Class XmlMetadataParser<T extends GenericXmlMetadata>

java.lang.Object
org.esa.snap.core.metadata.XmlMetadataParser<T>

public class XmlMetadataParser<T extends GenericXmlMetadata> extends Object
SAX parser for XML metadata. This is because DOM parsing would consume more time and resources for large metadata files.
  • Field Details

    • fileClass

      protected Class fileClass
    • schemaLocations

      protected String[] schemaLocations
    • schemaBasePath

      protected String schemaBasePath
  • Constructor Details

    • XmlMetadataParser

      public XmlMetadataParser(Class metadataClass)
      Constructs an instance of XmlMetadataParser for the given metadata class.
      Parameters:
      metadataClass - The class of metadata (it should be derived from XmlMetadata).
  • Method Details

    • inferType

      protected ProductData inferType(String elementName, String value)
      Tries to infer the type of the element, based on the available XSD schema definition. If no schema definition exist, the type will always be ProductData.ASCII.
      Parameters:
      elementName - The name of the XML element.
      value - The value of the XML element.
      Returns:
      An instance of ProductData wrapping the element value.
    • parse

      public T parse(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException
      Tries to parse the given InputStream (which may be a string or a stream over a file).
      Parameters:
      inputStream - The input stream
      Returns:
      If successful, it returns an instance of a class extending XmlMetadata.
      Throws:
      ParserConfigurationException - Exception is thrown by the underlying SAX mechanism.
      SAXException - Exception is thrown if the XML is not well formed.
      IOException - Exception is thrown if there is a problem reading the input stream.
    • parse

      Throws:
      ParserConfigurationException
      SAXException
      IOException
    • shouldValidateSchema

      protected boolean shouldValidateSchema()
      Indicates if the XSD validation should be performed. Override this in derived classes to enable schema validation.
      Returns:
      The default implementation always returns false. In a derived class, true would mean that the XML schema validation should be performed.
    • setSchemaBasePath

      protected void setSchemaBasePath(String schemaBasePath)
      Sets the location of the schema base path that should be used for XSD schema validation.
      Parameters:
      schemaBasePath - The schema base path.
    • setSchemaLocations

      protected void setSchemaLocations(String[] schemaLocations)
      Sets the location(s) of the XSD schema(s) that should be used for XSD schema validation.
      Parameters:
      schemaLocations - An array of schema locations.