--- documentViewer/documentViewer.py 2010/05/19 16:19:45 1.52 +++ documentViewer/documentViewer.py 2010/06/08 16:57:36 1.67 @@ -221,6 +221,10 @@ class documentViewer(Folder): """try to get the digilib URL from zogilib""" url = self.template.zogilib.getDLBaseUrl() return url + + def getDocumentViewerURL(self): + """returns the URL of this instance""" + return self.absolute_url() def getStyle(self, idx, selected, style=""): """returns a string with the given style and append 'sel' if path == selected.""" @@ -665,11 +669,10 @@ class documentViewer(Folder): pageinfo['query'] = self.REQUEST.get('query',' ') pageinfo['queryType'] = self.REQUEST.get('queryType',' ') pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') - pageinfo['textPN'] = self.REQUEST.get('textPN','1') - + pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','') pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30') - pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '20') + pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10') pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') toc = int (pageinfo['tocPN']) pageinfo['textPages'] =int (toc) @@ -686,7 +689,7 @@ class documentViewer(Folder): pageinfo['tocPN'] = min (tocPages,toc) pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') - pageinfo['sn'] =self.REQUEST.get('sn','1') + pageinfo['sn'] =self.REQUEST.get('sn','') return pageinfo @@ -699,14 +702,14 @@ class documentViewer(Folder): pagesize = pageinfo['queryPageSize'] pn = pageinfo['searchPN'] sn = pageinfo['sn'] + highlightQuery = pageinfo['highlightQuery'] query =pageinfo['query'] queryType =pageinfo['queryType'] viewMode= pageinfo['viewMode'] tocMode = pageinfo['tocMode'] tocPN = pageinfo['tocPN'] selfurl = self.absolute_url() - logging.debug("documentViewer (gettoc) /mpdl/interface/doc-query.xql?document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn, viewMode)) - page=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn, viewMode) ,outputUnicode=False) + page=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&highlightQuery=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn, viewMode,highlightQuery) ,outputUnicode=False) pagexml = page.replace('?document=%s'%str(docpath),'?url=%s'%url) pagedom = Parse(pagexml) if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"): @@ -719,16 +722,13 @@ class documentViewer(Folder): if hrefNode: href = hrefNode.nodeValue if href.startswith('page-fragment.xql'): - selfurl = self.absolute_url() - #l.setAttributeNS(None, "span class = 'hit highlight'", "background-color: #77DD77;") + 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) - l.setAttributeNS(None, "onClick", "id='highlighting'") + hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) return serializeNode(pagenode) if (queryType=="fulltextMorph"): pagedivs = pagedom.xpath("//div[@class='queryResult']") - if len(pagedivs)>0: pagenode=pagedivs[0] links=pagenode.xpath("//a") @@ -741,11 +741,12 @@ class documentViewer(Folder): 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'): - selfurl = self.absolute_url() - 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'%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();') + l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') + pagedivs = pagedom.xpath("//div[@class='queryResultMorphExpansion']") return serializeNode(pagenode) if (queryType=="ftIndex")or(queryType=="ftIndexMorph"): @@ -760,13 +761,11 @@ class documentViewer(Folder): 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'): - # selfurl = self.absolute_url() hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_voc'%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();') 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=400, scrollbars=1'); return false;") @@ -782,38 +781,45 @@ class documentViewer(Folder): docinfo['numPages'] = text.count(" 0: - + 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-0006-01'): - selfurl = self.absolute_url() - hrefNode.nodeValue = href.replace("href='#note-'",'xaxa/%s/'%selfurl) + 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 @@ -821,6 +827,12 @@ class documentViewer(Folder): if len(pagedivs) > 0: pagenode = pagedivs[0] return serializeNode(pagenode) + if mode == "pureXml": + # first div contains text + pagedivs = pagedom.xpath("/div") + if len(pagedivs) > 0: + pagenode = pagedivs[0] + return serializeNode(pagenode) # text-with-links mode if mode == "text_dict": # first div contains text @@ -850,6 +862,11 @@ class documentViewer(Folder): 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();') + + 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" @@ -880,16 +897,20 @@ class documentViewer(Folder): pagedom = Parse(pagexml) numdivs = pagedom.xpath("//div[@class='queryResultHits']") tocSearch = int(getTextFromNode(numdivs[0])) - tc=int((tocSearch/20)+1) + 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: # cached toc - return docinfo + return docinfo + docpath = docinfo['textURLPath'] # we need to set a result set size pagesize = 1000 @@ -948,7 +969,6 @@ class documentViewer(Folder): # return serializeNode(pagenode) #else: # return "No TOC!" - def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): """init document viewer"""