Annotation of documentViewer/MpdlXmlTextServer.py, revision 1.230

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

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