Mercurial > hg > MetaDataProvider
comparison MetaDataFolder.py @ 14:281d223aa361
attribution works now
author | casties |
---|---|
date | Mon, 01 Aug 2011 19:30:12 +0200 |
parents | 7f0e2b656e5c |
children | 41b90f09a1f2 |
comparison
equal
deleted
inserted
replaced
13:5f48f956ffa3 | 14:281d223aa361 |
---|---|
120 if data: | 120 if data: |
121 dom = ET.fromstring(data) | 121 dom = ET.fromstring(data) |
122 | 122 |
123 return dom | 123 return dom |
124 | 124 |
125 def getXmlPathData(self, xmlpath, path=None, dom=None): | 125 def getXmlPathObj(self, xmlpath): |
126 """returns contents of element at xmlpath as dict""" | 126 """returns object at xmlpath""" |
127 logging.error("getXmlPathData(%s)"%xmlpath) | |
128 # make xmlpath relative for Zope | 127 # make xmlpath relative for Zope |
129 if xmlpath[0] == '/': | 128 if xmlpath[0] == '/': |
130 xmlpath = xmlpath[1:] | 129 xmlpath = xmlpath[1:] |
131 | 130 |
132 mdObj = self.restrictedTraverse(xmlpath, None) | 131 obj = self.restrictedTraverse(xmlpath, None) |
132 return obj | |
133 | |
134 def getXmlPathData(self, xmlpath, path=None, dom=None, allText=False, allOccurrences=False): | |
135 """returns contents of element at xmlpath as dict""" | |
136 logging.error("getXmlPathData(%s)"%xmlpath) | |
137 mdObj = self.getXmlPathObj(xmlpath) | |
133 if mdObj is not None: | 138 if mdObj is not None: |
134 return mdObj.getData(path=path, dom=dom) | 139 return mdObj.getData(path=path, dom=dom, allText=allText, allOccurrences=allOccurrences) |
135 else: | 140 else: |
136 logging.error("getXmlPathData: MetaData element at '%s' not found!"%xmlpath) | 141 logging.error("getXmlPathData: MetaData element at '%s' not found!"%xmlpath) |
137 return None | 142 return None |
138 | 143 |
144 def getXmlPathFormatted(self, xmlpath, template, path=None, dom=None, data=None, allFields=False, allText=False, allOccurrences=False): | |
145 """returns contents of element at xmlpath as dict""" | |
146 logging.error("getXmlPathFormatted(xmlpath=%s, template=%s)"%(xmlpath,template)) | |
147 mdObj = self.getXmlPathObj(xmlpath) | |
148 if mdObj is not None: | |
149 if data is None: | |
150 data = mdObj.getData(path=path, dom=dom, allText=allText, allOccurrences=allOccurrences) | |
151 | |
152 if data is None: | |
153 return '' | |
154 | |
155 fmt = '' | |
156 if allOccurrences: | |
157 # data is list of elements | |
158 for d in data: | |
159 # concatenate formatted strings | |
160 fmt += mdObj.getFormatted(template, path=path, dom=dom, data=d, allFields=allFields) + '\n' | |
161 | |
162 else: | |
163 fmt = mdObj.getFormatted(template, path=path, dom=dom, data=data, allFields=allFields) | |
164 | |
165 return fmt | |
166 | |
167 else: | |
168 logging.error("getXmlPathFormatted: MetaData element at '%s' not found!"%xmlpath) | |
169 return '' | |
170 | |
139 def getResourceData(self, path=None, dom=None): | 171 def getResourceData(self, path=None, dom=None): |
140 """returns contents of resource tag as dict""" | 172 """returns contents of resource tag as dict""" |
141 return self.getXmlPathData('resource', path=path, dom=dom) | 173 return self.getXmlPathData('resource', path=path, dom=dom) |
142 | 174 |
143 def getTexttoolData(self, path=None, dom=None): | 175 def getTexttoolData(self, path=None, dom=None): |
145 return self.getXmlPathData('resource/meta/texttool', path=path, dom=dom) | 177 return self.getXmlPathData('resource/meta/texttool', path=path, dom=dom) |
146 | 178 |
147 def getAccessData(self, path=None, dom=None): | 179 def getAccessData(self, path=None, dom=None): |
148 """returns contents of access tag as dict""" | 180 """returns contents of access tag as dict""" |
149 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 | |
183 def getAttributionData(self, path=None, dom=None, allOccurrences=True): | |
184 """returns contents of attribution tag as dict""" | |
185 return self.getXmlPathData('resource/meta/access-conditions/attribution', path=path, dom=dom, allOccurrences=allOccurrences) | |
186 | |
187 def getAttributionFormatted(self, template, path=None, dom=None, data=None, allOccurrences=True): | |
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) | |
190 | |
191 def getCopyrightData(self, path=None, dom=None, allOccurrences=True): | |
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) | |
194 | |
195 def getCopyrightFormatted(self, template, path=None, dom=None, data=None, allOccurrences=True): | |
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) | |
150 | 198 |
151 def getBibData(self, path=None, dom=None): | 199 def getBibData(self, path=None, dom=None): |
152 """returns contents of bib tag as dict""" | 200 """returns contents of bib tag as dict""" |
153 return self.resource.meta.bib.getData(path=path, dom=dom) | 201 return self.resource.meta.bib.getData(path=path, dom=dom) |
154 | 202 |