Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 32)
+++ documentViewer.py	(revision 35)
@@ -24,5 +24,4 @@
     except:
         return default
-    
 
 def getTextFromNode(nodename):
@@ -36,4 +35,10 @@
     return rc
 
+        
+def getParentDir(path):
+    """returns pathname shortened by one"""
+    return '/'.join(path.split('/')[0:-1])
+        
+
 import socket
 
@@ -112,5 +117,5 @@
     def getLink(self,param=None,val=None):
         """link to documentviewer with parameter param set to val"""
-        params=cgi.parse_qs(self.REQUEST['QUERY_STRING'])
+        params=self.REQUEST.form.copy()
         if param is not None:
             if val is None:
@@ -118,9 +123,9 @@
                     del params[param]
             else:
-                params[param] = [str(val)]
+                params[param] = str(val)
                 
-        ps = "&".join(["%s=%s"%(k,urllib.quote(v[0])) for (k, v) in params.items()])
-        url=self.REQUEST['URL']+"?"+ps
-        #url=self.REQUEST['URL']+"?"+urllib.urlencode(params, doseq=True)
+        # quote values and assemble into query string
+        ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()])
+        url=self.REQUEST['URL1']+"?"+ps
         return url
 
@@ -132,26 +137,29 @@
             return style + 'sel'
         else:
-            return style    
-        
-    def accessOK(self, docinfo):
+            return style
+        
+        
+    def isAccessible(self, docinfo):
         """returns if access to the resource is granted"""
         access = docinfo.get('accessType', None)
         if access is None:
-            # no information - no access (not yet)
+            # no information - no access 
+            #TODO: check
             return True
         elif access == 'free':
             return True
-        
-        print "access: ", access, " authgroups: ", self.authgroups
-        if access in self.authgroups:
-            # local access OK
-            user = getSecurityManager().getUser().getUserName()
-            print "user: ", user
-            return (user != "Anonymous User")
-        
-        zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access group %s"%access)
+        elif access in self.authgroups:
+            # only local access -- only logged in users
+            user = getSecurityManager().getUser()
+            if user is not None:
+                #print "user: ", user
+                return (user.getUserName() != "Anonymous User")
+            else:
+                return False
+        
+        zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access type %s"%access)
         return False
+    
                 
-        
     def getDirinfoFromDigilib(self,path,docinfo=None):
         """gibt param von dlInfo aus"""
@@ -163,8 +171,11 @@
         zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(imageUrl))
         
-        try:
-            dom = NonvalidatingReader.parseUri(imageUrl)
-        except:
-            zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.ERROR, "error reading %s"%(imageUrl))
+        for cnt in (1,2,3):
+            try:
+                dom = NonvalidatingReader.parseUri(imageUrl)
+                break
+            except:
+                zLOG.LOG("documentViewer (getdirinfofromdigilib)", zLOG.ERROR, "error reading %s (try %d)"%(imageUrl,cnt))
+        else:
             raise IOError("Unable to get dirinfo from %s"%(imageUrl))
         
@@ -180,26 +191,45 @@
     
             
-    def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None):
-        """gets authorization info from the index.meta file at url or given by dom"""
-        zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path))
-        
-        access = None
-        
-        if docinfo is None:
-            docinfo = {}
-            
-        if dom is None:
+    def getIndexMeta(self, url):
+        """returns dom of index.meta document at url"""
+        dom = None
+        if url.startswith("http://"):
+            # real URL
+            try:
+                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:
+            # online path
             server=self.digilibBaseUrl+"/servlet/Texter?fn="
-            path="/".join(path.split("/")[0:-1])
-            metaUrl=server+path+"/index.meta"
+            metaUrl=server+url
+            if not metaUrl.endswith("index.meta"):
+                metaUrl += "/index.meta"
             try:
                 dom = NonvalidatingReader.parseUri(metaUrl)
             except:
