Search in sources :

Example 36 with WebXmlRenderContext

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

the class AjaxDebugStructureInterceptor method paint.

/**
 * Override paint to only output the debugging info for the current targets.
 *
 * @param renderContext the renderContext to send the output to.
 */
@Override
public void paint(final RenderContext renderContext) {
    if (!DebugUtil.isDebugFeaturesEnabled() || !(renderContext instanceof WebXmlRenderContext)) {
        getBackingComponent().paint(renderContext);
        return;
    }
    AjaxOperation operation = AjaxHelper.getCurrentOperation();
    if (operation == null) {
        getBackingComponent().paint(renderContext);
        return;
    }
    getBackingComponent().paint(renderContext);
    XmlStringBuilder xml = ((WebXmlRenderContext) renderContext).getWriter();
    xml.appendTag("ui:debug");
    for (String targetId : operation.getTargets()) {
        ComponentWithContext target = WebUtilities.getComponentById(targetId, true);
        if (target != null) {
            writeDebugInfo(target.getComponent(), xml);
        }
    }
    xml.appendEndTag("ui:debug");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 37 with WebXmlRenderContext

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

the class VelocityRenderer_Test method testPaint.

@Test
public void testPaint() {
    TestComponent component = new TestComponent();
    VelocityRenderer layout = new VelocityRenderer("com/github/bordertech/wcomponents/velocity/VelocityRenderer_Test.vm");
    setActiveContext(createUIContext());
    StringWriter writer = new StringWriter();
    PrintWriter printWriter = new PrintWriter(writer);
    layout.render(component, new WebXmlRenderContext(printWriter));
    printWriter.close();
    String result = writer.toString();
    Assert.assertTrue("Missing 'this'", result.contains("this=com.github.bordertech.wcomponents.velocity.VelocityRenderer_Test$TestComponent"));
    Assert.assertTrue("Missing 'this.someProperty'", result.contains("[this.someProperty=somePropertyValue]"));
    Assert.assertTrue("Missing 'uicontext'", result.contains("[uicontext=com.github.bordertech.wcomponents.UIContextImpl"));
    Assert.assertTrue("Missing 'uic'", result.contains("uicontext=com.github.bordertech.wcomponents.UIContextImpl"));
    Assert.assertTrue("Missing 'children'", result.contains("[children=[A, B, C, D]]"));
    Assert.assertTrue("Missing 'childA'", result.contains("[childA=A]"));
    Assert.assertTrue("Missing 'childB'", result.contains("[childB=B]"));
    Assert.assertTrue("Missing 'childC'", result.contains("[childC=]"));
    Assert.assertTrue("Missing 'test_list'", result.contains("[test_list=[C, D]]"));
    Assert.assertTrue("Missing velocity map params", result.contains("[velocityMapParam=velocityMapParamValue]"));
    Assert.assertTrue("Map should have been used", component.mapUsedCalled);
    Assert.assertFalse("Should not contain debug markers", result.contains("<!-- Start"));
    Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_VELOCITY_DEBUG, "true");
    writer = new StringWriter();
    printWriter = new PrintWriter(writer);
    layout.render(component, new WebXmlRenderContext(printWriter));
    printWriter.close();
    result = writer.toString();
    int startIndex = result.indexOf("<!-- Start " + layout.getUrl() + " -->");
    int endIndex = result.indexOf("<!-- End   " + layout.getUrl() + " -->");
    Assert.assertTrue("Should contain start debug marker", startIndex != -1);
    Assert.assertTrue("Should contain end debug marker", endIndex != -1);
    Assert.assertTrue("Start debug marker should be before end debug marker", startIndex < endIndex);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) VelocityRenderer(com.github.bordertech.wcomponents.render.webxml.VelocityRenderer) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 38 with WebXmlRenderContext

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

the class VelocityRenderer_Test method testPaintMissingTemplate.

