Java Code Examples for javax.portlet.PortletSession#setAttribute()
The following examples show how to use
javax.portlet.PortletSession#setAttribute() .
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: PortletRequestAttributes.java From spring4-understanding with Apache License 2.0 | 7 votes |
@Override public void setAttribute(String name, Object value, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot set request attribute - request is not active anymore!"); } this.request.setAttribute(name, value); } else { PortletSession session = getSession(true); if (scope == SCOPE_GLOBAL_SESSION) { session.setAttribute(name, value, PortletSession.APPLICATION_SCOPE); this.globalSessionAttributesToUpdate.remove(name); } else { session.setAttribute(name, value); this.sessionAttributesToUpdate.remove(name); } } }
Example 2
Source File: IMSBLTIPortlet.java From sakai with Educational Community License v2.0 | 6 votes |
public void processActionReset(String action,ActionRequest request, ActionResponse response) throws PortletException, IOException { // TODO: Check Role log.debug("Removing preferences...."); clearSession(request); PortletSession pSession = request.getPortletSession(true); PortletPreferences prefs = request.getPreferences(); try { prefs.reset("sakai.descriptor"); for (String element : fieldList) { prefs.reset("imsti."+element); prefs.reset("sakai:imsti."+element); } log.debug("Preference removed"); } catch (ReadOnlyException e) { setErrorMessage(request, rb.getString("error.modify.prefs")) ; return; } prefs.store(); // Go back to the main edit page pSession.setAttribute("sakai.view", "edit"); }
Example 3
Source File: AppScopedSessionAttributeTest.java From portals-pluto with Apache License 2.0 | 6 votes |
protected TestResult checkRemoveAppScopedAttribute(PortletSession session) { TestResult result = new TestResult(); result.setDescription("Remove an application scoped session attribute " + "and ensure it's null."); result.setSpecPLT("15.3"); session.setAttribute(KEY, VALUE, PortletSession.APPLICATION_SCOPE); session.removeAttribute(KEY, PortletSession.APPLICATION_SCOPE); Object value = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE); if (value == null) { result.setReturnCode(TestResult.PASSED); } else { TestUtils.failOnAssertion("session attribute", value, null, result); } return result; }
Example 4
Source File: URLTests_ActionURL.java From portals-pluto with Apache License 2.0 | 6 votes |
@ActionMethod(portletName = "ActionURLTests") public void processAction(ActionRequest portletReq, ActionResponse portletResp) throws PortletException, IOException { // evaluate results for test case // V3URLTests_ActionURL_setParameterB7 { ModuleTestCaseDetails tcd = new ModuleTestCaseDetails(); TestResult tr8 = tcd.getTestResultFailed( V3URLTESTS_ACTIONURL_SETPARAMETERB7); String tcval = portletReq.getParameter("tc"); // let exception be thrown if tc parm isn't defined (test case error) if (tcval != null && tcval != null && tcval .equals("V3URLTests_ActionURL_setParameterB7")) { String[] aval = portletReq.getParameterValues("parm1"); String[] eval = null; CompareUtils.arraysEqual("Request", aval, " expected: ", eval, tr8); PortletSession ps = portletReq.getPortletSession(); ps.setAttribute( RESULT_ATTR_PREFIX + "V3URLTests_ActionURL_setParameterB7", tr8); portletResp.setRenderParameter("tc", tcval); } } }
Example 5
Source File: IMSBLTIPortlet.java From sakai with Educational Community License v2.0 | 6 votes |
public void processActionReset(String action,ActionRequest request, ActionResponse response) throws PortletException, IOException { // TODO: Check Role log.debug("Removing preferences...."); clearSession(request); PortletSession pSession = request.getPortletSession(true); PortletPreferences prefs = request.getPreferences(); try { prefs.reset("sakai.descriptor"); for (String element : fieldList) { prefs.reset("imsti."+element); prefs.reset("sakai:imsti."+element); } log.debug("Preference removed"); } catch (ReadOnlyException e) { setErrorMessage(request, rb.getString("error.modify.prefs")) ; return; } prefs.store(); // Go back to the main edit page pSession.setAttribute("sakai.view", "edit"); }
Example 6
Source File: PortletHelper.java From sakai with Educational Community License v2.0 | 6 votes |
public static void setErrorMessage(PortletRequest request, String errorMsg, Throwable t) { if ( errorMsg == null ) errorMsg = "null"; PortletSession pSession = request.getPortletSession(true); pSession.setAttribute("error.message",errorMsg); OutputStream oStream = new ByteArrayOutputStream(); PrintStream pStream = new PrintStream(oStream); log.error("{}", oStream); log.error("{}", pStream); // errorMsg = errorMsg .replaceAll("<","<").replaceAll(">",">"); StringBuffer errorOut = new StringBuffer(); errorOut.append("<p class=\"portlet-msg-error\">\n"); errorOut.append(ComponentManager.get(FormattedText.class).escapeHtmlFormattedText(errorMsg)); errorOut.append("\n</p>\n<!-- Traceback for this error\n"); errorOut.append(oStream.toString()); errorOut.append("\n-->\n"); pSession.setAttribute("error.output",errorOut.toString()); Map map = request.getParameterMap(); pSession.setAttribute("error.map",map); }
Example 7
Source File: RenderStateTests_SPEC2_12_MutableRenderState2.java From portals-pluto with Apache License 2.0 | 6 votes |
@Override public void processAction(ActionRequest portletReq, ActionResponse portletResp) throws PortletException, IOException { ModuleTestCaseDetails tcd = new ModuleTestCaseDetails(); StringWriter writer = new StringWriter(); /* * TestCase: * V3RenderStateTests_SPEC2_12_MutableRenderState_getRenderParameters3 */ /* * Details: * "If no render parameters are available, the object will be empty." */ TestResult result = tcd.getTestResultFailed( V3RENDERSTATETESTS_SPEC2_12_MUTABLERENDERSTATE_GETRENDERPARAMETERS3); if(portletResp.getRenderParameters().isEmpty()){ result.setTcSuccess(true); } result.writeTo(writer); PortletSession ps = portletReq.getPortletSession(); ps.setAttribute(Constants.RESULT_ATTR_PREFIX + "RenderStateTests_SPEC2_12_MutableRenderState2", writer.toString()); }
Example 8
Source File: AdapterPortlet.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
public void processAction( ActionRequest request, ActionResponse response) throws PortletException, IOException { PortletTracer.info(Constants.NOME_MODULO, "AdapterPortlet", "action", "Invocato"); // set into threadLocal variables the jsr 168 portlet object PortletAccess.setPortletConfig(getPortletConfig()); PortletAccess.setPortletRequest(request); PortletAccess.setPortletResponse(response); PortletSession portletSession = request.getPortletSession(); portletSession.setAttribute("BrowserLocale", request.getLocale()); processService(request, response); }
Example 9
Source File: PortletSessionBeanHolder.java From portals-pluto with Apache License 2.0 | 5 votes |
/** * Sets the portlet session bean holder in a ThreadLocal object for the given portlet session. If no bean holder * exists in the session, a new one is created. * * @param ps * The portlet session. * @return The portlet session bean holder */ public static void setBeanHolder(PortletRequest req, PortletSessionScopedConfig config) { PortletSession ps = req.getPortletSession(); String windowId = req.getWindowID(); PortletSessionScopedBeanMap map = (PortletSessionScopedBeanMap) ps.getAttribute(ATTRIBNAME, PortletSession.APPLICATION_SCOPE); boolean createdMap = false; if (map == null) { map = new PortletSessionScopedBeanMap(); ps.setAttribute(ATTRIBNAME, map, PortletSession.APPLICATION_SCOPE); createdMap = true; } PortletSessionBeanHolder holder = new PortletSessionBeanHolder(map, windowId, config); holders.set(holder); if (isTrace) { StringBuilder txt = new StringBuilder(80); txt.append("Set portlet session bean holder."); txt.append(" ThreadId: ").append(Thread.currentThread().getId()); txt.append(", PortletSession: ").append(ps.getId()); txt.append(", WindowId: ").append(windowId); txt.append(", Added new BeanMap to session: ").append(createdMap); LOG.debug(txt.toString()); } }
Example 10
Source File: IMSBLTIPortlet.java From sakai with Educational Community License v2.0 | 5 votes |
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { log.debug("==== processAction called ===="); String action = request.getParameter("sakai.action"); log.debug("sakai.action = {}", action); PortletSession pSession = request.getPortletSession(true); // Clear before Action clearErrorMessage(request); String view = (String) pSession.getAttribute("sakai.view"); log.debug("sakai.view={}", view); if ( action == null ) { // Do nothing } else if ( action.equals("main") ) { response.setPortletMode(PortletMode.VIEW); } else if ( action.equals("edit") ) { pSession.setAttribute("sakai.view", "edit"); } else if ( action.equals("edit.reset") ) { pSession.setAttribute("sakai.view","edit.reset"); } else if (action.equals("edit.setup")){ pSession.setAttribute("sakai.view","edit.setup"); } else if ( action.equals("edit.clear") ) { clearSession(request); response.setPortletMode(PortletMode.VIEW); pSession.setAttribute("sakai.view", "main"); } else if ( action.equals("edit.do.reset") ) { processActionReset(action,request, response); } else if ( action.equals("edit.save") ) { processActionSave(action,request, response); } log.debug("==== End of ProcessAction ===="); }
Example 11
Source File: TestPortlet.java From portals-pluto with Apache License 2.0 | 5 votes |
private void processStateAwarePhase( PortletRequest request, StateAwareResponse response) { String testId = getTestId(request); PortletTest test = (PortletTest) tests.get(testId); if (test != null) { TestResults results = test.doTest(getPortletConfig(), getPortletContext(), request, response); PortletSession session = request.getPortletSession(); TestResults existingResults = (TestResults) session.getAttribute(test.getClass().getName()); if (existingResults != null) { for (TestResult result : results.getCollection()) { existingResults.add(result); } } else { session.setAttribute(test.getClass().getName(), results); } } Map<String, String[]> renderParameters = null; if (test != null) { renderParameters = test.getRenderParameters(request); } if (renderParameters == null) { renderParameters = new HashMap<String, String[]>(); } renderParameters.put("testId", new String[] { testId }); response.setRenderParameters(renderParameters); }
Example 12
Source File: TestPortlet.java From portals-pluto with Apache License 2.0 | 5 votes |
public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { String testId = getTestId(request); PortletTest test = (PortletTest) tests.get(testId); if (test != null) { TestResults results = test.doTest(getPortletConfig(), getPortletContext(), request, response); PortletSession session = request.getPortletSession(); TestResults existing = (TestResults) session.getAttribute( test.getClass().getName()); if (existing != null) { for (TestResult result : results.getCollection()) { existing.add(result); } request.setAttribute("results", existing); session.setAttribute(test.getClass().getName(), null); } else { request.setAttribute("results", results); } } if (test.getConfig().getDisplayURI().indexOf("load_resource_test") > -1) { response.setContentType("text/html"); getPortletContext().getRequestDispatcher("/jsp/test_results.jsp") .include(request, response); } }
Example 13
Source File: IMSBLTIPortlet.java From sakai with Educational Community License v2.0 | 5 votes |
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { log.debug("==== processAction called ===="); String action = request.getParameter("sakai.action"); log.debug("sakai.action = {}", action); PortletSession pSession = request.getPortletSession(true); // Clear before Action clearErrorMessage(request); String view = (String) pSession.getAttribute("sakai.view"); log.debug("sakai.view={}", view); if ( action == null ) { // Do nothing } else if ( action.equals("main") ) { response.setPortletMode(PortletMode.VIEW); } else if ( action.equals("edit") ) { pSession.setAttribute("sakai.view", "edit"); } else if ( action.equals("edit.reset") ) { pSession.setAttribute("sakai.view","edit.reset"); } else if (action.equals("edit.setup")){ pSession.setAttribute("sakai.view","edit.setup"); } else if ( action.equals("edit.clear") ) { clearSession(request); response.setPortletMode(PortletMode.VIEW); pSession.setAttribute("sakai.view", "main"); } else if ( action.equals("edit.do.reset") ) { processActionReset(action,request, response); } else if ( action.equals("edit.save") ) { processActionSave(action,request, response); } log.debug("==== End of ProcessAction ===="); }
Example 14
Source File: AdapterPortlet.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
@Override public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { PortletTracer.info(Constants.NOME_MODULO, "AdapterPortlet", "action", "Invocato"); // set into threadLocal variables the jsr 168 portlet object PortletAccess.setPortletConfig(getPortletConfig()); PortletAccess.setPortletRequest(request); PortletAccess.setPortletResponse(response); PortletSession portletSession = request.getPortletSession(); portletSession.setAttribute("BrowserLocale", request.getLocale()); processService(request, response); }
Example 15
Source File: SimpleAttributeTest.java From portals-pluto with Apache License 2.0 | 5 votes |
protected TestResult checkEnumerateAttributes(PortletSession session) { TestResult result = new TestResult(); result.setDescription("Sets session attributes and enumerates over them."); int count = 5; for (int i = 0; i < count; i++) { session.setAttribute(KEY + "." + i, VAL); } int found = 0; for (Enumeration<String> en = session.getAttributeNames(); en.hasMoreElements(); ) { String name = (String) en.nextElement(); if (name.startsWith(KEY)) { found++; } } if (count != found) { result.setReturnCode(TestResult.FAILED); result.setResultMessage("Expected " + count + " attributes. " + "Found " + found); } else { result.setReturnCode(TestResult.PASSED); } return result; }
Example 16
Source File: RedirectScopedBeanHolder.java From portals-pluto with Apache License 2.0 | 5 votes |
/** * Sets the redirect scope bean holder in a ThreadLocal object for the portlet session associated with the given request. If no bean holder * exists in the session, a new one is created. * * @param req The portlet request. * @return The redirect scope bean holder */ public static void setBeanHolder(PortletRequest req) { PortletSession ps = req.getPortletSession(); String windowId = req.getWindowID(); PortletSessionScopedBeanMap map = (PortletSessionScopedBeanMap) ps.getAttribute(ATTRIBNAME, PortletSession.APPLICATION_SCOPE); boolean createdMap = false; if (map == null) { map = new PortletSessionScopedBeanMap(); ps.setAttribute(ATTRIBNAME, map, PortletSession.APPLICATION_SCOPE); createdMap = true; } RedirectScopedBeanHolder holder = new RedirectScopedBeanHolder(map, windowId); holders.set(holder); if (isTrace) { StringBuilder txt = new StringBuilder(80); txt.append("Set redirect scope bean holder."); txt.append(" ThreadId: ").append(Thread.currentThread().getId()); txt.append(", PortletSession: ").append(ps.getId()); txt.append(", WindowId: ").append(windowId); txt.append(", Added new BeanMap to session: ").append(createdMap); LOG.debug(txt.toString()); } }
Example 17
Source File: SakaiIFrame.java From sakai with Educational Community License v2.0 | 4 votes |
private void addAlert(ActionRequest request,String message) { PortletSession pSession = request.getPortletSession(true); pSession.setAttribute(ALERT_MESSAGE, message); }
Example 18
Source File: PortletIFrame.java From sakai with Educational Community License v2.0 | 4 votes |
private void addAlert(ActionRequest request,String message) { PortletSession pSession = request.getPortletSession(true); pSession.setAttribute(ALERT_MESSAGE, message); }
Example 19
Source File: TestPortlet.java From portals-pluto with Apache License 2.0 | 4 votes |
/** * Serves up the <code>view</code> mode. * TODO: more javadoc. * * @param request the protlet request. * @param response the portlet response. */ @Override public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { // Get the current test ID, the test instance and its config. String testId = getTestId(request); TestConfig testConfig = null; PortletTest test = null; if (testId != null) { testConfig = (TestConfig) testConfigs.get(Integer.parseInt(testId)); test = (PortletTest) tests.get(testId); } if (LOG.isDebugEnabled()) { for (Entry<String, String[]> e : request.getParameterMap().entrySet()) { LOG.debug(e.getKey() + " => " + Arrays.asList(e.getValue())); } LOG.debug("Test ID: " + testId); LOG.debug("Test Config: " + testConfig); if (testConfig != null) { LOG.debug("Test config view: " + testConfig.getDisplayURI()); } } // For non-ActionTest, run test and save results in request. if (test != null) { TestResults results = test.doTest(getPortletConfig(), getPortletContext(), request, response); PortletSession session = request.getPortletSession(); TestResults existing = (TestResults) session.getAttribute( test.getClass().getName()); if (existing != null) { for (TestResult result : results.getCollection()) { existing.add(result); } request.setAttribute("results", existing); session.setAttribute(test.getClass().getName(), null); } else { request.setAttribute("results", results); } } if (testId == null) { request.setAttribute("testConfigs", testConfigs); } else { TestConfig nextTestConfig = null; TestConfig prevTestConfig = null; int index = testConfigs.indexOf(test.getConfig()); if (index == 0) { prevTestConfig = (TestConfig) testConfigs.get(testConfigs.size() - 1); nextTestConfig = (TestConfig) testConfigs.get(index + 1); } else if (index == testConfigs.size() - 1) { prevTestConfig = (TestConfig) testConfigs.get(index - 1); nextTestConfig = (TestConfig) testConfigs.get(0); } else { prevTestConfig = (TestConfig) testConfigs.get(index - 1); nextTestConfig = (TestConfig) testConfigs.get(index + 1); } request.setAttribute("prevTest", prevTestConfig); request.setAttribute("nextTest", nextTestConfig); request.setAttribute("testId", new Integer(testId)); request.setAttribute("test", test); } // Set content type for render response, and dispatch to JSP. response.setContentType("text/html"); String displayUri = null; if (testConfig != null) { displayUri = testConfig.getDisplayURI(); } else { displayUri = "/jsp/introduction.jsp"; } PortletRequestDispatcher dispatcher = getPortletContext() .getRequestDispatcher(displayUri); dispatcher.include(request, response); }
Example 20
Source File: PortletIFrame.java From sakai with Educational Community License v2.0 | 4 votes |
private void addAlert(ActionRequest request,String message) { PortletSession pSession = request.getPortletSession(true); pSession.setAttribute(ALERT_MESSAGE, message); }