Changeset 52:92047eaa6272 in documentViewer
- Timestamp:
- Jan 24, 2007, 4:12:26 PM (18 years ago)
- Branch:
- default
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
documentViewer.py
r51 r52 3 3 from OFS.Folder import Folder 4 4 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate 5 from Products.PageTemplates.PageTemplateFile import PageTemplateFile 5 from Products.PageTemplates.PageTemplateFile import PageTemplateFile 6 6 from AccessControl import ClassSecurityInfo 7 7 from AccessControl import getSecurityManager … … 19 19 import urllib 20 20 import logging 21 import zLOG 21 22 22 import urlparse 23 23 24 def logger(txt,method,txt2): 25 """logging""" 26 logging.info(txt+ txt2) 27 28 24 29 def getInt(number, default=0): 25 30 """returns always an int (0 in case of problems)""" … … 110 115 ''' 111 116 112 zLOG.LOG("documentViewer (index)", zLOG.INFO, "mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn))117 logger("documentViewer (index)", logging.INFO, "mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) 113 118 114 119 if not hasattr(self, 'template'): … … 128 133 else: 129 134 viewMode="images" 130 135 136 131 137 return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) 132 138 … … 150 156 def getStyle(self, idx, selected, style=""): 151 157 """returns a string with the given style and append 'sel' if path == selected.""" 152 # zLOG.LOG("documentViewer (getstyle)", zLOG.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style))158 #logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style)) 153 159 if idx == selected: 154 160 return style + 'sel' … … 160 166 """returns if access to the resource is granted""" 161 167 access = docinfo.get('accessType', None) 162 zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "access type %s"%access)168 logger("documentViewer (accessOK)", logging.INFO, "access type %s"%access) 163 169 if access is not None and access == 'free': 164 zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "access is free")170 logger("documentViewer (accessOK)", logging.INFO, "access is free") 165 171 return True 166 172 elif access is None or access in self.authgroups: … … 173 179 return False 174 180 175 zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access type %s"%access)181 logger("documentViewer (accessOK)", logging.INFO, "unknown access type %s"%access) 176 182 return False 177 183 … … 185 191 infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path 186 192 187 zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(infoUrl))193 logger("documentViewer (getparamfromdigilib)", logging.INFO, "dirInfo from %s"%(infoUrl)) 188 194 189 195 for cnt in range(num_retries): … … 194 200 break 195 201 except: 196 zLOG.LOG("documentViewer (getdirinfofromdigilib)", zLOG.ERROR, "error reading %s (try %d)"%(infoUrl,cnt))202 logger("documentViewer (getdirinfofromdigilib)", logging.ERROR, "error reading %s (try %d)"%(infoUrl,cnt)) 197 203 else: 198 204 raise IOError("Unable to get dir-info from %s"%(infoUrl)) 199 205 200 206 sizes=dom.xpath("//dir/size") 201 zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo:size"%sizes)207 logger("documentViewer (getparamfromdigilib)", logging.INFO, "dirInfo:size"%sizes) 202 208 203 209 if sizes: … … 232 238 break 233 239 except: 234 zLOG.LOG("ERROR documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2])240 logger("ERROR documentViewer (getIndexMata)", logging.INFO,"%s (%s)"%sys.exc_info()[0:2]) 235 241 236 242 if dom is None: … … 261 267 break 262 268 except: 263 zLOG.LOG("ERROR documentViewer (getPresentationInfoXML)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2])269 logger("ERROR documentViewer (getPresentationInfoXML)", logging.INFO,"%s (%s)"%sys.exc_info()[0:2]) 264 270 265 271 if dom is None: … … 271 277 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): 272 278 """gets authorization info from the index.meta file at path or given by dom""" 273 zLOG.LOG("documentViewer (getauthinfofromindexmeta)", zLOG.INFO,"path: %s"%(path))279 logger("documentViewer (getauthinfofromindexmeta)", logging.INFO,"path: %s"%(path)) 274 280 275 281 access = None … … 293 299 def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): 294 300 """gets bibliographical info from the index.meta file at path or given by dom""" 295 zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path))301 logger("documentViewer (getbibinfofromindexmeta)", logging.INFO,"path: %s"%(path)) 296 302 297 303 if docinfo is None: … … 315 321 docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0]) 316 322 docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0]) 317 323 324 logging.info("bla") 325 try: 326 docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) 327 except: 328 docinfo['lang']='' 318 329 return docinfo 319 330 … … 321 332 def getDocinfoFromTextTool(self,url,dom=None,docinfo=None): 322 333 """parse texttool tag in index meta""" 323 zLOG.LOG("documentViewer (getdocinfofromtexttool)", zLOG.INFO,"url: %s"%(url))334 logger("documentViewer (getdocinfofromtexttool)", logging.INFO,"url: %s"%(url)) 324 335 if docinfo is None: 325 336 docinfo = {} 326 337 338 if docinfo.get('lang',None) is None: 339 docinfo['lang']='' # default keine Sprache gesetzt 327 340 if dom is None: 328 341 dom = self.getIndexMeta(url) … … 335 348 archiveName=getTextFromNode(archiveNames[0]) 336 349 else: 337 zLOG.LOG("documentViewer (getdocinfofromtexttool)", zLOG.WARNING,"resource/name missing in: %s"%(url))350 logger("documentViewer (getdocinfofromtexttool)", logging.WARNING,"resource/name missing in: %s"%(url)) 338 351 339 352 archivePaths=dom.xpath("//resource/archive-path") … … 347 360 else: 348 361 # try to get archive-path from url 349 zLOG.LOG("documentViewer (getdocinfofromtexttool)", zLOG.WARNING,"resource/archive-path missing in: %s"%(url))362 logger("documentViewer (getdocinfofromtexttool)", logging.WARNING,"resource/archive-path missing in: %s"%(url)) 350 363 if (not url.startswith('http')): 351 364 archivePath = url.replace('index.meta', '') … … 359 372 imageDir=getTextFromNode(imageDirs[0]) 360 373 else: 361 # we balk with no image tag 362 raise IOError("No text-tool info in %s"%(url)) 363 374 # we balk with no image tag / not necessary anymore because textmode is now standard 375 #raise IOError("No text-tool info in %s"%(url)) 376 imageDir="" 377 docinfo['numPages']=1 # im moment einfach auf eins setzen, navigation ueber die thumbs geht natuerlich nicht 378 379 docinfo['imagePath'] = "" # keine Bilder 380 docinfo['imageURL'] = "" 381 364 382 if imageDir and archivePath: 365 383 #print "image: ", imageDir, " archivepath: ", archivePath … … 385 403 386 404 presentationUrls=dom.xpath("//texttool/presentation") 387 if presentationUrls and (len(presentationUrls)>0): 405 docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) # get info von bib tag 406 407 if presentationUrls and (len(presentationUrls)>0): # ueberschreibe diese durch presentation informationen 388 408 # presentation url ergiebt sich ersetzen von index.meta in der url der fr die Metadaten 389 409 # durch den relativen Pfad auf die presentation infos … … 391 411 392 412 docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl,docinfo=docinfo,dom=dom) 393 else: 394 docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom)395 docinfo = self.getAuthinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) 413 414 415 396 416 return docinfo 397 417 … … 408 428 def getDocinfoFromImagePath(self,path,docinfo=None): 409 429 """path ist the path to the images it assumes that the index.meta file is one level higher.""" 410 zLOG.LOG("documentViewer (getdocinfofromimagepath)", zLOG.INFO,"path: %s"%(path))430 logger("documentViewer (getdocinfofromimagepath)", logging.INFO,"path: %s"%(path)) 411 431 if docinfo is None: 412 432 docinfo = {} … … 424 444 def getDocinfo(self, mode, url): 425 445 """returns docinfo depending on mode""" 426 zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"mode: %s, url: %s"%(mode,url))446 logger("documentViewer (getdocinfo)", logging.INFO,"mode: %s, url: %s"%(mode,url)) 427 447 # look for cached docinfo in session 428 448 if self.REQUEST.SESSION.has_key('docinfo'): … … 430 450 # check if its still current 431 451 if docinfo is not None and docinfo.get('mode') == mode and docinfo.get('url') == url: 432 zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"docinfo in session: %s"%docinfo)452 logger("documentViewer (getdocinfo)", logging.INFO,"docinfo in session: %s"%docinfo) 433 453 return docinfo 434 454 # new docinfo … … 439 459 docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo) 440 460 else: 441 zLOG.LOG("documentViewer (getdocinfo)", zLOG.ERROR,"unknown mode!")461 logger("documentViewer (getdocinfo)", logging.ERROR,"unknown mode!") 442 462 raise ValueError("Unknown mode %s"%(mode)) 443 463 444 zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"docinfo: %s"%docinfo)464 logger("documentViewer (getdocinfo)", logging.INFO,"docinfo: %s"%docinfo) 445 465 self.REQUEST.SESSION['docinfo'] = docinfo 446 466 return docinfo -
zpt/image_main.zpt
r50 r52 1 1 <tal:block tal:define="docinfo options/docinfo; pageinfo options/pageinfo; mode python:options.get('viewMode','images')"> 2 2 <iframe tal:condition="python:mode=='images'" height="100%" width="100%" tal:attributes="src string:${here/imageViewerUrl}fn=${docinfo/imagePath}&pn=${pageinfo/current}"/> 3 <iframe tal:condition="python:mode=='text'" height="100%" width="100%" tal:attributes="src string:${here/textViewerUrl}fn=${docinfo/textURL}&pn=${pageinfo/current} "/>3 <iframe tal:condition="python:mode=='text'" height="100%" width="100%" tal:attributes="src string:${here/textViewerUrl}fn=${docinfo/textURL}&pn=${pageinfo/current}&lang=${docinfo/lang}"/> 4 4 </tal:block>
Note: See TracChangeset
for help on using the changeset viewer.