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 java.lang.Object implements Encoder, StreamingEncoder, EncodesToWriter
Abstract base class for implementing encoders that do character replacements Implements theStreamingEncoderinterface that enables efficient streaming encoding- Since:
- 2.3
-
-
Field Summary
Fields Modifier and Type Field Description protected CodecIdentifiercodecIdentifier
-
Constructor Summary
Constructors Constructor Description AbstractCharReplacementEncoder(CodecIdentifier codecIdentifier)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringconvertToString(java.lang.Object o)EncodesToWritercreateChainingEncodesToWriter(java.util.List<StreamingEncoder> encoders, boolean applyAdditionalFirst)protected java.lang.ObjectdoCharReplacementEncoding(java.lang.Object o)java.lang.Objectencode(java.lang.Object o)Encode given input objectvoidencodeToStream(Encoder thisInstance, java.lang.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, java.io.Writer writer, EncodingState encodingState)voidencodeToWriter(java.lang.CharSequence str, int off, int len, java.io.Writer writer, EncodingState encodingState)protected abstract java.lang.StringescapeCharacter(char ch, char previousChar)Escape the character, return null if no replacement has to be madeprotected java.lang.ObjectescapeCharSequence(java.lang.CharSequence str)CodecIdentifiergetCodecIdentifier()Gets the codec identifier information.booleanisApplyToSafelyEncoded()booleanisSafe()Checks if this encoder is XSS "safe".voidmarkEncoded(java.lang.CharSequence string)Mark this instance as encoded with this encoder in the currentEncodingStateRegistry
-
-
-
Field Detail
-
codecIdentifier
protected CodecIdentifier codecIdentifier
-
-
Constructor Detail
-
AbstractCharReplacementEncoder
public AbstractCharReplacementEncoder(CodecIdentifier codecIdentifier)
-
-
Method Detail
-
escapeCharacter
protected abstract java.lang.String escapeCharacter(char ch, char previousChar)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
public java.lang.Object encode(java.lang.Object o)
Description copied from interface:EncoderEncode given input object
-
doCharReplacementEncoding
protected final java.lang.Object doCharReplacementEncoding(java.lang.Object o)
-
convertToString
protected java.lang.String convertToString(java.lang.Object o)
-
escapeCharSequence
protected java.lang.Object escapeCharSequence(java.lang.CharSequence str)
-
encodeToWriter
public void encodeToWriter(java.lang.CharSequence str, int off, int len, java.io.Writer writer, EncodingState encodingState) throws java.io.IOException- Specified by:
encodeToWriterin interfaceEncodesToWriter- Throws:
java.io.IOException
-
encodeToWriter
public void encodeToWriter(char[] buf, int off, int len, java.io.Writer writer, EncodingState encodingState) throws java.io.IOException- Specified by:
encodeToWriterin interfaceEncodesToWriter- Throws:
java.io.IOException
-
createChainingEncodesToWriter
public EncodesToWriter createChainingEncodesToWriter(java.util.List<StreamingEncoder> encoders, boolean applyAdditionalFirst)
- Specified by:
createChainingEncodesToWriterin interfaceEncodesToWriter
-
encodeToStream
public void encodeToStream(Encoder thisInstance, java.lang.CharSequence str, int off, int len, EncodedAppender appender, EncodingState encodingState) throws java.io.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:
java.io.IOException- Signals that an I/O exception has occurred.
-
markEncoded
public void markEncoded(java.lang.CharSequence string)
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
public CodecIdentifier getCodecIdentifier()
Description copied from interface:CodecIdentifierProviderGets the codec identifier information.- Specified by:
getCodecIdentifierin interfaceCodecIdentifierProvider- Returns:
- the codec identifier information
-
-