You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/04/04 20:49:06 UTC

svn commit: r644820 - /incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java

Author: fmeschbe
Date: Fri Apr  4 11:49:00 2008
New Revision: 644820

URL: http://svn.apache.org/viewvc?rev=644820&view=rev
Log:
Some code formatting

Modified:
    incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java

Modified: incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java?rev=644820&r1=644819&r2=644820&view=diff
==============================================================================
--- incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java (original)
+++ incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java Fri Apr  4 11:49:00 2008
@@ -35,8 +35,8 @@
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.io.JSONWriter;
 
-/** Dumps JCR Items as JSON data. The dump methods
- *  are threadsafe.
+/**
+ * Dumps JCR Items as JSON data. The dump methods are threadsafe.
  */
 public class JsonItemWriter {
 
@@ -44,19 +44,25 @@
 
     private final Set<String> propertyNamesToIgnore;
 
-    /** Create a JsonItemWriter
-     *  @param 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.
+    /**
+     * Create a JsonItemWriter
+     * 
+     * @param 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.
      */
     public JsonItemWriter(Set<String> propertyNamesToIgnore) {
         this.propertyNamesToIgnore = propertyNamesToIgnore;
     }
 
-    /** Dump all Nodes of given NodeIterator in JSON
-     * @throws JSONException */
-    public void dump(NodeIterator it, Writer out) throws RepositoryException, JSONException {
+    /**
+     * Dump all Nodes of given NodeIterator in JSON
+     * 
+     * @throws JSONException
+     */
+    public void dump(NodeIterator it, Writer out) throws RepositoryException,
+            JSONException {
         final JSONWriter w = new JSONWriter(out);
         w.array();
         while (it.hasNext()) {
@@ -66,12 +72,14 @@
     }
 
     /** Dump given node in JSON, optionally recursing into its child nodes */
-    public void dump(Node node, Writer w, int maxRecursionLevels) throws RepositoryException, JSONException {
+    public void dump(Node node, Writer w, int maxRecursionLevels)
+            throws RepositoryException, JSONException {
         dump(node, new JSONWriter(w), 0, maxRecursionLevels);
     }
 
     /** Dump given property in JSON */
-    public void dump(Property p, Writer w) throws JSONException, ValueFormatException, RepositoryException {
+    public void dump(Property p, Writer w) throws JSONException,
+            ValueFormatException, RepositoryException {
         final JSONWriter jw = new JSONWriter(w);
         jw.object();
         writeProperty(jw, p);
@@ -79,8 +87,8 @@
     }
 
     /** Dump given node in JSON, optionally recursing into its child nodes */
-    protected void dump(Node node, JSONWriter w, int currentRecursionLevel, int maxRecursionLevels)
-    throws RepositoryException, JSONException {
+    protected void dump(Node node, JSONWriter w, int currentRecursionLevel,
+            int maxRecursionLevels) throws RepositoryException, JSONException {
 
         w.object();
         PropertyIterator props = node.getProperties();
@@ -89,7 +97,8 @@
         while (props.hasNext()) {
             Property prop = props.nextProperty();
 
-            if (propertyNamesToIgnore!=null && propertyNamesToIgnore.contains(prop.getName())) {
+            if (propertyNamesToIgnore != null
+                && propertyNamesToIgnore.contains(prop.getName())) {
                 continue;
             }
 
@@ -97,9 +106,9 @@
         }
 
         // the child nodes
-        if(recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
+        if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
             final NodeIterator children = node.getNodes();
-            while(children.hasNext()) {
+            while (children.hasNext()) {
                 final Node n = children.nextNode();
                 dumpSingleNode(n, w, currentRecursionLevel, maxRecursionLevels);
             }
@@ -109,8 +118,9 @@
     }
 
     /** Dump a single node */
-    protected void dumpSingleNode(Node n, JSONWriter w, int currentRecursionLevel, int maxRecursionLevels)
-    throws RepositoryException, JSONException {
+    protected void dumpSingleNode(Node n, JSONWriter w,
+            int currentRecursionLevel, int maxRecursionLevels)
+            throws RepositoryException, JSONException {
         if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
             w.key(n.getName());
             dump(n, w, currentRecursionLevel + 1, maxRecursionLevels);
@@ -118,18 +128,21 @@
     }
 
     /** true if the current recursion level is active */
-    protected boolean recursionLevelActive(int currentRecursionLevel, int maxRecursionLevels) {
-        return maxRecursionLevels < 0 || currentRecursionLevel < maxRecursionLevels;
+    protected boolean recursionLevelActive(int currentRecursionLevel,
+            int maxRecursionLevels) {
+        return maxRecursionLevels < 0
+            || currentRecursionLevel < maxRecursionLevels;
     }
 
     /**
      * Write a single property
      */
     protected void writeProperty(JSONWriter w, Property p)
-    throws ValueFormatException, RepositoryException, JSONException {
+            throws ValueFormatException, RepositoryException, JSONException {
         // special handling for binaries: we dump the length and not the length
-                if (p.getType() == PropertyType.BINARY) {
-            // TODO for now we mark binary properties with an initial colon in their name
+        if (p.getType() == PropertyType.BINARY) {
+            // TODO for now we mark binary properties with an initial colon in
+            // their name
             // (colon is not allowed as a JCR property name)
             // in the name, and the value should be the size of the binary data
             w.key(":" + p.getName());
@@ -138,7 +151,7 @@
             } else {
                 final long[] sizes = p.getLengths();
                 w.array();
-                for(int i=0;i<sizes.length;i++) {
+                for (int i = 0; i < sizes.length; i++) {
                     w.value(sizes[i]);
                 }
                 w.endArray();
@@ -151,7 +164,7 @@
             dumpValue(w, p.getValue());
         } else {
             w.array();
-            for(Value v : p.getValues()) {
+            for (Value v : p.getValues()) {
                 dumpValue(w, v);
             }
             w.endArray();
@@ -160,18 +173,38 @@
 
     /**
      * Writes the given value to the JSON writer. currently the following
-     * conversions are done:
-     * <table>
-     *   <tr><th>JSR Property Type</th><th>JSON Value Type</th></tr>
-     *   <tr><td>BINARY</td><td>always 0 as long</td></tr>
-     *   <tr><td>DATE</td><td>converted date string as defined by ECMA</td></tr>
-     *   <tr><td>BOOLEAN</td><td>boolean</td></tr>
-     *   <tr><td>LONG</td><td>long</td></tr>
-     *   <tr><td>DOUBLE</td><td>double</td></tr>
-     *   <tr><td><i>all other</li></td><td>string</td></tr>
-     * </table>
-     * <sup>1</sup> Currently not implemented and uses 0 as default.
-     *
+     * conversions are done: <table>
+     * <tr>
+     * <th>JSR Property Type</th>
+     * <th>JSON Value Type</th>
+     * </tr>
+     * <tr>
+     * <td>BINARY</td>
+     * <td>always 0 as long</td>
+     * </tr>
+     * <tr>
+     * <td>DATE</td>
+     * <td>converted date string as defined by ECMA</td>
+     * </tr>
+     * <tr>
+     * <td>BOOLEAN</td>
+     * <td>boolean</td>
+     * </tr>
+     * <tr>
+     * <td>LONG</td>
+     * <td>long</td>
+     * </tr>
+     * <tr>
+     * <td>DOUBLE</td>
+     * <td>double</td>
+     * </tr>
+     * <tr>
+     * <td><i>all other</li>
+     * </td>
+     * <td>string</td>
+     * </tr>
+     * </table> <sup>1</sup> Currently not implemented and uses 0 as default.
+     * 
      * @param w json writer
      * @param v value to dump
      */