public abstract class

BaseMixedContentEncodingStrategy

extends MixedContentEncodingStrategy
java.lang.Object
   ↳ org.apache.commons.betwixt.strategy.MixedContentEncodingStrategy
     ↳ org.apache.commons.betwixt.strategy.BaseMixedContentEncodingStrategy

Class Overview

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(ElementDescriptor) with an appropriate decision algorithm.

Summary

[Expand]
Inherited Constants
From class org.apache.commons.betwixt.strategy.MixedContentEncodingStrategy
[Expand]
Inherited Fields
From class org.apache.commons.betwixt.strategy.MixedContentEncodingStrategy
Public Constructors
BaseMixedContentEncodingStrategy()
Public Methods
String encode(String bodyContent, ElementDescriptor element)
Encodes the given body content by either escaping the character data or by encoding within a CDATA section.
Protected Methods
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.

String encodeInCDATA(String bodyContent)
Wraps the given content into a CDATA section.
String escapeCharacters(String bodyContent)
Escapes a sequence of body content.
[Expand]
Inherited Methods
From class org.apache.commons.betwixt.strategy.MixedContentEncodingStrategy
From class java.lang.Object

Public Constructors

public BaseMixedContentEncodingStrategy ()

Public Methods

public String encode (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(ElementDescriptor)

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

Protected Methods

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

protected String encodeInCDATA (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

protected String escapeCharacters (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