use of org.grails.encoder.StreamingEncoder in project grails-core by grails.
the class BasicCodecLookup method createChainedCodecInstance.
protected <T extends CodecIdentifierProvider> T createChainedCodecInstance(String codecName, ConcurrentMap<String, T> map, Class<T> returnType) {
String[] codecs = codecName.split(",");
List<T> codecInstances = new ArrayList<T>(codecs.length);
for (int i = 0; i < codecs.length; i++) {
T codecInstance = map.get(codecs[i]);
if (codecInstance != null) {
codecInstances.add(codecInstance);
}
}
if (returnType == Encoder.class) {
List<StreamingEncoder> streamingEncoders = ChainedEncoders.toStreamingEncoders((List<Encoder>) codecInstances);
if (streamingEncoders == null) {
throw new RuntimeException("ChainedEncoder only supports StreamingEncoder instances. Couldn't build chained encoder for '" + codecName + "'");
} else {
return (T) ChainedEncoder.createFor(streamingEncoders);
}
} else {
Collections.reverse(codecInstances);
return (T) new ChainedDecoder(codecInstances.toArray(new Decoder[codecInstances.size()]));
}
}
use of org.grails.encoder.StreamingEncoder 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;
}
use of org.grails.encoder.StreamingEncoder in project grails-core by grails.
the class DefaultGrailsCodecClass method initializeCodec.
private void initializeCodec() {
if (initialized)
return;
initialized = true;
Integer orderSetting = getStaticPropertyValue("order", Integer.class);
if (orderSetting != null) {
order = orderSetting;
}
Object instance = getReferenceInstance();
if (Encoder.class.isAssignableFrom(getClazz())) {
encoder = (Encoder) instance;
encoder = (Encoder) autowireCodecBean(encoder);
if (encoder instanceof Ordered) {
order = ((Ordered) encoder).getOrder();
}
}
if (Decoder.class.isAssignableFrom(getClazz())) {
decoder = (Decoder) instance;
decoder = (Decoder) autowireCodecBean(decoder);
if (decoder instanceof Ordered) {
order = ((Ordered) decoder).getOrder();
}
}
if (encoder == null && decoder == null) {
CodecFactory codecFactory = null;
if (CodecFactory.class.isAssignableFrom(getClazz())) {
codecFactory = (CodecFactory) instance;
codecFactory = (CodecFactory) autowireCodecBean(codecFactory);
}
if (codecFactory == null) {
codecFactory = getStaticPropertyValue("codecFactory", CodecFactory.class);
codecFactory = (CodecFactory) autowireCodecBean(codecFactory);
}
if (codecFactory == null) {
codecFactory = new ClosureCodecFactory(instance);
}
encoder = codecFactory.getEncoder();
decoder = codecFactory.getDecoder();
if (codecFactory instanceof Ordered) {
order = ((Ordered) codecFactory).getOrder();
}
}
if (encoder != null) {
if (encoder instanceof StreamingEncoder) {
encoder = new StreamingStateAwareEncoderWrapper((StreamingEncoder) encoder);
} else {
encoder = new StateAwareEncoderWrapper(encoder);
}
}
}
Aggregations