tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkuhn...@apache.org
Subject svn commit: r431046 - in /tapestry/tapestry4/trunk: ./ tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/ tapestry-framework/src/java/org/apache/tapestry/dojo/form/ tapestry-framework/src/java/org/apache/tapestry/json/ tapestr...
Date Sat, 12 Aug 2006 16:07:50 GMT
Author: jkuhnert
Date: Sat Aug 12 09:07:50 2006
New Revision: 431046

URL: http://svn.apache.org/viewvc?rev=431046&view=rev
Log:
JSONWriter changes to support TAPESTRY-1053. It's kind of a breaking change for people, but
given that it's this early in the game I'm
hoping it won't be noticed as much. Hopefully this refactoring represents a more long term
solution than the previous.

Modified:
    tapestry/tapestry4/trunk/pom.xml
    tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/form/Autocompleter.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/IJSONWriter.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/form/TestAutocompleter.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java

Modified: tapestry/tapestry4/trunk/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/pom.xml?rev=431046&r1=431045&r2=431046&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/pom.xml (original)
+++ tapestry/tapestry4/trunk/pom.xml Sat Aug 12 09:07:50 2006
@@ -88,7 +88,7 @@
                 <role>Developer</role>
             </roles>
             <timezone>-2</timezone>
-        </developer>        
+        </developer>
     </developers>
 
     <modules>
@@ -342,21 +342,25 @@
                     </reportSet>
                 </reportSets>
             </plugin>
-            <!--
-                <plugin>
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-changes-plugin</artifactId>
                 <version>2.0-beta-2-SNAPSHOT</version>
                 <reportSets>
-                <reportSet>
-                <reports>
-                <report>changes-report</report>
-                <report>jira-report</report>
-                </reports>
-                </reportSet>
+                    <reportSet>
+                        <reports>
+                            <report>changes-report</report>
+                            <report>jira-report</report>
+                        </reports>
+                    </reportSet>
                 </reportSets>
-                </plugin>
-            -->
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-site-plugin</artifactId>
+                <version>2.0-SNAPSHOT</version>
+            </plugin>
         </plugins>
     </reporting>
 

Modified: tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java?rev=431046&r1=431045&r2=431046&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java
Sat Aug 12 09:07:50 2006
@@ -105,8 +105,6 @@
     {
         cycle.getResponseBuilder().updateComponent("projectDescription");
         cycle.getResponseBuilder().updateComponent("feedbackBlock");
-        
-        System.out.println("Found event with name: " + event.getName());
     }
     
     public void linkUpdateClicked()

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/form/Autocompleter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/form/Autocompleter.java?rev=431046&r1=431045&r2=431046&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/form/Autocompleter.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/form/Autocompleter.java
Sat Aug 12 09:07:50 2006
@@ -130,11 +130,13 @@
         Iterator it = filteredValues.keySet().iterator();
         Object key = null;
         
+        JSONObject json = writer.object();
+        
         while (it.hasNext()) {
             
             key = it.next();
             
-            writer.put(getDataSqueezer().squeeze(key), filteredValues.get(key));
+            json.put(getDataSqueezer().squeeze(key), filteredValues.get(key));
         }
         
     }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/IJSONWriter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/IJSONWriter.java?rev=431046&r1=431045&r2=431046&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/IJSONWriter.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/json/IJSONWriter.java
Sat Aug 12 09:07:50 2006
@@ -14,412 +14,40 @@
 
 package org.apache.tapestry.json;
 
-import java.util.Iterator;
 
 /**
- * JavaScript Object Notation writer interface that defines an object capable of
- * writing JSON style output. 
+ * JavaScript Object Notation writer which manages two core object response 
+ * types, {@link JSONObject} or {@link JSONArray}. It is up to the components
+ * participating in a particular response to decide how to cooperate and build
+ * a JSON structure that their client side will accept.
  * 
  * @see <a href="http://www.json.org/">http://www.json.org/</a>
  * @author JSON.org, jkuhnert
  */
 public interface IJSONWriter
-{
+{   
     /**
-     * Accumulate values under a key. It is similar to the put method except
-     * that if there is already an object stored under the key then a JSONArray
-     * is stored under the key to hold all of the accumulated values. If there
-     * is already a JSONArray, then the new value is appended to it. In
-     * contrast, the put method replaces the previous value.
+     * Provides access to the core outer {@link JSONObject} being 
+     * rendered to a response. The object may not necessarily be instantiated
+     * until requested, for instances where a response should be a pure array
+     * or other.
      * 
-     * @param key
-     *            A key string.
-     * @param value
-     *            An object to be accumulated under the key.
-     * @return this.
-     * @throws NullPointerException
-     *             if the key is null
-     */
-    IJSONWriter accumulate(String key, Object value);
-
-    /**
-     * Get the value object associated with a key.
-     * 
-     * @param key
-     *            A key string.
-     * @return The object associated with the key.
-     * @exception NoSuchElementException
-     *                if the key is not found.
-     */
-    Object get(String key);
-
-    /**
-     * Get the boolean value associated with a key.
-     * 
-     * @param key
-     *            A key string.
-     * @return The truth.
-     * @exception NoSuchElementException
-     *                if the key is not found.
-     * @exception ClassCastException
-     *                if the value is not a Boolean or the String "true" or
-     *                "false".
-     */
-    boolean getBoolean(String key);
-
-    /**
-     * Get the double value associated with a key.
-     * 
-     * @param key
-     *            A key string.
-     * @return The numeric value.
-     * @exception NumberFormatException
-     *                if the value cannot be converted to a number.
-     * @exception NoSuchElementException
-     *                if the key is not found or if the value is a Number
-     *                object.
-     */
-    double getDouble(String key);
-
-    /**
-     * Get the int value associated with a key.
-     * 
-     * @param key
-     *            A key string.
-     * @return The integer value.
-     * @exception NoSuchElementException
-     *                if the key is not found
-     * @exception NumberFormatException
-     *                if the value cannot be converted to a number.
-     */
-    int getInt(String key);
-
-    /**
-     * Get the JSONArray value associated with a key.
-     * 
-     * @param key
-     *            A key string.
-     * @return A JSONArray which is the value.
-     * @exception NoSuchElementException
-     *                if the key is not found or if the value is not a
-     *                JSONArray.
-     */
-    JSONArray getJSONArray(String key);
-
-    /**
-     * Get the JSONObject value associated with a key.
-     * 
-     * @param key
-     *            A key string.
-     * @return A JSONObject which is the value.
-     * @exception NoSuchElementException
-     *                if the key is not found or if the value is not a
-     *                JSONObject.
-     */
-    IJSONWriter getJSONObject(String key);
-
-    /**
-     * Get the string associated with a key.
-     * 
-     * @param key
-     *            A key string.
-     * @return A string which is the value.
-     * @exception NoSuchElementException
-     *                if the key is not found.
-     */
-    String getString(String key);
-
-    /**
-     * Determine if the JSONObject contains a specific key.
-     * 
-     * @param key
-     *            A key string.
-     * @return true if the key exists in the JSONObject.
-     */
-    boolean has(String key);
-
-    /**
-     * Determine if the value associated with the key is null or if there is no
-     * value.
-     * 
-     * @param key
-     *            A key string.
-     * @return true if there is no value associated with the key or if the value
-     *         is the JSONObject.NULL object.
-     */
-    boolean isNull(String key);
-
-    /**
-     * Get an enumeration of the keys of the JSONObject.
-     * 
-     * @return An iterator of the keys.
-     */
-    Iterator keys();
-
-    /**
-     * Get the number of keys stored in the JSONObject.
-     * 
-     * @return The number of keys in the JSONObject.
-     */
-    int length();
-
-    /**
-     * Produce a JSONArray containing the names of the elements of this
-     * JSONObject.
-     * 
-     * @return A JSONArray containing the key strings, or null if the JSONObject
-     *         is empty.
-     */
-    JSONArray names();
-
-    /**
-     * Get an optional value associated with a key.
-     * 
-     * @param key
-     *            A key string.
-     * @return An object which is the value, or null if there is no value.
-     * @exception NullPointerException
-     *                The key must not be null.
-     */
-    Object opt(String key);
-
-    /**
-     * Get an optional boolean associated with a key. It returns false if there
-     * is no such key, or if the value is not Boolean.TRUE or the String "true".
-     * 
-     * @param key
-     *            A key string.
-     * @return The truth.
-     */
-    boolean optBoolean(String key);
-
-    /**
-     * Get an optional boolean associated with a key. It returns the
-     * defaultValue if there is no such key, or if it is not a Boolean or the
-     * String "true" or "false" (case insensitive).
-     * 
-     * @param key
-     *            A key string.
-     * @param defaultValue
-     *            The default.
-     * @return The truth.
-     */
-    boolean optBoolean(String key, boolean defaultValue);
-
-    /**
-     * Get an optional double associated with a key, or NaN if there is no such
-     * key or if its value is not a number. If the value is a string, an attempt
-     * will be made to evaluate it as a number.
-     * 
-     * @param key
-     *            A string which is the key.
-     * @return An object which is the value.
-     */
-    double optDouble(String key);
-
-    /**
-     * Get an optional double associated with a key, or the defaultValue if
-     * there is no such key or if its value is not a number. If the value is a
-     * string, an attempt will be made to evaluate it as a number.
-     * 
-     * @param key
-     *            A key string.
-     * @param defaultValue
-     *            The default.
-     * @return An object which is the value.
-     */
-    double optDouble(String key, double defaultValue);
-
-    /**
-     * Get an optional int value associated with a key, or zero if there is no
-     * such key or if the value is not a number. If the value is a string, an
-     * attempt will be made to evaluate it as a number.
-     * 
-     * @param key
-     *            A key string.
-     * @return An object which is the value.
-     */
-    int optInt(String key);
-
-    /**
-     * Get an optional int value associated with a key, or the default if there
-     * is no such key or if the value is not a number. If the value is a string,
-     * an attempt will be made to evaluate it as a number.
-     * 
-     * @param key
-     *            A key string.
-     * @param defaultValue
-     *            The default.
-     * @return An object which is the value.
-     */
-    int optInt(String key, int defaultValue);
-
-    /**
-     * Get an optional JSONArray associated with a key. It returns null if there
-     * is no such key, or if its value is not a JSONArray.
-     * 
-     * @param key
-     *            A key string.
-     * @return A JSONArray which is the value.
-     */
-    JSONArray optJSONArray(String key);
-
-    /**
-     * Get an optional JSONObject associated with a key. It returns null if
-     * there is no such key, or if its value is not a JSONObject.
-     * 
-     * @param key
-     *            A key string.
-     * @return A JSONObject which is the value.
-     */
-    IJSONWriter optJSONObject(String key);
-
-    /**
-     * Get an optional string associated with a key. It returns an empty string
-     * if there is no such key. If the value is not a string and is not null,
-     * then it is coverted to a string.
-     * 
-     * @param key
-     *            A key string.
-     * @return A string which is the value.
-     */
-    String optString(String key);
-
-    /**
-     * Get an optional string associated with a key. It returns the defaultValue
-     * if there is no such key.
-     * 
-     * @param key
-     *            A key string.
-     * @param defaultValue
-     *            The default.
-     * @return A string which is the value.
-     */
-    String optString(String key, String defaultValue);
-
-    /**
-     * Put a key/boolean pair in the JSONObject.
-     * 
-     * @param key
-     *            A key string.
-     * @param value
-     *            A boolean which is the value.
-     * @return this.
-     */
-    IJSONWriter put(String key, boolean value);
-    
-    /**
-     * Put a key/double pair in the JSONObject.
-     * 
-     * @param key
-     *            A key string.
-     * @param value
-     *            A double which is the value.
-     * @return this.
-     */
-    IJSONWriter put(String key, double value);
-
-    /**
-     * Put a key/int pair in the JSONObject.
-     * 
-     * @param key
-     *            A key string.
-     * @param value
-     *            An int which is the value.
-     * @return this.
-     */
-    IJSONWriter put(String key, int value);
-
-    /**
-     * Put a key/value pair in the JSONObject. If the value is null, then the
-     * key will be removed from the JSONObject if it is present.
-     * 
-     * @param key
-     *            A key string.
-     * @param value
-     *            An object which is the value. It should be of one of these
-     *            types: Boolean, Double, Integer, JSONArray, JSONObject,
-     *            String, or the JSONObject.NULL object.
-     * @return this.
-     * @exception NullPointerException
-     *                The key must be non-null.
+     * @return The {@link JSONObject} being delegated to.
      */
-    IJSONWriter put(String key, Object value);
+    JSONObject object();
     
     /**
-     * Put a key/value pair in the JSONObject, but only if the value is
-     * non-null.
-     * 
-     * @param key
-     *            A key string.
-     * @param value
-     *            An object which is the value. It should be of one of these
-     *            types: Boolean, Double, Integer, JSONArray, JSONObject,
-     *            String, or the JSONObject.NULL object.
-     * @return this.
-     * @exception NullPointerException
-     *                The key must be non-null.
-     */
-    IJSONWriter putOpt(String key, Object value);
-
-    /**
-     * Remove a name and its value, if present.
+     * Provides access to the core outer {@link JSONArray} being 
+     * rendered to a response. The object may not necessarily be instantiated
+     * until requested.
      * 
-     * @param key
-     *            The name to be removed.
-     * @return The value that was associated with the name, or null if there was
-     *         no value.
+     * @return The {@link JSONArray} being delegated to.
      */
-    Object remove(String key);
-
-    /**
-     * Produce a JSONArray containing the values of the members of this
-     * JSONObject.
-     * 
-     * @param names
-     *            A JSONArray containing a list of key strings. This determines
-     *            the sequence of the values in the result.
-     * @return A JSONArray of values.
-     */
-    JSONArray toJSONArray(JSONArray names);
-
-    /**
-     * Make an JSON external form string of this JSONObject. For compactness, no
-     * unnecessary whitespace is added.
-     * <p>
-     * Warning: This method assumes that the data structure is acyclical.
-     * 
-     * @return a printable, displayable, portable, transmittable representation
-     *         of the object, beginning with <code>{</code>&nbsp;<small>(left
-     *         brace)</small> and ending with <code>}</code>&nbsp;<small>(right
-     *         brace)</small>.
-     */
-    String toString();
-
-    /**
-     * Make a prettyprinted JSON external form string of this JSONObject.
-     * <p>
-     * Warning: This method assumes that the data structure is acyclical.
-     * 
-     * @param indentFactor
-     *            The number of spaces to add to each level of indentation.
-     * @return a printable, displayable, portable, transmittable representation
-     *         of the object, beginning with <code>{</code>&nbsp;<small>(left
-     *         brace)</small> and ending with <code>}</code>&nbsp;<small>(right
-     *         brace)</small>.
-     */
-    String toString(int indentFactor);
+    JSONArray array();
     
     /**
      * Causes any un-ended blocks to be closed, as well as 
      * any reasources associated with writer to be flushed/written.
      */
     void close();
-    
-    /**
-     * Allows access to the underlying {@link JSONObject} being used to
-     * write content.
-     * @return The {@link JSONObject} being delegated to.
-     */
-    JSONObject getJSONSource();
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java?rev=431046&r1=431045&r2=431046&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/markup/JSONWriterImpl.java
Sat Aug 12 09:07:50 2006
@@ -14,7 +14,6 @@
 package org.apache.tapestry.markup;
 
 import java.io.PrintWriter;
-import java.util.Iterator;
 
 import org.apache.hivemind.util.Defense;
 import org.apache.tapestry.json.IJSONWriter;
@@ -22,7 +21,7 @@
 import org.apache.tapestry.json.JSONObject;
 
 /**
- * Implementation of {@link IIJSONWriter}.
+ * Implementation of {@link IJSONWriter}.
  * 
  * @author jkuhnert
  */
@@ -32,11 +31,16 @@
     protected PrintWriter _writer;
     
     /**
-     * Delegate object that handles all json logic.
+     * Delegate object that handles object json renders.
      */
     private JSONObject _json;
     
     /**
+     * Delegate array object that handles object array json renders.
+     */
+    private JSONArray _array;
+    
+    /**
      * Creates a new instance that will write all content to 
      * the specified {@link PrintWriter}.
      * 
@@ -47,295 +51,6 @@
         Defense.notNull(writer, "writer");
         
         _writer = writer;
-        _json = new JSONObject();
-    }
-    
-    /** 
-     * {@inheritDoc}
-     */
-    public IJSONWriter accumulate(String key, Object value)
-    {
-        _json.accumulate(key, value);
-        return this;
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public boolean equals(Object o)
-    {
-        return _json.equals(o);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public Object get(String key)
-    {
-        return _json.get(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public boolean getBoolean(String key)
-    {
-        return _json.getBoolean(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public double getDouble(String key)
-    {
-        return _json.getDouble(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public int getInt(String key)
-    {
-        return _json.getInt(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public JSONArray getJSONArray(String key)
-    {
-        return _json.getJSONArray(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public IJSONWriter getJSONObject(String key)
-    {
-        _json.getJSONObject(key);
-        return this;
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public String getString(String key)
-    {
-        return _json.getString(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public boolean has(String key)
-    {
-        return _json.has(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public int hashCode()
-    {
-        return _json.hashCode();
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public boolean isNull(String key)
-    {
-        return _json.isNull(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public Iterator keys()
-    {
-        return _json.keys();
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public int length()
-    {
-        return _json.length();
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public JSONArray names()
-    {
-        return _json.names();
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public Object opt(String key)
-    {
-        return _json.opt(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public boolean optBoolean(String key, boolean defaultValue)
-    {
-        return _json.optBoolean(key, defaultValue);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public boolean optBoolean(String key)
-    {
-        return _json.optBoolean(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public double optDouble(String key, double defaultValue)
-    {
-        return _json.optDouble(key, defaultValue);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public double optDouble(String key)
-    {
-        return _json.optDouble(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public int optInt(String key, int defaultValue)
-    {
-        return _json.optInt(key, defaultValue);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public int optInt(String key)
-    {
-        return _json.optInt(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public JSONArray optJSONArray(String key)
-    {
-        return _json.optJSONArray(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public IJSONWriter optJSONObject(String key)
-    {
-        _json.optJSONObject(key);
-        return this;
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public String optString(String key, String defaultValue)
-    {
-        return _json.optString(key, defaultValue);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public String optString(String key)
-    {
-        return _json.optString(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public IJSONWriter put(String key, boolean value)
-    {
-        _json.put(key, value);
-        return this;
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public IJSONWriter put(String key, double value)
-    {
-        _json.put(key, value);
-        return this;
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public IJSONWriter put(String key, int value)
-    {
-        _json.put(key, value);
-        return this;
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public IJSONWriter put(String key, Object value)
-    {
-        _json.put(key, value);
-        return this;
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public IJSONWriter putOpt(String key, Object value)
-    {
-        _json.putOpt(key, value);
-        return this;
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public Object remove(String key)
-    {
-        return _json.remove(key);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public JSONArray toJSONArray(JSONArray names)
-    {
-        return _json.toJSONArray(names);
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public String toString()
-    {
-        return _json.toString();
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    public String toString(int indentFactor)
-    {
-        return _json.toString(indentFactor);
     }
 
     /**
@@ -344,7 +59,15 @@
      */
     public void close()
     {
-        _writer.write(_json.toString());
+        if (_json != null && _json.length() > 0) {
+            
+            _writer.write(_json.toString());
+        }
+        
+        if (_array != null && _array.length() > 0) {
+            
+            _writer.write(_array.toString());
+        }
         
         _writer.flush();
         _writer.close();
@@ -353,9 +76,23 @@
     /**
      * {@inheritDoc}
      */
-    public JSONObject getJSONSource()
+    public JSONObject object()
     {
+        if (_json == null)
+            _json = new JSONObject();
+        
         return _json;
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public JSONArray array()
+    {
+        if (_array == null)
+            _array = new JSONArray();
+        
+        return _array;
     }
     
     /**

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/form/TestAutocompleter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/form/TestAutocompleter.java?rev=431046&r1=431045&r2=431046&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/form/TestAutocompleter.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/form/TestAutocompleter.java
Sat Aug 12 09:07:50 2006
@@ -36,6 +36,7 @@
 import org.apache.tapestry.form.MockDelegate;
 import org.apache.tapestry.form.ValidatableFieldSupport;
 import org.apache.tapestry.json.IJSONWriter;
+import org.apache.tapestry.json.JSONObject;
 import org.apache.tapestry.services.DataSqueezer;
 import org.apache.tapestry.valid.IValidationDelegate;
 import org.apache.tapestry.valid.ValidatorException;
@@ -223,7 +224,7 @@
         DataSqueezer ds = newMock(DataSqueezer.class);
         checkOrder(ds, false);
         
-        IJSONWriter json = newBufferJSONWriter();
+        IJSONWriter writer = newBufferJSONWriter();
         
         Autocompleter component = newInstance(Autocompleter.class, new Object[]
         { "name", "fred", "model", model,
@@ -235,9 +236,11 @@
         
         replay();
         
-        component.renderComponent(json, cycle);
+        component.renderComponent(writer, cycle);
         
         verify();
+        
+        JSONObject json = writer.object();
         
         assertEquals(json.length(), 3);
         assertEquals(json.get("1"), "Simple 1");

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java?rev=431046&r1=431045&r2=431046&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/markup/TestJSONWriter.java
Sat Aug 12 09:07:50 2006
@@ -20,6 +20,7 @@
 
 import org.apache.tapestry.BaseComponentTestCase;
 import org.apache.tapestry.json.IJSONWriter;
+import org.apache.tapestry.json.JSONObject;
 import org.testng.annotations.Test;
 
 
@@ -39,13 +40,15 @@
     {
         IJSONWriter writer = newJSONWriter();
         
-        writer.put("red", "ball");
-        writer.put("black", "cat");
-        writer.put("orange", "orange");
+        JSONObject json = writer.object();
         
-        assertEquals(writer.get("red"), "ball");
-        assertEquals(writer.get("black"), "cat");
-        assertEquals(writer.get("orange"), "orange");
+        json.put("red", "ball");
+        json.put("black", "cat");
+        json.put("orange", "orange");
+        
+        assertEquals(json.get("red"), "ball");
+        assertEquals(json.get("black"), "cat");
+        assertEquals(json.get("orange"), "orange");
     }
     
     /* All writer content is written to this buffer */



Mime
View raw message