Ignore:
Timestamp:
05/01/09 09:37:12 (11 years ago)
Author:
cbyrom
Message:

Further tidy up of Atom model, tightening up XPath expressions to
include full namespace details.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/models/Atom.py

    r4696 r4721  
    3636    ''' 
    3737    Class representing atom author type data - with name, uri and role attributes 
     38    @keyword personType: Type of person to create - specified using the Person.._Type 
     39    values.  Default is AUTHOR_TYPE. 
     40    @keyword namespace: a two value array of format, ['short_namespace_name', 'full_namespace_name'] 
     41    - e.g. ['moles', 'http://ndg.nerc.ac.uk/schema/moles2beta'] 
    3842    ''' 
    3943    AUTHOR_TYPE = 0 
     
    4448    def __init__(self, personType = AUTHOR_TYPE, namespace = None): 
    4549        self.type = personType 
    46         self.ns = namespace 
     50        if namespace: 
     51            self.ns_shortname = namespace[0] 
     52            self.ns_fullname = namespace[1] 
     53        else: 
     54            self.ns_shortname = "" 
     55            self.ns_fullname = ndgObject.ATOM_NS 
     56             
    4757        self.name = "" 
    4858        self.uri = "" 
     
    5363        # NB, responsible party data is always stored in the moles section 
    5464        if self.type == self.RESPONSIBLE_PARTY_TYPE: 
    55             self.ns = 'moles' 
     65            self.ns_shortname = 'moles' 
     66            self.ns_fullname = ndgObject.MOLES_NS 
    5667            self.uriTagName = "uri" 
    5768 
     
    7182         
    7283    def fromETElement(self, personTag): 
    73         self.name = personTag.findtext('{%s}name' %ndgObject.ATOM_NS) or "" 
    74         self.role = personTag.findtext('{%s}role' %ndgObject.ATOM_NS) or "" 
    75         self.uri = personTag.findtext('{%s}%s' %(ndgObject.ATOM_NS, self.uriTagName)) or "" 
     84        self.name = personTag.findtext('{%s}name' %self.ns_fullname) or "" 
     85        self.role = personTag.findtext('{%s}role' %self.ns_fullname) or "" 
     86        self.uri = personTag.findtext('{%s}%s' %(self.ns_fullname, self.uriTagName)) or "" 
    7687        logging.debug("Added name: '%s', role: '%s', %s: '%s'" \ 
    7788                      %(self.name, self.role, self.uriTagName, self.uri)) 
     
    7990    def toXML(self): 
    8091        prefix = "" 
    81         if self.ns: 
    82             prefix = self.ns + ':' 
     92        if self.ns_shortname: 
     93            prefix = self.ns_shortname + ':' 
    8394 
    8495        author = ET.Element(prefix + self.ELEMENT_NAMES[self.type]) 
     
    761772                    self.maxY = spatialData[1] 
    762773                 
    763         publishedDate = tree.findtext('published') 
     774        publishedDate = tree.findtext('{%s}published' %ndgObject.ATOM_NS) 
    764775        if publishedDate: 
    765776            logging.debug("Adding published date") 
    766777            self.publishedDate = publishedDate 
    767778                 
    768         updatedDate = tree.findtext('updated') 
     779        updatedDate = tree.findtext('{%s}updated' %ndgObject.ATOM_NS) 
    769780        if updatedDate: 
    770781            logging.debug("Adding updated date") 
     
    957968        if attributeName == "relatedLinks": 
    958969            obj = Link() 
    959         elif attributeName == "atomAuthors" or attributeName == "authors": 
     970        elif attributeName == "atomAuthors": 
     971            obj = Person(personType = Person.RESPONSIBLE_PARTY_TYPE) 
     972        elif attributeName == "authors": 
    960973            # NB, ensure there is only one author tag - extra authors are contributors 
    961974            authorType = Person.AUTHOR_TYPE 
Note: See TracChangeset for help on using the changeset viewer.