| LayoutLister.java |
1 /**
2 * Copyright (c) 2000-2008 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.kernel.util.StringMaker;
28 import com.liferay.portal.model.Layout;
29 import com.liferay.portal.model.impl.LayoutImpl;
30 import com.liferay.portal.service.LayoutLocalServiceUtil;
31
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Locale;
35
36 /**
37 * <a href="LayoutLister.java.html"><b><i>View Source</i></b></a>
38 *
39 * @author Brian Wing Shun Chan
40 *
41 */
42 public class LayoutLister {
43
44 public LayoutView getLayoutView(
45 long groupId, boolean privateLayout, String rootNodeName,
46 Locale locale)
47 throws PortalException, SystemException {
48
49 _groupId = groupId;
50 _privateLayout = privateLayout;
51 _locale = locale;
52 _nodeId = 1;
53
54 _list = new ArrayList<String>();
55
56 _list.add(
57 "1|0|0|" + LayoutImpl.DEFAULT_PLID + "|" + rootNodeName + "|0");
58
59 _createList(LayoutImpl.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 StringMaker sm = new StringMaker();
83
84 sm.append(++_nodeId).append("|");
85 sm.append(parentId).append("|");
86
87 if ((i + 1) == layouts.size()) {
88 sm.append("1");
89 }
90 else {
91 sm.append("0");
92 }
93
94 sm.append("|");
95 sm.append(layout.getPlid()).append("|");
96 sm.append(layout.getName(_locale)).append("|");
97 //sm.append("9");
98 sm.append("11");
99 sm.append("|");
100 sm.append(depth);
101
102 _list.add(sm.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 }