xmlBlaster 2.1.0 API

org.xmlBlaster.util
Class XmlBuffer

java.lang.Object
  extended by org.xmlBlaster.util.XmlBuffer

public class XmlBuffer
extends java.lang.Object

Same as StringBuilder but has the additional method appendEscaped() which escapes predefined XML identities.

Author:
mr@marcelruff.info

Field Summary
private static char[] AMP
           
private static char[] APOS
           
private  java.lang.StringBuilder buf
           
private static char[] GT
           
private static char[] LT
           
private static char[] NULL
           
private static char[] QUOT
           
private static char[] SLASH_R
           
 
Constructor Summary
XmlBuffer(int len)
           
 
Method Summary
 XmlBuffer append(boolean b)
          Aquivalent to a StringBuilder.append().
 XmlBuffer append(double ln)
          Aquivalent to a StringBuilder.append().
 XmlBuffer append(float ln)
          Aquivalent to a StringBuilder.append().
 XmlBuffer append(long ln)
          Aquivalent to a StringBuilder.append().
 XmlBuffer append(java.lang.String str)
          Aquivalent to a StringBuilder.append().
static void append(java.lang.StringBuilder buf, java.lang.String text)
          Escape predefined xml entities (&, <, >, ', ").
static void appendAttr(java.lang.StringBuilder buf, java.lang.String text)
          Escape predefined xml entities (\0, ', ", \r).
 XmlBuffer appendAttributeEscaped(java.lang.String text)
          Escape predefined xml entities (', ", \r) for attributes.
 XmlBuffer appendCdataEscaped(java.lang.String str)
          Sorround string with CDATA
 XmlBuffer appendCsvEscaped(java.lang.String text, char separator)
          Supports only "," -> "," and ";" -> "%3B"
 XmlBuffer appendEscaped(java.lang.String text)
          Escape predefined xml entities (&, <, >, ', ").
 XmlBuffer appendTag(java.lang.String tagName)
          Appends a tag name (e.g.
static java.lang.String escape(java.lang.String text)
          Escape predefined xml entities (&, <, >, ', ").
 java.lang.StringBuilder getRawBuffer()
           
 int length()
           
static void main(java.lang.String[] args)
           
 void reset()
          Removes all buffer entries.
private static boolean startsWith(java.lang.String xml, char[] ch, int pos)
           
 java.lang.String toString()
           
static java.lang.String unEscapeXml(java.lang.String xml)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buf

private java.lang.StringBuilder buf

AMP

private static final char[] AMP

LT

private static final char[] LT

GT

private static final char[] GT

QUOT

private static final char[] QUOT

APOS

private static final char[] APOS

SLASH_R

private static final char[] SLASH_R

NULL

private static final char[] NULL
Constructor Detail

XmlBuffer

public XmlBuffer(int len)
Method Detail

appendEscaped

public XmlBuffer appendEscaped(java.lang.String text)
Escape predefined xml entities (&, <, >, ', "). Additionally the '\0' is escaped.

Parameters:
text -
Returns:
The escaped text is appended to the StringBuilder.

appendAttributeEscaped

public XmlBuffer appendAttributeEscaped(java.lang.String text)
Escape predefined xml entities (', ", \r) for attributes. Additionally the '\0' is escaped.

Parameters:
text -
Returns:
The escaped text is appended to the StringBuilder.

appendTag

public XmlBuffer appendTag(java.lang.String tagName)
Appends a tag name (e.g. "bla" of a tag called ). Currently is a normal append()

Parameters:
tagName - Could in future escape invalid tokens '<' and '&' in a tag name.
Returns:

appendCdataEscaped

public XmlBuffer appendCdataEscaped(java.lang.String str)
Sorround string with CDATA

Parameters:
str -
Returns:

appendCsvEscaped

public XmlBuffer appendCsvEscaped(java.lang.String text,
                                  char separator)
Supports only "," -> "," and ";" -> "%3B"

Parameters:
text - "bla,bla"
separator - ','
Returns:
"bla,bla"

append

public XmlBuffer append(java.lang.String str)
Aquivalent to a StringBuilder.append().


append

public XmlBuffer append(long ln)
Aquivalent to a StringBuilder.append().


append

public XmlBuffer append(float ln)
Aquivalent to a StringBuilder.append().


append

public XmlBuffer append(double ln)
Aquivalent to a StringBuilder.append().


append

public XmlBuffer append(boolean b)
Aquivalent to a StringBuilder.append().


getRawBuffer

public java.lang.StringBuilder getRawBuffer()

length

public int length()

reset

public void reset()
Removes all buffer entries. Calling append fills new data to the beginning of the buffer.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

escape

public static java.lang.String escape(java.lang.String text)
Escape predefined xml entities (&, <, >, ', "). Additionally the '\0' is escaped.

Parameters:
text - e.g. "Hello < and &"
Returns:
"Hello < and &"

append

public static void append(java.lang.StringBuilder buf,
                          java.lang.String text)
Escape predefined xml entities (&, <, >, ', "). Additionally the '\0' is escaped.

Parameters:
text -

appendAttr

public static void appendAttr(java.lang.StringBuilder buf,
                              java.lang.String text)
Escape predefined xml entities (\0, ', ", \r). for attribute notation Additionally the '\0' is escaped.

Parameters:
text -

startsWith

private static final boolean startsWith(java.lang.String xml,
                                        char[] ch,
                                        int pos)

unEscapeXml

public static final java.lang.String unEscapeXml(java.lang.String xml)

main

public static void main(java.lang.String[] args)
                 throws XmlBlasterException
Throws:
XmlBlasterException

xmlBlaster 2.1.0 API

Copyright © 1999-2011 The xmlBlaster.org contributers.