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 Canonical
clear()
Sets the current state of the canonicalThreadLocal
tofalse
.abstract void
close()
Restores the previous state of the canonicalThreadLocal
.static String
encodeCanonicalRedirectURL
(HttpServletResponse response, String url) Sets the state of the canonicalThreadLocal
and invokesHttpServletResponse.encodeRedirectURL(java.lang.String)
.static String
encodeCanonicalURL
(HttpServletResponse response, String url) Sets the state of the canonicalThreadLocal
and invokesHttpServletResponse.encodeURL(java.lang.String)
.static boolean
get()
Gets the current state of the canonicalThreadLocal
.static Canonical
set()
Sets the current state of the canonicalThreadLocal
totrue
.static Canonical
set
(boolean value) Sets the current state of the canonicalThreadLocal
to the given value.
-
Method Details
-
close
public abstract void close()Restores the previous state of the canonicalThreadLocal
.- Specified by:
close
in interfaceAutoCloseable
-
get
public static boolean get()Gets the current state of the canonicalThreadLocal
. -
set
Sets the current state of the canonicalThreadLocal
to 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 canonicalThreadLocal
totrue
. This should be used in a try-with-resources block to ensure the previous value is restored. -
clear
Sets the current state of the canonicalThreadLocal
tofalse
. This should be used in a try-with-resources block to ensure the previous value is restored. -
encodeCanonicalURL
Sets the state of the canonicalThreadLocal
and invokesHttpServletResponse.encodeURL(java.lang.String)
. -
encodeCanonicalRedirectURL
Sets the state of the canonicalThreadLocal
and invokesHttpServletResponse.encodeRedirectURL(java.lang.String)
.
-