コード例 #1
0
ファイル: citation.py プロジェクト: ostwald/python-lib
	def populate (self):
		for field in required_fields:
			if field == 'authors':
				continue
			self.addChild (field, self.data[field])
			
		# process authors
		authorsElement = self.addElement (self.doc, "authors")
		for author in self.data['authors']:
			authorElement = self.addElement (authorsElement, "author")
			
			## attributes
			if author.authororder:
				authorElement.setAttribute ("author_order", str(author.authororder))
			if author.person_id:
				authorElement.setAttribute ("person_id", str(author.person_id))
			if author.upid:
				authorElement.setAttribute ("upid", str(author.upid))
				
			# self.setText (authorElement, author)
			for attr in ['lastName', 'firstName', 'middleName', 'suffix']:
				if getattr (author, attr):
					XmlUtils.addChild (self.dom, attr, getattr (author, attr), authorElement)
				
		for field in other_fields:
			if field in self.data.keys():
				self.addChild (field, self.data[field])
コード例 #2
0
 def addFieldsFiles(self):
     filesElement = self.rec.selectSingleNode(self.rec.doc, "files")
     if not filesElement:
         raise Exception, "Files element not found"
     for fieldsFile in self.getFieldsFileNames():
         text = "/".join(
             [self.xmlFormat, self.version, "fields", fieldsFile])
         XmlUtils.addChild(self.rec.dom, "file", text, filesElement)
コード例 #3
0
ファイル: WebCatComposite.py プロジェクト: ostwald/python-lib
    def finalizeXml(self):
        if not self.node:
            return
        childrenElement = XmlUtils.addElement(self.dom, self.doc, "children")
        for child in self.node.children:
            XmlUtils.addChild(self.dom, "child", child.title, childrenElement)

        children = XmlUtils.getChildElements(self.doc)
        self.doc.appendChild(childrenElement)
コード例 #4
0
ファイル: WebCatMetadata.py プロジェクト: ostwald/python-lib
	def populateXml (self, xmlData):
		dataRec = XmlRecord (xml=xmlData)
		dataElements = dataRec.getElements (dataRec.doc)
		for dataElement in dataElements:
			cells = XmlUtils.getChildElements (dataElement, "TD")
			name = XmlUtils.getText (cells[0]).strip()
			if name[-1] == ":": name = name[:-1]
			value = XmlUtils.getText (XmlUtils.getChild ("B", cells[1])).strip()
			
			XmlUtils.addChild (self.dom, self.normalizeTagName(name), value)
コード例 #5
0
 def addViewContext(self, vc):
     vcParent = self.selectSingleNode(self.dom,
                                      'record:collection:viewContexts')
     vcNodes = XmlUtils.getChildElements(vcParent)
     print '%d vc nodes found' % len(vcNodes)
     vcValues = map(lambda x: XmlUtils.getText(x), vcNodes)
     for val in vcValues:
         print '-', val
     if not vc in vcValues:
         XmlUtils.addChild(self.dom, 'viewContext', vc, vcParent)
コード例 #6
0
 def makeRecord(self):
     rec = XmlRecord(xml=self.record_template)
     XmlUtils.addChild(rec.dom, "date", asctime(localtime()))
     XmlUtils.addChild(rec.dom, "recordSource", self.record_source)
     collections = XmlUtils.addElement(rec.dom, rec.doc, "collections")
     for key in self.keys():
         collection = XmlUtils.addElement(rec.dom, collections,
                                          "collection")
         collection.setAttribute("key", key)
         collection.setAttribute("prefix", self[key].getIdPrefix())
     return rec
コード例 #7
0
 def asElement(self):
     doc = XmlUtils.createDocument("docInfo")
     root = doc.documentElement
     root.setAttribute("path", self.path)
     for attr in self.attrs:
         val = getattr(self, attr) or ""
         # print "%s: %s" % (attr, val)
         XmlUtils.addChild(doc, attr, val)
     element = doc.removeChild(root)
     doc.unlink()
     return element
コード例 #8
0
    def finalizeXml(self):
        """
		doctor the metadata with information contained in the folderNode
		"""
        if not self.node:
            return

        # get TN issue from title, or if not from parent's title
        self.tn_issue = self.getTN() or self.tn_issue
        if self.tn_issue:
            print "ADDING %s" % self.tn_issue
            tnElement = XmlUtils.addElement(self.dom, self.doc, "tn_isssue")
            XmlUtils.setText(tnElement, self.tn_issue)
            self.title = webcatUtils.stripIssue(self.title, self.tn_issue)
            self.setFieldValue("title", self.title)

        childrenElement = XmlUtils.addElement(self.dom, self.doc, "children")
        for child in self.node.children:
            # XmlUtils.addChild  (self.dom, "child", child.title, childrenElement)

            md = child.getMetadata(None)
            id = md.getAccessionNum()
            print id
            childElement = XmlUtils.addChild(self.dom, "child", child.title,
                                             childrenElement)
            childElement.setAttribute("accessionNum", id)
        children = XmlUtils.getChildElements(self.doc)
        self.doc.appendChild(childrenElement)
