Annotation of documentViewer/MpdlXmlTextServer.py, revision 1.219

1.2       casties     1: 
                      2: from OFS.SimpleItem import SimpleItem
                      3: from Products.PageTemplates.PageTemplateFile import PageTemplateFile 
                      4: from Ft.Xml import EMPTY_NAMESPACE, Parse
                      5: 
                      6: import sys
                      7: import logging
1.5       casties     8: import urllib
1.2       casties     9: import documentViewer
                     10: from documentViewer import getTextFromNode, serializeNode
                     11: 
                     12: class MpdlXmlTextServer(SimpleItem):
                     13:     """TextServer implementation for MPDL-XML eXist server"""
                     14:     meta_type="MPDL-XML TextServer"
                     15: 
                     16:     manage_options=(
                     17:         {'label':'Config','action':'manage_changeMpdlXmlTextServerForm'},
                     18:        )+SimpleItem.manage_options
                     19:     
                     20:     manage_changeMpdlXmlTextServerForm = PageTemplateFile("zpt/manage_changeMpdlXmlTextServer", globals())
                     21:         
1.3       casties    22:     def __init__(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40):
1.2       casties    23:         """constructor"""
                     24:         self.id=id
                     25:         self.title=title
                     26:         self.timeout = timeout
1.3       casties    27:         if serverName is None:
                     28:             self.serverUrl = serverUrl
                     29:         else:
                     30:             self.serverUrl = "http://%s/mpdl/interface/"%serverName
1.2       casties    31:         
                     32:     def getHttpData(self, url, data=None):
                     33:         """returns result from url+data HTTP request"""
                     34:         return documentViewer.getHttpData(url,data,timeout=self.timeout)
                     35:     
                     36:     def getServerData(self, method, data=None):
                     37:         """returns result from text server for method+data"""
                     38:         url = self.serverUrl+method
                     39:         return documentViewer.getHttpData(url,data,timeout=self.timeout)
                     40: 
1.206     abukhman   41:     def getSearch(self, pn=1, pageinfo=None,  docinfo=None, query=None, queryType=None, lemma=None, characterNormalization=None, optionToggle=None):
1.2       casties    42:         """get search list"""
                     43:         docpath = docinfo['textURLPath'] 
                     44:         url = docinfo['url']
                     45:         pagesize = pageinfo['queryPageSize']
                     46:         pn = pageinfo['searchPN']
                     47:         sn = pageinfo['sn']
                     48:         highlightQuery = pageinfo['highlightQuery']
1.34      abukhman   49:         query =pageinfo['query']
1.2       casties    50:         queryType =pageinfo['queryType']
                     51:         viewMode=  pageinfo['viewMode']
                     52:         tocMode = pageinfo['tocMode']
1.24      abukhman   53:         characterNormalization = pageinfo['characterNormalization']
1.207     abukhman   54:         optionToggle = pageinfo['optionToggle']
1.2       casties    55:         tocPN = pageinfo['tocPN']
                     56:         selfurl = self.absolute_url()
                     57:         
1.207     abukhman   58:         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)))
1.2       casties    59:         #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)                
                     60:         
                     61:         pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url)
                     62:         pagedom = Parse(pagexml)
                     63:         if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"):   
                     64:             pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
                     65:             if len(pagedivs)>0:
                     66:                 pagenode=pagedivs[0]
                     67:                 links=pagenode.xpath("//a")
                     68:                 for l in links:
                     69:                     hrefNode = l.getAttributeNodeNS(None, u"href")
                     70:                     if hrefNode:
                     71:                         href = hrefNode.nodeValue
                     72:                         if href.startswith('page-fragment.xql'):
                     73:                             selfurl = self.absolute_url()            
1.213     abukhman   74:                             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))
1.2       casties    75:                             hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl)                                           
                     76:                 return serializeNode(pagenode)        
                     77:         if (queryType=="fulltextMorph"):
                     78:             pagedivs = pagedom.xpath("//div[@class='queryResult']")
                     79:             if len(pagedivs)>0:
                     80:                 pagenode=pagedivs[0]
                     81:                 links=pagenode.xpath("//a")
                     82:                 for l in links:
                     83:                     hrefNode = l.getAttributeNodeNS(None, u"href")
                     84:                     if hrefNode:
                     85:                         href = hrefNode.nodeValue
                     86:                         if href.startswith('page-fragment.xql'):
                     87:                             selfurl = self.absolute_url()       
