Mercurial > hg > documentViewer
comparison MpdlXmlTextServer.py @ 435:94baa8dbc7e8
*** empty log message ***
| author | abukhman |
|---|---|
| date | Tue, 01 Mar 2011 15:53:15 +0100 |
| parents | 44ccb7bd0938 |
| children | 0baf4e761be7 |
comparison
equal
deleted
inserted
replaced
| 434:44ccb7bd0938 | 435:94baa8dbc7e8 |
|---|---|
| 127 l.setAttributeNS(None, 'target', '_blank') | 127 l.setAttributeNS(None, 'target', '_blank') |
| 128 l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") | 128 l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") |
| 129 l.setAttributeNS(None, 'onClick', 'popupWin.focus();') | 129 l.setAttributeNS(None, 'onClick', 'popupWin.focus();') |
| 130 return serializeNode(pagenode) | 130 return serializeNode(pagenode) |
| 131 return "no text here" | 131 return "no text here" |
| 132 | |
| 133 | 132 |
| 134 def getGisPlaces(self, docinfo=None, pageinfo=None): | 133 def getGisPlaces(self, docinfo=None, pageinfo=None): |
| 135 """ Show all Gis Places of whole Page""" | 134 """ Show all Gis Places of whole Page""" |
| 136 xpath='//place' | 135 xpath='//place' |
| 137 docpath = docinfo.get('textURLPath',None) | 136 docpath = docinfo.get('textURLPath',None) |
| 199 if highlightQuery is not None: | 198 if highlightQuery is not None: |
| 200 textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn) | 199 textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn) |
| 201 | 200 |
| 202 pagexml = self.getServerData("page-fragment.xql",textParam) | 201 pagexml = self.getServerData("page-fragment.xql",textParam) |
| 203 dom = Parse(pagexml) | 202 dom = Parse(pagexml) |
| 204 | |
| 205 #original Pages | 203 #original Pages |
| 206 pagedivs = dom.xpath("//div[@class='pageNumberOrig']") | 204 pagedivs = dom.xpath("//div[@class='pageNumberOrig']") |
| 207 if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"): | 205 if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"): |
| 208 if len(pagedivs)>0: | 206 if len(pagedivs)>0: |
| 209 docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0]) | 207 docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0]) |
| 210 #logging.debug("ORIGINAL PAGES: %s"%(docinfo['pageNumberOrig'])) | |
| 211 | 208 |
| 212 #original Pages Norm | 209 #original Pages Norm |
| 213 pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']") | 210 pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']") |
| 214 if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"): | 211 if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"): |
| 215 if len(pagedivs)>0: | 212 if len(pagedivs)>0: |
| 216 docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0]) | 213 docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0]) |
| 217 #logging.debug("ORIGINAL PAGES: %s"%(docinfo['pageNumberOrigNorm'])) | |
| 218 | |
| 219 | 214 |
| 220 #figureEntries | 215 #figureEntries |
| 221 pagedivs = dom.xpath("//div[@class='countFigureEntries']") | 216 pagedivs = dom.xpath("//div[@class='countFigureEntries']") |
| 222 if pagedivs == dom.xpath("//div[@class='countFigureEntries']"): | 217 if pagedivs == dom.xpath("//div[@class='countFigureEntries']"): |
| 223 if len(pagedivs)>0: | 218 if len(pagedivs)>0: |
| 224 docinfo['countFigureEntries'] = getTextFromNode(pagedivs[0]) | 219 docinfo['countFigureEntries'] = getTextFromNode(pagedivs[0]) |
| 225 s = getTextFromNode(pagedivs[0]) | 220 s = getTextFromNode(pagedivs[0]) |
| 226 if s=='0': | 221 if s=='0': |
| 227 try: | 222 try: |
| 228 docinfo['countFigureEntries'] = int(s) | 223 docinfo['countFigureEntries'] = int(s) |
| 229 #logging.debug("FIGURE ENTRIES: %s"%(s)) | |
| 230 except: | 224 except: |
| 231 docinfo['countFigureEntries'] = 0 | 225 docinfo['countFigureEntries'] = 0 |
| 232 else: | 226 else: |
| 233 s1 = int(s)/30+1 | 227 s1 = int(s)/30+1 |
| 234 try: | 228 try: |
| 235 docinfo['countFigureEntries'] = int(s1) | 229 docinfo['countFigureEntries'] = int(s1) |
| 236 #logging.debug("FIGURE ENTRIES: %s"%(s1)) | |
| 237 except: | 230 except: |
| 238 docinfo['countFigureEntries'] = 0 | 231 docinfo['countFigureEntries'] = 0 |
| 239 | 232 |
| 240 #allPlaces | 233 #allPlaces |
| 241 pagedivs = dom.xpath("//div[@class='countPlaces']") | 234 pagedivs = dom.xpath("//div[@class='countPlaces']") |
| 243 if len(pagedivs)>0: | 236 if len(pagedivs)>0: |
| 244 docinfo['countPlaces']= getTextFromNode(pagedivs[0]) | 237 docinfo['countPlaces']= getTextFromNode(pagedivs[0]) |
| 245 s = getTextFromNode(pagedivs[0]) | 238 s = getTextFromNode(pagedivs[0]) |
| 246 try: | 239 try: |
| 247 docinfo['countPlaces'] = int(s) | 240 docinfo['countPlaces'] = int(s) |
| 248 #logging.debug("PLACES HERE: %s"%(s)) | |
| 249 except: | 241 except: |
| 250 docinfo['countPlaces'] = 0 | 242 docinfo['countPlaces'] = 0 |
| 251 | 243 |
| 252 #tocEntries | 244 #tocEntries |
| 253 pagedivs = dom.xpath("//div[@class='countTocEntries']") | 245 pagedivs = dom.xpath("//div[@class='countTocEntries']") |
| 256 docinfo['countTocEntries'] = int(getTextFromNode(pagedivs[0])) | 248 docinfo['countTocEntries'] = int(getTextFromNode(pagedivs[0])) |
| 257 s = getTextFromNode(pagedivs[0]) | 249 s = getTextFromNode(pagedivs[0]) |
| 258 if s=='0': | 250 if s=='0': |
| 259 try: | 251 try: |
| 260 docinfo['countTocEntries'] = int(s) | 252 docinfo['countTocEntries'] = int(s) |
| 261 #logging.debug("TEXT ENTRIES: %s"%(s)) | |
| 262 except: | 253 except: |
| 263 docinfo['countTocEntries'] = 0 | 254 docinfo['countTocEntries'] = 0 |
| 264 else: | 255 else: |
| 265 s1 = int(s)/30+1 | 256 s1 = int(s)/30+1 |
| 266 try: | 257 try: |
| 267 docinfo['countTocEntries'] = int(s1) | 258 docinfo['countTocEntries'] = int(s1) |
| 268 #logging.debug("TEXT ENTRIES: %s"%(s1)) | |
| 269 except: | 259 except: |
| 270 docinfo['countTocEntries'] = 0 | 260 docinfo['countTocEntries'] = 0 |
| 271 | 261 |
| 272 #numTextPages | 262 #numTextPages |
| 273 pagedivs = dom.xpath("//div[@class='countPages']") | 263 pagedivs = dom.xpath("//div[@class='countPages']") |
| 299 #return docinfo | 289 #return docinfo |
| 300 | 290 |
| 301 # plain text mode | 291 # plain text mode |
| 302 if mode == "text": | 292 if mode == "text": |
| 303 # first div contains text | 293 # first div contains text |
| 304 #mode = viewMode | |
| 305 pagedivs = dom.xpath("/div") | 294 pagedivs = dom.xpath("/div") |
| 306 if len(pagedivs) > 0: | 295 if len(pagedivs) > 0: |
| 307 pagenode = pagedivs[0] | 296 pagenode = pagedivs[0] |
| 308 links = pagenode.xpath("//a") | 297 links = pagenode.xpath("//a") |
| 309 for l in links: | 298 for l in links: |
| 404 | 393 |
| 405 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)) | 394 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)) |
| 406 pagedom = Parse(pagexml) | 395 pagedom = Parse(pagexml) |
| 407 numdivs = pagedom.xpath("//div[@class='queryResultHits']") | 396 numdivs = pagedom.xpath("//div[@class='queryResultHits']") |
| 408 tocSearch = int(getTextFromNode(numdivs[0])) | 397 tocSearch = int(getTextFromNode(numdivs[0])) |
| 409 #logging.debug("documentViewer (gettoc) tocSearch: %s"%(tocSearch)) | |
| 410 tc=int((tocSearch/10)+1) | 398 tc=int((tocSearch/10)+1) |
| 411 #logging.debug("documentViewer (gettoc) tc: %s"%(tc)) | |
| 412 return tc | 399 return tc |
| 413 | 400 |
| 414 def getToc(self, mode="text", docinfo=None): | 401 def getToc(self, mode="text", docinfo=None): |
| 415 """loads table of contents and stores in docinfo""" | 402 """loads table of contents and stores in docinfo""" |
| 416 #logging.debug("documentViewer (gettoc) mode: %s"%(mode)) | |
| 417 if mode == "none": | 403 if mode == "none": |
| 418 return docinfo | 404 return docinfo |
| 419 if 'tocSize_%s'%mode in docinfo: | 405 if 'tocSize_%s'%mode in docinfo: |
| 420 # cached toc | 406 # cached toc |
| 421 return docinfo | 407 return docinfo |
| 463 tocPN = pageinfo['tocPN'] | 449 tocPN = pageinfo['tocPN'] |
| 464 | 450 |
| 465 data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn)) | 451 data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn)) |
| 466 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)) | 452 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)) |
| 467 text = page.replace('mode=image','mode=texttool') | 453 text = page.replace('mode=image','mode=texttool') |
| 468 #logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization)) | |
| 469 #logging.debug("TEXT %s"%(text)) | |
| 470 return text | 454 return text |
| 471 | 455 |
| 472 def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): | 456 def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): |
| 473 """change settings""" | 457 """change settings""" |
| 474 self.title=title | 458 self.title=title |
