You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/08/29 04:27:18 UTC

svn commit: r1518447 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/config/element/ main/java/org/apache/myfaces/view/facelets/compiler/ test/java/org/apache/myfaces/view/facelets/compiler/

Author: lu4242
Date: Thu Aug 29 02:27:18 2013
New Revision: 1518447

URL: http://svn.apache.org/r1518447
Log:
MYFACES-3761 Implement html5 doctype on facelets compiler 

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeInstruction.java   (with props)
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeUnit.java   (with props)
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/HTML5FaceletsProcessingTestCase.java
      - copied, changed from r1509781, myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/XHTMLFaceletsProcessingTestCase.java
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/element/FaceletsProcessing.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/CompilationManager.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/FaceletsProcessingInstructions.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/XHTMLFaceletsProcessingTestCase.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/element/FaceletsProcessing.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/element/FaceletsProcessing.java?rev=1518447&r1=1518446&r2=1518447&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/element/FaceletsProcessing.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/element/FaceletsProcessing.java Thu Aug 29 02:27:18 2013
@@ -27,6 +27,7 @@ import java.io.Serializable;
  */
 public abstract class FaceletsProcessing implements Serializable
 {
+    public static final String PROCESS_AS_HTML5 = "html5";
     public static final String PROCESS_AS_XHTML = "xhtml";
     public static final String PROCESS_AS_XML = "xml";
     public static final String PROCESS_AS_JSPX = "jspx";

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/CompilationManager.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/CompilationManager.java?rev=1518447&r1=1518446&r2=1518447&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/CompilationManager.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/CompilationManager.java Thu Aug 29 02:27:18 2013
@@ -130,6 +130,18 @@ final class CompilationManager
         }
         unit.writeInstruction(value);
     }
