Class ThemingUtil

java.lang.Object
com.jalios.jcms.theming.ThemingUtil

public class ThemingUtil extends Object
  • Field Details

    • WEBAPP_PATH

      public static final String WEBAPP_PATH
  • Constructor Details

    • ThemingUtil

      public ThemingUtil()
  • Method Details

    • deleteFiles

      public static void deleteFiles(File... files)
      Deletes the specified files. This method takes a variable number of File objects and attempts to delete each one. If a File does not exist, it is skipped. If any deletion operation encounters an error, it is logged but does not prevent the deletion of other files in the list.
      Parameters:
      files - An array of File objects to be deleted.
      Throws:
      SecurityException - If a security manager exists and denies delete permissions.
      See Also:
    • createFile

      public static boolean createFile(String content, File file)
      Parameters:
      content - the text to write in the file
      file - file path relative to the webapp
      Returns:
      true if creation succeeded
    • getFileContent

      public static String getFileContent(File file)
      Reads the content of a file and returns it as a single String. This method takes a File object, attempts to read its content, and returns it as a single String. The file is expected to be encoded in UTF-8. If the file is not found or if an IOException occurs during the reading process, an error is logged, and the method returns null.
      Parameters:
      file - The File object from which to read the content.
      Returns:
      The content of the file as a single String, or null if an error occurs.
    • getPortalSettings

      public static PublicationSettings getPortalSettings(Object value, Member mbr)
      Retrieves publication settings for a sample page. The chooser list all Portal, JPortal and PortalJSPCollection The member's rights are checked.
      Parameters:
      value - Current page
      mbr - The member for right checking.
      Returns:
      PublicationSettings containing the list of available page.
    • getLoginPageModeSettings

      public static EnumerateSettings getLoginPageModeSettings(Object value)
    • getLoginPageBackgroundFitSettings

      public static EnumerateSettings getLoginPageBackgroundFitSettings(Object value)
    • getWidthSettings

      public static NumberSettings getWidthSettings(Object value, String name)
      Gets the settings for border width with a "px" unit and integer values. This method retrieves the settings for specifying border width, allowing specifying the value, name, and "px" unit. It is often used for defining border width settings.
      Parameters:
      value - The current value of the border width.
      name - The name for the border width setting.
      Returns:
      A NumberSettings object for border width settings.
    • getFontSizeSettings

      public static TextFieldSettings getFontSizeSettings(Object value, String name)
      Gets the settings for font size with a specified maximum length and "px" unit. This method retrieves the settings for a font size input, allowing the specification of the value, name, maximum length, and "px" unit. It's commonly used for defining font size settings.
      Parameters:
      value - The current value of the font size.
      name - The name for the font size setting.
      Returns:
      A TextFieldSettings object for font size settings.
    • getFontWeightSettings

      public static EnumerateSettings getFontWeightSettings(Object value, String name)
      Gets the settings for font weight (e.g., "normal," "bold") with a default value label. This method retrieves the settings for font weight, allowing specifying the value, name, and providing a default value label. It is commonly used for font weight settings.
      Parameters:
      value - The current value of the font weight.
      name - The name for the font weight setting.
      Returns:
      An EnumerateSettings object for font weight settings.
    • getUnderlineTypeSettings

      public static SelectSettings getUnderlineTypeSettings(Object value)
    • getColorSettings

      public static ColorSettings getColorSettings(Object value, String name)
      Gets the settings for specifying a color value. This method retrieves the settings for specifying a color value, allowing specifying the value and the name of the setting. It is commonly used for defining color-related settings.
      Parameters:
      value - The current color value.
      name - The name for the color setting.
      Returns:
      A ColorSettings object for color settings.
    • getBooleanSettings

      public static BooleanSettings getBooleanSettings(Object value, String name, Boolean defaultValue)
      Gets the settings for specifying a boolean value. This method retrieves the settings for a boolean value.
      Parameters:
      value - The current boolean value.
      name - The name for the boolean setting.
      defaultValue - default value if value is null
      Returns:
      A BooleanSettings object for boolean settings.
    • getAllThemes

      public static Set<UITheme> getAllThemes()
      Get All UITheme data sort by cdate
      Returns:
      set of UITheme
      Since:
      jcms-11.0.0
    • getBreadcrumbItems

      public static List<BreadcrumbItem> getBreadcrumbItems(String userLang, String currentThemeLabel)
      Retrieves a list of breadcrumb items for the Theming Tool application. This method constructs a list of breadcrumb items for navigating within the Theming Tool application. It includes entries for "All Themes" and the current theme label. The items are represented as BreadcrumbItem objects.
      Parameters:
      userLang - The user's language for localization.
      currentThemeLabel - The label of the current theme.
      Returns:
      A list of BreadcrumbItem objects for the Theming Tool application.
    • getThemeMapper

      public static com.fasterxml.jackson.databind.ObjectMapper getThemeMapper()
      Get Jackson object Mapper for Theme class
      Returns:
      ObjectMapper for Theme
      Since:
      jcms-11.0.0
    • getPreviewThemeId

      public static String getPreviewThemeId(javax.servlet.http.HttpSession session)
      Retrieves the theme ID for preview mode from an HTTP servlet request. This method extracts the theme ID used for preview mode from an HTTP servlet request. It checks for the presence of the theme ID in the session attributes, and if found, returns it as a string. If the servlet request is null, the method returns null.
      Parameters:
      session - The HTTP session from which to retrieve the theme ID.
      Returns:
      The theme ID for preview mode as a string, or null if the request is null or no theme ID is found.
      Since:
      jcms-11.0.0
      See Also:
    • getThemeFromFile

      public static UIThemeDTO getThemeFromFile(File themeFile)
      Retrieves a UItheme DTO from a theme file. This method reads and deserializes a UItheme DTO from a given theme file (import process for example). It uses an object mapper obtained from `getThemeMapper()` to perform the deserialization.
      Parameters:
      themeFile - The theme file from which to retrieve the UItheme DTO.
      Returns:
      The UITheme DTO deserialized from the theme file, or null in case of an exception.
    • getTheme

      public static UITheme getTheme(String themeId)
      Retrieves a UItheme based on his ID. This method retrieves a UI theme based on the provided theme ID. If no UItheme is found for the given theme ID, the method returns null.
      Parameters:
      themeId - The ID of the theme for which to retrieve the UI theme.
      Returns:
      The UItheme associated with the theme ID, or null if no UI theme is found.
    • getCardCorner

      public static String getCardCorner(UITheme theme)
      Generates HTML code for a card corner based on the UI theme. This method generates HTML code for a card corner based on the provided UItheme. The HTML code is constructed to represent a theme preview or activated status as a string.
      Parameters:
      theme - The UI theme for which to generate the card corner.
      Returns:
      HTML code for the card corner based on the theme.
    • getThemeCssSelector

      public static String getThemeCssSelector(String name, boolean isPreview)
      Generates a CSS selector based on class for the given theme, considering whether it is for preview purposes. This method builds a CSS selector based on the name of the theme, appending "_preview" if it is intended for preview. The resulting selector is then processed to remove accents, replace spaces with underscores, and convert to lowercase for consistent and clean representation.
      Parameters:
      name - The theme name for which the CSS selector is generated.
      isPreview - A boolean flag indicating whether the theme is intended for preview.
      Returns:
      A CSS selector representing the given theme, with optional "_preview" suffix for preview themes.
    • getDataThemeAttribute

      public static String getDataThemeAttribute(UITheme theme, boolean isPreview)
      Generates the data-theme attribute for the given theme, considering whether it is for preview purposes. This method builds a CSS selector based on the name of the theme, appending "_preview" if it is intended for preview. The resulting selector is then processed to remove accents, replace spaces with underscores, and convert to lowercase for consistent and clean representation.
      Parameters:
      theme - The theme for which the CSS selector is generated.
      isPreview - A boolean flag indicating whether the theme is intended for preview.
      Returns:
      A CSS selector representing the given theme, with optional "_preview" suffix for preview themes.
    • getThemeCssSelector

      public static String getThemeCssSelector(UITheme theme, boolean isPreview)
      Generates a CSS selector based on class for the given theme, considering whether it is for preview purposes. This method builds a CSS selector based on the name of the theme, appending "_preview" if it is intended for preview. The resulting selector is then processed to remove accents, replace spaces with underscores, and convert to lowercase for consistent and clean representation.
      Parameters:
      theme - The theme for which the CSS selector is generated.
      isPreview - A boolean flag indicating whether the theme is intended for preview.
      Returns:
      A CSS selector representing the given theme, with optional "_preview" suffix for preview themes.
    • getThemeCssSelector

      public static String getThemeCssSelector(UITheme theme)
      Generates a CSS selector for the given theme. This method builds a CSS selector based on the name of the theme. The resulting selector is then processed to remove accents, replace spaces with underscores, and convert to lowercase for consistent and clean representation.
      Parameters:
      theme - The theme for which the CSS selector is generated.
      Returns:
      A CSS selector representing the given theme.
    • getRadiusValueWithUnit

      public static String getRadiusValueWithUnit(String radius)
      Appends ThemeConstants.PIXEL_UNIT to the given radius value, forming a complete radius string. If the input radius is empty or null, the method returns null.
      Parameters:
      radius - The numeric radius value to which the unit will be appended.
      Returns:
      The complete radius string with the specified unit, or null if the input radius is empty or null.
      See Also:
    • getRadiusValueWithUnit

      public static String getRadiusValueWithUnit(Object radius)
    • createFileDocumentFromTmpFile

      public static FileDocument createFileDocumentFromTmpFile(File tmpFile, Member author)
      Creates a FileDocument from a temporary file, associating it with the specified author.

      This method takes a temporary file and an author, generates a FileDocument by uploading the file content, and sets relevant fields such as content type, author, and workspace. The resulting FileDocument is returned.

      Parameters:
      tmpFile - The temporary file to create the FileDocument from.
      author - The author associated with the FileDocument.
      Returns:
      The generated FileDocument or null if the upload fails.
    • fileToFileDocument

      public static FileDocument fileToFileDocument(File file, FileDocument refFileDoc, Member opAuthor, Map<String,? extends Object> contextMap)
      Creates a FileDocument from the specified file.

      Important : the specified File must be in a temporary location, it will moved to its final location in JCMS.

      Parameters:
      file - the extracted file, still in its temporary location
      refFileDoc - optional FileDocument from which to retrieve fields value to be assigned to the newly created FileDocument. See Publication.assignCommonPublicationFields(Publication).
      opAuthor - optional (but recommended) Member to used to perform the create operation
      contextMap - optional Map to be used during performCreate operation (may be null)
      Returns:
      null if the FileDocument was not created, or the newly created instance if it was successful.
      Since:
      jcms-11.0.0
    • getDefaultPropertyValue

      public static String getDefaultPropertyValue(String propName)
    • validateImageProperty

      public static boolean validateImageProperty(String path)
      Ensures given image path target a file in the webapp.

      Only returns true if image file exists.

      Parameters:
      path - the image path to test file existence
      Returns:
      true if file exists
    • declarePublicMedia

      public static void declarePublicMedia(JProperties props, String allLoginPageFooter)
    • cleanPublicMedia

      public static void cleanPublicMedia(JProperties props)
    • updateLoginPageBackImage

      public static void updateLoginPageBackImage(JProperties props, String loginBackImage)
      Update login page background image.
      Image is an already known path in upload directory. This path has been declared as public-path for InitFilter.
      Parameters:
      props - Properties being modified
      loginBackImage - Login page background image filename
      Since:
      jcms-11.0.0
    • updateLoginPageLogo

      public static void updateLoginPageLogo(JProperties props, String loginPageLogo)
      Update public logo from chosen logo.
      Public logo is an already known path in upload directory. This path has been declared as public-path for InitFilter.
      Since public-paths are only read one time at startup, we use a final public path for logo, and update the file in case of modification.
      Parameters:
      props - Properties
      loginPageLogo - the new login page logo path
      Since:
      jcms-11.0.0
    • getTypeTemplateEntryFromSkin

      public static TypeTemplateEntry getTypeTemplateEntryFromSkin(String skinName)
    • getRealSkinName

      public static String getRealSkinName(String skinName)
    • getJMobileCss

      public static String getJMobileCss(String themeSelector, String topbarBackgroundColor, String topbarFontColor)
    • updateThemeAttribute

      public static String updateThemeAttribute(UITheme theme, boolean isPreview)
    • removeIsDelegatedCssClass

      public static String removeIsDelegatedCssClass()
    • closeGuidedTour

      public static String closeGuidedTour()
    • getDefaultThemeStyles

      public static Map<String,String> getDefaultThemeStyles()
    • getThemeFromUuid

      public static UITheme getThemeFromUuid(String uuid)
      Get the first Theme from uuid
      Parameters:
      uuid - the uuid to fetch
      Returns:
      the Theme which matches the uuid, null otherwise
    • showJMobileTab

      public static boolean showJMobileTab()
    • showNavigationTab

      public static boolean showNavigationTab()
    • extractFontFamilyFontUrl

      public static String extractFontFamilyFontUrl(String url)
    • getDefaultSkin

      public static String getDefaultSkin()
    • getThemeProperties

      public static JProperties getThemeProperties(UITheme theme)
    • getPagePreviewUrl

      public static String getPagePreviewUrl(String page)
    • getJMobilePreviewUrl

      public static String getJMobilePreviewUrl()
    • getLoginPagePreviewUrl

      public static String getLoginPagePreviewUrl(String loginPage)
    • getSkinPreviewUrl

      public static String getSkinPreviewUrl(String skin)
    • isValidThemeName

      public static boolean isValidThemeName(String name, String userLang)
    • createCSSThemeFile

      public static boolean createCSSThemeFile(UITheme theme, boolean isPreview)
    • activateTheme

      public static boolean activateTheme(UITheme theme)
    • getCSSThemeStyles

      public static String getCSSThemeStyles(UITheme theme, String themeSelector)
    • getThemeCSSMap

      public static Map<String,String> getThemeCSSMap(boolean isPreviewMode, boolean ignoreActiveTheme)
    • getDataThemeName

      public static String getDataThemeName(UITheme previewTheme)
    • decodeVariationBrandColor

      public static LinkedHashMap<Integer,String> decodeVariationBrandColor(String json)