Mercurial > hg > documentViewer
changeset 128:4db49915d825 Root_modularisierung
Last lemma
author | abukhman |
---|---|
date | Fri, 11 Jun 2010 12:34:24 +0200 |
parents | 49f381f896d0 |
children | 9404b6c37920 |
files | documentViewer.py |
diffstat | 1 files changed, 22 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/documentViewer.py Wed Jun 09 12:29:33 2010 +0200 +++ b/documentViewer.py Fri Jun 11 12:34:24 2010 +0200 @@ -639,8 +639,7 @@ logger("documentViewer (getdocinfo)", logging.INFO,"docinfo: %s"%docinfo) self.REQUEST.SESSION['docinfo'] = docinfo return docinfo - - + def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None, viewMode=None, tocMode=None): """returns pageinfo with the given parameters""" pageinfo = {} @@ -661,9 +660,7 @@ pageinfo['end'] = min(pageinfo['end'], np) pageinfo['numgroups'] = int(np / grpsize) if np % grpsize > 0: - pageinfo['numgroups'] += 1 - - + pageinfo['numgroups'] += 1 pageinfo['viewMode'] = viewMode pageinfo['tocMode'] = tocMode pageinfo['query'] = self.REQUEST.get('query',' ') @@ -680,20 +677,17 @@ if 'tocSize_%s'%tocMode in docinfo: tocSize = int(docinfo['tocSize_%s'%tocMode]) tocPageSize = int(pageinfo['tocPageSize']) - # cached toc - + # cached toc if tocSize%tocPageSize>0: tocPages=tocSize/tocPageSize+1 else: tocPages=tocSize/tocPageSize - pageinfo['tocPN'] = min (tocPages,toc) - + pageinfo['tocPN'] = min (tocPages,toc) pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') pageinfo['sn'] =self.REQUEST.get('sn','') - return pageinfo - def getSearch(self, pn=1, pageinfo=None, docinfo=None, query=None, queryType=None): + def getSearch(self, pn=1, pageinfo=None, docinfo=None, query=None, queryType=None, lemma=None): """get search list""" docpath = docinfo['textURLPath'] url = docinfo['url'] @@ -725,8 +719,7 @@ 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'%(viewMode,queryType,query,pagesize,pn,tocMode,pn,tocPN)) hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) - return serializeNode(pagenode) - + return serializeNode(pagenode) if (queryType=="fulltextMorph"): pagedivs = pagedom.xpath("//div[@class='queryResult']") if len(pagedivs)>0: @@ -741,14 +734,12 @@ pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s'%(viewMode,queryType,query,pagesize,pn,tocMode,pn,tocPN)) hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) if href.startswith('../lt/lemma.xql'): - - hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma'%selfurl) + hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma_New'%(selfurl)) l.setAttributeNS(None, 'target', '_blank') l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;") l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') pagedivs = pagedom.xpath("//div[@class='queryResultMorphExpansion']") - return serializeNode(pagenode) - + return serializeNode(pagenode) if (queryType=="ftIndex")or(queryType=="ftIndexMorph"): pagedivs= pagedom.xpath("//div[@class='queryResultPage']") if len(pagedivs)>0: @@ -758,8 +749,7 @@ hrefNode = l.getAttributeNodeNS(None, u"href") if hrefNode: href = hrefNode.nodeValue - hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s'%(viewMode,tocMode,tocPN,pn)) - + hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s'%(viewMode,tocMode,tocPN,pn)) if href.startswith('../lt/lex.xql'): hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_voc'%selfurl) l.setAttributeNS(None, 'target', '_blank') @@ -790,9 +780,6 @@ tocMode = pageinfo['tocMode'] tocPN = pageinfo['tocPN'] selfurl = self.absolute_url() - - #pn = pageinfo['searchPN'] - if mode == "text_dict": textmode = "textPollux" else: @@ -800,26 +787,22 @@ textParam = "document=%s&mode=%s&pn=%s"%(docpath,textmode,pn) if highlightQuery is not None: - textParam +="&highlightQuery=%s&sn=%s"%(highlightQuery,sn) - + textParam +="&highlightQuery=%s&sn=%s"%(highlightQuery,sn) pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False) pagedom = Parse(pagexml) # plain text mode if mode == "text": # first div contains text pagedivs = pagedom.xpath("/div") - #queryResultPage if len(pagedivs) > 0: pagenode = pagedivs[0] links = pagenode.xpath("//a") for l in links: hrefNode = l.getAttributeNodeNS(None, u"href") - 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)) - return serializeNode(pagenode) if mode == "xml": # first div contains text @@ -854,21 +837,16 @@ # add target l.setAttributeNS(None, 'target', '_blank') 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, 'onDblclick', 'popupWin.focus();') - + l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') if href.startswith('lt/lemma.xql'): selfurl = self.absolute_url() hrefNode.nodeValue = href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl) l.setAttributeNS(None, 'target', '_blank') 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, 'onDblclick', 'popupWin.focus();') - + l.setAttributeNS(None, 'onDblclick', '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)) - - return serializeNode(pagenode) - return "no text here" def getTranslate(self, query=None, language=None): @@ -879,7 +857,11 @@ def getLemma(self, lemma=None, language=None): """simular words lemma """ pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(lemma))) - #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","lemma=%s&language=%s"%(lemma,language),outputUnicode=False) + return pagexml + + def getLemmaNew(self, query=None, language=None): + """simular words lemma """ + pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query))) return pagexml def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1): @@ -889,11 +871,9 @@ pn = pageinfo['searchPN'] query =pageinfo['query'] queryType =pageinfo['queryType'] - tocSearch = 0 tocDiv = None pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, query, pagesize, pn) ,outputUnicode=False) - pagedom = Parse(pagexml) numdivs = pagedom.xpath("//div[@class='queryResultHits']") tocSearch = int(getTextFromNode(numdivs[0])) @@ -905,8 +885,7 @@ """loads table of contents and stores in docinfo""" logging.debug("documentViewer (gettoc) mode: %s"%(mode)) if mode == "none": - return docinfo - + return docinfo if 'tocSize_%s'%mode in docinfo: # cached toc return docinfo @@ -929,16 +908,10 @@ numdivs = pagedom.xpath("//div[@class='queryResultHits']") if len(numdivs) > 0: tocSize = int(getTextFromNode(numdivs[0])) - # div contains text - #pagedivs = pagedom.xpath("//div[@class='queryResultPage']") - #if len(pagedivs) > 0: - # tocDiv = pagedivs[0] - docinfo['tocSize_%s'%mode] = tocSize - #docinfo['tocDiv_%s'%mode] = tocDiv return docinfo - def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None): +def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None): """returns single page from the table of contents""" # TODO: this should use the cached TOC if mode == "text": @@ -946,31 +919,20 @@ else: queryType = mode docpath = docinfo['textURLPath'] - path = docinfo['textURLPath'] - #logging.debug("documentViewer (gettoc) pathNomer: %s"%(pathNomer)) + path = docinfo['textURLPath'] pagesize = pageinfo['tocPageSize'] pn = pageinfo['tocPN'] url = docinfo['url'] selfurl = self.absolute_url() viewMode= pageinfo['viewMode'] tocMode = pageinfo['tocMode'] - tocPN = pageinfo['tocPN'] - + tocPN = pageinfo['tocPN'] pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn), outputUnicode=False) page = pagexml.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s'%(selfurl,url, viewMode, tocMode, tocPN)) text = page.replace('mode=image','mode=texttool') return text - # post-processing downloaded xml - #pagedom = Parse(text) - # div contains text - #pagedivs = pagedom.xpath("//div[@class='queryResultPage']") - #if len(pagedivs) > 0: - # pagenode = pagedivs[0] - # return serializeNode(pagenode) - #else: - # return "No TOC!" - def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): +def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): """init document viewer""" self.title=title self.digilibBaseUrl = digilibBaseUrl @@ -979,8 +941,6 @@ self.authgroups = [s.strip().lower() for s in authgroups.split(',')] if RESPONSE is not None: RESPONSE.redirect('manage_main') - - def manage_AddDocumentViewerForm(self): """add the viewer form""" @@ -995,10 +955,7 @@ if RESPONSE is not None: RESPONSE.redirect('manage_main') - -## ## DocumentViewerTemplate class -## class DocumentViewerTemplate(ZopePageTemplate): """Template for document viewer""" meta_type="DocumentViewer Template"