use of com.github.bordertech.wcomponents.container.TemplateRenderInterceptor in project wcomponents by BorderTech.
the class ServletUtil method createInterceptorChain.
/**
* Creates a new interceptor chain to handle the given request.
*
* @param request the request to handle
* @return a new interceptor chain for the request.
*/
public static InterceptorComponent createInterceptorChain(final HttpServletRequest request) {
// Allow for multi part parameters
Map<String, String[]> parameters = getRequestParameters(request);
InterceptorComponent[] chain;
if (parameters.get(WServlet.DATA_LIST_PARAM_NAME) != null) {
// Datalist
chain = new InterceptorComponent[] { new TransformXMLInterceptor(), new DataListInterceptor() };
} else if (parameters.get(WServlet.AJAX_TRIGGER_PARAM_NAME) != null) {
// AJAX
chain = new InterceptorComponent[] { new TemplateRenderInterceptor(), new TransformXMLInterceptor(), new ValidateXMLInterceptor(), new AjaxErrorInterceptor(), new SessionTokenAjaxInterceptor(), new ResponseCacheInterceptor(CacheType.NO_CACHE), new UIContextDumpInterceptor(), new AjaxSetupInterceptor(), new WWindowInterceptor(true), new WrongStepAjaxInterceptor(), new ContextCleanupInterceptor(), new WhitespaceFilterInterceptor(), new SubordinateControlInterceptor(), new AjaxPageShellInterceptor(), new AjaxDebugStructureInterceptor(), new AjaxInterceptor() };
} else if (parameters.get(WServlet.TARGET_ID_PARAM_NAME) != null) {
// Targetted Content
chain = new InterceptorComponent[] { new TargetableErrorInterceptor(), new SessionTokenContentInterceptor(), new UIContextDumpInterceptor(), new TargetableInterceptor(), new WWindowInterceptor(false), new WrongStepContentInterceptor() };
} else {
chain = new InterceptorComponent[] { // Page submit
new TemplateRenderInterceptor(), new TransformXMLInterceptor(), new ValidateXMLInterceptor(), new SessionTokenInterceptor(), new ResponseCacheInterceptor(CacheType.NO_CACHE), new UIContextDumpInterceptor(), new WWindowInterceptor(true), new WrongStepServerInterceptor(), new AjaxCleanupInterceptor(), new ContextCleanupInterceptor(), new WhitespaceFilterInterceptor(), new SubordinateControlInterceptor(), new PageShellInterceptor(), new FormInterceptor(), new DebugStructureInterceptor() };
}
// Link the interceptors together in a chain.
for (int i = 0; i < chain.length - 1; i++) {
chain[i].setBackingComponent(chain[i + 1]);
}
// Return the top of the chain.
return chain[0];
}
use of com.github.bordertech.wcomponents.container.TemplateRenderInterceptor in project wcomponents by BorderTech.
the class WebUtilities method renderWithTransformToHTML.
/**
* Renders and transforms the given WComponent to a HTML String outside of the context of a Servlet.
*
* @param request the request being responded to
* @param component the root WComponent to render
* @param includePageShell true if include page shell
* @return the rendered output as a String.
*/
public static String renderWithTransformToHTML(final Request request, final WComponent component, final boolean includePageShell) {
// Setup a context (if needed)
boolean needsContext = UIContextHolder.getCurrent() == null;
if (needsContext) {
UIContextHolder.pushContext(new UIContextImpl());
}
try {
// Link Interceptors
InterceptorComponent templateRender = new TemplateRenderInterceptor();
InterceptorComponent transformXML = new TransformXMLInterceptor();
templateRender.setBackingComponent(transformXML);
if (includePageShell) {
transformXML.setBackingComponent(new PageShellInterceptor());
}
// Attach Component and Mock Response
InterceptorComponent chain = templateRender;
chain.attachUI(component);
chain.attachResponse(new MockResponse());
// Render chain
StringWriter buffer = new StringWriter();
chain.preparePaint(request);
try (PrintWriter writer = new PrintWriter(buffer)) {
chain.paint(new WebXmlRenderContext(writer));
}
return buffer.toString();
} finally {
if (needsContext) {
UIContextHolder.popContext();
}
}
}
Aggregations