Index: MpdlXmlTextServer.py
===================================================================
--- MpdlXmlTextServer.py	(revision 418)
+++ MpdlXmlTextServer.py	(revision 419)
@@ -39,10 +39,10 @@
         return documentViewer.getHttpData(url,data,timeout=self.timeout)
 
-    def getSearch(self, pn=1, pageinfo=None,  docinfo=None, query=None, queryType=None, lemma=None, characterNormalization=None, optionToggle=None):
+    def getSearch(self, pageinfo=None,  docinfo=None,   lemma=None):
         """get search list"""
         docpath = docinfo['textURLPath'] 
         url = docinfo['url']
         pagesize = pageinfo['queryPageSize']
-        pn = pageinfo['searchPN']
+        pn = pageinfo.get('searchPN',1)
         sn = pageinfo['sn']
         highlightQuery = pageinfo['highlightQuery']
@@ -57,8 +57,21 @@
         
         data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&characterNormalization=%s&optionToggle=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, sn, viewMode,characterNormalization,optionToggle ,urllib.quote(highlightQuery)))
-        #page=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&highlightQuery=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn, viewMode,highlightQuery) ,outputUnicode=False)                
-        
+                              
         pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url)
         pagedom = Parse(pagexml)
+        
+        """
+        pagedivs = pagedom.xpath("//div[@class='queryResultHits']") 
+        if (pagedivs == pagedom.xpath("//div[@class='queryResultHits']")):
+            if len(pagedivs)>0:
+                docinfo['queryResultHits'] = int(getTextFromNode(pagedivs[0]))
+                s = getTextFromNode(pagedivs[0])
+                s1 = int(s)/10+1
+                try:
+                    docinfo['queryResultHits'] = int(s1)
+                    logging.debug("SEARCH ENTRIES: %s"%(s1))
+                except:
+                    docinfo['queryResultHits'] = 0
+        """
         if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"):   
             pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
@@ -118,34 +131,5 @@
         return "no text here"   
                        
-    
-    def getNumTextPages (self, docinfo=None):
-        """get list of pages from fulltext (texts without images) and put in docinfo"""
-        logging.debug("getNumTextPages")
-        docpath = docinfo['textURLPath'] 
-        selfurl = self.absolute_url()   
-        #viewMode=  pageinfo['viewMode']
-        if 'numPages' in docinfo:
-            # allredy there
-            return docinfo
-        
-        text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))
-        dom =Parse(text)
-        pagedivs = dom.xpath("//div[@class='countPages']")
-        logging.debug ("pagedivs=%s"%(pagedivs))
-        if len(pagedivs)>0:
-            docinfo['numPages']= int(getTextFromNode(pagedivs[0]))
-            return docinfo
-     
-    def getTocEntries (self, docinfo=None):
-        """ number of text entries"""
-        docinfo = self.getInfoFromPage(docinfo)
-        logging.debug("gettocentries: docinfo=%s"%docinfo)
-        return docinfo['tocEntries']
-            
-    def getFigureEntries (self, docinfo=None):
-        """ number of figure entries"""
-        docinfo = self.getInfoFromPage(docinfo)
-        return docinfo['figureEntries']
-                       
+           
     def getGisPlaces(self, docinfo=None, pageinfo=None):
         """ Show all Gis Places of whole Page"""
@@ -191,78 +175,17 @@
             logging.debug("getALLGisPlaces :%s"%(myList))
         return myList
