Diff for /documentViewer/MpdlXmlTextServer.py between versions 1.222 and 1.230

version 1.222, 2011/01/06 15:44:18 version 1.230, 2011/03/07 14:08:07
Line 3  from OFS.SimpleItem import SimpleItem Line 3  from OFS.SimpleItem import SimpleItem
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile   from Products.PageTemplates.PageTemplateFile import PageTemplateFile 
 from Ft.Xml import EMPTY_NAMESPACE, Parse  from Ft.Xml import EMPTY_NAMESPACE, Parse
   
   import md5
 import sys  import sys
 import logging  import logging
 import urllib  import urllib
Line 54  class MpdlXmlTextServer(SimpleItem): Line 55  class MpdlXmlTextServer(SimpleItem):
         optionToggle = pageinfo['optionToggle']          optionToggle = pageinfo['optionToggle']
         tocPN = pageinfo['tocPN']          tocPN = pageinfo['tocPN']
         selfurl = self.absolute_url()          selfurl = self.absolute_url()
           
         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)))          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)))
                                 
         pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url)          pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url)
         pagedom = Parse(pagexml)          pagedom = Parse(pagexml)
                   
Line 86  class MpdlXmlTextServer(SimpleItem): Line 85  class MpdlXmlTextServer(SimpleItem):
                             selfurl = self.absolute_url()                                          selfurl = self.absolute_url()            
                             pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&optionToggle=%s&characterNormalization=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN,optionToggle,characterNormalization))                              pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&optionToggle=%s&characterNormalization=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN,optionToggle,characterNormalization))
                             hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl)                                                                         hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl)                                           
                   #logging.debug("PUREXML :%s"%(serializeNode(pagenode)))
                 return serializeNode(pagenode)                          return serializeNode(pagenode)        
         if (queryType=="fulltextMorph"):          if (queryType=="fulltextMorph"):
             pagedivs = pagedom.xpath("//div[@class='queryResult']")              pagedivs = pagedom.xpath("//div[@class='queryResult']")
Line 130  class MpdlXmlTextServer(SimpleItem): Line 130  class MpdlXmlTextServer(SimpleItem):
                 return serializeNode(pagenode)                        return serializeNode(pagenode)      
         return "no text here"             return "no text here"   
                                                 
              
     def getGisPlaces(self, docinfo=None, pageinfo=None):      def getGisPlaces(self, docinfo=None, pageinfo=None):
         """ Show all Gis Places of whole Page"""          """ Show all Gis Places of whole Page"""
         xpath='//place'          xpath='//place'
Line 151  class MpdlXmlTextServer(SimpleItem): Line 150  class MpdlXmlTextServer(SimpleItem):
             href= hrefNode.nodeValue              href= hrefNode.nodeValue
             hrefList.append(href)              hrefList.append(href)
             myList = ",".join(hrefList)              myList = ",".join(hrefList)
         logging.debug("getGisPlaces :%s"%(myList))                                       #logging.debug("getGisPlaces :%s"%(myList))                             
         return myList          return myList
           
     def getAllGisPlaces (self, docinfo=None, pageinfo=None):      def getAllGisPlaces (self, docinfo=None, pageinfo=None):
Line 172  class MpdlXmlTextServer(SimpleItem): Line 171  class MpdlXmlTextServer(SimpleItem):
             href= hrefNode.nodeValue              href= hrefNode.nodeValue
             hrefList.append(href)              hrefList.append(href)
             myList = ",".join(hrefList)              myList = ",".join(hrefList)
             logging.debug("getALLGisPlaces :%s"%(myList))              #logging.debug("getALLGisPlaces :%s"%(myList))
         return myList          return myList
                       
                         
     def getTextPage(self, docinfo=None, pageinfo=None):      def getTextPage(self, mode="text_dict", pn=1, docinfo=None, pageinfo=None):
         """returns single page from fulltext"""          """returns single page from fulltext"""
         docpath = docinfo['textURLPath']          docpath = docinfo['textURLPath']
         path = docinfo['textURLPath']          path = docinfo['textURLPath']
         url = docinfo.get('url',None)          url = docinfo.get('url',None)
         name = docinfo.get('name',None)          name = docinfo.get('name',None)
         pn =pageinfo['current']          pn =pageinfo['current']
         #viewMode= pageinfo['viewMode']  
         sn = pageinfo['sn']          sn = pageinfo['sn']
         highlightQuery = pageinfo['highlightQuery']          highlightQuery = pageinfo['highlightQuery']
         mode = pageinfo ['viewMode']          #mode = pageinfo ['viewMode']
         tocMode = pageinfo['tocMode']          tocMode = pageinfo['tocMode']
         characterNormalization=pageinfo['characterNormalization']          characterNormalization=pageinfo['characterNormalization']
         tocPN = pageinfo['tocPN']          tocPN = pageinfo['tocPN']
