use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class ValidateXMLInterceptor method paint.
/**
* Override paint to include XML Validation.
*
* @param renderContext the renderContext to send the output to.
*/
@Override
public void paint(final RenderContext renderContext) {
// Check interceptor is enabled
if (!DebugValidateXML.isEnabled()) {
super.paint(renderContext);
return;
}
if (!(renderContext instanceof WebXmlRenderContext)) {
LOG.warn("Unable to validate against a " + renderContext);
super.paint(renderContext);
return;
}
LOG.debug("Validate XML Interceptor: Start");
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
PrintWriter writer = webRenderContext.getWriter();
// Generate XML
StringWriter tempBuffer = new StringWriter();
PrintWriter tempWriter = new PrintWriter(tempBuffer);
WebXmlRenderContext tempContext = new WebXmlRenderContext(tempWriter, UIContextHolder.getCurrent().getLocale());
super.paint(tempContext);
String xml = tempBuffer.toString();
// If no errors, check against the schema
String error = DebugValidateXML.validateXMLAgainstSchema(xml);
if (error != null) {
// XML is NOT valid, so Report Errors and Wrap the original XML
LOG.debug("Validate XML Interceptor: XML Has Errors");
writer.println("<div>");
writer.println("<div>");
writer.println("Invalid XML");
writer.println("<ul><li>" + WebUtilities.encode(error) + "</li></ul>");
writer.println("<br/>");
writer.println("</div>");
// If a schema error detected, Wrap XML so line numbers reported in validation message are correct
String testXML = DebugValidateXML.wrapXMLInRootElement(xml);
paintOriginalXML(testXML, writer);
writer.println("</div>");
} else {
// XML is valid
writer.write(xml);
}
LOG.debug("Validate XML Interceptor: Finished");
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class TemplateWriter 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();
}
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class AbstractWComponent_Test method testDuplicateId.
@Test(expected = SystemException.class)
public void testDuplicateId() {
WNamingContext root = new WNamingContext("TEST");
Assert.assertEquals("Incorrect context id", "TEST", root.getId());
SimpleComponent component = new SimpleComponent();
component.setIdName("X");
root.add(component);
component = new SimpleComponent();
component.setIdName("X");
root.add(component);
setActiveContext(new UIContextImpl());
PrintWriter writer = new XmlStringBuilder(new StringWriter());
root.preparePaint(new MockRequest());
root.paint(new WebXmlRenderContext(writer));
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class FatalErrorPage_Test method testPaintComponentDeveloperFriendly.
@Test
public void testPaintComponentDeveloperFriendly() {
setActiveContext(createUIContext());
TestSampleException exception = new TestSampleException("sample exception only");
FatalErrorPage fatalErrPage = new FatalErrorPage(true, exception);
String correctMsg = fatalErrPage.getMessage();
StringWriter strWriter = new StringWriter();
PrintWriter writer = new PrintWriter(strWriter);
fatalErrPage.paintComponent(new WebXmlRenderContext(writer));
String result = strWriter.toString();
Assert.assertTrue("should contain contents of getMessage()", result.indexOf(correctMsg) != -1);
Assert.assertTrue("should contain the name of the Exception", result.indexOf(exception.getClass().getName()) != -1);
}
use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.
the class FatalErrorPage_Test method testPaintComponentNotDeveloperFriendly.
@Test
public void testPaintComponentNotDeveloperFriendly() {
setActiveContext(createUIContext());
TestSampleException exception = new TestSampleException("sample exception only");
FatalErrorPage fatalErrPage = new FatalErrorPage(false, exception);
String correctMsg = fatalErrPage.getMessage();
StringWriter strWriter = new StringWriter();
PrintWriter writer = new PrintWriter(strWriter);
fatalErrPage.paintComponent(new WebXmlRenderContext(writer));
Assert.assertTrue("Should equal the contents of getMessage()", strWriter.toString().equals(correctMsg + System.getProperty("line.separator")));
}
Aggregations