Author: liem_nguyen
Date: 2009-11-04 02:33:42 -0500 (Wed, 04 Nov 2009)
New Revision: 488
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
Log:
GTNPORTAL-170 NPE when click maximize gadget in dashboard page
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2009-11-04
03:35:24 UTC (rev 487)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIGadget.java 2009-11-04
07:33:42 UTC (rev 488)
@@ -47,303 +47,343 @@
* 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),
+ @EventConfig(listeners = UIGadget.SetNoCacheActionListener.class),
+ @EventConfig(listeners = UIGadget.SetDebugActionListener.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.
*/
-public class UIGadget extends UIComponent {
+public class UIGadget extends UIComponent
+{
- /** The storage id. */
- private String storageId;
+ /** The storage id. */
+ private String storageId;
- /** The storage name. */
- private String storageName;
+ /** The storage name. */
+ private String storageName;
- /** . */
- private ApplicationState<org.exoplatform.portal.pom.spi.gadget.Gadget> state;
+ /** . */
+ private ApplicationState<org.exoplatform.portal.pom.spi.gadget.Gadget> state;
- /** . */
- private GadgetId gadgetId;
+ /** . */
+ private GadgetId gadgetId;
- private Properties properties_;
+ private Properties properties_;
- private JSONObject metadata_;
+ private JSONObject metadata_;
- private String url_;
+ private String url_;
- private GadgetRegistryService
gadgetRegistryService = null;
+ private GadgetRegistryService gadgetRegistryService = null;
- public static final String PREF_KEY
= "_pref_gadget_";
+ public static final String PREF_KEY = "_pref_gadget_";
- public static final String PREF_NO_CACHE
= "_pref_no_cache_";
+ public static final String PREF_NO_CACHE = "_pref_no_cache_";
- public static final String PREF_DEBUG
= "_pref_debug_";
+ public static final String PREF_DEBUG = "_pref_debug_";
- public static final String HOME_VIEW
= "home";
+ public static final String HOME_VIEW = "home";
- public static final String CANVAS_VIEW
= "canvas";
+ public static final String CANVAS_VIEW = "canvas";
- public String view
= HOME_VIEW;
+ public String view = HOME_VIEW;
- /**
- * Initializes a newly created <code>UIGadget</code> object
- *
- * @throws Exception if can't initialize object
- */
- public UIGadget() {
- // That value will be overriden when it is mapped onto a data storage
- storageName = UUID.randomUUID().toString();
- state = new
TransientApplicationState<org.exoplatform.portal.pom.spi.gadget.Gadget>();
- }
+ /**
+ * Initializes a newly created <code>UIGadget</code> object
+ *
+ * @throws Exception if can't initialize object
+ */
+ public UIGadget()
+ {
+ // That value will be overriden when it is mapped onto a data storage
+ storageName = UUID.randomUUID().toString();
+ state = new
TransientApplicationState<org.exoplatform.portal.pom.spi.gadget.Gadget>();
+ }
- public String getStorageId() {
- return storageId;
- }
+ public String getStorageId()
+ {
+ return storageId;
+ }
- public void setStorageId(String storageId) {
- this.storageId = storageId;
- }
+ public void setStorageId(String storageId)
+ {
+ this.storageId = storageId;
+ }
- public String getStorageName() {
- return storageName;
- }
+ public String getStorageName()
+ {
+ return storageName;
+ }
- public void setStorageName(String storageName) {
- this.storageName = storageName;
- }
+ public void setStorageName(String storageName)
+ {
+ this.storageName = storageName;
+ }
- public String getId() {
- return storageName;
- }
+ public String getId()
+ {
+ return storageName;
+ }
- public ApplicationState<org.exoplatform.portal.pom.spi.gadget.Gadget> getState()
{
- return state;
- }
+ public ApplicationState<org.exoplatform.portal.pom.spi.gadget.Gadget>
getState()
+ {
+ return state;
+ }
- public void
setState(ApplicationState<org.exoplatform.portal.pom.spi.gadget.Gadget> state) {
- this.state = state;
- }
+ public void
setState(ApplicationState<org.exoplatform.portal.pom.spi.gadget.Gadget> state)
+ {
+ this.state = state;
+ }
- public GadgetId getGadgetId() {
- return gadgetId;
- }
+ public GadgetId getGadgetId()
+ {
+ return gadgetId;
+ }
- public void setGadgetId(GadgetId gadgetId) {
- this.gadgetId = gadgetId;
- }
+ public void setGadgetId(GadgetId gadgetId)
+ {
+ this.gadgetId = gadgetId;
+ }
- /**
- * Gets name of gadget application
- *
- * @return the string represents name of gadget application
- */
- public String getApplicationName() {
- return gadgetId.getGadgetName();
- }
+ /**
+ * Gets name of gadget application
+ *
+ * @return the string represents name of gadget application
+ */
+ public String getApplicationName()
+ {
+ return gadgetId.getGadgetName();
+ }
- /**
- * Gets Properties of gadget application such as locationX, locationY in
- * desktop page
- *
- * @return all properties of gadget application
- * @see org.exoplatform.portal.config.model.Application
- * @see org.exoplatform.portal.config.model.Properties
- */
- public Properties getProperties() {
- if (properties_ == null)
- properties_ = new Properties();
- return properties_;
- }
+ /**
+ * Gets Properties of gadget application such as locationX, locationY in
+ * desktop page
+ *
+ * @return all properties of gadget application
+ * @see org.exoplatform.portal.config.model.Application
+ * @see org.exoplatform.portal.config.model.Properties
+ */
+ public Properties getProperties()
+ {
+ if (properties_ == null)
+ properties_ = new Properties();
+ return properties_;
+ }
- /**
- * Sets Properties of gadget application such as locationX, locationY in
- * desktop page
- *
- * @param properties Properties that is the properties of gadget application
- * @see org.exoplatform.portal.config.model.Properties
- * @see org.exoplatform.portal.config.model.Application
- */
- public void setProperties(Properties properties) {
- this.properties_ = properties;
- }
+ /**
+ * Sets Properties of gadget application such as locationX, locationY in
+ * desktop page
+ *
+ * @param properties Properties that is the properties of gadget application
+ * @see org.exoplatform.portal.config.model.Properties
+ * @see org.exoplatform.portal.config.model.Application
+ */
+ public void setProperties(Properties properties)
+ {
+ this.properties_ = properties;
+ }
- public String getMetadata() {
- try {
- if (metadata_ == null) {
- String strMetadata = GadgetUtil.fetchGagdetMetadata(getUrl());
- metadata_ = new JSONObject(strMetadata);
+ public String getMetadata()
+ {
+ try
+ {
+ if (metadata_ == null)
+ {
+ String strMetadata = GadgetUtil.fetchGagdetMetadata(getUrl());
+ metadata_ = new JSONObject(strMetadata);
+ }
+ JSONObject obj = metadata_.getJSONArray("gadgets").getJSONObject(0);
+ String token = GadgetUtil.createToken(this.getUrl(), new Random().nextLong());
+ obj.put("secureToken", token);
+ return metadata_.toString();
}
- JSONObject obj = metadata_.getJSONArray("gadgets").getJSONObject(0);
- String token = GadgetUtil.createToken(this.getUrl(), new Random().nextLong());
- obj.put("secureToken", token);
- return metadata_.toString();
- } catch (JSONException e) {
- return null;
- }
- }
+ catch (JSONException e)
+ {
+ return null;
+ }
+ }
- /**
- * Gets GadgetApplication by GadgedRegistryService
- *
- * @return Gadget Application
- * @throws Exception
- */
- private GadgetApplication getApplication() {
- WebAppController webController = getApplicationComponent(WebAppController.class);
- GadgetApplication application = webController.getApplication("eXoGadgets/"
- + gadgetId.getGadgetName());
- if (application == null) {
- GadgetRegistryService gadgetService =
getApplicationComponent(GadgetRegistryService.class);
- Gadget model;
- try {
- model = gadgetService.getGadget(gadgetId.getGadgetName());
- } catch (Exception ex) {
- return null;
+ /**
+ * Gets GadgetApplication by GadgedRegistryService
+ *
+ * @return Gadget Application
+ * @throws Exception
+ */
+ private GadgetApplication getApplication()
+ {
+ WebAppController webController = getApplicationComponent(WebAppController.class);
+ GadgetApplication application =
webController.getApplication("eXoGadgets/" + gadgetId.getGadgetName());
+ if (application == null)
+ {
+ GadgetRegistryService gadgetService =
getApplicationComponent(GadgetRegistryService.class);
+ Gadget model;
+ try
+ {
+ model = gadgetService.getGadget(gadgetId.getGadgetName());
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
+ application = GadgetUtil.toGadgetApplication(model);
+ webController.addApplication(application);
}
- application = GadgetUtil.toGadgetApplication(model);
- webController.addApplication(application);
- }
- return application;
- }
+ return application;
+ }
- /**
- * Gets Url of gadget application, it saved before by GadgetRegistryService
- *
- * @return url of gadget application, such as
- * "http://www.google.com/ig/modules/horoscope.xml"
- */
- public String getUrl() {
- if (url_ == null) {
- GadgetApplication application = getApplication();
- url_ = GadgetUtil.reproduceUrl(application.getUrl(), application.isLocal());
- }
- return url_;
- }
+ /**
+ * Gets Url of gadget application, it saved before by GadgetRegistryService
+ *
+ * @return url of gadget application, such as
+ * "http://www.google.com/ig/modules/horoscope.xml"
+ */
+ public String getUrl()
+ {
+ if (url_ == null)
+ {
+ GadgetApplication application = getApplication();
+ url_ = GadgetUtil.reproduceUrl(application.getUrl(), application.isLocal());
+ }
+ return url_;
+ }
- private GadgetRegistryService getGadgetRegistryService() {
- if (gadgetRegistryService == null)
- gadgetRegistryService = (GadgetRegistryService)
ExoContainerContext.getCurrentContainer()
-
.getComponentInstanceOfType(GadgetRegistryService.class);
- return gadgetRegistryService;
- }
+ private GadgetRegistryService getGadgetRegistryService()
+ {
+ if (gadgetRegistryService == null)
+ gadgetRegistryService =
+
(GadgetRegistryService)ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(
+ GadgetRegistryService.class);
+ return gadgetRegistryService;
+ }
- public boolean isNoCache() {
- /*
- * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
- * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
- * null) { String prefs = userGadgetStorage.get(username,
- * getApplicationName(), getApplicationInstanceUniqueId(), PREF_NO_CACHE);
- * return prefs.equals("1"); } } catch (Exception e) {} return false;
- */
- return true;
- }
+ public boolean isNoCache()
+ {
+ /*
+ * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
+ * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
+ * null) { String prefs = userGadgetStorage.get(username,
+ * getApplicationName(), getApplicationInstanceUniqueId(), PREF_NO_CACHE);
+ * return prefs.equals("1"); } } catch (Exception e) {} return false;
+ */
+ return true;
+ }
- public void setNoCache(boolean value) {
- /*
- * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
- * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
- * null && getGadgetRegistryService().isGadgetDeveloper(username)) {
- * userGadgetStorage.save(username, getApplicationName(),
- * getApplicationInstanceUniqueId(), PREF_NO_CACHE, value ? "1" :
"0"); } }
- * catch (Exception e) {}
- */
- }
+ public void setNoCache(boolean value)
+ {
+ /*
+ * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
+ * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
+ * null && getGadgetRegistryService().isGadgetDeveloper(username)) {
+ * userGadgetStorage.save(username, getApplicationName(),
+ * getApplicationInstanceUniqueId(), PREF_NO_CACHE, value ? "1" :
"0"); } }
+ * catch (Exception e) {}
+ */
+ }
- public boolean isDebug() {
- /*
- * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
- * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
- * null) { String prefs = userGadgetStorage.get(username,
- * getApplicationName(), getApplicationInstanceUniqueId(), PREF_DEBUG);
- * return prefs.equals("1"); } } catch (Exception e) {} return false;
- */
- return true;
- }
+ public boolean isDebug()
+ {
+ /*
+ * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
+ * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
+ * null) { String prefs = userGadgetStorage.get(username,
+ * getApplicationName(), getApplicationInstanceUniqueId(), PREF_DEBUG);
+ * return prefs.equals("1"); } } catch (Exception e) {} return false;
+ */
+ return true;
+ }
- public void setDebug(boolean value) {
- /*
- * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
- * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
- * null && getGadgetRegistryService().isGadgetDeveloper(username)) {
- * userGadgetStorage.save(username, getApplicationName(),
- * getApplicationInstanceUniqueId(), PREF_DEBUG, value ? "1" :
"0"); } }
- * catch (Exception e) {}
- */
- }
+ public void setDebug(boolean value)
+ {
+ /*
+ * try { UserGadgetStorage userGadgetStorage = getGadgetStorage(); String
+ * username = Util.getPortalRequestContext().getRemoteUser(); if(username !=
+ * null && getGadgetRegistryService().isGadgetDeveloper(username)) {
+ * userGadgetStorage.save(username, getApplicationName(),
+ * getApplicationInstanceUniqueId(), PREF_DEBUG, value ? "1" :
"0"); } }
+ * catch (Exception e) {}
+ */
+ }
- public boolean isGadgetDeveloper() {
- return getGadgetRegistryService().isGadgetDeveloper(Util.getPortalRequestContext()
- .getRemoteUser());
- }
+ public boolean isGadgetDeveloper()
+ {
+ return
getGadgetRegistryService().isGadgetDeveloper(Util.getPortalRequestContext().getRemoteUser());
+ }
- public String getView() {
- if (view != null)
- return view;
- return HOME_VIEW;
- }
+ public String getView()
+ {
+ if (view != null)
+ return view;
+ return HOME_VIEW;
+ }
- public void setView(String view) {
- this.view = view;
- }
+ public void setView(String view)
+ {
+ this.view = view;
+ }
- /**
- * Gets user preference of gadget application
- *
- * @return the string represents user preference of gadget application
- * @throws Exception
- * @throws Exception when can't convert object to string
- */
- public String getUserPref() throws Exception {
- DataStorage service = getApplicationComponent(DataStorage.class);
- org.exoplatform.portal.pom.spi.gadget.Gadget pp = service.load(state);
- return pp != null ? pp.getUserPref() : null;
- }
+ /**
+ * Gets user preference of gadget application
+ *
+ * @return the string represents user preference of gadget application
+ * @throws Exception
+ * @throws Exception when can't convert object to string
+ */
+ public String getUserPref() throws Exception
+ {
+ DataStorage service = getApplicationComponent(DataStorage.class);
+ org.exoplatform.portal.pom.spi.gadget.Gadget pp = service.load(state);
+ return pp != null ? pp.getUserPref() : null;
+ }
- /**
- * Initializes a newly created <code>SaveUserPrefActionListener</code>
- * object
- *
- * @throws Exception if can't initialize object
- */
- static public class SaveUserPrefActionListener extends EventListener<UIGadget> {
- public void execute(Event<UIGadget> event) throws Exception {
- String userPref =
event.getRequestContext().getRequestParameter("userPref");
- org.exoplatform.portal.pom.spi.gadget.Gadget gadget = new
org.exoplatform.portal.pom.spi.gadget.Gadget();
- gadget.setUserPref(userPref);
+ /**
+ * Initializes a newly created <code>SaveUserPrefActionListener</code>
+ * object
+ *
+ * @throws Exception if can't initialize object
+ */
+ static public class SaveUserPrefActionListener extends EventListener<UIGadget>
+ {
+ public void execute(Event<UIGadget> event) throws Exception
+ {
+ String userPref =
event.getRequestContext().getRequestParameter("userPref");
+ org.exoplatform.portal.pom.spi.gadget.Gadget gadget = new
org.exoplatform.portal.pom.spi.gadget.Gadget();
+ gadget.setUserPref(userPref);
- //
- UIGadget uiGadget = event.getSource();
- DataStorage service = uiGadget.getApplicationComponent(DataStorage.class);
+ //
+ UIGadget uiGadget = event.getSource();
+ DataStorage service = uiGadget.getApplicationComponent(DataStorage.class);
- //
- uiGadget.state = service.save(uiGadget.state, gadget);
- event.getRequestContext().setResponseComplete(true);
- }
- }
+ //
+ uiGadget.state = service.save(uiGadget.state, gadget);
+ 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 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);
- }
- }
+ 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);
+ }
+ }
}