Package de.xima.fc.servlet.resource
Interface IPluginStaticResourceServletAction
- All Superinterfaces:
IFCPlugin,INamedUiElement,INameProviding,IPluginServletAction,ITransferable,Serializable
- All Known Implementing Classes:
APluginStaticResourceServletAction
Mixin for
IPluginServletAction that provides a basic implementation for a servlet action that provides static
resources.
The execute should not be overridden. All other methods implement
sane defaults, are orthogonal to each other and can be overridden as required.
- Since:
- 1.0.0
- Author:
- XIMA MEDIA GmbH
-
Field Summary
Fields inherited from interface de.xima.fc.plugin.interfaces.IFCPlugin
CONFIG_FILENAMEFields inherited from interface de.xima.fc.interfaces.INamedUiElement
ATTR_DISPLAY_NAMEFields inherited from interface de.xima.fc.entities.interfaces.INameProviding
ATTR_NAME, COL_NAME -
Method Summary
Modifier and TypeMethodDescriptiondefault IPluginServletActionRetValThe main method of this plugin.default StringfindContentType(String internalPath) Finds the content type of a requested path.default StringThe URL parameter that contains the requested resource path.getResourceTag(String internalPath) Gets the tag of the requested resource path.default booleanisPathSupported(String externalPath) Checks if the requested path is supported or allowed.default byte[]readResource(String internalPath) Reads the resource for the requested path.default IPluginServletActionRetValCreates the response for when thepath parameterswas not provided.default IPluginServletActionRetValrespondResourceFound(String fileName, String contentType, byte[] content) Creates the response for when the resource was found.default IPluginServletActionRetValCreates the response for when the resource could not be found.default IPluginServletActionRetValCreates the response for when an unexpected error occurred.default IPluginServletActionRetValCreates the response for when the requested path is not acceptable.default StringtoInternalPath(String externalPath) Converts an external path to an internal path.Methods inherited from interface de.xima.fc.plugin.interfaces.IFCPlugin
getDescription, getDescription, getDisplayName, getName, initialize, initPlugin, install, shutdown, shutdown, uninstall, validateConfigurationData
-
Method Details
-
execute
default IPluginServletActionRetVal execute(IPluginServletActionParams args) throws FCPluginException Description copied from interface:IPluginServletActionThe main method of this plugin.When any exception other than
FCPluginExceptionis thrown, a generic HTML error page is returned to the client.- Specified by:
executein interfaceIPluginServletAction- Parameters:
args- The parameters this plugin may make use of. Contains for example the URL parameters, the data of theHttpSessionor the currentuser.- Returns:
- The HTTP response code and the data to be sent as the response.
- Throws:
FCPluginException- May be thrown when this plugin cannot handle the request. When this exception is thrown, a404HTTP response is returned to the client.
-
findContentType
Finds the content type of a requested path. Defaults to making a best guess based on the file name.- Parameters:
internalPath- Path to check.- Returns:
- The content type of the resource with the given path.
-
getPathParam
The URL parameter that contains the requested resource path. Defaults topath.- Returns:
- The URL parameter that contains the requested resource path.
-
getResourceTag
Gets the tag of the requested resource path. The tag is used for caching. As long as the tag does not change, the resource content is not sent again to clients that already have the resource.- Parameters:
internalPath- Path to check.- Returns:
- The (version) tag of the given resource path.
-
isPathSupported
Checks if the requested path is supported or allowed. If not, an error response is sent back to the client immediately. Defaults to allowing common resource files such as text files, images, fonts, and JavaScript and CSS.- Parameters:
externalPath- Path to check.- Returns:
trueif the requested path is supported,falseotherwise.
-
readResource
Reads the resource for the requested path. Defaults to reading the resource in theclass pathof this class.- Parameters:
internalPath- Path of the resource.- Returns:
- The contents of the resource, or
nullif not found.
-
respondMissingPath
Creates the response for when thepath parameterswas not provided. Defaults to sending a 404.- Returns:
- The response when a resource was not found.
-
respondResourceFound
default IPluginServletActionRetVal respondResourceFound(String fileName, String contentType, byte[] content) Creates the response for when the resource was found. Defaults to sending a 200 with the contents of the resource.- Parameters:
fileName- Name of the requested file.contentType- Content type of the file.content- Content of the file.- Returns:
- The response when a resource was found.
-
respondResourceNotFound
Creates the response for when the resource could not be found. Defaults to sending a 404.- Returns:
- The response when a resource was not found.
-
respondServerError
Creates the response for when an unexpected error occurred. Defaults to sending a 500.- Returns:
- The response when an unexpected error occurred.
-
respondUnsupportedPath
Creates the response for when the requested path is not acceptable. Defaults to sending a 400.- Returns:
- The response when the requested path is not acceptable.
-
toInternalPath
Converts an external path to an internal path. Called after the external path was checked viaisPathSupported. The external path is the path as requested. The internal path is passed togetResourceTag,findContentType, andreadResource. The default implementation simply return the path as given. Can be used e.g. to prepend a prefix such as a directory or a package path.- Parameters:
externalPath- External path to convert.- Returns:
- The internal path representing the resource.
-