net.sf.xolite
Class ElementText

java.lang.Object
  extended by net.sf.xolite.ElementText

public class ElementText
extends Object

A helper class to get formatted value out of XML element text.

Author:
Olivier Berlanger

Constructor Summary
ElementText()
           
 
Method Summary
static boolean getBoolean(boolean defaultValue, XMLEventParser parser)
           
protected static boolean getBoolean(boolean defaultValue, XMLEventParser parser, boolean mandatory)
           
protected static Date getDate(String pattern, Date defaultValue, boolean mandatory, XMLEventParser parser)
           
static Date getDate(String pattern, Date defaultValue, XMLEventParser parser)
           
protected static Dimension getDimension(Dimension defaultValue, boolean mandatory, XMLEventParser parser)
           
static Dimension getDimension(Dimension defaultValue, XMLEventParser parser)
           
static double getDouble(double defaultValue, XMLEventParser parser)
           
protected static double getDouble(double defaultValue, XMLEventParser parser, boolean mandatory)
           
static
<T extends Enum<T>>
T
getEnum(T defaultValue, Class<T> enumType, XMLEventParser parser)
           
protected static
<T extends Enum<T>>
T
getEnum(T defaultValue, Class<T> enumType, XMLEventParser parser, boolean mandatory)
           
static int getInt(int defaultValue, XMLEventParser parser)
           
protected static int getInt(int defaultValue, XMLEventParser parser, boolean mandatory)
           
static int[] getIntArray(int[] defaultValue, XMLEventParser parser)
           
protected static int[] getIntArray(int[] defaultValue, XMLEventParser parser, boolean mandatory)
           
static long getLong(long defaultValue, XMLEventParser parser)
           
protected static long getLong(long defaultValue, XMLEventParser parser, boolean mandatory)
           
static boolean getMandatoryBoolean(XMLEventParser parser)
           
static Date getMandatoryDate(String pattern, XMLEventParser parser)
           
static Dimension getMandatoryDimension(XMLEventParser parser)
           
static double getMandatoryDouble(XMLEventParser parser)
           
static
<T extends Enum<T>>
T
getMandatoryEnum(Class<T> enumType, XMLEventParser parser)
           
static int getMandatoryInt(XMLEventParser parser)
           
static int[] getMandatoryIntArray(XMLEventParser parser)
           
static long getMandatoryLong(XMLEventParser parser)
           
static String getMandatoryMultilineText(XMLEventParser parser)
          Get a mandatory multi-line text.
static Point getMandatoryPoint(XMLEventParser parser)
           
static Rectangle getMandatoryRectangle(XMLEventParser parser)
           
static String getMandatoryString(XMLEventParser parser)
          Get the current text from the given parser.
static String getMultilineText(String defaultValue, XMLEventParser parser)
          Get a multi-line text.
protected static String getMultilineText(String defaultValue, XMLEventParser parser, boolean mandatory)
           
protected static Point getPoint(Point defaultValue, boolean mandatory, XMLEventParser parser)
           
static Point getPoint(Point defaultValue, XMLEventParser parser)
           
protected static Rectangle getRectangle(Rectangle defaultValue, boolean mandatory, XMLEventParser parser)
           
static Rectangle getRectangle(Rectangle defaultValue, XMLEventParser parser)
           
static String getString(String defaultValue, XMLEventParser parser)
          Get the current text from the given parser.
protected static String getString(String defaultValue, XMLEventParser parser, boolean mandatory)
           
static String getString(XMLEventParser parser)
          Get the current text from the given parser.
protected static String getTrimmedText(boolean mandatory, XMLEventParser parser)
           
static void simpleElementMultiline(String uri, String tag, String text, XMLSerializer serilalizer)
           
static String trimMultiLine(String str)
          Remove extra whitespaces that were added by the XMLSerializer.charactersMultiLine(text) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementText

public ElementText()
Method Detail

getString

public static String getString(XMLEventParser parser)
                        throws XMLParseException
Get the current text from the given parser.
If there is no current text or if this text is only made of white spaces, null is returned.

