Package com.helger.schematron
Class AbstractSchematronResource
- java.lang.Object
-
- com.helger.schematron.AbstractSchematronResource
-
- All Implemented Interfaces:
com.helger.commons.id.IHasID<String>
,ISchematronResource
- Direct Known Subclasses:
AbstractSchematronXSLTBasedResource
@NotThreadSafe public abstract class AbstractSchematronResource extends Object implements ISchematronResource
Abstract implementation of theISchematronResource
interface handling the underlying resource and wrapping one method.- Author:
- Philip Helger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractSchematronResource.NodeAndBaseURI
Helper class to handle DOM Document and base URI for reference
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_USE_CACHE
-
Constructor Summary
Constructors Constructor Description AbstractSchematronResource(com.helger.commons.io.resource.IReadableResource aResource)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Document
applySchematronValidation(com.helger.commons.io.IHasInputStream aXMLResource)
Apply the Schematron validation on the passed XML resource and return an SVRL XML DOM Document.Document
applySchematronValidation(Source aXMLSource)
Apply the Schematron validation on the passed XML source and return an SVRL XML DOM Document.SchematronOutputType
applySchematronValidationToSVRL(com.helger.commons.io.IHasInputStream aXMLResource)
Apply the Schematron validation on the passed XML resource and return aSchematronOutputType
object.SchematronOutputType
applySchematronValidationToSVRL(Source aXMLSource)
Apply the Schematron validation on the passed XML source and return aSchematronOutputType
object.protected AbstractSchematronResource.NodeAndBaseURI
getAsNode(com.helger.commons.io.IHasInputStream aXMLResource)
protected Node
getAsNode(Source aXMLSource)
EntityResolver
getEntityResolver()
String
getID()
com.helger.commons.io.resource.IReadableResource
getResource()
com.helger.commons.state.EValidity
getSchematronValidity(com.helger.commons.io.IHasInputStream aXMLResource)
A method to check if the passed XML DOM node matches the Schematron rules or not.com.helger.commons.state.EValidity
getSchematronValidity(Source aXMLSource)
A method to check if the passed XML DOM node matches the Schematron rules or not.protected com.helger.xml.serialize.read.DOMReaderSettings
internalCreateDOMReaderSettings()
protected void
internalSetEntityResolver(EntityResolver aEntityResolver)
Set the XML entity resolver to be used when reading the Schematron or the XML to be validated.boolean
isLenient()
This is currently only supported for the "pure Schematron".boolean
isUseCache()
void
setLenient(boolean bLenient)
This is currently only supported for the "pure Schematron".void
setUseCache(boolean bUseCache)
Enable or disable caching.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.schematron.ISchematronResource
applySchematronValidation, applySchematronValidationToSVRL, getSchematronValidity, isValidSchematron
-
-
-
-
Field Detail
-
DEFAULT_USE_CACHE
public static final boolean DEFAULT_USE_CACHE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractSchematronResource
public AbstractSchematronResource(@Nonnull com.helger.commons.io.resource.IReadableResource aResource)
Constructor- Parameters:
aResource
- The Schematron resource. May not benull
.
-
-
Method Detail
-
getID
@Nonnull public final String getID()
- Specified by:
getID
in interfacecom.helger.commons.id.IHasID<String>
-
getResource
@Nonnull public final com.helger.commons.io.resource.IReadableResource getResource()
- Specified by:
getResource
in interfaceISchematronResource
- Returns:
- The non-
null
resource from which to read the Schematron rules.
-
isUseCache
public final boolean isUseCache()
- Specified by:
isUseCache
in interfaceISchematronResource
- Returns:
true
to use caching, if applicable.
-
setUseCache
public final void setUseCache(boolean bUseCache)
Description copied from interface:ISchematronResource
Enable or disable caching.- Specified by:
setUseCache
in interfaceISchematronResource
- Parameters:
bUseCache
-true
to use the cache,false
to not use it.
-
isLenient
public final boolean isLenient()
Description copied from interface:ISchematronResource
This is currently only supported for the "pure Schematron".- Specified by:
isLenient
in interfaceISchematronResource
- Returns:
true
if 'old' schematron NS is tolerated,false
if not. Default isfalse
.
-
setLenient
public final void setLenient(boolean bLenient)
Description copied from interface:ISchematronResource
This is currently only supported for the "pure Schematron". Allow use of 'old' schematron NS.- Specified by:
setLenient
in interfaceISchematronResource
- Parameters:
bLenient
-true
if 'old' schematron NS is tolerated,false
if not.
-
getEntityResolver
@Nullable public final EntityResolver getEntityResolver()
- Specified by:
getEntityResolver
in interfaceISchematronResource
- Returns:
- The XML entity resolver to be used to read the Schematron or XML to
be validated. May be
null
.
-
internalSetEntityResolver
protected final void internalSetEntityResolver(@Nullable EntityResolver aEntityResolver)
Set the XML entity resolver to be used when reading the Schematron or the XML to be validated. This can only be set before the Schematron is bound. If it is already bound an exception is thrown to indicate the unnecessity of the call.- Parameters:
aEntityResolver
- The entity resolver to set. May benull
.- Since:
- 4.2.3
-
internalCreateDOMReaderSettings
@Nonnull @ReturnsMutableCopy protected com.helger.xml.serialize.read.DOMReaderSettings internalCreateDOMReaderSettings()
- Returns:
- The
DOMReaderSettings
to be used for reading the XML files to be validated. This includes theEntityResolver
to be used. - See Also:
getEntityResolver()
-
getAsNode
@Nullable @OverrideOnDemand protected AbstractSchematronResource.NodeAndBaseURI getAsNode(@Nonnull com.helger.commons.io.IHasInputStream aXMLResource) throws Exception
- Throws:
Exception
-
getAsNode
@Nullable @OverrideOnDemand protected Node getAsNode(@Nonnull Source aXMLSource) throws Exception
- Throws:
Exception
-
getSchematronValidity
@Nonnull public com.helger.commons.state.EValidity getSchematronValidity(@Nonnull com.helger.commons.io.IHasInputStream aXMLResource) throws Exception
Description copied from interface:ISchematronResource
A method to check if the passed XML DOM node matches the Schematron rules or not. This is the quick check method, as it breaks upon the first failed assertion or the first successful report, if the implementation supports it (as e.g. the native pure Schematron version).- Specified by:
getSchematronValidity
in interfaceISchematronResource
- Parameters:
aXMLResource
- The source XML to read and validate against the Schematron. May not benull
.- Returns:
EValidity.VALID
if the document is valid,EValidity.INVALID
if it is invalid.- Throws:
Exception
- in case of a sever error validating the schema
-
getSchematronValidity
@Nonnull public com.helger.commons.state.EValidity getSchematronValidity(@Nonnull Source aXMLSource) throws Exception
Description copied from interface:ISchematronResource
A method to check if the passed XML DOM node matches the Schematron rules or not. This is the quick check method, as it breaks upon the first failed assertion or the first successful report, if the implementation supports it (as e.g. the native pure Schematron version).- Specified by:
getSchematronValidity
in interfaceISchematronResource
- Parameters:
aXMLSource
- The source XML to be validated against the Schematron. May not benull
.- Returns:
EValidity.VALID
if the document is valid,EValidity.INVALID
if it is invalid.- Throws:
Exception
- in case of a sever error validating the schema
-
applySchematronValidation
@Nullable public Document applySchematronValidation(@Nonnull com.helger.commons.io.IHasInputStream aXMLResource) throws Exception
Description copied from interface:ISchematronResource
Apply the Schematron validation on the passed XML resource and return an SVRL XML DOM Document.- Specified by:
applySchematronValidation
in interfaceISchematronResource
- Parameters:
aXMLResource
- The XML resource to be validated via Schematron. May not benull
.- Returns:
null
if the passed resource does not exist or the non-null
SVRL document otherwise.- Throws:
Exception
- In case the transformation somehow goes wrong.- See Also:
on how to convert the document into a domain object
-
applySchematronValidation
@Nullable public Document applySchematronValidation(@Nonnull Source aXMLSource) throws Exception
Description copied from interface:ISchematronResource
Apply the Schematron validation on the passed XML source and return an SVRL XML DOM Document.- Specified by:
applySchematronValidation
in interfaceISchematronResource
- Parameters:
aXMLSource
- The XML source to be validated via Schematron. May not benull
.- Returns:
- The SVRL XML document containing the result. May be
null
when interpreting the Schematron failed. - Throws:
Exception
- In case the transformation somehow goes wrong.- See Also:
on how to convert the document into a domain object
-
applySchematronValidationToSVRL
@Nullable public SchematronOutputType applySchematronValidationToSVRL(@Nonnull com.helger.commons.io.IHasInputStream aXMLResource) throws Exception
Description copied from interface:ISchematronResource
Apply the Schematron validation on the passed XML resource and return aSchematronOutputType
object.- Specified by:
applySchematronValidationToSVRL
in interfaceISchematronResource
- Parameters:
aXMLResource
- The XML resource to be validated via Schematron. May not benull
.- Returns:
- The SVRL object containing the result. May be
null
when interpreting the Schematron failed. - Throws:
Exception
- In case the transformation somehow goes wrong.
-
applySchematronValidationToSVRL
@Nullable public SchematronOutputType applySchematronValidationToSVRL(@Nonnull Source aXMLSource) throws Exception
Description copied from interface:ISchematronResource
Apply the Schematron validation on the passed XML source and return aSchematronOutputType
object.- Specified by:
applySchematronValidationToSVRL
in interfaceISchematronResource
- Parameters:
aXMLSource
- The XML source to be validated via Schematron. May not benull
.- Returns:
- The SVRL object containing the result. May be
null
when interpreting the Schematron failed. - Throws:
Exception
- In case the transformation somehow goes wrong.
-
-