Revision: 3885
Author: jasvir
Date: Wed Dec 2 15:52:21 2009
Log: Small change in the cajoling service api to allow the uri policy to be
set
http://codereview.appspot.com/141042
Changes CajolingService to take a UriCallback object which rewrites uris
[email protected]
http://code.google.com/p/google-caja/source/detail?r=3885
Modified:
/trunk/src/com/google/caja/service/CajolingService.java
/trunk/src/com/google/caja/service/HtmlHandler.java
=======================================
--- /trunk/src/com/google/caja/service/CajolingService.java Fri Nov 13
13:37:15 2009
+++ /trunk/src/com/google/caja/service/CajolingService.java Wed Dec 2
15:52:21 2009
@@ -47,6 +47,24 @@
* @author [email protected] (Jasvir Nagra)
*/
public class CajolingService extends HttpServlet {
+ private static final String DEFAULT_HOST
= "http://caja.appspot.com/cajoler";
+ private final UriCallback DEFAULT_URIPOLICY = new UriCallback() {
+ public Reader retrieve(ExternalReference extref, String mimeType)
+ throws UriCallbackException {
+ try {
+ FetchedData data = fetch(extref.getUri());
+ return new InputStreamReader(
+ new ByteArrayInputStream(data.getContent()),
data.getCharSet());
+ } catch (IOException ex) {
+ throw new UriCallbackException(extref, ex);
+ }
+ }
+
+ public URI rewrite(ExternalReference extref, String mimeType) {
+ return extref.getUri();
+ }
+ };
+
private static class HttpContentHandlerArgs extends ContentHandlerArgs {
private final HttpServletRequest request;
@@ -62,16 +80,24 @@
private List<ContentHandler> handlers = new Vector<ContentHandler>();
private ContentTypeCheck typeCheck = new LooseContentTypeCheck();
- private String host = "http://caja.appspot.com/cajoler";
+ private String host;
+ private UriCallback cb;
public CajolingService(BuildInfo buildInfo) {
- registerHandlers(buildInfo);
+ this(buildInfo, DEFAULT_HOST);
}
public CajolingService(BuildInfo buildInfo, String host) {
this.host = host;
+ this.cb = DEFAULT_URIPOLICY;
registerHandlers(buildInfo);
}
+
+ public CajolingService(BuildInfo buildInfo, String host, UriCallback cb)
{
+ this.host = host;
+ this.cb = cb;
+ registerHandlers(buildInfo);
+ }
/**
* Read the remainder of the input request, send a BAD_REQUEST http
status
@@ -228,27 +254,11 @@
}
public void registerHandlers(BuildInfo buildInfo) {
- UriCallback retriever = new UriCallback() {
- public Reader retrieve(ExternalReference extref, String mimeType)
- throws UriCallbackException {
- try {
- FetchedData data = fetch(extref.getUri());
- return new InputStreamReader(
- new ByteArrayInputStream(data.getContent()),
data.getCharSet());
- } catch (IOException ex) {
- throw new UriCallbackException(extref, ex);
- }
- }
-
- public URI rewrite(ExternalReference extref, String mimeType) {
- return null;
- }
- };
handlers.add(new JsHandler(buildInfo));
handlers.add(new ImageHandler());
- handlers.add(new GadgetHandler(buildInfo, retriever));
+ handlers.add(new GadgetHandler(buildInfo, cb));
handlers.add(new InnocentHandler());
- handlers.add(new HtmlHandler(buildInfo, host, retriever));
+ handlers.add(new HtmlHandler(buildInfo, host, cb));
}
protected FetchedData fetch(URI uri) throws IOException {
=======================================
--- /trunk/src/com/google/caja/service/HtmlHandler.java Fri Nov 20 16:58:55
2009
+++ /trunk/src/com/google/caja/service/HtmlHandler.java Wed Dec 2 15:52:21
2009
@@ -63,12 +63,6 @@
public class HtmlHandler implements ContentHandler {
private final BuildInfo buildInfo;
private final PluginEnvironment pluginEnvironment;
- private final static String DEFAULT_HOSTED_SERVICE
- = "http://caja.appspot.com/cajoler";
-
- public HtmlHandler(BuildInfo buildInfo) {
- this(buildInfo, DEFAULT_HOSTED_SERVICE, null);
- }
public HtmlHandler(
BuildInfo buildInfo, final String hostedService,