Parameters:
parser - the parser.
Returns:
the text of the current element of the given parser.
Throws:
XMLParseException

getString

public static String getString(String defaultValue,
                               XMLEventParser parser)
                        throws XMLParseException
Get the current text from the given parser.
If there is no current text or if this text is only made of white spaces, the given default value is returned.

Parameters:
defaultValue - the value to return if no text is defined.
parser - the parser.
Returns:
the text of the current element of the given parser.
Throws:
XMLParseException

getMandatoryString

public static String getMandatoryString(XMLEventParser parser)
                                 throws XMLParseException
Get the current text from the given parser.
If there is no current text or if this text is only made of white spaces, an exception is throw saying that this text is mandatory.

Parameters:
parser - the parser.
Returns:
the text of the current element of the given parser.
Throws:
XMLParseException - if no text is defined.

getMultilineText

public static String getMultilineText(String defaultValue,
                                      XMLEventParser parser)
                               throws XMLParseException
Get a multi-line text.
This method removes from the given multi-line text the witespace that was added for indentation at the begin of each text line. This method does the invert operation of the XMLSerializer.charactersMultiLine(String text) method.

Parameters:
defaultValue - the value to return if no text is defined.
parser - the parser.
Returns:
the text of the current element of the given parser.
Throws:
XMLParseException
See Also:
XMLSerializer.charactersMultiLine(String)

getMandatoryMultilineText

public static String getMandatoryMultilineText(XMLEventParser parser)
                                        throws XMLParseException
Get a mandatory multi-line text.
This method removes from the given multi-line text the witespace that was added for indentation at the begin of each text line. This method does the invert operation of the XMLSerializer.charactersMultiLine(String text) method.

If there is no current text or if this text is only made of white spaces, an exception is throw saying that this text is mandatory.

Parameters:
parser - the parser.
Returns:
the text of the current element of the given parser.
Throws:
XMLParseException - if no text is defined.
See Also:
XMLSerializer.charactersMultiLine(String)

getInt

public static int getInt(int defaultValue,
                         XMLEventParser parser)
                  throws XMLParseException
Throws:
XMLParseException

getMandatoryInt

public static int getMandatoryInt(XMLEventParser parser)
                           throws XMLParseException
Throws:
XMLParseException

getEnum

public static <T extends Enum<T>> T getEnum(T defaultValue,
                                            Class<T> enumType,
                                            XMLEventParser parser)
                                 throws XMLParseException
Throws:
XMLParseException

getMandatoryEnum

public static <T extends Enum<T>> T getMandatoryEnum(Class<T> enumType,
                                                     XMLEventParser parser)
                                          throws XMLParseException
Throws:
XMLParseException

getDouble

public static double getDouble(double defaultValue,
                               XMLEventParser parser)
                        throws XMLParseException
Throws:
XMLParseException

getMandatoryDouble

public static double getMandatoryDouble(XMLEventParser parser)
                                 throws XMLParseException
Throws:
XMLParseException

getIntArray

public static int[] getIntArray(int[] defaultValue,
                                XMLEventParser parser)
                         throws XMLParseException
Throws:
XMLParseException

getMandatoryIntArray

public static int[] getMandatoryIntArray(XMLEventParser parser)
                                  throws XMLParseException
Throws:
XMLParseException

getLong

public static long getLong(long defaultValue,
                           XMLEventParser parser)
                    throws XMLParseException
Throws:
XMLParseException

getMandatoryLong

public static long getMandatoryLong(XMLEventParser parser)
                             throws XMLParseException
Throws:
XMLParseException

getBoolean

public static boolean getBoolean(boolean defaultValue,
                                 XMLEventParser parser)
                          throws XMLParseException
Throws:
XMLParseException

getMandatoryBoolean

public static boolean getMandatoryBoolean(XMLEventParser parser)
                                   throws XMLParseException
Throws:
XMLParseException

getPoint

public static Point getPoint(Point defaultValue,
                             XMLEventParser parser)
                      throws XMLParseException
Throws:
XMLParseException

getMandatoryPoint

public static Point getMandatoryPoint(XMLEventParser parser)
                               throws XMLParseException
Throws:
XMLParseException

