Package eu.woolplatform.utils.xml
Class AbstractSimpleSAXHandler<T>
- java.lang.Object
-
- eu.woolplatform.utils.xml.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 ofSimpleSAXHandlercontains convenient methods to parse attribute values.
-
-
Constructor Summary
Constructors Constructor Description AbstractSimpleSAXHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringreadAttribute(Attributes atts, String name)Tries to read the value of an attribute.protected StringreadAttribute(Attributes atts, String name, Integer minLength, Integer maxLength)Tries to read the value of an attribute and validates the length of the value.protected booleanreadBooleanAttribute(Attributes atts, String name)Tries to read a boolean value of an attribute.protected <U extends Enum<U>>
UreadEnumAttribute(Class<U> clazz, Attributes atts, String name)Tries to read an enum value of an attribute.protected FilereadFileAttribute(Attributes atts, String name)Tries to read an attribute with the path to a file or directory.protected FilereadFileAttribute(Attributes atts, String name, File parent)Tries to read an attribute with the path to a file or directory.protected floatreadFloatAttribute(Attributes atts, String name)Tries to read a float value of an attribute.protected intreadIntAttribute(Attributes atts, String name)Tries to read an integer value of an attribute.protected StringreadRegexAttribute(Attributes atts, String name, String regex)Reads an attribute value and validates whether it matches the specified regular expression.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface eu.woolplatform.utils.xml.SimpleSAXHandler
characters, endElement, getObject, startElement
-
-
-
-
Method Detail
-
readAttribute
protected String readAttribute(Attributes atts, String name) throws ParseException
Tries to read the value of an attribute.- Parameters:
atts- the attributesname- 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 attributesname- the attribute nameminLength- the minimum length or nullmaxLength- 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 attributesname- 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 attributesname- 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 attributesname- 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 classatts- the attributesname- 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 attributesname- 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 attributesname- the attribute nameparent- 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 attributesname- the attribute nameregex- the regular expression- Returns:
- the attribute value
- Throws:
ParseException- if the attribute doesn't exist or its value is invalid
-
-