You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2006/11/23 12:07:49 UTC

svn commit: r478531 - in /myfaces: shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/ tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/

Author: mmarinschek
Date: Thu Nov 23 03:07:47 2006
New Revision: 478531

URL: http://svn.apache.org/viewvc?view=rev&rev=478531
Log:
fixed TOMAHAWK-797: Nested CDATA sections not allowed

Modified:
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
    myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java?view=diff&rev=478531&r1=478530&r2=478531
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java Thu Nov 23 03:07:47 2006
@@ -63,6 +63,7 @@
     public static final String SUBMIT_FORM_FN_NAME = "oamSubmitForm";
     private static final String AUTO_SCROLL_PARAM = "autoScroll";
     private static final String AUTO_SCROLL_FUNCTION = "getScrolling";
+    public static final String ALLOW_CDATA_SECTION_ON = "org.apache.myfaces.ResponseWriter.CdataSectionOn";
 
     private HtmlRendererUtils() {
         // utility class, do not instantiate
@@ -1111,6 +1112,19 @@
 
         writer.endElement(HTML.SCRIPT_ELEM);
         writePrettyLineSeparator(facesContext);
+    }
+
+    public static boolean isAllowedCdataSection(FacesContext fc) {
+
+        Boolean value = (Boolean) fc.getExternalContext().getRequestMap().get(ALLOW_CDATA_SECTION_ON);
+
+        return value != null && ((Boolean) value).booleanValue();
+
+    }
+
+    public static void allowCdataSection(FacesContext fc, boolean cdataSectionAllowed)
+    {
+          fc.getExternalContext().getRequestMap().put(ALLOW_CDATA_SECTION_ON,Boolean.valueOf(cdataSectionAllowed));
     }
 
     public static class LinkParameter {

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java?view=diff&rev=478531&r1=478530&r2=478531
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java Thu Nov 23 03:07:47 2006
@@ -22,11 +22,10 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 import org.apache.myfaces.shared.renderkit.html.util.UnicodeEncoder;
-import org.apache.myfaces.shared.renderkit.html.HTML;
-import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils;
 
 import javax.faces.FacesException;
 import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
@@ -63,6 +62,13 @@
 
     private static final Set s_emptyHtmlElements = new HashSet();
 
+    private static final String CDATA_START = "<![CDATA[ \n";
+    private static final String COMMENT_START = "<!--\n";
+    private static final String CDATA_COMMENT_END = "\n//]]>";
+    private static final String CDATA_END = "\n]]>";
+    private static final String COMMENT_COMMENT_END = "\n//-->";
+    private static final String COMMENT_END = "\n-->";
+
     static
     {
         s_emptyHtmlElements.add("area");
@@ -191,11 +197,14 @@
                 {
                     if(HtmlRendererUtils.isXHTMLContentType(_contentType))
                     {
-                        _writer.write("<![CDATA[ \n");
+                        if(HtmlRendererUtils.isAllowedCdataSection(FacesContext.getCurrentInstance()))
+                        {
+                            _writer.write(CDATA_START);
+                        }
                     }
                     else
                     {
-                        _writer.write("<!--\n");
+                        _writer.write(COMMENT_START);
                     }
                 }
             }
@@ -272,17 +281,20 @@
         {
             if(HtmlRendererUtils.isXHTMLContentType(_contentType))
             {
-                if(isScript())
-                    _writer.write("\n//]]>");
-                else
-                    _writer.write("\n]]>");
+                if(HtmlRendererUtils.isAllowedCdataSection(FacesContext.getCurrentInstance()))
+                {
+                    if(isScript())
+                        _writer.write(CDATA_COMMENT_END);
+                    else
+                        _writer.write(CDATA_END);
+                }
             }
             else
             {
                 if(isScript())
-                    _writer.write("\n//-->");
+                    _writer.write(COMMENT_COMMENT_END);
                 else
-                    _writer.write("\n-->");
+                    _writer.write(COMMENT_END);
             }
         }
 

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java?view=diff&rev=478531&r1=478530&r2=478531
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java Thu Nov 23 03:07:47 2006
@@ -22,6 +22,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlResponseWriterImpl;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
 
 import javax.faces.FacesException;
 import javax.faces.application.StateManager;
@@ -118,7 +119,9 @@
 				out.print("<component id=\"" +
 					component.getClientId(context) +
 					"\"><![CDATA[");
-				try
+                boolean oldValue = HtmlRendererUtils.isAllowedCdataSection(context);
+                HtmlRendererUtils.allowCdataSection(context, false);
+                try
 				{
 					RendererUtils.renderChildren(context, component);
 				}
@@ -126,7 +129,8 @@
 				{
 					throw new FacesException(e);
 				}
-				out.print("]]></component>");
+                HtmlRendererUtils.allowCdataSection(context, oldValue);
+                out.print("]]></component>");
 			}
 			else
 			{