org.apache.cocoon.components.serializers
Class EncodingSerializer

java.lang.Object
  extended by org.apache.cocoon.components.serializers.EncodingSerializer
All Implemented Interfaces:
Poolable, Recyclable, Component, Configurable, Serializer, SitemapOutputComponent, XMLConsumer, ContentHandler, LexicalHandler, Locator
Direct Known Subclasses:
XMLSerializer

public abstract class EncodingSerializer
extends Object
implements Serializer, Locator, Recyclable, Configurable

An abstract serializer supporting multiple encodings.

This serializer can accept the following configuration whenever it is declared into a sitemap:

 <serializer class="org.apache.cocoon.components.serializers..." ... >
   <encoding>myencoding</encoding>
   <indent>myindenting</indent>
   <setContentLength>false</setContentLength>
 </serializer>
 

The value indicated by myencoding must be replaced with a valid charset encoding (this serializer does not rely on the JVM for character encoding, you can look into the cocoon-serializers-charsets JAR file for a list).

The value indicated by myindenting will control the indenting level for each element.

The value indicated by setContentLength determines if the serializer sets the Content-Length HTTP header. The parameter is optional, the default value is false.

Version:
CVS $Id: EncodingSerializer.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Field Summary
static int ATTRIBUTE_LENGTH
          The length of the array of strings representing an attribute.
static int ATTRIBUTE_LOCAL
          The position of the local name in the attributes array.
static int ATTRIBUTE_NSURI
          The position of the namespace URI in the attributes array.
static int ATTRIBUTE_QNAME
          The position of the qualified name in the attributes array.
static int ATTRIBUTE_VALUE
          The position of the value in the attributes array.
protected  Charset charset
          The Charset associated with the character encoding.
protected  int indentPerLevel
          Per level indent spaces
protected  Namespaces namespaces
          The Namespace associated with this instance.
 
Fields inherited from interface org.apache.cocoon.serialization.Serializer
ROLE
 
Constructor Summary
protected EncodingSerializer(Encoder encoder)
          Create a new instance of this EncodingSerializer
 
Method Summary
abstract  void body(String uri, String local, String qual)
          Receive notification of the beginning of the document body.
 void characters(char[] ch, int start, int length)
           
abstract  void charactersImpl(char[] ch, int start, int length)
          Receive character notifications
 void configure(Configuration conf)
          Set the configurations for this serializer.
protected  void encode(char[] data)
          Encode and write an array of characters.
protected  void encode(char[] data, int start, int length)
          Encode and write a specific part of an array of characters.
protected  void encode(String data)
          Encode and write a String
 void endDocument()
          Receive notification of the end of a document.
 void endElement(String nsuri, String local, String qual)
          Receive notification of the end of an element.
abstract  void endElementImpl(String uri, String local, String qual)
          Receive notification of the end of an element.
 void endPrefixMapping(String prefix)
          End the scope of a prefix-URI mapping.
protected  void flush()
          Flush the stream.
 int getColumnNumber()
          Return the column number where the current document event ends.
 int getLineNumber()
          Return the line number where the current document event ends.
protected  String getLocation()
          Return a String describing the current location.
 String getPublicId()
          Return the public identifier for the current document event.
 String getSystemId()
          Return the system identifier for the current document event.
 void recycle()
          Reset this EncodingSerializer.
 void setDocumentLocator(Locator locator)
          Receive an object for locating the origin of SAX document events.
 void setOutputStream(OutputStream out)
          Set the OutputStream where this serializer will write data to.
 boolean shouldSetContentLength()
          Test if the component wants to set the content length.
 void startDocument()
          Receive notification of the beginning of a document.
 void startElement(String nsuri, String local, String qual, Attributes attributes)
          Receive notification of the beginning of an element.
abstract  void startElementImpl(String uri, String local, String qual, String[][] namespaces, String[][] attributes)
          Receive notification of the beginning of an element.
 void startPrefixMapping(String prefix, String uri)
          Begin the scope of a prefix-URI Namespace mapping.
protected  void write(char[] data)
          Write an array of characters.
protected  void write(char[] data, int start, int length)
          Write a portion of an array of characters.
protected  void write(int c)
          Write a single character.
protected  void write(String data)
          Write a string.
protected  void write(String data, int start, int length)
          Write a portion of a string.
protected  void writeIndent(int indent)
          Write out character to indent the output according to the level of nesting
protected  void writeln()
          Write a end-of-line character.
protected  void writeln(String data)
          Write a string and a end-of-line character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xml.sax.ContentHandler
ignorableWhitespace, processingInstruction, skippedEntity
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity
 
Methods inherited from interface org.apache.cocoon.sitemap.SitemapOutputComponent
getMimeType
 

Field Detail

ATTRIBUTE_NSURI

public static final int ATTRIBUTE_NSURI
The position of the namespace URI in the attributes array.

See Also:
Constant Field Values

ATTRIBUTE_LOCAL

public static final int ATTRIBUTE_LOCAL
The position of the local name in the attributes array.

See Also:
Constant Field Values

ATTRIBUTE_QNAME

public static final int ATTRIBUTE_QNAME
The position of the qualified name in the attributes array.

See Also:
Constant Field Values

ATTRIBUTE_VALUE

public static final int ATTRIBUTE_VALUE
The position of the value in the attributes array.

See Also:
Constant Field Values

ATTRIBUTE_LENGTH

public static final int ATTRIBUTE_LENGTH
The length of the array of strings representing an attribute.

See Also:
Constant Field Values

charset

protected Charset charset
The Charset associated with the character encoding.


namespaces

