Package org.ametys.core.util
Class AmetysXSLTHelper
- java.lang.Object
-
- org.ametys.core.util.AmetysXSLTHelper
-
- All Implemented Interfaces:
Contextualizable
,Serviceable
- Direct Known Subclasses:
AmetysXSLTHelper
public class AmetysXSLTHelper extends Object implements Contextualizable, Serviceable
Helper component to be used from XSL stylesheets.
-
-
Field Summary
Fields Modifier and Type Field Description private static Context
_context
protected static CurrentUserProvider
_currentUserProvider
The current user providerprotected static GroupManager
_groupManager
The groups managerprotected static I18nUtils
_i18nUtils
The i18n utils instanceprotected static JSONUtils
_jsonUtils
The json utilsprotected static org.slf4j.Logger
_LOGGER
The loggerprotected static RightManager
_rightManager
The right managerprotected static UserHelper
_userHelper
The user helperprotected static VersionsHandler
_versionHandler
The versions handler
-
Constructor Summary
Constructors Constructor Description AmetysXSLTHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
absoluteUriPrefix()
Returns the absolute URI prefix.static String
absoluteUriPrefix(boolean withWorkspaceURI)
Returns the absolute URI prefix.static Object
config(String id)
Returns the configuration value associated with the given parameter.void
contextualize(Context context)
static String
escapeJS(String str)
Escape the given string to be used as JS variable.protected static String
getAbsoluteUriPrefix(boolean withWorkspaceURI)
Get the absolutized version of the context path.protected static String
getUriPrefix(boolean withWorkspaceURI)
Get the application context path.static String
getValueFromJsonObject(String jsonString, String key)
Parse a JSON string as a Map and return the value with the desired keyprotected static String
getWorkspaceName()
Return the current workspace nameprotected static String
getWorkspacePrefix()
Return the current workspace URIstatic NodeList
groups()
Returns the list of the current user's groups.static NodeList
groups(String userIdentity)
Returns the of the given user's group.static NodeList
groups(String login, String populationId)
Returns the of the given user's group.static boolean
hasRight(String rightId, String objectCtx)
Determines if the current logged user has right on a String contextstatic boolean
isDeveloperMode()
Get the current mode of the application for the current user.static String
requestParameter(String parameter)
Return the value of a request parameter.void
service(ServiceManager manager)
static String
splitText(String textToSplit, String tokenizers, int startIndex)
Split the text.static String
splitText(String textToSplit, String tokenizers, int maxCharacters, int currentCharactersNumber)
Deprecated.static String
translate(String key)
Translate an i18n key using current user language.static String
translate(String key, String lang, NodeList parameters)
Translate an i18n keystatic String
uriPrefix()
Returns the current URI prefix.static String
uriPrefix(boolean withWorkspaceURI)
Returns the current URI prefix.static Node
user()
Return the userstatic Node
user(String userIdentity)
Return the given userstatic Node
user(String login, String populationId)
Return the given userstatic Node
userByMail(String email, String populationId)
Return the given userstatic Node
versions()
Get the versions of the application.static String
workspaceName()
Return the current workspace namestatic String
workspacePrefix()
Return the current workspace URIstatic String
workspaceTheme()
Return the current workspace theme namestatic String
workspaceThemeURL()
Return the current workspace theme url
-
-
-
Field Detail
-
_LOGGER
protected static final org.slf4j.Logger _LOGGER
The logger
-
_i18nUtils
protected static I18nUtils _i18nUtils
The i18n utils instance
-
_versionHandler
protected static VersionsHandler _versionHandler
The versions handler
-
_currentUserProvider
protected static CurrentUserProvider _currentUserProvider
The current user provider
-
_groupManager
protected static GroupManager _groupManager
The groups manager
-
_userHelper
protected static UserHelper _userHelper
The user helper
-
_jsonUtils
protected static JSONUtils _jsonUtils
The json utils
-
_rightManager
protected static RightManager _rightManager
The right manager
-
-
Constructor Detail
-
AmetysXSLTHelper
public AmetysXSLTHelper()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
uriPrefix
public static String uriPrefix()
Returns the current URI prefix.- Returns:
- the current URI prefix.
-
uriPrefix
public static String uriPrefix(boolean withWorkspaceURI)
Returns the current URI prefix.- Parameters:
withWorkspaceURI
- true to add the workspace URI (recommended)- Returns:
- the current URI prefix.
-
absoluteUriPrefix
public static String absoluteUriPrefix()
Returns the absolute URI prefix.- Returns:
- the absolute URI prefix.
-
absoluteUriPrefix
public static String absoluteUriPrefix(boolean withWorkspaceURI)
Returns the absolute URI prefix.- Parameters:
withWorkspaceURI
- true to add the workspace URI (recommended)- Returns:
- the absolute URI prefix.
-
workspaceName
public static String workspaceName()
Return the current workspace name- Returns:
- The workspace name. Cannot be empty.
-
workspacePrefix
public static String workspacePrefix()
Return the current workspace URI- Returns:
- The workspace name. Can be empty.
-
workspaceTheme
public static String workspaceTheme()
Return the current workspace theme name- Returns:
- The name
-
workspaceThemeURL
public static String workspaceThemeURL()
Return the current workspace theme url- Returns:
- The url without any prefix
-
getUriPrefix
protected static String getUriPrefix(boolean withWorkspaceURI)
Get the application context path. Can be empty if the application resides in the root context. Use it to create a link beginning with the application root.- Parameters:
withWorkspaceURI
- true to add the workspace URI (recommended)- Returns:
- The application context path with workspace URI
- See Also:
Request.getContextPath()
-
getAbsoluteUriPrefix
protected static String getAbsoluteUriPrefix(boolean withWorkspaceURI)
Get the absolutized version of the context path. Use it to create an absolute link beginning with the application root, for instance when sending a mail linking to the application.- Parameters:
withWorkspaceURI
- true to add the workspace URI (recommended)- Returns:
- The absolute context path.
-
getWorkspaceName
protected static String getWorkspaceName()
Return the current workspace name- Returns:
- The workspace name. Cannot be empty.
-
getWorkspacePrefix
protected static String getWorkspacePrefix()
Return the current workspace URI- Returns:
- The workspace name. Can be empty for the default workspace.
-
config
public static Object config(String id)
Returns the configuration value associated with the given parameter.- Parameters:
id
- the configuration parameter.- Returns:
- the configuration value associated with the given parameter.
-
requestParameter
public static String requestParameter(String parameter)
Return the value of a request parameter.- Parameters:
parameter
- the parameter name.- Returns:
- the request parameter.
-
translate
public static String translate(String key)
Translate an i18n key using current user language.- Parameters:
key
- The key to translate. Specify the catalog this way: "catalogue:KEY"- Returns:
- The translation or null.
-
translate
public static String translate(String key, String lang, NodeList parameters)
Translate an i18n key- Parameters:
key
- The key to translate. Specify the catalog this way: "catalogue:KEY"lang
- The language. Can be null to use current user language.parameters
- The key parameters. Can be empty.- Returns:
- The translation or null.
-
escapeJS
public static String escapeJS(String str)
Escape the given string to be used as JS variable.- Parameters:
str
- the string to escape.- Returns:
- the escaped String.
-
splitText
public static String splitText(String textToSplit, String tokenizers, int startIndex)
Split the text.- Parameters:
textToSplit
- the text to split.tokenizers
- the tokenizer characters.startIndex
- the minimum number of characters of the result string- Returns:
- the split text.
-
splitText
@Deprecated public static String splitText(String textToSplit, String tokenizers, int maxCharacters, int currentCharactersNumber)
Deprecated.Split the text.- Parameters:
textToSplit
- the text to split.tokenizers
- the tokenizer characters.maxCharacters
- the maximum number of characters of the result stringcurrentCharactersNumber
- the current character number.- Returns:
- the split text.
-
versions
public static Node versions()
Get the versions of the application. Default VersionsHandler impl will return Ametys and Application versions- Returns:
- The versions <Version><Version><Name>X</Name><Version>X</Version><Date>X</Date></Version></Versions> (empty tags are removed)
-
isDeveloperMode
public static boolean isDeveloperMode()
Get the current mode of the application for the current user.- Returns:
- True if the application is in developer mode, false if in production mode.
-
user
public static Node user() throws SAXException
Return the user- Returns:
- The current connected user object or null
- Throws:
SAXException
- if a problem occured while getting the user
-
user
public static Node user(String userIdentity) throws SAXException
Return the given user- Parameters:
userIdentity
- the concerned user's login + population- Returns:
- The informations about the given user
- Throws:
SAXException
- If an error occurred while saxing the user
-
user
public static Node user(String login, String populationId) throws SAXException
Return the given user- Parameters:
login
- the concerned user's loginpopulationId
- the concerned user's population id- Returns:
- The informations about the given user
- Throws:
SAXException
- If an error occurred while saxing the user
-
userByMail
public static Node userByMail(String email, String populationId) throws SAXException
Return the given user- Parameters:
email
- the concerned user's emailpopulationId
- the concerned user's population id- Returns:
- The informations about the given user
- Throws:
SAXException
- If an error occurred while saxing the user
-
groups
public static NodeList groups()
Returns the list of the current user's groups.- Returns:
- the list of the current user's groups. Can be null if there is no connected user.
-
groups
public static NodeList groups(String userIdentity)
Returns the of the given user's group.- Parameters:
userIdentity
- the concerned user's login + population- Returns:
- the of the given user's group.
-
groups
public static NodeList groups(String login, String populationId)
Returns the of the given user's group.- Parameters:
login
- the concerned user's login.populationId
- the concerned user's population.- Returns:
- the of the given user's group.
-
getValueFromJsonObject
public static String getValueFromJsonObject(String jsonString, String key)
Parse a JSON string as a Map and return the value with the desired key- Parameters:
jsonString
- the JSON representation of the object.key
- name of the value to return- Returns:
- the value as a String, or empty string if an error occurred or the key was not found.
-
hasRight
public static boolean hasRight(String rightId, String objectCtx)
Determines if the current logged user has right on a String context- Parameters:
rightId
- The id of rightobjectCtx
- the context. Can be null to search on any context.- Returns:
- true if the current user is allowed, false otherwise
-
-