Search in sources :

Example 1 with PortletModeException

use of javax.portlet.PortletModeException in project displaytag by hazendaz.

the class PortletHref method toString.

/**
 * To string.
 *
 * @return the string
 *
 * @see org.displaytag.util.Href#toString()
 */
@Override
public String toString() {
    final PortletURL url;
    if (this.isAction()) {
        url = this.renderResponse.createActionURL();
    } else {
        url = this.renderResponse.createRenderURL();
    }
    if (this.isRequestedSecure()) {
        try {
            url.setSecure(true);
        } catch (final PortletSecurityException pse) {
            throw new RuntimeException("Creating secure PortletURL Failed.", pse);
        }
    }
    if (this.getRequestedMode() != null) {
        try {
            url.setPortletMode(this.getRequestedMode());
        } catch (final PortletModeException pme) {
            final IllegalStateException ise = new IllegalStateException("Requested PortletMode='" + this.getRequestedMode() + "' could not be set.");
            ise.initCause(pme);
            throw ise;
        }
    }
    if (this.getRequestedState() != null) {
        try {
            url.setWindowState(this.getRequestedState());
        } catch (final WindowStateException wse) {
            final IllegalStateException ise = new IllegalStateException("Requested WindowState='" + this.getRequestedState() + "' could not be set.");
            ise.initCause(wse);
            throw ise;
        }
    }
    for (final Entry<String, String[]> entry : this.parameters.entrySet()) {
        final String name = entry.getKey();
        final String[] value = entry.getValue();
        url.setParameter(name, value);
    }
    if (this.getAnchor() == null) {
        return url.toString();
    }
    return url.toString() + "#" + this.getAnchor();
}
Also used : WindowStateException(javax.portlet.WindowStateException) PortletSecurityException(javax.portlet.PortletSecurityException) PortletURL(javax.portlet.PortletURL) PortletModeException(javax.portlet.PortletModeException)

Example 2 with PortletModeException

use of javax.portlet.PortletModeException in project liferay-faces-bridge-impl by liferay.

the class BridgePhaseActionImpl method execute.

@Override
public void execute() throws BridgeDefaultViewNotSpecifiedException, BridgeException {
    logger.debug(Logger.SEPARATOR);
    logger.debug("execute(ActionRequest, ActionResponse) portletName=[{0}]", portletName);
    try {
        init(actionRequest, actionResponse, Bridge.PortletPhase.ACTION_PHASE);
        // PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-202
        bridgeRequestScope.setPortletMode(actionRequest.getPortletMode());
        // If the "javax.portlet.faces.PortletMode" request parameter has a value, then the developer probably
        // specified a URL like <h:outputLink value="portlet:render"> using f:param to set the request parameter
        // for switching modes. This is one of the tests in the TCK.
        String portletModeParam = actionRequest.getParameter(Bridge.PORTLET_MODE_PARAMETER);
        if (portletModeParam != null) {
            try {
                actionResponse.setPortletMode(new PortletMode(portletModeParam));
            } catch (PortletModeException e) {
                logger.error("Invalid parameter value {0}=[{1}]", Bridge.PORTLET_MODE_PARAMETER, portletModeParam);
            }
        }
        // Attach the JSF 2.2 client window to the JSF lifecycle so that Faces Flows can be utilized.
        attachClientWindowToLifecycle(facesContext, facesLifecycle);
        // Execute all the phases of the JSF lifecycle except for RENDER_RESPONSE since that can only be executed
        // during the RENDER_PHASE of the portlet lifecycle.
        facesLifecycle.execute(facesContext);
        throwQueuedExceptionIfNecessary(facesContext);
        // Set a flag on the bridge request scope indicating that the Faces Lifecycle has executed.
        bridgeRequestScope.setFacesLifecycleExecuted(true);
        // Since this is a full-page postback, the <head>...</head> section of the portal page needs to be
        // completely re-rendered during the subsequent RENDER_PHASE of the portlet lifecycle. Because of this, the
        // resources in the HeadManagedBean must be cleared so that the bridge will not recognize any resources as
        // already being present in the <head>...</head> section.
        clearHeadManagedBeanResources(facesContext);
        // redirect and portlet mode change has not occurred.
        if (bridgeRequestScope.isRedirectOccurred() || bridgeRequestScope.isPortletModeChanged()) {
            bridgeRequestScope.release(facesContext);
        } else {
            // Save the faces view root and any messages in the faces context so that they can be restored during
            // the RENDER_PHASE of the portlet lifecycle.
            bridgeRequestScope.saveState(facesContext);
            maintainBridgeRequestScope(actionRequest, actionResponse, BridgeRequestScope.Transport.RENDER_PARAMETER);
        }
        // Spec 6.6 (Namespacing)
        indicateNamespacingToConsumers(facesContext.getViewRoot(), actionResponse);
    } catch (Throwable t) {
        throw new BridgeException(t);
    } finally {
        cleanup(actionRequest);
    }
}
Also used : BridgeException(javax.portlet.faces.BridgeException) PortletMode(javax.portlet.PortletMode) PortletModeException(javax.portlet.PortletModeException)

