001    /**
002     * Copyright (c) 2000-2012 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            @Override
037            public ActionForward execute(
038                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
039                            HttpServletResponse response)
040                    throws Exception {
041    
042                    try {
043                            String cmd = ParamUtil.getString(request, Constants.CMD);
044    
045                            String treeId = ParamUtil.getString(request, "treeId");
046    
047                            if (cmd.equals("collapse")) {
048                                    SessionTreeJSClicks.closeNodes(request, treeId);
049                            }
050                            else if (cmd.equals("expand")) {
051                                    String[] nodeIds = StringUtil.split(
052                                            ParamUtil.getString(request, "nodeIds"));
053    
054                                    SessionTreeJSClicks.openNodes(request, treeId, nodeIds);
055                            }
056                            else if (cmd.equals("layoutCheck")) {
057                            }
058                            else if (cmd.equals("layoutCollpase")) {
059                            }
060                            else if (cmd.equals("layoutUncheck")) {
061                            }
062                            else if (cmd.equals("layoutUncollpase")) {
063                            }
064                            else {
065                                    String nodeId = ParamUtil.getString(request, "nodeId");
066                                    boolean openNode = ParamUtil.getBoolean(request, "openNode");
067    
068                                    if (openNode) {
069                                            SessionTreeJSClicks.openNode(request, treeId, nodeId);
070                                    }
071                                    else {
072                                            SessionTreeJSClicks.closeNode(request, treeId, nodeId);
073                                    }
074                            }
075    
076                            return null;
077                    }
078                    catch (Exception e) {
079                            PortalUtil.sendError(e, request, response);
080    
081                            return null;
082                    }
083            }
084    
085    }