001
014
015 package com.liferay.portlet.communities.action;
016
017 import com.liferay.portal.kernel.json.JSONArray;
018 import com.liferay.portal.kernel.json.JSONFactoryUtil;
019 import com.liferay.portal.kernel.json.JSONObject;
020 import com.liferay.portal.kernel.util.ParamUtil;
021 import com.liferay.portal.model.Layout;
022 import com.liferay.portal.service.LayoutLocalServiceUtil;
023 import com.liferay.portal.struts.JSONAction;
024
025 import java.util.List;
026
027 import javax.servlet.http.HttpServletRequest;
028 import javax.servlet.http.HttpServletResponse;
029
030 import org.apache.struts.action.ActionForm;
031 import org.apache.struts.action.ActionMapping;
032
033
036 public class GetLayoutsAction extends JSONAction {
037
038 public String getJSON(
039 ActionMapping mapping, ActionForm form, HttpServletRequest request,
040 HttpServletResponse response)
041 throws Exception {
042
043 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
044
045 List<Layout> layouts = getLayouts(request);
046
047 for (Layout layout : layouts) {
048 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
049
050 jsonObject.put("hasChildren", layout.hasChildren());
051 jsonObject.put("layoutId", layout.getLayoutId());
052 jsonObject.put("name", layout.getName());
053 jsonObject.put("parentLayoutId", layout.getParentLayoutId());
054 jsonObject.put("plid", layout.getPlid());
055 jsonObject.put("priority", layout.getPriority());
056 jsonObject.put("privateLayout", layout.getPrivateLayout());
057 jsonObject.put("type", layout.getType());
058
059 jsonArray.put(jsonObject);
060 }
061
062 return jsonArray.toString();
063 }
064
065 protected List<Layout> getLayouts(HttpServletRequest request)
066 throws Exception {
067
068 long groupId = ParamUtil.getLong(request, "groupId");
069 boolean privateLayout = ParamUtil.getBoolean(request, "privateLayout");
070 long parentLayoutId = ParamUtil.getLong(request, "parentLayoutId");
071
072 return LayoutLocalServiceUtil.getLayouts(
073 groupId, privateLayout, parentLayoutId);
074 }
075
076 }