Example usage for com.liferay.portal.kernel.util MapUtil copy

List of usage examples for com.liferay.portal.kernel.util MapUtil copy

Introduction

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

Prototype

public static <K, V> void copy(Map<? extends K, ? extends V> master, Map<? super K, ? super V> copy) 

Source Link

Usage

From source file:com.liferay.marketplace.store.web.internal.portlet.RemoteMVCPortlet.java

License:Open Source License

protected void setRequestParameters(PortletRequest portletRequest, PortletResponse portletResponse,
        OAuthRequest oAuthRequest) {/*  w  w  w.j  ava  2s .co  m*/

    setBaseRequestParameters(portletRequest, portletResponse, oAuthRequest);

    Map<String, String[]> parameterMap = new HashMap<>();

    MapUtil.copy(portletRequest.getParameterMap(), parameterMap);

    processPortletParameterMap(portletRequest, portletResponse, parameterMap);

    String serverNamespace = getServerNamespace();

    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
        String key = entry.getKey();
        String[] values = entry.getValue();

        if (key.equals("remoteWindowState")) {
            key = "p_p_state";
        } else {
            key = serverNamespace.concat(key);
        }

        if (ArrayUtil.isEmpty(values) || Validator.isNull(values[0])) {
            continue;
        }

        addOAuthParameter(oAuthRequest, key, values[0]);
    }
}

From source file:com.liferay.portlet.journal.util.PropertiesTransformerListener.java

License:Open Source License

/**
 * Replace the properties in a given string with their values fetched from
 * the template GLOBAL-PROPERTIES./*from   w  w w  .jav a2  s  . co m*/
 *
 * @return the processed string
 */
protected String replace(String s) {
    Map<String, String> tokens = getTokens();

    String templateId = tokens.get("template_id");

    if ((templateId == null) || ((templateId != null) && (templateId.equals(_GLOBAL_PROPERTIES)))) {

        // Return the original string if no template ID is specified or if
        // the template ID is GLOBAL-PROPERTIES to prevent an infinite loop.

        return s;
    }

    Properties properties = new Properties();

    try {
        Map<String, String> newTokens = new HashMap<String, String>();

        MapUtil.copy(tokens, newTokens);

        newTokens.put("template_id", _GLOBAL_PROPERTIES);

        long groupId = GetterUtil.getLong(tokens.get("group_id"));

        String script = JournalUtil.getTemplateScript(groupId, _GLOBAL_PROPERTIES, newTokens, getLanguageId());

        PropertiesUtil.load(properties, script);
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e);
        }
    }

    if (properties.isEmpty()) {
        return s;
    }

    String[] escapedKeys = new String[properties.size()];
    String[] escapedValues = new String[properties.size()];

    String[] keys = new String[properties.size()];
    String[] values = new String[properties.size()];

    String[] tempEscapedKeys = new String[properties.size()];
    String[] tempEscapedValues = new String[properties.size()];

    int counter = 0;

    Iterator<Map.Entry<Object, Object>> itr = properties.entrySet().iterator();

    while (itr.hasNext()) {
        Map.Entry<Object, Object> entry = itr.next();

        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        String escapedKey = StringPool.AT + StringPool.AT + key + StringPool.AT + StringPool.AT;

        String actualKey = StringPool.AT + key + StringPool.AT;

        String tempEscapedKey = TokensTransformerListener.TEMP_ESCAPED_AT_OPEN + key
                + TokensTransformerListener.TEMP_ESCAPED_AT_CLOSE;

        escapedKeys[counter] = escapedKey;
        escapedValues[counter] = tempEscapedKey;

        keys[counter] = actualKey;
        values[counter] = value;

        tempEscapedKeys[counter] = tempEscapedKey;
        tempEscapedValues[counter] = actualKey;

        counter++;
    }

    s = StringUtil.replace(s, escapedKeys, escapedValues);

    s = StringUtil.replace(s, keys, values);

    s = StringUtil.replace(s, tempEscapedKeys, tempEscapedValues);

    return s;
}