Example 3 with PortletModeException

use of javax.portlet.PortletModeException in project WebproxyPortlet by uPortal-Project.

the class EditProxyController method updatePortlet.

@ActionMapping
public void updatePortlet(@ModelAttribute("form") ProxyPortletForm form, ActionRequest request, ActionResponse response, @RequestParam(value = "Save", required = false) String save) throws PortletModeException {
    if (StringUtils.isNotBlank(save)) {
        try {
            final PortletPreferences preferences = request.getPreferences();
            preferences.setValue(GenericContentRequestImpl.CONTENT_LOCATION_PREFERENCE, form.getLocation());
            preferences.setValue(GenericContentRequestImpl.CONTENT_LOCATION_MAXIMIZED_PREFERENCE, form.getMaxLocation());
            preferences.setValue(ProxyPortletController.CONTENT_SERVICE_KEY, form.getContentService());
            preferences.setValue(URLRewritingFilter.WHITELIST_REGEXES_KEY, form.getWhitelistRegexes());
            preferences.setValue(ProxyPortletController.PREF_CHARACTER_ENCODING, form.getPageCharacterEncodingFormat());
            final List<String> filters = new ArrayList<String>();
            // if a clipping selector has been specified, add the content clipping filter
            preferences.setValue(ContentClippingFilter.SELECTOR_KEY, form.getClippingSelector());
            if (StringUtils.isNotBlank(form.getClippingSelector())) {
                filters.add("contentClippingFilter");
            }
            preferences.setValue(HeaderFooterFilter.HEADER_KEY, form.getHeader());
            preferences.setValue(HeaderFooterFilter.FOOTER_KEY, form.getFooter());
            if (StringUtils.isNotBlank(form.getHeader()) || StringUtils.isNotBlank(form.getFooter())) {
                filters.add("headerFooterFilter");
            }
            // proxied URLs
            if ("httpContentService".equals(form.getContentService())) {
                filters.add("urlRewritingFilter");
            }
            preferences.setValues(ProxyPortletController.FILTER_LIST_KEY, filters.toArray(new String[] {}));
            final List<String> preInterceptors = new ArrayList<String>();
            preInterceptors.add("userInfoUrlParameterizingPreInterceptor");
            // Authentication
            ProxyPortletForm.ProxyAuthType authType = form.getAuthType();
            switch(authType) {
                case NONE:
                    // Fair enough;  nothing to do...
                    break;
                case CAS:
                    preInterceptors.add(ProxyCASAuthenticationPreInterceptor.BEAN_ID);
                    break;
                case BASIC:
                    preInterceptors.add(UserInfoBasicAuthenticationPreInterceptor.BEAN_ID);
                    break;
                case BASIC_PORTLET_PREFERENCES:
                    preInterceptors.add(PortletPreferencesBasicAuthenticationPreInterceptor.BEAN_ID);
                    preferences.setValue(PortletPreferencesBasicAuthenticationPreInterceptor.USERNAME_PREFERENCE, form.getBasicAuthPreferencesUsername());
                    preferences.setValue(PortletPreferencesBasicAuthenticationPreInterceptor.PASSWORD_PREFERENCE, form.getBasicAuthPreferencesPassword());
                    break;
                default:
                    final String msg = "Unrecognized authentication type:  " + authType;
                    throw new IllegalArgumentException(msg);
            }
            if (!ProxyPortletForm.ProxyAuthType.BASIC_PORTLET_PREFERENCES.equals(authType)) {
                // Clear out any previous data...
                preferences.reset(PortletPreferencesBasicAuthenticationPreInterceptor.USERNAME_PREFERENCE);
                preferences.reset(PortletPreferencesBasicAuthenticationPreInterceptor.PASSWORD_PREFERENCE);
            }
            preferences.setValue(ProxyPortletForm.AUTHENTICATION_TYPE, form.getAuthType().toString());
            preferences.setValues(HttpContentServiceImpl.PREINTERCEPTOR_LIST_KEY, preInterceptors.toArray(new String[] {}));
            preferences.setValue("gsaHost", form.getGsaHost());
            preferences.setValue("gsaCollection", form.getGsaCollection());
            preferences.setValue("gsaFrontend", form.getGsaFrontend());
            preferences.setValue("gsaWhitelistRegex", form.getGsaWhitelistRegex());
            preferences.setValue("anchorWhitelistRegex", form.getAnchorWhitelistRegex());
            preferences.setValues("searchStrategies", form.getSearchStrategies());
            preferences.store();
        } catch (Exception e) {
            log.error("Unable to update web proxy portlet configuration", e);
        }
    }
    response.setPortletMode(PortletMode.VIEW);
}
Also used : ArrayList(java.util.ArrayList) PortletPreferences(javax.portlet.PortletPreferences) PortletModeException(javax.portlet.PortletModeException) ActionMapping(org.springframework.web.portlet.bind.annotation.ActionMapping)

