Annotation of documentViewer/MpdlXmlTextServer.py, revision 1.217

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.216     abukhman  123:         docpath = docinfo['textURLPath'] 
                    124:         selfurl = self.absolute_url()   
                    125:         #viewMode=  pageinfo['viewMode']
1.56      abukhman  126:         if 'numPages' in docinfo:
1.43      abukhman  127:             # allredy there
1.56      abukhman  128:             return docinfo
1.216     abukhman  129:         
                    130:         text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))
                    131:         dom =Parse(text)
                    132:         pagedivs = dom.xpath("//div[@class='countPages']")
                    133:         logging.debug ("pagedivs=%s"%(pagedivs))
                    134:         if len(pagedivs)>0:
                    135:             docinfo['numPages']= int(getTextFromNode(pagedivs[0]))
                    136:             return docinfo
                    137:      
                    138:     def getTocEntries (self, docinfo=None):
                    139:         """ number of text entries"""
                    140:         docpath = docinfo['textURLPath'] 
                    141:         selfurl = self.absolute_url()
1.217   ! abukhman  142:         if 'tocEntries' in docinfo:
        !           143:             # allredy there
        !           144:             return docinfo['tocEntries']
1.216     abukhman  145:         if (docpath!=None):
                    146:             text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))
                    147:             dom =Parse(text)
                    148:             pagedivs = dom.xpath("//div[@class='countTocEntries']")
1.217   ! abukhman  149:             #logging.debug ("pagedivs=%s"%(pagedivs))
        !           150:             docinfo['tocEntries'] = getTextFromNode(pagedivs[0])
        !           151:             #tc = int (originalPage)
        !           152:             return docinfo['tocEntries']
1.205     abukhman  153:             
1.216     abukhman  154:     def getFigureEntries (self, docinfo=None):
                    155:         """ number of figure entries"""
                    156:         docpath = docinfo['textURLPath'] 
                    157:         selfurl = self.absolute_url()
1.217   ! abukhman  158:         if 'figureEntries' in docinfo:
        !           159:             # allredy there
        !           160:             return docinfo['figureEntries']
1.216     abukhman  161:         if (docpath!=None):   
                    162:             text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))
                    163:             dom = Parse(text)
                    164:             pagedivs = dom.xpath("//div[@class='countFigureEntries']")
1.217   ! abukhman  165:             #logging.debug ("pagedivs=%s"%(pagedivs))
        !           166:             docinfo['figureEntries'] = getTextFromNode(pagedivs[0])
        !           167:             #tc = int (docinfo['figureEntries'])
        !           168:             return docinfo['figureEntries']
1.216     abukhman  169:                        
1.89      abukhman  170:     def getGisPlaces(self, docinfo=None, pageinfo=None):
1.58      abukhman  171:         """ Show all Gis Places of whole Page"""
1.100     abukhman  172:         xpath='//place'
1.214     casties   173:         docpath = docinfo.get('textURLPath',None)
                    174:         if not docpath:
                    175:             return None
                    176: 
1.89      abukhman  177:         url = docinfo['url']
                    178:         selfurl = self.absolute_url()
1.93      abukhman  179:         pn = pageinfo['current']
1.127     abukhman  180:         hrefList=[]
1.142     abukhman  181:         myList= ""
1.100     abukhman  182:         text=self.getServerData("xpath.xql", "document=%s&xpath=%s&pn=%s"%(docinfo['textURLPath'],xpath,pn))
                    183:         dom = Parse(text)
1.101     abukhman  184:         result = dom.xpath("//result/resultPage/place")
1.72      abukhman  185:         for l in result:
1.86      abukhman  186:             hrefNode= l.getAttributeNodeNS(None, u"id")
1.108     abukhman  187:             href= hrefNode.nodeValue
1.128     abukhman  188:             hrefList.append(href)
1.145     abukhman  189:             myList = ",".join(hrefList)
                    190:         logging.debug("getGisPlaces :%s"%(myList))                             
