Package org.exoplatform.portal.application

Examples of org.exoplatform.portal.application.PortalRequestContext


        public void execute(Event<UIPortalComposer> event) throws Exception {
            UIPortalComposer uiComposer = event.getSource();
            uiComposer.save();
            uiComposer.setEditted(false);

            PortalRequestContext prContext = Util.getPortalRequestContext();

            UIPortalApplication uiPortalApp = (UIPortalApplication) prContext.getUIApplication();
            UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
            UIEditInlineWorkspace uiEditWS = uiWorkingWS.getChild(UIEditInlineWorkspace.class);
            UIPortal editPortal = (UIPortal) uiEditWS.getUIComponent();

            UISiteBody siteBody = uiWorkingWS.findFirstComponentOfType(UISiteBody.class);
            UIPortal uiPortal = (UIPortal) siteBody.getUIComponent();

            if (uiPortal == null) {
                siteBody.setUIComponent(editPortal);
            }
            uiEditWS.setRendered(false);
            uiPortal = (UIPortal) siteBody.getUIComponent();

            uiPortalApp.setSessionOpen(PortalProperties.SESSION_ALWAYS.equals(uiPortal.getSessionAlive()));
            uiPortalApp.setModeState(UIPortalApplication.NORMAL_MODE);
            uiWorkingWS.setRenderedChild(UIPortalApplication.UI_VIEWING_WS_ID);
            prContext.ignoreAJAXUpdateOnPortlets(true);

            if (uiComposer.isPortalExist(editPortal)) {
                DataStorage storage = uiPortalApp.getApplicationComponent(DataStorage.class);
                PortalConfig pConfig = storage.getPortalConfig(uiPortal.getSiteKey().getTypeName(), uiPortal.getSiteKey()
                        .getName());
                if (pConfig != null) {
                    prContext.getUserPortalConfig().setPortalConfig(pConfig);
                }

                // Update the cache of UIPortal from UIPortalApplication
                uiPortalApp.refreshCachedUI();

                UserNode currentNode = uiPortal.getSelectedUserNode();
                SiteKey siteKey = currentNode.getNavigation().getKey();
                PageNodeEvent<UIPortalApplication> pnevent = new PageNodeEvent<UIPortalApplication>(uiPortalApp,
                        PageNodeEvent.CHANGE_NODE, siteKey, currentNode.getURI());
                uiPortalApp.broadcast(pnevent, Event.Phase.PROCESS);

                prContext.addUIComponentToUpdateByAjax(uiWorkingWS);
                JavascriptManager jsManager = prContext.getJavascriptManager();
                jsManager.require("SHARED/portal", "portal").addScripts(
                        "eXo.portal.portalMode=" + UIPortalApplication.NORMAL_MODE + ";");
            } else {
                if (editPortal.getName().equals(prContext.getPortalOwner())) {
                    HttpServletRequest request = prContext.getRequest();
                    LogoutControl.wantLogout();
                    prContext.setResponseComplete(true);
                    prContext.getResponse().sendRedirect(request.getContextPath());
                    return;
                } else {
                    UIApplication uiApp = prContext.getUIApplication();
                    uiApp.addMessage(new ApplicationMessage("UIPortalForm.msg.notExistAnymore", null));
                    prContext.addUIComponentToUpdateByAjax(uiWorkingWS);
                }
            }
        }
View Full Code Here


        super(internalOAuthProvider, socialNetworkService);
    }

    @Override
    public void startOAuthWorkflow(String neededCustomScope) throws OAuthApiException, IOException {
        PortalRequestContext prc = Util.getPortalRequestContext();

        // Save session attribute with URL to redirect. It will be used by GateIn to return to current page after finish OAuth flow
        HttpSession session = prc.getRequest().getSession();
        session.setAttribute(OAuthConstants.ATTRIBUTE_URL_TO_REDIRECT_AFTER_LINK_SOCIAL_ACCOUNT, prc.getRequestURI());

        // Redirect to start OAuth2 flow
        String reqContextPath = prc.getRequestContextPath();
        String requestURI = prc.getRequestURI();
        OAuthProviderType<?> oauthProviderType = getInternalOAuthProvider();
        String initOauthFlowURL = oauthProviderType.getInitOAuthURL(reqContextPath, requestURI);

        // Attach custom scope
        if (neededCustomScope != null) {
            initOauthFlowURL = initOauthFlowURL + "&" + OAuthConstants.PARAM_CUSTOM_SCOPE + "=" + neededCustomScope;
        }

        prc.getResponse().sendRedirect(initOauthFlowURL);
    }
View Full Code Here

     */
    public static <S, C extends Serializable, I> List<javax.portlet.Event> processEvent(UIPortlet<S, C> uiPortlet,
            javax.portlet.Event event) {
        log.trace("Process Event: " + event.getName() + " for portlet: " + uiPortlet.getState());
        try {
            PortalRequestContext context = (PortalRequestContext) WebuiRequestContext.getCurrentInstance();

            //
            EventInvocation eventInvocation = uiPortlet.create(EventInvocation.class, context);

            //
View Full Code Here

*/
public class UIPortalActionListener {

    public static class PingActionListener extends EventListener<UIPortal> {
        public void execute(Event<UIPortal> event) throws Exception {
            PortalRequestContext pContext = (PortalRequestContext) event.getRequestContext();
            HttpServletRequest request = pContext.getRequest();
            pContext.ignoreAJAXUpdateOnPortlets(false);
            pContext.setResponseComplete(true);
            pContext.getWriter().write("" + request.getSession().getMaxInactiveInterval());
        }
View Full Code Here

    public static class ChangeOwnerTypeActionListener extends EventListener<UIPageForm> {
        public void execute(Event<UIPageForm> event) throws Exception {
            UIPageForm uiForm = event.getSource();
            UIFormSelectBox uiSelectBox = uiForm.getUIFormSelectBox(OWNER_TYPE);
            String ownerType = uiSelectBox.getValue();
            PortalRequestContext prContext = Util.getPortalRequestContext();
            UIFormInputSet uiSettingSet = uiForm.getChildById("PageSetting");
            uiForm.setSelectedTab("PageSetting");
            List<UIComponent> list = uiSettingSet.getChildren();

            if (SiteType.PORTAL.getName().equals(ownerType)) {
                list.remove(2);
                list.add(2, uiForm.ownerIdInput);
                uiForm.ownerIdInput.setValue(prContext.getPortalOwner());
                uiForm.findFirstComponentOfType(UIListPermissionSelector.class).setValue(
                        Util.getUIPortal().getAccessPermissions());
                uiForm.findFirstComponentOfType(UIPermissionSelector.class).setValue(Util.getUIPortal().getEditPermission());
            } else {
                list.remove(2);
                uiForm.loadMakableGroupNavigations();
                list.add(2, uiForm.groupIdSelectBox);
                String groupIdSelected = uiForm.groupIdSelectBox.getValue();
                groupIdSelected = groupIdSelected.startsWith("/") ? groupIdSelected : "/" + groupIdSelected;
                String permission = "*:" + groupIdSelected;
                uiForm.findFirstComponentOfType(UIListPermissionSelector.class).setValue(new String[] { permission });
                UserACL userACL = uiForm.getApplicationComponent(UserACL.class);
                permission = userACL.getMakableMT() + ":" + groupIdSelected;
                uiForm.findFirstComponentOfType(UIPermissionSelector.class).setValue(permission);
            }
            prContext.addUIComponentToUpdateByAjax(uiForm.getParent());
        }
View Full Code Here

            // This means that registration has been successful
            if (newUser != null) {
                UIApplication uiApp = context.getUIApplication();
                UIRegisterForm uiRegisterForm = event.getSource();
                PortalRequestContext portalRequestContext = Util.getPortalRequestContext();

                // Save OAuth username as part of user profile of new user
                OrganizationService orgService = uiRegisterForm.getApplicationComponent(OrganizationService.class);
                UserProfileHandler profileHandler = orgService.getUserProfileHandler();
                UserProfile newUserProfile = profileHandler.findUserProfileByName(newUser.getUserName());

                AuthenticationRegistry authRegistry = uiRegisterForm.getApplicationComponent(AuthenticationRegistry.class);
                HttpServletRequest httpRequest = portalRequestContext.getRequest();
                OAuthPrincipal oauthPrincipal = (OAuthPrincipal)authRegistry.getAttributeOfClient(httpRequest, OAuthConstants.ATTRIBUTE_AUTHENTICATED_OAUTH_PRINCIPAL);

                newUserProfile.setAttribute(oauthPrincipal.getOauthProviderType().getUserNameAttrName(), oauthPrincipal.getUserName());
                try {
                    profileHandler.saveUserProfile(newUserProfile, true);
                } catch (OAuthException gtnOAuthException) {
                    // Show warning message if user with this facebookUsername (or googleUsername) already exists
                    // NOTE: It could happen only in case of parallel registration of same oauth user from more browser windows
                    if (gtnOAuthException.getExceptionCode() == OAuthExceptionCode.DUPLICATE_OAUTH_PROVIDER_USERNAME) {

                        // Drop new user
                        orgService.getUserHandler().removeUser(newUser.getUserName(), true);

                        // Clear previous message about successful creation of user because we dropped him. Add message about duplicate oauth username
                        Object[] args = new Object[] {gtnOAuthException.getExceptionAttribute(OAuthConstants.EXCEPTION_OAUTH_PROVIDER_USERNAME),
                                gtnOAuthException.getExceptionAttribute(OAuthConstants.EXCEPTION_OAUTH_PROVIDER_NAME)};
                        ApplicationMessage appMessage = new ApplicationMessage("UIAccountSocial.msg.failed-registration", args, ApplicationMessage.WARNING);
                        uiApp.addMessage(appMessage);
                        return;
                    } else {
                        throw gtnOAuthException;
                    }
                }

                // Clean portalUser from context as we don't need it anymore
                authRegistry.removeAttributeOfClient(httpRequest, OAuthConstants.ATTRIBUTE_AUTHENTICATED_PORTAL_USER);

                // Clear messages (message about successful registration of user)
                uiApp.clearMessages();

                // Close the registration popup
                UIMaskWorkspace.CloseActionListener closePopupListener = new UIMaskWorkspace.CloseActionListener();
                closePopupListener.execute((Event)event);

                // Redirect to finish login with new user
                SiteKey siteKey = portalRequestContext.getSiteKey();
                NodeURL urlToRedirect = portalRequestContext.createURL(NodeURL.TYPE);
                urlToRedirect.setResource(new NavigationResource(siteKey, portalRequestContext.getNodePath()));

                portalRequestContext.getJavascriptManager().addJavascript("window.location = '" + urlToRedirect.toString() + "';");
            }

        }
View Full Code Here

     * have to change) as well as a list of Events to be broadcasted to the other portlets located in the same portal page
     */
    public static class ProcessActionActionListener<S, C extends Serializable, I> extends EventListener<UIPortlet<S, C>> {
        public void execute(Event<UIPortlet<S, C>> event) throws Exception {
            UIPortlet<S, C> uiPortlet = event.getSource();
            PortalRequestContext prcontext = (PortalRequestContext) event.getRequestContext();

            // set the public render parameters from the request before creating the invocation
            HttpServletRequest request = prcontext.getRequest();
            setupPublicRenderParams(uiPortlet, request.getParameterMap());

            // set the navigational state
            String navState = prcontext.getRequestParameter(ExoPortletInvocationContext.NAVIGATIONAL_STATE_PARAM_NAME);
            if (navState != null) {
                uiPortlet.setNavigationalState(ParametersStateString.create(navState));
            }

            //
            ActionInvocation actionInvocation = uiPortlet.create(ActionInvocation.class, prcontext);
            if (actionInvocation == null) {
                return;
            }
            //
            PortletInvocationResponse portletResponse = uiPortlet.invoke(actionInvocation);

            // deal with potential portlet context modifications
            ExoPortletInstanceContext instanceCtx = (ExoPortletInstanceContext) actionInvocation.getInstanceContext();
            if (instanceCtx.getModifiedContext() != null) {
                StatefulPortletContext<C> updatedCtx = (StatefulPortletContext<C>) instanceCtx.getModifiedContext();
                C portletState = uiPortlet.getModifiedState(updatedCtx);
                uiPortlet.update(portletState);
            } else {
                // todo: fix me as this shouldn't probably be done only for the WSRP case
                PortletContext clonedContext = instanceCtx.getClonedContext();
                if (clonedContext != null) {
                    C state = uiPortlet.getClonedState(clonedContext);
                    uiPortlet.update(state);
                }
            }

            if (portletResponse instanceof UpdateNavigationalStateResponse) {
                handleUpdateNavigationalStateResponse((UpdateNavigationalStateResponse) portletResponse, uiPortlet, prcontext);
            } else if (portletResponse instanceof HTTPRedirectionResponse) {
                handleRedirectionResponse((HTTPRedirectionResponse) portletResponse, prcontext.getResponse());
                prcontext.setResponseComplete(true);
            } else if (portletResponse instanceof ErrorResponse) {
                handleErrorResponse((ErrorResponse) portletResponse);
            } else if (portletResponse instanceof SecurityResponse) {
                handleSecurityResponse((SecurityResponse) portletResponse);
            } else {
View Full Code Here

            UIPortlet<S, C> uiPortlet = event.getSource();
            log.trace("Serve Resource for portlet: " + uiPortlet.getPortletContext());
            String resourceId = null;

            //
            PortalRequestContext context = (PortalRequestContext) event.getRequestContext();
            HttpServletResponse response = context.getResponse();

            //
            try {
                // Set the NavigationalState
                String navState = context.getRequestParameter(ExoPortletInvocationContext.NAVIGATIONAL_STATE_PARAM_NAME);
                if (navState != null) {
                    uiPortlet.setNavigationalState(ParametersStateString.create(navState));
                }

                //
                ResourceInvocation resourceInvocation = uiPortlet.create(ResourceInvocation.class, context);

                // set the resourceId to be used in case of a problem
                resourceId = resourceInvocation.getResourceId();

                //
                PortletInvocationResponse portletResponse = uiPortlet.invoke(resourceInvocation);

                //
                int statusCode;
                MultiValuedPropertyMap<String> transportHeaders;
                String contentType;
                String charset;
                Object content;
                if (!(portletResponse instanceof ContentResponse)) {
                    if (portletResponse instanceof ErrorResponse) {
                        ErrorResponse errorResponse = (ErrorResponse) portletResponse;
                        Throwable cause = errorResponse.getCause();
                        if (cause != null) {
                            log.trace("Got error response from portlet", cause);
                        } else if (errorResponse.getMessage() != null) {
                            log.trace("Got error response from portlet:" + errorResponse.getMessage());
                        } else {
                            log.trace("Got error response from portlet");
                        }
                    } else {
                        log.trace("Unexpected response type [" + portletResponse
                                + "]. Expected a ContentResponse or an ErrorResponse.");
                    }
                    statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                    contentType = null;
                    charset = null;
                    transportHeaders = null;
                    content = null;
                } else {
                    //
                    ContentResponse piResponse = (ContentResponse) portletResponse;
                    ResponseProperties properties = piResponse.getProperties();
                    transportHeaders = properties != null ? properties.getTransportHeaders() : null;

                    // Look at status code if there is one and honour it
                    String status = transportHeaders != null ? transportHeaders.getValue(ResourceResponse.HTTP_STATUS_CODE)
                            : null;
                    if (status != null) {
                        try {
                            statusCode = Integer.parseInt(status);
                        } catch (NumberFormatException e) {
                            statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                        }
                    } else {
                        statusCode = HttpServletResponse.SC_OK;
                    }

                    //
                    contentType = piResponse.getContentType();
                    charset = piResponse.getEncoding();

                    //
                    log.trace("Try to get a resource of type: " + contentType + " for the portlet: "
                            + uiPortlet.getId());
                    if (piResponse.getChars() != null) {
                        content = piResponse.getChars();
                    } else if (piResponse.getBytes() != null) {
                        content = piResponse.getBytes();
                    } else {
                        content = null;
                    }
                }

                //
                response.setStatus(statusCode);

                // Set content type if any
                if (contentType != null) {
                    response.setContentType(contentType);
                }

                // Set encoding
                if (charset != null) {
                    response.setCharacterEncoding(charset);
                }

                // Send headers if any
                if (transportHeaders != null) {
                    sendHeaders(transportHeaders, context);
                }

                // Send body if any
                if (content instanceof String) {
                    context.getWriter().write((String) content);
                } else if (content instanceof byte[]) {
                    byte[] bytes = (byte[]) content;
                    response.setContentLength(bytes.length);
                    OutputStream stream = response.getOutputStream();
                    try {
View Full Code Here

        // Remove current UIPage from UIPageBody
        UIPageBody pageBody = uiWorkingWS.findFirstComponentOfType(UIPageBody.class);
        pageBody.setUIComponent(null);

        PortalRequestContext prContext = Util.getPortalRequestContext();
        prContext.addUIComponentToUpdateByAjax(uiWorkingWS);
        prContext.setFullRender(true);
    }
View Full Code Here

    public static class SaveActionListener extends EventListener<UILanguageSelector> {
        public void execute(Event<UILanguageSelector> event) throws Exception {
            WebuiRequestContext rContext = event.getRequestContext();
            String language = event.getRequestContext().getRequestParameter("language");
            PortalRequestContext prqCtx = PortalRequestContext.getCurrentInstance();

            UIPortalApplication uiApp = Util.getUIPortalApplication();
            UIMaskWorkspace uiMaskWS = uiApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
            uiMaskWS.createEvent("Close", Phase.DECODE, rContext).broadcast();

            if (language == null || language.isEmpty() || language.trim().equals(prqCtx.getLocale().getLanguage())) {
                // LocalizationLifecycle will save userProfile if locale is changed
                // We need to handle case : locale is not changed, but user's locale setting has not been initialized
                if (prqCtx.getRemoteUser() != null) {
                    saveLocaleToUserProfile(prqCtx);
                }
                return;
            }
            LocaleConfigService localeConfigService = event.getSource().getApplicationComponent(LocaleConfigService.class);
            LocaleConfig localeConfig = localeConfigService.getLocaleConfig(language);
            if (localeConfig == null)
                localeConfig = localeConfigService.getDefaultLocaleConfig();
            prqCtx.setLocale(localeConfig.getLocale());

            if (prqCtx.getRequestLocale() != null) {
                NodeURL url = prqCtx.createURL(NodeURL.TYPE).setNode(Util.getUIPortal().getNavPath());
                url.setLocale(prqCtx.getLocale());
                prqCtx.sendRedirect(url.toString());
            }
        }
View Full Code Here

TOP

Related Classes of org.exoplatform.portal.application.PortalRequestContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.