List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:module.entities.NameFinder.RegexNameFinder.java
/** * @param args the command line arguments *///from w ww .j a v a 2 s . c o m public static void main(String[] args) throws SQLException, IOException { if (args.length == 1) { Config.configFile = args[0]; } long lStartTime = System.currentTimeMillis(); Timestamp startTime = new Timestamp(lStartTime); System.out.println("Regex Name Finder process started at: " + startTime); DB.initPostgres(); regexerId = DB.LogRegexFinder(lStartTime); initLexicons(); JSONObject obj = new JSONObject(); TreeMap<Integer, String> consultations = DB.getDemocracitConsultationBody(); Document doc; int count = 0; TreeMap<Integer, String> consFoundNames = new TreeMap<>(); TreeMap<Integer, String> consFoundRoles = new TreeMap<>(); for (int consId : consultations.keySet()) { String consBody = consultations.get(consId); String signName = "", roleName = ""; doc = Jsoup.parse(consBody); Elements allPars = new Elements(); Elements paragraphs = doc.select("p"); for (Element par : paragraphs) { if (par.html().contains("<br>")) { String out = "<p>" + par.html().replaceAll("<br>", "</p><p>") + "</p>"; Document internal_doc = Jsoup.parse(out); Elements subparagraphs = internal_doc.select("p"); allPars.addAll(subparagraphs); } else { allPars.add(par); } // System.out.println(formatedText); } String signature = getSignatureFromParagraphs(allPars); // System.out.println(signature); if (signature.contains("#")) { String[] sign_tokens = signature.split("#"); signName = sign_tokens[0]; if (sign_tokens.length > 1) { roleName = sign_tokens[1]; } consFoundNames.put(consId, signName.trim()); consFoundRoles.put(consId, roleName.trim()); count++; } else { System.err.println("--" + consId); } // } DB.insertDemocracitConsultationMinister(consFoundNames, consFoundRoles); TreeMap<Integer, String> consultationsCompletedText = DB.getDemocracitCompletedConsultationBody(); Document doc2; TreeMap<Integer, String> complConsFoundNames = new TreeMap<>(); int count2 = 0; for (int consId : consultationsCompletedText.keySet()) { String consBody = consultationsCompletedText.get(consId); String signName = "", roleName = ""; doc2 = Jsoup.parse(consBody); // if (doc.text().contains("<br>")) { // doc.text().replaceAll("(<[Bb][Rr]>)+", "<p>"); // } Elements allPars = new Elements(); Elements paragraphs = doc2.select("p"); for (Element par : paragraphs) { if (par.html().contains("<br>")) { String out = "<p>" + par.html().replaceAll("<br>", "</p><p>") + "</p>"; Document internal_doc = Jsoup.parse(out); Elements subparagraphs = internal_doc.select("p"); allPars.addAll(subparagraphs); } else { allPars.add(par); } } String signature = getSignatureFromParagraphs(allPars); if (signature.contains("#")) { String[] sign_tokens = signature.split("#"); signName = sign_tokens[0]; if (sign_tokens.length > 1) { roleName = sign_tokens[1]; } consFoundNames.put(consId, signName.trim()); consFoundRoles.put(consId, roleName.trim()); // System.out.println(consId); // System.out.println(signName.trim()); // System.out.println("***************"); count2++; } else { System.err.println("++" + consId); } } DB.insertDemocracitConsultationMinister(complConsFoundNames, consFoundRoles); long lEndTime = System.currentTimeMillis(); System.out.println("Regex Name Finder process finished at: " + startTime); obj.put("message", "Regex Name Finder finished with no errors"); obj.put("details", ""); DB.UpdateLogRegexFinder(lEndTime, regexerId, obj); DB.close(); }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.Util.java
public static void errordeRespuesta(ArrayList r, PrintWriter out) { System.err.print(//from w w w. j a v a 2 s. c o m "Respuesta inesperada del control !! r.size:" + r.size() + "|r0:" + r.get(0) + "|r1:" + r.get(1)); JSONObject obj = new JSONObject(); obj.put("isError", true); obj.put("errorDescrip", "Error inesperado"); out.print(obj); }
From source file:com.oic.utils.Tools.java
public static JSONObject convertPosToJSON(Position pos) { JSONObject json = new JSONObject(); json.put("x", pos.getX()); json.put("y", pos.getY()); json.put("width", pos.getWidth()); json.put("height", pos.getHeight()); return json;//from www . j av a 2 s. c o m }
From source file:app.NotificationJSONizer.java
public static void jsonize(ArrayList<backend.Notification> notis, PrintWriter out) { JSONArray a = new JSONArray(); notis.stream().forEach((noti) -> { JSONObject o = noti.jsonize(); o.put("type", noti.get_type().toString()); a.add(o);//w w w. j a va 2s .c o m }); out.print(a.toString()); }
From source file:naftoreiclag.villagefive.SaveLoad.java
public static void save(World data) throws IOException { JSONObject obj = new JSONObject(); obj.put("world", data); FileWriter fw = new FileWriter(new File("saves/save.json")); obj.writeJSONString(fw);//from ww w . j a v a2s. c o m fw.flush(); }
From source file:com.conwet.silbops.connectors.comet.JSONUtils.java
@SuppressWarnings("unchecked") public static String toJSONReply(String command, JSONObject parameters) { JSONObject json = new JSONObject(); json.put("command", command); json.put("parameters", parameters); return json.toJSONString(); }
From source file:com.conwet.silbops.connectors.comet.JSONUtils.java
@SuppressWarnings("unchecked") public static JSONObject buildResponseMessage(String endpoinID, String string) { JSONObject json = new JSONObject(); json.put("endpointID", endpoinID); json.put("message", string); return json;// ww w .j a va2 s . com }
From source file:cs.rsa.ts14dist.common.CommandLanguage.java
@SuppressWarnings("unchecked") /** Create an invalid reply object */ public static JSONObject createInvalidReplyWithExplantion(String errorMsg) { JSONObject reply = new JSONObject(); reply.put("error", true); reply.put("errorMsg", errorMsg); return reply; }
From source file:cs.rsa.ts14dist.common.CommandLanguage.java
@SuppressWarnings("unchecked") /** Create a valid reply object */ public static JSONObject createValidReplyWithReturnValue(Object returnValkue) { JSONObject reply = new JSONObject(); reply.put("error", false); reply.put("errorMsg", "OK"); reply.put(Constants.RETURNVALUE_KEY, returnValkue); return reply; }
From source file:cs.rsa.ts14dist.common.CommandLanguage.java
@SuppressWarnings("unchecked") /** Create a request object */ public static JSONObject createRequestObject(String user, String commandKey, String parameter) { JSONObject requestJson = new JSONObject(); requestJson.put(Constants.USER_KEY, user); requestJson.put(Constants.COMMAND_KEY, commandKey); requestJson.put(Constants.PARAMETER_KEY, parameter); return requestJson; }