コード例 #9
0
	def getStandardElement (self, key):
		node = self.nodeMap[key]
		nodeEl = self.dom.createElement ("Standard")
		XmlUtils.addChild (self.dom, "id", node.id, nodeEl)
		XmlUtils.addChild (self.dom, "itemText", node.getItemText(), nodeEl)
		XmlUtils.addChild (self.dom, "parent", node.parent, nodeEl)
		childrenEl = self.addElement (nodeEl, "children")
		for childKey in node.children:
			XmlUtils.addChild (self.dom, "child", self.getNodeId(childKey), childrenEl)
		return nodeEl
コード例 #10
0
ファイル: osmConverter.py プロジェクト: ostwald/python-lib
def convert(path, useTestSchema=True):

    rec = OsmRecord(path=path)
    changed = 0

    if useTestSchema:
        rec.setSchemaLocation(
            'http://test.nldr.library.ucar.edu/metadata/osm/1.1/schemas/osm.xsd',
            'http://nldr.library.ucar.edu/metadata/osm')

    for contrib in rec.getContributorPeople() + rec.getContributorOrgs():
        # print "\nBEFORE\n",contrib.element.toxml()
        for level in contrib.affiliationLevels:
            suffix = contrib.getSuffix(level)
            if contrib.hasAffiliationLevel(level):
                changed = 1
                affiliation = XmlUtils.addElement(rec.dom, contrib.element,
                                                  'affiliation')
                for baseFieldName in contrib.affiliationFields:
                    field = baseFieldName + suffix
                    child2delete = contrib.element.getElementsByTagName(field)
                    if child2delete:
                        for e in child2delete:
                            contrib.element.removeChild(e)
                    value = getattr(contrib, field)
                    # print "value: '%s' (%s)" % (value, type(value))
                    if value:
                        if type(value) != type([]):
                            value = [value]
                        for item in value:
                            try:
                                XmlUtils.addChild(rec.dom, baseFieldName, item,
                                                  affiliation)
                            except TypeError:
                                print "\nCouldn't insert %s in %s: %s" % (
                                    item, baseFieldName, sys.exc_info()[1])
                                sys.exit()
        # print "\nAFTER\n",prettyElement(contrib.element)

    return rec
コード例 #11
0
ファイル: ucar_orgs.py プロジェクト: ostwald/python-lib
    def asXml(self):
        rec = XmlRecord(xml="<orgchart/>")
        root = rec.doc
        for org in self.values():
            orgNode = rec.addElement(root, "node")
            orgNode.setAttribute("id", str(org.id))
            # print "children: %s" % org.children
            children = XmlUtils.addElement(rec.dom, orgNode, "children")
            for child in org.children:
                # print "child: ", child
                XmlUtils.addChild(rec.dom, "child", str(child), children)
            XmlUtils.addChild(rec.dom, "parent", str(org.parent), orgNode)
            for attr in ['acronym', 'full_name', 'active', 'org_level_id']:
                val = getattr(org.orgRec, attr)
                XmlUtils.addChild(rec.dom, attr, str(val), orgNode)

        # print root.toxml()
        return rec
コード例 #12
0
ファイル: AdnRecord.py プロジェクト: ostwald/python-lib
 def add_keyword(self, keyword):
     keywords_element = self.keywords_element()
     el = XmlUtils.addChild(self.dom, "keyword", keyword, keywords_element)
コード例 #13
0
	def getDocElement (self):
		docEl = self.dom.createElement ("Document")
		XmlUtils.addChild (self.dom, "version", "0.0.1", docEl)
		XmlUtils.addChild (self.dom, "topic", "all", docEl)
		XmlUtils.addChild (self.dom, "author", "WGBH-Teachers Domain", docEl)
		XmlUtils.addChild (self.dom, "title", "Teachers Domain Lexicon", docEl)
		XmlUtils.addChild (self.dom, "id", self.docId, docEl)
		XmlUtils.addChild (self.dom, "fileCreated", "Aug 5 2010", docEl)
		XmlUtils.addChild (self.dom, "description", "This is a test document", docEl)
		childrenEl = self.addElement (docEl, "children")
		for childKey in self.nodeMap[self.docId].children:
			XmlUtils.addChild (self.dom, "child", self.getNodeId(childKey), childrenEl)
		return docEl