org.openadaptor.simplexml
Class XToken

java.lang.Object
  extended by org.openadaptor.simplexml.XToken
All Implemented Interfaces:
ReusableObject
Direct Known Subclasses:
XAttribute, XBadElement, XCData, XComment, XName, XRawText, XString, XSymbol, XTag, XText

public abstract class XToken
extends java.lang.Object
implements ReusableObject

XToken - abstract superclass for the various simplexml token classes. This class has two sets of methods. The first is some static (class-wide) helper methods, which provide methods for XML to plain text translations, and synchronised access to a shared StringBuffer instance, amongst other things.
The second set of instance methods define the common functionality of all XTokens. XTokens are intended to be used by XML Scanners, and the XML parsers and document parsers which control them, for reading and writing the basic units of XML from and onto I/O streams. As such, XTokens have methods for writing themselves out, and comparing themselves to existing XTokens.

Currently the subclasses of XToken cover the basic units of XML syntax; symbols (markup), strings and runs of free text, and also higher level XML syntactic units; comments, tags, tag attributes and strings. We might want to group these higher-level elements under another class, but we still want the same common functionality for writing and reading, so it would have to be a subclass of XToken.


Field Summary
protected static java.lang.String AMPERSAND
           
(package private) static org.apache.log4j.Logger log
           
protected static java.lang.String RCARET
           
 
Constructor Summary
XToken()
           
 
Method Summary
protected static java.lang.StringBuffer _grabStringBuffer()
          Returns an empty string string buffer from the pool for your use.
protected static void _releaseStringBuffer(java.lang.StringBuffer sb)
          Called to return a StringBuffer to the 'free' pool.
static java.lang.String convertToPlaintext(java.lang.String xmlText, java.lang.String[][] entities)
          Translates XML free text to plain text.
abstract  boolean equals(XToken other)
          Returns true if the receiver exactly matches other.
protected  java.lang.String getClassName()
          Convenience method which returns the unqualified class name e.g.
 boolean isReleased()
          Returns "reuse" status of object.
 boolean isWhitespace()
          Returns true if the XToken represents whitespace.
abstract  boolean matches(XToken token)
          Returns true if the receiver is the same "type" of XToken as other.
 void printDebug()
          Print receiver details on System.err.
 void setReleased(boolean flag)
          Sets the object "reuse" status
abstract  java.lang.String toString()
          Returns a textual representation of the receiver in a String
abstract  void toWriter(java.io.Writer writer)
          Writes a textual representation of the receiver onto writer
 void toWriter(java.io.Writer writer, java.lang.String text)
          A convenience method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

static org.apache.log4j.Logger log

RCARET

protected static java.lang.String RCARET

AMPERSAND

protected static java.lang.String AMPERSAND
Constructor Detail

XToken

public XToken()
Method Detail

convertToPlaintext

public static java.lang.String convertToPlaintext(java.lang.String xmlText,
                                                  java.lang.String[][] entities)
Translates XML free text to plain text. Changes all occurrences of &lt;, &gt; and &amp; etc to <, >, &.

Parameters:
xmlText - XML format text
Returns:
plain text version of xmlText.

_grabStringBuffer

protected static java.lang.StringBuffer _grabStringBuffer()
Returns an empty string string buffer from the pool for your use. When you have finished with it, be sure to call releaseStringBuffer().


_releaseStringBuffer

protected static void _releaseStringBuffer(java.lang.StringBuffer sb)
Called to return a StringBuffer to the 'free' pool.


getClassName

protected java.lang.String getClassName()
Convenience method which returns the unqualified class name e.g. XToken.

Returns:
The class name as a String.

printDebug

public void printDebug()
Print receiver details on System.err.


toWriter

public void toWriter(java.io.Writer writer,
                     java.lang.String text)
              throws java.io.IOException
A convenience method. Writes the receiver onto writer, followed by text.

Parameters:
writer - Output stream.
text - Text to follow representation of the receiver on the stream.
Throws:
java.io.IOException

isWhitespace

public boolean isWhitespace()
Returns true if the XToken represents whitespace. This is a helper method for scanners and parsers; it tells them that the token can be treated simply as a separator. Subclasses such as XComment and XText may return true.

Returns:
false. May be overridden in subclasses.

toWriter

public abstract void toWriter(java.io.Writer writer)
                       throws java.io.IOException
Writes a textual representation of the receiver onto writer

Parameters:
writer - Output stream.
Throws:
java.io.IOException

toString

public abstract java.lang.String toString()
Returns a textual representation of the receiver in a String

Overrides:
toString in class java.lang.Object
Returns:
Textual representation of receiver.

matches

public abstract boolean matches(XToken token)
Returns true if the receiver is the same "type" of XToken as other. How "same type" is interpreted varies from subclass to subclass. For instance, a comment matches any other comment no matter what text they contain, but a string only matches a string if they are equal. A tag with attributes matches another tag with the same name and attribute names, even if the values of the attributes are not the same. This method is used by scanners and tokens looking for a specific class of XToken.

Parameters:
token - XToken to be compared.
Returns:
true if the receiver equals other.
See Also:
equals(org.openadaptor.simplexml.XToken)

equals

public abstract boolean equals(XToken other)
Returns true if the receiver exactly matches other. This method will be used by scanners and parsers looking for exact matches of e.g. comments, runs of text or tags.

Parameters:
other - XToken to be compared.
Returns:
true if the receiver equals other.
See Also:
matches(org.openadaptor.simplexml.XToken)

setReleased

public void setReleased(boolean flag)
Sets the object "reuse" status

Specified by:
setReleased in interface ReusableObject

isReleased

public boolean isReleased()
Returns "reuse" status of object.

Specified by:
isReleased in interface ReusableObject
Returns:
YES is the object if ready for reuse.