[dna-commits] DNA SVN: r787 - in trunk/dna-graph/src: test/java/org/jboss/dna/graph/property/basic and 1 other directory.
dna-commits at lists.jboss.org
dna-commits at lists.jboss.org
Mon Mar 23 16:41:31 EDT 2009
Author: rhauch
Date: 2009-03-23 16:41:31 -0400 (Mon, 23 Mar 2009)
New Revision: 787
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicName.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicNameTest.java
Log:
DNA-333 BasicName.getString Doesn't Use Provided TextEncoder When the Name Has No Namespace
Applied the patch that corrects BasicName to use the encoder if suppliedto getString(), specifically when the name contains no namespace (e.g., "*"). The patch also changes the behavior of BasicName.getString(TextEncoder) to return the encoded local name ONLY when called. It used to return "{}" + localName.
Verified that all tests pass.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicName.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicName.java 2009-03-23 19:31:51 UTC (rev 786)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/basic/BasicName.java 2009-03-23 20:41:31 UTC (rev 787)
@@ -91,7 +91,11 @@
if (this.getLocalName().equals(Path.PARENT)) return Path.PARENT;
}
if (encoder == null) encoder = Path.DEFAULT_ENCODER;
- return "{" + encoder.encode(this.namespaceUri) + "}" + encoder.encode(this.localName);
+
+ if (namespaceUri.length() > 0) {
+ return "{" + encoder.encode(this.namespaceUri) + "}" + encoder.encode(this.localName);
+ }
+ return encoder.encode(this.localName);
}
/**
@@ -117,7 +121,7 @@
if (prefix != null && prefix.length() != 0) {
return encoder.encode(prefix) + ":" + encoder.encode(this.localName);
}
- return this.localName;
+ return encoder.encode(this.localName);
}
/**
@@ -148,7 +152,7 @@
String delim = delimiterEncoder != null ? delimiterEncoder.encode(":") : ":";
return encoder.encode(prefix) + delim + encoder.encode(this.localName);
}
- return this.localName;
+ return encoder.encode(this.localName);
}
/**
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicNameTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicNameTest.java 2009-03-23 19:31:51 UTC (rev 786)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/property/basic/BasicNameTest.java 2009-03-23 20:41:31 UTC (rev 787)
@@ -24,6 +24,7 @@
package org.jboss.dna.graph.property.basic;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import org.jboss.dna.common.text.Jsr283Encoder;
@@ -180,7 +181,7 @@
validLocalName = "some:name:with:colons";
name = new BasicName(validNamespaceUri, validLocalName);
result = name.getString(namespaceRegistry, encoder);
- assertThat(result, is("some:name:with:colons"));
+ assertThat(result, is(encoder.encode(validLocalName)));
}
@Test
@@ -191,4 +192,21 @@
assertThat(name.getString(null, encoder, delimiterEncoder), is("\\{" + encoder.encode(DnaLexicon.Namespace.URI)
+ "\\}some\uf03aname\uf03awith\uf03acolons"));
}
+
+ @Test
+ public void shouldEncodeWhenNoNamespace() {
+ String nameForEncoding = "test name";
+ String encodedNameForEncoding = encoder.encode(nameForEncoding);
+ // Make sure that we're not testing a trivial encoding
+ assertThat(encodedNameForEncoding, not(nameForEncoding));
+
+ name = new BasicName(null, nameForEncoding);
+
+ String result = name.getString(namespaceRegistry, encoder);
+ assertThat(result, is(encodedNameForEncoding));
+
+ result = name.getString(encoder);
+ assertThat(result, is(encodedNameForEncoding));
+ }
+
}
More information about the dna-commits
mailing list