Example usage for com.liferay.portal.kernel.model Layout hasChildren

List of usage examples for com.liferay.portal.kernel.model Layout hasChildren

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Layout hasChildren.

Prototype

public boolean hasChildren();

Source Link

Document

Returns true if the current layout has child layouts.

Usage

From source file:com.liferay.layout.internal.util.LayoutsTreeImpl.java

License:Open Source License

private JSONObject _toJSONObject(HttpServletRequest request, long groupId, LayoutTreeNodes layoutTreeNodes,
        LayoutSetBranch layoutSetBranch) throws Exception {

    if (_log.isDebugEnabled()) {
        StringBundler sb = new StringBundler(5);

        sb.append("_toJSON(groupId=");
        sb.append(groupId);/*from w w  w . ja va 2s.  c  om*/
        sb.append(", layoutTreeNodes=");
        sb.append(layoutTreeNodes);
        sb.append(StringPool.CLOSE_PARENTHESIS);

        _log.debug(sb.toString());
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    boolean hasManageLayoutsPermission = GroupPermissionUtil.contains(themeDisplay.getPermissionChecker(),
            groupId, ActionKeys.MANAGE_LAYOUTS);
    boolean mobile = BrowserSnifferUtil.isMobile(request);

    for (LayoutTreeNode layoutTreeNode : layoutTreeNodes) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        JSONObject childrenJSONObject = _toJSONObject(request, groupId,
                layoutTreeNode.getChildLayoutTreeNodes(), layoutSetBranch);

        jsonObject.put("children", childrenJSONObject);

        Layout layout = layoutTreeNode.getLayout();

        jsonObject.put("contentDisplayPage", layout.isContentDisplayPage());
        jsonObject.put("deleteable", _isDeleteable(layout, themeDisplay, layoutSetBranch));
        jsonObject.put("friendlyURL", layout.getFriendlyURL());

        if (layout instanceof VirtualLayout) {
            VirtualLayout virtualLayout = (VirtualLayout) layout;

            jsonObject.put("groupId", virtualLayout.getSourceGroupId());
        } else {
            jsonObject.put("groupId", layout.getGroupId());
        }

        jsonObject.put("hasChildren", layout.hasChildren());
        jsonObject.put("layoutId", layout.getLayoutId());
        jsonObject.put("name", layout.getName(themeDisplay.getLocale()));
        jsonObject.put("parentable", LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout,
                ActionKeys.ADD_LAYOUT));
        jsonObject.put("parentLayoutId", layout.getParentLayoutId());
        jsonObject.put("plid", layout.getPlid());
        jsonObject.put("priority", layout.getPriority());
        jsonObject.put("privateLayout", layout.isPrivateLayout());
        jsonObject.put("regularURL", layout.getRegularURL(request));
        jsonObject.put("sortable", hasManageLayoutsPermission && !mobile && SitesUtil.isLayoutSortable(layout));
        jsonObject.put("type", layout.getType());
        jsonObject.put("updateable",
                LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout, ActionKeys.UPDATE));
        jsonObject.put("uuid", layout.getUuid());

        LayoutRevision layoutRevision = LayoutStagingUtil.getLayoutRevision(layout);

        if (layoutRevision != null) {
            long layoutSetBranchId = layoutRevision.getLayoutSetBranchId();

            if (_staging.isIncomplete(layout, layoutSetBranchId)) {
                jsonObject.put("incomplete", true);
            }

            LayoutSetBranch boundLayoutSetBranch = _layoutSetBranchLocalService
                    .getLayoutSetBranch(layoutSetBranchId);

            LayoutBranch layoutBranch = layoutRevision.getLayoutBranch();

            if (!layoutBranch.isMaster()) {
                jsonObject.put("layoutBranchId", layoutBranch.getLayoutBranchId());
                jsonObject.put("layoutBranchName", layoutBranch.getName());
            }

            if (layoutRevision.isHead()) {
                jsonObject.put("layoutRevisionHead", true);
            }

            jsonObject.put("layoutRevisionId", layoutRevision.getLayoutRevisionId());
            jsonObject.put("layoutSetBranchId", layoutSetBranchId);
            jsonObject.put("layoutSetBranchName", boundLayoutSetBranch.getName());
        }

        jsonArray.put(jsonObject);
    }

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject();

    responseJSONObject.put("layouts", jsonArray);
    responseJSONObject.put("total", layoutTreeNodes.getTotal());

    return responseJSONObject;
}