Exemplo n.º 1
0
 def asCatalogElement(self):
     element = XmlUtils.createElement('asnDocument')
     element.setAttribute("id", self.asnUri)
     for attr in ['title', 'topic', 'author', 'created', 'status']:
         child = XmlUtils.createElement(attr)
         val = getattr(self, attr) or ''
         ## print "val: %s (%s)" % (val, type(val))
         XmlUtils.setText(child, val)
         element.appendChild(child)
     return element
Exemplo n.º 2
0
 def asElement(self):
     element = XmlUtils.createElement('relation')
     element.setAttribute('relationship', self.relationship)
     if self.num:
         element.setAttribute('num', self.num)
     element.setAttribute('objectTitle', unicode(self.objectTitle))
     element.setAttribute('object', self.object)
     idEl = element.appendChild(XmlUtils.createElement('id'))
     # idEl = XmlUtils.addElement(doc, parent, tagName)
     # idEl.setAttribute ('id', self.id)
     XmlUtils.setText(idEl, self.id)
     idEl.setAttribute('type', self.idType)
     return element
Exemplo n.º 3
0
    def asElement(self):
        element = XmlUtils.createElement('person')
        element.setAttribute('role', 'Author')

        if self.authororder is not None:
            element.setAttribute('order', str(self.authororder))

        for attr in self.attrs:
            tag = attr
            value = getattr(self, attr)
            if value:
                child = element.appendChild(XmlUtils.createElement(tag))
                XmlUtils.setText(child, value)
        return element
Exemplo n.º 4
0
	def getAffiliation (self, instName):
		"""
		affilations are associated with ONE instName
		returns Affilation instance for provided instName, creating if necessary
		"""
		affiliationEl = None
		for node in self.getAffiliationElements():
			instNameEl = XmlUtils.getChild('instName', node)
			if XmlUtils.getText(instNameEl) == instName:
				affiliationEl = node
				break
		if not affiliationEl:
			affiliationEl = self.element.appendChild (XmlUtils.createElement('affiliation'))
			instNameEl = affiliationEl.appendChild (XmlUtils.createElement('instName'))
			XmlUtils.setText(instNameEl, instName)
		return Affiliation (affiliationEl)
Exemplo n.º 5
0
    def insertFiscalYear(self, fiscalYear):
        """
		insert proviced fiscalYear in the dom
		
		if setFiscalYear fails the first call,
		the instance record does not have the necessary elements, which are created
		"""
        try:
            self.setFiscalYear(fiscalYear)
            return
        except:
            pass

        fyEl = XmlUtils.createElement('fiscalYear')
        coverageNode = self.getCoverageNode()
        # coverageNode = self.selectSingleNode (self.dom, 'record/coverage')
        if not coverageNode:
            raise Exception, "not not found at 'record/coverage' for %s" % self.getId(
            )
        children = XmlUtils.getChildElements(coverageNode)
        if children:
            coverageNode.insertBefore(fyEl, children[0])
        else:
            coverageNode.appendChild(fyEl)
        self.setFiscalYear(fiscalYear)
Exemplo n.º 6
0
	def setPubName (self, pubName, pubNameType=None):
		"""
		creates pubName element if one doesn't exist
		ASSUMES A TITLE ELEMENT EXISTS for proper insertion
			(inserts following title element)
		"""
		if not self.selectSingleNode (self.dom, self.xpaths['pubName']):
			# create pubNamem element now, but we populate later
			pubNameEl = XmlUtils.createElement("pubName")
			
			## now find where to insert pubNameEl
			generalEl = self.selectSingleNode (self.dom, 'record/general')
			if not generalEl:
				raise Exception, "record does not contain a general element"
			gen_children = XmlUtils.getChildElements(generalEl)
			print "%d elements found" % len(gen_children)
			targetEl = None
			for child in gen_children:
				print ' - ', child.tagName
				if not child.tagName in ['recordID', 'recordDate', 'urlOfRecord']:
					targetEl = child
					print "target is %s" % child.tagName
					break
					
			if targetEl:
				# insert after targetEl
				generalEl.insertBefore (pubNameEl, targetEl)
			else:
				# insert at end of general element
				XmlUtils.addElement (self.dom, generalEl, 'pubName')
			
		self.set ('pubName', pubName)
		if pubNameType:
			self.setPubNameType (pubNameType)
