Skip to content

Commit

Permalink
Issue #3605: enable certain SAXParserFactory features
Browse files Browse the repository at this point in the history
  • Loading branch information
liutikas authored and romani committed Dec 6, 2016
1 parent 62e1209 commit 636ae05
Showing 1 changed file with 8 additions and 0 deletions.
Expand Up @@ -49,6 +49,12 @@
*/
public abstract class AbstractLoader
extends DefaultHandler {
/** Feature that enables loading external DTD when loading XML files. */
private static final String LOAD_EXTERNAL_DTD =
"http://apache.org/xml/features/nonvalidating/load-external-dtd";
/** Feature that enables including external general entities in XML files. */
private static final String EXTERNAL_GENERAL_ENTITIES =
"http://xml.org/sax/features/external-general-entities";
/** Maps public id to resolve to resource name for the DTD. */
private final Map<String, String> publicIdToResourceNameMap;
/** Parser to read XML files. **/
Expand Down Expand Up @@ -77,6 +83,8 @@ protected AbstractLoader(Map<String, String> publicIdToResourceNameMap)
throws SAXException, ParserConfigurationException {
this.publicIdToResourceNameMap = new HashMap<>(publicIdToResourceNameMap);
final SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setFeature(LOAD_EXTERNAL_DTD, true);
factory.setFeature(EXTERNAL_GENERAL_ENTITIES, true);
factory.setValidating(true);
factory.setNamespaceAware(true);
parser = factory.newSAXParser().getXMLReader();
Expand Down

0 comments on commit 636ae05

Please sign in to comment.