View Javadoc
1   /**
2    * Copyright (C) 2014-2018 Philip Helger (www.helger.com)
3    * philip[at]helger[dot]com
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *         http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package com.helger.schematron.pure.bound;
18  
19  import javax.annotation.Nonnull;
20  import javax.annotation.Nullable;
21  
22  import org.oclc.purl.dsdl.svrl.SchematronOutputType;
23  import org.w3c.dom.Node;
24  
25  import com.helger.commons.annotation.ReturnsMutableCopy;
26  import com.helger.commons.collection.impl.ICommonsList;
27  import com.helger.commons.state.EValidity;
28  import com.helger.schematron.CSchematron;
29  import com.helger.schematron.pure.binding.IPSQueryBinding;
30  import com.helger.schematron.pure.model.PSPattern;
31  import com.helger.schematron.pure.model.PSPhase;
32  import com.helger.schematron.pure.model.PSSchema;
33  import com.helger.schematron.pure.validation.IPSValidationHandler;
34  import com.helger.schematron.pure.validation.SchematronValidationException;
35  import com.helger.xml.namespace.MapBasedNamespaceContext;
36  
37  /**
38   * Base interface for a bound schema. A bound schema is a {@link PSSchema} with
39   * a specific
40   *
41   * @author Philip Helger
42   */
43  public interface IPSBoundSchema
44  {
45    /**
46     * @return The query binding that was used to create this bound schema.
47     */
48    @Nonnull
49    IPSQueryBinding getQueryBinding ();
50  
51    /**
52     * @return The original schema used to bind. Never <code>null</code>.
53     */
54    @Nonnull
55    PSSchema getOriginalSchema ();
56  
57    /**
58     * @return The namespace context as defined by the namespaces in the original
59     *         schema. Never <code>null</code>.
60     */
61    @Nonnull
62    MapBasedNamespaceContext getNamespaceContext ();
63  
64    /**
65     * @return Get the phase ID used. If none was specified, the schema
66     *         defaultPhase is used. If this is not present, than all patterns are
67     *         used and ID of the phase is {@link CSchematron#PHASE_ALL}.
68     */
69    @Nonnull
70    String getPhaseID ();
71  
72    /**
73     * @return The phase object to be evaluated. May be <code>null</code> if no
74     *         specific phase is to be validated!
75     */
76    @Nullable
77    PSPhase getPhase ();
78  
79    /**
80     * @return <code>true</code> if a special phase was specified,
81     *         <code>false</code> if not.
82     */
83    boolean isPhaseSpecified ();
84  
85    /**
86     * @return A list of all patterns to be validated. If a phase was selected,
87     *         only the patterns matching the selected phase are contained. Never
88     *         <code>null</code>.
89     */
90    @Nonnull
91    @ReturnsMutableCopy
92    ICommonsList <PSPattern> getAllRelevantPatterns ();
93  
94    /**
95     * Get the validation context to be used. As rules can be stated as "element"
96     * they are not necessarily present on root level. For XPath this may e.g. be
97     * resolved by prepending "//" so that all elements are resolved correctly.
98     *
99     * @param sRuleContext
100    *        The original rule context. May not be <code>null</code>.
101    * @return The real validation context to use.
102    */
103   @Nonnull
104   String getValidationContext (@Nonnull String sRuleContext);
105 
106   /**
107    * The generic validation method. It validates the passed XML node to this
108    * bound schema.
109    *
110    * @param aNode
111    *        The node to be validated. May not be <code>null</code>.
112    * @param sBaseURI
113    *        Base URI of the XML to be validated. May be <code>null</code>.
114    * @param aHandler
115    *        The validation handler that receives the callback informations. May
116    *        not be <code>null</code>.
117    * @throws SchematronValidationException
118    *         In case a validation exception occurs
119    */
120   void validate (@Nonnull Node aNode,
121                  @Nullable String sBaseURI,
122                  @Nonnull IPSValidationHandler aHandler) throws SchematronValidationException;
123 
124   /**
125    * Special validation that breaks on the first error. This is a specialized
126    * call of {@link #validate(Node, String, IPSValidationHandler)}.
127    *
128    * @param aNode
129    *        The XML node to be validated. May not be <code>null</code>.
130    * @param sBaseURI
131    *        Base URI of the XML to be validated. May be <code>null</code>.
132    * @return {@link EValidity#VALID} if the document is valid,
133    *         {@link EValidity#INVALID} if it is invalid.
134    * @throws SchematronValidationException
135    *         In case a validation exception occurs
136    */
137   @Nonnull
138   EValidity validatePartially (@Nonnull Node aNode, @Nullable String sBaseURI) throws SchematronValidationException;
139 
140   /**
141    * Special validation that creates an SVRL document. This is a specialized
142    * call of {@link #validate(Node, String, IPSValidationHandler)}.
143    *
144    * @param aNode
145    *        The XML node to be validated. May not be <code>null</code>.
146    * @param sBaseURI
147    *        Base URI of the XML to be validated. May be <code>null</code>.
148    * @return The SVRL domain object.
149    * @throws SchematronValidationException
150    *         In case a validation exception occurs
151    */
152   @Nonnull
153   SchematronOutputType validateComplete (@Nonnull Node aNode,
154                                          @Nullable String sBaseURI) throws SchematronValidationException;
155 }