org.apache.commons.betwixt.strategy
Class BaseMixedContentEncodingStrategy

java.lang.Object
  extended by org.apache.commons.betwixt.strategy.MixedContentEncodingStrategy
      extended by org.apache.commons.betwixt.strategy.BaseMixedContentEncodingStrategy

public abstract class BaseMixedContentEncodingStrategy
extends MixedContentEncodingStrategy

Basic implementation for MixedContentEncodingStrategy supports variations of most common use case.

This supports subclasses that choose to encode body content either as a CDATA section or by escaping the characters. Implementations should override encodeAsCDATA(org.apache.commons.betwixt.ElementDescriptor) with an appropriate decision algorithm.

Since:
0.5
Author:
Apache Commons Team

Field Summary
 
Fields inherited from class org.apache.commons.betwixt.strategy.MixedContentEncodingStrategy
CDATA, CDATA_ENCODING, DEFAULT, ENCODING_OPTION_NAME, ESCAPED_CHARACTERS
 
Constructor Summary
BaseMixedContentEncodingStrategy()
           
 
Method Summary
 java.lang.String encode(java.lang.String bodyContent, ElementDescriptor element)
          Encodes the given body content by either escaping the character data or by encoding within a CDATA section.
protected abstract  boolean encodeAsCDATA(ElementDescriptor element)
          Should the element described by the given ElementDescriptor be encoded as a CDATA section?
protected  java.lang.String encodeInCDATA(java.lang.String bodyContent)
          Wraps the given content into a CDATA section.
protected  java.lang.String escapeCharacters(java.lang.String bodyContent)
          Escapes a sequence of body content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseMixedContentEncodingStrategy

public BaseMixedContentEncodingStrategy()
Method Detail

escapeCharacters

protected java.lang.String escapeCharacters(java.lang.String bodyContent)
Escapes a sequence of body content.

Parameters:
bodyContent - the content whose character data should be escaped, not null
Returns:
the escaped character data, not null

encodeInCDATA

protected java.lang.String encodeInCDATA(java.lang.String bodyContent)
Wraps the given content into a CDATA section.

Parameters:
bodyContent - the content to be encoded into a CDATA section
Returns:
the content wrapped inside a CDATA section, not null

encode

public java.lang.String encode(java.lang.String bodyContent,
                               ElementDescriptor element)
Encodes the given body content by either escaping the character data or by encoding within a CDATA section. The algorithm used to decide whether a particular element's mixed should be escaped is delegated to the concrete subclass through encodeAsCDATA(org.apache.commons.betwixt.ElementDescriptor)

Specified by:
encode in class MixedContentEncodingStrategy
Parameters:
bodyContent - the raw (unescaped) character data, not null
element - the ElementDescriptor describing the element whose content is being encoded.
Returns:
the encoded (escaped) character data, not null
See Also:
MixedContentEncodingStrategy.encode(java.lang.String, org.apache.commons.betwixt.ElementDescriptor)

encodeAsCDATA

protected abstract boolean encodeAsCDATA(ElementDescriptor element)

Should the element described by the given ElementDescriptor be encoded as a CDATA section?

Usage: subclasses should provide a strategy to determine whether an element should be encoded using a CDATA section.

Parameters:
element - ElementDescriptor, not null
Returns:
true if the element should be encoded as a CDATA section


Copyright © 2002-2008 The Apache Software Foundation. All Rights Reserved.