Changeset 52:92047eaa6272 in documentViewer


Ignore:
Timestamp:
Jan 24, 2007, 4:12:26 PM (17 years ago)
Author:
dwinter
Branch:
default
Message:

zLOG exchanged by logging

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • documentViewer.py

    r51 r52  
    33from OFS.Folder import Folder
    44from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
    5 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
     5from Products.PageTemplates.PageTemplateFile import PageTemplateFile 
    66from AccessControl import ClassSecurityInfo
    77from AccessControl import getSecurityManager
     
    1919import urllib
    2020import logging
    21 import zLOG
     21
    2222import urlparse
    2323
     24def logger(txt,method,txt2):
     25    """logging"""
     26    logging.info(txt+ txt2)
     27   
     28   
    2429def getInt(number, default=0):
    2530    """returns always an int (0 in case of problems)"""
     
    110115        '''
    111116       
    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))
    113118       
    114119        if not hasattr(self, 'template'):
     
    128133            else:
    129134                viewMode="images"
    130                
     135               
     136
    131137        return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode)
    132138 
     
    150156    def getStyle(self, idx, selected, style=""):
    151157        """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))
    153159        if idx == selected:
    154160            return style + 'sel'
     
    160166        """returns if access to the resource is granted"""
    161167        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)
    163169        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")
    165171            return True
    166172        elif access is None or access in self.authgroups:
     
    173179                return False
    174180       
    175         zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access type %s"%access)
     181        logger("documentViewer (accessOK)", logging.INFO, "unknown access type %s"%access)
    176182        return False
    177183   
     
    185191        infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path
    186192   
    187         zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(infoUrl))
     193        logger("documentViewer (getparamfromdigilib)", logging.INFO, "dirInfo from %s"%(infoUrl))
    188194       
    189195        for cnt in range(num_retries):
     
    194200                break
    195201            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))
    197203        else:
    198204            raise IOError("Unable to get dir-info from %s"%(infoUrl))
    199205       
    200206        sizes=dom.xpath("//dir/size")
    201         zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo:size"%sizes)
     207        logger("documentViewer (getparamfromdigilib)", logging.INFO, "dirInfo:size"%sizes)
    202208       
    203209        if sizes:
     
    232238                break
    233239            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])
    235241               
    236242        if dom is None:
     
    261267                break
    262268            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])
    264270               
    265271        if dom is None:
     
    271277    def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None):
    272278        """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))
    274280       
    275281        access = None
     
    293299    def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None):
    294300        """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))
    296302       
    297303        if docinfo is None:
     
    315321            docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0])
    316322            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']=''
    318329        return docinfo
    319330
     
    321332    def getDocinfoFromTextTool(self,url,dom=None,docinfo=None):
    322333       """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))
    324335       if docinfo is None:
    325336           docinfo = {}
    326337           
     338       if docinfo.get('lang',None) is None:
     339           docinfo['lang']='' # default keine Sprache gesetzt
    327340       if dom is None:
    328341           dom = self.getIndexMeta(url)
     
    335348           archiveName=getTextFromNode(archiveNames[0])
    336349       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))
    338351       
    339352       archivePaths=dom.xpath("//resource/archive-path")
     
    347360       else:
    348361           # 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))
    350363           if (not url.startswith('http')):
    351364               archivePath = url.replace('index.meta', '')
     
    359372           imageDir=getTextFromNode(imageDirs[0])
    360373       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
    364382       if imageDir and archivePath:
    365383           #print "image: ", imageDir, " archivepath: ", archivePath
     
    385403   
    386404       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
    388408            # presentation url ergiebt sich ersetzen von index.meta in der url der fŸr die Metadaten
    389409            # durch den relativen Pfad auf die presentation infos
     
    391411           
    392412           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
    396416       return docinfo
    397417   
     
    408428    def getDocinfoFromImagePath(self,path,docinfo=None):
    409429        """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))
    411431        if docinfo is None:
    412432            docinfo = {}
     
    424444    def getDocinfo(self, mode, url):
    425445        """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))
    427447        # look for cached docinfo in session
    428448        if self.REQUEST.SESSION.has_key('docinfo'):
     
    430450            # check if its still current
    431451            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)
    433453                return docinfo
    434454        # new docinfo
     
    439459            docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo)
    440460        else:
    441             zLOG.LOG("documentViewer (getdocinfo)", zLOG.ERROR,"unknown mode!")
     461            logger("documentViewer (getdocinfo)", logging.ERROR,"unknown mode!")
    442462            raise ValueError("Unknown mode %s"%(mode))
    443463                       
    444         zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"docinfo: %s"%docinfo)
     464        logger("documentViewer (getdocinfo)", logging.INFO,"docinfo: %s"%docinfo)
    445465        self.REQUEST.SESSION['docinfo'] = docinfo
    446466        return docinfo
  • zpt/image_main.zpt

    r50 r52  
    11<tal:block tal:define="docinfo options/docinfo; pageinfo options/pageinfo; mode python:options.get('viewMode','images')">
    22 <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}"/>
    44</tal:block>
Note: See TracChangeset for help on using the changeset viewer.