com.helger.schematron.ISchematronResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ph-schematron Show documentation
Show all versions of ph-schematron Show documentation
Library for validating XML documents with Schematron
/**
* Copyright (C) 2014-2020 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.schematron;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.xml.transform.Source;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.EntityResolver;
import com.helger.commons.id.IHasID;
import com.helger.commons.io.IHasInputStream;
import com.helger.commons.io.resource.IReadableResource;
import com.helger.commons.state.EValidity;
import com.helger.schematron.svrl.jaxb.SchematronOutputType;
/**
* Base interface for a Schematron resource. The implementation can e.g. be a
* SCH file that needs preprocessing to XSLT or an already precompiled XSLT
* file.
*
* @author Philip Helger
*/
public interface ISchematronResource extends IHasID
{
/**
* @return The non-null
resource from which to read the
* Schematron rules.
*/
@Nonnull
IReadableResource getResource ();
/**
* @return true
to use caching, if applicable.
* @since 5.0.2 in this interface
*/
boolean isUseCache ();
/**
* Enable or disable caching.
*
* @param bUseCache
* true
to use the cache, false
to not use
* it.
* @since 5.0.2 in this interface
*/
void setUseCache (boolean bUseCache);
/**
* This is currently only supported for the "pure Schematron".
*
* @return true
if 'old' schematron NS is tolerated,
* false
if not. Default is false
.
* @since 5.4.1
*/
boolean isLenient ();
/**
* This is currently only supported for the "pure Schematron". Allow use of
* 'old' schematron NS.
*
* @param bLenient
* true
if 'old' schematron NS is tolerated,
* false
if not.
* @since 5.4.1
*/
void setLenient (boolean bLenient);
/**
* @return The XML entity resolver to be used to read the Schematron or XML to
* be validated. May be null
.
* @since 4.1.1 in implementation
* @since 5.0.2 in this interface
*/
@Nullable
EntityResolver getEntityResolver ();
/**
* @return true
if this Schematron can be used to validate XML
* instances. If not, the Schematron is invalid and the log files must
* be investigated.
*/
boolean isValidSchematron ();
/**
* 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).
*
* @param aXMLResource
* The source XML to read and validate against the Schematron. May not
* be null
.
* @return {@link EValidity#VALID} if the document is valid,
* {@link EValidity#INVALID} if it is invalid.
* @throws Exception
* in case of a sever error validating the schema
*/
@Nonnull
EValidity getSchematronValidity (@Nonnull IHasInputStream aXMLResource) throws Exception;
/**
* A method to check if the passed 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).
*
* @param aXMLNode
* The source DOM node to validate against the Schematron. May not be
* null
.
* @param sBaseURI
* The Base URI of the XML document to be validated. May be
* null
.
* @return {@link EValidity#VALID} if the document is valid,
* {@link EValidity#INVALID} if it is invalid.
* @throws Exception
* in case of a sever error validating the schema
*/
@Nonnull
EValidity getSchematronValidity (@Nonnull Node aXMLNode, @Nullable String sBaseURI) throws Exception;
/**
* 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).
*
* @param aXMLSource
* The source XML to be validated against the Schematron. May not be
* null
.
* @return {@link EValidity#VALID} if the document is valid,
* {@link EValidity#INVALID} if it is invalid.
* @throws Exception
* in case of a sever error validating the schema
*/
@Nonnull
EValidity getSchematronValidity (@Nonnull Source aXMLSource) throws Exception;
/**
* Apply the Schematron validation on the passed XML resource and return an
* SVRL XML DOM Document.
*
* @param aXMLResource
* The XML resource to be validated via Schematron. May not be
* null
.
* @return 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 com.helger.schematron.svrl.SVRLMarshaller on how to convert the
* document into a domain object
*/
@Nullable
Document applySchematronValidation (@Nonnull IHasInputStream aXMLResource) throws Exception;
/**
* Apply the Schematron validation on the passed DOM node and return an SVRL
* XML DOM Document.
*
* @param aXMLNode
* The DOM node to be validated via Schematron. May not be
* null
.
* @param sBaseURI
* The Base URI of the XML document to be validated. May be
* null
.
* @return 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 com.helger.schematron.svrl.SVRLMarshaller on how to convert the
* document into a domain object
*/
@Nullable
Document applySchematronValidation (@Nonnull Node aXMLNode, @Nullable String sBaseURI) throws Exception;
/**
* Apply the Schematron validation on the passed XML source and return an SVRL
* XML DOM Document.
*
* @param aXMLSource
* The XML source to be validated via Schematron. May not be
* null
.
* @return 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 com.helger.schematron.svrl.SVRLMarshaller on how to convert the
* document into a domain object
*/
@Nullable
Document applySchematronValidation (@Nonnull Source aXMLSource) throws Exception;
/**
* Apply the Schematron validation on the passed XML resource and return a
* {@link SchematronOutputType} object.
*
* @param aXMLResource
* The XML resource to be validated via Schematron. May not be
* null
.
* @return The SVRL object containing the result. May be null
* when interpreting the Schematron failed.
* @throws Exception
* In case the transformation somehow goes wrong.
*/
@Nullable
SchematronOutputType applySchematronValidationToSVRL (@Nonnull IHasInputStream aXMLResource) throws Exception;
/**
* Apply the Schematron validation on the passed DOM Node and return a
* {@link SchematronOutputType} object.
*
* @param aXMLNode
* The DOM node to be validated via Schematron. May not be
* null
.
* @param sBaseURI
* The Base URI of the XML document to be validated. May be
* null
.
* @return The SVRL object containing the result. May be null
* when interpreting the Schematron failed.
* @throws Exception
* In case the transformation somehow goes wrong.
*/
@Nullable
SchematronOutputType applySchematronValidationToSVRL (@Nonnull Node aXMLNode, @Nullable String sBaseURI) throws Exception;
/**
* Apply the Schematron validation on the passed XML source and return a
* {@link SchematronOutputType} object.
*
* @param aXMLSource
* The XML source to be validated via Schematron. May not be
* null
.
* @return The SVRL object containing the result. May be null
* when interpreting the Schematron failed.
* @throws Exception
* In case the transformation somehow goes wrong.
*/
@Nullable
SchematronOutputType applySchematronValidationToSVRL (@Nonnull Source aXMLSource) throws Exception;
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy