Author: jkuhnert Date: Thu Feb 23 08:59:24 2006 New Revision: 380151 URL: http://svn.apache.org/viewcvs?rev=380151&view=rev Log: Applied patch from TAPESTRY-635
Added: jakarta/tapestry/branches/4.0/.checkstyle jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/AbstractMultipartDecoder.java jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/ServletMultipartDecoder.java jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/tapestry.portlet.multipart.xml jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/ jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/ActionRequestWrapper.java jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoder.java jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderFilter.java jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderImpl.java jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/UploadFormPortletParametersWrapper.java Removed: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/org.apache.tapestry.multipart.patch Modified: jakarta/tapestry/branches/4.0/.classpath jakarta/tapestry/branches/4.0/annotations/src/java/org/apache/tapestry/annotations/Bean.java jakarta/tapestry/branches/4.0/config/common.properties jakarta/tapestry/branches/4.0/framework/build.xml jakarta/tapestry/branches/4.0/framework/src/descriptor/META-INF/tapestry.multipart.xml jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/Upload.jwc jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoder.java jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderFilter.java jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderImpl.java jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartMessages.java jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/ServletWebContext.java jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/WebContext.java jakarta/tapestry/branches/4.0/framework/src/scripts/TestUpload.xml jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/multipart/TestMultipartDecoderFilter.java jakarta/tapestry/branches/4.0/portlet/build.xml jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/hivemodule.xml jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/PortletWebContext.java jakarta/tapestry/branches/4.0/status.xml Added: jakarta/tapestry/branches/4.0/.checkstyle URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/.checkstyle?rev=380151&view=auto ============================================================================== --- jakarta/tapestry/branches/4.0/.checkstyle (added) +++ jakarta/tapestry/branches/4.0/.checkstyle Thu Feb 23 08:59:24 2006 @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<fileset-config file-format-version="1.2.0" simple-config="true"> + <fileset name="all" enabled="true" check-config-name="Sun Checks" local="false"> + <file-match-pattern match-pattern="." include-pattern="true"/> + </fileset> +</fileset-config> Modified: jakarta/tapestry/branches/4.0/.classpath URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/.classpath?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== Binary files - no diff available. Modified: jakarta/tapestry/branches/4.0/annotations/src/java/org/apache/tapestry/annotations/Bean.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/annotations/src/java/org/apache/tapestry/annotations/Bean.java?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/annotations/src/java/org/apache/tapestry/annotations/Bean.java (original) +++ jakarta/tapestry/branches/4.0/annotations/src/java/org/apache/tapestry/annotations/Bean.java Thu Feb 23 08:59:24 2006 @@ -66,4 +66,4 @@ */ Lifecycle lifecycle() default Lifecycle.REQUEST; -} \ No newline at end of file +} Modified: jakarta/tapestry/branches/4.0/config/common.properties URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/config/common.properties?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/config/common.properties (original) +++ jakarta/tapestry/branches/4.0/config/common.properties Thu Feb 23 08:59:24 2006 @@ -16,9 +16,10 @@ javassist.version=3.0 ognl.version=2.6.7 codec.version=1.3 -fileupload.version=1.0 +fileupload.version=1.1 logging.version=1.0.4 oro.version=2.0.8 servlet.version=2.3 log4j.version=1.2.8 -jboss-j2ee.version=4.0.0DR4 \ No newline at end of file +jboss-j2ee.version=4.0.0DR4 +io.version=1.0 Modified: jakarta/tapestry/branches/4.0/framework/build.xml URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/build.xml?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/build.xml (original) +++ jakarta/tapestry/branches/4.0/framework/build.xml Thu Feb 23 08:59:24 2006 @@ -45,6 +45,7 @@ <ibiblio-dependency artifact="javassist" version="${javassist.version}" group="javassist"/> <ibiblio-dependency artifact="servletapi" version="${servlet.version}" group="servletapi"/> <ibiblio-dependency artifact="ognl" version="${ognl.version}" group="ognl"/> + <ibiblio-dependency artifact="commons-io" version="${io.version}" group="commons-io"/> <ibiblio-dependency artifact="log4j" version="${log4j.version}" group="log4j" use="test"/> <ibiblio-dependency artifact="easymock" version="1.1" group="easymock" use="test"/> Modified: jakarta/tapestry/branches/4.0/framework/src/descriptor/META-INF/tapestry.multipart.xml URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/descriptor/META-INF/tapestry.multipart.xml?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/descriptor/META-INF/tapestry.multipart.xml (original) +++ jakarta/tapestry/branches/4.0/framework/src/descriptor/META-INF/tapestry.multipart.xml Thu Feb 23 08:59:24 2006 @@ -19,7 +19,7 @@ Support for multipart/form-data encoded requests used for file uploads. - <service-point id="MultipartDecoder"> + <service-point id="ServletMultipartDecoder"> Service responsible for parsing and decoding multipart form submissions. @@ -27,23 +27,26 @@ </service-point> - <service-point id="MultipartDecoderFilter" interface="org.apache.tapestry.services.ServletRequestServicerFilter"> + <service-point id="ServletMultipartDecoderFilter" interface="org.apache.tapestry.services.ServletRequestServicerFilter"> Identifies upload requests and passes them to the MultipartDecoder service for decoding. <invoke-factory> <construct class="MultipartDecoderFilter"> - <set-service property="decoder" service-id="MultipartDecoder"/> + <set-service property="decoder" service-id="ServletMultipartDecoder"/> </construct> </invoke-factory> </service-point> <contribution configuration-id="tapestry.request.ServletRequestServicerPipeline"> - <filter name="MultipartDecoderFilter" - object="service:MultipartDecoderFilter" + <filter name="ServletMultipartDecoderFilter" + object="service:ServletMultipartDecoderFilter" after="tapestry.request.SetupRequestEncoding"/> </contribution> + <contribution configuration-id="tapestry.Infrastructure"> + <property name="multipartDecoder" object="service:ServletMultipartDecoder"/> + </contribution> </module> Modified: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/Upload.jwc URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/Upload.jwc?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/Upload.jwc (original) +++ jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/form/Upload.jwc Thu Feb 23 08:59:24 2006 @@ -42,7 +42,7 @@ <reserved-parameter name="type"/> <reserved-parameter name="name"/> - <inject property="decoder" object="service:tapestry.multipart.MultipartDecoder"/> + <inject property="decoder" object="infrastructure:multipartDecoder"/> <inject property="validatableFieldSupport" object="service:tapestry.form.ValidatableFieldSupport"/> </component-specification> Added: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/AbstractMultipartDecoder.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/AbstractMultipartDecoder.java?rev=380151&view=auto ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/AbstractMultipartDecoder.java (added) +++ jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/AbstractMultipartDecoder.java Thu Feb 23 08:59:24 2006 @@ -0,0 +1,133 @@ +// Copyright 2004, 2005 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package org.apache.tapestry.multipart; + +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.fileupload.FileItem; +import org.apache.hivemind.ApplicationRuntimeException; +import org.apache.tapestry.request.IUploadFile; + +/** + * + * @author Raphael Jean + */ +public abstract class AbstractMultipartDecoder { + + /** + * Map of UploadPart (which implements IUploadFile), keyed on parameter + * name. + */ + protected Map _uploadParts = new HashMap(); + + /** + * Map of ValuePart, keyed on parameter name. + */ + private Map _valueParts = new HashMap(); + + protected int _maxSize = 10000000; + + protected int _thresholdSize = 1024; + + protected String _repositoryPath = System.getProperty("java.io.tmpdir"); + + protected String _encoding; + + public IUploadFile getFileUpload(String parameterName) { + return (IUploadFile) _uploadParts.get(parameterName); + } + + public void cleanup() { + Iterator i = _uploadParts.values().iterator(); + + while (i.hasNext()) { + UploadPart part = (UploadPart) i.next(); + + part.cleanup(); + } + } + + protected Map buildParameterMap() { + Map result = new HashMap(); + + Iterator i = _valueParts.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry e = (Map.Entry) i.next(); + + String name = (String) e.getKey(); + ValuePart part = (ValuePart) e.getValue(); + + result.put(name, part.getValues()); + } + + return result; + } + + protected void processFileItems(List parts) { + if (parts == null) + return; + + Iterator i = parts.iterator(); + + while (i.hasNext()) { + FileItem item = (FileItem) i.next(); + + processFileItem(item); + } + } + + private void processFileItem(FileItem item) { + if (item.isFormField()) { + processFormFieldItem(item); + return; + } + + processUploadFileItem(item); + } + + private void processUploadFileItem(FileItem item) { + String name = item.getFieldName(); + + UploadPart part = new UploadPart(item); + + _uploadParts.put(name, part); + } + + void processFormFieldItem(FileItem item) { + String name = item.getFieldName(); + + String value = extractFileItemValue(item); + + ValuePart part = (ValuePart) _valueParts.get(name); + + if (part == null) + _valueParts.put(name, new ValuePart(value)); + else + part.add(value); + } + + private String extractFileItemValue(FileItem item) { + try { + return (_encoding == null) ? item.getString() : item + .getString(_encoding); + } catch (UnsupportedEncodingException ex) { + throw new ApplicationRuntimeException(MultipartMessages + .unsupportedEncoding(_encoding, ex), ex); + } + } +} Modified: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoder.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoder.java?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoder.java (original) +++ jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoder.java Thu Feb 23 08:59:24 2006 @@ -14,38 +14,30 @@ package org.apache.tapestry.multipart; -import javax.servlet.http.HttpServletRequest; - import org.apache.tapestry.request.IUploadFile; /** - * Responsible for detecting and processing file upload requests, using Jakarta Commons FileUpload. - * Implementations of this service typically use the threaded service lifecycle model. + * Responsible for detecting and processing file upload requests, using Jakarta + * Commons FileUpload. Implementations of this service typically use the + * threaded service lifecycle model. * * @author Howard M. Lewis Ship * @since 4.0 */ -public interface MultipartDecoder -{ - /** - * Decodes the request, returning a new [EMAIL PROTECTED] javax.servlet.http.HttpServletRequest} - * implementation that will allow access to the form fields submitted in the request (but omits - * uploaded files. - */ - - public HttpServletRequest decode(HttpServletRequest request); - - /** - * Gets a file upload with the given name, or returns null if no such file upload was in the - * request. - */ - - public IUploadFile getFileUpload(String parameterName); - - /** - * Cleans up any temporary resources created during the request processing. This typically - * includes temporary files used to contain uploaded file content. - */ +public interface MultipartDecoder { + + /** + * Gets a file upload with the given name, or returns null if no such file + * upload was in the request. + */ + + public IUploadFile getFileUpload(String parameterName); + + /** + * Cleans up any temporary resources created during the request processing. + * This typically includes temporary files used to contain uploaded file + * content. + */ - public void cleanup(); -} \ No newline at end of file + void cleanup(); +} Modified: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderFilter.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderFilter.java?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderFilter.java (original) +++ jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderFilter.java Thu Feb 23 08:59:24 2006 @@ -32,8 +32,8 @@ */ public class MultipartDecoderFilter implements ServletRequestServicerFilter { - private MultipartDecoder _decoder; - + private ServletMultipartDecoder _decoder; + public void service(HttpServletRequest request, HttpServletResponse response, ServletRequestServicer servicer) throws IOException, ServletException { @@ -58,8 +58,8 @@ } } - public void setDecoder(MultipartDecoder decoder) + public void setDecoder(ServletMultipartDecoder decoder) { _decoder = decoder; } -} \ No newline at end of file +} Modified: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderImpl.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderImpl.java?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderImpl.java (original) +++ jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartDecoderImpl.java Thu Feb 23 08:59:24 2006 @@ -14,19 +14,17 @@ package org.apache.tapestry.multipart; -import java.io.UnsupportedEncodingException; -import java.util.HashMap; -import java.util.Iterator; +import java.io.File; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import org.apache.commons.fileupload.DiskFileUpload; -import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileUploadException; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.hivemind.ApplicationRuntimeException; -import org.apache.tapestry.request.IUploadFile; /** * Implementation of [EMAIL PROTECTED] org.apache.tapestry.multipart.MultipartDecoder}that is based on <a @@ -36,37 +34,17 @@ * @author Joe Panico * @since 4.0 */ -public class MultipartDecoderImpl implements MultipartDecoder +public class MultipartDecoderImpl extends AbstractMultipartDecoder implements ServletMultipartDecoder { - /** - * Map of UploadPart (which implements IUploadFile), keyed on parameter name. - */ - - private Map _uploadParts = new HashMap(); - - /** - * Map of ValuePart, keyed on parameter name. - */ - private Map _valueParts = new HashMap(); - - private int _maxSize = 10000000; - - private int _thresholdSize = 1024; - - private String _repositoryPath = System.getProperty("java.io.tmpdir"); - - private String _encoding; - public HttpServletRequest decode(HttpServletRequest request) { _encoding = request.getCharacterEncoding(); - DiskFileUpload upload = createUpload(request); + ServletFileUpload upload = createFileUpload(); try { - List fileItems = upload - .parseRequest(request, _thresholdSize, _maxSize, _repositoryPath); + List fileItems = upload.parseRequest(request); processFileItems(fileItems); } @@ -80,112 +58,14 @@ return new UploadFormParametersWrapper(request, parameterMap); } - private Map buildParameterMap() - { - Map result = new HashMap(); - - Iterator i = _valueParts.entrySet().iterator(); - while (i.hasNext()) - { - Map.Entry e = (Map.Entry) i.next(); - - String name = (String) e.getKey(); - ValuePart part = (ValuePart) e.getValue(); - - result.put(name, part.getValues()); - } - - return result; - } - - private void processFileItems(List parts) - { - if (parts == null) - return; - - Iterator i = parts.iterator(); - - while (i.hasNext()) - { - FileItem item = (FileItem) i.next(); - - processFileItem(item); - } - } - - private void processFileItem(FileItem item) - { - if (item.isFormField()) - { - processFormFieldItem(item); - return; - } - - processUploadFileItem(item); - } - - private void processUploadFileItem(FileItem item) - { - String name = item.getFieldName(); - - UploadPart part = new UploadPart(item); - - _uploadParts.put(name, part); - } - - void processFormFieldItem(FileItem item) - { - String name = item.getFieldName(); - - String value = extractFileItemValue(item); - - ValuePart part = (ValuePart) _valueParts.get(name); - - if (part == null) - _valueParts.put(name, new ValuePart(value)); - else - part.add(value); - } - - private String extractFileItemValue(FileItem item) - { - try - { - return (_encoding == null) ? item.getString() : item.getString(_encoding); - } - catch (UnsupportedEncodingException ex) - { - throw new ApplicationRuntimeException(MultipartMessages.unsupportedEncoding( - _encoding, - ex), ex); - } - } - - protected DiskFileUpload createUpload(HttpServletRequest request) - { - DiskFileUpload upload = new DiskFileUpload(); + private ServletFileUpload createFileUpload() { + FileItemFactory factory = new DiskFileItemFactory(_thresholdSize, new File(_repositoryPath)); + ServletFileUpload upload = new ServletFileUpload(factory); if (_encoding != null) upload.setHeaderEncoding(_encoding); return upload; - } - - public IUploadFile getFileUpload(String parameterName) - { - return (IUploadFile) _uploadParts.get(parameterName); - } - - public void cleanup() - { - Iterator i = _uploadParts.values().iterator(); - - while (i.hasNext()) - { - UploadPart part = (UploadPart) i.next(); - - part.cleanup(); - } - } + } } Modified: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartMessages.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartMessages.java?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartMessages.java (original) +++ jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/MultipartMessages.java Thu Feb 23 08:59:24 2006 @@ -22,11 +22,11 @@ * @author Howard M. Lewis Ship * @since 4.0 */ -class MultipartMessages +public class MultipartMessages { private final static MessageFormatter _formatter = new MessageFormatter(MultipartMessages.class); - static String unableToDecode(Throwable cause) + public static String unableToDecode(Throwable cause) { return _formatter.format("unable-to-decode", cause); } Added: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/ServletMultipartDecoder.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/ServletMultipartDecoder.java?rev=380151&view=auto ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/ServletMultipartDecoder.java (added) +++ jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/multipart/ServletMultipartDecoder.java Thu Feb 23 08:59:24 2006 @@ -0,0 +1,32 @@ +// Copyright 2005 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package org.apache.tapestry.multipart; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author Raphael Jean + * + */ +public interface ServletMultipartDecoder extends MultipartDecoder { + + /** + * Decodes the request, returning a new [EMAIL PROTECTED] javax.servlet.http.HttpServletRequest} + * implementation that will allow access to the form fields submitted in the request (but omits + * uploaded files. + */ + + public HttpServletRequest decode(HttpServletRequest request); + +} Modified: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/ServletWebContext.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/ServletWebContext.java?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/ServletWebContext.java (original) +++ jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/ServletWebContext.java Thu Feb 23 08:59:24 2006 @@ -14,9 +14,11 @@ package org.apache.tapestry.web; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.List; +import java.util.Set; import javax.servlet.ServletContext; @@ -37,18 +39,18 @@ private final ServletContext _servletContext; - public void describeTo(DescriptionReceiver receiver) - { - receiver.describeAlternate(_servletContext); - } - public ServletWebContext(ServletContext context) { Defense.notNull(context, "context"); _servletContext = context; } - + + public void describeTo(DescriptionReceiver receiver) + { + receiver.describeAlternate(_servletContext); + } + public List getAttributeNames() { return WebUtils.toSortedList(_servletContext.getAttributeNames()); @@ -96,4 +98,16 @@ { return _servletContext.getMimeType(resourcePath); } + + public String getRealPath(String path) { + return _servletContext.getRealPath(path); + } + + public InputStream getResourceAsStream(String path) { + return _servletContext.getResourceAsStream(path); + } + + public Set getResourcePaths(String path) { + return _servletContext.getResourcePaths(path); + } } Modified: jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/WebContext.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/WebContext.java?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/WebContext.java (original) +++ jakarta/tapestry/branches/4.0/framework/src/java/org/apache/tapestry/web/WebContext.java Thu Feb 23 08:59:24 2006 @@ -14,7 +14,9 @@ package org.apache.tapestry.web; +import java.io.InputStream; import java.net.URL; +import java.util.Set; import org.apache.tapestry.describe.Describable; @@ -38,4 +40,38 @@ * Returns the MIME type of the specified file, or null if the MIME type is not known. */ public String getMimeType(String resourcePath); + + /** + * Returns a directory-like listing of all the paths to resources within + * the web application whose longest sub-path matches the supplied + * path argument. Paths indicating subdirectory paths end with a slash (/). + * The returned paths are all relative to the root of the web application + * and have a leading '/'. + * @param path partial path used to match the resources, which must start with a '/' + * @return a Set containing the directory listing, or null if there are no resources + * in the web application whose path begins with the supplied path. + */ + public Set getResourcePaths(String path); + + /** + * Returns the resource located at the named path as an <code>InputStream</code> + * object. + * @param path a <code>String</code> specifying the path to the resource + * @return the <code>InputStream</code> returned to the servlet, + * or <code>null</code> if no resource exists at the specified path + */ + public InputStream getResourceAsStream(String path); + + /** + * Returns a <code>String</code> containing the real path for a given virtual path. + * For example, the path "/index.html" returns the absolute file path + * on the server's filesystem would be served by a request for + * "http://host/contextPath/index.html", where contextPath is the + * context path of this WebContext. + * + * @param path a <code>String</code> specifying a virtual path + * @return a <code>String</code> specifying the real path, or <code>null</code> if the + * translation cannot be performed + */ + public String getRealPath(String path); } Modified: jakarta/tapestry/branches/4.0/framework/src/scripts/TestUpload.xml URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/scripts/TestUpload.xml?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/scripts/TestUpload.xml (original) +++ jakarta/tapestry/branches/4.0/framework/src/scripts/TestUpload.xml Thu Feb 23 08:59:24 2006 @@ -110,6 +110,11 @@ </request> + <!-- IMPORTANT NOTE: commons-fileupload-1.1 has a bug that converts file path and + file name to lowercase. This is accounted for in the next test: the name + of the file should be Tapestry-Banner.png. + When this bug is fixed (fileupload 1.2), this test should be updated accordingly + --> <request content-type="multipart/form-data; boundary=---------------------------9d33212e1c03e3" content-path="context19/upload-image.request"> @@ -125,11 +130,11 @@ </assert-output> <assert-output name="Path"> - Path: [context19/Tapestry-Banner.png] + Path: [context19/tapestry-banner.png] </assert-output> <assert-output name="Name"> - Name: [Tapestry-Banner.png] + Name: [tapestry-banner.png] </assert-output> <assert-output name="Match Confirmation"> Modified: jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/multipart/TestMultipartDecoderFilter.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/multipart/TestMultipartDecoderFilter.java?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/multipart/TestMultipartDecoderFilter.java (original) +++ jakarta/tapestry/branches/4.0/framework/src/test/org/apache/tapestry/multipart/TestMultipartDecoderFilter.java Thu Feb 23 08:59:24 2006 @@ -83,8 +83,8 @@ HttpServletResponse response = newResponse(); HttpServletRequest decoded = (HttpServletRequest) newMock(HttpServletRequest.class); - MockControl control = newControl(MultipartDecoder.class); - MultipartDecoder decoder = (MultipartDecoder) control.getMock(); + MockControl control = newControl(ServletMultipartDecoder.class); + ServletMultipartDecoder decoder = (ServletMultipartDecoder) control.getMock(); decoder.decode(request); control.setReturnValue(decoded); Modified: jakarta/tapestry/branches/4.0/portlet/build.xml URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/portlet/build.xml?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/portlet/build.xml (original) +++ jakarta/tapestry/branches/4.0/portlet/build.xml Thu Feb 23 08:59:24 2006 @@ -46,6 +46,8 @@ <ibiblio-dependency artifact="log4j" version="${log4j.version}" group="log4j" use="test"/> <ibiblio-dependency artifact="javassist" version="${javassist.version}" group="javassist"/> <ibiblio-dependency artifact="servletapi" version="${servlet.version}" group="servletapi"/> + <ibiblio-dependency artifact="commons-fileupload" version="${fileupload.version}" group="commons-fileupload"/> + <ibiblio-dependency artifact="commons-io" version="${io.version}" group="commons-io"/> </target> Modified: jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/hivemodule.xml URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/hivemodule.xml?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/hivemodule.xml (original) +++ jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/hivemodule.xml Thu Feb 23 08:59:24 2006 @@ -25,6 +25,7 @@ <sub-module descriptor="tapestry.portlet.services.xml"/> <sub-module descriptor="tapestry.portlet.resolver.xml"/> <sub-module descriptor="tapestry.portlet.bindings.xml"/> + <sub-module descriptor="tapestry.portlet.multipart.xml"/> <configuration-point id="PortletApplicationInitializers" schema-id="hivemind.lib.ChainContribution"> Added: jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/tapestry.portlet.multipart.xml URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/tapestry.portlet.multipart.xml?rev=380151&view=auto ============================================================================== --- jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/tapestry.portlet.multipart.xml (added) +++ jakarta/tapestry/branches/4.0/portlet/src/descriptor/META-INF/tapestry.portlet.multipart.xml Thu Feb 23 08:59:24 2006 @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<!-- + Copyright 2005 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<module id="tapestry.portlet.multipart" version="4.0.0" package="org.apache.tapestry.portlet.multipart"> + + Support for multipart/form-data encoded requests used for file uploads. + + <service-point id="PortletMultipartDecoder"> + + Service responsible for parsing and decoding multipart form submissions. + + <create-instance class="PortletMultipartDecoderImpl" model="threaded"/> + + </service-point> + + <service-point id="PortletMultipartDecoderFilter" interface="org.apache.tapestry.portlet.ActionRequestServicerFilter"> + + Identifies upload requests and passes them to the PortletMultipartDecoder service + for decoding. + + <invoke-factory> + <construct class="PortletMultipartDecoderFilter"> + <set-service property="decoder" service-id="PortletMultipartDecoder"/> + </construct> + </invoke-factory> + + </service-point> + + <contribution configuration-id="tapestry.portlet.ActionRequestServicerPipeline"> + <filter name="PortletMultipartDecoderFilter" + object="service:PortletMultipartDecoderFilter"/> + </contribution> + + <contribution configuration-id="tapestry.Infrastructure"> + <property name="multipartDecoder" mode="portlet" object="service:PortletMultipartDecoder"/> + </contribution> +</module> \ No newline at end of file Modified: jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/PortletWebContext.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/PortletWebContext.java?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/PortletWebContext.java (original) +++ jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/PortletWebContext.java Thu Feb 23 08:59:24 2006 @@ -14,9 +14,11 @@ package org.apache.tapestry.portlet; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.List; +import java.util.Set; import javax.portlet.PortletContext; @@ -97,4 +99,16 @@ { receiver.describeAlternate(_portletContext); } -} \ No newline at end of file + + public String getRealPath(String path) { + return _portletContext.getRealPath(path); + } + + public InputStream getResourceAsStream(String path) { + return _portletContext.getResourceAsStream(path); + } + + public Set getResourcePaths(String path) { + return _portletContext.getResourcePaths(path); + } +} Added: jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/ActionRequestWrapper.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/ActionRequestWrapper.java?rev=380151&view=auto ============================================================================== --- jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/ActionRequestWrapper.java (added) +++ jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/ActionRequestWrapper.java Thu Feb 23 08:59:24 2006 @@ -0,0 +1,211 @@ +// Copyright 2006 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package org.apache.tapestry.portlet.multipart; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.security.Principal; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +import javax.portlet.ActionRequest; +import javax.portlet.PortalContext; +import javax.portlet.PortletMode; +import javax.portlet.PortletPreferences; +import javax.portlet.PortletSession; +import javax.portlet.WindowState; + +/** + * @author Raphael Jean + * + */ +public class ActionRequestWrapper extends Object implements ActionRequest +{ + private ActionRequest wrapped; + + public ActionRequestWrapper(ActionRequest request) + { + wrapped = request; + } + + public InputStream getPortletInputStream() throws IOException { + return wrapped.getPortletInputStream(); + } + + public void setCharacterEncoding(String arg0) + throws UnsupportedEncodingException { + wrapped.setCharacterEncoding(arg0); + } + + public BufferedReader getReader() throws UnsupportedEncodingException, + IOException { + return wrapped.getReader(); + } + + public String getCharacterEncoding() { + return wrapped.getCharacterEncoding(); + } + + public String getContentType() { + return wrapped.getContentType(); + } + + public int getContentLength() { + return wrapped.getContentLength(); + } + + public boolean isWindowStateAllowed(WindowState arg0) { + return wrapped.isWindowStateAllowed(arg0); + } + + public boolean isPortletModeAllowed(PortletMode arg0) { + return wrapped.isPortletModeAllowed(arg0); + } + + public PortletMode getPortletMode() { + return wrapped.getPortletMode(); + } + + public WindowState getWindowState() { + return wrapped.getWindowState(); + } + + public PortletPreferences getPreferences() { + return wrapped.getPreferences(); + } + + public PortletSession getPortletSession() { + return wrapped.getPortletSession(); + } + + public PortletSession getPortletSession(boolean arg0) { + return wrapped.getPortletSession(arg0); + } + + public String getProperty(String arg0) { + return wrapped.getProperty(arg0); + } + + public Enumeration getProperties(String arg0) { + return wrapped.getProperties(arg0); + } + + public Enumeration getPropertyNames() { + return wrapped.getPropertyNames(); + } + + public PortalContext getPortalContext() { + return wrapped.getPortalContext(); + } + + public String getAuthType() { + return wrapped.getAuthType(); + } + + public String getContextPath() { + return wrapped.getContextPath(); + } + + public String getRemoteUser() { + return wrapped.getRemoteUser(); + } + + public Principal getUserPrincipal() { + return wrapped.getUserPrincipal(); + } + + public boolean isUserInRole(String arg0) { + return wrapped.isUserInRole(arg0); + } + + public Object getAttribute(String arg0) { + return wrapped.getAttribute(arg0); + } + + public Enumeration getAttributeNames() { + return wrapped.getAttributeNames(); + } + + public String getParameter(String arg0) { + return wrapped.getParameter(arg0); + } + + public Enumeration getParameterNames() { + return wrapped.getParameterNames(); + } + + public String[] getParameterValues(String arg0) { + return wrapped.getParameterValues(arg0); + } + + public Map getParameterMap() { + return wrapped.getParameterMap(); + } + + public boolean isSecure() { + return wrapped.isSecure(); + } + + public void setAttribute(String arg0, Object arg1) { + wrapped.setAttribute(arg0, arg1); + } + + public void removeAttribute(String arg0) { + wrapped.removeAttribute(arg0); + } + + public String getRequestedSessionId() { + return wrapped.getRequestedSessionId(); + } + + public boolean isRequestedSessionIdValid() { + return wrapped.isRequestedSessionIdValid(); + } + + public String getResponseContentType() { + return wrapped.getResponseContentType(); + } + + public Enumeration getResponseContentTypes() { + return wrapped.getResponseContentTypes(); + } + + public Locale getLocale() { + return wrapped.getLocale(); + } + + public Enumeration getLocales() { + return wrapped.getLocales(); + } + + public String getScheme() { + return wrapped.getScheme(); + } + + public String getServerName() { + return wrapped.getServerName(); + } + + public int getServerPort() { + return wrapped.getServerPort(); + } + + protected ActionRequest getRequest() { + return wrapped; + } + +} \ No newline at end of file Added: jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoder.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoder.java?rev=380151&view=auto ============================================================================== --- jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoder.java (added) +++ jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoder.java Thu Feb 23 08:59:24 2006 @@ -0,0 +1,32 @@ +// Copyright 2006 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package org.apache.tapestry.portlet.multipart; + +import javax.portlet.ActionRequest; + +import org.apache.tapestry.multipart.MultipartDecoder; + +/** + * @author Raphael Jean + * + */ +public interface PortletMultipartDecoder extends MultipartDecoder { + /** + * Decodes the request, returning a new [EMAIL PROTECTED] javax.portlet.ActionRequest} + * implementation that will allow access to the form fields submitted in the request (but omits + * uploaded files). + */ + + public ActionRequest decode(ActionRequest request); +} Added: jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderFilter.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderFilter.java?rev=380151&view=auto ============================================================================== --- jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderFilter.java (added) +++ jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderFilter.java Thu Feb 23 08:59:24 2006 @@ -0,0 +1,61 @@ +// Copyright 2006 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package org.apache.tapestry.portlet.multipart; + +import java.io.IOException; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.PortletException; + +import org.apache.tapestry.portlet.ActionRequestServicer; +import org.apache.tapestry.portlet.ActionRequestServicerFilter; + +/** + * @author Raphael Jean + * + */ +public class PortletMultipartDecoderFilter implements ActionRequestServicerFilter +{ + private PortletMultipartDecoder _decoder; + + public void service(ActionRequest request, ActionResponse response, + ActionRequestServicer servicer) throws IOException, PortletException + { + String contentType = request.getContentType(); + + // contentType is occasionally null in testing. The browser tacks on additional + // information onto the contentType to indicate where the boundaries are in + // the stream. + + boolean encoded = contentType != null && contentType.startsWith("multipart/form-data"); + + try + { + ActionRequest newRequest = encoded ? _decoder.decode(request) : request; + + servicer.service(newRequest, response); + } + finally + { + if (encoded) + _decoder.cleanup(); + } + } + + public void setDecoder(PortletMultipartDecoder decoder) { + this._decoder = decoder; + } + +} \ No newline at end of file Added: jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderImpl.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderImpl.java?rev=380151&view=auto ============================================================================== --- jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderImpl.java (added) +++ jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/PortletMultipartDecoderImpl.java Thu Feb 23 08:59:24 2006 @@ -0,0 +1,67 @@ +// Copyright 2006 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package org.apache.tapestry.portlet.multipart; + +import java.io.File; +import java.util.List; +import java.util.Map; + +import javax.portlet.ActionRequest; + +import org.apache.commons.fileupload.FileItemFactory; +import org.apache.commons.fileupload.FileUploadException; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.portlet.PortletFileUpload; +import org.apache.hivemind.ApplicationRuntimeException; +import org.apache.tapestry.multipart.AbstractMultipartDecoder; +import org.apache.tapestry.multipart.MultipartMessages; + +/** + * @author Raphael Jean + * + */ +public class PortletMultipartDecoderImpl extends AbstractMultipartDecoder implements PortletMultipartDecoder { + + public ActionRequest decode(ActionRequest request) { + _encoding = request.getCharacterEncoding(); + + PortletFileUpload upload = createFileUpload(); + + try + { + List fileItems = upload.parseRequest(request); + + processFileItems(fileItems); + } + catch (FileUploadException ex) + { + throw new ApplicationRuntimeException(MultipartMessages.unableToDecode(ex), ex); + } + + Map parameterMap = buildParameterMap(); + + return new UploadFormPortletParametersWrapper(request, parameterMap); + } + + private PortletFileUpload createFileUpload() { + FileItemFactory factory = new DiskFileItemFactory(_thresholdSize, new File(_repositoryPath)); + PortletFileUpload upload = new PortletFileUpload(factory); + + if (_encoding != null) + upload.setHeaderEncoding(_encoding); + + return upload; + } + +} Added: jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/UploadFormPortletParametersWrapper.java URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/UploadFormPortletParametersWrapper.java?rev=380151&view=auto ============================================================================== --- jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/UploadFormPortletParametersWrapper.java (added) +++ jakarta/tapestry/branches/4.0/portlet/src/java/org/apache/tapestry/portlet/multipart/UploadFormPortletParametersWrapper.java Thu Feb 23 08:59:24 2006 @@ -0,0 +1,72 @@ +// Copyright 2006 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package org.apache.tapestry.portlet.multipart; + +import java.util.Collections; +import java.util.Enumeration; +import java.util.Map; + +import javax.portlet.ActionRequest; + +import org.apache.hivemind.util.Defense; +import org.apache.tapestry.multipart.ValuePart; + +/** + * @author Raphael Jean + * + */ +public class UploadFormPortletParametersWrapper extends ActionRequestWrapper { + + /** + * Map of [EMAIL PROTECTED] ValuePart} keyed on parameter name. + */ + private Map _parameterMap; + + public UploadFormPortletParametersWrapper(ActionRequest request, + Map parameterMap) { + super(request); + + Defense.notNull(parameterMap, "parameterMap"); + + _parameterMap = Collections.unmodifiableMap(parameterMap); + } + + public String getParameter(String name) + { + String[] values = getParameterValues(name); + + return (values == null || values.length == 0) ? null : values[0]; + } + + public Map getParameterMap() + { + return _parameterMap; + } + + public Enumeration getParameterNames() + { + return Collections.enumeration(_parameterMap.keySet()); + } + + public String[] getParameterValues(String name) + { + return (String[]) _parameterMap.get(name); + } + + public String toString() + { + return "<UploadFormPortletParametersWrapper for " + getRequest() + ">"; + } + +} \ No newline at end of file Modified: jakarta/tapestry/branches/4.0/status.xml URL: http://svn.apache.org/viewcvs/jakarta/tapestry/branches/4.0/status.xml?rev=380151&r1=380150&r2=380151&view=diff ============================================================================== --- jakarta/tapestry/branches/4.0/status.xml (original) +++ jakarta/tapestry/branches/4.0/status.xml Thu Feb 23 08:59:24 2006 @@ -60,6 +60,10 @@ Form.set_focus() not compatible with some ie fields. Patch adds logic to check more cross-browser friendly functions for setting focus. </action> + <action type="fix" dev="JK" fixes-bug="TAPESTRY-635" due-to="Raphael Jean" > + Applied patch upgrading tapestry to use commons-fileupload 1.1 as well as adding new + functionality enabling a more dynamic fileupload system for normal or portlet environments. + </action> </release> <release version="4.0" date="Jan 6 2006"> <action type="update" dev="HLS">Add link to DeveloperWorks Tapestry article</action> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]