Package org.esa.snap.core.metadata
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
XmlMetadataParser.MetadataHandler
Actual document handler implementationprotected class
XmlMetadataParser.SimpleMetadataHandler
-
Field Summary
Fields Modifier and Type Field Description protected Class
fileClass
protected String
schemaBasePath
protected String[]
schemaLocations
-
Constructor Summary
Constructors Constructor Description XmlMetadataParser(Class metadataClass)
Constructs an instance ofXmlMetadataParser
for the given metadata class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ProductData
inferType(String elementName, String value)
Tries to infer the type of the element, based on the available XSD schema definition.T
parse(InputStream inputStream)
Tries to parse the givenInputStream
(which may be a string or a stream over a file).MetadataElement
parse(Path file, Set<String> excludes)
protected void
setSchemaBasePath(String schemaBasePath)
Sets the location of the schema base path that should be used for XSD schema validation.protected void
setSchemaLocations(String[] schemaLocations)
Sets the location(s) of the XSD schema(s) that should be used for XSD schema validation.protected boolean
shouldValidateSchema()
Indicates if the XSD validation should be performed.
-
-
-
Constructor Detail
-
XmlMetadataParser
public XmlMetadataParser(Class metadataClass)
Constructs an instance ofXmlMetadataParser
for the given metadata class.- Parameters:
metadataClass
- The class of metadata (it should be derived fromXmlMetadata
).
-
-
Method Detail
-
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 beProductData.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 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,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.
-
-