From 083c2f470f77b7a8702051400c163da6f34454d6 Mon Sep 17 00:00:00 2001 From: claudemamo <823038+claudemamo@users.noreply.github.com> Date: Thu, 18 Mar 2021 11:24:32 +0100 Subject: [PATCH] refactor: rename new EXPAND_GENERAL_ENTITIES property to RETAIN_GENERAL_ENTITIES to avoid confusion with existing EXPAND_ENTITIES parameter Refs: FasterXML/aalto-xml#65 --- .../com/fasterxml/aalto/AaltoInputProperties.java | 4 ++-- .../java/com/fasterxml/aalto/in/ReaderConfig.java | 15 +++++++++------ .../com/fasterxml/aalto/in/ReaderScanner.java | 2 +- .../fasterxml/aalto/sax/SAXParserFactoryImpl.java | 4 ++-- .../com/fasterxml/aalto/sax/SAXParserImpl.java | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/fasterxml/aalto/AaltoInputProperties.java b/src/main/java/com/fasterxml/aalto/AaltoInputProperties.java index 9871327..b0842ca 100644 --- a/src/main/java/com/fasterxml/aalto/AaltoInputProperties.java +++ b/src/main/java/com/fasterxml/aalto/AaltoInputProperties.java @@ -8,9 +8,9 @@ public final class AaltoInputProperties { /** - * Feature controlling whether general entities are expanded or retained. + * Feature controlling whether general entities are retained. * * @since 1.3 */ - public final static String P_EXPAND_GENERAL_ENTITIES = "com.fasterxml.aalto.expandGeneralEntities"; + public final static String P_RETAIN_GENERAL_ENTITIES = "com.fasterxml.aalto.retainGeneralEntities"; } diff --git a/src/main/java/com/fasterxml/aalto/in/ReaderConfig.java b/src/main/java/com/fasterxml/aalto/in/ReaderConfig.java index 2d7d267..424b6ba 100644 --- a/src/main/java/com/fasterxml/aalto/in/ReaderConfig.java +++ b/src/main/java/com/fasterxml/aalto/in/ReaderConfig.java @@ -42,10 +42,10 @@ public final class ReaderConfig final static int F_AUTO_CLOSE_INPUT = 0x2000; // Custom flags: - final static int F_EXPAND_GENERAL_ENTITIES = 0x3000; + final static int F_RETAIN_GENERAL_ENTITIES = 0x4000; /** - * These are the default settigs for XMLInputFactory. + * These are the default settings for XMLInputFactory. */ final static int DEFAULT_FLAGS = F_NS_AWARE @@ -57,8 +57,7 @@ public final class ReaderConfig | F_INTERN_NS_URIS // and will report CDATA as such (and not as CHARACTERS) | F_REPORT_CDATA - | F_PRESERVE_LOCATION - | F_EXPAND_GENERAL_ENTITIES + | F_PRESERVE_LOCATION ; private final static HashMap sProperties; @@ -102,7 +101,7 @@ public final class ReaderConfig sProperties.put(XMLInputFactory2.P_DTD_OVERRIDE, null); // Custom ones - sProperties.put(AaltoInputProperties.P_EXPAND_GENERAL_ENTITIES, Integer.valueOf(F_EXPAND_GENERAL_ENTITIES)); + sProperties.put(AaltoInputProperties.P_RETAIN_GENERAL_ENTITIES, Integer.valueOf(F_RETAIN_GENERAL_ENTITIES)); } /** @@ -284,6 +283,10 @@ public void doReportCData(boolean state) { setFlag(F_REPORT_CDATA, state); } + public void doRetainGeneralEntities(boolean state) { + setFlag(F_RETAIN_GENERAL_ENTITIES, state); + } + /* /********************************************************************** /* Common accessors from CommonConfig @@ -418,7 +421,7 @@ public boolean willParseLazily() { // // // Custom properties - public boolean willExpandGeneralEntities() { return hasFlag(F_EXPAND_GENERAL_ENTITIES); } + public boolean willRetainGeneralEntities() { return hasFlag(F_RETAIN_GENERAL_ENTITIES); } /* /********************************************************************** diff --git a/src/main/java/com/fasterxml/aalto/in/ReaderScanner.java b/src/main/java/com/fasterxml/aalto/in/ReaderScanner.java index bccf9ea..51e67b3 100644 --- a/src/main/java/com/fasterxml/aalto/in/ReaderScanner.java +++ b/src/main/java/com/fasterxml/aalto/in/ReaderScanner.java @@ -896,7 +896,7 @@ private final int collectValue(int attrPtr, char quoteChar, PName attrName) throwUnexpectedChar(c, "'<' not allowed in attribute value"); case XmlCharTypes.CT_AMP: { - if (_config.willExpandGeneralEntities()) { + if (!_config.willRetainGeneralEntities()) { int d = handleEntityInText(false); if (d == 0) { // unexpanded general entity... not good reportUnexpandedEntityInAttr(attrName, false); diff --git a/src/main/java/com/fasterxml/aalto/sax/SAXParserFactoryImpl.java b/src/main/java/com/fasterxml/aalto/sax/SAXParserFactoryImpl.java index 6ff97b6..36e89f0 100644 --- a/src/main/java/com/fasterxml/aalto/sax/SAXParserFactoryImpl.java +++ b/src/main/java/com/fasterxml/aalto/sax/SAXParserFactoryImpl.java @@ -70,7 +70,7 @@ public boolean getFeature(String name) case IS_STANDALONE: // read-only, but only during parsing return true; case EXTERNAL_GENERAL_ENTITIES: - return ((Boolean) mStaxFactory.getProperty(AaltoInputProperties.P_EXPAND_GENERAL_ENTITIES)).booleanValue(); + return !((Boolean) mStaxFactory.getProperty(AaltoInputProperties.P_RETAIN_GENERAL_ENTITIES)).booleanValue(); default: } } else { @@ -98,7 +98,7 @@ public void setFeature(String name, boolean enabled) switch (stdFeat) { case EXTERNAL_GENERAL_ENTITIES: - mStaxFactory.setProperty(AaltoInputProperties.P_EXPAND_GENERAL_ENTITIES, enabled); + mStaxFactory.setProperty(AaltoInputProperties.P_RETAIN_GENERAL_ENTITIES, !enabled); ok = true; break; case EXTERNAL_PARAMETER_ENTITIES: diff --git a/src/main/java/com/fasterxml/aalto/sax/SAXParserImpl.java b/src/main/java/com/fasterxml/aalto/sax/SAXParserImpl.java index c8994db..ca32d5d 100644 --- a/src/main/java/com/fasterxml/aalto/sax/SAXParserImpl.java +++ b/src/main/java/com/fasterxml/aalto/sax/SAXParserImpl.java @@ -264,7 +264,7 @@ public boolean getFeature(String name) // !!! TBI return true; case EXTERNAL_GENERAL_ENTITIES: - return ((Boolean) _staxFactory.getProperty(AaltoInputProperties.P_EXPAND_GENERAL_ENTITIES)).booleanValue(); + return !((Boolean) _staxFactory.getProperty(AaltoInputProperties.P_RETAIN_GENERAL_ENTITIES)).booleanValue(); default: } } else {