[gatein-commits] gatein SVN: r7413 - in epp/portal/branches/EPP_5_2_Branch: component and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Sep 14 06:00:18 EDT 2011


Author: theute
Date: 2011-09-14 06:00:18 -0400 (Wed, 14 Sep 2011)
New Revision: 7413

Removed:
   epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/LocalImporter.java
Modified:
   epp/portal/branches/EPP_5_2_Branch/
   epp/portal/branches/EPP_5_2_Branch/component/
   epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetDeployer.java
   epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetRegistryService.java
   epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/ServletLocalImporter.java
   epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java
   epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/
   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/wsrp-integration/
Log:
JBEPP-1172: Decouple gadget import process and gadget import metadata extraction


Property changes on: epp/portal/branches/EPP_5_2_Branch
___________________________________________________________________
Modified: svn:mergeinfo
   - /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795:5868
/portal/branches/branch-GTNPORTAL-1592:4894
/portal/branches/branch-GTNPORTAL-1643:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745:5765
/portal/branches/branch-GTNPORTAL-1790:5871
/portal/branches/branch-GTNPORTAL-1822:5943,5952
/portal/branches/branch-GTNPORTAL-1832:6030,6063
/portal/branches/branch-GTNPORTAL-1872:6400,6551
/portal/branches/branch-GTNPORTAL-1921:6603
/portal/branches/branch-GTNPORTAL-1963:6904,6915-6916
/portal/branches/decoupled-webos:6214-6243
/portal/branches/gatein-management:6920-6958
/portal/branches/global-portlet-metadata:6298-6384
/portal/branches/site-describability:6171-6235
/portal/trunk:4891,5744,5822,5943,6168,6196,6201-6203,6205-6206,6223,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7095,7117,7125,7132-7134,7239,7262,7308,7326,7331,7359,7367
   + /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795:5868
/portal/branches/branch-GTNPORTAL-1592:4894
/portal/branches/branch-GTNPORTAL-1643:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745:5765
/portal/branches/branch-GTNPORTAL-1790:5871
/portal/branches/branch-GTNPORTAL-1822:5943,5952
/portal/branches/branch-GTNPORTAL-1832:6030,6063
/portal/branches/branch-GTNPORTAL-1872:6400,6551
/portal/branches/branch-GTNPORTAL-1921:6603
/portal/branches/branch-GTNPORTAL-1963:6904,6915-6916
/portal/branches/decoupled-webos:6214-6243
/portal/branches/gatein-management:6920-6958
/portal/branches/global-portlet-metadata:6298-6384
/portal/branches/site-describability:6171-6235
/portal/trunk:4891,5269,5744,5822,5943,6168,6196,6201-6203,6205-6206,6223,6323,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7095,7117,7125,7132-7134,7239,7262,7308,7326,7331,7359,7367


Property changes on: epp/portal/branches/EPP_5_2_Branch/component
___________________________________________________________________
Modified: svn:mergeinfo
   - /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component:5868
/portal/branches/branch-GTNPORTAL-1592/component:4894
/portal/branches/branch-GTNPORTAL-1643/component:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/component:5765
/portal/branches/branch-GTNPORTAL-1790/component:5871
/portal/branches/branch-GTNPORTAL-1822/component:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component:6603
/portal/branches/branch-GTNPORTAL-1963/component:6904,6915-6916
/portal/trunk/component:4891,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6223,6292,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7095,7117,7120,7125,7132-7134,7239,7262,7308,7326,7331,7359,7367
   + /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component:5868
/portal/branches/branch-GTNPORTAL-1592/component:4894
/portal/branches/branch-GTNPORTAL-1643/component:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/component:5765
/portal/branches/branch-GTNPORTAL-1790/component:5871
/portal/branches/branch-GTNPORTAL-1822/component:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component:6603
/portal/branches/branch-GTNPORTAL-1963/component:6904,6915-6916
/portal/trunk/component:4891,5269,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6223,6292,6323,6437,6440,6449,6452,6573,6783-6784,6912-6913,6960,7042,7061,7095,7117,7120,7125,7132-7134,7239,7262,7308,7326,7331,7359,7367

