Changeset 99:4738a696d265 in documentViewer for documentViewer.py
- Timestamp:
- Apr 30, 2010, 2:36:00 PM (15 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
documentViewer.py
r97 r99 97 97 page_main_text = PageTemplateFile('zpt/page_main_text', globals()) 98 98 page_main_text_dict = PageTemplateFile('zpt/page_main_text_dict', globals()) 99 page_main_xml = PageTemplateFile('zpt/page_main_xml', globals()) 99 100 head_main = PageTemplateFile('zpt/head_main', globals()) 100 101 docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) … … 173 174 @param url: url which contains display information 174 175 @param viewMode: if images display images, if text display text, default is auto (text,images or auto) 175 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, search)176 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) 176 177 @param querySearch: type of different search modes (fulltext, fulltextMorph, xpath, xquery, ftIndex, ftIndexMorph) 177 178 ''' … … 654 655 if np % grpsize > 0: 655 656 pageinfo['numgroups'] += 1 656 657 658 657 659 pageinfo['viewMode'] = viewMode 658 660 pageinfo['tocMode'] = tocMode … … 660 662 pageinfo['queryType'] = self.REQUEST.get('queryType',' ') 661 663 pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') 664 665 pageinfo['textPN'] = self.REQUEST.get('textPN','1') 666 662 667 pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30') 663 668 pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '20') 664 669 pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') 665 #if 'tocSize_%s'%tocMode in docinfo: 670 toc = int (pageinfo['tocPN']) 671 pageinfo['textPages'] =int (toc) 672 673 if 'tocSize_%s'%tocMode in docinfo: 674 tocSize = int(docinfo['tocSize_%s'%tocMode]) 675 tocPageSize = int(pageinfo['tocPageSize']) 666 676 # cached toc 667 # pageinfo['tocPN'] = min (int (docinfo['tocSize_%s'%tocMode])/int(pageinfo['tocPageSize']),int(pageinfo['tocPN'])) 668 677 678 if tocSize%tocPageSize>0: 679 tocPages=tocSize/tocPageSize+1 680 else: 681 tocPages=tocSize/tocPageSize 682 pageinfo['tocPN'] = min (tocPages,toc) 683 669 684 pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') 670 685 pageinfo['sn'] =self.REQUEST.get('sn','1') … … 683 698 tocMode = pageinfo['tocMode'] 684 699 tocPN = pageinfo['tocPN'] 685 pagexml=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) 700 701 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) 702 pagexm = page.replace('?document=/echo/la/Benedetti_1585.xml','?url=/mpiwg/online/permanent/library/163127KK') 703 pagexml=pagexm.replace('mode=text','mode=texttool') 686 704 pagedom = Parse(pagexml) 687 pagedivs = pagedom.xpath("//div[@class='queryResultPage']") 688 689 selfurl = self.absolute_url() 690 691 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)) 692 text =page.replace('mode=text','mode=texttool') 693 href = text.replace('lt/lex.xql','%s/template/head_main_voc'%selfurl) 694 lemma= href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl) 695 #logging.debug("documentViewer (gettoc) lemma: %s"%(lemma)) 696 697 return lemma 705 706 if (queryType=="fulltext")or(queryType=="fulltextMorph")or(queryType=="xpath")or(queryType=="xquery"): 707 pagedivs = pagedom.xpath("//div[@class='queryResultPage']") 708 selfurl = self.absolute_url() 709 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)) 710 text =page.replace('mode=text','mode=texttool') 711 return text 712 713 if (queryType=="ftIndex")or(queryType=="ftIndexMorph"): 714 pagedivs= pagedom.xpath("//div[@class='queryResultPage']") 715 if len(pagedivs)>0: 716 pagenode=pagedivs[0] 717 links=pagenode.xpath("//a") 718 for l in links: 719 hrefNode = l.getAttributeNodeNS(None, u"href") 720 if hrefNode: 721 href = hrefNode.nodeValue 722 if href.startswith('../lt/lex.xql'): 723 selfurl = self.absolute_url() 724 hrefNode.nodeValue = href.replace('lt/lex.xql','%s/template/head_main_voc'%selfurl) 725 726 727 728 l.setAttributeNS(None, 'target', '_blank') 729 l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=200, scrollbars=1'); return false;") 730 l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') 731 if href.startswith('../lt/lemma.xql'): 732 selfurl = self.absolute_url() 733 hrefNode.nodeValue = href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl) 734 l.setAttributeNS(None, 'target', '_blank') 735 l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=200, scrollbars=1'); return false;") 736 l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') 737 return serializeNode(pagenode) 738 739 return "no text here" 698 740 699 700 #if len(pagedivs) > 0:701 # pagenode = pagedom[0]702 # return serializeNode(pagenode)703 #else:704 # return "xaxa"705 706 741 def getNumPages(self,docinfo=None): 707 742 """get list of pages from fulltext and put in docinfo""" … … 726 761 727 762 pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", "document=%s&mode=%s&pn=%s"%(docpath,textmode,pn), outputUnicode=False) 728 #######729 #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))730 #text =page.replace('mode=text','mode=texttool')731 #######732 763 # post-processing downloaded xml 733 764 pagedom = Parse(pagexml) … … 740 771 pagenode = pagedivs[0] 741 772 return serializeNode(pagenode) 742 773 if mode == "xml": 774 # first div contains text 775 pagedivs = pagedom.xpath("/div") 776 if len(pagedivs) > 0: 777 pagenode = pagedivs[0] 778 return serializeNode(pagenode) 743 779 # text-with-links mode 744 780 if mode == "text_dict": … … 761 797 # add target 762 798 l.setAttributeNS(None, 'target', '_blank') 799 l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;") 800 l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') 763 801 764 802 if href.startswith('lt/lemma.xql'): … … 766 804 hrefNode.nodeValue = href.replace('lt/lemma.xql','%s/template/head_main_lemma'%selfurl) 767 805 l.setAttributeNS(None, 'target', '_blank') 806 l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=700, scrollbars=1'); return false;") 807 l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();') 768 808 return serializeNode(pagenode) 769 809 … … 776 816 777 817 def getLemma(self, lemma=None, language=None): 778 """ lemma"""818 """simular words lemma """ 779 819 pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","lemma=%s&language=%s"%(lemma,language),outputUnicode=False) 780 820 return pagexml
Note: See TracChangeset
for help on using the changeset viewer.