-               
-    def getOrigPages (self, docinfo=None, pageinfo=None):
-        """Show original page """
-        docpath = docinfo.get('textURLPath',None)
-        if not docpath:
-            return None
-        selfurl = self.absolute_url()
-        pn =pageinfo['current']
-       
-        viewMode=  pageinfo['viewMode']
-        text = self.getServerData("page-fragment.xql","document=%s&mode=%s&pn=%s"%(docinfo['textURLPath'], 'text',  pn))
-        dom =Parse(text)
-        pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
-        if len(pagedivs)>0:
-            originalPage= getTextFromNode(pagedivs[0])
-            #return docinfo['originalPage']
-            return originalPage
-    
-    def getAllPlaces (self, docinfo=None):
-        """Show all Places if no places than 0"""
-        docinfo = self.getInfoFromPage(docinfo)
-        return docinfo['allPlaces']
-
-    def getInfoFromPage(self, docinfo=None):
-        """ extract diverse info from page-fragment"""
-        docpath = docinfo['textURLPath']
-        if 'allPlaces' in docinfo:
-            # allredy there
-            return docinfo
-        
-        if (docpath is not None):   
-            text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))
-            dom = Parse(text)
-            # figureEntries
-            pagedivs = dom.xpath("//div[@class='countFigureEntries']")
-            s = getTextFromNode(pagedivs[0])
-            try:
-                docinfo['figureEntries'] = int(s)
-            except:
-                docinfo['figureEntries'] = 0
-            # tocEntries
-            pagedivs = dom.xpath("//div[@class='countTocEntries']")
-            s = getTextFromNode(pagedivs[0])
-            try:
-                docinfo['tocEntries'] = int(s)
-            except:
-                docinfo['tocEntries'] = 0
-            # allPlaces
-            pagedivs = dom.xpath("//div[@class='countPlaces']")
-            s = getTextFromNode(pagedivs[0])
-            try:
-                docinfo['allPlaces'] = int(s)
-            except:
-                docinfo['allPlaces'] = 0
-                
-        else:
-            # no full text -- init to 0
-            docinfo['figureEntries'] = 0
-            docinfo['tocEntries'] = 0
-            docinfo['allPlaces'] = 0
-
-        return docinfo
-                       
+          
            
-    def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None, viewMode=None, tocMode=None, tocPN=None, characterNormalization="reg", highlightQuery=None, sn=None, optionToggle=None):
+    def getTextPage(self, docinfo=None, pageinfo=None):
         """returns single page from fulltext"""
         docpath = docinfo['textURLPath']
         path = docinfo['textURLPath']
-        url = docinfo['url']
-        name = docinfo['name']
-        viewMode= pageinfo['viewMode']
+        url = docinfo.get('url',None)
+        name = docinfo.get('name',None)
+        pn =pageinfo['current']
+        #viewMode= pageinfo['viewMode']
         sn = pageinfo['sn']
         highlightQuery = pageinfo['highlightQuery']
-        
+        mode = pageinfo ['viewMode']
         tocMode = pageinfo['tocMode']
         characterNormalization=pageinfo['characterNormalization']
@@ -273,18 +196,103 @@
         else:
             textmode = mode
-        #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
+        
         textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization)
         if highlightQuery is not None:
             textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn)           
-            #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
+        
         pagexml = self.getServerData("page-fragment.xql",textParam)
-        logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
-        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False)
-        
-        pagedom = Parse(pagexml)
+        dom = Parse(pagexml)
+        
+        #original Pages
+        pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
+        if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
+            if len(pagedivs)>0:
+                docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])
+                logging.debug("ORIGINAL PAGES: %s"%(docinfo['pageNumberOrig']))
+                          
+        #figureEntries
+        pagedivs = dom.xpath("//div[@class='countFigureEntries']")
+        if pagedivs == dom.xpath("//div[@class='countFigureEntries']"):
+            if len(pagedivs)>0:
+                docinfo['countFigureEntries'] = getTextFromNode(pagedivs[0])
+                s = getTextFromNode(pagedivs[0])
+                if s=='0':
+                    try:
+                        docinfo['countFigureEntries'] = int(s)
+                        logging.debug("FIGURE ENTRIES: %s"%(s))
+                    except:
+                        docinfo['countFigureEntries'] = 0
+                else:
+                    s1 = int(s)/30+1
+                    try:
+                        docinfo['countFigureEntries'] = int(s1)
+                        logging.debug("FIGURE ENTRIES: %s"%(s1))
+                    except:
+                        docinfo['countFigureEntries'] = 0      
+        
+        #allPlaces
+        pagedivs = dom.xpath("//div[@class='countPlaces']")
+        if pagedivs == dom.xpath("//div[@class='countPlaces']"):
+            if len(pagedivs)>0:
+                docinfo['countPlaces']= getTextFromNode(pagedivs[0])
+                s = getTextFromNode(pagedivs[0])
+                try:
+                    docinfo['countPlaces'] = int(s)
+                    logging.debug("PLACES HERE: %s"%(s))
+                except:
+                    docinfo['countPlaces'] = 0
+        
+        #tocEntries
+        pagedivs = dom.xpath("//div[@class='countTocEntries']")
+        if pagedivs == dom.xpath("//div[@class='countTocEntries']"):
+            if len(pagedivs)>0:
+                docinfo['countTocEntries'] = int(getTextFromNode(pagedivs[0]))
+                s = getTextFromNode(pagedivs[0])
+                if s=='0':
+                    try:
+                        docinfo['countTocEntries'] = int(s)
+                        logging.debug("TEXT ENTRIES: %s"%(s))
+                    except:
+                        docinfo['countTocEntries'] = 0
+                else:
+                    s1 = int(s)/30+1
+                    try:
+                        docinfo['countTocEntries'] = int(s1)
+                        logging.debug("TEXT ENTRIES: %s"%(s1))
+                    except:
+                        docinfo['countTocEntries'] = 0
+        
+        #numTextPages
+        pagedivs = dom.xpath("//div[@class='countPages']")
+        if pagedivs == dom.xpath("//div[@class='countPages']"):
+            if len(pagedivs)>0:
+                docinfo['numPages'] = getTextFromNode(pagedivs[0])
+                s = getTextFromNode(pagedivs[0])
+                
+                try:
+                    docinfo['numPages'] = int(s)
+                    logging.debug("PAGE NUMBER: %s"%(s))
+                
+                    np = docinfo['numPages']
+                    pageinfo['end'] = min(pageinfo['end'], np)
+                    pageinfo['numgroups'] = int(np / pageinfo['groupsize'])
+                    if np % pageinfo['groupsize'] > 0:
+                        pageinfo['numgroups'] += 1                
+                except:
+                    docinfo['numPages'] = 0
+                  
+        else:
+         #no full text -- init to 0
+            docinfo['pageNumberOrig'] = 0
+            docinfo['countFigureEntries'] = 0
+            docinfo['countPlaces'] = 0
+            docinfo['countTocEntries'] = 0
+            docinfo['numPages'] = 0
+        #return docinfo
+        
         # plain text mode
         if mode == "text":
             # first div contains text
