Package net.i2p.router.web
Class FormHandler
java.lang.Object
net.i2p.router.web.FormHandler
- Direct Known Subclasses:
ConfigAdvancedHandler,ConfigClientsHandler,ConfigFamilyHandler,ConfigHomeHandler,ConfigKeyringHandler,ConfigLoggingHandler,ConfigNetHandler,ConfigPeerHandler,ConfigReseedHandler,ConfigServiceHandler,ConfigStatsHandler,ConfigSummaryHandler,ConfigTunnelsHandler,ConfigUIHandler,ConfigUpdateHandler,EventLogHelper,GraphHelper,NetDbHelper,WizardHandler
public abstract class FormHandler extends Object
Simple form handler base class - does not depend on servlets or jsp,
but instead the subclasses are populated with javabean properties. e.g.
<jsp:setProperty name="handler" property="*" />
The form is "processed" after the properties are set and the first output
property is retrieved - either getAll(), getNotices() or getErrors().
This Handler will only process a single POST. The jsp bean must be declared scope=request.
-
Field Summary
Fields Modifier and Type Field Description protected String_actionprotected RouterContext_contextprotected Log_logprotected String_methodprotected Writer_outprotected RequestWrapper_requestWrapperOnly for multipart/form-data.protected Map_settingsNot for multipart/form-data, will be null -
Constructor Summary
Constructors Constructor Description FormHandler() -
Method Summary
Modifier and Type Method Description String_t(String s)translate a stringString_t(String s, Object o)translate a string with a parameter This is a lot more expensive than _t(s), so use sparingly.String_t(String s, Object o, Object o2)two params @since 0.8.2static String_x(String s)Mark a string for extraction by xgettext and translation.protected voidaddFormError(String errorMsg)Add an error message to display Use if it does not include a link.protected voidaddFormErrorNoEscape(String msg)Add an error message to display Use if it includes a link or other formatting.protected voidaddFormNotice(String msg)Add a non-error message to display Use if it does not include a link.protected voidaddFormNoticeNoEscape(String msg)Add a non-error message to display Use if it includes a link or other formatting.StringgetAllMessages()Display everything, wrap it in a div for consistent presentationStringgetErrors()Display any error messages (processing the form if it hasn't been yet)protected StringgetJettyString(String key)setSettings() must have been called previously Curses Jetty for returning arrays.StringgetNewNonce()Generate a new nonce.StringgetNotices()Display any non-error messages (processing the form if it hasn't been yet)booleanisAdvanced()Same as HelperBaseprotected abstract voidprocessForm()Implement this to perform the final processing (in turn, adding formNotice and formError messages, etc) Will only be called if _action is non-null and the nonce is valid.voidsetAction(String val)voidsetContextId(String contextId)Configure this bean to query a particular router contextvoidsetNonce(String val)voidsetRequestWrapper(RequestWrapper rw)Only set by formhandler.jsi for multipart/form-datavoidsetSettings(Map settings)For many forms, it's easiest just to put all the parameters here.voidstoreMethod(String val)Call this to prevent changes using GETvoidstoreNonces(String n1, String n2)The old nonces from the sessionvoidstoreWriter(Writer out)
-
Field Details
-
Constructor Details
-
FormHandler
public FormHandler()
-
-
Method Details
-
setContextId
Configure this bean to query a particular router context- Parameters:
contextId- beginning few characters of the routerHash, or null to pick the first one we come across.
-
setNonce
-
setAction
-
setSettings
For many forms, it's easiest just to put all the parameters here.- Since:
- 0.9.4 consolidated from numerous FormHandlers
-
setRequestWrapper
Only set by formhandler.jsi for multipart/form-data- Since:
- 0.9.19
-
isAdvanced
public boolean isAdvanced()Same as HelperBase- Since:
- 0.9.14.1
-
getJettyString
setSettings() must have been called previously Curses Jetty for returning arrays.- Returns:
- trimmed string or null
- Since:
- 0.9.4 consolidated from numerous FormHandlers
-
storeMethod
Call this to prevent changes using GET- Parameters:
val- the request method- Since:
- 0.8.2
-
storeWriter
- Since:
- 0.9.38
-
storeNonces
The old nonces from the session- Since:
- 0.9.4
-
processForm
protected abstract void processForm()Implement this to perform the final processing (in turn, adding formNotice and formError messages, etc) Will only be called if _action is non-null and the nonce is valid. -
addFormError
Add an error message to display Use if it does not include a link. Escapes '<' and '>' before queueing -
addFormNotice
Add a non-error message to display Use if it does not include a link. Escapes '<' and '>' before queueing -
addFormNoticeNoEscape
Add a non-error message to display Use if it includes a link or other formatting. Does not escape '<' and '>' before queueing- Since:
- 0.9.14.1
-
addFormErrorNoEscape
Add an error message to display Use if it includes a link or other formatting. Does not escape '<' and '>' before queueing- Since:
- 0.9.19
-
getAllMessages
Display everything, wrap it in a div for consistent presentation -
getErrors
Display any error messages (processing the form if it hasn't been yet) -
getNotices
Display any non-error messages (processing the form if it hasn't been yet) -
getNewNonce
Generate a new nonce. Only call once per page!- Returns:
- a new random long as a String
- Since:
- 0.8.5
-
_t
translate a string -
_t
translate a string with a parameter This is a lot more expensive than _t(s), so use sparingly.- Parameters:
s- string to be translated containing {0} The {0} will be replaced by the parameter. Single quotes must be doubled, i.e. ' -> '' in the string.o- parameter, not translated. To translate parameter also, use _t("foo {0} bar", _t("baz")) Do not double the single quotes in the parameter. Use autoboxing to call with ints, longs, floats, etc.
-
_t
two params @since 0.8.2 -
_x
Mark a string for extraction by xgettext and translation. Use this only in static initializers. It does not translate!- Returns:
- s
-