Author: hoang_to
Date: 2009-11-05 04:29:56 -0500 (Thu, 05 Nov 2009)
New Revision: 504
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigRemoval.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinDependentManager.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/PortalSkinTask.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/PortletSkinTask.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/AbstractTaskXMLBinding.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/GateinResource.java
Log:
GTNPORTAL-130: Skin undeployment
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigRemoval.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigRemoval.java 2009-11-05
09:15:32 UTC (rev 503)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateinSkinConfigRemoval.java 2009-11-05
09:29:56 UTC (rev 504)
@@ -18,26 +18,30 @@
*/
package org.exoplatform.portal.resource;
+import java.util.List;
+import java.util.Set;
+
import org.gatein.wci.WebAppEvent;
import org.gatein.wci.WebAppLifeCycleEvent;
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* @version $Id$
- *
+ *
*/
public class GateinSkinConfigRemoval extends AbstractResourceHandler
{
-
+
private SkinService service;
-
+
private String portalContainerName;
-
- public GateinSkinConfigRemoval(String _portalContainerName, SkinService _service){
+
+ public GateinSkinConfigRemoval(String _portalContainerName, SkinService _service)
+ {
this.portalContainerName = _portalContainerName;
this.service = _service;
}
-
+
/**
* @see
org.exoplatform.portal.resource.AbstractResourceHandler#onEvent(org.gatein.wci.WebAppEvent)
*/
@@ -45,12 +49,63 @@
public void onEvent(WebAppEvent event)
{
// TODO Auto-generated method stub
- if(event instanceof WebAppLifeCycleEvent){
+ if (event instanceof WebAppLifeCycleEvent)
+ {
WebAppLifeCycleEvent waEvent = (WebAppLifeCycleEvent)event;
- if(waEvent.getType() == WebAppLifeCycleEvent.REMOVED){
-
+ if (waEvent.getType() == WebAppLifeCycleEvent.REMOVED)
+ {
+ String webApp = event.getWebApp().getServletContext().getContextPath();
+ removeWebAppSkin(webApp);
}
}
}
+ private void removeWebAppSkin(String webApp)
+ {
+ try
+ {
+ removePortalSkins(webApp);
+ removePortletSkins(webApp);
+ removeSkinName(webApp);
+
+ // Update the 'skinDependentManager'
+ SkinDependentManager.clearAssociatedSkins(webApp);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ private void removePortalSkins(String webApp) throws Exception
+ {
+ List<SkinKey> portalSkins = SkinDependentManager.getPortalSkins(webApp);
+ service.remove(portalSkins);
+ }
+
+ private void removePortletSkins(String webApp) throws Exception
+ {
+ List<SkinKey> portletSkins = SkinDependentManager.getPortletSkins(webApp);
+ service.remove(portletSkins);
+ }
+
+ /**
+ * Remove skinName defined by the webApp, if no other webApps supports the
+ * skinName
+ */
+ private void removeSkinName(String webApp) throws Exception
+ {
+ Set<String> supportedSkins = SkinDependentManager.getSkinNames(webApp);
+ if (supportedSkins != null)
+ {
+ for (String skin : supportedSkins)
+ {
+ if (SkinDependentManager.skinNameIsRemovable(skin, webApp))
+ {
+ service.removeSupportedSkin(skin);
+ }
+ }
+ }
+ }
+
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinDependentManager.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinDependentManager.java 2009-11-05
09:15:32 UTC (rev 503)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinDependentManager.java 2009-11-05
09:29:56 UTC (rev 504)
@@ -18,20 +18,130 @@
*/
package org.exoplatform.portal.resource;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* @version $Id$
- *
+ *
*/
public class SkinDependentManager
-{
-
- /** Map of skinName (Default, Mac, Vista ) and associated web applications */
- private static Map<String, List<String>> skinName_dependentApps_Map = new
HashMap<String, List<String>>();
+{
-
+ private static Map<String, Set<String>> skinName_Apps_map = new
HashMap<String, Set<String>>();
+
+ private static Map<String, Set<String>> app_skinNames_map = new
HashMap<String, Set<String>>();
+
+ private static Map<String, List<SkinKey>> app_portalSkins_map = new
HashMap<String, List<SkinKey>>();
+
+ private static Map<String, List<SkinKey>> app_portletSkins_map = new
HashMap<String, List<SkinKey>>();
+
+ public static void addSkinDeployedInApp(String webApp, String skinName)
+ {
+ Set<String> skinsDefinedInApp = app_skinNames_map.get(webApp);
+ if (skinsDefinedInApp == null)
+ {
+ skinsDefinedInApp = new HashSet<String>();
+ skinsDefinedInApp.add(skinName);
+ app_skinNames_map.put(webApp, skinsDefinedInApp);
+ return;
+ }
+ skinsDefinedInApp.add(skinName);
+ }
+
+ public static void addDependentAppToSkinName(String skinName, String dependentApp)
+ {
+ Set<String> dependentApps = skinName_Apps_map.get(skinName);
+ if (dependentApps == null)
+ {
+ dependentApps = new HashSet<String>();
+ dependentApps.add(dependentApp);
+ skinName_Apps_map.put(skinName, dependentApps);
+ return;
+ }
+ dependentApps.add(dependentApp);
+ }
+
+ public static boolean skinNameIsRemovable(String skinName, String dependentApp)
+ {
+ Set<String> dependentApps = skinName_Apps_map.get(skinName);
+ if (dependentApps == null)
+ {
+ return false;
+ }
+ // Remove the dependentApp defining 'skinName' skin
+ dependentApps.remove(dependentApp);
+
+ if (dependentApps.isEmpty())
+ {
+ skinName_Apps_map.remove(skinName);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public static void addPortalSkin(String webApp, String moduleName, String skinName)
+ {
+ addSkin(webApp, new SkinKey(moduleName, skinName), app_portalSkins_map);
+ }
+
+ public static void addPortletSkin(String webApp, String moduleName, String skinName)
+ {
+ addSkin(webApp, new SkinKey(moduleName, skinName), app_portletSkins_map);
+ }
+
+ public static List<SkinKey> getPortalSkins(String webApp)
+ {
+ return app_portalSkins_map.get(webApp);
+ }
+
+ public static List<SkinKey> getPortletSkins(String webApp)
+ {
+ return app_portletSkins_map.get(webApp);
+ }
+
+ public static Set<String> getSkinNames(String webApp)
+ {
+ return app_skinNames_map.get(webApp);
+ }
+
+ public static void clearAssociatedSkins(String webApp)
+ {
+ app_portalSkins_map.remove(webApp);
+ app_portletSkins_map.remove(webApp);
+ }
+
+ public static void removeSkinName(String webApp, String skinName)
+ {
+ Set<String> skinsDefinedInApp = app_skinNames_map.get(webApp);
+ if (skinsDefinedInApp == null)
+ {
+ return;
+ }
+ else
+ {
+ skinsDefinedInApp.remove(skinName);// TODO: Check the remove here
+ }
+ }
+
+ private static void addSkin(String webApp, SkinKey key, Map<String,
List<SkinKey>> map)
+ {
+ List<SkinKey> skinKeys = map.get(webApp);
+ if (skinKeys == null)
+ {
+ skinKeys = new ArrayList<SkinKey>(5);
+ skinKeys.add(key);
+ map.put(webApp, skinKeys);
+ return;
+ }
+ skinKeys.add(key);
+ }
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java 2009-11-05
09:15:32 UTC (rev 503)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java 2009-11-05
09:29:56 UTC (rev 504)
@@ -97,7 +97,7 @@
/** The deployer. */
private final AbstractResourceHandler deployer;
-
+
/** The removal. */
private final AbstractResourceHandler removal;
@@ -116,15 +116,16 @@
private final MainResourceResolver mainResolver;
/**
- * The name of the portal container
- */
+ * The name of the portal container
+ */
final String portalContainerName;
/**
- * An id used for caching request. The id life cycle is the same than the class
instance because
- * we consider css will change until server is restarted. Of course this only applies
for the
- * developing mode set to false.
- */
+ * An id used for caching request. The id life cycle is the same than the
+ * class instance because we consider css will change until server is
+ * restarted. Of course this only applies for the developing mode set to
+ * false.
+ */
final String id = Long.toString(System.currentTimeMillis());
public SkinService(ExoContainerContext context)
@@ -137,7 +138,7 @@
portletThemes_ = new HashMap<String, Set<String>>();
portalContainerName = context.getPortalContainerName();
mainResolver = new MainResourceResolver(portalContainerName, skinConfigs_);
- deployer = new GateinSkinConfigDeployer(portalContainerName, this);
+ deployer = new GateinSkinConfigDeployer(portalContainerName, this);
removal = new GateinSkinConfigRemoval(portalContainerName, this);
}
@@ -154,12 +155,18 @@
/**
* Register the stylesheet for a portal Skin.
- *
- * @param module skin module identifier
- * @param skinName skin name
- * @param cssPath path uri to the css file. This is relative to the root context, use
leading '/'
- * @param scontext the webapp's {@link javax.servlet.ServletContext}
- * @param overwrite if any previous skin should be replaced by that one
+ *
+ * @param module
+ * skin module identifier
+ * @param skinName
+ * skin name
+ * @param cssPath
+ * path uri to the css file. This is relative to the root context,
+ * use leading '/'
+ * @param scontext
+ * the webapp's {@link javax.servlet.ServletContext}
+ * @param overwrite
+ * if any previous skin should be replaced by that one
*/
public void addPortalSkin(String module, String skinName, String cssPath,
ServletContext scontext, boolean overwrite)
{
@@ -196,8 +203,9 @@
/**
* Merge several skins into one single skin.
- *
- * @param skins the skins to merge
+ *
+ * @param skins
+ * the skins to merge
* @return the merged skin
*/
public Skin merge(Collection<SkinConfig> skins)
@@ -207,8 +215,9 @@
/**
* Add a resource resolver to plug external resolvers.
- *
- * @param resolver a resolver to add
+ *
+ * @param resolver
+ * a resolver to add
*/
public void addResourceResolver(ResourceResolver resolver)
{
@@ -265,8 +274,9 @@
/**
* Return the CSS content of the file specified by the given URI.
- *
- * @param cssPath path of the css to find
+ *
+ * @param cssPath
+ * path of the css to find
* @return the css
*/
public String getCSS(String cssPath)
@@ -390,6 +400,23 @@
skinConfigs_.remove(key);
}
+ public void removeSupportedSkin(String skinName) throws Exception
+ {
+ availableSkins_.remove(skinName);
+ }
+
+ public void remove(List<SkinKey> keys) throws Exception
+ {
+ if (keys == null)
+ {
+ return;
+ }
+ for (SkinKey key : keys)
+ {
+ skinConfigs_.remove(key);
+ }
+ }
+
public int size()
{
return skinConfigs_.size();
@@ -474,9 +501,11 @@
/**
* Filter what if it's annotated with the alternative orientation.
- *
- * @param line the line to include
- * @param orientation the orientation
+ *
+ * @param line
+ * the line to include
+ * @param orientation
+ * the orientation
* @return true if the line is included
*/
private boolean wantInclude(String line, Orientation orientation)
@@ -538,7 +567,9 @@
@Managed
@ManagedDescription("Reload a specified skin")
- public void reloadSkin(@ManagedDescription("The skin id")
@ManagedName("skinId") String skinId)
+ public void reloadSkin(@ManagedDescription("The skin id")
+ @ManagedName("skinId")
+ String skinId)
{
ltCache.remove(skinId);
rtCache.remove(skinId);
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/PortalSkinTask.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/PortalSkinTask.java 2009-11-05
09:15:32 UTC (rev 503)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/PortalSkinTask.java 2009-11-05
09:29:56 UTC (rev 504)
@@ -19,6 +19,7 @@
package org.exoplatform.portal.resource.config.tasks;
+import org.exoplatform.portal.resource.SkinDependentManager;
import org.exoplatform.portal.resource.SkinService;
import javax.servlet.ServletContext;
@@ -26,10 +27,10 @@
/**
*
* Created by eXoPlatform SAS
- *
+ *
* Author: Minh Hoang TO - hoang281283(a)gmail.com
- *
- * Sep 16, 2009
+ *
+ * Sep 16, 2009
*/
public class PortalSkinTask extends AbstractSkinTask
{
@@ -80,8 +81,19 @@
{
return;
}
- String fullCSSPath = scontext.getContextPath() + cssPath;
+ String contextPath = scontext.getContextPath();
+ String fullCSSPath = contextPath + cssPath;
skinService.addPortalSkin(moduleName, skinName, fullCSSPath, scontext, overwrite);
+ updateSkinDependentManager(contextPath, moduleName, skinName);
}
+ /** Update skinDependentManager as it is needed to undeploy skin at runtime */
+ private void updateSkinDependentManager(String webApp, String moduleName, String
skinName)
+ {
+ SkinDependentManager.addPortalSkin(webApp, moduleName, skinName);
+ SkinDependentManager.addSkinDeployedInApp(webApp, skinName);
+
+ // Remark: Invoked only in PortalSkinTask
+ SkinDependentManager.addDependentAppToSkinName(skinName, webApp);
+ }
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/PortletSkinTask.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/PortletSkinTask.java 2009-11-05
09:15:32 UTC (rev 503)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/tasks/PortletSkinTask.java 2009-11-05
09:29:56 UTC (rev 504)
@@ -19,6 +19,7 @@
package org.exoplatform.portal.resource.config.tasks;
+import org.exoplatform.portal.resource.SkinDependentManager;
import org.exoplatform.portal.resource.SkinService;
import javax.servlet.ServletContext;
@@ -26,10 +27,10 @@
/**
*
* Created by eXoPlatform SAS
- *
+ *
* Author: Minh Hoang TO - hoang281283(a)gmail.com
- *
- * Sep 16, 2009
+ *
+ * Sep 16, 2009
*/
public class PortletSkinTask extends AbstractSkinTask
{
@@ -87,8 +88,16 @@
applicationName = scontext.getContextPath();
}
String moduleName = applicationName + "/" + portletName;
- String fullCSSPath = scontext.getContextPath() + cssPath;
+ String contextPath = scontext.getContextPath();
+ String fullCSSPath = contextPath + cssPath;
skinService.addSkin(moduleName, skinName, fullCSSPath, scontext, overwrite);
+ updateSkinDependentManager(contextPath, moduleName, skinName);
}
+ private void updateSkinDependentManager(String webApp, String moduleName, String
skinName)
+ {
+ SkinDependentManager.addPortletSkin(webApp, moduleName, skinName);
+ SkinDependentManager.addSkinDeployedInApp(webApp, skinName);
+ }
+
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/AbstractTaskXMLBinding.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/AbstractTaskXMLBinding.java 2009-11-05
09:15:32 UTC (rev 503)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/AbstractTaskXMLBinding.java 2009-11-05
09:29:56 UTC (rev 504)
@@ -29,10 +29,10 @@
/**
*
* Created by eXoPlatform SAS
- *
+ *
* Author: Minh Hoang TO - hoang281283(a)gmail.com
- *
- * Sep 17, 2009
+ *
+ * Sep 17, 2009
*/
public abstract class AbstractTaskXMLBinding
{
@@ -53,6 +53,7 @@
PortalSkinTask pTask = new PortalSkinTask();
bindingCSSPath(pTask, element);
bindingSkinName(pTask, element);
+ bindingModuleName(pTask, element);
return pTask;
}
@@ -79,6 +80,17 @@
task.setSkinName(skinName);
}
+ private void bindingModuleName(PortalSkinTask task, Element element)
+ {
+ NodeList nodes = element.getElementsByTagName(GateinResource.SKIN_MODULE_TAG);
+ if (nodes == null || nodes.getLength() < 1)
+ {
+ return;
+ }
+ String skinModule = nodes.item(0).getFirstChild().getNodeValue();
+ task.setModuleName(skinModule);
+ }
+
}
public static class ThemeTaskXMLBinding extends AbstractTaskXMLBinding
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/GateinResource.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/GateinResource.java 2009-11-05
09:15:32 UTC (rev 503)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/GateinResource.java 2009-11-05
09:29:56 UTC (rev 504)
@@ -22,10 +22,10 @@
/**
*
* Created by eXoPlatform SAS
- *
+ *
* Author: Minh Hoang TO - hoang281283(a)gmail.com
- *
- * Sep 17, 2009
+ *
+ * Sep 17, 2009
*/
public interface GateinResource
{
@@ -34,6 +34,8 @@
final public static String SKIN_NAME_TAG = "skin-name";
+ final public static String SKIN_MODULE_TAG = "skin-module";
+
final public static String PORTAl_SKIN_TAG = "portal-skin";
final public static String PORTLET_SKIN_TAG = "portlet-skin";
@@ -51,12 +53,12 @@
final public static String STYLE_THEME_TAG = "style-theme";
final public static String THEME_NAME_TAG = "theme-name";
-
+
final public static String JAVA_SCRIPT_TAG = "javascript";
-
+
final public static String JAVA_SCRIPT_PARAM = "param";
-
+
final public static String JAVA_SCRIPT_MODULE = "js-module";
-
+
final public static String JAVA_SCRIPT_PATH = "js-path";
}