javax.ws.rs.core.CacheControl Maven / Gradle / Ivy
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* http://www.opensource.org/licenses/cddl1.php
* See the License for the specific language governing
* permissions and limitations under the License.
*/
/*
* CacheControl.java
*
* Created on March 5, 2007, 3:36 PM
*/
package javax.ws.rs.core;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* An abstraction for the value of a HTTP Cache-Control response header.
* @see HTTP/1.1 section 14.9
*/
public class CacheControl {
private boolean _public;
private boolean _private;
private List privateFields;
private boolean noCache;
private List noCacheFields;
private boolean noStore;
private boolean noTransform;
private boolean mustRevalidate;
private boolean proxyRevalidate;
private int maxAge = -1;
private int sMaxAge = -1;
private Map cacheExtension;
/**
* Create a new instance of CacheControl. The new instance will have the
* following default settings:
*
*
* - public = true
* - private = false
* - noCache = false
* - noStore = false
* - noTransform = true
* - mustRevalidate = false
* - proxyRevalidate = false
* - An empty list of private fields
* - An empty list of no-cache fields
* - An empty list of cache extensions
*
*/
public CacheControl() {
_public = true;
_private = false;
noCache = false;
noStore = false;
noTransform = true;
mustRevalidate = false;
proxyRevalidate = false;
}
/**
* Corresponds to the must-revalidate cache control directive.
* @return true if the must-revalidate cache control directive will be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.4
*/
public boolean isMustRevalidate() {
return mustRevalidate;
}
/**
* Corresponds to the must-revalidate cache control directive.
* @param mustRevalidate true if the must-revalidate cache control directive should be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.4
*/
public void setMustRevalidate(boolean mustRevalidate) {
this.mustRevalidate = mustRevalidate;
}
/**
* Corresponds to the proxy-revalidate cache control directive.
* @return true if the proxy-revalidate cache control directive will be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.4
*/
public boolean isProxyRevalidate() {
return proxyRevalidate;
}
/**
* Corresponds to the must-revalidate cache control directive.
* @param proxyRevalidate true if the proxy-revalidate cache control directive should be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.4
*/
public void setProxyRevalidate(boolean proxyRevalidate) {
this.proxyRevalidate = proxyRevalidate;
}
/**
* Corresponds to the max-age cache control directive.
* @return the value of the max-age cache control directive, -1 if the directive is disabled.
* @see HTTP/1.1 section 14.9.3
*/
public int getMaxAge() {
return maxAge;
}
/**
* Corresponds to the max-age cache control directive.
* @param maxAge the value of the max-age cache control directive, a value of -1 will disable the directive.
* @see HTTP/1.1 section 14.9.3
*/
public void setMaxAge(int maxAge) {
this.maxAge = maxAge;
}
/**
* Corresponds to the s-maxage cache control directive.
* @return the value of the s-maxage cache control directive, -1 if the directive is disabled.
* @see HTTP/1.1 section 14.9.3
*/
public int getSMaxAge() {
return sMaxAge;
}
/**
* Corresponds to the s-maxage cache control directive.
* @param sMaxAge the value of the s-maxage cache control directive, a value of -1 will disable the directive.
* @see HTTP/1.1 section 14.9.3
*/
public void setSMaxAge(int sMaxAge) {
this.sMaxAge = sMaxAge;
}
/**
* Corresponds to the value of the no-cache cache control directive.
* @return a mutable list of field-names that will form the value of the no-cache cache control directive.
* An empty list results in a bare no-cache directive.
* @see #isNoCache
* @see #setNoCache
* @see HTTP/1.1 section 14.9.1
*/
public List getNoCacheFields() {
if (noCacheFields == null)
noCacheFields = new ArrayList();
return noCacheFields;
}
/**
* Corresponds to the no-cache cache control directive.
* @param noCache true if the no-cache cache control directive should be included in the
* response, false otherwise.
* @see #getNoCacheFields
* @see HTTP/1.1 section 14.9.1
*/
public void setNoCache(boolean noCache) {
this.noCache = noCache;
}
/**
* Corresponds to the no-cache cache control directive.
* @return true if the no-cache cache control directive will be included in the
* response, false otherwise.
* @see #getNoCacheFields
* @see HTTP/1.1 section 14.9.1
*/
public boolean isNoCache() {
return noCache;
}
/**
* Corresponds to the public cache control directive.
* @return true if the public cache control directive will be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.1
*/
public boolean isPublic() {
return _public;
}
/**
* Corresponds to the public cache control directive.
* @param _public true if the public cache control directive should be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.1
*/
public void setPublic(boolean _public) {
this._public = _public;
}
/**
* Corresponds to the private cache control directive.
* @return true if the private cache control directive will be included in the
* response, false otherwise.
* @see #getPrivateFields
* @see HTTP/1.1 section 14.9.1
*/
public boolean isPrivate() {
return _private;
}
/**
* Corresponds to the value of the private cache control directive.
* @return a mutable list of field-names that will form the value of the private cache control directive.
* An empty list results in a bare no-cache directive.
* @see #isPrivate
* @see #setPrivate
* @see HTTP/1.1 section 14.9.1
*/
public List getPrivateFields() {
if (privateFields == null)
privateFields = new ArrayList();
return privateFields;
}
/**
* Corresponds to the private cache control directive.
* @param _private true if the private cache control directive should be included in the
* response, false otherwise.
* @see #getPrivateFields
* @see HTTP/1.1 section 14.9.1
*/
public void setPrivate(boolean _private) {
this._private = _private;
}
/**
* Corresponds to the no-transform cache control directive.
* @return true if the no-transform cache control directive will be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.5
*/
public boolean isNoTransform() {
return noTransform;
}
/**
* Corresponds to the no-transform cache control directive.
* @param noTransform true if the no-transform cache control directive should be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.5
*/
public void setNoTransform(boolean noTransform) {
this.noTransform = noTransform;
}
/**
* Corresponds to the no-store cache control directive.
* @return true if the no-store cache control directive will be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.2
*/
public boolean isNoStore() {
return noStore;
}
/**
* Corresponds to the no-store cache control directive.
* @param noStore true if the no-store cache control directive should be included in the
* response, false otherwise.
* @see HTTP/1.1 section 14.9.2
*/
public void setNoStore(boolean noStore) {
this.noStore = noStore;
}
/**
* Corresponds to a set of extension cache control directives.
* @return a mutable map of cache control extension names and their values.
* If a key has a null value, it will appear as a bare directive. If a key has
* a value that contains no whitespace then the directive will appear as
* a simple name=value pair. If a key has a value that contains whitespace
* then the directive will appear as a quoted name="value" pair.
* @see HTTP/1.1 section 14.9.6
*/
public Map getCacheExtension() {
if (cacheExtension == null)
cacheExtension = new HashMap();
return cacheExtension;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy