--- documentViewer/MpdlXmlTextServer.py 2011/08/05 13:31:27 1.238.2.9 +++ documentViewer/MpdlXmlTextServer.py 2011/08/10 19:18:03 1.238.2.12 @@ -29,12 +29,6 @@ def getTextFromNode(node): """get the cdata content of a node""" if node is None: return "" - # ET: -# text = node.text or "" -# for e in node: -# text += gettext(e) -# if e.tail: -# text += e.tail # 4Suite: nodelist=node.childNodes @@ -187,8 +181,6 @@ class MpdlXmlTextServer(SimpleItem): if not docpath: return None - url = docinfo['url'] - selfurl = self.absolute_url() pn = pageinfo['current'] hrefList=[] myList= "" @@ -206,10 +198,6 @@ class MpdlXmlTextServer(SimpleItem): def getAllGisPlaces (self, docinfo=None, pageinfo=None): """Show all Gis Places of whole Book """ xpath ='//echo:place' - docpath =docinfo['textURLPath'] - url = docinfo['url'] - selfurl =self.absolute_url() - pn =pageinfo['current'] hrefList=[] myList="" text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'],xpath)) @@ -257,6 +245,10 @@ class MpdlXmlTextServer(SimpleItem): # WTF: s1 = int(s)/30+1 docinfo['numTocEntries'] = getInt(div.text) + # numPlaces + elif dc == 'countPlaces': + docinfo['numPlaces'] = getInt(div.text) + # numTextPages elif dc == 'countPages': np = getInt(div.text) @@ -265,7 +257,7 @@ class MpdlXmlTextServer(SimpleItem): if docinfo.get('numPages', 0) == 0: # seems to be text-only - update page count docinfo['numPages'] = np - pageinfo['end'] = min(pageinfo['end'], np) + #pageinfo['end'] = min(pageinfo['end'], np) pageinfo['numgroups'] = int(np / pageinfo['groupsize']) if np % pageinfo['groupsize'] > 0: pageinfo['numgroups'] += 1 @@ -302,6 +294,7 @@ class MpdlXmlTextServer(SimpleItem): textmode = "textPollux" elif not mode: # default is text + mode = "text" textmode = "text" else: textmode = mode @@ -340,7 +333,7 @@ class MpdlXmlTextServer(SimpleItem): return serialize(pagediv) # text-with-links mode - elif mode == "text_dict": + elif mode == "dict": if pagediv is not None: # check all a-tags links = pagediv.findall(".//a") @@ -499,7 +492,7 @@ class MpdlXmlTextServer(SimpleItem): return docinfo - def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None): + def getTocPage(self, mode="text", pn=0, pageinfo=None, docinfo=None): """returns single page from the table of contents""" logging.debug("getTocPage mode=%s, pn=%s"%(mode,pn)) if mode == "text": @@ -516,14 +509,10 @@ class MpdlXmlTextServer(SimpleItem): logging.error("getTocPage: unable to find tocXML") return "No ToC" - pagesize = int(pageinfo['tocPageSize']) - url = docinfo['url'] - urlmode = docinfo['mode'] - selfurl = docinfo['viewerUrl'] - viewMode= pageinfo['viewMode'] - tocMode = pageinfo['tocMode'] - tocPN = int(pageinfo['tocPN']) - pn = tocPN + pagesize = pageinfo['tocPageSize'] + tocPN = pageinfo['tocPN'] + if not pn: + pn = tocPN fulltoc = ET.fromstring(tocxml) @@ -543,8 +532,9 @@ class MpdlXmlTextServer(SimpleItem): # take pn from href m = re.match(r'page-fragment\.xql.*pn=(\d+)', href) if m is not None: - # and create new url - l.set('href', '%s?mode=%s&url=%s&viewMode=%s&pn=%s&tocMode=%s&tocPN=%s'%(selfurl, urlmode, url, viewMode, m.group(1), tocMode, tocPN)) + # 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)