1.213     abukhman   88:                             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))
1.2       casties    89:                             hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl)  
                     90:                         if href.startswith('../lt/lemma.xql'):
                     91:                             hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma_New'%(selfurl))        
                     92:                             l.setAttributeNS(None, 'target', '_blank')
                     93:                             l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;")
1.6       abukhman   94:                             l.setAttributeNS(None, 'onClick', 'popupWin.focus();')  
1.2       casties    95:                 pagedivs = pagedom.xpath("//div[@class='queryResultMorphExpansion']")                
                     96:                 return serializeNode(pagenode)        
                     97:         if (queryType=="ftIndex")or(queryType=="ftIndexMorph"):
                     98:             pagedivs= pagedom.xpath("//div[@class='queryResultPage']")
                     99:             if len(pagedivs)>0:
                    100:                 pagenode=pagedivs[0]
                    101:                 links=pagenode.xpath("//a")
                    102:                 for l in links:
                    103:                     hrefNode = l.getAttributeNodeNS(None, u"href")
                    104:                     if hrefNode:
                    105:                         href = hrefNode.nodeValue
1.213     abukhman  106:                         hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s&optionToggle=%s&characterNormalization=%s'%(viewMode,tocMode,tocPN,pn,optionToggle,characterNormalization))             
1.2       casties   107:                         if href.startswith('../lt/lex.xql'):
                    108:                             hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_voc'%selfurl)         
                    109:                             l.setAttributeNS(None, 'target', '_blank')
                    110:                             l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;")
1.6       abukhman  111:                             l.setAttributeNS(None, 'onClick', 'popupWin.focus();')
1.2       casties   112:                         if href.startswith('../lt/lemma.xql'):
                    113:                             hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma'%selfurl)        
                    114:                             l.setAttributeNS(None, 'target', '_blank')
                    115:                             l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;")
1.6       abukhman  116:                             l.setAttributeNS(None, 'onClick', 'popupWin.focus();')
1.2       casties   117:                 return serializeNode(pagenode)      
                    118:         return "no text here"   
                    119:                        
1.216     abukhman  120:     
                    121:     def getNumTextPages (self, docinfo=None):
1.43      abukhman  122:         """get list of pages from fulltext (texts without images) and put in docinfo"""
1.218     casties   123:         logging.debug("getNumTextPages")
1.216     abukhman  124:         docpath = docinfo['textURLPath'] 
                    125:         selfurl = self.absolute_url()   
                    126:         #viewMode=  pageinfo['viewMode']
1.56      abukhman  127:         if 'numPages' in docinfo:
1.43      abukhman  128:             # allredy there
1.56      abukhman  129:             return docinfo
1.216     abukhman  130:         
                    131:         text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))
                    132:         dom =Parse(text)
                    133:         pagedivs = dom.xpath("//div[@class='countPages']")
                    134:         logging.debug ("pagedivs=%s"%(pagedivs))
                    135:         if len(pagedivs)>0:
                    136:             docinfo['numPages']= int(getTextFromNode(pagedivs[0]))
                    137:             return docinfo
                    138:      
                    139:     def getTocEntries (self, docinfo=None):
                    140:         """ number of text entries"""
1.218     casties   141:         self.getInfoFromPage(docinfo)
                    142:         return docinfo['tocEntries']
1.205     abukhman  143:             
1.216     abukhman  144:     def getFigureEntries (self, docinfo=None):
                    145:         """ number of figure entries"""
1.218     casties   146:         self.getInfoFromPage(docinfo)
                    147:         return docinfo['figureEntries']
1.216     abukhman  148:                        
1.89      abukhman  149:     def getGisPlaces(self, docinfo=None, pageinfo=None):
1.58      abukhman  150:         """ Show all Gis Places of whole Page"""
1.100     abukhman  151:         xpath='//place'
1.214     casties   152:         docpath = docinfo.get('textURLPath',None)
                    153:         if not docpath:
                    154:             return None
                    155: 
1.89      abukhman  156:         url = docinfo['url']
                    157:         selfurl = self.absolute_url()
1.93      abukhman  158:         pn = pageinfo['current']
1.127     abukhman  159:         hrefList=[]
1.142     abukhman  160:         myList= ""
1.100     abukhman  161:         text=self.getServerData("xpath.xql", "document=%s&xpath=%s&pn=%s"%(docinfo['textURLPath'],xpath,pn))
                    162:         dom = Parse(text)
