Class AbstractSimpleSAXHandler<T>

  • Type Parameters:
    T - the type of objects returned by the handler
    All Implemented Interfaces:
    SimpleSAXHandler<T>

    public abstract class AbstractSimpleSAXHandler<T>
    extends Object
    implements SimpleSAXHandler<T>
    This abstract implementation of SimpleSAXHandler contains convenient methods to parse attribute values.
    • Constructor Detail

      • AbstractSimpleSAXHandler

        public AbstractSimpleSAXHandler()
    • Method Detail

      • readAttribute

        protected String readAttribute​(Attributes atts,
                                       String name)
                                throws ParseException
        Tries to read the value of an attribute.
        Parameters:
        atts - the attributes
        name - the attribute name
        Returns:
        the attribute value
        Throws:
        ParseException - if the attribute doesn't exist
      • readAttribute

        protected String readAttribute​(Attributes atts,
                                       String name,
                                       Integer minLength,
                                       Integer maxLength)
                                throws ParseException
        Tries to read the value of an attribute and validates the length of the value.
        Parameters:
        atts - the attributes
        name - the attribute name
        minLength - the minimum length or null
        maxLength - the maximum length or null
        Returns:
        the attribute value
        Throws:
        ParseException - if the attribute doesn't exist or doesn't have the required length
      • readIntAttribute

        protected int readIntAttribute​(Attributes atts,
                                       String name)
                                throws ParseException
        Tries to read an integer value of an attribute.
        Parameters:
        atts - the attributes
        name - the attribute name
        Returns:
        the attribute value
        Throws:
        ParseException - if the attribute doesn't exist or its value is invalid
      • readFloatAttribute

        protected float readFloatAttribute​(Attributes atts,
                                           String name)
                                    throws ParseException
        Tries to read a float value of an attribute.
        Parameters:
        atts - the attributes
        name - the attribute name
        Returns:
        the attribute value
        Throws:
        ParseException - if the attribute doesn't exist or its value is invalid
      • readBooleanAttribute

        protected boolean readBooleanAttribute​(Attributes atts,
                                               String name)
                                        throws ParseException
        Tries to read a boolean value of an attribute.
        Parameters:
        atts - the attributes
        name - the attribute name
        Returns:
        the attribute value
        Throws:
        ParseException - if the attribute doesn't exist or its value is invalid
      • readEnumAttribute

        protected <U extends Enum<U>> U readEnumAttribute​(Class<U> clazz,
                                                          Attributes atts,
                                                          String name)
                                                   throws ParseException
        Tries to read an enum value of an attribute.
        Type Parameters:
        U - the enum type
        Parameters:
        clazz - the enum class
        atts - the attributes
        name - the attribute name
        Returns:
        the attribute value
        Throws:
        ParseException - if the attribute doesn't exist or its value is invalid
      • readFileAttribute

        protected File readFileAttribute​(Attributes atts,
                                         String name)
                                  throws ParseException
        Tries to read an attribute with the path to a file or directory. This method tries to return a canonical path. If that fails, it will print an error and return an absolute path. If the attribute value is a relative path, it will be made absolute with respect to the current directory.
        Parameters:
        atts - the attributes
        name - the attribute name
        Returns:
        the attribute value
        Throws:
        ParseException - if the attribute doesn't exist or its value is invalid
      • readFileAttribute

        protected File readFileAttribute​(Attributes atts,
                                         String name,
                                         File parent)
                                  throws ParseException
        Tries to read an attribute with the path to a file or directory. This method tries to return a canonical path. If that fails, it will print an error and return an absolute path. If the attribute value is a relative path, it will be made absolute with respect to the specified parent or the current directory (if the parent is not specified).
        Parameters:
        atts - the attributes
        name - the attribute name
        parent - a directory to resolve a relative path or null
        Returns:
        the attribute value
        Throws:
        ParseException - if the attribute doesn't exist or its value is invalid
      • readRegexAttribute

        protected String readRegexAttribute​(Attributes atts,
                                            String name,
                                            String regex)
                                     throws ParseException
        Reads an attribute value and validates whether it matches the specified regular expression.
        Parameters:
        atts - the attributes
        name - the attribute name
        regex - the regular expression
        Returns:
        the attribute value
        Throws:
        ParseException - if the attribute doesn't exist or its value is invalid