getDimension

public static Dimension getDimension(Dimension defaultValue,
                                     XMLEventParser parser)
                              throws XMLParseException
Throws:
XMLParseException

getMandatoryDimension

public static Dimension getMandatoryDimension(XMLEventParser parser)
                                       throws XMLParseException
Throws:
XMLParseException

getRectangle

public static Rectangle getRectangle(Rectangle defaultValue,
                                     XMLEventParser parser)
                              throws XMLParseException
Throws:
XMLParseException

getMandatoryRectangle

public static Rectangle getMandatoryRectangle(XMLEventParser parser)
                                       throws XMLParseException
Throws:
XMLParseException

getDate

public static Date getDate(String pattern,
                           Date defaultValue,
                           XMLEventParser parser)
                    throws XMLParseException
Throws:
XMLParseException

getMandatoryDate

public static Date getMandatoryDate(String pattern,
                                    XMLEventParser parser)
                             throws XMLParseException
Throws:
XMLParseException

getString

protected static String getString(String defaultValue,
                                  XMLEventParser parser,
                                  boolean mandatory)
                           throws XMLParseException
Throws:
XMLParseException

getMultilineText

protected static String getMultilineText(String defaultValue,
                                         XMLEventParser parser,
                                         boolean mandatory)
                                  throws XMLParseException
Throws:
XMLParseException

getBoolean

protected static boolean getBoolean(boolean defaultValue,
                                    XMLEventParser parser,
                                    boolean mandatory)
                             throws XMLParseException
Throws:
XMLParseException

getInt

protected static int getInt(int defaultValue,
                            XMLEventParser parser,
                            boolean mandatory)
                     throws XMLParseException
Throws:
XMLParseException

getEnum

protected static <T extends Enum<T>> T getEnum(T defaultValue,
                                               Class<T> enumType,
                                               XMLEventParser parser,
                                               boolean mandatory)
                                    throws XMLParseException
Throws:
XMLParseException

getDouble

protected static double getDouble(double defaultValue,
                                  XMLEventParser parser,
                                  boolean mandatory)
                           throws XMLParseException
Throws:
XMLParseException

getIntArray

protected static int[] getIntArray(int[] defaultValue,
                                   XMLEventParser parser,
                                   boolean mandatory)
                            throws XMLParseException
Throws:
XMLParseException

getLong

protected static long getLong(long defaultValue,
                              XMLEventParser parser,
                              boolean mandatory)
                       throws XMLParseException
Throws:
XMLParseException

getDimension

protected static Dimension getDimension(Dimension defaultValue,
                                        boolean mandatory,
                                        XMLEventParser parser)
                                 throws XMLParseException
Throws:
XMLParseException

getPoint

protected static Point getPoint(Point defaultValue,
                                boolean mandatory,
                                XMLEventParser parser)
                         throws XMLParseException
Throws:
XMLParseException

getRectangle

protected static Rectangle getRectangle(Rectangle defaultValue,
                                        boolean mandatory,
                                        XMLEventParser parser)
                                 throws XMLParseException
Throws:
XMLParseException

getDate

protected static Date getDate(String pattern,
                              Date defaultValue,
                              boolean mandatory,
                              XMLEventParser parser)
                       throws XMLParseException
Throws:
XMLParseException

getTrimmedText

protected static String getTrimmedText(boolean mandatory,
                                       XMLEventParser parser)
                                throws XMLParseException
Throws:
XMLParseException

trimMultiLine

public static final String trimMultiLine(String str)
Remove extra whitespaces that were added by the XMLSerializer.charactersMultiLine(text) method.
Each line of the string is 'smartly trimmed' to get back the input text. If the given string contains only one line (new 'new-line' characters) it is simply trimmed.

Parameters:
str - The multi-line string to be trimmed at each line.
Returns:
The input string trimmed at each line.

simpleElementMultiline

public static void simpleElementMultiline(String uri,
                                          String tag,
                                          String text,
                                          XMLSerializer serilalizer)
                                   throws XMLSerializeException
Throws:
XMLSerializeException


Copyright © 2012. All Rights Reserved.