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