Class FormThemeManager


  • public final class FormThemeManager
    extends Object
    Manager for IFormTheme. This class provides various static methods to find available form themes or to read the content of a file from a form theme.
    Since:
    8.3.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • defaultFormThemeReferenceIfUnresolvable

        public static FormThemeReference defaultFormThemeReferenceIfUnresolvable​(IEntityContext ec,
                                                                                 Mandant client,
                                                                                 FormThemeReference themeReference)
        Checks whether the given form theme reference can be resolved to a corresponding IFormTheme. If so, returns that reference. Otherwise, returns the default form theme reference for the given client scope.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client for which to resolve the form theme reference.
        themeReference - The form theme reference to resolve.
        Returns:
        The resolved form theme reference, or the default form theme reference if the given reference could not be resolved. Returns null if and only if the given theme reference is null.
      • findAvailableFormThemes

        public static Set<FormThemeReference> findAvailableFormThemes​(IEntityContext ec,
                                                                      Mandant client)
        Finds all form themes that are available to the given client. This includes themes from different sources, such as system form themes, client form themes, and plugin form themes.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client for which to find form themes.
        Returns:
        A list of form themes that are available to the given client.
      • findDefaultFormTheme

        public static FormThemeReference findDefaultFormTheme​(IEntityContext ec,
                                                              Mandant client)
        Finds the configured default form theme. A default can be configured for each client (optional) and for the entire system as a fallback.
        • If a client was given and the client has a default form theme, return that.
        • If the system-wide form theme was configured, return that.
        • Otherwise, the system is misconfigured. Return the modern form theme.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client scope where to look for the default form theme. Can be null, then only the system scope is considered.
        Returns:
        The default form theme for the given client or the system-wide default form theme.
      • findFormThemeFileVersion

        public static String findFormThemeFileVersion​(IEntityContext ec,
                                                      Mandant client,
                                                      FormThemeReference theme,
                                                      String context,
                                                      String filePath)
        Finds the version of a file from the given form theme. The version can be used e.g. as a cache key. No guarantees are made regarding the format of the version string, it should be treated as an opaque value. The only guarantee is that the version string will change when the content of the file changes.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client for which to find the form theme.
        theme - The form theme reference to use.
        context - The context in which the file is used. See EFormThemeResourceContext for well-known contexts.
        filePath - The path to the file for which to find the version.
        Returns:
        The version of the file from the given form theme, or null if the file does not exist.
      • findFormThemeFileVersion

        public static String findFormThemeFileVersion​(IEntityContext ec,
                                                      UUID clientUuid,
                                                      FormThemeReference theme,
                                                      String context,
                                                      String filePath)
        Finds the version of a file from the given form theme. The version can be used e.g. as a cache key. No guarantees are made regarding the format of the version string, it should be treated as an opaque value. The only guarantee is that the version string will change when the content of the file changes.
        Parameters:
        ec - Entity context to use for accessing the database.
        clientUuid - The client for which to find the form theme.
        theme - The form theme reference to use.
        context - The context in which the file is used. See EFormThemeResourceContext for well-known contexts.
        filePath - The path to the file for which to find the version.
        Returns:
        The version of the file from the given form theme, or null if the file does not exist.
      • findFormThemeUsages

        public static FormThemeUsages findFormThemeUsages​(IEntityContext ec,
                                                          Mandant client,
                                                          FormThemeReference themeReference)
        Finds all locations where the given form theme is still used. For example, a form theme may still be used as the theme of a form version; or as the parent of a client form theme.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client to which to limit the search. Optional, when not given, all clients are searched.
        themeReference - The form theme reference to search for.
        Returns:
        All locations where the given form theme is still used.
      • findFormThemeUsages

        public static FormThemeUsages findFormThemeUsages​(IEntityContext ec,
                                                          Mandant client,
                                                          PluginRuntime runtime)
        Finds all locations where any theme from the given form theme plugin is still used. For example, a theme may still be used as the theme of a form version; or as the parent of a client form theme.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client to which to limit the search. Optional, when not given, all clients are searched.
        runtime - Runtime of a plugin containing form theme plugins.
        Returns:
        All locations where the given form theme is still used.
      • findFormThemesPossibleAsParentFor

        public static Set<FormThemeReference> findFormThemesPossibleAsParentFor​(IEntityContext ec,
                                                                                Mandant client,
                                                                                FormThemeReference theme,
                                                                                Set<FormThemeReference> themes)
        Finds all form themes that can be used as a parent theme for the given theme. This is the set of all form themes, excluding the given theme itself, as well as any theme that would result in a circular reference when used as a parent theme.

        Returns an empty set if the given theme is not resolvable.

        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client for which to find possible parent themes, used to resolve the form themes.
        theme - The theme for which to find possible parent themes.
        themes - The set of all available form themes to consider. This is often the result of calling findAvailableFormThemes.
        Returns:
        The set of all form themes that can be used as a parent theme for the given theme.
      • isFormThemeReferenceResolvable

        public static boolean isFormThemeReferenceResolvable​(IEntityContext ec,
                                                             Mandant client,
                                                             FormThemeReference themeReference)
        Checks whether form theme reference can be resolved to a corresponding IFormTheme. May return false e.g. when the referenced theme no longer exists.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client for which to resolve the form theme reference.
        themeReference - The form theme reference to resolve.
        Returns:
        True if a form theme exists that corresponds to the given form theme reference, or false if the form theme reference is invalid or the form theme cannot be found.
        See Also:
        resolveFormThemeReference(IEntityContext, Mandant, FormThemeReference)
      • openFormThemeFilesHierarchically

        public static InputStream openFormThemeFilesHierarchically​(IEntityContext ec,
                                                                   Mandant client,
                                                                   FormThemeReference themeReference,
                                                                   String context,
                                                                   Predicate<? super String> fileNameFilter)
        Opens an input stream to a file or multiple files from the given form theme.

        Files are sorted in alphanumerical order, ignoring upper and lower case.

        When the given theme has parent themes and those themes also contain the file, their contents are combined according to the indicated inheritance mode.

        Returns an empty stream if the given theme is not resolvable.

        Parameters:
        ec - Entity context to use for accessing the database.
        client - Client scope where to look for themes.
        themeReference - UUID of a form theme from the given client.
        context - The context in which the file is used. See EFormThemeResourceContext for well-known contexts.
        fileNameFilter - Filter for the files to include.
        Returns:
        The content of the given file from the form theme and all its parent form themes, starting at the topmost parent theme and ordered by the file name.
        Throws:
        CyclicFormThemeHierarchyException - When a circular reference is detected in the form theme hierarchy.
      • resolveFormThemeCssClassesHierarchically

        public static Set<String> resolveFormThemeCssClassesHierarchically​(IEntityContext ec,
                                                                           Mandant client,
                                                                           FormThemeReference formTheme)
        Gets all CSS classes from the given form theme, including all its parent themes. The CSS classes are returned in no particular order. Returns an empty set if the given theme is not resolvable.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - Client scope where to look for themes.
        formTheme - UUID of a form theme from the given client.
        Returns:
        A set of all CSS classes from the given form theme and all its parent form themes.
        Throws:
        CyclicFormThemeHierarchyException - When a circular reference is detected in the form theme hierarchy.
      • resolveFormThemeCssClassesHierarchically

        public static Set<String> resolveFormThemeCssClassesHierarchically​(IFormThemeChain themeChain)
        Gets all CSS classes from the given form theme, including all its parent themes. The CSS classes are returned in no particular order. Returns an empty set if the given theme is not resolvable.
        Parameters:
        themeChain - Resolved form theme chain of the theme, see resolveFormThemeReferenceHierarchy.
        Returns:
        A set of all CSS classes from the given form theme and all its parent form themes.
      • resolveFormThemeFilesHierarchically

        public static List<FormThemeFileReference> resolveFormThemeFilesHierarchically​(IEntityContext ec,
                                                                                       Mandant client,
                                                                                       FormThemeReference themeReference,
                                                                                       String context,
                                                                                       Predicate<? super String> fileNameFilter)
        Resolves one or multiple files from the given form theme. Reference to files are returned in the appropriate order, respecting the file name and the inheritance mode of the files. This is also the order used for the input stream returned by openFormThemeFilesHierarchically

        Files are sorted in alphanumerical order, ignoring upper and lower case.

        When the given theme has parent themes and those themes also contain the file, their contents are combined according to the indicated inheritance mode.

        Returns an empty list if the given theme is not resolvable.

        Parameters:
        ec - Entity context to use for accessing the database.
        client - Client scope where to look for themes.
        themeReference - UUID of a form theme from the given client.
        context - The resource context in which the file is used. See EFormThemeResourceContext for well-known contexts.
        fileNameFilter - Filter for the files to include.
        Returns:
        A list with the given file or files from the form theme and all its parent form themes, starting at the topmost parent theme and ordered by the file name.
        Throws:
        CyclicFormThemeHierarchyException - When a circular reference is detected in the form theme hierarchy.
      • resolveFormThemeFilesHierarchically

        public static List<FormThemeFileReference> resolveFormThemeFilesHierarchically​(IFormThemeChain themeChain,
                                                                                       String context,
                                                                                       Predicate<? super String> fileNameFilter)
        Resolves one or multiple files from the given form theme. Reference to files are returned in the appropriate order, respecting the file name and the inheritance mode of the files. This is also the order used for the input stream returned by openFormThemeFilesHierarchically

        Files are sorted in alphanumerical order, ignoring upper and lower case.

        When the given theme has parent themes and those themes also contain the file, their contents are combined according to the indicated inheritance mode.

        Returns an empty list if the given theme is not resolvable.

        Parameters:
        themeChain - Resolved form theme chain of the theme, see resolveFormThemeReferenceHierarchy.
        context - The resource context in which the file is used. See EFormThemeResourceContext for well-known contexts.
        fileNameFilter - Filter for the files to include.
        Returns:
        A list with the given file or files from the form theme and all its parent form themes, starting at the topmost parent theme and ordered by the file name.
      • resolveFormThemeReference

        public static IFormTheme resolveFormThemeReference​(IEntityContext ec,
                                                           Mandant client,
                                                           FormThemeReference themeReference)
        Resolves a form theme reference to the corresponding IFormTheme that can be used to access the form theme. Returns the null if the given theme is not resolvable.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client for which to resolve the form theme reference.
        themeReference - The form theme reference to resolve.
        Returns:
        The form theme that corresponds to the given form theme reference, or the default theme if the form theme reference is invalid or the form theme cannot be found.
        See Also:
        resolveFormThemeReferenceHierarchy(IEntityContext, Mandant, FormThemeReference)
      • resolveFormThemeReferenceHierarchy

        public static IFormThemeChain resolveFormThemeReferenceHierarchy​(IEntityContext ec,
                                                                         Mandant client,
                                                                         FormThemeReference themeReference)
        Resolves the given theme reference and all its parents to a list of IFormTheme instances. The returned list contains the topmost parent theme first. When the given theme has no parent, the returned list contains only the given theme. Returns an empty list if the given theme is not resolvable.
        Parameters:
        ec - Entity context to use for accessing the database.
        client - The client for which to resolve the form theme reference.
        themeReference - The form theme reference to resolve.
        Returns:
        A list of form themes that correspond to the given form theme reference and all its parents, starting at the topmost parent theme.
        Throws:
        CyclicFormThemeHierarchyException - When a circular reference is detected in the form theme hierarchy.
        See Also:
        resolveFormThemeReference(IEntityContext, Mandant, FormThemeReference)