+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-/**\r
- * This provides static methods to convert comma delimited text into a\r
- * JSONArray, and to covert a JSONArray into comma delimited text. Comma\r
- * delimited text is a very popular format for data interchange. It is\r
- * understood by most database, spreadsheet, and organizer programs.\r
- * <p>\r
- * Each row of text represents a row in a table or a data record. Each row\r
- * ends with a NEWLINE character. Each row contains one or more values.\r
- * Values are separated by commas. A value can contain any character except\r
- * for comma, unless is is wrapped in single quotes or double quotes.\r
- * <p>\r
- * The first row usually contains the names of the columns.\r
- * <p>\r
- * A comma delimited list can be converted into a JSONArray of JSONObjects.\r
- * The names for the elements in the JSONObjects can be taken from the names\r
- * in the first row.\r
- * @author JSON.org\r
- * @version 2012-11-13\r
- */\r
-public class CDL {\r
-\r
- /**\r
- * Get the next value. The value can be wrapped in quotes. The value can\r
- * be empty.\r
- * @param x A JSONTokener of the source text.\r
- * @return The value string, or null if empty.\r
- * @throws JSONException if the quoted string is badly formed.\r
- */\r
- private static String getValue(JSONTokener x) throws JSONException {\r
- char c;\r
- char q;\r
- StringBuffer sb;\r
- do {\r
- c = x.next();\r
- } while (c == ' ' || c == '\t');\r
- switch (c) {\r
- case 0:\r
- return null;\r
- case '"':\r
- case '\'':\r
- q = c;\r
- sb = new StringBuffer();\r
- for (;;) {\r
- c = x.next();\r
- if (c == q) {\r
- break;\r
- }\r
- if (c == 0 || c == '\n' || c == '\r') {\r
- throw x.syntaxError("Missing close quote '" + q + "'.");\r
- }\r
- sb.append(c);\r
- }\r
- return sb.toString();\r
- case ',':\r
- x.back();\r
- return "";\r
- default:\r
- x.back();\r
- return x.nextTo(',');\r
- }\r
- }\r
-\r
- /**\r
- * Produce a JSONArray of strings from a row of comma delimited values.\r
- * @param x A JSONTokener of the source text.\r
- * @return A JSONArray of strings.\r
- * @throws JSONException\r
- */\r
- public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {\r
- JSONArray ja = new JSONArray();\r
- for (;;) {\r
- String value = getValue(x);\r
- char c = x.next();\r
- if (value == null ||\r
- (ja.length() == 0 && value.length() == 0 && c != ',')) {\r
- return null;\r
- }\r
- ja.put(value);\r
- for (;;) {\r
- if (c == ',') {\r
- break;\r
- }\r
- if (c != ' ') {\r
- if (c == '\n' || c == '\r' || c == 0) {\r
- return ja;\r
- }\r
- throw x.syntaxError("Bad character '" + c + "' (" +\r
- (int)c + ").");\r
- }\r
- c = x.next();\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Produce a JSONObject from a row of comma delimited text, using a\r
- * parallel JSONArray of strings to provides the names of the elements.\r
- * @param names A JSONArray of names. This is commonly obtained from the\r
- * first row of a comma delimited text file using the rowToJSONArray\r
- * method.\r
- * @param x A JSONTokener of the source text.\r
- * @return A JSONObject combining the names and values.\r
- * @throws JSONException\r
- */\r
- public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)\r
- throws JSONException {\r
- JSONArray ja = rowToJSONArray(x);\r
- return ja != null ? ja.toJSONObject(names) : null;\r
- }\r
-\r
- /**\r
- * Produce a comma delimited text row from a JSONArray. Values containing\r
- * the comma character will be quoted. Troublesome characters may be\r
- * removed.\r
- * @param ja A JSONArray of strings.\r
- * @return A string ending in NEWLINE.\r
- */\r
- public static String rowToString(JSONArray ja) {\r
- StringBuffer sb = new StringBuffer();\r
- for (int i = 0; i < ja.length(); i += 1) {\r
- if (i > 0) {\r
- sb.append(',');\r
- }\r
- Object object = ja.opt(i);\r
- if (object != null) {\r
- String string = object.toString();\r
- if (string.length() > 0 && (string.indexOf(',') >= 0 ||\r
- string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 ||\r
- string.indexOf(0) >= 0 || string.charAt(0) == '"')) {\r
- sb.append('"');\r
- int length = string.length();\r
- for (int j = 0; j < length; j += 1) {\r
- char c = string.charAt(j);\r
- if (c >= ' ' && c != '"') {\r
- sb.append(c);\r
- }\r
- }\r
- sb.append('"');\r
- } else {\r
- sb.append(string);\r
- }\r
- }\r
- }\r
- sb.append('\n');\r
- return sb.toString();\r
- }\r
-\r
- /**\r
- * Produce a JSONArray of JSONObjects from a comma delimited text string,\r
- * using the first row as a source of names.\r
- * @param string The comma delimited text.\r
- * @return A JSONArray of JSONObjects.\r
- * @throws JSONException\r
- */\r
- public static JSONArray toJSONArray(String string) throws JSONException {\r
- return toJSONArray(new JSONTokener(string));\r
- }\r
-\r
- /**\r
- * Produce a JSONArray of JSONObjects from a comma delimited text string,\r
- * using the first row as a source of names.\r
- * @param x The JSONTokener containing the comma delimited text.\r
- * @return A JSONArray of JSONObjects.\r
- * @throws JSONException\r
- */\r
- public static JSONArray toJSONArray(JSONTokener x) throws JSONException {\r
- return toJSONArray(rowToJSONArray(x), x);\r
- }\r
-\r
- /**\r
- * Produce a JSONArray of JSONObjects from a comma delimited text string\r
- * using a supplied JSONArray as the source of element names.\r
- * @param names A JSONArray of strings.\r
- * @param string The comma delimited text.\r
- * @return A JSONArray of JSONObjects.\r
- * @throws JSONException\r
- */\r
- public static JSONArray toJSONArray(JSONArray names, String string)\r
- throws JSONException {\r
- return toJSONArray(names, new JSONTokener(string));\r
- }\r
-\r
- /**\r
- * Produce a JSONArray of JSONObjects from a comma delimited text string\r
- * using a supplied JSONArray as the source of element names.\r
- * @param names A JSONArray of strings.\r
- * @param x A JSONTokener of the source text.\r
- * @return A JSONArray of JSONObjects.\r
- * @throws JSONException\r
- */\r
- public static JSONArray toJSONArray(JSONArray names, JSONTokener x)\r
- throws JSONException {\r
- if (names == null || names.length() == 0) {\r
- return null;\r
- }\r
- JSONArray ja = new JSONArray();\r
- for (;;) {\r
- JSONObject jo = rowToJSONObject(names, x);\r
- if (jo == null) {\r
- break;\r
- }\r
- ja.put(jo);\r
- }\r
- if (ja.length() == 0) {\r
- return null;\r
- }\r
- return ja;\r
- }\r
-\r
-\r
- /**\r
- * Produce a comma delimited text from a JSONArray of JSONObjects. The\r
- * first row will be a list of names obtained by inspecting the first\r
- * JSONObject.\r
- * @param ja A JSONArray of JSONObjects.\r
- * @return A comma delimited text.\r
- * @throws JSONException\r
- */\r
- public static String toString(JSONArray ja) throws JSONException {\r
- JSONObject jo = ja.optJSONObject(0);\r
- if (jo != null) {\r
- JSONArray names = jo.names();\r
- if (names != null) {\r
- return rowToString(names) + toString(names, ja);\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- * Produce a comma delimited text from a JSONArray of JSONObjects using\r
- * a provided list of names. The list of names is not included in the\r
- * output.\r
- * @param names A JSONArray of strings.\r
- * @param ja A JSONArray of JSONObjects.\r
- * @return A comma delimited text.\r
- * @throws JSONException\r
- */\r
- public static String toString(JSONArray names, JSONArray ja)\r
- throws JSONException {\r
- if (names == null || names.length() == 0) {\r
- return null;\r
- }\r
- StringBuffer sb = new StringBuffer();\r
- for (int i = 0; i < ja.length(); i += 1) {\r
- JSONObject jo = ja.optJSONObject(i);\r
- if (jo != null) {\r
- sb.append(rowToString(jo.toJSONArray(names)));\r
- }\r
- }\r
- return sb.toString();\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-/**\r
- * Convert a web browser cookie specification to a JSONObject and back.\r
- * JSON and Cookies are both notations for name/value pairs.\r
- * @author JSON.org\r
- * @version 2010-12-24\r
- */\r
-public class Cookie {\r
-\r
- /**\r
- * Produce a copy of a string in which the characters '+', '%', '=', ';'\r
- * and control characters are replaced with "%hh". This is a gentle form\r
- * of URL encoding, attempting to cause as little distortion to the\r
- * string as possible. The characters '=' and ';' are meta characters in\r
- * cookies. By convention, they are escaped using the URL-encoding. This is\r
- * only a convention, not a standard. Often, cookies are expected to have\r
- * encoded values. We encode '=' and ';' because we must. We encode '%' and\r
- * '+' because they are meta characters in URL encoding.\r
- * @param string The source string.\r
- * @return The escaped result.\r
- */\r
- public static String escape(String string) {\r
- char c;\r
- String s = string.trim();\r
- StringBuffer sb = new StringBuffer();\r
- int length = s.length();\r
- for (int i = 0; i < length; i += 1) {\r
- c = s.charAt(i);\r
- if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') {\r
- sb.append('%');\r
- sb.append(Character.forDigit((char)((c >>> 4) & 0x0f), 16));\r
- sb.append(Character.forDigit((char)(c & 0x0f), 16));\r
- } else {\r
- sb.append(c);\r
- }\r
- }\r
- return sb.toString();\r
- }\r
-\r
-\r
- /**\r
- * Convert a cookie specification string into a JSONObject. The string\r
- * will contain a name value pair separated by '='. The name and the value\r
- * will be unescaped, possibly converting '+' and '%' sequences. The\r
- * cookie properties may follow, separated by ';', also represented as\r
- * name=value (except the secure property, which does not have a value).\r
- * The name will be stored under the key "name", and the value will be\r
- * stored under the key "value". This method does not do checking or\r
- * validation of the parameters. It only converts the cookie string into\r
- * a JSONObject.\r
- * @param string The cookie specification string.\r
- * @return A JSONObject containing "name", "value", and possibly other\r
- * members.\r
- * @throws JSONException\r
- */\r
- public static JSONObject toJSONObject(String string) throws JSONException {\r
- String name;\r
- JSONObject jo = new JSONObject();\r
- Object value;\r
- JSONTokener x = new JSONTokener(string);\r
- jo.put("name", x.nextTo('='));\r
- x.next('=');\r
- jo.put("value", x.nextTo(';'));\r
- x.next();\r
- while (x.more()) {\r
- name = unescape(x.nextTo("=;"));\r
- if (x.next() != '=') {\r
- if (name.equals("secure")) {\r
- value = Boolean.TRUE;\r
- } else {\r
- throw x.syntaxError("Missing '=' in cookie parameter.");\r
- }\r
- } else {\r
- value = unescape(x.nextTo(';'));\r
- x.next();\r
- }\r
- jo.put(name, value);\r
- }\r
- return jo;\r
- }\r
-\r
-\r
- /**\r
- * Convert a JSONObject into a cookie specification string. The JSONObject\r
- * must contain "name" and "value" members.\r
- * If the JSONObject contains "expires", "domain", "path", or "secure"\r
- * members, they will be appended to the cookie specification string.\r
- * All other members are ignored.\r
- * @param jo A JSONObject\r
- * @return A cookie specification string\r
- * @throws JSONException\r
- */\r
- public static String toString(JSONObject jo) throws JSONException {\r
- StringBuffer sb = new StringBuffer();\r
-\r
- sb.append(escape(jo.getString("name")));\r
- sb.append("=");\r
- sb.append(escape(jo.getString("value")));\r
- if (jo.has("expires")) {\r
- sb.append(";expires=");\r
- sb.append(jo.getString("expires"));\r
- }\r
- if (jo.has("domain")) {\r
- sb.append(";domain=");\r
- sb.append(escape(jo.getString("domain")));\r
- }\r
- if (jo.has("path")) {\r
- sb.append(";path=");\r
- sb.append(escape(jo.getString("path")));\r
- }\r
- if (jo.optBoolean("secure")) {\r
- sb.append(";secure");\r
- }\r
- return sb.toString();\r
- }\r
-\r
- /**\r
- * Convert <code>%</code><i>hh</i> sequences to single characters, and\r
- * convert plus to space.\r
- * @param string A string that may contain\r
- * <code>+</code> <small>(plus)</small> and\r
- * <code>%</code><i>hh</i> sequences.\r
- * @return The unescaped string.\r
- */\r
- public static String unescape(String string) {\r
- int length = string.length();\r
- StringBuffer sb = new StringBuffer();\r
- for (int i = 0; i < length; ++i) {\r
- char c = string.charAt(i);\r
- if (c == '+') {\r
- c = ' ';\r
- } else if (c == '%' && i + 2 < length) {\r
- int d = JSONTokener.dehexchar(string.charAt(i + 1));\r
- int e = JSONTokener.dehexchar(string.charAt(i + 2));\r
- if (d >= 0 && e >= 0) {\r
- c = (char)(d * 16 + e);\r
- i += 2;\r
- }\r
- }\r
- sb.append(c);\r
- }\r
- return sb.toString();\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-import java.util.Iterator;\r
-\r
-/**\r
- * Convert a web browser cookie list string to a JSONObject and back.\r
- * @author JSON.org\r
- * @version 2010-12-24\r
- */\r
-public class CookieList {\r
-\r
- /**\r
- * Convert a cookie list into a JSONObject. A cookie list is a sequence\r
- * of name/value pairs. The names are separated from the values by '='.\r
- * The pairs are separated by ';'. The names and the values\r
- * will be unescaped, possibly converting '+' and '%' sequences.\r
- *\r
- * To add a cookie to a cooklist,\r
- * cookielistJSONObject.put(cookieJSONObject.getString("name"),\r
- * cookieJSONObject.getString("value"));\r
- * @param string A cookie list string\r
- * @return A JSONObject\r
- * @throws JSONException\r
- */\r
- public static JSONObject toJSONObject(String string) throws JSONException {\r
- JSONObject jo = new JSONObject();\r
- JSONTokener x = new JSONTokener(string);\r
- while (x.more()) {\r
- String name = Cookie.unescape(x.nextTo('='));\r
- x.next('=');\r
- jo.put(name, Cookie.unescape(x.nextTo(';')));\r
- x.next();\r
- }\r
- return jo;\r
- }\r
-\r
-\r
- /**\r
- * Convert a JSONObject into a cookie list. A cookie list is a sequence\r
- * of name/value pairs. The names are separated from the values by '='.\r
- * The pairs are separated by ';'. The characters '%', '+', '=', and ';'\r
- * in the names and values are replaced by "%hh".\r
- * @param jo A JSONObject\r
- * @return A cookie list string\r
- * @throws JSONException\r
- */\r
- public static String toString(JSONObject jo) throws JSONException {\r
- boolean b = false;\r
- Iterator<String> keys = jo.keys();\r
- String string;\r
- StringBuffer sb = new StringBuffer();\r
- while (keys.hasNext()) {\r
- string = keys.next().toString();\r
- if (!jo.isNull(string)) {\r
- if (b) {\r
- sb.append(';');\r
- }\r
- sb.append(Cookie.escape(string));\r
- sb.append("=");\r
- sb.append(Cookie.escape(jo.getString(string)));\r
- b = true;\r
- }\r
- }\r
- return sb.toString();\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-import java.util.Iterator;\r
-\r
-/**\r
- * Convert an HTTP header to a JSONObject and back.\r
- * @author JSON.org\r
- * @version 2010-12-24\r
- */\r
-public class HTTP {\r
-\r
- /** Carriage return/line feed. */\r
- public static final String CRLF = "\r\n";\r
-\r
- /**\r
- * Convert an HTTP header string into a JSONObject. It can be a request\r
- * header or a response header. A request header will contain\r
- * <pre>{\r
- * Method: "POST" (for example),\r
- * "Request-URI": "/" (for example),\r
- * "HTTP-Version": "HTTP/1.1" (for example)\r
- * }</pre>\r
- * A response header will contain\r
- * <pre>{\r
- * "HTTP-Version": "HTTP/1.1" (for example),\r
- * "Status-Code": "200" (for example),\r
- * "Reason-Phrase": "OK" (for example)\r
- * }</pre>\r
- * In addition, the other parameters in the header will be captured, using\r
- * the HTTP field names as JSON names, so that <pre>\r
- * Date: Sun, 26 May 2002 18:06:04 GMT\r
- * Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s\r
- * Cache-Control: no-cache</pre>\r
- * become\r
- * <pre>{...\r
- * Date: "Sun, 26 May 2002 18:06:04 GMT",\r
- * Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",\r
- * "Cache-Control": "no-cache",\r
- * ...}</pre>\r
- * It does no further checking or conversion. It does not parse dates.\r
- * It does not do '%' transforms on URLs.\r
- * @param string An HTTP header string.\r
- * @return A JSONObject containing the elements and attributes\r
- * of the XML string.\r
- * @throws JSONException\r
- */\r
- public static JSONObject toJSONObject(String string) throws JSONException {\r
- JSONObject jo = new JSONObject();\r
- HTTPTokener x = new HTTPTokener(string);\r
- String token;\r
-\r
- token = x.nextToken();\r
- if (token.toUpperCase().startsWith("HTTP")) {\r
-\r
-// Response\r
-\r
- jo.put("HTTP-Version", token);\r
- jo.put("Status-Code", x.nextToken());\r
- jo.put("Reason-Phrase", x.nextTo('\0'));\r
- x.next();\r
-\r
- } else {\r
-\r
-// Request\r
-\r
- jo.put("Method", token);\r
- jo.put("Request-URI", x.nextToken());\r
- jo.put("HTTP-Version", x.nextToken());\r
- }\r
-\r
-// Fields\r
-\r
- while (x.more()) {\r
- String name = x.nextTo(':');\r
- x.next(':');\r
- jo.put(name, x.nextTo('\0'));\r
- x.next();\r
- }\r
- return jo;\r
- }\r
-\r
-\r
- /**\r
- * Convert a JSONObject into an HTTP header. A request header must contain\r
- * <pre>{\r
- * Method: "POST" (for example),\r
- * "Request-URI": "/" (for example),\r
- * "HTTP-Version": "HTTP/1.1" (for example)\r
- * }</pre>\r
- * A response header must contain\r
- * <pre>{\r
- * "HTTP-Version": "HTTP/1.1" (for example),\r
- * "Status-Code": "200" (for example),\r
- * "Reason-Phrase": "OK" (for example)\r
- * }</pre>\r
- * Any other members of the JSONObject will be output as HTTP fields.\r
- * The result will end with two CRLF pairs.\r
- * @param jo A JSONObject\r
- * @return An HTTP header string.\r
- * @throws JSONException if the object does not contain enough\r
- * information.\r
- */\r
- public static String toString(JSONObject jo) throws JSONException {\r
- Iterator<String> keys = jo.keys();\r
- String string;\r
- StringBuffer sb = new StringBuffer();\r
- if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {\r
- sb.append(jo.getString("HTTP-Version"));\r
- sb.append(' ');\r
- sb.append(jo.getString("Status-Code"));\r
- sb.append(' ');\r
- sb.append(jo.getString("Reason-Phrase"));\r
- } else if (jo.has("Method") && jo.has("Request-URI")) {\r
- sb.append(jo.getString("Method"));\r
- sb.append(' ');\r
- sb.append('"');\r
- sb.append(jo.getString("Request-URI"));\r
- sb.append('"');\r
- sb.append(' ');\r
- sb.append(jo.getString("HTTP-Version"));\r
- } else {\r
- throw new JSONException("Not enough material for an HTTP header.");\r
- }\r
- sb.append(CRLF);\r
- while (keys.hasNext()) {\r
- string = keys.next().toString();\r
- if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) &&\r
- !"Reason-Phrase".equals(string) && !"Method".equals(string) &&\r
- !"Request-URI".equals(string) && !jo.isNull(string)) {\r
- sb.append(string);\r
- sb.append(": ");\r
- sb.append(jo.getString(string));\r
- sb.append(CRLF);\r
- }\r
- }\r
- sb.append(CRLF);\r
- return sb.toString();\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-/**\r
- * The HTTPTokener extends the JSONTokener to provide additional methods\r
- * for the parsing of HTTP headers.\r
- * @author JSON.org\r
- * @version 2012-11-13\r
- */\r
-public class HTTPTokener extends JSONTokener {\r
-\r
- /**\r
- * Construct an HTTPTokener from a string.\r
- * @param string A source string.\r
- */\r
- public HTTPTokener(String string) {\r
- super(string);\r
- }\r
-\r
-\r
- /**\r
- * Get the next token or string. This is used in parsing HTTP headers.\r
- * @throws JSONException\r
- * @return A String.\r
- */\r
- public String nextToken() throws JSONException {\r
- char c;\r
- char q;\r
- StringBuffer sb = new StringBuffer();\r
- do {\r
- c = next();\r
- } while (Character.isWhitespace(c));\r
- if (c == '"' || c == '\'') {\r
- q = c;\r
- for (;;) {\r
- c = next();\r
- if (c < ' ') {\r
- throw syntaxError("Unterminated string.");\r
- }\r
- if (c == q) {\r
- return sb.toString();\r
- }\r
- sb.append(c);\r
- }\r
- }\r
- for (;;) {\r
- if (c == 0 || Character.isWhitespace(c)) {\r
- return sb.toString();\r
- }\r
- sb.append(c);\r
- c = next();\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
- Copyright (c) 2002 JSON.org\r
-\r
- Permission is hereby granted, free of charge, to any person obtaining a copy\r
- of this software and associated documentation files (the "Software"), to deal\r
- in the Software without restriction, including without limitation the rights\r
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
- copies of the Software, and to permit persons to whom the Software is\r
- furnished to do so, subject to the following conditions:\r
-\r
- The above copyright notice and this permission notice shall be included in all\r
- copies or substantial portions of the Software.\r
-\r
- The Software shall be used for Good, not Evil.\r
-\r
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
- SOFTWARE.\r
- */\r
-\r
-import java.io.IOException;\r
-import java.io.StringWriter;\r
-import java.io.Writer;\r
-import java.lang.reflect.Array;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-/**\r
- * A JSONArray is an ordered sequence of values. Its external text form is a\r
- * string wrapped in square brackets with commas separating the values. The\r
- * internal form is an object having <code>get</code> and <code>opt</code>\r
- * methods for accessing the values by index, and <code>put</code> methods for\r
- * adding or replacing values. The values can be any of these types:\r
- * <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>,\r
- * <code>Number</code>, <code>String</code>, or the\r
- * <code>JSONObject.NULL object</code>.\r
- * <p>\r
- * The constructor can convert a JSON text into a Java object. The\r
- * <code>toString</code> method converts to JSON text.\r
- * <p>\r
- * A <code>get</code> method returns a value if one can be found, and throws an\r
- * exception if one cannot be found. An <code>opt</code> method returns a\r
- * default value instead of throwing an exception, and so is useful for\r
- * obtaining optional values.\r
- * <p>\r
- * The generic <code>get()</code> and <code>opt()</code> methods return an\r
- * object which you can cast or query for type. There are also typed\r
- * <code>get</code> and <code>opt</code> methods that do type checking and type\r
- * coercion for you.\r
- * <p>\r
- * The texts produced by the <code>toString</code> methods strictly conform to\r
- * JSON syntax rules. The constructors are more forgiving in the texts they will\r
- * accept:\r
- * <ul>\r
- * <li>An extra <code>,</code> <small>(comma)</small> may appear just\r
- * before the closing bracket.</li>\r
- * <li>The <code>null</code> value will be inserted when there is <code>,</code>\r
- * <small>(comma)</small> elision.</li>\r
- * <li>Strings may be quoted with <code>'</code> <small>(single\r
- * quote)</small>.</li>\r
- * <li>Strings do not need to be quoted at all if they do not begin with a quote\r
- * or single quote, and if they do not contain leading or trailing spaces, and\r
- * if they do not contain any of these characters:\r
- * <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers and\r
- * if they are not the reserved words <code>true</code>, <code>false</code>, or\r
- * <code>null</code>.</li>\r
- * <li>Values can be separated by <code>;</code> <small>(semicolon)</small> as\r
- * well as by <code>,</code> <small>(comma)</small>.</li>\r
- * </ul>\r
- *\r
- * @author JSON.org\r
- * @version 2012-11-13\r
- */\r
-public class JSONArray {\r
-\r
- /**\r
- * The arrayList where the JSONArray's properties are kept.\r
- */\r
- private final List<Object> myArrayList;\r
-\r
- /**\r
- * Construct an empty JSONArray.\r
- */\r
- public JSONArray() {\r
- this.myArrayList = new ArrayList<Object>();\r
- }\r
-\r
- /**\r
- * Construct a JSONArray from a JSONTokener.\r
- *\r
- * @param x\r
- * A JSONTokener\r
- * @throws JSONException\r
- * If there is a syntax error.\r
- */\r
- public JSONArray(JSONTokener x) throws JSONException {\r
- this();\r
- if (x.nextClean() != '[') {\r
- throw x.syntaxError("A JSONArray text must start with '['");\r
- }\r
- if (x.nextClean() != ']') {\r
- x.back();\r
- for (;;) {\r
- if (x.nextClean() == ',') {\r
- x.back();\r
- this.myArrayList.add(JSONObject.NULL);\r
- } else {\r
- x.back();\r
- this.myArrayList.add(x.nextValue());\r
- }\r
- switch (x.nextClean()) {\r
- case ';':\r
- case ',':\r
- if (x.nextClean() == ']') {\r
- return;\r
- }\r
- x.back();\r
- break;\r
- case ']':\r
- return;\r
- default:\r
- throw x.syntaxError("Expected a ',' or ']'");\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Construct a JSONArray from a source JSON text.\r
- *\r
- * @param source\r
- * A string that begins with <code>[</code> <small>(left\r
- * bracket)</small> and ends with <code>]</code>\r
- * <small>(right bracket)</small>.\r
- * @throws JSONException\r
- * If there is a syntax error.\r
- */\r
- public JSONArray(String source) throws JSONException {\r
- this(new JSONTokener(source));\r
- }\r
-\r
- /**\r
- * Construct a JSONArray from a Collection.\r
- *\r
- * @param collection\r
- * A Collection.\r
- */\r
- public JSONArray(Collection<Object> collection) {\r
- this.myArrayList = new ArrayList<Object>();\r
- if (collection != null) {\r
- Iterator<Object> iter = collection.iterator();\r
- while (iter.hasNext()) {\r
- this.myArrayList.add(JSONObject.wrap(iter.next()));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Construct a JSONArray from an array\r
- *\r
- * @throws JSONException\r
- * If not an array.\r
- */\r
- public JSONArray(Object array) throws JSONException {\r
- this();\r
- if (array.getClass().isArray()) {\r
- int length = Array.getLength(array);\r
- for (int i = 0; i < length; i += 1) {\r
- this.put(JSONObject.wrap(Array.get(array, i)));\r
- }\r
- } else {\r
- throw new JSONException(\r
- "JSONArray initial value should be a string or collection or array.");\r
- }\r
- }\r
-\r
- /**\r
- * Get the object value associated with an index.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return An object value.\r
- * @throws JSONException\r
- * If there is no value for the index.\r
- */\r
- public Object get(int index) throws JSONException {\r
- Object object = this.opt(index);\r
- if (object == null) {\r
- throw new JSONException("JSONArray[" + index + "] not found.");\r
- }\r
- return object;\r
- }\r
-\r
- /**\r
- * Get the boolean value associated with an index. The string values "true"\r
- * and "false" are converted to boolean.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return The truth.\r
- * @throws JSONException\r
- * If there is no value for the index or if the value is not\r
- * convertible to boolean.\r
- */\r
- public boolean getBoolean(int index) throws JSONException {\r
- Object object = this.get(index);\r
- if (object.equals(Boolean.FALSE)\r
- || (object instanceof String && ((String) object)\r
- .equalsIgnoreCase("false"))) {\r
- return false;\r
- } else if (object.equals(Boolean.TRUE)\r
- || (object instanceof String && ((String) object)\r
- .equalsIgnoreCase("true"))) {\r
- return true;\r
- }\r
- throw new JSONException("JSONArray[" + index + "] is not a boolean.");\r
- }\r
-\r
- /**\r
- * Get the double value associated with an index.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return The value.\r
- * @throws JSONException\r
- * If the key is not found or if the value cannot be converted\r
- * to a number.\r
- */\r
- public double getDouble(int index) throws JSONException {\r
- Object object = this.get(index);\r
- try {\r
- return object instanceof Number ? ((Number) object).doubleValue()\r
- : Double.parseDouble((String) object);\r
- } catch (Exception e) {\r
- throw new JSONException("JSONArray[" + index + "] is not a number.");\r
- }\r
- }\r
-\r
- /**\r
- * Get the int value associated with an index.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return The value.\r
- * @throws JSONException\r
- * If the key is not found or if the value is not a number.\r
- */\r
- public int getInt(int index) throws JSONException {\r
- Object object = this.get(index);\r
- try {\r
- return object instanceof Number ? ((Number) object).intValue()\r
- : Integer.parseInt((String) object);\r
- } catch (Exception e) {\r
- throw new JSONException("JSONArray[" + index + "] is not a number.");\r
- }\r
- }\r
-\r
- /**\r
- * Get the JSONArray associated with an index.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return A JSONArray value.\r
- * @throws JSONException\r
- * If there is no value for the index. or if the value is not a\r
- * JSONArray\r
- */\r
- public JSONArray getJSONArray(int index) throws JSONException {\r
- Object object = this.get(index);\r
- if (object instanceof JSONArray) {\r
- return (JSONArray) object;\r
- }\r
- throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");\r
- }\r
-\r
- /**\r
- * Get the JSONObject associated with an index.\r
- *\r
- * @param index\r
- * subscript\r
- * @return A JSONObject value.\r
- * @throws JSONException\r
- * If there is no value for the index or if the value is not a\r
- * JSONObject\r
- */\r
- public JSONObject getJSONObject(int index) throws JSONException {\r
- Object object = this.get(index);\r
- if (object instanceof JSONObject) {\r
- return (JSONObject) object;\r
- }\r
- throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");\r
- }\r
-\r
- /**\r
- * Get the long value associated with an index.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return The value.\r
- * @throws JSONException\r
- * If the key is not found or if the value cannot be converted\r
- * to a number.\r
- */\r
- public long getLong(int index) throws JSONException {\r
- Object object = this.get(index);\r
- try {\r
- return object instanceof Number ? ((Number) object).longValue()\r
- : Long.parseLong((String) object);\r
- } catch (Exception e) {\r
- throw new JSONException("JSONArray[" + index + "] is not a number.");\r
- }\r
- }\r
-\r
- /**\r
- * Get the string associated with an index.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return A string value.\r
- * @throws JSONException\r
- * If there is no string value for the index.\r
- */\r
- public String getString(int index) throws JSONException {\r
- Object object = this.get(index);\r
- if (object instanceof String) {\r
- return (String) object;\r
- }\r
- throw new JSONException("JSONArray[" + index + "] not a string.");\r
- }\r
-\r
- /**\r
- * Determine if the value is null.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return true if the value at the index is null, or if there is no value.\r
- */\r
- public boolean isNull(int index) {\r
- return JSONObject.NULL.equals(this.opt(index));\r
- }\r
-\r
- /**\r
- * Make a string from the contents of this JSONArray. The\r
- * <code>separator</code> string is inserted between each element. Warning:\r
- * This method assumes that the data structure is acyclical.\r
- *\r
- * @param separator\r
- * A string that will be inserted between the elements.\r
- * @return a string.\r
- * @throws JSONException\r
- * If the array contains an invalid number.\r
- */\r
- public String join(String separator) throws JSONException {\r
- int len = this.length();\r
- StringBuffer sb = new StringBuffer();\r
-\r
- for (int i = 0; i < len; i += 1) {\r
- if (i > 0) {\r
- sb.append(separator);\r
- }\r
- sb.append(JSONObject.valueToString(this.myArrayList.get(i)));\r
- }\r
- return sb.toString();\r
- }\r
-\r
- /**\r
- * Get the number of elements in the JSONArray, included nulls.\r
- *\r
- * @return The length (or size).\r
- */\r
- public int length() {\r
- return this.myArrayList.size();\r
- }\r
-\r
- /**\r
- * Get the optional object value associated with an index.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return An object value, or null if there is no object at that index.\r
- */\r
- public Object opt(int index) {\r
- return (index < 0 || index >= this.length()) ? null : this.myArrayList\r
- .get(index);\r
- }\r
-\r
- /**\r
- * Get the optional boolean value associated with an index. It returns false\r
- * if there is no value at that index, or if the value is not Boolean.TRUE\r
- * or the String "true".\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return The truth.\r
- */\r
- public boolean optBoolean(int index) {\r
- return this.optBoolean(index, false);\r
- }\r
-\r
- /**\r
- * Get the optional boolean value associated with an index. It returns the\r
- * defaultValue if there is no value at that index or if it is not a Boolean\r
- * or the String "true" or "false" (case insensitive).\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @param defaultValue\r
- * A boolean default.\r
- * @return The truth.\r
- */\r
- public boolean optBoolean(int index, boolean defaultValue) {\r
- try {\r
- return this.getBoolean(index);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
- /**\r
- * Get the optional double value associated with an index. NaN is returned\r
- * if there is no value for the index, or if the value is not a number and\r
- * cannot be converted to a number.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return The value.\r
- */\r
- public double optDouble(int index) {\r
- return this.optDouble(index, Double.NaN);\r
- }\r
-\r
- /**\r
- * Get the optional double value associated with an index. The defaultValue\r
- * is returned if there is no value for the index, or if the value is not a\r
- * number and cannot be converted to a number.\r
- *\r
- * @param index\r
- * subscript\r
- * @param defaultValue\r
- * The default value.\r
- * @return The value.\r
- */\r
- public double optDouble(int index, double defaultValue) {\r
- try {\r
- return this.getDouble(index);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
- /**\r
- * Get the optional int value associated with an index. Zero is returned if\r
- * there is no value for the index, or if the value is not a number and\r
- * cannot be converted to a number.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return The value.\r
- */\r
- public int optInt(int index) {\r
- return this.optInt(index, 0);\r
- }\r
-\r
- /**\r
- * Get the optional int value associated with an index. The defaultValue is\r
- * returned if there is no value for the index, or if the value is not a\r
- * number and cannot be converted to a number.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @param defaultValue\r
- * The default value.\r
- * @return The value.\r
- */\r
- public int optInt(int index, int defaultValue) {\r
- try {\r
- return this.getInt(index);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
- /**\r
- * Get the optional JSONArray associated with an index.\r
- *\r
- * @param index\r
- * subscript\r
- * @return A JSONArray value, or null if the index has no value, or if the\r
- * value is not a JSONArray.\r
- */\r
- public JSONArray optJSONArray(int index) {\r
- Object o = this.opt(index);\r
- return o instanceof JSONArray ? (JSONArray) o : null;\r
- }\r
-\r
- /**\r
- * Get the optional JSONObject associated with an index. Null is returned if\r
- * the key is not found, or null if the index has no value, or if the value\r
- * is not a JSONObject.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return A JSONObject value.\r
- */\r
- public JSONObject optJSONObject(int index) {\r
- Object o = this.opt(index);\r
- return o instanceof JSONObject ? (JSONObject) o : null;\r
- }\r
-\r
- /**\r
- * Get the optional long value associated with an index. Zero is returned if\r
- * there is no value for the index, or if the value is not a number and\r
- * cannot be converted to a number.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return The value.\r
- */\r
- public long optLong(int index) {\r
- return this.optLong(index, 0);\r
- }\r
-\r
- /**\r
- * Get the optional long value associated with an index. The defaultValue is\r
- * returned if there is no value for the index, or if the value is not a\r
- * number and cannot be converted to a number.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @param defaultValue\r
- * The default value.\r
- * @return The value.\r
- */\r
- public long optLong(int index, long defaultValue) {\r
- try {\r
- return this.getLong(index);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
- /**\r
- * Get the optional string value associated with an index. It returns an\r
- * empty string if there is no value at that index. If the value is not a\r
- * string and is not null, then it is coverted to a string.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @return A String value.\r
- */\r
- public String optString(int index) {\r
- return this.optString(index, "");\r
- }\r
-\r
- /**\r
- * Get the optional string associated with an index. The defaultValue is\r
- * returned if the key is not found.\r
- *\r
- * @param index\r
- * The index must be between 0 and length() - 1.\r
- * @param defaultValue\r
- * The default value.\r
- * @return A String value.\r
- */\r
- public String optString(int index, String defaultValue) {\r
- Object object = this.opt(index);\r
- return JSONObject.NULL.equals(object) ? defaultValue : object\r
- .toString();\r
- }\r
-\r
- /**\r
- * Append a boolean value. This increases the array's length by one.\r
- *\r
- * @param value\r
- * A boolean value.\r
- * @return this.\r
- */\r
- public JSONArray put(boolean value) {\r
- this.put(value ? Boolean.TRUE : Boolean.FALSE);\r
- return this;\r
- }\r
-\r
- /**\r
- * Put a value in the JSONArray, where the value will be a JSONArray which\r
- * is produced from a Collection.\r
- *\r
- * @param value\r
- * A Collection value.\r
- * @return this.\r
- */\r
- public JSONArray put(Collection<Object> value) {\r
- this.put(new JSONArray(value));\r
- return this;\r
- }\r
-\r
- /**\r
- * Append a double value. This increases the array's length by one.\r
- *\r
- * @param value\r
- * A double value.\r
- * @throws JSONException\r
- * if the value is not finite.\r
- * @return this.\r
- */\r
- public JSONArray put(double value) throws JSONException {\r
- Double d = new Double(value);\r
- JSONObject.testValidity(d);\r
- this.put(d);\r
- return this;\r
- }\r
-\r
- /**\r
- * Append an int value. This increases the array's length by one.\r
- *\r
- * @param value\r
- * An int value.\r
- * @return this.\r
- */\r
- public JSONArray put(int value) {\r
- this.put(new Integer(value));\r
- return this;\r
- }\r
-\r
- /**\r
- * Append an long value. This increases the array's length by one.\r
- *\r
- * @param value\r
- * A long value.\r
- * @return this.\r
- */\r
- public JSONArray put(long value) {\r
- this.put(new Long(value));\r
- return this;\r
- }\r
-\r
- /**\r
- * Put a value in the JSONArray, where the value will be a JSONObject which\r
- * is produced from a Map.\r
- *\r
- * @param value\r
- * A Map value.\r
- * @return this.\r
- */\r
- public JSONArray put(Map<String,Object> value) {\r
- this.put(new JSONObject(value));\r
- return this;\r
- }\r
-\r
- /**\r
- * Append an object value. This increases the array's length by one.\r
- *\r
- * @param value\r
- * An object value. The value should be a Boolean, Double,\r
- * Integer, JSONArray, JSONObject, Long, or String, or the\r
- * JSONObject.NULL object.\r
- * @return this.\r
- */\r
- public JSONArray put(Object value) {\r
- this.myArrayList.add(value);\r
- return this;\r
- }\r
-\r
- /**\r
- * Put or replace a boolean value in the JSONArray. If the index is greater\r
- * than the length of the JSONArray, then null elements will be added as\r
- * necessary to pad it out.\r
- *\r
- * @param index\r
- * The subscript.\r
- * @param value\r
- * A boolean value.\r
- * @return this.\r
- * @throws JSONException\r
- * If the index is negative.\r
- */\r
- public JSONArray put(int index, boolean value) throws JSONException {\r
- this.put(index, value ? Boolean.TRUE : Boolean.FALSE);\r
- return this;\r
- }\r
-\r
- /**\r
- * Put a value in the JSONArray, where the value will be a JSONArray which\r
- * is produced from a Collection.\r
- *\r
- * @param index\r
- * The subscript.\r
- * @param value\r
- * A Collection value.\r
- * @return this.\r
- * @throws JSONException\r
- * If the index is negative or if the value is not finite.\r
- */\r
- public JSONArray put(int index, Collection<Object> value) throws JSONException {\r
- this.put(index, new JSONArray(value));\r
- return this;\r
- }\r
-\r
- /**\r
- * Put or replace a double value. If the index is greater than the length of\r
- * the JSONArray, then null elements will be added as necessary to pad it\r
- * out.\r
- *\r
- * @param index\r
- * The subscript.\r
- * @param value\r
- * A double value.\r
- * @return this.\r
- * @throws JSONException\r
- * If the index is negative or if the value is not finite.\r
- */\r
- public JSONArray put(int index, double value) throws JSONException {\r
- this.put(index, new Double(value));\r
- return this;\r
- }\r
-\r
- /**\r
- * Put or replace an int value. If the index is greater than the length of\r
- * the JSONArray, then null elements will be added as necessary to pad it\r
- * out.\r
- *\r
- * @param index\r
- * The subscript.\r
- * @param value\r
- * An int value.\r
- * @return this.\r
- * @throws JSONException\r
- * If the index is negative.\r
- */\r
- public JSONArray put(int index, int value) throws JSONException {\r
- this.put(index, new Integer(value));\r
- return this;\r
- }\r
-\r
- /**\r
- * Put or replace a long value. If the index is greater than the length of\r
- * the JSONArray, then null elements will be added as necessary to pad it\r
- * out.\r
- *\r
- * @param index\r
- * The subscript.\r
- * @param value\r
- * A long value.\r
- * @return this.\r
- * @throws JSONException\r
- * If the index is negative.\r
- */\r
- public JSONArray put(int index, long value) throws JSONException {\r
- this.put(index, new Long(value));\r
- return this;\r
- }\r
-\r
- /**\r
- * Put a value in the JSONArray, where the value will be a JSONObject that\r
- * is produced from a Map.\r
- *\r
- * @param index\r
- * The subscript.\r
- * @param value\r
- * The Map value.\r
- * @return this.\r
- * @throws JSONException\r
- * If the index is negative or if the the value is an invalid\r
- * number.\r
- */\r
- public JSONArray put(int index, Map<String,Object> value) throws JSONException {\r
- this.put(index, new JSONObject(value));\r
- return this;\r
- }\r
-\r
- /**\r
- * Put or replace an object value in the JSONArray. If the index is greater\r
- * than the length of the JSONArray, then null elements will be added as\r
- * necessary to pad it out.\r
- *\r
- * @param index\r
- * The subscript.\r
- * @param value\r
- * The value to put into the array. The value should be a\r
- * Boolean, Double, Integer, JSONArray, JSONObject, Long, or\r
- * String, or the JSONObject.NULL object.\r
- * @return this.\r
- * @throws JSONException\r
- * If the index is negative or if the the value is an invalid\r
- * number.\r
- */\r
- public JSONArray put(int index, Object value) throws JSONException {\r
- JSONObject.testValidity(value);\r
- if (index < 0) {\r
- throw new JSONException("JSONArray[" + index + "] not found.");\r
- }\r
- if (index < this.length()) {\r
- this.myArrayList.set(index, value);\r
- } else {\r
- while (index != this.length()) {\r
- this.put(JSONObject.NULL);\r
- }\r
- this.put(value);\r
- }\r
- return this;\r
- }\r
-\r
- /**\r
- * Remove an index and close the hole.\r
- *\r
- * @param index\r
- * The index of the element to be removed.\r
- * @return The value that was associated with the index, or null if there\r
- * was no value.\r
- */\r
- public Object remove(int index) {\r
- Object o = this.opt(index);\r
- this.myArrayList.remove(index);\r
- return o;\r
- }\r
-\r
- /**\r
- * Produce a JSONObject by combining a JSONArray of names with the values of\r
- * this JSONArray.\r
- *\r
- * @param names\r
- * A JSONArray containing a list of key strings. These will be\r
- * paired with the values.\r
- * @return A JSONObject, or null if there are no names or if this JSONArray\r
- * has no values.\r
- * @throws JSONException\r
- * If any of the names are null.\r
- */\r
- public JSONObject toJSONObject(JSONArray names) throws JSONException {\r
- if (names == null || names.length() == 0 || this.length() == 0) {\r
- return null;\r
- }\r
- JSONObject jo = new JSONObject();\r
- for (int i = 0; i < names.length(); i += 1) {\r
- jo.put(names.getString(i), this.opt(i));\r
- }\r
- return jo;\r
- }\r
-\r
- /**\r
- * Make a JSON text of this JSONArray. For compactness, no unnecessary\r
- * whitespace is added. If it is not possible to produce a syntactically\r
- * correct JSON text then null will be returned instead. This could occur if\r
- * the array contains an invalid number.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- *\r
- * @return a printable, displayable, transmittable representation of the\r
- * array.\r
- */\r
- public String toString() {\r
- try {\r
- return this.toString(0);\r
- } catch (Exception e) {\r
- return null;\r
- }\r
- }\r
-\r
- /**\r
- * Make a prettyprinted JSON text of this JSONArray. Warning: This method\r
- * assumes that the data structure is acyclical.\r
- *\r
- * @param indentFactor\r
- * The number of spaces to add to each level of indentation.\r
- * @return a printable, displayable, transmittable representation of the\r
- * object, beginning with <code>[</code> <small>(left\r
- * bracket)</small> and ending with <code>]</code>\r
- * <small>(right bracket)</small>.\r
- * @throws JSONException\r
- */\r
- public String toString(int indentFactor) throws JSONException {\r
- StringWriter sw = new StringWriter();\r
- synchronized (sw.getBuffer()) {\r
- return this.write(sw, indentFactor, 0).toString();\r
- }\r
- }\r
-\r
- /**\r
- * Write the contents of the JSONArray as JSON text to a writer. For\r
- * compactness, no whitespace is added.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- *\r
- * @return The writer.\r
- * @throws JSONException\r
- */\r
- public Writer write(Writer writer) throws JSONException {\r
- return this.write(writer, 0, 0);\r
- }\r
-\r
- /**\r
- * Write the contents of the JSONArray as JSON text to a writer. For\r
- * compactness, no whitespace is added.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- *\r
- * @param indentFactor\r
- * The number of spaces to add to each level of indentation.\r
- * @param indent\r
- * The indention of the top level.\r
- * @return The writer.\r
- * @throws JSONException\r
- */\r
- Writer write(Writer writer, int indentFactor, int indent)\r
- throws JSONException {\r
- try {\r
- boolean commanate = false;\r
- int length = this.length();\r
- writer.write('[');\r
-\r
- if (length == 1) {\r
- JSONObject.writeValue(writer, this.myArrayList.get(0),\r
- indentFactor, indent);\r
- } else if (length != 0) {\r
- final int newindent = indent + indentFactor;\r
-\r
- for (int i = 0; i < length; i += 1) {\r
- if (commanate) {\r
- writer.write(',');\r
- }\r
- if (indentFactor > 0) {\r
- writer.write('\n');\r
- }\r
- JSONObject.indent(writer, newindent);\r
- JSONObject.writeValue(writer, this.myArrayList.get(i),\r
- indentFactor, newindent);\r
- commanate = true;\r
- }\r
- if (indentFactor > 0) {\r
- writer.write('\n');\r
- }\r
- JSONObject.indent(writer, indent);\r
- }\r
- writer.write(']');\r
- return writer;\r
- } catch (IOException e) {\r
- throw new JSONException(e);\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/**\r
- * The JSONException is thrown by the JSON.org classes when things are amiss.\r
- *\r
- * @author JSON.org\r
- * @version 2013-02-10\r
- */\r
-public class JSONException extends RuntimeException {\r
- private static final long serialVersionUID = 0;\r
- private Throwable cause;\r
-\r
- /**\r
- * Constructs a JSONException with an explanatory message.\r
- *\r
- * @param message\r
- * Detail about the reason for the exception.\r
- */\r
- public JSONException(String message) {\r
- super(message);\r
- }\r
-\r
- /**\r
- * Constructs a new JSONException with the specified cause.\r
- */\r
- public JSONException(Throwable cause) {\r
- super(cause.getMessage());\r
- this.cause = cause;\r
- }\r
-\r
- /**\r
- * Returns the cause of this exception or null if the cause is nonexistent\r
- * or unknown.\r
- *\r
- * @return the cause of this exception or null if the cause is nonexistent\r
- * or unknown.\r
- */\r
- public Throwable getCause() {\r
- return this.cause;\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2008 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-import java.util.Iterator;\r
-\r
-\r
-/**\r
- * This provides static methods to convert an XML text into a JSONArray or\r
- * JSONObject, and to covert a JSONArray or JSONObject into an XML text using\r
- * the JsonML transform.\r
- *\r
- * @author JSON.org\r
- * @version 2012-03-28\r
- */\r
-public class JSONML {\r
-\r
- /**\r
- * Parse XML values and store them in a JSONArray.\r
- * @param x The XMLTokener containing the source string.\r
- * @param arrayForm true if array form, false if object form.\r
- * @param ja The JSONArray that is containing the current tag or null\r
- * if we are at the outermost level.\r
- * @return A JSONArray if the value is the outermost tag, otherwise null.\r
- * @throws JSONException\r
- */\r
- private static Object parse(\r
- XMLTokener x,\r
- boolean arrayForm,\r
- JSONArray ja\r
- ) throws JSONException {\r
- String attribute;\r
- char c;\r
- String closeTag = null;\r
- int i;\r
- JSONArray newja = null;\r
- JSONObject newjo = null;\r
- Object token;\r
- String tagName = null;\r
-\r
-// Test for and skip past these forms:\r
-// <!-- ... -->\r
-// <![ ... ]]>\r
-// <! ... >\r
-// <? ... ?>\r
-\r
- while (true) {\r
- if (!x.more()) {\r
- throw x.syntaxError("Bad XML");\r
- }\r
- token = x.nextContent();\r
- if (token == XML.LT) {\r
- token = x.nextToken();\r
- if (token instanceof Character) {\r
- if (token == XML.SLASH) {\r
-\r
-// Close tag </\r
-\r
- token = x.nextToken();\r
- if (!(token instanceof String)) {\r
- throw new JSONException(\r
- "Expected a closing name instead of '" +\r
- token + "'.");\r
- }\r
- if (x.nextToken() != XML.GT) {\r
- throw x.syntaxError("Misshaped close tag");\r
- }\r
- return token;\r
- } else if (token == XML.BANG) {\r
-\r
-// <!\r
-\r
- c = x.next();\r
- if (c == '-') {\r
- if (x.next() == '-') {\r
- x.skipPast("-->");\r
- } else {\r
- x.back();\r
- }\r
- } else if (c == '[') {\r
- token = x.nextToken();\r
- if (token.equals("CDATA") && x.next() == '[') {\r
- if (ja != null) {\r
- ja.put(x.nextCDATA());\r
- }\r
- } else {\r
- throw x.syntaxError("Expected 'CDATA['");\r
- }\r
- } else {\r
- i = 1;\r
- do {\r
- token = x.nextMeta();\r
- if (token == null) {\r
- throw x.syntaxError("Missing '>' after '<!'.");\r
- } else if (token == XML.LT) {\r
- i += 1;\r
- } else if (token == XML.GT) {\r
- i -= 1;\r
- }\r
- } while (i > 0);\r
- }\r
- } else if (token == XML.QUEST) {\r
-\r
-// <?\r
-\r
- x.skipPast("?>");\r
- } else {\r
- throw x.syntaxError("Misshaped tag");\r
- }\r
-\r
-// Open tag <\r
-\r
- } else {\r
- if (!(token instanceof String)) {\r
- throw x.syntaxError("Bad tagName '" + token + "'.");\r
- }\r
- tagName = (String)token;\r
- newja = new JSONArray();\r
- newjo = new JSONObject();\r
- if (arrayForm) {\r
- newja.put(tagName);\r
- if (ja != null) {\r
- ja.put(newja);\r
- }\r
- } else {\r
- newjo.put("tagName", tagName);\r
- if (ja != null) {\r
- ja.put(newjo);\r
- }\r
- }\r
- token = null;\r
- for (;;) {\r
- if (token == null) {\r
- token = x.nextToken();\r
- }\r
- if (token == null) {\r
- throw x.syntaxError("Misshaped tag");\r
- }\r
- if (!(token instanceof String)) {\r
- break;\r
- }\r
-\r
-// attribute = value\r
-\r
- attribute = (String)token;\r
- if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) {\r
- throw x.syntaxError("Reserved attribute.");\r
- }\r
- token = x.nextToken();\r
- if (token == XML.EQ) {\r
- token = x.nextToken();\r
- if (!(token instanceof String)) {\r
- throw x.syntaxError("Missing value");\r
- }\r
- newjo.accumulate(attribute, XML.stringToValue((String)token));\r
- token = null;\r
- } else {\r
- newjo.accumulate(attribute, "");\r
- }\r
- }\r
- if (arrayForm && newjo.length() > 0) {\r
- newja.put(newjo);\r
- }\r
-\r
-// Empty tag <.../>\r
-\r
- if (token == XML.SLASH) {\r
- if (x.nextToken() != XML.GT) {\r
- throw x.syntaxError("Misshaped tag");\r
- }\r
- if (ja == null) {\r
- if (arrayForm) {\r
- return newja;\r
- } else {\r
- return newjo;\r
- }\r
- }\r
-\r
-// Content, between <...> and </...>\r
-\r
- } else {\r
- if (token != XML.GT) {\r
- throw x.syntaxError("Misshaped tag");\r
- }\r
- closeTag = (String)parse(x, arrayForm, newja);\r
- if (closeTag != null) {\r
- if (!closeTag.equals(tagName)) {\r
- throw x.syntaxError("Mismatched '" + tagName +\r
- "' and '" + closeTag + "'");\r
- }\r
- tagName = null;\r
- if (!arrayForm && newja.length() > 0) {\r
- newjo.put("childNodes", newja);\r
- }\r
- if (ja == null) {\r
- if (arrayForm) {\r
- return newja;\r
- } else {\r
- return newjo;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- } else {\r
- if (ja != null) {\r
- ja.put(token instanceof String\r
- ? XML.stringToValue((String)token)\r
- : token);\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Convert a well-formed (but not necessarily valid) XML string into a\r
- * JSONArray using the JsonML transform. Each XML tag is represented as\r
- * a JSONArray in which the first element is the tag name. If the tag has\r
- * attributes, then the second element will be JSONObject containing the\r
- * name/value pairs. If the tag contains children, then strings and\r
- * JSONArrays will represent the child tags.\r
- * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.\r
- * @param string The source string.\r
- * @return A JSONArray containing the structured data from the XML string.\r
- * @throws JSONException\r
- */\r
- public static JSONArray toJSONArray(String string) throws JSONException {\r
- return toJSONArray(new XMLTokener(string));\r
- }\r
-\r
-\r
- /**\r
- * Convert a well-formed (but not necessarily valid) XML string into a\r
- * JSONArray using the JsonML transform. Each XML tag is represented as\r
- * a JSONArray in which the first element is the tag name. If the tag has\r
- * attributes, then the second element will be JSONObject containing the\r
- * name/value pairs. If the tag contains children, then strings and\r
- * JSONArrays will represent the child content and tags.\r
- * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.\r
- * @param x An XMLTokener.\r
- * @return A JSONArray containing the structured data from the XML string.\r
- * @throws JSONException\r
- */\r
- public static JSONArray toJSONArray(XMLTokener x) throws JSONException {\r
- return (JSONArray)parse(x, true, null);\r
- }\r
-\r
-\r
- /**\r
- * Convert a well-formed (but not necessarily valid) XML string into a\r
- * JSONObject using the JsonML transform. Each XML tag is represented as\r
- * a JSONObject with a "tagName" property. If the tag has attributes, then\r
- * the attributes will be in the JSONObject as properties. If the tag\r
- * contains children, the object will have a "childNodes" property which\r
- * will be an array of strings and JsonML JSONObjects.\r
-\r
- * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.\r
- * @param x An XMLTokener of the XML source text.\r
- * @return A JSONObject containing the structured data from the XML string.\r
- * @throws JSONException\r
- */\r
- public static JSONObject toJSONObject(XMLTokener x) throws JSONException {\r
- return (JSONObject)parse(x, false, null);\r
- }\r
-\r
-\r
- /**\r
- * Convert a well-formed (but not necessarily valid) XML string into a\r
- * JSONObject using the JsonML transform. Each XML tag is represented as\r
- * a JSONObject with a "tagName" property. If the tag has attributes, then\r
- * the attributes will be in the JSONObject as properties. If the tag\r
- * contains children, the object will have a "childNodes" property which\r
- * will be an array of strings and JsonML JSONObjects.\r
-\r
- * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored.\r
- * @param string The XML source text.\r
- * @return A JSONObject containing the structured data from the XML string.\r
- * @throws JSONException\r
- */\r
- public static JSONObject toJSONObject(String string) throws JSONException {\r
- return toJSONObject(new XMLTokener(string));\r
- }\r
-\r
-\r
- /**\r
- * Reverse the JSONML transformation, making an XML text from a JSONArray.\r
- * @param ja A JSONArray.\r
- * @return An XML string.\r
- * @throws JSONException\r
- */\r
- public static String toString(JSONArray ja) throws JSONException {\r
- int i;\r
- JSONObject jo;\r
- String key;\r
- Iterator<String> keys;\r
- int length;\r
- Object object;\r
- StringBuffer sb = new StringBuffer();\r
- String tagName;\r
- String value;\r
-\r
-// Emit <tagName\r
-\r
- tagName = ja.getString(0);\r
- XML.noSpace(tagName);\r
- tagName = XML.escape(tagName);\r
- sb.append('<');\r
- sb.append(tagName);\r
-\r
- object = ja.opt(1);\r
- if (object instanceof JSONObject) {\r
- i = 2;\r
- jo = (JSONObject)object;\r
-\r
-// Emit the attributes\r
-\r
- keys = jo.keys();\r
- while (keys.hasNext()) {\r
- key = keys.next().toString();\r
- XML.noSpace(key);\r
- value = jo.optString(key);\r
- if (value != null) {\r
- sb.append(' ');\r
- sb.append(XML.escape(key));\r
- sb.append('=');\r
- sb.append('"');\r
- sb.append(XML.escape(value));\r
- sb.append('"');\r
- }\r
- }\r
- } else {\r
- i = 1;\r
- }\r
-\r
-//Emit content in body\r
-\r
- length = ja.length();\r
- if (i >= length) {\r
- sb.append('/');\r
- sb.append('>');\r
- } else {\r
- sb.append('>');\r
- do {\r
- object = ja.get(i);\r
- i += 1;\r
- if (object != null) {\r
- if (object instanceof String) {\r
- sb.append(XML.escape(object.toString()));\r
- } else if (object instanceof JSONObject) {\r
- sb.append(toString((JSONObject)object));\r
- } else if (object instanceof JSONArray) {\r
- sb.append(toString((JSONArray)object));\r
- }\r
- }\r
- } while (i < length);\r
- sb.append('<');\r
- sb.append('/');\r
- sb.append(tagName);\r
- sb.append('>');\r
- }\r
- return sb.toString();\r
- }\r
-\r
- /**\r
- * Reverse the JSONML transformation, making an XML text from a JSONObject.\r
- * The JSONObject must contain a "tagName" property. If it has children,\r
- * then it must have a "childNodes" property containing an array of objects.\r
- * The other properties are attributes with string values.\r
- * @param jo A JSONObject.\r
- * @return An XML string.\r
- * @throws JSONException\r
- */\r
- public static String toString(JSONObject jo) throws JSONException {\r
- StringBuffer sb = new StringBuffer();\r
- int i;\r
- JSONArray ja;\r
- String key;\r
- Iterator<String> keys;\r
- int length;\r
- Object object;\r
- String tagName;\r
- String value;\r
-\r
-//Emit <tagName\r
-\r
- tagName = jo.optString("tagName");\r
- if (tagName == null) {\r
- return XML.escape(jo.toString());\r
- }\r
- XML.noSpace(tagName);\r
- tagName = XML.escape(tagName);\r
- sb.append('<');\r
- sb.append(tagName);\r
-\r
-//Emit the attributes\r
-\r
- keys = jo.keys();\r
- while (keys.hasNext()) {\r
- key = keys.next().toString();\r
- if (!"tagName".equals(key) && !"childNodes".equals(key)) {\r
- XML.noSpace(key);\r
- value = jo.optString(key);\r
- if (value != null) {\r
- sb.append(' ');\r
- sb.append(XML.escape(key));\r
- sb.append('=');\r
- sb.append('"');\r
- sb.append(XML.escape(value));\r
- sb.append('"');\r
- }\r
- }\r
- }\r
-\r
-//Emit content in body\r
-\r
- ja = jo.optJSONArray("childNodes");\r
- if (ja == null) {\r
- sb.append('/');\r
- sb.append('>');\r
- } else {\r
- sb.append('>');\r
- length = ja.length();\r
- for (i = 0; i < length; i += 1) {\r
- object = ja.get(i);\r
- if (object != null) {\r
- if (object instanceof String) {\r
- sb.append(XML.escape(object.toString()));\r
- } else if (object instanceof JSONObject) {\r
- sb.append(toString((JSONObject)object));\r
- } else if (object instanceof JSONArray) {\r
- sb.append(toString((JSONArray)object));\r
- } else {\r
- sb.append(object.toString());\r
- }\r
- }\r
- }\r
- sb.append('<');\r
- sb.append('/');\r
- sb.append(tagName);\r
- sb.append('>');\r
- }\r
- return sb.toString();\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-import java.io.IOException;\r
-import java.io.StringWriter;\r
-import java.io.Writer;\r
-import java.lang.reflect.Field;\r
-import java.lang.reflect.Method;\r
-import java.lang.reflect.Modifier;\r
-import java.util.Collection;\r
-import java.util.Enumeration;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Locale;\r
-import java.util.Map;\r
-import java.util.ResourceBundle;\r
-import java.util.Set;\r
-\r
-/**\r
- * A JSONObject is an unordered collection of name/value pairs. Its external\r
- * form is a string wrapped in curly braces with colons between the names and\r
- * values, and commas between the values and names. The internal form is an\r
- * object having <code>get</code> and <code>opt</code> methods for accessing the\r
- * values by name, and <code>put</code> methods for adding or replacing values\r
- * by name. The values can be any of these types: <code>Boolean</code>,\r
- * <code>JSONArray</code>, <code>JSONObject</code>, <code>Number</code>,\r
- * <code>String</code>, or the <code>JSONObject.NULL</code> object. A JSONObject\r
- * constructor can be used to convert an external form JSON text into an\r
- * internal form whose values can be retrieved with the <code>get</code> and\r
- * <code>opt</code> methods, or to convert values into a JSON text using the\r
- * <code>put</code> and <code>toString</code> methods. A <code>get</code> method\r
- * returns a value if one can be found, and throws an exception if one cannot be\r
- * found. An <code>opt</code> method returns a default value instead of throwing\r
- * an exception, and so is useful for obtaining optional values.\r
- * <p>\r
- * The generic <code>get()</code> and <code>opt()</code> methods return an\r
- * object, which you can cast or query for type. There are also typed\r
- * <code>get</code> and <code>opt</code> methods that do type checking and type\r
- * coercion for you. The opt methods differ from the get methods in that they do\r
- * not throw. Instead, they return a specified value, such as null.\r
- * <p>\r
- * The <code>put</code> methods add or replace values in an object. For example,\r
- *\r
- * <pre>\r
- * myString = new JSONObject().put("JSON", "Hello, World!").toString();\r
- * </pre>\r
- *\r
- * produces the string <code>{"JSON": "Hello, World"}</code>.\r
- * <p>\r
- * The texts produced by the <code>toString</code> methods strictly conform to\r
- * the JSON syntax rules. The constructors are more forgiving in the texts they\r
- * will accept:\r
- * <ul>\r
- * <li>An extra <code>,</code> <small>(comma)</small> may appear just\r
- * before the closing brace.</li>\r
- * <li>Strings may be quoted with <code>'</code> <small>(single\r
- * quote)</small>.</li>\r
- * <li>Strings do not need to be quoted at all if they do not begin with a quote\r
- * or single quote, and if they do not contain leading or trailing spaces, and\r
- * if they do not contain any of these characters:\r
- * <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers and\r
- * if they are not the reserved words <code>true</code>, <code>false</code>, or\r
- * <code>null</code>.</li>\r
- * <li>Keys can be followed by <code>=</code> or <code>=></code> as well as by\r
- * <code>:</code>.</li>\r
- * <li>Values can be followed by <code>;</code> <small>(semicolon)</small> as\r
- * well as by <code>,</code> <small>(comma)</small>.</li>\r
- * </ul>\r
- *\r
- * @author JSON.org\r
- * @version 2012-12-01\r
- */\r
-public class JSONObject {\r
- /**\r
- * The maximum number of keys in the key pool.\r
- */\r
- private static final int keyPoolSize = 100;\r
-\r
- /**\r
- * Key pooling is like string interning, but without permanently tying up\r
- * memory. To help conserve memory, storage of duplicated key strings in\r
- * JSONObjects will be avoided by using a key pool to manage unique key\r
- * string objects. This is used by JSONObject.put(string, object).\r
- */\r
- private static Map<String,Object> keyPool = new HashMap<String,Object>(keyPoolSize);\r
-\r
- /**\r
- * JSONObject.NULL is equivalent to the value that JavaScript calls null,\r
- * whilst Java's null is equivalent to the value that JavaScript calls\r
- * undefined.\r
- */\r
- private static final class Null {\r
-\r
- /**\r
- * There is only intended to be a single instance of the NULL object,\r
- * so the clone method returns itself.\r
- * @return NULL.\r
- */\r
- protected final Object clone() {\r
- return this;\r
- }\r
-\r
- /**\r
- * A Null object is equal to the null value and to itself.\r
- * @param object An object to test for nullness.\r
- * @return true if the object parameter is the JSONObject.NULL object\r
- * or null.\r
- */\r
- public boolean equals(Object object) {\r
- return object == null || object == this;\r
- }\r
-\r
- /**\r
- * Get the "null" string value.\r
- * @return The string "null".\r
- */\r
- public String toString() {\r
- return "null";\r
- }\r
- }\r
-\r
-\r
- /**\r
- * The map where the JSONObject's properties are kept.\r
- */\r
- private final Map<String,Object> map;\r
-\r
-\r
- /**\r
- * It is sometimes more convenient and less ambiguous to have a\r
- * <code>NULL</code> object than to use Java's <code>null</code> value.\r
- * <code>JSONObject.NULL.equals(null)</code> returns <code>true</code>.\r
- * <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>.\r
- */\r
- public static final Object NULL = new Null();\r
-\r
-\r
- /**\r
- * Construct an empty JSONObject.\r
- */\r
- public JSONObject() {\r
- this.map = new HashMap<String,Object>();\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a subset of another JSONObject.\r
- * An array of strings is used to identify the keys that should be copied.\r
- * Missing keys are ignored.\r
- * @param jo A JSONObject.\r
- * @param names An array of strings.\r
- * @throws JSONException\r
- * @exception JSONException If a value is a non-finite number or if a name is duplicated.\r
- */\r
- public JSONObject(JSONObject jo, String[] names) {\r
- this();\r
- for (int i = 0; i < names.length; i += 1) {\r
- try {\r
- this.putOnce(names[i], jo.opt(names[i]));\r
- } catch (Exception ignore) {\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a JSONTokener.\r
- * @param x A JSONTokener object containing the source string.\r
- * @throws JSONException If there is a syntax error in the source string\r
- * or a duplicated key.\r
- */\r
- public JSONObject(JSONTokener x) throws JSONException {\r
- this();\r
- char c;\r
- String key;\r
-\r
- if (x.nextClean() != '{') {\r
- throw x.syntaxError("A JSONObject text must begin with '{'");\r
- }\r
- for (;;) {\r
- c = x.nextClean();\r
- switch (c) {\r
- case 0:\r
- throw x.syntaxError("A JSONObject text must end with '}'");\r
- case '}':\r
- return;\r
- default:\r
- x.back();\r
- key = x.nextValue().toString();\r
- }\r
-\r
-// The key is followed by ':'. We will also tolerate '=' or '=>'.\r
-\r
- c = x.nextClean();\r
- if (c == '=') {\r
- if (x.next() != '>') {\r
- x.back();\r
- }\r
- } else if (c != ':') {\r
- throw x.syntaxError("Expected a ':' after a key");\r
- }\r
- this.putOnce(key, x.nextValue());\r
-\r
-// Pairs are separated by ','. We will also tolerate ';'.\r
-\r
- switch (x.nextClean()) {\r
- case ';':\r
- case ',':\r
- if (x.nextClean() == '}') {\r
- return;\r
- }\r
- x.back();\r
- break;\r
- case '}':\r
- return;\r
- default:\r
- throw x.syntaxError("Expected a ',' or '}'");\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a Map.\r
- *\r
- * @param map A map object that can be used to initialize the contents of\r
- * the JSONObject.\r
- * @throws JSONException\r
- */\r
- public JSONObject(Map<String,Object> map) {\r
- this.map = new HashMap<String,Object>();\r
- if (map != null) {\r
- Iterator<Map.Entry<String,Object>> i = map.entrySet().iterator();\r
- while (i.hasNext()) {\r
- Map.Entry<String,Object> e = i.next();\r
- Object value = e.getValue();\r
- if (value != null) {\r
- this.map.put(e.getKey(), wrap(value));\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from an Object using bean getters.\r
- * It reflects on all of the public methods of the object.\r
- * For each of the methods with no parameters and a name starting\r
- * with <code>"get"</code> or <code>"is"</code> followed by an uppercase letter,\r
- * the method is invoked, and a key and the value returned from the getter method\r
- * are put into the new JSONObject.\r
- *\r
- * The key is formed by removing the <code>"get"</code> or <code>"is"</code> prefix.\r
- * If the second remaining character is not upper case, then the first\r
- * character is converted to lower case.\r
- *\r
- * For example, if an object has a method named <code>"getName"</code>, and\r
- * if the result of calling <code>object.getName()</code> is <code>"Larry Fine"</code>,\r
- * then the JSONObject will contain <code>"name": "Larry Fine"</code>.\r
- *\r
- * @param bean An object that has getter methods that should be used\r
- * to make a JSONObject.\r
- */\r
- public JSONObject(Object bean) {\r
- this();\r
- this.populateMap(bean);\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from an Object, using reflection to find the\r
- * public members. The resulting JSONObject's keys will be the strings\r
- * from the names array, and the values will be the field values associated\r
- * with those keys in the object. If a key is not found or not visible,\r
- * then it will not be copied into the new JSONObject.\r
- * @param object An object that has fields that should be used to make a\r
- * JSONObject.\r
- * @param names An array of strings, the names of the fields to be obtained\r
- * from the object.\r
- */\r
- public JSONObject(Object object, String names[]) {\r
- this();\r
- Class<? extends Object> c = object.getClass();\r
- for (int i = 0; i < names.length; i += 1) {\r
- String name = names[i];\r
- try {\r
- this.putOpt(name, c.getField(name).get(object));\r
- } catch (Exception ignore) {\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a source JSON text string.\r
- * This is the most commonly used JSONObject constructor.\r
- * @param source A string beginning\r
- * with <code>{</code> <small>(left brace)</small> and ending\r
- * with <code>}</code> <small>(right brace)</small>.\r
- * @exception JSONException If there is a syntax error in the source\r
- * string or a duplicated key.\r
- */\r
- public JSONObject(String source) throws JSONException {\r
- this(new JSONTokener(source));\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a ResourceBundle.\r
- * @param baseName The ResourceBundle base name.\r
- * @param locale The Locale to load the ResourceBundle for.\r
- * @throws JSONException If any JSONExceptions are detected.\r
- */\r
- public JSONObject(String baseName, Locale locale) throws JSONException {\r
- this();\r
- ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,\r
- Thread.currentThread().getContextClassLoader());\r
-\r
-// Iterate through the keys in the bundle.\r
-\r
- Enumeration<?> keys = bundle.getKeys();\r
- while (keys.hasMoreElements()) {\r
- Object key = keys.nextElement();\r
- if (key instanceof String) {\r
-\r
-// Go through the path, ensuring that there is a nested JSONObject for each\r
-// segment except the last. Add the value using the last segment's name into\r
-// the deepest nested JSONObject.\r
-\r
- String[] path = ((String)key).split("\\.");\r
- int last = path.length - 1;\r
- JSONObject target = this;\r
- for (int i = 0; i < last; i += 1) {\r
- String segment = path[i];\r
- JSONObject nextTarget = target.optJSONObject(segment);\r
- if (nextTarget == null) {\r
- nextTarget = new JSONObject();\r
- target.put(segment, nextTarget);\r
- }\r
- target = nextTarget;\r
- }\r
- target.put(path[last], bundle.getString((String)key));\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Accumulate values under a key. It is similar to the put method except\r
- * that if there is already an object stored under the key then a\r
- * JSONArray is stored under the key to hold all of the accumulated values.\r
- * If there is already a JSONArray, then the new value is appended to it.\r
- * In contrast, the put method replaces the previous value.\r
- *\r
- * If only one value is accumulated that is not a JSONArray, then the\r
- * result will be the same as using put. But if multiple values are\r
- * accumulated, then the result will be like append.\r
- * @param key A key string.\r
- * @param value An object to be accumulated under the key.\r
- * @return this.\r
- * @throws JSONException If the value is an invalid number\r
- * or if the key is null.\r
- */\r
- public JSONObject accumulate(\r
- String key,\r
- Object value\r
- ) throws JSONException {\r
- testValidity(value);\r
- Object object = this.opt(key);\r
- if (object == null) {\r
- this.put(key, value instanceof JSONArray\r
- ? new JSONArray().put(value)\r
- : value);\r
- } else if (object instanceof JSONArray) {\r
- ((JSONArray)object).put(value);\r
- } else {\r
- this.put(key, new JSONArray().put(object).put(value));\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Append values to the array under a key. If the key does not exist in the\r
- * JSONObject, then the key is put in the JSONObject with its value being a\r
- * JSONArray containing the value parameter. If the key was already\r
- * associated with a JSONArray, then the value parameter is appended to it.\r
- * @param key A key string.\r
- * @param value An object to be accumulated under the key.\r
- * @return this.\r
- * @throws JSONException If the key is null or if the current value\r
- * associated with the key is not a JSONArray.\r
- */\r
- public JSONObject append(String key, Object value) throws JSONException {\r
- testValidity(value);\r
- Object object = this.opt(key);\r
- if (object == null) {\r
- this.put(key, new JSONArray().put(value));\r
- } else if (object instanceof JSONArray) {\r
- this.put(key, ((JSONArray)object).put(value));\r
- } else {\r
- throw new JSONException("JSONObject[" + key +\r
- "] is not a JSONArray.");\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Produce a string from a double. The string "null" will be returned if\r
- * the number is not finite.\r
- * @param d A double.\r
- * @return A String.\r
- */\r
- public static String doubleToString(double d) {\r
- if (Double.isInfinite(d) || Double.isNaN(d)) {\r
- return "null";\r
- }\r
-\r
-// Shave off trailing zeros and decimal point, if possible.\r
-\r
- String string = Double.toString(d);\r
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&\r
- string.indexOf('E') < 0) {\r
- while (string.endsWith("0")) {\r
- string = string.substring(0, string.length() - 1);\r
- }\r
- if (string.endsWith(".")) {\r
- string = string.substring(0, string.length() - 1);\r
- }\r
- }\r
- return string;\r
- }\r
-\r
-\r
- /**\r
- * Get the value object associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return The object associated with the key.\r
- * @throws JSONException if the key is not found.\r
- */\r
- public Object get(String key) throws JSONException {\r
- if (key == null) {\r
- throw new JSONException("Null key.");\r
- }\r
- Object object = this.opt(key);\r
- if (object == null) {\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] not found.");\r
- }\r
- return object;\r
- }\r
-\r
-\r
- /**\r
- * Get the boolean value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return The truth.\r
- * @throws JSONException\r
- * if the value is not a Boolean or the String "true" or "false".\r
- */\r
- public boolean getBoolean(String key) throws JSONException {\r
- Object object = this.get(key);\r
- if (object.equals(Boolean.FALSE) ||\r
- (object instanceof String &&\r
- ((String)object).equalsIgnoreCase("false"))) {\r
- return false;\r
- } else if (object.equals(Boolean.TRUE) ||\r
- (object instanceof String &&\r
- ((String)object).equalsIgnoreCase("true"))) {\r
- return true;\r
- }\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a Boolean.");\r
- }\r
-\r
-\r
- /**\r
- * Get the double value associated with a key.\r
- * @param key A key string.\r
- * @return The numeric value.\r
- * @throws JSONException if the key is not found or\r
- * if the value is not a Number object and cannot be converted to a number.\r
- */\r
- public double getDouble(String key) throws JSONException {\r
- Object object = this.get(key);\r
- try {\r
- return object instanceof Number\r
- ? ((Number)object).doubleValue()\r
- : Double.parseDouble((String)object);\r
- } catch (Exception e) {\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a number.");\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the int value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return The integer value.\r
- * @throws JSONException if the key is not found or if the value cannot\r
- * be converted to an integer.\r
- */\r
- public int getInt(String key) throws JSONException {\r
- Object object = this.get(key);\r
- try {\r
- return object instanceof Number\r
- ? ((Number)object).intValue()\r
- : Integer.parseInt((String)object);\r
- } catch (Exception e) {\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not an int.");\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the JSONArray value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return A JSONArray which is the value.\r
- * @throws JSONException if the key is not found or\r
- * if the value is not a JSONArray.\r
- */\r
- public JSONArray getJSONArray(String key) throws JSONException {\r
- Object object = this.get(key);\r
- if (object instanceof JSONArray) {\r
- return (JSONArray)object;\r
- }\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a JSONArray.");\r
- }\r
-\r
-\r
- /**\r
- * Get the JSONObject value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return A JSONObject which is the value.\r
- * @throws JSONException if the key is not found or\r
- * if the value is not a JSONObject.\r
- */\r
- public JSONObject getJSONObject(String key) throws JSONException {\r
- Object object = this.get(key);\r
- if (object instanceof JSONObject) {\r
- return (JSONObject)object;\r
- }\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a JSONObject.");\r
- }\r
-\r
-\r
- /**\r
- * Get the long value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return The long value.\r
- * @throws JSONException if the key is not found or if the value cannot\r
- * be converted to a long.\r
- */\r
- public long getLong(String key) throws JSONException {\r
- Object object = this.get(key);\r
- try {\r
- return object instanceof Number\r
- ? ((Number)object).longValue()\r
- : Long.parseLong((String)object);\r
- } catch (Exception e) {\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a long.");\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an array of field names from a JSONObject.\r
- *\r
- * @return An array of field names, or null if there are no names.\r
- */\r
- public static String[] getNames(JSONObject jo) {\r
- int length = jo.length();\r
- if (length == 0) {\r
- return null;\r
- }\r
- Iterator<String> iterator = jo.keys();\r
- String[] names = new String[length];\r
- int i = 0;\r
- while (iterator.hasNext()) {\r
- names[i] = iterator.next();\r
- i += 1;\r
- }\r
- return names;\r
- }\r
-\r
-\r
- /**\r
- * Get an array of field names from an Object.\r
- *\r
- * @return An array of field names, or null if there are no names.\r
- */\r
- public static String[] getNames(Object object) {\r
- if (object == null) {\r
- return null;\r
- }\r
- Class<? extends Object> klass = object.getClass();\r
- Field[] fields = klass.getFields();\r
- int length = fields.length;\r
- if (length == 0) {\r
- return null;\r
- }\r
- String[] names = new String[length];\r
- for (int i = 0; i < length; i += 1) {\r
- names[i] = fields[i].getName();\r
- }\r
- return names;\r
- }\r
-\r
-\r
- /**\r
- * Get the string associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return A string which is the value.\r
- * @throws JSONException if there is no string value for the key.\r
- */\r
- public String getString(String key) throws JSONException {\r
- Object object = this.get(key);\r
- if (object instanceof String) {\r
- return (String)object;\r
- }\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] not a string.");\r
- }\r
-\r
-\r
- /**\r
- * Determine if the JSONObject contains a specific key.\r
- * @param key A key string.\r
- * @return true if the key exists in the JSONObject.\r
- */\r
- public boolean has(String key) {\r
- return this.map.containsKey(key);\r
- }\r
-\r
-\r
- /**\r
- * Increment a property of a JSONObject. If there is no such property,\r
- * create one with a value of 1. If there is such a property, and if\r
- * it is an Integer, Long, Double, or Float, then add one to it.\r
- * @param key A key string.\r
- * @return this.\r
- * @throws JSONException If there is already a property with this name\r
- * that is not an Integer, Long, Double, or Float.\r
- */\r
- public JSONObject increment(String key) throws JSONException {\r
- Object value = this.opt(key);\r
- if (value == null) {\r
- this.put(key, 1);\r
- } else if (value instanceof Integer) {\r
- this.put(key, ((Integer)value).intValue() + 1);\r
- } else if (value instanceof Long) {\r
- this.put(key, ((Long)value).longValue() + 1);\r
- } else if (value instanceof Double) {\r
- this.put(key, ((Double)value).doubleValue() + 1);\r
- } else if (value instanceof Float) {\r
- this.put(key, ((Float)value).floatValue() + 1);\r
- } else {\r
- throw new JSONException("Unable to increment [" + quote(key) + "].");\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Determine if the value associated with the key is null or if there is\r
- * no value.\r
- * @param key A key string.\r
- * @return true if there is no value associated with the key or if\r
- * the value is the JSONObject.NULL object.\r
- */\r
- public boolean isNull(String key) {\r
- return JSONObject.NULL.equals(this.opt(key));\r
- }\r
-\r
-\r
- /**\r
- * Get an enumeration of the keys of the JSONObject.\r
- *\r
- * @return An iterator of the keys.\r
- */\r
- public Iterator<String> keys() {\r
- return this.keySet().iterator();\r
- }\r
-\r
-\r
- /**\r
- * Get a set of keys of the JSONObject.\r
- *\r
- * @return A keySet.\r
- */\r
- public Set<String> keySet() {\r
- return this.map.keySet();\r
- }\r
-\r
-\r
- /**\r
- * Get the number of keys stored in the JSONObject.\r
- *\r
- * @return The number of keys in the JSONObject.\r
- */\r
- public int length() {\r
- return this.map.size();\r
- }\r
-\r
-\r
- /**\r
- * Produce a JSONArray containing the names of the elements of this\r
- * JSONObject.\r
- * @return A JSONArray containing the key strings, or null if the JSONObject\r
- * is empty.\r
- */\r
- public JSONArray names() {\r
- JSONArray ja = new JSONArray();\r
- Iterator<String> keys = this.keys();\r
- while (keys.hasNext()) {\r
- ja.put(keys.next());\r
- }\r
- return ja.length() == 0 ? null : ja;\r
- }\r
-\r
- /**\r
- * Produce a string from a Number.\r
- * @param number A Number\r
- * @return A String.\r
- * @throws JSONException If n is a non-finite number.\r
- */\r
- public static String numberToString(Number number)\r
- throws JSONException {\r
- if (number == null) {\r
- throw new JSONException("Null pointer");\r
- }\r
- testValidity(number);\r
-\r
-// Shave off trailing zeros and decimal point, if possible.\r
-\r
- String string = number.toString();\r
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&\r
- string.indexOf('E') < 0) {\r
- while (string.endsWith("0")) {\r
- string = string.substring(0, string.length() - 1);\r
- }\r
- if (string.endsWith(".")) {\r
- string = string.substring(0, string.length() - 1);\r
- }\r
- }\r
- return string;\r
- }\r
-\r
-\r
- /**\r
- * Get an optional value associated with a key.\r
- * @param key A key string.\r
- * @return An object which is the value, or null if there is no value.\r
- */\r
- public Object opt(String key) {\r
- return key == null ? null : this.map.get(key);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional boolean associated with a key.\r
- * It returns false if there is no such key, or if the value is not\r
- * Boolean.TRUE or the String "true".\r
- *\r
- * @param key A key string.\r
- * @return The truth.\r
- */\r
- public boolean optBoolean(String key) {\r
- return this.optBoolean(key, false);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional boolean associated with a key.\r
- * It returns the defaultValue if there is no such key, or if it is not\r
- * a Boolean or the String "true" or "false" (case insensitive).\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return The truth.\r
- */\r
- public boolean optBoolean(String key, boolean defaultValue) {\r
- try {\r
- return this.getBoolean(key);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an optional double associated with a key,\r
- * or NaN if there is no such key or if its value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A string which is the key.\r
- * @return An object which is the value.\r
- */\r
- public double optDouble(String key) {\r
- return this.optDouble(key, Double.NaN);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional double associated with a key, or the\r
- * defaultValue if there is no such key or if its value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return An object which is the value.\r
- */\r
- public double optDouble(String key, double defaultValue) {\r
- try {\r
- return this.getDouble(key);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an optional int value associated with a key,\r
- * or zero if there is no such key or if the value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @return An object which is the value.\r
- */\r
- public int optInt(String key) {\r
- return this.optInt(key, 0);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional int value associated with a key,\r
- * or the default if there is no such key or if the value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return An object which is the value.\r
- */\r
- public int optInt(String key, int defaultValue) {\r
- try {\r
- return this.getInt(key);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an optional JSONArray associated with a key.\r
- * It returns null if there is no such key, or if its value is not a\r
- * JSONArray.\r
- *\r
- * @param key A key string.\r
- * @return A JSONArray which is the value.\r
- */\r
- public JSONArray optJSONArray(String key) {\r
- Object o = this.opt(key);\r
- return o instanceof JSONArray ? (JSONArray)o : null;\r
- }\r
-\r
-\r
- /**\r
- * Get an optional JSONObject associated with a key.\r
- * It returns null if there is no such key, or if its value is not a\r
- * JSONObject.\r
- *\r
- * @param key A key string.\r
- * @return A JSONObject which is the value.\r
- */\r
- public JSONObject optJSONObject(String key) {\r
- Object object = this.opt(key);\r
- return object instanceof JSONObject ? (JSONObject)object : null;\r
- }\r
-\r
-\r
- /**\r
- * Get an optional long value associated with a key,\r
- * or zero if there is no such key or if the value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @return An object which is the value.\r
- */\r
- public long optLong(String key) {\r
- return this.optLong(key, 0);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional long value associated with a key,\r
- * or the default if there is no such key or if the value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return An object which is the value.\r
- */\r
- public long optLong(String key, long defaultValue) {\r
- try {\r
- return this.getLong(key);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an optional string associated with a key.\r
- * It returns an empty string if there is no such key. If the value is not\r
- * a string and is not null, then it is converted to a string.\r
- *\r
- * @param key A key string.\r
- * @return A string which is the value.\r
- */\r
- public String optString(String key) {\r
- return this.optString(key, "");\r
- }\r
-\r
-\r
- /**\r
- * Get an optional string associated with a key.\r
- * It returns the defaultValue if there is no such key.\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return A string which is the value.\r
- */\r
- public String optString(String key, String defaultValue) {\r
- Object object = this.opt(key);\r
- return NULL.equals(object) ? defaultValue : object.toString();\r
- }\r
-\r
-\r
- private void populateMap(Object bean) {\r
- Class<? extends Object> klass = bean.getClass();\r
-\r
-// If klass is a System class then set includeSuperClass to false.\r
-\r
- boolean includeSuperClass = klass.getClassLoader() != null;\r
-\r
- Method[] methods = includeSuperClass\r
- ? klass.getMethods()\r
- : klass.getDeclaredMethods();\r
- for (int i = 0; i < methods.length; i += 1) {\r
- try {\r
- Method method = methods[i];\r
- if (Modifier.isPublic(method.getModifiers())) {\r
- String name = method.getName();\r
- String key = "";\r
- if (name.startsWith("get")) {\r
- if ("getClass".equals(name) ||\r
- "getDeclaringClass".equals(name)) {\r
- key = "";\r
- } else {\r
- key = name.substring(3);\r
- }\r
- } else if (name.startsWith("is")) {\r
- key = name.substring(2);\r
- }\r
- if (key.length() > 0 &&\r
- Character.isUpperCase(key.charAt(0)) &&\r
- method.getParameterTypes().length == 0) {\r
- if (key.length() == 1) {\r
- key = key.toLowerCase();\r
- } else if (!Character.isUpperCase(key.charAt(1))) {\r
- key = key.substring(0, 1).toLowerCase() +\r
- key.substring(1);\r
- }\r
-\r
- Object result = method.invoke(bean, (Object[])null);\r
- if (result != null) {\r
- this.map.put(key, wrap(result));\r
- }\r
- }\r
- }\r
- } catch (Exception ignore) {\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Put a key/boolean pair in the JSONObject.\r
- *\r
- * @param key A key string.\r
- * @param value A boolean which is the value.\r
- * @return this.\r
- * @throws JSONException If the key is null.\r
- */\r
- public JSONObject put(String key, boolean value) throws JSONException {\r
- this.put(key, value ? Boolean.TRUE : Boolean.FALSE);\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject, where the value will be a\r
- * JSONArray which is produced from a Collection.\r
- * @param key A key string.\r
- * @param value A Collection value.\r
- * @return this.\r
- * @throws JSONException\r
- */\r
- public JSONObject put(String key, Collection<Object> value) throws JSONException {\r
- this.put(key, new JSONArray(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/double pair in the JSONObject.\r
- *\r
- * @param key A key string.\r
- * @param value A double which is the value.\r
- * @return this.\r
- * @throws JSONException If the key is null or if the number is invalid.\r
- */\r
- public JSONObject put(String key, double value) throws JSONException {\r
- this.put(key, new Double(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/int pair in the JSONObject.\r
- *\r
- * @param key A key string.\r
- * @param value An int which is the value.\r
- * @return this.\r
- * @throws JSONException If the key is null.\r
- */\r
- public JSONObject put(String key, int value) throws JSONException {\r
- this.put(key, new Integer(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/long pair in the JSONObject.\r
- *\r
- * @param key A key string.\r
- * @param value A long which is the value.\r
- * @return this.\r
- * @throws JSONException If the key is null.\r
- */\r
- public JSONObject put(String key, long value) throws JSONException {\r
- this.put(key, new Long(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject, where the value will be a\r
- * JSONObject which is produced from a Map.\r
- * @param key A key string.\r
- * @param value A Map value.\r
- * @return this.\r
- * @throws JSONException\r
- */\r
- public JSONObject put(String key, Map<String, Object> value) throws JSONException {\r
- this.put(key, new JSONObject(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject. If the value is null,\r
- * then the key will be removed from the JSONObject if it is present.\r
- * @param key A key string.\r
- * @param value An object which is the value. It should be of one of these\r
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,\r
- * or the JSONObject.NULL object.\r
- * @return this.\r
- * @throws JSONException If the value is non-finite number\r
- * or if the key is null.\r
- */\r
- public JSONObject put(String key, Object value) throws JSONException {\r
- String pooled;\r
- if (key == null) {\r
- throw new JSONException("Null key.");\r
- }\r
- if (value != null) {\r
- testValidity(value);\r
- pooled = (String)keyPool.get(key);\r
- if (pooled == null) {\r
- if (keyPool.size() >= keyPoolSize) {\r
- keyPool = new HashMap<String, Object>(keyPoolSize);\r
- }\r
- keyPool.put(key, key);\r
- } else {\r
- key = pooled;\r
- }\r
- this.map.put(key, value);\r
- } else {\r
- this.remove(key);\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject, but only if the key and the\r
- * value are both non-null, and only if there is not already a member\r
- * with that name.\r
- * @param key\r
- * @param value\r
- * @return his.\r
- * @throws JSONException if the key is a duplicate\r
- */\r
- public JSONObject putOnce(String key, Object value) throws JSONException {\r
- if (key != null && value != null) {\r
- if (this.opt(key) != null) {\r
- throw new JSONException("Duplicate key \"" + key + "\"");\r
- }\r
- this.put(key, value);\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject, but only if the\r
- * key and the value are both non-null.\r
- * @param key A key string.\r
- * @param value An object which is the value. It should be of one of these\r
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,\r
- * or the JSONObject.NULL object.\r
- * @return this.\r
- * @throws JSONException If the value is a non-finite number.\r
- */\r
- public JSONObject putOpt(String key, Object value) throws JSONException {\r
- if (key != null && value != null) {\r
- this.put(key, value);\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Produce a string in double quotes with backslash sequences in all the\r
- * right places. A backslash will be inserted within </, producing <\/,\r
- * allowing JSON text to be delivered in HTML. In JSON text, a string\r
- * cannot contain a control character or an unescaped quote or backslash.\r
- * @param string A String\r
- * @return A String correctly formatted for insertion in a JSON text.\r
- */\r
- public static String quote(String string) {\r
- StringWriter sw = new StringWriter();\r
- synchronized (sw.getBuffer()) {\r
- try {\r
- return quote(string, sw).toString();\r
- } catch (IOException ignored) {\r
- // will never happen - we are writing to a string writer\r
- return "";\r
- }\r
- }\r
- }\r
-\r
- public static Writer quote(String string, Writer w) throws IOException {\r
- if (string == null || string.length() == 0) {\r
- w.write("\"\"");\r
- return w;\r
- }\r
-\r
- char b;\r
- char c = 0;\r
- String hhhh;\r
- int i;\r
- int len = string.length();\r
-\r
- w.write('"');\r
- for (i = 0; i < len; i += 1) {\r
- b = c;\r
- c = string.charAt(i);\r
- switch (c) {\r
- case '\\':\r
- case '"':\r
- w.write('\\');\r
- w.write(c);\r
- break;\r
- case '/':\r
- if (b == '<') {\r
- w.write('\\');\r
- }\r
- w.write(c);\r
- break;\r
- case '\b':\r
- w.write("\\b");\r
- break;\r
- case '\t':\r
- w.write("\\t");\r
- break;\r
- case '\n':\r
- w.write("\\n");\r
- break;\r
- case '\f':\r
- w.write("\\f");\r
- break;\r
- case '\r':\r
- w.write("\\r");\r
- break;\r
- default:\r
- if (c < ' ' || (c >= '\u0080' && c < '\u00a0')\r
- || (c >= '\u2000' && c < '\u2100')) {\r
- w.write("\\u");\r
- hhhh = Integer.toHexString(c);\r
- w.write("0000", 0, 4 - hhhh.length());\r
- w.write(hhhh);\r
- } else {\r
- w.write(c);\r
- }\r
- }\r
- }\r
- w.write('"');\r
- return w;\r
- }\r
-\r
- /**\r
- * Remove a name and its value, if present.\r
- * @param key The name to be removed.\r
- * @return The value that was associated with the name,\r
- * or null if there was no value.\r
- */\r
- public Object remove(String key) {\r
- return this.map.remove(key);\r
- }\r
-\r
- /**\r
- * Try to convert a string into a number, boolean, or null. If the string\r
- * can't be converted, return the string.\r
- * @param string A String.\r
- * @return A simple JSON value.\r
- */\r
- public static Object stringToValue(String string) {\r
- Double d;\r
- if (string.equals("")) {\r
- return string;\r
- }\r
- if (string.equalsIgnoreCase("true")) {\r
- return Boolean.TRUE;\r
- }\r
- if (string.equalsIgnoreCase("false")) {\r
- return Boolean.FALSE;\r
- }\r
- if (string.equalsIgnoreCase("null")) {\r
- return JSONObject.NULL;\r
- }\r
-\r
- /*\r
- * If it might be a number, try converting it.\r
- * If a number cannot be produced, then the value will just\r
- * be a string. Note that the plus and implied string\r
- * conventions are non-standard. A JSON parser may accept\r
- * non-JSON forms as long as it accepts all correct JSON forms.\r
- */\r
-\r
- char b = string.charAt(0);\r
- if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {\r
- try {\r
- if (string.indexOf('.') > -1 ||\r
- string.indexOf('e') > -1 || string.indexOf('E') > -1) {\r
- d = Double.valueOf(string);\r
- if (!d.isInfinite() && !d.isNaN()) {\r
- return d;\r
- }\r
- } else {\r
- Long myLong = new Long(string);\r
- if (myLong.longValue() == myLong.intValue()) {\r
- return new Integer(myLong.intValue());\r
- } else {\r
- return myLong;\r
- }\r
- }\r
- } catch (Exception ignore) {\r
- }\r
- }\r
- return string;\r
- }\r
-\r
-\r
- /**\r
- * Throw an exception if the object is a NaN or infinite number.\r
- * @param o The object to test.\r
- * @throws JSONException If o is a non-finite number.\r
- */\r
- public static void testValidity(Object o) throws JSONException {\r
- if (o != null) {\r
- if (o instanceof Double) {\r
- if (((Double)o).isInfinite() || ((Double)o).isNaN()) {\r
- throw new JSONException(\r
- "JSON does not allow non-finite numbers.");\r
- }\r
- } else if (o instanceof Float) {\r
- if (((Float)o).isInfinite() || ((Float)o).isNaN()) {\r
- throw new JSONException(\r
- "JSON does not allow non-finite numbers.");\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Produce a JSONArray containing the values of the members of this\r
- * JSONObject.\r
- * @param names A JSONArray containing a list of key strings. This\r
- * determines the sequence of the values in the result.\r
- * @return A JSONArray of values.\r
- * @throws JSONException If any of the values are non-finite numbers.\r
- */\r
- public JSONArray toJSONArray(JSONArray names) throws JSONException {\r
- if (names == null || names.length() == 0) {\r
- return null;\r
- }\r
- JSONArray ja = new JSONArray();\r
- for (int i = 0; i < names.length(); i += 1) {\r
- ja.put(this.opt(names.getString(i)));\r
- }\r
- return ja;\r
- }\r
-\r
- /**\r
- * Make a JSON text of this JSONObject. For compactness, no whitespace\r
- * is added. If this would not result in a syntactically correct JSON text,\r
- * then null will be returned instead.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- *\r
- * @return a printable, displayable, portable, transmittable\r
- * representation of the object, beginning\r
- * with <code>{</code> <small>(left brace)</small> and ending\r
- * with <code>}</code> <small>(right brace)</small>.\r
- */\r
- public String toString() {\r
- try {\r
- return this.toString(0);\r
- } catch (Exception e) {\r
- return null;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Make a prettyprinted JSON text of this JSONObject.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- * @param indentFactor The number of spaces to add to each level of\r
- * indentation.\r
- * @return a printable, displayable, portable, transmittable\r
- * representation of the object, beginning\r
- * with <code>{</code> <small>(left brace)</small> and ending\r
- * with <code>}</code> <small>(right brace)</small>.\r
- * @throws JSONException If the object contains an invalid number.\r
- */\r
- public String toString(int indentFactor) throws JSONException {\r
- StringWriter w = new StringWriter();\r
- synchronized (w.getBuffer()) {\r
- return this.write(w, indentFactor, 0).toString();\r
- }\r
- }\r
-\r
- /**\r
- * Make a JSON text of an Object value. If the object has an\r
- * value.toJSONString() method, then that method will be used to produce\r
- * the JSON text. The method is required to produce a strictly\r
- * conforming text. If the object does not contain a toJSONString\r
- * method (which is the most common case), then a text will be\r
- * produced by other means. If the value is an array or Collection,\r
- * then a JSONArray will be made from it and its toJSONString method\r
- * will be called. If the value is a MAP, then a JSONObject will be made\r
- * from it and its toJSONString method will be called. Otherwise, the\r
- * value's toString method will be called, and the result will be quoted.\r
- *\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- * @param value The value to be serialized.\r
- * @return a printable, displayable, transmittable\r
- * representation of the object, beginning\r
- * with <code>{</code> <small>(left brace)</small> and ending\r
- * with <code>}</code> <small>(right brace)</small>.\r
- * @throws JSONException If the value is or contains an invalid number.\r
- */\r
- @SuppressWarnings("unchecked")\r
- public static String valueToString(Object value) throws JSONException {\r
- if (value == null || value.equals(null)) {\r
- return "null";\r
- }\r
- if (value instanceof JSONString) {\r
- Object object;\r
- try {\r
- object = ((JSONString)value).toJSONString();\r
- } catch (Exception e) {\r
- throw new JSONException(e);\r
- }\r
- if (object instanceof String) {\r
- return (String)object;\r
- }\r
- throw new JSONException("Bad value from toJSONString: " + object);\r
- }\r
- if (value instanceof Number) {\r
- return numberToString((Number) value);\r
- }\r
- if (value instanceof Boolean || value instanceof JSONObject ||\r
- value instanceof JSONArray) {\r
- return value.toString();\r
- }\r
- if (value instanceof Map) {\r
- return new JSONObject((Map<String, Object>)value).toString();\r
- }\r
- if (value instanceof Collection) {\r
- return new JSONArray((Collection<Object>)value).toString();\r
- }\r
- if (value.getClass().isArray()) {\r
- return new JSONArray(value).toString();\r
- }\r
- return quote(value.toString());\r
- }\r
-\r
- /**\r
- * Wrap an object, if necessary. If the object is null, return the NULL\r
- * object. If it is an array or collection, wrap it in a JSONArray. If\r
- * it is a map, wrap it in a JSONObject. If it is a standard property\r
- * (Double, String, et al) then it is already wrapped. Otherwise, if it\r
- * comes from one of the java packages, turn it into a string. And if\r
- * it doesn't, try to wrap it in a JSONObject. If the wrapping fails,\r
- * then null is returned.\r
- *\r
- * @param object The object to wrap\r
- * @return The wrapped value\r
- */\r
- @SuppressWarnings("unchecked")\r
- public static Object wrap(Object object) {\r
- try {\r
- if (object == null) {\r
- return NULL;\r
- }\r
- if (object instanceof JSONObject || object instanceof JSONArray ||\r
- NULL.equals(object) || object instanceof JSONString ||\r
- object instanceof Byte || object instanceof Character ||\r
- object instanceof Short || object instanceof Integer ||\r
- object instanceof Long || object instanceof Boolean ||\r
- object instanceof Float || object instanceof Double ||\r
- object instanceof String) {\r
- return object;\r
- }\r
-\r
- if (object instanceof Collection) {\r
- return new JSONArray((Collection<Object>)object);\r
- }\r
- if (object.getClass().isArray()) {\r
- return new JSONArray(object);\r
- }\r
- if (object instanceof Map) {\r
- return new JSONObject((Map<String, Object>)object);\r
- }\r
- Package objectPackage = object.getClass().getPackage();\r
- String objectPackageName = objectPackage != null\r
- ? objectPackage.getName()\r
- : "";\r
- if (\r
- objectPackageName.startsWith("java.") ||\r
- objectPackageName.startsWith("javax.") ||\r
- object.getClass().getClassLoader() == null\r
- ) {\r
- return object.toString();\r
- }\r
- return new JSONObject(object);\r
- } catch(Exception exception) {\r
- return null;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Write the contents of the JSONObject as JSON text to a writer.\r
- * For compactness, no whitespace is added.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- *\r
- * @return The writer.\r
- * @throws JSONException\r
- */\r
- public Writer write(Writer writer) throws JSONException {\r
- return this.write(writer, 0, 0);\r
- }\r
-\r
-\r
- @SuppressWarnings("unchecked")\r
- static final Writer writeValue(Writer writer, Object value,\r
- int indentFactor, int indent) throws JSONException, IOException {\r
- if (value == null || value.equals(null)) {\r
- writer.write("null");\r
- } else if (value instanceof JSONObject) {\r
- ((JSONObject) value).write(writer, indentFactor, indent);\r
- } else if (value instanceof JSONArray) {\r
- ((JSONArray) value).write(writer, indentFactor, indent);\r
- } else if (value instanceof Map) {\r
- new JSONObject((Map<String, Object>) value).write(writer, indentFactor, indent);\r
- } else if (value instanceof Collection) {\r
- new JSONArray((Collection<Object>) value).write(writer, indentFactor,\r
- indent);\r
- } else if (value.getClass().isArray()) {\r
- new JSONArray(value).write(writer, indentFactor, indent);\r
- } else if (value instanceof Number) {\r
- writer.write(numberToString((Number) value));\r
- } else if (value instanceof Boolean) {\r
- writer.write(value.toString());\r
- } else if (value instanceof JSONString) {\r
- Object o;\r
- try {\r
- o = ((JSONString) value).toJSONString();\r
- } catch (Exception e) {\r
- throw new JSONException(e);\r
- }\r
- writer.write(o != null ? o.toString() : quote(value.toString()));\r
- } else {\r
- quote(value.toString(), writer);\r
- }\r
- return writer;\r
- }\r
-\r
- static final void indent(Writer writer, int indent) throws IOException {\r
- for (int i = 0; i < indent; i += 1) {\r
- writer.write(' ');\r
- }\r
- }\r
-\r
- /**\r
- * Write the contents of the JSONObject as JSON text to a writer. For\r
- * compactness, no whitespace is added.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- *\r
- * @return The writer.\r
- * @throws JSONException\r
- */\r
- Writer write(Writer writer, int indentFactor, int indent)\r
- throws JSONException {\r
- try {\r
- boolean commanate = false;\r
- final int length = this.length();\r
- Iterator<String> keys = this.keys();\r
- writer.write('{');\r
-\r
- if (length == 1) {\r
- Object key = keys.next();\r
- writer.write(quote(key.toString()));\r
- writer.write(':');\r
- if (indentFactor > 0) {\r
- writer.write(' ');\r
- }\r
- writeValue(writer, this.map.get(key), indentFactor, indent);\r
- } else if (length != 0) {\r
- final int newindent = indent + indentFactor;\r
- while (keys.hasNext()) {\r
- Object key = keys.next();\r
- if (commanate) {\r
- writer.write(',');\r
- }\r
- if (indentFactor > 0) {\r
- writer.write('\n');\r
- }\r
- indent(writer, newindent);\r
- writer.write(quote(key.toString()));\r
- writer.write(':');\r
- if (indentFactor > 0) {\r
- writer.write(' ');\r
- }\r
- writeValue(writer, this.map.get(key), indentFactor,\r
- newindent);\r
- commanate = true;\r
- }\r
- if (indentFactor > 0) {\r
- writer.write('\n');\r
- }\r
- indent(writer, indent);\r
- }\r
- writer.write('}');\r
- return writer;\r
- } catch (IOException exception) {\r
- throw new JSONException(exception);\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-/**\r
- * The <code>JSONString</code> interface allows a <code>toJSONString()</code>\r
- * method so that a class can change the behavior of\r
- * <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>,\r
- * and <code>JSONWriter.value(</code>Object<code>)</code>. The\r
- * <code>toJSONString</code> method will be used instead of the default behavior\r
- * of using the Object's <code>toString()</code> method and quoting the result.\r
- */\r
-public interface JSONString {\r
- /**\r
- * The <code>toJSONString</code> method allows a class to produce its own JSON\r
- * serialization.\r
- *\r
- * @return A strictly syntactically correct JSON text.\r
- */\r
- public String toJSONString();\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2006 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-import java.io.StringWriter;\r
-\r
-/**\r
- * JSONStringer provides a quick and convenient way of producing JSON text.\r
- * The texts produced strictly conform to JSON syntax rules. No whitespace is\r
- * added, so the results are ready for transmission or storage. Each instance of\r
- * JSONStringer can produce one JSON text.\r
- * <p>\r
- * A JSONStringer instance provides a <code>value</code> method for appending\r
- * values to the\r
- * text, and a <code>key</code>\r
- * method for adding keys before values in objects. There are <code>array</code>\r
- * and <code>endArray</code> methods that make and bound array values, and\r
- * <code>object</code> and <code>endObject</code> methods which make and bound\r
- * object values. All of these methods return the JSONWriter instance,\r
- * permitting cascade style. For example, <pre>\r
- * myString = new JSONStringer()\r
- * .object()\r
- * .key("JSON")\r
- * .value("Hello, World!")\r
- * .endObject()\r
- * .toString();</pre> which produces the string <pre>\r
- * {"JSON":"Hello, World!"}</pre>\r
- * <p>\r
- * The first method called must be <code>array</code> or <code>object</code>.\r
- * There are no methods for adding commas or colons. JSONStringer adds them for\r
- * you. Objects and arrays can be nested up to 20 levels deep.\r
- * <p>\r
- * This can sometimes be easier than using a JSONObject to build a string.\r
- * @author JSON.org\r
- * @version 2008-09-18\r
- */\r
-public class JSONStringer extends JSONWriter {\r
- /**\r
- * Make a fresh JSONStringer. It can be used to build one JSON text.\r
- */\r
- public JSONStringer() {\r
- super(new StringWriter());\r
- }\r
-\r
- /**\r
- * Return the JSON text. This method is used to obtain the product of the\r
- * JSONStringer instance. It will return <code>null</code> if there was a\r
- * problem in the construction of the JSON text (such as the calls to\r
- * <code>array</code> were not properly balanced with calls to\r
- * <code>endArray</code>).\r
- * @return The JSON text.\r
- */\r
- public String toString() {\r
- return this.mode == 'd' ? this.writer.toString() : null;\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.io.Reader;\r
-import java.io.StringReader;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-/**\r
- * A JSONTokener takes a source string and extracts characters and tokens from\r
- * it. It is used by the JSONObject and JSONArray constructors to parse\r
- * JSON source strings.\r
- * @author JSON.org\r
- * @version 2012-02-16\r
- */\r
-public class JSONTokener {\r
-\r
- private long character;\r
- private boolean eof;\r
- private long index;\r
- private long line;\r
- private char previous;\r
- private Reader reader;\r
- private boolean usePrevious;\r
-\r
-\r
- /**\r
- * Construct a JSONTokener from a Reader.\r
- *\r
- * @param reader A reader.\r
- */\r
- public JSONTokener(Reader reader) {\r
- this.reader = reader.markSupported()\r
- ? reader\r
- : new BufferedReader(reader);\r
- this.eof = false;\r
- this.usePrevious = false;\r
- this.previous = 0;\r
- this.index = 0;\r
- this.character = 1;\r
- this.line = 1;\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONTokener from an InputStream.\r
- */\r
- public JSONTokener(InputStream inputStream) throws JSONException {\r
- this(new InputStreamReader(inputStream));\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONTokener from a string.\r
- *\r
- * @param s A source string.\r
- */\r
- public JSONTokener(String s) {\r
- this(new StringReader(s));\r
- }\r
-\r
-\r
- /**\r
- * Back up one character. This provides a sort of lookahead capability,\r
- * so that you can test for a digit or letter before attempting to parse\r
- * the next number or identifier.\r
- */\r
- public void back() throws JSONException {\r
- if (this.usePrevious || this.index <= 0) {\r
- throw new JSONException("Stepping back two steps is not supported");\r
- }\r
- this.index -= 1;\r
- this.character -= 1;\r
- this.usePrevious = true;\r
- this.eof = false;\r
- }\r
-\r
-\r
- /**\r
- * Get the hex value of a character (base16).\r
- * @param c A character between '0' and '9' or between 'A' and 'F' or\r
- * between 'a' and 'f'.\r
- * @return An int between 0 and 15, or -1 if c was not a hex digit.\r
- */\r
- public static int dehexchar(char c) {\r
- if (c >= '0' && c <= '9') {\r
- return c - '0';\r
- }\r
- if (c >= 'A' && c <= 'F') {\r
- return c - ('A' - 10);\r
- }\r
- if (c >= 'a' && c <= 'f') {\r
- return c - ('a' - 10);\r
- }\r
- return -1;\r
- }\r
-\r
- public boolean end() {\r
- return this.eof && !this.usePrevious;\r
- }\r
-\r
-\r
- /**\r
- * Determine if the source string still contains characters that next()\r
- * can consume.\r
- * @return true if not yet at the end of the source.\r
- */\r
- public boolean more() throws JSONException {\r
- this.next();\r
- if (this.end()) {\r
- return false;\r
- }\r
- this.back();\r
- return true;\r
- }\r
-\r
-\r
- /**\r
- * Get the next character in the source string.\r
- *\r
- * @return The next character, or 0 if past the end of the source string.\r
- */\r
- public char next() throws JSONException {\r
- int c;\r
- if (this.usePrevious) {\r
- this.usePrevious = false;\r
- c = this.previous;\r
- } else {\r
- try {\r
- c = this.reader.read();\r
- } catch (IOException exception) {\r
- throw new JSONException(exception);\r
- }\r
-\r
- if (c <= 0) { // End of stream\r
- this.eof = true;\r
- c = 0;\r
- }\r
- }\r
- this.index += 1;\r
- if (this.previous == '\r') {\r
- this.line += 1;\r
- this.character = c == '\n' ? 0 : 1;\r
- } else if (c == '\n') {\r
- this.line += 1;\r
- this.character = 0;\r
- } else {\r
- this.character += 1;\r
- }\r
- this.previous = (char) c;\r
- return this.previous;\r
- }\r
-\r
-\r
- /**\r
- * Consume the next character, and check that it matches a specified\r
- * character.\r
- * @param c The character to match.\r
- * @return The character.\r
- * @throws JSONException if the character does not match.\r
- */\r
- public char next(char c) throws JSONException {\r
- char n = this.next();\r
- if (n != c) {\r
- throw this.syntaxError("Expected '" + c + "' and instead saw '" +\r
- n + "'");\r
- }\r
- return n;\r
- }\r
-\r
-\r
- /**\r
- * Get the next n characters.\r
- *\r
- * @param n The number of characters to take.\r
- * @return A string of n characters.\r
- * @throws JSONException\r
- * Substring bounds error if there are not\r
- * n characters remaining in the source string.\r
- */\r
- public String next(int n) throws JSONException {\r
- if (n == 0) {\r
- return "";\r
- }\r
-\r
- char[] chars = new char[n];\r
- int pos = 0;\r
-\r
- while (pos < n) {\r
- chars[pos] = this.next();\r
- if (this.end()) {\r
- throw this.syntaxError("Substring bounds error");\r
- }\r
- pos += 1;\r
- }\r
- return new String(chars);\r
- }\r
-\r
-\r
- /**\r
- * Get the next char in the string, skipping whitespace.\r
- * @throws JSONException\r
- * @return A character, or 0 if there are no more characters.\r
- */\r
- public char nextClean() throws JSONException {\r
- for (;;) {\r
- char c = this.next();\r
- if (c == 0 || c > ' ') {\r
- return c;\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Return the characters up to the next close quote character.\r
- * Backslash processing is done. The formal JSON format does not\r
- * allow strings in single quotes, but an implementation is allowed to\r
- * accept them.\r
- * @param quote The quoting character, either\r
- * <code>"</code> <small>(double quote)</small> or\r
- * <code>'</code> <small>(single quote)</small>.\r
- * @return A String.\r
- * @throws JSONException Unterminated string.\r
- */\r
- public String nextString(char quote) throws JSONException {\r
- char c;\r
- StringBuffer sb = new StringBuffer();\r
- for (;;) {\r
- c = this.next();\r
- switch (c) {\r
- case 0:\r
- case '\n':\r
- case '\r':\r
- throw this.syntaxError("Unterminated string");\r
- case '\\':\r
- c = this.next();\r
- switch (c) {\r
- case 'b':\r
- sb.append('\b');\r
- break;\r
- case 't':\r
- sb.append('\t');\r
- break;\r
- case 'n':\r
- sb.append('\n');\r
- break;\r
- case 'f':\r
- sb.append('\f');\r
- break;\r
- case 'r':\r
- sb.append('\r');\r
- break;\r
- case 'u':\r
- sb.append((char)Integer.parseInt(this.next(4), 16));\r
- break;\r
- case '"':\r
- case '\'':\r
- case '\\':\r
- case '/':\r
- sb.append(c);\r
- break;\r
- default:\r
- throw this.syntaxError("Illegal escape.");\r
- }\r
- break;\r
- default:\r
- if (c == quote) {\r
- return sb.toString();\r
- }\r
- sb.append(c);\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the text up but not including the specified character or the\r
- * end of line, whichever comes first.\r
- * @param delimiter A delimiter character.\r
- * @return A string.\r
- */\r
- public String nextTo(char delimiter) throws JSONException {\r
- StringBuffer sb = new StringBuffer();\r
- for (;;) {\r
- char c = this.next();\r
- if (c == delimiter || c == 0 || c == '\n' || c == '\r') {\r
- if (c != 0) {\r
- this.back();\r
- }\r
- return sb.toString().trim();\r
- }\r
- sb.append(c);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the text up but not including one of the specified delimiter\r
- * characters or the end of line, whichever comes first.\r
- * @param delimiters A set of delimiter characters.\r
- * @return A string, trimmed.\r
- */\r
- public String nextTo(String delimiters) throws JSONException {\r
- char c;\r
- StringBuffer sb = new StringBuffer();\r
- for (;;) {\r
- c = this.next();\r
- if (delimiters.indexOf(c) >= 0 || c == 0 ||\r
- c == '\n' || c == '\r') {\r
- if (c != 0) {\r
- this.back();\r
- }\r
- return sb.toString().trim();\r
- }\r
- sb.append(c);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the next value. The value can be a Boolean, Double, Integer,\r
- * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.\r
- * @throws JSONException If syntax error.\r
- *\r
- * @return An object.\r
- */\r
- public Object nextValue() throws JSONException {\r
- char c = this.nextClean();\r
- String string;\r
-\r
- switch (c) {\r
- case '"':\r
- case '\'':\r
- return this.nextString(c);\r
- case '{':\r
- this.back();\r
- return new JSONObject(this);\r
- case '[':\r
- this.back();\r
- return new JSONArray(this);\r
- }\r
-\r
- /*\r
- * Handle unquoted text. This could be the values true, false, or\r
- * null, or it can be a number. An implementation (such as this one)\r
- * is allowed to also accept non-standard forms.\r
- *\r
- * Accumulate characters until we reach the end of the text or a\r
- * formatting character.\r
- */\r
-\r
- StringBuffer sb = new StringBuffer();\r
- while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {\r
- sb.append(c);\r
- c = this.next();\r
- }\r
- this.back();\r
-\r
- string = sb.toString().trim();\r
- if ("".equals(string)) {\r
- throw this.syntaxError("Missing value");\r
- }\r
- return JSONObject.stringToValue(string);\r
- }\r
-\r
-\r
- /**\r
- * Skip characters until the next character is the requested character.\r
- * If the requested character is not found, no characters are skipped.\r
- * @param to A character to skip to.\r
- * @return The requested character, or zero if the requested character\r
- * is not found.\r
- */\r
- public char skipTo(char to) throws JSONException {\r
- char c;\r
- try {\r
- long startIndex = this.index;\r
- long startCharacter = this.character;\r
- long startLine = this.line;\r
- this.reader.mark(1000000);\r
- do {\r
- c = this.next();\r
- if (c == 0) {\r
- this.reader.reset();\r
- this.index = startIndex;\r
- this.character = startCharacter;\r
- this.line = startLine;\r
- return c;\r
- }\r
- } while (c != to);\r
- } catch (IOException exc) {\r
- throw new JSONException(exc);\r
- }\r
-\r
- this.back();\r
- return c;\r
- }\r
-\r
-\r
- /**\r
- * Make a JSONException to signal a syntax error.\r
- *\r
- * @param message The error message.\r
- * @return A JSONException object, suitable for throwing\r
- */\r
- public JSONException syntaxError(String message) {\r
- return new JSONException(message + this.toString());\r
- }\r
-\r
-\r
- /**\r
- * Make a printable string of this JSONTokener.\r
- *\r
- * @return " at {index} [character {character} line {line}]"\r
- */\r
- public String toString() {\r
- return " at " + this.index + " [character " + this.character + " line " +\r
- this.line + "]";\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-import java.io.IOException;\r
-import java.io.Writer;\r
-\r
-/*\r
-Copyright (c) 2006 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-/**\r
- * JSONWriter provides a quick and convenient way of producing JSON text.\r
- * The texts produced strictly conform to JSON syntax rules. No whitespace is\r
- * added, so the results are ready for transmission or storage. Each instance of\r
- * JSONWriter can produce one JSON text.\r
- * <p>\r
- * A JSONWriter instance provides a <code>value</code> method for appending\r
- * values to the\r
- * text, and a <code>key</code>\r
- * method for adding keys before values in objects. There are <code>array</code>\r
- * and <code>endArray</code> methods that make and bound array values, and\r
- * <code>object</code> and <code>endObject</code> methods which make and bound\r
- * object values. All of these methods return the JSONWriter instance,\r
- * permitting a cascade style. For example, <pre>\r
- * new JSONWriter(myWriter)\r
- * .object()\r
- * .key("JSON")\r
- * .value("Hello, World!")\r
- * .endObject();</pre> which writes <pre>\r
- * {"JSON":"Hello, World!"}</pre>\r
- * <p>\r
- * The first method called must be <code>array</code> or <code>object</code>.\r
- * There are no methods for adding commas or colons. JSONWriter adds them for\r
- * you. Objects and arrays can be nested up to 20 levels deep.\r
- * <p>\r
- * This can sometimes be easier than using a JSONObject to build a string.\r
- * @author JSON.org\r
- * @version 2011-11-24\r
- */\r
-public class JSONWriter {\r
- private static final int maxdepth = 200;\r
-\r
- /**\r
- * The comma flag determines if a comma should be output before the next\r
- * value.\r
- */\r
- private boolean comma;\r
-\r
- /**\r
- * The current mode. Values:\r
- * 'a' (array),\r
- * 'd' (done),\r
- * 'i' (initial),\r
- * 'k' (key),\r
- * 'o' (object).\r
- */\r
- protected char mode;\r
-\r
- /**\r
- * The object/array stack.\r
- */\r
- private final JSONObject stack[];\r
-\r
- /**\r
- * The stack top index. A value of 0 indicates that the stack is empty.\r
- */\r
- private int top;\r
-\r
- /**\r
- * The writer that will receive the output.\r
- */\r
- protected Writer writer;\r
-\r
- /**\r
- * Make a fresh JSONWriter. It can be used to build one JSON text.\r
- */\r
- public JSONWriter(Writer w) {\r
- this.comma = false;\r
- this.mode = 'i';\r
- this.stack = new JSONObject[maxdepth];\r
- this.top = 0;\r
- this.writer = w;\r
- }\r
-\r
- /**\r
- * Append a value.\r
- * @param string A string value.\r
- * @return this\r
- * @throws JSONException If the value is out of sequence.\r
- */\r
- private JSONWriter append(String string) throws JSONException {\r
- if (string == null) {\r
- throw new JSONException("Null pointer");\r
- }\r
- if (this.mode == 'o' || this.mode == 'a') {\r
- try {\r
- if (this.comma && this.mode == 'a') {\r
- this.writer.write(',');\r
- }\r
- this.writer.write(string);\r
- } catch (IOException e) {\r
- throw new JSONException(e);\r
- }\r
- if (this.mode == 'o') {\r
- this.mode = 'k';\r
- }\r
- this.comma = true;\r
- return this;\r
- }\r
- throw new JSONException("Value out of sequence.");\r
- }\r
-\r
- /**\r
- * Begin appending a new array. All values until the balancing\r
- * <code>endArray</code> will be appended to this array. The\r
- * <code>endArray</code> method must be called to mark the array's end.\r
- * @return this\r
- * @throws JSONException If the nesting is too deep, or if the object is\r
- * started in the wrong place (for example as a key or after the end of the\r
- * outermost array or object).\r
- */\r
- public JSONWriter array() throws JSONException {\r
- if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') {\r
- this.push(null);\r
- this.append("[");\r
- this.comma = false;\r
- return this;\r
- }\r
- throw new JSONException("Misplaced array.");\r
- }\r
-\r
- /**\r
- * End something.\r
- * @param mode Mode\r
- * @param c Closing character\r
- * @return this\r
- * @throws JSONException If unbalanced.\r
- */\r
- private JSONWriter end(char mode, char c) throws JSONException {\r
- if (this.mode != mode) {\r
- throw new JSONException(mode == 'a'\r
- ? "Misplaced endArray."\r
- : "Misplaced endObject.");\r
- }\r
- this.pop(mode);\r
- try {\r
- this.writer.write(c);\r
- } catch (IOException e) {\r
- throw new JSONException(e);\r
- }\r
- this.comma = true;\r
- return this;\r
- }\r
-\r
- /**\r
- * End an array. This method most be called to balance calls to\r
- * <code>array</code>.\r
- * @return this\r
- * @throws JSONException If incorrectly nested.\r
- */\r
- public JSONWriter endArray() throws JSONException {\r
- return this.end('a', ']');\r
- }\r
-\r
- /**\r
- * End an object. This method most be called to balance calls to\r
- * <code>object</code>.\r
- * @return this\r
- * @throws JSONException If incorrectly nested.\r
- */\r
- public JSONWriter endObject() throws JSONException {\r
- return this.end('k', '}');\r
- }\r
-\r
- /**\r
- * Append a key. The key will be associated with the next value. In an\r
- * object, every value must be preceded by a key.\r
- * @param string A key string.\r
- * @return this\r
- * @throws JSONException If the key is out of place. For example, keys\r
- * do not belong in arrays or if the key is null.\r
- */\r
- public JSONWriter key(String string) throws JSONException {\r
- if (string == null) {\r
- throw new JSONException("Null key.");\r
- }\r
- if (this.mode == 'k') {\r
- try {\r
- this.stack[this.top - 1].putOnce(string, Boolean.TRUE);\r
- if (this.comma) {\r
- this.writer.write(',');\r
- }\r
- this.writer.write(JSONObject.quote(string));\r
- this.writer.write(':');\r
- this.comma = false;\r
- this.mode = 'o';\r
- return this;\r
- } catch (IOException e) {\r
- throw new JSONException(e);\r
- }\r
- }\r
- throw new JSONException("Misplaced key.");\r
- }\r
-\r
-\r
- /**\r
- * Begin appending a new object. All keys and values until the balancing\r
- * <code>endObject</code> will be appended to this object. The\r
- * <code>endObject</code> method must be called to mark the object's end.\r
- * @return this\r
- * @throws JSONException If the nesting is too deep, or if the object is\r
- * started in the wrong place (for example as a key or after the end of the\r
- * outermost array or object).\r
- */\r
- public JSONWriter object() throws JSONException {\r
- if (this.mode == 'i') {\r
- this.mode = 'o';\r
- }\r
- if (this.mode == 'o' || this.mode == 'a') {\r
- this.append("{");\r
- this.push(new JSONObject());\r
- this.comma = false;\r
- return this;\r
- }\r
- throw new JSONException("Misplaced object.");\r
-\r
- }\r
-\r
-\r
- /**\r
- * Pop an array or object scope.\r
- * @param c The scope to close.\r
- * @throws JSONException If nesting is wrong.\r
- */\r
- private void pop(char c) throws JSONException {\r
- if (this.top <= 0) {\r
- throw new JSONException("Nesting error.");\r
- }\r
- char m = this.stack[this.top - 1] == null ? 'a' : 'k';\r
- if (m != c) {\r
- throw new JSONException("Nesting error.");\r
- }\r
- this.top -= 1;\r
- this.mode = this.top == 0\r
- ? 'd'\r
- : this.stack[this.top - 1] == null\r
- ? 'a'\r
- : 'k';\r
- }\r
-\r
- /**\r
- * Push an array or object scope.\r
- * @param jo The scope to open.\r
- * @throws JSONException If nesting is too deep.\r
- */\r
- private void push(JSONObject jo) throws JSONException {\r
- if (this.top >= maxdepth) {\r
- throw new JSONException("Nesting too deep.");\r
- }\r
- this.stack[this.top] = jo;\r
- this.mode = jo == null ? 'a' : 'k';\r
- this.top += 1;\r
- }\r
-\r
-\r
- /**\r
- * Append either the value <code>true</code> or the value\r
- * <code>false</code>.\r
- * @param b A boolean.\r
- * @return this\r
- * @throws JSONException\r
- */\r
- public JSONWriter value(boolean b) throws JSONException {\r
- return this.append(b ? "true" : "false");\r
- }\r
-\r
- /**\r
- * Append a double value.\r
- * @param d A double.\r
- * @return this\r
- * @throws JSONException If the number is not finite.\r
- */\r
- public JSONWriter value(double d) throws JSONException {\r
- return this.value(new Double(d));\r
- }\r
-\r
- /**\r
- * Append a long value.\r
- * @param l A long.\r
- * @return this\r
- * @throws JSONException\r
- */\r
- public JSONWriter value(long l) throws JSONException {\r
- return this.append(Long.toString(l));\r
- }\r
-\r
-\r
- /**\r
- * Append an object value.\r
- * @param object The object to append. It can be null, or a Boolean, Number,\r
- * String, JSONObject, or JSONArray, or an object that implements JSONString.\r
- * @return this\r
- * @throws JSONException If the value is out of sequence.\r
- */\r
- public JSONWriter value(Object object) throws JSONException {\r
- return this.append(JSONObject.valueToString(object));\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-import java.io.IOException;\r
-import java.io.StringWriter;\r
-import java.io.Writer;\r
-import java.lang.reflect.Field;\r
-import java.lang.reflect.Method;\r
-import java.lang.reflect.Modifier;\r
-import java.util.Collection;\r
-import java.util.Enumeration;\r
-import java.util.LinkedHashMap;\r
-import java.util.Iterator;\r
-import java.util.Locale;\r
-import java.util.Map;\r
-import java.util.ResourceBundle;\r
-import java.util.Set;\r
-\r
-/**\r
- * A JSONObject is an unordered collection of name/value pairs. Its external\r
- * form is a string wrapped in curly braces with colons between the names and\r
- * values, and commas between the values and names. The internal form is an\r
- * object having <code>get</code> and <code>opt</code> methods for accessing the\r
- * values by name, and <code>put</code> methods for adding or replacing values\r
- * by name. The values can be any of these types: <code>Boolean</code>,\r
- * <code>JSONArray</code>, <code>JSONObject</code>, <code>Number</code>,\r
- * <code>String</code>, or the <code>JSONObject.NULL</code> object. A JSONObject\r
- * constructor can be used to convert an external form JSON text into an\r
- * internal form whose values can be retrieved with the <code>get</code> and\r
- * <code>opt</code> methods, or to convert values into a JSON text using the\r
- * <code>put</code> and <code>toString</code> methods. A <code>get</code> method\r
- * returns a value if one can be found, and throws an exception if one cannot be\r
- * found. An <code>opt</code> method returns a default value instead of throwing\r
- * an exception, and so is useful for obtaining optional values.\r
- * <p>\r
- * The generic <code>get()</code> and <code>opt()</code> methods return an\r
- * object, which you can cast or query for type. There are also typed\r
- * <code>get</code> and <code>opt</code> methods that do type checking and type\r
- * coercion for you. The opt methods differ from the get methods in that they do\r
- * not throw. Instead, they return a specified value, such as null.\r
- * <p>\r
- * The <code>put</code> methods add or replace values in an object. For example,\r
- *\r
- * <pre>\r
- * myString = new JSONObject().put("JSON", "Hello, World!").toString();\r
- * </pre>\r
- *\r
- * produces the string <code>{"JSON": "Hello, World"}</code>.\r
- * <p>\r
- * The texts produced by the <code>toString</code> methods strictly conform to\r
- * the JSON syntax rules. The constructors are more forgiving in the texts they\r
- * will accept:\r
- * <ul>\r
- * <li>An extra <code>,</code> <small>(comma)</small> may appear just\r
- * before the closing brace.</li>\r
- * <li>Strings may be quoted with <code>'</code> <small>(single\r
- * quote)</small>.</li>\r
- * <li>Strings do not need to be quoted at all if they do not begin with a quote\r
- * or single quote, and if they do not contain leading or trailing spaces, and\r
- * if they do not contain any of these characters:\r
- * <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers and\r
- * if they are not the reserved words <code>true</code>, <code>false</code>, or\r
- * <code>null</code>.</li>\r
- * <li>Keys can be followed by <code>=</code> or <code>=></code> as well as by\r
- * <code>:</code>.</li>\r
- * <li>Values can be followed by <code>;</code> <small>(semicolon)</small> as\r
- * well as by <code>,</code> <small>(comma)</small>.</li>\r
- * </ul>\r
- *\r
- * @author JSON.org\r
- * @version 2012-12-01\r
- */\r
-public class LOGJSONObject {\r
- /**\r
- * The maximum number of keys in the key pool.\r
- */\r
- private static final int keyPoolSize = 100;\r
-\r
- /**\r
- * Key pooling is like string interning, but without permanently tying up\r
- * memory. To help conserve memory, storage of duplicated key strings in\r
- * JSONObjects will be avoided by using a key pool to manage unique key\r
- * string objects. This is used by JSONObject.put(string, object).\r
- */\r
- private static Map<String,Object> keyPool = new LinkedHashMap<String,Object>(keyPoolSize);\r
-\r
- /**\r
- * JSONObject.NULL is equivalent to the value that JavaScript calls null,\r
- * whilst Java's null is equivalent to the value that JavaScript calls\r
- * undefined.\r
- */\r
- private static final class Null {\r
-\r
- /**\r
- * There is only intended to be a single instance of the NULL object,\r
- * so the clone method returns itself.\r
- * @return NULL.\r
- */\r
- protected final Object clone() {\r
- return this;\r
- }\r
-\r
- /**\r
- * A Null object is equal to the null value and to itself.\r
- * @param object An object to test for nullness.\r
- * @return true if the object parameter is the JSONObject.NULL object\r
- * or null.\r
- */\r
- public boolean equals(Object object) {\r
- return object == null || object == this;\r
- }\r
-\r
- /**\r
- * Get the "null" string value.\r
- * @return The string "null".\r
- */\r
- public String toString() {\r
- return "null";\r
- }\r
- }\r
-\r
-\r
- /**\r
- * The map where the JSONObject's properties are kept.\r
- */\r
- private final Map<String,Object> map;\r
-\r
-\r
- /**\r
- * It is sometimes more convenient and less ambiguous to have a\r
- * <code>NULL</code> object than to use Java's <code>null</code> value.\r
- * <code>JSONObject.NULL.equals(null)</code> returns <code>true</code>.\r
- * <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>.\r
- */\r
- public static final Object NULL = new Null();\r
-\r
-\r
- /**\r
- * Construct an empty JSONObject.\r
- */\r
- public LOGJSONObject() {\r
- this.map = new LinkedHashMap<String,Object>();\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a subset of another JSONObject.\r
- * An array of strings is used to identify the keys that should be copied.\r
- * Missing keys are ignored.\r
- * @param jo A JSONObject.\r
- * @param names An array of strings.\r
- * @throws JSONException\r
- * @exception JSONException If a value is a non-finite number or if a name is duplicated.\r
- */\r
- public LOGJSONObject(LOGJSONObject jo, String[] names) {\r
- this();\r
- for (int i = 0; i < names.length; i += 1) {\r
- try {\r
- this.putOnce(names[i], jo.opt(names[i]));\r
- } catch (Exception ignore) {\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a JSONTokener.\r
- * @param x A JSONTokener object containing the source string.\r
- * @throws JSONException If there is a syntax error in the source string\r
- * or a duplicated key.\r
- */\r
- public LOGJSONObject(JSONTokener x) throws JSONException {\r
- this();\r
- char c;\r
- String key;\r
-\r
- if (x.nextClean() != '{') {\r
- throw x.syntaxError("A JSONObject text must begin with '{'");\r
- }\r
- for (;;) {\r
- c = x.nextClean();\r
- switch (c) {\r
- case 0:\r
- throw x.syntaxError("A JSONObject text must end with '}'");\r
- case '}':\r
- return;\r
- default:\r
- x.back();\r
- key = x.nextValue().toString();\r
- }\r
-\r
-// The key is followed by ':'. We will also tolerate '=' or '=>'.\r
-\r
- c = x.nextClean();\r
- if (c == '=') {\r
- if (x.next() != '>') {\r
- x.back();\r
- }\r
- } else if (c != ':') {\r
- throw x.syntaxError("Expected a ':' after a key");\r
- }\r
- this.putOnce(key, x.nextValue());\r
-\r
-// Pairs are separated by ','. We will also tolerate ';'.\r
-\r
- switch (x.nextClean()) {\r
- case ';':\r
- case ',':\r
- if (x.nextClean() == '}') {\r
- return;\r
- }\r
- x.back();\r
- break;\r
- case '}':\r
- return;\r
- default:\r
- throw x.syntaxError("Expected a ',' or '}'");\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a Map.\r
- *\r
- * @param map A map object that can be used to initialize the contents of\r
- * the JSONObject.\r
- * @throws JSONException\r
- */\r
- public LOGJSONObject(Map<String,Object> map) {\r
- this.map = new LinkedHashMap<String,Object>();\r
- if (map != null) {\r
- Iterator<Map.Entry<String,Object>> i = map.entrySet().iterator();\r
- while (i.hasNext()) {\r
- Map.Entry<String,Object> e = i.next();\r
- Object value = e.getValue();\r
- if (value != null) {\r
- this.map.put(e.getKey(), wrap(value));\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from an Object using bean getters.\r
- * It reflects on all of the public methods of the object.\r
- * For each of the methods with no parameters and a name starting\r
- * with <code>"get"</code> or <code>"is"</code> followed by an uppercase letter,\r
- * the method is invoked, and a key and the value returned from the getter method\r
- * are put into the new JSONObject.\r
- *\r
- * The key is formed by removing the <code>"get"</code> or <code>"is"</code> prefix.\r
- * If the second remaining character is not upper case, then the first\r
- * character is converted to lower case.\r
- *\r
- * For example, if an object has a method named <code>"getName"</code>, and\r
- * if the result of calling <code>object.getName()</code> is <code>"Larry Fine"</code>,\r
- * then the JSONObject will contain <code>"name": "Larry Fine"</code>.\r
- *\r
- * @param bean An object that has getter methods that should be used\r
- * to make a JSONObject.\r
- */\r
- public LOGJSONObject(Object bean) {\r
- this();\r
- this.populateMap(bean);\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from an Object, using reflection to find the\r
- * public members. The resulting JSONObject's keys will be the strings\r
- * from the names array, and the values will be the field values associated\r
- * with those keys in the object. If a key is not found or not visible,\r
- * then it will not be copied into the new JSONObject.\r
- * @param object An object that has fields that should be used to make a\r
- * JSONObject.\r
- * @param names An array of strings, the names of the fields to be obtained\r
- * from the object.\r
- */\r
- public LOGJSONObject(Object object, String names[]) {\r
- this();\r
- Class<? extends Object> c = object.getClass();\r
- for (int i = 0; i < names.length; i += 1) {\r
- String name = names[i];\r
- try {\r
- this.putOpt(name, c.getField(name).get(object));\r
- } catch (Exception ignore) {\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a source JSON text string.\r
- * This is the most commonly used JSONObject constructor.\r
- * @param source A string beginning\r
- * with <code>{</code> <small>(left brace)</small> and ending\r
- * with <code>}</code> <small>(right brace)</small>.\r
- * @exception JSONException If there is a syntax error in the source\r
- * string or a duplicated key.\r
- */\r
- public LOGJSONObject(String source) throws JSONException {\r
- this(new JSONTokener(source));\r
- }\r
-\r
-\r
- /**\r
- * Construct a JSONObject from a ResourceBundle.\r
- * @param baseName The ResourceBundle base name.\r
- * @param locale The Locale to load the ResourceBundle for.\r
- * @throws JSONException If any JSONExceptions are detected.\r
- */\r
- public LOGJSONObject(String baseName, Locale locale) throws JSONException {\r
- this();\r
- ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,\r
- Thread.currentThread().getContextClassLoader());\r
-\r
-// Iterate through the keys in the bundle.\r
-\r
- Enumeration<?> keys = bundle.getKeys();\r
- while (keys.hasMoreElements()) {\r
- Object key = keys.nextElement();\r
- if (key instanceof String) {\r
-\r
-// Go through the path, ensuring that there is a nested JSONObject for each\r
-// segment except the last. Add the value using the last segment's name into\r
-// the deepest nested JSONObject.\r
-\r
- String[] path = ((String)key).split("\\.");\r
- int last = path.length - 1;\r
- LOGJSONObject target = this;\r
- for (int i = 0; i < last; i += 1) {\r
- String segment = path[i];\r
- LOGJSONObject nextTarget = target.optJSONObject(segment);\r
- if (nextTarget == null) {\r
- nextTarget = new LOGJSONObject();\r
- target.put(segment, nextTarget);\r
- }\r
- target = nextTarget;\r
- }\r
- target.put(path[last], bundle.getString((String)key));\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Accumulate values under a key. It is similar to the put method except\r
- * that if there is already an object stored under the key then a\r
- * JSONArray is stored under the key to hold all of the accumulated values.\r
- * If there is already a JSONArray, then the new value is appended to it.\r
- * In contrast, the put method replaces the previous value.\r
- *\r
- * If only one value is accumulated that is not a JSONArray, then the\r
- * result will be the same as using put. But if multiple values are\r
- * accumulated, then the result will be like append.\r
- * @param key A key string.\r
- * @param value An object to be accumulated under the key.\r
- * @return this.\r
- * @throws JSONException If the value is an invalid number\r
- * or if the key is null.\r
- */\r
- public LOGJSONObject accumulate(\r
- String key,\r
- Object value\r
- ) throws JSONException {\r
- testValidity(value);\r
- Object object = this.opt(key);\r
- if (object == null) {\r
- this.put(key, value instanceof JSONArray\r
- ? new JSONArray().put(value)\r
- : value);\r
- } else if (object instanceof JSONArray) {\r
- ((JSONArray)object).put(value);\r
- } else {\r
- this.put(key, new JSONArray().put(object).put(value));\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Append values to the array under a key. If the key does not exist in the\r
- * JSONObject, then the key is put in the JSONObject with its value being a\r
- * JSONArray containing the value parameter. If the key was already\r
- * associated with a JSONArray, then the value parameter is appended to it.\r
- * @param key A key string.\r
- * @param value An object to be accumulated under the key.\r
- * @return this.\r
- * @throws JSONException If the key is null or if the current value\r
- * associated with the key is not a JSONArray.\r
- */\r
- public LOGJSONObject append(String key, Object value) throws JSONException {\r
- testValidity(value);\r
- Object object = this.opt(key);\r
- if (object == null) {\r
- this.put(key, new JSONArray().put(value));\r
- } else if (object instanceof JSONArray) {\r
- this.put(key, ((JSONArray)object).put(value));\r
- } else {\r
- throw new JSONException("JSONObject[" + key +\r
- "] is not a JSONArray.");\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Produce a string from a double. The string "null" will be returned if\r
- * the number is not finite.\r
- * @param d A double.\r
- * @return A String.\r
- */\r
- public static String doubleToString(double d) {\r
- if (Double.isInfinite(d) || Double.isNaN(d)) {\r
- return "null";\r
- }\r
-\r
-// Shave off trailing zeros and decimal point, if possible.\r
-\r
- String string = Double.toString(d);\r
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&\r
- string.indexOf('E') < 0) {\r
- while (string.endsWith("0")) {\r
- string = string.substring(0, string.length() - 1);\r
- }\r
- if (string.endsWith(".")) {\r
- string = string.substring(0, string.length() - 1);\r
- }\r
- }\r
- return string;\r
- }\r
-\r
-\r
- /**\r
- * Get the value object associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return The object associated with the key.\r
- * @throws JSONException if the key is not found.\r
- */\r
- public Object get(String key) throws JSONException {\r
- if (key == null) {\r
- throw new JSONException("Null key.");\r
- }\r
- Object object = this.opt(key);\r
- if (object == null) {\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] not found.");\r
- }\r
- return object;\r
- }\r
-\r
-\r
- /**\r
- * Get the boolean value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return The truth.\r
- * @throws JSONException\r
- * if the value is not a Boolean or the String "true" or "false".\r
- */\r
- public boolean getBoolean(String key) throws JSONException {\r
- Object object = this.get(key);\r
- if (object.equals(Boolean.FALSE) ||\r
- (object instanceof String &&\r
- ((String)object).equalsIgnoreCase("false"))) {\r
- return false;\r
- } else if (object.equals(Boolean.TRUE) ||\r
- (object instanceof String &&\r
- ((String)object).equalsIgnoreCase("true"))) {\r
- return true;\r
- }\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a Boolean.");\r
- }\r
-\r
-\r
- /**\r
- * Get the double value associated with a key.\r
- * @param key A key string.\r
- * @return The numeric value.\r
- * @throws JSONException if the key is not found or\r
- * if the value is not a Number object and cannot be converted to a number.\r
- */\r
- public double getDouble(String key) throws JSONException {\r
- Object object = this.get(key);\r
- try {\r
- return object instanceof Number\r
- ? ((Number)object).doubleValue()\r
- : Double.parseDouble((String)object);\r
- } catch (Exception e) {\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a number.");\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the int value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return The integer value.\r
- * @throws JSONException if the key is not found or if the value cannot\r
- * be converted to an integer.\r
- */\r
- public int getInt(String key) throws JSONException {\r
- Object object = this.get(key);\r
- try {\r
- return object instanceof Number\r
- ? ((Number)object).intValue()\r
- : Integer.parseInt((String)object);\r
- } catch (Exception e) {\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not an int.");\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the JSONArray value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return A JSONArray which is the value.\r
- * @throws JSONException if the key is not found or\r
- * if the value is not a JSONArray.\r
- */\r
- public JSONArray getJSONArray(String key) throws JSONException {\r
- Object object = this.get(key);\r
- if (object instanceof JSONArray) {\r
- return (JSONArray)object;\r
- }\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a JSONArray.");\r
- }\r
-\r
-\r
- /**\r
- * Get the JSONObject value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return A JSONObject which is the value.\r
- * @throws JSONException if the key is not found or\r
- * if the value is not a JSONObject.\r
- */\r
- public LOGJSONObject getJSONObject(String key) throws JSONException {\r
- Object object = this.get(key);\r
- if (object instanceof LOGJSONObject) {\r
- return (LOGJSONObject)object;\r
- }\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a JSONObject.");\r
- }\r
-\r
-\r
- /**\r
- * Get the long value associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return The long value.\r
- * @throws JSONException if the key is not found or if the value cannot\r
- * be converted to a long.\r
- */\r
- public long getLong(String key) throws JSONException {\r
- Object object = this.get(key);\r
- try {\r
- return object instanceof Number\r
- ? ((Number)object).longValue()\r
- : Long.parseLong((String)object);\r
- } catch (Exception e) {\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] is not a long.");\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an array of field names from a JSONObject.\r
- *\r
- * @return An array of field names, or null if there are no names.\r
- */\r
- public static String[] getNames(LOGJSONObject jo) {\r
- int length = jo.length();\r
- if (length == 0) {\r
- return null;\r
- }\r
- Iterator<String> iterator = jo.keys();\r
- String[] names = new String[length];\r
- int i = 0;\r
- while (iterator.hasNext()) {\r
- names[i] = iterator.next();\r
- i += 1;\r
- }\r
- return names;\r
- }\r
-\r
-\r
- /**\r
- * Get an array of field names from an Object.\r
- *\r
- * @return An array of field names, or null if there are no names.\r
- */\r
- public static String[] getNames(Object object) {\r
- if (object == null) {\r
- return null;\r
- }\r
- Class<? extends Object> klass = object.getClass();\r
- Field[] fields = klass.getFields();\r
- int length = fields.length;\r
- if (length == 0) {\r
- return null;\r
- }\r
- String[] names = new String[length];\r
- for (int i = 0; i < length; i += 1) {\r
- names[i] = fields[i].getName();\r
- }\r
- return names;\r
- }\r
-\r
-\r
- /**\r
- * Get the string associated with a key.\r
- *\r
- * @param key A key string.\r
- * @return A string which is the value.\r
- * @throws JSONException if there is no string value for the key.\r
- */\r
- public String getString(String key) throws JSONException {\r
- Object object = this.get(key);\r
- if (object instanceof String) {\r
- return (String)object;\r
- }\r
- throw new JSONException("JSONObject[" + quote(key) +\r
- "] not a string.");\r
- }\r
-\r
-\r
- /**\r
- * Determine if the JSONObject contains a specific key.\r
- * @param key A key string.\r
- * @return true if the key exists in the JSONObject.\r
- */\r
- public boolean has(String key) {\r
- return this.map.containsKey(key);\r
- }\r
-\r
-\r
- /**\r
- * Increment a property of a JSONObject. If there is no such property,\r
- * create one with a value of 1. If there is such a property, and if\r
- * it is an Integer, Long, Double, or Float, then add one to it.\r
- * @param key A key string.\r
- * @return this.\r
- * @throws JSONException If there is already a property with this name\r
- * that is not an Integer, Long, Double, or Float.\r
- */\r
- public LOGJSONObject increment(String key) throws JSONException {\r
- Object value = this.opt(key);\r
- if (value == null) {\r
- this.put(key, 1);\r
- } else if (value instanceof Integer) {\r
- this.put(key, ((Integer)value).intValue() + 1);\r
- } else if (value instanceof Long) {\r
- this.put(key, ((Long)value).longValue() + 1);\r
- } else if (value instanceof Double) {\r
- this.put(key, ((Double)value).doubleValue() + 1);\r
- } else if (value instanceof Float) {\r
- this.put(key, ((Float)value).floatValue() + 1);\r
- } else {\r
- throw new JSONException("Unable to increment [" + quote(key) + "].");\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Determine if the value associated with the key is null or if there is\r
- * no value.\r
- * @param key A key string.\r
- * @return true if there is no value associated with the key or if\r
- * the value is the JSONObject.NULL object.\r
- */\r
- public boolean isNull(String key) {\r
- return LOGJSONObject.NULL.equals(this.opt(key));\r
- }\r
-\r
-\r
- /**\r
- * Get an enumeration of the keys of the JSONObject.\r
- *\r
- * @return An iterator of the keys.\r
- */\r
- public Iterator<String> keys() {\r
- return this.keySet().iterator();\r
- }\r
-\r
-\r
- /**\r
- * Get a set of keys of the JSONObject.\r
- *\r
- * @return A keySet.\r
- */\r
- public Set<String> keySet() {\r
- return this.map.keySet();\r
- }\r
-\r
-\r
- /**\r
- * Get the number of keys stored in the JSONObject.\r
- *\r
- * @return The number of keys in the JSONObject.\r
- */\r
- public int length() {\r
- return this.map.size();\r
- }\r
-\r
-\r
- /**\r
- * Produce a JSONArray containing the names of the elements of this\r
- * JSONObject.\r
- * @return A JSONArray containing the key strings, or null if the JSONObject\r
- * is empty.\r
- */\r
- public JSONArray names() {\r
- JSONArray ja = new JSONArray();\r
- Iterator<String> keys = this.keys();\r
- while (keys.hasNext()) {\r
- ja.put(keys.next());\r
- }\r
- return ja.length() == 0 ? null : ja;\r
- }\r
-\r
- /**\r
- * Produce a string from a Number.\r
- * @param number A Number\r
- * @return A String.\r
- * @throws JSONException If n is a non-finite number.\r
- */\r
- public static String numberToString(Number number)\r
- throws JSONException {\r
- if (number == null) {\r
- throw new JSONException("Null pointer");\r
- }\r
- testValidity(number);\r
-\r
-// Shave off trailing zeros and decimal point, if possible.\r
-\r
- String string = number.toString();\r
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&\r
- string.indexOf('E') < 0) {\r
- while (string.endsWith("0")) {\r
- string = string.substring(0, string.length() - 1);\r
- }\r
- if (string.endsWith(".")) {\r
- string = string.substring(0, string.length() - 1);\r
- }\r
- }\r
- return string;\r
- }\r
-\r
-\r
- /**\r
- * Get an optional value associated with a key.\r
- * @param key A key string.\r
- * @return An object which is the value, or null if there is no value.\r
- */\r
- public Object opt(String key) {\r
- return key == null ? null : this.map.get(key);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional boolean associated with a key.\r
- * It returns false if there is no such key, or if the value is not\r
- * Boolean.TRUE or the String "true".\r
- *\r
- * @param key A key string.\r
- * @return The truth.\r
- */\r
- public boolean optBoolean(String key) {\r
- return this.optBoolean(key, false);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional boolean associated with a key.\r
- * It returns the defaultValue if there is no such key, or if it is not\r
- * a Boolean or the String "true" or "false" (case insensitive).\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return The truth.\r
- */\r
- public boolean optBoolean(String key, boolean defaultValue) {\r
- try {\r
- return this.getBoolean(key);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an optional double associated with a key,\r
- * or NaN if there is no such key or if its value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A string which is the key.\r
- * @return An object which is the value.\r
- */\r
- public double optDouble(String key) {\r
- return this.optDouble(key, Double.NaN);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional double associated with a key, or the\r
- * defaultValue if there is no such key or if its value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return An object which is the value.\r
- */\r
- public double optDouble(String key, double defaultValue) {\r
- try {\r
- return this.getDouble(key);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an optional int value associated with a key,\r
- * or zero if there is no such key or if the value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @return An object which is the value.\r
- */\r
- public int optInt(String key) {\r
- return this.optInt(key, 0);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional int value associated with a key,\r
- * or the default if there is no such key or if the value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return An object which is the value.\r
- */\r
- public int optInt(String key, int defaultValue) {\r
- try {\r
- return this.getInt(key);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an optional JSONArray associated with a key.\r
- * It returns null if there is no such key, or if its value is not a\r
- * JSONArray.\r
- *\r
- * @param key A key string.\r
- * @return A JSONArray which is the value.\r
- */\r
- public JSONArray optJSONArray(String key) {\r
- Object o = this.opt(key);\r
- return o instanceof JSONArray ? (JSONArray)o : null;\r
- }\r
-\r
-\r
- /**\r
- * Get an optional JSONObject associated with a key.\r
- * It returns null if there is no such key, or if its value is not a\r
- * JSONObject.\r
- *\r
- * @param key A key string.\r
- * @return A JSONObject which is the value.\r
- */\r
- public LOGJSONObject optJSONObject(String key) {\r
- Object object = this.opt(key);\r
- return object instanceof LOGJSONObject ? (LOGJSONObject)object : null;\r
- }\r
-\r
-\r
- /**\r
- * Get an optional long value associated with a key,\r
- * or zero if there is no such key or if the value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @return An object which is the value.\r
- */\r
- public long optLong(String key) {\r
- return this.optLong(key, 0);\r
- }\r
-\r
-\r
- /**\r
- * Get an optional long value associated with a key,\r
- * or the default if there is no such key or if the value is not a number.\r
- * If the value is a string, an attempt will be made to evaluate it as\r
- * a number.\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return An object which is the value.\r
- */\r
- public long optLong(String key, long defaultValue) {\r
- try {\r
- return this.getLong(key);\r
- } catch (Exception e) {\r
- return defaultValue;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get an optional string associated with a key.\r
- * It returns an empty string if there is no such key. If the value is not\r
- * a string and is not null, then it is converted to a string.\r
- *\r
- * @param key A key string.\r
- * @return A string which is the value.\r
- */\r
- public String optString(String key) {\r
- return this.optString(key, "");\r
- }\r
-\r
-\r
- /**\r
- * Get an optional string associated with a key.\r
- * It returns the defaultValue if there is no such key.\r
- *\r
- * @param key A key string.\r
- * @param defaultValue The default.\r
- * @return A string which is the value.\r
- */\r
- public String optString(String key, String defaultValue) {\r
- Object object = this.opt(key);\r
- return NULL.equals(object) ? defaultValue : object.toString();\r
- }\r
-\r
-\r
- private void populateMap(Object bean) {\r
- Class<? extends Object> klass = bean.getClass();\r
-\r
-// If klass is a System class then set includeSuperClass to false.\r
-\r
- boolean includeSuperClass = klass.getClassLoader() != null;\r
-\r
- Method[] methods = includeSuperClass\r
- ? klass.getMethods()\r
- : klass.getDeclaredMethods();\r
- for (int i = 0; i < methods.length; i += 1) {\r
- try {\r
- Method method = methods[i];\r
- if (Modifier.isPublic(method.getModifiers())) {\r
- String name = method.getName();\r
- String key = "";\r
- if (name.startsWith("get")) {\r
- if ("getClass".equals(name) ||\r
- "getDeclaringClass".equals(name)) {\r
- key = "";\r
- } else {\r
- key = name.substring(3);\r
- }\r
- } else if (name.startsWith("is")) {\r
- key = name.substring(2);\r
- }\r
- if (key.length() > 0 &&\r
- Character.isUpperCase(key.charAt(0)) &&\r
- method.getParameterTypes().length == 0) {\r
- if (key.length() == 1) {\r
- key = key.toLowerCase();\r
- } else if (!Character.isUpperCase(key.charAt(1))) {\r
- key = key.substring(0, 1).toLowerCase() +\r
- key.substring(1);\r
- }\r
-\r
- Object result = method.invoke(bean, (Object[])null);\r
- if (result != null) {\r
- this.map.put(key, wrap(result));\r
- }\r
- }\r
- }\r
- } catch (Exception ignore) {\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Put a key/boolean pair in the JSONObject.\r
- *\r
- * @param key A key string.\r
- * @param value A boolean which is the value.\r
- * @return this.\r
- * @throws JSONException If the key is null.\r
- */\r
- public LOGJSONObject put(String key, boolean value) throws JSONException {\r
- this.put(key, value ? Boolean.TRUE : Boolean.FALSE);\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject, where the value will be a\r
- * JSONArray which is produced from a Collection.\r
- * @param key A key string.\r
- * @param value A Collection value.\r
- * @return this.\r
- * @throws JSONException\r
- */\r
- public LOGJSONObject put(String key, Collection<Object> value) throws JSONException {\r
- this.put(key, new JSONArray(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/double pair in the JSONObject.\r
- *\r
- * @param key A key string.\r
- * @param value A double which is the value.\r
- * @return this.\r
- * @throws JSONException If the key is null or if the number is invalid.\r
- */\r
- public LOGJSONObject put(String key, double value) throws JSONException {\r
- this.put(key, new Double(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/int pair in the JSONObject.\r
- *\r
- * @param key A key string.\r
- * @param value An int which is the value.\r
- * @return this.\r
- * @throws JSONException If the key is null.\r
- */\r
- public LOGJSONObject put(String key, int value) throws JSONException {\r
- this.put(key, new Integer(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/long pair in the JSONObject.\r
- *\r
- * @param key A key string.\r
- * @param value A long which is the value.\r
- * @return this.\r
- * @throws JSONException If the key is null.\r
- */\r
- public LOGJSONObject put(String key, long value) throws JSONException {\r
- this.put(key, new Long(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject, where the value will be a\r
- * JSONObject which is produced from a Map.\r
- * @param key A key string.\r
- * @param value A Map value.\r
- * @return this.\r
- * @throws JSONException\r
- */\r
- public LOGJSONObject put(String key, Map<String, Object> value) throws JSONException {\r
- this.put(key, new LOGJSONObject(value));\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject. If the value is null,\r
- * then the key will be removed from the JSONObject if it is present.\r
- * @param key A key string.\r
- * @param value An object which is the value. It should be of one of these\r
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,\r
- * or the JSONObject.NULL object.\r
- * @return this.\r
- * @throws JSONException If the value is non-finite number\r
- * or if the key is null.\r
- */\r
- public LOGJSONObject put(String key, Object value) throws JSONException {\r
- String pooled;\r
- if (key == null) {\r
- throw new JSONException("Null key.");\r
- }\r
- if (value != null) {\r
- testValidity(value);\r
- pooled = (String)keyPool.get(key);\r
- if (pooled == null) {\r
- if (keyPool.size() >= keyPoolSize) {\r
- keyPool = new LinkedHashMap<String, Object>(keyPoolSize);\r
- }\r
- keyPool.put(key, key);\r
- } else {\r
- key = pooled;\r
- }\r
- this.map.put(key, value);\r
- } else {\r
- this.remove(key);\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject, but only if the key and the\r
- * value are both non-null, and only if there is not already a member\r
- * with that name.\r
- * @param key\r
- * @param value\r
- * @return his.\r
- * @throws JSONException if the key is a duplicate\r
- */\r
- public LOGJSONObject putOnce(String key, Object value) throws JSONException {\r
- if (key != null && value != null) {\r
- if (this.opt(key) != null) {\r
- throw new JSONException("Duplicate key \"" + key + "\"");\r
- }\r
- this.put(key, value);\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Put a key/value pair in the JSONObject, but only if the\r
- * key and the value are both non-null.\r
- * @param key A key string.\r
- * @param value An object which is the value. It should be of one of these\r
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,\r
- * or the JSONObject.NULL object.\r
- * @return this.\r
- * @throws JSONException If the value is a non-finite number.\r
- */\r
- public LOGJSONObject putOpt(String key, Object value) throws JSONException {\r
- if (key != null && value != null) {\r
- this.put(key, value);\r
- }\r
- return this;\r
- }\r
-\r
-\r
- /**\r
- * Produce a string in double quotes with backslash sequences in all the\r
- * right places. A backslash will be inserted within </, producing <\/,\r
- * allowing JSON text to be delivered in HTML. In JSON text, a string\r
- * cannot contain a control character or an unescaped quote or backslash.\r
- * @param string A String\r
- * @return A String correctly formatted for insertion in a JSON text.\r
- */\r
- public static String quote(String string) {\r
- StringWriter sw = new StringWriter();\r
- synchronized (sw.getBuffer()) {\r
- try {\r
- return quote(string, sw).toString();\r
- } catch (IOException ignored) {\r
- // will never happen - we are writing to a string writer\r
- return "";\r
- }\r
- }\r
- }\r
-\r
- public static Writer quote(String string, Writer w) throws IOException {\r
- if (string == null || string.length() == 0) {\r
- w.write("\"\"");\r
- return w;\r
- }\r
-\r
- char b;\r
- char c = 0;\r
- String hhhh;\r
- int i;\r
- int len = string.length();\r
-\r
- w.write('"');\r
- for (i = 0; i < len; i += 1) {\r
- b = c;\r
- c = string.charAt(i);\r
- switch (c) {\r
- case '\\':\r
- case '"':\r
- w.write('\\');\r
- w.write(c);\r
- break;\r
- case '/':\r
- if (b == '<') {\r
- w.write('\\');\r
- }\r
- w.write(c);\r
- break;\r
- case '\b':\r
- w.write("\\b");\r
- break;\r
- case '\t':\r
- w.write("\\t");\r
- break;\r
- case '\n':\r
- w.write("\\n");\r
- break;\r
- case '\f':\r
- w.write("\\f");\r
- break;\r
- case '\r':\r
- w.write("\\r");\r
- break;\r
- default:\r
- if (c < ' ' || (c >= '\u0080' && c < '\u00a0')\r
- || (c >= '\u2000' && c < '\u2100')) {\r
- w.write("\\u");\r
- hhhh = Integer.toHexString(c);\r
- w.write("0000", 0, 4 - hhhh.length());\r
- w.write(hhhh);\r
- } else {\r
- w.write(c);\r
- }\r
- }\r
- }\r
- w.write('"');\r
- return w;\r
- }\r
-\r
- /**\r
- * Remove a name and its value, if present.\r
- * @param key The name to be removed.\r
- * @return The value that was associated with the name,\r
- * or null if there was no value.\r
- */\r
- public Object remove(String key) {\r
- return this.map.remove(key);\r
- }\r
-\r
- /**\r
- * Try to convert a string into a number, boolean, or null. If the string\r
- * can't be converted, return the string.\r
- * @param string A String.\r
- * @return A simple JSON value.\r
- */\r
- public static Object stringToValue(String string) {\r
- Double d;\r
- if (string.equals("")) {\r
- return string;\r
- }\r
- if (string.equalsIgnoreCase("true")) {\r
- return Boolean.TRUE;\r
- }\r
- if (string.equalsIgnoreCase("false")) {\r
- return Boolean.FALSE;\r
- }\r
- if (string.equalsIgnoreCase("null")) {\r
- return LOGJSONObject.NULL;\r
- }\r
-\r
- /*\r
- * If it might be a number, try converting it.\r
- * If a number cannot be produced, then the value will just\r
- * be a string. Note that the plus and implied string\r
- * conventions are non-standard. A JSON parser may accept\r
- * non-JSON forms as long as it accepts all correct JSON forms.\r
- */\r
-\r
- char b = string.charAt(0);\r
- if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {\r
- try {\r
- if (string.indexOf('.') > -1 ||\r
- string.indexOf('e') > -1 || string.indexOf('E') > -1) {\r
- d = Double.valueOf(string);\r
- if (!d.isInfinite() && !d.isNaN()) {\r
- return d;\r
- }\r
- } else {\r
- Long myLong = new Long(string);\r
- if (myLong.longValue() == myLong.intValue()) {\r
- return new Integer(myLong.intValue());\r
- } else {\r
- return myLong;\r
- }\r
- }\r
- } catch (Exception ignore) {\r
- }\r
- }\r
- return string;\r
- }\r
-\r
-\r
- /**\r
- * Throw an exception if the object is a NaN or infinite number.\r
- * @param o The object to test.\r
- * @throws JSONException If o is a non-finite number.\r
- */\r
- public static void testValidity(Object o) throws JSONException {\r
- if (o != null) {\r
- if (o instanceof Double) {\r
- if (((Double)o).isInfinite() || ((Double)o).isNaN()) {\r
- throw new JSONException(\r
- "JSON does not allow non-finite numbers.");\r
- }\r
- } else if (o instanceof Float) {\r
- if (((Float)o).isInfinite() || ((Float)o).isNaN()) {\r
- throw new JSONException(\r
- "JSON does not allow non-finite numbers.");\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Produce a JSONArray containing the values of the members of this\r
- * JSONObject.\r
- * @param names A JSONArray containing a list of key strings. This\r
- * determines the sequence of the values in the result.\r
- * @return A JSONArray of values.\r
- * @throws JSONException If any of the values are non-finite numbers.\r
- */\r
- public JSONArray toJSONArray(JSONArray names) throws JSONException {\r
- if (names == null || names.length() == 0) {\r
- return null;\r
- }\r
- JSONArray ja = new JSONArray();\r
- for (int i = 0; i < names.length(); i += 1) {\r
- ja.put(this.opt(names.getString(i)));\r
- }\r
- return ja;\r
- }\r
-\r
- /**\r
- * Make a JSON text of this JSONObject. For compactness, no whitespace\r
- * is added. If this would not result in a syntactically correct JSON text,\r
- * then null will be returned instead.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- *\r
- * @return a printable, displayable, portable, transmittable\r
- * representation of the object, beginning\r
- * with <code>{</code> <small>(left brace)</small> and ending\r
- * with <code>}</code> <small>(right brace)</small>.\r
- */\r
- public String toString() {\r
- try {\r
- return this.toString(0);\r
- } catch (Exception e) {\r
- return null;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Make a prettyprinted JSON text of this JSONObject.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- * @param indentFactor The number of spaces to add to each level of\r
- * indentation.\r
- * @return a printable, displayable, portable, transmittable\r
- * representation of the object, beginning\r
- * with <code>{</code> <small>(left brace)</small> and ending\r
- * with <code>}</code> <small>(right brace)</small>.\r
- * @throws JSONException If the object contains an invalid number.\r
- */\r
- public String toString(int indentFactor) throws JSONException {\r
- StringWriter w = new StringWriter();\r
- synchronized (w.getBuffer()) {\r
- return this.write(w, indentFactor, 0).toString();\r
- }\r
- }\r
-\r
- /**\r
- * Make a JSON text of an Object value. If the object has an\r
- * value.toJSONString() method, then that method will be used to produce\r
- * the JSON text. The method is required to produce a strictly\r
- * conforming text. If the object does not contain a toJSONString\r
- * method (which is the most common case), then a text will be\r
- * produced by other means. If the value is an array or Collection,\r
- * then a JSONArray will be made from it and its toJSONString method\r
- * will be called. If the value is a MAP, then a JSONObject will be made\r
- * from it and its toJSONString method will be called. Otherwise, the\r
- * value's toString method will be called, and the result will be quoted.\r
- *\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- * @param value The value to be serialized.\r
- * @return a printable, displayable, transmittable\r
- * representation of the object, beginning\r
- * with <code>{</code> <small>(left brace)</small> and ending\r
- * with <code>}</code> <small>(right brace)</small>.\r
- * @throws JSONException If the value is or contains an invalid number.\r
- */\r
- @SuppressWarnings("unchecked")\r
- public static String valueToString(Object value) throws JSONException {\r
- if (value == null || value.equals(null)) {\r
- return "null";\r
- }\r
- if (value instanceof JSONString) {\r
- Object object;\r
- try {\r
- object = ((JSONString)value).toJSONString();\r
- } catch (Exception e) {\r
- throw new JSONException(e);\r
- }\r
- if (object instanceof String) {\r
- return (String)object;\r
- }\r
- throw new JSONException("Bad value from toJSONString: " + object);\r
- }\r
- if (value instanceof Number) {\r
- return numberToString((Number) value);\r
- }\r
- if (value instanceof Boolean || value instanceof LOGJSONObject ||\r
- value instanceof JSONArray) {\r
- return value.toString();\r
- }\r
- if (value instanceof Map) {\r
- return new LOGJSONObject((Map<String, Object>)value).toString();\r
- }\r
- if (value instanceof Collection) {\r
- return new JSONArray((Collection<Object>)value).toString();\r
- }\r
- if (value.getClass().isArray()) {\r
- return new JSONArray(value).toString();\r
- }\r
- return quote(value.toString());\r
- }\r
-\r
- /**\r
- * Wrap an object, if necessary. If the object is null, return the NULL\r
- * object. If it is an array or collection, wrap it in a JSONArray. If\r
- * it is a map, wrap it in a JSONObject. If it is a standard property\r
- * (Double, String, et al) then it is already wrapped. Otherwise, if it\r
- * comes from one of the java packages, turn it into a string. And if\r
- * it doesn't, try to wrap it in a JSONObject. If the wrapping fails,\r
- * then null is returned.\r
- *\r
- * @param object The object to wrap\r
- * @return The wrapped value\r
- */\r
- @SuppressWarnings("unchecked")\r
- public static Object wrap(Object object) {\r
- try {\r
- if (object == null) {\r
- return NULL;\r
- }\r
- if (object instanceof LOGJSONObject || object instanceof JSONArray ||\r
- NULL.equals(object) || object instanceof JSONString ||\r
- object instanceof Byte || object instanceof Character ||\r
- object instanceof Short || object instanceof Integer ||\r
- object instanceof Long || object instanceof Boolean ||\r
- object instanceof Float || object instanceof Double ||\r
- object instanceof String) {\r
- return object;\r
- }\r
-\r
- if (object instanceof Collection) {\r
- return new JSONArray((Collection<Object>)object);\r
- }\r
- if (object.getClass().isArray()) {\r
- return new JSONArray(object);\r
- }\r
- if (object instanceof Map) {\r
- return new LOGJSONObject((Map<String, Object>)object);\r
- }\r
- Package objectPackage = object.getClass().getPackage();\r
- String objectPackageName = objectPackage != null\r
- ? objectPackage.getName()\r
- : "";\r
- if (\r
- objectPackageName.startsWith("java.") ||\r
- objectPackageName.startsWith("javax.") ||\r
- object.getClass().getClassLoader() == null\r
- ) {\r
- return object.toString();\r
- }\r
- return new LOGJSONObject(object);\r
- } catch(Exception exception) {\r
- return null;\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Write the contents of the JSONObject as JSON text to a writer.\r
- * For compactness, no whitespace is added.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- *\r
- * @return The writer.\r
- * @throws JSONException\r
- */\r
- public Writer write(Writer writer) throws JSONException {\r
- return this.write(writer, 0, 0);\r
- }\r
-\r
-\r
- @SuppressWarnings("unchecked")\r
- static final Writer writeValue(Writer writer, Object value,\r
- int indentFactor, int indent) throws JSONException, IOException {\r
- if (value == null || value.equals(null)) {\r
- writer.write("null");\r
- } else if (value instanceof LOGJSONObject) {\r
- ((LOGJSONObject) value).write(writer, indentFactor, indent);\r
- } else if (value instanceof JSONArray) {\r
- ((JSONArray) value).write(writer, indentFactor, indent);\r
- } else if (value instanceof Map) {\r
- new LOGJSONObject((Map<String, Object>) value).write(writer, indentFactor, indent);\r
- } else if (value instanceof Collection) {\r
- new JSONArray((Collection<Object>) value).write(writer, indentFactor,\r
- indent);\r
- } else if (value.getClass().isArray()) {\r
- new JSONArray(value).write(writer, indentFactor, indent);\r
- } else if (value instanceof Number) {\r
- writer.write(numberToString((Number) value));\r
- } else if (value instanceof Boolean) {\r
- writer.write(value.toString());\r
- } else if (value instanceof JSONString) {\r
- Object o;\r
- try {\r
- o = ((JSONString) value).toJSONString();\r
- } catch (Exception e) {\r
- throw new JSONException(e);\r
- }\r
- writer.write(o != null ? o.toString() : quote(value.toString()));\r
- } else {\r
- quote(value.toString(), writer);\r
- }\r
- return writer;\r
- }\r
-\r
- static final void indent(Writer writer, int indent) throws IOException {\r
- for (int i = 0; i < indent; i += 1) {\r
- writer.write(' ');\r
- }\r
- }\r
-\r
- /**\r
- * Write the contents of the JSONObject as JSON text to a writer. For\r
- * compactness, no whitespace is added.\r
- * <p>\r
- * Warning: This method assumes that the data structure is acyclical.\r
- *\r
- * @return The writer.\r
- * @throws JSONException\r
- */\r
- Writer write(Writer writer, int indentFactor, int indent)\r
- throws JSONException {\r
- try {\r
- boolean commanate = false;\r
- final int length = this.length();\r
- Iterator<String> keys = this.keys();\r
- writer.write('{');\r
-\r
- if (length == 1) {\r
- Object key = keys.next();\r
- writer.write(quote(key.toString()));\r
- writer.write(':');\r
- if (indentFactor > 0) {\r
- writer.write(' ');\r
- }\r
- writeValue(writer, this.map.get(key), indentFactor, indent);\r
- } else if (length != 0) {\r
- final int newindent = indent + indentFactor;\r
- while (keys.hasNext()) {\r
- Object key = keys.next();\r
- if (commanate) {\r
- writer.write(',');\r
- }\r
- if (indentFactor > 0) {\r
- writer.write('\n');\r
- }\r
- indent(writer, newindent);\r
- writer.write(quote(key.toString()));\r
- writer.write(':');\r
- if (indentFactor > 0) {\r
- writer.write(' ');\r
- }\r
- writeValue(writer, this.map.get(key), indentFactor,\r
- newindent);\r
- commanate = true;\r
- }\r
- if (indentFactor > 0) {\r
- writer.write('\n');\r
- }\r
- indent(writer, indent);\r
- }\r
- writer.write('}');\r
- return writer;\r
- } catch (IOException exception) {\r
- throw new JSONException(exception);\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-public interface None {\r
- /**\r
- * Negative One\r
- */\r
- public static final int none = -1;\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-import java.util.Iterator;\r
-\r
-\r
-/**\r
- * This provides static methods to convert an XML text into a JSONObject,\r
- * and to covert a JSONObject into an XML text.\r
- * @author JSON.org\r
- * @version 2012-10-26\r
- */\r
-public class XML {\r
-\r
- /** The Character '&'. */\r
- public static final Character AMP = new Character('&');\r
-\r
- /** The Character '''. */\r
- public static final Character APOS = new Character('\'');\r
-\r
- /** The Character '!'. */\r
- public static final Character BANG = new Character('!');\r
-\r
- /** The Character '='. */\r
- public static final Character EQ = new Character('=');\r
-\r
- /** The Character '>'. */\r
- public static final Character GT = new Character('>');\r
-\r
- /** The Character '<'. */\r
- public static final Character LT = new Character('<');\r
-\r
- /** The Character '?'. */\r
- public static final Character QUEST = new Character('?');\r
-\r
- /** The Character '"'. */\r
- public static final Character QUOT = new Character('"');\r
-\r
- /** The Character '/'. */\r
- public static final Character SLASH = new Character('/');\r
-\r
- /**\r
- * Replace special characters with XML escapes:\r
- * <pre>\r
- * & <small>(ampersand)</small> is replaced by &amp;\r
- * < <small>(less than)</small> is replaced by &lt;\r
- * > <small>(greater than)</small> is replaced by &gt;\r
- * " <small>(double quote)</small> is replaced by &quot;\r
- * </pre>\r
- * @param string The string to be escaped.\r
- * @return The escaped string.\r
- */\r
- public static String escape(String string) {\r
- StringBuffer sb = new StringBuffer();\r
- for (int i = 0, length = string.length(); i < length; i++) {\r
- char c = string.charAt(i);\r
- switch (c) {\r
- case '&':\r
- sb.append("&");\r
- break;\r
- case '<':\r
- sb.append("<");\r
- break;\r
- case '>':\r
- sb.append(">");\r
- break;\r
- case '"':\r
- sb.append(""");\r
- break;\r
- case '\'':\r
- sb.append("'");\r
- break;\r
- default:\r
- sb.append(c);\r
- }\r
- }\r
- return sb.toString();\r
- }\r
-\r
- /**\r
- * Throw an exception if the string contains whitespace.\r
- * Whitespace is not allowed in tagNames and attributes.\r
- * @param string\r
- * @throws JSONException\r
- */\r
- public static void noSpace(String string) throws JSONException {\r
- int i, length = string.length();\r
- if (length == 0) {\r
- throw new JSONException("Empty string.");\r
- }\r
- for (i = 0; i < length; i += 1) {\r
- if (Character.isWhitespace(string.charAt(i))) {\r
- throw new JSONException("'" + string +\r
- "' contains a space character.");\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Scan the content following the named tag, attaching it to the context.\r
- * @param x The XMLTokener containing the source string.\r
- * @param context The JSONObject that will include the new material.\r
- * @param name The tag name.\r
- * @return true if the close tag is processed.\r
- * @throws JSONException\r
- */\r
- private static boolean parse(XMLTokener x, JSONObject context,\r
- String name) throws JSONException {\r
- char c;\r
- int i;\r
- JSONObject jsonobject = null;\r
- String string;\r
- String tagName;\r
- Object token;\r
-\r
-// Test for and skip past these forms:\r
-// <!-- ... -->\r
-// <! ... >\r
-// <![ ... ]]>\r
-// <? ... ?>\r
-// Report errors for these forms:\r
-// <>\r
-// <=\r
-// <<\r
-\r
- token = x.nextToken();\r
-\r
-// <!\r
-\r
- if (token == BANG) {\r
- c = x.next();\r
- if (c == '-') {\r
- if (x.next() == '-') {\r
- x.skipPast("-->");\r
- return false;\r
- }\r
- x.back();\r
- } else if (c == '[') {\r
- token = x.nextToken();\r
- if ("CDATA".equals(token)) {\r
- if (x.next() == '[') {\r
- string = x.nextCDATA();\r
- if (string.length() > 0) {\r
- context.accumulate("content", string);\r
- }\r
- return false;\r
- }\r
- }\r
- throw x.syntaxError("Expected 'CDATA['");\r
- }\r
- i = 1;\r
- do {\r
- token = x.nextMeta();\r
- if (token == null) {\r
- throw x.syntaxError("Missing '>' after '<!'.");\r
- } else if (token == LT) {\r
- i += 1;\r
- } else if (token == GT) {\r
- i -= 1;\r
- }\r
- } while (i > 0);\r
- return false;\r
- } else if (token == QUEST) {\r
-\r
-// <?\r
-\r
- x.skipPast("?>");\r
- return false;\r
- } else if (token == SLASH) {\r
-\r
-// Close tag </\r
-\r
- token = x.nextToken();\r
- if (name == null) {\r
- throw x.syntaxError("Mismatched close tag " + token);\r
- }\r
- if (!token.equals(name)) {\r
- throw x.syntaxError("Mismatched " + name + " and " + token);\r
- }\r
- if (x.nextToken() != GT) {\r
- throw x.syntaxError("Misshaped close tag");\r
- }\r
- return true;\r
-\r
- } else if (token instanceof Character) {\r
- throw x.syntaxError("Misshaped tag");\r
-\r
-// Open tag <\r
-\r
- } else {\r
- tagName = (String)token;\r
- token = null;\r
- jsonobject = new JSONObject();\r
- for (;;) {\r
- if (token == null) {\r
- token = x.nextToken();\r
- }\r
-\r
-// attribute = value\r
-\r
- if (token instanceof String) {\r
- string = (String)token;\r
- token = x.nextToken();\r
- if (token == EQ) {\r
- token = x.nextToken();\r
- if (!(token instanceof String)) {\r
- throw x.syntaxError("Missing value");\r
- }\r
- jsonobject.accumulate(string,\r
- XML.stringToValue((String)token));\r
- token = null;\r
- } else {\r
- jsonobject.accumulate(string, "");\r
- }\r
-\r
-// Empty tag <.../>\r
-\r
- } else if (token == SLASH) {\r
- if (x.nextToken() != GT) {\r
- throw x.syntaxError("Misshaped tag");\r
- }\r
- if (jsonobject.length() > 0) {\r
- context.accumulate(tagName, jsonobject);\r
- } else {\r
- context.accumulate(tagName, "");\r
- }\r
- return false;\r
-\r
-// Content, between <...> and </...>\r
-\r
- } else if (token == GT) {\r
- for (;;) {\r
- token = x.nextContent();\r
- if (token == null) {\r
- if (tagName != null) {\r
- throw x.syntaxError("Unclosed tag " + tagName);\r
- }\r
- return false;\r
- } else if (token instanceof String) {\r
- string = (String)token;\r
- if (string.length() > 0) {\r
- jsonobject.accumulate("content",\r
- XML.stringToValue(string));\r
- }\r
-\r
-// Nested element\r
-\r
- } else if (token == LT) {\r
- if (parse(x, jsonobject, tagName)) {\r
- if (jsonobject.length() == 0) {\r
- context.accumulate(tagName, "");\r
- } else if (jsonobject.length() == 1 &&\r
- jsonobject.opt("content") != null) {\r
- context.accumulate(tagName,\r
- jsonobject.opt("content"));\r
- } else {\r
- context.accumulate(tagName, jsonobject);\r
- }\r
- return false;\r
- }\r
- }\r
- }\r
- } else {\r
- throw x.syntaxError("Misshaped tag");\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Try to convert a string into a number, boolean, or null. If the string\r
- * can't be converted, return the string. This is much less ambitious than\r
- * JSONObject.stringToValue, especially because it does not attempt to\r
- * convert plus forms, octal forms, hex forms, or E forms lacking decimal\r
- * points.\r
- * @param string A String.\r
- * @return A simple JSON value.\r
- */\r
- public static Object stringToValue(String string) {\r
- if ("".equals(string)) {\r
- return string;\r
- }\r
- if ("true".equalsIgnoreCase(string)) {\r
- return Boolean.TRUE;\r
- }\r
- if ("false".equalsIgnoreCase(string)) {\r
- return Boolean.FALSE;\r
- }\r
- if ("null".equalsIgnoreCase(string)) {\r
- return JSONObject.NULL;\r
- }\r
- if ("0".equals(string)) {\r
- return new Integer(0);\r
- }\r
-\r
-// If it might be a number, try converting it. If that doesn't work,\r
-// return the string.\r
-\r
- try {\r
- char initial = string.charAt(0);\r
- boolean negative = false;\r
- if (initial == '-') {\r
- initial = string.charAt(1);\r
- negative = true;\r
- }\r
- if (initial == '0' && string.charAt(negative ? 2 : 1) == '0') {\r
- return string;\r
- }\r
- if ((initial >= '0' && initial <= '9')) {\r
- if (string.indexOf('.') >= 0) {\r
- return Double.valueOf(string);\r
- } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) {\r
- Long myLong = new Long(string);\r
- if (myLong.longValue() == myLong.intValue()) {\r
- return new Integer(myLong.intValue());\r
- } else {\r
- return myLong;\r
- }\r
- }\r
- }\r
- } catch (Exception ignore) {\r
- }\r
- return string;\r
- }\r
-\r
-\r
- /**\r
- * Convert a well-formed (but not necessarily valid) XML string into a\r
- * JSONObject. Some information may be lost in this transformation\r
- * because JSON is a data format and XML is a document format. XML uses\r
- * elements, attributes, and content text, while JSON uses unordered\r
- * collections of name/value pairs and arrays of values. JSON does not\r
- * does not like to distinguish between elements and attributes.\r
- * Sequences of similar elements are represented as JSONArrays. Content\r
- * text may be placed in a "content" member. Comments, prologs, DTDs, and\r
- * <code><[ [ ]]></code> are ignored.\r
- * @param string The source string.\r
- * @return A JSONObject containing the structured data from the XML string.\r
- * @throws JSONException\r
- */\r
- public static JSONObject toJSONObject(String string) throws JSONException {\r
- JSONObject jo = new JSONObject();\r
- XMLTokener x = new XMLTokener(string);\r
- while (x.more() && x.skipPast("<")) {\r
- parse(x, jo, null);\r
- }\r
- return jo;\r
- }\r
-\r
-\r
- /**\r
- * Convert a JSONObject into a well-formed, element-normal XML string.\r
- * @param object A JSONObject.\r
- * @return A string.\r
- * @throws JSONException\r
- */\r
- public static String toString(Object object) throws JSONException {\r
- return toString(object, null);\r
- }\r
-\r
-\r
- /**\r
- * Convert a JSONObject into a well-formed, element-normal XML string.\r
- * @param object A JSONObject.\r
- * @param tagName The optional name of the enclosing tag.\r
- * @return A string.\r
- * @throws JSONException\r
- */\r
- public static String toString(Object object, String tagName)\r
- throws JSONException {\r
- StringBuffer sb = new StringBuffer();\r
- int i;\r
- JSONArray ja;\r
- JSONObject jo;\r
- String key;\r
- Iterator<String> keys;\r
- int length;\r
- String string;\r
- Object value;\r
- if (object instanceof JSONObject) {\r
-\r
-// Emit <tagName>\r
-\r
- if (tagName != null) {\r
- sb.append('<');\r
- sb.append(tagName);\r
- sb.append('>');\r
- }\r
-\r
-// Loop thru the keys.\r
-\r
- jo = (JSONObject)object;\r
- keys = jo.keys();\r
- while (keys.hasNext()) {\r
- key = keys.next().toString();\r
- value = jo.opt(key);\r
- if (value == null) {\r
- value = "";\r
- }\r
- if (value instanceof String) {\r
- string = (String)value;\r
- } else {\r
- string = null;\r
- }\r
-\r
-// Emit content in body\r
-\r
- if ("content".equals(key)) {\r
- if (value instanceof JSONArray) {\r
- ja = (JSONArray)value;\r
- length = ja.length();\r
- for (i = 0; i < length; i += 1) {\r
- if (i > 0) {\r
- sb.append('\n');\r
- }\r
- sb.append(escape(ja.get(i).toString()));\r
- }\r
- } else {\r
- sb.append(escape(value.toString()));\r
- }\r
-\r
-// Emit an array of similar keys\r
-\r
- } else if (value instanceof JSONArray) {\r
- ja = (JSONArray)value;\r
- length = ja.length();\r
- for (i = 0; i < length; i += 1) {\r
- value = ja.get(i);\r
- if (value instanceof JSONArray) {\r
- sb.append('<');\r
- sb.append(key);\r
- sb.append('>');\r
- sb.append(toString(value));\r
- sb.append("</");\r
- sb.append(key);\r
- sb.append('>');\r
- } else {\r
- sb.append(toString(value, key));\r
- }\r
- }\r
- } else if ("".equals(value)) {\r
- sb.append('<');\r
- sb.append(key);\r
- sb.append("/>");\r
-\r
-// Emit a new tag <k>\r
-\r
- } else {\r
- sb.append(toString(value, key));\r
- }\r
- }\r
- if (tagName != null) {\r
-\r
-// Emit the </tagname> close tag\r
-\r
- sb.append("</");\r
- sb.append(tagName);\r
- sb.append('>');\r
- }\r
- return sb.toString();\r
-\r
-// XML does not have good support for arrays. If an array appears in a place\r
-// where XML is lacking, synthesize an <array> element.\r
-\r
- } else {\r
- if (object.getClass().isArray()) {\r
- object = new JSONArray(object);\r
- }\r
- if (object instanceof JSONArray) {\r
- ja = (JSONArray)object;\r
- length = ja.length();\r
- for (i = 0; i < length; i += 1) {\r
- sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));\r
- }\r
- return sb.toString();\r
- } else {\r
- string = (object == null) ? "null" : escape(object.toString());\r
- return (tagName == null) ? "\"" + string + "\"" :\r
- (string.length() == 0) ? "<" + tagName + "/>" :\r
- "<" + tagName + ">" + string + "</" + tagName + ">";\r
- }\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.json;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-/*\r
-Copyright (c) 2002 JSON.org\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a copy\r
-of this software and associated documentation files (the "Software"), to deal\r
-in the Software without restriction, including without limitation the rights\r
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-copies of the Software, and to permit persons to whom the Software is\r
-furnished to do so, subject to the following conditions:\r
-\r
-The above copyright notice and this permission notice shall be included in all\r
-copies or substantial portions of the Software.\r
-\r
-The Software shall be used for Good, not Evil.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
-SOFTWARE.\r
-*/\r
-\r
-/**\r
- * The XMLTokener extends the JSONTokener to provide additional methods\r
- * for the parsing of XML texts.\r
- * @author JSON.org\r
- * @version 2012-11-13\r
- */\r
-public class XMLTokener extends JSONTokener {\r
-\r
-\r
- /** The table of entity values. It initially contains Character values for\r
- * amp, apos, gt, lt, quot.\r
- */\r
- public static final Map<String,Character> entity;\r
-\r
- static {\r
- entity = new HashMap<String,Character>(8);\r
- entity.put("amp", XML.AMP);\r
- entity.put("apos", XML.APOS);\r
- entity.put("gt", XML.GT);\r
- entity.put("lt", XML.LT);\r
- entity.put("quot", XML.QUOT);\r
- }\r
-\r
- /**\r
- * Construct an XMLTokener from a string.\r
- * @param s A source string.\r
- */\r
- public XMLTokener(String s) {\r
- super(s);\r
- }\r
-\r
- /**\r
- * Get the text in the CDATA block.\r
- * @return The string up to the <code>]]></code>.\r
- * @throws JSONException If the <code>]]></code> is not found.\r
- */\r
- public String nextCDATA() throws JSONException {\r
- char c;\r
- int i;\r
- StringBuffer sb = new StringBuffer();\r
- for (;;) {\r
- c = next();\r
- if (end()) {\r
- throw syntaxError("Unclosed CDATA");\r
- }\r
- sb.append(c);\r
- i = sb.length() - 3;\r
- if (i >= 0 && sb.charAt(i) == ']' &&\r
- sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') {\r
- sb.setLength(i);\r
- return sb.toString();\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the next XML outer token, trimming whitespace. There are two kinds\r
- * of tokens: the '<' character which begins a markup tag, and the content\r
- * text between markup tags.\r
- *\r
- * @return A string, or a '<' Character, or null if there is no more\r
- * source text.\r
- * @throws JSONException\r
- */\r
- public Object nextContent() throws JSONException {\r
- char c;\r
- StringBuffer sb;\r
- do {\r
- c = next();\r
- } while (Character.isWhitespace(c));\r
- if (c == 0) {\r
- return null;\r
- }\r
- if (c == '<') {\r
- return XML.LT;\r
- }\r
- sb = new StringBuffer();\r
- for (;;) {\r
- if (c == '<' || c == 0) {\r
- back();\r
- return sb.toString().trim();\r
- }\r
- if (c == '&') {\r
- sb.append(nextEntity(c));\r
- } else {\r
- sb.append(c);\r
- }\r
- c = next();\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Return the next entity. These entities are translated to Characters:\r
- * <code>& ' > < "</code>.\r
- * @param ampersand An ampersand character.\r
- * @return A Character or an entity String if the entity is not recognized.\r
- * @throws JSONException If missing ';' in XML entity.\r
- */\r
- public Object nextEntity(char ampersand) throws JSONException {\r
- StringBuffer sb = new StringBuffer();\r
- for (;;) {\r
- char c = next();\r
- if (Character.isLetterOrDigit(c) || c == '#') {\r
- sb.append(Character.toLowerCase(c));\r
- } else if (c == ';') {\r
- break;\r
- } else {\r
- throw syntaxError("Missing ';' in XML entity: &" + sb);\r
- }\r
- }\r
- String string = sb.toString();\r
- Object object = entity.get(string);\r
- return object != null ? object : ampersand + string + ";";\r
- }\r
-\r
-\r
- /**\r
- * Returns the next XML meta token. This is used for skipping over <!...>\r
- * and <?...?> structures.\r
- * @return Syntax characters (<code>< > / = ! ?</code>) are returned as\r
- * Character, and strings and names are returned as Boolean. We don't care\r
- * what the values actually are.\r
- * @throws JSONException If a string is not properly closed or if the XML\r
- * is badly structured.\r
- */\r
- public Object nextMeta() throws JSONException {\r
- char c;\r
- char q;\r
- do {\r
- c = next();\r
- } while (Character.isWhitespace(c));\r
- switch (c) {\r
- case 0:\r
- throw syntaxError("Misshaped meta tag");\r
- case '<':\r
- return XML.LT;\r
- case '>':\r
- return XML.GT;\r
- case '/':\r
- return XML.SLASH;\r
- case '=':\r
- return XML.EQ;\r
- case '!':\r
- return XML.BANG;\r
- case '?':\r
- return XML.QUEST;\r
- case '"':\r
- case '\'':\r
- q = c;\r
- for (;;) {\r
- c = next();\r
- if (c == 0) {\r
- throw syntaxError("Unterminated string");\r
- }\r
- if (c == q) {\r
- return Boolean.TRUE;\r
- }\r
- }\r
- default:\r
- for (;;) {\r
- c = next();\r
- if (Character.isWhitespace(c)) {\r
- return Boolean.TRUE;\r
- }\r
- switch (c) {\r
- case 0:\r
- case '<':\r
- case '>':\r
- case '/':\r
- case '=':\r
- case '!':\r
- case '?':\r
- case '"':\r
- case '\'':\r
- back();\r
- return Boolean.TRUE;\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Get the next XML Token. These tokens are found inside of angle\r
- * brackets. It may be one of these characters: <code>/ > = ! ?</code> or it\r
- * may be a string wrapped in single quotes or double quotes, or it may be a\r
- * name.\r
- * @return a String or a Character.\r
- * @throws JSONException If the XML is not well formed.\r
- */\r
- public Object nextToken() throws JSONException {\r
- char c;\r
- char q;\r
- StringBuffer sb;\r
- do {\r
- c = next();\r
- } while (Character.isWhitespace(c));\r
- switch (c) {\r
- case 0:\r
- throw syntaxError("Misshaped element");\r
- case '<':\r
- throw syntaxError("Misplaced '<'");\r
- case '>':\r
- return XML.GT;\r
- case '/':\r
- return XML.SLASH;\r
- case '=':\r
- return XML.EQ;\r
- case '!':\r
- return XML.BANG;\r
- case '?':\r
- return XML.QUEST;\r
-\r
-// Quoted string\r
-\r
- case '"':\r
- case '\'':\r
- q = c;\r
- sb = new StringBuffer();\r
- for (;;) {\r
- c = next();\r
- if (c == 0) {\r
- throw syntaxError("Unterminated string");\r
- }\r
- if (c == q) {\r
- return sb.toString();\r
- }\r
- if (c == '&') {\r
- sb.append(nextEntity(c));\r
- } else {\r
- sb.append(c);\r
- }\r
- }\r
- default:\r
-\r
-// Name\r
-\r
- sb = new StringBuffer();\r
- for (;;) {\r
- sb.append(c);\r
- c = next();\r
- if (Character.isWhitespace(c)) {\r
- return sb.toString();\r
- }\r
- switch (c) {\r
- case 0:\r
- return sb.toString();\r
- case '>':\r
- case '/':\r
- case '=':\r
- case '!':\r
- case '?':\r
- case '[':\r
- case ']':\r
- back();\r
- return sb.toString();\r
- case '<':\r
- case '"':\r
- case '\'':\r
- throw syntaxError("Bad character in a name");\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Skip characters until past the requested string.\r
- * If it is not found, we are left at the end of the source with a result of false.\r
- * @param to A string to skip past.\r
- * @throws JSONException\r
- */\r
- public boolean skipPast(String to) throws JSONException {\r
- boolean b;\r
- char c;\r
- int i;\r
- int j;\r
- int offset = 0;\r
- int length = to.length();\r
- char[] circle = new char[length];\r
-\r
- /*\r
- * First fill the circle buffer with as many characters as are in the\r
- * to string. If we reach an early end, bail.\r
- */\r
-\r
- for (i = 0; i < length; i += 1) {\r
- c = next();\r
- if (c == 0) {\r
- return false;\r
- }\r
- circle[i] = c;\r
- }\r
-\r
- /* We will loop, possibly for all of the remaining characters. */\r
-\r
- for (;;) {\r
- j = offset;\r
- b = true;\r
-\r
- /* Compare the circle buffer with the to string. */\r
-\r
- for (i = 0; i < length; i += 1) {\r
- if (circle[j] != to.charAt(i)) {\r
- b = false;\r
- break;\r
- }\r
- j += 1;\r
- if (j >= length) {\r
- j -= length;\r
- }\r
- }\r
-\r
- /* If we exit the loop with b intact, then victory is ours. */\r
-\r
- if (b) {\r
- return true;\r
- }\r
-\r
- /* Get the next character. If there isn't one, then defeat is ours. */\r
-\r
- c = next();\r
- if (c == 0) {\r
- return false;\r
- }\r
- /*\r
- * Shove the character in the circle buffer and advance the\r
- * circle offset. The offset is mod n.\r
- */\r
- circle[offset] = c;\r
- offset += 1;\r
- if (offset >= length) {\r
- offset -= length;\r
- }\r
- }\r
- }\r
-}\r
+++ /dev/null
-#-------------------------------------------------------------------------------\r
-# ============LICENSE_START==================================================\r
-# * org.onap.dmaap\r
-# * ===========================================================================\r
-# * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
-# * ===========================================================================\r
-# * Licensed under the Apache License, Version 2.0 (the "License");\r
-# * you may not use this file except in compliance with the License.\r
-# * You may obtain a copy of the License at\r
-# * \r
-# * http://www.apache.org/licenses/LICENSE-2.0\r
-# * \r
-# * Unless required by applicable law or agreed to in writing, software\r
-# * distributed under the License is distributed on an "AS IS" BASIS,\r
-# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-# * See the License for the specific language governing permissions and\r
-# * limitations under the License.\r
-# * ============LICENSE_END====================================================\r
-# *\r
-# * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
-# *\r
-#-------------------------------------------------------------------------------\r
-<!-- CVS: $Id: package.html,v 1.1 2013/04/26 21:01:51 eby Exp $ -->\r
-<!--\r
- AT&T - PROPRIETARY\r
- THIS FILE CONTAINS PROPRIETARY INFORMATION OF\r
- AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN\r
- ACCORDANCE WITH APPLICABLE AGREEMENTS.\r
-\r
- Copyright (c) 2013 AT&T Knowledge Ventures\r
- Unpublished and Not for Publication\r
- All Rights Reserved\r
--->\r
-<html>\r
-<body>\r
-<p>\r
-This package provides the json.org JSON library.\r
-</p>\r
-</body>\r
-</html>\r