Author: mwringe
Date: 2011-08-24 09:58:45 -0400 (Wed, 24 Aug 2011)
New Revision: 7208
Modified:
epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
Log:
JBEPP-1111, JBEPP-938: Commit missing patch from Shindig 2 update (r7166,r7167)
Modified:
epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java 2011-08-24
12:11:40 UTC (rev 7207)
+++
epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java 2011-08-24
13:58:45 UTC (rev 7208)
@@ -25,6 +25,7 @@
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.webui.application.GadgetUtil;
+import org.exoplatform.portal.webui.application.UIGadget;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.application.WebuiApplication;
import org.exoplatform.webui.application.WebuiRequestContext;
@@ -35,6 +36,7 @@
import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -146,19 +148,18 @@
public String getMetadata(String url)
{
- String metadata_ = GadgetUtil.fetchGagdetMetadata(url);
+ JSONObject metadata_ = null;
try
{
- JSONObject jsonObj = new JSONObject(metadata_);
- JSONObject obj = jsonObj.getJSONArray("gadgets").getJSONObject(0);
+ String strMetadata = GadgetUtil.fetchGagdetRpcMetadata(url);
+ metadata_ = new
JSONArray(strMetadata).getJSONObject(0).getJSONObject(UIGadget.RPC_RESULT).getJSONObject(url);
String token = GadgetUtil.createToken(url, new Long(hashCode()));
- obj.put("secureToken", token);
- metadata_ = jsonObj.toString();
+ metadata_.put("secureToken", token);
}
catch (JSONException e)
{
e.printStackTrace(); //To change body of catch statement use File | Settings |
File Templates.
}
- return metadata_;
+ return metadata_.toString();
}
}
Modified:
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js 2011-08-24
12:11:40 UTC (rev 7207)
+++
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/gadget/Gadgets.js 2011-08-24
13:58:45 UTC (rev 7208)
@@ -218,7 +218,7 @@
value) {
var id = gadgets.container.gadgetService.getGadgetIdFromModuleId(this.f);
var gadget = gadgets.container.getGadget(id);
- var new_prefs = {};
+ var new_prefs = gadget.getUserPrefs() || {};
for (var i = 1, j = arguments.length; i < j; i += 2) {
new_prefs[arguments[i]] = arguments[i + 1];
}
@@ -631,7 +631,7 @@
var j = 0;
for (var att in prefs) {
//TODO: dang.tung not append when using list
- type = prefs[att].type;
+ type = prefs[att].dataType.toLowerCase();
if(type == "list"|| type == "hidden") continue;
// end
var attEl = document.createElement("div");
Modified:
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js 2011-08-24
12:11:40 UTC (rev 7207)
+++
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js 2011-08-24
13:58:45 UTC (rev 7208)
@@ -52,11 +52,11 @@
var gadget;
if (metadata != null) {
// Check if gadget's height is not set and current view is canvas. By
default, gadget's height is 800px
- if(metadata.gadgets[0].height == 0 && view == 'canvas') {
- metadata.gadgets[0].height = "800px";
+ if(metadata.modulePrefs.height == 0 && view == 'canvas') {
+ metadata.modulePrefs.height = "800px";
}
- gadget = gadgets.container.createGadget({specUrl: url,height:
metadata.gadgets[0].height, secureToken: metadata.gadgets[0].secureToken, view: view});
- gadget.metadata = metadata.gadgets[0];
+ gadget = gadgets.container.createGadget({specUrl: url,height:
metadata.modulePrefs.height, secureToken: metadata.secureToken, view: view});
+ gadget.metadata = metadata;
} else {
gadget = gadgets.container.createGadget({specUrl: url});
}
@@ -101,7 +101,7 @@
gadgetControl.style.display = "block";
var gadgetTitle = eXo.core.DOMUtil.findFirstDescendantByClass(gadgetControl,
"div", "GadgetTitle") ;
gadgetTitle.style.display = "block";
- if (metadata && metadata.title != null &&
metadata.title.length > 0) gadgetTitle.innerHTML = metadata.title;
+ if (metadata && metadata.modulePrefs.title != null &&
metadata.modulePrefs.title.length > 0) gadgetTitle.innerHTML =
metadata.modulePrefs.title;
}
if (inDesktop) {
Modified:
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl 2011-08-24
12:11:40 UTC (rev 7207)
+++
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl 2011-08-24
13:58:45 UTC (rev 7208)
@@ -6,7 +6,7 @@
JavascriptManager jsmanager = rcontext.getJavascriptManager();
def hostName = GadgetUtil.getRelGadgetServerUrl();
def url = uicomponent.getUrl();
- def metadata = uicomponent.getMetadata();
+ def metadata = uicomponent.getRpcMetadata();
def posX = uicomponent.getProperties().getIntValue("locationX") +
"px";
def posY = uicomponent.getProperties().getIntValue("locationY") +
"px";
def zIndex = uicomponent.getProperties().getIntValue("zIndex");
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java 2011-08-24
12:11:40 UTC (rev 7207)
+++
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java 2011-08-24
13:58:45 UTC (rev 7208)
@@ -28,6 +28,7 @@
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.gadget.core.SecurityTokenGenerator;
import org.exoplatform.portal.webui.util.Util;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -73,6 +74,7 @@
*
* @return the string represents metadata of gadget application
*/
+ @Deprecated
public static String fetchGagdetMetadata(String urlStr)
{
String result = null;
@@ -106,6 +108,46 @@
return result;
}
+ /**
+ * Fetchs Metatada of gadget application, create the connection to shindig
+ * server to get the metadata TODO cache the informations for better
+ * performance
+ *
+ * @return the string represents metadata of gadget application
+ */
+ public static String fetchGagdetRpcMetadata(String urlStr)
+ {
+ String result = null;
+
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ GadgetRegistryService gadgetService =
+
(GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class);
+ try
+ {
+ String data = "[{method:\"gadgets.metadata\",
id:\"test\", params: {ids:[\""
+ + urlStr + "\"], container:\"default\",
language:\""
+ + gadgetService.getLanguage() + "\", country:\"" +
gadgetService.getCountry() + "\", view:\"home\"}}]";
+
+ // Send data
+ String gadgetServer = getGadgetServerUrl();
+ URL url = new URL(gadgetServer + (gadgetServer.endsWith("/") ?
"" : "/") + "api/rpc");
+ URLConnection conn = url.openConnection();
+ conn.setRequestProperty("Content-Type",
"application/json");
+ conn.setDoOutput(true);
+ OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
+ wr.write(data);
+ wr.flush();
+ // Get the response
+ result = IOUtils.toString(conn.getInputStream(), "UTF-8");
+ wr.close();
+ }
+ catch (IOException ioexc)
+ {
+ ioexc.printStackTrace();
+ return "{}";
+ }
+ return result;
+ }
public static String createToken(String gadgetURL, Long moduleId)
{
SecurityTokenGenerator tokenGenerator =
@@ -125,9 +167,9 @@
static public Map<String, String> getMapMetadata(String url) throws
JSONException
{
Map<String, String> mapMetaData = new HashMap<String, String>();
- String metadata = fetchGagdetMetadata(url);
+ String metadata = fetchGagdetRpcMetadata(url);
metadata = metadata.substring(metadata.indexOf("[") + 1,
metadata.lastIndexOf("]"));
- JSONObject jsonObj = new JSONObject(metadata);
+ JSONObject jsonObj = new
JSONObject(metadata).getJSONObject(UIGadget.RPC_RESULT).getJSONObject(url).getJSONObject(UIGadget.METADATA_MODULEPREFS);
Iterator<String> iter = jsonObj.keys();
while (iter.hasNext())
{
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2011-08-24
12:11:40 UTC (rev 7207)
+++
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2011-08-24
13:58:45 UTC (rev 7208)
@@ -94,8 +94,12 @@
public static final String METADATA_USERPREFS = "userPrefs";
- public static final String METADATA_USERPREFS_TYPE = "type";
+ public static final String METADATA_MODULEPREFS = "modulePrefs";
+ public static final String RPC_RESULT = "result";
+
+ public static final String METADATA_USERPREFS_TYPE = "dataType";
+
public static final String METADATA_USERPREFS_TYPE_HIDDEN = "hidden";
public static final String METADATA_USERPREFS_TYPE_LIST = "list";
@@ -207,13 +211,14 @@
this.properties_ = properties;
}
+ @Deprecated
public String getMetadata()
{
try
{
if (metadata_ == null)
{
- String strMetadata = GadgetUtil.fetchGagdetMetadata(getUrl());
+ String strMetadata = GadgetUtil.fetchGagdetRpcMetadata(getUrl());
metadata_ = new JSONObject(strMetadata);
}
JSONObject obj = metadata_.getJSONArray(METADATA_GADGETS).getJSONObject(0);
@@ -226,6 +231,25 @@
return null;
}
}
+ public String getRpcMetadata()
+ {
+ try
+ {
+ if (metadata_ == null)
+ {
+ String gadgetUrl = getUrl();
+ String strMetadata = GadgetUtil.fetchGagdetRpcMetadata(gadgetUrl);
+ metadata_ = new
JSONArray(strMetadata).getJSONObject(0).getJSONObject(UIGadget.RPC_RESULT).getJSONObject(gadgetUrl);
+ }
+ String token = GadgetUtil.createToken(this.getUrl(), new Random().nextLong());
+ metadata_.put("secureToken", token);
+ return metadata_.toString();
+ }
+ catch (JSONException e)
+ {
+ return null;
+ }
+ }
/**
* Check if content of gadget has <UserPref>? (Content is parsed from gadget
specification in .xml file)
* @return boolean
@@ -236,8 +260,7 @@
{
if(metadata_ != null)
{
- JSONObject obj = metadata_.getJSONArray(METADATA_GADGETS).getJSONObject(0);
- JSONObject userPrefs = obj.getJSONObject(METADATA_USERPREFS);
+ JSONObject userPrefs = metadata_.getJSONObject(METADATA_USERPREFS);
JSONArray names = userPrefs.names();
int count = names.length();
if(count > 0)