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
This commit is contained in:
parent
c587f48e09
commit
b773dda43e
@ -31,6 +31,15 @@
|
|||||||
xmlns:assert="assert">
|
xmlns:assert="assert">
|
||||||
|
|
||||||
<define:taglib uri="plugin">
|
<define:taglib uri="plugin">
|
||||||
|
|
||||||
|
<define:jellybean
|
||||||
|
name="validate-xml"
|
||||||
|
className="org.apache.maven.JaxpMsvBean"
|
||||||
|
method="validate">
|
||||||
|
<!-- @schema : The schema to validate against (full path) -->
|
||||||
|
<!-- @file : The file to be validated (full path) -->
|
||||||
|
</define:jellybean>
|
||||||
|
|
||||||
<define:tag name="uninstall">
|
<define:tag name="uninstall">
|
||||||
<ant:delete verbose="false" failonerror="false">
|
<ant:delete verbose="false" failonerror="false">
|
||||||
<ant:fileset dir="${maven.plugin.dir}">
|
<ant:fileset dir="${maven.plugin.dir}">
|
||||||
|
|||||||
@ -115,6 +115,14 @@
|
|||||||
<role>Developer</role>
|
<role>Developer</role>
|
||||||
</roles>
|
</roles>
|
||||||
</developer>
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<name>Lukas Theussl</name>
|
||||||
|
<id>ltheussl</id>
|
||||||
|
<email>ltheussl@apache.org</email>
|
||||||
|
<roles>
|
||||||
|
<role>Developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -134,6 +142,11 @@
|
|||||||
<artifactId>commons-jelly-tags-interaction</artifactId>
|
<artifactId>commons-jelly-tags-interaction</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
<version>1.0.3</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jdom</groupId>
|
<groupId>jdom</groupId>
|
||||||
<artifactId>jdom</artifactId>
|
<artifactId>jdom</artifactId>
|
||||||
@ -160,5 +173,25 @@
|
|||||||
<version>2.4.0</version>
|
<version>2.4.0</version>
|
||||||
<url>http://xml.apache.org/xerces2-j/</url>
|
<url>http://xml.apache.org/xerces2-j/</url>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>msv</groupId>
|
||||||
|
<artifactId>msv</artifactId>
|
||||||
|
<version>20050913</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>msv</groupId>
|
||||||
|
<artifactId>isorelax</artifactId>
|
||||||
|
<version>20050913</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>msv</groupId>
|
||||||
|
<artifactId>relaxngDatatype</artifactId>
|
||||||
|
<version>20050913</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>msv</groupId>
|
||||||
|
<artifactId>xsdlib</artifactId>
|
||||||
|
<version>20050913</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
136
plugin/src/main/org/apache/maven/JaxpMsvBean.java
Normal file
136
plugin/src/main/org/apache/maven/JaxpMsvBean.java
Normal file
@ -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 <a href="mailto:ltheussl@apache.org">Lukas Theussl</a>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -24,6 +24,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
<body>
|
<body>
|
||||||
<release version="1.7-SNAPSHOT" date="In SVN">
|
<release version="1.7-SNAPSHOT" date="In SVN">
|
||||||
|
<action dev="ltheussl" type="add">new plugin:validate-xml tag to validate xml documents against a schema.</action>
|
||||||
<action dev="aheritier" type="add">new assert:assertPluginAvailable tag to check if a minimal release of a plugin is present.</action>
|
<action dev="aheritier" type="add">new assert:assertPluginAvailable tag to check if a minimal release of a plugin is present.</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="1.6" date="2005-06-03">
|
<release version="1.6" date="2005-06-03">
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
<goals>
|
<goals>
|
||||||
<goal>
|
<goal>
|
||||||
<name>plugin</name>
|
<name>plugin</name>
|
||||||
<description>Build and install a plugin</description>
|
<description>Build a plugin jar</description>
|
||||||
</goal>
|
</goal>
|
||||||
<goal>
|
<goal>
|
||||||
<name>plugin:download</name>
|
<name>plugin:download</name>
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
<ol>
|
<ol>
|
||||||
<li><a href='#uninstall_Tag'>uninstall</a></li>
|
<li><a href='#uninstall_Tag'>uninstall</a></li>
|
||||||
<li><a href='#clearCache_Tag'>clearCache</a></li>
|
<li><a href='#clearCache_Tag'>clearCache</a></li>
|
||||||
|
<li><a href='#validate-xml_Tag'>validate-xml</a></li>
|
||||||
</ol>
|
</ol>
|
||||||
</li>
|
</li>
|
||||||
<li><a href='#assert_Tag_Library'>assert</a>
|
<li><a href='#assert_Tag_Library'>assert</a>
|
||||||
@ -39,7 +40,7 @@
|
|||||||
<li><a href='#assertFileContains_Tag'>assertFileContains</a></li>
|
<li><a href='#assertFileContains_Tag'>assertFileContains</a></li>
|
||||||
<li><a href='#assertFileNotFound_Tag'>assertFileNotFound</a></li>
|
<li><a href='#assertFileNotFound_Tag'>assertFileNotFound</a></li>
|
||||||
<li><a href='#assertEquals_Tag'>assertEquals</a></li>
|
<li><a href='#assertEquals_Tag'>assertEquals</a></li>
|
||||||
<li><a href='#assertPluginAvailable_Tag'>available</a></li>
|
<li><a href='#assertPluginAvailable_Tag'>assertPluginAvailable</a></li>
|
||||||
</ol>
|
</ol>
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
@ -71,6 +72,24 @@
|
|||||||
</p>
|
</p>
|
||||||
<p>There are no attributes for this tag</p>
|
<p>There are no attributes for this tag</p>
|
||||||
</subsection>
|
</subsection>
|
||||||
|
<subsection name='validate-xml Tag'>
|
||||||
|
<p>
|
||||||
|
A tag to validate an arbitrary xml document against a schema.
|
||||||
|
</p>
|
||||||
|
<table>
|
||||||
|
<tr><th>Attribute</th><th>Optional?</th><th>Description</th></tr>
|
||||||
|
<tr>
|
||||||
|
<td>schema</td>
|
||||||
|
<td>No</td>
|
||||||
|
<td>The schema file to use.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>file</td>
|
||||||
|
<td>No</td>
|
||||||
|
<td>The file to validate.</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</subsection>
|
||||||
</section>
|
</section>
|
||||||
<section name='assert Tag Library'>
|
<section name='assert Tag Library'>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user