java.lang.Object
com.aoapps.servlet.http.Canonical
- All Implemented Interfaces:
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
Modifier and TypeMethodDescriptionstatic 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 Details
-
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
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
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
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
Sets the state of the canonicalThreadLocaland invokesHttpServletResponse.encodeURL(java.lang.String). -
encodeCanonicalRedirectURL
Sets the state of the canonicalThreadLocaland invokesHttpServletResponse.encodeRedirectURL(java.lang.String).
-
