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