Class AmetysXSLTHelper

java.lang.Object
org.ametys.core.util.AmetysXSLTHelper
org.ametys.cms.transformation.xslt.AmetysXSLTHelper
All Implemented Interfaces:
Contextualizable, LogEnabled, Serviceable
Direct Known Subclasses:
AmetysXSLTHelper

public class AmetysXSLTHelper extends AmetysXSLTHelper implements LogEnabled
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
      Overrides:
      contextualize in class AmetysXSLTHelper
      Throws:
      ContextException
    • enableLogging

      public void enableLogging(Logger logger)
      Specified by:
      enableLogging in interface LogEnabled
    • service

      public void service(ServiceManager manager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Overrides:
      service in class AmetysXSLTHelper
      Throws:
      ServiceException
    • contentTypes

      public static NodeList contentTypes(String contentId)
      Get the content types of a content
      Parameters:
      contentId - The content id
      Returns:
      The content type or empty if the content does not exist
    • contentMixinTypes

      public static NodeList contentMixinTypes(String contentId)
      Get the mixins of a content
      Parameters:
      contentId - The content id
      Returns:
      The content type or empty if the content does not exist
    • isReferenceTableContent

      public static boolean isReferenceTableContent(String contentId)
      Determines if the content of given id is a entry of reference table
      Parameters:
      contentId - the content id
      Returns:
      true if the content type is a reference table
    • lang

      public static String lang()
      Returns the current language for rendering.
      Returns:
      the current language for rendering.
    • hasValue

      public static boolean hasValue(String contentId, String dataPath)
      Determines if there is a non-empty value for the data at the given path
      Parameters:
      contentId - The content id
      dataPath - the path of data
      Returns:
      true if the data exists
    • contentAttribute

      public static NodeList contentAttribute(String contentId, String dataPath)
      Get the attribute of a content at the given path
      Parameters:
      contentId - The content id
      dataPath - The data path
      Returns:
      The value into a "value" node or null if an error occurred
    • contentAttribute

      public static NodeList contentAttribute(String contentId, String dataPath, String lang)
      Get the attribute of a content at the given path
      Parameters:
      contentId - The content id
      dataPath - The data path
      lang - The language for localized attribute. Can be null for non-localized attribute or to get the values for all existing locales.
      Returns:
      The value into a "value" node or null if an error occurred
    • _getNodeValues

      protected static List<Node> _getNodeValues(ModelAwareDataHolder dataHolder, String dataPath, String lang)
      Get values of an attribute of a model aware data holder at the given path
      Parameters:
      dataHolder - the data holder
      dataPath - The data path
      lang - The language for localized attribute. Can be null for non-localized attribute or to get the values for all existing locales.
      Returns:
      A Node for each values or null if an error occurred
    • _getNodeValues

      protected static List<Node> _getNodeValues(ModelAwareDataHolder dataHolder, String dataPath, String lang, DataContext dataContext)
      Get values of an attribute of a model aware data holder at the given path
      Parameters:
      dataHolder - the data holder
      dataPath - The data path
      lang - The language for localized attribute. Can be null for non-localized attribute or to get the values for all existing locales.
      dataContext - The data context
      Returns:
      A Node for each values or null if an error occurred
    • contentMetadata

      public static String contentMetadata(String contentId, String metadataName, String lang)
      Get the metadata of a content
      Parameters:
      contentId - The content id
      metadataName - The metadata name (/ for composite)
      lang - The language for localized metadata. Can be null to get the current language.
      Returns:
      The name or empty if the metadata or the content does not exist
    • contentMetadata

      public static String contentMetadata(String contentId, String metadataName)
      Get the metadata of a content
      Parameters:
      contentId - The content id
      metadataName - The metadata name (/ for composite)
      Returns:
      The name or empty if the metadata or the content does not exist
    • contentAttachments

      public static Node contentAttachments()
      Returns a DOM Element containing Resources representing the attachments of the current content.
      Returns:
      an Element containing the attachments of the current content as Resources.
    • contentAttachments

      public static Node contentAttachments(String contentId)
      Returns a DOM Element containing Resources representing the attachments of a given content.
      Parameters:
      contentId - the content ID.
      Returns:
      an Element containing the attachments of the given content as Resources.
    • setCurrentContent

      public static void setCurrentContent(String contentId)
      Set the content of given id in request attribute
      Parameters:
      contentId - the id of content
    • setCurrentContent

      public static void setCurrentContent(String contentId, String versionLabel)
      Set the content of given id and version in request attribute
      Parameters:
      contentId - the id of content
      versionLabel - The version label
    • contentTags

      public static NodeList contentTags()
      Returns all tags of the current content.
      Returns:
      a list of tags.
    • contentTags

      public static NodeList contentTags(String contentId)
      Returns all tags of the given content
      Parameters:
      contentId - The identifier of the content
      Returns:
      a list of tags.
    • _contentTags

      protected static NodeList _contentTags(Content content)
      Returns all tags of the given content
      Parameters:
      content - The content
      Returns:
      a list of tags.
    • tagParent

      public static String tagParent(String siteName, String tagName)
      Get the name of the parent of a tag.
      Parameters:
      siteName - the site name
      tagName - the tag's name
      Returns:
      The id of parent or empty if not found
    • tagPath

      public static String tagPath(String siteName, String tagName)
      Get the path of a tag. The path contains the tag's parents seprated by '/'.
      Parameters:
      siteName - The site name
      tagName - The unique tag's name
      Returns:
      The tag's path or empty string if tag does not exist
    • tagLabel

      public static String tagLabel(String siteName, String tagName, String lang)
      Get the label of a tag
      Parameters:
      siteName - the current site
      tagName - the name of the tag
      lang - the lang (if i18n tag)
      Returns:
      the label of the tag or empty if it cannot be found
    • tagDescription

      public static String tagDescription(String siteName, String tagName, String lang)
      Get the description of a tag
      Parameters:
      siteName - the current site
      tagName - the name of the tag
      lang - the lang (if i18n tag)
      Returns:
      the label of the tag or empty if it cannot be found
    • tagVisibility

      public static String tagVisibility(String siteName, String tagName)
      Get the visibility of a tag
      Parameters:
      siteName - the current site
      tagName - the name of the tag
      Returns:
      the lower-cased visibility of the tag ("public" or "private")
    • tagColor

      public static MapElement tagColor(String siteName, String tagName)
      Get the color (main and text) of a tag
      Parameters:
      siteName - the current site
      tagName - the name of the tag
      Returns:
      the the color (main and text) of a tag
    • contentTypeTags

      public static NodeList contentTypeTags(String contentTypeId)
      Returns all tags of a content type
      Parameters:
      contentTypeId - The id of the content type
      Returns:
      a list of tags.
    • contentExcerpt

      public static String contentExcerpt(String contentId, String attributePath, int limit)
      Get the excerpt of content from the given richtext attribute
      Parameters:
      contentId - the id of content
      attributePath - the attribute path of rich text attribute
      limit - the max length for content excerpt
      Returns:
      the excerpt
    • getContentView

      public static Node getContentView(String contentId)
      Get the HTML view of a content
      Parameters:
      contentId - the id of content
      Returns:
      the content html view wrapped into a <content> tag
    • getContentView

      public static Node getContentView(String contentId, int startHeadingsLevel)
      Get the HTML view of a content with offset on headings
      Parameters:
      contentId - the id of content
      startHeadingsLevel - The start level for headings (h1, h2, h3, ...). For example, set to 2 so that the highest level headings are <h2>. Set to 1 for no offset.
      Returns:
      the content html view wrapped into a <content> tag
    • getContentView

      public static Node getContentView(String contentId, String viewName)
      Get the HTML view of a content
      Parameters:
      contentId - the id of content
      viewName - The content view name
      Returns:
      the content html view wrapped into a <content> tag
    • getContentView

      public static Node getContentView(String contentId, String viewName, int startHeadingsLevel)
      Get the HTML view of a content
      Parameters:
      contentId - the id of content
      viewName - The content view name
      startHeadingsLevel - The start level for headings (h1, h2, h3, ...). For example, set to 2 so that the highest level headings are <h2>. Set to 1 for no offset.
      Returns:
      the content html view wrapped into a <content> tag
    • getContentView

      public static Node getContentView(String contentId, String viewName, int startHeadingsLevel, String lang, boolean checkReadAccess)
      Get the HTML view of a content with offset on headings
      Parameters:
      contentId - the id of content
      viewName - The content view name
      lang - the language. Can be null. Useful only if the content has a multilingual title.
      startHeadingsLevel - The start level for headings (h1, h2, h3, ...). For example, set to 2 so that the highest level headings are <h2>. Set to 1 for no offset.
      checkReadAccess - Set to true to check the read access on content. Be careful, do not use with true on a cacheable element.
      Returns:
      the content html view wrapped into a <content> tag