use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class DebugStructureInterceptor method paint.
/**
* Override paint to render additional information for debugging purposes.
*
* @param renderContext the renderContext to send the output to.
*/
@Override
public void paint(final RenderContext renderContext) {
super.paint(renderContext);
if (!DebugUtil.isDebugFeaturesEnabled() || !(renderContext instanceof WebXmlRenderContext)) {
return;
}
XmlStringBuilder xml = ((WebXmlRenderContext) renderContext).getWriter();
xml.appendTag("ui:debug");
writeDebugInfo(getUI(), xml);
xml.appendEndTag("ui:debug");
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class InterceptorComponent method render.
/**
* Renders the given component to a web-XML String and returns it. This occurs outside the context of a Servlet.
*
* @param component the component to render.
* @return the rendered output as a String.
*/
protected static String render(final WebComponent component) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
component.paint(new WebXmlRenderContext(printWriter));
printWriter.flush();
String content = stringWriter.toString();
return content;
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class TemplateRenderInterceptor method paint.
/**
* {@inheritDoc}
*/
@Override
public void paint(final RenderContext renderContext) {
UIContext uic = UIContextHolder.getCurrent();
// Generate the HTML
StringWriter outputBuffer = new StringWriter();
PrintWriter outputWriter = new PrintWriter(outputBuffer);
WebXmlRenderContext outputContext = new WebXmlRenderContext(outputWriter, uic.getLocale());
super.paint(outputContext);
String html = outputBuffer.toString();
// Only process TEMPLATE if has I18N brackets
if (html.contains("{{#i18n")) {
// Create a new instance of factory to avoid caching the page.
// https://github.com/spullara/mustache.java/issues/117
final MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile(new StringReader(html), UUID.randomUUID().toString());
StringWriter templateWriter = new StringWriter();
mustache.execute(templateWriter, new I18NContext(getResourceBundle()));
html = templateWriter.toString();
}
// Get the OUTPUT writer
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
PrintWriter writer = webRenderContext.getWriter();
writer.print(html);
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class VelocityInterceptor method paint.
/**
* Renders the component using the velocity template which has been provided.
*
* @param renderContext the context for rendering.
*/
@Override
public void paint(final RenderContext renderContext) {
if (!(renderContext instanceof WebXmlRenderContext)) {
throw new SystemException("Unable to render to " + renderContext);
}
PrintWriter writer = ((WebXmlRenderContext) renderContext).getWriter();
Template template = null;
try {
template = VelocityEngineFactory.getVelocityEngine().getTemplate(templateUrl);
} catch (Exception ex) {
String message = "Could not open velocity template \"" + templateUrl + "\" for \"" + this.getClass().getName() + "\"";
LOG.error(message, ex);
writer.println(message);
return;
}
try {
VelocityContext context = new VelocityContext();
fillContext(context);
template.merge(context, writer);
} catch (ResourceNotFoundException rnfe) {
LOG.error("Could not find template " + templateUrl, rnfe);
} catch (ParseErrorException pee) {
// syntax error : problem parsing the template
LOG.error("Parse problems", pee);
} catch (MethodInvocationException mie) {
// something invoked in the template
// threw an exception
Throwable wrapped = mie.getWrappedThrowable();
LOG.error("Problems with velocity", mie);
if (wrapped != null) {
LOG.error("Wrapped exception...", wrapped);
}
} catch (Exception e) {
LOG.error("Problems with velocity", e);
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class WhitespaceFilterInterceptor method paint.
/**
* Paints the component.
*
* @param renderContext the renderContext to send the output to.
*/
@Override
public void paint(final RenderContext renderContext) {
boolean enabled = ConfigurationProperties.getWhitespaceFilter();
if (enabled && renderContext instanceof WebXmlRenderContext) {
PrintWriter writer = ((WebXmlRenderContext) renderContext).getWriter();
writer = new WhiteSpaceFilterPrintWriter(writer);
WebXmlRenderContext filteredContext = new WebXmlRenderContext(writer, UIContextHolder.getCurrent().getLocale());
super.paint(filteredContext);
} else {
super.paint(renderContext);
}
}
Aggregations