dev@javaserverfaces.java.net

Seeking Review [696-SuppressXmlDeclaration]

From: Ed Burns <edward.burns_at_oracle.com>
Date: Mon, 26 Jul 2010 13:17:18 -0700

https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=696

SECTION: Modified Files
----------------------------
M jsf-api/src/main/java/javax/faces/application/ViewHandler.java

-

    /**
     * <p class="changed_added_2_1">If this param is set to true, the
     * XML declaration that appears at the start of a Facelet page (if
     * present) is suppressed and not passed through to the user agent.</p>
     *
     * @since 2.1
     */

    public static final String = FACELETS_SUPPRESS_XML_DECLARATION
            "javax.faces.FACELETS_SUPPRESS_XML_DECLARATION";

M jsf-ri/src/main/java/com/sun/faces/facelets/compiler/SAXCompiler.java

- leverage new option

M jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java

- add new option

M jsf-ri/systest-per-webapp/build.xml

- add new test webapp

M jsf-ri/systest-per-webapp/build-tests.xml

- add new testcase in test webapp

A jsf-ri/systest-per-webapp/suppress-xml-decl
A jsf-ri/systest-per-webapp/suppress-xml-decl/src
A jsf-ri/systest-per-webapp/suppress-xml-decl/src/java
A jsf-ri/systest-per-webapp/suppress-xml-decl/src/java/com
A jsf-ri/systest-per-webapp/suppress-xml-decl/src/java/com/sun
A jsf-ri/systest-per-webapp/suppress-xml-decl/src/java/com/sun/faces
A jsf-ri/systest-per-webapp/suppress-xml-decl/src/java/com/sun/faces/systest
A jsf-ri/systest-per-webapp/suppress-xml-decl/src/java/com/sun/faces/systest/SuppressXmlDeclTestCase.java
A jsf-ri/systest-per-webapp/suppress-xml-decl/web
A jsf-ri/systest-per-webapp/suppress-xml-decl/web/index.xhtml
A jsf-ri/systest-per-webapp/suppress-xml-decl/web/WEB-INF
A jsf-ri/systest-per-webapp/suppress-xml-decl/web/WEB-INF/web.xml

- the new test webapp

M usingFacesInWebapps.fm

- 11.1.3 Application Configuration Parameters

  re-alphabetized the context params

  Added FACELETS_SUPPRESS_XML_DECLARATION.




SECTION: Diffs
----------------------------
Index: jsf-api/src/main/java/javax/faces/application/ViewHandler.java
===================================================================
--- jsf-api/src/main/java/javax/faces/application/ViewHandler.java (revision 8515)
+++ jsf-api/src/main/java/javax/faces/application/ViewHandler.java (working copy)
@@ -171,7 +171,18 @@
     public static final String FACELETS_VIEW_MAPPINGS_PARAM_NAME =
             "javax.faces.FACELETS_VIEW_MAPPINGS";
 
+ /**
+ * <p class="changed_added_2_1">If this param is set to true, the
+ * XML declaration that appears at the start of a Facelet page (if
+ * present) is suppressed and not passed through to the user agent.</p>
+ *
+ * @since 2.1
+ */
 
+ public static final String FACELETS_SUPPRESS_XML_DECLARATION =
+ "javax.faces.FACELETS_SUPPRESS_XML_DECLARATION";
+
+
     // ---------------------------------------------------------- Public Methods
 
 
Index: jsf-ri/src/main/java/com/sun/faces/facelets/compiler/SAXCompiler.java
===================================================================
--- jsf-ri/src/main/java/com/sun/faces/facelets/compiler/SAXCompiler.java (revision 8515)
+++ jsf-ri/src/main/java/com/sun/faces/facelets/compiler/SAXCompiler.java (working copy)
@@ -55,6 +55,7 @@
 package com.sun.faces.facelets.compiler;
 
 import com.sun.faces.RIConstants;
+import com.sun.faces.config.WebConfiguration;
 import com.sun.faces.facelets.tag.TagAttributeImpl;
 import com.sun.faces.facelets.tag.TagAttributesImpl;
 import org.xml.sax.*;
