@Override protected void preparePaintComponent(final Request request) { super.preparePaintComponent(request); menuContent.setContentAccess(contentAccess); setUrl(menuContent.getUrl()); } };
/** * Sets the content display mode. Note that the window attributes will be ignored if the mode is changed to * something other than {@link WContent.DisplayMode#OPEN_NEW_WINDOW}. * * @param displayMode the content display mode to set. */ public void setDisplayMode(final DisplayMode displayMode) { content.setDisplayMode(displayMode); link.setOpenNewWindow(DisplayMode.OPEN_NEW_WINDOW.equals(content.getDisplayMode())); }
@Override public void execute(final ActionEvent event) { buttonContent.setContentAccess(contentAccess); buttonContent.display(); } });
/** * @return a String representation of this component, for debugging purposes. */ @Override public String toString() { ContentAccess content = getContentAccess(); return toString(content == null ? "null" : content.getClass().getSimpleName()); }
WContent wContent = new WContent(); setActiveContext(createUIContext()); wContent.setContentAccess(content); wContent.setCacheKey("abcd{}<>"); // this test needs the URLs to be consistent wContent.handleRequest(request); wContent.handleRequest(request); wContent.display(); wContent.display(); assertXpathUrlEvaluatesTo(wContent.getUrl(), "//ui:popup/@url", wContent); wContent.display(); assertXpathNotExists("ui:redirect", wContent); wContent.setWidth(width); wContent.setHeight(height); wContent.setResizable(true); wContent.setDisplayMode(WContent.DisplayMode.PROMPT_TO_SAVE); wContent.display(); assertXpathNotExists("//ui:popup", wContent); wContent.display(); assertXpathUrlEvaluatesTo(wContent.getUrl(), "//ui:redirect/@url", wContent); wContent.setContentAccess(null); xml = render(wContent); Assert.assertEquals("Should not have painted any content", "", xml);
XmlStringBuilder xml = renderContext.getWriter(); if (!content.isDisplayRequested()) { Object contentAccess = content.getContentAccess(); switch (content.getDisplayMode()) { case DISPLAY_INLINE: case PROMPT_TO_SAVE: xml.appendTagOpen("ui:redirect"); xml.appendUrlAttribute("url", content.getUrl()); xml.appendEnd(); break; xml.appendUrlAttribute("url", content.getUrl()); xml.appendAttribute("width", content.getWidth().replaceAll("px", "")); xml.appendAttribute("height", content.getHeight().replaceAll("px", "")); xml.appendOptionalAttribute("resizable", content.isResizable(), "true"); xml.appendEnd(); break; throw new IllegalStateException("Invalid display mode: " + content.getDisplayMode());
content.setBytes(data); WContent wContent = new WContent(); wContent.setContentAccess(content); request.setParameter(Environment.TARGET_ID, wContent.getTargetId()); wContent.handleRequest(request); Assert.fail("Should have thrown a content escape"); } catch (ContentEscape escape) { wContent.setCacheKey("key"); wContent.handleRequest(request); Assert.fail("Should have thrown a content escape"); } catch (ContentEscape escape) { wContent.setContentAccess(contentStream); wContent.handleRequest(request); Assert.fail("Should have thrown a content escape"); } catch (ContentEscape escape) {
/** * <p> * Override handleRequest in order to perform processing specific to this component.</p> * * <p> * When the new browser window for the document content is opened, it will make another request to fetch the * content. It is that situation we are trying to detect and handle here.</p> * * @param request the request being responded to. */ @Override public void handleRequest(final Request request) { resetDisplayRequested(); // Has this component been targeted to return the document content? // Look in the request for the target parameter and see if it's for us. // The target parameter is encoded into the url in the javascript that // was rendered by this component to open the new browser window. String targ = request.getParameter(Environment.TARGET_ID); boolean contentReqested = targ != null && targ.equals(getTargetId()); if (contentReqested) { ContentEscape escape = new ContentEscape(getContentAccess()); escape.setCacheable(!Util.empty(getCacheKey())); escape.setDisplayInline(getDisplayMode() != DisplayMode.PROMPT_TO_SAVE); throw escape; } }
ContentAccess content = getContentAccess(); String mode = DisplayMode.PROMPT_TO_SAVE.equals(getDisplayMode()) ? "attach" : "inline"; Environment env = getEnvironment(); Map<String, String> parameters = env.getHiddenParameters(); parameters.put(Environment.TARGET_ID, getTargetId()); if (Util.empty(getCacheKey())) { parameters.remove(Environment.SESSION_TOKEN_VARIABLE); parameters.put(Environment.CONTENT_CACHE_KEY, getCacheKey());
@Test public void testSetContentAccess() { WContent wContent = new WContent(); MockContentAccess content = new MockContentAccess(); wContent.setLocked(true); setActiveContext(createUIContext()); wContent.setContentAccess(content); Assert.assertSame("Incorrect content access returned", content, wContent.getContentAccess()); resetContext(); Assert.assertNull("ContentAccess should be null by default", wContent.getContentAccess()); }
@Test public void testSetCacheKey() throws IOException { final String defaultKey = "DEFAULT KEY"; final String testKey = "TEST KEY"; WContent wContent = new WContent(); Assert.assertNull("CacheKey should be null by default", wContent.getCacheKey()); wContent.setCacheKey(defaultKey); Assert.assertEquals("Incorrect value returned for default cache key", defaultKey, wContent. getCacheKey()); wContent.setLocked(true); setActiveContext(createUIContext()); Assert.assertEquals("Incorrect value returned for default cache key with user context", defaultKey, wContent.getCacheKey()); wContent.setCacheKey(testKey); Assert.assertEquals("Incorrect value returned for cache key with user context", testKey, wContent.getCacheKey()); resetContext(); Assert.assertEquals("Incorrect value returned for default cache key", defaultKey, wContent. getCacheKey()); }
window.setContent(new MockLabel("dummy")); app.add(window); WContent content = new WContent(); content.setContentAccess(new InternalResource("/wcomponents-test.properties", "test")); app.add(content); app.setLocked(true); request.setParameter(Environment.TARGET_ID, content.getId());
@Test public void testSetDisplay() throws IOException { WContent wContent = new WContent(); setActiveContext(createUIContext()); Assert.assertFalse("Display flag should be false by default", wContent.isDisplayRequested()); wContent.display(); Assert.assertTrue("Display flag should be true", wContent.isDisplayRequested()); }
@Test public void testSetHeight() { String height1 = "123px"; String height2 = "456px"; WContent wContent = new WContent(); wContent.setHeight(height1); Assert.assertEquals("Incorrect height returned", height1, wContent.getHeight()); wContent.setHeight(height2); Assert.assertEquals("Incorrect height returned", height2, wContent.getHeight()); }
@Test public void testSetWidth() { String width1 = "123px"; String width2 = "456px"; WContent wContent = new WContent(); wContent.setWidth(width1); Assert.assertEquals("Incorrect width returned", width1, wContent.getWidth()); wContent.setWidth(width2); Assert.assertEquals("Incorrect width returned", width2, wContent.getWidth()); }
@Test public void testSetResizable() { WContent wContent = new WContent(); Assert.assertTrue("Should be resizable by default", wContent.isResizable()); wContent.setResizable(false); Assert.assertFalse("Incorrect value for resizable after setResizable(false) called", wContent.isResizable()); wContent.setResizable(true); Assert.assertTrue("Incorrect value for resizable after setResizable(true) called", wContent. isResizable()); }
@Override public String getUrl() { return content.getUrl(); } };
final WContent buttonContent = new WContent(); final WContent ajaxContent = new WContent(); final WContent menuContent = new WContent(); menuContent.setDisplayMode(DisplayMode.PROMPT_TO_SAVE); WMenuItem menuItem = new WMenuItem(contentDesc) { @Override
/** * Supply this component with access to the document content to be displayed. * * @param contentAccess the ContentAccess which will supply the content. */ public void setContentAccess(final ContentAccess contentAccess) { content.setContentAccess(contentAccess); }
@Test public void testRendererCorrectlyConfigured() { WContent component = new WContent(); Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WContentRenderer); }