You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2009/06/15 22:24:41 UTC

svn commit: r784963 - in /myfaces/trinidad/branches/1.2.11.3-branch: trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/ trinidad-impl/src/main/java/org/apache/myfaces/tr...

Author: matzew
Date: Mon Jun 15 20:24:40 2009
New Revision: 784963

URL: http://svn.apache.org/viewvc?rev=784963&view=rev
Log:
TRINIDAD-1495 - ResponseWriters should throw IllegalStateException when attributes written outside of start element
TRINIDAD-1504 - Allow FlattenedComponent to render content

thanks to Blake Sullivan for the patches

Modified:
    myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessingContext.java
    myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java
    myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java
    myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelFormLayoutRenderer.java
    myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelListRenderer.java

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessingContext.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessingContext.java?rev=784963&r1=784962&r2=784963&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessingContext.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ComponentProcessingContext.java Mon Jun 15 20:24:40 2009
@@ -18,8 +18,8 @@
  */
 package org.apache.myfaces.trinidad.component;
 
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
+import java.util.Collections;
+import java.util.Set;
 
 /**
  * ProcessingContext passed to FlattenedComponents and ComponentProcessors representing the
@@ -36,6 +36,24 @@
   ComponentProcessingContext()
   {      
   }
+
+  /**
+   * Hints to the the FlattenedComponents regarding what the flattened iteration is being used for,
+   * The FlattenedComponent may use this information to change its flattening behavior.
+   * For example, a FlattenedComponent may generate output during a <code>PROCESS_FOR_ENCODING</code>
+   * iteration, but not during a normal iteration.
+   */
+  public enum ProcessingHint
+  {
+    /**
+     * Indicates that the iteration is occurring in order to encode iterated components.  This
+     * hint may only be used during the RenderResponse phase and only once per an iterated
+     * component.  Due to these guarantees, the FlattenedComponent is allowed to generate
+     * content during the iteration, an exception to the normal rule that iterations must
+     * be idempotent in case the same component is iterated multiple times.
+     */
+    PROCESS_FOR_ENCODING
+  }
   
   /**
    * Returns the current starting group depth of the ProcessingContext.  The starting depth is only
@@ -60,7 +78,17 @@
   {
     return _groupDepth;
   }
-  
+
+  /**
+   * <p>Returns hints that influence the behavior of the component processing</p>
+   *
+   * @return a non-empty, unmodifiable collection of ProcessingHints
+   */
+  public Set<ProcessingHint> getHints()
+  {
+    return _hints;
+  }
+
   /**
    * Increment the grouping and startGroup states.
    * <p>
@@ -103,6 +131,15 @@
     _startDepth = 0;
   }
   
+  /**
+   * Handshake from the UIXComponent
+   */
+  void __setIsRendering()
+  {
+    _hints = Collections.singleton(ProcessingHint.PROCESS_FOR_ENCODING);
+  }
+
   private int _startDepth;
   private int _groupDepth;