1.143     abukhman  191:         return myList
                    192:     
                    193:     def getAllGisPlaces (self, docinfo=None, pageinfo=None):
                    194:         """Show all Gis Places of whole Book """
                    195:         xpath ='//echo:place'
                    196:         docpath =docinfo['textURLPath']
                    197:         url = docinfo['url']
                    198:         selfurl =self.absolute_url()
                    199:         pn =pageinfo['current']
                    200:         hrefList=[]
                    201:         myList=""
                    202:         text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'],xpath))
                    203:         dom =Parse(text)
                    204:         result = dom.xpath("//result/resultPage/place")
1.205     abukhman  205:         
1.143     abukhman  206:         for l in result:
                    207:             hrefNode = l.getAttributeNodeNS(None, u"id")
                    208:             href= hrefNode.nodeValue
                    209:             hrefList.append(href)
1.136     abukhman  210:             myList = ",".join(hrefList)
1.145     abukhman  211:             logging.debug("getALLGisPlaces :%s"%(myList))
                    212:         return myList
1.216     abukhman  213:                
1.183     abukhman  214:     def getOrigPages (self, docinfo=None, pageinfo=None):
1.146     abukhman  215:         """Show original page """
1.214     casties   216:         docpath = docinfo.get('textURLPath',None)
                    217:         if not docpath:
                    218:             return None
1.146     abukhman  219:         selfurl = self.absolute_url()
1.174     abukhman  220:         pn =pageinfo['current']
1.161     abukhman  221:        
1.174     abukhman  222:         viewMode=  pageinfo['viewMode']
                    223:         text = self.getServerData("page-fragment.xql","document=%s&mode=%s&pn=%s"%(docinfo['textURLPath'], 'text',  pn))
1.146     abukhman  224:         dom =Parse(text)
                    225:         pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
1.160     abukhman  226:         if len(pagedivs)>0:
1.183     abukhman  227:             originalPage= getTextFromNode(pagedivs[0])
1.181     abukhman  228:             #return docinfo['originalPage']
1.179     abukhman  229:             return originalPage
1.183     abukhman  230:     
1.217   ! abukhman  231:     def getAllPlaces (self, docinfo=None):
1.215     abukhman  232:         """Show all Places if no places than 0"""
                    233:         docpath = docinfo['textURLPath'] 
1.217   ! abukhman  234:         selfurl = self.absolute_url()
        !           235:         if 'allPlaces' in docinfo:
        !           236:             # allredy there
        !           237:             return docinfo['allPlaces']
        !           238:         
        !           239:         text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))
1.215     abukhman  240:         dom =Parse(text)
                    241:         pagedivs = dom.xpath("//div[@class='countPlaces']")
                    242:         logging.debug ("pagedivs=%s"%(pagedivs))
                    243:         if len(pagedivs)>0:
1.217   ! abukhman  244:             docinfo['allPlaces']= getTextFromNode(pagedivs[0])
        !           245:             #logging.debug ("docinfo['allPlaces']=%s"%(docinfo['allPlaces']))
        !           246:             return docinfo['allPlaces']
1.215     abukhman  247:            
1.216     abukhman  248:     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   249:         """returns single page from fulltext"""
                    250:         docpath = docinfo['textURLPath']
                    251:         path = docinfo['textURLPath']
                    252:         url = docinfo['url']
1.73      abukhman  253:         name = docinfo['name']
1.2       casties   254:         viewMode= pageinfo['viewMode']
1.196     abukhman  255:         sn = pageinfo['sn']
1.187     abukhman  256:         highlightQuery = pageinfo['highlightQuery']
1.196     abukhman  257:         
1.2       casties   258:         tocMode = pageinfo['tocMode']
1.20      abukhman  259:         characterNormalization=pageinfo['characterNormalization']
1.2       casties   260:         tocPN = pageinfo['tocPN']
                    261:         selfurl = self.absolute_url()   
                    262:         if mode == "text_dict":
                    263:             textmode = "textPollux"
                    264:         else:
                    265:             textmode = mode
