All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.helger.schematron.ISchematronResource Maven / Gradle / Ivy

There is a newer version: 5.6.5
Show newest version
/**
 * Copyright (C) 2014-2017 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.oclc.purl.dsdl.svrl.SchematronOutputType;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

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.SVRLReader;

/**
 * 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 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.
   * @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) 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 SVRLReader#readXML(org.w3c.dom.Node) 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.
   * @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 SVRLReader#readXML(org.w3c.dom.Node) on how to convert the document
   *      into a domain object
   */
  @Nullable
  Document applySchematronValidation (@Nonnull Node aXMLNode) 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 SVRLReader#readXML(org.w3c.dom.Node) 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.
   * @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) 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