com.bbn.swede.core.dom
Class OASTStringLocator

java.lang.Object
  extended bycom.bbn.swede.core.dom.OASTStringLocator

public class OASTStringLocator
extends Object

Traverses an OAST to find exact start offsets and lengths for its nodes. This class is intended for use after a full-file parse, since locating nodes against a file stream while SAX is still in the middle of parsing from the same file is incredibly slow.

Author:
jlerner

Field Summary
protected  String _sText
          The full text to use for locating nodes.
 
Constructor Summary
OASTStringLocator(String sText)
          Creates an OAST string locator to run against a string representation of the document.
 
Method Summary
 void locate(OASTNode root)
          Locates the nodes in an OAST subtree.
protected  void locateAttribute(AttributeNode node)
          Finds the start offset and length of an attribute node.
protected  void locateBegin(TagNode tag)
          Finds the start offset of a tag node.
protected  void locateEnd(TagNode tag)
          Finds the length of a tag node.
protected  void locateLiteral(Literal lit)
          Finds the start offset and length of a literal node.
protected  void locateRoot(OASTNode root)
          Sets the start offset and length of the root node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sText

protected String _sText
The full text to use for locating nodes. This should be the real text for the parse, not the dummy text used to fool the SAX parser into parsing part of a document.

Constructor Detail

OASTStringLocator

public OASTStringLocator(String sText)
Creates an OAST string locator to run against a string representation of the document.

Parameters:
sText - A string containing the entire portion of the OAST to be located.
Method Detail

locate

public void locate(OASTNode root)

Locates the nodes in an OAST subtree. The method used varies by node type - the top-level OASTNode subclasses TagNode, AttributeNode, and Literal are used as a rough cut to determine which helper method will be invoked to do the work.

Do not invoke locate() on a subtree that contains unparseable nodes. It is only designed for use after a successful parse and its behavior in the presence of invalid XML fragments is undefined.

Parameters:
root - The root of the tree to locate.
See Also:
locateAttribute(AttributeNode), locateBegin(TagNode), locateEnd(TagNode), locateLiteral(Literal), locateRoot(OASTNode)

locateBegin

protected void locateBegin(TagNode tag)
Finds the start offset of a tag node. The offset is determined by searching forward from the start offset of tag's parent node.

Parameters:
tag - The tag node to locate.

locateEnd

protected void locateEnd(TagNode tag)
Finds the length of a tag node. The length is determined by searching forward from the just-past-the-end offset of tag's last child.

Parameters:
tag - The tag node to locate.

locateAttribute

protected void locateAttribute(AttributeNode node)
Finds the start offset and length of an attribute node. The offset is found by searching forward from the just-past-the-end offset of node's parent's previous child (or its parent's start offset, if node is its first child), and the length is determined by searching forward from the located start offset.

Parameters:
node - The attribute node to locate.

locateLiteral

protected void locateLiteral(Literal lit)
Finds the start offset and length of a literal node. Since literals, by definition, fill the entire space between the opening and closing tag of their parent, the literal is located based on the offset of the first '>' beyond the parent's start offset and the first '<' after that.

Parameters:
lit - The literal node to locate.

locateRoot

protected void locateRoot(OASTNode root)
Sets the start offset and length of the root node. The root offset is always zero, and the length is the length of the string provided at construction.

Parameters:
root - The root node to locate.


Copyright © 2004-2005 BBN Technologies. All Rights Reserved.