diff --git a/XML.java b/XML.java old mode 100755 new mode 100644 index 82455b337..03eff5ec1 --- a/XML.java +++ b/XML.java @@ -31,7 +31,7 @@ of this software and associated documentation files (the "Software"), to deal * This provides static methods to convert an XML text into a JSONObject, * and to covert a JSONObject into an XML text. * @author JSON.org - * @version 2011-02-11 + * @version 2011-01-13 */ public class XML { @@ -107,16 +107,16 @@ public static String escape(String string) { * @throws JSONException */ public static void noSpace(String string) throws JSONException { - int i, length = string.length(); - if (length == 0) { - throw new JSONException("Empty string."); - } - for (i = 0; i < length; i += 1) { - if (Character.isWhitespace(string.charAt(i))) { - throw new JSONException("'" + string + - "' contains a space character."); - } - } + int i, length = string.length(); + if (length == 0) { + throw new JSONException("Empty string."); + } + for (i = 0; i < length; i += 1) { + if (Character.isWhitespace(string.charAt(i))) { + throw new JSONException("'" + string + + "' contains a space character."); + } + } } /** @@ -160,7 +160,7 @@ private static boolean parse(XMLTokener x, JSONObject context, x.back(); } else if (c == '[') { token = x.nextToken(); - if ("CDATA".equals(token)) { + if (token.equals("CDATA")) { if (x.next() == '[') { string = x.nextCDATA(); if (string.length() > 0) { @@ -193,7 +193,7 @@ private static boolean parse(XMLTokener x, JSONObject context, // Close tag 0) { context.accumulate(tagName, jsonobject); } else { - context.accumulate(tagName, ""); + context.accumulate(tagName, ""); } return false; @@ -263,7 +263,7 @@ private static boolean parse(XMLTokener x, JSONObject context, string = (String)token; if (string.length() > 0) { jsonobject.accumulate("content", - XML.stringToValue(string)); + XML.stringToValue(string)); } // Nested element @@ -275,7 +275,7 @@ private static boolean parse(XMLTokener x, JSONObject context, } else if (jsonobject.length() == 1 && jsonobject.opt("content") != null) { context.accumulate(tagName, - jsonobject.opt("content")); + jsonobject.opt("content")); } else { context.accumulate(tagName, jsonobject); } @@ -321,16 +321,16 @@ public static Object stringToValue(String string) { // return the string. try { - char initial = string.charAt(0); - boolean negative = false; - if (initial == '-') { - initial = string.charAt(1); - negative = true; - } - if (initial == '0' && string.charAt(negative ? 2 : 1) == '0') { - return string; - } - if ((initial >= '0' && initial <= '9')) { + char initial = string.charAt(0); + boolean negative = false; + if (initial == '-') { + initial = string.charAt(1); + negative = true; + } + if (initial == '0' && string.charAt(negative ? 2 : 1) == '0') { + return string; + } + if ((initial >= '0' && initial <= '9')) { if (string.indexOf('.') >= 0) { return Double.valueOf(string); } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) { @@ -341,7 +341,7 @@ public static Object stringToValue(String string) { return myLong; } } - } + } } catch (Exception ignore) { } return string; @@ -419,7 +419,7 @@ public static String toString(Object object, String tagName) key = keys.next().toString(); value = jo.opt(key); if (value == null) { - value = ""; + value = ""; } if (value instanceof String) { string = (String)value; @@ -429,7 +429,7 @@ public static String toString(Object object, String tagName) // Emit content in body - if ("content".equals(key)) { + if (key.equals("content")) { if (value instanceof JSONArray) { ja = (JSONArray)value; length = ja.length(); @@ -462,7 +462,7 @@ public static String toString(Object object, String tagName) sb.append(toString(value, key)); } } - } else if ("".equals(value)) { + } else if (value.equals("")) { sb.append('<'); sb.append(key); sb.append("/>");