Index: MpdlXmlTextServer.py
===================================================================
--- MpdlXmlTextServer.py	(revision 517)
+++ MpdlXmlTextServer.py	(revision 518)
@@ -74,6 +74,18 @@
     def getTextInfo(self, mode='', docinfo=None):
         """reads document info, including page concordance, from text server"""
-        logging.debug("getDocInfo")
-        #TODO: check cached info
+        logging.debug("getTextInfo mode=%s"%mode)
+        if mode not in ['toc', 'figures', '']:
+            mode = ''
+        # check cached info
+        if mode:
+            # cached toc-request?
+            if 'full_%s'%mode in docinfo:
+                return docinfo
+            
+        else:
+            # no toc-request
+            if 'numTextPages' in docinfo:
+                return docinfo
+                
         docpath = docinfo.get('textURLPath', None)
         if docpath is None:
@@ -84,5 +96,5 @@
         pagesize = 10000
         pn = 1
-        # fetch docinfo
+        # fetch docinfo            
         pagexml = self.getServerData("doc-info.xql","document=%s&info=%s&pageSize=%s&pn=%s"%(docpath,mode,pagesize,pn))
         dom = ET.fromstring(pagexml)
@@ -127,5 +139,5 @@
                             if p.tag == 'n':
                                 n = getInt(p.text)
-                                page['n'] = n
+                                page['pn'] = n
                             elif p.tag == 'no':
                                 page['no'] = p.text
@@ -141,7 +153,25 @@
                 # toc
                 elif name == 'toc':
-                    # contains tags with table of contents
-                    # TODO: implement
-                    pass
+                    # contains tags with table of contents/figures
+                    # <toc-entry><page>13</page><level>3</level><content>Chapter I</content><level-string>1.</level-string><real-level>1</real-level></toc-entry>
+                    tocs = []
+                    for te in tag:
+                        toc = {}
+                        for t in te:
+                            if t.tag == 'page':
+                                toc['pn'] = getInt(t.text)
+                            elif t.tag == 'level':
+                                toc['level'] = t.text
+                            elif t.tag == 'content':
+                                toc['content'] = t.text
+                            elif t.tag == 'level-string':
+                                toc['level-string'] = t.text
+                            elif t.tag == 'real-level':
+                                toc['real-level'] = t.text
+                                
+                        tocs.append(toc)
+                    
+                    # save as full_toc/full_figures
+                    docinfo['full_%s'%mode] = tocs
 
         return docinfo
@@ -430,5 +460,50 @@
 
 
-    def getToc(self, mode="text", docinfo=None):
+    def getToc(self, mode='text', docinfo=None):
+        """returns list of table of contents from docinfo"""
+        logging.debug("getToc mode=%s"%mode)
+        if mode == 'text':
+            queryType = 'toc'
+        else:
+            queryType = mode
+            
+        if not 'full_%s'%queryType in docinfo:
+            # get new toc
+            docinfo = self.getTextInfo(queryType, docinfo)
+            
+        return docinfo.get('full_%s'%queryType, [])
+
+    def getTocPage(self, mode='text', pn=None, start=None, size=None, pageinfo=None, docinfo=None):
+        """returns single page from the table of contents"""
+        logging.debug("getTocPage mode=%s, pn=%s start=%s size=%s"%(mode,repr(pn),repr(start),repr(size)))
+        fulltoc = self.getToc(mode=mode, docinfo=docinfo)
+        if len(fulltoc) < 1:
+            logging.error("getTocPage: unable to find toc!")
+            return "Error: no table of contents!"        
+        
+        if size is None:
+            size = pageinfo.get('tocPageSize', 30)
+            
+        if start is None:
+            start = (pn - 1) * size
+
+        # paginate
+        first = (start - 1)
+        last = first + size
+        tocs = fulltoc[first:last]
+        tp = '<div>'
+        for toc in tocs:
+            pageurl = self.getLink('pn', toc['pn'])
+            tp += '<div class="tocline">'
+            tp += '<div class="toc name">[%s %s]</div>'%(toc['level-string'], toc['content'])
+            tp += '<div class="toc float right page"><a href="%s">Page: %s</a></div>'%(pageurl, toc['pn'])
+            tp += '</div>\n'
+            
+        tp += '</div>'
+        
+        return tp
+       
+
+    def getToc_old(self, mode="text", docinfo=None):
         """loads table of contents and stores XML in docinfo"""
         logging.debug("getToc mode=%s"%mode)
@@ -473,5 +548,5 @@
         return docinfo
     
-    def getTocPage(self, mode="text", pn=None, start=None, size=None, pageinfo=None, docinfo=None):
+    def getTocPage_old(self, mode="text", pn=None, start=None, size=None, pageinfo=None, docinfo=None):
         """returns single page from the table of contents"""
         logging.debug("getTocPage mode=%s, pn=%s"%(mode,pn))
