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 Details

  • Constructor Details

    • AbstractCharReplacementEncoder

      public AbstractCharReplacementEncoder(CodecIdentifier codecIdentifier)
  • Method Details

    • escapeCharacter

      protected abstract String escapeCharacter(char ch, char previousChar)
      Escape the character, return null if no replacement has to be made
      Parameters:
      ch - the character to escape
      previousChar - the previous char
      Returns:
      the replacement string, null if no replacement has to be made
    • encode

      public Object encode(Object o)
      Description copied from interface: Encoder
      Encode given input object
      Specified by:
      encode in interface Encoder
      Parameters:
      o - the input object
      Returns:
      the encoded object
    • doCharReplacementEncoding

      protected final Object doCharReplacementEncoding(Object o)
    • convertToString

      protected String convertToString(Object o)
    • escapeCharSequence

      protected Object escapeCharSequence(CharSequence str)
    • encodeToWriter

      public void encodeToWriter(CharSequence str, int off, int len, Writer writer, EncodingState encodingState) throws IOException
      Specified by:
      encodeToWriter in interface EncodesToWriter
      Throws:
      IOException
    • encodeToWriter

      public void encodeToWriter(char[] buf, int off, int len, Writer writer, EncodingState encodingState) throws IOException
      Specified by:
      encodeToWriter in interface EncodesToWriter
      Throws:
      IOException
    • createChainingEncodesToWriter

      public EncodesToWriter createChainingEncodesToWriter(List<StreamingEncoder> encoders, boolean applyAdditionalFirst)
      Specified by:
      createChainingEncodesToWriter in interface EncodesToWriter
    • encodeToStream

      public void encodeToStream(Encoder thisInstance, CharSequence str, int off, int len, EncodedAppender appender, EncodingState encodingState) throws IOException
      Description copied from interface: StreamingEncoder
      Encode and append portion of source CharSequence to the appender.
      Specified by:
      encodeToStream in interface StreamingEncoder
      str - The source CharSequence
      off - Offset from which to start encoding characters
      len - Number of characters to encode
      appender - the appender to write to
      encodingState - the current encoding state
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • markEncoded

      public void markEncoded(CharSequence string)
      Description copied from interface: Encoder
      Mark this instance as encoded with this encoder in the current EncodingStateRegistry
      Specified by:
      markEncoded in interface Encoder
      Parameters:
      string - a CharSequence to mark as encoded
    • isSafe

      public boolean isSafe()
      Description copied from interface: Encoder
      Checks 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.
      Specified by:
      isSafe in interface Encoder
      Returns:
      true, if is safe
    • isApplyToSafelyEncoded

      public boolean isApplyToSafelyEncoded()
      Specified by:
      isApplyToSafelyEncoded in interface Encoder
      Returns:
      true if 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: CodecIdentifierProvider
      Gets the codec identifier information.
      Specified by:
      getCodecIdentifier in interface CodecIdentifierProvider
      Returns:
      the codec identifier information