Example 4 with PortletModeException

use of javax.portlet.PortletModeException in project gatein-portal by Meeds-io.

the class PortletRequestContext method setApplicationMode.

public void setApplicationMode(PortletMode mode) throws PortletModeException {
    if (response_ instanceof StateAwareResponse) {
        StateAwareResponse res = (StateAwareResponse) response_;
        res.setPortletMode(mode);
    } else {
        throw new PortletModeException("The portlet don't support to set a portlet mode by current runtime environment", mode);
    }
}
Also used : StateAwareResponse(javax.portlet.StateAwareResponse) PortletModeException(javax.portlet.PortletModeException)

Example 5 with PortletModeException

use of javax.portlet.PortletModeException in project liferay-faces-bridge-impl by liferay.

the class PortletURLRenderer method createBaseURL.

@Override
protected BaseURL createBaseURL(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    ExternalContext externalContext = facesContext.getExternalContext();
    javax.portlet.PortletURL portletURL = createPortletURL(externalContext, uiComponent);
    PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
    String portletModeString = getPortletMode(uiComponent);
    PortletMode portletMode;
    if (portletModeString != null) {
        portletMode = new PortletMode(portletModeString);
    } else {
        portletMode = portletRequest.getPortletMode();
    }
    try {
        portletURL.setPortletMode(portletMode);
    } catch (PortletModeException e) {
        throw new IOException(e);
    }
    String windowStateString = getWindowState(uiComponent);
    WindowState windowState;
    if (windowStateString != null) {
        windowState = new WindowState(windowStateString);
    } else {
        windowState = portletRequest.getWindowState();
    }
    try {
        portletURL.setWindowState(windowState);
    } catch (WindowStateException e) {
        throw new IOException(e);
    }
    return portletURL;
}
Also used : WindowState(javax.portlet.WindowState) WindowStateException(javax.portlet.WindowStateException) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) IOException(java.io.IOException) PortletMode(javax.portlet.PortletMode) PortletModeException(javax.portlet.PortletModeException)

Aggregations

PortletModeException (javax.portlet.PortletModeException)6 ExternalContext (javax.faces.context.ExternalContext)2 PortletMode (javax.portlet.PortletMode)2 PortletURL (javax.portlet.PortletURL)2 WindowStateException (javax.portlet.WindowStateException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 FacesContext (javax.faces.context.FacesContext)1 MimeResponse (javax.portlet.MimeResponse)1 PortletPreferences (javax.portlet.PortletPreferences)1 PortletRequest (javax.portlet.PortletRequest)1 PortletSecurityException (javax.portlet.PortletSecurityException)1 StateAwareResponse (javax.portlet.StateAwareResponse)1 WindowState (javax.portlet.WindowState)1 BridgeException (javax.portlet.faces.BridgeException)1 ActionMapping (org.springframework.web.portlet.bind.annotation.ActionMapping)1