1
22
23 package com.liferay.portlet.journal.util;
24
25 import com.liferay.portal.kernel.util.StringPool;
26 import com.liferay.portal.util.PortalUtil;
27
28 import java.util.ArrayList;
29 import java.util.LinkedHashMap;
30 import java.util.List;
31 import java.util.Map;
32
33
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 String layoutLink = getData();
96 String layoutId = layoutLink;
97
98 int pos = layoutId.indexOf(StringPool.AT);
99
100 if (pos != -1) {
101 layoutId = layoutId.substring(0, pos);
102 }
103
104 StringBuilder sb = new StringBuilder();
105
106 if (layoutLink.endsWith("@public")) {
107 sb.append(PortalUtil.getPathFriendlyURLPublic());
108 }
109 else if (layoutLink.endsWith("@private-group")) {
110 sb.append(PortalUtil.getPathFriendlyURLPrivateGroup());
111 }
112 else if (layoutLink.endsWith("@private-user")) {
113 sb.append(PortalUtil.getPathFriendlyURLPrivateUser());
114 }
115 else {
116 sb.append("@friendly_url_current@");
117 }
118
119 sb.append(StringPool.SLASH);
120 sb.append("@group_id@");
121 sb.append(StringPool.SLASH);
122 sb.append(layoutId);
123
124 return sb.toString();
125 }
126 else {
127 return StringPool.BLANK;
128 }
129 }
130
131 private Map<String, TemplateNode> _children =
132 new LinkedHashMap<String, TemplateNode>();
133
134 }