Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.znerd.xmlenc
Class XMLEncoder  view XMLEncoder download XMLEncoder.java

java.lang.Object
  extended byorg.znerd.xmlenc.XMLEncoder

public class XMLEncoder
extends java.lang.Object

Encodes character streams for an XML document.

The following encodings are supported:

Since:
xmlenc 0.1
Version:
$Revision: 1.210 $ $Date: 2005/10/24 09:54:53 $

Field Summary
private  java.lang.String _encoding
          The name of the encoding.
private  char[] _encodingCharArray
          The name of the encoding as a character array.
private  boolean _sevenBitEncoding
          Flag that indicates whether the encoding is based on the ISO 646 character set.
private static char[] AMPERSAND_HASH
          Character array representing the string "&#".
private static char[] DECLARATION_END
          The last part of a declaration, after the encoding.
private static int DECLARATION_END_LENGTH
          The length of DECLARATION_END.
private static char[] DECLARATION_START
          The first part of a declaration, before the encoding.
private static int DECLARATION_START_LENGTH
          The length of DECLARATION_START.
private static char[] EQUALS_APOSTROPHE
          Character array representing the string "='".
private static char[] EQUALS_QUOTE
          Character array representing the string "=\"".
private static char[] ESC_AMPERSAND
          Character array representing the string "&".
private static char[] ESC_APOSTROPHE
          Character array representing the string "'".
private static char[] ESC_GREATER_THAN
          Character array representing the string ">".
private static char[] ESC_LESS_THAN
          Character array representing the string "<".
private static char[] ESC_QUOTE
          Character array representing the string "&apos;".
 
Constructor Summary
XMLEncoder(java.lang.String encoding)
          Deprecated. Deprecated since xmlenc 0.47. Use the factory method getEncoder(String) 55 instead.
 
Method Summary
 void attribute(java.io.Writer out, java.lang.String name, java.lang.String value, char quotationMark, boolean escapeAmpersands)
          Writes an attribute assignment.
 void declaration(java.io.Writer out)
          Writes an XML declaration.
static XMLEncoder getEncoder(java.lang.String encoding)
          Retrieves an XMLEncoder for the specified encoding.
 java.lang.String getEncoding()
          Returns the encoding.
 void text(java.io.Writer out, char c)
          Deprecated. Deprecated since xmlenc 0.51. Use the text method text(Writer, char, boolean) 55 instead.
 void text(java.io.Writer out, char[] ch, int start, int length, boolean escapeAmpersands)
          Writes text from the specified character array.
 void text(java.io.Writer out, char c, boolean escapeAmpersands)
          Writes the specified character.
 void text(java.io.Writer out, java.lang.String text, boolean escapeAmpersands)
          Writes the specified text.
 void whitespace(java.io.Writer out, char[] ch, int start, int length)
          Writes whitespace from the specified character array.
 void whitespace(java.io.Writer out, java.lang.String s)
          Writes the specified whitespace string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DECLARATION_START

private static final char[] DECLARATION_START
The first part of a declaration, before the encoding.


DECLARATION_START_LENGTH

private static final int DECLARATION_START_LENGTH
The length of DECLARATION_START.


DECLARATION_END

private static final char[] DECLARATION_END
The last part of a declaration, after the encoding.


DECLARATION_END_LENGTH

private static final int DECLARATION_END_LENGTH
The length of DECLARATION_END.


ESC_GREATER_THAN

private static final char[] ESC_GREATER_THAN
Character array representing the string ">".


ESC_LESS_THAN

private static final char[] ESC_LESS_THAN
Character array representing the string "<".


ESC_AMPERSAND

private static final char[] ESC_AMPERSAND
Character array representing the string "&amp;".


ESC_APOSTROPHE

private static final char[] ESC_APOSTROPHE
Character array representing the string "&apos;".


ESC_QUOTE

private static final char[] ESC_QUOTE
Character array representing the string "&apos;".


