Source Code Cross Referenced for PellMultiPartRequest.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » dispatcher » multipart » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » webwork 2.2.6 » com.opensymphony.webwork.dispatcher.multipart 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.dispatcher.multipart;
006:
007:        import com.opensymphony.webwork.config.Configuration;
008:        import com.opensymphony.webwork.WebWorkConstants;
009:        import http.utils.multipartrequest.ServletMultipartRequest;
010:
011:        import javax.servlet.http.HttpServletRequest;
012:        import java.io.File;
013:        import java.io.IOException;
014:        import java.io.UnsupportedEncodingException;
015:        import java.util.ArrayList;
016:        import java.util.Collections;
017:        import java.util.Enumeration;
018:        import java.util.List;
019:
020:        /**
021:         * Multipart form data request adapter for Jason Pell's multipart utils package.
022:         *
023:         * @author <a href="matt@smallleap.com">Matt Baldree</a> (modified for WW's use)
024:         * @author <a href="scott@atlassian.com">Scott Farquhar</a> (added i18n handling (WW-109))
025:         */
026:        public class PellMultiPartRequest extends MultiPartRequest {
027:
028:            private ServletMultipartRequest multi;
029:
030:            /**
031:             * Creates a new request wrapper to handle multi-part data using methods adapted from Jason Pell's
032:             * multipart classes (see class description).
033:             *
034:             * @param maxSize        maximum size post allowed
035:             * @param saveDir        the directory to save off the file
036:             * @param servletRequest the request containing the multipart
037:             */
038:            public PellMultiPartRequest(HttpServletRequest servletRequest,
039:                    String saveDir, int maxSize) throws IOException {
040:                //this needs to be synchronised, as we should not change the encoding at the same time as
041:                //calling the constructor.  See javadoc for MultipartRequest.setEncoding().
042:                synchronized (this ) {
043:                    setEncoding();
044:                    multi = new ServletMultipartRequest(servletRequest,
045:                            saveDir, maxSize);
046:                }
047:            }
048:
049:            public Enumeration getFileParameterNames() {
050:                return multi.getFileParameterNames();
051:            }
052:
053:            public String[] getContentType(String fieldName) {
054:                return new String[] { multi.getContentType(fieldName) };
055:            }
056:
057:            public File[] getFile(String fieldName) {
058:                return new File[] { multi.getFile(fieldName) };
059:            }
060:
061:            public String[] getFileNames(String fieldName) {
062:
063:                // TODO - not sure about this - is this the filename of the actual file or
064:                // TODO - the uploaded filename as provided by the browser?
065:                // TODO - Not sure what version of Pell this class uses as it doesn't seem to be the latest
066:                return new String[] { multi.getFile(fieldName).getName() };
067:            }
068:
069:            public String[] getFilesystemName(String fieldName) {
070:                return new String[] { multi.getFileSystemName(fieldName) };
071:            }
072:
073:            public String getParameter(String name) {
074:                return multi.getURLParameter(name);
075:            }
076:
077:            public Enumeration getParameterNames() {
078:                return multi.getParameterNames();
079:            }
080:
081:            public String[] getParameterValues(String name) {
082:                Enumeration enumeration = multi.getURLParameters(name);
083:
084:                if (!enumeration.hasMoreElements()) {
085:                    return null;
086:                }
087:
088:                List values = new ArrayList();
089:
090:                while (enumeration.hasMoreElements()) {
091:                    values.add(enumeration.nextElement());
092:                }
093:
094:                return (String[]) values.toArray(new String[values.size()]);
095:            }
096:
097:            public List getErrors() {
098:                return Collections.EMPTY_LIST;
099:            }
100:
101:            /**
102:             * Sets the encoding for the uploaded params.  This needs to be set if you are using character sets other than
103:             * ASCII.
104:             * <p/>
105:             * The encoding is looked up from the configuration setting 'webwork.i18n.encoding'.  This is usually set in
106:             * default.properties & webwork.properties.
107:             */
108:            private static void setEncoding() {
109:                String encoding = null;
110:
111:                try {
112:                    encoding = Configuration
113:                            .getString(WebWorkConstants.WEBWORK_I18N_ENCODING);
114:
115:                    if (encoding != null) {
116:                        //NB: This should never be called at the same time as the constructor for
117:                        //ServletMultiPartRequest, as it can cause problems.
118:                        //See javadoc for MultipartRequest.setEncoding()
119:                        http.utils.multipartrequest.MultipartRequest
120:                                .setEncoding(encoding);
121:                    } else {
122:                        http.utils.multipartrequest.MultipartRequest
123:                                .setEncoding("UTF-8");
124:                    }
125:                } catch (IllegalArgumentException e) {
126:                    log
127:                            .info("Could not get encoding property 'webwork.i18n.encoding' for file upload.  Using system default");
128:                } catch (UnsupportedEncodingException e) {
129:                    log
130:                            .error("Encoding "
131:                                    + encoding
132:                                    + " is not a valid encoding.  Please check your webwork.properties file.");
133:                }
134:            }
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.