com.izforge.izpack.adaptator.impl
Class LineNumberFilter

java.lang.Object
  extended by org.xml.sax.helpers.XMLFilterImpl
      extended by com.izforge.izpack.adaptator.impl.LineNumberFilter
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader

public class LineNumberFilter
extends org.xml.sax.helpers.XMLFilterImpl

A custom SAX XML filter, used to add line numbers to a DOM document. This filter stores line numbers while parsing, and the applyLN method set line numbers on the result. Line numbers are stored in the user data of the Element, so require Java 5 (DOM 3) or higher.

Author:
Anthonin Bonnefoy, David Duponchel

Field Summary
private  java.util.Queue<java.lang.Integer> lnQueue
          a queue to store line numbers while parsing.
private  org.xml.sax.Locator locator
          The locator given while parsing.
 
Constructor Summary
LineNumberFilter(org.xml.sax.XMLReader xmlReader)
           
 
Method Summary
 void applyLN(javax.xml.transform.dom.DOMResult result)
          Apply line numbers stored by a parse using this object on the xml elements.
private  void applyLN(org.w3c.dom.Element elt)
          Apply a line number on the given element.
 org.xml.sax.Locator getDocumentLocator()
          Return the locator on the current position.
private  org.w3c.dom.Element getFirstChild(org.w3c.dom.Node elt)
          Return the first element child found from the given Node.
private  org.w3c.dom.Element getFirstFoundElement(org.w3c.dom.Node elt)
          Return the first element found from the given Node.
private  org.w3c.dom.Element getNextSibling(org.w3c.dom.Node elt)
          Return the next element sibling found from the given Node.
private  boolean hasChildElements(org.w3c.dom.Node elt)
          Returns whether the given node has any element children.
 void setDocumentLocator(org.xml.sax.Locator locator)
           
 void startDocument()
           
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
           
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
characters, endDocument, endElement, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, notationDecl, parse, parse, processingInstruction, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lnQueue

private java.util.Queue<java.lang.Integer> lnQueue
a queue to store line numbers while parsing.


locator

private org.xml.sax.Locator locator
The locator given while parsing.

Constructor Detail

LineNumberFilter

public LineNumberFilter(org.xml.sax.XMLReader xmlReader)
Method Detail

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.XMLFilterImpl
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.XMLFilterImpl
Throws:
org.xml.sax.SAXException

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Overrides:
setDocumentLocator in class org.xml.sax.helpers.XMLFilterImpl

getDocumentLocator

public org.xml.sax.Locator getDocumentLocator()
Return the locator on the current position.

Returns:
the current locator.

getFirstFoundElement

private org.w3c.dom.Element getFirstFoundElement(org.w3c.dom.Node elt)
Return the first element found from the given Node.

Parameters:
elt - The Node start point.
Returns:
The first Element found, or null.

getNextSibling

private org.w3c.dom.Element getNextSibling(org.w3c.dom.Node elt)
Return the next element sibling found from the given Node.

Parameters:
elt - The Node start point.
Returns:
The next sibling Element, or null if nto found.

getFirstChild

private org.w3c.dom.Element getFirstChild(org.w3c.dom.Node elt)
Return the first element child found from the given Node.

Parameters:
elt - The Node start point.
Returns:
The first child Element found, or null.

hasChildElements

private boolean hasChildElements(org.w3c.dom.Node elt)
Returns whether the given node has any element children.

Parameters:
elt - The node to check.
Returns:
Returns true if this node has any children, false otherwise.

applyLN

private void applyLN(org.w3c.dom.Element elt)
Apply a line number on the given element. We assume that the line number queue has been correctly filled, and that the current DOM tree correspond to the parsed XML.

Parameters:
elt - the element to apply the line number.

applyLN

public void applyLN(javax.xml.transform.dom.DOMResult result)
Apply line numbers stored by a parse using this object on the xml elements.

Parameters:
result - The result of the parse.