Class AbstractCharReplacementEncoder

    • 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 escape
        previousChar - 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: Encoder
        Encode given input object
        Specified by:
        encode in interface Encoder
        Parameters:
        o - the input object
        Returns:
        the encoded 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:
        encodeToWriter in interface EncodesToWriter
        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:
        encodeToWriter in interface EncodesToWriter
        Throws:
        java.io.IOException
      • 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: 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:
        java.io.IOException - Signals that an I/O exception has occurred.
      • markEncoded

        public void markEncoded​(java.lang.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