Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.maryanovsky.gwtutils.client.text
Class ParseUtils

    java.lang.Object
      com.maryanovsky.gwtutils.client.text.ParseUtils

    public class ParseUtils

extends Object

A utility class providing useful methods for parsing.

Author:
  Maryanovsky Alexander

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

### ParseUtils

    public ParseUtils()

Method Detail

### parseProperties

    public static Map<String,String> parseProperties(String propertiesText)
                                              throws ParseException

  Parses a simplified properties file.

  Throws:
    `ParseException`

### parseProperties

    public static Map<String,String> parseProperties(String propertiesText,
                                                     boolean trim)
                                              throws ParseException

  Parses a simplified properties file, optionally trimming the property names and values. The parser supports comments (lines whose first non-whitespace character is `'#'`) 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.

  Throws:
    `ParseException`

### checkTagName

    public static void checkTagName(Element element,
                                    String tagName)
                             throws ParseException

  If the specified element's tag name equals to the specified value, returns quietly. Otherwise throws an appropriate ParseException.

  Throws:
    `ParseException`

### getNamedChildElements

    public static List<Element> getNamedChildElements(Element parentElement,
                                                      String tagName)

  Returns the list of (immediate) child elements with the specified tag name.

### getNamedChildElement

    public static Element getNamedChildElement(Element parentElement,
                                               String tagName,
                                               boolean isMandatory)
                                        throws ParseException

  Returns the child element with the specified tag name. If there is more than one such child element, throws a `ParseException`. If the element is missing, then depending on the value of `isMandatory` either a `ParseException` is thrown or `null` is returned.

  Throws:
    `ParseException`

### getMandatoryNamedElement

    public static Element getMandatoryNamedElement(Element parentElement,
                                                   String tagName)
                                            throws ParseException

  Equivalent to `getNamedChildElement(element, tagName, true)`.

  Throws:
    `ParseException`

### getOptionalNamedElement

    public static Element getOptionalNamedElement(Element parentElement,
                                                  String tagName)
                                           throws ParseException

  Equivalent to `getNamedChildElement(element, tagName, false)`.

  Throws:
    `ParseException`

### getTextContent

    public static String getTextContent(Element element)
                                 throws ParseException

  Returns the text content of the specified element by concatenating the data of all its `Text` child nodes.

  Throws:
    `ParseException`

### getAttribute

    public static String getAttribute(Element element,
                                      String attributeName,
                                      boolean isMandatory)
                               throws ParseException

  Returns the value of the specified element's attribute. If the attribute is missing, then depending on the value of `isMandatory` either a `ParseException` is thrown or `null` is returned.

  Throws:
    `ParseException`

### getMandatoryAttribute

    public static String getMandatoryAttribute(Element element,
                                               String attributeName)
                                        throws ParseException

  Equivalent to `getAttribute(element, attributeName, true)`.

  Throws:
    `ParseException`

### getOptionalAttribute

    public static String getOptionalAttribute(Element element,
                                              String attributeName,
                                              String defaultValue)

  Returns the value of the specified element's attribute. If the attribute is missing, returns the specified default value.

### getMandatoryDoubleAttribute

    public static double getMandatoryDoubleAttribute(Element element,
                                                     String attributeName)
                                              throws ParseException

  Returns the value of the specified element's attribute, parsed as a double. Throws a `ParseException` if the attribute is missing or if its value can't be parsed as a double.

  Throws:
    `ParseException`

### getOptionalDoubleAttribute

    public static double getOptionalDoubleAttribute(Element element,
                                                    String attributeName,
                                                    double defaultValue)
                                             throws ParseException

  Returns the value of the specified element's attribute, parsed as a double. If the attribute is missing, returns the specified default value. If the attribute's value can't be parsed as a double, throws a `ParseException`.

  Throws:
    `ParseException`

### getMandatoryIntAttribute

    public static int getMandatoryIntAttribute(Element element,
                                               String attributeName)
                                        throws ParseException

  Returns the value of the specified element's attribute, parsed as an int. Throws a `ParseException` if the attribute is missing or if its value can't be parsed as an int.

  Throws:
    `ParseException`

### getOptionalIntAttribute

    public static int getOptionalIntAttribute(Element element,
                                              String attributeName,
                                              int defaultValue)
                                       throws ParseException

  Returns the value of the specified element's attribute, parsed as an int. If the attribute is missing, returns the specified default value. If the attribute's value can't be parsed as an int, throws a `ParseException`.

  Throws:
    `ParseException`

### getMandatoryElementTextContent

    public static String getMandatoryElementTextContent(Element element,
                                                        String childElementName)
                                                 throws ParseException

  Returns the content of the child element of the specified element with the specified name. Throws a `ParseException` if the element is missing.

  Throws:
    `ParseException`

### getOptionalElementTextContent

    public static String getOptionalElementTextContent(Element element,
                                                       String childElementName,
                                                       String defaultValue)
                                                throws ParseException

  Returns the content of the child element of the specified element with the specified name. Returns the specified default value if the element is missing.

  Throws:
    `ParseException`

### getElementListTextContent

    public static String[] getElementListTextContent(Element element,
                                                     String childElementsName)
                                              throws ParseException

  Returns a list of the text contents of the child elements of the specified element with the specified name.

  Throws:
    `ParseException`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD