SWS-1050 - Warn if property doesn't exist.

Original pull request: #128
This commit is contained in:
Greg Turnquist
2019-01-11 12:12:44 -06:00
parent 72d616c1ef
commit a16fcaae77

View File

@@ -19,12 +19,17 @@ import javax.xml.XMLConstants;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Greg Turnquist
* @since 3.0.5
*/
public class TransformerFactoryUtils {
private static final Log log = LogFactory.getLog(TransformerFactoryUtils.class);
/**
* Build a new {@link TransformerFactory} using the default constructor.
*/
@@ -50,8 +55,22 @@ public class TransformerFactoryUtils {
* Prevent external entities from accessing.
*/
private static TransformerFactory defaultSettings(TransformerFactory factory) {
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
try {
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
} catch (IllegalArgumentException e) {
if (log.isWarnEnabled()) {
log.warn(XMLConstants.ACCESS_EXTERNAL_DTD + " property not supported by " + factory.getClass().getCanonicalName());
}
}
try {
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
} catch (IllegalArgumentException e) {
if (log.isWarnEnabled()) {
log.warn(XMLConstants.ACCESS_EXTERNAL_STYLESHEET + " property not supported by " + factory.getClass().getCanonicalName());
}
}
return factory;
}
}