Class CmsXmlContentPropertyHelper

  • All Implemented Interfaces:
    java.lang.Cloneable

    public final class CmsXmlContentPropertyHelper
    extends java.lang.Object
    implements java.lang.Cloneable
    Provides common methods on XML property configuration.

    Since:
    8.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String PAGE_PROPERTY_PREFIX
      The prefix for macros used to acess properties of the current container page.
      protected static java.lang.Object PROPERTY_EMPTY_MARKER
      If a property has this value, the page-property macro for this property will expand to the empty string instead.
    • Field Detail

      • PROPERTY_EMPTY_MARKER

        protected static final java.lang.Object PROPERTY_EMPTY_MARKER
        If a property has this value, the page-property macro for this property will expand to the empty string instead.
    • Method Detail

      • convertPropertiesToClientFormat

        public static java.util.Map<java.lang.String,​java.lang.String> convertPropertiesToClientFormat​(CmsObject cms,
                                                                                                             java.util.Map<java.lang.String,​java.lang.String> props,
                                                                                                             java.util.Map<java.lang.String,​CmsXmlContentProperty> propConfig)
        Converts a map of properties from server format to client format.

        Parameters:
        cms - the CmsObject to use for VFS operations
        props - the map of properties
        propConfig - the property configuration
        Returns:
        the converted property map
      • convertPropertiesToServerFormat

        public static java.util.Map<java.lang.String,​java.lang.String> convertPropertiesToServerFormat​(CmsObject cms,
                                                                                                             java.util.Map<java.lang.String,​java.lang.String> props,
                                                                                                             java.util.Map<java.lang.String,​CmsXmlContentProperty> propConfig)
        Converts a map of properties from client format to server format.

        Parameters:
        cms - the CmsObject to use for VFS operations
        props - the map of properties
        propConfig - the property configuration
        Returns:
        the converted property map
      • copyPropertyConfiguration

        public static java.util.Map<java.lang.String,​CmsXmlContentPropertycopyPropertyConfiguration​(java.util.Map<java.lang.String,​CmsXmlContentProperty> propConfig)
        Creates a deep copy of a property configuration map.

        Parameters:
        propConfig - the property configuration which should be copied
        Returns:
        a copy of the property configuration
      • getIdForUri

        public static CmsUUID getIdForUri​(CmsObject cms,
                                          java.lang.String uri)
                                   throws CmsException
        Looks up an URI in the sitemap and returns either a sitemap entry id (if the URI is a sitemap URI) or the structure id of a resource (if the URI is a VFS path).

        Parameters:
        cms - the current CMS context
        uri - the URI to look up
        Returns:
        a sitemap entry id or a structure id
        Throws:
        CmsException - if something goes wrong
      • getMacroResolverForProperties

        public static CmsMacroResolver getMacroResolverForProperties​(CmsObject cms,
                                                                     I_CmsXmlContentHandler contentHandler,
                                                                     CmsXmlContent content,
                                                                     java.util.function.Function<java.lang.String,​java.lang.String> stringtemplateSource,
                                                                     CmsResource containerPage)
        Creates and configures a new macro resolver for resolving macros which occur in property definitions.

        Parameters:
        cms - the CMS context
        contentHandler - the content handler which contains the message bundle that should be available in the macro resolver
        content - the XML content object
        stringtemplateSource - provides stringtemplate templates for use in %(stringtemplate:...) macros
        containerPage - the current container page
        Returns:
        a new macro resolver
      • getPropValueIds

        public static java.lang.String getPropValueIds​(CmsObject cms,
                                                       java.lang.String type,
                                                       java.lang.String value)
        Returns a converted property value depending on the given type.

        If the type is CmsXmlContentProperty.PropType.vfslist, the value is parsed as a list of paths and converted to a list of IDs.

        Parameters:
        cms - the current CMS context
        type - the property type
        value - the raw property value
        Returns:
        a converted property value depending on the given type
      • getPropValuePaths

        public static java.lang.String getPropValuePaths​(CmsObject cms,
                                                         java.lang.String type,
                                                         java.lang.String value)
        Returns a converted property value depending on the given type.

        If the type is CmsXmlContentProperty.PropType.vfslist, the value is parsed as a list of IDs and converted to a list of paths.

        Parameters:
        cms - the current CMS context
        type - the property type
        value - the raw property value
        Returns:
        a converted property value depending on the given type
      • getUriForId

        public static java.lang.String getUriForId​(CmsObject cms,
                                                   CmsUUID id)
                                            throws CmsException
        Returns a sitemap or VFS path given a sitemap entry id or structure id.

        This method first tries to read a sitemap entry with the given id. If this succeeds, the sitemap entry's sitemap path will be returned. If it fails, the method interprets the id as a structure id and tries to read the corresponding resource, and then returns its VFS path.

        Parameters:
        cms - the CMS context
        id - a sitemap entry id or structure id
        Returns:
        a sitemap or VFS uri
        Throws:
        CmsException - if something goes wrong
      • getWidgetConfigurationAsJSON

        public static JSONObject getWidgetConfigurationAsJSON​(java.lang.String widgetConfiguration)
        Returns the widget configuration string parsed into a JSONObject.

        The configuration string should be a map of key value pairs separated by ':' and '|': KEY_1:VALUE_1|KEY_2:VALUE_2 ...

        Parameters:
        widgetConfiguration - the configuration to parse
        Returns:
        the configuration JSON
      • mergeDefaults

        public static java.util.Map<java.lang.String,​java.lang.String> mergeDefaults​(CmsObject cms,
                                                                                           CmsADEConfigData config,
                                                                                           CmsResource resource,
                                                                                           java.util.Map<java.lang.String,​java.lang.String> properties,
                                                                                           java.util.Locale locale,
                                                                                           javax.servlet.ServletRequest request)
        Extends the given properties with the default values from the resource's property configuration.

        Parameters:
        cms - the current CMS context
        config - the current sitemap configuration
        resource - the resource to get the property configuration from
        properties - the properties to extend
        locale - the content locale
        request - the current request, if available
        Returns:
        a merged map of properties
      • mergeDefaults

        public static java.util.Map<java.lang.String,​java.lang.String> mergeDefaults​(CmsObject cms,
                                                                                           java.util.Map<java.lang.String,​CmsXmlContentProperty> propertyConfig,
                                                                                           java.util.Map<java.lang.String,​java.lang.String> properties)
        Extends the given properties with the default values from property configuration.

        Parameters:
        cms - the current CMS context
        propertyConfig - the property configuration
        properties - the properties to extend
        Returns:
        a merged map of properties
      • readProperties

        public static java.util.Map<java.lang.String,​java.lang.String> readProperties​(CmsObject cms,
                                                                                            I_CmsXmlContentLocation baseLocation)
        Reads property nodes from the given location.

        Parameters:
        cms - the current cms context
        baseLocation - the base location
        Returns:
        the properties
      • readProperties

        public static java.util.Map<java.lang.String,​java.lang.String> readProperties​(CmsXmlContent xmlContent,
                                                                                            java.util.Locale locale,
                                                                                            org.dom4j.Element element,
                                                                                            java.lang.String elemPath,
                                                                                            CmsXmlContentDefinition elemDef)
        Reads the properties from property-enabled xml content values.

        Parameters:
        xmlContent - the xml content
        locale - the current locale
        element - the xml element
        elemPath - the xpath
        elemDef - the element definition
        Returns:
        the read property map
        See Also:
        CmsXmlContainerPage.XmlNode.Elements
      • resolveMacrosForPropertyInfo

        public static java.util.Map<java.lang.String,​CmsXmlContentPropertyresolveMacrosForPropertyInfo​(CmsObject cms,
                                                                                                               CmsResource page,
                                                                                                               CmsResource resource,
                                                                                                               com.google.common.base.Supplier<CmsXmlContent> contentGetter,
                                                                                                               java.util.function.Function<java.lang.String,​java.lang.String> stringtemplateSource,
                                                                                                               java.util.Map<java.lang.String,​CmsXmlContentProperty> propertiesConf)
                                                                                                        throws CmsException
        Resolves macros in the given property information for the given resource (type) AND the current user.

        Parameters:
        cms - the current CMS context
        page - the current container page
        resource - the resource
        contentGetter - loads the actual content
        stringtemplateSource - provider for stringtemplate templates
        propertiesConf - the property information
        Returns:
        the property information
        Throws:
        CmsException - if something goes wrong
      • resolveMacrosInProperties

        public static java.util.Map<java.lang.String,​CmsXmlContentPropertyresolveMacrosInProperties​(java.util.Map<java.lang.String,​CmsXmlContentProperty> properties,
                                                                                                            I_CmsMacroResolver resolver)
        Resolves macros in all properties in a map.

        Parameters:
        properties - the map of properties in which macros should be resolved
        resolver - the macro resolver to use
        Returns:
        a new map of properties with resolved macros
      • saveProperties

        public static void saveProperties​(CmsObject cms,
                                          org.dom4j.Element parentElement,
                                          java.util.Map<java.lang.String,​java.lang.String> properties,
                                          java.util.Map<java.lang.String,​CmsXmlContentProperty> propertiesConf,
                                          boolean sort)
        Saves the given properties to the given xml element.

        Parameters:
        cms - the current CMS context
        parentElement - the parent xml element
        properties - the properties to save, if there is a list of resources, every entry can be a site path or a UUID
        propertiesConf - the configuration of the properties
        sort - if true, properties will be sorted by map keys via string co
      • addFileListPropertyValue

        protected static void addFileListPropertyValue​(CmsObject cms,
                                                       org.dom4j.Element valueElement,
                                                       java.lang.String propValue)
        Adds the XML for a property value of a property of type 'vfslist' to the DOM.

        Parameters:
        cms - the current CMS context
        valueElement - the element to which the vfslist property value should be added
        propValue - the property value which should be saved
      • convertIdsToPaths

        protected static java.lang.String convertIdsToPaths​(CmsObject cms,
                                                            java.lang.String value)
        Converts a string containing zero or more structure ids into a string containing the corresponding VFS paths.

        Parameters:
        cms - the CmsObject to use for the VFS operations
        value - a string representation of a list of ids
        Returns:
        a string representation of a list of paths
      • convertPathsToIds

        protected static java.lang.String convertPathsToIds​(CmsObject cms,
                                                            java.lang.String value)
        Converts a string containing zero or more VFS paths into a string containing the corresponding structure ids.

        Parameters:
        cms - the CmsObject to use for the VFS operations
        value - a string representation of a list of paths
        Returns:
        a string representation of a list of ids
      • convertProperties

        protected static java.util.Map<java.lang.String,​java.lang.String> convertProperties​(CmsObject cms,
                                                                                                  java.util.Map<java.lang.String,​java.lang.String> props,
                                                                                                  java.util.Map<java.lang.String,​CmsXmlContentProperty> propConfig,
                                                                                                  boolean toClient)
        Helper method for converting a map of properties from client format to server format or vice versa.

        Parameters:
        cms - the CmsObject to use for VFS operations
        props - the map of properties
        propConfig - the property configuration
        toClient - if true, convert from server to client, else from client to server
        Returns:
        the converted property map
      • convertStringPropertyValue

        protected static java.lang.String convertStringPropertyValue​(CmsObject cms,
                                                                     java.lang.String propValue,
                                                                     java.lang.String type,
                                                                     boolean toClient)
        Converts a property value given as a string between server format and client format.

        Parameters:
        cms - the current CMS context
        propValue - the property value to convert
        type - the type of the property
        toClient - if true, convert to client format, else convert to server format
        Returns:
        the converted property value
      • getFileValueForIdOrUri

        protected static CmsVfsFileValueBean getFileValueForIdOrUri​(CmsObject cms,
                                                                    java.lang.String idOrUri)
                                                             throws CmsException
        Given a string which might be a id or a (sitemap or VFS) URI, this method will return a bean containing the right (sitemap or vfs) root path and (sitemap entry or structure) id.

        Parameters:
        cms - the current CMS context
        idOrUri - a string containing an id or an URI
        Returns:
        a bean containing a root path and an id
        Throws:
        CmsException - if something goes wrong
      • getPropertyConfig

        protected static CmsXmlContentProperty getPropertyConfig​(java.util.Map<java.lang.String,​CmsXmlContentProperty> propertyConfig,
                                                                 java.lang.String propName)
        Helper method for accessing the property configuration for a single property.

        This method uses the base name of the property to access the property configuration, i.e. if propName starts with a '#', the part after the '#' will be used as the key for the property configuration.

        Parameters:
        propertyConfig - the property configuration map
        propName - the name of a property
        Returns:
        the property configuration for the given property name