Skip to content

Commit 72f4c3e

Browse files
refactor: rename XMLtoJSONMLParserConfiguration to JSONMLParserConfiguration
1 parent df2d6f8 commit 72f4c3e

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

src/main/java/org/json/JSONML.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private static Object parse(
3131
int currentNestingDepth
3232
) throws JSONException {
3333
return parse(x,arrayForm, ja,
34-
keepStrings ? XMLtoJSONMLParserConfiguration.KEEP_STRINGS : XMLtoJSONMLParserConfiguration.ORIGINAL,
34+
keepStrings ? JSONMLParserConfiguration.KEEP_STRINGS : JSONMLParserConfiguration.ORIGINAL,
3535
currentNestingDepth);
3636
}
3737

@@ -41,17 +41,17 @@ private static Object parse(
4141
* @param arrayForm true if array form, false if object form.
4242
* @param ja The JSONArray that is containing the current tag or null
4343
* if we are at the outermost level.
44-
* @param config The XML parser configuration:
45-
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
46-
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means Don't type-convert text nodes and attribute values.
44+
* @param config The parser configuration:
45+
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
46+
* JSONMLParserConfiguration.KEEP_STRINGS means Don't type-convert text nodes and attribute values.
4747
* @return A JSONArray if the value is the outermost tag, otherwise null.
4848
* @throws JSONException if a parsing error occurs
4949
*/
5050
private static Object parse(
5151
XMLTokener x,
5252
boolean arrayForm,
5353
JSONArray ja,
54-
XMLtoJSONMLParserConfiguration config,
54+
JSONMLParserConfiguration config,
5555
int currentNestingDepth
5656
) throws JSONException {
5757
String attribute;
@@ -254,7 +254,7 @@ private static Object parse(
254254
* @throws JSONException Thrown on error converting to a JSONArray
255255
*/
256256
public static JSONArray toJSONArray(String string) throws JSONException {
257-
return (JSONArray)parse(new XMLTokener(string), true, null, XMLtoJSONMLParserConfiguration.ORIGINAL, 0);
257+
return (JSONArray)parse(new XMLTokener(string), true, null, JSONMLParserConfiguration.ORIGINAL, 0);
258258
}
259259

260260

@@ -293,14 +293,14 @@ public static JSONArray toJSONArray(String string, boolean keepStrings) throws J
293293
* but just leaves it as a string.
294294
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
295295
* @param string The source string.
296-
* @param config The XML parser configuration:
297-
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
298-
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
296+
* @param config The parser configuration:
297+
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
298+
* JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
299299
* or numeric values and will instead be left as strings
300300
* @return A JSONArray containing the structured data from the XML string.
301301
* @throws JSONException Thrown on error converting to a JSONArray
302302
*/
303-
public static JSONArray toJSONArray(String string, XMLtoJSONMLParserConfiguration config) throws JSONException {
303+
public static JSONArray toJSONArray(String string, JSONMLParserConfiguration config) throws JSONException {
304304
return (JSONArray)parse(new XMLTokener(string), true, null, config, 0);
305305
}
306306

@@ -317,14 +317,14 @@ public static JSONArray toJSONArray(String string, XMLtoJSONMLParserConfiguratio
317317
* but just leaves it as a string.
318318
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
319319
* @param x An XMLTokener.
320-
* @param config The XML parser configuration:
321-
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
322-
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
320+
* @param config The parser configuration:
321+
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
322+
* JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
323323
* or numeric values and will instead be left as strings
324324
* @return A JSONArray containing the structured data from the XML string.
325325
* @throws JSONException Thrown on error converting to a JSONArray
326326
*/
327-
public static JSONArray toJSONArray(XMLTokener x, XMLtoJSONMLParserConfiguration config) throws JSONException {
327+
public static JSONArray toJSONArray(XMLTokener x, JSONMLParserConfiguration config) throws JSONException {
328328
return (JSONArray)parse(x, true, null, config, 0);
329329
}
330330

@@ -416,14 +416,14 @@ public static JSONObject toJSONObject(String string, boolean keepStrings) throws
416416
417417
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
418418
* @param string The XML source text.
419-
* @param config The XML parser configuration:
420-
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
421-
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
419+
* @param config The parser configuration:
420+
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
421+
* JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
422422
* or numeric values and will instead be left as strings
423423
* @return A JSONObject containing the structured data from the XML string.
424424
* @throws JSONException Thrown on error converting to a JSONObject
425425
*/
426-
public static JSONObject toJSONObject(String string, XMLtoJSONMLParserConfiguration config) throws JSONException {
426+
public static JSONObject toJSONObject(String string, JSONMLParserConfiguration config) throws JSONException {
427427
return (JSONObject)parse(new XMLTokener(string), false, null, config, 0);
428428
}
429429

@@ -476,14 +476,14 @@ public static JSONObject toJSONObject(XMLTokener x, boolean keepStrings) throws
476476
477477
* Comments, prologs, DTDs, and <pre>{@code &lt;[ [ ]]>}</pre> are ignored.
478478
* @param x An XMLTokener of the XML source text.
479-
* @param config The XML parser configuration:
480-
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
481-
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
479+
* @param config The parser configuration:
480+
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
481+
* JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
482482
* or numeric values and will instead be left as strings
483483
* @return A JSONObject containing the structured data from the XML string.
484484
* @throws JSONException Thrown on error converting to a JSONObject
485485
*/
486-
public static JSONObject toJSONObject(XMLTokener x, XMLtoJSONMLParserConfiguration config) throws JSONException {
486+
public static JSONObject toJSONObject(XMLTokener x, JSONMLParserConfiguration config) throws JSONException {
487487
return (JSONObject)parse(x, false, null, config, 0);
488488
}
489489

src/main/java/org/json/XMLtoJSONMLParserConfiguration.java renamed to src/main/java/org/json/JSONMLParserConfiguration.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Configuration object for the XML to JSONML parser. The configuration is immutable.
88
*/
99
@SuppressWarnings({""})
10-
public class XMLtoJSONMLParserConfiguration {
10+
public class JSONMLParserConfiguration {
1111
/**
1212
* Used to indicate there's no defined limit to the maximum nesting depth when parsing a XML
1313
* document to JSONML.
@@ -20,11 +20,11 @@ public class XMLtoJSONMLParserConfiguration {
2020
public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = 512;
2121

2222
/** Original Configuration of the XML to JSONML Parser. */
23-
public static final XMLtoJSONMLParserConfiguration ORIGINAL
24-
= new XMLtoJSONMLParserConfiguration();
23+
public static final JSONMLParserConfiguration ORIGINAL
24+
= new JSONMLParserConfiguration();
2525
/** Original configuration of the XML to JSONML Parser except that values are kept as strings. */
26-
public static final XMLtoJSONMLParserConfiguration KEEP_STRINGS
27-
= new XMLtoJSONMLParserConfiguration().withKeepStrings(true);
26+
public static final JSONMLParserConfiguration KEEP_STRINGS
27+
= new JSONMLParserConfiguration().withKeepStrings(true);
2828

2929
/**
3030
* When parsing the XML into JSONML, specifies if values should be kept as strings (<code>true</code>), or if
@@ -40,7 +40,7 @@ public class XMLtoJSONMLParserConfiguration {
4040
/**
4141
* Default parser configuration. Does not keep strings (tries to implicitly convert values).
4242
*/
43-
public XMLtoJSONMLParserConfiguration() {
43+
public JSONMLParserConfiguration() {
4444
this.keepStrings = false;
4545
}
4646

@@ -50,7 +50,7 @@ public XMLtoJSONMLParserConfiguration() {
5050
* <code>false</code> to try and convert XML string values into a JSON value.
5151
* @param maxNestingDepth <code>int</code> to limit the nesting depth
5252
*/
53-
public XMLtoJSONMLParserConfiguration(final boolean keepStrings, final int maxNestingDepth) {
53+
public JSONMLParserConfiguration(final boolean keepStrings, final int maxNestingDepth) {
5454
this.keepStrings = keepStrings;
5555
this.maxNestingDepth = maxNestingDepth;
5656
}
@@ -59,13 +59,13 @@ public XMLtoJSONMLParserConfiguration(final boolean keepStrings, final int maxNe
5959
* Provides a new instance of the same configuration.
6060
*/
6161
@Override
62-
protected XMLtoJSONMLParserConfiguration clone() {
62+
protected JSONMLParserConfiguration clone() {
6363
// future modifications to this method should always ensure a "deep"
6464
// clone in the case of collections. i.e. if a Map is added as a configuration
6565
// item, a new map instance should be created and if possible each value in the
6666
// map should be cloned as well. If the values of the map are known to also
6767
// be immutable, then a shallow clone of the map is acceptable.
68-
return new XMLtoJSONMLParserConfiguration(
68+
return new JSONMLParserConfiguration(
6969
this.keepStrings,
7070
this.maxNestingDepth
7171
);
@@ -90,8 +90,8 @@ public boolean isKeepStrings() {
9090
*
9191
* @return The existing configuration will not be modified. A new configuration is returned.
9292
*/
93-
public XMLtoJSONMLParserConfiguration withKeepStrings(final boolean newVal) {
94-
XMLtoJSONMLParserConfiguration newConfig = this.clone();
93+
public JSONMLParserConfiguration withKeepStrings(final boolean newVal) {
94+
JSONMLParserConfiguration newConfig = this.clone();
9595
newConfig.keepStrings = newVal;
9696
return newConfig;
9797
}
@@ -114,8 +114,8 @@ public int getMaxNestingDepth() {
114114
* @param maxNestingDepth the maximum nesting depth allowed to the XML parser
115115
* @return The existing configuration will not be modified. A new configuration is returned.
116116
*/
117-
public XMLtoJSONMLParserConfiguration withMaxNestingDepth(int maxNestingDepth) {
118-
XMLtoJSONMLParserConfiguration newConfig = this.clone();
117+
public JSONMLParserConfiguration withMaxNestingDepth(int maxNestingDepth) {
118+
JSONMLParserConfiguration newConfig = this.clone();
119119

120120
if (maxNestingDepth > UNDEFINED_MAXIMUM_NESTING_DEPTH) {
121121
newConfig.maxNestingDepth = maxNestingDepth;

src/test/java/org/json/junit/JSONMLTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ public void testToJSONArrayMaxNestingDepthOf42IsRespected() {
841841
final int maxNestingDepth = 42;
842842

843843
try {
844-
JSONML.toJSONArray(wayTooLongMalformedXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
844+
JSONML.toJSONArray(wayTooLongMalformedXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
845845

846846
fail("Expecting a JSONException");
847847
} catch (JSONException e) {
@@ -864,7 +864,7 @@ public void testToJSONArrayMaxNestingDepthIsRespectedWithValidXML() {
864864
final int maxNestingDepth = 1;
865865

866866
try {
867-
JSONML.toJSONArray(perfectlyFineXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
867+
JSONML.toJSONArray(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
868868

869869
fail("Expecting a JSONException");
870870
} catch (JSONException e) {
@@ -886,11 +886,11 @@ public void testToJSONArrayMaxNestingDepthWithValidFittingXML() {
886886
final int maxNestingDepth = 3;
887887

888888
try {
889-
JSONML.toJSONArray(perfectlyFineXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
889+
JSONML.toJSONArray(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
890890
} catch (JSONException e) {
891891
e.printStackTrace();
892892
fail("XML document should be parsed as its maximum depth fits the maxNestingDepth " +
893-
"parameter of the XMLtoJSONMLParserConfiguration used");
893+
"parameter of the JSONMLParserConfiguration used");
894894
}
895895
}
896896

@@ -905,7 +905,7 @@ public void testToJSONObjectMaxNestingDepthOf42IsRespected() {
905905
final int maxNestingDepth = 42;
906906

907907
try {
908-
JSONML.toJSONObject(wayTooLongMalformedXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
908+
JSONML.toJSONObject(wayTooLongMalformedXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
909909

910910
fail("Expecting a JSONException");
911911
} catch (JSONException e) {
@@ -927,7 +927,7 @@ public void testToJSONObjectMaxNestingDepthIsRespectedWithValidXML() {
927927
final int maxNestingDepth = 1;
928928

929929
try {
930-
JSONML.toJSONObject(perfectlyFineXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
930+
JSONML.toJSONObject(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
931931

932932
fail("Expecting a JSONException");
933933
} catch (JSONException e) {
@@ -949,11 +949,11 @@ public void testToJSONObjectMaxNestingDepthWithValidFittingXML() {
949949
final int maxNestingDepth = 3;
950950

951951
try {
952-
JSONML.toJSONObject(perfectlyFineXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
952+
JSONML.toJSONObject(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
953953
} catch (JSONException e) {
954954
e.printStackTrace();
955955
fail("XML document should be parsed as its maximum depth fits the maxNestingDepth " +
956-
"parameter of the XMLtoJSONMLParserConfiguration used");
956+
"parameter of the JSONMLParserConfiguration used");
957957
}
958958
}
959959

0 commit comments

Comments
 (0)