|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.maryanovsky.gwtutils.client.text.ParseUtils
public class ParseUtils
A utility class providing useful methods for parsing.
Constructor Summary | |
---|---|
ParseUtils()
|
Method Summary | |
---|---|
static void |
checkTagName(Element element,
String tagName)
If the specified element's tag name equals to the specified value, returns quietly. |
static String |
getAttribute(Element element,
String attributeName,
boolean isMandatory)
Returns the value of the specified element's attribute. |
static String[] |
getElementListTextContent(Element element,
String childElementsName)
Returns a list of the text contents of the child elements of the specified element with the specified name. |
static String |
getMandatoryAttribute(Element element,
String attributeName)
Equivalent to getAttribute(element, attributeName, true) . |
static double |
getMandatoryDoubleAttribute(Element element,
String attributeName)
Returns the value of the specified element's attribute, parsed as a double. |
static String |
getMandatoryElementTextContent(Element element,
String childElementName)
Returns the content of the child element of the specified element with the specified name. |
static int |
getMandatoryIntAttribute(Element element,
String attributeName)
Returns the value of the specified element's attribute, parsed as an int. |
static Element |
getMandatoryNamedElement(Element parentElement,
String tagName)
Equivalent to getNamedChildElement(element, tagName, true) . |
static Element |
getNamedChildElement(Element parentElement,
String tagName,
boolean isMandatory)
Returns the child element with the specified tag name. |
static List<Element> |
getNamedChildElements(Element parentElement,
String tagName)
Returns the list of (immediate) child elements with the specified tag name. |
static String |
getOptionalAttribute(Element element,
String attributeName,
String defaultValue)
Returns the value of the specified element's attribute. |
static double |
getOptionalDoubleAttribute(Element element,
String attributeName,
double defaultValue)
Returns the value of the specified element's attribute, parsed as a double. |
static String |
getOptionalElementTextContent(Element element,
String childElementName,
String defaultValue)
Returns the content of the child element of the specified element with the specified name. |
static int |
getOptionalIntAttribute(Element element,
String attributeName,
int defaultValue)
Returns the value of the specified element's attribute, parsed as an int. |
static Element |
getOptionalNamedElement(Element parentElement,
String tagName)
Equivalent to getNamedChildElement(element, tagName, false) . |
static String |
getTextContent(Element element)
Returns the text content of the specified element by concatenating the data of all its Text child nodes. |
static Map<String,String> |
parseProperties(String propertiesText)
Parses a simplified properties file. |
static Map<String,String> |
parseProperties(String propertiesText,
boolean trim)
Parses a simplified properties file, optionally trimming the property names and values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ParseUtils()
Method Detail |
---|
public static Map<String,String> parseProperties(String propertiesText) throws ParseException
ParseException
public static Map<String,String> parseProperties(String propertiesText, boolean trim) throws ParseException
'#'
) and allows empty lines.
Otherwise, every line must has a '='
character, the first of
which separates the property name and the value. A logical line may be
continued on a new physical line by ending the physical line with a
backslash character.
ParseException
public static void checkTagName(Element element, String tagName) throws ParseException
ParseException
public static List<Element> getNamedChildElements(Element parentElement, String tagName)
public static Element getNamedChildElement(Element parentElement, String tagName, boolean isMandatory) throws ParseException
ParseException
. If the
element is missing, then depending on the value of
isMandatory
either a ParseException
is thrown or
null
is returned.
ParseException
public static Element getMandatoryNamedElement(Element parentElement, String tagName) throws ParseException
getNamedChildElement(element, tagName, true)
.
ParseException
public static Element getOptionalNamedElement(Element parentElement, String tagName) throws ParseException
getNamedChildElement(element, tagName, false)
.
ParseException
public static String getTextContent(Element element) throws ParseException
Text
child nodes.
ParseException
public static String getAttribute(Element element, String attributeName, boolean isMandatory) throws ParseException
isMandatory
either a ParseException
is thrown or null
is
returned.
ParseException
public static String getMandatoryAttribute(Element element, String attributeName) throws ParseException
getAttribute(element, attributeName, true)
.
ParseException
public static String getOptionalAttribute(Element element, String attributeName, String defaultValue)
public static double getMandatoryDoubleAttribute(Element element, String attributeName) throws ParseException
ParseException
if the attribute is missing or if its
value can't be parsed as a double.
ParseException
public static double getOptionalDoubleAttribute(Element element, String attributeName, double defaultValue) throws ParseException
ParseException
.
ParseException
public static int getMandatoryIntAttribute(Element element, String attributeName) throws ParseException
ParseException
if the attribute is missing or if its
value can't be parsed as an int.
ParseException
public static int getOptionalIntAttribute(Element element, String attributeName, int defaultValue) throws ParseException
ParseException
.
ParseException
public static String getMandatoryElementTextContent(Element element, String childElementName) throws ParseException
ParseException
if the element is
missing.
ParseException
public static String getOptionalElementTextContent(Element element, String childElementName, String defaultValue) throws ParseException
ParseException
public static String[] getElementListTextContent(Element element, String childElementsName) throws ParseException
ParseException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |