| LayoutLister.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
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 /**
36 * <a href="LayoutLister.java.html"><b><i>View Source</i></b></a>
37 *
38 * @author Brian Wing Shun Chan
39 *
40 */
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("9");
98 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 }