comparison MetaDataFolder.py @ 15:41b90f09a1f2

new getdata
author casties
date Tue, 02 Aug 2011 12:34:11 +0200
parents 281d223aa361
children ba617e755c56
comparison
equal deleted inserted replaced
14:281d223aa361 15:41b90f09a1f2
129 xmlpath = xmlpath[1:] 129 xmlpath = xmlpath[1:]
130 130
131 obj = self.restrictedTraverse(xmlpath, None) 131 obj = self.restrictedTraverse(xmlpath, None)
132 return obj 132 return obj
133 133
134 def getXmlPathData(self, xmlpath, path=None, dom=None, allText=False, allOccurrences=False): 134 def getXmlPathData(self, xmlpath, path=None, dom=None, allText=False, all=False):
135 """returns contents of element at xmlpath as dict""" 135 """returns contents of element at xmlpath as dict"""
136 logging.error("getXmlPathData(%s)"%xmlpath) 136 logging.error("getXmlPathData(%s)"%xmlpath)
137 mdObj = self.getXmlPathObj(xmlpath) 137 mdObj = self.getXmlPathObj(xmlpath)
138 if mdObj is not None: 138 if mdObj is not None:
139 return mdObj.getData(path=path, dom=dom, allText=allText, allOccurrences=allOccurrences) 139 return mdObj.getData(path=path, dom=dom, allText=allText, all=all)
140 else: 140 else:
141 logging.error("getXmlPathData: MetaData element at '%s' not found!"%xmlpath) 141 logging.error("getXmlPathData: MetaData element at '%s' not found!"%xmlpath)
142 return None 142 return None
143 143
144 def getXmlPathFormatted(self, xmlpath, template, path=None, dom=None, data=None, allFields=False, allText=False, allOccurrences=False): 144 def getXmlPathFormatted(self, xmlpath, template, path=None, dom=None, data=None, allFields=False, allText=False, all=False):
145 """returns contents of element at xmlpath as dict""" 145 """returns contents of element at xmlpath as dict"""
146 logging.error("getXmlPathFormatted(xmlpath=%s, template=%s)"%(xmlpath,template)) 146 logging.error("getXmlPathFormatted(xmlpath=%s, template=%s)"%(xmlpath,template))
147 mdObj = self.getXmlPathObj(xmlpath) 147 mdObj = self.getXmlPathObj(xmlpath)
148 if mdObj is not None: 148 if mdObj is not None:
149 if data is None: 149 if data is None:
150 data = mdObj.getData(path=path, dom=dom, allText=allText, allOccurrences=allOccurrences) 150 data = mdObj.getData(path=path, dom=dom, allText=allText, all=all)
151 151
152 if data is None: 152 if data is None:
153 return '' 153 return ''
154 154
155 fmt = '' 155 fmt = ''
156 if allOccurrences: 156 if all:
157 # data is list of elements 157 # data is list of elements
158 for d in data: 158 for d in data:
159 # concatenate formatted strings 159 # concatenate formatted strings
160 fmt += mdObj.getFormatted(template, path=path, dom=dom, data=d, allFields=allFields) + '\n' 160 fmt += mdObj.getFormatted(template, path=path, dom=dom, data=d, allFields=allFields) + '\n'
161 161
178 178
179 def getAccessData(self, path=None, dom=None): 179 def getAccessData(self, path=None, dom=None):
180 """returns contents of access tag as dict""" 180 """returns contents of access tag as dict"""
181 return self.getXmlPathData('resource/meta/access-conditions/access', path=path, dom=dom) 181 return self.getXmlPathData('resource/meta/access-conditions/access', path=path, dom=dom)
182 182
183 def getAttributionData(self, path=None, dom=None, allOccurrences=True): 183 def getAttributionData(self, path=None, dom=None, all=True):
184 """returns contents of attribution tag as dict""" 184 """returns contents of attribution tag as dict"""
185 return self.getXmlPathData('resource/meta/access-conditions/attribution', path=path, dom=dom, allOccurrences=allOccurrences) 185 return self.getXmlPathData('resource/meta/access-conditions/attribution', path=path, dom=dom, all=all)
186 186
187 def getAttributionFormatted(self, template, path=None, dom=None, data=None, allOccurrences=True): 187 def getAttributionFormatted(self, template, path=None, dom=None, data=None, all=True):
188 """returns formatted contents of access tag""" 188 """returns formatted contents of access tag"""
189 return self.getXmlPathFormatted('resource/meta/access-conditions/attribution', template, path=path, dom=dom, data=data, allOccurrences=allOccurrences) 189 return self.getXmlPathFormatted('resource/meta/access-conditions/attribution', template, path=path, dom=dom, data=data, all=all)
190 190
191 def getCopyrightData(self, path=None, dom=None, allOccurrences=True): 191 def getCopyrightData(self, path=None, dom=None, all=True):
192 """returns contents of copyright tag as dict""" 192 """returns contents of copyright tag as dict"""
193 return self.getXmlPathData('resource/meta/access-conditions/copyright', path=path, dom=dom, allText=True, allOccurrences=allOccurrences) 193 return self.getXmlPathData('resource/meta/access-conditions/copyright', path=path, dom=dom, allText=True, all=all)
194 194
195 def getCopyrightFormatted(self, template, path=None, dom=None, data=None, allOccurrences=True): 195 def getCopyrightFormatted(self, template, path=None, dom=None, data=None, all=True):
196 """returns formatted contents of access tag""" 196 """returns formatted contents of access tag"""
197 return self.getXmlPathFormatted('resource/meta/access-conditions/copyright', template, path=path, dom=dom, data=data, allOccurrences=allOccurrences) 197 return self.getXmlPathFormatted('resource/meta/access-conditions/copyright', template, path=path, dom=dom, data=data, all=all)
198 198
199 def getBibData(self, path=None, dom=None): 199 def getBibData(self, path=None, dom=None):
200 """returns contents of bib tag as dict""" 200 """returns contents of bib tag as dict"""
201 return self.resource.meta.bib.getData(path=path, dom=dom) 201 return self.resource.meta.bib.getData(path=path, dom=dom)
202 202