Changeset 463:89ad327b4bbd in documentViewer
- Timestamp:
- Jul 28, 2011, 1:00:07 PM (13 years ago)
- Branch:
- elementtree
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
documentViewer.py
r462 r463 103 103 return '/'.join(path.split('/')[0:-1]) 104 104 105 def normalizeBibField(bt, underscore=True):106 """returns normalised bib type for looking up mappings"""107 bt = bt.strip().replace(' ', '-').lower()108 if underscore:109 bt = bt.replace('_', '-')110 111 return bt112 113 def getBibdataFromDom(dom):114 """returns dict with all elements from bib-tag"""115 bibinfo = {}116 bib = dom.find(".//meta/bib")117 if bib is not None:118 # put type in @type119 type = bib.get('type')120 bibinfo['@type'] = normalizeBibField(type)121 # put all subelements in dict122 for e in bib:123 bibinfo[normalizeBibField(e.tag)] = getText(e)124 125 return bibinfo126 127 105 128 106 ## … … 137 115 {'label':'main config','action':'changeDocumentViewerForm'}, 138 116 ) 117 118 metadataService = None 119 """MetaDataFolder instance""" 139 120 140 121 # templates and forms … … 156 137 157 138 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) 158 security.declareProtected('View management screens','changeDocumentViewerForm')159 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())160 139 161 140 … … 180 159 except Exception, e: 181 160 logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e)) 161 182 162 try: 183 163 from Products.zogiLib.zogiLib import zogiLib … … 187 167 except Exception, e: 188 168 logging.error("Unable to create zogiLib for zogilib: "+str(e)) 189 169 170 try: 171 # assume MetaDataFolder instance is called metadata 172 self.metadataService = getattr(self, 'metadata') 173 except Exception, e: 174 logging.error("Unable to find MetaDataFolder 'metadata': "+str(e)) 175 190 176 191 177 # proxy text server methods to fulltextclient … … 582 568 583 569 logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path)) 584 # try to get MetaDataFolder 585 metadata = getattr(self, 'metadata') 586 if metadata is not None: 570 if self.metadataService is not None: 587 571 # put all raw bib fields in dict "bib" 588 bib = metadata.getBibdataFromDom(dom)572 bib = self.metadataService.getBibData(dom=dom) 589 573 docinfo['bib'] = bib 590 574 bibtype = bib.get('@type', None) 591 575 docinfo['bib_type'] = bibtype 592 576 # also store DC metadata for convenience 593 dc = metadata.getDCMappedData(bib)577 dc = self.metadataService.getDCMappedData(bib) 594 578 docinfo['creator'] = dc.get('creator',None) 595 579 docinfo['title'] = dc.get('title',None) 596 580 docinfo['date'] = dc.get('date',None) 597 581 else: 598 logging.error("MetaDataFolder 'metadata' not found!") 599 #TODO: remove 600 bib = getBibdataFromDom(dom) 582 logging.error("MetadataService not found!") 601 583 return docinfo 602 584 … … 616 598 logging.debug("documentViewer docinfo[name] %s"%docinfo['name']) 617 599 return docinfo 600 618 601 619 602 def getDocinfoFromTextTool(self, url, dom=None, docinfo=None): … … 626 609 if dom is None: 627 610 dom = self.getDomFromIndexMeta(url) 611 612 texttool = self.metadata.getTexttoolData(dom=dom) 628 613 629 614 archivePath = None … … 651 636 raise IOError("Missing archive-path (for text-tool) in %s" % (url)) 652 637 653 imageDir = getText(dom.find(".//texttool/image"))638 imageDir = texttool.get('image', None) 654 639 655 640 if not imageDir: … … 670 655 docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + imageDir 671 656 672 viewerUrl = getText(dom.find(".//texttool/digiliburlprefix"))657 viewerUrl = texttool.get('digiliburlprefix', None) 673 658 if viewerUrl: 674 659 docinfo['viewerURL'] = viewerUrl 675 660 676 661 # old style text URL 677 textUrl = getText(dom.find(".//texttool/text"))662 textUrl = texttool.get('text', None) 678 663 if textUrl: 679 664 if urlparse.urlparse(textUrl)[0] == "": #keine url … … 686 671 687 672 # new style text-url-path 688 textUrl = getText(dom.find(".//texttool/text-url-path"))673 textUrl = texttool.get('text-url-path', None) 689 674 if textUrl: 690 675 docinfo['textURLPath'] = textUrl … … 695 680 #docinfo = self.getNumTextPages(docinfo) 696 681 697 698 presentationUrl = getText(dom.find(".//texttool/presentation")) 682 # get bib info 699 683 docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get info von bib tag 700 684 # TODO: is this needed here? 701 685 docinfo = self.getNameFromIndexMeta(url, docinfo=docinfo, dom=dom) 702 686 703 687 # TODO: what to do with presentation? 688 presentationUrl = texttool.get('presentation', None) 704 689 if presentationUrl: # ueberschreibe diese durch presentation informationen 705 690 # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten … … 713 698 docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl, docinfo=docinfo, dom=dom) 714 699 700 # get authorization 715 701 docinfo = self.getAuthinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get access info 716 702 … … 840 826 return pageinfo 841 827 828 829 security.declareProtected('View management screens','changeDocumentViewerForm') 830 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) 842 831 843 832 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): … … 848 837 self.thumbcols = thumbcols 849 838 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] 839 try: 840 # assume MetaDataFolder instance is called metadata 841 self.metadataService = getattr(self, 'metadata') 842 except Exception, e: 843 logging.error("Unable to find MetaDataFolder 'metadata': "+str(e)) 844 850 845 if RESPONSE is not None: 851 846 RESPONSE.redirect('manage_main')
Note: See TracChangeset
for help on using the changeset viewer.