Author: trong.tran
Date: 2011-02-15 04:45:25 -0500 (Tue, 15 Feb 2011)
New Revision: 5890
Modified:
components/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/MessageBundle.java
components/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/MessageBundleTest.java
Log:
GTNPORTAL-1800 support CDATA in message bundle sections
Modified:
components/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/MessageBundle.java
===================================================================
---
components/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/MessageBundle.java 2011-02-15
09:27:31 UTC (rev 5889)
+++
components/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/spec/MessageBundle.java 2011-02-15
09:45:25 UTC (rev 5890)
@@ -27,6 +27,7 @@
import org.json.JSONObject;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.IOException;
@@ -164,7 +165,12 @@
NodeList msgChildren = msg.getChildNodes();
for (int child = 0; child < msgChildren.getLength(); ++child) {
try {
- htmlSerializer.serialize(msgChildren.item(child), sw);
+ if (msgChildren.item(child).getNodeType() == Node.CDATA_SECTION_NODE) {
+ // Workaround to treat CDATA as text.
+ sw.append(msgChildren.item(child).getTextContent());
+ } else {
+ htmlSerializer.serialize(msgChildren.item(child), sw);
+ }
} catch (IOException e) {
throw new SpecParserException("Unexpected error getting value of msg
node",
new XmlException(e));
Modified:
components/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/MessageBundleTest.java
===================================================================
---
components/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/MessageBundleTest.java 2011-02-15
09:27:31 UTC (rev 5889)
+++
components/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/MessageBundleTest.java 2011-02-15
09:45:25 UTC (rev 5890)
@@ -84,6 +84,16 @@
assertEquals(ImmutableMap.of("key", "value"),
bundle.getMessages());
}
+ @Test
+ public void containsCdataSection() throws Exception {
+ String cdataXml =
+ "<messagebundle>" +
+ " <msg name='key'><![CDATA[<span
id='foo'>data</span>]]></msg>" +
+ "</messagebundle>";
+ MessageBundle bundle = new MessageBundle(locale, cdataXml);
+ assertEquals(ImmutableMap.of("key", "<span
id='foo'>data</span>"), bundle.getMessages());
+ }
+
@Test(expected = SpecParserException.class)
public void missingNameThrows() throws SpecParserException {
String xml =
"<messagebundle><msg>foo</msg></messagebundle>";
Show replies by date