Mercurial > hg > MetaDataProvider
comparison MetaDataFolder.py @ 27:a0d273542509
better DRI handling.
author | casties |
---|---|
date | Wed, 15 Aug 2012 17:07:37 +0200 |
parents | a19575be96e8 |
children | 40508e672841 |
comparison
equal
deleted
inserted
replaced
26:a19575be96e8 | 27:a0d273542509 |
---|---|
141 logging.error("getXmlPathData(%s)"%xmlpath) | 141 logging.error("getXmlPathData(%s)"%xmlpath) |
142 mdObj = self.getXmlPathObj(xmlpath) | 142 mdObj = self.getXmlPathObj(xmlpath) |
143 if mdObj is not None: | 143 if mdObj is not None: |
144 return mdObj.getData(path=path, dom=dom, recursive=recursive, all=all, allText=allText) | 144 return mdObj.getData(path=path, dom=dom, recursive=recursive, all=all, allText=allText) |
145 else: | 145 else: |
146 logging.error("getXmlPathData: MetaData element at '%s' not found!"%xmlpath) | 146 logging.error("getXmlPathData: MetaData object for '%s' not found!"%xmlpath) |
147 return None | 147 return None |
148 | 148 |
149 def getXmlPathFormatted(self, xmlpath, template, path=None, dom=None, data=None, allFields=False, recursive=0, all=False, allText=False): | 149 def getXmlPathFormatted(self, xmlpath, template, path=None, dom=None, data=None, allFields=False, recursive=0, all=False, allText=False): |
150 """returns contents of element at xmlpath as dict""" | 150 """returns contents of element at xmlpath as dict""" |
151 logging.error("getXmlPathFormatted(xmlpath=%s, template=%s)"%(xmlpath,template)) | 151 logging.error("getXmlPathFormatted(xmlpath=%s, template=%s)"%(xmlpath,template)) |
168 fmt = mdObj.getFormatted(template, path=path, dom=dom, data=data, allFields=allFields) | 168 fmt = mdObj.getFormatted(template, path=path, dom=dom, data=data, allFields=allFields) |
169 | 169 |
170 return fmt | 170 return fmt |
171 | 171 |
172 else: | 172 else: |
173 logging.error("getXmlPathFormatted: MetaData element at '%s' not found!"%xmlpath) | 173 logging.error("getXmlPathFormatted: MetaData object for '%s' not found!"%xmlpath) |
174 return '' | 174 return '' |
175 | 175 |
176 def getResourceData(self, path=None, dom=None): | 176 def getResourceData(self, path=None, dom=None): |
177 """returns contents of resource tag as dict""" | 177 """returns contents of resource tag as dict""" |
178 return self.getXmlPathData('resource', path=path, dom=dom) | 178 return self.getXmlPathData('resource', path=path, dom=dom) |
210 | 210 |
211 | 211 |
212 def getDRI(self, path=None, dom=None, type="escidoc"): | 212 def getDRI(self, path=None, dom=None, type="escidoc"): |
213 """returns the DRI of the document""" | 213 """returns the DRI of the document""" |
214 dris = self.getXmlPathData('resource/meta/dri', path=path, dom=dom, all=True) | 214 dris = self.getXmlPathData('resource/meta/dri', path=path, dom=dom, all=True) |
215 logging.debug("getDRI: dris=%s"%repr(dris)) | 215 #logging.debug("getDRI: dris=%s"%repr(dris)) |
216 if dris is None: | 216 if dris is None: |
217 return None | 217 return None |
218 | 218 |
219 for dri in dris: | 219 for dri in dris: |
220 logging.debug("getDRI: dri=%s"%dri) | 220 #logging.debug("getDRI: dri=%s"%dri) |
221 if type is None: | |
222 # no type -- take the first one | |
223 return dri.get('@text', None) | |
224 | |
225 # use element with matching @type | |
221 att = dri.get('@attr', None) | 226 att = dri.get('@attr', None) |
222 if att is not None: | 227 if att is not None: |
223 if (att.get('type', None) == type): | 228 if (att.get('type', None) == type): |
224 return dri.get('@text', None) | 229 return dri.get('@text', None) |
225 | 230 |
226 return None | 231 return None |
227 #return self.resource.meta.getDRI(path=path, dom=dom, type=type) | 232 |
228 | 233 |
229 def getBibData(self, path=None, dom=None): | 234 def getBibData(self, path=None, dom=None): |
230 """returns contents of bib tag as dict""" | 235 """returns contents of bib tag as dict""" |
231 return self.resource.meta.bib.getData(path=path, dom=dom) | 236 return self.resource.meta.bib.getData(path=path, dom=dom) |
232 | 237 |