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.portal.util;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024: import com.liferay.portal.kernel.util.StringUtil;
025: import com.liferay.portlet.PortalPreferences;
026: import com.liferay.portlet.PortletPreferencesFactoryUtil;
027:
028: import javax.servlet.http.HttpServletRequest;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032:
033: /**
034: * <a href="SessionTreeJSClicks.java.html"><b><i>View Source</i></b></a>
035: *
036: * @author Brian Wing Shun Chan
037: *
038: */
039: public class SessionTreeJSClicks {
040:
041: public static final String CLASS_NAME = SessionTreeJSClicks.class
042: .getName();
043:
044: public static void closeNode(HttpServletRequest req, String treeId,
045: String nodeId) {
046:
047: try {
048: PortalPreferences prefs = PortletPreferencesFactoryUtil
049: .getPortalPreferences(req);
050:
051: String openNodesString = prefs.getValue(CLASS_NAME, treeId);
052:
053: openNodesString = StringUtil
054: .remove(openNodesString, nodeId);
055:
056: prefs.setValue(CLASS_NAME, treeId, openNodesString);
057: } catch (Exception e) {
058: _log.error(e, e);
059: }
060: }
061:
062: public static void closeNodes(HttpServletRequest req, String treeId) {
063: try {
064: PortalPreferences prefs = PortletPreferencesFactoryUtil
065: .getPortalPreferences(req);
066:
067: String openNodesString = StringPool.BLANK;
068:
069: prefs.setValue(CLASS_NAME, treeId, openNodesString);
070: } catch (Exception e) {
071: _log.error(e, e);
072: }
073: }
074:
075: public static String getOpenNodes(HttpServletRequest req,
076: String treeId) {
077: try {
078: PortalPreferences prefs = PortletPreferencesFactoryUtil
079: .getPortalPreferences(req);
080:
081: return prefs.getValue(CLASS_NAME, treeId);
082: } catch (Exception e) {
083: _log.error(e, e);
084:
085: return null;
086: }
087: }
088:
089: public static void openNode(HttpServletRequest req, String treeId,
090: String nodeId) {
091:
092: try {
093: PortalPreferences prefs = PortletPreferencesFactoryUtil
094: .getPortalPreferences(req);
095:
096: String openNodesString = prefs.getValue(CLASS_NAME, treeId);
097:
098: openNodesString = StringUtil.add(openNodesString, nodeId);
099:
100: prefs.setValue(CLASS_NAME, treeId, openNodesString);
101: } catch (Exception e) {
102: _log.error(e, e);
103: }
104: }
105:
106: public static void openNodes(HttpServletRequest req, String treeId,
107: String[] nodeIds) {
108:
109: try {
110: PortalPreferences prefs = PortletPreferencesFactoryUtil
111: .getPortalPreferences(req);
112:
113: String openNodesString = prefs.getValue(CLASS_NAME, treeId);
114:
115: for (int i = 0; i < nodeIds.length; i++) {
116: openNodesString = StringUtil.add(openNodesString,
117: nodeIds[i]);
118: }
119:
120: prefs.setValue(CLASS_NAME, treeId, openNodesString);
121: } catch (Exception e) {
122: _log.error(e, e);
123: }
124: }
125:
126: private static Log _log = LogFactory
127: .getLog(SessionTreeJSClicks.class);
128:
129: }
|