You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by mh...@apache.org on 2011/03/23 03:21:14 UTC
svn commit: r1084458 - in
/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js:
JsResponse.java JsResponseBuilder.java
Author: mhermanto
Date: Wed Mar 23 02:21:14 2011
New Revision: 1084458
URL: http://svn.apache.org/viewvc?rev=1084458&view=rev
Log:
Add compiled externs to JsResponse.
http://codereview.appspot.com/4284061/
Modified:
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponse.java
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponseBuilder.java
Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponse.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponse.java?rev=1084458&r1=1084457&r2=1084458&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponse.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponse.java Wed Mar 23 02:21:14 2011
@@ -27,20 +27,22 @@ import java.util.List;
public class JsResponse {
private final List<JsContent> jsCode;
private final List<String> errors;
- private String codeString;
+ private final String externs;
private final int cacheTtlSecs;
private final int statusCode;
private final boolean proxyCacheable;
-
+ private String codeString;
+
JsResponse(List<JsContent> jsCode, int statusCode, int cacheTtlSecs,
- boolean proxyCacheable, List<String> errors) {
+ boolean proxyCacheable, List<String> errors, String externs) {
this.jsCode = Collections.unmodifiableList(jsCode);
this.errors = Collections.unmodifiableList(errors);
this.statusCode = statusCode;
this.cacheTtlSecs = cacheTtlSecs;
this.proxyCacheable = proxyCacheable;
+ this.externs = externs;
}
-
+
/**
* Returns the JavaScript code to serve.
*/
@@ -54,48 +56,55 @@ public class JsResponse {
}
return codeString;
}
-
+
/**
* Returns an iterator starting at the beginning of all JS code in the response.
*/
public Iterable<JsContent> getAllJsContent() {
return jsCode;
}
-
+
/**
* Returns the HTTP status code.
*/
public int getStatusCode() {
return statusCode;
}
-
+
/**
* Returns whether the current response code is an error code.
*/
public boolean isError() {
return statusCode >= 400;
}
-
+
/**
* Returns the cache TTL in seconds for this response.
- *
+ *
* 0 seconds means "no cache"; a value below 0 means "cache forever".
*/
public int getCacheTtlSecs() {
return cacheTtlSecs;
}
-
+
/**
* Returns whether the response can be cached by intermediary proxies.
*/
public boolean isProxyCacheable() {
return proxyCacheable;
}
-
+
/**
* Returns a list of any error messages associated with this response.
*/
public List<String> getErrors() {
return errors;
}
+
+ /**
+ * Returns a string of generated externs.
+ */
+ public String getExterns() {
+ return externs;
+ }
}
Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponseBuilder.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponseBuilder.java?rev=1084458&r1=1084457&r2=1084458&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponseBuilder.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsResponseBuilder.java Wed Mar 23 02:21:14 2011
@@ -31,17 +31,19 @@ import java.util.List;
*/
public class JsResponseBuilder {
private LinkedList<JsContent> jsCode;
- private List<String> errors;
+ private final List<String> errors;
private int statusCode;
private int cacheTtlSecs;
private boolean proxyCacheable;
-
+ private String externs;
+
public JsResponseBuilder() {
jsCode = Lists.newLinkedList();
statusCode = HttpServletResponse.SC_OK;
cacheTtlSecs = 0;
proxyCacheable = false;
errors = Lists.newLinkedList();
+ externs = null;
}
public JsResponseBuilder(JsResponse response) {
@@ -50,8 +52,9 @@ public class JsResponseBuilder {
statusCode = response.getStatusCode();
cacheTtlSecs = response.getCacheTtlSecs();
proxyCacheable = response.isProxyCacheable();
+ externs = response.getExterns();
}
-
+
/**
* Appends more JS to the response.
*/
@@ -59,14 +62,14 @@ public class JsResponseBuilder {
jsCode.add(jsContent);
return this;
}
-
+
/**
* Helper to append JS to the response w/ a name.
*/
public JsResponseBuilder appendJs(String content, String name) {
return appendJs(new JsContent(content, name));
}
-
+
/**
* Helper to append a bunch of JS.
*/
@@ -76,7 +79,7 @@ public class JsResponseBuilder {
}
return this;
}
-
+
/**
* Prepends JS to the output.
*/
@@ -84,7 +87,7 @@ public class JsResponseBuilder {
jsCode.addFirst(new JsContent(content, name));
return this;
}
-
+
/**
* Replaces the current JavaScript code with some new code.
*/
@@ -107,14 +110,14 @@ public class JsResponseBuilder {
this.statusCode = responseCode;
return this;
}
-
+
/**
* Returns the HTTP status code.
*/
public int getStatusCode() {
return statusCode;
}
-
+
/**
* Adds an error to the response
*/
@@ -122,7 +125,7 @@ public class JsResponseBuilder {
this.errors.add(error);
return this;
}
-
+
/**
* Adds multiple errors to the response
*/
@@ -130,17 +133,17 @@ public class JsResponseBuilder {
this.errors.addAll(errs);
return this;
}
-
+
/**
* Sets the cache TTL in seconds for the response being built.
- *
+ *
* 0 seconds means "no cache"; a value below 0 means "cache forever".
*/
public JsResponseBuilder setCacheTtlSecs(int cacheTtlSecs) {
this.cacheTtlSecs = cacheTtlSecs;
return this;
}
-
+
/**
* Returns the cache TTL in seconds for the response.
*/
@@ -155,7 +158,7 @@ public class JsResponseBuilder {
this.proxyCacheable = proxyCacheable;
return this;
}
-
+
/**
* Returns whether the response can be cached by intermediary proxies.
*/
@@ -164,9 +167,18 @@ public class JsResponseBuilder {
}
/**
+ * Sets whether the compiled externs.
+ */
+ public JsResponseBuilder setExterns(String externs) {
+ this.externs = externs;
+ return this;
+ }
+
+ /**
* Builds a {@link JsResponse} object with the provided data.
*/
public JsResponse build() {
- return new JsResponse(jsCode, statusCode, cacheTtlSecs, proxyCacheable, errors);
+ return new JsResponse(jsCode, statusCode, cacheTtlSecs, proxyCacheable,
+ errors, externs);
}
}
\ No newline at end of file