Changeset 35:2d9261aea8f3 in documentViewer
- Timestamp:
- Apr 12, 2006, 5:47:53 PM (18 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
documentViewer.py
r32 r35 24 24 except: 25 25 return default 26 27 26 28 27 def getTextFromNode(nodename): … … 36 35 return rc 37 36 37 38 def getParentDir(path): 39 """returns pathname shortened by one""" 40 return '/'.join(path.split('/')[0:-1]) 41 42 38 43 import socket 39 44 … … 112 117 def getLink(self,param=None,val=None): 113 118 """link to documentviewer with parameter param set to val""" 114 params= cgi.parse_qs(self.REQUEST['QUERY_STRING'])119 params=self.REQUEST.form.copy() 115 120 if param is not None: 116 121 if val is None: … … 118 123 del params[param] 119 124 else: 120 params[param] = [str(val)]125 params[param] = str(val) 121 126 122 ps = "&".join(["%s=%s"%(k,urllib.quote(v[0])) for (k, v) in params.items()])123 url=self.REQUEST['URL']+"?"+ps124 #url=self.REQUEST['URL']+"?"+urllib.urlencode(params, doseq=True)127 # quote values and assemble into query string 128 ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) 129 url=self.REQUEST['URL1']+"?"+ps 125 130 return url 126 131 … … 132 137 return style + 'sel' 133 138 else: 134 return style 135 136 def accessOK(self, docinfo): 139 return style 140 141 142 def isAccessible(self, docinfo): 137 143 """returns if access to the resource is granted""" 138 144 access = docinfo.get('accessType', None) 139 145 if access is None: 140 # no information - no access (not yet) 146 # no information - no access 147 #TODO: check 141 148 return True 142 149 elif access == 'free': 143 150 return True 144 145 print "access: ", access, " authgroups: ", self.authgroups 146 if access in self.authgroups: 147 # local access OK 148 user = getSecurityManager().getUser().getUserName() 149 print "user: ", user 150 return (user != "Anonymous User") 151 152 zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access group %s"%access) 151 elif access in self.authgroups: 152 # only local access -- only logged in users 153 user = getSecurityManager().getUser() 154 if user is not None: 155 #print "user: ", user 156 return (user.getUserName() != "Anonymous User") 157 else: 158 return False 159 160 zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access type %s"%access) 153 161 return False 162 154 163 155 156 164 def getDirinfoFromDigilib(self,path,docinfo=None): 157 165 """gibt param von dlInfo aus""" … … 163 171 zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(imageUrl)) 164 172 165 try: 166 dom = NonvalidatingReader.parseUri(imageUrl) 167 except: 168 zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.ERROR, "error reading %s"%(imageUrl)) 173 for cnt in (1,2,3): 174 try: 175 dom = NonvalidatingReader.parseUri(imageUrl) 176 break 177 except: 178 zLOG.LOG("documentViewer (getdirinfofromdigilib)", zLOG.ERROR, "error reading %s (try %d)"%(imageUrl,cnt)) 179 else: 169 180 raise IOError("Unable to get dirinfo from %s"%(imageUrl)) 170 181 … … 180 191 181 192 182 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): 183 """gets authorization info from the index.meta file at url or given by dom""" 184 zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) 185 186 access = None 187 188 if docinfo is None: 189 docinfo = {} 190 191 if dom is None: 193 def getIndexMeta(self, url): 194 """returns dom of index.meta document at url""" 195 dom = None 196 if url.startswith("http://"): 197 # real URL 198 try: 199 dom = NonvalidatingReader.parseUri(url) 200 except: 201 zLOG.LOG("documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) 202 raise IOError("Unable to get info from %s"%(url)) 203 else: 204 # online path 192 205 server=self.digilibBaseUrl+"/servlet/Texter?fn=" 193 path="/".join(path.split("/")[0:-1]) 194 metaUrl=server+path+"/index.meta" 206 metaUrl=server+url 207 if not metaUrl.endswith("index.meta"): 208 metaUrl += "/index.meta" 195 209 try: 196 210 dom = NonvalidatingReader.parseUri(metaUrl) 197 211 except: 198 return docinfo 212 zLOG.LOG("documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) 213 raise IOError("Unable to get info from %s"%(url)) 214 215 return dom 216 217 218 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): 219 """gets authorization info from the index.meta file at path or given by dom""" 220 zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) 221 222 access = None 223 224 if docinfo is None: 225 docinfo = {} 226 227 if dom is None: 228 dom = self.getIndexMeta(getParentDir(path)) 199 229 200 230 acctype = dom.xpath("//access-conditions/access/@type") 201 231 if acctype and (len(acctype)>0): 202 232 access=acctype[0].value 203 if access == 'group':233 if access in ['group', 'institution']: 204 234 access = getTextFromNode(dom.xpath("//access-conditions/access/name")[0]).lower() 205 235 … … 209 239 210 240 def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): 211 """gets bibliographical info from the index.meta file at urlor given by dom"""241 """gets bibliographical info from the index.meta file at path or given by dom""" 212 242 zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) 213 243 … … 216 246 217 247 if dom is None: 218 server=self.digilibBaseUrl+"/servlet/Texter?fn=" 219 path="/".join(path.split("/")[0:-1]) 220 metaUrl=server+path+"/index.meta" 221 try: 222 dom = NonvalidatingReader.parseUri(metaUrl) 223 except: 224 return docinfo 225 248 dom = self.getIndexMeta(getParentDir(path)) 249 226 250 metaData=self.metadata.main.meta.bib 227 251 bibtype=dom.xpath("//bib/@type") … … 232 256 bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) 233 257 bibmap=metaData.generateMappingForType(bibtype) 234 print "bibmap: ", bibmap, " for: ", bibtype258 #print "bibmap: ", bibmap, " for: ", bibtype 235 259 # if there is no mapping bibmap is empty (mapping sometimes has empty fields) 236 260 if len(bibmap) > 0 and len(bibmap['author'][0]) > 0: … … 249 273 250 274 if dom is None: 251 try: 252 dom = NonvalidatingReader.parseUri(url) 253 except: 254 zLOG.LOG("documentViewer (parseUrlTexttool)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) 255 raise IOError("Unable to get texttool info from %s"%(url)) 275 dom = self.getIndexMeta(url) 256 276 257 277 archiveNames=dom.xpath("//resource/name") … … 270 290 archivePath=None 271 291 272 image s=dom.xpath("//texttool/image")273 if image s and (len(images)>0):274 image =getTextFromNode(images[0])292 imageDirs=dom.xpath("//texttool/image") 293 if imageDirs and (len(imageDirs)>0): 294 imageDir=getTextFromNode(imageDirs[0]) 275 295 else: 276 image =None296 imageDir=None 277 297 278 if image and archivePath:279 print "image: ", image, " archivepath: ", archivePath280 image =os.path.join(archivePath,image)281 image =image.replace("/mpiwg/online",'')282 docinfo=self.getDirinfoFromDigilib(image ,docinfo=docinfo)283 docinfo['imagePath'] = image 284 docinfo['imageURL'] = self.digilibBaseUrl+"/servlet/Scaler?fn="+image 298 if imageDir and archivePath: 299 #print "image: ", imageDir, " archivepath: ", archivePath 300 imageDir=os.path.join(archivePath,imageDir) 301 imageDir=imageDir.replace("/mpiwg/online",'') 302 docinfo=self.getDirinfoFromDigilib(imageDir,docinfo=docinfo) 303 docinfo['imagePath'] = imageDir 304 docinfo['imageURL'] = self.digilibBaseUrl+"/servlet/Scaler?fn="+imageDir 285 305 286 306 viewerUrls=dom.xpath("//texttool/digiliburlprefix") … … 366 386 (viewerUrl,imagepath,textpath)=parseUrlTextTool(url) 367 387 368 print textpath388 #print textpath 369 389 try: 370 390 dom = NonvalidatingReader.parseUri(textpath)
Note: See TracChangeset
for help on using the changeset viewer.