List of usage examples for org.json.simple JSONObject toString
@Override
public String toString()
From source file:oeg.rdflicense.RDFLicense.java
License:asdf
public String toMicroJSON() { String json = ""; try {//from w w w . j a va 2 s .c om JSONObject obj = new JSONObject(); obj.put("uri", uri); obj.put("title", getLabel()); obj.put("source", getSeeAlso()); json = obj.toString(); } catch (Exception e) { json = "error"; } return json; }
From source file:oeg.rdflicense.RDFLicense.java
License:asdf
public String toJSON() { String json = ""; try {/*from ww w . ja va2s .c o m*/ JSONObject obj = new JSONObject(); obj.put("uri", getSeeAlso()); obj.put("title", getLabel()); obj.put("rdflicense", uri); json = obj.toString(); } catch (Exception e) { json = "error"; } return json; }
From source file:oeg.rdflicense.RDFLicense.java
License:asdf
public String toLongJSON() { String json = ""; try {/*from w w w . java 2s . c om*/ JSONObject obj = new JSONObject(); obj.put("uri", uri); obj.put("title", getTitle()); obj.put("version", getVersion()); obj.put("seeAlso", getSeeAlso()); obj.put("label", getLabel()); obj.put("legalcode", getLegalCodeLanguages()); json = obj.toString(); } catch (Exception e) { json = "error"; } return json; }
From source file:oeg.rdflicense.RDFLicenseCheck.java
/** * This is to determine the compatibility between any two licenses *//*from w w w . jav a2 s . com*/ public static String compose(RDFLicense lic1, RDFLicense lic2) { String compatible = ""; String reason = ""; String source = ""; String resulting = ""; reason = "A computation has been made on the basis of the main permissions, prohibitions. The result has been computed automatically and no warranty exists on its reliability. Please check the legal text."; source = "computed"; List<String> per1 = RDFLicenseCheck.getPermissions(lic1); List<String> pro1 = RDFLicenseCheck.getProhibitions(lic1); List<String> dut1 = RDFLicenseCheck.getDuties(lic1); List<String> per2 = RDFLicenseCheck.getPermissions(lic2); List<String> pro2 = RDFLicenseCheck.getProhibitions(lic2); List<String> dut2 = RDFLicenseCheck.getDuties(lic2); /*System.out.print("Per1: "); for(String p : per1) System.out.print(p+" "); System.out.print("\nPro1: "); for(String p : pro1) System.out.print(p+" "); System.out.print("\nPer2: "); for(String p : per2) System.out.print(p+" "); System.out.print("\nPro2: "); for(String p : pro2) System.out.print(p+" "); System.out.print("\n");*/ if (lic1.getURI().equals(lic2.getURI())) { compatible = "compatible"; reason = "The licenses are the same."; } List<String> per3 = ListUtils.intersection(per1, per2); List<String> pro3 = ListUtils.union(pro1, pro2); List<String> dut3 = ListUtils.union(dut1, dut2); List<String> em1 = ListUtils.intersection(pro3, per3); if (!em1.isEmpty()) { compatible = "not compatible"; } else { compatible = "compatible"; } RDFLicense lic3 = RDFLicenseFactory.createLicense(per3, dut3, pro3); resulting = lic3.toTTL(); // System.out.println(lic3.toTTL()); String json = ""; try { JSONObject obj = new JSONObject(); obj.put("compatible", compatible); obj.put("reason", reason); obj.put("source", source); obj.put("resulting", resulting); json = obj.toString(); } catch (Exception e) { json = "error"; } return json; }
From source file:org.alfresco.dataprep.AlfrescoHttpClient.java
/** * Populate HTTP message call with given content. * @param json {@link JSONObject} content * @return {@link StringEntity} content. *///from w ww .j a v a 2 s .com public StringEntity setMessageBody(final JSONObject json) { if (json == null || json.toString().isEmpty()) { throw new IllegalArgumentException("JSON Content is required."); } StringEntity se = new StringEntity(json.toString(), UTF_8_ENCODING); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, MIME_TYPE_JSON)); if (logger.isDebugEnabled()) { logger.debug("Json string value: " + se); } return se; }
From source file:org.alfresco.json.JSONUtil.java
/** * Populate HTTP message call with given content. * //w w w.j a v a 2 s . c om * @param json {@link JSONObject} content * @return {@link StringEntity} content. * @throws UnsupportedEncodingException if unsupported */ public static StringEntity setMessageBody(final JSONObject json) throws UnsupportedEncodingException { if (json == null || json.toString().isEmpty()) throw new UnsupportedOperationException("JSON Content is required."); StringEntity se = setMessageBody(json.toString()); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, MIME_TYPE_JSON)); if (logger.isDebugEnabled()) { logger.debug("Json string value: " + se); } return se; }
From source file:org.alfresco.provision.BMService.java
/** * Populate HTTP message call with given content. * //from w w w .j a v a 2 s . c o m * @param json * {@link JSONObject} content * @return {@link StringEntity} content. * @throws UnsupportedEncodingException * if unsupported */ public StringEntity setMessageBody(final JSONObject json) throws UnsupportedEncodingException { if (json == null || json.toString().isEmpty()) throw new UnsupportedOperationException("JSON Content is required."); StringEntity se = setMessageBody(json.toString()); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, MIME_TYPE_JSON)); return se; }
From source file:org.alfresco.repo.content.filestore.SpoofedTextContentReader.java
/** * Helper to create a content URL that represents spoofed text * //w w w . j a va 2s . c om * @param locale the text local (must be supported by an appropriate lexicon config resource) * @param seed numerical seed to ensure repeatable sequences of random text * @param size the size (bytes) of the text to generate * @param words additional words with decreasing frequency * @return the content URL * * @throws IllegalArgumentException if the resulting URL exceeds 255 characters */ @SuppressWarnings("unchecked") public static String createContentUrl(Locale locale, long seed, long size, String... words) { if (locale == null || size < 0L) { throw new IllegalArgumentException("Locale must be supplied and size must be zero or greater."); } // Make sure that there is a text generator available SpoofedTextContentReader.getTextGenerator(locale); // Build map String url = null; try { JSONObject jsonObj = new JSONObject(); jsonObj.put(KEY_LOCALE, locale.toString()); jsonObj.put(KEY_SEED, Long.valueOf(seed).toString()); jsonObj.put(KEY_SIZE, Long.valueOf(size).toString()); JSONArray jsonWords = new JSONArray(); for (String word : words) { if (word == null) { throw new IllegalArgumentException("Words to inject into the document may not be null."); } jsonWords.add(word); } jsonObj.put(KEY_WORDS, jsonWords); url = FileContentStore.SPOOF_PROTOCOL + "://" + jsonObj.toString(); if (url.length() > 255) { throw new IllegalArgumentException( "Content URLs can be up to 255 characters. Have " + url.length() + " characters: " + url); } return url; } catch (IllegalArgumentException e) { // Let these out as they are throw e; } catch (Exception e) { throw new RuntimeException( "Unable to create content URL using " + locale + ", " + seed + ", " + size + ", " + words, e); } }
From source file:org.alfresco.repo.forum.CommentServiceImpl.java
private void postActivity(String siteId, String activityType, JSONObject activityData) { if (activityData != null) { activityService.postActivity(activityType, siteId, "comments", activityData.toString()); }//from ww w. ja v a2 s .co m }
From source file:org.alfresco.repo.web.scripts.discussion.AbstractDiscussionWebScript.java
/** * Generates an activity entry for the discussion item * /*from ww w.j a va2 s .c o m*/ * @param thing Either post or reply * @param event One of created, updated, deleted */ protected void addActivityEntry(String thing, String event, TopicInfo topic, PostInfo post, SiteInfo site, WebScriptRequest req, JSONObject json) { // We can only add activities against a site if (site == null) { logger.info("Unable to add activity entry for " + thing + " " + event + " as no site given"); return; } // What page is this for? String page = req.getParameter("page"); if (page == null && json != null) { if (json.containsKey("page")) { page = (String) json.get("page"); } } if (page == null) { // Default page = "discussions-topicview"; } // Get the title String title = topic.getTitle(); if (post != null) { String postTitle = post.getTitle(); if (postTitle != null && postTitle.length() > 0) { title = postTitle; } } try { JSONObject params = new JSONObject(); params.put("topicId", topic.getSystemName()); JSONObject activity = new JSONObject(); activity.put("title", title); activity.put("page", page + "?topicId=" + topic.getSystemName()); activity.put("params", params); activityService.postActivity("org.alfresco.discussions." + thing + "-" + event, site.getShortName(), DISCUSSIONS_SERVICE_ACTIVITY_APP_NAME, activity.toString()); } catch (Exception e) { // Warn, but carry on logger.warn("Error adding discussions " + thing + " " + event + " to activities feed", e); } }