AMPERSAND_HASH

private static final char[] AMPERSAND_HASH
Character array representing the string "&#".


EQUALS_APOSTROPHE

private static final char[] EQUALS_APOSTROPHE
Character array representing the string "='".


EQUALS_QUOTE

private static final char[] EQUALS_QUOTE
Character array representing the string "=\"".


_encoding

private final java.lang.String _encoding
The name of the encoding. Cannot be null.


_encodingCharArray

private final char[] _encodingCharArray
The name of the encoding as a character array. Cannot be null.


_sevenBitEncoding

private final boolean _sevenBitEncoding
Flag that indicates whether the encoding is based on the ISO 646 character set. The value is true if the encoding is a 7 bit encoding, or false if the encoding supports all Unicode characters.

Constructor Detail

XMLEncoder

public XMLEncoder(java.lang.String encoding)
           throws java.lang.IllegalArgumentException,
                  java.io.UnsupportedEncodingException
Deprecated. Deprecated since xmlenc 0.47. Use the factory method getEncoder(String) 55 instead.

Constructs a new XMLEncoder instance.

Method Detail

getEncoder

public static final XMLEncoder getEncoder(java.lang.String encoding)
                                   throws java.lang.IllegalArgumentException,
                                          java.io.UnsupportedEncodingException
Retrieves an XMLEncoder for the specified encoding. If no suitable instance can be returned, then an exception is thrown.


getEncoding

public java.lang.String getEncoding()
Returns the encoding.


declaration

public void declaration(java.io.Writer out)
                 throws java.lang.NullPointerException,
                        java.io.IOException
Writes an XML declaration.


text

public void text(java.io.Writer out,
                 java.lang.String text,
                 boolean escapeAmpersands)
          throws java.lang.NullPointerException,
                 InvalidXMLException,
                 java.io.IOException
Writes the specified text. Any characters that are non-printable in this encoding will be escaped.

It must be specified whether ampersands should be escaped. Unless ampersands are escaped, entity references can be written.


text

public void text(java.io.Writer out,
                 char[] ch,
                 int start,
                 int length,
                 boolean escapeAmpersands)
          throws java.lang.NullPointerException,
                 java.lang.IndexOutOfBoundsException,
                 InvalidXMLException,
                 java.io.IOException
Writes text from the specified character array. Any characters that are non-printable in this encoding will be escaped.

It must be specified whether ampersands should be escaped. Unless ampersands are escaped, entity references can be written.


text

public void text(java.io.Writer out,
                 char c)
          throws InvalidXMLException,
                 java.io.IOException
Deprecated. Deprecated since xmlenc 0.51. Use the text method text(Writer, char, boolean) 55 instead.

Writes the specified character. If the character is non-printable in this encoding, then it will be escaped.

It is safe for this method to assume that the specified character does not need to be escaped unless the encoding does not support the character.


text

public void text(java.io.Writer out,
                 char c,
                 boolean escapeAmpersands)
          throws InvalidXMLException,
                 java.io.IOException
Writes the specified character. If the character is non-printable in this encoding, then it will be escaped.

It is safe for this method to assume that the specified character does not need to be escaped unless the encoding does not support the character.


whitespace

public void whitespace(java.io.Writer out,
                       java.lang.String s)
                throws java.lang.NullPointerException,
                       InvalidXMLException,
                       java.io.IOException
Writes the specified whitespace string.


whitespace

public void whitespace(java.io.Writer out,
                       char[] ch,
                       int start,
                       int length)
                throws java.lang.NullPointerException,
                       java.lang.IndexOutOfBoundsException,
                       InvalidXMLException,
                       java.io.IOException
Writes whitespace from the specified character array.


attribute

public void attribute(java.io.Writer out,
                      java.lang.String name,
                      java.lang.String value,
                      char quotationMark,
                      boolean escapeAmpersands)
               throws java.lang.NullPointerException,
                      java.io.IOException
Writes an attribute assignment.