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