Author: julien_viet
Date: 2009-12-07 05:41:38 -0500 (Mon, 07 Dec 2009)
New Revision: 959
Modified:
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/SourceStorageImpl.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/uiconf/applicationregistry/component/SampleGadget.groovy
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java
Log:
fix issues with gadget creation in the gadget registry service
Modified:
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java
===================================================================
---
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java 2009-12-07
06:36:13 UTC (rev 958)
+++
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java 2009-12-07
10:41:38 UTC (rev 959)
@@ -20,6 +20,8 @@
import org.chromattic.api.Chromattic;
import org.chromattic.api.ChromatticSession;
+import org.chromattic.ntdef.NTFile;
+import org.chromattic.ntdef.Resource;
import org.exoplatform.application.gadget.Gadget;
import org.exoplatform.application.gadget.GadgetRegistryService;
import org.exoplatform.application.registry.impl.ApplicationRegistryChromatticLifeCycle;
@@ -171,7 +173,28 @@
//
if (def == null)
{
- throw new IllegalArgumentException("No such gadget " +
gadget.getName());
+ def = registry.addGadget(gadget.getName());
+ if (gadget.isLocal())
+ {
+ def.setLocal(true);
+ LocalGadgetData data = (LocalGadgetData)def.getData();
+ String fileName = gadget.getName() + ".xml";
+ data.setFileName(fileName);
+ data.getResources().createFile(fileName, new Resource(
+ "application.xml",
+ "UTF-8",
+ ("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>" +
+ "<Module><ModulePrefs title=\"\" />" +
+ "<Content type=\"html\"> <![CDATA[]]>" +
+ "</Content>" +
+ "</Module>").getBytes("UTF-8")));
+ }
+ else
+ {
+ def.setLocal(false);
+ RemoteGadgetData data = (RemoteGadgetData)def.getData();
+ data.setURL(gadget.getUrl());
+ }
}
//
Modified:
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/SourceStorageImpl.java
===================================================================
---
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/SourceStorageImpl.java 2009-12-07
06:36:13 UTC (rev 958)
+++
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/SourceStorageImpl.java 2009-12-07
10:41:38 UTC (rev 959)
@@ -18,6 +18,10 @@
*/
package org.exoplatform.application.gadget.impl;
+import org.apache.shindig.common.uri.Uri;
+import org.apache.shindig.gadgets.spec.GadgetSpec;
+import org.apache.shindig.gadgets.spec.ModulePrefs;
+import org.chromattic.ntdef.Resource;
import org.exoplatform.application.gadget.Gadget;
import org.exoplatform.application.gadget.GadgetRegistryService;
import org.exoplatform.application.gadget.Source;
@@ -85,18 +89,31 @@
}
//
- GadgetDefinition def =
gadgetRegistryService.getRegistry().getGadget(gadget.getName());
+ GadgetRegistry registry = gadgetRegistryService.getRegistry();
//
- if (def == null)
- {
- throw new IllegalStateException("No such gadget " +
gadget.getName());
- }
+ GadgetDefinition def = registry.getGadget(gadget.getName());
//
GadgetData data = def.getData();
if (data instanceof LocalGadgetData)
{
+ GadgetSpec spec = new GadgetSpec(Uri.parse("http://www.gatein.org"),
source.getTextContent());
+ ModulePrefs prefs = spec.getModulePrefs();
+
+ //
+ String description = prefs.getDescription();
+ String thumbnail = prefs.getThumbnail().toString();
+ String title = getGadgetTitle(prefs, gadget.getName());
+ String referenceURL = prefs.getTitleUrl().toString();
+
+ // Update state from XML
+ def.setDescription(description);
+ def.setThumbnail(thumbnail); // Do something better than that
+ def.setTitle(title);
+ def.setReferenceURL(referenceURL);
+
+ // Save text content
LocalGadgetData localData = (LocalGadgetData)data;
localData.setSource(source.getTextContent());
}
@@ -106,8 +123,20 @@
}
}
+ private String getGadgetTitle(ModulePrefs prefs, String defaultValue)
+ {
+ String title = prefs.getDirectoryTitle();
+ if (title == null || title.trim().length() < 1)
+ {
+ title = prefs.getTitle();
+ }
+ if (title == null || title.trim().length() < 1)
+ {
+ return defaultValue;
+ }
+ return title;
+ }
-
public void removeSource(String sourcePath) throws Exception
{
// No op
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2009-12-07
06:36:13 UTC (rev 958)
+++
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2009-12-07
10:41:38 UTC (rev 959)
@@ -168,6 +168,23 @@
}
}
+ // If gadget is null we need to create it first
+ if (gadget == null)
+ {
+ gadget = new Gadget();
+ gadget.setName("CHANGME");
+
+ // Those data will be taken from the gadget XML anyway
+ gadget.setDescription("");
+ gadget.setThumbnail("");
+ gadget.setLocal(true);
+ gadget.setTitle("");
+ gadget.setReferenceUrl("");
+
+ // Save gadget with empty data first
+ service.saveGadget(gadget);
+ }
+
//
Source source = new Source(fileName, "application/xml");
source.setTextContent(text);
Modified:
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/uiconf/applicationregistry/component/SampleGadget.groovy
===================================================================
---
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/uiconf/applicationregistry/component/SampleGadget.groovy 2009-12-07
06:36:13 UTC (rev 958)
+++
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/conf/uiconf/applicationregistry/component/SampleGadget.groovy 2009-12-07
10:41:38 UTC (rev 959)
@@ -19,7 +19,7 @@
String sample = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>"+
"<Module>" +
- "<ModulePrefs title=\"hello world example\" />" +
+ "<ModulePrefs title=\"hello world example\"
description=\"The hello world gadget.\"/>" +
"<Content type=\"html\">" +
" <![CDATA[" +
" Hello, world!" +
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java 2009-12-07
06:36:13 UTC (rev 958)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java 2009-12-07
10:41:38 UTC (rev 959)
@@ -46,12 +46,12 @@
*/
public class GadgetUtil
{
- static final public GadgetApplication toGadgetApplication(Gadget model)
+ static public GadgetApplication toGadgetApplication(Gadget model)
{
return new GadgetApplication(model.getName(), model.getUrl(), model.isLocal());
}
- static final public Gadget toGadget(String name, String path, boolean isLocal) throws
Exception
+ static public Gadget toGadget(String name, String path, boolean isLocal) throws
Exception
{
Gadget gadget = new Gadget();
gadget.setName(name);
@@ -79,7 +79,7 @@
*
* @return the string represents metadata of gadget application
*/
- static final public String fetchGagdetMetadata(String urlStr)
+ public static String fetchGagdetMetadata(String urlStr)
{
String result = null;
@@ -127,7 +127,7 @@
* @throws JSONException if can't create jsonObject from metadata
*/
@SuppressWarnings("unchecked")
- static final public Map<String, String> getMapMetadata(String url) throws
JSONException
+ static public Map<String, String> getMapMetadata(String url) throws
JSONException
{
Map<String, String> mapMetaData = new HashMap<String, String>();
String metadata = fetchGagdetMetadata(url);
@@ -142,7 +142,7 @@
return mapMetaData;
}
- static final public String reproduceUrl(String path, boolean isLocal)
+ static public String reproduceUrl(String path, boolean isLocal)
{
if (isLocal)
{
@@ -151,12 +151,12 @@
return path;
}
- static final public String getViewPath(String uri)
+ static public String getViewPath(String uri)
{
return getLocalHostBase() + "/" +
PortalContainer.getCurrentRestContextName() + "/" + uri;
}
- static final public String getEditPath(String uri)
+ static public String getEditPath(String uri)
{
return getLocalHostBase() + "/" +
PortalContainer.getCurrentRestContextName() + "/private/" + uri;
}
@@ -225,7 +225,7 @@
return hostName.substring(0, index);
}
- static final private String getHostName()
+ static private String getHostName()
{
ExoContainer container = ExoContainerContext.getCurrentContainer();
GadgetRegistryService gadgetService =
@@ -233,7 +233,7 @@
return gadgetService.getHostName();
}
- static final private String getLocalHostName()
+ static private String getLocalHostName()
{
PortalRequestContext pContext = Util.getPortalRequestContext();
StringBuffer requestUrl = pContext.getRequest().getRequestURL();