From: <bo...@us...> - 2009-05-25 15:05:38
|
Revision: 333 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=333&view=rev Author: bodewig Date: 2009-05-25 15:05:35 +0000 (Mon, 25 May 2009) Log Message: ----------- validation infrastructure Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java 2009-05-25 15:05:35 UTC (rev 333) @@ -0,0 +1,50 @@ +/* + This file is licensed to You 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 net.sf.xmlunit.validation; + +import javax.xml.XMLConstants; + +/** + * Contants for the languages supported by XMLUnit's schema + * validation. More languages may be supported depending on your JAXP + * environment. + */ +public final class Languages { + private Languages() {} + + /** + * W3C XML Schema. + * + * @see javax.xml.XMLConstants#W3C_XML_SCHEMA_NS_URI + */ + public static final String W3C_XML_SCHEMA_NS_URI = + XMLConstants.W3C_XML_SCHEMA_NS_URI; + + /** + * DTD + * + * @see javax.xml.XMLConstants#XML_DTD_NS_URI + */ + public static final String XML_DTD_NS_URI = XMLConstants.XML_DTD_NS_URI; + + /** + * RELAX NG + * + * <p>This is most likely only supported if you use additional + * libraries and configure JAXP to use them.</p> + * + * @see javax.xml.XMLConstants#RELAXNG_NS_URI + */ + public static final String RELAXNG_NS_URI = XMLConstants.RELAXNG_NS_URI; +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Languages.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java 2009-05-25 15:05:35 UTC (rev 333) @@ -0,0 +1,63 @@ +/* + This file is licensed to You 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 net.sf.xmlunit.validation; + +/** + * A validation "problem" which may be an error or a warning. + */ +public class ValidationProblem { + public static enum ProblemType {ERROR, WARNING}; + + public static final int UNKNOWN = -1; + + private final int line, column; + private final ProblemType type; + private final String message; + + public ValidationProblem(String message, int line, int column, + ProblemType type) { + this.message = message; + this.line = line; + this.column = column; + this.type = type; + } + + /** + * The line where the problem occured or {@link #UNKNOWN UNKNOWN}. + */ + public int getLine() { + return line; + } + + /** + * The column where the problem occured or {@link #UNKNOWN UNKNOWN}. + */ + public int getColumn() { + return column; + } + + /** + * Whether this is an error or a warning. + */ + public ProblemType getType() { + return type; + } + + /** + * The problem's message. + */ + public String getMessage() { + return message; + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationProblem.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java 2009-05-25 15:05:35 UTC (rev 333) @@ -0,0 +1,41 @@ +/* + This file is licensed to You 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 net.sf.xmlunit.validation; + +/** + * The result of a validation. + */ +public class ValidationResult { + private final boolean valid; + private final Iterable<ValidationProblem> problems; + + public ValidationResult(boolean valid, Iterable<ValidationProblem> problems) { + this.valid = valid; + this.problems = problems; + } + + /** + * Has the validation been successful? + */ + public boolean isValid() { + return valid; + } + + /** + * Retrieves the problems that have been found. + */ + public Iterable<ValidationProblem> getProblems() { + return problems; + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/ValidationResult.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java 2009-05-25 15:05:35 UTC (rev 333) @@ -0,0 +1,83 @@ +/* + This file is licensed to You 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 net.sf.xmlunit.validation; + +import javax.xml.transform.Source; + +/** + * Validates a piece of XML against a schema given in a supported + * language or the defintion of such a schema itself. + */ +public abstract class Validator { + private String schemaURI; + private Source[] sourceLocations; + + /** + * The URI (or for example the System ID in case of a DTD) that + * identifies the schema to validate or use during validation. + */ + public void setSchemaURI(String uri) { + this.schemaURI = uri; + } + + protected String getSchemaURI() { + return schemaURI; + } + + /** + * Where to find the schema. + */ + public void setSchemaSources(Source[] s) { + if (s != null) { + sourceLocations = new Source[s.length]; + System.arraycopy(s, 0, sourceLocations, 0, s.length); + } else { + sourceLocations = null; + } + } + + /** + * Where to find the schema. + */ + public final void setSchemaSource(Source s) { + setSchemaSources(s == null ? null : new Source[] {s}); + } + + protected Source[] getSchemaSources() { + return sourceLocations; + } + + /** + * Validates a schema. + * + * @throws UnsupportedOperationException if the language's + * implementation doesn't support schema validation + */ + public abstract ValidationResult validateSchema(); + + /** + * Validates an instance against the schema. + */ + public abstract ValidationResult validateInstance(Source instance); + + + /** + * Factory that obtains a Validator instance based on the schema language. + * + * @see Languages + */ + public static Validator forLanguage(String language) { + return null; + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/validation/Validator.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |