weaver 2004/07/02 07:15:35
Modified: portal/src/java/org/apache/jetspeed/deployment/impl
DeployDecoratorEventListener.java
DeployPortletAppEventListener.java
Log:
Refactored to matach interface changes
Revision Changes Path
1.4 +115 -70
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployDecoratorEventListener.java
Index: DeployDecoratorEventListener.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployDecoratorEventListener.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DeployDecoratorEventListener.java 25 Mar 2004 21:39:22 -0000 1.3
+++ DeployDecoratorEventListener.java 2 Jul 2004 14:15:35 -0000 1.4
@@ -7,15 +7,19 @@
package org.apache.jetspeed.deployment.impl;
import java.io.File;
-import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.vfs.AllFileSelector;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.VFS;
+import org.apache.commons.vfs.provider.local.LocalFileSystem;
import org.apache.jetspeed.deployment.DeploymentEvent;
import org.apache.jetspeed.deployment.DeploymentEventListener;
import org.apache.jetspeed.deployment.DeploymentException;
@@ -27,112 +31,153 @@
* DirectFolderEventListener
* </p>
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
- * @version $Id$
- *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
+ * @version $Id: DeployDecoratorEventListener.java,v 1.3 2004/03/25 21:39:22
+ * jford Exp $
+ *
*/
public class DeployDecoratorEventListener implements DeploymentEventListener
{
protected SimpleRegistry registry;
protected static final Log log = LogFactory.getLog("deployment");
+ protected FileSystemManager fsManager;
+ protected String deployToDir;
- public DeployDecoratorEventListener(SimpleRegistry registry)
+ public DeployDecoratorEventListener( SimpleRegistry registry, String
deployToDir ) throws IOException
{
this.registry = registry;
+
+ fsManager = VFS.getManager();
+
+ File checkFile = new File(deployToDir);
+ if (checkFile.exists())
+ {
+ this.deployToDir = deployToDir;
+ }
+ else
+ {
+ throw new FileNotFoundException("The deployment directory, " +
checkFile.getAbsolutePath()
+ + ", does not exist");
+ }
}
/**
* @see
org.apache.jetspeed.deployment.DeploymentEventListener#invoke(org.apache.jetspeed.deployment.DeploymentEvent)
*/
- public void invoke(DeploymentEvent event) throws DeploymentException
+ public void invokeDeploy( DeploymentEvent event ) throws DeploymentException
{
- // In most cases we are already looking at the target deployment directory
- // and all we need to do is register the folder name
- if (event.getEventType().equals(DeploymentEvent.EVENT_TYPE_DEPLOY))
+ InputStream configStream = null;
+
+ PropertiesConfiguration conf;
+ try
{
- PropertiesConfiguration conf;
- try
+
+ configStream =
event.getDeploymentObject().getConfiguration("decorator.properties");
+ if (configStream == null)
+ {
+ return;
+ }
+ else
{
+ conf = new PropertiesConfiguration();
+ conf.load(configStream);
+ }
+ }
+ catch (IOException e1)
+ {
+ // TODO Auto-generated catch block
- InputStream configStream =
event.getHandler().getConfiguration("decorator.properties");
- if (configStream == null)
+ throw new DeploymentException("Error reading configuration from jar: "
+ e1.toString(), e1);
+ }
+ finally
+ {
+ if (configStream != null)
+ {
+ try
{
- return;
+ configStream.close();
}
- else
+ catch (IOException e)
{
- conf = new PropertiesConfiguration();
- conf.load(configStream);
+
}
}
- catch (IOException e1)
+ }
+
+ String id = conf.getString("id");
+ if (id != null)
+ {
+ log.info("Found decorator deployment archive " + id);
+ Entry entry = new Entry();
+ entry.setId(id);
+ if (!registry.isRegistered(entry))
{
- // TODO Auto-generated catch block
+ log.info("Deploying decorator " + id);
+ FileObject sourceObject = null;
+ FileObject deployObject = null;
+ try
+ {
- throw new DeploymentException("Error reading configuration from
jar: " + e1.toString(), e1);
- }
+ String mediaType = conf.getString("media.type", "html");
+ log.info("Decorator " + id + " supports media type \"" +
mediaType + "\"");
+ String deployPath = deployToDir + File.separator + mediaType +
File.separator + id;
+ log.info("Deploying decorator " + id + " to " + deployPath);
+ sourceObject = event.getDeploymentObject().getFileObject();
+
+ deployObject = fsManager.resolveFile(deployPath);
+ deployObject.createFolder();
+ deployObject.copyFrom(sourceObject, new AllFileSelector());
- String id = conf.getString("id");
- if (id != null)
- {
- log.info("Found decorator deployment archive " + id);
- Entry entry = new Entry();
- entry.setId(id);
- if (!registry.isRegistered(entry))
+ registry.register(entry);
+ log.info("Registering decorator " + deployToDir + "/" + id);
+ }
+ catch (Exception e)
+ {
+ log.error("Error deploying decorator " + id + ": " +
e.toString(), e);
+
+ }
+ finally
{
- log.info("Deploying decorator " + id);
try
{
-
- String mediaType = conf.getString("media.type", "html");
- log.info("Decorator " + id + " supports media type \"" +
mediaType + "\"");
- String deployPath = event.getDeploymentRoot() +
File.separator + mediaType + File.separator + id;
- log.info("Deploying decorator " + id + " to " + deployPath);
- JarInputStream jis = (JarInputStream)
event.getHandler().getAsStream();
- JarEntry jarEntry = jis.getNextJarEntry();
- while (jarEntry != null)
+ if (sourceObject != null)
{
- String entryName = jarEntry.getName();
- log.info("Deploying " + entryName + " for decorator " +
id);
- File fullPath = new File(deployPath + File.separator +
entryName);
- if (!fullPath.exists())
- {
- // First create parnets
- fullPath.getParentFile().mkdirs();
- fullPath.createNewFile();
-
- }
-
- FileOutputStream fos = new FileOutputStream(fullPath);
- byte[] buf = new byte[1024];
- int len;
- while ((len = jis.read(buf)) > 0)
- {
- fos.write(buf, 0, len);
- }
-
- jarEntry = jis.getNextJarEntry();
+ sourceObject.close();
}
- registry.register(entry);
- log.info("Registering decorator " +
event.getDeploymentRoot() + "/" + id);
+ if (deployObject != null)
+ {
+ deployObject.close();
+ }
}
- catch (Exception e)
+ catch (FileSystemException e2)
{
- log.error("Error deploying decorator " + id + ": " +
e.toString(), e);
}
}
- log.info("Decorator " + id + " deployed and registered
successfuly.");
-
- }
- else
- {
- log.error("Unable to register directory, \"id\" attribute not
defined in configuration");
}
+ log.info("Decorator " + id + " deployed and registered successfuly.");
}
+ else
+ {
+ log.error("Unable to register directory, \"id\" attribute not defined
in configuration");
+ }
}
-}
+ /**
+ * <p>
+ * invokeUndeploy
+ * </p>
+ *
+ * @see
org.apache.jetspeed.deployment.DeploymentEventListener#invokeUndeploy(org.apache.jetspeed.deployment.DeploymentEvent)
+ * @param event
+ * @throws DeploymentException
+ */
+ public void invokeUndeploy( DeploymentEvent event ) throws DeploymentException
+ {
+ // TODO Auto-generated method stub
+
+ }
+}
\ No newline at end of file
1.14 +183 -122
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployPortletAppEventListener.java
Index: DeployPortletAppEventListener.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployPortletAppEventListener.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DeployPortletAppEventListener.java 23 Jun 2004 18:41:26 -0000 1.13
+++ DeployPortletAppEventListener.java 2 Jul 2004 14:15:35 -0000 1.14
@@ -7,25 +7,29 @@
package org.apache.jetspeed.deployment.impl;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
-import java.util.Locale;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.vfs.FileSystemManager;
import org.apache.jetspeed.cache.PortletCache;
import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
import org.apache.jetspeed.deployment.DeploymentEvent;
import org.apache.jetspeed.deployment.DeploymentEventListener;
import org.apache.jetspeed.deployment.DeploymentException;
-import org.apache.jetspeed.deployment.fs.FSObjectHandler;
+import org.apache.jetspeed.deployment.DeploymentObject;
import org.apache.jetspeed.factory.JetspeedPortletFactory;
+import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
import org.apache.jetspeed.tools.pamanager.PortletApplicationManagement;
import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
import org.apache.pluto.om.portlet.PortletApplicationDefinition;
import org.jdom.Document;
import org.jdom.Element;
+import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
/**
@@ -33,159 +37,216 @@
* DeployportletAppEventListener
* </p>
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
- * @version $Id$
- *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
+ * @version $Id: DeployPortletAppEventListener.java,v 1.13 2004/06/23 18:41:26
+ * weaver Exp $
+ *
*/
public class DeployPortletAppEventListener implements DeploymentEventListener
{
protected static final Log log = LogFactory.getLog("deployment");
private String webAppDir;
- private PortletApplicationManagement pam;
+ private PortletApplicationManagement pam;
private Map appNameToFile;
protected PortletRegistryComponent registry;
- protected Locale defaultLocale;
+ protected FileSystemManager fsManager;
-
- public DeployPortletAppEventListener(String webAppDir,
PortletApplicationManagement pam, PortletRegistryComponent registry, Locale
defaultLocale)
+ /**
+ *
+ * @param webAppDir
+ * @param pam
+ * @param registry
+ * @throws FileNotFoundException
+ * the <code>webAppDir</code> directory does not exist.
+ */
+ public DeployPortletAppEventListener( String webAppDir,
PortletApplicationManagement pam,
+ PortletRegistryComponent registry, FileSystemManager fsManager ) throws
FileNotFoundException
{
- this.webAppDir = webAppDir;
+ File checkFile = new File(webAppDir);
+ this.fsManager = fsManager;
+
+ if (checkFile.exists())
+ {
+ this.webAppDir = webAppDir;
+ }
+ else
+ {
+ throw new FileNotFoundException("The depoyment directory for portlet
applications \""
+ + checkFile.getAbsolutePath() + "\" does not exist.");
+ }
this.pam = pam;
- this.appNameToFile = new HashMap();
- this.registry = registry;
- this.defaultLocale = defaultLocale;
+ this.appNameToFile = new HashMap();
+ this.registry = registry;
}
/**
- * @see
org.apache.jetspeed.deployment.DeploymentEventListener#invoke(org.apache.jetspeed.deployment.DeploymentEvent)
+ * <p>
+ * doUnDeploy
+ * </p>
+ *
+ * @param event
+ * @throws DeploymentException
*/
- public void invoke(DeploymentEvent event) throws DeploymentException
+ public void invokeUndeploy( DeploymentEvent event ) throws DeploymentException
{
- if (event.getEventType().equals(DeploymentEvent.EVENT_TYPE_DEPLOY))
+ String paName = null;
+ try
{
- try
- {
- FSObjectHandler handler = (FSObjectHandler) event.getHandler();
- boolean isLocal =
handler.getFile().getName().startsWith("jetspeed-");
- InputStream portletXmlStream =
handler.getConfiguration("WEB-INF/portlet.xml");
- if (portletXmlStream == null)
- {
- return;
- }
- else
- {
- log.info("Loading portlet application from web archive " +
handler.getPath());
- SAXBuilder builder = new SAXBuilder();
- Document portletXml = builder.build(portletXmlStream);
- Element portletApp = portletXml.getRootElement();
- String id = portletApp.getAttributeValue("id");
- if (id == null)
- {
-
- String warFileName = handler.getFile().getName();
- int extensionIdx = warFileName.lastIndexOf(".war");
- id = warFileName.substring(0, extensionIdx);
- log.info("Application id not defined in portlet.xml so
using war name "+id);
- }
-
- if (registry.getPortletApplicationByIdentifier(id) != null)
- {
- log.info("Portlet application \"" + id + "\"" + " already
been registered. Skipping initial deployment.");
- // still need to register the filename to the app name so
undeploy works correctly
-
appNameToFile.put(handler.getFile().getName(), id);
- if(isLocal)
- {
- PortletApplicationWar paWar = new
PortletApplicationWar(handler.getPath(), id, "/"+id, defaultLocale, id, null );
-
JetspeedPortletFactory.addClassLoader(paWar.createClassloader(getClass().getClassLoader()));
- }
- return;
- }
-
- log.info("Preparing to deploy portlet app \"" + id + "\"");
-
- if(isLocal)
- {
- log.info(handler.getFile().getName()+" will be registered
as a local portlet applicaiton.");
- pam.register(id, id, handler.getPath());
- PortletApplicationWar paWar = new
PortletApplicationWar(handler.getPath(), id, "/"+id, defaultLocale, id, null );
-
JetspeedPortletFactory.addClassLoader(paWar.createClassloader(getClass().getClassLoader()));
- }
- else
- {
- log.info("Deploying portlet applicaion WAR
"+handler.getFile().getName());
- pam.deploy(webAppDir, handler.getPath(), id);
- }
-
-
- appNameToFile.put(handler.getFile().getName(),
id);
- log.info("Portlet app \"" + id + "\" " + "successfuly
deployed.");
-
- }
+
+ boolean isLocal = event.getName().startsWith("jetspeed-");
+ String filePath = event.getPath();
+ paName = (String) appNameToFile.get(filePath);
+ if (paName == null)
+ {
+ String msg = "Unable to locate application name for archive \"" +
filePath + "\"";
+ log.warn(msg);
+ throw new DeploymentException(msg);
}
- catch (Exception e1)
+
+ PortletApplicationWar deployedWar = null;
+
+ PortletApplicationDefinition pa =
registry.getPortletApplicationByIdentifier(paName);
+ String webAppContextRoot = null;
+
+ if (pa != null)
{
+ log.info("Removing a portlets from the PortletCache that belong to
portlet application " + paName);
+ PortletCache.removeAll(pa);
+ webAppContextRoot =
pa.getWebApplicationDefinition().getContextRoot();
+ }
+ else
+ {
+ webAppContextRoot = "/" + paName;
+ }
+
+
+ if (isLocal)
+ {
+ log.info("Preparing to unregister portlet application \"" + paName
+ "\"");
+ pam.unregister(paName);
+ }
+ else
+ {
+ log.info("Preparing to undeploy portlet application \"" + paName +
"\"");
- String msg = "Error deploying portlet app: " + e1.toString();
- throw new DeploymentException(msg, e1);
+ deployedWar = new PortletApplicationWar(webAppDir + "/" + paName,
paName, webAppContextRoot, fsManager);
+ pam.undeploy(deployedWar);
}
+
+ log.info("Portlet application \"" + paName + "\"" + " was successfuly
undeployed.");
}
- else if (event.getEventType().equals(DeploymentEvent.EVENT_TYPE_UNDEPLOY))
+ catch (Exception e)
{
- String paName = null;
- try
+ String msg = "Error undeploying portlet app " + paName + ": " +
e.toString();
+ if (e instanceof DeploymentException)
{
- FSObjectHandler handler = (FSObjectHandler) event.getHandler();
- boolean isLocal =
handler.getFile().getName().startsWith("jetspeed-");
- File fileThatWasRemoved = handler.getFile();
- String fileName = fileThatWasRemoved.getName();
- paName = (String) appNameToFile.get(fileName);
- if(paName == null)
- {
- String msg = "Unable to locate application name for archive
\""+fileName+"\"";
- log.warn(msg);
- throw new DeploymentException(msg);
- }
-
-
- PortletApplicationDefinition pa =
registry.getPortletApplicationByIdentifier(paName);
- if(pa != null)
+ throw (DeploymentException) e;
+ }
+ else
+ {
+ throw new DeploymentException(msg, e);
+ }
+
+ }
+ }
+
+ /**
+ * <p>
+ * doDeploy
+ * </p>
+ *
+ * @param event
+ * @throws DeploymentException
+ * @throws PortletApplicationException
+ * @throws IOException
+ * @throws JDOMException
+ */
+ public void invokeDeploy( DeploymentEvent event ) throws DeploymentException
+ {
+ InputStream portletXmlStream = null;
+ try
+ {
+ DeploymentObject deploymentObj = event.getDeploymentObject();
+ portletXmlStream =
deploymentObj.getConfiguration("WEB-INF/portlet.xml");
+ if (portletXmlStream == null)
+ {
+ return;
+ }
+
+
+ String fileName = deploymentObj.getName();
+ boolean isLocal = fileName.startsWith("jetspeed-");
+
+ log.info("Loading portlet application from web archive " +
deploymentObj.getPath());
+ SAXBuilder builder = new SAXBuilder();
+ Document portletXml = builder.build(portletXmlStream);
+ Element portletApp = portletXml.getRootElement();
+ String id = portletApp.getAttributeValue("id");
+ if (id == null)
+ {
+
+ String warFileName = fileName;
+ int extensionIdx = warFileName.lastIndexOf(".war");
+ id = warFileName.substring(0, extensionIdx);
+ log.info("Application id not defined in portlet.xml so using war
name " + id);
+ }
+
+ PortletApplicationWar paWar = new
PortletApplicationWar(deploymentObj.getFileObject(), id, "/" + id,
+ this.fsManager);
+
+ if (registry.getPortletApplicationByIdentifier(id) != null)
+ {
+ log.info("Portlet application \"" + id + "\""
+ + " already been registered. Skipping initial
deployment.");
+ // still need to register the filename to the app name so
+ // undeploy works correctly
+ appNameToFile.put(deploymentObj.getPath(), id);
+ if (isLocal)
{
- log.info("Removing a portlets from the PortletCache that belong
to portlet application "+paName);
- PortletCache.removeAll(pa);
+
JetspeedPortletFactory.addClassLoader(paWar.createClassloader(getClass().getClassLoader()));
}
-
-
- if(isLocal)
+ return;
+ }
+
+ log.info("Preparing to deploy portlet app \"" + id + "\"");
+
+ if (isLocal)
+ {
+ log.info(fileName + " will be registered as a local portlet
applicaiton.");
+ pam.register(paWar);
+
JetspeedPortletFactory.addClassLoader(paWar.createClassloader(getClass().getClassLoader()));
+ }
+ else
+ {
+ log.info("Deploying portlet applicaion WAR " + fileName);
+ pam.deploy(paWar);
+ }
+
+ appNameToFile.put(deploymentObj.getPath(), id);
+ log.info("Portlet app \"" + id + "\" " + "successfuly deployed.");
+ }
+ catch (Exception e)
+ {
+ String msg = "Error deploying portlet app: " + e.toString();
+ throw new DeploymentException(msg, e);
+ }
+ finally
+ {
+ if (portletXmlStream != null)
+ {
+ try
{
- log.info("Preparing to unregister portlet application
\""+paName+"\"");
- pam.unregister(paName, paName);
+ portletXmlStream.close();
}
- else
+ catch (IOException e1)
{
- log.info("Preparing to undeploy portlet application
\""+paName+"\"");
- pam.undeploy(webAppDir, paName);
+ // ignore
}
-
- log.info("Portlet application \""+paName+"\""+" was successfuly
undeployed.");
- }
- catch (Exception e)
- {
- String msg = "Error undeploying portlet app
"+paName+": " + e.toString();
- if(e instanceof DeploymentException)
- {
- throw (DeploymentException) e;
- }
- else
- {
- throw new DeploymentException(msg, e);
- }
-
}
-
}
}
-}
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]