1.196     abukhman  266:         #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
1.193     abukhman  267:         textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization)
1.190     abukhman  268:         if highlightQuery is not None:
1.196     abukhman  269:             textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn)           
1.198     abukhman  270:             #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
1.38      abukhman  271:         pagexml = self.getServerData("page-fragment.xql",textParam)
1.198     abukhman  272:         logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
1.2       casties   273:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False)
                    274:         
1.39      abukhman  275:         pagedom = Parse(pagexml)
1.2       casties   276:         # plain text mode
                    277:         if mode == "text":
                    278:             # first div contains text
                    279:             pagedivs = pagedom.xpath("/div")
                    280:             if len(pagedivs) > 0:      
                    281:                 pagenode = pagedivs[0]
                    282:                 links = pagenode.xpath("//a")
                    283:                 for l in links:
                    284:                     hrefNode = l.getAttributeNodeNS(None, u"href")
                    285:                     if hrefNode:
                    286:                         href= hrefNode.nodeValue
                    287:                         if href.startswith('#note-'):
1.27      abukhman  288:                             hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))
1.2       casties   289:                 return serializeNode(pagenode)
                    290:         if mode == "xml":
                    291:               # first div contains text
                    292:               pagedivs = pagedom.xpath("/div")
                    293:               if len(pagedivs) > 0:
                    294:                   pagenode = pagedivs[0]
                    295:                   return serializeNode(pagenode)
1.7       abukhman  296:         if mode == "gis":
                    297:               # first div contains text
                    298:               pagedivs = pagedom.xpath("/div")
                    299:               if len(pagedivs) > 0:
                    300:                   pagenode = pagedivs[0]
1.28      abukhman  301:                   links =pagenode.xpath("//a")
                    302:                   for l in links:
                    303:                       hrefNode =l.getAttributeNodeNS(None, u"href")
                    304:                       if hrefNode:
                    305:                           href=hrefNode.nodeValue
                    306:                           if href.startswith('http://chinagis.mpiwg-berlin.mpg.de'):
1.75      abukhman  307:                               hrefNode.nodeValue =href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl/%s'%name)
1.62      abukhman  308:                               l.setAttributeNS(None, 'target', '_blank') 
1.61      abukhman  309:                   return serializeNode(pagenode)
1.7       abukhman  310:                     
1.2       casties   311:         if mode == "pureXml":
                    312:               # first div contains text
                    313:               pagedivs = pagedom.xpath("/div")
                    314:               if len(pagedivs) > 0:
                    315:                   pagenode = pagedivs[0]
                    316:                   return serializeNode(pagenode)      
                    317:         # text-with-links mode
                    318:         if mode == "text_dict":
                    319:             # first div contains text
                    320:             pagedivs = pagedom.xpath("/div")
                    321:             if len(pagedivs) > 0:
                    322:                 pagenode = pagedivs[0]
                    323:                 # check all a-tags
                    324:                 links = pagenode.xpath("//a")
                    325:                 for l in links:
                    326:                     hrefNode = l.getAttributeNodeNS(None, u"href")
                    327:                     if hrefNode:
                    328:                         # is link with href
                    329:                         href = hrefNode.nodeValue
                    330:                         if href.startswith('lt/lex.xql'):
                    331:                             # is pollux link
                    332:                             selfurl = self.absolute_url()
                    333:                             # change href
                    334:                             hrefNode.nodeValue = href.replace('lt/lex.xql','%s/template/head_main_voc'%selfurl)
                    335:                             # add target
                    336:                             l.setAttributeNS(None, 'target', '_blank')
                    337:                             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  338:                             l.setAttributeNS(None, 'onClick', 'popupWin.focus();')      
1.2       casties   339:                         if href.startswith('lt/lemma.xql'):    
                    340:                             selfurl = self.absolute_url()
                    341:                             hrefNode.nodeValue = href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl)
                    342:                             l.setAttributeNS(None, 'target', '_blank')
                    343:                             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  344:                             l.setAttributeNS(None, 'onClick', 'popupWin.focus();')   
