Package org.grails.encoder
Class AbstractCharReplacementEncoder
java.lang.Object
org.grails.encoder.AbstractCharReplacementEncoder
- All Implemented Interfaces:
CodecIdentifierProvider,Encoder,EncodesToWriter,StreamingEncoder
- Direct Known Subclasses:
BasicJSONEncoder,BasicXMLEncoder,HTML4Encoder,JavaScriptEncoder
public abstract class AbstractCharReplacementEncoder
extends Object
implements Encoder, StreamingEncoder, EncodesToWriter
Abstract base class for implementing encoders that do character replacements
Implements the
StreamingEncoder interface that enables efficient
streaming encoding- Since:
- 2.3
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcreateChainingEncodesToWriter(List<StreamingEncoder> encoders, boolean applyAdditionalFirst) protected final ObjectEncode given input objectvoidencodeToStream(Encoder thisInstance, CharSequence str, int off, int len, EncodedAppender appender, EncodingState encodingState) Encode and append portion of source CharSequence to the appender.voidencodeToWriter(char[] buf, int off, int len, Writer writer, EncodingState encodingState) voidencodeToWriter(CharSequence str, int off, int len, Writer writer, EncodingState encodingState) protected abstract StringescapeCharacter(char ch, char previousChar) Escape the character, return null if no replacement has to be madeprotected ObjectGets the codec identifier information.booleanbooleanisSafe()Checks if this encoder is XSS "safe".voidmarkEncoded(CharSequence string) Mark this instance as encoded with this encoder in the currentEncodingStateRegistry
-
Field Details
-
codecIdentifier
-
-
Constructor Details
-
AbstractCharReplacementEncoder
-
-
Method Details
-
escapeCharacter
Escape the character, return null if no replacement has to be made- Parameters:
ch- the character to escapepreviousChar- the previous char- Returns:
- the replacement string, null if no replacement has to be made
-
encode
Description copied from interface:EncoderEncode given input object -
doCharReplacementEncoding
-
convertToString
-
escapeCharSequence
-
encodeToWriter
public void encodeToWriter(CharSequence str, int off, int len, Writer writer, EncodingState encodingState) throws IOException - Specified by:
encodeToWriterin interfaceEncodesToWriter- Throws:
IOException
-
encodeToWriter
public void encodeToWriter(char[] buf, int off, int len, Writer writer, EncodingState encodingState) throws IOException - Specified by:
encodeToWriterin interfaceEncodesToWriter- Throws:
IOException
-
createChainingEncodesToWriter
public EncodesToWriter createChainingEncodesToWriter(List<StreamingEncoder> encoders, boolean applyAdditionalFirst) - Specified by:
createChainingEncodesToWriterin interfaceEncodesToWriter
-
encodeToStream
public void encodeToStream(Encoder thisInstance, CharSequence str, int off, int len, EncodedAppender appender, EncodingState encodingState) throws IOException Description copied from interface:StreamingEncoderEncode and append portion of source CharSequence to the appender.- Specified by:
encodeToStreamin interfaceStreamingEncoderstr- The source CharSequenceoff- Offset from which to start encoding characterslen- Number of characters to encodeappender- the appender to write toencodingState- the current encoding state- Throws:
IOException- Signals that an I/O exception has occurred.
-
markEncoded
Description copied from interface:EncoderMark this instance as encoded with this encoder in the currentEncodingStateRegistry- Specified by:
markEncodedin interfaceEncoder- Parameters:
string- a CharSequence to mark as encoded
-
isSafe
public boolean isSafe()Description copied from interface:EncoderChecks if this encoder is XSS "safe". This means that after appling this encoder, the characters have been escaped and are XSS safe to be included in HTML documents. -
isApplyToSafelyEncoded
public boolean isApplyToSafelyEncoded()- Specified by:
isApplyToSafelyEncodedin interfaceEncoder- Returns:
trueif this this codec should be applied to a buffer part that is already encoded with a safe encoder
-
getCodecIdentifier
Description copied from interface:CodecIdentifierProviderGets the codec identifier information.- Specified by:
getCodecIdentifierin interfaceCodecIdentifierProvider- Returns:
- the codec identifier information
-