|
|
| version 1.48, 2010/04/30 14:36:00 | version 1.61, 2010/05/21 14:36:17 |
|---|---|
| Line 2 | Line 2 |
| from OFS.Folder import Folder | from OFS.Folder import Folder |
| from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate | from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
| from Products.PageTemplates.PageTemplateFile import PageTemplateFile | from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
| from Products.PythonScripts.standard import url_quote | |
| from AccessControl import ClassSecurityInfo | from AccessControl import ClassSecurityInfo |
| from AccessControl import getSecurityManager | from AccessControl import getSecurityManager |
| from Globals import package_home | from Globals import package_home |
| Line 174 class documentViewer(Folder): | Line 175 class documentViewer(Folder): |
| @param url: url which contains display information | @param url: url which contains display information |
| @param viewMode: if images display images, if text display text, default is auto (text,images or auto) | @param viewMode: if images display images, if text display text, default is auto (text,images or auto) |
| @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) | @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
| @param querySearch: type of different search modes (fulltext, fulltextMorph, xpath, xquery, ftIndex, ftIndexMorph) | @param querySearch: type of different search modes (fulltext, fulltextMorph, xpath, xquery, ftIndex, ftIndexMorph, fulltextMorphLemma) |
| ''' | ''' |
| logging.debug("documentViewer (index) mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) | logging.debug("documentViewer (index) mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) |
| Line 546 class documentViewer(Folder): | Line 547 class documentViewer(Folder): |
| if textUrls and (len(textUrls) > 0): | if textUrls and (len(textUrls) > 0): |
| textUrl = getTextFromNode(textUrls[0]) | textUrl = getTextFromNode(textUrls[0]) |
| docinfo['textURLPath'] = textUrl | docinfo['textURLPath'] = textUrl |
| if not docinfo['imagePath']: | |
| # text-only, no page images | |
| docinfo = self.getNumPages(docinfo) #im moment einfach auf eins setzen, navigation ueber die thumbs geht natuerlich nicht | |
| presentationUrls = dom.xpath("//texttool/presentation") | presentationUrls = dom.xpath("//texttool/presentation") |
| docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get info von bib tag | docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get info von bib tag |
| Line 558 class documentViewer(Folder): | Line 562 class documentViewer(Folder): |
| presentationUrl = url.replace('index.meta', presentationPath) | presentationUrl = url.replace('index.meta', presentationPath) |
| else: | else: |
| presentationUrl = url + "/" + presentationPath | presentationUrl = url + "/" + presentationPath |
| docinfo = self.getNumPages(docinfo) #im moment einfach auf eins setzen, navigation ueber die thumbs geht natuerlich nicht | |
| docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl, docinfo=docinfo, dom=dom) | docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl, docinfo=docinfo, dom=dom) |
| docinfo = self.getAuthinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get access info | docinfo = self.getAuthinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get access info |
| Line 661 class documentViewer(Folder): | Line 665 class documentViewer(Folder): |
| pageinfo['query'] = self.REQUEST.get('query',' ') | pageinfo['query'] = self.REQUEST.get('query',' ') |
| pageinfo['queryType'] = self.REQUEST.get('queryType',' ') | pageinfo['queryType'] = self.REQUEST.get('queryType',' ') |
| pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') | pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') |
| pageinfo['textPN'] = self.REQUEST.get('textPN','1') | pageinfo['textPN'] = self.REQUEST.get('textPN','1') |
| pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','') | |
| pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30') | 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') | pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') |
| toc = int (pageinfo['tocPN']) | toc = int (pageinfo['tocPN']) |
| pageinfo['textPages'] =int (toc) | pageinfo['textPages'] =int (toc) |
| Line 682 class documentViewer(Folder): | Line 685 class documentViewer(Folder): |
| pageinfo['tocPN'] = min (tocPages,toc) | pageinfo['tocPN'] = min (tocPages,toc) |
| pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') | pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') |
| pageinfo['sn'] =self.REQUEST.get('sn','1') | pageinfo['sn'] =self.REQUEST.get('sn','') |
| return pageinfo | 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): |
| """get search list""" | """get search list""" |
| docpath = docinfo['textURLPath'] | docpath = docinfo['textURLPath'] |
| url = docinfo['url'] | |
| logging.debug("documentViewer (gettoc) docpath: %s"%(docpath)) | |
| logging.debug("documentViewer (gettoc) url: %s"%(url)) | |
| pagesize = pageinfo['queryPageSize'] | pagesize = pageinfo['queryPageSize'] |
| pn = pageinfo['searchPN'] | pn = pageinfo['searchPN'] |
| sn = pageinfo['sn'] | sn = pageinfo['sn'] |
| highlightQuery = pageinfo['highlightQuery'] | |
| query =pageinfo['query'] | query =pageinfo['query'] |
| queryType =pageinfo['queryType'] | queryType =pageinfo['queryType'] |
| viewMode= pageinfo['viewMode'] | viewMode= pageinfo['viewMode'] |
| tocMode = pageinfo['tocMode'] | tocMode = pageinfo['tocMode'] |
| tocPN = pageinfo['tocPN'] | tocPN = pageinfo['tocPN'] |
| selfurl = self.absolute_url() | |
| page=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn) ,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) |
| pagexm = page.replace('?document=/echo/la/Benedetti_1585.xml','?url=/mpiwg/online/permanent/library/163127KK') | pagexml = page.replace('?document=%s'%str(docpath),'?url=%s'%url) |
| pagexml=pagexm.replace('mode=text','mode=texttool') | |
| pagedom = Parse(pagexml) | pagedom = Parse(pagexml) |
| if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"): | |
| if (queryType=="fulltext")or(queryType=="fulltextMorph")or(queryType=="xpath")or(queryType=="xquery"): | |
| pagedivs = pagedom.xpath("//div[@class='queryResultPage']") | pagedivs = pagedom.xpath("//div[@class='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('page-fragment.xql'): | |
| selfurl = self.absolute_url() | selfurl = self.absolute_url() |
| page = pagexml.replace('page-fragment.xql?document=/echo/la/Benedetti_1585.xml','%s?url=/mpiwg/online/permanent/library/163127KK&viewMode=%s&tocMode=%s&tocPN=%s&query=%s&queryType=%s'%(selfurl, viewMode, tocMode, tocPN, query, queryType)) | 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)) |
| text =page.replace('mode=text','mode=texttool') | hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) |
| return text | return serializeNode(pagenode) |
| if (queryType=="ftIndex")or(queryType=="ftIndexMorph"): | if (queryType=="fulltextMorph"): |
| pagedivs= pagedom.xpath("//div[@class='queryResultPage']") | pagedivs = pagedom.xpath("//div[@class='queryResult']") |
| if len(pagedivs)>0: | if len(pagedivs)>0: |
| pagenode=pagedivs[0] | pagenode=pagedivs[0] |
| links=pagenode.xpath("//a") | links=pagenode.xpath("//a") |
| Line 719 class documentViewer(Folder): | Line 732 class documentViewer(Folder): |
| hrefNode = l.getAttributeNodeNS(None, u"href") | hrefNode = l.getAttributeNodeNS(None, u"href") |
| if hrefNode: | if hrefNode: |
| href = hrefNode.nodeValue | href = hrefNode.nodeValue |
| if href.startswith('../lt/lex.xql'): | if href.startswith('page-fragment.xql'): |
| selfurl = self.absolute_url() | selfurl = self.absolute_url() |
| hrefNode.nodeValue = href.replace('lt/lex.xql','%s/template/head_main_voc'%selfurl) | 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) | |
| 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();') | |
| return serializeNode(pagenode) | |
| if (queryType=="ftIndex")or(queryType=="ftIndexMorph"): | |
| pagedivs= pagedom.xpath("//div[@class='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 | |
| 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') | l.setAttributeNS(None, 'target', '_blank') |
| l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=200, scrollbars=1'); return false;") | 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();') |
| if href.startswith('../lt/lemma.xql'): | 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, 'target', '_blank') |
| l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=200, scrollbars=1'); return false;") | 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();') |
| return serializeNode(pagenode) | return serializeNode(pagenode) |
| return "no text here" | return "no text here" |
| def getNumPages(self,docinfo=None): | def getNumPages(self,docinfo=None): |
| Line 746 class documentViewer(Folder): | Line 776 class documentViewer(Folder): |
| docinfo['numPages'] = text.count("<pb ") | docinfo['numPages'] = text.count("<pb ") |
| return docinfo | return docinfo |
| def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None,): | def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None, highlightQuery=None,sn=None, viewMode=None): |
| """returns single page from fulltext""" | """returns single page from fulltext""" |
| docpath = docinfo['textURLPath'] | docpath = docinfo['textURLPath'] |
| path = docinfo['textURLPath'] | |
| url = docinfo['url'] | |
| viewMode= pageinfo['viewMode'] | |
| tocMode = pageinfo['tocMode'] | |
| tocPN = pageinfo['tocPN'] | |
| selfurl = self.absolute_url() | |
| #pn = pageinfo['searchPN'] | |
| if mode == "text_dict": | if mode == "text_dict": |
| textmode = "textPollux" | textmode = "textPollux" |
| else: | else: |
| textmode = mode | textmode = mode |
| #selfurl = self.absolute_url() | textParam = "document=%s&mode=%s&pn=%s"%(docpath,textmode,pn) |
| #viewMode= pageinfo['viewMode'] | if highlightQuery is not None: |
| #tocMode = pageinfo['tocMode'] | textParam +="&highlightQuery=%s&sn=%s"%(highlightQuery,sn) |
| #tocPN = pageinfo['tocPN'] | |
| pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", "document=%s&mode=%s&pn=%s"%(docpath,textmode,pn), outputUnicode=False) | pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False) |
| # post-processing downloaded xml | |
| pagedom = Parse(pagexml) | pagedom = Parse(pagexml) |
| # plain text mode | # plain text mode |
| if mode == "text": | if mode == "text": |
| Line 769 class documentViewer(Folder): | Line 806 class documentViewer(Folder): |
| #queryResultPage | #queryResultPage |
| if len(pagedivs) > 0: | if len(pagedivs) > 0: |
| pagenode = 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) | return serializeNode(pagenode) |
| if mode == "xml": | if mode == "xml": |
| # first div contains text | # first div contains text |
| Line 805 class documentViewer(Folder): | Line 851 class documentViewer(Folder): |
| l.setAttributeNS(None, 'target', '_blank') | 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, '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 serializeNode(pagenode) |
| return "no text here" | return "no text here" |
| def getTranslate(self, query=None, language=None): | def getTranslate(self, query=None, language=None): |
| """translate into another languages""" | """translate into another languages""" |
| pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","query=%s&language=%s"%(query,language),outputUnicode=False) | pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query))) |
| return pagexml | return pagexml |
| def getLemma(self, lemma=None, language=None): | def getLemma(self, lemma=None, language=None): |
| """simular words lemma """ | """simular words lemma """ |
| pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","lemma=%s&language=%s"%(lemma,language),outputUnicode=False) | 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 | return pagexml |
| def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1): | def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1): |
| Line 834 class documentViewer(Folder): | Line 886 class documentViewer(Folder): |
| pagedom = Parse(pagexml) | pagedom = Parse(pagexml) |
| numdivs = pagedom.xpath("//div[@class='queryResultHits']") | numdivs = pagedom.xpath("//div[@class='queryResultHits']") |
| tocSearch = int(getTextFromNode(numdivs[0])) | tocSearch = int(getTextFromNode(numdivs[0])) |
| tc=int((tocSearch/20)+1) | tc=int((tocSearch/10)+1) |
| logging.debug("documentViewer (gettoc) tc: %s"%(tc)) | logging.debug("documentViewer (gettoc) tc: %s"%(tc)) |
| return tc | return tc |
| Line 879 class documentViewer(Folder): | Line 931 class documentViewer(Folder): |
| else: | else: |
| queryType = mode | queryType = mode |
| docpath = docinfo['textURLPath'] | docpath = docinfo['textURLPath'] |
| path = docinfo['textURLPath'] | |
| #logging.debug("documentViewer (gettoc) pathNomer: %s"%(pathNomer)) | |
| pagesize = pageinfo['tocPageSize'] | pagesize = pageinfo['tocPageSize'] |
| pn = pageinfo['tocPN'] | pn = pageinfo['tocPN'] |
| url = docinfo['url'] | |
| selfurl = self.absolute_url() | selfurl = self.absolute_url() |
| viewMode= pageinfo['viewMode'] | viewMode= pageinfo['viewMode'] |
| tocMode = pageinfo['tocMode'] | 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) | 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=/echo/la/Benedetti_1585.xml','%s?url=/mpiwg/online/permanent/library/163127KK&viewMode=%s&tocMode=%s&tocPN=%s'%(selfurl, viewMode, tocMode, tocPN)) | 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') | text = page.replace('mode=image','mode=texttool') |
| return text | return text |
| # post-processing downloaded xml | # post-processing downloaded xml |