|
Spring Framework example source code file (CookieGenerator.java)
The Spring Framework CookieGenerator.java source code/* * Copyright 2002-2006 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.web.util; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Helper class for cookie generation, carrying cookie descriptor settings * as bean properties and being able to add and remove cookie to/from a * given response. * * <p>Can serve as base class for components that generate specific cookies, * like CookieLocaleResolcer and CookieThemeResolver. * * @author Juergen Hoeller * @since 1.1.4 * @see #addCookie * @see #removeCookie * @see org.springframework.web.servlet.i18n.CookieLocaleResolver * @see org.springframework.web.servlet.theme.CookieThemeResolver */ public class CookieGenerator { /** * Default path that cookies will be visible to: "/", i.e. the entire server. */ public static final String DEFAULT_COOKIE_PATH = "/"; /** * Default maximum age of cookies: maximum integer value, i.e. forever. */ public static final int DEFAULT_COOKIE_MAX_AGE = Integer.MAX_VALUE; protected final Log logger = LogFactory.getLog(getClass()); private String cookieName; private String cookieDomain; private String cookiePath = DEFAULT_COOKIE_PATH; private int cookieMaxAge = DEFAULT_COOKIE_MAX_AGE; private boolean cookieSecure = false; /** * Use the given name for cookies created by this generator. */ public void setCookieName(String cookieName) { this.cookieName = cookieName; } /** * Return the given name for cookies created by this generator. */ public String getCookieName() { return cookieName; } /** * Use the given domain for cookies created by this generator. * The cookie is only visible to servers in this domain. */ public void setCookieDomain(String cookieDomain) { this.cookieDomain = cookieDomain; } /** * Return the domain for cookies created by this generator, if any. */ public String getCookieDomain() { return cookieDomain; } /** * Use the given path for cookies created by this generator. * The cookie is only visible to URLs in this path and below. */ public void setCookiePath(String cookiePath) { this.cookiePath = cookiePath; } /** * Return the path for cookies created by this generator. */ public String getCookiePath() { return cookiePath; } /** * Use the given maximum age (in seconds) for cookies created by this generator. * Useful special value: -1 ... not persistent, deleted when client shuts down */ public void setCookieMaxAge(int cookieMaxAge) { this.cookieMaxAge = cookieMaxAge; } /** * Return the maximum age for cookies created by this generator. */ public int getCookieMaxAge() { return cookieMaxAge; } /** * Set whether the cookie should only be sent using a secure protocol, * such as HTTPS (SSL). This is an indication to the receiving browser, * not processed by the HTTP server itself. Default is "false". */ public void setCookieSecure(boolean cookieSecure) { this.cookieSecure = cookieSecure; } /** * Return whether the cookie should only be sent using a secure protocol, * such as HTTPS (SSL). */ public boolean isCookieSecure() { return cookieSecure; } /** * Add a cookie with the given value to the response, * using the cookie descriptor settings of this generator. * <p>Delegates to Other Spring Framework examples (source code examples)Here is a short list of links related to this Spring Framework CookieGenerator.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.