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");
}
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);
}
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>"));
}
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();
}
}
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>");
}
}
}
Aggregations