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 Details

  • Constructor Details

  • Method Details

    • contextualize

      public void contextualize(Context context) throws ContextException
      Specified by:
      contextualize in interface Contextualizable
      Throws:
      ContextException
    • service

      public void service(ServiceManager manager) throws ServiceException
      Specified by:
      service in interface Serviceable
      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:
    • 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)
      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.
      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.
    • escapeURLforCSS

      public static String escapeURLforCSS(String url)
      Escape the given URL, meant to be used in eg. a background-image CSS style
      Parameters:
      url - the URL to escape
      Returns:
      the escaped URL
    • 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 string
      currentCharactersNumber - 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 login
      populationId - 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 email
      populationId - 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 right
      objectCtx - the context. Can be null to search on any context.
      Returns:
      true if the current user is allowed, false otherwise
    • isPluginEnabled

      public static boolean isPluginEnabled(String plugin)
      Check if a given plugin is enabled
      Parameters:
      plugin - the plugin's name.
      Returns:
      the plugin is enabled
    • pluginImageBase64

      public static String pluginImageBase64(String plugin, String path) throws MalformedURLException, IOException
      Computes the base 64 representation of the image at the specified path in the given plugin.
      Parameters:
      plugin - the plugin's name.
      path - the resource path.
      Returns:
      the base 64 encoding for the given resource.
      Throws:
      IOException - if an error occurs when trying to get the file
      MalformedURLException - if the url is invalid
    • _getResourceBase64

      protected static String _getResourceBase64(Source source)
      Get the base 64 encoding for the given source
      Parameters:
      source - the source
      Returns:
      the base 64 encoding of the source