Modified: epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetDeployer.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetDeployer.java	2011-09-14 09:45:02 UTC (rev 7412)
+++ epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetDeployer.java	2011-09-14 10:00:18 UTC (rev 7413)
@@ -19,8 +19,6 @@
 package org.exoplatform.application.gadget;
 
 import org.exoplatform.application.gadget.impl.GadgetRegistryServiceImpl;
-import org.exoplatform.commons.chromattic.ChromatticLifeCycle;
-import org.exoplatform.commons.chromattic.SessionContext;
 import org.exoplatform.commons.xml.DocumentSource;
 import org.exoplatform.commons.xml.XMLValidator;
 import org.exoplatform.container.ExoContainerContext;
@@ -40,11 +38,10 @@
 import org.w3c.dom.NodeList;
 
 import javax.servlet.ServletContext;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
@@ -115,28 +112,27 @@
 
    private void handle(ServletContext scontext, URL gadgetsURL)
    {
-      ChromatticLifeCycle lifeCycle = gadgetRegistryService.getChromatticLifeCycle();
-      lifeCycle.openContext();
       try
       {
+         List<GadgetImporter> importers = new ArrayList<GadgetImporter>();
          Document docXML = validator.validate(DocumentSource.create(gadgetsURL));
          NodeList nodeList = docXML.getElementsByTagName("gadget");
          for (int i = 0; i < nodeList.getLength(); i++)
          {
             Element gadgetElement = (Element)nodeList.item(i);
             String gadgetName = gadgetElement.getAttribute("name");
-            log.debug("About to import gadget " + gadgetName);
+
+            //
+            log.debug("About to parse gadget " + gadgetName);
             Element pathElt = XMLTools.getUniqueChild(gadgetElement, "path", false);
+            GadgetImporter importer = null;
             if (pathElt != null)
             {
                String path = XMLTools.asString(pathElt, true);
-               ServletLocalImporter importer = new ServletLocalImporter(
+               importer = new ServletLocalImporter(
                   gadgetName,
-                  gadgetRegistryService.getRegistry(),
                   path,
-                  scontext,
-                  true);
-               importer.doImport();
+                  scontext);
             }
             else
             {
@@ -144,24 +140,26 @@
                if (urlElt != null)
                {
                   String url = XMLTools.asString(urlElt, true);
-                  ServletLocalImporter importer = new ServletLocalImporter(
+                  importer = new RemoteImporter(
                      gadgetName,
-                     gadgetRegistryService.getRegistry(),
-                     url, 
-                     scontext,
-                     false);
-                  importer.doImport();
+                     url);
                }
             }
+
+            //
+            if (importer != null)
+            {
+               importers.add(importer);
+               log.debug("Add gadget " + gadgetName + " to gadget imports");
+            }
          }
+
+         // Import everything
+         gadgetRegistryService.deploy(importers);
       }
       catch (Exception e)
       {
          log.error("Could not process gadget file " + gadgetsURL, e);
       }
-      finally
-      {
-         lifeCycle.closeContext(true);
-      }
    }
 }

