use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.
the class WFigureRenderer method doRender.
/**
* Paints the given WFigure.
*
* @param component the WFigure to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WFigure figure = (WFigure) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean renderChildren = isRenderContent(figure);
xml.appendTagOpen("ui:figure");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
if (FigureMode.LAZY.equals(figure.getMode())) {
xml.appendOptionalAttribute("hidden", !renderChildren, "true");
} else {
xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
}
FigureMode mode = figure.getMode();
if (mode != null) {
switch(mode) {
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
case EAGER:
xml.appendAttribute("mode", "eager");
break;
default:
throw new SystemException("Unknown figure mode: " + figure.getMode());
}
}
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(figure, renderContext);
if (renderChildren) {
// Label
figure.getDecoratedLabel().paint(renderContext);
// Content
xml.appendTagOpen("ui:content");
xml.appendAttribute("id", component.getId() + "-content");
xml.appendClose();
figure.getContent().paint(renderContext);
xml.appendEndTag("ui:content");
}
xml.appendEndTag("ui:figure");
}
use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.
the class WFigureRenderer_Test method testRendererCorrectlyConfigured.
@Test
public void testRendererCorrectlyConfigured() {
WFigure figure = new WFigure(new WText(), "");
Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(figure) instanceof WFigureRenderer);
}
use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.
the class WFigureRenderer_Test method testRenderedWithMargins.
@Test
public void testRenderedWithMargins() throws IOException, SAXException, XpathException {
WFigure figure = new WFigure(new WText(FIGURE_CONTENT), FIGURE_HEADING);
assertXpathNotExists("//ui:figure/ui:margin", figure);
Margin margin = new Margin(0);
figure.setMargin(margin);
assertXpathNotExists("//ui:figure/ui:margin", figure);
margin = new Margin(Size.SMALL);
figure.setMargin(margin);
assertSchemaMatch(figure);
assertXpathEvaluatesTo("sm", "//ui:figure/ui:margin/@all", figure);
assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@north", figure);
assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@east", figure);
assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@south", figure);
assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@west", figure);
margin = new Margin(Size.SMALL, Size.MEDIUM, Size.LARGE, Size.XL);
figure.setMargin(margin);
assertSchemaMatch(figure);
assertXpathEvaluatesTo("", "//ui:figure/ui:margin/@all", figure);
assertXpathEvaluatesTo("sm", "//ui:figure/ui:margin/@north", figure);
assertXpathEvaluatesTo("med", "//ui:figure/ui:margin/@east", figure);
assertXpathEvaluatesTo("lg", "//ui:figure/ui:margin/@south", figure);
assertXpathEvaluatesTo("xl", "//ui:figure/ui:margin/@west", figure);
}
use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.
the class WFigureRenderer_Test method testRenderedEagerMode.
@Test
public void testRenderedEagerMode() throws IOException, SAXException, XpathException {
WFigure figure = new WFigure(new WText(FIGURE_CONTENT), FIGURE_HEADING);
figure.setMode(FigureMode.EAGER);
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
// The figure's content should NOT be rendered
assertSchemaMatch(figure);
assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
assertXpathEvaluatesTo("", "//ui:figure/ui:content", figure);
try {
// Figure is the AJAX Trigger, content should be rendered
AjaxOperation operation = new AjaxOperation(figure.getId(), figure.getId());
AjaxHelper.setCurrentOperationDetails(operation, null);
assertSchemaMatch(figure);
assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
assertXpathEvaluatesTo(FIGURE_CONTENT, "//ui:figure/ui:content", figure);
} finally {
AjaxHelper.clearCurrentOperationDetails();
}
}
use of com.github.bordertech.wcomponents.WFigure in project wcomponents by BorderTech.
the class WFigureRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WFigure figure = new WFigure(new WText(getMaliciousContent()), getMaliciousContent());
assertSafeContent(figure);
}
Aggregations