+  private Set<ProcessingHint> _hints = Collections.emptySet();
 }

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java?rev=784963&r1=784962&r2=784963&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponent.java Mon Jun 15 20:24:40 2009
@@ -50,17 +50,16 @@
 {
   /**
    * Helper function called by Renderers to iterate over a flattened view of a group of
-   * potentially FlattenedComponent instances rooted at a single child of the component that
-   * the Renderer is encoding, invoking the <code>childProcessor</code> with its
-   * <code>callbackContext</code> on each renderable instance.
+   * potentially FlattenedComponent instances rooted at a single child of the component to collect
+   * information about these children prior to encoding the children using
+   * <code>encodeFlattenedChild(FacesContext, ComponentProcessor, UIComponent, Object)</code>.
    * <p>
    * If the child is a FlattenedComponent, the <code>childProcessor</code> will
    * be called on each of that FlattenedComponent's children, recursing if those children are
    * themselves FlattenedComponents, otherwise, the <code>childProcessor</code> will be called on
    * the child itself.
    * <p>
-   * This method is typically used to flatten the contents of a facet on the FlattenedComponent to
-   * be encoded.  If the Renderer accidentally passes in the component to be encoded instead of one
+   *  If the Renderer accidentally passes in the component to be processed instead of one
    * of its children, the result will almost certainly be an infinite recursion and stack overflow.
    * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, Iterable, Object)
    * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext, ComponentProcessor, UIComponent, Object)
@@ -81,6 +80,51 @@
   }
 
   /**
+   * Helper function called by Renderers to encode a flattened view of a group of
+   * potentially FlattenedComponent instances rooted at a single child of the component,
+   * invoking the <code>childProcessor</code> with its
+   * <code>callbackContext</code> on each renderable instance.  This method must  be called
+   * when the childProcessor is actually encoding and the childProcessor must not attempt
+   * to encode the same component instances more than once per request.
+   * <p>
+   * If a Renderer needs to
+   * collect information about its possibly flattened children before calling
+   * <code>encodeFlattenedChild(FacesContext, ComponentProcessor, UIComponent, Object)</code>,
+   * it should call <code>processFlattenedChildren(FacesContext, ComponentProcessor, UIComponent, Object)</code>
+   * to collect the information.
+   * <p>
+   * If the child is a FlattenedComponent, the <code>childProcessor</code> will
+   * be called  on each of that FlattenedComponent's children, recursing if those children are
+   * themselves FlattenedComponents, otherwise, the <code>childProcessor</code> will be called on
+   * the child itself.
+   * <p>
+   * FlattenedComponents that wish to check whether they are processed for the purpose of
+   * encoding can check the ProcessingHints of the ComponentProcessingContext for the
+   * presence of <code>PROCESS_FOR_ENCODING hint</code>.
+   * <p>
+   * If the Renderer accidentally passes in the component to be encoded instead of one
+   * of its children, the result will almost certainly be an infinite recursion and stack overflow.
+   * @return <code>true</code> If any children were processed
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, UIComponent, Object)
+   * @see FlattenedComponent
+   */
+  public static <S> boolean encodeFlattenedChild(
+    FacesContext context,
+    ComponentProcessor<S> childProcessor,
+    UIComponent child,
+    S callbackContext) throws IOException
+  {
+    ComponentProcessingContext processingContext = new ComponentProcessingContext();
+    processingContext.__setIsRendering();
+
+    return processFlattenedChildren(context,
+                                    processingContext,
+                                    childProcessor,
+                                    child,
+                                    callbackContext);
+  }
+
+  /**
    * Helper function called by FlattenedComponent to iterate over a flattened view of a group of
    * potentially FlattenedComponent instances rooted at a single child of the FlattenedComponent,
    * invoking the <code>childProcessor</code> with its
@@ -94,12 +138,13 @@
    * This method is typically used to flatten the contents of a facet of the FlattenedComponent.
    * If the FlattenedComponent accidentally passes in itself instead of one
    * of its children, the result will almost certainly be an infinite recursion and stack overflow.
+   * @return <code>true</code> If any children were processed
    * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, UIComponent, Object)
    * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, Iterable, Object)
    * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext, ComponentProcessor, Iterable, Object)
    * @see FlattenedComponent
    */
-    public static <S> boolean processFlattenedChildren(
+  public static <S> boolean processFlattenedChildren(
     FacesContext context,
     ComponentProcessingContext cpContext,
     ComponentProcessor<S> childProcessor,
@@ -153,6 +198,7 @@
    * <p>
    * This method is typically used to flatten the children of the FlattenedComponent to
    * be encoded.
+   * @return <code>true</code> If any children were processed
    * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, UIComponent, Object)
    * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext, ComponentProcessor, UIComponent, Object)
    * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessingContext, ComponentProcessor, Iterable, Object)
