Example usage for com.liferay.portal.kernel.util InheritableMap InheritableMap

List of usage examples for com.liferay.portal.kernel.util InheritableMap InheritableMap

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util InheritableMap InheritableMap.

Prototype

public InheritableMap() 

Source Link

Usage

From source file:com.liferay.asset.publisher.web.portlet.DisplayPageFriendlyURLResolver.java

License:Open Source License

@Override
public String getActualURL(long companyId, long groupId, boolean privateLayout, String mainPath,
        String friendlyURL, Map<String, String[]> params, Map<String, Object> requestContext)
        throws PortalException {

    String urlTitle = friendlyURL.substring(JournalArticleConstants.CANONICAL_URL_SEPARATOR.length());

    JournalArticle journalArticle = _journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);

    Layout layout = getJournalArticleLayout(groupId, privateLayout, friendlyURL);

    String layoutActualURL = _portal.getLayoutActualURL(layout, mainPath);

    InheritableMap<String, String[]> actualParams = new InheritableMap<>();

    if (params != null) {
        actualParams.setParentMap(params);
    }/*w  ww.  j  av  a2  s  . c o m*/

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String defaultAssetPublisherPortletId = typeSettingsProperties
            .get(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);

    String currentDefaultAssetPublisherPortletId = defaultAssetPublisherPortletId;

    if (Validator.isNull(defaultAssetPublisherPortletId)) {
        defaultAssetPublisherPortletId = PortletIdCodec.encode(AssetPublisherPortletKeys.ASSET_PUBLISHER);
    }

    HttpServletRequest request = (HttpServletRequest) requestContext.get("request");

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
        String actualPortletAuthenticationToken = AuthTokenUtil.getToken(request, layout.getPlid(),
                defaultAssetPublisherPortletId);

        actualParams.put("p_p_auth", new String[] { actualPortletAuthenticationToken });
    }

    actualParams.put("p_p_id", new String[] { defaultAssetPublisherPortletId });
    actualParams.put("p_p_lifecycle", new String[] { "0" });

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
        actualParams.put("p_p_state", new String[] { WindowState.MAXIMIZED.toString() });
    }

    actualParams.put("p_p_mode", new String[] { "view" });
    actualParams.put("p_j_a_id", new String[] { String.valueOf(journalArticle.getId()) });

    String namespace = _portal.getPortletNamespace(defaultAssetPublisherPortletId);

    actualParams.put(namespace + "mvcPath", new String[] { "/view_content.jsp" });

    AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
            .getAssetRendererFactoryByClassName(JournalArticle.class.getName());

    actualParams.put(namespace + "type", new String[] { assetRendererFactory.getType() });

    actualParams.put(namespace + "urlTitle", new String[] { journalArticle.getUrlTitle() });

    String queryString = _http.parameterMapToString(actualParams, false);

    if (layoutActualURL.contains(StringPool.QUESTION)) {
        layoutActualURL = layoutActualURL + StringPool.AMPERSAND + queryString;
    } else {
        layoutActualURL = layoutActualURL + StringPool.QUESTION + queryString;
    }

    Locale locale = _portal.getLocale(request);

    _portal.addPageSubtitle(journalArticle.getTitle(locale), request);
    _portal.addPageDescription(journalArticle.getDescription(locale), request);

    List<AssetTag> assetTags = _assetTagLocalService.getTags(JournalArticle.class.getName(),
            journalArticle.getPrimaryKey());

    if (!assetTags.isEmpty()) {
        _portal.addPageKeywords(ListUtil.toString(assetTags, AssetTag.NAME_ACCESSOR), request);
    }

    return layoutActualURL;
}

From source file:com.liferay.portlet.RouteImpl.java

License:Open Source License

public String parametersToUrl(Map<String, String> parameters) {
    InheritableMap<String, String> allParameters = new InheritableMap<String, String>();

    allParameters.setParentMap(parameters);

    // The order is important because virtual parameters may sometimes be
    // checked by implicit parameters

    for (Map.Entry<String, StringParser> entry : _generatedParameters.entrySet()) {

        String name = entry.getKey();
        StringParser stringParser = entry.getValue();

        String value = MapUtil.getString(allParameters, name);

        if (!stringParser.parse(value, allParameters)) {
            return null;
        }// w  w w . ja v  a  2  s .c o  m
    }

    for (Map.Entry<String, String> entry : _implicitParameters.entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue();

        if (!value.equals(MapUtil.getString(allParameters, name))) {
            return null;
        }
    }

    String url = _stringParser.build(allParameters);

    if (Validator.isNull(url)) {
        return null;
    }

    for (String name : _generatedParameters.keySet()) {

        // Virtual parameters will never be placed in the query string,
        // so parameters is modified directly instead of allParameters

        parameters.remove(name);
    }

    for (String name : _implicitParameters.keySet()) {
        parameters.remove(name);
    }

    for (String name : _ignoredParameters) {
        parameters.remove(name);
    }

    return url;
}