use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WrongStepAjaxInterceptor method handleWarpToTheFuture.
/**
* Warp the user to the future by replacing the entire page.
*
* @param uic the current user context
*/
private void handleWarpToTheFuture(final UIContext uic) {
// Increment the step counter
StepCountUtil.incrementSessionStep(uic);
// Get component at end of chain
WComponent application = getUI();
// Call handle step error on WApplication
if (application instanceof WApplication) {
LOG.warn("The handleStepError method will be called on WApplication.");
((WApplication) application).handleStepError();
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WrongStepServerInterceptor 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();
// Get step count from the request
int got = StepCountUtil.getRequestStep(request);
// or no Step count and processing a GET
if (expected == got || (!StepCountUtil.isStepOnRequest(request) && "GET".equals(request.getMethod()))) {
// Process Service Request
getBackingComponent().serviceRequest(request);
} else {
// Invalid step
LOG.warn("SERVER: Wrong step detected. Expected step " + expected + " but got step " + got);
// Redirect to error page
if (StepCountUtil.isErrorRedirect()) {
String url = StepCountUtil.getErrorUrl();
LOG.warn("User will be redirected to an error page. URL: " + url);
try {
getResponse().sendRedirect(url);
} catch (IOException e) {
LOG.warn("Error trying to redirect for wrong step indicator.");
}
// Make sure the render phase is not processed
throw new ActionEscape();
} else {
// Warp to the future
// Call handle step error
WComponent application = getUI();
if (application instanceof WApplication) {
LOG.warn("The handleStepError method will be called on WApplication.");
((WApplication) application).handleStepError();
}
LOG.warn("The render phase will warp the user back to the future.");
}
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class UicStats method addStats.
/**
* Recursively adds statistics for a component and its children to the stats map.
*
* @param statsMap the stats map to add to.
* @param comp the component to analyse.
*/
private void addStats(final Map<WComponent, Stat> statsMap, final WComponent comp) {
Stat stat = createStat(comp);
statsMap.put(comp, stat);
if (comp instanceof Container) {
Container container = (Container) comp;
int childCount = container.getChildCount();
for (int i = 0; i < childCount; i++) {
WComponent child = container.getChildAt(i);
addStats(statsMap, child);
}
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class UicStatsAsHtml method write.
/**
* Writes out the given statistics in HTML format.
*
* @param writer the writer to write to.
* @param stats the stats to write.
*/
public static void write(final PrintWriter writer, final UicStats stats) {
writer.println("<dl>");
writer.print("<dt>Total root wcomponents found in UIC</dt>");
writer.println("<dd>" + stats.getRootWCs().size() + "</dd>");
writer.print("<dt>Size of UIC (by serialization)</dt>");
writer.println("<dd>" + stats.getOverallSerializedSize() + "</dd>");
writer.print("<dt>UI</dt>");
writer.println("<dd>" + stats.getUI().getClass().getName() + "</dd>");
writer.println("</dl>");
for (Iterator<WComponent> it = stats.getWCsAnalysed(); it.hasNext(); ) {
WComponent comp = it.next();
Map<WComponent, UicStats.Stat> treeStats = stats.getWCTreeStats(comp);
writer.println("<br /><strong>Analysed component:</strong> " + comp);
writer.println("<br /><strong>Number of components in tree:</strong> " + treeStats.size());
writeHeader(writer);
writeProfileForTree(writer, treeStats);
writeFooter(writer);
}
}
use of com.github.bordertech.wcomponents.WComponent 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