Mercurial > hg > documentViewer
changeset 519:9a3cc3732194
uses xml from doc-info.xql for table of contents now.
author | casties |
---|---|
date | Mon, 12 Mar 2012 19:02:57 +0100 |
parents | 91051b36b9cc |
children | 8c5aae9bdbbb acdbd82114bb |
files | MpdlXmlTextServer.py |
diffstat | 1 files changed, 2 insertions(+), 105 deletions(-) [+] |
line wrap: on
line diff
--- a/MpdlXmlTextServer.py Mon Mar 12 19:01:14 2012 +0100 +++ b/MpdlXmlTextServer.py Mon Mar 12 19:02:57 2012 +0100 @@ -499,113 +499,10 @@ tp += '<div class="toc float right page"><a href="%s">Page: %s</a></div>'%(pageurl, toc['pn']) tp += '</div>\n' - tp += '</div>' + tp += '</div>\n' return tp - - - def getToc_old(self, mode="text", docinfo=None): - """loads table of contents and stores XML in docinfo""" - logging.debug("getToc mode=%s"%mode) - if mode == "none": - return docinfo - - if 'tocSize_%s'%mode in docinfo: - # cached toc - return docinfo - - docpath = docinfo['textURLPath'] - # we need to set a result set size - pagesize = 1000 - pn = 1 - if mode == "text": - queryType = "toc" - else: - queryType = mode - # number of entries in toc - tocSize = 0 - tocDiv = None - # fetch full toc - pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn)) - dom = ET.fromstring(pagexml) - # page content is in <div class="queryResultPage"> - pagediv = None - # ElementTree 1.2 in Python 2.6 can't do div[@class='queryResultPage'] - alldivs = dom.findall("div") - for div in alldivs: - dc = div.get('class') - # page content div - if dc == 'queryResultPage': - pagediv = div - - elif dc == 'queryResultHits': - docinfo['tocSize_%s'%mode] = getInt(div.text) - - if pagediv is not None: - # store XML in docinfo - docinfo['tocXML_%s'%mode] = ET.tostring(pagediv, 'UTF-8') - - return docinfo - - def getTocPage_old(self, mode="text", pn=None, start=None, size=None, pageinfo=None, docinfo=None): - """returns single page from the table of contents""" - logging.debug("getTocPage mode=%s, pn=%s"%(mode,pn)) - if mode == "text": - queryType = "toc" - else: - queryType = mode - - # check for cached TOC - if not docinfo.has_key('tocXML_%s'%mode): - self.getToc(mode=mode, docinfo=docinfo) - - tocxml = docinfo.get('tocXML_%s'%mode, None) - if not tocxml: - logging.error("getTocPage: unable to find tocXML") - return "Error: no table of contents!" - - if size is None: - size = pageinfo.get('tocPageSize', 30) - - if start is None: - start = (pn - 1) * size - - fulltoc = ET.fromstring(tocxml) - - if fulltoc is not None: - # paginate - first = (start - 1) * 2 - len = size * 2 - del fulltoc[:first] - del fulltoc[len:] - tocdivs = fulltoc - - # check all a-tags - links = tocdivs.findall(".//a") - for l in links: - href = l.get('href') - if href: - # take pn from href - m = re.match(r'page-fragment\.xql.*pn=(\d+)', href) - if m is not None: - # and create new url (assuming parent is documentViewer) - url = self.getLink('pn', m.group(1)) - l.set('href', url) - else: - logging.warning("getTocPage: Problem with link=%s"%href) - - # fix two-divs-per-row with containing div - newtoc = ET.Element('div', {'class':'queryResultPage'}) - for (d1,d2) in zip(tocdivs[::2],tocdivs[1::2]): - e = ET.Element('div',{'class':'tocline'}) - e.append(d1) - e.append(d2) - newtoc.append(e) - - return serialize(newtoc) - - return "ERROR: no table of contents!" - + def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): """change settings"""