Class AbstractWebResourceComponent

java.lang.Object
de.aristaflow.adept2.core.runtimemanager.executionenvironments.ExecutionEnvironment
de.aristaflow.adept2.ui.htmlgui.executionenvironments.AbstractWebResourceComponent
All Implemented Interfaces:
ExecutableComponent
Direct Known Subclasses:
AbstractWebComponent

public abstract class AbstractWebResourceComponent extends ExecutionEnvironment
Abstract base class for web components implementing handling of external and internal resources which may be used for and from the web frontend.
  • Field Details

    • CONF_EXT_RESOURCE_DIR

      public static final String CONF_EXT_RESOURCE_DIR
      The configuration entry for a specific external resource directory.
      See Also:
    • GLOBAL_EXT_RESOURCE_DIR

      public static final String GLOBAL_EXT_RESOURCE_DIR
      The name of the external resources directory below the data dir.
      See Also:
    • USER_SIGNAL_FILE

      public static final String USER_SIGNAL_FILE
      The parameter indicating that a file from internal resources is being requested.
      See Also:
    • USER_SIGNAL_EXT_FILE

      public static final String USER_SIGNAL_EXT_FILE
      The parameter indicating that an external file is being requested.
      See Also:
    • extScripts

      protected final List<String> extScripts
      List of external scripts to be automatically included into the form.
    • extCssFiles

      protected final List<String> extCssFiles
      List of external CSS files to be automatically included into the form.
    • htmlContext

      protected HTMLContext htmlContext
      Context that contains the URL of the current environment and accepts and displays the HTML content for the page that should be shown to the user.
      Use url for retrieving the (relative) URL from a non executable component thread.
    • url

      protected String url
      The (relative) URL of the HTMLContext. This is separated to allow access from threads which are not allowed to access the HTMLContext.
  • Constructor Details

    • AbstractWebResourceComponent

      public AbstractWebResourceComponent(String ecName, ActivityInstance activityInstance, String internalResourcePath)
      Parameters:
      ecName - The executable component name.
      activityInstance - The activity instance.
      internalResourcePath - The path for internal resources, to be used with getClass().getRessourceAsStream(...).
  • Method Details

    • init

      public void init(SessionContext sessContext)
      Description copied from class: ExecutionEnvironment
      Initialises this ExecutionEnvironment by setting the session context, the logger field and the activity data. These fields are not available before! Therefore you should call this method very early when initialising or initialising for resume.

      Initialises and prepares the execution of the application and provides all necessary data which maybe necessary for this. This method or ExecutableComponent.initResume(String, SessionContext) is only called once in the lifetime of an executable component. One of these methods is guaranteed to be called before calling any other method.

      When leaving this method the execution has to be completely prepared. This includes for instance the availability of the GUI in the GUI context, which is necessary for Web applications with HTML-UI.

      Specified by:
      init in interface ExecutableComponent
      Overrides:
      init in class ExecutionEnvironment
      Parameters:
      sessContext - The session context to associate with this ExecutionEnvironment.
    • initialiseAndGetInitialContent

      protected abstract String initialiseAndGetInitialContent()
      Called from within init(SessionContext) to let the subclass initialise itself, e.g. restoring any previous state on resume, and create the initial HTML page content.
      Returns:
      The HTML content of the initial reply.
    • getResourceAsString

      protected String getResourceAsString(String name, boolean external) throws FileNotFoundException, IOException
      Gets the content of the designated resource as UTF-8 string. The name is either appended to the external resource path and loaded as file or appended to the internal class path and loaded via this (that is, the corresponding subclass of this) class. Therefore an internal path is relative to this class.
      Parameters:
      name - The name of the resource which to load from the external or internal resource path.
      external - Whether to load the designated resource as external (or internal) resource, that is as file or as resource relative to this (that is, the corresponding subclass of this) class.
      Returns:
      The content of the designated resource as UTF-8 string.
      Throws:
      FileNotFoundException - If the external resource cannot be loaded since it is not found as file, a FileNotFoundException will be thrown.
      IOException - If there are problems reading the UTF-8 string from the input stream, an IOException will be thrown.
    • getResourceAsStream

      protected InputStream getResourceAsStream(String name, boolean external) throws FileNotFoundException
      Gets the content of the designated resource as input stream. The name is either appended to the external resource path and loaded as file or appended to the internal class path and loaded via this (that is, the corresponding subclass of this) class. Therefore an internal path is relative to this class. If there is no external resource path set, the internal path will be added (but it will still be loaded as file).
      Parameters:
      name - The name of the resource which to load from the external or internal resource path.
      external - Whether to load the designated resource as external (or internal) resource, that is as file or as resource relative to this (that is, the corresponding subclass of this) class.
      Returns:
      The content of the designated resource as input stream. The caller is responsible for closing.
      Throws:
      FileNotFoundException - If the external resource cannot be loaded since it is not found as file, a FileNotFoundException will be thrown.
    • getResourceLink

      protected String getResourceLink(String simpleName, boolean external)
      Builds a link which can be embedded into the HTML code and references an internal or external resource.
      Parameters:
      simpleName - The simple name of the resource.
      external - True, if it is an external resource.
      Returns:
      The URL which can be used to retrieve the resource from this component.
    • getMimeType

      @Deprecated(since="14.0.0", forRemoval=true) protected String getMimeType(String fileName)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the MIME type guessed from the given file name.

      Currently recognises: .css, .js, .png, .html, .htm

      Parameters:
      fileName -
      Returns:
      The mime type for the given file name.