You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by lt...@apache.org on 2005/09/20 06:44:31 UTC

svn commit: r290354 - in /maven/maven-1/plugins/trunk/plugin: plugin.jelly project.xml src/main/org/apache/maven/JaxpMsvBean.java xdocs/changes.xml xdocs/goals.xml xdocs/tags.xml

Author: ltheussl
Date: Mon Sep 19 21:44:28 2005
New Revision: 290354

URL: http://svn.apache.org/viewcvs?rev=290354&view=rev
Log:
Add new tag validate-xml

Added:
    maven/maven-1/plugins/trunk/plugin/src/main/org/apache/maven/JaxpMsvBean.java
Modified:
    maven/maven-1/plugins/trunk/plugin/plugin.jelly
    maven/maven-1/plugins/trunk/plugin/project.xml
    maven/maven-1/plugins/trunk/plugin/xdocs/changes.xml
    maven/maven-1/plugins/trunk/plugin/xdocs/goals.xml
    maven/maven-1/plugins/trunk/plugin/xdocs/tags.xml

Modified: maven/maven-1/plugins/trunk/plugin/plugin.jelly
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/plugin/plugin.jelly?rev=290354&r1=290353&r2=290354&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/plugin/plugin.jelly (original)
+++ maven/maven-1/plugins/trunk/plugin/plugin.jelly Mon Sep 19 21:44:28 2005
@@ -31,6 +31,15 @@
   xmlns:assert="assert">
 
   <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">
       <ant:delete verbose="false" failonerror="false">
         <ant:fileset dir="${maven.plugin.dir}">
@@ -55,8 +64,8 @@
           <ant:include name="**/.processed" />
         </ant:fileset>
       </ant:delete>
-    </define:tag>    
-    
+    </define:tag>
+
   </define:taglib>
     
   <define:taglib uri="assert">

Modified: maven/maven-1/plugins/trunk/plugin/project.xml
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/plugin/project.xml?rev=290354&r1=290353&r2=290354&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/plugin/project.xml (original)
+++ maven/maven-1/plugins/trunk/plugin/project.xml Mon Sep 19 21:44:28 2005
@@ -115,6 +115,14 @@
         <role>Developer</role>
       </roles>
     </developer>
+    <developer>
+      <name>Lukas Theussl</name>
+      <id>ltheussl</id>
+      <email>ltheussl@apache.org</email>
+      <roles>
+        <role>Developer</role>
+      </roles>
+    </developer>
   </developers>
   <dependencies>
     <dependency>
@@ -135,6 +143,11 @@
       <version>1.0</version>
     </dependency>
     <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.0.3</version>
+    </dependency>
+    <dependency>
       <groupId>jdom</groupId>
       <artifactId>jdom</artifactId>
       <version>b10</version>
@@ -159,6 +172,26 @@
       <id>xerces</id>
       <version>2.4.0</version>
       <url>http://xml.apache.org/xerces2-j/</url>
+    </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>
 </project>

Added: maven/maven-1/plugins/trunk/plugin/src/main/org/apache/maven/JaxpMsvBean.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/plugin/src/main/org/apache/maven/JaxpMsvBean.java?rev=290354&view=auto
==============================================================================
--- maven/maven-1/plugins/trunk/plugin/src/main/org/apache/maven/JaxpMsvBean.java (added)
+++ maven/maven-1/plugins/trunk/plugin/src/main/org/apache/maven/JaxpMsvBean.java Mon Sep 19 21:44:28 2005
@@ -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;
+    }
+
+  
+
+}

Modified: maven/maven-1/plugins/trunk/plugin/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/plugin/xdocs/changes.xml?rev=290354&r1=290353&r2=290354&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/plugin/xdocs/changes.xml (original)
+++ maven/maven-1/plugins/trunk/plugin/xdocs/changes.xml Mon Sep 19 21:44:28 2005
@@ -24,6 +24,7 @@
   </properties>
   <body>
     <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>
     </release>
     <release version="1.6" date="2005-06-03">

Modified: maven/maven-1/plugins/trunk/plugin/xdocs/goals.xml
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/plugin/xdocs/goals.xml?rev=290354&r1=290353&r2=290354&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/plugin/xdocs/goals.xml (original)
+++ maven/maven-1/plugins/trunk/plugin/xdocs/goals.xml Mon Sep 19 21:44:28 2005
@@ -27,7 +27,7 @@
     <goals>
       <goal>
         <name>plugin</name>
-        <description>Build and install a plugin</description>
+        <description>Build a plugin jar</description>
       </goal>
       <goal>
         <name>plugin:download</name>

Modified: maven/maven-1/plugins/trunk/plugin/xdocs/tags.xml
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/plugin/xdocs/tags.xml?rev=290354&r1=290353&r2=290354&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/plugin/xdocs/tags.xml (original)
+++ maven/maven-1/plugins/trunk/plugin/xdocs/tags.xml Mon Sep 19 21:44:28 2005
@@ -31,6 +31,7 @@
           <ol>
             <li><a href='#uninstall_Tag'>uninstall</a></li>
             <li><a href='#clearCache_Tag'>clearCache</a></li>
+            <li><a href='#validate-xml_Tag'>validate-xml</a></li>
           </ol>
         </li>
         <li><a href='#assert_Tag_Library'>assert</a>
@@ -39,7 +40,7 @@
             <li><a href='#assertFileContains_Tag'>assertFileContains</a></li>
             <li><a href='#assertFileNotFound_Tag'>assertFileNotFound</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>
         </li>
       </ol>
@@ -70,6 +71,24 @@
           tag libraries from <code>${maven.plugin.unpacked.dir}</code>
         </p>
         <p>There are no attributes for this tag</p>
+      </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 name='assert Tag Library'>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org