You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2015/10/14 11:06:28 UTC

svn commit: r1708565 - in /myfaces/tobago/branches/tobago-3.0.x/tobago-core/src: main/java/org/apache/myfaces/tobago/internal/webapp/ main/java/org/apache/myfaces/tobago/renderkit/html/ test/java/org/apache/myfaces/tobago/renderkit/html/

Author: lofwyr
Date: Wed Oct 14 09:06:27 2015
New Revision: 1708565

URL: http://svn.apache.org/viewvc?rev=1708565&view=rev
Log:
TOBAGO-1500: Complete the enum list of HtmlElement and add void support

Added:
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/html/HtmlElementsUnitTest.java
Modified:
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/JsonResponseWriter.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseWriterBase.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/JsonResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/JsonResponseWriter.java?rev=1708565&r1=1708564&r2=1708565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/JsonResponseWriter.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/JsonResponseWriter.java Wed Oct 14 09:06:27 2015
@@ -113,7 +113,7 @@ public class JsonResponseWriter extends
 
   @Override
   protected void endElementInternal(final Writer writer, final HtmlElements name) throws IOException {
-    if (EMPTY_TAG.contains(name)) {
+    if (name.isVoid()) {
         writer.write(">");
     } else {
       if (isStartStillOpen()) {

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseWriterBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseWriterBase.java?rev=1708565&r1=1708564&r2=1708565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseWriterBase.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/TobagoResponseWriterBase.java Wed Oct 14 09:06:27 2015
@@ -30,33 +30,12 @@ import javax.faces.component.UIComponent
 import java.io.IOException;
 import java.io.Writer;
 import java.net.URI;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
 
 public abstract class TobagoResponseWriterBase extends TobagoResponseWriter {
 
   private static final Logger LOG = LoggerFactory.getLogger(TobagoResponseWriterBase.class);
 
-  protected static final Set<HtmlElements> EMPTY_TAG = new HashSet<HtmlElements>(Arrays.asList(
-      HtmlElements.BR,
-      HtmlElements.AREA,
-      HtmlElements.LINK,
-      HtmlElements.IMG,
-      HtmlElements.PARAM,
-      HtmlElements.HR,
-      HtmlElements.INPUT,
-      HtmlElements.COL,
-      HtmlElements.BASE,
-      HtmlElements.META));
-
-  /** @deprecated Since Tobago 1.5.3 */
-  @Deprecated
-  public static final String XML_VERSION_1_0_ENCODING_UTF_8 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
-
-  /** @deprecated Since Tobago 1.5.3 */
-  @Deprecated
-  public static final int XML_VERSION_1_0_ENCODING_UTF_8_LENGTH = XML_VERSION_1_0_ENCODING_UTF_8.length();
+  protected static final String XML_VERSION_1_0_ENCODING_UTF_8 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 
   protected static final char[] XML_VERSION_1_0_ENCODING_UTF_8_CHARS = XML_VERSION_1_0_ENCODING_UTF_8.toCharArray();
 
@@ -284,7 +263,7 @@ public abstract class TobagoResponseWrit
   }
 
   protected void endElementInternal(final Writer writer, final HtmlElements name) throws IOException {
-    if (EMPTY_TAG.contains(name)) {
+    if (name.isVoid()) {
       closeEmptyTag();
     } else {
       if (startStillOpen) {

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java?rev=1708565&r1=1708564&r2=1708565&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java Wed Oct 14 09:06:27 2015
@@ -22,16 +22,40 @@ package org.apache.myfaces.tobago.render
 public enum HtmlElements {
 
   A("a"),
-  AREA("area"),
+  ABBR("abbr"),
+  ADDRESS("address"),
+  AREA("area", true),
+  ARTICLE("article"),
+  ASIDE("aside"),
+  AUDIO("audio"),
   B("b"),
-  BASE("base"),
+  BASE("base", true),
+  BDI("bdi"),
+  BDO("bdo"),
+  BLOCKQUOTE("blockquote"),
   BODY("body"),
-  BR("br"),
+  BR("br", true),
   BUTTON("button"),
-  COL("col"),
+  CANVAS("canvas"),
+  CAPTION("caption"),
+  CITE("cite"),
+  CODE("code"),
+  COL("col", true),
   COLGROUP("colgroup"),
+  COMMAND("command", true),
+  DATALIST("datalist"),
+  DD("dd"),
+  DEL("del"),
+  DETAILS("details"),
+  DFN("dfn"),
   DIV("div"),
+  DL("dl"),
+  DT("dt"),
+  EM("em"),
+  EMBED("embed", true),
   FIELDSET("fieldset"),
+  FIGCAPTION("figcaption"),
+  FIGURE("figure"),
   FOOTER("footer"),
   FORM("form"),
   H1("h1"),
@@ -42,46 +66,91 @@ public enum HtmlElements {
   H6("h6"),
   HEAD("head"),
   HEADER("header"),
-  HR("hr"),
+  HGROUP("hgroup"),
+  HR("hr", true),
   HTML("html"),
+  I("i"),
   IFRAME("iframe"),
-  IMG("img"),
-  INPUT("input"),
+  IMG("img", true),
+  INPUT("input", true),
+  INS("ins"),
+  KBD("kbd"),
+  KEYGEN("keygen", true),
   LABEL("label"),
   LEGEND("legend"),
   LI("li"),
-  LINK("link"),
-  META("meta"),
+  LINK("link", true),
+  MAP("map"),
+  MARK("mark"),
+  MENU("menu"),
+  META("meta", true),
+  METER("meter"),
   NAV("nav"),
   NOSCRIPT("noscript"),
+  OBJECT("object"),
   OL("ol"),
   OPTGROUP("optgroup"),
   OPTION("option"),
   P("p"),
-  PARAM("param"),
+  PARAM("param", true),
+  PRE("pre"),
+  PRODRESS("prodress"),
+  Q("q"),
+  RP("rp"),
+  RT("rt"),
+  RUBY("ruby"),
+  S("s"),
+  SAMP("samp"),
   SCRIPT("script"),
+  SECTION("section"),
   SELECT("select"),
+  SMALL("small"),
+  SOURCE("source", true),
   SPAN("span"),
+  STRONG("strong"),
   STYLE("style"),
+  SUB("sub"),
+  SUMMARY("summary"),
+  SUP("sup"),
   TABLE("table"),
   TBODY("tbody"),
   TD("td"),
   TEXTAREA("textarea"),
+  TFOOT("tfoot"),
   TH("th"),
+  THEAD("thead"),
+  TIME("time"),
   TITLE("title"),
   TR("tr"),
-
-  @Deprecated
+  TRACK("track", true),
   U("u"),
-  UL("ul");
+  UL("ul"),
+  VAR("var"),
+  VIDEO("video"),
+  WBR("wbr", true);
 
   private final String value;
+  private final boolean voidElement;
 
   HtmlElements(String value) {
+    this(value, false);
+  }
+
+  HtmlElements(String value, boolean voidElement) {
     this.value = value;
+    this.voidElement = voidElement;
   }
 
   public String getValue() {
     return value;
   }
+
+  /**
+   * A void HTML elements is an element whose content model never allows it to have contents under any circumstances.
+   * See <a href="http://www.w3.org/TR/html-markup/syntax.html#void-element">
+   *   http://www.w3.org/TR/html-markup/syntax.html#void-element</a>
+   */
+  public boolean isVoid() {
+    return voidElement;
+  }
 }

Added: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/html/HtmlElementsUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/html/HtmlElementsUnitTest.java?rev=1708565&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/html/HtmlElementsUnitTest.java (added)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/renderkit/html/HtmlElementsUnitTest.java Wed Oct 14 09:06:27 2015
@@ -0,0 +1,58 @@
+/*
+ * 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.tobago.renderkit.html;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.List;
+
+public class HtmlElementsUnitTest {
+
+  @Test
+  public void testNames() throws IllegalAccessException {
+    for (final Field field : HtmlElements.class.getFields()) {
+
+      final HtmlElements element = (HtmlElements) field.get(null);
+      final String value = element.getValue();
+      Assert.assertEquals("Check to lower: '" + element + "'", value, element.name().toLowerCase());
+      Assert.assertEquals("Check to upper: '" + element + "'", value.toUpperCase(), element.name());
+    }
+  }
+
+  @Test
+  public void testVoid() throws IllegalAccessException {
+
+    // list from spec.
+    List<String> voids = Arrays.asList(
+        "area", "base", "br", "col", "command", "embed",
+        "hr", "img", "input", "keygen", "link", "meta",
+        "param", "source", "track", "wbr");
+
+    for (final Field field : HtmlElements.class.getFields()) {
+      final HtmlElements element = (HtmlElements) field.get(null);
+
+      Assert.assertEquals("Check void: '" + element + "'", voids.contains(element.getValue()),  element.isVoid());
+    }
+
+  }
+}