1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.action;
16  
17  import com.liferay.portal.kernel.util.Constants;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.kernel.util.StringUtil;
20  import com.liferay.portal.util.PortalUtil;
21  import com.liferay.portal.util.SessionTreeJSClicks;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.http.HttpServletResponse;
25  
26  import org.apache.struts.action.Action;
27  import org.apache.struts.action.ActionForm;
28  import org.apache.struts.action.ActionForward;
29  import org.apache.struts.action.ActionMapping;
30  
31  /**
32   * <a href="SessionTreeJSClickAction.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class SessionTreeJSClickAction extends Action {
37  
38      public ActionForward execute(
39              ActionMapping mapping, ActionForm form, HttpServletRequest request,
40              HttpServletResponse response)
41          throws Exception {
42  
43          try {
44              String cmd = ParamUtil.getString(request, Constants.CMD);
45  
46              String treeId = ParamUtil.getString(request, "treeId");
47  
48              if (cmd.equals("expand")) {
49                  String[] nodeIds = StringUtil.split(
50                      ParamUtil.getString(request, "nodeIds"));
51  
52                  SessionTreeJSClicks.openNodes(request, treeId, nodeIds);
53              }
54              else if (cmd.equals("collapse")) {
55                  SessionTreeJSClicks.closeNodes(request, treeId);
56              }
57              else {
58                  String nodeId = ParamUtil.getString(request, "nodeId");
59                  boolean openNode = ParamUtil.getBoolean(request, "openNode");
60  
61                  if (openNode) {
62                      SessionTreeJSClicks.openNode(request, treeId, nodeId);
63                  }
64                  else {
65                      SessionTreeJSClicks.closeNode(request, treeId, nodeId);
66                  }
67              }
68  
69              return null;
70          }
71          catch (Exception e) {
72              PortalUtil.sendError(e, request, response);
73  
74              return null;
75          }
76      }
77  
78  }