Modified: epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetRegistryService.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetRegistryService.java	2011-09-14 09:45:02 UTC (rev 7412)
+++ epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetRegistryService.java	2011-09-14 10:00:18 UTC (rev 7413)
@@ -33,6 +33,13 @@
 {
 
    /**
+    * Deploy a set of gadgets.
+    *
+    * @param gadgets the gadgets to deploy
+    */
+   public void deploy(Iterable<GadgetImporter> gadgets);
+
+   /**
     * Return Gadget object retrieved from database by its name.
     * 
     * @param name the name of gadget

Deleted: epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/LocalImporter.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/LocalImporter.java	2011-09-14 09:45:02 UTC (rev 7412)
+++ epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/LocalImporter.java	2011-09-14 10:00:18 UTC (rev 7413)
@@ -1,247 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.application.gadget;
-
-import org.apache.shindig.common.uri.Uri;
-import org.apache.shindig.gadgets.spec.GadgetSpec;
-import org.apache.shindig.gadgets.spec.ModulePrefs;
-import org.chromattic.ext.ntdef.NTFolder;
-import org.chromattic.ext.ntdef.Resource;
-import org.exoplatform.application.gadget.impl.GadgetDefinition;
-import org.exoplatform.application.gadget.impl.GadgetRegistry;
-import org.exoplatform.application.gadget.impl.LocalGadgetData;
-import org.exoplatform.application.gadget.impl.RemoteGadgetData;
-import org.gatein.common.logging.Logger;
-import org.gatein.common.logging.LoggerFactory;
-import org.gatein.common.net.URLTools;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.URL;
-
-/**
- * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public abstract class LocalImporter
-{
-
-   /** . */
-   private static final Logger log = LoggerFactory.getLogger(LocalImporter.class);
-
-   /** The gadget name as seen by GateIn. */
-   private String name;
-
-   /** The gadget registry. */
-   private GadgetRegistry registry;
-
-   /** The gadget path. */
-   private String gadgetPath;
-
-   /** . */
-   private boolean local;
-
-   /** Used temporarily when importing resources. */
-   private NTFolder folder;
-
-   protected LocalImporter(
-      String name,
-      GadgetRegistry registry,
-      String gadgetPath,
-      boolean local)
-   {
-      this.name = name;
-      this.registry = registry;
-      this.gadgetPath = gadgetPath;
-      this.local = local;
-   }
-
-   private byte[] getGadgetBytes() throws IOException
-   {
-      if (local)
-      {
-         return getContent(gadgetPath);
-      }
-      else
-      {
-         URL url = new URL(gadgetPath);
-         return URLTools.getContent(url, 5000, 5000);
-      }
-   }
-
-   private String getGadgetURL() throws Exception
-   {
-      if (local)
-      {
-         return "http://www.gatein.org";
-      }
-      else
-      {
-         return gadgetPath;
-      }
-   }
-
-   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 doImport() throws Exception
-   {
-      if (registry.getGadget(name) != null)
-      {
-         log.debug("Will not import existing gagdet " + name);
-         return;
-      }
-
-      // Get bytes
-      byte[] bytes = getGadgetBytes();
-      if (bytes == null)
-      {
-         log.error("Cannot import gadget " + gadgetPath + " because its data could not be found");
-         return;
-      }
-
-      // Get encoding
-      String encoding = EncodingDetector.detect(new ByteArrayInputStream(bytes));
-
-      //
-      String gadget = new String(bytes, encoding);
-
-      //
-      String gadgetURL = getGadgetURL();
-      GadgetSpec spec = new GadgetSpec(Uri.parse(gadgetURL), gadget);
-      ModulePrefs prefs = spec.getModulePrefs();
-
-      //
-      GadgetDefinition def = registry.addGadget(name);
-
-      //
-      String description = prefs.getDescription();
-      String thumbnail = prefs.getThumbnail().toString();
-      String title = getGadgetTitle(prefs, name);
-      String referenceURL = prefs.getTitleUrl().toString();
-
-      //
-      log.info("Importing gadget name=" + name + " description=" + description + " thumbnail=" + thumbnail + " title=" +
-               thumbnail + " title=" + title);
-
-      //
-      def.setDescription(description);
-      def.setThumbnail(thumbnail); // Do something better than that
-      def.setTitle(title);
-      def.setReferenceURL(referenceURL);
-      def.setLocal(local);
-
-      //
-      if (local)
-      {
-         LocalGadgetData data = (LocalGadgetData)def.getData();
-
-         //
-         String fileName = getName(gadgetPath);
-         data.setFileName(fileName);
-
-         // Import resource
-         folder = data.getResources();
-         String folderPath = getParent(gadgetPath);
-         visitChildren(folderPath);
-         folder = null;
-      }
-      else
-      {
-         RemoteGadgetData data = (RemoteGadgetData)def.getData();
-
-         // Set remote URL
-         data.setURL(gadgetPath);
-      }
-   }
-
-   private void visit(String resourcePath) throws Exception
-   {
-      String name = getName(resourcePath);
-      if (isFile(resourcePath))
-      {
-         byte[] content = getContent(resourcePath);
-
-         //
-         if (content != null)
-         {
-            String mimeType = getMimeType(name);
-
-            //
-            if (mimeType == null)
-            {
-               mimeType = "application/octet-stream";
-            }
-
-            // We can detect encoding for XML files
-            String encoding = null;
-            if ("application/xml".equals(mimeType))
-            {
-               encoding = EncodingDetector.detect(new ByteArrayInputStream(content));
-            }
-
-            // Correct mime type for gadgets
-            if (resourcePath.equals(gadgetPath)) {
-               mimeType = LocalGadgetData.GADGET_MIME_TYPE;
-            }
-
-            //
-            folder.createFile(name, new Resource(mimeType, encoding, content));
-         }
-      }
-      else
-      {
-         folder = folder.createFolder(name);
-         visitChildren(resourcePath);
-         folder = folder.getParent();
-      }
-   }
-
-   private void visitChildren(String folderPath) throws Exception
-   {
-      for (String childPath : getChildren(folderPath))
-      {
-         visit(childPath);
-      }
-   }
-
-   public abstract String getName(String resourcePath) throws IOException;
-
-   public abstract String getParent(String resourcePath) throws IOException;
-
-   public abstract byte[] getContent(String filePath) throws IOException;
-
-   public abstract Iterable<String> getChildren(String folderPath) throws IOException;
-
-   public abstract boolean isFile(String resourcePath) throws IOException;
-
-   public abstract String getMimeType(String fileName);
-}