1.101     abukhman  163:         result = dom.xpath("//result/resultPage/place")
1.72      abukhman  164:         for l in result:
1.86      abukhman  165:             hrefNode= l.getAttributeNodeNS(None, u"id")
1.108     abukhman  166:             href= hrefNode.nodeValue
1.128     abukhman  167:             hrefList.append(href)
1.145     abukhman  168:             myList = ",".join(hrefList)
                    169:         logging.debug("getGisPlaces :%s"%(myList))                             
1.143     abukhman  170:         return myList
                    171:     
                    172:     def getAllGisPlaces (self, docinfo=None, pageinfo=None):
                    173:         """Show all Gis Places of whole Book """
                    174:         xpath ='//echo:place'
                    175:         docpath =docinfo['textURLPath']
                    176:         url = docinfo['url']
                    177:         selfurl =self.absolute_url()
                    178:         pn =pageinfo['current']
                    179:         hrefList=[]
                    180:         myList=""
                    181:         text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'],xpath))
                    182:         dom =Parse(text)
                    183:         result = dom.xpath("//result/resultPage/place")
1.205     abukhman  184:         
1.143     abukhman  185:         for l in result:
                    186:             hrefNode = l.getAttributeNodeNS(None, u"id")
                    187:             href= hrefNode.nodeValue
                    188:             hrefList.append(href)
1.136     abukhman  189:             myList = ",".join(hrefList)
1.145     abukhman  190:             logging.debug("getALLGisPlaces :%s"%(myList))
                    191:         return myList
1.216     abukhman  192:                
1.183     abukhman  193:     def getOrigPages (self, docinfo=None, pageinfo=None):
1.146     abukhman  194:         """Show original page """
1.214     casties   195:         docpath = docinfo.get('textURLPath',None)
                    196:         if not docpath:
                    197:             return None
1.146     abukhman  198:         selfurl = self.absolute_url()
1.174     abukhman  199:         pn =pageinfo['current']
1.161     abukhman  200:        
1.174     abukhman  201:         viewMode=  pageinfo['viewMode']
                    202:         text = self.getServerData("page-fragment.xql","document=%s&mode=%s&pn=%s"%(docinfo['textURLPath'], 'text',  pn))
1.146     abukhman  203:         dom =Parse(text)
                    204:         pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
1.160     abukhman  205:         if len(pagedivs)>0:
1.183     abukhman  206:             originalPage= getTextFromNode(pagedivs[0])
1.181     abukhman  207:             #return docinfo['originalPage']
1.179     abukhman  208:             return originalPage
1.183     abukhman  209:     
1.217     abukhman  210:     def getAllPlaces (self, docinfo=None):
1.215     abukhman  211:         """Show all Places if no places than 0"""
1.218     casties   212:         self.getInfoFromPage(docinfo)
                    213:         return docinfo['allPlaces']
                    214: 
                    215:     def getInfoFromPage(self, docinfo=None):
                    216:         """ extract diverse info from page-fragment"""
                    217:         docpath = docinfo['textURLPath']
1.217     abukhman  218:         if 'allPlaces' in docinfo:
                    219:             # allredy there
1.218     casties   220:             return docinfo
1.217     abukhman  221:         
1.218     casties   222:         if (docpath is not None):   
                    223:             text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))
                    224:             dom = Parse(text)
                    225:             # figureEntries
                    226:             pagedivs = dom.xpath("//div[@class='countFigureEntries']")
1.219   ! casties   227:             s = getTextFromNode(pagedivs[0])
        !           228:             try:
        !           229:                 docinfo['figureEntries'] = int(s)
        !           230:             except:
        !           231:                 docinfo['figureEntries'] = 0
1.218     casties   232:             # tocEntries
                    233:             pagedivs = dom.xpath("//div[@class='countTocEntries']")
1.219   ! casties   234:             s = getTextFromNode(pagedivs[0])
        !           235:             try:
        !           236:                 docinfo['tocEntries'] = int(s)
        !           237:             except:
        !           238:                 docinfo['tocEntries'] = 0
1.218     casties   239:             # allPlaces
                    240:             pagedivs = dom.xpath("//div[@class='countPlaces']")
1.219   ! casties   241:             s = getTextFromNode(pagedivs[0])
        !           242:             try:
        !           243:                 docinfo['allPlaces'] = int(s)
        !           244:             except:
        !           245:                 docinfo['allPlaces'] = 0
1.218     casties   246: 
                    247:         return docinfo
                    248:                        
