Package com.jalios.jcms.theming
Class ThemingUtil
java.lang.Object
com.jalios.jcms.theming.ThemingUtil
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanactivateTheme(UITheme theme) static voidcleanPublicMedia(JProperties props) static Stringstatic booleancreateCSSThemeFile(UITheme theme, boolean isPreview) static booleancreateFile(String content, File file) static FileDocumentcreateFileDocumentFromTmpFile(File tmpFile, Member author) Creates a FileDocument from a temporary file, associating it with the specified author.static voiddeclarePublicMedia(JProperties props, String allLoginPageFooter) static LinkedHashMap<Integer, String> static voiddeleteFiles(File... files) Deletes the specified files.static Stringstatic FileDocumentfileToFileDocument(File file, FileDocument refFileDoc, Member opAuthor, Map<String, ? extends Object> contextMap) Creates a FileDocument from the specified file.Get All UITheme data sort by cdatestatic BooleanSettingsgetBooleanSettings(Object value, String name, Boolean defaultValue) Gets the settings for specifying a boolean value.static List<BreadcrumbItem> getBreadcrumbItems(String userLang, String currentThemeLabel) Retrieves a list of breadcrumb items for the Theming Tool application.static StringgetCardCorner(UITheme theme) Generates HTML code for a card corner based on the UI theme.static ColorSettingsgetColorSettings(Object value, String name) Gets the settings for specifying a color value.static StringgetCSSThemeStyles(UITheme theme, String themeSelector) static StringgetDataThemeAttribute(UITheme theme, boolean isPreview) Generates the data-theme attribute for the given theme, considering whether it is for preview purposes.static StringgetDataThemeName(UITheme previewTheme) static StringgetDefaultPropertyValue(String propName) static Stringstatic StringgetFileContent(File file) Reads the content of a file and returns it as a single String.static TextFieldSettingsgetFontSizeSettings(Object value, String name) Gets the settings for font size with a specified maximum length and "px" unit.static EnumerateSettingsgetFontWeightSettings(Object value, String name) Gets the settings for font weight (e.g., "normal," "bold") with a default value label.static StringgetJMobileCss(String themeSelector, String topbarBackgroundColor, String topbarFontColor) static Stringstatic EnumerateSettingsstatic EnumerateSettingsgetLoginPageModeSettings(Object value) static StringgetLoginPagePreviewUrl(String loginPage) static StringgetPagePreviewUrl(String page) static PublicationSettingsgetPortalSettings(Object value, Member mbr) Retrieves publication settings for a sample page.static StringgetPreviewThemeId(javax.servlet.http.HttpSession session) Retrieves the theme ID for preview mode from an HTTP servlet request.static StringgetRadiusValueWithUnit(Object radius) static StringgetRadiusValueWithUnit(String radius) AppendsThemeConstants.PIXEL_UNITto the given radius value, forming a complete radius string.static StringgetRealSkinName(String skinName) static StringgetSkinPreviewUrl(String skin) static UIThemeRetrieves a UItheme based on his ID.getThemeCSSMap(boolean isPreviewMode, boolean ignoreActiveTheme) static StringgetThemeCssSelector(UITheme theme) Generates a CSS selector for the given theme.static StringgetThemeCssSelector(UITheme theme, boolean isPreview) Generates a CSS selector based on class for the given theme, considering whether it is for preview purposes.static StringgetThemeCssSelector(String name, boolean isPreview) Generates a CSS selector based on class for the given theme, considering whether it is for preview purposes.static UIThemeDTOgetThemeFromFile(File themeFile) Retrieves a UItheme DTO from a theme file.static UIThemegetThemeFromUuid(String uuid) Get the first Theme from uuidstatic com.fasterxml.jackson.databind.ObjectMapperGet Jackson object Mapper for Theme classstatic JPropertiesgetThemeProperties(UITheme theme) static TypeTemplateEntrygetTypeTemplateEntryFromSkin(String skinName) static SelectSettingsgetUnderlineTypeSettings(Object value) static NumberSettingsgetWidthSettings(Object value, String name) Gets the settings for border width with a "px" unit and integer values.static booleanisValidThemeName(String name, String userLang) static Stringstatic booleanstatic booleanstatic voidupdateLoginPageBackImage(JProperties props, String loginBackImage) Update login page background image.
Image is an already known path in upload directory.static voidupdateLoginPageLogo(JProperties props, String loginPageLogo) Update public logo from chosen logo.
Public logo is an already known path in upload directory.static StringupdateThemeAttribute(UITheme theme, boolean isPreview) static booleanvalidateImageProperty(String path) Ensures given image path target a file in the webapp.
-
Field Details
-
WEBAPP_PATH
-
-
Constructor Details
-
ThemingUtil
public ThemingUtil()
-
-
Method Details
-
deleteFiles
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
- Parameters:
content- the text to write in the filefile- file path relative to the webapp- Returns:
- true if creation succeeded
-
getFileContent
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
Retrieves publication settings for a sample page. The chooser list all Portal, JPortal and PortalJSPCollection The member's rights are checked.- Parameters:
value- Current pagembr- The member for right checking.- Returns:
- PublicationSettings containing the list of available page.
-
getLoginPageModeSettings
-
getLoginPageBackgroundFitSettings
-
getWidthSettings
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
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
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
-
getColorSettings
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
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
Get All UITheme data sort by cdate- Returns:
- set of UITheme
- Since:
- jcms-11.0.0
-
getBreadcrumbItems
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
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
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
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
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
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
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
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
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
AppendsThemeConstants.PIXEL_UNITto 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
-
createFileDocumentFromTmpFile
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 locationrefFileDoc- optional FileDocument from which to retrieve fields value to be assigned to the newly created FileDocument. SeePublication.assignCommonPublicationFields(Publication).opAuthor- optional (but recommended) Member to used to perform the create operationcontextMap- 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
-
validateImageProperty
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
-
cleanPublicMedia
-
updateLoginPageBackImage
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 modifiedloginBackImage- Login page background image filename- Since:
- jcms-11.0.0
-
updateLoginPageLogo
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- PropertiesloginPageLogo- the new login page logo path- Since:
- jcms-11.0.0
-
getTypeTemplateEntryFromSkin
-
getRealSkinName
-
getJMobileCss
-
updateThemeAttribute
-
removeIsDelegatedCssClass
-
closeGuidedTour
-
getDefaultThemeStyles
-
getThemeFromUuid
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() -
extractFontFamilyFontUrl
-
getDefaultSkin
-
getThemeProperties
-
getPagePreviewUrl
-
getJMobilePreviewUrl
-
getLoginPagePreviewUrl
-
getSkinPreviewUrl
-
isValidThemeName
-
createCSSThemeFile
-
activateTheme
-
getCSSThemeStyles
-
getThemeCSSMap
-
getDataThemeName
-
decodeVariationBrandColor
-