| Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
| WOCookie |
|
| 1.0588235294117647;1.059 |
| 1 | /* |
|
| 2 | Wotonomy: OpenStep design patterns for pure Java applications. |
|
| 3 | Copyright (C) 2000 Blacksmith, Inc. |
|
| 4 | ||
| 5 | This library is free software; you can redistribute it and/or |
|
| 6 | modify it under the terms of the GNU Lesser General Public |
|
| 7 | License as published by the Free Software Foundation; either |
|
| 8 | version 2.1 of the License, or (at your option) any later version. |
|
| 9 | ||
| 10 | This library is distributed in the hope that it will be useful, |
|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 | Lesser General Public License for more details. |
|
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public |
|
| 16 | License along with this library; if not, see http://www.gnu.org |
|
| 17 | */ |
|
| 18 | ||
| 19 | package net.wotonomy.web; |
|
| 20 | ||
| 21 | import net.wotonomy.foundation.NSDate; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * A pure java implementation of WOCookie that extends |
|
| 25 | * javax.servlet.httpd.Cookie for greater compatibility. |
|
| 26 | * |
|
| 27 | * @author michael@mpowers.net |
|
| 28 | * @author $Author: cgruber $ |
|
| 29 | * @version $Revision: 905 $ |
|
| 30 | */ |
|
| 31 | public class WOCookie |
|
| 32 | extends javax.servlet.http.Cookie |
|
| 33 | { |
|
| 34 | /** |
|
| 35 | * Default constructor. |
|
| 36 | */ |
|
| 37 | public WOCookie () |
|
| 38 | { |
|
| 39 | 0 | super( "", "" ); |
| 40 | 0 | } |
| 41 | ||
| 42 | /** |
|
| 43 | * Constructs a cookie with the specified name and value. |
|
| 44 | */ |
|
| 45 | public WOCookie( String aName, String aValue ) |
|
| 46 | { |
|
| 47 | 0 | super( aName, aValue ); |
| 48 | 0 | } |
| 49 | ||
| 50 | /** |
|
| 51 | * Constructs a cookie with the specified name and value. |
|
| 52 | * Also sets the path to the current application's path. |
|
| 53 | */ |
|
| 54 | public static WOCookie cookieWithName (String aName, String aValue) |
|
| 55 | { |
|
| 56 | 0 | WOCookie result = new WOCookie( aName, aValue ); |
| 57 | //TODO: Set the path to the current application's path. |
|
| 58 | 0 | return result; |
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * Constructs a cookie with the specified attributes. |
|
| 63 | */ |
|
| 64 | public static WOCookie cookieWithName (String aName, String aValue, |
|
| 65 | String aPath, String aDomain, NSDate expirationDate, boolean secure) |
|
| 66 | { |
|
| 67 | 0 | WOCookie result = new WOCookie( aName, aValue ); |
| 68 | 0 | result.setPath( aPath ); |
| 69 | 0 | result.setDomain( aDomain ); |
| 70 | 0 | result.setExpires( expirationDate ); |
| 71 | 0 | result.setSecure( secure ); |
| 72 | 0 | return result; |
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * Returns the name of the cookie. |
|
| 77 | */ |
|
| 78 | public String name () |
|
| 79 | { |
|
| 80 | 0 | return this.getName(); |
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Sets the name of the cookie. |
|
| 85 | */ |
|
| 86 | public void setName (String aString) |
|
| 87 | { |
|
| 88 | // super.setName( aString ); |
|
| 89 | 0 | throw new RuntimeException( "Not yet implemented." ); |
| 90 | } |
|
| 91 | ||
| 92 | /** |
|
| 93 | * Returns the value of the cookie. |
|
| 94 | */ |
|
| 95 | public String value () |
|
| 96 | { |
|
| 97 | 0 | return this.getValue(); |
| 98 | } |
|
| 99 | ||
| 100 | /** |
|
| 101 | * Sets the value of the cookie. |
|
| 102 | */ |
|
| 103 | public void setValue (String aString) |
|
| 104 | { |
|
| 105 | 0 | super.setValue( aString ); |
| 106 | 0 | } |
| 107 | ||
| 108 | /** |
|
| 109 | * Gets the domain of the cookie. |
|
| 110 | */ |
|
| 111 | public String domain () |
|
| 112 | { |
|
| 113 | 0 | return this.getDomain(); |
| 114 | } |
|
| 115 | ||
| 116 | /** |
|
| 117 | * Sets the domain of the cookie. |
|
| 118 | */ |
|
| 119 | public void setDomain (String aString) |
|
| 120 | { |
|
| 121 | 0 | super.setDomain( aString ); |
| 122 | 0 | } |
| 123 | ||
| 124 | /** |
|
| 125 | * Gets the path of the cookie. |
|
| 126 | */ |
|
| 127 | public String path () |
|
| 128 | { |
|
| 129 | 0 | return this.getPath(); |
| 130 | } |
|
| 131 | ||
| 132 | /** |
|
| 133 | * Sets the path of the cookie. |
|
| 134 | */ |
|
| 135 | public void setPath (String aString) |
|
| 136 | { |
|
| 137 | 0 | super.setPath( aString ); |
| 138 | 0 | } |
| 139 | ||
| 140 | /** |
|
| 141 | * Gets the expiration date of the cookie. |
|
| 142 | * If in the past, the cookie will persist until browser shutdown. |
|
| 143 | */ |
|
| 144 | public NSDate expires () |
|
| 145 | { |
|
| 146 | 0 | return new NSDate( this.getMaxAge() ); |
| 147 | } |
|
| 148 | ||
| 149 | /** |
|
| 150 | * Sets the expiration date of the cookie. |
|
| 151 | */ |
|
| 152 | public void setExpires (NSDate aDate) |
|
| 153 | { |
|
| 154 | 0 | this.setMaxAge( (int) aDate.timeIntervalSinceNow() ); |
| 155 | 0 | } |
| 156 | ||
| 157 | /** |
|
| 158 | * Returns whether the cookie will only be sent over a secure protocol. |
|
| 159 | */ |
|
| 160 | public boolean isSecure () |
|
| 161 | { |
|
| 162 | 0 | return this.getSecure(); |
| 163 | } |
|
| 164 | ||
| 165 | /** |
|
| 166 | * Sets whether the cookie will only be sent over a secure protocol. |
|
| 167 | */ |
|
| 168 | public void setIsSecure (boolean isSecure) |
|
| 169 | { |
|
| 170 | 0 | this.setSecure( isSecure ); |
| 171 | 0 | } |
| 172 | ||
| 173 | /** |
|
| 174 | * Returns the string as it appears in the HTTP header of the response. |
|
| 175 | * This would normally be called by WOResponse, but is handled automatically |
|
| 176 | * by the servlet implementation. |
|
| 177 | */ |
|
| 178 | public String headerString () |
|
| 179 | { |
|
| 180 | 0 | new RuntimeException( "Not implemented yet." ); |
| 181 | 0 | return null; |
| 182 | } |
|
| 183 | } |
|
| 184 | ||
| 185 | /* |
|
| 186 | * $Log$ |
|
| 187 | * Revision 1.2 2006/02/19 01:44:02 cgruber |
|
| 188 | * Add xmlrpc files |
|
| 189 | * Remove jclark and replace with dom4j and javax.xml.sax stuff |
|
| 190 | * Re-work dependencies and imports so it all compiles. |
|
| 191 | * |
|
| 192 | * Revision 1.1 2006/02/16 13:22:22 cgruber |
|
| 193 | * Check in all sources in eclipse-friendly maven-enabled packages. |
|
| 194 | * |
|
| 195 | * Revision 1.1.1.1 2000/12/21 15:53:04 mpowers |
|
| 196 | * Contributing wotonomy. |
|
| 197 | * |
|
| 198 | * Revision 1.2 2000/12/20 16:25:50 michael |
|
| 199 | * Added log to all files. |
|
| 200 | * |
|
| 201 | * |
|
| 202 | */ |
|
| 203 |