Author: joshcanfield
Date: Sun Oct 17 22:19:36 2010
New Revision: 1023590

URL: http://svn.apache.org/viewvc?rev=1023590&view=rev
Log:
TAP5-708, TAP5-804 and TAP5-709.
Added forceAttributesNS, modified forceAttributes to use null namespace. 
Attributes belong in the global namespace, not the namespace of their 
containing element.

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java?rev=1023590&r1=1023589&r2=1023590&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
 Sun Oct 17 22:19:36 2010
@@ -191,9 +191,27 @@ public final class Element extends Node
     /**
      * Forces changes to a number of attributes. The new attributes 
<em>overwrite</em> previous values. Overriding an
      * attribute's value to null will remove the attribute entirely.
+     *
+     * @param namesAndValues alternating attribute names and attribute values
+     * @return this element
      */
     public Element forceAttributes(String... namesAndValues)
     {
+        return forceAttributesNS(null, namesAndValues);
+    }
+
+    /**
+     * Forces changes to a number of attributes in the global namespace. The 
new attributes <em>overwrite</em> previous
+     * values. Overriding attribute's value to null will remove the attribute 
entirely.
+     * TAP5-708: don't use element namespace for attributes
+     *
+     * @param namespace the namespace or null
+     * @param namesAndValues alternating attribute name and value
+     * @return this element
+     *
+     */
+    public Element forceAttributesNS(String namespace, String... 
namesAndValues)
+    {
         int i = 0;
 
         while (i < namesAndValues.length)

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java?rev=1023590&r1=1023589&r2=1023590&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java
 Sun Oct 17 22:19:36 2010
@@ -378,6 +378,27 @@ public class DOMTest extends InternalBas
         assertEquals(root.toString(), "<fred hi=\"bit\"/>");
     }
 
+    /**
+     * TAP5-708
+     */
+    @Test
+    public void namespace_element_force_attributes_overrides_existing() 
+    {
+        Document d = new Document(new XMLMarkupModel());
+
+        Element root = d.newRootElement("fredns", "fred");
+
+        root.attributes("hi", "ho", "gnip", "gnop");
+
+        assertEquals(root.toString(), "<fred gnip=\"gnop\" hi=\"ho\" 
xmlns=\"fredns\"/>");
+
+        root.forceAttributes("hi", "bit", "gnip", null);
+
+        assertEquals(root.toString(), "<fred hi=\"bit\" xmlns=\"fredns\"/>");
+    }
+
+
+
     @Test
     public void raw_output()
     {
@@ -462,6 +483,25 @@ public class DOMTest extends InternalBas
         assertEquals(root.toString(), "<div class=\"fred barney wilma\"/>");
     }
 
+    /**
+     * TAP5-804
+     */
+    @Test
+    public void namespace_add_class_name()
+    {
+        Document document = new Document(new DefaultMarkupModel());
+
+        Element element = document.newRootElement("fredns", "e");
+
+        element.attribute("class", "a");
+
+        assertEquals(element.toString(), "<e class=\"a\" 
xmlns=\"fredns\"></e>");
+
+        element.addClassName("b");
+
+        assertEquals(element.toString(), "<e class=\"a b\" 
xmlns=\"fredns\"></e>");
+    }
+
     @Test
     public void cdata_in_HTML_document()
     {


Reply via email to