-            pagedivs = pagedom.xpath("/div")
+            pagedivs = dom.xpath("/div")
             if len(pagedivs) > 0:      
                 pagenode = pagedivs[0]
@@ -299,5 +307,5 @@
         if mode == "xml":
               # first div contains text
-              pagedivs = pagedom.xpath("/div")
+              pagedivs = dom.xpath("/div")
               if len(pagedivs) > 0:
                   pagenode = pagedivs[0]
@@ -305,5 +313,5 @@
         if mode == "gis":
               # first div contains text
-              pagedivs = pagedom.xpath("/div")
+              pagedivs = dom.xpath("/div")
               if len(pagedivs) > 0:
                   pagenode = pagedivs[0]
@@ -320,5 +328,5 @@
         if mode == "pureXml":
               # first div contains text
-              pagedivs = pagedom.xpath("/div")
+              pagedivs = dom.xpath("/div")
               if len(pagedivs) > 0:
                   pagenode = pagedivs[0]
@@ -327,5 +335,5 @@
         if mode == "text_dict":
             # first div contains text
-            pagedivs = pagedom.xpath("/div")
+            pagedivs = dom.xpath("/div")
             if len(pagedivs) > 0:
                 pagenode = pagedivs[0]
@@ -376,5 +384,5 @@
     
     def getQuery (self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionToggle=None):
-         """number of"""
+         #number of
          docpath = docinfo['textURLPath'] 
          pagesize = pageinfo['queryPageSize']
@@ -386,5 +394,4 @@
          
          pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn))
-         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, query, pagesize, pn) ,outputUnicode=False)
          pagedom = Parse(pagexml)
          numdivs = pagedom.xpath("//div[@class='queryResultHits']")
@@ -394,56 +401,5 @@
          logging.debug("documentViewer (gettoc) tc: %s"%(tc))
          return tc
