Review checkstyle rules of spring-xml
See gh-1479
This commit is contained in:
@@ -24,10 +24,12 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* General utilities for {@link DocumentBuilderFactory}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class DocumentBuilderFactoryUtils {
|
||||
public abstract class DocumentBuilderFactoryUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DocumentBuilderFactoryUtils.class);
|
||||
|
||||
@@ -42,7 +44,7 @@ public class DocumentBuilderFactoryUtils {
|
||||
try {
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
catch (IllegalArgumentException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by "
|
||||
+ factory.getClass().getCanonicalName());
|
||||
@@ -52,7 +54,7 @@ public class DocumentBuilderFactoryUtils {
|
||||
try {
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
catch (IllegalArgumentException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by "
|
||||
+ factory.getClass().getCanonicalName());
|
||||
@@ -62,7 +64,7 @@ public class DocumentBuilderFactoryUtils {
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
}
|
||||
catch (ParserConfigurationException e) {
|
||||
catch (ParserConfigurationException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://apache.org/xml/features/disallow-doctype-decl' is probably not supported by "
|
||||
+ factory.getClass().getCanonicalName());
|
||||
@@ -72,7 +74,7 @@ public class DocumentBuilderFactoryUtils {
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
}
|
||||
catch (ParserConfigurationException e) {
|
||||
catch (ParserConfigurationException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("FEATURE 'http://xml.org/sax/features/external-general-entities' is probably not supported by "
|
||||
+ factory.getClass().getCanonicalName());
|
||||
@@ -82,7 +84,7 @@ public class DocumentBuilderFactoryUtils {
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
}
|
||||
catch (ParserConfigurationException e) {
|
||||
catch (ParserConfigurationException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(
|
||||
"FEATURE 'http://xml.org/sax/features/external-parameter-entities' is probably not supported by "
|
||||
@@ -93,7 +95,7 @@ public class DocumentBuilderFactoryUtils {
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
}
|
||||
catch (ParserConfigurationException e) {
|
||||
catch (ParserConfigurationException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(
|
||||
"FEATURE 'http://apache.org/xml/features/nonvalidating/load-external-dtd' is probably not supported by "
|
||||
@@ -105,9 +107,9 @@ public class DocumentBuilderFactoryUtils {
|
||||
factory.setXIncludeAware(false);
|
||||
factory.setExpandEntityReferences(false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("Caught " + e.getMessage() + " attempting to configure your XML parser.");
|
||||
log.warn("Caught " + ex.getMessage() + " attempting to configure your XML parser.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public abstract class JaxpVersion {
|
||||
ClassUtils.forName(JAXP_14_CLASS_NAME, classLoader);
|
||||
jaxpVersion = JAXP_14;
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
catch (ClassNotFoundException ex2) {
|
||||
// leave 1.3 as default (it's either 1.3 or unknown)
|
||||
jaxpVersion = JAXP_13;
|
||||
}
|
||||
|
||||
@@ -19,9 +19,11 @@ package org.springframework.xml;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
|
||||
/**
|
||||
* General utilities for {@link XMLInputFactory}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class XMLInputFactoryUtils {
|
||||
public abstract class XMLInputFactoryUtils {
|
||||
|
||||
/**
|
||||
* Build an {@link XMLInputFactory} and set properties to prevent external entities
|
||||
|
||||
@@ -41,8 +41,8 @@ public abstract class QNameUtils {
|
||||
* @param localPart local part of the {@code QName}
|
||||
* @param prefix prefix of the {@code QName}. May be ignored.
|
||||
* @return the created {@code QName}
|
||||
* @see QName#QName(String,String,String)
|
||||
* @deprecated in favor of {@link QName#QName(String, String, String)}
|
||||
* @see QName#QName(String,String,String)
|
||||
*/
|
||||
@Deprecated
|
||||
public static QName createQName(String namespaceUri, String localPart, String prefix) {
|
||||
@@ -56,8 +56,8 @@ public abstract class QNameUtils {
|
||||
* returned.
|
||||
* @param qName the {@code QName} to return the prefix from
|
||||
* @return the prefix, if available, or an empty string
|
||||
* @see javax.xml.namespace.QName#getPrefix()
|
||||
* @deprecated in favor of {@link QName#getPrefix()}
|
||||
* @see javax.xml.namespace.QName#getPrefix()
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getPrefix(QName qName) {
|
||||
@@ -65,7 +65,7 @@ public abstract class QNameUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the given String as a QName
|
||||
* Validates the given String as a QName.
|
||||
* @param text the qualified name
|
||||
* @return {@code true} if valid, {@code false} otherwise
|
||||
*/
|
||||
|
||||
@@ -26,10 +26,12 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* General utilities of {@link TransformerFactory}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class TransformerFactoryUtils {
|
||||
public abstract class TransformerFactoryUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TransformerFactoryUtils.class);
|
||||
|
||||
@@ -48,8 +50,8 @@ public class TransformerFactoryUtils {
|
||||
try {
|
||||
return defaultSettings(transformerFactoryClass.getDeclaredConstructor().newInstance());
|
||||
}
|
||||
catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException e) {
|
||||
throw new TransformerFactoryConfigurationError(e,
|
||||
catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException ex) {
|
||||
throw new TransformerFactoryConfigurationError(ex,
|
||||
"Could not instantiate TransformerFactory [" + transformerFactoryClass + "]");
|
||||
}
|
||||
}
|
||||
@@ -61,7 +63,7 @@ public class TransformerFactoryUtils {
|
||||
try {
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
catch (IllegalArgumentException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by "
|
||||
+ factory.getClass().getCanonicalName());
|
||||
@@ -71,7 +73,7 @@ public class TransformerFactoryUtils {
|
||||
try {
|
||||
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
catch (IllegalArgumentException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_STYLESHEET + " property not supported by "
|
||||
+ factory.getClass().getCanonicalName());
|
||||
|
||||
@@ -100,7 +100,8 @@ public class TransformerHelper {
|
||||
synchronized (this) {
|
||||
result = this.transformerFactory;
|
||||
if (result == null) {
|
||||
this.transformerFactory = result = newTransformerFactory(this.transformerFactoryClass);
|
||||
result = newTransformerFactory(this.transformerFactoryClass);
|
||||
this.transformerFactory = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ abstract class Jaxp13ValidatorFactory {
|
||||
|
||||
private Schema schema;
|
||||
|
||||
public Jaxp13Validator(Schema schema) {
|
||||
Jaxp13Validator(Schema schema) {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ abstract class Jaxp15ValidatorFactory {
|
||||
|
||||
private Schema schema;
|
||||
|
||||
public Jaxp15Validator(Schema schema) {
|
||||
Jaxp15Validator(Schema schema) {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ abstract class Jaxp15ValidatorFactory {
|
||||
try {
|
||||
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
}
|
||||
catch (SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by "
|
||||
+ validator.getClass().getCanonicalName());
|
||||
@@ -89,7 +89,7 @@ abstract class Jaxp15ValidatorFactory {
|
||||
try {
|
||||
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
|
||||
}
|
||||
catch (SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by "
|
||||
+ validator.getClass().getCanonicalName());
|
||||
|
||||
@@ -27,10 +27,12 @@ import org.xml.sax.SAXNotSupportedException;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
/**
|
||||
* General utilities for {@link SchemaFactory}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class SchemaFactoryUtils {
|
||||
public abstract class SchemaFactoryUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SchemaFactoryUtils.class);
|
||||
|
||||
@@ -45,7 +47,7 @@ public class SchemaFactoryUtils {
|
||||
try {
|
||||
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
|
||||
}
|
||||
catch (SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by "
|
||||
+ schemaFactory.getClass().getCanonicalName());
|
||||
@@ -57,7 +59,7 @@ public class SchemaFactoryUtils {
|
||||
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ResourceUtils.URL_PROTOCOL_FILE + ","
|
||||
+ "jar:file" + "," + "nested" + "," + ResourceUtils.URL_PROTOCOL_WSJAR);
|
||||
}
|
||||
catch (SAXNotRecognizedException | SAXNotSupportedException e) {
|
||||
catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(XMLConstants.ACCESS_EXTERNAL_SCHEMA + " property not supported by "
|
||||
+ schemaFactory.getClass().getCanonicalName());
|
||||
|
||||
@@ -85,7 +85,7 @@ public abstract class SchemaLoaderUtils {
|
||||
try {
|
||||
return resource.getURL().toString();
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,12 @@ import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
/**
|
||||
* General utilities to create an {@link XMLReader}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @since 3.0.5
|
||||
*/
|
||||
public class XMLReaderFactoryUtils {
|
||||
public abstract class XMLReaderFactoryUtils {
|
||||
|
||||
/**
|
||||
* Build a {@link XMLReader} and set properties to prevent external entity access.
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.xml.validation;
|
||||
import org.springframework.xml.XmlException;
|
||||
|
||||
/**
|
||||
* Exception thrown when a validation error occurs
|
||||
* Exception thrown when a validation error occurs.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
|
||||
@@ -56,26 +56,6 @@ public abstract class AbstractXPathTemplate extends TransformerObjectSupport imp
|
||||
evaluate(expression, context, new NodeCallbackHandlerNodeMapper(callbackHandler));
|
||||
}
|
||||
|
||||
/**
|
||||
* Static inner class that adapts a {@link NodeCallbackHandler} to the interface of
|
||||
* {@link NodeMapper}.
|
||||
*/
|
||||
private static final class NodeCallbackHandlerNodeMapper implements NodeMapper<Object> {
|
||||
|
||||
private final NodeCallbackHandler callbackHandler;
|
||||
|
||||
public NodeCallbackHandlerNodeMapper(NodeCallbackHandler callbackHandler) {
|
||||
this.callbackHandler = callbackHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object mapNode(Node node, int nodeNum) throws DOMException {
|
||||
this.callbackHandler.processNode(node);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root element of the given source.
|
||||
* @param source the source to get the root element from
|
||||
@@ -88,4 +68,24 @@ public abstract class AbstractXPathTemplate extends TransformerObjectSupport imp
|
||||
return document.getDocumentElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Static inner class that adapts a {@link NodeCallbackHandler} to the interface of
|
||||
* {@link NodeMapper}.
|
||||
*/
|
||||
private static final class NodeCallbackHandlerNodeMapper implements NodeMapper<Object> {
|
||||
|
||||
private final NodeCallbackHandler callbackHandler;
|
||||
|
||||
NodeCallbackHandlerNodeMapper(NodeCallbackHandler callbackHandler) {
|
||||
this.callbackHandler = callbackHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object mapNode(Node node, int nodeNum) throws DOMException {
|
||||
this.callbackHandler.processNode(node);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class Jaxp13XPathTemplate extends AbstractXPathTemplate {
|
||||
@Override
|
||||
public double evaluateAsDouble(String expression, Source context) throws XPathException {
|
||||
Double result = (Double) evaluate(expression, context, XPathConstants.NUMBER);
|
||||
return result != null ? result : Double.NaN;
|
||||
return (result != null) ? result : Double.NaN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.w3c.dom.Node;
|
||||
* of mapping each node to a result object, but don't need to worry about exception
|
||||
* handling.
|
||||
*
|
||||
* @param <T> the type of the result object
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
* @see XPathOperations#evaluate(String,javax.xml.transform.Source,NodeMapper)
|
||||
|
||||
@@ -254,7 +254,7 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
|
||||
return createInputSource(resource);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user