Package gov.nasa.pds.tools.label
Class LabelValidator
- java.lang.Object
-
- gov.nasa.pds.tools.label.LabelValidator
-
public class LabelValidator extends Object
This class is responsible for providing utility functions for validating PDS XML Labels.- Author:
- pramirez
-
-
Field Summary
Fields Modifier and Type Field Description static String
SCHEMA_CHECK
static String
SCHEMATRON_CHECK
-
Constructor Summary
Constructors Constructor Description LabelValidator()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addValidator(DocumentValidator validator)
void
addValidator(ExternalValidator validator)
void
clear()
XMLCatalogResolver
getCatalogResolver()
Boolean
getConfiguration(String key)
long
getFilesProcessed()
Returns the number of files processed by the validation function.List<String>
getSchematrons(NodeList nodeList, URL url, ProblemHandler handler)
double
getTotalTimeElapsed()
Returns the duration it took to run the validation function.Document
parseAndValidate(ProblemHandler handler, URL url)
Parses and validates a label against the schema and Schematron files, and returns the parsed XML.Boolean
performsSchematronValidation()
Boolean
performsSchemaValidation()
void
setCachedEntityResolver(CachedEntityResolver resolver)
void
setCachedLSResourceResolver(CachedLSResourceResolver resolver)
void
setCatalogs(String[] catalogFiles)
Pass in a list of Catalog files to use during the validation step.void
setConfiguration(String key, Boolean value)
void
setLabelSchematrons(Map<String,String> schematronMap)
Pass in a hash map of schematron URLs to its transformed schematron object.void
setSchema(List<URL> schemaFiles)
Pass in a list of schemas to validate against.void
setSchemaCheck(Boolean value)
void
setSchemaCheck(Boolean value, Boolean useLabelSchema)
void
setSchematronCheck(Boolean value)
void
setSchematronCheck(Boolean value, Boolean useLabelSchematron)
void
setSchematronFiles(List<URL> schematronFiles)
Pass in a list of schematron files to validate against.void
setSchematrons(List<String> schematrons)
Pass in a list of transformed schematrons to validate against.void
setSkipProductValidation(Boolean flag)
void
validate(ProblemHandler handler, File labelFile)
void
validate(ProblemHandler handler, URL url)
Validates the label against schema and schematron constraints.void
validate(ProblemHandler handler, URL url, String labelExtension)
void
validate(File labelFile)
-
-
-
Field Detail
-
SCHEMA_CHECK
public static final String SCHEMA_CHECK
- See Also:
- Constant Field Values
-
SCHEMATRON_CHECK
public static final String SCHEMATRON_CHECK
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LabelValidator
public LabelValidator() throws ParserConfigurationException, TransformerConfigurationException
Default constructor.- Throws:
ParserConfigurationException
- If there was an error setting up the configuration of the parser that is reposnible for doing the label validation.TransformerConfigurationException
- If there was an error setting up the Transformer responsible for doing the transformations of the schematrons.
-
-
Method Detail
-
getFilesProcessed
public long getFilesProcessed()
Returns the number of files processed by the validation function.
-
getTotalTimeElapsed
public double getTotalTimeElapsed()
Returns the duration it took to run the validation function.
-
setSchema
public void setSchema(List<URL> schemaFiles)
Pass in a list of schemas to validate against.- Parameters:
schemaFiles
- A list of schema URLs.
-
setSchematrons
public void setSchematrons(List<String> schematrons)
Pass in a list of transformed schematrons to validate against.- Parameters:
schematrons
- A list of transformed schematrons.
-
clear
public void clear() throws ParserConfigurationException, TransformerConfigurationException
-
setLabelSchematrons
public void setLabelSchematrons(Map<String,String> schematronMap)
Pass in a hash map of schematron URLs to its transformed schematron object. This is used when validating a label against it's referenced schematron.- Parameters:
schematronMap
-
-
setSchematronFiles
public void setSchematronFiles(List<URL> schematronFiles)
Pass in a list of schematron files to validate against.- Parameters:
schematronFiles
- A list of schematron URLs.
-
setCatalogs
public void setCatalogs(String[] catalogFiles)
Pass in a list of Catalog files to use during the validation step.- Parameters:
catalogFiles
-
-
getCatalogResolver
public XMLCatalogResolver getCatalogResolver()
-
validate
public void validate(ProblemHandler handler, File labelFile) throws SAXException, IOException, ParserConfigurationException, TransformerException, MissingLabelSchemaException
-
validate
public void validate(ProblemHandler handler, URL url) throws SAXException, IOException, ParserConfigurationException, TransformerException, MissingLabelSchemaException
Validates the label against schema and schematron constraints.- Parameters:
handler
- a handler to receive errors during the validationurl
- label to validate- Throws:
SAXException
- if there are parsing exceptionsIOException
- if there are I/O errors during the parseParserConfigurationException
- if the parser configuration is invalidTransformerException
- if there is an error during Schematron transformationMissingLabelSchemaException
- if the label schema cannot be found
-
validate
public void validate(ProblemHandler handler, URL url, String labelExtension) throws SAXException, IOException, ParserConfigurationException, TransformerException, MissingLabelSchemaException
-
parseAndValidate
public Document parseAndValidate(ProblemHandler handler, URL url) throws SAXException, IOException, ParserConfigurationException, TransformerException, MissingLabelSchemaException
Parses and validates a label against the schema and Schematron files, and returns the parsed XML.- Parameters:
handler
- an problem handler to receive errors during the validationurl
- the URL of the label to validate- Returns:
- the XML document represented by the label
- Throws:
SAXException
- if there are parsing exceptionsIOException
- if there are I/O errors during the parseParserConfigurationException
- if the parser configuration is invalidTransformerException
- if there is an error during Schematron transformationMissingLabelSchemaException
- if the label schema cannot be found
-
validate
public void validate(File labelFile) throws SAXException, IOException, ParserConfigurationException, TransformerException, MissingLabelSchemaException
-
getSchematrons
public List<String> getSchematrons(NodeList nodeList, URL url, ProblemHandler handler)
-
performsSchemaValidation
public Boolean performsSchemaValidation()
-
setSchemaCheck
public void setSchemaCheck(Boolean value)
-
performsSchematronValidation
public Boolean performsSchematronValidation()
-
setSchematronCheck
public void setSchematronCheck(Boolean value)
-
setSkipProductValidation
public void setSkipProductValidation(Boolean flag)
-
addValidator
public void addValidator(ExternalValidator validator)
-
addValidator
public void addValidator(DocumentValidator validator)
-
setCachedEntityResolver
public void setCachedEntityResolver(CachedEntityResolver resolver)
-
setCachedLSResourceResolver
public void setCachedLSResourceResolver(CachedLSResourceResolver resolver)
-
-