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