-                return docinfo
+                zLOG.LOG("documentViewer (getIndexMata)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2])
+                raise IOError("Unable to get info from %s"%(url))
+                 
+        return dom
+                        
+        
+    def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None):
+        """gets authorization info from the index.meta file at path or given by dom"""
+        zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path))
+        
+        access = None
+        
+        if docinfo is None:
+            docinfo = {}
+            
+        if dom is None:
+            dom = self.getIndexMeta(getParentDir(path))
             
         acctype = dom.xpath("//access-conditions/access/@type")
         if acctype and (len(acctype)>0):
             access=acctype[0].value
-            if access == 'group':
+            if access in ['group', 'institution']:
                 access = getTextFromNode(dom.xpath("//access-conditions/access/name")[0]).lower()
             
@@ -209,5 +239,5 @@
         
     def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None):
-        """gets bibliographical info from the index.meta file at url or given by dom"""
+        """gets bibliographical info from the index.meta file at path or given by dom"""
         zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path))
         
@@ -216,12 +246,6 @@
             
         if dom is None:
-            server=self.digilibBaseUrl+"/servlet/Texter?fn="
-            path="/".join(path.split("/")[0:-1])
-            metaUrl=server+path+"/index.meta"
-            try:
-                dom = NonvalidatingReader.parseUri(metaUrl)
-            except:
-                return docinfo
-        
+            dom = self.getIndexMeta(getParentDir(path))
+            
         metaData=self.metadata.main.meta.bib
         bibtype=dom.xpath("//bib/@type")
@@ -232,5 +256,5 @@
         bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC)
         bibmap=metaData.generateMappingForType(bibtype)
-        print "bibmap: ", bibmap, " for: ", bibtype
+        #print "bibmap: ", bibmap, " for: ", bibtype
         # if there is no mapping bibmap is empty (mapping sometimes has empty fields)
         if len(bibmap) > 0 and len(bibmap['author'][0]) > 0:
@@ -249,9 +273,5 @@
            
        if dom is None:
-           try:
-               dom = NonvalidatingReader.parseUri(url)
-           except:
-               zLOG.LOG("documentViewer (parseUrlTexttool)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2])
-               raise IOError("Unable to get texttool info from %s"%(url))
+           dom = self.getIndexMeta(url)
        
        archiveNames=dom.xpath("//resource/name")
@@ -270,17 +290,17 @@
            archivePath=None
        
-       images=dom.xpath("//texttool/image")
-       if images and (len(images)>0):
-           image=getTextFromNode(images[0])
+       imageDirs=dom.xpath("//texttool/image")
+       if imageDirs and (len(imageDirs)>0):
+           imageDir=getTextFromNode(imageDirs[0])
        else:
-           image=None
+           imageDir=None
            
-       if image and archivePath:
-           print "image: ", image, " archivepath: ", archivePath
-           image=os.path.join(archivePath,image)
-           image=image.replace("/mpiwg/online",'')
-           docinfo=self.getDirinfoFromDigilib(image,docinfo=docinfo)
-           docinfo['imagePath'] = image
-           docinfo['imageURL'] = self.digilibBaseUrl+"/servlet/Scaler?fn="+image
+       if imageDir and archivePath:
+           #print "image: ", imageDir, " archivepath: ", archivePath
+           imageDir=os.path.join(archivePath,imageDir)
+           imageDir=imageDir.replace("/mpiwg/online",'')
+           docinfo=self.getDirinfoFromDigilib(imageDir,docinfo=docinfo)
+           docinfo['imagePath'] = imageDir
+           docinfo['imageURL'] = self.digilibBaseUrl+"/servlet/Scaler?fn="+imageDir
            
        viewerUrls=dom.xpath("//texttool/digiliburlprefix")
@@ -366,5 +386,5 @@
             (viewerUrl,imagepath,textpath)=parseUrlTextTool(url)
         
-        print textpath
+        #print textpath
         try:
             dom = NonvalidatingReader.parseUri(textpath)