@Test
public void testPaintMissingTemplate() {
    TestComponent component = new TestComponent();
    VelocityRenderer layout = new VelocityRenderer("/com/github/bordertech/wcomponents/velocity/VelocityRenderer_Test_missing_template.vm");
    StringWriter writer = new StringWriter();
    PrintWriter printWriter = new PrintWriter(writer);
    layout.render(component, new WebXmlRenderContext(printWriter));
    printWriter.close();
    // This should still render, and just dump out the contents of the Velocity context.
    String result = writer.toString();
    Assert.assertTrue("Should have rendered output", result.contains("<td>this</td>"));
    Assert.assertTrue("Should have rendered output", result.contains("<td>" + component.getClass().getName() + "</td>"));
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) VelocityRenderer(com.github.bordertech.wcomponents.render.webxml.VelocityRenderer) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 39 with WebXmlRenderContext

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

the class WComponentRenderPerfTest method runRenderTest.

/**
 * Runs the render test.
 */
private static void runRenderTest() {
    UIContextImpl uic = new UIContextImpl();
    PrintWriter printWriter = new PrintWriter(new NullWriter());
    RenderContext renderContext = new WebXmlRenderContext(printWriter);
    WComponent component = null;
    long baseLineMemory = getHeapUsed();
    try {
        component = (WComponent) Class.forName(CLASS_TO_TEST).newInstance();
    } catch (Exception e) {
        String msg = "Unable to instantiate test component: " + CLASS_TO_TEST;
        LOG.error(LINE_PREFIX + msg);
        throw new SystemException(msg, e);
    }
    long memBeforePaint = getHeapUsed() - baseLineMemory;
    // Set up velocity etc. to obtain a memory reading, and
    // so that the performance results aren't skewed too much
    UIContextHolder.pushContext(uic);
    try {
        component.paint(renderContext);
        long memAfterOnePaint = getHeapUsed() - baseLineMemory;
        long startTime = System.currentTimeMillis();
        // Figure out the loop overhead
        for (int i = 0; i < NUM_RENDERS; i++) {
        }
        long loopOverhead = System.currentTimeMillis() - startTime;
        startTime = System.currentTimeMillis();
        // Now run the render test
        for (int i = 0; i < NUM_RENDERS; i++) {
            component.paint(renderContext);
        }
        long elapsedTime = System.currentTimeMillis() - startTime - loopOverhead;
        long memAfterAllPaints = getHeapUsed() - baseLineMemory;
        LOG.info(LINE_PREFIX + "Memory use before paint: " + memBeforePaint);
        LOG.info(LINE_PREFIX + "Memory use after 1 paint: " + memAfterOnePaint);
        LOG.info(LINE_PREFIX + "Memory use after " + NUM_RENDERS + " paints: " + memAfterAllPaints);
        LOG.info(LINE_PREFIX + "Render time: " + (elapsedTime / (double) NUM_RENDERS) + "ms");
        Object[] treeAndSession = new Object[] { component, uic };
        ObjectGraphNode root = ObjectGraphDump.dump(treeAndSession);
        LOG.info(LINE_PREFIX + "Component mem use: " + ((ObjectGraphNode) root.getChildAt(0)).getSize());
        LOG.info(LINE_PREFIX + "UIC mem use: " + ((ObjectGraphNode) root.getChildAt(1)).getSize());
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) IOException(java.io.IOException) SystemException(com.github.bordertech.wcomponents.util.SystemException) WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) ObjectGraphNode(com.github.bordertech.wcomponents.util.ObjectGraphNode) PrintWriter(java.io.PrintWriter)

Example 40 with WebXmlRenderContext

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

the class ErrorComponent method afterPaint.

/**
 * Override in order to paint the component. Real applications should not emit HTML directly.
 *
 * @param renderContext the renderContext to send output to.
 */
@Override
protected void afterPaint(final RenderContext renderContext) {
    if (renderContext instanceof WebXmlRenderContext) {
        PrintWriter writer = ((WebXmlRenderContext) renderContext).getWriter();
        writer.println(WebUtilities.encode(message));
        if (error != null) {
            writer.println("\n<br/>\n<pre>\n");
            StringWriter buf = new StringWriter();
            error.printStackTrace(new PrintWriter(buf));
            writer.println(WebUtilities.encode(buf.toString()));
            writer.println("\n</pre>");
        }
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

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