Source Code Cross Referenced for ServletParameter.java in  » Scripting » Pnuts » org » pnuts » servlet » 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 » Scripting » Pnuts » org.pnuts.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ServletParameter.java
003:         *
004:         * Copyright (c) 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         *
006:         * See the file "LICENSE.txt" for information on usage and redistribution
007:         * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
008:         */
009:        package org.pnuts.servlet;
010:
011:        import java.io.UnsupportedEncodingException;
012:        import java.util.Collection;
013:        import java.util.Iterator;
014:        import java.util.Map;
015:        import java.util.Set;
016:        import java.util.AbstractSet;
017:        import org.pnuts.net.URLEncoding;
018:        import pnuts.lang.Pnuts;
019:
020:        class ServletParameter implements  Map {
021:            private Map map;
022:
023:            public ServletParameter(Map map) {
024:                this .map = map;
025:            }
026:
027:            public int size() {
028:                return map.size();
029:            }
030:
031:            public boolean isEmpty() {
032:                return map.isEmpty();
033:            }
034:
035:            public boolean containsKey(Object key) {
036:                return map.containsKey(key);
037:            }
038:
039:            public boolean containsValue(Object value) {
040:                throw new UnsupportedOperationException();
041:            }
042:
043:            public Set keySet() {
044:                return map.keySet();
045:            }
046:
047:            public Set entrySet() {
048:                return new ParameterSet(map.entrySet());
049:            }
050:
051:            public Object[] getAll(String name) {
052:                return (Object[]) map.get(name);
053:            }
054:
055:            public Object get(Object name) {
056:                return get(name, null);
057:            }
058:
059:            public Object get(Object name, String defaultValue) {
060:                Object[] array = (Object[]) map.get(name);
061:                if (array == null) {
062:                    return defaultValue;
063:                } else {
064:                    return array[0];
065:                }
066:            }
067:
068:            public Object put(Object key, Object value) {
069:                if (value instanceof  Object[]) {
070:                    return map.put(key, (Object[]) value);
071:                } else {
072:                    return map.put(key, new Object[] { value });
073:                }
074:            }
075:
076:            public void putAll(Map t) {
077:                map.putAll(t);
078:            }
079:
080:            public Object remove(Object key) {
081:                return map.remove(key);
082:            }
083:
084:            public void clear() {
085:                map.clear();
086:            }
087:
088:            public Collection values() {
089:                return new ValueSet(map.values());
090:            }
091:
092:            public void copyInto(Map m) {
093:                Iterator it = map.keySet().iterator();
094:                if (it.hasNext()) {
095:                    Object key = it.next();
096:                    Object value = map.get(key);
097:                    if (value instanceof  Object[]) {
098:                        value = ((Object[]) value)[0];
099:                    }
100:                    m.put(key, value);
101:                }
102:            }
103:
104:            public String toQueryString(String encoding)
105:                    throws UnsupportedEncodingException {
106:                StringBuffer sbuf = new StringBuffer();
107:                Iterator it = map.entrySet().iterator();
108:                boolean first = true;
109:                if (it.hasNext()) {
110:                    Map.Entry entry = (Map.Entry) it.next();
111:                    String key = (String) entry.getKey();
112:                    Object value = entry.getValue();
113:                    if (value instanceof  Object[]) {
114:                        Object[] array = (Object[]) value;
115:                        for (int i = 0; i < array.length; i++) {
116:                            if (!first) {
117:                                sbuf.append('&');
118:                                first = false;
119:                            }
120:                            sbuf.append(URLEncoding.encode(key, encoding));
121:                            sbuf.append('=');
122:                            sbuf.append(URLEncoding.encode((String) array[i],
123:                                    encoding));
124:                        }
125:                    } else {
126:                        first = false;
127:                        sbuf.append(URLEncoding.encode(key, encoding));
128:                        sbuf.append('=');
129:                        sbuf.append(URLEncoding
130:                                .encode((String) value, encoding));
131:                    }
132:                }
133:                while (it.hasNext()) {
134:                    Map.Entry entry = (Map.Entry) it.next();
135:                    String key = (String) entry.getKey();
136:                    Object value = entry.getValue();
137:                    if (value instanceof  Object[]) {
138:                        Object[] array = (Object[]) value;
139:                        for (int i = 0; i < array.length; i++) {
140:                            sbuf.append('&');
141:                            sbuf.append(URLEncoding.encode(key, encoding));
142:                            sbuf.append('=');
143:                            sbuf.append(URLEncoding.encode((String) array[i],
144:                                    encoding));
145:                        }
146:                    } else {
147:                        sbuf.append('&');
148:                        sbuf.append(URLEncoding.encode(key, encoding));
149:                        sbuf.append('=');
150:                        sbuf.append(URLEncoding
151:                                .encode((String) value, encoding));
152:                    }
153:                }
154:                return sbuf.toString();
155:            }
156:
157:            public String toString() {
158:                StringBuffer sbuf = new StringBuffer();
159:                sbuf.append('{');
160:                Iterator it = map.keySet().iterator();
161:                Object key, value;
162:                if (it.hasNext()) {
163:                    sbuf.append(key = it.next());
164:                    sbuf.append('=');
165:                    sbuf.append(Pnuts.format(map.get(key)));
166:                }
167:                while (it.hasNext()) {
168:                    sbuf.append(',');
169:                    sbuf.append(key = it.next());
170:                    sbuf.append('=');
171:                    sbuf.append(Pnuts.format(map.get(key)));
172:                }
173:                sbuf.append('}');
174:                return sbuf.toString();
175:            }
176:
177:            static class ValueSet extends AbstractSet {
178:                private Collection col;
179:
180:                ValueSet(Collection col) {
181:                    this .col = col;
182:                }
183:
184:                public Iterator iterator() {
185:                    return new ParameterIterator(this .col.iterator(), 1);
186:                }
187:
188:                public int size() {
189:                    return col.size();
190:                }
191:            }
192:
193:            static class ParameterSet extends AbstractSet {
194:                private Set set;
195:
196:                ParameterSet(Set set) {
197:                    this .set = set;
198:                }
199:
200:                public Iterator iterator() {
201:                    return new ParameterIterator(this .set.iterator(), 0);
202:                }
203:
204:                public int size() {
205:                    return set.size();
206:                }
207:            }
208:
209:            static class ParameterIterator implements  Iterator {
210:                private Iterator it;
211:                private ParameterEntry entry;
212:                private int type; // 0==Entry,1==Value,2==Key
213:
214:                ParameterIterator(Iterator it, int type) {
215:                    this .it = it;
216:                    this .type = type;
217:                    if (type == 0) {
218:                        this .entry = new ParameterEntry();
219:                    }
220:                }
221:
222:                public boolean hasNext() {
223:                    return it.hasNext();
224:                }
225:
226:                public Object next() {
227:                    if (type == 0) {
228:                        Map.Entry n = (Map.Entry) it.next();
229:                        entry.attach(n);
230:                        return entry;
231:                    } else if (type == 1) {
232:                        Object[] n = (Object[]) it.next();
233:                        if (n != null && n.length > 0) {
234:                            return n[0];
235:                        } else {
236:                            return null;
237:                        }
238:                    } else {
239:                        return it.next();
240:                    }
241:                }
242:
243:                public void remove() {
244:                    this .it.remove();
245:                }
246:            }
247:
248:            static class ParameterEntry implements  Map.Entry {
249:                private Map.Entry entry;
250:
251:                ParameterEntry() {
252:                }
253:
254:                void attach(Map.Entry entry) {
255:                    this .entry = entry;
256:                }
257:
258:                public Object getKey() {
259:                    return this .entry.getKey();
260:                }
261:
262:                public Object getValue() {
263:                    return ((Object[]) entry.getValue())[0];
264:                }
265:
266:                public Object[] getValues() {
267:                    return (Object[]) entry.getValue();
268:                }
269:
270:                public Object setValue(Object value) {
271:                    return (Object[]) entry.setValue(new Object[] { value });
272:                }
273:
274:                public int hashCode() {
275:                    return entry.getKey().hashCode()
276:                            ^ entry.getValue().hashCode();
277:                }
278:
279:                public boolean equals(Object obj) {
280:                    if (obj instanceof  ParameterEntry) {
281:                        ParameterEntry that = (ParameterEntry) obj;
282:                        Object k1 = getKey();
283:                        Object k2 = that.getKey();
284:                        Object v1 = getValue();
285:                        Object v2 = that.getValue();
286:                        return (k1 == k2 || (k1 != null && k1.equals(k2)))
287:                                && (v1 == v2 || (v1 != null && v1.equals(v2)));
288:                    } else {
289:                        return false;
290:                    }
291:                }
292:            }
293:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.