Line 202  class MpdlXmlTextServer(SimpleItem): Line 200  class MpdlXmlTextServer(SimpleItem):
                   
         pagexml = self.getServerData("page-fragment.xql",textParam)          pagexml = self.getServerData("page-fragment.xql",textParam)
         dom = Parse(pagexml)          dom = Parse(pagexml)
           
         #original Pages          #original Pages
         pagedivs = dom.xpath("//div[@class='pageNumberOrig']")          pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
         if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):          """if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
             if len(pagedivs)>0:              if len(pagedivs)>0:
                 docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])                  docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])
                 logging.debug("ORIGINAL PAGES: %s"%(docinfo['pageNumberOrig']))                  logging.debug("ORIGINAL PAGE: %s"%(docinfo['pageNumberOrig']))
                                                       
           #original Pages Norm
           pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']")
           if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"):
               if len(pagedivs)>0:
                   docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0])
                   logging.debug("ORIGINAL PAGE NORM: %s"%(docinfo['pageNumberOrigNorm']))
           """
         #figureEntries          #figureEntries
         pagedivs = dom.xpath("//div[@class='countFigureEntries']")          pagedivs = dom.xpath("//div[@class='countFigureEntries']")
         if pagedivs == dom.xpath("//div[@class='countFigureEntries']"):          if pagedivs == dom.xpath("//div[@class='countFigureEntries']"):
Line 219  class MpdlXmlTextServer(SimpleItem): Line 223  class MpdlXmlTextServer(SimpleItem):
                 if s=='0':                  if s=='0':
                     try:                      try:
                         docinfo['countFigureEntries'] = int(s)                          docinfo['countFigureEntries'] = int(s)
                         logging.debug("FIGURE ENTRIES: %s"%(s))  
                     except:                      except:
                         docinfo['countFigureEntries'] = 0                          docinfo['countFigureEntries'] = 0
                 else:                  else:
                     s1 = int(s)/30+1                      s1 = int(s)/30+1
                     try:                      try:
                         docinfo['countFigureEntries'] = int(s1)                          docinfo['countFigureEntries'] = int(s1)
                         logging.debug("FIGURE ENTRIES: %s"%(s1))  
                     except:                      except:
                         docinfo['countFigureEntries'] = 0                                docinfo['countFigureEntries'] = 0      
                   
Line 238  class MpdlXmlTextServer(SimpleItem): Line 240  class MpdlXmlTextServer(SimpleItem):
                 s = getTextFromNode(pagedivs[0])                  s = getTextFromNode(pagedivs[0])
                 try:                  try:
                     docinfo['countPlaces'] = int(s)                      docinfo['countPlaces'] = int(s)
                     logging.debug("PLACES HERE: %s"%(s))  
                 except:                  except:
                     docinfo['countPlaces'] = 0                      docinfo['countPlaces'] = 0
                   
Line 251  class MpdlXmlTextServer(SimpleItem): Line 252  class MpdlXmlTextServer(SimpleItem):
                 if s=='0':                  if s=='0':
                     try:                      try:
                         docinfo['countTocEntries'] = int(s)                          docinfo['countTocEntries'] = int(s)
                         logging.debug("TEXT ENTRIES: %s"%(s))  
                     except:                      except:
                         docinfo['countTocEntries'] = 0                          docinfo['countTocEntries'] = 0
                 else:                  else:
                     s1 = int(s)/30+1                      s1 = int(s)/30+1
                     try:                      try:
                         docinfo['countTocEntries'] = int(s1)                          docinfo['countTocEntries'] = int(s1)
                         logging.debug("TEXT ENTRIES: %s"%(s1))  
                     except:                      except:
                         docinfo['countTocEntries'] = 0                          docinfo['countTocEntries'] = 0
                   
Line 271  class MpdlXmlTextServer(SimpleItem): Line 270  class MpdlXmlTextServer(SimpleItem):
                                   
                 try:                  try:
                     docinfo['numPages'] = int(s)                      docinfo['numPages'] = int(s)
                     logging.debug("PAGE NUMBER: %s"%(s))                      #logging.debug("PAGE NUMBER: %s"%(s))
                                   
                     np = docinfo['numPages']                      np = docinfo['numPages']
                     pageinfo['end'] = min(pageinfo['end'], np)                      pageinfo['end'] = min(pageinfo['end'], np)
Line 288  class MpdlXmlTextServer(SimpleItem): Line 287  class MpdlXmlTextServer(SimpleItem):
             docinfo['countPlaces'] = 0              docinfo['countPlaces'] = 0
             docinfo['countTocEntries'] = 0              docinfo['countTocEntries'] = 0
             docinfo['numPages'] = 0              docinfo['numPages'] = 0
               docinfo['pageNumberOrigNorm'] = 0
         #return docinfo          #return docinfo
                   
         # plain text mode          # plain text mode
