com.liferay.portlet.RenderParametersPool Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portlet;
import com.liferay.portal.kernel.servlet.PortalSessionContext;
import com.liferay.portal.kernel.util.WebKeys;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @author Brian Wing Shun Chan
*/
public class RenderParametersPool {
public static Map> clear(
HttpServletRequest httpServletRequest, long plid) {
if (plid <= 0) {
return null;
}
Map>> pool =
_getRenderParametersPool(httpServletRequest, false);
if (pool == null) {
return null;
}
return pool.remove(plid);
}
public static Map clear(
HttpServletRequest httpServletRequest, long plid, String portletId) {
Map> plidPool = get(
httpServletRequest, plid);
if (plidPool == null) {
return null;
}
return plidPool.remove(portletId);
}
public static Map> get(
HttpServletRequest httpServletRequest, long plid) {
if (plid <= 0) {
return null;
}
Map>> pool =
_getRenderParametersPool(httpServletRequest, false);
if (pool == null) {
return null;
}
return pool.get(plid);
}
public static Map get(
HttpServletRequest httpServletRequest, long plid, String portletId) {
Map> plidPool = get(
httpServletRequest, plid);
if (plidPool == null) {
return null;
}
return plidPool.get(portletId);
}
public static Map> getOrCreate(
HttpServletRequest httpServletRequest, long plid) {
if (plid <= 0) {
return new ConcurrentHashMap<>();
}
Map>> pool =
_getRenderParametersPool(httpServletRequest, true);
return pool.computeIfAbsent(plid, key -> new ConcurrentHashMap<>());
}
public static Map getOrCreate(
HttpServletRequest httpServletRequest, long plid, String portletId) {
Map> plidPool = getOrCreate(
httpServletRequest, plid);
return plidPool.computeIfAbsent(portletId, key -> new HashMap<>());
}
public static void put(
HttpServletRequest httpServletRequest, long plid, String portletId,
Map params) {
if (params.isEmpty()) {
return;
}
Map> plidPool = getOrCreate(
httpServletRequest, plid);
plidPool.put(portletId, params);
}
private static Map>>
_getRenderParametersPool(
HttpServletRequest httpServletRequest, boolean createIfAbsent) {
HttpSession httpSession = httpServletRequest.getSession();
HttpSession portalHttpSession = PortalSessionContext.get(
httpSession.getId());
if (portalHttpSession != null) {
httpSession = portalHttpSession;
}
Map>> renderParametersPool =
(Map>>)
httpSession.getAttribute(WebKeys.PORTLET_RENDER_PARAMETERS);
if (createIfAbsent && (renderParametersPool == null)) {
renderParametersPool = new ConcurrentHashMap<>();
httpSession.setAttribute(
WebKeys.PORTLET_RENDER_PARAMETERS, renderParametersPool);
}
return renderParametersPool;
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy