Interface IPluginStaticResourceServletAction

All Superinterfaces:
IFCPlugin, INamedUiElement, INameProviding, IPluginServletAction, ITransferable, Serializable
All Known Implementing Classes:
APluginStaticResourceServletAction

public interface IPluginStaticResourceServletAction extends IPluginServletAction
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
  • Method Details

    • execute

      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 interface IPluginServletAction
      Parameters:
      args - The parameters this plugin may make use of. Contains for example the URL parameters, the data of the HttpSession or the current user.
      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, a 404 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 to path.
      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 the class 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 the path 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 via isPathSupported. The external path is the path as requested. The internal path is passed to getResourceTag,findContentType, and readResource. 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.