Class ConfigurationParser

  • Direct Known Subclasses:
    RepositoryConfigurationParser

    public class ConfigurationParser
    extends Object
    Configuration parser base class. This class provides the basic functionality for parsing Jackrabbit configuration files. Subclasses extend this functionality with knowledge of the exact structure of the different configuration files. Each configuration parser instance contains a set of parser variables that are used for variable replacement in the configuration file.
    • Field Detail

      • PARAM_ELEMENT

        public static final String PARAM_ELEMENT
        Name of the bean parameter configuration element.
        See Also:
        Constant Field Values
      • CLASS_ATTRIBUTE

        public static final String CLASS_ATTRIBUTE
        Name of the bean implementation class configuration attribute.
        See Also:
        Constant Field Values
      • NAME_ATTRIBUTE

        public static final String NAME_ATTRIBUTE
        Name of the bean parameter name configuration attribute.
        See Also:
        Constant Field Values
      • VALUE_ATTRIBUTE

        public static final String VALUE_ATTRIBUTE
        Name of the bean parameter value configuration attribute.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ConfigurationParser

        public ConfigurationParser​(Properties variables)
        Creates a new configuration parser with the given parser variables.
        Parameters:
        variables - parser variables
    • Method Detail

      • getVariables

        public Properties getVariables()
        Returns the variables.
        Returns:
        the variables.
      • parseBeanConfig

        protected BeanConfig parseBeanConfig​(Element parent,
                                             String name)
                                      throws ConfigurationException
        Parses a named bean configuration from the given element. Bean configuration uses the following format:
           <BeanName class="...">
             <param name="..." value="..."/>
             ...
           </BeanName>
         

        The returned bean configuration object contains the configured class name and configuration parameters. Variable replacement is performed on the parameter values.

        Parameters:
        parent - parent element
        name - name of the bean configuration element
        Returns:
        bean configuration,
        Throws:
        ConfigurationException - if the configuration element does not exist or is broken
      • parseBeanConfig

        protected BeanConfig parseBeanConfig​(Element element)
                                      throws ConfigurationException
        Parses a named bean configuration from the given element. Bean configuration uses the following format:
           <BeanName class="...">
             <param name="..." value="..."/>
             ...
           </BeanName>
         

        The returned bean configuration object contains the configured class name and configuration parameters. Variable replacement is performed on the parameter values.

        Parameters:
        element -
        Returns:
        bean configuration,
        Throws:
        ConfigurationException - if the configuration element does not exist or is broken
      • parseParameters

        protected Properties parseParameters​(Element element)
                                      throws ConfigurationException
        Parses the configuration parameters of the given element. Parameters are stored as <param name="..." value="..."/> child elements. This method parses all param elements, performs variable replacement on parameter values, and returns the resulting name-value pairs.
        Parameters:
        element - configuration element
        Returns:
        configuration parameters
        Throws:
        ConfigurationException - if a param element does not contain the name and value attributes
      • replaceVariables

        protected String replaceVariables​(String value)
                                   throws ConfigurationException
        Performs variable replacement on the given string value. Each ${...} sequence within the given value is replaced with the value of the named parser variable. The replacement is not done if the named variable does not exist.
        Parameters:
        value - original value
        Returns:
        value after variable replacements
        Throws:
        ConfigurationException - if the replacement of a referenced variable is not found
      • parseXML

        protected Element parseXML​(InputSource xml)
                            throws ConfigurationException
        Parses the given XML document and returns the DOM root element. A custom entity resolver is used to make the included configuration file DTD available using the specified public identifiers. This implementation does not validate the XML.
        Parameters:
        xml - xml document
        Returns:
        root element
        Throws:
        ConfigurationException - if the configuration document could not be read or parsed
        See Also:
        ConfigurationEntityResolver
      • getErrorHandler

        protected ErrorHandler getErrorHandler()
        Returns the error handler to be used when parsing configuration documents. Subclasses can override this method to provide custom error handling.
        Returns:
        error handler
        Since:
        Apache Jackrabbit 2.0
      • getEntityResolver

        protected EntityResolver getEntityResolver()
        Returns the entity resolver to be used when parsing configuration documents. Subclasses can override this method to provide custom entity resolution rules.
        Returns:
        error handler
        Since:
        Apache Jackrabbit 2.0
      • postParseModificationHook

        protected Document postParseModificationHook​(Document document)
        A post-processing hook for the parsed repository or workspace configuration documents. This hook makes it possible to make custom DOM modifications for backwards-compatibility or other reasons.
        Parameters:
        document - the parsed configuration document
        Returns:
        the configuration document after any modifications
        Since:
        Apache Jackrabbit 2.0
      • parseXML

        protected Element parseXML​(InputSource xml,
                                   boolean validate)
                            throws ConfigurationException
        Parses the given XML document and returns the DOM root element. A custom entity resolver is used to make the included configuration file DTD available using the specified public identifiers.
        Parameters:
        xml - xml document
        validate - whether the XML should be validated
        Returns:
        root element
        Throws:
        ConfigurationException - if the configuration document could not be read or parsed
        See Also:
        ConfigurationEntityResolver
      • getElement

        protected Element getElement​(Element parent,
                                     String name,
                                     boolean required)
                              throws ConfigurationException
        Returns the named child of the given parent element.
        Parameters:
        parent - parent element
        name - name of the child element
        required - indicates if the child element is required
        Returns:
        named child element, or null if not found and required is false.
        Throws:
        ConfigurationException - if the child element is not found and required is true; or if more than one element with this name exists.
      • getElements

        protected Element[] getElements​(Element parent,
                                        String name,
                                        boolean required)
                                 throws ConfigurationException
        Returns the named child of the given parent element.
        Parameters:
        parent - parent element
        name - name of the child element
        required - indicates if the child element is required
        Returns:
        named child element, or null if not found and required is false.
        Throws:
        ConfigurationException - if the child element is not found and required is true; or if more than one element with this name exists.
      • getAttribute

        protected String getAttribute​(Element element,
                                      String name,
                                      String def)
        Returns the value of the named attribute of the given element. If the attribute is not found, then the given default value is returned.
        Parameters:
        element - element
        name - attribute name
        def - default value
        Returns:
        attribute value, or the default value