Search in sources :

Example 6 with FastStringWriter

use of org.grails.buffer.FastStringWriter in project grails-core by grails.

the class GroovyPagesUriSupport method getRelativeTemplateURIInternal.

private String getRelativeTemplateURIInternal(String templateName, boolean includeSuffix) {
    String tmp = templateName.substring(RELATIVE_STRING.length(), templateName.length());
    FastStringWriter buf = new FastStringWriter();
    buf.append("/_");
    buf.append(tmp);
    if (includeSuffix) {
        buf.append(SUFFIX);
    }
    return buf.toString();
}
Also used : FastStringWriter(org.grails.buffer.FastStringWriter)

Example 7 with FastStringWriter

use of org.grails.buffer.FastStringWriter in project grails-core by grails.

the class GroovyPagesUriSupport method getTemplateURI.

/**
     * Obtains the URI to a template using the controller name and template name
     * @param controllerName The controller name
     * @param templateName The template name
     * @param includeExtension The flag to include the template extension
     * @return The template URI
     */
@Override
public String getTemplateURI(String controllerName, String templateName, boolean includeExtension) {
    if (templateName.startsWith(SLASH_STR)) {
        return getAbsoluteTemplateURI(templateName, includeExtension);
    } else if (templateName.startsWith(RELATIVE_STRING)) {
        return getRelativeTemplateURIInternal(templateName, includeExtension);
    }
    FastStringWriter buf = new FastStringWriter();
    String pathToTemplate = BLANK;
    int lastSlash = templateName.lastIndexOf(SLASH);
    if (lastSlash > -1) {
        pathToTemplate = templateName.substring(0, lastSlash + 1);
        templateName = templateName.substring(lastSlash + 1);
    }
    if (controllerName != null) {
        buf.append(SLASH).append(controllerName);
    }
    buf.append(SLASH).append(pathToTemplate).append(UNDERSCORE).append(templateName);
    if (includeExtension) {
        return buf.append(EXTENSION).toString();
    } else {
        return buf.toString();
    }
}
Also used : FastStringWriter(org.grails.buffer.FastStringWriter)

Example 8 with FastStringWriter

use of org.grails.buffer.FastStringWriter in project grails-core by grails.

the class MockGrailsApplication method testPrintStringWithClosure.

@Test
public void testPrintStringWithClosure() {
    FastStringWriter stringwriter = new FastStringWriter();
    CodecPrintWriter writer = new CodecPrintWriter(stringwriter, getEncoder(new MockGrailsApplication(), CodecWithClosureProperties.class), registry);
    writer.print("hello");
    writer.flush();
    assertEquals("-> hello <-", stringwriter.getValue());
}
Also used : FastStringWriter(org.grails.buffer.FastStringWriter) CodecPrintWriter(org.grails.buffer.CodecPrintWriter) Test(org.junit.Test)

Example 9 with FastStringWriter

use of org.grails.buffer.FastStringWriter in project grails-core by grails.

the class MockGrailsApplication method testPrintStreamCharBuffer.

@Test
public void testPrintStreamCharBuffer() throws IOException {
    FastStringWriter stringwriter = new FastStringWriter();
    CodecPrintWriter writer = new CodecPrintWriter(stringwriter, getEncoder(new MockGrailsApplication(), HTMLCodec.class), registry);
    StreamCharBuffer buf = new StreamCharBuffer();
    buf.getWriter().write("&&");
    writer.write(buf);
    writer.flush();
    assertEquals("&amp;&amp;", stringwriter.getValue());
}
Also used : FastStringWriter(org.grails.buffer.FastStringWriter) CodecPrintWriter(org.grails.buffer.CodecPrintWriter) StreamCharBuffer(org.grails.buffer.StreamCharBuffer) HTMLCodec(org.grails.plugins.codecs.HTMLCodec) Test(org.junit.Test)

Example 10 with FastStringWriter

use of org.grails.buffer.FastStringWriter in project grails-core by grails.

the class MockGrailsApplication method testPrintStreamCharBufferWithClosure.

@Test
public void testPrintStreamCharBufferWithClosure() throws IOException {
    FastStringWriter stringwriter = new FastStringWriter();
    CodecPrintWriter writer = new CodecPrintWriter(stringwriter, getEncoder(new MockGrailsApplication(), CodecWithClosureProperties.class), registry);
    StreamCharBuffer buf = new StreamCharBuffer();
    buf.getWriter().write("hola");
    writer.write(buf);
    writer.flush();
    assertEquals("-> hola <-", stringwriter.getValue());
}
Also used : FastStringWriter(org.grails.buffer.FastStringWriter) CodecPrintWriter(org.grails.buffer.CodecPrintWriter) StreamCharBuffer(org.grails.buffer.StreamCharBuffer) Test(org.junit.Test)

Aggregations

FastStringWriter (org.grails.buffer.FastStringWriter)12 CodecPrintWriter (org.grails.buffer.CodecPrintWriter)5 Test (org.junit.Test)5 StreamCharBuffer (org.grails.buffer.StreamCharBuffer)2 HTMLCodec (org.grails.plugins.codecs.HTMLCodec)2 ConfigMap (grails.config.ConfigMap)1 GrailsDomainClass (grails.core.GrailsDomainClass)1 Template (groovy.text.Template)1 Matcher (java.util.regex.Matcher)1 GrailsPrintWriter (org.grails.buffer.GrailsPrintWriter)1 GroovySyntaxTag (org.grails.gsp.compiler.tags.GroovySyntaxTag)1 GrailsTagException (org.grails.taglib.GrailsTagException)1 OutputEncodingStack (org.grails.taglib.encoder.OutputEncodingStack)1 DefaultRequestStateLookupStrategy (org.grails.web.servlet.mvc.DefaultRequestStateLookupStrategy)1 GrailsRequestStateLookupStrategy (org.grails.web.servlet.mvc.GrailsRequestStateLookupStrategy)1 GrailsWebRequest (org.grails.web.servlet.mvc.GrailsWebRequest)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1