1
14
15 package com.liferay.portlet.journal.util;
16
17 import com.liferay.portal.kernel.util.StringBundler;
18 import com.liferay.portal.kernel.util.StringPool;
19 import com.liferay.portal.util.PortalUtil;
20
21 import java.util.ArrayList;
22 import java.util.LinkedHashMap;
23 import java.util.List;
24 import java.util.Map;
25
26
32 public class TemplateNode extends LinkedHashMap<String, Object> {
33
34 public TemplateNode(String name, String data, String type) {
35 super();
36
37 put("name", name);
38 put("data", data);
39 put("type", type);
40 put("options", new ArrayList<String>());
41 }
42
43 public void appendChild(TemplateNode child) {
44 _children.put(child.getName(), child);
45 put(child.getName(), child);
46 }
47
48 public void appendChildren(List<TemplateNode> children) {
49 for (TemplateNode child : children) {
50 appendChild(child);
51 }
52 }
53
54 public void appendOption(String option) {
55 getOptions().add(option);
56 }
57
58 public void appendOptions(List<String> options) {
59 getOptions().addAll(options);
60 }
61
62 public TemplateNode getChild(String name) {
63 return _children.get(name);
64 }
65
66 public List<TemplateNode> getChildren() {
67 return new ArrayList<TemplateNode>(_children.values());
68 }
69
70 public String getData() {
71 return (String)get("data");
72 }
73
74 public String getName() {
75 return (String)get("name");
76 }
77
78 public List<String> getOptions() {
79 return (List<String>)get("options");
80 }
81
82 public String getType() {
83 return (String)get("type");
84 }
85
86 public String getUrl() {
87 if (getType().equals("link_to_layout")) {
88 String layoutLink = getData();
89 String layoutId = layoutLink;
90
91 int pos = layoutId.indexOf(StringPool.AT);
92
93 if (pos != -1) {
94 layoutId = layoutId.substring(0, pos);
95 }
96
97 StringBundler sb = new StringBundler(5);
98
99 if (layoutLink.endsWith("@public")) {
100 sb.append(PortalUtil.getPathFriendlyURLPublic());
101 }
102 else if (layoutLink.endsWith("@private-group")) {
103 sb.append(PortalUtil.getPathFriendlyURLPrivateGroup());
104 }
105 else if (layoutLink.endsWith("@private-user")) {
106 sb.append(PortalUtil.getPathFriendlyURLPrivateUser());
107 }
108 else {
109 sb.append("@friendly_url_current@");
110 }
111
112 sb.append(StringPool.SLASH);
113 sb.append("@group_id@");
114 sb.append(StringPool.SLASH);
115 sb.append(layoutId);
116
117 return sb.toString();
118 }
119 else {
120 return StringPool.BLANK;
121 }
122 }
123
124 private Map<String, TemplateNode> _children =
125 new LinkedHashMap<String, TemplateNode>();
126
127 }