1.215     abukhman  249:            
1.216     abukhman  250:     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):
1.2       casties   251:         """returns single page from fulltext"""
                    252:         docpath = docinfo['textURLPath']
                    253:         path = docinfo['textURLPath']
                    254:         url = docinfo['url']
1.73      abukhman  255:         name = docinfo['name']
1.2       casties   256:         viewMode= pageinfo['viewMode']
1.196     abukhman  257:         sn = pageinfo['sn']
1.187     abukhman  258:         highlightQuery = pageinfo['highlightQuery']
1.196     abukhman  259:         
1.2       casties   260:         tocMode = pageinfo['tocMode']
1.20      abukhman  261:         characterNormalization=pageinfo['characterNormalization']
1.2       casties   262:         tocPN = pageinfo['tocPN']
                    263:         selfurl = self.absolute_url()   
                    264:         if mode == "text_dict":
                    265:             textmode = "textPollux"
                    266:         else:
                    267:             textmode = mode
1.196     abukhman  268:         #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
1.193     abukhman  269:         textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization)
1.190     abukhman  270:         if highlightQuery is not None:
1.196     abukhman  271:             textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn)           
1.198     abukhman  272:             #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
1.38      abukhman  273:         pagexml = self.getServerData("page-fragment.xql",textParam)
1.198     abukhman  274:         logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
1.2       casties   275:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False)
                    276:         
1.39      abukhman  277:         pagedom = Parse(pagexml)
1.2       casties   278:         # plain text mode
                    279:         if mode == "text":
                    280:             # first div contains text
                    281:             pagedivs = pagedom.xpath("/div")
                    282:             if len(pagedivs) > 0:      
                    283:                 pagenode = pagedivs[0]
                    284:                 links = pagenode.xpath("//a")
                    285:                 for l in links:
                    286:                     hrefNode = l.getAttributeNodeNS(None, u"href")
                    287:                     if hrefNode:
                    288:                         href= hrefNode.nodeValue
                    289:                         if href.startswith('#note-'):
1.27      abukhman  290:                             hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))
1.2       casties   291:                 return serializeNode(pagenode)
                    292:         if mode == "xml":
                    293:               # first div contains text
                    294:               pagedivs = pagedom.xpath("/div")
                    295:               if len(pagedivs) > 0:
                    296:                   pagenode = pagedivs[0]
                    297:                   return serializeNode(pagenode)
1.7       abukhman  298:         if mode == "gis":
                    299:               # first div contains text
                    300:               pagedivs = pagedom.xpath("/div")
                    301:               if len(pagedivs) > 0:
                    302:                   pagenode = pagedivs[0]
1.28      abukhman  303:                   links =pagenode.xpath("//a")
                    304:                   for l in links:
                    305:                       hrefNode =l.getAttributeNodeNS(None, u"href")
                    306:                       if hrefNode:
                    307:                           href=hrefNode.nodeValue
                    308:                           if href.startswith('http://chinagis.mpiwg-berlin.mpg.de'):
1.75      abukhman  309:                               hrefNode.nodeValue =href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl/%s'%name)
1.62      abukhman  310:                               l.setAttributeNS(None, 'target', '_blank') 
1.61      abukhman  311:                   return serializeNode(pagenode)
1.7       abukhman  312:                     
1.2       casties   313:         if mode == "pureXml":
                    314:               # first div contains text
                    315:               pagedivs = pagedom.xpath("/div")
                    316:               if len(pagedivs) > 0:
                    317:                   pagenode = pagedivs[0]
                    318:                   return serializeNode(pagenode)      
                    319:         # text-with-links mode
                    320:         if mode == "text_dict":
                    321:             # first div contains text
                    322:             pagedivs = pagedom.xpath("/div")
                    323:             if len(pagedivs) > 0:
                    324:                 pagenode = pagedivs[0]
                    325:                 # check all a-tags
                    326:                 links = pagenode.xpath("//a")
                    327:                 for l in links:
                    328:                     hrefNode = l.getAttributeNodeNS(None, u"href")
                    329:                     if hrefNode:
                    330:                         # is link with href
                    331:                         href = hrefNode.nodeValue
                    332:                         if href.startswith('lt/lex.xql'):
                    333:                             # is pollux link
                    334:                             selfurl = self.absolute_url()
                    335:                             # change href
                    336:                             hrefNode.nodeValue = href.replace('lt/lex.xql','%s/template/head_main_voc'%selfurl)
                    337:                             # add target
                    338:                             l.setAttributeNS(None, 'target', '_blank')
                    339:                             l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;")
