Package de.xima.fc.servlet.resource
Interface IPluginStaticResourceServletAction
-
- All Superinterfaces:
IFCPlugin
,INamedUiElement
,INameProviding
,IPluginServletAction
,ITransferable
,Serializable
- All Known Implementing Classes:
APluginStaticResourceServletAction
public interface IPluginStaticResourceServletAction extends IPluginServletAction
Mixin forIPluginServletAction
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_FILENAME
-
Fields inherited from interface de.xima.fc.interfaces.INamedUiElement
ATTR_DISPLAY_NAME
-
Fields inherited from interface de.xima.fc.entities.interfaces.INameProviding
ATTR_NAME, COL_NAME
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default IPluginServletActionRetVal
execute(IPluginServletActionParams args)
The main method of this plugin.default String
findContentType(String internalPath)
Finds the content type of a requested path.default String
getPathParam()
The URL parameter that contains the requested resource path.ETagUtil.ETag
getResourceTag(String internalPath)
Gets the tag of the requested resource path.default boolean
isPathSupported(String externalPath)
Checks if the requested path is supported or allowed.default byte[]
readResource(String internalPath)
Reads the resource for the requested path.default IPluginServletActionRetVal
respondMissingPath()
Creates the response for when thepath parameters
was not provided.default IPluginServletActionRetVal
respondResourceFound(String fileName, String contentType, byte[] content)
Creates the response for when the resource was found.default IPluginServletActionRetVal
respondResourceNotFound()
Creates the response for when the resource could not be found.default IPluginServletActionRetVal
respondServerError()
Creates the response for when an unexpected error occurred.default IPluginServletActionRetVal
respondUnsupportedPath()
Creates the response for when the requested path is not acceptable.default String
toInternalPath(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 Detail
-
execute
default IPluginServletActionRetVal execute(IPluginServletActionParams args) throws FCPluginException
Description copied from interface:IPluginServletAction
The main method of this plugin.When any exception other than
FCPluginException
is thrown, a generic HTML error page is returned to the client.- Specified by:
execute
in interfaceIPluginServletAction
- Parameters:
args
- The parameters this plugin may make use of. Contains for example the URL parameters, the data of theHttpSession
or 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, a404
HTTP response is returned to the client.
-
findContentType
default String findContentType(String internalPath)
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
default String getPathParam()
The URL parameter that contains the requested resource path. Defaults topath
.- Returns:
- The URL parameter that contains the requested resource path.
-
getResourceTag
ETagUtil.ETag getResourceTag(String internalPath)
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
default boolean isPathSupported(String externalPath)
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:
true
if the requested path is supported,false
otherwise.
-
readResource
default byte[] readResource(String internalPath)
Reads the resource for the requested path. Defaults to reading the resource in theclass path
of this class.- Parameters:
internalPath
- Path of the resource.- Returns:
- The contents of the resource, or
null
if not found.
-
respondMissingPath
default IPluginServletActionRetVal respondMissingPath()
Creates the response for when thepath parameters
was 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
default IPluginServletActionRetVal 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
default IPluginServletActionRetVal respondServerError()
Creates the response for when an unexpected error occurred. Defaults to sending a 500.- Returns:
- The response when an unexpected error occurred.
-
respondUnsupportedPath
default IPluginServletActionRetVal 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
default String toInternalPath(String externalPath)
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.
-
-