Changeset 4502 for exist


Ignore:
Timestamp:
27/11/08 15:12:25 (11 years ago)
Author:
cbyrom
Message:

Move code from granulite, to add CSML data to atom, to Atom class + add
several fixes to Atom to make it more robust wrt data handling.

File:
1 edited

Legend:

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

    r4494 r4502  
    1717from ndgUtils.ETxmlView import et2text 
    1818from ndgUtils.lib.utilities import getTripleData, escapeSpecialCharacters, \ 
    19     tidyUpParameters, getISO8601Date, normaliseLongitude 
     19    tidyUpParameters, getISO8601Date, normaliseLongitude, formatDateYYYYMMDD 
    2020from ndgUtils.vocabtermdata import VocabTermData as VTD 
    2121from ndgUtils.models import MolesEntity as ME 
     
    589589        # - and this is mandatory 
    590590        content = ET.SubElement(root, "content") 
    591         if self.contentFile: 
     591        contentFile = self.contentFile or self.csmlFile or self.cdmlFile 
     592        if contentFile: 
    592593            content.attrib["type"] = "application/xml" 
    593             content.attrib["src"] = self.contentFile 
     594            content.attrib["src"] = contentFile 
    594595        else: 
    595596            content.text = self.Content 
     
    893894        envelope = ET.SubElement(bbox, "gml:Envelope") 
    894895        lc = ET.SubElement(envelope, "gml:lowerCorner") 
    895         lc.text = self.minX + " " + self.minY 
     896        lc.text = str(self.minX) + " " + str(self.minY) 
    896897        uc = ET.SubElement(envelope, "gml:upperCorner") 
    897         uc.text = self.maxX + " " + self.maxY 
     898        uc.text = str(self.maxX) + " " + str(self.maxY) 
    898899 
    899900         
     
    10341035 
    10351036         
    1036     def addCSMLData(self, csml, aggregateCoverage=False): 
     1037    def addCSMLData(self, csmlName, csmlContent, aggregateCoverage=False, useCSMLID=False): 
    10371038        ''' 
    10381039        Parse CSML data and add extracted info to the atom 
    1039         @param csml: csml file contents - or path to csml file 
     1040        @param csmlName: name of the csml file 
     1041        @param csmlContent: content of the csml file - NB, if this is set to None and the 
     1042        file, csmlName, is available locally, CsmlParser.Dataset will read in the file 
     1043        directly 
    10401044        @keyword aggregateCoverage: if set to True, only coverage data that extends the 
     1045        @keyword useCSMLID: if True, use the CSML doc ID as the dataset ID - NB,  
     1046        this should only be True if creating a new atom - e.g. from a granulite 
    10411047        atom coverage data will be added 
     1048        @return csmlDoc: the CsmlParser.Dataset object with the csml data in 
    10421049        ''' 
    10431050        logging.info("Creating CSML data model") 
    1044         self.csmlFile = csml.filename 
    1045         csmlDoc = CsmlParser.Dataset(file=csml.value) 
     1051        self.csmlFile = csmlName 
     1052        self.contentFile = csmlName 
     1053        content = csmlContent or csmlName 
     1054        csmlDoc = CsmlParser.Dataset(file=content) 
    10461055         
    10471056        logging.info("Extracting info from CSML file") 
    10481057        logging.debug("Got dataset ID: %s" %csmlDoc.id) 
    1049         self.setDatasetID(csmlDoc.id) 
     1058        if useCSMLID: 
     1059            logging.debug(" - using this ID for the atom") 
     1060            self.setDatasetID(VTD.GRANULE_TERM + '_' + csmlDoc.id) 
    10501061         
    10511062        title = csmlDoc.name.CONTENT 
     
    11321143        self.addParameters(parameters) 
    11331144        logging.info("Finished adding CSML data") 
     1145        return csmlDoc 
    11341146 
    11351147 
Note: See TracChangeset for help on using the changeset viewer.