You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2010/08/10 13:32:34 UTC
svn commit: r983934 [2/8] - in /shindig/branches/2.0.x: ./ config/
content/container/ content/samplecontainer/examples/ActivityStreams/
extras/src/main/java/org/apache/shindig/extras/as/core/model/
extras/src/main/java/org/apache/shindig/extras/as/open...
Modified: shindig/branches/2.0.x/extras/src/main/java/org/apache/shindig/extras/as/sample/ActivityStreamsJsonDbService.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/extras/src/main/java/org/apache/shindig/extras/as/sample/ActivityStreamsJsonDbService.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/extras/src/main/java/org/apache/shindig/extras/as/sample/ActivityStreamsJsonDbService.java (original)
+++ shindig/branches/2.0.x/extras/src/main/java/org/apache/shindig/extras/as/sample/ActivityStreamsJsonDbService.java Tue Aug 10 11:32:26 2010
@@ -66,9 +66,11 @@ public class ActivityStreamsJsonDbServic
public Future<Void> createActivityEntry(UserId userId, GroupId groupId, String appId,
Set<String> fields, ActivityEntry activityEntry, SecurityToken token) throws ProtocolException {
try {
- JSONObject jsonObject = convertFromActivityEntry(activityEntry, fields);
- if (!jsonObject.has(ActivityEntry.Field.ID.toString())) {
- jsonObject.put(ActivityEntry.Field.ID.toString(), System.currentTimeMillis());
+ JSONObject jsonEntry = convertFromActivityEntry(activityEntry, fields);
+ JSONObject jsonEntryObject = jsonEntry.getJSONObject(ActivityEntry.Field.OBJECT.toString());
+ if (!jsonEntryObject.has(ActivityObject.Field.ID.toString())) {
+ jsonEntryObject.put(ActivityObject.Field.ID.toString(), System.currentTimeMillis());
+ jsonEntry.put(ActivityEntry.Field.OBJECT.toString(), jsonEntryObject);
}
// TODO: bug fixed: jsonArray will not be null; will throw exception!
@@ -81,7 +83,7 @@ public class ActivityStreamsJsonDbServic
jsonArray = new JSONArray();
db.getJSONObject(ACTIVITYSTREAMS_TABLE).put(userId.getUserId(token), jsonArray);
}
- jsonArray.put(jsonObject);
+ jsonArray.put(jsonEntry);
return ImmediateFuture.newInstance(null);
} catch (JSONException je) {
throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(),
@@ -100,7 +102,7 @@ public class ActivityStreamsJsonDbServic
JSONArray newList = new JSONArray();
for (int i = 0; i < activityEntries.length(); i++) {
JSONObject activityEntry = activityEntries.getJSONObject(i);
- if (!activityIds.contains(activityEntry.getString(ActivityEntry.Field.ID.toString()))) {
+ if (!activityIds.contains(activityEntry.getJSONObject(ActivityEntry.Field.OBJECT.toString()).getString(ActivityObject.Field.ID.toString()))) {
newList.put(activityEntry);
}
}
@@ -123,16 +125,16 @@ public class ActivityStreamsJsonDbServic
public Future<ActivityEntry> getActivityEntry(UserId userId, GroupId groupId,
String appId, Set<String> fields, String activityId, SecurityToken token)
throws ProtocolException {
- try {
+ try {
String user = userId.getUserId(token);
if (db.getJSONObject(ACTIVITYSTREAMS_TABLE).has(user)) {
JSONArray activityEntries = db.getJSONObject(ACTIVITYSTREAMS_TABLE).getJSONArray(user);
for (int i = 0; i < activityEntries.length(); i++) {
JSONObject activityEntry = activityEntries.getJSONObject(i);
- JSONObject actor = new JSONObject(activityEntry.get(ActivityEntry.Field.ACTOR.toString()).toString());
+ JSONObject actor = activityEntry.getJSONObject(ActivityEntry.Field.ACTOR.toString());
String actorId = actor.get(ActivityObject.Field.ID.toString()).toString();
if (actorId.equals(user)
- && activityEntry.get(ActivityEntry.Field.ID.toString()).toString().equals(activityId)) {
+ && activityEntry.getJSONObject(ActivityEntry.Field.OBJECT.toString()).get(ActivityObject.Field.ID.toString()).toString().equals(activityId)) {
return ImmediateFuture.newInstance(jsonDb.filterFields(activityEntry, fields, ActivityEntry.class));
}
}
@@ -144,13 +146,29 @@ public class ActivityStreamsJsonDbServic
je);
}
}
-
+
public Future<RestfulCollection<ActivityEntry>> getActivityEntries(
Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields,
CollectionOptions options, SecurityToken token)
throws ProtocolException {
List<ActivityEntry> result = Lists.newArrayList();
-
+
+// // Retrieve activities from Lotus Connections
+// FeedParser parser;
+// try {
+// parser = new FeedParser();
+// ArrayList<JSONObject> activityEntries = parser.parseFeed("http://w3.ibm.com/connections/news/atom/stories/public");
+// for(JSONObject activityEntry : activityEntries) {
+// result.add(jsonDb.filterFields(activityEntry, fields, ActivityEntry.class));
+// }
+// } catch (ParserConfigurationException e) {
+// e.printStackTrace();
+// } catch (SAXException e) {
+// e.printStackTrace();
+// } catch (JSONException e) {
+// e.printStackTrace();
+// }
+
try {
Set<String> idSet = jsonDb.getIdSet(userIds, groupId, token);
for (String id : idSet) {
@@ -161,9 +179,9 @@ public class ActivityStreamsJsonDbServic
result.add(jsonDb.filterFields(activityEntry, fields, ActivityEntry.class));
// TODO: ActivityStreams don't have appIds
// if (appId == null || !activitystream.has(ActivityStream.Field.APP_ID.toString())) {
-// result.add(filterFields(activitystream, fields, ActivityStream.class));
+// result.add(jsonDb.filterFields(activitystream, fields, ActivityStream.class));
// } else if (activitystream.get(ActivityStream.Field.APP_ID.toString()).equals(appId)) {
-// result.add(filterFields(activitystream, fields, ActivityStream.class));
+// result.add(jsonDb.filterFields(activitystream, fields, ActivityStream.class));
// }
}
}
@@ -174,7 +192,7 @@ public class ActivityStreamsJsonDbServic
je);
}
}
-
+
public Future<RestfulCollection<ActivityEntry>> getActivityEntries(
UserId userId, GroupId groupId, String appId, Set<String> fields,
CollectionOptions options, Set<String> activityIds, SecurityToken token)
@@ -189,7 +207,7 @@ public class ActivityStreamsJsonDbServic
JSONObject actor = new JSONObject(activityEntry.get(ActivityEntry.Field.ACTOR.toString()));
String actorId = actor.get(ActivityObject.Field.ID.toString()).toString();
if (actorId.equals(user)
- && activityIds.contains(activityEntry.getString(ActivityEntry.Field.ID.toString()))) {
+ && activityIds.contains(activityEntry.getJSONObject(ActivityEntry.Field.OBJECT.toString()).getString(ActivityObject.Field.ID.toString()).toString())) {
result.add(jsonDb.filterFields(activityEntry, fields, ActivityEntry.class));
}
}
Modified: shindig/branches/2.0.x/extras/src/main/javascript/features-extras/features.txt
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/extras/src/main/javascript/features-extras/features.txt?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/extras/src/main/javascript/features-extras/features.txt (original)
+++ shindig/branches/2.0.x/extras/src/main/javascript/features-extras/features.txt Tue Aug 10 11:32:26 2010
@@ -16,4 +16,6 @@
# specific language governing permissions and limitations
# under the License.
-features/org.jquery.core-1.4.2/feature.xml
+features-extras/org.jquery.core-1.4.2/feature.xml
+features-extras/wave/feature.xml
+features-extras/opensocial-payment/feature.xml
Modified: shindig/branches/2.0.x/features/NOTICE
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/NOTICE?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/NOTICE (original)
+++ shindig/branches/2.0.x/features/NOTICE Tue Aug 10 11:32:26 2010
@@ -22,3 +22,4 @@ Geoff Stearns, Michael Williams, and Bob
This product includes software (opensocial-resources) developed by
The OpenSocial Foundation (http://opensocial-resources.googlecode.com/svn/spec/0.8/)
+This product contains software (sha1 JS impl) developed by Google Inc.
Modified: shindig/branches/2.0.x/features/pom.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/pom.xml?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/pom.xml (original)
+++ shindig/branches/2.0.x/features/pom.xml Tue Aug 10 11:32:26 2010
@@ -108,6 +108,8 @@
<source>../../../../src/test/javascript/features/mocks/xhr.js</source>
<source>globals/globals.js</source>
<source>core.config/config.js</source>
+ <source>core.config/configcontainer.js</source>
+ <source>core.config/configgadget.js</source>
<source>core.json/json.js</source>
<source>shindig.auth/auth.js</source>
<source>core.util/util.js</source>
@@ -121,6 +123,7 @@
<source>i18n/numberformat.js</source>
<source>setprefs/setprefs.js</source>
<source>views/views.js</source>
+ <source>shindig.uri/uri.js</source>
<source>shindig.xhrwrapper/xhrwrapper.js</source>
<source>xmlutil/xmlutil.js</source>
<source>opensocial-data-context/datacontext.js</source>
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/container/container.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/container/container.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/container/container.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/container/container.js Tue Aug 10 11:32:26 2010
@@ -174,18 +174,27 @@ shindig.container.Container.prototype.cl
/**
+ * Pre-load one gadget metadata information. More details on preloadGadgets().
+ * @param {string} gadgetUrl gadget URI to preload.
+ */
+shindig.container.Container.prototype.preloadGadget = function(gadgetUrl) {
+ this.preloadGadgets([gadgetUrl]);
+};
+
+
+/**
* Pre-load gadgets metadata information. This is done by priming the cache,
* and making an immediate call to fetch metadata of gadgets fully specified at
* gadgetUrls. This will not render, and do additional callback operations.
- * @param {Object} request JSON containing ids of gadgets URIs to preload.
+ * @param {Array} gadgetUrls gadgets URIs to preload.
*/
-shindig.container.Container.prototype.preloadGadgets = function(request) {
- var metadataRequest = {
+shindig.container.Container.prototype.preloadGadgets = function(gadgetUrls) {
+ var request = {
'container' : window.__CONTAINER,
- 'ids' : request['ids']
+ 'ids' : gadgetUrls
};
var self = this;
- this.service_.getGadgetMetadata(metadataRequest, function(response) {
+ this.service_.getGadgetMetadata(request, function(response) {
if (!response.error) {
for (var id in response) {
self.addPreloadedGadgetUrl_(id);
@@ -195,6 +204,22 @@ shindig.container.Container.prototype.pr
});
};
+
+/**
+ * Fetch the gadget metadata commonly used by container for user preferences.
+ * @param {string} gadgetUrl gadgets URI to fetch metadata for. to preload.
+ * @param {function(Object)} callback Function called with gadget metadata.
+ */
+shindig.container.Container.prototype.getGadgetMetadata = function(
+ gadgetUrl, callback) {
+ var request = {
+ 'container' : window.__CONTAINER,
+ 'ids' : [ gadgetUrl ]
+ };
+ this.service_.getGadgetMetadata(request, callback);
+};
+
+
/**
* Callback that occurs after instantiation/construction of this. Override to
* provide your specific functionalities.
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/container/feature.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/container/feature.xml?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/container/feature.xml (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/container/feature.xml Tue Aug 10 11:32:26 2010
@@ -22,6 +22,7 @@ under the License.
<dependency>globals</dependency>
<dependency>core.log</dependency>
<dependency>shindig.auth</dependency>
+ <dependency>shindig.uri.ext</dependency>
<dependency>core.util</dependency>
<dependency>osapi</dependency>
<dependency>rpc</dependency>
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/container/gadget_holder.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/container/gadget_holder.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/container/gadget_holder.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/container/gadget_holder.js Tue Aug 10 11:32:26 2010
@@ -29,7 +29,7 @@
*/
shindig.container.GadgetHolder = function(siteId, el) {
/**
- * Unique numeric gadget ID. Should be the same as siteId.
+ * Unique numeric gadget ID.
* @type {number}
* @private
*/
@@ -85,13 +85,6 @@ shindig.container.GadgetHolder = functio
this.view_ = null;
/**
- * JSON metadata about current view being rendered.
- * @type {Object?}
- * @private
- */
- this.viewInfo_ = null;
-
- /**
* A dynamically set social/security token.
* Social tokens are sent with original view URLs but may need
* to be refreshed for long lived gadgets.
@@ -197,8 +190,7 @@ shindig.container.GadgetHolder.prototype
}
this.renderParams_ = renderParams;
this.view_ = renderParams['view'];
- this.viewInfo_ = this.gadgetInfo_['views'][this.view_];
- if (!this.viewInfo_) {
+ if (!this.gadgetInfo_['views'][this.view_]) {
throw 'View ' + this.view_ + ' unsupported in ' + this.gadgetInfo_['url'];
}
@@ -206,10 +198,13 @@ shindig.container.GadgetHolder.prototype
// Set up RPC channel. RPC relay url is on gmodules, relative to base of the
// container. Assumes container has set up forwarding to gmodules at /gadgets.
- gadgets.rpc.setRelayUrl(this.iframeId_, this.viewInfo_['iframeHost'] +
- '/gadgets/files/container/rpc_relay.html');
- // Pull RPC token from gadget URI
- gadgets.rpc.setAuthToken(this.iframeId_, this.getRpcToken_());
+ var iframeUri = shindig.uri(this.gadgetInfo_['iframeUrl']);
+ var relayUri = shindig.uri()
+ .setSchema(iframeUri.getSchema())
+ .setAuthority(iframeUri.getAuthority())
+ .setPath('/gadgets/files/container/rpc_relay.html');
+ gadgets.rpc.setRelayUrl(this.iframeId_, relayUri.toString());
+ gadgets.rpc.setAuthToken(this.iframeId_, iframeUri.getFP('rpctoken'));
};
@@ -270,53 +265,31 @@ shindig.container.GadgetHolder.prototype
* @private
*/
shindig.container.GadgetHolder.prototype.getIframeUrl_ = function() {
- var iframeHost = this.viewInfo_['iframeHost'] || '';
- var uri = iframeHost + this.viewInfo_['iframePath'];
- uri = this.updateBooleanParam_(uri, 'debug');
- uri = this.updateBooleanParam_(uri, 'nocache');
- uri = this.updateBooleanParam_(uri, 'testmode');
- uri = this.updateUserPrefParams_(uri);
+ var uri = shindig.uri(this.gadgetInfo_['iframeUrl']);
+ uri.setQP('debug', this.renderParams_['debug'] ? '1' : '0');
+ uri.setQP('nocache', this.renderParams_['nocache'] ? '1' : '0');
+ uri.setQP('testmode', this.renderParams_['testmode'] ? '1' : '0');
+ uri.setQP('view', this.view_);
+ this.updateUserPrefParams_(uri);
// TODO: Share this base container logic
// TODO: Two SD base URIs - one for container, one for gadgets
// Need to add parent at end of query due to gadgets parsing bug
- uri = this.addQueryParam_(uri, 'parent', shindig.container.util.parseOrigin(
- document.location.href));
+ uri.setQP('parent', window.__CONTAINER_HOST);
// Remove existing social token if we have a new one
if (this.securityToken_) {
- var securityTokenMatch = uri.match(/([&#?])(st=[^&#]*)/);
- if (securityTokenMatch) {
- // TODO: Should we move the token to the hash?
- uri = uri.replace(securityTokenMatch[0], securityTokenMatch[1] +
- 'st=' + this.securityToken_);
- }
+ uri.setExistingP('st', this.securityToken_);
}
-
- uri = this.addHashParam_(uri, 'mid', String(this.siteId_));
+
+ uri.setFP('mid', String(this.siteId_));
if (this.hasGadgetParams_) {
var gadgetParamText = gadgets.json.stringify(this.gadgetParams_);
- uri = this.addHashParam_(uri, 'view-params',
- encodeURIComponent(gadgetParamText));
+ uri.setFP('view-params', gadgetParamText);
}
- return uri;
-};
-
-/**
- * Updates query params of interest.
- * @param {string} uri The URL to append query param to.
- * @param {string} param The query param to update uri with.
- * @return {string} The URL with param append to.
- * @private
- */
-shindig.container.GadgetHolder.prototype.updateBooleanParam_
- = function(uri, param) {
- if (this.renderParams_[param]) {
- uri = this.addQueryParam_(uri, param, "1");
- }
- return uri;
+ return uri.toString();
};
@@ -324,8 +297,8 @@ shindig.container.GadgetHolder.prototype
* Replace user prefs specified in url with only those specified. This will
* maintain each user prefs existence (or lack of), order (from left to right)
* and its appearance (in query params or fragment).
- * @param {string} uri The URL possibly containing user preferences parameters
- * prefixed by up_.
+ * @param {shindig.uri} uri The URL possibly containing user preferences
+ * parameters prefixed by up_.
* @return {string} The URL with up_ replaced by those specified in userPrefs.
* @private
*/
@@ -333,59 +306,12 @@ shindig.container.GadgetHolder.prototype
var userPrefs = this.renderParams_['userPrefs'];
if (userPrefs) {
for (var up in userPrefs) {
- // Maybe more efficient to have a pre-compiled regex that looks for
- // up_ANY_TEXT and match all instances.
- var re = new RegExp('([&#?])up_' + up + '[^&#]*');
- if (re) {
- var key = encodeURIComponent('up_' + up);
- var val = userPrefs[up];
- if (val instanceof Array) {
- val = val.join('|');
- }
- val = encodeURIComponent(val);
- uri = uri.replace(re, '$1' + key + '=' + val);
+ var upKey = 'up_' + up;
+ var upValue = userPrefs[up];
+ if (upValue instanceof Array) {
+ upValue = upValue.join('|');
}
+ uri.setExistingP(upKey, upValue);
}
}
- return uri;
-};
-
-
-/**
- * @return {string} The current RPC token.
- * @private
- */
-shindig.container.GadgetHolder.prototype.getRpcToken_ = function() {
- return this.viewInfo_['iframePath'].match(/rpctoken=([^&]+)/)[1];
-};
-
-
-/**
- * Adds a hash parameter to a URI.
- * @param {string} uri The URI.
- * @param {string} key The param key.
- * @param {string} value The param value.
- * @return {string} The new URI.
- * @private
- */
-shindig.container.GadgetHolder.prototype.addHashParam_ = function(
- uri, key, value) {
- return uri + ((uri.indexOf('#') == -1) ? '#' : '&') + key + '=' + value;
-};
-
-
-/**
- * Adds a query parameter to a URI.
- * @param {string} uri The URI.
- * @param {string} key The param key.
- * @param {string} value The param value.
- * @return {string} The new URI.
- * @private
- */
-shindig.container.GadgetHolder.prototype.addQueryParam_ = function(
- uri, key, value) {
- var hasQuery = uri.indexOf('?') != -1;
- var insertPos = (uri.indexOf('#') != -1) ? uri.indexOf('#') : uri.length;
- return uri.substring(0, insertPos) + (hasQuery ? '&' : '?') +
- key + '=' + value + uri.substring(insertPos);
};
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/container/init.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/container/init.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/container/init.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/container/init.js Tue Aug 10 11:32:26 2010
@@ -40,23 +40,23 @@
}
function initializeGlobalVars() {
- var scriptSrc = getLastScriptSrc();
- if (scriptSrc) {
- window.__API_HOST = shindig.container.util.parseOrigin(scriptSrc);
- window.__API_PREFIX_PATH = shindig.container.util.parsePrefixPath(
- scriptSrc, '/gadgets/js/container.js');
- window.__CONTAINER = shindig.container.util.getParamValue(
- scriptSrc, 'container');
- window.__CONTAINER_HOST = shindig.container.util.parseOrigin(
- document.location.href);
+ var scriptUri = getLastScriptUri();
+ if (scriptUri) {
+ window.__API_HOST = scriptUri.getOrigin();
+ window.__CONTAINER = scriptUri.getQP('container');
}
+ window.__CONTAINER_HOST = shindig.uri(document.location.href).getOrigin();
}
- function getLastScriptSrc() {
+ function getLastScriptUri() {
var scriptEls = document.getElementsByTagName('script');
- return (scriptEls.length > 0)
- ? scriptEls[scriptEls.length - 1].src
- : null;
+ var uri = null;
+ if (scriptEls.length > 0) {
+ uri = shindig.uri(scriptEls[scriptEls.length - 1].src)
+ // In case script URI is relative, resolve it against window.location
+ uri.resolve(shindig.uri(window.location));
+ }
+ return uri;
}
initializeConfig();
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/container/service.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/container/service.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/container/service.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/container/service.js Tue Aug 10 11:32:26 2010
@@ -35,13 +35,6 @@ shindig.container.Service = function(opt
*/
this.apiHost_ = String(shindig.container.util.getSafeJsonValue(config,
shindig.container.ServiceConfig.API_HOST, window.__API_HOST));
-
- /**
- * @type {string}
- */
- this.apiPrefixPath_ = String(shindig.container.util.getSafeJsonValue(config,
- shindig.container.ServiceConfig.API_PREFIX_PATH,
- window.__API_PREFIX_PATH));
/**
* @type {string}
@@ -174,7 +167,7 @@ shindig.container.Service.prototype.proc
* @private
*/
shindig.container.Service.prototype.initializeOsapi_ = function() {
- var endPoint = this.apiHost_ + this.apiPrefixPath_ + this.apiPath_;
+ var endPoint = this.apiHost_ + this.apiPath_;
var osapiServicesConfig = {};
osapiServicesConfig['gadgets.rpc'] = [ 'container.listMethods' ];
@@ -201,11 +194,9 @@ shindig.container.Service.prototype.init
* @enum {string}
*/
shindig.container.ServiceConfig = {};
-//Host to fetch gadget information, via XHR.
+// Host to fetch gadget information, via XHR.
shindig.container.ServiceConfig.API_HOST = 'apiHost';
-// Prefix to path to fetch gadget information, via XHR.
-shindig.container.ServiceConfig.API_PREFIX_PATH = 'apiPrefixPath';
-// Path (appears after API_PREFIX_PATH) to fetch gadget information, via XHR.
+// Path to fetch gadget information, via XHR.
shindig.container.ServiceConfig.API_PATH = 'apiPath';
// Toggle to render gadgets in the same domain.
shindig.container.ServiceConfig.SAME_DOMAIN = 'sameDomain';
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/container/util.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/container/util.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/container/util.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/container/util.js Tue Aug 10 11:32:26 2010
@@ -35,60 +35,6 @@ shindig.container.util = {};
/**
- * Extract protocol and domain of container page. Valid values:
- * http://www.cnn.com, chrome-extension://www.cnn.com
- * @param {string} uri The URL to extract path domain from.
- * @return {string} The protocol and domain of container page.
- */
-shindig.container.util.parseOrigin = function(uri) {
- var indexAtStartOfAuthority = uri.indexOf('//') + 2;
- var indexAtEndOfAuthority = uri.indexOf('/', indexAtStartOfAuthority);
- return uri.substring(0, indexAtEndOfAuthority);
-};
-
-
-/**
- * Extract prefix path of a URL, not including opt_postfixPath.
- * @param {string} uri The URL to extract path from.
- * @param {string=} opt_postfixPath The URL postfix to avoid extracting.
- * @return {string} The path in URL, before postfixPath.
- */
-shindig.container.util.parsePrefixPath = function(uri, opt_postfixPath) {
- var path = shindig.container.util.parsePath(uri);
- if (path && opt_postfixPath) {
- var endIndex = path.length - opt_postfixPath.length;
- if (path.lastIndexOf(opt_postfixPath) == endIndex) {
- return path.substring(0, endIndex);
- }
- }
- return path;
-};
-
-
-/**
- * Extract path of a URL.
- * @param {string} uri The URL to extract path from.
- * @return {string} The path in URL.
- */
-shindig.container.util.parsePath = function(uri) {
- var match = uri.match(new RegExp("//[^/]+(/[^?#]*)"));
- return match ? match[1] : null;
-};
-
-
-/**
- * Extract the parameter value in path with name paramName.
- * @param {string} path The path to extract parameter from.
- * @param {string} paramName The name of parameter to exact value from.
- * @return {string} The value of the parameter. Null otherwise.
- */
-shindig.container.util.getParamValue = function(path, paramName) {
- var match = path.match(new RegExp("[?&]" + paramName + "=([^&#]+)"));
- return match ? match[1] : null;
-};
-
-
-/**
* Return value of json at key, if valid. Otherwise, return defaultValue.
* @param {Object} json The JSON to look up key param from.
* @param {string} key Key in config.
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/core.config/config.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/core.config/config.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/core.config/config.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/core.config/config.js Tue Aug 10 11:32:26 2010
@@ -57,7 +57,7 @@
/** @namespace */
gadgets.config = function() {
- var components = [];
+ var components = {};
var configuration;
return {
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/core.config/feature.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/core.config/feature.xml?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/core.config/feature.xml (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/core.config/feature.xml Tue Aug 10 11:32:26 2010
@@ -21,8 +21,10 @@
<dependency>globals</dependency>
<gadget>
<script src="config.js"/>
+ <script src="configgadget.js"/>
</gadget>
<container>
<script src="config.js"/>
+ <script src="configcontainer.js"/>
</container>
</feature>
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/core.io/io.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/core.io/io.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/core.io/io.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/core.io/io.js Tue Aug 10 11:32:26 2010
@@ -132,9 +132,16 @@ gadgets.io = function() {
return;
}
var txt = xobj.responseText;
+
// remove unparseable cruft used to prevent cross-site script inclusion
- txt = txt.substr(UNPARSEABLE_CRUFT.length);
- // We are using eval directly here because the outer response comes from a
+ var offset = txt.indexOf(UNPARSEABLE_CRUFT) + UNPARSEABLE_CRUFT.length;
+
+ // If no cruft then just return without a callback - avoid JS errors
+ // TODO craft an error response?
+ if (offset < UNPARSEABLE_CRUFT.length) return;
+ txt = txt.substr(offset)
+
+ // We are using eval directly here because the outer response comes from a
// trusted source, and json parsing is slow in IE.
var data = eval("(" + txt + ")");
data = data[url];
@@ -507,7 +514,7 @@ gadgets.io = function() {
replace("%rawurl%", url).
replace("%refresh%", encodeURIComponent(refresh)).
replace("%gadget%", encodeURIComponent(urlParams.url)).
- replace("%container%", encodeURIComponent(urlParams.container || urlParams.synd)).
+ replace("%container%", encodeURIComponent(urlParams.container || urlParams.synd || "default")).
replace("%rewriteMime%", rewriteMimeParam);
if (ret.indexOf('//') == 0) {
ret = window.location.protocol + ret;
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/dynamic-height.util/dynamic-height-util.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/dynamic-height.util/dynamic-height-util.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/dynamic-height.util/dynamic-height-util.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/dynamic-height.util/dynamic-height-util.js Tue Aug 10 11:32:26 2010
@@ -34,6 +34,8 @@ gadgets.window = gadgets.window || {};
* @member gadgets.window
*/
gadgets.window.getViewportDimensions = function() {
+ var x = 0;
+ var y = 0;
if (self.innerHeight) {
// all except Explorer
x = self.innerWidth;
@@ -47,9 +49,6 @@ gadgets.window = gadgets.window || {};
// other Explorers
x = document.body.clientWidth;
y = document.body.clientHeight;
- } else {
- x = 0;
- y = 0;
}
return {width: x, height: y};
};
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/features.txt
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/features.txt?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/features.txt (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/features.txt Tue Aug 10 11:32:26 2010
@@ -37,6 +37,7 @@ features/dynamic-height.util/feature.xml
features/dynamic-height/feature.xml
features/flash/feature.xml
features/i18n/feature.xml
+features/jsondom/feature.xml
features/locked-domain/feature.xml
features/minimessage/feature.xml
features/oauthpopup/feature.xml
@@ -62,6 +63,9 @@ features/settitle/feature.xml
features/shindig.auth/feature.xml
features/shindig.container/feature.xml
features/shindig.container-1.0/feature.xml
+features/shindig.random/feature.xml
+features/shindig.uri/feature.xml
+features/shindig.uri.ext/feature.xml
features/shindig.xhrwrapper/feature.xml
features/skins/feature.xml
features/swfobject/feature.xml
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/minimessage/feature.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/minimessage/feature.xml?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/minimessage/feature.xml (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/minimessage/feature.xml Tue Aug 10 11:32:26 2010
@@ -19,6 +19,7 @@ specific language governing permissions
<feature>
<name>minimessage</name>
<dependency>globals</dependency>
+ <dependency>core.config</dependency>
<gadget>
<script src="minimessage.js"/>
<script src="taming.js"/>
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/minimessage/minimessage.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/minimessage/minimessage.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/minimessage/minimessage.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/minimessage/minimessage.js Tue Aug 10 11:32:26 2010
@@ -210,24 +210,11 @@ gadgets.MiniMessage.prototype.dismissMes
};
// Injects the default stylesheet for mini-messages.
-gadgets.MiniMessage.addCSS_([
- '.mmlib_table {',
- 'width: 100%;',
- 'font: bold 9px arial,sans-serif;',
- 'background-color: #fff4c2;',
- 'border-collapse: separate;',
- 'border-spacing: 0px;',
- 'padding: 1px 0px;',
- '}',
- '.mmlib_xlink {',
- 'font: normal 1.1em arial,sans-serif;',
- 'font-weight: bold;',
- 'color: #0000cc;',
- 'cursor: pointer;',
- '}'
-].join(''));
+gadgets.config.register("minimessage", {}, function (configuration) {
+ // Injects the default stylesheet for mini-messages
+ gadgets.MiniMessage.addCSS_( configuration.minimessage.css.join(''));
+});
// Alias for legacy code
-
var _IG_MiniMessage = gadgets.MiniMessage;
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/base.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/base.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/base.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/base.js Tue Aug 10 11:32:26 2010
@@ -140,7 +140,7 @@ os.compileTemplate = function(node, opt_
*/
os.compileTemplateString = function(src, opt_id, opt_container) {
src = opensocial.xmlutil.prepareXML(src, opt_container);
- var doc = opensocial.xmlutil.parseXML(src);
+ var doc = gadgets.jsondom.parse(src, opt_id);
return os.compileXMLDoc(doc, opt_id);
};
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/feature.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/feature.xml?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/feature.xml (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/feature.xml Tue Aug 10 11:32:26 2010
@@ -33,6 +33,7 @@ This should not be used in a production
<name>opensocial-templates</name>
<dependency>globals</dependency>
<dependency>opensocial-data-context</dependency>
+ <dependency>jsondom</dependency>
<dependency>security-token</dependency>
<dependency>xmlutil</dependency>
<gadget>
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/jsTemplate/util.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/jsTemplate/util.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/jsTemplate/util.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/jsTemplate/util.js Tue Aug 10 11:32:26 2010
@@ -180,23 +180,6 @@ function bindFully(object, method, var_a
};
}
-// Based on <http://www.w3.org/TR/2000/ REC-DOM-Level-2-Core-20001113/
-// core.html#ID-1950641247>.
-var DOM_ELEMENT_NODE = 1;
-var DOM_ATTRIBUTE_NODE = 2;
-var DOM_TEXT_NODE = 3;
-var DOM_CDATA_SECTION_NODE = 4;
-var DOM_ENTITY_REFERENCE_NODE = 5;
-var DOM_ENTITY_NODE = 6;
-var DOM_PROCESSING_INSTRUCTION_NODE = 7;
-var DOM_COMMENT_NODE = 8;
-var DOM_DOCUMENT_NODE = 9;
-var DOM_DOCUMENT_TYPE_NODE = 10;
-var DOM_DOCUMENT_FRAGMENT_NODE = 11;
-var DOM_NOTATION_NODE = 12;
-
-
-
function domGetElementById(document, id) {
return document.getElementById(id);
}
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/loader.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/loader.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/loader.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/opensocial-templates/loader.js Tue Aug 10 11:32:26 2010
@@ -145,7 +145,7 @@ os.Loader.loadUrls = function(urls, call
* Processes the XML markup of a Template Library.
*/
os.Loader.loadContent = function(xmlString, url) {
- var doc = opensocial.xmlutil.parseXML(xmlString);
+ var doc = gadgets.jsondom.parse(xmlString, url);
var templatesNode = doc.firstChild;
os.Loader.processTemplatesNode(templatesNode);
os.Loader.loadedUrls_[url] = true;
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/osapi/gadgetsrpctransport.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/osapi/gadgetsrpctransport.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/osapi/gadgetsrpctransport.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/osapi/gadgetsrpctransport.js Tue Aug 10 11:32:26 2010
@@ -95,7 +95,10 @@ if (gadgets && gadgets.rpc) { //Dont bin
osapi.container.listMethods({}).execute(function(response) {
if (!response.error) {
for (var i = 0; i < response.length; i++) {
- osapi._registerMethod(response[i], transport);
+ // do not rebind container.listMethods implementation
+ if (response[i] != "container.listMethods") {
+ osapi._registerMethod(response[i], transport);
+ }
}
}
// Notify completion
@@ -110,7 +113,7 @@ if (gadgets && gadgets.rpc) { //Dont bin
}
// Do not run this in container mode.
- if (gadgets.config) {
+ if (gadgets.config && gadgets.config.isGadget) {
gadgets.config.register("osapi.services", null, init);
}
})();
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/osapi/jsonrpctransport.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/osapi/jsonrpctransport.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/osapi/jsonrpctransport.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/osapi/jsonrpctransport.js Tue Aug 10 11:32:26 2010
@@ -88,7 +88,7 @@
}
}
- // Do not run this in container mode.
+ // We do run this in the container mode in the new common container
if (gadgets.config) {
gadgets.config.register("osapi.services", null, init);
}
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/osapi/osapi.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/osapi/osapi.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/osapi/osapi.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/osapi/osapi.js Tue Aug 10 11:32:26 2010
@@ -23,6 +23,13 @@
* @param {Object.<string,Object>} transport The transport used to execute a call for the method
*/
osapi._registerMethod = function (method, transport) {
+
+ // Skip registration of local newBatch implementation.
+ if (method == "newBatch") {
+ return;
+ }
+
+ // Lookup last method value.
var parts = method.split(".");
var last = osapi;
for (var i = 0; i < parts.length - 1; i++) {
@@ -67,8 +74,9 @@
}
if (last[parts[parts.length - 1]]) {
- gadgets.warn("Duplicate osapi method definition " + method);
+ gadgets.warn("Skipping duplicate osapi method definition " + method + " on transport " + transport.name);
+ } else {
+ last[parts[parts.length - 1]] = apiMethod;
}
- last[parts[parts.length - 1]] = apiMethod;
};
})();
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/shindig.container/feature.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/shindig.container/feature.xml?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/shindig.container/feature.xml (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/shindig.container/feature.xml Tue Aug 10 11:32:26 2010
@@ -31,5 +31,6 @@ A map of view names to view attributes.
<script src="util.js"/>
<script src="cookies.js"/>
<script src="shindig-container.js"/>
+ <script src="osapi.js"/>
</container>
</feature>
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/tabs/feature.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/tabs/feature.xml?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/tabs/feature.xml (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/tabs/feature.xml Tue Aug 10 11:32:26 2010
@@ -20,6 +20,7 @@ specific language governing permissions
<name>tabs</name>
<dependency>globals</dependency>
<dependency>core.prefs</dependency>
+ <dependency>core.config</dependency>
<gadget>
<script src="tabs.js"/>
<script src="taming.js"/>
Modified: shindig/branches/2.0.x/features/src/main/javascript/features/tabs/tabs.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/main/javascript/features/tabs/tabs.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/main/javascript/features/tabs/tabs.js (original)
+++ shindig/branches/2.0.x/features/src/main/javascript/features/tabs/tabs.js Tue Aug 10 11:32:26 2010
@@ -123,56 +123,15 @@ gadgets.TabSet = function(opt_moduleId,
this.mainContainer_ = this.createMainContainer_(opt_container);
this.tabTable_ = this.createTabTable_();
this.displayTabs(false);
- gadgets.TabSet.addCSS_([
- '.tablib_table {',
- 'width: 100%;',
- 'border-collapse: separate;',
- 'border-spacing: 0px;',
- 'empty-cells: show;',
- 'font-size: 11px;',
- 'text-align: center;',
- '}',
- '.tablib_emptyTab {',
- 'border-bottom: 1px solid #676767;',
- 'padding: 0px 1px;',
- '}',
- '.tablib_spacerTab {',
- 'border-bottom: 1px solid #676767;',
- 'padding: 0px 1px;',
- 'width: 1px;',
- '}',
- '.tablib_selected {',
- 'padding: 2px;',
- 'background-color: #ffffff;',
- 'border: 1px solid #676767;',
- 'border-bottom-width: 0px;',
- 'color: #3366cc;',
- 'font-weight: bold;',
- 'width: 80px;',
- 'cursor: default;',
- '}',
- '.tablib_unselected {',
- 'padding: 2px;',
- 'background-color: #dddddd;',
- 'border: 1px solid #aaaaaa;',
- 'border-bottom-color: #676767;',
- 'color: #000000;',
- 'width: 80px;',
- 'cursor: pointer;',
- '}',
- '.tablib_navContainer {',
- 'width: 10px;',
- 'vertical-align: middle;',
- '}',
- '.tablib_navContainer a:link, ',
- '.tablib_navContainer a:visited, ',
- '.tablib_navContainer a:hover {',
- 'color: #3366aa;',
- 'text-decoration: none;',
- '}'
- ].join(''));
+ // gadgets.TabSet.addCSS_([ ].join(''));
};
+gadgets.config.register("tabset", {}, function (configuration) {
+ // Injects the default stylesheet for tabs
+ gadgets.TabSet.addCSS_( configuration.tabs.css.join(''));
+});
+
+
/**
* Adds a new tab based on the name-value pairs specified in opt_params.
* @param {string} tabName Label of the tab to create.
Modified: shindig/branches/2.0.x/features/src/test/javascript/features/alltests.js
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/features/src/test/javascript/features/alltests.js?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/features/src/test/javascript/features/alltests.js (original)
+++ shindig/branches/2.0.x/features/src/test/javascript/features/alltests.js Tue Aug 10 11:32:26 2010
@@ -73,11 +73,11 @@ if (!this.JsUtil) {
eval(JsUtil.prototype.include(srcDir + '/osapi/jsonrpctransport.js'));
eval(JsUtil.prototype.include(srcDir + '/osapi/gadgetsrpctransport.js'));
eval(JsUtil.prototype.include(srcDir + '/osapi/peoplehelpers.js'));
+ eval(JsUtil.prototype.include(srcDir + '/shindig.uri/uri.js'));
eval(JsUtil.prototype.include(testToolsDir + "/JsUnit.js"));
eval(JsUtil.prototype.include(testSrcDir + "/core/authtest.js"));
eval(JsUtil.prototype.include(testSrcDir + "/core/config-test.js"));
eval(JsUtil.prototype.include(testSrcDir + "/core/prefstest.js"));
- eval(JsUtil.prototype.include(testSrcDir + "/core/utiltest.js"));
eval(JsUtil.prototype.include(testSrcDir + "/core.io/iotest.js"));
eval(JsUtil.prototype.include(testSrcDir + "/opensocial-base/jsonactivitytest.js"));
eval(JsUtil.prototype.include(testSrcDir + "/opensocial-reference/activitytest.js"));
@@ -93,6 +93,7 @@ if (!this.JsUtil) {
eval(JsUtil.prototype.include(testSrcDir + "/osapi/jsonrpctransporttest.js"));
eval(JsUtil.prototype.include(testSrcDir + "/views/urltemplatetest.js"));
eval(JsUtil.prototype.include(testSrcDir + "/xhrwrapper/xhrwrappertest.js"));
+ eval(JsUtil.prototype.include(testSrcDir + '/shindig.uri/uritest.js'));
}
function AllTests() {
Modified: shindig/branches/2.0.x/java/common/conf/shindig.properties
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/conf/shindig.properties?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/conf/shindig.properties (original)
+++ shindig/branches/2.0.x/java/common/conf/shindig.properties Tue Aug 10 11:32:26 2010
@@ -48,7 +48,7 @@ shindig.locked-domain.enabled=false
shindig.content-rewrite.only-allow-excludes=false
shindig.content-rewrite.include-urls=.*
shindig.content-rewrite.exclude-urls=
-shindig.content-rewrite.include-tags=link,script,embed,img,style
+shindig.content-rewrite.include-tags=body,embed,img,input,link,script,style
shindig.content-rewrite.expires=86400
shindig.content-rewrite.proxy-url=/gadgets/proxy?container=default&url=
shindig.content-rewrite.concat-url=/gadgets/concat?container=default&
@@ -141,3 +141,9 @@ org.apache.shindig.serviceExpirationDura
# both - return both fields for full compatibility
#
shindig.json-rpc.result-field=result
+
+# Remap "Internal server error"s received from the basicHttpFetcherProxy server to
+# "Bad Gateway error"s, so that it is clear to the user that the proxy server is
+# the one that threw the exception.
+shindig.accelerate.remapInternalServerError=true
+shindig.proxy.remapInternalServerError=true
Modified: shindig/branches/2.0.x/java/common/pom.xml
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/pom.xml?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/pom.xml (original)
+++ shindig/branches/2.0.x/java/common/pom.xml Tue Aug 10 11:32:26 2010
@@ -101,10 +101,9 @@
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-jmx</artifactId>
</dependency>
-
<dependency>
- <groupId>com.google.collections</groupId>
- <artifactId>google-collections</artifactId>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
@@ -135,6 +134,10 @@
<artifactId>oauth</artifactId>
</dependency>
<dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ </dependency>
+ <dependency>
<artifactId>commons-betwixt</artifactId>
<groupId>commons-betwixt</groupId>
</dependency>
@@ -151,9 +154,12 @@
<artifactId>juel-impl</artifactId>
</dependency>
<dependency>
- <groupId>de.odysseus.juel</groupId>
- <artifactId>juel-api</artifactId>
- <scope>provided</scope>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>el-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>jasper-el</artifactId>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/AuthenticationServletFilter.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/AuthenticationServletFilter.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/AuthenticationServletFilter.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/AuthenticationServletFilter.java Tue Aug 10 11:32:26 2010
@@ -17,6 +17,8 @@
*/
package org.apache.shindig.auth;
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import org.apache.shindig.common.servlet.InjectedFilter;
@@ -139,10 +141,8 @@ public class AuthenticationServletFilter
@Override
public ServletInputStream getInputStream() throws IOException {
- if (reader != null) {
- throw new IllegalStateException(
- "The methods getInputStream() and getReader() are mutually exclusive.");
- }
+ Preconditions.checkState(reader == null, "The methods getInputStream() and getReader() are mutually exclusive.");
+
if (stream == null) {
stream = new ServletInputStream() {
public int read() throws IOException {
@@ -155,14 +155,12 @@ public class AuthenticationServletFilter
@Override
public BufferedReader getReader() throws IOException {
- if (stream != null) {
- throw new IllegalStateException(
- "The methods getInputStream() and getReader() are mutually exclusive.");
- }
+ Preconditions.checkState(stream == null, "The methods getInputStream() and getReader() are mutually exclusive.");
+
if (reader == null) {
Charset charset = Charset.forName(getCharacterEncoding());
if (charset == null) {
- charset = CharsetUtil.UTF8;
+ charset = Charsets.UTF_8;
}
reader = new BufferedReader(new InputStreamReader(rawStream, charset));
}
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityToken.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityToken.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityToken.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/BlobCrypterSecurityToken.java Tue Aug 10 11:32:26 2010
@@ -70,7 +70,7 @@ public class BlobCrypterSecurityToken ex
}
/**
- * Decrypt and verify a token. Note this is not public, use BlobCrypterSecurityTokenDecoder
+ * Decrypt and verify a token. Note this is not public, use BlobCrypterSecurityTokenCodec
* instead.
*
* @param crypter crypter to use for decryption
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/SecurityToken.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/SecurityToken.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/SecurityToken.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/SecurityToken.java Tue Aug 10 11:32:26 2010
@@ -20,7 +20,7 @@ package org.apache.shindig.auth;
/**
* An abstract representation of a signing token.
- * Use in conjunction with @code SecurityTokenDecoder.
+ * Use in conjunction with @code SecurityTokenCodec.
*/
public interface SecurityToken {
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenException.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenException.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenException.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/SecurityTokenException.java Tue Aug 10 11:32:26 2010
@@ -19,7 +19,7 @@
package org.apache.shindig.auth;
/**
- * Exceptions thrown by SecurityTokenDecoder implementations.
+ * Exceptions thrown by SecurityTokenCodec implementations.
*/
public class SecurityTokenException extends Exception {
public SecurityTokenException(String message) {
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/UrlParameterAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/UrlParameterAuthenticationHandler.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/UrlParameterAuthenticationHandler.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/auth/UrlParameterAuthenticationHandler.java Tue Aug 10 11:32:26 2010
@@ -34,12 +34,12 @@ import javax.servlet.http.HttpServletReq
public class UrlParameterAuthenticationHandler implements AuthenticationHandler {
private static final String SECURITY_TOKEN_PARAM = "st";
- private final SecurityTokenDecoder securityTokenDecoder;
+ private final SecurityTokenCodec securityTokenCodec;
private static final Pattern COMMAWHITESPACE = Pattern.compile("\\s*,\\s*");
@Inject
- public UrlParameterAuthenticationHandler(SecurityTokenDecoder securityTokenDecoder) {
- this.securityTokenDecoder = securityTokenDecoder;
+ public UrlParameterAuthenticationHandler(SecurityTokenCodec securityTokenCodec) {
+ this.securityTokenCodec = securityTokenCodec;
}
public String getName() {
@@ -50,13 +50,13 @@ public class UrlParameterAuthenticationH
throws InvalidAuthenticationException {
Map<String, String> parameters = getMappedParameters(request);
try {
- if (parameters.get(SecurityTokenDecoder.SECURITY_TOKEN_NAME) == null) {
+ if (parameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME) == null) {
return null;
}
- return securityTokenDecoder.createToken(parameters);
+ return securityTokenCodec.createToken(parameters);
} catch (SecurityTokenException e) {
throw new InvalidAuthenticationException("Malformed security token " +
- parameters.get(SecurityTokenDecoder.SECURITY_TOKEN_NAME), e);
+ parameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME), e);
}
}
@@ -64,8 +64,8 @@ public class UrlParameterAuthenticationH
return null;
}
- protected SecurityTokenDecoder getSecurityTokenDecoder() {
- return this.securityTokenDecoder;
+ protected SecurityTokenCodec getSecurityTokenCodec() {
+ return this.securityTokenCodec;
}
// From OAuthMessage
@@ -102,8 +102,8 @@ public class UrlParameterAuthenticationH
}
}
- params.put(SecurityTokenDecoder.SECURITY_TOKEN_NAME, token);
- params.put(SecurityTokenDecoder.ACTIVE_URL_NAME, getActiveUrl(request));
+ params.put(SecurityTokenCodec.SECURITY_TOKEN_NAME, token);
+ params.put(SecurityTokenCodec.ACTIVE_URL_NAME, getActiveUrl(request));
return params;
}
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java Tue Aug 10 11:32:26 2010
@@ -19,6 +19,7 @@
package org.apache.shindig.common;
import org.apache.shindig.common.util.DateUtil;
+import org.apache.shindig.common.uri.Uri;
import org.joda.time.DateTime;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -31,6 +32,7 @@ import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
+import java.util.Locale;
import java.util.Map;
/**
@@ -150,6 +152,8 @@ public final class JsonSerializer {
buf.append(value.toString());
} else if (value instanceof CharSequence ||
value instanceof DateTime ||
+ value instanceof Locale ||
+ value instanceof Uri ||
value.getClass().isEnum()) {
// String-like Primitives
appendString(buf, value.toString());
@@ -284,7 +288,7 @@ public final class JsonSerializer {
*
* @throws IOException If {@link Appendable#append(char)} throws an exception.
*/
- public static void appendMap(Appendable buf, Map<String, ?> map) throws IOException {
+ public static void appendMap(final Appendable buf, final Map<String, ?> map) throws IOException {
buf.append('{');
boolean firstDone = false;
for (Map.Entry<String, ?> entry : map.entrySet()) {
@@ -295,7 +299,9 @@ public final class JsonSerializer {
} else {
firstDone = true;
}
- appendString(buf, entry.getKey());
+ Object key = entry.getKey();
+
+ appendString(buf, key.toString());
buf.append(':');
append(buf, value);
}
@@ -309,7 +315,7 @@ public final class JsonSerializer {
* @throws IOException If {@link Appendable#append(char)} throws an exception.
*/
public static void appendMultimap(Appendable buf, Multimap<String, Object> map) throws IOException {
- appendMap(buf, map.asMap());
+ appendMap(buf, map.asMap());
}
/**
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/PropertiesModule.java Tue Aug 10 11:32:26 2010
@@ -59,6 +59,7 @@ public class PropertiesModule extends Ab
Names.bindProperties(this.binder(), getProperties());
// This could be generalized to inject any system property...
this.binder().bindConstant().annotatedWith(Names.named("shindig.port")).to(getServerPort());
+ this.binder().bindConstant().annotatedWith(Names.named("shindig.host")).to(getServerHostname());
}
/**
@@ -72,6 +73,18 @@ public class PropertiesModule extends Ab
"8080";
}
+ /*
+ * Should return the hostname that the current server is running on. Useful for testing and working out of the box configs.
+ * Looks for a hostname in system properties "shindig.host", if not set uses fixed value of "localhost"
+ * @return a hostname
+ */
+
+ protected String getServerHostname() {
+ return System.getProperty("shindig.host") != null ? System.getProperty("shindig.host") :
+ System.getProperty("jetty.host") != null ? System.getProperty("jetty.host") :
+ "localhost";
+ }
+
protected static String getDefaultPropertiesPath() {
return DEFAULT_PROPERTIES;
}
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/crypto/BasicBlobCrypter.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/crypto/BasicBlobCrypter.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/crypto/BasicBlobCrypter.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/crypto/BasicBlobCrypter.java Tue Aug 10 11:32:26 2010
@@ -18,6 +18,7 @@
*/
package org.apache.shindig.common.crypto;
+import com.google.common.base.Charsets;
import com.google.common.collect.Maps;
import com.google.common.base.Preconditions;
@@ -79,7 +80,7 @@ public class BasicBlobCrypter implements
try {
FileInputStream openFile = new FileInputStream(keyfile);
reader = new BufferedReader(
- new InputStreamReader(openFile, CharsetUtil.UTF8));
+ new InputStreamReader(openFile, Charsets.UTF_8));
String line = reader.readLine();
if (line == null) {
throw new IOException("Unexpectedly empty keyfile:" + keyfile);
@@ -148,7 +149,7 @@ public class BasicBlobCrypter implements
byte[] encoded = serializeAndTimestamp(in);
byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded);
byte[] hmac = Crypto.hmacSha1(hmacKey, cipherText);
- byte[] b64 = Base64.encodeBase64(Crypto.concat(cipherText, hmac));
+ byte[] b64 = Base64.encodeBase64URLSafe(Crypto.concat(cipherText, hmac));
return new String(b64, UTF8);
} catch (UnsupportedEncodingException e) {
throw new BlobCrypterException(e);
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/servlet/HttpUtil.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/servlet/HttpUtil.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/servlet/HttpUtil.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/servlet/HttpUtil.java Tue Aug 10 11:32:26 2010
@@ -18,11 +18,17 @@
*/
package org.apache.shindig.common.servlet;
+import com.google.common.base.Preconditions;
+import org.apache.shindig.common.Pair;
+import org.apache.shindig.common.util.DateUtil;
import org.apache.shindig.common.util.TimeSource;
+import com.google.common.collect.Lists;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collection;
+import java.util.List;
import java.util.regex.Pattern;
/**
@@ -30,7 +36,7 @@ import java.util.regex.Pattern;
*/
public final class HttpUtil {
private HttpUtil() {}
-
+
// 1 year.
private static int defaultTtl = 60 * 60 * 24 * 365;
@@ -44,6 +50,10 @@ public final class HttpUtil {
HttpUtil.timeSource = timeSource;
}
+ public static TimeSource getTimeSource() {
+ return timeSource;
+ }
+
/**
* Sets HTTP headers that instruct the browser to cache content. Implementations should take care
* to use cache-busting techniques on the url if caching for a long period of time.
@@ -76,7 +86,7 @@ public final class HttpUtil {
public static void setCachingHeaders(HttpServletResponse response, int ttl) {
setCachingHeaders(response, ttl, false);
}
-
+
public static void setNoCache(HttpServletResponse response) {
setCachingHeaders(response, 0, false);
}
@@ -91,18 +101,28 @@ public final class HttpUtil {
* @param noProxy True if you don't want the response to be cacheable by proxies.
*/
public static void setCachingHeaders(HttpServletResponse response, int ttl, boolean noProxy) {
- response.setDateHeader("Expires", timeSource.currentTimeMillis() + (1000L * ttl));
-
- if (ttl == 0) {
- response.setHeader("Pragma", "no-cache");
- response.setHeader("Cache-Control", "no-cache");
+ for (Pair<String, String> header : getCachingHeadersToSet(ttl, noProxy)) {
+ response.setHeader(header.one, header.two);
+ }
+ }
+
+ public static List<Pair<String, String>> getCachingHeadersToSet(int ttl, boolean noProxy) {
+ List<Pair<String, String>> cachingHeaders = Lists.newArrayListWithExpectedSize(3);
+ cachingHeaders.add(Pair.of("Expires",
+ DateUtil.formatRfc1123Date(timeSource.currentTimeMillis() + (1000L * ttl))));
+
+ if (ttl <= 0) {
+ cachingHeaders.add(Pair.of("Pragma", "no-cache"));
+ cachingHeaders.add(Pair.of("Cache-Control", "no-cache"));
} else {
if (noProxy) {
- response.setHeader("Cache-Control", "private,max-age=" + Integer.toString(ttl));
+ cachingHeaders.add(Pair.of("Cache-Control", "private,max-age=" + Integer.toString(ttl)));
} else {
- response.setHeader("Cache-Control", "public,max-age=" + Integer.toString(ttl));
+ cachingHeaders.add(Pair.of("Cache-Control", "public,max-age=" + Integer.toString(ttl)));
}
}
+
+ return cachingHeaders;
}
public static int getDefaultTtl() {
@@ -122,14 +142,14 @@ public final class HttpUtil {
// Must be a GET
if (!"GET".equals(request.getMethod()))
return false;
-
+
// No callback specified
if (callback == null) return false;
- if (!GET_REQUEST_CALLBACK_PATTERN.matcher(callback).matches()) {
- throw new IllegalArgumentException("Wrong format for parameter 'callback' specified. Must match: " +
+ Preconditions.checkArgument(GET_REQUEST_CALLBACK_PATTERN.matcher(callback).matches(),
+ "Wrong format for parameter 'callback' specified. Must match: " +
GET_REQUEST_CALLBACK_PATTERN.toString());
- }
+
return true;
}
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedServlet.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedServlet.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedServlet.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedServlet.java Tue Aug 10 11:32:26 2010
@@ -18,6 +18,7 @@
*/
package org.apache.shindig.common.servlet;
+import com.google.common.base.Preconditions;
import com.google.inject.Injector;
import javax.servlet.ServletConfig;
@@ -32,21 +33,29 @@ import javax.servlet.http.HttpServlet;
*/
public abstract class InjectedServlet extends HttpServlet {
protected Injector injector;
+ protected transient boolean initialized = false;
- @Override public void init(ServletConfig config) throws ServletException {
- super.init(config);
- ServletContext context = config.getServletContext();
- injector = (Injector)
- context.getAttribute(GuiceServletContextListener.INJECTOR_ATTRIBUTE);
- if (injector == null) {
- injector = (Injector)
- context.getAttribute(GuiceServletContextListener.INJECTOR_NAME);
- if (injector == null) {
- throw new UnavailableException(
- "Guice Injector not found! Make sure you registered " +
- GuiceServletContextListener.class.getName() + " as a listener");
- }
- }
- injector.injectMembers(this);
- }
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ ServletContext context = config.getServletContext();
+ injector = (Injector) context.getAttribute(GuiceServletContextListener.INJECTOR_ATTRIBUTE);
+ if (injector == null) {
+ injector = (Injector) context.getAttribute(GuiceServletContextListener.INJECTOR_NAME);
+ if (injector == null) {
+ throw new UnavailableException(
+ "Guice Injector not found! Make sure you registered " +
+ GuiceServletContextListener.class.getName() + " as a listener");
+ }
+ }
+ injector.injectMembers(this);
+ initialized = true;
+ }
+
+ /**
+ * Called in each guice injected method to insure we are not initialized twice
+ */
+ protected void checkInitialized() {
+ Preconditions.checkState(!initialized, "Servlet already initialized");
+ }
}
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/uri/Uri.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/uri/Uri.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/uri/Uri.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/uri/Uri.java Tue Aug 10 11:32:26 2010
@@ -176,7 +176,7 @@ public final class Uri {
result = new UriBuilder(this);
result.setFragment(relative.fragment);
result.setQuery(relative.query);
- String relativePath = (relative.path == null) ? "" : relative.path;
+ String relativePath = Objects.firstNonNull(relative.path, "");;
if (relativePath.startsWith("/")) { //$NON-NLS-1$
result.setPath(relativePath);
} else {
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/util/CharsetUtil.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/util/CharsetUtil.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/util/CharsetUtil.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/common/util/CharsetUtil.java Tue Aug 10 11:32:26 2010
@@ -19,6 +19,7 @@
package org.apache.shindig.common.util;
+import com.google.common.base.Charsets;
import org.apache.commons.lang.ArrayUtils;
import java.nio.ByteBuffer;
@@ -31,18 +32,13 @@ public final class CharsetUtil {
private CharsetUtil() {}
/**
- * UTF-8 Charset.
- */
- public static final Charset UTF8 = Charset.forName("UTF-8");
-
- /**
* @return UTF-8 byte array for the input string.
*/
public static byte[] getUtf8Bytes(String s) {
if (s == null) {
return ArrayUtils.EMPTY_BYTE_ARRAY;
}
- ByteBuffer bb = UTF8.encode(s);
+ ByteBuffer bb = Charsets.UTF_8.encode(s);
return ArrayUtils.subarray(bb.array(), 0, bb.limit());
}
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/config/JsonContainerConfig.java Tue Aug 10 11:32:26 2010
@@ -48,6 +48,8 @@ import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.regex.Pattern;
+import javax.annotation.Nullable;
+
import javax.el.ELContext;
import javax.el.ELException;
import javax.el.ValueExpression;
@@ -78,7 +80,7 @@ public class JsonContainerConfig extends
// Used by tests
public JsonContainerConfig(String containers, Expressions expressions) throws ContainerConfigException {
- this(containers, "8080", expressions);
+ this(containers, "localhost", "8080", expressions);
}
/**
* Creates a new configuration from files.
@@ -86,13 +88,15 @@ public class JsonContainerConfig extends
*/
@Inject
public JsonContainerConfig(@Named("shindig.containers.default") String containers,
- @Named("shindig.port") String port,
+ @Nullable @Named("shindig.host") String host,
+ @Nullable @Named("shindig.port") String port,
Expressions expressions)
throws ContainerConfigException {
this.expressions = expressions;
JSONObject configJson = loadContainers(containers);
try {
configJson.getJSONObject(ContainerConfig.DEFAULT_CONTAINER).put("SERVER_PORT", port);
+ configJson.getJSONObject(ContainerConfig.DEFAULT_CONTAINER).put("SERVER_HOST", host);
} catch (JSONException e) {
// ignore
}
@@ -119,7 +123,7 @@ public class JsonContainerConfig extends
configEntry.setValue(value);
}
}
-
+
@Override
public Collection<String> getContainers() {
return Collections.unmodifiableSet(config.keySet());
@@ -389,7 +393,7 @@ public class JsonContainerConfig extends
public String toString() {
return JsonSerializer.serialize(config);
}
-
+
private Object evaluateAll(Object value) {
if (value instanceof CharSequence) {
return value.toString();
@@ -399,14 +403,14 @@ public class JsonContainerConfig extends
for (Map.Entry<?, ?> entry : mapValue.entrySet()) {
newMap.put(entry.getKey(), evaluateAll(entry.getValue()));
}
-
+
return newMap.build();
} else if (value instanceof List<?>) {
- ImmutableList.Builder<Object> newList = ImmutableList.builder();
+ ImmutableList.Builder<Object> newList = ImmutableList.builder();
for (Object entry : (List<?>) value) {
newList.add(evaluateAll(entry));
}
-
+
return newList.build();
} else {
return value;
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/expressions/Expressions.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/expressions/Expressions.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/expressions/Expressions.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/expressions/Expressions.java Tue Aug 10 11:32:26 2010
@@ -18,20 +18,23 @@
*/
package org.apache.shindig.expressions;
-import org.apache.shindig.common.cache.Cache;
import org.apache.shindig.common.cache.CacheProvider;
-import org.apache.shindig.common.cache.NullCache;
+import org.apache.shindig.expressions.juel.JuelProvider;
+import org.apache.shindig.expressions.juel.JuelTypeConverter;
import java.util.Map;
import javax.el.ArrayELResolver;
import javax.el.CompositeELResolver;
import javax.el.ELContext;
+import javax.el.ELException;
import javax.el.ELResolver;
import javax.el.ExpressionFactory;
import javax.el.FunctionMapper;
import javax.el.ListELResolver;
import javax.el.MapELResolver;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
import javax.el.ValueExpression;
import javax.el.VariableMapper;
@@ -39,43 +42,46 @@ import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-import de.odysseus.el.ExpressionFactoryImpl;
-import de.odysseus.el.misc.TypeConverter;
-import de.odysseus.el.tree.Tree;
-import de.odysseus.el.tree.TreeCache;
-import de.odysseus.el.tree.TreeStore;
-import de.odysseus.el.tree.impl.Builder;
/**
* A facade to the expressions functionality.
*/
@Singleton
public class Expressions {
- private static final String EXPRESSION_CACHE = "expressions";
private final ExpressionFactory factory;
private final ELContext parseContext;
private final ELResolver defaultELResolver;
private final Functions functions;
- private final TypeConverter typeConverter;
+ private final ELTypeConverter typeConverter;
/**
* Returns an instance of Expressions that doesn't require
* any functions or perform any caching. Use only for testing.
*/
+ public static Expressions forTesting(Functions functions) {
+ return new Expressions(functions, null, new JuelTypeConverter(), new JuelProvider());
+ }
+
+ /**
+ * Returns an instance of Expressions that doesn't require
+ * any functions or perform any caching. Use only for testing.
+ */
public static Expressions forTesting() {
- return new Expressions(null, null, new ShindigTypeConverter());
+ return new Expressions(null, null, new JuelTypeConverter(), new JuelProvider());
}
@Inject
public Expressions(Functions functions, CacheProvider cacheProvider,
- ShindigTypeConverter typeConverter) {
+ ELTypeConverter typeConverter, ExpressionProvider expProvider) {
this.functions = functions;
this.typeConverter = typeConverter;
- factory = newExpressionFactory(cacheProvider);
+ factory = newExpressionFactory(expProvider, cacheProvider);
// Stub context with no FunctionMapper, used only to parse expressions
parseContext = new Context(null);
defaultELResolver = createDefaultELResolver();
+
+
}
/**
@@ -100,40 +106,31 @@ public class Expressions {
* @return a ValueExpression corresponding to the expression
*/
public ValueExpression parse(String expression, Class<?> type) {
- return factory.createValueExpression(parseContext, expression, type);
+ boolean shouldConvert = typeConverter.isPostConvertible(type);
+ if (shouldConvert) {
+ return new ValueExpressionWrapper(factory.createValueExpression(
+ parseContext, expression, Object.class), typeConverter, type);
+ }
+ else {
+ return factory.createValueExpression(parseContext, expression, type);
+ }
}
public ValueExpression constant(Object value, Class<?> type) {
- return factory.createValueExpression(value, type);
- }
-
- /**
- * Create a JUEL cache of expressions.
- */
- private TreeCache createTreeCache(CacheProvider cacheProvider) {
- Cache<String, Tree> treeCache;
- if (cacheProvider == null) {
- treeCache = new NullCache<String, Tree>();
- } else {
- treeCache = cacheProvider.createCache(EXPRESSION_CACHE);
+ boolean shouldConvert = typeConverter.isPostConvertible(type);
+ if (shouldConvert) {
+ return new ValueExpressionWrapper(factory.createValueExpression(value, Object.class), typeConverter, type);
}
-
- final Cache<String, Tree> resolvedTreeCache = treeCache;
- return new TreeCache() {
- public Tree get(String expression) {
- return resolvedTreeCache.getElement(expression);
- }
-
- public void put(String expression, Tree tree) {
- resolvedTreeCache.addElement(expression, tree);
- }
- };
+ else {
+ return factory.createValueExpression(value, type);
+ }
+
}
- private ExpressionFactory newExpressionFactory(CacheProvider cacheProvider) {
- TreeStore store = new TreeStore(new Builder(), createTreeCache(cacheProvider));
- return new ExpressionFactoryImpl(store, typeConverter);
+ private ExpressionFactory newExpressionFactory(
+ ExpressionProvider expProvider, CacheProvider cacheProvider) {
+ return expProvider.newExpressionFactory(cacheProvider, typeConverter);
}
/**
@@ -200,4 +197,71 @@ public class Expressions {
}
}
+
+ private class ValueExpressionWrapper extends ValueExpression {
+
+ private static final long serialVersionUID = 2135607228206570229L;
+ private ValueExpression expression = null;
+ private Class<?> type = null;
+ private ELTypeConverter converter = null;
+
+ public ValueExpressionWrapper(ValueExpression ve,
+ ELTypeConverter converter, Class<?> type) {
+ expression = ve;
+ this.type = type;
+ this.converter = converter;
+ }
+
+ @Override
+ public Object getValue(ELContext context) throws NullPointerException,
+ PropertyNotFoundException, ELException {
+ return converter.convert(expression.getValue(context), type);
+ }
+
+ @Override
+ public Class<?> getExpectedType() {
+ return expression.getExpectedType();
+ }
+
+ @Override
+ public Class<?> getType(ELContext context) throws NullPointerException,
+ PropertyNotFoundException, ELException {
+ return expression.getType(context);
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context) throws NullPointerException,
+ PropertyNotFoundException, ELException {
+ return expression.isReadOnly(context);
+ }
+
+ @Override
+ public void setValue(ELContext context, Object value)
+ throws NullPointerException, PropertyNotFoundException,
+ PropertyNotWritableException, ELException {
+ expression.setValue(context, value);
+
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return expression.equals(obj);
+ }
+
+ @Override
+ public String getExpressionString() {
+ return expression.getExpressionString();
+ }
+
+ @Override
+ public int hashCode() {
+ return expression.hashCode();
+ }
+
+ @Override
+ public boolean isLiteralText() {
+ return expression.isLiteralText();
+ }
+ }
+
}
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/expressions/ShindigTypeConverter.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/expressions/ShindigTypeConverter.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/expressions/ShindigTypeConverter.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/expressions/ShindigTypeConverter.java Tue Aug 10 11:32:26 2010
@@ -28,19 +28,18 @@ import java.util.StringTokenizer;
import javax.el.ELException;
import com.google.common.collect.ImmutableList;
-import com.google.inject.Inject;
-import de.odysseus.el.misc.TypeConverter;
/**
* Custom type converter class that overrides the default EL coercion rules
* where necessary. Specifically, Booleans are handled differently,
* and JSONArray is supported.
*/
-public class ShindigTypeConverter implements TypeConverter {
-
- @Inject
- public ShindigTypeConverter() {
+public class ShindigTypeConverter implements ELTypeConverter {
+
+
+ public boolean isPostConvertible(Class<?> type) {
+ return false;
}
@SuppressWarnings("unchecked")
@@ -58,8 +57,8 @@ public class ShindigTypeConverter implem
return (T) coerceToIterable(obj);
}
- // Otherwise, use the default
- return TypeConverter.DEFAULT.convert(obj, type);
+ // Nothing more we can do.
+ return null;
}
/**
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/protocol/ApiServlet.java Tue Aug 10 11:32:26 2010
@@ -68,6 +68,7 @@ public abstract class ApiServlet extends
protected BeanJsonConverter jsonConverter;
protected BeanConverter xmlConverter;
protected BeanConverter atomConverter;
+ protected ContainerConfig containerConfig;
@Override
public void init(ServletConfig config) throws ServletException {
@@ -91,8 +92,6 @@ public abstract class ApiServlet extends
this.dispatcher = dispatcher;
}
- protected ContainerConfig containerConfig;
-
@Inject
public void setContainerConfig(ContainerConfig containerConfig) {
this.containerConfig = containerConfig;
@@ -154,9 +153,4 @@ public abstract class ApiServlet extends
}
servletResponse.setCharacterEncoding(DEFAULT_ENCODING);
}
-
- public void checkContentTypes(Set<String> allowedContentTypes,
- String contentType) throws ContentTypes.InvalidContentTypeException {
- ContentTypes.checkContentTypes(allowedContentTypes, contentType);
- }
}
Modified: shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java
URL: http://svn.apache.org/viewvc/shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java?rev=983934&r1=983933&r2=983934&view=diff
==============================================================================
--- shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java (original)
+++ shindig/branches/2.0.x/java/common/src/main/java/org/apache/shindig/protocol/BaseRequestItem.java Tue Aug 10 11:32:26 2010
@@ -17,6 +17,7 @@
*/
package org.apache.shindig.protocol;
+import com.google.common.base.Objects;
import org.apache.commons.lang.StringUtils;
import org.apache.shindig.auth.SecurityToken;
import org.apache.shindig.protocol.conversion.BeanConverter;
@@ -174,7 +175,7 @@ public class BaseRequestItem implements
public String getFilterValue() {
String filterValue = getParameter(FILTER_VALUE);
- return filterValue == null ? "" : filterValue;
+ return Objects.firstNonNull(filterValue, "");
}
public Set<String> getFields() {