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.
CDATA, CDATA_ENCODING, DEFAULT, ENCODING_OPTION_NAME, ESCAPED_CHARACTERS| Constructor and Description |
|---|
BaseMixedContentEncodingStrategy() |
| Modifier and Type | Method and Description |
|---|---|
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 abstract boolean |
encodeAsCDATA(ElementDescriptor element)
Should the element described by the given
ElementDescriptor be encoded as a CDATA
section? |
protected String |
encodeInCDATA(String bodyContent)
Wraps the given content into a CDATA section.
|
protected String |
escapeCharacters(String bodyContent)
Escapes a sequence of body content.
|
protected String escapeCharacters(String bodyContent)
bodyContent - the content whose character data should be escaped,
not nullprotected String encodeInCDATA(String bodyContent)
bodyContent - the content to be encoded into a CDATA
sectionpublic String encode(String bodyContent, ElementDescriptor element)
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)encode in class MixedContentEncodingStrategybodyContent - the raw (unescaped) character data, not nullelement - the ElementDescriptor describing the element
whose content is being encoded.MixedContentEncodingStrategy.encode(java.lang.String, org.apache.commons.betwixt.ElementDescriptor)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.
element - ElementDescriptor, not nullCDATA sectionCopyright © 2002-2013 Apache Software Foundation. All Rights Reserved.