org.apache.shindig.common.xml
Class XmlUtil

java.lang.Object
  extended by org.apache.shindig.common.xml.XmlUtil

public final class XmlUtil
extends Object

Utility class for simplifying parsing of xml documents. Documents are not validated, and loading of external files (xinclude, external entities, DTDs, etc.) are disabled.


Method Summary
static String getAttribute(Node node, String attr)
           
static String getAttribute(Node node, String attr, String def)
          Extracts an attribute from a node.
static boolean getBoolAttribute(Node node, String attr)
           
static boolean getBoolAttribute(Node node, String attr, boolean def)
          Retrieves an attribute as a boolean.
static Uri getHttpUriAttribute(Node node, String attr, Uri base)
          Retrieves an attribute as a URI, and verifies that the URI is an http or https URI.
static Uri getHttpUriAttribute(Node node, String attr, Uri base, Uri def)
          Retrieves an attribute as a URI, and verifies that the URI is an http or https URI.
static int getIntAttribute(Node node, String attr)
           
static int getIntAttribute(Node node, String attr, int def)
           
static Uri getUriAttribute(Node node, String attr)
          Retrieves an attribute as a URI.
static Uri getUriAttribute(Node node, String attr, Uri def)
          Retrieves an attribute as a URI.
static Element parse(String xml)
          Attempts to parse the input xml into a single element.
static Element parseSilent(String xml)
          Same as parse(String), but throws a RuntimeException instead of XmlException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAttribute

public static String getAttribute(Node node,
                                  String attr,
                                  String def)
Extracts an attribute from a node.

Parameters:
node -
attr -
def -
Returns:
The value of the attribute, or def

getAttribute

public static String getAttribute(Node node,
                                  String attr)
Parameters:
node -
attr -
Returns:
The value of the given attribute, or null if not present.

getUriAttribute

public static Uri getUriAttribute(Node node,
                                  String attr,
                                  Uri def)
Retrieves an attribute as a URI.

Parameters:
node -
attr -
Returns:
The parsed uri, or def if the attribute doesn't exist or can not be parsed as a URI.

getUriAttribute

public static Uri getUriAttribute(Node node,
                                  String attr)
Retrieves an attribute as a URI.

Parameters:
node -
attr -
Returns:
The parsed uri, or null.

getHttpUriAttribute

public static Uri getHttpUriAttribute(Node node,
                                      String attr,
                                      Uri base,
                                      Uri def)
Retrieves an attribute as a URI, and verifies that the URI is an http or https URI.

Parameters:
node -
attr -
base -
def - @return the parsed uri, or def if the attribute is not a valid http or https URI.

getHttpUriAttribute

public static Uri getHttpUriAttribute(Node node,
                                      String attr,
                                      Uri base)
Retrieves an attribute as a URI, and verifies that the URI is an http or https URI.

Parameters:
node -
attr -
base -
Returns:
the parsed uri, or null if the attribute is not a valid http or https URI.

getBoolAttribute

public static boolean getBoolAttribute(Node node,
                                       String attr,
                                       boolean def)
Retrieves an attribute as a boolean.

Parameters:
node -
attr -
def -
Returns:
True if the attribute exists and is not equal to "false" false if equal to "false", and def if not present.

getBoolAttribute

public static boolean getBoolAttribute(Node node,
                                       String attr)
Parameters:
node -
attr -
Returns:
True if the attribute exists and is not equal to "false" false otherwise.

getIntAttribute

public static int getIntAttribute(Node node,
                                  String attr,
                                  int def)
Returns:
An attribute coerced to an integer.

getIntAttribute

public static int getIntAttribute(Node node,
                                  String attr)
Returns:
An attribute coerced to an integer.

parse

public static Element parse(String xml)
                     throws XmlException
Attempts to parse the input xml into a single element.

Parameters:
xml -
Returns:
The document object
Throws:
XmlException - if a parse error occured.

parseSilent

public static Element parseSilent(String xml)
Same as parse(String), but throws a RuntimeException instead of XmlException.



Copyright © 2007-2012. All Rights Reserved.