1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.journal.util;
21  
22  import com.liferay.portal.kernel.util.StringPool;
23  
24  import java.util.ArrayList;
25  import java.util.LinkedHashMap;
26  import java.util.List;
27  import java.util.Map;
28  
29  /**
30   * <a href="TemplateNode.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Alexander Chow
33   * @author Raymond Augé
34   *
35   */
36  public class TemplateNode extends LinkedHashMap<String, Object> {
37  
38      public TemplateNode(String name, String data, String type) {
39          super();
40  
41          put("name", name);
42          put("data", data);
43          put("type", type);
44          put("options", new ArrayList<String>());
45      }
46  
47      public void appendChild(TemplateNode child) {
48          _children.put(child.getName(), child);
49          put(child.getName(), child);
50      }
51  
52      public void appendChildren(List<TemplateNode> children) {
53          for (TemplateNode child : children) {
54              appendChild(child);
55          }
56      }
57  
58      public void appendOption(String option) {
59          getOptions().add(option);
60      }
61  
62      public void appendOptions(List<String> options) {
63          getOptions().addAll(options);
64      }
65  
66      public TemplateNode getChild(String name) {
67          return _children.get(name);
68      }
69  
70      public List<TemplateNode> getChildren() {
71          return new ArrayList<TemplateNode>(_children.values());
72      }
73  
74      public String getData() {
75          return (String)get("data");
76      }
77  
78      public String getName() {
79          return (String)get("name");
80      }
81  
82      public List<String> getOptions() {
83          return (List<String>)get("options");
84      }
85  
86      public String getType() {
87          return (String)get("type");
88      }
89  
90      public String getUrl() {
91          if (getType().equals("link_to_layout")) {
92              StringBuilder sb = new StringBuilder();
93  
94              sb.append("@friendly_url_current@");
95              sb.append(StringPool.SLASH);
96              sb.append("@group_id@");
97              sb.append(StringPool.SLASH);
98              sb.append(getData());
99  
100             return sb.toString();
101         }
102         else {
103             return StringPool.BLANK;
104         }
105     }
106 
107     private Map<String, TemplateNode> _children =
108         new LinkedHashMap<String, TemplateNode>();
109 
110 }