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 |
---|
8 | import urllib |
---|
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 | |
---|
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): |
---|
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 | tocPN = pageinfo['tocPN'] |
---|
55 | selfurl = self.absolute_url() |
---|
56 | |
---|
57 | data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&characterNormalization=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, sn, viewMode,characterNormalization ,urllib.quote(highlightQuery))) |
---|
58 | #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) |
---|
59 | |
---|
60 | pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url) |
---|
61 | pagedom = Parse(pagexml) |
---|
62 | if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"): |
---|
63 | pagedivs = pagedom.xpath("//div[@class='queryResultPage']") |
---|
64 | if len(pagedivs)>0: |
---|
65 | pagenode=pagedivs[0] |
---|
66 | links=pagenode.xpath("//a") |
---|
67 | for l in links: |
---|
68 | hrefNode = l.getAttributeNodeNS(None, u"href") |
---|
69 | if hrefNode: |
---|
70 | href = hrefNode.nodeValue |
---|
71 | if href.startswith('page-fragment.xql'): |
---|
72 | selfurl = self.absolute_url() |
---|
73 | pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN)) |
---|
74 | hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) |
---|
75 | return serializeNode(pagenode) |
---|
76 | if (queryType=="fulltextMorph"): |
---|
77 | pagedivs = pagedom.xpath("//div[@class='queryResult']") |
---|
78 | if len(pagedivs)>0: |
---|
79 | pagenode=pagedivs[0] |
---|
80 | links=pagenode.xpath("//a") |
---|
81 | for l in links: |
---|
82 | hrefNode = l.getAttributeNodeNS(None, u"href") |
---|
83 | if hrefNode: |
---|
84 | href = hrefNode.nodeValue |
---|
85 | if href.startswith('page-fragment.xql'): |
---|
86 | selfurl = self.absolute_url() |
---|
87 | pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN)) |
---|
88 | hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) |
---|
89 | if href.startswith('../lt/lemma.xql'): |
---|
90 | hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma_New'%(selfurl)) |
---|
91 | l.setAttributeNS(None, 'target', '_blank') |
---|
92 | l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
---|
93 | l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
---|
94 | pagedivs = pagedom.xpath("//div[@class='queryResultMorphExpansion']") |
---|
95 | return serializeNode(pagenode) |
---|
96 | if (queryType=="ftIndex")or(queryType=="ftIndexMorph"): |
---|
97 | pagedivs= pagedom.xpath("//div[@class='queryResultPage']") |
---|
98 | if len(pagedivs)>0: |
---|
99 | pagenode=pagedivs[0] |
---|
100 | links=pagenode.xpath("//a") |
---|
101 | for l in links: |
---|
102 | hrefNode = l.getAttributeNodeNS(None, u"href") |
---|
103 | if hrefNode: |
---|
104 | href = hrefNode.nodeValue |
---|
105 | hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s'%(viewMode,tocMode,tocPN,pn)) |
---|
106 | if href.startswith('../lt/lex.xql'): |
---|
107 | hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_voc'%selfurl) |
---|
108 | l.setAttributeNS(None, 'target', '_blank') |
---|
109 | l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
---|
110 | l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
---|
111 | if href.startswith('../lt/lemma.xql'): |
---|
112 | hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma'%selfurl) |
---|
113 | l.setAttributeNS(None, 'target', '_blank') |
---|
114 | l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
---|
115 | l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
---|
116 | return serializeNode(pagenode) |
---|
117 | return "no text here" |
---|
118 | |
---|
119 | """def getNumPages(self, docinfo): |
---|
120 | ""get list of pages from fulltext and put in docinfo"" |
---|
121 | if 'numPages' in docinfo: |
---|
122 | # already there |
---|
123 | return docinfo |
---|
124 | xquery = '//pb' |
---|
125 | text = self.getServerData("xquery.xql","document=%s&xquery=%s"%(docinfo['textURLPath'],xquery)) |
---|
126 | docinfo['numPages'] = text.count("<pb ") |
---|
127 | return docinfo |
---|
128 | """ |
---|
129 | def getNumTextPages (self, docinfo): |
---|
130 | """get list of pages from fulltext (texts without images) and put in docinfo""" |
---|
131 | if 'numPages' in docinfo: |
---|
132 | # allredy there |
---|
133 | return docinfo |
---|
134 | xpath ='/count(//pb)' |
---|
135 | text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'], xpath)) |
---|
136 | dom = Parse(text) |
---|
137 | result= dom.xpath("//result/resultPage") |
---|
138 | |
---|
139 | docinfo['numPages']=int(getTextFromNode(result[0])) |
---|
140 | return docinfo |
---|
141 | |
---|
142 | def getGisPlaces(self, docinfo=None, pageinfo=None): |
---|
143 | """ Show all Gis Places of whole Page""" |
---|
144 | xpath='//place' |
---|
145 | docpath = docinfo['textURLPath'] |
---|
146 | url = docinfo['url'] |
---|
147 | selfurl = self.absolute_url() |
---|
148 | pn = pageinfo['current'] |
---|
149 | hrefList=[] |
---|
150 | myList= "" |
---|
151 | text=self.getServerData("xpath.xql", "document=%s&xpath=%s&pn=%s"%(docinfo['textURLPath'],xpath,pn)) |
---|
152 | dom = Parse(text) |
---|
153 | result = dom.xpath("//result/resultPage/place") |
---|
154 | for l in result: |
---|
155 | hrefNode= l.getAttributeNodeNS(None, u"id") |
---|
156 | href= hrefNode.nodeValue |
---|
157 | hrefList.append(href) |
---|
158 | myList = ",".join(hrefList) |
---|
159 | logging.debug("getGisPlaces :%s"%(myList)) |
---|
160 | return myList |
---|
161 | |
---|
162 | def getAllGisPlaces (self, docinfo=None, pageinfo=None): |
---|
163 | """Show all Gis Places of whole Book """ |
---|
164 | xpath ='//echo:place' |
---|
165 | docpath =docinfo['textURLPath'] |
---|
166 | url = docinfo['url'] |
---|
167 | selfurl =self.absolute_url() |
---|
168 | pn =pageinfo['current'] |
---|
169 | hrefList=[] |
---|
170 | myList="" |
---|
171 | text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'],xpath)) |
---|
172 | dom =Parse(text) |
---|
173 | result = dom.xpath("//result/resultPage/place") |
---|
174 | for l in result: |
---|
175 | hrefNode = l.getAttributeNodeNS(None, u"id") |
---|
176 | href= hrefNode.nodeValue |
---|
177 | hrefList.append(href) |
---|
178 | myList = ",".join(hrefList) |
---|
179 | logging.debug("getALLGisPlaces :%s"%(myList)) |
---|
180 | return myList |
---|
181 | |
---|
182 | |
---|
183 | def getPDF (self, docinfo=None, pageinfo=None): |
---|
184 | """Show and Save different Pages as PDF in Options""" |
---|
185 | selfurl=self.absolute_url() |
---|
186 | pn=pageinfo['current'] |
---|
187 | |
---|
188 | viewMode =pageinfo['viewMode'] |
---|
189 | |
---|
190 | #text = ("page-fragment.xql","document=%s&mode=%s&pn=%s&export=%s"%(docinfo['textURLPath'], 'text', pn,'pdf')) |
---|
191 | #text = self.getServerData("page-fragment.xql", "document=%s&mode=%s&pn=%s&export=%s"(docinfo['textURLPath'],'text', pn,'pdf')) |
---|
192 | #logging.debug("text :%s"%(text)) |
---|
193 | #dom =Parse(text) |
---|
194 | #logging.debug("text :%s"%(text)) |
---|
195 | #return text |
---|
196 | |
---|
197 | def getOrigPages (self, docinfo=None, pageinfo=None): |
---|
198 | """Show original page """ |
---|
199 | docpath = docinfo['textURLPath'] |
---|
200 | logging.debug ("docinfo['textURLPath']=%s"%(docinfo['textURLPath'])) |
---|
201 | #url = docinfo['url'] |
---|
202 | selfurl = self.absolute_url() |
---|
203 | pn =pageinfo['current'] |
---|
204 | |
---|
205 | viewMode= pageinfo['viewMode'] |
---|
206 | text = self.getServerData("page-fragment.xql","document=%s&mode=%s&pn=%s"%(docinfo['textURLPath'], 'text', pn)) |
---|
207 | dom =Parse(text) |
---|
208 | pagedivs = dom.xpath("//div[@class='pageNumberOrig']") |
---|
209 | logging.debug("YYYYYYpagedivs :%s"%(pagedivs)) |
---|
210 | if len(pagedivs)>0: |
---|
211 | originalPage= getTextFromNode(pagedivs[0]) |
---|
212 | #return docinfo['originalPage'] |
---|
213 | return originalPage |
---|
214 | |
---|
215 | |
---|
216 | def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None, viewMode=None, tocMode=None, tocPN=None, characterNormalization="", highlightQuery=None, sn=None): |
---|
217 | """returns single page from fulltext""" |
---|
218 | docpath = docinfo['textURLPath'] |
---|
219 | path = docinfo['textURLPath'] |
---|
220 | url = docinfo['url'] |
---|
221 | name = docinfo['name'] |
---|
222 | viewMode= pageinfo['viewMode'] |
---|
223 | sn = pageinfo['sn'] |
---|
224 | highlightQuery = pageinfo['highlightQuery'] |
---|
225 | |
---|
226 | tocMode = pageinfo['tocMode'] |
---|
227 | characterNormalization=pageinfo['characterNormalization'] |
---|
228 | tocPN = pageinfo['tocPN'] |
---|
229 | selfurl = self.absolute_url() |
---|
230 | if mode == "text_dict": |
---|
231 | textmode = "textPollux" |
---|
232 | else: |
---|
233 | textmode = mode |
---|
234 | #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery)) |
---|
235 | textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization) |
---|
236 | if highlightQuery is not None: |
---|
237 | textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn) |
---|
238 | #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery)) |
---|
239 | pagexml = self.getServerData("page-fragment.xql",textParam) |
---|
240 | logging.debug("documentViewer highlightQuery: %s"%(highlightQuery)) |
---|
241 | #pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False) |
---|
242 | |
---|
243 | pagedom = Parse(pagexml) |
---|
244 | # plain text mode |
---|
245 | if mode == "text": |
---|
246 | # first div contains text |
---|
247 | pagedivs = pagedom.xpath("/div") |
---|
248 | if len(pagedivs) > 0: |
---|
249 | pagenode = pagedivs[0] |
---|
250 | links = pagenode.xpath("//a") |
---|
251 | for l in links: |
---|
252 | hrefNode = l.getAttributeNodeNS(None, u"href") |
---|
253 | if hrefNode: |
---|
254 | href= hrefNode.nodeValue |
---|
255 | if href.startswith('#note-'): |
---|
256 | hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn)) |
---|
257 | return serializeNode(pagenode) |
---|
258 | if mode == "xml": |
---|
259 | # first div contains text |
---|
260 | pagedivs = pagedom.xpath("/div") |
---|
261 | if len(pagedivs) > 0: |
---|
262 | pagenode = pagedivs[0] |
---|
263 | return serializeNode(pagenode) |
---|
264 | if mode == "gis": |
---|
265 | # first div contains text |
---|
266 | pagedivs = pagedom.xpath("/div") |
---|
267 | if len(pagedivs) > 0: |
---|
268 | pagenode = pagedivs[0] |
---|
269 | links =pagenode.xpath("//a") |
---|
270 | for l in links: |
---|
271 | hrefNode =l.getAttributeNodeNS(None, u"href") |
---|
272 | if hrefNode: |
---|
273 | href=hrefNode.nodeValue |
---|
274 | if href.startswith('http://chinagis.mpiwg-berlin.mpg.de'): |
---|
275 | hrefNode.nodeValue =href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl/%s'%name) |
---|
276 | l.setAttributeNS(None, 'target', '_blank') |
---|
277 | return serializeNode(pagenode) |
---|
278 | |
---|
279 | if mode == "pureXml": |
---|
280 | # first div contains text |
---|
281 | pagedivs = pagedom.xpath("/div") |
---|
282 | if len(pagedivs) > 0: |
---|
283 | pagenode = pagedivs[0] |
---|
284 | return serializeNode(pagenode) |
---|
285 | # text-with-links mode |
---|
286 | if mode == "text_dict": |
---|
287 | # first div contains text |
---|
288 | pagedivs = pagedom.xpath("/div") |
---|
289 | if len(pagedivs) > 0: |
---|
290 | pagenode = pagedivs[0] |
---|
291 | # check all a-tags |
---|
292 | links = pagenode.xpath("//a") |
---|
293 | for l in links: |
---|
294 | hrefNode = l.getAttributeNodeNS(None, u"href") |
---|
295 | if hrefNode: |
---|
296 | # is link with href |
---|
297 | href = hrefNode.nodeValue |
---|
298 | if href.startswith('lt/lex.xql'): |
---|
299 | # is pollux link |
---|
300 | selfurl = self.absolute_url() |
---|
301 | # change href |
---|
302 | hrefNode.nodeValue = href.replace('lt/lex.xql','%s/template/head_main_voc'%selfurl) |
---|
303 | # add target |
---|
304 | l.setAttributeNS(None, 'target', '_blank') |
---|
305 | l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;") |
---|
306 | l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
---|
307 | if href.startswith('lt/lemma.xql'): |
---|
308 | selfurl = self.absolute_url() |
---|
309 | hrefNode.nodeValue = href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl) |
---|
310 | l.setAttributeNS(None, 'target', '_blank') |
---|
311 | l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;") |
---|
312 | l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
---|
313 | if href.startswith('#note-'): |
---|
314 | hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn)) |
---|
315 | return serializeNode(pagenode) |
---|
316 | return "no text here" |
---|
317 | |
---|
318 | def getTranslate(self, query=None, language=None): |
---|
319 | """translate into another languages""" |
---|
320 | data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query)) |
---|
321 | #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query))) |
---|
322 | return data |
---|
323 | |
---|
324 | def getLemma(self, lemma=None, language=None): |
---|
325 | """simular words lemma """ |
---|
326 | data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(lemma)) |
---|
327 | #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma))) |
---|
328 | return data |
---|
329 | |
---|
330 | def getLemmaNew(self, query=None, language=None): |
---|
331 | """simular words lemma """ |
---|
332 | data = self.getServerData("lt/lemma.xql","document=&language="+str(language)+"&lemma="+urllib.quote(query)) |
---|
333 | #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query))) |
---|
334 | return data |
---|
335 | |
---|
336 | def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1): |
---|
337 | """number of""" |
---|
338 | docpath = docinfo['textURLPath'] |
---|
339 | pagesize = pageinfo['queryPageSize'] |
---|
340 | pn = pageinfo['searchPN'] |
---|
341 | query =pageinfo['query'] |
---|
342 | queryType =pageinfo['queryType'] |
---|
343 | tocSearch = 0 |
---|
344 | tocDiv = None |
---|
345 | |
---|
346 | 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)) |
---|
347 | #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) |
---|
348 | pagedom = Parse(pagexml) |
---|
349 | numdivs = pagedom.xpath("//div[@class='queryResultHits']") |
---|
350 | tocSearch = int(getTextFromNode(numdivs[0])) |
---|
351 | tc=int((tocSearch/10)+1) |
---|
352 | logging.debug("documentViewer (gettoc) tc: %s"%(tc)) |
---|
353 | return tc |
---|
354 | |
---|
355 | def getToc(self, mode="text", docinfo=None): |
---|
356 | """loads table of contents and stores in docinfo""" |
---|
357 | logging.debug("documentViewer (gettoc) mode: %s"%(mode)) |
---|
358 | if mode == "none": |
---|
359 | return docinfo |
---|
360 | if 'tocSize_%s'%mode in docinfo: |
---|
361 | # cached toc |
---|
362 | return docinfo |
---|
363 | |
---|
364 | docpath = docinfo['textURLPath'] |
---|
365 | # we need to set a result set size |
---|
366 | pagesize = 1000 |
---|
367 | pn = 1 |
---|
368 | if mode == "text": |
---|
369 | queryType = "toc" |
---|
370 | else: |
---|
371 | queryType = mode |
---|
372 | # number of entries in toc |
---|
373 | tocSize = 0 |
---|
374 | tocDiv = None |
---|
375 | |
---|
376 | pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn)) |
---|
377 | #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False) |
---|
378 | # post-processing downloaded xml |
---|
379 | pagedom = Parse(pagexml) |
---|
380 | # get number of entries |
---|
381 | numdivs = pagedom.xpath("//div[@class='queryResultHits']") |
---|
382 | if len(numdivs) > 0: |
---|
383 | tocSize = int(getTextFromNode(numdivs[0])) |
---|
384 | docinfo['tocSize_%s'%mode] = tocSize |
---|
385 | return docinfo |
---|
386 | |
---|
387 | def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None): |
---|
388 | """returns single page from the table of contents""" |
---|
389 | # TODO: this should use the cached TOC |
---|
390 | if mode == "text": |
---|
391 | queryType = "toc" |
---|
392 | else: |
---|
393 | queryType = mode |
---|
394 | docpath = docinfo['textURLPath'] |
---|
395 | path = docinfo['textURLPath'] |
---|
396 | pagesize = pageinfo['tocPageSize'] |
---|
397 | pn = pageinfo['tocPN'] |
---|
398 | url = docinfo['url'] |
---|
399 | selfurl = self.absolute_url() |
---|
400 | viewMode= pageinfo['viewMode'] |
---|
401 | characterNormalization = pageinfo ['characterNormalization'] |
---|
402 | tocMode = pageinfo['tocMode'] |
---|
403 | tocPN = pageinfo['tocPN'] |
---|
404 | |
---|
405 | data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=%s"%(docpath,queryType, pagesize, pn,characterNormalization)) |
---|
406 | page = data.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s'%(selfurl,url, viewMode, tocMode, tocPN)) |
---|
407 | text = page.replace('mode=image','mode=texttool') |
---|
408 | logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization)) |
---|
409 | #logging.debug("documentViewer (characterNormalization) text: %s"%(text)) |
---|
410 | return text |
---|
411 | |
---|
412 | def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): |
---|
413 | """change settings""" |
---|
414 | self.title=title |
---|
415 | self.timeout = timeout |
---|
416 | self.serverUrl = serverUrl |
---|
417 | if RESPONSE is not None: |
---|
418 | RESPONSE.redirect('manage_main') |
---|
419 | |
---|
420 | # management methods |
---|
421 | def manage_addMpdlXmlTextServerForm(self): |
---|
422 | """Form for adding""" |
---|
423 | pt = PageTemplateFile("zpt/manage_addMpdlXmlTextServer", globals()).__of__(self) |
---|
424 | return pt() |
---|
425 | |
---|
426 | def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): |
---|
427 | """add zogiimage""" |
---|
428 | newObj = MpdlXmlTextServer(id,title,serverUrl,timeout) |
---|
429 | self.Destination()._setObject(id, newObj) |
---|
430 | if RESPONSE is not None: |
---|
431 | RESPONSE.redirect('manage_main') |
---|
432 | |
---|
433 | |
---|
434 | |
---|