You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2012/05/11 10:15:05 UTC
svn commit: r1337053 - in /pivot/trunk:
core/src/org/apache/pivot/xml/Element.java
core/test/org/apache/pivot/xml/test/XMLSerializerTest.java
demos/src/org/apache/pivot/demos/xml/XMLViewer.java
Author: smartini
Date: Fri May 11 08:15:05 2012
New Revision: 1337053
URL: http://svn.apache.org/viewvc?rev=1337053&view=rev
Log:
PIVOT-855, the fix.
Note that some public methods are moved/changed here (for the fix).
Modified:
pivot/trunk/core/src/org/apache/pivot/xml/Element.java
pivot/trunk/core/test/org/apache/pivot/xml/test/XMLSerializerTest.java
pivot/trunk/demos/src/org/apache/pivot/demos/xml/XMLViewer.java
Modified: pivot/trunk/core/src/org/apache/pivot/xml/Element.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/xml/Element.java?rev=1337053&r1=1337052&r2=1337053&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/xml/Element.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/xml/Element.java Fri May 11 08:15:05 2012
@@ -31,7 +31,7 @@ import org.apache.pivot.util.ListenerLis
/**
* Node class representing an XML element.
*/
-public class Element extends Node implements List<Node>, Dictionary<String, String> {
+public class Element extends Node implements List<Node> {
/**
* Class representing an XML attribute.
*/
@@ -453,12 +453,108 @@ public class Element extends Node implem
}
}
+ /**
+
+ * Dictionary representing the attributes declared by this element.
+ */
+ public class ElementDictionary implements Dictionary<String, String> {
+ private ElementDictionary() {
+ }
+
+ /**
+ * Returns an attribute value.
+ *
+ * @param attributeName
+ *
+ * @return
+ * The value associated with the given attribute, or <tt>null</tt>
+ */
+ @Override
+ public String get(String attributeName) {
+ Attribute attribute = attributeMap.get(attributeName);
+ return (attribute == null) ? null : attribute.getValue();
+ }
+
+ /**
+ * Sets an attribute value.
+ *
+ * @param attributeName
+ * @param value
+ *
+ * @return
+ * The value previously associated with the given attribute, or <tt>null</tt>
+ * if the attribute did not previously exist.
+ */
+ @Override
+ public String put(String attributeName, String value) {
+ String previousValue;
+
+ Attribute attribute = attributeMap.get(attributeName);
+ if (attribute == null) {
+ previousValue = null;
+
+ String namespacePrefix;
+ String localName;
+ int i = attributeName.indexOf(':');
+ if (i == -1) {
+ namespacePrefix = null;
+ localName = attributeName;
+ } else {
+ namespacePrefix = attributeName.substring(0, i);
+ localName = attributeName.substring(i + 1);
+ }
+
+ attributeSequence.add(new Attribute(namespacePrefix, localName, value));
+ } else {
+ previousValue = attribute.getValue();
+ attribute.setValue(value);
+ }
+
+ return previousValue;
+ }
+
+ /**
+ * Removes an attribute.
+ *
+ * @param attributeName
+ *
+ * @return
+ * The value previously associated with the given attribute.
+ */
+ @Override
+ public String remove(String attributeName) {
+ Attribute attribute = attributeMap.get(attributeName);
+ if (attribute != null) {
+ attributeSequence.remove(attribute);
+ }
+
+ return (attribute == null) ? null : attribute.getValue();
+ }
+
+ /**
+ * Tests for the existence of an attribute.
+ *
+ * @param attributeName
+ *
+ * @return
+ * <tt>true</tt> if this element defines the given attribute; <tt>false<tt>,
+ * otherwise.
+ */
+ @Override
+ public boolean containsKey(String attributeName) {
+ return attributeMap.containsKey(attributeName);
+ }
+
+ }
+
+
private String namespacePrefix;
private String localName;
private String defaultNamespaceURI = null;
private HashMap<String, String> namespaces = new HashMap<String, String>();
private NamespaceDictionary namespaceDictionary = new NamespaceDictionary();
+ private ElementDictionary elementDictionary = new ElementDictionary();
private ArrayList<Attribute> attributes = new ArrayList<Attribute>();
private AttributeSequence attributeSequence = new AttributeSequence();
@@ -580,6 +676,13 @@ public class Element extends Node implem
}
/**
+ * Returns the element's element dictionary.
+ */
+ public ElementDictionary getElementDictionary() {
+ return elementDictionary;
+ }
+
+ /**
* Returns the element's attribute dictionary.
*/
public AttributeSequence getAttributes() {
@@ -744,85 +847,6 @@ public class Element extends Node implem
}
/**
- * Returns an attribute value.
- */
- @Override
- public String get(String attributeName) {
- Attribute attribute = attributeMap.get(attributeName);
- return (attribute == null) ? null : attribute.getValue();
- }
-
- /**
- * Sets an attribute value.
- *
- * @param attributeName
- * @param value
- *
- * @return
- * The value previously associated with the given attribute, or <tt>null</tt>
- * if the attribute did not previously exist.
- */
- @Override
- public String put(String attributeName, String value) {
- String previousValue;
-
- Attribute attribute = attributeMap.get(attributeName);
- if (attribute == null) {
- previousValue = null;
-
- String namespacePrefix;
- String localName;
- int i = attributeName.indexOf(':');
- if (i == -1) {
- namespacePrefix = null;
- localName = attributeName;
- } else {
- namespacePrefix = attributeName.substring(0, i);
- localName = attributeName.substring(i + 1);
- }
-
- attributeSequence.add(new Attribute(namespacePrefix, localName, value));
- } else {
- previousValue = attribute.getValue();
- attribute.setValue(value);
- }
-
- return previousValue;
- }
-
- /**
- * Removes an attribute.
- *
- * @param attributeName
- *
- * @return
- * The value previously associated with the given attribute.
- */
- @Override
- public String remove(String attributeName) {
- Attribute attribute = attributeMap.get(attributeName);
- if (attribute != null) {
- attributeSequence.remove(attribute);
- }
-
- return (attribute == null) ? null : attribute.getValue();
- }
-
- /**
- * Tests for the existence of an attribute.
- *
- * @param attributeName
- *
- * @return
- * <tt>true</tt> if this element defines the given attribute; <tt>false<tt>,
- * otherwise.
- */
- @Override
- public boolean containsKey(String attributeName) {
- return attributeMap.containsKey(attributeName);
- }
-
- /**
* Determines if this element defines any attributes.
*
* @return
Modified: pivot/trunk/core/test/org/apache/pivot/xml/test/XMLSerializerTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/xml/test/XMLSerializerTest.java?rev=1337053&r1=1337052&r2=1337053&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/xml/test/XMLSerializerTest.java (original)
+++ pivot/trunk/core/test/org/apache/pivot/xml/test/XMLSerializerTest.java Fri May 11 08:15:05 2012
@@ -42,15 +42,15 @@ public class XMLSerializerTest {
Element a = XML.getElement(root, "a");
assertEquals(a.getName(), "a");
- assertEquals(a.get("id"), "x");
+ assertEquals(a.getElementDictionary().get("id"), "x");
Element b = XML.getElement(root, "a/b");
assertEquals(b.getName(), "b");
- assertEquals(b.get("id"), "y");
+ assertEquals(b.getElementDictionary().get("id"), "y");
b = XML.getElement(a, "b");
assertEquals(b.getName(), "b");
- assertEquals(b.get("id"), "y");
+ assertEquals(b.getElementDictionary().get("id"), "y");
List<Element> cs = XML.getElements(root, "a/b", "c");
assertEquals(cs.getLength(), 1);
Modified: pivot/trunk/demos/src/org/apache/pivot/demos/xml/XMLViewer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/xml/XMLViewer.java?rev=1337053&r1=1337052&r2=1337053&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/xml/XMLViewer.java (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/xml/XMLViewer.java Fri May 11 08:15:05 2012
@@ -170,7 +170,9 @@ public class XMLViewer implements Applic
public void updateProperties() {
Node node = (Node)treeView.getSelectedNode();
- if (node instanceof TextNode) {
+ if (node == null) {
+ // no selection, but it's ok
+ } else if (node instanceof TextNode) {
TextNode textNode = (TextNode)node;
textArea.setText(textNode.getText());
propertiesCardPane.setSelectedIndex(1);
@@ -208,7 +210,7 @@ public class XMLViewer implements Applic
String attributeName = attribute.getName();
row.put("name", attributeName);
- row.put("value", element.get(attributeName));
+ row.put("value", element.getElementDictionary().get(attributeName));
attributesTableData.add(row);
}