1.2       casties   345:                         if href.startswith('#note-'):
1.19      abukhman  346:                             hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))    
1.2       casties   347:                 return serializeNode(pagenode)
                    348:         return "no text here"
                    349: 
                    350:     def getTranslate(self, query=None, language=None):
                    351:         """translate into another languages"""
1.5       casties   352:         data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))
1.2       casties   353:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
                    354:         return data
                    355:     
                    356:     def getLemma(self, lemma=None, language=None):
                    357:         """simular words lemma """
1.5       casties   358:         data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(lemma))
1.2       casties   359:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma)))
                    360:         return data
                    361:     
                    362:     def getLemmaNew(self, query=None, language=None):
                    363:         """simular words lemma """
1.5       casties   364:         data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(query))
1.2       casties   365:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query)))
                    366:         return data
1.28      abukhman  367:     
1.206     abukhman  368:     def getQuery (self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionToggle=None):
1.2       casties   369:          """number of"""
                    370:          docpath = docinfo['textURLPath'] 
                    371:          pagesize = pageinfo['queryPageSize']
                    372:          pn = pageinfo['searchPN']
1.34      abukhman  373:          query =pageinfo['query']
1.2       casties   374:          queryType =pageinfo['queryType']
                    375:          tocSearch = 0
                    376:          tocDiv = None
                    377:          
1.32      abukhman  378:          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   379:          #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)
                    380:          pagedom = Parse(pagexml)
                    381:          numdivs = pagedom.xpath("//div[@class='queryResultHits']")
                    382:          tocSearch = int(getTextFromNode(numdivs[0]))
1.204     abukhman  383:          logging.debug("documentViewer (gettoc) tocSearch: %s"%(tocSearch))
1.2       casties   384:          tc=int((tocSearch/10)+1)
1.23      abukhman  385:          logging.debug("documentViewer (gettoc) tc: %s"%(tc))
1.2       casties   386:          return tc
                    387: 
1.205     abukhman  388:     def getQueryResultHits(self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionsClose=None):
                    389:         
                    390:          """number of hits in Search mode"""
                    391:          docpath = docinfo['textURLPath'] 
                    392:          pagesize = pageinfo['queryPageSize']
                    393:          pn = pageinfo['searchPN']
                    394:          query =pageinfo['query']
                    395:          queryType =pageinfo['queryType']
                    396:          tocSearch = 0
                    397:          tocDiv = None
                    398:          
                    399:          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))
                    400:          #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)
                    401:          pagedom = Parse(pagexml)
                    402:          numdivs = pagedom.xpath("//div[@class='queryResultHits']")
1.210     abukhman  403:          tocSearch = int(getTextFromNode(numdivs[0])) 
                    404:          tc=int((tocSearch/10)+1)   
                    405:          return tc
1.205     abukhman  406:      
                    407:     def getQueryResultHitsText(self,  docinfo=None, pageinfo=None):      
                    408:          """number of hits in Text of Contents mode"""
1.216     abukhman  409:          selfurl = self.absolute_url()
                    410:          docpath = docinfo['textURLPath']
                    411:          viewMode=  pageinfo['viewMode']
                    412:          text = self.getServerData("page-fragment.xql","document=%s&mode=%s"%(docinfo['textURLPath'], 'text'))
                    413:          dom =Parse(text)
                    414:          pagedivs = dom.xpath("//div[@class='countTocEntries']")
                    415:          logging.debug ("pagedivs=%s"%(pagedivs))
                    416:          if len(pagedivs)>0:
                    417:             originalPage= (getTextFromNode(pagedivs[0]))
                    418:             tc = int (originalPage)
                    419:             tc1 =tc/30+1
                    420:             return tc1
1.205     abukhman  421:          
                    422:     def getQueryResultHitsFigures(self,  docinfo=None, pageinfo=None):      
                    423:          """number of hits in Text of Figures mode"""
                    424:          
