Search in sources :

Example 1 with JsonItemWriter

use of org.apache.sling.commons.json.jcr.JsonItemWriter in project acs-aem-commons by Adobe-Consulting-Services.

the class AbstractWidgetConfigurationServlet method toJSONObject.

protected JSONObject toJSONObject(Resource resource) throws JSONException, ServletException {
    JSONObject config = null;
    Node node = resource.adaptTo(Node.class);
    if (node != null) {
        JsonItemWriter writer = new JsonItemWriter(null);
        StringWriter string = new StringWriter();
        try {
            writer.dump(node, string, -1);
        } catch (RepositoryException e) {
            throw new ServletException(e);
        }
        config = new JSONObject(string.toString());
    }
    return config;
}
Also used : ServletException(javax.servlet.ServletException) JSONObject(org.apache.sling.commons.json.JSONObject) StringWriter(java.io.StringWriter) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JsonItemWriter(org.apache.sling.commons.json.jcr.JsonItemWriter)

Aggregations

StringWriter (java.io.StringWriter)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 ServletException (javax.servlet.ServletException)1 JSONObject (org.apache.sling.commons.json.JSONObject)1 JsonItemWriter (org.apache.sling.commons.json.jcr.JsonItemWriter)1