protected Namespaces namespaces
The Namespace associated with this instance.


indentPerLevel

protected int indentPerLevel
Per level indent spaces

Constructor Detail

EncodingSerializer

protected EncodingSerializer(Encoder encoder)
Create a new instance of this EncodingSerializer

Method Detail

shouldSetContentLength

public boolean shouldSetContentLength()
Test if the component wants to set the content length.

Specified by:
shouldSetContentLength in interface SitemapOutputComponent

recycle

public void recycle()
Reset this EncodingSerializer.

Specified by:
recycle in interface Recyclable

setOutputStream

public void setOutputStream(OutputStream out)
                     throws IOException
Set the OutputStream where this serializer will write data to.

Specified by:
setOutputStream in interface SitemapOutputComponent
Parameters:
out - The OutputStream used for output.
Throws:
IOException

configure

public void configure(Configuration conf)
               throws ConfigurationException
Set the configurations for this serializer.

Specified by:
configure in interface Configurable
Throws:
ConfigurationException

encode

protected void encode(String data)
               throws SAXException
Encode and write a String

Throws:
SAXException

encode

protected void encode(char[] data)
               throws SAXException
Encode and write an array of characters.

Throws:
SAXException

encode

protected void encode(char[] data,
                      int start,
                      int length)
               throws SAXException
Encode and write a specific part of an array of characters.

Throws:
SAXException

setDocumentLocator

public final void setDocumentLocator(Locator locator)
Receive an object for locating the origin of SAX document events.

Specified by:
setDocumentLocator in interface ContentHandler

getPublicId

public String getPublicId()
Return the public identifier for the current document event.

Specified by:
getPublicId in interface Locator
Returns:
A String containing the public identifier, or null if none is available.

getSystemId

public String getSystemId()
Return the system identifier for the current document event.

Specified by:
getSystemId in interface Locator
Returns:
A String containing the system identifier, or null if none is available.

getLineNumber

public int getLineNumber()
Return the line number where the current document event ends.

Specified by:
getLineNumber in interface Locator
Returns:
The line number, or -1 if none is available.

getColumnNumber

public int getColumnNumber()
Return the column number where the current document event ends.

Specified by:
getColumnNumber in interface Locator
Returns:
The column number, or -1 if none is available.

getLocation

protected String getLocation()
Return a String describing the current location.


flush

protected void flush()
              throws SAXException
Flush the stream.

Throws:
SAXException

write

protected void write(char[] data)
              throws SAXException
Write an array of characters.

Throws:
SAXException

write

protected void write(char[] data,
                     int start,
                     int length)
              throws SAXException
Write a portion of an array of characters.

Throws:
SAXException

write

protected void write(int c)
              throws SAXException
Write a single character.

Throws:
SAXException

write

protected void write(String data)
              throws SAXException
Write a string.

Throws:
SAXException

write

protected void write(String data,
                     int start,
                     int length)
              throws SAXException
Write a portion of a string.

Throws:
SAXException

writeln

protected void writeln()
                throws SAXException
Write a end-of-line character.

Throws:
SAXException

writeln

protected void writeln(String data)
                throws SAXException
Write a string and a end-of-line character.

Throws:
SAXException

writeIndent

protected void writeIndent(int indent)
                    throws SAXException
Write out character to indent the output according to the level of nesting

Parameters:
indent -
Throws:
SAXException

startDocument

public void startDocument()
                   throws SAXException
Receive notification of the beginning of a document.

Specified by:
startDocument in interface ContentHandler
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Receive notification of the end of a document.

Specified by:
endDocument in interface ContentHandler
Throws:
SAXException

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Begin the scope of a prefix-URI Namespace mapping.

Specified by:
startPrefixMapping in interface ContentHandler
Throws:
SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
End the scope of a prefix-URI mapping.

Specified by:
endPrefixMapping in interface ContentHandler
Throws:
SAXException

startElement

public void startElement(String nsuri,
                         String local,
                         String qual,
                         Attributes attributes)
                  throws SAXException
Receive notification of the beginning of an element.

Specified by:
startElement in interface ContentHandler
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
Throws:
SAXException

endElement

public void endElement(String nsuri,
                       String local,
                       String qual)
                throws SAXException
Receive notification of the end of an element.

Specified by:
endElement in interface ContentHandler
Throws:
SAXException

body

public abstract void body(String uri,
                          String local,
                          String qual)
                   throws SAXException
Receive notification of the beginning of the document body.

Parameters:
uri - The namespace URI of the root element.
local - The local name of the root element.
qual - The fully-qualified name of the root element.
Throws:
SAXException

startElementImpl

public abstract void startElementImpl(String uri,
                                      String local,
                                      String qual,
                                      String[][] namespaces,
                                      String[][] attributes)
                               throws SAXException
Receive notification of the beginning of an element.

Parameters:
uri - The namespace URI of the root element.
local - The local name of the root element.
qual - The fully-qualified name of the root element.
namespaces - An array of String objects containing the namespaces to be declared by this element.
attributes - An array of String objects containing all attributes of this element.
Throws:
SAXException

charactersImpl

public abstract void charactersImpl(char[] ch,
                                    int start,
                                    int length)
                             throws SAXException
Receive character notifications

Parameters:
ch -
start -
length -
Throws:
SAXException

endElementImpl

public abstract void endElementImpl(String uri,
                                    String local,
                                    String qual)
                             throws SAXException
Receive notification of the end of an element.

Parameters:
uri - The namespace URI of the root element.
local - The local name of the root element.
qual - The fully-qualified name of the root element.
Throws:
SAXException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.