Example usage for com.liferay.portal.kernel.model Portlet isAddDefaultResource

List of usage examples for com.liferay.portal.kernel.model Portlet isAddDefaultResource

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Portlet isAddDefaultResource.

Prototype

public boolean isAddDefaultResource();

Source Link

Document

Returns true if default resources for the portlet are added to a page.

Usage

From source file:com.liferay.faces.bridge.ext.filter.internal.LiferayURLGeneratorBaseImpl.java

License:Open Source License

public String generateURL(Map<String, String[]> additionalParameterMap, String cacheability,
        PortletMode portletMode, String resourceId, WindowState windowState) {

    String toStringValue;/*from  ww  w .j  a  v  a  2  s. co  m*/

    if (baseURL.contains(Portal.FRIENDLY_URL_SEPARATOR)) {
        toStringValue = baseURL;
    } else {

        StringBuilder url = new StringBuilder();

        // Build up a new URL string based on the one returned by Liferay, but discard everything after the
        // question mark because it's filled with all kinds of unnecessary stuff.
        url.append(prefix);

        // Possibly add the p_auth parameter.
        boolean firstParameter = true;

        String portalAuthToken = StringHelper.toString(additionalParameterMap.get(P_AUTH),
                parameterMap.get(P_AUTH));

        if (portalAuthToken != null) {

            appendParameterToURL(firstParameter, P_AUTH, portalAuthToken, url);
            firstParameter = false;
        }

        // Possibly add the p_l_id parameter.
        String plid = StringHelper.toString(additionalParameterMap.get(P_L_ID), parameterMap.get(P_L_ID));

        if (plid != null) {

            appendParameterToURL(firstParameter, P_L_ID, plid, url);
            firstParameter = false;
        }

        // Possibly add the p_p_auth parameter.
        String portletAuthToken = StringHelper.toString(additionalParameterMap.get(P_P_AUTH),
                parameterMap.get(P_P_AUTH));

        if (portletAuthToken != null) {

            boolean addPortletAuthToken = true;

            if ((LIFERAY_BUILD_NUMBER < 6102)
                    || ((LIFERAY_BUILD_NUMBER > 6102) && (LIFERAY_BUILD_NUMBER < 6130))) {

                // Versions of Liferay Portal prior to 6.1.2-CE/6.1.30-EE suffered from LPS-36481 which caused
                // PortletURLImpl.addPortletAuthToken(StringBundle, Key) method to add the p_p_auth parameter to
                // URLs for portlets when add-default-resource=false. It is therefore necessary to check that
                // add-default-resource=true before adding the p_p_auth parameter to the URL.
                FacesContext facesContext = FacesContext.getCurrentInstance();
                PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
                String portletId = (String) portletRequest.getAttribute(WebKeys.PORTLET_ID);
                ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

                try {
                    Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(),
                            portletId);
                    addPortletAuthToken = portlet.isAddDefaultResource();
                } catch (SystemException e) {
                    logger.error(e);
                }
            }

            if (addPortletAuthToken) {
                appendParameterToURL(firstParameter, P_P_AUTH, portletAuthToken, url);
                firstParameter = false;
            }
        }

        // Always add the p_p_id parameter
        String parameterValue = StringHelper.toString(additionalParameterMap.get(P_P_ID), responseNamespace);

        if (parameterValue.startsWith("_")) {
            parameterValue = parameterValue.substring(1);
        }

        if (parameterValue.endsWith("_")) {
            parameterValue = parameterValue.substring(0, parameterValue.length() - 1);
        }

        appendParameterToURL(firstParameter, P_P_ID, parameterValue, url);

        firstParameter = false;

        // Always add the p_p_lifecycle parameter.
        String portletLifecycleId = getPortletLifecycleId();
        appendParameterToURL(P_P_LIFECYCLE, portletLifecycleId, url);

        // Add the p_p_state parameter.
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();

        WindowState urlWindowState = initialWindowState;

        if (additionalParameterMap.get(P_P_STATE) != null) {
            urlWindowState = new WindowState(additionalParameterMap.get(P_P_STATE)[0]);
        }

        if (windowState != null) {
            urlWindowState = windowState;
        }

        if (urlWindowState == null) {
            parameterValue = (String) applicationMap.get(responseNamespace + P_P_STATE);
        } else {
            parameterValue = urlWindowState.toString();
        }

        appendParameterToURL(P_P_STATE, parameterValue, url);

        // Possibly add the p_p_state_rcv parameter.
        String stateRestoreCurrentView = StringHelper.toString(additionalParameterMap.get(P_P_STATE_RCV),
                parameterMap.get(P_P_STATE_RCV));

        if (stateRestoreCurrentView != null) {
            appendParameterToURL(P_P_STATE_RCV, stateRestoreCurrentView, url);
        }

        // Add the p_p_mode parameter.
        PortletMode urlPortletMode = initialPortletMode;

        if (additionalParameterMap.get(P_P_MODE) != null) {
            urlPortletMode = new PortletMode(additionalParameterMap.get(P_P_MODE)[0]);
        }

        if (portletMode != null) {
            urlPortletMode = portletMode;
        }

        if (urlPortletMode == null) {
            parameterValue = (String) applicationMap.get(responseNamespace + P_P_MODE);
        } else {
            parameterValue = urlPortletMode.toString();
        }

        appendParameterToURL(P_P_MODE, parameterValue, url);

        // Possibly add the p_p_cacheability parameter
        if (LIFECYCLE_RESOURCE_PHASE_ID.equals(portletLifecycleId)) {

            String urlCacheability = null;

            if (cacheability != null) {
                urlCacheability = cacheability;
            }

            if (urlCacheability == null) {
                urlCacheability = StringHelper.toString(additionalParameterMap.get(P_P_CACHEABILITY),
                        parameterMap.get(P_P_CACHEABILITY));
            }

            if (urlCacheability != null) {
                appendParameterToURL(P_P_CACHEABILITY, urlCacheability, url);
            }
        }

        // Always add the p_p_col_id parameter
        parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_ID);
        appendParameterToURL(P_P_COL_ID, parameterValue, url);

        // Possibly add the p_p_col_count parameter.
        parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_COUNT);
        appendParameterToURL(P_P_COL_COUNT, parameterValue, url);

        // Add the p_p_col_pos parameter if it is greater than zero (same logic as Liferay's
        // PortletURLImpl.toString())
        parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_POS);

        if ((parameterValue != null) && (parameterValue.length() > 0)) {

            try {
                int colPos = Integer.parseInt(parameterValue);

                if (colPos > 0) {
                    appendParameterToURL(P_P_COL_POS, parameterValue, url);
                }
            } catch (NumberFormatException e) {
                // ignore
            }
        }

        // Possibly add the p_o_p_id parameter.
        String outerPortletId = StringHelper.toString(additionalParameterMap.get(P_O_P_ID),
                parameterMap.get(P_O_P_ID));

        if (outerPortletId != null) {
            appendParameterToURL(P_O_P_ID, outerPortletId, url);
        }

        // Possibly add the doAsUserId parameter.
        String doAsUserId = StringHelper.toString(additionalParameterMap.get(DO_AS_USER_ID),
                parameterMap.get(DO_AS_USER_ID));

        if (doAsUserId != null) {
            appendParameterToURL(DO_AS_USER_ID, doAsUserId, url);
        }

        // Possibly add the doAsUserLanguageId parameter.
        String doAsUserLanguageId = StringHelper.toString(additionalParameterMap.get(DO_AS_USER_LANGUAGE_ID),
                parameterMap.get(DO_AS_USER_LANGUAGE_ID));

        if (doAsUserLanguageId != null) {
            appendParameterToURL(DO_AS_USER_LANGUAGE_ID, doAsUserLanguageId, url);
        }

        // Possibly add the doAsGroupId parameter.
        String doAsGroupId = StringHelper.toString(additionalParameterMap.get(DO_AS_GROUP_ID),
                parameterMap.get(DO_AS_GROUP_ID));

        if (doAsGroupId != null) {
            appendParameterToURL(DO_AS_GROUP_ID, doAsGroupId, url);
        }

        // Possibly add the refererGroupId parameter.
        String refererGroupId = StringHelper.toString(additionalParameterMap.get(REFERER_GROUP_ID),
                parameterMap.get(REFERER_GROUP_ID));

        if (refererGroupId != null) {
            appendParameterToURL(REFERER_GROUP_ID, refererGroupId, url);
        }

        // Possibly add the refererPlid parameter.
        String refererPlid = StringHelper.toString(additionalParameterMap.get(REFERER_PLID),
                parameterMap.get(REFERER_PLID));

        if (refererPlid != null) {
            appendParameterToURL(REFERER_PLID, refererPlid, url);
        }

        // Possibly add the controlPanelCategory parameter.
        String controlPanelCategory = StringHelper.toString(additionalParameterMap.get(CONTROL_PANEL_CATEGORY),
                parameterMap.get(CONTROL_PANEL_CATEGORY));

        if (controlPanelCategory != null) {
            appendParameterToURL(CONTROL_PANEL_CATEGORY, controlPanelCategory, url);
        }

        // Add request parameters from the request parameter map.
        boolean namespaced = !responseNamespace.startsWith("wsrp");

        Set<Map.Entry<String, String[]>> mapEntries = additionalParameterMap.entrySet();

        if (mapEntries != null) {

            for (Map.Entry<String, String[]> mapEntry : mapEntries) {
                String[] parameterValues = mapEntry.getValue();

                if (parameterValues != null) {

                    String parameterName = mapEntry.getKey();

                    if (!LIFERAY_NON_NAMESPACED_PARAMS.contains(parameterName)) {

                        for (String curParameterValue : parameterValues) {

                            if (curParameterValue != null) {

                                String encodedParameterValue = encode(curParameterValue);
                                appendParameterToURL(firstParameter, namespaced, parameterName,
                                        encodedParameterValue, url);
                            }
                        }
                    }
                }
            }
        }

        // Add WSRP URL parameters
        for (LiferayURLParameter wsrpParameter : wsrpParameters) {

            appendParameterToURL(wsrpParameter.getName(), wsrpParameter.getValue(), url);
        }

        // Possibly add the p_p_resource_id parameter.
        String urlResourceId = parameterMap.get(P_O_P_ID);

        if (resourceId != null) {
            urlResourceId = resourceId;
        }

        if (urlResourceId == null) {

            if (prefix.startsWith("wsrp")) {
                appendParameterToURL(P_P_RESOURCE_ID, "wsrp", url);
            }
        } else {
            appendParameterToURL(P_P_RESOURCE_ID, urlResourceId, url);
        }

        // Possibly add a Portlet URL Anchor
        if (portletURLAnchor != null) {
            url.append(portletURLAnchor);
        }

        toStringValue = url.toString();
    }

    return toStringValue;
}