KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > portlet > PortletCookie


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.environment.portlet;
17
18 import org.apache.cocoon.environment.Cookie;
19
20 /**
21  * Implements {@link Cookie} interface for the JSR-168 Portlet environment.
22  *
23  * Portlet preferences are available in the Cocoon as Cookie objects.
24  *
25  * @author <a HREF="mailto:alex.rudnev@dc.gov">Alex Rudnev</a>
26  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
27  * @version CVS $Id: PortletCookie.java 30932 2004-07-29 17:35:38Z vgritsenko $
28  */

29 public final class PortletCookie implements Cookie {
30
31     private String JavaDoc name;
32     private String JavaDoc value;
33
34     public PortletCookie(String JavaDoc name, String JavaDoc value) {
35         init(name, value);
36     }
37
38     /**
39      * Constructs a cookie with a specified name and value.
40      *
41      * @param name a <code>String</code> specifying the name of the cookie
42      * @param value a <code>String</code> specifying the value of the cookie
43      * @see #setValue(String)
44      */

45     public void init(String JavaDoc name, String JavaDoc value) {
46         if (this.name == null) {
47             this.name = name;
48             this.value = value;
49         } else {
50             throw new IllegalStateException JavaDoc("Cookie is already initialised");
51         }
52     }
53
54     private void checkState() {
55         if (this.name == null) {
56             throw new IllegalStateException JavaDoc("Cookie is not initialised");
57         }
58     }
59
60     /**
61      * This method does nothing
62      */

63     public void setComment(String JavaDoc purpose) {
64     }
65
66     /**
67      * @return null
68      * @see #setComment(String)
69      */

70     public String JavaDoc getComment() {
71         checkState();
72         return null;
73     }
74
75     /**
76      * This method does nothing
77      */

78     public void setDomain(String JavaDoc pattern) {
79         checkState();
80     }
81
82     /**
83      * @return null
84      * @see #setDomain(String)
85      */

86     public String JavaDoc getDomain() {
87         checkState();
88         return null;
89     }
90
91     /**
92      * This method does nothing
93      */

94     public void setMaxAge(int expiry) {
95         checkState();
96     }
97
98     /**
99      * @return Integer.MAX_VALUE
100      * @see #setMaxAge(int)
101      */

102     public int getMaxAge() {
103         checkState();
104         return Integer.MAX_VALUE;
105     }
106
107     /**
108      * This method does nothing
109      */

110     public void setPath(String JavaDoc uri) {
111         checkState();
112     }
113
114     /**
115      * @return empty string
116      * @see #setPath(String)
117      */

118     public String JavaDoc getPath() {
119         checkState();
120         return "";
121     }
122
123     /**
124      * This method does nothing
125      * @see #getSecure()
126      */

127     public void setSecure(boolean flag) {
128         checkState();
129     }
130
131     /**
132      * @return false
133      * @see #setSecure(boolean)
134      */

135     public boolean getSecure() {
136         checkState();
137         return false;
138     }
139
140     /**
141      * Returns the name of the cookie. The name cannot be changed after
142      * creation.
143      *
144      * @return a <code>String</code> specifying the cookie's name
145      */

146     public String JavaDoc getName() {
147         checkState();
148         return this.name;
149     }
150
151     /**
152      * Assigns a new value to a cookie after the cookie is created.
153      * If you use a binary value, you may want to use BASE64 encoding.
154      *
155      * <p>With Version 0 cookies, values should not contain white
156      * space, brackets, parentheses, equals signs, commas,
157      * double quotes, slashes, question marks, at signs, colons,
158      * and semicolons. Empty values may not behave the same way
159      * on all browsers.
160      *
161      * @param newValue a <code>String</code> specifying the new value
162      * @see #getValue()
163      * @see Cookie
164      */

165     public void setValue(String JavaDoc newValue) {
166         checkState();
167         this.value = newValue;
168     }
169
170     /**
171      * Returns the value of the cookie.
172      *
173      * @return a <code>String</code> containing the cookie's
174      * present value
175      * @see #setValue(String)
176      * @see Cookie
177      */

178     public String JavaDoc getValue() {
179         checkState();
180         return this.value;
181     }
182
183     /**
184      * Returns the version of the protocol this cookie complies
185      * with.
186      *
187      * @return Always 0
188      * @see #setVersion(int)
189      */

190     public int getVersion() {
191         checkState();
192         return 0;
193     }
194
195     /**
196      * Sets the version of the cookie protocol this cookie complies
197      * with. This method does nothing, version 0 is always returned in
198      * getVersion
199      *
200      * @see #getVersion()
201      */

202     public void setVersion(int v) {
203         checkState();
204     }
205 }
206
Popular Tags