You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2005/03/25 22:18:39 UTC

cvs commit: jakarta-tapestry/framework/src/java/org/apache/tapestry/engine NullWriter.java

hlship      2005/03/25 13:18:39

  Modified:    .        status.xml
               framework/src/java/org/apache/tapestry/valid FieldLabel.java
               framework/src/test/org/apache/tapestry/markup
                        TestMarkupWriter.java
               framework/src/java/org/apache/tapestry IMarkupWriter.java
               framework/src/java/org/apache/tapestry/services/impl
                        LocalizedStringRender.java
               framework/src/test/org/apache/tapestry/components
                        TestInsert.java
               framework/src/java/org/apache/tapestry/components
                        Insert.java
               framework/src/java/org/apache/tapestry/engine
                        NullWriter.java
  Log:
  Add methods to IMarkupWriter that allow filtering to be specified using a parameter.
  
  Revision  Changes    Path
  1.81      +1 -0      jakarta-tapestry/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- status.xml	25 Mar 2005 20:36:58 -0000	1.80
  +++ status.xml	25 Mar 2005 21:18:38 -0000	1.81
  @@ -61,6 +61,7 @@
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-281"> Include a message digest, as a credential, inside asset URLs. </action>
         <action type="add" dev="HLS"> Add asset-encoding that encodes and decodes a friendly URL for the asset service. </action>
         <action type="update" dev="HLS"> Add an extra level of indirection, so that engine services can be wired together using the engine-service: object provider. </action>
  +      <action type="add" dev="HLS"> Add methods to IMarkupWriter that allow filtering to be specified using a parameter. </action>
       </release>
       <release version="3.1-alpha-1" date="Feb 21 2005">
         <action type="update" dev="HLS"> Remove dependencies on Jakarta digester, collections and beanutils. Add dependency on Jakarta HiveMind. </action>
  
  
  
  1.4       +1 -5      jakarta-tapestry/framework/src/java/org/apache/tapestry/valid/FieldLabel.java
  
  Index: FieldLabel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/valid/FieldLabel.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FieldLabel.java	5 Jan 2005 23:17:15 -0000	1.3
  +++ FieldLabel.java	25 Mar 2005 21:18:38 -0000	1.4
  @@ -91,11 +91,7 @@
   
           delegate.writeLabelPrefix(field, writer, cycle);
   
  -        if (getRaw()) {
  -            writer.printRaw(displayName);
  -        } else {
  -            writer.print(displayName);
  -        }
  +        writer.print(displayName, getRaw());
   
           delegate.writeLabelSuffix(field, writer, cycle);
       }
  
  
  
  1.2       +17 -1     jakarta-tapestry/framework/src/test/org/apache/tapestry/markup/TestMarkupWriter.java
  
  Index: TestMarkupWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/markup/TestMarkupWriter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestMarkupWriter.java	22 Mar 2005 13:40:53 -0000	1.1
  +++ TestMarkupWriter.java	25 Mar 2005 21:18:38 -0000	1.2
  @@ -249,6 +249,22 @@
           assertOutput("{Hello}");
       }
   
  +    public void testPrintWithRawFlag()
  +    {
  +        MarkupFilter filter = new EchoMarkupFilter();
  +        PrintWriter writer = newPrintWriter();
  +
  +        IMarkupWriter mw = new MarkupWriterImpl("text/html", writer, filter);
  +
  +        mw.print("Filtered", false);
  +
  +        assertOutput("{Filtered}");
  +
  +        mw.print("Raw", true);
  +
  +        assertOutput("Raw");
  +    }
  +
       public void testPrintClosesCurrentTag()
       {
           MarkupFilter filter = new EchoMarkupFilter();
  @@ -565,7 +581,7 @@
   
           assertOutput("<p");
   
  -        mw.printRaw("Fred");
  +        mw.print("Fred", true);
   
           assertOutput(">Fred");
   
  
  
  
  1.4       +113 -136  jakarta-tapestry/framework/src/java/org/apache/tapestry/IMarkupWriter.java
  
  Index: IMarkupWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/IMarkupWriter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IMarkupWriter.java	5 Jan 2005 23:17:12 -0000	1.3
  +++ IMarkupWriter.java	25 Mar 2005 21:18:38 -0000	1.4
  @@ -15,238 +15,215 @@
   package org.apache.tapestry;
   
   /**
  - *  Defines an object that can write markup (XML, HTML, XHTML) style output.
  - *  A <code>IMarkupWriter</code> handles translation from unicode to
  - *  the markup language (escaping characters such as '&lt;' and '&gt;' to
  - *  their entity equivalents, '&amp;lt;' and '&amp;gt;') as well as assisting
  - *  with nested elements, closing tags, etc.
  - *
  - *  @author Howard Ship, David Solis
  - **/
  + * Defines an object that can write markup (XML, HTML, XHTML) style output. A
  + * <code>IMarkupWriter</code> handles translation from unicode to the markup language (escaping
  + * characters such as '&lt;' and '&gt;' to their entity equivalents, '&amp;lt;' and '&amp;gt;') as
  + * well as assisting with nested elements, closing tags, etc.
  + * 
  + * @author Howard Ship, David Solis
  + */
   
   public interface IMarkupWriter
   {
       /**
        * Writes an integer attribute into the currently open tag.
  -     *
  -     * @throws IllegalStateException if there is no open tag.
  -     *
  -     **/
  +     * 
  +     * @throws IllegalStateException
  +     *             if there is no open tag.
  +     */
   
       public void attribute(String name, int value);
   
       /**
        * Writes a boolean attribute into the currently open tag.
  -     *
  -     * @throws IllegalStateException if there is no open tag.
  -     *
  +     * 
  +     * @throws IllegalStateException
  +     *             if there is no open tag.
        * @since 3.0
  -     **/
  +     */
   
       public void attribute(String name, boolean value);
   
       /**
        * Writes an attribute into the most recently opened tag. This must be called after
  -     * {@link #begin(String)}
  -     * and before any other kind of writing (which closes the tag).
  -     *
  -     * <p>The value may be null.
  -     *
  -     * @throws IllegalStateException if there is no open tag.
  -     **/
  +     * {@link #begin(String)}and before any other kind of writing (which closes the tag).
  +     * <p>
  +     * The value may be null.
  +     * 
  +     * @throws IllegalStateException
  +     *             if there is no open tag.
  +     */
   
       public void attribute(String name, String value);
   
       /**
  -     * Similar to {@link #attribute(String, String)} but no escaping of invalid elements
  -     * is done for the value.
  +     * Similar to {@link #attribute(String, String)}but no escaping of invalid elements is done for
  +     * the value.
        * 
  -     * @throws IllegalStateException if there is no open tag.
  -     *
  +     * @throws IllegalStateException
  +     *             if there is no open tag.
        * @since 3.0
  -     **/
  +     */
   
       public void attributeRaw(String name, String value);
   
       /**
  -     * Closes any existing tag then starts a new element. The new element is pushed
  -     * onto the active element stack.
  -     **/
  +     * Closes any existing tag then starts a new element. The new element is pushed onto the active
  +     * element stack.
  +     */
   
       public void begin(String name);
   
       /**
  -     * Starts an element that will not later be matched with an <code>end()</code>
  -     * call. This is useful for elements that
  -     * do not need closing tags.
  -     *
  -     **/
  +     * Starts an element that will not later be matched with an <code>end()</code> call. This is
  +     * useful for elements that do not need closing tags.
  +     */
   
       public void beginEmpty(String name);
   
       /**
  -     * Invokes checkError() on the <code>PrintWriter</code> used to
  -     *  format output.
  -     **/
  +     * Invokes checkError() on the <code>PrintWriter</code> used to format output.
  +     */
   
       public boolean checkError();
   
       /**
  -     * Closes this <code>IMarkupWriter</code>. Close tags are
  -     * written for any active elements. The <code>PrintWriter</code>
  -     * is then sent <code>close()</code>.  A nested writer will commit
  -     * its buffer to its containing writer.
  -     *
  -     **/
  +     * Closes this <code>IMarkupWriter</code>. Close tags are written for any active elements.
  +     * The <code>PrintWriter</code> is then sent <code>close()</code>. A nested writer will
  +     * commit its buffer to its containing writer.
  +     */
   
       public void close();
   
       /**
  -     * Closes the most recently opened element by writing the '&gt;' that ends
  -     * it. Once this is invoked, the <code>attribute()</code> methods
  -     * may not be used until a new element is opened with {@link #begin(String)} or
  -     * or {@link #beginEmpty(String)}.
  -     **/
  +     * Closes the most recently opened element by writing the '&gt;' that ends it. Once this is
  +     * invoked, the <code>attribute()</code> methods may not be used until a new element is opened
  +     * with {@link #begin(String)}or or {@link #beginEmpty(String)}.
  +     */
   
       public void closeTag();
   
       /**
  -     * Writes an XML/HTML comment. Any open tag is first closed. 
  -     * The method takes care of
  -     * providing the <code>&lt;!--</code> and <code>--&gt;</code>, and
  -     * provides a blank line after the close of the comment.
  -     *
  -     * <p><em>Most</em> characters are valid inside a comment, so no check
  -     * of the contents is made (much like {@link #printRaw(String)}.
  -     *
  -     **/
  +     * Writes an XML/HTML comment. Any open tag is first closed. The method takes care of providing
  +     * the <code>&lt;!--</code> and <code>--&gt;</code>, and provides a blank line after the
  +     * close of the comment.
  +     * <p>
  +     * <em>Most</em> characters are valid inside a comment, so no check of the contents is made
  +     * (much like {@link #printRaw(String)}.
  +     */
   
       public void comment(String value);
   
       /**
  -     * Ends the element most recently started by {@link
  -     * #begin(String)}.  The name of the tag is popped off of the
  -     * active element stack and used to form an HTML close tag.
  -     *
  -     **/
  +     * Ends the element most recently started by {@link#begin(String)}. The name of the tag is
  +     * popped off of the active element stack and used to form an HTML close tag.
  +     */
   
       public void end();
   
       /**
  -     * Ends the most recently started element with the given
  -     * name. This will also end any other intermediate
  -     * elements. This is very useful for easily ending a table or
  -     * even an entire page.
  -     *
  -     **/
  +     * Ends the most recently started element with the given name. This will also end any other
  +     * intermediate elements. This is very useful for easily ending a table or even an entire page.
  +     */
   
       public void end(String name);
   
       /**
  -     * Forwards <code>flush()</code> to this 
  -     * <code>IMarkupWriter</code>'s <code>PrintWriter</code>.
  -     *
  -     **/
  +     * Forwards <code>flush()</code> to this <code>IMarkupWriter</code>'s
  +     * <code>PrintWriter</code>.
  +     */
   
       public void flush();
   
       /**
  -     *  Returns a nested writer, one that accumulates its changes in a
  -     *  buffer.  When the nested  writer is closed, it writes its
  -     *  buffer into its containing <code>IMarkupWriter</code>.
  -     *
  -     **/
  +     * Returns a nested writer, one that accumulates its changes in a buffer. When the nested writer
  +     * is closed, it writes its buffer into its containing <code>IMarkupWriter</code>.
  +     */
   
       public IMarkupWriter getNestedWriter();
   
       /**
  -     *
  -     * The primary <code>print()</code> method, used by most other
  -     * methods.
  -     *
  -     * <p>Prints the character array, first closing any open tag. Problematic characters
  -     * ('&lt;', '&gt;' and '&amp;') are converted to appropriate
  -     * entities.
  -     *
  -     * <p>Does <em>nothing</em> if <code>data</code> is null.
  -     *
  -     * <p>Closes any open tag.
  -     *
  -     **/
  +     * Version of {@link #print(char[], int, int, boolean)}&nbsp;that assumes filter is
  +     * <em>enabled</em>.
  +     */
   
       public void print(char[] data, int offset, int length);
   
       /**
  +     * The primary <code>print()</code> method, used by most other methods.
  +     * <p>
  +     * Prints the character array, first closing any open tag. Problematic characters ('&lt;',
  +     * '&gt;' and '&amp;') are converted to appropriate entities.
  +     * <p>
  +     * Does <em>nothing</em> if <code>data</code> is null.
  +     * <p>
  +     * Closes any open tag.
  +     * 
  +     * @param data
  +     *            contains the characters to print, or null to not print anything
  +     * @param offset
  +     *            offset into the array to start printing from
  +     * @param length
  +     *            number of characters to print
  +     * @param raw
  +     *            if true, filtering is disabled
  +     * @since 3.1
  +     */
  +
  +    public void print(char[] data, int offset, int length, boolean raw);
  +
  +    /**
        * Prints a single character, or its equivalent entity.
  -     *
  -     * <p>Closes any open tag.
  -     *
  -     **/
  +     * <p>
  +     * Closes any open tag.
  +     */
   
       public void print(char value);
   
       /**
        * Prints an integer.
  -     *
  -     * <p>Closes any open tag.
  -     *
  -     **/
  +     * <p>
  +     * Closes any open tag.
  +     */
   
       public void print(int value);
   
       /**
  -     * Invokes {@link #print(char[], int, int)} to print the string.  Use
  -     * {@link #printRaw(String)} if the character data is known to be safe.
  -     *
  -     * <p>Does <em>nothing</em> if <code>value</code> is null.
  -     *
  -     * <p>Closes any open tag.
  -     *
  -     * @see #print(char[], int, int)
  -     *
  -     **/
  +     * As with {@link #print(char[], int, int, boolean)}, but the data to print is defined by the
  +     * String. Assumes filtering is <em>enabled</em>.
  +     */
   
       public void print(String value);
   
       /**
  -     * Closes the open tag (if any), then prints a line seperator to
  -     * the output stream.
  -     *
  -     **/
  +     * As with {@link #print(char[], int, int, boolean)}, but the data to print is defined by the
  +     * String.
  +     */
  +
  +    public void print(String value, boolean raw);
  +
  +    /**
  +     * Closes the open tag (if any), then prints a line seperator to the output stream.
  +     */
   
       public void println();
   
       /**
  -     * Prints a portion of an output buffer to the stream.
  -     * No escaping of invalid elements is done, which
  -     * makes this more effecient than <code>print()</code>. 
  -     * Does <em>nothing</em> if <code>buffer</code>
  -     * is null.
  -     *
  -     * <p>Closes any open tag.
  -     *
  -     **/
  +     * Version of {@link #print(char[], int, int, boolean)}that assumes filter is <em>enabled</em>.
  +     */
   
       public void printRaw(char[] buffer, int offset, int length);
   
       /**
  -     * Prints output to the stream. No escaping of invalid elements is done, which
  -     * makes this more effecient than <code>print()</code>.
  -     *
  -     * <p>Does <em>nothing</em> if <code>value</code>
  -     * is null.
  -     *
  -     * <p>Closes any open tag.
  -     *
  -     **/
  +     * As with {@link #print(char[], int, int, boolean)}, but the data to print is defined by the
  +     * String. Assumes filtering is <em>disabled</em>.
  +     */
   
       public void printRaw(String value);
   
       /**
  -     *  Returns the type of content generated by this response writer, as
  -     *  a MIME type.
  -     *
  -     **/
  +     * Returns the type of content generated by this response writer, as a MIME type.
  +     */
   
       public String getContentType();
   }
  \ No newline at end of file
  
  
  
  1.4       +2 -5      jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/LocalizedStringRender.java
  
  Index: LocalizedStringRender.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/LocalizedStringRender.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalizedStringRender.java	6 Jan 2005 02:17:11 -0000	1.3
  +++ LocalizedStringRender.java	25 Mar 2005 21:18:38 -0000	1.4
  @@ -76,11 +76,8 @@
           if (_value == null)
               _value = _component.getMessages().getMessage(_key);
   
  -        if (_raw)
  -            writer.printRaw(_value);
  -        else
  -            writer.print(_value);
  -
  +        writer.print(_value, _raw);
  +        
           if (_attributes != null)
               writer.end();
       }
  
  
  
  1.2       +4 -4      jakarta-tapestry/framework/src/test/org/apache/tapestry/components/TestInsert.java
  
  Index: TestInsert.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/components/TestInsert.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestInsert.java	21 Feb 2005 14:01:06 -0000	1.1
  +++ TestInsert.java	25 Mar 2005 21:18:39 -0000	1.2
  @@ -88,7 +88,7 @@
           IRequestCycle cycle = newRequestCycle(false);
           IMarkupWriter writer = newWriter();
   
  -        writer.print("42");
  +        writer.print("42", false);
   
           replayControls();
   
  @@ -109,7 +109,7 @@
           DateFormat format = DateFormat.getDateInstance();
           String expected = format.format(date);
   
  -        writer.print(expected);
  +        writer.print(expected, false);
   
           replayControls();
   
  @@ -165,7 +165,7 @@
           IRequestCycle cycle = newRequestCycle(false);
           IMarkupWriter writer = newWriter();
   
  -        writer.printRaw("42");
  +        writer.print("42", true);
   
           replayControls();
   
  @@ -188,7 +188,7 @@
           writer.begin("span");
           writer.attribute("class", "paisley");
           writer.attribute("informal", "informal-value");
  -        writer.print("42");
  +        writer.print("42", false);
           writer.end();
   
           replayControls();
  
  
  
  1.7       +2 -5      jakarta-tapestry/framework/src/java/org/apache/tapestry/components/Insert.java
  
  Index: Insert.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/components/Insert.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Insert.java	21 Feb 2005 14:01:06 -0000	1.6
  +++ Insert.java	25 Mar 2005 21:18:39 -0000	1.7
  @@ -77,11 +77,8 @@
               renderInformalParameters(writer, cycle);
           }
   
  -        if (getRaw())
  -            writer.printRaw(insert);
  -        else
  -            writer.print(insert);
  -
  +        writer.print(insert, getRaw());
  +        
           if (styleClass != null)
               writer.end(); // <span>
       }
  
  
  
  1.4       +21 -23    jakarta-tapestry/framework/src/java/org/apache/tapestry/engine/NullWriter.java
  
  Index: NullWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/engine/NullWriter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NullWriter.java	6 Jan 2005 02:17:12 -0000	1.3
  +++ NullWriter.java	25 Mar 2005 21:18:39 -0000	1.4
  @@ -17,14 +17,12 @@
   import org.apache.tapestry.IMarkupWriter;
   
   /**
  - *  A {@link IMarkupWriter} that does absolutely <em>nothing</em>; this
  - *  is used during the rewind phase of the request cycle when output
  - *  is discarded anyway.
  - *
  - *  @author Howard Lewis Ship, David Solis
  - *  @since 0.2.9
  - *
  - **/
  + * A {@link IMarkupWriter}that does absolutely <em>nothing</em>; this is used during the rewind
  + * phase of the request cycle when output is discarded anyway.
  + * 
  + * @author Howard Lewis Ship, David Solis
  + * @since 0.2.9
  + */
   
   public class NullWriter implements IMarkupWriter
   {
  @@ -67,10 +65,9 @@
       }
   
       /**
  -     *  Returns <code>this</code>: since a NullWriter doesn't actually
  -     *  do anything, one is as good as another!.
  -     *
  -     **/
  +     * Returns <code>this</code>: since a NullWriter doesn't actually do anything, one is as good
  +     * as another!.
  +     */
   
       public IMarkupWriter getNestedWriter()
       {
  @@ -107,9 +104,8 @@
       }
   
       /**
  -     *  Always returns false.
  -     *
  -     **/
  +     * Always returns false.
  +     */
   
       public boolean checkError()
       {
  @@ -133,22 +129,24 @@
       }
   
       /**
  -     *  @see org.apache.tapestry.IMarkupWriter#attribute(java.lang.String, boolean)
  -     *
  -     *  @since 3.0
  -     **/
  +     * @see org.apache.tapestry.IMarkupWriter#attribute(java.lang.String, boolean)
  +     * @since 3.0
  +     */
   
       public void attribute(String name, boolean value)
       {
       }
   
       /**
  -     *  @see org.apache.tapestry.IMarkupWriter#attributeRaw(java.lang.String, java.lang.String)
  -     *
  -     *  @since 3.0
  -     **/
  +     * @see org.apache.tapestry.IMarkupWriter#attributeRaw(java.lang.String, java.lang.String)
  +     * @since 3.0
  +     */
   
       public void attributeRaw(String name, String value)
       {
       }
  +
  +    public void print(char[] data, int offset, int length, boolean raw)
  +    {
  +    }
   }
  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org