Package org.esa.snap.core.metadata
Class XmlMetadataParser<T extends GenericXmlMetadata>
java.lang.Object
org.esa.snap.core.metadata.XmlMetadataParser<T>
SAX parser for XML metadata. This is because DOM parsing would consume more time and resources
for large metadata files.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classActual document handler implementationprotected class -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionXmlMetadataParser(Class metadataClass) Constructs an instance ofXmlMetadataParserfor the given metadata class. -
Method Summary
Modifier and TypeMethodDescriptionprotected ProductDataTries to infer the type of the element, based on the available XSD schema definition.parse(InputStream inputStream) Tries to parse the givenInputStream(which may be a string or a stream over a file).protected voidsetSchemaBasePath(String schemaBasePath) Sets the location of the schema base path that should be used for XSD schema validation.protected voidsetSchemaLocations(String[] schemaLocations) Sets the location(s) of the XSD schema(s) that should be used for XSD schema validation.protected booleanIndicates if the XSD validation should be performed.
-
Field Details
-
fileClass
-
schemaLocations
-
schemaBasePath
-
-
Constructor Details
-
XmlMetadataParser
Constructs an instance ofXmlMetadataParserfor the given metadata class.- Parameters:
metadataClass- The class of metadata (it should be derived fromXmlMetadata).
-
-
Method Details
-
inferType
Tries to infer the type of the element, based on the available XSD schema definition. If no schema definition exist, the type will always beProductData.ASCII.- Parameters:
elementName- The name of the XML element.value- The value of the XML element.- Returns:
- An instance of
ProductDatawrapping the element value.
-
parse
public T parse(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException Tries to parse the givenInputStream(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
public MetadataElement parse(Path file, Set<String> excludes) 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,truewould mean that the XML schema validation should be performed.
-
setSchemaBasePath
Sets the location of the schema base path that should be used for XSD schema validation.- Parameters:
schemaBasePath- The schema base path.
-
setSchemaLocations
Sets the location(s) of the XSD schema(s) that should be used for XSD schema validation.- Parameters:
schemaLocations- An array of schema locations.
-