Class PluginConfigExtension
- java.lang.Object
-
- ro.sync.ecss.extensions.api.webapp.plugin.WebappServletPluginExtension
-
- ro.sync.ecss.extensions.api.webapp.plugin.PluginConfigExtension
-
- All Implemented Interfaces:
PluginExtension
@API(type=EXTENDABLE, src=PUBLIC) @Deprecated public abstract class PluginConfigExtension extends WebappServletPluginExtension
Deprecated.This API is deprecated because it's based on javax package that's no more supported starting with Servlet 5.0 specification and because this extension type isn't protected against CSRF attacks. UseServletPluginConfigExtension
instead.This class should be extended to create a configuration page for a Web Author plugin. For common use-cases, only the abstract methods should be implemented/overridden.
This class creates an HTML form that will be presented in the Administration Page to the user to configure some options. The options will be applied for all the users.
These options can be read from the server-side code like in the code snippet below:
PluginWorkspaceProvider.getPluginWorkspace().getOptionsStorage().getOption("option_name", "default_value");
The options can be read from client-side like in the code snippet below:
sync.options.PluginsOptions.getClientOption('option_name');
Make sure to call super.init() in the extended class otherwise you won't be able to manipulate the options.
- Since:
- 17.1
-
-
Field Summary
-
Fields inherited from class ro.sync.ecss.extensions.api.webapp.plugin.WebappServletPluginExtension
config
-
-
Constructor Summary
Constructors Constructor Description PluginConfigExtension()
Deprecated.In the derived class make sure to set the default options.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
Deprecated.This method should return a plugin to its default options.void
doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
Deprecated.This method responds with the plugin configuration page (html/css/js).void
doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
Deprecated.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()
Deprecated.protected java.lang.String
getOption(java.lang.String key, java.lang.String defaultValue)
Deprecated.Returns the option for the given key or the default value if the key doesn't exist.abstract java.lang.String
getOptionsForm()
Deprecated.Implement this method to return an HTML form containing the options which should be modified using the administration page.abstract java.lang.String
getOptionsJson()
Deprecated.Returns the options available of the client-side in JSON format.abstract java.lang.String
getPath()
Deprecated.Should be implemented to return the relative path handled by this plugin.void
init()
Deprecated.Derived classes should make sure to call this method.boolean
requiresAuthorization()
Deprecated.PluginConfigExtensions will only serve content if the user is authenticated.protected void
saveOptions()
Deprecated.Saves the set options to disk.java.lang.String
serializeMapToJSON(java.util.Map<java.lang.String,java.lang.Object> map)
Deprecated.Serializes a map to a JSON string.void
setDefaultOptions(java.util.Map<java.lang.String,java.lang.String> defaultOptions)
Deprecated.Sets the default options for this plugin configuration extension.protected void
setOption(java.lang.String key, java.lang.String value)
Deprecated.Sets the value of an option referenced by its key.-
Methods inherited from class ro.sync.ecss.extensions.api.webapp.plugin.WebappServletPluginExtension
doPost, getServletConfig, init, service
-
-
-
-
Method Detail
-
getPath
public abstract java.lang.String getPath()
Deprecated.Should be implemented to return the relative path handled by this plugin. The path should be unique among other webapp servlet plugins paths and not an empty String. and should contain only lower case letters or the '-' sign. Example: "plugin-path".- Specified by:
getPath
in classWebappServletPluginExtension
- Returns:
- The path at which the servlet will be accessed.
-
init
public void init() throws javax.servlet.ServletException
Deprecated.Derived classes should make sure to call this method.- Overrides:
init
in classWebappServletPluginExtension
- Throws:
javax.servlet.ServletException
- Thrown to respect the interface
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
Deprecated.This method responds with the plugin configuration page (html/css/js).- Overrides:
doGet
in classWebappServletPluginExtension
- Parameters:
req
- The HTTP requestresp
- The HTTP response- Throws:
javax.servlet.ServletException
- To respect the interfacejava.io.IOException
- Thrown by getWriter
-
doPut
public void doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
Deprecated.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. Derived methods should use setOption in this method. And afterwards call saveOptions().- Overrides:
doPut
in classWebappServletPluginExtension
- Parameters:
req
- The HTTP request objectresp
- The HTTP response object- Throws:
javax.servlet.ServletException
- To respect the interfacejava.io.IOException
- If the options file is not found or storing the options encounters an error
-
doDelete
public void doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
Deprecated.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.
- Overrides:
doDelete
in classWebappServletPluginExtension
- Parameters:
req
- The HTTP request objectresp
- The HTTP response object- Throws:
javax.servlet.ServletException
- To respect the interfacejava.io.IOException
- When the options file is not found or storing options encounters an error
-
getOption
protected java.lang.String getOption(java.lang.String key, java.lang.String defaultValue)
Deprecated.Returns the option for the given key or the default value if the key doesn't exist.- Parameters:
key
- The key for the option to returndefaultValue
- The value to return if the key doesn't exist- Returns:
- The option for the given key or the default value if the key doesn't exist
-
setOption
protected void setOption(java.lang.String key, java.lang.String value)
Deprecated.Sets the value of an option referenced by its key.- Parameters:
key
- The key of the option to setvalue
- The value of the option to set
-
saveOptions
protected void saveOptions() throws java.io.IOException
Deprecated.Saves the set options to disk.- Throws:
java.io.IOException
- Couldn't save options.
-
getDefaultOptions
public java.util.Map<java.lang.String,java.lang.String> getDefaultOptions()
Deprecated.- Returns:
- the defaultOptions
-
setDefaultOptions
public void setDefaultOptions(java.util.Map<java.lang.String,java.lang.String> defaultOptions)
Deprecated.Sets the default options for this plugin configuration extension.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.
- Parameters:
defaultOptions
- the defaultOptions to set
-
getOptionsForm
public abstract java.lang.String getOptionsForm()
Deprecated.Implement this method to return an HTML form containing the options which should be modified using the administration page. The form inputs name attribute should be the option name.- Returns:
- The options form representing an html form with inputs where every input's name attribute represents the name of the option which we want to set.
-
getOptionsJson
public abstract java.lang.String getOptionsJson()
Deprecated.Returns the options available of the client-side in JSON format. These options will be available for all type of users so you should not include sensitive options that should require authorization.- Returns:
- the options available on client formated as JSON.
-
requiresAuthorization
public final boolean requiresAuthorization()
Deprecated.PluginConfigExtensions will only serve content if the user is authenticated.- Overrides:
requiresAuthorization
in classWebappServletPluginExtension
- Returns:
- True to require authorization
-
serializeMapToJSON
public java.lang.String serializeMapToJSON(java.util.Map<java.lang.String,java.lang.Object> map)
Deprecated.Serializes a map to a JSON string.- Parameters:
map
- the map to serialize to JSON string.- Returns:
- the map serialized as a JSON.
-
-