You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2009/01/06 20:58:23 UTC
svn commit: r732085 - in /turbine/fulcrum/trunk/upload:
src/java/org/apache/fulcrum/upload/DefaultUploadService.java
src/java/org/apache/fulcrum/upload/UploadService.java
src/test/TestComponentConfig.xml xdocs/changes.xml
Author: tv
Date: Tue Jan 6 11:58:22 2009
New Revision: 732085
URL: http://svn.apache.org/viewvc?rev=732085&view=rev
Log:
Allow Non-ASCII characters in upload file names. Fixes TRB-13
Modified:
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/src/test/TestComponentConfig.xml
turbine/fulcrum/trunk/upload/xdocs/changes.xml
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=732085&r1=732084&r2=732085&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 Tue Jan 6 11:58:22 2009
@@ -70,6 +70,7 @@
private int sizeMax;
private String repositoryPath;
+ private String headerEncoding;
/**
* The application root
@@ -102,6 +103,14 @@
}
/**
+ * @return Returns the headerEncoding.
+ */
+ public String getHeaderEncoding()
+ {
+ return headerEncoding;
+ }
+
+ /**
* <p>Parses a <a href="http://rf.cx/rfc1867.html">RFC 1867</a>
* compliant <code>multipart/form-data</code> stream.</p>
*
@@ -112,16 +121,7 @@
public List parseRequest(HttpServletRequest req)
throws ServiceException
{
- try
- {
- ServletFileUpload fileUpload = new ServletFileUpload(itemFactory);
- fileUpload.setSizeMax(sizeMax);
- return fileUpload.parseRequest(req);
- }
- catch (FileUploadException e)
- {
- throw new ServiceException(UploadService.ROLE, e.getMessage(), e);
- }
+ return parseRequest(req, this.sizeMax, this.itemFactory);
}
/**
@@ -136,17 +136,7 @@
public List parseRequest(HttpServletRequest req, String path)
throws ServiceException
{
- try
- {
- DiskFileItemFactory localItemFactory = new DiskFileItemFactory(sizeThreshold, new File(path));
- ServletFileUpload fileUpload = new ServletFileUpload(localItemFactory);
- fileUpload.setSizeMax(sizeMax);
- return fileUpload.parseRequest(req);
- }
- catch (FileUploadException e)
- {
- throw new ServiceException(UploadService.ROLE, e.getMessage(), e);
- }
+ return parseRequest(req, this.sizeThreshold, this.sizeMax, path);
}
/**
@@ -164,11 +154,28 @@
int sizeMax, String path)
throws ServiceException
{
+ return parseRequest(req, sizeMax, new DiskFileItemFactory(sizeThreshold, new File(path)));
+ }
+
+ /**
+ * <p>Parses a <a href="http://rf.cx/rfc1867.html">RFC 1867</a>
+ * compliant <code>multipart/form-data</code> stream.</p>
+ *
+ * @param req The servlet 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).
+ */
+ private List parseRequest(HttpServletRequest req, int sizeMax, DiskFileItemFactory factory)
+ throws ServiceException
+ {
try
{
- DiskFileItemFactory localItemFactory = new DiskFileItemFactory(sizeThreshold, new File(path));
- ServletFileUpload fileUpload = new ServletFileUpload(localItemFactory);
+ ServletFileUpload fileUpload = new ServletFileUpload(factory);
fileUpload.setSizeMax(sizeMax);
+ fileUpload.setHeaderEncoding(headerEncoding);
return fileUpload.parseRequest(req);
}
catch (FileUploadException e)
@@ -205,6 +212,10 @@
UploadService.REPOSITORY_KEY,
UploadService.REPOSITORY_DEFAULT);
+ headerEncoding = conf.getAttribute(
+ UploadService.HEADER_ENCODING_KEY,
+ UploadService.HEADER_ENCODING_DEFAULT);
+
sizeMax = conf.getAttributeAsInteger(
UploadService.SIZE_MAX_KEY,
UploadService.SIZE_MAX_DEFAULT);
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=732085&r1=732084&r2=732085&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 Tue Jan 6 11:58:22 2009
@@ -47,50 +47,50 @@
/**
* HTTP header.
*/
- static final String CONTENT_TYPE = "Content-type";
+ String CONTENT_TYPE = "Content-type";
/**
* HTTP header.
*/
- static final String CONTENT_DISPOSITION = "Content-disposition";
+ String CONTENT_DISPOSITION = "Content-disposition";
/**
* HTTP header base type.
*/
- static final String MULTIPART = "multipart";
+ String MULTIPART = "multipart";
/**
* HTTP header base type modifier.
*/
- static final String FORM_DATA = "form-data";
+ String FORM_DATA = "form-data";
/**
* HTTP header base type modifier.
*/
- static final String MIXED = "mixed";
+ String MIXED = "mixed";
/**
* HTTP header.
*/
- static final String MULTIPART_FORM_DATA =
+ String MULTIPART_FORM_DATA =
MULTIPART + '/' + FORM_DATA;
/**
* HTTP header.
*/
- static final String MULTIPART_MIXED = MULTIPART + '/' + MIXED;
+ String MULTIPART_MIXED = MULTIPART + '/' + MIXED;
/**
* The request parameter name for overriding 'repository' property
* (path).
*/
- static final String REPOSITORY_PARAMETER = "path";
+ String REPOSITORY_PARAMETER = "path";
/**
* The key in UploadService properties in
* TurbineResources.properties 'repository' property.
*/
- static final String REPOSITORY_KEY = "repository";
+ String REPOSITORY_KEY = "repository";
/**
* <p> The default value of 'repository' property (.). This is
@@ -98,13 +98,13 @@
* Note that "." is whatever the servlet container chooses to be
* it's 'current directory'.
*/
- static final String REPOSITORY_DEFAULT = ".";
+ String REPOSITORY_DEFAULT = ".";
/**
* w The key in UploadService properties in
* service configuration 'sizeMax' property.
*/
- static final String SIZE_MAX_KEY = "sizeMax";
+ String SIZE_MAX_KEY = "sizeMax";
/**
* <p> The default value of 'sizMax' property (1 megabyte =
@@ -114,13 +114,13 @@
* value, and use an action + no auto upload to enforce limits.
*
*/
- static final int SIZE_MAX_DEFAULT = 1048576;
+ int SIZE_MAX_DEFAULT = 1048576;
/**
* The key in UploadService properties in
* TurbineResources.properties 'sizeThreshold' property.
*/
- static final String SIZE_THRESHOLD_KEY = "sizeThreshold";
+ String SIZE_THRESHOLD_KEY = "sizeThreshold";
/**
* <p> The default value of 'sizeThreshold' property (10
@@ -128,9 +128,21 @@
* request that will have it's components stored temporarily in
* memory, instead of disk.
*/
- static final int SIZE_THRESHOLD_DEFAULT = 10240;
+ int SIZE_THRESHOLD_DEFAULT = 10240;
/**
+ * The key in UploadService properties in
+ * TurbineResources.properties 'headerEncoding' property.
+ */
+ String HEADER_ENCODING_KEY = "headerEncoding";
+
+ /**
+ * <p> The default value of 'headerEncoding' property (.).
+ * The value has been decided by copying from DiskFileItem class
+ */
+ String HEADER_ENCODING_DEFAULT = "ISO-8859-1";
+
+ /**
* <p>Parses a <a href="http://rf.cx/rfc1867.html">RFC 1867</a>
* compliant <code>multipart/form-data</code> stream.</p>
*
@@ -191,4 +203,12 @@
* @return The repository.
*/
String getRepository();
+
+ /**
+ * <p> Retrieves the value of the <code>headerEncoding</code> property of
+ * {@link org.apache.fulcrum.upload.UploadService}.
+ *
+ * @return Returns the headerEncoding.
+ */
+ String getHeaderEncoding();
}
Modified: turbine/fulcrum/trunk/upload/src/test/TestComponentConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/src/test/TestComponentConfig.xml?rev=732085&r1=732084&r2=732085&view=diff
==============================================================================
--- turbine/fulcrum/trunk/upload/src/test/TestComponentConfig.xml (original)
+++ turbine/fulcrum/trunk/upload/src/test/TestComponentConfig.xml Tue Jan 6 11:58:22 2009
@@ -18,5 +18,5 @@
under the License.
-->
<componentConfig>
- <upload repository="target" sizeMax="1048576" sizeThreshold="10240"/>
+ <upload repository="target" sizeMax="1048576" sizeThreshold="10240" headerEncoding="UTF-8" />
</componentConfig>
Modified: turbine/fulcrum/trunk/upload/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/upload/xdocs/changes.xml?rev=732085&r1=732084&r2=732085&view=diff
==============================================================================
--- turbine/fulcrum/trunk/upload/xdocs/changes.xml (original)
+++ turbine/fulcrum/trunk/upload/xdocs/changes.xml Tue Jan 6 11:58:22 2009
@@ -25,6 +25,9 @@
<body>
<release version="1.0.4-dev" date="in SVN">
+ <action dev="tv" type="update" issue="TRB-13" due-to="Scott Eade">
+ Allow Non-ASCII characters in upload file names
+ </action>
<action dev="tv" type="update" issue="TRB-32" due-to="Juergen Hofmann">
Port parser fixes of Turbine 2.3.2 over to the component.
</action>