Index: MpiwgXmlTextServer.py
===================================================================
--- MpiwgXmlTextServer.py	(revision 567)
+++ MpiwgXmlTextServer.py	(revision 568)
@@ -94,5 +94,5 @@
         
         field = ''
-        if mode in ['pages', 'toc', 'figures']:
+        if mode in ['pages', 'toc', 'figures', 'handwritten']:
             # translate mode to field param
             field = '&field=%s'%mode
@@ -126,7 +126,10 @@
             if mode is None:
                 # get general info from system-tag
-                cp = doc.find('system/countPages')
-                if cp is not None:
-                    docinfo['numTextPages'] = getInt(cp.text) 
+                sys = doc.find('system')
+                if sys is not None:
+                    docinfo['numTextPages'] = getInt(getText(sys.find('countPages'))) 
+                    docinfo['numFigureEntries'] = getInt(getText(sys.find('countFigures'))) 
+                    docinfo['numHandwritten'] = getInt(getText(sys.find('countHandwritten'))) 
+                    docinfo['numTocEntries'] = getInt(getText(sys.find('countTocEntries'))) 
                     
             else:
@@ -146,7 +149,7 @@
                             pn = getInt(i.get('n'))
                             page['pn'] = pn
-                            no = getInt(i.get('o'))
+                            no = i.get('o')
                             page['no'] = no
-                            non = getInt(i.get('o-norm'))
+                            non = i.get('o-norm')
                             page['non'] = non
                                     
@@ -158,23 +161,19 @@
                                     
                     # toc
-                    elif name == 'toc':
+                    elif lt == 'toc' or lt == 'figures' or lt == 'handwritten':
                         # 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>
+                        # <item n="2.1." lv="2">CAP.I. <ref o="119">132</ref></item>
                         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)
+                        for te in l:
+                            if te.tag == 'item':
+                                toc = {}
+                                toc['level-string'] = te.get('n')
+                                toc['level'] = te.get('lv')
+                                toc['content'] = te.text.strip()
+                                ref = te.find('ref')
+                                toc['pn'] = getInt(ref.text)
+                                toc['no'] = ref.get('o')
+                                toc['non'] = ref.get('o-norm')
+                                tocs.append(toc)
                         
                         # save as full_toc/full_figures
@@ -184,32 +183,4 @@
         
           
-    def processPageInfo(self, dom, docinfo, pageinfo):
-        """processes page info divs from dom and stores in docinfo and pageinfo"""
-        # assume first second level div is pageMeta
-        alldivs = dom.find("div")
-        
-        if alldivs is None or alldivs.get('class', '') != 'pageMeta':
-            logging.error("processPageInfo: pageMeta div not found!")
-            return
-        
-        for div in alldivs:
-            dc = div.get('class')
-            
-            # pageNumberOrig  
-            if dc == 'pageNumberOrig':
-                pageinfo['pageNumberOrig'] = div.text
-                
-            # pageNumberOrigNorm
-            elif dc == 'pageNumberOrigNorm':
-                pageinfo['pageNumberOrigNorm'] = div.text
-                
-            # pageHeaderTitle
-            elif dc == 'pageHeaderTitle':
-                pageinfo['pageHeaderTitle'] = div.text
-                        
-        #logging.debug("processPageInfo: pageinfo=%s"%repr(pageinfo))
-        return
-         
-           
     def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None):
         """returns single page from fulltext"""
@@ -452,4 +423,6 @@
             return docinfo
               
+        #TODO: put mode into query
+        
         cachedQuery = docinfo.get('cachedQuery', None)
         if cachedQuery is not None:
@@ -462,5 +435,5 @@
                 # different query
                 del docinfo['resultSize']
-                del docinfo['resultXML']
+                del docinfo['results']
         
         # cache query
@@ -469,30 +442,25 @@
         # fetch full results
         docpath = docinfo['textURLPath']
