Author: sohil.shah(a)jboss.com
Date: 2008-12-31 16:48:00 -0500 (Wed, 31 Dec 2008)
New Revision: 12419
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/CMSException.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties
Log:
JBPORTAL-2157 - User not notified when uploading nonexisting / wrong type archive in CMS
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/CMSException.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/CMSException.java 2008-12-31
21:06:30 UTC (rev 12418)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/CMSException.java 2008-12-31
21:48:00 UTC (rev 12419)
@@ -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:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java 2008-12-31
21:06:30 UTC (rev 12418)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/AsyncStoreArchiveCommand.java 2008-12-31
21:48:00 UTC (rev 12419)
@@ -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:
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2008-12-31
21:06:30 UTC (rev 12418)
+++
branches/JBoss_Portal_Branch_2_6/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSAdminPortlet.java 2008-12-31
21:48:00 UTC (rev 12419)
@@ -1079,12 +1079,26 @@
if (!item.isFormField())
{
byte[] archiveBytes = item.get();
-
+
Command storearchiveCMD =
CMSService.getCommandFactory().createAsyncStoreArchiveCommand(sPath, archiveBytes,
sLanguage);
- CMSService.execute(storearchiveCMD);
List messages = new ArrayList();
-
messages.add(this.resources.getObject("CMS_MSG_UPLOADARCHIVE_ASYNC"));
+
+ try
+ {
+ CMSService.execute(storearchiveCMD);
+
messages.add(this.resources.getObject("CMS_MSG_UPLOADARCHIVE_ASYNC"));
+ }
+ catch(CMSException cme)
+ {
+ String messageKey = cme.getMessageKey();
+ if(messageKey != null && messageKey.trim().length() >
0)
+ {
+ messages.add(this.resources.getObject(messageKey));
+ }
+ }
+
+
aReq.getPortletSession().setAttribute("messages",
messages);
aRes.setRenderParameter("path",
FileUtil.cleanDoubleSlashes(sPath));
Modified:
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties 2008-12-31
21:06:30 UTC (rev 12418)
+++
branches/JBoss_Portal_Branch_2_6/core-cms/src/resources/portal-cms-war/WEB-INF/classes/Resource.properties 2008-12-31
21:48:00 UTC (rev 12419)
@@ -149,4 +149,6 @@
CMS_DATE_PATTERN=MM/dd/yy HH:mm
+INVALID_ARCHIVE_MESSAGE=The archive being uploaded is not a valid archive file
+
Show replies by date