1515 * @author AylwardJ
1616 */
1717@ SuppressWarnings ({"" })
18- public class XMLParserConfiguration {
19- /**
20- * Used to indicate there's no defined limit to the maximum nesting depth when parsing a XML
21- * document to JSON.
22- */
23- public static final int UNDEFINED_MAXIMUM_NESTING_DEPTH = -1 ;
18+ public class XMLParserConfiguration extends ParserConfiguration {
2419
2520 /**
2621 * The default maximum nesting depth when parsing a XML document to JSON.
2722 */
28- public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = 512 ;
23+ // public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = 512; // We could override
2924
3025 /** Original Configuration of the XML Parser. */
3126 public static final XMLParserConfiguration ORIGINAL
@@ -34,12 +29,6 @@ public class XMLParserConfiguration {
3429 public static final XMLParserConfiguration KEEP_STRINGS
3530 = new XMLParserConfiguration ().withKeepStrings (true );
3631
37- /**
38- * When parsing the XML into JSON, specifies if values should be kept as strings (<code>true</code>), or if
39- * they should try to be guessed into JSON values (numeric, boolean, string)
40- */
41- private boolean keepStrings ;
42-
4332 /**
4433 * The name of the key in a JSON Object that indicates a CDATA section. Historically this has
4534 * been the value "content" but can be changed. Use <code>null</code> to indicate no CDATA
@@ -65,17 +54,12 @@ public class XMLParserConfiguration {
6554 */
6655 private Set <String > forceList ;
6756
68- /**
69- * The maximum nesting depth when parsing a XML document to JSON.
70- */
71- private int maxNestingDepth = DEFAULT_MAXIMUM_NESTING_DEPTH ;
72-
7357 /**
7458 * Default parser configuration. Does not keep strings (tries to implicitly convert
7559 * values), and the CDATA Tag Name is "content".
7660 */
7761 public XMLParserConfiguration () {
78- this . keepStrings = false ;
62+ super () ;
7963 this .cDataTagName = "content" ;
8064 this .convertNilAttributeToNull = false ;
8165 this .xsiTypeMap = Collections .emptyMap ();
@@ -122,7 +106,7 @@ public XMLParserConfiguration (final String cDataTagName) {
122106 */
123107 @ Deprecated
124108 public XMLParserConfiguration (final boolean keepStrings , final String cDataTagName ) {
125- this . keepStrings = keepStrings ;
109+ super ( keepStrings , DEFAULT_MAXIMUM_NESTING_DEPTH ) ;
126110 this .cDataTagName = cDataTagName ;
127111 this .convertNilAttributeToNull = false ;
128112 }
@@ -141,7 +125,7 @@ public XMLParserConfiguration (final boolean keepStrings, final String cDataTagN
141125 */
142126 @ Deprecated
143127 public XMLParserConfiguration (final boolean keepStrings , final String cDataTagName , final boolean convertNilAttributeToNull ) {
144- this . keepStrings = keepStrings ;
128+ super ( keepStrings , DEFAULT_MAXIMUM_NESTING_DEPTH ) ;
145129 this .cDataTagName = cDataTagName ;
146130 this .convertNilAttributeToNull = convertNilAttributeToNull ;
147131 }
@@ -162,12 +146,11 @@ public XMLParserConfiguration (final boolean keepStrings, final String cDataTagN
162146 private XMLParserConfiguration (final boolean keepStrings , final String cDataTagName ,
163147 final boolean convertNilAttributeToNull , final Map <String , XMLXsiTypeConverter <?>> xsiTypeMap , final Set <String > forceList ,
164148 final int maxNestingDepth ) {
165- this . keepStrings = keepStrings ;
149+ super ( keepStrings , maxNestingDepth ) ;
166150 this .cDataTagName = cDataTagName ;
167151 this .convertNilAttributeToNull = convertNilAttributeToNull ;
168152 this .xsiTypeMap = Collections .unmodifiableMap (xsiTypeMap );
169153 this .forceList = Collections .unmodifiableSet (forceList );
170- this .maxNestingDepth = maxNestingDepth ;
171154 }
172155
173156 /**
@@ -190,16 +173,6 @@ protected XMLParserConfiguration clone() {
190173 );
191174 }
192175
193- /**
194- * When parsing the XML into JSON, specifies if values should be kept as strings (<code>true</code>), or if
195- * they should try to be guessed into JSON values (numeric, boolean, string)
196- *
197- * @return The <code>keepStrings</code> configuration value.
198- */
199- public boolean isKeepStrings () {
200- return this .keepStrings ;
201- }
202-
203176 /**
204177 * When parsing the XML into JSON, specifies if values should be kept as strings (<code>true</code>), or if
205178 * they should try to be guessed into JSON values (numeric, boolean, string)
@@ -209,10 +182,9 @@ public boolean isKeepStrings() {
209182 *
210183 * @return The existing configuration will not be modified. A new configuration is returned.
211184 */
185+ @ Override
212186 public XMLParserConfiguration withKeepStrings (final boolean newVal ) {
213- XMLParserConfiguration newConfig = this .clone ();
214- newConfig .keepStrings = newVal ;
215- return newConfig ;
187+ return super .withKeepStrings (newVal );
216188 }
217189
218190 /**
@@ -318,15 +290,6 @@ public XMLParserConfiguration withForceList(final Set<String> forceList) {
318290 return newConfig ;
319291 }
320292
321- /**
322- * The maximum nesting depth that the parser will descend before throwing an exception
323- * when parsing the XML into JSON.
324- * @return the maximum nesting depth set for this configuration
325- */
326- public int getMaxNestingDepth () {
327- return maxNestingDepth ;
328- }
329-
330293 /**
331294 * Defines the maximum nesting depth that the parser will descend before throwing an exception
332295 * when parsing the XML into JSON. The default max nesting depth is 512, which means the parser
@@ -336,15 +299,8 @@ public int getMaxNestingDepth() {
336299 * @param maxNestingDepth the maximum nesting depth allowed to the XML parser
337300 * @return The existing configuration will not be modified. A new configuration is returned.
338301 */
302+ @ Override
339303 public XMLParserConfiguration withMaxNestingDepth (int maxNestingDepth ) {
340- XMLParserConfiguration newConfig = this .clone ();
341-
342- if (maxNestingDepth > UNDEFINED_MAXIMUM_NESTING_DEPTH ) {
343- newConfig .maxNestingDepth = maxNestingDepth ;
344- } else {
345- newConfig .maxNestingDepth = UNDEFINED_MAXIMUM_NESTING_DEPTH ;
346- }
347-
348- return newConfig ;
304+ return super .withMaxNestingDepth (maxNestingDepth );
349305 }
350306}
0 commit comments