Author: hfnukal
Date: 2012-06-07 02:52:22 -0400 (Thu, 07 Jun 2012)
New Revision: 8714
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/skin/DefaultSkin/portal/webui/component/view/UIGadget/Stylesheet.css
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties
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/UIGadget.java
Log:
Bug 824860 - Error while rendering doodle gadget when source is dead
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 2012-06-05
14:03:10 UTC (rev 8713)
+++
epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java 2012-06-07
06:52:22 UTC (rev 8714)
@@ -64,6 +64,10 @@
/** User pref. */
private String userPref;
+ private JSONObject metadata;
+
+ private String url;
+
public UIGadgetPortlet() throws Exception
{
addChild(UIGadgetViewMode.class, null, null);
@@ -102,14 +106,26 @@
PortletPreferences prefs = req.getPreferences();
userPref = prefs.getValue("userPref", null);
+ url = getUrl(prefs);
+ metadata = fetchMetadata(url);
+
super.processRender(app, context);
}
public String getUrl()
{
- PortletRequestContext pcontext =
(PortletRequestContext)WebuiRequestContext.getCurrentInstance();
- PortletPreferences pref = pcontext.getRequest().getPreferences();
- String urlPref = pref.getValue("url",
"http://www.google.com/ig/modules/horoscope.xml");
+ return url;
+ }
+
+ public boolean isLossData()
+ {
+ return (url == null || metadata.has("error"));
+ }
+
+ private String getUrl(PortletPreferences pref)
+ {
+ String url = null;
+ String urlPref = pref.getValue("url", "local://Calendar");
if (urlPref.startsWith(LOCAL_STRING))
{
try
@@ -121,7 +137,7 @@
Gadget gadget = gadgetService.getGadget(gadgetName);
if (gadget != null)
{
- return GadgetUtil.reproduceUrl(gadget.getUrl(), gadget.isLocal());
+ url = GadgetUtil.reproduceUrl(gadget.getUrl(), gadget.isLocal());
}
else
{
@@ -129,7 +145,6 @@
{
log.warn("The local gadget '" + gadgetName + "'
was not found, nothing rendered");
}
- return null;
}
}
catch (Exception e)
@@ -137,37 +152,50 @@
log.warn("Failure retrieving gadget from url!");
}
}
- return urlPref;
- }
-
- public String getMetadata()
- {
- String url = getUrl();
+ else
+ {
+ url = urlPref;
+ }
+
if (url == null)
{
WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
UIApplication uiApplication = context.getUIApplication();
uiApplication.addMessage(new
ApplicationMessage("UIGadgetPortlet.msg.url-invalid", null));
}
+
+ return url;
+
+ }
- return getMetadata(url);
+ public String getMetadata()
+ {
+ if (metadata == null)
+ {
+ PortletRequestContext pcontext =
(PortletRequestContext)WebuiRequestContext.getCurrentInstance();
+ PortletPreferences pref = pcontext.getRequest().getPreferences();
+ url = getUrl(pref);
+ metadata = fetchMetadata(url);
+ }
+
+ return metadata.toString();
}
- public String getMetadata(String url)
+ private JSONObject fetchMetadata(String url)
{
JSONObject metadata_ = null;
try
{
String strMetadata = GadgetUtil.fetchGagdetRpcMetadata(url);
- metadata_ = new
JSONArray(strMetadata).getJSONObject(0).getJSONObject(UIGadget.RPC_RESULT).getJSONObject(url);
+ metadata_ = new
JSONArray(strMetadata).getJSONObject(0).getJSONObject(UIGadget.RPC_RESULT).getJSONObject(url);
String token = GadgetUtil.createToken(url, new Long(hashCode()));
metadata_.put("secureToken", token);
}
catch (JSONException e)
{
- e.printStackTrace(); //To change body of catch statement use File | Settings |
File Templates.
+ log.warn("Unable to retrieve metadata of url: " + url, e);
}
- return metadata_.toString();
+ return metadata_;
}
static public class SaveUserPrefActionListener extends
EventListener<UIGadgetPortlet>
Modified:
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/skin/DefaultSkin/portal/webui/component/view/UIGadget/Stylesheet.css
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/skin/DefaultSkin/portal/webui/component/view/UIGadget/Stylesheet.css 2012-06-05
14:03:10 UTC (rev 8713)
+++
epp/portal/branches/EPP_5_2_Branch/web/eXoResources/src/main/webapp/skin/DefaultSkin/portal/webui/component/view/UIGadget/Stylesheet.css 2012-06-07
06:52:22 UTC (rev 8714)
@@ -1,4 +1,3 @@
-
/*************************************** UIGadget
**************************************/
.UIWindow .UIGadgetPortlet {
@@ -81,6 +80,7 @@
border: 1px solid #c3c3c3;
border-top: none;
padding: 3px;
+ word-wrap: break-word;
}
.UIGadget iframe {
Modified:
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties 2012-06-05
14:03:10 UTC (rev 8713)
+++
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties 2012-06-07
06:52:22 UTC (rev 8714)
@@ -1268,6 +1268,7 @@
UIGadget.tooltip.Unmaximize=Restaurer Again
UIGadget.tooltip.editGadget=Editer la Gadget
UIGadget.tooltip.deleteGadget=Supprimer la Gadget
+UIGadget.error.NotAvailable=Erreurs lors de laïcs fichier de spécification de gadget
UIUserToolBarDashboard.page.Tab_Default=Cliquez pour renommer
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 2012-06-05
14:03:10 UTC (rev 8713)
+++
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl 2012-06-07
06:52:22 UTC (rev 8714)
@@ -11,23 +11,21 @@
def posY = uicomponent.getProperties().getIntValue("locationY") +
"px";
def zIndex = uicomponent.getProperties().getIntValue("zIndex");
def id = uicomponent.getId() != null ? uicomponent.getId() : "UIGadget";
- def isDev = uicomponent.isGadgetDeveloper();
- def noCache = uicomponent.isNoCache();
- def isDebug = uicomponent.isDebug();
def view = uicomponent.getView();
def userPref = null;
def isLossData = uicomponent.isLossData();
if(!isLossData) {
- url = uicomponent.getUrl();
+ url = uicomponent.getUrl();
metadata = uicomponent.getRpcMetadata();
userPref = uicomponent.getUserPref();
+ def noCache = uicomponent.isNoCache();
+ def isDebug = uicomponent.isDebug();
jsmanager.importJavascript("eXo.gadget.UIGadget");
-
rcontext.getJavascriptManager().addCustomizedOnLoadScript("eXo.gadget.UIGadget.confirmDeleteGadget
= '" + _ctx.appRes("UIGadgetContainerManagement.confirm.DeleteGadget")
+ "';");
-
jsmanager.addCustomizedOnLoadScript("eXo.gadget.UIGadget.createGadget('$url','content-$id',
$metadata, $userPref, '$view', '$hostName', " + (isDev ? 1 : 0)
- + ", " + (isDebug ? 1 : 0) +
", " + (noCache ? 1 : 0) + ");");
+ jsmanager.addCustomizedOnLoadScript("eXo.gadget.UIGadget.confirmDeleteGadget
= '" + _ctx.appRes("UIGadgetContainerManagement.confirm.DeleteGadget")
+ "';");
+
jsmanager.addCustomizedOnLoadScript("eXo.gadget.UIGadget.createGadget('$url','content-$id',
$metadata, $userPref, '$view', '$hostName', " + (isDebug ? 1 : 0) +
", " + (noCache ? 1 : 0) + ");");
}
-
+
boolean isMini =
Boolean.parseBoolean(uicomponent.getProperties().get("minimized"));
String miniTitle = _ctx.appRes("UIGadget.tooltip.Minimize");
String unminiTitle = _ctx.appRes("UIGadget.tooltip.Unminimize");
@@ -50,9 +48,9 @@
<span class="GadgetTitle" style="display: <%=isLossData ?
"block" : "none"; %> ; float: none; width: auto; margin-right:
75px"><%= uicomponent.getApplicationName() %></span>
</div>
<div class="GadgetApplication" id="content-$id"
style="display:<%=
Boolean.parseBoolean(uicomponent.getProperties().get("minimized")) ?
"none": "block"; %>">
- <% if(isLossData) {%>
- <%=_ctx.appRes("UIGadget.message.isLossData")%>
- <% } %>
+ <% if(isLossData) { %>
+ <span><%=_ctx.appRes("UIGadget.error.NotAvailable");%></span>
+ <% } %>
</div>
<div class="UIMask" style="display: none; border:solid 1px
red"><span></span></div>
-</div>
+</div>
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 2012-06-05
14:03:10 UTC (rev 8713)
+++
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2012-06-07
06:52:22 UTC (rev 8714)
@@ -50,9 +50,7 @@
* 2008
*/
@ComponentConfig(template =
"system:/groovy/portal/webui/application/UIGadget.gtmpl", events = {
- @EventConfig(listeners = UIGadget.SaveUserPrefActionListener.class),
- @EventConfig(listeners = UIGadget.SetNoCacheActionListener.class),
- @EventConfig(listeners = UIGadget.SetDebugActionListener.class)})
+ @EventConfig(listeners = UIGadget.SaveUserPrefActionListener.class)})
/**
* This class represents user interface gadgets, it using UIGadget.gtmpl for
* rendering UI in eXo. It mapped to Application model in page or container.
@@ -96,6 +94,8 @@
public static final String METADATA_MODULEPREFS = "modulePrefs";
+ public static final String METADATA_ERROR = "error";
+
public static final String RPC_RESULT = "result";
public static final String METADATA_USERPREFS_TYPE = "dataType";
@@ -234,15 +234,18 @@
}
}
+ /**
+ * Get metadata of this gadget application
+ * This metadata contains both metadata of gadget specification (.xml file) and a
token from container
+ * @return String represent metadata of gadget
+ */
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);
+ metadata_ = fetchRpcMetadata();
}
String token = GadgetUtil.createToken(this.getUrl(), new Random().nextLong());
metadata_.put("secureToken", token);
@@ -254,6 +257,23 @@
}
}
+ private JSONObject fetchRpcMetadata()
+ {
+ try
+ {
+ String gadgetUrl = getUrl();
+ String strMetadata = GadgetUtil.fetchGagdetRpcMetadata(gadgetUrl);
+ JSONObject metadata =
+ new
JSONArray(strMetadata).getJSONObject(0).getJSONObject(UIGadget.RPC_RESULT).getJSONObject(gadgetUrl);
+
+ return metadata;
+ }
+ catch (JSONException e)
+ {
+ return null;
+ }
+ }
+
/**
* Check if content of gadget has <UserPref>? (Content is parsed from gadget
specification in .xml file)
* @return boolean
@@ -298,6 +318,16 @@
{
throw new Exception();
}
+
+ if (metadata_ == null)
+ {
+ metadata_ = fetchRpcMetadata();
+ }
+
+ if (metadata_ == null || metadata_.has(METADATA_ERROR))
+ {
+ throw new Exception();
+ }
}
catch (Exception e)
{
@@ -478,31 +508,4 @@
//event.getRequestContext().setResponseComplete(true);
}
}
-
- static public class SetNoCacheActionListener extends EventListener<UIGadget>
- {
- public void execute(Event<UIGadget> event) throws Exception
- {
- /*
- * String noCache =
- * event.getRequestContext().getRequestParameter("nocache") ;
UIGadget
- * uiGadget = event.getSource() ;
- * uiGadget.setNoCache(noCache.equals("1"));
- */
- event.getRequestContext().setResponseComplete(true);
- }
- }
-
- static public class SetDebugActionListener extends EventListener<UIGadget>
- {
- public void execute(Event<UIGadget> event) throws Exception
- {
- /*
- * String debug =
event.getRequestContext().getRequestParameter("debug") ;
- * UIGadget uiGadget = event.getSource() ;
- * uiGadget.setDebug(debug.equals("1"));
- */
- event.getRequestContext().setResponseComplete(true);
- }
- }
}