From c55292fe82d5b3101fc51fa931048ce4636b581d Mon Sep 17 00:00:00 2001 From: claudemamo <823038+claudemamo@users.noreply.github.com> Date: Thu, 18 Mar 2021 09:43:50 +0100 Subject: [PATCH] fix: implement accessor for SAX external-general-entities feature Refs: FasterXML/aalto-xml#65 --- .../aalto/sax/SAXParserFactoryImpl.java | 2 ++ .../com/fasterxml/aalto/sax/SAXParserImpl.java | 2 ++ .../java/com/fasterxml/aalto/sax/SAXUtil.java | 2 -- .../aalto/sax/TestSAXParserFactoryImpl.java | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/fasterxml/aalto/sax/TestSAXParserFactoryImpl.java diff --git a/src/main/java/com/fasterxml/aalto/sax/SAXParserFactoryImpl.java b/src/main/java/com/fasterxml/aalto/sax/SAXParserFactoryImpl.java index 71c769b..70542d5 100644 --- a/src/main/java/com/fasterxml/aalto/sax/SAXParserFactoryImpl.java +++ b/src/main/java/com/fasterxml/aalto/sax/SAXParserFactoryImpl.java @@ -69,6 +69,8 @@ public boolean getFeature(String name) switch (stdFeat) { case IS_STANDALONE: // read-only, but only during parsing return true; + case EXTERNAL_GENERAL_ENTITIES: + return ((Boolean) mStaxFactory.getProperty(ReaderConfig.EXPAND_GENERAL_ENTITIES)).booleanValue(); default: } } else { diff --git a/src/main/java/com/fasterxml/aalto/sax/SAXParserImpl.java b/src/main/java/com/fasterxml/aalto/sax/SAXParserImpl.java index cfbed04..8ba79ce 100644 --- a/src/main/java/com/fasterxml/aalto/sax/SAXParserImpl.java +++ b/src/main/java/com/fasterxml/aalto/sax/SAXParserImpl.java @@ -262,6 +262,8 @@ public boolean getFeature(String name) case IS_STANDALONE: // read-only, but only during parsing // !!! TBI return true; + case EXTERNAL_GENERAL_ENTITIES: + return ((Boolean) _staxFactory.getProperty(ReaderConfig.EXPAND_GENERAL_ENTITIES)).booleanValue(); default: } } else { diff --git a/src/main/java/com/fasterxml/aalto/sax/SAXUtil.java b/src/main/java/com/fasterxml/aalto/sax/SAXUtil.java index 57a77aa..be9db8f 100644 --- a/src/main/java/com/fasterxml/aalto/sax/SAXUtil.java +++ b/src/main/java/com/fasterxml/aalto/sax/SAXUtil.java @@ -71,8 +71,6 @@ public static SAXProperty findStdProperty(String featURI) public static Boolean getFixedStdFeatureValue(SAXFeature stdFeat) { switch (stdFeat) { - case EXTERNAL_GENERAL_ENTITIES: // not yet implemented - return Boolean.FALSE; case EXTERNAL_PARAMETER_ENTITIES: // not yet implemented return Boolean.FALSE; case IS_STANDALONE: // read-only, but only during parsing diff --git a/src/test/java/com/fasterxml/aalto/sax/TestSAXParserFactoryImpl.java b/src/test/java/com/fasterxml/aalto/sax/TestSAXParserFactoryImpl.java new file mode 100644 index 0000000..2c3c438 --- /dev/null +++ b/src/test/java/com/fasterxml/aalto/sax/TestSAXParserFactoryImpl.java @@ -0,0 +1,17 @@ +package com.fasterxml.aalto.sax; + +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; + +public class TestSAXParserFactoryImpl extends base.BaseTestCase { + + public void testSetGetFeatureExternalGeneralEntities() throws SAXNotRecognizedException, SAXNotSupportedException { + SAXParserFactoryImpl saxParserFactory = new SAXParserFactoryImpl(); + saxParserFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); + assertFalse(saxParserFactory.getFeature("http://xml.org/sax/features/external-general-entities")); + + saxParserFactory.setFeature("http://xml.org/sax/features/external-general-entities", true); + assertTrue(saxParserFactory.getFeature("http://xml.org/sax/features/external-general-entities")); + } + +}