annotate MetaData.py @ 0:9f9d9be26e53

first checkin in Mercurial (see history in SVN)
author casties
date Mon, 25 Jul 2011 16:50:48 +0200
parents
children e4bae49e657b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
1 from OFS.Folder import Folder
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
2 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
3 from Globals import package_home
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
4 from AccessControl import ClassSecurityInfo
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
5 import os.path
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
6 import urllib
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
7 import logging
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
8 import urlparse
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
9
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
10 # TODO: which xml toolkit?
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
11 import amara
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
12 import xml.sax.saxutils
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
13 import xml.dom.minidom
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
14 import xml.etree.ElementTree as ET
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
15
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
16
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
17 # TODO: do we need this?
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
18 #from Products.OSA_system2 import OSAS_helpers
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
19 #from Products.OSA_system2.OSAS_metadata import OSAS_Metadata,OSAS_MetadataMapping
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
20
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
21 from OSAS_metadata import OSAS_Metadata, OSAS_MetadataMapping
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
22
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
23
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
24 from SrvTxtUtils import getHttpData, getText
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
25
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
26
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
27 # TODO: get rid of this
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
28 def getTextFromNode(nodelist):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
29 """gibt text aus nodelist"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
30 rc = ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
31 for node in nodelist:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
32 if node.nodeType == node.TEXT_NODE:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
33 rc = rc + node.data
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
34 return rc
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
35
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
36
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
37 def normalizeBibtype(bt):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
38 """returns normalised bib type for looking up mappings"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
39 bt = bt.strip().replace(' ', '-').lower()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
40 return bt
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
41
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
42 def toString(list):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
43 ret=u""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
44
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
45 for l in list:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
46 ret+=unicode(l)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
47
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
48 return ret
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
49
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
50 def dcMetaDataToHash(mdSet):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
51 """Convenience Function for creates a hash from the DCMetadataset
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
52 @param mdSet: String containing DCMetadata informmation
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
53 currently only in the format getDCMetadata of this module"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
54
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
55 NSS = {
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
56 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
57 'dc': 'http://dublincore.org/documents/dcmi-namespace/',
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
58 'owl':"http://www.w3.org/2002/07/owl#",
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
59 'rdfs':"http://www.w3.org/2000/01/rdf-schema#"
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
60 }
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
61 ret={}
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
62 import StringIO
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
63 import sys
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
64 buffer= StringIO.StringIO(mdSet)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
65 try:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
66 md = amara.parse(buffer,prefixes=NSS)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
67 except:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
68 logging.error("Error: %s (%s)"%(sys.exc_info()[0],sys.exc_info()[1]))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
69
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
70 ret["error"]=mdSet
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
71 return ret
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
72
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
73 ret["title"] = toString(md.xml_xpath("//dc:title/text()"))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
74 ret["creator"] =toString(md.xml_xpath("//dc:creator/text()"))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
75 ret["date"] = toString(md.xml_xpath("//dc:date/text()"))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
76
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
77 return ret
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
78
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
79 def getBibdataFromDom(dom):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
80 """returns dict with all elements from bib-tag"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
81 bibinfo = {}
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
82 bib = dom.find(".//meta/bib")
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
83 if bib is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
84 # put type in @type
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
85 type = bib.get('type')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
86 bibinfo['@type'] = normalizedBibtype(type)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
87 # put all subelements in dict
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
88 for e in bib:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
89 bibinfo[e.tag] = getText(e)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
90
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
91 return bibinfo
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
92
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
93
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
94
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
95
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
96 class MetaData(OSAS_Metadata):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
97 """provides basic methods for managing metadata structures"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
98 meta_type='MetaData'
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
99 security=ClassSecurityInfo()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
100 manage_options = Folder.manage_options+(
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
101 {'label':'Main Config','action':'changeMetadataForm'},
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
102 {'label':'Import XML Schema','action':'importMetaDataExportXML'},
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
103 {'label':'Select Fields for Display','action':'indicateDisplayFieldsForm'},
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
104 )
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
105
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
106 def __init__(self,id,shortDescription='',description='',fields=''):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
107 """initialize a new instance"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
108 self.id = id
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
109 self.shortDescription =shortDescription #label fuer link auf add page
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
110 self.description=description #description of the method for link page
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
111 self.fieldList=fields.split(",")[0:]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
112 self.metaDataServerUrl="" # muss mit change metadata gesetzt werden
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
113
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
114
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
115 def correctPath(self,path,remove=None,prefix=None,cut=0):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
116 """convinience method um einen pfad zu veraendern"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
117
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
118 if remove is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
119 path=path.replace(remove,'')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
120 if prefix is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
121 path=os.path.join(prefix,path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
122
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
123 if cut>0:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
124 splitted=path.split("/")
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
125 path="/".join(splitted[0:len(splitted)-cut])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
126 return path
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
127
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
128 def importMetaDataExportXML(self,importFile=None,RESPONSE=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
129 """imports metadata from the metadataexportxml file"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
130
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
131 if importFile is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
132 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','importMetaDataExportXML.zpt')).__of__(self)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
133 return pt()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
134
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
135 dom=xml.dom.minidom.parse(importFile)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
136 self.createMappingFromDom(dom.getElementsByTagName("metadataExport")[0])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
137
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
138 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
139 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
140
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
141
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
142 def createMappingFromDom(self,metadatanode,metadata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
143 """erzeuge ein Mapping aus dem der metadatanode des xmlformats, metadata ist ein metadataobject"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
144
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
145 if metadata is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
146 metadata=self
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
147
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
148 nodes=metadatanode.childNodes
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
149
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
150 #erster schritt: anlegen der fieldlist
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
151 for node in nodes:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
152 logging.debug("node: %s"%node.tagName)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
153 if node.tagName=="set":
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
154 set=node
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
155 if set.getAttribute('name')=='generic':
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
156 list=[]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
157 for entry in set.getElementsByTagName('entry'):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
158 list.append(entry.getAttribute('genericName'))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
159 metadata.fieldList=list[0:]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
160
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
161 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
162 id=set.getAttribute('name').encode('utf-8')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
163 list=[]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
164 argList={}
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
165 for entry in set.getElementsByTagName('entry'):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
166 genericName=entry.getAttribute('genericName')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
167 tag=entry.getAttribute('tag')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
168 label=entry.getAttribute('label')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
169 description=getTextFromNode(entry.childNodes) #TODO: clean
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
170 argList[genericName]=(tag,label,description)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
171 metadata._setObject(id,MetaDataMapping(id,id,argList))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
172
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
173 elif node.tagName=="metadata":
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
174 mn=node
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
175 name=mn.getAttribute('name').encode('utf-8')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
176 metadata._setObject(name,MetaData(name,name))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
177 mdObj=getattr(metadata,name)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
178 mdObj.createMappingFromDom(mn)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
179
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
180
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
181 def getMDFromPathOrUrl(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
182 parsedurl = urlparse.urlparse(path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
183 if parsedurl[0] != "":
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
184 # has schema (e.g. http)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
185 url=path
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
186 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
187 # path only
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
188 if path.endswith("index.meta"):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
189 url =self.metaDataServerUrl%path
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
190 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
191 url=os.path.join(self.metaDataServerUrl%path,'index.meta')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
192
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
193 #logging.debug("get Metadata: %s"%url)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
194 md = getHttpData(url)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
195 return md
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
196
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
197 def getDCFormatted(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
198 """get the metadata as dc set"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
199 logging.debug("getDCFormatted(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
200 namespace={ 'mpiwg': "http://www.mpiwg-berlin.mpg.de/ns/mpiwg"}
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
201 namespaceUsed=False
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
202
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
203 md = self.getMDFromPathOrUrl(path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
204 logging.debug("MD in XML"+md)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
205 im = amara.parse(md, prefixes=namespace)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
206
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
207 typePaths=im.xml_xpath('//bib/@type')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
208 archimedes=False
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
209
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
210 if len(typePaths)<1:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
211 typePaths=im.xml_xpath('//meta/archimedes') # sinderfall fuer veraltete index.meta files vom typ archimedes
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
212 if len(typePaths)>0:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
213 type = "archimedes"
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
214 archimedes=True
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
215 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
216 typePaths=im.xml_xpath('//mpiwg:bib/@type')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
217 if len(typePaths)<1:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
218 return ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
219 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
220 namespaceUsed=True
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
221
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
222 type=unicode(typePaths[0])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
223 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
224 type=unicode(typePaths[0])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
225 logging.info("got type:"+type)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
226 try:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
227 mapping=getattr(self.main.meta.bib,type.lower(),None)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
228 except:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
229 logging.error("getMetaDataFromServer no mapping for type: %s"%type)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
230 return ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
231
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
232 try:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
233 dcMapping=getattr(self.main.meta.bib,"dc",None)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
234 except:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
235 logging.error("getMetaDataFromServer no dc in meta/bib")
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
236 return ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
237
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
238 mds=mapping.generateMappingHash() # Hole das Mapping generisches Feld --> Feld im entsprechenden Typ
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
239 dcMds=dcMapping.generateMappingHash()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
240
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
241 mdHash=[]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
242 logging.debug("Value: %s"%repr(mds))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
243
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
244 for key,valueTriple in mds.items():
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
245 value=valueTriple[0]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
246 logging.debug("Value: %s"%repr(value))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
247 logging.debug("Key: %s"%repr(key))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
248 if value!="":
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
249 if not archimedes:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
250 if namespaceUsed:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
251 try:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
252 v = im.xml_xpath('//mpiwg:bib/mpiwg:%s/text()'%value)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
253 except:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
254 logging.error('cannot do: //mpiwg:bib/mpiwg:%s/text()'%value)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
255 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
256 v = im.xml_xpath('//bib/%s/text()'%value)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
257 else:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
258 v = im.xml_xpath('//archimedes/%s/text()'%value)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
259 if len(v) > 0:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
260 dc=dcMds[key][0]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
261
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
262 if (dc !="") and (value !=""):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
263 logging.debug("%s--> : %s"%(repr(value),dc))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
264 mdHash.append([dc,unicode(v[0])])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
265
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
266 ret="""<bib xmlns:dc="http://dublincore.org/documents/dcmi-namespace/"> """
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
267 ret+="<dc:type>%s</dc:type>"%type
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
268 for md in mdHash:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
269
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
270 ret+="""<dc:%s>%s</dc:%s>"""%(md[0],xml.sax.saxutils.escape(md[1]),md[0])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
271 ret+="</bib>"
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
272 return ret
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
273
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
274
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
275 def getStdMappedHash(self, bibdata):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
276 """returns dict with metadata from bibdata mapped according to standard mapping"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
277 mdHash={}
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
278 bibtype = bibdata['@type']
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
279 # get mapping from main/meta/bib
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
280 try:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
281 mapping=getattr(self.main.meta.bib, bibtype.lower())
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
282 except:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
283 logging.error("getStdMappedHash: no mapping for type: %s"%bibtype)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
284 return mdHash
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
285
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
286 mds = mapping.generateMappingHash() # Hole das Mapping generisches Feld --> Feld im entsprechenden Typ
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
287
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
288 for field in mds.keys():
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
289 # get mapped field name
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
290 mf = mds[field][0]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
291 if not mf:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
292 continue
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
293 logging.debug("mapping: %s = %s"%(field,mf))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
294 mdHash[field] = bibdata.get(mf, '')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
295
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
296 return mdHash
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
297
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
298
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
299 def getFormatted(self, template, path=None, dom=None, bibdata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
300 """returns string with document data formatted according to template.
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
301 gets data from server or dom or pre-parsed bibdata."""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
302 logging.debug("getFormatted(template=%s)"%(template))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
303
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
304 if dom is None and bibdata is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
305 # get from server
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
306 md = self.getMDFromPathOrUrl(path.replace("/mpiwg/online",""))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
307 #logging.debug("md:"+md)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
308 #dom = amara.parse(md)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
309 dom = ET.fromstring(md)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
310
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
311 # get contents of bib tag
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
312 if bibdata is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
313 bibdata = getBibdataFromDom(dom)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
314
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
315 bibtype = bibdata['@type']
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
316
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
317 # get template
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
318 tp=getattr(self,"%s_%s"%(template, bibtype.lower()), None)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
319 if tp is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
320 logging.warning("getFormatted: no template for: %s_%s"%(template, bibtype))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
321 # try generic
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
322 tp=getattr(self,"%s_generic"%(template), None)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
323 if tp is None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
324 logging.error("getFormatted: no generic template either: %s"%(template))
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
325 return ""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
326
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
327 # put mapped data in mdHash
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
328 mdHash = self.getStdMappedHash(bibdata)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
329
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
330 return tp(stdmd=mdHash, md=bibdata)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
331
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
332
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
333 def getFormattedMetaData(self, path=None, dom=None, bibdata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
334 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
335 logging.debug("getFormattedMetaData(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
336 return self.getFormatted('metadata_template', path=path, dom=dom, bibdata=bibdata)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
337
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
338 def getFormattedMetaDataShort(self, path=None, dom=None, bibdata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
339 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
340 logging.debug("getFormattedMetaDataShort(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
341 return self.getFormatted('metadata_template', path=path, dom=dom, bibdata=bibdata)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
342
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
343 def getFormattedMetaDataExtended(self,path=None, dom=None, bibdata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
344 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
345 logging.debug("getFormattedMetaDataExtended(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
346 return self.getFormatted('metadata_extended_template', path=path, dom=dom, bibdata=bibdata)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
347
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
348 def getFormattedLabel(self,path=None, dom=None, bibdata=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
349 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
350 logging.debug("getFormattedLabel(%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
351 return self.getFormatted('label_template', path=path, dom=dom, bibdata=bibdata)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
352
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
353 def getFormattedMetaDataShortFromServer(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
354 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
355 logging.debug("getFormattedMetaDataShortFromServer(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
356 return self.getFormatted('metadata_template', path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
357
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
358 def getFormattedMetaDataExtendedFromServer(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
359 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
360 logging.debug("getFormattedMetaDataExtendedFromServer(path=%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
361 return self.getFormatted('metadata_extended_template', path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
362
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
363 def getFormattedLabelFromServer(self,path):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
364 """get the metadafrom server"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
365 logging.debug("getFormattedLabelFromServer(%s)"%path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
366 return self.getFormatted('label_template', path)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
367
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
368
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
369 security.declarePublic('changeMetadataForm')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
370 def changeMetadataForm(self):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
371 """Main configuration"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
372 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','changeMetadata.zpt')).__of__(self)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
373 return pt()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
374
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
375 security.declarePublic('changeMetadata')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
376 def changeMetadata(self,shortDescription,description,fields,metaDataServerUrl,RESPONSE=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
377 """Change Metadata"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
378 self.shortDescription=shortDescription
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
379 self.description=description
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
380 self.fieldList=fields.split(",")[0:]
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
381 self.metaDataServerUrl=metaDataServerUrl
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
382 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
383 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
384
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
385
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
386 def manage_addMetaDataForm(self):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
387 """interface for adding the OSAS_add_Metadata"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
388 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMetadataForm.zpt')).__of__(self)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
389 return pt()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
390
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
391 def manage_addMetaData(self,id,shortDescription,description,fields,RESPONSE=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
392 """a metadata objekt"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
393 newObj=MetaData(id,shortDescription,description,fields)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
394 self.Destination()._setObject(id,newObj)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
395 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
396 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
397
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
398 class MetaDataMapping(OSAS_MetadataMapping):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
399 meta_type="MetadataMapping"
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
400
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
401 def manage_addMetaDataMappingForm(self):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
402 """interface for adding the OSAS_root"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
403 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','addMetadataMappingForm.zpt')).__of__(self)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
404
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
405 return pt()
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
406
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
407 def manage_addMetaDataMapping(self,idOfObject,titleOfObject,RESPONSE=None):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
408 """add the OSAS_root"""
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
409
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
410 argList={}
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
411 for arg in self.fieldList:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
412 if not (arg in ['idOfObject','titleOfObject']):
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
413 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])
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
414
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
415 newObj=MetaDataMapping(idOfObject,titleOfObject,argList)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
416 self._setObject(idOfObject,newObj)
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
417 if RESPONSE is not None:
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
418 RESPONSE.redirect('manage_main')
9f9d9be26e53 first checkin in Mercurial (see history in SVN)
casties
parents:
diff changeset
419