@API(type=EXTENDABLE, src=PUBLIC) public abstract class PluginConfigExtension extends WebappServletPluginExtension
This class should be extended when creating a web-app plugin with a configuration page.
Make sure to call super.init() in the extended class otherwise options will not be saved to disk and will be lost upon application restart.
This class exposes the following HTTP api to the web-app admin page.
GET with Accept: text/html
responds with the html/css/js of the configuration page.
GET with Accept: application/json
responds with the current options of
a plugin as a JSON object.
PUT with a JSON object of key-value pairs representing the options to set as request body. Will set the options for a plugin and save them to disk.
DELETE will reset a plugins options to their default values.
config
Constructor and Description |
---|
PluginConfigExtension()
In the derived class make sure to set the default options.
|
Modifier and Type | Method and Description |
---|---|
void |
doDelete(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
In derived classes return the plugin to the default options and make sure to call saveOptions
to save the options to the options file as well.
|
void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
If the request Accept header is text/html this method should respond with the configuration page (html/css/js).
|
void |
doPut(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
The request body of this request should contain a JSON object of the options to set.
|
java.util.Map<java.lang.String,java.lang.String> |
getDefaultOptions() |
protected java.lang.String |
getOption(java.lang.String key,
java.lang.String defaultValue)
Returns the option for the given key or the default value if the key doesn't exist.
|
abstract java.lang.String |
getOptionsForm() |
abstract java.lang.String |
getOptionsJson() |
abstract java.lang.String |
getPath()
Should be implemented to return the relative path handled by this plugin.
|
void |
init()
Derived classes should make sure they call super.init() if they want to override.
|
void |
init(javax.servlet.ServletConfig config)
Init function that stores the config.
|
boolean |
requiresAuthorization()
PluginConfigExtensions will only serve content if the user is authenticated.
|
protected void |
saveOptions()
Saves the set options to disk.
|
void |
setDefaultOptions(java.util.Map<java.lang.String,java.lang.String> defaultOptions) |
protected void |
setOption(java.lang.String key,
java.lang.String value)
Sets the value of an option referenced by its key.
|
doPost, getServletConfig
public PluginConfigExtension()
public abstract java.lang.String getPath()
getPath
in class WebappServletPluginExtension
public void init() throws javax.servlet.ServletException
init
in class WebappServletPluginExtension
javax.servlet.ServletException
- Thrown to respect the interfacepublic void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
WebappServletPluginExtension
WebappServletPluginExtension.init()
method instead. If you decide to override this one,
call the super implementation.init
in class WebappServletPluginExtension
config
- The configuration.javax.servlet.ServletException
public void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
doGet
in class WebappServletPluginExtension
req
- The HTTP requestresp
- The HTTP responsejavax.servlet.ServletException
- To respect the interfacejava.io.IOException
- Thrown by getWriterpublic void doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
doPut
in class WebappServletPluginExtension
req
- The HTTP request objectresp
- The HTTP response objectjavax.servlet.ServletException
- To respect the interfacejava.io.IOException
- If the options file is not found or storing the options encounters an errorpublic void doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
doDelete
in class WebappServletPluginExtension
req
- The HTTP request objectresp
- The HTTP response objectjavax.servlet.ServletException
- To respect the interfacejava.io.IOException
- When the options file is not found or storing options encounters an errorprotected java.lang.String getOption(java.lang.String key, java.lang.String defaultValue)
key
- The key for the option to returndefaultValue
- The value to return if the key doesn't existprotected void setOption(java.lang.String key, java.lang.String value)
key
- The key of the option to setvalue
- The value of the option to setprotected void saveOptions() throws java.io.IOException
java.io.IOException
- Couldn't save options.public java.util.Map<java.lang.String,java.lang.String> getDefaultOptions()
public void setDefaultOptions(java.util.Map<java.lang.String,java.lang.String> defaultOptions)
defaultOptions
- the defaultOptions to setpublic abstract java.lang.String getOptionsForm()
public abstract java.lang.String getOptionsJson()
public final boolean requiresAuthorization()
requiresAuthorization
in class WebappServletPluginExtension
© Copyright SyncRO Soft SRL 2002 - 2015. All rights reserved.