// Process action is called for action URLs / form posts, etc // Process action is called once for each click - doView may be called many times // Hence an obsession in process action with putting things in session to // Send to the render process. public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { // System.out.println("==== processAction called ===="); PortletSession pSession = request.getPortletSession(true); // Our first challenge is to figure out which action we want to take // The view selects the "next action" either as a URL parameter // or as a hidden field in the POST data - we check both String doCancel = request.getParameter("sakai.cancel"); String doUpdate = request.getParameter("sakai.update"); // Our next challenge is to pick which action the previous view // has told us to do. Note that the view may place several actions // on the screen and the user may have an option to pick between // them. Make sure we handle the "no action" fall-through. pSession.removeAttribute("error.message"); if (doCancel != null) { response.setPortletMode(PortletMode.VIEW); } else if (doUpdate != null) { processActionEdit(request, response); } else { // System.out.println("Unknown action"); response.setPortletMode(PortletMode.VIEW); } // System.out.println("==== End of ProcessAction ===="); }
@Override public int doEndTag() throws JspException { // From portlet:defineObjects final RenderRequest renderRequest = (RenderRequest) this.pageContext.getAttribute("renderRequest"); final RenderResponse renderResponse = (RenderResponse) this.pageContext.getAttribute("renderResponse"); final PortletDelegationLocator portletDelegationLocator = (PortletDelegationLocator) renderRequest.getAttribute(PortletDelegationLocator.PORTLET_DELECATION_LOCATOR_ATTR); final String sessionKey = this.sessionKeyPrefix + this.fname; final PortletSession portletSession = renderRequest.getPortletSession(); IPortletWindowId portletWindowId = (IPortletWindowId) portletSession.getAttribute(sessionKey); final PortletDelegationDispatcher portletDelegationDispatcher; final DelegateState delegateState; // No id in session, create a new dispatcher if (portletWindowId == null) { portletDelegationDispatcher = portletDelegationLocator.createRequestDispatcher(renderRequest, this.fname); portletWindowId = portletDelegationDispatcher.getPortletWindowId(); portletSession.setAttribute(sessionKey, portletWindowId); final PortletMode portletMode = PortletUtils.getPortletMode(this.portletMode); final WindowState windowState = PortletUtils.getWindowState(this.windowState); delegateState = new DelegateState(portletMode, windowState); } // id in session, get the old dispatcher else { portletDelegationDispatcher = portletDelegationLocator.getRequestDispatcher(renderRequest, portletWindowId); delegateState = null; } final DelegationRequest delegationRequest = new DelegationRequest(); delegationRequest.setDelegateState(delegateState); // Setup base for portlet URLs delegationRequest.setParentPortletMode(this.parentUrlMode); delegationRequest.setParentWindowState(this.parentUrlState); delegationRequest.setParentParameters(this.parentUrlParameters); final JspWriter out = this.pageContext.getOut(); try { portletDelegationDispatcher.doRender( renderRequest, renderResponse, delegationRequest, new JspWriterPortletOutputHandler(out, renderResponse)); } catch (IOException e) { throw new JspException( "Failed to execute delegate render on portlet '" + this.fname + "'", e); } return Tag.EVAL_PAGE; }
@Override public int getSessionMaxInactiveInterval() { PortletSession portletSession = (PortletSession) getSession(true); return portletSession.getMaxInactiveInterval(); }
@Override protected void doProcessCommand(PortletRequest portletRequest, PortletResponse portletResponse) throws Exception { try { copyArticle(portletRequest); } catch (Exception e) { if (e instanceof NoSuchArticleException || e instanceof PrincipalException) { SessionErrors.add(portletRequest, e.getClass()); PortletSession portletSession = portletRequest.getPortletSession(); PortletContext portletContext = portletSession.getPortletContext(); PortletRequestDispatcher portletRequestDispatcher = portletContext.getRequestDispatcher("/html/portlet/journal/error.jsp"); portletRequestDispatcher.include(portletRequest, portletResponse); } else if (e instanceof DuplicateArticleIdException || e instanceof ArticleIdException) { SessionErrors.add(portletRequest, e.getClass()); } else { throw e; } } }
public <T> boolean exists(Class<T> ssoClass) { String key = buildKey(ssoClass); PortletSession session = getSession(); return session != null && session.getAttribute(key, PortletSession.APPLICATION_SCOPE) != null; }
private void sendAlert(RenderRequest request, Context context) { PortletSession pSession = request.getPortletSession(true); String str = (String) pSession.getAttribute(ALERT_MESSAGE); pSession.removeAttribute(ALERT_MESSAGE); if (str != null && str.length() > 0) context.put("alertMessage", validator.escapeHtml(str, false)); }
@Override public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { PortletSession session = request.getPortletSession(); MainSessionController mainSessionController = (MainSessionController) session.getAttribute( MainSessionController.MAIN_SESSION_CONTROLLER_ATT, PortletSession.APPLICATION_SCOPE); String spaceId = (String) session.getAttribute("Silverpeas_Portlet_SpaceId", PortletSession.APPLICATION_SCOPE); PortletPreferences pref = request.getPreferences(); int nbPublis = 5; if (StringUtil.isInteger(pref.getValue("nbPublis", "5"))) { nbPublis = Integer.parseInt(pref.getValue("nbPublis", "5")); } int maxAge = 0; if (StringUtil.isInteger(pref.getValue("maxAge", "0"))) { maxAge = Integer.parseInt(pref.getValue("maxAge", "0")); } KmeliaTransversal kmeliaTransversal = new KmeliaTransversal(mainSessionController); List<PublicationDetail> publications = kmeliaTransversal.getUpdatedPublications(spaceId, maxAge, nbPublis); if (StringUtil.isDefined(spaceId)) { String rssUrl = getRSSUrl(mainSessionController, spaceId); request.setAttribute("rssUrl", rssUrl); } request.setAttribute("Publications", publications); include(request, response, "portlet.jsp"); }
/** * Sets the "javax.portlet.faces.viewIdHistory.<code>portletMode</code>" session attribute * according to the requirements in Section 5.4.3 of the Bridge Spec. There is no corresponding * getter method, because the value is meant to be retrieved by developers via an EL expression. * * @param viewId The current Faces viewId. */ protected void setViewHistory(String viewId) { String attributeName = Bridge.VIEWID_HISTORY.concat(".").concat(renderRequest.getPortletMode().toString()); PortletSession portletSession = renderRequest.getPortletSession(); portletSession.setAttribute(attributeName, viewId); }
/** * Get the specified session attribute in the given scope, creating and setting a new attribute if * no existing found. The given class needs to have a public no-arg constructor. Useful for * on-demand state objects in a web tier, like shopping carts. * * @param session current portlet session * @param name the name of the session attribute * @param clazz the class to instantiate for a new attribute * @param scope the session scope of this attribute * @return the value of the session attribute, newly created if not found * @throws IllegalArgumentException if the session attribute could not be instantiated */ public static Object getOrCreateSessionAttribute( PortletSession session, String name, Class<?> clazz, int scope) throws IllegalArgumentException { Assert.notNull(session, "Session must not be null"); Object sessionObject = session.getAttribute(name, scope); if (sessionObject == null) { Assert.notNull(clazz, "Class must not be null if attribute value is to be instantiated"); try { sessionObject = clazz.newInstance(); } catch (InstantiationException ex) { throw new IllegalArgumentException( "Could not instantiate class [" + clazz.getName() + "] for session attribute '" + name + "': " + ex.getMessage()); } catch (IllegalAccessException ex) { throw new IllegalArgumentException( "Could not access default constructor of class [" + clazz.getName() + "] for session attribute '" + name + "': " + ex.getMessage()); } session.setAttribute(name, sessionObject, scope); } return sessionObject; }
private Map<Object, Object> getSessionContext() { PortletSession session = request.getPortletSession(); Map<Object, Object> store = (Map<Object, Object>) session.getAttribute("org.juzu.session_scope"); if (store == null) { session.setAttribute("org.juzu.session_scope", store = new HashMap<Object, Object>()); } return store; }
protected void maintainBridgeRequestScope( PortletRequest portletRequest, PortletResponse portletResponse, BridgeRequestScope.Transport bridgeRequestScopeTransport) { String bridgeRequestScopeId = bridgeRequestScope.getId(); bridgeRequestScopeCache.put(bridgeRequestScopeId, bridgeRequestScope); String bridgeRequestScopeKey = portletName + PARAM_BRIDGE_REQUEST_SCOPE_ID; if (bridgeRequestScopeTransport == BridgeRequestScope.Transport.PORTLET_SESSION_ATTRIBUTE) { // TCK TestPage071: nonFacesResourceTest // TCK TestPage073: scopeAfterRedisplayResourcePPRTest PortletSession portletSession = portletRequest.getPortletSession(true); portletSession.setAttribute(bridgeRequestScopeKey, bridgeRequestScopeId); } else { if (portletResponse instanceof StateAwareResponse) { logger.debug( "Setting render parameter name=[{0}] value=[{1}]", bridgeRequestScopeKey, bridgeRequestScopeId); try { StateAwareResponse stateAwareResponse = (StateAwareResponse) portletResponse; stateAwareResponse.setRenderParameter(bridgeRequestScopeKey, bridgeRequestScopeId); } catch (IllegalStateException e) { // If a redirect occurred, then swallow/ignore the IllegalStateException if (bridgeRequestScope.isRedirectOccurred()) { // The Portlet API JavaDocs indicate that StateAwareResponse.setRenderParameter(String, // String) // must throw an IllegalStateException if ActionResponse.sendRedirect(String) was // previously // called. The JSR 329 TCK TestPage039 (requestNoScopeOnRedirectTest) and TestPage176 // (redirectActionTest) both perform pseudo-redirects (effectively treated like // navigation-rules // from one JSF viewId to another). Since the tests don't actually call // ActionResponse.sendRedirect(String), this condition is never reached by the TCK. // However, // this condition is a real-world use-case and so the IllegalStateException must be // swallowed/ignored here so that portlet lifecycle processing is able to continue. For // more // information, see: http://issues.liferay.com/browse/FACES-1367 } // Otherwise throw the IllegalStateException. else { throw e; } } } } }
/** * Sets the "javax.portlet.faces.viewIdHistory.<code>portletMode</code>" session attribute * according to the requirements in Section 5.4.3 of the Bridge Spec. There is no corresponding * getter method, because the value is meant to be retrieved by developers via an EL expression. * * @param viewId The current Faces viewId. */ protected void setViewHistory(String viewId) { StringBuilder buf = new StringBuilder(); buf.append(Bridge.VIEWID_HISTORY); buf.append(StringPool.PERIOD); buf.append(renderRequest.getPortletMode()); String attributeName = buf.toString(); PortletSession portletSession = renderRequest.getPortletSession(); portletSession.setAttribute(attributeName, viewId); }
public static List<AnalysisStatusDTO> getBackgroundQueue() { PortletSession session = (PortletSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false); List<AnalysisStatusDTO> backgroundQueue = (List<AnalysisStatusDTO>) session.getAttribute("analysis.backgroundQueue"); if (backgroundQueue == null) { backgroundQueue = new ArrayList<AnalysisStatusDTO>(); session.setAttribute("analysis.backgroundQueue", backgroundQueue); } return backgroundQueue; }
/** * Get SessionBean. * * @param request PortletRequest * @return Vlado2PortletSessionBean */ private static Vlado2PortletSessionBean getSessionBean(PortletRequest request) { PortletSession session = request.getPortletSession(); if (session == null) return null; Vlado2PortletSessionBean sessionBean = (Vlado2PortletSessionBean) session.getAttribute(SESSION_BEAN); if (sessionBean == null) { sessionBean = new Vlado2PortletSessionBean(); session.setAttribute(SESSION_BEAN, sessionBean); } return sessionBean; }
public void addListener(SessionListener sessionListener) { ServletExternalContext.SessionListeners listeners = (ServletExternalContext.SessionListeners) portletSession.getAttribute( ServletExternalContext.SESSION_LISTENERS, PortletSession.APPLICATION_SCOPE); if (listeners == null) { listeners = new ServletExternalContext.SessionListeners(); portletSession.setAttribute( ServletExternalContext.SESSION_LISTENERS, listeners, PortletSession.APPLICATION_SCOPE); } listeners.addListener(sessionListener); }
/** * @see * org.apache.portals.bridges.velocity.GenericVelocityPortlet#processAction(javax.portlet.ActionRequest, * javax.portlet.ActionResponse) */ public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, IOException { String action = request.getParameter(Settings.PARAM_ACTION); if (action == null) { action = ""; } PortletSession session = request.getPortletSession(); if (action.equalsIgnoreCase("doOpenPartner")) { DisplayTreeNode partnerRoot = (DisplayTreeNode) session.getAttribute("partnerRoot"); if (partnerRoot != null) { DisplayTreeNode node = partnerRoot.getChild(request.getParameter("id")); node.setOpen(true); if (node.get("checked") != null) { Iterator it = node.getChildren().iterator(); while (it.hasNext()) { DisplayTreeNode child = (DisplayTreeNode) it.next(); child.put("checked", "true"); } } } } else if (action.equalsIgnoreCase("doClosePartner")) { DisplayTreeNode partnerRoot = (DisplayTreeNode) session.getAttribute("partnerRoot"); if (partnerRoot != null) { DisplayTreeNode node = partnerRoot.getChild(request.getParameter("id")); node.setOpen(false); } } else if (action.equalsIgnoreCase("doOriginalSettings")) { Principal principal = request.getUserPrincipal(); IngridPersistencePrefs.setPref( principal.getName(), IngridPersistencePrefs.SEARCH_PARTNER, ""); DisplayTreeNode partnerRoot = (DisplayTreeNode) session.getAttribute("partnerRoot"); Iterator it = partnerRoot.getChildren().iterator(); while (it.hasNext()) { DisplayTreeNode partnerNode = (DisplayTreeNode) it.next(); partnerNode.setOpen(false); Iterator it2 = partnerNode.getChildren().iterator(); while (it2.hasNext()) { DisplayTreeNode providerNode = (DisplayTreeNode) it2.next(); providerNode.remove("checked"); } } } else { // Zur Suchanfrage hinzufuegen DisplayTreeNode partnerRoot = (DisplayTreeNode) session.getAttribute("partnerRoot"); String resultQuery = UtilsSearch.processSearchPartner("", partnerRoot, request); Principal principal = request.getUserPrincipal(); IngridPersistencePrefs.setPref( principal.getName(), IngridPersistencePrefs.SEARCH_PARTNER, resultQuery); } }
/** * Set the session attribute with the given name to the given value in the given scope. Removes * the session attribute if value is {@code null}, if a session existed at all. Does not create a * new session if not necessary! * * @param request current portlet request * @param name the name of the session attribute * @param value the value of the session attribute * @param scope session scope of this attribute */ public static void setSessionAttribute( PortletRequest request, String name, Object value, int scope) { Assert.notNull(request, "Request must not be null"); if (value != null) { request.getPortletSession().setAttribute(name, value, scope); } else { PortletSession session = request.getPortletSession(false); if (session != null) { session.removeAttribute(name, scope); } } }
@Override public void intercept(HttpContentRequestImpl proxyRequest, PortletRequest portletRequest) { // if the user isn't already authenticated, perform any required // authentication pre-processing final PortletSession session = portletRequest.getPortletSession(); synchronized (PortletUtils.getSessionMutex(session)) { if (!isAlreadyAuthenticated(portletRequest)) { prepareAuthentication(proxyRequest, portletRequest); } session.setAttribute(AUTHENTICATION_TIMEOUT_KEY, System.currentTimeMillis()); } }
public void handleFileUpload(FileUploadEvent event) { List<UploadedFile> uploadedFiles = applicantModelBean.getUploadedFiles(); ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); PortletSession portletSession = (PortletSession) externalContext.getSession(false); String uniqueFolderName = portletSession.getId(); org.primefaces.model.UploadedFile uploadedFile = event.getFile(); UploadedFileWrapper uploadedFileWrapper = new UploadedFileWrapper(uploadedFile, UploadedFile.Status.FILE_SAVED, uniqueFolderName); uploadedFiles.add(uploadedFileWrapper); logger.debug( "Received fileName=[{0}] absolutePath=[{1}]", uploadedFileWrapper.getName(), uploadedFileWrapper.getAbsolutePath()); }
/** * Processes the <CODE>defineObjects</CODE> tag. * * @return <CODE>SKIP_BODY</CODE> */ public int doStartTag() throws JspException { ServletRequest servletRequest = pageContext.getRequest(); PortletRequest portletRequest = (PortletRequest) servletRequest.getAttribute(Constants.PORTLET_REQUEST); PortletResponse portletResponse = (PortletResponse) servletRequest.getAttribute(Constants.PORTLET_RESPONSE); PortletConfig portletConfig = (PortletConfig) servletRequest.getAttribute(Constants.PORTLET_CONFIG); PortletSession portletSession = portletRequest.getPortletSession(false); Map<String, Object> portletSessionScope = null; if (portletSession != null) { portletSessionScope = (Map<String, Object>) portletSession.getAttributeMap(); // getMap(); } else { portletSessionScope = new HashMap<String, Object>(); } PortletPreferences portletPreferences = portletRequest.getPreferences(); Map<String, String[]> portletPreferencesValues = null; if (portletPreferences != null) { portletPreferencesValues = portletPreferences.getMap(); } else { portletPreferencesValues = new HashMap<String, String[]>(); } // set attributes render and request setPortletRequestResponseAttribute(portletRequest, portletResponse); // set attribute portletConfig setAttribute(portletConfig, "portletConfig"); // set attribute portletSession setAttribute(portletSession, "portletSession"); // set attribute portletSession setAttribute(portletSessionScope, "portletSessionScope"); // set attribute portletPreferences setAttribute(portletPreferences, "portletPreferences"); // set attribute portletPreferences setAttribute(portletPreferencesValues, "portletPreferencesValues"); return SKIP_BODY; }
/** * @see * org.apache.portals.bridges.velocity.GenericVelocityPortlet#doView(javax.portlet.RenderRequest, * javax.portlet.RenderResponse) */ public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { Context context = getContext(request); IngridResourceBundle messages = new IngridResourceBundle( getPortletConfig().getResourceBundle(request.getLocale()), request.getLocale()); context.put("MESSAGES", messages); PortletPreferences prefs = request.getPreferences(); String titleKey = prefs.getValue("titleKey", "searchSettings.title.rankingAndGrouping"); response.setTitle(messages.getString(titleKey)); UtilsSearch.doViewForPartnerPortlet(request, context); Principal principal = request.getUserPrincipal(); String partnerStr = (String) IngridPersistencePrefs.getPref( principal.getName(), IngridPersistencePrefs.SEARCH_PARTNER); if (partnerStr != null) { PortletSession session = request.getPortletSession(); DisplayTreeNode partnerRoot = (DisplayTreeNode) session.getAttribute("partnerRoot"); Iterator it = partnerRoot.getChildren().iterator(); while (it.hasNext()) { DisplayTreeNode partnerNode = (DisplayTreeNode) it.next(); if (partnerStr.indexOf(Settings.QFIELD_PARTNER.concat(":").concat(partnerNode.getId())) != -1 || partnerNode.get("checked") != null) { partnerNode.put("checked", "true"); } else { partnerNode.remove("checked"); } Iterator it2 = partnerNode.getChildren().iterator(); while (it2.hasNext()) { DisplayTreeNode providerNode = (DisplayTreeNode) it2.next(); if (partnerStr.indexOf(Settings.QFIELD_PROVIDER.concat(":").concat(providerNode.getId())) != -1) { providerNode.put("checked", "true"); partnerNode.setOpen(true); } else { providerNode.remove("checked"); } } } } super.doView(request, response); }
protected <T> Object getOrCreate(Class<T> ssoClass, ApplicationStateCreator<T> creator) { PortletSession session = getSession(); String key = buildKey(ssoClass); Object sso = session.getAttribute(key, PortletSession.APPLICATION_SCOPE); if (sso == null) { sso = creator.create(); set(ssoClass, (T) sso); } return sso; }
protected String convertProcess( ActionRequest actionRequest, ActionResponse actionResponse, String cmd) throws Exception { ActionResponseImpl actionResponseImpl = (ActionResponseImpl) actionResponse; PortletSession portletSession = actionRequest.getPortletSession(); String className = StringUtil.replaceFirst(cmd, "convertProcess.", StringPool.BLANK); ConvertProcess convertProcess = (ConvertProcess) InstancePool.get(className); String[] parameters = convertProcess.getParameterNames(); if (parameters != null) { String[] values = new String[parameters.length]; for (int i = 0; i < parameters.length; i++) { String parameter = className + StringPool.PERIOD + parameters[i]; if (parameters[i].contains(StringPool.EQUAL)) { String[] parameterPair = StringUtil.split(parameters[i], CharPool.EQUAL); parameter = className + StringPool.PERIOD + parameterPair[0]; } values[i] = ParamUtil.getString(actionRequest, parameter); } convertProcess.setParameterValues(values); } String path = convertProcess.getPath(); if (path != null) { PortletURL portletURL = actionResponseImpl.createRenderURL(); portletURL.setWindowState(WindowState.MAXIMIZED); portletURL.setParameter("struts_action", path); return portletURL.toString(); } else { MaintenanceUtil.maintain(portletSession.getId(), className); MessageBusUtil.sendMessage(DestinationNames.CONVERT_PROCESS, className); return null; } }
/** * Use the configured timeout to determine if the user is already authenticated to the remote * site. * * @param request * @return */ protected boolean isAlreadyAuthenticated(PortletRequest request) { // determine if the last session access was within the timeout window final PortletPreferences preferences = request.getPreferences(); final PortletSession session = request.getPortletSession(); final Long timestamp = (Long) session.getAttribute(AUTHENTICATION_TIMESTAMP_KEY); if (timestamp == null) { return false; } else { final Long timeout = Long.valueOf( preferences.getValue(AUTHENTICATION_TIMESTAMP_KEY, String.valueOf(30 * 60 * 1000))); return (timestamp < System.currentTimeMillis() - timeout); } }
public long getLastAccessedTime() { try { return session.getLastAccessedTime(); } catch (IllegalStateException e) { throw new SessionExpiredException(e); } }
public int getMaxInactiveInterval() { try { return session.getMaxInactiveInterval(); } catch (IllegalStateException e) { throw new SessionExpiredException(e); } }
public void invalidate() { try { session.invalidate(); } catch (IllegalStateException e) { throw new SessionExpiredException(e); } }
public boolean isNew() { try { return session.isNew(); } catch (IllegalStateException e) { throw new SessionExpiredException(e); } }
public void removeAttribute(String string) { try { session.removeAttribute(string); } catch (IllegalStateException e) { throw new SessionExpiredException(e); } }
/** * See note above in run method. Just fiddle with the session to try to cause * IllegalStateExceptions before Seam takes over. * * @param state PersistentFacesState used in rendering * @throws IllegalStateException If logged out. */ private void testSession(PersistentFacesState state) throws IllegalStateException { FacesContext fc = state.getFacesContext(); Object o = fc.getExternalContext().getSession(false); if (o == null) { renderable.renderingException( new FatalRenderingException("Session has ended (User Logout?)")); } else { if (o instanceof HttpSession) { HttpSession session = (HttpSession) o; session.getAttributeNames(); } else if (o instanceof PortletSession) { PortletSession ps = (PortletSession) o; ps.getAttributeNames(); } } }