changeset 28:40508e672841

richer metadata for bib. still not sufficient though.
author casties
date Mon, 20 Aug 2012 20:14:45 +0200
parents a0d273542509
children b3428e281ee2
files MetaData.py MetaDataFolder.py
diffstat 2 files changed, 19 insertions(+), 134 deletions(-) [+]
line wrap: on
line diff
--- a/MetaData.py	Wed Aug 15 17:07:37 2012 +0200
+++ b/MetaData.py	Mon Aug 20 20:14:45 2012 +0200
@@ -181,11 +181,18 @@
 
         if self.mappingSelectAttribute:
             # put type in @type
-            attr = data.get('@attr', None)
+            if all:
+                attr = data[0].get('@attr', None)
+            else:
+                attr = data.get('@attr', None)
+                
             if attr:
                 type = attr.get(self.mappingSelectAttribute, None)
                 if type is not None:
-                    data['@type'] = normalizeFieldName(type)
+                    if all:
+                        data[0]['@type'] = normalizeFieldName(type)
+                    else:
+                        data['@type'] = normalizeFieldName(type)
                 
         return data
     
@@ -277,7 +284,7 @@
             dc = fields[bk].get('dcmap', None)
             if dc:
                 # add value
-                if dcData.get('dc',None):
+                if dcData.get('dc', None):
                     # key exists - append
                     dcData[dc] += '/' + data[bk]
                 else:
@@ -285,7 +292,7 @@
                     
         return dcData
     
-    def getFormatted(self, template, path=None, dom=None, data=None, allFields=False):
+    def getFormatted(self, template, path=None, dom=None, data=None, xdata=None, allFields=False):
             """returns string with document data formatted according to template.
                gets data from server or dom or pre-parsed data."""
             logging.debug("getFormatted(template=%s)"%(template))
@@ -318,7 +325,7 @@
                 fields = {}
             
             #logging.debug(tp)    
-            return tp(mdmap=fields, md=data)
+            return tp(mdmap=fields, md=data, mdx=xdata)
 
 
     def correctPath(self,path,remove=None,prefix=None,cut=0):
--- a/MetaDataFolder.py	Wed Aug 15 17:07:37 2012 +0200
+++ b/MetaDataFolder.py	Mon Aug 20 20:14:45 2012 +0200
@@ -20,20 +20,6 @@
         
     return bt
 