Exemplo n.º 7
0
	def asElement(self):
		# print "\n%s creating element: %s" % (self.__class__.__name__, self.tagName)
		element = XmlUtils.createElement(self.tagName)
		element.setAttribute ('recordId', self.id)
		element.setAttribute ('name', self.name)
		for child in self.children:
			element.appendChild (child.asElement())
		return element
Exemplo n.º 8
0
	def asElement(self):
		element = XmlUtils.createElement("record")
		element.setAttribute ("recId", self.recId)
		element.setAttribute ("status", self.status)
		element.setAttribute ("title", self.title)
		element.setAttribute ("pubName", self.pubName)
		element.setAttribute ("fiscalYear", self.fiscalYear)
		element.setAttribute ("titleKey", self.titleKey)
		return element
Exemplo n.º 9
0
    def asElement(self):
        """
		render this PubNameSpec as an XML element so it can be put in an XML
		document containing multiple change PubNameSpecs
		"""
        element = XmlUtils.createElement("pubNameSpec")
        for attr in ['recId', 'collection', 'xmlFormat', 'pubType']:
            element.setAttribute(attr, getattr(self, attr))
            XmlUtils.setText(element, self.term)
        return element
Exemplo n.º 10
0
	def setInstName (self, instName):
		"""
		Affiliations have ONE instName element
		if an instName element does not exist, create one
		set the text of the instName element to provided instName value
		"""
		instNameEl = XmlUtils.getChild ('instName', self.element)
		if not instNameEl:
			instNameEl = self.element.appendChild (XmlUtils.createElement('instName'))
			print 'created instNameEl: ' + instNameEl.toxml()
		XnlUtils.setText(instNameEl, instName)
		return instNameEl
Exemplo n.º 11
0
    def __init__(self, line, fromShape, fromConnector, toShape, toConnector):
        """
		line, fromShape, toShape are shape IDs
		from and toConnector are connector IDs
		"""
        self.element = XmlUtils.createElement('Connects')
        # connect begining of line to connector on fromShape
        connect1 = XmlUtils.createElement('Connect')
        connect1.setAttribute('FromSheet', str(line))
        connect1.setAttribute('FromPart', '9')
        connect1.setAttribute('ToSheet', str(fromShape))
        connect1.setAttribute('ToPart', '10%s' % fromConnector)
        self.element.appendChild(connect1)

        # connect end of line to connector on toShape
        connect2 = XmlUtils.createElement('Connect')
        connect2.setAttribute('FromSheet', str(line))
        connect2.setAttribute('FromPart', '12')
        connect2.setAttribute('ToSheet', str(toShape))
        connect2.setAttribute('ToPart', '10%s' % toConnector)
        self.element.appendChild(connect2)
Exemplo n.º 12
0
	def addInstDivVocab (self, instDivVocab):
		"""
		add all the segments of the provided instDivVocab (that
		do not already exist) to this Affliation.
		NOTE: we don't add the first split by itself, the first
		split we add is [0:1]
		"""
		splits = instDivVocab.split(":")
		for i in range (1, len(splits)):
			vocab = ':'.join(splits[:i+1])
			if not self.getInstDiv (vocab):
				instDiv = XmlUtils.createElement("instDivision")
				XmlUtils.setText (instDiv, vocab)
				self.element.appendChild (instDiv)
Exemplo n.º 13
0
    def getUnknownCopyrightNoticeElement(self):
        """<copyrightNotice type="Unknown" holder="Unknown" url="http://www.ucar.edu/legal/terms_of_use.shtml">
				Copyright information is unknown. Please contact the creator, author or publisher for further information.
			</copyrightNotice>
		"""

        el = XmlUtils.createElement("copyrightNotice")
        XmlUtils.setText(
            el,
            "Copyright information is unknown. Please contact the creator, author or publisher for further information."
        )
        el.setAttribute('type', 'Unknown')
        el.setAttribute('holder', 'Unknown')
        el.setAttribute('url', 'http://www.ucar.edu/legal/terms_of_use.shtml')
        return el
