org.apache.sling.commons.json.jcr
Class JsonJcrNode

java.lang.Object
  extended by org.apache.sling.commons.json.JSONObject
      extended by org.apache.sling.commons.json.jcr.JsonJcrNode

public class JsonJcrNode
extends JSONObject

This class makes it easy to create a JSON object out of a JCR node. It is a shameless copy of JsonItemWriter, but instead of writing the resulting JSON directly to an output, you get a JSONObject that you can deal with.

Since:
Apr 17, 2009 6:55:30 PM
Author:
vidar@idium.no

Field Summary
 
Fields inherited from class org.apache.sling.commons.json.JSONObject
NULL
 
Constructor Summary
JsonJcrNode(javax.jcr.Node node)
          Creates a JSONObject out of node.
JsonJcrNode(javax.jcr.Node node, java.util.Set<java.lang.String> propertyNamesToIgnore)
          Creates a JSONObject out of node.
 
Method Summary
protected  void addProperty(javax.jcr.Property p)
           
protected  void addValue(java.lang.String key, javax.jcr.Value v)
           
 
Methods inherited from class org.apache.sling.commons.json.JSONObject
accumulate, append, doubleToString, get, getBoolean, getDouble, getInt, getJSONArray, getJSONObject, getLong, getString, has, isNull, keys, length, names, numberToString, opt, optBoolean, optBoolean, optDouble, optDouble, optInt, optInt, optJSONArray, optJSONObject, optLong, optLong, optString, optString, put, put, put, put, put, put, put, putOpt, quote, remove, toJSONArray, toString, toString, valueToString, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonJcrNode

public JsonJcrNode(javax.jcr.Node node)
            throws JSONException,
                   javax.jcr.RepositoryException
Creates a JSONObject out of node. All node's properties will be reflected in the JSON object. In addition, properties jcr:path and jcr:name are added. Their values are those returned by node.getPath() and node.getName(), respectively.

Parameters:
node - The JCR node to use
Throws:
JSONException - If there's a problem generating the JSON object
javax.jcr.RepositoryException - If there's a problem reading data from the JCR repository

JsonJcrNode

public JsonJcrNode(javax.jcr.Node node,
                   java.util.Set<java.lang.String> propertyNamesToIgnore)
            throws JSONException,
                   javax.jcr.RepositoryException
Creates a JSONObject out of node. All node's properties will be reflected in the JSON object, except those in propertyNamesToIgnore. In addition, properties jcr:path and jcr:name are added. Their values are those returned by node.getPath() and node.getName(), respectively.

Parameters:
node - The JCR node to use
propertyNamesToIgnore - A set of property names that should not be reflected in the resulting JSON object.
Throws:
JSONException - If there's a problem generating the JSON object
javax.jcr.RepositoryException - If there's a problem reading data from the JCR repository
Method Detail

addProperty

protected void addProperty(javax.jcr.Property p)
                    throws javax.jcr.ValueFormatException,
                           javax.jcr.RepositoryException,
                           JSONException
Throws:
javax.jcr.ValueFormatException
javax.jcr.RepositoryException
JSONException

addValue

protected void addValue(java.lang.String key,
                        javax.jcr.Value v)
                 throws java.lang.IllegalStateException,
                        javax.jcr.RepositoryException,
                        JSONException
Throws:
java.lang.IllegalStateException
javax.jcr.RepositoryException
JSONException


Copyright © 2007-2009. All Rights Reserved.