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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface de.aristaflow.adept2.model.runtimeenvironment.ExecutableComponent
ExecutableComponent.Signals
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONF_EXT_RESOURCE_DIR
The configuration entry for a specific external resource directory.protected List<String>
extCssFiles
List of external CSS files to be automatically included into the form.protected List<String>
extScripts
List of external scripts to be automatically included into the form.static String
GLOBAL_EXT_RESOURCE_DIR
The name of the external resources directory below the data dir.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.protected String
url
The (relative) URL of theHTMLContext
.static String
USER_SIGNAL_EXT_FILE
The parameter indicating that an external file is being requested.static String
USER_SIGNAL_FILE
The parameter indicating that a file from internal resources is being requested.-
Fields inherited from class de.aristaflow.adept2.core.runtimemanager.executionenvironments.ExecutionEnvironment
actData, activityInstance, cleanup, localisedActInst, logger, sessionContext, SUSPEND_SAVEPOINT
-
Fields inherited from interface de.aristaflow.adept2.model.runtimeenvironment.ExecutableComponent
CONF_DATA_DIRECTORY, CONF_LIB_DIRECTORY, CONF_LOG_DIRECTORY, UNLOADING_CLASS_METHOD
-
-
Constructor Summary
Constructors Constructor Description AbstractWebResourceComponent(String ecName, ActivityInstance activityInstance, String internalResourcePath)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected String
getMimeType(String fileName)
Deprecated, for removal: This API element is subject to removal in a future version.UseMediaTypes.detect(String)
instead.protected InputStream
getResourceAsStream(String name, boolean external)
Gets the content of the designated resource as input stream.protected String
getResourceAsString(String name, boolean external)
Gets the content of the designated resource as UTF-8 string.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.void
init(SessionContext sessContext)
Initialises thisExecutionEnvironment
by setting the session context, the logger field and the activity data.protected abstract String
initialiseAndGetInitialContent()
Called from withininit(SessionContext)
to let the subclass initialise itself, e.g.-
Methods inherited from class de.aristaflow.adept2.core.runtimemanager.executionenvironments.ExecutionEnvironment
cleanup, close, commit, createActivityData, getApplicationState, getApplicationState, getRawApplicationState, getRawApplicationState, initResume, kill, prepareCommit, requireGUIContext, reset, rollback, run, setApplicationState, setApplicationState, setRawApplicationState, setRawApplicationState, signal, suspend
-
-
-
-
Field Detail
-
CONF_EXT_RESOURCE_DIR
public static final String CONF_EXT_RESOURCE_DIR
The configuration entry for a specific external resource directory.- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
USER_SIGNAL_FILE
public static final String USER_SIGNAL_FILE
The parameter indicating that a file from internal resources is being requested.- See Also:
- Constant Field Values
-
USER_SIGNAL_EXT_FILE
public static final String USER_SIGNAL_EXT_FILE
The parameter indicating that an external file is being requested.- See Also:
- Constant Field Values
-
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.
Useurl
for retrieving the (relative) URL from a non executable component thread.
-
url
protected String url
The (relative) URL of theHTMLContext
. This is separated to allow access from threads which are not allowed to access theHTMLContext
.
-
-
Constructor Detail
-
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 Detail
-
init
public void init(SessionContext sessContext)
Description copied from class:ExecutionEnvironment
Initialises thisExecutionEnvironment
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 interfaceExecutableComponent
- Overrides:
init
in classExecutionEnvironment
- Parameters:
sessContext
- The session context to associate with thisExecutionEnvironment
.
-
initialiseAndGetInitialContent
protected abstract String initialiseAndGetInitialContent()
Called from withininit(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, aFileNotFoundException
will be thrown.IOException
- If there are problems reading the UTF-8 string from the input stream, anIOException
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, aFileNotFoundException
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.UseMediaTypes.detect(String)
instead.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.
-
-