Annotation of documentViewer/MpdlXmlTextServer.py, revision 1.235
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.234 abukhman 23: def __init__(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40):
24: #def __init__(self,id,title="",serverUrl="http://mpdl-text.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.235 ! abukhman 44: def getSearch(self, pageinfo=None, docinfo=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'):
1.235 ! abukhman 106: hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_query'%(selfurl))
1.2 casties 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.235 ! abukhman 109: l.setAttributeNS(None, 'onDblclick', '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'):
1.235 ! abukhman 123: hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_lex'%selfurl)
1.2 casties 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.235 ! abukhman 126: l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')
1.2 casties 127: if href.startswith('../lt/lemma.xql'):
1.235 ! abukhman 128: hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma'%(selfurl))
1.2 casties 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.235 ! abukhman 131: l.setAttributeNS(None, 'onDblclick', '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
1.233 abukhman 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
1.235 ! abukhman 351: if href.startswith('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql'):
1.2 casties 352: # is pollux link
353: selfurl = self.absolute_url()
354: # change href
1.235 ! abukhman 355: hrefNode.nodeValue = href.replace('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql','%s/head_main_voc'%selfurl)
1.2 casties 356: # add target
357: l.setAttributeNS(None, 'target', '_blank')
1.235 ! abukhman 358: l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=no, scrollbars=1'); return false;")
! 359: l.setAttributeNS(None, "onDblclick", "popupWin.focus();")
! 360: #window.open("this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=yes, scrollbars=1'"); return false;")
! 361:
! 362: if href.startswith('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql'):
1.2 casties 363: selfurl = self.absolute_url()
1.235 ! abukhman 364: hrefNode.nodeValue = href.replace('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql','%s/head_main_lemma'%selfurl)
1.2 casties 365: l.setAttributeNS(None, 'target', '_blank')
1.235 ! abukhman 366: l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=no, scrollbars=1'); return false;")
! 367: l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')
! 368:
1.2 casties 369: if href.startswith('#note-'):
1.227 abukhman 370: hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text_dict&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn))
1.2 casties 371: return serializeNode(pagenode)
372: return "no text here"
1.225 abukhman 373:
1.230 abukhman 374: def getOrigPages(self, docinfo=None, pageinfo=None):
375: docpath = docinfo['textURLPath']
376: pn =pageinfo['current']
377: selfurl = self.absolute_url()
378: pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
379: dom = Parse(pagexml)
380: pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
381: if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
382: if len(pagedivs)>0:
383: docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])
384: return docinfo['pageNumberOrig']
385:
386: def getOrigPagesNorm(self, docinfo=None, pageinfo=None):
387: docpath = docinfo['textURLPath']
388: pn =pageinfo['current']
389: selfurl = self.absolute_url()
390: pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
391: dom = Parse(pagexml)
392: pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']")
393: if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"):
394: if len(pagedivs)>0:
395: docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0])
396: return docinfo['pageNumberOrigNorm']
397:
398:
1.235 ! abukhman 399: def getTranslate(self, word=None, language=None):
1.2 casties 400: """translate into another languages"""
1.235 ! abukhman 401: data = self.getServerData("lt/wordInfo.xql","language="+str(language)+"&word="+urllib.quote(word)+"&output=html")
1.2 casties 402: #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
403: return data
404:
405: def getLemma(self, lemma=None, language=None):
406: """simular words lemma """
1.235 ! abukhman 407: data = self.getServerData("lt/lemma.xql","language="+str(language)+"&lemma="+urllib.quote(lemma)+"&output=html")
1.2 casties 408: return data
409:
1.235 ! abukhman 410: def getLemmaQuery(self, query=None, language=None):
1.2 casties 411: """simular words lemma """
1.235 ! abukhman 412: data = self.getServerData("lt/lemma.xql","language="+str(language)+"&query="+urllib.quote(query)+"&output=html")
! 413: return data
! 414:
! 415: def getLex(self, query=None, language=None):
! 416: #simular words lemma
! 417: data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))
1.2 casties 418: return data
1.28 abukhman 419:
1.206 abukhman 420: def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionToggle=None):
1.222 abukhman 421: #number of
1.2 casties 422: docpath = docinfo['textURLPath']
423: pagesize = pageinfo['queryPageSize']
424: pn = pageinfo['searchPN']
1.34 abukhman 425: query =pageinfo['query']
1.2 casties 426: queryType =pageinfo['queryType']
427: tocSearch = 0
428: tocDiv = None
429:
1.32 abukhman 430: 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 431: pagedom = Parse(pagexml)
432: numdivs = pagedom.xpath("//div[@class='queryResultHits']")
433: tocSearch = int(getTextFromNode(numdivs[0]))
434: tc=int((tocSearch/10)+1)
435: return tc
1.222 abukhman 436:
1.2 casties 437: def getToc(self, mode="text", docinfo=None):
438: """loads table of contents and stores in docinfo"""
439: if mode == "none":
440: return docinfo
441: if 'tocSize_%s'%mode in docinfo:
442: # cached toc
443: return docinfo
444:
445: docpath = docinfo['textURLPath']
446: # we need to set a result set size
447: pagesize = 1000
448: pn = 1
449: if mode == "text":
450: queryType = "toc"
451: else:
452: queryType = mode
453: # number of entries in toc
454: tocSize = 0
455: tocDiv = None
456:
457: pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))
1.222 abukhman 458:
1.2 casties 459: # post-processing downloaded xml
460: pagedom = Parse(pagexml)
461: # get number of entries
462: numdivs = pagedom.xpath("//div[@class='queryResultHits']")
463: if len(numdivs) > 0:
464: tocSize = int(getTextFromNode(numdivs[0]))
465: docinfo['tocSize_%s'%mode] = tocSize
466: return docinfo
467:
468: def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None):
469: """returns single page from the table of contents"""
470: # TODO: this should use the cached TOC
471: if mode == "text":
472: queryType = "toc"
473: else:
474: queryType = mode
475: docpath = docinfo['textURLPath']
476: path = docinfo['textURLPath']
477: pagesize = pageinfo['tocPageSize']
478: pn = pageinfo['tocPN']
479: url = docinfo['url']
480: selfurl = self.absolute_url()
481: viewMode= pageinfo['viewMode']
1.26 abukhman 482: characterNormalization = pageinfo ['characterNormalization']
1.206 abukhman 483: optionToggle =pageinfo ['optionToggle']
1.2 casties 484: tocMode = pageinfo['tocMode']
485: tocPN = pageinfo['tocPN']
486:
1.213 abukhman 487: data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn))
488: 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 489: text = page.replace('mode=image','mode=texttool')
490: return text
491:
1.234 abukhman 492: def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
493: #def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/",timeout=40,RESPONSE=None):
1.2 casties 494: """change settings"""
495: self.title=title
496: self.timeout = timeout
497: self.serverUrl = serverUrl
498: if RESPONSE is not None:
499: RESPONSE.redirect('manage_main')
500:
501: # management methods
502: def manage_addMpdlXmlTextServerForm(self):
503: """Form for adding"""
504: pt = PageTemplateFile("zpt/manage_addMpdlXmlTextServer", globals()).__of__(self)
505: return pt()
506:
1.234 abukhman 507: def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
508: #def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/",timeout=40,RESPONSE=None):
1.2 casties 509: """add zogiimage"""
510: newObj = MpdlXmlTextServer(id,title,serverUrl,timeout)
511: self.Destination()._setObject(id, newObj)
512: if RESPONSE is not None:
1.224 abukhman 513: RESPONSE.redirect('manage_main')
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>