1.6       abukhman  340:                             l.setAttributeNS(None, 'onClick', 'popupWin.focus();')      
1.2       casties   341:                         if href.startswith('lt/lemma.xql'):    
                    342:                             selfurl = self.absolute_url()
                    343:                             hrefNode.nodeValue = href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl)
                    344:                             l.setAttributeNS(None, 'target', '_blank')
                    345:                             l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;")
1.6       abukhman  346:                             l.setAttributeNS(None, 'onClick', 'popupWin.focus();')   
1.2       casties   347:                         if href.startswith('#note-'):
1.19      abukhman  348:                             hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))    
1.2       casties   349:                 return serializeNode(pagenode)
                    350:         return "no text here"
                    351: 
                    352:     def getTranslate(self, query=None, language=None):
                    353:         """translate into another languages"""
1.5       casties   354:         data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))
1.2       casties   355:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
                    356:         return data
                    357:     
                    358:     def getLemma(self, lemma=None, language=None):
                    359:         """simular words lemma """
1.5       casties   360:         data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(lemma))
1.2       casties   361:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma)))
                    362:         return data
                    363:     
                    364:     def getLemmaNew(self, query=None, language=None):
                    365:         """simular words lemma """
1.5       casties   366:         data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(query))
1.2       casties   367:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query)))
                    368:         return data
1.28      abukhman  369:     
1.206     abukhman  370:     def getQuery (self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionToggle=None):
1.2       casties   371:          """number of"""
                    372:          docpath = docinfo['textURLPath'] 
                    373:          pagesize = pageinfo['queryPageSize']
                    374:          pn = pageinfo['searchPN']
1.34      abukhman  375:          query =pageinfo['query']
1.2       casties   376:          queryType =pageinfo['queryType']
                    377:          tocSearch = 0
                    378:          tocDiv = None
                    379:          
1.32      abukhman  380:          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))
1.2       casties   381:          #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)
                    382:          pagedom = Parse(pagexml)
                    383:          numdivs = pagedom.xpath("//div[@class='queryResultHits']")
                    384:          tocSearch = int(getTextFromNode(numdivs[0]))
1.204     abukhman  385:          logging.debug("documentViewer (gettoc) tocSearch: %s"%(tocSearch))
1.2       casties   386:          tc=int((tocSearch/10)+1)
1.23      abukhman  387:          logging.debug("documentViewer (gettoc) tc: %s"%(tc))
1.2       casties   388:          return tc
                    389: 
1.205     abukhman  390:     def getQueryResultHits(self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionsClose=None):
                    391:         
                    392:          """number of hits in Search mode"""
                    393:          docpath = docinfo['textURLPath'] 
                    394:          pagesize = pageinfo['queryPageSize']
                    395:          pn = pageinfo['searchPN']
                    396:          query =pageinfo['query']
                    397:          queryType =pageinfo['queryType']
                    398:          tocSearch = 0
                    399:          tocDiv = None
                    400:          
                    401:          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))
                    402:          #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)
                    403:          pagedom = Parse(pagexml)
                    404:          numdivs = pagedom.xpath("//div[@class='queryResultHits']")
1.210     abukhman  405:          tocSearch = int(getTextFromNode(numdivs[0])) 
                    406:          tc=int((tocSearch/10)+1)   
                    407:          return tc
1.205     abukhman  408:      
                    409:     def getQueryResultHitsText(self,  docinfo=None, pageinfo=None):      
                    410:          """number of hits in Text of Contents mode"""
1.216     abukhman  411:          selfurl = self.absolute_url()
                    412:          docpath = docinfo['textURLPath']
                    413:          viewMode=  pageinfo['viewMode']
                    414:          text = self.getServerData("page-fragment.xql","document=%s&mode=%s"%(docinfo['textURLPath'], 'text'))
                    415:          dom =Parse(text)
                    416:          pagedivs = dom.xpath("//div[@class='countTocEntries']")
                    417:          logging.debug ("pagedivs=%s"%(pagedivs))
                    418:          if len(pagedivs)>0:
                    419:             originalPage= (getTextFromNode(pagedivs[0]))
                    420:             tc = int (originalPage)
                    421:             tc1 =tc/30+1
                    422:             return tc1
