You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2012/12/22 03:01:44 UTC
git commit: TAP5-2039: Element.attribute() should treat "class"
specially, appending the new value to the old
Updated Branches:
refs/heads/master 87bda99a1 -> cf19bd9b1
TAP5-2039: Element.attribute() should treat "class" specially, appending the new value to the old
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/cf19bd9b
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/cf19bd9b
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/cf19bd9b
Branch: refs/heads/master
Commit: cf19bd9b11a807e1c885256906c280a68812f12a
Parents: 87bda99
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Fri Dec 21 18:01:35 2012 -0800
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Fri Dec 21 18:01:35 2012 -0800
----------------------------------------------------------------------
.../tapestry5/corelib/components/FormInjector.java | 4 +-
.../apache/tapestry5/corelib/components/Tree.java | 4 +-
.../java/org/apache/tapestry5/dom/Element.java | 95 ++++++---------
.../internal/renderers/LocationRenderer.java | 17 ++-
4 files changed, 52 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf19bd9b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
index 1330be7..7e53d9d 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -131,7 +131,7 @@ public class FormInjector implements ClientElement
// Add the class name to the rendered client element. This allows nested elements to locate
// the containing FormInjector element.
- clientElement.addClassName("t-forminjector");
+ clientElement.attribute("class", "t-forminjector");
}
/**
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf19bd9b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Tree.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Tree.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Tree.java
index b6ada1f..d8875fb 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Tree.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Tree.java
@@ -138,7 +138,7 @@ public class Tree
@Override
public void render(MarkupWriter writer, RenderQueue queue)
{
- writer.getElement().addClassName("t-selected-leaf-node");
+ writer.getElement().attribute("class", "t-selected-leaf-node");
}
};
@@ -176,7 +176,7 @@ public class Tree
if (isLeaf)
{
- writer.getElement().addClassName("t-leaf-node");
+ writer.getElement().attribute("class", "t-leaf-node");
}
Element e = writer.element("span", "class", "t-tree-icon");
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf19bd9b/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java b/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
index af3c4a3..75dc68a 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
@@ -90,6 +90,8 @@ public final class Element extends Node
/**
* Adds an attribute to the element, but only if the attribute name does not already exist.
+ * The "class" attribute is treated specially: the new value is appended, after a space, to the
+ * existing value.
*
* @param name
* the name of the attribute to add
@@ -104,9 +106,11 @@ public final class Element extends Node
/**
* Adds a namespaced attribute to the element, but only if the attribute name does not already exist.
+ * The "class" attribute of the default namespace is treated specially: the new value
+ * is appended, after a space, to the existing value.
*
* @param namespace
- * the namespace to contain the attribute, or null
+ * the namespace to contain the attribute, or null for the default namespace
* @param name
* the name of the attribute to add
* @param value
@@ -116,6 +120,7 @@ public final class Element extends Node
public Element attribute(String namespace, String name, String value)
{
assert InternalUtils.isNonBlank(name);
+
updateAttribute(namespace, name, value, false);
return this;
@@ -124,7 +129,9 @@ public final class Element extends Node
private void updateAttribute(String namespace, String name, String value, boolean force)
{
if (!force && value == null)
+ {
return;
+ }
Attribute prior = null;
Attribute cursor = firstAttribute;
@@ -133,21 +140,35 @@ public final class Element extends Node
{
if (cursor.matches(namespace, name))
{
- if (!force)
+ boolean isClass = namespace == null && name.equals("class");
+
+ if (!(force || isClass))
+ {
return;
+ }
if (value != null)
{
- cursor.value = value;
+ if (!force && isClass)
+ {
+ cursor.value += (" " + value);
+ } else
+ {
+ cursor.value = value;
+ }
+
return;
}
// Remove this Attribute node from the linked list
if (prior == null)
+ {
firstAttribute = cursor.nextAttribute;
- else
+ } else
+ {
prior.nextAttribute = cursor.nextAttribute;
+ }
return;
}
@@ -156,12 +177,12 @@ public final class Element extends Node
cursor = cursor.nextAttribute;
}
- // Don't add a Attribute if the value is null.
-
- if (value == null)
- return;
+ // Don't add an Attribute if the value is null.
- firstAttribute = new Attribute(this, namespace, name, value, firstAttribute);
+ if (value != null)
+ {
+ firstAttribute = new Attribute(this, namespace, name, value, firstAttribute);
+ }
}
/**
@@ -199,7 +220,7 @@ public final class Element extends Node
/**
* 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.
+ * values (event for the "class" attribute). Overriding attribute's value to null will remove the attribute entirely.
* TAP5-708: don't use element namespace for attributes
*
* @param namespace
@@ -616,66 +637,20 @@ public final class Element extends Node
}
/**
- * Adds one or more CSS class names to the "class" attribute, using {@link #extendAttribute}. Note that CSS class
- * names are case insensitive on the client.
+ * Adds one or more CSS class names to the "class" attribute.
*
* @param classNames
* one or more CSS class names
* @return the element for further configuration
+ * @deprecated Deprecated in 5.4, as this is now special behavior for the "class" attribute.
*/
public Element addClassName(String... classNames)
{
- return extendAttribute("class", classNames);
- }
-
- /**
- * Adds one or more new values to an attribute; the attribute is considered to have multiple
- * value separated by spaces (such as the HTML {@code class} attribute). The new values are added
- * to the existing ones. Duplicates are removed (the comparison is, however, case sensitive). The order
- * of the individual words inside the attribute value may change.
- *
- * @param name
- * name of attribute to update
- * @param words
- * additional words to add to the attribute value; they should not contain any whitespace
- * @return the element for further configuration
- * @since 5.4
- */
- public Element extendAttribute(String name, String... words)
- {
- Set<String> values = CollectionFactory.newSet();
-
- String attributeValue = getAttribute(name);
-
- String[] existing = attributeValue == null ? EMPTY_ARRAY : SPACES.split(attributeValue);
-
- int length = 0;
-
- for (String word : existing)
+ for (String name : classNames)
{
- length += word.length() + 1;
-
- values.add(word);
- }
-
- for (String word : words)
- {
- length += word.length() + 1;
-
- values.add(word);
+ attribute("class", name);
}
- StringBuilder builder = new StringBuilder(length);
- String sep = "";
-
- for (String word : values)
- {
- builder.append(sep).append(word);
- sep = " ";
- }
-
- updateAttribute(null, name, builder.toString(), true);
-
return this;
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cf19bd9b/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/LocationRenderer.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/LocationRenderer.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/LocationRenderer.java
index 9fb649c..5d260ba 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/LocationRenderer.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/LocationRenderer.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2012 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -87,16 +87,25 @@ public class LocationRenderer implements ObjectRenderer<Location>
writer.element("td", "class", "t-location-line");
- if (line == current) writer.getElement().addClassName("t-location-current");
+ if (line == current)
+ {
+ writer.getElement().attribute("class", "t-location-current");
+ }
writer.write(Integer.toString(current));
writer.end();
Element td = writer.element("td", "class", "t-location-content");
- if (line == current) td.addClassName("t-location-current");
+ if (line == current)
+ {
+ td.attribute("class", "t-location-current");
+ }
- if (start == current) td.addClassName("t-location-content-first");
+ if (start == current)
+ {
+ td.attribute("class", "t-location-content-first");
+ }
writer.write(input);
writer.end();