| TemplateNode.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.portlet.journal.util;
24
25 import com.liferay.portal.kernel.util.StringPool;
26
27 import java.util.ArrayList;
28 import java.util.LinkedHashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 /**
33 * <a href="TemplateNode.java.html"><b><i>View Source</i></b></a>
34 *
35 * @author Alexander Chow
36 * @author Raymond Augé
37 *
38 */
39 public class TemplateNode extends LinkedHashMap<String, Object> {
40
41 public TemplateNode(String name, String data, String type) {
42 super();
43
44 put("name", name);
45 put("data", data);
46 put("type", type);
47 put("options", new ArrayList<String>());
48 }
49
50 public void appendChild(TemplateNode child) {
51 _children.put(child.getName(), child);
52 put(child.getName(), child);
53 }
54
55 public void appendChildren(List<TemplateNode> children) {
56 for (TemplateNode child : children) {
57 appendChild(child);
58 }
59 }
60
61 public void appendOption(String option) {
62 getOptions().add(option);
63 }
64
65 public void appendOptions(List<String> options) {
66 getOptions().addAll(options);
67 }
68
69 public TemplateNode getChild(String name) {
70 return _children.get(name);
71 }
72
73 public List<TemplateNode> getChildren() {
74 return new ArrayList<TemplateNode>(_children.values());
75 }
76
77 public String getData() {
78 return (String)get("data");
79 }
80
81 public String getName() {
82 return (String)get("name");
83 }
84
85 public List<String> getOptions() {
86 return (List<String>)get("options");
87 }
88
89 public String getType() {
90 return (String)get("type");
91 }
92
93 public String getUrl() {
94 if (getType().equals("link_to_layout")) {
95 StringBuilder sb = new StringBuilder();
96
97 sb.append("@friendly_url_current@");
98 sb.append(StringPool.SLASH);
99 sb.append("@group_id@");
100 sb.append(StringPool.SLASH);
101 sb.append(getData());
102
103 return sb.toString();
104 }
105 else {
106 return StringPool.BLANK;
107 }
108 }
109
110 private Map<String, TemplateNode> _children =
111 new LinkedHashMap<String, TemplateNode>();
112
113 }