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.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 void appendSibling(TemplateNode sibling) {
70          _siblings.add(sibling);
71      }
72  
73      public TemplateNode getChild(String name) {
74          return _children.get(name);
75      }
76  
77      public List<TemplateNode> getChildren() {
78          return new ArrayList<TemplateNode>(_children.values());
79      }
80  
81      public String getData() {
82          return (String)get("data");
83      }
84  
85      public String getName() {
86          return (String)get("name");
87      }
88  
89      public List<String> getOptions() {
90          return (List<String>)get("options");
91      }
92  
93      public List<TemplateNode> getSiblings() {
94          return _siblings;
95      }
96  
97      public String getType() {
98          return (String)get("type");
99      }
100 
101     public String getUrl() {
102         if (getType().equals("link_to_layout")) {
103             StringBuilder sb = new StringBuilder();
104 
105             sb.append("@friendly_url_current@");
106             sb.append(StringPool.SLASH);
107             sb.append("@group_id@");
108             sb.append(StringPool.SLASH);
109             sb.append(getData());
110 
111             return sb.toString();
112         }
113         else {
114             return StringPool.BLANK;
115         }
116     }
117 
118     private Map<String, TemplateNode> _children =
119         new LinkedHashMap<String, TemplateNode>();
120     private List<TemplateNode> _siblings = new ArrayList<TemplateNode>();
121 
122 }