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