Beispiel #1
0
    def validateMetadataFile(self):
        # check if metadata exists
        if not self.checkMetadata():
            return

        # check matadata standard
        standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)
        if standard != MetaInfoStandard.FGDC:
            QMessageBox.critical(
                self.iface.mainWindow(),
                QCoreApplication.translate("Metatools", "Metatools"),
                QCoreApplication.translate(
                    "Metatools",
                    "Unsupported metadata standard! Only FGDC supported now!"))
            return

        from PyQt4.QtXmlPatterns import QXmlSchema, QXmlSchemaValidator
        # TODO: validate metadata file

        # setup xml schema
        schema = QXmlSchema()

        # setup handler
        self.handler = ErrorHandler(
            QCoreApplication.translate("Metatools", "Metadata is invalid"))
        schema.setMessageHandler(self.handler)

        # load schema from file
        xsdFilePath = self.pluginPath + '/xsd/fgdc/fgdc-std-001-1998.xsd'
        #if standard != MetaInfoStandard.FGDC:
        #    xsdFilePath = 'c:/xsd/gml/basicTypes.xsd' #   gmd/gmd.xsd'
        schemaUrl = QUrl(xsdFilePath)
        loadResult = schema.load(schemaUrl)
        if not loadResult or self.handler.errorOccured:
            QMessageBox.critical(
                self.iface.mainWindow(),
                QCoreApplication.translate("Metatools", "Metatools"),
                QCoreApplication.translate("Metatools",
                                           "Schema for validate not loaded!"))
            return

        #setup validator
        validator = QXmlSchemaValidator(schema)
        validator.setMessageHandler(self.handler)

        #validate
        metadata = self.metaProvider.getMetadata().encode('utf-8')
        if validator.validate(metadata):
            QMessageBox.information(
                self.iface.mainWindow(),
                QCoreApplication.translate("Metatools", "Metatools"),
                QCoreApplication.translate("Metatools", "Metadata is valid!"))
Beispiel #2
0
def validate_ex():
    from PyQt4.QtCore import QUrl
    from PyQt4.QtXmlPatterns import QXmlSchema, QXmlSchemaValidator
    qurl = QUrl(
        'file:///home/michele/oq-nrmllib/openquake/nrmllib/schema/nrml.xsd')
    schema = QXmlSchema()
    schema.load(qurl)
    if schema.isValid():
        v = QXmlSchemaValidator(schema)
        print v.validate(QUrl('file:///home/michele/oq-nrmllib/examples/'
                              'vulnerability-model-discrete.xml'))
    else:
        print 'schema invalid'
Beispiel #3
0
    def check_xml_validity(self, xml):
        message_handler = MessageHandler()

        f = QtCore.QFile(STYLESHEET)
        f.open(QtCore.QIODevice.ReadOnly)
        schema = QXmlSchema()
        schema.load(f)

        validator = QXmlSchemaValidator(schema)
        validator.setMessageHandler(message_handler)
        result = validator.validate(self.text)

        return result, message_handler
Beispiel #4
0
    def check_xml_validity(self, xml):
        message_handler = MessageHandler()

        LOGGER.debug("checking phrasebook xml against %s" % STYLESHEET)
        f = QtCore.QFile(STYLESHEET)
        f.open(QtCore.QIODevice.ReadOnly)
        schema = QXmlSchema()
        schema.load(f)

        validator = QXmlSchemaValidator(schema)
        validator.setMessageHandler(message_handler)
        result = validator.validate(self.text)

        return result, message_handler
Beispiel #5
0
  def validateMetadataFile(self):
    # check if metadata exists
    if not self.checkMetadata():
      return

    # check matadata standard
    standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider)
    if standard != MetaInfoStandard.FGDC:
      QMessageBox.critical(self.iface.mainWindow(),
                           QCoreApplication.translate("Metatools", "Metatools"),
                           QCoreApplication.translate("Metatools", "Unsupported metadata standard! Only FGDC supported now!")
                          )
      return


    from PyQt4.QtXmlPatterns import QXmlSchema, QXmlSchemaValidator
    # TODO: validate metadata file

    # setup xml schema
    schema = QXmlSchema()

    # setup handler
    self.handler = ErrorHandler(QCoreApplication.translate("Metatools", "Metadata is invalid"))
    schema.setMessageHandler(self.handler)

    # load schema from file
    xsdFilePath = self.pluginPath + '/xsd/fgdc/fgdc-std-001-1998.xsd'
    #if standard != MetaInfoStandard.FGDC:
    #    xsdFilePath = 'c:/xsd/gml/basicTypes.xsd' #   gmd/gmd.xsd'
    schemaUrl = QUrl(xsdFilePath)
    loadResult = schema.load(schemaUrl)
    if not loadResult or self.handler.errorOccured:
        QMessageBox.critical(self.iface.mainWindow(),
                             QCoreApplication.translate("Metatools", "Metatools"),
                             QCoreApplication.translate("Metatools", "Schema for validate not loaded!")
                            )
        return

    #setup validator
    validator = QXmlSchemaValidator(schema)
    validator.setMessageHandler(self.handler)

    #validate
    metadata = self.metaProvider.getMetadata().encode('utf-8')
    if validator.validate(metadata):
        QMessageBox.information(self.iface.mainWindow(),
                                QCoreApplication.translate("Metatools", "Metatools"),
                                QCoreApplication.translate("Metatools", "Metadata is valid!")
                               )
Beispiel #6
0
    def check_validity(self, xml):
        '''
        check that the dom validates
        '''
        self.message_handler.reset()

        f = QtCore.QFile(STYLESHEET)
        f.open(QtCore.QIODevice.ReadOnly)
        schema = QXmlSchema()
        schema.load(f)

        validator = QXmlSchemaValidator(schema)
        validator.setMessageHandler(self.message_handler)
        result = validator.validate(xml)

        if result:
            LOGGER.debug(
                "Feescale complies with stylesheet!")
        else:
            LOGGER.warning(
                "Feescale does not comply with stylesheet %s"% STYLESHEET)
        return (result, self.message_handler.last_error)
Beispiel #7
0
    def check_validity(self, xml):
        '''
        check that the dom validates
        '''
        self.message_handler.reset()

        LOGGER.debug("checking phrasebook xml against %s", STYLESHEET)

        f = QtCore.QFile(STYLESHEET)
        f.open(QtCore.QIODevice.ReadOnly)
        schema = QXmlSchema()
        schema.load(f)

        validator = QXmlSchemaValidator(schema)
        validator.setMessageHandler(self.message_handler)
        result = validator.validate(xml)

        if result:
            LOGGER.debug("Feescale complies with stylesheet!")
        else:
            LOGGER.warning("Feescale does not comply with stylesheet %s" %
                           STYLESHEET)
        return (result, self.message_handler.last_error)