• Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Change
  • Next Change →

Changeset 134 for Xml/Validator/WebApp/validator/OmeValidator.py

Show
Ignore:
Timestamp:
01/10/08 15:31:25 (11 months ago)
Author:
andrew
Message:

Added the checkOldSchemas code the the file but it is not called by the mail validate function yet.

Files:
1 modified

  • Xml/Validator/WebApp/validator/OmeValidator.py (modified) (4 diffs)

Legend:

Unmodified
Added
Removed
  • Xml/Validator/WebApp/validator/OmeValidator.py

    r130 r134  
    144144         
    145145        """ 
     146        The file the schema for the namespace has been loaded from 
     147        """ 
     148        theSchemaFile = None 
     149        """ 
    146150        Create the message lists for this instance of the report object 
    147151        """ 
    … …  
    241245                # loading the OME schema to validate against 
    242246                schema = self.loadChoosenSchema() 
     247                if schema is None: 
     248                        return 
     249                 
    243250                # create an IO string for the xml string provided 
    244251                stringXml = StringIO(self.theDom.toxml()) 
    … …  
    265272                        self.isXsdValid = False 
    266273                        self.errorList.append(ParseMessage(None, None, None, "XML", None, "Processing the XML data has generated an unspecified error in the XML sub-system. This is usually a result of an incorrect top level block. Please check the OME block is well-formed and that the schemaLocation is specified correctly. This may also be caused by a missing namespace prefix or incorrect xmlns attribute.")) 
    267                          
     274         
     275        def checkOldSchemas(self, inDocument): 
     276                for thePossibleSchema in [["ome-2007-07-V2.xsd","September 2007 V2"],["ome-2007-07-V1.xsd","June 2007 V1"],["ome-fc-tiff.xsd","2003 - Tiff Variant"], ["ome-fc.xsd","2003 - Standard version"]]: 
     277                        # skip current one 
     278                        if not thePossibleSchema[0] == self.theSchemaFile: 
     279                                # load each old schema 
     280                                try: 
     281                                        schema = etree.XMLSchema(etree.parse(schemaFilePath(thePossibleSchema[0]))) 
     282                                except: 
     283                                        # chosen schema failed to laod 
     284                                        self.errorList.append(ParseMessage(None, None, None, "XSD", None, "Validator Internal error: XSD schema file could not be found")) 
     285                                # try validation 
     286                                try: 
     287                                        schema.validate(inDocument) 
     288                                        err = schema.error_log.last_error 
     289                                        if not err: 
     290                                                # if valid then add info message "also valid under..." 
     291                                                self.warningList.append(ParseMessage(None, None, None, "Info", None, "File also valid under schema: " + thePossibleSchema[1])) 
     292                                except etree.XMLSchemaValidateError: 
     293                                        err = False 
    268294         
    269295        def loadChoosenSchema(self): 
    270296                # choose the schema source 
    271297                # assume the new schema 
    272                 theSchemaFile = "ome-2007-07-V2.xsd" 
     298                self.theSchemaFile = "ome-2007-07-V2.xsd" 
    273299                # if old schema 
    274300                if self.theNamespace == "http://www.openmicroscopy.org/XMLschemas/OME/FC/ome.xsd": 
    … …  
    276302                        if self.isOmeTiff: 
    277303                                # use special tiff version of old schema 
    278                                 theSchemaFile = "ome-fc-tiff.xsd" 
     304                                self.theSchemaFile = "ome-fc-tiff.xsd" 
    279305                        else: 
    280306                                # use normal version of old schema 
    281                                 theSchemaFile = "ome-fc.xsd" 
     307                                self.theSchemaFile = "ome-fc.xsd" 
    282308                 
    283309                # loading the OME schema to validate against 
    284310                try: 
    285                         schema = etree.XMLSchema(etree.parse(schemaFilePath(theSchemaFile))) 
     311                        schema = etree.XMLSchema(etree.parse(schemaFilePath(self.theSchemaFile))) 
    286312                except: 
    287                         #chosen scema failed to laod 
     313                        # chosen schema failed to laod 
    288314                        self.errorList.append(ParseMessage(None, None, None, "XSD", None, "Validator Internal error: XSD schema file could not be found")) 
    289                  
     315                        schema = None; 
     316                         
    290317                return schema 
    291318         

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/