Search in sources :

Example 61 with WComponent

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();
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WApplication(com.github.bordertech.wcomponents.WApplication)

Example 62 with WComponent

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.");
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) ActionEscape(com.github.bordertech.wcomponents.ActionEscape) UIContext(com.github.bordertech.wcomponents.UIContext) WApplication(com.github.bordertech.wcomponents.WApplication) IOException(java.io.IOException)

Example 63 with WComponent

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);
        }
    }
}
Also used : AbstractWComponent(com.github.bordertech.wcomponents.AbstractWComponent) WComponent(com.github.bordertech.wcomponents.WComponent) Container(com.github.bordertech.wcomponents.Container)

Example 64 with WComponent

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);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent)

Example 65 with WComponent

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;
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) FatalErrorPageFactory(com.github.bordertech.wcomponents.FatalErrorPageFactory) SystemException(com.github.bordertech.wcomponents.util.SystemException)

Aggregations

WComponent (com.github.bordertech.wcomponents.WComponent)107 Test (org.junit.Test)35 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)30 UIContext (com.github.bordertech.wcomponents.UIContext)20 SystemException (com.github.bordertech.wcomponents.util.SystemException)16 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)8 WApplication (com.github.bordertech.wcomponents.WApplication)8 WLabel (com.github.bordertech.wcomponents.WLabel)8 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)7 IOException (java.io.IOException)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)5 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Size (com.github.bordertech.wcomponents.Size)4 WRepeater (com.github.bordertech.wcomponents.WRepeater)4 WText (com.github.bordertech.wcomponents.WText)4 WTextField (com.github.bordertech.wcomponents.WTextField)4