View Javadoc

1   /*
2    * Copyright 2007 Hippo
3    *
4    * Licensed under the Apache License, Version 2.0 (the  "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" 
12   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  package nl.hippo.portal.cms;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  
22  public class CMSMetaDataItemImpl implements CMSMetaDataItem {
23  
24      private final String id;
25      private final Map attributes;
26      private final String value;
27      private List children = new ArrayList();
28      private CMSMetaDataItem parent;
29      private int nestingLevel;
30  
31      public CMSMetaDataItemImpl(String id, String value, Map attributes) {
32          this.id = id;
33          this.attributes = attributes;
34          this.value = value;
35          nestingLevel = 0;
36      }
37  
38      public String getAttribute(String key) {
39          return (String) attributes.get(key);
40      }
41  
42      public Map getAttributes() {
43          return attributes;
44      }
45  
46      public List getChildren() {
47          return children;
48      }
49      
50      public void addChild(CMSMetaDataItemImpl child) {
51          children.add(child);
52          child.setNestingLevel(nestingLevel + 1);
53          child.setParent(this);
54      }
55      
56      public String getId() {
57          return id;
58      }
59  
60      public CMSMetaDataItem getParent() {
61          return parent;
62      }
63  
64      public void setParent(CMSMetaDataItem parent) {
65          this.parent = parent;
66      }
67      
68      public String getValue() {
69          return value;
70      }
71  
72      public boolean hasChildren() {
73          return !children.isEmpty();
74      }
75  
76      public String toString() {
77          return "id="+id + ", value="+value+", nrOfChildren="+children.size();
78      }
79      
80      public int getNestingLevel() {
81          return nestingLevel;
82      }
83      
84      private void setNestingLevel(int nestingLevel) {
85          this.nestingLevel = nestingLevel;
86      }
87  
88  }