List of usage examples for org.json.simple JSONValue toJSONString
public static String toJSONString(Object value)
From source file:inventory.Inventory.java
/** * Dump all inventory information to the console and returns JSON with the * dump as well// w w w.ja va 2s . co m */ public String dump() { // loop through all possible entires in inventory for (Entry<CabinetType, HashMap<Integer, InventoryShelf>> entry : inventory.entrySet()) { CabinetType cabinet = entry.getKey(); HashMap<Integer, InventoryShelf> shelves = entry.getValue(); System.out.println("Inventory on cabinet " + cabinet.toString()); // response.add(new KVObj("cabinet", cabinet.toString())); for (Entry<Integer, InventoryShelf> shelf : shelves.entrySet()) { Integer shelfId = shelf.getKey(); InventoryShelf is = shelf.getValue(); System.out.println("* " + shelfId + ": " + is.count + " units of " + is.originalShelf); // response.add(new KVObj("shelf", shelfId.toString())); // response.add(new KVObj("count", Integer.toString(is.count))); // response.add(new KVObj("originalShelf", Integer.toString(is.originalShelf))); } } // return Utils.buildJSON(response); return JSONValue.toJSONString(inventory); }
From source file:me.neatmonster.spacebukkit.PanelListener.java
@Override public void run() { if (mode == 0) { try {/* ww w . j av a 2s . co m*/ serverSocket = new ServerSocket(SpaceBukkit.getInstance().port, SO_BACKLOG, SpaceBukkit.getInstance().bindAddress); serverSocket.setSoTimeout(SO_TIMEOUT); } catch (IOException e) { e.printStackTrace(); return; } while (running && !serverSocket.isClosed()) { try { final Socket clientSocket = serverSocket.accept(); new PanelListener(clientSocket); } catch (SocketTimeoutException e) { // Do nothing. } catch (IOException e) { if (!e.getMessage().toLowerCase().contains("socket closed")) e.printStackTrace(); } } } else { try { final BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); String string = input.readLine(); if (string == null) { return; } string = URLDecoder.decode(string, "UTF-8"); string = string.substring(5, string.length() - 9); final PrintWriter output = new PrintWriter(socket.getOutputStream()); if (string.startsWith("call") && string.contains("?method=") && string.contains("&args=")) { final String method = string.substring(12, string.indexOf("&args=")); if (string.contains("&key=" + Utilities.crypt(method + SpaceBukkit.getInstance().salt))) { final Object result = interpret(string); if (result != null) try { output.println(Utilities.addHeader(JSONValue.toJSONString(result))); } catch (OutOfMemoryError e) { System.gc(); output.println(Utilities.addHeader(null)); } else output.println(Utilities.addHeader(null)); } else output.println(Utilities.addHeader("Incorrect Salt supplied. Access denied!")); } else if (string.startsWith("multiple") && string.contains("?method=") && string.contains("&args=")) { final String method = string.substring(16, string.indexOf("&args=")); if (string.contains("&key=" + Utilities.crypt(method + SpaceBukkit.getInstance().salt))) { final Object result = interpretm(string); if (result != null) try { output.println(Utilities.addHeader(JSONValue.toJSONString(result))); } catch (OutOfMemoryError e) { System.gc(); output.println(Utilities.addHeader(null)); } else output.println(Utilities.addHeader(null)); } else output.println(Utilities.addHeader("Incorrect Salt supplied. Access denied!")); } else if (string.startsWith("ping")) output.println(Utilities.addHeader("Pong!")); else output.println(Utilities.addHeader(null)); output.flush(); input.close(); output.close(); } catch (final Exception e) { e.printStackTrace(); } } }
From source file:com.jql.gcmccsmock.GCMMessageHandler.java
/** * Create Bad RegId Nack Message Stanza//from ww w.java2s . co m * <message> <gcm xmlns="google:mobile:data"> { "message_type":"nack", "message_id":"msgId1", "from":"SomeInvalidRegistrationId", "error":"BAD_REGISTRATION", "error_description":"Invalid token on 'to' field: SomeInvalidRegistrationId" } </gcm> </message> * @param original * @param jsonObject * @return * @throws EntityFormatException */ private static Stanza createNackBadRegIdMessageStanza(Stanza original, JSONObject jsonObject) throws EntityFormatException { Map<String, Object> message = new HashMap<>(); message.put(JSON_MESSAGE_TYPE, JSON_NACK); message.put(JSON_FROM, jsonObject.get(JSON_TO)); message.put(JSON_MESSAGE_ID, jsonObject.get(JSON_MESSAGE_ID)); message.put(JSON_ERROR, JSON_ERROR_BAD_REGISTRATION); message.put(JSON_ERROR_DESCRIPTION, "Invalid token on 'to' field: " + jsonObject.get(JSON_TO)); String payload = JSONValue.toJSONString(message); StanzaBuilder builder = new StanzaBuilder("message"); builder.addAttribute("id", original.getAttributeValue("id") == null ? "" : original.getAttributeValue("id")); GCMMessage.Builder gcmMessageBuilder = new GCMMessage.Builder(); gcmMessageBuilder.addText(payload); builder.addPreparedElement(gcmMessageBuilder.build()); return builder.build(); }
From source file:classes.Product.java
private String getResult(String query, String... params) { StringBuilder sb = new StringBuilder(); String strJSON = ""; try (Connection connection = DatabaseConnection.connect()) { PreparedStatement pStatement = connection.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pStatement.setString(i, params[i - 1]); }// ww w . j a va2 s .c om ResultSet resultSet = pStatement.executeQuery(); List list1 = new LinkedList(); while (resultSet.next()) { Map map = new LinkedHashMap(); map.put("productId", resultSet.getInt("productId")); map.put("productName", resultSet.getString("productName")); map.put("productDescription", resultSet.getString("productDescription")); map.put("productQuantity", resultSet.getInt("productQuantity")); list1.add(map); } strJSON = JSONValue.toJSONString(list1); } catch (SQLException ex) { System.out.println("SQL Exception Error: " + ex.getMessage()); } return strJSON.replace("},", "},\n"); }
From source file:backtype.storm.task.TopologyContext.java
@Override public String toJSONString() { Map obj = new HashMap(); obj.put("task->component", this.getTaskToComponent()); obj.put("taskid", this.getThisTaskId()); // TODO: jsonify StormTopology // at the minimum should send source info return JSONValue.toJSONString(obj); }
From source file:action.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w .j a v a 2s . com * * @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 { HttpSession session = request.getSession(); String form_action = (String) request.getParameter("form_action"); if (form_action == null) { form_action = ""; } PrintWriter out = response.getWriter(); if (form_action.equalsIgnoreCase("cekauth")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); JSONObject obj1 = (JSONObject) obj; String admin = "N"; String icw = "N"; String email = obj1.get("email").toString(); String first_name = obj1.get("first_name").toString(); String gender = obj1.get("gender").toString(); String id = obj1.get("id").toString(); String last_name = obj1.get("last_name").toString(); String link = obj1.get("link").toString(); String name = obj1.get("name").toString(); String verified = obj1.get("verified").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key linkKey = KeyFactory.createKey("userTable", "user"); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Filter posisinama = new FilterPredicate("link", FilterOperator.EQUAL, link.toLowerCase()); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("userTable", linkKey).setFilter(posisinama); List<Entity> userTables = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(1)); Date date = new Date(); if (userTables.isEmpty()) { Entity userTable = new Entity("userTable", linkKey); userTable.setProperty("email", email); userTable.setProperty("first_name", first_name); userTable.setProperty("gender", gender); userTable.setProperty("id", id); userTable.setProperty("last_name", last_name); userTable.setProperty("link", link.toLowerCase()); userTable.setProperty("name", name); userTable.setProperty("verified", verified); userTable.setProperty("lastLogin", date); if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || name.equalsIgnoreCase("Khairul Anshar")) { userTable.setProperty("admin", "Y"); userTable.setProperty("icw", "Y"); } else { userTable.setProperty("admin", admin); userTable.setProperty("icw", "N"); } userTable.setProperty("imported", "N"); datastore.put(userTable); } else { for (Entity userTable : userTables) { admin = userTable.getProperty("admin").toString(); try { icw = userTable.getProperty("icw").toString(); } catch (Exception e) { userTable.setProperty("icw", "N"); icw = "N"; } userTable.setProperty("lastLogin", date); datastore.put(userTable); } } if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || name.equalsIgnoreCase("Khairul Anshar")) { admin = "Y"; icw = "Y"; } obj1.put("admin", admin); obj1.put("icw", icw); session.setAttribute("userAccount", obj1); record.put("userAccount", obj1); } catch (Exception e) { } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getiframeData")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String src = obj1.get("src").toString(); final URL url = new URL(src); final URLConnection urlConnection = url.openConnection(); urlConnection.setDoOutput(true); urlConnection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); urlConnection.connect(); final InputStream inputStream = urlConnection.getInputStream(); InputStreamReader is = new InputStreamReader(inputStream); StringBuilder sb1 = new StringBuilder(); BufferedReader br = new BufferedReader(is); String read = br.readLine(); while (read != null) { sb1.append(read); read = br.readLine(); } record.put("data", sb1.toString()); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("postCommentPosisi")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String dept = obj1.get("dept").toString(); String star = obj1.get("star").toString(); String comment = obj1.get("comment").toString(); String id = userAccount.get("id").toString(); String name = userAccount.get("name").toString(); String link = userAccount.get("link").toString(); postData2(name, dept, "", star, comment, id, "AlasanStarCalonPosisi", "dept", dept, link); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("postLikeComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String id = obj1.get("id").toString(); String star = obj1.get("star").toString(); JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String name = userAccount.get("name").toString(); String link = userAccount.get("link").toString(); postData11("AlasanStarLike", "id", id, star, link, name); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getLikeComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); String idx_ = ""; try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; idx_ = obj1.get("id").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); LinkedHashMap record11 = new LinkedHashMap(); String link_ = ""; try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); link_ = userAccount.get("link").toString(); } catch (Exception e) { } Key guestbookKey = KeyFactory.createKey("id", idx_); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("AlasanStarLike", guestbookKey).addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); JSONArray obj11p = new JSONArray(); JSONArray obj11n = new JSONArray(); int i = 0; int ip = 0; int in = 0; double total = 0; double totalp = 0; double totaln = 0; for (Entity AlasanStar : pq.asIterable()) { LinkedHashMap record1 = new LinkedHashMap(); String date = AlasanStar.getProperty("date").toString(); String star = AlasanStar.getProperty("star").toString(); String name = AlasanStar.getProperty("user").toString(); String link = AlasanStar.getProperty("link").toString(); record1.put("date", date); record1.put("star", star); record1.put("name", name); record1.put("link", link); obj11.add(record1); i++; double d = Double.parseDouble(star); total = total + d; if (d >= 0) { obj11p.add(record1); ip++; totalp = totalp + d; } else { obj11n.add(record1); in++; totaln = totaln + d; } if (link_.equalsIgnoreCase(link)) { record11.put("date", date); record11.put("star", star); record11.put("name", name); record11.put("link", link); } } double avg = total / i; if (i == 0) { avg = 0; } DecimalFormat df = new DecimalFormat("#.##"); record.put("total", total); record.put("totalp", totalp); record.put("totaln", totaln); record.put("avg", df.format(avg)); //record.put("AlasanStars", obj11); record.put("AlasanStarsp", obj11p); record.put("AlasanStarsn", obj11n); record.put("AlasanStar", record11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getMyCommentPosisi")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); String dept = ""; DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); LinkedHashMap record1 = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; dept = obj1.get("dept").toString(); String link_ = ""; try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); link_ = userAccount.get("link").toString(); } catch (Exception e) { } LinkedHashMap record11 = new LinkedHashMap(); Key guestbookKey = KeyFactory.createKey("dept", dept); Query query = new Query("AlasanStarCalonPosisi", guestbookKey).addSort("date", Query.SortDirection.DESCENDING); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); JSONArray obj11p = new JSONArray(); JSONArray obj11n = new JSONArray(); int i = 0; int ip = 0; int in = 0; double total = 0; double totalp = 0; double totaln = 0; for (Entity AlasanStar : pq.asIterable()) { record1 = new LinkedHashMap(); String id = AlasanStar.getProperty("user").toString(); //DateTime dateTime = AlasanStar.getProperties().getDateTimeValue(); Date time = (Date) AlasanStar.getProperty("date"); String date = time.toString();//AlasanStar.getProperty("date").toString(); String star = AlasanStar.getProperty("star").toString(); String comment = AlasanStar.getProperty("comment").toString(); comment = comment.replaceAll("\n", "<br/>"); String name = AlasanStar.getProperty("name").toString(); String link = AlasanStar.getProperty("link").toString(); String id__ = AlasanStar.getKey().toString(); record1.put("id_", id__); record1.put("id", id); record1.put("date", date); record1.put("star", star); record1.put("comment", comment); record1.put("name", name); record1.put("link", link); obj11.add(record1); i++; double d = Double.parseDouble(star); total = total + d; if (d >= 0) { obj11p.add(record1); ip++; totalp = totalp + d; } else { obj11n.add(record1); in++; totaln = totaln + d; } if (link_.equalsIgnoreCase(link)) { record11.put("id_", id__); record11.put("id", id); record11.put("date", date); record11.put("star", star); record11.put("comment", comment); record11.put("name", name); record11.put("link", link); } } double avg = total / i; if (i == 0) { avg = 0; } DecimalFormat df = new DecimalFormat("#.##"); record.put("total", total); record.put("totalp", totalp); record.put("totaln", totaln); record.put("avg", df.format(avg)); //record.put("AlasanStars", obj11); record.put("AlasanStarsp", obj11p); record.put("AlasanStarsn", obj11n); record.put("AlasanStar", record11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("postComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String dept = obj1.get("dept").toString(); String namaCalon = obj1.get("namaCalon").toString(); String star = obj1.get("star").toString(); String comment = obj1.get("comment").toString(); String id = userAccount.get("id").toString(); String name = userAccount.get("name").toString(); String link = userAccount.get("link").toString(); postData2(name, dept, namaCalon, star, comment, id, "AlasanStarCalon", dept, namaCalon, link); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getMyComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); String dept = ""; String namaCalon = ""; try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; dept = obj1.get("dept").toString(); namaCalon = obj1.get("namaCalon").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); String link_ = ""; LinkedHashMap record11 = new LinkedHashMap(); try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); link_ = userAccount.get("link").toString(); } catch (Exception e) { } Key guestbookKey = KeyFactory.createKey(dept, namaCalon); Query query = new Query("AlasanStarCalon", guestbookKey).addSort("date", Query.SortDirection.DESCENDING); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); JSONArray obj11p = new JSONArray(); JSONArray obj11n = new JSONArray(); int i = 0; int ip = 0; int in = 0; double total = 0; double totalp = 0; double totaln = 0; for (Entity AlasanStar : pq.asIterable()) { LinkedHashMap record1 = new LinkedHashMap(); String id = AlasanStar.getProperty("user").toString(); Date time = (Date) AlasanStar.getProperty("date"); String date = time.toString();//AlasanStar.getProperty("date").toString(); String star = AlasanStar.getProperty("star").toString(); String comment = AlasanStar.getProperty("comment").toString(); comment = comment.replaceAll("\n", "<br/>"); String name = AlasanStar.getProperty("name").toString(); String link = AlasanStar.getProperty("link").toString(); String id__ = AlasanStar.getKey().toString(); record1.put("id_", id__); record1.put("id", id); record1.put("date", date); record1.put("star", star); record1.put("comment", comment); record1.put("name", name); record1.put("link", link); obj11.add(record1); i++; double d = Double.parseDouble(star); total = total + d; if (d >= 0) { obj11p.add(record1); ip++; totalp = totalp + d; } else { obj11n.add(record1); in++; totaln = totaln + d; } if (link_.equalsIgnoreCase(link)) { record11.put("id_", id__); record11.put("id", id); record11.put("date", date); record11.put("star", star); record11.put("comment", comment); record11.put("name", name); record11.put("link", link); } } double avg = total / i; if (i == 0) { avg = 0; } DecimalFormat df = new DecimalFormat("#.##"); record.put("total", total); record.put("totalp", totalp); record.put("totaln", totaln); record.put("avg", df.format(avg)); record.put("AlasanStarsp", obj11p); record.put("AlasanStarsn", obj11n); record.put("AlasanStar", record11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getAlasanStarCalon")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String dept = obj1.get("dept").toString(); String namaCalon = obj1.get("namaCalon").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key guestbookKey = KeyFactory.createKey(dept, namaCalon); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("AlasanStarCalon", guestbookKey).addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); int i = 0; double total = 0; for (Entity AlasanStar : pq.asIterable()) { LinkedHashMap record1 = new LinkedHashMap(); String id = AlasanStar.getProperty("user").toString(); String date = AlasanStar.getProperty("date").toString(); String star = AlasanStar.getProperty("star").toString(); String comment = AlasanStar.getProperty("comment").toString(); comment = comment.replaceAll("\n", "<br/>"); String name = AlasanStar.getProperty("name").toString(); String link = AlasanStar.getProperty("link").toString(); String id__ = AlasanStar.getKey().toString(); record1.put("id_", id__); record1.put("id", id); record1.put("date", date); record1.put("star", star); record1.put("comment", comment); record1.put("name", name); record1.put("link", link); obj11.add(record1); i++; double d = Double.parseDouble(star); total = total + d; } double avg = total / i; if (i == 0) { avg = 0; } DecimalFormat df = new DecimalFormat("#.##"); record.put("total", total); record.put("avg", df.format(avg)); record.put("AlasanStars", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("postUsulan")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String dept = obj1.get("dept").toString(); String usulan = obj1.get("usulan").toString(); JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String id = userAccount.get("id").toString(); String name = userAccount.get("name").toString(); String email = userAccount.get("email").toString(); String link = userAccount.get("link").toString(); Key usulanCalonKey = KeyFactory.createKey("dept", dept); Date date = new Date(); Entity usulanCalon = new Entity("usulanCalon", usulanCalonKey); usulanCalon.setProperty("user", id); usulanCalon.setProperty("name", name); usulanCalon.setProperty("email", email); usulanCalon.setProperty("link", link); usulanCalon.setProperty("date", date); usulanCalon.setProperty("usulan", usulan); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); usulanCalon.setProperty("imported", "N"); datastore.put(usulanCalon); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getSet1")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String type = obj1.get("type").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key typeKey = KeyFactory.createKey("posisi", type.toLowerCase().replaceAll(" ", "")); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("posisi", typeKey).addSort("date", Query.SortDirection.ASCENDING); //List<Entity> AlasanStars = datastore.prepare(query); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); String id = ""; try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); id = userAccount.get("id").toString(); } catch (Exception ex1) { } for (Entity typeEntity : pq.asIterable()) { String reviewed = typeEntity.getProperty("reviewed").toString(); if (reviewed.equalsIgnoreCase("Y")) { LinkedHashMap record1 = new LinkedHashMap(); String posisi = typeEntity.getProperty("posisi").toString(); String nama = typeEntity.getProperty("nama").toString(); String link = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("posisi", posisi); record1.put("nama", nama); record1.put("link", link); record1.put("date", date); String detail1 = ""; try { Text detail0 = (Text) typeEntity.getProperty("detail"); detail1 = detail0.getValue(); } catch (Exception e) { detail1 = ""; } record1.put("detail", detail1); obj11.add(record1); } else { String user = typeEntity.getProperty("user").toString(); if (user.equalsIgnoreCase(id)) { LinkedHashMap record1 = new LinkedHashMap(); String posisi = typeEntity.getProperty("posisi").toString(); String nama = typeEntity.getProperty("nama").toString(); String link = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("posisi", posisi); record1.put("nama", nama); record1.put("link", link); record1.put("date", date); String detail1 = ""; try { Text detail0 = (Text) typeEntity.getProperty("detail"); detail1 = detail0.getValue(); } catch (Exception e) { detail1 = ""; } record1.put("detail", detail1); obj11.add(record1); } } } record.put("records", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("setSet1")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String id = userAccount.get("id").toString(); String nama = userAccount.get("name").toString(); String email = userAccount.get("email").toString(); String link = userAccount.get("link").toString(); String admin = userAccount.get("admin").toString(); BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String type = obj1.get("type").toString(); String value = obj1.get("value").toString(); String detail = obj1.get("value1").toString(); Key typeKey = KeyFactory.createKey("posisi", type.toLowerCase().replaceAll(" ", "")); Filter posisinama = new FilterPredicate("posisi", FilterOperator.EQUAL, value); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("posisi", typeKey).setFilter(posisinama); //Query query = new Query("posisi", typeKey);//.addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); PreparedQuery pq = datastore.prepare(query); boolean found = pq.asIterable().iterator().hasNext(); if (found) { if (admin.equalsIgnoreCase("Y")) { for (Entity psosisiEntity : pq.asList(FetchOptions.Builder.withLimit(1))) { Date date = new Date(); psosisiEntity.setProperty("date", date); psosisiEntity.setProperty("detail", new Text(detail)); datastore.put(psosisiEntity); } } } if (!found) { Date date = new Date(); Entity psosisiEntity = new Entity("posisi", typeKey); psosisiEntity.setProperty("user", id); psosisiEntity.setProperty("link", link); psosisiEntity.setProperty("nama", nama); psosisiEntity.setProperty("email", email); psosisiEntity.setProperty("date", date); psosisiEntity.setProperty("posisi", value); psosisiEntity.setProperty("detail", new Text(detail)); if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y")) { psosisiEntity.setProperty("reviewed", "Y"); psosisiEntity.setProperty("nama", "Kawal Menteri"); psosisiEntity.setProperty("link", "https://www.facebook.com/KawalMenteri"); } else { psosisiEntity.setProperty("reviewed", "N"); } psosisiEntity.setProperty("imported", "N"); datastore.put(psosisiEntity); } query = new Query("posisi", typeKey).addSort("date", Query.SortDirection.ASCENDING); pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); for (Entity typeEntity : pq.asIterable()) { String reviewed = typeEntity.getProperty("reviewed").toString(); if (reviewed.equalsIgnoreCase("Y")) { LinkedHashMap record1 = new LinkedHashMap(); String posisi = typeEntity.getProperty("posisi").toString(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("posisi", posisi); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); String detail1 = ""; try { Text detail0 = (Text) typeEntity.getProperty("detail"); detail1 = detail0.getValue(); } catch (Exception e) { detail1 = ""; } record1.put("detail", detail1); obj11.add(record1); } else { String user = typeEntity.getProperty("user").toString(); if (user.equalsIgnoreCase(id) || (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y"))) { LinkedHashMap record1 = new LinkedHashMap(); String posisi = typeEntity.getProperty("posisi").toString(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("posisi", posisi); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); String detail1 = ""; try { Text detail0 = (Text) typeEntity.getProperty("detail"); detail1 = detail0.getValue(); } catch (Exception e) { detail1 = ""; } record1.put("detail", detail1); obj11.add(record1); } } } record.put("records", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("getSet2")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String input0 = obj1.get("input0").toString(); String type0 = obj1.get("type0").toString(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key typeKey = KeyFactory.createKey("kandidat" + type0, input); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("kandidat", typeKey).addSort("date", Query.SortDirection.ASCENDING); //List<Entity> AlasanStars = datastore.prepare(query); PreparedQuery pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); String id = ""; String nama = ""; String email = ""; String link = ""; String admin = ""; String icw = ""; try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); id = userAccount.get("id").toString(); nama = userAccount.get("name").toString(); email = userAccount.get("email").toString(); link = userAccount.get("link").toString(); admin = userAccount.get("admin").toString(); icw = userAccount.get("icw").toString(); } catch (Exception ex1) { } for (Entity typeEntity : pq.asIterable()) { String reviewed = typeEntity.getProperty("reviewed").toString(); if (reviewed.equalsIgnoreCase("Y")) { LinkedHashMap record1 = new LinkedHashMap(); String kandidat = typeEntity.getProperty("kandidat").toString(); String desc = typeEntity.getProperty("desc").toString(); Text detail0 = (Text) typeEntity.getProperty("detail"); String detail = detail0.getValue(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); String icwcomment = ""; try { icwcomment = typeEntity.getProperty("icwcomment").toString(); } catch (Exception e) { icwcomment = ""; } record1.put("key", "kandidat" + type0); record1.put("val", input); record1.put("kandidat", kandidat); record1.put("desc", desc); record1.put("detail", detail); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); record1.put("icwcomment", icwcomment); obj11.add(record1); } else { String user = typeEntity.getProperty("user").toString(); if (user.equalsIgnoreCase(id) || (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y"))) { LinkedHashMap record1 = new LinkedHashMap(); String kandidat = typeEntity.getProperty("kandidat").toString(); String desc = typeEntity.getProperty("desc").toString(); Text detail0 = (Text) typeEntity.getProperty("detail"); String detail = detail0.getValue(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("key", "kandidat" + type0); record1.put("val", input); record1.put("kandidat", kandidat); record1.put("desc", desc); record1.put("detail", detail); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); String icwcomment = ""; if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y") || icw.equalsIgnoreCase("Y")) { try { icwcomment = typeEntity.getProperty("icwcomment").toString(); } catch (Exception e) { icwcomment = ""; } } record1.put("icwcomment", icwcomment); obj11.add(record1); } } } record.put("records", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("setIcwComment")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String icw = userAccount.get("icw").toString(); if (icw.equalsIgnoreCase("N")) { } else { BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String input0 = obj1.get("input0").toString(); String type0 = obj1.get("type0").toString(); String value = obj1.get("value").toString(); String menteri = obj1.get("menteri").toString(); String kandidat = obj1.get("kandidat").toString(); Key typeKey = KeyFactory.createKey("kandidat" + type0, input); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Filter namaKandidat = new FilterPredicate("kandidat", FilterOperator.EQUAL, kandidat); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("kandidat", typeKey).setFilter(namaKandidat); //Query query = new Query("posisi", typeKey);//.addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); for (Entity psosisiEntity : datastore.prepare(query) .asList(FetchOptions.Builder.withLimit(1))) { psosisiEntity.setProperty("icwcomment", value); datastore.put(psosisiEntity); } } record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("setSet2")) { StringBuffer sb = new StringBuffer(); String line = null; LinkedHashMap record = new LinkedHashMap(); try { JSONObject userAccount = (JSONObject) session.getAttribute("userAccount"); String id = userAccount.get("id").toString(); String nama = userAccount.get("name").toString(); String email = userAccount.get("email").toString(); String link = userAccount.get("link").toString(); String admin = userAccount.get("admin").toString(); String icw = userAccount.get("icw").toString(); BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } Object obj = JSONValue.parse(sb.toString()); //JSONArray records = (JSONArray) obj; JSONObject obj1 = (JSONObject) obj; String input = obj1.get("input").toString(); String input0 = obj1.get("input0").toString(); String type0 = obj1.get("type0").toString(); String value = obj1.get("value").toString(); String value1 = obj1.get("value1").toString(); String value2 = obj1.get("value2").toString(); String menteri = obj1.get("menteri").toString(); Key typeKey = KeyFactory.createKey("kandidat" + type0, input); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Filter namaKandidat = new FilterPredicate("kandidat", FilterOperator.EQUAL, value); // Run an ancestor query to ensure we see the most up-to-date // view of the Greetings belonging to the selected Guestbook. Query query = new Query("kandidat", typeKey).setFilter(namaKandidat); //Query query = new Query("posisi", typeKey);//.addSort("date", Query.SortDirection.DESCENDING); //List<Entity> AlasanStars = datastore.prepare(query); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); PreparedQuery pq = datastore.prepare(query); boolean found = pq.asIterable().iterator().hasNext(); if (found) { if (admin.equalsIgnoreCase("Y")) { for (Entity psosisiEntity : pq.asList(FetchOptions.Builder.withLimit(1))) { Date date = new Date(); psosisiEntity.setProperty("date", date); psosisiEntity.setProperty("detail", new Text(value2)); datastore.put(psosisiEntity); } } } if (!found) { Date date = new Date(); Entity psosisiEntity = new Entity("kandidat", typeKey); psosisiEntity.setProperty("user", id); psosisiEntity.setProperty("link", link); psosisiEntity.setProperty("nama", nama); psosisiEntity.setProperty("email", email); psosisiEntity.setProperty("date", date); psosisiEntity.setProperty("kandidat", value); psosisiEntity.setProperty("desc", value1); psosisiEntity.setProperty("posisi", menteri); psosisiEntity.setProperty("detail", new Text(value2)); psosisiEntity.setProperty("icwcomment", ""); if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y")) { psosisiEntity.setProperty("reviewed", "Y"); psosisiEntity.setProperty("nama", "Kawal Menteri"); psosisiEntity.setProperty("link", "https://www.facebook.com/KawalMenteri"); } else { psosisiEntity.setProperty("reviewed", "N"); } psosisiEntity.setProperty("imported", "N"); datastore.put(psosisiEntity); } query = new Query("kandidat", typeKey).addSort("date", Query.SortDirection.ASCENDING); pq = datastore.prepare(query); JSONArray obj11 = new JSONArray(); for (Entity typeEntity : pq.asIterable()) { String reviewed = typeEntity.getProperty("reviewed").toString(); if (reviewed.equalsIgnoreCase("Y")) { LinkedHashMap record1 = new LinkedHashMap(); String kandidat = typeEntity.getProperty("kandidat").toString(); String desc = typeEntity.getProperty("desc").toString(); Text detail0 = (Text) typeEntity.getProperty("detail"); String detail = detail0.getValue(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); String icwcomment = ""; try { icwcomment = typeEntity.getProperty("icwcomment").toString(); } catch (Exception e) { icwcomment = ""; } record1.put("key", "kandidat" + type0); record1.put("val", input); record1.put("kandidat", kandidat); record1.put("desc", desc); record1.put("detail", detail); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); record1.put("icwcomment", icwcomment); obj11.add(record1); } else { String user = typeEntity.getProperty("user").toString(); if (user.equalsIgnoreCase(id) || (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y"))) { LinkedHashMap record1 = new LinkedHashMap(); String kandidat = typeEntity.getProperty("kandidat").toString(); String desc = typeEntity.getProperty("desc").toString(); Text detail0 = (Text) typeEntity.getProperty("detail"); String detail = detail0.getValue(); String nama1 = typeEntity.getProperty("nama").toString(); String link1 = typeEntity.getProperty("link").toString(); String date = typeEntity.getProperty("date").toString(); record1.put("key", "kandidat" + type0); record1.put("val", input); record1.put("kandidat", kandidat); record1.put("desc", desc); record1.put("detail", detail); record1.put("nama", nama1); record1.put("link", link1); record1.put("date", date); String icwcomment = ""; if (email.equalsIgnoreCase("khairul.anshar@gmail.com") || id.equalsIgnoreCase("112525777678499279265") || id.equalsIgnoreCase("10152397276159760") || nama.equalsIgnoreCase("Khairul Anshar") || admin.equalsIgnoreCase("Y") || icw.equalsIgnoreCase("Y")) { try { icwcomment = typeEntity.getProperty("icwcomment").toString(); } catch (Exception e) { icwcomment = ""; } } record1.put("icwcomment", icwcomment); obj11.add(record1); } } } record.put("records", obj11); record.put("status", "OK"); } catch (Exception e) { record.put("status", "error"); record.put("errormsg", e.toString()); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } }
From source file:cc.mincai.android.desecret.storage.dropbox.DropboxClient.java
@SuppressWarnings("unchecked") public Map eventMetadata(String root, Map target_events) throws DropboxException { String jsonText = JSONValue.toJSONString(target_events); Object[] params = { "root", root, "target_events", jsonText, }; return (Map) request("POST", secureProtocol, api_host, port, "/event_metadata", API_VERSION, params, auth); }
From source file:com.dropbox.DropboxClient.java
@SuppressWarnings("unchecked") public Map eventMetadata(String root, Map target_events) throws DropboxException { String jsonText = JSONValue.toJSONString(target_events); Object[] params = { "root", root, "target_events", jsonText, }; return (Map) request("POST", defaultProtocol, api_host, port, "/event_metadata", API_VERSION, params, auth); }
From source file:au.org.paperminer.main.UserFilter.java
/** * Return user prefs as JSON, checking that the user id in the cookie (if any) still exists. * @param req The request/*www .ja v a 2 s . c om*/ * @param resp The response */ private void getPrefs(HttpServletRequest req, HttpServletResponse resp) { m_logger.debug("get user prefs "); try { String id = CookieHelper.getCookieValue(req, PaperMinerConstants.PMC_USER_ID); UserHelper helper = new UserHelper(id); if (!helper.isKnownUser()) { removeCookie(resp); req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e103"); } else { HashMap<String, String> map = new HashMap<String, String>(); map.put("id", CookieHelper.getCookieValue(req, PaperMinerConstants.PMC_USER_ID)); map.put("key", CookieHelper.getCookieValue(req, PaperMinerConstants.PMC_TROVE_KEY)); map.put("em", CookieHelper.getCookieValue(req, PaperMinerConstants.PMC_USER_STATUS)); map.put("stat", CookieHelper.getCookieValue(req, PaperMinerConstants.PMC_USER_STATUS)); String jsonStr = JSONValue.toJSONString(map); resp.setContentType("text/json"); PrintWriter pm = resp.getWriter(); pm.write(jsonStr); } } catch (IOException ex) { req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e110"); } }
From source file:au.org.paperminer.main.LocationFilter.java
/** * Locate an existing location by its name, and optionally, state (short form) and/or country (long form). * @param req//from w w w.j a va2s. c o m * @param resp */ private void findLocation(HttpServletRequest req, HttpServletResponse resp) { String locnName = req.getParameter("ln"); String stateName = req.getParameter("sn"); String cntryName = req.getParameter("cn"); try { ArrayList<HashMap<String, String>> list = m_helper.locationsLike(locnName, stateName, cntryName); m_logger.debug("locationFilter locn lookup: " + locnName + " (" + stateName + ", " + cntryName + "): " + list.size()); resp.setContentType("text/json"); PrintWriter pm = resp.getWriter(); pm.write(JSONValue.toJSONString(list)); pm.close(); } catch (PaperMinerException ex) { m_logger.error("lookup failed", ex); req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e305"); } catch (IOException ex) { req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e114"); } }