0
|
1 """ Classes for managing metadata"""
|
|
2
|
|
3 from OFS.SimpleItem import SimpleItem
|
|
4 from Globals import InitializeClass,package_home
|
|
5 from OFS.Folder import Folder
|
|
6 from AccessControl import ClassSecurityInfo
|
|
7 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
|
|
8 import os.path
|
|
9 import sys
|
|
10 import xml.dom.minidom
|
|
11 import xml.dom.pulldom
|
|
12 #TODO: get rid of this
|
|
13 from Products.OSA_system2 import OSAS_helpers
|
|
14 import logging
|
|
15
|
|
16 #ersetzt logging
|
|
17 def logger(txt,method,txt2):
|
|
18 """logging"""
|
|
19 logging.info(txt+ txt2)
|
|
20
|
|
21
|
|
22 import string
|
|
23 try:
|
|
24 from xml.xpath import Evaluate
|
|
25 except:
|
|
26 from Ft.Xml.XPath import Evaluate
|
|
27 import xmlrpclib
|
|
28
|
|
29 from types import *
|
|
30
|
|
31 class OSAS_MetadataMapping(SimpleItem):
|
|
32 """Einfaches Mapping Object"""
|
|
33
|
|
34 meta_type="OSAS_MetadataMapping__neu"
|
|
35
|
|
36 def readFieldsFromParent(self):
|
|
37 """read all elements from root"""
|
|
38
|
|
39 return self.aq_parent.fieldList
|
|
40
|
|
41 def __init__(self,id,title,arglist):
|
|
42 """init
|
|
43 @param id: id
|
|
44 @param title: title fuer zope navigation
|
|
45 @param arglist: dictionary mit Namen der zugelassenen generische Metadaten als key und Tripel als Werte (human readable, tag version,explanation
|
|
46 """
|
|
47 self.id=id
|
|
48 self.title=title
|
|
49 for fieldName in arglist.keys():
|
|
50 setattr(self,"md_"+fieldName,arglist[fieldName])
|
|
51
|
|
52
|
|
53 manage_options = SimpleItem.manage_options+(
|
|
54 {'label':'Main Config','action':'changeMetadataMappingForm'},
|
|
55 )
|
|
56
|
|
57
|
|
58 def showSetXML(self,RESPONSE=None):
|
|
59 """prints out the mapping as XML"""
|
|
60 ret="""<set name="%s">"""%self.title
|
|
61 for fieldName in self.readFieldsFromParent():
|
|
62 entry=getattr(self,"md_"+fieldName)
|
|
63 if entry[2]=="": # no explanation of this field
|
|
64 ret+="""<entry genericName="%s" tag="%s" label="%s"/>"""%(fieldName,entry[0],entry[1])
|
|
65 else:
|
|
66 ret+="""<entry genericName="%s" tag="%s" label="%s">%s</entry>"""%(fieldName,entry[0],entry[1],entry[2])
|
|
67 ret+="</set>"
|
|
68
|
|
69 if not RESPONSE:
|
|
70 return ret
|
|
71 else:
|
|
72 self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
|
|
73 return ret
|
|
74
|
|
75 def getValue(self,fieldName):
|
|
76 """get md value
|
|
77 @param fieldName: Bezeichnung des gesuchten Metadatums
|
|
78 @retunr: Value des Metadatums"""
|
|
79
|
|
80 ret= getattr(self,"md_"+fieldName,(None,None,None,None,None))
|
|
81 if len(ret)!= 4: # alte MD haben keine info ueber optional/required und listen werte
|
|
82 ret=ret+("","")
|
|
83 return ret
|
|
84
|
|
85
|
|
86 def isEmptyValue(self,fieldName):
|
|
87 """teste ob fielname in diesem Metadatenschema definiert ist"""
|
|
88 field=getattr(self,"md_"+fieldName,'')
|
|
89 if field[1]=='':
|
|
90 return 0
|
|
91 else:
|
|
92 return 1
|
|
93
|
|
94 def generateMappingHash(self):
|
|
95 """erzeugen des dictionaries: generisches Feld -> Definition in diesem Schema"""
|
|
96 hash={}
|
|
97 for field in self.fieldList:
|
|
98 hash[field]=getattr(self,"md_"+field,'')
|
|
99 return hash
|
|
100
|
|
101
|
|
102
|
|
103 def changeMetadataMappingForm(self):
|
|
104 """change"""
|
|
105 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMetadataMapping.zpt')).__of__(self)
|
|
106 return pt()
|
|
107
|
|
108 def changeMetadataMapping(self,titleOfObject,RESPONSE=None):
|
|
109 """change"""
|
|
110
|
|
111 self.title=titleOfObject
|
|
112 arglist=self.REQUEST.form
|
|
113
|
|
114 for fieldName in self.readFieldsFromParent():
|
|
115 setattr(self,"md_"+fieldName,(arglist[fieldName],arglist['label_'+fieldName],arglist['explanation_'+fieldName],arglist['status_'+fieldName],arglist['values_'+fieldName]))
|
|
116
|
|
117
|
|
118 if RESPONSE is not None:
|
|
119 RESPONSE.redirect('manage_main')
|
|
120
|
|
121 manage_workspace=changeMetadataMappingForm
|
|
122
|
|
123 def manage_addMetadataMappingForm(self):
|
|
124 """interface for adding the OSAS_root"""
|
|
125 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMetadataMappingForm.zpt')).__of__(self)
|
|
126
|
|
127 return pt()
|
|
128
|
|
129 def manage_addMetadataMapping(self,idOfObject,titleOfObject,RESPONSE=None):
|
|
130 """add the OSAS_root"""
|
|
131
|
|
132 argList={}
|
|
133 for arg in self.fieldList:
|
|
134 if not (arg in ['idOfObject','titleOfObject']):
|
|
135 argList[arg]=(self.REQUEST.form[arg],self.REQUEST.form['label_'+arg],self.REQUEST.form['explanation_'+arg],self.REQUEST.form['status_'+arg],self.REQUEST.form['values_'+arg])
|
|
136
|
|
137 newObj=OSAS_MetadataMapping(idOfObject,titleOfObject,argList)
|
|
138 self._setObject(idOfObject,newObj)
|
|
139 if RESPONSE is not None:
|
|
140 RESPONSE.redirect('manage_main')
|
|
141
|
|
142
|
|
143
|
|
144 class OSAS_Metadata(Folder):
|
|
145 """Foldertype enthaelt methoden zur Halbautomatischen Erstellung von Metadatenfiles"""
|
|
146 security=ClassSecurityInfo()
|
|
147
|
|
148 def __init__(self,id,shortDescription,description,fields):
|
|
149 """initialize a new instance"""
|
|
150 self.id = id
|
|
151 self.shortDescription =shortDescription #label fuer link auf add page
|
|
152 self.description=description #description of the method for link page
|
|
153 self.fieldList=fields.split(",")[0:]
|
|
154
|
|
155 meta_type='OSAS_Metadata__neu'
|
|
156
|
|
157 manage_options = Folder.manage_options+(
|
|
158 {'label':'Main Config','action':'changeMetadataForm'},
|
|
159 {'label':'Import XML Schema','action':'importXMLSchemaForm'},
|
|
160 {'label':'Select Fields for Display','action':'indicateDisplayFieldsForm'},
|
|
161 )
|
|
162
|
|
163 def showGenericXML(self,RESPONSE=None):
|
|
164 """show generic fields as XML"""
|
|
165 ret="""<set name="%s">"""%"generic"
|
|
166 for field in self.fieldList:
|
|
167 ret+="""<entry genericName="%s"/>"""%field
|
|
168
|
|
169 ret+="</set>"
|
|
170
|
|
171 if not RESPONSE:
|
|
172 return ret
|
|
173 else:
|
|
174 self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
|
|
175 return ret
|
|
176
|
|
177
|
|
178 def showOverviewXML(self,RESPONSE=None,wrapped=False):
|
|
179 """gives an overview over the Metadata stored in this folder"""
|
|
180 ret=""
|
|
181 if wrapped:
|
|
182 ret+="""<metadataExport>"""
|
|
183 ret+="""<metadata name="%s">"""%self.getId()
|
|
184 ret+=self.showGenericXML()
|
|
185 for entry in self.ZopeFind(self,obj_metatypes=['OSAS_MetadataMapping__neu']):
|
|
186 ret+=entry[1].showSetXML()
|
|
187
|
|
188 for entry in self.ZopeFind(self,obj_metatypes=['OSAS_Metadata__neu']):
|
|
189 ret+=entry[1].showOverviewXML()
|
|
190
|
|
191 ret+="</metadata>"
|
|
192
|
|
193 if wrapped:
|
|
194 ret+="""</metadataExport>"""
|
|
195 if not RESPONSE:
|
|
196 return ret
|
|
197 else:
|
|
198 RESPONSE.setHeader('Content-Type','text/xml')
|
|
199 return ret
|
|
200
|
|
201 def generateMappingList(self):
|
|
202 """Erzeuge Mapping"""
|
|
203 mapping={}
|
|
204
|
|
205 for dict in self.__dict__:
|
|
206 #print dict
|
|
207 obj=getattr(self,dict)
|
|
208 if hasattr(obj,'meta_type'):
|
|
209 logging.debug("generateMappungList read type:"+repr(obj.meta_type))
|
|
210 if ((obj.meta_type=="OSAS_MetadataMapping__neu") or (obj.meta_type=="MetadataMapping")): #metadatamapping is the newer type
|
|
211 logging.debug("generateMappungListadded:"+repr(obj.getId()))
|
|
212 mapping[obj.getId()]=obj.generateMappingHash()
|
|
213
|
|
214 return mapping
|
|
215
|
|
216 def generateMappingForType(self,type,clean="yes"):
|
|
217 """erzeuge spezifisches Mapping"""
|
|
218
|
|
219 hash=self.generateMappingList()
|
|
220 logging.debug("generateMappingForType:"+type)
|
|
221 for key in hash.keys():
|
|
222 logging.debug("generateMappingForType comparing:"+key.lower()+type.lower())
|
|
223 if (key.lower() == type.lower()):
|
|
224 if clean=="yes":
|
|
225 temp={}
|
|
226 for x in hash[key].keys():
|
|
227 if not hash[key][x]=="":
|
|
228 temp[x]=hash[key][x]
|
|
229 return temp
|
|
230 else:
|
|
231
|
|
232 return hash[key]
|
|
233
|
|
234 return {}
|
|
235
|
|
236 def getFieldList(self):
|
|
237 """erzeuge string aus fields"""
|
|
238 try:
|
|
239 return string.join(self.fieldList,",")
|
|
240 except:
|
|
241 return ""
|
|
242
|
|
243 security.declarePublic('getFields')
|
|
244 def getFields(self):
|
|
245 """ausgabe der Felder"""
|
|
246 return self.fieldList
|
|
247
|
|
248 def getTypeTitle(self,id):
|
|
249 """Title von ID"""
|
|
250 try:
|
|
251 obj=getattr(self,id)
|
|
252 return obj.title
|
|
253 except:
|
|
254 return id
|
|
255
|
|
256 def getType(self,type):
|
|
257 """gib metadataobject type zurueck"""
|
|
258
|
|
259 for obj in self.ZopeFind(self,obj_metatypes=['OSAS_MetadataMapping__neu']):
|
|
260 if obj[0]==type:
|
|
261 return obj
|
|
262 return (self.id,self)
|
|
263
|
|
264
|
|
265
|
|
266 def getStoredTypes(self):
|
|
267 """Gebe gespeicherte typen zurueck"""
|
|
268
|
|
269 types=[]
|
|
270
|
|
271 for obj in self.ZopeFind(self,obj_metatypes=['OSAS_MetadataMapping__neu']):
|
|
272 if obj[1].title=="":
|
|
273 title=obj[1].id
|
|
274 else:
|
|
275 title=obj[1].title
|
|
276 types.append((obj[1].id, title, obj[1]))
|
|
277
|
|
278 return types
|
|
279
|
|
280 def indicateDisplayFieldsForm(self):
|
|
281 """form zur Makierung der Felder die in der Browserumgebung angezeigt werden"""
|
|
282 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','indicateDisplayFieldsForm.zpt')).__of__(self)
|
|
283 return pt()
|
|
284
|
|
285 def indicateDisplayFields(self,displayFields,RESPONSE=None):
|
|
286 """set Displayfields
|
|
287 @param displayFields: Liste von Felder die im Browserenvironment angezeigt werden
|
|
288 """
|
|
289 self.displayFields=OSAS_helpers.toList(displayFields)
|
|
290 if RESPONSE is not None:
|
|
291 RESPONSE.redirect('manage_main')
|
|
292
|
|
293 def getDisplayFieldsAsStr(self,indexMeta):
|
|
294 ret=[]
|
|
295 try:
|
|
296 if indexMeta and not (indexMeta==""):
|
|
297 dom=xml.dom.pulldom.parseString(indexMeta)
|
|
298
|
|
299 for (event,node) in dom:
|
|
300
|
|
301 if event == xml.dom.pulldom.START_ELEMENT and node.tagName=="bib":
|
|
302 dom.expandNode(node)
|
|
303
|
|
304 try:
|
|
305 type=node.getAttribute('type')
|
|
306 mapping=getattr(self,type).generateMappingHash()
|
|
307 except:
|
|
308 type='generic'
|
|
309 mapping=getattr(self,type).generateMappingHash()
|
|
310
|
|
311 for field in self.displayFields:
|
|
312 try:
|
|
313 ret.append(OSAS_helpers.getText(node.getElementsByTagName(mapping[field][0])[0].childNodes))
|
|
314 except:
|
|
315 """nothing"""
|
|
316
|
|
317 return "; ".join(ret)
|
|
318 else:
|
|
319 return ""
|
|
320 except:
|
|
321 return ""
|
|
322 def getDisplayFieldsAsStrOLD(self,indexMeta):
|
|
323 """Gebe display fields als string zurueck
|
|
324 @param path: Pfad zum Object
|
|
325 """
|
|
326 ret=[]
|
|
327 try:
|
|
328 dom=xml.dom.minidom.parseString(indexMeta)
|
|
329 except:
|
|
330 logger("OSAS_metadata (getDisplayFieldsAsStr)",logging.INFO,"Cannot parse: %s"%indexMeta)
|
|
331 try:
|
|
332 bib = dom.getElementsByTagName("meta")[0].getElementsByTagName("bib")[0]
|
|
333 except:
|
|
334 return ""
|
|
335 try:
|
|
336 type=bib.getAttribute('type')
|
|
337 mapping=getattr(self,type).generateMappingHash()
|
|
338 except:
|
|
339 type='generic'
|
|
340 mapping=getattr(self,type).generateMappingHash()
|
|
341
|
|
342 for field in self.displayFields:
|
|
343 try:
|
|
344 ret.append(OSAS_helpers.getText(bib.getElementsByTagName(mapping[field][0])[0].childNodes))
|
|
345 except:
|
|
346 """nothing"""
|
|
347
|
|
348 return "; ".join(ret)
|
|
349
|
|
350 security.declarePublic('changeMetadataForm')
|
|
351 def changeMetadataForm(self):
|
|
352 """Main configuration"""
|
|
353 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMetadata.zpt')).__of__(self)
|
|
354 return pt()
|
|
355
|
|
356 security.declarePublic('changeMetadata')
|
|
357 def changeMetadata(self,shortDescription,description,fields,RESPONSE=None):
|
|
358 """Change Metadata"""
|
|
359 self.shortDescription=shortDescription
|
|
360 self.description=description
|
|
361 self.fieldList=fields.split(",")[0:]
|
|
362 if RESPONSE is not None:
|
|
363 RESPONSE.redirect('manage_main')
|
|
364
|
|
365 security.declarePublic('index_html')
|
|
366
|
|
367 def importXMLSchemaForm(self):
|
|
368 """form"""
|
|
369 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','importXMLSchemaForm.zpt')).__of__(self)
|
|
370 return pt()
|
|
371
|
|
372
|
|
373 def importXMLSchema(self,file,RESPONSE=None):
|
|
374 """import xmlschema, Metadatenschema wird eingelesen und entsprechende Metadatenmappings angelegt."""
|
|
375
|
|
376 dom=xml.dom.minidom.parse(file)
|
|
377 sets=dom.getElementsByTagName('set')
|
|
378 #erster schritt: anlegen der fieldlist
|
|
379 for set in sets:
|
|
380 if set.getAttribute('name')=='generic':
|
|
381 list=[]
|
|
382 for entry in set.getElementsByTagName('entry'):
|
|
383 list.append(entry.getAttribute('genericName'))
|
|
384 self.fieldList=list[0:]
|
|
385
|
|
386 #zweiter schritt: anlegen der mapping
|
|
387 for set in sets:
|
|
388 id=set.getAttribute('name').encode('utf-8')
|
|
389 list=[]
|
|
390 argList={}
|
|
391 for entry in set.getElementsByTagName('entry'):
|
|
392 genericName=entry.getAttribute('genericName')
|
|
393 tag=entry.getAttribute('tag')
|
|
394 label=entry.getAttribute('label')
|
|
395 description=OSAS_helpers.getText(entry.childNodes)
|
|
396 argList[genericName]=(tag,label,description)
|
|
397 self._setObject(id,OSAS_MetadataMapping(id,id,argList))
|
|
398 if RESPONSE:
|
|
399 RESPONSE.write("Wrote: %s"%id)
|
|
400
|
|
401
|
|
402 def createMetadataFragment(self,type,path,prefix="",presets={}):
|
|
403 """fragment"""
|
|
404 self.REQUEST.SESSION['MDF_type']=type
|
|
405 self.REQUEST.SESSION['MDF_path']=path
|
|
406 self.REQUEST.SESSION['MDF_prefix']=prefix
|
|
407 self.REQUEST.SESSION['MDF_presets']=presets
|
|
408
|
|
409 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMetadataForm_fragment.zpt')).__of__(self)
|
|
410 return pt()
|
|
411
|
|
412 def createMetadataForm(self,type="",path=""):
|
|
413 """createMetadataForm"""
|
|
414 self.REQUEST.SESSION['MDF_type']=type
|
|
415 self.REQUEST.SESSION['MDF_path']=path
|
|
416
|
|
417
|
|
418 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMetadataForm_template.zpt')).__of__(self)
|
|
419 return pt()
|
|
420
|
|
421 def readMetadata(self,MDF_path,MDF_type,MDF_prefix="",MDF_xpathStart="", MDF_addPath=None,MDF_identifyFields=None,newdoc=None,actualNode=None):
|
|
422
|
|
423 if type(MDF_path)==ListType:
|
|
424 MDF_path=MDF_path[0]
|
|
425
|
|
426 indexFile=os.path.join(MDF_path,'index.meta')
|
|
427
|
|
428 server=xmlrpclib.Server(self.serverUrl)
|
|
429
|
|
430 documentStr=server.getFile(indexFile)
|
|
431
|
|
432 if documentStr:
|
|
433 newdoc=xml.dom.minidom.parseString(documentStr)
|
|
434 dom=newdoc.documentElement
|
|
435 actualNode=dom
|
|
436 else:
|
|
437 return {}
|
|
438
|
|
439 if self.containerTag=="":
|
|
440 containerTag="doc"
|
|
441 else:
|
|
442 containerTag=self.containerTag
|
|
443
|
|
444 if MDF_xpathStart=="":
|
|
445 dom=newdoc.documentElement
|
|
446 actualNode=dom
|
|
447 else:
|
|
448 #try to find xpath
|
|
449 if MDF_identifyFields:
|
|
450 query=[]
|
|
451 for field in MDF_identifyFields.keys():
|
|
452
|
|
453 query.append("""(%s="%s")"""%(field,MDF_identifyFields[field]))
|
|
454 querystr=" and ".join(query)
|
|
455 xpathStr=MDF_xpathStart+"[%s]"%querystr
|
|
456
|
|
457 else:
|
|
458 xpathStr=MDF_xpathStart
|
|
459
|
|
460
|
|
461 xpathNodes=Evaluate(xpathStr,actualNode)
|
|
462
|
|
463
|
|
464 if len(xpathNodes)>0:
|
|
465 actualNode=xpathNodes[0]
|
|
466 else:
|
|
467 return {}
|
|
468
|
|
469 ret={}
|
|
470 for node in actualNode.childNodes:
|
|
471 name=node.tagName
|
|
472 text=OSAS_helpers.getText(node.childNodes)
|
|
473 ret[name]=text
|
|
474
|
|
475 return ret
|
|
476
|
|
477 def writeMetadata(self,MDF_path,MDF_type,form,MDF_prefix="",MDF_xpathStart="", MDF_addPath=None,MDF_identifyFields=None,newdoc=None,actualNode=None):
|
|
478 """writeMetadata"""
|
|
479 #MDF_path="/tmp/index.meta"
|
|
480 if type(MDF_path)==ListType:
|
|
481 MDF_path=MDF_path[0]
|
|
482
|
|
483
|
|
484 indexFile=os.path.join(MDF_path,'index.meta')
|
|
485
|
|
486 server=xmlrpclib.Server(self.serverUrl)
|
|
487 if newdoc:
|
|
488 if not actualNode: actualNode=newdoc
|
|
489 dom=newdoc
|
|
490 else:
|
|
491 documentStr=server.getFile(indexFile)
|
|
492
|
|
493 if documentStr:
|
|
494
|
|
495 newdoc=xml.dom.minidom.parseString(documentStr)
|
|
496 dom=newdoc.documentElement
|
|
497 actualNode=dom
|
|
498
|
|
499
|
|
500 else:
|
|
501
|
|
502 impl=xml.dom.minidom.getDOMImplementation()
|
|
503 newdoc=None
|
|
504
|
|
505
|
|
506 if self.containerTag=="":
|
|
507 containerTag="doc"
|
|
508 else:
|
|
509 containerTag=self.containerTag
|
|
510
|
|
511 create=None
|
|
512 if MDF_xpathStart=="":
|
|
513 if not newdoc:
|
|
514 newdoc=impl.createDocument(None,containerTag,None)
|
|
515 dom=newdoc.documentElement
|
|
516 actualNode=dom
|
|
517 else:
|
|
518
|
|
519 #try to find xpath
|
|
520 if MDF_identifyFields:
|
|
521 query=[]
|
|
522 for field in MDF_identifyFields:
|
|
523
|
|
524 query.append("""(%s="%s")"""%(field,form[MDF_prefix+"MD_"+field]))
|
|
525 querystr=" and ".join(query)
|
|
526 xpathStr=MDF_xpathStart+"[%s]"%querystr
|
|
527
|
|
528 else:
|
|
529 xpathStr=MDF_xpathStart
|
|
530
|
|
531
|
|
532 xpathNodes=Evaluate(xpathStr,actualNode)
|
|
533
|
|
534
|
|
535
|
|
536
|
|
537 if len(xpathNodes)>0:
|
|
538 actualNode=xpathNodes[0]
|
|
539
|
|
540 else:
|
|
541 #existiert nicht dann neue erzeugen
|
|
542
|
|
543 if len(Evaluate(MDF_xpathStart,dom))>0:
|
|
544
|
|
545 create=True
|
|
546
|
|
547 splitted=MDF_xpathStart.split("/")
|
|
548 base=""
|
|
549 for element in splitted:
|
|
550
|
|
551 if not (element=="") and not (element==containerTag):
|
|
552 base="/".join([base,element])
|
|
553
|
|
554 if not newdoc:
|
|
555 newdoc=impl.createDocument(None,element,None)
|
|
556 actualNode=newdoc.documentElement
|
|
557 dom=actualNode
|
|
558 else:
|
|
559 changed=None
|
|
560
|
|
561 if not (MDF_addPath==base):
|
|
562
|
|
563
|
|
564 for childNode in actualNode.childNodes:
|
|
565 if getattr(childNode,'tagName','')==element:
|
|
566 actualNode=childNode
|
|
567 changed=1
|
|
568
|
|
569 if (os.path.normpath("/".join(["",containerTag,base]))==MDF_xpathStart) and create:
|
|
570 actualNode=actualNode.parentNode
|
|
571 changed=None
|
|
572
|
|
573 if not changed:
|
|
574 namenode=newdoc.createElement(element)
|
|
575
|
|
576 actualNode.appendChild(namenode)
|
|
577 actualNode=namenode
|
|
578
|
|
579
|
|
580
|
|
581
|
|
582 for name in self.REQUEST.form.keys():
|
|
583 length=len(MDF_prefix)
|
|
584 if MDF_type and not (MDF_type == ""):
|
|
585 actualNode.setAttribute("type",MDF_type)
|
|
586 if name[0:3+length]==MDF_prefix+"MD_":
|
|
587 tagName=name[3+length:]
|
|
588
|
|
589 #CHECK if element exists
|
|
590 for childNode in actualNode.childNodes:
|
|
591 if getattr(childNode,'tagName','')==tagName:
|
|
592 actualNode.removeChild(childNode).unlink()
|
|
593
|
|
594 namenode=newdoc.createElement(tagName)
|
|
595 namenodetext=newdoc.createTextNode(self.REQUEST.form[name])
|
|
596 namenode.appendChild(namenodetext)
|
|
597 actualNode.appendChild(namenode)
|
|
598
|
|
599 ret=newdoc.toxml(encoding='utf-8')
|
|
600 zLOG.LOG("OSAS_metadata (writeMetadata)",zLOG.INFO,"write: %s"%ret)
|
|
601
|
|
602
|
|
603 server.writeMetaDataFile(indexFile,ret)
|
|
604
|
|
605
|
|
606 return newdoc,actualNode
|
|
607
|
|
608 def writeMetadataFile(self,MDF_path,MDF_type,MDF_xpathStart="",newdoc=None,actualNode=None):
|
|
609 """writeMetaFile"""
|
|
610
|
|
611 return self.writeMetadata(MDF_path,MDF_type,self.REQUEST.form,MDF_xpathStart=MDF_xpathStart,newdoc=newdoc,actualNode=actualNode)
|
|
612
|
|
613
|
|
614 def isEmptyValue(self,fieldName):
|
|
615 """im generischen fall stets falsch"""
|
|
616 return 1
|
|
617
|
|
618 def getValue(self,fieldName):
|
|
619 """im generischen fall gleich fieldname"""
|
|
620 return fieldName,fieldName,"","",""
|
|
621
|
|
622 def getList(self,list):
|
|
623 """return list"""
|
|
624
|
|
625 if list=="":
|
|
626 return None
|
|
627 listsplit=[i.rstrip() for i in list.split("\n")]
|
|
628 return listsplit
|
|
629
|
|
630 def showHelp(self,refType,genericTag):
|
|
631 """helptext"""
|
|
632 for reference in self.ZopeFind(self):
|
|
633 if reference[1].title==refType:
|
|
634 text=getattr(reference[1],'md_'+genericTag)[2]
|
|
635 return text
|
|
636 return "NO EXPLANATION"
|
|
637
|
|
638 def showHelpTag(self,url,reftype,item):
|
|
639 """gen javascript for showhelp"""
|
|
640 url2=url+'/showHelp?refType=%s&genericTag=%s'%(reftype,item)
|
|
641 ret="""javascript:wd=window.open(\'%s\',\'Help\',\'width=300,height=250\');void(\'\');wd.focus();"""%url2
|
|
642 return ret
|
|
643
|
|
644
|
|
645 def manage_addMetadataForm(self):
|
|
646 """interface for adding the OSAS_add_Metadata"""
|
|
647 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMetadataForm.zpt')).__of__(self)
|
|
648 return pt()
|
|
649
|
|
650 def manage_addMetadata(self,id,shortDescription,description,fields,RESPONSE=None):
|
|
651 """add the OSAS_root"""
|
|
652 newObj=OSAS_Metadata(id,shortDescription,description,fields)
|
|
653 self.Destination()._setObject(id,newObj)
|
|
654 if RESPONSE is not None:
|
|
655 RESPONSE.redirect('manage_main')
|
|
656
|
|
657
|
|
658
|