Line 302  class MpdlXmlTextServer(SimpleItem): Line 302  class MpdlXmlTextServer(SimpleItem):
                     if hrefNode:                      if hrefNode:
                         href= hrefNode.nodeValue                          href= hrefNode.nodeValue
                         if href.startswith('#note-'):                          if href.startswith('#note-'):
                             hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))                              hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn))
                 return serializeNode(pagenode)                  return serializeNode(pagenode)
         if mode == "xml":          if mode == "xml":
               # first div contains text                # first div contains text
Line 334  class MpdlXmlTextServer(SimpleItem): Line 334  class MpdlXmlTextServer(SimpleItem):
         # text-with-links mode          # text-with-links mode
         if mode == "text_dict":          if mode == "text_dict":
             # first div contains text              # first div contains text
               #mode = pageinfo ['viewMode']
             pagedivs = dom.xpath("/div")              pagedivs = dom.xpath("/div")
             if len(pagedivs) > 0:              if len(pagedivs) > 0:
                 pagenode = pagedivs[0]                  pagenode = pagedivs[0]
Line 360  class MpdlXmlTextServer(SimpleItem): Line 361  class MpdlXmlTextServer(SimpleItem):
                             l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;")                              l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;")
                             l.setAttributeNS(None, 'onClick', 'popupWin.focus();')                                 l.setAttributeNS(None, 'onClick', 'popupWin.focus();')   
                         if href.startswith('#note-'):                          if href.startswith('#note-'):
                             hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))                                  hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text_dict&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn))    
                 return serializeNode(pagenode)                  return serializeNode(pagenode)
         return "no text here"          return "no text here"
   
       def getOrigPages(self, docinfo=None, pageinfo=None):
           docpath = docinfo['textURLPath']
           pn =pageinfo['current']
           selfurl = self.absolute_url()   
           pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
           dom = Parse(pagexml)
           pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
           if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
               if len(pagedivs)>0:
                   docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])        
                   return docinfo['pageNumberOrig']
       
       def getOrigPagesNorm(self, docinfo=None, pageinfo=None):
           docpath = docinfo['textURLPath']
           pn =pageinfo['current']
           selfurl = self.absolute_url()   
           pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
           dom = Parse(pagexml)
           pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']")
           if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"):
               if len(pagedivs)>0:
                   docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0])        
                   return docinfo['pageNumberOrigNorm']
   
                   
     def getTranslate(self, query=None, language=None):      def getTranslate(self, query=None, language=None):
         """translate into another languages"""          """translate into another languages"""
         data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))          data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))
Line 396  class MpdlXmlTextServer(SimpleItem): Line 422  class MpdlXmlTextServer(SimpleItem):
          pagedom = Parse(pagexml)           pagedom = Parse(pagexml)
          numdivs = pagedom.xpath("//div[@class='queryResultHits']")           numdivs = pagedom.xpath("//div[@class='queryResultHits']")
          tocSearch = int(getTextFromNode(numdivs[0]))           tocSearch = int(getTextFromNode(numdivs[0]))
          logging.debug("documentViewer (gettoc) tocSearch: %s"%(tocSearch))  
          tc=int((tocSearch/10)+1)           tc=int((tocSearch/10)+1)
          logging.debug("documentViewer (gettoc) tc: %s"%(tc))  
          return tc           return tc
           
     def getToc(self, mode="text", docinfo=None):      def getToc(self, mode="text", docinfo=None):
         """loads table of contents and stores in docinfo"""          """loads table of contents and stores in docinfo"""
         logging.debug("documentViewer (gettoc) mode: %s"%(mode))  
         if mode == "none":          if mode == "none":
             return docinfo                      return docinfo        
         if 'tocSize_%s'%mode in docinfo:          if 'tocSize_%s'%mode in docinfo:
Line 455  class MpdlXmlTextServer(SimpleItem): Line 478  class MpdlXmlTextServer(SimpleItem):
         data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn))            data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn))  
         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))          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')          text = page.replace('mode=image','mode=texttool')
         #logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization))  
           
         return text          return text
           
     def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):      def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
Line 479  def manage_addMpdlXmlTextServer(self,id, Line 500  def manage_addMpdlXmlTextServer(self,id,
     self.Destination()._setObject(id, newObj)      self.Destination()._setObject(id, newObj)
     if RESPONSE is not None:      if RESPONSE is not None:
         RESPONSE.redirect('manage_main')          RESPONSE.redirect('manage_main')
   
   
       

Removed from v.1.222  
changed lines
  Added in v.1.230


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>