Author: trong.tran
Date: 2010-05-20 05:25:11 -0400 (Thu, 20 May 2010)
New Revision: 3150
Modified:
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/gadget/GadgetPortlet_en.properties
portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/gadget/GadgetPortlet_vi.xml
Log:
GTNPORTAL-1060 Alternative to URL preference for local gadgets in Gadget Wrapper portlet
Modified:
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
===================================================================
---
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java 2010-05-20
09:22:00 UTC (rev 3149)
+++
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java 2010-05-20
09:25:11 UTC (rev 3150)
@@ -19,12 +19,21 @@
package org.exoplatform.gadget.webui.component;
+import org.exoplatform.application.gadget.Gadget;
+import org.exoplatform.application.gadget.GadgetRegistryService;
+import org.exoplatform.application.gadget.LocalImporter;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.webui.application.GadgetUtil;
+import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.application.portlet.PortletRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
+import org.exoplatform.webui.core.UIApplication;
import org.exoplatform.webui.core.UIPortletApplication;
import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
import org.json.JSONException;
import org.json.JSONObject;
@@ -39,26 +48,58 @@
@ComponentConfig(lifecycle = UIApplicationLifecycle.class, template =
"app:/groovy/gadget/webui/component/UIGadgetPortlet.gtmpl")
public class UIGadgetPortlet extends UIPortletApplication
{
+ final static public String LOCAL_STRING = "local://";
+
+ private static final Logger log = LoggerFactory.getLogger(LocalImporter.class);
+
public UIGadgetPortlet() throws Exception
{
- addChild(UIGadgetViewMode.class, null, null);
+ addChild(UIGadgetViewMode.class, null, null);
}
public String getUrl()
{
PortletRequestContext pcontext =
(PortletRequestContext)WebuiRequestContext.getCurrentInstance();
PortletPreferences pref = pcontext.getRequest().getPreferences();
- return pref.getValue("url",
"http://www.google.com/ig/modules/horoscope.xml");
+ String urlPref = pref.getValue("url",
"http://www.google.com/ig/modules/horoscope.xml");
+ if (urlPref.startsWith(LOCAL_STRING))
+ {
+ try
+ {
+ String gadgetName = urlPref.replaceFirst(LOCAL_STRING, "");
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ GadgetRegistryService gadgetService =
+
(GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class);
+ Gadget gadget = gadgetService.getGadget(gadgetName);
+ if (gadget != null)
+ {
+ return GadgetUtil.reproduceUrl(gadget.getUrl(), gadget.isLocal());
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Failure retrieving gadget from url!");
+ }
+ }
+ return urlPref;
}
public String getMetadata()
{
- String metadata_ = GadgetUtil.fetchGagdetMetadata(getUrl());
+ String url = getUrl();
+ if (url == null)
+ {
+ WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
+ UIApplication uiApplication = context.getUIApplication();
+ uiApplication.addMessage(new
ApplicationMessage("UIGadgetPortlet.msg.url-invalid", null));
+ }
+
+ String metadata_ = GadgetUtil.fetchGagdetMetadata(url);
try
{
JSONObject jsonObj = new JSONObject(metadata_);
JSONObject obj = jsonObj.getJSONArray("gadgets").getJSONObject(0);
- String token = GadgetUtil.createToken(getUrl(), new Long(hashCode()));
+ String token = GadgetUtil.createToken(url, new Long(hashCode()));
obj.put("secureToken", token);
metadata_ = jsonObj.toString();
}
Modified:
portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/gadget/GadgetPortlet_en.properties
===================================================================
---
portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/gadget/GadgetPortlet_en.properties 2010-05-20
09:22:00 UTC (rev 3149)
+++
portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/gadget/GadgetPortlet_en.properties 2010-05-20
09:25:11 UTC (rev 3150)
@@ -24,4 +24,6 @@
UIGadgetEditMode.action.Save=Save
UIGadgetEditMode.label.option.remote=Remote Gadget
-UIGadgetEditMode.label.option.local=Local Gadget
\ No newline at end of file
+UIGadgetEditMode.label.option.local=Local Gadget
+
+UIGadgetPortlet.msg.url-invalid=The gadget url formating is wrong in Preference
Modified:
portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/gadget/GadgetPortlet_vi.xml
===================================================================
---
portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/gadget/GadgetPortlet_vi.xml 2010-05-20
09:22:00 UTC (rev 3149)
+++
portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/classes/locale/portlet/gadget/GadgetPortlet_vi.xml 2010-05-20
09:25:11 UTC (rev 3150)
@@ -36,5 +36,10 @@
<Save>Lưu</Save>
</action>
</UIGadgetEditMode>
+ <UIGadgetPortlet>
+ <msg>
+ <url-invalid>Url sai định dạng</url-invalid>
+ </msg>
+ </UIGadgetPortlet>
</bundle>
Show replies by date