Author: tv
Date: Wed Jul 29 08:19:52 2015
New Revision: 1693205
URL: http://svn.apache.org/r1693205
Log:
Add methods to handle portlet upload requests
Update dependency commons-fileupload to 1.3.1
Move to JDK 1.6
Added:
turbine/fulcrum/trunk/upload/src/changes/changes.xml
- copied, changed from r1673424,
turbine/fulcrum/trunk/upload/xdocs/changes.xml
Removed:
turbine/fulcrum/trunk/upload/xdocs/changes.xml
Modified:
turbine/fulcrum/trunk/upload/pom.xml
turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java
turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java
turbine/fulcrum/trunk/upload/xdocs/index.xml
Modified: turbine/fulcrum/trunk/upload/pom.xml
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/pom.xml?rev=1693205&r1=1693204&r2=1693205&view=diff
==============================================================================
--- turbine/fulcrum/trunk/upload/pom.xml (original)
+++ turbine/fulcrum/trunk/upload/pom.xml Wed Jul 29 08:19:52 2015
@@ -36,14 +36,6 @@
<url>http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/</url>
</scm>
- <distributionManagement>
- <site>
- <id>apache.website</id>
- <name>Fulcrum Website</name>
-
<url>${fulcrum.deployment.protocol}://people.apache.org/www/turbine.apache.org/fulcrum/fulcrum-upload/</url>
- </site>
- </distributionManagement>
-
<developers>
<developer>
<name>Eric Pugh</name>
@@ -88,12 +80,17 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
- <version>2.4</version>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.portlet</groupId>
+ <artifactId>portlet-api</artifactId>
+ <version>2.0</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
- <version>1.2.2</version>
+ <version>1.3.1</version>
</dependency>
<!-- testing dependencies -->
@@ -116,27 +113,8 @@
<testSourceDirectory>${basedir}/src/test</testSourceDirectory>
</build>
- <profiles>
- <profile>
- <id>rc</id>
- <distributionManagement>
- <!-- Cannot define in parent ATM, see COMMONSSITE-26 -->
- <site>
- <id>apache.website</id>
- <name>Apache Fulcrum Release Candidate Staging Site</name>
-
<url>${fulcrum.deployment.protocol}://people.apache.org/www/turbine.apache.org/builds/fulcrum/${fulcrum.componentid}/${fulcrum.release.version}/${fulcrum.rc.version}/site</url>
- </site>
- </distributionManagement>
- </profile>
- </profiles>
-
<properties>
- <maven.compile.source>1.5</maven.compile.source>
- <maven.compile.target>1.5</maven.compile.target>
- <!-- This bits are used for the staging directory -->
- <fulcrum.release.version>1.0.5</fulcrum.release.version>
- <fulcrum.rc.version>RC2</fulcrum.rc.version>
- <fulcrum.deployment.protocol>scpexe</fulcrum.deployment.protocol>
+ <turbine.site.path>fulcrum/fulcrum-upload</turbine.site.path>
</properties>
</project>
\ No newline at end of file
Copied: turbine/fulcrum/trunk/upload/src/changes/changes.xml (from r1673424,
turbine/fulcrum/trunk/upload/xdocs/changes.xml)
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/src/changes/changes.xml?p2=turbine/fulcrum/trunk/upload/src/changes/changes.xml&p1=turbine/fulcrum/trunk/upload/xdocs/changes.xml&r1=1673424&r2=1693205&rev=1693205&view=diff
==============================================================================
--- turbine/fulcrum/trunk/upload/xdocs/changes.xml (original)
+++ turbine/fulcrum/trunk/upload/src/changes/changes.xml Wed Jul 29 08:19:52
2015
@@ -24,6 +24,17 @@
</properties>
<body>
+ <release version="1.0.6" date="in SVN">
+ <action dev="tv" type="add">
+ Add methods to handle portlet upload requests
+ </action>
+ <action dev="tv" type="update">
+ Update dependency commons-fileupload to 1.3.1
+ </action>
+ <action dev="tv" type="update">
+ Move to JDK 1.6
+ </action>
+ </release>
<release version="1.0.5" date="2012-06-17">
<action dev="tv" type="update">
Cleanup documentation
Modified:
turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java?rev=1693205&r1=1693204&r2=1693205&view=diff
==============================================================================
---
turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java
(original)
+++
turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/DefaultUploadService.java
Wed Jul 29 08:19:52 2015
@@ -25,6 +25,7 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
+import javax.portlet.ActionRequest;
import javax.servlet.http.HttpServletRequest;
import org.apache.avalon.framework.activity.Initializable;
@@ -39,6 +40,7 @@ import org.apache.commons.fileupload.Fil
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.portlet.PortletFileUpload;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
/**
@@ -83,7 +85,8 @@ public class DefaultUploadService
/**
* The maximum allowed upload size
*/
- public long getSizeMax()
+ @Override
+ public long getSizeMax()
{
return sizeMax;
}
@@ -91,7 +94,8 @@ public class DefaultUploadService
/**
* The threshold beyond which files are written directly to disk.
*/
- public long getSizeThreshold()
+ @Override
+ public long getSizeThreshold()
{
return itemFactory.getSizeThreshold();
}
@@ -100,7 +104,8 @@ public class DefaultUploadService
* The location used to temporarily store files that are larger
* than the size threshold.
*/
- public String getRepository()
+ @Override
+ public String getRepository()
{
return itemFactory.getRepository().getAbsolutePath();
}
@@ -108,7 +113,8 @@ public class DefaultUploadService
/**
* @return Returns the headerEncoding.
*/
- public String getHeaderEncoding()
+ @Override
+ public String getHeaderEncoding()
{
return headerEncoding;
}
@@ -121,7 +127,8 @@ public class DefaultUploadService
* @exception ServiceException Problems reading/parsing the
* request or storing the uploaded file(s).
*/
- public List<FileItem> parseRequest(HttpServletRequest req)
+ @Override
+ public List<FileItem> parseRequest(HttpServletRequest req)
throws ServiceException
{
return parseRequest(req, this.sizeMax, this.itemFactory);
@@ -136,7 +143,8 @@ public class DefaultUploadService
* @exception ServiceException Problems reading/parsing the
* request or storing the uploaded file(s).
*/
- public List<FileItem> parseRequest(HttpServletRequest req, String path)
+ @Override
+ public List<FileItem> parseRequest(HttpServletRequest req, String path)
throws ServiceException
{
return parseRequest(req, this.sizeThreshold, this.sizeMax, path);
@@ -153,7 +161,8 @@ public class DefaultUploadService
* @exception ServiceException Problems reading/parsing the
* request or storing the uploaded file(s).
*/
- public List<FileItem> parseRequest(HttpServletRequest req, int
sizeThreshold,
+ @Override
+ public List<FileItem> parseRequest(HttpServletRequest req, int
sizeThreshold,
int sizeMax, String path)
throws ServiceException
{
@@ -171,7 +180,6 @@ public class DefaultUploadService
* @exception ServiceException Problems reading/parsing the
* request or storing the uploaded file(s).
*/
- @SuppressWarnings("unchecked")
protected List<FileItem> parseRequest(HttpServletRequest req, int sizeMax,
DiskFileItemFactory factory)
throws ServiceException
{
@@ -205,7 +213,8 @@ public class DefaultUploadService
* problem while storing the uploaded
* content.
*/
- public FileItemIterator getItemIterator(HttpServletRequest req) throws
ServiceException
+ @Override
+ public FileItemIterator getItemIterator(HttpServletRequest req) throws
ServiceException
{
ServletFileUpload upload = new ServletFileUpload();
try
@@ -223,6 +232,118 @@ public class DefaultUploadService
}
/**
+ * <p>Parses a <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.</p>
+ *
+ * @param req The portlet request to be parsed.
+ * @exception ServiceException Problems reading/parsing the
+ * request or storing the uploaded file(s).
+ */
+ @Override
+ public List<FileItem> parseRequest(ActionRequest req)
+ throws ServiceException
+ {
+ return parseRequest(req, this.sizeMax, this.itemFactory);
+ }
+
+ /**
+ * <p>Parses a <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.</p>
+ *
+ * @param req The portlet request to be parsed.
+ * @param path The location where the files should be stored.
+ * @exception ServiceException Problems reading/parsing the
+ * request or storing the uploaded file(s).
+ */
+ @Override
+ public List<FileItem> parseRequest(ActionRequest req, String path)
+ throws ServiceException
+ {
+ return parseRequest(req, this.sizeThreshold, this.sizeMax, path);
+ }
+
+ /**
+ * <p>Parses a <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.</p>
+ *
+ * @param req The portlet request to be parsed.
+ * @param sizeThreshold the max size in bytes to be stored in memory
+ * @param sizeMax the maximum allowed upload size in bytes
+ * @param path The location where the files should be stored.
+ * @exception ServiceException Problems reading/parsing the
+ * request or storing the uploaded file(s).
+ */
+ @Override
+ public List<FileItem> parseRequest(ActionRequest req, int sizeThreshold,
+ int sizeMax, String path)
+ throws ServiceException
+ {
+ return parseRequest(req, sizeMax, new
DiskFileItemFactory(sizeThreshold, new File(path)));
+ }
+
+ /**
+ * <p>Parses a <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.</p>
+ *
+ * @param req The portlet request to be parsed.
+ * @param sizeMax the maximum allowed upload size in bytes
+ * @param factory the file item factory to use
+ *
+ * @exception ServiceException Problems reading/parsing the
+ * request or storing the uploaded file(s).
+ */
+ protected List<FileItem> parseRequest(ActionRequest req, int sizeMax,
DiskFileItemFactory factory)
+ throws ServiceException
+ {
+ try
+ {
+ PortletFileUpload fileUpload = new PortletFileUpload(factory);
+ fileUpload.setSizeMax(sizeMax);
+ fileUpload.setHeaderEncoding(headerEncoding);
+ return fileUpload.parseRequest(req);
+ }
+ catch (FileUploadException e)
+ {
+ throw new ServiceException(UploadService.ROLE, e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.
+ *
+ * @param req The portlet request to be parsed.
+ *
+ * @return An iterator to instances of <code>FileItemStream</code>
+ * parsed from the request, in the order that they were
+ * transmitted.
+ *
+ * @throws ServiceException if there are problems reading/parsing
+ * the request or storing files. This
+ * may also be a network error while
+ * communicating with the client or a
+ * problem while storing the uploaded
+ * content.
+ */
+ @Override
+ public FileItemIterator getItemIterator(ActionRequest req) throws
ServiceException
+ {
+ PortletFileUpload upload = new PortletFileUpload();
+ try
+ {
+ return upload.getItemIterator(req);
+ }
+ catch (FileUploadException e)
+ {
+ throw new ServiceException(UploadService.ROLE, e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ throw new ServiceException(UploadService.ROLE, e.getMessage(), e);
+ }
+ }
+
+ /**
* Utility method that determines whether the request contains multipart
* content.
*
@@ -231,7 +352,8 @@ public class DefaultUploadService
* @return <code>true</code> if the request is multipart;
* <code>false</code> otherwise.
*/
- public boolean isMultipart(HttpServletRequest req)
+ @Override
+ public boolean isMultipart(HttpServletRequest req)
{
return ServletFileUpload.isMultipartContent(req);
}
@@ -258,7 +380,8 @@ public class DefaultUploadService
/**
* Avalon component lifecycle method
*/
- public void configure(Configuration conf)
+ @Override
+ public void configure(Configuration conf)
{
repositoryPath = conf.getAttribute(
UploadService.REPOSITORY_KEY,
@@ -285,7 +408,8 @@ public class DefaultUploadService
* This method processes the repository path, to make it relative to the
* web application root, if necessary
*/
- public void initialize() throws Exception
+ @Override
+ public void initialize() throws Exception
{
// test for the existence of the path within the webapp directory.
// if it does not exist, assume the path was to be used as is.
@@ -305,7 +429,8 @@ public class DefaultUploadService
/**
* Avalon component lifecycle method
*/
- public void contextualize(Context context) throws ContextException
+ @Override
+ public void contextualize(Context context) throws ContextException
{
this.applicationRoot = context.get( "urn:avalon:home" ).toString();
}
Modified:
turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java?rev=1693205&r1=1693204&r2=1693205&view=diff
==============================================================================
---
turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java
(original)
+++
turbine/fulcrum/trunk/upload/src/java/org/apache/fulcrum/upload/UploadService.java
Wed Jul 29 08:19:52 2015
@@ -23,6 +23,7 @@ package org.apache.fulcrum.upload;
import java.util.List;
+import javax.portlet.ActionRequest;
import javax.servlet.http.HttpServletRequest;
import org.apache.avalon.framework.service.ServiceException;
@@ -204,6 +205,65 @@ public interface UploadService
/**
+ * <p>Parses a <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.</p>
+ *
+ * @param req The portlet request to be parsed.
+ * @exception ServiceException Problems reading/parsing the
+ * request or storing the uploaded file(s).
+ */
+ List<FileItem> parseRequest(ActionRequest req)
+ throws ServiceException;
+
+ /**
+ * <p>Parses a <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.</p>
+ *
+ * @param req The portlet request to be parsed.
+ * @param path The location where the files should be stored.
+ * @exception ServiceException Problems reading/parsing the
+ * request or storing the uploaded file(s).
+ */
+ List<FileItem> parseRequest(ActionRequest req, String path)
+ throws ServiceException;
+
+ /**
+ * <p>Parses a <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.</p>
+ *
+ * @param req The portlet request to be parsed.
+ * @param sizeThreshold the max size in bytes to be stored in memory
+ * @param sizeMax the maximum allowed upload size in bytes
+ * @param path The location where the files should be stored.
+ * @exception ServiceException Problems reading/parsing the
+ * request or storing the uploaded file(s).
+ */
+ List<FileItem> parseRequest(ActionRequest req, int sizeThreshold,
+ int sizeMax, String path)
+ throws ServiceException;
+
+
+ /**
+ * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.
+ *
+ * @param req The portlet request to be parsed.
+ *
+ * @return An iterator to instances of <code>FileItemStream</code>
+ * parsed from the request, in the order that they were
+ * transmitted.
+ *
+ * @throws ServiceException if there are problems reading/parsing
+ * the request or storing files. This
+ * may also be a network error while
+ * communicating with the client or a
+ * problem while storing the uploaded
+ * content.
+ */
+ FileItemIterator getItemIterator(ActionRequest req) throws
ServiceException;
+
+
+ /**
* <p> Retrieves the value of <code>size.max</code> property of the
* {@link org.apache.fulcrum.upload.UploadService}.
*
Modified: turbine/fulcrum/trunk/upload/xdocs/index.xml
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/xdocs/index.xml?rev=1693205&r1=1693204&r2=1693205&view=diff
==============================================================================
--- turbine/fulcrum/trunk/upload/xdocs/index.xml (original)
+++ turbine/fulcrum/trunk/upload/xdocs/index.xml Wed Jul 29 08:19:52 2015
@@ -17,99 +17,102 @@
specific language governing permissions and limitations
under the License.
-->
-
<document>
- <properties>
- <title>Upload Component</title>
- <author email="[email protected]">Eric Pugh</author>
- </properties>
-
- <body>
-
- <section name="Overview">
-<p>
-The Upload Service handles the parsing of multi-part/form-data from POST
-Requests, making the multi-part files available from either memory or from a
-specified location on the file system.
-</p>
-
- <p>
- It is written for use in Turbine but it can be used in Avalon compatible
container.
- </p>
- </section>
-
- <section name="Configuration">
- <subsection name="Role Configuration">
- <source><![CDATA[
+ <properties>
+ <title>Upload Component</title>
+ <author email="[email protected]">Eric
Pugh</author>
+ </properties>
+
+ <body>
+
+ <section name="Overview">
+ <p>
+ The Upload Service handles the parsing of
multi-part/form-data from
+ POST Requests for Servlets and Portlets, making
the multi-part files available
+ from either memory or from a specified location
on the file system.
+ </p>
+
+ <p>
+ It is written for use in Turbine but it can be
used in Avalon
+ compatible container.
+ </p>
+ </section>
+
+ <section name="Configuration">
+ <subsection name="Role Configuration">
+ <source><![CDATA[
<role
name="org.apache.fulcrum.upload.UploadService"
shorthand="upload"
default-class="org.apache.fulcrum.upload.DefaultUploadService"/>
- ]]></source>
- </subsection>
-
- <subsection name="Component Configuration">
- <table>
- <tr>
- <th>Item</th>
- <th>Datatype</th>
- <th>Cardinality</th>
- <th>Description</th>
- </tr>
- <tr>
- <td>repository</td>
- <td>String</td>
- <td>[0|1]</td>
- <td>
- The directory where files will be temporarily stored (default is
".").
- On Win32 file systems an entry of the form
- <code>f:\path\to\upload\repository</code> is most likely necessary.
- </td>
- </tr>
- <tr>
- <td>sizeMax</td>
- <td>Integer</td>
- <td>[0|1]</td>
- <td>
- The maximum size of a request that will be processed
- (default is 1048576 bytes).
- </td>
- </tr>
- <tr>
- <td>sizeThreshold</td>
- <td>Integer</td>
- <td>[0|1]</td>
- <td>
- The maximum size of a request that will have it's elements cached in
- memory (default is 10240 bytes).
- </td>
- </tr>
- <tr>
- <td>headerEncoding</td>
- <td>String</td>
- <td>[0|1]</td>
- <td>
- Used to specify how the headers are encoded (default is
"ISO-8859-1").
- </td>
- </tr>
- </table>
- </subsection>
+]]></source>
+ </subsection>
- <subsection name="Component Configuration Example">
- <source><![CDATA[
+ <subsection name="Component Configuration">
+ <table>
+ <tr>
+ <th>Item</th>
+ <th>Datatype</th>
+ <th>Cardinality</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td>repository</td>
+ <td>String</td>
+ <td>[0|1]</td>
+ <td>
+ The directory where
files will be temporarily stored (default is
+ ".").
+ On Win32 file systems
an entry of the form
+
<code>f:\path\to\upload\repository</code>
+ is most likely
necessary.
+ </td>
+ </tr>
+ <tr>
+ <td>sizeMax</td>
+ <td>Integer</td>
+ <td>[0|1]</td>
+ <td>
+ The maximum size of a
request that will be processed
+ (default is 1048576
bytes).
+ </td>
+ </tr>
+ <tr>
+ <td>sizeThreshold</td>
+ <td>Integer</td>
+ <td>[0|1]</td>
+ <td>
+ The maximum size of a
request that will have it's elements cached in
+ memory (default is
10240 bytes).
+ </td>
+ </tr>
+ <tr>
+ <td>headerEncoding</td>
+ <td>String</td>
+ <td>[0|1]</td>
+ <td>
+ Used to specify how the
headers are encoded (default is
+ "ISO-8859-1").
+ </td>
+ </tr>
+ </table>
+ </subsection>
+
+ <subsection name="Component Configuration Example">
+ <source><![CDATA[
<upload repository="target" sizeMax="1048576" sizeThreshold="10240"
headerEncoding="UTF-8"/>
- ]]></source>
- </subsection>
- </section>
+]]></source>
+ </subsection>
+ </section>
- <section name="Usage">
+ <section name="Usage">
-<p>
-Create an HTML form of the type:
-</p>
+ <p>
+ Create an HTML form of the type:
+ </p>
-<source test=""><![CDATA[
+ <source test=""><![CDATA[
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="action" value="UploadExample" />
<input type="file" name="filename">
@@ -117,30 +120,32 @@ Create an HTML form of the type:
</form>
]]></source>
-<p>
-The Upload Service manages the storage of the FileItem in memory or at the
-configured repository location in the file system. It is also possible to
-override the repository location using the overloaded parseRequest() methods.
-</p>
-
-<p>
-Typically a request would be parsed using the Fulcrum ParameterParser service,
-but you can achieve this manually thus:
-</p>
-<source test=""><![CDATA[
+ <p>
+ The Upload Service manages the storage of the
FileItem in memory or at
+ the configured repository location in the file
system. It is also possible to
+ override the repository location using the
overloaded parseRequest()
+ methods.
+ </p>
+
+ <p>
+ Typically a request would be parsed using the
Fulcrum ParameterParser
+ service, but you can achieve this manually thus:
+ </p>
+ <source test=""><![CDATA[
UploadService us = (UploadService) this.lookup(UploadService.ROLE);
List fileItems = us.parse(request);
]]></source>
-<p>
-FileItem provides many methods for working with the uploaded files that will
-function whether a file is loaded into memory or as a temporary file.
-All the temporary storage management and clean up occurs behind the scenes
-transparently to your application. FileItem objects do not span Requests,
-finalizers remove any temporary files created along the way.
-</p>
+ <p>
+ FileItem provides many methods for working with
the uploaded files that will
+ function whether a file is loaded into memory
or as a temporary
+ file.
+ All the temporary storage management and clean
up occurs behind the
+ scenes transparently to your application.
FileItem objects do not span Requests,
+ finalizers remove any temporary files created
along the way.
+ </p>
- </section>
+ </section>
-</body>
+ </body>
</document>