Modified: epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/ServletLocalImporter.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/ServletLocalImporter.java	2011-09-14 09:45:02 UTC (rev 7412)
+++ epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/ServletLocalImporter.java	2011-09-14 10:00:18 UTC (rev 7413)
@@ -18,12 +18,16 @@
  */
 package org.exoplatform.application.gadget;
 
-import org.exoplatform.application.gadget.impl.GadgetRegistry;
+import org.chromattic.ext.ntdef.NTFolder;
+import org.chromattic.ext.ntdef.Resource;
+import org.exoplatform.application.gadget.impl.GadgetDefinition;
+import org.exoplatform.application.gadget.impl.LocalGadgetData;
 import org.gatein.common.io.IOTools;
 import org.gatein.common.logging.Logger;
 import org.gatein.common.logging.LoggerFactory;
 
 import javax.servlet.ServletContext;
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Set;
@@ -32,7 +36,7 @@
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
  */
-public class ServletLocalImporter extends LocalImporter
+public class ServletLocalImporter extends GadgetImporter
 {
 
    /** . */
@@ -41,22 +45,103 @@
    /** . */
    private final ServletContext servletContext;
 
+   /** Used temporarily when importing resources. */
+   private NTFolder folder;
+
    public ServletLocalImporter(
       String name,
-      GadgetRegistry registry,
       String gadgetPath,
-      ServletContext servletContext,
-      boolean local)
+      ServletContext servletContext)
    {
-      super(name, registry, gadgetPath, local);
+      super(name, gadgetPath);
 
       //
       this.servletContext = servletContext;
    }
 
    @Override
