Search in sources :

Example 26 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class ProfileContainer method afterPaint.

/**
 * Override afterPaint to write the statistics after the component is painted.
 *
 * @param renderContext the renderContext to send output to.
 */
@Override
protected void afterPaint(final RenderContext renderContext) {
    super.afterPaint(renderContext);
    // UIC serialization stats
    UicStats stats = new UicStats(UIContextHolder.getCurrent());
    stats.analyseWC(this);
    if (renderContext instanceof WebXmlRenderContext) {
        PrintWriter writer = ((WebXmlRenderContext) renderContext).getWriter();
        writer.println("<h2>Serialization Profile of UIC</h2>");
        UicStatsAsHtml.write(writer, stats);
        // ObjectProfiler
        writer.println("<h2>ObjectProfiler - " + getClass().getName() + "</h2>");
        writer.println("<pre>");
        try {
            writer.println(ObjectGraphDump.dump(this).toFlatSummary());
        } catch (Exception e) {
            LOG.error("Failed to dump component", e);
        }
        writer.println("</pre>");
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) PrintWriter(java.io.PrintWriter)

Example 27 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class VelocityRenderer method render.

/**
 * Paints the component in HTML using the Velocity Template.
 *
 * @param component the component to paint.
 * @param context the context to send the XML output to.
 */
@Override
public void render(final WComponent component, final RenderContext context) {
    PrintWriter out = ((WebXmlRenderContext) context).getWriter();
    // If we are debugging the layout, write markers so that the html
    // designer can see where templates start and end.
    boolean debugLayout = ConfigurationProperties.getDeveloperVelocityDebug();
    if (debugLayout) {
        String templateUrl = url;
        if (url == null && component instanceof AbstractWComponent) {
            templateUrl = ((AbstractWComponent) component).getTemplate();
        }
        out.println("<!-- Start " + templateUrl + " -->");
        paintXml(component, out);
        out.println("<!-- End   " + templateUrl + " -->");
    } else {
        paintXml(component, out);
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) AbstractWComponent(com.github.bordertech.wcomponents.AbstractWComponent) PrintWriter(java.io.PrintWriter)

Example 28 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class VelocityWriter method doReplace.

/**
 * Replaces the search string by rendering the corresponding component.
 *
 * @param search the search String that was matched.
 * @param backing the underlying writer to write the replacement to.
 */
@Override
protected void doReplace(final String search, final Writer backing) {
    WComponent component = componentsByKey.get(search);
    UIContextHolder.pushContext(uic);
    try {
        component.paint(new WebXmlRenderContext((PrintWriter) backing));
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) PrintWriter(java.io.PrintWriter)

Example 29 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class WebXmlRenderingPerformance_Test method testRenderingScalingWithInterceptorChain.

@Test
public void testRenderingScalingWithInterceptorChain() throws Exception {
    final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
    final AllComponents component1 = new AllComponents();
    makeAllInputsMandatory(component1);
    component1.setLocked(true);
    final UIContext uic1 = createUIContext();
    final UIContext uicChain = createUIContext();
    sendRequest(component1, uic1);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            setActiveContext(uic1);
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                // Just paint component
                component1.preparePaint(new MockRequest());
                component1.paint(renderContext);
            }
        }
    };
    // JIT warm-up
    runnable.run();
    long renderTime1 = time(runnable) / NUM_REPETITIONS;
    runnable = new Runnable() {

        @Override
        public void run() {
            setActiveContext(uicChain);
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                // Paint with the interceptor chain
                WebUtilities.renderWithTransformToHTML(component1);
            }
        }
    };
    // JIT warm-up
    runnable.run();
    long renderTimeChain = time(runnable) / NUM_REPETITIONS;
    LOG.info("Render Component time: " + (renderTime1 / 1000000.0) + "ms");
    LOG.info("Render Component/Chain time: " + (renderTimeChain / 1000000.0) + "ms");
    Assert.assertTrue("Render with Chain time scaling should not be more than 3x.", renderTimeChain < renderTime1 * 3);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) AllComponents(com.github.bordertech.wcomponents.AllComponents) Test(org.junit.Test)

Example 30 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class WebXmlRenderingPerformance_Test method testRenderingScaling.

@Test
public void testRenderingScaling() throws Exception {
    final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
    final AllComponents component1 = new AllComponents();
    final UIContext uic1 = createUIContext();
    sendRequest(component1, uic1);
    final AllComponents component10 = new AllComponents(10);
    final UIContext uic10 = createUIContext();
    sendRequest(component10, uic10);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            setActiveContext(uic1);
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                component1.paint(renderContext);
            }
        }
    };
    // JIT warm-up
    runnable.run();
    long renderTime1 = time(runnable) / NUM_REPETITIONS;
    runnable = new Runnable() {

        @Override
        public void run() {
            setActiveContext(uic10);
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                component10.paint(renderContext);
            }
        }
    };
    // JIT warm-up
    runnable.run();
    long renderTime10 = time(runnable) / NUM_REPETITIONS;
    LOG.info("Render 1x time: " + (renderTime1 / 1000000.0) + "ms");
    LOG.info("Render 10x time: " + (renderTime10 / 1000000.0) + "ms");
    Assert.assertTrue("Render time scaling should be O(n)", renderTime10 < renderTime1 * 12);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UIContext(com.github.bordertech.wcomponents.UIContext) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) AllComponents(com.github.bordertech.wcomponents.AllComponents) Test(org.junit.Test)

Aggregations

WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)63 PrintWriter (java.io.PrintWriter)48 StringWriter (java.io.StringWriter)27 Test (org.junit.Test)27 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)17 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)17 UIContext (com.github.bordertech.wcomponents.UIContext)15 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)7 SystemException (com.github.bordertech.wcomponents.util.SystemException)7 WText (com.github.bordertech.wcomponents.WText)6 RenderContext (com.github.bordertech.wcomponents.RenderContext)5 WComponent (com.github.bordertech.wcomponents.WComponent)5 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)5 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)5 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)4 Configuration (org.apache.commons.configuration.Configuration)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3 AllComponents (com.github.bordertech.wcomponents.AllComponents)3 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 Response (com.github.bordertech.wcomponents.Response)3