List of usage examples for org.json.simple JSONObject escape
public static String escape(String s)
From source file:de.Keyle.MyPet.util.BukkitUtil.java
public static void sendMessageActionBar(Player player, String message) { if (player instanceof CraftPlayer) { IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer .a("{\"text\": \"" + JSONObject.escape(message) + "\"}"); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(cbc, (byte) 2)); }/*from w w w. j a v a 2 s . c o m*/ }
From source file:de.Keyle.MyPet.compat.v1_10_R1.PlatformHelper.java
public void sendMessageActionBar(Player player, String message) { if (player instanceof CraftPlayer) { IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer .a("{\"text\": \"" + JSONObject.escape(message) + "\"}"); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(cbc, (byte) 2)); }/*from w w w. jav a 2s . co m*/ }
From source file:de.Keyle.MyPet.compat.v1_12_R1.PlatformHelper.java
public void sendMessageActionBar(Player player, String message) { if (player instanceof CraftPlayer) { IChatBaseComponent cbc = IChatBaseComponent.ChatSerializer .a("{\"text\": \"" + JSONObject.escape(message) + "\"}"); ((CraftPlayer) player).getHandle().playerConnection .sendPacket(new PacketPlayOutChat(cbc, ChatMessageType.CHAT)); }//w ww . j av a2 s. c o m }
From source file:net.sourceforge.fenixedu.presentationTier.Action.gep.a3es.A3ESDegreeProcess.java
private String cut(String field, String content, StringBuilder output, int size) { if (content == null) { output.append(" " + field + " vazio."); } else {//from w ww .j a va2 s .co m int escapedLength = JSONObject.escape(content).getBytes().length; if (escapedLength > size) { output.append(" " + field + " cortado a " + size + " caracteres."); return content.substring(0, size - 4 - (escapedLength - content.length())) + " ..."; } } return content; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.gep.a3es.A3ESDegreeProcess.java
private String getTeachersAndTeachingHours(CurricularCourse course, boolean responsibleTeacher) { Map<Teacher, Double> responsiblesMap = new HashMap<Teacher, Double>(); List<ExecutionSemester> executionSemesters = getSelectedExecutionSemesters(); for (final ExecutionCourse executionCourse : course.getAssociatedExecutionCoursesSet()) { if (executionSemesters.contains(executionCourse.getExecutionPeriod())) { for (Professorship professorhip : executionCourse.getProfessorshipsSet()) { if (professorhip.isResponsibleFor() == responsibleTeacher && professorhip.getPerson().getTeacher() .isActiveOrHasAuthorizationForSemester(executionCourse.getExecutionPeriod())) { Double hours = responsiblesMap.get(professorhip.getTeacher()); if (hours == null) { hours = 0.0;/* ww w . ja v a 2 s. co m*/ } hours = hours + getHours(professorhip); responsiblesMap.put(professorhip.getTeacher(), hours); } } } } int counter = 1000; List<String> responsibles = new ArrayList<String>(); for (Teacher teacher : responsiblesMap.keySet()) { String responsible = (responsibleTeacher ? teacher.getPerson().getFirstAndLastName() : teacher.getPerson().getName()) + " (" + responsiblesMap.get(teacher) + ")"; counter -= JSONObject.escape(responsible + ", ").getBytes().length; responsibles.add(responsible); } if (!responsibleTeacher && course.isDissertation()) { Set<Teacher> teachers = new HashSet<Teacher>(); for (ExecutionCourse executionCourse : course.getAssociatedExecutionCoursesSet()) { if (executionCourse.getExecutionPeriod().getExecutionYear() .equals(executionSemester.getExecutionYear().getPreviousExecutionYear())) { for (Attends attends : executionCourse.getAttendsSet()) { if (attends.getEnrolment() != null && attends.getEnrolment().getThesis() != null) { for (ThesisEvaluationParticipant thesisEvaluationParticipant : attends.getEnrolment() .getThesis().getOrientation()) { if (thesisEvaluationParticipant.getPerson().getTeacher() != null && thesisEvaluationParticipant.getPerson().getTeacher() .isActiveOrHasAuthorizationForSemester( executionCourse.getExecutionPeriod())) { teachers.add(thesisEvaluationParticipant.getPerson().getTeacher()); } } } } } } for (Teacher teacher : teachers) { String responsible = (responsibleTeacher ? teacher.getPerson().getFirstAndLastName() : teacher.getPerson().getName()) + " (0.0)"; if (counter - JSONObject.escape(responsible).getBytes().length < 0) { break; } if (!responsiblesMap.containsKey(teacher)) { counter -= JSONObject.escape(responsible + ", ").getBytes().length; responsibles.add(responsible); } } } return StringUtils.join(responsibles, ", "); }
From source file:net.bashtech.geobot.Channel.java
public boolean updateGame(String game) throws IOException { String resp = BotManager.putRemoteData("https://api.twitch.tv/kraken/channels/" + this.channel.substring(1), "{\"channel\": {\"game\": \"" + JSONObject.escape(game) + "\"}}"); if (game.equals("-")) { game = null;// w w w . j a va 2 s .c o m } try { JSONParser parser = new JSONParser(); Object obj = parser.parse(resp); JSONObject jsonObject = (JSONObject) obj; try { String newStatus = (String) jsonObject.get("game"); return game.equalsIgnoreCase(newStatus); } catch (Exception e) { return true; } } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:net.bashtech.geobot.Channel.java
public boolean updateStatus(String status) throws IOException { String resp = BotManager.putRemoteData("https://api.twitch.tv/kraken/channels/" + this.channel.substring(1), "{\"channel\": {\"status\": \"" + JSONObject.escape(status) + "\"}}"); try {/*from www. ja v a2 s . c o m*/ JSONParser parser = new JSONParser(); Object obj = parser.parse(resp); JSONObject jsonObject = (JSONObject) obj; String newStatus = (String) jsonObject.get("status"); return status.equalsIgnoreCase(newStatus); } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:com.portfolio.data.provider.MysqlAdminProvider.java
private StringBuffer getNodeJsonOutput(String nodeUuid, boolean withChildren, String withChildrenOfXsiType, int userId, int groupId, String label, boolean checkSecurity) throws SQLException { StringBuffer result = new StringBuffer(); ResultSet resNode = getMysqlNode(nodeUuid, userId, groupId); ResultSet resResource;// ww w . ja v a2 s . c o m if (checkSecurity) { NodeRight nodeRight = credential.getNodeRight(userId, groupId, nodeUuid, label); // if (!nodeRight.read) return result; } String indentation = " "; //try //{ // resNode.next(); if (resNode.next()) { result.append("\"" + resNode.getString("asm_type") + "\": { " + DomUtils.getJsonAttributeOutput("id", resNode.getString("node_uuid")) + ", "); //if(resNodes.getString("node_parent_uuid").length()>0) // result.append(getXmlAttributeOutput("parent-uuid",resNodes.getString("node_parent_uuid"))+" "); //if(resNodes.getString("semtag")!=null) //if(resNodes.getString("semtag").length()>0) result.append(DomUtils.getJsonAttributeOutput("semantictag", resNode.getString("semtag")) + ", "); if (resNode.getString("xsi_type") != null) if (resNode.getString("xsi_type").length() > 0) result.append( DomUtils.getJsonAttributeOutput("xsi_type", resNode.getString("xsi_type")) + ", "); //if(resNodes.getString("format")!=null) // if(resNodes.getString("format").length()>0) result.append(DomUtils.getJsonAttributeOutput("format", resNode.getString("format")) + ", "); //if(resNodes.getTimestamp("modif_date")!=null) result.append( DomUtils.getJsonAttributeOutput("modified", resNode.getTimestamp("modif_date").toGMTString()) + ", "); //result.append(">"); if (!resNode.getString("asm_type").equals("asmResource")) { //obsolete //result.append(DomUtils.getJsonElementOutput("code", resNode.getString("code"))+", "); //result.append(DomUtils.getJsonElementOutput("label", resNode.getString("label"))+", "); //result.append(DomUtils.getJsonElementOutput("description", resNode.getString("descr"))+" "); } else { // si asmResource try { resResource = getMysqlResource(nodeUuid); if (resResource.next()) result.append("\"#cdata-section\": \"" + JSONObject.escape(resResource.getString("content")) + "\""); } catch (Exception ex) { ex.printStackTrace(); } } if (withChildren || withChildrenOfXsiType != null) { String[] arrayChild; try { if (resNode.getString("node_children_uuid").length() > 0) { result.append(", "); arrayChild = resNode.getString("node_children_uuid").split(","); for (int i = 0; i < (arrayChild.length); i++) { ResultSet resChildNode = this.getMysqlNodeResultset(arrayChild[i]); String tmpXsiType = ""; try { tmpXsiType = resChildNode.getString("xsi_type"); } catch (Exception ex) { } if (withChildrenOfXsiType == null || withChildrenOfXsiType.equals(tmpXsiType)) result.append( getNodeJsonOutput(arrayChild[i], true, null, userId, groupId, label, true)); if (withChildrenOfXsiType == null) if (arrayChild.length > 1) if (i < (arrayChild.length - 1)) result.append(", "); } } } catch (Exception ex) { // Pas de children } } result.append(" } "); } //} //catch(Exception ex) //{ // ex.printStackTrace(); // //} return result; }
From source file:lv.semti.Thesaurus.struct.Gram.java
public String toJSON(boolean printOrig) { StringBuilder res = new StringBuilder(); res.append("\"Gram\":{"); boolean hasPrev = false; if (paradigm != null && !paradigm.isEmpty()) { if (hasPrev) res.append(", "); res.append("\"Paradigm\":"); res.append(JSONUtils.simplesToJSON(paradigm)); hasPrev = true;// www. j a v a 2 s.com } if (altLemmas != null && !altLemmas.isEmpty()) { if (hasPrev) res.append(", "); res.append("\"AltLemmas\":{"); Iterator<Integer> it = altLemmas.keySet().iterator(); while (it.hasNext()) { Integer next = it.next(); if (!altLemmas.getAll(next).isEmpty()) { res.append("\""); res.append(JSONObject.escape(next.toString())); res.append("\":["); Iterator<Tuple<Lemma, HashSet<String>>> flagIt = altLemmas.getAll(next).iterator(); while (flagIt.hasNext()) { Tuple<Lemma, HashSet<String>> alt = flagIt.next(); res.append("{"); res.append(alt.first.toJSON()); if (alt.second != null && !alt.second.isEmpty()) { res.append(", \"Flags\":"); res.append(JSONUtils.simplesToJSON(alt.second)); } res.append("}"); if (flagIt.hasNext()) res.append(", "); } res.append("]"); if (it.hasNext()) res.append(", "); } } res.append("}"); hasPrev = true; } if (flags != null && !flags.isEmpty()) { if (hasPrev) res.append(", "); res.append("\"Flags\":"); res.append(JSONUtils.simplesToJSON(flags)); hasPrev = true; } if (leftovers != null && leftovers.size() > 0) { if (hasPrev) res.append(", "); res.append("\"Leftovers\":["); Iterator<LinkedList<String>> it = leftovers.iterator(); while (it.hasNext()) { LinkedList<String> next = it.next(); if (!next.isEmpty()) { res.append(JSONUtils.simplesToJSON(next)); if (it.hasNext()) res.append(", "); } } res.append("]"); hasPrev = true; } if (printOrig && orig != null && orig.length() > 0) { if (hasPrev) res.append(", "); res.append("\"Original\":\""); res.append(JSONObject.escape(orig)); res.append("\""); hasPrev = true; } res.append("}"); return res.toString(); }
From source file:oeg.licensius.model.LicensiusFound.java
@Override public String getJSON() { String json = "["; int n = licenses.size(); for (int i = 0; i < n; i++) { String license = JSONObject.escape(licenses.get(i)); String confidence = JSONObject.escape(confidences.get(i)); String evidence = JSONObject.escape(evidences.get(i)); String found = " {\n" + " \"license\": \"" + license + "\",\n" + " \"evidence\": \"" + evidence + "\",\n" + " \"confidence\": \"" + confidence + "\"\n" + " }\n" + ""; json += found + ",\n"; }/* ww w . ja v a2s . c o m*/ json += "]"; return json; }