diff --git a/geowebcache/core/pom.xml b/geowebcache/core/pom.xml
index d309d9b99..05cf22068 100644
--- a/geowebcache/core/pom.xml
+++ b/geowebcache/core/pom.xml
@@ -23,6 +23,10 @@
org.geotools
gt-coverage
+
+ org.geotools
+ gt-xml
+
org.apache.commons
commons-collections4
diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java b/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java
index 7c330fb78..552e2d027 100644
--- a/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java
+++ b/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java
@@ -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;
@@ -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;
@@ -614,9 +614,9 @@ private synchronized void addOrReplaceGridSet(final XMLGridSet gridSet) throws I
static Node loadDocument(InputStream xmlFile) throws ConfigurationException, IOException {
Node topNode = null;
try {
- DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilderFactory docBuilderFactory = XMLUtils.newDocumentBuilderFactory();
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);
@@ -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);
}
@@ -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);
diff --git a/geowebcache/georss/src/main/java/org/geowebcache/georss/StaxGeoRSSReader.java b/geowebcache/georss/src/main/java/org/geowebcache/georss/StaxGeoRSSReader.java
index f6a26af12..53f166c68 100644
--- a/geowebcache/georss/src/main/java/org/geowebcache/georss/StaxGeoRSSReader.java
+++ b/geowebcache/georss/src/main/java/org/geowebcache/georss/StaxGeoRSSReader.java
@@ -33,6 +33,7 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.geotools.util.logging.Logging;
+import org.geotools.xml.XMLUtils;
import org.geowebcache.georss.GML31ParsingUtils.GML;
import org.locationtech.jts.geom.Geometry;
@@ -77,7 +78,7 @@ private static final class GEORSS {
private final GML31ParsingUtils gmlParser;
public StaxGeoRSSReader(final Reader feed) throws XMLStreamException, FactoryConfigurationError {
- XMLInputFactory factory = XMLInputFactory.newInstance();
+ XMLInputFactory factory = XMLUtils.newXMLInputFactory();
reader = factory.createXMLStreamReader(feed);
reader.nextTag();
diff --git a/geowebcache/pmd-ruleset.xml b/geowebcache/pmd-ruleset.xml
index 4031bf176..3dcc17d3f 100644
--- a/geowebcache/pmd-ruleset.xml
+++ b/geowebcache/pmd-ruleset.xml
@@ -114,5 +114,160 @@ GeoWebCache ruleset. See https://pmd.github.io/pmd/pmd_userdocs_making_rulesets.
-
+
+
+
+
+ Notice use of DocumentBuilderFactory.newInstance() which should be avoided in favor of
+ XMLUtils.DocumentBuilderFactory(Hints) to respect GeoTools init configuration.
+
+ 3
+
+
+
+
+
+
+
+
+
+
+ Notice use of DocumentBuilderFactory.newDocumentBuilder() which should be avoided in favor of
+ XMLUtils.newDocumentBuilder(Hints) to respect GeoTools init configuration.
+
+ 3
+
+
+
+
+
+
+
+
+
+
+ Notice use of TransformerFactory.newInstance() which should be avoided in favor of
+ XMLUtils.newTransformerFactory(Hints) to respect GeoTools init configuration.
+
+ 3
+
+
+
+
+
+
+
+
+
+
+ Notice use of TransformerFactory.newTransformer() which should be avoided in favor of
+ XMLUtils.newTransformer(Hints) to respect GeoTools init configuration.
+
+ 3
+
+
+
+
+
+
+
+
+
+
+ Notice use of TransformerFactory.newTransformer(Source) which should be avoided in favor of
+ XMLUtils.newTransformer(Source,Hints) to respect GeoTools init configuration.
+
+ 3
+
+
+
+
+
+
+
+
+
+
+ Notice use of SAXParserFactory.newInstance() which should be avoided in favor of
+ XMLUtils.newSAXParserFactory(Hints) to respect GeoTools init configuration.
+
+ 3
+
+
+
+
+
+
+
+
+
+
+ Notice use of SAXParserFactory.newSAXParser() which should be avoided in favor of
+ XMLUtils.newSAXParser(Hints) to respect GeoTools init configuration.
+
+ 3
+
+
+
+
+
+
+
+
+
+
+
+ Notice use of SAXParserFactory.newSAXParser() which should be avoided in favor of
+ XMLUtils.newSAXParser(Hints) to respect GeoTools init configuration.
+
+ 3
+
+
+
+
+
+
+
+
+