Annotation of documentViewer/MpdlXmlTextServer.py, revision 1.232

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

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