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

java.lang.Object
  extended by org.apache.sling.commons.json.jcr.JsonItemWriter
Direct Known Subclasses:
TidyJsonItemWriter

public class JsonItemWriter
extends Object

Dumps JCR Items as JSON data. The dump methods are threadsafe.


Field Summary
static Locale DATE_FORMAT_LOCALE
          Used to format date values
static String ECMA_DATE_FORMAT
          Used to format date values
 
Constructor Summary
JsonItemWriter(Set<String> propertyNamesToIgnore)
          Create a JsonItemWriter
 
Method Summary
 void dump(NodeIterator it, Writer out)
          Dump all Nodes of given NodeIterator in JSON
protected  void dump(Node node, JSONWriter w, int currentRecursionLevel, int maxRecursionLevels)
          Dump given node in JSON, optionally recursing into its child nodes
 void dump(Node node, Writer w, int maxRecursionLevels)
          Dump given node in JSON, optionally recursing into its child nodes
 void dump(Node node, Writer w, int maxRecursionLevels, boolean tidy)
          Dump given node in JSON, optionally recursing into its child nodes
 void dump(Property p, Writer w)
          Dump given property in JSON
protected  void dumpSingleNode(Node n, JSONWriter w, int currentRecursionLevel, int maxRecursionLevels)
          Dump a single node
protected  void dumpValue(JSONWriter w, Value v)
          Writes the given value to the JSON writer. currently the following conversions are done: JSR Property Type JSON Value Type BINARY always 0 as long DATE converted date string as defined by ECMA BOOLEAN boolean LONG long DOUBLE double all other string 1 Currently not implemented and uses 0 as default.
static String format(Calendar date)
           
protected  boolean recursionLevelActive(int currentRecursionLevel, int maxRecursionLevels)
          true if the current recursion level is active
protected  void writeProperty(JSONWriter w, Property p)
          Write a single property
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ECMA_DATE_FORMAT

public static final String ECMA_DATE_FORMAT
Used to format date values

See Also:
Constant Field Values

DATE_FORMAT_LOCALE

public static final Locale DATE_FORMAT_LOCALE
Used to format date values

Constructor Detail

JsonItemWriter

public JsonItemWriter(Set<String> propertyNamesToIgnore)
Create a JsonItemWriter

Parameters:
propertyNamesToIgnore - if not null, a property having a name from this set of values is ignored. TODO we should use a filtering interface to make the selection of which Nodes and Properties to dump more flexible.
Method Detail

dump

public void dump(NodeIterator it,
                 Writer out)
          throws RepositoryException,
                 JSONException
Dump all Nodes of given NodeIterator in JSON

Throws:
JSONException
RepositoryException

dump

public void dump(Node node,
                 Writer w,
                 int maxRecursionLevels)
          throws RepositoryException,
                 JSONException
Dump given node in JSON, optionally recursing into its child nodes

Throws:
RepositoryException
JSONException

dump

public void dump(Node node,
                 Writer w,
                 int maxRecursionLevels,
                 boolean tidy)
          throws RepositoryException,
                 JSONException
Dump given node in JSON, optionally recursing into its child nodes

Parameters:
tidy - if true the json dump is nicely formatted
Throws:
RepositoryException
JSONException

dump

public void dump(Property p,
                 Writer w)
          throws JSONException,
                 ValueFormatException,
                 RepositoryException
Dump given property in JSON

Throws:
JSONException
ValueFormatException
RepositoryException

dump

protected void dump(Node node,
                    JSONWriter w,
                    int currentRecursionLevel,
                    int maxRecursionLevels)
             throws RepositoryException,
                    JSONException
Dump given node in JSON, optionally recursing into its child nodes

Throws:
RepositoryException
JSONException

dumpSingleNode

protected void dumpSingleNode(Node n,
                              JSONWriter w,
                              int currentRecursionLevel,
                              int maxRecursionLevels)
                       throws RepositoryException,
                              JSONException
Dump a single node

Throws:
RepositoryException
JSONException

recursionLevelActive

protected boolean recursionLevelActive(int currentRecursionLevel,
                                       int maxRecursionLevels)
true if the current recursion level is active


writeProperty

protected void writeProperty(JSONWriter w,
                             Property p)
                      throws ValueFormatException,
                             RepositoryException,
                             JSONException
Write a single property

Throws:
ValueFormatException
RepositoryException
JSONException

dumpValue

protected void dumpValue(JSONWriter w,
                         Value v)
                  throws ValueFormatException,
                         IllegalStateException,
                         RepositoryException,
                         JSONException
Writes the given value to the JSON writer. currently the following conversions are done:
JSR Property Type JSON Value Type
BINARY always 0 as long
DATE converted date string as defined by ECMA
BOOLEAN boolean
LONG long
DOUBLE double
all other string
1 Currently not implemented and uses 0 as default.

Parameters:
w - json writer
v - value to dump
Throws:
ValueFormatException
IllegalStateException
RepositoryException
JSONException

format

public static String format(Calendar date)


Copyright © 2011-2013 Adobe Systems Incorporated. All Rights Reserved.