Diff for /documentViewer/documentViewer.py between versions 1.9 and 1.14

version 1.9, 2006/04/12 17:47:53 version 1.14, 2006/07/06 16:01:42
Line 7  from Globals import package_home Line 7  from Globals import package_home
   
 from Ft.Xml.Domlette import NonvalidatingReader  from Ft.Xml.Domlette import NonvalidatingReader
 from Ft.Xml.Domlette import PrettyPrint, Print  from Ft.Xml.Domlette import PrettyPrint, Print
 from Ft.Xml import EMPTY_NAMESPACE  from Ft.Xml import EMPTY_NAMESPACE, Parse
   
 import Ft.Xml.XPath  import Ft.Xml.XPath
   
Line 142  class documentViewer(Folder): Line 142  class documentViewer(Folder):
     def isAccessible(self, docinfo):      def isAccessible(self, docinfo):
         """returns if access to the resource is granted"""          """returns if access to the resource is granted"""
         access = docinfo.get('accessType', None)          access = docinfo.get('accessType', None)
           zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "access type %s"%access)
         if access is None:          if access is None:
             # no information - no access               # no information - no access 
             #TODO: check              #TODO: check
             return True              return True
         elif access == 'free':          elif access == 'free':
           zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "access is free")
             return True              return True
         elif access in self.authgroups:          elif access in self.authgroups:
             # only local access -- only logged in users              # only local access -- only logged in users
Line 163  class documentViewer(Folder): Line 165  class documentViewer(Folder):
                                   
     def getDirinfoFromDigilib(self,path,docinfo=None):      def getDirinfoFromDigilib(self,path,docinfo=None):
         """gibt param von dlInfo aus"""          """gibt param von dlInfo aus"""
           num_retries = 3
         if docinfo is None:          if docinfo is None:
             docinfo = {}              docinfo = {}
                           
         imageUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path          infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path
           
         zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(imageUrl))          zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(infoUrl))
                   
         for cnt in (1,2,3):          for cnt in range(num_retries):
             try:              try:
                 dom = NonvalidatingReader.parseUri(imageUrl)                  # dom = NonvalidatingReader.parseUri(imageUrl)
                   txt=urllib.urlopen(infoUrl).read()
                   dom = Parse(txt)
                 break                  break
             except:              except:
                 zLOG.LOG("documentViewer (getdirinfofromdigilib)", zLOG.ERROR, "error reading %s (try %d)"%(imageUrl,cnt))                  zLOG.LOG("documentViewer (getdirinfofromdigilib)", zLOG.ERROR, "error reading %s (try %d)"%(infoUrl,cnt))
         else:          else:
             raise IOError("Unable to get dirinfo from %s"%(imageUrl))              raise IOError("Unable to get dir-info from %s"%(infoUrl))
                   
         params=dom.xpath("//dir/size")          sizes=dom.xpath("//dir/size")
         zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo:size"%params)          zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo:size"%sizes)
                   
         if params:          if sizes:
             docinfo['numPages'] = int(getTextFromNode(params[0]))              docinfo['numPages'] = int(getTextFromNode(sizes[0]))
         else:          else:
             docinfo['numPages'] = 0              docinfo['numPages'] = 0
                                                   
Line 192  class documentViewer(Folder): Line 197  class documentViewer(Folder):
                           
     def getIndexMeta(self, url):      def getIndexMeta(self, url):
         """returns dom of index.meta document at url"""          """returns dom of index.meta document at url"""
           num_retries = 3
         dom = None          dom = None
           metaUrl = None
         if url.startswith("http://"):          if url.startswith("http://"):
             # real URL              # real URL
             try:              metaUrl = url
                 dom = NonvalidatingReader.parseUri(url)  
             except:  
                 zLOG.LOG("documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2])  
                 raise IOError("Unable to get info from %s"%(url))  
         else:          else:
             # online path              # online path
             server=self.digilibBaseUrl+"/servlet/Texter?fn="              server=self.digilibBaseUrl+"/servlet/Texter?fn="
             metaUrl=server+url              metaUrl=server+url.replace("/mpiwg/online","")
             if not metaUrl.endswith("index.meta"):              if not metaUrl.endswith("index.meta"):
                 metaUrl += "/index.meta"                  metaUrl += "/index.meta"
           
           for cnt in range(num_retries):
             try:              try:
                 dom = NonvalidatingReader.parseUri(metaUrl)                  # patch dirk encoding fehler treten dann nicht mehr auf
                   # dom = NonvalidatingReader.parseUri(metaUrl)
                   txt=urllib.urlopen(metaUrl).read()
                   dom = Parse(txt)
                   break
             except:              except:
                 zLOG.LOG("documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2])                  zLOG.LOG("ERROR documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2])
                 raise IOError("Unable to get info from %s"%(url))                  
           if dom is None:
               raise IOError("Unable to read index meta from %s"%(url))
                                     
         return dom          return dom
                                                   
                   
     def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None):      def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None):
         """gets authorization info from the index.meta file at path or given by dom"""          """gets authorization info from the index.meta file at path or given by dom"""
         zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path))          zLOG.LOG("documentViewer (getauthinfofromindexmeta)", zLOG.INFO,"path: %s"%(path))
                   
         access = None          access = None
                   
Line 293  class documentViewer(Folder): Line 304  class documentViewer(Folder):
        if imageDirs and (len(imageDirs)>0):         if imageDirs and (len(imageDirs)>0):
            imageDir=getTextFromNode(imageDirs[0])             imageDir=getTextFromNode(imageDirs[0])
        else:         else:
            imageDir=None             # we balk with no image tag
              raise IOError("No text-tool info in %s"%(url))
                         
        if imageDir and archivePath:         if imageDir and archivePath:
            #print "image: ", imageDir, " archivepath: ", archivePath             #print "image: ", imageDir, " archivepath: ", archivePath
Line 352  class documentViewer(Folder): Line 364  class documentViewer(Folder):
             docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo)              docinfo = self.getDocinfoFromImagePath(url, docinfo=docinfo)
         else:          else:
             zLOG.LOG("documentViewer (getdocinfo)", zLOG.ERROR,"unknown mode!")              zLOG.LOG("documentViewer (getdocinfo)", zLOG.ERROR,"unknown mode!")
               raise ValueError("Unknown mode %s"%(mode))
                           
         zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"docinfo: %s"%docinfo)          zLOG.LOG("documentViewer (getdocinfo)", zLOG.INFO,"docinfo: %s"%docinfo)
         self.REQUEST.SESSION['docinfo'] = docinfo          self.REQUEST.SESSION['docinfo'] = docinfo
         return docinfo          return docinfo

Removed from v.1.9  
changed lines
  Added in v.1.14


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>