001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.environment.portlet;
018:
019: import org.apache.cocoon.environment.Cookie;
020:
021: /**
022: * Implements {@link Cookie} interface for the JSR-168 Portlet environment.
023: *
024: * Portlet preferences are available in the Cocoon as Cookie objects.
025: *
026: * @author <a href="mailto:alex.rudnev@dc.gov">Alex Rudnev</a>
027: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
028: * @version CVS $Id: PortletCookie.java 433543 2006-08-22 06:22:54Z crossley $
029: */
030: public final class PortletCookie implements Cookie {
031:
032: private String name;
033: private String value;
034:
035: public PortletCookie(String name, String value) {
036: init(name, value);
037: }
038:
039: /**
040: * Constructs a cookie with a specified name and value.
041: *
042: * @param name a <code>String</code> specifying the name of the cookie
043: * @param value a <code>String</code> specifying the value of the cookie
044: * @see #setValue(String)
045: */
046: public void init(String name, String value) {
047: if (this .name == null) {
048: this .name = name;
049: this .value = value;
050: } else {
051: throw new IllegalStateException(
052: "Cookie is already initialised");
053: }
054: }
055:
056: private void checkState() {
057: if (this .name == null) {
058: throw new IllegalStateException("Cookie is not initialised");
059: }
060: }
061:
062: /**
063: * This method does nothing
064: */
065: public void setComment(String purpose) {
066: }
067:
068: /**
069: * @return null
070: * @see #setComment(String)
071: */
072: public String getComment() {
073: checkState();
074: return null;
075: }
076:
077: /**
078: * This method does nothing
079: */
080: public void setDomain(String pattern) {
081: checkState();
082: }
083:
084: /**
085: * @return null
086: * @see #setDomain(String)
087: */
088: public String getDomain() {
089: checkState();
090: return null;
091: }
092:
093: /**
094: * This method does nothing
095: */
096: public void setMaxAge(int expiry) {
097: checkState();
098: }
099:
100: /**
101: * @return Integer.MAX_VALUE
102: * @see #setMaxAge(int)
103: */
104: public int getMaxAge() {
105: checkState();
106: return Integer.MAX_VALUE;
107: }
108:
109: /**
110: * This method does nothing
111: */
112: public void setPath(String uri) {
113: checkState();
114: }
115:
116: /**
117: * @return empty string
118: * @see #setPath(String)
119: */
120: public String getPath() {
121: checkState();
122: return "";
123: }
124:
125: /**
126: * This method does nothing
127: * @see #getSecure()
128: */
129: public void setSecure(boolean flag) {
130: checkState();
131: }
132:
133: /**
134: * @return false
135: * @see #setSecure(boolean)
136: */
137: public boolean getSecure() {
138: checkState();
139: return false;
140: }
141:
142: /**
143: * Returns the name of the cookie. The name cannot be changed after
144: * creation.
145: *
146: * @return a <code>String</code> specifying the cookie's name
147: */
148: public String getName() {
149: checkState();
150: return this .name;
151: }
152:
153: /**
154: * Assigns a new value to a cookie after the cookie is created.
155: * If you use a binary value, you may want to use BASE64 encoding.
156: *
157: * <p>With Version 0 cookies, values should not contain white
158: * space, brackets, parentheses, equals signs, commas,
159: * double quotes, slashes, question marks, at signs, colons,
160: * and semicolons. Empty values may not behave the same way
161: * on all browsers.
162: *
163: * @param newValue a <code>String</code> specifying the new value
164: * @see #getValue()
165: * @see Cookie
166: */
167: public void setValue(String newValue) {
168: checkState();
169: this .value = newValue;
170: }
171:
172: /**
173: * Returns the value of the cookie.
174: *
175: * @return a <code>String</code> containing the cookie's
176: * present value
177: * @see #setValue(String)
178: * @see Cookie
179: */
180: public String getValue() {
181: checkState();
182: return this .value;
183: }
184:
185: /**
186: * Returns the version of the protocol this cookie complies
187: * with.
188: *
189: * @return Always 0
190: * @see #setVersion(int)
191: */
192: public int getVersion() {
193: checkState();
194: return 0;
195: }
196:
197: /**
198: * Sets the version of the cookie protocol this cookie complies
199: * with. This method does nothing, version 0 is always returned in
200: * getVersion
201: *
202: * @see #getVersion()
203: */
204: public void setVersion(int v) {
205: checkState();
206: }
207: }
|