org.apache.sling.servlets.get.impl.helpers
Class JsonResourceWriter

java.lang.Object
  extended by org.apache.sling.servlets.get.impl.helpers.JsonResourceWriter

public class JsonResourceWriter
extends Object

Dumps JCR Items as JSON data. The dump methods are threadsafe. Dump can be done on the Resource, property or value level.


Field Summary
static Locale DATE_FORMAT_LOCALE
          Used to format date values
static String ECMA_DATE_FORMAT
          Used to format date values
 
Constructor Summary
JsonResourceWriter(Set<String> propertyNamesToIgnore)
          Create a JsonItemWriter
 
Method Summary
protected  void dump(Resource resource, JSONWriter w, int currentRecursionLevel, int maxRecursionLevels)
          Dump given resource in JSON, optionally recursing into its objects
 void dump(Resource resource, Writer w, int maxRecursionLevels)
          Dump given resource in JSON, optionally recursing into its object
 void dump(Resource resource, Writer w, int maxRecursionLevels, boolean tidy)
          Dump given resource in JSON, optionally recursing into its objects
 void dumpProperties(Resource resource, JSONWriter w, List<String> properties)
          Dump only a subset of the resource properties
protected  void dumpSingleResource(Resource n, JSONWriter w, int currentRecursionLevel, int maxRecursionLevels)
          Dump a single node
 void dumpValue(JSONWriter w, Object value)
          Dump only a value in the correct format
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, ValueMap valueMap, String key, Object value)
          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

JsonResourceWriter

public JsonResourceWriter(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(Resource resource,
                 Writer w,
                 int maxRecursionLevels)
          throws JSONException
Dump given resource in JSON, optionally recursing into its object

Throws:
JSONException

dump

public void dump(Resource resource,
                 Writer w,
                 int maxRecursionLevels,
                 boolean tidy)
          throws JSONException
Dump given resource in JSON, optionally recursing into its objects

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

dump

protected void dump(Resource resource,
                    JSONWriter w,
                    int currentRecursionLevel,
                    int maxRecursionLevels)
             throws JSONException
Dump given resource in JSON, optionally recursing into its objects

Throws:
JSONException

dumpProperties

public void dumpProperties(Resource resource,
                           JSONWriter w,
                           List<String> properties)
                    throws JSONException
Dump only a subset of the resource properties

Throws:
JSONException

dumpValue

public void dumpValue(JSONWriter w,
                      Object value)
               throws JSONException
Dump only a value in the correct format

Throws:
JSONException

dumpSingleResource

protected void dumpSingleResource(Resource n,
                                  JSONWriter w,
                                  int currentRecursionLevel,
                                  int maxRecursionLevels)
                           throws JSONException
Dump a single node

Throws:
JSONException

recursionLevelActive

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


writeProperty

protected void writeProperty(JSONWriter w,
                             ValueMap valueMap,
                             String key,
                             Object value)
                      throws JSONException
Write a single property

Throws:
JSONException

format

public static String format(Calendar date)


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.