@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 you won't be able to manipulate the options.
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)
This method should return a plugin to its default options.
|
void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
This method responds with the plugin 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, containing only
key-value pairs with value being a string and not an object.
|
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()
Implement this method to return an HTML form containing the options which should be modified using the administration page.
|
abstract java.lang.String |
getOptionsJson()
Returns the options available of the client-side in JSON format.
|
abstract java.lang.String |
getPath()
Should be implemented to return the relative path handled by this plugin.
|
void |
init()
Derived classes should make sure to call this method.
|
boolean |
requiresAuthorization()
PluginConfigExtensions will only serve content if the user is authenticated.
|
protected void |
saveOptions()
Saves the set options to disk.
|
java.lang.String |
serializeMapToJSON(java.util.Map<java.lang.String,java.lang.Object> map)
Serializes a map to a JSON string.
|
void |
setDefaultOptions(java.util.Map<java.lang.String,java.lang.String> defaultOptions)
Sets the default options for this plugin configuration extension.
|
protected void |
setOption(java.lang.String key,
java.lang.String value)
Sets the value of an option referenced by its key.
|
doPost, getServletConfig, init, service
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 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
This method should return a plugin to its default options.
It sets the options back to their defaults and saves them on disk.
In derived classes return your plugin to the default options and call the super method to set the options to the default values and save them on disk.
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)
If you want the default values for your options to be empty/null make sure to set them as empty/null, don't leave them out of the defaultOptions map.
defaultOptions
- the defaultOptions to setpublic abstract java.lang.String getOptionsForm()
public abstract java.lang.String getOptionsJson()
public final boolean requiresAuthorization()
requiresAuthorization
in class WebappServletPluginExtension
public java.lang.String serializeMapToJSON(java.util.Map<java.lang.String,java.lang.Object> map)
map
- the map to serialize to JSON string.© Copyright SyncRO Soft SRL 2002 - 2016. All rights reserved.