net.sf.webmancer.util.xml.sax
Class ContentHandlerUtils

java.lang.Object
  extended by net.sf.webmancer.util.xml.sax.ContentHandlerUtils

public class ContentHandlerUtils
extends java.lang.Object

This class provides various utility methods used while creating SAX parsers. SAX parsing is parsing of XML files using Simple API for XML.

Author:
Michal Burda

Method Summary
static void expected(boolean condition, java.lang.String message, org.xml.sax.Locator locator)
          Throws SAXSemanticException if the given condition is not satisfied.
static java.lang.String getAttributesValue(org.xml.sax.Attributes atts, javax.xml.namespace.QName attributeQName)
          Search in atts for an attribute with name given by attributeQName and return its value or null if no such attribute is found.
static double getAttributesValueAsDouble(org.xml.sax.Attributes atts, javax.xml.namespace.QName attributeQName, org.xml.sax.Locator locator)
          Search in atts for an attribute with name given by attributeQName and return its value as double.
static float getAttributesValueAsFloat(org.xml.sax.Attributes atts, javax.xml.namespace.QName attributeQName, org.xml.sax.Locator locator)
          Search in atts for an attribute with name given by attributeQName and return its value as float.
static int getAttributesValueAsInt(org.xml.sax.Attributes atts, javax.xml.namespace.QName attributeQName, org.xml.sax.Locator locator)
          Search in atts for an attribute with name given by attributeQName and return its value as int.
static long getAttributesValueAsLong(org.xml.sax.Attributes atts, javax.xml.namespace.QName attributeQName, org.xml.sax.Locator locator)
          Search in atts for an attribute with name given by attributeQName and return its value as long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAttributesValue

public static java.lang.String getAttributesValue(org.xml.sax.Attributes atts,
                                                  javax.xml.namespace.QName attributeQName)
Search in atts for an attribute with name given by attributeQName and return its value or null if no such attribute is found. All parameters must not be null.

Parameters:
atts - The list of attributes being searched in
attributeQName - The QName of the searched attribute
Returns:
The attribute value or null if no such attribute is found

expected

public static void expected(boolean condition,
                            java.lang.String message,
                            org.xml.sax.Locator locator)
                     throws SAXSemanticException
Throws SAXSemanticException if the given condition is not satisfied.

Parameters:
condition - The condition that has to be satisfied or the exception is thrown
message - The error message
locator - The locator of the error
Throws:
SAXSemanticException - Thrown if the given condition is not satisfied

getAttributesValueAsInt

public static int getAttributesValueAsInt(org.xml.sax.Attributes atts,
                                          javax.xml.namespace.QName attributeQName,
                                          org.xml.sax.Locator locator)
                                   throws SAXSemanticException
Search in atts for an attribute with name given by attributeQName and return its value as int. If no such attribute is found or its value is not parsable string, the SAXSemanticException is thrown.

Parameters:
atts - The list of attributes being searched in
attributeQName - The QName of the searched attribute
locator - The locator that would be used in exception creation
Returns:
The attribute value as int
Throws:
SAXSemanticException - Thrown if no such attribute is found or its value is not parsable string

getAttributesValueAsLong

public static long getAttributesValueAsLong(org.xml.sax.Attributes atts,
                                            javax.xml.namespace.QName attributeQName,
                                            org.xml.sax.Locator locator)
                                     throws SAXSemanticException
Search in atts for an attribute with name given by attributeQName and return its value as long. If no such attribute is found or its value is not parsable string, the SAXSemanticException is thrown.

Parameters:
atts - The list of attributes being searched in
attributeQName - The QName of the searched attribute
locator - The locator that would be used in exception creation
Returns:
The attribute value as long
Throws:
SAXSemanticException - Thrown if no such attribute is found or its value is not parsable string

getAttributesValueAsFloat

public static float getAttributesValueAsFloat(org.xml.sax.Attributes atts,
                                              javax.xml.namespace.QName attributeQName,
                                              org.xml.sax.Locator locator)
                                       throws SAXSemanticException
Search in atts for an attribute with name given by attributeQName and return its value as float. If no such attribute is found or its value is not parsable string, the SAXSemanticException is thrown.

Parameters:
atts - The list of attributes being searched in
attributeQName - The QName of the searched attribute
locator - The locator that would be used in exception creation
Returns:
The attribute value as float
Throws:
SAXSemanticException - Thrown if no such attribute is found or its value is not parsable string

getAttributesValueAsDouble

public static double getAttributesValueAsDouble(org.xml.sax.Attributes atts,
                                                javax.xml.namespace.QName attributeQName,
                                                org.xml.sax.Locator locator)
                                         throws SAXSemanticException
Search in atts for an attribute with name given by attributeQName and return its value as double. If no such attribute is found or its value is not parsable string, the SAXSemanticException is thrown.

Parameters:
atts - The list of attributes being searched in
attributeQName - The QName of the searched attribute
locator - The locator that would be used in exception creation
Returns:
The attribute value as double
Throws:
SAXSemanticException - Thrown if no such attribute is found or its value is not parsable string


Copyright © 2006-2007. All Rights Reserved.