/** * {@inheritDoc} */ @Override public void doInvokeLaters() { backing.doInvokeLaters(); }
/** * {@inheritDoc} */ @Override public void setLocale(final Locale locale) { backing.setLocale(locale); }
/** * {@inheritDoc} */ @Override public void setUI(final WComponent ui) { backing.setUI(ui); }
/** * @param uuic the user context */ private void detectRootWCs(final UIContext uuic) { rootWCsDetected = new HashSet<>(); WComponent root = WebUtilities.getTop(uuic.getUI()); rootWCsDetected.add(root); // TODO: Should report if the ui is not a root component. // Find any other root components that are storing information in the context. for (Iterator it = uuic.getComponents().iterator(); it.hasNext();) { WComponent wc = (WComponent) it.next(); root = WebUtilities.getTop(wc); rootWCsDetected.add(root); } } }
/** * Clears the scratch map with phase scope for the given component. * * @param component the component to clear the scratch map for. */ @Override public void clearScratchMap(final WComponent component) { if (isInContext(component)) { Map sharedScratchMap = getParentContext().getScratchMap(component); sharedScratchMap.remove(this); } else { getParentContext().clearScratchMap(component); } }
/** * Clears the scratch map for the given component. * * @param component the component to clear the scratch map for. */ @Override public void clearRequestScratchMap(final WComponent component) { if (isInContext(component)) { Map sharedScratchMap = getParentContext().getRequestScratchMap(component); sharedScratchMap.remove(this); } else { getParentContext().clearRequestScratchMap(component); } }
uic.setUI(root); uic.clearScratchMap(); String focusId = uic.getFocussedId(); Assert.assertNull("Focus ID should be null with hidden parent", uic.getFocussedId());
@Before public void setUp() { component = new MyBackingComponent(); interceptor = new SessionTokenInterceptor(); interceptor.setBackingComponent(component); uic = new UIContextImpl(); uic.setUI(component); uic.setEnvironment(new MockWEnvironment()); setActiveContext(uic); request = new MockRequest(); }
@Test public void testFocussedIDAccessors() { UIContext uic = createUIContext(); WComponent component = new DefaultWComponent(); uic.setFocussed(component); uic.setUI(component); setActiveContext(uic); Assert.assertEquals("Incorrect focussed component id returned", component.getId(), uic. getFocussedId()); UIContext uic2 = createUIContext(); uic2.setUI(component); uic.setFocussed(component, uic2); Assert.assertEquals("Incorrect focussed component id returned with a different context", component.getId(), uic.getFocussedId()); }
@Test public void testRenderedFormatWithFocussedComponent() throws XpathException, IOException, SAXException { MockWEnvironment environment = new MockWEnvironment(); WApplication application = new WApplication(); environment.setPostPath("WApplicationRendererTest.postPath"); WTextField focussedComponent = new WTextField(); application.add(focussedComponent); UIContext uic = createUIContext(); uic.setEnvironment(environment); uic.setUI(application); uic.setFocusRequired(true); uic.setFocussed(focussedComponent); setActiveContext(uic); assertSchemaMatch(application); assertXpathEvaluatesTo(environment.getPostPath(), "//ui:application/@applicationUrl", application); assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application); assertXpathEvaluatesTo(environment.getWServletPath(), "//ui:application/@ajaxUrl", application); assertXpathEvaluatesTo(focussedComponent.getId(), "//ui:application/@defaultFocusId", application); uic.setFocusRequired(false); assertXpathNotExists("//ui:application/@defaultFocusId", application); }
@Test public void testModelAccessors() { UIContext uic = createUIContext(); WComponent component = new DefaultWComponent(); WebModel model = new ComponentModel(); uic.setModel(component, model); Assert.assertEquals("Incorrect model returned", model, uic.getModel(component)); uic.removeModel(component); Assert.assertNull("Model should be null after being removed", uic.getModel(component)); WComponent component2 = new DefaultWComponent(); WebModel model2 = new ComponentModel(); uic.setModel(component, model); uic.setModel(component2, model2); Assert. assertEquals("Incorrect number of components returned", 2, uic.getComponents(). size()); Assert.assertTrue("Component is not in the user context", uic.getComponents().contains( component)); Assert.assertTrue("Component2 is not in the user context", uic.getComponents().contains( component2)); }
/** * {@inheritDoc} */ @Override public Environment getEnvironment() { return backing.getEnvironment(); }
/** * Override paint to clear out the scratch map and component models which are no longer necessary. * * @param renderContext the renderContext to send the output to. */ @Override public void paint(final RenderContext renderContext) { super.paint(renderContext); UIContext uic = UIContextHolder.getCurrent(); if (LOG.isDebugEnabled()) { UIContextDebugWrapper debugWrapper = new UIContextDebugWrapper(uic); LOG.debug("Session usage after paint:\n" + debugWrapper); } LOG.debug("Performing session tidy up of WComponents (any WComponents disconnected from the active top component will not be tidied up."); getUI().tidyUpUIContextForTree(); LOG.debug("After paint - Clearing scratch maps."); uic.clearScratchMap(); uic.clearRequestScratchMap(); } }
@Test public void testFocussedAccessors() { UIContext uic = createUIContext(); WComponent component = new DefaultWComponent(); uic.setFocussed(component); uic.setUI(component); Assert.assertEquals("Incorrect focussed component returned", component, uic.getFocussed()); UIContext uic2 = createUIContext(); uic2.setUI(component); uic.setFocussed(component, uic2); Assert.assertEquals("Incorrect focussed component returned with a different context", component, uic.getFocussed()); }
uic.setFocussed(null, null); uic.setFocusRequired(true); tuic.doInvokeLaters(); } finally { UIContextHolder.popContext();
@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); }
@Test public void testEnvironmentAccessors() { UIContext uic = createUIContext(); Assert.assertTrue("User Context should have a dummy environment by default", uic. isDummyEnvironment()); Assert.assertNotNull("User context should return an environment by default", uic. getEnvironment()); Environment environment = new AbstractEnvironment() { }; uic.setEnvironment(environment); Assert.assertEquals("Incorrect environment returned", environment, uic.getEnvironment()); }
String focusId = uic.getFocussedId(); 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()); Map<String, String> hiddenFields = uic.getEnvironment().getHiddenParameters();
/** * {@inheritDoc} */ @Override public WComponent getFocussed() { return backing.getFocussed(); }
/** * Retrieves the application title for the given context. This mess is required due to WWindow essentially existing * as a separate UI root. If WWindow is eventually removed, then we can just retrieve the title from the root * WApplication. * * @param uic the context to check. * @return the current application title. */ private String getApplicationTitle(final UIContext uic) { WComponent root = uic.getUI(); String title = root instanceof WApplication ? ((WApplication) root).getTitle() : null; Map<String, String> params = uic.getEnvironment().getHiddenParameters(); String target = params.get(WWindow.WWINDOW_REQUEST_PARAM_KEY); if (target != null) { ComponentWithContext targetComp = WebUtilities.getComponentById(target, true); if (targetComp != null && targetComp.getComponent() instanceof WWindow) { try { UIContextHolder.pushContext(targetComp.getContext()); title = ((WWindow) targetComp.getComponent()).getTitle(); } finally { UIContextHolder.popContext(); } } } return title == null ? "" : title; }