1.216     abukhman  425:          selfurl = self.absolute_url()
                    426:          docpath = docinfo['textURLPath']
                    427:          viewMode=  pageinfo['viewMode']
                    428:          text = self.getServerData("page-fragment.xql","document=%s&mode=%s"%(docinfo['textURLPath'], 'text'))
                    429:          dom =Parse(text)
                    430:          pagedivs = dom.xpath("//div[@class='countFigureEntries']")
                    431:          logging.debug ("pagedivs=%s"%(pagedivs))
                    432:          if len(pagedivs)>0:
                    433:             originalPage= (getTextFromNode(pagedivs[0]))
                    434:             tc = int (originalPage)
                    435:             tc1 =tc/30+1
                    436:             return tc1 
1.205     abukhman  437: 
                    438: 
1.2       casties   439:     def getToc(self, mode="text", docinfo=None):
                    440:         """loads table of contents and stores in docinfo"""
1.23      abukhman  441:         logging.debug("documentViewer (gettoc) mode: %s"%(mode))
1.2       casties   442:         if mode == "none":
                    443:             return docinfo        
                    444:         if 'tocSize_%s'%mode in docinfo:
                    445:             # cached toc
                    446:             return docinfo
                    447:         
                    448:         docpath = docinfo['textURLPath']
                    449:         # we need to set a result set size
                    450:         pagesize = 1000
                    451:         pn = 1
                    452:         if mode == "text":
                    453:             queryType = "toc"
                    454:         else:
                    455:             queryType = mode
                    456:         # number of entries in toc
                    457:         tocSize = 0
                    458:         tocDiv = None
                    459:         
                    460:         pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))
                    461:         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False)
                    462:         # post-processing downloaded xml
                    463:         pagedom = Parse(pagexml)
                    464:         # get number of entries
                    465:         numdivs = pagedom.xpath("//div[@class='queryResultHits']")
                    466:         if len(numdivs) > 0:
                    467:             tocSize = int(getTextFromNode(numdivs[0]))
                    468:         docinfo['tocSize_%s'%mode] = tocSize
                    469:         return docinfo
                    470:     
                    471:     def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None):
                    472:         """returns single page from the table of contents"""
                    473:         # TODO: this should use the cached TOC
                    474:         if mode == "text":
                    475:             queryType = "toc"
                    476:         else:
                    477:             queryType = mode
                    478:         docpath = docinfo['textURLPath']
                    479:         path = docinfo['textURLPath']       
                    480:         pagesize = pageinfo['tocPageSize']
                    481:         pn = pageinfo['tocPN']
                    482:         url = docinfo['url']
                    483:         selfurl = self.absolute_url()  
                    484:         viewMode=  pageinfo['viewMode']
1.26      abukhman  485:         characterNormalization = pageinfo ['characterNormalization']
1.206     abukhman  486:         optionToggle =pageinfo ['optionToggle']
1.2       casties   487:         tocMode = pageinfo['tocMode']
                    488:         tocPN = pageinfo['tocPN']  
                    489:         
1.213     abukhman  490:         data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn))  
                    491:         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   492:         text = page.replace('mode=image','mode=texttool')
1.21      abukhman  493:         logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization))
1.19      abukhman  494:         #logging.debug("documentViewer (characterNormalization) text: %s"%(text))
1.2       casties   495:         return text
                    496:     
                    497:     def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
                    498:         """change settings"""
                    499:         self.title=title
                    500:         self.timeout = timeout
                    501:         self.serverUrl = serverUrl
                    502:         if RESPONSE is not None:
                    503:             RESPONSE.redirect('manage_main')
                    504:         
                    505: # management methods
                    506: def manage_addMpdlXmlTextServerForm(self):
                    507:     """Form for adding"""
                    508:     pt = PageTemplateFile("zpt/manage_addMpdlXmlTextServer", globals()).__of__(self)
                    509:     return pt()
                    510: 
                    511: def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
                    512:     """add zogiimage"""
                    513:     newObj = MpdlXmlTextServer(id,title,serverUrl,timeout)
                    514:     self.Destination()._setObject(id, newObj)
                    515:     if RESPONSE is not None:
                    516:         RESPONSE.redirect('manage_main')
                    517: 
                    518: 
1.4       casties   519:     

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