Author: johnh
Date: Fri Dec 14 16:50:47 2007
New Revision: 604358
URL: http://svn.apache.org/viewvc?rev=604358&view=rev
Log:
* Fixed NPE in substitute() and substituteType() when input is null, and
check if there are no subs for that type before checking input for
its prefix since that is much faster.
* GadgetSpec.getContentData/Href() throw ISE if not correct type.
* Gadget and ParsedGadgetSpec honor this contract.
* Resolved proxy handler confusion by adding an explicit output parameter
to /proxy and eliminating /jsonp. Fixed a potenatial runtime exception in
Utf8InputStream.
* Fix handling of null title-url.
Contributors: [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED] (still
getting SVN access set up; I'm proxying in the meantime)
Removed:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/JsonpProxyServlet.java
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpec.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecParser.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Substitutions.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Utf8InputStream.java
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ProxyServlet.java
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java?rev=604358&r1=604357&r2=604358&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Gadget.java
Fri Dec 14 16:50:47 2007
@@ -135,11 +135,13 @@
*/
public URL getTitleURL() {
URL ret = null;
- String urlStr = baseSpec.getTitleURL().toString();
- try {
- ret = new URL(substitutions.substitute(urlStr));
- } catch (MalformedURLException e) {
- return null;
+ if (baseSpec.getTitleURL() != null) {
+ String urlStr = baseSpec.getTitleURL().toString();
+ try {
+ ret = new URL(substitutions.substitute(urlStr));
+ } catch (MalformedURLException e) {
+ return null;
+ }
}
return ret;
}
@@ -264,12 +266,9 @@
/**
* @return URL of gadget to render of type == URL; null if malformed/missing
+ * @throws IllegalStateException if contentType is not URL.
*/
public URL getContentHref() {
- if (getContentType() != ContentType.URL) {
- return null;
- }
-
URL ret = null;
String urlStr = baseSpec.getContentHref().toString();
try {
@@ -282,6 +281,7 @@
/**
* @return Gadget contents with all substitutions applied
+ * @throws IllegalStateException if contentType is not HTML.
*/
public String getContentData() {
return substitutions.substitute(baseSpec.getContentData());
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpec.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpec.java?rev=604358&r1=604357&r2=604358&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpec.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpec.java
Fri Dec 14 16:50:47 2007
@@ -77,7 +77,19 @@
}
public ContentType getContentType();
+
+ /**
+ * Must be a URL type gadget.
+ *
+ * @return The URL for this gadget spec.
+ * @throws IllegalStateException if contentType is not URL.
+ */
public URL getContentHref();
+
+ /**
+ * @return The HTML content for this gadget spec.
+ * @throws IllegalStateException if contentType is not HTML.
+ */
public String getContentData();
/**
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecParser.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecParser.java?rev=604358&r1=604357&r2=604358&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecParser.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/GadgetSpecParser.java
Fri Dec 14 16:50:47 2007
@@ -507,10 +507,16 @@
}
public URL getContentHref() {
+ if (contentType != ContentType.URL) {
+ throw new IllegalStateException("contentType must be URL");
+ }
return contentHref;
}
public String getContentData() {
+ if (contentType != ContentType.HTML) {
+ throw new IllegalStateException("contentType must be HTML");
+ }
return contentData;
}
}
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Substitutions.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Substitutions.java?rev=604358&r1=604357&r2=604358&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Substitutions.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Substitutions.java
Fri Dec 14 16:50:47 2007
@@ -106,19 +106,21 @@
*
* @param input
* The base string, with substitution markers.
- * @return The substituted string.
+ * @return The substituted string or null if [EMAIL PROTECTED] input} is
null.
*/
public String substitute(String input) {
- for (Type type : Type.values()) {
- input = substituteType(type, input);
+ if (input != null) {
+ for (Type type : Type.values()) {
+ input = substituteType(type, input);
+ }
}
return input;
}
/**
* Performs string substitution only for the specified type. If no
- * substitution for the given string was provided, the output is left
- * untouched.
+ * substitution for [EMAIL PROTECTED] input} was provided or [EMAIL
PROTECTED] input} is null,
+ * the output is left untouched.
*
* @param type
* The type you wish to perform substitutions for.
@@ -127,8 +129,8 @@
* @return The substituted string.
*/
public String substituteType(Type type, String input) {
- if (!input.contains(type.prefix) ||
- substitutions.get(type).size() == 0) {
+ if (input == null || substitutions.get(type).size() == 0 ||
+ !input.contains(type.prefix)) {
return input;
}
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Utf8InputStream.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Utf8InputStream.java?rev=604358&r1=604357&r2=604358&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Utf8InputStream.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/Utf8InputStream.java
Fri Dec 14 16:50:47 2007
@@ -13,7 +13,6 @@
*/
package org.apache.shindig.gadgets;
-import java.io.IOException;
import java.io.InputStream;
/**
@@ -24,8 +23,9 @@
private int position = 0;
@Override
- public int read() throws IOException {
+ public int read() {
if (position == 0
+ && content.length >= 3
&& content[0] == (byte)0xEF
&& content[1] == (byte)0xBB
&& content[2] == (byte)0xBF) {
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ProxyServlet.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ProxyServlet.java?rev=604358&r1=604357&r2=604358&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ProxyServlet.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/http/ProxyServlet.java
Fri Dec 14 16:50:47 2007
@@ -28,7 +28,8 @@
private final static ProxyHandler handler = new ProxyHandler();
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
- if (request.getServletPath().equals("/gadgets/jsonp")) {
+ String output = request.getParameter("output");
+ if (output != null && output.equals("js")) {
handler.fetchJson(request, response);
} else {
handler.fetch(request, response);