Author: sohil.shah(a)jboss.com
Date: 2008-07-01 09:14:12 -0400 (Tue, 01 Jul 2008)
New Revision: 11230
Added:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/test/cms/commands/TestFileSize.java
Modified:
branches/JBoss_Portal_Branch_2_6/cms/build.xml
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/FileImpl.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentCreateCommand.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentGetCommand.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentGetVersionsCommand.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileGetListCommand.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileUpdateAndVersionCommand.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileUpdateCommand.java
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/model/File.java
Log:
JBPORTAL-2016 - CMS content object should have a method to return the size of the latest
version of the file
Modified: branches/JBoss_Portal_Branch_2_6/cms/build.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/cms/build.xml 2008-07-01 07:55:01 UTC (rev 11229)
+++ branches/JBoss_Portal_Branch_2_6/cms/build.xml 2008-07-01 13:14:12 UTC (rev 11230)
@@ -411,6 +411,7 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileCreate"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileUpdate"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileSize"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileArchiveUpload"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileGetVersion"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.cms.commands.TestFileGet"/>
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/FileImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/FileImpl.java 2008-07-01
07:55:01 UTC (rev 11229)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/FileImpl.java 2008-07-01
13:14:12 UTC (rev 11230)
@@ -34,19 +34,8 @@
{
/** The serialVersionUID */
private static final long serialVersionUID = 7700626816158921578L;
- protected long fileSize;
protected Content content;
- public long getFileSize()
- {
- return fileSize;
- }
-
- public void setFileSize(long fileSize)
- {
- this.fileSize = fileSize;
- }
-
public void setContent(Locale locale, Content content)
{
this.content = content;
@@ -64,5 +53,10 @@
return this.content;
}
+
+ public long getSize()
+ {
+ return this.content.getSize();
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentCreateCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentCreateCommand.java 2008-07-01
07:55:01 UTC (rev 11229)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentCreateCommand.java 2008-07-01
13:14:12 UTC (rev 11230)
@@ -62,6 +62,8 @@
contentNode.setProperty("portalcms:description", new
StringValue(mFile.getContent().getDescription()));
contentNode.setProperty("portalcms:title", new
StringValue(mFile.getContent().getTitle()));
contentNode.setProperty("portalcms:language", new
StringValue(mFile.getContent().getLocale().getLanguage()));
+ contentNode.setProperty("portalcms:size", new StringValue(String
+ .valueOf(mFile.getContent().getBytes().length)));
if (mFile.getContent().getMimeType() != null)
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentGetCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentGetCommand.java 2008-07-01
07:55:01 UTC (rev 11229)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentGetCommand.java 2008-07-01
13:14:12 UTC (rev 11230)
@@ -102,6 +102,11 @@
content.setLastModified(contentNode.getProperty("jcr:lastModified").getDate().getTime());
content.setBasePath(this.msPath + "/" + this.mlocale.getLanguage());
content.setDescription(contentNode.getProperty("portalcms:description").getString());
+ if (contentNode.hasProperty("portalcms:size"))
+ {
+ long size =
Long.parseLong(contentNode.getProperty("portalcms:size").getString());
+ content.setSize(size);
+ }
if (this.msVersionNumber == null) // get LIVE
{
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentGetVersionsCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentGetVersionsCommand.java 2008-07-01
07:55:01 UTC (rev 11229)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/ContentGetVersionsCommand.java 2008-07-01
13:14:12 UTC (rev 11230)
@@ -95,10 +95,10 @@
content.setVersionUUID(node.getUUID());
content.setBytes("".getBytes());
- int size = 0;
+ long size = 0;
if (node.hasProperty("portalcms:size"))
{
- size =
Integer.parseInt(node.getProperty("portalcms:size").getString());
+ size =
Long.parseLong(node.getProperty("portalcms:size").getString());
}
content.setSize(size);
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileGetListCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileGetListCommand.java 2008-07-01
07:55:01 UTC (rev 11229)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileGetListCommand.java 2008-07-01
13:14:12 UTC (rev 11230)
@@ -81,6 +81,11 @@
content.setEncoding(contentNode.getProperty("jcr:encoding").getString());
content.setStream(contentNode.getProperty("jcr:data").getStream());
content.setLocale(new
Locale(contentNode.getProperty("portalcms:language").getString()));
+ if (contentNode.hasProperty("portalcms:size"))
+ {
+ long size =
Long.parseLong(contentNode.getProperty("portalcms:size").getString());
+ content.setSize(size);
+ }
contents.add(content);
}
}
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileUpdateAndVersionCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileUpdateAndVersionCommand.java 2008-07-01
07:55:01 UTC (rev 11229)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileUpdateAndVersionCommand.java 2008-07-01
13:14:12 UTC (rev 11230)
@@ -24,6 +24,7 @@
import org.apache.jackrabbit.value.BinaryValue;
import org.apache.jackrabbit.value.DateValue;
+import org.apache.jackrabbit.value.StringValue;
import org.jboss.portal.cms.CMSMimeMappings;
import org.jboss.portal.cms.impl.jcr.JCRCommand;
import org.jboss.portal.cms.impl.jcr.util.VersionUtil;
@@ -66,6 +67,8 @@
contentNode.setProperty("jcr:encoding", "UTF-8");
contentNode.setProperty("jcr:data", new
BinaryValue(mFile.getContent().getBytes()));
contentNode.setProperty("jcr:lastModified", timestamp);
+ contentNode.setProperty("portalcms:size", new StringValue(String
+ .valueOf(mFile.getContent().getBytes().length)));
if (mFile.getContent().getMimeType() != null)
{
@@ -91,7 +94,7 @@
//Update the lastModified Property of the FileNode of this content
Node fileNode = (Node)context.getSession().getItem(mFile.getBasePath());
- fileNode.setProperty("jcr:lastModified", timestamp);
+ fileNode.setProperty("jcr:lastModified", timestamp);
// Update the folder modified date
fileNode.getParent().setProperty("portalcms:lastmodified",
timestamp);
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileUpdateCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileUpdateCommand.java 2008-07-01
07:55:01 UTC (rev 11229)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/impl/jcr/command/FileUpdateCommand.java 2008-07-01
13:14:12 UTC (rev 11230)
@@ -24,6 +24,7 @@
import org.apache.jackrabbit.value.BinaryValue;
import org.apache.jackrabbit.value.DateValue;
+import org.apache.jackrabbit.value.StringValue;
import org.jboss.portal.cms.CMSMimeMappings;
import org.jboss.portal.cms.impl.jcr.JCRCommand;
import org.jboss.portal.cms.model.File;
@@ -65,6 +66,8 @@
contentNode.setProperty("jcr:encoding", "UTF-8");
contentNode.setProperty("jcr:data", new
BinaryValue(mFile.getContent().getBytes()));
contentNode.setProperty("jcr:lastModified", timestamp);
+ contentNode.setProperty("portalcms:size", new StringValue(String
+ .valueOf(mFile.getContent().getBytes().length)));
if (mFile.getContent().getMimeType() != null)
{
@@ -86,7 +89,7 @@
//Update the lastModified Property of the FileNode of this content
Node fileNode = (Node)context.getSession().getItem(mFile.getBasePath());
- fileNode.setProperty("jcr:lastModified", timestamp);
+ fileNode.setProperty("jcr:lastModified", timestamp);
// Update the folder modified date
fileNode.getParent().setProperty("portalcms:lastmodified",
timestamp);
Modified:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/model/File.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/model/File.java 2008-07-01
07:55:01 UTC (rev 11229)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/cms/model/File.java 2008-07-01
13:14:12 UTC (rev 11230)
@@ -38,4 +38,6 @@
void setContent(Locale locale, Content content);
Content getContent();
+
+ long getSize();
}
Added:
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/test/cms/commands/TestFileSize.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/test/cms/commands/TestFileSize.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/cms/src/main/org/jboss/portal/test/cms/commands/TestFileSize.java 2008-07-01
13:14:12 UTC (rev 11230)
@@ -0,0 +1,178 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * 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.jboss.portal.test.cms.commands;
+
+import junit.framework.TestSuite;
+import org.jboss.portal.cms.Command;
+import org.jboss.portal.cms.impl.ContentImpl;
+import org.jboss.portal.cms.impl.FileImpl;
+import org.jboss.portal.cms.model.Content;
+import org.jboss.portal.cms.model.File;
+
+import java.util.Locale;
+
+
+/**
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class TestFileSize extends AbstractCommandTestCase
+{
+ String sFilePath = "/testdoc.gif";
+
+ String sCopyToFilePath = "/testdoccopy.gif";
+
+ // zip vars
+ String sZipPath = "/poop";
+
+ String sZipFile = "resources/test/jcr/ziptest.zip";
+
+ String sJPG = "/hibernate_logo.gif";
+
+ String sText = "/training.txt";
+
+
+ /**
+ *
+ *
+ */
+ public TestFileSize()
+ {
+ }
+
+ /**
+ *
+ *
+ */
+ public static TestSuite suite() throws Exception
+ {
+ return createTestSuite(TestFileSize.class);
+ }
+
+ /**
+ *
+ *
+ */
+ public void testFileCreate() throws Exception
+ {
+ // create file english
+ File file = new FileImpl();
+ file.setBasePath(sFilePath);
+
+ Content content = new ContentImpl();
+ content.setEncoding("UTF-8");
+ content.setTitle("English Title");
+ content.setDescription("English Description");
+ content.setBasePath(sFilePath + "/" + Locale.ENGLISH.getLanguage());
+ content.setBytes("1234567890".getBytes());
+ content.setMimeType("image/gif");
+ file.setContent(Locale.ENGLISH, content);
+
+ // save english file
+ Command saveFileCMD = service.getCommandFactory().createFileSaveCommand(file);
+ service.execute(saveFileCMD);
+
+ //save english content
+ Command saveContentCMD =
service.getCommandFactory().createContentSaveCommand(file);
+ service.execute(saveContentCMD);
+
+ // version the english content node
+ Command verCMD =
service.getCommandFactory().createContentCreateNewVersionCommand(content, true);
+ service.execute(verCMD);
+
+ Command fileGet = service.getCommandFactory().createFileGetCommand(sFilePath,
Locale.ENGLISH);
+ File cour = (File)service.execute(fileGet);
+ assertEquals("File Size Incorrect", cour.getSize(),
"1234567890".length());
+
+
+ //create content spanish
+ Content contentSP = new ContentImpl();
+ contentSP.setEncoding("UTF-8");
+ contentSP.setTitle("Spanish Title");
+ contentSP.setDescription("Spanish Description");
+ contentSP.setBasePath(sFilePath + "/es");
+ contentSP.setBytes("0987654321/es".getBytes());
+ contentSP.setMimeType("image/gif");
+ file.setContent(new Locale("es"), contentSP);
+
+ //save spanish content
+ Command saveSPContentCMD =
service.getCommandFactory().createContentSaveCommand(file);
+ service.execute(saveSPContentCMD);
+
+ // version the spanish content node
+ Command verSPCMD =
service.getCommandFactory().createContentCreateNewVersionCommand(contentSP, true);
+ service.execute(verSPCMD);
+
+ fileGet = service.getCommandFactory().createFileGetCommand(sFilePath, new
Locale("es"));
+ cour = (File)service.execute(fileGet);
+ assertEquals("File Size Incorrect", cour.getSize(),
"0987654321/es".length());
+ }
+
+ /**
+ *
+ *
+ */
+ public void testFileUpdate() throws Exception
+ {
+ // create file english
+ File file = new FileImpl();
+ file.setBasePath(sFilePath);
+
+ Content content = new ContentImpl();
+ content.setEncoding("UTF-8");
+ content.setTitle("English Title");
+ content.setDescription("English Description");
+ content.setBasePath(sFilePath + "/" + Locale.ENGLISH.getLanguage());
+ content.setBytes("1234567890".getBytes());
+ content.setMimeType("image/gif");
+ file.setContent(Locale.ENGLISH, content);
+
+ // save english file
+ Command saveFileCMD = service.getCommandFactory().createFileSaveCommand(file);
+ service.execute(saveFileCMD);
+
+ //save english content
+ Command saveContentCMD = service.getCommandFactory().createContentSaveCommand(file);
+ service.execute(saveContentCMD);
+
+ // version the english content node
+ Command verCMD =
service.getCommandFactory().createContentCreateNewVersionCommand(content, true);
+ service.execute(verCMD);
+
+ Command fileGet = service.getCommandFactory().createFileGetCommand(sFilePath,
Locale.ENGLISH);
+ File cour = (File)service.execute(fileGet);
+ assertEquals("File Size Incorrect", cour.getSize(),
"1234567890".length());
+ assertEquals("File Content Incorrect", new
String(cour.getContent().getBytes()), "1234567890");
+
+ //Now Update this content and create a new version
+ content.setBytes("1234567890/updated".getBytes());
+ Command cmdUpdate = service.getCommandFactory().createUpdateFileCommand(file,
content, true);
+ service.execute(cmdUpdate);
+
+ fileGet = service.getCommandFactory().createFileGetCommand(sFilePath,
Locale.ENGLISH);
+ cour = (File)service.execute(fileGet);
+ assertEquals("File Size Incorrect", cour.getSize(),
"1234567890/updated".length());
+ assertEquals("File Content Incorrect", new
String(cour.getContent().getBytes()), "1234567890/updated");
+ }
+}