Source Code Cross Referenced for SavedRequestWrapper.java in  » Database-ORM » Velosurf » velosurf » util » 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 » Database ORM » Velosurf » velosurf.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003 The Apache Software Foundation.
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:
017:        package velosurf.util;
018:
019:        import javax.servlet.http.Cookie;
020:        import javax.servlet.http.HttpServletRequest;
021:        import javax.servlet.http.HttpSession;
022:        import javax.servlet.http.HttpServletRequestWrapper;
023:        import java.text.SimpleDateFormat;
024:        import java.util.*;
025:
026:        /**
027:         * <p>This class provides request parameters, headers, cookies from original requrest or saved request.</p>
028:         *
029:         * @author Andrey Grebnev <a href="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
030:         * @author <a href="mailto:claude.brisson@gmail.com">Claude Brisson</a>
031:         */
032:
033:        public @SuppressWarnings("deprecation")
034:        class SavedRequestWrapper extends HttpServletRequestWrapper {
035:
036:            /** the saved request. */
037:            private SavedRequest savedRequest = null;
038:
039:            /** timezone. */
040:            private static final TimeZone GMT_ZONE = TimeZone
041:                    .getTimeZone("GMT");
042:
043:            /**
044:             * The default Locale if none are specified.
045:             */
046:            private static final Locale defaultLocale = Locale.getDefault();
047:
048:            /**
049:             * The set of SimpleDateFormat formats to use in getDateHeader().
050:             *
051:             * Notice that because SimpleDateFormat is not thread-safe, we can't
052:             * declare formats[] as a static variable.
053:             */
054:            private SimpleDateFormat formats[] = new SimpleDateFormat[3];
055:
056:            /**
057:             * Constructor
058:             * @param request to save
059:             */
060:            public SavedRequestWrapper(HttpServletRequest request,
061:                    SavedRequest saved) {
062:                super (request);
063:
064:                HttpSession session = request.getSession(false);
065:                if (session == null)
066:                    return;
067:
068:                String requestURI = saved.getRequestURI();
069:                if (requestURI == null)
070:                    return;
071:
072:                savedRequest = saved;
073:
074:                formats[0] = new SimpleDateFormat(
075:                        "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
076:                formats[1] = new SimpleDateFormat(
077:                        "EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US);
078:                formats[2] = new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy",
079:                        Locale.US);
080:
081:                formats[0].setTimeZone(GMT_ZONE);
082:                formats[1].setTimeZone(GMT_ZONE);
083:                formats[2].setTimeZone(GMT_ZONE);
084:            }
085:
086:            /**
087:             * The default behavior of this method is to return getMethod()
088:             * on the wrapped request object.
089:             * @return the HTTP method
090:             */
091:            public String getMethod() {
092:                return savedRequest.getMethod();
093:            }
094:
095:            /**
096:             * The default behavior of this method is to return getHeader(String name)
097:             * on the wrapped request object.
098:             * @param name header name
099:             * @return header value or null
100:             */
101:            public String getHeader(String name) {
102:                String header = null;
103:                Iterator iterator = savedRequest.getHeaderValues(name);
104:                while (iterator.hasNext()) {
105:                    header = (String) iterator.next();
106:                    break;
107:                }
108:                return header;
109:            }
110:
111:            /**
112:             * The default behavior of this method is to return getIntHeader(String name)
113:             * on the wrapped request object.
114:             * @param name integer header name
115:             * @return integer header value or -1
116:             */
117:
118:            public int getIntHeader(String name) {
119:                String value = getHeader(name);
120:                if (value == null) {
121:                    return (-1);
122:                } else {
123:                    return (Integer.parseInt(value));
124:                }
125:            }
126:
127:            /**
128:             * The default behavior of this method is to return getDateHeader(String name)
129:             * on the wrapped request object.
130:             * @param name date header name
131:             * @return date header value or null
132:             */
133:            public long getDateHeader(String name) {
134:                String value = getHeader(name);
135:                if (value == null)
136:                    return (-1L);
137:
138:                // Attempt to convert the date header in a variety of formats
139:                long result = FastHttpDateFormat.parseDate(value, formats);
140:                if (result != (-1L)) {
141:                    return result;
142:                }
143:                throw new IllegalArgumentException(value);
144:            }
145:
146:            /**
147:             * The default behavior of this method is to return getHeaderNames()
148:             * on the wrapped request object.
149:             * @return an enumeration of header names
150:             */
151:
152:            public Enumeration getHeaderNames() {
153:                return new Enumerator(savedRequest.getHeaderNames());
154:            }
155:
156:            /**
157:             * The default behavior of this method is to return getHeaders(String name)
158:             * on the wrapped request object.
159:             * @param name multivalued header
160:             * @return enumeration of values for this header
161:             */
162:            public Enumeration getHeaders(String name) {
163:                return new Enumerator(savedRequest.getHeaderValues(name));
164:            }
165:
166:            /**
167:             * The default behavior of this method is to return getCookies()
168:             * on the wrapped request object.
169:             * @return cookies array
170:             */
171:            public Cookie[] getCookies() {
172:                List cookies = savedRequest.getCookies();
173:                return (Cookie[]) cookies.toArray(new Cookie[cookies.size()]);
174:            }
175:
176:            /**
177:             * The default behavior of this method is to return getParameterValues(String name)
178:             * on the wrapped request object.
179:             * @param name parameter name
180:             * @value array of values
181:             */
182:            public String[] getParameterValues(String name) {
183:                return savedRequest.getParameterValues(name);
184:            }
185:
186:            /**
187:             * The default behavior of this method is to return getParameterNames()
188:             * on the wrapped request object.
189:             * @return enumeration of parameter names
190:             */
191:
192:            public Enumeration getParameterNames() {
193:                return new Enumerator(savedRequest.getParameterNames());
194:            }
195:
196:            /**
197:             * The default behavior of this method is to return getParameterMap()
198:             * on the wrapped request object.
199:             * @return parameter map
200:             */
201:            public Map getParameterMap() {
202:                return savedRequest.getParameterMap();
203:            }
204:
205:            /**
206:             * The default behavior of this method is to return getParameter(String name)
207:             * on the wrapped request object.
208:             * @param name parameter name
209:             * @return  parameter value
210:             */
211:
212:            public String getParameter(String name) {
213:                String[] values = savedRequest.getParameterValues(name);
214:                if (values == null) {
215:                    return null;
216:                } else {
217:                    return values[0];
218:                }
219:            }
220:
221:            /**
222:             * The default behavior of this method is to return getLocales()
223:             * on the wrapped request object.
224:             * @return enumeration of locales
225:             */
226:
227:            public Enumeration getLocales() {
228:                Iterator iterator = savedRequest.getLocales();
229:                if (iterator.hasNext()) {
230:                    return new Enumerator(iterator);
231:                } else {
232:                    ArrayList results = new ArrayList();
233:                    results.add(defaultLocale);
234:                    return new Enumerator(results.iterator());
235:                }
236:            }
237:
238:            /**
239:             * The default behavior of this method is to return getLocale()
240:             * on the wrapped request object.
241:             * @return locale
242:             */
243:
244:            public Locale getLocale() {
245:                Locale locale = null;
246:                Iterator iterator = savedRequest.getLocales();
247:                while (iterator.hasNext()) {
248:                    locale = (Locale) iterator.next();
249:                    break;
250:                }
251:                if (locale == null) {
252:                    return defaultLocale;
253:                } else {
254:                    return locale;
255:                }
256:            }
257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.