use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class TransformXMLInterceptor method initTemplates.
/**
* Statically initialize the XSLT templates that are cached for all future transforms.
*
* @return the XSLT Templates.
*/
private static Templates initTemplates() {
try {
URL xsltURL = ThemeUtil.class.getResource(RESOURCE_NAME);
if (xsltURL != null) {
Source xsltSource = new StreamSource(xsltURL.openStream(), xsltURL.toExternalForm());
TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
Templates templates = factory.newTemplates(xsltSource);
LOG.debug("Generated XSLT templates for: " + RESOURCE_NAME);
return templates;
} else {
// Server-side XSLT enabled but theme resource not on classpath.
throw new IllegalStateException(RESOURCE_NAME + " not on classpath");
}
} catch (IOException | TransformerConfigurationException ex) {
throw new SystemException("Could not create transformer for " + RESOURCE_NAME, ex);
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WWindowInterceptor method serviceRequest.
/**
* Temporarily replaces the environment while the request is being handled.
*
* @param request the request being responded to.
*/
@Override
public void serviceRequest(final Request request) {
// Get window id off the request
windowId = request.getParameter(WWindow.WWINDOW_REQUEST_PARAM_KEY);
if (windowId == null) {
super.serviceRequest(request);
} else {
// Get the window component
ComponentWithContext target = WebUtilities.getComponentById(windowId, true);
if (target == null) {
throw new SystemException("No window component for id " + windowId);
}
// Setup the Environment on the context
UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
Environment originalEnvironment = uic.getEnvironment();
uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target));
if (attachWindow) {
attachUI(target.getComponent());
}
UIContextHolder.pushContext(target.getContext());
try {
super.serviceRequest(request);
} finally {
uic.setEnvironment(originalEnvironment);
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WrongStepAjaxInterceptor method serviceRequest.
/**
* Override to check whether the step variable in the incoming request matches what we expect.
*
* @param request the request being serviced.
*/
@Override
public void serviceRequest(final Request request) {
// Get trigger id
triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
if (triggerId == null) {
throw new SystemException("No AJAX trigger id to check step count");
}
// Get trigger and its context
ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
if (trigger == null) {
throw new IllegalStateException("No component/context available for AJAX trigger " + triggerId + ".");
}
// Get expected step count
UIContext uic = UIContextHolder.getCurrent();
int expected = uic.getEnvironment().getStep();
// Step should already be set on the session
if (expected == 0) {
throw new SystemException("Step count should already be set on the session before AJAX request.");
}
// Get step count on the request
int got = StepCountUtil.getRequestStep(request);
// Check we are on the current step
if (expected == got) {
// Process Service Request
getBackingComponent().serviceRequest(request);
} else {
// Invalid step
LOG.warn("AJAX: Wrong step detected. Expected step " + expected + " but got step " + got);
// "GET" Ajax requests are just ignored and return an error code
if ("GET".equals(request.getMethod())) {
LOG.warn("Error code will be sent in the response for AJAX GET Request.");
handleErrorCode();
// Make sure the render phase is not processed
throw new ActionEscape();
} else if (StepCountUtil.isErrorRedirect()) {
// Redirect to error page
LOG.warn("User will be redirected to an error page.");
redirectUrl = StepCountUtil.getErrorUrl();
} else {
// Warp to the future by refreshing the page
LOG.warn("Warp the user back to the future by refreshing the page.");
handleWarpToTheFuture(uic);
redirectUrl = buildApplicationUrl(uic);
}
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WrongStepContentInterceptor method serviceRequest.
/**
* Override to check whether the step variable in the incoming request matches what we expect.
*
* @param request the request being serviced.
*/
@Override
public void serviceRequest(final Request request) {
// Get expected step count
UIContext uic = UIContextHolder.getCurrent();
int expected = uic.getEnvironment().getStep();
// Step should already be set on the session
if (expected == 0) {
throw new SystemException("Step count should already be set on the session before content request.");
}
// Get step count on the request
int got = StepCountUtil.getRequestStep(request);
// Check tokens match (both must be provided)
if (expected == got) {
// Process Service Request
getBackingComponent().serviceRequest(request);
} else if (!StepCountUtil.isStepOnRequest(request) && StepCountUtil.isCachedContentRequest(request)) {
// cached content (no step on request)
// Process Service Request
getBackingComponent().serviceRequest(request);
} else {
// Invalid token
// Set an error code
LOG.warn("Wrong step detected for content request. Expected step [" + expected + "] but got step [" + got + "].");
handleError();
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class UIRegistryAmicableImpl method loadUI.
/**
* Attempts to load a UI using the key as a class name.
*
* @param key The registration key.
* @return A WComponent if one could be loaded from the classpath, else an ErrorPage WComponent containing the
* problem.
*/
private static WComponent loadUI(final String key) {
String classname = key.trim();
try {
Class<?> clas = Class.forName(classname);
if (WComponent.class.isAssignableFrom(clas)) {
WComponent instance = (WComponent) clas.newInstance();
LOG.debug("WComponent successfully loaded with class name \"" + classname + "\".");
return instance;
} else {
throw new SystemException("The resource with the name \"" + classname + "\" is not a WComponent.");
}
} catch (Exception ex) {
LOG.error("Unable to load a WComponent using the resource name \"" + classname + "\"", ex);
// Are we in developer friendly error mode?
boolean friendly = ConfigurationProperties.getDeveloperErrorHandling();
FatalErrorPageFactory factory = Factory.newInstance(FatalErrorPageFactory.class);
WComponent errorPage = factory.createErrorPage(friendly, ex);
return errorPage;
}
}
Aggregations