diff --git a/contrib/examples/XInclude/NamespacesSAXParserFactoryImpl.java b/contrib/examples/XInclude/NamespacesSAXParserFactoryImpl.java new file mode 100644 index 000000000..6a6257722 --- /dev/null +++ b/contrib/examples/XInclude/NamespacesSAXParserFactoryImpl.java @@ -0,0 +1,21 @@ +package com.puppycrawl.tools.checkstyle; + +import org.apache.xerces.jaxp.SAXParserFactoryImpl; + +/** + * A parser factory that produces parsers that support XML namespaces. + * @author Rick Giles + * @version May 28, 2004 + */ +public class NamespacesSAXParserFactoryImpl extends SAXParserFactoryImpl +{ + /** + * Constructs a NamespacesSAXParserFactoryImpl. Initializes + * it to produce parsers that support XML namespaces. + */ + public NamespacesSAXParserFactoryImpl() + { + super(); + setNamespaceAware(true); + } +} diff --git a/contrib/examples/XInclude/config.xml b/contrib/examples/XInclude/config.xml new file mode 100644 index 000000000..06f65e33c --- /dev/null +++ b/contrib/examples/XInclude/config.xml @@ -0,0 +1,26 @@ + + + + + + + + + + +]> + + + + + diff --git a/contrib/examples/XInclude/index.html b/contrib/examples/XInclude/index.html new file mode 100644 index 000000000..581f5c511 --- /dev/null +++ b/contrib/examples/XInclude/index.html @@ -0,0 +1,142 @@ + + + + + + XInclude Processing + + + + +

XInclude Processing

+

Description

+

This is an example of how you can separate a Checkstyle configuration file +into several files and process the configuration using +XInclude processing. +This requires a SAX parser that supports XML namespaces. +First we give an example a SAX parser factory that produces parsers supporting XML namespaces +and indicate how to configure your system to use this factory. +Then we give an example XML configuration files with XInclude processing and +an ant target that uses the Checkstyle ant task +to check a Java source file with the configuration files. +

+

Parsers

+

SAX parser factory NamespacesSAXParserFactoryImpl +is an example of a factory that produces parsers +supporting XML namespaces: +

+package com.puppycrawl.tools.checkstyle;
+
+import org.apache.xerces.jaxp.SAXParserFactoryImpl;
+
+/**
+ * A parser factory that produces parsers that support XML namespaces. 
+ * @author Rick Giles
+ * @version May 28, 2004
+ */
+public class NamespacesSAXParserFactoryImpl extends SAXParserFactoryImpl
+{
+    /**
+     * Constructs a NamespacesSAXParserFactoryImpl. Initializes
+     * it to produce parsers that support XML namespaces. 
+     */
+    public NamespacesSAXParserFactoryImpl()
+    {
+        super();
+        setNamespaceAware(true);
+    }
+}
+
+

+

+In order to use NamespacesSAXParserFactoryImpl as the +SAX parser factory, place NamespacesSAXParserFactoryImpl +in the classpath and +configure your system +to load +NamespacesSAXParserFactoryImpl +as the SAXParserFactory. +For example, you can create a file called jaxp.properties +in the lib subdirectory of the JRE installation with contents +

+javax.xml.parsers.SAXParserFactory=com.puppycrawl.tools.checkstyle.NamespacesSAXParserFactoryImpl
+
+

+

+XInclude processing requires an XML parser that implements XML inclusions. +Here we use the Xerces parser +that is in the ant distribution. In order +to enable Xinclude processing, +you can change the parser configuration by creating a file called xerces.properties +in the lib subdirectory of the JRE installation with contents +

+org.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration
+
+

Checkstyle Configuration

+

+

The Checkstyle configuration of this example is in two files. +File config.xml has an internal DTD that supports +xi:include elements: +

+<?xml version="1.0"?>
+<!DOCTYPE module [
+<!ELEMENT module (module|property|xi:include)*>
+<!ATTLIST module name NMTOKEN #REQUIRED>
+
+<!ELEMENT xi:include EMPTY>
+<!ATTLIST xi:include
+    href CDATA #REQUIRED
+    xmlns:xi CDATA #REQUIRED
+>
+
+<!ELEMENT property EMPTY>
+<!ATTLIST property
+    name NMTOKEN #REQUIRED
+    value CDATA #REQUIRED
+    default CDATA #IMPLIED
+>
+]>
+<module name="Checker">
+    <module name="TreeWalker">
+        <xi:include
+            href="treewalker.xml"
+            xmlns:xi="http://www.w3.org/2003/XInclude"/>
+    </module>
+</module>
+
+

+

+The configuration in config.xml includes a second +configuration file, treewalker.xml, that applies +the TypeName module: +

+<?xml version="1.0"?>
+<!DOCTYPE module PUBLIC
+    "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
+    "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
+<module name="TypeName">
+    <property name="format" value="${typename.format}"/>
+</module>
+
+

+

+Notice that the configuration of treewalker.xml +applies property ${typename.format}. +That propery is set in the following segment of an ant build file that uses the +Checkstyle ant task to check file InputHeader.java +with the configuration of config.xml: +

+    <taskdef
+        resource="checkstyletask.properties"
+        classpath="/path/to/checkstyle-all-@CHECKSTYLE_VERSION@.jar" />
+    <target name="checkstyle" description="run checkstyle">
+        <checkstyle file="InputHeader.java" config="config.xml">
+            <property key="typename.format" value="xyz" />
+        </checkstyle>
+    </target>
+
+

+ + \ No newline at end of file diff --git a/contrib/examples/XInclude/treewalker.xml b/contrib/examples/XInclude/treewalker.xml new file mode 100644 index 000000000..70b17961a --- /dev/null +++ b/contrib/examples/XInclude/treewalker.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/docs/releasenotes.html b/docs/releasenotes.html index b0e2c9e51..932e7a7cf 100644 --- a/docs/releasenotes.html +++ b/docs/releasenotes.html @@ -76,6 +76,10 @@
  • Added check that checks for a modified control variable in a for loop, contributed by Daniel Grenner (module ModifiedControlVariable, patch 927680).
  • + +
  • Added example of how to configure the XML parser factory + for Checkstyle, and how to support XInclude processing + (contrib/examples/XInclude, request 905169).
  • @@ -821,7 +825,7 @@
  • Added DTD for XML output (request 622157).
  • Added an XSL stylesheet to convert XML output to plain text, contributed by Jon Scott Stevens.
  • Added portuguese localization, contributed by Pedro Morais.
  • -
  • Added finnish localization, contributed by Ville Skyttä.
  • +
  • Added finnish localization, contributed by Ville Skyttä.
  • Added french localization, contributed by Pierre Dittgen.
  • @@ -877,7 +881,7 @@
  • Incorporate patch 566855 from Rob Worth to optionally check that parenthesis are padded with spaces.
  • Incorporate patch 590931 from Vijay Aravamudhan to improve documentation of the build.xml file.
  • Incorporate patch from Vijay Aravamudhan to enforce requiring @version tag (request 543964).
  • -
  • Incorporate patch 607481 from Ville Skyttä to enforce wrap on operator at EOL.
  • +
  • Incorporate patch 607481 from Ville Skyttä to enforce wrap on operator at EOL.
  • @@ -1007,5 +1011,5 @@


    Back to the Checkstyle Home Page
    - - + + \ No newline at end of file