Class StaticFormTheme
- java.lang.Object
-
- de.xima.fc.common.form_theme.StaticFormTheme
-
- All Implemented Interfaces:
IFormTheme
public final class StaticFormTheme extends Object implements IFormTheme
A generic implementation ofIFormTheme
with a builder. Assumes the set of available files in the theme is known statically. Not intended for use cases when the set of available files must be determined dynamically.The builder lets configure various options. It also lets you add files to the theme. The available files must be known beforehand, but the contents can be loaded dynamically. You can either specify the content for each file separately, or use a global loader that is able to load files for a given context and file path.
This implementation is immutable and thread-safe, providing user provided logic such as loaders are also immutable and thread-safe.
- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StaticFormTheme.Builder
Builder for aform theme
.static class
StaticFormTheme.FormThemeFileMeta
Metadata of a file in a form theme.static interface
StaticFormTheme.IFormThemeFileLoader
Loader for the contents of a specific file in a form theme.static interface
StaticFormTheme.IFormThemeInheritanceModeProvider
Provider for the inheritance mode of a file in a form theme.static interface
StaticFormTheme.IFormThemeOfferCssClassesAsSuggestionsProvider
Provider for the flag that indicates whether to offer CSS classes as suggestions, for a file in a form theme.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StaticFormTheme.Builder
builder()
Creates a new builder for a form theme.boolean
containsFile(String context, String filePath)
Checks if the form theme contains a file with the given name.Set<String>
getCssClasses()
Gets a list of CSS classes that should be added to the container element.String
getDisplayName(Locale locale)
Gets the display name of this theme in the given locale.EFormThemeFileInheritanceMode
getFileInheritanceMode(String context, String filePath)
Controls the behavior when aIFormTheme
and its parent both contain a file with the same name.Set<String>
getFilePaths(String context)
Returns a list of all file paths in this form theme.String
getGroupName(Locale locale)
Gets the localized group name of this theme in the given locale.FormThemeReference
getParentFormTheme()
The parent form theme from which this form theme inherits.boolean
isOfferCssClassesAsSuggestions(String context, String filePath)
Controls the behavior in the form designer.InputStream
openFile(String context, String filePath)
Opens an input stream to the file with the given name.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.xima.fc.form.common.interfaces.IFormTheme
readTextFile
-
-
-
-
Method Detail
-
containsFile
public boolean containsFile(String context, String filePath)
Description copied from interface:IFormTheme
Checks if the form theme contains a file with the given name. This method only checks files from this particular form theme, implementations must NOT attempt to check files from the parent theme (if any).- Specified by:
containsFile
in interfaceIFormTheme
- Parameters:
context
- The context from which to retrieve the file. SeeEFormThemeResourceContext
for common contexts. Other resource contexts may be used by plugins.filePath
- The name of the file to check.- Returns:
- True if the file exists, false otherwise.
-
getCssClasses
public Set<String> getCssClasses()
Description copied from interface:IFormTheme
Gets a list of CSS classes that should be added to the container element. The exact nature of the container element depends on how and where the form is used. You should not make any assumptions about the container element, other than that all relevant elements will be inside that container.You could e.g. use these CSS classes as part of a CSS selector to style the form.
- Specified by:
getCssClasses
in interfaceIFormTheme
- Returns:
- A list of CSS classes to add to the container element.
-
getDisplayName
public String getDisplayName(Locale locale)
Description copied from interface:IFormTheme
Gets the display name of this theme in the given locale. The display name is a human-readable name that can be shown to the user, e.g. in the form designer.- Specified by:
getDisplayName
in interfaceIFormTheme
- Parameters:
locale
- The locale for which to retrieve the display name.- Returns:
- The display name of this theme in the given locale.
-
getFileInheritanceMode
public EFormThemeFileInheritanceMode getFileInheritanceMode(String context, String filePath)
Description copied from interface:IFormTheme
Controls the behavior when aIFormTheme
and its parent both contain a file with the same name.- Specified by:
getFileInheritanceMode
in interfaceIFormTheme
- Parameters:
context
- The context for which to retrieve the inheritance mode. SeeEFormThemeResourceContext
for well-known contexts. Other resource contexts may be used by plugins.filePath
- The path of the file to check. Should be one of the paths returned bygetFilePaths
.- Returns:
- The inheritance mode for the given file.
-
getFilePaths
public Set<String> getFilePaths(String context)
Description copied from interface:IFormTheme
Returns a list of all file paths in this form theme. This method only returns files from this particular form theme, implementations must NOT attempt to access files from the parent theme (if any).The order in which the file names are returned is irrelevant. If an order is required, the framework will sort the file names as needed.
Note regarding file paths: Paths are used as-is, and passed on to other methods that require a file path. If you need case-insensitive file paths, you need to implement the other methods appropriately. Also, when a file name contains a forward slash, this is interpreted as a path separator and used e.g. when generating URLs. For example, a file named
a/b/c.css
can reference a file nameda/b/d.png
viabackground-image: url(../d.png)
.- Specified by:
getFilePaths
in interfaceIFormTheme
- Parameters:
context
- The context for which to retrieve the file name. SeeEFormThemeResourceContext
for common contexts. Other resource contexts may be used by plugins.- Returns:
- A list of all file names in this form theme.
-
getGroupName
public String getGroupName(Locale locale)
Description copied from interface:IFormTheme
Gets the localized group name of this theme in the given locale. The group name may be used on the UI, e.g. when displaying a select list of all available themes.- Specified by:
getGroupName
in interfaceIFormTheme
- Parameters:
locale
- The locale for which to retrieve the group name.- Returns:
- The group name of this theme in the given locale.
-
getParentFormTheme
public FormThemeReference getParentFormTheme()
Description copied from interface:IFormTheme
The parent form theme from which this form theme inherits. If this form theme has no parent, this method returns null. When a form theme has a parent.- Specified by:
getParentFormTheme
in interfaceIFormTheme
- Returns:
- The parent form theme, or null if this form theme has no parent.
-
isOfferCssClassesAsSuggestions
public boolean isOfferCssClassesAsSuggestions(String context, String filePath)
Description copied from interface:IFormTheme
Controls the behavior in the form designer. Users can add custom classes to form elements. The form designer offers the CSS classes from themes as suggestions. If this method returns false, the CSS classes from this file (and all files it@import
s) are not offered as suggestions.This method will only be called for CSS files.
- Specified by:
isOfferCssClassesAsSuggestions
in interfaceIFormTheme
- Parameters:
context
- The context of the CSS file to check. SeeEFormThemeResourceContext
for common contexts. Other resource contexts may be used by plugins.filePath
- The path of the file to check. Should be one of the paths returned bygetFilePaths
.- Returns:
- True if the CSS classes from this file should be offered as suggestions, false otherwise.
-
openFile
public InputStream openFile(String context, String filePath) throws IOException
Description copied from interface:IFormTheme
Opens an input stream to the file with the given name. The file name must be one of the file names returned byIFormTheme.getFilePaths(String)
. This method only returns files from this particular form theme, implementations must NOT attempt to access files from the parent theme (if any).- Specified by:
openFile
in interfaceIFormTheme
- Parameters:
context
- The context from which to retrieve the file. SeeEFormThemeResourceContext
for common contexts. Other resource contexts may be used by plugins.filePath
- The path of the file to open. Should be one of path returned byIFormTheme.getFilePaths(String)
.- Returns:
- An input stream to the contents of the file.
- Throws:
IOException
- If the file could not be opened.
-
builder
public static StaticFormTheme.Builder builder()
Creates a new builder for a form theme.The builder lets configure various options. It also lets you add files to the theme. The available files must be known beforehand, but the contents can be loaded dynamically. You can either specify the content for each file separately, or use a global loader that is able to load files for a given context and file path.
- Returns:
- A new form theme builder.
-
-