Changeset 511:551ca1641a5e in documentViewer for MpdlXmlTextServer.py
- Timestamp:
- Feb 28, 2012, 5:21:59 PM (12 years ago)
- Branch:
- elementtree
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MpdlXmlTextServer.py
r510 r511 7 7 import logging 8 8 import urllib 9 import urlparse 9 10 import base64 10 11 … … 140 141 141 142 # stuff for constructing full urls 142 characterNormalization = pageinfo.get('characterNormalization', None)143 moreTextParam = ''144 143 selfurl = docinfo['viewerUrl'] 144 textParams = {'document': docpath, 145 'pn': pn} 146 if 'characterNormalization' in pageinfo: 147 textParams['characterNormalization'] = pageinfo['characterNormalization'] 145 148 146 149 if not mode: … … 157 160 # add highlighting 158 161 highlightQuery = pageinfo.get('highlightQuery', None) 159 sn = pageinfo.get('sn', None) 160 if highlightQuery and sn: 161 moreTextParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn) 162 163 # remove mode 162 if highlightQuery: 163 textParams['highlightQuery'] = highlightQuery 164 textParams['highlightElement'] = pageinfo.get('highlightElement', '') 165 textParams['highlightElementPos'] = pageinfo.get('highlightElementPos', '') 166 167 # ignore mode in the following 164 168 modes.remove('search') 165 169 … … 175 179 textmode = modes[0] 176 180 177 textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization) 178 textParam += moreTextParam 181 textParams['mode'] = textmode 179 182 180 183 # fetch the page 181 pagexml = self.getServerData("page-fragment.xql", textParam)184 pagexml = self.getServerData("page-fragment.xql",urllib.urlencode(textParams)) 182 185 dom = ET.fromstring(pagexml) 183 186 # extract additional info … … 221 224 if href: 222 225 # is link with href 223 if href.startswith('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql'): 226 linkurl = urlparse.urlparse(href) 227 #logging.debug("getTextPage: linkurl=%s"%repr(linkurl)) 228 if linkurl.path.endswith('GetDictionaryEntries'): 229 #TODO: replace wordInfo page 224 230 # is dictionary link - change href (keeping parameters) 225 l.set('href', href.replace('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql','%s/template/viewer_wordinfo'%viewerurl))231 #l.set('href', href.replace('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql','%s/template/viewer_wordinfo'%viewerurl)) 226 232 # add target to open new page 227 233 l.set('target', '_blank') 228 234 229 235 # TODO: is this needed? 230 if href.startswith('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql'):231 selfurl = self.absolute_url()232 l.set('href', href.replace('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql','%s/head_main_lemma'%selfurl))233 l.set('target', '_blank')234 l.set('onclick',"popupWin = window.open(this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=no, scrollbars=1'); return false;")235 l.set('ondblclick', 'popupWin.focus();')236 # if href.startswith('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql'): 237 # selfurl = self.absolute_url() 238 # l.set('href', href.replace('http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql','%s/head_main_lemma'%selfurl)) 239 # l.set('target', '_blank') 240 # l.set('onclick',"popupWin = window.open(this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=no, scrollbars=1'); return false;") 241 # l.set('ondblclick', 'popupWin.focus();') 236 242 237 243 if href.startswith('#note-'): … … 273 279 def getSearchResults(self, mode, query=None, pageinfo=None, docinfo=None): 274 280 """loads list of search results and stores XML in docinfo""" 281 275 282 logging.debug("getSearchResults mode=%s query=%s"%(mode, query)) 276 283 if mode == "none": 277 284 return docinfo 278 285 279 if 'resultSize_%s_%s'%(mode,query) in docinfo: 280 # cached result 281 return docinfo 282 286 cachedQuery = docinfo.get('cachedQuery', None) 287 if cachedQuery is not None: 288 # cached search result 289 if cachedQuery == '%s_%s'%(mode,query): 290 # same query 291 return docinfo 292 293 else: 294 # different query 295 del docinfo['resultSize'] 296 del docinfo['resultXML'] 297 298 # cache query 299 docinfo['cachedQuery'] = '%s_%s'%(mode,query) 300 301 # fetch full results 283 302 docpath = docinfo['textURLPath'] 284 285 # fetch full results286 303 params = {'document': docpath, 287 304 'mode': 'text', … … 305 322 306 323 elif dc == 'queryResultHits': 307 docinfo['resultSize _%s_%s'%(mode,query)] = getInt(div.text)324 docinfo['resultSize'] = getInt(div.text) 308 325 309 326 if pagediv is not None: 310 327 # store XML in docinfo 311 docinfo['resultXML _%s_%s'%(mode,query)] = ET.tostring(pagediv, 'UTF-8')328 docinfo['resultXML'] = ET.tostring(pagediv, 'UTF-8') 312 329 313 330 return docinfo … … 317 334 """returns single page from the table of contents""" 318 335 logging.debug("getResultsPage mode=%s, pn=%s"%(mode,pn)) 319 # check for cached TOC 320 #TODO: cache only one search 321 if not docinfo.has_key('resultXML_%s_%s'%(mode,query)): 336 # check for cached result 337 if not 'resultXML' in docinfo: 322 338 self.getSearchResults(mode=mode, query=query, pageinfo=pageinfo, docinfo=docinfo) 323 339 324 resultxml = docinfo.get('resultXML _%s_%s'%(mode,query), None)340 resultxml = docinfo.get('resultXML', None) 325 341 if not resultxml: 326 342 logging.error("getResultPage: unable to find resultXML") … … 328 344 329 345 if size is None: 330 size = pageinfo.get(' searchResultPageSize', 20)346 size = pageinfo.get('resultPageSize', 10) 331 347 332 348 if start is None: … … 337 353 if fullresult is not None: 338 354 # paginate 339 first = start 355 first = start-1 340 356 len = size 341 357 del fullresult[:first] … … 348 364 href = l.get('href') 349 365 if href: 350 # take pn from href 351 m = re.match(r'page-fragment\.xql.*pn=(\d+)', href) 352 if m is not None: 353 # and create new url (assuming parent is documentViewer) 354 #TODO: add highlighting params 355 url = self.getLink('pn', m.group(1)) 356 l.set('href', url) 357 else: 358 logging.warning("getResultPage: Problem with link=%s"%href) 366 # assume all links go to pages 367 linkUrl = urlparse.urlparse(href) 368 linkParams = urlparse.parse_qs(linkUrl.query) 369 # take some parameters 370 params = {'pn': linkParams['pn'], 371 'highlightQuery': linkParams.get('highlightQuery',''), 372 'highlightElement': linkParams.get('highlightElement',''), 373 'highlightElementPos': linkParams.get('highlightElementPos','') 374 } 375 url = self.getLink(params=params) 376 l.set('href', url) 359 377 360 # fix two-divs-per-row with containing div361 # newtoc = ET.Element('div', {'class':'queryResultPage'})362 # for (d1,d2) in zip(tocdivs[::2],tocdivs[1::2]):363 # e = ET.Element('div',{'class':'tocline'})364 # e.append(d1)365 # e.append(d2)366 # newtoc.append(e)367 368 378 return serialize(tocdivs) 369 379
Note: See TracChangeset
for help on using the changeset viewer.