changeset 463:89ad327b4bbd elementtree

more renovation
author casties
date Thu, 28 Jul 2011 15:00:07 +0200
parents 0d378e8ebcc3
children 19bd41d95f62
files documentViewer.py
diffstat 1 files changed, 35 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/documentViewer.py	Wed Jul 27 21:09:44 2011 +0200
+++ b/documentViewer.py	Thu Jul 28 15:00:07 2011 +0200
@@ -102,28 +102,6 @@
     """returns pathname shortened by one"""
     return '/'.join(path.split('/')[0:-1])
         
-def normalizeBibField(bt, underscore=True):
-    """returns normalised bib type for looking up mappings"""
-    bt = bt.strip().replace(' ', '-').lower()
-    if underscore:
-        bt = bt.replace('_', '-')
-        
-    return bt
-
-def getBibdataFromDom(dom):
-    """returns dict with all elements from bib-tag"""
-    bibinfo = {}
-    bib = dom.find(".//meta/bib")
-    if bib is not None:
-        # put type in @type
-        type = bib.get('type')
-        bibinfo['@type'] = normalizeBibField(type)
-        # put all subelements in dict
-        for e in bib:
-            bibinfo[normalizeBibField(e.tag)] = getText(e)
-            
-    return bibinfo
-
 
 ##
 ## documentViewer class
@@ -136,6 +114,9 @@
     manage_options=Folder.manage_options+(
         {'label':'main config','action':'changeDocumentViewerForm'},
         )
+    
+    metadataService = None
+    """MetaDataFolder instance"""
 
     # templates and forms
     viewer_main = PageTemplateFile('zpt/viewer_main', globals())
@@ -155,8 +136,6 @@
     
     
     thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals())
-    security.declareProtected('View management screens','changeDocumentViewerForm')    
-    changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
 
     
     def __init__(self,id,imageScalerUrl=None,textServerName=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=5,authgroups="mpiwg"):
@@ -179,6 +158,7 @@
             templateFolder._setObject('fulltextclient',textServer)
         except Exception, e:
             logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e))
+            
         try:
             from Products.zogiLib.zogiLib import zogiLib
             zogilib = zogiLib(id="zogilib", title="zogilib for docuviewer", dlServerURL=imageScalerUrl, layout="book")
@@ -186,7 +166,13 @@
             templateFolder._setObject('zogilib',zogilib)
         except Exception, e:
             logging.error("Unable to create zogiLib for zogilib: "+str(e))
-        
+            
+        try:
+            # assume MetaDataFolder instance is called metadata 
+            self.metadataService = getattr(self, 'metadata')
+        except Exception, e:
+            logging.error("Unable to find MetaDataFolder 'metadata': "+str(e))
+            
         
     # proxy text server methods to fulltextclient
     def getTextPage(self, **args):
@@ -581,23 +567,19 @@
         docinfo['indexMetaPath']=self.getIndexMetaPath(path);
         
         logging.debug("documentViewer (getbibinfofromindexmeta cutted) path: %s"%(path))
-        # try to get MetaDataFolder
-        metadata = getattr(self, 'metadata')
-        if metadata is not None:
+        if self.metadataService is not None:
             # put all raw bib fields in dict "bib"
-            bib = metadata.getBibdataFromDom(dom)
+            bib = self.metadataService.getBibData(dom=dom)
             docinfo['bib'] = bib
             bibtype = bib.get('@type', None)
             docinfo['bib_type'] = bibtype
             # also store DC metadata for convenience
-            dc = metadata.getDCMappedData(bib)
+            dc = self.metadataService.getDCMappedData(bib)
             docinfo['creator'] = dc.get('creator',None)
             docinfo['title'] = dc.get('title',None)
             docinfo['date'] = dc.get('date',None)
         else:
-            logging.error("MetaDataFolder 'metadata' not found!")
-            #TODO: remove
-            bib = getBibdataFromDom(dom)
+            logging.error("MetadataService not found!")
         return docinfo
     
     
@@ -615,6 +597,7 @@
         docinfo['name']=getText(dom.find("name"))
         logging.debug("documentViewer docinfo[name] %s"%docinfo['name'])
         return docinfo
+
     
     def getDocinfoFromTextTool(self, url, dom=None, docinfo=None):
         """parse texttool tag in index meta"""
@@ -625,6 +608,8 @@
             docinfo['lang'] = '' # default keine Sprache gesetzt
         if dom is None:
             dom = self.getDomFromIndexMeta(url)
+            
+        texttool = self.metadata.getTexttoolData(dom=dom)
         
         archivePath = None
         archiveName = None
@@ -650,7 +635,7 @@
             # we balk without archive-path
             raise IOError("Missing archive-path (for text-tool) in %s" % (url))
         
-        imageDir = getText(dom.find(".//texttool/image"))
+        imageDir = texttool.get('image', None)
             
         if not imageDir:
             # we balk with no image tag / not necessary anymore because textmode is now standard
@@ -669,12 +654,12 @@
             
             docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + imageDir
             
-        viewerUrl = getText(dom.find(".//texttool/digiliburlprefix"))
+        viewerUrl = texttool.get('digiliburlprefix', None)
         if viewerUrl:
             docinfo['viewerURL'] = viewerUrl
         
         # old style text URL
-        textUrl = getText(dom.find(".//texttool/text"))
+        textUrl = texttool.get('text', None)
         if textUrl:
             if urlparse.urlparse(textUrl)[0] == "": #keine url
                 textUrl = os.path.join(archivePath, textUrl) 
@@ -685,7 +670,7 @@
             docinfo['textURL'] = textUrl
     
         # new style text-url-path
-        textUrl = getText(dom.find(".//texttool/text-url-path"))
+        textUrl = texttool.get('text-url-path', None)
         if textUrl:
             docinfo['textURLPath'] = textUrl
             textUrlkurz = string.split(textUrl, ".")[0]
@@ -694,13 +679,13 @@
                 # text-only, no page images
                 #docinfo = self.getNumTextPages(docinfo)
                   
-         
-        presentationUrl = getText(dom.find(".//texttool/presentation"))
+        # get bib info
         docinfo = self.getBibinfoFromIndexMeta(url, docinfo=docinfo, dom=dom)   # get info von bib tag
         # TODO: is this needed here?
         docinfo = self.getNameFromIndexMeta(url, docinfo=docinfo, dom=dom)
         
-        
+        # TODO: what to do with presentation?
+        presentationUrl = texttool.get('presentation', None)
         if presentationUrl: # ueberschreibe diese durch presentation informationen 
              # presentation url ergiebt sich ersetzen von index.meta in der url der fuer die Metadaten
              # durch den relativen Pfad auf die presentation infos
@@ -712,6 +697,7 @@
                 
             docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl, docinfo=docinfo, dom=dom)
     
+        # get authorization
         docinfo = self.getAuthinfoFromIndexMeta(url, docinfo=docinfo, dom=dom)   # get access info
         
         return docinfo
@@ -839,6 +825,9 @@
         pageinfo['sn'] =self.REQUEST.get('sn','')
         return pageinfo
 
+
+    security.declareProtected('View management screens','changeDocumentViewerForm')    
+    changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
     
     def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):
         """init document viewer"""
@@ -847,6 +836,12 @@
         self.thumbrows = thumbrows
         self.thumbcols = thumbcols
         self.authgroups = [s.strip().lower() for s in authgroups.split(',')]
+        try:
+            # assume MetaDataFolder instance is called metadata 
+            self.metadataService = getattr(self, 'metadata')
+        except Exception, e:
+            logging.error("Unable to find MetaDataFolder 'metadata': "+str(e))
+
         if RESPONSE is not None:
             RESPONSE.redirect('manage_main')