net.sf.jmatchparser.util
Class LocationAwareDOMParser

java.lang.Object
  extended by net.sf.jmatchparser.util.LocationAwareDOMParser

public class LocationAwareDOMParser
extends Object

A DOM parser that annotates each Node with an approximate line/column number where it was parsed. Technically, this is done by parsing the document twice; therefore, this class also provides a utility method to create clones of an InputSource.


Constructor Summary
LocationAwareDOMParser()
           
 
Method Summary
static InputSource[] createClones(InputSource input, int count)
          Create an arbitrary number of clones of an InputSource.
static int getColumnNumber(Node node)
          Get the column number embedded in a node.
static int getLineNumber(Node node)
          Get the line number embedded in a node.
static Document parse(DocumentBuilder documentBuilder, InputSource source)
          Parse the given InputSource to a DOM document that contains line number information, using a custom DocumentBuilder.
static Document parse(InputSource source)
          Parse the given InputSource to a DOM document that contains line number information, using the default DocumentBuilder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocationAwareDOMParser

public LocationAwareDOMParser()
Method Detail

createClones

public static InputSource[] createClones(InputSource input,
                                         int count)
                                  throws IOException
Create an arbitrary number of clones of an InputSource. The original InputSource will be invalid after that, but each of the clone can be used individually to parse the same document in multiple ways.

Parameters:
input - The InputSource to clone
count - The desired number of clones
Returns:
An array that contains the clones
Throws:
IOException

parse

public static Document parse(InputSource source)
                      throws Exception
Parse the given InputSource to a DOM document that contains line number information, using the default DocumentBuilder.

Throws:
Exception

parse

public static Document parse(DocumentBuilder documentBuilder,
                             InputSource source)
                      throws Exception
Parse the given InputSource to a DOM document that contains line number information, using a custom DocumentBuilder.

Throws:
Exception

getLineNumber

public static int getLineNumber(Node node)
Get the line number embedded in a node.

Parameters:
node - the node
Returns:
the line number, or -1 if none was embedded

getColumnNumber

public static int getColumnNumber(Node node)
Get the column number embedded in a node.

Parameters:
node - the node
Returns:
the column number, or -1 if none was embedded


Copyright © 2011. All Rights Reserved.