Mercurial > hg > MetaDataProvider
diff MetaDataFolder.py @ 14:281d223aa361
attribution works now
author | casties |
---|---|
date | Mon, 01 Aug 2011 19:30:12 +0200 |
parents | 7f0e2b656e5c |
children | 41b90f09a1f2 |
line wrap: on
line diff
--- a/MetaDataFolder.py Fri Jul 29 20:35:10 2011 +0200 +++ b/MetaDataFolder.py Mon Aug 01 19:30:12 2011 +0200 @@ -122,20 +122,52 @@ return dom - def getXmlPathData(self, xmlpath, path=None, dom=None): - """returns contents of element at xmlpath as dict""" - logging.error("getXmlPathData(%s)"%xmlpath) + def getXmlPathObj(self, xmlpath): + """returns object at xmlpath""" # make xmlpath relative for Zope if xmlpath[0] == '/': xmlpath = xmlpath[1:] - mdObj = self.restrictedTraverse(xmlpath, None) + obj = self.restrictedTraverse(xmlpath, None) + return obj + + def getXmlPathData(self, xmlpath, path=None, dom=None, allText=False, allOccurrences=False): + """returns contents of element at xmlpath as dict""" + logging.error("getXmlPathData(%s)"%xmlpath) + mdObj = self.getXmlPathObj(xmlpath) if mdObj is not None: - return mdObj.getData(path=path, dom=dom) + return mdObj.getData(path=path, dom=dom, allText=allText, allOccurrences=allOccurrences) else: logging.error("getXmlPathData: MetaData element at '%s' not found!"%xmlpath) return None + def getXmlPathFormatted(self, xmlpath, template, path=None, dom=None, data=None, allFields=False, allText=False, allOccurrences=False): + """returns contents of element at xmlpath as dict""" + logging.error("getXmlPathFormatted(xmlpath=%s, template=%s)"%(xmlpath,template)) + mdObj = self.getXmlPathObj(xmlpath) + if mdObj is not None: + if data is None: + data = mdObj.getData(path=path, dom=dom, allText=allText, allOccurrences=allOccurrences) + + if data is None: + return '' + + fmt = '' + if allOccurrences: + # data is list of elements + for d in data: + # concatenate formatted strings + fmt += mdObj.getFormatted(template, path=path, dom=dom, data=d, allFields=allFields) + '\n' + + else: + fmt = mdObj.getFormatted(template, path=path, dom=dom, data=data, allFields=allFields) + + return fmt + + else: + logging.error("getXmlPathFormatted: MetaData element at '%s' not found!"%xmlpath) + return '' + def getResourceData(self, path=None, dom=None): """returns contents of resource tag as dict""" return self.getXmlPathData('resource', path=path, dom=dom) @@ -148,6 +180,22 @@ """returns contents of access tag as dict""" return self.getXmlPathData('resource/meta/access-conditions/access', path=path, dom=dom) + def getAttributionData(self, path=None, dom=None, allOccurrences=True): + """returns contents of attribution tag as dict""" + return self.getXmlPathData('resource/meta/access-conditions/attribution', path=path, dom=dom, allOccurrences=allOccurrences) + + def getAttributionFormatted(self, template, path=None, dom=None, data=None, allOccurrences=True): + """returns formatted contents of access tag""" + return self.getXmlPathFormatted('resource/meta/access-conditions/attribution', template, path=path, dom=dom, data=data, allOccurrences=allOccurrences) + + def getCopyrightData(self, path=None, dom=None, allOccurrences=True): + """returns contents of copyright tag as dict""" + return self.getXmlPathData('resource/meta/access-conditions/copyright', path=path, dom=dom, allText=True, allOccurrences=allOccurrences) + + def getCopyrightFormatted(self, template, path=None, dom=None, data=None, allOccurrences=True): + """returns formatted contents of access tag""" + return self.getXmlPathFormatted('resource/meta/access-conditions/copyright', template, path=path, dom=dom, data=data, allOccurrences=allOccurrences) + def getBibData(self, path=None, dom=None): """returns contents of bib tag as dict""" return self.resource.meta.bib.getData(path=path, dom=dom)