Search in sources :

Example 21 with WApplication

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");
}
Also used : WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) Map(java.util.Map)

Example 22 with WApplication

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);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 23 with WApplication

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);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 24 with WApplication

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);
}
Also used : WApplication(com.github.bordertech.wcomponents.WApplication) Test(org.junit.Test)

Example 25 with WApplication

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);
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) WApplication(com.github.bordertech.wcomponents.WApplication) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WButton(com.github.bordertech.wcomponents.WButton) WLabel(com.github.bordertech.wcomponents.WLabel) Before(org.junit.Before)

Aggregations

WApplication (com.github.bordertech.wcomponents.WApplication)28 Test (org.junit.Test)14 UIContext (com.github.bordertech.wcomponents.UIContext)13 WComponent (com.github.bordertech.wcomponents.WComponent)8 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 WButton (com.github.bordertech.wcomponents.WButton)4 WLabel (com.github.bordertech.wcomponents.WLabel)4 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)3 WText (com.github.bordertech.wcomponents.WText)3 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)3 PrintWriter (java.io.PrintWriter)3 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 WWindow (com.github.bordertech.wcomponents.WWindow)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 Map (java.util.Map)2 Before (org.junit.Before)2 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)1 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)1 Environment (com.github.bordertech.wcomponents.Environment)1