Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 29)
+++ documentViewer.py	(revision 31)
@@ -15,4 +15,5 @@
 
 import os.path
+import sys
 import cgi
 import urllib
@@ -43,6 +44,4 @@
         socket.setdefaulttimeout(5)
         return ret
-    
-    
 
 
@@ -98,5 +97,4 @@
         if not hasattr(self, 'template'):
             # create template folder if it doesn't exist
-            print "no template folder -- creating"
             self.manage_addFolder('template')
             
@@ -114,10 +112,13 @@
         params=cgi.parse_qs(self.REQUEST['QUERY_STRING'])
         if param is not None:
-            if val is None and params.has_key(param):
-                del params[param]
+            if val is None:
+                if params.has_key(param):
+                    del params[param]
             else:
-                params[param] = val
-        
-        url=self.REQUEST['URL']+"?"+urllib.urlencode(params, doseq=True)
+                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)
         return url
 
@@ -132,20 +133,28 @@
         
         
-    def getParamFromDigilib(self,path,param):
+    def getDirinfoFromDigilib(self,path,docinfo=None):
         """gibt param von dlInfo aus"""
+        if docinfo is None:
+            docinfo = {}
+            
         imageUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path
     
-        zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo (%s) from %s"%(param,imageUrl))
+        zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo from %s"%(imageUrl))
         
         try:
             dom = NonvalidatingReader.parseUri(imageUrl)
         except:
-            return None
-        
-        params=dom.xpath("//dir/%s"%param)
-        zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo:%s"%params)
+            zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.ERROR, "error reading %s"%(imageUrl))
+            raise IOError("Unable to get dirinfo from %s"%(imageUrl))
+        
+        params=dom.xpath("//dir/size")
+        zLOG.LOG("documentViewer (getparamfromdigilib)", zLOG.INFO, "dirInfo:size"%params)
         
         if params:
-            return getTextFromNode(params[0])
+            docinfo['numPages'] = getTextFromNode(params[0])
+        else:
+            docinfo['numPages'] = 0
+                        
+        return docinfo
             
     
@@ -158,5 +167,5 @@
             
         if dom is None:
-            server="http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary/servlet/Texter?fn="
+            server=self.digilibBaseUrl+"/servlet/Texter?fn="
             path="/".join(path.split("/")[0:-1])
             metaUrl=server+path+"/index.meta"
@@ -174,5 +183,6 @@
         bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC)
         bibmap=metaData.generateMappingForType(bibtype)
-        if len(bibmap) > 0:
+        print "bibmap: ", bibmap, " for: ", bibtype
+        if len(bibmap) > 0 and len(bibmap['author'][0]) > 0:
             docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0])
             docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0])
@@ -192,8 +202,7 @@
        except:
            zLOG.LOG("documentViewer (parseUrlTexttool)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2])
-           return docinfo
+           raise IOError("Unable to get texttool info from %s"%(url))
        
        archivePaths=dom.xpath("//resource/archive-path")
-       
        if archivePaths and (len(archivePaths)>0):
            archivePath=getTextFromNode(archivePaths[0])
@@ -202,5 +211,4 @@
        
        images=dom.xpath("//texttool/image")
-       
        if images and (len(images)>0):
            image=getTextFromNode(images[0])
@@ -211,19 +219,17 @@
            image=os.path.join(archivePath,image)
            image=image.replace("/mpiwg/online",'')
-           pt=self.getParamFromDigilib(image,'size')
+           docinfo=self.getDirinfoFromDigilib(image,docinfo=docinfo)
            docinfo['imagePath'] = image
-           docinfo['numPages'] = pt
+           docinfo['imageURL'] = self.digilibBaseUrl+"/servlet/Scaler?fn="+image
            
        viewerUrls=dom.xpath("//texttool/digiliburlprefix")
-       
        if viewerUrls and (len(viewerUrls)>0):
            viewerUrl=getTextFromNode(viewerUrls[0])
-           docinfo['imageURL'] = viewerURL
+           docinfo['viewerURL'] = viewerUrl
                   
        textUrls=dom.xpath("//texttool/text")
-       
        if textUrls and (len(textUrls)>0):
            textUrl=getTextFromNode(textUrls[0])
-           docinfo['textURL'] = textURL
+           docinfo['textURL'] = textUrl
                      
        docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom)
@@ -238,7 +244,6 @@
         path=path.replace("/mpiwg/online","")
         docinfo['imagePath'] = path
-        pt=self.getParamFromDigilib(path,'size')
-        docinfo['numPages'] = pt
-        imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn=%s"%path
+        docinfo=self.getDirinfoFromDigilib(path,docinfo=docinfo)
+        imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path
         docinfo['imageURL'] = imageUrl
         
@@ -282,5 +287,4 @@
         pageinfo['groupsize'] = grpsize
         start = getInt(start, default=(int(current / grpsize) * grpsize +1))
-        print "start3:", start
         pageinfo['start'] = start
         pageinfo['end'] = start + grpsize
Index: version.txt
===================================================================
--- version.txt	(revision 28)
+++ version.txt	(revision 31)
@@ -1,1 +1,1 @@
-DocumentViewer 0.2.1
+DocumentViewer 0.2.2
Index: zpt/viewer_main.zpt
===================================================================
--- zpt/viewer_main.zpt	(revision 27)
+++ zpt/viewer_main.zpt	(revision 31)
@@ -3,5 +3,5 @@
 <link rel="stylesheet" href="template/docuviewer_css" type="text/css">
 </head>
-<body tal:define="docinfo options/docinfo; pageinfo options/pageinfo">
+<body tal:define="docinfo options/docinfo; pageinfo options/pageinfo" tal:condition="docinfo/numPages">
 <div tal:replace="structure python:here.template.head_main(docinfo=docinfo)"/>
 <table border="0" width="100%" height="100%">
@@ -16,3 +16,6 @@
 </table>
 </body>
+<body tal:define="docinfo options/docinfo; pageinfo options/pageinfo" tal:condition="not:docinfo/numPages">
+<div class="errortext">Sorry, document doesn't exist.</div>
+</body>
 </html>
