Class ServletPluginConfigExtension
- All Implemented Interfaces:
- PluginExtension
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:
- 26
- 
Field SummaryFields inherited from class ro.sync.ecss.extensions.api.webapp.plugin.ServletPluginExtensionconfig
- 
Constructor SummaryConstructorsConstructorDescriptionIn the derived class make sure to set the default options.
- 
Method SummaryModifier and TypeMethodDescriptionvoiddoDelete(HttpServletRequest req, HttpServletResponse resp) This method should return a plugin to its default options.voiddoGet(HttpServletRequest req, HttpServletResponse resp) This method responds with the plugin configuration page (html/css/js).voiddoPut(HttpServletRequest req, 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.protected StringReturns the option for the given key or the default value if the key doesn't exist.abstract StringImplement this method to return an HTML form containing the options which should be modified using the administration page.abstract StringReturns the options available of the client-side in JSON format.protected StringgetOrMigrateSecretOption(String key, String defaultValue) Retrieves a secret option with migration support.abstract StringgetPath()Should be implemented to return the relative path handled by this plugin.protected StringgetSecretOption(String key, String defaultValue) Returns the secret option for the given key or the default value if the key doesn't exist.voidinit()Derived classes should make sure to call this method.final booleanPluginConfigExtensions will only serve content if the user is authenticated.protected voidSaves the set options to disk.serializeMapToJSON(Map<String, Object> map) Serializes a map to a JSON string.voidsetDefaultOptions(Map<String, String> defaultOptions) Sets the default options for this plugin configuration extension.protected voidSets the value of an option referenced by its key.protected voidsetSecretOption(String key, String value) Sets the value of a secret option referenced by its key.Methods inherited from class ro.sync.ecss.extensions.api.webapp.plugin.ServletPluginExtensiondoPost, getServletConfig, init, service
- 
Constructor Details- 
ServletPluginConfigExtensionpublic ServletPluginConfigExtension()In the derived class make sure to set the default options.
 
- 
- 
Method Details- 
getPathShould 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:
- getPathin class- ServletPluginExtension
- Returns:
- The path at which the servlet will be accessed.
 
- 
initDerived classes should make sure to call this method.- Overrides:
- initin class- ServletPluginExtension
- Throws:
- ServletException- Thrown to respect the interface
 
- 
doGetpublic void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException This method responds with the plugin configuration page (html/css/js).- Overrides:
- doGetin class- ServletPluginExtension
- Parameters:
- req- The HTTP request
- resp- The HTTP response
- Throws:
- ServletException- To respect the interface
- IOException- Thrown by getWriter
 
- 
doPutpublic void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 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:
- doPutin class- ServletPluginExtension
- Parameters:
- req- The HTTP request object
- resp- The HTTP response object
- Throws:
- ServletException- To respect the interface
- IOException- If the options file is not found or storing the options encounters an error
 
- 
doDeletepublic void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, 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. - Overrides:
- doDeletein class- ServletPluginExtension
- Parameters:
- req- The HTTP request object
- resp- The HTTP response object
- Throws:
- ServletException- To respect the interface
- IOException- When the options file is not found or storing options encounters an error
 
- 
getOptionReturns the option for the given key or the default value if the key doesn't exist.- Parameters:
- key- The key for the option to return
- defaultValue- 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
 
- 
getSecretOptionReturns the secret option for the given key or the default value if the key doesn't exist.- Parameters:
- key-
- defaultValue-
- Returns:
- The secret option for the given key or the default value if the key doesn't exist
 
- 
getOrMigrateSecretOptionRetrieves a secret option with migration support. If no encrypted option is found, it falls back to a non-encrypted value, encrypts it, saves it securely, and removes the non-encrypted version.- Parameters:
- key- The key for the option.
- defaultValue- The default value to return if no option is found.
- Returns:
- The decrypted value, or the default value if neither is found.
 
- 
setOptionSets the value of an option referenced by its key.- Parameters:
- key- The key of the option to set
- value- The value of the option to set
 
- 
setSecretOptionSets the value of a secret option referenced by its key.- Parameters:
- key- The key of the option to set
- value- The value of the secret option to set
 
- 
saveOptionsSaves the set options to disk.- Throws:
- IOException- Couldn't save options.
 
- 
getDefaultOptions- Returns:
- the defaultOptions
 
- 
setDefaultOptionsSets 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
 
- 
getOptionsFormImplement 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.
 
- 
getOptionsJsonReturns 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.
 
- 
requiresAuthorizationpublic final boolean requiresAuthorization()PluginConfigExtensions will only serve content if the user is authenticated.- Overrides:
- requiresAuthorizationin class- ServletPluginExtension
- Returns:
- True to require authorization
 
- 
serializeMapToJSONSerializes a map to a JSON string.- Parameters:
- map- the map to serialize to JSON string.
- Returns:
- the map serialized as a JSON.
 
 
-