Exemplo n.º 14
0
    def handleSponsor(self, osmRecord):
        """
		/record/contributors/organization/@role="Meeting sponsor"; 
		/record/contributors/organization/affliation/instName
		
		ISSUE: are names REALLY are separated by commas?? 
		perform a lookup of the sponsor name to get the correct OSM instName by using
		http://nldr.library.ucar.edu/metadata/osm/1.1/documents/wosSponsorLook-up-2011.xslx
		"""
        sponsor = self['sponsor']

        ## NOTE - THERE MAY BE MULTIPLE SPONSORS, so we have to do the following for EACH

        instName = sponsor_reader.getInstName(sponsor)

        orgEl = XmlUtils.createElement('organization')
        orgEl.setAttribute('role', 'Meeting sponsor')
        org = ContributorOrganization(orgEl)
        affiliation = org.getAffiliation(instName)
        osmRecord.addContributorInstance(org)
Exemplo n.º 15
0
	def setDate (self, dateStr, dateType):
		coverageNode = self.selectSingleNode (self.dom, 'record/coverage')
		if not coverageNode:
			#raise Exception, "no coverage node found"
			coverageNode = XmlUtils.addElement(self.dom, self.doc, "coverage")
		targetDateElement = None
		dateNodes = self.getDateNodes()
		if dateNodes:
			for node in dateNodes:
				if node.hasAttribute (dateType):
					targetDateElement = node
		if targetDateElement is None:
			targetDateElement = XmlUtils.createElement ("date")
			targetDateElement.setAttribute ("type", dateType)
			coverageChildren = XmlUtils.getChildElements (coverageNode)
			if coverageChildren:
				firstChild = coverageChildren[0]
				coverageNode.insertBefore (targetDateElement, firstChild)
			else:
				coverageNode.appendChild (targetDateElement)
		XmlUtils.setText (targetDateElement, dateStr)
		return targetDateElement
Exemplo n.º 16
0
def makeTerm(title, docCount):
    element = XmlUtils.createElement('term')
    element.setAttribute('docCount', str(docCount))
    element.setAttribute('termCount', '0')  # we don't care about termCount
    XmlUtils.setText(element, title)
    return Term(element)
Exemplo n.º 17
0
	def addValue(self, value):
		vocabTerm = XmlUtils.createElement (qp("enumeration"), XSD_NAMESPACE_URI)
		vocabTerm.setAttribute ("value", value)
		self.restriction.appendChild (vocabTerm)
Exemplo n.º 18
0
	def setDateCreated (self):
		dateEl = self.selectSingleNode (self.dom, 'orgConfig/date')
		if not dateEl:
			dateEl = self.doc.appendChild (XmlUtils.createElement('date'))
		dateEl.setAttribute ('created', self.getXsdDate())
Exemplo n.º 19
0
	def setOrgEntity (self, orgEntity, key):
		orgEntityEl = self.selectSingleNode (self.dom, self._xpath ('orgEntity'))
		if not orgEntityEl:
			orgEntityEl = self.doc.appendChild (XmlUtils.createElement('orgEntity'))
		self.set ('orgEntity', orgEntity)
		orgEntityEl.setAttribute ('key', key)
Exemplo n.º 20
0
def createSchemaElement(name):
    """
	names the element with the correct XSD_PREFIX and sends namespace
	returns an element
	"""
    return XmlUtils.createElement(qp(name), XSD_NAMESPACE_URI)
Exemplo n.º 21
0
	def setChildElementValue (self, tag, value):
		# print "TAG:%s, VALUE: %s" % (tag, value)
		child = XmlUtils.getChild (tag, self.element)
		if not child:
			child = self.element.appendChild(XmlUtils.createElement(tag))
		XmlUtils.setText (child, value)
Exemplo n.º 22
0
	def setContactInfoProp (self, prop, val):
		contactInfoEl = XmlUtils.getChild ('contactInfo', self.element)
		if not contactInfoEl:
			contactInfoEl = self.element.appendChild (XmlUtils.createElement ('contactInfo'))
		contactInfoEl.setAttribute (prop, val)	
Exemplo n.º 23
0
 def setNameLast(self, name):
     node = XmlUtils.getChild('nameLast', self.element)
     if not node:
         node = XmlUtils.createElement('nameLast')
         self.element.appendChild(node)
     XmlUtils.setText(node, name)