use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class AbstractContainerHelper method render.
/**
* Support standard processing of the render phase of a request.
*
* @throws IOException IO Exception
*/
public void render() throws IOException {
if (isDisposed()) {
LOG.debug("Skipping render phase.");
return;
}
try {
// Check user context has been prepared
if (getNewConversation() == null) {
throw new IllegalStateException("User context has not been prepared before the render phase");
}
prepareRender();
UIContext uic = getUIContext();
if (uic == null) {
throw new IllegalStateException("No user context set for the render phase.");
}
UIContextHolder.pushContext(uic);
prepareRequest();
// Handle errors from the action phase now.
if (havePropogatedError()) {
handleError(getPropogatedError());
return;
}
WComponent uiComponent = getUI();
if (uiComponent == null) {
throw new SystemException("No UI Component exists.");
}
Environment environment = uiComponent.getEnvironment();
if (environment == null) {
throw new SystemException("No WEnvironment exists.");
}
getInterceptor().attachResponse(getResponse());
getInterceptor().preparePaint(getRequest());
String contentType = getUI().getHeaders().getContentType();
Response response = getResponse();
response.setContentType(contentType);
addGenericHeaders(uic, getUI());
PrintWriter writer = getPrintWriter();
getInterceptor().paint(new WebXmlRenderContext(writer, uic.getLocale()));
// The following only matters for a Portal context
String title = uiComponent instanceof WApplication ? ((WApplication) uiComponent).getTitle() : null;
if (title != null) {
setTitle(title);
}
} catch (Escape esc) {
LOG.debug("Escape performed during render phase.");
handleEscape(esc);
} catch (Throwable t) {
// We try not to let any exception propagate to container.
String message = "Caught exception during render phase.";
LOG.error(message, t);
handleError(t);
} finally {
UIContextHolder.reset();
dispose();
}
}
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 WebUtilities method render.
/**
* Renders the given WComponent to a String outside of the context of a Servlet. This is good for getting hold of
* the XML for debugging, unit testing etc. Also it is good for using the WComponent framework as a more generic
* templating framework.
*
* @param request the request being responded to.
* @param component the root WComponent to render.
* @return the rendered output as a String.
*/
public static String render(final Request request, final WComponent component) {
boolean needsContext = UIContextHolder.getCurrent() == null;
if (needsContext) {
UIContextHolder.pushContext(new UIContextImpl());
}
try {
StringWriter buffer = new StringWriter();
component.preparePaint(request);
try (PrintWriter writer = new PrintWriter(buffer)) {
component.paint(new WebXmlRenderContext(writer));
}
return buffer.toString();
} finally {
if (needsContext) {
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class AjaxInterceptor method paintResponse.
/**
* Paint the ajax response.
*
* @param renderContext the render context
* @param operation the ajax operation
*/
private void paintResponse(final RenderContext renderContext, final AjaxOperation operation) {
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
XmlStringBuilder xml = webRenderContext.getWriter();
// Get trigger's context
ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
if (trigger == null) {
throw new SystemException("No context available for trigger " + operation.getTriggerId());
}
for (String targetId : operation.getTargets()) {
ComponentWithContext target;
if (targetId.equals(operation.getTriggerId())) {
target = trigger;
} else {
target = WebUtilities.getComponentById(targetId, true);
if (target == null) {
LOG.warn("Could not find ajax target to render [" + targetId + "]");
continue;
}
}
UIContextHolder.pushContext(target.getContext());
try {
xml.appendTagOpen("ui:ajaxtarget");
xml.appendAttribute("id", targetId);
xml.appendAttribute("action", operation.getAction().getDesc());
xml.appendClose();
target.getComponent().paint(renderContext);
xml.appendEndTag("ui:ajaxtarget");
} finally {
UIContextHolder.popContext();
}
}
}
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");
}
Aggregations