Class Config


  • public class Config
    extends java.lang.Object
    The config properties of a resource.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DATASOURCE
      The resource name for datasource config ("datasource").
      static java.lang.String DEFAULTS
      The resource name for the defaults config ("defaults").
      static java.lang.String ITEMS
      The resource name for items ("items").
      static java.lang.String LAYOUT
      The resource name for layout config ("layout").
      static java.lang.String RENDERCONDITION
      The resource name for render condition config ("rendercondition").
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String get​(java.lang.String name)
      Returns the value of property with the given name, converted to string.
      <T> T get​(java.lang.String name, java.lang.Class<T> type)
      Returns the value of property with the given name, converted into the given type.
      <T> T get​(java.lang.String name, T defaultValue)
      Returns the value of property with the given name, converted into the given type.
      Resource getChild​(java.lang.String name)
      Returns the child resource with the given name.
      ValueMap getDefaultProperties()
      Returns the default properties that will be applied to child elements.
      java.lang.String getInherited​(java.lang.String name)
      Returns the value of property with the given name, converted to string.
      <T> T getInherited​(java.lang.String name, java.lang.Class<T> type)
      Returns the value of property with the given name, converted into the given type.
      <T> T getInherited​(java.lang.String name, T defaultValue)
      Returns the value of property with the given name, converted into the given type.
      java.lang.String getInheritedDefault​(java.lang.String name)
      Alias of get(String).
      <T> T getInheritedDefault​(java.lang.String name, java.lang.Class<T> type)
      <T> T getInheritedDefault​(java.lang.String name, T defaultValue)
      java.util.Iterator<Resource> getItems()
      Returns the child resources of ITEMS sub-resource.
      java.util.Iterator<Resource> getItems​(java.lang.String name)
      Returns the child resources of the sub-resource with the given name.
      java.util.Iterator<Resource> getItems​(Resource resource)
      Returns the child resources of ITEMS sub-resource of the given resource.
      java.util.Iterator<Resource> getItems​(Resource resource, java.lang.String name)
      Returns the child resources of the sub resource with the given name of the given resource.
      Resource getParentResource()
      Returns the parent of the resource.
      ValueMap getProperties()
      Returns the properties of the resource merged with the default properties.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULTS

        @Nonnull
        public static java.lang.String DEFAULTS
        The resource name for the defaults config ("defaults").
      • ITEMS

        @Nonnull
        public static java.lang.String ITEMS
        The resource name for items ("items").
      • LAYOUT

        @Nonnull
        public static java.lang.String LAYOUT
        The resource name for layout config ("layout").
      • DATASOURCE

        @Nonnull
        public static java.lang.String DATASOURCE
        The resource name for datasource config ("datasource").
      • RENDERCONDITION

        @Nonnull
        public static java.lang.String RENDERCONDITION
        The resource name for render condition config ("rendercondition").
    • Constructor Detail

      • Config

        public Config​(@CheckForNull
                      Resource resource,
                      boolean inherit)
        Create a new Config object for the given resource. If inherit is true, the default properties are setup and taken from the parent's DEFAULTS sub-resource, and parent properties are used when calling getInherited(String, Class).
        Parameters:
        resource - The resource
        inherit - Whether to inherit default properties or not
        See Also:
        getParentResource()
      • Config

        public Config​(@CheckForNull
                      Resource resource,
                      @CheckForNull
                      ValueMap defaults,
                      @CheckForNull
                      ValueMap parentProperties)
        Create a new Config object for the given resource.
        Parameters:
        resource - The resource
        defaults - The default properties. Pass null if these are not required.
        parentProperties - The properties of the parent resource. Pass null if these are not required.
    • Method Detail

      • get

        @Nonnull
        public java.lang.String get​(@Nonnull
                                    java.lang.String name)
        Returns the value of property with the given name, converted to string. If the property does not exist it is taken from the defaults. Return an empty string if still not existing can't be converted.
        Parameters:
        name - the name of the property
        Returns:
        the value of property with the given name, converted to string
      • get

        @Nonnull
        public <T> T get​(@Nonnull
                         java.lang.String name,
                         @Nonnull
                         T defaultValue)
        Returns the value of property with the given name, converted into the given type. If the property does not exist it is taken from the defaults. Return the given defaultValue if still non existing or can't be converted.
        Type Parameters:
        T - The type of the default value
        Parameters:
        name - The name of the property
        defaultValue - The default value to use if the named property does not exist or cannot be converted to the requested type. The default value is also used to define the type to convert the value to. If this is null any existing property is not converted.
        Returns:
        The value of property with the given name, converted into the given type
      • get

        @CheckForNull
        public <T> T get​(@Nonnull
                         java.lang.String name,
                         @Nonnull
                         java.lang.Class<T> type)
        Returns the value of property with the given name, converted into the given type. If the property does not exist, it is taken from the defaults. Return null if non existing or can't be converted.
        Type Parameters:
        T - The type of the submitted type param
        Parameters:
        name - The name of the property
        type - The type to convert the value of the given property name to
        Returns:
        The value of property with the given name, converted into the given type
      • getInherited

        @Nonnull
        public java.lang.String getInherited​(@Nonnull
                                             java.lang.String name)
        Returns the value of property with the given name, converted to string. If the property does not exist, it is taken from the parent properties. Return an empty string if still not existing can't be converted.
        Parameters:
        name - The name of the property
        Returns:
        The value of property with the given name, converted to string.
        See Also:
        getParentResource()
      • getInherited

        @Nonnull
        public <T> T getInherited​(@Nonnull
                                  java.lang.String name,
                                  @Nonnull
                                  T defaultValue)
        Returns the value of property with the given name, converted into the given type. If the property does not exist, it is taken from the parent properties. Return the given defaultValue if still non existing or can't be converted.
        Type Parameters:
        T - The type to convert the value of the property to
        Parameters:
        name - The name of the property
        defaultValue - The default value to use if the named property does not exist or cannot be converted to the requested type. The default value is also used to define the type to convert the value to. If this is null any existing property is not converted.
        Returns:
        The value of property with the given name, converted into the given type
        See Also:
        getParentResource()
      • getInherited

        @CheckForNull
        public <T> T getInherited​(@Nonnull
                                  java.lang.String name,
                                  @Nonnull
                                  java.lang.Class<T> type)
        Returns the value of property with the given name, converted into the given type. If the property does not exist, it is taken from the parent properties. Return null if non existing or can't be converted.
        Type Parameters:
        T - The type to convert the value of the property to
        Parameters:
        name - The name of the property
        type - The type to convert the value of the given property name to
        Returns:
        The value of property with the given name, converted into the given type
        See Also:
        getParentResource()
      • getInheritedDefault

        @Nonnull
        public java.lang.String getInheritedDefault​(@Nonnull
                                                    java.lang.String name)
        Alias of get(String).
        Parameters:
        name - The name of the property
        Returns:
        The value of property with the given name, converted to string
      • getInheritedDefault

        @Nonnull
        public <T> T getInheritedDefault​(@Nonnull
                                         java.lang.String name,
                                         @Nonnull
                                         T defaultValue)
        Type Parameters:
        T - The type to convert the value of the property to
        Parameters:
        name - The name of the property
        defaultValue - The default value to use if the named property does not exist or cannot be converted to the requested type. The default value is also used to define the type to convert the value to. If this is null any existing property is not converted.
        Returns:
        The value of property with the given name, converted to string
      • getInheritedDefault

        @CheckForNull
        public <T> T getInheritedDefault​(@Nonnull
                                         java.lang.String name,
                                         @Nonnull
                                         java.lang.Class<T> type)
        Type Parameters:
        T - The type to convert the value of the property to
        Parameters:
        name - The name of the property
        type - The type to convert the value of the given property name to
        Returns:
        The value of property with the given name, converted to string
      • getDefaultProperties

        @Nonnull
        public ValueMap getDefaultProperties()
        Returns the default properties that will be applied to child elements. Be aware that these are not the defaults that are applied to the resource itself.
        Returns:
        The value map containing the default properties
      • getProperties

        @Nonnull
        public ValueMap getProperties()
        Returns the properties of the resource merged with the default properties.
        Returns:
        The value map containing the properties merged with the default properties.
      • getItems

        @Nonnull
        public java.util.Iterator<Resource> getItems()
        Returns the child resources of ITEMS sub-resource.
        Returns:
        The child resources of the specified ITEMS sub-resource
      • getItems

        @Nonnull
        public java.util.Iterator<Resource> getItems​(@CheckForNull
                                                     java.lang.String name)
        Returns the child resources of the sub-resource with the given name.
        Parameters:
        name - The name of the resource
        Returns:
        The child resources of the sub-resource with the given name
      • getItems

        @Nonnull
        public java.util.Iterator<Resource> getItems​(@CheckForNull
                                                     Resource resource)
        Returns the child resources of ITEMS sub-resource of the given resource.
        Parameters:
        resource - The resource
        Returns:
        The child resources of the ITEMS sub-resource of the given resource
      • getItems

        @Nonnull
        public java.util.Iterator<Resource> getItems​(@CheckForNull
                                                     Resource resource,
                                                     @CheckForNull
                                                     java.lang.String name)
        Returns the child resources of the sub resource with the given name of the given resource.
        Parameters:
        name - The name of the resource
        resource - The resource
        Returns:
        the child resources of the sub resource with the given name of the given resource.
      • getChild

        @CheckForNull
        public Resource getChild​(@Nonnull
                                 java.lang.String name)
        Returns the child resource with the given name.
        Parameters:
        name - The name of the resource
        Returns:
        The child resource
      • getParentResource

        @CheckForNull
        public Resource getParentResource()
        Returns the parent of the resource. If the parent is of type JcrConstants.NT_UNSTRUCTURED, then the parent is a container (e.g. "items"), then the container's parent is returned instead.
        Returns:
        The parent of the resource