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();
}
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();
}
}
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());
}
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("&&", stringwriter.getValue());
}
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());
}
Aggregations