-   public String getName(String resourcePath) throws IOException
+   protected byte[] getGadgetBytes(String gadgetURI) throws IOException
    {
+      return getContent(gadgetURI);
+   }
+
+   @Override
+   protected String getGadgetURL(String gadgetURI) throws Exception
+   {
+      return gadgetURI;
+   }
+
+   @Override
+   protected void process(String gadgetURI, GadgetDefinition def) throws Exception
+   {
+      def.setLocal(true);
+
+      //
+      LocalGadgetData data = (LocalGadgetData)def.getData();
+
+      //
+      String fileName = getName(gadgetURI);
+      data.setFileName(fileName);
+
+      // Import resource
+      folder = data.getResources();
+      String folderPath = getParent(gadgetURI);
+      visitChildren(gadgetURI, folderPath);
+      folder = null;
+   }
+
+   private void visit(String uri, String resourcePath) throws Exception
+   {
+      String name = getName(resourcePath);
+      if (isFile(resourcePath))
+      {
+         byte[] content = getContent(resourcePath);
+
+         //
+         if (content != null)
+         {
+            String mimeType = getMimeType(name);
+
+            //
+            if (mimeType == null)
+            {
+               mimeType = "application/octet-stream";
+            }
+
+            // We can detect encoding for XML files
+            String encoding = null;
+            if ("application/xml".equals(mimeType))
+            {
+               encoding = EncodingDetector.detect(new ByteArrayInputStream(content));
+            }
+
+            // Correct mime type for gadgets
+            if (resourcePath.equals(uri)) {
+               mimeType = LocalGadgetData.GADGET_MIME_TYPE;
+            }
+
+            //
+            folder.createFile(name, new Resource(mimeType, encoding, content));
+         }
+      }
+      else
+      {
+         folder = folder.createFolder(name);
+         visitChildren(uri, resourcePath);
+         folder = folder.getParent();
+      }
+   }
+
+   private void visitChildren(String gadgetURI, String folderPath) throws Exception
+   {
+      for (String childPath : getChildren(folderPath))
+      {
+         visit(gadgetURI, childPath);
+      }
+   }
+
+   private String getName(String resourcePath) throws IOException
+   {
       // It's a directory, remove the trailing '/'
       if (resourcePath.endsWith("/"))
       {
@@ -70,8 +155,7 @@
       return resourcePath.substring(index + 1);
    }
 
-   @Override
-   public String getParent(String resourcePath) throws IOException
+   private String getParent(String resourcePath) throws IOException
    {
       // It's a directory, remove the trailing '/'
       if (resourcePath.endsWith("/"))
@@ -86,8 +170,7 @@
       return resourcePath.substring(0, index + 1);
    }
 
-   @Override
-   public byte[] getContent(String filePath) throws IOException
+   private byte[] getContent(String filePath) throws IOException
    {
       InputStream in = servletContext.getResourceAsStream(filePath);
       if (in == null)
@@ -101,21 +184,18 @@
       }
    }
 
-   @Override
-   public Iterable<String> getChildren(String folderPath) throws IOException
+   private Iterable<String> getChildren(String folderPath) throws IOException
    {
-      @SuppressWarnings("unchecked") Set resourcePaths = servletContext.getResourcePaths(folderPath);
+      @SuppressWarnings("unchecked") Set<String> resourcePaths = servletContext.getResourcePaths(folderPath);
       return resourcePaths;
    }
 
-   @Override
-   public boolean isFile(String resourcePath) throws IOException
+   private boolean isFile(String resourcePath) throws IOException
    {
       return !resourcePath.endsWith("/");
    }
 
-   @Override
-   public String getMimeType(String fileName)
+   private String getMimeType(String fileName)
    {
       return servletContext.getMimeType(fileName);
    }

Modified: epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java	2011-09-14 09:45:02 UTC (rev 7412)
+++ epp/portal/branches/EPP_5_2_Branch/component/application-registry/src/main/java/org/exoplatform/application/gadget/impl/GadgetRegistryServiceImpl.java	2011-09-14 10:00:18 UTC (rev 7413)
@@ -23,6 +23,7 @@
 import org.chromattic.ext.ntdef.Resource;
 import org.exoplatform.application.gadget.Gadget;
 import org.exoplatform.application.gadget.GadgetRegistryService;
+import org.exoplatform.application.gadget.GadgetImporter;
 import org.exoplatform.application.registry.impl.ApplicationRegistryChromatticLifeCycle;
 import org.exoplatform.commons.chromattic.ChromatticLifeCycle;
 import org.exoplatform.commons.chromattic.ChromatticManager;
@@ -30,11 +31,14 @@
 import org.exoplatform.container.xml.InitParams;
 import org.exoplatform.container.xml.PropertiesParam;
 import org.exoplatform.container.xml.ValueParam;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.concurrent.Callable;
 
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
@@ -44,6 +48,9 @@
 {
 
    /** . */
+   private final Logger log = LoggerFactory.getLogger(GadgetRegistryServiceImpl.class);
+
+   /** . */
    private static final String DEFAULT_DEVELOPER_GROUP = "/platform/administrators";
 
    /** . */
@@ -120,13 +127,23 @@
       return registry;
    }
 
-   public ChromatticLifeCycle getChromatticLifeCycle()
+   // ***************
+
+   public void deploy(Iterable<GadgetImporter> gadgets)
    {
-      return chromatticLifeCycle;
+      for (GadgetImporter importer : gadgets)
+      {
+         try
+         {
+            new DeployTask(importer).call();
+         }
+         catch (Exception e)
+         {
+            log.error("Could not process gadget file " + importer, e);
+         }
+      }
    }
 
-   // ***************
-
    public Gadget getGadget(String name) throws Exception
    {
       GadgetRegistry registry = getRegistry();
@@ -285,4 +302,40 @@
    {
       return hostName;
    }
+
+   private class DeployTask implements Callable<Boolean>
+   {
+
+      /** . */
+      private final GadgetImporter importer;
+
+      private DeployTask(GadgetImporter importer)
+      {
+         this.importer = importer;
+      }
+
+      public Boolean call() throws Exception
+      {
+         chromatticLifeCycle.openContext();
+         try
+         {
+            boolean done = false;
+            if (getRegistry().getGadget(importer.getGadgetName()) == null)
+            {
+               GadgetDefinition def = getRegistry().addGadget(importer.getGadgetName());
+               importer.doImport(def);
+               done = true;
+            }
+            else
+            {
+               log.debug("Will not import existing gagdet " + importer.getGadgetName());
+            }
+            return done;
+         }
+         finally
+         {
+            chromatticLifeCycle.closeContext(true);
+         }
+      }
+   }
 }


Property changes on: epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org
___________________________________________________________________
Modified: svn:mergeinfo
   - /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component/portal/src/main/java/org:5868
/portal/branches/branch-GTNPORTAL-1592/component/portal/src/main/java/org:4894
/portal/branches/branch-GTNPORTAL-1643/component/portal/src/main/java/org:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component/portal/src/main/java/org:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component/portal/src/main/java/org:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/component/portal/src/main/java/org:5765
/portal/branches/branch-GTNPORTAL-1790/component/portal/src/main/java/org:5871
/portal/branches/branch-GTNPORTAL-1822/component/portal/src/main/java/org:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component/portal/src/main/java/org:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component/portal/src/main/java/org:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component/portal/src/main/java/org:6603
/portal/branches/branch-GTNPORTAL-1963/component/portal/src/main/java/org:6904,6915-6916
/portal/trunk/component/portal/src/main/java/org:4891,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6223,6292,6437,6440,6449,6452,6573,6741,6783-6784,6912-6913,6960,7042,7061,7095,7117,7120,7125,7132-7134,7239,7262,7308,7326,7331,7359,7367
   + /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/component/portal/src/main/java/org:5868
/portal/branches/branch-GTNPORTAL-1592/component/portal/src/main/java/org:4894
/portal/branches/branch-GTNPORTAL-1643/component/portal/src/main/java/org:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/component/portal/src/main/java/org:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/component/portal/src/main/java/org:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/component/portal/src/main/java/org:5765
/portal/branches/branch-GTNPORTAL-1790/component/portal/src/main/java/org:5871
/portal/branches/branch-GTNPORTAL-1822/component/portal/src/main/java/org:5943,5952
/portal/branches/branch-GTNPORTAL-1832/component/portal/src/main/java/org:6030,6063
/portal/branches/branch-GTNPORTAL-1872/component/portal/src/main/java/org:6400,6551
/portal/branches/branch-GTNPORTAL-1921/component/portal/src/main/java/org:6603
/portal/branches/branch-GTNPORTAL-1963/component/portal/src/main/java/org:6904,6915-6916
/portal/trunk/component/portal/src/main/java/org:4891,5269,5744,5822,5943,6031,6033,6168,6196,6201-6203,6205-6206,6223,6292,6323,6437,6440,6449,6452,6573,6741,6783-6784,6912-6913,6960,7042,7061,7095,7117,7120,7125,7132-7134,7239,7262,7308,7326,7331,7359,7367

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-09-14 09:45:02 UTC (rev 7412)
+++ epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java	2011-09-14 10:00:18 UTC (rev 7413)
@@ -20,8 +20,8 @@
 package org.exoplatform.gadget.webui.component;
 
 import org.exoplatform.application.gadget.Gadget;