-        params = {'document': docpath,
-                  'mode': 'text',
-                  'queryType': mode,
+        params = {'docId': docpath,
                   'query': query,
-                  'queryResultPageSize': 1000,
-                  'queryResultPN': 1,
-                  'characterNormalization': pageinfo.get('characterNormalization', 'reg')}
-        pagexml = self.getServerData("doc-query.xql",urllib.urlencode(params))
-        #pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&s=%s&viewMode=%s&characterNormalization=%s&highlightElementPos=%s&highlightElement=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, s, viewMode,characterNormalization, highlightElementPos, highlightElement, urllib.quote(highlightQuery)))
-        dom = ET.fromstring(pagexml)
-        # page content is in <div class="queryResultPage">
-        pagediv = None
-        # ElementTree 1.2 in Python 2.6 can't do div[@class='queryResultPage']
-        alldivs = dom.findall("div")
-        for div in alldivs:
-            dc = div.get('class')
-            # page content div
-            if dc == 'queryResultPage':
-                pagediv = div
-                
-            elif dc == 'queryResultHits':
-                docinfo['resultSize'] = getInt(div.text)
-
-        if pagediv is not None:
-            # store XML in docinfo
-            docinfo['resultXML'] = ET.tostring(pagediv, 'UTF-8')
+                  'pageSize': 1000,
+                  'page': 1,
+                  'outputFormat': 'html'}
+        pagexml = self.getServerData("query/QueryDocument",urllib.urlencode(params))
+        results = []
+        try:
+            dom = ET.fromstring(pagexml)
+            # page content is currently in multiple <td align=left>
+            alldivs = dom.findall(".//td[@align='left']")
+            for div in alldivs:
+                # TODO: can we put etree in the session?
+                results.append(div)
+        
+        except Exception, e:
+            logging.error("GetSearchResults: Error parsing search result: %s"%e)
+                
+        # store results in docinfo
+        docinfo['resultSize'] = len(results)
+        docinfo['results'] = results
 
         return docinfo
@@ -505,7 +473,7 @@
         self.getSearchResults(mode=mode, query=query, pageinfo=pageinfo, docinfo=docinfo)
             
-        resultxml = docinfo.get('resultXML', None)
+        resultxml = docinfo.get('results', None)
         if not resultxml:
-            logging.error("getResultPage: unable to find resultXML")
+            logging.error("getResultPage: unable to find results")
             return "Error: no result!"
         
@@ -562,4 +530,5 @@
         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"""
@@ -584,6 +553,15 @@
             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'])
+            content = toc['content']
+            if content:
+                tp += '<div class="toc name">[%s] %s</div>'%(toc['level-string'], toc['content'])
+            else:
+                tp += '<div class="toc name">[Figure %s]</div>'%(toc['level-string'])
+            
+            if toc.get('no', None):
+                tp += '<div class="toc page"><a href="%s">Page: %s (%s)</a></div>'%(pageurl, toc['pn'], toc['no'])
+            else:
+                tp += '<div class="toc page"><a href="%s">Page: %s</a></div>'%(pageurl, toc['pn'])
+                
             tp += '</div>\n'
             
Index: css/docuviewer.css
===================================================================
--- css/docuviewer.css	(revision 567)
+++ css/docuviewer.css	(revision 568)
@@ -147,13 +147,14 @@
 }
 
-div.tocbody.text .toc, 
-div.tocbody.figures .toc,
-div.tocbody.concordance .toc {
+div.tocbody.text .toc.name, 
+div.tocbody.figures .toc.name,
+div.tocbody.concordance .toc.name {
     float:left;
     clear:right; 
-}
-div.tocbody.text .toc.float.right, 
-div.tocbody.figures .toc.float.right,
-div.tocbody.concordance .toc.float.right {
+    margin-right: 1em;
+}
+div.tocbody.text .toc.page, 
+div.tocbody.figures .toc.page,
+div.tocbody.concordance .toc.page {
     float:right;
 }
@@ -273,9 +274,7 @@
 	display: none;
 }
+/* running head */
 div.col.main div.content.text span.pb span.rhead {
-	display: block;
-}
-/* running head */
-div.col.main div.content.text div.pageHeaderTitle {
+    display: block;
     text-align: center;
     margin-bottom: 1em;
Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 566)
+++ documentViewer.py	(revision 568)
@@ -589,7 +589,9 @@
             if texttool:
                 docinfo = self.getDocinfoFromTexttool(docinfo, texttool)
-                # document info (including toc) from full text
+                # document info from full text server
                 if docinfo.get('textURLPath', None):
                     docinfo = self.getTextInfo(mode=None, docinfo=docinfo)
+                    # include list of pages TODO: do we need this always? 
+                    docinfo = self.getTextInfo(mode='pages', docinfo=docinfo)
             
             # bib info
