javax.portlet.PortletMode Java Examples
The following examples show how to use
javax.portlet.PortletMode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleRSSPortlet.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Get the feed content * @param request * @param response * @return Map of params or null if any required data is missing */ private SyndFeed getFeedContent(RenderRequest request, RenderResponse response) { SyndFeed feed; //check cache, otherwise get fresh //we use the feedUrl as the cacheKey String feedUrl = getConfiguredFeedUrl(request); if(StringUtils.isBlank(feedUrl)) { log.debug("No feed URL configured"); doError("error.no.config", "error.heading.config", getPortletModeUrl(response, PortletMode.EDIT), request, response); return null; } String cacheKey = feedUrl; feed = feedCache.get(cacheKey); if(feed != null) { log.debug("Fetching data from feed cache for: " + cacheKey); } else { //get from remote feed = getRemoteFeed(feedUrl, request, response); } return feed; }
Example #2
Source File: InvokeHeaderTest.java From portals-pluto with Apache License 2.0 | 6 votes |
@Test public void invoke2b() throws Exception { meths.reset(); PortletInvoker i = new PortletInvoker(ams, "portlet2"); PortletMode mode = new PortletMode("Config"); req.setMode(mode); i.renderHeaders(req, resp); List<String> names = meths.getMethods(); assertNotNull(names); assertEquals(1, names.size()); List<String> soll = Arrays.asList(new String[] { Header1.class.getSimpleName() + "#header2c", }); for (String name : names) { assertTrue(soll.contains(name)); } }
Example #3
Source File: InvokeRenderTest.java From portals-pluto with Apache License 2.0 | 6 votes |
@Test public void invoke2c() throws Exception { meths.reset(); PortletInvoker i = new PortletInvoker(ams, "portlet2", cfg); PortletMode mode = PortletMode.EDIT; req.setMode(mode); i.render(req, resp); List<String> names = meths.getMethods(); assertNotNull(names); assertEquals(3, names.size()); List<String> soll = Arrays.asList(new String[] { Render2.class.getSimpleName() + "#render2c", Render1.class.getSimpleName() + "#render2b", Render2.class.getSimpleName() + "#render2d", }); assertArrayEquals(soll.toArray(), names.toArray()); }
Example #4
Source File: PortletStateTest.java From sakai with Educational Community License v2.0 | 6 votes |
public void testSerialization() throws IOException, ClassNotFoundException { PortletState state = new PortletState("id"); state.setPortletMode(PortletMode.VIEW); state.setWindowState(WindowState.MAXIMIZED); ByteArrayOutputStream bao = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bao); out.writeObject(state); ByteArrayInputStream bai = new ByteArrayInputStream(bao.toByteArray()); ObjectInputStream in = new ObjectInputStream(bai); PortletState alter = (PortletState) in.readObject(); assertEquals(state, alter); }
Example #5
Source File: Portlet20AnnotationControllerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void standardHandleMethod() throws Exception { DispatcherPortlet portlet = new DispatcherPortlet() { @Override protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException { GenericWebApplicationContext wac = new GenericWebApplicationContext(); wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class)); wac.refresh(); return wac; } }; portlet.init(new MockPortletConfig()); MockRenderRequest request = new MockRenderRequest(PortletMode.VIEW); MockRenderResponse response = new MockRenderResponse(); portlet.render(request, response); assertEquals("test", response.getContentAsString()); }
Example #6
Source File: InvokeRenderTest.java From portals-pluto with Apache License 2.0 | 6 votes |
@Test public void invoke3b() throws Exception { meths.reset(); PortletInvoker i = new PortletInvoker(ams, "portlet3", cfg); PortletMode mode = PortletMode.VIEW; req.setMode(mode); i.render(req, resp); List<String> names = meths.getMethods(); assertNotNull(names); assertEquals(3, names.size()); List<String> soll = Arrays.asList(new String[] { Render1.class.getSimpleName() + "#render3c", Render1.class.getSimpleName() + "#render3a", Render1.class.getSimpleName() + "#render3b", }); assertArrayEquals(soll.toArray(), names.toArray()); }
Example #7
Source File: Utils.java From portals-pluto with Apache License 2.0 | 6 votes |
public boolean checkEqualStateAwareResponse( StateAwareResponse injectedPortletArtifact, StateAwareResponse stateAwareResponse) { if (injectedPortletArtifact.equals(stateAwareResponse)) { return true; } PortletMode injectedPortletMode = injectedPortletArtifact .getPortletMode(); PortletMode portletPortletMode = stateAwareResponse.getPortletMode(); WindowState injectedWindowState = injectedPortletArtifact .getWindowState(); WindowState portletWindowState = stateAwareResponse.getWindowState(); MutableRenderParameters injectedMutableRenderParams = injectedPortletArtifact .getRenderParameters(); MutableRenderParameters portletMutableRenderParams = stateAwareResponse .getRenderParameters(); if (checkEqualResponses(injectedPortletArtifact, stateAwareResponse) && injectedPortletMode.equals(portletPortletMode) && injectedWindowState.equals(portletWindowState) && checkEqualParameters(injectedMutableRenderParams, portletMutableRenderParams)) { return true; } else { return false; } }
Example #8
Source File: PreferencesActionController.java From portals-pluto with Apache License 2.0 | 6 votes |
@ActionMethod(portletName = "portlet1", actionName = "submitPreferences") @CsrfProtected public void submitPreferences(ActionRequest actionRequest, ActionResponse actionResponse) { ResourceBundle resourceBundle = portletConfig.getResourceBundle(actionRequest.getLocale()); models.put("preferences", new Preferences(datePattern)); Set<ParamError> bindingErrors = bindingResult.getAllErrors(); if (bindingErrors.isEmpty()) { try { portletPreferences.setValue("datePattern", datePattern); portletPreferences.store(); actionResponse.setPortletMode(PortletMode.VIEW); actionResponse.setWindowState(WindowState.NORMAL); models.put("globalInfoMessage", resourceBundle.getString("your-request-processed-successfully")); } catch (Exception e) { models.put("globalErrorMessage", resourceBundle.getString("an-unexpected-error-occurred")); logger.error(e.getMessage(), e); } } }
Example #9
Source File: SimpleRSSPortlet.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Get the feed content * @param request * @param response * @return Map of params or null if any required data is missing */ private SyndFeed getFeedContent(RenderRequest request, RenderResponse response) { SyndFeed feed; //check cache, otherwise get fresh //we use the feedUrl as the cacheKey String feedUrl = getConfiguredFeedUrl(request); if(StringUtils.isBlank(feedUrl)) { log.debug("No feed URL configured"); doError("error.no.config", "error.heading.config", getPortletModeUrl(response, PortletMode.EDIT), request, response); return null; } String cacheKey = feedUrl; feed = feedCache.get(cacheKey); if(feed != null) { log.debug("Fetching data from feed cache for: " + cacheKey); } else { //get from remote feed = getRemoteFeed(feedUrl, request, response); } return feed; }
Example #10
Source File: PortletState.java From sakai with Educational Community License v2.0 | 5 votes |
public PortletState(String id) { this.id = id; portletMode = PortletMode.VIEW; windowState = WindowState.NORMAL; parameters = new HashMap(); }
Example #11
Source File: DispatcherPortletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void parameterMappingInterceptorWithIncorrectParam() throws Exception { MockActionRequest request = new MockActionRequest(); MockActionResponse response = new MockActionResponse(); request.setPortletMode(PortletMode.VIEW); request.addUserRole("role1"); request.addParameter("incorrect", "test1"); complexDispatcherPortlet.processAction(request, response); assertNull(response.getRenderParameter("incorrect")); assertNull(response.getRenderParameter("interceptingParam")); }
Example #12
Source File: PortletModeHandlerMappingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void portletModeEdit() throws Exception { request.setPortletMode(PortletMode.EDIT); Object handler = hm.getHandler(request).getHandler(); assertEquals(pac.getBean("editHandler"), handler); }
Example #13
Source File: PortletModeParameterHandlerMapping.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Returns a lookup key that combines the current PortletMode and the current * value of the specified parameter. * @see javax.portlet.PortletRequest#getPortletMode() * @see #setParameterName */ @Override protected PortletModeParameterLookupKey getLookupKey(PortletRequest request) throws Exception { PortletMode mode = request.getPortletMode(); String parameter = request.getParameter(this.parameterName); return new PortletModeParameterLookupKey(mode, parameter); }
Example #14
Source File: ClassChecker.java From portals-pluto with Apache License 2.0 | 5 votes |
/** * Returns true if the class under test has a field by the specified name and value. * * @param fname * Field name * @param value * Field value * @return true if the class under test defines the field with the specified value */ public boolean hasField(String fname, PortletMode value) { boolean result = false; try { Field f = cut.getField(fname); PortletMode fValue = (PortletMode) f.get(null); if (fValue.equals(value)) { result = true; } } catch (Exception e) { } return result; }
Example #15
Source File: InvokeRenderTest.java From portals-pluto with Apache License 2.0 | 5 votes |
@Test public void invoke1b() throws Exception { meths.reset(); PortletInvoker i = new PortletInvoker(ams, "portlet1", cfg); PortletMode mode = new PortletMode("CustomMode"); req.setMode(mode); i.render(req, resp); List<String> names = meths.getMethods(); assertNotNull(names); assertEquals(0, names.size()); }
Example #16
Source File: MockPortalContext.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Create a new MockPortalContext * with default PortletModes (VIEW, EDIT, HELP) * and default WindowStates (NORMAL, MAXIMIZED, MINIMIZED). * @see javax.portlet.PortletMode * @see javax.portlet.WindowState */ public MockPortalContext() { this.portletModes = new ArrayList<PortletMode>(3); this.portletModes.add(PortletMode.VIEW); this.portletModes.add(PortletMode.EDIT); this.portletModes.add(PortletMode.HELP); this.windowStates = new ArrayList<WindowState>(3); this.windowStates.add(WindowState.NORMAL); this.windowStates.add(WindowState.MAXIMIZED); this.windowStates.add(WindowState.MINIMIZED); }
Example #17
Source File: GenericPortletFeaturesInvokeTest.java From portals-pluto with Apache License 2.0 | 5 votes |
@Test public void test6doConfig() throws Exception { List<String> methNames = Arrays.asList(new String[] { TestPortlet6.class.getSimpleName() + "#doHeaders", TestPortlet6.class.getSimpleName() + "#doConfig", }); PortletMode pm = new PortletMode("config"); helper.renderWithHeaders("Portlet6", pm, methNames); assertTrue(meths.isConfigExists()); }
Example #18
Source File: GenericPortletFeaturesInvokeTest.java From portals-pluto with Apache License 2.0 | 5 votes |
@Test public void test6doView() throws Exception { List<String> methNames = Arrays.asList(new String[] { TestPortlet6.class.getSimpleName() + "#doHeaders", TestPortlet6.class.getSimpleName() + "#doView", }); PortletMode pm = PortletMode.VIEW; helper.renderWithHeaders("Portlet6", pm, methNames); assertTrue(meths.isConfigExists()); }
Example #19
Source File: DispatcherPortletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void parameterMappingInterceptorWithCorrectParam() throws Exception { MockActionRequest request = new MockActionRequest(); MockActionResponse response = new MockActionResponse(); request.setPortletMode(PortletMode.VIEW); request.addUserRole("role1"); request.addParameter("interceptingParam", "test1"); complexDispatcherPortlet.processAction(request, response); assertEquals("test1", response.getRenderParameter("interceptingParam")); }
Example #20
Source File: SupportedModesServiceImpl.java From portals-pluto with Apache License 2.0 | 5 votes |
public boolean isPortletModeSupportedByPortlet(String portletId, String mode) { // View mode is always supported if (mode.equalsIgnoreCase(PortletMode.VIEW.toString())) { return true; } String applicationId = PortletWindowConfig.parseContextPath(portletId); String applicationName = applicationId; String portletName = PortletWindowConfig.parsePortletName(portletId); try { if (portletRegistry == null) { LOG.error("Optional Portlet Registry Service not found."); throw new PortletContainerException("Optional Portlet Registry Service not found."); } PortletApplicationDefinition ctx = portletRegistry.getPortletApplication(applicationName); for (Supports sd : ctx.getPortlet(portletName).getSupports()) { if (sd.getMimeType().matches("(?:\\*|\\*/\\*|text/html|text/\\*)")) { for (String pm : sd.getPortletModes()) { if (pm.equalsIgnoreCase(mode)) { return true; } } } } } catch (PortletContainerException e) { LOG.error("Error determining mode support.", e); } LOG.info("Portlet mode '" + mode + "' not found for portletId: '" + portletId + "'"); return false; }
Example #21
Source File: EventRequestWrapperChecker.java From portals-pluto with Apache License 2.0 | 5 votes |
@Override public boolean isPortletModeAllowed(PortletMode mode) { String meth = "isPortletModeAllowed"; Object[] args = { mode }; boolean ret = true; retVal = ret; checkArgs(meth, args); return ret; }
Example #22
Source File: InvokeRenderTest.java From portals-pluto with Apache License 2.0 | 5 votes |
@Test public void invoke2() throws Exception { meths.reset(); PortletInvoker i = new PortletInvoker(ams, "portlet2", cfg); PortletMode mode = PortletMode.VIEW; req.setMode(mode); i.render(req, resp); List<String> names = meths.getMethods(); assertNotNull(names); assertEquals(0, names.size()); }
Example #23
Source File: DispatcherPortletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void handlerInterceptorNoAbort() throws Exception { MockRenderRequest request = new MockRenderRequest(); MockRenderResponse response = new MockRenderResponse(); request.setPortletMode(PortletMode.VIEW); request.addUserRole("role1"); request.addParameter("abort", "false"); complexDispatcherPortlet.doDispatch(request, response); assertTrue(request.getAttribute("test1-remove-never") != null); assertTrue(request.getAttribute("test1-remove-post") == null); assertTrue(request.getAttribute("test1-remove-after") == null); assertTrue(request.getAttribute("test2-remove-never") != null); assertTrue(request.getAttribute("test2-remove-post") == null); assertTrue(request.getAttribute("test2-remove-after") == null); }
Example #24
Source File: DispatcherPortletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void portletModeParameterMappingInvalidHelpRenderRequest() throws Exception { MockRenderRequest request = new MockRenderRequest(); MockRenderResponse response = new MockRenderResponse(); request.setPortletMode(PortletMode.HELP); request.setParameter("action", "help3"); complexDispatcherPortlet.doDispatch(request, response); Map<?, ?> model = (Map<?, ?>) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE); assertTrue(model.get("exception").getClass().equals(NoHandlerFoundException.class)); InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE); assertEquals("failed-unavailable", view.getBeanName()); }
Example #25
Source File: DispatcherPortletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void portletModeMappingEditActionRequestWithUnauthorizedUserRole() throws Exception { MockActionRequest request = new MockActionRequest(); MockActionResponse response = new MockActionResponse(); request.setPortletMode(PortletMode.EDIT); request.addUserRole("role3"); request.setParameter("action", "not mapped"); request.setParameter("myParam", "not mapped"); complexDispatcherPortlet.processAction(request, response); String exception = response.getRenderParameter(DispatcherPortlet.ACTION_EXCEPTION_RENDER_PARAMETER); assertNotNull(exception); String name = PortletSecurityException.class.getName(); assertTrue(exception.startsWith(name)); }
Example #26
Source File: MiscTest.java From portals-pluto with Apache License 2.0 | 5 votes |
/** * Test to ensure that the basic modes are supported. * @todo Enhance to check for custom modes. * @param req * @return */ protected TestResult checkSupportedModes(PortletRequest request) { TestResult result = new TestResult(); result.setDescription("Ensure the expected portlet modes are returned."); List<PortletMode> requiredPortletModes = new ArrayList<PortletMode>(); requiredPortletModes.add(PortletMode.VIEW); requiredPortletModes.add(PortletMode.EDIT); requiredPortletModes.add(PortletMode.HELP); for (Enumeration<PortletMode> en = request.getPortalContext().getSupportedPortletModes(); en.hasMoreElements(); ) { PortletMode portletMode = en.nextElement(); requiredPortletModes.remove(portletMode); } if (requiredPortletModes.isEmpty()) { result.setReturnCode(TestResult.PASSED); } else { result.setReturnCode(TestResult.FAILED); StringBuffer buffer = new StringBuffer(); for (Iterator<PortletMode> it = requiredPortletModes.iterator(); it.hasNext(); ) { buffer.append(it.next()).append(", "); } result.setResultMessage("Required portlet modes [" + buffer.toString() + "] are not supported."); } return result; }
Example #27
Source File: ActionResponseWrapperChecker.java From portals-pluto with Apache License 2.0 | 5 votes |
@Override public PortletMode getPortletMode() { String meth = "getPortletMode"; Object[] args = {}; PortletMode ret = PortletMode.EDIT; retVal = ret; checkArgs(meth, args); return ret; }
Example #28
Source File: EventResponseWrapperChecker.java From portals-pluto with Apache License 2.0 | 5 votes |
@Override public PortletMode getPortletMode() { String meth = "getPortletMode"; Object[] args = {}; PortletMode ret = PortletMode.EDIT; retVal = ret; checkArgs(meth, args); return ret; }
Example #29
Source File: DispatcherPortletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void existingMultipartRequest() throws Exception { MockActionRequest request = new MockActionRequest(); MockActionResponse response = new MockActionResponse(); request.setPortletMode(PortletMode.EDIT); ComplexPortletApplicationContext.MockMultipartResolver multipartResolver = (ComplexPortletApplicationContext.MockMultipartResolver) complexDispatcherPortlet.getPortletApplicationContext().getBean("portletMultipartResolver"); MultipartActionRequest multipartRequest = multipartResolver.resolveMultipart(request); complexDispatcherPortlet.processAction(multipartRequest, response); multipartResolver.cleanupMultipart(multipartRequest); assertNotNull(request.getAttribute("cleanedUp")); }
Example #30
Source File: DispatcherPortletTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void noDetectAllHandlerMappingsWithPortletModeActionRequest() throws Exception { DispatcherPortlet complexDispatcherPortlet = new DispatcherPortlet(); complexDispatcherPortlet.setContextClass(ComplexPortletApplicationContext.class); complexDispatcherPortlet.setNamespace("test"); complexDispatcherPortlet.setDetectAllHandlerMappings(false); complexDispatcherPortlet.init(new MockPortletConfig(getPortletContext(), "complex")); MockActionRequest request = new MockActionRequest(); MockActionResponse response = new MockActionResponse(); request.setPortletMode(PortletMode.EDIT); complexDispatcherPortlet.processAction(request, response); String exceptionParam = response.getRenderParameter(DispatcherPortlet.ACTION_EXCEPTION_RENDER_PARAMETER); assertNotNull(exceptionParam); assertTrue(exceptionParam.startsWith(NoHandlerFoundException.class.getName())); }