K
- key typeT
- Target typepublic class TransitionServlet<K,T> extends WebappServlet
TransitionFactory
and Target are encoded in the servlet path to give them a unique URL.
Optionally other parameters like the transition-key may also be encoded there.
This allows jsp pages invoked by forward to have the same URL as their target
so they can omit the action attribute. This is particularly useful
when using a PathTransitionProvider
Transitions do their own access control so this only extends SessionServlet
Modifier and Type | Class and Description |
---|---|
static class |
TransitionServlet.GetIDVisitor<T,K> |
static class |
TransitionServlet.GetTargetVisitor<T,K> |
Modifier and Type | Field and Description |
---|---|
static Feature |
MODIFY_ON_POST_ONLY
This is a security control.
|
static java.lang.String |
TARGET_ATTRIBUTE |
static Preference |
TRANSITION_ANCHOR |
static java.lang.String |
TRANSITION_CSRF_ATTR |
static java.lang.String |
TRANSITION_KEY_ATTR |
static java.lang.String |
TRANSITION_PROVIDER_ATTR |
static java.lang.String |
TRANSITION_SERVLET |
static Feature |
TRANSITION_TRANSACTIONS |
static java.lang.String |
VIEW_TRANSITION |
ARGS, CONFIRM_NO, CONFIRM_POST_URL, CONFIRM_TYPE, CONFIRM_YES, EXTRA_HTML, MESSAGE_EXTRA_ATTR, MESSAGE_TYPE_ATTR, MESSAGES_JSP_URL, SCRIPTS_CONFIRM_JSP
Constructor and Description |
---|
TransitionServlet() |
Modifier and Type | Method and Description |
---|---|
static <A,B,X extends ExtendedXMLBuilder> |
addButton(AppContext c,
X hb,
ChainedTransitionResult<B,A> next,
java.lang.String text) |
static <A,B,X extends ExtendedXMLBuilder> |
addButton(AppContext c,
X hb,
ChainedTransitionResult<B,A> next,
java.lang.String text,
java.lang.String title) |
static <A,B,X extends ExtendedXMLBuilder> |
addButton(AppContext c,
X hb,
TransitionFactory<A,B> tp,
A operation,
B target,
java.lang.String text)
Add a button to perform the required operation on the target
|
static <A,B,X extends ExtendedXMLBuilder> |
addButton(AppContext c,
X hb,
TransitionFactory<A,B> tp,
A operation,
B target,
java.lang.String text,
java.lang.String title) |
static <A,B,X extends ExtendedXMLBuilder> |
addButton(AppContext c,
X hb,
TransitionFactory<A,B> tp,
A operation,
B target,
java.lang.String text,
java.lang.String title,
boolean new_tab) |
static ExtendedXMLBuilder |
addLink(AppContext c,
ExtendedXMLBuilder hb,
ChainedTransitionResult next,
java.lang.String text) |
static ExtendedXMLBuilder |
addLink(AppContext c,
ExtendedXMLBuilder hb,
ChainedTransitionResult next,
java.lang.String text,
java.lang.String hover) |
static <A,B,X extends ExtendedXMLBuilder> |
addLink(AppContext c,
X hb,
TransitionFactory<A,B> tp,
A operation,
B target,
java.lang.String text,
java.lang.String hover,
boolean new_tab)
Add a link to perform the required operation on the target
|
boolean |
checkOrigin(AppContext conn,
HttpServletRequest req,
HttpServletResponse res)
check headers for csrf etc.
|
void |
doPost(HttpServletRequest req,
HttpServletResponse res,
AppContext conn)
Method that does the actual work
|
protected boolean |
enabled(AppContext conn)
Extension point to allow sub-classes to enable/disable the servlet
|
static <A,B> java.lang.String |
getActionURL(AppContext conn,
TransitionFactory<A,B> tp,
B target) |
static java.lang.String |
getCrsfToken(AppContext conn,
HttpServletRequest req) |
protected java.lang.String |
getCRSFToken(AppContext conn,
TransitionFactory<K,T> fac,
K key,
T target)
generate a CRSF token to be included in form posts.
|
static <T,K> java.lang.String |
getPageHeader(TransitionFactory<K,T> tp,
K key,
T target) |
static <T,K> java.lang.String |
getPageTitle(TransitionFactory<K,T> tp,
K key,
T target) |
static TransitionFactory |
getProvider(AppContext conn,
HttpServletRequest req)
Static method for jsp pages to retrieve the TransitionProvider
in a way compatible with the TransitionSerlvet
|
static TransitionFactory |
getProviderFromName(AppContext conn,
java.lang.String type)
method to retrieve the TransitionProvider from a string tag
If the tag contains a colon this is taken as a separator between two fields.
|
protected SessionService |
getSessionService(AppContext conn,
TransitionFactory<K,T> tp,
java.util.Map<java.lang.String,java.lang.Object> raw_params)
Extension point to get the session including any custom login code based on the parameters and the
TransitionFactory
This allows sub-classes to that parse the parameters for login credentials or look for annotations on the TransitionFactory . |
protected TransitionVisitor<T> |
getShortcutVisitor(AppContext conn,
java.util.Map<java.lang.String,java.lang.Object> params,
TransitionFactory<K,T> tp,
T target,
K key) |
static <A,B> B |
getTarget(AppContext conn,
TransitionFactory<A,B> provider,
HttpServletRequest req)
Static method for jsp pages to use to retieve the target in a way compatible with the
TransitionServlet
|
protected T |
getTarget(AppContext conn,
TransitionFactory<K,T> provider,
java.util.LinkedList<java.lang.String> path)
Extracts the Target form the URL and sets it as an attribute for any scripts we forward to.
|
static <A,B> java.lang.String |
getURL(AppContext conn,
TransitionFactory<A,B> tp,
B target)
Get the TransitionServlet URL for a given TransitionProvider and target.
|
static <A,B> java.lang.String |
getURL(AppContext conn,
TransitionFactory<A,B> tp,
B target,
A operation) |
static <A,B> java.lang.String |
getURL(HttpServletRequest req,
HttpServletResponse res,
AppContext conn,
TransitionFactory<A,B> tp,
B target) |
static <A,B> java.lang.String |
getURL(HttpServletRequest req,
HttpServletResponse res,
AppContext conn,
TransitionFactory<A,B> tp,
B target,
A operation) |
static <T,K> boolean |
hasViewRecorded(SessionService<?> sess,
ViewTransitionFactory<K,T> tp) |
protected FormResult |
processTransition(AppContext conn,
HttpServletRequest req,
java.util.Map<java.lang.String,java.lang.Object> params,
TransitionFactory<K,T> tp,
K key,
T target,
Transition<T> t) |
static <T,K> void |
recordView(SessionService<?> sess,
ViewTransitionFactory<K,T> tp,
T target)
Register the most recent view transition for this provider for use by the
BackResult
passing a null target clears the memory. |
protected void |
sessionError(AppContext conn,
SessionService sess,
HttpServletRequest req,
HttpServletResponse res)
Extension point for missing authorisation
|
protected void |
setTarget(HttpServletRequest req,
T q) |
badInputCheck, checkBadInput, confirm, confirm, doGet, doPost, doPut, doPut, encodeCGI, getLogger, handleFormResult, message, message, messageWithArgs, sendMessageWithArgs
public static final java.lang.String VIEW_TRANSITION
public static final Feature TRANSITION_TRANSACTIONS
public static final Preference TRANSITION_ANCHOR
public static final Feature MODIFY_ON_POST_ONLY
ViewTransitionKey
and reports the transition as safe.public static final java.lang.String TRANSITION_SERVLET
public static final java.lang.String TRANSITION_PROVIDER_ATTR
public static final java.lang.String TRANSITION_KEY_ATTR
public static final java.lang.String TRANSITION_CSRF_ATTR
public static final java.lang.String TARGET_ATTRIBUTE
public void doPost(HttpServletRequest req, HttpServletResponse res, AppContext conn)
WebappServlet
doPost
in class WebappServlet
protected TransitionVisitor<T> getShortcutVisitor(AppContext conn, java.util.Map<java.lang.String,java.lang.Object> params, TransitionFactory<K,T> tp, T target, K key)
protected void sessionError(AppContext conn, SessionService sess, HttpServletRequest req, HttpServletResponse res) throws java.io.IOException, ServletException
conn
- sess
- req
- res
- java.io.IOException
ServletException
protected FormResult processTransition(AppContext conn, HttpServletRequest req, java.util.Map<java.lang.String,java.lang.Object> params, TransitionFactory<K,T> tp, K key, T target, Transition<T> t) throws java.lang.Exception
java.lang.Exception
protected SessionService getSessionService(AppContext conn, TransitionFactory<K,T> tp, java.util.Map<java.lang.String,java.lang.Object> raw_params)
TransitionFactory
This allows sub-classes to that parse the parameters for login credentials or look for annotations on the TransitionFactory
.conn
- tp
- raw_params
- public static TransitionFactory getProviderFromName(AppContext conn, java.lang.String type)
TransitionFactoryCreator
using AppContext.makeObject(Class, String)
and the second field is used as the parameter to TransitionFactoryCreator.getTransitionProvider(String)
.
otherwise calls to AppContext.makeObject(Class, String)
are attempted with the following tag/type parameters
TransitionFactory
.
TransitionFactory
TransitionFactoryCreator
conn
- type
- TargetName of the TransitionProviderTransitionFactory
public static TransitionFactory getProvider(AppContext conn, HttpServletRequest req) throws java.lang.Exception
conn
- req
- java.lang.Exception
protected T getTarget(AppContext conn, TransitionFactory<K,T> provider, java.util.LinkedList<java.lang.String> path)
conn
- provider
- path
- req
- public static <A,B> B getTarget(AppContext conn, TransitionFactory<A,B> provider, HttpServletRequest req)
A
- B
- conn
- provider
- req
- protected void setTarget(HttpServletRequest req, T q)
public static java.lang.String getCrsfToken(AppContext conn, HttpServletRequest req)
public static <A,B,X extends ExtendedXMLBuilder> X addButton(AppContext c, X hb, TransitionFactory<A,B> tp, A operation, B target, java.lang.String text)
A
- B
- c
- hb
- HtmlBulder to modifytp
- TransitionProvideroperation
- target
- text
- public static <A,B,X extends ExtendedXMLBuilder> X addButton(AppContext c, X hb, TransitionFactory<A,B> tp, A operation, B target, java.lang.String text, java.lang.String title)
public static <A,B,X extends ExtendedXMLBuilder> X addButton(AppContext c, X hb, TransitionFactory<A,B> tp, A operation, B target, java.lang.String text, java.lang.String title, boolean new_tab)
public static <A,B,X extends ExtendedXMLBuilder> X addButton(AppContext c, X hb, ChainedTransitionResult<B,A> next, java.lang.String text)
public static <A,B,X extends ExtendedXMLBuilder> X addButton(AppContext c, X hb, ChainedTransitionResult<B,A> next, java.lang.String text, java.lang.String title)
public static <A,B,X extends ExtendedXMLBuilder> X addLink(AppContext c, X hb, TransitionFactory<A,B> tp, A operation, B target, java.lang.String text, java.lang.String hover, boolean new_tab)
A
- B
- c
- hb
- HtmlBulder to modifytp
- TransitionProvideroperation
- target
- text
- public static ExtendedXMLBuilder addLink(AppContext c, ExtendedXMLBuilder hb, ChainedTransitionResult next, java.lang.String text)
public static ExtendedXMLBuilder addLink(AppContext c, ExtendedXMLBuilder hb, ChainedTransitionResult next, java.lang.String text, java.lang.String hover)
public static <A,B> java.lang.String getURL(AppContext conn, TransitionFactory<A,B> tp, B target)
A
- B
- conn
- tp
- target
- public static <A,B> java.lang.String getActionURL(AppContext conn, TransitionFactory<A,B> tp, B target)
public static <A,B> java.lang.String getURL(HttpServletRequest req, HttpServletResponse res, AppContext conn, TransitionFactory<A,B> tp, B target)
public static <A,B> java.lang.String getURL(HttpServletRequest req, HttpServletResponse res, AppContext conn, TransitionFactory<A,B> tp, B target, A operation)
public static <A,B> java.lang.String getURL(AppContext conn, TransitionFactory<A,B> tp, B target, A operation)
public static <T,K> void recordView(SessionService<?> sess, ViewTransitionFactory<K,T> tp, T target)
BackResult
passing a null target clears the memory.T
- K
- sess
- tp
- target
- public static <T,K> boolean hasViewRecorded(SessionService<?> sess, ViewTransitionFactory<K,T> tp)
public static <T,K> java.lang.String getPageTitle(TransitionFactory<K,T> tp, K key, T target)
public static <T,K> java.lang.String getPageHeader(TransitionFactory<K,T> tp, K key, T target)
protected java.lang.String getCRSFToken(AppContext conn, TransitionFactory<K,T> fac, K key, T target)
fac
- key
- target
- public boolean checkOrigin(AppContext conn, HttpServletRequest req, HttpServletResponse res)
req
- res
- protected boolean enabled(AppContext conn)