001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet;
022:
023: import com.liferay.portal.util.WebKeys;
024: import com.liferay.util.CollectionFactory;
025:
026: import java.util.HashMap;
027: import java.util.Map;
028:
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.http.HttpSession;
031:
032: /**
033: * <a href="RenderParametersPool.java.html"><b><i>View Source</i></b></a>
034: *
035: * @author Brian Wing Shun Chan
036: *
037: */
038: public class RenderParametersPool {
039:
040: public static void clear(HttpServletRequest req, long plid) {
041: Map plidPool = get(req, plid);
042:
043: plidPool.clear();
044: }
045:
046: public static void clear(HttpServletRequest req, long plid,
047: String portletId) {
048:
049: Map params = get(req, plid, portletId);
050:
051: params.clear();
052: }
053:
054: public static Map get(HttpServletRequest req, long plid) {
055: HttpSession ses = req.getSession();
056:
057: if (plid <= 0) {
058: return CollectionFactory.getHashMap();
059: }
060:
061: String key = RenderParametersPool.class.getName() + plid;
062:
063: Map pool = (Map) _getRenderParametersPool(ses);
064:
065: Map plidPool = (Map) pool.get(key);
066:
067: if (plidPool == null) {
068: plidPool = CollectionFactory.getHashMap();
069:
070: pool.put(key, plidPool);
071: }
072:
073: return plidPool;
074: }
075:
076: public static Map get(HttpServletRequest req, long plid,
077: String portletId) {
078: Map plidPool = get(req, plid);
079:
080: Map params = (Map) plidPool.get(portletId);
081:
082: if (params == null) {
083: params = new HashMap();
084:
085: plidPool.put(portletId, params);
086: }
087:
088: return params;
089: }
090:
091: public static void put(HttpServletRequest req, long plid,
092: String portletId, Map params) {
093:
094: Map plidPool = get(req, plid);
095:
096: plidPool.put(portletId, params);
097: }
098:
099: private static Map _getRenderParametersPool(HttpSession ses) {
100: Map renderParametersPool = (Map) ses
101: .getAttribute(WebKeys.PORTLET_RENDER_PARAMETERS);
102:
103: if (renderParametersPool == null) {
104: renderParametersPool = CollectionFactory.getHashMap();
105:
106: ses.setAttribute(WebKeys.PORTLET_RENDER_PARAMETERS,
107: renderParametersPool);
108: }
109:
110: return renderParametersPool;
111: }
112:
113: }
|