--- documentViewer/MpdlXmlTextServer.py 2011/01/20 16:04:21 1.224 +++ documentViewer/MpdlXmlTextServer.py 2011/03/07 14:08:07 1.230 @@ -85,6 +85,7 @@ class MpdlXmlTextServer(SimpleItem): selfurl = self.absolute_url() 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)) hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) + #logging.debug("PUREXML :%s"%(serializeNode(pagenode))) return serializeNode(pagenode) if (queryType=="fulltextMorph"): pagedivs = pagedom.xpath("//div[@class='queryResult']") @@ -128,7 +129,6 @@ class MpdlXmlTextServer(SimpleItem): l.setAttributeNS(None, 'onClick', 'popupWin.focus();') return serializeNode(pagenode) return "no text here" - def getGisPlaces(self, docinfo=None, pageinfo=None): """ Show all Gis Places of whole Page""" @@ -150,7 +150,7 @@ class MpdlXmlTextServer(SimpleItem): href= hrefNode.nodeValue hrefList.append(href) myList = ",".join(hrefList) - logging.debug("getGisPlaces :%s"%(myList)) + #logging.debug("getGisPlaces :%s"%(myList)) return myList def getAllGisPlaces (self, docinfo=None, pageinfo=None): @@ -171,21 +171,20 @@ class MpdlXmlTextServer(SimpleItem): href= hrefNode.nodeValue hrefList.append(href) myList = ",".join(hrefList) - logging.debug("getALLGisPlaces :%s"%(myList)) + #logging.debug("getALLGisPlaces :%s"%(myList)) return myList - def getTextPage(self, docinfo=None, pageinfo=None): + def getTextPage(self, mode="text_dict", pn=1, docinfo=None, pageinfo=None): """returns single page from fulltext""" docpath = docinfo['textURLPath'] path = docinfo['textURLPath'] url = docinfo.get('url',None) name = docinfo.get('name',None) pn =pageinfo['current'] - viewMode= pageinfo['viewMode'] sn = pageinfo['sn'] highlightQuery = pageinfo['highlightQuery'] - mode = pageinfo ['viewMode'] + #mode = pageinfo ['viewMode'] tocMode = pageinfo['tocMode'] characterNormalization=pageinfo['characterNormalization'] tocPN = pageinfo['tocPN'] @@ -201,14 +200,20 @@ class MpdlXmlTextServer(SimpleItem): pagexml = self.getServerData("page-fragment.xql",textParam) dom = Parse(pagexml) - #original Pages pagedivs = dom.xpath("//div[@class='pageNumberOrig']") - if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"): + """if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"): if len(pagedivs)>0: docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0]) - logging.debug("ORIGINAL PAGES: %s"%(docinfo['pageNumberOrig'])) - + logging.debug("ORIGINAL PAGE: %s"%(docinfo['pageNumberOrig'])) + + #original Pages Norm + pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']") + if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"): + if len(pagedivs)>0: + docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0]) + logging.debug("ORIGINAL PAGE NORM: %s"%(docinfo['pageNumberOrigNorm'])) + """ #figureEntries pagedivs = dom.xpath("//div[@class='countFigureEntries']") if pagedivs == dom.xpath("//div[@class='countFigureEntries']"): @@ -218,14 +223,12 @@ class MpdlXmlTextServer(SimpleItem): if s=='0': try: docinfo['countFigureEntries'] = int(s) - logging.debug("FIGURE ENTRIES: %s"%(s)) except: docinfo['countFigureEntries'] = 0 else: s1 = int(s)/30+1 try: docinfo['countFigureEntries'] = int(s1) - logging.debug("FIGURE ENTRIES: %s"%(s1)) except: docinfo['countFigureEntries'] = 0 @@ -237,7 +240,6 @@ class MpdlXmlTextServer(SimpleItem): s = getTextFromNode(pagedivs[0]) try: docinfo['countPlaces'] = int(s) - logging.debug("PLACES HERE: %s"%(s)) except: docinfo['countPlaces'] = 0 @@ -250,14 +252,12 @@ class MpdlXmlTextServer(SimpleItem): if s=='0': try: docinfo['countTocEntries'] = int(s) - logging.debug("TEXT ENTRIES: %s"%(s)) except: docinfo['countTocEntries'] = 0 else: s1 = int(s)/30+1 try: docinfo['countTocEntries'] = int(s1) - logging.debug("TEXT ENTRIES: %s"%(s1)) except: docinfo['countTocEntries'] = 0 @@ -270,7 +270,7 @@ class MpdlXmlTextServer(SimpleItem): try: docinfo['numPages'] = int(s) - logging.debug("PAGE NUMBER: %s"%(s)) + #logging.debug("PAGE NUMBER: %s"%(s)) np = docinfo['numPages'] pageinfo['end'] = min(pageinfo['end'], np) @@ -287,6 +287,7 @@ class MpdlXmlTextServer(SimpleItem): docinfo['countPlaces'] = 0 docinfo['countTocEntries'] = 0 docinfo['numPages'] = 0 + docinfo['pageNumberOrigNorm'] = 0 #return docinfo # plain text mode @@ -301,7 +302,7 @@ class MpdlXmlTextServer(SimpleItem): if hrefNode: href= hrefNode.nodeValue if href.startswith('#note-'): - hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn)) + hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn)) return serializeNode(pagenode) if mode == "xml": # first div contains text @@ -333,6 +334,7 @@ class MpdlXmlTextServer(SimpleItem): # text-with-links mode if mode == "text_dict": # first div contains text + #mode = pageinfo ['viewMode'] pagedivs = dom.xpath("/div") if len(pagedivs) > 0: pagenode = pagedivs[0] @@ -359,10 +361,35 @@ class MpdlXmlTextServer(SimpleItem): l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;") l.setAttributeNS(None, 'onClick', 'popupWin.focus();') if href.startswith('#note-'): - hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,viewMode,tocMode,tocPN,pn)) + hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text_dict&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn)) return serializeNode(pagenode) return "no text here" + + def getOrigPages(self, docinfo=None, pageinfo=None): + docpath = docinfo['textURLPath'] + pn =pageinfo['current'] + selfurl = self.absolute_url() + pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn)) + dom = Parse(pagexml) + pagedivs = dom.xpath("//div[@class='pageNumberOrig']") + if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"): + if len(pagedivs)>0: + docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0]) + return docinfo['pageNumberOrig'] + + def getOrigPagesNorm(self, docinfo=None, pageinfo=None): + docpath = docinfo['textURLPath'] + pn =pageinfo['current'] + selfurl = self.absolute_url() + pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn)) + dom = Parse(pagexml) + pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']") + if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"): + if len(pagedivs)>0: + docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0]) + return docinfo['pageNumberOrigNorm'] + def getTranslate(self, query=None, language=None): """translate into another languages""" data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query)) @@ -395,14 +422,11 @@ class MpdlXmlTextServer(SimpleItem): pagedom = Parse(pagexml) numdivs = pagedom.xpath("//div[@class='queryResultHits']") tocSearch = int(getTextFromNode(numdivs[0])) - logging.debug("documentViewer (gettoc) tocSearch: %s"%(tocSearch)) tc=int((tocSearch/10)+1) - logging.debug("documentViewer (gettoc) tc: %s"%(tc)) return tc def getToc(self, mode="text", docinfo=None): """loads table of contents and stores in docinfo""" - logging.debug("documentViewer (gettoc) mode: %s"%(mode)) if mode == "none": return docinfo if 'tocSize_%s'%mode in docinfo: @@ -454,8 +478,6 @@ class MpdlXmlTextServer(SimpleItem): data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn)) 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)) text = page.replace('mode=image','mode=texttool') - #logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization)) - return text def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):