mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -04:00
refactor: rename XMLtoJSONMLParserConfiguration to JSONMLParserConfiguration
This commit is contained in:
parent
df2d6f8363
commit
72f4c3e646
@ -31,7 +31,7 @@ public class JSONML {
|
|||||||
int currentNestingDepth
|
int currentNestingDepth
|
||||||
) throws JSONException {
|
) throws JSONException {
|
||||||
return parse(x,arrayForm, ja,
|
return parse(x,arrayForm, ja,
|
||||||
keepStrings ? XMLtoJSONMLParserConfiguration.KEEP_STRINGS : XMLtoJSONMLParserConfiguration.ORIGINAL,
|
keepStrings ? JSONMLParserConfiguration.KEEP_STRINGS : JSONMLParserConfiguration.ORIGINAL,
|
||||||
currentNestingDepth);
|
currentNestingDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,9 +41,9 @@ public class JSONML {
|
|||||||
* @param arrayForm true if array form, false if object form.
|
* @param arrayForm true if array form, false if object form.
|
||||||
* @param ja The JSONArray that is containing the current tag or null
|
* @param ja The JSONArray that is containing the current tag or null
|
||||||
* if we are at the outermost level.
|
* if we are at the outermost level.
|
||||||
* @param config The XML parser configuration:
|
* @param config The parser configuration:
|
||||||
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
||||||
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means Don't type-convert text nodes and attribute values.
|
* JSONMLParserConfiguration.KEEP_STRINGS means Don't type-convert text nodes and attribute values.
|
||||||
* @return A JSONArray if the value is the outermost tag, otherwise null.
|
* @return A JSONArray if the value is the outermost tag, otherwise null.
|
||||||
* @throws JSONException if a parsing error occurs
|
* @throws JSONException if a parsing error occurs
|
||||||
*/
|
*/
|
||||||
@ -51,7 +51,7 @@ public class JSONML {
|
|||||||
XMLTokener x,
|
XMLTokener x,
|
||||||
boolean arrayForm,
|
boolean arrayForm,
|
||||||
JSONArray ja,
|
JSONArray ja,
|
||||||
XMLtoJSONMLParserConfiguration config,
|
JSONMLParserConfiguration config,
|
||||||
int currentNestingDepth
|
int currentNestingDepth
|
||||||
) throws JSONException {
|
) throws JSONException {
|
||||||
String attribute;
|
String attribute;
|
||||||
@ -254,7 +254,7 @@ public class JSONML {
|
|||||||
* @throws JSONException Thrown on error converting to a JSONArray
|
* @throws JSONException Thrown on error converting to a JSONArray
|
||||||
*/
|
*/
|
||||||
public static JSONArray toJSONArray(String string) throws JSONException {
|
public static JSONArray toJSONArray(String string) throws JSONException {
|
||||||
return (JSONArray)parse(new XMLTokener(string), true, null, XMLtoJSONMLParserConfiguration.ORIGINAL, 0);
|
return (JSONArray)parse(new XMLTokener(string), true, null, JSONMLParserConfiguration.ORIGINAL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -293,14 +293,14 @@ public class JSONML {
|
|||||||
* but just leaves it as a string.
|
* but just leaves it as a string.
|
||||||
* Comments, prologs, DTDs, and <pre>{@code <[ [ ]]>}</pre> are ignored.
|
* Comments, prologs, DTDs, and <pre>{@code <[ [ ]]>}</pre> are ignored.
|
||||||
* @param string The source string.
|
* @param string The source string.
|
||||||
* @param config The XML parser configuration:
|
* @param config The parser configuration:
|
||||||
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
||||||
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
|
* JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
|
||||||
* or numeric values and will instead be left as strings
|
* or numeric values and will instead be left as strings
|
||||||
* @return A JSONArray containing the structured data from the XML string.
|
* @return A JSONArray containing the structured data from the XML string.
|
||||||
* @throws JSONException Thrown on error converting to a JSONArray
|
* @throws JSONException Thrown on error converting to a JSONArray
|
||||||
*/
|
*/
|
||||||
public static JSONArray toJSONArray(String string, XMLtoJSONMLParserConfiguration config) throws JSONException {
|
public static JSONArray toJSONArray(String string, JSONMLParserConfiguration config) throws JSONException {
|
||||||
return (JSONArray)parse(new XMLTokener(string), true, null, config, 0);
|
return (JSONArray)parse(new XMLTokener(string), true, null, config, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,14 +317,14 @@ public class JSONML {
|
|||||||
* but just leaves it as a string.
|
* but just leaves it as a string.
|
||||||
* Comments, prologs, DTDs, and <pre>{@code <[ [ ]]>}</pre> are ignored.
|
* Comments, prologs, DTDs, and <pre>{@code <[ [ ]]>}</pre> are ignored.
|
||||||
* @param x An XMLTokener.
|
* @param x An XMLTokener.
|
||||||
* @param config The XML parser configuration:
|
* @param config The parser configuration:
|
||||||
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
||||||
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
|
* JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
|
||||||
* or numeric values and will instead be left as strings
|
* or numeric values and will instead be left as strings
|
||||||
* @return A JSONArray containing the structured data from the XML string.
|
* @return A JSONArray containing the structured data from the XML string.
|
||||||
* @throws JSONException Thrown on error converting to a JSONArray
|
* @throws JSONException Thrown on error converting to a JSONArray
|
||||||
*/
|
*/
|
||||||
public static JSONArray toJSONArray(XMLTokener x, XMLtoJSONMLParserConfiguration config) throws JSONException {
|
public static JSONArray toJSONArray(XMLTokener x, JSONMLParserConfiguration config) throws JSONException {
|
||||||
return (JSONArray)parse(x, true, null, config, 0);
|
return (JSONArray)parse(x, true, null, config, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,14 +416,14 @@ public class JSONML {
|
|||||||
|
|
||||||
* Comments, prologs, DTDs, and <pre>{@code <[ [ ]]>}</pre> are ignored.
|
* Comments, prologs, DTDs, and <pre>{@code <[ [ ]]>}</pre> are ignored.
|
||||||
* @param string The XML source text.
|
* @param string The XML source text.
|
||||||
* @param config The XML parser configuration:
|
* @param config The parser configuration:
|
||||||
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
||||||
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
|
* JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
|
||||||
* or numeric values and will instead be left as strings
|
* or numeric values and will instead be left as strings
|
||||||
* @return A JSONObject containing the structured data from the XML string.
|
* @return A JSONObject containing the structured data from the XML string.
|
||||||
* @throws JSONException Thrown on error converting to a JSONObject
|
* @throws JSONException Thrown on error converting to a JSONObject
|
||||||
*/
|
*/
|
||||||
public static JSONObject toJSONObject(String string, XMLtoJSONMLParserConfiguration config) throws JSONException {
|
public static JSONObject toJSONObject(String string, JSONMLParserConfiguration config) throws JSONException {
|
||||||
return (JSONObject)parse(new XMLTokener(string), false, null, config, 0);
|
return (JSONObject)parse(new XMLTokener(string), false, null, config, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,14 +476,14 @@ public class JSONML {
|
|||||||
|
|
||||||
* Comments, prologs, DTDs, and <pre>{@code <[ [ ]]>}</pre> are ignored.
|
* Comments, prologs, DTDs, and <pre>{@code <[ [ ]]>}</pre> are ignored.
|
||||||
* @param x An XMLTokener of the XML source text.
|
* @param x An XMLTokener of the XML source text.
|
||||||
* @param config The XML parser configuration:
|
* @param config The parser configuration:
|
||||||
* XMLtoJSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
* JSONMLParserConfiguration.ORIGINAL is the default behaviour;
|
||||||
* XMLtoJSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
|
* JSONMLParserConfiguration.KEEP_STRINGS means values will not be coerced into boolean
|
||||||
* or numeric values and will instead be left as strings
|
* or numeric values and will instead be left as strings
|
||||||
* @return A JSONObject containing the structured data from the XML string.
|
* @return A JSONObject containing the structured data from the XML string.
|
||||||
* @throws JSONException Thrown on error converting to a JSONObject
|
* @throws JSONException Thrown on error converting to a JSONObject
|
||||||
*/
|
*/
|
||||||
public static JSONObject toJSONObject(XMLTokener x, XMLtoJSONMLParserConfiguration config) throws JSONException {
|
public static JSONObject toJSONObject(XMLTokener x, JSONMLParserConfiguration config) throws JSONException {
|
||||||
return (JSONObject)parse(x, false, null, config, 0);
|
return (JSONObject)parse(x, false, null, config, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ Public Domain.
|
|||||||
* Configuration object for the XML to JSONML parser. The configuration is immutable.
|
* Configuration object for the XML to JSONML parser. The configuration is immutable.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({""})
|
@SuppressWarnings({""})
|
||||||
public class XMLtoJSONMLParserConfiguration {
|
public class JSONMLParserConfiguration {
|
||||||
/**
|
/**
|
||||||
* Used to indicate there's no defined limit to the maximum nesting depth when parsing a XML
|
* Used to indicate there's no defined limit to the maximum nesting depth when parsing a XML
|
||||||
* document to JSONML.
|
* document to JSONML.
|
||||||
@ -20,11 +20,11 @@ public class XMLtoJSONMLParserConfiguration {
|
|||||||
public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = 512;
|
public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = 512;
|
||||||
|
|
||||||
/** Original Configuration of the XML to JSONML Parser. */
|
/** Original Configuration of the XML to JSONML Parser. */
|
||||||
public static final XMLtoJSONMLParserConfiguration ORIGINAL
|
public static final JSONMLParserConfiguration ORIGINAL
|
||||||
= new XMLtoJSONMLParserConfiguration();
|
= new JSONMLParserConfiguration();
|
||||||
/** Original configuration of the XML to JSONML Parser except that values are kept as strings. */
|
/** Original configuration of the XML to JSONML Parser except that values are kept as strings. */
|
||||||
public static final XMLtoJSONMLParserConfiguration KEEP_STRINGS
|
public static final JSONMLParserConfiguration KEEP_STRINGS
|
||||||
= new XMLtoJSONMLParserConfiguration().withKeepStrings(true);
|
= new JSONMLParserConfiguration().withKeepStrings(true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When parsing the XML into JSONML, specifies if values should be kept as strings (<code>true</code>), or if
|
* 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 {
|
|||||||
/**
|
/**
|
||||||
* Default parser configuration. Does not keep strings (tries to implicitly convert values).
|
* Default parser configuration. Does not keep strings (tries to implicitly convert values).
|
||||||
*/
|
*/
|
||||||
public XMLtoJSONMLParserConfiguration() {
|
public JSONMLParserConfiguration() {
|
||||||
this.keepStrings = false;
|
this.keepStrings = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ public class XMLtoJSONMLParserConfiguration {
|
|||||||
* <code>false</code> to try and convert XML string values into a JSON value.
|
* <code>false</code> to try and convert XML string values into a JSON value.
|
||||||
* @param maxNestingDepth <code>int</code> to limit the nesting depth
|
* @param maxNestingDepth <code>int</code> to limit the nesting depth
|
||||||
*/
|
*/
|
||||||
public XMLtoJSONMLParserConfiguration(final boolean keepStrings, final int maxNestingDepth) {
|
public JSONMLParserConfiguration(final boolean keepStrings, final int maxNestingDepth) {
|
||||||
this.keepStrings = keepStrings;
|
this.keepStrings = keepStrings;
|
||||||
this.maxNestingDepth = maxNestingDepth;
|
this.maxNestingDepth = maxNestingDepth;
|
||||||
}
|
}
|
||||||
@ -59,13 +59,13 @@ public class XMLtoJSONMLParserConfiguration {
|
|||||||
* Provides a new instance of the same configuration.
|
* Provides a new instance of the same configuration.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected XMLtoJSONMLParserConfiguration clone() {
|
protected JSONMLParserConfiguration clone() {
|
||||||
// future modifications to this method should always ensure a "deep"
|
// future modifications to this method should always ensure a "deep"
|
||||||
// clone in the case of collections. i.e. if a Map is added as a configuration
|
// clone in the case of collections. i.e. if a Map is added as a configuration
|
||||||
// item, a new map instance should be created and if possible each value in the
|
// item, a new map instance should be created and if possible each value in the
|
||||||
// map should be cloned as well. If the values of the map are known to also
|
// map should be cloned as well. If the values of the map are known to also
|
||||||
// be immutable, then a shallow clone of the map is acceptable.
|
// be immutable, then a shallow clone of the map is acceptable.
|
||||||
return new XMLtoJSONMLParserConfiguration(
|
return new JSONMLParserConfiguration(
|
||||||
this.keepStrings,
|
this.keepStrings,
|
||||||
this.maxNestingDepth
|
this.maxNestingDepth
|
||||||
);
|
);
|
||||||
@ -90,8 +90,8 @@ public class XMLtoJSONMLParserConfiguration {
|
|||||||
*
|
*
|
||||||
* @return The existing configuration will not be modified. A new configuration is returned.
|
* @return The existing configuration will not be modified. A new configuration is returned.
|
||||||
*/
|
*/
|
||||||
public XMLtoJSONMLParserConfiguration withKeepStrings(final boolean newVal) {
|
public JSONMLParserConfiguration withKeepStrings(final boolean newVal) {
|
||||||
XMLtoJSONMLParserConfiguration newConfig = this.clone();
|
JSONMLParserConfiguration newConfig = this.clone();
|
||||||
newConfig.keepStrings = newVal;
|
newConfig.keepStrings = newVal;
|
||||||
return newConfig;
|
return newConfig;
|
||||||
}
|
}
|
||||||
@ -114,8 +114,8 @@ public class XMLtoJSONMLParserConfiguration {
|
|||||||
* @param maxNestingDepth the maximum nesting depth allowed to the XML parser
|
* @param maxNestingDepth the maximum nesting depth allowed to the XML parser
|
||||||
* @return The existing configuration will not be modified. A new configuration is returned.
|
* @return The existing configuration will not be modified. A new configuration is returned.
|
||||||
*/
|
*/
|
||||||
public XMLtoJSONMLParserConfiguration withMaxNestingDepth(int maxNestingDepth) {
|
public JSONMLParserConfiguration withMaxNestingDepth(int maxNestingDepth) {
|
||||||
XMLtoJSONMLParserConfiguration newConfig = this.clone();
|
JSONMLParserConfiguration newConfig = this.clone();
|
||||||
|
|
||||||
if (maxNestingDepth > UNDEFINED_MAXIMUM_NESTING_DEPTH) {
|
if (maxNestingDepth > UNDEFINED_MAXIMUM_NESTING_DEPTH) {
|
||||||
newConfig.maxNestingDepth = maxNestingDepth;
|
newConfig.maxNestingDepth = maxNestingDepth;
|
@ -841,7 +841,7 @@ public class JSONMLTest {
|
|||||||
final int maxNestingDepth = 42;
|
final int maxNestingDepth = 42;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONML.toJSONArray(wayTooLongMalformedXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
JSONML.toJSONArray(wayTooLongMalformedXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
||||||
|
|
||||||
fail("Expecting a JSONException");
|
fail("Expecting a JSONException");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -864,7 +864,7 @@ public class JSONMLTest {
|
|||||||
final int maxNestingDepth = 1;
|
final int maxNestingDepth = 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONML.toJSONArray(perfectlyFineXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
JSONML.toJSONArray(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
||||||
|
|
||||||
fail("Expecting a JSONException");
|
fail("Expecting a JSONException");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -886,11 +886,11 @@ public class JSONMLTest {
|
|||||||
final int maxNestingDepth = 3;
|
final int maxNestingDepth = 3;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONML.toJSONArray(perfectlyFineXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
JSONML.toJSONArray(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("XML document should be parsed as its maximum depth fits the maxNestingDepth " +
|
fail("XML document should be parsed as its maximum depth fits the maxNestingDepth " +
|
||||||
"parameter of the XMLtoJSONMLParserConfiguration used");
|
"parameter of the JSONMLParserConfiguration used");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -905,7 +905,7 @@ public class JSONMLTest {
|
|||||||
final int maxNestingDepth = 42;
|
final int maxNestingDepth = 42;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONML.toJSONObject(wayTooLongMalformedXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
JSONML.toJSONObject(wayTooLongMalformedXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
||||||
|
|
||||||
fail("Expecting a JSONException");
|
fail("Expecting a JSONException");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -927,7 +927,7 @@ public class JSONMLTest {
|
|||||||
final int maxNestingDepth = 1;
|
final int maxNestingDepth = 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONML.toJSONObject(perfectlyFineXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
JSONML.toJSONObject(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
||||||
|
|
||||||
fail("Expecting a JSONException");
|
fail("Expecting a JSONException");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -949,11 +949,11 @@ public class JSONMLTest {
|
|||||||
final int maxNestingDepth = 3;
|
final int maxNestingDepth = 3;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONML.toJSONObject(perfectlyFineXML, XMLtoJSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
JSONML.toJSONObject(perfectlyFineXML, JSONMLParserConfiguration.ORIGINAL.withMaxNestingDepth(maxNestingDepth));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("XML document should be parsed as its maximum depth fits the maxNestingDepth " +
|
fail("XML document should be parsed as its maximum depth fits the maxNestingDepth " +
|
||||||
"parameter of the XMLtoJSONMLParserConfiguration used");
|
"parameter of the JSONMLParserConfiguration used");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user