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

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

Introduction

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

Prototype

public java.util.List<Layout> getChildren();

Source Link

Document

Returns all child layouts of the current layout, independent of user access permissions.

Usage

From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java

License:Open Source License

protected boolean populateLayoutsJSON(JSONArray layoutsJSONArray, Layout layout, long[] selectedLayoutIds) {

    List<Layout> childLayouts = layout.getChildren();
    JSONArray childLayoutsJSONArray = null;
    boolean includeChildren = true;

    if (ListUtil.isNotEmpty(childLayouts)) {
        childLayoutsJSONArray = JSONFactoryUtil.createJSONArray();

        for (Layout childLayout : childLayouts) {
            if (!populateLayoutsJSON(childLayoutsJSONArray, childLayout, selectedLayoutIds)) {

                includeChildren = false;
            }//  w w w .  jav  a 2 s. c  o m
        }
    }

    boolean checked = ArrayUtil.contains(selectedLayoutIds, layout.getLayoutId());

    if (checked) {
        JSONObject layoutJSONObject = JSONFactoryUtil.createJSONObject();

        layoutJSONObject.put("includeChildren", includeChildren);
        layoutJSONObject.put("plid", layout.getPlid());

        layoutsJSONArray.put(layoutJSONObject);
    }

    if (checked && includeChildren) {
        return true;
    }

    if (childLayoutsJSONArray != null) {

        // We want a 1 level array and not an array of arrays

        for (int i = 0; i < childLayoutsJSONArray.length(); i++) {
            layoutsJSONArray.put(childLayoutsJSONArray.getJSONObject(i));
        }
    }

    return false;
}

From source file:com.liferay.site.navigation.site.map.web.internal.display.context.SiteNavigationSiteMapDisplayContext.java

License:Open Source License

private void _buildSiteMap(Layout layout, List<Layout> layouts, Layout rootLayout, boolean includeRootInTree,
        int displayDepth, boolean showCurrentPage, boolean useHtmlTitle, boolean showHiddenPages, int curDepth,
        ThemeDisplay themeDisplay, StringBundler sb) throws Exception {

    if (layouts.isEmpty()) {
        return;//from w w w  .jav a2 s  .c o m
    }

    if ((rootLayout != null) && !LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), rootLayout,
            ActionKeys.VIEW)) {

        return;
    }

    sb.append("<ul>");

    if (includeRootInTree && (rootLayout != null) && (curDepth == 1)) {
        sb.append("<li>");

        String cssClass = "root";

        if (rootLayout.getPlid() == layout.getPlid()) {
            cssClass += " current";
        }

        _buildLayoutView(rootLayout, cssClass, useHtmlTitle, themeDisplay, sb);

        _buildSiteMap(layout, layouts, rootLayout, includeRootInTree, displayDepth, showCurrentPage,
                useHtmlTitle, showHiddenPages, curDepth + 1, themeDisplay, sb);

        sb.append("</li>");
    } else {
        for (Layout curLayout : layouts) {
            if ((showHiddenPages || !curLayout.isHidden()) && LayoutPermissionUtil
                    .contains(themeDisplay.getPermissionChecker(), curLayout, ActionKeys.VIEW)) {

                sb.append("<li>");

                String cssClass = StringPool.BLANK;

                if (curLayout.getPlid() == layout.getPlid()) {
                    cssClass = "current";
                }

                _buildLayoutView(curLayout, cssClass, useHtmlTitle, themeDisplay, sb);

                if ((displayDepth == 0) || (displayDepth > curDepth)) {
                    if (showHiddenPages) {
                        _buildSiteMap(layout, curLayout.getChildren(), rootLayout, includeRootInTree,
                                displayDepth, showCurrentPage, useHtmlTitle, showHiddenPages, curDepth + 1,
                                themeDisplay, sb);
                    } else {
                        _buildSiteMap(layout, curLayout.getChildren(themeDisplay.getPermissionChecker()),
                                rootLayout, includeRootInTree, displayDepth, showCurrentPage, useHtmlTitle,
                                showHiddenPages, curDepth + 1, themeDisplay, sb);
                    }
                }

                sb.append("</li>");
            }
        }
    }

    sb.append("</ul>");
}