001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.action;
016    
017    import com.liferay.portal.kernel.util.Constants;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.util.PortalUtil;
021    import com.liferay.portal.util.SessionTreeJSClicks;
022    
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.http.HttpServletResponse;
025    
026    import org.apache.struts.action.Action;
027    import org.apache.struts.action.ActionForm;
028    import org.apache.struts.action.ActionForward;
029    import org.apache.struts.action.ActionMapping;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class SessionTreeJSClickAction extends Action {
035    
036            public ActionForward execute(
037                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
038                            HttpServletResponse response)
039                    throws Exception {
040    
041                    try {
042                            String cmd = ParamUtil.getString(request, Constants.CMD);
043    
044                            String treeId = ParamUtil.getString(request, "treeId");
045    
046                            if (cmd.equals("expand")) {
047                                    String[] nodeIds = StringUtil.split(
048                                            ParamUtil.getString(request, "nodeIds"));
049    
050                                    SessionTreeJSClicks.openNodes(request, treeId, nodeIds);
051                            }
052                            else if (cmd.equals("collapse")) {
053                                    SessionTreeJSClicks.closeNodes(request, treeId);
054                            }
055                            else {
056                                    String nodeId = ParamUtil.getString(request, "nodeId");
057                                    boolean openNode = ParamUtil.getBoolean(request, "openNode");
058    
059                                    if (openNode) {
060                                            SessionTreeJSClicks.openNode(request, treeId, nodeId);
061                                    }
062                                    else {
063                                            SessionTreeJSClicks.closeNode(request, treeId, nodeId);
064                                    }
065                            }
066    
067                            return null;
068                    }
069                    catch (Exception e) {
070                            PortalUtil.sendError(e, request, response);
071    
072                            return null;
073                    }
074            }
075    
076    }