Author: hoang_to
Date: 2011-01-17 00:02:04 -0500 (Mon, 17 Jan 2011)
New Revision: 5761
Added:
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInContainerConfigLoader.java
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInGuiceServletContextListener.java
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/containers/
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/containers/default/
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/containers/default/container.js
Removed:
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/WEB-INF/classes/
Modified:
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInJsonContainerConfig.java
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/WEB-INF/web.xml
Log:
GTNPORTAL-1712: Use ServletContext to load resource, hence escape the constraint on
location of container.js
Added:
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInContainerConfigLoader.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInContainerConfigLoader.java
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInContainerConfigLoader.java 2011-01-17
05:02:04 UTC (rev 5761)
@@ -0,0 +1,18 @@
+package org.exoplatform.portal.gadget.core;
+
+import javax.servlet.ServletContext;
+import java.io.IOException;
+
+/**
+ * A generic loader, used to load gadget server configuration files. We abuse the
ThreadLocal here, as there is no way
+ * to associate Guice components with Kernel 's configuration loader component
(ConfigurationManager)
+ *
+ * User: Minh Hoang TO - hoang281283(a)gmail.com
+ * Date: 1/12/11
+ * Time: 3:31 PM
+ */
+public abstract class GateInContainerConfigLoader {
+
+ public abstract String loadContentAsString(String path, String encoding) throws
IOException;
+
+}
Added:
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInGuiceServletContextListener.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInGuiceServletContextListener.java
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInGuiceServletContextListener.java 2011-01-17
05:02:04 UTC (rev 5761)
@@ -0,0 +1,69 @@
+package org.exoplatform.portal.gadget.core;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.shindig.common.servlet.GuiceServletContextListener;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ *
+ * Extending the GuiceServletContextListener to setup a
ThreadLocal<GateInContainerConfigLoader> variable wrapping
+ * the ServletContext. That makes the ServletContext accessible within the scope of
thread executing the method
+ * contextInitialized
+ *
+ *
+ * User: Minh Hoang TO - hoang281283(a)gmail.com
+ * Date: 1/12/11
+ * Time: 3:50 PM
+ */
+public class GateInGuiceServletContextListener extends GuiceServletContextListener {
+
+ private static ThreadLocal<GateInContainerConfigLoader> currentLoader = new
ThreadLocal<GateInContainerConfigLoader>();
+
+ @Override
+ public void contextInitialized(ServletContextEvent event) {
+
+ final ServletContext scontext = event.getServletContext();
+
+ GateInContainerConfigLoader loader = new GateInContainerConfigLoader() {
+ @Override
+ public String loadContentAsString(String path, String encoding) throws
IOException{
+
+ InputStream is = scontext.getResourceAsStream(path);
+
+ if(is == null)
+ {
+ throw new NullPointerException("There is no file specified by path :
" + path);
+ }
+ return IOUtils.toString(is, encoding);
+ }
+ };
+
+ //Setup the threadlocal loader
+ currentLoader.set(loader);
+
+ try
+ {
+ //Setup the Guice objects, the threadlocal loader is accessible for the moment
+ super.contextInitialized(event);
+ }
+ catch(Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ finally
+ {
+ //Reset the threadlocal loader to null
+ currentLoader.set(null);
+ }
+
+ }
+
+ public static GateInContainerConfigLoader getCurrentLoader()
+ {
+ return currentLoader.get();
+ }
+}
Modified:
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInJsonContainerConfig.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInJsonContainerConfig.java 2011-01-17
04:55:09 UTC (rev 5760)
+++
portal/branches/branch-GTNPORTAL-1745/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GateInJsonContainerConfig.java 2011-01-17
05:02:04 UTC (rev 5761)
@@ -239,9 +239,12 @@
try {
for (String entry : files) {
LOG.info("Reading container config: " + entry);
- final ClassLoader contextCl = Thread.currentThread().getContextClassLoader();
- InputStream resourceInputStream = contextCl.getResourceAsStream(entry);
- String content = IOUtils.toString(resourceInputStream, "UTF-8");
+ //final ClassLoader contextCl = Thread.currentThread().getContextClassLoader();
+ //InputStream resourceInputStream = contextCl.getResourceAsStream(entry);
+ //String content = IOUtils.toString(resourceInputStream, "UTF-8");
+
+ GateInContainerConfigLoader currentLoader =
GateInGuiceServletContextListener.getCurrentLoader();
+ String content = currentLoader.loadContentAsString(entry, "UTF-8");
loadFromString(content, all);
}
} catch (IOException e) {
Modified:
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/WEB-INF/web.xml
===================================================================
---
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/WEB-INF/web.xml 2011-01-17
04:55:09 UTC (rev 5760)
+++
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/WEB-INF/web.xml 2011-01-17
05:02:04 UTC (rev 5761)
@@ -79,7 +79,8 @@
</filter-mapping>
<listener>
-
<listener-class>org.apache.shindig.common.servlet.GuiceServletContextListener</listener-class>
+
<!--<listener-class>org.apache.shindig.common.servlet.GuiceServletContextListener</listener-class>-->
+
<listener-class>org.exoplatform.portal.gadget.core.GateInGuiceServletContextListener</listener-class>
</listener>
<!-- Render a Gadget -->
Added:
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/containers/default/container.js
===================================================================
---
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/containers/default/container.js
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1745/gadgets/server/src/main/webapp/containers/default/container.js 2011-01-17
05:02:04 UTC (rev 5761)
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Default container configuration. To change the configuration, you have two options:
+//
+// A. If you run the Java server: Create your own "myContainer.js" file and
+// modify the value in web.xml.
+//
+// B. If you run the PHP server: Create a myContainer.js, copy the contents of
container.js to it,
+// change
+// {"gadgets.container" : ["default"],
+// to
+// {"gadgets.container" : ["myContainer"],
+// And make your changes that you need to myContainer.js.
+// Just make sure on the iframe URL you specify &container=myContainer
+// for it to use that config.
+//
+// All configurations will automatically inherit values from this
+// config, so you only need to provide configuration for items
+// that you require explicit special casing for.
+//
+// Please namespace your attributes using the same conventions
+// as you would for javascript objects, e.g. gadgets.features
+// rather than "features".
+
+// NOTE: Please _don't_ leave trailing commas because the php json parser
+// errors out on this.
+
+// Container must be an array; this allows multiple containers
+// to share configuration.
+{"gadgets.container" : ["default"],
+
+// Set of regular expressions to validate the parent parameter. This is
+// necessary to support situations where you want a single container to support
+// multiple possible host names (such as for localized domains, such as
+// <
language>.example.org. If left as null, the parent parameter will be
+// ignored; otherwise, any requests that do not include a parent
+// value matching this set will return a 404 error.
+"gadgets.parent" : null,
+
+// Should all gadgets be forced on to a locked domain?
+"gadgets.lockedDomainRequired" : false,
+
+// DNS domain on which gadgets should render.
+"gadgets.lockedDomainSuffix" : "-a.example.com:8080",
+
+// Various urls generated throughout the code base.
+// iframeBaseUri will automatically have the host inserted
+// if locked domain is enabled and the implementation supports it.
+// query parameters will be added.
+"gadgets.iframeBaseUri" : "/eXoGadgetServer/gadgets/ifr",
+
+// jsUriTemplate will have %host% and %js% substituted.
+// No locked domain special cases, but jsUriTemplate must
+// never conflict with a lockedDomainSuffix.
+"gadgets.jsUriTemplate" :
"http://%host%/eXoGadgetServer/gadgets/js/%js%",
+
+// Callback URL. Scheme relative URL for easy switch between https/http.
+"gadgets.oauthGadgetCallbackTemplate" :
"//%host%/eXoGadgetServer/gadgets/oauthcallback",
+
+// Use an insecure security token by default
+"gadgets.securityTokenType" : "secure",
+"gadgets.securityTokenKeyFile" : "key.txt",
+
+"gadgets.signingKeyFile" : "oauthkey.pem",
+"gadgets.signingKeyName" : "mytestkey",
+
+"gadgets.signedFetchDomain" : "eXo",
+// Config param to load Opensocial data for social
+// preloads in data pipelining. %host% will be
+// substituted with the current host.
+"gadgets.osDataUri" : "http://%host%/social/rpc",
+
+// Uncomment these to switch to a secure version
+//
+//"gadgets.securityTokenType" : "secure",
+//"gadgets.securityTokenKeyFile" : "/path/to/key/file.txt",
+
+"gadgets.content-rewrite" : {
+ "include-urls": ".*",
+ "exclude-urls": "",
+ "include-tags": ["link", "script", "embed",
"img", "style"],
+ "expires": "86400",
+ "proxy-url": "/eXoGadgetServer/gadgets/proxy?url=",
+ "concat-url": "/eXoGadgetServer/gadgets/concat?"
+},
+
+// This config data will be passed down to javascript. Please
+// configure your object using the feature name rather than
+// the javascript name.
+
+// Only configuration for required features will be used.
+// See individual feature.xml files for configuration details.
+"gadgets.features" : {
+ "core.io" : {
+ // Note: /proxy is an open proxy. Be careful how you expose this!
+ "proxyUrl" :
"http://%host%/eXoGadgetServer/gadgets/proxy?refresh=%refresh%&url=%url%",
+ "jsonProxyUrl" :
"http://%host%/eXoGadgetServer/gadgets/makeRequest"
+ },
+ "views" : {
+ "home" : {
+ "isOnlyVisible" : false,
+ "urlTemplate" :
"http://%host%/eXoGadgetServer/gadgets/home?{var}",
+ "aliases": ["DASHBOARD", "default"]
+ },
+ "canvas" : {
+ "isOnlyVisible" : true,
+ "urlTemplate" :
"http://%host%/eXoGadgetServer/gadgets/canvas?{var}",
+ "aliases" : ["FULL_PAGE"]
+ }
+ },
+ "rpc" : {
+ // Path to the relay file. Automatically appended to the parent
+ /// parameter if it passes input validation and is not null.
+ // This should never be on the same host in a production environment!
+ // Only use this for TESTING!
+ "parentRelayUrl" :
"/eXoGadgetServer/gadgets/files/container/rpc_relay.html",
+
+ // If true, this will use the legacy ifpc wire format when making rpc
+ // requests.
+ "useLegacyProtocol" : false
+ },
+ // Skin defaults
+ "skins" : {
+ "properties" : {
+ "BG_COLOR": "",
+ "BG_IMAGE": "",
+ "BG_POSITION": "",
+ "BG_REPEAT": "",
+ "FONT_COLOR": "",
+ "ANCHOR_COLOR": ""
+ }
+ },
+ "opensocial-0.8" : {
+ // Path to fetch opensocial data from
+ // Must be on the same domain as the gadget rendering server
+ "path" : "http://%host%/social",
+ "domain" : "shindig",
+ "enableCaja" : false,
+ "supportedFields" : {
+ "person" : ["id", {"name" : ["familyName",
"givenName", "unstructured"]}, "thumbnailUrl",
"profileUrl"],
+ "activity" : ["id", "title"]
+ }
+ },
+ "osapi.services" : {
+ // Specifying a binding to "container.listMethods" instructs osapi to
dynamicaly introspect the services
+ // provided by the container and delay the gadget onLoad handler until that
introspection is
+ // complete.
+ // Alternatively a container can directly configure services here rather than having
them
+ // introspected. Simply list out the available servies and omit
"container.listMethods" to
+ // avoid the initialization delay caused by gadgets.rpc
+ // E.g. "gadgets.rpc" : ["activities.requestCreate",
"messages.requestSend", "requestShareApp",
"requestPermission"]
+ "gadgets.rpc" : ["container.listMethods"]
+ },
+// "osapi" : {
+// // The endpoints to query for available JSONRPC/REST services
+// "endPoints" : [ "http://%host%/social/rpc",
"http://%host%/gadgets/api/rpc" ]
+// },
+ "osml": {
+ // OSML library resource. Can be set to null or the empty string to disable OSML
+ // for a container.
+ "library": ""
+ }
+}}