Search in sources :

Example 1 with StreamingEncoderWriter

use of org.grails.encoder.StreamingEncoderWriter in project grails-core by grails.

the class JSONObject method writeQuoted.

static void writeQuoted(Writer writer, Object value) throws IOException {
    if (useStreamingJavascriptEncoder) {
        writer.write("\"");
        if (value.getClass() == String.class || value.getClass() == StringBuilder.class || value.getClass() == StringBuffer.class) {
            encodeToWriter((CharSequence) value, writer);
        } else if (value instanceof StreamingEncoderWritable) {
            ((StreamingEncoderWritable) value).encodeTo(writer, javascriptEncoderStateless);
        } else if (value instanceof Writable) {
            ((Writable) value).writeTo(new StreamingEncoderWriter(writer, javascriptEncoder, null));
        } else {
            encodeToWriter(value.toString(), writer);
        }
        writer.write("\"");
    } else {
        writer.write(valueToString(value));
    }
}
Also used : StreamingEncoderWriter(org.grails.encoder.StreamingEncoderWriter) StreamingEncoderWritable(org.grails.encoder.StreamingEncoderWritable) Writable(groovy.lang.Writable) StreamingEncoderWritable(org.grails.encoder.StreamingEncoderWritable)

Example 2 with StreamingEncoderWriter

use of org.grails.encoder.StreamingEncoderWriter in project grails-core by grails.

the class GroovyPagesTemplateRenderer method wrapWriterWithEncoder.

private Writer wrapWriterWithEncoder(GrailsWebRequest webRequest, Map<String, Object> attrs, Writer out) {
    Object encodeAs = attrs.get(GroovyPage.ENCODE_AS_ATTRIBUTE_NAME);
    if (encodeAs != null) {
        Map<String, Object> codecSettings = WithCodecHelper.makeSettingsCanonical(encodeAs);
        String codecForTaglibs = (String) codecSettings.get(OutputEncodingSettings.TAGLIB_CODEC_NAME);
        if (codecForTaglibs != null) {
            Encoder encoder = WithCodecHelper.lookupEncoder(webRequest.getAttributes().getGrailsApplication(), codecForTaglibs);
            if (out instanceof EncodedAppenderWriterFactory) {
                out = ((EncodedAppenderWriterFactory) out).getWriterForEncoder(encoder, webRequest.getEncodingStateRegistry());
            } else if (encoder instanceof StreamingEncoder) {
                out = new StreamingEncoderWriter(out, (StreamingEncoder) encoder, webRequest.getEncodingStateRegistry());
            } else {
                out = new CodecPrintWriter(out, encoder, webRequest.getEncodingStateRegistry());
            }
        }
    }
    return out;
}
Also used : Encoder(org.grails.encoder.Encoder) StreamingEncoder(org.grails.encoder.StreamingEncoder) StreamingEncoderWriter(org.grails.encoder.StreamingEncoderWriter) GroovyObject(groovy.lang.GroovyObject) StreamingEncoder(org.grails.encoder.StreamingEncoder) CodecPrintWriter(org.grails.buffer.CodecPrintWriter) EncodedAppenderWriterFactory(org.grails.encoder.EncodedAppenderWriterFactory)

Aggregations

StreamingEncoderWriter (org.grails.encoder.StreamingEncoderWriter)2 GroovyObject (groovy.lang.GroovyObject)1 Writable (groovy.lang.Writable)1 CodecPrintWriter (org.grails.buffer.CodecPrintWriter)1 EncodedAppenderWriterFactory (org.grails.encoder.EncodedAppenderWriterFactory)1 Encoder (org.grails.encoder.Encoder)1 StreamingEncoder (org.grails.encoder.StreamingEncoder)1 StreamingEncoderWritable (org.grails.encoder.StreamingEncoderWritable)1