You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bs...@apache.org on 2011/01/13 03:50:19 UTC

svn commit: r1058396 - in /myfaces/trinidad/trunk: trinidad-examples/trinidad-demo/src/main/webapp/demos/ trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/ trinidad-impl/src/...

Author: bsullivan
Date: Thu Jan 13 02:50:19 2011
New Revision: 1058396

URL: http://svn.apache.org/viewvc?rev=1058396&view=rev
Log:
Trinidad-2000 partial response writers should handle nesting of CDATA blocks.

Patch to fix cases where nested calls are made to startCDATA in the ResponseWriter (which will cause the CDATA block to be closed prematurely when the nested endCDATA is called) by ignoring all but the outermost CDATA block.

Also fixes places where Trinidad was outputting the start and end CDATA tokens in text to instead output them using startCDATA/endCDATA on the ResponseWriter

Thans Pavitra for the patch

Added:
    myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/faceletsTagsInTrinidad.xhtml
Modified:
    myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/XhtmlResponseWriter.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/XmlResponseWriter.java

Modified: myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml?rev=1058396&r1=1058395&r2=1058396&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml (original)
+++ myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml Thu Jan 13 02:50:19 2011
@@ -118,9 +118,8 @@ function setFocus(event)
 
                   <tr:outputFormatted styleUsage="instruction"
                                       value="h:commandButton using f:ajax." id="of13"/>
-                  <h:commandButton id="axBtn3" text="Submit"
-                                    actionListener="#{partialDemoUtil.action}">
-                    <f:ajax event="action" render="btnTarget" />
+                  <h:commandButton id="axBtn3" value="Submit" actionListener="#{partialDemoUtil.action}">
+                    <f:ajax event="click" render="btnTarget" />
                   </h:commandButton>
                 </tr:panelGroupLayout>
                 <tr:spacer width="30" height="10" id="sp12"/>

Added: myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/faceletsTagsInTrinidad.xhtml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/faceletsTagsInTrinidad.xhtml?rev=1058396&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/faceletsTagsInTrinidad.xhtml (added)
+++ myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/demos/tags/faceletsTagsInTrinidad.xhtml Thu Jan 13 02:50:19 2011
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+
+<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
+                xmlns:f="http://java.sun.com/jsf/core" xmlns:tr="http://myfaces.apache.org/trinidad"
+                xmlns:trd="http://myfaces.apache.org/trinidad/demo"
+                xmlns:trh="http://myfaces.apache.org/trinidad/html">
+  <tr:document title="Facelets Tags in Trinidad Page">
+    <tr:form id="f1">
+
+      <tr:panelHeader text="Tests for Facelets tags in Trinidad Demos">
+        <tr:outputFormatted styleUsage="instruction" id="of0"
+                            value="These demos test Trinidad components in conjunction with Facelets tags and JSF 2.0"/>
+        <tr:panelGroupLayout layout="vertical">
+          <f:facet name="separator">
+            <tr:spacer width="30" height="10"/>
+          </f:facet>    
+          
+          <tr:panelHeader text="ui:debug tag" id="phUIDbg">
+            <tr:outputFormatted styleUsage="instruction" id="of10"
+                                value="Tests the Facelets ui:debug"/>
+            <tr:spacer height="10" id="sp10"/>
+            <tr:inputText id="itStatus" label="View Status" value="#{partialDemoUtil.status.linkUpdate}"/>
+            <tr:commandButton text="PPR Status" id="clStatus" partialSubmit="true" actionListener="#{partialDemoUtil.action}">
+              <f:ajax event="action" render="phUIDbg"/>
+            </tr:commandButton>
+            <ui:debug hotkey="m"/>
+          </tr:panelHeader>
+          
+          
+        </tr:panelGroupLayout>
+      </tr:panelHeader>
+    </tr:form>
+  </tr:document>
+</ui:composition>
\ No newline at end of file

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java?rev=1058396&r1=1058395&r2=1058396&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/HtmlResponseWriter.java Thu Jan 13 02:50:19 2011
@@ -49,6 +49,7 @@ public class HtmlResponseWriter extends 
   {
     _out = out;
     _encoding = encoding;
+    _cdataCount = 0;
     CaboHttpUtils.validateEncoding(encoding);
   }
 
@@ -76,8 +77,13 @@ public class HtmlResponseWriter extends 
   public void startCDATA() throws IOException 
   {
     _closeStartIfNecessary();
-    _out.write("<![CDATA[");
 
+    // Ignore all nested calls to start a CDATA section except the first - a CDATA section cannot contain the string 
+    // "]]>" as the section ends ends with the first occurrence of this sequence.
+    _cdataCount++;
+    
+    if (_cdataCount == 1)
+      _out.write("<![CDATA[");
   }
 
   /**
@@ -86,7 +92,11 @@ public class HtmlResponseWriter extends 
    */
   public void endCDATA() throws IOException 
   {
-    _out.write("]]>");
+    // Only close the outermost CDATA section and ignore nested calls to endCDATA(). 
+    if (_cdataCount == 1)
+      _out.write("]]>");
+    
+    _cdataCount--;
   }
 
 
@@ -653,6 +663,9 @@ public class HtmlResponseWriter extends 
   private String      _pendingElement;
 
   private String      _currAttr;