@@ -417,9 +418,12 @@
                 String r = new String(b);
                 Matcher m = XmlDeclaration.matcher(r);
                 if (m.find()) {
- mngr.writeInstruction(m.group(0) + "\n");
- if (m.group(3) != null) {
- encoding = m.group(3);
+ WebConfiguration config = WebConfiguration.getInstance();
+ if (!config.isOptionEnabled(WebConfiguration.BooleanWebContextInitParameter.SuppressXmlDeclaration)) {
+ mngr.writeInstruction(m.group(0) + "\n");
+ if (m.group(3) != null) {
+ encoding = m.group(3);
+ }
                     }
                 }
             }
Index: jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java
===================================================================
--- jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java (revision 8515)
+++ jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java (working copy)
@@ -1143,6 +1143,10 @@
         CacheResourceModificationTimestamp(
               "com.sun.faces.cacheResourceModificationTimestamp",
               false
+ ),
+ SuppressXmlDeclaration(
+ "javax.faces.FACELETS_SUPPRESS_XML_DECLARATION",
+ false
         );
 
         private BooleanWebContextInitParameter alternate;
Index: jsf-ri/systest-per-webapp/suppress-xml-decl/src/java/com/sun/faces/systest/SuppressXmlDeclTestCase.java
===================================================================
--- jsf-ri/systest-per-webapp/suppress-xml-decl/src/java/com/sun/faces/systest/SuppressXmlDeclTestCase.java (revision 0)
+++ jsf-ri/systest-per-webapp/suppress-xml-decl/src/java/com/sun/faces/systest/SuppressXmlDeclTestCase.java (revision 0)
@@ -0,0 +1,102 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package com.sun.faces.systest;
+
+
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.sun.faces.htmlunit.AbstractTestCase;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+public class SuppressXmlDeclTestCase extends AbstractTestCase {
+
+ private final static Pattern XmlDeclaration = Pattern.compile("^<\\?xml.+?version=['\"](.+?)['\"](.+?encoding=['\"]((.+?))['\"])?.*?\\?>");
+
+
+ public SuppressXmlDeclTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+
+ /**
+ * Return the tests included in this test suite.
+ */
+ public static Test suite() {
+ return (new TestSuite(SuppressXmlDeclTestCase.class));
+ }
+
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ super.tearDown();
+ }
+
+
+ // ------------------------------------------------------------ Test Methods
+
+ public void testSuppressXmlDecl() throws Exception {
+ URL url = getURL("/faces/index.xhtml");
+ InputStreamReader reader = new InputStreamReader(url.openStream());
+ BufferedReader bufferedReader = new BufferedReader(reader);
+ String line = bufferedReader.readLine();
+ while (0 == line.length()) {
+ line = bufferedReader.readLine();
+ }
+ Matcher m = XmlDeclaration.matcher(line);
+ assertFalse(m.find());
+
+ HtmlPage page = getPage("/faces/index.xhtml");
+ String xml = page.asXml();
+ assertTrue(xml.contains("javax.faces.ViewState"));
+
+ }
+}
Index: jsf-ri/systest-per-webapp/suppress-xml-decl/web/index.xhtml
===================================================================
--- jsf-ri/systest-per-webapp/suppress-xml-decl/web/index.xhtml (revision 0)
+++ jsf-ri/systest-per-webapp/suppress-xml-decl/web/index.xhtml (revision 0)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<!--
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common Development
+ and Distribution License("CDDL") (collectively, the "License"). You
+ may not use this file except in compliance with the License. You can obtain
+ a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ When distributing the software, include this License Header Notice in each
+ file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ Sun designates this particular file as subject to the "Classpath" exception
+ as provided by Sun in the GPL Version 2 section of the License file that
+ accompanied this code. If applicable, add the following below the License
+ Header, with the fields enclosed by brackets [] replaced by your own
+ identifying information: "Portions Copyrighted [year]
+ [name of copyright owner]"
+
+ Contributor(s):
+
+ If you wish your version of this file to be governed by only the CDDL or
+ only the GPL Version 2, indicate your decision by adding "[Contributor]
+ elects to include this software in this distribution under the [CDDL or GPL
+ Version 2] license." If you don't indicate a single choice of license, a
+ recipient has the option to distribute your version of this file under
+ either the CDDL, the GPL Version 2 or to extend the choice of license to
+ its licensees as provided above. However, if you add GPL Version 2 code
+ and therefore, elected the GPL Version 2 license, then the option applies
+ only if the new code is made subject to such option by the copyright
+ holder.
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
+ "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+<h:head>
+
+ <title>issue 696 test</title>
+
+</h:head>
+
+<h:body>
+
+ <h:form>
+
+ <h:commandButton value="reload" />
+
+ </h:form>
+
+</h:body>
+
+</html>
Index: jsf-ri/systest-per-webapp/suppress-xml-decl/web/WEB-INF/web.xml
===================================================================
--- jsf-ri/systest-per-webapp/suppress-xml-decl/web/WEB-INF/web.xml (revision 0)
+++ jsf-ri/systest-per-webapp/suppress-xml-decl/web/WEB-INF/web.xml (revision 0)
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common Development
+ and Distribution License("CDDL") (collectively, the "License"). You
+ may not use this file except in compliance with the License. You can obtain
+ a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ When distributing the software, include this License Header Notice in each
+ file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ Sun designates this particular file as subject to the "Classpath" exception
+ as provided by Sun in the GPL Version 2 section of the License file that
+ accompanied this code. If applicable, add the following below the License
+ Header, with the fields enclosed by brackets [] replaced by your own
+ identifying information: "Portions Copyrighted [year]
+ [name of copyright owner]"
+
+ Contributor(s):
+
+ If you wish your version of this file to be governed by only the CDDL or
+ only the GPL Version 2, indicate your decision by adding "[Contributor]
+ elects to include this software in this distribution under the [CDDL or GPL
+ Version 2] license." If you don't indicate a single choice of license, a
+ recipient has the option to distribute your version of this file under
+ either the CDDL, the GPL Version 2 or to extend the choice of license to
+ its licensees as provided above. However, if you add GPL Version 2 code
+ and therefore, elected the GPL Version 2 license, then the option applies
+ only if the new code is made subject to such option by the copyright
+ holder.
+-->
+<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_3_0.xsd">
+ <description>
+ test suppress xml config param
+ </description>
+ <display-name>test suppress xml config param</display-name>
+ <!-- Validate the Application Configuration Resources -->
+ <context-param>
+ <param-name>javax.faces.FACELETS_SUPPRESS_XML_DECLARATION</param-name>
+ <param-value>true</param-value>
+ </context-param>
+ <!-- Faces Servlet -->
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup> 1 </load-on-startup>
+ </servlet>
+ <!-- Faces Servlet Mapping -->
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>/faces/*</url-pattern>
+ </servlet-mapping>
+</web-app>
Index: jsf-ri/systest-per-webapp/build.xml
===================================================================
--- jsf-ri/systest-per-webapp/build.xml (revision 8515)
+++ jsf-ri/systest-per-webapp/build.xml (working copy)
@@ -105,7 +105,8 @@
                    write-attribute-script-enabled,
                    wcag-datatable,
                    flash,
- jsp-flash"/>
+ jsp-flash,
+ suppress-xml-decl"/>
     <!--
 
        EXCLUDED APPLICATIONS:
Index: jsf-ri/systest-per-webapp/build-tests.xml
===================================================================
--- jsf-ri/systest-per-webapp/build-tests.xml (revision 8515)
+++ jsf-ri/systest-per-webapp/build-tests.xml (working copy)
@@ -115,6 +115,8 @@
                value="com/sun/faces/systest/NoWebXMLTestCase.class" />
     <property name="injection"
                value="com/sun/faces/systest/InjectionTestCase.class" />
+ <property name="suppress-xml-decl"
+ value="com/sun/faces/systest/SuppressXmlDeclTestCase.class" />
 
     <!--
         EXCLUDED APPLICATIONS:

-- 
| edburns_at_oracle.com | office: +1 407 458 0017
| homepage:          | http://ridingthecrest.com/
| 15 work days until JSF 2.1 Milestone 2