Index: MpdlXmlTextServer.py
===================================================================
--- MpdlXmlTextServer.py	(revision 465)
+++ MpdlXmlTextServer.py	(revision 469)
@@ -228,16 +228,11 @@
     def processPageInfo(self, dom, docinfo, pageinfo):
         """processes page info divs from dom and stores in docinfo and pageinfo"""
-        # process all toplevel divs
-        alldivs = dom.findall(".//div")
-        pagediv = None
+        # assume first second level div is pageMeta
+        alldivs = dom.find("div")
         for div in alldivs:
             dc = div.get('class')
             
-            # page content div
-            if dc == 'pageContent':
-                pagediv = div
-            
             # pageNumberOrig  
-            elif dc == 'pageNumberOrig':
+            if dc == 'pageNumberOrig':
                 pageinfo['pageNumberOrig'] = div.text
                 
@@ -248,10 +243,14 @@
             # pageNumberOrigNorm
             elif dc == 'countFigureEntries':
-                docinfo['countFigureEntries'] = getInt(div.text)
+                docinfo['numFigureEntries'] = getInt(div.text)
                 
             # pageNumberOrigNorm
             elif dc == 'countTocEntries':
                 # WTF: s1 = int(s)/30+1
-                docinfo['countTocEntries'] = getInt(div.text)
+                docinfo['numTocEntries'] = getInt(div.text)
+                
+            # pageHeaderTitle
+            elif dc == 'pageHeaderTitle':
+                docinfo['pageHeaderTitle'] = div.text
                 
             # numTextPages
@@ -312,5 +311,6 @@
         pagediv = None
         # ElementTree 1.2 in Python 2.6 can't do div[@class='pageContent']
-        alldivs = dom.findall(".//div")
+        # so we look at the second level divs
+        alldivs = dom.findall("div")
         for div in alldivs:
             dc = div.get('class')
Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 468)
+++ documentViewer.py	(revision 469)
@@ -300,10 +300,5 @@
                 
         pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, viewMode=viewMode, tocMode=tocMode)
-        
-        if viewMode != 'images' and docinfo.get('textURLPath', None):
-            # get full text page
-            page = self.getTextPage(mode=viewMode, pn=pn, docinfo=docinfo, pageinfo=pageinfo)
-            pageinfo['textPage'] = page
-            
+                    
         # get template /template/viewer_main
         pt = getattr(self.template, 'viewer_main')
@@ -345,15 +340,18 @@
             return style
     
-    def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&'):
-        """returns URL to documentviewer with parameter param set to val or from dict params"""
+    def getParams(self, param=None, val=None, params=None):
+        """returns dict with URL parameters.
+        
+        Takes URL parameters and additionally param=val or dict params.
+        Deletes key if value is None."""
         # copy existing request params
-        urlParams=self.REQUEST.form.copy()
+        newParams=self.REQUEST.form.copy()
         # change single param
         if param is not None:
             if val is None:
-                if urlParams.has_key(param):
-                    del urlParams[param]
+                if newParams.has_key(param):
+                    del newParams[param]
             else:
-                urlParams[param] = str(val)
+                newParams[param] = str(val)
                 
         # change more params
@@ -363,28 +361,27 @@
                 if v is None:
                     # val=None removes param
-                    if urlParams.has_key(k):
-                        del urlParams[k]
+                    if newParams.has_key(k):
+                        del newParams[k]
                         
                 else:
-                    urlParams[k] = v
-
-        # FIXME: does this belong here?
-        if urlParams.get("mode", None) == "filepath": #wenn beim erst Aufruf filepath gesetzt wurde aendere das nun zu imagepath
-                urlParams["mode"] = "imagepath"
-                urlParams["url"] = getParentPath(urlParams["url"])
-                
+                    newParams[k] = v
+                    
+        return newParams
+    
+    def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&'):
+        """returns URL to documentviewer with parameter param set to val or from dict params"""
+        urlParams = self.getParams(param=param, val=val, params=params)
         # quote values and assemble into query string (not escaping '/')
         ps = paramSep.join(["%s=%s"%(k,urllib.quote_plus(v,'/')) for (k, v) in urlParams.items()])
-        #ps = urllib.urlencode(urlParams)
         if baseUrl is None:
-            baseUrl = self.REQUEST['URL1']
+            baseUrl = self.getDocumentViewerURL()
             
         url = "%s?%s"%(baseUrl, ps)
         return url
-
 
     def getLinkAmp(self, param=None, val=None, params=None, baseUrl=None):
         """link to documentviewer with parameter param set to val"""
         return self.getLink(param, val, params, baseUrl, '&amp;')
+    
     
     def getInfo_xml(self,url,mode):
@@ -465,5 +462,4 @@
         if metaDom is not None:
             # document directory name and path
-            logging.debug("RESOURCE: %s"%repr(self.metadataService.resource.meta.getData(dom=metaDom, all=True, recursive=2)))
             resource = self.metadataService.getResourceData(dom=metaDom)
             if resource:
@@ -573,5 +569,5 @@
         docinfo['oddPage'] = texttool.get('odd-scan-orientation', 'left')
             
-        # number of title page
+        # number of title page (0: not defined)
         docinfo['titlePage'] = texttool.get('title-scan-no', 0)
             
@@ -673,5 +669,4 @@
         pageinfo = {}
         current = getInt(current)
-    
         pageinfo['current'] = current
         rows = int(rows or self.thumbrows)
@@ -686,10 +681,18 @@
         pageinfo['start'] = start
         pageinfo['end'] = start + grpsize
-        if (docinfo is not None) and ('numPages' in docinfo):
-            np = int(docinfo['numPages'])
-            pageinfo['end'] = min(pageinfo['end'], np)
-            pageinfo['numgroups'] = int(np / grpsize)
-            if np % grpsize > 0:
-                pageinfo['numgroups'] += 1
+        pn = self.REQUEST.get('pn','1')
+        pageinfo['pn'] = pn
+        np = int(docinfo.get('numPages', 0))
+        if np == 0:
+            # numPages unknown - maybe we can get it from text page
+            if docinfo.get('textURLPath', None):
+                # cache text page as well
+                pageinfo['textPage'] = self.getTextPage(mode=viewMode, pn=pn, docinfo=docinfo, pageinfo=pageinfo)
+                np = int(docinfo.get('numPages', 0))
+                
+        pageinfo['end'] = min(pageinfo['end'], np)
+        pageinfo['numgroups'] = int(np / grpsize)
+        if np % grpsize > 0:
+            pageinfo['numgroups'] += 1
                 
         pageinfo['viewMode'] = viewMode
@@ -700,5 +703,4 @@
         pageinfo['queryType'] = self.REQUEST.get('queryType','')
         pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext')
-        pageinfo['textPN'] = self.REQUEST.get('textPN','1')
         pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','')
         pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30')
@@ -722,5 +724,4 @@
             
         pageinfo['searchPN'] =self.REQUEST.get('searchPN','1')
-        pageinfo['sn'] =self.REQUEST.get('sn','')
         return pageinfo
 
