net.sf.doolin.util.xml
Class DigesterUtils

java.lang.Object
  extended by net.sf.doolin.util.xml.DigesterUtils

public class DigesterUtils
extends Object

Utilities for dealing with a Jakarta Commons Digester.

Author:
Damien Coraboeuf

Constructor Summary
protected DigesterUtils()
          Protected constructor, used internally
 
Method Summary
static DigesterUtils createNonValidatingDigester()
          Creates a non validating digester
static DigesterUtils createValidatingDigester(URL schemaURL)
          Creates a digester that validates against a schema.
 org.apache.commons.digester.Digester getDigester()
          Access to the underlying digester.
 SAXParser getParser()
          Returns the associated SAX parser
 void parse(File file, Object initialValue)
          Parses a file
 void parse(InputSource inputSource, Object initialValue)
          Parses an input source.
 void parse(String xml, Object initialValue)
          Parses an XML stream.
 void parse(URL url, Object initialValue)
          Parses an URL.
 void ruleObject(String node, Class<?> clazz, String method)
          Creates a simple rule in the digester to create a new class for a node, setting its properties and calling a method on it after creation.
 void ruleProperties(String node)
          Creates a simple rule in the digester to setup an item from for a node, setting its properties.
 void ruleProperty(String node, String propertySetMethod)
          Creates a rule for creating a property from a leaf node, using the node's content as a value.
 void ruleProperty(String node, String propertySetMethod, Class<?> type)
          Creates a rule for creating a typed property from a leaf node, using the node's content as a value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DigesterUtils

protected DigesterUtils()
Protected constructor, used internally

Method Detail

createNonValidatingDigester

public static DigesterUtils createNonValidatingDigester()
Creates a non validating digester

Returns:
Digester wrapper

createValidatingDigester

public static DigesterUtils createValidatingDigester(URL schemaURL)
Creates a digester that validates against a schema.

Parameters:
schemaURL - URL to the schema.
Returns:
Digester wrapper.

getDigester

public org.apache.commons.digester.Digester getDigester()
Access to the underlying digester.

Returns:
Returns the digester.

getParser

public SAXParser getParser()
Returns the associated SAX parser

Returns:
SAX parser

parse

public void parse(File file,
                  Object initialValue)
Parses a file

Parameters:
file - File to parse
initialValue - Initial value for the digester

parse

public void parse(InputSource inputSource,
                  Object initialValue)
Parses an input source.

Parameters:
inputSource - Source to parse
initialValue - Initial value for the digester

parse

public void parse(String xml,
                  Object initialValue)
Parses an XML stream.

Parameters:
xml - XML string to parse
initialValue - Initial value for the digester

parse

public void parse(URL url,
                  Object initialValue)
Parses an URL.

Parameters:
url - URL to the XML document
initialValue - Initial value for the digester

ruleObject

public void ruleObject(String node,
                       Class<?> clazz,
                       String method)
Creates a simple rule in the digester to create a new class for a node, setting its properties and calling a method on it after creation.

Parameters:
node - Name (or path) of the XML node. Note that a */ will be prepended.
clazz - Class of the object to be created for this node.
method - Method to call after the node creation. This method is called on the next object of the digester's stack. If null, no call is performed.

ruleProperties

public void ruleProperties(String node)
Creates a simple rule in the digester to setup an item from for a node, setting its properties.

Parameters:
node - Name (or path) of the XML node. Note that a */ will be prepended.

ruleProperty

public void ruleProperty(String node,
                         String propertySetMethod)
Creates a rule for creating a property from a leaf node, using the node's content as a value.

Parameters:
node - Name (or path) of the XML node. Note that a */ will be prepended.
propertySetMethod - Method name to call to set the property

ruleProperty

public void ruleProperty(String node,
                         String propertySetMethod,
                         Class<?> type)
Creates a rule for creating a typed property from a leaf node, using the node's content as a value.

Parameters:
node - Name (or path) of the XML node. Note that a */ will be prepended.
propertySetMethod - Method name to call to set the property
type - Type of the property


Copyright © 2011. All Rights Reserved.