+import org.exoplatform.application.gadget.GadgetImporter;
 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;
@@ -54,7 +54,7 @@
 {
    final static public String LOCAL_STRING = "local://";
 
-   private static final Logger log = LoggerFactory.getLogger(LocalImporter.class);
+   private static final Logger log = LoggerFactory.getLogger(GadgetImporter.class);
 
    /** User pref. */
    private String userPref;


Property changes on: epp/portal/branches/EPP_5_2_Branch/wsrp-integration
___________________________________________________________________
Modified: svn:mergeinfo
   - /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/wsrp-integration:5868
/portal/branches/branch-GTNPORTAL-1592/wsrp-integration:4894
/portal/branches/branch-GTNPORTAL-1643/wsrp-integration:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/wsrp-integration:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/wsrp-integration:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/wsrp-integration:5765
/portal/branches/branch-GTNPORTAL-1790/wsrp-integration:5871
/portal/branches/branch-GTNPORTAL-1822/wsrp-integration:5943,5952
/portal/branches/branch-GTNPORTAL-1832/wsrp-integration:6030,6063
/portal/branches/branch-GTNPORTAL-1872/wsrp-integration:6400,6551
/portal/branches/branch-GTNPORTAL-1921/wsrp-integration:6603
/portal/branches/branch-GTNPORTAL-1963/wsrp-integration:6904,6915-6916
/portal/branches/decoupled-webos/wsrp-integration:6214-6243
/portal/branches/gatein-management/wsrp-integration:6920-6958
/portal/branches/global-portlet-metadata/wsrp-integration:6298-6384
/portal/branches/site-describability/wsrp-integration:6171-6235
/portal/trunk/wsrp-integration:4891,5744,5822,5943,6168,6196,6201-6203,6205-6206,6223,6323,6437,6440,6449,6452,6573,6741,6783-6784,6912-6913,6960,7042,7061,7095,7117,7125,7132-7134,7239,7262,7308,7326,7331,7359,7367
   + /epp/portal/branches/EPP_5_1_0_GA_JBEPP-795/wsrp-integration:5868
/portal/branches/branch-GTNPORTAL-1592/wsrp-integration:4894
/portal/branches/branch-GTNPORTAL-1643/wsrp-integration:5002,5063,5167
/portal/branches/branch-GTNPORTAL-1700/wsrp-integration:5348,5363,5402,5445
/portal/branches/branch-GTNPORTAL-1731/wsrp-integration:5622,5644,5668
/portal/branches/branch-GTNPORTAL-1745/wsrp-integration:5765
/portal/branches/branch-GTNPORTAL-1790/wsrp-integration:5871
/portal/branches/branch-GTNPORTAL-1822/wsrp-integration:5943,5952
/portal/branches/branch-GTNPORTAL-1832/wsrp-integration:6030,6063
/portal/branches/branch-GTNPORTAL-1872/wsrp-integration:6400,6551
/portal/branches/branch-GTNPORTAL-1921/wsrp-integration:6603
/portal/branches/branch-GTNPORTAL-1963/wsrp-integration:6904,6915-6916
/portal/branches/decoupled-webos/wsrp-integration:6214-6243
/portal/branches/gatein-management/wsrp-integration:6920-6958
/portal/branches/global-portlet-metadata/wsrp-integration:6298-6384
/portal/branches/site-describability/wsrp-integration:6171-6235
/portal/trunk/wsrp-integration:4891,5269,5744,5822,5943,6168,6196,6201-6203,6205-6206,6223,6323,6437,6440,6449,6452,6573,6741,6783-6784,6912-6913,6960,7042,7061,7095,7117,7125,7132-7134,7239,7262,7308,7326,7331,7359,7367



More information about the gatein-commits mailing list