Source Code Cross Referenced for DefaultCookieParser.java in  » Web-Framework » TURBINE » org » apache » turbine » util » parser » 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 » Web Framework » TURBINE » org.apache.turbine.util.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.util.parser;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import javax.servlet.http.Cookie;
023:        import javax.servlet.http.HttpServletRequest;
024:        import javax.servlet.http.HttpServletResponse;
025:
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:
029:        import org.apache.turbine.util.RunData;
030:        import org.apache.turbine.util.ServerData;
031:        import org.apache.turbine.util.pool.Recyclable;
032:        import org.apache.turbine.util.uri.DataURI;
033:        import org.apache.turbine.util.uri.URI;
034:
035:        /**
036:         * CookieParser is used to get and set values of Cookies on the Client
037:         * Browser.  You can use CookieParser to convert Cookie values to
038:         * various types or to set Bean values with setParameters(). See the
039:         * Servlet Spec for more information on Cookies.
040:         * <p>
041:         * Use set() or unset() to Create or Destroy Cookies.
042:         * <p>
043:         * NOTE: The name= portion of a name=value pair may be converted
044:         * to lowercase or uppercase when the object is initialized and when
045:         * new data is added.  This behaviour is determined by the url.case.folding
046:         * property in TurbineResources.properties.  Adding a name/value pair may
047:         * overwrite existing name=value pairs if the names match:
048:         *
049:         * <pre>
050:         * CookieParser cp = data.getCookies();
051:         * cp.add("ERROR",1);
052:         * cp.add("eRrOr",2);
053:         * int result = cp.getInt("ERROR");
054:         * </pre>
055:         *
056:         * In the above example, result is 2.
057:         *
058:         * @author <a href="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
059:         * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
060:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
061:         * @version $Id: DefaultCookieParser.java 534527 2007-05-02 16:10:59Z tv $
062:         */
063:        public class DefaultCookieParser extends BaseValueParser implements 
064:                CookieParser, Recyclable {
065:            /** Logging */
066:            private static Log log = LogFactory
067:                    .getLog(DefaultCookieParser.class);
068:
069:            /** Internal Run Data object containing the parameters to parse */
070:            private RunData data = null;
071:
072:            /** Just like Fulcrum, we actually use the Request and response objects */
073:            private HttpServletRequest request;
074:
075:            /** Just like Fulcrum, we actually use the Request and response objects */
076:            private HttpServletResponse response;
077:
078:            /** The cookie path. */
079:            private URI cookiePath = null;
080:
081:            /**
082:             * Constructs a new CookieParser.
083:             */
084:            public DefaultCookieParser() {
085:                super ();
086:            }
087:
088:            /**
089:             * Disposes the parser.
090:             */
091:            public void dispose() {
092:                this .data = null;
093:                this .cookiePath = null;
094:                this .request = null;
095:                this .response = null;
096:                super .dispose();
097:            }
098:
099:            /**
100:             * Gets the parsed RunData.
101:             *
102:             * @return the parsed RunData object or null.
103:             * @deprecated Don't use the Run Data object. use getRequest().
104:             */
105:            public RunData getRunData() {
106:                return data;
107:            }
108:
109:            /**
110:             * Gets the Request Object for this parser.
111:             *
112:             * @return the HttpServletRequest or null.
113:             */
114:            public HttpServletRequest getRequest() {
115:                return request;
116:            }
117:
118:            /**
119:             * Sets the RunData to be parsed. This is a convenience method to
120:             * set the request and response from the RunData object. It is
121:             * equivalent to
122:             *
123:             * <pre>
124:             *  setData(data.getRequest(), data.getResponse());
125:             * </pre>
126:             *
127:             * All previous cookies will be cleared.
128:             *
129:             * @param data the RunData object.
130:             */
131:            public void setRunData(RunData data) {
132:                this .data = data;
133:                setData(data.getRequest(), data.getResponse());
134:            }
135:
136:            /**
137:             * Sets Request and Response to be parsed.
138:             * <p>
139:             * All previous cookies will be cleared.
140:             *
141:             * @param request The http request from the servlet
142:             * @param response The http reponse from the servlet
143:             */
144:            public void setData(HttpServletRequest request,
145:                    HttpServletResponse response) {
146:                clear();
147:
148:                String enc = request.getCharacterEncoding();
149:                setCharacterEncoding(enc != null ? enc : "US-ASCII");
150:
151:                cookiePath = new DataURI(new ServerData(request));
152:
153:                Cookie[] cookies = request.getCookies();
154:
155:                int cookiesCount = (cookies != null) ? cookies.length : 0;
156:
157:                log.debug("Number of Cookies: " + cookiesCount);
158:
159:                for (int i = 0; i < cookiesCount; i++) {
160:                    String name = convert(cookies[i].getName());
161:                    String value = cookies[i].getValue();
162:                    log.debug("Adding " + name + "=" + value);
163:                    add(name, value);
164:                }
165:
166:                this .request = request;
167:                this .response = response;
168:            }
169:
170:            /**
171:             * Get the Path where cookies will be stored
172:             *
173:             * @return path for cookie storage
174:             */
175:            public URI getCookiePath() {
176:                return cookiePath;
177:            }
178:
179:            /**
180:             * Set the path for cookie storage
181:             *
182:             * @param cookiePath path for cookie storage
183:             */
184:            public void setCookiePath(URI cookiePath) {
185:                this .cookiePath = cookiePath;
186:            }
187:
188:            /**
189:             * Set a cookie that will be stored on the client for
190:             * the duration of the session.
191:             *
192:             * @param name name of the cookie
193:             * @param value value of the cookie
194:             */
195:            public void set(String name, String value) {
196:                set(name, value, AGE_SESSION);
197:            }
198:
199:            /**
200:             * Set a persisten cookie on the client that will expire
201:             * after a maximum age (given in seconds).
202:             *
203:             * @param name name of the cookie
204:             * @param value value of the cookie
205:             * @param seconds_age max age of the cookie in seconds
206:             */
207:            public void set(String name, String value, int seconds_age) {
208:                if (response == null) {
209:                    throw new IllegalStateException(
210:                            "Servlet response not available");
211:                }
212:
213:                Cookie cookie = new Cookie(name, value);
214:                cookie.setMaxAge(seconds_age);
215:                cookie.setPath(cookiePath.getContextPath()
216:                        + cookiePath.getScriptName());
217:                response.addCookie(cookie);
218:            }
219:
220:            /**
221:             * Remove a previously set cookie from the client machine.
222:             *
223:             * @param name name of the cookie
224:             */
225:            public void unset(String name) {
226:                set(name, " ", AGE_DELETE);
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.