I am trying to set features on a DocumentBuilderFactory
. However, it just throws a javax.xml.parsers.ParserConfigurationException
with the features name as the message:
public void execute() throws Exception
{
// Get the factory.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-general-entities
// Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-general-entities
setFeature(dbf, "http://xml.org/sax/features/external-general-entities", false);
// Xerces 2 only - http://xerces.apache.org/xerces-j/features.html#external-general-entities
setFeature(dbf, "http://apache.org/xml/features/disallow-doctype-decl", true);
...
}
private void setFeature(DocumentBuilderFactory dbf, String name, boolean value)
{
try {
dbf.setFeature(name, value);
} catch (ParserConfigurationException e) {
e.printStackTrace(); // <- see below
}
}
The error gives no useful information:
javax.xml.parsers.ParserConfigurationException: http://xml.org/sax/features/external-general-entities
at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setFeature(DocumentBuilderFactoryImpl.java:101)
at com.kounta.printing.epson.EpsonReceiptTranslator.setFeature(EpsonReceiptTranslator.java:76)
at com.kounta.printing.epson.EpsonReceiptTranslator.execute(EpsonReceiptTranslator.java:49)
at com.kounta.printing.epson.EpsonPrintJob$1.run(EpsonPrintJob.java:48)
at com.kounta.util.TaskQueue.internalRun(TaskQueue.java:68)
at com.kounta.util.TaskQueue.access$100(TaskQueue.java:11)
at com.kounta.util.TaskQueue$InternalRunnable.run(TaskQueue.java:79)
at java.lang.Thread.run(Thread.java:841)
Is there a way to get all the supported features? Or am I doing something wrong? Both features throw an exception.