use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class WApplicationRenderer method doRender.
/**
* Paints the given WApplication.
*
* @param component the WApplication to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WApplication application = (WApplication) component;
XmlStringBuilder xml = renderContext.getWriter();
UIContext uic = UIContextHolder.getCurrent();
String focusId = uic.getFocussedId();
// Check that this is the top level component
if (application.getParent() != null) {
LOG.warn("WApplication component should be the top level component.");
}
xml.appendTagOpen("ui:application");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendUrlAttribute("applicationUrl", uic.getEnvironment().getPostPath());
xml.appendUrlAttribute("ajaxUrl", uic.getEnvironment().getWServletPath());
xml.appendOptionalAttribute("unsavedChanges", application.hasUnsavedChanges(), "true");
xml.appendOptionalAttribute("title", application.getTitle());
xml.appendOptionalAttribute("defaultFocusId", uic.isFocusRequired() && !Util.empty(focusId), focusId);
xml.appendOptionalUrlAttribute("icon", WApplication.getIcon());
xml.appendClose();
// Tracking enabled globally
if (TrackingUtil.isTrackingEnabled()) {
xml.appendTagOpen("ui:analytic");
xml.appendAttribute("clientId", TrackingUtil.getClientId());
xml.appendOptionalAttribute("cd", TrackingUtil.getCookieDomain());
xml.appendOptionalAttribute("dcd", TrackingUtil.getDataCollectionDomain());
xml.appendOptionalAttribute("name", TrackingUtil.getApplicationName());
xml.appendEnd();
}
// Hidden fields
Map<String, String> hiddenFields = uic.getEnvironment().getHiddenParameters();
if (hiddenFields != null) {
for (Map.Entry<String, String> entry : hiddenFields.entrySet()) {
xml.appendTagOpen("ui:param");
xml.appendAttribute("name", entry.getKey());
xml.appendAttribute("value", entry.getValue());
xml.appendEnd();
}
}
// Custom CSS Resources (if any)
for (WApplication.ApplicationResource resource : application.getCssResources()) {
String url = resource.getTargetUrl();
if (!Util.empty(url)) {
xml.appendTagOpen("ui:css");
xml.appendUrlAttribute("url", url);
xml.appendEnd();
}
}
// Custom JavaScript Resources (if any)
for (WApplication.ApplicationResource resource : application.getJsResources()) {
String url = resource.getTargetUrl();
if (!Util.empty(url)) {
xml.appendTagOpen("ui:js");
xml.appendUrlAttribute("url", url);
xml.appendEnd();
}
}
paintChildren(application, renderContext);
xml.appendEndTag("ui:application");
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class WApplicationRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
MockWEnvironment environment = new MockWEnvironment();
environment.setPostPath("WApplicationRendererTest.postPath");
WApplication application = new WApplication();
UIContext uic = createUIContext();
uic.setEnvironment(environment);
uic.setUI(application);
setActiveContext(uic);
application.setTitle(getMaliciousAttribute("ui:application"));
assertSafeContent(application);
uic.getEnvironment().getHiddenParameters().put(getMaliciousAttribute("ui:param"), "dummy");
uic.getEnvironment().getHiddenParameters().put("dummy", getMaliciousAttribute("ui:param"));
assertSafeContent(application);
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class WApplicationRenderer_Test method testBasicRenderedFormat.
@Test
public void testBasicRenderedFormat() throws XpathException, IOException, SAXException {
// Basic component (no optional fields)
MockWEnvironment environment = new MockWEnvironment();
WApplication application = new WApplication();
environment.setPostPath("WApplicationRendererTest.postPath");
UIContext uic = createUIContext();
uic.setEnvironment(environment);
uic.setUI(application);
setActiveContext(uic);
assertSchemaMatch(application);
assertXpathEvaluatesTo(environment.getPostPath(), "//ui:application/@applicationUrl", application);
assertXpathEvaluatesTo(environment.getWServletPath(), "//ui:application/@ajaxUrl", application);
assertXpathNotExists("//ui:application/@defaultFocusId", application);
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class WApplicationRenderer_Test method testRendererCorrectlyConfigured.
@Test
public void testRendererCorrectlyConfigured() {
WApplication application = new WApplication();
Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(application) instanceof WApplicationRenderer);
}
use of com.github.bordertech.wcomponents.WApplication in project wcomponents by BorderTech.
the class UicStats_Test method setUp.
@Before
public void setUp() {
UIContext uic;
uic = new UIContextImpl();
setActiveContext(uic);
app = new WApplication();
button = new WButton("PUSH");
app.add(button);
label = new WLabel("HERE");
app.add(label);
uic.setUI(app);
stats = new UicStats(uic);
}
Aggregations