Skip to content

Commit

Permalink
refactor: rename new EXPAND_GENERAL_ENTITIES property to RETAIN_GENER…
Browse files Browse the repository at this point in the history
…AL_ENTITIES to avoid confusion with existing EXPAND_ENTITIES parameter

Refs: FasterXML#65
  • Loading branch information
cjmamo committed Mar 18, 2021
1 parent 552e37f commit 083c2f4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/fasterxml/aalto/AaltoInputProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
15 changes: 9 additions & 6 deletions src/main/java/com/fasterxml/aalto/in/ReaderConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, Object> sProperties;
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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); }

/*
/**********************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fasterxml/aalto/in/ReaderScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fasterxml/aalto/sax/SAXParserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 083c2f4

Please sign in to comment.