--- OSA_system2/OSAS_metadata.py 2005/04/06 09:18:41 1.7 +++ OSA_system2/OSAS_metadata.py 2005/11/29 13:21:33 1.15 @@ -12,7 +12,10 @@ import xml.dom.pulldom import OSAS_helpers import zLOG import string -import xml.xpath +try: + from xml.xpath import Evaluate +except: + from Ft.Xml.XPath import Evaluate import xmlrpclib from types import * @@ -38,7 +41,7 @@ class OSAS_MetadataMapping(SimpleItem): for fieldName in arglist.keys(): setattr(self,"md_"+fieldName,arglist[fieldName]) - + manage_options = SimpleItem.manage_options+( {'label':'Main Config','action':'changeMetadataMappingForm'}, ) @@ -107,7 +110,7 @@ class OSAS_MetadataMapping(SimpleItem): if RESPONSE is not None: RESPONSE.redirect('manage_main') - + manage_workspace=changeMetadataMappingForm def manage_addMetadataMappingForm(self): """interface for adding the OSAS_root""" @@ -121,7 +124,7 @@ def manage_addMetadataMapping(self,idOfO argList={} for arg in self.fieldList: if not (arg in ['idOfObject','titleOfObject']): - argList[arg]=(self.REQUEST.form[arg],self.REQUEST.form['label_'+arg],self.REQUEST.form['explanation_'+arg],arglist['status_'+fieldName],arglist['values_'+fieldName]) + argList[arg]=(self.REQUEST.form[arg],self.REQUEST.form['label_'+arg],self.REQUEST.form['explanation_'+arg],self.REQUEST.form['status_'+arg],self.REQUEST.form['values_'+arg]) newObj=OSAS_MetadataMapping(idOfObject,titleOfObject,argList) self._setObject(idOfObject,newObj) @@ -181,29 +184,34 @@ class OSAS_Metadata(Folder): def generateMappingList(self): """Erzeuge Mapping""" mapping={} + for dict in self.__dict__: #print dict obj=getattr(self,dict) if hasattr(obj,'meta_type'): - if obj.meta_type=="OSAS_MetadataMapping": + if obj.meta_type=="OSAS_MetadataMapping__neu": mapping[obj.getId()]=obj.generateMappingHash() + return mapping def generateMappingForType(self,type,clean="yes"): """erzeuge spezifisches Mapping""" + hash=self.generateMappingList() - if hash.has_key(type): - if clean=="yes": - temp={} - for x in hash[type].keys(): - if not hash[type][x]=="": - temp[x]=hash[type][x] - return temp - else: - return hash[type] - else: - return {} + for key in hash.keys(): + if (key.lower() == type.lower()): + if clean=="yes": + temp={} + for x in hash[key].keys(): + if not hash[key][x]=="": + temp[x]=hash[key][x] + return temp + else: + + return hash[key] + + return {} def getFieldList(self): """erzeuge string aus fields""" @@ -212,6 +220,7 @@ class OSAS_Metadata(Folder): except: return "" + security.declarePublic('getFields') def getFields(self): """ausgabe der Felder""" return self.fieldList @@ -239,12 +248,12 @@ class OSAS_Metadata(Folder): types=[] - for obj in self.ZopeFind(self,obj_metatypes=['OSAS_MetadataMapping_neu']): - if obj.title=="": - title=obj.id - else: - title=obj.title - types.append((obj.id,title,obj)) + for obj in self.ZopeFind(self,obj_metatypes=['OSAS_MetadataMapping__neu']): + if obj[1].title=="": + title=obj[1].id + else: + title=obj[1].title + types.append((obj[1].id, title, obj[1])) return types @@ -263,7 +272,7 @@ class OSAS_Metadata(Folder): def getDisplayFieldsAsStr(self,indexMeta): ret=[] - try: + try: if indexMeta and not (indexMeta==""): dom=xml.dom.pulldom.parseString(indexMeta) @@ -288,8 +297,8 @@ class OSAS_Metadata(Folder): return "; ".join(ret) else: return "" - except: - return "" + except: + return "" def getDisplayFieldsAsStrOLD(self,indexMeta): """Gebe display fields als string zurück @param path: Pfad zum Object @@ -429,7 +438,7 @@ class OSAS_Metadata(Folder): xpathStr=MDF_xpathStart - xpathNodes=xml.xpath.Evaluate(xpathStr,actualNode) + xpathNodes=Evaluate(xpathStr,actualNode) if len(xpathNodes)>0: @@ -500,7 +509,7 @@ class OSAS_Metadata(Folder): xpathStr=MDF_xpathStart - xpathNodes=xml.xpath.Evaluate(xpathStr,actualNode) + xpathNodes=Evaluate(xpathStr,actualNode) @@ -511,7 +520,7 @@ class OSAS_Metadata(Folder): else: #existiert nicht dann neue erzeugen - if len(xml.xpath.Evaluate(MDF_xpathStart,dom))>0: + if len(Evaluate(MDF_xpathStart,dom))>0: create=True @@ -568,6 +577,8 @@ class OSAS_Metadata(Folder): actualNode.appendChild(namenode) ret=newdoc.toxml(encoding='utf-8') + zLOG.LOG("OSAS_metadata (writeMetadata)",zLOG.INFO,"write: %s"%ret) + server.writeMetaDataFile(indexFile,ret) @@ -593,7 +604,7 @@ class OSAS_Metadata(Folder): if list=="": return None - listsplit=list.split("\n") + listsplit=[i.rstrip() for i in list.split("\n")] return listsplit def showHelp(self,refType,genericTag):