incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awi...@apache.org
Subject svn commit: r490902 - in /incubator/adffaces/trunk/trinidad/trinidad-impl: pom.xml src/test/java/org/apache/myfaces/trinidadinternal/renderkit/TestResponseWriter.java
Date Fri, 29 Dec 2006 00:58:50 GMT
Author: awiner
Date: Thu Dec 28 16:58:49 2006
New Revision: 490902

URL: http://svn.apache.org/viewvc?view=rev&rev=490902
Log:
Add support to the renderkit test framework to fail on invalid IDs or use of block-level elements
inside of inline elements.  Trinidad currently fails - BADLY - on both accounts, so this is
turned off for now

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/pom.xml
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/TestResponseWriter.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/pom.xml?view=diff&rev=490902&r1=490901&r2=490902
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/pom.xml (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/pom.xml Thu Dec 28 16:58:49 2006
@@ -47,6 +47,18 @@
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <systemProperties>
+            <!-- Trinidad currently fails proper HTML ID validity,
+		 and rather badly - so turn that test off -->
+            <property>
+              <name>org.apache.myfaces.trinidad.TestIdValidity</name>
+              <value>false</value>
+            </property>
+            <!-- Trinidad currently puts a lot of block-elements inside
+		 of inline elements - so turn that test off too -->
+            <property>
+              <name>org.apache.myfaces.trinidad.TestBlockElementNesting</name>
+              <value>false</value>
+            </property>
             <property>
               <name>trinidad.renderkit.fulltests</name>
               <value>lenient</value>

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/TestResponseWriter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/TestResponseWriter.java?view=diff&rev=490902&r1=490901&r2=490902
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/TestResponseWriter.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/renderkit/TestResponseWriter.java
Thu Dec 28 16:58:49 2006
@@ -19,9 +19,14 @@
 import java.io.Writer;
 import java.io.UnsupportedEncodingException;
 
+import java.util.regex.Pattern;
+
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeMap;
 
 
@@ -68,14 +73,15 @@
       throw new NullPointerException();
 
     _out = out;
-    // -= Simon Lessard =-
-    // TODO: Never read locally as of 2006-08-09. Remove for good if no problem 
-    //       show up.
-    //_contentType = contentType;
     _encoding = encoding;
     _test = test;
     _result = result;
     CaboHttpUtils.validateEncoding(encoding);
+
+    _onlyValidIds = "true".equals(
+       System.getProperty("org.apache.myfaces.trinidad.TestIdValidity"));
+    _testBlockLevel = "true".equals(
+       System.getProperty("org.apache.myfaces.trinidad.TestBlockElementNesting"));
   }
 
   @Override
@@ -177,6 +183,7 @@
                     element);
       }
 
+      _elementStack.removeFirst();
       Writer out = _out;
 
       // always turn escaping back on once an element ends
@@ -214,6 +221,12 @@
 
     }
 
+    if (_onlyValidIds && "id".equals(name))
+    {
+      if (!_VALID_ID_PATTERN.matcher(value.toString()).matches())
+        _LOG.severe("ID \"" + value + "\" is not a valid ID.");
+    }
+
     if (_attributes.containsKey(name))
     {
       AssertionFailedError failure = new AssertionFailedError(
@@ -407,6 +420,17 @@
     // note that we started a non-skipped element
     _pushOutputtedElement(name);
 
+    if (_testBlockLevel &&
+        !_elementStack.isEmpty() &&
+        _BLOCK_LEVEL_ELEMENTS.contains(name) &&
+        _isInline(_elementStack.getFirst()))
+    {
+      _LOG.severe("The block level element " + name + " may not be used " +
+                  "inside of the inline element " + _elementStack.getFirst());
+    }
+
+    _elementStack.addFirst(name);
+
     int depth = _depth++;
     _writeIndent(depth);
 
@@ -660,6 +684,14 @@
 
   }
 
+  static private boolean _isInline(String name)
+  {
+    return (!_BLOCK_LEVEL_ELEMENTS.contains(name) &&
+            !_NEUTRAL_ELEMENTS.contains(name));
+  }
+
+  private boolean     _testBlockLevel;
+  private boolean     _onlyValidIds;
 
   private boolean     _closeStart;
   private boolean     _dontEscape;
@@ -667,13 +699,10 @@
   private boolean _isCachedImage;
   private Map<String, Object> _attributes = new TreeMap<String, Object>();
   private Map<String, Object> _uriAttributes = new TreeMap<String, Object>();
+  private LinkedList<String> _elementStack = new LinkedList<String>();
   private int     _depth;
 
   private Writer       _out;
-  // -= Simon Lessard =-
-  // TODO: Never read locally as of 2006-08-09. Remove for good if no problem 
-  //       show up.
-  //private String       _contentType;
   private String       _encoding;
 
   // holds an element that will only be started if it has attributes
@@ -687,6 +716,9 @@
   private final ArrayList<String> _skippedElements = new ArrayList<String>(20);
 
 
+  private static final Pattern _VALID_ID_PATTERN  =
+    Pattern.compile("[A-Za-z][A-Za-z0-9:_.-]*");
+
   private static final Class<?> _CHAR_ARRAY_CLASS = (new char[0]).getClass();
   private static final Class<Boolean> _BOOLEAN_CLASS = Boolean.class;
   private static final Class<Integer> _INTEGER_CLASS = Integer.class;
@@ -707,6 +739,57 @@
     }
   }
 
