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, ConfigSidebarHandler, ConfigStatsHandler, 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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `FormHandler.Message` Message class to encapsulate the message text and the canClose flag

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected String` | `_action`
    `protected RouterContext` | `_context`
    `protected Log` | `_log`
    `protected String` | `_method`
    `protected Writer` | `_out`
    `protected RequestWrapper` | `_requestWrapper` Only for multipart/form-data.
    `protected Map` | `_settings` Not for multipart/form-data, will be null

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FormHandler()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `_t(String s)` translate a string
    `String` | `_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.2
    `static String` | `_x(String s)` Mark a string for extraction by xgettext and translation.
    `protected void` | `addFormError(String errorMsg)` Add an error message to display Use if it does not include a link.
    `protected void` | `addFormError(String errorMsg, boolean canClose)` Add an error message to display Use if it does not include a link.
    `protected void` | `addFormErrorNoEscape(String msg)` Add an error message to display Use if it includes a link or other formatting.
    `protected void` | `addFormErrorNoEscape(String msg, boolean canClose)` Add an error message to display Use if it includes a link or other formatting.
    `protected void` | `addFormNotice(String msg)` Add a non-error message to display Use if it does not include a link.
    `protected void` | `addFormNotice(String msg, boolean canClose)` Add a non-error message to display Use if it does not include a link.
    `protected void` | `addFormNoticeNoEscape(String msg)` Add a non-error message to display Use if it includes a link or other formatting.
    `protected void` | `addFormNoticeNoEscape(String msg, boolean canClose)` Add a non-error message to display Use if it includes a link or other formatting.
    `String` | `getAllMessages()` Display everything, wrap it in a div for consistent presentation
    `String` | `getErrors()` Display any error messages (processing the form if it hasn't been yet)
    `protected String` | `getJettyString(String key)` setSettings() must have been called previously Curses Jetty for returning arrays.
    `String` | `getNewNonce()` Generate a new nonce.
    `String` | `getNotices()` Display any non-error messages (processing the form if it hasn't been yet)
    `boolean` | `isAdvanced()` Same as HelperBase
    `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.
    `void` | `setAction(String val)`
    `void` | `setContextId(String contextId)` Configure this bean to query a particular router context
    `void` | `setNonce(String val)`
    `void` | `setRequestWrapper(RequestWrapper rw)` Only set by formhandler.jsi for multipart/form-data
    `void` | `setSettings(Map settings)` For many forms, it's easiest just to put all the parameters here.
    `void` | `storeMethod(String val)` Call this to prevent changes using GET
    `void` | `storeNonces(String n1, String n2)` The old nonces from the session
    `void` | `storeWriter(Writer out)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### _action

          protected String _action

    - #### _context

          protected RouterContext _context

    - #### _log

          protected Log _log

    - #### _method

          protected String _method

    - #### _out

          protected Writer _out

    - #### _requestWrapper

          protected RequestWrapper _requestWrapper

      Only for multipart/form-data. Warning, parameters are NOT XSS filtered

    - #### _settings

          protected Map _settings

      Not for multipart/form-data, will be null

  - ### Constructor Detail

    - #### FormHandler

          public FormHandler()

  - ### Method Detail

    - #### _t

          public String _t(String s)

      translate a string

    - #### _t

          public String _t(String s,
                           Object o)

      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

          public String _t(String s,
                           Object o,
                           Object o2)

      two params @since 0.8.2

    - #### _x

          public static String _x(String s)

      Mark a string for extraction by xgettext and translation. Use this only in static initializers. It does not translate!
      Returns:
        s

    - #### addFormError

          protected void addFormError(String errorMsg)

      Add an error message to display Use if it does not include a link. Escapes '<' and '>' before queueing

    - #### addFormError

          protected void addFormError(String errorMsg,
                                      boolean canClose)

      Add an error message to display Use if it does not include a link. Escapes '<' and '>' before queueing
      Parameters:
        `canClose` - If true, the message can be closed by the user.

    - #### addFormErrorNoEscape

          protected void addFormErrorNoEscape(String msg)

      Add an error message to display Use if it includes a link or other formatting. Does not escape '<' and '>' before queueing

    - #### addFormErrorNoEscape

          protected void addFormErrorNoEscape(String msg,
                                              boolean canClose)

      Add an error message to display Use if it includes a link or other formatting. Does not escape '<' and '>' before queueing
      Parameters:
        `canClose` - If true, the message can be closed by the user.

    - #### addFormNotice

          protected void addFormNotice(String msg)

      Add a non-error message to display Use if it does not include a link. Escapes '<' and '>' before queueing

    - #### addFormNotice

          protected void addFormNotice(String msg,
                                       boolean canClose)

      Add a non-error message to display Use if it does not include a link. Escapes '<' and '>' before queueing
      Parameters:
        `canClose` - If true, the message can be closed by the user.

    - #### addFormNoticeNoEscape

          protected void addFormNoticeNoEscape(String msg)

      Add a non-error message to display Use if it includes a link or other formatting. Does not escape '<' and '>' before queueing

    - #### addFormNoticeNoEscape

          protected void addFormNoticeNoEscape(String msg,
                                               boolean canClose)

      Add a non-error message to display Use if it includes a link or other formatting. Does not escape '<' and '>' before queueing
      Parameters:
        `canClose` - If true, the message can be closed by the user.

    - #### getAllMessages

          public String getAllMessages()

      Display everything, wrap it in a div for consistent presentation

    - #### getErrors

          public String getErrors()

      Display any error messages (processing the form if it hasn't been yet)

    - #### getJettyString

          protected String getJettyString(String key)

      setSettings() must have been called previously Curses Jetty for returning arrays.
      Returns:
        trimmed string or null

    - #### getNewNonce

          public String getNewNonce()

      Generate a new nonce. Only call once per page!
      Returns:
        a new random long as a String

    - #### getNotices

          public String getNotices()

      Display any non-error messages (processing the form if it hasn't been yet)

    - #### isAdvanced

          public boolean isAdvanced()

      Same as HelperBase

    - #### 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.

    - #### setAction

          public void setAction(String val)

    - #### setContextId

          public void setContextId(String contextId)

      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

          public void setNonce(String val)

    - #### setRequestWrapper

          public void setRequestWrapper(RequestWrapper rw)

      Only set by formhandler.jsi for multipart/form-data

    - #### setSettings

          public void setSettings(Map settings)

      For many forms, it's easiest just to put all the parameters here.

    - #### storeMethod

          public void storeMethod(String val)

      Call this to prevent changes using GET
      Parameters:
        `val` - the request method

    - #### storeNonces

          public void storeNonces(String n1,
                                  String n2)

      The old nonces from the session

    - #### storeWriter

          public void storeWriter(Writer out)