Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 84)
+++ documentViewer.py	(revision 90)
@@ -88,8 +88,10 @@
     # templates and forms
     viewer_main = PageTemplateFile('zpt/viewer_main', globals())
-    thumbs_main = PageTemplateFile('zpt/thumbs_main', globals())
-    image_main = PageTemplateFile('zpt/image_main', globals()) # obsolete!
+    toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals())
+    toc_text = PageTemplateFile('zpt/toc_text', globals())
+    toc_figures = PageTemplateFile('zpt/toc_figures', globals())
     page_main_images = PageTemplateFile('zpt/page_main_images', globals())
     page_main_text = PageTemplateFile('zpt/page_main_text', globals())
+    page_main_text_dict = PageTemplateFile('zpt/page_main_text_dict', globals())
     head_main = PageTemplateFile('zpt/head_main', globals())
     docuviewer_css = PageTemplateFile('css/docuviewer.css', globals())
@@ -162,11 +164,11 @@
   
     security.declareProtected('View','index_html')
-    def index_html(self,url,mode="texttool",viewMode="auto",start=None,pn=1,mk=None):
+    def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None):
         '''
         view it
         @param mode: defines how to access the document behind url 
         @param url: url which contains display information
-        @param viewMode: if images display images, if text display text, default is images (text,images or auto)
-        
+        @param viewMode: if images display images, if text display text, default is auto (text,images or auto)
+        @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures)
         '''
         
@@ -182,7 +184,9 @@
             
         docinfo = self.getDocinfo(mode=mode,url=url)
-        pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo)
-        pt = getattr(self.template, 'viewer_main')
-        
+        pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo,viewMode=viewMode,tocMode=tocMode)
+        if tocMode != "thumbs":
+            # get table of contents
+            docinfo = self.getToc(mode=tocMode, docinfo=docinfo)
+
         if viewMode=="auto": # automodus gewaehlt
             if docinfo.get("textURL",''): #texturl gesetzt und textViewer konfiguriert
@@ -190,17 +194,18 @@
             else:
                 viewMode="images"
-               
+                
+        pt = getattr(self.template, 'viewer_main')               
         return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode,mk=self.generateMarks(mk))
   
     def generateMarks(self,mk):
         ret=""
-	if mk is None:
-		return ""
-	
-	if type(mk) is not ListType:
-		mk=[mk]
+        if mk is None:
+            return ""
+    	if type(mk) is not ListType:
+    		mk=[mk]
         for m in mk:
             ret+="mk=%s"%m
         return ret
+
 
     def findDigilibUrl(self):
@@ -344,5 +349,5 @@
                 break
             except:
-                logger("ERROR documentViewer (getIndexMata)", logging.INFO,"%s (%s)"%sys.exc_info()[0:2])
+                logger("ERROR documentViewer (getIndexMeta)", logging.INFO,"%s (%s)"%sys.exc_info()[0:2])
                 
         if dom is None:
@@ -363,5 +368,4 @@
             server=self.digilibBaseUrl+"/servlet/Texter?fn="
             metaUrl=server+url.replace("/mpiwg/online","")
-           
         
         for cnt in range(num_retries):
@@ -462,5 +466,4 @@
         if docinfo is None:
            docinfo = {}
-            
         if docinfo.get('lang', None) is None:
             docinfo['lang'] = '' # default keine Sprache gesetzt
@@ -554,7 +557,4 @@
         
         return docinfo
-
-
-
    
    
@@ -619,5 +619,5 @@
         else:
             logger("documentViewer (getdocinfo)", logging.ERROR,"unknown mode!")
-            raise ValueError("Unknown mode %s"%(mode))
+            raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode))
                         
         logger("documentViewer (getdocinfo)", logging.INFO,"docinfo: %s"%docinfo)
@@ -626,5 +626,5 @@
         
         
-    def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None):
+    def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None, viewMode=None, tocMode=None):
         """returns pageinfo with the given parameters"""
         pageinfo = {}
@@ -641,5 +641,5 @@
         pageinfo['start'] = start
         pageinfo['end'] = start + grpsize
-        if docinfo is not None:
+        if (docinfo is not None) and ('numPages' in docinfo):
             np = int(docinfo['numPages'])
             pageinfo['end'] = min(pageinfo['end'], np)
@@ -647,4 +647,9 @@
             if np % grpsize > 0:
                 pageinfo['numgroups'] += 1
+                
+        pageinfo['viewMode'] = viewMode
+        pageinfo['tocMode'] = tocMode
+        pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '10')
+        pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')
 
         return pageinfo
@@ -662,5 +667,11 @@
     def getTextPage(self, mode="text", pn=1, docinfo=None):
         """returns single page from fulltext"""
-        pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", "document=%s&mode=%s&pn=%s"%(docinfo['textURLPath'],mode,pn), outputUnicode=False)
+        docpath = docinfo['textURLPath']
+        if mode == "text_dict":
+            textmode = "textPollux"
+        else:
+            textmode = mode
+            
+        pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", "document=%s&mode=%s&pn=%s"%(docpath,textmode,pn), outputUnicode=False)
         # post-processing downloaded xml
         pagedom = Parse(pagexml)
@@ -674,5 +685,5 @@
 
         # text-with-links mode
-        if mode == "textPollux":
+        if mode == "text_dict":
             # first div contains text
             pagedivs = pagedom.xpath("/div")
@@ -697,4 +708,59 @@
         return "no text here"
 
+    def getToc(self, mode="text", docinfo=None):
+        """loads table of contents and stores in docinfo"""
+        logging.debug("documentViewer (gettoc) mode: %s"%(mode))
+        if 'tocSize_%s'%mode in docinfo:
+            # cached toc
+            return docinfo
+        
+        docpath = docinfo['textURLPath']
+        # we need to set a result set size
+        pagesize = 1000
+        pn = 1
+        if mode == "text":
+            queryType = "toc"
+        else:
+            queryType = mode
+        # number of entries in toc
+        tocSize = 0
+        tocDiv = None
+        pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False)
+        # post-processing downloaded xml
+        pagedom = Parse(pagexml)
+        # get number of entries
+        numdivs = pagedom.xpath("//div[@class='queryResultHits']")
+        if len(numdivs) > 0:
+            tocSize = int(getTextFromNode(numdivs[0]))
+            # div contains text
+            #pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
+            #if len(pagedivs) > 0:
+            #    tocDiv = pagedivs[0]
+
+        docinfo['tocSize_%s'%mode] = tocSize
+        #docinfo['tocDiv_%s'%mode] = tocDiv
+        return docinfo
+    
+    def getTocPage(self, mode="toc", pn=1, pageinfo=None, docinfo=None):
+        """returns single page from the table of contents"""
+        # TODO: this should use the cached TOC
+        if mode == "text":
+            queryType = "toc"
+        else:
+            queryType = mode
+        docpath = docinfo['textURLPath']
+        pagesize = pageinfo['tocPageSize']
+        pn = pageinfo['tocPN']
+        pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False)
+        # post-processing downloaded xml
+        pagedom = Parse(pagexml)
+        # div contains text
+        pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
+        if len(pagedivs) > 0:
+            pagenode = pagedivs[0]
+            return serializeNode(pagenode)
+        else:
+            return "No TOC!"
+
     
     def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=10,authgroups='mpiwg',RESPONSE=None):