-def OLDgetBibdataFromDom(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
-
 def toString(list):
     ret=u""
     
@@ -42,36 +28,6 @@
     
     return ret
 
-def dcMetaDataToHash(mdSet):
-    """Convenience Function for creates a hash from the DCMetadataset
-    @param mdSet: String containing DCMetadata informmation
-    currently only in the format getDCMetadata of this module"""
-    
-    NSS = {
-           'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
-           'dc': 'http://dublincore.org/documents/dcmi-namespace/',
-           'owl':"http://www.w3.org/2002/07/owl#",
-           'rdfs':"http://www.w3.org/2000/01/rdf-schema#"
-    }   
-    ret={}
-    import StringIO
-    import sys
-    buffer= StringIO.StringIO(mdSet)
-    try:
-        md = amara.parse(buffer,prefixes=NSS)
-    except:
-        logging.error("Error: %s (%s)"%(sys.exc_info()[0],sys.exc_info()[1]))
-                                
-        ret["error"]=mdSet
-        return ret
-   
-    ret["title"] = toString(md.xml_xpath("//dc:title/text()"))
-    ret["creator"] =toString(md.xml_xpath("//dc:creator/text()"))
-    ret["date"] = toString(md.xml_xpath("//dc:date/text()"))
-    
-    return ret
-        
-
 class MetaDataFolder(Folder):
     """provides methods for managing complete metadata structures"""
     meta_type='MetaDataFolder'
@@ -231,9 +187,9 @@
         return None
 
     
-    def getBibData(self, path=None, dom=None):
+    def getBibData(self, path=None, dom=None, all=False, recursive=0):
         """returns contents of bib tag as dict"""
-        return self.resource.meta.bib.getData(path=path, dom=dom)
+        return self.resource.meta.bib.getData(path=path, dom=dom, all=all, recursive=recursive)
 
     def getBibMapping(self, bibtype):
         """returns MetaDataMapping for resource/meta/bib of bibtype"""
@@ -251,15 +207,15 @@
         """returns dict with DC keys and data from bibdata"""
         return self.resource.meta.bib.getDCMappedData(bibdata)
                 
-    def getBibFormattedMetaData(self, path=None, dom=None, bibdata=None):
+    def getBibFormattedMetaData(self, path=None, dom=None, bibdata=None, bibxdata=None):
             """get the metadafrom server"""
             logging.debug("getBibFormattedMetaData(path=%s)"%path)
-            return self.resource.meta.bib.getFormatted('metadata_template', path=path, dom=dom, data=bibdata)
+            return self.resource.meta.bib.getFormatted('metadata_template', path=path, dom=dom, data=bibdata, xdata=bibxdata)
                 
-    def getBibFormattedMetaDataExtended(self,path=None, dom=None, bibdata=None):
+    def getBibFormattedMetaDataExtended(self,path=None, dom=None, bibdata=None, bibxdata=None):
             """get the metadafrom server"""
             logging.debug("getBibFormattedMetaDataExtended(path=%s)"%path)
-            return self.resource.meta.bib.getFormatted('metadata_extended_template', path=path, dom=dom, data=bibdata, allFields=True)
+            return self.resource.meta.bib.getFormatted('metadata_extended_template', path=path, dom=dom, data=bibdata, xdata=bibxdata, allFields=True)
             
     def getBibFormattedLabel(self,path=None, dom=None, bibdata=None):
             """get the metadafrom server"""
@@ -272,85 +228,7 @@
     getFormattedMetaDataExtended = getBibFormattedMetaDataExtended
     getFormattedLabel = getBibFormattedLabel
 
-                
-    def OLDgetDCFormatted(self,path):
-        """get the metadata as dc set"""
-        logging.debug("getDCFormatted(path=%s)"%path)
-        namespace={ 'mpiwg':  "http://www.mpiwg-berlin.mpg.de/ns/mpiwg"}
-        namespaceUsed=False
-        
-        md = self.getMDFromPathOrUrl(path)
-        logging.debug("MD in XML"+md)
-        im = amara.parse(md, prefixes=namespace)
-        
-        typePaths=im.xml_xpath('//bib/@type')
-        archimedes=False
-        
-        if len(typePaths)<1: 
-            typePaths=im.xml_xpath('//meta/archimedes') # sinderfall fuer veraltete index.meta files vom typ archimedes
-            if len(typePaths)>0:
-                type = "archimedes"
-                archimedes=True
-            else:
-                typePaths=im.xml_xpath('//mpiwg:bib/@type')
-                if len(typePaths)<1:
-                    return ""
-                else:
-                    namespaceUsed=True
-                    
-                    type=unicode(typePaths[0])
-        else:
-            type=unicode(typePaths[0])
-        logging.info("got type:"+type)    
-        try:
-            mapping=getattr(self.main.meta.bib,type.lower(),None)
-        except:
-            logging.error("getMetaDataFromServer no mapping  for type: %s"%type)
-            return ""     
-        
-        try:
-            dcMapping=getattr(self.main.meta.bib,"dc",None)
-        except:
-            logging.error("getMetaDataFromServer no dc in meta/bib")
-            return ""     
-        
-        mds=mapping.generateMappingHash() # Hole  das Mapping generisches Feld --> Feld im entsprechenden Typ
-        dcMds=dcMapping.generateMappingHash() 
-        
-        mdHash=[]
-        logging.debug("Value: %s"%repr(mds))
-       
-        for key,valueTriple in mds.items():
-                value=valueTriple[0]
-                logging.debug("Value: %s"%repr(value))
-                logging.debug("Key: %s"%repr(key))
-                if value!="":
-                    if not archimedes:
-                        if namespaceUsed:
-                            try:
-                                v = im.xml_xpath('//mpiwg:bib/mpiwg:%s/text()'%value)
-                            except:
-                                logging.error('cannot do: //mpiwg:bib/mpiwg:%s/text()'%value)
-                        else:
-                            v = im.xml_xpath('//bib/%s/text()'%value)
-                    else:
-                        v = im.xml_xpath('//archimedes/%s/text()'%value)
-                    if len(v) > 0:
-                        dc=dcMds[key][0]
-                        
-                        if (dc !="") and (value !=""):
-                            logging.debug("%s--> : %s"%(repr(value),dc))
-                            mdHash.append([dc,unicode(v[0])])
-               
-        ret="""<bib xmlns:dc="http://dublincore.org/documents/dcmi-namespace/"> """
-        ret+="<dc:type>%s</dc:type>"%type
-        for md in mdHash:
-
-            ret+="""<dc:%s>%s</dc:%s>"""%(md[0],xml.sax.saxutils.escape(md[1]),md[0])
-        ret+="</bib>"
-        return ret
-
-                        
+                                        
     changeMetaDataFolderForm = PageTemplateFile('zpt/changeMetaDataFolder',globals())
     
     security.declarePublic('changeMetaDataFolder')