- java.lang.Object
-
- com.aoapps.servlet.http.Canonical
-
- All Implemented Interfaces:
AutoCloseable
public abstract class Canonical extends Object implements AutoCloseable
Coordinates when canonical URLs should be generated during response URL rewriting (such as information added when cookies are disabled). These URLs without per-user settings are used in things like Canonical URLs, BreadcrumbList, and Sitemaps.This is implemented as a thread local, so the state must be set by the thread that will invoke
HttpServletResponse.encodeURL(java.lang.String)(and related methods). Thus, it would be inappropriate to set this in a broad, asynchronous scope where the thread handling the request may change.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Canonicalclear()Sets the current state of the canonicalThreadLocaltofalse.abstract voidclose()Restores the previous state of the canonicalThreadLocal.static StringencodeCanonicalRedirectURL(HttpServletResponse response, String url)Sets the state of the canonicalThreadLocaland invokesHttpServletResponse.encodeRedirectURL(java.lang.String).static StringencodeCanonicalURL(HttpServletResponse response, String url)Sets the state of the canonicalThreadLocaland invokesHttpServletResponse.encodeURL(java.lang.String).static booleanget()Gets the current state of the canonicalThreadLocal.static Canonicalset()Sets the current state of the canonicalThreadLocaltotrue.static Canonicalset(boolean value)Sets the current state of the canonicalThreadLocalto the given value.
-
-
-
Method Detail
-
close
public abstract void close()
Restores the previous state of the canonicalThreadLocal.- Specified by:
closein interfaceAutoCloseable
-
get
public static boolean get()
Gets the current state of the canonicalThreadLocal.
-
set
public static Canonical set(boolean value)
Sets the current state of the canonicalThreadLocalto the given value. This should be used in a try-with-resources block to ensure the previous value is restored.
-
set
public static Canonical set()
Sets the current state of the canonicalThreadLocaltotrue. This should be used in a try-with-resources block to ensure the previous value is restored.
-
clear
public static Canonical clear()
Sets the current state of the canonicalThreadLocaltofalse. This should be used in a try-with-resources block to ensure the previous value is restored.
-
encodeCanonicalURL
public static String encodeCanonicalURL(HttpServletResponse response, String url)
Sets the state of the canonicalThreadLocaland invokesHttpServletResponse.encodeURL(java.lang.String).
-
encodeCanonicalRedirectURL
public static String encodeCanonicalRedirectURL(HttpServletResponse response, String url)
Sets the state of the canonicalThreadLocaland invokesHttpServletResponse.encodeRedirectURL(java.lang.String).
-
-