source: documentViewer/MpdlXmlTextServer.py @ 411:691f0c341b33

Last change on this file since 411:691f0c341b33 was 411:691f0c341b33, checked in by abukhman, 13 years ago

* empty log message *

File size: 26.1 KB
Line 
1
2from OFS.SimpleItem import SimpleItem
3from Products.PageTemplates.PageTemplateFile import PageTemplateFile
4from Ft.Xml import EMPTY_NAMESPACE, Parse
5
6import sys
7import logging
8import urllib
9import documentViewer
10from documentViewer import getTextFromNode, serializeNode
11
12class 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       
22    def __init__(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40):
23        """constructor"""
24        self.id=id
25        self.title=title
26        self.timeout = timeout
27        if serverName is None:
28            self.serverUrl = serverUrl
29        else:
30            self.serverUrl = "http://%s/mpdl/interface/"%serverName
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
41    def getSearch(self, pn=1, pageinfo=None,  docinfo=None, query=None, queryType=None, lemma=None, characterNormalization=None, optionToggle=None):
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']
49        query =pageinfo['query']
50        queryType =pageinfo['queryType']
51        viewMode=  pageinfo['viewMode']
52        tocMode = pageinfo['tocMode']
53        characterNormalization = pageinfo['characterNormalization']
54        optionToggle = pageinfo['optionToggle']
55        tocPN = pageinfo['tocPN']
56        selfurl = self.absolute_url()
57       
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)))
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()           
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))
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()       
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))
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;")
94                            l.setAttributeNS(None, 'onClick', 'popupWin.focus();') 
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
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))             
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;")
111                            l.setAttributeNS(None, 'onClick', 'popupWin.focus();')
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;")
116                            l.setAttributeNS(None, 'onClick', 'popupWin.focus();')
117                return serializeNode(pagenode)     
118        return "no text here"   
119                       
120    """def getNumPages(self, docinfo):
121        ""get list of pages from fulltext and put in docinfo""
122        if 'numPages' in docinfo:
123            # already there
124            return docinfo       
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
129     """
130    def getNumTextPages (self, docinfo):
131        """get list of pages from fulltext (texts without images) and put in docinfo"""
132        if 'numPages' in docinfo:
133            # allredy there
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")
139         
140        docinfo['numPages']=int(getTextFromNode(result[0]))
141        return docinfo
142           
143    def getGisPlaces(self, docinfo=None, pageinfo=None):
144        """ Show all Gis Places of whole Page"""
145        xpath='//place'
146        docpath = docinfo.get('textURLPath',None)
147        if not docpath:
148            return None
149
150        url = docinfo['url']
151        selfurl = self.absolute_url()
152        pn = pageinfo['current']
153        hrefList=[]
154        myList= ""
155        text=self.getServerData("xpath.xql", "document=%s&xpath=%s&pn=%s"%(docinfo['textURLPath'],xpath,pn))
156        dom = Parse(text)
157        result = dom.xpath("//result/resultPage/place")
158        for l in result:
159            hrefNode= l.getAttributeNodeNS(None, u"id")
160            href= hrefNode.nodeValue
161            hrefList.append(href)
162            myList = ",".join(hrefList)
163        logging.debug("getGisPlaces :%s"%(myList))                             
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")
178       
179        for l in result:
180            hrefNode = l.getAttributeNodeNS(None, u"id")
181            href= hrefNode.nodeValue
182            hrefList.append(href)
183            myList = ",".join(hrefList)
184            logging.debug("getALLGisPlaces :%s"%(myList))
185        return myList
186   
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       
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))
200        #return text
201           
202    def getOrigPages (self, docinfo=None, pageinfo=None):
203        """Show original page """
204        docpath = docinfo.get('textURLPath',None)
205        if not docpath:
206            return None
207
208        logging.debug ("docinfo['textURLPath']=%s"%(docinfo['textURLPath']))
209        #url = docinfo['url']
210        selfurl = self.absolute_url()
211        pn =pageinfo['current']
212       
213        viewMode=  pageinfo['viewMode']
214        text = self.getServerData("page-fragment.xql","document=%s&mode=%s&pn=%s"%(docinfo['textURLPath'], 'text',  pn))
215        dom =Parse(text)
216        pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
217        if len(pagedivs)>0:
218            originalPage= getTextFromNode(pagedivs[0])
219            #return docinfo['originalPage']
220            return originalPage
221   
222    def getAllPlaces (self, docinfo=None, pageinfo=None):
223        """Show all Places if no places than 0"""
224        docpath = docinfo['textURLPath'] 
225        selfurl = self.absolute_url()   
226        viewMode=  pageinfo['viewMode']
227        text = self.getServerData("page-fragment.xql","document=%s&mode=%s"%(docinfo['textURLPath'], 'text'))
228        dom =Parse(text)
229        pagedivs = dom.xpath("//div[@class='countPlaces']")
230        logging.debug ("pagedivs=%s"%(pagedivs))
231        #originalPage= getTextFromNode(pagedivs[0])
232        #return allPlaces
233        if len(pagedivs)>0:
234            originalPage= getTextFromNode(pagedivs[0])
235            #return docinfo['originalPage']
236            return originalPage
237           
238    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):
239        """returns single page from fulltext"""
240        docpath = docinfo['textURLPath']
241        path = docinfo['textURLPath']
242        url = docinfo['url']
243        name = docinfo['name']
244        viewMode= pageinfo['viewMode']
245        sn = pageinfo['sn']
246        highlightQuery = pageinfo['highlightQuery']
247       
248        tocMode = pageinfo['tocMode']
249        characterNormalization=pageinfo['characterNormalization']
250        tocPN = pageinfo['tocPN']
251        selfurl = self.absolute_url()   
252        if mode == "text_dict":
253            textmode = "textPollux"
254        else:
255            textmode = mode
256        #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
257        textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization)
258        if highlightQuery is not None:
259            textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn)           
260            #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
261        pagexml = self.getServerData("page-fragment.xql",textParam)
262        logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))
263        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False)
264       
265        pagedom = Parse(pagexml)
266        # plain text mode
267        if mode == "text":
268            # first div contains text
269            pagedivs = pagedom.xpath("/div")
270            if len(pagedivs) > 0:     
271                pagenode = pagedivs[0]
272                links = pagenode.xpath("//a")
273                for l in links:
274                    hrefNode = l.getAttributeNodeNS(None, u"href")
275                    if hrefNode:
276                        href= hrefNode.nodeValue
277                        if href.startswith('#note-'):
278                            hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))
279                return serializeNode(pagenode)
280        if mode == "xml":
281              # first div contains text
282              pagedivs = pagedom.xpath("/div")
283              if len(pagedivs) > 0:
284                  pagenode = pagedivs[0]
285                  return serializeNode(pagenode)
286        if mode == "gis":
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('http://chinagis.mpiwg-berlin.mpg.de'):
297                              hrefNode.nodeValue =href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl/%s'%name)
298                              l.setAttributeNS(None, 'target', '_blank') 
299                  return serializeNode(pagenode)
300                   
301        if mode == "pureXml":
302              # first div contains text
303              pagedivs = pagedom.xpath("/div")
304              if len(pagedivs) > 0:
305                  pagenode = pagedivs[0]
306                  return serializeNode(pagenode)     
307        # text-with-links mode
308        if mode == "text_dict":
309            # first div contains text
310            pagedivs = pagedom.xpath("/div")
311            if len(pagedivs) > 0:
312                pagenode = pagedivs[0]
313                # check all a-tags
314                links = pagenode.xpath("//a")
315                for l in links:
316                    hrefNode = l.getAttributeNodeNS(None, u"href")
317                    if hrefNode:
318                        # is link with href
319                        href = hrefNode.nodeValue
320                        if href.startswith('lt/lex.xql'):
321                            # is pollux link
322                            selfurl = self.absolute_url()
323                            # change href
324                            hrefNode.nodeValue = href.replace('lt/lex.xql','%s/template/head_main_voc'%selfurl)
325                            # add target
326                            l.setAttributeNS(None, 'target', '_blank')
327                            l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;")
328                            l.setAttributeNS(None, 'onClick', 'popupWin.focus();')     
329                        if href.startswith('lt/lemma.xql'):   
330                            selfurl = self.absolute_url()
331                            hrefNode.nodeValue = href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl)
332                            l.setAttributeNS(None, 'target', '_blank')
333                            l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;")
334                            l.setAttributeNS(None, 'onClick', 'popupWin.focus();')   
335                        if href.startswith('#note-'):
336                            hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn))   
337                return serializeNode(pagenode)
338        return "no text here"
339
340    def getTranslate(self, query=None, language=None):
341        """translate into another languages"""
342        data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))
343        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
344        return data
345   
346    def getLemma(self, lemma=None, language=None):
347        """simular words lemma """
348        data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(lemma))
349        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma)))
350        return data
351   
352    def getLemmaNew(self, query=None, language=None):
353        """simular words lemma """
354        data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(query))
355        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query)))
356        return data
357   
358    def getQuery (self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionToggle=None):
359         """number of"""
360         docpath = docinfo['textURLPath'] 
361         pagesize = pageinfo['queryPageSize']
362         pn = pageinfo['searchPN']
363         query =pageinfo['query']
364         queryType =pageinfo['queryType']
365         tocSearch = 0
366         tocDiv = None
367         
368         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))
369         #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)
370         pagedom = Parse(pagexml)
371         numdivs = pagedom.xpath("//div[@class='queryResultHits']")
372         tocSearch = int(getTextFromNode(numdivs[0]))
373         logging.debug("documentViewer (gettoc) tocSearch: %s"%(tocSearch))
374         tc=int((tocSearch/10)+1)
375         logging.debug("documentViewer (gettoc) tc: %s"%(tc))
376         return tc
377
378    def getQueryResultHits(self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionsClose=None):
379       
380         """number of hits in Search mode"""
381         docpath = docinfo['textURLPath'] 
382         pagesize = pageinfo['queryPageSize']
383         pn = pageinfo['searchPN']
384         query =pageinfo['query']
385         queryType =pageinfo['queryType']
386         tocSearch = 0
387         tocDiv = None
388         
389         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))
390         #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)
391         pagedom = Parse(pagexml)
392         numdivs = pagedom.xpath("//div[@class='queryResultHits']")
393         tocSearch = int(getTextFromNode(numdivs[0])) 
394         tc=int((tocSearch/10)+1)   
395         return tc
396     
397    def getQueryResultHitsText(self,  docinfo=None, pageinfo=None):     
398         """number of hits in Text of Contents mode"""
399         
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         tocMode = pageinfo['tocMode']
408         tocPN = pageinfo['tocPN'] 
409         pagexml=self.getServerData("doc-query.xql", "document=%s&queryType=%s"%(docpath,'toc'))
410         pagedom = Parse(pagexml)
411         logging.debug("documentViewer (pagedom) pagedom: %s"%(pagedom))
412         numdivs = pagedom.xpath("//div[@class='queryResultHits']")
413         tocSearch = int(getTextFromNode(numdivs[0])) 
414         tc=int((tocSearch/30)+1) 
415         return tc
416
417    def getQueryResultHitsFigures(self,  docinfo=None, pageinfo=None):     
418         """number of hits in Text of Figures mode"""
419         
420         docpath = docinfo['textURLPath'] 
421         pagesize = pageinfo['queryPageSize']
422         pn = pageinfo['searchPN']
423         query =pageinfo['query']
424         queryType =pageinfo['queryType']
425         tocSearch = 0
426         tocDiv = None
427         tocMode = pageinfo['tocMode']
428         tocPN = pageinfo['tocPN'] 
429         pagexml=self.getServerData("doc-query.xql", "document=%s&queryType=%s"%(docpath,'figures'))
430         pagedom = Parse(pagexml)
431         logging.debug("documentViewer (pagedom) pagedom: %s"%(pagedom))
432         numdivs = pagedom.xpath("//div[@class='queryResultHits']")
433         tocSearch = int(getTextFromNode(numdivs[0])) 
434         tc=int((tocSearch/30)+1) 
435         return tc
436
437
438    def getToc(self, mode="text", docinfo=None):
439        """loads table of contents and stores in docinfo"""
440        logging.debug("documentViewer (gettoc) mode: %s"%(mode))
441        if mode == "none":
442            return docinfo       
443        if 'tocSize_%s'%mode in docinfo:
444            # cached toc
445            return docinfo
446       
447        docpath = docinfo['textURLPath']
448        # we need to set a result set size
449        pagesize = 1000
450        pn = 1
451        if mode == "text":
452            queryType = "toc"
453        else:
454            queryType = mode
455        # number of entries in toc
456        tocSize = 0
457        tocDiv = None
458       
459        pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))
460        #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False)
461        # post-processing downloaded xml
462        pagedom = Parse(pagexml)
463        # get number of entries
464        numdivs = pagedom.xpath("//div[@class='queryResultHits']")
465        if len(numdivs) > 0:
466            tocSize = int(getTextFromNode(numdivs[0]))
467        docinfo['tocSize_%s'%mode] = tocSize
468        return docinfo
469   
470    def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None):
471        """returns single page from the table of contents"""
472        # TODO: this should use the cached TOC
473        if mode == "text":
474            queryType = "toc"
475        else:
476            queryType = mode
477        docpath = docinfo['textURLPath']
478        path = docinfo['textURLPath']       
479        pagesize = pageinfo['tocPageSize']
480        pn = pageinfo['tocPN']
481        url = docinfo['url']
482        selfurl = self.absolute_url() 
483        viewMode=  pageinfo['viewMode']
484        characterNormalization = pageinfo ['characterNormalization']
485        optionToggle =pageinfo ['optionToggle']
486        tocMode = pageinfo['tocMode']
487        tocPN = pageinfo['tocPN'] 
488       
489        data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn)) 
490        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))
491        text = page.replace('mode=image','mode=texttool')
492        logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization))
493        #logging.debug("documentViewer (characterNormalization) text: %s"%(text))
494        return text
495   
496    def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
497        """change settings"""
498        self.title=title
499        self.timeout = timeout
500        self.serverUrl = serverUrl
501        if RESPONSE is not None:
502            RESPONSE.redirect('manage_main')
503       
504# management methods
505def manage_addMpdlXmlTextServerForm(self):
506    """Form for adding"""
507    pt = PageTemplateFile("zpt/manage_addMpdlXmlTextServer", globals()).__of__(self)
508    return pt()
509
510def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
511    """add zogiimage"""
512    newObj = MpdlXmlTextServer(id,title,serverUrl,timeout)
513    self.Destination()._setObject(id, newObj)
514    if RESPONSE is not None:
515        RESPONSE.redirect('manage_main')
516
517
518   
Note: See TracBrowser for help on using the repository browser.