Author: sohil.shah(a)jboss.com
Date: 2008-12-31 16:05:25 -0500 (Wed, 31 Dec 2008)
New Revision: 12417
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/CMSException.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java
modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-unit.xml
Log:
JBPORTAL-2157 - User not notified when uploading nonexisting / wrong type archive in CMS
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/CMSException.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/CMSException.java 2008-12-22
16:52:59 UTC (rev 12416)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/CMSException.java 2008-12-31
21:05:25 UTC (rev 12417)
@@ -30,6 +30,10 @@
{
/** The serialVersionUID */
private static final long serialVersionUID = 3646107693814633408L;
+
+ public static final int INVALID_ARCHIVE = 1;
+
+ private int errorCode = 0;
public CMSException()
{
@@ -50,6 +54,11 @@
super(cause);
}
+ public CMSException(int errorCode)
+ {
+ this.errorCode = errorCode;
+ }
+
public boolean hasPathFormatFailure()
{
boolean pathFormatFailure = false;
@@ -61,4 +70,22 @@
return pathFormatFailure;
}
+
+ public String getMessageKey()
+ {
+ String key = "";
+
+ switch(this.errorCode)
+ {
+ case INVALID_ARCHIVE:
+ key = "INVALID_ARCHIVE_MESSAGE";
+ break;
+
+ default:
+ key = "";
+ break;
+ }
+
+ return key;
+ }
}
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java 2008-12-22
16:52:59 UTC (rev 12416)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java 2008-12-31
21:05:25 UTC (rev 12417)
@@ -22,10 +22,14 @@
******************************************************************************/
package org.jboss.portal.cms.impl.jcr.command;
+import java.io.File;
+import java.io.FileOutputStream;
+
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.log4j.Logger;
+import org.apache.tools.zip.ZipFile;
import org.jboss.mx.util.MBeanProxy;
import org.jboss.mx.util.MBeanServerLocator;
@@ -79,16 +83,58 @@
this.user = context.getAttribute(JCRCommandContext.scope, "user");
this.approvePublishWorkflow = context.getAttribute(JCRCommandContext.scope,
"approvePublishWorkflow");
+ //Validate the archive being uploaded
+ this.validateArchive();
+
Thread t = new Thread(new AsyncProcessor());
t.start();
return null;
+ }
+ catch(Exception e)
+ {
+ if(e instanceof CMSException)
+ {
+ throw (CMSException)e;
+ }
+ else
+ {
+ throw new CMSException(e);
+ }
}
+ }
+
+ private void validateArchive() throws CMSException
+ {
+ try
+ {
+ File tmpFile = this.getZipFile();
+ ZipFile zipFile = new ZipFile(tmpFile);
+ }
catch(Exception e)
{
- throw new CMSException(e);
+ throw new CMSException(CMSException.INVALID_ARCHIVE);
}
}
+
+ private File getZipFile() throws Exception
+ {
+ File zipFile = null;
+
+ zipFile = File.createTempFile("jbportal_", "_cmsimport.zip");
+ FileOutputStream fos = new FileOutputStream(zipFile.getCanonicalPath());
+ try
+ {
+ fos.write(this.archiveBytes);
+ fos.close();
+ }
+ finally
+ {
+ fos.close();
+ }
+
+ return zipFile;
+ }
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
*
Modified: modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-unit.xml
===================================================================
--- modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-unit.xml 2008-12-22 16:52:59
UTC (rev 12416)
+++ modules/cms/trunk/cms-jackrabbit/src/test/resources/jboss-unit.xml 2008-12-31 21:05:25
UTC (rev 12417)
@@ -3,9 +3,15 @@
xmlns="urn:jboss:jboss-unit:1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:jboss-unit:1.0 jboss-unit_1_0.xsd">
- <pojo>
+ <pojo>
<parameter name="datasources" value="datasources.xml"/>
- <parameter name="dataSourceName" value="hsqldb"/>
+ <parameter name="dataSourceName">
+ <value>hsqldb</value>
+ <!--
+ <value>mysql5</value>
+ <value>postgresql8</value>
+ -->
+ </parameter>
<parameter name="hibernateConfig"
value="hibernates.xml"/>
<test >
<class name="org.jboss.portal.cms.test.TestJackrabbit"/>
@@ -71,7 +77,13 @@
<pojo>
<parameter name="datasources" value="datasources.xml"/>
- <parameter name="dataSourceName" value="hsqldb"/>
+ <parameter name="dataSourceName">
+ <value>hsqldb</value>
+ <!--
+ <value>mysql5</value>
+ <value>postgresql8</value>
+ -->
+ </parameter>
<parameter name="hibernateConfig"
value="hibernates.xml"/>
<parameter name="standardIdentityConfig"
value="standardidentity-config.xml"/>
<parameter name="identityConfig" value="db-config.xml"/>
@@ -91,7 +103,13 @@
<pojo>
<parameter name="datasources" value="datasources.xml"/>
- <parameter name="dataSourceName" value="hsqldb"/>
+ <parameter name="dataSourceName">
+ <value>hsqldb</value>
+ <!--
+ <value>mysql5</value>
+ <value>postgresql8</value>
+ -->
+ </parameter>
<parameter name="hibernateConfig"
value="hibernates.xml"/>
<parameter name="standardIdentityConfig"
value="standardidentity-config.xml"/>
<parameter name="identityConfig" value="db-config.xml"/>