Changeset 35:2d9261aea8f3 in documentViewer


Ignore:
Timestamp:
Apr 12, 2006, 5:47:53 PM (18 years ago)
Author:
casties
Branch:
default
Message:

version 0.2.4

  • minor improvements
  • tries more than one time to read info from digilib
File:
1 edited

Legend:

Unmodified
Added
Removed
  • documentViewer.py

    r32 r35  
    2424    except:
    2525        return default
    26    
    2726
    2827def getTextFromNode(nodename):
     
    3635    return rc
    3736
     37       
     38def getParentDir(path):
     39    """returns pathname shortened by one"""
     40    return '/'.join(path.split('/')[0:-1])
     41       
     42
    3843import socket
    3944
     
    112117    def getLink(self,param=None,val=None):
    113118        """link to documentviewer with parameter param set to val"""
    114         params=cgi.parse_qs(self.REQUEST['QUERY_STRING'])
     119        params=self.REQUEST.form.copy()
    115120        if param is not None:
    116121            if val is None:
     
    118123                    del params[param]
    119124            else:
    120                 params[param] = [str(val)]
     125                params[param] = str(val)
    121126               
    122         ps = "&".join(["%s=%s"%(k,urllib.quote(v[0])) for (k, v) in params.items()])
    123         url=self.REQUEST['URL']+"?"+ps
    124         #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
    125130        return url
    126131
     
    132137            return style + 'sel'
    133138        else:
    134             return style   
    135        
    136     def accessOK(self, docinfo):
     139            return style
     140       
     141       
     142    def isAccessible(self, docinfo):
    137143        """returns if access to the resource is granted"""
    138144        access = docinfo.get('accessType', None)
    139145        if access is None:
    140             # no information - no access (not yet)
     146            # no information - no access
     147            #TODO: check
    141148            return True
    142149        elif access == 'free':
    143150            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)
    153161        return False
     162   
    154163               
    155        
    156164    def getDirinfoFromDigilib(self,path,docinfo=None):
    157165        """gibt param von dlInfo aus"""
     
    163171        zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(imageUrl))
    164172       
    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:
    169180            raise IOError("Unable to get dirinfo from %s"%(imageUrl))
    170181       
     
    180191   
    181192           
    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
    192205            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"
    195209            try:
    196210                dom = NonvalidatingReader.parseUri(metaUrl)
    197211            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))
    199229           
    200230        acctype = dom.xpath("//access-conditions/access/@type")
    201231        if acctype and (len(acctype)>0):
    202232            access=acctype[0].value
    203             if access == 'group':
     233            if access in ['group', 'institution']:
    204234                access = getTextFromNode(dom.xpath("//access-conditions/access/name")[0]).lower()
    205235           
     
    209239       
    210240    def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None):
    211         """gets bibliographical info from the index.meta file at url or given by dom"""
     241        """gets bibliographical info from the index.meta file at path or given by dom"""
    212242        zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path))
    213243       
     
    216246           
    217247        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           
    226250        metaData=self.metadata.main.meta.bib
    227251        bibtype=dom.xpath("//bib/@type")
     
    232256        bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC)
    233257        bibmap=metaData.generateMappingForType(bibtype)
    234         print "bibmap: ", bibmap, " for: ", bibtype
     258        #print "bibmap: ", bibmap, " for: ", bibtype
    235259        # if there is no mapping bibmap is empty (mapping sometimes has empty fields)
    236260        if len(bibmap) > 0 and len(bibmap['author'][0]) > 0:
     
    249273           
    250274       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)
    256276       
    257277       archiveNames=dom.xpath("//resource/name")
     
    270290           archivePath=None
    271291       
    272        images=dom.xpath("//texttool/image")
    273        if images 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])
    275295       else:
    276            image=None
     296           imageDir=None
    277297           
    278        if image and archivePath:
    279            print "image: ", image, " archivepath: ", archivePath
    280            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
    285305           
    286306       viewerUrls=dom.xpath("//texttool/digiliburlprefix")
     
    366386            (viewerUrl,imagepath,textpath)=parseUrlTextTool(url)
    367387       
    368         print textpath
     388        #print textpath
    369389        try:
    370390            dom = NonvalidatingReader.parseUri(textpath)
Note: See TracChangeset for help on using the changeset viewer.