1
14
15 package com.liferay.portal.util;
16
17 import com.liferay.portal.kernel.exception.PortalException;
18 import com.liferay.portal.kernel.exception.SystemException;
19 import com.liferay.portal.kernel.util.StringBundler;
20 import com.liferay.portal.model.Layout;
21 import com.liferay.portal.model.LayoutConstants;
22 import com.liferay.portal.service.LayoutLocalServiceUtil;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Locale;
27
28
33 public class LayoutLister {
34
35 public LayoutView getLayoutView(
36 long groupId, boolean privateLayout, String rootNodeName,
37 Locale locale)
38 throws PortalException, SystemException {
39
40 _groupId = groupId;
41 _privateLayout = privateLayout;
42 _locale = locale;
43 _nodeId = 1;
44
45 _list = new ArrayList<String>();
46
47 _list.add(
48 "1|0|0|" + LayoutConstants.DEFAULT_PLID + "|" + rootNodeName +
49 "|0");
50
51 _createList(LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, _nodeId, 0);
52
53 return new LayoutView(_list, _depth);
54 }
55
56 private void _createList(
57 long parentLayoutId, int parentId, int depth)
58 throws PortalException, SystemException {
59
60 List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(
61 _groupId, _privateLayout, parentLayoutId);
62
63 for (int i = 0; i < layouts.size(); i++) {
64 Layout layout = layouts.get(i);
65
66 if (i == 0) {
67 depth++;
68
69 if (depth > _depth) {
70 _depth = depth;
71 }
72 }
73
74 StringBundler sb = new StringBundler(13);
75
76 sb.append(++_nodeId);
77 sb.append("|");
78 sb.append(parentId);
79 sb.append("|");
80
81 if ((i + 1) == layouts.size()) {
82 sb.append("1");
83 }
84 else {
85 sb.append("0");
86 }
87
88 sb.append("|");
89 sb.append(layout.getPlid());
90 sb.append("|");
91 sb.append(layout.getName(_locale));
92 sb.append("|");
93 sb.append("11");
95 sb.append("|");
96 sb.append(depth);
97
98 _list.add(sb.toString());
99
100 _createList(layout.getLayoutId(), _nodeId, depth);
101 }
102 }
103
104 private long _groupId;
105 private boolean _privateLayout;
106 private Locale _locale;
107 private int _nodeId;
108 private List<String> _list;
109 private int _depth;
110
111 }