@@ -172,6 +218,49 @@
   }
 
   /**
+   * Helper function called by Renderers to encode a flattened view of their children,
+   * invoking the <code>childProcessor</code> with its
+   * <code>callbackContext</code> on each renderable instance.  This method must  be called
+   * when the childProcessor is actually encoding and the childProcessor must not attempt
+   * to encode the same component instances more than once per request.
+   * <p>
+   * If a Renderer needs to
+   * collect information about its possibly flattened children before calling
+   * <code>encodeFlattenedChild(FacesContext, ComponentProcessor, Iterable<UIComponent>, Object)</code>,
+   * it should call
+   * <code>processFlattenedChildren(FacesContext, ComponentProcessor, Iterable<UIComponent>, Object)</code>
+   * to collect the information.
+   * <p>
+   * For each FlattenedComponent child, the <code>childProcessor</code> will
+   * be called on each of that FlattenedComponent's children, recursing if those children are
+   * themselves FlattenedComponents, otherwise, the <code>childProcessor</code> will be called on
+   * the child itself.
+   * <p>
+   * FlattenedComponents that wish to check whether they are processed for the purpose of
+   * encoding can check the ProcessingHints of the ComponentProcessingContext for the
+   * presence of <code>PROCESS_FOR_ENCODING hint</code>.
+   * @return <code>true</code> If any children were processed
+   * @see UIXComponent#processFlattenedChildren(FacesContext, ComponentProcessor, Iterable, Object)
+   * @see FlattenedComponent
+   */
+  public static <S> boolean encodeFlattenedChildren(
+    FacesContext context,
+    ComponentProcessor<S> childProcessor,
+    Iterable<UIComponent> children,
+    S callbackContext) throws IOException
+  {
+    ComponentProcessingContext processingContext = new ComponentProcessingContext();
+    processingContext.__setIsRendering();
+    
+    return processFlattenedChildren(context,
+                                    processingContext,
+                                    childProcessor,
+                                    children,
+                                    callbackContext);
+  }
+
+
+  /**
    * Helper function called by FlattenedComponents to iterate over a flattened view of their
    * children, potentially themselves FlattenedComponents, invoking the <code>childProcessor</code>
    * with its <code>callbackContext</code> on each renderable instance.

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java?rev=784963&r1=784962&r2=784963&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java Mon Jun 15 20:24:40 2009
@@ -28,7 +28,6 @@
 
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.util.IntegerUtils;
-import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.MimeTypes;
 import org.apache.myfaces.trinidadinternal.share.url.EncoderUtils;
 import org.apache.myfaces.trinidadinternal.share.util.CaboHttpUtils;
 
@@ -193,6 +192,10 @@
     // it has an attribute, and is thus needed
     _outputPendingElements();
 
+    // if we aren't in in the element's start tag, we shouldn't be writing attributes
+    if (!_closeStart)
+      throw new IllegalStateException();
+
     Writer out = _out;
 
     Class<?> valueClass = value.getClass();
@@ -252,6 +255,10 @@
     // it has an attribute, and is thus needed
     _outputPendingElements();
 
+    // if we aren't in in the element's start tag, we shouldn't be writing attributes
+    if (!_closeStart)
+      throw new IllegalStateException();
+
     Writer out = _out;
 
     // No current support for multi-part URI attributes
@@ -441,7 +448,7 @@
 
 
   /**
-   * Flushes out any pending element, celaring the pending
+   * Flushes out any pending element, clearing the pending
    * entry.
    */
   private void _outputPendingElements() throws IOException

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelFormLayoutRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelFormLayoutRenderer.java?rev=784963&r1=784962&r2=784963&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelFormLayoutRenderer.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelFormLayoutRenderer.java Mon Jun 15 20:24:40 2009
@@ -295,10 +295,10 @@
       1, // colSpan
       renderedLayoutActions);
 
-    UIXComponent.processFlattenedChildren(context,
-                                          _formColumnEncoder,
-                                          formChildren,
-                                          columnEncodingState);
+    UIXComponent.encodeFlattenedChildren(context,
+                                         _formColumnEncoder,
+                                         formChildren,
+                                         columnEncodingState);
 
     rw.endElement("tr"); // the outer row
 
@@ -324,10 +324,8 @@
         actualColumns, // this is actually colSpan
         footerLayoutActions);
 
-      UIXComponent.processFlattenedChildren(context,
-                                            _formColumnEncoder,
-                                            footerFacetComponent,
-                                            footerEncodingState);
+      UIXComponent.encodeFlattenedChild(context, _formColumnEncoder, footerFacetComponent, footerEncodingState);
+
       rw.endElement("tr"); // the outer row
     }
 

Modified: myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelListRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelListRenderer.java?rev=784963&r1=784962&r2=784963&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelListRenderer.java (original)
+++ myfaces/trinidad/branches/1.2.11.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PanelListRenderer.java Mon Jun 15 20:24:40 2009
@@ -165,7 +165,7 @@
         columnWidth,
         listStyle,
         usesPossiblyMultipleColumnDom);
-    UIXComponent.processFlattenedChildren(
+    UIXComponent.encodeFlattenedChildren(
       context,
       _encoderCallback,
       children,