Author: mmillson
Date: 2008-01-24 17:28:21 -0500 (Thu, 24 Jan 2008)
New Revision: 9601
Modified:
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/cms/src/main/org/jboss/portal/test/cms/commands/TestFileGet.java
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/common/build.xml
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core-cms/src/main/org/jboss/portal/core/cms/command/StreamContentCommand.java
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
Log:
Fixes for dependent issues JBPORTAL-1867, JBPORTAL-1617, and JBPORTAL-1651.
Modified:
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/cms/src/main/org/jboss/portal/test/cms/commands/TestFileGet.java
===================================================================
---
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/cms/src/main/org/jboss/portal/test/cms/commands/TestFileGet.java 2008-01-24
21:33:17 UTC (rev 9600)
+++
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/cms/src/main/org/jboss/portal/test/cms/commands/TestFileGet.java 2008-01-24
22:28:21 UTC (rev 9601)
@@ -1,125 +1,126 @@
-/******************************************************************************
- * 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.CMSException;
-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;
-import java.util.Map;
-
-
-/**
- * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
- */
-public class TestFileGet 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 TestFileGet()
- {
- }
-
- /**
- *
- *
- */
- public static TestSuite suite() throws Exception
- {
- return createTestSuite(TestFileGet.class);
- }
-
- /** Tests retrieval of the version labeled LIVE. */
- public void testFileGet() throws CMSException
- {
- createFile();
- Command getCMD = service.getCommandFactory().createFileGetCommand(sFilePath,
Locale.ENGLISH);
- File newfile = (File)service.execute(getCMD);
-
- Content content = newfile.getContent();
- assertEquals("Encoding Incorrect", content.getEncoding(),
"UTF-8");
- assertEquals("Mimetype Incorrect", content.getMimeType(),
"image/gif");
- assertEquals("Language Incorrect", content.getLocale().getLanguage(),
"en");
- assertEquals("Title Incorrect", content.getTitle(), "English
Title");
- assertEquals("Desc Incorrect", content.getDescription(), "English
Description");
- }
-
- /**
- *
- *
- */
- private void createFile() throws CMSException
- {
- // 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);
-
- Command newFileCMD = service.getCommandFactory().createNewFileCommand(file,
content);
- service.execute(newFileCMD);
-
- // 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".getBytes());
- contentSP.setMimeType("image/gif");
- file.setContent(new Locale("es"), contentSP);
-
- Command newFileSPCMD = service.getCommandFactory().createNewFileCommand(file,
contentSP);
- service.execute(newFileSPCMD);
- }
-}
+/******************************************************************************
+ * 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.CMSException;
+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;
+import java.util.Map;
+
+
+/**
+ * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
+ */
+public class TestFileGet 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 TestFileGet()
+ {
+ }
+
+ /**
+ *
+ *
+ */
+ public static TestSuite suite() throws Exception
+ {
+ return createTestSuite(TestFileGet.class);
+ }
+
+ /** Tests retrieval of the version labeled LIVE. */
+ public void testFileGet() throws CMSException
+ {
+ createFile();
+ Command getCMD = service.getCommandFactory().createFileGetCommand(sFilePath,
Locale.ENGLISH);
+ File newfile = (File)service.execute(getCMD);
+
+ Content content = newfile.getContent();
+ assertEquals("Encoding Incorrect", content.getEncoding(),
"UTF-8");
+ assertEquals("Mimetype Incorrect", content.getMimeType(),
"image/gif");
+ assertEquals("Language Incorrect", content.getLocale().getLanguage(),
"en");
+ assertEquals("Title Incorrect", content.getTitle(), "English
Title");
+ assertEquals("Desc Incorrect", content.getDescription(), "English
Description");
+ assertNotNull("Last Modified Date Missing", content.getLastModified());
+ }
+
+ /**
+ *
+ *
+ */
+ private void createFile() throws CMSException
+ {
+ // 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);
+
+ Command newFileCMD = service.getCommandFactory().createNewFileCommand(file,
content);
+ service.execute(newFileCMD);
+
+ // 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".getBytes());
+ contentSP.setMimeType("image/gif");
+ file.setContent(new Locale("es"), contentSP);
+
+ Command newFileSPCMD = service.getCommandFactory().createNewFileCommand(file,
contentSP);
+ service.execute(newFileSPCMD);
+ }
+}
Modified: branches/JBoss_Portal_2_6_1_JBPORTAL-1872/common/build.xml
===================================================================
--- branches/JBoss_Portal_2_6_1_JBPORTAL-1872/common/build.xml 2008-01-24 21:33:17 UTC
(rev 9600)
+++ branches/JBoss_Portal_2_6_1_JBPORTAL-1872/common/build.xml 2008-01-24 22:28:21 UTC
(rev 9601)
@@ -143,7 +143,7 @@
<mkdir dir="${build.lib}"/>
- <jar jarfile="${build.lib}/portal-common-lib.jar"
manifest="${build.etc}/portal-common-lib-jar.mf">
+ <jar jarfile="${build.lib}/portal-common-lib.jar"
manifest="${build.etc}/portal-common-lib-jar.mf"
duplicate="preserve">
<fileset dir="${build.classes}"/>
<fileset dir="${build.resources}/format/code"/>
<fileset dir="${build.classes}">
Modified:
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
===================================================================
---
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java 2008-01-24
21:33:17 UTC (rev 9600)
+++
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java 2008-01-24
22:28:21 UTC (rev 9601)
@@ -29,6 +29,7 @@
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.ControllerCommand;
import org.jboss.portal.core.controller.ControllerResponse;
+import org.jboss.portal.core.controller.command.response.RedirectionResponse;
import org.jboss.portal.core.controller.command.response.SignOutResponse;
import org.jboss.portal.core.controller.command.response.StreamContentResponse;
import org.jboss.portal.core.controller.command.response.ErrorResponse;
@@ -105,10 +106,28 @@
//
return HTTPResponse.sendRedirect(location);
}
+ else if (controllerResponse instanceof RedirectionResponse)
+ {
+ // Get the optional signout location
+ String location = ((RedirectionResponse)controllerResponse).getLocation();
+
+ //
+ if (location == null)
+ {
+ PortalObjectContainer portalObjectContainer =
controllerContext.getController().getPortalObjectContainer();
+ Portal portal =
(Portal)portalObjectContainer.getObject(DEFAULT_PORTAL_PATH);
+ ViewPageCommand renderCmd = new ViewPageCommand(portal.getId());
+ URLContext urlContext = invocation.getServerContext().getURLContext();
+ location = controllerContext.renderURL(renderCmd, urlContext, null);
+ }
+
+ //
+ return HTTPResponse.sendRedirect(location);
+ }
else if (controllerResponse instanceof StreamContentResponse)
{
StreamContentResponse scr = (StreamContentResponse)controllerResponse;
- return HTTPResponse.sendBinary(scr.getContentType(), scr.getInputStream());
+ return HTTPResponse.sendBinary(scr.getContentType(), scr.getLastModified(),
scr.getInputStream());
}
else if (controllerResponse instanceof SecurityErrorResponse)
{
Modified:
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java
===================================================================
---
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java 2008-01-24
21:33:17 UTC (rev 9600)
+++
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java 2008-01-24
22:28:21 UTC (rev 9601)
@@ -35,11 +35,17 @@
/** . */
private String contentType;
+
+ /**
+ * The time the content was last modified, measured in milliseconds since
+ * the epoch (00:00:00 GMT, January 1, 1970).
+ */
+ private long lastModified;
/** . */
private InputStream inputStream;
- public StreamContentResponse(String contentType, InputStream inputStream)
+ public StreamContentResponse(String contentType, long lastModified, InputStream
inputStream)
{
if (contentType == null)
{
@@ -50,6 +56,7 @@
throw new IllegalArgumentException();
}
this.contentType = contentType;
+ this.lastModified = lastModified;
this.inputStream = inputStream;
}
@@ -57,6 +64,11 @@
{
return contentType;
}
+
+ public long getLastModified()
+ {
+ return lastModified;
+ }
public InputStream getInputStream()
{
Modified:
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
===================================================================
---
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2008-01-24
21:33:17 UTC (rev 9600)
+++
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2008-01-24
22:28:21 UTC (rev 9601)
@@ -54,7 +54,7 @@
};
}
- public static HTTPResponse sendBinary(final String contentType, final InputStream in)
+ public static HTTPResponse sendBinary(final String contentType, final long
lastModified, final InputStream in)
{
return new HTTPResponse()
{
@@ -62,6 +62,7 @@
{
HttpServletResponse resp = ctx.getClientResponse();
resp.setContentType(contentType);
+ resp.addDateHeader("Last-Modified", lastModified);
ServletOutputStream sout = null;
try
{
Modified:
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core-cms/src/main/org/jboss/portal/core/cms/command/StreamContentCommand.java
===================================================================
---
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core-cms/src/main/org/jboss/portal/core/cms/command/StreamContentCommand.java 2008-01-24
21:33:17 UTC (rev 9600)
+++
branches/JBoss_Portal_2_6_1_JBPORTAL-1872/core-cms/src/main/org/jboss/portal/core/cms/command/StreamContentCommand.java 2008-01-24
22:28:21 UTC (rev 9601)
@@ -86,8 +86,18 @@
}
Content content = file.getContent();
String mimeType = content.getMimeType();
+ long lastModified;
+ if(content.getLastModified() != null)
+ {
+ lastModified = content.getLastModified().getTime();
+ }
+ else
+ {
+ // Use current time in none available
+ lastModified = System.currentTimeMillis();
+ }
InputStream inputStream = content.getStream();
- return new StreamContentResponse(mimeType, inputStream);
+ return new StreamContentResponse(mimeType, lastModified, inputStream);
}
catch (Exception e)
{