use of com.github.bordertech.wcomponents.util.SystemException 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.util.SystemException in project wcomponents by BorderTech.
the class InternalResourceMap method computeHash.
/**
* Computes a simple hash of the resource contents.
*
* @param resource the resource to hash.
* @return a hash of the resource contents.
*/
public static String computeHash(final InternalResource resource) {
final int bufferSize = 1024;
try (InputStream stream = resource.getStream()) {
if (stream == null) {
return null;
}
// Compute CRC-32 checksum
// TODO: Is a 1 in 2^32 chance of a cache bust fail good enough?
// Checksum checksumEngine = new Adler32();
Checksum checksumEngine = new CRC32();
byte[] buf = new byte[bufferSize];
for (int read = stream.read(buf); read != -1; read = stream.read(buf)) {
checksumEngine.update(buf, 0, read);
}
return Long.toHexString(checksumEngine.getValue());
} catch (Exception e) {
throw new SystemException("Error calculating resource hash", e);
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class TargetableInterceptor method paint.
@Override
public void paint(final RenderContext renderContext) {
// Should still be visible
ComponentWithContext target = WebUtilities.getComponentById(targetId, true);
if (target == null) {
throw new SystemException("No target component found for id " + targetId);
}
UIContextHolder.pushContext(target.getContext());
try {
super.paint(renderContext);
} finally {
UIContextHolder.popContext();
}
}
use of com.github.bordertech.wcomponents.util.SystemException 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.util.SystemException in project wcomponents by BorderTech.
the class WWindowInterceptor method preparePaint.
/**
* Temporarily replaces the environment while the UI prepares to render.
*
* @param request the request being responded to.
*/
@Override
public void preparePaint(final Request request) {
if (windowId == null) {
super.preparePaint(request);
} else {
// Get the window component
ComponentWithContext target = WebUtilities.getComponentById(windowId, true);
if (target == null) {
throw new SystemException("No window component for id " + windowId);
}
UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
Environment originalEnvironment = uic.getEnvironment();
uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target));
UIContextHolder.pushContext(target.getContext());
try {
super.preparePaint(request);
} finally {
uic.setEnvironment(originalEnvironment);
UIContextHolder.popContext();
}
}
}
Aggregations