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