1.205     abukhman  423:          
                    424:     def getQueryResultHitsFigures(self,  docinfo=None, pageinfo=None):      
                    425:          """number of hits in Text of Figures mode"""
                    426:          
1.216     abukhman  427:          selfurl = self.absolute_url()
                    428:          docpath = docinfo['textURLPath']
                    429:          viewMode=  pageinfo['viewMode']
                    430:          text = self.getServerData("page-fragment.xql","document=%s&mode=%s"%(docinfo['textURLPath'], 'text'))
                    431:          dom =Parse(text)
                    432:          pagedivs = dom.xpath("//div[@class='countFigureEntries']")
                    433:          logging.debug ("pagedivs=%s"%(pagedivs))
                    434:          if len(pagedivs)>0:
                    435:             originalPage= (getTextFromNode(pagedivs[0]))
                    436:             tc = int (originalPage)
                    437:             tc1 =tc/30+1
                    438:             return tc1 
1.205     abukhman  439: 
                    440: 
1.2       casties   441:     def getToc(self, mode="text", docinfo=None):
                    442:         """loads table of contents and stores in docinfo"""
1.23      abukhman  443:         logging.debug("documentViewer (gettoc) mode: %s"%(mode))
1.2       casties   444:         if mode == "none":
                    445:             return docinfo        
                    446:         if 'tocSize_%s'%mode in docinfo:
                    447:             # cached toc
                    448:             return docinfo
                    449:         
                    450:         docpath = docinfo['textURLPath']
                    451:         # we need to set a result set size
                    452:         pagesize = 1000
                    453:         pn = 1
                    454:         if mode == "text":
                    455:             queryType = "toc"
                    456:         else:
                    457:             queryType = mode
                    458:         # number of entries in toc
                    459:         tocSize = 0
                    460:         tocDiv = None
                    461:         
                    462:         pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))
                    463:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False)
                    464:         # post-processing downloaded xml
                    465:         pagedom = Parse(pagexml)
                    466:         # get number of entries
                    467:         numdivs = pagedom.xpath("//div[@class='queryResultHits']")
                    468:         if len(numdivs) > 0:
                    469:             tocSize = int(getTextFromNode(numdivs[0]))
                    470:         docinfo['tocSize_%s'%mode] = tocSize
                    471:         return docinfo
                    472:     
                    473:     def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None):
                    474:         """returns single page from the table of contents"""
                    475:         # TODO: this should use the cached TOC
                    476:         if mode == "text":
                    477:             queryType = "toc"
                    478:         else:
                    479:             queryType = mode
                    480:         docpath = docinfo['textURLPath']
                    481:         path = docinfo['textURLPath']       
                    482:         pagesize = pageinfo['tocPageSize']
                    483:         pn = pageinfo['tocPN']
                    484:         url = docinfo['url']
                    485:         selfurl = self.absolute_url()  
                    486:         viewMode=  pageinfo['viewMode']
1.26      abukhman  487:         characterNormalization = pageinfo ['characterNormalization']
1.206     abukhman  488:         optionToggle =pageinfo ['optionToggle']
1.2       casties   489:         tocMode = pageinfo['tocMode']
                    490:         tocPN = pageinfo['tocPN']  
                    491:         
1.213     abukhman  492:         data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn))  
                    493:         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))
1.2       casties   494:         text = page.replace('mode=image','mode=texttool')
1.21      abukhman  495:         logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization))
1.19      abukhman  496:         #logging.debug("documentViewer (characterNormalization) text: %s"%(text))
1.2       casties   497:         return text
                    498:     
                    499:     def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
                    500:         """change settings"""
                    501:         self.title=title
                    502:         self.timeout = timeout
                    503:         self.serverUrl = serverUrl
                    504:         if RESPONSE is not None:
                    505:             RESPONSE.redirect('manage_main')
                    506:         
                    507: # management methods
                    508: def manage_addMpdlXmlTextServerForm(self):
                    509:     """Form for adding"""
                    510:     pt = PageTemplateFile("zpt/manage_addMpdlXmlTextServer", globals()).__of__(self)
                    511:     return pt()
                    512: 
                    513: def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
                    514:     """add zogiimage"""
                    515:     newObj = MpdlXmlTextServer(id,title,serverUrl,timeout)
                    516:     self.Destination()._setObject(id, newObj)
                    517:     if RESPONSE is not None:
                    518:         RESPONSE.redirect('manage_main')
                    519: 
                    520: 
1.4       casties   521:     

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