Format some stuffs
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
<version>3.3.0-SNAPSHOT</version>
|
<version>3.3.0-SNAPSHOT</version>
|
||||||
<name>PlayerVaults</name>
|
<name>PlayerVaults</name>
|
||||||
<url>http://dev.bukkit.org/server-mods/playervaults/</url>
|
<url>http://dev.bukkit.org/server-mods/playervaults/</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||||
<id>bin</id>
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<includeBaseDirectory>false</includeBaseDirectory>
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||||
<files>
|
<id>bin</id>
|
||||||
<file>
|
<includeBaseDirectory>false</includeBaseDirectory>
|
||||||
<source>${project.build.directory}/${artifactId}.jar</source>
|
<files>
|
||||||
<outputDirectory>/</outputDirectory>
|
<file>
|
||||||
<destName>${project.name}.jar</destName>
|
<source>${project.build.directory}/${artifactId}.jar</source>
|
||||||
</file>
|
<outputDirectory>/</outputDirectory>
|
||||||
</files>
|
<destName>${project.name}.jar</destName>
|
||||||
|
</file>
|
||||||
|
</files>
|
||||||
</assembly>
|
</assembly>
|
||||||
@@ -17,37 +17,35 @@ public class Commands implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
if (VaultOperations.openOwnVault(p, args[0]))
|
if (VaultOperations.openOwnVault(p, args[0]))
|
||||||
PlayerVaults.IN_VAULT.put(sender.getName(), new VaultViewInfo(sender.getName(), Integer.parseInt(args[0])));
|
PlayerVaults.IN_VAULT.put(sender.getName(), new VaultViewInfo(sender.getName(), Integer.parseInt(args[0])));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (VaultOperations.openOtherVault(p, args[0], args[1]))
|
if (VaultOperations.openOtherVault(p, args[0], args[1]))
|
||||||
PlayerVaults.IN_VAULT.put(sender.getName(), new VaultViewInfo(args[0], Integer.parseInt(args[1])));
|
PlayerVaults.IN_VAULT.put(sender.getName(), new VaultViewInfo(args[0], Integer.parseInt(args[1])));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(Lang.TITLE + "/pv <number>");
|
sender.sendMessage(Lang.TITLE + "/pv <number>");
|
||||||
sender.sendMessage(Lang.TITLE + "/pv <player> <number>");
|
sender.sendMessage(Lang.TITLE + "/pv <player> <number>");
|
||||||
}
|
}
|
||||||
}
|
} else sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.PLAYER_ONLY);
|
||||||
else sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.PLAYER_ONLY);
|
|
||||||
} else if (cmd.getName().equalsIgnoreCase("pvdel")) {
|
} else if (cmd.getName().equalsIgnoreCase("pvdel")) {
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 1:
|
case 1:
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
VaultOperations.deleteOwnVault(p, args[0]);
|
VaultOperations.deleteOwnVault(p, args[0]);
|
||||||
}
|
} else {
|
||||||
else {
|
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.PLAYER_ONLY);
|
||||||
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.PLAYER_ONLY);
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case 2:
|
||||||
case 2:
|
VaultOperations.deleteOtherVault(sender, args[0], args[1]);
|
||||||
VaultOperations.deleteOtherVault(sender, args[0], args[1]);
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
sender.sendMessage(Lang.TITLE + "/pvdel <number>");
|
||||||
sender.sendMessage(Lang.TITLE + "/pvdel <number>");
|
sender.sendMessage(Lang.TITLE + "/pvdel <player> <number>");
|
||||||
sender.sendMessage(Lang.TITLE + "/pvdel <player> <number>");
|
|
||||||
}
|
}
|
||||||
} else if (cmd.getName().equalsIgnoreCase("workbench")) {
|
} else if (cmd.getName().equalsIgnoreCase("workbench")) {
|
||||||
if (sender.hasPermission("playervaults.workbench")) {
|
if (sender.hasPermission("playervaults.workbench")) {
|
||||||
@@ -75,8 +73,7 @@ public class Commands implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
PlayerVaults.SET_SIGN.put(sender.getName(), new SignSetInfo(i));
|
PlayerVaults.SET_SIGN.put(sender.getName(), new SignSetInfo(i));
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.CLICK_A_SIGN);
|
sender.sendMessage(Lang.TITLE.toString() + Lang.CLICK_A_SIGN);
|
||||||
}
|
} else if (args.length >= 2) {
|
||||||
else if (args.length >= 2) {
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
try {
|
try {
|
||||||
i = Integer.parseInt(args[1]);
|
i = Integer.parseInt(args[1]);
|
||||||
|
|||||||
@@ -85,8 +85,7 @@ public class EconomyOperations {
|
|||||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -561,7 +561,8 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Called when the server owner decides to opt-out of Metrics while the server is running.
|
* Called when the server owner decides to opt-out of Metrics while the server is running.
|
||||||
*/
|
*/
|
||||||
protected void onOptOut() {}
|
protected void onOptOut() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,7 +614,8 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Called after the website graphs have been updated
|
* Called after the website graphs have been updated
|
||||||
*/
|
*/
|
||||||
public void reset() {}
|
public void reset() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ public class Serialization {
|
|||||||
for (ConfigurationSerializable cs : items) {
|
for (ConfigurationSerializable cs : items) {
|
||||||
if (cs == null) {
|
if (cs == null) {
|
||||||
result.add("null");
|
result.add("null");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
result.add(new JSONObject(serialize(cs)).toString());
|
result.add(new JSONObject(serialize(cs)).toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,8 +79,7 @@ public class Serialization {
|
|||||||
for (String piece : stringItems) {
|
for (String piece : stringItems) {
|
||||||
if (piece.equalsIgnoreCase("null")) {
|
if (piece.equalsIgnoreCase("null")) {
|
||||||
contents.add(null);
|
contents.add(null);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
try {
|
try {
|
||||||
ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece)));
|
ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece)));
|
||||||
contents.add(item);
|
contents.add(item);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class VaultHolder implements InventoryHolder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new vault holder
|
* Creates a new vault holder
|
||||||
*
|
*
|
||||||
* @param vaultNumber the vault number this holder is using
|
* @param vaultNumber the vault number this holder is using
|
||||||
*/
|
*/
|
||||||
public VaultHolder(int vaultNumber) {
|
public VaultHolder(int vaultNumber) {
|
||||||
@@ -23,7 +23,7 @@ public class VaultHolder implements InventoryHolder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the vault number this holder is currently using
|
* Gets the vault number this holder is currently using
|
||||||
*
|
*
|
||||||
* @return the vault number
|
* @return the vault number
|
||||||
*/
|
*/
|
||||||
public int getVaultNumber() {
|
public int getVaultNumber() {
|
||||||
@@ -32,7 +32,7 @@ public class VaultHolder implements InventoryHolder {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the inventory this vault holder holds
|
* Sets the inventory this vault holder holds
|
||||||
*
|
*
|
||||||
* @param inventory the inventory, may be null
|
* @param inventory the inventory, may be null
|
||||||
*/
|
*/
|
||||||
public void setInventory(Inventory inventory) {
|
public void setInventory(Inventory inventory) {
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
if (x.nextClean() != ']') {
|
if (x.nextClean() != ']') {
|
||||||
x.back();
|
x.back();
|
||||||
for (;;) {
|
for (; ; ) {
|
||||||
if (x.nextClean() == ',') {
|
if (x.nextClean() == ',') {
|
||||||
x.back();
|
x.back();
|
||||||
this.myArrayList.add(JSONObject.NULL);
|
this.myArrayList.add(JSONObject.NULL);
|
||||||
@@ -114,17 +114,17 @@ public class JSONArray {
|
|||||||
this.myArrayList.add(x.nextValue());
|
this.myArrayList.add(x.nextValue());
|
||||||
}
|
}
|
||||||
switch (x.nextClean()) {
|
switch (x.nextClean()) {
|
||||||
case ';':
|
case ';':
|
||||||
case ',':
|
case ',':
|
||||||
if (x.nextClean() == ']') {
|
if (x.nextClean() == ']') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
x.back();
|
||||||
|
break;
|
||||||
|
case ']':
|
||||||
return;
|
return;
|
||||||
}
|
default:
|
||||||
x.back();
|
throw x.syntaxError("Expected a ',' or ']'");
|
||||||
break;
|
|
||||||
case ']':
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
throw x.syntaxError("Expected a ',' or ']'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ public class JSONArray {
|
|||||||
* The string values "true" and "false" are converted to boolean.
|
* The string values "true" and "false" are converted to boolean.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return The truth.
|
* @return The truth.
|
||||||
* @throws JSONException If there is no value for the index or if the
|
* @throws JSONException If there is no value for the index or if the
|
||||||
* value is not convertible to boolean.
|
* value is not convertible to boolean.
|
||||||
*/
|
*/
|
||||||
@@ -200,11 +200,11 @@ public class JSONArray {
|
|||||||
Object object = this.get(index);
|
Object object = this.get(index);
|
||||||
if (object.equals(Boolean.FALSE) ||
|
if (object.equals(Boolean.FALSE) ||
|
||||||
(object instanceof String &&
|
(object instanceof String &&
|
||||||
((String) object).equalsIgnoreCase("false"))) {
|
((String) object).equalsIgnoreCase("false"))) {
|
||||||
return false;
|
return false;
|
||||||
} else if (object.equals(Boolean.TRUE) ||
|
} else if (object.equals(Boolean.TRUE) ||
|
||||||
(object instanceof String &&
|
(object instanceof String &&
|
||||||
((String) object).equalsIgnoreCase("true"))) {
|
((String) object).equalsIgnoreCase("true"))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
||||||
@@ -214,8 +214,8 @@ public class JSONArray {
|
|||||||
* Get the double value associated with an index.
|
* Get the double value associated with an index.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
* @throws JSONException If the key is not found or if the value cannot
|
* @throws JSONException If the key is not found or if the value cannot
|
||||||
* be converted to a number.
|
* be converted to a number.
|
||||||
*/
|
*/
|
||||||
public double getDouble(int index) throws JSONException {
|
public double getDouble(int index) throws JSONException {
|
||||||
@@ -234,8 +234,8 @@ public class JSONArray {
|
|||||||
* Get the int value associated with an index.
|
* Get the int value associated with an index.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
* @throws JSONException If the key is not found or if the value is not a number.
|
* @throws JSONException If the key is not found or if the value is not a number.
|
||||||
*/
|
*/
|
||||||
public int getInt(int index) throws JSONException {
|
public int getInt(int index) throws JSONException {
|
||||||
Object object = this.get(index);
|
Object object = this.get(index);
|
||||||
@@ -252,7 +252,7 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the JSONArray associated with an index.
|
* Get the JSONArray associated with an index.
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return A JSONArray value.
|
* @return A JSONArray value.
|
||||||
* @throws JSONException If there is no value for the index. or if the
|
* @throws JSONException If there is no value for the index. or if the
|
||||||
* value is not a JSONArray
|
* value is not a JSONArray
|
||||||
*/
|
*/
|
||||||
@@ -268,7 +268,7 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the JSONObject associated with an index.
|
* Get the JSONObject associated with an index.
|
||||||
* @param index subscript
|
* @param index subscript
|
||||||
* @return A JSONObject value.
|
* @return A JSONObject value.
|
||||||
* @throws JSONException If there is no value for the index or if the
|
* @throws JSONException If there is no value for the index or if the
|
||||||
* value is not a JSONObject
|
* value is not a JSONObject
|
||||||
*/
|
*/
|
||||||
@@ -285,8 +285,8 @@ public class JSONArray {
|
|||||||
* Get the long value associated with an index.
|
* Get the long value associated with an index.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
* @throws JSONException If the key is not found or if the value cannot
|
* @throws JSONException If the key is not found or if the value cannot
|
||||||
* be converted to a number.
|
* be converted to a number.
|
||||||
*/
|
*/
|
||||||
public long getLong(int index) throws JSONException {
|
public long getLong(int index) throws JSONException {
|
||||||
@@ -304,7 +304,7 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the string associated with an index.
|
* Get the string associated with an index.
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return A string value.
|
* @return A string value.
|
||||||
* @throws JSONException If there is no string value for the index.
|
* @throws JSONException If there is no string value for the index.
|
||||||
*/
|
*/
|
||||||
public String getString(int index) throws JSONException {
|
public String getString(int index) throws JSONException {
|
||||||
@@ -357,7 +357,7 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the optional object value associated with an index.
|
* Get the optional object value associated with an index.
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return An object value, or null if there is no
|
* @return An object value, or null if there is no
|
||||||
* object at that index.
|
* object at that index.
|
||||||
*/
|
*/
|
||||||
public Object opt(int index) {
|
public Object opt(int index) {
|
||||||
@@ -372,7 +372,7 @@ public class JSONArray {
|
|||||||
* or if the value is not Boolean.TRUE or the String "true".
|
* or if the value is not Boolean.TRUE or the String "true".
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return The truth.
|
* @return The truth.
|
||||||
*/
|
*/
|
||||||
public boolean optBoolean(int index) {
|
public boolean optBoolean(int index) {
|
||||||
return this.optBoolean(index, false);
|
return this.optBoolean(index, false);
|
||||||
@@ -385,7 +385,7 @@ public class JSONArray {
|
|||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @param defaultValue A boolean default.
|
* @param defaultValue A boolean default.
|
||||||
* @return The truth.
|
* @return The truth.
|
||||||
*/
|
*/
|
||||||
public boolean optBoolean(int index, boolean defaultValue) {
|
public boolean optBoolean(int index, boolean defaultValue) {
|
||||||
try {
|
try {
|
||||||
@@ -401,7 +401,7 @@ public class JSONArray {
|
|||||||
* or if the value is not a number and cannot be converted to a number.
|
* or if the value is not a number and cannot be converted to a number.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public double optDouble(int index) {
|
public double optDouble(int index) {
|
||||||
return this.optDouble(index, Double.NaN);
|
return this.optDouble(index, Double.NaN);
|
||||||
@@ -414,7 +414,7 @@ public class JSONArray {
|
|||||||
*
|
*
|
||||||
* @param index subscript
|
* @param index subscript
|
||||||
* @param defaultValue The default value.
|
* @param defaultValue The default value.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public double optDouble(int index, double defaultValue) {
|
public double optDouble(int index, double defaultValue) {
|
||||||
try {
|
try {
|
||||||
@@ -430,7 +430,7 @@ public class JSONArray {
|
|||||||
* or if the value is not a number and cannot be converted to a number.
|
* or if the value is not a number and cannot be converted to a number.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public int optInt(int index) {
|
public int optInt(int index) {
|
||||||
return this.optInt(index, 0);
|
return this.optInt(index, 0);
|
||||||
@@ -442,7 +442,7 @@ public class JSONArray {
|
|||||||
* or if the value is not a number and cannot be converted to a number.
|
* or if the value is not a number and cannot be converted to a number.
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @param defaultValue The default value.
|
* @param defaultValue The default value.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public int optInt(int index, int defaultValue) {
|
public int optInt(int index, int defaultValue) {
|
||||||
try {
|
try {
|
||||||
@@ -455,7 +455,7 @@ public class JSONArray {
|
|||||||
/**
|
/**
|
||||||
* Get the optional JSONArray associated with an index.
|
* Get the optional JSONArray associated with an index.
|
||||||
* @param index subscript
|
* @param index subscript
|
||||||
* @return A JSONArray value, or null if the index has no value,
|
* @return A JSONArray value, or null if the index has no value,
|
||||||
* or if the value is not a JSONArray.
|
* or if the value is not a JSONArray.
|
||||||
*/
|
*/
|
||||||
public JSONArray optJSONArray(int index) {
|
public JSONArray optJSONArray(int index) {
|
||||||
@@ -469,7 +469,7 @@ public class JSONArray {
|
|||||||
* no value, or if the value is not a JSONObject.
|
* no value, or if the value is not a JSONObject.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return A JSONObject value.
|
* @return A JSONObject value.
|
||||||
*/
|
*/
|
||||||
public JSONObject optJSONObject(int index) {
|
public JSONObject optJSONObject(int index) {
|
||||||
Object o = this.opt(index);
|
Object o = this.opt(index);
|
||||||
@@ -482,7 +482,7 @@ public class JSONArray {
|
|||||||
* or if the value is not a number and cannot be converted to a number.
|
* or if the value is not a number and cannot be converted to a number.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public long optLong(int index) {
|
public long optLong(int index) {
|
||||||
return this.optLong(index, 0);
|
return this.optLong(index, 0);
|
||||||
@@ -494,7 +494,7 @@ public class JSONArray {
|
|||||||
* or if the value is not a number and cannot be converted to a number.
|
* or if the value is not a number and cannot be converted to a number.
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @param defaultValue The default value.
|
* @param defaultValue The default value.
|
||||||
* @return The value.
|
* @return The value.
|
||||||
*/
|
*/
|
||||||
public long optLong(int index, long defaultValue) {
|
public long optLong(int index, long defaultValue) {
|
||||||
try {
|
try {
|
||||||
@@ -510,7 +510,7 @@ public class JSONArray {
|
|||||||
* is not a string and is not null, then it is coverted to a string.
|
* is not a string and is not null, then it is coverted to a string.
|
||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @return A String value.
|
* @return A String value.
|
||||||
*/
|
*/
|
||||||
public String optString(int index) {
|
public String optString(int index) {
|
||||||
return this.optString(index, "");
|
return this.optString(index, "");
|
||||||
@@ -522,7 +522,7 @@ public class JSONArray {
|
|||||||
*
|
*
|
||||||
* @param index The index must be between 0 and length() - 1.
|
* @param index The index must be between 0 and length() - 1.
|
||||||
* @param defaultValue The default value.
|
* @param defaultValue The default value.
|
||||||
* @return A String value.
|
* @return A String value.
|
||||||
*/
|
*/
|
||||||
public String optString(int index, String defaultValue) {
|
public String optString(int index, String defaultValue) {
|
||||||
Object object = this.opt(index);
|
Object object = this.opt(index);
|
||||||
@@ -546,7 +546,7 @@ public class JSONArray {
|
|||||||
* Put a value in the JSONArray, where the value will be a
|
* Put a value in the JSONArray, where the value will be a
|
||||||
* JSONArray which is produced from a Collection.
|
* JSONArray which is produced from a Collection.
|
||||||
* @param value A Collection value.
|
* @param value A Collection value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(Collection<?> value) {
|
public JSONArray put(Collection<?> value) {
|
||||||
this.put(new JSONArray(value));
|
this.put(new JSONArray(value));
|
||||||
@@ -593,7 +593,7 @@ public class JSONArray {
|
|||||||
* Put a value in the JSONArray, where the value will be a
|
* Put a value in the JSONArray, where the value will be a
|
||||||
* JSONObject which is produced from a Map.
|
* JSONObject which is produced from a Map.
|
||||||
* @param value A Map value.
|
* @param value A Map value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(Map<?, ?> value) {
|
public JSONArray put(Map<?, ?> value) {
|
||||||
this.put(new JSONObject(value));
|
this.put(new JSONObject(value));
|
||||||
@@ -631,7 +631,7 @@ public class JSONArray {
|
|||||||
* JSONArray which is produced from a Collection.
|
* JSONArray which is produced from a Collection.
|
||||||
* @param index The subscript.
|
* @param index The subscript.
|
||||||
* @param value A Collection value.
|
* @param value A Collection value.
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws JSONException If the index is negative or if the value is
|
* @throws JSONException If the index is negative or if the value is
|
||||||
* not finite.
|
* not finite.
|
||||||
*/
|
*/
|
||||||
@@ -688,7 +688,7 @@ public class JSONArray {
|
|||||||
* JSONObject that is produced from a Map.
|
* JSONObject that is produced from a Map.
|
||||||
* @param index The subscript.
|
* @param index The subscript.
|
||||||
* @param value The Map value.
|
* @param value The Map value.
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws JSONException If the index is negative or if the the value is
|
* @throws JSONException If the index is negative or if the the value is
|
||||||
* an invalid number.
|
* an invalid number.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class JSONObject {
|
|||||||
/**
|
/**
|
||||||
* There is only intended to be a single instance of the NULL object,
|
* There is only intended to be a single instance of the NULL object,
|
||||||
* so the clone method returns itself.
|
* so the clone method returns itself.
|
||||||
* @return NULL.
|
* @return NULL.
|
||||||
*/
|
*/
|
||||||
protected final Object clone() {
|
protected final Object clone() {
|
||||||
return this;
|
return this;
|
||||||
@@ -196,16 +196,16 @@ public class JSONObject {
|
|||||||
if (x.nextClean() != '{') {
|
if (x.nextClean() != '{') {
|
||||||
throw x.syntaxError("A JSONObject text must begin with '{'");
|
throw x.syntaxError("A JSONObject text must begin with '{'");
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (; ; ) {
|
||||||
c = x.nextClean();
|
c = x.nextClean();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0:
|
case 0:
|
||||||
throw x.syntaxError("A JSONObject text must end with '}'");
|
throw x.syntaxError("A JSONObject text must end with '}'");
|
||||||
case '}':
|
case '}':
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
x.back();
|
x.back();
|
||||||
key = x.nextValue().toString();
|
key = x.nextValue().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The key is followed by ':'. We will also tolerate '=' or '=>'.
|
// The key is followed by ':'. We will also tolerate '=' or '=>'.
|
||||||
@@ -223,17 +223,17 @@ public class JSONObject {
|
|||||||
// Pairs are separated by ','. We will also tolerate ';'.
|
// Pairs are separated by ','. We will also tolerate ';'.
|
||||||
|
|
||||||
switch (x.nextClean()) {
|
switch (x.nextClean()) {
|
||||||
case ';':
|
case ';':
|
||||||
case ',':
|
case ',':
|
||||||
if (x.nextClean() == '}') {
|
if (x.nextClean() == '}') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
x.back();
|
||||||
|
break;
|
||||||
|
case '}':
|
||||||
return;
|
return;
|
||||||
}
|
default:
|
||||||
x.back();
|
throw x.syntaxError("Expected a ',' or '}'");
|
||||||
break;
|
|
||||||
case '}':
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
throw x.syntaxError("Expected a ',' or '}'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,7 +377,7 @@ public class JSONObject {
|
|||||||
public JSONObject accumulate(
|
public JSONObject accumulate(
|
||||||
String key,
|
String key,
|
||||||
Object value
|
Object value
|
||||||
) throws JSONException {
|
) throws JSONException {
|
||||||
testValidity(value);
|
testValidity(value);
|
||||||
Object object = this.opt(key);
|
Object object = this.opt(key);
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
@@ -447,8 +447,8 @@ public class JSONObject {
|
|||||||
* Get the value object associated with a key.
|
* Get the value object associated with a key.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return The object associated with the key.
|
* @return The object associated with the key.
|
||||||
* @throws JSONException if the key is not found.
|
* @throws JSONException if the key is not found.
|
||||||
*/
|
*/
|
||||||
public Object get(String key) throws JSONException {
|
public Object get(String key) throws JSONException {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
@@ -466,19 +466,19 @@ public class JSONObject {
|
|||||||
* Get the boolean value associated with a key.
|
* Get the boolean value associated with a key.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return The truth.
|
* @return The truth.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
* if the value is not a Boolean or the String "true" or "false".
|
* if the value is not a Boolean or the String "true" or "false".
|
||||||
*/
|
*/
|
||||||
public boolean getBoolean(String key) throws JSONException {
|
public boolean getBoolean(String key) throws JSONException {
|
||||||
Object object = this.get(key);
|
Object object = this.get(key);
|
||||||
if (object.equals(Boolean.FALSE) ||
|
if (object.equals(Boolean.FALSE) ||
|
||||||
(object instanceof String &&
|
(object instanceof String &&
|
||||||
((String) object).equalsIgnoreCase("false"))) {
|
((String) object).equalsIgnoreCase("false"))) {
|
||||||
return false;
|
return false;
|
||||||
} else if (object.equals(Boolean.TRUE) ||
|
} else if (object.equals(Boolean.TRUE) ||
|
||||||
(object instanceof String &&
|
(object instanceof String &&
|
||||||
((String) object).equalsIgnoreCase("true"))) {
|
((String) object).equalsIgnoreCase("true"))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
throw new JSONException("JSONObject[" + quote(key) +
|
throw new JSONException("JSONObject[" + quote(key) +
|
||||||
@@ -488,7 +488,7 @@ public class JSONObject {
|
|||||||
/**
|
/**
|
||||||
* Get the double value associated with a key.
|
* Get the double value associated with a key.
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return The numeric value.
|
* @return The numeric value.
|
||||||
* @throws JSONException if the key is not found or
|
* @throws JSONException if the key is not found or
|
||||||
* if the value is not a Number object and cannot be converted to a number.
|
* if the value is not a Number object and cannot be converted to a number.
|
||||||
*/
|
*/
|
||||||
@@ -508,8 +508,8 @@ public class JSONObject {
|
|||||||
* Get the int value associated with a key.
|
* Get the int value associated with a key.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return The integer value.
|
* @return The integer value.
|
||||||
* @throws JSONException if the key is not found or if the value cannot
|
* @throws JSONException if the key is not found or if the value cannot
|
||||||
* be converted to an integer.
|
* be converted to an integer.
|
||||||
*/
|
*/
|
||||||
public int getInt(String key) throws JSONException {
|
public int getInt(String key) throws JSONException {
|
||||||
@@ -528,8 +528,8 @@ public class JSONObject {
|
|||||||
* Get the JSONArray value associated with a key.
|
* Get the JSONArray value associated with a key.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return A JSONArray which is the value.
|
* @return A JSONArray which is the value.
|
||||||
* @throws JSONException if the key is not found or
|
* @throws JSONException if the key is not found or
|
||||||
* if the value is not a JSONArray.
|
* if the value is not a JSONArray.
|
||||||
*/
|
*/
|
||||||
public JSONArray getJSONArray(String key) throws JSONException {
|
public JSONArray getJSONArray(String key) throws JSONException {
|
||||||
@@ -545,8 +545,8 @@ public class JSONObject {
|
|||||||
* Get the JSONObject value associated with a key.
|
* Get the JSONObject value associated with a key.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return A JSONObject which is the value.
|
* @return A JSONObject which is the value.
|
||||||
* @throws JSONException if the key is not found or
|
* @throws JSONException if the key is not found or
|
||||||
* if the value is not a JSONObject.
|
* if the value is not a JSONObject.
|
||||||
*/
|
*/
|
||||||
public JSONObject getJSONObject(String key) throws JSONException {
|
public JSONObject getJSONObject(String key) throws JSONException {
|
||||||
@@ -562,8 +562,8 @@ public class JSONObject {
|
|||||||
* Get the long value associated with a key.
|
* Get the long value associated with a key.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return The long value.
|
* @return The long value.
|
||||||
* @throws JSONException if the key is not found or if the value cannot
|
* @throws JSONException if the key is not found or if the value cannot
|
||||||
* be converted to a long.
|
* be converted to a long.
|
||||||
*/
|
*/
|
||||||
public long getLong(String key) throws JSONException {
|
public long getLong(String key) throws JSONException {
|
||||||
@@ -624,8 +624,8 @@ public class JSONObject {
|
|||||||
* Get the string associated with a key.
|
* Get the string associated with a key.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return A string which is the value.
|
* @return A string which is the value.
|
||||||
* @throws JSONException if there is no string value for the key.
|
* @throws JSONException if there is no string value for the key.
|
||||||
*/
|
*/
|
||||||
public String getString(String key) throws JSONException {
|
public String getString(String key) throws JSONException {
|
||||||
Object object = this.get(key);
|
Object object = this.get(key);
|
||||||
@@ -639,7 +639,7 @@ public class JSONObject {
|
|||||||
/**
|
/**
|
||||||
* Determine if the JSONObject contains a specific key.
|
* Determine if the JSONObject contains a specific key.
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return true if the key exists in the JSONObject.
|
* @return true if the key exists in the JSONObject.
|
||||||
*/
|
*/
|
||||||
public boolean has(String key) {
|
public boolean has(String key) {
|
||||||
return this.map.containsKey(key);
|
return this.map.containsKey(key);
|
||||||
@@ -676,7 +676,7 @@ public class JSONObject {
|
|||||||
* Determine if the value associated with the key is null or if there is
|
* Determine if the value associated with the key is null or if there is
|
||||||
* no value.
|
* no value.
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return true if there is no value associated with the key or if
|
* @return true if there is no value associated with the key or if
|
||||||
* the value is the JSONObject.NULL object.
|
* the value is the JSONObject.NULL object.
|
||||||
*/
|
*/
|
||||||
public boolean isNull(String key) {
|
public boolean isNull(String key) {
|
||||||
@@ -756,7 +756,7 @@ public class JSONObject {
|
|||||||
/**
|
/**
|
||||||
* Get an optional value associated with a key.
|
* Get an optional value associated with a key.
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return An object which is the value, or null if there is no value.
|
* @return An object which is the value, or null if there is no value.
|
||||||
*/
|
*/
|
||||||
public Object opt(String key) {
|
public Object opt(String key) {
|
||||||
return key == null ? null : this.map.get(key);
|
return key == null ? null : this.map.get(key);
|
||||||
@@ -768,7 +768,7 @@ public class JSONObject {
|
|||||||
* Boolean.TRUE or the String "true".
|
* Boolean.TRUE or the String "true".
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return The truth.
|
* @return The truth.
|
||||||
*/
|
*/
|
||||||
public boolean optBoolean(String key) {
|
public boolean optBoolean(String key) {
|
||||||
return this.optBoolean(key, false);
|
return this.optBoolean(key, false);
|
||||||
@@ -781,7 +781,7 @@ public class JSONObject {
|
|||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @param defaultValue The default.
|
* @param defaultValue The default.
|
||||||
* @return The truth.
|
* @return The truth.
|
||||||
*/
|
*/
|
||||||
public boolean optBoolean(String key, boolean defaultValue) {
|
public boolean optBoolean(String key, boolean defaultValue) {
|
||||||
try {
|
try {
|
||||||
@@ -798,7 +798,7 @@ public class JSONObject {
|
|||||||
* a number.
|
* a number.
|
||||||
*
|
*
|
||||||
* @param key A string which is the key.
|
* @param key A string which is the key.
|
||||||
* @return An object which is the value.
|
* @return An object which is the value.
|
||||||
*/
|
*/
|
||||||
public double optDouble(String key) {
|
public double optDouble(String key) {
|
||||||
return this.optDouble(key, Double.NaN);
|
return this.optDouble(key, Double.NaN);
|
||||||
@@ -812,7 +812,7 @@ public class JSONObject {
|
|||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @param defaultValue The default.
|
* @param defaultValue The default.
|
||||||
* @return An object which is the value.
|
* @return An object which is the value.
|
||||||
*/
|
*/
|
||||||
public double optDouble(String key, double defaultValue) {
|
public double optDouble(String key, double defaultValue) {
|
||||||
try {
|
try {
|
||||||
@@ -829,7 +829,7 @@ public class JSONObject {
|
|||||||
* a number.
|
* a number.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return An object which is the value.
|
* @return An object which is the value.
|
||||||
*/
|
*/
|
||||||
public int optInt(String key) {
|
public int optInt(String key) {
|
||||||
return this.optInt(key, 0);
|
return this.optInt(key, 0);
|
||||||
@@ -843,7 +843,7 @@ public class JSONObject {
|
|||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @param defaultValue The default.
|
* @param defaultValue The default.
|
||||||
* @return An object which is the value.
|
* @return An object which is the value.
|
||||||
*/
|
*/
|
||||||
public int optInt(String key, int defaultValue) {
|
public int optInt(String key, int defaultValue) {
|
||||||
try {
|
try {
|
||||||
@@ -859,7 +859,7 @@ public class JSONObject {
|
|||||||
* JSONArray.
|
* JSONArray.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return A JSONArray which is the value.
|
* @return A JSONArray which is the value.
|
||||||
*/
|
*/
|
||||||
public JSONArray optJSONArray(String key) {
|
public JSONArray optJSONArray(String key) {
|
||||||
Object o = this.opt(key);
|
Object o = this.opt(key);
|
||||||
@@ -872,7 +872,7 @@ public class JSONObject {
|
|||||||
* JSONObject.
|
* JSONObject.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return A JSONObject which is the value.
|
* @return A JSONObject which is the value.
|
||||||
*/
|
*/
|
||||||
public JSONObject optJSONObject(String key) {
|
public JSONObject optJSONObject(String key) {
|
||||||
Object object = this.opt(key);
|
Object object = this.opt(key);
|
||||||
@@ -886,7 +886,7 @@ public class JSONObject {
|
|||||||
* a number.
|
* a number.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return An object which is the value.
|
* @return An object which is the value.
|
||||||
*/
|
*/
|
||||||
public long optLong(String key) {
|
public long optLong(String key) {
|
||||||
return this.optLong(key, 0);
|
return this.optLong(key, 0);
|
||||||
@@ -900,7 +900,7 @@ public class JSONObject {
|
|||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @param defaultValue The default.
|
* @param defaultValue The default.
|
||||||
* @return An object which is the value.
|
* @return An object which is the value.
|
||||||
*/
|
*/
|
||||||
public long optLong(String key, long defaultValue) {
|
public long optLong(String key, long defaultValue) {
|
||||||
try {
|
try {
|
||||||
@@ -916,7 +916,7 @@ public class JSONObject {
|
|||||||
* a string and is not null, then it is converted to a string.
|
* a string and is not null, then it is converted to a string.
|
||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @return A string which is the value.
|
* @return A string which is the value.
|
||||||
*/
|
*/
|
||||||
public String optString(String key) {
|
public String optString(String key) {
|
||||||
return this.optString(key, "");
|
return this.optString(key, "");
|
||||||
@@ -928,7 +928,7 @@ public class JSONObject {
|
|||||||
*
|
*
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @param defaultValue The default.
|
* @param defaultValue The default.
|
||||||
* @return A string which is the value.
|
* @return A string which is the value.
|
||||||
*/
|
*/
|
||||||
public String optString(String key, String defaultValue) {
|
public String optString(String key, String defaultValue) {
|
||||||
Object object = this.opt(key);
|
Object object = this.opt(key);
|
||||||
@@ -1000,7 +1000,7 @@ public class JSONObject {
|
|||||||
* JSONArray which is produced from a Collection.
|
* JSONArray which is produced from a Collection.
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @param value A Collection value.
|
* @param value A Collection value.
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public JSONObject put(String key, Collection value) throws JSONException {
|
public JSONObject put(String key, Collection value) throws JSONException {
|
||||||
@@ -1052,7 +1052,7 @@ public class JSONObject {
|
|||||||
* JSONObject which is produced from a Map.
|
* JSONObject which is produced from a Map.
|
||||||
* @param key A key string.
|
* @param key A key string.
|
||||||
* @param value A Map value.
|
* @param value A Map value.
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public JSONObject put(String key, Map value) throws JSONException {
|
public JSONObject put(String key, Map value) throws JSONException {
|
||||||
@@ -1136,7 +1136,7 @@ public class JSONObject {
|
|||||||
* allowing JSON text to be delivered in HTML. In JSON text, a string
|
* allowing JSON text to be delivered in HTML. In JSON text, a string
|
||||||
* cannot contain a control character or an unescaped quote or backslash.
|
* cannot contain a control character or an unescaped quote or backslash.
|
||||||
* @param string A String
|
* @param string A String
|
||||||
* @return A String correctly formatted for insertion in a JSON text.
|
* @return A String correctly formatted for insertion in a JSON text.
|
||||||
*/
|
*/
|
||||||
public static String quote(String string) {
|
public static String quote(String string) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
@@ -1167,42 +1167,42 @@ public class JSONObject {
|
|||||||
b = c;
|
b = c;
|
||||||
c = string.charAt(i);
|
c = string.charAt(i);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\\':
|
case '\\':
|
||||||
case '"':
|
case '"':
|
||||||
w.write('\\');
|
|
||||||
w.write(c);
|
|
||||||
break;
|
|
||||||
case '/':
|
|
||||||
if (b == '<') {
|
|
||||||
w.write('\\');
|
w.write('\\');
|
||||||
}
|
|
||||||
w.write(c);
|
|
||||||
break;
|
|
||||||
case '\b':
|
|
||||||
w.write("\\b");
|
|
||||||
break;
|
|
||||||
case '\t':
|
|
||||||
w.write("\\t");
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
w.write("\\n");
|
|
||||||
break;
|
|
||||||
case '\f':
|
|
||||||
w.write("\\f");
|
|
||||||
break;
|
|
||||||
case '\r':
|
|
||||||
w.write("\\r");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
|
|
||||||
|| (c >= '\u2000' && c < '\u2100')) {
|
|
||||||
w.write("\\u");
|
|
||||||
hhhh = Integer.toHexString(c);
|
|
||||||
w.write("0000", 0, 4 - hhhh.length());
|
|
||||||
w.write(hhhh);
|
|
||||||
} else {
|
|
||||||
w.write(c);
|
w.write(c);
|
||||||
}
|
break;
|
||||||
|
case '/':
|
||||||
|
if (b == '<') {
|
||||||
|
w.write('\\');
|
||||||
|
}
|
||||||
|
w.write(c);
|
||||||
|
break;
|
||||||
|
case '\b':
|
||||||
|
w.write("\\b");
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
w.write("\\t");
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
w.write("\\n");
|
||||||
|
break;
|
||||||
|
case '\f':
|
||||||
|
w.write("\\f");
|
||||||
|
break;
|
||||||
|
case '\r':
|
||||||
|
w.write("\\r");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
|
||||||
|
|| (c >= '\u2000' && c < '\u2100')) {
|
||||||
|
w.write("\\u");
|
||||||
|
hhhh = Integer.toHexString(c);
|
||||||
|
w.write("0000", 0, 4 - hhhh.length());
|
||||||
|
w.write(hhhh);
|
||||||
|
} else {
|
||||||
|
w.write(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.write('"');
|
w.write('"');
|
||||||
@@ -1471,7 +1471,7 @@ public class JSONObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static final Writer writeValue(Writer writer, Object value,
|
static final Writer writeValue(Writer writer, Object value,
|
||||||
int indentFactor, int indent) throws JSONException, IOException {
|
int indentFactor, int indent) throws JSONException, IOException {
|
||||||
if (value == null || value.equals(null)) {
|
if (value == null || value.equals(null)) {
|
||||||
writer.write("null");
|
writer.write("null");
|
||||||
} else if (value instanceof JSONObject) {
|
} else if (value instanceof JSONObject) {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class JSONTokener {
|
|||||||
* Get the hex value of a character (base16).
|
* Get the hex value of a character (base16).
|
||||||
* @param c A character between '0' and '9' or between 'A' and 'F' or
|
* @param c A character between '0' and '9' or between 'A' and 'F' or
|
||||||
* between 'a' and 'f'.
|
* between 'a' and 'f'.
|
||||||
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
||||||
*/
|
*/
|
||||||
public static int dehexchar(char c) {
|
public static int dehexchar(char c) {
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
@@ -189,7 +189,7 @@ public class JSONTokener {
|
|||||||
* Get the next n characters.
|
* Get the next n characters.
|
||||||
*
|
*
|
||||||
* @param n The number of characters to take.
|
* @param n The number of characters to take.
|
||||||
* @return A string of n characters.
|
* @return A string of n characters.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
* Substring bounds error if there are not
|
* Substring bounds error if there are not
|
||||||
* n characters remaining in the source string.
|
* n characters remaining in the source string.
|
||||||
@@ -215,10 +215,10 @@ public class JSONTokener {
|
|||||||
/**
|
/**
|
||||||
* Get the next char in the string, skipping whitespace.
|
* Get the next char in the string, skipping whitespace.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
* @return A character, or 0 if there are no more characters.
|
* @return A character, or 0 if there are no more characters.
|
||||||
*/
|
*/
|
||||||
public char nextClean() throws JSONException {
|
public char nextClean() throws JSONException {
|
||||||
for (;;) {
|
for (; ; ) {
|
||||||
char c = this.next();
|
char c = this.next();
|
||||||
if (c == 0 || c > ' ') {
|
if (c == 0 || c > ' ') {
|
||||||
return c;
|
return c;
|
||||||
@@ -234,55 +234,55 @@ public class JSONTokener {
|
|||||||
* @param quote The quoting character, either
|
* @param quote The quoting character, either
|
||||||
* <code>"</code> <small>(double quote)</small> or
|
* <code>"</code> <small>(double quote)</small> or
|
||||||
* <code>'</code> <small>(single quote)</small>.
|
* <code>'</code> <small>(single quote)</small>.
|
||||||
* @return A String.
|
* @return A String.
|
||||||
* @throws JSONException Unterminated string.
|
* @throws JSONException Unterminated string.
|
||||||
*/
|
*/
|
||||||
public String nextString(char quote) throws JSONException {
|
public String nextString(char quote) throws JSONException {
|
||||||
char c;
|
char c;
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (;;) {
|
for (; ; ) {
|
||||||
c = this.next();
|
c = this.next();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0:
|
case 0:
|
||||||
case '\n':
|
case '\n':
|
||||||
case '\r':
|
case '\r':
|
||||||
throw this.syntaxError("Unterminated string");
|
throw this.syntaxError("Unterminated string");
|
||||||
case '\\':
|
|
||||||
c = this.next();
|
|
||||||
switch (c) {
|
|
||||||
case 'b':
|
|
||||||
sb.append('\b');
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
sb.append('\t');
|
|
||||||
break;
|
|
||||||
case 'n':
|
|
||||||
sb.append('\n');
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
sb.append('\f');
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
sb.append('\r');
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
sb.append((char) Integer.parseInt(this.next(4), 16));
|
|
||||||
break;
|
|
||||||
case '"':
|
|
||||||
case '\'':
|
|
||||||
case '\\':
|
case '\\':
|
||||||
case '/':
|
c = this.next();
|
||||||
sb.append(c);
|
switch (c) {
|
||||||
|
case 'b':
|
||||||
|
sb.append('\b');
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
sb.append('\t');
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
sb.append('\n');
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
sb.append('\f');
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
sb.append('\r');
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
sb.append((char) Integer.parseInt(this.next(4), 16));
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
case '\'':
|
||||||
|
case '\\':
|
||||||
|
case '/':
|
||||||
|
sb.append(c);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw this.syntaxError("Illegal escape.");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw this.syntaxError("Illegal escape.");
|
if (c == quote) {
|
||||||
}
|
return sb.toString();
|
||||||
break;
|
}
|
||||||
default:
|
sb.append(c);
|
||||||
if (c == quote) {
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
sb.append(c);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -291,11 +291,11 @@ public class JSONTokener {
|
|||||||
* Get the text up but not including the specified character or the
|
* Get the text up but not including the specified character or the
|
||||||
* end of line, whichever comes first.
|
* end of line, whichever comes first.
|
||||||
* @param delimiter A delimiter character.
|
* @param delimiter A delimiter character.
|
||||||
* @return A string.
|
* @return A string.
|
||||||
*/
|
*/
|
||||||
public String nextTo(char delimiter) throws JSONException {
|
public String nextTo(char delimiter) throws JSONException {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (;;) {
|
for (; ; ) {
|
||||||
char c = this.next();
|
char c = this.next();
|
||||||
if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
|
if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
|
||||||
if (c != 0) {
|
if (c != 0) {
|
||||||
@@ -316,7 +316,7 @@ public class JSONTokener {
|
|||||||
public String nextTo(String delimiters) throws JSONException {
|
public String nextTo(String delimiters) throws JSONException {
|
||||||
char c;
|
char c;
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (;;) {
|
for (; ; ) {
|
||||||
c = this.next();
|
c = this.next();
|
||||||
if (delimiters.indexOf(c) >= 0 || c == 0 ||
|
if (delimiters.indexOf(c) >= 0 || c == 0 ||
|
||||||
c == '\n' || c == '\r') {
|
c == '\n' || c == '\r') {
|
||||||
@@ -341,15 +341,15 @@ public class JSONTokener {
|
|||||||
String string;
|
String string;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '"':
|
case '"':
|
||||||
case '\'':
|
case '\'':
|
||||||
return this.nextString(c);
|
return this.nextString(c);
|
||||||
case '{':
|
case '{':
|
||||||
this.back();
|
this.back();
|
||||||
return new JSONObject(this);
|
return new JSONObject(this);
|
||||||
case '[':
|
case '[':
|
||||||
this.back();
|
this.back();
|
||||||
return new JSONArray(this);
|
return new JSONArray(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -411,7 +411,7 @@ public class JSONTokener {
|
|||||||
* Make a JSONException to signal a syntax error.
|
* Make a JSONException to signal a syntax error.
|
||||||
*
|
*
|
||||||
* @param message The error message.
|
* @param message The error message.
|
||||||
* @return A JSONException object, suitable for throwing
|
* @return A JSONException object, suitable for throwing
|
||||||
*/
|
*/
|
||||||
public JSONException syntaxError(String message) {
|
public JSONException syntaxError(String message) {
|
||||||
return new JSONException(message + this.toString());
|
return new JSONException(message + this.toString());
|
||||||
|
|||||||
Reference in New Issue
Block a user