diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..5be82732 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..1224a324 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/eurilys3/dist/ +/eurilys4/nbproject/private/ +/eurilys4-service/nbproject/private/ +/eurilys4/build/ +/eurilys4/dist/ +/eurilys4-service/dist/ +/eurilys4-service/build/ \ No newline at end of file diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 00000000..c99b187d --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,2 @@ +How to install +1. Login dengan username : admin, password :adminadmin \ No newline at end of file diff --git a/MEMBER.md b/MEMBER.md new file mode 100644 index 00000000..b6cc80b3 --- /dev/null +++ b/MEMBER.md @@ -0,0 +1,5 @@ +No NIM Naama GitHub_ID Mail + +1 13510086 Sharon Loh sharonloh lohh.sharon@gmail.com +2 +3 \ No newline at end of file diff --git a/Tubes5/Client/.classpath b/Tubes5/Client/.classpath new file mode 100644 index 00000000..18d70f02 --- /dev/null +++ b/Tubes5/Client/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Tubes5/Client/.project b/Tubes5/Client/.project new file mode 100644 index 00000000..0d1ca8e6 --- /dev/null +++ b/Tubes5/Client/.project @@ -0,0 +1,17 @@ + + + Client + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Tubes5/Client/.settings/org.eclipse.jdt.core.prefs b/Tubes5/Client/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..bf50819d --- /dev/null +++ b/Tubes5/Client/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Sat May 18 13:00:09 ICT 2013 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/Tubes5/Client/bin/Controller/Controller.class b/Tubes5/Client/bin/Controller/Controller.class new file mode 100644 index 00000000..a334f64c Binary files /dev/null and b/Tubes5/Client/bin/Controller/Controller.class differ diff --git a/Tubes5/Client/bin/Model/Task.class b/Tubes5/Client/bin/Model/Task.class new file mode 100644 index 00000000..2a06494f Binary files /dev/null and b/Tubes5/Client/bin/Model/Task.class differ diff --git a/Tubes5/Client/bin/Program.class b/Tubes5/Client/bin/Program.class new file mode 100644 index 00000000..0537cad2 Binary files /dev/null and b/Tubes5/Client/bin/Program.class differ diff --git a/Tubes5/Client/bin/org/json/JSONArray.class b/Tubes5/Client/bin/org/json/JSONArray.class new file mode 100644 index 00000000..34005cae Binary files /dev/null and b/Tubes5/Client/bin/org/json/JSONArray.class differ diff --git a/Tubes5/Client/bin/org/json/JSONException.class b/Tubes5/Client/bin/org/json/JSONException.class new file mode 100644 index 00000000..680b715f Binary files /dev/null and b/Tubes5/Client/bin/org/json/JSONException.class differ diff --git a/Tubes5/Client/bin/org/json/JSONModel.class b/Tubes5/Client/bin/org/json/JSONModel.class new file mode 100644 index 00000000..6e91c32c Binary files /dev/null and b/Tubes5/Client/bin/org/json/JSONModel.class differ diff --git a/Tubes5/Client/bin/org/json/JSONObject$Null.class b/Tubes5/Client/bin/org/json/JSONObject$Null.class new file mode 100644 index 00000000..9b15f605 Binary files /dev/null and b/Tubes5/Client/bin/org/json/JSONObject$Null.class differ diff --git a/Tubes5/Client/bin/org/json/JSONObject.class b/Tubes5/Client/bin/org/json/JSONObject.class new file mode 100644 index 00000000..c3fdcb63 Binary files /dev/null and b/Tubes5/Client/bin/org/json/JSONObject.class differ diff --git a/Tubes5/Client/bin/org/json/JSONString.class b/Tubes5/Client/bin/org/json/JSONString.class new file mode 100644 index 00000000..592bd20b Binary files /dev/null and b/Tubes5/Client/bin/org/json/JSONString.class differ diff --git a/Tubes5/Client/bin/org/json/JSONStringer.class b/Tubes5/Client/bin/org/json/JSONStringer.class new file mode 100644 index 00000000..6da6ae20 Binary files /dev/null and b/Tubes5/Client/bin/org/json/JSONStringer.class differ diff --git a/Tubes5/Client/bin/org/json/JSONTokener.class b/Tubes5/Client/bin/org/json/JSONTokener.class new file mode 100644 index 00000000..60dd2d01 Binary files /dev/null and b/Tubes5/Client/bin/org/json/JSONTokener.class differ diff --git a/Tubes5/Client/bin/org/json/JSONWriter.class b/Tubes5/Client/bin/org/json/JSONWriter.class new file mode 100644 index 00000000..159cb35a Binary files /dev/null and b/Tubes5/Client/bin/org/json/JSONWriter.class differ diff --git a/Tubes5/Client/load.out b/Tubes5/Client/load.out new file mode 100644 index 00000000..d513544c --- /dev/null +++ b/Tubes5/Client/load.out @@ -0,0 +1,5 @@ +{"tag_list":["tag2","tag3","halo"," pulang"],"task_creator":"sharonloh","task_name":"CCC","task_status":"1","task_id":"4","task_deadline":"2013-02-24","task_category":"Household"} +{"tag_list":["lalala"," liliili"," lululu"],"task_creator":"sharonloh","task_name":"Cinta ","task_status":"0","task_id":"6","task_deadline":"2013-05-03","task_category":"Personal"} +{"tag_list":[],"task_creator":"sharonloh","task_name":"Cuci Mangga","task_status":"0","task_id":"7","task_deadline":"2013-04-30","task_category":"Household"} +{"tag_list":["cuci"," bersih"," bathroom"],"task_creator":"sharonloh","task_name":"Sikat Lantai Kamar Mandi","task_status":"0","task_id":"8","task_deadline":"2013-04-24","task_category":"Household"} +{"tag_list":["sapu"," kamar"],"task_creator":"sharonloh","task_name":"Sapu kamar tuan","task_status":"0","task_id":"9","task_deadline":"2013-04-14","task_category":"Household"} diff --git a/Tubes5/Client/sharonlohload.out b/Tubes5/Client/sharonlohload.out new file mode 100644 index 00000000..2f47e5bb --- /dev/null +++ b/Tubes5/Client/sharonlohload.out @@ -0,0 +1,7 @@ +5 +{"tag_list":["tag2","tag3","halo"," pulang"],"task_creator":"sharonloh","task_name":"CCC","task_status":"0","task_id":"4","task_deadline":"2013-02-24","task_category":"Household"} +{"tag_list":["lalala"," liliili"," lululu"],"task_creator":"sharonloh","task_name":"Cinta ","task_status":"1","task_id":"6","task_deadline":"2013-05-03","task_category":"Personal"} +{"tag_list":[],"task_creator":"sharonloh","task_name":"Cuci Mangga","task_status":"0","task_id":"7","task_deadline":"2013-04-30","task_category":"Household"} +{"tag_list":["cuci"," bersih"," bathroom"],"task_creator":"sharonloh","task_name":"Sikat Lantai Kamar Mandi","task_status":"0","task_id":"8","task_deadline":"2013-04-24","task_category":"Household"} +{"tag_list":["sapu"," kamar"],"task_creator":"sharonloh","task_name":"Sapu kamar tuan","task_status":"0","task_id":"9","task_deadline":"2013-04-14","task_category":"Household"} +0 diff --git a/Tubes5/Client/src/Controller/Controller.java b/Tubes5/Client/src/Controller/Controller.java new file mode 100644 index 00000000..ca685793 --- /dev/null +++ b/Tubes5/Client/src/Controller/Controller.java @@ -0,0 +1,281 @@ +package Controller; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.Socket; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.json.JSONObject; + +import Model.Task; + +public class Controller { + + private Socket clientSocket; + private static final byte LOGIN = 0; + private static final byte SYNC = 1; + private static final byte UPDATE = 2; + private static final byte LIST = 3; + private static final byte LOGOUT = 9; + private static final byte SUCCESS = 10; + private static final byte FAILED = 11; + private long sessionId; + private String userID; + public boolean isLogin = false; + public List task_list = new ArrayList(); + public List update_list = new ArrayList(); + + public long getSessionId() + { + return sessionId; + } + + public boolean connect(String ip, int port) + { + try + { + if (clientSocket != null && clientSocket.isConnected()) + { + clientSocket.close(); + } + clientSocket = new Socket(ip,port); + } + catch (IOException e) + { + e.printStackTrace(); + clientSocket = null; + } + + return (clientSocket != null); + } + + public boolean login(String username, String password) + { + try + { + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + out.write(LOGIN); + + byte[] sendbyte = username.getBytes(); + out.writeInt(sendbyte.length); + out.write(sendbyte); + + sendbyte = password.getBytes(); + out.writeInt(sendbyte.length); + out.write(sendbyte); + byte response = in.readByte(); + if (response == SUCCESS) + { + System.out.println("RESPONSE :: SUCCESS"); + sessionId = in.readLong(); + userID = username; + isLogin = true; + System.out.println("SESSIONID :: " + sessionId); + return true; + } + else if (response == FAILED) + { + System.out.println("RESPONSE :: FAILED"); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + + return false; + } + + public void saveTask() { + try{ + BufferedWriter writer = new BufferedWriter(new FileWriter(userID+"load.out")); + String s = ""; + s += task_list.size() + "\n"; + for (int i = 0; i < task_list.size(); i++) + { + s += task_list.get(i).TaskToString()+ "\n"; + } + + s += update_list.size() + "\n"; + for (int i = 0; i < update_list.size(); i++) + { + s += update_list.get(i)+ "\n"; + } + + writer.write(s); + writer.close(); + }catch(IOException ex){ + ex.printStackTrace(); + } + } + + public void loadTask() { + try{ + task_list.clear(); + BufferedReader reader = new BufferedReader(new FileReader(userID+"load.out")); + String line = reader.readLine(); + int n = Integer.parseInt(line); + if (n > 0) + { + task_list.clear(); + for (int i = 0; i < n; i++) + { + line = reader.readLine(); + JSONObject temp = new JSONObject(line); + task_list.add(new Task(temp)); + } + } + + line = reader.readLine(); + n = Integer.parseInt(line); + if (n > 0) + { + update_list.clear(); + for (int i = 0; i < n; i++) + { + line = reader.readLine(); + update_list.add(line); + } + } + + }catch (Exception e) { + e.printStackTrace(); + } + } + + public void sync() + { + try{ + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + out.writeByte(SYNC); + out.writeLong(sessionId); + + out.writeInt(task_list.size()); + for (int i = 0; i < task_list.size(); i++) + { + String taskTemp = task_list.get(i).TaskToString(); + byte[] sendbyte = taskTemp.getBytes(); + out.writeInt(sendbyte.length); + out.write(sendbyte); + } + + byte response = in.readByte(); + if (response == SUCCESS) + { + System.out.println("BERHASIL SYNC"); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void list(){ + try{ + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + out.writeByte(LIST); + out.writeLong(sessionId); + System.out.println("tunggu response list"); + byte response = in.readByte(); + System.out.println("dapat response list" + response); + if (response == SUCCESS) + { + task_list.clear(); + int n = in.readInt(); + for (int i = 0; i < n; i++) { + byte[] data = new byte[in.readInt()]; + in.readFully(data); + String taskTemp = new String(data); + JSONObject taskObject = new JSONObject(taskTemp.toString()); + task_list.add(new Task(taskObject)); + } + saveTask(); + } + else if (response == FAILED) + { + System.out.println("list to server failed"); + } + System.out.println("hahahihi"); + } + catch (IOException e) + { + System.out.println("EXCEPTION"); + e.printStackTrace(); + } + } + + public void update(){ + try{ + System.out.println("amsuk update"); + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + out.writeByte(UPDATE); + out.writeLong(sessionId); + System.out.println("kirim pesan update"); + int n = update_list.size(); + if (n > 0) + { + out.writeInt(n); + for (int i = 0; i < n; i++) + { + byte[] sendbyte = update_list.get(i).getBytes(); + out.writeInt(sendbyte.length); + out.write(sendbyte); + } + } + else out.writeInt(n); + System.out.println("tunggu response update"); + byte response = in.readByte(); + if (response == SUCCESS) + { + list(); + update_list.clear(); + } + else if (response == FAILED) + { + System.out.println("update to server failed"); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void ubahStatus() + { + String s = task_list.get(1).getId_task() + "," + task_list.get(1).getStatus(); + //ubah juga task_list nya.. + update_list.add(s); + } + + public void logout() + { + saveTask(); + System.out.println("logout"); + isLogin = false; + userID = ""; + sessionId = -1; + } +} diff --git a/Tubes5/Client/src/Model/Task.java b/Tubes5/Client/src/Model/Task.java new file mode 100644 index 00000000..173a4f4c --- /dev/null +++ b/Tubes5/Client/src/Model/Task.java @@ -0,0 +1,112 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package Model; + +import org.json.JSONArray; +import org.json.JSONObject; + +/** + * + * @author dell + */ +public class Task { + + private String id_task; + private String name; + private String deadline; + private String status; + private String creator; + private String task_category; + private JSONArray tag_list; + + public String getId_task() { + return id_task; + } + + public void setId_task(String id_task) { + this.id_task = id_task; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDeadline() { + return deadline; + } + + public void setDeadline(String deadline) { + this.deadline = deadline; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getTask_category() { + return task_category; + } + + public void setTask_category(String task_category) { + this.task_category = task_category; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public JSONArray getTag_list(){ + return tag_list; + } + + public void setTag_list(JSONArray tag_list){ + this.tag_list = tag_list; + } + + public Task(String id_task, String name, String deadline, String status, String task_category, String creator, JSONArray tag_list) { + this.id_task = id_task; + this.name = name; + this.deadline = deadline; + this.status = status; + this.task_category = task_category; + this.creator = creator; + this.tag_list = tag_list; + } + + public Task(JSONObject jsonObj) { + this.id_task = jsonObj.getString("task_id"); + this.name = jsonObj.getString("task_name"); + this.deadline = jsonObj.getString("task_deadline"); + this.status = jsonObj.getString("task_status"); + this.task_category = jsonObj.getString("task_category"); + this.creator = jsonObj.getString("task_creator"); + this.tag_list = jsonObj.getJSONArray("tag_list"); + } + + public String TaskToString(){ + JSONObject taskObject = new JSONObject(); + taskObject.put("task_id", id_task); + taskObject.put("task_name", name); + taskObject.put("task_status", status); + taskObject.put("task_deadline", deadline); + taskObject.put("task_category", task_category); + taskObject.put("task_creator", creator); + taskObject.put("tag_list", tag_list); + + return taskObject.toString(); + } +} diff --git a/Tubes5/Client/src/Program.java b/Tubes5/Client/src/Program.java new file mode 100644 index 00000000..74294d32 --- /dev/null +++ b/Tubes5/Client/src/Program.java @@ -0,0 +1,60 @@ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.ObjectInputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; + +import Controller.Controller; +import Model.Task; + +public class Program { + + /** + * @param args + */ + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + Controller controller = new Controller(); + System.out.println("-Connect- " + controller.connect("127.0.0.1", 9000)); + System.out.println("-Login- " + controller.login("sharonloh", "gilagila")); + controller.loadTask(); + if (controller.update_list.size() == 0) + { + System.out.println("daftar update kosong"); + } + controller.update(); + //sc.next(); + //controller.list(); + sc.next(); + /* + controller.ubahStatus(); + for (int i = 0; i < controller.update_list.size(); i++) + { + System.out.println("daftar update = " + controller.update_list.get(i)); + } + controller.update(); + */ + //controller.list(); + controller.logout(); + /* + controller.ubahStatus(); + //controller.saveTask(); + for (int i = 0; i < controller.update_list.size(); i++) + { + System.out.println("daftar update = " + controller.update_list.get(i)); + } + controller.update(); + controller.list();*/ + } + +} diff --git a/Tubes5/Client/src/org/json/JSONArray.java b/Tubes5/Client/src/org/json/JSONArray.java new file mode 100644 index 00000000..673a9192 --- /dev/null +++ b/Tubes5/Client/src/org/json/JSONArray.java @@ -0,0 +1,944 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +/** + * A JSONArray is an ordered sequence of values. Its external text form is a + * string wrapped in square brackets with commas separating the values. The + * internal form is an object having get and opt + * methods for accessing the values by index, and put methods for + * adding or replacing values. The values can be any of these types: + * Boolean, JSONArray, JSONObject, + * Number, String, or the + * JSONObject.NULL object. + *

+ * The constructor can convert a JSON text into a Java object. The + * toString method converts to JSON text. + *

+ * A get method returns a value if one can be found, and throws an + * exception if one cannot be found. An opt method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + *

+ * The generic get() and opt() methods return an + * object which you can cast or query for type. There are also typed + * get and opt methods that do type checking and type + * coercion for you. + *

+ * The texts produced by the toString methods strictly conform to + * JSON syntax rules. The constructors are more forgiving in the texts they will + * accept: + *

    + *
  • An extra , (comma) may appear just + * before the closing bracket.
  • + *
  • The null value will be inserted when there is , + *  (comma) elision.
  • + *
  • Strings may be quoted with ' (single + * quote).
  • + *
  • Strings do not need to be quoted at all if they do not begin with a quote + * or single quote, and if they do not contain leading or trailing spaces, and + * if they do not contain any of these characters: + * { } [ ] / \ : , # and if they do not look like numbers and + * if they are not the reserved words true, false, or + * null.
  • + *
+ * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONArray { + + /** + * The arrayList where the JSONArray's properties are kept. + */ + private final ArrayList myArrayList; + + /** + * Construct an empty JSONArray. + */ + public JSONArray() { + this.myArrayList = new ArrayList(); + } + + /** + * Construct a JSONArray from a JSONTokener. + * + * @param x + * A JSONTokener + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(JSONTokener x) throws JSONException { + this(); + if (x.nextClean() != '[') { + throw x.syntaxError("A JSONArray text must start with '['"); + } + if (x.nextClean() != ']') { + x.back(); + for (;;) { + if (x.nextClean() == ',') { + x.back(); + this.myArrayList.add(JSONObject.NULL); + } else { + x.back(); + this.myArrayList.add(x.nextValue()); + } + switch (x.nextClean()) { + case ',': + if (x.nextClean() == ']') { + return; + } + x.back(); + break; + case ']': + return; + default: + throw x.syntaxError("Expected a ',' or ']'"); + } + } + } + } + + /** + * Construct a JSONArray from a source JSON text. + * + * @param source + * A string that begins with [ (left + * bracket) and ends with ] + *  (right bracket). + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONArray from a Collection. + * + * @param collection + * A Collection. + */ + public JSONArray(Collection collection) { + this.myArrayList = new ArrayList(); + if (collection != null) { + Iterator iter = collection.iterator(); + while (iter.hasNext()) { + this.myArrayList.add(JSONObject.wrap(iter.next())); + } + } + } + + /** + * Construct a JSONArray from an array + * + * @throws JSONException + * If not an array. + */ + public JSONArray(Object array) throws JSONException { + this(); + if (array.getClass().isArray()) { + int length = Array.getLength(array); + for (int i = 0; i < length; i += 1) { + this.put(JSONObject.wrap(Array.get(array, i))); + } + } else { + throw new JSONException( + "JSONArray initial value should be a string or collection or array."); + } + } + + /** + * Get the object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value. + * @throws JSONException + * If there is no value for the index. + */ + public Object get(int index) throws JSONException { + Object object = this.opt(index); + if (object == null) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with an index. The string values "true" + * and "false" are converted to boolean. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + * @throws JSONException + * If there is no value for the index or if the value is not + * convertible to boolean. + */ + public boolean getBoolean(int index) throws JSONException { + Object object = this.get(index); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONArray[" + index + "] is not a boolean."); + } + + /** + * Get the double value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public double getDouble(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the int value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value is not a number. + */ + public int getInt(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the JSONArray associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONArray value. + * @throws JSONException + * If there is no value for the index. or if the value is not a + * JSONArray + */ + public JSONArray getJSONArray(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); + } + + /** + * Get the JSONObject associated with an index. + * + * @param index + * subscript + * @return A JSONObject value. + * @throws JSONException + * If there is no value for the index or if the value is not a + * JSONObject + */ + public JSONObject getJSONObject(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); + } + + /** + * Get the long value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public long getLong(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the string associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A string value. + * @throws JSONException + * If there is no string value for the index. + */ + public String getString(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONArray[" + index + "] not a string."); + } + + /** + * Determine if the value is null. + * + * @param index + * The index must be between 0 and length() - 1. + * @return true if the value at the index is null, or if there is no value. + */ + public boolean isNull(int index) { + return JSONObject.NULL.equals(this.opt(index)); + } + + /** + * Make a string from the contents of this JSONArray. The + * separator string is inserted between each element. Warning: + * This method assumes that the data structure is acyclical. + * + * @param separator + * A string that will be inserted between the elements. + * @return a string. + * @throws JSONException + * If the array contains an invalid number. + */ + public String join(String separator) throws JSONException { + int len = this.length(); + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < len; i += 1) { + if (i > 0) { + sb.append(separator); + } + sb.append(JSONObject.valueToString(this.myArrayList.get(i))); + } + return sb.toString(); + } + + /** + * Get the number of elements in the JSONArray, included nulls. + * + * @return The length (or size). + */ + public int length() { + return this.myArrayList.size(); + } + + /** + * Get the optional object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value, or null if there is no object at that index. + */ + public Object opt(int index) { + return (index < 0 || index >= this.length()) ? null : this.myArrayList + .get(index); + } + + /** + * Get the optional boolean value associated with an index. It returns false + * if there is no value at that index, or if the value is not Boolean.TRUE + * or the String "true". + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + */ + public boolean optBoolean(int index) { + return this.optBoolean(index, false); + } + + /** + * Get the optional boolean value associated with an index. It returns the + * defaultValue if there is no value at that index or if it is not a Boolean + * or the String "true" or "false" (case insensitive). + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * A boolean default. + * @return The truth. + */ + public boolean optBoolean(int index, boolean defaultValue) { + try { + return this.getBoolean(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional double value associated with an index. NaN is returned + * if there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public double optDouble(int index) { + return this.optDouble(index, Double.NaN); + } + + /** + * Get the optional double value associated with an index. The defaultValue + * is returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * subscript + * @param defaultValue + * The default value. + * @return The value. + */ + public double optDouble(int index, double defaultValue) { + try { + return this.getDouble(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional int value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public int optInt(int index) { + return this.optInt(index, 0); + } + + /** + * Get the optional int value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public int optInt(int index, int defaultValue) { + try { + return this.getInt(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional JSONArray associated with an index. + * + * @param index + * subscript + * @return A JSONArray value, or null if the index has no value, or if the + * value is not a JSONArray. + */ + public JSONArray optJSONArray(int index) { + Object o = this.opt(index); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get the optional JSONObject associated with an index. Null is returned if + * the key is not found, or null if the index has no value, or if the value + * is not a JSONObject. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONObject value. + */ + public JSONObject optJSONObject(int index) { + Object o = this.opt(index); + return o instanceof JSONObject ? (JSONObject) o : null; + } + + /** + * Get the optional long value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public long optLong(int index) { + return this.optLong(index, 0); + } + + /** + * Get the optional long value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public long optLong(int index, long defaultValue) { + try { + return this.getLong(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional string value associated with an index. It returns an + * empty string if there is no value at that index. If the value is not a + * string and is not null, then it is coverted to a string. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A String value. + */ + public String optString(int index) { + return this.optString(index, ""); + } + + /** + * Get the optional string associated with an index. The defaultValue is + * returned if the key is not found. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return A String value. + */ + public String optString(int index, String defaultValue) { + Object object = this.opt(index); + return JSONObject.NULL.equals(object) ? defaultValue : object + .toString(); + } + + /** + * Append a boolean value. This increases the array's length by one. + * + * @param value + * A boolean value. + * @return this. + */ + public JSONArray put(boolean value) { + this.put(value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param value + * A Collection value. + * @return this. + */ + public JSONArray put(Collection value) { + this.put(new JSONArray(value)); + return this; + } + + /** + * Append a double value. This increases the array's length by one. + * + * @param value + * A double value. + * @throws JSONException + * if the value is not finite. + * @return this. + */ + public JSONArray put(double value) throws JSONException { + Double d = new Double(value); + JSONObject.testValidity(d); + this.put(d); + return this; + } + + /** + * Append an int value. This increases the array's length by one. + * + * @param value + * An int value. + * @return this. + */ + public JSONArray put(int value) { + this.put(new Integer(value)); + return this; + } + + /** + * Append an long value. This increases the array's length by one. + * + * @param value + * A long value. + * @return this. + */ + public JSONArray put(long value) { + this.put(new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject which + * is produced from a Map. + * + * @param value + * A Map value. + * @return this. + */ + public JSONArray put(Map value) { + this.put(new JSONObject(value)); + return this; + } + + /** + * Append an object value. This increases the array's length by one. + * + * @param value + * An object value. The value should be a Boolean, Double, + * Integer, JSONArray, JSONObject, Long, or String, or the + * JSONObject.NULL object. + * @return this. + */ + public JSONArray put(Object value) { + this.myArrayList.add(value); + return this; + } + + /** + * Put or replace a boolean value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * A boolean value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, boolean value) throws JSONException { + this.put(index, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param index + * The subscript. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, Collection value) throws JSONException { + this.put(index, new JSONArray(value)); + return this; + } + + /** + * Put or replace a double value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A double value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, double value) throws JSONException { + this.put(index, new Double(value)); + return this; + } + + /** + * Put or replace an int value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * An int value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, int value) throws JSONException { + this.put(index, new Integer(value)); + return this; + } + + /** + * Put or replace a long value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A long value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, long value) throws JSONException { + this.put(index, new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject that + * is produced from a Map. + * + * @param index + * The subscript. + * @param value + * The Map value. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Map value) throws JSONException { + this.put(index, new JSONObject(value)); + return this; + } + + /** + * Put or replace an object value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * The value to put into the array. The value should be a + * Boolean, Double, Integer, JSONArray, JSONObject, Long, or + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Object value) throws JSONException { + JSONObject.testValidity(value); + if (index < 0) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + if (index < this.length()) { + this.myArrayList.set(index, value); + } else { + while (index != this.length()) { + this.put(JSONObject.NULL); + } + this.put(value); + } + return this; + } + + /** + * Remove an index and close the hole. + * + * @param index + * The index of the element to be removed. + * @return The value that was associated with the index, or null if there + * was no value. + */ + public Object remove(int index) { + Object o = this.opt(index); + this.myArrayList.remove(index); + return o; + } + + /** + * Produce a JSONObject by combining a JSONArray of names with the values of + * this JSONArray. + * + * @param names + * A JSONArray containing a list of key strings. These will be + * paired with the values. + * @return A JSONObject, or null if there are no names or if this JSONArray + * has no values. + * @throws JSONException + * If any of the names are null. + */ + public JSONObject toJSONObject(JSONArray names) throws JSONException { + if (names == null || names.length() == 0 || this.length() == 0) { + return null; + } + JSONObject jo = new JSONObject(); + for (int i = 0; i < names.length(); i += 1) { + jo.put(names.getString(i), this.opt(i)); + } + return jo; + } + + /** + * Make a JSON text of this JSONArray. For compactness, no unnecessary + * whitespace is added. If it is not possible to produce a syntactically + * correct JSON text then null will be returned instead. This could occur if + * the array contains an invalid number. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, transmittable representation of the + * array. + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONArray. Warning: This method + * assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, transmittable representation of the + * object, beginning with [ (left + * bracket) and ending with ] + *  (right bracket). + * @throws JSONException + */ + public String toString(int indentFactor) throws JSONException { + StringWriter sw = new StringWriter(); + synchronized (sw.getBuffer()) { + return this.write(sw, indentFactor, 0).toString(); + } + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @param indent + * The indention of the top level. + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + int length = this.length(); + writer.write('['); + + if (length == 1) { + JSONObject.writeValue(writer, this.myArrayList.get(0), + indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + + for (int i = 0; i < length; i += 1) { + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, newindent); + JSONObject.writeValue(writer, this.myArrayList.get(i), + indentFactor, newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, indent); + } + writer.write(']'); + return writer; + } catch (IOException e) { + throw new JSONException(e); + } + } +} diff --git a/Tubes5/Client/src/org/json/JSONException.java b/Tubes5/Client/src/org/json/JSONException.java new file mode 100644 index 00000000..971547e6 --- /dev/null +++ b/Tubes5/Client/src/org/json/JSONException.java @@ -0,0 +1,41 @@ +package org.json; + +/** + * The JSONException is thrown by the JSON.org classes when things are amiss. + * + * @author JSON.org + * @version 2013-02-10 + */ +public class JSONException extends RuntimeException { + private static final long serialVersionUID = 0; + private Throwable cause; + + /** + * Constructs a JSONException with an explanatory message. + * + * @param message + * Detail about the reason for the exception. + */ + public JSONException(String message) { + super(message); + } + + /** + * Constructs a new JSONException with the specified cause. + */ + public JSONException(Throwable cause) { + super(cause.getMessage()); + this.cause = cause; + } + + /** + * Returns the cause of this exception or null if the cause is nonexistent + * or unknown. + * + * @returns the cause of this exception or null if the cause is nonexistent + * or unknown. + */ + public Throwable getCause() { + return this.cause; + } +} diff --git a/Tubes5/Client/src/org/json/JSONModel.java b/Tubes5/Client/src/org/json/JSONModel.java new file mode 100644 index 00000000..637bb38f --- /dev/null +++ b/Tubes5/Client/src/org/json/JSONModel.java @@ -0,0 +1,6 @@ +package org.json; + +public abstract class JSONModel { + + public abstract JSONObject toJsonObject(); +} diff --git a/Tubes5/Client/src/org/json/JSONObject.java b/Tubes5/Client/src/org/json/JSONObject.java new file mode 100644 index 00000000..5666eb57 --- /dev/null +++ b/Tubes5/Client/src/org/json/JSONObject.java @@ -0,0 +1,1666 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; + +/** + * A JSONObject is an unordered collection of name/value pairs. Its external + * form is a string wrapped in curly braces with colons between the names and + * values, and commas between the values and names. The internal form is an + * object having get and opt methods for accessing + * the values by name, and put methods for adding or replacing + * values by name. The values can be any of these types: Boolean, + * JSONArray, JSONObject, Number, + * String, or the JSONObject.NULL object. A + * JSONObject constructor can be used to convert an external form JSON text + * into an internal form whose values can be retrieved with the + * get and opt methods, or to convert values into a + * JSON text using the put and toString methods. A + * get method returns a value if one can be found, and throws an + * exception if one cannot be found. An opt method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + *

+ * The generic get() and opt() methods return an + * object, which you can cast or query for type. There are also typed + * get and opt methods that do type checking and type + * coercion for you. The opt methods differ from the get methods in that they + * do not throw. Instead, they return a specified value, such as null. + *

+ * The put methods add or replace values in an object. For + * example, + * + *

+ * myString = new JSONObject()
+ *         .put("JSON", "Hello, World!").toString();
+ * 
+ * + * produces the string {"JSON": "Hello, World"}. + *

+ * The texts produced by the toString methods strictly conform to + * the JSON syntax rules. The constructors are more forgiving in the texts they + * will accept: + *

    + *
  • An extra , (comma) may appear just + * before the closing brace.
  • + *
  • Strings may be quoted with ' (single + * quote).
  • + *
  • Strings do not need to be quoted at all if they do not begin with a + * quote or single quote, and if they do not contain leading or trailing + * spaces, and if they do not contain any of these characters: + * { } [ ] / \ : , # and if they do not look like numbers and + * if they are not the reserved words true, false, + * or null.
  • + *
+ * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONObject { + /** + * The maximum number of keys in the key pool. + */ + private static final int keyPoolSize = 100; + + /** + * Key pooling is like string interning, but without permanently tying up + * memory. To help conserve memory, storage of duplicated key strings in + * JSONObjects will be avoided by using a key pool to manage unique key + * string objects. This is used by JSONObject.put(string, object). + */ + private static HashMap keyPool = new HashMap(keyPoolSize); + + /** + * JSONObject.NULL is equivalent to the value that JavaScript calls null, + * whilst Java's null is equivalent to the value that JavaScript calls + * undefined. + */ + private static final class Null { + + /** + * There is only intended to be a single instance of the NULL object, + * so the clone method returns itself. + * + * @return NULL. + */ + protected final Object clone() { + return this; + } + + /** + * A Null object is equal to the null value and to itself. + * + * @param object + * An object to test for nullness. + * @return true if the object parameter is the JSONObject.NULL object or + * null. + */ + public boolean equals(Object object) { + return object == null || object == this; + } + + /** + * Get the "null" string value. + * + * @return The string "null". + */ + public String toString() { + return "null"; + } + } + + /** + * The map where the JSONObject's properties are kept. + */ + private final Map map; + + /** + * It is sometimes more convenient and less ambiguous to have a + * NULL object than to use Java's null value. + * JSONObject.NULL.equals(null) returns true. + * JSONObject.NULL.toString() returns "null". + */ + public static final Object NULL = new Null(); + + /** + * Construct an empty JSONObject. + */ + public JSONObject() { + this.map = new HashMap(); + } + + /** + * Construct a JSONObject from a subset of another JSONObject. An array of + * strings is used to identify the keys that should be copied. Missing keys + * are ignored. + * + * @param jo + * A JSONObject. + * @param names + * An array of strings. + * @throws JSONException + * @exception JSONException + * If a value is a non-finite number or if a name is + * duplicated. + */ + public JSONObject(JSONObject jo, String[] names) { + this(); + for (int i = 0; i < names.length; i += 1) { + try { + this.putOnce(names[i], jo.opt(names[i])); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a JSONTokener. + * + * @param x + * A JSONTokener object containing the source string. + * @throws JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(JSONTokener x) throws JSONException { + this(); + char c; + String key; + + if (x.nextClean() != '{') { + throw x.syntaxError("A JSONObject text must begin with '{'"); + } + for (;;) { + c = x.nextClean(); + switch (c) { + case 0: + throw x.syntaxError("A JSONObject text must end with '}'"); + case '}': + return; + default: + x.back(); + key = x.nextValue().toString(); + } + +// The key is followed by ':'. + + c = x.nextClean(); + if (c != ':') { + throw x.syntaxError("Expected a ':' after a key"); + } + this.putOnce(key, x.nextValue()); + +// Pairs are separated by ','. + + switch (x.nextClean()) { + case ';': + case ',': + if (x.nextClean() == '}') { + return; + } + x.back(); + break; + case '}': + return; + default: + throw x.syntaxError("Expected a ',' or '}'"); + } + } + } + + /** + * Construct a JSONObject from a Map. + * + * @param map + * A map object that can be used to initialize the contents of + * the JSONObject. + * @throws JSONException + */ + public JSONObject(Map map) { + this.map = new HashMap(); + if (map != null) { + Iterator i = map.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry e = (Map.Entry) i.next(); + Object value = e.getValue(); + if (value != null) { + this.map.put(e.getKey(), wrap(value)); + } + } + } + } + + /** + * Construct a JSONObject from an Object using bean getters. It reflects on + * all of the public methods of the object. For each of the methods with no + * parameters and a name starting with "get" or + * "is" followed by an uppercase letter, the method is invoked, + * and a key and the value returned from the getter method are put into the + * new JSONObject. + * + * The key is formed by removing the "get" or "is" + * prefix. If the second remaining character is not upper case, then the + * first character is converted to lower case. + * + * For example, if an object has a method named "getName", and + * if the result of calling object.getName() is + * "Larry Fine", then the JSONObject will contain + * "name": "Larry Fine". + * + * @param bean + * An object that has getter methods that should be used to make + * a JSONObject. + */ + public JSONObject(Object bean) { + this(); + this.populateMap(bean); + } + + /** + * Construct a JSONObject from an Object, using reflection to find the + * public members. The resulting JSONObject's keys will be the strings from + * the names array, and the values will be the field values associated with + * those keys in the object. If a key is not found or not visible, then it + * will not be copied into the new JSONObject. + * + * @param object + * An object that has fields that should be used to make a + * JSONObject. + * @param names + * An array of strings, the names of the fields to be obtained + * from the object. + */ + public JSONObject(Object object, String names[]) { + this(); + Class c = object.getClass(); + for (int i = 0; i < names.length; i += 1) { + String name = names[i]; + try { + this.putOpt(name, c.getField(name).get(object)); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a source JSON text string. This is the most + * commonly used JSONObject constructor. + * + * @param source + * A string beginning with { (left + * brace) and ending with } + *  (right brace). + * @exception JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONObject from a ResourceBundle. + * + * @param baseName + * The ResourceBundle base name. + * @param locale + * The Locale to load the ResourceBundle for. + * @throws JSONException + * If any JSONExceptions are detected. + */ + public JSONObject(String baseName, Locale locale) throws JSONException { + this(); + ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, + Thread.currentThread().getContextClassLoader()); + +// Iterate through the keys in the bundle. + + Enumeration keys = bundle.getKeys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + if (key instanceof String) { + +// Go through the path, ensuring that there is a nested JSONObject for each +// segment except the last. Add the value using the last segment's name into +// the deepest nested JSONObject. + + String[] path = ((String) key).split("\\."); + int last = path.length - 1; + JSONObject target = this; + for (int i = 0; i < last; i += 1) { + String segment = path[i]; + JSONObject nextTarget = target.optJSONObject(segment); + if (nextTarget == null) { + nextTarget = new JSONObject(); + target.put(segment, nextTarget); + } + target = nextTarget; + } + target.put(path[last], bundle.getString((String) key)); + } + } + } + + /** + * Accumulate values under a key. It is similar to the put method except + * that if there is already an object stored under the key then a JSONArray + * is stored under the key to hold all of the accumulated values. If there + * is already a JSONArray, then the new value is appended to it. In + * contrast, the put method replaces the previous value. + * + * If only one value is accumulated that is not a JSONArray, then the result + * will be the same as using put. But if multiple values are accumulated, + * then the result will be like append. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the value is an invalid number or if the key is null. + */ + public JSONObject accumulate(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, + value instanceof JSONArray ? new JSONArray().put(value) + : value); + } else if (object instanceof JSONArray) { + ((JSONArray) object).put(value); + } else { + this.put(key, new JSONArray().put(object).put(value)); + } + return this; + } + + /** + * Append values to the array under a key. If the key does not exist in the + * JSONObject, then the key is put in the JSONObject with its value being a + * JSONArray containing the value parameter. If the key was already + * associated with a JSONArray, then the value parameter is appended to it. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the key is null or if the current value associated with + * the key is not a JSONArray. + */ + public JSONObject append(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, new JSONArray().put(value)); + } else if (object instanceof JSONArray) { + this.put(key, ((JSONArray) object).put(value)); + } else { + throw new JSONException("JSONObject[" + key + + "] is not a JSONArray."); + } + return this; + } + + /** + * Produce a string from a double. The string "null" will be returned if the + * number is not finite. + * + * @param d + * A double. + * @return A String. + */ + public static String doubleToString(double d) { + if (Double.isInfinite(d) || Double.isNaN(d)) { + return "null"; + } + +// Shave off trailing zeros and decimal point, if possible. + + String string = Double.toString(d); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get the value object associated with a key. + * + * @param key + * A key string. + * @return The object associated with the key. + * @throws JSONException + * if the key is not found. + */ + public Object get(String key) throws JSONException { + if (key == null) { + throw new JSONException("Null key."); + } + Object object = this.opt(key); + if (object == null) { + throw new JSONException("JSONObject[" + quote(key) + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with a key. + * + * @param key + * A key string. + * @return The truth. + * @throws JSONException + * if the value is not a Boolean or the String "true" or + * "false". + */ + public boolean getBoolean(String key) throws JSONException { + Object object = this.get(key); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a Boolean."); + } + + /** + * Get the double value associated with a key. + * + * @param key + * A key string. + * @return The numeric value. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. + */ + public double getDouble(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a number."); + } + } + + /** + * Get the int value associated with a key. + * + * @param key + * A key string. + * @return The integer value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to an integer. + */ + public int getInt(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not an int."); + } + } + + /** + * Get the JSONArray value associated with a key. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONArray. + */ + public JSONArray getJSONArray(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONArray."); + } + + /** + * Get the JSONObject value associated with a key. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONObject. + */ + public JSONObject getJSONObject(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONObject."); + } + + /** + * Get the long value associated with a key. + * + * @param key + * A key string. + * @return The long value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to a long. + */ + public long getLong(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a long."); + } + } + + /** + * Get an array of field names from a JSONObject. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(JSONObject jo) { + int length = jo.length(); + if (length == 0) { + return null; + } + Iterator iterator = jo.keys(); + String[] names = new String[length]; + int i = 0; + while (iterator.hasNext()) { + names[i] = (String) iterator.next(); + i += 1; + } + return names; + } + + /** + * Get an array of field names from an Object. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(Object object) { + if (object == null) { + return null; + } + Class klass = object.getClass(); + Field[] fields = klass.getFields(); + int length = fields.length; + if (length == 0) { + return null; + } + String[] names = new String[length]; + for (int i = 0; i < length; i += 1) { + names[i] = fields[i].getName(); + } + return names; + } + + /** + * Get the string associated with a key. + * + * @param key + * A key string. + * @return A string which is the value. + * @throws JSONException + * if there is no string value for the key. + */ + public String getString(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONObject[" + quote(key) + "] not a string."); + } + + /** + * Determine if the JSONObject contains a specific key. + * + * @param key + * A key string. + * @return true if the key exists in the JSONObject. + */ + public boolean has(String key) { + return this.map.containsKey(key); + } + + /** + * Increment a property of a JSONObject. If there is no such property, + * create one with a value of 1. If there is such a property, and if it is + * an Integer, Long, Double, or Float, then add one to it. + * + * @param key + * A key string. + * @return this. + * @throws JSONException + * If there is already a property with this name that is not an + * Integer, Long, Double, or Float. + */ + public JSONObject increment(String key) throws JSONException { + Object value = this.opt(key); + if (value == null) { + this.put(key, 1); + } else if (value instanceof Integer) { + this.put(key, ((Integer) value).intValue() + 1); + } else if (value instanceof Long) { + this.put(key, ((Long) value).longValue() + 1); + } else if (value instanceof Double) { + this.put(key, ((Double) value).doubleValue() + 1); + } else if (value instanceof Float) { + this.put(key, ((Float) value).floatValue() + 1); + } else { + throw new JSONException("Unable to increment [" + quote(key) + "]."); + } + return this; + } + + /** + * Determine if the value associated with the key is null or if there is no + * value. + * + * @param key + * A key string. + * @return true if there is no value associated with the key or if the value + * is the JSONObject.NULL object. + */ + public boolean isNull(String key) { + return JSONObject.NULL.equals(this.opt(key)); + } + + /** + * Get an enumeration of the keys of the JSONObject. + * + * @return An iterator of the keys. + */ + public Iterator keys() { + return this.keySet().iterator(); + } + + /** + * Get a set of keys of the JSONObject. + * + * @return A keySet. + */ + public Set keySet() { + return this.map.keySet(); + } + + /** + * Get the number of keys stored in the JSONObject. + * + * @return The number of keys in the JSONObject. + */ + public int length() { + return this.map.size(); + } + + /** + * Produce a JSONArray containing the names of the elements of this + * JSONObject. + * + * @return A JSONArray containing the key strings, or null if the JSONObject + * is empty. + */ + public JSONArray names() { + JSONArray ja = new JSONArray(); + Iterator keys = this.keys(); + while (keys.hasNext()) { + ja.put(keys.next()); + } + return ja.length() == 0 ? null : ja; + } + + /** + * Produce a string from a Number. + * + * @param number + * A Number + * @return A String. + * @throws JSONException + * If n is a non-finite number. + */ + public static String numberToString(Number number) throws JSONException { + if (number == null) { + throw new JSONException("Null pointer"); + } + testValidity(number); + +// Shave off trailing zeros and decimal point, if possible. + + String string = number.toString(); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get an optional value associated with a key. + * + * @param key + * A key string. + * @return An object which is the value, or null if there is no value. + */ + public Object opt(String key) { + return key == null ? null : this.map.get(key); + } + + /** + * Get an optional boolean associated with a key. It returns false if there + * is no such key, or if the value is not Boolean.TRUE or the String "true". + * + * @param key + * A key string. + * @return The truth. + */ + public boolean optBoolean(String key) { + return this.optBoolean(key, false); + } + + /** + * Get an optional boolean associated with a key. It returns the + * defaultValue if there is no such key, or if it is not a Boolean or the + * String "true" or "false" (case insensitive). + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return The truth. + */ + public boolean optBoolean(String key, boolean defaultValue) { + try { + return this.getBoolean(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional double associated with a key, or NaN if there is no such + * key or if its value is not a number. If the value is a string, an attempt + * will be made to evaluate it as a number. + * + * @param key + * A string which is the key. + * @return An object which is the value. + */ + public double optDouble(String key) { + return this.optDouble(key, Double.NaN); + } + + /** + * Get an optional double associated with a key, or the defaultValue if + * there is no such key or if its value is not a number. If the value is a + * string, an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public double optDouble(String key, double defaultValue) { + try { + return this.getDouble(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional int value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public int optInt(String key) { + return this.optInt(key, 0); + } + + /** + * Get an optional int value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public int optInt(String key, int defaultValue) { + try { + return this.getInt(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional JSONArray associated with a key. It returns null if there + * is no such key, or if its value is not a JSONArray. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + */ + public JSONArray optJSONArray(String key) { + Object o = this.opt(key); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get an optional JSONObject associated with a key. It returns null if + * there is no such key, or if its value is not a JSONObject. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + */ + public JSONObject optJSONObject(String key) { + Object object = this.opt(key); + return object instanceof JSONObject ? (JSONObject) object : null; + } + + /** + * Get an optional long value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public long optLong(String key) { + return this.optLong(key, 0); + } + + /** + * Get an optional long value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public long optLong(String key, long defaultValue) { + try { + return this.getLong(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional string associated with a key. It returns an empty string + * if there is no such key. If the value is not a string and is not null, + * then it is converted to a string. + * + * @param key + * A key string. + * @return A string which is the value. + */ + public String optString(String key) { + return this.optString(key, ""); + } + + /** + * Get an optional string associated with a key. It returns the defaultValue + * if there is no such key. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return A string which is the value. + */ + public String optString(String key, String defaultValue) { + Object object = this.opt(key); + return NULL.equals(object) ? defaultValue : object.toString(); + } + + private void populateMap(Object bean) { + Class klass = bean.getClass(); + +// If klass is a System class then set includeSuperClass to false. + + boolean includeSuperClass = klass.getClassLoader() != null; + + Method[] methods = includeSuperClass ? klass.getMethods() : klass + .getDeclaredMethods(); + for (int i = 0; i < methods.length; i += 1) { + try { + Method method = methods[i]; + if (Modifier.isPublic(method.getModifiers())) { + String name = method.getName(); + String key = ""; + if (name.startsWith("get")) { + if ("getClass".equals(name) + || "getDeclaringClass".equals(name)) { + key = ""; + } else { + key = name.substring(3); + } + } else if (name.startsWith("is")) { + key = name.substring(2); + } + if (key.length() > 0 + && Character.isUpperCase(key.charAt(0)) + && method.getParameterTypes().length == 0) { + if (key.length() == 1) { + key = key.toLowerCase(); + } else if (!Character.isUpperCase(key.charAt(1))) { + key = key.substring(0, 1).toLowerCase() + + key.substring(1); + } + + Object result = method.invoke(bean, (Object[]) null); + if (result != null) { + this.map.put(key, wrap(result)); + } + } + } + } catch (Exception ignore) { + } + } + } + + /** + * Put a key/boolean pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A boolean which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, boolean value) throws JSONException { + this.put(key, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONArray which is produced from a Collection. + * + * @param key + * A key string. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Collection value) throws JSONException { + this.put(key, new JSONArray(value)); + return this; + } + + /** + * Put a key/double pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A double which is the value. + * @return this. + * @throws JSONException + * If the key is null or if the number is invalid. + */ + public JSONObject put(String key, double value) throws JSONException { + this.put(key, new Double(value)); + return this; + } + + /** + * Put a key/int pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * An int which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, int value) throws JSONException { + this.put(key, new Integer(value)); + return this; + } + + /** + * Put a key/long pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A long which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, long value) throws JSONException { + this.put(key, new Long(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONObject which is produced from a Map. + * + * @param key + * A key string. + * @param value + * A Map value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Map value) throws JSONException { + this.put(key, new JSONObject(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject. If the value is null, then the + * key will be removed from the JSONObject if it is present. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is non-finite number or if the key is null. + */ + public JSONObject put(String key, Object value) throws JSONException { + String pooled; + if (key == null) { + throw new NullPointerException("Null key."); + } + if (value != null) { + testValidity(value); + pooled = (String) keyPool.get(key); + if (pooled == null) { + if (keyPool.size() >= keyPoolSize) { + keyPool = new HashMap(keyPoolSize); + } + keyPool.put(key, key); + } else { + key = pooled; + } + this.map.put(key, value); + } else { + this.remove(key); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null, and only if there is not already a member with that + * name. + * + * @param key + * @param value + * @return his. + * @throws JSONException + * if the key is a duplicate + */ + public JSONObject putOnce(String key, Object value) throws JSONException { + if (key != null && value != null) { + if (this.opt(key) != null) { + throw new JSONException("Duplicate key \"" + key + "\""); + } + this.put(key, value); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is a non-finite number. + */ + public JSONObject putOpt(String key, Object value) throws JSONException { + if (key != null && value != null) { + this.put(key, value); + } + return this; + } + + /** + * Produce a string in double quotes with backslash sequences in all the + * right places. A backslash will be inserted within = '\u0080' && c < '\u00a0') + || (c >= '\u2000' && c < '\u2100')) { + w.write("\\u"); + hhhh = Integer.toHexString(c); + w.write("0000", 0, 4 - hhhh.length()); + w.write(hhhh); + } else { + w.write(c); + } + } + } + w.write('"'); + return w; + } + + /** + * Remove a name and its value, if present. + * + * @param key + * The name to be removed. + * @return The value that was associated with the name, or null if there was + * no value. + */ + public Object remove(String key) { + return this.map.remove(key); + } + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. + * + * @param string + * A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + Double d; + if (string.equals("")) { + return string; + } + if (string.equalsIgnoreCase("true")) { + return Boolean.TRUE; + } + if (string.equalsIgnoreCase("false")) { + return Boolean.FALSE; + } + if (string.equalsIgnoreCase("null")) { + return JSONObject.NULL; + } + + /* + * If it might be a number, try converting it. If a number cannot be + * produced, then the value will just be a string. + */ + + char b = string.charAt(0); + if ((b >= '0' && b <= '9') || b == '-') { + try { + if (string.indexOf('.') > -1 || string.indexOf('e') > -1 + || string.indexOf('E') > -1) { + d = Double.valueOf(string); + if (!d.isInfinite() && !d.isNaN()) { + return d; + } + } else { + Long myLong = new Long(string); + if (string.equals(myLong.toString())) { + if (myLong.longValue() == myLong.intValue()) { + return new Integer(myLong.intValue()); + } else { + return myLong; + } + } + } + } catch (Exception ignore) { + } + } + return string; + } + + /** + * Throw an exception if the object is a NaN or infinite number. + * + * @param o + * The object to test. + * @throws JSONException + * If o is a non-finite number. + */ + public static void testValidity(Object o) throws JSONException { + if (o != null) { + if (o instanceof Double) { + if (((Double) o).isInfinite() || ((Double) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } else if (o instanceof Float) { + if (((Float) o).isInfinite() || ((Float) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } + } + } + + /** + * Produce a JSONArray containing the values of the members of this + * JSONObject. + * + * @param names + * A JSONArray containing a list of key strings. This determines + * the sequence of the values in the result. + * @return A JSONArray of values. + * @throws JSONException + * If any of the values are non-finite numbers. + */ + public JSONArray toJSONArray(JSONArray names) throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + JSONArray ja = new JSONArray(); + for (int i = 0; i < names.length(); i += 1) { + ja.put(this.opt(names.getString(i))); + } + return ja; + } + + /** + * Make a JSON text of this JSONObject. For compactness, no whitespace is + * added. If this would not result in a syntactically correct JSON text, + * then null will be returned instead. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONObject. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the object contains an invalid number. + */ + public String toString(int indentFactor) throws JSONException { + StringWriter w = new StringWriter(); + synchronized (w.getBuffer()) { + return this.write(w, indentFactor, 0).toString(); + } + } + + /** + * Make a JSON text of an Object value. If the object has an + * value.toJSONString() method, then that method will be used to produce the + * JSON text. The method is required to produce a strictly conforming text. + * If the object does not contain a toJSONString method (which is the most + * common case), then a text will be produced by other means. If the value + * is an array or Collection, then a JSONArray will be made from it and its + * toJSONString method will be called. If the value is a MAP, then a + * JSONObject will be made from it and its toJSONString method will be + * called. Otherwise, the value's toString method will be called, and the + * result will be quoted. + * + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param value + * The value to be serialized. + * @return a printable, displayable, transmittable representation of the + * object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the value is or contains an invalid number. + */ + public static String valueToString(Object value) throws JSONException { + if (value == null || value.equals(null)) { + return "null"; + } + if (value instanceof JSONString) { + Object object; + try { + object = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + if (object instanceof String) { + return (String) object; + } + throw new JSONException("Bad value from toJSONString: " + object); + } + if (value instanceof Number) { + return numberToString((Number) value); + } + if (value instanceof Boolean || value instanceof JSONObject + || value instanceof JSONArray) { + return value.toString(); + } + if (value instanceof Map) { + return new JSONObject((Map) value).toString(); + } + if (value instanceof Collection) { + return new JSONArray((Collection) value).toString(); + } + if (value.getClass().isArray()) { + return new JSONArray(value).toString(); + } + return quote(value.toString()); + } + + /** + * Wrap an object, if necessary. If the object is null, return the NULL + * object. If it is an array or collection, wrap it in a JSONArray. If it is + * a map, wrap it in a JSONObject. If it is a standard property (Double, + * String, et al) then it is already wrapped. Otherwise, if it comes from + * one of the java packages, turn it into a string. And if it doesn't, try + * to wrap it in a JSONObject. If the wrapping fails, then null is returned. + * + * @param object + * The object to wrap + * @return The wrapped value + */ + public static Object wrap(Object object) { + try { + if (object == null) { + return NULL; + } + if (object instanceof JSONObject || object instanceof JSONArray || object instanceof JSONModel + || NULL.equals(object) || object instanceof JSONString + || object instanceof Byte || object instanceof Character + || object instanceof Short || object instanceof Integer + || object instanceof Long || object instanceof Boolean + || object instanceof Float || object instanceof Double + || object instanceof String) { + return object; + } + + if (object instanceof Collection) { + return new JSONArray((Collection) object); + } + if (object.getClass().isArray()) { + return new JSONArray(object); + } + if (object instanceof Map) { + return new JSONObject((Map) object); + } + Package objectPackage = object.getClass().getPackage(); + String objectPackageName = objectPackage != null ? objectPackage + .getName() : ""; + if (objectPackageName.startsWith("java.") + || objectPackageName.startsWith("javax.") + || object.getClass().getClassLoader() == null) { + return object.toString(); + } + return new JSONObject(object); + } catch (Exception exception) { + return null; + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + static final Writer writeValue(Writer writer, Object value, + int indentFactor, int indent) throws JSONException, IOException { + if (value == null || value.equals(null)) { + writer.write("null"); + } else if (value instanceof JSONObject) { + ((JSONObject) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONArray) { + ((JSONArray) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONModel) { + ((JSONModel) value).toJsonObject().write(writer, indentFactor, indent); + } else if (value instanceof Map) { + new JSONObject((Map) value).write(writer, indentFactor, indent); + } else if (value instanceof Collection) { + new JSONArray((Collection) value).write(writer, indentFactor, + indent); + } else if (value.getClass().isArray()) { + new JSONArray(value).write(writer, indentFactor, indent); + } else if (value instanceof Number) { + writer.write(numberToString((Number) value)); + } else if (value instanceof Boolean) { + writer.write(value.toString()); + } else if (value instanceof JSONString) { + Object o; + try { + o = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + writer.write(o != null ? o.toString() : quote(value.toString())); + } else { + quote(value.toString(), writer); + } + return writer; + } + + static final void indent(Writer writer, int indent) throws IOException { + for (int i = 0; i < indent; i += 1) { + writer.write(' '); + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + final int length = this.length(); + Iterator keys = this.keys(); + writer.write('{'); + + if (length == 1) { + Object key = keys.next(); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + while (keys.hasNext()) { + Object key = keys.next(); + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, newindent); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, + newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, indent); + } + writer.write('}'); + return writer; + } catch (IOException exception) { + throw new JSONException(exception); + } + } +} diff --git a/Tubes5/Client/src/org/json/JSONString.java b/Tubes5/Client/src/org/json/JSONString.java new file mode 100644 index 00000000..1f2d77dd --- /dev/null +++ b/Tubes5/Client/src/org/json/JSONString.java @@ -0,0 +1,18 @@ +package org.json; +/** + * The JSONString interface allows a toJSONString() + * method so that a class can change the behavior of + * JSONObject.toString(), JSONArray.toString(), + * and JSONWriter.value(Object). The + * toJSONString method will be used instead of the default behavior + * of using the Object's toString() method and quoting the result. + */ +public interface JSONString { + /** + * The toJSONString method allows a class to produce its own JSON + * serialization. + * + * @return A strictly syntactically correct JSON text. + */ + public String toJSONString(); +} diff --git a/Tubes5/Client/src/org/json/JSONStringer.java b/Tubes5/Client/src/org/json/JSONStringer.java new file mode 100644 index 00000000..32c9f7f4 --- /dev/null +++ b/Tubes5/Client/src/org/json/JSONStringer.java @@ -0,0 +1,78 @@ +package org.json; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.io.StringWriter; + +/** + * JSONStringer provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONStringer can produce one JSON text. + *

+ * A JSONStringer instance provides a value method for appending + * values to the + * text, and a key + * method for adding keys before values in objects. There are array + * and endArray methods that make and bound array values, and + * object and endObject methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting cascade style. For example,

+ * myString = new JSONStringer()
+ *     .object()
+ *         .key("JSON")
+ *         .value("Hello, World!")
+ *     .endObject()
+ *     .toString();
which produces the string
+ * {"JSON":"Hello, World!"}
+ *

+ * The first method called must be array or object. + * There are no methods for adding commas or colons. JSONStringer adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + *

+ * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2008-09-18 + */ +public class JSONStringer extends JSONWriter { + /** + * Make a fresh JSONStringer. It can be used to build one JSON text. + */ + public JSONStringer() { + super(new StringWriter()); + } + + /** + * Return the JSON text. This method is used to obtain the product of the + * JSONStringer instance. It will return null if there was a + * problem in the construction of the JSON text (such as the calls to + * array were not properly balanced with calls to + * endArray). + * @return The JSON text. + */ + public String toString() { + return this.mode == 'd' ? this.writer.toString() : null; + } +} diff --git a/Tubes5/Client/src/org/json/JSONTokener.java b/Tubes5/Client/src/org/json/JSONTokener.java new file mode 100644 index 00000000..13c84f1f --- /dev/null +++ b/Tubes5/Client/src/org/json/JSONTokener.java @@ -0,0 +1,446 @@ +package org.json; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * A JSONTokener takes a source string and extracts characters and tokens from + * it. It is used by the JSONObject and JSONArray constructors to parse + * JSON source strings. + * @author JSON.org + * @version 2012-02-16 + */ +public class JSONTokener { + + private long character; + private boolean eof; + private long index; + private long line; + private char previous; + private Reader reader; + private boolean usePrevious; + + + /** + * Construct a JSONTokener from a Reader. + * + * @param reader A reader. + */ + public JSONTokener(Reader reader) { + this.reader = reader.markSupported() + ? reader + : new BufferedReader(reader); + this.eof = false; + this.usePrevious = false; + this.previous = 0; + this.index = 0; + this.character = 1; + this.line = 1; + } + + + /** + * Construct a JSONTokener from an InputStream. + */ + public JSONTokener(InputStream inputStream) throws JSONException { + this(new InputStreamReader(inputStream)); + } + + + /** + * Construct a JSONTokener from a string. + * + * @param s A source string. + */ + public JSONTokener(String s) { + this(new StringReader(s)); + } + + + /** + * Back up one character. This provides a sort of lookahead capability, + * so that you can test for a digit or letter before attempting to parse + * the next number or identifier. + */ + public void back() throws JSONException { + if (this.usePrevious || this.index <= 0) { + throw new JSONException("Stepping back two steps is not supported"); + } + this.index -= 1; + this.character -= 1; + this.usePrevious = true; + this.eof = false; + } + + + /** + * Get the hex value of a character (base16). + * @param c A character between '0' and '9' or between 'A' and 'F' or + * between 'a' and 'f'. + * @return An int between 0 and 15, or -1 if c was not a hex digit. + */ + public static int dehexchar(char c) { + if (c >= '0' && c <= '9') { + return c - '0'; + } + if (c >= 'A' && c <= 'F') { + return c - ('A' - 10); + } + if (c >= 'a' && c <= 'f') { + return c - ('a' - 10); + } + return -1; + } + + public boolean end() { + return this.eof && !this.usePrevious; + } + + + /** + * Determine if the source string still contains characters that next() + * can consume. + * @return true if not yet at the end of the source. + */ + public boolean more() throws JSONException { + this.next(); + if (this.end()) { + return false; + } + this.back(); + return true; + } + + + /** + * Get the next character in the source string. + * + * @return The next character, or 0 if past the end of the source string. + */ + public char next() throws JSONException { + int c; + if (this.usePrevious) { + this.usePrevious = false; + c = this.previous; + } else { + try { + c = this.reader.read(); + } catch (IOException exception) { + throw new JSONException(exception); + } + + if (c <= 0) { // End of stream + this.eof = true; + c = 0; + } + } + this.index += 1; + if (this.previous == '\r') { + this.line += 1; + this.character = c == '\n' ? 0 : 1; + } else if (c == '\n') { + this.line += 1; + this.character = 0; + } else { + this.character += 1; + } + this.previous = (char) c; + return this.previous; + } + + + /** + * Consume the next character, and check that it matches a specified + * character. + * @param c The character to match. + * @return The character. + * @throws JSONException if the character does not match. + */ + public char next(char c) throws JSONException { + char n = this.next(); + if (n != c) { + throw this.syntaxError("Expected '" + c + "' and instead saw '" + + n + "'"); + } + return n; + } + + + /** + * Get the next n characters. + * + * @param n The number of characters to take. + * @return A string of n characters. + * @throws JSONException + * Substring bounds error if there are not + * n characters remaining in the source string. + */ + public String next(int n) throws JSONException { + if (n == 0) { + return ""; + } + + char[] chars = new char[n]; + int pos = 0; + + while (pos < n) { + chars[pos] = this.next(); + if (this.end()) { + throw this.syntaxError("Substring bounds error"); + } + pos += 1; + } + return new String(chars); + } + + + /** + * Get the next char in the string, skipping whitespace. + * @throws JSONException + * @return A character, or 0 if there are no more characters. + */ + public char nextClean() throws JSONException { + for (;;) { + char c = this.next(); + if (c == 0 || c > ' ') { + return c; + } + } + } + + + /** + * Return the characters up to the next close quote character. + * Backslash processing is done. The formal JSON format does not + * allow strings in single quotes, but an implementation is allowed to + * accept them. + * @param quote The quoting character, either + * " (double quote) or + * ' (single quote). + * @return A String. + * @throws JSONException Unterminated string. + */ + public String nextString(char quote) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + switch (c) { + case 0: + case '\n': + case '\r': + throw this.syntaxError("Unterminated string"); + case '\\': + c = this.next(); + switch (c) { + case 'b': + sb.append('\b'); + break; + case 't': + sb.append('\t'); + break; + case 'n': + sb.append('\n'); + break; + case 'f': + sb.append('\f'); + break; + case 'r': + sb.append('\r'); + break; + case 'u': + sb.append((char)Integer.parseInt(this.next(4), 16)); + break; + case '"': + case '\'': + case '\\': + case '/': + sb.append(c); + break; + default: + throw this.syntaxError("Illegal escape."); + } + break; + default: + if (c == quote) { + return sb.toString(); + } + sb.append(c); + } + } + } + + + /** + * Get the text up but not including the specified character or the + * end of line, whichever comes first. + * @param delimiter A delimiter character. + * @return A string. + */ + public String nextTo(char delimiter) throws JSONException { + StringBuffer sb = new StringBuffer(); + for (;;) { + char c = this.next(); + if (c == delimiter || c == 0 || c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the text up but not including one of the specified delimiter + * characters or the end of line, whichever comes first. + * @param delimiters A set of delimiter characters. + * @return A string, trimmed. + */ + public String nextTo(String delimiters) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + if (delimiters.indexOf(c) >= 0 || c == 0 || + c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the next value. The value can be a Boolean, Double, Integer, + * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. + * @throws JSONException If syntax error. + * + * @return An object. + */ + public Object nextValue() throws JSONException { + char c = this.nextClean(); + String string; + + switch (c) { + case '"': + case '\'': + return this.nextString(c); + case '{': + this.back(); + return new JSONObject(this); + case '[': + this.back(); + return new JSONArray(this); + } + + /* + * Handle unquoted text. This could be the values true, false, or + * null, or it can be a number. An implementation (such as this one) + * is allowed to also accept non-standard forms. + * + * Accumulate characters until we reach the end of the text or a + * formatting character. + */ + + StringBuffer sb = new StringBuffer(); + while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { + sb.append(c); + c = this.next(); + } + this.back(); + + string = sb.toString().trim(); + if ("".equals(string)) { + throw this.syntaxError("Missing value"); + } + return JSONObject.stringToValue(string); + } + + + /** + * Skip characters until the next character is the requested character. + * If the requested character is not found, no characters are skipped. + * @param to A character to skip to. + * @return The requested character, or zero if the requested character + * is not found. + */ + public char skipTo(char to) throws JSONException { + char c; + try { + long startIndex = this.index; + long startCharacter = this.character; + long startLine = this.line; + this.reader.mark(1000000); + do { + c = this.next(); + if (c == 0) { + this.reader.reset(); + this.index = startIndex; + this.character = startCharacter; + this.line = startLine; + return c; + } + } while (c != to); + } catch (IOException exc) { + throw new JSONException(exc); + } + + this.back(); + return c; + } + + + /** + * Make a JSONException to signal a syntax error. + * + * @param message The error message. + * @return A JSONException object, suitable for throwing + */ + public JSONException syntaxError(String message) { + return new JSONException(message + this.toString()); + } + + + /** + * Make a printable string of this JSONTokener. + * + * @return " at {index} [character {character} line {line}]" + */ + public String toString() { + return " at " + this.index + " [character " + this.character + " line " + + this.line + "]"; + } +} diff --git a/Tubes5/Client/src/org/json/JSONWriter.java b/Tubes5/Client/src/org/json/JSONWriter.java new file mode 100644 index 00000000..35b60d90 --- /dev/null +++ b/Tubes5/Client/src/org/json/JSONWriter.java @@ -0,0 +1,327 @@ +package org.json; + +import java.io.IOException; +import java.io.Writer; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * JSONWriter provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONWriter can produce one JSON text. + *

+ * A JSONWriter instance provides a value method for appending + * values to the + * text, and a key + * method for adding keys before values in objects. There are array + * and endArray methods that make and bound array values, and + * object and endObject methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting a cascade style. For example,

+ * new JSONWriter(myWriter)
+ *     .object()
+ *         .key("JSON")
+ *         .value("Hello, World!")
+ *     .endObject();
which writes
+ * {"JSON":"Hello, World!"}
+ *

+ * The first method called must be array or object. + * There are no methods for adding commas or colons. JSONWriter adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + *

+ * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2011-11-24 + */ +public class JSONWriter { + private static final int maxdepth = 200; + + /** + * The comma flag determines if a comma should be output before the next + * value. + */ + private boolean comma; + + /** + * The current mode. Values: + * 'a' (array), + * 'd' (done), + * 'i' (initial), + * 'k' (key), + * 'o' (object). + */ + protected char mode; + + /** + * The object/array stack. + */ + private final JSONObject stack[]; + + /** + * The stack top index. A value of 0 indicates that the stack is empty. + */ + private int top; + + /** + * The writer that will receive the output. + */ + protected Writer writer; + + /** + * Make a fresh JSONWriter. It can be used to build one JSON text. + */ + public JSONWriter(Writer w) { + this.comma = false; + this.mode = 'i'; + this.stack = new JSONObject[maxdepth]; + this.top = 0; + this.writer = w; + } + + /** + * Append a value. + * @param string A string value. + * @return this + * @throws JSONException If the value is out of sequence. + */ + private JSONWriter append(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null pointer"); + } + if (this.mode == 'o' || this.mode == 'a') { + try { + if (this.comma && this.mode == 'a') { + this.writer.write(','); + } + this.writer.write(string); + } catch (IOException e) { + throw new JSONException(e); + } + if (this.mode == 'o') { + this.mode = 'k'; + } + this.comma = true; + return this; + } + throw new JSONException("Value out of sequence."); + } + + /** + * Begin appending a new array. All values until the balancing + * endArray will be appended to this array. The + * endArray method must be called to mark the array's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter array() throws JSONException { + if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { + this.push(null); + this.append("["); + this.comma = false; + return this; + } + throw new JSONException("Misplaced array."); + } + + /** + * End something. + * @param mode Mode + * @param c Closing character + * @return this + * @throws JSONException If unbalanced. + */ + private JSONWriter end(char mode, char c) throws JSONException { + if (this.mode != mode) { + throw new JSONException(mode == 'a' + ? "Misplaced endArray." + : "Misplaced endObject."); + } + this.pop(mode); + try { + this.writer.write(c); + } catch (IOException e) { + throw new JSONException(e); + } + this.comma = true; + return this; + } + + /** + * End an array. This method most be called to balance calls to + * array. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endArray() throws JSONException { + return this.end('a', ']'); + } + + /** + * End an object. This method most be called to balance calls to + * object. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endObject() throws JSONException { + return this.end('k', '}'); + } + + /** + * Append a key. The key will be associated with the next value. In an + * object, every value must be preceded by a key. + * @param string A key string. + * @return this + * @throws JSONException If the key is out of place. For example, keys + * do not belong in arrays or if the key is null. + */ + public JSONWriter key(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null key."); + } + if (this.mode == 'k') { + try { + this.stack[this.top - 1].putOnce(string, Boolean.TRUE); + if (this.comma) { + this.writer.write(','); + } + this.writer.write(JSONObject.quote(string)); + this.writer.write(':'); + this.comma = false; + this.mode = 'o'; + return this; + } catch (IOException e) { + throw new JSONException(e); + } + } + throw new JSONException("Misplaced key."); + } + + + /** + * Begin appending a new object. All keys and values until the balancing + * endObject will be appended to this object. The + * endObject method must be called to mark the object's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter object() throws JSONException { + if (this.mode == 'i') { + this.mode = 'o'; + } + if (this.mode == 'o' || this.mode == 'a') { + this.append("{"); + this.push(new JSONObject()); + this.comma = false; + return this; + } + throw new JSONException("Misplaced object."); + + } + + + /** + * Pop an array or object scope. + * @param c The scope to close. + * @throws JSONException If nesting is wrong. + */ + private void pop(char c) throws JSONException { + if (this.top <= 0) { + throw new JSONException("Nesting error."); + } + char m = this.stack[this.top - 1] == null ? 'a' : 'k'; + if (m != c) { + throw new JSONException("Nesting error."); + } + this.top -= 1; + this.mode = this.top == 0 + ? 'd' + : this.stack[this.top - 1] == null + ? 'a' + : 'k'; + } + + /** + * Push an array or object scope. + * @param c The scope to open. + * @throws JSONException If nesting is too deep. + */ + private void push(JSONObject jo) throws JSONException { + if (this.top >= maxdepth) { + throw new JSONException("Nesting too deep."); + } + this.stack[this.top] = jo; + this.mode = jo == null ? 'a' : 'k'; + this.top += 1; + } + + + /** + * Append either the value true or the value + * false. + * @param b A boolean. + * @return this + * @throws JSONException + */ + public JSONWriter value(boolean b) throws JSONException { + return this.append(b ? "true" : "false"); + } + + /** + * Append a double value. + * @param d A double. + * @return this + * @throws JSONException If the number is not finite. + */ + public JSONWriter value(double d) throws JSONException { + return this.value(new Double(d)); + } + + /** + * Append a long value. + * @param l A long. + * @return this + * @throws JSONException + */ + public JSONWriter value(long l) throws JSONException { + return this.append(Long.toString(l)); + } + + + /** + * Append an object value. + * @param object The object to append. It can be null, or a Boolean, Number, + * String, JSONObject, or JSONArray, or an object that implements JSONString. + * @return this + * @throws JSONException If the value is out of sequence. + */ + public JSONWriter value(Object object) throws JSONException { + return this.append(JSONObject.valueToString(object)); + } +} diff --git a/Tubes5/Server/.classpath b/Tubes5/Server/.classpath new file mode 100644 index 00000000..18d70f02 --- /dev/null +++ b/Tubes5/Server/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Tubes5/Server/.project b/Tubes5/Server/.project new file mode 100644 index 00000000..8ab3f3c3 --- /dev/null +++ b/Tubes5/Server/.project @@ -0,0 +1,17 @@ + + + Server + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Tubes5/Server/.settings/org.eclipse.jdt.core.prefs b/Tubes5/Server/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..0d534ecc --- /dev/null +++ b/Tubes5/Server/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Sat May 18 13:00:03 ICT 2013 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/Tubes5/Server/bin/Controller/ConnectionHandler.class b/Tubes5/Server/bin/Controller/ConnectionHandler.class new file mode 100644 index 00000000..3d357507 Binary files /dev/null and b/Tubes5/Server/bin/Controller/ConnectionHandler.class differ diff --git a/Tubes5/Server/bin/Controller/Controller.class b/Tubes5/Server/bin/Controller/Controller.class new file mode 100644 index 00000000..81ca91cc Binary files /dev/null and b/Tubes5/Server/bin/Controller/Controller.class differ diff --git a/Tubes5/Server/bin/Model/Task.class b/Tubes5/Server/bin/Model/Task.class new file mode 100644 index 00000000..2a06494f Binary files /dev/null and b/Tubes5/Server/bin/Model/Task.class differ diff --git a/Tubes5/Server/bin/Program.class b/Tubes5/Server/bin/Program.class new file mode 100644 index 00000000..6d8dc074 Binary files /dev/null and b/Tubes5/Server/bin/Program.class differ diff --git a/Tubes5/Server/bin/Utility/DBUtil.class b/Tubes5/Server/bin/Utility/DBUtil.class new file mode 100644 index 00000000..7b3dbdfb Binary files /dev/null and b/Tubes5/Server/bin/Utility/DBUtil.class differ diff --git a/Tubes5/Server/bin/org/json/JSONArray.class b/Tubes5/Server/bin/org/json/JSONArray.class new file mode 100644 index 00000000..34005cae Binary files /dev/null and b/Tubes5/Server/bin/org/json/JSONArray.class differ diff --git a/Tubes5/Server/bin/org/json/JSONException.class b/Tubes5/Server/bin/org/json/JSONException.class new file mode 100644 index 00000000..680b715f Binary files /dev/null and b/Tubes5/Server/bin/org/json/JSONException.class differ diff --git a/Tubes5/Server/bin/org/json/JSONModel.class b/Tubes5/Server/bin/org/json/JSONModel.class new file mode 100644 index 00000000..1e882e03 Binary files /dev/null and b/Tubes5/Server/bin/org/json/JSONModel.class differ diff --git a/Tubes5/Server/bin/org/json/JSONObject$Null.class b/Tubes5/Server/bin/org/json/JSONObject$Null.class new file mode 100644 index 00000000..9b15f605 Binary files /dev/null and b/Tubes5/Server/bin/org/json/JSONObject$Null.class differ diff --git a/Tubes5/Server/bin/org/json/JSONObject.class b/Tubes5/Server/bin/org/json/JSONObject.class new file mode 100644 index 00000000..c3fdcb63 Binary files /dev/null and b/Tubes5/Server/bin/org/json/JSONObject.class differ diff --git a/Tubes5/Server/bin/org/json/JSONString.class b/Tubes5/Server/bin/org/json/JSONString.class new file mode 100644 index 00000000..592bd20b Binary files /dev/null and b/Tubes5/Server/bin/org/json/JSONString.class differ diff --git a/Tubes5/Server/bin/org/json/JSONStringer.class b/Tubes5/Server/bin/org/json/JSONStringer.class new file mode 100644 index 00000000..6da6ae20 Binary files /dev/null and b/Tubes5/Server/bin/org/json/JSONStringer.class differ diff --git a/Tubes5/Server/bin/org/json/JSONTokener.class b/Tubes5/Server/bin/org/json/JSONTokener.class new file mode 100644 index 00000000..60dd2d01 Binary files /dev/null and b/Tubes5/Server/bin/org/json/JSONTokener.class differ diff --git a/Tubes5/Server/bin/org/json/JSONWriter.class b/Tubes5/Server/bin/org/json/JSONWriter.class new file mode 100644 index 00000000..159cb35a Binary files /dev/null and b/Tubes5/Server/bin/org/json/JSONWriter.class differ diff --git a/Tubes5/Server/src/Controller/ConnectionHandler.java b/Tubes5/Server/src/Controller/ConnectionHandler.java new file mode 100644 index 00000000..bb2fc32f --- /dev/null +++ b/Tubes5/Server/src/Controller/ConnectionHandler.java @@ -0,0 +1,330 @@ +package Controller; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.Socket; +import java.net.URL; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Random; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; + +import Model.Task; + +public class ConnectionHandler extends Thread { + + private Socket clientSocket; + private static final byte LOGIN = 0; + private static final byte SYNC = 1; + private static final byte UPDATE = 2; + private static final byte LIST = 3; + private static final byte LOGOUT = 9; + private static final byte SUCCESS = 10; + private static final byte FAILED = 11; + private static Random random = new Random(); + private HashMap session = new HashMap(); + public List task_list = new ArrayList(); + public List task_listServer = new ArrayList(); + + public ConnectionHandler(Socket clientSocket) { + this.clientSocket = clientSocket; + } + + @Override + public void run() { + long sessionId = -1; + try + { + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + while(true) + { + System.out.println("DENGERIN"); + byte msg = in.readByte(); + System.out.println("MSG = "+msg); + if (msg != LOGIN) + { + sessionId = in.readLong(); + + synchronized(session){ + if (!session.containsKey(sessionId)){ + out.write(FAILED); + clientSocket.close(); + return; + } + } + } + + if (msg == LOGIN) + { + byte[] data = new byte[in.readInt()]; + in.readFully(data); + String username = new String(data); + + data = new byte[in.readInt()]; + in.readFully(data); + String password = new String(data); + try{ + URL url = new URL("http://eurilys.ap01.aws.af.cm/user/login_check?login_username="+username+"&login_password="+password); + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + + String[] output_parts = outputObject.split(","); + String fullname = output_parts[0]; + String avatar = output_parts[1]; + + if ("failed".equals(outputObject)) { + out.writeByte(FAILED); + } else { + synchronized (session) { + long i = random.nextLong(); + while (session.containsKey(i)) { + i = random.nextLong(); + } + session.put(i, username); + out.writeByte(SUCCESS); + out.writeLong(i); + System.out.println("SESSIONID :: " + i); + } + } + } + catch (Exception e) + { + out.writeByte(FAILED); + } + } + else if (msg == SYNC) + { + int n = in.readInt(); + for (int i = 0; i < n; i++) { + byte[] data = new byte[in.readInt()]; + in.readFully(data); + String taskTemp = new String(data); + JSONObject taskObject = new JSONObject(taskTemp.toString()); + task_list.add(new Task(taskObject)); + } + + String username = session.get(sessionId); + System.out.println("LIST USERNAME :: "+ username); + URL taskURL = new URL("http://eurilys.ap01.aws.af.cm/task/all_task?username=" + username); + HttpURLConnection taskConn = (HttpURLConnection) taskURL.openConnection(); + taskConn.setRequestMethod("GET"); + taskConn.setRequestProperty("Accept", "application/json"); + if (taskConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + taskConn.getResponseCode()); + } + BufferedReader taskBr = new BufferedReader(new InputStreamReader((taskConn.getInputStream()))); + String taskOutput; + String taskJSONObject = ""; + while ((taskOutput = taskBr.readLine()) != null) { + taskJSONObject += taskOutput; + } + taskConn.disconnect(); + + JSONTokener taskTokener = new JSONTokener(taskJSONObject); + JSONArray taskroot = new JSONArray(taskTokener); + + for (int i=0; iget and opt + * methods for accessing the values by index, and put methods for + * adding or replacing values. The values can be any of these types: + * Boolean, JSONArray, JSONObject, + * Number, String, or the + * JSONObject.NULL object. + *

+ * The constructor can convert a JSON text into a Java object. The + * toString method converts to JSON text. + *

+ * A get method returns a value if one can be found, and throws an + * exception if one cannot be found. An opt method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + *

+ * The generic get() and opt() methods return an + * object which you can cast or query for type. There are also typed + * get and opt methods that do type checking and type + * coercion for you. + *

+ * The texts produced by the toString methods strictly conform to + * JSON syntax rules. The constructors are more forgiving in the texts they will + * accept: + *

    + *
  • An extra , (comma) may appear just + * before the closing bracket.
  • + *
  • The null value will be inserted when there is , + *  (comma) elision.
  • + *
  • Strings may be quoted with ' (single + * quote).
  • + *
  • Strings do not need to be quoted at all if they do not begin with a quote + * or single quote, and if they do not contain leading or trailing spaces, and + * if they do not contain any of these characters: + * { } [ ] / \ : , # and if they do not look like numbers and + * if they are not the reserved words true, false, or + * null.
  • + *
+ * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONArray { + + /** + * The arrayList where the JSONArray's properties are kept. + */ + private final ArrayList myArrayList; + + /** + * Construct an empty JSONArray. + */ + public JSONArray() { + this.myArrayList = new ArrayList(); + } + + /** + * Construct a JSONArray from a JSONTokener. + * + * @param x + * A JSONTokener + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(JSONTokener x) throws JSONException { + this(); + if (x.nextClean() != '[') { + throw x.syntaxError("A JSONArray text must start with '['"); + } + if (x.nextClean() != ']') { + x.back(); + for (;;) { + if (x.nextClean() == ',') { + x.back(); + this.myArrayList.add(JSONObject.NULL); + } else { + x.back(); + this.myArrayList.add(x.nextValue()); + } + switch (x.nextClean()) { + case ',': + if (x.nextClean() == ']') { + return; + } + x.back(); + break; + case ']': + return; + default: + throw x.syntaxError("Expected a ',' or ']'"); + } + } + } + } + + /** + * Construct a JSONArray from a source JSON text. + * + * @param source + * A string that begins with [ (left + * bracket) and ends with ] + *  (right bracket). + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONArray from a Collection. + * + * @param collection + * A Collection. + */ + public JSONArray(Collection collection) { + this.myArrayList = new ArrayList(); + if (collection != null) { + Iterator iter = collection.iterator(); + while (iter.hasNext()) { + this.myArrayList.add(JSONObject.wrap(iter.next())); + } + } + } + + /** + * Construct a JSONArray from an array + * + * @throws JSONException + * If not an array. + */ + public JSONArray(Object array) throws JSONException { + this(); + if (array.getClass().isArray()) { + int length = Array.getLength(array); + for (int i = 0; i < length; i += 1) { + this.put(JSONObject.wrap(Array.get(array, i))); + } + } else { + throw new JSONException( + "JSONArray initial value should be a string or collection or array."); + } + } + + /** + * Get the object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value. + * @throws JSONException + * If there is no value for the index. + */ + public Object get(int index) throws JSONException { + Object object = this.opt(index); + if (object == null) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with an index. The string values "true" + * and "false" are converted to boolean. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + * @throws JSONException + * If there is no value for the index or if the value is not + * convertible to boolean. + */ + public boolean getBoolean(int index) throws JSONException { + Object object = this.get(index); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONArray[" + index + "] is not a boolean."); + } + + /** + * Get the double value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public double getDouble(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the int value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value is not a number. + */ + public int getInt(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the JSONArray associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONArray value. + * @throws JSONException + * If there is no value for the index. or if the value is not a + * JSONArray + */ + public JSONArray getJSONArray(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); + } + + /** + * Get the JSONObject associated with an index. + * + * @param index + * subscript + * @return A JSONObject value. + * @throws JSONException + * If there is no value for the index or if the value is not a + * JSONObject + */ + public JSONObject getJSONObject(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); + } + + /** + * Get the long value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public long getLong(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the string associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A string value. + * @throws JSONException + * If there is no string value for the index. + */ + public String getString(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONArray[" + index + "] not a string."); + } + + /** + * Determine if the value is null. + * + * @param index + * The index must be between 0 and length() - 1. + * @return true if the value at the index is null, or if there is no value. + */ + public boolean isNull(int index) { + return JSONObject.NULL.equals(this.opt(index)); + } + + /** + * Make a string from the contents of this JSONArray. The + * separator string is inserted between each element. Warning: + * This method assumes that the data structure is acyclical. + * + * @param separator + * A string that will be inserted between the elements. + * @return a string. + * @throws JSONException + * If the array contains an invalid number. + */ + public String join(String separator) throws JSONException { + int len = this.length(); + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < len; i += 1) { + if (i > 0) { + sb.append(separator); + } + sb.append(JSONObject.valueToString(this.myArrayList.get(i))); + } + return sb.toString(); + } + + /** + * Get the number of elements in the JSONArray, included nulls. + * + * @return The length (or size). + */ + public int length() { + return this.myArrayList.size(); + } + + /** + * Get the optional object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value, or null if there is no object at that index. + */ + public Object opt(int index) { + return (index < 0 || index >= this.length()) ? null : this.myArrayList + .get(index); + } + + /** + * Get the optional boolean value associated with an index. It returns false + * if there is no value at that index, or if the value is not Boolean.TRUE + * or the String "true". + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + */ + public boolean optBoolean(int index) { + return this.optBoolean(index, false); + } + + /** + * Get the optional boolean value associated with an index. It returns the + * defaultValue if there is no value at that index or if it is not a Boolean + * or the String "true" or "false" (case insensitive). + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * A boolean default. + * @return The truth. + */ + public boolean optBoolean(int index, boolean defaultValue) { + try { + return this.getBoolean(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional double value associated with an index. NaN is returned + * if there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public double optDouble(int index) { + return this.optDouble(index, Double.NaN); + } + + /** + * Get the optional double value associated with an index. The defaultValue + * is returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * subscript + * @param defaultValue + * The default value. + * @return The value. + */ + public double optDouble(int index, double defaultValue) { + try { + return this.getDouble(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional int value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public int optInt(int index) { + return this.optInt(index, 0); + } + + /** + * Get the optional int value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public int optInt(int index, int defaultValue) { + try { + return this.getInt(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional JSONArray associated with an index. + * + * @param index + * subscript + * @return A JSONArray value, or null if the index has no value, or if the + * value is not a JSONArray. + */ + public JSONArray optJSONArray(int index) { + Object o = this.opt(index); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get the optional JSONObject associated with an index. Null is returned if + * the key is not found, or null if the index has no value, or if the value + * is not a JSONObject. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONObject value. + */ + public JSONObject optJSONObject(int index) { + Object o = this.opt(index); + return o instanceof JSONObject ? (JSONObject) o : null; + } + + /** + * Get the optional long value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public long optLong(int index) { + return this.optLong(index, 0); + } + + /** + * Get the optional long value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public long optLong(int index, long defaultValue) { + try { + return this.getLong(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional string value associated with an index. It returns an + * empty string if there is no value at that index. If the value is not a + * string and is not null, then it is coverted to a string. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A String value. + */ + public String optString(int index) { + return this.optString(index, ""); + } + + /** + * Get the optional string associated with an index. The defaultValue is + * returned if the key is not found. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return A String value. + */ + public String optString(int index, String defaultValue) { + Object object = this.opt(index); + return JSONObject.NULL.equals(object) ? defaultValue : object + .toString(); + } + + /** + * Append a boolean value. This increases the array's length by one. + * + * @param value + * A boolean value. + * @return this. + */ + public JSONArray put(boolean value) { + this.put(value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param value + * A Collection value. + * @return this. + */ + public JSONArray put(Collection value) { + this.put(new JSONArray(value)); + return this; + } + + /** + * Append a double value. This increases the array's length by one. + * + * @param value + * A double value. + * @throws JSONException + * if the value is not finite. + * @return this. + */ + public JSONArray put(double value) throws JSONException { + Double d = new Double(value); + JSONObject.testValidity(d); + this.put(d); + return this; + } + + /** + * Append an int value. This increases the array's length by one. + * + * @param value + * An int value. + * @return this. + */ + public JSONArray put(int value) { + this.put(new Integer(value)); + return this; + } + + /** + * Append an long value. This increases the array's length by one. + * + * @param value + * A long value. + * @return this. + */ + public JSONArray put(long value) { + this.put(new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject which + * is produced from a Map. + * + * @param value + * A Map value. + * @return this. + */ + public JSONArray put(Map value) { + this.put(new JSONObject(value)); + return this; + } + + /** + * Append an object value. This increases the array's length by one. + * + * @param value + * An object value. The value should be a Boolean, Double, + * Integer, JSONArray, JSONObject, Long, or String, or the + * JSONObject.NULL object. + * @return this. + */ + public JSONArray put(Object value) { + this.myArrayList.add(value); + return this; + } + + /** + * Put or replace a boolean value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * A boolean value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, boolean value) throws JSONException { + this.put(index, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param index + * The subscript. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, Collection value) throws JSONException { + this.put(index, new JSONArray(value)); + return this; + } + + /** + * Put or replace a double value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A double value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, double value) throws JSONException { + this.put(index, new Double(value)); + return this; + } + + /** + * Put or replace an int value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * An int value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, int value) throws JSONException { + this.put(index, new Integer(value)); + return this; + } + + /** + * Put or replace a long value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A long value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, long value) throws JSONException { + this.put(index, new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject that + * is produced from a Map. + * + * @param index + * The subscript. + * @param value + * The Map value. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Map value) throws JSONException { + this.put(index, new JSONObject(value)); + return this; + } + + /** + * Put or replace an object value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * The value to put into the array. The value should be a + * Boolean, Double, Integer, JSONArray, JSONObject, Long, or + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Object value) throws JSONException { + JSONObject.testValidity(value); + if (index < 0) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + if (index < this.length()) { + this.myArrayList.set(index, value); + } else { + while (index != this.length()) { + this.put(JSONObject.NULL); + } + this.put(value); + } + return this; + } + + /** + * Remove an index and close the hole. + * + * @param index + * The index of the element to be removed. + * @return The value that was associated with the index, or null if there + * was no value. + */ + public Object remove(int index) { + Object o = this.opt(index); + this.myArrayList.remove(index); + return o; + } + + /** + * Produce a JSONObject by combining a JSONArray of names with the values of + * this JSONArray. + * + * @param names + * A JSONArray containing a list of key strings. These will be + * paired with the values. + * @return A JSONObject, or null if there are no names or if this JSONArray + * has no values. + * @throws JSONException + * If any of the names are null. + */ + public JSONObject toJSONObject(JSONArray names) throws JSONException { + if (names == null || names.length() == 0 || this.length() == 0) { + return null; + } + JSONObject jo = new JSONObject(); + for (int i = 0; i < names.length(); i += 1) { + jo.put(names.getString(i), this.opt(i)); + } + return jo; + } + + /** + * Make a JSON text of this JSONArray. For compactness, no unnecessary + * whitespace is added. If it is not possible to produce a syntactically + * correct JSON text then null will be returned instead. This could occur if + * the array contains an invalid number. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, transmittable representation of the + * array. + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONArray. Warning: This method + * assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, transmittable representation of the + * object, beginning with [ (left + * bracket) and ending with ] + *  (right bracket). + * @throws JSONException + */ + public String toString(int indentFactor) throws JSONException { + StringWriter sw = new StringWriter(); + synchronized (sw.getBuffer()) { + return this.write(sw, indentFactor, 0).toString(); + } + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @param indent + * The indention of the top level. + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + int length = this.length(); + writer.write('['); + + if (length == 1) { + JSONObject.writeValue(writer, this.myArrayList.get(0), + indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + + for (int i = 0; i < length; i += 1) { + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, newindent); + JSONObject.writeValue(writer, this.myArrayList.get(i), + indentFactor, newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, indent); + } + writer.write(']'); + return writer; + } catch (IOException e) { + throw new JSONException(e); + } + } +} diff --git a/Tubes5/Server/src/org/json/JSONException.java b/Tubes5/Server/src/org/json/JSONException.java new file mode 100644 index 00000000..971547e6 --- /dev/null +++ b/Tubes5/Server/src/org/json/JSONException.java @@ -0,0 +1,41 @@ +package org.json; + +/** + * The JSONException is thrown by the JSON.org classes when things are amiss. + * + * @author JSON.org + * @version 2013-02-10 + */ +public class JSONException extends RuntimeException { + private static final long serialVersionUID = 0; + private Throwable cause; + + /** + * Constructs a JSONException with an explanatory message. + * + * @param message + * Detail about the reason for the exception. + */ + public JSONException(String message) { + super(message); + } + + /** + * Constructs a new JSONException with the specified cause. + */ + public JSONException(Throwable cause) { + super(cause.getMessage()); + this.cause = cause; + } + + /** + * Returns the cause of this exception or null if the cause is nonexistent + * or unknown. + * + * @returns the cause of this exception or null if the cause is nonexistent + * or unknown. + */ + public Throwable getCause() { + return this.cause; + } +} diff --git a/Tubes5/Server/src/org/json/JSONModel.java b/Tubes5/Server/src/org/json/JSONModel.java new file mode 100644 index 00000000..c52b04cd --- /dev/null +++ b/Tubes5/Server/src/org/json/JSONModel.java @@ -0,0 +1,7 @@ +package org.json; + +public abstract class JSONModel { + + public abstract JSONObject toJsonObject(); + public abstract void fromJsonObject(JSONObject jObject); +} diff --git a/Tubes5/Server/src/org/json/JSONObject.java b/Tubes5/Server/src/org/json/JSONObject.java new file mode 100644 index 00000000..5666eb57 --- /dev/null +++ b/Tubes5/Server/src/org/json/JSONObject.java @@ -0,0 +1,1666 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; + +/** + * A JSONObject is an unordered collection of name/value pairs. Its external + * form is a string wrapped in curly braces with colons between the names and + * values, and commas between the values and names. The internal form is an + * object having get and opt methods for accessing + * the values by name, and put methods for adding or replacing + * values by name. The values can be any of these types: Boolean, + * JSONArray, JSONObject, Number, + * String, or the JSONObject.NULL object. A + * JSONObject constructor can be used to convert an external form JSON text + * into an internal form whose values can be retrieved with the + * get and opt methods, or to convert values into a + * JSON text using the put and toString methods. A + * get method returns a value if one can be found, and throws an + * exception if one cannot be found. An opt method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + *

+ * The generic get() and opt() methods return an + * object, which you can cast or query for type. There are also typed + * get and opt methods that do type checking and type + * coercion for you. The opt methods differ from the get methods in that they + * do not throw. Instead, they return a specified value, such as null. + *

+ * The put methods add or replace values in an object. For + * example, + * + *

+ * myString = new JSONObject()
+ *         .put("JSON", "Hello, World!").toString();
+ * 
+ * + * produces the string {"JSON": "Hello, World"}. + *

+ * The texts produced by the toString methods strictly conform to + * the JSON syntax rules. The constructors are more forgiving in the texts they + * will accept: + *

    + *
  • An extra , (comma) may appear just + * before the closing brace.
  • + *
  • Strings may be quoted with ' (single + * quote).
  • + *
  • Strings do not need to be quoted at all if they do not begin with a + * quote or single quote, and if they do not contain leading or trailing + * spaces, and if they do not contain any of these characters: + * { } [ ] / \ : , # and if they do not look like numbers and + * if they are not the reserved words true, false, + * or null.
  • + *
+ * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONObject { + /** + * The maximum number of keys in the key pool. + */ + private static final int keyPoolSize = 100; + + /** + * Key pooling is like string interning, but without permanently tying up + * memory. To help conserve memory, storage of duplicated key strings in + * JSONObjects will be avoided by using a key pool to manage unique key + * string objects. This is used by JSONObject.put(string, object). + */ + private static HashMap keyPool = new HashMap(keyPoolSize); + + /** + * JSONObject.NULL is equivalent to the value that JavaScript calls null, + * whilst Java's null is equivalent to the value that JavaScript calls + * undefined. + */ + private static final class Null { + + /** + * There is only intended to be a single instance of the NULL object, + * so the clone method returns itself. + * + * @return NULL. + */ + protected final Object clone() { + return this; + } + + /** + * A Null object is equal to the null value and to itself. + * + * @param object + * An object to test for nullness. + * @return true if the object parameter is the JSONObject.NULL object or + * null. + */ + public boolean equals(Object object) { + return object == null || object == this; + } + + /** + * Get the "null" string value. + * + * @return The string "null". + */ + public String toString() { + return "null"; + } + } + + /** + * The map where the JSONObject's properties are kept. + */ + private final Map map; + + /** + * It is sometimes more convenient and less ambiguous to have a + * NULL object than to use Java's null value. + * JSONObject.NULL.equals(null) returns true. + * JSONObject.NULL.toString() returns "null". + */ + public static final Object NULL = new Null(); + + /** + * Construct an empty JSONObject. + */ + public JSONObject() { + this.map = new HashMap(); + } + + /** + * Construct a JSONObject from a subset of another JSONObject. An array of + * strings is used to identify the keys that should be copied. Missing keys + * are ignored. + * + * @param jo + * A JSONObject. + * @param names + * An array of strings. + * @throws JSONException + * @exception JSONException + * If a value is a non-finite number or if a name is + * duplicated. + */ + public JSONObject(JSONObject jo, String[] names) { + this(); + for (int i = 0; i < names.length; i += 1) { + try { + this.putOnce(names[i], jo.opt(names[i])); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a JSONTokener. + * + * @param x + * A JSONTokener object containing the source string. + * @throws JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(JSONTokener x) throws JSONException { + this(); + char c; + String key; + + if (x.nextClean() != '{') { + throw x.syntaxError("A JSONObject text must begin with '{'"); + } + for (;;) { + c = x.nextClean(); + switch (c) { + case 0: + throw x.syntaxError("A JSONObject text must end with '}'"); + case '}': + return; + default: + x.back(); + key = x.nextValue().toString(); + } + +// The key is followed by ':'. + + c = x.nextClean(); + if (c != ':') { + throw x.syntaxError("Expected a ':' after a key"); + } + this.putOnce(key, x.nextValue()); + +// Pairs are separated by ','. + + switch (x.nextClean()) { + case ';': + case ',': + if (x.nextClean() == '}') { + return; + } + x.back(); + break; + case '}': + return; + default: + throw x.syntaxError("Expected a ',' or '}'"); + } + } + } + + /** + * Construct a JSONObject from a Map. + * + * @param map + * A map object that can be used to initialize the contents of + * the JSONObject. + * @throws JSONException + */ + public JSONObject(Map map) { + this.map = new HashMap(); + if (map != null) { + Iterator i = map.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry e = (Map.Entry) i.next(); + Object value = e.getValue(); + if (value != null) { + this.map.put(e.getKey(), wrap(value)); + } + } + } + } + + /** + * Construct a JSONObject from an Object using bean getters. It reflects on + * all of the public methods of the object. For each of the methods with no + * parameters and a name starting with "get" or + * "is" followed by an uppercase letter, the method is invoked, + * and a key and the value returned from the getter method are put into the + * new JSONObject. + * + * The key is formed by removing the "get" or "is" + * prefix. If the second remaining character is not upper case, then the + * first character is converted to lower case. + * + * For example, if an object has a method named "getName", and + * if the result of calling object.getName() is + * "Larry Fine", then the JSONObject will contain + * "name": "Larry Fine". + * + * @param bean + * An object that has getter methods that should be used to make + * a JSONObject. + */ + public JSONObject(Object bean) { + this(); + this.populateMap(bean); + } + + /** + * Construct a JSONObject from an Object, using reflection to find the + * public members. The resulting JSONObject's keys will be the strings from + * the names array, and the values will be the field values associated with + * those keys in the object. If a key is not found or not visible, then it + * will not be copied into the new JSONObject. + * + * @param object + * An object that has fields that should be used to make a + * JSONObject. + * @param names + * An array of strings, the names of the fields to be obtained + * from the object. + */ + public JSONObject(Object object, String names[]) { + this(); + Class c = object.getClass(); + for (int i = 0; i < names.length; i += 1) { + String name = names[i]; + try { + this.putOpt(name, c.getField(name).get(object)); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a source JSON text string. This is the most + * commonly used JSONObject constructor. + * + * @param source + * A string beginning with { (left + * brace) and ending with } + *  (right brace). + * @exception JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONObject from a ResourceBundle. + * + * @param baseName + * The ResourceBundle base name. + * @param locale + * The Locale to load the ResourceBundle for. + * @throws JSONException + * If any JSONExceptions are detected. + */ + public JSONObject(String baseName, Locale locale) throws JSONException { + this(); + ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, + Thread.currentThread().getContextClassLoader()); + +// Iterate through the keys in the bundle. + + Enumeration keys = bundle.getKeys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + if (key instanceof String) { + +// Go through the path, ensuring that there is a nested JSONObject for each +// segment except the last. Add the value using the last segment's name into +// the deepest nested JSONObject. + + String[] path = ((String) key).split("\\."); + int last = path.length - 1; + JSONObject target = this; + for (int i = 0; i < last; i += 1) { + String segment = path[i]; + JSONObject nextTarget = target.optJSONObject(segment); + if (nextTarget == null) { + nextTarget = new JSONObject(); + target.put(segment, nextTarget); + } + target = nextTarget; + } + target.put(path[last], bundle.getString((String) key)); + } + } + } + + /** + * Accumulate values under a key. It is similar to the put method except + * that if there is already an object stored under the key then a JSONArray + * is stored under the key to hold all of the accumulated values. If there + * is already a JSONArray, then the new value is appended to it. In + * contrast, the put method replaces the previous value. + * + * If only one value is accumulated that is not a JSONArray, then the result + * will be the same as using put. But if multiple values are accumulated, + * then the result will be like append. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the value is an invalid number or if the key is null. + */ + public JSONObject accumulate(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, + value instanceof JSONArray ? new JSONArray().put(value) + : value); + } else if (object instanceof JSONArray) { + ((JSONArray) object).put(value); + } else { + this.put(key, new JSONArray().put(object).put(value)); + } + return this; + } + + /** + * Append values to the array under a key. If the key does not exist in the + * JSONObject, then the key is put in the JSONObject with its value being a + * JSONArray containing the value parameter. If the key was already + * associated with a JSONArray, then the value parameter is appended to it. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the key is null or if the current value associated with + * the key is not a JSONArray. + */ + public JSONObject append(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, new JSONArray().put(value)); + } else if (object instanceof JSONArray) { + this.put(key, ((JSONArray) object).put(value)); + } else { + throw new JSONException("JSONObject[" + key + + "] is not a JSONArray."); + } + return this; + } + + /** + * Produce a string from a double. The string "null" will be returned if the + * number is not finite. + * + * @param d + * A double. + * @return A String. + */ + public static String doubleToString(double d) { + if (Double.isInfinite(d) || Double.isNaN(d)) { + return "null"; + } + +// Shave off trailing zeros and decimal point, if possible. + + String string = Double.toString(d); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get the value object associated with a key. + * + * @param key + * A key string. + * @return The object associated with the key. + * @throws JSONException + * if the key is not found. + */ + public Object get(String key) throws JSONException { + if (key == null) { + throw new JSONException("Null key."); + } + Object object = this.opt(key); + if (object == null) { + throw new JSONException("JSONObject[" + quote(key) + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with a key. + * + * @param key + * A key string. + * @return The truth. + * @throws JSONException + * if the value is not a Boolean or the String "true" or + * "false". + */ + public boolean getBoolean(String key) throws JSONException { + Object object = this.get(key); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a Boolean."); + } + + /** + * Get the double value associated with a key. + * + * @param key + * A key string. + * @return The numeric value. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. + */ + public double getDouble(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a number."); + } + } + + /** + * Get the int value associated with a key. + * + * @param key + * A key string. + * @return The integer value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to an integer. + */ + public int getInt(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not an int."); + } + } + + /** + * Get the JSONArray value associated with a key. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONArray. + */ + public JSONArray getJSONArray(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONArray."); + } + + /** + * Get the JSONObject value associated with a key. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONObject. + */ + public JSONObject getJSONObject(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONObject."); + } + + /** + * Get the long value associated with a key. + * + * @param key + * A key string. + * @return The long value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to a long. + */ + public long getLong(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a long."); + } + } + + /** + * Get an array of field names from a JSONObject. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(JSONObject jo) { + int length = jo.length(); + if (length == 0) { + return null; + } + Iterator iterator = jo.keys(); + String[] names = new String[length]; + int i = 0; + while (iterator.hasNext()) { + names[i] = (String) iterator.next(); + i += 1; + } + return names; + } + + /** + * Get an array of field names from an Object. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(Object object) { + if (object == null) { + return null; + } + Class klass = object.getClass(); + Field[] fields = klass.getFields(); + int length = fields.length; + if (length == 0) { + return null; + } + String[] names = new String[length]; + for (int i = 0; i < length; i += 1) { + names[i] = fields[i].getName(); + } + return names; + } + + /** + * Get the string associated with a key. + * + * @param key + * A key string. + * @return A string which is the value. + * @throws JSONException + * if there is no string value for the key. + */ + public String getString(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONObject[" + quote(key) + "] not a string."); + } + + /** + * Determine if the JSONObject contains a specific key. + * + * @param key + * A key string. + * @return true if the key exists in the JSONObject. + */ + public boolean has(String key) { + return this.map.containsKey(key); + } + + /** + * Increment a property of a JSONObject. If there is no such property, + * create one with a value of 1. If there is such a property, and if it is + * an Integer, Long, Double, or Float, then add one to it. + * + * @param key + * A key string. + * @return this. + * @throws JSONException + * If there is already a property with this name that is not an + * Integer, Long, Double, or Float. + */ + public JSONObject increment(String key) throws JSONException { + Object value = this.opt(key); + if (value == null) { + this.put(key, 1); + } else if (value instanceof Integer) { + this.put(key, ((Integer) value).intValue() + 1); + } else if (value instanceof Long) { + this.put(key, ((Long) value).longValue() + 1); + } else if (value instanceof Double) { + this.put(key, ((Double) value).doubleValue() + 1); + } else if (value instanceof Float) { + this.put(key, ((Float) value).floatValue() + 1); + } else { + throw new JSONException("Unable to increment [" + quote(key) + "]."); + } + return this; + } + + /** + * Determine if the value associated with the key is null or if there is no + * value. + * + * @param key + * A key string. + * @return true if there is no value associated with the key or if the value + * is the JSONObject.NULL object. + */ + public boolean isNull(String key) { + return JSONObject.NULL.equals(this.opt(key)); + } + + /** + * Get an enumeration of the keys of the JSONObject. + * + * @return An iterator of the keys. + */ + public Iterator keys() { + return this.keySet().iterator(); + } + + /** + * Get a set of keys of the JSONObject. + * + * @return A keySet. + */ + public Set keySet() { + return this.map.keySet(); + } + + /** + * Get the number of keys stored in the JSONObject. + * + * @return The number of keys in the JSONObject. + */ + public int length() { + return this.map.size(); + } + + /** + * Produce a JSONArray containing the names of the elements of this + * JSONObject. + * + * @return A JSONArray containing the key strings, or null if the JSONObject + * is empty. + */ + public JSONArray names() { + JSONArray ja = new JSONArray(); + Iterator keys = this.keys(); + while (keys.hasNext()) { + ja.put(keys.next()); + } + return ja.length() == 0 ? null : ja; + } + + /** + * Produce a string from a Number. + * + * @param number + * A Number + * @return A String. + * @throws JSONException + * If n is a non-finite number. + */ + public static String numberToString(Number number) throws JSONException { + if (number == null) { + throw new JSONException("Null pointer"); + } + testValidity(number); + +// Shave off trailing zeros and decimal point, if possible. + + String string = number.toString(); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get an optional value associated with a key. + * + * @param key + * A key string. + * @return An object which is the value, or null if there is no value. + */ + public Object opt(String key) { + return key == null ? null : this.map.get(key); + } + + /** + * Get an optional boolean associated with a key. It returns false if there + * is no such key, or if the value is not Boolean.TRUE or the String "true". + * + * @param key + * A key string. + * @return The truth. + */ + public boolean optBoolean(String key) { + return this.optBoolean(key, false); + } + + /** + * Get an optional boolean associated with a key. It returns the + * defaultValue if there is no such key, or if it is not a Boolean or the + * String "true" or "false" (case insensitive). + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return The truth. + */ + public boolean optBoolean(String key, boolean defaultValue) { + try { + return this.getBoolean(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional double associated with a key, or NaN if there is no such + * key or if its value is not a number. If the value is a string, an attempt + * will be made to evaluate it as a number. + * + * @param key + * A string which is the key. + * @return An object which is the value. + */ + public double optDouble(String key) { + return this.optDouble(key, Double.NaN); + } + + /** + * Get an optional double associated with a key, or the defaultValue if + * there is no such key or if its value is not a number. If the value is a + * string, an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public double optDouble(String key, double defaultValue) { + try { + return this.getDouble(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional int value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public int optInt(String key) { + return this.optInt(key, 0); + } + + /** + * Get an optional int value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public int optInt(String key, int defaultValue) { + try { + return this.getInt(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional JSONArray associated with a key. It returns null if there + * is no such key, or if its value is not a JSONArray. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + */ + public JSONArray optJSONArray(String key) { + Object o = this.opt(key); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get an optional JSONObject associated with a key. It returns null if + * there is no such key, or if its value is not a JSONObject. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + */ + public JSONObject optJSONObject(String key) { + Object object = this.opt(key); + return object instanceof JSONObject ? (JSONObject) object : null; + } + + /** + * Get an optional long value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public long optLong(String key) { + return this.optLong(key, 0); + } + + /** + * Get an optional long value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public long optLong(String key, long defaultValue) { + try { + return this.getLong(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional string associated with a key. It returns an empty string + * if there is no such key. If the value is not a string and is not null, + * then it is converted to a string. + * + * @param key + * A key string. + * @return A string which is the value. + */ + public String optString(String key) { + return this.optString(key, ""); + } + + /** + * Get an optional string associated with a key. It returns the defaultValue + * if there is no such key. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return A string which is the value. + */ + public String optString(String key, String defaultValue) { + Object object = this.opt(key); + return NULL.equals(object) ? defaultValue : object.toString(); + } + + private void populateMap(Object bean) { + Class klass = bean.getClass(); + +// If klass is a System class then set includeSuperClass to false. + + boolean includeSuperClass = klass.getClassLoader() != null; + + Method[] methods = includeSuperClass ? klass.getMethods() : klass + .getDeclaredMethods(); + for (int i = 0; i < methods.length; i += 1) { + try { + Method method = methods[i]; + if (Modifier.isPublic(method.getModifiers())) { + String name = method.getName(); + String key = ""; + if (name.startsWith("get")) { + if ("getClass".equals(name) + || "getDeclaringClass".equals(name)) { + key = ""; + } else { + key = name.substring(3); + } + } else if (name.startsWith("is")) { + key = name.substring(2); + } + if (key.length() > 0 + && Character.isUpperCase(key.charAt(0)) + && method.getParameterTypes().length == 0) { + if (key.length() == 1) { + key = key.toLowerCase(); + } else if (!Character.isUpperCase(key.charAt(1))) { + key = key.substring(0, 1).toLowerCase() + + key.substring(1); + } + + Object result = method.invoke(bean, (Object[]) null); + if (result != null) { + this.map.put(key, wrap(result)); + } + } + } + } catch (Exception ignore) { + } + } + } + + /** + * Put a key/boolean pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A boolean which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, boolean value) throws JSONException { + this.put(key, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONArray which is produced from a Collection. + * + * @param key + * A key string. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Collection value) throws JSONException { + this.put(key, new JSONArray(value)); + return this; + } + + /** + * Put a key/double pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A double which is the value. + * @return this. + * @throws JSONException + * If the key is null or if the number is invalid. + */ + public JSONObject put(String key, double value) throws JSONException { + this.put(key, new Double(value)); + return this; + } + + /** + * Put a key/int pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * An int which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, int value) throws JSONException { + this.put(key, new Integer(value)); + return this; + } + + /** + * Put a key/long pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A long which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, long value) throws JSONException { + this.put(key, new Long(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONObject which is produced from a Map. + * + * @param key + * A key string. + * @param value + * A Map value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Map value) throws JSONException { + this.put(key, new JSONObject(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject. If the value is null, then the + * key will be removed from the JSONObject if it is present. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is non-finite number or if the key is null. + */ + public JSONObject put(String key, Object value) throws JSONException { + String pooled; + if (key == null) { + throw new NullPointerException("Null key."); + } + if (value != null) { + testValidity(value); + pooled = (String) keyPool.get(key); + if (pooled == null) { + if (keyPool.size() >= keyPoolSize) { + keyPool = new HashMap(keyPoolSize); + } + keyPool.put(key, key); + } else { + key = pooled; + } + this.map.put(key, value); + } else { + this.remove(key); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null, and only if there is not already a member with that + * name. + * + * @param key + * @param value + * @return his. + * @throws JSONException + * if the key is a duplicate + */ + public JSONObject putOnce(String key, Object value) throws JSONException { + if (key != null && value != null) { + if (this.opt(key) != null) { + throw new JSONException("Duplicate key \"" + key + "\""); + } + this.put(key, value); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is a non-finite number. + */ + public JSONObject putOpt(String key, Object value) throws JSONException { + if (key != null && value != null) { + this.put(key, value); + } + return this; + } + + /** + * Produce a string in double quotes with backslash sequences in all the + * right places. A backslash will be inserted within = '\u0080' && c < '\u00a0') + || (c >= '\u2000' && c < '\u2100')) { + w.write("\\u"); + hhhh = Integer.toHexString(c); + w.write("0000", 0, 4 - hhhh.length()); + w.write(hhhh); + } else { + w.write(c); + } + } + } + w.write('"'); + return w; + } + + /** + * Remove a name and its value, if present. + * + * @param key + * The name to be removed. + * @return The value that was associated with the name, or null if there was + * no value. + */ + public Object remove(String key) { + return this.map.remove(key); + } + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. + * + * @param string + * A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + Double d; + if (string.equals("")) { + return string; + } + if (string.equalsIgnoreCase("true")) { + return Boolean.TRUE; + } + if (string.equalsIgnoreCase("false")) { + return Boolean.FALSE; + } + if (string.equalsIgnoreCase("null")) { + return JSONObject.NULL; + } + + /* + * If it might be a number, try converting it. If a number cannot be + * produced, then the value will just be a string. + */ + + char b = string.charAt(0); + if ((b >= '0' && b <= '9') || b == '-') { + try { + if (string.indexOf('.') > -1 || string.indexOf('e') > -1 + || string.indexOf('E') > -1) { + d = Double.valueOf(string); + if (!d.isInfinite() && !d.isNaN()) { + return d; + } + } else { + Long myLong = new Long(string); + if (string.equals(myLong.toString())) { + if (myLong.longValue() == myLong.intValue()) { + return new Integer(myLong.intValue()); + } else { + return myLong; + } + } + } + } catch (Exception ignore) { + } + } + return string; + } + + /** + * Throw an exception if the object is a NaN or infinite number. + * + * @param o + * The object to test. + * @throws JSONException + * If o is a non-finite number. + */ + public static void testValidity(Object o) throws JSONException { + if (o != null) { + if (o instanceof Double) { + if (((Double) o).isInfinite() || ((Double) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } else if (o instanceof Float) { + if (((Float) o).isInfinite() || ((Float) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } + } + } + + /** + * Produce a JSONArray containing the values of the members of this + * JSONObject. + * + * @param names + * A JSONArray containing a list of key strings. This determines + * the sequence of the values in the result. + * @return A JSONArray of values. + * @throws JSONException + * If any of the values are non-finite numbers. + */ + public JSONArray toJSONArray(JSONArray names) throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + JSONArray ja = new JSONArray(); + for (int i = 0; i < names.length(); i += 1) { + ja.put(this.opt(names.getString(i))); + } + return ja; + } + + /** + * Make a JSON text of this JSONObject. For compactness, no whitespace is + * added. If this would not result in a syntactically correct JSON text, + * then null will be returned instead. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONObject. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the object contains an invalid number. + */ + public String toString(int indentFactor) throws JSONException { + StringWriter w = new StringWriter(); + synchronized (w.getBuffer()) { + return this.write(w, indentFactor, 0).toString(); + } + } + + /** + * Make a JSON text of an Object value. If the object has an + * value.toJSONString() method, then that method will be used to produce the + * JSON text. The method is required to produce a strictly conforming text. + * If the object does not contain a toJSONString method (which is the most + * common case), then a text will be produced by other means. If the value + * is an array or Collection, then a JSONArray will be made from it and its + * toJSONString method will be called. If the value is a MAP, then a + * JSONObject will be made from it and its toJSONString method will be + * called. Otherwise, the value's toString method will be called, and the + * result will be quoted. + * + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param value + * The value to be serialized. + * @return a printable, displayable, transmittable representation of the + * object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the value is or contains an invalid number. + */ + public static String valueToString(Object value) throws JSONException { + if (value == null || value.equals(null)) { + return "null"; + } + if (value instanceof JSONString) { + Object object; + try { + object = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + if (object instanceof String) { + return (String) object; + } + throw new JSONException("Bad value from toJSONString: " + object); + } + if (value instanceof Number) { + return numberToString((Number) value); + } + if (value instanceof Boolean || value instanceof JSONObject + || value instanceof JSONArray) { + return value.toString(); + } + if (value instanceof Map) { + return new JSONObject((Map) value).toString(); + } + if (value instanceof Collection) { + return new JSONArray((Collection) value).toString(); + } + if (value.getClass().isArray()) { + return new JSONArray(value).toString(); + } + return quote(value.toString()); + } + + /** + * Wrap an object, if necessary. If the object is null, return the NULL + * object. If it is an array or collection, wrap it in a JSONArray. If it is + * a map, wrap it in a JSONObject. If it is a standard property (Double, + * String, et al) then it is already wrapped. Otherwise, if it comes from + * one of the java packages, turn it into a string. And if it doesn't, try + * to wrap it in a JSONObject. If the wrapping fails, then null is returned. + * + * @param object + * The object to wrap + * @return The wrapped value + */ + public static Object wrap(Object object) { + try { + if (object == null) { + return NULL; + } + if (object instanceof JSONObject || object instanceof JSONArray || object instanceof JSONModel + || NULL.equals(object) || object instanceof JSONString + || object instanceof Byte || object instanceof Character + || object instanceof Short || object instanceof Integer + || object instanceof Long || object instanceof Boolean + || object instanceof Float || object instanceof Double + || object instanceof String) { + return object; + } + + if (object instanceof Collection) { + return new JSONArray((Collection) object); + } + if (object.getClass().isArray()) { + return new JSONArray(object); + } + if (object instanceof Map) { + return new JSONObject((Map) object); + } + Package objectPackage = object.getClass().getPackage(); + String objectPackageName = objectPackage != null ? objectPackage + .getName() : ""; + if (objectPackageName.startsWith("java.") + || objectPackageName.startsWith("javax.") + || object.getClass().getClassLoader() == null) { + return object.toString(); + } + return new JSONObject(object); + } catch (Exception exception) { + return null; + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + static final Writer writeValue(Writer writer, Object value, + int indentFactor, int indent) throws JSONException, IOException { + if (value == null || value.equals(null)) { + writer.write("null"); + } else if (value instanceof JSONObject) { + ((JSONObject) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONArray) { + ((JSONArray) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONModel) { + ((JSONModel) value).toJsonObject().write(writer, indentFactor, indent); + } else if (value instanceof Map) { + new JSONObject((Map) value).write(writer, indentFactor, indent); + } else if (value instanceof Collection) { + new JSONArray((Collection) value).write(writer, indentFactor, + indent); + } else if (value.getClass().isArray()) { + new JSONArray(value).write(writer, indentFactor, indent); + } else if (value instanceof Number) { + writer.write(numberToString((Number) value)); + } else if (value instanceof Boolean) { + writer.write(value.toString()); + } else if (value instanceof JSONString) { + Object o; + try { + o = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + writer.write(o != null ? o.toString() : quote(value.toString())); + } else { + quote(value.toString(), writer); + } + return writer; + } + + static final void indent(Writer writer, int indent) throws IOException { + for (int i = 0; i < indent; i += 1) { + writer.write(' '); + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + final int length = this.length(); + Iterator keys = this.keys(); + writer.write('{'); + + if (length == 1) { + Object key = keys.next(); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + while (keys.hasNext()) { + Object key = keys.next(); + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, newindent); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, + newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, indent); + } + writer.write('}'); + return writer; + } catch (IOException exception) { + throw new JSONException(exception); + } + } +} diff --git a/Tubes5/Server/src/org/json/JSONString.java b/Tubes5/Server/src/org/json/JSONString.java new file mode 100644 index 00000000..1f2d77dd --- /dev/null +++ b/Tubes5/Server/src/org/json/JSONString.java @@ -0,0 +1,18 @@ +package org.json; +/** + * The JSONString interface allows a toJSONString() + * method so that a class can change the behavior of + * JSONObject.toString(), JSONArray.toString(), + * and JSONWriter.value(Object). The + * toJSONString method will be used instead of the default behavior + * of using the Object's toString() method and quoting the result. + */ +public interface JSONString { + /** + * The toJSONString method allows a class to produce its own JSON + * serialization. + * + * @return A strictly syntactically correct JSON text. + */ + public String toJSONString(); +} diff --git a/Tubes5/Server/src/org/json/JSONStringer.java b/Tubes5/Server/src/org/json/JSONStringer.java new file mode 100644 index 00000000..32c9f7f4 --- /dev/null +++ b/Tubes5/Server/src/org/json/JSONStringer.java @@ -0,0 +1,78 @@ +package org.json; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.io.StringWriter; + +/** + * JSONStringer provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONStringer can produce one JSON text. + *

+ * A JSONStringer instance provides a value method for appending + * values to the + * text, and a key + * method for adding keys before values in objects. There are array + * and endArray methods that make and bound array values, and + * object and endObject methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting cascade style. For example,

+ * myString = new JSONStringer()
+ *     .object()
+ *         .key("JSON")
+ *         .value("Hello, World!")
+ *     .endObject()
+ *     .toString();
which produces the string
+ * {"JSON":"Hello, World!"}
+ *

+ * The first method called must be array or object. + * There are no methods for adding commas or colons. JSONStringer adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + *

+ * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2008-09-18 + */ +public class JSONStringer extends JSONWriter { + /** + * Make a fresh JSONStringer. It can be used to build one JSON text. + */ + public JSONStringer() { + super(new StringWriter()); + } + + /** + * Return the JSON text. This method is used to obtain the product of the + * JSONStringer instance. It will return null if there was a + * problem in the construction of the JSON text (such as the calls to + * array were not properly balanced with calls to + * endArray). + * @return The JSON text. + */ + public String toString() { + return this.mode == 'd' ? this.writer.toString() : null; + } +} diff --git a/Tubes5/Server/src/org/json/JSONTokener.java b/Tubes5/Server/src/org/json/JSONTokener.java new file mode 100644 index 00000000..13c84f1f --- /dev/null +++ b/Tubes5/Server/src/org/json/JSONTokener.java @@ -0,0 +1,446 @@ +package org.json; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * A JSONTokener takes a source string and extracts characters and tokens from + * it. It is used by the JSONObject and JSONArray constructors to parse + * JSON source strings. + * @author JSON.org + * @version 2012-02-16 + */ +public class JSONTokener { + + private long character; + private boolean eof; + private long index; + private long line; + private char previous; + private Reader reader; + private boolean usePrevious; + + + /** + * Construct a JSONTokener from a Reader. + * + * @param reader A reader. + */ + public JSONTokener(Reader reader) { + this.reader = reader.markSupported() + ? reader + : new BufferedReader(reader); + this.eof = false; + this.usePrevious = false; + this.previous = 0; + this.index = 0; + this.character = 1; + this.line = 1; + } + + + /** + * Construct a JSONTokener from an InputStream. + */ + public JSONTokener(InputStream inputStream) throws JSONException { + this(new InputStreamReader(inputStream)); + } + + + /** + * Construct a JSONTokener from a string. + * + * @param s A source string. + */ + public JSONTokener(String s) { + this(new StringReader(s)); + } + + + /** + * Back up one character. This provides a sort of lookahead capability, + * so that you can test for a digit or letter before attempting to parse + * the next number or identifier. + */ + public void back() throws JSONException { + if (this.usePrevious || this.index <= 0) { + throw new JSONException("Stepping back two steps is not supported"); + } + this.index -= 1; + this.character -= 1; + this.usePrevious = true; + this.eof = false; + } + + + /** + * Get the hex value of a character (base16). + * @param c A character between '0' and '9' or between 'A' and 'F' or + * between 'a' and 'f'. + * @return An int between 0 and 15, or -1 if c was not a hex digit. + */ + public static int dehexchar(char c) { + if (c >= '0' && c <= '9') { + return c - '0'; + } + if (c >= 'A' && c <= 'F') { + return c - ('A' - 10); + } + if (c >= 'a' && c <= 'f') { + return c - ('a' - 10); + } + return -1; + } + + public boolean end() { + return this.eof && !this.usePrevious; + } + + + /** + * Determine if the source string still contains characters that next() + * can consume. + * @return true if not yet at the end of the source. + */ + public boolean more() throws JSONException { + this.next(); + if (this.end()) { + return false; + } + this.back(); + return true; + } + + + /** + * Get the next character in the source string. + * + * @return The next character, or 0 if past the end of the source string. + */ + public char next() throws JSONException { + int c; + if (this.usePrevious) { + this.usePrevious = false; + c = this.previous; + } else { + try { + c = this.reader.read(); + } catch (IOException exception) { + throw new JSONException(exception); + } + + if (c <= 0) { // End of stream + this.eof = true; + c = 0; + } + } + this.index += 1; + if (this.previous == '\r') { + this.line += 1; + this.character = c == '\n' ? 0 : 1; + } else if (c == '\n') { + this.line += 1; + this.character = 0; + } else { + this.character += 1; + } + this.previous = (char) c; + return this.previous; + } + + + /** + * Consume the next character, and check that it matches a specified + * character. + * @param c The character to match. + * @return The character. + * @throws JSONException if the character does not match. + */ + public char next(char c) throws JSONException { + char n = this.next(); + if (n != c) { + throw this.syntaxError("Expected '" + c + "' and instead saw '" + + n + "'"); + } + return n; + } + + + /** + * Get the next n characters. + * + * @param n The number of characters to take. + * @return A string of n characters. + * @throws JSONException + * Substring bounds error if there are not + * n characters remaining in the source string. + */ + public String next(int n) throws JSONException { + if (n == 0) { + return ""; + } + + char[] chars = new char[n]; + int pos = 0; + + while (pos < n) { + chars[pos] = this.next(); + if (this.end()) { + throw this.syntaxError("Substring bounds error"); + } + pos += 1; + } + return new String(chars); + } + + + /** + * Get the next char in the string, skipping whitespace. + * @throws JSONException + * @return A character, or 0 if there are no more characters. + */ + public char nextClean() throws JSONException { + for (;;) { + char c = this.next(); + if (c == 0 || c > ' ') { + return c; + } + } + } + + + /** + * Return the characters up to the next close quote character. + * Backslash processing is done. The formal JSON format does not + * allow strings in single quotes, but an implementation is allowed to + * accept them. + * @param quote The quoting character, either + * " (double quote) or + * ' (single quote). + * @return A String. + * @throws JSONException Unterminated string. + */ + public String nextString(char quote) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + switch (c) { + case 0: + case '\n': + case '\r': + throw this.syntaxError("Unterminated string"); + case '\\': + c = this.next(); + switch (c) { + case 'b': + sb.append('\b'); + break; + case 't': + sb.append('\t'); + break; + case 'n': + sb.append('\n'); + break; + case 'f': + sb.append('\f'); + break; + case 'r': + sb.append('\r'); + break; + case 'u': + sb.append((char)Integer.parseInt(this.next(4), 16)); + break; + case '"': + case '\'': + case '\\': + case '/': + sb.append(c); + break; + default: + throw this.syntaxError("Illegal escape."); + } + break; + default: + if (c == quote) { + return sb.toString(); + } + sb.append(c); + } + } + } + + + /** + * Get the text up but not including the specified character or the + * end of line, whichever comes first. + * @param delimiter A delimiter character. + * @return A string. + */ + public String nextTo(char delimiter) throws JSONException { + StringBuffer sb = new StringBuffer(); + for (;;) { + char c = this.next(); + if (c == delimiter || c == 0 || c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the text up but not including one of the specified delimiter + * characters or the end of line, whichever comes first. + * @param delimiters A set of delimiter characters. + * @return A string, trimmed. + */ + public String nextTo(String delimiters) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + if (delimiters.indexOf(c) >= 0 || c == 0 || + c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the next value. The value can be a Boolean, Double, Integer, + * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. + * @throws JSONException If syntax error. + * + * @return An object. + */ + public Object nextValue() throws JSONException { + char c = this.nextClean(); + String string; + + switch (c) { + case '"': + case '\'': + return this.nextString(c); + case '{': + this.back(); + return new JSONObject(this); + case '[': + this.back(); + return new JSONArray(this); + } + + /* + * Handle unquoted text. This could be the values true, false, or + * null, or it can be a number. An implementation (such as this one) + * is allowed to also accept non-standard forms. + * + * Accumulate characters until we reach the end of the text or a + * formatting character. + */ + + StringBuffer sb = new StringBuffer(); + while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { + sb.append(c); + c = this.next(); + } + this.back(); + + string = sb.toString().trim(); + if ("".equals(string)) { + throw this.syntaxError("Missing value"); + } + return JSONObject.stringToValue(string); + } + + + /** + * Skip characters until the next character is the requested character. + * If the requested character is not found, no characters are skipped. + * @param to A character to skip to. + * @return The requested character, or zero if the requested character + * is not found. + */ + public char skipTo(char to) throws JSONException { + char c; + try { + long startIndex = this.index; + long startCharacter = this.character; + long startLine = this.line; + this.reader.mark(1000000); + do { + c = this.next(); + if (c == 0) { + this.reader.reset(); + this.index = startIndex; + this.character = startCharacter; + this.line = startLine; + return c; + } + } while (c != to); + } catch (IOException exc) { + throw new JSONException(exc); + } + + this.back(); + return c; + } + + + /** + * Make a JSONException to signal a syntax error. + * + * @param message The error message. + * @return A JSONException object, suitable for throwing + */ + public JSONException syntaxError(String message) { + return new JSONException(message + this.toString()); + } + + + /** + * Make a printable string of this JSONTokener. + * + * @return " at {index} [character {character} line {line}]" + */ + public String toString() { + return " at " + this.index + " [character " + this.character + " line " + + this.line + "]"; + } +} diff --git a/Tubes5/Server/src/org/json/JSONWriter.java b/Tubes5/Server/src/org/json/JSONWriter.java new file mode 100644 index 00000000..35b60d90 --- /dev/null +++ b/Tubes5/Server/src/org/json/JSONWriter.java @@ -0,0 +1,327 @@ +package org.json; + +import java.io.IOException; +import java.io.Writer; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * JSONWriter provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONWriter can produce one JSON text. + *

+ * A JSONWriter instance provides a value method for appending + * values to the + * text, and a key + * method for adding keys before values in objects. There are array + * and endArray methods that make and bound array values, and + * object and endObject methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting a cascade style. For example,

+ * new JSONWriter(myWriter)
+ *     .object()
+ *         .key("JSON")
+ *         .value("Hello, World!")
+ *     .endObject();
which writes
+ * {"JSON":"Hello, World!"}
+ *

+ * The first method called must be array or object. + * There are no methods for adding commas or colons. JSONWriter adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + *

+ * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2011-11-24 + */ +public class JSONWriter { + private static final int maxdepth = 200; + + /** + * The comma flag determines if a comma should be output before the next + * value. + */ + private boolean comma; + + /** + * The current mode. Values: + * 'a' (array), + * 'd' (done), + * 'i' (initial), + * 'k' (key), + * 'o' (object). + */ + protected char mode; + + /** + * The object/array stack. + */ + private final JSONObject stack[]; + + /** + * The stack top index. A value of 0 indicates that the stack is empty. + */ + private int top; + + /** + * The writer that will receive the output. + */ + protected Writer writer; + + /** + * Make a fresh JSONWriter. It can be used to build one JSON text. + */ + public JSONWriter(Writer w) { + this.comma = false; + this.mode = 'i'; + this.stack = new JSONObject[maxdepth]; + this.top = 0; + this.writer = w; + } + + /** + * Append a value. + * @param string A string value. + * @return this + * @throws JSONException If the value is out of sequence. + */ + private JSONWriter append(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null pointer"); + } + if (this.mode == 'o' || this.mode == 'a') { + try { + if (this.comma && this.mode == 'a') { + this.writer.write(','); + } + this.writer.write(string); + } catch (IOException e) { + throw new JSONException(e); + } + if (this.mode == 'o') { + this.mode = 'k'; + } + this.comma = true; + return this; + } + throw new JSONException("Value out of sequence."); + } + + /** + * Begin appending a new array. All values until the balancing + * endArray will be appended to this array. The + * endArray method must be called to mark the array's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter array() throws JSONException { + if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { + this.push(null); + this.append("["); + this.comma = false; + return this; + } + throw new JSONException("Misplaced array."); + } + + /** + * End something. + * @param mode Mode + * @param c Closing character + * @return this + * @throws JSONException If unbalanced. + */ + private JSONWriter end(char mode, char c) throws JSONException { + if (this.mode != mode) { + throw new JSONException(mode == 'a' + ? "Misplaced endArray." + : "Misplaced endObject."); + } + this.pop(mode); + try { + this.writer.write(c); + } catch (IOException e) { + throw new JSONException(e); + } + this.comma = true; + return this; + } + + /** + * End an array. This method most be called to balance calls to + * array. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endArray() throws JSONException { + return this.end('a', ']'); + } + + /** + * End an object. This method most be called to balance calls to + * object. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endObject() throws JSONException { + return this.end('k', '}'); + } + + /** + * Append a key. The key will be associated with the next value. In an + * object, every value must be preceded by a key. + * @param string A key string. + * @return this + * @throws JSONException If the key is out of place. For example, keys + * do not belong in arrays or if the key is null. + */ + public JSONWriter key(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null key."); + } + if (this.mode == 'k') { + try { + this.stack[this.top - 1].putOnce(string, Boolean.TRUE); + if (this.comma) { + this.writer.write(','); + } + this.writer.write(JSONObject.quote(string)); + this.writer.write(':'); + this.comma = false; + this.mode = 'o'; + return this; + } catch (IOException e) { + throw new JSONException(e); + } + } + throw new JSONException("Misplaced key."); + } + + + /** + * Begin appending a new object. All keys and values until the balancing + * endObject will be appended to this object. The + * endObject method must be called to mark the object's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter object() throws JSONException { + if (this.mode == 'i') { + this.mode = 'o'; + } + if (this.mode == 'o' || this.mode == 'a') { + this.append("{"); + this.push(new JSONObject()); + this.comma = false; + return this; + } + throw new JSONException("Misplaced object."); + + } + + + /** + * Pop an array or object scope. + * @param c The scope to close. + * @throws JSONException If nesting is wrong. + */ + private void pop(char c) throws JSONException { + if (this.top <= 0) { + throw new JSONException("Nesting error."); + } + char m = this.stack[this.top - 1] == null ? 'a' : 'k'; + if (m != c) { + throw new JSONException("Nesting error."); + } + this.top -= 1; + this.mode = this.top == 0 + ? 'd' + : this.stack[this.top - 1] == null + ? 'a' + : 'k'; + } + + /** + * Push an array or object scope. + * @param c The scope to open. + * @throws JSONException If nesting is too deep. + */ + private void push(JSONObject jo) throws JSONException { + if (this.top >= maxdepth) { + throw new JSONException("Nesting too deep."); + } + this.stack[this.top] = jo; + this.mode = jo == null ? 'a' : 'k'; + this.top += 1; + } + + + /** + * Append either the value true or the value + * false. + * @param b A boolean. + * @return this + * @throws JSONException + */ + public JSONWriter value(boolean b) throws JSONException { + return this.append(b ? "true" : "false"); + } + + /** + * Append a double value. + * @param d A double. + * @return this + * @throws JSONException If the number is not finite. + */ + public JSONWriter value(double d) throws JSONException { + return this.value(new Double(d)); + } + + /** + * Append a long value. + * @param l A long. + * @return this + * @throws JSONException + */ + public JSONWriter value(long l) throws JSONException { + return this.append(Long.toString(l)); + } + + + /** + * Append an object value. + * @param object The object to append. It can be null, or a Boolean, Number, + * String, JSONObject, or JSONArray, or an object that implements JSONString. + * @return this + * @throws JSONException If the value is out of sequence. + */ + public JSONWriter value(Object object) throws JSONException { + return this.append(JSONObject.valueToString(object)); + } +} diff --git a/Tubes5/Tubes5server/build.xml b/Tubes5/Tubes5server/build.xml new file mode 100644 index 00000000..a3aaaa92 --- /dev/null +++ b/Tubes5/Tubes5server/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project Tubes5server. + + + diff --git a/Tubes5/Tubes5server/build/classes/.netbeans_automatic_build b/Tubes5/Tubes5server/build/classes/.netbeans_automatic_build new file mode 100644 index 00000000..e69de29b diff --git a/Tubes5/Tubes5server/build/classes/.netbeans_update_resources b/Tubes5/Tubes5server/build/classes/.netbeans_update_resources new file mode 100644 index 00000000..e69de29b diff --git a/Tubes5/Tubes5server/build/classes/Controller/ConnectionHandler.class b/Tubes5/Tubes5server/build/classes/Controller/ConnectionHandler.class new file mode 100644 index 00000000..e7fd4625 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/Controller/ConnectionHandler.class differ diff --git a/Tubes5/Tubes5server/build/classes/Controller/Controller.class b/Tubes5/Tubes5server/build/classes/Controller/Controller.class new file mode 100644 index 00000000..fe969d15 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/Controller/Controller.class differ diff --git a/Tubes5/Tubes5server/build/classes/Model/Task.class b/Tubes5/Tubes5server/build/classes/Model/Task.class new file mode 100644 index 00000000..de415913 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/Model/Task.class differ diff --git a/Tubes5/Tubes5server/build/classes/Program.class b/Tubes5/Tubes5server/build/classes/Program.class new file mode 100644 index 00000000..eff455b7 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/Program.class differ diff --git a/Tubes5/Tubes5server/build/classes/Utility/DBUtil.class b/Tubes5/Tubes5server/build/classes/Utility/DBUtil.class new file mode 100644 index 00000000..018e9884 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/Utility/DBUtil.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONArray.class b/Tubes5/Tubes5server/build/classes/org/json/JSONArray.class new file mode 100644 index 00000000..3db455ff Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONArray.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONException.class b/Tubes5/Tubes5server/build/classes/org/json/JSONException.class new file mode 100644 index 00000000..a6421311 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONException.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONModel.class b/Tubes5/Tubes5server/build/classes/org/json/JSONModel.class new file mode 100644 index 00000000..8730343a Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONModel.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONObject$1.class b/Tubes5/Tubes5server/build/classes/org/json/JSONObject$1.class new file mode 100644 index 00000000..91808fbe Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONObject$1.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONObject$Null.class b/Tubes5/Tubes5server/build/classes/org/json/JSONObject$Null.class new file mode 100644 index 00000000..7f654f4e Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONObject$Null.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONObject.class b/Tubes5/Tubes5server/build/classes/org/json/JSONObject.class new file mode 100644 index 00000000..790c9a12 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONObject.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONString.class b/Tubes5/Tubes5server/build/classes/org/json/JSONString.class new file mode 100644 index 00000000..7fff2574 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONString.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONStringer.class b/Tubes5/Tubes5server/build/classes/org/json/JSONStringer.class new file mode 100644 index 00000000..22e326ce Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONStringer.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONTokener.class b/Tubes5/Tubes5server/build/classes/org/json/JSONTokener.class new file mode 100644 index 00000000..1d06cb25 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONTokener.class differ diff --git a/Tubes5/Tubes5server/build/classes/org/json/JSONWriter.class b/Tubes5/Tubes5server/build/classes/org/json/JSONWriter.class new file mode 100644 index 00000000..bfa1d239 Binary files /dev/null and b/Tubes5/Tubes5server/build/classes/org/json/JSONWriter.class differ diff --git a/Tubes5/Tubes5server/manifest.mf b/Tubes5/Tubes5server/manifest.mf new file mode 100644 index 00000000..328e8e5b --- /dev/null +++ b/Tubes5/Tubes5server/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Tubes5/Tubes5server/nbproject/build-impl.xml b/Tubes5/Tubes5server/nbproject/build-impl.xml new file mode 100644 index 00000000..206db990 --- /dev/null +++ b/Tubes5/Tubes5server/nbproject/build-impl.xml @@ -0,0 +1,1411 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + java -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tubes5/Tubes5server/nbproject/genfiles.properties b/Tubes5/Tubes5server/nbproject/genfiles.properties new file mode 100644 index 00000000..b2901262 --- /dev/null +++ b/Tubes5/Tubes5server/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=becf1176 +build.xml.script.CRC32=381332c1 +build.xml.stylesheet.CRC32=28e38971@1.56.1.46 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=becf1176 +nbproject/build-impl.xml.script.CRC32=3e3f4f02 +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/Tubes5/Tubes5server/nbproject/private/private.properties b/Tubes5/Tubes5server/nbproject/private/private.properties new file mode 100644 index 00000000..673448f4 --- /dev/null +++ b/Tubes5/Tubes5server/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\Aji\\AppData\\Roaming\\NetBeans\\7.3rc2\\build.properties diff --git a/Tubes5/Tubes5server/nbproject/project.properties b/Tubes5/Tubes5server/nbproject/project.properties new file mode 100644 index 00000000..d63fc21e --- /dev/null +++ b/Tubes5/Tubes5server/nbproject/project.properties @@ -0,0 +1,71 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Tubes5server.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=Program +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Tubes5/Tubes5server/nbproject/project.xml b/Tubes5/Tubes5server/nbproject/project.xml new file mode 100644 index 00000000..f56200c9 --- /dev/null +++ b/Tubes5/Tubes5server/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Tubes5server + + + + + + + + + diff --git a/Tubes5/Tubes5server/src/Controller/ConnectionHandler.java b/Tubes5/Tubes5server/src/Controller/ConnectionHandler.java new file mode 100644 index 00000000..0037e8a8 --- /dev/null +++ b/Tubes5/Tubes5server/src/Controller/ConnectionHandler.java @@ -0,0 +1,331 @@ +package Controller; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.Socket; +import java.net.URL; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Random; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; + +import Model.Task; + +public class ConnectionHandler extends Thread { + + private Socket clientSocket; + private static final byte LOGIN = 0; + private static final byte SYNC = 1; + private static final byte UPDATE = 2; + private static final byte LIST = 3; + private static final byte LOGOUT = 9; + private static final byte SUCCESS = 10; + private static final byte FAILED = 11; + private static Random random = new Random(); + private HashMap session = new HashMap(); + public List task_list = new ArrayList(); + public List task_listServer = new ArrayList(); + + public ConnectionHandler(Socket clientSocket) { + this.clientSocket = clientSocket; + } + + @Override + public void run() { + long sessionId = -1; + try + { + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + while(true) + { + System.out.println("DENGERIN"); + byte msg = in.readByte(); + System.out.println("MSG = "+msg); + if (msg != LOGIN) + { + sessionId = in.readLong(); + + synchronized(session){ + if (!session.containsKey(sessionId)){ + out.write(FAILED); + clientSocket.close(); + return; + } + } + } + + if (msg == LOGIN) + { + byte[] data = new byte[in.readInt()]; + in.readFully(data); + String username = new String(data); + + data = new byte[in.readInt()]; + in.readFully(data ); + String password = new String(data); + try{ + URL url = new URL("http://eurilys.ap01.aws.af.cm/user/login_check?login_username="+username+"&login_password="+password); + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + + String[] output_parts = outputObject.split(","); + String fullname = output_parts[0]; + String avatar = output_parts[1]; + + if ("failed".equals(outputObject)) { + out.writeByte(FAILED); + } else { + synchronized (session) { + long i = random.nextLong(); + while (session.containsKey(i)) { + i = random.nextLong(); + } + session.put(i, username); + out.writeByte(SUCCESS); + out.writeLong(i); + System.out.println("SESSION LOGIN :: " + username); + System.out.println("SESSIONID :: " + i); + } + } + } + catch (Exception e) + { + out.writeByte(FAILED); + } + } + else if (msg == SYNC) + { + int n = in.readInt(); + for (int i = 0; i < n; i++) { + byte[] data = new byte[in.readInt()]; + in.readFully(data); + String taskTemp = new String(data); + JSONObject taskObject = new JSONObject(taskTemp.toString()); + task_list.add(new Task(taskObject)); + } + + String username = session.get(sessionId); + System.out.println("LIST USERNAME :: "+ username); + URL taskURL = new URL("http://eurilys.ap01.aws.af.cm/task/all_task?username=" + username); + HttpURLConnection taskConn = (HttpURLConnection) taskURL.openConnection(); + taskConn.setRequestMethod("GET"); + taskConn.setRequestProperty("Accept", "application/json"); + if (taskConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + taskConn.getResponseCode()); + } + BufferedReader taskBr = new BufferedReader(new InputStreamReader((taskConn.getInputStream()))); + String taskOutput; + String taskJSONObject = ""; + while ((taskOutput = taskBr.readLine()) != null) { + taskJSONObject += taskOutput; + } + taskConn.disconnect(); + + JSONTokener taskTokener = new JSONTokener(taskJSONObject); + JSONArray taskroot = new JSONArray(taskTokener); + + for (int i=0; iget and opt + * methods for accessing the values by index, and put methods for + * adding or replacing values. The values can be any of these types: + * Boolean, JSONArray, JSONObject, + * Number, String, or the + * JSONObject.NULL object. + *

+ * The constructor can convert a JSON text into a Java object. The + * toString method converts to JSON text. + *

+ * A get method returns a value if one can be found, and throws an + * exception if one cannot be found. An opt method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + *

+ * The generic get() and opt() methods return an + * object which you can cast or query for type. There are also typed + * get and opt methods that do type checking and type + * coercion for you. + *

+ * The texts produced by the toString methods strictly conform to + * JSON syntax rules. The constructors are more forgiving in the texts they will + * accept: + *

    + *
  • An extra , (comma) may appear just + * before the closing bracket.
  • + *
  • The null value will be inserted when there is , + *  (comma) elision.
  • + *
  • Strings may be quoted with ' (single + * quote).
  • + *
  • Strings do not need to be quoted at all if they do not begin with a quote + * or single quote, and if they do not contain leading or trailing spaces, and + * if they do not contain any of these characters: + * { } [ ] / \ : , # and if they do not look like numbers and + * if they are not the reserved words true, false, or + * null.
  • + *
+ * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONArray { + + /** + * The arrayList where the JSONArray's properties are kept. + */ + private final ArrayList myArrayList; + + /** + * Construct an empty JSONArray. + */ + public JSONArray() { + this.myArrayList = new ArrayList(); + } + + /** + * Construct a JSONArray from a JSONTokener. + * + * @param x + * A JSONTokener + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(JSONTokener x) throws JSONException { + this(); + if (x.nextClean() != '[') { + throw x.syntaxError("A JSONArray text must start with '['"); + } + if (x.nextClean() != ']') { + x.back(); + for (;;) { + if (x.nextClean() == ',') { + x.back(); + this.myArrayList.add(JSONObject.NULL); + } else { + x.back(); + this.myArrayList.add(x.nextValue()); + } + switch (x.nextClean()) { + case ',': + if (x.nextClean() == ']') { + return; + } + x.back(); + break; + case ']': + return; + default: + throw x.syntaxError("Expected a ',' or ']'"); + } + } + } + } + + /** + * Construct a JSONArray from a source JSON text. + * + * @param source + * A string that begins with [ (left + * bracket) and ends with ] + *  (right bracket). + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONArray from a Collection. + * + * @param collection + * A Collection. + */ + public JSONArray(Collection collection) { + this.myArrayList = new ArrayList(); + if (collection != null) { + Iterator iter = collection.iterator(); + while (iter.hasNext()) { + this.myArrayList.add(JSONObject.wrap(iter.next())); + } + } + } + + /** + * Construct a JSONArray from an array + * + * @throws JSONException + * If not an array. + */ + public JSONArray(Object array) throws JSONException { + this(); + if (array.getClass().isArray()) { + int length = Array.getLength(array); + for (int i = 0; i < length; i += 1) { + this.put(JSONObject.wrap(Array.get(array, i))); + } + } else { + throw new JSONException( + "JSONArray initial value should be a string or collection or array."); + } + } + + /** + * Get the object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value. + * @throws JSONException + * If there is no value for the index. + */ + public Object get(int index) throws JSONException { + Object object = this.opt(index); + if (object == null) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with an index. The string values "true" + * and "false" are converted to boolean. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + * @throws JSONException + * If there is no value for the index or if the value is not + * convertible to boolean. + */ + public boolean getBoolean(int index) throws JSONException { + Object object = this.get(index); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONArray[" + index + "] is not a boolean."); + } + + /** + * Get the double value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public double getDouble(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the int value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value is not a number. + */ + public int getInt(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the JSONArray associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONArray value. + * @throws JSONException + * If there is no value for the index. or if the value is not a + * JSONArray + */ + public JSONArray getJSONArray(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); + } + + /** + * Get the JSONObject associated with an index. + * + * @param index + * subscript + * @return A JSONObject value. + * @throws JSONException + * If there is no value for the index or if the value is not a + * JSONObject + */ + public JSONObject getJSONObject(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); + } + + /** + * Get the long value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public long getLong(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the string associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A string value. + * @throws JSONException + * If there is no string value for the index. + */ + public String getString(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONArray[" + index + "] not a string."); + } + + /** + * Determine if the value is null. + * + * @param index + * The index must be between 0 and length() - 1. + * @return true if the value at the index is null, or if there is no value. + */ + public boolean isNull(int index) { + return JSONObject.NULL.equals(this.opt(index)); + } + + /** + * Make a string from the contents of this JSONArray. The + * separator string is inserted between each element. Warning: + * This method assumes that the data structure is acyclical. + * + * @param separator + * A string that will be inserted between the elements. + * @return a string. + * @throws JSONException + * If the array contains an invalid number. + */ + public String join(String separator) throws JSONException { + int len = this.length(); + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < len; i += 1) { + if (i > 0) { + sb.append(separator); + } + sb.append(JSONObject.valueToString(this.myArrayList.get(i))); + } + return sb.toString(); + } + + /** + * Get the number of elements in the JSONArray, included nulls. + * + * @return The length (or size). + */ + public int length() { + return this.myArrayList.size(); + } + + /** + * Get the optional object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value, or null if there is no object at that index. + */ + public Object opt(int index) { + return (index < 0 || index >= this.length()) ? null : this.myArrayList + .get(index); + } + + /** + * Get the optional boolean value associated with an index. It returns false + * if there is no value at that index, or if the value is not Boolean.TRUE + * or the String "true". + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + */ + public boolean optBoolean(int index) { + return this.optBoolean(index, false); + } + + /** + * Get the optional boolean value associated with an index. It returns the + * defaultValue if there is no value at that index or if it is not a Boolean + * or the String "true" or "false" (case insensitive). + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * A boolean default. + * @return The truth. + */ + public boolean optBoolean(int index, boolean defaultValue) { + try { + return this.getBoolean(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional double value associated with an index. NaN is returned + * if there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public double optDouble(int index) { + return this.optDouble(index, Double.NaN); + } + + /** + * Get the optional double value associated with an index. The defaultValue + * is returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * subscript + * @param defaultValue + * The default value. + * @return The value. + */ + public double optDouble(int index, double defaultValue) { + try { + return this.getDouble(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional int value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public int optInt(int index) { + return this.optInt(index, 0); + } + + /** + * Get the optional int value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public int optInt(int index, int defaultValue) { + try { + return this.getInt(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional JSONArray associated with an index. + * + * @param index + * subscript + * @return A JSONArray value, or null if the index has no value, or if the + * value is not a JSONArray. + */ + public JSONArray optJSONArray(int index) { + Object o = this.opt(index); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get the optional JSONObject associated with an index. Null is returned if + * the key is not found, or null if the index has no value, or if the value + * is not a JSONObject. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONObject value. + */ + public JSONObject optJSONObject(int index) { + Object o = this.opt(index); + return o instanceof JSONObject ? (JSONObject) o : null; + } + + /** + * Get the optional long value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public long optLong(int index) { + return this.optLong(index, 0); + } + + /** + * Get the optional long value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public long optLong(int index, long defaultValue) { + try { + return this.getLong(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional string value associated with an index. It returns an + * empty string if there is no value at that index. If the value is not a + * string and is not null, then it is coverted to a string. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A String value. + */ + public String optString(int index) { + return this.optString(index, ""); + } + + /** + * Get the optional string associated with an index. The defaultValue is + * returned if the key is not found. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return A String value. + */ + public String optString(int index, String defaultValue) { + Object object = this.opt(index); + return JSONObject.NULL.equals(object) ? defaultValue : object + .toString(); + } + + /** + * Append a boolean value. This increases the array's length by one. + * + * @param value + * A boolean value. + * @return this. + */ + public JSONArray put(boolean value) { + this.put(value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param value + * A Collection value. + * @return this. + */ + public JSONArray put(Collection value) { + this.put(new JSONArray(value)); + return this; + } + + /** + * Append a double value. This increases the array's length by one. + * + * @param value + * A double value. + * @throws JSONException + * if the value is not finite. + * @return this. + */ + public JSONArray put(double value) throws JSONException { + Double d = new Double(value); + JSONObject.testValidity(d); + this.put(d); + return this; + } + + /** + * Append an int value. This increases the array's length by one. + * + * @param value + * An int value. + * @return this. + */ + public JSONArray put(int value) { + this.put(new Integer(value)); + return this; + } + + /** + * Append an long value. This increases the array's length by one. + * + * @param value + * A long value. + * @return this. + */ + public JSONArray put(long value) { + this.put(new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject which + * is produced from a Map. + * + * @param value + * A Map value. + * @return this. + */ + public JSONArray put(Map value) { + this.put(new JSONObject(value)); + return this; + } + + /** + * Append an object value. This increases the array's length by one. + * + * @param value + * An object value. The value should be a Boolean, Double, + * Integer, JSONArray, JSONObject, Long, or String, or the + * JSONObject.NULL object. + * @return this. + */ + public JSONArray put(Object value) { + this.myArrayList.add(value); + return this; + } + + /** + * Put or replace a boolean value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * A boolean value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, boolean value) throws JSONException { + this.put(index, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param index + * The subscript. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, Collection value) throws JSONException { + this.put(index, new JSONArray(value)); + return this; + } + + /** + * Put or replace a double value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A double value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, double value) throws JSONException { + this.put(index, new Double(value)); + return this; + } + + /** + * Put or replace an int value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * An int value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, int value) throws JSONException { + this.put(index, new Integer(value)); + return this; + } + + /** + * Put or replace a long value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A long value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, long value) throws JSONException { + this.put(index, new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject that + * is produced from a Map. + * + * @param index + * The subscript. + * @param value + * The Map value. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Map value) throws JSONException { + this.put(index, new JSONObject(value)); + return this; + } + + /** + * Put or replace an object value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * The value to put into the array. The value should be a + * Boolean, Double, Integer, JSONArray, JSONObject, Long, or + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Object value) throws JSONException { + JSONObject.testValidity(value); + if (index < 0) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + if (index < this.length()) { + this.myArrayList.set(index, value); + } else { + while (index != this.length()) { + this.put(JSONObject.NULL); + } + this.put(value); + } + return this; + } + + /** + * Remove an index and close the hole. + * + * @param index + * The index of the element to be removed. + * @return The value that was associated with the index, or null if there + * was no value. + */ + public Object remove(int index) { + Object o = this.opt(index); + this.myArrayList.remove(index); + return o; + } + + /** + * Produce a JSONObject by combining a JSONArray of names with the values of + * this JSONArray. + * + * @param names + * A JSONArray containing a list of key strings. These will be + * paired with the values. + * @return A JSONObject, or null if there are no names or if this JSONArray + * has no values. + * @throws JSONException + * If any of the names are null. + */ + public JSONObject toJSONObject(JSONArray names) throws JSONException { + if (names == null || names.length() == 0 || this.length() == 0) { + return null; + } + JSONObject jo = new JSONObject(); + for (int i = 0; i < names.length(); i += 1) { + jo.put(names.getString(i), this.opt(i)); + } + return jo; + } + + /** + * Make a JSON text of this JSONArray. For compactness, no unnecessary + * whitespace is added. If it is not possible to produce a syntactically + * correct JSON text then null will be returned instead. This could occur if + * the array contains an invalid number. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, transmittable representation of the + * array. + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONArray. Warning: This method + * assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, transmittable representation of the + * object, beginning with [ (left + * bracket) and ending with ] + *  (right bracket). + * @throws JSONException + */ + public String toString(int indentFactor) throws JSONException { + StringWriter sw = new StringWriter(); + synchronized (sw.getBuffer()) { + return this.write(sw, indentFactor, 0).toString(); + } + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @param indent + * The indention of the top level. + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + int length = this.length(); + writer.write('['); + + if (length == 1) { + JSONObject.writeValue(writer, this.myArrayList.get(0), + indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + + for (int i = 0; i < length; i += 1) { + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, newindent); + JSONObject.writeValue(writer, this.myArrayList.get(i), + indentFactor, newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, indent); + } + writer.write(']'); + return writer; + } catch (IOException e) { + throw new JSONException(e); + } + } +} diff --git a/Tubes5/Tubes5server/src/org/json/JSONException.java b/Tubes5/Tubes5server/src/org/json/JSONException.java new file mode 100644 index 00000000..971547e6 --- /dev/null +++ b/Tubes5/Tubes5server/src/org/json/JSONException.java @@ -0,0 +1,41 @@ +package org.json; + +/** + * The JSONException is thrown by the JSON.org classes when things are amiss. + * + * @author JSON.org + * @version 2013-02-10 + */ +public class JSONException extends RuntimeException { + private static final long serialVersionUID = 0; + private Throwable cause; + + /** + * Constructs a JSONException with an explanatory message. + * + * @param message + * Detail about the reason for the exception. + */ + public JSONException(String message) { + super(message); + } + + /** + * Constructs a new JSONException with the specified cause. + */ + public JSONException(Throwable cause) { + super(cause.getMessage()); + this.cause = cause; + } + + /** + * Returns the cause of this exception or null if the cause is nonexistent + * or unknown. + * + * @returns the cause of this exception or null if the cause is nonexistent + * or unknown. + */ + public Throwable getCause() { + return this.cause; + } +} diff --git a/Tubes5/Tubes5server/src/org/json/JSONModel.java b/Tubes5/Tubes5server/src/org/json/JSONModel.java new file mode 100644 index 00000000..c52b04cd --- /dev/null +++ b/Tubes5/Tubes5server/src/org/json/JSONModel.java @@ -0,0 +1,7 @@ +package org.json; + +public abstract class JSONModel { + + public abstract JSONObject toJsonObject(); + public abstract void fromJsonObject(JSONObject jObject); +} diff --git a/Tubes5/Tubes5server/src/org/json/JSONObject.java b/Tubes5/Tubes5server/src/org/json/JSONObject.java new file mode 100644 index 00000000..5666eb57 --- /dev/null +++ b/Tubes5/Tubes5server/src/org/json/JSONObject.java @@ -0,0 +1,1666 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; + +/** + * A JSONObject is an unordered collection of name/value pairs. Its external + * form is a string wrapped in curly braces with colons between the names and + * values, and commas between the values and names. The internal form is an + * object having get and opt methods for accessing + * the values by name, and put methods for adding or replacing + * values by name. The values can be any of these types: Boolean, + * JSONArray, JSONObject, Number, + * String, or the JSONObject.NULL object. A + * JSONObject constructor can be used to convert an external form JSON text + * into an internal form whose values can be retrieved with the + * get and opt methods, or to convert values into a + * JSON text using the put and toString methods. A + * get method returns a value if one can be found, and throws an + * exception if one cannot be found. An opt method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + *

+ * The generic get() and opt() methods return an + * object, which you can cast or query for type. There are also typed + * get and opt methods that do type checking and type + * coercion for you. The opt methods differ from the get methods in that they + * do not throw. Instead, they return a specified value, such as null. + *

+ * The put methods add or replace values in an object. For + * example, + * + *

+ * myString = new JSONObject()
+ *         .put("JSON", "Hello, World!").toString();
+ * 
+ * + * produces the string {"JSON": "Hello, World"}. + *

+ * The texts produced by the toString methods strictly conform to + * the JSON syntax rules. The constructors are more forgiving in the texts they + * will accept: + *

    + *
  • An extra , (comma) may appear just + * before the closing brace.
  • + *
  • Strings may be quoted with ' (single + * quote).
  • + *
  • Strings do not need to be quoted at all if they do not begin with a + * quote or single quote, and if they do not contain leading or trailing + * spaces, and if they do not contain any of these characters: + * { } [ ] / \ : , # and if they do not look like numbers and + * if they are not the reserved words true, false, + * or null.
  • + *
+ * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONObject { + /** + * The maximum number of keys in the key pool. + */ + private static final int keyPoolSize = 100; + + /** + * Key pooling is like string interning, but without permanently tying up + * memory. To help conserve memory, storage of duplicated key strings in + * JSONObjects will be avoided by using a key pool to manage unique key + * string objects. This is used by JSONObject.put(string, object). + */ + private static HashMap keyPool = new HashMap(keyPoolSize); + + /** + * JSONObject.NULL is equivalent to the value that JavaScript calls null, + * whilst Java's null is equivalent to the value that JavaScript calls + * undefined. + */ + private static final class Null { + + /** + * There is only intended to be a single instance of the NULL object, + * so the clone method returns itself. + * + * @return NULL. + */ + protected final Object clone() { + return this; + } + + /** + * A Null object is equal to the null value and to itself. + * + * @param object + * An object to test for nullness. + * @return true if the object parameter is the JSONObject.NULL object or + * null. + */ + public boolean equals(Object object) { + return object == null || object == this; + } + + /** + * Get the "null" string value. + * + * @return The string "null". + */ + public String toString() { + return "null"; + } + } + + /** + * The map where the JSONObject's properties are kept. + */ + private final Map map; + + /** + * It is sometimes more convenient and less ambiguous to have a + * NULL object than to use Java's null value. + * JSONObject.NULL.equals(null) returns true. + * JSONObject.NULL.toString() returns "null". + */ + public static final Object NULL = new Null(); + + /** + * Construct an empty JSONObject. + */ + public JSONObject() { + this.map = new HashMap(); + } + + /** + * Construct a JSONObject from a subset of another JSONObject. An array of + * strings is used to identify the keys that should be copied. Missing keys + * are ignored. + * + * @param jo + * A JSONObject. + * @param names + * An array of strings. + * @throws JSONException + * @exception JSONException + * If a value is a non-finite number or if a name is + * duplicated. + */ + public JSONObject(JSONObject jo, String[] names) { + this(); + for (int i = 0; i < names.length; i += 1) { + try { + this.putOnce(names[i], jo.opt(names[i])); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a JSONTokener. + * + * @param x + * A JSONTokener object containing the source string. + * @throws JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(JSONTokener x) throws JSONException { + this(); + char c; + String key; + + if (x.nextClean() != '{') { + throw x.syntaxError("A JSONObject text must begin with '{'"); + } + for (;;) { + c = x.nextClean(); + switch (c) { + case 0: + throw x.syntaxError("A JSONObject text must end with '}'"); + case '}': + return; + default: + x.back(); + key = x.nextValue().toString(); + } + +// The key is followed by ':'. + + c = x.nextClean(); + if (c != ':') { + throw x.syntaxError("Expected a ':' after a key"); + } + this.putOnce(key, x.nextValue()); + +// Pairs are separated by ','. + + switch (x.nextClean()) { + case ';': + case ',': + if (x.nextClean() == '}') { + return; + } + x.back(); + break; + case '}': + return; + default: + throw x.syntaxError("Expected a ',' or '}'"); + } + } + } + + /** + * Construct a JSONObject from a Map. + * + * @param map + * A map object that can be used to initialize the contents of + * the JSONObject. + * @throws JSONException + */ + public JSONObject(Map map) { + this.map = new HashMap(); + if (map != null) { + Iterator i = map.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry e = (Map.Entry) i.next(); + Object value = e.getValue(); + if (value != null) { + this.map.put(e.getKey(), wrap(value)); + } + } + } + } + + /** + * Construct a JSONObject from an Object using bean getters. It reflects on + * all of the public methods of the object. For each of the methods with no + * parameters and a name starting with "get" or + * "is" followed by an uppercase letter, the method is invoked, + * and a key and the value returned from the getter method are put into the + * new JSONObject. + * + * The key is formed by removing the "get" or "is" + * prefix. If the second remaining character is not upper case, then the + * first character is converted to lower case. + * + * For example, if an object has a method named "getName", and + * if the result of calling object.getName() is + * "Larry Fine", then the JSONObject will contain + * "name": "Larry Fine". + * + * @param bean + * An object that has getter methods that should be used to make + * a JSONObject. + */ + public JSONObject(Object bean) { + this(); + this.populateMap(bean); + } + + /** + * Construct a JSONObject from an Object, using reflection to find the + * public members. The resulting JSONObject's keys will be the strings from + * the names array, and the values will be the field values associated with + * those keys in the object. If a key is not found or not visible, then it + * will not be copied into the new JSONObject. + * + * @param object + * An object that has fields that should be used to make a + * JSONObject. + * @param names + * An array of strings, the names of the fields to be obtained + * from the object. + */ + public JSONObject(Object object, String names[]) { + this(); + Class c = object.getClass(); + for (int i = 0; i < names.length; i += 1) { + String name = names[i]; + try { + this.putOpt(name, c.getField(name).get(object)); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a source JSON text string. This is the most + * commonly used JSONObject constructor. + * + * @param source + * A string beginning with { (left + * brace) and ending with } + *  (right brace). + * @exception JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONObject from a ResourceBundle. + * + * @param baseName + * The ResourceBundle base name. + * @param locale + * The Locale to load the ResourceBundle for. + * @throws JSONException + * If any JSONExceptions are detected. + */ + public JSONObject(String baseName, Locale locale) throws JSONException { + this(); + ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, + Thread.currentThread().getContextClassLoader()); + +// Iterate through the keys in the bundle. + + Enumeration keys = bundle.getKeys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + if (key instanceof String) { + +// Go through the path, ensuring that there is a nested JSONObject for each +// segment except the last. Add the value using the last segment's name into +// the deepest nested JSONObject. + + String[] path = ((String) key).split("\\."); + int last = path.length - 1; + JSONObject target = this; + for (int i = 0; i < last; i += 1) { + String segment = path[i]; + JSONObject nextTarget = target.optJSONObject(segment); + if (nextTarget == null) { + nextTarget = new JSONObject(); + target.put(segment, nextTarget); + } + target = nextTarget; + } + target.put(path[last], bundle.getString((String) key)); + } + } + } + + /** + * Accumulate values under a key. It is similar to the put method except + * that if there is already an object stored under the key then a JSONArray + * is stored under the key to hold all of the accumulated values. If there + * is already a JSONArray, then the new value is appended to it. In + * contrast, the put method replaces the previous value. + * + * If only one value is accumulated that is not a JSONArray, then the result + * will be the same as using put. But if multiple values are accumulated, + * then the result will be like append. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the value is an invalid number or if the key is null. + */ + public JSONObject accumulate(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, + value instanceof JSONArray ? new JSONArray().put(value) + : value); + } else if (object instanceof JSONArray) { + ((JSONArray) object).put(value); + } else { + this.put(key, new JSONArray().put(object).put(value)); + } + return this; + } + + /** + * Append values to the array under a key. If the key does not exist in the + * JSONObject, then the key is put in the JSONObject with its value being a + * JSONArray containing the value parameter. If the key was already + * associated with a JSONArray, then the value parameter is appended to it. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the key is null or if the current value associated with + * the key is not a JSONArray. + */ + public JSONObject append(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, new JSONArray().put(value)); + } else if (object instanceof JSONArray) { + this.put(key, ((JSONArray) object).put(value)); + } else { + throw new JSONException("JSONObject[" + key + + "] is not a JSONArray."); + } + return this; + } + + /** + * Produce a string from a double. The string "null" will be returned if the + * number is not finite. + * + * @param d + * A double. + * @return A String. + */ + public static String doubleToString(double d) { + if (Double.isInfinite(d) || Double.isNaN(d)) { + return "null"; + } + +// Shave off trailing zeros and decimal point, if possible. + + String string = Double.toString(d); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get the value object associated with a key. + * + * @param key + * A key string. + * @return The object associated with the key. + * @throws JSONException + * if the key is not found. + */ + public Object get(String key) throws JSONException { + if (key == null) { + throw new JSONException("Null key."); + } + Object object = this.opt(key); + if (object == null) { + throw new JSONException("JSONObject[" + quote(key) + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with a key. + * + * @param key + * A key string. + * @return The truth. + * @throws JSONException + * if the value is not a Boolean or the String "true" or + * "false". + */ + public boolean getBoolean(String key) throws JSONException { + Object object = this.get(key); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a Boolean."); + } + + /** + * Get the double value associated with a key. + * + * @param key + * A key string. + * @return The numeric value. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. + */ + public double getDouble(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a number."); + } + } + + /** + * Get the int value associated with a key. + * + * @param key + * A key string. + * @return The integer value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to an integer. + */ + public int getInt(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not an int."); + } + } + + /** + * Get the JSONArray value associated with a key. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONArray. + */ + public JSONArray getJSONArray(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONArray."); + } + + /** + * Get the JSONObject value associated with a key. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONObject. + */ + public JSONObject getJSONObject(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONObject."); + } + + /** + * Get the long value associated with a key. + * + * @param key + * A key string. + * @return The long value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to a long. + */ + public long getLong(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a long."); + } + } + + /** + * Get an array of field names from a JSONObject. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(JSONObject jo) { + int length = jo.length(); + if (length == 0) { + return null; + } + Iterator iterator = jo.keys(); + String[] names = new String[length]; + int i = 0; + while (iterator.hasNext()) { + names[i] = (String) iterator.next(); + i += 1; + } + return names; + } + + /** + * Get an array of field names from an Object. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(Object object) { + if (object == null) { + return null; + } + Class klass = object.getClass(); + Field[] fields = klass.getFields(); + int length = fields.length; + if (length == 0) { + return null; + } + String[] names = new String[length]; + for (int i = 0; i < length; i += 1) { + names[i] = fields[i].getName(); + } + return names; + } + + /** + * Get the string associated with a key. + * + * @param key + * A key string. + * @return A string which is the value. + * @throws JSONException + * if there is no string value for the key. + */ + public String getString(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONObject[" + quote(key) + "] not a string."); + } + + /** + * Determine if the JSONObject contains a specific key. + * + * @param key + * A key string. + * @return true if the key exists in the JSONObject. + */ + public boolean has(String key) { + return this.map.containsKey(key); + } + + /** + * Increment a property of a JSONObject. If there is no such property, + * create one with a value of 1. If there is such a property, and if it is + * an Integer, Long, Double, or Float, then add one to it. + * + * @param key + * A key string. + * @return this. + * @throws JSONException + * If there is already a property with this name that is not an + * Integer, Long, Double, or Float. + */ + public JSONObject increment(String key) throws JSONException { + Object value = this.opt(key); + if (value == null) { + this.put(key, 1); + } else if (value instanceof Integer) { + this.put(key, ((Integer) value).intValue() + 1); + } else if (value instanceof Long) { + this.put(key, ((Long) value).longValue() + 1); + } else if (value instanceof Double) { + this.put(key, ((Double) value).doubleValue() + 1); + } else if (value instanceof Float) { + this.put(key, ((Float) value).floatValue() + 1); + } else { + throw new JSONException("Unable to increment [" + quote(key) + "]."); + } + return this; + } + + /** + * Determine if the value associated with the key is null or if there is no + * value. + * + * @param key + * A key string. + * @return true if there is no value associated with the key or if the value + * is the JSONObject.NULL object. + */ + public boolean isNull(String key) { + return JSONObject.NULL.equals(this.opt(key)); + } + + /** + * Get an enumeration of the keys of the JSONObject. + * + * @return An iterator of the keys. + */ + public Iterator keys() { + return this.keySet().iterator(); + } + + /** + * Get a set of keys of the JSONObject. + * + * @return A keySet. + */ + public Set keySet() { + return this.map.keySet(); + } + + /** + * Get the number of keys stored in the JSONObject. + * + * @return The number of keys in the JSONObject. + */ + public int length() { + return this.map.size(); + } + + /** + * Produce a JSONArray containing the names of the elements of this + * JSONObject. + * + * @return A JSONArray containing the key strings, or null if the JSONObject + * is empty. + */ + public JSONArray names() { + JSONArray ja = new JSONArray(); + Iterator keys = this.keys(); + while (keys.hasNext()) { + ja.put(keys.next()); + } + return ja.length() == 0 ? null : ja; + } + + /** + * Produce a string from a Number. + * + * @param number + * A Number + * @return A String. + * @throws JSONException + * If n is a non-finite number. + */ + public static String numberToString(Number number) throws JSONException { + if (number == null) { + throw new JSONException("Null pointer"); + } + testValidity(number); + +// Shave off trailing zeros and decimal point, if possible. + + String string = number.toString(); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get an optional value associated with a key. + * + * @param key + * A key string. + * @return An object which is the value, or null if there is no value. + */ + public Object opt(String key) { + return key == null ? null : this.map.get(key); + } + + /** + * Get an optional boolean associated with a key. It returns false if there + * is no such key, or if the value is not Boolean.TRUE or the String "true". + * + * @param key + * A key string. + * @return The truth. + */ + public boolean optBoolean(String key) { + return this.optBoolean(key, false); + } + + /** + * Get an optional boolean associated with a key. It returns the + * defaultValue if there is no such key, or if it is not a Boolean or the + * String "true" or "false" (case insensitive). + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return The truth. + */ + public boolean optBoolean(String key, boolean defaultValue) { + try { + return this.getBoolean(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional double associated with a key, or NaN if there is no such + * key or if its value is not a number. If the value is a string, an attempt + * will be made to evaluate it as a number. + * + * @param key + * A string which is the key. + * @return An object which is the value. + */ + public double optDouble(String key) { + return this.optDouble(key, Double.NaN); + } + + /** + * Get an optional double associated with a key, or the defaultValue if + * there is no such key or if its value is not a number. If the value is a + * string, an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public double optDouble(String key, double defaultValue) { + try { + return this.getDouble(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional int value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public int optInt(String key) { + return this.optInt(key, 0); + } + + /** + * Get an optional int value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public int optInt(String key, int defaultValue) { + try { + return this.getInt(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional JSONArray associated with a key. It returns null if there + * is no such key, or if its value is not a JSONArray. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + */ + public JSONArray optJSONArray(String key) { + Object o = this.opt(key); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get an optional JSONObject associated with a key. It returns null if + * there is no such key, or if its value is not a JSONObject. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + */ + public JSONObject optJSONObject(String key) { + Object object = this.opt(key); + return object instanceof JSONObject ? (JSONObject) object : null; + } + + /** + * Get an optional long value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public long optLong(String key) { + return this.optLong(key, 0); + } + + /** + * Get an optional long value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public long optLong(String key, long defaultValue) { + try { + return this.getLong(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional string associated with a key. It returns an empty string + * if there is no such key. If the value is not a string and is not null, + * then it is converted to a string. + * + * @param key + * A key string. + * @return A string which is the value. + */ + public String optString(String key) { + return this.optString(key, ""); + } + + /** + * Get an optional string associated with a key. It returns the defaultValue + * if there is no such key. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return A string which is the value. + */ + public String optString(String key, String defaultValue) { + Object object = this.opt(key); + return NULL.equals(object) ? defaultValue : object.toString(); + } + + private void populateMap(Object bean) { + Class klass = bean.getClass(); + +// If klass is a System class then set includeSuperClass to false. + + boolean includeSuperClass = klass.getClassLoader() != null; + + Method[] methods = includeSuperClass ? klass.getMethods() : klass + .getDeclaredMethods(); + for (int i = 0; i < methods.length; i += 1) { + try { + Method method = methods[i]; + if (Modifier.isPublic(method.getModifiers())) { + String name = method.getName(); + String key = ""; + if (name.startsWith("get")) { + if ("getClass".equals(name) + || "getDeclaringClass".equals(name)) { + key = ""; + } else { + key = name.substring(3); + } + } else if (name.startsWith("is")) { + key = name.substring(2); + } + if (key.length() > 0 + && Character.isUpperCase(key.charAt(0)) + && method.getParameterTypes().length == 0) { + if (key.length() == 1) { + key = key.toLowerCase(); + } else if (!Character.isUpperCase(key.charAt(1))) { + key = key.substring(0, 1).toLowerCase() + + key.substring(1); + } + + Object result = method.invoke(bean, (Object[]) null); + if (result != null) { + this.map.put(key, wrap(result)); + } + } + } + } catch (Exception ignore) { + } + } + } + + /** + * Put a key/boolean pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A boolean which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, boolean value) throws JSONException { + this.put(key, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONArray which is produced from a Collection. + * + * @param key + * A key string. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Collection value) throws JSONException { + this.put(key, new JSONArray(value)); + return this; + } + + /** + * Put a key/double pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A double which is the value. + * @return this. + * @throws JSONException + * If the key is null or if the number is invalid. + */ + public JSONObject put(String key, double value) throws JSONException { + this.put(key, new Double(value)); + return this; + } + + /** + * Put a key/int pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * An int which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, int value) throws JSONException { + this.put(key, new Integer(value)); + return this; + } + + /** + * Put a key/long pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A long which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, long value) throws JSONException { + this.put(key, new Long(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONObject which is produced from a Map. + * + * @param key + * A key string. + * @param value + * A Map value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Map value) throws JSONException { + this.put(key, new JSONObject(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject. If the value is null, then the + * key will be removed from the JSONObject if it is present. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is non-finite number or if the key is null. + */ + public JSONObject put(String key, Object value) throws JSONException { + String pooled; + if (key == null) { + throw new NullPointerException("Null key."); + } + if (value != null) { + testValidity(value); + pooled = (String) keyPool.get(key); + if (pooled == null) { + if (keyPool.size() >= keyPoolSize) { + keyPool = new HashMap(keyPoolSize); + } + keyPool.put(key, key); + } else { + key = pooled; + } + this.map.put(key, value); + } else { + this.remove(key); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null, and only if there is not already a member with that + * name. + * + * @param key + * @param value + * @return his. + * @throws JSONException + * if the key is a duplicate + */ + public JSONObject putOnce(String key, Object value) throws JSONException { + if (key != null && value != null) { + if (this.opt(key) != null) { + throw new JSONException("Duplicate key \"" + key + "\""); + } + this.put(key, value); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is a non-finite number. + */ + public JSONObject putOpt(String key, Object value) throws JSONException { + if (key != null && value != null) { + this.put(key, value); + } + return this; + } + + /** + * Produce a string in double quotes with backslash sequences in all the + * right places. A backslash will be inserted within = '\u0080' && c < '\u00a0') + || (c >= '\u2000' && c < '\u2100')) { + w.write("\\u"); + hhhh = Integer.toHexString(c); + w.write("0000", 0, 4 - hhhh.length()); + w.write(hhhh); + } else { + w.write(c); + } + } + } + w.write('"'); + return w; + } + + /** + * Remove a name and its value, if present. + * + * @param key + * The name to be removed. + * @return The value that was associated with the name, or null if there was + * no value. + */ + public Object remove(String key) { + return this.map.remove(key); + } + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. + * + * @param string + * A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + Double d; + if (string.equals("")) { + return string; + } + if (string.equalsIgnoreCase("true")) { + return Boolean.TRUE; + } + if (string.equalsIgnoreCase("false")) { + return Boolean.FALSE; + } + if (string.equalsIgnoreCase("null")) { + return JSONObject.NULL; + } + + /* + * If it might be a number, try converting it. If a number cannot be + * produced, then the value will just be a string. + */ + + char b = string.charAt(0); + if ((b >= '0' && b <= '9') || b == '-') { + try { + if (string.indexOf('.') > -1 || string.indexOf('e') > -1 + || string.indexOf('E') > -1) { + d = Double.valueOf(string); + if (!d.isInfinite() && !d.isNaN()) { + return d; + } + } else { + Long myLong = new Long(string); + if (string.equals(myLong.toString())) { + if (myLong.longValue() == myLong.intValue()) { + return new Integer(myLong.intValue()); + } else { + return myLong; + } + } + } + } catch (Exception ignore) { + } + } + return string; + } + + /** + * Throw an exception if the object is a NaN or infinite number. + * + * @param o + * The object to test. + * @throws JSONException + * If o is a non-finite number. + */ + public static void testValidity(Object o) throws JSONException { + if (o != null) { + if (o instanceof Double) { + if (((Double) o).isInfinite() || ((Double) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } else if (o instanceof Float) { + if (((Float) o).isInfinite() || ((Float) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } + } + } + + /** + * Produce a JSONArray containing the values of the members of this + * JSONObject. + * + * @param names + * A JSONArray containing a list of key strings. This determines + * the sequence of the values in the result. + * @return A JSONArray of values. + * @throws JSONException + * If any of the values are non-finite numbers. + */ + public JSONArray toJSONArray(JSONArray names) throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + JSONArray ja = new JSONArray(); + for (int i = 0; i < names.length(); i += 1) { + ja.put(this.opt(names.getString(i))); + } + return ja; + } + + /** + * Make a JSON text of this JSONObject. For compactness, no whitespace is + * added. If this would not result in a syntactically correct JSON text, + * then null will be returned instead. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONObject. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the object contains an invalid number. + */ + public String toString(int indentFactor) throws JSONException { + StringWriter w = new StringWriter(); + synchronized (w.getBuffer()) { + return this.write(w, indentFactor, 0).toString(); + } + } + + /** + * Make a JSON text of an Object value. If the object has an + * value.toJSONString() method, then that method will be used to produce the + * JSON text. The method is required to produce a strictly conforming text. + * If the object does not contain a toJSONString method (which is the most + * common case), then a text will be produced by other means. If the value + * is an array or Collection, then a JSONArray will be made from it and its + * toJSONString method will be called. If the value is a MAP, then a + * JSONObject will be made from it and its toJSONString method will be + * called. Otherwise, the value's toString method will be called, and the + * result will be quoted. + * + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param value + * The value to be serialized. + * @return a printable, displayable, transmittable representation of the + * object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the value is or contains an invalid number. + */ + public static String valueToString(Object value) throws JSONException { + if (value == null || value.equals(null)) { + return "null"; + } + if (value instanceof JSONString) { + Object object; + try { + object = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + if (object instanceof String) { + return (String) object; + } + throw new JSONException("Bad value from toJSONString: " + object); + } + if (value instanceof Number) { + return numberToString((Number) value); + } + if (value instanceof Boolean || value instanceof JSONObject + || value instanceof JSONArray) { + return value.toString(); + } + if (value instanceof Map) { + return new JSONObject((Map) value).toString(); + } + if (value instanceof Collection) { + return new JSONArray((Collection) value).toString(); + } + if (value.getClass().isArray()) { + return new JSONArray(value).toString(); + } + return quote(value.toString()); + } + + /** + * Wrap an object, if necessary. If the object is null, return the NULL + * object. If it is an array or collection, wrap it in a JSONArray. If it is + * a map, wrap it in a JSONObject. If it is a standard property (Double, + * String, et al) then it is already wrapped. Otherwise, if it comes from + * one of the java packages, turn it into a string. And if it doesn't, try + * to wrap it in a JSONObject. If the wrapping fails, then null is returned. + * + * @param object + * The object to wrap + * @return The wrapped value + */ + public static Object wrap(Object object) { + try { + if (object == null) { + return NULL; + } + if (object instanceof JSONObject || object instanceof JSONArray || object instanceof JSONModel + || NULL.equals(object) || object instanceof JSONString + || object instanceof Byte || object instanceof Character + || object instanceof Short || object instanceof Integer + || object instanceof Long || object instanceof Boolean + || object instanceof Float || object instanceof Double + || object instanceof String) { + return object; + } + + if (object instanceof Collection) { + return new JSONArray((Collection) object); + } + if (object.getClass().isArray()) { + return new JSONArray(object); + } + if (object instanceof Map) { + return new JSONObject((Map) object); + } + Package objectPackage = object.getClass().getPackage(); + String objectPackageName = objectPackage != null ? objectPackage + .getName() : ""; + if (objectPackageName.startsWith("java.") + || objectPackageName.startsWith("javax.") + || object.getClass().getClassLoader() == null) { + return object.toString(); + } + return new JSONObject(object); + } catch (Exception exception) { + return null; + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + static final Writer writeValue(Writer writer, Object value, + int indentFactor, int indent) throws JSONException, IOException { + if (value == null || value.equals(null)) { + writer.write("null"); + } else if (value instanceof JSONObject) { + ((JSONObject) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONArray) { + ((JSONArray) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONModel) { + ((JSONModel) value).toJsonObject().write(writer, indentFactor, indent); + } else if (value instanceof Map) { + new JSONObject((Map) value).write(writer, indentFactor, indent); + } else if (value instanceof Collection) { + new JSONArray((Collection) value).write(writer, indentFactor, + indent); + } else if (value.getClass().isArray()) { + new JSONArray(value).write(writer, indentFactor, indent); + } else if (value instanceof Number) { + writer.write(numberToString((Number) value)); + } else if (value instanceof Boolean) { + writer.write(value.toString()); + } else if (value instanceof JSONString) { + Object o; + try { + o = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + writer.write(o != null ? o.toString() : quote(value.toString())); + } else { + quote(value.toString(), writer); + } + return writer; + } + + static final void indent(Writer writer, int indent) throws IOException { + for (int i = 0; i < indent; i += 1) { + writer.write(' '); + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + final int length = this.length(); + Iterator keys = this.keys(); + writer.write('{'); + + if (length == 1) { + Object key = keys.next(); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + while (keys.hasNext()) { + Object key = keys.next(); + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, newindent); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, + newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, indent); + } + writer.write('}'); + return writer; + } catch (IOException exception) { + throw new JSONException(exception); + } + } +} diff --git a/Tubes5/Tubes5server/src/org/json/JSONString.java b/Tubes5/Tubes5server/src/org/json/JSONString.java new file mode 100644 index 00000000..1f2d77dd --- /dev/null +++ b/Tubes5/Tubes5server/src/org/json/JSONString.java @@ -0,0 +1,18 @@ +package org.json; +/** + * The JSONString interface allows a toJSONString() + * method so that a class can change the behavior of + * JSONObject.toString(), JSONArray.toString(), + * and JSONWriter.value(Object). The + * toJSONString method will be used instead of the default behavior + * of using the Object's toString() method and quoting the result. + */ +public interface JSONString { + /** + * The toJSONString method allows a class to produce its own JSON + * serialization. + * + * @return A strictly syntactically correct JSON text. + */ + public String toJSONString(); +} diff --git a/Tubes5/Tubes5server/src/org/json/JSONStringer.java b/Tubes5/Tubes5server/src/org/json/JSONStringer.java new file mode 100644 index 00000000..32c9f7f4 --- /dev/null +++ b/Tubes5/Tubes5server/src/org/json/JSONStringer.java @@ -0,0 +1,78 @@ +package org.json; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.io.StringWriter; + +/** + * JSONStringer provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONStringer can produce one JSON text. + *

+ * A JSONStringer instance provides a value method for appending + * values to the + * text, and a key + * method for adding keys before values in objects. There are array + * and endArray methods that make and bound array values, and + * object and endObject methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting cascade style. For example,

+ * myString = new JSONStringer()
+ *     .object()
+ *         .key("JSON")
+ *         .value("Hello, World!")
+ *     .endObject()
+ *     .toString();
which produces the string
+ * {"JSON":"Hello, World!"}
+ *

+ * The first method called must be array or object. + * There are no methods for adding commas or colons. JSONStringer adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + *

+ * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2008-09-18 + */ +public class JSONStringer extends JSONWriter { + /** + * Make a fresh JSONStringer. It can be used to build one JSON text. + */ + public JSONStringer() { + super(new StringWriter()); + } + + /** + * Return the JSON text. This method is used to obtain the product of the + * JSONStringer instance. It will return null if there was a + * problem in the construction of the JSON text (such as the calls to + * array were not properly balanced with calls to + * endArray). + * @return The JSON text. + */ + public String toString() { + return this.mode == 'd' ? this.writer.toString() : null; + } +} diff --git a/Tubes5/Tubes5server/src/org/json/JSONTokener.java b/Tubes5/Tubes5server/src/org/json/JSONTokener.java new file mode 100644 index 00000000..13c84f1f --- /dev/null +++ b/Tubes5/Tubes5server/src/org/json/JSONTokener.java @@ -0,0 +1,446 @@ +package org.json; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * A JSONTokener takes a source string and extracts characters and tokens from + * it. It is used by the JSONObject and JSONArray constructors to parse + * JSON source strings. + * @author JSON.org + * @version 2012-02-16 + */ +public class JSONTokener { + + private long character; + private boolean eof; + private long index; + private long line; + private char previous; + private Reader reader; + private boolean usePrevious; + + + /** + * Construct a JSONTokener from a Reader. + * + * @param reader A reader. + */ + public JSONTokener(Reader reader) { + this.reader = reader.markSupported() + ? reader + : new BufferedReader(reader); + this.eof = false; + this.usePrevious = false; + this.previous = 0; + this.index = 0; + this.character = 1; + this.line = 1; + } + + + /** + * Construct a JSONTokener from an InputStream. + */ + public JSONTokener(InputStream inputStream) throws JSONException { + this(new InputStreamReader(inputStream)); + } + + + /** + * Construct a JSONTokener from a string. + * + * @param s A source string. + */ + public JSONTokener(String s) { + this(new StringReader(s)); + } + + + /** + * Back up one character. This provides a sort of lookahead capability, + * so that you can test for a digit or letter before attempting to parse + * the next number or identifier. + */ + public void back() throws JSONException { + if (this.usePrevious || this.index <= 0) { + throw new JSONException("Stepping back two steps is not supported"); + } + this.index -= 1; + this.character -= 1; + this.usePrevious = true; + this.eof = false; + } + + + /** + * Get the hex value of a character (base16). + * @param c A character between '0' and '9' or between 'A' and 'F' or + * between 'a' and 'f'. + * @return An int between 0 and 15, or -1 if c was not a hex digit. + */ + public static int dehexchar(char c) { + if (c >= '0' && c <= '9') { + return c - '0'; + } + if (c >= 'A' && c <= 'F') { + return c - ('A' - 10); + } + if (c >= 'a' && c <= 'f') { + return c - ('a' - 10); + } + return -1; + } + + public boolean end() { + return this.eof && !this.usePrevious; + } + + + /** + * Determine if the source string still contains characters that next() + * can consume. + * @return true if not yet at the end of the source. + */ + public boolean more() throws JSONException { + this.next(); + if (this.end()) { + return false; + } + this.back(); + return true; + } + + + /** + * Get the next character in the source string. + * + * @return The next character, or 0 if past the end of the source string. + */ + public char next() throws JSONException { + int c; + if (this.usePrevious) { + this.usePrevious = false; + c = this.previous; + } else { + try { + c = this.reader.read(); + } catch (IOException exception) { + throw new JSONException(exception); + } + + if (c <= 0) { // End of stream + this.eof = true; + c = 0; + } + } + this.index += 1; + if (this.previous == '\r') { + this.line += 1; + this.character = c == '\n' ? 0 : 1; + } else if (c == '\n') { + this.line += 1; + this.character = 0; + } else { + this.character += 1; + } + this.previous = (char) c; + return this.previous; + } + + + /** + * Consume the next character, and check that it matches a specified + * character. + * @param c The character to match. + * @return The character. + * @throws JSONException if the character does not match. + */ + public char next(char c) throws JSONException { + char n = this.next(); + if (n != c) { + throw this.syntaxError("Expected '" + c + "' and instead saw '" + + n + "'"); + } + return n; + } + + + /** + * Get the next n characters. + * + * @param n The number of characters to take. + * @return A string of n characters. + * @throws JSONException + * Substring bounds error if there are not + * n characters remaining in the source string. + */ + public String next(int n) throws JSONException { + if (n == 0) { + return ""; + } + + char[] chars = new char[n]; + int pos = 0; + + while (pos < n) { + chars[pos] = this.next(); + if (this.end()) { + throw this.syntaxError("Substring bounds error"); + } + pos += 1; + } + return new String(chars); + } + + + /** + * Get the next char in the string, skipping whitespace. + * @throws JSONException + * @return A character, or 0 if there are no more characters. + */ + public char nextClean() throws JSONException { + for (;;) { + char c = this.next(); + if (c == 0 || c > ' ') { + return c; + } + } + } + + + /** + * Return the characters up to the next close quote character. + * Backslash processing is done. The formal JSON format does not + * allow strings in single quotes, but an implementation is allowed to + * accept them. + * @param quote The quoting character, either + * " (double quote) or + * ' (single quote). + * @return A String. + * @throws JSONException Unterminated string. + */ + public String nextString(char quote) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + switch (c) { + case 0: + case '\n': + case '\r': + throw this.syntaxError("Unterminated string"); + case '\\': + c = this.next(); + switch (c) { + case 'b': + sb.append('\b'); + break; + case 't': + sb.append('\t'); + break; + case 'n': + sb.append('\n'); + break; + case 'f': + sb.append('\f'); + break; + case 'r': + sb.append('\r'); + break; + case 'u': + sb.append((char)Integer.parseInt(this.next(4), 16)); + break; + case '"': + case '\'': + case '\\': + case '/': + sb.append(c); + break; + default: + throw this.syntaxError("Illegal escape."); + } + break; + default: + if (c == quote) { + return sb.toString(); + } + sb.append(c); + } + } + } + + + /** + * Get the text up but not including the specified character or the + * end of line, whichever comes first. + * @param delimiter A delimiter character. + * @return A string. + */ + public String nextTo(char delimiter) throws JSONException { + StringBuffer sb = new StringBuffer(); + for (;;) { + char c = this.next(); + if (c == delimiter || c == 0 || c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the text up but not including one of the specified delimiter + * characters or the end of line, whichever comes first. + * @param delimiters A set of delimiter characters. + * @return A string, trimmed. + */ + public String nextTo(String delimiters) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + if (delimiters.indexOf(c) >= 0 || c == 0 || + c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the next value. The value can be a Boolean, Double, Integer, + * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. + * @throws JSONException If syntax error. + * + * @return An object. + */ + public Object nextValue() throws JSONException { + char c = this.nextClean(); + String string; + + switch (c) { + case '"': + case '\'': + return this.nextString(c); + case '{': + this.back(); + return new JSONObject(this); + case '[': + this.back(); + return new JSONArray(this); + } + + /* + * Handle unquoted text. This could be the values true, false, or + * null, or it can be a number. An implementation (such as this one) + * is allowed to also accept non-standard forms. + * + * Accumulate characters until we reach the end of the text or a + * formatting character. + */ + + StringBuffer sb = new StringBuffer(); + while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { + sb.append(c); + c = this.next(); + } + this.back(); + + string = sb.toString().trim(); + if ("".equals(string)) { + throw this.syntaxError("Missing value"); + } + return JSONObject.stringToValue(string); + } + + + /** + * Skip characters until the next character is the requested character. + * If the requested character is not found, no characters are skipped. + * @param to A character to skip to. + * @return The requested character, or zero if the requested character + * is not found. + */ + public char skipTo(char to) throws JSONException { + char c; + try { + long startIndex = this.index; + long startCharacter = this.character; + long startLine = this.line; + this.reader.mark(1000000); + do { + c = this.next(); + if (c == 0) { + this.reader.reset(); + this.index = startIndex; + this.character = startCharacter; + this.line = startLine; + return c; + } + } while (c != to); + } catch (IOException exc) { + throw new JSONException(exc); + } + + this.back(); + return c; + } + + + /** + * Make a JSONException to signal a syntax error. + * + * @param message The error message. + * @return A JSONException object, suitable for throwing + */ + public JSONException syntaxError(String message) { + return new JSONException(message + this.toString()); + } + + + /** + * Make a printable string of this JSONTokener. + * + * @return " at {index} [character {character} line {line}]" + */ + public String toString() { + return " at " + this.index + " [character " + this.character + " line " + + this.line + "]"; + } +} diff --git a/Tubes5/Tubes5server/src/org/json/JSONWriter.java b/Tubes5/Tubes5server/src/org/json/JSONWriter.java new file mode 100644 index 00000000..35b60d90 --- /dev/null +++ b/Tubes5/Tubes5server/src/org/json/JSONWriter.java @@ -0,0 +1,327 @@ +package org.json; + +import java.io.IOException; +import java.io.Writer; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * JSONWriter provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONWriter can produce one JSON text. + *

+ * A JSONWriter instance provides a value method for appending + * values to the + * text, and a key + * method for adding keys before values in objects. There are array + * and endArray methods that make and bound array values, and + * object and endObject methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting a cascade style. For example,

+ * new JSONWriter(myWriter)
+ *     .object()
+ *         .key("JSON")
+ *         .value("Hello, World!")
+ *     .endObject();
which writes
+ * {"JSON":"Hello, World!"}
+ *

+ * The first method called must be array or object. + * There are no methods for adding commas or colons. JSONWriter adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + *

+ * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2011-11-24 + */ +public class JSONWriter { + private static final int maxdepth = 200; + + /** + * The comma flag determines if a comma should be output before the next + * value. + */ + private boolean comma; + + /** + * The current mode. Values: + * 'a' (array), + * 'd' (done), + * 'i' (initial), + * 'k' (key), + * 'o' (object). + */ + protected char mode; + + /** + * The object/array stack. + */ + private final JSONObject stack[]; + + /** + * The stack top index. A value of 0 indicates that the stack is empty. + */ + private int top; + + /** + * The writer that will receive the output. + */ + protected Writer writer; + + /** + * Make a fresh JSONWriter. It can be used to build one JSON text. + */ + public JSONWriter(Writer w) { + this.comma = false; + this.mode = 'i'; + this.stack = new JSONObject[maxdepth]; + this.top = 0; + this.writer = w; + } + + /** + * Append a value. + * @param string A string value. + * @return this + * @throws JSONException If the value is out of sequence. + */ + private JSONWriter append(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null pointer"); + } + if (this.mode == 'o' || this.mode == 'a') { + try { + if (this.comma && this.mode == 'a') { + this.writer.write(','); + } + this.writer.write(string); + } catch (IOException e) { + throw new JSONException(e); + } + if (this.mode == 'o') { + this.mode = 'k'; + } + this.comma = true; + return this; + } + throw new JSONException("Value out of sequence."); + } + + /** + * Begin appending a new array. All values until the balancing + * endArray will be appended to this array. The + * endArray method must be called to mark the array's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter array() throws JSONException { + if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { + this.push(null); + this.append("["); + this.comma = false; + return this; + } + throw new JSONException("Misplaced array."); + } + + /** + * End something. + * @param mode Mode + * @param c Closing character + * @return this + * @throws JSONException If unbalanced. + */ + private JSONWriter end(char mode, char c) throws JSONException { + if (this.mode != mode) { + throw new JSONException(mode == 'a' + ? "Misplaced endArray." + : "Misplaced endObject."); + } + this.pop(mode); + try { + this.writer.write(c); + } catch (IOException e) { + throw new JSONException(e); + } + this.comma = true; + return this; + } + + /** + * End an array. This method most be called to balance calls to + * array. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endArray() throws JSONException { + return this.end('a', ']'); + } + + /** + * End an object. This method most be called to balance calls to + * object. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endObject() throws JSONException { + return this.end('k', '}'); + } + + /** + * Append a key. The key will be associated with the next value. In an + * object, every value must be preceded by a key. + * @param string A key string. + * @return this + * @throws JSONException If the key is out of place. For example, keys + * do not belong in arrays or if the key is null. + */ + public JSONWriter key(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null key."); + } + if (this.mode == 'k') { + try { + this.stack[this.top - 1].putOnce(string, Boolean.TRUE); + if (this.comma) { + this.writer.write(','); + } + this.writer.write(JSONObject.quote(string)); + this.writer.write(':'); + this.comma = false; + this.mode = 'o'; + return this; + } catch (IOException e) { + throw new JSONException(e); + } + } + throw new JSONException("Misplaced key."); + } + + + /** + * Begin appending a new object. All keys and values until the balancing + * endObject will be appended to this object. The + * endObject method must be called to mark the object's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter object() throws JSONException { + if (this.mode == 'i') { + this.mode = 'o'; + } + if (this.mode == 'o' || this.mode == 'a') { + this.append("{"); + this.push(new JSONObject()); + this.comma = false; + return this; + } + throw new JSONException("Misplaced object."); + + } + + + /** + * Pop an array or object scope. + * @param c The scope to close. + * @throws JSONException If nesting is wrong. + */ + private void pop(char c) throws JSONException { + if (this.top <= 0) { + throw new JSONException("Nesting error."); + } + char m = this.stack[this.top - 1] == null ? 'a' : 'k'; + if (m != c) { + throw new JSONException("Nesting error."); + } + this.top -= 1; + this.mode = this.top == 0 + ? 'd' + : this.stack[this.top - 1] == null + ? 'a' + : 'k'; + } + + /** + * Push an array or object scope. + * @param c The scope to open. + * @throws JSONException If nesting is too deep. + */ + private void push(JSONObject jo) throws JSONException { + if (this.top >= maxdepth) { + throw new JSONException("Nesting too deep."); + } + this.stack[this.top] = jo; + this.mode = jo == null ? 'a' : 'k'; + this.top += 1; + } + + + /** + * Append either the value true or the value + * false. + * @param b A boolean. + * @return this + * @throws JSONException + */ + public JSONWriter value(boolean b) throws JSONException { + return this.append(b ? "true" : "false"); + } + + /** + * Append a double value. + * @param d A double. + * @return this + * @throws JSONException If the number is not finite. + */ + public JSONWriter value(double d) throws JSONException { + return this.value(new Double(d)); + } + + /** + * Append a long value. + * @param l A long. + * @return this + * @throws JSONException + */ + public JSONWriter value(long l) throws JSONException { + return this.append(Long.toString(l)); + } + + + /** + * Append an object value. + * @param object The object to append. It can be null, or a Boolean, Number, + * String, JSONObject, or JSONArray, or an object that implements JSONString. + * @return this + * @throws JSONException If the value is out of sequence. + */ + public JSONWriter value(Object object) throws JSONException { + return this.append(JSONObject.valueToString(object)); + } +} diff --git a/Tubes5/tubes5/build.xml b/Tubes5/tubes5/build.xml new file mode 100644 index 00000000..80a01ba3 --- /dev/null +++ b/Tubes5/tubes5/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project tubes5. + + + diff --git a/Tubes5/tubes5/build/built-jar.properties b/Tubes5/tubes5/build/built-jar.properties new file mode 100644 index 00000000..c3cb2910 --- /dev/null +++ b/Tubes5/tubes5/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 20 May 2013 20:19:12 +0700 + + +C\:\\Users\\Aji\\Documents\\NetBeansProjects\\tubes5= diff --git a/Tubes5/tubes5/build/classes/.netbeans_automatic_build b/Tubes5/tubes5/build/classes/.netbeans_automatic_build new file mode 100644 index 00000000..e69de29b diff --git a/Tubes5/tubes5/build/classes/.netbeans_update_resources b/Tubes5/tubes5/build/classes/.netbeans_update_resources new file mode 100644 index 00000000..e69de29b diff --git a/Tubes5/tubes5/build/classes/AnimationCanvas.class b/Tubes5/tubes5/build/classes/AnimationCanvas.class new file mode 100644 index 00000000..69390307 Binary files /dev/null and b/Tubes5/tubes5/build/classes/AnimationCanvas.class differ diff --git a/Tubes5/tubes5/build/classes/Controller/Controller.class b/Tubes5/tubes5/build/classes/Controller/Controller.class new file mode 100644 index 00000000..a79d076c Binary files /dev/null and b/Tubes5/tubes5/build/classes/Controller/Controller.class differ diff --git a/Tubes5/tubes5/build/classes/ImageUtils.class b/Tubes5/tubes5/build/classes/ImageUtils.class new file mode 100644 index 00000000..d790bf18 Binary files /dev/null and b/Tubes5/tubes5/build/classes/ImageUtils.class differ diff --git a/Tubes5/tubes5/build/classes/Model/Task.class b/Tubes5/tubes5/build/classes/Model/Task.class new file mode 100644 index 00000000..de415913 Binary files /dev/null and b/Tubes5/tubes5/build/classes/Model/Task.class differ diff --git a/Tubes5/tubes5/build/classes/Program.class b/Tubes5/tubes5/build/classes/Program.class new file mode 100644 index 00000000..0277ea65 Binary files /dev/null and b/Tubes5/tubes5/build/classes/Program.class differ diff --git a/Tubes5/tubes5/build/classes/ShowMovingDialogAction$1.class b/Tubes5/tubes5/build/classes/ShowMovingDialogAction$1.class new file mode 100644 index 00000000..32889bc0 Binary files /dev/null and b/Tubes5/tubes5/build/classes/ShowMovingDialogAction$1.class differ diff --git a/Tubes5/tubes5/build/classes/ShowtestAction$1.class b/Tubes5/tubes5/build/classes/ShowtestAction$1.class new file mode 100644 index 00000000..147670fe Binary files /dev/null and b/Tubes5/tubes5/build/classes/ShowtestAction$1.class differ diff --git a/Tubes5/tubes5/build/classes/ShowtestAction.class b/Tubes5/tubes5/build/classes/ShowtestAction.class new file mode 100644 index 00000000..c6f19018 Binary files /dev/null and b/Tubes5/tubes5/build/classes/ShowtestAction.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONArray.class b/Tubes5/tubes5/build/classes/org/json/JSONArray.class new file mode 100644 index 00000000..3db455ff Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONArray.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONException.class b/Tubes5/tubes5/build/classes/org/json/JSONException.class new file mode 100644 index 00000000..a6421311 Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONException.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONModel.class b/Tubes5/tubes5/build/classes/org/json/JSONModel.class new file mode 100644 index 00000000..da7b0861 Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONModel.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONObject$1.class b/Tubes5/tubes5/build/classes/org/json/JSONObject$1.class new file mode 100644 index 00000000..91808fbe Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONObject$1.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONObject$Null.class b/Tubes5/tubes5/build/classes/org/json/JSONObject$Null.class new file mode 100644 index 00000000..7f654f4e Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONObject$Null.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONObject.class b/Tubes5/tubes5/build/classes/org/json/JSONObject.class new file mode 100644 index 00000000..790c9a12 Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONObject.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONString.class b/Tubes5/tubes5/build/classes/org/json/JSONString.class new file mode 100644 index 00000000..7fff2574 Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONString.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONStringer.class b/Tubes5/tubes5/build/classes/org/json/JSONStringer.class new file mode 100644 index 00000000..22e326ce Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONStringer.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONTokener.class b/Tubes5/tubes5/build/classes/org/json/JSONTokener.class new file mode 100644 index 00000000..1d06cb25 Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONTokener.class differ diff --git a/Tubes5/tubes5/build/classes/org/json/JSONWriter.class b/Tubes5/tubes5/build/classes/org/json/JSONWriter.class new file mode 100644 index 00000000..bfa1d239 Binary files /dev/null and b/Tubes5/tubes5/build/classes/org/json/JSONWriter.class differ diff --git a/Tubes5/tubes5/build/classes/test$1.class b/Tubes5/tubes5/build/classes/test$1.class new file mode 100644 index 00000000..219e07aa Binary files /dev/null and b/Tubes5/tubes5/build/classes/test$1.class differ diff --git a/Tubes5/tubes5/build/classes/test.class b/Tubes5/tubes5/build/classes/test.class new file mode 100644 index 00000000..6df50d76 Binary files /dev/null and b/Tubes5/tubes5/build/classes/test.class differ diff --git a/Tubes5/tubes5/build/classes/test.rs b/Tubes5/tubes5/build/classes/test.rs new file mode 100644 index 00000000..f82c18be --- /dev/null +++ b/Tubes5/tubes5/build/classes/test.rs @@ -0,0 +1,7 @@ +ShowtestAction +ShowMovingDialogAction$1 +test +MovingDialog +MovingDialog$1 +ShowMovingDialogAction +ShowtestAction$1 diff --git a/Tubes5/tubes5/build/classes/test2$1.class b/Tubes5/tubes5/build/classes/test2$1.class new file mode 100644 index 00000000..df16ff87 Binary files /dev/null and b/Tubes5/tubes5/build/classes/test2$1.class differ diff --git a/Tubes5/tubes5/build/classes/test2$ButtonListener.class b/Tubes5/tubes5/build/classes/test2$ButtonListener.class new file mode 100644 index 00000000..221c4278 Binary files /dev/null and b/Tubes5/tubes5/build/classes/test2$ButtonListener.class differ diff --git a/Tubes5/tubes5/build/classes/test2.class b/Tubes5/tubes5/build/classes/test2.class new file mode 100644 index 00000000..f2db924d Binary files /dev/null and b/Tubes5/tubes5/build/classes/test2.class differ diff --git a/Tubes5/tubes5/build/classes/test2.rs b/Tubes5/tubes5/build/classes/test2.rs new file mode 100644 index 00000000..85f205e8 --- /dev/null +++ b/Tubes5/tubes5/build/classes/test2.rs @@ -0,0 +1,2 @@ +AnimationCanvas +test2 diff --git a/Tubes5/tubes5/build/classes/tubes5/Tubes5.class b/Tubes5/tubes5/build/classes/tubes5/Tubes5.class new file mode 100644 index 00000000..591a0eac Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/Tubes5.class differ diff --git a/Tubes5/tubes5/build/classes/tubes5/background.png b/Tubes5/tubes5/build/classes/tubes5/background.png new file mode 100644 index 00000000..1902c77c Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/background.png differ diff --git a/Tubes5/tubes5/build/classes/tubes5/front.png b/Tubes5/tubes5/build/classes/tubes5/front.png new file mode 100644 index 00000000..45b5ada4 Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/front.png differ diff --git a/Tubes5/tubes5/build/classes/tubes5/list.png b/Tubes5/tubes5/build/classes/tubes5/list.png new file mode 100644 index 00000000..b816e7e2 Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/list.png differ diff --git a/Tubes5/tubes5/build/classes/tubes5/login$1.class b/Tubes5/tubes5/build/classes/tubes5/login$1.class new file mode 100644 index 00000000..9943a1d4 Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/login$1.class differ diff --git a/Tubes5/tubes5/build/classes/tubes5/login$2.class b/Tubes5/tubes5/build/classes/tubes5/login$2.class new file mode 100644 index 00000000..039ae925 Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/login$2.class differ diff --git a/Tubes5/tubes5/build/classes/tubes5/login$3.class b/Tubes5/tubes5/build/classes/tubes5/login$3.class new file mode 100644 index 00000000..bbcbedc6 Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/login$3.class differ diff --git a/Tubes5/tubes5/build/classes/tubes5/login$4.class b/Tubes5/tubes5/build/classes/tubes5/login$4.class new file mode 100644 index 00000000..1fec6612 Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/login$4.class differ diff --git a/Tubes5/tubes5/build/classes/tubes5/login$5.class b/Tubes5/tubes5/build/classes/tubes5/login$5.class new file mode 100644 index 00000000..10ffa27e Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/login$5.class differ diff --git a/Tubes5/tubes5/build/classes/tubes5/login$6.class b/Tubes5/tubes5/build/classes/tubes5/login$6.class new file mode 100644 index 00000000..266510f0 Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/login$6.class differ diff --git a/Tubes5/tubes5/build/classes/tubes5/login$7.class b/Tubes5/tubes5/build/classes/tubes5/login$7.class new file mode 100644 index 00000000..6dc865a1 Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/login$7.class differ diff --git a/Tubes5/tubes5/build/classes/tubes5/login.class b/Tubes5/tubes5/build/classes/tubes5/login.class new file mode 100644 index 00000000..6b0c3fe4 Binary files /dev/null and b/Tubes5/tubes5/build/classes/tubes5/login.class differ diff --git a/Tubes5/tubes5/build/classes/tubes5/login.form b/Tubes5/tubes5/build/classes/tubes5/login.form new file mode 100644 index 00000000..6fcb4c59 --- /dev/null +++ b/Tubes5/tubes5/build/classes/tubes5/login.form @@ -0,0 +1,288 @@ + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="80" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="100" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="20" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + </TableColumnModel> + </Property> + <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor"> + <TableHeader reorderingAllowed="true" resizingAllowed="true"/> + </Property> + </Properties> + </Component> + </SubComponents> + </Container> + <Component class="javax.swing.JLabel" name="jLabel8"> + <Properties> + <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> + <Image iconType="2" name="D:\list.png"/> + </Property> + <Property name="toolTipText" type="java.lang.String" value=""/> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="10" y="10" width="780" height="458"/> + </Constraint> + </Constraints> + </Component> + </SubComponents> + </Container> + <Component class="javax.swing.JLabel" name="jLabel1"> + <Properties> + <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> + <Image iconType="3" name="/tubes5/background.png"/> + </Property> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="0" y="0" width="838" height="-1"/> + </Constraint> + </Constraints> + </Component> + </SubComponents> +</Form> diff --git a/Tubes5/tubes5/dist/README.TXT b/Tubes5/tubes5/dist/README.TXT new file mode 100644 index 00000000..4f40abec --- /dev/null +++ b/Tubes5/tubes5/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "tubes5.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/Tubes5/tubes5/dist/tubes5.jar b/Tubes5/tubes5/dist/tubes5.jar new file mode 100644 index 00000000..d4d5a8d7 Binary files /dev/null and b/Tubes5/tubes5/dist/tubes5.jar differ diff --git a/Tubes5/tubes5/kennyazrinaload.out b/Tubes5/tubes5/kennyazrinaload.out new file mode 100644 index 00000000..029de79f --- /dev/null +++ b/Tubes5/tubes5/kennyazrinaload.out @@ -0,0 +1,7 @@ +5 +{"tag_list":["tag3","halo"," pulang","test2","test3"],"task_creator":"sharonloh","task_name":"CCC","task_status":"1","task_id":"4","task_deadline":"2013-02-12","task_category":"Household"} +{"tag_list":["lalala"," liliili"," lululu"],"task_creator":"sharonloh","task_name":"Cinta ","task_status":"1","task_id":"6","task_deadline":"2013-05-03","task_category":"Personal"} +{"tag_list":[],"task_creator":"sharonloh","task_name":"Cuci Mangga","task_status":"1","task_id":"7","task_deadline":"2013-04-30","task_category":"Household"} +{"tag_list":["cuci"," bersih"," bathroom"],"task_creator":"sharonloh","task_name":"Sikat Lantai Kamar Mandi","task_status":"0","task_id":"8","task_deadline":"2013-04-24","task_category":"Household"} +{"tag_list":["sapu","kamar"],"task_creator":"sharonloh","task_name":"Sapu kamar tuan","task_status":"0","task_id":"9","task_deadline":"2013-04-14","task_category":"Household"} +0 diff --git a/Tubes5/tubes5/list.png b/Tubes5/tubes5/list.png new file mode 100644 index 00000000..b816e7e2 Binary files /dev/null and b/Tubes5/tubes5/list.png differ diff --git a/Tubes5/tubes5/lucyhaleload.out b/Tubes5/tubes5/lucyhaleload.out new file mode 100644 index 00000000..aa47d0d4 --- /dev/null +++ b/Tubes5/tubes5/lucyhaleload.out @@ -0,0 +1,2 @@ +0 +0 diff --git a/Tubes5/tubes5/manifest.mf b/Tubes5/tubes5/manifest.mf new file mode 100644 index 00000000..328e8e5b --- /dev/null +++ b/Tubes5/tubes5/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Tubes5/tubes5/nbproject/build-impl.xml b/Tubes5/tubes5/nbproject/build-impl.xml new file mode 100644 index 00000000..7053f751 --- /dev/null +++ b/Tubes5/tubes5/nbproject/build-impl.xml @@ -0,0 +1,1411 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +*** GENERATED FROM project.xml - DO NOT EDIT *** +*** EDIT ../build.xml INSTEAD *** + +For the purpose of easier reading the script +is divided into following sections: + + - initialization + - compilation + - jar + - execution + - debugging + - javadoc + - test compilation + - test execution + - test debugging + - applet + - cleanup + + --> +<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="tubes5-impl"> + <fail message="Please build using Ant 1.8.0 or higher."> + <condition> + <not> + <antversion atleast="1.8.0"/> + </not> + </condition> + </fail> + <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/> + <!-- + ====================== + INITIALIZATION SECTION + ====================== + --> + <target name="-pre-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="-pre-init" name="-init-private"> + <property file="nbproject/private/config.properties"/> + <property file="nbproject/private/configs/${config}.properties"/> + <property file="nbproject/private/private.properties"/> + </target> + <target depends="-pre-init,-init-private" name="-init-user"> + <property file="${user.properties.file}"/> + <!-- The two properties below are usually overridden --> + <!-- by the active platform. Just a fallback. --> + <property name="default.javac.source" value="1.4"/> + <property name="default.javac.target" value="1.4"/> + </target> + <target depends="-pre-init,-init-private,-init-user" name="-init-project"> + <property file="nbproject/configs/${config}.properties"/> + <property file="nbproject/project.properties"/> + </target> + <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init"> + <available file="${manifest.file}" property="manifest.available"/> + <condition property="splashscreen.available"> + <and> + <not> + <equals arg1="${application.splash}" arg2="" trim="true"/> + </not> + <available file="${application.splash}"/> + </and> + </condition> + <condition property="main.class.available"> + <and> + <isset property="main.class"/> + <not> + <equals arg1="${main.class}" arg2="" trim="true"/> + </not> + </and> + </condition> + <condition property="manifest.available+main.class"> + <and> + <isset property="manifest.available"/> + <isset property="main.class.available"/> + </and> + </condition> + <condition property="do.archive"> + <not> + <istrue value="${jar.archive.disabled}"/> + </not> + </condition> + <condition property="do.mkdist"> + <and> + <isset property="do.archive"/> + <isset property="libs.CopyLibs.classpath"/> + <not> + <istrue value="${mkdist.disabled}"/> + </not> + </and> + </condition> + <condition property="manifest.available+main.class+mkdist.available"> + <and> + <istrue value="${manifest.available+main.class}"/> + <isset property="do.mkdist"/> + </and> + </condition> + <condition property="do.archive+manifest.available"> + <and> + <isset property="manifest.available"/> + <istrue value="${do.archive}"/> + </and> + </condition> + <condition property="do.archive+main.class.available"> + <and> + <isset property="main.class.available"/> + <istrue value="${do.archive}"/> + </and> + </condition> + <condition property="do.archive+splashscreen.available"> + <and> + <isset property="splashscreen.available"/> + <istrue value="${do.archive}"/> + </and> + </condition> + <condition property="do.archive+manifest.available+main.class"> + <and> + <istrue value="${manifest.available+main.class}"/> + <istrue value="${do.archive}"/> + </and> + </condition> + <condition property="manifest.available-mkdist.available"> + <or> + <istrue value="${manifest.available}"/> + <isset property="do.mkdist"/> + </or> + </condition> + <condition property="manifest.available+main.class-mkdist.available"> + <or> + <istrue value="${manifest.available+main.class}"/> + <isset property="do.mkdist"/> + </or> + </condition> + <condition property="have.tests"> + <or> + <available file="${test.src.dir}"/> + </or> + </condition> + <condition property="have.sources"> + <or> + <available file="${src.dir}"/> + </or> + </condition> + <condition property="netbeans.home+have.tests"> + <and> + <isset property="netbeans.home"/> + <isset property="have.tests"/> + </and> + </condition> + <condition property="no.javadoc.preview"> + <and> + <isset property="javadoc.preview"/> + <isfalse value="${javadoc.preview}"/> + </and> + </condition> + <property name="run.jvmargs" value=""/> + <property name="run.jvmargs.ide" value=""/> + <property name="javac.compilerargs" value=""/> + <property name="work.dir" value="${basedir}"/> + <condition property="no.deps"> + <and> + <istrue value="${no.dependencies}"/> + </and> + </condition> + <property name="javac.debug" value="true"/> + <property name="javadoc.preview" value="true"/> + <property name="application.args" value=""/> + <property name="source.encoding" value="${file.encoding}"/> + <property name="runtime.encoding" value="${source.encoding}"/> + <condition property="javadoc.encoding.used" value="${javadoc.encoding}"> + <and> + <isset property="javadoc.encoding"/> + <not> + <equals arg1="${javadoc.encoding}" arg2=""/> + </not> + </and> + </condition> + <property name="javadoc.encoding.used" value="${source.encoding}"/> + <property name="includes" value="**"/> + <property name="excludes" value=""/> + <property name="do.depend" value="false"/> + <condition property="do.depend.true"> + <istrue value="${do.depend}"/> + </condition> + <path id="endorsed.classpath.path" path="${endorsed.classpath}"/> + <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'"> + <length length="0" string="${endorsed.classpath}" when="greater"/> + </condition> + <condition else="false" property="jdkBug6558476"> + <and> + <matches pattern="1\.[56]" string="${java.specification.version}"/> + <not> + <os family="unix"/> + </not> + </and> + </condition> + <property name="javac.fork" value="${jdkBug6558476}"/> + <property name="jar.index" value="false"/> + <property name="jar.index.metainf" value="${jar.index}"/> + <property name="copylibs.rebase" value="true"/> + <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/> + <condition property="junit.available"> + <or> + <available classname="org.junit.Test" classpath="${run.test.classpath}"/> + <available classname="junit.framework.Test" classpath="${run.test.classpath}"/> + </or> + </condition> + <condition property="testng.available"> + <available classname="org.testng.annotations.Test" classpath="${run.test.classpath}"/> + </condition> + <condition property="junit+testng.available"> + <and> + <istrue value="${junit.available}"/> + <istrue value="${testng.available}"/> + </and> + </condition> + <condition else="testng" property="testng.mode" value="mixed"> + <istrue value="${junit+testng.available}"/> + </condition> + <condition else="" property="testng.debug.mode" value="-mixed"> + <istrue value="${junit+testng.available}"/> + </condition> + </target> + <target name="-post-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check"> + <fail unless="src.dir">Must set src.dir</fail> + <fail unless="test.src.dir">Must set test.src.dir</fail> + <fail unless="build.dir">Must set build.dir</fail> + <fail unless="dist.dir">Must set dist.dir</fail> + <fail unless="build.classes.dir">Must set build.classes.dir</fail> + <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail> + <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail> + <fail unless="build.test.results.dir">Must set build.test.results.dir</fail> + <fail unless="build.classes.excludes">Must set build.classes.excludes</fail> + <fail unless="dist.jar">Must set dist.jar</fail> + </target> + <target name="-init-macrodef-property"> + <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute name="name"/> + <attribute name="value"/> + <sequential> + <property name="@{name}" value="${@{value}}"/> + </sequential> + </macrodef> + </target> + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors"> + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}" name="classpath"/> + <attribute default="${javac.processorpath}" name="processorpath"/> + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="${javac.debug}" name="debug"/> + <attribute default="${empty.dir}" name="sourcepath"/> + <attribute default="${empty.dir}" name="gensrcdir"/> + <element name="customize" optional="true"/> + <sequential> + <property location="${build.dir}/empty" name="empty.dir"/> + <mkdir dir="${empty.dir}"/> + <mkdir dir="@{apgeneratedsrcdir}"/> + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}"> + <src> + <dirset dir="@{gensrcdir}" erroronmissingdir="false"> + <include name="*"/> + </dirset> + </src> + <classpath> + <path path="@{classpath}"/> + </classpath> + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/> + <compilerarg line="${javac.compilerargs}"/> + <compilerarg value="-processorpath"/> + <compilerarg path="@{processorpath}:${empty.dir}"/> + <compilerarg line="${ap.processors.internal}"/> + <compilerarg line="${annotation.processing.processor.options}"/> + <compilerarg value="-s"/> + <compilerarg path="@{apgeneratedsrcdir}"/> + <compilerarg line="${ap.proc.none.internal}"/> + <customize/> + </javac> + </sequential> + </macrodef> + </target> + <target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal"> + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}" name="classpath"/> + <attribute default="${javac.processorpath}" name="processorpath"/> + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="${javac.debug}" name="debug"/> + <attribute default="${empty.dir}" name="sourcepath"/> + <attribute default="${empty.dir}" name="gensrcdir"/> + <element name="customize" optional="true"/> + <sequential> + <property location="${build.dir}/empty" name="empty.dir"/> + <mkdir dir="${empty.dir}"/> + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}"> + <src> + <dirset dir="@{gensrcdir}" erroronmissingdir="false"> + <include name="*"/> + </dirset> + </src> + <classpath> + <path path="@{classpath}"/> + </classpath> + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/> + <compilerarg line="${javac.compilerargs}"/> + <customize/> + </javac> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac"> + <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}" name="classpath"/> + <sequential> + <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}"> + <classpath> + <path path="@{classpath}"/> + </classpath> + </depend> + </sequential> + </macrodef> + <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${build.classes.dir}" name="destdir"/> + <sequential> + <fail unless="javac.includes">Must set javac.includes</fail> + <pathconvert pathsep="${line.separator}" property="javac.includes.binary"> + <path> + <filelist dir="@{destdir}" files="${javac.includes}"/> + </path> + <globmapper from="*.java" to="*.class"/> + </pathconvert> + <tempfile deleteonexit="true" property="javac.includesfile.binary"/> + <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/> + <delete> + <files includesfile="${javac.includesfile.binary}"/> + </delete> + <delete> + <fileset file="${javac.includesfile.binary}"/> + </delete> + </sequential> + </macrodef> + </target> + <target if="${junit.available}" name="-init-macrodef-junit-init"> + <condition else="false" property="nb.junit.batch" value="true"> + <and> + <istrue value="${junit.available}"/> + <not> + <isset property="test.method"/> + </not> + </and> + </condition> + <condition else="false" property="nb.junit.single" value="true"> + <and> + <istrue value="${junit.available}"/> + <isset property="test.method"/> + </and> + </condition> + </target> + <target name="-init-test-properties"> + <property name="test.binaryincludes" value="<nothing>"/> + <property name="test.binarytestincludes" value=""/> + <property name="test.binaryexcludes" value=""/> + </target> + <target if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}"> + <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <property name="junit.forkmode" value="perTest"/> + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}"> + <test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg value="-ea"/> + <customize/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-test-properties" if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}"> + <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <property name="junit.forkmode" value="perTest"/> + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}"> + <batchtest todir="${build.test.results.dir}"> + <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}"> + <filename name="@{testincludes}"/> + </fileset> + <fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}"> + <filename name="${test.binarytestincludes}"/> + </fileset> + </batchtest> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg value="-ea"/> + <customize/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit-init,-init-macrodef-junit-single, -init-macrodef-junit-batch" if="${junit.available}" name="-init-macrodef-junit"/> + <target if="${testng.available}" name="-init-macrodef-testng"> + <macrodef name="testng" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}"> + <isset property="test.method"/> + </condition> + <union id="test.set"> + <fileset dir="${test.src.dir}" excludes="@{excludes},**/*.xml,${excludes}" includes="@{includes}"> + <filename name="@{testincludes}"/> + </fileset> + </union> + <taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/> + <testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="tubes5" testname="TestNG tests" workingDir="${work.dir}"> + <xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/> + <propertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </propertyset> + <customize/> + </testng> + </sequential> + </macrodef> + </target> + <target name="-init-macrodef-test-impl"> + <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <echo>No tests executed.</echo> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit" if="${junit.available}" name="-init-macrodef-junit-impl"> + <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <j2seproject3:junit excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize/> + </j2seproject3:junit> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-testng" if="${testng.available}" name="-init-macrodef-testng-impl"> + <macrodef name="test-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <j2seproject3:testng excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize/> + </j2seproject3:testng> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-test-impl,-init-macrodef-junit-impl,-init-macrodef-testng-impl" name="-init-macrodef-test"> + <macrodef name="test" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <sequential> + <j2seproject3:test-impl excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize> + <classpath> + <path path="${run.test.classpath}"/> + </classpath> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg line="${run.jvmargs}"/> + <jvmarg line="${run.jvmargs.ide}"/> + </customize> + </j2seproject3:test-impl> + </sequential> + </macrodef> + </target> + <target if="${junit.available}" name="-init-macrodef-junit-debug" unless="${nb.junit.batch}"> + <macrodef name="junit-debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <property name="junit.forkmode" value="perTest"/> + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}"> + <test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg value="-ea"/> + <jvmarg line="${debug-args-line}"/> + <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/> + <customize/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-test-properties" if="${nb.junit.batch}" name="-init-macrodef-junit-debug-batch"> + <macrodef name="junit-debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <property name="junit.forkmode" value="perTest"/> + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}"> + <batchtest todir="${build.test.results.dir}"> + <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}"> + <filename name="@{testincludes}"/> + </fileset> + <fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}"> + <filename name="${test.binarytestincludes}"/> + </fileset> + </batchtest> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg value="-ea"/> + <jvmarg line="${debug-args-line}"/> + <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/> + <customize/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit-debug,-init-macrodef-junit-debug-batch" if="${junit.available}" name="-init-macrodef-junit-debug-impl"> + <macrodef name="test-debug-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <j2seproject3:junit-debug excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize/> + </j2seproject3:junit-debug> + </sequential> + </macrodef> + </target> + <target if="${testng.available}" name="-init-macrodef-testng-debug"> + <macrodef name="testng-debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <element name="customize2" optional="true"/> + <sequential> + <condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}"> + <isset property="test.method"/> + </condition> + <condition else="-suitename tubes5 -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}"> + <matches pattern=".*\.xml" string="@{testClass}"/> + </condition> + <delete dir="${build.test.results.dir}" quiet="true"/> + <mkdir dir="${build.test.results.dir}"/> + <j2seproject3:debug classname="org.testng.TestNG" classpath="${debug.test.classpath}"> + <customize> + <customize2/> + <jvmarg value="-ea"/> + <arg line="${testng.debug.mode}"/> + <arg line="-d ${build.test.results.dir}"/> + <arg line="-listener org.testng.reporters.VerboseReporter"/> + <arg line="${testng.cmd.args}"/> + </customize> + </j2seproject3:debug> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-testng-debug" if="${testng.available}" name="-init-macrodef-testng-debug-impl"> + <macrodef name="testng-debug-impl" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <element implicit="true" name="customize2" optional="true"/> + <sequential> + <j2seproject3:testng-debug testClass="@{testClass}" testMethod="@{testMethod}"> + <customize2/> + </j2seproject3:testng-debug> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit-debug-impl" if="${junit.available}" name="-init-macrodef-test-debug-junit"> + <macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <sequential> + <j2seproject3:test-debug-impl excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize> + <classpath> + <path path="${run.test.classpath}"/> + </classpath> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg line="${run.jvmargs}"/> + <jvmarg line="${run.jvmargs.ide}"/> + </customize> + </j2seproject3:test-debug-impl> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-testng-debug-impl" if="${testng.available}" name="-init-macrodef-test-debug-testng"> + <macrodef name="test-debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <sequential> + <j2seproject3:testng-debug-impl testClass="@{testClass}" testMethod="@{testMethod}"> + <customize2> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + </customize2> + </j2seproject3:testng-debug-impl> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-test-debug-junit,-init-macrodef-test-debug-testng" name="-init-macrodef-test-debug"/> + <!-- + pre NB7.2 profiling section; consider it deprecated + --> + <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" if="profiler.info.jvmargs.agent" name="profile-init"/> + <target if="profiler.info.jvmargs.agent" name="-profile-pre-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target if="profiler.info.jvmargs.agent" name="-profile-post-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target if="profiler.info.jvmargs.agent" name="-profile-init-macrodef-profile"> + <macrodef name="resolve"> + <attribute name="name"/> + <attribute name="value"/> + <sequential> + <property name="@{name}" value="${env.@{value}}"/> + </sequential> + </macrodef> + <macrodef name="profile"> + <attribute default="${main.class}" name="classname"/> + <element name="customize" optional="true"/> + <sequential> + <property environment="env"/> + <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/> + <java classname="@{classname}" dir="${profiler.info.dir}" fork="true" jvm="${profiler.info.jvm}"> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg value="${profiler.info.jvmargs.agent}"/> + <jvmarg line="${profiler.info.jvmargs}"/> + <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/> + <arg line="${application.args}"/> + <classpath> + <path path="${run.classpath}"/> + </classpath> + <syspropertyset> + <propertyref prefix="run-sys-prop."/> + <mapper from="run-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <customize/> + </java> + </sequential> + </macrodef> + </target> + <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile" if="profiler.info.jvmargs.agent" name="-profile-init-check"> + <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail> + <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail> + </target> + <!-- + end of pre NB7.2 profiling section + --> + <target depends="-init-debug-args" name="-init-macrodef-nbjpda"> + <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute default="${main.class}" name="name"/> + <attribute default="${debug.classpath}" name="classpath"/> + <attribute default="" name="stopclassname"/> + <sequential> + <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}"> + <classpath> + <path path="@{classpath}"/> + </classpath> + </nbjpdastart> + </sequential> + </macrodef> + <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute default="${build.classes.dir}" name="dir"/> + <sequential> + <nbjpdareload> + <fileset dir="@{dir}" includes="${fix.classes}"> + <include name="${fix.includes}*.class"/> + </fileset> + </nbjpdareload> + </sequential> + </macrodef> + </target> + <target name="-init-debug-args"> + <property name="version-output" value="java version "${ant.java.version}"/> + <condition property="have-jdk-older-than-1.4"> + <or> + <contains string="${version-output}" substring="java version "1.0"/> + <contains string="${version-output}" substring="java version "1.1"/> + <contains string="${version-output}" substring="java version "1.2"/> + <contains string="${version-output}" substring="java version "1.3"/> + </or> + </condition> + <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none"> + <istrue value="${have-jdk-older-than-1.4}"/> + </condition> + <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem"> + <os family="windows"/> + </condition> + <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}"> + <isset property="debug.transport"/> + </condition> + </target> + <target depends="-init-debug-args" name="-init-macrodef-debug"> + <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${main.class}" name="classname"/> + <attribute default="${debug.classpath}" name="classpath"/> + <element name="customize" optional="true"/> + <sequential> + <java classname="@{classname}" dir="${work.dir}" fork="true"> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg line="${debug-args-line}"/> + <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/> + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/> + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/> + <jvmarg line="${run.jvmargs}"/> + <jvmarg line="${run.jvmargs.ide}"/> + <classpath> + <path path="@{classpath}"/> + </classpath> + <syspropertyset> + <propertyref prefix="run-sys-prop."/> + <mapper from="run-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <customize/> + </java> + </sequential> + </macrodef> + </target> + <target name="-init-macrodef-java"> + <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1"> + <attribute default="${main.class}" name="classname"/> + <attribute default="${run.classpath}" name="classpath"/> + <attribute default="jvm" name="jvm"/> + <element name="customize" optional="true"/> + <sequential> + <java classname="@{classname}" dir="${work.dir}" fork="true"> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/> + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/> + <jvmarg line="${run.jvmargs}"/> + <jvmarg line="${run.jvmargs.ide}"/> + <classpath> + <path path="@{classpath}"/> + </classpath> + <syspropertyset> + <propertyref prefix="run-sys-prop."/> + <mapper from="run-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <customize/> + </java> + </sequential> + </macrodef> + </target> + <target name="-init-macrodef-copylibs"> + <macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/3"> + <attribute default="${manifest.file}" name="manifest"/> + <element name="customize" optional="true"/> + <sequential> + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/> + <pathconvert property="run.classpath.without.build.classes.dir"> + <path path="${run.classpath}"/> + <map from="${build.classes.dir.resolved}" to=""/> + </pathconvert> + <pathconvert pathsep=" " property="jar.classpath"> + <path path="${run.classpath.without.build.classes.dir}"/> + <chainedmapper> + <flattenmapper/> + <filtermapper> + <replacestring from=" " to="%20"/> + </filtermapper> + <globmapper from="*" to="lib/*"/> + </chainedmapper> + </pathconvert> + <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/> + <copylibs compress="${jar.compress}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}"> + <fileset dir="${build.classes.dir}"/> + <manifest> + <attribute name="Class-Path" value="${jar.classpath}"/> + <customize/> + </manifest> + </copylibs> + </sequential> + </macrodef> + </target> + <target name="-init-presetdef-jar"> + <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1"> + <jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}"> + <j2seproject1:fileset dir="${build.classes.dir}"/> + </jar> + </presetdef> + </target> + <target name="-init-ap-cmdline-properties"> + <property name="annotation.processing.enabled" value="true"/> + <property name="annotation.processing.processors.list" value=""/> + <property name="annotation.processing.processor.options" value=""/> + <property name="annotation.processing.run.all.processors" value="true"/> + <property name="javac.processorpath" value="${javac.classpath}"/> + <property name="javac.test.processorpath" value="${javac.test.classpath}"/> + <condition property="ap.supported.internal" value="true"> + <not> + <matches pattern="1\.[0-5](\..*)?" string="${javac.source}"/> + </not> + </condition> + </target> + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-ap-cmdline-supported"> + <condition else="" property="ap.processors.internal" value="-processor ${annotation.processing.processors.list}"> + <isfalse value="${annotation.processing.run.all.processors}"/> + </condition> + <condition else="" property="ap.proc.none.internal" value="-proc:none"> + <isfalse value="${annotation.processing.enabled}"/> + </condition> + </target> + <target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline"> + <property name="ap.cmd.line.internal" value=""/> + </target> + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-test,-init-macrodef-test-debug,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/> + <!-- + =================== + COMPILATION SECTION + =================== + --> + <target name="-deps-jar-init" unless="built-jar.properties"> + <property location="${build.dir}/built-jar.properties" name="built-jar.properties"/> + <delete file="${built-jar.properties}" quiet="true"/> + </target> + <target if="already.built.jar.${basedir}" name="-warn-already-built-jar"> + <echo level="warn" message="Cycle detected: tubes5 was already built"/> + </target> + <target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps"> + <mkdir dir="${build.dir}"/> + <touch file="${built-jar.properties}" verbose="false"/> + <property file="${built-jar.properties}" prefix="already.built.jar."/> + <antcall target="-warn-already-built-jar"/> + <propertyfile file="${built-jar.properties}"> + <entry key="${basedir}" value=""/> + </propertyfile> + </target> + <target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/> + <target depends="init" name="-check-automatic-build"> + <available file="${build.classes.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/> + </target> + <target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build"> + <antcall target="clean"/> + </target> + <target depends="init,deps-jar" name="-pre-pre-compile"> + <mkdir dir="${build.classes.dir}"/> + </target> + <target name="-pre-compile"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target if="do.depend.true" name="-compile-depend"> + <pathconvert property="build.generated.subdirs"> + <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false"> + <include name="*"/> + </dirset> + </pathconvert> + <j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/> + </target> + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile"> + <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/> + <copy todir="${build.classes.dir}"> + <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target if="has.persistence.xml" name="-copy-persistence-xml"> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy todir="${build.classes.dir}/META-INF"> + <fileset dir="${meta.inf.dir}" includes="persistence.xml orm.xml"/> + </copy> + </target> + <target name="-post-compile"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/> + <target name="-pre-compile-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single"> + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail> + <j2seproject3:force-recompile/> + <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/> + </target> + <target name="-post-compile-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/> + <!-- + ==================== + JAR BUILDING SECTION + ==================== + --> + <target depends="init" name="-pre-pre-jar"> + <dirname file="${dist.jar}" property="dist.jar.dir"/> + <mkdir dir="${dist.jar.dir}"/> + </target> + <target name="-pre-jar"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-without-manifest" unless="manifest.available-mkdist.available"> + <j2seproject1:jar/> + </target> + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class-mkdist.available"> + <j2seproject1:jar manifest="${manifest.file}"/> + </target> + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available"> + <j2seproject1:jar manifest="${manifest.file}"> + <j2seproject1:manifest> + <j2seproject1:attribute name="Main-Class" value="${main.class}"/> + </j2seproject1:manifest> + </j2seproject1:jar> + <echo level="info">To run this application from the command line without Ant, try:</echo> + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/> + <property location="${dist.jar}" name="dist.jar.resolved"/> + <pathconvert property="run.classpath.with.dist.jar"> + <path path="${run.classpath}"/> + <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/> + </pathconvert> + <echo level="info">java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo> + </target> + <target depends="init" if="do.archive" name="-do-jar-with-libraries-create-manifest" unless="manifest.available"> + <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/> + <touch file="${tmp.manifest.file}" verbose="false"/> + </target> + <target depends="init" if="do.archive+manifest.available" name="-do-jar-with-libraries-copy-manifest"> + <tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/> + <copy file="${manifest.file}" tofile="${tmp.manifest.file}"/> + </target> + <target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+main.class.available" name="-do-jar-with-libraries-set-main"> + <manifest file="${tmp.manifest.file}" mode="update"> + <attribute name="Main-Class" value="${main.class}"/> + </manifest> + </target> + <target depends="init,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-with-libraries-set-splashscreen"> + <basename file="${application.splash}" property="splashscreen.basename"/> + <mkdir dir="${build.classes.dir}/META-INF"/> + <copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/> + <manifest file="${tmp.manifest.file}" mode="update"> + <attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/> + </manifest> + </target> + <target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen" if="do.mkdist" name="-do-jar-with-libraries-pack"> + <j2seproject3:copylibs manifest="${tmp.manifest.file}"/> + <echo level="info">To run this application from the command line without Ant, try:</echo> + <property location="${dist.jar}" name="dist.jar.resolved"/> + <echo level="info">java -jar "${dist.jar.resolved}"</echo> + </target> + <target depends="-do-jar-with-libraries-pack" if="do.archive" name="-do-jar-with-libraries-delete-manifest"> + <delete> + <fileset file="${tmp.manifest.file}"/> + </delete> + </target> + <target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-with-libraries-create-manifest,-do-jar-with-libraries-copy-manifest,-do-jar-with-libraries-set-main,-do-jar-with-libraries-set-splashscreen,-do-jar-with-libraries-pack,-do-jar-with-libraries-delete-manifest" name="-do-jar-with-libraries"/> + <target name="-post-jar"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/> + <!-- + ================= + EXECUTION SECTION + ================= + --> + <target depends="init,compile" description="Run a main class." name="run"> + <j2seproject1:java> + <customize> + <arg line="${application.args}"/> + </customize> + </j2seproject1:java> + </target> + <target name="-do-not-recompile"> + <property name="javac.includes.binary" value=""/> + </target> + <target depends="init,compile-single" name="run-single"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <j2seproject1:java classname="${run.class}"/> + </target> + <target depends="init,compile-test-single" name="run-test-with-main"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/> + </target> + <!-- + ================= + DEBUGGING SECTION + ================= + --> + <target depends="init" if="netbeans.home" name="-debug-start-debugger"> + <j2seproject1:nbjpdastart name="${debug.class}"/> + </target> + <target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test"> + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/> + </target> + <target depends="init,compile" name="-debug-start-debuggee"> + <j2seproject3:debug> + <customize> + <arg line="${application.args}"/> + </customize> + </j2seproject3:debug> + </target> + <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/> + <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto"> + <j2seproject1:nbjpdastart stopclassname="${main.class}"/> + </target> + <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/> + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single"> + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail> + <j2seproject3:debug classname="${debug.class}"/> + </target> + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/> + <target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test"> + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail> + <j2seproject3:debug classname="${debug.class}" classpath="${debug.test.classpath}"/> + </target> + <target depends="init,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/> + <target depends="init" name="-pre-debug-fix"> + <fail unless="fix.includes">Must set fix.includes</fail> + <property name="javac.includes" value="${fix.includes}.java"/> + </target> + <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix"> + <j2seproject1:nbjpdareload/> + </target> + <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/> + <!-- + ================= + PROFILING SECTION + ================= + --> + <!-- + pre NB7.2 profiler integration + --> + <target depends="profile-init,compile" description="Profile a project in the IDE." if="profiler.info.jvmargs.agent" name="-profile-pre72"> + <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail> + <nbprofiledirect> + <classpath> + <path path="${run.classpath}"/> + </classpath> + </nbprofiledirect> + <profile/> + </target> + <target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="profiler.info.jvmargs.agent" name="-profile-single-pre72"> + <fail unless="profile.class">Must select one file in the IDE or set profile.class</fail> + <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail> + <nbprofiledirect> + <classpath> + <path path="${run.classpath}"/> + </classpath> + </nbprofiledirect> + <profile classname="${profile.class}"/> + </target> + <target depends="profile-init,compile-single" if="profiler.info.jvmargs.agent" name="-profile-applet-pre72"> + <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail> + <nbprofiledirect> + <classpath> + <path path="${run.classpath}"/> + </classpath> + </nbprofiledirect> + <profile classname="sun.applet.AppletViewer"> + <customize> + <arg value="${applet.url}"/> + </customize> + </profile> + </target> + <target depends="profile-init,compile-test-single" if="profiler.info.jvmargs.agent" name="-profile-test-single-pre72"> + <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail> + <nbprofiledirect> + <classpath> + <path path="${run.test.classpath}"/> + </classpath> + </nbprofiledirect> + <junit dir="${profiler.info.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" jvm="${profiler.info.jvm}" showoutput="true"> + <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/> + <jvmarg value="${profiler.info.jvmargs.agent}"/> + <jvmarg line="${profiler.info.jvmargs}"/> + <test name="${profile.class}"/> + <classpath> + <path path="${run.test.classpath}"/> + </classpath> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + </junit> + </target> + <!-- + end of pre NB72 profiling section + --> + <target if="netbeans.home" name="-profile-check"> + <condition property="profiler.configured"> + <or> + <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-agentpath:"/> + <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-javaagent:"/> + </or> + </condition> + </target> + <target depends="-profile-check,-profile-pre72" description="Profile a project in the IDE." if="profiler.configured" name="profile" unless="profiler.info.jvmargs.agent"> + <startprofiler/> + <antcall target="run"/> + </target> + <target depends="-profile-check,-profile-single-pre72" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-single" unless="profiler.info.jvmargs.agent"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <startprofiler/> + <antcall target="run-single"/> + </target> + <target depends="-profile-test-single-pre72" description="Profile a selected test in the IDE." name="profile-test-single"/> + <target depends="-profile-check" description="Profile a selected test in the IDE." if="profiler.configured" name="profile-test" unless="profiler.info.jvmargs"> + <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail> + <startprofiler/> + <antcall target="test-single"/> + </target> + <target depends="-profile-check" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-test-with-main"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <startprofiler/> + <antcal target="run-test-with-main"/> + </target> + <target depends="-profile-check,-profile-applet-pre72" if="profiler.configured" name="profile-applet" unless="profiler.info.jvmargs.agent"> + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail> + <startprofiler/> + <antcall target="run-applet"/> + </target> + <!-- + =============== + JAVADOC SECTION + =============== + --> + <target depends="init" if="have.sources" name="-javadoc-build"> + <mkdir dir="${dist.javadoc.dir}"/> + <condition else="" property="javadoc.endorsed.classpath.cmd.line.arg" value="-J${endorsed.classpath.cmd.line.arg}"> + <and> + <isset property="endorsed.classpath.cmd.line.arg"/> + <not> + <equals arg1="${endorsed.classpath.cmd.line.arg}" arg2=""/> + </not> + </and> + </condition> + <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}"> + <classpath> + <path path="${javac.classpath}"/> + </classpath> + <fileset dir="${src.dir}" excludes="*.java,${excludes}" includes="${includes}"> + <filename name="**/*.java"/> + </fileset> + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false"> + <include name="**/*.java"/> + <exclude name="*.java"/> + </fileset> + <arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/> + </javadoc> + <copy todir="${dist.javadoc.dir}"> + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}"> + <filename name="**/doc-files/**"/> + </fileset> + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false"> + <include name="**/doc-files/**"/> + </fileset> + </copy> + </target> + <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview"> + <nbbrowse file="${dist.javadoc.dir}/index.html"/> + </target> + <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/> + <!-- + ========================= + TEST COMPILATION SECTION + ========================= + --> + <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test"> + <mkdir dir="${build.test.classes.dir}"/> + </target> + <target name="-pre-compile-test"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target if="do.depend.true" name="-compile-test-depend"> + <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/> + </target> + <target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test"> + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir="${test.src.dir}"/> + <copy todir="${build.test.classes.dir}"> + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target name="-post-compile-test"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/> + <target name="-pre-compile-test-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single"> + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail> + <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/> + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/> + <copy todir="${build.test.classes.dir}"> + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target name="-post-compile-test-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/> + <!-- + ======================= + TEST EXECUTION SECTION + ======================= + --> + <target depends="init" if="have.tests" name="-pre-test-run"> + <mkdir dir="${build.test.results.dir}"/> + </target> + <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run"> + <j2seproject3:test testincludes="**/*Test.java"/> + </target> + <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run"> + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> + </target> + <target depends="init" if="have.tests" name="test-report"/> + <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/> + <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/> + <target depends="init" if="have.tests" name="-pre-test-run-single"> + <mkdir dir="${build.test.results.dir}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single"> + <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail> + <j2seproject3:test excludes="" includes="${test.includes}" testincludes="${test.includes}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single"> + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single-method"> + <fail unless="test.class">Must select some files in the IDE or set test.class</fail> + <fail unless="test.method">Must select some method in the IDE or set test.method</fail> + <j2seproject3:test excludes="" includes="${javac.includes}" testincludes="${test.class}" testmethods="${test.method}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single-method" if="have.tests" name="-post-test-run-single-method"> + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single-method,-post-test-run-single-method" description="Run single unit test." name="test-single-method"/> + <!-- + ======================= + TEST DEBUGGING SECTION + ======================= + --> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test"> + <fail unless="test.class">Must select one file in the IDE or set test.class</fail> + <j2seproject3:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testincludes="${javac.includes}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test-method"> + <fail unless="test.class">Must select one file in the IDE or set test.class</fail> + <fail unless="test.method">Must select some method in the IDE or set test.method</fail> + <j2seproject3:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testMethod="${test.method}" testincludes="${test.class}" testmethods="${test.method}"/> + </target> + <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test"> + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/> + </target> + <target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/> + <target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test-method" name="debug-test-method"/> + <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test"> + <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/> + </target> + <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/> + <!-- + ========================= + APPLET EXECUTION SECTION + ========================= + --> + <target depends="init,compile-single" name="run-applet"> + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail> + <j2seproject1:java classname="sun.applet.AppletViewer"> + <customize> + <arg value="${applet.url}"/> + </customize> + </j2seproject1:java> + </target> + <!-- + ========================= + APPLET DEBUGGING SECTION + ========================= + --> + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet"> + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail> + <j2seproject3:debug classname="sun.applet.AppletViewer"> + <customize> + <arg value="${applet.url}"/> + </customize> + </j2seproject3:debug> + </target> + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/> + <!-- + =============== + CLEANUP SECTION + =============== + --> + <target name="-deps-clean-init" unless="built-clean.properties"> + <property location="${build.dir}/built-clean.properties" name="built-clean.properties"/> + <delete file="${built-clean.properties}" quiet="true"/> + </target> + <target if="already.built.clean.${basedir}" name="-warn-already-built-clean"> + <echo level="warn" message="Cycle detected: tubes5 was already built"/> + </target> + <target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps"> + <mkdir dir="${build.dir}"/> + <touch file="${built-clean.properties}" verbose="false"/> + <property file="${built-clean.properties}" prefix="already.built.clean."/> + <antcall target="-warn-already-built-clean"/> + <propertyfile file="${built-clean.properties}"> + <entry key="${basedir}" value=""/> + </propertyfile> + </target> + <target depends="init" name="-do-clean"> + <delete dir="${build.dir}"/> + <delete dir="${dist.dir}" followsymlinks="false" includeemptydirs="true"/> + </target> + <target name="-post-clean"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/> + <target name="-check-call-dep"> + <property file="${call.built.properties}" prefix="already.built."/> + <condition property="should.call.dep"> + <and> + <not> + <isset property="already.built.${call.subproject}"/> + </not> + <available file="${call.script}"/> + </and> + </condition> + </target> + <target depends="-check-call-dep" if="should.call.dep" name="-maybe-call-dep"> + <ant antfile="${call.script}" inheritall="false" target="${call.target}"> + <propertyset> + <propertyref prefix="transfer."/> + <mapper from="transfer.*" to="*" type="glob"/> + </propertyset> + </ant> + </target> +</project> diff --git a/Tubes5/tubes5/nbproject/genfiles.properties b/Tubes5/tubes5/nbproject/genfiles.properties new file mode 100644 index 00000000..10086758 --- /dev/null +++ b/Tubes5/tubes5/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=1268b09c +build.xml.script.CRC32=5ead8235 +build.xml.stylesheet.CRC32=28e38971@1.56.1.46 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=1268b09c +nbproject/build-impl.xml.script.CRC32=044c2f83 +nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46 diff --git a/Tubes5/tubes5/nbproject/private/private.properties b/Tubes5/tubes5/nbproject/private/private.properties new file mode 100644 index 00000000..673448f4 --- /dev/null +++ b/Tubes5/tubes5/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\Aji\\AppData\\Roaming\\NetBeans\\7.3rc2\\build.properties diff --git a/Tubes5/tubes5/nbproject/private/private.xml b/Tubes5/tubes5/nbproject/private/private.xml new file mode 100644 index 00000000..47509625 --- /dev/null +++ b/Tubes5/tubes5/nbproject/private/private.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> + <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> +</project-private> diff --git a/Tubes5/tubes5/nbproject/project.properties b/Tubes5/tubes5/nbproject/project.properties new file mode 100644 index 00000000..39f385f4 --- /dev/null +++ b/Tubes5/tubes5/nbproject/project.properties @@ -0,0 +1,71 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/tubes5.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=tubes5.Tubes5 +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Tubes5/tubes5/nbproject/project.xml b/Tubes5/tubes5/nbproject/project.xml new file mode 100644 index 00000000..04d0789e --- /dev/null +++ b/Tubes5/tubes5/nbproject/project.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.java.j2seproject</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/j2se-project/3"> + <name>tubes5</name> + <source-roots> + <root id="src.dir"/> + </source-roots> + <test-roots> + <root id="test.src.dir"/> + </test-roots> + </data> + </configuration> +</project> diff --git a/Tubes5/tubes5/nflubisload.out b/Tubes5/tubes5/nflubisload.out new file mode 100644 index 00000000..029de79f --- /dev/null +++ b/Tubes5/tubes5/nflubisload.out @@ -0,0 +1,7 @@ +5 +{"tag_list":["tag3","halo"," pulang","test2","test3"],"task_creator":"sharonloh","task_name":"CCC","task_status":"1","task_id":"4","task_deadline":"2013-02-12","task_category":"Household"} +{"tag_list":["lalala"," liliili"," lululu"],"task_creator":"sharonloh","task_name":"Cinta ","task_status":"1","task_id":"6","task_deadline":"2013-05-03","task_category":"Personal"} +{"tag_list":[],"task_creator":"sharonloh","task_name":"Cuci Mangga","task_status":"1","task_id":"7","task_deadline":"2013-04-30","task_category":"Household"} +{"tag_list":["cuci"," bersih"," bathroom"],"task_creator":"sharonloh","task_name":"Sikat Lantai Kamar Mandi","task_status":"0","task_id":"8","task_deadline":"2013-04-24","task_category":"Household"} +{"tag_list":["sapu","kamar"],"task_creator":"sharonloh","task_name":"Sapu kamar tuan","task_status":"0","task_id":"9","task_deadline":"2013-04-14","task_category":"Household"} +0 diff --git a/Tubes5/tubes5/sharonlohload.out b/Tubes5/tubes5/sharonlohload.out new file mode 100644 index 00000000..029de79f --- /dev/null +++ b/Tubes5/tubes5/sharonlohload.out @@ -0,0 +1,7 @@ +5 +{"tag_list":["tag3","halo"," pulang","test2","test3"],"task_creator":"sharonloh","task_name":"CCC","task_status":"1","task_id":"4","task_deadline":"2013-02-12","task_category":"Household"} +{"tag_list":["lalala"," liliili"," lululu"],"task_creator":"sharonloh","task_name":"Cinta ","task_status":"1","task_id":"6","task_deadline":"2013-05-03","task_category":"Personal"} +{"tag_list":[],"task_creator":"sharonloh","task_name":"Cuci Mangga","task_status":"1","task_id":"7","task_deadline":"2013-04-30","task_category":"Household"} +{"tag_list":["cuci"," bersih"," bathroom"],"task_creator":"sharonloh","task_name":"Sikat Lantai Kamar Mandi","task_status":"0","task_id":"8","task_deadline":"2013-04-24","task_category":"Household"} +{"tag_list":["sapu","kamar"],"task_creator":"sharonloh","task_name":"Sapu kamar tuan","task_status":"0","task_id":"9","task_deadline":"2013-04-14","task_category":"Household"} +0 diff --git a/Tubes5/tubes5/src/Controller/Controller.java b/Tubes5/tubes5/src/Controller/Controller.java new file mode 100644 index 00000000..e1be25cc --- /dev/null +++ b/Tubes5/tubes5/src/Controller/Controller.java @@ -0,0 +1,280 @@ +package Controller; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.Socket; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.json.JSONObject; + +import Model.Task; + +public class Controller { + + private Socket clientSocket; + private static final byte LOGIN = 0; + private static final byte SYNC = 1; + private static final byte UPDATE = 2; + private static final byte LIST = 3; + private static final byte LOGOUT = 9; + private static final byte SUCCESS = 10; + private static final byte FAILED = 11; + private long sessionId; + private String userID; + public boolean isLogin = false; + public List<Task> task_list = new ArrayList<Task>(); + public List<String> update_list = new ArrayList<String>(); + + public long getSessionId() + { + return sessionId; + } + + public boolean connect(String ip, int port) + { + try + { + if (clientSocket != null && clientSocket.isConnected()) + { + clientSocket.close(); + } + clientSocket = new Socket(ip,port); + } + catch (IOException e) + { + e.printStackTrace(); + clientSocket = null; + } + + return (clientSocket != null); + } + + public boolean login(String username, String password) + { + try + { + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + out.write(LOGIN); + + byte[] sendbyte = username.getBytes(); + out.writeInt(sendbyte.length); + out.write(sendbyte); + + sendbyte = password.getBytes(); + out.writeInt(sendbyte.length); + out.write(sendbyte); + byte response = in.readByte(); + if (response == SUCCESS) + { + System.out.println("RESPONSE :: SUCCESS"); + sessionId = in.readLong(); + userID = username; + isLogin = true; + System.out.println("SESSIONID :: " + sessionId); + return true; + } + else if (response == FAILED) + { + System.out.println("RESPONSE :: FAILED"); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + + return false; + } + + public void saveTask() { + try{ + BufferedWriter writer = new BufferedWriter(new FileWriter(userID+"load.out")); + String s = ""; + s += task_list.size() + "\n"; + for (int i = 0; i < task_list.size(); i++) + { + s += task_list.get(i).TaskToString()+ "\n"; + } + + s += update_list.size() + "\n"; + for (int i = 0; i < update_list.size(); i++) + { + s += update_list.get(i)+ "\n"; + } + + writer.write(s); + writer.close(); + }catch(IOException ex){ + ex.printStackTrace(); + } + } + + public void loadTask() { + try{ + task_list.clear(); + BufferedReader reader = new BufferedReader(new FileReader(userID+"load.out")); + String line = reader.readLine(); + int n = Integer.parseInt(line); + if (n > 0) + { + task_list.clear(); + for (int i = 0; i < n; i++) + { + line = reader.readLine(); + JSONObject temp = new JSONObject(line); + task_list.add(new Task(temp)); + } + } + + line = reader.readLine(); + n = Integer.parseInt(line); + if (n > 0) + { + update_list.clear(); + for (int i = 0; i < n; i++) + { + line = reader.readLine(); + update_list.add(line); + } + } + + }catch (Exception e) { + e.printStackTrace(); + } + } + + public void sync() + { + try{ + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + out.writeByte(SYNC); + out.writeLong(sessionId); + + out.writeInt(task_list.size()); + for (int i = 0; i < task_list.size(); i++) + { + String taskTemp = task_list.get(i).TaskToString(); + byte[] sendbyte = taskTemp.getBytes(); + out.writeInt(sendbyte.length); + out.write(sendbyte); + } + + byte response = in.readByte(); + if (response == SUCCESS) + { + System.out.println("BERHASIL SYNC"); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void list(){ + try{ + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + out.writeByte(LIST); + out.writeLong(sessionId); + System.out.println("tunggu response list"); + byte response = in.readByte(); + System.out.println("dapat response list" + response); + if (response == SUCCESS) + { + task_list.clear(); + int n = in.readInt(); + for (int i = 0; i < n; i++) { + byte[] data = new byte[in.readInt()]; + in.readFully(data); + String taskTemp = new String(data); + JSONObject taskObject = new JSONObject(taskTemp.toString()); + task_list.add(new Task(taskObject)); + } + saveTask(); + } + else if (response == FAILED) + { + System.out.println("list to server failed"); + } + } + catch (IOException e) + { + System.out.println("EXCEPTION"); + e.printStackTrace(); + } + } + + public void update(){ + try{ + System.out.println("amsuk update"); + DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream()); + DataInputStream in = new DataInputStream(clientSocket.getInputStream()); + + out.writeByte(UPDATE); + out.writeLong(sessionId); + System.out.println("kirim pesan update"); + int n = update_list.size(); + if (n > 0) + { + out.writeInt(n); + for (int i = 0; i < n; i++) + { + byte[] sendbyte = update_list.get(i).getBytes(); + out.writeInt(sendbyte.length); + out.write(sendbyte); + } + } + else out.writeInt(n); + System.out.println("tunggu response update"); + byte response = in.readByte(); + if (response == SUCCESS) + { + list(); + update_list.clear(); + } + else if (response == FAILED) + { + System.out.println("update to server failed"); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void ubahStatus(int i) + { + String s = task_list.get(i).getId_task() + "," + task_list.get(i).getStatus(); + //ubah juga task_list nya.. + update_list.add(s); + } + + public void logout() + { + saveTask(); + System.out.println("logout"); + isLogin = false; + userID = ""; + sessionId = -1; + } +} diff --git a/Tubes5/tubes5/src/ImageUtils.java b/Tubes5/tubes5/src/ImageUtils.java new file mode 100644 index 00000000..11ce9423 --- /dev/null +++ b/Tubes5/tubes5/src/ImageUtils.java @@ -0,0 +1,145 @@ +// ImageUtils.java +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.HeadlessException; +import java.awt.Image; +import java.awt.Transparency; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.PixelGrabber; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; + +public class ImageUtils { + + public static Image rotateImage(Image img,double degree){ + BufferedImage bufImg = toBufferedImage(img); + double angle = Math.toRadians(degree); + + return tilt(bufImg,angle); + } + + public static BufferedImage tilt(BufferedImage image, double angle) { + double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); + int w = image.getWidth(), h = image.getHeight(); + int neww = (int)Math.floor(w*cos+h*sin), newh = (int)Math.floor(h*cos+w*sin); + GraphicsConfiguration gc = getDefaultConfiguration(); + BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT); + Graphics2D g = result.createGraphics(); + g.translate((neww-w)/2, (newh-h)/2); + g.rotate(angle, w/2, h/2); + g.drawRenderedImage(image, null); + g.dispose(); + return result; + } + + public static GraphicsConfiguration getDefaultConfiguration() { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice gd = ge.getDefaultScreenDevice(); + return gd.getDefaultConfiguration(); + } + + // http://www.exampledepot.com/egs/java.awt.image/Image2Buf.html + // An Image object cannot be converted to a BufferedImage object. + // The closest equivalent is to create a buffered image and then draw the image on the buffered image. + // This example defines a method that does this. + + // This method returns a buffered image with the contents of an image + public static BufferedImage toBufferedImage(Image image) { + if (image instanceof BufferedImage) { + return (BufferedImage)image; + } + + // This code ensures that all the pixels in the image are loaded + image = new ImageIcon(image).getImage(); + + // Determine if the image has transparent pixels; for this method's + // implementation, see e661 Determining If an Image Has Transparent Pixels + boolean hasAlpha = hasAlpha(image); + + // Create a buffered image with a format that's compatible with the screen + BufferedImage bimage = null; + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + try { + // Determine the type of transparency of the new buffered image + int transparency = Transparency.OPAQUE; + if (hasAlpha) { + transparency = Transparency.BITMASK; + } + + // Create the buffered image + GraphicsDevice gs = ge.getDefaultScreenDevice(); + GraphicsConfiguration gc = gs.getDefaultConfiguration(); + bimage = gc.createCompatibleImage( + image.getWidth(null), image.getHeight(null), transparency); + } catch (HeadlessException e) { + // The system does not have a screen + } + + if (bimage == null) { + // Create a buffered image using the default color model + int type = BufferedImage.TYPE_INT_RGB; + if (hasAlpha) { + type = BufferedImage.TYPE_INT_ARGB; + } + bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); + } + + // Copy image to buffered image + Graphics g = bimage.createGraphics(); + + // Paint the image onto the buffered image + g.drawImage(image, 0, 0, null); + g.dispose(); + + return bimage; + } + + // http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html + // This method returns true if the specified image has transparent pixels + public static boolean hasAlpha(Image image) { + // If buffered image, the color model is readily available + if (image instanceof BufferedImage) { + BufferedImage bimage = (BufferedImage)image; + return bimage.getColorModel().hasAlpha(); + } + + // Use a pixel grabber to retrieve the image's color model; + // grabbing a single pixel is usually sufficient + PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); + try { + pg.grabPixels(); + } catch (InterruptedException e) { + } + + // Get the image's color model + ColorModel cm = pg.getColorModel(); + return cm.hasAlpha(); + } + + public ImageUtils(){ + try{ + a = ImageIO.read(new File("D:/gear.png")); + }catch(IOException e){ + + } + } + + private BufferedImage a; + + protected void paintComponent(Graphics g){ + g.drawImage(a, 0, 0, null); + } + + public static void main(String[] args) { + // TODO code application logic here + ImageUtils x = new ImageUtils(); + Graphics g = null; + x.paintComponent(g); + } +} \ No newline at end of file diff --git a/Tubes5/tubes5/src/Model/Task.java b/Tubes5/tubes5/src/Model/Task.java new file mode 100644 index 00000000..173a4f4c --- /dev/null +++ b/Tubes5/tubes5/src/Model/Task.java @@ -0,0 +1,112 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package Model; + +import org.json.JSONArray; +import org.json.JSONObject; + +/** + * + * @author dell + */ +public class Task { + + private String id_task; + private String name; + private String deadline; + private String status; + private String creator; + private String task_category; + private JSONArray tag_list; + + public String getId_task() { + return id_task; + } + + public void setId_task(String id_task) { + this.id_task = id_task; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDeadline() { + return deadline; + } + + public void setDeadline(String deadline) { + this.deadline = deadline; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getTask_category() { + return task_category; + } + + public void setTask_category(String task_category) { + this.task_category = task_category; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public JSONArray getTag_list(){ + return tag_list; + } + + public void setTag_list(JSONArray tag_list){ + this.tag_list = tag_list; + } + + public Task(String id_task, String name, String deadline, String status, String task_category, String creator, JSONArray tag_list) { + this.id_task = id_task; + this.name = name; + this.deadline = deadline; + this.status = status; + this.task_category = task_category; + this.creator = creator; + this.tag_list = tag_list; + } + + public Task(JSONObject jsonObj) { + this.id_task = jsonObj.getString("task_id"); + this.name = jsonObj.getString("task_name"); + this.deadline = jsonObj.getString("task_deadline"); + this.status = jsonObj.getString("task_status"); + this.task_category = jsonObj.getString("task_category"); + this.creator = jsonObj.getString("task_creator"); + this.tag_list = jsonObj.getJSONArray("tag_list"); + } + + public String TaskToString(){ + JSONObject taskObject = new JSONObject(); + taskObject.put("task_id", id_task); + taskObject.put("task_name", name); + taskObject.put("task_status", status); + taskObject.put("task_deadline", deadline); + taskObject.put("task_category", task_category); + taskObject.put("task_creator", creator); + taskObject.put("tag_list", tag_list); + + return taskObject.toString(); + } +} diff --git a/Tubes5/tubes5/src/Program.java b/Tubes5/tubes5/src/Program.java new file mode 100644 index 00000000..b7b8621e --- /dev/null +++ b/Tubes5/tubes5/src/Program.java @@ -0,0 +1,62 @@ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.ObjectInputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; + +import Controller.Controller; +import Model.Task; + +public class Program { + + /** + * @param args + */ + /* + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + Controller controller = new Controller(); + System.out.println("-Connect- " + controller.connect("127.0.0.1", 9000)); + System.out.println("-Login- " + controller.login("sharonloh", "gilagila")); + controller.loadTask(); + if (controller.update_list.size() == 0) + { + System.out.println("daftar update kosong"); + } + controller.update(); + //sc.next(); + controller.list(); + //sc.next(); + + controller.ubahStatus(); + for (int i = 0; i < controller.update_list.size(); i++) + { + System.out.println("daftar update = " + controller.update_list.get(i)); + } + controller.update(); + + //controller.list(); + controller.logout(); + + controller.ubahStatus(); + //controller.saveTask(); + for (int i = 0; i < controller.update_list.size(); i++) + { + System.out.println("daftar update = " + controller.update_list.get(i)); + } + controller.update(); + controller.list(); + //System.out.println("-Login- " + controller.login("sharonloh", "gilagila")); + //controller.logout(); + } +*/ +} diff --git a/Tubes5/tubes5/src/org/json/JSONArray.java b/Tubes5/tubes5/src/org/json/JSONArray.java new file mode 100644 index 00000000..673a9192 --- /dev/null +++ b/Tubes5/tubes5/src/org/json/JSONArray.java @@ -0,0 +1,944 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +/** + * A JSONArray is an ordered sequence of values. Its external text form is a + * string wrapped in square brackets with commas separating the values. The + * internal form is an object having <code>get</code> and <code>opt</code> + * methods for accessing the values by index, and <code>put</code> methods for + * adding or replacing values. The values can be any of these types: + * <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>, + * <code>Number</code>, <code>String</code>, or the + * <code>JSONObject.NULL object</code>. + * <p> + * The constructor can convert a JSON text into a Java object. The + * <code>toString</code> method converts to JSON text. + * <p> + * A <code>get</code> method returns a value if one can be found, and throws an + * exception if one cannot be found. An <code>opt</code> method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + * <p> + * The generic <code>get()</code> and <code>opt()</code> methods return an + * object which you can cast or query for type. There are also typed + * <code>get</code> and <code>opt</code> methods that do type checking and type + * coercion for you. + * <p> + * The texts produced by the <code>toString</code> methods strictly conform to + * JSON syntax rules. The constructors are more forgiving in the texts they will + * accept: + * <ul> + * <li>An extra <code>,</code> <small>(comma)</small> may appear just + * before the closing bracket.</li> + * <li>The <code>null</code> value will be inserted when there is <code>,</code> + *  <small>(comma)</small> elision.</li> + * <li>Strings may be quoted with <code>'</code> <small>(single + * quote)</small>.</li> + * <li>Strings do not need to be quoted at all if they do not begin with a quote + * or single quote, and if they do not contain leading or trailing spaces, and + * if they do not contain any of these characters: + * <code>{ } [ ] / \ : , #</code> and if they do not look like numbers and + * if they are not the reserved words <code>true</code>, <code>false</code>, or + * <code>null</code>.</li> + * </ul> + * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONArray { + + /** + * The arrayList where the JSONArray's properties are kept. + */ + private final ArrayList myArrayList; + + /** + * Construct an empty JSONArray. + */ + public JSONArray() { + this.myArrayList = new ArrayList(); + } + + /** + * Construct a JSONArray from a JSONTokener. + * + * @param x + * A JSONTokener + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(JSONTokener x) throws JSONException { + this(); + if (x.nextClean() != '[') { + throw x.syntaxError("A JSONArray text must start with '['"); + } + if (x.nextClean() != ']') { + x.back(); + for (;;) { + if (x.nextClean() == ',') { + x.back(); + this.myArrayList.add(JSONObject.NULL); + } else { + x.back(); + this.myArrayList.add(x.nextValue()); + } + switch (x.nextClean()) { + case ',': + if (x.nextClean() == ']') { + return; + } + x.back(); + break; + case ']': + return; + default: + throw x.syntaxError("Expected a ',' or ']'"); + } + } + } + } + + /** + * Construct a JSONArray from a source JSON text. + * + * @param source + * A string that begins with <code>[</code> <small>(left + * bracket)</small> and ends with <code>]</code> + *  <small>(right bracket)</small>. + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONArray from a Collection. + * + * @param collection + * A Collection. + */ + public JSONArray(Collection collection) { + this.myArrayList = new ArrayList(); + if (collection != null) { + Iterator iter = collection.iterator(); + while (iter.hasNext()) { + this.myArrayList.add(JSONObject.wrap(iter.next())); + } + } + } + + /** + * Construct a JSONArray from an array + * + * @throws JSONException + * If not an array. + */ + public JSONArray(Object array) throws JSONException { + this(); + if (array.getClass().isArray()) { + int length = Array.getLength(array); + for (int i = 0; i < length; i += 1) { + this.put(JSONObject.wrap(Array.get(array, i))); + } + } else { + throw new JSONException( + "JSONArray initial value should be a string or collection or array."); + } + } + + /** + * Get the object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value. + * @throws JSONException + * If there is no value for the index. + */ + public Object get(int index) throws JSONException { + Object object = this.opt(index); + if (object == null) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with an index. The string values "true" + * and "false" are converted to boolean. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + * @throws JSONException + * If there is no value for the index or if the value is not + * convertible to boolean. + */ + public boolean getBoolean(int index) throws JSONException { + Object object = this.get(index); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONArray[" + index + "] is not a boolean."); + } + + /** + * Get the double value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public double getDouble(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the int value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value is not a number. + */ + public int getInt(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the JSONArray associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONArray value. + * @throws JSONException + * If there is no value for the index. or if the value is not a + * JSONArray + */ + public JSONArray getJSONArray(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); + } + + /** + * Get the JSONObject associated with an index. + * + * @param index + * subscript + * @return A JSONObject value. + * @throws JSONException + * If there is no value for the index or if the value is not a + * JSONObject + */ + public JSONObject getJSONObject(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); + } + + /** + * Get the long value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public long getLong(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the string associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A string value. + * @throws JSONException + * If there is no string value for the index. + */ + public String getString(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONArray[" + index + "] not a string."); + } + + /** + * Determine if the value is null. + * + * @param index + * The index must be between 0 and length() - 1. + * @return true if the value at the index is null, or if there is no value. + */ + public boolean isNull(int index) { + return JSONObject.NULL.equals(this.opt(index)); + } + + /** + * Make a string from the contents of this JSONArray. The + * <code>separator</code> string is inserted between each element. Warning: + * This method assumes that the data structure is acyclical. + * + * @param separator + * A string that will be inserted between the elements. + * @return a string. + * @throws JSONException + * If the array contains an invalid number. + */ + public String join(String separator) throws JSONException { + int len = this.length(); + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < len; i += 1) { + if (i > 0) { + sb.append(separator); + } + sb.append(JSONObject.valueToString(this.myArrayList.get(i))); + } + return sb.toString(); + } + + /** + * Get the number of elements in the JSONArray, included nulls. + * + * @return The length (or size). + */ + public int length() { + return this.myArrayList.size(); + } + + /** + * Get the optional object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value, or null if there is no object at that index. + */ + public Object opt(int index) { + return (index < 0 || index >= this.length()) ? null : this.myArrayList + .get(index); + } + + /** + * Get the optional boolean value associated with an index. It returns false + * if there is no value at that index, or if the value is not Boolean.TRUE + * or the String "true". + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + */ + public boolean optBoolean(int index) { + return this.optBoolean(index, false); + } + + /** + * Get the optional boolean value associated with an index. It returns the + * defaultValue if there is no value at that index or if it is not a Boolean + * or the String "true" or "false" (case insensitive). + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * A boolean default. + * @return The truth. + */ + public boolean optBoolean(int index, boolean defaultValue) { + try { + return this.getBoolean(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional double value associated with an index. NaN is returned + * if there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public double optDouble(int index) { + return this.optDouble(index, Double.NaN); + } + + /** + * Get the optional double value associated with an index. The defaultValue + * is returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * subscript + * @param defaultValue + * The default value. + * @return The value. + */ + public double optDouble(int index, double defaultValue) { + try { + return this.getDouble(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional int value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public int optInt(int index) { + return this.optInt(index, 0); + } + + /** + * Get the optional int value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public int optInt(int index, int defaultValue) { + try { + return this.getInt(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional JSONArray associated with an index. + * + * @param index + * subscript + * @return A JSONArray value, or null if the index has no value, or if the + * value is not a JSONArray. + */ + public JSONArray optJSONArray(int index) { + Object o = this.opt(index); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get the optional JSONObject associated with an index. Null is returned if + * the key is not found, or null if the index has no value, or if the value + * is not a JSONObject. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONObject value. + */ + public JSONObject optJSONObject(int index) { + Object o = this.opt(index); + return o instanceof JSONObject ? (JSONObject) o : null; + } + + /** + * Get the optional long value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public long optLong(int index) { + return this.optLong(index, 0); + } + + /** + * Get the optional long value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public long optLong(int index, long defaultValue) { + try { + return this.getLong(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional string value associated with an index. It returns an + * empty string if there is no value at that index. If the value is not a + * string and is not null, then it is coverted to a string. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A String value. + */ + public String optString(int index) { + return this.optString(index, ""); + } + + /** + * Get the optional string associated with an index. The defaultValue is + * returned if the key is not found. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return A String value. + */ + public String optString(int index, String defaultValue) { + Object object = this.opt(index); + return JSONObject.NULL.equals(object) ? defaultValue : object + .toString(); + } + + /** + * Append a boolean value. This increases the array's length by one. + * + * @param value + * A boolean value. + * @return this. + */ + public JSONArray put(boolean value) { + this.put(value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param value + * A Collection value. + * @return this. + */ + public JSONArray put(Collection value) { + this.put(new JSONArray(value)); + return this; + } + + /** + * Append a double value. This increases the array's length by one. + * + * @param value + * A double value. + * @throws JSONException + * if the value is not finite. + * @return this. + */ + public JSONArray put(double value) throws JSONException { + Double d = new Double(value); + JSONObject.testValidity(d); + this.put(d); + return this; + } + + /** + * Append an int value. This increases the array's length by one. + * + * @param value + * An int value. + * @return this. + */ + public JSONArray put(int value) { + this.put(new Integer(value)); + return this; + } + + /** + * Append an long value. This increases the array's length by one. + * + * @param value + * A long value. + * @return this. + */ + public JSONArray put(long value) { + this.put(new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject which + * is produced from a Map. + * + * @param value + * A Map value. + * @return this. + */ + public JSONArray put(Map value) { + this.put(new JSONObject(value)); + return this; + } + + /** + * Append an object value. This increases the array's length by one. + * + * @param value + * An object value. The value should be a Boolean, Double, + * Integer, JSONArray, JSONObject, Long, or String, or the + * JSONObject.NULL object. + * @return this. + */ + public JSONArray put(Object value) { + this.myArrayList.add(value); + return this; + } + + /** + * Put or replace a boolean value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * A boolean value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, boolean value) throws JSONException { + this.put(index, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param index + * The subscript. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, Collection value) throws JSONException { + this.put(index, new JSONArray(value)); + return this; + } + + /** + * Put or replace a double value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A double value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, double value) throws JSONException { + this.put(index, new Double(value)); + return this; + } + + /** + * Put or replace an int value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * An int value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, int value) throws JSONException { + this.put(index, new Integer(value)); + return this; + } + + /** + * Put or replace a long value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A long value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, long value) throws JSONException { + this.put(index, new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject that + * is produced from a Map. + * + * @param index + * The subscript. + * @param value + * The Map value. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Map value) throws JSONException { + this.put(index, new JSONObject(value)); + return this; + } + + /** + * Put or replace an object value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * The value to put into the array. The value should be a + * Boolean, Double, Integer, JSONArray, JSONObject, Long, or + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Object value) throws JSONException { + JSONObject.testValidity(value); + if (index < 0) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + if (index < this.length()) { + this.myArrayList.set(index, value); + } else { + while (index != this.length()) { + this.put(JSONObject.NULL); + } + this.put(value); + } + return this; + } + + /** + * Remove an index and close the hole. + * + * @param index + * The index of the element to be removed. + * @return The value that was associated with the index, or null if there + * was no value. + */ + public Object remove(int index) { + Object o = this.opt(index); + this.myArrayList.remove(index); + return o; + } + + /** + * Produce a JSONObject by combining a JSONArray of names with the values of + * this JSONArray. + * + * @param names + * A JSONArray containing a list of key strings. These will be + * paired with the values. + * @return A JSONObject, or null if there are no names or if this JSONArray + * has no values. + * @throws JSONException + * If any of the names are null. + */ + public JSONObject toJSONObject(JSONArray names) throws JSONException { + if (names == null || names.length() == 0 || this.length() == 0) { + return null; + } + JSONObject jo = new JSONObject(); + for (int i = 0; i < names.length(); i += 1) { + jo.put(names.getString(i), this.opt(i)); + } + return jo; + } + + /** + * Make a JSON text of this JSONArray. For compactness, no unnecessary + * whitespace is added. If it is not possible to produce a syntactically + * correct JSON text then null will be returned instead. This could occur if + * the array contains an invalid number. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, transmittable representation of the + * array. + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONArray. Warning: This method + * assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, transmittable representation of the + * object, beginning with <code>[</code> <small>(left + * bracket)</small> and ending with <code>]</code> + *  <small>(right bracket)</small>. + * @throws JSONException + */ + public String toString(int indentFactor) throws JSONException { + StringWriter sw = new StringWriter(); + synchronized (sw.getBuffer()) { + return this.write(sw, indentFactor, 0).toString(); + } + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @param indent + * The indention of the top level. + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + int length = this.length(); + writer.write('['); + + if (length == 1) { + JSONObject.writeValue(writer, this.myArrayList.get(0), + indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + + for (int i = 0; i < length; i += 1) { + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, newindent); + JSONObject.writeValue(writer, this.myArrayList.get(i), + indentFactor, newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, indent); + } + writer.write(']'); + return writer; + } catch (IOException e) { + throw new JSONException(e); + } + } +} diff --git a/Tubes5/tubes5/src/org/json/JSONException.java b/Tubes5/tubes5/src/org/json/JSONException.java new file mode 100644 index 00000000..971547e6 --- /dev/null +++ b/Tubes5/tubes5/src/org/json/JSONException.java @@ -0,0 +1,41 @@ +package org.json; + +/** + * The JSONException is thrown by the JSON.org classes when things are amiss. + * + * @author JSON.org + * @version 2013-02-10 + */ +public class JSONException extends RuntimeException { + private static final long serialVersionUID = 0; + private Throwable cause; + + /** + * Constructs a JSONException with an explanatory message. + * + * @param message + * Detail about the reason for the exception. + */ + public JSONException(String message) { + super(message); + } + + /** + * Constructs a new JSONException with the specified cause. + */ + public JSONException(Throwable cause) { + super(cause.getMessage()); + this.cause = cause; + } + + /** + * Returns the cause of this exception or null if the cause is nonexistent + * or unknown. + * + * @returns the cause of this exception or null if the cause is nonexistent + * or unknown. + */ + public Throwable getCause() { + return this.cause; + } +} diff --git a/Tubes5/tubes5/src/org/json/JSONModel.java b/Tubes5/tubes5/src/org/json/JSONModel.java new file mode 100644 index 00000000..637bb38f --- /dev/null +++ b/Tubes5/tubes5/src/org/json/JSONModel.java @@ -0,0 +1,6 @@ +package org.json; + +public abstract class JSONModel { + + public abstract JSONObject toJsonObject(); +} diff --git a/Tubes5/tubes5/src/org/json/JSONObject.java b/Tubes5/tubes5/src/org/json/JSONObject.java new file mode 100644 index 00000000..5666eb57 --- /dev/null +++ b/Tubes5/tubes5/src/org/json/JSONObject.java @@ -0,0 +1,1666 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; + +/** + * A JSONObject is an unordered collection of name/value pairs. Its external + * form is a string wrapped in curly braces with colons between the names and + * values, and commas between the values and names. The internal form is an + * object having <code>get</code> and <code>opt</code> methods for accessing + * the values by name, and <code>put</code> methods for adding or replacing + * values by name. The values can be any of these types: <code>Boolean</code>, + * <code>JSONArray</code>, <code>JSONObject</code>, <code>Number</code>, + * <code>String</code>, or the <code>JSONObject.NULL</code> object. A + * JSONObject constructor can be used to convert an external form JSON text + * into an internal form whose values can be retrieved with the + * <code>get</code> and <code>opt</code> methods, or to convert values into a + * JSON text using the <code>put</code> and <code>toString</code> methods. A + * <code>get</code> method returns a value if one can be found, and throws an + * exception if one cannot be found. An <code>opt</code> method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + * <p> + * The generic <code>get()</code> and <code>opt()</code> methods return an + * object, which you can cast or query for type. There are also typed + * <code>get</code> and <code>opt</code> methods that do type checking and type + * coercion for you. The opt methods differ from the get methods in that they + * do not throw. Instead, they return a specified value, such as null. + * <p> + * The <code>put</code> methods add or replace values in an object. For + * example, + * + * <pre> + * myString = new JSONObject() + * .put("JSON", "Hello, World!").toString(); + * </pre> + * + * produces the string <code>{"JSON": "Hello, World"}</code>. + * <p> + * The texts produced by the <code>toString</code> methods strictly conform to + * the JSON syntax rules. The constructors are more forgiving in the texts they + * will accept: + * <ul> + * <li>An extra <code>,</code> <small>(comma)</small> may appear just + * before the closing brace.</li> + * <li>Strings may be quoted with <code>'</code> <small>(single + * quote)</small>.</li> + * <li>Strings do not need to be quoted at all if they do not begin with a + * quote or single quote, and if they do not contain leading or trailing + * spaces, and if they do not contain any of these characters: + * <code>{ } [ ] / \ : , #</code> and if they do not look like numbers and + * if they are not the reserved words <code>true</code>, <code>false</code>, + * or <code>null</code>.</li> + * </ul> + * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONObject { + /** + * The maximum number of keys in the key pool. + */ + private static final int keyPoolSize = 100; + + /** + * Key pooling is like string interning, but without permanently tying up + * memory. To help conserve memory, storage of duplicated key strings in + * JSONObjects will be avoided by using a key pool to manage unique key + * string objects. This is used by JSONObject.put(string, object). + */ + private static HashMap keyPool = new HashMap(keyPoolSize); + + /** + * JSONObject.NULL is equivalent to the value that JavaScript calls null, + * whilst Java's null is equivalent to the value that JavaScript calls + * undefined. + */ + private static final class Null { + + /** + * There is only intended to be a single instance of the NULL object, + * so the clone method returns itself. + * + * @return NULL. + */ + protected final Object clone() { + return this; + } + + /** + * A Null object is equal to the null value and to itself. + * + * @param object + * An object to test for nullness. + * @return true if the object parameter is the JSONObject.NULL object or + * null. + */ + public boolean equals(Object object) { + return object == null || object == this; + } + + /** + * Get the "null" string value. + * + * @return The string "null". + */ + public String toString() { + return "null"; + } + } + + /** + * The map where the JSONObject's properties are kept. + */ + private final Map map; + + /** + * It is sometimes more convenient and less ambiguous to have a + * <code>NULL</code> object than to use Java's <code>null</code> value. + * <code>JSONObject.NULL.equals(null)</code> returns <code>true</code>. + * <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>. + */ + public static final Object NULL = new Null(); + + /** + * Construct an empty JSONObject. + */ + public JSONObject() { + this.map = new HashMap(); + } + + /** + * Construct a JSONObject from a subset of another JSONObject. An array of + * strings is used to identify the keys that should be copied. Missing keys + * are ignored. + * + * @param jo + * A JSONObject. + * @param names + * An array of strings. + * @throws JSONException + * @exception JSONException + * If a value is a non-finite number or if a name is + * duplicated. + */ + public JSONObject(JSONObject jo, String[] names) { + this(); + for (int i = 0; i < names.length; i += 1) { + try { + this.putOnce(names[i], jo.opt(names[i])); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a JSONTokener. + * + * @param x + * A JSONTokener object containing the source string. + * @throws JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(JSONTokener x) throws JSONException { + this(); + char c; + String key; + + if (x.nextClean() != '{') { + throw x.syntaxError("A JSONObject text must begin with '{'"); + } + for (;;) { + c = x.nextClean(); + switch (c) { + case 0: + throw x.syntaxError("A JSONObject text must end with '}'"); + case '}': + return; + default: + x.back(); + key = x.nextValue().toString(); + } + +// The key is followed by ':'. + + c = x.nextClean(); + if (c != ':') { + throw x.syntaxError("Expected a ':' after a key"); + } + this.putOnce(key, x.nextValue()); + +// Pairs are separated by ','. + + switch (x.nextClean()) { + case ';': + case ',': + if (x.nextClean() == '}') { + return; + } + x.back(); + break; + case '}': + return; + default: + throw x.syntaxError("Expected a ',' or '}'"); + } + } + } + + /** + * Construct a JSONObject from a Map. + * + * @param map + * A map object that can be used to initialize the contents of + * the JSONObject. + * @throws JSONException + */ + public JSONObject(Map map) { + this.map = new HashMap(); + if (map != null) { + Iterator i = map.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry e = (Map.Entry) i.next(); + Object value = e.getValue(); + if (value != null) { + this.map.put(e.getKey(), wrap(value)); + } + } + } + } + + /** + * Construct a JSONObject from an Object using bean getters. It reflects on + * all of the public methods of the object. For each of the methods with no + * parameters and a name starting with <code>"get"</code> or + * <code>"is"</code> followed by an uppercase letter, the method is invoked, + * and a key and the value returned from the getter method are put into the + * new JSONObject. + * + * The key is formed by removing the <code>"get"</code> or <code>"is"</code> + * prefix. If the second remaining character is not upper case, then the + * first character is converted to lower case. + * + * For example, if an object has a method named <code>"getName"</code>, and + * if the result of calling <code>object.getName()</code> is + * <code>"Larry Fine"</code>, then the JSONObject will contain + * <code>"name": "Larry Fine"</code>. + * + * @param bean + * An object that has getter methods that should be used to make + * a JSONObject. + */ + public JSONObject(Object bean) { + this(); + this.populateMap(bean); + } + + /** + * Construct a JSONObject from an Object, using reflection to find the + * public members. The resulting JSONObject's keys will be the strings from + * the names array, and the values will be the field values associated with + * those keys in the object. If a key is not found or not visible, then it + * will not be copied into the new JSONObject. + * + * @param object + * An object that has fields that should be used to make a + * JSONObject. + * @param names + * An array of strings, the names of the fields to be obtained + * from the object. + */ + public JSONObject(Object object, String names[]) { + this(); + Class c = object.getClass(); + for (int i = 0; i < names.length; i += 1) { + String name = names[i]; + try { + this.putOpt(name, c.getField(name).get(object)); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a source JSON text string. This is the most + * commonly used JSONObject constructor. + * + * @param source + * A string beginning with <code>{</code> <small>(left + * brace)</small> and ending with <code>}</code> + *  <small>(right brace)</small>. + * @exception JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONObject from a ResourceBundle. + * + * @param baseName + * The ResourceBundle base name. + * @param locale + * The Locale to load the ResourceBundle for. + * @throws JSONException + * If any JSONExceptions are detected. + */ + public JSONObject(String baseName, Locale locale) throws JSONException { + this(); + ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, + Thread.currentThread().getContextClassLoader()); + +// Iterate through the keys in the bundle. + + Enumeration keys = bundle.getKeys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + if (key instanceof String) { + +// Go through the path, ensuring that there is a nested JSONObject for each +// segment except the last. Add the value using the last segment's name into +// the deepest nested JSONObject. + + String[] path = ((String) key).split("\\."); + int last = path.length - 1; + JSONObject target = this; + for (int i = 0; i < last; i += 1) { + String segment = path[i]; + JSONObject nextTarget = target.optJSONObject(segment); + if (nextTarget == null) { + nextTarget = new JSONObject(); + target.put(segment, nextTarget); + } + target = nextTarget; + } + target.put(path[last], bundle.getString((String) key)); + } + } + } + + /** + * Accumulate values under a key. It is similar to the put method except + * that if there is already an object stored under the key then a JSONArray + * is stored under the key to hold all of the accumulated values. If there + * is already a JSONArray, then the new value is appended to it. In + * contrast, the put method replaces the previous value. + * + * If only one value is accumulated that is not a JSONArray, then the result + * will be the same as using put. But if multiple values are accumulated, + * then the result will be like append. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the value is an invalid number or if the key is null. + */ + public JSONObject accumulate(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, + value instanceof JSONArray ? new JSONArray().put(value) + : value); + } else if (object instanceof JSONArray) { + ((JSONArray) object).put(value); + } else { + this.put(key, new JSONArray().put(object).put(value)); + } + return this; + } + + /** + * Append values to the array under a key. If the key does not exist in the + * JSONObject, then the key is put in the JSONObject with its value being a + * JSONArray containing the value parameter. If the key was already + * associated with a JSONArray, then the value parameter is appended to it. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the key is null or if the current value associated with + * the key is not a JSONArray. + */ + public JSONObject append(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, new JSONArray().put(value)); + } else if (object instanceof JSONArray) { + this.put(key, ((JSONArray) object).put(value)); + } else { + throw new JSONException("JSONObject[" + key + + "] is not a JSONArray."); + } + return this; + } + + /** + * Produce a string from a double. The string "null" will be returned if the + * number is not finite. + * + * @param d + * A double. + * @return A String. + */ + public static String doubleToString(double d) { + if (Double.isInfinite(d) || Double.isNaN(d)) { + return "null"; + } + +// Shave off trailing zeros and decimal point, if possible. + + String string = Double.toString(d); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get the value object associated with a key. + * + * @param key + * A key string. + * @return The object associated with the key. + * @throws JSONException + * if the key is not found. + */ + public Object get(String key) throws JSONException { + if (key == null) { + throw new JSONException("Null key."); + } + Object object = this.opt(key); + if (object == null) { + throw new JSONException("JSONObject[" + quote(key) + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with a key. + * + * @param key + * A key string. + * @return The truth. + * @throws JSONException + * if the value is not a Boolean or the String "true" or + * "false". + */ + public boolean getBoolean(String key) throws JSONException { + Object object = this.get(key); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a Boolean."); + } + + /** + * Get the double value associated with a key. + * + * @param key + * A key string. + * @return The numeric value. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. + */ + public double getDouble(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a number."); + } + } + + /** + * Get the int value associated with a key. + * + * @param key + * A key string. + * @return The integer value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to an integer. + */ + public int getInt(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not an int."); + } + } + + /** + * Get the JSONArray value associated with a key. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONArray. + */ + public JSONArray getJSONArray(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONArray."); + } + + /** + * Get the JSONObject value associated with a key. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONObject. + */ + public JSONObject getJSONObject(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONObject."); + } + + /** + * Get the long value associated with a key. + * + * @param key + * A key string. + * @return The long value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to a long. + */ + public long getLong(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a long."); + } + } + + /** + * Get an array of field names from a JSONObject. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(JSONObject jo) { + int length = jo.length(); + if (length == 0) { + return null; + } + Iterator iterator = jo.keys(); + String[] names = new String[length]; + int i = 0; + while (iterator.hasNext()) { + names[i] = (String) iterator.next(); + i += 1; + } + return names; + } + + /** + * Get an array of field names from an Object. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(Object object) { + if (object == null) { + return null; + } + Class klass = object.getClass(); + Field[] fields = klass.getFields(); + int length = fields.length; + if (length == 0) { + return null; + } + String[] names = new String[length]; + for (int i = 0; i < length; i += 1) { + names[i] = fields[i].getName(); + } + return names; + } + + /** + * Get the string associated with a key. + * + * @param key + * A key string. + * @return A string which is the value. + * @throws JSONException + * if there is no string value for the key. + */ + public String getString(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONObject[" + quote(key) + "] not a string."); + } + + /** + * Determine if the JSONObject contains a specific key. + * + * @param key + * A key string. + * @return true if the key exists in the JSONObject. + */ + public boolean has(String key) { + return this.map.containsKey(key); + } + + /** + * Increment a property of a JSONObject. If there is no such property, + * create one with a value of 1. If there is such a property, and if it is + * an Integer, Long, Double, or Float, then add one to it. + * + * @param key + * A key string. + * @return this. + * @throws JSONException + * If there is already a property with this name that is not an + * Integer, Long, Double, or Float. + */ + public JSONObject increment(String key) throws JSONException { + Object value = this.opt(key); + if (value == null) { + this.put(key, 1); + } else if (value instanceof Integer) { + this.put(key, ((Integer) value).intValue() + 1); + } else if (value instanceof Long) { + this.put(key, ((Long) value).longValue() + 1); + } else if (value instanceof Double) { + this.put(key, ((Double) value).doubleValue() + 1); + } else if (value instanceof Float) { + this.put(key, ((Float) value).floatValue() + 1); + } else { + throw new JSONException("Unable to increment [" + quote(key) + "]."); + } + return this; + } + + /** + * Determine if the value associated with the key is null or if there is no + * value. + * + * @param key + * A key string. + * @return true if there is no value associated with the key or if the value + * is the JSONObject.NULL object. + */ + public boolean isNull(String key) { + return JSONObject.NULL.equals(this.opt(key)); + } + + /** + * Get an enumeration of the keys of the JSONObject. + * + * @return An iterator of the keys. + */ + public Iterator keys() { + return this.keySet().iterator(); + } + + /** + * Get a set of keys of the JSONObject. + * + * @return A keySet. + */ + public Set keySet() { + return this.map.keySet(); + } + + /** + * Get the number of keys stored in the JSONObject. + * + * @return The number of keys in the JSONObject. + */ + public int length() { + return this.map.size(); + } + + /** + * Produce a JSONArray containing the names of the elements of this + * JSONObject. + * + * @return A JSONArray containing the key strings, or null if the JSONObject + * is empty. + */ + public JSONArray names() { + JSONArray ja = new JSONArray(); + Iterator keys = this.keys(); + while (keys.hasNext()) { + ja.put(keys.next()); + } + return ja.length() == 0 ? null : ja; + } + + /** + * Produce a string from a Number. + * + * @param number + * A Number + * @return A String. + * @throws JSONException + * If n is a non-finite number. + */ + public static String numberToString(Number number) throws JSONException { + if (number == null) { + throw new JSONException("Null pointer"); + } + testValidity(number); + +// Shave off trailing zeros and decimal point, if possible. + + String string = number.toString(); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get an optional value associated with a key. + * + * @param key + * A key string. + * @return An object which is the value, or null if there is no value. + */ + public Object opt(String key) { + return key == null ? null : this.map.get(key); + } + + /** + * Get an optional boolean associated with a key. It returns false if there + * is no such key, or if the value is not Boolean.TRUE or the String "true". + * + * @param key + * A key string. + * @return The truth. + */ + public boolean optBoolean(String key) { + return this.optBoolean(key, false); + } + + /** + * Get an optional boolean associated with a key. It returns the + * defaultValue if there is no such key, or if it is not a Boolean or the + * String "true" or "false" (case insensitive). + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return The truth. + */ + public boolean optBoolean(String key, boolean defaultValue) { + try { + return this.getBoolean(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional double associated with a key, or NaN if there is no such + * key or if its value is not a number. If the value is a string, an attempt + * will be made to evaluate it as a number. + * + * @param key + * A string which is the key. + * @return An object which is the value. + */ + public double optDouble(String key) { + return this.optDouble(key, Double.NaN); + } + + /** + * Get an optional double associated with a key, or the defaultValue if + * there is no such key or if its value is not a number. If the value is a + * string, an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public double optDouble(String key, double defaultValue) { + try { + return this.getDouble(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional int value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public int optInt(String key) { + return this.optInt(key, 0); + } + + /** + * Get an optional int value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public int optInt(String key, int defaultValue) { + try { + return this.getInt(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional JSONArray associated with a key. It returns null if there + * is no such key, or if its value is not a JSONArray. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + */ + public JSONArray optJSONArray(String key) { + Object o = this.opt(key); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get an optional JSONObject associated with a key. It returns null if + * there is no such key, or if its value is not a JSONObject. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + */ + public JSONObject optJSONObject(String key) { + Object object = this.opt(key); + return object instanceof JSONObject ? (JSONObject) object : null; + } + + /** + * Get an optional long value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public long optLong(String key) { + return this.optLong(key, 0); + } + + /** + * Get an optional long value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public long optLong(String key, long defaultValue) { + try { + return this.getLong(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional string associated with a key. It returns an empty string + * if there is no such key. If the value is not a string and is not null, + * then it is converted to a string. + * + * @param key + * A key string. + * @return A string which is the value. + */ + public String optString(String key) { + return this.optString(key, ""); + } + + /** + * Get an optional string associated with a key. It returns the defaultValue + * if there is no such key. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return A string which is the value. + */ + public String optString(String key, String defaultValue) { + Object object = this.opt(key); + return NULL.equals(object) ? defaultValue : object.toString(); + } + + private void populateMap(Object bean) { + Class klass = bean.getClass(); + +// If klass is a System class then set includeSuperClass to false. + + boolean includeSuperClass = klass.getClassLoader() != null; + + Method[] methods = includeSuperClass ? klass.getMethods() : klass + .getDeclaredMethods(); + for (int i = 0; i < methods.length; i += 1) { + try { + Method method = methods[i]; + if (Modifier.isPublic(method.getModifiers())) { + String name = method.getName(); + String key = ""; + if (name.startsWith("get")) { + if ("getClass".equals(name) + || "getDeclaringClass".equals(name)) { + key = ""; + } else { + key = name.substring(3); + } + } else if (name.startsWith("is")) { + key = name.substring(2); + } + if (key.length() > 0 + && Character.isUpperCase(key.charAt(0)) + && method.getParameterTypes().length == 0) { + if (key.length() == 1) { + key = key.toLowerCase(); + } else if (!Character.isUpperCase(key.charAt(1))) { + key = key.substring(0, 1).toLowerCase() + + key.substring(1); + } + + Object result = method.invoke(bean, (Object[]) null); + if (result != null) { + this.map.put(key, wrap(result)); + } + } + } + } catch (Exception ignore) { + } + } + } + + /** + * Put a key/boolean pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A boolean which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, boolean value) throws JSONException { + this.put(key, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONArray which is produced from a Collection. + * + * @param key + * A key string. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Collection value) throws JSONException { + this.put(key, new JSONArray(value)); + return this; + } + + /** + * Put a key/double pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A double which is the value. + * @return this. + * @throws JSONException + * If the key is null or if the number is invalid. + */ + public JSONObject put(String key, double value) throws JSONException { + this.put(key, new Double(value)); + return this; + } + + /** + * Put a key/int pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * An int which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, int value) throws JSONException { + this.put(key, new Integer(value)); + return this; + } + + /** + * Put a key/long pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A long which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, long value) throws JSONException { + this.put(key, new Long(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONObject which is produced from a Map. + * + * @param key + * A key string. + * @param value + * A Map value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Map value) throws JSONException { + this.put(key, new JSONObject(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject. If the value is null, then the + * key will be removed from the JSONObject if it is present. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is non-finite number or if the key is null. + */ + public JSONObject put(String key, Object value) throws JSONException { + String pooled; + if (key == null) { + throw new NullPointerException("Null key."); + } + if (value != null) { + testValidity(value); + pooled = (String) keyPool.get(key); + if (pooled == null) { + if (keyPool.size() >= keyPoolSize) { + keyPool = new HashMap(keyPoolSize); + } + keyPool.put(key, key); + } else { + key = pooled; + } + this.map.put(key, value); + } else { + this.remove(key); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null, and only if there is not already a member with that + * name. + * + * @param key + * @param value + * @return his. + * @throws JSONException + * if the key is a duplicate + */ + public JSONObject putOnce(String key, Object value) throws JSONException { + if (key != null && value != null) { + if (this.opt(key) != null) { + throw new JSONException("Duplicate key \"" + key + "\""); + } + this.put(key, value); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is a non-finite number. + */ + public JSONObject putOpt(String key, Object value) throws JSONException { + if (key != null && value != null) { + this.put(key, value); + } + return this; + } + + /** + * Produce a string in double quotes with backslash sequences in all the + * right places. A backslash will be inserted within </, producing <\/, + * allowing JSON text to be delivered in HTML. In JSON text, a string cannot + * contain a control character or an unescaped quote or backslash. + * + * @param string + * A String + * @return A String correctly formatted for insertion in a JSON text. + */ + public static String quote(String string) { + StringWriter sw = new StringWriter(); + synchronized (sw.getBuffer()) { + try { + return quote(string, sw).toString(); + } catch (IOException ignored) { + // will never happen - we are writing to a string writer + return ""; + } + } + } + + public static Writer quote(String string, Writer w) throws IOException { + if (string == null || string.length() == 0) { + w.write("\"\""); + return w; + } + + char b; + char c = 0; + String hhhh; + int i; + int len = string.length(); + + w.write('"'); + for (i = 0; i < len; i += 1) { + b = c; + c = string.charAt(i); + switch (c) { + case '\\': + case '"': + w.write('\\'); + w.write(c); + break; + case '/': + if (b == '<') { + w.write('\\'); + } + w.write(c); + break; + case '\b': + w.write("\\b"); + break; + case '\t': + w.write("\\t"); + break; + case '\n': + w.write("\\n"); + break; + case '\f': + w.write("\\f"); + break; + case '\r': + w.write("\\r"); + break; + default: + if (c < ' ' || (c >= '\u0080' && c < '\u00a0') + || (c >= '\u2000' && c < '\u2100')) { + w.write("\\u"); + hhhh = Integer.toHexString(c); + w.write("0000", 0, 4 - hhhh.length()); + w.write(hhhh); + } else { + w.write(c); + } + } + } + w.write('"'); + return w; + } + + /** + * Remove a name and its value, if present. + * + * @param key + * The name to be removed. + * @return The value that was associated with the name, or null if there was + * no value. + */ + public Object remove(String key) { + return this.map.remove(key); + } + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. + * + * @param string + * A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + Double d; + if (string.equals("")) { + return string; + } + if (string.equalsIgnoreCase("true")) { + return Boolean.TRUE; + } + if (string.equalsIgnoreCase("false")) { + return Boolean.FALSE; + } + if (string.equalsIgnoreCase("null")) { + return JSONObject.NULL; + } + + /* + * If it might be a number, try converting it. If a number cannot be + * produced, then the value will just be a string. + */ + + char b = string.charAt(0); + if ((b >= '0' && b <= '9') || b == '-') { + try { + if (string.indexOf('.') > -1 || string.indexOf('e') > -1 + || string.indexOf('E') > -1) { + d = Double.valueOf(string); + if (!d.isInfinite() && !d.isNaN()) { + return d; + } + } else { + Long myLong = new Long(string); + if (string.equals(myLong.toString())) { + if (myLong.longValue() == myLong.intValue()) { + return new Integer(myLong.intValue()); + } else { + return myLong; + } + } + } + } catch (Exception ignore) { + } + } + return string; + } + + /** + * Throw an exception if the object is a NaN or infinite number. + * + * @param o + * The object to test. + * @throws JSONException + * If o is a non-finite number. + */ + public static void testValidity(Object o) throws JSONException { + if (o != null) { + if (o instanceof Double) { + if (((Double) o).isInfinite() || ((Double) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } else if (o instanceof Float) { + if (((Float) o).isInfinite() || ((Float) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } + } + } + + /** + * Produce a JSONArray containing the values of the members of this + * JSONObject. + * + * @param names + * A JSONArray containing a list of key strings. This determines + * the sequence of the values in the result. + * @return A JSONArray of values. + * @throws JSONException + * If any of the values are non-finite numbers. + */ + public JSONArray toJSONArray(JSONArray names) throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + JSONArray ja = new JSONArray(); + for (int i = 0; i < names.length(); i += 1) { + ja.put(this.opt(names.getString(i))); + } + return ja; + } + + /** + * Make a JSON text of this JSONObject. For compactness, no whitespace is + * added. If this would not result in a syntactically correct JSON text, + * then null will be returned instead. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with <code>{</code> <small>(left + * brace)</small> and ending with <code>}</code> <small>(right + * brace)</small>. + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONObject. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with <code>{</code> <small>(left + * brace)</small> and ending with <code>}</code> <small>(right + * brace)</small>. + * @throws JSONException + * If the object contains an invalid number. + */ + public String toString(int indentFactor) throws JSONException { + StringWriter w = new StringWriter(); + synchronized (w.getBuffer()) { + return this.write(w, indentFactor, 0).toString(); + } + } + + /** + * Make a JSON text of an Object value. If the object has an + * value.toJSONString() method, then that method will be used to produce the + * JSON text. The method is required to produce a strictly conforming text. + * If the object does not contain a toJSONString method (which is the most + * common case), then a text will be produced by other means. If the value + * is an array or Collection, then a JSONArray will be made from it and its + * toJSONString method will be called. If the value is a MAP, then a + * JSONObject will be made from it and its toJSONString method will be + * called. Otherwise, the value's toString method will be called, and the + * result will be quoted. + * + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @param value + * The value to be serialized. + * @return a printable, displayable, transmittable representation of the + * object, beginning with <code>{</code> <small>(left + * brace)</small> and ending with <code>}</code> <small>(right + * brace)</small>. + * @throws JSONException + * If the value is or contains an invalid number. + */ + public static String valueToString(Object value) throws JSONException { + if (value == null || value.equals(null)) { + return "null"; + } + if (value instanceof JSONString) { + Object object; + try { + object = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + if (object instanceof String) { + return (String) object; + } + throw new JSONException("Bad value from toJSONString: " + object); + } + if (value instanceof Number) { + return numberToString((Number) value); + } + if (value instanceof Boolean || value instanceof JSONObject + || value instanceof JSONArray) { + return value.toString(); + } + if (value instanceof Map) { + return new JSONObject((Map) value).toString(); + } + if (value instanceof Collection) { + return new JSONArray((Collection) value).toString(); + } + if (value.getClass().isArray()) { + return new JSONArray(value).toString(); + } + return quote(value.toString()); + } + + /** + * Wrap an object, if necessary. If the object is null, return the NULL + * object. If it is an array or collection, wrap it in a JSONArray. If it is + * a map, wrap it in a JSONObject. If it is a standard property (Double, + * String, et al) then it is already wrapped. Otherwise, if it comes from + * one of the java packages, turn it into a string. And if it doesn't, try + * to wrap it in a JSONObject. If the wrapping fails, then null is returned. + * + * @param object + * The object to wrap + * @return The wrapped value + */ + public static Object wrap(Object object) { + try { + if (object == null) { + return NULL; + } + if (object instanceof JSONObject || object instanceof JSONArray || object instanceof JSONModel + || NULL.equals(object) || object instanceof JSONString + || object instanceof Byte || object instanceof Character + || object instanceof Short || object instanceof Integer + || object instanceof Long || object instanceof Boolean + || object instanceof Float || object instanceof Double + || object instanceof String) { + return object; + } + + if (object instanceof Collection) { + return new JSONArray((Collection) object); + } + if (object.getClass().isArray()) { + return new JSONArray(object); + } + if (object instanceof Map) { + return new JSONObject((Map) object); + } + Package objectPackage = object.getClass().getPackage(); + String objectPackageName = objectPackage != null ? objectPackage + .getName() : ""; + if (objectPackageName.startsWith("java.") + || objectPackageName.startsWith("javax.") + || object.getClass().getClassLoader() == null) { + return object.toString(); + } + return new JSONObject(object); + } catch (Exception exception) { + return null; + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + static final Writer writeValue(Writer writer, Object value, + int indentFactor, int indent) throws JSONException, IOException { + if (value == null || value.equals(null)) { + writer.write("null"); + } else if (value instanceof JSONObject) { + ((JSONObject) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONArray) { + ((JSONArray) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONModel) { + ((JSONModel) value).toJsonObject().write(writer, indentFactor, indent); + } else if (value instanceof Map) { + new JSONObject((Map) value).write(writer, indentFactor, indent); + } else if (value instanceof Collection) { + new JSONArray((Collection) value).write(writer, indentFactor, + indent); + } else if (value.getClass().isArray()) { + new JSONArray(value).write(writer, indentFactor, indent); + } else if (value instanceof Number) { + writer.write(numberToString((Number) value)); + } else if (value instanceof Boolean) { + writer.write(value.toString()); + } else if (value instanceof JSONString) { + Object o; + try { + o = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + writer.write(o != null ? o.toString() : quote(value.toString())); + } else { + quote(value.toString(), writer); + } + return writer; + } + + static final void indent(Writer writer, int indent) throws IOException { + for (int i = 0; i < indent; i += 1) { + writer.write(' '); + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + final int length = this.length(); + Iterator keys = this.keys(); + writer.write('{'); + + if (length == 1) { + Object key = keys.next(); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + while (keys.hasNext()) { + Object key = keys.next(); + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, newindent); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, + newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, indent); + } + writer.write('}'); + return writer; + } catch (IOException exception) { + throw new JSONException(exception); + } + } +} diff --git a/Tubes5/tubes5/src/org/json/JSONString.java b/Tubes5/tubes5/src/org/json/JSONString.java new file mode 100644 index 00000000..1f2d77dd --- /dev/null +++ b/Tubes5/tubes5/src/org/json/JSONString.java @@ -0,0 +1,18 @@ +package org.json; +/** + * The <code>JSONString</code> interface allows a <code>toJSONString()</code> + * method so that a class can change the behavior of + * <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>, + * and <code>JSONWriter.value(</code>Object<code>)</code>. The + * <code>toJSONString</code> method will be used instead of the default behavior + * of using the Object's <code>toString()</code> method and quoting the result. + */ +public interface JSONString { + /** + * The <code>toJSONString</code> method allows a class to produce its own JSON + * serialization. + * + * @return A strictly syntactically correct JSON text. + */ + public String toJSONString(); +} diff --git a/Tubes5/tubes5/src/org/json/JSONStringer.java b/Tubes5/tubes5/src/org/json/JSONStringer.java new file mode 100644 index 00000000..32c9f7f4 --- /dev/null +++ b/Tubes5/tubes5/src/org/json/JSONStringer.java @@ -0,0 +1,78 @@ +package org.json; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.io.StringWriter; + +/** + * JSONStringer provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONStringer can produce one JSON text. + * <p> + * A JSONStringer instance provides a <code>value</code> method for appending + * values to the + * text, and a <code>key</code> + * method for adding keys before values in objects. There are <code>array</code> + * and <code>endArray</code> methods that make and bound array values, and + * <code>object</code> and <code>endObject</code> methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting cascade style. For example, <pre> + * myString = new JSONStringer() + * .object() + * .key("JSON") + * .value("Hello, World!") + * .endObject() + * .toString();</pre> which produces the string <pre> + * {"JSON":"Hello, World!"}</pre> + * <p> + * The first method called must be <code>array</code> or <code>object</code>. + * There are no methods for adding commas or colons. JSONStringer adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + * <p> + * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2008-09-18 + */ +public class JSONStringer extends JSONWriter { + /** + * Make a fresh JSONStringer. It can be used to build one JSON text. + */ + public JSONStringer() { + super(new StringWriter()); + } + + /** + * Return the JSON text. This method is used to obtain the product of the + * JSONStringer instance. It will return <code>null</code> if there was a + * problem in the construction of the JSON text (such as the calls to + * <code>array</code> were not properly balanced with calls to + * <code>endArray</code>). + * @return The JSON text. + */ + public String toString() { + return this.mode == 'd' ? this.writer.toString() : null; + } +} diff --git a/Tubes5/tubes5/src/org/json/JSONTokener.java b/Tubes5/tubes5/src/org/json/JSONTokener.java new file mode 100644 index 00000000..13c84f1f --- /dev/null +++ b/Tubes5/tubes5/src/org/json/JSONTokener.java @@ -0,0 +1,446 @@ +package org.json; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * A JSONTokener takes a source string and extracts characters and tokens from + * it. It is used by the JSONObject and JSONArray constructors to parse + * JSON source strings. + * @author JSON.org + * @version 2012-02-16 + */ +public class JSONTokener { + + private long character; + private boolean eof; + private long index; + private long line; + private char previous; + private Reader reader; + private boolean usePrevious; + + + /** + * Construct a JSONTokener from a Reader. + * + * @param reader A reader. + */ + public JSONTokener(Reader reader) { + this.reader = reader.markSupported() + ? reader + : new BufferedReader(reader); + this.eof = false; + this.usePrevious = false; + this.previous = 0; + this.index = 0; + this.character = 1; + this.line = 1; + } + + + /** + * Construct a JSONTokener from an InputStream. + */ + public JSONTokener(InputStream inputStream) throws JSONException { + this(new InputStreamReader(inputStream)); + } + + + /** + * Construct a JSONTokener from a string. + * + * @param s A source string. + */ + public JSONTokener(String s) { + this(new StringReader(s)); + } + + + /** + * Back up one character. This provides a sort of lookahead capability, + * so that you can test for a digit or letter before attempting to parse + * the next number or identifier. + */ + public void back() throws JSONException { + if (this.usePrevious || this.index <= 0) { + throw new JSONException("Stepping back two steps is not supported"); + } + this.index -= 1; + this.character -= 1; + this.usePrevious = true; + this.eof = false; + } + + + /** + * Get the hex value of a character (base16). + * @param c A character between '0' and '9' or between 'A' and 'F' or + * between 'a' and 'f'. + * @return An int between 0 and 15, or -1 if c was not a hex digit. + */ + public static int dehexchar(char c) { + if (c >= '0' && c <= '9') { + return c - '0'; + } + if (c >= 'A' && c <= 'F') { + return c - ('A' - 10); + } + if (c >= 'a' && c <= 'f') { + return c - ('a' - 10); + } + return -1; + } + + public boolean end() { + return this.eof && !this.usePrevious; + } + + + /** + * Determine if the source string still contains characters that next() + * can consume. + * @return true if not yet at the end of the source. + */ + public boolean more() throws JSONException { + this.next(); + if (this.end()) { + return false; + } + this.back(); + return true; + } + + + /** + * Get the next character in the source string. + * + * @return The next character, or 0 if past the end of the source string. + */ + public char next() throws JSONException { + int c; + if (this.usePrevious) { + this.usePrevious = false; + c = this.previous; + } else { + try { + c = this.reader.read(); + } catch (IOException exception) { + throw new JSONException(exception); + } + + if (c <= 0) { // End of stream + this.eof = true; + c = 0; + } + } + this.index += 1; + if (this.previous == '\r') { + this.line += 1; + this.character = c == '\n' ? 0 : 1; + } else if (c == '\n') { + this.line += 1; + this.character = 0; + } else { + this.character += 1; + } + this.previous = (char) c; + return this.previous; + } + + + /** + * Consume the next character, and check that it matches a specified + * character. + * @param c The character to match. + * @return The character. + * @throws JSONException if the character does not match. + */ + public char next(char c) throws JSONException { + char n = this.next(); + if (n != c) { + throw this.syntaxError("Expected '" + c + "' and instead saw '" + + n + "'"); + } + return n; + } + + + /** + * Get the next n characters. + * + * @param n The number of characters to take. + * @return A string of n characters. + * @throws JSONException + * Substring bounds error if there are not + * n characters remaining in the source string. + */ + public String next(int n) throws JSONException { + if (n == 0) { + return ""; + } + + char[] chars = new char[n]; + int pos = 0; + + while (pos < n) { + chars[pos] = this.next(); + if (this.end()) { + throw this.syntaxError("Substring bounds error"); + } + pos += 1; + } + return new String(chars); + } + + + /** + * Get the next char in the string, skipping whitespace. + * @throws JSONException + * @return A character, or 0 if there are no more characters. + */ + public char nextClean() throws JSONException { + for (;;) { + char c = this.next(); + if (c == 0 || c > ' ') { + return c; + } + } + } + + + /** + * Return the characters up to the next close quote character. + * Backslash processing is done. The formal JSON format does not + * allow strings in single quotes, but an implementation is allowed to + * accept them. + * @param quote The quoting character, either + * <code>"</code> <small>(double quote)</small> or + * <code>'</code> <small>(single quote)</small>. + * @return A String. + * @throws JSONException Unterminated string. + */ + public String nextString(char quote) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + switch (c) { + case 0: + case '\n': + case '\r': + throw this.syntaxError("Unterminated string"); + case '\\': + c = this.next(); + switch (c) { + case 'b': + sb.append('\b'); + break; + case 't': + sb.append('\t'); + break; + case 'n': + sb.append('\n'); + break; + case 'f': + sb.append('\f'); + break; + case 'r': + sb.append('\r'); + break; + case 'u': + sb.append((char)Integer.parseInt(this.next(4), 16)); + break; + case '"': + case '\'': + case '\\': + case '/': + sb.append(c); + break; + default: + throw this.syntaxError("Illegal escape."); + } + break; + default: + if (c == quote) { + return sb.toString(); + } + sb.append(c); + } + } + } + + + /** + * Get the text up but not including the specified character or the + * end of line, whichever comes first. + * @param delimiter A delimiter character. + * @return A string. + */ + public String nextTo(char delimiter) throws JSONException { + StringBuffer sb = new StringBuffer(); + for (;;) { + char c = this.next(); + if (c == delimiter || c == 0 || c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the text up but not including one of the specified delimiter + * characters or the end of line, whichever comes first. + * @param delimiters A set of delimiter characters. + * @return A string, trimmed. + */ + public String nextTo(String delimiters) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + if (delimiters.indexOf(c) >= 0 || c == 0 || + c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the next value. The value can be a Boolean, Double, Integer, + * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. + * @throws JSONException If syntax error. + * + * @return An object. + */ + public Object nextValue() throws JSONException { + char c = this.nextClean(); + String string; + + switch (c) { + case '"': + case '\'': + return this.nextString(c); + case '{': + this.back(); + return new JSONObject(this); + case '[': + this.back(); + return new JSONArray(this); + } + + /* + * Handle unquoted text. This could be the values true, false, or + * null, or it can be a number. An implementation (such as this one) + * is allowed to also accept non-standard forms. + * + * Accumulate characters until we reach the end of the text or a + * formatting character. + */ + + StringBuffer sb = new StringBuffer(); + while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { + sb.append(c); + c = this.next(); + } + this.back(); + + string = sb.toString().trim(); + if ("".equals(string)) { + throw this.syntaxError("Missing value"); + } + return JSONObject.stringToValue(string); + } + + + /** + * Skip characters until the next character is the requested character. + * If the requested character is not found, no characters are skipped. + * @param to A character to skip to. + * @return The requested character, or zero if the requested character + * is not found. + */ + public char skipTo(char to) throws JSONException { + char c; + try { + long startIndex = this.index; + long startCharacter = this.character; + long startLine = this.line; + this.reader.mark(1000000); + do { + c = this.next(); + if (c == 0) { + this.reader.reset(); + this.index = startIndex; + this.character = startCharacter; + this.line = startLine; + return c; + } + } while (c != to); + } catch (IOException exc) { + throw new JSONException(exc); + } + + this.back(); + return c; + } + + + /** + * Make a JSONException to signal a syntax error. + * + * @param message The error message. + * @return A JSONException object, suitable for throwing + */ + public JSONException syntaxError(String message) { + return new JSONException(message + this.toString()); + } + + + /** + * Make a printable string of this JSONTokener. + * + * @return " at {index} [character {character} line {line}]" + */ + public String toString() { + return " at " + this.index + " [character " + this.character + " line " + + this.line + "]"; + } +} diff --git a/Tubes5/tubes5/src/org/json/JSONWriter.java b/Tubes5/tubes5/src/org/json/JSONWriter.java new file mode 100644 index 00000000..35b60d90 --- /dev/null +++ b/Tubes5/tubes5/src/org/json/JSONWriter.java @@ -0,0 +1,327 @@ +package org.json; + +import java.io.IOException; +import java.io.Writer; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * JSONWriter provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONWriter can produce one JSON text. + * <p> + * A JSONWriter instance provides a <code>value</code> method for appending + * values to the + * text, and a <code>key</code> + * method for adding keys before values in objects. There are <code>array</code> + * and <code>endArray</code> methods that make and bound array values, and + * <code>object</code> and <code>endObject</code> methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting a cascade style. For example, <pre> + * new JSONWriter(myWriter) + * .object() + * .key("JSON") + * .value("Hello, World!") + * .endObject();</pre> which writes <pre> + * {"JSON":"Hello, World!"}</pre> + * <p> + * The first method called must be <code>array</code> or <code>object</code>. + * There are no methods for adding commas or colons. JSONWriter adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + * <p> + * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2011-11-24 + */ +public class JSONWriter { + private static final int maxdepth = 200; + + /** + * The comma flag determines if a comma should be output before the next + * value. + */ + private boolean comma; + + /** + * The current mode. Values: + * 'a' (array), + * 'd' (done), + * 'i' (initial), + * 'k' (key), + * 'o' (object). + */ + protected char mode; + + /** + * The object/array stack. + */ + private final JSONObject stack[]; + + /** + * The stack top index. A value of 0 indicates that the stack is empty. + */ + private int top; + + /** + * The writer that will receive the output. + */ + protected Writer writer; + + /** + * Make a fresh JSONWriter. It can be used to build one JSON text. + */ + public JSONWriter(Writer w) { + this.comma = false; + this.mode = 'i'; + this.stack = new JSONObject[maxdepth]; + this.top = 0; + this.writer = w; + } + + /** + * Append a value. + * @param string A string value. + * @return this + * @throws JSONException If the value is out of sequence. + */ + private JSONWriter append(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null pointer"); + } + if (this.mode == 'o' || this.mode == 'a') { + try { + if (this.comma && this.mode == 'a') { + this.writer.write(','); + } + this.writer.write(string); + } catch (IOException e) { + throw new JSONException(e); + } + if (this.mode == 'o') { + this.mode = 'k'; + } + this.comma = true; + return this; + } + throw new JSONException("Value out of sequence."); + } + + /** + * Begin appending a new array. All values until the balancing + * <code>endArray</code> will be appended to this array. The + * <code>endArray</code> method must be called to mark the array's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter array() throws JSONException { + if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { + this.push(null); + this.append("["); + this.comma = false; + return this; + } + throw new JSONException("Misplaced array."); + } + + /** + * End something. + * @param mode Mode + * @param c Closing character + * @return this + * @throws JSONException If unbalanced. + */ + private JSONWriter end(char mode, char c) throws JSONException { + if (this.mode != mode) { + throw new JSONException(mode == 'a' + ? "Misplaced endArray." + : "Misplaced endObject."); + } + this.pop(mode); + try { + this.writer.write(c); + } catch (IOException e) { + throw new JSONException(e); + } + this.comma = true; + return this; + } + + /** + * End an array. This method most be called to balance calls to + * <code>array</code>. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endArray() throws JSONException { + return this.end('a', ']'); + } + + /** + * End an object. This method most be called to balance calls to + * <code>object</code>. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endObject() throws JSONException { + return this.end('k', '}'); + } + + /** + * Append a key. The key will be associated with the next value. In an + * object, every value must be preceded by a key. + * @param string A key string. + * @return this + * @throws JSONException If the key is out of place. For example, keys + * do not belong in arrays or if the key is null. + */ + public JSONWriter key(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null key."); + } + if (this.mode == 'k') { + try { + this.stack[this.top - 1].putOnce(string, Boolean.TRUE); + if (this.comma) { + this.writer.write(','); + } + this.writer.write(JSONObject.quote(string)); + this.writer.write(':'); + this.comma = false; + this.mode = 'o'; + return this; + } catch (IOException e) { + throw new JSONException(e); + } + } + throw new JSONException("Misplaced key."); + } + + + /** + * Begin appending a new object. All keys and values until the balancing + * <code>endObject</code> will be appended to this object. The + * <code>endObject</code> method must be called to mark the object's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter object() throws JSONException { + if (this.mode == 'i') { + this.mode = 'o'; + } + if (this.mode == 'o' || this.mode == 'a') { + this.append("{"); + this.push(new JSONObject()); + this.comma = false; + return this; + } + throw new JSONException("Misplaced object."); + + } + + + /** + * Pop an array or object scope. + * @param c The scope to close. + * @throws JSONException If nesting is wrong. + */ + private void pop(char c) throws JSONException { + if (this.top <= 0) { + throw new JSONException("Nesting error."); + } + char m = this.stack[this.top - 1] == null ? 'a' : 'k'; + if (m != c) { + throw new JSONException("Nesting error."); + } + this.top -= 1; + this.mode = this.top == 0 + ? 'd' + : this.stack[this.top - 1] == null + ? 'a' + : 'k'; + } + + /** + * Push an array or object scope. + * @param c The scope to open. + * @throws JSONException If nesting is too deep. + */ + private void push(JSONObject jo) throws JSONException { + if (this.top >= maxdepth) { + throw new JSONException("Nesting too deep."); + } + this.stack[this.top] = jo; + this.mode = jo == null ? 'a' : 'k'; + this.top += 1; + } + + + /** + * Append either the value <code>true</code> or the value + * <code>false</code>. + * @param b A boolean. + * @return this + * @throws JSONException + */ + public JSONWriter value(boolean b) throws JSONException { + return this.append(b ? "true" : "false"); + } + + /** + * Append a double value. + * @param d A double. + * @return this + * @throws JSONException If the number is not finite. + */ + public JSONWriter value(double d) throws JSONException { + return this.value(new Double(d)); + } + + /** + * Append a long value. + * @param l A long. + * @return this + * @throws JSONException + */ + public JSONWriter value(long l) throws JSONException { + return this.append(Long.toString(l)); + } + + + /** + * Append an object value. + * @param object The object to append. It can be null, or a Boolean, Number, + * String, JSONObject, or JSONArray, or an object that implements JSONString. + * @return this + * @throws JSONException If the value is out of sequence. + */ + public JSONWriter value(Object object) throws JSONException { + return this.append(JSONObject.valueToString(object)); + } +} diff --git a/Tubes5/tubes5/src/test.java b/Tubes5/tubes5/src/test.java new file mode 100644 index 00000000..d17f64eb --- /dev/null +++ b/Tubes5/tubes5/src/test.java @@ -0,0 +1,101 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Aji + */ +import java.awt.Color; +import java.awt.Component; +import java.awt.Dialog.ModalityType; +import java.awt.Dimension; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import javax.swing.border.LineBorder; + +public class test { + + private static JButton createSimpleButton(String text) { + JButton button = new javax.swing.JButton(text); + button.setForeground(Color.BLACK); + button.setBackground(Color.WHITE); + Border line = new LineBorder(Color.BLACK); + Border margin = new EmptyBorder(5, 15, 5, 15); + Border compound = new CompoundBorder(line, margin); + button.setBorder(compound); + + return button; + } + + private static void createAndShowGui() { + JPanel panel = new JPanel(); + panel.add(new JButton(new ShowtestAction())); + JFrame frame = new JFrame("test"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().add(panel); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + createAndShowGui(); + } + }); + } +} + +class ShowtestAction extends AbstractAction { + private JPanel panel = new JPanel(); + + public ShowtestAction() { + super("Show Moving Dialog"); + panel.add(new JLabel("label")); + panel.add(new JTextField("TextField", 10)); + panel.add(new JButton("Button")); + } + + @Override + public void actionPerformed(ActionEvent e) { + JFrame owner = (JFrame) SwingUtilities.getWindowAncestor((Component) e + .getSource()); + final JDialog dialog = new JDialog(owner, "Dialog", + ModalityType.APPLICATION_MODAL); + dialog.getContentPane().add(panel); + dialog.pack(); + dialog.setLocation(0, 0); + + int delay = 20; + new Timer(delay , new ActionListener() { + int x = 0; + int y = 0; + Dimension scrn = Toolkit.getDefaultToolkit().getScreenSize(); + + @Override + public void actionPerformed(ActionEvent e) { + int maxX = scrn.width - dialog.getWidth(); + int maxY = scrn.height - dialog.getHeight(); + if (x < maxX && y < maxY) { + x++; + y++; + dialog.setLocation(x, y); + } else { + ((Timer)e.getSource()).stop(); + } + } + }).start(); + + dialog.setVisible(true); + + } +} \ No newline at end of file diff --git a/Tubes5/tubes5/src/test2.java b/Tubes5/tubes5/src/test2.java new file mode 100644 index 00000000..32c627e2 --- /dev/null +++ b/Tubes5/tubes5/src/test2.java @@ -0,0 +1,154 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Aji + */ +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.MediaTracker; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class test2 extends JFrame { + AnimationCanvas canvas; + + JButton startButton, stopButton; + + public test2() { + super(); + Container container = getContentPane(); + + canvas = new AnimationCanvas(); + container.add(canvas); + + startButton = new JButton("Start Animation"); + startButton.addActionListener(new ButtonListener()); + stopButton = new JButton("Stop Animation"); + stopButton.addActionListener(new ButtonListener()); + JPanel panel = new JPanel(); + panel.add(startButton); + panel.add(stopButton); + container.add(BorderLayout.SOUTH, panel); + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + setSize(450, 425); + setVisible(true); + } + + class ButtonListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + JButton temp = (JButton) e.getSource(); + + if (temp.equals(startButton)) { + canvas.start(); + } else if (temp.equals(stopButton)) { + canvas.stop(); + } + } + } + + public static void main(String arg[]) { + new test2(); + } +} + +class AnimationCanvas extends JLabel implements Runnable { + Thread thread; + Image image; + BufferedImage bi; + double x, y, xi, yi; + int rotate; + double scale; + int UP = 0; + int DOWN = 1; + int scaleDirection; + + AnimationCanvas() { + setBackground(Color.green); + setSize(450, 400); + + image = getToolkit().getImage("D:/gear.png"); + + MediaTracker mt = new MediaTracker(this); + mt.addImage(image, 1); + try { + mt.waitForAll(); + } catch (Exception e) { + System.out.println("Exception while loading image."); + } + + if (image.getWidth(this) == -1) { + System.out.println("No gif file"); + System.exit(0); + } + + rotate = (int)2; + scale = 1; + scaleDirection = DOWN; + + xi = 50.0; + yi = 50.0; + + } + + + public void paintComponent(Graphics g) { + super.paintComponent(g); + Dimension d = getSize(); + + bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB); + Graphics2D big = bi.createGraphics(); + + AffineTransform at = new AffineTransform(); + at.setToIdentity(); + at.rotate(Math.toRadians(rotate)); + big.drawImage(image, at, this); + + Graphics2D g2D = (Graphics2D) g; + g2D.drawImage(bi, 0, 0, null); + + big.dispose(); + } + + public void start() { + thread = new Thread(this); + thread.setPriority(Thread.MIN_PRIORITY); + thread.start(); + } + + public void stop() { + if (thread != null) + thread.interrupt(); + thread = null; + } + + public void run() { + Thread me = Thread.currentThread(); + while (thread == me) { + repaint(); + } + thread = null; + } +} \ No newline at end of file diff --git a/Tubes5/tubes5/src/tubes5/Tubes5.java b/Tubes5/tubes5/src/tubes5/Tubes5.java new file mode 100644 index 00000000..9f631398 --- /dev/null +++ b/Tubes5/tubes5/src/tubes5/Tubes5.java @@ -0,0 +1,26 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package tubes5; + +import Controller.Controller; + +/** + * + * @author Aji + */ +public class Tubes5 { + + /** + * @param args the command line arguments + */ + + public static void main(String[] args) { + // TODO code application logic here + Controller controller = new Controller(); + if(controller.connect("127.0.0.1", 9000)){ + new login(controller).setVisible(true); + } + } +} diff --git a/Tubes5/tubes5/src/tubes5/background.png b/Tubes5/tubes5/src/tubes5/background.png new file mode 100644 index 00000000..1902c77c Binary files /dev/null and b/Tubes5/tubes5/src/tubes5/background.png differ diff --git a/Tubes5/tubes5/src/tubes5/front.png b/Tubes5/tubes5/src/tubes5/front.png new file mode 100644 index 00000000..45b5ada4 Binary files /dev/null and b/Tubes5/tubes5/src/tubes5/front.png differ diff --git a/Tubes5/tubes5/src/tubes5/list.png b/Tubes5/tubes5/src/tubes5/list.png new file mode 100644 index 00000000..b816e7e2 Binary files /dev/null and b/Tubes5/tubes5/src/tubes5/list.png differ diff --git a/Tubes5/tubes5/src/tubes5/login.form b/Tubes5/tubes5/src/tubes5/login.form new file mode 100644 index 00000000..6fcb4c59 --- /dev/null +++ b/Tubes5/tubes5/src/tubes5/login.form @@ -0,0 +1,288 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> + <Properties> + <Property name="defaultCloseOperation" type="int" value="3"/> + <Property name="focusTraversalPolicyProvider" type="boolean" value="true"/> + <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> + <Dimension value="[800, 508]"/> + </Property> + <Property name="resizable" type="boolean" value="false"/> + </Properties> + <SyntheticProperties> + <SyntheticProperty name="formSizePolicy" type="int" value="1"/> + <SyntheticProperty name="generateCenter" type="boolean" value="false"/> + </SyntheticProperties> + <AuxValues> + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-32,0,0,3,32"/> + </AuxValues> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> + <Property name="useNullLayout" type="boolean" value="true"/> + </Layout> + <SubComponents> + <Container class="javax.swing.JPanel" name="jPanel1"> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="10" y="10" width="778" height="458"/> + </Constraint> + </Constraints> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> + <Property name="useNullLayout" type="boolean" value="true"/> + </Layout> + <SubComponents> + <Component class="javax.swing.JTextField" name="jTextField1"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Tahoma" size="14" style="1"/> + </Property> + <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> + <Border info="null"/> + </Property> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="324" y="270" width="149" height="22"/> + </Constraint> + </Constraints> + </Component> + <Component class="javax.swing.JPasswordField" name="jPasswordField1"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="Tahoma" size="14" style="0"/> + </Property> + <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> + <Border info="null"/> + </Property> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="324" y="308" width="149" height="22"/> + </Constraint> + </Constraints> + </Component> + <Component class="javax.swing.JButton" name="jButton1"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="04b_19" size="30" style="0"/> + </Property> + <Property name="text" type="java.lang.String" value="LogiN"/> + </Properties> + <Events> + <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/> + </Events> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="485" y="265" width="111" height="67"/> + </Constraint> + </Constraints> + </Component> + <Component class="javax.swing.JLabel" name="jLabel3"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="04b_19" size="14" style="0"/> + </Property> + <Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> + <Color blue="33" green="33" red="ff" type="rgb"/> + </Property> + <Property name="text" type="java.lang.String" value="something wrong with your input.. please check again"/> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="197" y="340" width="390" height="-1"/> + </Constraint> + </Constraints> + </Component> + <Component class="javax.swing.JLabel" name="jLabel2"> + <Properties> + <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> + <Image iconType="3" name="/tubes5/front.png"/> + </Property> + <Property name="text" type="java.lang.String" value="jLabel2"/> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="0" y="0" width="778" height="458"/> + </Constraint> + </Constraints> + </Component> + </SubComponents> + </Container> + <Container class="javax.swing.JPanel" name="jPanel2"> + <Properties> + <Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> + <Color blue="cc" green="cc" red="cc" type="rgb"/> + </Property> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="820" y="10" width="778" height="458"/> + </Constraint> + </Constraints> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> + <Property name="useNullLayout" type="boolean" value="true"/> + </Layout> + <SubComponents> + <Component class="javax.swing.JLabel" name="jLabel4"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="04b_19" size="48" style="0"/> + </Property> + <Property name="text" type="java.lang.String" value="Dashboard"/> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="30" y="23" width="250" height="50"/> + </Constraint> + </Constraints> + </Component> + <Component class="javax.swing.JLabel" name="jLabel5"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="04b_19" size="18" style="0"/> + </Property> + <Property name="text" type="java.lang.String" value="Dear Users, Here is Your Task List"/> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="30" y="70" width="710" height="20"/> + </Constraint> + </Constraints> + </Component> + <Component class="javax.swing.JLabel" name="jLabel6"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="04b_19" size="18" style="0"/> + </Property> + <Property name="text" type="java.lang.String" value="Sick oF These Tasks ?"/> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="420" y="400" width="200" height="20"/> + </Constraint> + </Constraints> + </Component> + <Component class="javax.swing.JLabel" name="jLabel7"> + <Properties> + <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor"> + <Font name="04b_19" size="18" style="0"/> + </Property> + <Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> + <Color blue="33" green="33" red="ff" type="rgb"/> + </Property> + <Property name="text" type="java.lang.String" value="LOGOUT HERE"/> + </Properties> + <Events> + <EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jLabel7MouseClicked"/> + </Events> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="630" y="400" width="110" height="20"/> + </Constraint> + </Constraints> + </Component> + <Container class="javax.swing.JScrollPane" name="jScrollPane1"> + <AuxValues> + <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> + </AuxValues> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="30" y="100" width="720" height="290"/> + </Constraint> + </Constraints> + + <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> + <SubComponents> + <Component class="javax.swing.JTable" name="jTable1"> + <Properties> + <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor"> + <Table columnCount="6" rowCount="4"> + <Column editable="true" title="Task Name" type="java.lang.Object"/> + <Column editable="true" title="Category" type="java.lang.Object"/> + <Column editable="true" title="Deadline" type="java.lang.Object"/> + <Column editable="true" title="Assignee" type="java.lang.Object"/> + <Column editable="true" title="Tag" type="java.lang.Object"/> + <Column editable="true" title="Status" type="java.lang.Boolean"/> + </Table> + </Property> + <Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor"> + <TableColumnModel selectionModel="0"> + <Column maxWidth="-1" minWidth="-1" prefWidth="100" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="80" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="100" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="20" resizable="false"> + <Title/> + <Editor/> + <Renderer/> + </Column> + </TableColumnModel> + </Property> + <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor"> + <TableHeader reorderingAllowed="true" resizingAllowed="true"/> + </Property> + </Properties> + </Component> + </SubComponents> + </Container> + <Component class="javax.swing.JLabel" name="jLabel8"> + <Properties> + <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> + <Image iconType="2" name="D:\list.png"/> + </Property> + <Property name="toolTipText" type="java.lang.String" value=""/> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="10" y="10" width="780" height="458"/> + </Constraint> + </Constraints> + </Component> + </SubComponents> + </Container> + <Component class="javax.swing.JLabel" name="jLabel1"> + <Properties> + <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"> + <Image iconType="3" name="/tubes5/background.png"/> + </Property> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> + <AbsoluteConstraints x="0" y="0" width="838" height="-1"/> + </Constraint> + </Constraints> + </Component> + </SubComponents> +</Form> diff --git a/Tubes5/tubes5/src/tubes5/login.java b/Tubes5/tubes5/src/tubes5/login.java new file mode 100644 index 00000000..3bff97bb --- /dev/null +++ b/Tubes5/tubes5/src/tubes5/login.java @@ -0,0 +1,358 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package tubes5; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.Timer; +import Controller.*; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; + +/** + * + * @author Aji + */ +public class login extends javax.swing.JFrame { + + /** + * Creates new form login + */ + Controller cont; + DefaultTableModel model; + + public login(Controller _cont) { + initComponents(); + cont = _cont; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + jPanel1 = new javax.swing.JPanel(); + jTextField1 = new javax.swing.JTextField(); + jPasswordField1 = new javax.swing.JPasswordField(); + jButton1 = new javax.swing.JButton(); + jLabel3 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jPanel2 = new javax.swing.JPanel(); + jLabel4 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + jLabel6 = new javax.swing.JLabel(); + jLabel7 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTable1 = new javax.swing.JTable(); + jLabel8 = new javax.swing.JLabel(); + jLabel1 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setFocusTraversalPolicyProvider(true); + setMinimumSize(new java.awt.Dimension(800, 508)); + setResizable(false); + getContentPane().setLayout(null); + + jPanel1.setLayout(null); + + jTextField1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N + jTextField1.setBorder(null); + jPanel1.add(jTextField1); + jTextField1.setBounds(324, 270, 149, 22); + + jPasswordField1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N + jPasswordField1.setBorder(null); + jPanel1.add(jPasswordField1); + jPasswordField1.setBounds(324, 308, 149, 22); + + jButton1.setFont(new java.awt.Font("04b_19", 0, 30)); // NOI18N + jButton1.setText("LogiN"); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + jPanel1.add(jButton1); + jButton1.setBounds(485, 265, 111, 67); + + jLabel3.setFont(new java.awt.Font("04b_19", 0, 14)); // NOI18N + jLabel3.setForeground(new java.awt.Color(255, 51, 51)); + jLabel3.setText("something wrong with your input.. please check again"); + jPanel1.add(jLabel3); + jLabel3.setBounds(197, 340, 390, 14); + jLabel3.setVisible(false); + + jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tubes5/front.png"))); // NOI18N + jLabel2.setText("jLabel2"); + jPanel1.add(jLabel2); + jLabel2.setBounds(0, 0, 778, 458); + + getContentPane().add(jPanel1); + jPanel1.setBounds(10, 10, 778, 458); + + jPanel2.setBackground(new java.awt.Color(204, 204, 204)); + jPanel2.setLayout(null); + + jLabel4.setFont(new java.awt.Font("04b_19", 0, 48)); // NOI18N + jLabel4.setText("Dashboard"); + jPanel2.add(jLabel4); + jLabel4.setBounds(30, 23, 250, 50); + + jLabel5.setFont(new java.awt.Font("04b_19", 0, 18)); // NOI18N + jLabel5.setText("Dear Users, Here is Your Task List"); + jPanel2.add(jLabel5); + jLabel5.setBounds(30, 70, 710, 20); + + jLabel6.setFont(new java.awt.Font("04b_19", 0, 18)); // NOI18N + jLabel6.setText("Sick oF These Tasks ?"); + jPanel2.add(jLabel6); + jLabel6.setBounds(420, 400, 200, 20); + + jLabel7.setFont(new java.awt.Font("04b_19", 0, 18)); // NOI18N + jLabel7.setForeground(new java.awt.Color(255, 51, 51)); + jLabel7.setText("LOGOUT HERE"); + jLabel7.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + jLabel7MouseClicked(evt); + } + }); + jPanel2.add(jLabel7); + jLabel7.setBounds(630, 400, 110, 20); + + /*Object[][] obj = new Object[cont.task_list.size()][6]; + + for (int i=0; i< cont.task_list.size(); i++){ + obj[i][0] = cont.task_list.get(i).getName(); + obj[i][1] = cont.task_list.get(i).getTask_category(); + obj[i][2] = cont.task_list.get(i).getDeadline(); + obj[i][3] = cont.task_list.get(i).getCreator(); + obj[i][4] = cont.task_list.get(i).getTag_list().toString(); + if(cont.task_list.get(i).getStatus().equals("0")) + { + obj[i][5] = null; + } + else + { + obj[i][5] = true; + } + }*/ + String data[][] = {}; + String col[] = { + "Task Name", "Category", "Deadline", "Creator", "Tag", "Status" + }; + model = new DefaultTableModel(data,col){ + Class[] types = new Class [] { + java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Boolean.class + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + }; + + jTable1.setModel(model); + jTable1.addMouseListener(new java.awt.event.MouseAdapter(){ + public void mouseClicked(java.awt.event.MouseEvent e){ + int row = jTable1.rowAtPoint(e.getPoint()); + int col = jTable1.columnAtPoint(e.getPoint()); + System.out.println(row + " lalala "+ col); + cont.ubahStatus(row); + cont.update(); + RefreshList(); + } + }); + + jScrollPane1.setViewportView(jTable1); + jTable1.getColumnModel().getColumn(0).setResizable(false); + jTable1.getColumnModel().getColumn(0).setPreferredWidth(100); + jTable1.getColumnModel().getColumn(1).setResizable(false); + jTable1.getColumnModel().getColumn(2).setResizable(false); + jTable1.getColumnModel().getColumn(2).setPreferredWidth(80); + jTable1.getColumnModel().getColumn(3).setResizable(false); + jTable1.getColumnModel().getColumn(3).setPreferredWidth(100); + jTable1.getColumnModel().getColumn(4).setResizable(false); + jTable1.getColumnModel().getColumn(5).setResizable(false); + jTable1.getColumnModel().getColumn(5).setPreferredWidth(20); + + jPanel2.add(jScrollPane1); + jScrollPane1.setBounds(30, 100, 720, 290); + + jLabel8.setIcon(new javax.swing.ImageIcon("src/tubes5/list.png")); // NOI18N + jLabel8.setToolTipText(""); + jPanel2.add(jLabel8); + jLabel8.setBounds(0, 0, 780, 458); + + getContentPane().add(jPanel2); + jPanel2.setBounds(820, 10, 778, 458); + + jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tubes5/background.png"))); // NOI18N + getContentPane().add(jLabel1); + jLabel1.setBounds(0, 0, 838, 480); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + public void CreateList() { + while (model.getRowCount() > 0) { + model.removeRow(model.getRowCount() - 1); + } + for (int i = 0; i < cont.task_list.size(); i++) { + Object obj[] = new Object[6]; + obj[0] = cont.task_list.get(i).getName(); + obj[1] = cont.task_list.get(i).getTask_category(); + obj[2] = cont.task_list.get(i).getDeadline(); + obj[3] = cont.task_list.get(i).getCreator(); + obj[4] = cont.task_list.get(i).getTag_list().toString(); + if (cont.task_list.get(i).getStatus().equals("0")) { + obj[5] = null; + } else { + obj[5] = true; + } + model.insertRow(i, obj); + } + } + + public void RefreshList() { + while (model.getRowCount() > 0) { + model.removeRow(model.getRowCount() - 1); + } + for (int i = 0; i < cont.task_list.size(); i++) { + Object obj[] = new Object[6]; + obj[0] = cont.task_list.get(i).getName(); + obj[1] = cont.task_list.get(i).getTask_category(); + obj[2] = cont.task_list.get(i).getDeadline(); + obj[3] = cont.task_list.get(i).getCreator(); + obj[4] = cont.task_list.get(i).getTag_list().toString(); + if (cont.task_list.get(i).getStatus().equals("0")) { + obj[5] = null; + } else { + obj[5] = true; + } + model.insertRow(i, obj); + } + } + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + // if (jTextField1.getText().equals( "ajiganteng")){ + if (cont.login(jTextField1.getText(), jPasswordField1.getText())) { + jLabel5.setText("Dear " + jTextField1.getText().toUpperCase() + ", Here is Your Task List"); + jTextField1.setEnabled(false); + jPasswordField1.setEnabled(false); + jButton1.setEnabled(false); + + cont.loadTask(); + cont.update(); + CreateList(); + + int delay = 20; + new Timer(delay, new ActionListener() { + int x = jPanel1.getLocation().x; + int y = jPanel1.getLocation().y; + int a = jPanel2.getLocation().x; + int b = jPanel2.getLocation().y; + + @Override + public void actionPerformed(ActionEvent e) { + if (x > -800) { + x = x - 12; + a = a - 12; + jPanel1.setLocation(x, y); + jPanel2.setLocation(a, b); + } else { + ((Timer) e.getSource()).stop(); + jLabel3.setVisible(false); + jTextField1.setText(""); + } + } + }).start(); + } else { + jLabel3.setVisible(true); + } + }//GEN-LAST:event_jButton1ActionPerformed + + private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked + // TODO add your handling code here: + cont.logout(); + int delay = 20; + new Timer(delay, new ActionListener() { + int x = jPanel1.getLocation().x; + int y = jPanel1.getLocation().y; + int a = jPanel2.getLocation().x; + int b = jPanel2.getLocation().y; + + @Override + public void actionPerformed(ActionEvent e) { + if (x < 10) { + x = x + 12; + a = a + 12; + jPanel1.setLocation(x, y); + jPanel2.setLocation(a, b); + } else { + ((Timer) e.getSource()).stop(); + jTextField1.setEnabled(true); + jPasswordField1.setEnabled(true); + jButton1.setEnabled(true); + } + } + }).start(); + }//GEN-LAST:event_jLabel7MouseClicked + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + //</editor-fold> + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new login(new Controller()).setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JLabel jLabel7; + private javax.swing.JLabel jLabel8; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JPasswordField jPasswordField1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTable jTable1; + private javax.swing.JTextField jTextField1; + // End of variables declaration//GEN-END:variables +} diff --git a/eurilys4-service/build.xml b/eurilys4-service/build.xml new file mode 100644 index 00000000..cc1766c7 --- /dev/null +++ b/eurilys4-service/build.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- You may freely edit this file. See commented blocks below for --> +<!-- some examples of how to customize the build. --> +<!-- (If you delete it and reopen the project it will be recreated.) --> +<!-- By default, only the Clean and Build commands use this build script. --> +<!-- Commands such as Run, Debug, and Test only use this build script if --> +<!-- the Compile on Save feature is turned off for the project. --> +<!-- You can turn off the Compile on Save (or Deploy on Save) setting --> +<!-- in the project's Project Properties dialog box.--> +<project name="eurilys4-service" default="default" basedir="."> + <description>Builds, tests, and runs the project eurilys4-service.</description> + <import file="nbproject/build-impl.xml"/> + <!-- + + There exist several targets which are by default empty and which can be + used for execution of your tasks. These targets are usually executed + before and after some main targets. They are: + + -pre-init: called before initialization of project properties + -post-init: called after initialization of project properties + -pre-compile: called before javac compilation + -post-compile: called after javac compilation + -pre-compile-single: called before javac compilation of single file + -post-compile-single: called after javac compilation of single file + -pre-compile-test: called before javac compilation of JUnit tests + -post-compile-test: called after javac compilation of JUnit tests + -pre-compile-test-single: called before javac compilation of single JUnit test + -post-compile-test-single: called after javac compilation of single JUunit test + -pre-dist: called before archive building + -post-dist: called after archive building + -post-clean: called after cleaning build products + -pre-run-deploy: called before deploying + -post-run-deploy: called after deploying + + Example of pluging an obfuscator after the compilation could look like + + <target name="-post-compile"> + <obfuscate> + <fileset dir="${build.classes.dir}"/> + </obfuscate> + </target> + + For list of available properties check the imported + nbproject/build-impl.xml file. + + + Other way how to customize the build is by overriding existing main targets. + The target of interest are: + + init-macrodef-javac: defines macro for javac compilation + init-macrodef-junit: defines macro for junit execution + init-macrodef-debug: defines macro for class debugging + do-dist: archive building + run: execution of project + javadoc-build: javadoc generation + + Example of overriding the target for project execution could look like + + <target name="run" depends="<PROJNAME>-impl.jar"> + <exec dir="bin" executable="launcher.exe"> + <arg file="${dist.jar}"/> + </exec> + </target> + + Notice that overridden target depends on jar target and not only on + compile target as regular run target does. Again, for list of available + properties which you can use check the target you are overriding in + nbproject/build-impl.xml file. + + --> +</project> diff --git a/eurilys4-service/build/web/META-INF/MANIFEST.MF b/eurilys4-service/build/web/META-INF/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/eurilys4-service/build/web/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/eurilys4-service/build/web/META-INF/context.xml b/eurilys4-service/build/web/META-INF/context.xml new file mode 100644 index 00000000..4c8ded45 --- /dev/null +++ b/eurilys4-service/build/web/META-INF/context.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Context antiJARLocking="true" path="/eurilys4-service"/> diff --git a/eurilys4-service/build/web/WEB-INF/classes/.netbeans_automatic_build b/eurilys4-service/build/web/WEB-INF/classes/.netbeans_automatic_build new file mode 100644 index 00000000..e69de29b diff --git a/eurilys4-service/build/web/WEB-INF/classes/.netbeans_update_resources b/eurilys4-service/build/web/WEB-INF/classes/.netbeans_update_resources new file mode 100644 index 00000000..e69de29b diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/CDL.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/CDL.rs new file mode 100644 index 00000000..a3710a79 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/CDL.rs @@ -0,0 +1 @@ +org.json.CDL diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/Cookie.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/Cookie.rs new file mode 100644 index 00000000..571c1181 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/Cookie.rs @@ -0,0 +1 @@ +org.json.Cookie diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/CookieList.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/CookieList.rs new file mode 100644 index 00000000..a48aac42 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/CookieList.rs @@ -0,0 +1 @@ +org.json.CookieList diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/HTTP.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/HTTP.rs new file mode 100644 index 00000000..83fe1909 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/HTTP.rs @@ -0,0 +1 @@ +org.json.HTTP diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/HTTPTokener.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/HTTPTokener.rs new file mode 100644 index 00000000..a0637fec --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/HTTPTokener.rs @@ -0,0 +1 @@ +org.json.HTTPTokener diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONArray.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONArray.rs new file mode 100644 index 00000000..6793286f --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONArray.rs @@ -0,0 +1 @@ +org.json.JSONArray diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONException.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONException.rs new file mode 100644 index 00000000..82f20cb3 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONException.rs @@ -0,0 +1 @@ +org.json.JSONException diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONML.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONML.rs new file mode 100644 index 00000000..81987b67 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONML.rs @@ -0,0 +1 @@ +org.json.JSONML diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONObject.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONObject.rs new file mode 100644 index 00000000..d6cb8c81 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONObject.rs @@ -0,0 +1,2 @@ +org.json.JSONObject +org.json.JSONObject$Null diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONString.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONString.rs new file mode 100644 index 00000000..3d4d07c4 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONString.rs @@ -0,0 +1 @@ +org.json.JSONString diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONStringer.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONStringer.rs new file mode 100644 index 00000000..e2045850 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONStringer.rs @@ -0,0 +1 @@ +org.json.JSONStringer diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONTokener.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONTokener.rs new file mode 100644 index 00000000..df25afd9 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONTokener.rs @@ -0,0 +1 @@ +org.json.JSONTokener diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONWriter.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONWriter.rs new file mode 100644 index 00000000..1335350b --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/JSONWriter.rs @@ -0,0 +1 @@ +org.json.JSONWriter diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/Kim.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/Kim.rs new file mode 100644 index 00000000..59aa7a0c --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/Kim.rs @@ -0,0 +1 @@ +org.json.Kim diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/README b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/README new file mode 100644 index 00000000..b77c71a2 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/README @@ -0,0 +1,68 @@ +JSON in Java [package org.json] + +Douglas Crockford +douglas@crockford.com + +2011-02-02 + + +JSON is a light-weight, language independent, data interchange format. +See http://www.JSON.org/ + +The files in this package implement JSON encoders/decoders in Java. +It also includes the capability to convert between JSON and XML, HTTP +headers, Cookies, and CDL. + +This is a reference implementation. There is a large number of JSON packages +in Java. Perhaps someday the Java community will standardize on one. Until +then, choose carefully. + +The license includes this restriction: "The software shall be used for good, +not evil." If your conscience cannot live with that, then choose a different +package. + +The package compiles on Java 1.2 thru Java 1.4. + + +JSONObject.java: The JSONObject can parse text from a String or a JSONTokener +to produce a map-like object. The object provides methods for manipulating its +contents, and for producing a JSON compliant object serialization. + +JSONArray.java: The JSONObject can parse text from a String or a JSONTokener +to produce a vector-like object. The object provides methods for manipulating +its contents, and for producing a JSON compliant array serialization. + +JSONTokener.java: The JSONTokener breaks a text into a sequence of individual +tokens. It can be constructed from a String, Reader, or InputStream. + +JSONException.java: The JSONException is the standard exception type thrown +by this package. + + +JSONString.java: The JSONString interface requires a toJSONString method, +allowing an object to provide its own serialization. + +JSONStringer.java: The JSONStringer provides a convenient facility for +building JSON strings. + +JSONWriter.java: The JSONWriter provides a convenient facility for building +JSON text through a writer. + + +CDL.java: CDL provides support for converting between JSON and comma +delimited lists. + +Cookie.java: Cookie provides support for converting between JSON and cookies. + +CookieList.java: CookieList provides support for converting between JSON and +cookie lists. + +HTTP.java: HTTP provides support for converting between JSON and HTTP headers. + +HTTPTokener.java: HTTPTokener extends JSONTokener for parsing HTTP headers. + +XML.java: XML provides support for converting between JSON and XML. + +JSONML.java: JSONML provides support for converting between JSONML and XML. + +XMLTokener.java: XMLTokener extends JSONTokener for parsing XML text. diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/XML.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/XML.rs new file mode 100644 index 00000000..631ca87d --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/XML.rs @@ -0,0 +1 @@ +org.json.XML diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/XMLTokener.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/XMLTokener.rs new file mode 100644 index 00000000..a41502d6 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/XMLTokener.rs @@ -0,0 +1 @@ +org.json.XMLTokener diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitInputStream.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitInputStream.rs new file mode 100644 index 00000000..9c7eadd4 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitInputStream.rs @@ -0,0 +1 @@ +org.json.zip.BitInputStream diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitOutputStream.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitOutputStream.rs new file mode 100644 index 00000000..d34c8e32 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitOutputStream.rs @@ -0,0 +1 @@ +org.json.zip.BitOutputStream diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitReader.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitReader.rs new file mode 100644 index 00000000..f9abae2b --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitReader.rs @@ -0,0 +1 @@ +org.json.zip.BitReader diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitWriter.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitWriter.rs new file mode 100644 index 00000000..4a7f98f2 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/BitWriter.rs @@ -0,0 +1 @@ +org.json.zip.BitWriter diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Compressor.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Compressor.rs new file mode 100644 index 00000000..39140536 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Compressor.rs @@ -0,0 +1 @@ +org.json.zip.Compressor diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Decompressor.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Decompressor.rs new file mode 100644 index 00000000..8c1c2ed9 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Decompressor.rs @@ -0,0 +1 @@ +org.json.zip.Decompressor diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Huff.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Huff.rs new file mode 100644 index 00000000..64299f50 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Huff.rs @@ -0,0 +1,2 @@ +org.json.zip.Huff$Symbol +org.json.zip.Huff diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/JSONzip.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/JSONzip.rs new file mode 100644 index 00000000..e58f733a --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/JSONzip.rs @@ -0,0 +1 @@ +org.json.zip.JSONzip diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Keep.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Keep.rs new file mode 100644 index 00000000..1eb6bf30 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/Keep.rs @@ -0,0 +1 @@ +org.json.zip.Keep diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/MapKeep.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/MapKeep.rs new file mode 100644 index 00000000..b193c020 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/MapKeep.rs @@ -0,0 +1 @@ +org.json.zip.MapKeep diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/None.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/None.rs new file mode 100644 index 00000000..44be7ce0 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/None.rs @@ -0,0 +1 @@ +org.json.zip.None diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/PostMortem.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/PostMortem.rs new file mode 100644 index 00000000..5569b1f3 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/PostMortem.rs @@ -0,0 +1 @@ +org.json.zip.PostMortem diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/README b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/README new file mode 100644 index 00000000..93e6470b --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/README @@ -0,0 +1,2 @@ +FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT BEEN TESTED ADEQUATELY FOR +PRODUCTION USE. diff --git a/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/TrieKeep.rs b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/TrieKeep.rs new file mode 100644 index 00000000..2899c6e7 --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/classes/jsonlib/zip/TrieKeep.rs @@ -0,0 +1,2 @@ +org.json.zip.TrieKeep$Node +org.json.zip.TrieKeep diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/CDL.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/CDL.class new file mode 100644 index 00000000..4beb9950 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/CDL.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/Cookie.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/Cookie.class new file mode 100644 index 00000000..7899f2c9 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/Cookie.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/CookieList.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/CookieList.class new file mode 100644 index 00000000..7e850b56 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/CookieList.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/HTTP.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/HTTP.class new file mode 100644 index 00000000..176c6cba Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/HTTP.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/HTTPTokener.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/HTTPTokener.class new file mode 100644 index 00000000..e21a8139 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/HTTPTokener.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONArray.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONArray.class new file mode 100644 index 00000000..6db7705c Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONArray.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONException.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONException.class new file mode 100644 index 00000000..762a6377 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONException.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONML.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONML.class new file mode 100644 index 00000000..1b256170 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONML.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONObject$1.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONObject$1.class new file mode 100644 index 00000000..64c0e8fc Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONObject$1.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONObject$Null.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONObject$Null.class new file mode 100644 index 00000000..9450e095 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONObject$Null.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONObject.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONObject.class new file mode 100644 index 00000000..325831fc Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONObject.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONString.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONString.class new file mode 100644 index 00000000..329f6867 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONString.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONStringer.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONStringer.class new file mode 100644 index 00000000..292cfa50 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONStringer.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONTokener.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONTokener.class new file mode 100644 index 00000000..66964392 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONTokener.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONWriter.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONWriter.class new file mode 100644 index 00000000..00ebbbc3 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/JSONWriter.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/Kim.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/Kim.class new file mode 100644 index 00000000..3c533420 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/Kim.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/XML.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/XML.class new file mode 100644 index 00000000..753d7c7f Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/XML.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/XMLTokener.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/XMLTokener.class new file mode 100644 index 00000000..4284aeab Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/XMLTokener.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitInputStream.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitInputStream.class new file mode 100644 index 00000000..7c4f81e6 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitInputStream.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitOutputStream.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitOutputStream.class new file mode 100644 index 00000000..cb46e318 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitOutputStream.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitReader.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitReader.class new file mode 100644 index 00000000..58013572 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitReader.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitWriter.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitWriter.class new file mode 100644 index 00000000..b31e26bf Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/BitWriter.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Compressor.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Compressor.class new file mode 100644 index 00000000..748559fe Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Compressor.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Decompressor.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Decompressor.class new file mode 100644 index 00000000..1900fdbc Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Decompressor.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Huff$Symbol.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Huff$Symbol.class new file mode 100644 index 00000000..79564bf8 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Huff$Symbol.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Huff.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Huff.class new file mode 100644 index 00000000..8bb1b9d7 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Huff.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/JSONzip.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/JSONzip.class new file mode 100644 index 00000000..a4c09c35 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/JSONzip.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Keep.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Keep.class new file mode 100644 index 00000000..fd3244f2 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/Keep.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/MapKeep.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/MapKeep.class new file mode 100644 index 00000000..15202ba8 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/MapKeep.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/None.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/None.class new file mode 100644 index 00000000..de9a878c Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/None.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/PostMortem.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/PostMortem.class new file mode 100644 index 00000000..8a3ca8ce Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/PostMortem.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/TrieKeep$Node.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/TrieKeep$Node.class new file mode 100644 index 00000000..96583d87 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/TrieKeep$Node.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/TrieKeep.class b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/TrieKeep.class new file mode 100644 index 00000000..8f12032b Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/org/json/zip/TrieKeep.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/service/CategoryService.class b/eurilys4-service/build/web/WEB-INF/classes/service/CategoryService.class new file mode 100644 index 00000000..6ceee463 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/service/CategoryService.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/service/SearchService.class b/eurilys4-service/build/web/WEB-INF/classes/service/SearchService.class new file mode 100644 index 00000000..c2a4f1d5 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/service/SearchService.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/service/TaskService.class b/eurilys4-service/build/web/WEB-INF/classes/service/TaskService.class new file mode 100644 index 00000000..a9be0df3 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/service/TaskService.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/service/UserService.class b/eurilys4-service/build/web/WEB-INF/classes/service/UserService.class new file mode 100644 index 00000000..1e0e80b9 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/service/UserService.class differ diff --git a/eurilys4-service/build/web/WEB-INF/classes/service/dbConnection.class b/eurilys4-service/build/web/WEB-INF/classes/service/dbConnection.class new file mode 100644 index 00000000..86ee5b51 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/classes/service/dbConnection.class differ diff --git a/eurilys4-service/build/web/WEB-INF/lib/activation.jar b/eurilys4-service/build/web/WEB-INF/lib/activation.jar new file mode 100644 index 00000000..7b5cac39 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/lib/activation.jar differ diff --git a/eurilys4-service/build/web/WEB-INF/lib/jsr311-api-1.1.1.jar b/eurilys4-service/build/web/WEB-INF/lib/jsr311-api-1.1.1.jar new file mode 100644 index 00000000..2a55bcdd Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/lib/jsr311-api-1.1.1.jar differ diff --git a/eurilys4-service/build/web/WEB-INF/lib/mysql-connector-java-5.1.18-bin.jar b/eurilys4-service/build/web/WEB-INF/lib/mysql-connector-java-5.1.18-bin.jar new file mode 100644 index 00000000..d2b0e180 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/lib/mysql-connector-java-5.1.18-bin.jar differ diff --git a/eurilys4-service/build/web/WEB-INF/lib/webservices-api.jar b/eurilys4-service/build/web/WEB-INF/lib/webservices-api.jar new file mode 100644 index 00000000..56f6c249 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/lib/webservices-api.jar differ diff --git a/eurilys4-service/build/web/WEB-INF/lib/webservices-extra-api.jar b/eurilys4-service/build/web/WEB-INF/lib/webservices-extra-api.jar new file mode 100644 index 00000000..51d6ec90 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/lib/webservices-extra-api.jar differ diff --git a/eurilys4-service/build/web/WEB-INF/lib/webservices-extra.jar b/eurilys4-service/build/web/WEB-INF/lib/webservices-extra.jar new file mode 100644 index 00000000..f92db172 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/lib/webservices-extra.jar differ diff --git a/eurilys4-service/build/web/WEB-INF/lib/webservices-rt.jar b/eurilys4-service/build/web/WEB-INF/lib/webservices-rt.jar new file mode 100644 index 00000000..c2d83fd7 Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/lib/webservices-rt.jar differ diff --git a/eurilys4-service/build/web/WEB-INF/lib/webservices-tools.jar b/eurilys4-service/build/web/WEB-INF/lib/webservices-tools.jar new file mode 100644 index 00000000..646e1f6f Binary files /dev/null and b/eurilys4-service/build/web/WEB-INF/lib/webservices-tools.jar differ diff --git a/eurilys4-service/build/web/WEB-INF/web.xml b/eurilys4-service/build/web/WEB-INF/web.xml new file mode 100644 index 00000000..dddb4cda --- /dev/null +++ b/eurilys4-service/build/web/WEB-INF/web.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + <servlet> + <servlet-name>ServletHandler</servlet-name> + <servlet-class>servlet.ServletHandler</servlet-class> + </servlet> + <servlet> + <servlet-name>UserService</servlet-name> + <servlet-class>service.UserService</servlet-class> + </servlet> + <servlet> + <servlet-name>BasicServlet</servlet-name> + <servlet-class>service.BasicServlet</servlet-class> + </servlet> + <servlet> + <servlet-name>TaskService</servlet-name> + <servlet-class>service.TaskService</servlet-class> + </servlet> + <servlet> + <servlet-name>CategoryService</servlet-name> + <servlet-class>service.CategoryService</servlet-class> + </servlet> + <servlet> + <servlet-name>SearchService</servlet-name> + <servlet-class>service.SearchService</servlet-class> + </servlet> + <servlet> + <servlet-name>SOAPAddTask</servlet-name> + <servlet-class>service.SOAPAddTask</servlet-class> + </servlet> + <servlet> + <servlet-name>SOAPAddCategory</servlet-name> + <servlet-class>service.SOAPAddCategory</servlet-class> + </servlet> + <servlet> + <servlet-name>SOAPAddComment</servlet-name> + <servlet-class>service.SOAPAddComment</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>ServletHandler</servlet-name> + <url-pattern>/ServletHandler</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>UserService</servlet-name> + <url-pattern>/user/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>BasicServlet</servlet-name> + <url-pattern>/BasicServlet</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>TaskService</servlet-name> + <url-pattern>/task/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>CategoryService</servlet-name> + <url-pattern>/category/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>SearchService</servlet-name> + <url-pattern>/search/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>SOAPAddTask</servlet-name> + <url-pattern>/SOAPAddTask</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>SOAPAddCategory</servlet-name> + <url-pattern>/SOAPAddCategory</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>SOAPAddComment</servlet-name> + <url-pattern>/SOAPAddComment</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout> + 30 + </session-timeout> + </session-config> +</web-app> diff --git a/eurilys4-service/dist/eurilys4-service.war b/eurilys4-service/dist/eurilys4-service.war new file mode 100644 index 00000000..1ea4c26f Binary files /dev/null and b/eurilys4-service/dist/eurilys4-service.war differ diff --git a/eurilys4-service/nbproject/ant-deploy.xml b/eurilys4-service/nbproject/ant-deploy.xml new file mode 100644 index 00000000..9bc5adf7 --- /dev/null +++ b/eurilys4-service/nbproject/ant-deploy.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project default="-deploy-ant" basedir="."> + <target name="-init" if="deploy.ant.enabled"> + <property file="${deploy.ant.properties.file}"/> + <tempfile property="temp.module.folder" prefix="tomcat" destdir="${java.io.tmpdir}"/> + <unwar src="${deploy.ant.archive}" dest="${temp.module.folder}"> + <patternset includes="META-INF/context.xml"/> + </unwar> + <xmlproperty file="${temp.module.folder}/META-INF/context.xml"/> + <delete dir="${temp.module.folder}"/> + </target> + <target name="-check-credentials" if="deploy.ant.enabled" depends="-init"> + <fail message="Tomcat password has to be passed as tomcat.password property."> + <condition> + <not> + <isset property="tomcat.password"/> + </not> + </condition> + </fail> + </target> + <target name="-deploy-ant" if="deploy.ant.enabled" depends="-init,-check-credentials"> + <echo message="Deploying ${deploy.ant.archive} to ${Context(path)}"/> + <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"> + <classpath> + <pathelement path="${tomcat.home}/lib/catalina-ant.jar"/> + <pathelement path="${tomcat.home}/lib/tomcat-coyote.jar"/> + <pathelement path="${tomcat.home}/lib/tomcat-util.jar"/> + <pathelement path="${tomcat.home}/bin/tomcat-juli.jar"/> + </classpath> + </taskdef> + <deploy url="${tomcat.url}/manager/text" username="${tomcat.username}" + password="${tomcat.password}" path="${Context(path)}" + war="${deploy.ant.archive}"/> + <property name="deploy.ant.client.url" value="${tomcat.url}${Context(path)}"/> + </target> + <target name="-undeploy-ant" if="deploy.ant.enabled" depends="-init,-check-credentials"> + <echo message="Undeploying ${Context(path)}"/> + <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"> + <classpath> + <pathelement path="${tomcat.home}/lib/catalina-ant.jar"/> + <pathelement path="${tomcat.home}/lib/tomcat-coyote.jar"/> + <pathelement path="${tomcat.home}/lib/tomcat-util.jar"/> + <pathelement path="${tomcat.home}/bin/tomcat-juli.jar"/> + </classpath> + </taskdef> + <undeploy url="${tomcat.url}/manager/text" username="${tomcat.username}" + password="${tomcat.password}" path="${Context(path)}"/> + </target> +</project> diff --git a/eurilys4-service/nbproject/build-impl.xml b/eurilys4-service/nbproject/build-impl.xml new file mode 100644 index 00000000..33c21397 --- /dev/null +++ b/eurilys4-service/nbproject/build-impl.xml @@ -0,0 +1,1418 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *** GENERATED FROM project.xml - DO NOT EDIT *** + *** EDIT ../build.xml INSTEAD *** + + For the purpose of easier reading the script + is divided into following sections: + - initialization + - compilation + - dist + - execution + - debugging + - javadoc + - test compilation + - test execution + - test debugging + - cleanup + + --> +<project xmlns:webproject1="http://www.netbeans.org/ns/web-project/1" xmlns:webproject2="http://www.netbeans.org/ns/web-project/2" xmlns:webproject3="http://www.netbeans.org/ns/web-project/3" basedir=".." default="default" name="eurilys4-service-impl"> + <import file="rest-build.xml"/> + <import file="ant-deploy.xml"/> + <fail message="Please build using Ant 1.7.1 or higher."> + <condition> + <not> + <antversion atleast="1.7.1"/> + </not> + </condition> + </fail> + <target depends="dist,javadoc" description="Build whole project." name="default"/> + <!-- + INITIALIZATION SECTION + --> + <target name="-pre-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="-pre-init" name="-init-private"> + <property file="nbproject/private/private.properties"/> + </target> + <target depends="-pre-init,-init-private" name="-init-user"> + <property file="${user.properties.file}"/> + <!-- The two properties below are usually overridden --> + <!-- by the active platform. Just a fallback. --> + <property name="default.javac.source" value="1.4"/> + <property name="default.javac.target" value="1.4"/> + </target> + <target depends="-pre-init,-init-private,-init-user" name="-init-project"> + <property file="nbproject/project.properties"/> + </target> + <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" if="dist.ear.dir" name="-do-ear-init"/> + <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init"> + <condition property="have.tests"> + <or> + <available file="${test.src.dir}"/> + </or> + </condition> + <condition property="have.sources"> + <or> + <available file="${src.dir}"/> + </or> + </condition> + <condition property="netbeans.home+have.tests"> + <and> + <isset property="netbeans.home"/> + <isset property="have.tests"/> + </and> + </condition> + <condition property="no.javadoc.preview"> + <isfalse value="${javadoc.preview}"/> + </condition> + <property name="javac.compilerargs" value=""/> + <condition property="no.deps"> + <and> + <istrue value="${no.dependencies}"/> + </and> + </condition> + <condition property="no.dist.ear.dir"> + <not> + <isset property="dist.ear.dir"/> + </not> + </condition> + <property name="build.web.excludes" value="${build.classes.excludes}"/> + <condition property="do.compile.jsps"> + <istrue value="${compile.jsps}"/> + </condition> + <condition property="do.debug.server"> + <or> + <not> + <isset property="debug.server"/> + </not> + <istrue value="${debug.server}"/> + <and> + <not> + <istrue value="${debug.server}"/> + </not> + <not> + <istrue value="${debug.client}"/> + </not> + </and> + </or> + </condition> + <condition property="do.debug.client"> + <istrue value="${debug.client}"/> + </condition> + <condition property="do.display.browser"> + <istrue value="${display.browser}"/> + </condition> + <condition property="do.display.browser.debug"> + <and> + <isset property="do.display.browser"/> + <not> + <isset property="do.debug.client"/> + </not> + </and> + </condition> + <available file="${conf.dir}/MANIFEST.MF" property="has.custom.manifest"/> + <available file="${persistence.xml.dir}/persistence.xml" property="has.persistence.xml"/> + <condition property="do.war.package.with.custom.manifest"> + <isset property="has.custom.manifest"/> + </condition> + <condition property="do.war.package.without.custom.manifest"> + <not> + <isset property="has.custom.manifest"/> + </not> + </condition> + <condition property="do.tmp.war.package.with.custom.manifest"> + <and> + <isset property="has.custom.manifest"/> + <or> + <isfalse value="${directory.deployment.supported}"/> + <isset property="dist.ear.dir"/> + </or> + </and> + </condition> + <condition property="do.tmp.war.package.without.custom.manifest"> + <and> + <not> + <isset property="has.custom.manifest"/> + </not> + <or> + <isfalse value="${directory.deployment.supported}"/> + <isset property="dist.ear.dir"/> + </or> + </and> + </condition> + <condition property="do.tmp.war.package"> + <or> + <isfalse value="${directory.deployment.supported}"/> + <isset property="dist.ear.dir"/> + </or> + </condition> + <property name="build.meta.inf.dir" value="${build.web.dir}/META-INF"/> + <condition else="" property="application.args.param" value="${application.args}"> + <and> + <isset property="application.args"/> + <not> + <equals arg1="${application.args}" arg2="" trim="true"/> + </not> + </and> + </condition> + <property name="source.encoding" value="${file.encoding}"/> + <condition property="javadoc.encoding.used" value="${javadoc.encoding}"> + <and> + <isset property="javadoc.encoding"/> + <not> + <equals arg1="${javadoc.encoding}" arg2=""/> + </not> + </and> + </condition> + <property name="javadoc.encoding.used" value="${source.encoding}"/> + <property name="includes" value="**"/> + <property name="excludes" value=""/> + <property name="runmain.jvmargs" value=""/> + <path id="endorsed.classpath.path" path="${endorsed.classpath}"/> + <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'"> + <and> + <isset property="endorsed.classpath"/> + <length length="0" string="${endorsed.classpath}" when="greater"/> + </and> + </condition> + <condition else="false" property="jdkBug6558476"> + <and> + <matches pattern="1\.[56]" string="${java.specification.version}"/> + <not> + <os family="unix"/> + </not> + </and> + </condition> + <property name="javac.fork" value="${jdkBug6558476}"/> + <condition property="junit.available"> + <or> + <available classname="org.junit.Test" classpath="${run.test.classpath}"/> + <available classname="junit.framework.Test" classpath="${run.test.classpath}"/> + </or> + </condition> + <condition property="testng.available"> + <available classname="org.testng.annotations.Test" classpath="${run.test.classpath}"/> + </condition> + <condition property="junit+testng.available"> + <and> + <istrue value="${junit.available}"/> + <istrue value="${testng.available}"/> + </and> + </condition> + <condition else="testng" property="testng.mode" value="mixed"> + <istrue value="${junit+testng.available}"/> + </condition> + <condition else="" property="testng.debug.mode" value="-mixed"> + <istrue value="${junit+testng.available}"/> + </condition> + </target> + <target depends="init" name="-init-cos" unless="deploy.on.save"> + <condition property="deploy.on.save" value="true"> + <or> + <istrue value="${j2ee.deploy.on.save}"/> + <istrue value="${j2ee.compile.on.save}"/> + </or> + </condition> + </target> + <target name="-post-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check"> + <fail unless="src.dir">Must set src.dir</fail> + <fail unless="test.src.dir">Must set test.src.dir</fail> + <fail unless="build.dir">Must set build.dir</fail> + <fail unless="build.web.dir">Must set build.web.dir</fail> + <fail unless="build.generated.dir">Must set build.generated.dir</fail> + <fail unless="dist.dir">Must set dist.dir</fail> + <fail unless="build.classes.dir">Must set build.classes.dir</fail> + <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail> + <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail> + <fail unless="build.test.results.dir">Must set build.test.results.dir</fail> + <fail unless="build.classes.excludes">Must set build.classes.excludes</fail> + <fail unless="dist.war">Must set dist.war</fail> + <condition property="missing.j2ee.server.home"> + <and> + <matches pattern="j2ee.server.home" string="${j2ee.platform.classpath}"/> + <not> + <isset property="j2ee.server.home"/> + </not> + </and> + </condition> + <fail if="missing.j2ee.server.home"> +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + </fail> + <fail unless="j2ee.platform.classpath"> +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + </fail> + </target> + <target name="-init-macrodef-property"> + <macrodef name="property" uri="http://www.netbeans.org/ns/web-project/1"> + <attribute name="name"/> + <attribute name="value"/> + <sequential> + <property name="@{name}" value="${@{value}}"/> + </sequential> + </macrodef> + </target> + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors"> + <macrodef name="javac" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}:${j2ee.platform.classpath}" name="classpath"/> + <attribute default="${javac.processorpath}" name="processorpath"/> + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="${javac.debug}" name="debug"/> + <attribute default="${empty.dir}" name="gensrcdir"/> + <element name="customize" optional="true"/> + <sequential> + <property location="${build.dir}/empty" name="empty.dir"/> + <mkdir dir="${empty.dir}"/> + <mkdir dir="@{apgeneratedsrcdir}"/> + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" srcdir="@{srcdir}" target="${javac.target}"> + <src> + <dirset dir="@{gensrcdir}" erroronmissingdir="false"> + <include name="*"/> + </dirset> + </src> + <classpath> + <path path="@{classpath}"/> + </classpath> + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/> + <compilerarg line="${javac.compilerargs}"/> + <compilerarg value="-processorpath"/> + <compilerarg path="@{processorpath}:${empty.dir}"/> + <compilerarg line="${ap.processors.internal}"/> + <compilerarg value="-s"/> + <compilerarg path="@{apgeneratedsrcdir}"/> + <compilerarg line="${ap.proc.none.internal}"/> + <customize/> + </javac> + </sequential> + </macrodef> + </target> + <target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal"> + <macrodef name="javac" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}:${j2ee.platform.classpath}" name="classpath"/> + <attribute default="${javac.processorpath}" name="processorpath"/> + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="${javac.debug}" name="debug"/> + <attribute default="${empty.dir}" name="gensrcdir"/> + <element name="customize" optional="true"/> + <sequential> + <property location="${build.dir}/empty" name="empty.dir"/> + <mkdir dir="${empty.dir}"/> + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" includeantruntime="false" includes="@{includes}" source="${javac.source}" srcdir="@{srcdir}" target="${javac.target}"> + <src> + <dirset dir="@{gensrcdir}" erroronmissingdir="false"> + <include name="*"/> + </dirset> + </src> + <classpath> + <path path="@{classpath}"/> + </classpath> + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/> + <compilerarg line="${javac.compilerargs}"/> + <customize/> + </javac> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac"> + <macrodef name="depend" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${src.dir}" name="srcdir"/> + <attribute default="${build.classes.dir}" name="destdir"/> + <attribute default="${javac.classpath}:${j2ee.platform.classpath}" name="classpath"/> + <sequential> + <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}"> + <classpath> + <path path="@{classpath}"/> + </classpath> + </depend> + </sequential> + </macrodef> + <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${build.classes.dir}" name="destdir"/> + <sequential> + <fail unless="javac.includes">Must set javac.includes</fail> + <pathconvert pathsep="${line.separator}" property="javac.includes.binary"> + <path> + <filelist dir="@{destdir}" files="${javac.includes}"/> + </path> + <globmapper from="*.java" to="*.class"/> + </pathconvert> + <tempfile deleteonexit="true" property="javac.includesfile.binary"/> + <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/> + <delete> + <files includesfile="${javac.includesfile.binary}"/> + </delete> + <delete file="${javac.includesfile.binary}"/> + </sequential> + </macrodef> + </target> + <target if="${junit.available}" name="-init-macrodef-junit-init"> + <condition else="false" property="nb.junit.batch" value="true"> + <and> + <istrue value="${junit.available}"/> + <not> + <isset property="test.method"/> + </not> + </and> + </condition> + <condition else="false" property="nb.junit.single" value="true"> + <and> + <istrue value="${junit.available}"/> + <isset property="test.method"/> + </and> + </condition> + </target> + <target name="-init-test-properties"> + <property name="test.binaryincludes" value="<nothing>"/> + <property name="test.binarytestincludes" value=""/> + <property name="test.binaryexcludes" value=""/> + </target> + <target if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}"> + <macrodef name="junit" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <junit dir="${basedir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true" tempdir="${java.io.tmpdir}"> + <test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg value="-ea"/> + <customize/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-test-properties" if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}"> + <macrodef name="junit" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <property name="run.jvmargs.ide" value=""/> + <junit dir="${basedir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true" tempdir="${build.dir}"> + <batchtest todir="${build.test.results.dir}"> + <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}"> + <filename name="@{testincludes}"/> + </fileset> + <fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}"> + <filename name="${test.binarytestincludes}"/> + </fileset> + </batchtest> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg value="-ea"/> + <jvmarg line="${run.jvmargs.ide}"/> + <customize/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit-init,-init-macrodef-junit-single, -init-macrodef-junit-batch" if="${junit.available}" name="-init-macrodef-junit"/> + <target if="${testng.available}" name="-init-macrodef-testng"> + <macrodef name="testng" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}"> + <isset property="test.method"/> + </condition> + <union id="test.set"> + <fileset dir="${test.src.dir}" excludes="@{excludes},**/*.xml,${excludes}" includes="@{includes}"> + <filename name="@{testincludes}"/> + </fileset> + </union> + <taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/> + <testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="eurilys4-service" testname="TestNG tests" workingDir="${basedir}"> + <xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/> + <propertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </propertyset> + <customize/> + </testng> + </sequential> + </macrodef> + </target> + <target name="-init-macrodef-test-impl"> + <macrodef name="test-impl" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <echo>No tests executed.</echo> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit" if="${junit.available}" name="-init-macrodef-junit-impl"> + <macrodef name="test-impl" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <webproject2:junit excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize/> + </webproject2:junit> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-testng" if="${testng.available}" name="-init-macrodef-testng-impl"> + <macrodef name="test-impl" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <webproject2:testng excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize/> + </webproject2:testng> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-test-impl,-init-macrodef-junit-impl,-init-macrodef-testng-impl" name="-init-macrodef-test"> + <macrodef name="test" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <sequential> + <webproject2:test-impl excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize> + <classpath> + <path path="${run.test.classpath}:${j2ee.platform.classpath}:${j2ee.platform.embeddableejb.classpath}"/> + </classpath> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg line="${runmain.jvmargs}"/> + </customize> + </webproject2:test-impl> + </sequential> + </macrodef> + </target> + <target if="${junit.available}" name="-init-macrodef-junit-debug" unless="${nb.junit.batch}"> + <macrodef name="junit-debug" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <junit dir="${basedir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true" tempdir="${java.io.tmpdir}"> + <test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg value="-ea"/> + <jvmarg line="${debug-args-line}"/> + <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/> + <customize/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-test-properties" if="${nb.junit.batch}" name="-init-macrodef-junit-debug-batch"> + <macrodef name="junit-debug" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element name="customize" optional="true"/> + <sequential> + <property name="run.jvmargs.ide" value=""/> + <junit dir="${basedir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true" tempdir="${build.dir}"> + <batchtest todir="${build.test.results.dir}"> + <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}"> + <filename name="@{testincludes}"/> + </fileset> + <fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}"> + <filename name="${test.binarytestincludes}"/> + </fileset> + </batchtest> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + <jvmarg value="-ea"/> + <jvmarg line="${run.jvmargs.ide}"/> + <jvmarg line="${debug-args-line}"/> + <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/> + <customize/> + </junit> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit-debug,-init-macrodef-junit-debug-batch" if="${junit.available}" name="-init-macrodef-junit-debug-impl"> + <macrodef name="test-debug-impl" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <element implicit="true" name="customize" optional="true"/> + <sequential> + <webproject2:junit-debug excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize/> + </webproject2:junit-debug> + </sequential> + </macrodef> + </target> + <target if="${testng.available}" name="-init-macrodef-testng-debug"> + <macrodef name="testng-debug" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <element name="customize2" optional="true"/> + <sequential> + <condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}"> + <isset property="test.method"/> + </condition> + <condition else="-suitename eurilys4-service -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}"> + <matches pattern=".*\.xml" string="@{testClass}"/> + </condition> + <delete dir="${build.test.results.dir}" quiet="true"/> + <mkdir dir="${build.test.results.dir}"/> + <webproject1:debug args="${testng.cmd.args}" classname="org.testng.TestNG" classpath="${debug.test.classpath}:${j2ee.platform.embeddableejb.classpath}"> + <customize> + <customize2/> + <jvmarg value="-ea"/> + <arg line="${testng.debug.mode}"/> + <arg line="-d ${build.test.results.dir}"/> + <arg line="-listener org.testng.reporters.VerboseReporter"/> + </customize> + </webproject1:debug> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-testng-debug" if="${testng.available}" name="-init-macrodef-testng-debug-impl"> + <macrodef name="testng-debug-impl" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <element implicit="true" name="customize2" optional="true"/> + <sequential> + <webproject2:testng-debug testClass="@{testClass}" testMethod="@{testMethod}"> + <customize2/> + </webproject2:testng-debug> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-junit-debug-impl" if="${junit.available}" name="-init-macrodef-test-debug-junit"> + <macrodef name="test-debug" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <sequential> + <webproject2:test-debug-impl excludes="@{excludes}" includes="@{includes}" testincludes="@{testincludes}" testmethods="@{testmethods}"> + <customize> + <classpath> + <path path="${run.test.classpath}:${j2ee.platform.classpath}:${j2ee.platform.embeddableejb.classpath}"/> + </classpath> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg line="${runmain.jvmargs}"/> + </customize> + </webproject2:test-debug-impl> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-testng-debug-impl" if="${testng.available}" name="-init-macrodef-test-debug-testng"> + <macrodef name="test-debug" uri="http://www.netbeans.org/ns/web-project/2"> + <attribute default="${includes}" name="includes"/> + <attribute default="${excludes}" name="excludes"/> + <attribute default="**" name="testincludes"/> + <attribute default="" name="testmethods"/> + <attribute default="${main.class}" name="testClass"/> + <attribute default="" name="testMethod"/> + <sequential> + <webproject2:testng-debug-impl testClass="@{testClass}" testMethod="@{testMethod}"> + <customize2> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + </customize2> + </webproject2:testng-debug-impl> + </sequential> + </macrodef> + </target> + <target depends="-init-macrodef-test-debug-junit,-init-macrodef-test-debug-testng" name="-init-macrodef-test-debug"/> + <target name="-init-macrodef-java"> + <macrodef name="java" uri="http://www.netbeans.org/ns/web-project/1"> + <attribute default="${main.class}" name="classname"/> + <attribute default="${debug.classpath}" name="classpath"/> + <element name="customize" optional="true"/> + <sequential> + <java classname="@{classname}" fork="true"> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg line="${runmain.jvmargs}"/> + <classpath> + <path path="@{classpath}:${j2ee.platform.classpath}"/> + </classpath> + <syspropertyset> + <propertyref prefix="run-sys-prop."/> + <mapper from="run-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <customize/> + </java> + </sequential> + </macrodef> + </target> + <target name="-init-macrodef-nbjsdebug"> + <macrodef name="nbjsdebugstart" uri="http://www.netbeans.org/ns/web-project/1"> + <attribute default="${client.url}" name="webUrl"/> + <sequential> + <nbjsdebugstart urlPart="${client.urlPart}" webUrl="@{webUrl}"/> + </sequential> + </macrodef> + </target> + <target depends="-init-debug-args" name="-init-macrodef-nbjpda"> + <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/web-project/1"> + <attribute default="${main.class}" name="name"/> + <attribute default="${debug.classpath}:${j2ee.platform.classpath}" name="classpath"/> + <sequential> + <nbjpdastart addressproperty="jpda.address" name="@{name}" transport="${debug-transport}"> + <classpath> + <path path="@{classpath}"/> + </classpath> + </nbjpdastart> + </sequential> + </macrodef> + <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/web-project/1"> + <attribute default="${build.classes.dir}" name="dir"/> + <sequential> + <nbjpdareload> + <fileset dir="@{dir}" includes="${fix.classes}"> + <include name="${fix.includes}*.class"/> + </fileset> + </nbjpdareload> + </sequential> + </macrodef> + <macrodef name="nbjpdaappreloaded" uri="http://www.netbeans.org/ns/web-project/1"> + <sequential> + <nbjpdaappreloaded/> + </sequential> + </macrodef> + </target> + <target name="-init-debug-args"> + <property name="version-output" value="java version "${ant.java.version}"/> + <condition property="have-jdk-older-than-1.4"> + <or> + <contains string="${version-output}" substring="java version "1.0"/> + <contains string="${version-output}" substring="java version "1.1"/> + <contains string="${version-output}" substring="java version "1.2"/> + <contains string="${version-output}" substring="java version "1.3"/> + </or> + </condition> + <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none"> + <istrue value="${have-jdk-older-than-1.4}"/> + </condition> + <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem"> + <os family="windows"/> + </condition> + <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}"> + <isset property="debug.transport"/> + </condition> + </target> + <target depends="-init-debug-args" name="-init-macrodef-debug"> + <macrodef name="debug" uri="http://www.netbeans.org/ns/web-project/1"> + <attribute default="${main.class}" name="classname"/> + <attribute default="${debug.classpath}:${j2ee.platform.classpath}" name="classpath"/> + <attribute default="${application.args.param}" name="args"/> + <element name="customize" optional="true"/> + <sequential> + <java classname="@{classname}" fork="true"> + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/> + <jvmarg line="${debug-args-line}"/> + <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/> + <jvmarg line="${runmain.jvmargs}"/> + <classpath> + <path path="@{classpath}"/> + </classpath> + <syspropertyset> + <propertyref prefix="run-sys-prop."/> + <mapper from="run-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <arg line="@{args}"/> + <customize/> + </java> + </sequential> + </macrodef> + </target> + <target name="-init-taskdefs"> + <fail unless="libs.CopyLibs.classpath"> +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + </fail> + <taskdef classpath="${libs.CopyLibs.classpath}" resource="org/netbeans/modules/java/j2seproject/copylibstask/antlib.xml"/> + </target> + <target name="-init-ap-cmdline-properties"> + <property name="annotation.processing.enabled" value="true"/> + <property name="annotation.processing.processors.list" value=""/> + <property name="annotation.processing.run.all.processors" value="true"/> + <property name="javac.processorpath" value="${javac.classpath}"/> + <property name="javac.test.processorpath" value="${javac.test.classpath}"/> + <condition property="ap.supported.internal" value="true"> + <not> + <matches pattern="1\.[0-5](\..*)?" string="${javac.source}"/> + </not> + </condition> + </target> + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-ap-cmdline-supported"> + <condition else="" property="ap.processors.internal" value="-processor ${annotation.processing.processors.list}"> + <isfalse value="${annotation.processing.run.all.processors}"/> + </condition> + <condition else="" property="ap.proc.none.internal" value="-proc:none"> + <isfalse value="${annotation.processing.enabled}"/> + </condition> + </target> + <target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline"> + <property name="ap.cmd.line.internal" value=""/> + </target> + <!-- + pre NB7.2 profiling section; consider it deprecated + --> + <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-check" if="profiler.info.jvmargs.agent" name="profile-init"/> + <target if="profiler.info.jvmargs.agent" name="-profile-pre-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target if="profiler.info.jvmargs.agent" name="-profile-post-init"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="-profile-pre-init, init, -profile-post-init" if="profiler.info.jvmargs.agent" name="-profile-init-check"> + <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail> + <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail> + </target> + <!-- + end of pre NB7.2 profiling section + --> + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-test,-init-macrodef-test-debug,-init-macrodef-java,-init-macrodef-nbjpda,-init-macrodef-nbjsdebug,-init-macrodef-debug,-init-taskdefs,-init-ap-cmdline" name="init"/> + <!-- + COMPILATION SECTION + --> + <target depends="init" if="no.dist.ear.dir" name="deps-module-jar" unless="no.deps"/> + <target depends="init" if="dist.ear.dir" name="deps-ear-jar" unless="no.deps"/> + <target depends="init, deps-module-jar, deps-ear-jar" name="deps-jar" unless="no.deps"/> + <target depends="init,deps-jar,generate-rest-config" name="-pre-pre-compile"> + <mkdir dir="${build.classes.dir}"/> + </target> + <target name="-pre-compile"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target name="-copy-webdir"> + <copy todir="${build.web.dir}"> + <fileset dir="${web.docbase.dir}" excludes="${build.web.excludes},${excludes}" includes="${includes}"/> + </copy> + <copy todir="${build.web.dir}/WEB-INF"> + <fileset dir="${webinf.dir}" excludes="${build.web.excludes}"/> + </copy> + </target> + <target depends="init, deps-jar, -pre-pre-compile, -pre-compile, -copy-manifest, -copy-persistence-xml, -copy-webdir, library-inclusion-in-archive,library-inclusion-in-manifest" if="have.sources" name="-do-compile"> + <webproject2:javac destdir="${build.classes.dir}" gensrcdir="${build.generated.sources.dir}"/> + <copy todir="${build.classes.dir}"> + <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target if="has.custom.manifest" name="-copy-manifest"> + <mkdir dir="${build.meta.inf.dir}"/> + <copy todir="${build.meta.inf.dir}"> + <fileset dir="${conf.dir}" includes="MANIFEST.MF"/> + </copy> + </target> + <target if="has.persistence.xml" name="-copy-persistence-xml"> + <mkdir dir="${build.web.dir}/WEB-INF/classes/META-INF"/> + <copy todir="${build.web.dir}/WEB-INF/classes/META-INF"> + <fileset dir="${persistence.xml.dir}" includes="persistence.xml orm.xml"/> + </copy> + </target> + <target name="-post-compile"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/> + <target name="-pre-compile-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single"> + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail> + <webproject2:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}"/> + <copy todir="${build.classes.dir}"> + <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target name="-post-compile-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/> + <property name="jspc.schemas" value="/resources/schemas/"/> + <property name="jspc.dtds" value="/resources/dtds/"/> + <target depends="compile" description="Test compile JSP pages to expose compilation errors." if="do.compile.jsps" name="compile-jsps"> + <mkdir dir="${build.generated.dir}/src"/> + <java classname="org.netbeans.modules.web.project.ant.JspC" failonerror="true" fork="true"> + <arg value="-uriroot"/> + <arg file="${basedir}/${build.web.dir}"/> + <arg value="-d"/> + <arg file="${basedir}/${build.generated.dir}/src"/> + <arg value="-die1"/> + <arg value="-schemas ${jspc.schemas}"/> + <arg value="-dtds ${jspc.dtds}"/> + <arg value="-compilerSourceVM ${javac.source}"/> + <arg value="-compilerTargetVM ${javac.target}"/> + <arg value="-javaEncoding ${source.encoding}"/> + <arg value="-sysClasspath ${libs.jsp-compilation-syscp.classpath}"/> + <classpath path="${java.home}/../lib/tools.jar:${libs.jsp-compiler.classpath}:${libs.jsp-compilation.classpath}"/> + </java> + <mkdir dir="${build.generated.dir}/classes"/> + <webproject2:javac classpath="${build.classes.dir}:${libs.jsp-compilation.classpath}:${javac.classpath}:${j2ee.platform.classpath}" destdir="${build.generated.dir}/classes" srcdir="${build.generated.dir}/src"/> + </target> + <target depends="compile" if="jsp.includes" name="-do-compile-single-jsp"> + <fail unless="javac.jsp.includes">Must select some files in the IDE or set javac.jsp.includes</fail> + <mkdir dir="${build.generated.dir}/src"/> + <java classname="org.netbeans.modules.web.project.ant.JspCSingle" failonerror="true" fork="true"> + <arg value="-uriroot"/> + <arg file="${basedir}/${build.web.dir}"/> + <arg value="-d"/> + <arg file="${basedir}/${build.generated.dir}/src"/> + <arg value="-die1"/> + <arg value="-schemas ${jspc.schemas}"/> + <arg value="-dtds ${jspc.dtds}"/> + <arg value="-sysClasspath ${libs.jsp-compilation-syscp.classpath}"/> + <arg value="-jspc.files"/> + <arg path="${jsp.includes}"/> + <arg value="-compilerSourceVM ${javac.source}"/> + <arg value="-compilerTargetVM ${javac.target}"/> + <arg value="-javaEncoding ${source.encoding}"/> + <classpath path="${java.home}/../lib/tools.jar:${libs.jsp-compiler.classpath}:${libs.jsp-compilation.classpath}"/> + </java> + <mkdir dir="${build.generated.dir}/classes"/> + <webproject2:javac classpath="${build.classes.dir}:${libs.jsp-compilation.classpath}:${javac.classpath}:${j2ee.platform.classpath}" destdir="${build.generated.dir}/classes" srcdir="${build.generated.dir}/src"> + <customize> + <patternset includes="${javac.jsp.includes}"/> + </customize> + </webproject2:javac> + </target> + <target name="compile-single-jsp"> + <fail unless="jsp.includes">Must select a file in the IDE or set jsp.includes</fail> + <antcall target="-do-compile-single-jsp"/> + </target> + <!-- + DIST BUILDING SECTION + --> + <target name="-pre-dist"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,compile-jsps,-pre-dist" if="do.war.package.without.custom.manifest" name="-do-dist-without-manifest"> + <dirname file="${dist.war}" property="dist.jar.dir"/> + <mkdir dir="${dist.jar.dir}"/> + <jar compress="${jar.compress}" jarfile="${dist.war}"> + <fileset dir="${build.web.dir}" excludes="WEB-INF/classes/.netbeans_*"/> + </jar> + </target> + <target depends="init,compile,compile-jsps,-pre-dist" if="do.war.package.with.custom.manifest" name="-do-dist-with-manifest"> + <dirname file="${dist.war}" property="dist.jar.dir"/> + <mkdir dir="${dist.jar.dir}"/> + <jar compress="${jar.compress}" jarfile="${dist.war}" manifest="${build.meta.inf.dir}/MANIFEST.MF"> + <fileset dir="${build.web.dir}" excludes="WEB-INF/classes/.netbeans_*"/> + </jar> + </target> + <target depends="init,compile,compile-jsps,-pre-dist" if="do.tmp.war.package.without.custom.manifest" name="-do-tmp-dist-without-manifest"> + <dirname file="${dist.war}" property="dist.jar.dir"/> + <mkdir dir="${dist.jar.dir}"/> + <jar compress="${jar.compress}" jarfile="${dist.war}"> + <fileset dir="${build.web.dir}" excludes="WEB-INF/classes/.netbeans_*"/> + </jar> + </target> + <target depends="init,compile,compile-jsps,-pre-dist" if="do.tmp.war.package.with.custom.manifest" name="-do-tmp-dist-with-manifest"> + <dirname file="${dist.war}" property="dist.jar.dir"/> + <mkdir dir="${dist.jar.dir}"/> + <jar compress="${jar.compress}" jarfile="${dist.war}" manifest="${build.meta.inf.dir}/MANIFEST.MF"> + <fileset dir="${build.web.dir}" excludes="WEB-INF/classes/.netbeans_*"/> + </jar> + </target> + <target depends="init,compile,compile-jsps,-pre-dist,-do-dist-with-manifest,-do-dist-without-manifest" name="do-dist"/> + <target depends="init" if="dist.ear.dir" name="library-inclusion-in-manifest"> + <copyfiles files="${libs.MySQLDriver.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> + <copyfiles files="${libs.metro.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> + <copyfiles files="${libs.restapi.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> + <mkdir dir="${build.web.dir}/META-INF"/> + <manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/> + </target> + <target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir"> + <copyfiles files="${libs.MySQLDriver.classpath}" todir="${build.web.dir}/WEB-INF/lib"/> + <copyfiles files="${libs.metro.classpath}" todir="${build.web.dir}/WEB-INF/lib"/> + <copyfiles files="${libs.restapi.classpath}" todir="${build.web.dir}/WEB-INF/lib"/> + </target> + <target depends="init" if="dist.ear.dir" name="-clean-webinf-lib"> + <delete dir="${build.web.dir}/WEB-INF/lib"/> + </target> + <target depends="init,-clean-webinf-lib,compile,compile-jsps,-pre-dist,library-inclusion-in-manifest" if="do.tmp.war.package" name="do-ear-dist"> + <dirname file="${dist.ear.war}" property="dist.jar.dir"/> + <mkdir dir="${dist.jar.dir}"/> + <jar compress="${jar.compress}" jarfile="${dist.ear.war}" manifest="${build.web.dir}/META-INF/MANIFEST.MF"> + <fileset dir="${build.web.dir}" excludes="WEB-INF/classes/.netbeans_*"/> + </jar> + </target> + <target name="-post-dist"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-dist,do-dist,-post-dist" description="Build distribution (WAR)." name="dist"/> + <target depends="init,-clean-webinf-lib,-init-cos,compile,-pre-dist,do-ear-dist,-post-dist" description="Build distribution (WAR) to be packaged into an EAR." name="dist-ear"/> + <!-- + EXECUTION SECTION + --> + <target depends="run-deploy,run-display-browser" description="Deploy to server and show in browser." name="run"/> + <target name="-pre-run-deploy"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target name="-post-run-deploy"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target name="-pre-nbmodule-run-deploy"> + <!-- Empty placeholder for easier customization. --> + <!-- This target can be overriden by NetBeans modules. Don't override it directly, use -pre-run-deploy task instead. --> + </target> + <target name="-post-nbmodule-run-deploy"> + <!-- Empty placeholder for easier customization. --> + <!-- This target can be overriden by NetBeans modules. Don't override it directly, use -post-run-deploy task instead. --> + </target> + <target name="-run-deploy-am"> + <!-- Task to deploy to the Access Manager runtime. --> + </target> + <target depends="init,-init-cos,compile,compile-jsps,-do-compile-single-jsp,-pre-dist,-do-tmp-dist-with-manifest,-do-tmp-dist-without-manifest,-pre-run-deploy,-pre-nbmodule-run-deploy,-run-deploy-nb,-init-deploy-ant,-deploy-ant,-run-deploy-am,-post-nbmodule-run-deploy,-post-run-deploy,-do-update-breakpoints" name="run-deploy"/> + <target if="netbeans.home" name="-run-deploy-nb"> + <nbdeploy clientUrlPart="${client.urlPart}" debugmode="false" forceRedeploy="${forceRedeploy}"/> + </target> + <target name="-init-deploy-ant" unless="netbeans.home"> + <property name="deploy.ant.archive" value="${dist.war}"/> + <property name="deploy.ant.docbase.dir" value="${web.docbase.dir}"/> + <property name="deploy.ant.resource.dir" value="${resource.dir}"/> + <property name="deploy.ant.enabled" value="true"/> + </target> + <target depends="dist,-run-undeploy-nb,-init-deploy-ant,-undeploy-ant" name="run-undeploy"/> + <target if="netbeans.home" name="-run-undeploy-nb"> + <fail message="Undeploy is not supported from within the IDE"/> + </target> + <target depends="init,-pre-dist,dist,-post-dist" name="verify"> + <nbverify file="${dist.war}"/> + </target> + <target depends="run-deploy,-init-display-browser,-display-browser-nb,-display-browser-cl" name="run-display-browser"/> + <target if="do.display.browser" name="-init-display-browser"> + <condition property="do.display.browser.nb"> + <isset property="netbeans.home"/> + </condition> + <condition property="do.display.browser.cl"> + <isset property="deploy.ant.enabled"/> + </condition> + </target> + <target if="do.display.browser.nb" name="-display-browser-nb"> + <nbbrowse url="${client.url}"/> + </target> + <target if="do.display.browser.cl" name="-get-browser" unless="browser"> + <condition property="browser" value="rundll32"> + <os family="windows"/> + </condition> + <condition else="" property="browser.args" value="url.dll,FileProtocolHandler"> + <os family="windows"/> + </condition> + <condition property="browser" value="/usr/bin/open"> + <os family="mac"/> + </condition> + <property environment="env"/> + <condition property="browser" value="${env.BROWSER}"> + <isset property="env.BROWSER"/> + </condition> + <condition property="browser" value="/usr/bin/firefox"> + <available file="/usr/bin/firefox"/> + </condition> + <condition property="browser" value="/usr/local/firefox/firefox"> + <available file="/usr/local/firefox/firefox"/> + </condition> + <condition property="browser" value="/usr/bin/mozilla"> + <available file="/usr/bin/mozilla"/> + </condition> + <condition property="browser" value="/usr/local/mozilla/mozilla"> + <available file="/usr/local/mozilla/mozilla"/> + </condition> + <condition property="browser" value="/usr/sfw/lib/firefox/firefox"> + <available file="/usr/sfw/lib/firefox/firefox"/> + </condition> + <condition property="browser" value="/opt/csw/bin/firefox"> + <available file="/opt/csw/bin/firefox"/> + </condition> + <condition property="browser" value="/usr/sfw/lib/mozilla/mozilla"> + <available file="/usr/sfw/lib/mozilla/mozilla"/> + </condition> + <condition property="browser" value="/opt/csw/bin/mozilla"> + <available file="/opt/csw/bin/mozilla"/> + </condition> + </target> + <target depends="-get-browser" if="do.display.browser.cl" name="-display-browser-cl"> + <fail unless="browser"> + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + </fail> + <property name="browse.url" value="${deploy.ant.client.url}${client.urlPart}"/> + <echo>Launching ${browse.url}</echo> + <exec executable="${browser}" spawn="true"> + <arg line="${browser.args} ${browse.url}"/> + </exec> + </target> + <target depends="init,-init-cos,compile-single" name="run-main"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <webproject1:java classname="${run.class}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single" name="run-test-with-main"> + <fail unless="run.class">Must select one file in the IDE or set run.class</fail> + <webproject1:java classname="${run.class}" classpath="${run.test.classpath}"/> + </target> + <target depends="init" if="netbeans.home" name="-do-update-breakpoints"> + <webproject1:nbjpdaappreloaded/> + </target> + <!-- + DEBUGGING SECTION + --> + <target depends="init,-init-cos,compile,compile-jsps,-do-compile-single-jsp,-pre-dist,-do-tmp-dist-with-manifest,-do-tmp-dist-without-manifest" description="Debug project in IDE." if="netbeans.home" name="debug"> + <nbstartserver debugmode="true"/> + <antcall target="connect-debugger"/> + <nbdeploy clientUrlPart="${client.urlPart}" debugmode="true" forceRedeploy="true"/> + <antcall target="debug-display-browser"/> + <antcall target="connect-client-debugger"/> + </target> + <target if="do.debug.server" name="connect-debugger" unless="is.debugged"> + <condition property="listeningcp" value="sourcepath"> + <istrue value="${j2ee.compile.on.save}"/> + </condition> + <nbjpdaconnect address="${jpda.address}" host="${jpda.host}" listeningcp="${listeningcp}" name="${name}" transport="${jpda.transport}"> + <classpath> + <path path="${debug.classpath}:${j2ee.platform.classpath}"/> + </classpath> + <sourcepath> + <path path="${web.docbase.dir}"/> + </sourcepath> + </nbjpdaconnect> + </target> + <target if="do.display.browser.debug" name="debug-display-browser"> + <nbbrowse url="${client.url}"/> + </target> + <target if="do.debug.client" name="connect-client-debugger"> + <webproject1:nbjsdebugstart webUrl="${client.url}"/> + </target> + <target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test"> + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail> + <webproject1:debug classname="${debug.class}" classpath="${debug.test.classpath}"/> + </target> + <target depends="init,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/> + <target depends="init,compile,compile-jsps,-do-compile-single-jsp,debug" if="netbeans.home" name="debug-single"/> + <target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test"> + <webproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/> + </target> + <target depends="init" if="netbeans.home" name="-debug-start-debugger"> + <webproject1:nbjpdastart name="${debug.class}"/> + </target> + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single"> + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail> + <webproject1:debug classname="${debug.class}"/> + </target> + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single-main"/> + <target depends="init" name="-pre-debug-fix"> + <fail unless="fix.includes">Must set fix.includes</fail> + <property name="javac.includes" value="${fix.includes}.java"/> + </target> + <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix"> + <webproject1:nbjpdareload/> + </target> + <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/> + <!-- + ================= + PROFILING SECTION + ================= + --> + <!-- + pre NB7.2 profiling section; consider it deprecated + --> + <target description="Profile a J2EE project in the IDE." if="profiler.info.jvmargs.agent" name="-profile-pre72"> + <condition else="start-profiled-server" property="profiler.startserver.target" value="start-profiled-server-extraargs"> + <isset property="profiler.info.jvmargs.extra"/> + </condition> + <antcall target="${profiler.startserver.target}"/> + <antcall target="run"/> + <antcall target="-profile-start-loadgen"/> + </target> + <target if="profiler.info.jvmargs.agent" name="start-profiled-server"> + <nbstartprofiledserver forceRestart="${profiler.j2ee.serverForceRestart}" javaPlatform="${profiler.info.javaPlatform}" startupTimeout="${profiler.j2ee.serverStartupTimeout}"> + <jvmarg value="${profiler.info.jvmargs.agent}"/> + <jvmarg value="${profiler.j2ee.agentID}"/> + </nbstartprofiledserver> + </target> + <target if="profiler.info.jvmargs.agent" name="start-profiled-server-extraargs"> + <nbstartprofiledserver forceRestart="${profiler.j2ee.serverForceRestart}" javaPlatform="${profiler.info.javaPlatform}" startupTimeout="${profiler.j2ee.serverStartupTimeout}"> + <jvmarg value="${profiler.info.jvmargs.extra}"/> + <jvmarg value="${profiler.info.jvmargs.agent}"/> + <jvmarg value="${profiler.j2ee.agentID}"/> + </nbstartprofiledserver> + </target> + <target depends="profile-init,compile-test-single" if="profiler.info.jvmargs.agent" name="-profile-test-single-pre72"> + <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail> + <nbprofiledirect> + <classpath> + <path path="${run.test.classpath}"/> + <path path="${j2ee.platform.classpath}"/> + </classpath> + </nbprofiledirect> + <junit dir="${profiler.info.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" jvm="${profiler.info.jvm}" showoutput="true"> + <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/> + <jvmarg value="${profiler.info.jvmargs.agent}"/> + <jvmarg line="${profiler.info.jvmargs}"/> + <test name="${profile.class}"/> + <classpath> + <path path="${run.test.classpath}"/> + <path path="${j2ee.platform.classpath}"/> + </classpath> + <syspropertyset> + <propertyref prefix="test-sys-prop."/> + <mapper from="test-sys-prop.*" to="*" type="glob"/> + </syspropertyset> + <formatter type="brief" usefile="false"/> + <formatter type="xml"/> + </junit> + </target> + <target if="netbeans.home" name="-profile-check"> + <condition property="profiler.configured"> + <or> + <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-agentpath:"/> + <contains casesensitive="true" string="${run.jvmargs.ide}" substring="-javaagent:"/> + </or> + </condition> + </target> + <target depends="init,-init-cos,compile,compile-jsps,-do-compile-single-jsp,-pre-dist,-do-tmp-dist-with-manifest,-do-tmp-dist-without-manifest" name="-do-profile"> + <startprofiler/> + <nbstartserver profilemode="true"/> + <nbdeploy clientUrlPart="${client.urlPart}" forceRedeploy="true" profilemode="true"/> + <antcall target="debug-display-browser"/> + <antcall target="-profile-start-loadgen"/> + </target> + <target depends="-profile-check,-profile-pre72" description="Profile a J2EE project in the IDE." if="profiler.configured" name="profile" unless="profiler.info.jvmargs.agent"> + <antcall target="-do-profile"/> + </target> + <target depends="-profile-test-single-pre72" name="profile-test-single"/> + <target depends="-profile-check" if="profiler.configured" name="profile-test" unless="profiler.info.jvmargs.agent"> + <startprofiler/> + <antcall target="test-single"/> + </target> + <target if="profiler.loadgen.path" name="-profile-start-loadgen"> + <loadgenstart path="${profiler.loadgen.path}"/> + </target> + <!-- + JAVADOC SECTION + --> + <target depends="init" if="have.sources" name="javadoc-build"> + <mkdir dir="${dist.javadoc.dir}"/> + <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}"> + <classpath> + <path path="${javac.classpath}:${j2ee.platform.classpath}"/> + </classpath> + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}"> + <filename name="**/*.java"/> + </fileset> + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false"> + <include name="**/*.java"/> + </fileset> + </javadoc> + <copy todir="${dist.javadoc.dir}"> + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}"> + <filename name="**/doc-files/**"/> + </fileset> + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false"> + <include name="**/doc-files/**"/> + </fileset> + </copy> + </target> + <target depends="init,javadoc-build" if="netbeans.home" name="javadoc-browse" unless="no.javadoc.preview"> + <nbbrowse file="${dist.javadoc.dir}/index.html"/> + </target> + <target depends="init,javadoc-build,javadoc-browse" description="Build Javadoc." name="javadoc"/> + <!-- + + TEST COMPILATION SECTION + --> + <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test"> + <mkdir dir="${build.test.classes.dir}"/> + <property name="j2ee.platform.embeddableejb.classpath" value=""/> + </target> + <target name="-pre-compile-test"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test" if="have.tests" name="-do-compile-test"> + <webproject2:javac classpath="${javac.test.classpath}:${j2ee.platform.classpath}:${j2ee.platform.embeddableejb.classpath}" debug="true" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/> + <copy todir="${build.test.classes.dir}"> + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target name="-post-compile-test"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/> + <target name="-pre-compile-test-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single"> + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail> + <webproject2:javac classpath="${javac.test.classpath}:${j2ee.platform.classpath}:${j2ee.platform.embeddableejb.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" srcdir="${test.src.dir}"/> + <copy todir="${build.test.classes.dir}"> + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/> + </copy> + </target> + <target name="-post-compile-test-single"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/> + <!-- + + TEST EXECUTION SECTION + --> + <target depends="init" if="have.tests" name="-pre-test-run"> + <mkdir dir="${build.test.results.dir}"/> + </target> + <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run"> + <webproject2:test testincludes="**/*Test.java"/> + </target> + <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run"> + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> + </target> + <target depends="init" if="have.tests" name="test-report"/> + <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/> + <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/> + <target depends="init" if="have.tests" name="-pre-test-run-single"> + <mkdir dir="${build.test.results.dir}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single"> + <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail> + <webproject2:test excludes="" includes="${test.includes}" testincludes="${test.includes}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single"> + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single-method"> + <fail unless="test.class">Must select some files in the IDE or set test.class</fail> + <fail unless="test.method">Must select some method in the IDE or set test.method</fail> + <webproject2:test excludes="" includes="${javac.includes}" testincludes="${test.class}" testmethods="${test.method}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single-method" if="have.tests" name="-post-test-run-single-method"> + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail> + </target> + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single-method,-post-test-run-single-method" description="Run single unit test." name="test-single-method"/> + <!-- + + TEST DEBUGGING SECTION + --> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test"> + <fail unless="test.class">Must select one file in the IDE or set test.class</fail> + <webproject2:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testincludes="${javac.includes}"/> + </target> + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-debug-start-debuggee-test-method"> + <fail unless="test.class">Must select one file in the IDE or set test.class</fail> + <fail unless="test.method">Must select some method in the IDE or set test.method</fail> + <webproject2:test-debug excludes="" includes="${javac.includes}" testClass="${test.class}" testMethod="${test.method}" testincludes="${test.class}" testmethods="${test.method}"/> + </target> + <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test"> + <webproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/> + </target> + <target depends="init,compile-test,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/> + <target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test-method" name="debug-test-method"/> + <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test"> + <webproject1:nbjpdareload dir="${build.test.classes.dir}"/> + </target> + <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/> + <!-- + + CLEANUP SECTION + --> + <target depends="init" name="deps-clean" unless="no.deps"/> + <target depends="init" name="do-clean"> + <condition property="build.dir.to.clean" value="${build.web.dir}"> + <isset property="dist.ear.dir"/> + </condition> + <property name="build.dir.to.clean" value="${build.web.dir}"/> + <delete includeEmptyDirs="true" quiet="true"> + <fileset dir="${build.dir.to.clean}/WEB-INF/lib"/> + </delete> + <delete dir="${build.dir}"/> + <available file="${build.dir.to.clean}/WEB-INF/lib" property="status.clean-failed" type="dir"/> + <delete dir="${dist.dir}"/> + </target> + <target depends="do-clean" if="status.clean-failed" name="check-clean"> + <echo message="Warning: unable to delete some files in ${build.web.dir}/WEB-INF/lib - they are probably locked by the J2EE server. "/> + <echo level="info" message="To delete all files undeploy the module from Server Registry in Runtime tab and then use Clean again."/> + </target> + <target depends="init" if="netbeans.home" name="undeploy-clean"> + <nbundeploy failOnError="false" startServer="false"/> + </target> + <target name="-post-clean"> + <!-- Empty placeholder for easier customization. --> + <!-- You can override this target in the ../build.xml file. --> + </target> + <target depends="init,undeploy-clean,deps-clean,do-clean,check-clean,-post-clean" description="Clean build products." name="clean"/> + <target depends="clean" description="Clean build products." name="clean-ear"/> +</project> diff --git a/eurilys4-service/nbproject/genfiles.properties b/eurilys4-service/nbproject/genfiles.properties new file mode 100644 index 00000000..d80c29c0 --- /dev/null +++ b/eurilys4-service/nbproject/genfiles.properties @@ -0,0 +1,12 @@ +build.xml.data.CRC32=559f4779 +build.xml.script.CRC32=bd028cce +build.xml.stylesheet.CRC32=651128d4@1.41.1.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=559f4779 +nbproject/build-impl.xml.script.CRC32=4a61ffc0 +nbproject/build-impl.xml.stylesheet.CRC32=5459df51@1.41.1.1 +nbproject/rest-build.xml.data.CRC32=951a3912 +nbproject/rest-build.xml.script.CRC32=139c8b19 +nbproject/rest-build.xml.stylesheet.CRC32=5f13befe@1.14.2 +nbproject/jaxws-build.xml.stylesheet.CRC32=bba84283 diff --git a/eurilys4-service/nbproject/jax-ws.xml b/eurilys4-service/nbproject/jax-ws.xml new file mode 100644 index 00000000..dd483086 --- /dev/null +++ b/eurilys4-service/nbproject/jax-ws.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<jax-ws xmlns="http://www.netbeans.org/ns/jax-ws/1"> + <services> + </services> + <clients/> + <jsr109>false</jsr109> +</jax-ws> diff --git a/eurilys4-service/nbproject/jaxws-build.xml b/eurilys4-service/nbproject/jaxws-build.xml new file mode 100644 index 00000000..0267e77f --- /dev/null +++ b/eurilys4-service/nbproject/jaxws-build.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *** GENERATED FROM jax-ws.xml - DO NOT EDIT ! *** + *** TO MODIFY wsimport options USE Web Service node -> Edit WS Attributes *** + *** TO CHANGE TARGETS GENERATED TO jaxws-build.xml COPY THOSE *** + *** TARGETS TO ../build.xml AND MODIFY THAT FILE INSTEAD *** + + --> +<project xmlns:xalan="http://xml.apache.org/xslt" xmlns:webproject2="http://www.netbeans.org/ns/web-project/2" xmlns:jaxws="http://www.netbeans.org/ns/jax-ws/1"> + <!-- + =================== + JAX-WS WSGEN SECTION + =================== + --> + <!-- + =================== + JAX-WS WSIMPORT SECTION + =================== + --> +</project> diff --git a/eurilys4-service/nbproject/private/private.properties b/eurilys4-service/nbproject/private/private.properties new file mode 100644 index 00000000..e9983201 --- /dev/null +++ b/eurilys4-service/nbproject/private/private.properties @@ -0,0 +1,17 @@ +<<<<<<< HEAD +deploy.ant.properties.file=/Users/kaniaazrina/Library/Application Support/NetBeans/7.3/tomcat70.properties +j2ee.platform.is.jsr109=true +j2ee.server.domain=/Applications/NetBeans/glassfish-3.1.2.2/glassfish/domains/domain1 +j2ee.server.home=C:/Program Files/Apache Software Foundation/Apache Tomcat 7.0.27 +j2ee.server.instance=tomcat70:home=/Applications/NetBeans/apache-tomcat-7.0.39 +j2ee.server.middleware=/Applications/NetBeans/glassfish-3.1.2.2 +javac.debug=true +javadoc.preview=true +user.properties.file=/Users/kaniaazrina/Library/Application Support/NetBeans/7.3/build.properties +======= +deploy.ant.properties.file=C:\\Users\\Sharon\\AppData\\Roaming\\NetBeans\\7.2.1\\tomcat70.properties +j2ee.server.domain=C:/Users/Sharon/AppData/Roaming/NetBeans/7.2.1/apache-tomcat-7.0.27.0_base +j2ee.server.home=C:/Program Files/Apache Software Foundation/Apache Tomcat 7.0.27 +j2ee.server.instance=tomcat70:home=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 7.0.27:base=apache-tomcat-7.0.27.0_base +user.properties.file=C:\\Users\\Sharon\\AppData\\Roaming\\NetBeans\\7.2.1\\build.properties +>>>>>>> revisi edit profile diff --git a/eurilys4-service/nbproject/private/private.xml b/eurilys4-service/nbproject/private/private.xml new file mode 100644 index 00000000..47509625 --- /dev/null +++ b/eurilys4-service/nbproject/private/private.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> + <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> +</project-private> diff --git a/eurilys4-service/nbproject/project.properties b/eurilys4-service/nbproject/project.properties new file mode 100644 index 00000000..5b4d5650 --- /dev/null +++ b/eurilys4-service/nbproject/project.properties @@ -0,0 +1,86 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +auxiliary.org-netbeans-modules-html-editor-lib.default-html-public-id=HTML5 +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +dist.dir=dist +dist.ear.war=${dist.dir}/${war.ear.name} +dist.javadoc.dir=${dist.dir}/javadoc +dist.war=${dist.dir}/${war.name} +endorsed.classpath=\ + ${libs.javaee-endorsed-api-6.0.classpath} +excludes= +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.6-web +j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-3.7.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-util.jar +j2ee.server.type=Tomcat +jar.compress=false +javac.classpath=\ + ${libs.MySQLDriver.classpath}:\ + ${libs.metro.classpath}:\ + ${libs.restapi.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +rest.config.type=ide +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=eurilys4-service.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/eurilys4-service/nbproject/project.xml b/eurilys4-service/nbproject/project.xml new file mode 100644 index 00000000..10a8bdf6 --- /dev/null +++ b/eurilys4-service/nbproject/project.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.web.project</type> + <configuration> + <buildExtensions xmlns="http://www.netbeans.org/ns/ant-build-extender/1"> + <extension file="rest-build.xml" id="rest.4"> + <dependency dependsOn="generate-rest-config" target="-pre-pre-compile"/> + </extension> + </buildExtensions> + <data xmlns="http://www.netbeans.org/ns/web-project/3"> + <name>eurilys4-service</name> + <minimum-ant-version>1.6.5</minimum-ant-version> + <web-module-libraries> + <library dirs="200"> + <file>${libs.MySQLDriver.classpath}</file> + <path-in-war>WEB-INF/lib</path-in-war> + </library> + <library dirs="200"> + <file>${libs.metro.classpath}</file> + <path-in-war>WEB-INF/lib</path-in-war> + </library> + <library dirs="200"> + <file>${libs.restapi.classpath}</file> + <path-in-war>WEB-INF/lib</path-in-war> + </library> + </web-module-libraries> + <web-module-additional-libraries/> + <source-roots> + <root id="src.dir"/> + </source-roots> + <test-roots> + <root id="test.src.dir"/> + </test-roots> + </data> + </configuration> +</project> diff --git a/eurilys4-service/nbproject/rest-build.xml b/eurilys4-service/nbproject/rest-build.xml new file mode 100644 index 00000000..930d7a69 --- /dev/null +++ b/eurilys4-service/nbproject/rest-build.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *** GENERATED - DO NOT EDIT *** + --> +<project name="eurilys4-rest-build" basedir=".." xmlns:webproject3="http://www.netbeans.org/ns/web-project/3" xmlns:webproject2="http://www.netbeans.org/ns/web-project/2" xmlns:webproject1="http://www.netbeans.org/ns/web-project/1" xmlns:jaxrs="http://www.netbeans.org/ns/jax-rs/1"> + <target name="-check-trim"> + <condition property="do.trim"> + <and> + <isset property="client.urlPart"/> + <length string="${client.urlPart}" when="greater" length="0"/> + </and> + </condition> + </target> + <target name="-trim-url" if="do.trim"> + <pathconvert pathsep="/" property="rest.base.url"> + <propertyset> + <propertyref name="client.url"/> + </propertyset> + <globmapper from="*${client.urlPart}" to="*/"/> + </pathconvert> + </target> + <target name="-spare-url" unless="do.trim"> + <property name="rest.base.url" value="${client.url}"/> + </target> + <target name="test-restbeans" depends="run-deploy,-init-display-browser,-check-trim,-trim-url,-spare-url"> + <replace file="${restbeans.test.file}" token="${base.url.token}" value="${rest.base.url}||${rest.application.path}"/> + <condition property="do.browse-url"> + <istrue value="${display.browser}"/> + </condition> + <antcall target="browse-url"/> + </target> + <target name="browse-url" if="do.browse-url"> + <nbbrowse url="${restbeans.test.url}"/> + </target> + <target name="check-rest-config-props" depends="-do-init"> + <condition property="do-generate-rest-config"> + <and> + <equals arg1="${rest.config.type}" arg2="ide"/> + <isset property="rest.resources.path"/> + </and> + </condition> + </target> + <target name="generate-rest-config" depends="check-rest-config-props" if="do-generate-rest-config"> + <mkdir dir="${build.generated.sources.dir}/rest/org/netbeans/rest/application/config/"/> + <echo file="${build.generated.sources.dir}/rest/org/netbeans/rest/application/config/ApplicationConfig.java">/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.netbeans.rest.application.config; +/** + * This class is generated by the NetBeans IDE, + * and registers all REST root resources created in the project. + * Please, DO NOT EDIT this class unless you really need and + * understand the results of changes. + * It is safe to change REST resources path value of + * ApplicationPath annotation. It can be done also via UI action + * called on RESTful Web Services node ( REST Resources Configuration dialog ). + * + */ +@javax.ws.rs.ApplicationPath("${rest.resources.path}") +public class ApplicationConfig extends javax.ws.rs.core.Application { +}</echo> + </target> +</project> diff --git a/eurilys4-service/src/conf/MANIFEST.MF b/eurilys4-service/src/conf/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/eurilys4-service/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/eurilys4-service/src/java/jsonlib/CDL.java b/eurilys4-service/src/java/jsonlib/CDL.java new file mode 100644 index 00000000..0fc3cf82 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/CDL.java @@ -0,0 +1,279 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * This provides static methods to convert comma delimited text into a + * JSONArray, and to covert a JSONArray into comma delimited text. Comma + * delimited text is a very popular format for data interchange. It is + * understood by most database, spreadsheet, and organizer programs. + * <p> + * Each row of text represents a row in a table or a data record. Each row + * ends with a NEWLINE character. Each row contains one or more values. + * Values are separated by commas. A value can contain any character except + * for comma, unless is is wrapped in single quotes or double quotes. + * <p> + * The first row usually contains the names of the columns. + * <p> + * A comma delimited list can be converted into a JSONArray of JSONObjects. + * The names for the elements in the JSONObjects can be taken from the names + * in the first row. + * @author JSON.org + * @version 2012-11-13 + */ +public class CDL { + + /** + * Get the next value. The value can be wrapped in quotes. The value can + * be empty. + * @param x A JSONTokener of the source text. + * @return The value string, or null if empty. + * @throws JSONException if the quoted string is badly formed. + */ + private static String getValue(JSONTokener x) throws JSONException { + char c; + char q; + StringBuffer sb; + do { + c = x.next(); + } while (c == ' ' || c == '\t'); + switch (c) { + case 0: + return null; + case '"': + case '\'': + q = c; + sb = new StringBuffer(); + for (;;) { + c = x.next(); + if (c == q) { + break; + } + if (c == 0 || c == '\n' || c == '\r') { + throw x.syntaxError("Missing close quote '" + q + "'."); + } + sb.append(c); + } + return sb.toString(); + case ',': + x.back(); + return ""; + default: + x.back(); + return x.nextTo(','); + } + } + + /** + * Produce a JSONArray of strings from a row of comma delimited values. + * @param x A JSONTokener of the source text. + * @return A JSONArray of strings. + * @throws JSONException + */ + public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException { + JSONArray ja = new JSONArray(); + for (;;) { + String value = getValue(x); + char c = x.next(); + if (value == null || + (ja.length() == 0 && value.length() == 0 && c != ',')) { + return null; + } + ja.put(value); + for (;;) { + if (c == ',') { + break; + } + if (c != ' ') { + if (c == '\n' || c == '\r' || c == 0) { + return ja; + } + throw x.syntaxError("Bad character '" + c + "' (" + + (int)c + ")."); + } + c = x.next(); + } + } + } + + /** + * Produce a JSONObject from a row of comma delimited text, using a + * parallel JSONArray of strings to provides the names of the elements. + * @param names A JSONArray of names. This is commonly obtained from the + * first row of a comma delimited text file using the rowToJSONArray + * method. + * @param x A JSONTokener of the source text. + * @return A JSONObject combining the names and values. + * @throws JSONException + */ + public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x) + throws JSONException { + JSONArray ja = rowToJSONArray(x); + return ja != null ? ja.toJSONObject(names) : null; + } + + /** + * Produce a comma delimited text row from a JSONArray. Values containing + * the comma character will be quoted. Troublesome characters may be + * removed. + * @param ja A JSONArray of strings. + * @return A string ending in NEWLINE. + */ + public static String rowToString(JSONArray ja) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < ja.length(); i += 1) { + if (i > 0) { + sb.append(','); + } + Object object = ja.opt(i); + if (object != null) { + String string = object.toString(); + if (string.length() > 0 && (string.indexOf(',') >= 0 || + string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 || + string.indexOf(0) >= 0 || string.charAt(0) == '"')) { + sb.append('"'); + int length = string.length(); + for (int j = 0; j < length; j += 1) { + char c = string.charAt(j); + if (c >= ' ' && c != '"') { + sb.append(c); + } + } + sb.append('"'); + } else { + sb.append(string); + } + } + } + sb.append('\n'); + return sb.toString(); + } + + /** + * Produce a JSONArray of JSONObjects from a comma delimited text string, + * using the first row as a source of names. + * @param string The comma delimited text. + * @return A JSONArray of JSONObjects. + * @throws JSONException + */ + public static JSONArray toJSONArray(String string) throws JSONException { + return toJSONArray(new JSONTokener(string)); + } + + /** + * Produce a JSONArray of JSONObjects from a comma delimited text string, + * using the first row as a source of names. + * @param x The JSONTokener containing the comma delimited text. + * @return A JSONArray of JSONObjects. + * @throws JSONException + */ + public static JSONArray toJSONArray(JSONTokener x) throws JSONException { + return toJSONArray(rowToJSONArray(x), x); + } + + /** + * Produce a JSONArray of JSONObjects from a comma delimited text string + * using a supplied JSONArray as the source of element names. + * @param names A JSONArray of strings. + * @param string The comma delimited text. + * @return A JSONArray of JSONObjects. + * @throws JSONException + */ + public static JSONArray toJSONArray(JSONArray names, String string) + throws JSONException { + return toJSONArray(names, new JSONTokener(string)); + } + + /** + * Produce a JSONArray of JSONObjects from a comma delimited text string + * using a supplied JSONArray as the source of element names. + * @param names A JSONArray of strings. + * @param x A JSONTokener of the source text. + * @return A JSONArray of JSONObjects. + * @throws JSONException + */ + public static JSONArray toJSONArray(JSONArray names, JSONTokener x) + throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + JSONArray ja = new JSONArray(); + for (;;) { + JSONObject jo = rowToJSONObject(names, x); + if (jo == null) { + break; + } + ja.put(jo); + } + if (ja.length() == 0) { + return null; + } + return ja; + } + + + /** + * Produce a comma delimited text from a JSONArray of JSONObjects. The + * first row will be a list of names obtained by inspecting the first + * JSONObject. + * @param ja A JSONArray of JSONObjects. + * @return A comma delimited text. + * @throws JSONException + */ + public static String toString(JSONArray ja) throws JSONException { + JSONObject jo = ja.optJSONObject(0); + if (jo != null) { + JSONArray names = jo.names(); + if (names != null) { + return rowToString(names) + toString(names, ja); + } + } + return null; + } + + /** + * Produce a comma delimited text from a JSONArray of JSONObjects using + * a provided list of names. The list of names is not included in the + * output. + * @param names A JSONArray of strings. + * @param ja A JSONArray of JSONObjects. + * @return A comma delimited text. + * @throws JSONException + */ + public static String toString(JSONArray names, JSONArray ja) + throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < ja.length(); i += 1) { + JSONObject jo = ja.optJSONObject(i); + if (jo != null) { + sb.append(rowToString(jo.toJSONArray(names))); + } + } + return sb.toString(); + } +} diff --git a/eurilys4-service/src/java/jsonlib/Cookie.java b/eurilys4-service/src/java/jsonlib/Cookie.java new file mode 100644 index 00000000..a2d9c4ed --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/Cookie.java @@ -0,0 +1,169 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * Convert a web browser cookie specification to a JSONObject and back. + * JSON and Cookies are both notations for name/value pairs. + * @author JSON.org + * @version 2010-12-24 + */ +public class Cookie { + + /** + * Produce a copy of a string in which the characters '+', '%', '=', ';' + * and control characters are replaced with "%hh". This is a gentle form + * of URL encoding, attempting to cause as little distortion to the + * string as possible. The characters '=' and ';' are meta characters in + * cookies. By convention, they are escaped using the URL-encoding. This is + * only a convention, not a standard. Often, cookies are expected to have + * encoded values. We encode '=' and ';' because we must. We encode '%' and + * '+' because they are meta characters in URL encoding. + * @param string The source string. + * @return The escaped result. + */ + public static String escape(String string) { + char c; + String s = string.trim(); + StringBuffer sb = new StringBuffer(); + int length = s.length(); + for (int i = 0; i < length; i += 1) { + c = s.charAt(i); + if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') { + sb.append('%'); + sb.append(Character.forDigit((char)((c >>> 4) & 0x0f), 16)); + sb.append(Character.forDigit((char)(c & 0x0f), 16)); + } else { + sb.append(c); + } + } + return sb.toString(); + } + + + /** + * Convert a cookie specification string into a JSONObject. The string + * will contain a name value pair separated by '='. The name and the value + * will be unescaped, possibly converting '+' and '%' sequences. The + * cookie properties may follow, separated by ';', also represented as + * name=value (except the secure property, which does not have a value). + * The name will be stored under the key "name", and the value will be + * stored under the key "value". This method does not do checking or + * validation of the parameters. It only converts the cookie string into + * a JSONObject. + * @param string The cookie specification string. + * @return A JSONObject containing "name", "value", and possibly other + * members. + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + String name; + JSONObject jo = new JSONObject(); + Object value; + JSONTokener x = new JSONTokener(string); + jo.put("name", x.nextTo('=')); + x.next('='); + jo.put("value", x.nextTo(';')); + x.next(); + while (x.more()) { + name = unescape(x.nextTo("=;")); + if (x.next() != '=') { + if (name.equals("secure")) { + value = Boolean.TRUE; + } else { + throw x.syntaxError("Missing '=' in cookie parameter."); + } + } else { + value = unescape(x.nextTo(';')); + x.next(); + } + jo.put(name, value); + } + return jo; + } + + + /** + * Convert a JSONObject into a cookie specification string. The JSONObject + * must contain "name" and "value" members. + * If the JSONObject contains "expires", "domain", "path", or "secure" + * members, they will be appended to the cookie specification string. + * All other members are ignored. + * @param jo A JSONObject + * @return A cookie specification string + * @throws JSONException + */ + public static String toString(JSONObject jo) throws JSONException { + StringBuffer sb = new StringBuffer(); + + sb.append(escape(jo.getString("name"))); + sb.append("="); + sb.append(escape(jo.getString("value"))); + if (jo.has("expires")) { + sb.append(";expires="); + sb.append(jo.getString("expires")); + } + if (jo.has("domain")) { + sb.append(";domain="); + sb.append(escape(jo.getString("domain"))); + } + if (jo.has("path")) { + sb.append(";path="); + sb.append(escape(jo.getString("path"))); + } + if (jo.optBoolean("secure")) { + sb.append(";secure"); + } + return sb.toString(); + } + + /** + * Convert <code>%</code><i>hh</i> sequences to single characters, and + * convert plus to space. + * @param string A string that may contain + * <code>+</code> <small>(plus)</small> and + * <code>%</code><i>hh</i> sequences. + * @return The unescaped string. + */ + public static String unescape(String string) { + int length = string.length(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < length; ++i) { + char c = string.charAt(i); + if (c == '+') { + c = ' '; + } else if (c == '%' && i + 2 < length) { + int d = JSONTokener.dehexchar(string.charAt(i + 1)); + int e = JSONTokener.dehexchar(string.charAt(i + 2)); + if (d >= 0 && e >= 0) { + c = (char)(d * 16 + e); + i += 2; + } + } + sb.append(c); + } + return sb.toString(); + } +} diff --git a/eurilys4-service/src/java/jsonlib/CookieList.java b/eurilys4-service/src/java/jsonlib/CookieList.java new file mode 100644 index 00000000..1111135f --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/CookieList.java @@ -0,0 +1,90 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.util.Iterator; + +/** + * Convert a web browser cookie list string to a JSONObject and back. + * @author JSON.org + * @version 2010-12-24 + */ +public class CookieList { + + /** + * Convert a cookie list into a JSONObject. A cookie list is a sequence + * of name/value pairs. The names are separated from the values by '='. + * The pairs are separated by ';'. The names and the values + * will be unescaped, possibly converting '+' and '%' sequences. + * + * To add a cookie to a cooklist, + * cookielistJSONObject.put(cookieJSONObject.getString("name"), + * cookieJSONObject.getString("value")); + * @param string A cookie list string + * @return A JSONObject + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + JSONObject jo = new JSONObject(); + JSONTokener x = new JSONTokener(string); + while (x.more()) { + String name = Cookie.unescape(x.nextTo('=')); + x.next('='); + jo.put(name, Cookie.unescape(x.nextTo(';'))); + x.next(); + } + return jo; + } + + + /** + * Convert a JSONObject into a cookie list. A cookie list is a sequence + * of name/value pairs. The names are separated from the values by '='. + * The pairs are separated by ';'. The characters '%', '+', '=', and ';' + * in the names and values are replaced by "%hh". + * @param jo A JSONObject + * @return A cookie list string + * @throws JSONException + */ + public static String toString(JSONObject jo) throws JSONException { + boolean b = false; + Iterator keys = jo.keys(); + String string; + StringBuffer sb = new StringBuffer(); + while (keys.hasNext()) { + string = keys.next().toString(); + if (!jo.isNull(string)) { + if (b) { + sb.append(';'); + } + sb.append(Cookie.escape(string)); + sb.append("="); + sb.append(Cookie.escape(jo.getString(string))); + b = true; + } + } + return sb.toString(); + } +} diff --git a/eurilys4-service/src/java/jsonlib/HTTP.java b/eurilys4-service/src/java/jsonlib/HTTP.java new file mode 100644 index 00000000..cc8203d1 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/HTTP.java @@ -0,0 +1,163 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.util.Iterator; + +/** + * Convert an HTTP header to a JSONObject and back. + * @author JSON.org + * @version 2010-12-24 + */ +public class HTTP { + + /** Carriage return/line feed. */ + public static final String CRLF = "\r\n"; + + /** + * Convert an HTTP header string into a JSONObject. It can be a request + * header or a response header. A request header will contain + * <pre>{ + * Method: "POST" (for example), + * "Request-URI": "/" (for example), + * "HTTP-Version": "HTTP/1.1" (for example) + * }</pre> + * A response header will contain + * <pre>{ + * "HTTP-Version": "HTTP/1.1" (for example), + * "Status-Code": "200" (for example), + * "Reason-Phrase": "OK" (for example) + * }</pre> + * In addition, the other parameters in the header will be captured, using + * the HTTP field names as JSON names, so that <pre> + * Date: Sun, 26 May 2002 18:06:04 GMT + * Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s + * Cache-Control: no-cache</pre> + * become + * <pre>{... + * Date: "Sun, 26 May 2002 18:06:04 GMT", + * Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s", + * "Cache-Control": "no-cache", + * ...}</pre> + * It does no further checking or conversion. It does not parse dates. + * It does not do '%' transforms on URLs. + * @param string An HTTP header string. + * @return A JSONObject containing the elements and attributes + * of the XML string. + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + JSONObject jo = new JSONObject(); + HTTPTokener x = new HTTPTokener(string); + String token; + + token = x.nextToken(); + if (token.toUpperCase().startsWith("HTTP")) { + +// Response + + jo.put("HTTP-Version", token); + jo.put("Status-Code", x.nextToken()); + jo.put("Reason-Phrase", x.nextTo('\0')); + x.next(); + + } else { + +// Request + + jo.put("Method", token); + jo.put("Request-URI", x.nextToken()); + jo.put("HTTP-Version", x.nextToken()); + } + +// Fields + + while (x.more()) { + String name = x.nextTo(':'); + x.next(':'); + jo.put(name, x.nextTo('\0')); + x.next(); + } + return jo; + } + + + /** + * Convert a JSONObject into an HTTP header. A request header must contain + * <pre>{ + * Method: "POST" (for example), + * "Request-URI": "/" (for example), + * "HTTP-Version": "HTTP/1.1" (for example) + * }</pre> + * A response header must contain + * <pre>{ + * "HTTP-Version": "HTTP/1.1" (for example), + * "Status-Code": "200" (for example), + * "Reason-Phrase": "OK" (for example) + * }</pre> + * Any other members of the JSONObject will be output as HTTP fields. + * The result will end with two CRLF pairs. + * @param jo A JSONObject + * @return An HTTP header string. + * @throws JSONException if the object does not contain enough + * information. + */ + public static String toString(JSONObject jo) throws JSONException { + Iterator keys = jo.keys(); + String string; + StringBuffer sb = new StringBuffer(); + if (jo.has("Status-Code") && jo.has("Reason-Phrase")) { + sb.append(jo.getString("HTTP-Version")); + sb.append(' '); + sb.append(jo.getString("Status-Code")); + sb.append(' '); + sb.append(jo.getString("Reason-Phrase")); + } else if (jo.has("Method") && jo.has("Request-URI")) { + sb.append(jo.getString("Method")); + sb.append(' '); + sb.append('"'); + sb.append(jo.getString("Request-URI")); + sb.append('"'); + sb.append(' '); + sb.append(jo.getString("HTTP-Version")); + } else { + throw new JSONException("Not enough material for an HTTP header."); + } + sb.append(CRLF); + while (keys.hasNext()) { + string = keys.next().toString(); + if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && + !"Reason-Phrase".equals(string) && !"Method".equals(string) && + !"Request-URI".equals(string) && !jo.isNull(string)) { + sb.append(string); + sb.append(": "); + sb.append(jo.getString(string)); + sb.append(CRLF); + } + } + sb.append(CRLF); + return sb.toString(); + } +} diff --git a/eurilys4-service/src/java/jsonlib/HTTPTokener.java b/eurilys4-service/src/java/jsonlib/HTTPTokener.java new file mode 100644 index 00000000..ed41744a --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/HTTPTokener.java @@ -0,0 +1,77 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * The HTTPTokener extends the JSONTokener to provide additional methods + * for the parsing of HTTP headers. + * @author JSON.org + * @version 2012-11-13 + */ +public class HTTPTokener extends JSONTokener { + + /** + * Construct an HTTPTokener from a string. + * @param string A source string. + */ + public HTTPTokener(String string) { + super(string); + } + + + /** + * Get the next token or string. This is used in parsing HTTP headers. + * @throws JSONException + * @return A String. + */ + public String nextToken() throws JSONException { + char c; + char q; + StringBuffer sb = new StringBuffer(); + do { + c = next(); + } while (Character.isWhitespace(c)); + if (c == '"' || c == '\'') { + q = c; + for (;;) { + c = next(); + if (c < ' ') { + throw syntaxError("Unterminated string."); + } + if (c == q) { + return sb.toString(); + } + sb.append(c); + } + } + for (;;) { + if (c == 0 || Character.isWhitespace(c)) { + return sb.toString(); + } + sb.append(c); + c = next(); + } + } +} diff --git a/eurilys4-service/src/java/jsonlib/JSONArray.java b/eurilys4-service/src/java/jsonlib/JSONArray.java new file mode 100644 index 00000000..673a9192 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/JSONArray.java @@ -0,0 +1,944 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +/** + * A JSONArray is an ordered sequence of values. Its external text form is a + * string wrapped in square brackets with commas separating the values. The + * internal form is an object having <code>get</code> and <code>opt</code> + * methods for accessing the values by index, and <code>put</code> methods for + * adding or replacing values. The values can be any of these types: + * <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>, + * <code>Number</code>, <code>String</code>, or the + * <code>JSONObject.NULL object</code>. + * <p> + * The constructor can convert a JSON text into a Java object. The + * <code>toString</code> method converts to JSON text. + * <p> + * A <code>get</code> method returns a value if one can be found, and throws an + * exception if one cannot be found. An <code>opt</code> method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + * <p> + * The generic <code>get()</code> and <code>opt()</code> methods return an + * object which you can cast or query for type. There are also typed + * <code>get</code> and <code>opt</code> methods that do type checking and type + * coercion for you. + * <p> + * The texts produced by the <code>toString</code> methods strictly conform to + * JSON syntax rules. The constructors are more forgiving in the texts they will + * accept: + * <ul> + * <li>An extra <code>,</code> <small>(comma)</small> may appear just + * before the closing bracket.</li> + * <li>The <code>null</code> value will be inserted when there is <code>,</code> + *  <small>(comma)</small> elision.</li> + * <li>Strings may be quoted with <code>'</code> <small>(single + * quote)</small>.</li> + * <li>Strings do not need to be quoted at all if they do not begin with a quote + * or single quote, and if they do not contain leading or trailing spaces, and + * if they do not contain any of these characters: + * <code>{ } [ ] / \ : , #</code> and if they do not look like numbers and + * if they are not the reserved words <code>true</code>, <code>false</code>, or + * <code>null</code>.</li> + * </ul> + * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONArray { + + /** + * The arrayList where the JSONArray's properties are kept. + */ + private final ArrayList myArrayList; + + /** + * Construct an empty JSONArray. + */ + public JSONArray() { + this.myArrayList = new ArrayList(); + } + + /** + * Construct a JSONArray from a JSONTokener. + * + * @param x + * A JSONTokener + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(JSONTokener x) throws JSONException { + this(); + if (x.nextClean() != '[') { + throw x.syntaxError("A JSONArray text must start with '['"); + } + if (x.nextClean() != ']') { + x.back(); + for (;;) { + if (x.nextClean() == ',') { + x.back(); + this.myArrayList.add(JSONObject.NULL); + } else { + x.back(); + this.myArrayList.add(x.nextValue()); + } + switch (x.nextClean()) { + case ',': + if (x.nextClean() == ']') { + return; + } + x.back(); + break; + case ']': + return; + default: + throw x.syntaxError("Expected a ',' or ']'"); + } + } + } + } + + /** + * Construct a JSONArray from a source JSON text. + * + * @param source + * A string that begins with <code>[</code> <small>(left + * bracket)</small> and ends with <code>]</code> + *  <small>(right bracket)</small>. + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONArray from a Collection. + * + * @param collection + * A Collection. + */ + public JSONArray(Collection collection) { + this.myArrayList = new ArrayList(); + if (collection != null) { + Iterator iter = collection.iterator(); + while (iter.hasNext()) { + this.myArrayList.add(JSONObject.wrap(iter.next())); + } + } + } + + /** + * Construct a JSONArray from an array + * + * @throws JSONException + * If not an array. + */ + public JSONArray(Object array) throws JSONException { + this(); + if (array.getClass().isArray()) { + int length = Array.getLength(array); + for (int i = 0; i < length; i += 1) { + this.put(JSONObject.wrap(Array.get(array, i))); + } + } else { + throw new JSONException( + "JSONArray initial value should be a string or collection or array."); + } + } + + /** + * Get the object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value. + * @throws JSONException + * If there is no value for the index. + */ + public Object get(int index) throws JSONException { + Object object = this.opt(index); + if (object == null) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with an index. The string values "true" + * and "false" are converted to boolean. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + * @throws JSONException + * If there is no value for the index or if the value is not + * convertible to boolean. + */ + public boolean getBoolean(int index) throws JSONException { + Object object = this.get(index); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONArray[" + index + "] is not a boolean."); + } + + /** + * Get the double value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public double getDouble(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the int value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value is not a number. + */ + public int getInt(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the JSONArray associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONArray value. + * @throws JSONException + * If there is no value for the index. or if the value is not a + * JSONArray + */ + public JSONArray getJSONArray(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); + } + + /** + * Get the JSONObject associated with an index. + * + * @param index + * subscript + * @return A JSONObject value. + * @throws JSONException + * If there is no value for the index or if the value is not a + * JSONObject + */ + public JSONObject getJSONObject(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); + } + + /** + * Get the long value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public long getLong(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the string associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A string value. + * @throws JSONException + * If there is no string value for the index. + */ + public String getString(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONArray[" + index + "] not a string."); + } + + /** + * Determine if the value is null. + * + * @param index + * The index must be between 0 and length() - 1. + * @return true if the value at the index is null, or if there is no value. + */ + public boolean isNull(int index) { + return JSONObject.NULL.equals(this.opt(index)); + } + + /** + * Make a string from the contents of this JSONArray. The + * <code>separator</code> string is inserted between each element. Warning: + * This method assumes that the data structure is acyclical. + * + * @param separator + * A string that will be inserted between the elements. + * @return a string. + * @throws JSONException + * If the array contains an invalid number. + */ + public String join(String separator) throws JSONException { + int len = this.length(); + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < len; i += 1) { + if (i > 0) { + sb.append(separator); + } + sb.append(JSONObject.valueToString(this.myArrayList.get(i))); + } + return sb.toString(); + } + + /** + * Get the number of elements in the JSONArray, included nulls. + * + * @return The length (or size). + */ + public int length() { + return this.myArrayList.size(); + } + + /** + * Get the optional object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value, or null if there is no object at that index. + */ + public Object opt(int index) { + return (index < 0 || index >= this.length()) ? null : this.myArrayList + .get(index); + } + + /** + * Get the optional boolean value associated with an index. It returns false + * if there is no value at that index, or if the value is not Boolean.TRUE + * or the String "true". + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + */ + public boolean optBoolean(int index) { + return this.optBoolean(index, false); + } + + /** + * Get the optional boolean value associated with an index. It returns the + * defaultValue if there is no value at that index or if it is not a Boolean + * or the String "true" or "false" (case insensitive). + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * A boolean default. + * @return The truth. + */ + public boolean optBoolean(int index, boolean defaultValue) { + try { + return this.getBoolean(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional double value associated with an index. NaN is returned + * if there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public double optDouble(int index) { + return this.optDouble(index, Double.NaN); + } + + /** + * Get the optional double value associated with an index. The defaultValue + * is returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * subscript + * @param defaultValue + * The default value. + * @return The value. + */ + public double optDouble(int index, double defaultValue) { + try { + return this.getDouble(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional int value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public int optInt(int index) { + return this.optInt(index, 0); + } + + /** + * Get the optional int value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public int optInt(int index, int defaultValue) { + try { + return this.getInt(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional JSONArray associated with an index. + * + * @param index + * subscript + * @return A JSONArray value, or null if the index has no value, or if the + * value is not a JSONArray. + */ + public JSONArray optJSONArray(int index) { + Object o = this.opt(index); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get the optional JSONObject associated with an index. Null is returned if + * the key is not found, or null if the index has no value, or if the value + * is not a JSONObject. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONObject value. + */ + public JSONObject optJSONObject(int index) { + Object o = this.opt(index); + return o instanceof JSONObject ? (JSONObject) o : null; + } + + /** + * Get the optional long value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public long optLong(int index) { + return this.optLong(index, 0); + } + + /** + * Get the optional long value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public long optLong(int index, long defaultValue) { + try { + return this.getLong(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional string value associated with an index. It returns an + * empty string if there is no value at that index. If the value is not a + * string and is not null, then it is coverted to a string. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A String value. + */ + public String optString(int index) { + return this.optString(index, ""); + } + + /** + * Get the optional string associated with an index. The defaultValue is + * returned if the key is not found. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return A String value. + */ + public String optString(int index, String defaultValue) { + Object object = this.opt(index); + return JSONObject.NULL.equals(object) ? defaultValue : object + .toString(); + } + + /** + * Append a boolean value. This increases the array's length by one. + * + * @param value + * A boolean value. + * @return this. + */ + public JSONArray put(boolean value) { + this.put(value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param value + * A Collection value. + * @return this. + */ + public JSONArray put(Collection value) { + this.put(new JSONArray(value)); + return this; + } + + /** + * Append a double value. This increases the array's length by one. + * + * @param value + * A double value. + * @throws JSONException + * if the value is not finite. + * @return this. + */ + public JSONArray put(double value) throws JSONException { + Double d = new Double(value); + JSONObject.testValidity(d); + this.put(d); + return this; + } + + /** + * Append an int value. This increases the array's length by one. + * + * @param value + * An int value. + * @return this. + */ + public JSONArray put(int value) { + this.put(new Integer(value)); + return this; + } + + /** + * Append an long value. This increases the array's length by one. + * + * @param value + * A long value. + * @return this. + */ + public JSONArray put(long value) { + this.put(new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject which + * is produced from a Map. + * + * @param value + * A Map value. + * @return this. + */ + public JSONArray put(Map value) { + this.put(new JSONObject(value)); + return this; + } + + /** + * Append an object value. This increases the array's length by one. + * + * @param value + * An object value. The value should be a Boolean, Double, + * Integer, JSONArray, JSONObject, Long, or String, or the + * JSONObject.NULL object. + * @return this. + */ + public JSONArray put(Object value) { + this.myArrayList.add(value); + return this; + } + + /** + * Put or replace a boolean value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * A boolean value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, boolean value) throws JSONException { + this.put(index, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param index + * The subscript. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, Collection value) throws JSONException { + this.put(index, new JSONArray(value)); + return this; + } + + /** + * Put or replace a double value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A double value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, double value) throws JSONException { + this.put(index, new Double(value)); + return this; + } + + /** + * Put or replace an int value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * An int value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, int value) throws JSONException { + this.put(index, new Integer(value)); + return this; + } + + /** + * Put or replace a long value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A long value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, long value) throws JSONException { + this.put(index, new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject that + * is produced from a Map. + * + * @param index + * The subscript. + * @param value + * The Map value. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Map value) throws JSONException { + this.put(index, new JSONObject(value)); + return this; + } + + /** + * Put or replace an object value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * The value to put into the array. The value should be a + * Boolean, Double, Integer, JSONArray, JSONObject, Long, or + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Object value) throws JSONException { + JSONObject.testValidity(value); + if (index < 0) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + if (index < this.length()) { + this.myArrayList.set(index, value); + } else { + while (index != this.length()) { + this.put(JSONObject.NULL); + } + this.put(value); + } + return this; + } + + /** + * Remove an index and close the hole. + * + * @param index + * The index of the element to be removed. + * @return The value that was associated with the index, or null if there + * was no value. + */ + public Object remove(int index) { + Object o = this.opt(index); + this.myArrayList.remove(index); + return o; + } + + /** + * Produce a JSONObject by combining a JSONArray of names with the values of + * this JSONArray. + * + * @param names + * A JSONArray containing a list of key strings. These will be + * paired with the values. + * @return A JSONObject, or null if there are no names or if this JSONArray + * has no values. + * @throws JSONException + * If any of the names are null. + */ + public JSONObject toJSONObject(JSONArray names) throws JSONException { + if (names == null || names.length() == 0 || this.length() == 0) { + return null; + } + JSONObject jo = new JSONObject(); + for (int i = 0; i < names.length(); i += 1) { + jo.put(names.getString(i), this.opt(i)); + } + return jo; + } + + /** + * Make a JSON text of this JSONArray. For compactness, no unnecessary + * whitespace is added. If it is not possible to produce a syntactically + * correct JSON text then null will be returned instead. This could occur if + * the array contains an invalid number. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, transmittable representation of the + * array. + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONArray. Warning: This method + * assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, transmittable representation of the + * object, beginning with <code>[</code> <small>(left + * bracket)</small> and ending with <code>]</code> + *  <small>(right bracket)</small>. + * @throws JSONException + */ + public String toString(int indentFactor) throws JSONException { + StringWriter sw = new StringWriter(); + synchronized (sw.getBuffer()) { + return this.write(sw, indentFactor, 0).toString(); + } + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @param indent + * The indention of the top level. + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + int length = this.length(); + writer.write('['); + + if (length == 1) { + JSONObject.writeValue(writer, this.myArrayList.get(0), + indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + + for (int i = 0; i < length; i += 1) { + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, newindent); + JSONObject.writeValue(writer, this.myArrayList.get(i), + indentFactor, newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, indent); + } + writer.write(']'); + return writer; + } catch (IOException e) { + throw new JSONException(e); + } + } +} diff --git a/eurilys4-service/src/java/jsonlib/JSONException.java b/eurilys4-service/src/java/jsonlib/JSONException.java new file mode 100644 index 00000000..971547e6 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/JSONException.java @@ -0,0 +1,41 @@ +package org.json; + +/** + * The JSONException is thrown by the JSON.org classes when things are amiss. + * + * @author JSON.org + * @version 2013-02-10 + */ +public class JSONException extends RuntimeException { + private static final long serialVersionUID = 0; + private Throwable cause; + + /** + * Constructs a JSONException with an explanatory message. + * + * @param message + * Detail about the reason for the exception. + */ + public JSONException(String message) { + super(message); + } + + /** + * Constructs a new JSONException with the specified cause. + */ + public JSONException(Throwable cause) { + super(cause.getMessage()); + this.cause = cause; + } + + /** + * Returns the cause of this exception or null if the cause is nonexistent + * or unknown. + * + * @returns the cause of this exception or null if the cause is nonexistent + * or unknown. + */ + public Throwable getCause() { + return this.cause; + } +} diff --git a/eurilys4-service/src/java/jsonlib/JSONML.java b/eurilys4-service/src/java/jsonlib/JSONML.java new file mode 100644 index 00000000..4be68635 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/JSONML.java @@ -0,0 +1,467 @@ +package org.json; + +/* +Copyright (c) 2008 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.util.Iterator; + + +/** + * This provides static methods to convert an XML text into a JSONArray or + * JSONObject, and to covert a JSONArray or JSONObject into an XML text using + * the JsonML transform. + * + * @author JSON.org + * @version 2012-03-28 + */ +public class JSONML { + + /** + * Parse XML values and store them in a JSONArray. + * @param x The XMLTokener containing the source string. + * @param arrayForm true if array form, false if object form. + * @param ja The JSONArray that is containing the current tag or null + * if we are at the outermost level. + * @return A JSONArray if the value is the outermost tag, otherwise null. + * @throws JSONException + */ + private static Object parse( + XMLTokener x, + boolean arrayForm, + JSONArray ja + ) throws JSONException { + String attribute; + char c; + String closeTag = null; + int i; + JSONArray newja = null; + JSONObject newjo = null; + Object token; + String tagName = null; + +// Test for and skip past these forms: +// <!-- ... --> +// <![ ... ]]> +// <! ... > +// <? ... ?> + + while (true) { + if (!x.more()) { + throw x.syntaxError("Bad XML"); + } + token = x.nextContent(); + if (token == XML.LT) { + token = x.nextToken(); + if (token instanceof Character) { + if (token == XML.SLASH) { + +// Close tag </ + + token = x.nextToken(); + if (!(token instanceof String)) { + throw new JSONException( + "Expected a closing name instead of '" + + token + "'."); + } + if (x.nextToken() != XML.GT) { + throw x.syntaxError("Misshaped close tag"); + } + return token; + } else if (token == XML.BANG) { + +// <! + + c = x.next(); + if (c == '-') { + if (x.next() == '-') { + x.skipPast("-->"); + } else { + x.back(); + } + } else if (c == '[') { + token = x.nextToken(); + if (token.equals("CDATA") && x.next() == '[') { + if (ja != null) { + ja.put(x.nextCDATA()); + } + } else { + throw x.syntaxError("Expected 'CDATA['"); + } + } else { + i = 1; + do { + token = x.nextMeta(); + if (token == null) { + throw x.syntaxError("Missing '>' after '<!'."); + } else if (token == XML.LT) { + i += 1; + } else if (token == XML.GT) { + i -= 1; + } + } while (i > 0); + } + } else if (token == XML.QUEST) { + +// <? + + x.skipPast("?>"); + } else { + throw x.syntaxError("Misshaped tag"); + } + +// Open tag < + + } else { + if (!(token instanceof String)) { + throw x.syntaxError("Bad tagName '" + token + "'."); + } + tagName = (String)token; + newja = new JSONArray(); + newjo = new JSONObject(); + if (arrayForm) { + newja.put(tagName); + if (ja != null) { + ja.put(newja); + } + } else { + newjo.put("tagName", tagName); + if (ja != null) { + ja.put(newjo); + } + } + token = null; + for (;;) { + if (token == null) { + token = x.nextToken(); + } + if (token == null) { + throw x.syntaxError("Misshaped tag"); + } + if (!(token instanceof String)) { + break; + } + +// attribute = value + + attribute = (String)token; + if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) { + throw x.syntaxError("Reserved attribute."); + } + token = x.nextToken(); + if (token == XML.EQ) { + token = x.nextToken(); + if (!(token instanceof String)) { + throw x.syntaxError("Missing value"); + } + newjo.accumulate(attribute, XML.stringToValue((String)token)); + token = null; + } else { + newjo.accumulate(attribute, ""); + } + } + if (arrayForm && newjo.length() > 0) { + newja.put(newjo); + } + +// Empty tag <.../> + + if (token == XML.SLASH) { + if (x.nextToken() != XML.GT) { + throw x.syntaxError("Misshaped tag"); + } + if (ja == null) { + if (arrayForm) { + return newja; + } else { + return newjo; + } + } + +// Content, between <...> and </...> + + } else { + if (token != XML.GT) { + throw x.syntaxError("Misshaped tag"); + } + closeTag = (String)parse(x, arrayForm, newja); + if (closeTag != null) { + if (!closeTag.equals(tagName)) { + throw x.syntaxError("Mismatched '" + tagName + + "' and '" + closeTag + "'"); + } + tagName = null; + if (!arrayForm && newja.length() > 0) { + newjo.put("childNodes", newja); + } + if (ja == null) { + if (arrayForm) { + return newja; + } else { + return newjo; + } + } + } + } + } + } else { + if (ja != null) { + ja.put(token instanceof String + ? XML.stringToValue((String)token) + : token); + } + } + } + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONArray using the JsonML transform. Each XML tag is represented as + * a JSONArray in which the first element is the tag name. If the tag has + * attributes, then the second element will be JSONObject containing the + * name/value pairs. If the tag contains children, then strings and + * JSONArrays will represent the child tags. + * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored. + * @param string The source string. + * @return A JSONArray containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONArray toJSONArray(String string) throws JSONException { + return toJSONArray(new XMLTokener(string)); + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONArray using the JsonML transform. Each XML tag is represented as + * a JSONArray in which the first element is the tag name. If the tag has + * attributes, then the second element will be JSONObject containing the + * name/value pairs. If the tag contains children, then strings and + * JSONArrays will represent the child content and tags. + * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored. + * @param x An XMLTokener. + * @return A JSONArray containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONArray toJSONArray(XMLTokener x) throws JSONException { + return (JSONArray)parse(x, true, null); + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONObject using the JsonML transform. Each XML tag is represented as + * a JSONObject with a "tagName" property. If the tag has attributes, then + * the attributes will be in the JSONObject as properties. If the tag + * contains children, the object will have a "childNodes" property which + * will be an array of strings and JsonML JSONObjects. + + * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored. + * @param x An XMLTokener of the XML source text. + * @return A JSONObject containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONObject toJSONObject(XMLTokener x) throws JSONException { + return (JSONObject)parse(x, false, null); + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONObject using the JsonML transform. Each XML tag is represented as + * a JSONObject with a "tagName" property. If the tag has attributes, then + * the attributes will be in the JSONObject as properties. If the tag + * contains children, the object will have a "childNodes" property which + * will be an array of strings and JsonML JSONObjects. + + * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored. + * @param string The XML source text. + * @return A JSONObject containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + return toJSONObject(new XMLTokener(string)); + } + + + /** + * Reverse the JSONML transformation, making an XML text from a JSONArray. + * @param ja A JSONArray. + * @return An XML string. + * @throws JSONException + */ + public static String toString(JSONArray ja) throws JSONException { + int i; + JSONObject jo; + String key; + Iterator keys; + int length; + Object object; + StringBuffer sb = new StringBuffer(); + String tagName; + String value; + +// Emit <tagName + + tagName = ja.getString(0); + XML.noSpace(tagName); + tagName = XML.escape(tagName); + sb.append('<'); + sb.append(tagName); + + object = ja.opt(1); + if (object instanceof JSONObject) { + i = 2; + jo = (JSONObject)object; + +// Emit the attributes + + keys = jo.keys(); + while (keys.hasNext()) { + key = keys.next().toString(); + XML.noSpace(key); + value = jo.optString(key); + if (value != null) { + sb.append(' '); + sb.append(XML.escape(key)); + sb.append('='); + sb.append('"'); + sb.append(XML.escape(value)); + sb.append('"'); + } + } + } else { + i = 1; + } + +//Emit content in body + + length = ja.length(); + if (i >= length) { + sb.append('/'); + sb.append('>'); + } else { + sb.append('>'); + do { + object = ja.get(i); + i += 1; + if (object != null) { + if (object instanceof String) { + sb.append(XML.escape(object.toString())); + } else if (object instanceof JSONObject) { + sb.append(toString((JSONObject)object)); + } else if (object instanceof JSONArray) { + sb.append(toString((JSONArray)object)); + } + } + } while (i < length); + sb.append('<'); + sb.append('/'); + sb.append(tagName); + sb.append('>'); + } + return sb.toString(); + } + + /** + * Reverse the JSONML transformation, making an XML text from a JSONObject. + * The JSONObject must contain a "tagName" property. If it has children, + * then it must have a "childNodes" property containing an array of objects. + * The other properties are attributes with string values. + * @param jo A JSONObject. + * @return An XML string. + * @throws JSONException + */ + public static String toString(JSONObject jo) throws JSONException { + StringBuffer sb = new StringBuffer(); + int i; + JSONArray ja; + String key; + Iterator keys; + int length; + Object object; + String tagName; + String value; + +//Emit <tagName + + tagName = jo.optString("tagName"); + if (tagName == null) { + return XML.escape(jo.toString()); + } + XML.noSpace(tagName); + tagName = XML.escape(tagName); + sb.append('<'); + sb.append(tagName); + +//Emit the attributes + + keys = jo.keys(); + while (keys.hasNext()) { + key = keys.next().toString(); + if (!"tagName".equals(key) && !"childNodes".equals(key)) { + XML.noSpace(key); + value = jo.optString(key); + if (value != null) { + sb.append(' '); + sb.append(XML.escape(key)); + sb.append('='); + sb.append('"'); + sb.append(XML.escape(value)); + sb.append('"'); + } + } + } + +//Emit content in body + + ja = jo.optJSONArray("childNodes"); + if (ja == null) { + sb.append('/'); + sb.append('>'); + } else { + sb.append('>'); + length = ja.length(); + for (i = 0; i < length; i += 1) { + object = ja.get(i); + if (object != null) { + if (object instanceof String) { + sb.append(XML.escape(object.toString())); + } else if (object instanceof JSONObject) { + sb.append(toString((JSONObject)object)); + } else if (object instanceof JSONArray) { + sb.append(toString((JSONArray)object)); + } else { + sb.append(object.toString()); + } + } + } + sb.append('<'); + sb.append('/'); + sb.append(tagName); + sb.append('>'); + } + return sb.toString(); + } +} diff --git a/eurilys4-service/src/java/jsonlib/JSONObject.java b/eurilys4-service/src/java/jsonlib/JSONObject.java new file mode 100644 index 00000000..9d2d5cee --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/JSONObject.java @@ -0,0 +1,1664 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; + +/** + * A JSONObject is an unordered collection of name/value pairs. Its external + * form is a string wrapped in curly braces with colons between the names and + * values, and commas between the values and names. The internal form is an + * object having <code>get</code> and <code>opt</code> methods for accessing + * the values by name, and <code>put</code> methods for adding or replacing + * values by name. The values can be any of these types: <code>Boolean</code>, + * <code>JSONArray</code>, <code>JSONObject</code>, <code>Number</code>, + * <code>String</code>, or the <code>JSONObject.NULL</code> object. A + * JSONObject constructor can be used to convert an external form JSON text + * into an internal form whose values can be retrieved with the + * <code>get</code> and <code>opt</code> methods, or to convert values into a + * JSON text using the <code>put</code> and <code>toString</code> methods. A + * <code>get</code> method returns a value if one can be found, and throws an + * exception if one cannot be found. An <code>opt</code> method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + * <p> + * The generic <code>get()</code> and <code>opt()</code> methods return an + * object, which you can cast or query for type. There are also typed + * <code>get</code> and <code>opt</code> methods that do type checking and type + * coercion for you. The opt methods differ from the get methods in that they + * do not throw. Instead, they return a specified value, such as null. + * <p> + * The <code>put</code> methods add or replace values in an object. For + * example, + * + * <pre> + * myString = new JSONObject() + * .put("JSON", "Hello, World!").toString(); + * </pre> + * + * produces the string <code>{"JSON": "Hello, World"}</code>. + * <p> + * The texts produced by the <code>toString</code> methods strictly conform to + * the JSON syntax rules. The constructors are more forgiving in the texts they + * will accept: + * <ul> + * <li>An extra <code>,</code> <small>(comma)</small> may appear just + * before the closing brace.</li> + * <li>Strings may be quoted with <code>'</code> <small>(single + * quote)</small>.</li> + * <li>Strings do not need to be quoted at all if they do not begin with a + * quote or single quote, and if they do not contain leading or trailing + * spaces, and if they do not contain any of these characters: + * <code>{ } [ ] / \ : , #</code> and if they do not look like numbers and + * if they are not the reserved words <code>true</code>, <code>false</code>, + * or <code>null</code>.</li> + * </ul> + * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONObject { + /** + * The maximum number of keys in the key pool. + */ + private static final int keyPoolSize = 100; + + /** + * Key pooling is like string interning, but without permanently tying up + * memory. To help conserve memory, storage of duplicated key strings in + * JSONObjects will be avoided by using a key pool to manage unique key + * string objects. This is used by JSONObject.put(string, object). + */ + private static HashMap keyPool = new HashMap(keyPoolSize); + + /** + * JSONObject.NULL is equivalent to the value that JavaScript calls null, + * whilst Java's null is equivalent to the value that JavaScript calls + * undefined. + */ + private static final class Null { + + /** + * There is only intended to be a single instance of the NULL object, + * so the clone method returns itself. + * + * @return NULL. + */ + protected final Object clone() { + return this; + } + + /** + * A Null object is equal to the null value and to itself. + * + * @param object + * An object to test for nullness. + * @return true if the object parameter is the JSONObject.NULL object or + * null. + */ + public boolean equals(Object object) { + return object == null || object == this; + } + + /** + * Get the "null" string value. + * + * @return The string "null". + */ + public String toString() { + return "null"; + } + } + + /** + * The map where the JSONObject's properties are kept. + */ + private final Map map; + + /** + * It is sometimes more convenient and less ambiguous to have a + * <code>NULL</code> object than to use Java's <code>null</code> value. + * <code>JSONObject.NULL.equals(null)</code> returns <code>true</code>. + * <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>. + */ + public static final Object NULL = new Null(); + + /** + * Construct an empty JSONObject. + */ + public JSONObject() { + this.map = new HashMap(); + } + + /** + * Construct a JSONObject from a subset of another JSONObject. An array of + * strings is used to identify the keys that should be copied. Missing keys + * are ignored. + * + * @param jo + * A JSONObject. + * @param names + * An array of strings. + * @throws JSONException + * @exception JSONException + * If a value is a non-finite number or if a name is + * duplicated. + */ + public JSONObject(JSONObject jo, String[] names) { + this(); + for (int i = 0; i < names.length; i += 1) { + try { + this.putOnce(names[i], jo.opt(names[i])); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a JSONTokener. + * + * @param x + * A JSONTokener object containing the source string. + * @throws JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(JSONTokener x) throws JSONException { + this(); + char c; + String key; + + if (x.nextClean() != '{') { + throw x.syntaxError("A JSONObject text must begin with '{'"); + } + for (;;) { + c = x.nextClean(); + switch (c) { + case 0: + throw x.syntaxError("A JSONObject text must end with '}'"); + case '}': + return; + default: + x.back(); + key = x.nextValue().toString(); + } + +// The key is followed by ':'. + + c = x.nextClean(); + if (c != ':') { + throw x.syntaxError("Expected a ':' after a key"); + } + this.putOnce(key, x.nextValue()); + +// Pairs are separated by ','. + + switch (x.nextClean()) { + case ';': + case ',': + if (x.nextClean() == '}') { + return; + } + x.back(); + break; + case '}': + return; + default: + throw x.syntaxError("Expected a ',' or '}'"); + } + } + } + + /** + * Construct a JSONObject from a Map. + * + * @param map + * A map object that can be used to initialize the contents of + * the JSONObject. + * @throws JSONException + */ + public JSONObject(Map map) { + this.map = new HashMap(); + if (map != null) { + Iterator i = map.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry e = (Map.Entry) i.next(); + Object value = e.getValue(); + if (value != null) { + this.map.put(e.getKey(), wrap(value)); + } + } + } + } + + /** + * Construct a JSONObject from an Object using bean getters. It reflects on + * all of the public methods of the object. For each of the methods with no + * parameters and a name starting with <code>"get"</code> or + * <code>"is"</code> followed by an uppercase letter, the method is invoked, + * and a key and the value returned from the getter method are put into the + * new JSONObject. + * + * The key is formed by removing the <code>"get"</code> or <code>"is"</code> + * prefix. If the second remaining character is not upper case, then the + * first character is converted to lower case. + * + * For example, if an object has a method named <code>"getName"</code>, and + * if the result of calling <code>object.getName()</code> is + * <code>"Larry Fine"</code>, then the JSONObject will contain + * <code>"name": "Larry Fine"</code>. + * + * @param bean + * An object that has getter methods that should be used to make + * a JSONObject. + */ + public JSONObject(Object bean) { + this(); + this.populateMap(bean); + } + + /** + * Construct a JSONObject from an Object, using reflection to find the + * public members. The resulting JSONObject's keys will be the strings from + * the names array, and the values will be the field values associated with + * those keys in the object. If a key is not found or not visible, then it + * will not be copied into the new JSONObject. + * + * @param object + * An object that has fields that should be used to make a + * JSONObject. + * @param names + * An array of strings, the names of the fields to be obtained + * from the object. + */ + public JSONObject(Object object, String names[]) { + this(); + Class c = object.getClass(); + for (int i = 0; i < names.length; i += 1) { + String name = names[i]; + try { + this.putOpt(name, c.getField(name).get(object)); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a source JSON text string. This is the most + * commonly used JSONObject constructor. + * + * @param source + * A string beginning with <code>{</code> <small>(left + * brace)</small> and ending with <code>}</code> + *  <small>(right brace)</small>. + * @exception JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONObject from a ResourceBundle. + * + * @param baseName + * The ResourceBundle base name. + * @param locale + * The Locale to load the ResourceBundle for. + * @throws JSONException + * If any JSONExceptions are detected. + */ + public JSONObject(String baseName, Locale locale) throws JSONException { + this(); + ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, + Thread.currentThread().getContextClassLoader()); + +// Iterate through the keys in the bundle. + + Enumeration keys = bundle.getKeys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + if (key instanceof String) { + +// Go through the path, ensuring that there is a nested JSONObject for each +// segment except the last. Add the value using the last segment's name into +// the deepest nested JSONObject. + + String[] path = ((String) key).split("\\."); + int last = path.length - 1; + JSONObject target = this; + for (int i = 0; i < last; i += 1) { + String segment = path[i]; + JSONObject nextTarget = target.optJSONObject(segment); + if (nextTarget == null) { + nextTarget = new JSONObject(); + target.put(segment, nextTarget); + } + target = nextTarget; + } + target.put(path[last], bundle.getString((String) key)); + } + } + } + + /** + * Accumulate values under a key. It is similar to the put method except + * that if there is already an object stored under the key then a JSONArray + * is stored under the key to hold all of the accumulated values. If there + * is already a JSONArray, then the new value is appended to it. In + * contrast, the put method replaces the previous value. + * + * If only one value is accumulated that is not a JSONArray, then the result + * will be the same as using put. But if multiple values are accumulated, + * then the result will be like append. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the value is an invalid number or if the key is null. + */ + public JSONObject accumulate(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, + value instanceof JSONArray ? new JSONArray().put(value) + : value); + } else if (object instanceof JSONArray) { + ((JSONArray) object).put(value); + } else { + this.put(key, new JSONArray().put(object).put(value)); + } + return this; + } + + /** + * Append values to the array under a key. If the key does not exist in the + * JSONObject, then the key is put in the JSONObject with its value being a + * JSONArray containing the value parameter. If the key was already + * associated with a JSONArray, then the value parameter is appended to it. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the key is null or if the current value associated with + * the key is not a JSONArray. + */ + public JSONObject append(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, new JSONArray().put(value)); + } else if (object instanceof JSONArray) { + this.put(key, ((JSONArray) object).put(value)); + } else { + throw new JSONException("JSONObject[" + key + + "] is not a JSONArray."); + } + return this; + } + + /** + * Produce a string from a double. The string "null" will be returned if the + * number is not finite. + * + * @param d + * A double. + * @return A String. + */ + public static String doubleToString(double d) { + if (Double.isInfinite(d) || Double.isNaN(d)) { + return "null"; + } + +// Shave off trailing zeros and decimal point, if possible. + + String string = Double.toString(d); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get the value object associated with a key. + * + * @param key + * A key string. + * @return The object associated with the key. + * @throws JSONException + * if the key is not found. + */ + public Object get(String key) throws JSONException { + if (key == null) { + throw new JSONException("Null key."); + } + Object object = this.opt(key); + if (object == null) { + throw new JSONException("JSONObject[" + quote(key) + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with a key. + * + * @param key + * A key string. + * @return The truth. + * @throws JSONException + * if the value is not a Boolean or the String "true" or + * "false". + */ + public boolean getBoolean(String key) throws JSONException { + Object object = this.get(key); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a Boolean."); + } + + /** + * Get the double value associated with a key. + * + * @param key + * A key string. + * @return The numeric value. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. + */ + public double getDouble(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a number."); + } + } + + /** + * Get the int value associated with a key. + * + * @param key + * A key string. + * @return The integer value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to an integer. + */ + public int getInt(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not an int."); + } + } + + /** + * Get the JSONArray value associated with a key. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONArray. + */ + public JSONArray getJSONArray(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONArray."); + } + + /** + * Get the JSONObject value associated with a key. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONObject. + */ + public JSONObject getJSONObject(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONObject."); + } + + /** + * Get the long value associated with a key. + * + * @param key + * A key string. + * @return The long value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to a long. + */ + public long getLong(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a long."); + } + } + + /** + * Get an array of field names from a JSONObject. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(JSONObject jo) { + int length = jo.length(); + if (length == 0) { + return null; + } + Iterator iterator = jo.keys(); + String[] names = new String[length]; + int i = 0; + while (iterator.hasNext()) { + names[i] = (String) iterator.next(); + i += 1; + } + return names; + } + + /** + * Get an array of field names from an Object. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(Object object) { + if (object == null) { + return null; + } + Class klass = object.getClass(); + Field[] fields = klass.getFields(); + int length = fields.length; + if (length == 0) { + return null; + } + String[] names = new String[length]; + for (int i = 0; i < length; i += 1) { + names[i] = fields[i].getName(); + } + return names; + } + + /** + * Get the string associated with a key. + * + * @param key + * A key string. + * @return A string which is the value. + * @throws JSONException + * if there is no string value for the key. + */ + public String getString(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONObject[" + quote(key) + "] not a string."); + } + + /** + * Determine if the JSONObject contains a specific key. + * + * @param key + * A key string. + * @return true if the key exists in the JSONObject. + */ + public boolean has(String key) { + return this.map.containsKey(key); + } + + /** + * Increment a property of a JSONObject. If there is no such property, + * create one with a value of 1. If there is such a property, and if it is + * an Integer, Long, Double, or Float, then add one to it. + * + * @param key + * A key string. + * @return this. + * @throws JSONException + * If there is already a property with this name that is not an + * Integer, Long, Double, or Float. + */ + public JSONObject increment(String key) throws JSONException { + Object value = this.opt(key); + if (value == null) { + this.put(key, 1); + } else if (value instanceof Integer) { + this.put(key, ((Integer) value).intValue() + 1); + } else if (value instanceof Long) { + this.put(key, ((Long) value).longValue() + 1); + } else if (value instanceof Double) { + this.put(key, ((Double) value).doubleValue() + 1); + } else if (value instanceof Float) { + this.put(key, ((Float) value).floatValue() + 1); + } else { + throw new JSONException("Unable to increment [" + quote(key) + "]."); + } + return this; + } + + /** + * Determine if the value associated with the key is null or if there is no + * value. + * + * @param key + * A key string. + * @return true if there is no value associated with the key or if the value + * is the JSONObject.NULL object. + */ + public boolean isNull(String key) { + return JSONObject.NULL.equals(this.opt(key)); + } + + /** + * Get an enumeration of the keys of the JSONObject. + * + * @return An iterator of the keys. + */ + public Iterator keys() { + return this.keySet().iterator(); + } + + /** + * Get a set of keys of the JSONObject. + * + * @return A keySet. + */ + public Set keySet() { + return this.map.keySet(); + } + + /** + * Get the number of keys stored in the JSONObject. + * + * @return The number of keys in the JSONObject. + */ + public int length() { + return this.map.size(); + } + + /** + * Produce a JSONArray containing the names of the elements of this + * JSONObject. + * + * @return A JSONArray containing the key strings, or null if the JSONObject + * is empty. + */ + public JSONArray names() { + JSONArray ja = new JSONArray(); + Iterator keys = this.keys(); + while (keys.hasNext()) { + ja.put(keys.next()); + } + return ja.length() == 0 ? null : ja; + } + + /** + * Produce a string from a Number. + * + * @param number + * A Number + * @return A String. + * @throws JSONException + * If n is a non-finite number. + */ + public static String numberToString(Number number) throws JSONException { + if (number == null) { + throw new JSONException("Null pointer"); + } + testValidity(number); + +// Shave off trailing zeros and decimal point, if possible. + + String string = number.toString(); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get an optional value associated with a key. + * + * @param key + * A key string. + * @return An object which is the value, or null if there is no value. + */ + public Object opt(String key) { + return key == null ? null : this.map.get(key); + } + + /** + * Get an optional boolean associated with a key. It returns false if there + * is no such key, or if the value is not Boolean.TRUE or the String "true". + * + * @param key + * A key string. + * @return The truth. + */ + public boolean optBoolean(String key) { + return this.optBoolean(key, false); + } + + /** + * Get an optional boolean associated with a key. It returns the + * defaultValue if there is no such key, or if it is not a Boolean or the + * String "true" or "false" (case insensitive). + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return The truth. + */ + public boolean optBoolean(String key, boolean defaultValue) { + try { + return this.getBoolean(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional double associated with a key, or NaN if there is no such + * key or if its value is not a number. If the value is a string, an attempt + * will be made to evaluate it as a number. + * + * @param key + * A string which is the key. + * @return An object which is the value. + */ + public double optDouble(String key) { + return this.optDouble(key, Double.NaN); + } + + /** + * Get an optional double associated with a key, or the defaultValue if + * there is no such key or if its value is not a number. If the value is a + * string, an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public double optDouble(String key, double defaultValue) { + try { + return this.getDouble(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional int value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public int optInt(String key) { + return this.optInt(key, 0); + } + + /** + * Get an optional int value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public int optInt(String key, int defaultValue) { + try { + return this.getInt(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional JSONArray associated with a key. It returns null if there + * is no such key, or if its value is not a JSONArray. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + */ + public JSONArray optJSONArray(String key) { + Object o = this.opt(key); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get an optional JSONObject associated with a key. It returns null if + * there is no such key, or if its value is not a JSONObject. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + */ + public JSONObject optJSONObject(String key) { + Object object = this.opt(key); + return object instanceof JSONObject ? (JSONObject) object : null; + } + + /** + * Get an optional long value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public long optLong(String key) { + return this.optLong(key, 0); + } + + /** + * Get an optional long value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public long optLong(String key, long defaultValue) { + try { + return this.getLong(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional string associated with a key. It returns an empty string + * if there is no such key. If the value is not a string and is not null, + * then it is converted to a string. + * + * @param key + * A key string. + * @return A string which is the value. + */ + public String optString(String key) { + return this.optString(key, ""); + } + + /** + * Get an optional string associated with a key. It returns the defaultValue + * if there is no such key. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return A string which is the value. + */ + public String optString(String key, String defaultValue) { + Object object = this.opt(key); + return NULL.equals(object) ? defaultValue : object.toString(); + } + + private void populateMap(Object bean) { + Class klass = bean.getClass(); + +// If klass is a System class then set includeSuperClass to false. + + boolean includeSuperClass = klass.getClassLoader() != null; + + Method[] methods = includeSuperClass ? klass.getMethods() : klass + .getDeclaredMethods(); + for (int i = 0; i < methods.length; i += 1) { + try { + Method method = methods[i]; + if (Modifier.isPublic(method.getModifiers())) { + String name = method.getName(); + String key = ""; + if (name.startsWith("get")) { + if ("getClass".equals(name) + || "getDeclaringClass".equals(name)) { + key = ""; + } else { + key = name.substring(3); + } + } else if (name.startsWith("is")) { + key = name.substring(2); + } + if (key.length() > 0 + && Character.isUpperCase(key.charAt(0)) + && method.getParameterTypes().length == 0) { + if (key.length() == 1) { + key = key.toLowerCase(); + } else if (!Character.isUpperCase(key.charAt(1))) { + key = key.substring(0, 1).toLowerCase() + + key.substring(1); + } + + Object result = method.invoke(bean, (Object[]) null); + if (result != null) { + this.map.put(key, wrap(result)); + } + } + } + } catch (Exception ignore) { + } + } + } + + /** + * Put a key/boolean pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A boolean which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, boolean value) throws JSONException { + this.put(key, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONArray which is produced from a Collection. + * + * @param key + * A key string. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Collection value) throws JSONException { + this.put(key, new JSONArray(value)); + return this; + } + + /** + * Put a key/double pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A double which is the value. + * @return this. + * @throws JSONException + * If the key is null or if the number is invalid. + */ + public JSONObject put(String key, double value) throws JSONException { + this.put(key, new Double(value)); + return this; + } + + /** + * Put a key/int pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * An int which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, int value) throws JSONException { + this.put(key, new Integer(value)); + return this; + } + + /** + * Put a key/long pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A long which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, long value) throws JSONException { + this.put(key, new Long(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONObject which is produced from a Map. + * + * @param key + * A key string. + * @param value + * A Map value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Map value) throws JSONException { + this.put(key, new JSONObject(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject. If the value is null, then the + * key will be removed from the JSONObject if it is present. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is non-finite number or if the key is null. + */ + public JSONObject put(String key, Object value) throws JSONException { + String pooled; + if (key == null) { + throw new NullPointerException("Null key."); + } + if (value != null) { + testValidity(value); + pooled = (String) keyPool.get(key); + if (pooled == null) { + if (keyPool.size() >= keyPoolSize) { + keyPool = new HashMap(keyPoolSize); + } + keyPool.put(key, key); + } else { + key = pooled; + } + this.map.put(key, value); + } else { + this.remove(key); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null, and only if there is not already a member with that + * name. + * + * @param key + * @param value + * @return his. + * @throws JSONException + * if the key is a duplicate + */ + public JSONObject putOnce(String key, Object value) throws JSONException { + if (key != null && value != null) { + if (this.opt(key) != null) { + throw new JSONException("Duplicate key \"" + key + "\""); + } + this.put(key, value); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is a non-finite number. + */ + public JSONObject putOpt(String key, Object value) throws JSONException { + if (key != null && value != null) { + this.put(key, value); + } + return this; + } + + /** + * Produce a string in double quotes with backslash sequences in all the + * right places. A backslash will be inserted within </, producing <\/, + * allowing JSON text to be delivered in HTML. In JSON text, a string cannot + * contain a control character or an unescaped quote or backslash. + * + * @param string + * A String + * @return A String correctly formatted for insertion in a JSON text. + */ + public static String quote(String string) { + StringWriter sw = new StringWriter(); + synchronized (sw.getBuffer()) { + try { + return quote(string, sw).toString(); + } catch (IOException ignored) { + // will never happen - we are writing to a string writer + return ""; + } + } + } + + public static Writer quote(String string, Writer w) throws IOException { + if (string == null || string.length() == 0) { + w.write("\"\""); + return w; + } + + char b; + char c = 0; + String hhhh; + int i; + int len = string.length(); + + w.write('"'); + for (i = 0; i < len; i += 1) { + b = c; + c = string.charAt(i); + switch (c) { + case '\\': + case '"': + w.write('\\'); + w.write(c); + break; + case '/': + if (b == '<') { + w.write('\\'); + } + w.write(c); + break; + case '\b': + w.write("\\b"); + break; + case '\t': + w.write("\\t"); + break; + case '\n': + w.write("\\n"); + break; + case '\f': + w.write("\\f"); + break; + case '\r': + w.write("\\r"); + break; + default: + if (c < ' ' || (c >= '\u0080' && c < '\u00a0') + || (c >= '\u2000' && c < '\u2100')) { + w.write("\\u"); + hhhh = Integer.toHexString(c); + w.write("0000", 0, 4 - hhhh.length()); + w.write(hhhh); + } else { + w.write(c); + } + } + } + w.write('"'); + return w; + } + + /** + * Remove a name and its value, if present. + * + * @param key + * The name to be removed. + * @return The value that was associated with the name, or null if there was + * no value. + */ + public Object remove(String key) { + return this.map.remove(key); + } + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. + * + * @param string + * A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + Double d; + if (string.equals("")) { + return string; + } + if (string.equalsIgnoreCase("true")) { + return Boolean.TRUE; + } + if (string.equalsIgnoreCase("false")) { + return Boolean.FALSE; + } + if (string.equalsIgnoreCase("null")) { + return JSONObject.NULL; + } + + /* + * If it might be a number, try converting it. If a number cannot be + * produced, then the value will just be a string. + */ + + char b = string.charAt(0); + if ((b >= '0' && b <= '9') || b == '-') { + try { + if (string.indexOf('.') > -1 || string.indexOf('e') > -1 + || string.indexOf('E') > -1) { + d = Double.valueOf(string); + if (!d.isInfinite() && !d.isNaN()) { + return d; + } + } else { + Long myLong = new Long(string); + if (string.equals(myLong.toString())) { + if (myLong.longValue() == myLong.intValue()) { + return new Integer(myLong.intValue()); + } else { + return myLong; + } + } + } + } catch (Exception ignore) { + } + } + return string; + } + + /** + * Throw an exception if the object is a NaN or infinite number. + * + * @param o + * The object to test. + * @throws JSONException + * If o is a non-finite number. + */ + public static void testValidity(Object o) throws JSONException { + if (o != null) { + if (o instanceof Double) { + if (((Double) o).isInfinite() || ((Double) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } else if (o instanceof Float) { + if (((Float) o).isInfinite() || ((Float) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } + } + } + + /** + * Produce a JSONArray containing the values of the members of this + * JSONObject. + * + * @param names + * A JSONArray containing a list of key strings. This determines + * the sequence of the values in the result. + * @return A JSONArray of values. + * @throws JSONException + * If any of the values are non-finite numbers. + */ + public JSONArray toJSONArray(JSONArray names) throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + JSONArray ja = new JSONArray(); + for (int i = 0; i < names.length(); i += 1) { + ja.put(this.opt(names.getString(i))); + } + return ja; + } + + /** + * Make a JSON text of this JSONObject. For compactness, no whitespace is + * added. If this would not result in a syntactically correct JSON text, + * then null will be returned instead. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with <code>{</code> <small>(left + * brace)</small> and ending with <code>}</code> <small>(right + * brace)</small>. + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONObject. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with <code>{</code> <small>(left + * brace)</small> and ending with <code>}</code> <small>(right + * brace)</small>. + * @throws JSONException + * If the object contains an invalid number. + */ + public String toString(int indentFactor) throws JSONException { + StringWriter w = new StringWriter(); + synchronized (w.getBuffer()) { + return this.write(w, indentFactor, 0).toString(); + } + } + + /** + * Make a JSON text of an Object value. If the object has an + * value.toJSONString() method, then that method will be used to produce the + * JSON text. The method is required to produce a strictly conforming text. + * If the object does not contain a toJSONString method (which is the most + * common case), then a text will be produced by other means. If the value + * is an array or Collection, then a JSONArray will be made from it and its + * toJSONString method will be called. If the value is a MAP, then a + * JSONObject will be made from it and its toJSONString method will be + * called. Otherwise, the value's toString method will be called, and the + * result will be quoted. + * + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @param value + * The value to be serialized. + * @return a printable, displayable, transmittable representation of the + * object, beginning with <code>{</code> <small>(left + * brace)</small> and ending with <code>}</code> <small>(right + * brace)</small>. + * @throws JSONException + * If the value is or contains an invalid number. + */ + public static String valueToString(Object value) throws JSONException { + if (value == null || value.equals(null)) { + return "null"; + } + if (value instanceof JSONString) { + Object object; + try { + object = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + if (object instanceof String) { + return (String) object; + } + throw new JSONException("Bad value from toJSONString: " + object); + } + if (value instanceof Number) { + return numberToString((Number) value); + } + if (value instanceof Boolean || value instanceof JSONObject + || value instanceof JSONArray) { + return value.toString(); + } + if (value instanceof Map) { + return new JSONObject((Map) value).toString(); + } + if (value instanceof Collection) { + return new JSONArray((Collection) value).toString(); + } + if (value.getClass().isArray()) { + return new JSONArray(value).toString(); + } + return quote(value.toString()); + } + + /** + * Wrap an object, if necessary. If the object is null, return the NULL + * object. If it is an array or collection, wrap it in a JSONArray. If it is + * a map, wrap it in a JSONObject. If it is a standard property (Double, + * String, et al) then it is already wrapped. Otherwise, if it comes from + * one of the java packages, turn it into a string. And if it doesn't, try + * to wrap it in a JSONObject. If the wrapping fails, then null is returned. + * + * @param object + * The object to wrap + * @return The wrapped value + */ + public static Object wrap(Object object) { + try { + if (object == null) { + return NULL; + } + if (object instanceof JSONObject || object instanceof JSONArray + || NULL.equals(object) || object instanceof JSONString + || object instanceof Byte || object instanceof Character + || object instanceof Short || object instanceof Integer + || object instanceof Long || object instanceof Boolean + || object instanceof Float || object instanceof Double + || object instanceof String) { + return object; + } + + if (object instanceof Collection) { + return new JSONArray((Collection) object); + } + if (object.getClass().isArray()) { + return new JSONArray(object); + } + if (object instanceof Map) { + return new JSONObject((Map) object); + } + Package objectPackage = object.getClass().getPackage(); + String objectPackageName = objectPackage != null ? objectPackage + .getName() : ""; + if (objectPackageName.startsWith("java.") + || objectPackageName.startsWith("javax.") + || object.getClass().getClassLoader() == null) { + return object.toString(); + } + return new JSONObject(object); + } catch (Exception exception) { + return null; + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + static final Writer writeValue(Writer writer, Object value, + int indentFactor, int indent) throws JSONException, IOException { + if (value == null || value.equals(null)) { + writer.write("null"); + } else if (value instanceof JSONObject) { + ((JSONObject) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONArray) { + ((JSONArray) value).write(writer, indentFactor, indent); + } else if (value instanceof Map) { + new JSONObject((Map) value).write(writer, indentFactor, indent); + } else if (value instanceof Collection) { + new JSONArray((Collection) value).write(writer, indentFactor, + indent); + } else if (value.getClass().isArray()) { + new JSONArray(value).write(writer, indentFactor, indent); + } else if (value instanceof Number) { + writer.write(numberToString((Number) value)); + } else if (value instanceof Boolean) { + writer.write(value.toString()); + } else if (value instanceof JSONString) { + Object o; + try { + o = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + writer.write(o != null ? o.toString() : quote(value.toString())); + } else { + quote(value.toString(), writer); + } + return writer; + } + + static final void indent(Writer writer, int indent) throws IOException { + for (int i = 0; i < indent; i += 1) { + writer.write(' '); + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + * <p> + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + final int length = this.length(); + Iterator keys = this.keys(); + writer.write('{'); + + if (length == 1) { + Object key = keys.next(); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + while (keys.hasNext()) { + Object key = keys.next(); + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, newindent); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, + newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, indent); + } + writer.write('}'); + return writer; + } catch (IOException exception) { + throw new JSONException(exception); + } + } +} diff --git a/eurilys4-service/src/java/jsonlib/JSONString.java b/eurilys4-service/src/java/jsonlib/JSONString.java new file mode 100644 index 00000000..1f2d77dd --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/JSONString.java @@ -0,0 +1,18 @@ +package org.json; +/** + * The <code>JSONString</code> interface allows a <code>toJSONString()</code> + * method so that a class can change the behavior of + * <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>, + * and <code>JSONWriter.value(</code>Object<code>)</code>. The + * <code>toJSONString</code> method will be used instead of the default behavior + * of using the Object's <code>toString()</code> method and quoting the result. + */ +public interface JSONString { + /** + * The <code>toJSONString</code> method allows a class to produce its own JSON + * serialization. + * + * @return A strictly syntactically correct JSON text. + */ + public String toJSONString(); +} diff --git a/eurilys4-service/src/java/jsonlib/JSONStringer.java b/eurilys4-service/src/java/jsonlib/JSONStringer.java new file mode 100644 index 00000000..32c9f7f4 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/JSONStringer.java @@ -0,0 +1,78 @@ +package org.json; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.io.StringWriter; + +/** + * JSONStringer provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONStringer can produce one JSON text. + * <p> + * A JSONStringer instance provides a <code>value</code> method for appending + * values to the + * text, and a <code>key</code> + * method for adding keys before values in objects. There are <code>array</code> + * and <code>endArray</code> methods that make and bound array values, and + * <code>object</code> and <code>endObject</code> methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting cascade style. For example, <pre> + * myString = new JSONStringer() + * .object() + * .key("JSON") + * .value("Hello, World!") + * .endObject() + * .toString();</pre> which produces the string <pre> + * {"JSON":"Hello, World!"}</pre> + * <p> + * The first method called must be <code>array</code> or <code>object</code>. + * There are no methods for adding commas or colons. JSONStringer adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + * <p> + * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2008-09-18 + */ +public class JSONStringer extends JSONWriter { + /** + * Make a fresh JSONStringer. It can be used to build one JSON text. + */ + public JSONStringer() { + super(new StringWriter()); + } + + /** + * Return the JSON text. This method is used to obtain the product of the + * JSONStringer instance. It will return <code>null</code> if there was a + * problem in the construction of the JSON text (such as the calls to + * <code>array</code> were not properly balanced with calls to + * <code>endArray</code>). + * @return The JSON text. + */ + public String toString() { + return this.mode == 'd' ? this.writer.toString() : null; + } +} diff --git a/eurilys4-service/src/java/jsonlib/JSONTokener.java b/eurilys4-service/src/java/jsonlib/JSONTokener.java new file mode 100644 index 00000000..13c84f1f --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/JSONTokener.java @@ -0,0 +1,446 @@ +package org.json; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * A JSONTokener takes a source string and extracts characters and tokens from + * it. It is used by the JSONObject and JSONArray constructors to parse + * JSON source strings. + * @author JSON.org + * @version 2012-02-16 + */ +public class JSONTokener { + + private long character; + private boolean eof; + private long index; + private long line; + private char previous; + private Reader reader; + private boolean usePrevious; + + + /** + * Construct a JSONTokener from a Reader. + * + * @param reader A reader. + */ + public JSONTokener(Reader reader) { + this.reader = reader.markSupported() + ? reader + : new BufferedReader(reader); + this.eof = false; + this.usePrevious = false; + this.previous = 0; + this.index = 0; + this.character = 1; + this.line = 1; + } + + + /** + * Construct a JSONTokener from an InputStream. + */ + public JSONTokener(InputStream inputStream) throws JSONException { + this(new InputStreamReader(inputStream)); + } + + + /** + * Construct a JSONTokener from a string. + * + * @param s A source string. + */ + public JSONTokener(String s) { + this(new StringReader(s)); + } + + + /** + * Back up one character. This provides a sort of lookahead capability, + * so that you can test for a digit or letter before attempting to parse + * the next number or identifier. + */ + public void back() throws JSONException { + if (this.usePrevious || this.index <= 0) { + throw new JSONException("Stepping back two steps is not supported"); + } + this.index -= 1; + this.character -= 1; + this.usePrevious = true; + this.eof = false; + } + + + /** + * Get the hex value of a character (base16). + * @param c A character between '0' and '9' or between 'A' and 'F' or + * between 'a' and 'f'. + * @return An int between 0 and 15, or -1 if c was not a hex digit. + */ + public static int dehexchar(char c) { + if (c >= '0' && c <= '9') { + return c - '0'; + } + if (c >= 'A' && c <= 'F') { + return c - ('A' - 10); + } + if (c >= 'a' && c <= 'f') { + return c - ('a' - 10); + } + return -1; + } + + public boolean end() { + return this.eof && !this.usePrevious; + } + + + /** + * Determine if the source string still contains characters that next() + * can consume. + * @return true if not yet at the end of the source. + */ + public boolean more() throws JSONException { + this.next(); + if (this.end()) { + return false; + } + this.back(); + return true; + } + + + /** + * Get the next character in the source string. + * + * @return The next character, or 0 if past the end of the source string. + */ + public char next() throws JSONException { + int c; + if (this.usePrevious) { + this.usePrevious = false; + c = this.previous; + } else { + try { + c = this.reader.read(); + } catch (IOException exception) { + throw new JSONException(exception); + } + + if (c <= 0) { // End of stream + this.eof = true; + c = 0; + } + } + this.index += 1; + if (this.previous == '\r') { + this.line += 1; + this.character = c == '\n' ? 0 : 1; + } else if (c == '\n') { + this.line += 1; + this.character = 0; + } else { + this.character += 1; + } + this.previous = (char) c; + return this.previous; + } + + + /** + * Consume the next character, and check that it matches a specified + * character. + * @param c The character to match. + * @return The character. + * @throws JSONException if the character does not match. + */ + public char next(char c) throws JSONException { + char n = this.next(); + if (n != c) { + throw this.syntaxError("Expected '" + c + "' and instead saw '" + + n + "'"); + } + return n; + } + + + /** + * Get the next n characters. + * + * @param n The number of characters to take. + * @return A string of n characters. + * @throws JSONException + * Substring bounds error if there are not + * n characters remaining in the source string. + */ + public String next(int n) throws JSONException { + if (n == 0) { + return ""; + } + + char[] chars = new char[n]; + int pos = 0; + + while (pos < n) { + chars[pos] = this.next(); + if (this.end()) { + throw this.syntaxError("Substring bounds error"); + } + pos += 1; + } + return new String(chars); + } + + + /** + * Get the next char in the string, skipping whitespace. + * @throws JSONException + * @return A character, or 0 if there are no more characters. + */ + public char nextClean() throws JSONException { + for (;;) { + char c = this.next(); + if (c == 0 || c > ' ') { + return c; + } + } + } + + + /** + * Return the characters up to the next close quote character. + * Backslash processing is done. The formal JSON format does not + * allow strings in single quotes, but an implementation is allowed to + * accept them. + * @param quote The quoting character, either + * <code>"</code> <small>(double quote)</small> or + * <code>'</code> <small>(single quote)</small>. + * @return A String. + * @throws JSONException Unterminated string. + */ + public String nextString(char quote) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + switch (c) { + case 0: + case '\n': + case '\r': + throw this.syntaxError("Unterminated string"); + case '\\': + c = this.next(); + switch (c) { + case 'b': + sb.append('\b'); + break; + case 't': + sb.append('\t'); + break; + case 'n': + sb.append('\n'); + break; + case 'f': + sb.append('\f'); + break; + case 'r': + sb.append('\r'); + break; + case 'u': + sb.append((char)Integer.parseInt(this.next(4), 16)); + break; + case '"': + case '\'': + case '\\': + case '/': + sb.append(c); + break; + default: + throw this.syntaxError("Illegal escape."); + } + break; + default: + if (c == quote) { + return sb.toString(); + } + sb.append(c); + } + } + } + + + /** + * Get the text up but not including the specified character or the + * end of line, whichever comes first. + * @param delimiter A delimiter character. + * @return A string. + */ + public String nextTo(char delimiter) throws JSONException { + StringBuffer sb = new StringBuffer(); + for (;;) { + char c = this.next(); + if (c == delimiter || c == 0 || c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the text up but not including one of the specified delimiter + * characters or the end of line, whichever comes first. + * @param delimiters A set of delimiter characters. + * @return A string, trimmed. + */ + public String nextTo(String delimiters) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + if (delimiters.indexOf(c) >= 0 || c == 0 || + c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the next value. The value can be a Boolean, Double, Integer, + * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. + * @throws JSONException If syntax error. + * + * @return An object. + */ + public Object nextValue() throws JSONException { + char c = this.nextClean(); + String string; + + switch (c) { + case '"': + case '\'': + return this.nextString(c); + case '{': + this.back(); + return new JSONObject(this); + case '[': + this.back(); + return new JSONArray(this); + } + + /* + * Handle unquoted text. This could be the values true, false, or + * null, or it can be a number. An implementation (such as this one) + * is allowed to also accept non-standard forms. + * + * Accumulate characters until we reach the end of the text or a + * formatting character. + */ + + StringBuffer sb = new StringBuffer(); + while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { + sb.append(c); + c = this.next(); + } + this.back(); + + string = sb.toString().trim(); + if ("".equals(string)) { + throw this.syntaxError("Missing value"); + } + return JSONObject.stringToValue(string); + } + + + /** + * Skip characters until the next character is the requested character. + * If the requested character is not found, no characters are skipped. + * @param to A character to skip to. + * @return The requested character, or zero if the requested character + * is not found. + */ + public char skipTo(char to) throws JSONException { + char c; + try { + long startIndex = this.index; + long startCharacter = this.character; + long startLine = this.line; + this.reader.mark(1000000); + do { + c = this.next(); + if (c == 0) { + this.reader.reset(); + this.index = startIndex; + this.character = startCharacter; + this.line = startLine; + return c; + } + } while (c != to); + } catch (IOException exc) { + throw new JSONException(exc); + } + + this.back(); + return c; + } + + + /** + * Make a JSONException to signal a syntax error. + * + * @param message The error message. + * @return A JSONException object, suitable for throwing + */ + public JSONException syntaxError(String message) { + return new JSONException(message + this.toString()); + } + + + /** + * Make a printable string of this JSONTokener. + * + * @return " at {index} [character {character} line {line}]" + */ + public String toString() { + return " at " + this.index + " [character " + this.character + " line " + + this.line + "]"; + } +} diff --git a/eurilys4-service/src/java/jsonlib/JSONWriter.java b/eurilys4-service/src/java/jsonlib/JSONWriter.java new file mode 100644 index 00000000..35b60d90 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/JSONWriter.java @@ -0,0 +1,327 @@ +package org.json; + +import java.io.IOException; +import java.io.Writer; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * JSONWriter provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONWriter can produce one JSON text. + * <p> + * A JSONWriter instance provides a <code>value</code> method for appending + * values to the + * text, and a <code>key</code> + * method for adding keys before values in objects. There are <code>array</code> + * and <code>endArray</code> methods that make and bound array values, and + * <code>object</code> and <code>endObject</code> methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting a cascade style. For example, <pre> + * new JSONWriter(myWriter) + * .object() + * .key("JSON") + * .value("Hello, World!") + * .endObject();</pre> which writes <pre> + * {"JSON":"Hello, World!"}</pre> + * <p> + * The first method called must be <code>array</code> or <code>object</code>. + * There are no methods for adding commas or colons. JSONWriter adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + * <p> + * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2011-11-24 + */ +public class JSONWriter { + private static final int maxdepth = 200; + + /** + * The comma flag determines if a comma should be output before the next + * value. + */ + private boolean comma; + + /** + * The current mode. Values: + * 'a' (array), + * 'd' (done), + * 'i' (initial), + * 'k' (key), + * 'o' (object). + */ + protected char mode; + + /** + * The object/array stack. + */ + private final JSONObject stack[]; + + /** + * The stack top index. A value of 0 indicates that the stack is empty. + */ + private int top; + + /** + * The writer that will receive the output. + */ + protected Writer writer; + + /** + * Make a fresh JSONWriter. It can be used to build one JSON text. + */ + public JSONWriter(Writer w) { + this.comma = false; + this.mode = 'i'; + this.stack = new JSONObject[maxdepth]; + this.top = 0; + this.writer = w; + } + + /** + * Append a value. + * @param string A string value. + * @return this + * @throws JSONException If the value is out of sequence. + */ + private JSONWriter append(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null pointer"); + } + if (this.mode == 'o' || this.mode == 'a') { + try { + if (this.comma && this.mode == 'a') { + this.writer.write(','); + } + this.writer.write(string); + } catch (IOException e) { + throw new JSONException(e); + } + if (this.mode == 'o') { + this.mode = 'k'; + } + this.comma = true; + return this; + } + throw new JSONException("Value out of sequence."); + } + + /** + * Begin appending a new array. All values until the balancing + * <code>endArray</code> will be appended to this array. The + * <code>endArray</code> method must be called to mark the array's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter array() throws JSONException { + if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { + this.push(null); + this.append("["); + this.comma = false; + return this; + } + throw new JSONException("Misplaced array."); + } + + /** + * End something. + * @param mode Mode + * @param c Closing character + * @return this + * @throws JSONException If unbalanced. + */ + private JSONWriter end(char mode, char c) throws JSONException { + if (this.mode != mode) { + throw new JSONException(mode == 'a' + ? "Misplaced endArray." + : "Misplaced endObject."); + } + this.pop(mode); + try { + this.writer.write(c); + } catch (IOException e) { + throw new JSONException(e); + } + this.comma = true; + return this; + } + + /** + * End an array. This method most be called to balance calls to + * <code>array</code>. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endArray() throws JSONException { + return this.end('a', ']'); + } + + /** + * End an object. This method most be called to balance calls to + * <code>object</code>. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endObject() throws JSONException { + return this.end('k', '}'); + } + + /** + * Append a key. The key will be associated with the next value. In an + * object, every value must be preceded by a key. + * @param string A key string. + * @return this + * @throws JSONException If the key is out of place. For example, keys + * do not belong in arrays or if the key is null. + */ + public JSONWriter key(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null key."); + } + if (this.mode == 'k') { + try { + this.stack[this.top - 1].putOnce(string, Boolean.TRUE); + if (this.comma) { + this.writer.write(','); + } + this.writer.write(JSONObject.quote(string)); + this.writer.write(':'); + this.comma = false; + this.mode = 'o'; + return this; + } catch (IOException e) { + throw new JSONException(e); + } + } + throw new JSONException("Misplaced key."); + } + + + /** + * Begin appending a new object. All keys and values until the balancing + * <code>endObject</code> will be appended to this object. The + * <code>endObject</code> method must be called to mark the object's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter object() throws JSONException { + if (this.mode == 'i') { + this.mode = 'o'; + } + if (this.mode == 'o' || this.mode == 'a') { + this.append("{"); + this.push(new JSONObject()); + this.comma = false; + return this; + } + throw new JSONException("Misplaced object."); + + } + + + /** + * Pop an array or object scope. + * @param c The scope to close. + * @throws JSONException If nesting is wrong. + */ + private void pop(char c) throws JSONException { + if (this.top <= 0) { + throw new JSONException("Nesting error."); + } + char m = this.stack[this.top - 1] == null ? 'a' : 'k'; + if (m != c) { + throw new JSONException("Nesting error."); + } + this.top -= 1; + this.mode = this.top == 0 + ? 'd' + : this.stack[this.top - 1] == null + ? 'a' + : 'k'; + } + + /** + * Push an array or object scope. + * @param c The scope to open. + * @throws JSONException If nesting is too deep. + */ + private void push(JSONObject jo) throws JSONException { + if (this.top >= maxdepth) { + throw new JSONException("Nesting too deep."); + } + this.stack[this.top] = jo; + this.mode = jo == null ? 'a' : 'k'; + this.top += 1; + } + + + /** + * Append either the value <code>true</code> or the value + * <code>false</code>. + * @param b A boolean. + * @return this + * @throws JSONException + */ + public JSONWriter value(boolean b) throws JSONException { + return this.append(b ? "true" : "false"); + } + + /** + * Append a double value. + * @param d A double. + * @return this + * @throws JSONException If the number is not finite. + */ + public JSONWriter value(double d) throws JSONException { + return this.value(new Double(d)); + } + + /** + * Append a long value. + * @param l A long. + * @return this + * @throws JSONException + */ + public JSONWriter value(long l) throws JSONException { + return this.append(Long.toString(l)); + } + + + /** + * Append an object value. + * @param object The object to append. It can be null, or a Boolean, Number, + * String, JSONObject, or JSONArray, or an object that implements JSONString. + * @return this + * @throws JSONException If the value is out of sequence. + */ + public JSONWriter value(Object object) throws JSONException { + return this.append(JSONObject.valueToString(object)); + } +} diff --git a/eurilys4-service/src/java/jsonlib/Kim.java b/eurilys4-service/src/java/jsonlib/Kim.java new file mode 100644 index 00000000..d4770b56 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/Kim.java @@ -0,0 +1,373 @@ +package org.json; + + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * Kim makes immutable eight bit Unicode strings. If the MSB of a byte is set, + * then the next byte is a continuation byte. The last byte of a character + * never has the MSB reset. Every byte that is not the last byte has the MSB + * set. Kim stands for "Keep it minimal". A Unicode character is never longer + * than 3 bytes. Every byte contributes 7 bits to the character. ASCII is + * unmodified. + * + * Kim UTF-8 + * one byte U+007F U+007F + * two bytes U+3FFF U+07FF + * three bytes U+10FFF U+FFFF + * four bytes U+10FFFF + * + * Characters in the ranges U+0800..U+3FFF and U+10000..U+10FFFF will be one + * byte smaller when encoded in Kim compared to UTF-8. + * + * Kim is beneficial when using scripts such as Old South Arabian, Aramaic, + * Avestan, Balinese, Batak, Bopomofo, Buginese, Buhid, Carian, Cherokee, + * Coptic, Cyrillic, Deseret, Egyptian Hieroglyphs, Ethiopic, Georgian, + * Glagolitic, Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi, + * Kannada, Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu, Lycian, Lydian, + * Malayalam, Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue, + * Ol Chiki, Old Turkic, Oriya, Osmanya, Pahlavi, Parthian, Phags-Pa, + * Phoenician, Samaritan, Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa, + * Takri, Tai Le, Tai Tham, Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS. + * + * A kim object can be constructed from an ordinary UTF-16 string, or from a + * byte array. A kim object can produce a UTF-16 string. + * + * As with UTF-8, it is possible to detect character boundaries within a byte + * sequence. UTF-8 is one of the world's great inventions. While Kim is more + * efficient, it is not clear that it is worth the expense of transition. + * + * @version 2013-04-18 + */ +public class Kim { + + /** + * The byte array containing the kim's content. + */ + private byte[] bytes = null; + + /** + * The kim's hashcode, conforming to Java's hashcode conventions. + */ + private int hashcode = 0; + + /** + * The number of bytes in the kim. The number of bytes can be as much as + * three times the number of characters. + */ + public int length = 0; + + /** + * The memoization of toString(). + */ + private String string = null; + + /** + * Make a kim from a portion of a byte array. + * + * @param bytes + * A byte array. + * @param from + * The index of the first byte. + * @param thru + * The index of the last byte plus one. + */ + public Kim(byte[] bytes, int from, int thru) { + +// As the bytes are copied into the new kim, a hashcode is computed using a +// modified Fletcher code. + + int sum = 1; + int value; + this.hashcode = 0; + this.length = thru - from; + if (this.length > 0) { + this.bytes = new byte[this.length]; + for (int at = 0; at < this.length; at += 1) { + value = (int) bytes[at + from] & 0xFF; + sum += value; + this.hashcode += sum; + this.bytes[at] = (byte) value; + } + this.hashcode += sum << 16; + } + } + + /** + * Make a kim from a byte array. + * + * @param bytes + * The byte array. + * @param length + * The number of bytes. + */ + public Kim(byte[] bytes, int length) { + this(bytes, 0, length); + } + + /** + * Make a new kim from a substring of an existing kim. The coordinates are + * in byte units, not character units. + * + * @param kim + * The source of bytes. + * @param from + * The point at which to take bytes. + * @param thru + * The point at which to stop taking bytes. + * @return the substring + */ + public Kim(Kim kim, int from, int thru) { + this(kim.bytes, from, thru); + } + + /** + * Make a kim from a string. + * + * @param string + * The string. + * @throws JSONException + * if surrogate pair mismatch. + */ + public Kim(String string) throws JSONException { + int stringLength = string.length(); + this.hashcode = 0; + this.length = 0; + +// First pass: Determine the length of the kim, allowing for the UTF-16 +// to UTF-32 conversion, and then the UTF-32 to Kim conversion. + + if (stringLength > 0) { + for (int i = 0; i < stringLength; i += 1) { + int c = string.charAt(i); + if (c <= 0x7F) { + this.length += 1; + } else if (c <= 0x3FFF) { + this.length += 2; + } else { + if (c >= 0xD800 && c <= 0xDFFF) { + i += 1; + int d = string.charAt(i); + if (c > 0xDBFF || d < 0xDC00 || d > 0xDFFF) { + throw new JSONException("Bad UTF16"); + } + } + this.length += 3; + } + } + +// Second pass: Allocate a byte array and fill that array with the conversion +// while computing the hashcode. + + this.bytes = new byte[length]; + int at = 0; + int b; + int sum = 1; + for (int i = 0; i < stringLength; i += 1) { + int character = string.charAt(i); + if (character <= 0x7F) { + bytes[at] = (byte) character; + sum += character; + this.hashcode += sum; + at += 1; + } else if (character <= 0x3FFF) { + b = 0x80 | (character >>> 7); + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + b = character & 0x7F; + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + } else { + if (character >= 0xD800 && character <= 0xDBFF) { + i += 1; + character = (((character & 0x3FF) << 10) | (string + .charAt(i) & 0x3FF)) + 65536; + } + b = 0x80 | (character >>> 14); + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + b = 0x80 | ((character >>> 7) & 0xFF); + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + b = character & 0x7F; + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + } + } + this.hashcode += sum << 16; + } + } + + /** + * Returns the character at the specified index. The index refers to byte + * values and ranges from 0 to length - 1. The index of the next character + * is at index + Kim.characterSize(kim.characterAt(index)). + * + * @param at + * the index of the char value. The first character is at 0. + * @returns a Unicode character between 0 and 0x10FFFF. + * @throws JSONException + * if at does not point to a valid character. + */ + public int characterAt(int at) throws JSONException { + int c = get(at); + if ((c & 0x80) == 0) { + return c; + } + int character; + int c1 = get(at + 1); + if ((c1 & 0x80) == 0) { + character = ((c & 0x7F) << 7) | c1; + if (character > 0x7F) { + return character; + } + } else { + int c2 = get(at + 2); + character = ((c & 0x7F) << 14) | ((c1 & 0x7F) << 7) | c2; + if ((c2 & 0x80) == 0 && character > 0x3FFF && character <= 0x10FFFF + && (character < 0xD800 || character > 0xDFFF)) { + return character; + } + } + throw new JSONException("Bad character at " + at); + } + + /** + * Returns the number of bytes needed to contain the character in Kim + * format. + * + * @param character + * a Unicode character between 0 and 0x10FFFF. + * @return 1, 2, or 3 + * @throws JSONException + * if the character is not representable in a kim. + */ + public static int characterSize(int character) throws JSONException { + if (character < 0 || character > 0x10FFFF) { + throw new JSONException("Bad character " + character); + } + return character <= 0x7F ? 1 : character <= 0x3FFF ? 2 : 3; + } + + /** + * Copy the contents of this kim to a byte array. + * + * @param bytes + * A byte array of sufficient size. + * @param at + * The position within the byte array to take the byes. + * @return The position immediately after the copy. + */ + public int copy(byte[] bytes, int at) { + System.arraycopy(this.bytes, 0, bytes, at, this.length); + return at + this.length; + } + + /** + * Two kim objects containing exactly the same bytes in the same order are + * equal to each other. + * + * @param obj + * the other kim with which to compare. + * @returns true if this and obj are both kim objects containing identical + * byte sequences. + */ + public boolean equals(Object obj) { + if (!(obj instanceof Kim)) { + return false; + } + Kim that = (Kim) obj; + if (this == that) { + return true; + } + if (this.hashcode != that.hashcode) { + return false; + } + return java.util.Arrays.equals(this.bytes, that.bytes); + } + + /** + * Get a byte from a kim. + * @param at + * The position of the byte. The first byte is at 0. + * @return The byte. + * @throws JSONException + * if there is no byte at that position. + */ + public int get(int at) throws JSONException { + if (at < 0 || at > this.length) { + throw new JSONException("Bad character at " + at); + } + return ((int) this.bytes[at]) & 0xFF; + } + + /** + * Returns a hash code value for the kim. + */ + public int hashCode() { + return this.hashcode; + } + + /** + * Produce a UTF-16 String from this kim. The number of codepoints in the + * string will not be greater than the number of bytes in the kim, although + * it could be less. + * + * @return The string. A kim memoizes its string representation. + * @throws JSONException + * if the kim is not valid. + */ + public String toString() throws JSONException { + if (this.string == null) { + int c; + int length = 0; + char chars[] = new char[this.length]; + for (int at = 0; at < this.length; at += characterSize(c)) { + c = this.characterAt(at); + if (c < 0x10000) { + chars[length] = (char) c; + length += 1; + } else { + chars[length] = (char) (0xD800 | ((c - 0x10000) >>> 10)); + length += 1; + chars[length] = (char) (0xDC00 | (c & 0x03FF)); + length += 1; + } + } + this.string = new String(chars, 0, length); + } + return this.string; + } +} diff --git a/eurilys4-service/src/java/jsonlib/README b/eurilys4-service/src/java/jsonlib/README new file mode 100644 index 00000000..b77c71a2 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/README @@ -0,0 +1,68 @@ +JSON in Java [package org.json] + +Douglas Crockford +douglas@crockford.com + +2011-02-02 + + +JSON is a light-weight, language independent, data interchange format. +See http://www.JSON.org/ + +The files in this package implement JSON encoders/decoders in Java. +It also includes the capability to convert between JSON and XML, HTTP +headers, Cookies, and CDL. + +This is a reference implementation. There is a large number of JSON packages +in Java. Perhaps someday the Java community will standardize on one. Until +then, choose carefully. + +The license includes this restriction: "The software shall be used for good, +not evil." If your conscience cannot live with that, then choose a different +package. + +The package compiles on Java 1.2 thru Java 1.4. + + +JSONObject.java: The JSONObject can parse text from a String or a JSONTokener +to produce a map-like object. The object provides methods for manipulating its +contents, and for producing a JSON compliant object serialization. + +JSONArray.java: The JSONObject can parse text from a String or a JSONTokener +to produce a vector-like object. The object provides methods for manipulating +its contents, and for producing a JSON compliant array serialization. + +JSONTokener.java: The JSONTokener breaks a text into a sequence of individual +tokens. It can be constructed from a String, Reader, or InputStream. + +JSONException.java: The JSONException is the standard exception type thrown +by this package. + + +JSONString.java: The JSONString interface requires a toJSONString method, +allowing an object to provide its own serialization. + +JSONStringer.java: The JSONStringer provides a convenient facility for +building JSON strings. + +JSONWriter.java: The JSONWriter provides a convenient facility for building +JSON text through a writer. + + +CDL.java: CDL provides support for converting between JSON and comma +delimited lists. + +Cookie.java: Cookie provides support for converting between JSON and cookies. + +CookieList.java: CookieList provides support for converting between JSON and +cookie lists. + +HTTP.java: HTTP provides support for converting between JSON and HTTP headers. + +HTTPTokener.java: HTTPTokener extends JSONTokener for parsing HTTP headers. + +XML.java: XML provides support for converting between JSON and XML. + +JSONML.java: JSONML provides support for converting between JSONML and XML. + +XMLTokener.java: XMLTokener extends JSONTokener for parsing XML text. diff --git a/eurilys4-service/src/java/jsonlib/XML.java b/eurilys4-service/src/java/jsonlib/XML.java new file mode 100644 index 00000000..d49784d6 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/XML.java @@ -0,0 +1,508 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.util.Iterator; + + +/** + * This provides static methods to convert an XML text into a JSONObject, + * and to covert a JSONObject into an XML text. + * @author JSON.org + * @version 2012-10-26 + */ +public class XML { + + /** The Character '&'. */ + public static final Character AMP = new Character('&'); + + /** The Character '''. */ + public static final Character APOS = new Character('\''); + + /** The Character '!'. */ + public static final Character BANG = new Character('!'); + + /** The Character '='. */ + public static final Character EQ = new Character('='); + + /** The Character '>'. */ + public static final Character GT = new Character('>'); + + /** The Character '<'. */ + public static final Character LT = new Character('<'); + + /** The Character '?'. */ + public static final Character QUEST = new Character('?'); + + /** The Character '"'. */ + public static final Character QUOT = new Character('"'); + + /** The Character '/'. */ + public static final Character SLASH = new Character('/'); + + /** + * Replace special characters with XML escapes: + * <pre> + * & <small>(ampersand)</small> is replaced by &amp; + * < <small>(less than)</small> is replaced by &lt; + * > <small>(greater than)</small> is replaced by &gt; + * " <small>(double quote)</small> is replaced by &quot; + * </pre> + * @param string The string to be escaped. + * @return The escaped string. + */ + public static String escape(String string) { + StringBuffer sb = new StringBuffer(); + for (int i = 0, length = string.length(); i < length; i++) { + char c = string.charAt(i); + switch (c) { + case '&': + sb.append("&"); + break; + case '<': + sb.append("<"); + break; + case '>': + sb.append(">"); + break; + case '"': + sb.append("""); + break; + case '\'': + sb.append("'"); + break; + default: + sb.append(c); + } + } + return sb.toString(); + } + + /** + * Throw an exception if the string contains whitespace. + * Whitespace is not allowed in tagNames and attributes. + * @param string + * @throws JSONException + */ + public static void noSpace(String string) throws JSONException { + int i, length = string.length(); + if (length == 0) { + throw new JSONException("Empty string."); + } + for (i = 0; i < length; i += 1) { + if (Character.isWhitespace(string.charAt(i))) { + throw new JSONException("'" + string + + "' contains a space character."); + } + } + } + + /** + * Scan the content following the named tag, attaching it to the context. + * @param x The XMLTokener containing the source string. + * @param context The JSONObject that will include the new material. + * @param name The tag name. + * @return true if the close tag is processed. + * @throws JSONException + */ + private static boolean parse(XMLTokener x, JSONObject context, + String name) throws JSONException { + char c; + int i; + JSONObject jsonobject = null; + String string; + String tagName; + Object token; + +// Test for and skip past these forms: +// <!-- ... --> +// <! ... > +// <![ ... ]]> +// <? ... ?> +// Report errors for these forms: +// <> +// <= +// << + + token = x.nextToken(); + +// <! + + if (token == BANG) { + c = x.next(); + if (c == '-') { + if (x.next() == '-') { + x.skipPast("-->"); + return false; + } + x.back(); + } else if (c == '[') { + token = x.nextToken(); + if ("CDATA".equals(token)) { + if (x.next() == '[') { + string = x.nextCDATA(); + if (string.length() > 0) { + context.accumulate("content", string); + } + return false; + } + } + throw x.syntaxError("Expected 'CDATA['"); + } + i = 1; + do { + token = x.nextMeta(); + if (token == null) { + throw x.syntaxError("Missing '>' after '<!'."); + } else if (token == LT) { + i += 1; + } else if (token == GT) { + i -= 1; + } + } while (i > 0); + return false; + } else if (token == QUEST) { + +// <? + + x.skipPast("?>"); + return false; + } else if (token == SLASH) { + +// Close tag </ + + token = x.nextToken(); + if (name == null) { + throw x.syntaxError("Mismatched close tag " + token); + } + if (!token.equals(name)) { + throw x.syntaxError("Mismatched " + name + " and " + token); + } + if (x.nextToken() != GT) { + throw x.syntaxError("Misshaped close tag"); + } + return true; + + } else if (token instanceof Character) { + throw x.syntaxError("Misshaped tag"); + +// Open tag < + + } else { + tagName = (String)token; + token = null; + jsonobject = new JSONObject(); + for (;;) { + if (token == null) { + token = x.nextToken(); + } + +// attribute = value + + if (token instanceof String) { + string = (String)token; + token = x.nextToken(); + if (token == EQ) { + token = x.nextToken(); + if (!(token instanceof String)) { + throw x.syntaxError("Missing value"); + } + jsonobject.accumulate(string, + XML.stringToValue((String)token)); + token = null; + } else { + jsonobject.accumulate(string, ""); + } + +// Empty tag <.../> + + } else if (token == SLASH) { + if (x.nextToken() != GT) { + throw x.syntaxError("Misshaped tag"); + } + if (jsonobject.length() > 0) { + context.accumulate(tagName, jsonobject); + } else { + context.accumulate(tagName, ""); + } + return false; + +// Content, between <...> and </...> + + } else if (token == GT) { + for (;;) { + token = x.nextContent(); + if (token == null) { + if (tagName != null) { + throw x.syntaxError("Unclosed tag " + tagName); + } + return false; + } else if (token instanceof String) { + string = (String)token; + if (string.length() > 0) { + jsonobject.accumulate("content", + XML.stringToValue(string)); + } + +// Nested element + + } else if (token == LT) { + if (parse(x, jsonobject, tagName)) { + if (jsonobject.length() == 0) { + context.accumulate(tagName, ""); + } else if (jsonobject.length() == 1 && + jsonobject.opt("content") != null) { + context.accumulate(tagName, + jsonobject.opt("content")); + } else { + context.accumulate(tagName, jsonobject); + } + return false; + } + } + } + } else { + throw x.syntaxError("Misshaped tag"); + } + } + } + } + + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. This is much less ambitious than + * JSONObject.stringToValue, especially because it does not attempt to + * convert plus forms, octal forms, hex forms, or E forms lacking decimal + * points. + * @param string A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + if ("".equals(string)) { + return string; + } + if ("true".equalsIgnoreCase(string)) { + return Boolean.TRUE; + } + if ("false".equalsIgnoreCase(string)) { + return Boolean.FALSE; + } + if ("null".equalsIgnoreCase(string)) { + return JSONObject.NULL; + } + if ("0".equals(string)) { + return new Integer(0); + } + +// If it might be a number, try converting it. If that doesn't work, +// return the string. + + try { + char initial = string.charAt(0); + boolean negative = false; + if (initial == '-') { + initial = string.charAt(1); + negative = true; + } + if (initial == '0' && string.charAt(negative ? 2 : 1) == '0') { + return string; + } + if ((initial >= '0' && initial <= '9')) { + if (string.indexOf('.') >= 0) { + return Double.valueOf(string); + } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) { + Long myLong = new Long(string); + if (myLong.longValue() == myLong.intValue()) { + return new Integer(myLong.intValue()); + } else { + return myLong; + } + } + } + } catch (Exception ignore) { + } + return string; + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONObject. Some information may be lost in this transformation + * because JSON is a data format and XML is a document format. XML uses + * elements, attributes, and content text, while JSON uses unordered + * collections of name/value pairs and arrays of values. JSON does not + * does not like to distinguish between elements and attributes. + * Sequences of similar elements are represented as JSONArrays. Content + * text may be placed in a "content" member. Comments, prologs, DTDs, and + * <code><[ [ ]]></code> are ignored. + * @param string The source string. + * @return A JSONObject containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + JSONObject jo = new JSONObject(); + XMLTokener x = new XMLTokener(string); + while (x.more() && x.skipPast("<")) { + parse(x, jo, null); + } + return jo; + } + + + /** + * Convert a JSONObject into a well-formed, element-normal XML string. + * @param object A JSONObject. + * @return A string. + * @throws JSONException + */ + public static String toString(Object object) throws JSONException { + return toString(object, null); + } + + + /** + * Convert a JSONObject into a well-formed, element-normal XML string. + * @param object A JSONObject. + * @param tagName The optional name of the enclosing tag. + * @return A string. + * @throws JSONException + */ + public static String toString(Object object, String tagName) + throws JSONException { + StringBuffer sb = new StringBuffer(); + int i; + JSONArray ja; + JSONObject jo; + String key; + Iterator keys; + int length; + String string; + Object value; + if (object instanceof JSONObject) { + +// Emit <tagName> + + if (tagName != null) { + sb.append('<'); + sb.append(tagName); + sb.append('>'); + } + +// Loop thru the keys. + + jo = (JSONObject)object; + keys = jo.keys(); + while (keys.hasNext()) { + key = keys.next().toString(); + value = jo.opt(key); + if (value == null) { + value = ""; + } + if (value instanceof String) { + string = (String)value; + } else { + string = null; + } + +// Emit content in body + + if ("content".equals(key)) { + if (value instanceof JSONArray) { + ja = (JSONArray)value; + length = ja.length(); + for (i = 0; i < length; i += 1) { + if (i > 0) { + sb.append('\n'); + } + sb.append(escape(ja.get(i).toString())); + } + } else { + sb.append(escape(value.toString())); + } + +// Emit an array of similar keys + + } else if (value instanceof JSONArray) { + ja = (JSONArray)value; + length = ja.length(); + for (i = 0; i < length; i += 1) { + value = ja.get(i); + if (value instanceof JSONArray) { + sb.append('<'); + sb.append(key); + sb.append('>'); + sb.append(toString(value)); + sb.append("</"); + sb.append(key); + sb.append('>'); + } else { + sb.append(toString(value, key)); + } + } + } else if ("".equals(value)) { + sb.append('<'); + sb.append(key); + sb.append("/>"); + +// Emit a new tag <k> + + } else { + sb.append(toString(value, key)); + } + } + if (tagName != null) { + +// Emit the </tagname> close tag + + sb.append("</"); + sb.append(tagName); + sb.append('>'); + } + return sb.toString(); + +// XML does not have good support for arrays. If an array appears in a place +// where XML is lacking, synthesize an <array> element. + + } else { + if (object.getClass().isArray()) { + object = new JSONArray(object); + } + if (object instanceof JSONArray) { + ja = (JSONArray)object; + length = ja.length(); + for (i = 0; i < length; i += 1) { + sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName)); + } + return sb.toString(); + } else { + string = (object == null) ? "null" : escape(object.toString()); + return (tagName == null) ? "\"" + string + "\"" : + (string.length() == 0) ? "<" + tagName + "/>" : + "<" + tagName + ">" + string + "</" + tagName + ">"; + } + } + } +} diff --git a/eurilys4-service/src/java/jsonlib/XMLTokener.java b/eurilys4-service/src/java/jsonlib/XMLTokener.java new file mode 100644 index 00000000..be15ebeb --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/XMLTokener.java @@ -0,0 +1,365 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * The XMLTokener extends the JSONTokener to provide additional methods + * for the parsing of XML texts. + * @author JSON.org + * @version 2012-11-13 + */ +public class XMLTokener extends JSONTokener { + + + /** The table of entity values. It initially contains Character values for + * amp, apos, gt, lt, quot. + */ + public static final java.util.HashMap entity; + + static { + entity = new java.util.HashMap(8); + entity.put("amp", XML.AMP); + entity.put("apos", XML.APOS); + entity.put("gt", XML.GT); + entity.put("lt", XML.LT); + entity.put("quot", XML.QUOT); + } + + /** + * Construct an XMLTokener from a string. + * @param s A source string. + */ + public XMLTokener(String s) { + super(s); + } + + /** + * Get the text in the CDATA block. + * @return The string up to the <code>]]></code>. + * @throws JSONException If the <code>]]></code> is not found. + */ + public String nextCDATA() throws JSONException { + char c; + int i; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = next(); + if (end()) { + throw syntaxError("Unclosed CDATA"); + } + sb.append(c); + i = sb.length() - 3; + if (i >= 0 && sb.charAt(i) == ']' && + sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') { + sb.setLength(i); + return sb.toString(); + } + } + } + + + /** + * Get the next XML outer token, trimming whitespace. There are two kinds + * of tokens: the '<' character which begins a markup tag, and the content + * text between markup tags. + * + * @return A string, or a '<' Character, or null if there is no more + * source text. + * @throws JSONException + */ + public Object nextContent() throws JSONException { + char c; + StringBuffer sb; + do { + c = next(); + } while (Character.isWhitespace(c)); + if (c == 0) { + return null; + } + if (c == '<') { + return XML.LT; + } + sb = new StringBuffer(); + for (;;) { + if (c == '<' || c == 0) { + back(); + return sb.toString().trim(); + } + if (c == '&') { + sb.append(nextEntity(c)); + } else { + sb.append(c); + } + c = next(); + } + } + + + /** + * Return the next entity. These entities are translated to Characters: + * <code>& ' > < "</code>. + * @param ampersand An ampersand character. + * @return A Character or an entity String if the entity is not recognized. + * @throws JSONException If missing ';' in XML entity. + */ + public Object nextEntity(char ampersand) throws JSONException { + StringBuffer sb = new StringBuffer(); + for (;;) { + char c = next(); + if (Character.isLetterOrDigit(c) || c == '#') { + sb.append(Character.toLowerCase(c)); + } else if (c == ';') { + break; + } else { + throw syntaxError("Missing ';' in XML entity: &" + sb); + } + } + String string = sb.toString(); + Object object = entity.get(string); + return object != null ? object : ampersand + string + ";"; + } + + + /** + * Returns the next XML meta token. This is used for skipping over <!...> + * and <?...?> structures. + * @return Syntax characters (<code>< > / = ! ?</code>) are returned as + * Character, and strings and names are returned as Boolean. We don't care + * what the values actually are. + * @throws JSONException If a string is not properly closed or if the XML + * is badly structured. + */ + public Object nextMeta() throws JSONException { + char c; + char q; + do { + c = next(); + } while (Character.isWhitespace(c)); + switch (c) { + case 0: + throw syntaxError("Misshaped meta tag"); + case '<': + return XML.LT; + case '>': + return XML.GT; + case '/': + return XML.SLASH; + case '=': + return XML.EQ; + case '!': + return XML.BANG; + case '?': + return XML.QUEST; + case '"': + case '\'': + q = c; + for (;;) { + c = next(); + if (c == 0) { + throw syntaxError("Unterminated string"); + } + if (c == q) { + return Boolean.TRUE; + } + } + default: + for (;;) { + c = next(); + if (Character.isWhitespace(c)) { + return Boolean.TRUE; + } + switch (c) { + case 0: + case '<': + case '>': + case '/': + case '=': + case '!': + case '?': + case '"': + case '\'': + back(); + return Boolean.TRUE; + } + } + } + } + + + /** + * Get the next XML Token. These tokens are found inside of angle + * brackets. It may be one of these characters: <code>/ > = ! ?</code> or it + * may be a string wrapped in single quotes or double quotes, or it may be a + * name. + * @return a String or a Character. + * @throws JSONException If the XML is not well formed. + */ + public Object nextToken() throws JSONException { + char c; + char q; + StringBuffer sb; + do { + c = next(); + } while (Character.isWhitespace(c)); + switch (c) { + case 0: + throw syntaxError("Misshaped element"); + case '<': + throw syntaxError("Misplaced '<'"); + case '>': + return XML.GT; + case '/': + return XML.SLASH; + case '=': + return XML.EQ; + case '!': + return XML.BANG; + case '?': + return XML.QUEST; + +// Quoted string + + case '"': + case '\'': + q = c; + sb = new StringBuffer(); + for (;;) { + c = next(); + if (c == 0) { + throw syntaxError("Unterminated string"); + } + if (c == q) { + return sb.toString(); + } + if (c == '&') { + sb.append(nextEntity(c)); + } else { + sb.append(c); + } + } + default: + +// Name + + sb = new StringBuffer(); + for (;;) { + sb.append(c); + c = next(); + if (Character.isWhitespace(c)) { + return sb.toString(); + } + switch (c) { + case 0: + return sb.toString(); + case '>': + case '/': + case '=': + case '!': + case '?': + case '[': + case ']': + back(); + return sb.toString(); + case '<': + case '"': + case '\'': + throw syntaxError("Bad character in a name"); + } + } + } + } + + + /** + * Skip characters until past the requested string. + * If it is not found, we are left at the end of the source with a result of false. + * @param to A string to skip past. + * @throws JSONException + */ + public boolean skipPast(String to) throws JSONException { + boolean b; + char c; + int i; + int j; + int offset = 0; + int length = to.length(); + char[] circle = new char[length]; + + /* + * First fill the circle buffer with as many characters as are in the + * to string. If we reach an early end, bail. + */ + + for (i = 0; i < length; i += 1) { + c = next(); + if (c == 0) { + return false; + } + circle[i] = c; + } + + /* We will loop, possibly for all of the remaining characters. */ + + for (;;) { + j = offset; + b = true; + + /* Compare the circle buffer with the to string. */ + + for (i = 0; i < length; i += 1) { + if (circle[j] != to.charAt(i)) { + b = false; + break; + } + j += 1; + if (j >= length) { + j -= length; + } + } + + /* If we exit the loop with b intact, then victory is ours. */ + + if (b) { + return true; + } + + /* Get the next character. If there isn't one, then defeat is ours. */ + + c = next(); + if (c == 0) { + return false; + } + /* + * Shove the character in the circle buffer and advance the + * circle offset. The offset is mod n. + */ + circle[offset] = c; + offset += 1; + if (offset >= length) { + offset -= length; + } + } + } +} diff --git a/eurilys4-service/src/java/jsonlib/zip/BitInputStream.java b/eurilys4-service/src/java/jsonlib/zip/BitInputStream.java new file mode 100644 index 00000000..7864ce15 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/BitInputStream.java @@ -0,0 +1,169 @@ +package org.json.zip; + +import java.io.IOException; +import java.io.InputStream; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * This is a big endian bit reader. It reads its bits from an InputStream. + * + * @version 2013-04-18 + * + */ +public class BitInputStream implements BitReader { + /** + * 2^n - 1 + */ + static final int[] mask = { 0, 1, 3, 7, 15, 31, 63, 127, 255 }; + + /** + * The number of bits remaining in the current byte. + */ + private int available = 0; + + /** + * Up to a byte's worth of unread bits. + */ + private int unread = 0; + + /** + * The source of the bits. + */ + private InputStream in; + + /** + * The number of bits read so far. This is used in padding. + */ + private long nrBits = 0; + + /** + * Make a BitReader from an InputStream. The BitReader will take bytes from + * the InputStream and unpack them into bits. + * + * @param in + * An InputStream. + */ + public BitInputStream(InputStream in) { + this.in = in; + } + + /** + * Make a BitReader. The first byte is passed in explicitly, the remaining + * bytes are obtained from the InputStream. This makes it possible to look + * at the first byte of a stream before deciding that it should be read as + * bits. + * + * @param in + * An InputStream + * @param firstByte + * The first byte, which was probably read from in. + */ + public BitInputStream(InputStream in, int firstByte) { + this.in = in; + this.unread = firstByte; + this.available = 8; + } + + /** + * Read one bit. + * + * @return true if it is a 1 bit. + */ + public boolean bit() throws IOException { + return read(1) != 0; + } + + /** + * Get the number of bits that have been read from this BitInputStream. + * This includes pad bits that have been skipped, but might not include + * bytes that have been read from the underlying InputStream that have not + * yet been delivered as bits. + * + * @return The number of bits read so far. + */ + public long nrBits() { + return this.nrBits; + } + + /** + * Check that the rest of the block has been padded with zeroes. + * + * @param factor + * The size of the block to pad. This will typically be 8, 16, + * 32, 64, 128, 256, etc. + * @return true if the block was zero padded, or false if the the padding + * contains any one bits. + * @throws IOException + */ + public boolean pad(int factor) throws IOException { + int padding = factor - (int) (this.nrBits % factor); + boolean result = true; + + for (int i = 0; i < padding; i += 1) { + if (bit()) { + result = false; + } + } + return result; + } + + /** + * Read some bits. + * + * @param width + * The number of bits to read. (0..32) + * @throws IOException + * @return the bits + */ + public int read(int width) throws IOException { + if (width == 0) { + return 0; + } + if (width < 0 || width > 32) { + throw new IOException("Bad read width."); + } + int result = 0; + while (width > 0) { + if (this.available == 0) { + this.unread = this.in.read(); + if (this.unread < 0) { + throw new IOException("Attempt to read past end."); + } + this.available = 8; + } + int take = width; + if (take > this.available) { + take = this.available; + } + result |= ((this.unread >>> (this.available - take)) & mask[take]) + << (width - take); + this.nrBits += take; + this.available -= take; + width -= take; + } + return result; + } +} diff --git a/eurilys4-service/src/java/jsonlib/zip/BitOutputStream.java b/eurilys4-service/src/java/jsonlib/zip/BitOutputStream.java new file mode 100644 index 00000000..526ad611 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/BitOutputStream.java @@ -0,0 +1,154 @@ +package org.json.zip; + +import java.io.IOException; +import java.io.OutputStream; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * This is a big endian bit writer. It writes its bits to an OutputStream. + * + * @version 2013-04-18 + * + */ +public class BitOutputStream implements BitWriter { + + /** + * The number of bits written. + */ + private long nrBits = 0; + + /** + * The destination of the bits. + */ + private OutputStream out; + + /** + * Holder of bits not yet written. + */ + private int unwritten; + + /** + * The number of unused bits in this.unwritten. + */ + private int vacant = 8; + + /** + * Use an OutputStream to produce a BitWriter. The BitWriter will send its + * bits to the OutputStream as each byte is filled. + * + * @param out + * An Output Stream + */ + public BitOutputStream(OutputStream out) { + this.out = out; + } + + /** + * Returns the number of bits that have been written to this + * bitOutputStream. This may include bits that have not yet been written + * to the underlying outputStream. + */ + public long nrBits() { + return this.nrBits; + } + + /** + * Write a 1 bit. + * + * @throws IOException + */ + public void one() throws IOException { + write(1, 1); + } + + /** + * Pad the rest of the block with zeroes and flush. pad(8) flushes the last + * unfinished byte. The underlying OutputStream will be flushed. + * + * @param factor + * The size of the block to pad. This will typically be 8, 16, + * 32, 64, 128, 256, etc. + * @return this + * @throws IOException + */ + public void pad(int factor) throws IOException { + int padding = factor - (int) (nrBits % factor); + int excess = padding & 7; + if (excess > 0) { + this.write(0, excess); + padding -= excess; + } + while (padding > 0) { + this.write(0, 8); + padding -= 8; + } + this.out.flush(); + } + + /** + * Write some bits. Up to 32 bits can be written at a time. + * + * @param bits + * The bits to be written. + * @param width + * The number of bits to write. (0..32) + * @throws IOException + */ + public void write(int bits, int width) throws IOException { + if (bits == 0 && width == 0) { + return; + } + if (width <= 0 || width > 32) { + throw new IOException("Bad write width."); + } + while (width > 0) { + int actual = width; + if (actual > this.vacant) { + actual = this.vacant; + } + this.unwritten |= ((bits >>> (width - actual)) & + BitInputStream.mask[actual]) << (this.vacant - actual); + width -= actual; + nrBits += actual; + this.vacant -= actual; + if (this.vacant == 0) { + this.out.write(this.unwritten); + this.unwritten = 0; + this.vacant = 8; + } + } + } + + /** + * Write a 0 bit. + * + * @throws IOException + */ + public void zero() throws IOException { + write(0, 1); + + } +} diff --git a/eurilys4-service/src/java/jsonlib/zip/BitReader.java b/eurilys4-service/src/java/jsonlib/zip/BitReader.java new file mode 100644 index 00000000..1987729b --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/BitReader.java @@ -0,0 +1,41 @@ +package org.json.zip; + +import java.io.IOException; + +public interface BitReader { + /** + * Read one bit. + * + * @return true if it is a 1 bit. + */ + public boolean bit() throws IOException; + + /** + * Returns the number of bits that have been read from this bitreader. + * + * @return The number of bits read so far. + */ + public long nrBits(); + + /** + * Check that the rest of the block has been padded with zeroes. + * + * @param factor + * The size in bits of the block to pad. This will typically be + * 8, 16, 32, 64, 128, 256, etc. + * @return true if the block was zero padded, or false if the the padding + * contained any one bits. + * @throws IOException + */ + public boolean pad(int factor) throws IOException; + + /** + * Read some bits. + * + * @param width + * The number of bits to read. (0..32) + * @throws IOException + * @return the bits + */ + public int read(int width) throws IOException; +} diff --git a/eurilys4-service/src/java/jsonlib/zip/BitWriter.java b/eurilys4-service/src/java/jsonlib/zip/BitWriter.java new file mode 100644 index 00000000..83eb7e31 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/BitWriter.java @@ -0,0 +1,51 @@ +package org.json.zip; + +import java.io.IOException; + +/** + * A bitwriter is a an interface that allows for doing output at the bit level. + * Most IO interfaces only allow for writing at the byte level or higher. + */ +public interface BitWriter { + /** + * Returns the number of bits that have been written to this bitwriter. + */ + public long nrBits(); + + /** + * Write a 1 bit. + * + * @throws IOException + */ + public void one() throws IOException; + + /** + * Pad the rest of the block with zeros and flush. + * + * @param factor + * The size in bits of the block to pad. This will typically be + * 8, 16, 32, 64, 128, 256, etc. + * @return true if the block was zero padded, or false if the the padding + * contains any one bits. + * @throws IOException + */ + public void pad(int factor) throws IOException; + + /** + * Write some bits. Up to 32 bits can be written at a time. + * + * @param bits + * The bits to be written. + * @param width + * The number of bits to write. (0..32) + * @throws IOException + */ + public void write(int bits, int width) throws IOException; + + /** + * Write a 0 bit. + * + * @throws IOException + */ + public void zero() throws IOException; +} diff --git a/eurilys4-service/src/java/jsonlib/zip/Compressor.java b/eurilys4-service/src/java/jsonlib/zip/Compressor.java new file mode 100644 index 00000000..6dddff42 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/Compressor.java @@ -0,0 +1,575 @@ +package org.json.zip; + +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.Kim; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * JSONzip is a compression scheme for JSON text. + * + * @author JSON.org + * @version 2013-04-18 + */ + +/** + * A compressor implements the compression behavior of JSONzip. It provides a + * zip method that takes a JSONObject or JSONArray and delivers a stream of + * bits to a BitWriter. + * + * FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT BEEN TESTED ADEQUATELY + * FOR PRODUCTION USE. + */ +public class Compressor extends JSONzip { + + /** + * A compressor outputs to a BitWriter. + */ + final BitWriter bitwriter; + + /** + * Create a new compressor. It may be used for an entire session or + * subsession. + * + * @param bitwriter + * The BitWriter this Compressor will output to. Don't forget to + * flush. + */ + public Compressor(BitWriter bitwriter) { + super(); + this.bitwriter = bitwriter; + } + + /** + * Return a 4 bit code for a character in a JSON number. The digits '0' to + * '9' get the codes 0 to 9. '.' is 10, '-' is 11, '+' is 12, and 'E' or + * 'e' is 13. + * + * @param digit + * An ASCII character from a JSIN number. + * @return + */ + private static int bcd(char digit) { + if (digit >= '0' && digit <= '9') { + return digit - '0'; + } + switch (digit) { + case '.': + return 10; + case '-': + return 11; + case '+': + return 12; + default: + return 13; + } + } + + /** + * Finish the final byte and flush the bitwriter. This does the same thing + * as pad(8). + * + * @throws JSONException + */ + public void flush() throws JSONException { + pad(8); + } + + /** + * Output a one bit. + * + * @throws IOException + */ + private void one() throws JSONException { + if (probe) { + log(1); + } + write(1, 1); + } + + /** + * Pad the output to fill an allotment of bits. + * + * @param factor + * The size of the bit allotment. A value of 8 will complete and + * flush the current byte. If you don't pad, then some of the + * last bits might not be sent to the Output Stream. + * @throws JSONException + */ + public void pad(int factor) throws JSONException { + try { + this.bitwriter.pad(factor); + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Write a number, using the number of bits necessary to hold the number. + * + * @param integer + * The value to be encoded. + * @param width + * The number of bits to encode the value, between 0 and 32. + * @throws JSONException + */ + private void write(int integer, int width) throws JSONException { + try { + this.bitwriter.write(integer, width); + if (probe) { + log(integer, width); + } + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Write an integer with Huffman encoding. The bit pattern that is written + * will be determined by the Huffman encoder. + * + * @param integer + * The value to be written. + * @param huff + * The Huffman encoder. + * @throws JSONException + */ + private void write(int integer, Huff huff) throws JSONException { + huff.write(integer, this.bitwriter); + } + + /** + * Write each of the bytes in a kim with Huffman encoding. + * + * @param kim + * A kim containing the bytes to be written. + * @param huff + * The Huffman encoder. + * @throws JSONException + */ + private void write(Kim kim, Huff huff) throws JSONException { + write(kim, 0, kim.length, huff); + } + + /** + * Write a range of bytes from a Kim with Huffman encoding. + * + * @param kim + * A Kim containing the bytes to be written. + * @param from + * The index of the first byte to write. + * @param thru + * The index after the last byte to write. + * @param huff + * The Huffman encoder. + * @throws JSONException + */ + private void write(Kim kim, int from, int thru, Huff huff) + throws JSONException { + for (int at = from; at < thru; at += 1) { + write(kim.get(at), huff); + } + } + + /** + * Write an integer, using the number of bits necessary to hold the number + * as determined by its keep, and increment its usage count in the keep. + * + * @param integer + * The value to be encoded. + * @param keep + * The Keep that the integer is one of. + * @throws JSONException + */ + private void writeAndTick(int integer, Keep keep) throws JSONException { + int width = keep.bitsize(); + keep.tick(integer); + if (probe) { + log("\"" + keep.value(integer) + "\""); + } + write(integer, width); + } + + /** + * Write a JSON Array. + * + * @param jsonarray + * @throws JSONException + */ + private void writeArray(JSONArray jsonarray) throws JSONException { + +// JSONzip has three encodings for arrays: +// The array is empty (zipEmptyArray). +// First value in the array is a string (zipArrayString). +// First value in the array is not a string (zipArrayValue). + + boolean stringy = false; + int length = jsonarray.length(); + if (length == 0) { + write(zipEmptyArray, 3); + } else { + Object value = jsonarray.get(0); + if (value == null) { + value = JSONObject.NULL; + } + if (value instanceof String) { + stringy = true; + write(zipArrayString, 3); + writeString((String) value); + } else { + write(zipArrayValue, 3); + writeValue(value); + } + for (int i = 1; i < length; i += 1) { + if (probe) { + log(); + } + value = jsonarray.get(i); + if (value == null) { + value = JSONObject.NULL; + } + if (value instanceof String != stringy) { + zero(); + } + one(); + if (value instanceof String) { + writeString((String) value); + } else { + writeValue(value); + } + } + zero(); + zero(); + + } + } + + /** + * Write a JSON value. + * + * @param value + * One of these types: JSONObject, JSONArray (or Map or + * Collection or array), Number (or Integer or Long or Double), + * or String, or Boolean, or JSONObject.NULL, or null. + * @throws JSONException + */ + private void writeJSON(Object value) throws JSONException { + if (JSONObject.NULL.equals(value)) { + write(zipNull, 3); + } else if (Boolean.FALSE.equals(value)) { + write(zipFalse, 3); + } else if (Boolean.TRUE.equals(value)) { + write(zipTrue, 3); + } else { + if (value instanceof Map) { + value = new JSONObject((Map) value); + } else if (value instanceof Collection) { + value = new JSONArray((Collection) value); + } else if (value.getClass().isArray()) { + value = new JSONArray(value); + } + if (value instanceof JSONObject) { + writeObject((JSONObject) value); + } else if (value instanceof JSONArray) { + writeArray((JSONArray) value); + } else { + throw new JSONException("Unrecognized object"); + } + } + } + + /** + * Write the name of an object property. Names have their own Keep and + * Huffman encoder because they are expected to be a more restricted set. + * + * @param name + * @throws JSONException + */ + private void writeName(String name) throws JSONException { + +// If this name has already been registered, then emit its integer and +// increment its usage count. + + Kim kim = new Kim(name); + int integer = this.namekeep.find(kim); + if (integer != none) { + one(); + writeAndTick(integer, this.namekeep); + } else { + +// Otherwise, emit the string with Huffman encoding, and register it. + + zero(); + write(kim, this.namehuff); + write(end, namehuff); + this.namekeep.register(kim); + } + } + + /** + * Write a JSON object. + * + * @param jsonobject + * @return + * @throws JSONException + */ + private void writeObject(JSONObject jsonobject) throws JSONException { + +// JSONzip has two encodings for objects: Empty Objects (zipEmptyObject) and +// non-empty objects (zipObject). + + boolean first = true; + Iterator keys = jsonobject.keys(); + while (keys.hasNext()) { + if (probe) { + log("\n"); + } + Object key = keys.next(); + if (key instanceof String) { + if (first) { + first = false; + write(zipObject, 3); + } else { + one(); + } + writeName((String) key); + Object value = jsonobject.get((String) key); + if (value instanceof String) { + zero(); + writeString((String) value); + } else { + one(); + writeValue(value); + } + } + } + if (first) { + write(zipEmptyObject, 3); + } else { + zero(); + } + } + + /** + * Write a string. + * + * @param string + * @throws JSONException + */ + private void writeString(String string) throws JSONException { + +// Special case for empty strings. + + if (string.length() == 0) { + zero(); + zero(); + write(end, this.substringhuff); + zero(); + } else { + Kim kim = new Kim(string); + +// Look for the string in the strings keep. If it is found, emit its +// integer and count that as a use. + + int integer = this.stringkeep.find(kim); + if (integer != none) { + one(); + writeAndTick(integer, this.stringkeep); + } else { + +// But if it is not found, emit the string's substrings. Register the string +// so that the next lookup will succeed. + + writeSubstring(kim); + this.stringkeep.register(kim); + } + } + } + + /** + * Write a string, attempting to match registered substrings. + * + * @param kim + * @throws JSONException + */ + private void writeSubstring(Kim kim) throws JSONException { + this.substringkeep.reserve(); + zero(); + int from = 0; + int thru = kim.length; + int until = thru - JSONzip.minSubstringLength; + int previousFrom = none; + int previousThru = 0; + +// Find a substring from the substring keep. + + while (true) { + int at; + int integer = none; + for (at = from; at <= until; at += 1) { + integer = this.substringkeep.match(kim, at, thru); + if (integer != none) { + break; + } + } + if (integer == none) { + break; + } + +// If a substring is found, emit any characters that were before the matched +// substring. Then emit the substring's integer and loop back to match the +// remainder with another substring. + + if (from != at) { + zero(); + write(kim, from, at, this.substringhuff); + write(end, this.substringhuff); + if (previousFrom != none) { + this.substringkeep.registerOne(kim, previousFrom, + previousThru); + previousFrom = none; + } + } + one(); + writeAndTick(integer, this.substringkeep); + from = at + this.substringkeep.length(integer); + if (previousFrom != none) { + this.substringkeep.registerOne(kim, previousFrom, + previousThru); + previousFrom = none; + } + previousFrom = at; + previousThru = from + 1; + } + +// If a substring is not found, then emit the remaining characters. + + zero(); + if (from < thru) { + write(kim, from, thru, this.substringhuff); + if (previousFrom != none) { + this.substringkeep.registerOne(kim, previousFrom, previousThru); + } + } + write(end, this.substringhuff); + zero(); + +// Register the string's substrings in the trie in hopes of future substring +// matching. + + substringkeep.registerMany(kim); + } + + /** + * Write a value. + * + * @param value + * One of these types: Boolean, Number, etc. + * @throws JSONException + */ + private void writeValue(Object value) throws JSONException { + if (value instanceof Number) { + String string = JSONObject.numberToString((Number) value); + int integer = this.values.find(string); + if (integer != none) { + write(2, 2); + writeAndTick(integer, this.values); + return; + } + if (value instanceof Integer || value instanceof Long) { + long longer = ((Number) value).longValue(); + if (longer >= 0 && longer < int14) { + write(0, 2); + if (longer < int4) { + zero(); + write((int) longer, 4); + return; + } + one(); + if (longer < int7) { + zero(); + write((int) longer, 7); + return; + } + one(); + write((int) longer, 14); + return; + } + } + write(1, 2); + for (int i = 0; i < string.length(); i += 1) { + write(bcd(string.charAt(i)), 4); + } + write(endOfNumber, 4); + this.values.register(string); + } else { + write(3, 2); + writeJSON(value); + } + } + + /** + * Output a zero bit. + * + * @throws JSONException + * + * @throws IOException + */ + private void zero() throws JSONException { + if (probe) { + log(0); + } + write(0, 1); + } + + /** + * Compress a JSONObject. + * + * @param jsonobject + * @throws JSONException + */ + public void zip(JSONObject jsonobject) throws JSONException { + begin(); + writeJSON(jsonobject); + } + + /** + * Compress a JSONArray. + * + * @param jsonarray + * @throws JSONException + */ + public void zip(JSONArray jsonarray) throws JSONException { + begin(); + writeJSON(jsonarray); + } +} diff --git a/eurilys4-service/src/java/jsonlib/zip/Decompressor.java b/eurilys4-service/src/java/jsonlib/zip/Decompressor.java new file mode 100644 index 00000000..108a2e2c --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/Decompressor.java @@ -0,0 +1,325 @@ +package org.json.zip; + +import java.io.UnsupportedEncodingException; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.Kim; + +/* + Copyright (c) 2012 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * JSONzip is a compression scheme for JSON text. + * + * @author JSON.org + * @version 2013-04-18 + */ + +public class Decompressor extends JSONzip { + + /** + * A decompressor reads bits from a BitReader. + */ + BitReader bitreader; + + /** + * Create a new compressor. It may be used for an entire session or + * subsession. + * + * @param bitreader + * The bitreader that this decompressor will read from. + */ + public Decompressor(BitReader bitreader) { + super(); + this.bitreader = bitreader; + } + + /** + * Read one bit. + * + * @return true if 1, false if 0. + * @throws JSONException + */ + private boolean bit() throws JSONException { + boolean value; + try { + value = this.bitreader.bit(); + if (probe) { + log(value ? 1 : 0); + } + return value; + } catch (Throwable e) { + throw new JSONException(e); + } + + } + + /** + * Read enough bits to obtain an integer from the keep, and increase that + * integer's weight. + * + * @param keep + * @param bitreader + * @return + * @throws JSONException + */ + private Object getAndTick(Keep keep, BitReader bitreader) + throws JSONException { + try { + int width = keep.bitsize(); + int integer = bitreader.read(width); + Object value = keep.value(integer); + if (JSONzip.probe) { + JSONzip.log("\"" + value + "\""); + JSONzip.log(integer, width); + } + if (integer >= keep.length) { + throw new JSONException("Deep error."); + } + keep.tick(integer); + return value; + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * The pad method skips the bits that padded a stream to fit some + * allocation. pad(8) will skip over the remainder of a byte. + * + * @param factor + * @return true if all of the padding bits were zero. + * @throws JSONException + */ + public boolean pad(int factor) throws JSONException { + try { + return this.bitreader.pad(factor); + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Read an integer, specifying its width in bits. + * + * @param width + * 0 to 32. + * @return An unsigned integer. + * @throws JSONException + */ + private int read(int width) throws JSONException { + try { + int value = this.bitreader.read(width); + if (probe) { + log(value, width); + } + return value; + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Read a JSONArray. + * + * @param stringy + * true if the first element is a string. + * @return + * @throws JSONException + */ + private JSONArray readArray(boolean stringy) throws JSONException { + JSONArray jsonarray = new JSONArray(); + jsonarray.put(stringy ? readString() : readValue()); + while (true) { + if (probe) { + log("\n"); + } + if (!bit()) { + if (!bit()) { + return jsonarray; + } + jsonarray.put(stringy ? readValue() : readString()); + } else { + jsonarray.put(stringy ? readString() : readValue()); + } + } + } + + /** + * Read a JSON value. The type of value is determined by the next 3 bits. + * + * @return + * @throws JSONException + */ + private Object readJSON() throws JSONException { + switch (read(3)) { + case zipObject: + return readObject(); + case zipArrayString: + return readArray(true); + case zipArrayValue: + return readArray(false); + case zipEmptyObject: + return new JSONObject(); + case zipEmptyArray: + return new JSONArray(); + case zipTrue: + return Boolean.TRUE; + case zipFalse: + return Boolean.FALSE; + default: + return JSONObject.NULL; + } + } + + private String readName() throws JSONException { + byte[] bytes = new byte[65536]; + int length = 0; + if (!bit()) { + while (true) { + int c = this.namehuff.read(this.bitreader); + if (c == end) { + break; + } + bytes[length] = (byte) c; + length += 1; + } + if (length == 0) { + return ""; + } + Kim kim = new Kim(bytes, length); + this.namekeep.register(kim); + return kim.toString(); + } + return getAndTick(this.namekeep, this.bitreader).toString(); + } + + private JSONObject readObject() throws JSONException { + JSONObject jsonobject = new JSONObject(); + while (true) { + if (probe) { + log("\n"); + } + String name = readName(); + jsonobject.put(name, !bit() ? readString() : readValue()); + if (!bit()) { + return jsonobject; + } + } + } + + private String readString() throws JSONException { + Kim kim; + int from = 0; + int thru = 0; + int previousFrom = none; + int previousThru = 0; + if (bit()) { + return getAndTick(this.stringkeep, this.bitreader).toString(); + } + byte[] bytes = new byte[65536]; + boolean one = bit(); + this.substringkeep.reserve(); + while (true) { + if (one) { + from = thru; + kim = (Kim) getAndTick(this.substringkeep, this.bitreader); + thru = kim.copy(bytes, from); + if (previousFrom != none) { + this.substringkeep.registerOne(new Kim(bytes, previousFrom, + previousThru + 1)); + } + previousFrom = from; + previousThru = thru; + one = bit(); + } else { + from = none; + while (true) { + int c = this.substringhuff.read(this.bitreader); + if (c == end) { + break; + } + bytes[thru] = (byte) c; + thru += 1; + if (previousFrom != none) { + this.substringkeep.registerOne(new Kim(bytes, + previousFrom, previousThru + 1)); + previousFrom = none; + } + } + if (!bit()) { + break; + } + one = true; + } + } + if (thru == 0) { + return ""; + } + kim = new Kim(bytes, thru); + this.stringkeep.register(kim); + this.substringkeep.registerMany(kim); + return kim.toString(); + } + + private Object readValue() throws JSONException { + switch (read(2)) { + case 0: + return new Integer(read(!bit() ? 4 : !bit() ? 7 : 14)); + case 1: + byte[] bytes = new byte[256]; + int length = 0; + while (true) { + int c = read(4); + if (c == endOfNumber) { + break; + } + bytes[length] = bcd[c]; + length += 1; + } + Object value; + try { + value = JSONObject.stringToValue(new String(bytes, 0, length, + "US-ASCII")); + } catch (UnsupportedEncodingException e) { + throw new JSONException(e); + } + this.values.register(value); + return value; + case 2: + return getAndTick(this.values, this.bitreader); + case 3: + return readJSON(); + default: + throw new JSONException("Impossible."); + } + } + + public Object unzip() throws JSONException { + begin(); + return readJSON(); + } +} diff --git a/eurilys4-service/src/java/jsonlib/zip/Huff.java b/eurilys4-service/src/java/jsonlib/zip/Huff.java new file mode 100644 index 00000000..2e1d1c92 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/Huff.java @@ -0,0 +1,406 @@ +package org.json.zip; + +import org.json.JSONException; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * JSONzip is a compression scheme for JSON text. + * @author JSON.org + * @version 2013-04-18 + */ + +/** + * A Huffman encoder/decoder. It operates over a domain of integers, which may + * map to characters or other symbols. Symbols that are used frequently are + * given shorter codes than symbols that are used infrequently. This usually + * produces shorter messages. + * + * Initially, all of the symbols are given the same weight. The weight of a + * symbol is incremented by the tick method. The generate method is used to + * generate the encoding table. The table must be generated before encoding or + * decoding. You may regenerate the table with the latest weights at any time. + */ +public class Huff implements None, PostMortem { + + /** + * The number of symbols known to the encoder. + */ + private final int domain; + + /** + * An array that maps symbol values to symbols. + */ + private final Symbol[] symbols; + + /** + * The root of the decoding table, and the terminal of the encoding table. + */ + private Symbol table; + + /** + * Have any weights changed since the table was last generated? + */ + private boolean upToDate = false; + + /** + * The number of bits in the last symbol. This is used in tracing. + */ + private int width; + + private static class Symbol implements PostMortem { + public Symbol back; + public Symbol next; + public Symbol zero; + public Symbol one; + public final int integer; + public long weight; + + /** + * Make a symbol representing a character or other value. + * + * @param integer + * The symbol's number + */ + public Symbol(int integer) { + this.integer = integer; + this.weight = 0; + this.next = null; + this.back = null; + this.one = null; + this.zero = null; + } + + public boolean postMortem(PostMortem pm) { + boolean result = true; + Symbol that = (Symbol) pm; + + if (this.integer != that.integer || this.weight != that.weight) { + return false; + } + if ((this.back != null) != (that.back != null)) { + return false; + } + Symbol zero = this.zero; + Symbol one = this.one; + if (zero == null) { + if (that.zero != null) { + return false; + } + } else { + result = zero.postMortem(that.zero); + } + if (one == null) { + if (that.one != null) { + return false; + } + } else { + result = one.postMortem(that.one); + } + return result; + } + + } + + /** + * Construct a Huffman encoder/decoder. + * + * @param domain + * The number of values known to the object. + */ + public Huff(int domain) { + this.domain = domain; + int length = domain * 2 - 1; + this.symbols = new Symbol[length]; + +// Make the leaf symbols. + + for (int i = 0; i < domain; i += 1) { + symbols[i] = new Symbol(i); + } + +// SMake the links. + + for (int i = domain; i < length; i += 1) { + symbols[i] = new Symbol(none); + } + } + + /** + * Generate the encoding/decoding table. The table determines the bit + * sequences used by the read and write methods. + * + * @return this + */ + public void generate() { + if (!this.upToDate) { + +// Phase One: Sort the symbols by weight into a linked list. + + Symbol head = this.symbols[0]; + Symbol next; + Symbol previous = head; + Symbol symbol; + + this.table = null; + head.next = null; + for (int i = 1; i < this.domain; i += 1) { + symbol = symbols[i]; + +// If this symbol weights less than the head, then it becomes the new head. + + if (symbol.weight < head.weight) { + symbol.next = head; + head = symbol; + } else { + +// To save time, we will start the search from the previous symbol instead +// of the head unless the current symbol weights less than the previous symbol. + + if (symbol.weight < previous.weight) { + previous = head; + } + +// Find a connected pair (previous and next) where the symbol weighs the same +// or more than previous but less than the next. Link the symbol between them. + + while (true) { + next = previous.next; + if (next == null || symbol.weight < next.weight) { + break; + } + previous = next; + } + symbol.next = next; + previous.next = symbol; + previous = symbol; + } + } + +// Phase Two: Make new symbols from the two lightest symbols until only one +// symbol remains. The final symbol becomes the root of the table binary tree. + + int avail = this.domain; + Symbol first; + Symbol second; + previous = head; + while (true) { + first = head; + second = first.next; + head = second.next; + symbol = this.symbols[avail]; + avail += 1; + symbol.weight = first.weight + second.weight; + symbol.zero = first; + symbol.one = second; + symbol.back = null; + first.back = symbol; + second.back = symbol; + if (head == null) { + break; + } + +// Insert the new symbol back into the sorted list. + + if (symbol.weight < head.weight) { + symbol.next = head; + head = symbol; + previous = head; + } else { + while (true) { + next = previous.next; + if (next == null || symbol.weight < next.weight) { + break; + } + previous = next; + } + symbol.next = next; + previous.next = symbol; + previous = symbol; + } + + } + +// The last remaining symbol is the root of the table. + + this.table = symbol; + this.upToDate = true; + } + } + + private boolean postMortem(int integer) { + int[] bits = new int[this.domain]; + Symbol symbol = this.symbols[integer]; + if (symbol.integer != integer) { + return false; + } + int i = 0; + while (true) { + Symbol back = symbol.back; + if (back == null) { + break; + } + if (back.zero == symbol) { + bits[i] = 0; + } else if (back.one == symbol) { + bits[i] = 1; + } else { + return false; + } + i += 1; + symbol = back; + } + if (symbol != this.table) { + return false; + } + this.width = 0; + symbol = this.table; + while (symbol.integer == none) { + i -= 1; + symbol = bits[i] != 0 ? symbol.one : symbol.zero; + } + return symbol.integer == integer && i == 0; + } + + /** + * Compare two Huffman tables. + */ + public boolean postMortem(PostMortem pm) { + +// Go through every integer in the domain, generating its bit sequence, and +// then proving that that bit sequence produces the same integer. + + for (int integer = 0; integer < this.domain; integer += 1) { + if (!postMortem(integer)) { + JSONzip.log("\nBad huff "); + JSONzip.logchar(integer, integer); + return false; + } + } + return this.table.postMortem(((Huff) pm).table); + } + + /** + * Read bits until a symbol can be identified. The weight of the read + * symbol will be incremented. + * + * @param bitreader + * The source of bits. + * @return The integer value of the symbol. + * @throws JSONException + */ + public int read(BitReader bitreader) throws JSONException { + try { + this.width = 0; + Symbol symbol = this.table; + while (symbol.integer == none) { + this.width += 1; + symbol = bitreader.bit() ? symbol.one : symbol.zero; + } + tick(symbol.integer); + if (JSONzip.probe) { + JSONzip.logchar(symbol.integer, this.width); + } + return symbol.integer; + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Increase by 1 the weight associated with a value. + * + * @param value + * The number of the symbol to tick + * @return this + */ + public void tick(int value) { + this.symbols[value].weight += 1; + this.upToDate = false; + } + + /** + * Increase by 1 the weight associated with a range of values. + * + * @param from + * The first symbol to tick + * @param to + * The last symbol to tick + * @return this + */ + public void tick(int from, int to) { + for (int value = from; value <= to; value += 1) { + tick(value); + } + } + + /** + * Recur from a symbol back, emitting bits. We recur before emitting to + * make the bits come out in the right order. + * + * @param symbol + * The symbol to write. + * @param bitwriter + * The bitwriter to write it to. + * @throws JSONException + */ + private void write(Symbol symbol, BitWriter bitwriter) + throws JSONException { + try { + Symbol back = symbol.back; + if (back != null) { + this.width += 1; + write(back, bitwriter); + if (back.zero == symbol) { + bitwriter.zero(); + } else { + bitwriter.one(); + } + } + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Write the bits corresponding to a symbol. The weight of the symbol will + * be incremented. + * + * @param value + * The number of the symbol to write + * @param bitwriter + * The destination of the bits. + * @return this + * @throws JSONException + */ + public void write(int value, BitWriter bitwriter) throws JSONException { + this.width = 0; + write(this.symbols[value], bitwriter); + tick(value); + if (JSONzip.probe) { + JSONzip.logchar(value, this.width); + } + } +} diff --git a/eurilys4-service/src/java/jsonlib/zip/JSONzip.java b/eurilys4-service/src/java/jsonlib/zip/JSONzip.java new file mode 100644 index 00000000..2128742c --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/JSONzip.java @@ -0,0 +1,281 @@ +package org.json.zip; + + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * JSONzip is a binary-encoded JSON dialect. It is designed to compress the + * messages in a session. It is adaptive, so with each message seen, it should + * improve its compression. It minimizes JSON's overhead, reducing punctuation + * to a small number of bits. It uses Huffman encoding to reduce the average + * size of characters. It uses caches (or Keeps) to keep recently seen strings + * and values, so repetitive content (such as object keys) can be + * substantially reduced. It uses a character encoding called Kim (Keep it + * minimal) that is smaller than UTF-8 for most East European, African, and + * Asian scripts. + * + * JSONzip tends to reduce most content by about half. If there is a lot of + * recurring information, the reduction can be much more dramatic. + * + * FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT YET BEEN TESTED + * ADEQUATELY FOR PRODUCTION USE. + * + * @author JSON.org + * @version 2013-04-18 + */ +public abstract class JSONzip implements None, PostMortem { + /** + * Powers of 2. + */ + public static final int[] twos = { + 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, + 1024, 2048, 4096, 8192, 16384, 32768, 65536 + }; + + /** + * The characters in JSON numbers can be reduced to 4 bits each. + */ + public static final byte[] bcd = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-', '+', 'E' + }; + + /** + * The number of integers that can be encoded in 4 bits. + */ + public static final long int4 = 16; + + /** + * The number of integers that can be encoded in 7 bits. + */ + public static final long int7 = 128; + + /** + * The number of integers that can be encoded in 14 bits. + */ + public static final long int14 = 16384; + + /** + * The end of string code. + */ + public static final int end = 256; + + /** + * The end of number code. + */ + public static final int endOfNumber = bcd.length; + + /** + * The maximum substring length when registering many. The registration of + * one substring may be longer. + */ + public static final int maxSubstringLength = 10; + + /** + * The minimum substring length. + */ + public static final int minSubstringLength = 3; + + /** + * The package supports tracing for debugging. + */ + public static final boolean probe = false; + + /** + * The maximum number of substrings added to the substrings keep per + * string. + */ + public static final int substringLimit = 40; + + /** + * The value code for an empty object. + */ + public static final int zipEmptyObject = 0; + + /** + * The value code for an empty array. + */ + public static final int zipEmptyArray = 1; + + /** + * The value code for true. + */ + public static final int zipTrue = 2; + + /** + * The value code for false. + */ + public static final int zipFalse = 3; + + /** + * The value code for null. + */ + public static final int zipNull = 4; + + /** + * The value code for a non-empty object. + */ + public static final int zipObject = 5; + + /** + * The value code for an array with a string as its first element. + */ + public static final int zipArrayString = 6; + + /** + * The value code for an array with a non-string value as its first element. + */ + public static final int zipArrayValue = 7; + + /** + * A Huffman encoder for names. + */ + protected final Huff namehuff; + + /** + * A place to keep the names (keys). + */ + protected final MapKeep namekeep; + + /** + * A place to keep the strings. + */ + protected final MapKeep stringkeep; + + /** + * A Huffman encoder for string values. + */ + protected final Huff substringhuff; + + /** + * A place to keep the strings. + */ + protected final TrieKeep substringkeep; + + /** + * A place to keep the values. + */ + protected final MapKeep values; + + /** + * Initialize the data structures. + */ + protected JSONzip() { + this.namehuff = new Huff(end + 1); + this.namekeep = new MapKeep(9); + this.stringkeep = new MapKeep(11); + this.substringhuff = new Huff(end + 1); + this.substringkeep = new TrieKeep(12); + this.values = new MapKeep(10); + +// Increase the weights of the ASCII letters, digits, and special characters +// because they are highly likely to occur more frequently. The weight of each +// character will increase as it is used. The Huffman encoder will tend to +// use fewer bits to encode heavier characters. + + this.namehuff.tick(' ', '}'); + this.namehuff.tick('a', 'z'); + this.namehuff.tick(end); + this.namehuff.tick(end); + this.substringhuff.tick(' ', '}'); + this.substringhuff.tick('a', 'z'); + this.substringhuff.tick(end); + this.substringhuff.tick(end); + } + + /** + * + */ + protected void begin() { + this.namehuff.generate(); + this.substringhuff.generate(); + } + + /** + * Write an end-of-line to the console. + */ + static void log() { + log("\n"); + } + + /** + * Write an integer to the console. + * + * @param integer + */ + static void log(int integer) { + log(integer + " "); + } + + /** + * Write two integers, separated by ':' to the console. + * + * @param integer + * @param width + */ + static void log(int integer, int width) { + log(integer + ":" + width + " "); + } + + /** + * Write a string to the console. + * + * @param string + */ + static void log(String string) { + System.out.print(string); + } + + /** + * Write a character or its code to the console. + * + * @param integer + * @param width + */ + static void logchar(int integer, int width) { + if (integer > ' ' && integer <= '}') { + log("'" + (char) integer + "':" + width + " "); + } else { + log(integer, width); + } + } + + /** + * This method is used for testing the implementation of JSONzip. It is not + * suitable for any other purpose. It is used to compare a Compressor and a + * Decompressor, verifying that the data structures that were built during + * zipping and unzipping were the same. + * + * @return true if the structures match. + */ + public boolean postMortem(PostMortem pm) { + JSONzip that = (JSONzip) pm; + return this.namehuff.postMortem(that.namehuff) + && this.namekeep.postMortem(that.namekeep) + && this.stringkeep.postMortem(that.stringkeep) + && this.substringhuff.postMortem(that.substringhuff) + && this.substringkeep.postMortem(that.substringkeep) + && this.values.postMortem(that.values); + } +} diff --git a/eurilys4-service/src/java/jsonlib/zip/Keep.java b/eurilys4-service/src/java/jsonlib/zip/Keep.java new file mode 100644 index 00000000..377e344e --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/Keep.java @@ -0,0 +1,84 @@ +package org.json.zip; + + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * A keep is a data structure that associates strings (or substrings) with + * numbers. This allows the sending of small integers instead of strings. + * + * @author JSON.org + * @version 2013-04-18 + */ +abstract class Keep implements None, PostMortem { + protected int capacity; + protected int length; + protected int power; + protected long[] uses; + + public Keep(int bits) { + this.capacity = JSONzip.twos[bits]; + this.length = 0; + this.power = 0; + this.uses = new long[this.capacity]; + } + + /** + * When an item ages, its use count is reduced by at least half. + * + * @param use + * The current use count of an item. + * @return The new use count for that item. + */ + public static long age(long use) { + return use >= 32 ? 16 : use / 2; + } + + /** + * Return the number of bits required to contain an integer based on the + * current length of the keep. As the keep fills up, the number of bits + * required to identify one of its items goes up. + */ + public int bitsize() { + while (JSONzip.twos[this.power] < this.length) { + this.power += 1; + } + return this.power; + } + + /** + * Increase the usage count on an integer value. + */ + public void tick(int integer) { + this.uses[integer] += 1; + } + + /** + * Get the value associated with an integer. + * @param integer The number of an item in the keep. + * @return The value. + */ + abstract public Object value(int integer); +} diff --git a/eurilys4-service/src/java/jsonlib/zip/MapKeep.java b/eurilys4-service/src/java/jsonlib/zip/MapKeep.java new file mode 100644 index 00000000..1374e08d --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/MapKeep.java @@ -0,0 +1,160 @@ +package org.json.zip; + +import java.util.HashMap; + +import org.json.Kim; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * A keep is an associative data structure that maintains usage counts of each + * of the associations in its keeping. When the keep becomes full, it purges + * little used associations, and ages the survivors. Each key is assigned an + * integer value. When the keep is compacted, each key can be given a new + * value. + */ +class MapKeep extends Keep { + private Object[] list; + private HashMap map; + + /** + * Create a new Keep. + * @param bits + * The capacity of the keep expressed in the number of bits + * required to hold an integer. + */ + public MapKeep(int bits) { + super(bits); + this.list = new Object[this.capacity]; + this.map = new HashMap(this.capacity); + } + + /** + * Compact the keep. A keep may contain at most this.capacity elements. + * The keep contents can be reduced by deleting all elements with low use + * counts, and by reducing the use counts of the survivors. + */ + private void compact() { + int from = 0; + int to = 0; + while (from < this.capacity) { + Object key = this.list[from]; + long usage = age(this.uses[from]); + if (usage > 0) { + this.uses[to] = usage; + this.list[to] = key; + this.map.put(key, new Integer(to)); + to += 1; + } else { + this.map.remove(key); + } + from += 1; + } + if (to < this.capacity) { + this.length = to; + } else { + this.map.clear(); + this.length = 0; + } + this.power = 0; + } + + /** + * Find the integer value associated with this key, or nothing if this key + * is not in the keep. + * + * @param key + * An object. + * @return An integer + */ + public int find(Object key) { + Object o = this.map.get(key); + return o instanceof Integer ? ((Integer) o).intValue() : none; + } + + public boolean postMortem(PostMortem pm) { + MapKeep that = (MapKeep) pm; + if (this.length != that.length) { + JSONzip.log(this.length + " <> " + that.length); + return false; + } + for (int i = 0; i < this.length; i += 1) { + boolean b; + if (this.list[i] instanceof Kim) { + b = ((Kim) this.list[i]).equals(that.list[i]); + } else { + Object o = this.list[i]; + Object q = that.list[i]; + if (o instanceof Number) { + o = o.toString(); + } + if (q instanceof Number) { + q = q.toString(); + } + b = o.equals(q); + } + if (!b) { + JSONzip.log("\n[" + i + "]\n " + this.list[i] + "\n " + + that.list[i] + "\n " + this.uses[i] + "\n " + + that.uses[i]); + return false; + } + } + return true; + } + + /** + * Register a value in the keep. Compact the keep if it is full. The next + * time this value is encountered, its integer can be sent instead. + * @param value A value. + */ + public void register(Object value) { + if (JSONzip.probe) { + int integer = find(value); + if (integer >= 0) { + JSONzip.log("\nDuplicate key " + value); + } + } + if (this.length >= this.capacity) { + compact(); + } + this.list[this.length] = value; + this.map.put(value, new Integer(this.length)); + this.uses[this.length] = 1; + if (JSONzip.probe) { + JSONzip.log("<" + this.length + " " + value + "> "); + } + this.length += 1; + } + + /** + * Return the value associated with the integer. + * @param integer The number of an item in the keep. + * @return The value. + */ + public Object value(int integer) { + return this.list[integer]; + } +} diff --git a/eurilys4-service/src/java/jsonlib/zip/None.java b/eurilys4-service/src/java/jsonlib/zip/None.java new file mode 100644 index 00000000..818e68d8 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/None.java @@ -0,0 +1,15 @@ +package org.json.zip; + +/** + * None is an interface that makes the constant <i>none</i> (short for + * negative one or long for -1) available to any class that implements it. + * The none value is used to stand for an integer that is not an integer, + * such as the negative result of a search. + */ +public interface None { + /** + * Negative One. + */ + public static final int none = -1; + +} diff --git a/eurilys4-service/src/java/jsonlib/zip/PostMortem.java b/eurilys4-service/src/java/jsonlib/zip/PostMortem.java new file mode 100644 index 00000000..22416d70 --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/PostMortem.java @@ -0,0 +1,47 @@ +package org.json.zip; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * The PostMortem interface allows for testing the internal state of JSONzip + * processors. Testing that JSONzip can compress an object and reproduce a + * corresponding object is not sufficient. Complete testing requires that the + * same internal data structures were constructed on both ends. If those + * structures are not equivalent, then it is likely that the implementations + * are not correct, even if convention tests are passed. + * + * PostMortem allows for testing of deep structures without breaking + * encapsulation. + */ +public interface PostMortem { + /** + * Determine if two objects are equivalent. + * + * @param pm + * Another object of the same type. + * @return true if they match. + */ + public boolean postMortem(PostMortem pm); +} diff --git a/eurilys4-service/src/java/jsonlib/zip/README b/eurilys4-service/src/java/jsonlib/zip/README new file mode 100644 index 00000000..93e6470b --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/README @@ -0,0 +1,2 @@ +FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT BEEN TESTED ADEQUATELY FOR +PRODUCTION USE. diff --git a/eurilys4-service/src/java/jsonlib/zip/TrieKeep.java b/eurilys4-service/src/java/jsonlib/zip/TrieKeep.java new file mode 100644 index 00000000..dcb13c7a --- /dev/null +++ b/eurilys4-service/src/java/jsonlib/zip/TrieKeep.java @@ -0,0 +1,396 @@ +package org.json.zip; + +import org.json.Kim; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * A TrieKeep is a Keep that implements a Trie. + */ +class TrieKeep extends Keep { + + /** + * The trie is made of nodes. + */ + class Node implements PostMortem { + private int integer; + private Node[] next; + + /** + * Each non-leaf node contains links to up to 256 next nodes. Each node + * has an integer value. + */ + public Node() { + this.integer = none; + this.next = null; + } + + /** + * Get one of a node's 256 links. If it is a leaf node, it returns + * null. + * + * @param cell + * A integer between 0 and 255. + * @return + */ + public Node get(int cell) { + return this.next == null ? null : this.next[cell]; + } + + /** + * Get one of a node's 256 links. If it is a leap node, it returns + * null. The argument is treated as an unsigned integer. + * + * @param cell + * A byte. + * @return + */ + public Node get(byte cell) { + return get(((int) cell) & 0xFF); + } + + /** + * Compare two nodes. Their lengths must be equal. Their links must + * also compare. + */ + public boolean postMortem(PostMortem pm) { + Node that = (Node) pm; + if (that == null) { + JSONzip.log("\nMisalign"); + return false; + } + if (this.integer != that.integer) { + JSONzip.log("\nInteger " + this.integer + " <> " + + that.integer); + return false; + } + if (this.next == null) { + if (that.next == null) { + return true; + } + JSONzip.log("\nNext is null " + this.integer); + return false; + } + for (int i = 0; i < 256; i += 1) { + Node node = this.next[i]; + if (node != null) { + if (!node.postMortem(that.next[i])) { + return false; + } + } else if (that.next[i] != null) { + JSONzip.log("\nMisalign " + i); + return false; + } + } + return true; + } + + /** + * Set a node's link to another node. + * + * @param cell + * An integer between 0 and 255. + * @param node + * The new value for the cell. + */ + public void set(int cell, Node node) { + if (this.next == null) { + this.next = new Node[256]; + } + if (JSONzip.probe) { + if (node == null || this.next[cell] != null) { + JSONzip.log("\nUnexpected set.\n"); + } + } + this.next[cell] = node; + } + + /** + * Set a node's link to another node. + * + * @param cell + * A byte. + * @param node + * The new value for the cell. + */ + public void set(byte cell, Node node) { + set(((int) cell) & 0xFF, node); + } + + /** + * Get one of a node's 256 links. It will not return null. If there is + * no link, then a link is manufactured. + * + * @param cell + * A integer between 0 and 255. + * @return + */ + public Node vet(int cell) { + Node node = get(cell); + if (node == null) { + node = new Node(); + set(cell, node); + } + return node; + } + + /** + * Get one of a node's 256 links. It will not return null. If there is + * no link, then a link is manufactured. + * + * @param cell + * A byte. + * @return + */ + public Node vet(byte cell) { + return vet(((int) cell) & 0xFF); + } + } + + private int[] froms; + private int[] thrus; + private Node root; + private Kim[] kims; + + /** + * Create a new Keep of kims. + * + * @param bits + * The log2 of the capacity of the Keep. For example, if bits is + * 12, then the keep's capacity will be 4096. + */ + public TrieKeep(int bits) { + super(bits); + this.froms = new int[this.capacity]; + this.thrus = new int[this.capacity]; + this.kims = new Kim[this.capacity]; + this.root = new Node(); + } + + /** + * Get the kim associated with an integer. + * + * @param integer + * @return + */ + public Kim kim(int integer) { + Kim kim = this.kims[integer]; + int from = this.froms[integer]; + int thru = this.thrus[integer]; + if (from != 0 || thru != kim.length) { + kim = new Kim(kim, from, thru); + this.froms[integer] = 0; + this.thrus[integer] = kim.length; + this.kims[integer] = kim; + } + return kim; + } + + /** + * Get the length of the Kim associated with an integer. This is sometimes + * much faster than get(integer).length. + * + * @param integer + * @return + */ + public int length(int integer) { + return this.thrus[integer] - this.froms[integer]; + } + + /** + * Find the integer value associated with this key, or nothing if this key + * is not in the keep. + * + * @param key + * An object. + * @return An integer + */ + public int match(Kim kim, int from, int thru) { + Node node = this.root; + int best = none; + for (int at = from; at < thru; at += 1) { + node = node.get(kim.get(at)); + if (node == null) { + break; + } + if (node.integer != none) { + best = node.integer; + } + from += 1; + } + return best; + } + + public boolean postMortem(PostMortem pm) { + boolean result = true; + TrieKeep that = (TrieKeep) pm; + if (this.length != that.length) { + JSONzip.log("\nLength " + this.length + " <> " + that.length); + return false; + } + if (this.capacity != that.capacity) { + JSONzip.log("\nCapacity " + this.capacity + " <> " + + that.capacity); + return false; + } + for (int i = 0; i < this.length; i += 1) { + Kim thiskim = this.kim(i); + Kim thatkim = that.kim(i); + if (!thiskim.equals(thatkim)) { + JSONzip.log("\n[" + i + "] " + thiskim + " <> " + thatkim); + result = false; + } + } + return result && this.root.postMortem(that.root); + } + + public void registerMany(Kim kim) { + int length = kim.length; + int limit = this.capacity - this.length; + if (limit > JSONzip.substringLimit) { + limit = JSONzip.substringLimit; + } + int until = length - (JSONzip.minSubstringLength - 1); + for (int from = 0; from < until; from += 1) { + int len = length - from; + if (len > JSONzip.maxSubstringLength) { + len = JSONzip.maxSubstringLength; + } + len += from; + Node node = this.root; + for (int at = from; at < len; at += 1) { + Node next = node.vet(kim.get(at)); + if (next.integer == none + && at - from >= (JSONzip.minSubstringLength - 1)) { + next.integer = this.length; + this.uses[this.length] = 1; + this.kims[this.length] = kim; + this.froms[this.length] = from; + this.thrus[this.length] = at + 1; + if (JSONzip.probe) { + try { + JSONzip.log("<<" + this.length + " " + + new Kim(kim, from, at + 1) + ">> "); + } catch (Throwable ignore) { + } + } + this.length += 1; + limit -= 1; + if (limit <= 0) { + return; + } + } + node = next; + } + } + } + + public void registerOne(Kim kim) { + int integer = registerOne(kim, 0, kim.length); + if (integer != none) { + this.kims[integer] = kim; + } + } + + public int registerOne(Kim kim, int from, int thru) { + if (this.length < this.capacity) { + Node node = this.root; + for (int at = from; at < thru; at += 1) { + node = node.vet(kim.get(at)); + } + if (node.integer == none) { + int integer = this.length; + node.integer = integer; + this.uses[integer] = 1; + this.kims[integer] = kim; + this.froms[integer] = from; + this.thrus[integer] = thru; + if (JSONzip.probe) { + try { + JSONzip.log("<<" + integer + " " + new Kim(kim, from, thru) + ">> "); + } catch (Throwable ignore) { + } + } + this.length += 1; + return integer; + } + } + return none; + } + + /** + * Reserve space in the keep, compacting if necessary. A keep may contain + * at most -capacity- elements. The keep contents can be reduced by + * deleting all elements with low use counts, rebuilding the trie with the + * survivors. + */ + public void reserve() { + if (this.capacity - this.length < JSONzip.substringLimit) { + int from = 0; + int to = 0; + this.root = new Node(); + while (from < this.capacity) { + if (this.uses[from] > 1) { + Kim kim = this.kims[from]; + int thru = this.thrus[from]; + Node node = this.root; + for (int at = this.froms[from]; at < thru; at += 1) { + Node next = node.vet(kim.get(at)); + node = next; + } + node.integer = to; + this.uses[to] = age(this.uses[from]); + this.froms[to] = this.froms[from]; + this.thrus[to] = thru; + this.kims[to] = kim; + to += 1; + } + from += 1; + } + +// It is possible, but highly unlikely, that too many items survive. +// If that happens, clear the keep. + + if (this.capacity - to < JSONzip.substringLimit) { + this.power = 0; + this.root = new Node(); + to = 0; + } + this.length = to; + while (to < this.capacity) { + this.uses[to] = 0; + this.kims[to] = null; + this.froms[to] = 0; + this.thrus[to] = 0; + to += 1; + + } + } + } + + public Object value(int integer) { + return kim(integer); + } +} diff --git a/eurilys4-service/src/java/service/CategoryService.java b/eurilys4-service/src/java/service/CategoryService.java new file mode 100644 index 00000000..7da0d30a --- /dev/null +++ b/eurilys4-service/src/java/service/CategoryService.java @@ -0,0 +1,156 @@ +package service; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.json.*; + +/* + * CategoryService memiliki URL : baseURL/category + * CategoryService merupakan sebuah service class yang menangani : + * - get_list - done + * - delete - done + */ + +@WebServlet(name = "CategoryService", urlPatterns = {"/category/*"}) +public class CategoryService extends HttpServlet { + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + String pathInfo = request.getPathInfo(); + dbConnection connector = new dbConnection(); + Connection conn = null; + + /* + * pathInfo : baseURL/category/get_list + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + if (pathInfo.equals("/get_list")) { + try { + + //HttpSession session = request.getSession(true); + //String username = (String) session.getAttribute("username"); + + String username = request.getParameter("username"); + + JSONArray categoryArray = new JSONArray(); + conn = connector.getConnection (); + + /* Search Category by Creator */ + PreparedStatement stmt = conn.prepareStatement("SELECT * FROM category WHERE cat_creator=?;"); + stmt.setString(1, username); + ResultSet rs = stmt.executeQuery(); + + //Result set is not empty + rs.beforeFirst(); + while (rs.next()) { + JSONObject categoryObject = new JSONObject(); + categoryObject.put("category_creator", username); + categoryObject.put("category_id", rs.getString("cat_id")); + categoryObject.put("category_name", rs.getString("cat_name")); + categoryArray.put(categoryObject); + } + + /* Search Category by Assignee */ + stmt = conn.prepareStatement("SELECT cat_id FROM cat_asignee WHERE username =?;"); + stmt.setString(1, username); + rs = stmt.executeQuery(); + rs.beforeFirst(); + String categoryId = ""; + while (rs.next()) { + categoryId = rs.getString("cat_id"); + PreparedStatement stmt2 = conn.prepareStatement("SELECT * FROM category WHERE cat_id =?;"); + stmt2.setString(1, categoryId); + ResultSet rs2 = stmt2.executeQuery(); + rs2.beforeFirst(); + while (rs2.next()) { + JSONObject categoryObject = new JSONObject(); + categoryObject.put("category_creator", rs2.getString("cat_creator")); + categoryObject.put("category_id", categoryId); + categoryObject.put("category_name", rs2.getString("cat_name")); + categoryArray.put(categoryObject); + } + } + out.println(categoryArray); + + } catch (SQLException ex) { + Logger.getLogger(CategoryService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(CategoryService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/category/delete + * requestParameter : category_id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete")) { + try { + String category_id = request.getParameter("category_id"); + conn = connector.getConnection (); + PreparedStatement st = conn.prepareStatement("DELETE FROM category WHERE cat_id=?"); + st.setString(1, category_id); + int row = st.executeUpdate(); + response.sendRedirect("../src/dashboard.jsp"); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> + /** + * Handles the HTTP + * <code>GET</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * <code>POST</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// </editor-fold> +} diff --git a/eurilys4-service/src/java/service/SOAPAddCategory.java b/eurilys4-service/src/java/service/SOAPAddCategory.java new file mode 100644 index 00000000..f8bbb18f --- /dev/null +++ b/eurilys4-service/src/java/service/SOAPAddCategory.java @@ -0,0 +1,153 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package service; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.Part; + +/** + * + * @author Compaq + */ +public class SOAPAddCategory extends HttpServlet { + + /** + * Processes requests for both HTTP + * <code>GET</code> and + * <code>POST</code> methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + dbConnection connector = new dbConnection(); + Connection conn_category = null; + ResultSet rs_category = null; + + + //GET REQUEST BODY. + ServletInputStream i = request.getInputStream(); + int c = 0; + String xmlrpc = ""; + while((c = i.read()) != -1 ) + { + xmlrpc += (char)c; + } + + //EXTRACT PARAMETER. + int startTag = xmlrpc.indexOf("<cname>"); + int endTag = xmlrpc.indexOf("</cname>"); + String categoryName = xmlrpc.substring(startTag,endTag).replaceAll("<cname>",""); + startTag = xmlrpc.indexOf("<cassignee>"); + endTag = xmlrpc.indexOf("</cassignee>"); + String categoryAssigne = xmlrpc.substring(startTag,endTag).replaceAll("<cassignee>",""); + startTag = xmlrpc.indexOf("<ccreator>"); + endTag = xmlrpc.indexOf("</ccreator>"); + String categoryCreator = xmlrpc.substring(startTag,endTag).replaceAll("<ccreator>",""); + + //CALCULATING + String categoryID = ""; + try{ + conn_category = connector.getConnection(); + Statement st = conn_category.createStatement(); + st.executeUpdate("INSERT INTO category (cat_name, cat_creator) VALUES ('" + categoryName + "','" + categoryCreator + "')"); + + PreparedStatement stmt_category = conn_category.prepareStatement("SELECT cat_id FROM category WHERE cat_name=?"); + stmt_category.setString(1, categoryName); + rs_category = stmt_category.executeQuery(); + rs_category.beforeFirst(); + while (rs_category.next()) { + categoryID = rs_category.getString("cat_id"); + } + String[] assigneArray = categoryAssigne.split(","); + for (int j = 0; j < assigneArray.length; j++) { + st.executeUpdate("INSERT INTO cat_asignee (cat_id, username) VALUES ('" + categoryID + "','" + assigneArray[j] + "')"); + } + } catch (Exception e){ + } finally { + try { + conn_category.close(); + } catch (SQLException ex) { + Logger.getLogger(SOAPAddCategory.class.getName()).log(Level.SEVERE, null, ex); + System.out.println("Can not close connection"); + } + } + //PREPARE OUTPUT + String xml = ""; + xml += "<?xml version=\"1.0\"?> \n"; + xml += "<SOAP-ENV:Envelope> \n"; + xml += " <SOAP-ENV:Body> \n"; + xml += " <result> \n"; + xml += " "+categoryID+ "\n"; + xml += " </result> \n"; + xml += " </SOAP-ENV:Body> \n"; + xml += "</SOAP-ENV:Envelope> \n"; + + //RETURN RESPONSE. + response.getWriter().println(xml); + } + + // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> + /** + * Handles the HTTP + * <code>GET</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * <code>POST</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// </editor-fold> +} diff --git a/eurilys4-service/src/java/service/SOAPAddTask.java b/eurilys4-service/src/java/service/SOAPAddTask.java new file mode 100644 index 00000000..24a8a18c --- /dev/null +++ b/eurilys4-service/src/java/service/SOAPAddTask.java @@ -0,0 +1,230 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package service; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.Part; + +/** + * + * @author Compaq + */ +public class SOAPAddTask extends HttpServlet { + + /** + * Processes requests for both HTTP + * <code>GET</code> and + * <code>POST</code> methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + dbConnection connector = new dbConnection(); + Connection conn = null; + + //if (pathInfo.equals("/add_task")) { + //GET REQUEST BODY. + ServletInputStream i = request.getInputStream(); + int c = 0; + String xmlrpc = ""; + while((c = i.read()) != -1 ) + { + xmlrpc += (char)c; + } + //EXTRACT PARAMETER. + int startTag = xmlrpc.indexOf("<tname>"); + int endTag = xmlrpc.indexOf("</tname>"); + String task_name = xmlrpc.substring(startTag,endTag).replaceAll("<tname>",""); + /*startTag = xmlrpc.indexOf("<tattach1>"); + endTag = xmlrpc.indexOf("</tattach1>"); + String attachment1 = xmlrpc.substring(startTag,endTag).replaceAll("<tattach1>",""); + startTag = xmlrpc.indexOf("<tattach2>"); + endTag = xmlrpc.indexOf("</tattach2>"); + String attachment2 = xmlrpc.substring(startTag,endTag).replaceAll("<tattach2>",""); + startTag = xmlrpc.indexOf("<tattach3>"); + endTag = xmlrpc.indexOf("</tattach3>"); + String attachment3 = xmlrpc.substring(startTag,endTag).replaceAll("<tattach3>","");*/ + startTag = xmlrpc.indexOf("<tdeadline>"); + endTag = xmlrpc.indexOf("</tdeadline>"); + String task_deadline = xmlrpc.substring(startTag,endTag).replaceAll("<tdeadline>",""); + startTag = xmlrpc.indexOf("<tassignee>"); + endTag = xmlrpc.indexOf("</tassignee>"); + String assigneeList = xmlrpc.substring(startTag,endTag).replaceAll("<tassignee>",""); + startTag = xmlrpc.indexOf("<ttag>"); + endTag = xmlrpc.indexOf("</ttag>"); + String tagList = xmlrpc.substring(startTag,endTag).replaceAll("<ttag>",""); + startTag = xmlrpc.indexOf("<tcategory>"); + endTag = xmlrpc.indexOf("</tcategory>"); + String catName = xmlrpc.substring(startTag,endTag).replaceAll("<tcategory>",""); + startTag = xmlrpc.indexOf("<tcreator>"); + endTag = xmlrpc.indexOf("</tcreator>"); + String taskCreator = xmlrpc.substring(startTag,endTag).replaceAll("<tcreator>",""); + + //CALCULATING + String taskID = ""; + try{ + conn = connector.getConnection (); + Statement st = conn.createStatement(); + st.executeUpdate("INSERT INTO task(task_name, task_status, task_deadline, cat_name, task_creator) VALUES ('" + task_name + "','0','" + task_deadline + "','" + catName + "','" + taskCreator + "')"); + + PreparedStatement stmt; + + stmt = conn.prepareStatement("SELECT task_id FROM task WHERE task_name=? AND cat_name=?"); + stmt.setString(1, task_name); + stmt.setString(2, catName); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + taskID = rs.getString("task_id"); + } + + /*if (!"".equals(attachment1)) { + stmt = conn.prepareStatement("INSERT INTO attachment (att_content, att_task_id) VALUES (?,?)"); + stmt.setString(1, attachment1); + stmt.setString(2, taskID); + stmt.executeUpdate(); + } + + if (!"".equals(attachment2)) { + stmt = conn.prepareStatement("INSERT INTO attachment (att_content, att_task_id) VALUES (?,?)"); + stmt.setString(1, attachment2); + stmt.setString(2, taskID); + stmt.executeUpdate(); + } + + if (!"".equals(attachment3)) { + stmt = conn.prepareStatement("INSERT INTO attachment (att_content, att_task_id) VALUES (?,?)"); + stmt.setString(1, attachment3); + stmt.setString(2, taskID); + stmt.executeUpdate(); + }*/ + + /*//Insert Task Attachment + Part filePart = req.getPart("attachment_file1"); // Retrieves <input type="file" name="file"> + String filename = ""; + filename = getFilename(filePart); + String dir = "uploads/" + filename; + byte buf[] = new byte[1024 * 4]; + if (!filename.isEmpty()) { + Statement st2 = conn.createStatement(); + st2.executeUpdate("INSERT INTO `attachment` (`att_content`, `att_task_id`) VALUES ('" + filename + "','" + taskID + "')"); + FileOutputStream output = new FileOutputStream(getServletContext().getRealPath("/") + "uploads/" + filename); + try { + InputStream input = filePart.getInputStream(); + try { + while (true) { + int count = input.read(buf); + if (count == -1) { + break; + } + output.write(buf, 0, count); + } + } finally { + input.close(); + } + } finally { + output.close(); + } + }*/ + + //Insert Task Assignee + String[] assigneArray = assigneeList.split(","); + for (int j = 0; j < assigneArray.length; j++) { + st.executeUpdate("INSERT INTO task_asignee (task_id, username) VALUES ('" + taskID + "','" + assigneArray[j] + "')"); + } + + //Insert Task Tag + String[] tagArray = tagList.split(","); + for (int j = 0; j < tagArray.length; j++) { + st.executeUpdate("INSERT INTO tag(tag_name, task_id) VALUES ('" + tagArray[j] + "','" + taskID + "')"); + } + } catch (Exception e){ + } finally { + try { + conn.close(); + } catch (SQLException ex) { + Logger.getLogger(SOAPAddTask.class.getName()).log(Level.SEVERE, null, ex); + System.out.println("Can not close connection - Add Task"); + } + } + //PREPARE OUTPUT + String xml = ""; + xml += "<?xml version=\"1.0\"?> \n"; + xml += "<SOAP-ENV:Envelope> \n"; + xml += " <SOAP-ENV:Body> \n"; + xml += " <result> \n"; + xml += " "+taskID+ "\n"; + xml += " </result> \n"; + xml += " </SOAP-ENV:Body> \n"; + xml += "</SOAP-ENV:Envelope> \n"; + + //RETURN RESPONSE. + response.getWriter().println(xml); + //} + } + + // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> + /** + * Handles the HTTP + * <code>GET</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * <code>POST</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// </editor-fold> +} diff --git a/eurilys4-service/src/java/service/SearchService.java b/eurilys4-service/src/java/service/SearchService.java new file mode 100644 index 00000000..c26d8e64 --- /dev/null +++ b/eurilys4-service/src/java/service/SearchService.java @@ -0,0 +1,217 @@ +package service; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.json.*; + +public class SearchService extends HttpServlet { + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + String pathInfo = request.getPathInfo(); + dbConnection connector = new dbConnection(); + Connection conn = null; + + /* + * pathInfo : baseURL/search/result + * requestParameter : keyword=&filter= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + if (pathInfo.equals("/result")) { + try { + String keyword = request.getParameter("keyword"); + String filter = request.getParameter("filter"); + conn = connector.getConnection (); + PreparedStatement stmt = conn.prepareStatement(""); + ResultSet rs = null; + String HTMLresult = ""; + + if (filter.equals("1")) { //Search All + //Search User + stmt = conn.prepareStatement("SELECT distinct full_name, username FROM user WHERE username LIKE ? OR email LIKE ? OR full_name LIKE ? OR birthdate LIKE ?;"); + stmt.setString(1, "%" + keyword + "%"); //username + stmt.setString(2, "%" + keyword + "%"); //email + stmt.setString(3, "%" + keyword + "%"); //full_name + stmt.setString(4, "%" + keyword + "%"); //birthdate + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "<br>"; + } + HTMLresult += "<div class='search_recommend' onclick=\"javascript:searchResult('"+rs.getString("username")+"','user');\">"+ rs.getString("full_name") +"</div>"; + } + + //Search Category + stmt = conn.prepareStatement("SELECT distinct cat_id, cat_name FROM category WHERE cat_name LIKE ?;"); + stmt.setString(1, "%" + keyword + "%"); //category_name + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "<br>"; + } + HTMLresult += "<div class='search_recommend' onclick=\"javascript:searchResult('"+rs.getString("cat_id")+"','category');\">"+ rs.getString("cat_name") +"</div>"; + } + + //Search Task + stmt = conn.prepareStatement("SELECT DISTINCT task_name, task.task_id FROM ((task LEFT JOIN tag ON task.task_id = tag.task_id) LEFT JOIN comment ON task.task_id = comment.task_id) WHERE task_name LIKE ? OR tag_name LIKE ? OR comment_content LIKE ?"); + stmt.setString(1, "%" + keyword + "%"); //task_name + stmt.setString(2, "%" + keyword + "%"); //tag_name + stmt.setString(3, "%" + keyword + "%"); //comment_content + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "<br>"; + } + HTMLresult += "<div class='search_recommend' onclick=\"javascript:searchResult('"+rs.getString("task_id")+"','task');\">"+ rs.getString("task_name") +"</div>"; + } + } + else if (filter.equals("2")) { //Search User (username, email, nama lengkap, birthdate) + stmt = conn.prepareStatement("SELECT distinct full_name, username FROM user WHERE username LIKE ? OR email LIKE ? OR full_name LIKE ? OR birthdate LIKE ?;"); + stmt.setString(1, "%" + keyword + "%"); //username + stmt.setString(2, "%" + keyword + "%"); //email + stmt.setString(3, "%" + keyword + "%"); //full_name + stmt.setString(4, "%" + keyword + "%"); //birthdate + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "<br>"; + } + HTMLresult += "<div class='search_recommend' onclick=\"javascript:searchResult('"+rs.getString("username")+"','user');\">"+ rs.getString("full_name") +"</div>"; + } + } + else if (filter.equals("3")) { //Search Category + stmt = conn.prepareStatement("SELECT distinct cat_id, cat_name FROM category WHERE cat_name LIKE ?;"); + stmt.setString(1, "%" + keyword + "%"); //category_name + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "<br>"; + } + HTMLresult += "<div class='search_recommend' onclick=\"javascript:searchResult('"+rs.getString("cat_id")+"','category');\">"+ rs.getString("cat_name") +"</div>"; + } + } + else if (filter.equals("4")) { //Search Task (task name, tag, comment) + stmt = conn.prepareStatement("SELECT DISTINCT task_name, task.task_id FROM ((task LEFT JOIN tag ON task.task_id = tag.task_id) LEFT JOIN comment ON task.task_id = comment.task_id) WHERE task_name LIKE ? OR tag_name LIKE ? OR comment_content LIKE ?"); + stmt.setString(1, "%" + keyword + "%"); //task_name + stmt.setString(2, "%" + keyword + "%"); //tag_name + stmt.setString(3, "%" + keyword + "%"); //comment_content + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "<br>"; + } + HTMLresult += "<div class='search_recommend' onclick=\"javascript:searchResult('"+rs.getString("task_id")+"','task');\">"+ rs.getString("task_name") +"</div>"; + } + } + out.println(HTMLresult); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + + /* + * pathInfo : baseURL/search/category + * requestParameter : id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/category")) { + try { + String id = request.getParameter("id"); + conn = connector.getConnection (); + PreparedStatement stmt = conn.prepareStatement(""); + ResultSet rs = null; + JSONObject catResult = new JSONObject(); + + //Search Category + stmt = conn.prepareStatement("SELECT * FROM category WHERE cat_id=?"); + stmt.setString(1, id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + String cat_name = ""; + while (rs.next()) { + cat_name = rs.getString("cat_name"); + catResult.put("cat_name", rs.getString("cat_name")); + catResult.put("cat_creator", rs.getString("cat_creator")); + } + + //Search corresponding task + stmt = conn.prepareStatement("SELECT task_name, task_id FROM task WHERE cat_name=?"); + stmt.setString(1, cat_name); + rs = stmt.executeQuery(); + rs.beforeFirst(); + JSONArray taskList = new JSONArray(); + while (rs.next()) { + taskList.put(rs.getString("task_name")); + } + catResult.put("task", taskList); + + out.println(catResult); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> + /** + * Handles the HTTP + * <code>GET</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * <code>POST</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// </editor-fold> +} diff --git a/eurilys4-service/src/java/service/TaskService.java b/eurilys4-service/src/java/service/TaskService.java new file mode 100644 index 00000000..3c3431d4 --- /dev/null +++ b/eurilys4-service/src/java/service/TaskService.java @@ -0,0 +1,458 @@ +package service; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.json.*; + +/* + * TaskService memiliki URL : baseURL/task + * TaskService merupakan sebuah service class yang menangani : + * - task_detail - done + * - update_task - done + * - delete_comment - done + * - delete_tag - done + * - delete_assignee - done + * - get_category_task (get list of task based on category name) - done + * - finish_task - done + * - delete_task - done + */ +public class TaskService extends HttpServlet { + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + String pathInfo = request.getPathInfo(); + dbConnection connector = new dbConnection(); + Connection conn = null; + + /* + * pathInfo : baseURL/task/task_detail + * requestParameter : task_id= + * Notes : baseURL adalah localhost:8084/eurilys4-service ATAU http://eurilys.ap01.aws.af.cm/ + */ + if (pathInfo.equals("/task_detail")) { + try { + String task_id = request.getParameter("task_id"); + conn = connector.getConnection (); + PreparedStatement stmt = conn.prepareStatement(""); + ResultSet rs = null; + + //Get Tag List + List<String> tagList = new ArrayList<String>(); + stmt = conn.prepareStatement("SELECT * from tag WHERE task_id=?"); + stmt.setString(1, task_id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + tagList.add(rs.getString("tag_name")); + } + + //Get Comment List + List<String> commentContent = new ArrayList<String>(); + List<String> commentID = new ArrayList<String>(); + List<String> commentCreator = new ArrayList<String>(); + List<String> commentTimestamp = new ArrayList<String>(); + stmt = conn.prepareStatement("SELECT comment_id, comment_content, comment_creator, comment_timestamp from comment WHERE task_id=?"); + stmt.setString(1, task_id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + commentID.add(rs.getString("comment_id")); + commentContent.add(rs.getString("comment_content")); + commentCreator.add(rs.getString("comment_creator")); + commentTimestamp.add(rs.getString("comment_timestamp")); + } + + //Get Assignee List + List<String> assignee = new ArrayList<String>(); + stmt = conn.prepareStatement("SELECT username from task_asignee WHERE task_id=?"); + stmt.setString(1, task_id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + assignee.add(rs.getString("username")); + } + + //Get task detail + JSONObject taskObject = new JSONObject(); + stmt = conn.prepareStatement("SELECT * FROM task WHERE task_id=?"); + stmt.setString(1, task_id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + String task_name = rs.getString(2); + String task_status = rs.getString(3); + String task_deadline = rs.getString(4); + String task_category = rs.getString(5); + String task_creator = rs.getString(6); + + taskObject.put("task_id", task_id); + taskObject.put("task_name", task_name); + taskObject.put("task_deadline", task_deadline); + taskObject.put("task_status", task_status); + taskObject.put("task_category", task_category); + taskObject.put("task_creator", task_creator); + taskObject.put("tag_list", tagList); + taskObject.put("comment_content", commentContent); + taskObject.put("comment_id", commentID); + taskObject.put("comment_creator", commentCreator); + taskObject.put("comment_timestamp", commentTimestamp); + taskObject.put("task_assignee", assignee); + } + out.println(taskObject); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/update_task + * requestParameter : edit_task_id=&edit_task_deadline=&edit_task_assignee=&edit_task_tag= + * Notes : baseURL adalah localhost:8084/eurilys4-service ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/update_task")) { + try { + String taskID = request.getParameter("edit_task_id"); + String deadline = request.getParameter("edit_task_deadline"); + String assigneeList = request.getParameter("edit_task_assignee"); + String tagList = request.getParameter("edit_task_tag"); + + conn = connector.getConnection (); + Statement stmt = conn.createStatement(); + + int row1 = 0; + int row2 = 0; + int row3 = 0; + + //Update task_asignee + String[] assigneArray = assigneeList.split(","); + for (int i = 0; i < assigneArray.length; i++) { + if (!("".equals(assigneArray[i]))) { + row1 = stmt.executeUpdate("INSERT INTO task_asignee (task_id, username) VALUES ('" + taskID + "','" + assigneArray[i] + "')"); + } + } + + //Update tag + String[] tagArray = tagList.split(","); + for (int i = 0; i < tagArray.length; i++) { + if (!("".equals(tagArray[i]))) { + row2 = stmt.executeUpdate("INSERT INTO tag (tag_name, task_id) VALUES ('" + tagArray[i] + "','" + taskID + "')"); + } + } + + //Update task + row3 = stmt.executeUpdate("UPDATE task SET task_deadline='" + deadline + "' WHERE task_id='" + taskID + "'"); + + out.println(row1+row2+row3); + + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * HTTP Method : GET + * pathInfo : baseURL/task/delete_comment + * requestParameter : comment_id= + * Notes : baseURL adalah localhost:8084/eurilys4-service ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete_comment")) { + try { + String comment_id = request.getParameter("comment_id"); + conn = connector.getConnection (); + ResultSet rs = null; + PreparedStatement st; + st = conn.prepareStatement("DELETE FROM comment WHERE comment_id=?"); + st.setString(1, comment_id); + int row = st.executeUpdate(); + out.println(row); //row = 1 berhasil, row = 0 gagal + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/delete_tag + * requestParameter : tag_name=&task_id= + * Notes : baseURL adalah localhost:8084/eurilys4-service ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete_tag")) { + try { + String tag_name = request.getParameter("tag_name"); + String task_id = request.getParameter("task_id"); + conn = connector.getConnection (); + PreparedStatement st; + st = conn.prepareStatement("DELETE FROM tag WHERE tag_name=? AND task_id=?"); + st.setString(1, tag_name); + st.setString(2, task_id); + int row = st.executeUpdate(); + out.println(row); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * Delete Assignee in a Task + * pathInfo : baseURL/task/delete_assignee + * requestParameter : task_id=&username= + * Notes : baseURL adalah localhost:8084/eurilys4-service ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete_assignee")) { + try { + String task_id = request.getParameter("task_id"); + String username = request.getParameter("username"); + conn = connector.getConnection (); + PreparedStatement st = conn.prepareStatement("DELETE FROM task_asignee WHERE task_id=? AND username=?"); + st.setString(1, task_id); + st.setString(2, username); + int row = st.executeUpdate(); + out.println(row); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/get_category_task + * requestParameter : category_name= + * Notes : baseURL adalah localhost:8084/eurilys4-service ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/get_category_task")) { + try { + String category_name = request.getParameter("category_name"); + JSONArray taskArray = new JSONArray(); + List<String> tagList = new ArrayList<String>(); + conn = connector.getConnection (); + + //Get task detail + PreparedStatement stmt = conn.prepareStatement("SELECT * FROM task WHERE cat_name=?"); + stmt.setString(1, category_name); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + + String task_id = ""; + String task_name = ""; + String task_status = ""; + String task_deadline = ""; + String task_creator = ""; + + while (rs.next()) { + JSONObject taskObject = new JSONObject(); + + task_id = rs.getString(1); + task_name = rs.getString(2); + task_status = rs.getString(3); + task_deadline = rs.getString(4); + task_creator = rs.getString(6); + + //Get Tag List + stmt = conn.prepareStatement("SELECT * from tag WHERE task_id=?"); + stmt.setString(1, task_id); + ResultSet rs_tag = stmt.executeQuery(); + rs_tag.beforeFirst(); + tagList.clear(); + while (rs_tag.next()) { + tagList.add(rs_tag.getString("tag_name")); + } + taskObject.put("task_id", task_id); + taskObject.put("task_name", task_name); + taskObject.put("task_status", task_status); + taskObject.put("task_deadline", task_deadline); + taskObject.put("task_category", category_name); + taskObject.put("task_creator", task_creator); + taskObject.put("tag_list", tagList); + + taskArray.put(taskObject); + } + out.println(taskArray); + } + catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/all_task + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4-service ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/all_task")) { + try { + String username = request.getParameter("username"); + JSONArray taskArray = new JSONArray(); + List<String> tagList = new ArrayList<String>(); + conn = connector.getConnection (); + + //Get task detail + PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT task.* FROM task INNER JOIN task_asignee WHERE task.task_creator=? OR task_asignee.username=?;"); + stmt.setString(1, username); + stmt.setString(2, username); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + + String task_id = ""; + String task_name = ""; + String task_status = ""; + String task_deadline = ""; + String task_category = ""; + String task_creator = ""; + + while (rs.next()) { + JSONObject taskObject = new JSONObject(); + task_id = rs.getString(1); + task_name = rs.getString(2); + task_status = rs.getString(3); + task_deadline = rs.getString(4); + task_category = rs.getString(5); + task_creator = rs.getString(6); + + //Get Tag List + stmt = conn.prepareStatement("SELECT * from tag WHERE task_id=?"); + stmt.setString(1, task_id); + ResultSet rs_tag = stmt.executeQuery(); + rs_tag.beforeFirst(); + tagList.clear(); + while (rs_tag.next()) { + tagList.add(rs_tag.getString("tag_name")); + } + + taskObject.put("task_id", task_id); + taskObject.put("task_name", task_name); + taskObject.put("task_status", task_status); + taskObject.put("task_deadline", task_deadline); + taskObject.put("task_category", task_category); + taskObject.put("task_creator", task_creator); + taskObject.put("tag_list", tagList); + + taskArray.put(taskObject); + } + out.println(taskArray); + } + catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/finish_task + * requestParameter : task_id= + * Notes : baseURL adalah localhost:8084/eurilys4-service ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/finish_task")) { + try { + conn = connector.getConnection (); + Statement stmt = conn.createStatement(); + String taskID = request.getParameter("task_id"); + //Update task status + int updated_row = stmt.executeUpdate("UPDATE task SET task_status=1 WHERE task_id='" + taskID + "'"); + out.println(updated_row); //return 1, berarti berhasil. 0 berarti gagal + } + catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/add_task + * requestParameter : task_id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/add_task")) { + try { + + } catch (Exception e){ + + } + } + /* + * pathInfo : baseURL/task/delete_task + * requestParameter : task_id= + * Notes : baseURL adalah localhost:8084/eurilys4-service ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete_task")) { + try { + String task_id = request.getParameter("task_id"); + conn = connector.getConnection (); + PreparedStatement st = conn.prepareStatement("DELETE FROM task WHERE task_id=?"); + st.setString(1, task_id); + int row = st.executeUpdate(); + out.println(row); //row = 1 berhasil, row = 0 gagal + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> + /** + * Handles the HTTP + * <code>GET</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * <code>POST</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// </editor-fold> +} diff --git a/eurilys4-service/src/java/service/UserService.java b/eurilys4-service/src/java/service/UserService.java new file mode 100644 index 00000000..8d38baef --- /dev/null +++ b/eurilys4-service/src/java/service/UserService.java @@ -0,0 +1,341 @@ +package service; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import org.json.*; + +/* + * UserService memiliki URL : baseURL/user + * UserService merupakan sebuah service class yang menangani : + * - login_check + * - register + * - user_detail + * - update_profile + * - current_task + * - finished_task + */ + +public class UserService extends HttpServlet { + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + String pathInfo = request.getPathInfo(); + dbConnection connector = new dbConnection(); + Connection conn = null; + + /* + * pathInfo : baseURL/user/login_check + * requestParameter : login_username=&login_password= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + if (pathInfo.equals("/login_check")) { + try { + String username = request.getParameter("login_username"); + String password = request.getParameter("login_password"); + + conn = connector.getConnection (); + + PreparedStatement stmt = conn.prepareStatement("SELECT username, full_name , avatar FROM user WHERE username=? AND password=?;"); + stmt.setString(1, username); + stmt.setString(2, password); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + + String fullname = ""; + String avatar = ""; + while (rs.next()) { + fullname = rs.getString(2); + avatar = rs.getString(3); + } + + if (!fullname.equals("")) { + out.println(fullname + "," + avatar); + } + else { + out.println("failed"); + } + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/user/register + * requestParameter : signup_username=&signup_password=&signup_long_name=&signup_email=&signup_birth_date=signup_avatar_upload= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/register")) { + try { + String username = request.getParameter("signup_username"); + String password = request.getParameter("signup_password"); + String fullname = request.getParameter("signup_long_name"); + String email = request.getParameter("signup_email"); + String birthdate = request.getParameter("signup_birth_date"); + //Blob avatar = req.getParameter("signup_avatar_upload"); + + conn = connector.getConnection (); + Statement st = conn.createStatement(); + st.executeUpdate("INSERT INTO user VALUES ('" + username + "','" + password + "','" + fullname + "','" + birthdate + "','NULL','" + email + "')"); + + if (conn != null) { + //Berhasil register + HttpSession session = request.getSession(true); + session.setAttribute("username", username); + session.setAttribute("fullname", fullname); + response.sendRedirect("../src/dashboard.jsp"); + } else { + //Gagal register + response.sendRedirect("../index.jsp?register_status=failed"); + } + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/user/user_detail + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/user_detail")) { + try { + String username = request.getParameter("username"); + conn = connector.getConnection (); + + PreparedStatement stmt = conn.prepareStatement("SELECT * FROM user WHERE username=?;"); + stmt.setString(1, username); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + + while (rs.next()) { + String password = rs.getString(2); + String fullname = rs.getString(3); + String birthdate = rs.getString(4); + String avatar = rs.getString(5); + String email = rs.getString(6); + + JSONObject userObject = new JSONObject(); + userObject.put("username", username); + userObject.put("password", password); + userObject.put("fullname", fullname); + userObject.put("birthdate", birthdate); + userObject.put("avatar", avatar); + userObject.put("email", email); + out.println(userObject); + } + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/user/update_profile + * requestParameter : username=&password=&fullname=&birthdate=&avatar= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/update_profile")) { + try { + String username = request.getParameter("username"); + String password = request.getParameter("password"); + String fullname = request.getParameter("fullname"); + String birthdate = request.getParameter("birthdate"); + String avatar = request.getParameter("avatar"); + + conn = connector.getConnection(); + PreparedStatement stmt = conn.prepareStatement(""); + + if (!"".equals(avatar)) { + stmt = conn.prepareStatement("UPDATE user SET avatar=? WHERE username=?"); + stmt.setString(1, avatar); + stmt.setString(2, username); + } + stmt.executeUpdate(); + + if (!("".equals(password))) { + stmt = conn.prepareStatement("UPDATE user SET full_name=?, birthdate=?, password=? WHERE username=?"); + stmt.setString(1, fullname); + stmt.setString(2, birthdate); + stmt.setString(3, password); + stmt.setString(4, username); + } else { + stmt = conn.prepareStatement("UPDATE user SET full_name=?, birthdate=? WHERE username=?"); + stmt.setString(1, fullname); + stmt.setString(2, birthdate); + stmt.setString(3, username); + } + + int row = stmt.executeUpdate(); + out.println(row); //1 = berhasil, 0 = failed + + } catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + /* + * pathInfo : baseURL/user/current_task + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/current_task")) { + try { + String username = request.getParameter("username"); + conn = connector.getConnection (); + + PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT task.task_name, task.task_id, task.task_status FROM task_asignee LEFT JOIN task ON task.task_id=task_asignee.task_id WHERE username=? OR task_creator=?"); + stmt.setString(1, username); + stmt.setString(2, username); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + JSONArray currentTaskArray = new JSONArray(); + while (rs.next()) { + if ("0".equals(rs.getString("task_status"))) { + JSONObject currentTask = new JSONObject(); + currentTask.put("task_name", rs.getString("task_name")); + currentTask.put("task_id", rs.getString("task_id")); + currentTaskArray.put(currentTask); + } + } + out.println(currentTaskArray); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/user/finished_task + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/finished_task")) { + try { + String username = request.getParameter("username"); + conn = connector.getConnection (); + + PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT task.task_name, task.task_id, task.task_status FROM task_asignee LEFT JOIN task ON task.task_id=task_asignee.task_id WHERE username=? OR task_creator=?"); + stmt.setString(1, username); + stmt.setString(2, username); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + JSONArray finishedTaskArray = new JSONArray(); + while (rs.next()) { + if ("1".equals(rs.getString("task_status"))) { + JSONObject finishedTask = new JSONObject(); + finishedTask.put("task_name", rs.getString("task_name")); + finishedTask.put("task_id", rs.getString("task_id")); + finishedTaskArray.put(finishedTask); + } + } + out.println(finishedTaskArray); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/user/autocomplete + * requestParameter : keyword= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/autocomplete")) { + try { + String keyword = request.getParameter("keyword"); + conn = connector.getConnection (); + PreparedStatement stmt = conn.prepareStatement(""); + ResultSet rs = null; + String HTMLresult = ""; + + //Search User + stmt = conn.prepareStatement("SELECT distinct full_name, username FROM user WHERE username LIKE ? OR email LIKE ? OR full_name LIKE ? OR birthdate LIKE ?;"); + stmt.setString(1, "%" + keyword + "%"); //username + stmt.setString(2, "%" + keyword + "%"); //email + stmt.setString(3, "%" + keyword + "%"); //full_name + stmt.setString(4, "%" + keyword + "%"); //birthdate + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "<br>"; + } + //HTMLresult += "<div class='search_recommend' onclick=\"javascript:searchResult('"+rs.getString("username")+"','user');\">"+ rs.getString("full_name") +"</div>"; + HTMLresult = HTMLresult + "<div class='search_recommend' id='edittask_ass_"+rs.getString("username")+"' onclick=\"javascript:addEditTaskAssigne('"+rs.getString("username")+"');\">"+rs.getString("username")+"</div>"; + } + out.println(HTMLresult); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> + /** + * Handles the HTTP + * <code>GET</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * <code>POST</code> method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// </editor-fold> +} diff --git a/eurilys4-service/src/java/service/dbConnection.java b/eurilys4-service/src/java/service/dbConnection.java new file mode 100644 index 00000000..cfa3b42b --- /dev/null +++ b/eurilys4-service/src/java/service/dbConnection.java @@ -0,0 +1,38 @@ +package service; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import org.json.*; + +public class dbConnection { + + public dbConnection() {} + + public Connection getConnection () throws SQLException, ClassNotFoundException { + String jsonMsg = "{\"mysql-5.1\":[{\"name\":\"mysql-4f700\",\"label\":\"mysql-5.1\",\"plan\":\"free\",\"tags\":[\"mysql\",\"mysql-5.1\",\"relational\"],\"credentials\":{\"name\":\"progin_405_13510086\",\"hostname\":\"localhost\",\"host\":\"localhost\",\"port\":3306,\"user\":\"root\",\"username\":\"root\",\"password\":\"\"}}]}"; + //String jsonMsg = java.lang.System.getenv("VCAP_SERVICES"); + JSONTokener tokener = new JSONTokener(jsonMsg); + JSONObject root = new JSONObject(tokener); + + JSONArray mysql51 = root.getJSONArray("mysql-5.1"); + JSONObject credentials = mysql51.getJSONObject(0).getJSONObject("credentials"); + String db_username = credentials.getString("username"); + String db_password = credentials.getString("password"); + String db_hostname = credentials.getString("hostname"); + int db_port = credentials.getInt("port"); + String db_name = credentials.getString("name"); + /* + System.out.println("Username : " + db_username); + System.out.println("Password : " + db_password); + System.out.println("Hostname : " + db_hostname); + System.out.println("Port : " + db_port); + System.out.println("Name : " + db_name); */ + + String connectionURL = "jdbc:mysql://"+db_hostname+":"+db_port+"/"+db_name; + Connection conn = null; + Class.forName("com.mysql.jdbc.Driver"); + conn = DriverManager.getConnection(connectionURL,db_username,db_password); + return conn; + } +} diff --git a/eurilys4-service/web/META-INF/context.xml b/eurilys4-service/web/META-INF/context.xml new file mode 100644 index 00000000..4c8ded45 --- /dev/null +++ b/eurilys4-service/web/META-INF/context.xml @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Context antiJARLocking="true" path="/eurilys4-service"/> diff --git a/eurilys4-service/web/WEB-INF/web.xml b/eurilys4-service/web/WEB-INF/web.xml new file mode 100644 index 00000000..dddb4cda --- /dev/null +++ b/eurilys4-service/web/WEB-INF/web.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + <servlet> + <servlet-name>ServletHandler</servlet-name> + <servlet-class>servlet.ServletHandler</servlet-class> + </servlet> + <servlet> + <servlet-name>UserService</servlet-name> + <servlet-class>service.UserService</servlet-class> + </servlet> + <servlet> + <servlet-name>BasicServlet</servlet-name> + <servlet-class>service.BasicServlet</servlet-class> + </servlet> + <servlet> + <servlet-name>TaskService</servlet-name> + <servlet-class>service.TaskService</servlet-class> + </servlet> + <servlet> + <servlet-name>CategoryService</servlet-name> + <servlet-class>service.CategoryService</servlet-class> + </servlet> + <servlet> + <servlet-name>SearchService</servlet-name> + <servlet-class>service.SearchService</servlet-class> + </servlet> + <servlet> + <servlet-name>SOAPAddTask</servlet-name> + <servlet-class>service.SOAPAddTask</servlet-class> + </servlet> + <servlet> + <servlet-name>SOAPAddCategory</servlet-name> + <servlet-class>service.SOAPAddCategory</servlet-class> + </servlet> + <servlet> + <servlet-name>SOAPAddComment</servlet-name> + <servlet-class>service.SOAPAddComment</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>ServletHandler</servlet-name> + <url-pattern>/ServletHandler</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>UserService</servlet-name> + <url-pattern>/user/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>BasicServlet</servlet-name> + <url-pattern>/BasicServlet</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>TaskService</servlet-name> + <url-pattern>/task/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>CategoryService</servlet-name> + <url-pattern>/category/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>SearchService</servlet-name> + <url-pattern>/search/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>SOAPAddTask</servlet-name> + <url-pattern>/SOAPAddTask</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>SOAPAddCategory</servlet-name> + <url-pattern>/SOAPAddCategory</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>SOAPAddComment</servlet-name> + <url-pattern>/SOAPAddComment</url-pattern> + </servlet-mapping> + <session-config> + <session-timeout> + 30 + </session-timeout> + </session-config> +</web-app> diff --git a/eurilys4-service/web/index.jsp b/eurilys4-service/web/index.jsp new file mode 100644 index 00000000..1b081bd9 --- /dev/null +++ b/eurilys4-service/web/index.jsp @@ -0,0 +1,17 @@ +<%-- + Document : index + Created on : Apr 30, 2013, 4:11:01 PM + Author : Compaq +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <title>JSP Page + + +

Hello World!

+ + diff --git a/eurilys4/build.xml b/eurilys4/build.xml new file mode 100644 index 00000000..77c2d34e --- /dev/null +++ b/eurilys4/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project eurilys4. + + + diff --git a/eurilys4/build/web/META-INF/MANIFEST.MF b/eurilys4/build/web/META-INF/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/eurilys4/build/web/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/eurilys4/build/web/META-INF/context.xml b/eurilys4/build/web/META-INF/context.xml new file mode 100644 index 00000000..28c69a97 --- /dev/null +++ b/eurilys4/build/web/META-INF/context.xml @@ -0,0 +1,2 @@ + + diff --git a/eurilys4/build/web/WEB-INF/classes/.netbeans_automatic_build b/eurilys4/build/web/WEB-INF/classes/.netbeans_automatic_build new file mode 100644 index 00000000..e69de29b diff --git a/eurilys4/build/web/WEB-INF/classes/.netbeans_update_resources b/eurilys4/build/web/WEB-INF/classes/.netbeans_update_resources new file mode 100644 index 00000000..e69de29b diff --git a/eurilys4/build/web/WEB-INF/classes/Function/FileManager.class b/eurilys4/build/web/WEB-INF/classes/Function/FileManager.class new file mode 100644 index 00000000..ca605fed Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/Function/FileManager.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/CDL.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/CDL.rs new file mode 100644 index 00000000..a3710a79 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/CDL.rs @@ -0,0 +1 @@ +org.json.CDL diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/Cookie.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/Cookie.rs new file mode 100644 index 00000000..571c1181 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/Cookie.rs @@ -0,0 +1 @@ +org.json.Cookie diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/CookieList.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/CookieList.rs new file mode 100644 index 00000000..a48aac42 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/CookieList.rs @@ -0,0 +1 @@ +org.json.CookieList diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/HTTP.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/HTTP.rs new file mode 100644 index 00000000..83fe1909 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/HTTP.rs @@ -0,0 +1 @@ +org.json.HTTP diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/HTTPTokener.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/HTTPTokener.rs new file mode 100644 index 00000000..a0637fec --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/HTTPTokener.rs @@ -0,0 +1 @@ +org.json.HTTPTokener diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONArray.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONArray.rs new file mode 100644 index 00000000..6793286f --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONArray.rs @@ -0,0 +1 @@ +org.json.JSONArray diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONException.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONException.rs new file mode 100644 index 00000000..82f20cb3 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONException.rs @@ -0,0 +1 @@ +org.json.JSONException diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONML.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONML.rs new file mode 100644 index 00000000..81987b67 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONML.rs @@ -0,0 +1 @@ +org.json.JSONML diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONObject.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONObject.rs new file mode 100644 index 00000000..d6cb8c81 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONObject.rs @@ -0,0 +1,2 @@ +org.json.JSONObject +org.json.JSONObject$Null diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONString.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONString.rs new file mode 100644 index 00000000..3d4d07c4 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONString.rs @@ -0,0 +1 @@ +org.json.JSONString diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONStringer.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONStringer.rs new file mode 100644 index 00000000..e2045850 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONStringer.rs @@ -0,0 +1 @@ +org.json.JSONStringer diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONTokener.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONTokener.rs new file mode 100644 index 00000000..df25afd9 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONTokener.rs @@ -0,0 +1 @@ +org.json.JSONTokener diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONWriter.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONWriter.rs new file mode 100644 index 00000000..1335350b --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/JSONWriter.rs @@ -0,0 +1 @@ +org.json.JSONWriter diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/Kim.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/Kim.rs new file mode 100644 index 00000000..59aa7a0c --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/Kim.rs @@ -0,0 +1 @@ +org.json.Kim diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/README b/eurilys4/build/web/WEB-INF/classes/jsonlib/README new file mode 100644 index 00000000..b77c71a2 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/README @@ -0,0 +1,68 @@ +JSON in Java [package org.json] + +Douglas Crockford +douglas@crockford.com + +2011-02-02 + + +JSON is a light-weight, language independent, data interchange format. +See http://www.JSON.org/ + +The files in this package implement JSON encoders/decoders in Java. +It also includes the capability to convert between JSON and XML, HTTP +headers, Cookies, and CDL. + +This is a reference implementation. There is a large number of JSON packages +in Java. Perhaps someday the Java community will standardize on one. Until +then, choose carefully. + +The license includes this restriction: "The software shall be used for good, +not evil." If your conscience cannot live with that, then choose a different +package. + +The package compiles on Java 1.2 thru Java 1.4. + + +JSONObject.java: The JSONObject can parse text from a String or a JSONTokener +to produce a map-like object. The object provides methods for manipulating its +contents, and for producing a JSON compliant object serialization. + +JSONArray.java: The JSONObject can parse text from a String or a JSONTokener +to produce a vector-like object. The object provides methods for manipulating +its contents, and for producing a JSON compliant array serialization. + +JSONTokener.java: The JSONTokener breaks a text into a sequence of individual +tokens. It can be constructed from a String, Reader, or InputStream. + +JSONException.java: The JSONException is the standard exception type thrown +by this package. + + +JSONString.java: The JSONString interface requires a toJSONString method, +allowing an object to provide its own serialization. + +JSONStringer.java: The JSONStringer provides a convenient facility for +building JSON strings. + +JSONWriter.java: The JSONWriter provides a convenient facility for building +JSON text through a writer. + + +CDL.java: CDL provides support for converting between JSON and comma +delimited lists. + +Cookie.java: Cookie provides support for converting between JSON and cookies. + +CookieList.java: CookieList provides support for converting between JSON and +cookie lists. + +HTTP.java: HTTP provides support for converting between JSON and HTTP headers. + +HTTPTokener.java: HTTPTokener extends JSONTokener for parsing HTTP headers. + +XML.java: XML provides support for converting between JSON and XML. + +JSONML.java: JSONML provides support for converting between JSONML and XML. + +XMLTokener.java: XMLTokener extends JSONTokener for parsing XML text. diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/XML.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/XML.rs new file mode 100644 index 00000000..631ca87d --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/XML.rs @@ -0,0 +1 @@ +org.json.XML diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/XMLTokener.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/XMLTokener.rs new file mode 100644 index 00000000..a41502d6 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/XMLTokener.rs @@ -0,0 +1 @@ +org.json.XMLTokener diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitInputStream.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitInputStream.rs new file mode 100644 index 00000000..9c7eadd4 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitInputStream.rs @@ -0,0 +1 @@ +org.json.zip.BitInputStream diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitOutputStream.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitOutputStream.rs new file mode 100644 index 00000000..d34c8e32 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitOutputStream.rs @@ -0,0 +1 @@ +org.json.zip.BitOutputStream diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitReader.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitReader.rs new file mode 100644 index 00000000..f9abae2b --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitReader.rs @@ -0,0 +1 @@ +org.json.zip.BitReader diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitWriter.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitWriter.rs new file mode 100644 index 00000000..4a7f98f2 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/BitWriter.rs @@ -0,0 +1 @@ +org.json.zip.BitWriter diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Compressor.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Compressor.rs new file mode 100644 index 00000000..39140536 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Compressor.rs @@ -0,0 +1 @@ +org.json.zip.Compressor diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Decompressor.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Decompressor.rs new file mode 100644 index 00000000..8c1c2ed9 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Decompressor.rs @@ -0,0 +1 @@ +org.json.zip.Decompressor diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Huff.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Huff.rs new file mode 100644 index 00000000..64299f50 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Huff.rs @@ -0,0 +1,2 @@ +org.json.zip.Huff$Symbol +org.json.zip.Huff diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/JSONzip.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/JSONzip.rs new file mode 100644 index 00000000..e58f733a --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/JSONzip.rs @@ -0,0 +1 @@ +org.json.zip.JSONzip diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Keep.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Keep.rs new file mode 100644 index 00000000..1eb6bf30 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/Keep.rs @@ -0,0 +1 @@ +org.json.zip.Keep diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/MapKeep.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/MapKeep.rs new file mode 100644 index 00000000..b193c020 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/MapKeep.rs @@ -0,0 +1 @@ +org.json.zip.MapKeep diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/None.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/None.rs new file mode 100644 index 00000000..44be7ce0 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/None.rs @@ -0,0 +1 @@ +org.json.zip.None diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/PostMortem.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/PostMortem.rs new file mode 100644 index 00000000..5569b1f3 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/PostMortem.rs @@ -0,0 +1 @@ +org.json.zip.PostMortem diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/README b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/README new file mode 100644 index 00000000..93e6470b --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/README @@ -0,0 +1,2 @@ +FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT BEEN TESTED ADEQUATELY FOR +PRODUCTION USE. diff --git a/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/TrieKeep.rs b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/TrieKeep.rs new file mode 100644 index 00000000..2899c6e7 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/classes/jsonlib/zip/TrieKeep.rs @@ -0,0 +1,2 @@ +org.json.zip.TrieKeep$Node +org.json.zip.TrieKeep diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/CDL.class b/eurilys4/build/web/WEB-INF/classes/org/json/CDL.class new file mode 100644 index 00000000..4beb9950 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/CDL.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/Cookie.class b/eurilys4/build/web/WEB-INF/classes/org/json/Cookie.class new file mode 100644 index 00000000..7899f2c9 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/Cookie.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/CookieList.class b/eurilys4/build/web/WEB-INF/classes/org/json/CookieList.class new file mode 100644 index 00000000..7e850b56 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/CookieList.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/HTTP.class b/eurilys4/build/web/WEB-INF/classes/org/json/HTTP.class new file mode 100644 index 00000000..176c6cba Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/HTTP.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/HTTPTokener.class b/eurilys4/build/web/WEB-INF/classes/org/json/HTTPTokener.class new file mode 100644 index 00000000..e21a8139 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/HTTPTokener.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONArray.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONArray.class new file mode 100644 index 00000000..6db7705c Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONArray.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONException.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONException.class new file mode 100644 index 00000000..762a6377 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONException.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONML.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONML.class new file mode 100644 index 00000000..1b256170 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONML.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONObject$1.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONObject$1.class new file mode 100644 index 00000000..64c0e8fc Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONObject$1.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONObject$Null.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONObject$Null.class new file mode 100644 index 00000000..9450e095 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONObject$Null.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONObject.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONObject.class new file mode 100644 index 00000000..325831fc Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONObject.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONString.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONString.class new file mode 100644 index 00000000..329f6867 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONString.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONStringer.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONStringer.class new file mode 100644 index 00000000..292cfa50 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONStringer.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONTokener.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONTokener.class new file mode 100644 index 00000000..66964392 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONTokener.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/JSONWriter.class b/eurilys4/build/web/WEB-INF/classes/org/json/JSONWriter.class new file mode 100644 index 00000000..00ebbbc3 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/JSONWriter.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/Kim.class b/eurilys4/build/web/WEB-INF/classes/org/json/Kim.class new file mode 100644 index 00000000..3c533420 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/Kim.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/XML.class b/eurilys4/build/web/WEB-INF/classes/org/json/XML.class new file mode 100644 index 00000000..753d7c7f Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/XML.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/XMLTokener.class b/eurilys4/build/web/WEB-INF/classes/org/json/XMLTokener.class new file mode 100644 index 00000000..4284aeab Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/XMLTokener.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitInputStream.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitInputStream.class new file mode 100644 index 00000000..7c4f81e6 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitInputStream.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitOutputStream.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitOutputStream.class new file mode 100644 index 00000000..cb46e318 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitOutputStream.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitReader.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitReader.class new file mode 100644 index 00000000..58013572 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitReader.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitWriter.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitWriter.class new file mode 100644 index 00000000..b31e26bf Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/BitWriter.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/Compressor.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Compressor.class new file mode 100644 index 00000000..748559fe Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Compressor.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/Decompressor.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Decompressor.class new file mode 100644 index 00000000..1900fdbc Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Decompressor.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/Huff$Symbol.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Huff$Symbol.class new file mode 100644 index 00000000..79564bf8 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Huff$Symbol.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/Huff.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Huff.class new file mode 100644 index 00000000..8bb1b9d7 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Huff.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/JSONzip.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/JSONzip.class new file mode 100644 index 00000000..a4c09c35 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/JSONzip.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/Keep.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Keep.class new file mode 100644 index 00000000..fd3244f2 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/Keep.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/MapKeep.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/MapKeep.class new file mode 100644 index 00000000..15202ba8 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/MapKeep.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/None.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/None.class new file mode 100644 index 00000000..de9a878c Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/None.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/PostMortem.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/PostMortem.class new file mode 100644 index 00000000..8a3ca8ce Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/PostMortem.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/TrieKeep$Node.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/TrieKeep$Node.class new file mode 100644 index 00000000..96583d87 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/TrieKeep$Node.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/org/json/zip/TrieKeep.class b/eurilys4/build/web/WEB-INF/classes/org/json/zip/TrieKeep.class new file mode 100644 index 00000000..8f12032b Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/org/json/zip/TrieKeep.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/service/CategoryService.class b/eurilys4/build/web/WEB-INF/classes/service/CategoryService.class new file mode 100644 index 00000000..651d6049 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/service/CategoryService.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/service/SearchService.class b/eurilys4/build/web/WEB-INF/classes/service/SearchService.class new file mode 100644 index 00000000..c2a4f1d5 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/service/SearchService.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/service/TaskService.class b/eurilys4/build/web/WEB-INF/classes/service/TaskService.class new file mode 100644 index 00000000..60967a98 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/service/TaskService.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/service/UserService.class b/eurilys4/build/web/WEB-INF/classes/service/UserService.class new file mode 100644 index 00000000..6120351b Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/service/UserService.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/service/dbConnection.class b/eurilys4/build/web/WEB-INF/classes/service/dbConnection.class new file mode 100644 index 00000000..86ee5b51 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/service/dbConnection.class differ diff --git a/eurilys4/build/web/WEB-INF/classes/servlet/ServletHandler.class b/eurilys4/build/web/WEB-INF/classes/servlet/ServletHandler.class new file mode 100644 index 00000000..16bfb18a Binary files /dev/null and b/eurilys4/build/web/WEB-INF/classes/servlet/ServletHandler.class differ diff --git a/eurilys4/build/web/WEB-INF/lib/activation.jar b/eurilys4/build/web/WEB-INF/lib/activation.jar new file mode 100644 index 00000000..7b5cac39 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/lib/activation.jar differ diff --git a/eurilys4/build/web/WEB-INF/lib/jsr311-api-1.1.1.jar b/eurilys4/build/web/WEB-INF/lib/jsr311-api-1.1.1.jar new file mode 100644 index 00000000..2a55bcdd Binary files /dev/null and b/eurilys4/build/web/WEB-INF/lib/jsr311-api-1.1.1.jar differ diff --git a/eurilys4/build/web/WEB-INF/lib/mysql-connector-java-5.1.18-bin.jar b/eurilys4/build/web/WEB-INF/lib/mysql-connector-java-5.1.18-bin.jar new file mode 100644 index 00000000..d2b0e180 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/lib/mysql-connector-java-5.1.18-bin.jar differ diff --git a/eurilys4/build/web/WEB-INF/lib/webservices-api.jar b/eurilys4/build/web/WEB-INF/lib/webservices-api.jar new file mode 100644 index 00000000..56f6c249 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/lib/webservices-api.jar differ diff --git a/eurilys4/build/web/WEB-INF/lib/webservices-extra-api.jar b/eurilys4/build/web/WEB-INF/lib/webservices-extra-api.jar new file mode 100644 index 00000000..51d6ec90 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/lib/webservices-extra-api.jar differ diff --git a/eurilys4/build/web/WEB-INF/lib/webservices-extra.jar b/eurilys4/build/web/WEB-INF/lib/webservices-extra.jar new file mode 100644 index 00000000..f92db172 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/lib/webservices-extra.jar differ diff --git a/eurilys4/build/web/WEB-INF/lib/webservices-rt.jar b/eurilys4/build/web/WEB-INF/lib/webservices-rt.jar new file mode 100644 index 00000000..c2d83fd7 Binary files /dev/null and b/eurilys4/build/web/WEB-INF/lib/webservices-rt.jar differ diff --git a/eurilys4/build/web/WEB-INF/lib/webservices-tools.jar b/eurilys4/build/web/WEB-INF/lib/webservices-tools.jar new file mode 100644 index 00000000..646e1f6f Binary files /dev/null and b/eurilys4/build/web/WEB-INF/lib/webservices-tools.jar differ diff --git a/eurilys4/build/web/WEB-INF/web.xml b/eurilys4/build/web/WEB-INF/web.xml new file mode 100644 index 00000000..027adf28 --- /dev/null +++ b/eurilys4/build/web/WEB-INF/web.xml @@ -0,0 +1,64 @@ + + + + SOAPService + servlet.SOAPService + + + ServletHandler + servlet.ServletHandler + + + UserService + service.UserService + + + BasicServlet + service.BasicServlet + + + TaskService + service.TaskService + + + CategoryService + service.CategoryService + + + SearchService + service.SearchService + + + SOAPService + /SOAPService + + + ServletHandler + /ServletHandler + + + UserService + /user/* + + + BasicServlet + /BasicServlet + + + TaskService + /task/* + + + CategoryService + /category/* + + + SearchService + /search/* + + + + 30 + + + diff --git a/eurilys4/build/web/css/desktop_style.css b/eurilys4/build/web/css/desktop_style.css new file mode 100644 index 00000000..fec9e336 --- /dev/null +++ b/eurilys4/build/web/css/desktop_style.css @@ -0,0 +1,844 @@ +@media screen and (min-width: 960px) and (max-width: 1200px){ + +html {width:100%; height:100%; overflow-x:hidden; font-family:Segoe UI; font-weight: lighter;} +body {width:100%; height:300px; display:block; margin:0px; + /*background-image:url('../img/bg.jpg');*/ + background-color:#F3E8E6; +} + +h1{ + + font-size: 35px; + padding-left: 20px; + color: #FF5544; +} + +/* HEADER SECTION +------------------------------------------------------------------------------------------- */ +.search_recommend { + cursor:pointer; + display:block; + margin-bottom:2px; + width:100%; + color:gray; +} + +header { + width:100%; + height:90px; + background-color:#3f3f7a; + display:block; +} +.header_menu a { + color:white; + text-decoration:none; +} + +textarea { + font-family:Segoe UI; font-weight:lighter; +} + +#header_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; +} + +#login_form_container { + position:relative; + background-color:#3f3f7a; + float:right; + width:90%; + height:130px; + margin-right:5%; + z-index:100; +} +#login_form { + font-family:Segoe UI; font-weight:lighter;; + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:15px; + z-index:200; +} +#login_form label { + color:#fff; + float:left; + width:35%; + margin-left:3px; +} + +#login_username , #login_password { + color:gray; + float:left; + margin-left:7px; + width:55%; +} +#login_submit { + float:right; + margin-right:5%; +} +.login_reg_warning { + color:red; + width:90%; + font-style: italic; +} + +input#remember_me { + margin-top:20px;float:left; + width:auto; +} +label#remember_me { + float:left; font-size:12px; width:auto; margin-top:-20px; +} + +#edit_profil_container {width:90%; margin:auto; display:block;} +#edit_profil_container h3 {color:#007bc1;} +#edit_profile_form { + width:70%; + margin-top:20px; + margin-left:20px; +} +#edit_profile_form label { + float:left; + font-size:16px; + font-family:Segoe UI; + font-weight:lighter; + color:gray; + width:28%; +} + +#edit_profile_submit { + float:right; + margin-right:5%; +} + +#edit_profile_form input { + float:left; + height:28px; + font-size:17px; + width:60%; + margin-bottom:10px; +} + +#edit_profile_form input#edit_profile_submit { + float:right; + height:35px; + font-size:20px; + width:40%; + margin-bottom:10px; +} + +.header_menu a { + color:white; + text-decoration:none; +} +.header_menu { + float:right; margin-top:30px;height:60%; width:45%; + +} +.header_menu_button { + padding-top:8px; padding-bottom:8px; + width:28%; display:block;color:white; + margin-left:20px;margin-top:8px; text-align:center; + font-size:18px; cursor:pointer; float:left; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} +.header_menu_button:hover , .header_menu_button:active { + background-color:#6FBEC6;text-decoration:none; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} + +.header_menu_button:hover{background-color:#ff5645;} + +.current_header_menu { + background-color:#6FBEC6; +} +#search_box { + float:left; margin-left:45px; height:25px; margin-top:45px; width:20%; +} +#search_box_filter { + float:left; height:30px; margin-top:45px; margin-left:5px; +} +#txtHint , #category_asignee_autocomplete , #add_task_asignee_autocomplete , #edit_task_asignee_autocomplete { + position:absolute; + display:block; + margin-top:73px; + margin-left:275px; + width:16%; + z-index:300; + color:gray; + border:solid 1px #dedede; + overflow:hidden; + border-bottom-right-radius: 6px; + border-bottom-left-radius: 6px; + -moz-border-bottom-right-radius: 6px; + -moz-border-bottom-left-radius: 6px; + box-shadow: 0px 0px 5px #999; + border-width: 3px 1px 1px; + border-style: solid; + border-color: #333 #DEDEDE #DEDEDE; + background-color: white; +} + +/* LOGO +----------------------------------------------------------------------------------------------------------------- */ +#fleur { + font-size:100px; + color:#FF5544; + display:inline-block; +} +#textdesu{ + color:#fff; + display:inline-block; + font-size:60px; + letter-spacing:-6px; + font-family:Trajan Pro; + margin-left:-10px; +} +#tagline { + font-family:Times New Roman; + font-size:12px; + letter-spacing:2px; + font-style:italic; + margin-top:-20px; + margin-left:15px; + color:#fff; +} + +/* SECTION +--------------------------------------------------------------------------------------------------------------------- */ +section {width:80%;background-color:#F9F9F9; height:680px; margin-left:auto; margin-right:auto; margin-top:40px; margin-bottom:40px; z-index:1; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} + +#index_left { + height:100%; + width:65%; + background-color:#f9f9f9; + float:left; +} +#index_right { + height:100%; + width:35%; + float:left; + padding-top:40px; +} +.signup_label { + width:65%; + background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; + border:none; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + margin-left:auto;margin-right:auto; letter-spacing:1px; + text-align:center; + font-size:25px; + font-family:Segoe UI; font-weight:lighter;; + font-weight:bold; + margin-top:170px; +} +#signup_form_container { + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:10px; + background-color:#EBEBE9; + color:gray; + padding-top:20px; + height:350px; + display:block; +} +#signup_form { + width:90%; + margin-top:20px; + margin-left:20px; +} +#signup_form label { + float:left; + font-size:16px; + font-family:Segoe UI; font-weight:lighter;; + color:gray; + width:28%; +} +#signup_form input { + float:left; + height:20px; + font-size:20px; + width:60%; + margin-bottom:10px; +} +.signup_form_validation { + display:none; + padding-left:10px; + padding-top:5px; + padding-bottom:14px; +} +input#avatar_upload {font-size:12px;} + +#tutorial { + text-align:justify; + text-justify:inter-word; +} + +#tutorial_image { + width:100%; +} + +/* FOOTER SECTION +--------------------------------------------------------------------------------------------------------------------- */ +#footer_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; + color:#fff; + font-size:12px; + text-align:center; +} + +footer { + width:100%; + background-color:#3f3f7a; + height:80px; + display:block; + bottom:0px; +} + +/* NAVIGATION BAR +--------------------------------------------------------------------------------------------------------------------- */ +#navbar { + margin-left:auto; + display:block; + height:100%; + width:25%; + float:left; +} +#short_profile { + margin-top:30px; + width:80%; + margin-left:auto; + margin-right:auto; + height:150px; +} +#profile_picture { + width:100px; + float:left; +} +#mainpp { + max-width: 300px; +} +#profile_info { + margin-left:120px; + float:left; + color:gray; + font-size:14px; + color:gray; + width:120px; + position:absolute; +} +#profile_pic_upload { + clear:both; + margin-top:20px; +} +#category_list { + width:80%; + margin-left:auto; + margin-right:auto; +} +#category_list a { + color:#fff; + text-decoration:none; +} +#category_list ul { + list-style-image:url('../img/arrow.png'); + padding-top:5px; + margin-left:-10px; +} +#category_list ul li a { + cursor:pointer; + color:#6FBEC6; + padding-bottom:5px; +} +#category_list ul li a:hover { + color:#fff; +} + +#category_list ul li a:active{ + color:#ff5645; +} +#add_new_category , #add_task_link{ + color:gray; + cursor:pointer; +} +#add_task_link:hover , #add_new_category:hover { + color:#FF5544; +} +#add_task_link {display:none;} +#add_task_link a { + color:gray; + text-decoration:none; +} +#add_task_link a:hover { + color:#ff5544; +} + +#category_form { + width:100%; + height:180px; + background-color:#6FBEC6; + margin-top:5px; + color:#fff; + padding-top:15px; + display:none; +} +#category_form_inner { + width:90%; + height:90%; + margin:auto; +} +#category_form_inner input { + width:95%; +} +#category_item { + margin-top:5px; +} +#current_category { + color:#6FBEC6; +} + +#add_category { + font-size:11px; + cursor:pointer; +} +#add_category:hover { + color:gray; +} +#add_category_button { + width:80px; + text-align:center; +} +#category_title { + text-align:center; + padding-top:5px; + padding-bottom:5px; +} + +/* TASK DETAIL +--------------------------------------------------------------------------------------------------------------------- */ +#comment_textarea { + width:70%; + height:100px; + resize:none; +} + +#save_button_td { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +#save_edit_task { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:100px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +#task_attachment:hover { + color:#ff5544; +} + +#save_button_td:hover , #save_edit_task:hover{ + border-color:#0092dd; +} + +#edit_task_button, #save_edit_task { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +.edit_task_input {width:100%;} +#edit_task_button:hover { + border-color:#0092dd; +} + +#taskdetail_image { + height:100%; + width:auto; +} +.taskDetail { + width:90%; + margin:auto; +} + +/* ADD TASK +--------------------------------------------------------------------------------------------------------------------- */ +#task_name_input, #assignee_input, #deadline_input, #tag_input, #attachment_upload { + width:35%; +} +#add_task_button{ + display:block; + margin-left:22%; + border-style:solid; + border-color:#007bc1; + text-align:center; + width:80px; + font-size:15px; + padding-top:5px; + padding-bottom:5px; +} + +#add_task_button:hover { + border-color:#0092dd; +} +#add_task_container { + width:90%; + margin:auto; +} + +/* STYLING +--------------------------------------------------------------------------------------------------------------------- */ +.bold {font-weight:bold;} +.clear {clear:both;} +.left {float:left;} +.right {float:right;} +.left20 {margin-left:50px;} +.top10 {margin-top:10px;} +.top20 {margin-top:20px;} +.top45 {margin-top:45px;} +.top30 {margin-top:30px;} +.width100 {width:130px;} +.line10 {line-height:50%;} +a {text-decoration:none;} +#logout {color:#fff;} +.white {color:#fff;} +.red {color:red;} +.cursorPointer {cursor:pointer;} + +.thin_line {display:block;height:8px;margin-left:0px;width:100%;background-color:#524459;} + +.link_blue {background-color:#007bc1; color:#fff; padding-left:10px; padding-right:10px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none;cursor:pointer; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} +.link_blue:hover{background-color:#0092dd;text-decoration:none;} + +.link_blue_rect { + background-color:#007bc1; + color:#fff; + cursor:pointer; +} +.link_blue_rect:hover{ + background-color:#0092dd; +} + +.link_lightblue {background-color:#6FBEC6; color:#fff; padding-left:25px; padding-right:25px; padding-top:15px; padding-bottom:15px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +font-family:Segoe UI; font-weight:lighter;; margin-left:auto; margin-right:auto; +font-weight:bold; letter-spacing:1px; cursor:pointer; +font-size:20px; +} +.link_lightblue:hover{background-color:#9ad2d8;text-decoration:none;} + +.link_red {background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#ff786b;text-decoration:none;} + +.link_tosca {background-color:#dba8a8;color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_tosca:hover{background-color:#bae4d3;text-decoration:none;} + + +.link_red {background-color:#FA522C; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#FAAA98;text-decoration:none;} + +.darkBlue {color:#007bc1;} +.darkBlueItalic {color:#007bc1; font-style:italic; font-size:13px;} +.darkBlueLink {color:#007bc1; cursor:pointer;} +.userprofile_link {cursor:pointer;} +.userprofile_link:hover {color:#0092dd;} +/* DYNAMIC CONTENT +------------------------------------------------------------------------------------------------- */ +#dynamic_content { + border-left: 2px solid gray; + display:block; + width:73%; + height:100%; + float:right; + overflow:auto; + color:#55565B; + position:relative; +} +.dynamic_content_head { + display:block; + height:30px; + padding-left:2%; + width:75%; + font-weight:bold; +} + +.dynamic_content_row { + display:block; + width:100%; +} + +.dynamic_content_left { + display:block; + width:18%; + padding-left:2%; + font-weight:bold; +} + +.dynamic_content_right { + display:block; + width:74%; + padding-left:2%; + text-align:justify; + text-justify:inter-word; +} +.task_view_category { + float:right; + margin-right:20px; + color:red; +} +.task_view { + width:90%; + display:block; + background-color:white; + opacity:0.8; + padding-top:10px; + padding-bottom:10px; + padding-right:10px; + padding-left:10px; + color:gray; + height:125px; + margin:auto; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; + left:30px; +} +.task_view a:hover { + color:#ff5544; +} + +/* PROFILE CONTENT +------------------------------------------------------------------------------------------------- */ + +#profilebig { + padding:20px; + text-align:center; +} + +#upperprof{ +text-align:center; +} + +#upperprof img { +padding: 4px; +border: 1px solid rgb(204, 204, 204);} + +#namauser{ +width:230px;margin:auto;letter-spacing: 2px;background-color:#007bc1; + color:#fff; +font-size:20px; +text-transform:uppercase;margin-top:-50px;z-index: 99;position:relative; +} + +.headsdeh{ + background-color:#007bc1; + color:#fff; + width:230px; + font-size:17px;margin:auto; +} + +.categoryList, #newCategoryAdded { + display:block;padding:10px; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; + color:#007bc1; + cursor:pointer; +} + +.categoryList:hover, #newCategoryAdded:hover { + background-color:#007bc1; + color:#fff; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; +} + +#login_form input{margin-bottom:5px;} +#edit_profile_button {letter-spacing:0px;padding-left:8px; padding-right:8px;} +#edit_profile_button a {color:#fff; text-decoration:none;} +.ul_none {list-style:none; margin:auto; width:200px; margin-top:5px;} +.ul_none li {text-align:left;} +.red {color:#ff5544; font-weight:bold;} +.blue {color:#007bc1; font-weight:bold;} + +/* MAIN PAGE +--------------------------------------------------------------------------------- */ +#tutorial_container { + width:90%; + margin:auto; + margin-top:60px; + display:block; +} +#tutorial { + width:85%; + display:block; + margin:auto; + margin-top:20px; +} +.task_done_button {float:right;cursor:pointer;font-size:12px;} +.task_done_button:hover {color:#211C18;}; + +/* SCROLL BAR +---------------------------------------------------------------------------------- */ +/* Let's get this party started */ +::-webkit-scrollbar { + width: 12px; +} + +/* Track */ +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); +} + +/* Handle */ +::-webkit-scrollbar-thumb { + background: #A8DBC6; + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); +} +.half_div { + width:49%; + display:block; + float:left; + text-align:center; + margin-top:10%; +} +.half_tall { + height:250px; +} + +/* Search Result +--------------------------------------------------------------------------------- */ +.user_search_result_label { + float:left; + width:160px; + letter-spacing:1px; + display:block; + font-size:18px; + font-weight:bold; + text-align:left; + font-family:Helvetica; +} +.cat_search_result_label { + float:left; + width:170px; + display:block; + font-weight:bold; + text-align:left; +} + +/* MEDIA QUERIES +---------------------------------------------------------------------------------- */ +@media screen and (max-width:480px) { + #signup_form_container, #navbar, #search_box, .header_menu, #remember_me, + #remember_me_check {display:none} + + #index_left{ + height:300px; + width:100%; + } + + #tutorial_container{font-size:12px} + + #index_right{width:100%; margin-top:0px} + + #login_form_container { + width:100%; + float:left; + } + .signup_label{ + width:60%; + } + + div#dynamic_content{ + border-left:none; + width:100%; + } + + div#curtask1.task_view, div#curtask2.task_view, div#curtask3.task_view, + div#curtask4.task_view, div#curtask5.task_view{ + padding:none; + width:80% + } + + .dynamic_content_left{ + font-size:15px; + } + + .dynamic_content_right{ + font-size:15px; + } + + + + +} \ No newline at end of file diff --git a/eurilys4/build/web/css/mobile.css b/eurilys4/build/web/css/mobile.css new file mode 100644 index 00000000..25c08a8b --- /dev/null +++ b/eurilys4/build/web/css/mobile.css @@ -0,0 +1,808 @@ +@media screen and (max-width: 960px){ + +html {width:100%; height:100%; overflow-x:hidden; font-family:Segoe UI; font-weight: lighter;} +body {width:100%; height:300px; display:block; margin:0px;background-image:url('../img/bg.jpg');} + +h1{ + + font-size: 35px; + padding-left: 20px; + color: #FF5544; +} + +/* HEADER SECTION +------------------------------------------------------------------------------------------- */ +header { + width:100%; + height:80px; + background-color:#2a3c28; + display:block; +} +.header_menu a { + color:white; + text-decoration:none; + } + +textarea { + font-family:Segoe UI; font-weight:lighter;; +} + +#header_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; +} + +#login_form_container { + position:relative; + background-color:#2a3c28; + float:right; + width:90%; + height:130px; + margin-right:5%; + z-index:100; +} +#login_form { + font-family:Segoe UI; font-weight:lighter;; + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:15px; + z-index:200; +} +#login_form label { + color:#fff; + float:left; + width:35%; + margin-left:3px; +} + +#login_username , #login_password { + color:gray; + float:left; + margin-left:7px; + width:55%; +} +#login_submit { + float:right; + margin-right:5%; +} + +input#remember_me { + margin-top:20px;float:left; + width:auto; +} +label#remember_me { + float:left; font-size:12px; width:auto; margin-top:-20px; +} + +#edit_profil_container {width:90%; margin:auto; display:block;} +#edit_profil_container h3 {color:#007bc1;} +#edit_profile_form { + width:70%; + margin-top:20px; + margin-left:20px; +} +#edit_profile_form label { + float:left; + font-size:16px; + font-family:Segoe UI; + font-weight:lighter; + color:gray; + width:28%; +} + +#edit_profile_submit { + float:right; + margin-right:5%; +} + +#edit_profile_form input { + float:left; + height:28px; + font-size:17px; + width:60%; + margin-bottom:10px; +} + +#edit_profile_form input#edit_profile_submit { + float:right; + height:35px; + font-size:20px; + width:40%; + margin-bottom:10px; +} + +.header_menu a { + color:white; + text-decoration:none; +} +.header_menu { + float:right; margin-top:20px;height:60%; width:300px; + +} +.header_menu_button { + padding-top:8px; padding-bottom:8px; + width:85px; display:block;color:white; + margin-left:10px;margin-top:8px; text-align:center; + font-size:14px; cursor:pointer; float:left; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} +.header_menu_button:hover , .header_menu_button:active { + background-color:ff3000;text-decoration:none; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} + +.header_menu_button:hover{background-color:#ff5645;} + +.current_header_menu { + background-color:#ff3000; +} +#search_box { + float:left; margin-left:45px; height:25px; margin-top:30px; width:20%; +} +#search_box_filter { + float:left; height:30px; margin-top:30px; margin-left:5px; +} +#txtHint { + position:absolute; + display:block; + color:gray; + margin-top:73px; + margin-left:275px; + width:16%; + z-index:300; + overflow:hidden; + +} +/* LOGO +----------------------------------------------------------------------------------------------------------------- */ +#fleur { + font-size:100px; + color:#FF5544; + display:inline-block; +} +#textdesu{ + color:#fff; + display:inline-block; + font-size:60px; + letter-spacing:-6px; + font-family:Trajan Pro; + margin-left:-10px; +} +#tagline { + font-family:Times New Roman; + font-size:12px; + letter-spacing:2px; + font-style:italic; + margin-top:-20px; + margin-left:15px; + color:#fff; +} + +/* SECTION +--------------------------------------------------------------------------------------------------------------------- */ +section {width:80%;background-color:#F9F9F9; height:680px; margin-left:auto; margin-right:auto; margin-top:40px; margin-bottom:40px; z-index:1; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} + +#index_left { + height:100%; + width:65%; + background-color:#f9f9f9; + float:left; +} +#index_right { + height:100%; + width:35%; + float:left; + padding-top:40px; +} +.signup_label { + width:65%; + background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; + border:none; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + margin-left:auto;margin-right:auto; letter-spacing:1px; + text-align:center; + font-size:25px; + font-family:Segoe UI; font-weight:lighter;; + font-weight:bold; + margin-top:170px; +} +#signup_form_container { + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:10px; + background-color:#EBEBE9; + color:gray; + padding-top:20px; + height:350px; + display:block; +} +#signup_form { + width:90%; + margin-top:20px; + margin-left:20px; +} +#signup_form label { + float:left; + font-size:16px; + font-family:Segoe UI; font-weight:lighter;; + color:gray; + width:28%; +} +#signup_form input { + float:left; + height:20px; + font-size:20px; + width:60%; + margin-bottom:10px; +} +.signup_form_validation { + display:none; + padding-left:10px; + padding-top:5px; + padding-bottom:14px; +} +input#avatar_upload {font-size:12px;} + +#tutorial { + text-align:justify; + text-justify:inter-word; +} + +#tutorial_image { + width:100%; +} + +/* FOOTER SECTION +--------------------------------------------------------------------------------------------------------------------- */ +#footer_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; + color:#fff; + font-size:12px; + text-align:center; +} + +footer { + width:100%; + background-color:#2a3c28; + height:80px; + display:block; + bottom:0px; +} + +/* NAVIGATION BAR +--------------------------------------------------------------------------------------------------------------------- */ +#navbar { + margin-left:auto; + display:block; + height:100%; + width:200px; + float:left; +} +#short_profile { + margin-top:30px; + width:50%; + margin-left:20px; + margin-right:auto; + height:120px; +} +#profile_picture { + width:50px; + float:left; +} +#profile_info { + margin-left:60px; + float:right; + color:gray; + font-size:14px; + color:gray; + width:100px; + position:absolute; +} +#profile_pic_upload { + clear:both; + margin-top:20px; +} +#category_list { + width:80%; + margin-left:auto; + margin-right:auto; +} +#category_list a { + color:#fff; + text-decoration:none; +} +#category_list ul { + list-style-image:url('../img/arrow.png'); + padding-top:5px; + margin-left:-10px; +} +#category_list ul li a { + cursor:pointer; + color:#ff3000; + padding-bottom:5px; +} +#category_list ul li a:hover { + color:#fff; +} + +#category_list ul li a:active{ + color:#ff5645; +} +#add_new_category , #add_task_link{ + color:gray; + cursor:pointer; +} +#add_task_link:hover , #add_new_category:hover { + color:#FF5544; +} +#add_task_link {display:none;} +#add_task_link a { + color:gray; + text-decoration:none; +} +#add_task_link a:hover { + color:#ff5544; +} + +#category_form { + width:100%; + height:180px; + background-color:#ff3000; + margin-top:5px; + color:#fff; + padding-top:15px; + display:none; +} +#category_form_inner { + width:90%; + height:90%; + margin:auto; +} +#category_form_inner input { + width:95%; +} +#category_item { + margin-top:5px; +} +#current_category { + color:#ff3000; +} + +#add_category { + font-size:11px; + cursor:pointer; +} +#add_category:hover { + color:gray; +} +#add_category_button { + width:80px; + text-align:center; +} +#category_title { + text-align:center; + padding-top:5px; + padding-bottom:5px; +} + +/* TASK DETAIL +--------------------------------------------------------------------------------------------------------------------- */ +#comment_textarea { + width:70%; + height:100px; + resize:none; +} + +#save_button_td { + display:none; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +#task_attachment:hover { + color:#ff5544; +} + +#save_button_td:hover { + border-color:#0092dd; +} + +#edit_task_button, #save_edit_task { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} + +#edit_task_button:hover { + border-color:#0092dd; +} + +#taskdetail_image { + height:100%; + width:auto; +} +.taskDetail { + width:90%; + margin:auto; +} + +/* ADD TASK +--------------------------------------------------------------------------------------------------------------------- */ +#task_name_input, #assignee_input, #deadline_input, #tag_input, #attachment_upload { + width:35%; +} +#add_task_button{ + display:block; + margin-left:22%; + border-style:solid; + border-color:#007bc1; + text-align:center; + width:80px; + font-size:15px; + padding-top:5px; + padding-bottom:5px; +} + +#add_task_button:hover { + border-color:#0092dd; +} +#add_task_container { + width:90%; + margin:auto; +} + +/* STYLING +--------------------------------------------------------------------------------------------------------------------- */ +.bold {font-weight:bold;} +.clear {clear:both;} +.left {float:left; +width: 190px; +} +#logo{ +width:190px; +height:75px; +} +.right {float:right;} +.top10 {margin-top:10px;} +.top20 {margin-top:20px;} +.top45 {margin-top:45px;} +.top30 {margin-top:30px;} +.width100 {width:130px;} +.line10 {line-height:50%;} +a {text-decoration:none;} +#logout {color:#fff;} +.white {color:#fff;} +.cursorPointer {cursor:pointer;} + +.thin_line {display:block;height:8px;margin-left:0px;width:100%;background-color:#6b1e00;} + +.link_blue {background-color:#007bc1; color:#fff; padding-left:10px; padding-right:10px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none;cursor:pointer; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} +.link_blue:hover{background-color:#0092dd;text-decoration:none;} + +.link_blue_rect { + background-color:#c10029; + color:#fff; + cursor:pointer; +} +.link_blue_rect:hover{ + background-color:#ee5b7b; +} + +.link_lightblue {background-color:#ff3000; color:#fff; padding-left:25px; padding-right:25px; padding-top:15px; padding-bottom:15px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +font-family:Segoe UI; font-weight:lighter;; margin-left:auto; margin-right:auto; +font-weight:bold; letter-spacing:1px; cursor:pointer; +font-size:20px; +} +.link_lightblue:hover{background-color:#9ad2d8;text-decoration:none;} + +.link_red {background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#ff786b;text-decoration:none;} + +.link_tosca {background-color:#dbdaa8; color:#fff; padding-left:25px; padding-right:0px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_tosca:hover{background-color:#eeeec9;text-decoration:none;} + + +.link_red {background-color:#FA522C; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#FAAA98;text-decoration:none;} + +.darkBlue {color:#c10029;} +.darkBlueItalic {color:#c10029; font-style:italic; font-size:13px;} +.darkBlueLink {color:#c10029; cursor:pointer;} +.userprofile_link {cursor:pointer;} +.userprofile_link:hover {color:#ee5b7b;} +/* DYNAMIC CONTENT +------------------------------------------------------------------------------------------------- */ +#dynamic_content { + border-left: 2px solid gray; + display:block; + width:73%; + height:100%; + float:right; + overflow:auto; + color:#55565B; + position:relative; +} +.dynamic_content_head { + display:block; + height:30px; + padding-left:2%; + width:75%; + font-weight:bold; +} + +.dynamic_content_row { + display:block; + width:100%; +} + +.dynamic_content_left { + display:block; + width:18%; + padding-left:2%; + font-weight:bold; +} + +.dynamic_content_right { + display:block; + width:74%; + padding-left:2%; + text-align:justify; + text-justify:inter-word; +} +.task_view_category { + float:right; + margin-right:20px; + color:red; +} +.task_view { + width:90%; + display:block; + background-color:white; + opacity:0.8; + padding-top:10px; + padding-bottom:10px; + padding-right:10px; + padding-left:10px; + color:gray; + height:125px; + margin:auto; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; + left:30px; +} +.task_view a:hover { + color:#ff5544; +} + +/* PROFILE CONTENT +------------------------------------------------------------------------------------------------- */ + +#profilebig { + padding:20px; + text-align:center; +} + +#upperprof{ +text-align:center; +} + +#upperprof img { +padding: 4px; +border: 1px solid rgb(204, 204, 204);} + +#namauser{ +width:230px;margin:auto;letter-spacing: 2px;background-color:#c10029; + color:#fff; +font-size:20px; +text-transform:uppercase;margin-top:-50px;z-index: 99;position:relative; +} + +.headsdeh{ + background-color:#c10029; + color:#fff; + width:230px; + font-size:17px;margin:auto; +} + + +.categoryList, #newCategoryAdded { + display:block;padding:10px; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; + color:#c10029; + cursor:pointer; +} + +.categoryList:hover, #newCategoryAdded:hover { + background-color:#c10029; + color:#fff; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; +} + +#login_form input{margin-bottom:5px;} +#edit_profile_button {letter-spacing:0px;padding-left:8px; padding-right:0px;} +#edit_profile_button a {color:#fff; text-decoration:none;} +.ul_none {list-style:none; margin:auto; width:200px; margin-top:5px;} +.ul_none li {text-align:left;} +.red {color:#ff5544; font-weight:bold;} +.blue {color:#c10029; font-weight:bold;} + +/* MAIN PAGE +--------------------------------------------------------------------------------- */ +#tutorial_container { + width:90%; + margin:auto; + margin-top:60px; + display:block; +} +#tutorial { + width:85%; + display:block; + margin:auto; + margin-top:20px; +} +.task_done_button {float:right;cursor:pointer;font-size:12px;} +c10029.task_done_button:hover {color:#211C18;}; + +/* SCROLL BAR +---------------------------------------------------------------------------------- */ +/* Let's get this party started */ +::-webkit-scrollbar { + width: 12px; +} + +/* Track */ +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); +} + +/* Handle */ +::-webkit-scrollbar-thumb { + background: #A8DBC6; + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); +} +.half_div { + width:49%; + display:block; + float:left; + text-align:center; + margin-top:10%; +} +.half_tall { + height:200px; +} + +/* Search Result +--------------------------------------------------------------------------------- */ +.user_search_result_label { + float:left; + width:160px; + letter-spacing:1px; + display:block; + font-size:18px; + font-weight:bold; + text-align:left; + font-family:Helvetica; +} +.cat_search_result_label { + float:left; + width:170px; + display:block; + font-weight:bold; + text-align:left; +} + +/* MEDIA QUERIES +---------------------------------------------------------------------------------- */ +@media screen and (max-width:480px) { + #signup_form_container, #navbar, #search_box, .header_menu, #remember_me, + #remember_me_check {display:none} + + #index_left{ + height:300px; + width:100%; + } + + #tutorial_container{font-size:12px} + + #index_right{width:100%; margin-top:0px} + + #login_form_container { + width:100%; + float:left; + } + .signup_label{ + width:60%; + } + + div#dynamic_content{ + border-left:none; + width:100%; + } + + div#curtask1.task_view, div#curtask2.task_view, div#curtask3.task_view, + div#curtask4.task_view, div#curtask5.task_view{ + padding:none; + width:80% + } + + .dynamic_content_left{ + font-size:15px; + } + + .dynamic_content_right{ + font-size:15px; + } + +} + + diff --git a/eurilys4/build/web/css/wide.css b/eurilys4/build/web/css/wide.css new file mode 100644 index 00000000..82d68bf3 --- /dev/null +++ b/eurilys4/build/web/css/wide.css @@ -0,0 +1,815 @@ +@media screen and (min-width: 1200px) and (max-width: 2000px){ +html {width:100%; height:100%; overflow-x:hidden; font-family:Segoe UI; font-weight: lighter;} +body {width:100%; height:300px; display:block; margin:0px; + /*background-image:url('../img/bgw.jpg');*/ + background-color:#F3E8E6; +} + +h1{ + + font-size: 35px; + padding-left: 20px; + color: #FF5544; +} + +/* HEADER SECTION +------------------------------------------------------------------------------------------- */ +header { + width:100%; + height:90px; + background-color:#35283C; + display:block; +} +.header_menu a { + color:white; + text-decoration:none; + } + +textarea { + font-family:Segoe UI; font-weight:lighter;; +} + +#header_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; +} + +#login_form_container { + position:relative; + background-color:#35283C; + float:right; + width:90%; + height:130px; + margin-right:5%; + z-index:100; +} +#login_form { + font-family:Segoe UI; font-weight:lighter;; + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:15px; + z-index:200; +} +#login_form label { + color:#fff; + float:left; + width:35%; + margin-left:3px; +} + +#login_username , #login_password { + color:gray; + float:left; + margin-left:7px; + width:55%; +} +#login_submit { + float:right; + margin-right:5%; +} + +input#remember_me { + margin-top:20px;float:left; + width:auto; +} +label#remember_me { + float:left; font-size:12px; width:auto; margin-top:-20px; +} + +#edit_profil_container {width:90%; margin:auto; display:block;} +#edit_profil_container h3 {color:#007bc1;} +#edit_profile_form { + width:70%; + margin-top:20px; + margin-left:20px; +} +#edit_profile_form label { + float:left; + font-size:16px; + font-family:Segoe UI; + font-weight:lighter; + color:gray; + width:28%; +} + +#edit_profile_submit { + float:right; + margin-right:5%; +} + +#edit_profile_form input { + float:left; + height:28px; + font-size:17px; + width:60%; + margin-bottom:10px; +} + +#edit_profile_form input#edit_profile_submit { + float:right; + height:35px; + font-size:20px; + width:40%; + margin-bottom:10px; +} + +.header_menu a { + color:white; + text-decoration:none; +} +.header_menu { + float:right; margin-top:30px;height:60%; width:45%; + +} +.header_menu_button { + padding-top:8px; padding-bottom:8px; + width:28%; display:block;color:white; + margin-left:20px;margin-top:8px; text-align:center; + font-size:18px; cursor:pointer; float:left; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} +.header_menu_button:hover , .header_menu_button:active { + background-color:#6FBEC6;text-decoration:none; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} + +.header_menu_button:hover{background-color:#ff5645;} + +.current_header_menu { + background-color:#6FBEC6; +} +#search_box { + float:left; margin-left:45px; height:25px; margin-top:45px; width:20%; +} +#search_box_filter { + float:left; height:30px; margin-top:45px; margin-left:5px; +} +#txtHint { + position:absolute; + display:block; + color:gray; + margin-top:73px; + margin-left:275px; + width:16%; + z-index:300; + border:solid 1px #dedede; + overflow:hidden; + border-bottom-right-radius: 6px; + border-bottom-left-radius: 6px; + -moz-border-bottom-right-radius: 6px; + -moz-border-bottom-left-radius: 6px; + box-shadow: 0px 0px 5px #999; + border-width: 3px 1px 1px; + border-style: solid; + border-color: #333 #DEDEDE #DEDEDE; + background-color: white; + +} +/* LOGO +----------------------------------------------------------------------------------------------------------------- */ +#fleur { + font-size:100px; + color:#FF5544; + display:inline-block; +} +#textdesu{ + color:#fff; + display:inline-block; + font-size:60px; + letter-spacing:-6px; + font-family:Trajan Pro; + margin-left:-10px; +} +#tagline { + font-family:Times New Roman; + font-size:12px; + letter-spacing:2px; + font-style:italic; + margin-top:-20px; + margin-left:15px; + color:#fff; +} + +/* SECTION +--------------------------------------------------------------------------------------------------------------------- */ +section {width:80%;background-color:#F9F9F9; height:680px; margin-left:auto; margin-right:auto; margin-top:40px; margin-bottom:40px; z-index:1; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} + +#index_left { + height:100%; + width:65%; + background-color:#f9f9f9; + float:left; +} +#index_right { + height:100%; + width:35%; + float:left; + padding-top:40px; +} +.signup_label { + width:65%; + background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; + border:none; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + margin-left:auto;margin-right:auto; letter-spacing:1px; + text-align:center; + font-size:25px; + font-family:Segoe UI; font-weight:lighter;; + font-weight:bold; + margin-top:170px; +} +#signup_form_container { + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:10px; + background-color:#EBEBE9; + color:gray; + padding-top:20px; + height:350px; + display:block; +} +#signup_form { + width:90%; + margin-top:20px; + margin-left:20px; +} +#signup_form label { + float:left; + font-size:16px; + font-family:Segoe UI; font-weight:lighter;; + color:gray; + width:28%; +} +#signup_form input { + float:left; + height:20px; + font-size:20px; + width:60%; + margin-bottom:10px; +} +.signup_form_validation { + display:none; + padding-left:10px; + padding-top:5px; + padding-bottom:14px; +} +input#avatar_upload {font-size:12px;} + +#tutorial { + text-align:justify; + text-justify:inter-word; +} + +#tutorial_image { + width:100%; +} + +/* FOOTER SECTION +--------------------------------------------------------------------------------------------------------------------- */ +#footer_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; + color:#fff; + font-size:12px; + text-align:center; +} + +footer { + width:100%; + background-color:#35283C; + height:80px; + display:block; + bottom:0px; +} + +/* NAVIGATION BAR +--------------------------------------------------------------------------------------------------------------------- */ +#navbar { + margin-left:auto; + display:block; + height:100%; + width:25%; + float:left; +} +#short_profile { + margin-top:30px; + width:80%; + margin-left:auto; + margin-right:auto; + height:150px; +} +#profile_picture { + width:100px; + float:left; +} +#profile_info { + margin-left:120px; + float:left; + color:gray; + font-size:14px; + color:gray; + width:120px; + position:absolute; +} +#profile_pic_upload { + clear:both; + margin-top:20px; +} +#category_list { + width:80%; + margin-left:auto; + margin-right:auto; +} +#category_list a { + color:#fff; + text-decoration:none; +} +#category_list ul { + list-style-image:url('../img/arrow.png'); + padding-top:5px; + margin-left:-10px; +} +#category_list ul li a { + cursor:pointer; + color:#6FBEC6; + padding-bottom:5px; +} +#category_list ul li a:hover { + color:#fff; +} + +#category_list ul li a:active{ + color:#ff5645; +} +#add_new_category , #add_task_link{ + color:gray; + cursor:pointer; +} +#add_task_link:hover , #add_new_category:hover { + color:#FF5544; +} +#add_task_link {display:none;} +#add_task_link a { + color:gray; + text-decoration:none; +} +#add_task_link a:hover { + color:#ff5544; +} + +#category_form { + width:100%; + height:180px; + background-color:#6FBEC6; + margin-top:5px; + color:#fff; + padding-top:15px; + display:none; +} +#category_form_inner { + width:90%; + height:90%; + margin:auto; +} +#category_form_inner input { + width:95%; +} +#category_item { + margin-top:5px; +} +#current_category { + color:#6FBEC6; +} + +#add_category { + font-size:11px; + cursor:pointer; +} +#add_category:hover { + color:gray; +} +#add_category_button { + width:80px; + text-align:center; +} +#category_title { + text-align:center; + padding-top:5px; + padding-bottom:5px; +} + +/* TASK DETAIL +--------------------------------------------------------------------------------------------------------------------- */ +#comment_textarea { + width:70%; + height:100px; + resize:none; +} + +#save_button_td { + display:none; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +#task_attachment:hover { + color:#ff5544; +} + +#save_button_td:hover { + border-color:#0092dd; +} + +#edit_task_button, #save_edit_task { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} + +#edit_task_button:hover { + border-color:#0092dd; +} + +#taskdetail_image { + height:100%; + width:auto; +} +.taskDetail { + width:90%; + margin:auto; +} + +/* ADD TASK +--------------------------------------------------------------------------------------------------------------------- */ +#task_name_input, #assignee_input, #deadline_input, #tag_input, #attachment_upload { + width:35%; +} +#add_task_button{ + display:block; + margin-left:22%; + border-style:solid; + border-color:#007bc1; + text-align:center; + width:80px; + font-size:15px; + padding-top:5px; + padding-bottom:5px; +} + +#add_task_button:hover { + border-color:#0092dd; +} +#add_task_container { + width:90%; + margin:auto; +} + +/* STYLING +--------------------------------------------------------------------------------------------------------------------- */ +.bold {font-weight:bold;} +.clear {clear:both;} +.left {float:left;} +.right {float:right;} +.left20 {margin-left:50px;} +.top10 {margin-top:10px;} +.top20 {margin-top:20px;} +.top45 {margin-top:45px;} +.top30 {margin-top:30px;} +.width100 {width:130px;} +.line10 {line-height:50%;} +a {text-decoration:none;} +#logout {color:#fff;} +.white {color:#fff;} +.cursorPointer {cursor:pointer;} + +.thin_line {display:block;height:8px;margin-left:0px;width:100%;background-color:#524459;} + +.link_blue {background-color:#007bc1; color:#fff; padding-left:10px; padding-right:10px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none;cursor:pointer; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} +.link_blue:hover{background-color:#0092dd;text-decoration:none;} + +.link_blue_rect { + background-color:#007bc1; + color:#fff; + cursor:pointer; +} +.link_blue_rect:hover{ + background-color:#0092dd; +} + +.link_lightblue {background-color:#6FBEC6; color:#fff; padding-left:25px; padding-right:25px; padding-top:15px; padding-bottom:15px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +font-family:Segoe UI; font-weight:lighter;; margin-left:auto; margin-right:auto; +font-weight:bold; letter-spacing:1px; cursor:pointer; +font-size:20px; +} +.link_lightblue:hover{background-color:#9ad2d8;text-decoration:none;} + +.link_red {background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#ff786b;text-decoration:none;} + +.link_tosca {background-color:#dba8a8; background-color:#A8DBC6; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_tosca:hover{background-color:#bae4d3;text-decoration:none;} + + +.link_red {background-color:#FA522C; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#FAAA98;text-decoration:none;} + +.darkBlue {color:#007bc1;} +.darkBlueItalic {color:#007bc1; font-style:italic; font-size:13px;} +.darkBlueLink {color:#007bc1; cursor:pointer;} +.userprofile_link {cursor:pointer;} +.userprofile_link:hover {color:#0092dd;} +/* DYNAMIC CONTENT +------------------------------------------------------------------------------------------------- */ +#dynamic_content { + border-left: 2px solid gray; + display:block; + width:73%; + height:100%; + float:right; + overflow:auto; + color:#55565B; + position:relative; +} +.dynamic_content_head { + display:block; + height:30px; + padding-left:2%; + width:75%; + font-weight:bold; +} + +.dynamic_content_row { + display:block; + width:100%; +} + +.dynamic_content_left { + display:block; + width:18%; + padding-left:2%; + font-weight:bold; +} + +.dynamic_content_right { + display:block; + width:74%; + padding-left:2%; + text-align:justify; + text-justify:inter-word; +} +.task_view_category { + float:right; + margin-right:20px; + color:red; +} +.task_view { + width:90%; + display:block; + background-color:white; + opacity:0.8; + padding-top:10px; + padding-bottom:10px; + padding-right:10px; + padding-left:10px; + color:gray; + height:125px; + margin:auto; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; + left:30px; +} +.task_view a:hover { + color:#ff5544; +} + +/* PROFILE CONTENT +------------------------------------------------------------------------------------------------- */ + +#profilebig { + padding:20px; + text-align:center; +} + +#upperprof{ +text-align:center; +} + +#upperprof img { +padding: 4px; +border: 1px solid rgb(204, 204, 204);} + +#namauser{ +width:230px;margin:auto;letter-spacing: 2px;background-color:#007bc1; + color:#fff; +font-size:20px; +text-transform:uppercase;margin-top:-50px;z-index: 99;position:relative; +} + +.headsdeh{ + background-color:#007bc1; + color:#fff; + width:230px; + font-size:17px;margin:auto; +} + + +.categoryList, #newCategoryAdded { + display:block;padding:10px; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; + color:#007bc1; + cursor:pointer; +} + +.categoryList:hover, #newCategoryAdded:hover { + background-color:#007bc1; + color:#fff; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; +} + +#login_form input{margin-bottom:5px;} +#edit_profile_button {letter-spacing:0px;padding-left:8px; padding-right:8px;} +#edit_profile_button a {color:#fff; text-decoration:none;} +.ul_none {list-style:none; margin:auto; width:200px; margin-top:5px;} +.ul_none li {text-align:left;} +.red {color:#ff5544; font-weight:bold;} +.blue {color:#007bc1; font-weight:bold;} + +/* MAIN PAGE +--------------------------------------------------------------------------------- */ +#tutorial_container { + width:90%; + margin:auto; + margin-top:60px; + display:block; +} +#tutorial { + width:85%; + display:block; + margin:auto; + margin-top:20px; +} +.task_done_button {float:right;cursor:pointer;font-size:12px;} +.task_done_button:hover {color:#211C18;} + +/* SCROLL BAR +---------------------------------------------------------------------------------- */ +/* Let's get this party started */ +::-webkit-scrollbar { + width: 12px; +} + +/* Track */ +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); +} + +/* Handle */ +::-webkit-scrollbar-thumb { + background: #dba8a8; + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); +} +.half_div { + width:49%; + display:block; + float:left; + text-align:center; + margin-top:10%; +} +.half_tall { + height:200px; +} + +/* Search Result +--------------------------------------------------------------------------------- */ +.user_search_result_label { + float:left; + width:160px; + letter-spacing:1px; + display:block; + font-size:18px; + font-weight:bold; + text-align:left; + font-family:Helvetica; +} +.cat_search_result_label { + float:left; + width:170px; + display:block; + font-weight:bold; + text-align:left; +} + +/* MEDIA QUERIES +---------------------------------------------------------------------------------- */ +@media screen and (max-width:480px) { + #signup_form_container, #navbar, #search_box, .header_menu, #remember_me, + #remember_me_check {display:none} + + #index_left{ + height:300px; + width:100%; + } + + #tutorial_container{font-size:12px} + + #index_right{width:100%; margin-top:0px} + + #login_form_container { + width:100%; + float:left; + } + .signup_label{ + width:60%; + } + + div#dynamic_content{ + border-left:none; + width:100%; + } + + div#curtask1.task_view, div#curtask2.task_view, div#curtask3.task_view, + div#curtask4.task_view, div#curtask5.task_view{ + padding:none; + width:80% + } + + .dynamic_content_left{ + font-size:15px; + } + + .dynamic_content_right{ + font-size:15px; + } + + +} + diff --git a/eurilys4/build/web/img/arrow.png b/eurilys4/build/web/img/arrow.png new file mode 100644 index 00000000..4ad6f040 Binary files /dev/null and b/eurilys4/build/web/img/arrow.png differ diff --git a/eurilys4/build/web/img/avatar/avatar1.png b/eurilys4/build/web/img/avatar/avatar1.png new file mode 100644 index 00000000..390e4fc7 Binary files /dev/null and b/eurilys4/build/web/img/avatar/avatar1.png differ diff --git a/eurilys4/build/web/img/avatar/sharonloh.jpg b/eurilys4/build/web/img/avatar/sharonloh.jpg new file mode 100644 index 00000000..2eec5e95 Binary files /dev/null and b/eurilys4/build/web/img/avatar/sharonloh.jpg differ diff --git a/eurilys4/build/web/img/avatar1.png b/eurilys4/build/web/img/avatar1.png new file mode 100644 index 00000000..390e4fc7 Binary files /dev/null and b/eurilys4/build/web/img/avatar1.png differ diff --git a/eurilys4/build/web/img/bg.jpg b/eurilys4/build/web/img/bg.jpg new file mode 100644 index 00000000..39b1ae6b Binary files /dev/null and b/eurilys4/build/web/img/bg.jpg differ diff --git a/eurilys4/build/web/img/bgw.jpg b/eurilys4/build/web/img/bgw.jpg new file mode 100644 index 00000000..0d47710a Binary files /dev/null and b/eurilys4/build/web/img/bgw.jpg differ diff --git a/eurilys4/build/web/img/check.png b/eurilys4/build/web/img/check.png new file mode 100644 index 00000000..368ce423 Binary files /dev/null and b/eurilys4/build/web/img/check.png differ diff --git a/eurilys4/build/web/img/done.png b/eurilys4/build/web/img/done.png new file mode 100644 index 00000000..2edec562 Binary files /dev/null and b/eurilys4/build/web/img/done.png differ diff --git a/eurilys4/build/web/img/eurilys_comic.png b/eurilys4/build/web/img/eurilys_comic.png new file mode 100644 index 00000000..c854093b Binary files /dev/null and b/eurilys4/build/web/img/eurilys_comic.png differ diff --git a/eurilys4/build/web/img/favicon.ico b/eurilys4/build/web/img/favicon.ico new file mode 100644 index 00000000..cee53ad0 Binary files /dev/null and b/eurilys4/build/web/img/favicon.ico differ diff --git a/eurilys4/build/web/img/logo.png b/eurilys4/build/web/img/logo.png new file mode 100644 index 00000000..dae9a215 Binary files /dev/null and b/eurilys4/build/web/img/logo.png differ diff --git a/eurilys4/build/web/img/no.png b/eurilys4/build/web/img/no.png new file mode 100644 index 00000000..06868fd9 Binary files /dev/null and b/eurilys4/build/web/img/no.png differ diff --git a/eurilys4/build/web/img/tutorial.png b/eurilys4/build/web/img/tutorial.png new file mode 100644 index 00000000..059a73fe Binary files /dev/null and b/eurilys4/build/web/img/tutorial.png differ diff --git a/eurilys4/build/web/img/yes.png b/eurilys4/build/web/img/yes.png new file mode 100644 index 00000000..86fa4e7d Binary files /dev/null and b/eurilys4/build/web/img/yes.png differ diff --git a/eurilys4/build/web/index.jsp b/eurilys4/build/web/index.jsp new file mode 100644 index 00000000..e4690afc --- /dev/null +++ b/eurilys4/build/web/index.jsp @@ -0,0 +1,80 @@ +<%@page import="service.dbConnection"%> +<%@page import="java.sql.Connection"%> +<%@page import="org.json.*"%> +<%@page import="javax.print.attribute.PrintRequestAttribute"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@include file="src/header.jsp"%> +<% session.invalidate(); %> + + +
+
+
+
+ tutorial_pic +
+
+ Eurilys is an online to-do-list website which is so easy to use, user-friendly, and the most important + of all, it's completely FREE! +
+ You can add task, category for each task, and you can write down all the task's details here. +
+ No more papers, pens, and confusion. Eurilys is here to be your organization's partner. +
+
+
+
+ <% if ("failed".equals(request.getParameter("login_status"))) { %> +
Login Failed
+ <% } %> +
+ +
+ + + +
+ + +
+ <% if ("failed".equals(request.getParameter("register_status"))) { %> +
Sign Up Failed
+ <% } %> + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ +<%@ include file="src/footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/build/web/js/animation.js b/eurilys4/build/web/js/animation.js new file mode 100644 index 00000000..7e90638c --- /dev/null +++ b/eurilys4/build/web/js/animation.js @@ -0,0 +1,509 @@ +function toggle_visibility(id) { + var e = document.getElementById(id); + if(e.style.display == 'block') + e.style.display = 'none'; + else + e.style.display = 'block'; +} + +function add_category() { + var t = "
  • "; + t += ""; + t += document.getElementById("add_category_name").value; + t += ""; + t += "
  • "; + document.getElementById("category_item").innerHTML += t; +} + +var regValid = 0; +function regCheck() { + var username = document.getElementById("reg_username").value; + var password = document.getElementById("reg_password").value; + var confirm = document.getElementById("reg_confirm").value; + var name = document.getElementById("reg_name").value; + var email = document.getElementById("reg_email").value; + var birthdate = document.getElementById("reg_birthdate").value; + var avatar = document.getElementById("avatar_upload").value; + //alert(username + " " + password+ " " + confirm + " " +email + " " + birthdate + " " +avatar); + + //check username + if ((username.length > 4) && (username != password)) { + document.getElementById("username_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("username_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("username_validation").style.display = "block"; + + //check password + if ((password.length > 7) && (password != username) && (password != email)) { + document.getElementById("password_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("password_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("password_validation").style.display = "block"; + + //check confirm + //alert("confirm = " + confirm); + if ((confirm != password) || (confirm == '') || (confirm == null)) { + document.getElementById("confirm_validation").src = "img/no.png"; + regValid = 0; + } + else + if ( (confirm == password) && (password.length > 7) ) { + document.getElementById("confirm_validation").src = "img/yes.png"; + regValid = 1; + } + document.getElementById("confirm_validation").style.display = "block"; + + //check name + if (name.indexOf(' ') >= 0) { + document.getElementById("name_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("name_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("name_validation").style.display = "block"; + + //check email + var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i; + if ((email==password) || (email.search(emailRegEx) == -1)) { + document.getElementById("email_validation").src = "img/no.png"; + regValid = 0; + } + else { + document.getElementById("email_validation").src = "img/yes.png"; + regValid = 1; + } + document.getElementById("email_validation").style.display = "block"; + + //check birthday + if (birthdate != "") { + document.getElementById("birthdate_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("birthdate_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("birthdate_validation").style.display = "block"; + + //check avatar + var extension = avatar.split('.'); + if ( (extension[1] == "jpg") || (extension[1] == "jpeg") ) { + document.getElementById("avatar_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("avatar_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("avatar_validation").style.display = "block"; + + //alert("regvalid = " + regValid); + if (regValid == 1) { + document.getElementById('signup_submit').removeAttribute("disabled"); + //alert("yey"); + } + else { + document.getElementById('signup_submit').disabled = "disabled"; + //alert("Fill your registration form correctly"); + } +} + +function signup() { + if (regValid == 1) { + window.location.href = "src/Dashboard.php"; + } + else { + alert("Fill your registration form correctly"); + } +} + +function checkTaskName() { + var taskName = document.getElementById('task_name_input').value; + var taskNameValid = 0; + var iChars = "~=-_^&.\\|*|,\":<>[]{}`\';()@&$#%"; + for (var i = 0; i < taskName.length; i++) { + if (iChars.indexOf(taskName.charAt(i)) != -1){ + taskNameValid = 1; + break; + } + } + + if ((taskName.length > 25) || (taskNameValid == 1) || (taskName == "")) { + //tidak valid + document.getElementById('taskname_validation').src = "../img/no.png"; + } + else { + //valid + document.getElementById('taskname_validation').src = "../img/yes.png"; + } + document.getElementById('taskname_validation').style.display = "block"; +} + +function checkTaskAttachment() { + var attachmentName = document.getElementById('attachment_file').value; + var dot = "."; + if (attachmentName.indexOf(dot) != -1) { + //valid + document.getElementById('task_attachment_validation').src = "../img/yes.png"; + } + else { + //not valid + document.getElementById('task_attachment_validation').src = "../img/no.png"; + } + document.getElementById('task_attachment_validation').style.display = "block"; +} + +function getUrlVars() { + var vars = {}; + var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { + vars[key] = value; + }); + return vars; +} + +function addCatName(){ + var first = getUrlVars()["cat_name"]; + document.getElementById("cat_name").setAttribute('value',first); +} + +function showSearchHint(str) { + document.getElementById('txtHint').style.display = "block"; + if (str.length==0) { + document.getElementById("txtHint").innerHTML=""; + return; + } + + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("txtHint").innerHTML = xmlhttp.responseText; + } + } + var selectOption = document.getElementById("search_box_filter"); + var filter = selectOption.options[selectOption.selectedIndex].value; + + xmlhttp.open("GET", "../ServletHandler?type=search_result&keyword="+str+"&filter="+filter, true); + xmlhttp.send(); +} + +function AddCategoryAssigneHint(str) { + document.getElementById('category_asignee_autocomplete').style.display = "block"; + if (str.length==0) { + document.getElementById("category_asignee_autocomplete").innerHTML=""; + return; + } + + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("category_asignee_autocomplete").innerHTML = xmlhttp.responseText; + } + } + + var url="addcategory_autocomplete.jsp?hint="+str; + xmlhttp.open("GET", url, true); + xmlhttp.send(); +} + +function EditTaskAssigneHint(str) { + document.getElementById('edit_task_asignee_autocomplete').style.display = "block"; + if (str.length==0) { + document.getElementById("edit_task_asignee_autocomplete").innerHTML=""; + return; + } + + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("edit_task_asignee_autocomplete").innerHTML = xmlhttp.responseText; + } + } + + xmlhttp.open("GET", "../ServletHandler?type=assignee_autocomplete&keyword="+str, true); + xmlhttp.send(); +} + +function addCategoryAssigne(userID) { + var user = document.getElementById('cat_ass_'+userID).innerHTML; + document.getElementById('add_category_asignee_name').value += user; + document.getElementById('add_category_asignee_name').value += ", "; + document.getElementById("category_asignee_autocomplete").innerHTML=""; + document.getElementById("add_category_asignee_name_auto").value = ""; + +} + +function addEditTaskAssigne(userID) { + var user = document.getElementById('edittask_ass_'+userID).innerHTML; + document.getElementById('edit_task_assignee').value += user; + document.getElementById('edit_task_assignee').value += ", "; + document.getElementById("edit_task_asignee_autocomplete").innerHTML=""; + document.getElementById("edit_task_assignee_auto").value = ""; + +} +function addAddTaskAssigne(userID) { + var user = document.getElementById('addtask_ass_'+userID).innerHTML; + document.getElementById('add_task_assignee_input').value += user; + document.getElementById('add_task_assignee_input').value += ", "; + document.getElementById("add_task_asignee_autocomplete").innerHTML=""; + document.getElementById("add_task_assignee_auto").value = ""; +} + +function searchResult(resultID, resultType) { + document.getElementById('txtHint').style.display = "none"; + + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("dynamic_content").innerHTML = xmlhttp.responseText; + } + } + + var s = ""; + if (resultType == "user") { + s = "search_result.jsp?q="+resultID+"&type=user"; + xmlhttp.open("GET", s, true); + xmlhttp.send(); + } + else + if (resultType == "category") { + s = "search_result.jsp?q="+resultID+"&type=category"; + xmlhttp.open("GET", s, true); + xmlhttp.send(); + } + else + if (resultType == "task") { + window.location.href = "task_detail.jsp?task_id="+resultID; + } +} + +function viewTask(taskID) { + window.location.href = "task_detail.jsp?task_id="+taskID; +} + +function generateTask(categoryName) { + alert("masuk!"); + document.getElementById("dynamic_content").innerHTML = ""; + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + /* + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("dynamic_content").innerHTML = xmlhttp.responseText; + } + }*/ + + document.getElementById("add_task_link").style.display = "block"; + document.getElementById("add_task").setAttribute('href',"addtask.jsp?cat_name="+categoryName); + + //var url="category_task.jsp?categoryName="+categoryName; + xmlhttp.open("GET", "../task/get_category_task?category_name="+categoryName, true); + xmlhttp.send(); +} + +function finishTask(taskID) { + var finishTaskConfirm = confirm("Are you sure this task has been completely done?"); + if (finishTaskConfirm == true) + { + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById("taskHandler_"+taskID).innerHTML = ""; + } + } + } + xmlhttp.open('GET', '../ServletHandler?type=finish_task&task_id=' + taskID, true); + xmlhttp.send(null); + } +} + +function deleteTask(taskID) { + var deleteTaskConfirm = confirm("Are you sure you want to delete this task?"); + if (deleteTaskConfirm == true) { + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById(taskID).parentNode.removeChild(document.getElementById(taskID)); + } + } + } + //xmlhttp.open('GET', '../task/delete_task?task_id=' + taskID, true); + xmlhttp.open('GET', '../ServletHandler?type=delete_task&task_id=' + taskID, true); + xmlhttp.send(null); + } +} + +function deleteComment(commentID) { + var deleteCommentConfirm = confirm("Delete this comment?"); + if (deleteCommentConfirm == true) { //GET servlet + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById("comment_"+commentID).parentNode.removeChild(document.getElementById("comment_"+commentID)); + } + } + } + xmlhttp.open('GET', '../ServletHandler?type=delete_comment&comment_id='+commentID, true); + //xmlhttp.open('GET', '../task/delete_comment?comment_id='+commentID, true); + xmlhttp.send(null); + } +} + +function deleteTaskAssigne(taskID, userID) { + var deleteConfirm = confirm("Delete " + userID + " from this task?"); + if (deleteConfirm == true) { + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById("user_"+userID).parentNode.removeChild(document.getElementById("user_"+userID)); + } + } + } + xmlhttp.open('GET', '../ServletHandler?type=edittask_deleteAssignee&task_id='+taskID+'&user_id='+userID, true); + xmlhttp.send(null); + } +} + +function deleteTaskTag(taskID, tagName) { + var deleteConfirm = confirm("Delete " + tagName + " from this task tag?"); + if (deleteConfirm == true) { + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById("tag_"+tagName).parentNode.removeChild(document.getElementById("tag_"+tagName)); + } + } + } + xmlhttp.open('GET', '../ServletHandler?type=edittask_deleteTag&task_id='+taskID+'&tag_name='+tagName, true); + xmlhttp.send(null); + } +} + +function editProfileCheck() { + var username = document.getElementById("edit_username").value; + var email = document.getElementById("edit_email").value; + var password = document.getElementById("edit_password").value; + var confirm = document.getElementById("edit_password_confirm").value; + var name = document.getElementById("fullname").value; + var birthdate = document.getElementById("birthdate").value; + var avatar = document.getElementById("avatar").value; + + var passwordValid = 1; + //check password + if ((password.length > 7) && (password != username) && (password != email)) { + document.getElementById("password_validation").src = "../img/yes.png"; + passwordValid = 1; + } + else { + document.getElementById("password_validation").src = "../img/no.png"; + passwordValid = 0; + } + document.getElementById("password_validation").style.display = "block"; + + var confirmValid = 1; + //check confirm + if ((confirm != password) || (confirm == '') || (confirm == null)) { + document.getElementById("confirm_validation").src = "../img/no.png"; + confirmValid = 0; + } + else + if ( (confirm == password) && (password.length > 7) ) { + document.getElementById("confirm_validation").src = "../img/yes.png"; + confirmValid = 1; + } + document.getElementById("confirm_validation").style.display = "block"; + + if ((password == confirm) && (password.length == 0)) { + passwordValid = 1; + confirmValid = 1; + document.getElementById("password_validation").src = "../img/yes.png"; + document.getElementById("confirm_validation").src = "../img/yes.png"; + } + + var nameValid = 1; + //check name + if (name.indexOf(' ') >= 0) { + document.getElementById("name_validation").src = "../img/yes.png"; + nameValid = 1; + } + else { + document.getElementById("name_validation").src = "../img/no.png"; + nameValid = 0; + } + document.getElementById("name_validation").style.display = "block"; + + if ((passwordValid == 1) & (confirmValid == 1) & (nameValid == 1)) { + document.getElementById('edit_profile_submit').removeAttribute("disabled"); + } + else { + document.getElementById('edit_profile_submit').disabled = "disabled"; + } +} \ No newline at end of file diff --git a/eurilys4/build/web/src/addtask.jsp b/eurilys4/build/web/src/addtask.jsp new file mode 100644 index 00000000..86597fa3 --- /dev/null +++ b/eurilys4/build/web/src/addtask.jsp @@ -0,0 +1,83 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@include file="logged_in_header.jsp"%> + + +
    + <%@include file="navigation_bar.jsp"%> +
    + <% + String cat_name = (String) request.getParameter("cat_name"); + %> +
    +
    + Add New Task +
    +
    +
    +
    Task Name
    +
    + + +
    +
    + +
    +
    Attachment
    +
    + + +
    +
    + +
    +
    Add more attachment
    +
    + + +
    +
    + +
    +
    Add more attachment
    +
    + + +
    +
    + + +
    +
    Deadline
    +
    + +
    +
    + +
    +
    Assignee
    +
    +
    + +
    +
    + +
    +
    Tag
    +
    + +
    +
    + + + +
    + +
    +
    +
    +
    +
    + +<%@include file="footer.jsp"%> diff --git a/eurilys4/build/web/src/dashboard.jsp b/eurilys4/build/web/src/dashboard.jsp new file mode 100644 index 00000000..4d6daecb --- /dev/null +++ b/eurilys4/build/web/src/dashboard.jsp @@ -0,0 +1,73 @@ +<%@include file="logged_in_header.jsp"%> + +
    + + <%@include file="navigation_bar.jsp"%> +
    + + <% + String username = (String) session.getAttribute("username"); + //URL taskURL = new URL("http://localhost:8084/eurilys4-service/task/all_task?username=" + session.getAttribute("username")); + URL taskURL = new URL("http://eurilys.ap01.aws.af.cm/task/all_task?username=" + session.getAttribute("username")); + HttpURLConnection taskConn = (HttpURLConnection) taskURL.openConnection(); + taskConn.setRequestMethod("GET"); + taskConn.setRequestProperty("Accept", "application/json"); + if (taskConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + taskConn.getResponseCode()); + } + BufferedReader taskBr = new BufferedReader(new InputStreamReader((taskConn.getInputStream()))); + String taskOutput; + String taskJSONObject = ""; + while ((taskOutput = taskBr.readLine()) != null) { + taskJSONObject += taskOutput; + } + taskConn.disconnect(); + + //Parse taskJSONObject + JSONTokener taskTokener = new JSONTokener(taskJSONObject); + JSONArray taskroot = new JSONArray(taskTokener); + + for (int i=0; i
    "); + if (task_creator.equals(username)) { + out.println("
    Delete
    "); + out.println("
        |    
    "); + } + out.println("
    "); + if ("0".equals(task_status)) { + out.println("
    Mark as Finished
    "); + } else { + out.println(""); + } + out.println("
    "); + out.println("
    Task Name
    "); + out.println("
    " +task_name+ "


    "); + + out.println("
    Deadline
    "); + out.println("
    " +task_deadline+ "


    "); + + out.println("
    Tag
    "); + out.println("
    "); + JSONArray tag_list = task.getJSONArray("tag_list"); + for (int j=0; j
    "); + + out.println("
    "+task_category+"

    "); + out.println("
    "); + } + %> +

    +
    +
    + +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/build/web/src/edit_profile.jsp b/eurilys4/build/web/src/edit_profile.jsp new file mode 100644 index 00000000..2589c830 --- /dev/null +++ b/eurilys4/build/web/src/edit_profile.jsp @@ -0,0 +1,67 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.sql.DriverManager"%> +<%@page import="java.sql.PreparedStatement"%> +<%@include file="logged_in_header.jsp"%> + +
    + + <%@include file="navigation_bar.jsp"%> + <% + //URL userDetailURL = new URL("http://localhost:8084/eurilys4-service/user/user_detail?username=" + session.getAttribute("username")); + URL userDetailURL = new URL("http://eurilys.ap01.aws.af.cm/user/user_detail?username=" + session.getAttribute("username")); + HttpURLConnection userDetailConn = (HttpURLConnection) userDetailURL.openConnection(); + userDetailConn.setRequestMethod("GET"); + userDetailConn.setRequestProperty("Accept", "application/json"); + if (userDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + userDetailConn.getResponseCode()); + } + BufferedReader userDetailBr = new BufferedReader(new InputStreamReader((userDetailConn.getInputStream()))); + String userDetailOutput; + String userDetailJSONObject = ""; + while ((userDetailOutput = userDetailBr.readLine()) != null) { + userDetailJSONObject += userDetailOutput; + } + userDetailConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener userDetailTokener = new JSONTokener(userDetailJSONObject); + JSONObject userDetailroot = new JSONObject(userDetailTokener); + String password = userDetailroot.getString("password"); + String fullname = userDetailroot.getString("fullname"); + String birthdate = userDetailroot.getString("birthdate"); + String email = userDetailroot.getString("email"); + //String avatar = userDetailroot.getString("avatar"); + %> +
    +
    +

    Edit Profile

    +
    + <%= session.getAttribute("username") %> + "> + + +

    Change Password

    + + + + + + + +
    + +

    Change Details

    + + + +
    +
    + + +
    +
    +
    +
    +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/build/web/src/edit_task.jsp b/eurilys4/build/web/src/edit_task.jsp new file mode 100644 index 00000000..81bbe93e --- /dev/null +++ b/eurilys4/build/web/src/edit_task.jsp @@ -0,0 +1,123 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@page import="java.sql.Blob"%> +<%@page import="java.util.List"%> +<%@page import="java.util.ArrayList"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.PreparedStatement"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.sql.DriverManager"%> +<%@include file="logged_in_header.jsp"%> +
    + + <%@include file="navigation_bar.jsp"%> + +
    +
    + <% + String taskID = (String) request.getParameter("task_id"); + //URL taskDetailURL = new URL("http://localhost:8084/eurilys4-service/task/task_detail?task_id=" + taskID); + URL userDetailURL = new URL("http://eurilys.ap01.aws.af.cm/task/task_detail?task_id=" + taskID); + HttpURLConnection taskDetailConn = (HttpURLConnection) taskDetailURL.openConnection(); + taskDetailConn.setRequestMethod("GET"); + taskDetailConn.setRequestProperty("Accept", "application/json"); + if (taskDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + taskDetailConn.getResponseCode()); + } + BufferedReader taskDetailBr = new BufferedReader(new InputStreamReader((taskDetailConn.getInputStream()))); + String taskDetailOutput; + String taskDetailJSONObject = ""; + while ((taskDetailOutput = taskDetailBr.readLine()) != null) { + taskDetailJSONObject += taskDetailOutput; + } + taskDetailConn.disconnect(); + //Parse userDetailJSONObject + JSONTokener taskDetailTokener = new JSONTokener(taskDetailJSONObject); + JSONObject taskDetailroot = new JSONObject(taskDetailTokener); + + String task_name = taskDetailroot.getString("task_name"); + String task_id = taskDetailroot.getString("task_id"); + String task_deadline = taskDetailroot.getString("task_deadline"); + String task_status = taskDetailroot.getString("task_status"); + String task_category = taskDetailroot.getString("task_category"); + String task_creator = taskDetailroot.getString("task_creator"); + + JSONArray comment_id = taskDetailroot.getJSONArray("comment_id"); + JSONArray comment_timestamp = taskDetailroot.getJSONArray("comment_timestamp"); + JSONArray comment_content = taskDetailroot.getJSONArray("comment_content"); + JSONArray comment_creator = taskDetailroot.getJSONArray("comment_creator"); + + JSONArray tag_list = taskDetailroot.getJSONArray("tag_list"); + JSONArray task_assignee = taskDetailroot.getJSONArray("task_assignee"); + %> + +
    + <%=task_name%> +
    + +
    + + + +
    +
    Task Name
    +
    <%=task_name%>
    +
    +
    +
    Status
    +
    + <% if (task_status.equals("0")) { %> + Not Finished Yet + <% } else { %> + Finished + <% } %> +
    +
    +
    +
    Attachment
    +
    + Belom dibikin. Hahaha. +
    +
    + +
    +
    Deadline
    +
    + +
    +
    + +
    +
    Assignee
    +
    + <% for (int i=0; i +
    +     + <%= task_assignee.get(i) %> +
    +
    + <% } %> +
    +
    + +
    +
    +
    +
    +
    Tag
    +
    + <% for (int i=0; i +
    +     + <%=tag_list.get(i)%> +
    +
    + <% } %> +
    + +
    +
    +
    +
    +
    +
    +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/build/web/src/footer.jsp b/eurilys4/build/web/src/footer.jsp new file mode 100644 index 00000000..35ebb31c --- /dev/null +++ b/eurilys4/build/web/src/footer.jsp @@ -0,0 +1,12 @@ + +
    +
    + +
    + + \ No newline at end of file diff --git a/eurilys4/build/web/src/header.jsp b/eurilys4/build/web/src/header.jsp new file mode 100644 index 00000000..22681bdf --- /dev/null +++ b/eurilys4/build/web/src/header.jsp @@ -0,0 +1,22 @@ + + + + + + + + + + Eurilys + + + + +
    +
    +
    + logo +
    +
    +
    +
    \ No newline at end of file diff --git a/eurilys4/build/web/src/logged_in_header.jsp b/eurilys4/build/web/src/logged_in_header.jsp new file mode 100644 index 00000000..9a5f2f30 --- /dev/null +++ b/eurilys4/build/web/src/logged_in_header.jsp @@ -0,0 +1,42 @@ + +<% +if (session.getAttribute("fullname") == null) { + response.sendRedirect("../index.jsp"); +} +%> + + + + + + + + + Eurilys + + + + +
    +
    +
    + +
    + + +
    + + + +
    +
    +
    \ No newline at end of file diff --git a/eurilys4/build/web/src/navigation_bar.jsp b/eurilys4/build/web/src/navigation_bar.jsp new file mode 100644 index 00000000..4a83cd7b --- /dev/null +++ b/eurilys4/build/web/src/navigation_bar.jsp @@ -0,0 +1,160 @@ +<%@page import="java.net.URLDecoder"%> +<%@page import="org.json.*"%> +<%@page import="java.io.InputStreamReader"%> +<%@page import="java.io.BufferedReader"%> +<%@page import="java.net.HttpURLConnection"%> +<%@page import="java.net.URL"%> +<%@page import="java.sql.Blob"%> + + +<% + String user_name = (String) session.getAttribute("username"); + //URL url = new URL("http://localhost:8084/eurilys4-service/category/get_list?username=" + session.getAttribute("username")); + URL url = new URL("http://eurilys.ap01.aws.af.cm/category/get_list?username=" + session.getAttribute("username")); + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String categoryJSONObject = ""; + while ((output = br.readLine()) != null) { + categoryJSONObject += output; + } + httpConn.disconnect(); + + //Parse categoryJSONObject + JSONTokener tokener = new JSONTokener(categoryJSONObject); + JSONArray root = new JSONArray(tokener); +%> + + + + \ No newline at end of file diff --git a/eurilys4/build/web/src/profile.jsp b/eurilys4/build/web/src/profile.jsp new file mode 100644 index 00000000..6f864a00 --- /dev/null +++ b/eurilys4/build/web/src/profile.jsp @@ -0,0 +1,169 @@ +<%@page import="org.json.*"%> +<%@page import="java.io.InputStreamReader"%> +<%@page import="java.io.BufferedReader"%> +<%@page import="java.net.HttpURLConnection"%> +<%@page import="java.net.URL"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.sql.DriverManager"%> +<%@page import="java.sql.PreparedStatement"%> + + + + + + + + + + + Eurilys + + + + +
    +
    +
    + +
    + + +
    + + + +
    +
    +
    + + +
    + <%@include file="navigation_bar.jsp"%> + <% + //URL userDetailURL = new URL("http://localhost:8084/eurilys4-service/user/user_detail?username=" + session.getAttribute("username")); + URL userDetailURL = new URL("http://eurilys.ap01.aws.af.cm/user/user_detail?username=" + session.getAttribute("username")); + HttpURLConnection userDetailConn = (HttpURLConnection) userDetailURL.openConnection(); + userDetailConn.setRequestMethod("GET"); + userDetailConn.setRequestProperty("Accept", "application/json"); + if (userDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + userDetailConn.getResponseCode()); + } + BufferedReader userDetailBr = new BufferedReader(new InputStreamReader((userDetailConn.getInputStream()))); + String userDetailOutput; + String userDetailJSONObject = ""; + while ((userDetailOutput = userDetailBr.readLine()) != null) { + userDetailJSONObject += userDetailOutput; + } + userDetailConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener userDetailTokener = new JSONTokener(userDetailJSONObject); + JSONObject userDetailroot = new JSONObject(userDetailTokener); + String fullname = userDetailroot.getString("fullname"); + String birthdate = userDetailroot.getString("birthdate"); + String email = userDetailroot.getString("email"); + %> +
    +
    +
    + " alt=""/> +
    <%=fullname%>
    +
    +

    + <%=session.getAttribute("username")%> +
    + <%=email%> +
    + <%=birthdate%> +



    + <% if ("ok".equals(request.getParameter("profileupdate"))) { + session.setAttribute("fullname", fullname); + %> +
    Profile has been successfully updated
    + <% } else if ("failed".equals(request.getParameter("profileupdate"))) { %> +
    Profile NOT has been successfully updated.
    + <% } %> +
    + +
    +
    +
    Current Tasks
    + <% + //URL currentTaskURL = new URL("http://localhost:8084/eurilys4-service/user/current_task?username=" + session.getAttribute("username")); + URL currentTaskURL = new URL("http://eurilys.ap01.aws.af.cm/user/current_task?username=" + session.getAttribute("username")); + HttpURLConnection currentTaskConn = (HttpURLConnection) currentTaskURL.openConnection(); + currentTaskConn.setRequestMethod("GET"); + currentTaskConn.setRequestProperty("Accept", "application/json"); + if (currentTaskConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + currentTaskConn.getResponseCode()); + } + BufferedReader currentTaskBr = new BufferedReader(new InputStreamReader((currentTaskConn.getInputStream()))); + String currentTaskOutput; + String currentTaskJSONObject = ""; + while ((currentTaskOutput = currentTaskBr.readLine()) != null) { + currentTaskJSONObject += currentTaskOutput; + } + currentTaskConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener currentTaskTokener = new JSONTokener(currentTaskJSONObject); + JSONArray currentTaskRoot = new JSONArray(currentTaskTokener); + + for (int i=0; i + + <% + } + %> +
    +
    +
    Finished Tasks
    + <% + //currentTaskURL = new URL("http://localhost:8084/eurilys4-service/user/finished_task?username=" + session.getAttribute("username")); + currentTaskURL = new URL("http://eurilys.ap01.aws.af.cm/user/finished_task?username=" + session.getAttribute("username")); + currentTaskConn = (HttpURLConnection) currentTaskURL.openConnection(); + currentTaskConn.setRequestMethod("GET"); + currentTaskConn.setRequestProperty("Accept", "application/json"); + if (currentTaskConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + currentTaskConn.getResponseCode()); + } + currentTaskBr = new BufferedReader(new InputStreamReader((currentTaskConn.getInputStream()))); + currentTaskOutput = ""; + currentTaskJSONObject = ""; + while ((currentTaskOutput = currentTaskBr.readLine()) != null) { + currentTaskJSONObject += currentTaskOutput; + } + currentTaskConn.disconnect(); + + //Parse userDetailJSONObject + currentTaskTokener = new JSONTokener(currentTaskJSONObject); + currentTaskRoot = new JSONArray(currentTaskTokener); + + for (int i=0; i + + <% + } + %> +
    +
    +
    +
    + +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/build/web/src/search_result.jsp b/eurilys4/build/web/src/search_result.jsp new file mode 100644 index 00000000..6a37aef1 --- /dev/null +++ b/eurilys4/build/web/src/search_result.jsp @@ -0,0 +1,92 @@ +<%@page import="org.json.JSONArray"%> +<%@page import="org.json.JSONObject"%> +<%@page import="org.json.JSONTokener"%> +<%@page import="java.io.InputStreamReader"%> +<%@page import="java.io.BufferedReader"%> +<%@page import="java.net.HttpURLConnection"%> +<%@page import="java.net.URL"%> +<%@page import="java.util.Iterator"%> +<%@page import="java.util.List"%> +<%@page import="java.util.ArrayList"%> +<%@page language="java" import ="java.sql.*" %> + +<% + String q = request.getParameter("q"); + String type = request.getParameter("type"); + String buffer = ""; + + ResultSet search_result = null; + + if (type.equals("user")) { + //URL userDetailURL = new URL("http://localhost:8084/eurilys4/user/user_detail?username=" + q); + URL userDetailURL = new URL("http://eurilys.ap01.aws.af.cm/user/user_detail?username=" + q); + HttpURLConnection userDetailConn = (HttpURLConnection) userDetailURL.openConnection(); + userDetailConn.setRequestMethod("GET"); + userDetailConn.setRequestProperty("Accept", "application/json"); + if (userDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + userDetailConn.getResponseCode()); + } + BufferedReader userDetailBr = new BufferedReader(new InputStreamReader((userDetailConn.getInputStream()))); + String userDetailOutput; + String userDetailJSONObject = ""; + while ((userDetailOutput = userDetailBr.readLine()) != null) { + userDetailJSONObject += userDetailOutput; + } + userDetailConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener userDetailTokener = new JSONTokener(userDetailJSONObject); + JSONObject userDetailroot = new JSONObject(userDetailTokener); + String user_name = userDetailroot.getString("username"); + String fullname = userDetailroot.getString("fullname"); + String birthdate = userDetailroot.getString("birthdate"); + String email = userDetailroot.getString("email"); + String avatar = userDetailroot.getString("avatar"); + + buffer = "
    "+fullname+"


    "; + buffer = buffer + "
    Username
    "+user_name+"

    "; + buffer = buffer + "
    Email
    "+email+"

    "; + buffer = buffer + "
    Birthdate
    "+birthdate+"
    "; + + } + else + if (type.equals("category")) { + //call search/category?id= + //URL searchURL = new URL("http://localhost:8084/eurilys4/search/category?id=" + q); + URL searchURL = new URL("http://eurilys.ap01.aws.af.cm/search/category?id=" + q); + HttpURLConnection searchConn = (HttpURLConnection) searchURL.openConnection(); + searchConn.setRequestMethod("GET"); + searchConn.setRequestProperty("Accept", "application/json"); + if (searchConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + searchConn.getResponseCode()); + } + BufferedReader searchBr = new BufferedReader(new InputStreamReader((searchConn.getInputStream()))); + String searchOutput; + String searchJSONObject = ""; + while ((searchOutput = searchBr.readLine()) != null) { + searchJSONObject += searchOutput; + } + searchConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener searchTokener = new JSONTokener(searchJSONObject); + JSONObject searchRoot = new JSONObject(searchTokener); + + buffer += "

    "; + buffer += "
    Category Name
    "+ searchRoot.getString("cat_name")+"
    "; + buffer += "

    "; + buffer += "
    Creator
    " + searchRoot.getString("cat_creator") +"
    "; + buffer += "

    "; + buffer += "
    List of Task
    "; + JSONArray task_list = searchRoot.getJSONArray("task"); + for (int i=0; i \ No newline at end of file diff --git a/eurilys4/build/web/src/task_detail.jsp b/eurilys4/build/web/src/task_detail.jsp new file mode 100644 index 00000000..73bb12b8 --- /dev/null +++ b/eurilys4/build/web/src/task_detail.jsp @@ -0,0 +1,145 @@ +<%@page import="java.io.PrintWriter"%> +<%@page import="java.sql.Blob"%> +<%@page import="java.util.List"%> +<%@page import="java.util.ArrayList"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.PreparedStatement"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.sql.DriverManager"%> + +<%@include file="logged_in_header.jsp"%> + +
    + <%@include file="navigation_bar.jsp"%> +
    + <% + String taskID = (String) request.getParameter("task_id"); + //URL taskDetailURL = new URL("http://localhost:8084/eurilys4-service/task/task_detail?task_id=" + taskID); + URL taskDetailURL = new URL("http://eurilys.ap01.aws.af.cm/task/task_detail?task_id=" + taskID); + HttpURLConnection taskDetailConn = (HttpURLConnection) taskDetailURL.openConnection(); + taskDetailConn.setRequestMethod("GET"); + taskDetailConn.setRequestProperty("Accept", "application/json"); + if (taskDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + taskDetailConn.getResponseCode()); + } + BufferedReader taskDetailBr = new BufferedReader(new InputStreamReader((taskDetailConn.getInputStream()))); + String taskDetailOutput; + String taskDetailJSONObject = ""; + while ((taskDetailOutput = taskDetailBr.readLine()) != null) { + taskDetailJSONObject += taskDetailOutput; + } + taskDetailConn.disconnect(); + //Parse userDetailJSONObject + JSONTokener taskDetailTokener = new JSONTokener(taskDetailJSONObject); + JSONObject taskDetailroot = new JSONObject(taskDetailTokener); + + String task_name = taskDetailroot.getString("task_name"); + String task_id = taskDetailroot.getString("task_id"); + String task_deadline = taskDetailroot.getString("task_deadline"); + String task_status = taskDetailroot.getString("task_status"); + String task_category = taskDetailroot.getString("task_category"); + String task_creator = taskDetailroot.getString("task_creator"); + + JSONArray comment_id = taskDetailroot.getJSONArray("comment_id"); + JSONArray comment_timestamp = taskDetailroot.getJSONArray("comment_timestamp"); + JSONArray comment_content = taskDetailroot.getJSONArray("comment_content"); + JSONArray comment_creator = taskDetailroot.getJSONArray("comment_creator"); + + JSONArray tag_list = taskDetailroot.getJSONArray("tag_list"); + + JSONArray task_assignee = taskDetailroot.getJSONArray("task_assignee"); + + String tagList = ""; + for (int i=0; i + +
    + + <% if ("ok".equals(request.getParameter("update_task"))) { %> +
    Task has been successfully updated
    + <% } else if ("failed".equals(request.getParameter("update_task"))) { %> +
    Task NOT has been successfully updated.
    + <% } %> + +
    + <%=task_name%> +
    + Edit Task +
    +
    Task Name
    +
    <%=task_name%>
    +
    +
    +
    Status
    + <% if ("0".equals(task_status)) { %> +
    Not finished yet
    + <% } else { %> +
    Finished
    + <% } %> +
    +
    +
    Attachment
    +
    Belum buat hahaha~
    +
    +
    +
    Deadline
    +
    <%=task_deadline%>
    +
    + +
    +
    Assignee
    +
    + <% for (int i=0; i + <%=task_assignee.get(i)%> + <% + if (i != task_assignee.length()-1) + out.print(" , "); + } %> +
    +
    + + +
    +
    Tag
    +
    <%= tagList %>
    +
    +
    +
    Comment
    +
    +
    + + <% for (int i=0; i +
    + +
    <%= comment_content.get(i) %>
    + <% if (session.getAttribute("username").equals(comment_creator.get(i))) { %> + + <% } %> +
    + <% } %> +
    +
     
    +
    +
    + +
    + + +


    +
    +
    +
    +
    +
    + +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/build/web/src/uploads/23591_482718_10200745307864176_1702041215_n.jpg b/eurilys4/build/web/src/uploads/23591_482718_10200745307864176_1702041215_n.jpg new file mode 100644 index 00000000..b71561c6 Binary files /dev/null and b/eurilys4/build/web/src/uploads/23591_482718_10200745307864176_1702041215_n.jpg differ diff --git a/eurilys4/build/web/src/uploads/2472a_dddd.jpg b/eurilys4/build/web/src/uploads/2472a_dddd.jpg new file mode 100644 index 00000000..7aede463 Binary files /dev/null and b/eurilys4/build/web/src/uploads/2472a_dddd.jpg differ diff --git a/eurilys4/build/web/src/uploads/250c8_taskdetail_file.pdf b/eurilys4/build/web/src/uploads/250c8_taskdetail_file.pdf new file mode 100644 index 00000000..e1cc6294 Binary files /dev/null and b/eurilys4/build/web/src/uploads/250c8_taskdetail_file.pdf differ diff --git a/eurilys4/build/web/src/uploads/ab15e_2013-03-02 09.12.43.jpg b/eurilys4/build/web/src/uploads/ab15e_2013-03-02 09.12.43.jpg new file mode 100644 index 00000000..59071b9a Binary files /dev/null and b/eurilys4/build/web/src/uploads/ab15e_2013-03-02 09.12.43.jpg differ diff --git a/eurilys4/build/web/src/uploads/cf2c0_dddd.jpg b/eurilys4/build/web/src/uploads/cf2c0_dddd.jpg new file mode 100644 index 00000000..7aede463 Binary files /dev/null and b/eurilys4/build/web/src/uploads/cf2c0_dddd.jpg differ diff --git a/eurilys4/nbproject/ant-deploy.xml b/eurilys4/nbproject/ant-deploy.xml new file mode 100644 index 00000000..9bc5adf7 --- /dev/null +++ b/eurilys4/nbproject/ant-deploy.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eurilys4/nbproject/build-impl.xml b/eurilys4/nbproject/build-impl.xml new file mode 100644 index 00000000..739c258e --- /dev/null +++ b/eurilys4/nbproject/build-impl.xml @@ -0,0 +1,1418 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eurilys4/nbproject/genfiles.properties b/eurilys4/nbproject/genfiles.properties new file mode 100644 index 00000000..21313337 --- /dev/null +++ b/eurilys4/nbproject/genfiles.properties @@ -0,0 +1,12 @@ +build.xml.data.CRC32=951a3912 +build.xml.script.CRC32=47154bed +build.xml.stylesheet.CRC32=651128d4@1.38.1.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=951a3912 +nbproject/build-impl.xml.script.CRC32=3dc1473b +nbproject/build-impl.xml.stylesheet.CRC32=5459df51@1.41.1.1 +nbproject/rest-build.xml.data.CRC32=951a3912 +nbproject/rest-build.xml.script.CRC32=139c8b19 +nbproject/rest-build.xml.stylesheet.CRC32=5f13befe@1.14.2 +nbproject/jaxws-build.xml.stylesheet.CRC32=bba84283 diff --git a/eurilys4/nbproject/jax-ws.xml b/eurilys4/nbproject/jax-ws.xml new file mode 100644 index 00000000..dd483086 --- /dev/null +++ b/eurilys4/nbproject/jax-ws.xml @@ -0,0 +1,7 @@ + + + + + + false + diff --git a/eurilys4/nbproject/jaxws-build.xml b/eurilys4/nbproject/jaxws-build.xml new file mode 100644 index 00000000..0267e77f --- /dev/null +++ b/eurilys4/nbproject/jaxws-build.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/eurilys4/nbproject/private/private.properties b/eurilys4/nbproject/private/private.properties new file mode 100644 index 00000000..e9983201 --- /dev/null +++ b/eurilys4/nbproject/private/private.properties @@ -0,0 +1,17 @@ +<<<<<<< HEAD +deploy.ant.properties.file=/Users/kaniaazrina/Library/Application Support/NetBeans/7.3/tomcat70.properties +j2ee.platform.is.jsr109=true +j2ee.server.domain=/Applications/NetBeans/glassfish-3.1.2.2/glassfish/domains/domain1 +j2ee.server.home=C:/Program Files/Apache Software Foundation/Apache Tomcat 7.0.27 +j2ee.server.instance=tomcat70:home=/Applications/NetBeans/apache-tomcat-7.0.39 +j2ee.server.middleware=/Applications/NetBeans/glassfish-3.1.2.2 +javac.debug=true +javadoc.preview=true +user.properties.file=/Users/kaniaazrina/Library/Application Support/NetBeans/7.3/build.properties +======= +deploy.ant.properties.file=C:\\Users\\Sharon\\AppData\\Roaming\\NetBeans\\7.2.1\\tomcat70.properties +j2ee.server.domain=C:/Users/Sharon/AppData/Roaming/NetBeans/7.2.1/apache-tomcat-7.0.27.0_base +j2ee.server.home=C:/Program Files/Apache Software Foundation/Apache Tomcat 7.0.27 +j2ee.server.instance=tomcat70:home=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 7.0.27:base=apache-tomcat-7.0.27.0_base +user.properties.file=C:\\Users\\Sharon\\AppData\\Roaming\\NetBeans\\7.2.1\\build.properties +>>>>>>> revisi edit profile diff --git a/eurilys4/nbproject/private/private.xml b/eurilys4/nbproject/private/private.xml new file mode 100644 index 00000000..47509625 --- /dev/null +++ b/eurilys4/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/eurilys4/nbproject/project.properties b/eurilys4/nbproject/project.properties new file mode 100644 index 00000000..ab6763d6 --- /dev/null +++ b/eurilys4/nbproject/project.properties @@ -0,0 +1,86 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +auxiliary.org-netbeans-modules-html-editor-lib.default-html-public-id=HTML5 +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +dist.dir=dist +dist.ear.war=${dist.dir}/${war.ear.name} +dist.javadoc.dir=${dist.dir}/javadoc +dist.war=${dist.dir}/${war.name} +endorsed.classpath=\ + ${libs.javaee-endorsed-api-6.0.classpath} +excludes= +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.6-web +j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-3.7.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-util.jar +j2ee.server.type=Tomcat +jar.compress=false +javac.classpath=\ + ${libs.MySQLDriver.classpath}:\ + ${libs.metro.classpath}:\ + ${libs.restapi.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +rest.config.type=ide +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=eurilys4.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/eurilys4/nbproject/project.xml b/eurilys4/nbproject/project.xml new file mode 100644 index 00000000..b94b242f --- /dev/null +++ b/eurilys4/nbproject/project.xml @@ -0,0 +1,36 @@ + + + org.netbeans.modules.web.project + + + + + + + + eurilys4 + 1.6.5 + + + ${libs.MySQLDriver.classpath} + WEB-INF/lib + + + ${libs.metro.classpath} + WEB-INF/lib + + + ${libs.restapi.classpath} + WEB-INF/lib + + + + + + + + + + + + diff --git a/eurilys4/nbproject/rest-build.xml b/eurilys4/nbproject/rest-build.xml new file mode 100644 index 00000000..930d7a69 --- /dev/null +++ b/eurilys4/nbproject/rest-build.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.netbeans.rest.application.config; +/** + * This class is generated by the NetBeans IDE, + * and registers all REST root resources created in the project. + * Please, DO NOT EDIT this class unless you really need and + * understand the results of changes. + * It is safe to change REST resources path value of + * ApplicationPath annotation. It can be done also via UI action + * called on RESTful Web Services node ( REST Resources Configuration dialog ). + * + */ +@javax.ws.rs.ApplicationPath("${rest.resources.path}") +public class ApplicationConfig extends javax.ws.rs.core.Application { +} + + diff --git a/eurilys4/src/conf/MANIFEST.MF b/eurilys4/src/conf/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/eurilys4/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/eurilys4/src/java/Function/FileManager.java b/eurilys4/src/java/Function/FileManager.java new file mode 100644 index 00000000..2f3a4a1d --- /dev/null +++ b/eurilys4/src/java/Function/FileManager.java @@ -0,0 +1,19 @@ +package Function; + +import javax.servlet.http.Part; + +public class FileManager { + public static String getFilename(Part part) { + for (String cd : part.getHeader("content-disposition").split(";")) { + if (cd.trim().startsWith("filename")) { + String filename = cd.substring(cd.indexOf('=') + 1).trim().replace("\"", ""); + return filename.substring(filename.lastIndexOf('/') + 1).substring(filename.lastIndexOf('\\') + 1); // MSIE fix. + } + } + return null; + } + + public static String getExtension (String filename){ + return filename.substring(filename.lastIndexOf(".")).toLowerCase(); + } +} diff --git a/eurilys4/src/java/jsonlib/CDL.java b/eurilys4/src/java/jsonlib/CDL.java new file mode 100644 index 00000000..0fc3cf82 --- /dev/null +++ b/eurilys4/src/java/jsonlib/CDL.java @@ -0,0 +1,279 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * This provides static methods to convert comma delimited text into a + * JSONArray, and to covert a JSONArray into comma delimited text. Comma + * delimited text is a very popular format for data interchange. It is + * understood by most database, spreadsheet, and organizer programs. + *

    + * Each row of text represents a row in a table or a data record. Each row + * ends with a NEWLINE character. Each row contains one or more values. + * Values are separated by commas. A value can contain any character except + * for comma, unless is is wrapped in single quotes or double quotes. + *

    + * The first row usually contains the names of the columns. + *

    + * A comma delimited list can be converted into a JSONArray of JSONObjects. + * The names for the elements in the JSONObjects can be taken from the names + * in the first row. + * @author JSON.org + * @version 2012-11-13 + */ +public class CDL { + + /** + * Get the next value. The value can be wrapped in quotes. The value can + * be empty. + * @param x A JSONTokener of the source text. + * @return The value string, or null if empty. + * @throws JSONException if the quoted string is badly formed. + */ + private static String getValue(JSONTokener x) throws JSONException { + char c; + char q; + StringBuffer sb; + do { + c = x.next(); + } while (c == ' ' || c == '\t'); + switch (c) { + case 0: + return null; + case '"': + case '\'': + q = c; + sb = new StringBuffer(); + for (;;) { + c = x.next(); + if (c == q) { + break; + } + if (c == 0 || c == '\n' || c == '\r') { + throw x.syntaxError("Missing close quote '" + q + "'."); + } + sb.append(c); + } + return sb.toString(); + case ',': + x.back(); + return ""; + default: + x.back(); + return x.nextTo(','); + } + } + + /** + * Produce a JSONArray of strings from a row of comma delimited values. + * @param x A JSONTokener of the source text. + * @return A JSONArray of strings. + * @throws JSONException + */ + public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException { + JSONArray ja = new JSONArray(); + for (;;) { + String value = getValue(x); + char c = x.next(); + if (value == null || + (ja.length() == 0 && value.length() == 0 && c != ',')) { + return null; + } + ja.put(value); + for (;;) { + if (c == ',') { + break; + } + if (c != ' ') { + if (c == '\n' || c == '\r' || c == 0) { + return ja; + } + throw x.syntaxError("Bad character '" + c + "' (" + + (int)c + ")."); + } + c = x.next(); + } + } + } + + /** + * Produce a JSONObject from a row of comma delimited text, using a + * parallel JSONArray of strings to provides the names of the elements. + * @param names A JSONArray of names. This is commonly obtained from the + * first row of a comma delimited text file using the rowToJSONArray + * method. + * @param x A JSONTokener of the source text. + * @return A JSONObject combining the names and values. + * @throws JSONException + */ + public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x) + throws JSONException { + JSONArray ja = rowToJSONArray(x); + return ja != null ? ja.toJSONObject(names) : null; + } + + /** + * Produce a comma delimited text row from a JSONArray. Values containing + * the comma character will be quoted. Troublesome characters may be + * removed. + * @param ja A JSONArray of strings. + * @return A string ending in NEWLINE. + */ + public static String rowToString(JSONArray ja) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < ja.length(); i += 1) { + if (i > 0) { + sb.append(','); + } + Object object = ja.opt(i); + if (object != null) { + String string = object.toString(); + if (string.length() > 0 && (string.indexOf(',') >= 0 || + string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 || + string.indexOf(0) >= 0 || string.charAt(0) == '"')) { + sb.append('"'); + int length = string.length(); + for (int j = 0; j < length; j += 1) { + char c = string.charAt(j); + if (c >= ' ' && c != '"') { + sb.append(c); + } + } + sb.append('"'); + } else { + sb.append(string); + } + } + } + sb.append('\n'); + return sb.toString(); + } + + /** + * Produce a JSONArray of JSONObjects from a comma delimited text string, + * using the first row as a source of names. + * @param string The comma delimited text. + * @return A JSONArray of JSONObjects. + * @throws JSONException + */ + public static JSONArray toJSONArray(String string) throws JSONException { + return toJSONArray(new JSONTokener(string)); + } + + /** + * Produce a JSONArray of JSONObjects from a comma delimited text string, + * using the first row as a source of names. + * @param x The JSONTokener containing the comma delimited text. + * @return A JSONArray of JSONObjects. + * @throws JSONException + */ + public static JSONArray toJSONArray(JSONTokener x) throws JSONException { + return toJSONArray(rowToJSONArray(x), x); + } + + /** + * Produce a JSONArray of JSONObjects from a comma delimited text string + * using a supplied JSONArray as the source of element names. + * @param names A JSONArray of strings. + * @param string The comma delimited text. + * @return A JSONArray of JSONObjects. + * @throws JSONException + */ + public static JSONArray toJSONArray(JSONArray names, String string) + throws JSONException { + return toJSONArray(names, new JSONTokener(string)); + } + + /** + * Produce a JSONArray of JSONObjects from a comma delimited text string + * using a supplied JSONArray as the source of element names. + * @param names A JSONArray of strings. + * @param x A JSONTokener of the source text. + * @return A JSONArray of JSONObjects. + * @throws JSONException + */ + public static JSONArray toJSONArray(JSONArray names, JSONTokener x) + throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + JSONArray ja = new JSONArray(); + for (;;) { + JSONObject jo = rowToJSONObject(names, x); + if (jo == null) { + break; + } + ja.put(jo); + } + if (ja.length() == 0) { + return null; + } + return ja; + } + + + /** + * Produce a comma delimited text from a JSONArray of JSONObjects. The + * first row will be a list of names obtained by inspecting the first + * JSONObject. + * @param ja A JSONArray of JSONObjects. + * @return A comma delimited text. + * @throws JSONException + */ + public static String toString(JSONArray ja) throws JSONException { + JSONObject jo = ja.optJSONObject(0); + if (jo != null) { + JSONArray names = jo.names(); + if (names != null) { + return rowToString(names) + toString(names, ja); + } + } + return null; + } + + /** + * Produce a comma delimited text from a JSONArray of JSONObjects using + * a provided list of names. The list of names is not included in the + * output. + * @param names A JSONArray of strings. + * @param ja A JSONArray of JSONObjects. + * @return A comma delimited text. + * @throws JSONException + */ + public static String toString(JSONArray names, JSONArray ja) + throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < ja.length(); i += 1) { + JSONObject jo = ja.optJSONObject(i); + if (jo != null) { + sb.append(rowToString(jo.toJSONArray(names))); + } + } + return sb.toString(); + } +} diff --git a/eurilys4/src/java/jsonlib/Cookie.java b/eurilys4/src/java/jsonlib/Cookie.java new file mode 100644 index 00000000..a2d9c4ed --- /dev/null +++ b/eurilys4/src/java/jsonlib/Cookie.java @@ -0,0 +1,169 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * Convert a web browser cookie specification to a JSONObject and back. + * JSON and Cookies are both notations for name/value pairs. + * @author JSON.org + * @version 2010-12-24 + */ +public class Cookie { + + /** + * Produce a copy of a string in which the characters '+', '%', '=', ';' + * and control characters are replaced with "%hh". This is a gentle form + * of URL encoding, attempting to cause as little distortion to the + * string as possible. The characters '=' and ';' are meta characters in + * cookies. By convention, they are escaped using the URL-encoding. This is + * only a convention, not a standard. Often, cookies are expected to have + * encoded values. We encode '=' and ';' because we must. We encode '%' and + * '+' because they are meta characters in URL encoding. + * @param string The source string. + * @return The escaped result. + */ + public static String escape(String string) { + char c; + String s = string.trim(); + StringBuffer sb = new StringBuffer(); + int length = s.length(); + for (int i = 0; i < length; i += 1) { + c = s.charAt(i); + if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') { + sb.append('%'); + sb.append(Character.forDigit((char)((c >>> 4) & 0x0f), 16)); + sb.append(Character.forDigit((char)(c & 0x0f), 16)); + } else { + sb.append(c); + } + } + return sb.toString(); + } + + + /** + * Convert a cookie specification string into a JSONObject. The string + * will contain a name value pair separated by '='. The name and the value + * will be unescaped, possibly converting '+' and '%' sequences. The + * cookie properties may follow, separated by ';', also represented as + * name=value (except the secure property, which does not have a value). + * The name will be stored under the key "name", and the value will be + * stored under the key "value". This method does not do checking or + * validation of the parameters. It only converts the cookie string into + * a JSONObject. + * @param string The cookie specification string. + * @return A JSONObject containing "name", "value", and possibly other + * members. + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + String name; + JSONObject jo = new JSONObject(); + Object value; + JSONTokener x = new JSONTokener(string); + jo.put("name", x.nextTo('=')); + x.next('='); + jo.put("value", x.nextTo(';')); + x.next(); + while (x.more()) { + name = unescape(x.nextTo("=;")); + if (x.next() != '=') { + if (name.equals("secure")) { + value = Boolean.TRUE; + } else { + throw x.syntaxError("Missing '=' in cookie parameter."); + } + } else { + value = unescape(x.nextTo(';')); + x.next(); + } + jo.put(name, value); + } + return jo; + } + + + /** + * Convert a JSONObject into a cookie specification string. The JSONObject + * must contain "name" and "value" members. + * If the JSONObject contains "expires", "domain", "path", or "secure" + * members, they will be appended to the cookie specification string. + * All other members are ignored. + * @param jo A JSONObject + * @return A cookie specification string + * @throws JSONException + */ + public static String toString(JSONObject jo) throws JSONException { + StringBuffer sb = new StringBuffer(); + + sb.append(escape(jo.getString("name"))); + sb.append("="); + sb.append(escape(jo.getString("value"))); + if (jo.has("expires")) { + sb.append(";expires="); + sb.append(jo.getString("expires")); + } + if (jo.has("domain")) { + sb.append(";domain="); + sb.append(escape(jo.getString("domain"))); + } + if (jo.has("path")) { + sb.append(";path="); + sb.append(escape(jo.getString("path"))); + } + if (jo.optBoolean("secure")) { + sb.append(";secure"); + } + return sb.toString(); + } + + /** + * Convert %hh sequences to single characters, and + * convert plus to space. + * @param string A string that may contain + * + (plus) and + * %hh sequences. + * @return The unescaped string. + */ + public static String unescape(String string) { + int length = string.length(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < length; ++i) { + char c = string.charAt(i); + if (c == '+') { + c = ' '; + } else if (c == '%' && i + 2 < length) { + int d = JSONTokener.dehexchar(string.charAt(i + 1)); + int e = JSONTokener.dehexchar(string.charAt(i + 2)); + if (d >= 0 && e >= 0) { + c = (char)(d * 16 + e); + i += 2; + } + } + sb.append(c); + } + return sb.toString(); + } +} diff --git a/eurilys4/src/java/jsonlib/CookieList.java b/eurilys4/src/java/jsonlib/CookieList.java new file mode 100644 index 00000000..1111135f --- /dev/null +++ b/eurilys4/src/java/jsonlib/CookieList.java @@ -0,0 +1,90 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.util.Iterator; + +/** + * Convert a web browser cookie list string to a JSONObject and back. + * @author JSON.org + * @version 2010-12-24 + */ +public class CookieList { + + /** + * Convert a cookie list into a JSONObject. A cookie list is a sequence + * of name/value pairs. The names are separated from the values by '='. + * The pairs are separated by ';'. The names and the values + * will be unescaped, possibly converting '+' and '%' sequences. + * + * To add a cookie to a cooklist, + * cookielistJSONObject.put(cookieJSONObject.getString("name"), + * cookieJSONObject.getString("value")); + * @param string A cookie list string + * @return A JSONObject + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + JSONObject jo = new JSONObject(); + JSONTokener x = new JSONTokener(string); + while (x.more()) { + String name = Cookie.unescape(x.nextTo('=')); + x.next('='); + jo.put(name, Cookie.unescape(x.nextTo(';'))); + x.next(); + } + return jo; + } + + + /** + * Convert a JSONObject into a cookie list. A cookie list is a sequence + * of name/value pairs. The names are separated from the values by '='. + * The pairs are separated by ';'. The characters '%', '+', '=', and ';' + * in the names and values are replaced by "%hh". + * @param jo A JSONObject + * @return A cookie list string + * @throws JSONException + */ + public static String toString(JSONObject jo) throws JSONException { + boolean b = false; + Iterator keys = jo.keys(); + String string; + StringBuffer sb = new StringBuffer(); + while (keys.hasNext()) { + string = keys.next().toString(); + if (!jo.isNull(string)) { + if (b) { + sb.append(';'); + } + sb.append(Cookie.escape(string)); + sb.append("="); + sb.append(Cookie.escape(jo.getString(string))); + b = true; + } + } + return sb.toString(); + } +} diff --git a/eurilys4/src/java/jsonlib/HTTP.java b/eurilys4/src/java/jsonlib/HTTP.java new file mode 100644 index 00000000..cc8203d1 --- /dev/null +++ b/eurilys4/src/java/jsonlib/HTTP.java @@ -0,0 +1,163 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.util.Iterator; + +/** + * Convert an HTTP header to a JSONObject and back. + * @author JSON.org + * @version 2010-12-24 + */ +public class HTTP { + + /** Carriage return/line feed. */ + public static final String CRLF = "\r\n"; + + /** + * Convert an HTTP header string into a JSONObject. It can be a request + * header or a response header. A request header will contain + *

    {
    +     *    Method: "POST" (for example),
    +     *    "Request-URI": "/" (for example),
    +     *    "HTTP-Version": "HTTP/1.1" (for example)
    +     * }
    + * A response header will contain + *
    {
    +     *    "HTTP-Version": "HTTP/1.1" (for example),
    +     *    "Status-Code": "200" (for example),
    +     *    "Reason-Phrase": "OK" (for example)
    +     * }
    + * In addition, the other parameters in the header will be captured, using + * the HTTP field names as JSON names, so that
    +     *    Date: Sun, 26 May 2002 18:06:04 GMT
    +     *    Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
    +     *    Cache-Control: no-cache
    + * become + *
    {...
    +     *    Date: "Sun, 26 May 2002 18:06:04 GMT",
    +     *    Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
    +     *    "Cache-Control": "no-cache",
    +     * ...}
    + * It does no further checking or conversion. It does not parse dates. + * It does not do '%' transforms on URLs. + * @param string An HTTP header string. + * @return A JSONObject containing the elements and attributes + * of the XML string. + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + JSONObject jo = new JSONObject(); + HTTPTokener x = new HTTPTokener(string); + String token; + + token = x.nextToken(); + if (token.toUpperCase().startsWith("HTTP")) { + +// Response + + jo.put("HTTP-Version", token); + jo.put("Status-Code", x.nextToken()); + jo.put("Reason-Phrase", x.nextTo('\0')); + x.next(); + + } else { + +// Request + + jo.put("Method", token); + jo.put("Request-URI", x.nextToken()); + jo.put("HTTP-Version", x.nextToken()); + } + +// Fields + + while (x.more()) { + String name = x.nextTo(':'); + x.next(':'); + jo.put(name, x.nextTo('\0')); + x.next(); + } + return jo; + } + + + /** + * Convert a JSONObject into an HTTP header. A request header must contain + *
    {
    +     *    Method: "POST" (for example),
    +     *    "Request-URI": "/" (for example),
    +     *    "HTTP-Version": "HTTP/1.1" (for example)
    +     * }
    + * A response header must contain + *
    {
    +     *    "HTTP-Version": "HTTP/1.1" (for example),
    +     *    "Status-Code": "200" (for example),
    +     *    "Reason-Phrase": "OK" (for example)
    +     * }
    + * Any other members of the JSONObject will be output as HTTP fields. + * The result will end with two CRLF pairs. + * @param jo A JSONObject + * @return An HTTP header string. + * @throws JSONException if the object does not contain enough + * information. + */ + public static String toString(JSONObject jo) throws JSONException { + Iterator keys = jo.keys(); + String string; + StringBuffer sb = new StringBuffer(); + if (jo.has("Status-Code") && jo.has("Reason-Phrase")) { + sb.append(jo.getString("HTTP-Version")); + sb.append(' '); + sb.append(jo.getString("Status-Code")); + sb.append(' '); + sb.append(jo.getString("Reason-Phrase")); + } else if (jo.has("Method") && jo.has("Request-URI")) { + sb.append(jo.getString("Method")); + sb.append(' '); + sb.append('"'); + sb.append(jo.getString("Request-URI")); + sb.append('"'); + sb.append(' '); + sb.append(jo.getString("HTTP-Version")); + } else { + throw new JSONException("Not enough material for an HTTP header."); + } + sb.append(CRLF); + while (keys.hasNext()) { + string = keys.next().toString(); + if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && + !"Reason-Phrase".equals(string) && !"Method".equals(string) && + !"Request-URI".equals(string) && !jo.isNull(string)) { + sb.append(string); + sb.append(": "); + sb.append(jo.getString(string)); + sb.append(CRLF); + } + } + sb.append(CRLF); + return sb.toString(); + } +} diff --git a/eurilys4/src/java/jsonlib/HTTPTokener.java b/eurilys4/src/java/jsonlib/HTTPTokener.java new file mode 100644 index 00000000..ed41744a --- /dev/null +++ b/eurilys4/src/java/jsonlib/HTTPTokener.java @@ -0,0 +1,77 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * The HTTPTokener extends the JSONTokener to provide additional methods + * for the parsing of HTTP headers. + * @author JSON.org + * @version 2012-11-13 + */ +public class HTTPTokener extends JSONTokener { + + /** + * Construct an HTTPTokener from a string. + * @param string A source string. + */ + public HTTPTokener(String string) { + super(string); + } + + + /** + * Get the next token or string. This is used in parsing HTTP headers. + * @throws JSONException + * @return A String. + */ + public String nextToken() throws JSONException { + char c; + char q; + StringBuffer sb = new StringBuffer(); + do { + c = next(); + } while (Character.isWhitespace(c)); + if (c == '"' || c == '\'') { + q = c; + for (;;) { + c = next(); + if (c < ' ') { + throw syntaxError("Unterminated string."); + } + if (c == q) { + return sb.toString(); + } + sb.append(c); + } + } + for (;;) { + if (c == 0 || Character.isWhitespace(c)) { + return sb.toString(); + } + sb.append(c); + c = next(); + } + } +} diff --git a/eurilys4/src/java/jsonlib/JSONArray.java b/eurilys4/src/java/jsonlib/JSONArray.java new file mode 100644 index 00000000..673a9192 --- /dev/null +++ b/eurilys4/src/java/jsonlib/JSONArray.java @@ -0,0 +1,944 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +/** + * A JSONArray is an ordered sequence of values. Its external text form is a + * string wrapped in square brackets with commas separating the values. The + * internal form is an object having get and opt + * methods for accessing the values by index, and put methods for + * adding or replacing values. The values can be any of these types: + * Boolean, JSONArray, JSONObject, + * Number, String, or the + * JSONObject.NULL object. + *

    + * The constructor can convert a JSON text into a Java object. The + * toString method converts to JSON text. + *

    + * A get method returns a value if one can be found, and throws an + * exception if one cannot be found. An opt method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + *

    + * The generic get() and opt() methods return an + * object which you can cast or query for type. There are also typed + * get and opt methods that do type checking and type + * coercion for you. + *

    + * The texts produced by the toString methods strictly conform to + * JSON syntax rules. The constructors are more forgiving in the texts they will + * accept: + *

      + *
    • An extra , (comma) may appear just + * before the closing bracket.
    • + *
    • The null value will be inserted when there is , + *  (comma) elision.
    • + *
    • Strings may be quoted with ' (single + * quote).
    • + *
    • Strings do not need to be quoted at all if they do not begin with a quote + * or single quote, and if they do not contain leading or trailing spaces, and + * if they do not contain any of these characters: + * { } [ ] / \ : , # and if they do not look like numbers and + * if they are not the reserved words true, false, or + * null.
    • + *
    + * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONArray { + + /** + * The arrayList where the JSONArray's properties are kept. + */ + private final ArrayList myArrayList; + + /** + * Construct an empty JSONArray. + */ + public JSONArray() { + this.myArrayList = new ArrayList(); + } + + /** + * Construct a JSONArray from a JSONTokener. + * + * @param x + * A JSONTokener + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(JSONTokener x) throws JSONException { + this(); + if (x.nextClean() != '[') { + throw x.syntaxError("A JSONArray text must start with '['"); + } + if (x.nextClean() != ']') { + x.back(); + for (;;) { + if (x.nextClean() == ',') { + x.back(); + this.myArrayList.add(JSONObject.NULL); + } else { + x.back(); + this.myArrayList.add(x.nextValue()); + } + switch (x.nextClean()) { + case ',': + if (x.nextClean() == ']') { + return; + } + x.back(); + break; + case ']': + return; + default: + throw x.syntaxError("Expected a ',' or ']'"); + } + } + } + } + + /** + * Construct a JSONArray from a source JSON text. + * + * @param source + * A string that begins with [ (left + * bracket) and ends with ] + *  (right bracket). + * @throws JSONException + * If there is a syntax error. + */ + public JSONArray(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONArray from a Collection. + * + * @param collection + * A Collection. + */ + public JSONArray(Collection collection) { + this.myArrayList = new ArrayList(); + if (collection != null) { + Iterator iter = collection.iterator(); + while (iter.hasNext()) { + this.myArrayList.add(JSONObject.wrap(iter.next())); + } + } + } + + /** + * Construct a JSONArray from an array + * + * @throws JSONException + * If not an array. + */ + public JSONArray(Object array) throws JSONException { + this(); + if (array.getClass().isArray()) { + int length = Array.getLength(array); + for (int i = 0; i < length; i += 1) { + this.put(JSONObject.wrap(Array.get(array, i))); + } + } else { + throw new JSONException( + "JSONArray initial value should be a string or collection or array."); + } + } + + /** + * Get the object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value. + * @throws JSONException + * If there is no value for the index. + */ + public Object get(int index) throws JSONException { + Object object = this.opt(index); + if (object == null) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with an index. The string values "true" + * and "false" are converted to boolean. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + * @throws JSONException + * If there is no value for the index or if the value is not + * convertible to boolean. + */ + public boolean getBoolean(int index) throws JSONException { + Object object = this.get(index); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONArray[" + index + "] is not a boolean."); + } + + /** + * Get the double value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public double getDouble(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the int value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value is not a number. + */ + public int getInt(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the JSONArray associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONArray value. + * @throws JSONException + * If there is no value for the index. or if the value is not a + * JSONArray + */ + public JSONArray getJSONArray(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); + } + + /** + * Get the JSONObject associated with an index. + * + * @param index + * subscript + * @return A JSONObject value. + * @throws JSONException + * If there is no value for the index or if the value is not a + * JSONObject + */ + public JSONObject getJSONObject(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); + } + + /** + * Get the long value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a number. + */ + public long getLong(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + /** + * Get the string associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A string value. + * @throws JSONException + * If there is no string value for the index. + */ + public String getString(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONArray[" + index + "] not a string."); + } + + /** + * Determine if the value is null. + * + * @param index + * The index must be between 0 and length() - 1. + * @return true if the value at the index is null, or if there is no value. + */ + public boolean isNull(int index) { + return JSONObject.NULL.equals(this.opt(index)); + } + + /** + * Make a string from the contents of this JSONArray. The + * separator string is inserted between each element. Warning: + * This method assumes that the data structure is acyclical. + * + * @param separator + * A string that will be inserted between the elements. + * @return a string. + * @throws JSONException + * If the array contains an invalid number. + */ + public String join(String separator) throws JSONException { + int len = this.length(); + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < len; i += 1) { + if (i > 0) { + sb.append(separator); + } + sb.append(JSONObject.valueToString(this.myArrayList.get(i))); + } + return sb.toString(); + } + + /** + * Get the number of elements in the JSONArray, included nulls. + * + * @return The length (or size). + */ + public int length() { + return this.myArrayList.size(); + } + + /** + * Get the optional object value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return An object value, or null if there is no object at that index. + */ + public Object opt(int index) { + return (index < 0 || index >= this.length()) ? null : this.myArrayList + .get(index); + } + + /** + * Get the optional boolean value associated with an index. It returns false + * if there is no value at that index, or if the value is not Boolean.TRUE + * or the String "true". + * + * @param index + * The index must be between 0 and length() - 1. + * @return The truth. + */ + public boolean optBoolean(int index) { + return this.optBoolean(index, false); + } + + /** + * Get the optional boolean value associated with an index. It returns the + * defaultValue if there is no value at that index or if it is not a Boolean + * or the String "true" or "false" (case insensitive). + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * A boolean default. + * @return The truth. + */ + public boolean optBoolean(int index, boolean defaultValue) { + try { + return this.getBoolean(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional double value associated with an index. NaN is returned + * if there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public double optDouble(int index) { + return this.optDouble(index, Double.NaN); + } + + /** + * Get the optional double value associated with an index. The defaultValue + * is returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * subscript + * @param defaultValue + * The default value. + * @return The value. + */ + public double optDouble(int index, double defaultValue) { + try { + return this.getDouble(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional int value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public int optInt(int index) { + return this.optInt(index, 0); + } + + /** + * Get the optional int value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public int optInt(int index, int defaultValue) { + try { + return this.getInt(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional JSONArray associated with an index. + * + * @param index + * subscript + * @return A JSONArray value, or null if the index has no value, or if the + * value is not a JSONArray. + */ + public JSONArray optJSONArray(int index) { + Object o = this.opt(index); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get the optional JSONObject associated with an index. Null is returned if + * the key is not found, or null if the index has no value, or if the value + * is not a JSONObject. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A JSONObject value. + */ + public JSONObject optJSONObject(int index) { + Object o = this.opt(index); + return o instanceof JSONObject ? (JSONObject) o : null; + } + + /** + * Get the optional long value associated with an index. Zero is returned if + * there is no value for the index, or if the value is not a number and + * cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + */ + public long optLong(int index) { + return this.optLong(index, 0); + } + + /** + * Get the optional long value associated with an index. The defaultValue is + * returned if there is no value for the index, or if the value is not a + * number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public long optLong(int index, long defaultValue) { + try { + return this.getLong(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional string value associated with an index. It returns an + * empty string if there is no value at that index. If the value is not a + * string and is not null, then it is coverted to a string. + * + * @param index + * The index must be between 0 and length() - 1. + * @return A String value. + */ + public String optString(int index) { + return this.optString(index, ""); + } + + /** + * Get the optional string associated with an index. The defaultValue is + * returned if the key is not found. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return A String value. + */ + public String optString(int index, String defaultValue) { + Object object = this.opt(index); + return JSONObject.NULL.equals(object) ? defaultValue : object + .toString(); + } + + /** + * Append a boolean value. This increases the array's length by one. + * + * @param value + * A boolean value. + * @return this. + */ + public JSONArray put(boolean value) { + this.put(value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param value + * A Collection value. + * @return this. + */ + public JSONArray put(Collection value) { + this.put(new JSONArray(value)); + return this; + } + + /** + * Append a double value. This increases the array's length by one. + * + * @param value + * A double value. + * @throws JSONException + * if the value is not finite. + * @return this. + */ + public JSONArray put(double value) throws JSONException { + Double d = new Double(value); + JSONObject.testValidity(d); + this.put(d); + return this; + } + + /** + * Append an int value. This increases the array's length by one. + * + * @param value + * An int value. + * @return this. + */ + public JSONArray put(int value) { + this.put(new Integer(value)); + return this; + } + + /** + * Append an long value. This increases the array's length by one. + * + * @param value + * A long value. + * @return this. + */ + public JSONArray put(long value) { + this.put(new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject which + * is produced from a Map. + * + * @param value + * A Map value. + * @return this. + */ + public JSONArray put(Map value) { + this.put(new JSONObject(value)); + return this; + } + + /** + * Append an object value. This increases the array's length by one. + * + * @param value + * An object value. The value should be a Boolean, Double, + * Integer, JSONArray, JSONObject, Long, or String, or the + * JSONObject.NULL object. + * @return this. + */ + public JSONArray put(Object value) { + this.myArrayList.add(value); + return this; + } + + /** + * Put or replace a boolean value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * A boolean value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, boolean value) throws JSONException { + this.put(index, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONArray which + * is produced from a Collection. + * + * @param index + * The subscript. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, Collection value) throws JSONException { + this.put(index, new JSONArray(value)); + return this; + } + + /** + * Put or replace a double value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A double value. + * @return this. + * @throws JSONException + * If the index is negative or if the value is not finite. + */ + public JSONArray put(int index, double value) throws JSONException { + this.put(index, new Double(value)); + return this; + } + + /** + * Put or replace an int value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * An int value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, int value) throws JSONException { + this.put(index, new Integer(value)); + return this; + } + + /** + * Put or replace a long value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad it + * out. + * + * @param index + * The subscript. + * @param value + * A long value. + * @return this. + * @throws JSONException + * If the index is negative. + */ + public JSONArray put(int index, long value) throws JSONException { + this.put(index, new Long(value)); + return this; + } + + /** + * Put a value in the JSONArray, where the value will be a JSONObject that + * is produced from a Map. + * + * @param index + * The subscript. + * @param value + * The Map value. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Map value) throws JSONException { + this.put(index, new JSONObject(value)); + return this; + } + + /** + * Put or replace an object value in the JSONArray. If the index is greater + * than the length of the JSONArray, then null elements will be added as + * necessary to pad it out. + * + * @param index + * The subscript. + * @param value + * The value to put into the array. The value should be a + * Boolean, Double, Integer, JSONArray, JSONObject, Long, or + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the index is negative or if the the value is an invalid + * number. + */ + public JSONArray put(int index, Object value) throws JSONException { + JSONObject.testValidity(value); + if (index < 0) { + throw new JSONException("JSONArray[" + index + "] not found."); + } + if (index < this.length()) { + this.myArrayList.set(index, value); + } else { + while (index != this.length()) { + this.put(JSONObject.NULL); + } + this.put(value); + } + return this; + } + + /** + * Remove an index and close the hole. + * + * @param index + * The index of the element to be removed. + * @return The value that was associated with the index, or null if there + * was no value. + */ + public Object remove(int index) { + Object o = this.opt(index); + this.myArrayList.remove(index); + return o; + } + + /** + * Produce a JSONObject by combining a JSONArray of names with the values of + * this JSONArray. + * + * @param names + * A JSONArray containing a list of key strings. These will be + * paired with the values. + * @return A JSONObject, or null if there are no names or if this JSONArray + * has no values. + * @throws JSONException + * If any of the names are null. + */ + public JSONObject toJSONObject(JSONArray names) throws JSONException { + if (names == null || names.length() == 0 || this.length() == 0) { + return null; + } + JSONObject jo = new JSONObject(); + for (int i = 0; i < names.length(); i += 1) { + jo.put(names.getString(i), this.opt(i)); + } + return jo; + } + + /** + * Make a JSON text of this JSONArray. For compactness, no unnecessary + * whitespace is added. If it is not possible to produce a syntactically + * correct JSON text then null will be returned instead. This could occur if + * the array contains an invalid number. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, transmittable representation of the + * array. + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONArray. Warning: This method + * assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, transmittable representation of the + * object, beginning with [ (left + * bracket) and ending with ] + *  (right bracket). + * @throws JSONException + */ + public String toString(int indentFactor) throws JSONException { + StringWriter sw = new StringWriter(); + synchronized (sw.getBuffer()) { + return this.write(sw, indentFactor, 0).toString(); + } + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + /** + * Write the contents of the JSONArray as JSON text to a writer. For + * compactness, no whitespace is added. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @param indent + * The indention of the top level. + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + int length = this.length(); + writer.write('['); + + if (length == 1) { + JSONObject.writeValue(writer, this.myArrayList.get(0), + indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + + for (int i = 0; i < length; i += 1) { + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, newindent); + JSONObject.writeValue(writer, this.myArrayList.get(i), + indentFactor, newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, indent); + } + writer.write(']'); + return writer; + } catch (IOException e) { + throw new JSONException(e); + } + } +} diff --git a/eurilys4/src/java/jsonlib/JSONException.java b/eurilys4/src/java/jsonlib/JSONException.java new file mode 100644 index 00000000..971547e6 --- /dev/null +++ b/eurilys4/src/java/jsonlib/JSONException.java @@ -0,0 +1,41 @@ +package org.json; + +/** + * The JSONException is thrown by the JSON.org classes when things are amiss. + * + * @author JSON.org + * @version 2013-02-10 + */ +public class JSONException extends RuntimeException { + private static final long serialVersionUID = 0; + private Throwable cause; + + /** + * Constructs a JSONException with an explanatory message. + * + * @param message + * Detail about the reason for the exception. + */ + public JSONException(String message) { + super(message); + } + + /** + * Constructs a new JSONException with the specified cause. + */ + public JSONException(Throwable cause) { + super(cause.getMessage()); + this.cause = cause; + } + + /** + * Returns the cause of this exception or null if the cause is nonexistent + * or unknown. + * + * @returns the cause of this exception or null if the cause is nonexistent + * or unknown. + */ + public Throwable getCause() { + return this.cause; + } +} diff --git a/eurilys4/src/java/jsonlib/JSONML.java b/eurilys4/src/java/jsonlib/JSONML.java new file mode 100644 index 00000000..4be68635 --- /dev/null +++ b/eurilys4/src/java/jsonlib/JSONML.java @@ -0,0 +1,467 @@ +package org.json; + +/* +Copyright (c) 2008 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.util.Iterator; + + +/** + * This provides static methods to convert an XML text into a JSONArray or + * JSONObject, and to covert a JSONArray or JSONObject into an XML text using + * the JsonML transform. + * + * @author JSON.org + * @version 2012-03-28 + */ +public class JSONML { + + /** + * Parse XML values and store them in a JSONArray. + * @param x The XMLTokener containing the source string. + * @param arrayForm true if array form, false if object form. + * @param ja The JSONArray that is containing the current tag or null + * if we are at the outermost level. + * @return A JSONArray if the value is the outermost tag, otherwise null. + * @throws JSONException + */ + private static Object parse( + XMLTokener x, + boolean arrayForm, + JSONArray ja + ) throws JSONException { + String attribute; + char c; + String closeTag = null; + int i; + JSONArray newja = null; + JSONObject newjo = null; + Object token; + String tagName = null; + +// Test for and skip past these forms: +// +// +// +// + + while (true) { + if (!x.more()) { + throw x.syntaxError("Bad XML"); + } + token = x.nextContent(); + if (token == XML.LT) { + token = x.nextToken(); + if (token instanceof Character) { + if (token == XML.SLASH) { + +// Close tag "); + } else { + x.back(); + } + } else if (c == '[') { + token = x.nextToken(); + if (token.equals("CDATA") && x.next() == '[') { + if (ja != null) { + ja.put(x.nextCDATA()); + } + } else { + throw x.syntaxError("Expected 'CDATA['"); + } + } else { + i = 1; + do { + token = x.nextMeta(); + if (token == null) { + throw x.syntaxError("Missing '>' after ' 0); + } + } else if (token == XML.QUEST) { + +// "); + } else { + throw x.syntaxError("Misshaped tag"); + } + +// Open tag < + + } else { + if (!(token instanceof String)) { + throw x.syntaxError("Bad tagName '" + token + "'."); + } + tagName = (String)token; + newja = new JSONArray(); + newjo = new JSONObject(); + if (arrayForm) { + newja.put(tagName); + if (ja != null) { + ja.put(newja); + } + } else { + newjo.put("tagName", tagName); + if (ja != null) { + ja.put(newjo); + } + } + token = null; + for (;;) { + if (token == null) { + token = x.nextToken(); + } + if (token == null) { + throw x.syntaxError("Misshaped tag"); + } + if (!(token instanceof String)) { + break; + } + +// attribute = value + + attribute = (String)token; + if (!arrayForm && ("tagName".equals(attribute) || "childNode".equals(attribute))) { + throw x.syntaxError("Reserved attribute."); + } + token = x.nextToken(); + if (token == XML.EQ) { + token = x.nextToken(); + if (!(token instanceof String)) { + throw x.syntaxError("Missing value"); + } + newjo.accumulate(attribute, XML.stringToValue((String)token)); + token = null; + } else { + newjo.accumulate(attribute, ""); + } + } + if (arrayForm && newjo.length() > 0) { + newja.put(newjo); + } + +// Empty tag <.../> + + if (token == XML.SLASH) { + if (x.nextToken() != XML.GT) { + throw x.syntaxError("Misshaped tag"); + } + if (ja == null) { + if (arrayForm) { + return newja; + } else { + return newjo; + } + } + +// Content, between <...> and + + } else { + if (token != XML.GT) { + throw x.syntaxError("Misshaped tag"); + } + closeTag = (String)parse(x, arrayForm, newja); + if (closeTag != null) { + if (!closeTag.equals(tagName)) { + throw x.syntaxError("Mismatched '" + tagName + + "' and '" + closeTag + "'"); + } + tagName = null; + if (!arrayForm && newja.length() > 0) { + newjo.put("childNodes", newja); + } + if (ja == null) { + if (arrayForm) { + return newja; + } else { + return newjo; + } + } + } + } + } + } else { + if (ja != null) { + ja.put(token instanceof String + ? XML.stringToValue((String)token) + : token); + } + } + } + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONArray using the JsonML transform. Each XML tag is represented as + * a JSONArray in which the first element is the tag name. If the tag has + * attributes, then the second element will be JSONObject containing the + * name/value pairs. If the tag contains children, then strings and + * JSONArrays will represent the child tags. + * Comments, prologs, DTDs, and <[ [ ]]> are ignored. + * @param string The source string. + * @return A JSONArray containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONArray toJSONArray(String string) throws JSONException { + return toJSONArray(new XMLTokener(string)); + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONArray using the JsonML transform. Each XML tag is represented as + * a JSONArray in which the first element is the tag name. If the tag has + * attributes, then the second element will be JSONObject containing the + * name/value pairs. If the tag contains children, then strings and + * JSONArrays will represent the child content and tags. + * Comments, prologs, DTDs, and <[ [ ]]> are ignored. + * @param x An XMLTokener. + * @return A JSONArray containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONArray toJSONArray(XMLTokener x) throws JSONException { + return (JSONArray)parse(x, true, null); + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONObject using the JsonML transform. Each XML tag is represented as + * a JSONObject with a "tagName" property. If the tag has attributes, then + * the attributes will be in the JSONObject as properties. If the tag + * contains children, the object will have a "childNodes" property which + * will be an array of strings and JsonML JSONObjects. + + * Comments, prologs, DTDs, and <[ [ ]]> are ignored. + * @param x An XMLTokener of the XML source text. + * @return A JSONObject containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONObject toJSONObject(XMLTokener x) throws JSONException { + return (JSONObject)parse(x, false, null); + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONObject using the JsonML transform. Each XML tag is represented as + * a JSONObject with a "tagName" property. If the tag has attributes, then + * the attributes will be in the JSONObject as properties. If the tag + * contains children, the object will have a "childNodes" property which + * will be an array of strings and JsonML JSONObjects. + + * Comments, prologs, DTDs, and <[ [ ]]> are ignored. + * @param string The XML source text. + * @return A JSONObject containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + return toJSONObject(new XMLTokener(string)); + } + + + /** + * Reverse the JSONML transformation, making an XML text from a JSONArray. + * @param ja A JSONArray. + * @return An XML string. + * @throws JSONException + */ + public static String toString(JSONArray ja) throws JSONException { + int i; + JSONObject jo; + String key; + Iterator keys; + int length; + Object object; + StringBuffer sb = new StringBuffer(); + String tagName; + String value; + +// Emit = length) { + sb.append('/'); + sb.append('>'); + } else { + sb.append('>'); + do { + object = ja.get(i); + i += 1; + if (object != null) { + if (object instanceof String) { + sb.append(XML.escape(object.toString())); + } else if (object instanceof JSONObject) { + sb.append(toString((JSONObject)object)); + } else if (object instanceof JSONArray) { + sb.append(toString((JSONArray)object)); + } + } + } while (i < length); + sb.append('<'); + sb.append('/'); + sb.append(tagName); + sb.append('>'); + } + return sb.toString(); + } + + /** + * Reverse the JSONML transformation, making an XML text from a JSONObject. + * The JSONObject must contain a "tagName" property. If it has children, + * then it must have a "childNodes" property containing an array of objects. + * The other properties are attributes with string values. + * @param jo A JSONObject. + * @return An XML string. + * @throws JSONException + */ + public static String toString(JSONObject jo) throws JSONException { + StringBuffer sb = new StringBuffer(); + int i; + JSONArray ja; + String key; + Iterator keys; + int length; + Object object; + String tagName; + String value; + +//Emit '); + } else { + sb.append('>'); + length = ja.length(); + for (i = 0; i < length; i += 1) { + object = ja.get(i); + if (object != null) { + if (object instanceof String) { + sb.append(XML.escape(object.toString())); + } else if (object instanceof JSONObject) { + sb.append(toString((JSONObject)object)); + } else if (object instanceof JSONArray) { + sb.append(toString((JSONArray)object)); + } else { + sb.append(object.toString()); + } + } + } + sb.append('<'); + sb.append('/'); + sb.append(tagName); + sb.append('>'); + } + return sb.toString(); + } +} diff --git a/eurilys4/src/java/jsonlib/JSONObject.java b/eurilys4/src/java/jsonlib/JSONObject.java new file mode 100644 index 00000000..9d2d5cee --- /dev/null +++ b/eurilys4/src/java/jsonlib/JSONObject.java @@ -0,0 +1,1664 @@ +package org.json; + +/* + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; + +/** + * A JSONObject is an unordered collection of name/value pairs. Its external + * form is a string wrapped in curly braces with colons between the names and + * values, and commas between the values and names. The internal form is an + * object having get and opt methods for accessing + * the values by name, and put methods for adding or replacing + * values by name. The values can be any of these types: Boolean, + * JSONArray, JSONObject, Number, + * String, or the JSONObject.NULL object. A + * JSONObject constructor can be used to convert an external form JSON text + * into an internal form whose values can be retrieved with the + * get and opt methods, or to convert values into a + * JSON text using the put and toString methods. A + * get method returns a value if one can be found, and throws an + * exception if one cannot be found. An opt method returns a + * default value instead of throwing an exception, and so is useful for + * obtaining optional values. + *

    + * The generic get() and opt() methods return an + * object, which you can cast or query for type. There are also typed + * get and opt methods that do type checking and type + * coercion for you. The opt methods differ from the get methods in that they + * do not throw. Instead, they return a specified value, such as null. + *

    + * The put methods add or replace values in an object. For + * example, + * + *

    + * myString = new JSONObject()
    + *         .put("JSON", "Hello, World!").toString();
    + * 
    + * + * produces the string {"JSON": "Hello, World"}. + *

    + * The texts produced by the toString methods strictly conform to + * the JSON syntax rules. The constructors are more forgiving in the texts they + * will accept: + *

      + *
    • An extra , (comma) may appear just + * before the closing brace.
    • + *
    • Strings may be quoted with ' (single + * quote).
    • + *
    • Strings do not need to be quoted at all if they do not begin with a + * quote or single quote, and if they do not contain leading or trailing + * spaces, and if they do not contain any of these characters: + * { } [ ] / \ : , # and if they do not look like numbers and + * if they are not the reserved words true, false, + * or null.
    • + *
    + * + * @author JSON.org + * @version 2013-04-18 + */ +public class JSONObject { + /** + * The maximum number of keys in the key pool. + */ + private static final int keyPoolSize = 100; + + /** + * Key pooling is like string interning, but without permanently tying up + * memory. To help conserve memory, storage of duplicated key strings in + * JSONObjects will be avoided by using a key pool to manage unique key + * string objects. This is used by JSONObject.put(string, object). + */ + private static HashMap keyPool = new HashMap(keyPoolSize); + + /** + * JSONObject.NULL is equivalent to the value that JavaScript calls null, + * whilst Java's null is equivalent to the value that JavaScript calls + * undefined. + */ + private static final class Null { + + /** + * There is only intended to be a single instance of the NULL object, + * so the clone method returns itself. + * + * @return NULL. + */ + protected final Object clone() { + return this; + } + + /** + * A Null object is equal to the null value and to itself. + * + * @param object + * An object to test for nullness. + * @return true if the object parameter is the JSONObject.NULL object or + * null. + */ + public boolean equals(Object object) { + return object == null || object == this; + } + + /** + * Get the "null" string value. + * + * @return The string "null". + */ + public String toString() { + return "null"; + } + } + + /** + * The map where the JSONObject's properties are kept. + */ + private final Map map; + + /** + * It is sometimes more convenient and less ambiguous to have a + * NULL object than to use Java's null value. + * JSONObject.NULL.equals(null) returns true. + * JSONObject.NULL.toString() returns "null". + */ + public static final Object NULL = new Null(); + + /** + * Construct an empty JSONObject. + */ + public JSONObject() { + this.map = new HashMap(); + } + + /** + * Construct a JSONObject from a subset of another JSONObject. An array of + * strings is used to identify the keys that should be copied. Missing keys + * are ignored. + * + * @param jo + * A JSONObject. + * @param names + * An array of strings. + * @throws JSONException + * @exception JSONException + * If a value is a non-finite number or if a name is + * duplicated. + */ + public JSONObject(JSONObject jo, String[] names) { + this(); + for (int i = 0; i < names.length; i += 1) { + try { + this.putOnce(names[i], jo.opt(names[i])); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a JSONTokener. + * + * @param x + * A JSONTokener object containing the source string. + * @throws JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(JSONTokener x) throws JSONException { + this(); + char c; + String key; + + if (x.nextClean() != '{') { + throw x.syntaxError("A JSONObject text must begin with '{'"); + } + for (;;) { + c = x.nextClean(); + switch (c) { + case 0: + throw x.syntaxError("A JSONObject text must end with '}'"); + case '}': + return; + default: + x.back(); + key = x.nextValue().toString(); + } + +// The key is followed by ':'. + + c = x.nextClean(); + if (c != ':') { + throw x.syntaxError("Expected a ':' after a key"); + } + this.putOnce(key, x.nextValue()); + +// Pairs are separated by ','. + + switch (x.nextClean()) { + case ';': + case ',': + if (x.nextClean() == '}') { + return; + } + x.back(); + break; + case '}': + return; + default: + throw x.syntaxError("Expected a ',' or '}'"); + } + } + } + + /** + * Construct a JSONObject from a Map. + * + * @param map + * A map object that can be used to initialize the contents of + * the JSONObject. + * @throws JSONException + */ + public JSONObject(Map map) { + this.map = new HashMap(); + if (map != null) { + Iterator i = map.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry e = (Map.Entry) i.next(); + Object value = e.getValue(); + if (value != null) { + this.map.put(e.getKey(), wrap(value)); + } + } + } + } + + /** + * Construct a JSONObject from an Object using bean getters. It reflects on + * all of the public methods of the object. For each of the methods with no + * parameters and a name starting with "get" or + * "is" followed by an uppercase letter, the method is invoked, + * and a key and the value returned from the getter method are put into the + * new JSONObject. + * + * The key is formed by removing the "get" or "is" + * prefix. If the second remaining character is not upper case, then the + * first character is converted to lower case. + * + * For example, if an object has a method named "getName", and + * if the result of calling object.getName() is + * "Larry Fine", then the JSONObject will contain + * "name": "Larry Fine". + * + * @param bean + * An object that has getter methods that should be used to make + * a JSONObject. + */ + public JSONObject(Object bean) { + this(); + this.populateMap(bean); + } + + /** + * Construct a JSONObject from an Object, using reflection to find the + * public members. The resulting JSONObject's keys will be the strings from + * the names array, and the values will be the field values associated with + * those keys in the object. If a key is not found or not visible, then it + * will not be copied into the new JSONObject. + * + * @param object + * An object that has fields that should be used to make a + * JSONObject. + * @param names + * An array of strings, the names of the fields to be obtained + * from the object. + */ + public JSONObject(Object object, String names[]) { + this(); + Class c = object.getClass(); + for (int i = 0; i < names.length; i += 1) { + String name = names[i]; + try { + this.putOpt(name, c.getField(name).get(object)); + } catch (Exception ignore) { + } + } + } + + /** + * Construct a JSONObject from a source JSON text string. This is the most + * commonly used JSONObject constructor. + * + * @param source + * A string beginning with { (left + * brace) and ending with } + *  (right brace). + * @exception JSONException + * If there is a syntax error in the source string or a + * duplicated key. + */ + public JSONObject(String source) throws JSONException { + this(new JSONTokener(source)); + } + + /** + * Construct a JSONObject from a ResourceBundle. + * + * @param baseName + * The ResourceBundle base name. + * @param locale + * The Locale to load the ResourceBundle for. + * @throws JSONException + * If any JSONExceptions are detected. + */ + public JSONObject(String baseName, Locale locale) throws JSONException { + this(); + ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, + Thread.currentThread().getContextClassLoader()); + +// Iterate through the keys in the bundle. + + Enumeration keys = bundle.getKeys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + if (key instanceof String) { + +// Go through the path, ensuring that there is a nested JSONObject for each +// segment except the last. Add the value using the last segment's name into +// the deepest nested JSONObject. + + String[] path = ((String) key).split("\\."); + int last = path.length - 1; + JSONObject target = this; + for (int i = 0; i < last; i += 1) { + String segment = path[i]; + JSONObject nextTarget = target.optJSONObject(segment); + if (nextTarget == null) { + nextTarget = new JSONObject(); + target.put(segment, nextTarget); + } + target = nextTarget; + } + target.put(path[last], bundle.getString((String) key)); + } + } + } + + /** + * Accumulate values under a key. It is similar to the put method except + * that if there is already an object stored under the key then a JSONArray + * is stored under the key to hold all of the accumulated values. If there + * is already a JSONArray, then the new value is appended to it. In + * contrast, the put method replaces the previous value. + * + * If only one value is accumulated that is not a JSONArray, then the result + * will be the same as using put. But if multiple values are accumulated, + * then the result will be like append. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the value is an invalid number or if the key is null. + */ + public JSONObject accumulate(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, + value instanceof JSONArray ? new JSONArray().put(value) + : value); + } else if (object instanceof JSONArray) { + ((JSONArray) object).put(value); + } else { + this.put(key, new JSONArray().put(object).put(value)); + } + return this; + } + + /** + * Append values to the array under a key. If the key does not exist in the + * JSONObject, then the key is put in the JSONObject with its value being a + * JSONArray containing the value parameter. If the key was already + * associated with a JSONArray, then the value parameter is appended to it. + * + * @param key + * A key string. + * @param value + * An object to be accumulated under the key. + * @return this. + * @throws JSONException + * If the key is null or if the current value associated with + * the key is not a JSONArray. + */ + public JSONObject append(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, new JSONArray().put(value)); + } else if (object instanceof JSONArray) { + this.put(key, ((JSONArray) object).put(value)); + } else { + throw new JSONException("JSONObject[" + key + + "] is not a JSONArray."); + } + return this; + } + + /** + * Produce a string from a double. The string "null" will be returned if the + * number is not finite. + * + * @param d + * A double. + * @return A String. + */ + public static String doubleToString(double d) { + if (Double.isInfinite(d) || Double.isNaN(d)) { + return "null"; + } + +// Shave off trailing zeros and decimal point, if possible. + + String string = Double.toString(d); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get the value object associated with a key. + * + * @param key + * A key string. + * @return The object associated with the key. + * @throws JSONException + * if the key is not found. + */ + public Object get(String key) throws JSONException { + if (key == null) { + throw new JSONException("Null key."); + } + Object object = this.opt(key); + if (object == null) { + throw new JSONException("JSONObject[" + quote(key) + "] not found."); + } + return object; + } + + /** + * Get the boolean value associated with a key. + * + * @param key + * A key string. + * @return The truth. + * @throws JSONException + * if the value is not a Boolean or the String "true" or + * "false". + */ + public boolean getBoolean(String key) throws JSONException { + Object object = this.get(key); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) { + return true; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a Boolean."); + } + + /** + * Get the double value associated with a key. + * + * @param key + * A key string. + * @return The numeric value. + * @throws JSONException + * if the key is not found or if the value is not a Number + * object and cannot be converted to a number. + */ + public double getDouble(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a number."); + } + } + + /** + * Get the int value associated with a key. + * + * @param key + * A key string. + * @return The integer value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to an integer. + */ + public int getInt(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not an int."); + } + } + + /** + * Get the JSONArray value associated with a key. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONArray. + */ + public JSONArray getJSONArray(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONArray) { + return (JSONArray) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONArray."); + } + + /** + * Get the JSONObject value associated with a key. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + * @throws JSONException + * if the key is not found or if the value is not a JSONObject. + */ + public JSONObject getJSONObject(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONObject) { + return (JSONObject) object; + } + throw new JSONException("JSONObject[" + quote(key) + + "] is not a JSONObject."); + } + + /** + * Get the long value associated with a key. + * + * @param key + * A key string. + * @return The long value. + * @throws JSONException + * if the key is not found or if the value cannot be converted + * to a long. + */ + public long getLong(String key) throws JSONException { + Object object = this.get(key); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONObject[" + quote(key) + + "] is not a long."); + } + } + + /** + * Get an array of field names from a JSONObject. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(JSONObject jo) { + int length = jo.length(); + if (length == 0) { + return null; + } + Iterator iterator = jo.keys(); + String[] names = new String[length]; + int i = 0; + while (iterator.hasNext()) { + names[i] = (String) iterator.next(); + i += 1; + } + return names; + } + + /** + * Get an array of field names from an Object. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(Object object) { + if (object == null) { + return null; + } + Class klass = object.getClass(); + Field[] fields = klass.getFields(); + int length = fields.length; + if (length == 0) { + return null; + } + String[] names = new String[length]; + for (int i = 0; i < length; i += 1) { + names[i] = fields[i].getName(); + } + return names; + } + + /** + * Get the string associated with a key. + * + * @param key + * A key string. + * @return A string which is the value. + * @throws JSONException + * if there is no string value for the key. + */ + public String getString(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof String) { + return (String) object; + } + throw new JSONException("JSONObject[" + quote(key) + "] not a string."); + } + + /** + * Determine if the JSONObject contains a specific key. + * + * @param key + * A key string. + * @return true if the key exists in the JSONObject. + */ + public boolean has(String key) { + return this.map.containsKey(key); + } + + /** + * Increment a property of a JSONObject. If there is no such property, + * create one with a value of 1. If there is such a property, and if it is + * an Integer, Long, Double, or Float, then add one to it. + * + * @param key + * A key string. + * @return this. + * @throws JSONException + * If there is already a property with this name that is not an + * Integer, Long, Double, or Float. + */ + public JSONObject increment(String key) throws JSONException { + Object value = this.opt(key); + if (value == null) { + this.put(key, 1); + } else if (value instanceof Integer) { + this.put(key, ((Integer) value).intValue() + 1); + } else if (value instanceof Long) { + this.put(key, ((Long) value).longValue() + 1); + } else if (value instanceof Double) { + this.put(key, ((Double) value).doubleValue() + 1); + } else if (value instanceof Float) { + this.put(key, ((Float) value).floatValue() + 1); + } else { + throw new JSONException("Unable to increment [" + quote(key) + "]."); + } + return this; + } + + /** + * Determine if the value associated with the key is null or if there is no + * value. + * + * @param key + * A key string. + * @return true if there is no value associated with the key or if the value + * is the JSONObject.NULL object. + */ + public boolean isNull(String key) { + return JSONObject.NULL.equals(this.opt(key)); + } + + /** + * Get an enumeration of the keys of the JSONObject. + * + * @return An iterator of the keys. + */ + public Iterator keys() { + return this.keySet().iterator(); + } + + /** + * Get a set of keys of the JSONObject. + * + * @return A keySet. + */ + public Set keySet() { + return this.map.keySet(); + } + + /** + * Get the number of keys stored in the JSONObject. + * + * @return The number of keys in the JSONObject. + */ + public int length() { + return this.map.size(); + } + + /** + * Produce a JSONArray containing the names of the elements of this + * JSONObject. + * + * @return A JSONArray containing the key strings, or null if the JSONObject + * is empty. + */ + public JSONArray names() { + JSONArray ja = new JSONArray(); + Iterator keys = this.keys(); + while (keys.hasNext()) { + ja.put(keys.next()); + } + return ja.length() == 0 ? null : ja; + } + + /** + * Produce a string from a Number. + * + * @param number + * A Number + * @return A String. + * @throws JSONException + * If n is a non-finite number. + */ + public static String numberToString(Number number) throws JSONException { + if (number == null) { + throw new JSONException("Null pointer"); + } + testValidity(number); + +// Shave off trailing zeros and decimal point, if possible. + + String string = number.toString(); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 + && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get an optional value associated with a key. + * + * @param key + * A key string. + * @return An object which is the value, or null if there is no value. + */ + public Object opt(String key) { + return key == null ? null : this.map.get(key); + } + + /** + * Get an optional boolean associated with a key. It returns false if there + * is no such key, or if the value is not Boolean.TRUE or the String "true". + * + * @param key + * A key string. + * @return The truth. + */ + public boolean optBoolean(String key) { + return this.optBoolean(key, false); + } + + /** + * Get an optional boolean associated with a key. It returns the + * defaultValue if there is no such key, or if it is not a Boolean or the + * String "true" or "false" (case insensitive). + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return The truth. + */ + public boolean optBoolean(String key, boolean defaultValue) { + try { + return this.getBoolean(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional double associated with a key, or NaN if there is no such + * key or if its value is not a number. If the value is a string, an attempt + * will be made to evaluate it as a number. + * + * @param key + * A string which is the key. + * @return An object which is the value. + */ + public double optDouble(String key) { + return this.optDouble(key, Double.NaN); + } + + /** + * Get an optional double associated with a key, or the defaultValue if + * there is no such key or if its value is not a number. If the value is a + * string, an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public double optDouble(String key, double defaultValue) { + try { + return this.getDouble(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional int value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public int optInt(String key) { + return this.optInt(key, 0); + } + + /** + * Get an optional int value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public int optInt(String key, int defaultValue) { + try { + return this.getInt(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional JSONArray associated with a key. It returns null if there + * is no such key, or if its value is not a JSONArray. + * + * @param key + * A key string. + * @return A JSONArray which is the value. + */ + public JSONArray optJSONArray(String key) { + Object o = this.opt(key); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + /** + * Get an optional JSONObject associated with a key. It returns null if + * there is no such key, or if its value is not a JSONObject. + * + * @param key + * A key string. + * @return A JSONObject which is the value. + */ + public JSONObject optJSONObject(String key) { + Object object = this.opt(key); + return object instanceof JSONObject ? (JSONObject) object : null; + } + + /** + * Get an optional long value associated with a key, or zero if there is no + * such key or if the value is not a number. If the value is a string, an + * attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @return An object which is the value. + */ + public long optLong(String key) { + return this.optLong(key, 0); + } + + /** + * Get an optional long value associated with a key, or the default if there + * is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public long optLong(String key, long defaultValue) { + try { + return this.getLong(key); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get an optional string associated with a key. It returns an empty string + * if there is no such key. If the value is not a string and is not null, + * then it is converted to a string. + * + * @param key + * A key string. + * @return A string which is the value. + */ + public String optString(String key) { + return this.optString(key, ""); + } + + /** + * Get an optional string associated with a key. It returns the defaultValue + * if there is no such key. + * + * @param key + * A key string. + * @param defaultValue + * The default. + * @return A string which is the value. + */ + public String optString(String key, String defaultValue) { + Object object = this.opt(key); + return NULL.equals(object) ? defaultValue : object.toString(); + } + + private void populateMap(Object bean) { + Class klass = bean.getClass(); + +// If klass is a System class then set includeSuperClass to false. + + boolean includeSuperClass = klass.getClassLoader() != null; + + Method[] methods = includeSuperClass ? klass.getMethods() : klass + .getDeclaredMethods(); + for (int i = 0; i < methods.length; i += 1) { + try { + Method method = methods[i]; + if (Modifier.isPublic(method.getModifiers())) { + String name = method.getName(); + String key = ""; + if (name.startsWith("get")) { + if ("getClass".equals(name) + || "getDeclaringClass".equals(name)) { + key = ""; + } else { + key = name.substring(3); + } + } else if (name.startsWith("is")) { + key = name.substring(2); + } + if (key.length() > 0 + && Character.isUpperCase(key.charAt(0)) + && method.getParameterTypes().length == 0) { + if (key.length() == 1) { + key = key.toLowerCase(); + } else if (!Character.isUpperCase(key.charAt(1))) { + key = key.substring(0, 1).toLowerCase() + + key.substring(1); + } + + Object result = method.invoke(bean, (Object[]) null); + if (result != null) { + this.map.put(key, wrap(result)); + } + } + } + } catch (Exception ignore) { + } + } + } + + /** + * Put a key/boolean pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A boolean which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, boolean value) throws JSONException { + this.put(key, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONArray which is produced from a Collection. + * + * @param key + * A key string. + * @param value + * A Collection value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Collection value) throws JSONException { + this.put(key, new JSONArray(value)); + return this; + } + + /** + * Put a key/double pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A double which is the value. + * @return this. + * @throws JSONException + * If the key is null or if the number is invalid. + */ + public JSONObject put(String key, double value) throws JSONException { + this.put(key, new Double(value)); + return this; + } + + /** + * Put a key/int pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * An int which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, int value) throws JSONException { + this.put(key, new Integer(value)); + return this; + } + + /** + * Put a key/long pair in the JSONObject. + * + * @param key + * A key string. + * @param value + * A long which is the value. + * @return this. + * @throws JSONException + * If the key is null. + */ + public JSONObject put(String key, long value) throws JSONException { + this.put(key, new Long(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONObject which is produced from a Map. + * + * @param key + * A key string. + * @param value + * A Map value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Map value) throws JSONException { + this.put(key, new JSONObject(value)); + return this; + } + + /** + * Put a key/value pair in the JSONObject. If the value is null, then the + * key will be removed from the JSONObject if it is present. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is non-finite number or if the key is null. + */ + public JSONObject put(String key, Object value) throws JSONException { + String pooled; + if (key == null) { + throw new NullPointerException("Null key."); + } + if (value != null) { + testValidity(value); + pooled = (String) keyPool.get(key); + if (pooled == null) { + if (keyPool.size() >= keyPoolSize) { + keyPool = new HashMap(keyPoolSize); + } + keyPool.put(key, key); + } else { + key = pooled; + } + this.map.put(key, value); + } else { + this.remove(key); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null, and only if there is not already a member with that + * name. + * + * @param key + * @param value + * @return his. + * @throws JSONException + * if the key is a duplicate + */ + public JSONObject putOnce(String key, Object value) throws JSONException { + if (key != null && value != null) { + if (this.opt(key) != null) { + throw new JSONException("Duplicate key \"" + key + "\""); + } + this.put(key, value); + } + return this; + } + + /** + * Put a key/value pair in the JSONObject, but only if the key and the value + * are both non-null. + * + * @param key + * A key string. + * @param value + * An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, + * String, or the JSONObject.NULL object. + * @return this. + * @throws JSONException + * If the value is a non-finite number. + */ + public JSONObject putOpt(String key, Object value) throws JSONException { + if (key != null && value != null) { + this.put(key, value); + } + return this; + } + + /** + * Produce a string in double quotes with backslash sequences in all the + * right places. A backslash will be inserted within = '\u0080' && c < '\u00a0') + || (c >= '\u2000' && c < '\u2100')) { + w.write("\\u"); + hhhh = Integer.toHexString(c); + w.write("0000", 0, 4 - hhhh.length()); + w.write(hhhh); + } else { + w.write(c); + } + } + } + w.write('"'); + return w; + } + + /** + * Remove a name and its value, if present. + * + * @param key + * The name to be removed. + * @return The value that was associated with the name, or null if there was + * no value. + */ + public Object remove(String key) { + return this.map.remove(key); + } + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. + * + * @param string + * A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + Double d; + if (string.equals("")) { + return string; + } + if (string.equalsIgnoreCase("true")) { + return Boolean.TRUE; + } + if (string.equalsIgnoreCase("false")) { + return Boolean.FALSE; + } + if (string.equalsIgnoreCase("null")) { + return JSONObject.NULL; + } + + /* + * If it might be a number, try converting it. If a number cannot be + * produced, then the value will just be a string. + */ + + char b = string.charAt(0); + if ((b >= '0' && b <= '9') || b == '-') { + try { + if (string.indexOf('.') > -1 || string.indexOf('e') > -1 + || string.indexOf('E') > -1) { + d = Double.valueOf(string); + if (!d.isInfinite() && !d.isNaN()) { + return d; + } + } else { + Long myLong = new Long(string); + if (string.equals(myLong.toString())) { + if (myLong.longValue() == myLong.intValue()) { + return new Integer(myLong.intValue()); + } else { + return myLong; + } + } + } + } catch (Exception ignore) { + } + } + return string; + } + + /** + * Throw an exception if the object is a NaN or infinite number. + * + * @param o + * The object to test. + * @throws JSONException + * If o is a non-finite number. + */ + public static void testValidity(Object o) throws JSONException { + if (o != null) { + if (o instanceof Double) { + if (((Double) o).isInfinite() || ((Double) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } else if (o instanceof Float) { + if (((Float) o).isInfinite() || ((Float) o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } + } + } + + /** + * Produce a JSONArray containing the values of the members of this + * JSONObject. + * + * @param names + * A JSONArray containing a list of key strings. This determines + * the sequence of the values in the result. + * @return A JSONArray of values. + * @throws JSONException + * If any of the values are non-finite numbers. + */ + public JSONArray toJSONArray(JSONArray names) throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + JSONArray ja = new JSONArray(); + for (int i = 0; i < names.length(); i += 1) { + ja.put(this.opt(names.getString(i))); + } + return ja; + } + + /** + * Make a JSON text of this JSONObject. For compactness, no whitespace is + * added. If this would not result in a syntactically correct JSON text, + * then null will be returned instead. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + /** + * Make a prettyprinted JSON text of this JSONObject. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return a printable, displayable, portable, transmittable representation + * of the object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the object contains an invalid number. + */ + public String toString(int indentFactor) throws JSONException { + StringWriter w = new StringWriter(); + synchronized (w.getBuffer()) { + return this.write(w, indentFactor, 0).toString(); + } + } + + /** + * Make a JSON text of an Object value. If the object has an + * value.toJSONString() method, then that method will be used to produce the + * JSON text. The method is required to produce a strictly conforming text. + * If the object does not contain a toJSONString method (which is the most + * common case), then a text will be produced by other means. If the value + * is an array or Collection, then a JSONArray will be made from it and its + * toJSONString method will be called. If the value is a MAP, then a + * JSONObject will be made from it and its toJSONString method will be + * called. Otherwise, the value's toString method will be called, and the + * result will be quoted. + * + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @param value + * The value to be serialized. + * @return a printable, displayable, transmittable representation of the + * object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException + * If the value is or contains an invalid number. + */ + public static String valueToString(Object value) throws JSONException { + if (value == null || value.equals(null)) { + return "null"; + } + if (value instanceof JSONString) { + Object object; + try { + object = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + if (object instanceof String) { + return (String) object; + } + throw new JSONException("Bad value from toJSONString: " + object); + } + if (value instanceof Number) { + return numberToString((Number) value); + } + if (value instanceof Boolean || value instanceof JSONObject + || value instanceof JSONArray) { + return value.toString(); + } + if (value instanceof Map) { + return new JSONObject((Map) value).toString(); + } + if (value instanceof Collection) { + return new JSONArray((Collection) value).toString(); + } + if (value.getClass().isArray()) { + return new JSONArray(value).toString(); + } + return quote(value.toString()); + } + + /** + * Wrap an object, if necessary. If the object is null, return the NULL + * object. If it is an array or collection, wrap it in a JSONArray. If it is + * a map, wrap it in a JSONObject. If it is a standard property (Double, + * String, et al) then it is already wrapped. Otherwise, if it comes from + * one of the java packages, turn it into a string. And if it doesn't, try + * to wrap it in a JSONObject. If the wrapping fails, then null is returned. + * + * @param object + * The object to wrap + * @return The wrapped value + */ + public static Object wrap(Object object) { + try { + if (object == null) { + return NULL; + } + if (object instanceof JSONObject || object instanceof JSONArray + || NULL.equals(object) || object instanceof JSONString + || object instanceof Byte || object instanceof Character + || object instanceof Short || object instanceof Integer + || object instanceof Long || object instanceof Boolean + || object instanceof Float || object instanceof Double + || object instanceof String) { + return object; + } + + if (object instanceof Collection) { + return new JSONArray((Collection) object); + } + if (object.getClass().isArray()) { + return new JSONArray(object); + } + if (object instanceof Map) { + return new JSONObject((Map) object); + } + Package objectPackage = object.getClass().getPackage(); + String objectPackageName = objectPackage != null ? objectPackage + .getName() : ""; + if (objectPackageName.startsWith("java.") + || objectPackageName.startsWith("javax.") + || object.getClass().getClassLoader() == null) { + return object.toString(); + } + return new JSONObject(object); + } catch (Exception exception) { + return null; + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + static final Writer writeValue(Writer writer, Object value, + int indentFactor, int indent) throws JSONException, IOException { + if (value == null || value.equals(null)) { + writer.write("null"); + } else if (value instanceof JSONObject) { + ((JSONObject) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONArray) { + ((JSONArray) value).write(writer, indentFactor, indent); + } else if (value instanceof Map) { + new JSONObject((Map) value).write(writer, indentFactor, indent); + } else if (value instanceof Collection) { + new JSONArray((Collection) value).write(writer, indentFactor, + indent); + } else if (value.getClass().isArray()) { + new JSONArray(value).write(writer, indentFactor, indent); + } else if (value instanceof Number) { + writer.write(numberToString((Number) value)); + } else if (value instanceof Boolean) { + writer.write(value.toString()); + } else if (value instanceof JSONString) { + Object o; + try { + o = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + writer.write(o != null ? o.toString() : quote(value.toString())); + } else { + quote(value.toString(), writer); + } + return writer; + } + + static final void indent(Writer writer, int indent) throws IOException { + for (int i = 0; i < indent; i += 1) { + writer.write(' '); + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + final int length = this.length(); + Iterator keys = this.keys(); + writer.write('{'); + + if (length == 1) { + Object key = keys.next(); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + while (keys.hasNext()) { + Object key = keys.next(); + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, newindent); + writer.write(quote(key.toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, this.map.get(key), indentFactor, + newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, indent); + } + writer.write('}'); + return writer; + } catch (IOException exception) { + throw new JSONException(exception); + } + } +} diff --git a/eurilys4/src/java/jsonlib/JSONString.java b/eurilys4/src/java/jsonlib/JSONString.java new file mode 100644 index 00000000..1f2d77dd --- /dev/null +++ b/eurilys4/src/java/jsonlib/JSONString.java @@ -0,0 +1,18 @@ +package org.json; +/** + * The JSONString interface allows a toJSONString() + * method so that a class can change the behavior of + * JSONObject.toString(), JSONArray.toString(), + * and JSONWriter.value(Object). The + * toJSONString method will be used instead of the default behavior + * of using the Object's toString() method and quoting the result. + */ +public interface JSONString { + /** + * The toJSONString method allows a class to produce its own JSON + * serialization. + * + * @return A strictly syntactically correct JSON text. + */ + public String toJSONString(); +} diff --git a/eurilys4/src/java/jsonlib/JSONStringer.java b/eurilys4/src/java/jsonlib/JSONStringer.java new file mode 100644 index 00000000..32c9f7f4 --- /dev/null +++ b/eurilys4/src/java/jsonlib/JSONStringer.java @@ -0,0 +1,78 @@ +package org.json; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.io.StringWriter; + +/** + * JSONStringer provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONStringer can produce one JSON text. + *

    + * A JSONStringer instance provides a value method for appending + * values to the + * text, and a key + * method for adding keys before values in objects. There are array + * and endArray methods that make and bound array values, and + * object and endObject methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting cascade style. For example,

    + * myString = new JSONStringer()
    + *     .object()
    + *         .key("JSON")
    + *         .value("Hello, World!")
    + *     .endObject()
    + *     .toString();
    which produces the string
    + * {"JSON":"Hello, World!"}
    + *

    + * The first method called must be array or object. + * There are no methods for adding commas or colons. JSONStringer adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + *

    + * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2008-09-18 + */ +public class JSONStringer extends JSONWriter { + /** + * Make a fresh JSONStringer. It can be used to build one JSON text. + */ + public JSONStringer() { + super(new StringWriter()); + } + + /** + * Return the JSON text. This method is used to obtain the product of the + * JSONStringer instance. It will return null if there was a + * problem in the construction of the JSON text (such as the calls to + * array were not properly balanced with calls to + * endArray). + * @return The JSON text. + */ + public String toString() { + return this.mode == 'd' ? this.writer.toString() : null; + } +} diff --git a/eurilys4/src/java/jsonlib/JSONTokener.java b/eurilys4/src/java/jsonlib/JSONTokener.java new file mode 100644 index 00000000..13c84f1f --- /dev/null +++ b/eurilys4/src/java/jsonlib/JSONTokener.java @@ -0,0 +1,446 @@ +package org.json; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * A JSONTokener takes a source string and extracts characters and tokens from + * it. It is used by the JSONObject and JSONArray constructors to parse + * JSON source strings. + * @author JSON.org + * @version 2012-02-16 + */ +public class JSONTokener { + + private long character; + private boolean eof; + private long index; + private long line; + private char previous; + private Reader reader; + private boolean usePrevious; + + + /** + * Construct a JSONTokener from a Reader. + * + * @param reader A reader. + */ + public JSONTokener(Reader reader) { + this.reader = reader.markSupported() + ? reader + : new BufferedReader(reader); + this.eof = false; + this.usePrevious = false; + this.previous = 0; + this.index = 0; + this.character = 1; + this.line = 1; + } + + + /** + * Construct a JSONTokener from an InputStream. + */ + public JSONTokener(InputStream inputStream) throws JSONException { + this(new InputStreamReader(inputStream)); + } + + + /** + * Construct a JSONTokener from a string. + * + * @param s A source string. + */ + public JSONTokener(String s) { + this(new StringReader(s)); + } + + + /** + * Back up one character. This provides a sort of lookahead capability, + * so that you can test for a digit or letter before attempting to parse + * the next number or identifier. + */ + public void back() throws JSONException { + if (this.usePrevious || this.index <= 0) { + throw new JSONException("Stepping back two steps is not supported"); + } + this.index -= 1; + this.character -= 1; + this.usePrevious = true; + this.eof = false; + } + + + /** + * Get the hex value of a character (base16). + * @param c A character between '0' and '9' or between 'A' and 'F' or + * between 'a' and 'f'. + * @return An int between 0 and 15, or -1 if c was not a hex digit. + */ + public static int dehexchar(char c) { + if (c >= '0' && c <= '9') { + return c - '0'; + } + if (c >= 'A' && c <= 'F') { + return c - ('A' - 10); + } + if (c >= 'a' && c <= 'f') { + return c - ('a' - 10); + } + return -1; + } + + public boolean end() { + return this.eof && !this.usePrevious; + } + + + /** + * Determine if the source string still contains characters that next() + * can consume. + * @return true if not yet at the end of the source. + */ + public boolean more() throws JSONException { + this.next(); + if (this.end()) { + return false; + } + this.back(); + return true; + } + + + /** + * Get the next character in the source string. + * + * @return The next character, or 0 if past the end of the source string. + */ + public char next() throws JSONException { + int c; + if (this.usePrevious) { + this.usePrevious = false; + c = this.previous; + } else { + try { + c = this.reader.read(); + } catch (IOException exception) { + throw new JSONException(exception); + } + + if (c <= 0) { // End of stream + this.eof = true; + c = 0; + } + } + this.index += 1; + if (this.previous == '\r') { + this.line += 1; + this.character = c == '\n' ? 0 : 1; + } else if (c == '\n') { + this.line += 1; + this.character = 0; + } else { + this.character += 1; + } + this.previous = (char) c; + return this.previous; + } + + + /** + * Consume the next character, and check that it matches a specified + * character. + * @param c The character to match. + * @return The character. + * @throws JSONException if the character does not match. + */ + public char next(char c) throws JSONException { + char n = this.next(); + if (n != c) { + throw this.syntaxError("Expected '" + c + "' and instead saw '" + + n + "'"); + } + return n; + } + + + /** + * Get the next n characters. + * + * @param n The number of characters to take. + * @return A string of n characters. + * @throws JSONException + * Substring bounds error if there are not + * n characters remaining in the source string. + */ + public String next(int n) throws JSONException { + if (n == 0) { + return ""; + } + + char[] chars = new char[n]; + int pos = 0; + + while (pos < n) { + chars[pos] = this.next(); + if (this.end()) { + throw this.syntaxError("Substring bounds error"); + } + pos += 1; + } + return new String(chars); + } + + + /** + * Get the next char in the string, skipping whitespace. + * @throws JSONException + * @return A character, or 0 if there are no more characters. + */ + public char nextClean() throws JSONException { + for (;;) { + char c = this.next(); + if (c == 0 || c > ' ') { + return c; + } + } + } + + + /** + * Return the characters up to the next close quote character. + * Backslash processing is done. The formal JSON format does not + * allow strings in single quotes, but an implementation is allowed to + * accept them. + * @param quote The quoting character, either + * " (double quote) or + * ' (single quote). + * @return A String. + * @throws JSONException Unterminated string. + */ + public String nextString(char quote) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + switch (c) { + case 0: + case '\n': + case '\r': + throw this.syntaxError("Unterminated string"); + case '\\': + c = this.next(); + switch (c) { + case 'b': + sb.append('\b'); + break; + case 't': + sb.append('\t'); + break; + case 'n': + sb.append('\n'); + break; + case 'f': + sb.append('\f'); + break; + case 'r': + sb.append('\r'); + break; + case 'u': + sb.append((char)Integer.parseInt(this.next(4), 16)); + break; + case '"': + case '\'': + case '\\': + case '/': + sb.append(c); + break; + default: + throw this.syntaxError("Illegal escape."); + } + break; + default: + if (c == quote) { + return sb.toString(); + } + sb.append(c); + } + } + } + + + /** + * Get the text up but not including the specified character or the + * end of line, whichever comes first. + * @param delimiter A delimiter character. + * @return A string. + */ + public String nextTo(char delimiter) throws JSONException { + StringBuffer sb = new StringBuffer(); + for (;;) { + char c = this.next(); + if (c == delimiter || c == 0 || c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the text up but not including one of the specified delimiter + * characters or the end of line, whichever comes first. + * @param delimiters A set of delimiter characters. + * @return A string, trimmed. + */ + public String nextTo(String delimiters) throws JSONException { + char c; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = this.next(); + if (delimiters.indexOf(c) >= 0 || c == 0 || + c == '\n' || c == '\r') { + if (c != 0) { + this.back(); + } + return sb.toString().trim(); + } + sb.append(c); + } + } + + + /** + * Get the next value. The value can be a Boolean, Double, Integer, + * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. + * @throws JSONException If syntax error. + * + * @return An object. + */ + public Object nextValue() throws JSONException { + char c = this.nextClean(); + String string; + + switch (c) { + case '"': + case '\'': + return this.nextString(c); + case '{': + this.back(); + return new JSONObject(this); + case '[': + this.back(); + return new JSONArray(this); + } + + /* + * Handle unquoted text. This could be the values true, false, or + * null, or it can be a number. An implementation (such as this one) + * is allowed to also accept non-standard forms. + * + * Accumulate characters until we reach the end of the text or a + * formatting character. + */ + + StringBuffer sb = new StringBuffer(); + while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { + sb.append(c); + c = this.next(); + } + this.back(); + + string = sb.toString().trim(); + if ("".equals(string)) { + throw this.syntaxError("Missing value"); + } + return JSONObject.stringToValue(string); + } + + + /** + * Skip characters until the next character is the requested character. + * If the requested character is not found, no characters are skipped. + * @param to A character to skip to. + * @return The requested character, or zero if the requested character + * is not found. + */ + public char skipTo(char to) throws JSONException { + char c; + try { + long startIndex = this.index; + long startCharacter = this.character; + long startLine = this.line; + this.reader.mark(1000000); + do { + c = this.next(); + if (c == 0) { + this.reader.reset(); + this.index = startIndex; + this.character = startCharacter; + this.line = startLine; + return c; + } + } while (c != to); + } catch (IOException exc) { + throw new JSONException(exc); + } + + this.back(); + return c; + } + + + /** + * Make a JSONException to signal a syntax error. + * + * @param message The error message. + * @return A JSONException object, suitable for throwing + */ + public JSONException syntaxError(String message) { + return new JSONException(message + this.toString()); + } + + + /** + * Make a printable string of this JSONTokener. + * + * @return " at {index} [character {character} line {line}]" + */ + public String toString() { + return " at " + this.index + " [character " + this.character + " line " + + this.line + "]"; + } +} diff --git a/eurilys4/src/java/jsonlib/JSONWriter.java b/eurilys4/src/java/jsonlib/JSONWriter.java new file mode 100644 index 00000000..35b60d90 --- /dev/null +++ b/eurilys4/src/java/jsonlib/JSONWriter.java @@ -0,0 +1,327 @@ +package org.json; + +import java.io.IOException; +import java.io.Writer; + +/* +Copyright (c) 2006 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * JSONWriter provides a quick and convenient way of producing JSON text. + * The texts produced strictly conform to JSON syntax rules. No whitespace is + * added, so the results are ready for transmission or storage. Each instance of + * JSONWriter can produce one JSON text. + *

    + * A JSONWriter instance provides a value method for appending + * values to the + * text, and a key + * method for adding keys before values in objects. There are array + * and endArray methods that make and bound array values, and + * object and endObject methods which make and bound + * object values. All of these methods return the JSONWriter instance, + * permitting a cascade style. For example,

    + * new JSONWriter(myWriter)
    + *     .object()
    + *         .key("JSON")
    + *         .value("Hello, World!")
    + *     .endObject();
    which writes
    + * {"JSON":"Hello, World!"}
    + *

    + * The first method called must be array or object. + * There are no methods for adding commas or colons. JSONWriter adds them for + * you. Objects and arrays can be nested up to 20 levels deep. + *

    + * This can sometimes be easier than using a JSONObject to build a string. + * @author JSON.org + * @version 2011-11-24 + */ +public class JSONWriter { + private static final int maxdepth = 200; + + /** + * The comma flag determines if a comma should be output before the next + * value. + */ + private boolean comma; + + /** + * The current mode. Values: + * 'a' (array), + * 'd' (done), + * 'i' (initial), + * 'k' (key), + * 'o' (object). + */ + protected char mode; + + /** + * The object/array stack. + */ + private final JSONObject stack[]; + + /** + * The stack top index. A value of 0 indicates that the stack is empty. + */ + private int top; + + /** + * The writer that will receive the output. + */ + protected Writer writer; + + /** + * Make a fresh JSONWriter. It can be used to build one JSON text. + */ + public JSONWriter(Writer w) { + this.comma = false; + this.mode = 'i'; + this.stack = new JSONObject[maxdepth]; + this.top = 0; + this.writer = w; + } + + /** + * Append a value. + * @param string A string value. + * @return this + * @throws JSONException If the value is out of sequence. + */ + private JSONWriter append(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null pointer"); + } + if (this.mode == 'o' || this.mode == 'a') { + try { + if (this.comma && this.mode == 'a') { + this.writer.write(','); + } + this.writer.write(string); + } catch (IOException e) { + throw new JSONException(e); + } + if (this.mode == 'o') { + this.mode = 'k'; + } + this.comma = true; + return this; + } + throw new JSONException("Value out of sequence."); + } + + /** + * Begin appending a new array. All values until the balancing + * endArray will be appended to this array. The + * endArray method must be called to mark the array's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter array() throws JSONException { + if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { + this.push(null); + this.append("["); + this.comma = false; + return this; + } + throw new JSONException("Misplaced array."); + } + + /** + * End something. + * @param mode Mode + * @param c Closing character + * @return this + * @throws JSONException If unbalanced. + */ + private JSONWriter end(char mode, char c) throws JSONException { + if (this.mode != mode) { + throw new JSONException(mode == 'a' + ? "Misplaced endArray." + : "Misplaced endObject."); + } + this.pop(mode); + try { + this.writer.write(c); + } catch (IOException e) { + throw new JSONException(e); + } + this.comma = true; + return this; + } + + /** + * End an array. This method most be called to balance calls to + * array. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endArray() throws JSONException { + return this.end('a', ']'); + } + + /** + * End an object. This method most be called to balance calls to + * object. + * @return this + * @throws JSONException If incorrectly nested. + */ + public JSONWriter endObject() throws JSONException { + return this.end('k', '}'); + } + + /** + * Append a key. The key will be associated with the next value. In an + * object, every value must be preceded by a key. + * @param string A key string. + * @return this + * @throws JSONException If the key is out of place. For example, keys + * do not belong in arrays or if the key is null. + */ + public JSONWriter key(String string) throws JSONException { + if (string == null) { + throw new JSONException("Null key."); + } + if (this.mode == 'k') { + try { + this.stack[this.top - 1].putOnce(string, Boolean.TRUE); + if (this.comma) { + this.writer.write(','); + } + this.writer.write(JSONObject.quote(string)); + this.writer.write(':'); + this.comma = false; + this.mode = 'o'; + return this; + } catch (IOException e) { + throw new JSONException(e); + } + } + throw new JSONException("Misplaced key."); + } + + + /** + * Begin appending a new object. All keys and values until the balancing + * endObject will be appended to this object. The + * endObject method must be called to mark the object's end. + * @return this + * @throws JSONException If the nesting is too deep, or if the object is + * started in the wrong place (for example as a key or after the end of the + * outermost array or object). + */ + public JSONWriter object() throws JSONException { + if (this.mode == 'i') { + this.mode = 'o'; + } + if (this.mode == 'o' || this.mode == 'a') { + this.append("{"); + this.push(new JSONObject()); + this.comma = false; + return this; + } + throw new JSONException("Misplaced object."); + + } + + + /** + * Pop an array or object scope. + * @param c The scope to close. + * @throws JSONException If nesting is wrong. + */ + private void pop(char c) throws JSONException { + if (this.top <= 0) { + throw new JSONException("Nesting error."); + } + char m = this.stack[this.top - 1] == null ? 'a' : 'k'; + if (m != c) { + throw new JSONException("Nesting error."); + } + this.top -= 1; + this.mode = this.top == 0 + ? 'd' + : this.stack[this.top - 1] == null + ? 'a' + : 'k'; + } + + /** + * Push an array or object scope. + * @param c The scope to open. + * @throws JSONException If nesting is too deep. + */ + private void push(JSONObject jo) throws JSONException { + if (this.top >= maxdepth) { + throw new JSONException("Nesting too deep."); + } + this.stack[this.top] = jo; + this.mode = jo == null ? 'a' : 'k'; + this.top += 1; + } + + + /** + * Append either the value true or the value + * false. + * @param b A boolean. + * @return this + * @throws JSONException + */ + public JSONWriter value(boolean b) throws JSONException { + return this.append(b ? "true" : "false"); + } + + /** + * Append a double value. + * @param d A double. + * @return this + * @throws JSONException If the number is not finite. + */ + public JSONWriter value(double d) throws JSONException { + return this.value(new Double(d)); + } + + /** + * Append a long value. + * @param l A long. + * @return this + * @throws JSONException + */ + public JSONWriter value(long l) throws JSONException { + return this.append(Long.toString(l)); + } + + + /** + * Append an object value. + * @param object The object to append. It can be null, or a Boolean, Number, + * String, JSONObject, or JSONArray, or an object that implements JSONString. + * @return this + * @throws JSONException If the value is out of sequence. + */ + public JSONWriter value(Object object) throws JSONException { + return this.append(JSONObject.valueToString(object)); + } +} diff --git a/eurilys4/src/java/jsonlib/Kim.java b/eurilys4/src/java/jsonlib/Kim.java new file mode 100644 index 00000000..d4770b56 --- /dev/null +++ b/eurilys4/src/java/jsonlib/Kim.java @@ -0,0 +1,373 @@ +package org.json; + + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * Kim makes immutable eight bit Unicode strings. If the MSB of a byte is set, + * then the next byte is a continuation byte. The last byte of a character + * never has the MSB reset. Every byte that is not the last byte has the MSB + * set. Kim stands for "Keep it minimal". A Unicode character is never longer + * than 3 bytes. Every byte contributes 7 bits to the character. ASCII is + * unmodified. + * + * Kim UTF-8 + * one byte U+007F U+007F + * two bytes U+3FFF U+07FF + * three bytes U+10FFF U+FFFF + * four bytes U+10FFFF + * + * Characters in the ranges U+0800..U+3FFF and U+10000..U+10FFFF will be one + * byte smaller when encoded in Kim compared to UTF-8. + * + * Kim is beneficial when using scripts such as Old South Arabian, Aramaic, + * Avestan, Balinese, Batak, Bopomofo, Buginese, Buhid, Carian, Cherokee, + * Coptic, Cyrillic, Deseret, Egyptian Hieroglyphs, Ethiopic, Georgian, + * Glagolitic, Gothic, Hangul Jamo, Hanunoo, Hiragana, Kanbun, Kaithi, + * Kannada, Katakana, Kharoshthi, Khmer, Lao, Lepcha, Limbu, Lycian, Lydian, + * Malayalam, Mandaic, Meroitic, Miao, Mongolian, Myanmar, New Tai Lue, + * Ol Chiki, Old Turkic, Oriya, Osmanya, Pahlavi, Parthian, Phags-Pa, + * Phoenician, Samaritan, Sharada, Sinhala, Sora Sompeng, Tagalog, Tagbanwa, + * Takri, Tai Le, Tai Tham, Tamil, Telugu, Thai, Tibetan, Tifinagh, UCAS. + * + * A kim object can be constructed from an ordinary UTF-16 string, or from a + * byte array. A kim object can produce a UTF-16 string. + * + * As with UTF-8, it is possible to detect character boundaries within a byte + * sequence. UTF-8 is one of the world's great inventions. While Kim is more + * efficient, it is not clear that it is worth the expense of transition. + * + * @version 2013-04-18 + */ +public class Kim { + + /** + * The byte array containing the kim's content. + */ + private byte[] bytes = null; + + /** + * The kim's hashcode, conforming to Java's hashcode conventions. + */ + private int hashcode = 0; + + /** + * The number of bytes in the kim. The number of bytes can be as much as + * three times the number of characters. + */ + public int length = 0; + + /** + * The memoization of toString(). + */ + private String string = null; + + /** + * Make a kim from a portion of a byte array. + * + * @param bytes + * A byte array. + * @param from + * The index of the first byte. + * @param thru + * The index of the last byte plus one. + */ + public Kim(byte[] bytes, int from, int thru) { + +// As the bytes are copied into the new kim, a hashcode is computed using a +// modified Fletcher code. + + int sum = 1; + int value; + this.hashcode = 0; + this.length = thru - from; + if (this.length > 0) { + this.bytes = new byte[this.length]; + for (int at = 0; at < this.length; at += 1) { + value = (int) bytes[at + from] & 0xFF; + sum += value; + this.hashcode += sum; + this.bytes[at] = (byte) value; + } + this.hashcode += sum << 16; + } + } + + /** + * Make a kim from a byte array. + * + * @param bytes + * The byte array. + * @param length + * The number of bytes. + */ + public Kim(byte[] bytes, int length) { + this(bytes, 0, length); + } + + /** + * Make a new kim from a substring of an existing kim. The coordinates are + * in byte units, not character units. + * + * @param kim + * The source of bytes. + * @param from + * The point at which to take bytes. + * @param thru + * The point at which to stop taking bytes. + * @return the substring + */ + public Kim(Kim kim, int from, int thru) { + this(kim.bytes, from, thru); + } + + /** + * Make a kim from a string. + * + * @param string + * The string. + * @throws JSONException + * if surrogate pair mismatch. + */ + public Kim(String string) throws JSONException { + int stringLength = string.length(); + this.hashcode = 0; + this.length = 0; + +// First pass: Determine the length of the kim, allowing for the UTF-16 +// to UTF-32 conversion, and then the UTF-32 to Kim conversion. + + if (stringLength > 0) { + for (int i = 0; i < stringLength; i += 1) { + int c = string.charAt(i); + if (c <= 0x7F) { + this.length += 1; + } else if (c <= 0x3FFF) { + this.length += 2; + } else { + if (c >= 0xD800 && c <= 0xDFFF) { + i += 1; + int d = string.charAt(i); + if (c > 0xDBFF || d < 0xDC00 || d > 0xDFFF) { + throw new JSONException("Bad UTF16"); + } + } + this.length += 3; + } + } + +// Second pass: Allocate a byte array and fill that array with the conversion +// while computing the hashcode. + + this.bytes = new byte[length]; + int at = 0; + int b; + int sum = 1; + for (int i = 0; i < stringLength; i += 1) { + int character = string.charAt(i); + if (character <= 0x7F) { + bytes[at] = (byte) character; + sum += character; + this.hashcode += sum; + at += 1; + } else if (character <= 0x3FFF) { + b = 0x80 | (character >>> 7); + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + b = character & 0x7F; + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + } else { + if (character >= 0xD800 && character <= 0xDBFF) { + i += 1; + character = (((character & 0x3FF) << 10) | (string + .charAt(i) & 0x3FF)) + 65536; + } + b = 0x80 | (character >>> 14); + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + b = 0x80 | ((character >>> 7) & 0xFF); + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + b = character & 0x7F; + bytes[at] = (byte) b; + sum += b; + this.hashcode += sum; + at += 1; + } + } + this.hashcode += sum << 16; + } + } + + /** + * Returns the character at the specified index. The index refers to byte + * values and ranges from 0 to length - 1. The index of the next character + * is at index + Kim.characterSize(kim.characterAt(index)). + * + * @param at + * the index of the char value. The first character is at 0. + * @returns a Unicode character between 0 and 0x10FFFF. + * @throws JSONException + * if at does not point to a valid character. + */ + public int characterAt(int at) throws JSONException { + int c = get(at); + if ((c & 0x80) == 0) { + return c; + } + int character; + int c1 = get(at + 1); + if ((c1 & 0x80) == 0) { + character = ((c & 0x7F) << 7) | c1; + if (character > 0x7F) { + return character; + } + } else { + int c2 = get(at + 2); + character = ((c & 0x7F) << 14) | ((c1 & 0x7F) << 7) | c2; + if ((c2 & 0x80) == 0 && character > 0x3FFF && character <= 0x10FFFF + && (character < 0xD800 || character > 0xDFFF)) { + return character; + } + } + throw new JSONException("Bad character at " + at); + } + + /** + * Returns the number of bytes needed to contain the character in Kim + * format. + * + * @param character + * a Unicode character between 0 and 0x10FFFF. + * @return 1, 2, or 3 + * @throws JSONException + * if the character is not representable in a kim. + */ + public static int characterSize(int character) throws JSONException { + if (character < 0 || character > 0x10FFFF) { + throw new JSONException("Bad character " + character); + } + return character <= 0x7F ? 1 : character <= 0x3FFF ? 2 : 3; + } + + /** + * Copy the contents of this kim to a byte array. + * + * @param bytes + * A byte array of sufficient size. + * @param at + * The position within the byte array to take the byes. + * @return The position immediately after the copy. + */ + public int copy(byte[] bytes, int at) { + System.arraycopy(this.bytes, 0, bytes, at, this.length); + return at + this.length; + } + + /** + * Two kim objects containing exactly the same bytes in the same order are + * equal to each other. + * + * @param obj + * the other kim with which to compare. + * @returns true if this and obj are both kim objects containing identical + * byte sequences. + */ + public boolean equals(Object obj) { + if (!(obj instanceof Kim)) { + return false; + } + Kim that = (Kim) obj; + if (this == that) { + return true; + } + if (this.hashcode != that.hashcode) { + return false; + } + return java.util.Arrays.equals(this.bytes, that.bytes); + } + + /** + * Get a byte from a kim. + * @param at + * The position of the byte. The first byte is at 0. + * @return The byte. + * @throws JSONException + * if there is no byte at that position. + */ + public int get(int at) throws JSONException { + if (at < 0 || at > this.length) { + throw new JSONException("Bad character at " + at); + } + return ((int) this.bytes[at]) & 0xFF; + } + + /** + * Returns a hash code value for the kim. + */ + public int hashCode() { + return this.hashcode; + } + + /** + * Produce a UTF-16 String from this kim. The number of codepoints in the + * string will not be greater than the number of bytes in the kim, although + * it could be less. + * + * @return The string. A kim memoizes its string representation. + * @throws JSONException + * if the kim is not valid. + */ + public String toString() throws JSONException { + if (this.string == null) { + int c; + int length = 0; + char chars[] = new char[this.length]; + for (int at = 0; at < this.length; at += characterSize(c)) { + c = this.characterAt(at); + if (c < 0x10000) { + chars[length] = (char) c; + length += 1; + } else { + chars[length] = (char) (0xD800 | ((c - 0x10000) >>> 10)); + length += 1; + chars[length] = (char) (0xDC00 | (c & 0x03FF)); + length += 1; + } + } + this.string = new String(chars, 0, length); + } + return this.string; + } +} diff --git a/eurilys4/src/java/jsonlib/README b/eurilys4/src/java/jsonlib/README new file mode 100644 index 00000000..b77c71a2 --- /dev/null +++ b/eurilys4/src/java/jsonlib/README @@ -0,0 +1,68 @@ +JSON in Java [package org.json] + +Douglas Crockford +douglas@crockford.com + +2011-02-02 + + +JSON is a light-weight, language independent, data interchange format. +See http://www.JSON.org/ + +The files in this package implement JSON encoders/decoders in Java. +It also includes the capability to convert between JSON and XML, HTTP +headers, Cookies, and CDL. + +This is a reference implementation. There is a large number of JSON packages +in Java. Perhaps someday the Java community will standardize on one. Until +then, choose carefully. + +The license includes this restriction: "The software shall be used for good, +not evil." If your conscience cannot live with that, then choose a different +package. + +The package compiles on Java 1.2 thru Java 1.4. + + +JSONObject.java: The JSONObject can parse text from a String or a JSONTokener +to produce a map-like object. The object provides methods for manipulating its +contents, and for producing a JSON compliant object serialization. + +JSONArray.java: The JSONObject can parse text from a String or a JSONTokener +to produce a vector-like object. The object provides methods for manipulating +its contents, and for producing a JSON compliant array serialization. + +JSONTokener.java: The JSONTokener breaks a text into a sequence of individual +tokens. It can be constructed from a String, Reader, or InputStream. + +JSONException.java: The JSONException is the standard exception type thrown +by this package. + + +JSONString.java: The JSONString interface requires a toJSONString method, +allowing an object to provide its own serialization. + +JSONStringer.java: The JSONStringer provides a convenient facility for +building JSON strings. + +JSONWriter.java: The JSONWriter provides a convenient facility for building +JSON text through a writer. + + +CDL.java: CDL provides support for converting between JSON and comma +delimited lists. + +Cookie.java: Cookie provides support for converting between JSON and cookies. + +CookieList.java: CookieList provides support for converting between JSON and +cookie lists. + +HTTP.java: HTTP provides support for converting between JSON and HTTP headers. + +HTTPTokener.java: HTTPTokener extends JSONTokener for parsing HTTP headers. + +XML.java: XML provides support for converting between JSON and XML. + +JSONML.java: JSONML provides support for converting between JSONML and XML. + +XMLTokener.java: XMLTokener extends JSONTokener for parsing XML text. diff --git a/eurilys4/src/java/jsonlib/XML.java b/eurilys4/src/java/jsonlib/XML.java new file mode 100644 index 00000000..d49784d6 --- /dev/null +++ b/eurilys4/src/java/jsonlib/XML.java @@ -0,0 +1,508 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +import java.util.Iterator; + + +/** + * This provides static methods to convert an XML text into a JSONObject, + * and to covert a JSONObject into an XML text. + * @author JSON.org + * @version 2012-10-26 + */ +public class XML { + + /** The Character '&'. */ + public static final Character AMP = new Character('&'); + + /** The Character '''. */ + public static final Character APOS = new Character('\''); + + /** The Character '!'. */ + public static final Character BANG = new Character('!'); + + /** The Character '='. */ + public static final Character EQ = new Character('='); + + /** The Character '>'. */ + public static final Character GT = new Character('>'); + + /** The Character '<'. */ + public static final Character LT = new Character('<'); + + /** The Character '?'. */ + public static final Character QUEST = new Character('?'); + + /** The Character '"'. */ + public static final Character QUOT = new Character('"'); + + /** The Character '/'. */ + public static final Character SLASH = new Character('/'); + + /** + * Replace special characters with XML escapes: + *

    +     * & (ampersand) is replaced by &amp;
    +     * < (less than) is replaced by &lt;
    +     * > (greater than) is replaced by &gt;
    +     * " (double quote) is replaced by &quot;
    +     * 
    + * @param string The string to be escaped. + * @return The escaped string. + */ + public static String escape(String string) { + StringBuffer sb = new StringBuffer(); + for (int i = 0, length = string.length(); i < length; i++) { + char c = string.charAt(i); + switch (c) { + case '&': + sb.append("&"); + break; + case '<': + sb.append("<"); + break; + case '>': + sb.append(">"); + break; + case '"': + sb.append("""); + break; + case '\'': + sb.append("'"); + break; + default: + sb.append(c); + } + } + return sb.toString(); + } + + /** + * Throw an exception if the string contains whitespace. + * Whitespace is not allowed in tagNames and attributes. + * @param string + * @throws JSONException + */ + public static void noSpace(String string) throws JSONException { + int i, length = string.length(); + if (length == 0) { + throw new JSONException("Empty string."); + } + for (i = 0; i < length; i += 1) { + if (Character.isWhitespace(string.charAt(i))) { + throw new JSONException("'" + string + + "' contains a space character."); + } + } + } + + /** + * Scan the content following the named tag, attaching it to the context. + * @param x The XMLTokener containing the source string. + * @param context The JSONObject that will include the new material. + * @param name The tag name. + * @return true if the close tag is processed. + * @throws JSONException + */ + private static boolean parse(XMLTokener x, JSONObject context, + String name) throws JSONException { + char c; + int i; + JSONObject jsonobject = null; + String string; + String tagName; + Object token; + +// Test for and skip past these forms: +// +// +// +// +// Report errors for these forms: +// <> +// <= +// << + + token = x.nextToken(); + +// "); + return false; + } + x.back(); + } else if (c == '[') { + token = x.nextToken(); + if ("CDATA".equals(token)) { + if (x.next() == '[') { + string = x.nextCDATA(); + if (string.length() > 0) { + context.accumulate("content", string); + } + return false; + } + } + throw x.syntaxError("Expected 'CDATA['"); + } + i = 1; + do { + token = x.nextMeta(); + if (token == null) { + throw x.syntaxError("Missing '>' after ' 0); + return false; + } else if (token == QUEST) { + +// "); + return false; + } else if (token == SLASH) { + +// Close tag + + } else if (token == SLASH) { + if (x.nextToken() != GT) { + throw x.syntaxError("Misshaped tag"); + } + if (jsonobject.length() > 0) { + context.accumulate(tagName, jsonobject); + } else { + context.accumulate(tagName, ""); + } + return false; + +// Content, between <...> and + + } else if (token == GT) { + for (;;) { + token = x.nextContent(); + if (token == null) { + if (tagName != null) { + throw x.syntaxError("Unclosed tag " + tagName); + } + return false; + } else if (token instanceof String) { + string = (String)token; + if (string.length() > 0) { + jsonobject.accumulate("content", + XML.stringToValue(string)); + } + +// Nested element + + } else if (token == LT) { + if (parse(x, jsonobject, tagName)) { + if (jsonobject.length() == 0) { + context.accumulate(tagName, ""); + } else if (jsonobject.length() == 1 && + jsonobject.opt("content") != null) { + context.accumulate(tagName, + jsonobject.opt("content")); + } else { + context.accumulate(tagName, jsonobject); + } + return false; + } + } + } + } else { + throw x.syntaxError("Misshaped tag"); + } + } + } + } + + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. This is much less ambitious than + * JSONObject.stringToValue, especially because it does not attempt to + * convert plus forms, octal forms, hex forms, or E forms lacking decimal + * points. + * @param string A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + if ("".equals(string)) { + return string; + } + if ("true".equalsIgnoreCase(string)) { + return Boolean.TRUE; + } + if ("false".equalsIgnoreCase(string)) { + return Boolean.FALSE; + } + if ("null".equalsIgnoreCase(string)) { + return JSONObject.NULL; + } + if ("0".equals(string)) { + return new Integer(0); + } + +// If it might be a number, try converting it. If that doesn't work, +// return the string. + + try { + char initial = string.charAt(0); + boolean negative = false; + if (initial == '-') { + initial = string.charAt(1); + negative = true; + } + if (initial == '0' && string.charAt(negative ? 2 : 1) == '0') { + return string; + } + if ((initial >= '0' && initial <= '9')) { + if (string.indexOf('.') >= 0) { + return Double.valueOf(string); + } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) { + Long myLong = new Long(string); + if (myLong.longValue() == myLong.intValue()) { + return new Integer(myLong.intValue()); + } else { + return myLong; + } + } + } + } catch (Exception ignore) { + } + return string; + } + + + /** + * Convert a well-formed (but not necessarily valid) XML string into a + * JSONObject. Some information may be lost in this transformation + * because JSON is a data format and XML is a document format. XML uses + * elements, attributes, and content text, while JSON uses unordered + * collections of name/value pairs and arrays of values. JSON does not + * does not like to distinguish between elements and attributes. + * Sequences of similar elements are represented as JSONArrays. Content + * text may be placed in a "content" member. Comments, prologs, DTDs, and + * <[ [ ]]> are ignored. + * @param string The source string. + * @return A JSONObject containing the structured data from the XML string. + * @throws JSONException + */ + public static JSONObject toJSONObject(String string) throws JSONException { + JSONObject jo = new JSONObject(); + XMLTokener x = new XMLTokener(string); + while (x.more() && x.skipPast("<")) { + parse(x, jo, null); + } + return jo; + } + + + /** + * Convert a JSONObject into a well-formed, element-normal XML string. + * @param object A JSONObject. + * @return A string. + * @throws JSONException + */ + public static String toString(Object object) throws JSONException { + return toString(object, null); + } + + + /** + * Convert a JSONObject into a well-formed, element-normal XML string. + * @param object A JSONObject. + * @param tagName The optional name of the enclosing tag. + * @return A string. + * @throws JSONException + */ + public static String toString(Object object, String tagName) + throws JSONException { + StringBuffer sb = new StringBuffer(); + int i; + JSONArray ja; + JSONObject jo; + String key; + Iterator keys; + int length; + String string; + Object value; + if (object instanceof JSONObject) { + +// Emit + + if (tagName != null) { + sb.append('<'); + sb.append(tagName); + sb.append('>'); + } + +// Loop thru the keys. + + jo = (JSONObject)object; + keys = jo.keys(); + while (keys.hasNext()) { + key = keys.next().toString(); + value = jo.opt(key); + if (value == null) { + value = ""; + } + if (value instanceof String) { + string = (String)value; + } else { + string = null; + } + +// Emit content in body + + if ("content".equals(key)) { + if (value instanceof JSONArray) { + ja = (JSONArray)value; + length = ja.length(); + for (i = 0; i < length; i += 1) { + if (i > 0) { + sb.append('\n'); + } + sb.append(escape(ja.get(i).toString())); + } + } else { + sb.append(escape(value.toString())); + } + +// Emit an array of similar keys + + } else if (value instanceof JSONArray) { + ja = (JSONArray)value; + length = ja.length(); + for (i = 0; i < length; i += 1) { + value = ja.get(i); + if (value instanceof JSONArray) { + sb.append('<'); + sb.append(key); + sb.append('>'); + sb.append(toString(value)); + sb.append("'); + } else { + sb.append(toString(value, key)); + } + } + } else if ("".equals(value)) { + sb.append('<'); + sb.append(key); + sb.append("/>"); + +// Emit a new tag + + } else { + sb.append(toString(value, key)); + } + } + if (tagName != null) { + +// Emit the close tag + + sb.append("'); + } + return sb.toString(); + +// XML does not have good support for arrays. If an array appears in a place +// where XML is lacking, synthesize an element. + + } else { + if (object.getClass().isArray()) { + object = new JSONArray(object); + } + if (object instanceof JSONArray) { + ja = (JSONArray)object; + length = ja.length(); + for (i = 0; i < length; i += 1) { + sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName)); + } + return sb.toString(); + } else { + string = (object == null) ? "null" : escape(object.toString()); + return (tagName == null) ? "\"" + string + "\"" : + (string.length() == 0) ? "<" + tagName + "/>" : + "<" + tagName + ">" + string + ""; + } + } + } +} diff --git a/eurilys4/src/java/jsonlib/XMLTokener.java b/eurilys4/src/java/jsonlib/XMLTokener.java new file mode 100644 index 00000000..be15ebeb --- /dev/null +++ b/eurilys4/src/java/jsonlib/XMLTokener.java @@ -0,0 +1,365 @@ +package org.json; + +/* +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * The XMLTokener extends the JSONTokener to provide additional methods + * for the parsing of XML texts. + * @author JSON.org + * @version 2012-11-13 + */ +public class XMLTokener extends JSONTokener { + + + /** The table of entity values. It initially contains Character values for + * amp, apos, gt, lt, quot. + */ + public static final java.util.HashMap entity; + + static { + entity = new java.util.HashMap(8); + entity.put("amp", XML.AMP); + entity.put("apos", XML.APOS); + entity.put("gt", XML.GT); + entity.put("lt", XML.LT); + entity.put("quot", XML.QUOT); + } + + /** + * Construct an XMLTokener from a string. + * @param s A source string. + */ + public XMLTokener(String s) { + super(s); + } + + /** + * Get the text in the CDATA block. + * @return The string up to the ]]>. + * @throws JSONException If the ]]> is not found. + */ + public String nextCDATA() throws JSONException { + char c; + int i; + StringBuffer sb = new StringBuffer(); + for (;;) { + c = next(); + if (end()) { + throw syntaxError("Unclosed CDATA"); + } + sb.append(c); + i = sb.length() - 3; + if (i >= 0 && sb.charAt(i) == ']' && + sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') { + sb.setLength(i); + return sb.toString(); + } + } + } + + + /** + * Get the next XML outer token, trimming whitespace. There are two kinds + * of tokens: the '<' character which begins a markup tag, and the content + * text between markup tags. + * + * @return A string, or a '<' Character, or null if there is no more + * source text. + * @throws JSONException + */ + public Object nextContent() throws JSONException { + char c; + StringBuffer sb; + do { + c = next(); + } while (Character.isWhitespace(c)); + if (c == 0) { + return null; + } + if (c == '<') { + return XML.LT; + } + sb = new StringBuffer(); + for (;;) { + if (c == '<' || c == 0) { + back(); + return sb.toString().trim(); + } + if (c == '&') { + sb.append(nextEntity(c)); + } else { + sb.append(c); + } + c = next(); + } + } + + + /** + * Return the next entity. These entities are translated to Characters: + * & ' > < ". + * @param ampersand An ampersand character. + * @return A Character or an entity String if the entity is not recognized. + * @throws JSONException If missing ';' in XML entity. + */ + public Object nextEntity(char ampersand) throws JSONException { + StringBuffer sb = new StringBuffer(); + for (;;) { + char c = next(); + if (Character.isLetterOrDigit(c) || c == '#') { + sb.append(Character.toLowerCase(c)); + } else if (c == ';') { + break; + } else { + throw syntaxError("Missing ';' in XML entity: &" + sb); + } + } + String string = sb.toString(); + Object object = entity.get(string); + return object != null ? object : ampersand + string + ";"; + } + + + /** + * Returns the next XML meta token. This is used for skipping over + * and structures. + * @return Syntax characters (< > / = ! ?) are returned as + * Character, and strings and names are returned as Boolean. We don't care + * what the values actually are. + * @throws JSONException If a string is not properly closed or if the XML + * is badly structured. + */ + public Object nextMeta() throws JSONException { + char c; + char q; + do { + c = next(); + } while (Character.isWhitespace(c)); + switch (c) { + case 0: + throw syntaxError("Misshaped meta tag"); + case '<': + return XML.LT; + case '>': + return XML.GT; + case '/': + return XML.SLASH; + case '=': + return XML.EQ; + case '!': + return XML.BANG; + case '?': + return XML.QUEST; + case '"': + case '\'': + q = c; + for (;;) { + c = next(); + if (c == 0) { + throw syntaxError("Unterminated string"); + } + if (c == q) { + return Boolean.TRUE; + } + } + default: + for (;;) { + c = next(); + if (Character.isWhitespace(c)) { + return Boolean.TRUE; + } + switch (c) { + case 0: + case '<': + case '>': + case '/': + case '=': + case '!': + case '?': + case '"': + case '\'': + back(); + return Boolean.TRUE; + } + } + } + } + + + /** + * Get the next XML Token. These tokens are found inside of angle + * brackets. It may be one of these characters: / > = ! ? or it + * may be a string wrapped in single quotes or double quotes, or it may be a + * name. + * @return a String or a Character. + * @throws JSONException If the XML is not well formed. + */ + public Object nextToken() throws JSONException { + char c; + char q; + StringBuffer sb; + do { + c = next(); + } while (Character.isWhitespace(c)); + switch (c) { + case 0: + throw syntaxError("Misshaped element"); + case '<': + throw syntaxError("Misplaced '<'"); + case '>': + return XML.GT; + case '/': + return XML.SLASH; + case '=': + return XML.EQ; + case '!': + return XML.BANG; + case '?': + return XML.QUEST; + +// Quoted string + + case '"': + case '\'': + q = c; + sb = new StringBuffer(); + for (;;) { + c = next(); + if (c == 0) { + throw syntaxError("Unterminated string"); + } + if (c == q) { + return sb.toString(); + } + if (c == '&') { + sb.append(nextEntity(c)); + } else { + sb.append(c); + } + } + default: + +// Name + + sb = new StringBuffer(); + for (;;) { + sb.append(c); + c = next(); + if (Character.isWhitespace(c)) { + return sb.toString(); + } + switch (c) { + case 0: + return sb.toString(); + case '>': + case '/': + case '=': + case '!': + case '?': + case '[': + case ']': + back(); + return sb.toString(); + case '<': + case '"': + case '\'': + throw syntaxError("Bad character in a name"); + } + } + } + } + + + /** + * Skip characters until past the requested string. + * If it is not found, we are left at the end of the source with a result of false. + * @param to A string to skip past. + * @throws JSONException + */ + public boolean skipPast(String to) throws JSONException { + boolean b; + char c; + int i; + int j; + int offset = 0; + int length = to.length(); + char[] circle = new char[length]; + + /* + * First fill the circle buffer with as many characters as are in the + * to string. If we reach an early end, bail. + */ + + for (i = 0; i < length; i += 1) { + c = next(); + if (c == 0) { + return false; + } + circle[i] = c; + } + + /* We will loop, possibly for all of the remaining characters. */ + + for (;;) { + j = offset; + b = true; + + /* Compare the circle buffer with the to string. */ + + for (i = 0; i < length; i += 1) { + if (circle[j] != to.charAt(i)) { + b = false; + break; + } + j += 1; + if (j >= length) { + j -= length; + } + } + + /* If we exit the loop with b intact, then victory is ours. */ + + if (b) { + return true; + } + + /* Get the next character. If there isn't one, then defeat is ours. */ + + c = next(); + if (c == 0) { + return false; + } + /* + * Shove the character in the circle buffer and advance the + * circle offset. The offset is mod n. + */ + circle[offset] = c; + offset += 1; + if (offset >= length) { + offset -= length; + } + } + } +} diff --git a/eurilys4/src/java/jsonlib/zip/BitInputStream.java b/eurilys4/src/java/jsonlib/zip/BitInputStream.java new file mode 100644 index 00000000..7864ce15 --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/BitInputStream.java @@ -0,0 +1,169 @@ +package org.json.zip; + +import java.io.IOException; +import java.io.InputStream; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * This is a big endian bit reader. It reads its bits from an InputStream. + * + * @version 2013-04-18 + * + */ +public class BitInputStream implements BitReader { + /** + * 2^n - 1 + */ + static final int[] mask = { 0, 1, 3, 7, 15, 31, 63, 127, 255 }; + + /** + * The number of bits remaining in the current byte. + */ + private int available = 0; + + /** + * Up to a byte's worth of unread bits. + */ + private int unread = 0; + + /** + * The source of the bits. + */ + private InputStream in; + + /** + * The number of bits read so far. This is used in padding. + */ + private long nrBits = 0; + + /** + * Make a BitReader from an InputStream. The BitReader will take bytes from + * the InputStream and unpack them into bits. + * + * @param in + * An InputStream. + */ + public BitInputStream(InputStream in) { + this.in = in; + } + + /** + * Make a BitReader. The first byte is passed in explicitly, the remaining + * bytes are obtained from the InputStream. This makes it possible to look + * at the first byte of a stream before deciding that it should be read as + * bits. + * + * @param in + * An InputStream + * @param firstByte + * The first byte, which was probably read from in. + */ + public BitInputStream(InputStream in, int firstByte) { + this.in = in; + this.unread = firstByte; + this.available = 8; + } + + /** + * Read one bit. + * + * @return true if it is a 1 bit. + */ + public boolean bit() throws IOException { + return read(1) != 0; + } + + /** + * Get the number of bits that have been read from this BitInputStream. + * This includes pad bits that have been skipped, but might not include + * bytes that have been read from the underlying InputStream that have not + * yet been delivered as bits. + * + * @return The number of bits read so far. + */ + public long nrBits() { + return this.nrBits; + } + + /** + * Check that the rest of the block has been padded with zeroes. + * + * @param factor + * The size of the block to pad. This will typically be 8, 16, + * 32, 64, 128, 256, etc. + * @return true if the block was zero padded, or false if the the padding + * contains any one bits. + * @throws IOException + */ + public boolean pad(int factor) throws IOException { + int padding = factor - (int) (this.nrBits % factor); + boolean result = true; + + for (int i = 0; i < padding; i += 1) { + if (bit()) { + result = false; + } + } + return result; + } + + /** + * Read some bits. + * + * @param width + * The number of bits to read. (0..32) + * @throws IOException + * @return the bits + */ + public int read(int width) throws IOException { + if (width == 0) { + return 0; + } + if (width < 0 || width > 32) { + throw new IOException("Bad read width."); + } + int result = 0; + while (width > 0) { + if (this.available == 0) { + this.unread = this.in.read(); + if (this.unread < 0) { + throw new IOException("Attempt to read past end."); + } + this.available = 8; + } + int take = width; + if (take > this.available) { + take = this.available; + } + result |= ((this.unread >>> (this.available - take)) & mask[take]) + << (width - take); + this.nrBits += take; + this.available -= take; + width -= take; + } + return result; + } +} diff --git a/eurilys4/src/java/jsonlib/zip/BitOutputStream.java b/eurilys4/src/java/jsonlib/zip/BitOutputStream.java new file mode 100644 index 00000000..526ad611 --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/BitOutputStream.java @@ -0,0 +1,154 @@ +package org.json.zip; + +import java.io.IOException; +import java.io.OutputStream; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * This is a big endian bit writer. It writes its bits to an OutputStream. + * + * @version 2013-04-18 + * + */ +public class BitOutputStream implements BitWriter { + + /** + * The number of bits written. + */ + private long nrBits = 0; + + /** + * The destination of the bits. + */ + private OutputStream out; + + /** + * Holder of bits not yet written. + */ + private int unwritten; + + /** + * The number of unused bits in this.unwritten. + */ + private int vacant = 8; + + /** + * Use an OutputStream to produce a BitWriter. The BitWriter will send its + * bits to the OutputStream as each byte is filled. + * + * @param out + * An Output Stream + */ + public BitOutputStream(OutputStream out) { + this.out = out; + } + + /** + * Returns the number of bits that have been written to this + * bitOutputStream. This may include bits that have not yet been written + * to the underlying outputStream. + */ + public long nrBits() { + return this.nrBits; + } + + /** + * Write a 1 bit. + * + * @throws IOException + */ + public void one() throws IOException { + write(1, 1); + } + + /** + * Pad the rest of the block with zeroes and flush. pad(8) flushes the last + * unfinished byte. The underlying OutputStream will be flushed. + * + * @param factor + * The size of the block to pad. This will typically be 8, 16, + * 32, 64, 128, 256, etc. + * @return this + * @throws IOException + */ + public void pad(int factor) throws IOException { + int padding = factor - (int) (nrBits % factor); + int excess = padding & 7; + if (excess > 0) { + this.write(0, excess); + padding -= excess; + } + while (padding > 0) { + this.write(0, 8); + padding -= 8; + } + this.out.flush(); + } + + /** + * Write some bits. Up to 32 bits can be written at a time. + * + * @param bits + * The bits to be written. + * @param width + * The number of bits to write. (0..32) + * @throws IOException + */ + public void write(int bits, int width) throws IOException { + if (bits == 0 && width == 0) { + return; + } + if (width <= 0 || width > 32) { + throw new IOException("Bad write width."); + } + while (width > 0) { + int actual = width; + if (actual > this.vacant) { + actual = this.vacant; + } + this.unwritten |= ((bits >>> (width - actual)) & + BitInputStream.mask[actual]) << (this.vacant - actual); + width -= actual; + nrBits += actual; + this.vacant -= actual; + if (this.vacant == 0) { + this.out.write(this.unwritten); + this.unwritten = 0; + this.vacant = 8; + } + } + } + + /** + * Write a 0 bit. + * + * @throws IOException + */ + public void zero() throws IOException { + write(0, 1); + + } +} diff --git a/eurilys4/src/java/jsonlib/zip/BitReader.java b/eurilys4/src/java/jsonlib/zip/BitReader.java new file mode 100644 index 00000000..1987729b --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/BitReader.java @@ -0,0 +1,41 @@ +package org.json.zip; + +import java.io.IOException; + +public interface BitReader { + /** + * Read one bit. + * + * @return true if it is a 1 bit. + */ + public boolean bit() throws IOException; + + /** + * Returns the number of bits that have been read from this bitreader. + * + * @return The number of bits read so far. + */ + public long nrBits(); + + /** + * Check that the rest of the block has been padded with zeroes. + * + * @param factor + * The size in bits of the block to pad. This will typically be + * 8, 16, 32, 64, 128, 256, etc. + * @return true if the block was zero padded, or false if the the padding + * contained any one bits. + * @throws IOException + */ + public boolean pad(int factor) throws IOException; + + /** + * Read some bits. + * + * @param width + * The number of bits to read. (0..32) + * @throws IOException + * @return the bits + */ + public int read(int width) throws IOException; +} diff --git a/eurilys4/src/java/jsonlib/zip/BitWriter.java b/eurilys4/src/java/jsonlib/zip/BitWriter.java new file mode 100644 index 00000000..83eb7e31 --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/BitWriter.java @@ -0,0 +1,51 @@ +package org.json.zip; + +import java.io.IOException; + +/** + * A bitwriter is a an interface that allows for doing output at the bit level. + * Most IO interfaces only allow for writing at the byte level or higher. + */ +public interface BitWriter { + /** + * Returns the number of bits that have been written to this bitwriter. + */ + public long nrBits(); + + /** + * Write a 1 bit. + * + * @throws IOException + */ + public void one() throws IOException; + + /** + * Pad the rest of the block with zeros and flush. + * + * @param factor + * The size in bits of the block to pad. This will typically be + * 8, 16, 32, 64, 128, 256, etc. + * @return true if the block was zero padded, or false if the the padding + * contains any one bits. + * @throws IOException + */ + public void pad(int factor) throws IOException; + + /** + * Write some bits. Up to 32 bits can be written at a time. + * + * @param bits + * The bits to be written. + * @param width + * The number of bits to write. (0..32) + * @throws IOException + */ + public void write(int bits, int width) throws IOException; + + /** + * Write a 0 bit. + * + * @throws IOException + */ + public void zero() throws IOException; +} diff --git a/eurilys4/src/java/jsonlib/zip/Compressor.java b/eurilys4/src/java/jsonlib/zip/Compressor.java new file mode 100644 index 00000000..6dddff42 --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/Compressor.java @@ -0,0 +1,575 @@ +package org.json.zip; + +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.Kim; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * JSONzip is a compression scheme for JSON text. + * + * @author JSON.org + * @version 2013-04-18 + */ + +/** + * A compressor implements the compression behavior of JSONzip. It provides a + * zip method that takes a JSONObject or JSONArray and delivers a stream of + * bits to a BitWriter. + * + * FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT BEEN TESTED ADEQUATELY + * FOR PRODUCTION USE. + */ +public class Compressor extends JSONzip { + + /** + * A compressor outputs to a BitWriter. + */ + final BitWriter bitwriter; + + /** + * Create a new compressor. It may be used for an entire session or + * subsession. + * + * @param bitwriter + * The BitWriter this Compressor will output to. Don't forget to + * flush. + */ + public Compressor(BitWriter bitwriter) { + super(); + this.bitwriter = bitwriter; + } + + /** + * Return a 4 bit code for a character in a JSON number. The digits '0' to + * '9' get the codes 0 to 9. '.' is 10, '-' is 11, '+' is 12, and 'E' or + * 'e' is 13. + * + * @param digit + * An ASCII character from a JSIN number. + * @return + */ + private static int bcd(char digit) { + if (digit >= '0' && digit <= '9') { + return digit - '0'; + } + switch (digit) { + case '.': + return 10; + case '-': + return 11; + case '+': + return 12; + default: + return 13; + } + } + + /** + * Finish the final byte and flush the bitwriter. This does the same thing + * as pad(8). + * + * @throws JSONException + */ + public void flush() throws JSONException { + pad(8); + } + + /** + * Output a one bit. + * + * @throws IOException + */ + private void one() throws JSONException { + if (probe) { + log(1); + } + write(1, 1); + } + + /** + * Pad the output to fill an allotment of bits. + * + * @param factor + * The size of the bit allotment. A value of 8 will complete and + * flush the current byte. If you don't pad, then some of the + * last bits might not be sent to the Output Stream. + * @throws JSONException + */ + public void pad(int factor) throws JSONException { + try { + this.bitwriter.pad(factor); + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Write a number, using the number of bits necessary to hold the number. + * + * @param integer + * The value to be encoded. + * @param width + * The number of bits to encode the value, between 0 and 32. + * @throws JSONException + */ + private void write(int integer, int width) throws JSONException { + try { + this.bitwriter.write(integer, width); + if (probe) { + log(integer, width); + } + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Write an integer with Huffman encoding. The bit pattern that is written + * will be determined by the Huffman encoder. + * + * @param integer + * The value to be written. + * @param huff + * The Huffman encoder. + * @throws JSONException + */ + private void write(int integer, Huff huff) throws JSONException { + huff.write(integer, this.bitwriter); + } + + /** + * Write each of the bytes in a kim with Huffman encoding. + * + * @param kim + * A kim containing the bytes to be written. + * @param huff + * The Huffman encoder. + * @throws JSONException + */ + private void write(Kim kim, Huff huff) throws JSONException { + write(kim, 0, kim.length, huff); + } + + /** + * Write a range of bytes from a Kim with Huffman encoding. + * + * @param kim + * A Kim containing the bytes to be written. + * @param from + * The index of the first byte to write. + * @param thru + * The index after the last byte to write. + * @param huff + * The Huffman encoder. + * @throws JSONException + */ + private void write(Kim kim, int from, int thru, Huff huff) + throws JSONException { + for (int at = from; at < thru; at += 1) { + write(kim.get(at), huff); + } + } + + /** + * Write an integer, using the number of bits necessary to hold the number + * as determined by its keep, and increment its usage count in the keep. + * + * @param integer + * The value to be encoded. + * @param keep + * The Keep that the integer is one of. + * @throws JSONException + */ + private void writeAndTick(int integer, Keep keep) throws JSONException { + int width = keep.bitsize(); + keep.tick(integer); + if (probe) { + log("\"" + keep.value(integer) + "\""); + } + write(integer, width); + } + + /** + * Write a JSON Array. + * + * @param jsonarray + * @throws JSONException + */ + private void writeArray(JSONArray jsonarray) throws JSONException { + +// JSONzip has three encodings for arrays: +// The array is empty (zipEmptyArray). +// First value in the array is a string (zipArrayString). +// First value in the array is not a string (zipArrayValue). + + boolean stringy = false; + int length = jsonarray.length(); + if (length == 0) { + write(zipEmptyArray, 3); + } else { + Object value = jsonarray.get(0); + if (value == null) { + value = JSONObject.NULL; + } + if (value instanceof String) { + stringy = true; + write(zipArrayString, 3); + writeString((String) value); + } else { + write(zipArrayValue, 3); + writeValue(value); + } + for (int i = 1; i < length; i += 1) { + if (probe) { + log(); + } + value = jsonarray.get(i); + if (value == null) { + value = JSONObject.NULL; + } + if (value instanceof String != stringy) { + zero(); + } + one(); + if (value instanceof String) { + writeString((String) value); + } else { + writeValue(value); + } + } + zero(); + zero(); + + } + } + + /** + * Write a JSON value. + * + * @param value + * One of these types: JSONObject, JSONArray (or Map or + * Collection or array), Number (or Integer or Long or Double), + * or String, or Boolean, or JSONObject.NULL, or null. + * @throws JSONException + */ + private void writeJSON(Object value) throws JSONException { + if (JSONObject.NULL.equals(value)) { + write(zipNull, 3); + } else if (Boolean.FALSE.equals(value)) { + write(zipFalse, 3); + } else if (Boolean.TRUE.equals(value)) { + write(zipTrue, 3); + } else { + if (value instanceof Map) { + value = new JSONObject((Map) value); + } else if (value instanceof Collection) { + value = new JSONArray((Collection) value); + } else if (value.getClass().isArray()) { + value = new JSONArray(value); + } + if (value instanceof JSONObject) { + writeObject((JSONObject) value); + } else if (value instanceof JSONArray) { + writeArray((JSONArray) value); + } else { + throw new JSONException("Unrecognized object"); + } + } + } + + /** + * Write the name of an object property. Names have their own Keep and + * Huffman encoder because they are expected to be a more restricted set. + * + * @param name + * @throws JSONException + */ + private void writeName(String name) throws JSONException { + +// If this name has already been registered, then emit its integer and +// increment its usage count. + + Kim kim = new Kim(name); + int integer = this.namekeep.find(kim); + if (integer != none) { + one(); + writeAndTick(integer, this.namekeep); + } else { + +// Otherwise, emit the string with Huffman encoding, and register it. + + zero(); + write(kim, this.namehuff); + write(end, namehuff); + this.namekeep.register(kim); + } + } + + /** + * Write a JSON object. + * + * @param jsonobject + * @return + * @throws JSONException + */ + private void writeObject(JSONObject jsonobject) throws JSONException { + +// JSONzip has two encodings for objects: Empty Objects (zipEmptyObject) and +// non-empty objects (zipObject). + + boolean first = true; + Iterator keys = jsonobject.keys(); + while (keys.hasNext()) { + if (probe) { + log("\n"); + } + Object key = keys.next(); + if (key instanceof String) { + if (first) { + first = false; + write(zipObject, 3); + } else { + one(); + } + writeName((String) key); + Object value = jsonobject.get((String) key); + if (value instanceof String) { + zero(); + writeString((String) value); + } else { + one(); + writeValue(value); + } + } + } + if (first) { + write(zipEmptyObject, 3); + } else { + zero(); + } + } + + /** + * Write a string. + * + * @param string + * @throws JSONException + */ + private void writeString(String string) throws JSONException { + +// Special case for empty strings. + + if (string.length() == 0) { + zero(); + zero(); + write(end, this.substringhuff); + zero(); + } else { + Kim kim = new Kim(string); + +// Look for the string in the strings keep. If it is found, emit its +// integer and count that as a use. + + int integer = this.stringkeep.find(kim); + if (integer != none) { + one(); + writeAndTick(integer, this.stringkeep); + } else { + +// But if it is not found, emit the string's substrings. Register the string +// so that the next lookup will succeed. + + writeSubstring(kim); + this.stringkeep.register(kim); + } + } + } + + /** + * Write a string, attempting to match registered substrings. + * + * @param kim + * @throws JSONException + */ + private void writeSubstring(Kim kim) throws JSONException { + this.substringkeep.reserve(); + zero(); + int from = 0; + int thru = kim.length; + int until = thru - JSONzip.minSubstringLength; + int previousFrom = none; + int previousThru = 0; + +// Find a substring from the substring keep. + + while (true) { + int at; + int integer = none; + for (at = from; at <= until; at += 1) { + integer = this.substringkeep.match(kim, at, thru); + if (integer != none) { + break; + } + } + if (integer == none) { + break; + } + +// If a substring is found, emit any characters that were before the matched +// substring. Then emit the substring's integer and loop back to match the +// remainder with another substring. + + if (from != at) { + zero(); + write(kim, from, at, this.substringhuff); + write(end, this.substringhuff); + if (previousFrom != none) { + this.substringkeep.registerOne(kim, previousFrom, + previousThru); + previousFrom = none; + } + } + one(); + writeAndTick(integer, this.substringkeep); + from = at + this.substringkeep.length(integer); + if (previousFrom != none) { + this.substringkeep.registerOne(kim, previousFrom, + previousThru); + previousFrom = none; + } + previousFrom = at; + previousThru = from + 1; + } + +// If a substring is not found, then emit the remaining characters. + + zero(); + if (from < thru) { + write(kim, from, thru, this.substringhuff); + if (previousFrom != none) { + this.substringkeep.registerOne(kim, previousFrom, previousThru); + } + } + write(end, this.substringhuff); + zero(); + +// Register the string's substrings in the trie in hopes of future substring +// matching. + + substringkeep.registerMany(kim); + } + + /** + * Write a value. + * + * @param value + * One of these types: Boolean, Number, etc. + * @throws JSONException + */ + private void writeValue(Object value) throws JSONException { + if (value instanceof Number) { + String string = JSONObject.numberToString((Number) value); + int integer = this.values.find(string); + if (integer != none) { + write(2, 2); + writeAndTick(integer, this.values); + return; + } + if (value instanceof Integer || value instanceof Long) { + long longer = ((Number) value).longValue(); + if (longer >= 0 && longer < int14) { + write(0, 2); + if (longer < int4) { + zero(); + write((int) longer, 4); + return; + } + one(); + if (longer < int7) { + zero(); + write((int) longer, 7); + return; + } + one(); + write((int) longer, 14); + return; + } + } + write(1, 2); + for (int i = 0; i < string.length(); i += 1) { + write(bcd(string.charAt(i)), 4); + } + write(endOfNumber, 4); + this.values.register(string); + } else { + write(3, 2); + writeJSON(value); + } + } + + /** + * Output a zero bit. + * + * @throws JSONException + * + * @throws IOException + */ + private void zero() throws JSONException { + if (probe) { + log(0); + } + write(0, 1); + } + + /** + * Compress a JSONObject. + * + * @param jsonobject + * @throws JSONException + */ + public void zip(JSONObject jsonobject) throws JSONException { + begin(); + writeJSON(jsonobject); + } + + /** + * Compress a JSONArray. + * + * @param jsonarray + * @throws JSONException + */ + public void zip(JSONArray jsonarray) throws JSONException { + begin(); + writeJSON(jsonarray); + } +} diff --git a/eurilys4/src/java/jsonlib/zip/Decompressor.java b/eurilys4/src/java/jsonlib/zip/Decompressor.java new file mode 100644 index 00000000..108a2e2c --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/Decompressor.java @@ -0,0 +1,325 @@ +package org.json.zip; + +import java.io.UnsupportedEncodingException; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.Kim; + +/* + Copyright (c) 2012 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * JSONzip is a compression scheme for JSON text. + * + * @author JSON.org + * @version 2013-04-18 + */ + +public class Decompressor extends JSONzip { + + /** + * A decompressor reads bits from a BitReader. + */ + BitReader bitreader; + + /** + * Create a new compressor. It may be used for an entire session or + * subsession. + * + * @param bitreader + * The bitreader that this decompressor will read from. + */ + public Decompressor(BitReader bitreader) { + super(); + this.bitreader = bitreader; + } + + /** + * Read one bit. + * + * @return true if 1, false if 0. + * @throws JSONException + */ + private boolean bit() throws JSONException { + boolean value; + try { + value = this.bitreader.bit(); + if (probe) { + log(value ? 1 : 0); + } + return value; + } catch (Throwable e) { + throw new JSONException(e); + } + + } + + /** + * Read enough bits to obtain an integer from the keep, and increase that + * integer's weight. + * + * @param keep + * @param bitreader + * @return + * @throws JSONException + */ + private Object getAndTick(Keep keep, BitReader bitreader) + throws JSONException { + try { + int width = keep.bitsize(); + int integer = bitreader.read(width); + Object value = keep.value(integer); + if (JSONzip.probe) { + JSONzip.log("\"" + value + "\""); + JSONzip.log(integer, width); + } + if (integer >= keep.length) { + throw new JSONException("Deep error."); + } + keep.tick(integer); + return value; + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * The pad method skips the bits that padded a stream to fit some + * allocation. pad(8) will skip over the remainder of a byte. + * + * @param factor + * @return true if all of the padding bits were zero. + * @throws JSONException + */ + public boolean pad(int factor) throws JSONException { + try { + return this.bitreader.pad(factor); + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Read an integer, specifying its width in bits. + * + * @param width + * 0 to 32. + * @return An unsigned integer. + * @throws JSONException + */ + private int read(int width) throws JSONException { + try { + int value = this.bitreader.read(width); + if (probe) { + log(value, width); + } + return value; + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Read a JSONArray. + * + * @param stringy + * true if the first element is a string. + * @return + * @throws JSONException + */ + private JSONArray readArray(boolean stringy) throws JSONException { + JSONArray jsonarray = new JSONArray(); + jsonarray.put(stringy ? readString() : readValue()); + while (true) { + if (probe) { + log("\n"); + } + if (!bit()) { + if (!bit()) { + return jsonarray; + } + jsonarray.put(stringy ? readValue() : readString()); + } else { + jsonarray.put(stringy ? readString() : readValue()); + } + } + } + + /** + * Read a JSON value. The type of value is determined by the next 3 bits. + * + * @return + * @throws JSONException + */ + private Object readJSON() throws JSONException { + switch (read(3)) { + case zipObject: + return readObject(); + case zipArrayString: + return readArray(true); + case zipArrayValue: + return readArray(false); + case zipEmptyObject: + return new JSONObject(); + case zipEmptyArray: + return new JSONArray(); + case zipTrue: + return Boolean.TRUE; + case zipFalse: + return Boolean.FALSE; + default: + return JSONObject.NULL; + } + } + + private String readName() throws JSONException { + byte[] bytes = new byte[65536]; + int length = 0; + if (!bit()) { + while (true) { + int c = this.namehuff.read(this.bitreader); + if (c == end) { + break; + } + bytes[length] = (byte) c; + length += 1; + } + if (length == 0) { + return ""; + } + Kim kim = new Kim(bytes, length); + this.namekeep.register(kim); + return kim.toString(); + } + return getAndTick(this.namekeep, this.bitreader).toString(); + } + + private JSONObject readObject() throws JSONException { + JSONObject jsonobject = new JSONObject(); + while (true) { + if (probe) { + log("\n"); + } + String name = readName(); + jsonobject.put(name, !bit() ? readString() : readValue()); + if (!bit()) { + return jsonobject; + } + } + } + + private String readString() throws JSONException { + Kim kim; + int from = 0; + int thru = 0; + int previousFrom = none; + int previousThru = 0; + if (bit()) { + return getAndTick(this.stringkeep, this.bitreader).toString(); + } + byte[] bytes = new byte[65536]; + boolean one = bit(); + this.substringkeep.reserve(); + while (true) { + if (one) { + from = thru; + kim = (Kim) getAndTick(this.substringkeep, this.bitreader); + thru = kim.copy(bytes, from); + if (previousFrom != none) { + this.substringkeep.registerOne(new Kim(bytes, previousFrom, + previousThru + 1)); + } + previousFrom = from; + previousThru = thru; + one = bit(); + } else { + from = none; + while (true) { + int c = this.substringhuff.read(this.bitreader); + if (c == end) { + break; + } + bytes[thru] = (byte) c; + thru += 1; + if (previousFrom != none) { + this.substringkeep.registerOne(new Kim(bytes, + previousFrom, previousThru + 1)); + previousFrom = none; + } + } + if (!bit()) { + break; + } + one = true; + } + } + if (thru == 0) { + return ""; + } + kim = new Kim(bytes, thru); + this.stringkeep.register(kim); + this.substringkeep.registerMany(kim); + return kim.toString(); + } + + private Object readValue() throws JSONException { + switch (read(2)) { + case 0: + return new Integer(read(!bit() ? 4 : !bit() ? 7 : 14)); + case 1: + byte[] bytes = new byte[256]; + int length = 0; + while (true) { + int c = read(4); + if (c == endOfNumber) { + break; + } + bytes[length] = bcd[c]; + length += 1; + } + Object value; + try { + value = JSONObject.stringToValue(new String(bytes, 0, length, + "US-ASCII")); + } catch (UnsupportedEncodingException e) { + throw new JSONException(e); + } + this.values.register(value); + return value; + case 2: + return getAndTick(this.values, this.bitreader); + case 3: + return readJSON(); + default: + throw new JSONException("Impossible."); + } + } + + public Object unzip() throws JSONException { + begin(); + return readJSON(); + } +} diff --git a/eurilys4/src/java/jsonlib/zip/Huff.java b/eurilys4/src/java/jsonlib/zip/Huff.java new file mode 100644 index 00000000..2e1d1c92 --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/Huff.java @@ -0,0 +1,406 @@ +package org.json.zip; + +import org.json.JSONException; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * JSONzip is a compression scheme for JSON text. + * @author JSON.org + * @version 2013-04-18 + */ + +/** + * A Huffman encoder/decoder. It operates over a domain of integers, which may + * map to characters or other symbols. Symbols that are used frequently are + * given shorter codes than symbols that are used infrequently. This usually + * produces shorter messages. + * + * Initially, all of the symbols are given the same weight. The weight of a + * symbol is incremented by the tick method. The generate method is used to + * generate the encoding table. The table must be generated before encoding or + * decoding. You may regenerate the table with the latest weights at any time. + */ +public class Huff implements None, PostMortem { + + /** + * The number of symbols known to the encoder. + */ + private final int domain; + + /** + * An array that maps symbol values to symbols. + */ + private final Symbol[] symbols; + + /** + * The root of the decoding table, and the terminal of the encoding table. + */ + private Symbol table; + + /** + * Have any weights changed since the table was last generated? + */ + private boolean upToDate = false; + + /** + * The number of bits in the last symbol. This is used in tracing. + */ + private int width; + + private static class Symbol implements PostMortem { + public Symbol back; + public Symbol next; + public Symbol zero; + public Symbol one; + public final int integer; + public long weight; + + /** + * Make a symbol representing a character or other value. + * + * @param integer + * The symbol's number + */ + public Symbol(int integer) { + this.integer = integer; + this.weight = 0; + this.next = null; + this.back = null; + this.one = null; + this.zero = null; + } + + public boolean postMortem(PostMortem pm) { + boolean result = true; + Symbol that = (Symbol) pm; + + if (this.integer != that.integer || this.weight != that.weight) { + return false; + } + if ((this.back != null) != (that.back != null)) { + return false; + } + Symbol zero = this.zero; + Symbol one = this.one; + if (zero == null) { + if (that.zero != null) { + return false; + } + } else { + result = zero.postMortem(that.zero); + } + if (one == null) { + if (that.one != null) { + return false; + } + } else { + result = one.postMortem(that.one); + } + return result; + } + + } + + /** + * Construct a Huffman encoder/decoder. + * + * @param domain + * The number of values known to the object. + */ + public Huff(int domain) { + this.domain = domain; + int length = domain * 2 - 1; + this.symbols = new Symbol[length]; + +// Make the leaf symbols. + + for (int i = 0; i < domain; i += 1) { + symbols[i] = new Symbol(i); + } + +// SMake the links. + + for (int i = domain; i < length; i += 1) { + symbols[i] = new Symbol(none); + } + } + + /** + * Generate the encoding/decoding table. The table determines the bit + * sequences used by the read and write methods. + * + * @return this + */ + public void generate() { + if (!this.upToDate) { + +// Phase One: Sort the symbols by weight into a linked list. + + Symbol head = this.symbols[0]; + Symbol next; + Symbol previous = head; + Symbol symbol; + + this.table = null; + head.next = null; + for (int i = 1; i < this.domain; i += 1) { + symbol = symbols[i]; + +// If this symbol weights less than the head, then it becomes the new head. + + if (symbol.weight < head.weight) { + symbol.next = head; + head = symbol; + } else { + +// To save time, we will start the search from the previous symbol instead +// of the head unless the current symbol weights less than the previous symbol. + + if (symbol.weight < previous.weight) { + previous = head; + } + +// Find a connected pair (previous and next) where the symbol weighs the same +// or more than previous but less than the next. Link the symbol between them. + + while (true) { + next = previous.next; + if (next == null || symbol.weight < next.weight) { + break; + } + previous = next; + } + symbol.next = next; + previous.next = symbol; + previous = symbol; + } + } + +// Phase Two: Make new symbols from the two lightest symbols until only one +// symbol remains. The final symbol becomes the root of the table binary tree. + + int avail = this.domain; + Symbol first; + Symbol second; + previous = head; + while (true) { + first = head; + second = first.next; + head = second.next; + symbol = this.symbols[avail]; + avail += 1; + symbol.weight = first.weight + second.weight; + symbol.zero = first; + symbol.one = second; + symbol.back = null; + first.back = symbol; + second.back = symbol; + if (head == null) { + break; + } + +// Insert the new symbol back into the sorted list. + + if (symbol.weight < head.weight) { + symbol.next = head; + head = symbol; + previous = head; + } else { + while (true) { + next = previous.next; + if (next == null || symbol.weight < next.weight) { + break; + } + previous = next; + } + symbol.next = next; + previous.next = symbol; + previous = symbol; + } + + } + +// The last remaining symbol is the root of the table. + + this.table = symbol; + this.upToDate = true; + } + } + + private boolean postMortem(int integer) { + int[] bits = new int[this.domain]; + Symbol symbol = this.symbols[integer]; + if (symbol.integer != integer) { + return false; + } + int i = 0; + while (true) { + Symbol back = symbol.back; + if (back == null) { + break; + } + if (back.zero == symbol) { + bits[i] = 0; + } else if (back.one == symbol) { + bits[i] = 1; + } else { + return false; + } + i += 1; + symbol = back; + } + if (symbol != this.table) { + return false; + } + this.width = 0; + symbol = this.table; + while (symbol.integer == none) { + i -= 1; + symbol = bits[i] != 0 ? symbol.one : symbol.zero; + } + return symbol.integer == integer && i == 0; + } + + /** + * Compare two Huffman tables. + */ + public boolean postMortem(PostMortem pm) { + +// Go through every integer in the domain, generating its bit sequence, and +// then proving that that bit sequence produces the same integer. + + for (int integer = 0; integer < this.domain; integer += 1) { + if (!postMortem(integer)) { + JSONzip.log("\nBad huff "); + JSONzip.logchar(integer, integer); + return false; + } + } + return this.table.postMortem(((Huff) pm).table); + } + + /** + * Read bits until a symbol can be identified. The weight of the read + * symbol will be incremented. + * + * @param bitreader + * The source of bits. + * @return The integer value of the symbol. + * @throws JSONException + */ + public int read(BitReader bitreader) throws JSONException { + try { + this.width = 0; + Symbol symbol = this.table; + while (symbol.integer == none) { + this.width += 1; + symbol = bitreader.bit() ? symbol.one : symbol.zero; + } + tick(symbol.integer); + if (JSONzip.probe) { + JSONzip.logchar(symbol.integer, this.width); + } + return symbol.integer; + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Increase by 1 the weight associated with a value. + * + * @param value + * The number of the symbol to tick + * @return this + */ + public void tick(int value) { + this.symbols[value].weight += 1; + this.upToDate = false; + } + + /** + * Increase by 1 the weight associated with a range of values. + * + * @param from + * The first symbol to tick + * @param to + * The last symbol to tick + * @return this + */ + public void tick(int from, int to) { + for (int value = from; value <= to; value += 1) { + tick(value); + } + } + + /** + * Recur from a symbol back, emitting bits. We recur before emitting to + * make the bits come out in the right order. + * + * @param symbol + * The symbol to write. + * @param bitwriter + * The bitwriter to write it to. + * @throws JSONException + */ + private void write(Symbol symbol, BitWriter bitwriter) + throws JSONException { + try { + Symbol back = symbol.back; + if (back != null) { + this.width += 1; + write(back, bitwriter); + if (back.zero == symbol) { + bitwriter.zero(); + } else { + bitwriter.one(); + } + } + } catch (Throwable e) { + throw new JSONException(e); + } + } + + /** + * Write the bits corresponding to a symbol. The weight of the symbol will + * be incremented. + * + * @param value + * The number of the symbol to write + * @param bitwriter + * The destination of the bits. + * @return this + * @throws JSONException + */ + public void write(int value, BitWriter bitwriter) throws JSONException { + this.width = 0; + write(this.symbols[value], bitwriter); + tick(value); + if (JSONzip.probe) { + JSONzip.logchar(value, this.width); + } + } +} diff --git a/eurilys4/src/java/jsonlib/zip/JSONzip.java b/eurilys4/src/java/jsonlib/zip/JSONzip.java new file mode 100644 index 00000000..2128742c --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/JSONzip.java @@ -0,0 +1,281 @@ +package org.json.zip; + + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * JSONzip is a binary-encoded JSON dialect. It is designed to compress the + * messages in a session. It is adaptive, so with each message seen, it should + * improve its compression. It minimizes JSON's overhead, reducing punctuation + * to a small number of bits. It uses Huffman encoding to reduce the average + * size of characters. It uses caches (or Keeps) to keep recently seen strings + * and values, so repetitive content (such as object keys) can be + * substantially reduced. It uses a character encoding called Kim (Keep it + * minimal) that is smaller than UTF-8 for most East European, African, and + * Asian scripts. + * + * JSONzip tends to reduce most content by about half. If there is a lot of + * recurring information, the reduction can be much more dramatic. + * + * FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT YET BEEN TESTED + * ADEQUATELY FOR PRODUCTION USE. + * + * @author JSON.org + * @version 2013-04-18 + */ +public abstract class JSONzip implements None, PostMortem { + /** + * Powers of 2. + */ + public static final int[] twos = { + 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, + 1024, 2048, 4096, 8192, 16384, 32768, 65536 + }; + + /** + * The characters in JSON numbers can be reduced to 4 bits each. + */ + public static final byte[] bcd = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-', '+', 'E' + }; + + /** + * The number of integers that can be encoded in 4 bits. + */ + public static final long int4 = 16; + + /** + * The number of integers that can be encoded in 7 bits. + */ + public static final long int7 = 128; + + /** + * The number of integers that can be encoded in 14 bits. + */ + public static final long int14 = 16384; + + /** + * The end of string code. + */ + public static final int end = 256; + + /** + * The end of number code. + */ + public static final int endOfNumber = bcd.length; + + /** + * The maximum substring length when registering many. The registration of + * one substring may be longer. + */ + public static final int maxSubstringLength = 10; + + /** + * The minimum substring length. + */ + public static final int minSubstringLength = 3; + + /** + * The package supports tracing for debugging. + */ + public static final boolean probe = false; + + /** + * The maximum number of substrings added to the substrings keep per + * string. + */ + public static final int substringLimit = 40; + + /** + * The value code for an empty object. + */ + public static final int zipEmptyObject = 0; + + /** + * The value code for an empty array. + */ + public static final int zipEmptyArray = 1; + + /** + * The value code for true. + */ + public static final int zipTrue = 2; + + /** + * The value code for false. + */ + public static final int zipFalse = 3; + + /** + * The value code for null. + */ + public static final int zipNull = 4; + + /** + * The value code for a non-empty object. + */ + public static final int zipObject = 5; + + /** + * The value code for an array with a string as its first element. + */ + public static final int zipArrayString = 6; + + /** + * The value code for an array with a non-string value as its first element. + */ + public static final int zipArrayValue = 7; + + /** + * A Huffman encoder for names. + */ + protected final Huff namehuff; + + /** + * A place to keep the names (keys). + */ + protected final MapKeep namekeep; + + /** + * A place to keep the strings. + */ + protected final MapKeep stringkeep; + + /** + * A Huffman encoder for string values. + */ + protected final Huff substringhuff; + + /** + * A place to keep the strings. + */ + protected final TrieKeep substringkeep; + + /** + * A place to keep the values. + */ + protected final MapKeep values; + + /** + * Initialize the data structures. + */ + protected JSONzip() { + this.namehuff = new Huff(end + 1); + this.namekeep = new MapKeep(9); + this.stringkeep = new MapKeep(11); + this.substringhuff = new Huff(end + 1); + this.substringkeep = new TrieKeep(12); + this.values = new MapKeep(10); + +// Increase the weights of the ASCII letters, digits, and special characters +// because they are highly likely to occur more frequently. The weight of each +// character will increase as it is used. The Huffman encoder will tend to +// use fewer bits to encode heavier characters. + + this.namehuff.tick(' ', '}'); + this.namehuff.tick('a', 'z'); + this.namehuff.tick(end); + this.namehuff.tick(end); + this.substringhuff.tick(' ', '}'); + this.substringhuff.tick('a', 'z'); + this.substringhuff.tick(end); + this.substringhuff.tick(end); + } + + /** + * + */ + protected void begin() { + this.namehuff.generate(); + this.substringhuff.generate(); + } + + /** + * Write an end-of-line to the console. + */ + static void log() { + log("\n"); + } + + /** + * Write an integer to the console. + * + * @param integer + */ + static void log(int integer) { + log(integer + " "); + } + + /** + * Write two integers, separated by ':' to the console. + * + * @param integer + * @param width + */ + static void log(int integer, int width) { + log(integer + ":" + width + " "); + } + + /** + * Write a string to the console. + * + * @param string + */ + static void log(String string) { + System.out.print(string); + } + + /** + * Write a character or its code to the console. + * + * @param integer + * @param width + */ + static void logchar(int integer, int width) { + if (integer > ' ' && integer <= '}') { + log("'" + (char) integer + "':" + width + " "); + } else { + log(integer, width); + } + } + + /** + * This method is used for testing the implementation of JSONzip. It is not + * suitable for any other purpose. It is used to compare a Compressor and a + * Decompressor, verifying that the data structures that were built during + * zipping and unzipping were the same. + * + * @return true if the structures match. + */ + public boolean postMortem(PostMortem pm) { + JSONzip that = (JSONzip) pm; + return this.namehuff.postMortem(that.namehuff) + && this.namekeep.postMortem(that.namekeep) + && this.stringkeep.postMortem(that.stringkeep) + && this.substringhuff.postMortem(that.substringhuff) + && this.substringkeep.postMortem(that.substringkeep) + && this.values.postMortem(that.values); + } +} diff --git a/eurilys4/src/java/jsonlib/zip/Keep.java b/eurilys4/src/java/jsonlib/zip/Keep.java new file mode 100644 index 00000000..377e344e --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/Keep.java @@ -0,0 +1,84 @@ +package org.json.zip; + + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * A keep is a data structure that associates strings (or substrings) with + * numbers. This allows the sending of small integers instead of strings. + * + * @author JSON.org + * @version 2013-04-18 + */ +abstract class Keep implements None, PostMortem { + protected int capacity; + protected int length; + protected int power; + protected long[] uses; + + public Keep(int bits) { + this.capacity = JSONzip.twos[bits]; + this.length = 0; + this.power = 0; + this.uses = new long[this.capacity]; + } + + /** + * When an item ages, its use count is reduced by at least half. + * + * @param use + * The current use count of an item. + * @return The new use count for that item. + */ + public static long age(long use) { + return use >= 32 ? 16 : use / 2; + } + + /** + * Return the number of bits required to contain an integer based on the + * current length of the keep. As the keep fills up, the number of bits + * required to identify one of its items goes up. + */ + public int bitsize() { + while (JSONzip.twos[this.power] < this.length) { + this.power += 1; + } + return this.power; + } + + /** + * Increase the usage count on an integer value. + */ + public void tick(int integer) { + this.uses[integer] += 1; + } + + /** + * Get the value associated with an integer. + * @param integer The number of an item in the keep. + * @return The value. + */ + abstract public Object value(int integer); +} diff --git a/eurilys4/src/java/jsonlib/zip/MapKeep.java b/eurilys4/src/java/jsonlib/zip/MapKeep.java new file mode 100644 index 00000000..1374e08d --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/MapKeep.java @@ -0,0 +1,160 @@ +package org.json.zip; + +import java.util.HashMap; + +import org.json.Kim; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * A keep is an associative data structure that maintains usage counts of each + * of the associations in its keeping. When the keep becomes full, it purges + * little used associations, and ages the survivors. Each key is assigned an + * integer value. When the keep is compacted, each key can be given a new + * value. + */ +class MapKeep extends Keep { + private Object[] list; + private HashMap map; + + /** + * Create a new Keep. + * @param bits + * The capacity of the keep expressed in the number of bits + * required to hold an integer. + */ + public MapKeep(int bits) { + super(bits); + this.list = new Object[this.capacity]; + this.map = new HashMap(this.capacity); + } + + /** + * Compact the keep. A keep may contain at most this.capacity elements. + * The keep contents can be reduced by deleting all elements with low use + * counts, and by reducing the use counts of the survivors. + */ + private void compact() { + int from = 0; + int to = 0; + while (from < this.capacity) { + Object key = this.list[from]; + long usage = age(this.uses[from]); + if (usage > 0) { + this.uses[to] = usage; + this.list[to] = key; + this.map.put(key, new Integer(to)); + to += 1; + } else { + this.map.remove(key); + } + from += 1; + } + if (to < this.capacity) { + this.length = to; + } else { + this.map.clear(); + this.length = 0; + } + this.power = 0; + } + + /** + * Find the integer value associated with this key, or nothing if this key + * is not in the keep. + * + * @param key + * An object. + * @return An integer + */ + public int find(Object key) { + Object o = this.map.get(key); + return o instanceof Integer ? ((Integer) o).intValue() : none; + } + + public boolean postMortem(PostMortem pm) { + MapKeep that = (MapKeep) pm; + if (this.length != that.length) { + JSONzip.log(this.length + " <> " + that.length); + return false; + } + for (int i = 0; i < this.length; i += 1) { + boolean b; + if (this.list[i] instanceof Kim) { + b = ((Kim) this.list[i]).equals(that.list[i]); + } else { + Object o = this.list[i]; + Object q = that.list[i]; + if (o instanceof Number) { + o = o.toString(); + } + if (q instanceof Number) { + q = q.toString(); + } + b = o.equals(q); + } + if (!b) { + JSONzip.log("\n[" + i + "]\n " + this.list[i] + "\n " + + that.list[i] + "\n " + this.uses[i] + "\n " + + that.uses[i]); + return false; + } + } + return true; + } + + /** + * Register a value in the keep. Compact the keep if it is full. The next + * time this value is encountered, its integer can be sent instead. + * @param value A value. + */ + public void register(Object value) { + if (JSONzip.probe) { + int integer = find(value); + if (integer >= 0) { + JSONzip.log("\nDuplicate key " + value); + } + } + if (this.length >= this.capacity) { + compact(); + } + this.list[this.length] = value; + this.map.put(value, new Integer(this.length)); + this.uses[this.length] = 1; + if (JSONzip.probe) { + JSONzip.log("<" + this.length + " " + value + "> "); + } + this.length += 1; + } + + /** + * Return the value associated with the integer. + * @param integer The number of an item in the keep. + * @return The value. + */ + public Object value(int integer) { + return this.list[integer]; + } +} diff --git a/eurilys4/src/java/jsonlib/zip/None.java b/eurilys4/src/java/jsonlib/zip/None.java new file mode 100644 index 00000000..818e68d8 --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/None.java @@ -0,0 +1,15 @@ +package org.json.zip; + +/** + * None is an interface that makes the constant none (short for + * negative one or long for -1) available to any class that implements it. + * The none value is used to stand for an integer that is not an integer, + * such as the negative result of a search. + */ +public interface None { + /** + * Negative One. + */ + public static final int none = -1; + +} diff --git a/eurilys4/src/java/jsonlib/zip/PostMortem.java b/eurilys4/src/java/jsonlib/zip/PostMortem.java new file mode 100644 index 00000000..22416d70 --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/PostMortem.java @@ -0,0 +1,47 @@ +package org.json.zip; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * The PostMortem interface allows for testing the internal state of JSONzip + * processors. Testing that JSONzip can compress an object and reproduce a + * corresponding object is not sufficient. Complete testing requires that the + * same internal data structures were constructed on both ends. If those + * structures are not equivalent, then it is likely that the implementations + * are not correct, even if convention tests are passed. + * + * PostMortem allows for testing of deep structures without breaking + * encapsulation. + */ +public interface PostMortem { + /** + * Determine if two objects are equivalent. + * + * @param pm + * Another object of the same type. + * @return true if they match. + */ + public boolean postMortem(PostMortem pm); +} diff --git a/eurilys4/src/java/jsonlib/zip/README b/eurilys4/src/java/jsonlib/zip/README new file mode 100644 index 00000000..93e6470b --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/README @@ -0,0 +1,2 @@ +FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT BEEN TESTED ADEQUATELY FOR +PRODUCTION USE. diff --git a/eurilys4/src/java/jsonlib/zip/TrieKeep.java b/eurilys4/src/java/jsonlib/zip/TrieKeep.java new file mode 100644 index 00000000..dcb13c7a --- /dev/null +++ b/eurilys4/src/java/jsonlib/zip/TrieKeep.java @@ -0,0 +1,396 @@ +package org.json.zip; + +import org.json.Kim; + +/* + Copyright (c) 2013 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/** + * A TrieKeep is a Keep that implements a Trie. + */ +class TrieKeep extends Keep { + + /** + * The trie is made of nodes. + */ + class Node implements PostMortem { + private int integer; + private Node[] next; + + /** + * Each non-leaf node contains links to up to 256 next nodes. Each node + * has an integer value. + */ + public Node() { + this.integer = none; + this.next = null; + } + + /** + * Get one of a node's 256 links. If it is a leaf node, it returns + * null. + * + * @param cell + * A integer between 0 and 255. + * @return + */ + public Node get(int cell) { + return this.next == null ? null : this.next[cell]; + } + + /** + * Get one of a node's 256 links. If it is a leap node, it returns + * null. The argument is treated as an unsigned integer. + * + * @param cell + * A byte. + * @return + */ + public Node get(byte cell) { + return get(((int) cell) & 0xFF); + } + + /** + * Compare two nodes. Their lengths must be equal. Their links must + * also compare. + */ + public boolean postMortem(PostMortem pm) { + Node that = (Node) pm; + if (that == null) { + JSONzip.log("\nMisalign"); + return false; + } + if (this.integer != that.integer) { + JSONzip.log("\nInteger " + this.integer + " <> " + + that.integer); + return false; + } + if (this.next == null) { + if (that.next == null) { + return true; + } + JSONzip.log("\nNext is null " + this.integer); + return false; + } + for (int i = 0; i < 256; i += 1) { + Node node = this.next[i]; + if (node != null) { + if (!node.postMortem(that.next[i])) { + return false; + } + } else if (that.next[i] != null) { + JSONzip.log("\nMisalign " + i); + return false; + } + } + return true; + } + + /** + * Set a node's link to another node. + * + * @param cell + * An integer between 0 and 255. + * @param node + * The new value for the cell. + */ + public void set(int cell, Node node) { + if (this.next == null) { + this.next = new Node[256]; + } + if (JSONzip.probe) { + if (node == null || this.next[cell] != null) { + JSONzip.log("\nUnexpected set.\n"); + } + } + this.next[cell] = node; + } + + /** + * Set a node's link to another node. + * + * @param cell + * A byte. + * @param node + * The new value for the cell. + */ + public void set(byte cell, Node node) { + set(((int) cell) & 0xFF, node); + } + + /** + * Get one of a node's 256 links. It will not return null. If there is + * no link, then a link is manufactured. + * + * @param cell + * A integer between 0 and 255. + * @return + */ + public Node vet(int cell) { + Node node = get(cell); + if (node == null) { + node = new Node(); + set(cell, node); + } + return node; + } + + /** + * Get one of a node's 256 links. It will not return null. If there is + * no link, then a link is manufactured. + * + * @param cell + * A byte. + * @return + */ + public Node vet(byte cell) { + return vet(((int) cell) & 0xFF); + } + } + + private int[] froms; + private int[] thrus; + private Node root; + private Kim[] kims; + + /** + * Create a new Keep of kims. + * + * @param bits + * The log2 of the capacity of the Keep. For example, if bits is + * 12, then the keep's capacity will be 4096. + */ + public TrieKeep(int bits) { + super(bits); + this.froms = new int[this.capacity]; + this.thrus = new int[this.capacity]; + this.kims = new Kim[this.capacity]; + this.root = new Node(); + } + + /** + * Get the kim associated with an integer. + * + * @param integer + * @return + */ + public Kim kim(int integer) { + Kim kim = this.kims[integer]; + int from = this.froms[integer]; + int thru = this.thrus[integer]; + if (from != 0 || thru != kim.length) { + kim = new Kim(kim, from, thru); + this.froms[integer] = 0; + this.thrus[integer] = kim.length; + this.kims[integer] = kim; + } + return kim; + } + + /** + * Get the length of the Kim associated with an integer. This is sometimes + * much faster than get(integer).length. + * + * @param integer + * @return + */ + public int length(int integer) { + return this.thrus[integer] - this.froms[integer]; + } + + /** + * Find the integer value associated with this key, or nothing if this key + * is not in the keep. + * + * @param key + * An object. + * @return An integer + */ + public int match(Kim kim, int from, int thru) { + Node node = this.root; + int best = none; + for (int at = from; at < thru; at += 1) { + node = node.get(kim.get(at)); + if (node == null) { + break; + } + if (node.integer != none) { + best = node.integer; + } + from += 1; + } + return best; + } + + public boolean postMortem(PostMortem pm) { + boolean result = true; + TrieKeep that = (TrieKeep) pm; + if (this.length != that.length) { + JSONzip.log("\nLength " + this.length + " <> " + that.length); + return false; + } + if (this.capacity != that.capacity) { + JSONzip.log("\nCapacity " + this.capacity + " <> " + + that.capacity); + return false; + } + for (int i = 0; i < this.length; i += 1) { + Kim thiskim = this.kim(i); + Kim thatkim = that.kim(i); + if (!thiskim.equals(thatkim)) { + JSONzip.log("\n[" + i + "] " + thiskim + " <> " + thatkim); + result = false; + } + } + return result && this.root.postMortem(that.root); + } + + public void registerMany(Kim kim) { + int length = kim.length; + int limit = this.capacity - this.length; + if (limit > JSONzip.substringLimit) { + limit = JSONzip.substringLimit; + } + int until = length - (JSONzip.minSubstringLength - 1); + for (int from = 0; from < until; from += 1) { + int len = length - from; + if (len > JSONzip.maxSubstringLength) { + len = JSONzip.maxSubstringLength; + } + len += from; + Node node = this.root; + for (int at = from; at < len; at += 1) { + Node next = node.vet(kim.get(at)); + if (next.integer == none + && at - from >= (JSONzip.minSubstringLength - 1)) { + next.integer = this.length; + this.uses[this.length] = 1; + this.kims[this.length] = kim; + this.froms[this.length] = from; + this.thrus[this.length] = at + 1; + if (JSONzip.probe) { + try { + JSONzip.log("<<" + this.length + " " + + new Kim(kim, from, at + 1) + ">> "); + } catch (Throwable ignore) { + } + } + this.length += 1; + limit -= 1; + if (limit <= 0) { + return; + } + } + node = next; + } + } + } + + public void registerOne(Kim kim) { + int integer = registerOne(kim, 0, kim.length); + if (integer != none) { + this.kims[integer] = kim; + } + } + + public int registerOne(Kim kim, int from, int thru) { + if (this.length < this.capacity) { + Node node = this.root; + for (int at = from; at < thru; at += 1) { + node = node.vet(kim.get(at)); + } + if (node.integer == none) { + int integer = this.length; + node.integer = integer; + this.uses[integer] = 1; + this.kims[integer] = kim; + this.froms[integer] = from; + this.thrus[integer] = thru; + if (JSONzip.probe) { + try { + JSONzip.log("<<" + integer + " " + new Kim(kim, from, thru) + ">> "); + } catch (Throwable ignore) { + } + } + this.length += 1; + return integer; + } + } + return none; + } + + /** + * Reserve space in the keep, compacting if necessary. A keep may contain + * at most -capacity- elements. The keep contents can be reduced by + * deleting all elements with low use counts, rebuilding the trie with the + * survivors. + */ + public void reserve() { + if (this.capacity - this.length < JSONzip.substringLimit) { + int from = 0; + int to = 0; + this.root = new Node(); + while (from < this.capacity) { + if (this.uses[from] > 1) { + Kim kim = this.kims[from]; + int thru = this.thrus[from]; + Node node = this.root; + for (int at = this.froms[from]; at < thru; at += 1) { + Node next = node.vet(kim.get(at)); + node = next; + } + node.integer = to; + this.uses[to] = age(this.uses[from]); + this.froms[to] = this.froms[from]; + this.thrus[to] = thru; + this.kims[to] = kim; + to += 1; + } + from += 1; + } + +// It is possible, but highly unlikely, that too many items survive. +// If that happens, clear the keep. + + if (this.capacity - to < JSONzip.substringLimit) { + this.power = 0; + this.root = new Node(); + to = 0; + } + this.length = to; + while (to < this.capacity) { + this.uses[to] = 0; + this.kims[to] = null; + this.froms[to] = 0; + this.thrus[to] = 0; + to += 1; + + } + } + } + + public Object value(int integer) { + return kim(integer); + } +} diff --git a/eurilys4/src/java/service/CategoryService.java b/eurilys4/src/java/service/CategoryService.java new file mode 100644 index 00000000..b2afd76c --- /dev/null +++ b/eurilys4/src/java/service/CategoryService.java @@ -0,0 +1,156 @@ +package service; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.json.*; + +/* + * CategoryService memiliki URL : baseURL/category + * CategoryService merupakan sebuah service class yang menangani : + * - get_list - done + * - delete - done + */ + +@WebServlet(name = "CategoryService", urlPatterns = {"/category/*"}) +public class CategoryService extends HttpServlet { + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + String pathInfo = request.getPathInfo(); + dbConnection connector = new dbConnection(); + Connection conn = null; + + /* + * pathInfo : baseURL/category/get_list + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + if (pathInfo.equals("/get_list")) { + try { + + //HttpSession session = request.getSession(true); + //String username = (String) session.getAttribute("username"); + + String username = request.getParameter("username"); + + JSONArray categoryArray = new JSONArray(); + conn = connector.getConnection (); + + /* Search Category by Creator */ + PreparedStatement stmt = conn.prepareStatement("SELECT * FROM category WHERE cat_creator=?;"); + stmt.setString(1, username); + ResultSet rs = stmt.executeQuery(); + + //Result set is not empty + rs.beforeFirst(); + while (rs.next()) { + JSONObject categoryObject = new JSONObject(); + categoryObject.put("category_creator", username); + categoryObject.put("category_id", rs.getString("cat_id")); + categoryObject.put("category_name", rs.getString("cat_name")); + categoryArray.put(categoryObject); + } + + /* Search Category by Assignee */ + stmt = conn.prepareStatement("SELECT cat_id FROM cat_asignee WHERE username =?;"); + stmt.setString(1, username); + rs = stmt.executeQuery(); + rs.beforeFirst(); + String categoryId = ""; + while (rs.next()) { + categoryId = rs.getString("cat_id"); + PreparedStatement stmt2 = conn.prepareStatement("SELECT * FROM category WHERE cat_id =?;"); + stmt2.setString(1, categoryId); + ResultSet rs2 = stmt2.executeQuery(); + rs2.beforeFirst(); + while (rs2.next()) { + JSONObject categoryObject = new JSONObject(); + categoryObject.put("category_creator", rs2.getString("cat_creator")); + categoryObject.put("category_id", categoryId); + categoryObject.put("category_name", rs2.getString("cat_name")); + categoryArray.put(categoryObject); + } + } + out.println(categoryArray); + + } catch (SQLException ex) { + Logger.getLogger(CategoryService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(CategoryService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/category/delete + * requestParameter : category_id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete")) { + try { + String category_id = request.getParameter("category_id"); + conn = connector.getConnection (); + PreparedStatement st = conn.prepareStatement("DELETE FROM category WHERE cat_id=?"); + st.setString(1, category_id); + int row = st.executeUpdate(); + out.println(row); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + // + /** + * Handles the HTTP + * GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// +} diff --git a/eurilys4/src/java/service/SearchService.java b/eurilys4/src/java/service/SearchService.java new file mode 100644 index 00000000..c26d8e64 --- /dev/null +++ b/eurilys4/src/java/service/SearchService.java @@ -0,0 +1,217 @@ +package service; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.json.*; + +public class SearchService extends HttpServlet { + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + String pathInfo = request.getPathInfo(); + dbConnection connector = new dbConnection(); + Connection conn = null; + + /* + * pathInfo : baseURL/search/result + * requestParameter : keyword=&filter= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + if (pathInfo.equals("/result")) { + try { + String keyword = request.getParameter("keyword"); + String filter = request.getParameter("filter"); + conn = connector.getConnection (); + PreparedStatement stmt = conn.prepareStatement(""); + ResultSet rs = null; + String HTMLresult = ""; + + if (filter.equals("1")) { //Search All + //Search User + stmt = conn.prepareStatement("SELECT distinct full_name, username FROM user WHERE username LIKE ? OR email LIKE ? OR full_name LIKE ? OR birthdate LIKE ?;"); + stmt.setString(1, "%" + keyword + "%"); //username + stmt.setString(2, "%" + keyword + "%"); //email + stmt.setString(3, "%" + keyword + "%"); //full_name + stmt.setString(4, "%" + keyword + "%"); //birthdate + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "
    "; + } + HTMLresult += "
    "+ rs.getString("full_name") +"
    "; + } + + //Search Category + stmt = conn.prepareStatement("SELECT distinct cat_id, cat_name FROM category WHERE cat_name LIKE ?;"); + stmt.setString(1, "%" + keyword + "%"); //category_name + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "
    "; + } + HTMLresult += "
    "+ rs.getString("cat_name") +"
    "; + } + + //Search Task + stmt = conn.prepareStatement("SELECT DISTINCT task_name, task.task_id FROM ((task LEFT JOIN tag ON task.task_id = tag.task_id) LEFT JOIN comment ON task.task_id = comment.task_id) WHERE task_name LIKE ? OR tag_name LIKE ? OR comment_content LIKE ?"); + stmt.setString(1, "%" + keyword + "%"); //task_name + stmt.setString(2, "%" + keyword + "%"); //tag_name + stmt.setString(3, "%" + keyword + "%"); //comment_content + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "
    "; + } + HTMLresult += "
    "+ rs.getString("task_name") +"
    "; + } + } + else if (filter.equals("2")) { //Search User (username, email, nama lengkap, birthdate) + stmt = conn.prepareStatement("SELECT distinct full_name, username FROM user WHERE username LIKE ? OR email LIKE ? OR full_name LIKE ? OR birthdate LIKE ?;"); + stmt.setString(1, "%" + keyword + "%"); //username + stmt.setString(2, "%" + keyword + "%"); //email + stmt.setString(3, "%" + keyword + "%"); //full_name + stmt.setString(4, "%" + keyword + "%"); //birthdate + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "
    "; + } + HTMLresult += "
    "+ rs.getString("full_name") +"
    "; + } + } + else if (filter.equals("3")) { //Search Category + stmt = conn.prepareStatement("SELECT distinct cat_id, cat_name FROM category WHERE cat_name LIKE ?;"); + stmt.setString(1, "%" + keyword + "%"); //category_name + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "
    "; + } + HTMLresult += "
    "+ rs.getString("cat_name") +"
    "; + } + } + else if (filter.equals("4")) { //Search Task (task name, tag, comment) + stmt = conn.prepareStatement("SELECT DISTINCT task_name, task.task_id FROM ((task LEFT JOIN tag ON task.task_id = tag.task_id) LEFT JOIN comment ON task.task_id = comment.task_id) WHERE task_name LIKE ? OR tag_name LIKE ? OR comment_content LIKE ?"); + stmt.setString(1, "%" + keyword + "%"); //task_name + stmt.setString(2, "%" + keyword + "%"); //tag_name + stmt.setString(3, "%" + keyword + "%"); //comment_content + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + if (!("".equals(HTMLresult))) { + HTMLresult += "
    "; + } + HTMLresult += "
    "+ rs.getString("task_name") +"
    "; + } + } + out.println(HTMLresult); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + + /* + * pathInfo : baseURL/search/category + * requestParameter : id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/category")) { + try { + String id = request.getParameter("id"); + conn = connector.getConnection (); + PreparedStatement stmt = conn.prepareStatement(""); + ResultSet rs = null; + JSONObject catResult = new JSONObject(); + + //Search Category + stmt = conn.prepareStatement("SELECT * FROM category WHERE cat_id=?"); + stmt.setString(1, id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + String cat_name = ""; + while (rs.next()) { + cat_name = rs.getString("cat_name"); + catResult.put("cat_name", rs.getString("cat_name")); + catResult.put("cat_creator", rs.getString("cat_creator")); + } + + //Search corresponding task + stmt = conn.prepareStatement("SELECT task_name, task_id FROM task WHERE cat_name=?"); + stmt.setString(1, cat_name); + rs = stmt.executeQuery(); + rs.beforeFirst(); + JSONArray taskList = new JSONArray(); + while (rs.next()) { + taskList.put(rs.getString("task_name")); + } + catResult.put("task", taskList); + + out.println(catResult); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + // + /** + * Handles the HTTP + * GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// +} diff --git a/eurilys4/src/java/service/TaskService.java b/eurilys4/src/java/service/TaskService.java new file mode 100644 index 00000000..e2946e4a --- /dev/null +++ b/eurilys4/src/java/service/TaskService.java @@ -0,0 +1,445 @@ +package service; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.json.*; + +/* + * TaskService memiliki URL : baseURL/task + * TaskService merupakan sebuah service class yang menangani : + * - task_detail - done + * - update_task - done + * - delete_comment - done + * - delete_tag - done + * - delete_assignee - done + * - get_category_task (get list of task based on category name) - done + * - finish_task - done + * - delete_task - done + */ +public class TaskService extends HttpServlet { + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + String pathInfo = request.getPathInfo(); + dbConnection connector = new dbConnection(); + Connection conn = null; + + /* + * pathInfo : baseURL/task/task_detail + * requestParameter : task_id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + if (pathInfo.equals("/task_detail")) { + try { + String task_id = request.getParameter("task_id"); + conn = connector.getConnection (); + PreparedStatement stmt = conn.prepareStatement(""); + ResultSet rs = null; + + //Get Tag List + List tagList = new ArrayList(); + stmt = conn.prepareStatement("SELECT * from tag WHERE task_id=?"); + stmt.setString(1, task_id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + tagList.add(rs.getString("tag_name")); + } + + //Get Comment List + List commentContent = new ArrayList(); + List commentID = new ArrayList(); + List commentCreator = new ArrayList(); + List commentTimestamp = new ArrayList(); + stmt = conn.prepareStatement("SELECT comment_id, comment_content, comment_creator, comment_timestamp from comment WHERE task_id=?"); + stmt.setString(1, task_id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + commentID.add(rs.getString("comment_id")); + commentContent.add(rs.getString("comment_content")); + commentCreator.add(rs.getString("comment_creator")); + commentTimestamp.add(rs.getString("comment_timestamp")); + } + + //Get Assignee List + List assignee = new ArrayList(); + stmt = conn.prepareStatement("SELECT username from task_asignee WHERE task_id=?"); + stmt.setString(1, task_id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + assignee.add(rs.getString("username")); + } + + //Get task detail + JSONObject taskObject = new JSONObject(); + stmt = conn.prepareStatement("SELECT * FROM task WHERE task_id=?"); + stmt.setString(1, task_id); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + String task_name = rs.getString(2); + String task_status = rs.getString(3); + String task_deadline = rs.getString(4); + String task_category = rs.getString(5); + String task_creator = rs.getString(6); + + taskObject.put("task_id", task_id); + taskObject.put("task_name", task_name); + taskObject.put("task_deadline", task_deadline); + taskObject.put("task_status", task_status); + taskObject.put("task_category", task_category); + taskObject.put("task_creator", task_creator); + taskObject.put("tag_list", tagList); + taskObject.put("comment_content", commentContent); + taskObject.put("comment_id", commentID); + taskObject.put("comment_creator", commentCreator); + taskObject.put("comment_timestamp", commentTimestamp); + taskObject.put("task_assignee", assignee); + } + out.println(taskObject); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/update_task + * requestParameter : edit_task_id=&edit_task_deadline=&edit_task_assignee=&edit_task_tag= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/update_task")) { + try { + String taskID = request.getParameter("edit_task_id"); + String deadline = request.getParameter("edit_task_deadline"); + String assigneeList = request.getParameter("edit_task_assignee"); + String tagList = request.getParameter("edit_task_tag"); + + conn = connector.getConnection (); + Statement stmt = conn.createStatement(); + + //Update task_asignee + String[] assigneArray = assigneeList.split(","); + for (int i = 0; i < assigneArray.length; i++) { + if (!("".equals(assigneArray[i]))) { + stmt.executeUpdate("INSERT INTO task_asignee (task_id, username) VALUES ('" + taskID + "','" + assigneArray[i] + "')"); + } + } + + //Update tag + String[] tagArray = tagList.split(","); + for (int i = 0; i < tagArray.length; i++) { + if (!("".equals(tagArray[i]))) { + stmt.executeUpdate("INSERT INTO tag (tag_name, task_id) VALUES ('" + tagArray[i] + "','" + taskID + "')"); + } + } + + //Update task + stmt.executeUpdate("UPDATE task SET task_deadline='" + deadline + "' WHERE task_id='" + taskID + "'"); + + out.println("task updated"); + + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * HTTP Method : GET + * pathInfo : baseURL/task/delete_comment + * requestParameter : comment_id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete_comment")) { + try { + String comment_id = request.getParameter("comment_id"); + conn = connector.getConnection (); + ResultSet rs = null; + PreparedStatement st; + st = conn.prepareStatement("DELETE FROM comment WHERE comment_id=?"); + st.setString(1, comment_id); + int row = st.executeUpdate(); + out.println(row); //row = 1 berhasil, row = 0 gagal + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/delete_tag + * requestParameter : tag_name=&task_id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete_tag")) { + try { + String tag_name = request.getParameter("tag_name"); + String task_id = request.getParameter("task_id"); + conn = connector.getConnection (); + ResultSet rs = null; + PreparedStatement st; + st = conn.prepareStatement("DELETE FROM tag WHERE tag_name=? AND task_id=?"); + st.setString(1, tag_name); + st.setString(2, task_id); + st.executeUpdate(); + out.println("Tag " + tag_name + " from Task " + task_id + " has been deleted"); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/delete_assignee + * requestParameter : task_id=&username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete_assignee")) { + //task_asignee + try { + String task_id = request.getParameter("task_id"); + String username = request.getParameter("username"); + conn = connector.getConnection (); + ResultSet rs = null; + PreparedStatement st; + st = conn.prepareStatement("DELETE FROM task_asignee WHERE task_id=? AND username=?"); + st.setString(1, task_id); + st.setString(2, username); + st.executeUpdate(); + out.println("Assignee " + username + " from Task " + task_id + " has been deleted"); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/get_category_task + * requestParameter : category_name= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/get_category_task")) { + try { + String category_name = request.getParameter("category_name"); + JSONArray taskArray = new JSONArray(); + List tagList = new ArrayList(); + conn = connector.getConnection (); + + //Get task detail + PreparedStatement stmt = conn.prepareStatement("SELECT * FROM task WHERE cat_name=?"); + stmt.setString(1, category_name); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + + String task_id = ""; + String task_name = ""; + String task_status = ""; + String task_deadline = ""; + String task_creator = ""; + + while (rs.next()) { + JSONObject taskObject = new JSONObject(); + + task_id = rs.getString(1); + task_name = rs.getString(2); + task_status = rs.getString(3); + task_deadline = rs.getString(4); + task_creator = rs.getString(6); + + //Get Tag List + stmt = conn.prepareStatement("SELECT * from tag WHERE task_id=?"); + stmt.setString(1, task_id); + ResultSet rs_tag = stmt.executeQuery(); + rs_tag.beforeFirst(); + tagList.clear(); + while (rs_tag.next()) { + tagList.add(rs_tag.getString("tag_name")); + } + taskObject.put("task_id", task_id); + taskObject.put("task_name", task_name); + taskObject.put("task_status", task_status); + taskObject.put("task_deadline", task_deadline); + taskObject.put("task_category", category_name); + taskObject.put("task_creator", task_creator); + taskObject.put("tag_list", tagList); + + taskArray.put(taskObject); + } + out.println(taskArray); + } + catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/all_task + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/all_task")) { + try { + String username = request.getParameter("username"); + JSONArray taskArray = new JSONArray(); + List tagList = new ArrayList(); + conn = connector.getConnection (); + + //Get task detail + PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT task.* FROM task INNER JOIN task_asignee WHERE task.task_creator=? OR task_asignee.username=?;"); + stmt.setString(1, username); + stmt.setString(2, username); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + + String task_id = ""; + String task_name = ""; + String task_status = ""; + String task_deadline = ""; + String task_category = ""; + String task_creator = ""; + + while (rs.next()) { + JSONObject taskObject = new JSONObject(); + task_id = rs.getString(1); + task_name = rs.getString(2); + task_status = rs.getString(3); + task_deadline = rs.getString(4); + task_category = rs.getString(5); + task_creator = rs.getString(6); + + //Get Tag List + stmt = conn.prepareStatement("SELECT * from tag WHERE task_id=?"); + stmt.setString(1, task_id); + ResultSet rs_tag = stmt.executeQuery(); + rs_tag.beforeFirst(); + tagList.clear(); + while (rs_tag.next()) { + tagList.add(rs_tag.getString("tag_name")); + } + + taskObject.put("task_id", task_id); + taskObject.put("task_name", task_name); + taskObject.put("task_status", task_status); + taskObject.put("task_deadline", task_deadline); + taskObject.put("task_category", task_category); + taskObject.put("task_creator", task_creator); + taskObject.put("tag_list", tagList); + + taskArray.put(taskObject); + } + out.println(taskArray); + } + catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/finish_task + * requestParameter : task_id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/finish_task")) { + try { + conn = connector.getConnection (); + Statement stmt = conn.createStatement(); + String taskID = request.getParameter("task_id"); + //Update task status + int updated_row = stmt.executeUpdate("UPDATE task SET task_status=1 WHERE task_id='" + taskID + "'"); + out.println(updated_row); //return 1, berarti berhasil. 0 berarti gagal + } + catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/task/delete_task + * requestParameter : task_id= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/delete_task")) { + try { + String task_id = request.getParameter("task_id"); + conn = connector.getConnection (); + PreparedStatement st = conn.prepareStatement("DELETE FROM task WHERE task_id=?"); + st.setString(1, task_id); + int row = st.executeUpdate(); + out.println(row); //row = 1 berhasil, row = 0 gagal + } catch (SQLException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(TaskService.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + // + /** + * Handles the HTTP + * GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// +} diff --git a/eurilys4/src/java/service/UserService.java b/eurilys4/src/java/service/UserService.java new file mode 100644 index 00000000..d936784f --- /dev/null +++ b/eurilys4/src/java/service/UserService.java @@ -0,0 +1,302 @@ +package service; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import org.json.*; + +/* + * UserService memiliki URL : baseURL/user + * UserService merupakan sebuah service class yang menangani : + * - login_check + * - register + * - user_detail + * - update_profile + * - current_task + * - finished_task + */ + +public class UserService extends HttpServlet { + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + String pathInfo = request.getPathInfo(); + dbConnection connector = new dbConnection(); + Connection conn = null; + + /* + * pathInfo : baseURL/user/login_check + * requestParameter : login_username=&login_password= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + if (pathInfo.equals("/login_check")) { + try { + String username = request.getParameter("login_username"); + String password = request.getParameter("login_password"); + + conn = connector.getConnection (); + + PreparedStatement stmt = conn.prepareStatement("SELECT username, full_name FROM user WHERE username=? AND password=?;"); + stmt.setString(1, username); + stmt.setString(2, password); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + + String fullname = ""; + while (rs.next()) { + fullname = rs.getString(2); + } + + if (!fullname.equals("")) { + out.println(fullname); + } + else { + out.println("failed"); + } + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/user/register + * requestParameter : signup_username=&signup_password=&signup_long_name=&signup_email=&signup_birth_date=signup_avatar_upload= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/register")) { + try { + String username = request.getParameter("signup_username"); + String password = request.getParameter("signup_password"); + String fullname = request.getParameter("signup_long_name"); + String email = request.getParameter("signup_email"); + String birthdate = request.getParameter("signup_birth_date"); + //Blob avatar = req.getParameter("signup_avatar_upload"); + + conn = connector.getConnection (); + Statement st = conn.createStatement(); + st.executeUpdate("INSERT INTO user VALUES ('" + username + "','" + password + "','" + fullname + "','" + birthdate + "','NULL','" + email + "')"); + + if (conn != null) { + //Berhasil register + HttpSession session = request.getSession(true); + session.setAttribute("username", username); + session.setAttribute("fullname", fullname); + response.sendRedirect("../src/dashboard.jsp"); + } else { + //Gagal register + response.sendRedirect("../index.jsp?register_status=failed"); + } + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/user/user_detail + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/user_detail")) { + try { + String username = request.getParameter("username"); + conn = connector.getConnection (); + + PreparedStatement stmt = conn.prepareStatement("SELECT * FROM user WHERE username=?;"); + stmt.setString(1, username); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + + while (rs.next()) { + String password = rs.getString(2); + String fullname = rs.getString(3); + String birthdate = rs.getString(4); + String avatar = rs.getString(5); + String email = rs.getString(6); + + JSONObject userObject = new JSONObject(); + userObject.put("username", username); + userObject.put("password", password); + userObject.put("fullname", fullname); + userObject.put("birthdate", birthdate); + userObject.put("avatar", avatar); + userObject.put("email", email); + out.println(userObject); + } + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/user/update_profile + * requestParameter : username=&password=&fullname=&birthdate=&avatar= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/update_profile")) { + try { + String username = request.getParameter("edit_username"); + String password = request.getParameter("password"); + String fullname = request.getParameter("fullname"); + String birthdate = request.getParameter("birthdate"); + String avatar = request.getParameter("avatar"); + + conn = connector.getConnection(); + + PreparedStatement stmt = conn.prepareStatement("SELECT password FROM user WHERE username=?;"); + stmt.setString(1, username); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + String oldpassword = ""; + while (rs.next()) { + oldpassword = rs.getString(1); + } + + Statement st = conn.createStatement(); + if (!("".equals(password))) { + st.executeUpdate("UPDATE user SET full_name='" + fullname + "' , birthdate='" + birthdate + "' , password='" + password + "' WHERE username='" + username + "'"); + } else { + st.executeUpdate("UPDATE user SET full_name='" + fullname + "' , birthdate='" + birthdate + "' WHERE username='" + username + "'"); + } + + if (oldpassword.equals(password)) { + //profile berhasil di update, password tidak diganti + response.sendRedirect("../src/profile.jsp?profileupdate=pwd"); + } else + { + //profile berhasil di update, password diganti + response.sendRedirect("../src/profile.jsp?profileupdate=ok"); + } + } catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + + } + + /* + * pathInfo : baseURL/user/current_task + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/current_task")) { + try { + String username = request.getParameter("username"); + conn = connector.getConnection (); + + PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT task.task_name, task.task_id, task.task_status FROM task_asignee LEFT JOIN task ON task.task_id=task_asignee.task_id WHERE username=? OR task_creator=?"); + stmt.setString(1, username); + stmt.setString(2, username); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + JSONArray currentTaskArray = new JSONArray(); + while (rs.next()) { + if ("0".equals(rs.getString("task_status"))) { + JSONObject currentTask = new JSONObject(); + currentTask.put("task_name", rs.getString("task_name")); + currentTask.put("task_id", rs.getString("task_id")); + currentTaskArray.put(currentTask); + } + } + out.println(currentTaskArray); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /* + * pathInfo : baseURL/user/finished_task + * requestParameter : username= + * Notes : baseURL adalah localhost:8084/eurilys4 ATAU http://eurilys.ap01.aws.af.cm/ + */ + else if (pathInfo.equals("/finished_task")) { + try { + String username = request.getParameter("username"); + conn = connector.getConnection (); + + PreparedStatement stmt = conn.prepareStatement("SELECT DISTINCT task.task_name, task.task_id, task.task_status FROM task_asignee LEFT JOIN task ON task.task_id=task_asignee.task_id WHERE username=? OR task_creator=?"); + stmt.setString(1, username); + stmt.setString(2, username); + ResultSet rs = stmt.executeQuery(); + rs.beforeFirst(); + JSONArray finishedTaskArray = new JSONArray(); + while (rs.next()) { + if ("1".equals(rs.getString("task_status"))) { + JSONObject finishedTask = new JSONObject(); + finishedTask.put("task_name", rs.getString("task_name")); + finishedTask.put("task_id", rs.getString("task_id")); + finishedTaskArray.put(finishedTask); + } + } + out.println(finishedTaskArray); + } + catch (SQLException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); + } + } + } // + /** + * Handles the HTTP + * GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// +} diff --git a/eurilys4/src/java/service/dbConnection.java b/eurilys4/src/java/service/dbConnection.java new file mode 100644 index 00000000..cfa3b42b --- /dev/null +++ b/eurilys4/src/java/service/dbConnection.java @@ -0,0 +1,38 @@ +package service; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import org.json.*; + +public class dbConnection { + + public dbConnection() {} + + public Connection getConnection () throws SQLException, ClassNotFoundException { + String jsonMsg = "{\"mysql-5.1\":[{\"name\":\"mysql-4f700\",\"label\":\"mysql-5.1\",\"plan\":\"free\",\"tags\":[\"mysql\",\"mysql-5.1\",\"relational\"],\"credentials\":{\"name\":\"progin_405_13510086\",\"hostname\":\"localhost\",\"host\":\"localhost\",\"port\":3306,\"user\":\"root\",\"username\":\"root\",\"password\":\"\"}}]}"; + //String jsonMsg = java.lang.System.getenv("VCAP_SERVICES"); + JSONTokener tokener = new JSONTokener(jsonMsg); + JSONObject root = new JSONObject(tokener); + + JSONArray mysql51 = root.getJSONArray("mysql-5.1"); + JSONObject credentials = mysql51.getJSONObject(0).getJSONObject("credentials"); + String db_username = credentials.getString("username"); + String db_password = credentials.getString("password"); + String db_hostname = credentials.getString("hostname"); + int db_port = credentials.getInt("port"); + String db_name = credentials.getString("name"); + /* + System.out.println("Username : " + db_username); + System.out.println("Password : " + db_password); + System.out.println("Hostname : " + db_hostname); + System.out.println("Port : " + db_port); + System.out.println("Name : " + db_name); */ + + String connectionURL = "jdbc:mysql://"+db_hostname+":"+db_port+"/"+db_name; + Connection conn = null; + Class.forName("com.mysql.jdbc.Driver"); + conn = DriverManager.getConnection(connectionURL,db_username,db_password); + return conn; + } +} diff --git a/eurilys4/src/java/servlet/ServletHandler.java b/eurilys4/src/java/servlet/ServletHandler.java new file mode 100644 index 00000000..347573e8 --- /dev/null +++ b/eurilys4/src/java/servlet/ServletHandler.java @@ -0,0 +1,818 @@ +package servlet; + +//import java.io.BufferedInputStream; +//import java.io.BufferedOutputStream; +import Function.FileManager; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +//import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.servlet.http.Part; +import org.apache.tomcat.util.http.fileupload.FileItem; +//import org.apache.tomcat.util.http.fileupload.FileUploadException; +//import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory; +//import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; + +import org.json.*; + + +//import com.google.gson.*; + +import com.mysql.jdbc.MySQLConnection; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.Iterator; +import javax.servlet.annotation.MultipartConfig; +import org.apache.tomcat.util.http.fileupload.FileUploadException; +import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory; +import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; + +@MultipartConfig +public class ServletHandler extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + Connection conn = null; + + PrintWriter out = resp.getWriter(); + + //Login + if (req.getParameter("type").equalsIgnoreCase("login")) { + String username = req.getParameter("login_username"); + String password = req.getParameter("login_password"); + + //URL url = new URL("http://localhost:8084/eurilys4-service/user/login_check?login_username="+username+"&login_password="+password); + URL url = new URL("http://eurilys.ap01.aws.af.cm/user/login_check?login_username="+username+"&login_password="+password); + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + + //out.println("Output : " + outputObject); + + String[] output_parts = outputObject.split(","); + String fullname = output_parts[0]; + //String avatar = ""; + String avatar = output_parts[1]; + + + if ("failed".equals(outputObject)) { + //Login gagal + resp.sendRedirect("index.jsp?login_status=failed"); + + } else { + //Login berhasil + HttpSession session = req.getSession(true); + session.setAttribute("username", username); + session.setAttribute("fullname", fullname); + session.setAttribute("avatar", avatar); + resp.sendRedirect("src/dashboard.jsp"); + } + } + + //Sign Up + else if (req.getParameter("type").equalsIgnoreCase("signup")) { + String username = req.getParameter("signup_username"); + String password = req.getParameter("signup_password"); + //String password_confirm = req.getParameter("signup_confirm_password"); + String fullname = req.getParameter("signup_long_name"); + String email = req.getParameter("signup_email"); + String birthdate = req.getParameter("signup_birth_date"); + //Blob avatar = req.getParameter("signup_avatar_upload"); + + try { + try { + Class.forName("com.mysql.jdbc.Driver"); + System.out.println("Berhasil connect ke Mysql JDBC Driver ... "); + } catch (ClassNotFoundException ex) { + System.out.println("Where is your MySQL JDBC Driver?"); + } + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/progin_405_13510086", "root", ""); + Statement st = conn.createStatement(); + st.executeUpdate("INSERT INTO user VALUES ('" + username + "','" + password + "','" + fullname + "','" + birthdate + "','NULL','" + email + "')"); + + //berhasil sign up + if (conn != null) { + // Set Session + HttpSession session = req.getSession(true); + session.setAttribute("username", username); + session.setAttribute("fullname", fullname); + // Redirect + resp.sendRedirect("src/dashboard.jsp"); + } else { + //gagal sign up + req.setAttribute("result", "failed_register"); + req.getRequestDispatcher("index.jsp").forward(req, resp); + } + } catch (SQLException e) { + System.out.println("Connection Failed! Check output console"); + } finally { + try { + conn.close(); + } catch (SQLException ex) { + Logger.getLogger(ServletHandler.class.getName()).log(Level.SEVERE, null, ex); + System.out.println("Can not close connection"); + } + } + } + + //Add Category + else if (req.getParameter("type").equalsIgnoreCase("add_category")) { + + String categoryName = req.getParameter("add_category_name"); + String categoryAssigne = req.getParameter("add_category_asignee_name"); + HttpSession session = req.getSession(true); + String categoryCreator = (String) session.getAttribute("username"); + + String server = "http://localhost:8084/eurilys4-service/SOAPAddCategory"; + //String service = "http://eurilys.ap01.aws.af.cm/SOAPAddCategory"; + + try { + //DEFINE CONNECTION. + out.write("Servlet - Define Connection"); + HttpURLConnection connection = (HttpURLConnection) ( new URL(server).openConnection() ); + connection.setDoOutput (true); + connection.setDoInput (true); + connection.setRequestMethod ("POST"); + connection.setRequestProperty("SOAPAction", server); + //CREATE REQUEST. + out.write("Servlet - Create Request"); + String xml = ""+ + ""+ + ""+ + ""+categoryName+""+ + ""+categoryAssigne+""+ + ""+categoryCreator+""+ + ""+ + ""; + out.write(xml); + + //SEND REQUEST. + out.write("Servlet - Send Request"); + System.out.println(xml); + OutputStream _out = connection.getOutputStream(); + OutputStreamWriter wout = new OutputStreamWriter(_out, "UTF-8"); + wout.write(xml); + wout.flush(); + _out.close(); + + //READ RESPONSE. + out.write("Servlet - Read Response"); + InputStream in = connection.getInputStream(); + int c; + String response = ""; + while ((c = in.read()) != -1) + { + response += (char) c; + System.out.println(c); + } + System.out.println(response); + out.write(response); + + //EXTRACT RESULT. + out.write("Servlet - Extract Result"); + int startTag = response.indexOf(""); + int endTag = response.indexOf(""); + String parameter = response.substring(startTag,endTag).replaceAll("",""); + parameter = parameter.trim(); + out.write(parameter); + + //DISPLAY RESULT. + System.out.println("Result="+parameter); + resp.sendRedirect("src/dashboard.jsp"); + + //CLOSE ALL. + in .close(); + out .close(); + connection.disconnect(); + } + catch (IOException e) { System.out.println(e.toString()); } + } + + //Delete Category + else if (req.getParameter("type").equalsIgnoreCase("delete_category")) { + Connection conn_category = null; + ResultSet rs_category = null; + String categoryID = req.getParameter("delete_category_id"); + String categoryName = req.getParameter("delete_category_name"); + HttpSession session = req.getSession(true); + List deleteTaskId = new ArrayList(); + + /* The following will be executed if confirmed */ + try { + // Make connection to database + try { + Class.forName("com.mysql.jdbc.Driver"); + System.out.println("Berhasil connect ke Mysql JDBC Driver - ServletHandler.java delete_category"); + } catch (ClassNotFoundException ex) { + System.out.println("Where is your MySQL JDBC Driver? - ServletHandler.java delete_category"); + } + conn_category = DriverManager.getConnection("jdbc:mysql://localhost:3306/progin_405_13510086", "root", ""); + + PreparedStatement stmt_category = conn_category.prepareStatement("SELECT task_id FROM task WHERE cat_name=?"); + stmt_category.setString(1, categoryName); + rs_category = stmt_category.executeQuery(); + + rs_category.beforeFirst(); + //Ada Task pada category tersebut + while (rs_category.next()) { + deleteTaskId.add(rs_category.getString("task_id")); + + //Delete Task Assignee + stmt_category = conn_category.prepareStatement("DELETE FROM task_asignee WHERE task_id=?"); + stmt_category.setString(1, rs_category.getString("task_id")); + stmt_category.executeUpdate(); + } + + //Delete Task + if (deleteTaskId.size() > 0) { + for (int i = 0; i < deleteTaskId.size(); i++) { + stmt_category = conn_category.prepareStatement("DELETE FROM task WHERE task_id=?"); + stmt_category.setString(1, deleteTaskId.get(i)); + stmt_category.executeUpdate(); + } + } + + //Delete Category Assignee + stmt_category = conn_category.prepareStatement("DELETE FROM cat_asignee WHERE cat_id=?"); + stmt_category.setString(1, categoryID); + stmt_category.executeUpdate(); + + //Delete Category + stmt_category = conn_category.prepareStatement("DELETE FROM category WHERE cat_id=?"); + stmt_category.setString(1, categoryID); + stmt_category.executeUpdate(); + + //Redirect + resp.sendRedirect("src/dashboard.jsp"); + } catch (SQLException e) { + System.out.println("Connection Failed! Check output console"); + } finally { + try { + conn_category.close(); + } catch (SQLException ex) { + Logger.getLogger(ServletHandler.class.getName()).log(Level.SEVERE, null, ex); + System.out.println("Can not close connection"); + } + } + } + + //add comment + else if (req.getParameter("type").equalsIgnoreCase("add_comment")) { + String comment = req.getParameter("CommentBox"); + String taskID = req.getParameter("comment_task_id"); + HttpSession session = req.getSession(true); + String username = (String) session.getAttribute("username"); + + System.out.println("comment : " + comment); + System.out.println("taskID :" + taskID); + System.out.println("username " + username); + + String server = "http://localhost:8084/eurilys4-service/SOAPAddComment"; + //String service = "http://eurilys.ap01.aws.af.cm/SOAPAddComment"; + + try { + //DEFINE CONNECTION. + out.write("Servlet - Define Connection"); + HttpURLConnection connection = (HttpURLConnection) ( new URL(server).openConnection() ); + connection.setDoOutput (true); + connection.setDoInput (true); + connection.setRequestMethod ("POST"); + connection.setRequestProperty("SOAPAction", server); + //CREATE REQUEST. + out.write("Servlet - Create Request"); + String xml = ""+ + ""+ + ""+ + ""+comment+""+ + ""+taskID+""+ + ""+username+""+ + ""+ + ""; + out.write(xml); + + //SEND REQUEST. + out.write("Servlet - Send Request"); + System.out.println(xml); + OutputStream _out = connection.getOutputStream(); + OutputStreamWriter wout = new OutputStreamWriter(_out, "UTF-8"); + wout.write(xml); + wout.flush(); + _out.close(); + + //READ RESPONSE. + out.write("Servlet - Read Response"); + InputStream in = connection.getInputStream(); + int c; + String response = ""; + while ((c = in.read()) != -1) + { + response += (char) c; + System.out.println(c); + } + System.out.println(response); + out.write(response); + + //EXTRACT RESULT. + out.write("Servlet - Extract Result"); + int startTag = response.indexOf(""); + int endTag = response.indexOf(""); + String parameter = response.substring(startTag,endTag).replaceAll("",""); + parameter = parameter.trim(); + out.write(parameter); + + //DISPLAY RESULT. + System.out.println("Result="+parameter); + resp.sendRedirect("src/task_detail.jsp?task_id=" + parameter); + + //CLOSE ALL. + in .close(); + out .close(); + connection.disconnect(); + } + catch (IOException e) { System.out.println(e.toString()); } + /*try { + try { + Class.forName("com.mysql.jdbc.Driver"); + System.out.println("Berhasil connect ke Mysql JDBC Driver - add_comment "); + } catch (ClassNotFoundException ex) { + System.out.println("Where is your MySQL JDBC Driver? - add_comment"); + } + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/progin_405_13510086", "root", ""); + Statement st = conn.createStatement(); + st.executeUpdate("INSERT INTO `comment`(`comment_content`,`task_id`,`comment_creator`) VALUES ('" + comment + "','" + taskID + "','" + username + "')"); + resp.sendRedirect("src/task_detail.jsp?task_id=" + taskID); + } catch (SQLException e) { + System.out.println("Connection Failed! Check output console - add_comment"); + } finally { + try { + conn.close(); + } catch (SQLException ex) { + Logger.getLogger(ServletHandler.class.getName()).log(Level.SEVERE, null, ex); + System.out.println("Can not close connection - add_comment"); + } + }*/ + } + + //edit task + else if (req.getParameter("type").equalsIgnoreCase("edit_task")) { + String taskID = req.getParameter("edit_task_id"); + String deadline = req.getParameter("edit_task_deadline"); + String assigneeList = URLEncoder.encode(req.getParameter("edit_task_assignee"), "UTF-8"); + String tagList = URLEncoder.encode(req.getParameter("edit_task_tag"), "UTF-8"); + + //URL url = new URL("http://localhost:8084/eurilys4-service/task/update_task?edit_task_id="+taskID+"&edit_task_deadline="+deadline+"&edit_task_assignee="+assigneeList+"&edit_task_tag="+tagList); + URL url = new URL("http://eurilys.ap01.aws.af.cm/task/update_task?edit_task_id="+taskID+"&edit_task_deadline="+deadline+"&edit_task_assignee="+assigneeList+"&edit_task_tag="+tagList); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + if ("3".equals(outputObject)) { + resp.sendRedirect("src/task_detail.jsp?task_id="+taskID+"&update_task=ok"); + } else { + resp.sendRedirect("src/task_detail.jsp?task_id="+taskID+"&update_task=failed"); + } + } + + //edit profile + else if (req.getParameter("type").equalsIgnoreCase("edit_profile")) { + String user_name = req.getParameter("edit_username"); + String password = req.getParameter("password"); + String fullname = req.getParameter("fullname"); + //String target = req.getParameter("avatar"); + String birthdate = req.getParameter("birthdate"); + + Part filePart = req.getPart("avatar"); + System.out.println("file Part : " + filePart); + String avatar = "img/avatar/" + user_name + FileManager.getExtension(FileManager.getFilename(filePart)); + String filePath = getServletContext().getRealPath("/") + avatar; + + avatar = URLEncoder.encode(avatar, "UTF-8"); + fullname = URLEncoder.encode(fullname, "UTF-8"); + + //URL url = new URL("http://localhost:8084/eurilys4-service/user/update_profile?username="+user_name+"&password="+password+"&fullname="+fullname+"&birthdate="+birthdate+"&avatar="+avatar); + URL url = new URL("http://eurilys.ap01.aws.af.cm/user/update_profile?username="+user_name+"&password="+password+"&fullname="+fullname+"&birthdate="+birthdate+"&avatar="+avatar); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + if ("1".equals(outputObject)) { + //berhasil + Files.copy(filePart.getInputStream(), Paths.get(filePath), StandardCopyOption.REPLACE_EXISTING); + HttpSession session = req.getSession(true); + session.setAttribute("avatar", avatar); + resp.sendRedirect("src/profile.jsp?profileupdate=ok"); + } else { + //failed + resp.sendRedirect("src/profile.jsp?profileupdate=failed"); + } + + } + + //Add Task + else if (req.getParameter("type").equalsIgnoreCase("add_task")) { + String task_name = req.getParameter("task_name_input"); + //attachment + /*Part filePart1 = req.getPart("attachment_file1"); + Part filePart2 = req.getPart("attachment_file1"); + Part filePart3 = req.getPart("attachment_file1"); + System.out.println("file Part 1 : " + filePart1); + System.out.println("file Part 2 : " + filePart2); + System.out.println("file Part 3 : " + filePart3); + String attachment1 = "img/attachment/attachment1" + FileManager.getExtension(FileManager.getFilename(filePart1)); + String attachment2 = "img/attachment/attachment2" + FileManager.getExtension(FileManager.getFilename(filePart2)); + String attachment3 = "img/attachment/attachment3" + FileManager.getExtension(FileManager.getFilename(filePart3)); + String filePath1 = getServletContext().getRealPath("/") + attachment1; + String filePath2 = getServletContext().getRealPath("/") + attachment2; + String filePath3 = getServletContext().getRealPath("/") + attachment3; + + attachment1 = URLEncoder.encode(attachment1, "UTF-8"); + attachment2 = URLEncoder.encode(attachment2, "UTF-8"); + attachment3 = URLEncoder.encode(attachment3, "UTF-8");*/ + // + String task_deadline = req.getParameter("deadline_input"); + String assigneeList = req.getParameter("assignee_input"); + String tagList = req.getParameter("tag_input"); + String catName = req.getParameter("addtask_cat_name"); + HttpSession session = req.getSession(true); + String taskCreator = (String) session.getAttribute("username"); + + //String server = "http://localhost:8084/eurilys4-service/SOAPAddTask"; + String server = "http://eurilys.ap01.aws.af.cm/SOAPAddTask"; + + try { + //DEFINE CONNECTION. + out.write("Servlet - Define Connection"); + HttpURLConnection connection = (HttpURLConnection) ( new URL(server).openConnection() ); + connection.setDoOutput (true); + connection.setDoInput (true); + connection.setRequestMethod ("POST"); + connection.setRequestProperty("SOAPAction", server); + //CREATE REQUEST. + out.write("Servlet - Create Request"); + String xml = ""+ + ""+ + ""+ + ""+task_name+""+ + /*""+attachment1+""+ + ""+attachment2+""+ + ""+attachment3+""+*/ + ""+task_deadline+""+ + ""+assigneeList+""+ + ""+tagList+""+ + ""+catName+""+ + ""+taskCreator+""+ + ""+ + ""; + out.write(xml); + + //SEND REQUEST. + out.write("Servlet - Send Request"); + System.out.println(xml); + OutputStream _out = connection.getOutputStream(); + OutputStreamWriter wout = new OutputStreamWriter(_out, "UTF-8"); + wout.write(xml); + wout.flush(); + _out.close(); + + //READ RESPONSE. + out.write("Servlet - Read Response"); + InputStream in = connection.getInputStream(); + int c; + String response = ""; + while ((c = in.read()) != -1) + { + response += (char) c; + System.out.println(c); + } + System.out.println(response); + out.write(response); + + //EXTRACT RESULT. + out.write("Servlet - Extract Result"); + int startTag = response.indexOf(""); + int endTag = response.indexOf(""); + String parameter = response.substring(startTag,endTag).replaceAll("",""); + parameter = parameter.trim(); + out.write(parameter); + + //DISPLAY RESULT. + System.out.println("Result="+parameter); + if (parameter.equals("")){ + resp.sendRedirect("src/add_task.jsp"); + } else { + resp.sendRedirect("src/task_detail.jsp?task_id=" + parameter); + } + + //CLOSE ALL. + in .close(); + out .close(); + connection.disconnect(); + } + catch (IOException e) { System.out.println(e.toString()); } + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + Connection conn = null; + + //Finish Task + if (req.getParameter("type").equalsIgnoreCase("finish_task")) { + String taskID = req.getParameter("task_id"); + PrintWriter out = resp.getWriter(); + + //URL url = new URL("http://localhost:8084/eurilys4-service/task/finish_task?task_id="+taskID); + URL url = new URL("http://eurilys.ap01.aws.af.cm/task/finish_task?task_id="+taskID); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + out.println(outputObject); + } + + //Delete Task + else if (req.getParameter("type").equalsIgnoreCase("delete_task")) { + String taskID = req.getParameter("task_id"); + PrintWriter out = resp.getWriter(); + + //URL url = new URL("http://localhost:8084/eurilys4-service/task/delete_task?task_id="+taskID); + URL url = new URL("http://eurilys.ap01.aws.af.cm/task/delete_task?task_id="+taskID); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + out.println(outputObject); + } + + //Delete Comment + else if (req.getParameter("type").equalsIgnoreCase("delete_comment")) { + String commentID = req.getParameter("comment_id"); + //URL url = new URL("http://localhost:8084/eurilys4-service/task/delete_comment?comment_id="+commentID); + URL url = new URL("http://eurilys.ap01.aws.af.cm/task/delete_comment?comment_id="+commentID); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + PrintWriter out = resp.getWriter(); + out.println(outputObject); + } + + //Delete Category + else if (req.getParameter("type").equalsIgnoreCase("delete_category")) { + String categoryID = req.getParameter("category_id"); + //URL url = new URL("http://localhost:8084/eurilys4-service/category/delete?category_id="+categoryID); + URL url = new URL("http://eurilys.ap01.aws.af.cm/category/delete?category_id="+categoryID); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + if ("1".equals(outputObject)) { + //berhasil + resp.sendRedirect("src/dashboard.jsp"); + } else { + resp.sendRedirect("src/dashboard.jsp?delete_category=failed"); + } + + } + + //Category Task + else if (req.getParameter("type").equalsIgnoreCase("category_task")) { + PrintWriter out = resp.getWriter(); + String categoryName = req.getParameter("category_name"); + categoryName = URLEncoder.encode(categoryName); + + //URL url = new URL("http://localhost:8084/eurilys4-service/task/get_category_task?category_name="+categoryName); + URL url = new URL("http://eurilys.ap01.aws.af.cm/task/get_category_task?category_name="+categoryName); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + + out.println(outputObject); + } + + //Search Result + else if (req.getParameter("type").equalsIgnoreCase("search_result")) { + PrintWriter out = resp.getWriter(); + String keyword = req.getParameter("keyword"); + String filter = req.getParameter("filter"); + + //URL url = new URL("http://localhost:8084/eurilys4-service/search/result?keyword="+keyword+"&filter="+filter); + URL url = new URL("http://eurilys.ap01.aws.af.cm/search/result?keyword="+keyword+"&filter="+filter); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + + out.println(outputObject); + } + + //Assignee Autocomplete + else if (req.getParameter("type").equalsIgnoreCase("assignee_autocomplete")) { + PrintWriter out = resp.getWriter(); + String keyword = req.getParameter("keyword"); + + //URL url = new URL("http://localhost:8084/eurilys4-service/user/autocomplete?keyword="+keyword); + URL url = new URL("http://eurilys.ap01.aws.af.cm/user/autocomplete?keyword="+keyword); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + out.println(outputObject); + } + + //Edit Task - Delete Assignee + else if (req.getParameter("type").equalsIgnoreCase("edittask_deleteAssignee")) { + String taskID = req.getParameter("task_id"); + String userID = req.getParameter("user_id"); + PrintWriter out = resp.getWriter(); + + //URL url = new URL("http://localhost:8084/eurilys4-service/task/delete_assignee?task_id="+taskID+"&username="+userID); + URL url = new URL("http://eurilys.ap01.aws.af.cm/task/delete_assignee?task_id="+taskID+"&username="+userID); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + out.println(outputObject); + } + + //Edit Task - Delete Tag + else if (req.getParameter("type").equalsIgnoreCase("edittask_deleteTag")) { + String taskID = req.getParameter("task_id"); + String tagName = req.getParameter("tag_name"); + + PrintWriter out = resp.getWriter(); + + //URL url = new URL("http://localhost:8084/eurilys4-service/task/delete_tag?tag_name="+tagName+"&task_id="+taskID); + URL url = new URL("http://eurilys.ap01.aws.af.cm/task/delete_tag?tag_name="+tagName+"&task_id="+taskID); + + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String outputObject = ""; + while ((output = br.readLine()) != null) { + outputObject += output; + } + httpConn.disconnect(); + out.println(outputObject); + } + + } + + private static String getFilename(Part part) { + for (String cd : part.getHeader("content-disposition").split(";")) { + if (cd.trim().startsWith("filename")) { + String filename = cd.substring(cd.indexOf('=') + 1).trim().replace("\"", ""); + return filename.substring(filename.lastIndexOf('/') + 1).substring(filename.lastIndexOf('\\') + 1); // MSIE fix. + } + } + return null; + } +} diff --git a/eurilys4/web/META-INF/context.xml b/eurilys4/web/META-INF/context.xml new file mode 100644 index 00000000..28c69a97 --- /dev/null +++ b/eurilys4/web/META-INF/context.xml @@ -0,0 +1,2 @@ + + diff --git a/eurilys4/web/WEB-INF/web.xml b/eurilys4/web/WEB-INF/web.xml new file mode 100644 index 00000000..027adf28 --- /dev/null +++ b/eurilys4/web/WEB-INF/web.xml @@ -0,0 +1,64 @@ + + + + SOAPService + servlet.SOAPService + + + ServletHandler + servlet.ServletHandler + + + UserService + service.UserService + + + BasicServlet + service.BasicServlet + + + TaskService + service.TaskService + + + CategoryService + service.CategoryService + + + SearchService + service.SearchService + + + SOAPService + /SOAPService + + + ServletHandler + /ServletHandler + + + UserService + /user/* + + + BasicServlet + /BasicServlet + + + TaskService + /task/* + + + CategoryService + /category/* + + + SearchService + /search/* + + + + 30 + + + diff --git a/eurilys4/web/css/desktop_style.css b/eurilys4/web/css/desktop_style.css new file mode 100644 index 00000000..fec9e336 --- /dev/null +++ b/eurilys4/web/css/desktop_style.css @@ -0,0 +1,844 @@ +@media screen and (min-width: 960px) and (max-width: 1200px){ + +html {width:100%; height:100%; overflow-x:hidden; font-family:Segoe UI; font-weight: lighter;} +body {width:100%; height:300px; display:block; margin:0px; + /*background-image:url('../img/bg.jpg');*/ + background-color:#F3E8E6; +} + +h1{ + + font-size: 35px; + padding-left: 20px; + color: #FF5544; +} + +/* HEADER SECTION +------------------------------------------------------------------------------------------- */ +.search_recommend { + cursor:pointer; + display:block; + margin-bottom:2px; + width:100%; + color:gray; +} + +header { + width:100%; + height:90px; + background-color:#3f3f7a; + display:block; +} +.header_menu a { + color:white; + text-decoration:none; +} + +textarea { + font-family:Segoe UI; font-weight:lighter; +} + +#header_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; +} + +#login_form_container { + position:relative; + background-color:#3f3f7a; + float:right; + width:90%; + height:130px; + margin-right:5%; + z-index:100; +} +#login_form { + font-family:Segoe UI; font-weight:lighter;; + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:15px; + z-index:200; +} +#login_form label { + color:#fff; + float:left; + width:35%; + margin-left:3px; +} + +#login_username , #login_password { + color:gray; + float:left; + margin-left:7px; + width:55%; +} +#login_submit { + float:right; + margin-right:5%; +} +.login_reg_warning { + color:red; + width:90%; + font-style: italic; +} + +input#remember_me { + margin-top:20px;float:left; + width:auto; +} +label#remember_me { + float:left; font-size:12px; width:auto; margin-top:-20px; +} + +#edit_profil_container {width:90%; margin:auto; display:block;} +#edit_profil_container h3 {color:#007bc1;} +#edit_profile_form { + width:70%; + margin-top:20px; + margin-left:20px; +} +#edit_profile_form label { + float:left; + font-size:16px; + font-family:Segoe UI; + font-weight:lighter; + color:gray; + width:28%; +} + +#edit_profile_submit { + float:right; + margin-right:5%; +} + +#edit_profile_form input { + float:left; + height:28px; + font-size:17px; + width:60%; + margin-bottom:10px; +} + +#edit_profile_form input#edit_profile_submit { + float:right; + height:35px; + font-size:20px; + width:40%; + margin-bottom:10px; +} + +.header_menu a { + color:white; + text-decoration:none; +} +.header_menu { + float:right; margin-top:30px;height:60%; width:45%; + +} +.header_menu_button { + padding-top:8px; padding-bottom:8px; + width:28%; display:block;color:white; + margin-left:20px;margin-top:8px; text-align:center; + font-size:18px; cursor:pointer; float:left; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} +.header_menu_button:hover , .header_menu_button:active { + background-color:#6FBEC6;text-decoration:none; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} + +.header_menu_button:hover{background-color:#ff5645;} + +.current_header_menu { + background-color:#6FBEC6; +} +#search_box { + float:left; margin-left:45px; height:25px; margin-top:45px; width:20%; +} +#search_box_filter { + float:left; height:30px; margin-top:45px; margin-left:5px; +} +#txtHint , #category_asignee_autocomplete , #add_task_asignee_autocomplete , #edit_task_asignee_autocomplete { + position:absolute; + display:block; + margin-top:73px; + margin-left:275px; + width:16%; + z-index:300; + color:gray; + border:solid 1px #dedede; + overflow:hidden; + border-bottom-right-radius: 6px; + border-bottom-left-radius: 6px; + -moz-border-bottom-right-radius: 6px; + -moz-border-bottom-left-radius: 6px; + box-shadow: 0px 0px 5px #999; + border-width: 3px 1px 1px; + border-style: solid; + border-color: #333 #DEDEDE #DEDEDE; + background-color: white; +} + +/* LOGO +----------------------------------------------------------------------------------------------------------------- */ +#fleur { + font-size:100px; + color:#FF5544; + display:inline-block; +} +#textdesu{ + color:#fff; + display:inline-block; + font-size:60px; + letter-spacing:-6px; + font-family:Trajan Pro; + margin-left:-10px; +} +#tagline { + font-family:Times New Roman; + font-size:12px; + letter-spacing:2px; + font-style:italic; + margin-top:-20px; + margin-left:15px; + color:#fff; +} + +/* SECTION +--------------------------------------------------------------------------------------------------------------------- */ +section {width:80%;background-color:#F9F9F9; height:680px; margin-left:auto; margin-right:auto; margin-top:40px; margin-bottom:40px; z-index:1; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} + +#index_left { + height:100%; + width:65%; + background-color:#f9f9f9; + float:left; +} +#index_right { + height:100%; + width:35%; + float:left; + padding-top:40px; +} +.signup_label { + width:65%; + background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; + border:none; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + margin-left:auto;margin-right:auto; letter-spacing:1px; + text-align:center; + font-size:25px; + font-family:Segoe UI; font-weight:lighter;; + font-weight:bold; + margin-top:170px; +} +#signup_form_container { + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:10px; + background-color:#EBEBE9; + color:gray; + padding-top:20px; + height:350px; + display:block; +} +#signup_form { + width:90%; + margin-top:20px; + margin-left:20px; +} +#signup_form label { + float:left; + font-size:16px; + font-family:Segoe UI; font-weight:lighter;; + color:gray; + width:28%; +} +#signup_form input { + float:left; + height:20px; + font-size:20px; + width:60%; + margin-bottom:10px; +} +.signup_form_validation { + display:none; + padding-left:10px; + padding-top:5px; + padding-bottom:14px; +} +input#avatar_upload {font-size:12px;} + +#tutorial { + text-align:justify; + text-justify:inter-word; +} + +#tutorial_image { + width:100%; +} + +/* FOOTER SECTION +--------------------------------------------------------------------------------------------------------------------- */ +#footer_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; + color:#fff; + font-size:12px; + text-align:center; +} + +footer { + width:100%; + background-color:#3f3f7a; + height:80px; + display:block; + bottom:0px; +} + +/* NAVIGATION BAR +--------------------------------------------------------------------------------------------------------------------- */ +#navbar { + margin-left:auto; + display:block; + height:100%; + width:25%; + float:left; +} +#short_profile { + margin-top:30px; + width:80%; + margin-left:auto; + margin-right:auto; + height:150px; +} +#profile_picture { + width:100px; + float:left; +} +#mainpp { + max-width: 300px; +} +#profile_info { + margin-left:120px; + float:left; + color:gray; + font-size:14px; + color:gray; + width:120px; + position:absolute; +} +#profile_pic_upload { + clear:both; + margin-top:20px; +} +#category_list { + width:80%; + margin-left:auto; + margin-right:auto; +} +#category_list a { + color:#fff; + text-decoration:none; +} +#category_list ul { + list-style-image:url('../img/arrow.png'); + padding-top:5px; + margin-left:-10px; +} +#category_list ul li a { + cursor:pointer; + color:#6FBEC6; + padding-bottom:5px; +} +#category_list ul li a:hover { + color:#fff; +} + +#category_list ul li a:active{ + color:#ff5645; +} +#add_new_category , #add_task_link{ + color:gray; + cursor:pointer; +} +#add_task_link:hover , #add_new_category:hover { + color:#FF5544; +} +#add_task_link {display:none;} +#add_task_link a { + color:gray; + text-decoration:none; +} +#add_task_link a:hover { + color:#ff5544; +} + +#category_form { + width:100%; + height:180px; + background-color:#6FBEC6; + margin-top:5px; + color:#fff; + padding-top:15px; + display:none; +} +#category_form_inner { + width:90%; + height:90%; + margin:auto; +} +#category_form_inner input { + width:95%; +} +#category_item { + margin-top:5px; +} +#current_category { + color:#6FBEC6; +} + +#add_category { + font-size:11px; + cursor:pointer; +} +#add_category:hover { + color:gray; +} +#add_category_button { + width:80px; + text-align:center; +} +#category_title { + text-align:center; + padding-top:5px; + padding-bottom:5px; +} + +/* TASK DETAIL +--------------------------------------------------------------------------------------------------------------------- */ +#comment_textarea { + width:70%; + height:100px; + resize:none; +} + +#save_button_td { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +#save_edit_task { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:100px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +#task_attachment:hover { + color:#ff5544; +} + +#save_button_td:hover , #save_edit_task:hover{ + border-color:#0092dd; +} + +#edit_task_button, #save_edit_task { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +.edit_task_input {width:100%;} +#edit_task_button:hover { + border-color:#0092dd; +} + +#taskdetail_image { + height:100%; + width:auto; +} +.taskDetail { + width:90%; + margin:auto; +} + +/* ADD TASK +--------------------------------------------------------------------------------------------------------------------- */ +#task_name_input, #assignee_input, #deadline_input, #tag_input, #attachment_upload { + width:35%; +} +#add_task_button{ + display:block; + margin-left:22%; + border-style:solid; + border-color:#007bc1; + text-align:center; + width:80px; + font-size:15px; + padding-top:5px; + padding-bottom:5px; +} + +#add_task_button:hover { + border-color:#0092dd; +} +#add_task_container { + width:90%; + margin:auto; +} + +/* STYLING +--------------------------------------------------------------------------------------------------------------------- */ +.bold {font-weight:bold;} +.clear {clear:both;} +.left {float:left;} +.right {float:right;} +.left20 {margin-left:50px;} +.top10 {margin-top:10px;} +.top20 {margin-top:20px;} +.top45 {margin-top:45px;} +.top30 {margin-top:30px;} +.width100 {width:130px;} +.line10 {line-height:50%;} +a {text-decoration:none;} +#logout {color:#fff;} +.white {color:#fff;} +.red {color:red;} +.cursorPointer {cursor:pointer;} + +.thin_line {display:block;height:8px;margin-left:0px;width:100%;background-color:#524459;} + +.link_blue {background-color:#007bc1; color:#fff; padding-left:10px; padding-right:10px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none;cursor:pointer; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} +.link_blue:hover{background-color:#0092dd;text-decoration:none;} + +.link_blue_rect { + background-color:#007bc1; + color:#fff; + cursor:pointer; +} +.link_blue_rect:hover{ + background-color:#0092dd; +} + +.link_lightblue {background-color:#6FBEC6; color:#fff; padding-left:25px; padding-right:25px; padding-top:15px; padding-bottom:15px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +font-family:Segoe UI; font-weight:lighter;; margin-left:auto; margin-right:auto; +font-weight:bold; letter-spacing:1px; cursor:pointer; +font-size:20px; +} +.link_lightblue:hover{background-color:#9ad2d8;text-decoration:none;} + +.link_red {background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#ff786b;text-decoration:none;} + +.link_tosca {background-color:#dba8a8;color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_tosca:hover{background-color:#bae4d3;text-decoration:none;} + + +.link_red {background-color:#FA522C; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#FAAA98;text-decoration:none;} + +.darkBlue {color:#007bc1;} +.darkBlueItalic {color:#007bc1; font-style:italic; font-size:13px;} +.darkBlueLink {color:#007bc1; cursor:pointer;} +.userprofile_link {cursor:pointer;} +.userprofile_link:hover {color:#0092dd;} +/* DYNAMIC CONTENT +------------------------------------------------------------------------------------------------- */ +#dynamic_content { + border-left: 2px solid gray; + display:block; + width:73%; + height:100%; + float:right; + overflow:auto; + color:#55565B; + position:relative; +} +.dynamic_content_head { + display:block; + height:30px; + padding-left:2%; + width:75%; + font-weight:bold; +} + +.dynamic_content_row { + display:block; + width:100%; +} + +.dynamic_content_left { + display:block; + width:18%; + padding-left:2%; + font-weight:bold; +} + +.dynamic_content_right { + display:block; + width:74%; + padding-left:2%; + text-align:justify; + text-justify:inter-word; +} +.task_view_category { + float:right; + margin-right:20px; + color:red; +} +.task_view { + width:90%; + display:block; + background-color:white; + opacity:0.8; + padding-top:10px; + padding-bottom:10px; + padding-right:10px; + padding-left:10px; + color:gray; + height:125px; + margin:auto; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; + left:30px; +} +.task_view a:hover { + color:#ff5544; +} + +/* PROFILE CONTENT +------------------------------------------------------------------------------------------------- */ + +#profilebig { + padding:20px; + text-align:center; +} + +#upperprof{ +text-align:center; +} + +#upperprof img { +padding: 4px; +border: 1px solid rgb(204, 204, 204);} + +#namauser{ +width:230px;margin:auto;letter-spacing: 2px;background-color:#007bc1; + color:#fff; +font-size:20px; +text-transform:uppercase;margin-top:-50px;z-index: 99;position:relative; +} + +.headsdeh{ + background-color:#007bc1; + color:#fff; + width:230px; + font-size:17px;margin:auto; +} + +.categoryList, #newCategoryAdded { + display:block;padding:10px; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; + color:#007bc1; + cursor:pointer; +} + +.categoryList:hover, #newCategoryAdded:hover { + background-color:#007bc1; + color:#fff; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; +} + +#login_form input{margin-bottom:5px;} +#edit_profile_button {letter-spacing:0px;padding-left:8px; padding-right:8px;} +#edit_profile_button a {color:#fff; text-decoration:none;} +.ul_none {list-style:none; margin:auto; width:200px; margin-top:5px;} +.ul_none li {text-align:left;} +.red {color:#ff5544; font-weight:bold;} +.blue {color:#007bc1; font-weight:bold;} + +/* MAIN PAGE +--------------------------------------------------------------------------------- */ +#tutorial_container { + width:90%; + margin:auto; + margin-top:60px; + display:block; +} +#tutorial { + width:85%; + display:block; + margin:auto; + margin-top:20px; +} +.task_done_button {float:right;cursor:pointer;font-size:12px;} +.task_done_button:hover {color:#211C18;}; + +/* SCROLL BAR +---------------------------------------------------------------------------------- */ +/* Let's get this party started */ +::-webkit-scrollbar { + width: 12px; +} + +/* Track */ +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); +} + +/* Handle */ +::-webkit-scrollbar-thumb { + background: #A8DBC6; + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); +} +.half_div { + width:49%; + display:block; + float:left; + text-align:center; + margin-top:10%; +} +.half_tall { + height:250px; +} + +/* Search Result +--------------------------------------------------------------------------------- */ +.user_search_result_label { + float:left; + width:160px; + letter-spacing:1px; + display:block; + font-size:18px; + font-weight:bold; + text-align:left; + font-family:Helvetica; +} +.cat_search_result_label { + float:left; + width:170px; + display:block; + font-weight:bold; + text-align:left; +} + +/* MEDIA QUERIES +---------------------------------------------------------------------------------- */ +@media screen and (max-width:480px) { + #signup_form_container, #navbar, #search_box, .header_menu, #remember_me, + #remember_me_check {display:none} + + #index_left{ + height:300px; + width:100%; + } + + #tutorial_container{font-size:12px} + + #index_right{width:100%; margin-top:0px} + + #login_form_container { + width:100%; + float:left; + } + .signup_label{ + width:60%; + } + + div#dynamic_content{ + border-left:none; + width:100%; + } + + div#curtask1.task_view, div#curtask2.task_view, div#curtask3.task_view, + div#curtask4.task_view, div#curtask5.task_view{ + padding:none; + width:80% + } + + .dynamic_content_left{ + font-size:15px; + } + + .dynamic_content_right{ + font-size:15px; + } + + + + +} \ No newline at end of file diff --git a/eurilys4/web/css/mobile.css b/eurilys4/web/css/mobile.css new file mode 100644 index 00000000..25c08a8b --- /dev/null +++ b/eurilys4/web/css/mobile.css @@ -0,0 +1,808 @@ +@media screen and (max-width: 960px){ + +html {width:100%; height:100%; overflow-x:hidden; font-family:Segoe UI; font-weight: lighter;} +body {width:100%; height:300px; display:block; margin:0px;background-image:url('../img/bg.jpg');} + +h1{ + + font-size: 35px; + padding-left: 20px; + color: #FF5544; +} + +/* HEADER SECTION +------------------------------------------------------------------------------------------- */ +header { + width:100%; + height:80px; + background-color:#2a3c28; + display:block; +} +.header_menu a { + color:white; + text-decoration:none; + } + +textarea { + font-family:Segoe UI; font-weight:lighter;; +} + +#header_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; +} + +#login_form_container { + position:relative; + background-color:#2a3c28; + float:right; + width:90%; + height:130px; + margin-right:5%; + z-index:100; +} +#login_form { + font-family:Segoe UI; font-weight:lighter;; + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:15px; + z-index:200; +} +#login_form label { + color:#fff; + float:left; + width:35%; + margin-left:3px; +} + +#login_username , #login_password { + color:gray; + float:left; + margin-left:7px; + width:55%; +} +#login_submit { + float:right; + margin-right:5%; +} + +input#remember_me { + margin-top:20px;float:left; + width:auto; +} +label#remember_me { + float:left; font-size:12px; width:auto; margin-top:-20px; +} + +#edit_profil_container {width:90%; margin:auto; display:block;} +#edit_profil_container h3 {color:#007bc1;} +#edit_profile_form { + width:70%; + margin-top:20px; + margin-left:20px; +} +#edit_profile_form label { + float:left; + font-size:16px; + font-family:Segoe UI; + font-weight:lighter; + color:gray; + width:28%; +} + +#edit_profile_submit { + float:right; + margin-right:5%; +} + +#edit_profile_form input { + float:left; + height:28px; + font-size:17px; + width:60%; + margin-bottom:10px; +} + +#edit_profile_form input#edit_profile_submit { + float:right; + height:35px; + font-size:20px; + width:40%; + margin-bottom:10px; +} + +.header_menu a { + color:white; + text-decoration:none; +} +.header_menu { + float:right; margin-top:20px;height:60%; width:300px; + +} +.header_menu_button { + padding-top:8px; padding-bottom:8px; + width:85px; display:block;color:white; + margin-left:10px;margin-top:8px; text-align:center; + font-size:14px; cursor:pointer; float:left; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} +.header_menu_button:hover , .header_menu_button:active { + background-color:ff3000;text-decoration:none; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} + +.header_menu_button:hover{background-color:#ff5645;} + +.current_header_menu { + background-color:#ff3000; +} +#search_box { + float:left; margin-left:45px; height:25px; margin-top:30px; width:20%; +} +#search_box_filter { + float:left; height:30px; margin-top:30px; margin-left:5px; +} +#txtHint { + position:absolute; + display:block; + color:gray; + margin-top:73px; + margin-left:275px; + width:16%; + z-index:300; + overflow:hidden; + +} +/* LOGO +----------------------------------------------------------------------------------------------------------------- */ +#fleur { + font-size:100px; + color:#FF5544; + display:inline-block; +} +#textdesu{ + color:#fff; + display:inline-block; + font-size:60px; + letter-spacing:-6px; + font-family:Trajan Pro; + margin-left:-10px; +} +#tagline { + font-family:Times New Roman; + font-size:12px; + letter-spacing:2px; + font-style:italic; + margin-top:-20px; + margin-left:15px; + color:#fff; +} + +/* SECTION +--------------------------------------------------------------------------------------------------------------------- */ +section {width:80%;background-color:#F9F9F9; height:680px; margin-left:auto; margin-right:auto; margin-top:40px; margin-bottom:40px; z-index:1; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} + +#index_left { + height:100%; + width:65%; + background-color:#f9f9f9; + float:left; +} +#index_right { + height:100%; + width:35%; + float:left; + padding-top:40px; +} +.signup_label { + width:65%; + background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; + border:none; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + margin-left:auto;margin-right:auto; letter-spacing:1px; + text-align:center; + font-size:25px; + font-family:Segoe UI; font-weight:lighter;; + font-weight:bold; + margin-top:170px; +} +#signup_form_container { + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:10px; + background-color:#EBEBE9; + color:gray; + padding-top:20px; + height:350px; + display:block; +} +#signup_form { + width:90%; + margin-top:20px; + margin-left:20px; +} +#signup_form label { + float:left; + font-size:16px; + font-family:Segoe UI; font-weight:lighter;; + color:gray; + width:28%; +} +#signup_form input { + float:left; + height:20px; + font-size:20px; + width:60%; + margin-bottom:10px; +} +.signup_form_validation { + display:none; + padding-left:10px; + padding-top:5px; + padding-bottom:14px; +} +input#avatar_upload {font-size:12px;} + +#tutorial { + text-align:justify; + text-justify:inter-word; +} + +#tutorial_image { + width:100%; +} + +/* FOOTER SECTION +--------------------------------------------------------------------------------------------------------------------- */ +#footer_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; + color:#fff; + font-size:12px; + text-align:center; +} + +footer { + width:100%; + background-color:#2a3c28; + height:80px; + display:block; + bottom:0px; +} + +/* NAVIGATION BAR +--------------------------------------------------------------------------------------------------------------------- */ +#navbar { + margin-left:auto; + display:block; + height:100%; + width:200px; + float:left; +} +#short_profile { + margin-top:30px; + width:50%; + margin-left:20px; + margin-right:auto; + height:120px; +} +#profile_picture { + width:50px; + float:left; +} +#profile_info { + margin-left:60px; + float:right; + color:gray; + font-size:14px; + color:gray; + width:100px; + position:absolute; +} +#profile_pic_upload { + clear:both; + margin-top:20px; +} +#category_list { + width:80%; + margin-left:auto; + margin-right:auto; +} +#category_list a { + color:#fff; + text-decoration:none; +} +#category_list ul { + list-style-image:url('../img/arrow.png'); + padding-top:5px; + margin-left:-10px; +} +#category_list ul li a { + cursor:pointer; + color:#ff3000; + padding-bottom:5px; +} +#category_list ul li a:hover { + color:#fff; +} + +#category_list ul li a:active{ + color:#ff5645; +} +#add_new_category , #add_task_link{ + color:gray; + cursor:pointer; +} +#add_task_link:hover , #add_new_category:hover { + color:#FF5544; +} +#add_task_link {display:none;} +#add_task_link a { + color:gray; + text-decoration:none; +} +#add_task_link a:hover { + color:#ff5544; +} + +#category_form { + width:100%; + height:180px; + background-color:#ff3000; + margin-top:5px; + color:#fff; + padding-top:15px; + display:none; +} +#category_form_inner { + width:90%; + height:90%; + margin:auto; +} +#category_form_inner input { + width:95%; +} +#category_item { + margin-top:5px; +} +#current_category { + color:#ff3000; +} + +#add_category { + font-size:11px; + cursor:pointer; +} +#add_category:hover { + color:gray; +} +#add_category_button { + width:80px; + text-align:center; +} +#category_title { + text-align:center; + padding-top:5px; + padding-bottom:5px; +} + +/* TASK DETAIL +--------------------------------------------------------------------------------------------------------------------- */ +#comment_textarea { + width:70%; + height:100px; + resize:none; +} + +#save_button_td { + display:none; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +#task_attachment:hover { + color:#ff5544; +} + +#save_button_td:hover { + border-color:#0092dd; +} + +#edit_task_button, #save_edit_task { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} + +#edit_task_button:hover { + border-color:#0092dd; +} + +#taskdetail_image { + height:100%; + width:auto; +} +.taskDetail { + width:90%; + margin:auto; +} + +/* ADD TASK +--------------------------------------------------------------------------------------------------------------------- */ +#task_name_input, #assignee_input, #deadline_input, #tag_input, #attachment_upload { + width:35%; +} +#add_task_button{ + display:block; + margin-left:22%; + border-style:solid; + border-color:#007bc1; + text-align:center; + width:80px; + font-size:15px; + padding-top:5px; + padding-bottom:5px; +} + +#add_task_button:hover { + border-color:#0092dd; +} +#add_task_container { + width:90%; + margin:auto; +} + +/* STYLING +--------------------------------------------------------------------------------------------------------------------- */ +.bold {font-weight:bold;} +.clear {clear:both;} +.left {float:left; +width: 190px; +} +#logo{ +width:190px; +height:75px; +} +.right {float:right;} +.top10 {margin-top:10px;} +.top20 {margin-top:20px;} +.top45 {margin-top:45px;} +.top30 {margin-top:30px;} +.width100 {width:130px;} +.line10 {line-height:50%;} +a {text-decoration:none;} +#logout {color:#fff;} +.white {color:#fff;} +.cursorPointer {cursor:pointer;} + +.thin_line {display:block;height:8px;margin-left:0px;width:100%;background-color:#6b1e00;} + +.link_blue {background-color:#007bc1; color:#fff; padding-left:10px; padding-right:10px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none;cursor:pointer; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} +.link_blue:hover{background-color:#0092dd;text-decoration:none;} + +.link_blue_rect { + background-color:#c10029; + color:#fff; + cursor:pointer; +} +.link_blue_rect:hover{ + background-color:#ee5b7b; +} + +.link_lightblue {background-color:#ff3000; color:#fff; padding-left:25px; padding-right:25px; padding-top:15px; padding-bottom:15px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +font-family:Segoe UI; font-weight:lighter;; margin-left:auto; margin-right:auto; +font-weight:bold; letter-spacing:1px; cursor:pointer; +font-size:20px; +} +.link_lightblue:hover{background-color:#9ad2d8;text-decoration:none;} + +.link_red {background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#ff786b;text-decoration:none;} + +.link_tosca {background-color:#dbdaa8; color:#fff; padding-left:25px; padding-right:0px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_tosca:hover{background-color:#eeeec9;text-decoration:none;} + + +.link_red {background-color:#FA522C; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#FAAA98;text-decoration:none;} + +.darkBlue {color:#c10029;} +.darkBlueItalic {color:#c10029; font-style:italic; font-size:13px;} +.darkBlueLink {color:#c10029; cursor:pointer;} +.userprofile_link {cursor:pointer;} +.userprofile_link:hover {color:#ee5b7b;} +/* DYNAMIC CONTENT +------------------------------------------------------------------------------------------------- */ +#dynamic_content { + border-left: 2px solid gray; + display:block; + width:73%; + height:100%; + float:right; + overflow:auto; + color:#55565B; + position:relative; +} +.dynamic_content_head { + display:block; + height:30px; + padding-left:2%; + width:75%; + font-weight:bold; +} + +.dynamic_content_row { + display:block; + width:100%; +} + +.dynamic_content_left { + display:block; + width:18%; + padding-left:2%; + font-weight:bold; +} + +.dynamic_content_right { + display:block; + width:74%; + padding-left:2%; + text-align:justify; + text-justify:inter-word; +} +.task_view_category { + float:right; + margin-right:20px; + color:red; +} +.task_view { + width:90%; + display:block; + background-color:white; + opacity:0.8; + padding-top:10px; + padding-bottom:10px; + padding-right:10px; + padding-left:10px; + color:gray; + height:125px; + margin:auto; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; + left:30px; +} +.task_view a:hover { + color:#ff5544; +} + +/* PROFILE CONTENT +------------------------------------------------------------------------------------------------- */ + +#profilebig { + padding:20px; + text-align:center; +} + +#upperprof{ +text-align:center; +} + +#upperprof img { +padding: 4px; +border: 1px solid rgb(204, 204, 204);} + +#namauser{ +width:230px;margin:auto;letter-spacing: 2px;background-color:#c10029; + color:#fff; +font-size:20px; +text-transform:uppercase;margin-top:-50px;z-index: 99;position:relative; +} + +.headsdeh{ + background-color:#c10029; + color:#fff; + width:230px; + font-size:17px;margin:auto; +} + + +.categoryList, #newCategoryAdded { + display:block;padding:10px; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; + color:#c10029; + cursor:pointer; +} + +.categoryList:hover, #newCategoryAdded:hover { + background-color:#c10029; + color:#fff; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; +} + +#login_form input{margin-bottom:5px;} +#edit_profile_button {letter-spacing:0px;padding-left:8px; padding-right:0px;} +#edit_profile_button a {color:#fff; text-decoration:none;} +.ul_none {list-style:none; margin:auto; width:200px; margin-top:5px;} +.ul_none li {text-align:left;} +.red {color:#ff5544; font-weight:bold;} +.blue {color:#c10029; font-weight:bold;} + +/* MAIN PAGE +--------------------------------------------------------------------------------- */ +#tutorial_container { + width:90%; + margin:auto; + margin-top:60px; + display:block; +} +#tutorial { + width:85%; + display:block; + margin:auto; + margin-top:20px; +} +.task_done_button {float:right;cursor:pointer;font-size:12px;} +c10029.task_done_button:hover {color:#211C18;}; + +/* SCROLL BAR +---------------------------------------------------------------------------------- */ +/* Let's get this party started */ +::-webkit-scrollbar { + width: 12px; +} + +/* Track */ +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); +} + +/* Handle */ +::-webkit-scrollbar-thumb { + background: #A8DBC6; + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); +} +.half_div { + width:49%; + display:block; + float:left; + text-align:center; + margin-top:10%; +} +.half_tall { + height:200px; +} + +/* Search Result +--------------------------------------------------------------------------------- */ +.user_search_result_label { + float:left; + width:160px; + letter-spacing:1px; + display:block; + font-size:18px; + font-weight:bold; + text-align:left; + font-family:Helvetica; +} +.cat_search_result_label { + float:left; + width:170px; + display:block; + font-weight:bold; + text-align:left; +} + +/* MEDIA QUERIES +---------------------------------------------------------------------------------- */ +@media screen and (max-width:480px) { + #signup_form_container, #navbar, #search_box, .header_menu, #remember_me, + #remember_me_check {display:none} + + #index_left{ + height:300px; + width:100%; + } + + #tutorial_container{font-size:12px} + + #index_right{width:100%; margin-top:0px} + + #login_form_container { + width:100%; + float:left; + } + .signup_label{ + width:60%; + } + + div#dynamic_content{ + border-left:none; + width:100%; + } + + div#curtask1.task_view, div#curtask2.task_view, div#curtask3.task_view, + div#curtask4.task_view, div#curtask5.task_view{ + padding:none; + width:80% + } + + .dynamic_content_left{ + font-size:15px; + } + + .dynamic_content_right{ + font-size:15px; + } + +} + + diff --git a/eurilys4/web/css/wide.css b/eurilys4/web/css/wide.css new file mode 100644 index 00000000..82d68bf3 --- /dev/null +++ b/eurilys4/web/css/wide.css @@ -0,0 +1,815 @@ +@media screen and (min-width: 1200px) and (max-width: 2000px){ +html {width:100%; height:100%; overflow-x:hidden; font-family:Segoe UI; font-weight: lighter;} +body {width:100%; height:300px; display:block; margin:0px; + /*background-image:url('../img/bgw.jpg');*/ + background-color:#F3E8E6; +} + +h1{ + + font-size: 35px; + padding-left: 20px; + color: #FF5544; +} + +/* HEADER SECTION +------------------------------------------------------------------------------------------- */ +header { + width:100%; + height:90px; + background-color:#35283C; + display:block; +} +.header_menu a { + color:white; + text-decoration:none; + } + +textarea { + font-family:Segoe UI; font-weight:lighter;; +} + +#header_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; +} + +#login_form_container { + position:relative; + background-color:#35283C; + float:right; + width:90%; + height:130px; + margin-right:5%; + z-index:100; +} +#login_form { + font-family:Segoe UI; font-weight:lighter;; + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:15px; + z-index:200; +} +#login_form label { + color:#fff; + float:left; + width:35%; + margin-left:3px; +} + +#login_username , #login_password { + color:gray; + float:left; + margin-left:7px; + width:55%; +} +#login_submit { + float:right; + margin-right:5%; +} + +input#remember_me { + margin-top:20px;float:left; + width:auto; +} +label#remember_me { + float:left; font-size:12px; width:auto; margin-top:-20px; +} + +#edit_profil_container {width:90%; margin:auto; display:block;} +#edit_profil_container h3 {color:#007bc1;} +#edit_profile_form { + width:70%; + margin-top:20px; + margin-left:20px; +} +#edit_profile_form label { + float:left; + font-size:16px; + font-family:Segoe UI; + font-weight:lighter; + color:gray; + width:28%; +} + +#edit_profile_submit { + float:right; + margin-right:5%; +} + +#edit_profile_form input { + float:left; + height:28px; + font-size:17px; + width:60%; + margin-bottom:10px; +} + +#edit_profile_form input#edit_profile_submit { + float:right; + height:35px; + font-size:20px; + width:40%; + margin-bottom:10px; +} + +.header_menu a { + color:white; + text-decoration:none; +} +.header_menu { + float:right; margin-top:30px;height:60%; width:45%; + +} +.header_menu_button { + padding-top:8px; padding-bottom:8px; + width:28%; display:block;color:white; + margin-left:20px;margin-top:8px; text-align:center; + font-size:18px; cursor:pointer; float:left; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} +.header_menu_button:hover , .header_menu_button:active { + background-color:#6FBEC6;text-decoration:none; + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; +} + +.header_menu_button:hover{background-color:#ff5645;} + +.current_header_menu { + background-color:#6FBEC6; +} +#search_box { + float:left; margin-left:45px; height:25px; margin-top:45px; width:20%; +} +#search_box_filter { + float:left; height:30px; margin-top:45px; margin-left:5px; +} +#txtHint { + position:absolute; + display:block; + color:gray; + margin-top:73px; + margin-left:275px; + width:16%; + z-index:300; + border:solid 1px #dedede; + overflow:hidden; + border-bottom-right-radius: 6px; + border-bottom-left-radius: 6px; + -moz-border-bottom-right-radius: 6px; + -moz-border-bottom-left-radius: 6px; + box-shadow: 0px 0px 5px #999; + border-width: 3px 1px 1px; + border-style: solid; + border-color: #333 #DEDEDE #DEDEDE; + background-color: white; + +} +/* LOGO +----------------------------------------------------------------------------------------------------------------- */ +#fleur { + font-size:100px; + color:#FF5544; + display:inline-block; +} +#textdesu{ + color:#fff; + display:inline-block; + font-size:60px; + letter-spacing:-6px; + font-family:Trajan Pro; + margin-left:-10px; +} +#tagline { + font-family:Times New Roman; + font-size:12px; + letter-spacing:2px; + font-style:italic; + margin-top:-20px; + margin-left:15px; + color:#fff; +} + +/* SECTION +--------------------------------------------------------------------------------------------------------------------- */ +section {width:80%;background-color:#F9F9F9; height:680px; margin-left:auto; margin-right:auto; margin-top:40px; margin-bottom:40px; z-index:1; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} + +#index_left { + height:100%; + width:65%; + background-color:#f9f9f9; + float:left; +} +#index_right { + height:100%; + width:35%; + float:left; + padding-top:40px; +} +.signup_label { + width:65%; + background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; + border:none; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + margin-left:auto;margin-right:auto; letter-spacing:1px; + text-align:center; + font-size:25px; + font-family:Segoe UI; font-weight:lighter;; + font-weight:bold; + margin-top:170px; +} +#signup_form_container { + width:90%; + margin-left:auto; + margin-right:auto; + margin-top:10px; + background-color:#EBEBE9; + color:gray; + padding-top:20px; + height:350px; + display:block; +} +#signup_form { + width:90%; + margin-top:20px; + margin-left:20px; +} +#signup_form label { + float:left; + font-size:16px; + font-family:Segoe UI; font-weight:lighter;; + color:gray; + width:28%; +} +#signup_form input { + float:left; + height:20px; + font-size:20px; + width:60%; + margin-bottom:10px; +} +.signup_form_validation { + display:none; + padding-left:10px; + padding-top:5px; + padding-bottom:14px; +} +input#avatar_upload {font-size:12px;} + +#tutorial { + text-align:justify; + text-justify:inter-word; +} + +#tutorial_image { + width:100%; +} + +/* FOOTER SECTION +--------------------------------------------------------------------------------------------------------------------- */ +#footer_container { + width:80%; + height:100%; + margin-left:auto; + margin-right:auto; + display:block; + color:#fff; + font-size:12px; + text-align:center; +} + +footer { + width:100%; + background-color:#35283C; + height:80px; + display:block; + bottom:0px; +} + +/* NAVIGATION BAR +--------------------------------------------------------------------------------------------------------------------- */ +#navbar { + margin-left:auto; + display:block; + height:100%; + width:25%; + float:left; +} +#short_profile { + margin-top:30px; + width:80%; + margin-left:auto; + margin-right:auto; + height:150px; +} +#profile_picture { + width:100px; + float:left; +} +#profile_info { + margin-left:120px; + float:left; + color:gray; + font-size:14px; + color:gray; + width:120px; + position:absolute; +} +#profile_pic_upload { + clear:both; + margin-top:20px; +} +#category_list { + width:80%; + margin-left:auto; + margin-right:auto; +} +#category_list a { + color:#fff; + text-decoration:none; +} +#category_list ul { + list-style-image:url('../img/arrow.png'); + padding-top:5px; + margin-left:-10px; +} +#category_list ul li a { + cursor:pointer; + color:#6FBEC6; + padding-bottom:5px; +} +#category_list ul li a:hover { + color:#fff; +} + +#category_list ul li a:active{ + color:#ff5645; +} +#add_new_category , #add_task_link{ + color:gray; + cursor:pointer; +} +#add_task_link:hover , #add_new_category:hover { + color:#FF5544; +} +#add_task_link {display:none;} +#add_task_link a { + color:gray; + text-decoration:none; +} +#add_task_link a:hover { + color:#ff5544; +} + +#category_form { + width:100%; + height:180px; + background-color:#6FBEC6; + margin-top:5px; + color:#fff; + padding-top:15px; + display:none; +} +#category_form_inner { + width:90%; + height:90%; + margin:auto; +} +#category_form_inner input { + width:95%; +} +#category_item { + margin-top:5px; +} +#current_category { + color:#6FBEC6; +} + +#add_category { + font-size:11px; + cursor:pointer; +} +#add_category:hover { + color:gray; +} +#add_category_button { + width:80px; + text-align:center; +} +#category_title { + text-align:center; + padding-top:5px; + padding-bottom:5px; +} + +/* TASK DETAIL +--------------------------------------------------------------------------------------------------------------------- */ +#comment_textarea { + width:70%; + height:100px; + resize:none; +} + +#save_button_td { + display:none; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} +#task_attachment:hover { + color:#ff5544; +} + +#save_button_td:hover { + border-color:#0092dd; +} + +#edit_task_button, #save_edit_task { + display:block; + border-style:solid; + border-color:#007bc1; + margin-left:5%; + width:80px; + text-align:center; + font-size: 15px; + padding-top:5px; + padding-bottom:5px; +} + +#edit_task_button:hover { + border-color:#0092dd; +} + +#taskdetail_image { + height:100%; + width:auto; +} +.taskDetail { + width:90%; + margin:auto; +} + +/* ADD TASK +--------------------------------------------------------------------------------------------------------------------- */ +#task_name_input, #assignee_input, #deadline_input, #tag_input, #attachment_upload { + width:35%; +} +#add_task_button{ + display:block; + margin-left:22%; + border-style:solid; + border-color:#007bc1; + text-align:center; + width:80px; + font-size:15px; + padding-top:5px; + padding-bottom:5px; +} + +#add_task_button:hover { + border-color:#0092dd; +} +#add_task_container { + width:90%; + margin:auto; +} + +/* STYLING +--------------------------------------------------------------------------------------------------------------------- */ +.bold {font-weight:bold;} +.clear {clear:both;} +.left {float:left;} +.right {float:right;} +.left20 {margin-left:50px;} +.top10 {margin-top:10px;} +.top20 {margin-top:20px;} +.top45 {margin-top:45px;} +.top30 {margin-top:30px;} +.width100 {width:130px;} +.line10 {line-height:50%;} +a {text-decoration:none;} +#logout {color:#fff;} +.white {color:#fff;} +.cursorPointer {cursor:pointer;} + +.thin_line {display:block;height:8px;margin-left:0px;width:100%;background-color:#524459;} + +.link_blue {background-color:#007bc1; color:#fff; padding-left:10px; padding-right:10px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none;cursor:pointer; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +} +.link_blue:hover{background-color:#0092dd;text-decoration:none;} + +.link_blue_rect { + background-color:#007bc1; + color:#fff; + cursor:pointer; +} +.link_blue_rect:hover{ + background-color:#0092dd; +} + +.link_lightblue {background-color:#6FBEC6; color:#fff; padding-left:25px; padding-right:25px; padding-top:15px; padding-bottom:15px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +font-family:Segoe UI; font-weight:lighter;; margin-left:auto; margin-right:auto; +font-weight:bold; letter-spacing:1px; cursor:pointer; +font-size:20px; +} +.link_lightblue:hover{background-color:#9ad2d8;text-decoration:none;} + +.link_red {background-color:#FF5544; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#ff786b;text-decoration:none;} + +.link_tosca {background-color:#dba8a8; background-color:#A8DBC6; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_tosca:hover{background-color:#bae4d3;text-decoration:none;} + + +.link_red {background-color:#FA522C; color:#fff; padding-left:25px; padding-right:25px; padding-top:8px; padding-bottom:8px; +text-decoration:none;border:none; +-webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +-moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); +margin-left:auto;margin-right:auto; letter-spacing:1px; cursor:pointer; margin-right:10px; +} +.link_red:hover{background-color:#FAAA98;text-decoration:none;} + +.darkBlue {color:#007bc1;} +.darkBlueItalic {color:#007bc1; font-style:italic; font-size:13px;} +.darkBlueLink {color:#007bc1; cursor:pointer;} +.userprofile_link {cursor:pointer;} +.userprofile_link:hover {color:#0092dd;} +/* DYNAMIC CONTENT +------------------------------------------------------------------------------------------------- */ +#dynamic_content { + border-left: 2px solid gray; + display:block; + width:73%; + height:100%; + float:right; + overflow:auto; + color:#55565B; + position:relative; +} +.dynamic_content_head { + display:block; + height:30px; + padding-left:2%; + width:75%; + font-weight:bold; +} + +.dynamic_content_row { + display:block; + width:100%; +} + +.dynamic_content_left { + display:block; + width:18%; + padding-left:2%; + font-weight:bold; +} + +.dynamic_content_right { + display:block; + width:74%; + padding-left:2%; + text-align:justify; + text-justify:inter-word; +} +.task_view_category { + float:right; + margin-right:20px; + color:red; +} +.task_view { + width:90%; + display:block; + background-color:white; + opacity:0.8; + padding-top:10px; + padding-bottom:10px; + padding-right:10px; + padding-left:10px; + color:gray; + height:125px; + margin:auto; + -webkit-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -moz-box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + box-shadow: 2px 3px 5px rgba(50, 50, 50, 0.17); + -webkit-transition: opacity 0.7s linear; + -webkit-transition: all 0.7s ease-in-out; + -moz-transition: all 0.7s ease-in-out; + -o-transition: all 0.7s ease-in-out; + left:30px; +} +.task_view a:hover { + color:#ff5544; +} + +/* PROFILE CONTENT +------------------------------------------------------------------------------------------------- */ + +#profilebig { + padding:20px; + text-align:center; +} + +#upperprof{ +text-align:center; +} + +#upperprof img { +padding: 4px; +border: 1px solid rgb(204, 204, 204);} + +#namauser{ +width:230px;margin:auto;letter-spacing: 2px;background-color:#007bc1; + color:#fff; +font-size:20px; +text-transform:uppercase;margin-top:-50px;z-index: 99;position:relative; +} + +.headsdeh{ + background-color:#007bc1; + color:#fff; + width:230px; + font-size:17px;margin:auto; +} + + +.categoryList, #newCategoryAdded { + display:block;padding:10px; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; + color:#007bc1; + cursor:pointer; +} + +.categoryList:hover, #newCategoryAdded:hover { + background-color:#007bc1; + color:#fff; + -webkit-transition: opacity 0.5s linear; + -webkit-transition: all 0.5s ease-in-out; + -moz-transition: all 0.5s ease-in-out; + -o-transition: all 0.5s ease-in-out; +} + +#login_form input{margin-bottom:5px;} +#edit_profile_button {letter-spacing:0px;padding-left:8px; padding-right:8px;} +#edit_profile_button a {color:#fff; text-decoration:none;} +.ul_none {list-style:none; margin:auto; width:200px; margin-top:5px;} +.ul_none li {text-align:left;} +.red {color:#ff5544; font-weight:bold;} +.blue {color:#007bc1; font-weight:bold;} + +/* MAIN PAGE +--------------------------------------------------------------------------------- */ +#tutorial_container { + width:90%; + margin:auto; + margin-top:60px; + display:block; +} +#tutorial { + width:85%; + display:block; + margin:auto; + margin-top:20px; +} +.task_done_button {float:right;cursor:pointer;font-size:12px;} +.task_done_button:hover {color:#211C18;} + +/* SCROLL BAR +---------------------------------------------------------------------------------- */ +/* Let's get this party started */ +::-webkit-scrollbar { + width: 12px; +} + +/* Track */ +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); +} + +/* Handle */ +::-webkit-scrollbar-thumb { + background: #dba8a8; + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); +} +.half_div { + width:49%; + display:block; + float:left; + text-align:center; + margin-top:10%; +} +.half_tall { + height:200px; +} + +/* Search Result +--------------------------------------------------------------------------------- */ +.user_search_result_label { + float:left; + width:160px; + letter-spacing:1px; + display:block; + font-size:18px; + font-weight:bold; + text-align:left; + font-family:Helvetica; +} +.cat_search_result_label { + float:left; + width:170px; + display:block; + font-weight:bold; + text-align:left; +} + +/* MEDIA QUERIES +---------------------------------------------------------------------------------- */ +@media screen and (max-width:480px) { + #signup_form_container, #navbar, #search_box, .header_menu, #remember_me, + #remember_me_check {display:none} + + #index_left{ + height:300px; + width:100%; + } + + #tutorial_container{font-size:12px} + + #index_right{width:100%; margin-top:0px} + + #login_form_container { + width:100%; + float:left; + } + .signup_label{ + width:60%; + } + + div#dynamic_content{ + border-left:none; + width:100%; + } + + div#curtask1.task_view, div#curtask2.task_view, div#curtask3.task_view, + div#curtask4.task_view, div#curtask5.task_view{ + padding:none; + width:80% + } + + .dynamic_content_left{ + font-size:15px; + } + + .dynamic_content_right{ + font-size:15px; + } + + +} + diff --git a/eurilys4/web/img/arrow.png b/eurilys4/web/img/arrow.png new file mode 100644 index 00000000..4ad6f040 Binary files /dev/null and b/eurilys4/web/img/arrow.png differ diff --git a/eurilys4/web/img/avatar/avatar1.png b/eurilys4/web/img/avatar/avatar1.png new file mode 100644 index 00000000..390e4fc7 Binary files /dev/null and b/eurilys4/web/img/avatar/avatar1.png differ diff --git a/eurilys4/web/img/avatar/sharonloh.jpg b/eurilys4/web/img/avatar/sharonloh.jpg new file mode 100644 index 00000000..2eec5e95 Binary files /dev/null and b/eurilys4/web/img/avatar/sharonloh.jpg differ diff --git a/eurilys4/web/img/avatar1.png b/eurilys4/web/img/avatar1.png new file mode 100644 index 00000000..390e4fc7 Binary files /dev/null and b/eurilys4/web/img/avatar1.png differ diff --git a/eurilys4/web/img/bg.jpg b/eurilys4/web/img/bg.jpg new file mode 100644 index 00000000..39b1ae6b Binary files /dev/null and b/eurilys4/web/img/bg.jpg differ diff --git a/eurilys4/web/img/bgw.jpg b/eurilys4/web/img/bgw.jpg new file mode 100644 index 00000000..0d47710a Binary files /dev/null and b/eurilys4/web/img/bgw.jpg differ diff --git a/eurilys4/web/img/check.png b/eurilys4/web/img/check.png new file mode 100644 index 00000000..368ce423 Binary files /dev/null and b/eurilys4/web/img/check.png differ diff --git a/eurilys4/web/img/done.png b/eurilys4/web/img/done.png new file mode 100644 index 00000000..2edec562 Binary files /dev/null and b/eurilys4/web/img/done.png differ diff --git a/eurilys4/web/img/eurilys_comic.png b/eurilys4/web/img/eurilys_comic.png new file mode 100644 index 00000000..c854093b Binary files /dev/null and b/eurilys4/web/img/eurilys_comic.png differ diff --git a/eurilys4/web/img/favicon.ico b/eurilys4/web/img/favicon.ico new file mode 100644 index 00000000..cee53ad0 Binary files /dev/null and b/eurilys4/web/img/favicon.ico differ diff --git a/eurilys4/web/img/logo.png b/eurilys4/web/img/logo.png new file mode 100644 index 00000000..dae9a215 Binary files /dev/null and b/eurilys4/web/img/logo.png differ diff --git a/eurilys4/web/img/no.png b/eurilys4/web/img/no.png new file mode 100644 index 00000000..06868fd9 Binary files /dev/null and b/eurilys4/web/img/no.png differ diff --git a/eurilys4/web/img/tutorial.png b/eurilys4/web/img/tutorial.png new file mode 100644 index 00000000..059a73fe Binary files /dev/null and b/eurilys4/web/img/tutorial.png differ diff --git a/eurilys4/web/img/yes.png b/eurilys4/web/img/yes.png new file mode 100644 index 00000000..86fa4e7d Binary files /dev/null and b/eurilys4/web/img/yes.png differ diff --git a/eurilys4/web/index.jsp b/eurilys4/web/index.jsp new file mode 100644 index 00000000..e4690afc --- /dev/null +++ b/eurilys4/web/index.jsp @@ -0,0 +1,80 @@ +<%@page import="service.dbConnection"%> +<%@page import="java.sql.Connection"%> +<%@page import="org.json.*"%> +<%@page import="javax.print.attribute.PrintRequestAttribute"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@include file="src/header.jsp"%> +<% session.invalidate(); %> + + +
    +
    +
    +
    + tutorial_pic +
    +
    + Eurilys is an online to-do-list website which is so easy to use, user-friendly, and the most important + of all, it's completely FREE! +
    + You can add task, category for each task, and you can write down all the task's details here. +
    + No more papers, pens, and confusion. Eurilys is here to be your organization's partner. +
    +
    +
    +
    + <% if ("failed".equals(request.getParameter("login_status"))) { %> +
    Login Failed
    + <% } %> +
    +
    +
    + + +
    +
    + + +
    + <% if ("failed".equals(request.getParameter("register_status"))) { %> +
    Sign Up Failed
    + <% } %> + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    + +<%@ include file="src/footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/web/js/animation.js b/eurilys4/web/js/animation.js new file mode 100644 index 00000000..7e90638c --- /dev/null +++ b/eurilys4/web/js/animation.js @@ -0,0 +1,509 @@ +function toggle_visibility(id) { + var e = document.getElementById(id); + if(e.style.display == 'block') + e.style.display = 'none'; + else + e.style.display = 'block'; +} + +function add_category() { + var t = "
  • "; + t += ""; + t += document.getElementById("add_category_name").value; + t += ""; + t += "
  • "; + document.getElementById("category_item").innerHTML += t; +} + +var regValid = 0; +function regCheck() { + var username = document.getElementById("reg_username").value; + var password = document.getElementById("reg_password").value; + var confirm = document.getElementById("reg_confirm").value; + var name = document.getElementById("reg_name").value; + var email = document.getElementById("reg_email").value; + var birthdate = document.getElementById("reg_birthdate").value; + var avatar = document.getElementById("avatar_upload").value; + //alert(username + " " + password+ " " + confirm + " " +email + " " + birthdate + " " +avatar); + + //check username + if ((username.length > 4) && (username != password)) { + document.getElementById("username_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("username_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("username_validation").style.display = "block"; + + //check password + if ((password.length > 7) && (password != username) && (password != email)) { + document.getElementById("password_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("password_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("password_validation").style.display = "block"; + + //check confirm + //alert("confirm = " + confirm); + if ((confirm != password) || (confirm == '') || (confirm == null)) { + document.getElementById("confirm_validation").src = "img/no.png"; + regValid = 0; + } + else + if ( (confirm == password) && (password.length > 7) ) { + document.getElementById("confirm_validation").src = "img/yes.png"; + regValid = 1; + } + document.getElementById("confirm_validation").style.display = "block"; + + //check name + if (name.indexOf(' ') >= 0) { + document.getElementById("name_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("name_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("name_validation").style.display = "block"; + + //check email + var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i; + if ((email==password) || (email.search(emailRegEx) == -1)) { + document.getElementById("email_validation").src = "img/no.png"; + regValid = 0; + } + else { + document.getElementById("email_validation").src = "img/yes.png"; + regValid = 1; + } + document.getElementById("email_validation").style.display = "block"; + + //check birthday + if (birthdate != "") { + document.getElementById("birthdate_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("birthdate_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("birthdate_validation").style.display = "block"; + + //check avatar + var extension = avatar.split('.'); + if ( (extension[1] == "jpg") || (extension[1] == "jpeg") ) { + document.getElementById("avatar_validation").src = "img/yes.png"; + regValid = 1; + } + else { + document.getElementById("avatar_validation").src = "img/no.png"; + regValid = 0; + } + document.getElementById("avatar_validation").style.display = "block"; + + //alert("regvalid = " + regValid); + if (regValid == 1) { + document.getElementById('signup_submit').removeAttribute("disabled"); + //alert("yey"); + } + else { + document.getElementById('signup_submit').disabled = "disabled"; + //alert("Fill your registration form correctly"); + } +} + +function signup() { + if (regValid == 1) { + window.location.href = "src/Dashboard.php"; + } + else { + alert("Fill your registration form correctly"); + } +} + +function checkTaskName() { + var taskName = document.getElementById('task_name_input').value; + var taskNameValid = 0; + var iChars = "~=-_^&.\\|*|,\":<>[]{}`\';()@&$#%"; + for (var i = 0; i < taskName.length; i++) { + if (iChars.indexOf(taskName.charAt(i)) != -1){ + taskNameValid = 1; + break; + } + } + + if ((taskName.length > 25) || (taskNameValid == 1) || (taskName == "")) { + //tidak valid + document.getElementById('taskname_validation').src = "../img/no.png"; + } + else { + //valid + document.getElementById('taskname_validation').src = "../img/yes.png"; + } + document.getElementById('taskname_validation').style.display = "block"; +} + +function checkTaskAttachment() { + var attachmentName = document.getElementById('attachment_file').value; + var dot = "."; + if (attachmentName.indexOf(dot) != -1) { + //valid + document.getElementById('task_attachment_validation').src = "../img/yes.png"; + } + else { + //not valid + document.getElementById('task_attachment_validation').src = "../img/no.png"; + } + document.getElementById('task_attachment_validation').style.display = "block"; +} + +function getUrlVars() { + var vars = {}; + var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { + vars[key] = value; + }); + return vars; +} + +function addCatName(){ + var first = getUrlVars()["cat_name"]; + document.getElementById("cat_name").setAttribute('value',first); +} + +function showSearchHint(str) { + document.getElementById('txtHint').style.display = "block"; + if (str.length==0) { + document.getElementById("txtHint").innerHTML=""; + return; + } + + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("txtHint").innerHTML = xmlhttp.responseText; + } + } + var selectOption = document.getElementById("search_box_filter"); + var filter = selectOption.options[selectOption.selectedIndex].value; + + xmlhttp.open("GET", "../ServletHandler?type=search_result&keyword="+str+"&filter="+filter, true); + xmlhttp.send(); +} + +function AddCategoryAssigneHint(str) { + document.getElementById('category_asignee_autocomplete').style.display = "block"; + if (str.length==0) { + document.getElementById("category_asignee_autocomplete").innerHTML=""; + return; + } + + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("category_asignee_autocomplete").innerHTML = xmlhttp.responseText; + } + } + + var url="addcategory_autocomplete.jsp?hint="+str; + xmlhttp.open("GET", url, true); + xmlhttp.send(); +} + +function EditTaskAssigneHint(str) { + document.getElementById('edit_task_asignee_autocomplete').style.display = "block"; + if (str.length==0) { + document.getElementById("edit_task_asignee_autocomplete").innerHTML=""; + return; + } + + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("edit_task_asignee_autocomplete").innerHTML = xmlhttp.responseText; + } + } + + xmlhttp.open("GET", "../ServletHandler?type=assignee_autocomplete&keyword="+str, true); + xmlhttp.send(); +} + +function addCategoryAssigne(userID) { + var user = document.getElementById('cat_ass_'+userID).innerHTML; + document.getElementById('add_category_asignee_name').value += user; + document.getElementById('add_category_asignee_name').value += ", "; + document.getElementById("category_asignee_autocomplete").innerHTML=""; + document.getElementById("add_category_asignee_name_auto").value = ""; + +} + +function addEditTaskAssigne(userID) { + var user = document.getElementById('edittask_ass_'+userID).innerHTML; + document.getElementById('edit_task_assignee').value += user; + document.getElementById('edit_task_assignee').value += ", "; + document.getElementById("edit_task_asignee_autocomplete").innerHTML=""; + document.getElementById("edit_task_assignee_auto").value = ""; + +} +function addAddTaskAssigne(userID) { + var user = document.getElementById('addtask_ass_'+userID).innerHTML; + document.getElementById('add_task_assignee_input').value += user; + document.getElementById('add_task_assignee_input').value += ", "; + document.getElementById("add_task_asignee_autocomplete").innerHTML=""; + document.getElementById("add_task_assignee_auto").value = ""; +} + +function searchResult(resultID, resultType) { + document.getElementById('txtHint').style.display = "none"; + + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("dynamic_content").innerHTML = xmlhttp.responseText; + } + } + + var s = ""; + if (resultType == "user") { + s = "search_result.jsp?q="+resultID+"&type=user"; + xmlhttp.open("GET", s, true); + xmlhttp.send(); + } + else + if (resultType == "category") { + s = "search_result.jsp?q="+resultID+"&type=category"; + xmlhttp.open("GET", s, true); + xmlhttp.send(); + } + else + if (resultType == "task") { + window.location.href = "task_detail.jsp?task_id="+resultID; + } +} + +function viewTask(taskID) { + window.location.href = "task_detail.jsp?task_id="+taskID; +} + +function generateTask(categoryName) { + alert("masuk!"); + document.getElementById("dynamic_content").innerHTML = ""; + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + + /* + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + document.getElementById("dynamic_content").innerHTML = xmlhttp.responseText; + } + }*/ + + document.getElementById("add_task_link").style.display = "block"; + document.getElementById("add_task").setAttribute('href',"addtask.jsp?cat_name="+categoryName); + + //var url="category_task.jsp?categoryName="+categoryName; + xmlhttp.open("GET", "../task/get_category_task?category_name="+categoryName, true); + xmlhttp.send(); +} + +function finishTask(taskID) { + var finishTaskConfirm = confirm("Are you sure this task has been completely done?"); + if (finishTaskConfirm == true) + { + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById("taskHandler_"+taskID).innerHTML = ""; + } + } + } + xmlhttp.open('GET', '../ServletHandler?type=finish_task&task_id=' + taskID, true); + xmlhttp.send(null); + } +} + +function deleteTask(taskID) { + var deleteTaskConfirm = confirm("Are you sure you want to delete this task?"); + if (deleteTaskConfirm == true) { + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById(taskID).parentNode.removeChild(document.getElementById(taskID)); + } + } + } + //xmlhttp.open('GET', '../task/delete_task?task_id=' + taskID, true); + xmlhttp.open('GET', '../ServletHandler?type=delete_task&task_id=' + taskID, true); + xmlhttp.send(null); + } +} + +function deleteComment(commentID) { + var deleteCommentConfirm = confirm("Delete this comment?"); + if (deleteCommentConfirm == true) { //GET servlet + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById("comment_"+commentID).parentNode.removeChild(document.getElementById("comment_"+commentID)); + } + } + } + xmlhttp.open('GET', '../ServletHandler?type=delete_comment&comment_id='+commentID, true); + //xmlhttp.open('GET', '../task/delete_comment?comment_id='+commentID, true); + xmlhttp.send(null); + } +} + +function deleteTaskAssigne(taskID, userID) { + var deleteConfirm = confirm("Delete " + userID + " from this task?"); + if (deleteConfirm == true) { + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById("user_"+userID).parentNode.removeChild(document.getElementById("user_"+userID)); + } + } + } + xmlhttp.open('GET', '../ServletHandler?type=edittask_deleteAssignee&task_id='+taskID+'&user_id='+userID, true); + xmlhttp.send(null); + } +} + +function deleteTaskTag(taskID, tagName) { + var deleteConfirm = confirm("Delete " + tagName + " from this task tag?"); + if (deleteConfirm == true) { + if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari + xmlhttp=new XMLHttpRequest(); + } + else {// code for IE6, IE5 + xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); + } + xmlhttp.onreadystatechange=function() { + if (xmlhttp.readyState==4 && xmlhttp.status==200) { + if (xmlhttp.responseText == 1) { + document.getElementById("tag_"+tagName).parentNode.removeChild(document.getElementById("tag_"+tagName)); + } + } + } + xmlhttp.open('GET', '../ServletHandler?type=edittask_deleteTag&task_id='+taskID+'&tag_name='+tagName, true); + xmlhttp.send(null); + } +} + +function editProfileCheck() { + var username = document.getElementById("edit_username").value; + var email = document.getElementById("edit_email").value; + var password = document.getElementById("edit_password").value; + var confirm = document.getElementById("edit_password_confirm").value; + var name = document.getElementById("fullname").value; + var birthdate = document.getElementById("birthdate").value; + var avatar = document.getElementById("avatar").value; + + var passwordValid = 1; + //check password + if ((password.length > 7) && (password != username) && (password != email)) { + document.getElementById("password_validation").src = "../img/yes.png"; + passwordValid = 1; + } + else { + document.getElementById("password_validation").src = "../img/no.png"; + passwordValid = 0; + } + document.getElementById("password_validation").style.display = "block"; + + var confirmValid = 1; + //check confirm + if ((confirm != password) || (confirm == '') || (confirm == null)) { + document.getElementById("confirm_validation").src = "../img/no.png"; + confirmValid = 0; + } + else + if ( (confirm == password) && (password.length > 7) ) { + document.getElementById("confirm_validation").src = "../img/yes.png"; + confirmValid = 1; + } + document.getElementById("confirm_validation").style.display = "block"; + + if ((password == confirm) && (password.length == 0)) { + passwordValid = 1; + confirmValid = 1; + document.getElementById("password_validation").src = "../img/yes.png"; + document.getElementById("confirm_validation").src = "../img/yes.png"; + } + + var nameValid = 1; + //check name + if (name.indexOf(' ') >= 0) { + document.getElementById("name_validation").src = "../img/yes.png"; + nameValid = 1; + } + else { + document.getElementById("name_validation").src = "../img/no.png"; + nameValid = 0; + } + document.getElementById("name_validation").style.display = "block"; + + if ((passwordValid == 1) & (confirmValid == 1) & (nameValid == 1)) { + document.getElementById('edit_profile_submit').removeAttribute("disabled"); + } + else { + document.getElementById('edit_profile_submit').disabled = "disabled"; + } +} \ No newline at end of file diff --git a/eurilys4/web/src/addtask.jsp b/eurilys4/web/src/addtask.jsp new file mode 100644 index 00000000..86597fa3 --- /dev/null +++ b/eurilys4/web/src/addtask.jsp @@ -0,0 +1,83 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@include file="logged_in_header.jsp"%> + + +
    + <%@include file="navigation_bar.jsp"%> +
    + <% + String cat_name = (String) request.getParameter("cat_name"); + %> +
    +
    + Add New Task +
    +
    +
    +
    Task Name
    +
    + + +
    +
    + +
    +
    Attachment
    +
    + + +
    +
    + +
    +
    Add more attachment
    +
    + + +
    +
    + +
    +
    Add more attachment
    +
    + + +
    +
    + + +
    +
    Deadline
    +
    + +
    +
    + +
    +
    Assignee
    +
    +
    + +
    +
    + +
    +
    Tag
    +
    + +
    +
    + + + +
    + +
    +
    +
    +
    +
    + +<%@include file="footer.jsp"%> diff --git a/eurilys4/web/src/dashboard.jsp b/eurilys4/web/src/dashboard.jsp new file mode 100644 index 00000000..4d6daecb --- /dev/null +++ b/eurilys4/web/src/dashboard.jsp @@ -0,0 +1,73 @@ +<%@include file="logged_in_header.jsp"%> + +
    + + <%@include file="navigation_bar.jsp"%> +
    + + <% + String username = (String) session.getAttribute("username"); + //URL taskURL = new URL("http://localhost:8084/eurilys4-service/task/all_task?username=" + session.getAttribute("username")); + URL taskURL = new URL("http://eurilys.ap01.aws.af.cm/task/all_task?username=" + session.getAttribute("username")); + HttpURLConnection taskConn = (HttpURLConnection) taskURL.openConnection(); + taskConn.setRequestMethod("GET"); + taskConn.setRequestProperty("Accept", "application/json"); + if (taskConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + taskConn.getResponseCode()); + } + BufferedReader taskBr = new BufferedReader(new InputStreamReader((taskConn.getInputStream()))); + String taskOutput; + String taskJSONObject = ""; + while ((taskOutput = taskBr.readLine()) != null) { + taskJSONObject += taskOutput; + } + taskConn.disconnect(); + + //Parse taskJSONObject + JSONTokener taskTokener = new JSONTokener(taskJSONObject); + JSONArray taskroot = new JSONArray(taskTokener); + + for (int i=0; i
    "); + if (task_creator.equals(username)) { + out.println("
    Delete
    "); + out.println("
        |    
    "); + } + out.println("
    "); + if ("0".equals(task_status)) { + out.println("
    Mark as Finished
    "); + } else { + out.println(""); + } + out.println("
    "); + out.println("
    Task Name
    "); + out.println("
    " +task_name+ "


    "); + + out.println("
    Deadline
    "); + out.println("
    " +task_deadline+ "


    "); + + out.println("
    Tag
    "); + out.println("
    "); + JSONArray tag_list = task.getJSONArray("tag_list"); + for (int j=0; j
    "); + + out.println("
    "+task_category+"

    "); + out.println("
    "); + } + %> +

    +
    +
    + +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/web/src/edit_profile.jsp b/eurilys4/web/src/edit_profile.jsp new file mode 100644 index 00000000..2589c830 --- /dev/null +++ b/eurilys4/web/src/edit_profile.jsp @@ -0,0 +1,67 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.sql.DriverManager"%> +<%@page import="java.sql.PreparedStatement"%> +<%@include file="logged_in_header.jsp"%> + +
    + + <%@include file="navigation_bar.jsp"%> + <% + //URL userDetailURL = new URL("http://localhost:8084/eurilys4-service/user/user_detail?username=" + session.getAttribute("username")); + URL userDetailURL = new URL("http://eurilys.ap01.aws.af.cm/user/user_detail?username=" + session.getAttribute("username")); + HttpURLConnection userDetailConn = (HttpURLConnection) userDetailURL.openConnection(); + userDetailConn.setRequestMethod("GET"); + userDetailConn.setRequestProperty("Accept", "application/json"); + if (userDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + userDetailConn.getResponseCode()); + } + BufferedReader userDetailBr = new BufferedReader(new InputStreamReader((userDetailConn.getInputStream()))); + String userDetailOutput; + String userDetailJSONObject = ""; + while ((userDetailOutput = userDetailBr.readLine()) != null) { + userDetailJSONObject += userDetailOutput; + } + userDetailConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener userDetailTokener = new JSONTokener(userDetailJSONObject); + JSONObject userDetailroot = new JSONObject(userDetailTokener); + String password = userDetailroot.getString("password"); + String fullname = userDetailroot.getString("fullname"); + String birthdate = userDetailroot.getString("birthdate"); + String email = userDetailroot.getString("email"); + //String avatar = userDetailroot.getString("avatar"); + %> +
    +
    +

    Edit Profile

    +
    + <%= session.getAttribute("username") %> + "> + + +

    Change Password

    + + + + + + + +
    + +

    Change Details

    + + + +
    +
    + + +
    +
    +
    +
    +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/web/src/edit_task.jsp b/eurilys4/web/src/edit_task.jsp new file mode 100644 index 00000000..81bbe93e --- /dev/null +++ b/eurilys4/web/src/edit_task.jsp @@ -0,0 +1,123 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@page import="java.sql.Blob"%> +<%@page import="java.util.List"%> +<%@page import="java.util.ArrayList"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.PreparedStatement"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.sql.DriverManager"%> +<%@include file="logged_in_header.jsp"%> +
    + + <%@include file="navigation_bar.jsp"%> + +
    +
    + <% + String taskID = (String) request.getParameter("task_id"); + //URL taskDetailURL = new URL("http://localhost:8084/eurilys4-service/task/task_detail?task_id=" + taskID); + URL userDetailURL = new URL("http://eurilys.ap01.aws.af.cm/task/task_detail?task_id=" + taskID); + HttpURLConnection taskDetailConn = (HttpURLConnection) taskDetailURL.openConnection(); + taskDetailConn.setRequestMethod("GET"); + taskDetailConn.setRequestProperty("Accept", "application/json"); + if (taskDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + taskDetailConn.getResponseCode()); + } + BufferedReader taskDetailBr = new BufferedReader(new InputStreamReader((taskDetailConn.getInputStream()))); + String taskDetailOutput; + String taskDetailJSONObject = ""; + while ((taskDetailOutput = taskDetailBr.readLine()) != null) { + taskDetailJSONObject += taskDetailOutput; + } + taskDetailConn.disconnect(); + //Parse userDetailJSONObject + JSONTokener taskDetailTokener = new JSONTokener(taskDetailJSONObject); + JSONObject taskDetailroot = new JSONObject(taskDetailTokener); + + String task_name = taskDetailroot.getString("task_name"); + String task_id = taskDetailroot.getString("task_id"); + String task_deadline = taskDetailroot.getString("task_deadline"); + String task_status = taskDetailroot.getString("task_status"); + String task_category = taskDetailroot.getString("task_category"); + String task_creator = taskDetailroot.getString("task_creator"); + + JSONArray comment_id = taskDetailroot.getJSONArray("comment_id"); + JSONArray comment_timestamp = taskDetailroot.getJSONArray("comment_timestamp"); + JSONArray comment_content = taskDetailroot.getJSONArray("comment_content"); + JSONArray comment_creator = taskDetailroot.getJSONArray("comment_creator"); + + JSONArray tag_list = taskDetailroot.getJSONArray("tag_list"); + JSONArray task_assignee = taskDetailroot.getJSONArray("task_assignee"); + %> + +
    + <%=task_name%> +
    + +
    + + + +
    +
    Task Name
    +
    <%=task_name%>
    +
    +
    +
    Status
    +
    + <% if (task_status.equals("0")) { %> + Not Finished Yet + <% } else { %> + Finished + <% } %> +
    +
    +
    +
    Attachment
    +
    + Belom dibikin. Hahaha. +
    +
    + +
    +
    Deadline
    +
    + +
    +
    + +
    +
    Assignee
    +
    + <% for (int i=0; i +
    +     + <%= task_assignee.get(i) %> +
    +
    + <% } %> +
    +
    + +
    +
    +
    +
    +
    Tag
    +
    + <% for (int i=0; i +
    +     + <%=tag_list.get(i)%> +
    +
    + <% } %> +
    + +
    +
    +
    +
    +
    +
    +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/web/src/footer.jsp b/eurilys4/web/src/footer.jsp new file mode 100644 index 00000000..35ebb31c --- /dev/null +++ b/eurilys4/web/src/footer.jsp @@ -0,0 +1,12 @@ + +
    +
    + +
    + + \ No newline at end of file diff --git a/eurilys4/web/src/header.jsp b/eurilys4/web/src/header.jsp new file mode 100644 index 00000000..22681bdf --- /dev/null +++ b/eurilys4/web/src/header.jsp @@ -0,0 +1,22 @@ + + + + + + + + + + Eurilys + + + + +
    +
    +
    + logo +
    +
    +
    +
    \ No newline at end of file diff --git a/eurilys4/web/src/logged_in_header.jsp b/eurilys4/web/src/logged_in_header.jsp new file mode 100644 index 00000000..9a5f2f30 --- /dev/null +++ b/eurilys4/web/src/logged_in_header.jsp @@ -0,0 +1,42 @@ + +<% +if (session.getAttribute("fullname") == null) { + response.sendRedirect("../index.jsp"); +} +%> + + + + + + + + + Eurilys + + + + +
    +
    +
    + +
    + + +
    + + + +
    +
    +
    \ No newline at end of file diff --git a/eurilys4/web/src/navigation_bar.jsp b/eurilys4/web/src/navigation_bar.jsp new file mode 100644 index 00000000..4a83cd7b --- /dev/null +++ b/eurilys4/web/src/navigation_bar.jsp @@ -0,0 +1,160 @@ +<%@page import="java.net.URLDecoder"%> +<%@page import="org.json.*"%> +<%@page import="java.io.InputStreamReader"%> +<%@page import="java.io.BufferedReader"%> +<%@page import="java.net.HttpURLConnection"%> +<%@page import="java.net.URL"%> +<%@page import="java.sql.Blob"%> + + +<% + String user_name = (String) session.getAttribute("username"); + //URL url = new URL("http://localhost:8084/eurilys4-service/category/get_list?username=" + session.getAttribute("username")); + URL url = new URL("http://eurilys.ap01.aws.af.cm/category/get_list?username=" + session.getAttribute("username")); + HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); + httpConn.setRequestMethod("GET"); + httpConn.setRequestProperty("Accept", "application/json"); + if (httpConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + httpConn.getResponseCode()); + } + BufferedReader br = new BufferedReader(new InputStreamReader((httpConn.getInputStream()))); + String output; + String categoryJSONObject = ""; + while ((output = br.readLine()) != null) { + categoryJSONObject += output; + } + httpConn.disconnect(); + + //Parse categoryJSONObject + JSONTokener tokener = new JSONTokener(categoryJSONObject); + JSONArray root = new JSONArray(tokener); +%> + + + + \ No newline at end of file diff --git a/eurilys4/web/src/profile.jsp b/eurilys4/web/src/profile.jsp new file mode 100644 index 00000000..6f864a00 --- /dev/null +++ b/eurilys4/web/src/profile.jsp @@ -0,0 +1,169 @@ +<%@page import="org.json.*"%> +<%@page import="java.io.InputStreamReader"%> +<%@page import="java.io.BufferedReader"%> +<%@page import="java.net.HttpURLConnection"%> +<%@page import="java.net.URL"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.sql.DriverManager"%> +<%@page import="java.sql.PreparedStatement"%> + + + + + + + + + + + Eurilys + + + + +
    +
    +
    + +
    + + +
    + + + +
    +
    +
    + + +
    + <%@include file="navigation_bar.jsp"%> + <% + //URL userDetailURL = new URL("http://localhost:8084/eurilys4-service/user/user_detail?username=" + session.getAttribute("username")); + URL userDetailURL = new URL("http://eurilys.ap01.aws.af.cm/user/user_detail?username=" + session.getAttribute("username")); + HttpURLConnection userDetailConn = (HttpURLConnection) userDetailURL.openConnection(); + userDetailConn.setRequestMethod("GET"); + userDetailConn.setRequestProperty("Accept", "application/json"); + if (userDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + userDetailConn.getResponseCode()); + } + BufferedReader userDetailBr = new BufferedReader(new InputStreamReader((userDetailConn.getInputStream()))); + String userDetailOutput; + String userDetailJSONObject = ""; + while ((userDetailOutput = userDetailBr.readLine()) != null) { + userDetailJSONObject += userDetailOutput; + } + userDetailConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener userDetailTokener = new JSONTokener(userDetailJSONObject); + JSONObject userDetailroot = new JSONObject(userDetailTokener); + String fullname = userDetailroot.getString("fullname"); + String birthdate = userDetailroot.getString("birthdate"); + String email = userDetailroot.getString("email"); + %> +
    +
    +
    + " alt=""/> +
    <%=fullname%>
    +
    +

    + <%=session.getAttribute("username")%> +
    + <%=email%> +
    + <%=birthdate%> +



    + <% if ("ok".equals(request.getParameter("profileupdate"))) { + session.setAttribute("fullname", fullname); + %> +
    Profile has been successfully updated
    + <% } else if ("failed".equals(request.getParameter("profileupdate"))) { %> +
    Profile NOT has been successfully updated.
    + <% } %> +
    + +
    +
    +
    Current Tasks
    + <% + //URL currentTaskURL = new URL("http://localhost:8084/eurilys4-service/user/current_task?username=" + session.getAttribute("username")); + URL currentTaskURL = new URL("http://eurilys.ap01.aws.af.cm/user/current_task?username=" + session.getAttribute("username")); + HttpURLConnection currentTaskConn = (HttpURLConnection) currentTaskURL.openConnection(); + currentTaskConn.setRequestMethod("GET"); + currentTaskConn.setRequestProperty("Accept", "application/json"); + if (currentTaskConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + currentTaskConn.getResponseCode()); + } + BufferedReader currentTaskBr = new BufferedReader(new InputStreamReader((currentTaskConn.getInputStream()))); + String currentTaskOutput; + String currentTaskJSONObject = ""; + while ((currentTaskOutput = currentTaskBr.readLine()) != null) { + currentTaskJSONObject += currentTaskOutput; + } + currentTaskConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener currentTaskTokener = new JSONTokener(currentTaskJSONObject); + JSONArray currentTaskRoot = new JSONArray(currentTaskTokener); + + for (int i=0; i + + <% + } + %> +
    +
    +
    Finished Tasks
    + <% + //currentTaskURL = new URL("http://localhost:8084/eurilys4-service/user/finished_task?username=" + session.getAttribute("username")); + currentTaskURL = new URL("http://eurilys.ap01.aws.af.cm/user/finished_task?username=" + session.getAttribute("username")); + currentTaskConn = (HttpURLConnection) currentTaskURL.openConnection(); + currentTaskConn.setRequestMethod("GET"); + currentTaskConn.setRequestProperty("Accept", "application/json"); + if (currentTaskConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + currentTaskConn.getResponseCode()); + } + currentTaskBr = new BufferedReader(new InputStreamReader((currentTaskConn.getInputStream()))); + currentTaskOutput = ""; + currentTaskJSONObject = ""; + while ((currentTaskOutput = currentTaskBr.readLine()) != null) { + currentTaskJSONObject += currentTaskOutput; + } + currentTaskConn.disconnect(); + + //Parse userDetailJSONObject + currentTaskTokener = new JSONTokener(currentTaskJSONObject); + currentTaskRoot = new JSONArray(currentTaskTokener); + + for (int i=0; i + + <% + } + %> +
    +
    +
    +
    + +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/web/src/search_result.jsp b/eurilys4/web/src/search_result.jsp new file mode 100644 index 00000000..6a37aef1 --- /dev/null +++ b/eurilys4/web/src/search_result.jsp @@ -0,0 +1,92 @@ +<%@page import="org.json.JSONArray"%> +<%@page import="org.json.JSONObject"%> +<%@page import="org.json.JSONTokener"%> +<%@page import="java.io.InputStreamReader"%> +<%@page import="java.io.BufferedReader"%> +<%@page import="java.net.HttpURLConnection"%> +<%@page import="java.net.URL"%> +<%@page import="java.util.Iterator"%> +<%@page import="java.util.List"%> +<%@page import="java.util.ArrayList"%> +<%@page language="java" import ="java.sql.*" %> + +<% + String q = request.getParameter("q"); + String type = request.getParameter("type"); + String buffer = ""; + + ResultSet search_result = null; + + if (type.equals("user")) { + //URL userDetailURL = new URL("http://localhost:8084/eurilys4/user/user_detail?username=" + q); + URL userDetailURL = new URL("http://eurilys.ap01.aws.af.cm/user/user_detail?username=" + q); + HttpURLConnection userDetailConn = (HttpURLConnection) userDetailURL.openConnection(); + userDetailConn.setRequestMethod("GET"); + userDetailConn.setRequestProperty("Accept", "application/json"); + if (userDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + userDetailConn.getResponseCode()); + } + BufferedReader userDetailBr = new BufferedReader(new InputStreamReader((userDetailConn.getInputStream()))); + String userDetailOutput; + String userDetailJSONObject = ""; + while ((userDetailOutput = userDetailBr.readLine()) != null) { + userDetailJSONObject += userDetailOutput; + } + userDetailConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener userDetailTokener = new JSONTokener(userDetailJSONObject); + JSONObject userDetailroot = new JSONObject(userDetailTokener); + String user_name = userDetailroot.getString("username"); + String fullname = userDetailroot.getString("fullname"); + String birthdate = userDetailroot.getString("birthdate"); + String email = userDetailroot.getString("email"); + String avatar = userDetailroot.getString("avatar"); + + buffer = "
    "+fullname+"


    "; + buffer = buffer + "
    Username
    "+user_name+"

    "; + buffer = buffer + "
    Email
    "+email+"

    "; + buffer = buffer + "
    Birthdate
    "+birthdate+"
    "; + + } + else + if (type.equals("category")) { + //call search/category?id= + //URL searchURL = new URL("http://localhost:8084/eurilys4/search/category?id=" + q); + URL searchURL = new URL("http://eurilys.ap01.aws.af.cm/search/category?id=" + q); + HttpURLConnection searchConn = (HttpURLConnection) searchURL.openConnection(); + searchConn.setRequestMethod("GET"); + searchConn.setRequestProperty("Accept", "application/json"); + if (searchConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + searchConn.getResponseCode()); + } + BufferedReader searchBr = new BufferedReader(new InputStreamReader((searchConn.getInputStream()))); + String searchOutput; + String searchJSONObject = ""; + while ((searchOutput = searchBr.readLine()) != null) { + searchJSONObject += searchOutput; + } + searchConn.disconnect(); + + //Parse userDetailJSONObject + JSONTokener searchTokener = new JSONTokener(searchJSONObject); + JSONObject searchRoot = new JSONObject(searchTokener); + + buffer += "

    "; + buffer += "
    Category Name
    "+ searchRoot.getString("cat_name")+"
    "; + buffer += "

    "; + buffer += "
    Creator
    " + searchRoot.getString("cat_creator") +"
    "; + buffer += "

    "; + buffer += "
    List of Task
    "; + JSONArray task_list = searchRoot.getJSONArray("task"); + for (int i=0; i \ No newline at end of file diff --git a/eurilys4/web/src/task_detail.jsp b/eurilys4/web/src/task_detail.jsp new file mode 100644 index 00000000..73bb12b8 --- /dev/null +++ b/eurilys4/web/src/task_detail.jsp @@ -0,0 +1,145 @@ +<%@page import="java.io.PrintWriter"%> +<%@page import="java.sql.Blob"%> +<%@page import="java.util.List"%> +<%@page import="java.util.ArrayList"%> +<%@page import="java.sql.ResultSet"%> +<%@page import="java.sql.PreparedStatement"%> +<%@page import="java.sql.Connection"%> +<%@page import="java.sql.DriverManager"%> + +<%@include file="logged_in_header.jsp"%> + +
    + <%@include file="navigation_bar.jsp"%> +
    + <% + String taskID = (String) request.getParameter("task_id"); + //URL taskDetailURL = new URL("http://localhost:8084/eurilys4-service/task/task_detail?task_id=" + taskID); + URL taskDetailURL = new URL("http://eurilys.ap01.aws.af.cm/task/task_detail?task_id=" + taskID); + HttpURLConnection taskDetailConn = (HttpURLConnection) taskDetailURL.openConnection(); + taskDetailConn.setRequestMethod("GET"); + taskDetailConn.setRequestProperty("Accept", "application/json"); + if (taskDetailConn.getResponseCode() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + taskDetailConn.getResponseCode()); + } + BufferedReader taskDetailBr = new BufferedReader(new InputStreamReader((taskDetailConn.getInputStream()))); + String taskDetailOutput; + String taskDetailJSONObject = ""; + while ((taskDetailOutput = taskDetailBr.readLine()) != null) { + taskDetailJSONObject += taskDetailOutput; + } + taskDetailConn.disconnect(); + //Parse userDetailJSONObject + JSONTokener taskDetailTokener = new JSONTokener(taskDetailJSONObject); + JSONObject taskDetailroot = new JSONObject(taskDetailTokener); + + String task_name = taskDetailroot.getString("task_name"); + String task_id = taskDetailroot.getString("task_id"); + String task_deadline = taskDetailroot.getString("task_deadline"); + String task_status = taskDetailroot.getString("task_status"); + String task_category = taskDetailroot.getString("task_category"); + String task_creator = taskDetailroot.getString("task_creator"); + + JSONArray comment_id = taskDetailroot.getJSONArray("comment_id"); + JSONArray comment_timestamp = taskDetailroot.getJSONArray("comment_timestamp"); + JSONArray comment_content = taskDetailroot.getJSONArray("comment_content"); + JSONArray comment_creator = taskDetailroot.getJSONArray("comment_creator"); + + JSONArray tag_list = taskDetailroot.getJSONArray("tag_list"); + + JSONArray task_assignee = taskDetailroot.getJSONArray("task_assignee"); + + String tagList = ""; + for (int i=0; i + +
    + + <% if ("ok".equals(request.getParameter("update_task"))) { %> +
    Task has been successfully updated
    + <% } else if ("failed".equals(request.getParameter("update_task"))) { %> +
    Task NOT has been successfully updated.
    + <% } %> + +
    + <%=task_name%> +
    + Edit Task +
    +
    Task Name
    +
    <%=task_name%>
    +
    +
    +
    Status
    + <% if ("0".equals(task_status)) { %> +
    Not finished yet
    + <% } else { %> +
    Finished
    + <% } %> +
    +
    +
    Attachment
    +
    Belum buat hahaha~
    +
    +
    +
    Deadline
    +
    <%=task_deadline%>
    +
    + +
    +
    Assignee
    +
    + <% for (int i=0; i + <%=task_assignee.get(i)%> + <% + if (i != task_assignee.length()-1) + out.print(" , "); + } %> +
    +
    + + +
    +
    Tag
    +
    <%= tagList %>
    +
    +
    +
    Comment
    +
    +
    + + <% for (int i=0; i +
    + +
    <%= comment_content.get(i) %>
    + <% if (session.getAttribute("username").equals(comment_creator.get(i))) { %> + + <% } %> +
    + <% } %> +
    +
     
    +
    +
    + +
    + + +


    +
    +
    +
    +
    +
    + +<%@include file="footer.jsp"%> \ No newline at end of file diff --git a/eurilys4/web/src/uploads/23591_482718_10200745307864176_1702041215_n.jpg b/eurilys4/web/src/uploads/23591_482718_10200745307864176_1702041215_n.jpg new file mode 100644 index 00000000..b71561c6 Binary files /dev/null and b/eurilys4/web/src/uploads/23591_482718_10200745307864176_1702041215_n.jpg differ diff --git a/eurilys4/web/src/uploads/2472a_dddd.jpg b/eurilys4/web/src/uploads/2472a_dddd.jpg new file mode 100644 index 00000000..7aede463 Binary files /dev/null and b/eurilys4/web/src/uploads/2472a_dddd.jpg differ diff --git a/eurilys4/web/src/uploads/250c8_taskdetail_file.pdf b/eurilys4/web/src/uploads/250c8_taskdetail_file.pdf new file mode 100644 index 00000000..e1cc6294 Binary files /dev/null and b/eurilys4/web/src/uploads/250c8_taskdetail_file.pdf differ diff --git a/eurilys4/web/src/uploads/ab15e_2013-03-02 09.12.43.jpg b/eurilys4/web/src/uploads/ab15e_2013-03-02 09.12.43.jpg new file mode 100644 index 00000000..59071b9a Binary files /dev/null and b/eurilys4/web/src/uploads/ab15e_2013-03-02 09.12.43.jpg differ diff --git a/eurilys4/web/src/uploads/cf2c0_dddd.jpg b/eurilys4/web/src/uploads/cf2c0_dddd.jpg new file mode 100644 index 00000000..7aede463 Binary files /dev/null and b/eurilys4/web/src/uploads/cf2c0_dddd.jpg differ