org.openadaptor.simplexml
Class XText

java.lang.Object
  extended by org.openadaptor.simplexml.XToken
      extended by org.openadaptor.simplexml.XText
All Implemented Interfaces:
ReusableObject
Direct Known Subclasses:
XWhitespace

public class XText
extends XToken

XText - represents free (non-markup) text in an XML document, or the text inside an XML comment.


Field Summary
protected  java.lang.String text
          plain text string
protected  java.lang.String xmlText
          XML encoded string (i.e.
 
Fields inherited from class org.openadaptor.simplexml.XToken
AMPERSAND, log, RCARET
 
Constructor Summary
XText()
          Creates a new XText containing null text
XText(java.lang.String text)
          Creates a new XText containing text Note text may be null.
XText(XScanner scanner, boolean isComment)
           
 
Method Summary
 boolean equals(XToken other)
          Returns true if other is an XText with identical text.
protected  void fromScanner(XScanner scanner, boolean isComment)
           
 java.lang.String getText()
          Returns the text of the XText in plaintext form.
 java.lang.String getTrimmedText()
          Returns the text, with leading and trailing whitepace trimmed.
 java.lang.String getXmlText()
          Returns the text of the receiver in XML encoded form.
static XText grab(java.lang.String text)
          Grabs an uninitialised XText, and sets it to text
static XText grab(XScanner scanner, boolean isComment)
          Grabs an uninitialised XText, and sets it from the scanner
 boolean isWhitespace()
          Returns true if the text contains only whitespace.
 boolean matches(XToken other)
          Returns true if other is an XText with identical text.
protected  void prepareForRelease()
           
static void printStats()
          Prints statistics for XTag reuse pool.
static void release(XText txt)
          releases an XText for reuse.
protected  void setText(java.lang.String s)
           
static java.lang.String textToXml(java.lang.String text)
          Translates plain text to XML encoded text.
 java.lang.String toString()
          Returns the XML encoded text of the receiver as a String.
 void toWriter(java.io.Writer writer)
          Writes the text of receiver onto writer.
static java.lang.String xmlToText(java.lang.String xmlText)
          Translates XML free text to plain text.
 
Methods inherited from class org.openadaptor.simplexml.XToken
_grabStringBuffer, _releaseStringBuffer, convertToPlaintext, getClassName, isReleased, printDebug, setReleased, toWriter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

text

protected java.lang.String text
plain text string


xmlText

protected java.lang.String xmlText
XML encoded string (i.e. < becomes &lt;

Constructor Detail

XText

public XText()
Creates a new XText containing null text


XText

public XText(java.lang.String text)
Creates a new XText containing text Note text may be null.

Parameters:
text - text string.

XText

public XText(XScanner scanner,
             boolean isComment)
      throws java.io.IOException,
             XParserException
Throws:
java.io.IOException
XParserException
Method Detail

grab

public static XText grab(java.lang.String text)
Grabs an uninitialised XText, and sets it to text


grab

public static XText grab(XScanner scanner,
                         boolean isComment)
                  throws java.io.IOException,
                         XParserException
Grabs an uninitialised XText, and sets it from the scanner

Returns:
XText initialisef from scanner, or null if scanner starts with markup.
Throws:
java.io.IOException
XParserException

release

public static void release(XText txt)
releases an XText for reuse.


printStats

public static void printStats()
Prints statistics for XTag reuse pool.

See Also:
AbstractObjectPool.printStats()

xmlToText

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

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

textToXml

public static java.lang.String textToXml(java.lang.String text)
Translates plain text to XML encoded text. Changes all occurrences of <,>,& etc. to &lt;, &gt; and &amp;.

Parameters:
text - plain text String.
Returns:
XML encoded version of text.

prepareForRelease

protected void prepareForRelease()

fromScanner

protected void fromScanner(XScanner scanner,
                           boolean isComment)
                    throws java.io.IOException,
                           XParserException
Throws:
java.io.IOException
XParserException

setText

protected void setText(java.lang.String s)

getText

public java.lang.String getText()
Returns the text of the XText in plaintext form. I.e. carets are represented as '<' and '>', not <, >.

Returns:
text of the XText (possibly null).

getXmlText

public java.lang.String getXmlText()
Returns the text of the receiver in XML encoded form. I.e. carets are represented as <, >, not '<' and '>'.

Returns:
text of the XText (possibly null).

getTrimmedText

public java.lang.String getTrimmedText()
Returns the text, with leading and trailing whitepace trimmed.

Returns:
trimmed text, or null if text was null.

isWhitespace

public boolean isWhitespace()
Returns true if the text contains only whitespace. Null text is treated as whitepace.

Overrides:
isWhitespace in class XToken
Returns:
false. May be overridden in subclasses.

toWriter

public void toWriter(java.io.Writer writer)
              throws java.io.IOException
Writes the text of receiver onto writer. Writes the text of the receiver (if not null) onto writer.

Specified by:
toWriter in class XToken
Parameters:
writer - Output stream.
Throws:
java.io.IOException

toString

public java.lang.String toString()
Returns the XML encoded text of the receiver as a String. Null text is converted to the empty string.

Specified by:
toString in class XToken
Returns:
XML encoded version of text.
See Also:
getXmlText()

matches

public boolean matches(XToken other)
Returns true if other is an XText with identical text. Returns true if other is an XText with identical text, or the receiver and other are both whitespace (return true in response to isWhitespace()).

Specified by:
matches in class XToken
Parameters:
other - XToken to be compared.
Returns:
true if the receiver equals other.
See Also:
XToken.isWhitespace()

equals

public boolean equals(XToken other)
Returns true if other is an XText with identical text. Returns true if other is an XText with identical text.

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