Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions geowebcache/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<groupId>org.geotools</groupId>
<artifactId>gt-coverage</artifactId>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-xml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
Expand All @@ -54,6 +53,7 @@
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.geotools.util.logging.Logging;
import org.geotools.xml.XMLUtils;
import org.geowebcache.GeoWebCacheEnvironment;
import org.geowebcache.GeoWebCacheException;
import org.geowebcache.GeoWebCacheExtensions;
Expand Down Expand Up @@ -616,7 +616,7 @@ static Node loadDocument(InputStream xmlFile) throws ConfigurationException, IOE
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
DocumentBuilder docBuilder = XMLUtils.newDocumentBuilder(docBuilderFactory);
topNode = checkAndTransform(docBuilder.parse(xmlFile));
} catch (Exception e) {
throw (IOException) new IOException(e.getMessage()).initCause(e);
Expand Down Expand Up @@ -758,7 +758,7 @@ static String getCurrentSchemaVersion() {

Document dom;
try (InputStream is = XMLConfiguration.class.getResourceAsStream("geowebcache.xsd")) {
dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
dom = XMLUtils.newDocumentBuilder().parse(is);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -777,7 +777,7 @@ private static Node applyTransform(Node oldRootNode, String xslFilename) {
try (InputStream is = XMLConfiguration.class.getResourceAsStream(xslFilename)) {

try {
transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(is));
transformer = XMLUtils.newTransformer(new StreamSource(is));
transformer.transform(new DOMSource(oldRootNode), result);
} catch (TransformerFactoryConfigurationError | TransformerException e) {
log.log(Level.FINE, e.getMessage(), e);
Expand Down
137 changes: 136 additions & 1 deletion geowebcache/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,140 @@ GeoWebCache ruleset. See https://pmd.github.io/pmd/pmd_userdocs_making_rulesets.
<properties>
<property name="reportLevel" value="140"/>
</properties>
</rule>
</rule>

<rule name="AvoidDocumentBuilderFactory"
language="java"
message="Do not use DocumentBuildeFactory instance directly; recommend XMLUtils.newDocumentBuilderFactory()"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
Notice use of DocumentBuilderFactory.newInstance() which should be avoided in favor of
XMLUtils.DocumentBuilderFactory(Hints) to respect GeoTools init configuration.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//MethodCall[pmd-java:matchesSig("javax.xml.parsers.DocumentBuilderFactory#newInstance()")]
]]>
</value>
</property>
</properties>
</rule>
<rule name="AvoidDocumentBuilder"
language="java"
message="Do not use DocumentBuilder directly; recommend XMLUtils.newDocumentBuilder()"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
Notice use of DocumentBuilderFactory.newDocumentBuilder() which should be avoided in favor of
XMLUtils.newDocumentBuilder(Hints) to respect GeoTools init configuration.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//MethodCall[pmd-java:matchesSig("javax.xml.parsers.DocumentBuilderFactory#newDocumentBuilder()")]
]]>
</value>
</property>
</properties>
</rule>
<rule name="AvoidTransformFactory"
language="java"
message="Do not use TransformerFactory directly; recommend XMLUtils.newInstance()"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
Notice use of TransformerFactory.newInstance() which should be avoided in favor of
XMLUtils.newTransformerFactory(Hints) to respect GeoTools init configuration.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//MethodCall[pmd-java:matchesSig("javax.xml.transform.TransformerFactory#newInstance()")]
]]>
</value>
</property>
</properties>
</rule>
<rule name="AvoidTransformer"
language="java"
message="Do not use TransformerFactory.newTransformer() directly; recommend XMLUtils.newTransformer()"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
Notice use of TransformerFactory.newTransformer() which should be avoided in favor of
XMLUtils.newTransformer(Hints) to respect GeoTools init configuration.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//MethodCall[pmd-java:matchesSig("javax.xml.transform.TransformerFactory#newTransformer()")]
]]>
</value>
</property>
</properties>
</rule>
<rule name="AvoidTransformerSource"
language="java"
message="Do not use TransformerFactory.newTransformer(source) directly; recommend XMLUtils.newTransformer(source)"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
Notice use of TransformerFactory.newTransformer(Source) which should be avoided in favor of
XMLUtils.newTransformer(Source,Hints) to respect GeoTools init configuration.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//MethodCall[pmd-java:matchesSig("javax.xml.transform.TransformerFactory#newTransformer(javax.xml.transform.Source)")]
]]>
</value>
</property>
</properties>
</rule>
<rule name="AvoidSAXParserFactory"
language="java"
message="Do not use ParserFactory.newInstance() directly; recommend XMLUtils.newSAXParserFactory()"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
Notice use of SAXParserFactory.newInstance() which should be avoided in favor of
XMLUtils.newSAXParserFactory(Hints) to respect GeoTools init configuration.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//MethodCall[pmd-java:matchesSig("javax.xml.parsers.SAXParserFactory#newInstance()")]
]]>
</value>
</property>
</properties>
</rule>
<rule name="AvoidSaxParser"
language="java"
message="Do not use SAXParserFactory.newSAXParser() directly; recommend XMLUtils.newSAXParser()"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<description>
Notice use of SAXParserFactory.newSAXParser() which should be avoided in favor of
XMLUtils.newSAXParser(Hints) to respect GeoTools init configuration.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//MethodCall[pmd-java:matchesSig("javax.xml.parsers.SAXParserFactory#newInstance()")]
]]>
</value>
</property>
</properties>
</rule>

</ruleset>
Loading