From b773dda43e24a083f6194966171ee9491a1349e0 Mon Sep 17 00:00:00 2001 From: ltheussl Date: Tue, 20 Sep 2005 04:44:28 +0000 Subject: [PATCH] Add new tag validate-xml git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@290354 13f79535-47bb-0310-9956-ffa450edef68 --- plugin/plugin.jelly | 13 +- plugin/project.xml | 33 +++++ .../main/org/apache/maven/JaxpMsvBean.java | 136 ++++++++++++++++++ plugin/xdocs/changes.xml | 1 + plugin/xdocs/goals.xml | 2 +- plugin/xdocs/tags.xml | 21 ++- 6 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 plugin/src/main/org/apache/maven/JaxpMsvBean.java diff --git a/plugin/plugin.jelly b/plugin/plugin.jelly index 7c030531..245091ef 100644 --- a/plugin/plugin.jelly +++ b/plugin/plugin.jelly @@ -31,6 +31,15 @@ xmlns:assert="assert"> + + + + + + @@ -55,8 +64,8 @@ - - + + diff --git a/plugin/project.xml b/plugin/project.xml index 8334b79b..5a9c9d1f 100644 --- a/plugin/project.xml +++ b/plugin/project.xml @@ -115,6 +115,14 @@ Developer + + Lukas Theussl + ltheussl + ltheussl@apache.org + + Developer + + @@ -134,6 +142,11 @@ commons-jelly-tags-interaction 1.0 + + commons-logging + commons-logging + 1.0.3 + jdom jdom @@ -160,5 +173,25 @@ 2.4.0 http://xml.apache.org/xerces2-j/ + + msv + msv + 20050913 + + + msv + isorelax + 20050913 + + + msv + relaxngDatatype + 20050913 + + + msv + xsdlib + 20050913 + diff --git a/plugin/src/main/org/apache/maven/JaxpMsvBean.java b/plugin/src/main/org/apache/maven/JaxpMsvBean.java new file mode 100644 index 00000000..8776d6e8 --- /dev/null +++ b/plugin/src/main/org/apache/maven/JaxpMsvBean.java @@ -0,0 +1,136 @@ +package org.apache.maven; + +/* ==================================================================== + * Copyright 2001-2005 The Apache Software Foundation. + * + * 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. + * ==================================================================== + */ + + +import com.sun.msv.verifier.jaxp.SAXParserFactoryImpl; + +import java.io.File; + +import javax.xml.parsers.*; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.xml.sax.helpers.DefaultHandler; +import org.xml.sax.SAXParseException; +import org.xml.sax.SAXException; + + +/** + * JaxpMsvBean Bean: Uses JAXP implementation of MSV. + * + * @author Lukas Theussl + */ +public class JaxpMsvBean +{ + //~ Instance fields ------------------------------------------------------ + + /** The schema to use. */ + private String schema; + + /** The file to validate. */ + private String file; + + /** For debug output. */ + private Log log = LogFactory.getLog(JaxpMsvBean.class); + + + //~ Methods -------------------------------------------------------------- + + /** + * Performs validation. + */ + public void validate() throws Exception + { + SAXParserFactory factory = + new SAXParserFactoryImpl(new File(schema)); + factory.setNamespaceAware(true); + SAXParser parser = factory.newSAXParser(); + parser.parse(new File(file), new DefaultHandler() + { + boolean isValid = true; + public void warning(SAXParseException e) throws SAXException + { + log.warn(e); + } + public void error(SAXParseException e) throws SAXException + { + log.error(e); + isValid = false; + } + public void fatalError(SAXParseException e) throws SAXException + { + log.error(e); + isValid = false; + } + public void endDocument() + { + if(isValid) + { + log.info(file + " verified: OK"); + } else { + log.info("WARNING: " + file + " is NOT valid"); + } + } + }); + } + + /** + * Sets the schema. + * + * @param newSchema The schema to set + */ + public void setSchema(String newSchema) + { + this.schema = newSchema; + } + + /** + * Sets the file. + * + * @param newFile The file to set + */ + public void setFile(String newFile) + { + this.file = newFile; + } + + /** + * Gets the schema. + * + * @return The schema + */ + public String getSchema() + { + return schema; + } + + /** + * Gets the file. + * + * @return The file + */ + public String getFile() + { + return file; + } + + + +} diff --git a/plugin/xdocs/changes.xml b/plugin/xdocs/changes.xml index 82d85766..e0e8b07e 100644 --- a/plugin/xdocs/changes.xml +++ b/plugin/xdocs/changes.xml @@ -24,6 +24,7 @@ + new plugin:validate-xml tag to validate xml documents against a schema. new assert:assertPluginAvailable tag to check if a minimal release of a plugin is present. diff --git a/plugin/xdocs/goals.xml b/plugin/xdocs/goals.xml index 49515c47..d348c0ab 100644 --- a/plugin/xdocs/goals.xml +++ b/plugin/xdocs/goals.xml @@ -27,7 +27,7 @@ plugin - Build and install a plugin + Build a plugin jar plugin:download diff --git a/plugin/xdocs/tags.xml b/plugin/xdocs/tags.xml index 6049e8c2..f3858a5a 100644 --- a/plugin/xdocs/tags.xml +++ b/plugin/xdocs/tags.xml @@ -31,6 +31,7 @@
  1. uninstall
  2. clearCache
  3. +
  4. validate-xml
  • assert @@ -39,7 +40,7 @@
  • assertFileContains
  • assertFileNotFound
  • assertEquals
  • -
  • available
  • +
  • assertPluginAvailable
  • @@ -71,6 +72,24 @@

    There are no attributes for this tag

    + +

    + A tag to validate an arbitrary xml document against a schema. +

    + + + + + + + + + + + + +
    AttributeOptional?Description
    schemaNoThe schema file to use.
    fileNoThe file to validate.
    +