Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 462)
+++ documentViewer.py	(revision 463)
@@ -103,26 +103,4 @@
     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
-
 
 ##
@@ -137,4 +115,7 @@
         {'label':'main config','action':'changeDocumentViewerForm'},
         )
+    
+    metadataService = None
+    """MetaDataFolder instance"""
 
     # templates and forms
@@ -156,6 +137,4 @@
     
     thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals())
-    security.declareProtected('View management screens','changeDocumentViewerForm')    
-    changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
 
     
@@ -180,4 +159,5 @@
         except Exception, e:
             logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e))
+            
         try:
             from Products.zogiLib.zogiLib import zogiLib
@@ -187,5 +167,11 @@
         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
@@ -582,21 +568,17 @@
         
         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
     
@@ -616,4 +598,5 @@
         logging.debug("documentViewer docinfo[name] %s"%docinfo['name'])
         return docinfo
+
     
     def getDocinfoFromTextTool(self, url, dom=None, docinfo=None):
@@ -626,4 +609,6 @@
         if dom is None:
             dom = self.getDomFromIndexMeta(url)
+            
+        texttool = self.metadata.getTexttoolData(dom=dom)
         
         archivePath = None
@@ -651,5 +636,5 @@
             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:
@@ -670,10 +655,10 @@
             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
@@ -686,5 +671,5 @@
     
         # 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
@@ -695,11 +680,11 @@
                 #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
@@ -713,4 +698,5 @@
             docinfo = self.getBibinfoFromTextToolPresentation(presentationUrl, docinfo=docinfo, dom=dom)
     
+        # get authorization
         docinfo = self.getAuthinfoFromIndexMeta(url, docinfo=docinfo, dom=dom)   # get access info
         
@@ -840,4 +826,7 @@
         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):
@@ -848,4 +837,10 @@
         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')
