Author: chris.laprun(a)jboss.com
Date: 2008-03-18 17:47:59 -0400 (Tue, 18 Mar 2008)
New Revision: 10316
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/metadata/portlet/MarkupAttribute.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/MarkupTestCase.java
Log:
- Fixed incorrect toString version for MarkupAttribute and added related test case.
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/metadata/portlet/MarkupAttribute.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/metadata/portlet/MarkupAttribute.java 2008-03-18
20:54:51 UTC (rev 10315)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/metadata/portlet/MarkupAttribute.java 2008-03-18
21:47:59 UTC (rev 10316)
@@ -96,33 +96,25 @@
public String getEncodedValue()
{
StringWriter tmp = new StringWriter(32);
- type.encode(getValue(), tmp);
+ encodeValueTo(null, tmp);
return tmp.toString();
}
public String getEncodedValue(String contextPath)
{
StringWriter writer = new StringWriter(64);
- return getEncodedValue(contextPath, writer);
+ encodeValueTo(contextPath, writer);
+ return writer.toString();
}
- String getEncodedValue(String contextPath, Writer writer)
+ private void encodeValueTo(String contextPath, Writer writer)
{
- if (type == Type.URI && value.startsWith("/"))
+ if (contextPath != null && type == Type.URI &&
value.startsWith("/"))
{
Type.URI.encode(contextPath, writer);
}
- try
- {
- writer.write(getEncodedValue());
- }
- catch (IOException e)
- {
- throw new UndeclaredIOException(e);
- }
-
- return writer.toString();
+ type.encode(getValue(), writer);
}
public Type getType()
@@ -145,7 +137,7 @@
writer.write(name);
writer.write("=\"");
- writer.write(getEncodedValue(urlPrefix, writer));
+ encodeValueTo(urlPrefix, writer);
writer.write('"');
}
catch (IOException e)
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/MarkupTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/MarkupTestCase.java 2008-03-18
20:54:51 UTC (rev 10315)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/MarkupTestCase.java 2008-03-18
21:47:59 UTC (rev 10316)
@@ -93,4 +93,17 @@
MarkupAttribute attribute = new MarkupAttribute("name",
"/-_.*ABCabc012# ", MarkupAttribute.Type.URI);
assertEquals("/-_.*ABCabc012%23+", attribute.getEncodedValue());
}
+
+ public void testToString()
+ {
+ MarkupElement element = new MarkupElement("elementname",
"body", false,
+ new MarkupAttribute[]{new MarkupAttribute("attributename",
"attributevalue", MarkupAttribute.Type.CDATA)});
+
+ assertEquals("<elementname
attributename=\"attributevalue\">body</elementname>",
element.toString().trim());
+
+ element = new MarkupElement("elementname", null, false,
+ new MarkupAttribute[]{new MarkupAttribute("attributename",
"attributevalue", MarkupAttribute.Type.CDATA)});
+
+ assertEquals("<elementname
attributename=\"attributevalue\"/>", element.toString().trim());
+ }
}
Show replies by date