Source Code Cross Referenced for FormField.java in  » Ajax » dwr » org » directwebremoting » extend » 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 » Ajax » dwr » org.directwebremoting.extend 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Joe Walker
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.directwebremoting.extend;
017:
018:        import java.io.ByteArrayInputStream;
019:        import java.io.InputStream;
020:
021:        /**
022:         * The result of a DWR query is normally a set of name/value pairs unless we are
023:         * doing file-upload in which case there is more information with each field.
024:         * This class replaces the value part of the set of name/value pairs to
025:         * provide access to the extra information.
026:         * @author Lance Semmens [uklance at gmail dot com]
027:         */
028:        public class FormField {
029:            /**
030:             * Standard ctor for the normal non file-upload case
031:             * @param value The string value 
032:             */
033:            public FormField(String value) {
034:                this .name = null;
035:                this .mimeType = null;
036:                this .file = false;
037:                this .bytes = value.getBytes();
038:                this .string = value;
039:            }
040:
041:            /**
042:             * Ctor for when we are in the special file-upload case
043:             * @param name The file name
044:             * @param mimeType The mime type sent by the browser
045:             * @param bytes The bytes sent by the browser
046:             */
047:            public FormField(String name, String mimeType, byte[] bytes) {
048:                this .name = name;
049:                this .mimeType = mimeType;
050:                this .file = true;
051:                this .bytes = bytes;
052:                this .string = null;
053:            }
054:
055:            /**
056:             * Returns the content type passed by the browser or null if not defined. 
057:             * @return The content type passed by the browser or null if not defined.
058:             */
059:            public String getMimeType() {
060:                return mimeType;
061:            }
062:
063:            /**
064:             * Returns an InputStream that can be used to retrieve the contents of the file. 
065:             * @return An InputStream that can be used to retrieve the contents of the file.
066:             */
067:            public InputStream getInputStream() {
068:                return new ByteArrayInputStream(bytes);
069:            }
070:
071:            /**
072:             * Returns the original filename in the client's file-system, as provided by
073:             * the browser (or other client software). 
074:             * In most cases, this will be the base file name, without path information.
075:             * However, some clients, such as the Opera browser, do include path
076:             * information.
077:             * @return The original filename in the client's file-system.
078:             */
079:            public String getName() {
080:                return name;
081:            }
082:
083:            /**
084:             * Returns the contents of the file item as a String.
085:             */
086:            public String getString() {
087:                if (string == null && bytes != null) {
088:                    string = new String(bytes);
089:                }
090:                return string;
091:            }
092:
093:            /**
094:             * Determines whether or not a FormField instance represents a simple form
095:             * field. 
096:             * @return true for an uploaded file; false for a simple form field.
097:             */
098:            public boolean isFile() {
099:                return file;
100:            }
101:
102:            /* (non-Javadoc)
103:             * @see java.lang.Object#toString()
104:             */
105:            @Override
106:            public String toString() {
107:                if (file) {
108:                    return "FormField: "
109:                            + ("byteCount=" + (bytes == null ? 0 : bytes.length));
110:                } else {
111:                    return "FormField: " + getString();
112:                }
113:            }
114:
115:            /* (non-Javadoc)
116:             * @see java.lang.Object#hashCode()
117:             */
118:            @Override
119:            public int hashCode() {
120:                int hash = 0;
121:                if (file) {
122:                    if (mimeType != null) {
123:                        hash += mimeType.hashCode();
124:                    }
125:
126:                    if (name != null) {
127:                        hash += name.hashCode();
128:                    }
129:                }
130:
131:                hash += getString().hashCode();
132:                return hash;
133:            }
134:
135:            /* (non-Javadoc)
136:             * @see java.lang.Object#equals(java.lang.Object)
137:             */
138:            @Override
139:            public boolean equals(Object obj) {
140:                if (obj == this ) {
141:                    return true;
142:                }
143:
144:                if (!(obj instanceof  FormField)) {
145:                    return false;
146:                }
147:
148:                FormField that = (FormField) obj;
149:
150:                if (this .file != that.file) {
151:                    return false;
152:                }
153:
154:                if (this .file) {
155:                    if (!equals(this .mimeType, that.mimeType)) {
156:                        return false;
157:                    }
158:
159:                    if (!equals(this .name, that.name)) {
160:                        return false;
161:                    }
162:                }
163:
164:                if (this .bytes.length != that.bytes.length) {
165:                    return false;
166:                }
167:
168:                for (int i = 0; i < this .bytes.length; ++i) {
169:                    if (this .bytes[i] != that.bytes[i]) {
170:                        return false;
171:                    }
172:                }
173:
174:                return true;
175:            }
176:
177:            private boolean equals(Object o1, Object o2) {
178:                if (o1 == null) {
179:                    return o2 == null;
180:                }
181:                return o1.equals(o2);
182:            }
183:
184:            private boolean file;
185:            private byte[] bytes;
186:            private String name;
187:            private String mimeType;
188:            private String string;
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.