You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ga...@apache.org on 2011/05/01 12:40:37 UTC
svn commit: r1098248 - in /shindig/trunk/java/gadgets/src:
main/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializer.java
test/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializerTest.java
Author: gagan
Date: Sun May 1 10:40:37 2011
New Revision: 1098248
URL: http://svn.apache.org/viewvc?rev=1098248&view=rev
Log:
Patch by nikhilmadan23 | Issue 4423077: Run VanillCajaHtmlSerializer with ASCII only mode off and don't remove comments | http://codereview.appspot.com/4423077/
Added:
shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializerTest.java (with props)
Modified:
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializer.java
Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializer.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializer.java?rev=1098248&r1=1098247&r2=1098248&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializer.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializer.java Sun May 1 10:40:37 2011
@@ -38,8 +38,15 @@ public class VanillaCajaHtmlSerializer i
if (doc.getDoctype() != null) {
HtmlSerialization.outputDocType(doc.getDoctype(), sw);
}
- sw.append(Nodes.render(doc,
- new RenderContext(new Concatenator(sw, null)).asXml() ? MarkupRenderMode.XML : MarkupRenderMode.HTML));
+ RenderContext renderContext =
+ new RenderContext(new Concatenator(sw, null))
+ // More compact but needs charset set correctly.
+ .withAsciiOnly(false)
+ .withMarkupRenderMode(MarkupRenderMode.HTML);
+
+ // Use render unsafe in order to retain comments in the serialized HTML.
+ // TODO: This function is deprecated. Use a non-deprecated function.
+ Nodes.renderUnsafe(doc, renderContext);
return sw.toString();
} catch (IOException e) {
return null;
Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializerTest.java?rev=1098248&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializerTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializerTest.java Sun May 1 10:40:37 2011
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.gadgets.parse.caja;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for VanillaCajaHtmlSerializer.
+ */
+public class VanillaCajaHtmlSerializerTest {
+ private VanillaCajaHtmlParser parser;
+ private VanillaCajaHtmlSerializer serializer;
+
+ @Before
+ public void setUp() throws Exception {
+ DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
+ // Require the traversal API
+ DOMImplementation domImpl = registry.getDOMImplementation("XML 1.0 Traversal 2.0");
+ parser = new VanillaCajaHtmlParser(domImpl, true);
+ serializer = new VanillaCajaHtmlSerializer();
+ }
+
+ @Test
+ public void testParseAndSerializeNonASCIINotEscaped() throws Exception {
+ String html = "<html><head><script src=\"1.js\"></script></head>"
+ + "<body><a href=\"hello\">\\u200E\\u200F\\u2010\\u0410</a>"
+ + "</body></html>";
+ assertEquals(html, serializer.serialize(parser.parseDom(html)));
+ }
+
+ @Test
+ public void testParseAndSerializeCommentsNotRemoved() throws Exception {
+ String html = "<html><head><script src=\"1.js\"></script></head>"
+ + "<body><div>before <!-- Test Data --> after \n"
+ + "<!-- [if IE ]>"
+ + "<link href=\"iecss.css\" rel=\"stylesheet\" type=\"text/css\">"
+ + "<![endif]-->"
+ + "</div></body></html>";
+ // If we run the serializer with wantsComments set to false, all comments are removed from the
+ // serialized html and the output is:
+ // "<html><head><script src=\"1.js\"></script></head>"
+ // + "<body><div>"
+ // + "</div></body></html>"
+ assertEquals(html, serializer.serialize(parser.parseDom(html)));
+ }
+}
Propchange: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/VanillaCajaHtmlSerializerTest.java
------------------------------------------------------------------------------
svn:eol-style = native