Reviewers: jasvir,


Please review this at http://codereview.appspot.com/4610043/

Affected files:
M src/com/google/caja/demos/playground/server/GWTCajolingServiceImpl.java
  M     src/com/google/caja/parser/html/Dom.java
  M     src/com/google/caja/parser/js/CajoledModule.java
  M     src/com/google/caja/reporting/RenderContext.java
  M     tests/com/google/caja/plugin/BrowserTestCase.java


Index: tests/com/google/caja/plugin/BrowserTestCase.java
===================================================================
--- tests/com/google/caja/plugin/BrowserTestCase.java   (revision 4501)
+++ tests/com/google/caja/plugin/BrowserTestCase.java   (working copy)
@@ -264,7 +264,9 @@
    *
    * @param servlets a Jetty Context to which servlets can be added.
    */
-  protected void addServlets(Context servlets) { }
+  protected void addServlets(Context servlets) {
+    // Adds none but may be overridden.
+  }

   public interface Check {
     boolean run();
Index: src/com/google/caja/parser/html/Dom.java
===================================================================
--- src/com/google/caja/parser/html/Dom.java    (revision 4501)
+++ src/com/google/caja/parser/html/Dom.java    (working copy)
@@ -25,14 +25,13 @@
 import com.google.caja.util.Callback;

 import java.io.IOException;
-import java.io.Serializable;

 import org.w3c.dom.Node;

 /**
  * A parse tree wrapper for an org.w3c.DOM node.
  */
-public final class Dom extends AbstractParseTreeNode implements Serializable {
+public final class Dom extends AbstractParseTreeNode {
   private static final long serialVersionUID = -5111504015682453850L;
   private final Node n;

Index: src/com/google/caja/parser/js/CajoledModule.java
===================================================================
--- src/com/google/caja/parser/js/CajoledModule.java    (revision 4501)
+++ src/com/google/caja/parser/js/CajoledModule.java    (working copy)
@@ -30,7 +30,6 @@
 import com.google.javascript.jscomp.jsonml.JsonML;

 import java.io.IOException;
-import java.io.Serializable;
 import java.net.URI;
 import java.util.Arrays;
 import java.util.Collections;
@@ -48,9 +47,9 @@
  * @author [email protected]
  */
 public final class CajoledModule extends AbstractParseTreeNode
-    implements JsonMLCompatible, Serializable {
+    implements JsonMLCompatible {
   private static final long serialVersionUID = -2499144011243193616L;
-
+
// A stub file name by which to call the (otherwise anonymous) cajoled output.
   private static final InputSource CAJOLED_OUTPUT_FILE_NAME =
       new InputSource(URI.create("file:///CAJOLED-OUTPUT"));
Index: src/com/google/caja/demos/playground/server/GWTCajolingServiceImpl.java
===================================================================
--- src/com/google/caja/demos/playground/server/GWTCajolingServiceImpl.java (revision 4501) +++ src/com/google/caja/demos/playground/server/GWTCajolingServiceImpl.java (working copy)
@@ -19,7 +19,6 @@
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.net.URLConnection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -136,13 +135,13 @@

     Map<InputSource, ? extends CharSequence> originalSources
= Collections.singletonMap(new InputSource(guessURI(base, url)), input);
-
+
     PluginMeta meta = new PluginMeta(fetcher, null);
     meta.setEnableES53(es53Mode);
     PluginCompiler compiler = makePluginCompiler(meta, mq);
     compiler.setJobCache(new AppEngineJobCache());
     compiler.setMessageContext(mc);
-
+
     URI uri = guessURI(base, url);
     InputSource is = new InputSource(uri);
     CharProducer cp = CharProducer.Factory.fromString(input, is);
@@ -156,17 +155,17 @@
       mq.addMessage(e.getCajaMessage());
       okToContinue = false;
     }
-
+
     if (okToContinue && inputNode != null) {
       compiler.addInput(inputNode, uri);
       okToContinue &= compiler.run();
     }
-
+
     outputJs = okToContinue ? compiler.getJavascript() : null;
     outputHtml = okToContinue ? compiler.getStaticHtml() : null;
-
+
     String[] messages = formatMessages(originalSources, mc, mq);
-
+
     StringBuilder jsOut = new StringBuilder();
     TokenConsumer renderer = new JsPrettyPrinter(new Concatenator(jsOut));
     RenderContext rc = new RenderContext(renderer)
Index: src/com/google/caja/reporting/RenderContext.java
===================================================================
--- src/com/google/caja/reporting/RenderContext.java    (revision 4501)
+++ src/com/google/caja/reporting/RenderContext.java    (working copy)
@@ -70,26 +70,32 @@
   public final boolean rawObjKeys() { return rawObjKeys; }
   public final TokenConsumer getOut() { return out; }

+ /** Must be overridden by subclasses to return an instance of the subclass. */
+  protected RenderContext derive(
+      boolean asciiOnly, boolean embeddable, boolean json,
+      MarkupRenderMode markupMode, boolean rawObjKeys) {
+    return new RenderContext(
+        asciiOnly, embeddable, json, markupMode, rawObjKeys, out);
+  }
+
   public RenderContext withAsciiOnly(boolean b) {
     return b != asciiOnly
- ? new RenderContext(b, embeddable, json, markupMode, rawObjKeys, out)
+        ? derive(b, embeddable, json, markupMode, rawObjKeys)
         : this;
   }
   public RenderContext withEmbeddable(boolean b) {
     return b != embeddable
- ? new RenderContext(asciiOnly, b, json, markupMode, rawObjKeys, out)
+        ? derive(asciiOnly, b, json, markupMode, rawObjKeys)
         : this;
   }
   public RenderContext withJson(boolean b) {
     return b != json
-        ? new RenderContext(
-            asciiOnly, embeddable, b, markupMode, rawObjKeys, out)
+        ? derive(asciiOnly, embeddable, b, markupMode, rawObjKeys)
         : this;
   }
   public RenderContext withMarkupRenderMode(MarkupRenderMode markupMode) {
     return markupMode != this.markupMode
-        ? new RenderContext(
-            asciiOnly, embeddable, json, markupMode, rawObjKeys, out)
+        ? derive(asciiOnly, embeddable, json, markupMode, rawObjKeys)
         : this;
   }
   @Deprecated
@@ -99,7 +105,7 @@
   }
   public RenderContext withRawObjKeys(boolean b) {
     return b != this.rawObjKeys
- ? new RenderContext(asciiOnly, embeddable, json, markupMode, b, out)
+        ? derive(asciiOnly, embeddable, json, markupMode, b)
         : this;
   }
 }


Reply via email to