Source Code Cross Referenced for CookieWrapper.java in  » Net » Coadunation_1.0.1 » com » rift » coad » lib » httpd » 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 » Net » Coadunation_1.0.1 » com.rift.coad.lib.httpd 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * CoadunationLib: The coaduntion implementation library.
003:         * Copyright (C) 2006  Rift IT Contracting
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
018:         *
019:         * CookieWrapper.java
020:         *
021:         * This class is responsible for wrapping the access to the cookie information
022:         * containied within, and for parsing cookie headers.
023:         */
024:
025:        // package path
026:        package com.rift.coad.lib.httpd;
027:
028:        // logging import
029:        import org.apache.log4j.Logger;
030:
031:        // java imports
032:        import java.net.InetAddress;
033:        import java.util.Date;
034:        import java.util.Map;
035:        import java.util.HashMap;
036:        import java.util.StringTokenizer;
037:        import java.util.TimeZone;
038:        import java.text.SimpleDateFormat;
039:
040:        // coadunation imports
041:        import com.rift.coad.lib.configuration.Configuration;
042:        import com.rift.coad.lib.configuration.ConfigurationFactory;
043:
044:        /**
045:         * This class is responsible for wrapping the access to the cookie information
046:         * containied within, and for parsing cookie headers.
047:         * 
048:         * @author Brett Chaldecott
049:         */
050:        public class CookieWrapper {
051:
052:            // class constants
053:            private final static String PATH = "Path";
054:            private final static String DOMAIN = "Domain";
055:            public final static String VERSION = "Version";
056:            public final static String DOLLAR = "$";
057:            private final static String VERSION_NUMBER = "1";
058:            private final static String COOKIE_HOST = "cookie_host";
059:
060:            // private member variables
061:            private Logger log = Logger
062:                    .getLogger(CookieWrapper.class.getName());
063:            private String name = null;
064:            private String value = null;
065:            private String domain = null;
066:            private String path = null;
067:
068:            /**
069:             * The constructor of the class responsible for processing the raw source.
070:             *
071:             * @param rawSrouce The raw source to process.
072:             * @exception HttpdException
073:             */
074:            public CookieWrapper(String rawSource) throws HttpdException {
075:                // check for valid formatting of cookie
076:                if (rawSource.contains("=") == false) {
077:                    throw new HttpdException("Incorrectly formated cookie ["
078:                            + rawSource + "]");
079:                }
080:                name = rawSource.substring(0, rawSource.indexOf('=')).trim()
081:                        .toLowerCase();
082:                value = stripInvertedCommas(
083:                        rawSource.substring(rawSource.indexOf('=') + 1).trim())
084:                        .trim();
085:            }
086:
087:            /**
088:             * 
089:             * Creates a new instance of CookieWrapper 
090:             * 
091:             * 
092:             * @param name The name associated with this cookie.
093:             * @param value The value wrapped within.
094:             * @exception HttpdException
095:             */
096:            public CookieWrapper(String name, String value)
097:                    throws HttpdException {
098:                try {
099:                    Configuration config = ConfigurationFactory.getInstance()
100:                            .getConfig(CookieWrapper.class);
101:                    this .name = name.toLowerCase().trim();
102:                    this .value = value;
103:                } catch (Exception ex) {
104:                    throw new HttpdException(
105:                            "Failed to init the cookie wrapper : "
106:                                    + ex.getMessage(), ex);
107:                }
108:            }
109:
110:            /**
111:             * This method returns the name of this cookie.
112:             *
113:             * @return The string containing the name of this cookie.
114:             */
115:            public String getName() {
116:                return name;
117:            }
118:
119:            /**
120:             * This method returns the value contained within.
121:             *
122:             * @return The string containing the value of the cookie.
123:             */
124:            public String getValue() {
125:                return value;
126:            }
127:
128:            /**
129:             * This method sets the value of the cookie.
130:             *
131:             * @param value The value to store in the cookie.
132:             */
133:            public void setValue(String value) {
134:                this .value = value;
135:            }
136:
137:            /**
138:             * This method returns the domain name.
139:             *
140:             * @return The string containing the domain name.
141:             */
142:            public String getDomain() {
143:                return domain;
144:            }
145:
146:            /**
147:             * This method sets the domain key value.
148:             *
149:             * @param domain The new domain to set.
150:             */
151:            public void setDomain(String domain) {
152:                this .domain = domain;
153:            }
154:
155:            /**
156:             * This method returns the path under which the cookie will be available.
157:             *
158:             * @return The path the cookie can be used on.
159:             */
160:            public String getPath() {
161:                return path;
162:            }
163:
164:            /**
165:             * This method sets the path.
166:             *
167:             * @param path The path to the object.
168:             */
169:            public void setPath(String path) {
170:                this .path = path;
171:            }
172:
173:            /**
174:             * This method generates a cookie string that can be used by Set-Cookie.
175:             *
176:             * @return A string that can be used as a Set cookie header.
177:             */
178:            public String getSetCookieString() {
179:                StringBuffer cookieBuffer = new StringBuffer();
180:                cookieBuffer.append(name).append("=").append(value).append(";")
181:                        .append(VERSION).append("=").append(VERSION_NUMBER);
182:                if (domain != null) {
183:                    cookieBuffer.append(";").append(DOMAIN).append("=").append(
184:                            domain);
185:                }
186:                if (path != null) {
187:                    cookieBuffer.append(";").append(PATH).append("=").append(
188:                            path);
189:                }
190:                return cookieBuffer.toString();
191:            }
192:
193:            /**
194:             * This method strips the inverted commas off a string.
195:             *
196:             * @return The stripped string.
197:             * @param value The string to strip the values off of.
198:             */
199:            private String stripInvertedCommas(String value) {
200:                int beginPos = value.indexOf('"');
201:                if (beginPos == -1) {
202:                    return value;
203:                }
204:                int endPos = value.indexOf('"', beginPos);
205:                return value.substring(beginPos, endPos);
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.