+  static private final Set<String> _BLOCK_LEVEL_ELEMENTS =
+    new HashSet<String>();
+  static private final Set<String> _NEUTRAL_ELEMENTS =
+    new HashSet<String>();
+  {
+    _BLOCK_LEVEL_ELEMENTS.add("address");
+    _BLOCK_LEVEL_ELEMENTS.add("blockquote");
+    _BLOCK_LEVEL_ELEMENTS.add("center");
+    _BLOCK_LEVEL_ELEMENTS.add("dir");
+    _BLOCK_LEVEL_ELEMENTS.add("div");
+    _BLOCK_LEVEL_ELEMENTS.add("dl");
+    _BLOCK_LEVEL_ELEMENTS.add("fieldset");
+    _BLOCK_LEVEL_ELEMENTS.add("form");
+    _BLOCK_LEVEL_ELEMENTS.add("h1");
+    _BLOCK_LEVEL_ELEMENTS.add("h2");
+    _BLOCK_LEVEL_ELEMENTS.add("h3");
+    _BLOCK_LEVEL_ELEMENTS.add("h4");
+    _BLOCK_LEVEL_ELEMENTS.add("h5");
+    _BLOCK_LEVEL_ELEMENTS.add("h6");
+    _BLOCK_LEVEL_ELEMENTS.add("hr");
+    _BLOCK_LEVEL_ELEMENTS.add("isindex");
+    _BLOCK_LEVEL_ELEMENTS.add("menu");
+    _BLOCK_LEVEL_ELEMENTS.add("noframes");
+    _BLOCK_LEVEL_ELEMENTS.add("noscript");
+    _BLOCK_LEVEL_ELEMENTS.add("ol");
+    _BLOCK_LEVEL_ELEMENTS.add("p");
+    _BLOCK_LEVEL_ELEMENTS.add("pre");
+    _BLOCK_LEVEL_ELEMENTS.add("table");
+    _BLOCK_LEVEL_ELEMENTS.add("ul");
+    // These technically aren't block-level, but are allowed
+    // to contain block-level elements
+    _BLOCK_LEVEL_ELEMENTS.add("dd");
+    _BLOCK_LEVEL_ELEMENTS.add("dt");
+    _BLOCK_LEVEL_ELEMENTS.add("frameset");
+    _BLOCK_LEVEL_ELEMENTS.add("li");
+    _BLOCK_LEVEL_ELEMENTS.add("tbody");
+    _BLOCK_LEVEL_ELEMENTS.add("tfoot");
+    _BLOCK_LEVEL_ELEMENTS.add("th");
+    _BLOCK_LEVEL_ELEMENTS.add("thead");
+    _BLOCK_LEVEL_ELEMENTS.add("tr");
+    _BLOCK_LEVEL_ELEMENTS.add("td");
+    _NEUTRAL_ELEMENTS.add("applet");
+    _NEUTRAL_ELEMENTS.add("body");
+    _NEUTRAL_ELEMENTS.add("button");
+    _NEUTRAL_ELEMENTS.add("del");
+    _NEUTRAL_ELEMENTS.add("iframe");
+    _NEUTRAL_ELEMENTS.add("ins");
+    _NEUTRAL_ELEMENTS.add("map");
+    _NEUTRAL_ELEMENTS.add("object");
+    _NEUTRAL_ELEMENTS.add("script");
+  }
   static private final TrinidadLogger _LOG =
     TrinidadLogger.createTrinidadLogger(TestResponseWriter.class);
 }



Mime
View raw message