Search in sources :

Example 26 with JSONWriter

use of org.json.JSONWriter in project alfresco-remote-api by Alfresco.

the class AbstractBlogWebScript method addActivityEntry.

/**
 * Generates an activity entry for the discussion item
 *
 * @param event One of created, updated, deleted
 * @param blog Either post or reply
 * @param site site
 * @param req request
 * @param json json
 * @param nodeRef NodeRef
 */
protected void addActivityEntry(String event, BlogPostInfo blog, SiteInfo site, WebScriptRequest req, JSONObject json, NodeRef nodeRef) {
    // We can only add activities against a site
    if (site == null) {
        logger.info("Unable to add activity entry for blog " + 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 = "blog-postview";
    }
    if (page.indexOf('?') == -1) {
        page += "?postId=" + blog.getSystemName();
    }
    // Get the title
    String title = blog.getTitle();
    try {
        JSONWriter jsonWriter = new JSONStringer().object().key(TITLE).value(title).key(PAGE).value(page);
        if (nodeRef != null) {
            // ALF-10182: the nodeRef needs to be included in the activity
            // post to ensure read permissions are respected.
            jsonWriter.key(PostLookup.JSON_NODEREF).value(nodeRef.toString());
        }
        String data = jsonWriter.endObject().toString();
        activityService.postActivity("org.alfresco.blog.post-" + event, site.getShortName(), "blog", data);
    } catch (Exception e) {
        // Warn, but carry on
        logger.warn("Error adding blog post " + event + " to activities feed", e);
    }
}
Also used : JSONWriter(org.json.JSONWriter) JSONStringer(org.json.JSONStringer) ParseException(org.json.simple.parser.ParseException) IOException(java.io.IOException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Aggregations

JSONWriter (org.json.JSONWriter)26 Writer (java.io.Writer)9 StringWriter (java.io.StringWriter)8 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)6 JSONException (org.json.JSONException)6 Test (org.junit.Test)6 JsonFactory (com.fasterxml.jackson.core.JsonFactory)5 JsonParser (com.fasterxml.jackson.core.JsonParser)5 JSONObject (org.json.JSONObject)5 IOException (java.io.IOException)4 PrintWriter (java.io.PrintWriter)3 Properties (java.util.Properties)3 ServletException (javax.servlet.ServletException)3 JSONStringer (org.json.JSONStringer)3 TypeFormatterImportsUUT (com.instagram.common.json.annotation.processor.parent.TypeFormatterImportsUUT)2 FormatterUUT (com.instagram.common.json.annotation.processor.uut.FormatterUUT)2 OutputStreamWriter (java.io.OutputStreamWriter)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2