Mercurial > hg > documentViewer
comparison documentViewer.py @ 463:89ad327b4bbd elementtree
more renovation
author | casties |
---|---|
date | Thu, 28 Jul 2011 15:00:07 +0200 |
parents | 0d378e8ebcc3 |
children | 19bd41d95f62 |
comparison
equal
deleted
inserted
replaced
462:0d378e8ebcc3 | 463:89ad327b4bbd |
---|---|
100 | 100 |
101 def getParentDir(path): | 101 def getParentDir(path): |
102 """returns pathname shortened by one""" | 102 """returns pathname shortened by one""" |
103 return '/'.join(path.split('/')[0:-1]) | 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 bt | |
112 | |
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 @type | |
119 type = bib.get('type') | |
120 bibinfo['@type'] = normalizeBibField(type) | |
121 # put all subelements in dict | |
122 for e in bib: | |
123 bibinfo[normalizeBibField(e.tag)] = getText(e) | |
124 | |
125 return bibinfo | |
126 | |
127 | 105 |
128 ## | 106 ## |
129 ## documentViewer class | 107 ## documentViewer class |
130 ## | 108 ## |
131 class documentViewer(Folder): | 109 class documentViewer(Folder): |
134 | 112 |
135 security=ClassSecurityInfo() | 113 security=ClassSecurityInfo() |
136 manage_options=Folder.manage_options+( | 114 manage_options=Folder.manage_options+( |
137 {'label':'main config','action':'changeDocumentViewerForm'}, | 115 {'label':'main config','action':'changeDocumentViewerForm'}, |
138 ) | 116 ) |
117 | |
118 metadataService = None | |
119 """MetaDataFolder instance""" | |
139 | 120 |
140 # templates and forms | 121 # templates and forms |
141 viewer_main = PageTemplateFile('zpt/viewer_main', globals()) | 122 viewer_main = PageTemplateFile('zpt/viewer_main', globals()) |
142 toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals()) | 123 toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals()) |
143 toc_text = PageTemplateFile('zpt/toc_text', globals()) | 124 toc_text = PageTemplateFile('zpt/toc_text', globals()) |
153 docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) | 134 docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) |
154 info_xml = PageTemplateFile('zpt/info_xml', globals()) | 135 info_xml = PageTemplateFile('zpt/info_xml', globals()) |
155 | 136 |
156 | 137 |
157 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) | 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 |
162 def __init__(self,id,imageScalerUrl=None,textServerName=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=5,authgroups="mpiwg"): | 141 def __init__(self,id,imageScalerUrl=None,textServerName=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=5,authgroups="mpiwg"): |
163 """init document viewer""" | 142 """init document viewer""" |
164 self.id=id | 143 self.id=id |
177 textServer = MpdlXmlTextServer.MpdlXmlTextServer(id='fulltextclient',serverName=textServerName) | 156 textServer = MpdlXmlTextServer.MpdlXmlTextServer(id='fulltextclient',serverName=textServerName) |
178 #templateFolder['fulltextclient'] = xmlRpcClient | 157 #templateFolder['fulltextclient'] = xmlRpcClient |
179 templateFolder._setObject('fulltextclient',textServer) | 158 templateFolder._setObject('fulltextclient',textServer) |
180 except Exception, e: | 159 except Exception, e: |
181 logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e)) | 160 logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e)) |
161 | |
182 try: | 162 try: |
183 from Products.zogiLib.zogiLib import zogiLib | 163 from Products.zogiLib.zogiLib import zogiLib |
184 zogilib = zogiLib(id="zogilib", title="zogilib for docuviewer", dlServerURL=imageScalerUrl, layout="book") | 164 zogilib = zogiLib(id="zogilib", title="zogilib for docuviewer", dlServerURL=imageScalerUrl, layout="book") |
185 #templateFolder['zogilib'] = zogilib | 165 #templateFolder['zogilib'] = zogilib |
186 templateFolder._setObject('zogilib',zogilib) | 166 templateFolder._setObject('zogilib',zogilib) |
187 except Exception, e: | 167 except Exception, e: |
188 logging.error("Unable to create zogiLib for zogilib: "+str(e)) | 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 # proxy text server methods to fulltextclient | 177 # proxy text server methods to fulltextclient |
192 def getTextPage(self, **args): | 178 def getTextPage(self, **args): |
193 """get page""" | 179 """get page""" |
194 return self.template.fulltextclient.getTextPage(**args) | 180 return self.template.fulltextclient.getTextPage(**args) |
579 dom = self.getDomFromIndexMeta(path) | 565 dom = self.getDomFromIndexMeta(path) |
580 | 566 |
581 docinfo['indexMetaPath']=self.getIndexMetaPath(path); | 567 docinfo['indexMetaPath']=self.getIndexMetaPath(path); |
582 | 568 |
583 logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path)) | 569 logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path)) |
584 # try to get MetaDataFolder | 570 if self.metadataService is not None: |
585 metadata = getattr(self, 'metadata') | |
586 if metadata is not None: | |
587 # put all raw bib fields in dict "bib" | 571 # put all raw bib fields in dict "bib" |
588 bib = metadata.getBibdataFromDom(dom) | 572 bib = self.metadataService.getBibData(dom=dom) |
589 docinfo['bib'] = bib | 573 docinfo['bib'] = bib |
590 bibtype = bib.get('@type', None) | 574 bibtype = bib.get('@type', None) |
591 docinfo['bib_type'] = bibtype | 575 docinfo['bib_type'] = bibtype |
592 # also store DC metadata for convenience | 576 # also store DC metadata for convenience |
593 dc = metadata.getDCMappedData(bib) | 577 dc = self.metadataService.getDCMappedData(bib) |
594 docinfo['creator'] = dc.get('creator',None) | 578 docinfo['creator'] = dc.get('creator',None) |
595 docinfo['title'] = dc.get('title',None) | 579 docinfo['title'] = dc.get('title',None) |
596 docinfo['date'] = dc.get('date',None) | 580 docinfo['date'] = dc.get('date',None) |
597 else: | 581 else: |
598 logging.error("MetaDataFolder 'metadata' not found!") | 582 logging.error("MetadataService not found!") |
599 #TODO: remove | |
600 bib = getBibdataFromDom(dom) | |
601 return docinfo | 583 return docinfo |
602 | 584 |
603 | 585 |
604 # TODO: is this needed? | 586 # TODO: is this needed? |
605 def getNameFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): | 587 def getNameFromIndexMeta(self,path,docinfo=None,dom=None,cut=0): |
613 dom = self.getDomFromIndexMeta(path) | 595 dom = self.getDomFromIndexMeta(path) |
614 | 596 |
615 docinfo['name']=getText(dom.find("name")) | 597 docinfo['name']=getText(dom.find("name")) |
616 logging.debug("documentViewer docinfo[name] %s"%docinfo['name']) | 598 logging.debug("documentViewer docinfo[name] %s"%docinfo['name']) |
617 return docinfo | 599 return docinfo |
600 | |
618 | 601 |
619 def getDocinfoFromTextTool(self, url, dom=None, docinfo=None): | 602 def getDocinfoFromTextTool(self, url, dom=None, docinfo=None): |
620 """parse texttool tag in index meta""" | 603 """parse texttool tag in index meta""" |
621 logging.debug("documentViewer (getdocinfofromtexttool) url: %s" % (url)) | 604 logging.debug("documentViewer (getdocinfofromtexttool) url: %s" % (url)) |
622 if docinfo is None: | 605 if docinfo is None: |
623 docinfo = {} | 606 docinfo = {} |
624 if docinfo.get('lang', None) is None: | 607 if docinfo.get('lang', None) is None: |
625 docinfo['lang'] = '' # default keine Sprache gesetzt | 608 docinfo['lang'] = '' # default keine Sprache gesetzt |
626 if dom is None: | 609 if dom is None: |
627 dom = self.getDomFromIndexMeta(url) | 610 dom = self.getDomFromIndexMeta(url) |
611 | |
612 texttool = self.metadata.getTexttoolData(dom=dom) | |
628 | 613 |
629 archivePath = None | 614 archivePath = None |
630 archiveName = None | 615 archiveName = None |
631 | 616 |
632 archiveName = getText(dom.find("name")) | 617 archiveName = getText(dom.find("name")) |
648 | 633 |
649 if archivePath is None: | 634 if archivePath is None: |
650 # we balk without archive-path | 635 # we balk without archive-path |
651 raise IOError("Missing archive-path (for text-tool) in %s" % (url)) | 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 if not imageDir: | 640 if not imageDir: |
656 # we balk with no image tag / not necessary anymore because textmode is now standard | 641 # we balk with no image tag / not necessary anymore because textmode is now standard |
657 #raise IOError("No text-tool info in %s"%(url)) | 642 #raise IOError("No text-tool info in %s"%(url)) |
658 imageDir = "" | 643 imageDir = "" |
667 docinfo = self.getDirinfoFromDigilib(imageDir, docinfo=docinfo) | 652 docinfo = self.getDirinfoFromDigilib(imageDir, docinfo=docinfo) |
668 docinfo['imagePath'] = imageDir | 653 docinfo['imagePath'] = imageDir |
669 | 654 |
670 docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + imageDir | 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 if viewerUrl: | 658 if viewerUrl: |
674 docinfo['viewerURL'] = viewerUrl | 659 docinfo['viewerURL'] = viewerUrl |
675 | 660 |
676 # old style text URL | 661 # old style text URL |
677 textUrl = getText(dom.find(".//texttool/text")) | 662 textUrl = texttool.get('text', None) |
678 if textUrl: | 663 if textUrl: |
679 if urlparse.urlparse(textUrl)[0] == "": #keine url | 664 if urlparse.urlparse(textUrl)[0] == "": #keine url |
680 textUrl = os.path.join(archivePath, textUrl) | 665 textUrl = os.path.join(archivePath, textUrl) |
681 # fix URLs starting with /mpiwg/online | 666 # fix URLs starting with /mpiwg/online |
682 if textUrl.startswith("/mpiwg/online"): | 667 if textUrl.startswith("/mpiwg/online"): |
683 textUrl = textUrl.replace("/mpiwg/online", '', 1) | 668 textUrl = textUrl.replace("/mpiwg/online", '', 1) |
684 | 669 |
685 docinfo['textURL'] = textUrl | 670 docinfo['textURL'] = textUrl |
686 | 671 |
687 # new style text-url-path | 672 # new style text-url-path |
688 textUrl = getText(dom.find(".//texttool/text-url-path")) | 673 textUrl = texttool.get('text-url-path', None) |
689 if textUrl: | 674 if textUrl: |
690 docinfo['textURLPath'] = textUrl | 675 docinfo['textURLPath'] = textUrl |
691 textUrlkurz = string.split(textUrl, ".")[0] | 676 textUrlkurz = string.split(textUrl, ".")[0] |
692 docinfo['textURLPathkurz'] = textUrlkurz | 677 docinfo['textURLPathkurz'] = textUrlkurz |
693 #if not docinfo['imagePath']: | 678 #if not docinfo['imagePath']: |
694 # text-only, no page images | 679 # text-only, no page images |
695 #docinfo = self.getNumTextPages(docinfo) | 680 #docinfo = self.getNumTextPages(docinfo) |
696 | 681 |
697 | 682 # get bib info |
698 presentationUrl = getText(dom.find(".//texttool/presentation")) | |
699 docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get info von bib tag | 683 docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get info von bib tag |
700 # TODO: is this needed here? | 684 # TODO: is this needed here? |
701 docinfo = self.getNameFromIndexMeta(url, docinfo=docinfo, dom=dom) | 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 if presentationUrl: # ueberschreibe diese durch presentation informationen | 689 if presentationUrl: # ueberschreibe diese durch presentation informationen |
705 # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten | 690 # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten |
706 # durch den relativen Pfad auf die presentation infos | 691 # durch den relativen Pfad auf die presentation infos |
707 presentationPath = presentationUrl | 692 presentationPath = presentationUrl |
708 if url.endswith("index.meta"): | 693 if url.endswith("index.meta"): |
710 else: | 695 else: |
711 presentationUrl = url + "/" + presentationPath | 696 presentationUrl = url + "/" + presentationPath |
712 | 697 |
713 docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl, docinfo=docinfo, dom=dom) | 698 docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl, docinfo=docinfo, dom=dom) |
714 | 699 |
700 # get authorization | |
715 docinfo = self.getAuthinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get access info | 701 docinfo = self.getAuthinfoFromIndexMeta(url, docinfo=docinfo, dom=dom) # get access info |
716 | 702 |
717 return docinfo | 703 return docinfo |
718 | 704 |
719 | 705 |
837 | 823 |
838 pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') | 824 pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') |
839 pageinfo['sn'] =self.REQUEST.get('sn','') | 825 pageinfo['sn'] =self.REQUEST.get('sn','') |
840 return pageinfo | 826 return pageinfo |
841 | 827 |
828 | |
829 security.declareProtected('View management screens','changeDocumentViewerForm') | |
830 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) | |
842 | 831 |
843 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): | 832 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): |
844 """init document viewer""" | 833 """init document viewer""" |
845 self.title=title | 834 self.title=title |
846 self.digilibBaseUrl = digilibBaseUrl | 835 self.digilibBaseUrl = digilibBaseUrl |
847 self.thumbrows = thumbrows | 836 self.thumbrows = thumbrows |
848 self.thumbcols = thumbcols | 837 self.thumbcols = thumbcols |
849 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] | 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 if RESPONSE is not None: | 845 if RESPONSE is not None: |
851 RESPONSE.redirect('manage_main') | 846 RESPONSE.redirect('manage_main') |
852 | 847 |
853 def manage_AddDocumentViewerForm(self): | 848 def manage_AddDocumentViewerForm(self): |
854 """add the viewer form""" | 849 """add the viewer form""" |