-
-    def getQueryResultHits(self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionsClose=None):
-        
-         """number of hits in Search mode"""
-         docpath = docinfo['textURLPath'] 
-         pagesize = pageinfo['queryPageSize']
-         pn = pageinfo['searchPN']
-         query =pageinfo['query']
-         queryType =pageinfo['queryType']
-         tocSearch = 0
-         tocDiv = None
-         
-         pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn))
-         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, query, pagesize, pn) ,outputUnicode=False)
-         pagedom = Parse(pagexml)
-         numdivs = pagedom.xpath("//div[@class='queryResultHits']")
-         tocSearch = int(getTextFromNode(numdivs[0])) 
-         tc=int((tocSearch/10)+1)   
-         return tc
-     
-    def getQueryResultHitsText(self,  docinfo=None, pageinfo=None):      
-         """number of hits in Text of Contents mode"""
-         selfurl = self.absolute_url()
-         docpath = docinfo['textURLPath']
-         viewMode=  pageinfo['viewMode']
-         text = self.getServerData("page-fragment.xql","document=%s&mode=%s"%(docinfo['textURLPath'], 'text'))
-         dom =Parse(text)
-         pagedivs = dom.xpath("//div[@class='countTocEntries']")
-         logging.debug ("pagedivs=%s"%(pagedivs))
-         if len(pagedivs)>0:
-            originalPage= (getTextFromNode(pagedivs[0]))
-            tc = int (originalPage)
-            tc1 =tc/30+1
-            return tc1
-         
-    def getQueryResultHitsFigures(self,  docinfo=None, pageinfo=None):      
-         """number of hits in Text of Figures mode"""
-         
-         selfurl = self.absolute_url()
-         docpath = docinfo['textURLPath']
-         viewMode=  pageinfo['viewMode']
-         text = self.getServerData("page-fragment.xql","document=%s&mode=%s"%(docinfo['textURLPath'], 'text'))
-         dom =Parse(text)
-         pagedivs = dom.xpath("//div[@class='countFigureEntries']")
-         logging.debug ("pagedivs=%s"%(pagedivs))
-         if len(pagedivs)>0:
-            originalPage= (getTextFromNode(pagedivs[0]))
-            tc = int (originalPage)
-            tc1 =tc/30+1
-            return tc1 
-
-
+    
     def getToc(self, mode="text", docinfo=None):
         """loads table of contents and stores in docinfo"""
@@ -468,5 +424,5 @@
         
         pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))
-        #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)
@@ -500,6 +456,6 @@
         page = data.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&optionToggle=1'%(selfurl,url, viewMode, tocMode, tocPN))
         text = page.replace('mode=image','mode=texttool')
-        logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization))
-        #logging.debug("documentViewer (characterNormalization) text: %s"%(text))
+        #logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization))
+        
         return text
     
Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 413)
+++ documentViewer.py	(revision 419)
@@ -199,19 +199,7 @@
 
     def getQuery(self, **args):
-        """get query"""
+        """get query in search"""
         return self.template.fulltextclient.getQuery(**args)
-    
-    def getQueryResultHits(self, **args):
-        """get query"""
-        return self.template.fulltextclient.getQueryResultHits(**args)
-    
-    def getQueryResultHitsText(self, **args):
-        """get query"""
-        return self.template.fulltextclient.getQueryResultHitsText(**args)
-    
-    def getQueryResultHitsFigures(self, **args):
-        """get query"""
-        return self.template.fulltextclient.getQueryResultHitsFigures(**args)
-    
+     
     def getSearch(self, **args):
         """get search"""
@@ -225,29 +213,5 @@
         """get all gis places """
         return self.template.fulltextclient.getAllGisPlaces(**args)
-    
-    def getOrigPages(self, **args):
-        """get original page number """
-        return self.template.fulltextclient.getOrigPages(**args)
-    
-    def getAllPlaces(self, **args):
-        """get original page number """
-        return self.template.fulltextclient.getAllPlaces(**args)
-    
-    def getTocEntries(self, **args):
-        """get original page number """
-        return self.template.fulltextclient.getTocEntries(**args)
-    
-    def getFigureEntries(self, **args):
-        """get original page number """
-        return self.template.fulltextclient.getFigureEntries(**args)    
-    
-    def getNumPages(self, docinfo):
-        """get numpages"""
-        return self.template.fulltextclient.getNumPages(docinfo)
-   
-    def getNumTextPages(self, docinfo):
-        """get numpages text"""
-        return self.template.fulltextclient.getNumTextPages(docinfo)
-   
+       
     def getTranslate(self, **args):
         """get translate"""
@@ -336,4 +300,7 @@
         pageinfo = self.getPageinfo(start=start,current=pn, docinfo=docinfo,viewMode=viewMode,tocMode=tocMode)
         
+        if (docinfo.get('textURLPath',None)):
+            page = self.getTextPage(docinfo=docinfo, pageinfo=pageinfo)
+            pageinfo['textPage'] = page
         pt = getattr(self.template, 'viewer_main')               
         return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode,mk=self.generateMarks(mk))
@@ -725,7 +692,8 @@
             textUrl = getTextFromNode(textUrls[0])
             docinfo['textURLPath'] = textUrl
-            if not docinfo['imagePath']:
+            #if not docinfo['imagePath']:
                 # text-only, no page images
-                docinfo = self.getNumTextPages(docinfo)
+                #docinfo = self.getNumTextPages(docinfo)
+                  
          
         presentationUrls = dom.xpath("//texttool/presentation")
@@ -855,4 +823,5 @@
         pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10')
         pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')
+        
         toc = int (pageinfo['tocPN'])
         pageinfo['textPages'] =int (toc)