+  
+  // number of CDATA sections started
+  private int         _cdataCount;
 
   // stack of skipped and unskipped elements used to determine when
   // to suppress the end tag of a skipped element

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/XhtmlResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/XhtmlResponseWriter.java?rev=1058396&r1=1058395&r2=1058396&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/XhtmlResponseWriter.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/io/XhtmlResponseWriter.java Thu Jan 13 02:50:19 2011
@@ -52,6 +52,7 @@ public class XhtmlResponseWriter extends
     // Ignored: getContentType() always identifies this as XHTML
     //_contentType = contentType;
     _encoding = encoding;
+    _cdataCount = 0;
     CaboHttpUtils.validateEncoding(encoding);
   }
 
@@ -86,7 +87,12 @@ public class XhtmlResponseWriter extends
   public void startCDATA() throws IOException 
   {
     _closeStartIfNecessary();
-    _out.write("<![CDATA[");
+    // Ignore all nested calls to start a CDATA section except the first - a CDATA section cannot contain the string 
+    // "]]>" as the section ends ends with the first occurrence of this sequence.
+    _cdataCount++;
+    
+    if (_cdataCount == 1)
+      _out.write("<![CDATA[");
   }
 
   /**
@@ -95,7 +101,11 @@ public class XhtmlResponseWriter extends
    */
   public void endCDATA() throws IOException 
   {
-    _out.write("]]>");
+    // Only close the outermost CDATA section and ignore nested calls to endCDATA(). 
+    if (_cdataCount == 1)
+      _out.write("]]>");
+    
+    _cdataCount--;
   }
 
   @Override
@@ -476,6 +486,9 @@ public class XhtmlResponseWriter extends
 
   // holds an element that will only be started if it has attributes
   private String      _pendingElement;
+  
+  // number of CDATA sections started
+  private int         _cdataCount;
 
   // stack of skipped and unskipped elements used to determine when
   // to suppress the end tag of a skipped element

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java?rev=1058396&r1=1058395&r2=1058396&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java Thu Jan 13 02:50:19 2011
@@ -325,8 +325,6 @@ public class PPRResponseWriter extends S
     return _xml;
   }
   
-  
-  
   /*
    * Writes out buffered inline scripts and script libraries
    */
@@ -475,7 +473,7 @@ public class PPRResponseWriter extends S
   {
     List<PPRTag> componentStack = _state.componentStack;
     int pos = componentStack.size() - 1;
-    PPRTag tag = (PPRTag) componentStack.get(pos);
+    PPRTag tag = componentStack.get(pos);
     componentStack.remove(pos);
 
     if (tag != null)
@@ -559,6 +557,21 @@ public class PPRResponseWriter extends S
       _state.changesStarted = false;
     }
   }
+
+  @Override
+  public void startCDATA()
+    throws IOException
+  {
+    _xml.startCDATA();
+  }
+
+  @Override
+  public void endCDATA()
+    throws IOException
+  {
+    _xml.endCDATA();
+  }
+
   //
   // Class representing PPR behavior associated with a tag.  The
   // base class simply tells PPR when it's working with a partial target
@@ -581,7 +594,7 @@ public class PPRResponseWriter extends S
         pprContext.pushRenderedPartialTarget(_id);
         _xml.startElement(_ELEMENT_CHANGES_UPDATE, null);
         _xml.writeAttribute(_ATTRIBUTE_ID, _renderedId, null);
-        _xml.write("<![CDATA[");
+        _xml.startCDATA();
         _xml.flush(); // NEW
 
         if (_LOG.isFine())
@@ -612,7 +625,7 @@ public class PPRResponseWriter extends S
         
         PPRResponseWriter.super.flush();
       
-        _xml.write("]]>");
+        _xml.endCDATA();
         _xml.endElement(_ELEMENT_CHANGES_UPDATE);
         _xml.flush();
         

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/XmlResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/XmlResponseWriter.java?rev=1058396&r1=1058395&r2=1058396&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/XmlResponseWriter.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/XmlResponseWriter.java Thu Jan 13 02:50:19 2011
@@ -35,6 +35,7 @@ public class XmlResponseWriter extends R
   {
     _out = writer;
     _encoding = encoding;
+    _cdataCount = 0;
   }
 
   public String getCharacterEncoding()
@@ -60,8 +61,12 @@ public class XmlResponseWriter extends R
   public void startCDATA() throws IOException 
   {
     closeStartIfNecessary();
-    _out.write("<![CDATA[");
-
+    // Ignore all nested calls to start a CDATA section except the first - a CDATA section cannot contain the string 
+    // "]]>" as the section ends ends with the first occurrence of this sequence.
+    _cdataCount++;
+    
+    if (_cdataCount == 1)
+      _out.write("<![CDATA[");
   }
 
   /**
@@ -70,7 +75,11 @@ public class XmlResponseWriter extends R
    */
   public void endCDATA() throws IOException 
   {
-    _out.write("]]>");
+    // Only close the outermost CDATA section and ignore nested calls to endCDATA(). 
+    if (_cdataCount == 1)
+      _out.write("]]>");
+    
+    _cdataCount--;
   }
 
   public void endDocument() throws IOException
@@ -236,4 +245,5 @@ public class XmlResponseWriter extends R
   private final Writer      _out;
   private final String      _encoding;
   private       boolean     _closeStart;
+  private       int         _cdataCount;
 }