+    
+    public void writeDoctype(String name, String publicId, String systemId)
+    {
+        if (this.finished)
+        {
+            return;
+        }
+
+        DoctypeUnit unit = new DoctypeUnit(this.alias, this.nextTagId(),
+            name, publicId, systemId, faceletsProcessingInstructions.isHtml5Doctype());
+        this.startUnit(unit);
+    }
 
     public void writeText(String value)
     {

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeInstruction.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeInstruction.java?rev=1518447&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeInstruction.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeInstruction.java Thu Aug 29 02:27:18 2013
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+package org.apache.myfaces.view.facelets.compiler;
+
+import java.io.IOException;
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.faces.context.FacesContext;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public class DoctypeInstruction implements Instruction
+{
+    private final String name;
+    
+    private final String publicId;
+    
+    private final String systemId;
+    
+    private final boolean html5Doctype;
+
+    public DoctypeInstruction(String name, String publicId, String systemId, boolean html5Doctype)
+    {
+        this.name = name;
+        this.publicId = publicId;
+        this.systemId = systemId;
+        this.html5Doctype = html5Doctype;
+    }
+
+    public void write(FacesContext context) throws IOException
+    {
+        StringBuilder sb = new StringBuilder(64);
+        if (html5Doctype)
+        {
+            sb.append("<!DOCTYPE html>\n");
+        }
+        else
+        {
+            sb.append("<!DOCTYPE ").append(name);
+            if (publicId != null)
+            {
+                sb.append(" PUBLIC \"").append(publicId).append("\"");
+                if (systemId != null)
+                {
+                    sb.append(" \"").append(systemId).append("\"");
+                }
+            }
+            else if (systemId != null)
+            {
+                sb.append(" SYSTEM \"").append(systemId).append("\"");
+            }
+            sb.append(" >\n");
+        }
+        context.getResponseWriter().writeDoctype(sb.toString());
+    }
+
+    public Instruction apply(ExpressionFactory factory, ELContext ctx)
+    {
+        return this;
+    }
+
+    public boolean isLiteral()
+    {
+        return true;
+    }
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeInstruction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeUnit.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeUnit.java?rev=1518447&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeUnit.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeUnit.java Thu Aug 29 02:27:18 2013
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+package org.apache.myfaces.view.facelets.compiler;
+
+import javax.faces.view.facelets.CompositeFaceletHandler;
+import javax.faces.view.facelets.FaceletHandler;
+import org.apache.myfaces.view.facelets.el.ELText;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+final class DoctypeUnit extends CompilationUnit
+{
+    private final String alias;
+
+    private final String id;
+    
+    private final String name;
+    
+    private final String publicId;
+    
+    private final String systemId;
+    
+    private final boolean html5Doctype;
+
+    public DoctypeUnit(String alias, String id, String name, String publicId, String systemId, boolean html5Doctype)
+    {
+        this.alias = alias;
+        this.id = id;
+        this.name = name;
+        this.publicId = publicId;
+        this.systemId = systemId;
+        this.html5Doctype = html5Doctype;
+    }
+    
+    public FaceletHandler createFaceletHandler()
+    {
+        FaceletHandler[] h = new FaceletHandler[2];
+        h[0] = new UIInstructionHandler(this.alias, this.id, 
+            new Instruction[]{
+                new DoctypeInstruction(
+                    this.name, 
+                    this.publicId, 
+                    this.systemId, 
+                    this.html5Doctype)
+            }, new ELText(""));
+        h[1] = this.getNextFaceletHandler();
+        return new CompositeFaceletHandler(h);
+    }
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/DoctypeUnit.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/FaceletsProcessingInstructions.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/FaceletsProcessingInstructions.java?rev=1518447&r1=1518446&r2=1518447&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/FaceletsProcessingInstructions.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/FaceletsProcessingInstructions.java Thu Aug 29 02:27:18 2013
@@ -25,10 +25,15 @@ package org.apache.myfaces.view.facelets
  */
 public final class FaceletsProcessingInstructions
 {
+    public static final String PROCESS_AS_HTML5 = "html5";
     public static final String PROCESS_AS_JSPX = "jspx";
     public static final String PROCESS_AS_XHTML = "xhtml";
     public static final String PROCESS_AS_XML = "xml";
     
+    private static final FaceletsProcessingInstructions FACELETS_PROCESSING_HTML5 =
+        new FaceletsProcessingInstructions(
+                false, false, false, false, true, false, true, false, true);
+
     private static final FaceletsProcessingInstructions FACELETS_PROCESSING_XHTML =
         new FaceletsProcessingInstructions(
                 false, false, false, false, true, false, true);
@@ -41,6 +46,10 @@ public final class FaceletsProcessingIns
         new FaceletsProcessingInstructions(
                 true, true, true, true, false, true, false);
     
+    private static final FaceletsProcessingInstructions FACELETS_PROCESSING_HTML5_COMPRESS_SPACES =
+        new FaceletsProcessingInstructions(
+                false, false, false, false, true, false, true, true, true);
+    
     private static final FaceletsProcessingInstructions FACELETS_PROCESSING_XHTML_COMPRESS_SPACES =
         new FaceletsProcessingInstructions(
                 false, false, false, false, true, false, true, true);
@@ -69,11 +78,17 @@ public final class FaceletsProcessingIns
     
     private final boolean compressSpaces;
     
+    private final boolean html5Doctype;
+    
     public final static FaceletsProcessingInstructions getProcessingInstructions(String processAs)
     {
         if (processAs == null)
         {
-            return FACELETS_PROCESSING_XHTML;
+            return FACELETS_PROCESSING_HTML5;
+        }
+        else if (PROCESS_AS_HTML5.equals(processAs))
+        {
+            return FACELETS_PROCESSING_HTML5;
         }
         else if (PROCESS_AS_XHTML.equals(processAs))
         {
@@ -102,7 +117,11 @@ public final class FaceletsProcessingIns
         }
         if (processAs == null)
         {
-            return FACELETS_PROCESSING_XHTML_COMPRESS_SPACES;
+            return FACELETS_PROCESSING_HTML5_COMPRESS_SPACES;
+        }
+        else if (PROCESS_AS_HTML5.equals(processAs))
+        {
+            return FACELETS_PROCESSING_HTML5_COMPRESS_SPACES;
         }
         else if (PROCESS_AS_XHTML.equals(processAs))
         {
@@ -131,18 +150,16 @@ public final class FaceletsProcessingIns
             boolean consumeXMLComments,
             boolean swallowCDataContent)
     {
-        super();
-        this.consumeXmlDocType = consumeXmlDocType;
-        this.consumeXmlDeclaration = consumeXmlDeclaration;
-        this.consumeProcessingInstructions = consumeProcessingInstructions;
-        this.consumeCDataSections = consumeCDataSections;
-        this.escapeInlineText = escapeInlineText;
-        this.consumeXMLComments = consumeXMLComments;
-        this.swallowCDataContent = swallowCDataContent;
-        this.compressSpaces = false;
+        this(consumeXmlDocType, 
+            consumeXmlDeclaration, 
+            consumeProcessingInstructions, 
+            consumeCDataSections, 
+            escapeInlineText, 
+            consumeXMLComments, 
+            swallowCDataContent, 
+            false);
     }
     
-    
     public FaceletsProcessingInstructions(
             boolean consumeXmlDocType,
             boolean consumeXmlDeclaration,
@@ -153,6 +170,28 @@ public final class FaceletsProcessingIns
             boolean swallowCDataContent,
             boolean compressSpaces)
     {
+        this(consumeXmlDocType, 
+            consumeXmlDeclaration, 
+            consumeProcessingInstructions, 
+            consumeCDataSections, 
+            escapeInlineText, 
+            consumeXMLComments, 
+            swallowCDataContent, 
+            compressSpaces,
+            false);
+    }
+    
+    public FaceletsProcessingInstructions(
+            boolean consumeXmlDocType,
+            boolean consumeXmlDeclaration,
+            boolean consumeProcessingInstructions,
+            boolean consumeCDataSections, 
+            boolean escapeInlineText,
+            boolean consumeXMLComments,
+            boolean swallowCDataContent,
+            boolean compressSpaces,
+            boolean html5Doctype)
+    {
         super();
         this.consumeXmlDocType = consumeXmlDocType;
         this.consumeXmlDeclaration = consumeXmlDeclaration;
@@ -162,7 +201,8 @@ public final class FaceletsProcessingIns
         this.consumeXMLComments = consumeXMLComments;
         this.swallowCDataContent = swallowCDataContent;
         this.compressSpaces = compressSpaces;
-    }
+        this.html5Doctype = html5Doctype;
+    }    
 
     public boolean isConsumeXmlDocType()
     {
@@ -207,4 +247,8 @@ public final class FaceletsProcessingIns
         return compressSpaces;
     }
 
+    public boolean isHtml5Doctype()
+    {
+        return html5Doctype;
+    }
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java?rev=1518447&r1=1518446&r2=1518447&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java Thu Aug 29 02:27:18 2013
@@ -228,6 +228,8 @@ public final class SAXCompiler extends C
         {
             if (this.inDocument && !unit.getFaceletsProcessingInstructions().isConsumeXmlDocType())
             {
+                this.unit.writeDoctype(name, publicId, systemId);
+                /*
                 StringBuffer sb = new StringBuffer(64);
                 sb.append("<!DOCTYPE ").append(name);
                 if (publicId != null)
@@ -244,6 +246,7 @@ public final class SAXCompiler extends C
                 }
                 sb.append(" >\n");
                 this.unit.writeInstruction(sb.toString());
+                */
             }
             this.inDocument = false;
         }

Copied: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/HTML5FaceletsProcessingTestCase.java (from r1509781, myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/XHTMLFaceletsProcessingTestCase.java)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/HTML5FaceletsProcessingTestCase.java?p2=myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/HTML5FaceletsProcessingTestCase.java&p1=myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/XHTMLFaceletsProcessingTestCase.java&r1=1509781&r2=1518447&rev=1518447&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/XHTMLFaceletsProcessingTestCase.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/HTML5FaceletsProcessingTestCase.java Thu Aug 29 02:27:18 2013
@@ -33,6 +33,8 @@ import javax.faces.component.html.HtmlPa
 import javax.faces.component.html.HtmlSelectOneMenu;
 
 import junit.framework.Assert;
+import org.apache.myfaces.config.RuntimeConfig;
+import org.apache.myfaces.config.impl.digester.elements.FaceletsProcessing;
 
 import org.apache.myfaces.renderkit.html.HtmlFormRenderer;
 import org.apache.myfaces.renderkit.html.HtmlGridRenderer;
@@ -42,7 +44,7 @@ import org.apache.myfaces.test.mock.Mock
 import org.apache.myfaces.view.facelets.FaceletTestCase;
 import org.junit.Test;
 
-public class XHTMLFaceletsProcessingTestCase extends FaceletTestCase {
+public class HTML5FaceletsProcessingTestCase extends FaceletTestCase {
 
     @Override
     protected void setupComponents() throws Exception
@@ -81,12 +83,13 @@ public class XHTMLFaceletsProcessingTest
     protected void setUpExternalContext() throws Exception
     {
         super.setUpExternalContext();
-        /*
-        FaceletsProcessing item = new FaceletsProcessing();
-        item.setFileExtension(".view.xml");
-        item.setProcessAs(FaceletsProcessing.PROCESS_AS_XML);
-        RuntimeConfig.getCurrentInstance(externalContext).addFaceletProcessingConfiguration(FaceletsProcessing.PROCESS_AS_XML, item);
-        */
+        
+        // In JSF 2.2 xhtml default is html5
+        /*FaceletsProcessing item = new FaceletsProcessing();
+        item.setFileExtension(".xhtml");
+        item.setProcessAs(FaceletsProcessing.PROCESS_AS_HTML5);
+        RuntimeConfig.getCurrentInstance(externalContext).addFaceletProcessingConfiguration(
+            FaceletsProcessing.PROCESS_AS_HTML5, item);*/
     }
 
     @Test
@@ -105,7 +108,7 @@ public class XHTMLFaceletsProcessingTest
         
         String resp = sw.toString();
         
-        Assert.assertTrue("Response contains DOCTYPE declaration", resp.contains("<!DOCTYPE"));
+        Assert.assertTrue("Response contains DOCTYPE declaration", resp.contains("<!DOCTYPE html>"));
         Assert.assertTrue("Response contains xml declaration", resp.contains("<?xml"));
         Assert.assertTrue("Response contains xml processing instructions", resp.contains("<?name"));
         Assert.assertTrue("Response contains cdata section", resp.contains("<![CDATA["));

Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/XHTMLFaceletsProcessingTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/XHTMLFaceletsProcessingTestCase.java?rev=1518447&r1=1518446&r2=1518447&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/XHTMLFaceletsProcessingTestCase.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/compiler/XHTMLFaceletsProcessingTestCase.java Thu Aug 29 02:27:18 2013
@@ -33,6 +33,8 @@ import javax.faces.component.html.HtmlPa
 import javax.faces.component.html.HtmlSelectOneMenu;
 
 import junit.framework.Assert;
+import org.apache.myfaces.config.RuntimeConfig;
+import org.apache.myfaces.config.impl.digester.elements.FaceletsProcessing;
 
 import org.apache.myfaces.renderkit.html.HtmlFormRenderer;
 import org.apache.myfaces.renderkit.html.HtmlGridRenderer;
@@ -81,12 +83,12 @@ public class XHTMLFaceletsProcessingTest
     protected void setUpExternalContext() throws Exception
     {
         super.setUpExternalContext();
-        /*
+
         FaceletsProcessing item = new FaceletsProcessing();
-        item.setFileExtension(".view.xml");
-        item.setProcessAs(FaceletsProcessing.PROCESS_AS_XML);
-        RuntimeConfig.getCurrentInstance(externalContext).addFaceletProcessingConfiguration(FaceletsProcessing.PROCESS_AS_XML, item);
-        */
+        item.setFileExtension(".xhtml");
+        item.setProcessAs(FaceletsProcessing.PROCESS_AS_XHTML);
+        RuntimeConfig.getCurrentInstance(externalContext).addFaceletProcessingConfiguration(
+            FaceletsProcessing.PROCESS_AS_XHTML, item);
     }
 
     @Test
@@ -106,6 +108,7 @@ public class XHTMLFaceletsProcessingTest
         String resp = sw.toString();
         
         Assert.assertTrue("Response contains DOCTYPE declaration", resp.contains("<!DOCTYPE"));
+        Assert.assertFalse("Response not contains DOCTYPE html declaration", resp.contains("<!DOCTYPE html>"));
         Assert.assertTrue("Response contains xml declaration", resp.contains("<?xml"));
         Assert.assertTrue("Response contains xml processing instructions", resp.contains("<?name"));
         Assert.assertTrue("Response contains cdata section", resp.contains("<![CDATA["));