--- OSA_system2/OSAS_metadata.py 2005/03/07 21:25:41 1.6 +++ OSA_system2/OSAS_metadata.py 2005/04/06 09:18:41 1.7 @@ -389,14 +389,71 @@ class OSAS_Metadata(Folder): pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMetadataForm_template.zpt')).__of__(self) return pt() + def readMetadata(self,MDF_path,MDF_type,MDF_prefix="",MDF_xpathStart="", MDF_addPath=None,MDF_identifyFields=None,newdoc=None,actualNode=None): + + if type(MDF_path)==ListType: + MDF_path=MDF_path[0] + + indexFile=os.path.join(MDF_path,'index.meta') + + server=xmlrpclib.Server(self.serverUrl) + + documentStr=server.getFile(indexFile) + + if documentStr: + newdoc=xml.dom.minidom.parseString(documentStr) + dom=newdoc.documentElement + actualNode=dom + else: + return {} + + if self.containerTag=="": + containerTag="doc" + else: + containerTag=self.containerTag + + if MDF_xpathStart=="": + dom=newdoc.documentElement + actualNode=dom + else: + #try to find xpath + if MDF_identifyFields: + query=[] + for field in MDF_identifyFields.keys(): + + query.append("""(%s="%s")"""%(field,MDF_identifyFields[field])) + querystr=" and ".join(query) + xpathStr=MDF_xpathStart+"[%s]"%querystr + + else: + xpathStr=MDF_xpathStart + + + xpathNodes=xml.xpath.Evaluate(xpathStr,actualNode) + + + if len(xpathNodes)>0: + actualNode=xpathNodes[0] + else: + return {} + + ret={} + for node in actualNode.childNodes: + name=node.tagName + text=OSAS_helpers.getText(node.childNodes) + ret[name]=text + + return ret + def writeMetadata(self,MDF_path,MDF_type,form,MDF_prefix="",MDF_xpathStart="", MDF_addPath=None,MDF_identifyFields=None,newdoc=None,actualNode=None): """writeMetadata""" #MDF_path="/tmp/index.meta" if type(MDF_path)==ListType: MDF_path=MDF_path[0] - indexFile=os.path.join(MDF_path,'index.meta') + indexFile=os.path.join(MDF_path,'index.meta') + server=xmlrpclib.Server(self.serverUrl) if newdoc: if not actualNode: actualNode=newdoc