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