Search in sources :

Example 1 with FastStringWriter

use of org.thymeleaf.util.FastStringWriter in project thymeleaf by thymeleaf.

the class TemplateModel method toString.

@Override
public final String toString() {
    try {
        final Writer writer = new FastStringWriter();
        write(writer);
        return writer.toString();
    } catch (final IOException e) {
        throw new TemplateProcessingException("Error while creating String representation of model");
    }
}
Also used : FastStringWriter(org.thymeleaf.util.FastStringWriter) TemplateProcessingException(org.thymeleaf.exceptions.TemplateProcessingException) IOException(java.io.IOException) FastStringWriter(org.thymeleaf.util.FastStringWriter) Writer(java.io.Writer)

Example 2 with FastStringWriter

use of org.thymeleaf.util.FastStringWriter in project thymeleaf by thymeleaf.

the class AbstractStandardInliner method inlineSwitchTemplateMode.

private CharSequence inlineSwitchTemplateMode(final ITemplateContext context, final IComment comment) {
    final TemplateManager templateManager = context.getConfiguration().getTemplateManager();
    /*
         * Notice we are ONLY processing the contents of the Comment, because we know the target inlining
         * mode will not understand the Comment (it will be textual) and we don't want it to mess around with
         * the Comment's prefix and suffix.
         *
         * Note this will only be executed in markup modes (textual modes never fire "handleComment" events),
         * so we are safe assuming the sizes of Comment prefixes and suffixes in HTML/XML.
         */
    final TemplateModel templateModel = templateManager.parseString(context.getTemplateData(), comment.getContent(), // +4 because of the prefix
    comment.getLine(), // +4 because of the prefix
    comment.getCol() + 4, this.templateMode, true);
    final Writer stringWriter = new FastStringWriter(50);
    templateManager.process(templateModel, context, stringWriter);
    return stringWriter.toString();
}
Also used : FastStringWriter(org.thymeleaf.util.FastStringWriter) TemplateManager(org.thymeleaf.engine.TemplateManager) TemplateModel(org.thymeleaf.engine.TemplateModel) FastStringWriter(org.thymeleaf.util.FastStringWriter) Writer(java.io.Writer)

Example 3 with FastStringWriter

use of org.thymeleaf.util.FastStringWriter in project thymeleaf by thymeleaf.

the class AbstractStandardInliner method inlineSwitchTemplateMode.

private CharSequence inlineSwitchTemplateMode(final ITemplateContext context, final IText text) {
    final TemplateManager templateManager = context.getConfiguration().getTemplateManager();
    final TemplateModel templateModel = templateManager.parseString(context.getTemplateData(), text.getText(), text.getLine(), text.getCol(), this.templateMode, true);
    if (!this.writeTextsToOutput) {
        final Writer stringWriter = new FastStringWriter(50);
        templateManager.process(templateModel, context, stringWriter);
        return stringWriter.toString();
    }
    // If we can directly write to output (and text is an IText), we will use a LazyProcessingCharSequence
    return new LazyProcessingCharSequence(context, templateModel);
}
Also used : LazyProcessingCharSequence(org.thymeleaf.util.LazyProcessingCharSequence) FastStringWriter(org.thymeleaf.util.FastStringWriter) TemplateManager(org.thymeleaf.engine.TemplateManager) TemplateModel(org.thymeleaf.engine.TemplateModel) FastStringWriter(org.thymeleaf.util.FastStringWriter) Writer(java.io.Writer)

Example 4 with FastStringWriter

use of org.thymeleaf.util.FastStringWriter in project thymeleaf by thymeleaf.

the class StandardJavaScriptInliner method produceEscapedOutput.

@Override
protected String produceEscapedOutput(final Object input) {
    final Writer jsWriter = new FastStringWriter(input instanceof String ? ((String) input).length() * 2 : 20);
    this.serializer.serializeValue(input, jsWriter);
    return jsWriter.toString();
}
Also used : FastStringWriter(org.thymeleaf.util.FastStringWriter) FastStringWriter(org.thymeleaf.util.FastStringWriter) Writer(java.io.Writer)

Example 5 with FastStringWriter

use of org.thymeleaf.util.FastStringWriter in project thymeleaf by thymeleaf.

the class TemplateEngine method process.

public final String process(final TemplateSpec templateSpec, final IContext context) {
    final Writer stringWriter = new FastStringWriter(100);
    process(templateSpec, context, stringWriter);
    return stringWriter.toString();
}
Also used : FastStringWriter(org.thymeleaf.util.FastStringWriter) FastStringWriter(org.thymeleaf.util.FastStringWriter) Writer(java.io.Writer)

Aggregations

FastStringWriter (org.thymeleaf.util.FastStringWriter)10 Writer (java.io.Writer)9 TemplateModel (org.thymeleaf.engine.TemplateModel)5 TemplateManager (org.thymeleaf.engine.TemplateManager)4 TemplateProcessingException (org.thymeleaf.exceptions.TemplateProcessingException)3 IOException (java.io.IOException)2 Map (java.util.Map)1 IEngineConfiguration (org.thymeleaf.IEngineConfiguration)1 IEngineContext (org.thymeleaf.context.IEngineContext)1 ITemplateContext (org.thymeleaf.context.ITemplateContext)1 TemplateData (org.thymeleaf.engine.TemplateData)1 TemplateInputException (org.thymeleaf.exceptions.TemplateInputException)1 ICloseElementTag (org.thymeleaf.model.ICloseElementTag)1 IModel (org.thymeleaf.model.IModel)1 IOpenElementTag (org.thymeleaf.model.IOpenElementTag)1 IProcessableElementTag (org.thymeleaf.model.IProcessableElementTag)1 ITemplateEvent (org.thymeleaf.model.ITemplateEvent)1 Fragment (org.thymeleaf.standard.expression.Fragment)1 FragmentSignature (org.thymeleaf.standard.expression.FragmentSignature)1 StandardConditionalCommentUtils (org.thymeleaf.standard.util.StandardConditionalCommentUtils)1