class LazyEscapingCharSequence extends AbstractLazyCharSequence {

    private final IEngineConfiguration configuration;
    private final TemplateMode templateMode;
    private final Object input;


    public LazyEscapingCharSequence(final IEngineConfiguration configuration, final TemplateMode templateMode, final Object input) {

        super();

        if (configuration == null) {
            throw new IllegalArgumentException("Engine Configuraion is null, which is forbidden");
        }
        if (templateMode == null) {
            throw new IllegalArgumentException("Template Mode is null, which is forbidden");
        }

        this.configuration = configuration;
        this.templateMode = templateMode;
        this.input = input;

    }




    @Override
    protected String resolveText() {
        final Writer stringWriter = new FastStringWriter();
        produceEscapedOutput(stringWriter);
        return stringWriter.toString();
    }


    @Override
    protected void writeUnresolved(final Writer writer) throws IOException {
        produceEscapedOutput(writer);
    }





    private void produceEscapedOutput(final Writer writer) {<FILL_FUNCTION_BODY>}


}


        /*
         * Producing ESCAPED output is somewhat simple in HTML or XML modes, as it simply consists of converting
         * input into a String and HTML-or-XML-escaping it.
         *
         * But for JavaScript or CSS, it becomes a bit more complicated than that. JavaScript will output a complete
         * literal (incl. single quotes) if input is a String or a non-recognized value type, but will print input
         * as an object, number, boolean, etc. if it is recognized to be of one of these types. CSS will output
         * quoted literals.
         *
         * Note that, when in TEXT mode, HTML escaping will be used (as TEXT is many times used for
         * processing HTML templates)
         */
        try {

            switch (templateMode) {

                case TEXT:
                    // fall-through
                case HTML:
                    if (this.input != null) {
                        HtmlEscape.escapeHtml4Xml(this.input.toString(), writer);
                    }
                    return;
                case XML:
                    if (this.input != null) {
                        // Note we are outputting a body content here, so it is important that we use the version
                        // of XML escaping meant for content, not attributes (slight differences)
                        XmlEscape.escapeXml10(this.input.toString(), writer);
                    }
                    return;
                case JAVASCRIPT:
                    final IStandardJavaScriptSerializer javaScriptSerializer = StandardSerializers.getJavaScriptSerializer(this.configuration);
                    javaScriptSerializer.serializeValue(this.input, writer);
                    return;
                case CSS:
                    final IStandardCSSSerializer cssSerializer = StandardSerializers.getCSSSerializer(this.configuration);
                    cssSerializer.serializeValue(this.input, writer);
                    return;
                case RAW:
                    if (this.input != null) {
                        writer.write(this.input.toString());
                    }
                    return;
                default:
                    throw new TemplateProcessingException(
                            "Unrecognized template mode " + templateMode + ". Cannot produce escaped output for " +
                            "this template mode.");
            }

        } catch (final IOException e) {
            throw new TemplateProcessingException("An error happened while trying to produce escaped output", e);
        }

    
<methods>public final char charAt(int) ,public final boolean equals(java.lang.Object) ,public final int hashCode() ,public final int length() ,public final java.lang.CharSequence subSequence(int, int) ,public final java.lang.String toString() ,public final void write(java.io.Writer) throws java.io.IOException<variables>private java.lang.String resolvedText