View Javadoc

1   package org.apache.maven.doxia.module.confluence.parser.list;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  import java.util.ArrayList;
24  
25  /**
26   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
27   * @version $Id: TreeComponent.java 1090706 2011-04-09 23:15:28Z hboutemy $
28   */
29  class TreeComponent
30  {
31      private static final String EOL = System.getProperty( "line.separator" );
32  
33      private List<TreeComponent> children = new ArrayList<TreeComponent>();
34  
35      private String text;
36  
37      private TreeComponent father;
38  
39      private int type;
40  
41      TreeComponent( TreeComponent father, String text, int type )
42      {
43          this.text = text;
44          this.father = father;
45          this.type = type;
46      }
47  
48      List<TreeComponent> getChildren()
49      {
50          return children;
51      }
52  
53      TreeComponent addChildren( String t, int ttype )
54      {
55          if ( t == null )
56          {
57              throw new IllegalArgumentException( "argument is null" );
58          }
59  
60          TreeComponent ret = new TreeComponent( this, t, ttype );
61  
62          children.add( ret );
63  
64          return ret;
65      }
66  
67      TreeComponent getFather()
68      {
69          return father;
70      }
71  
72      int getDepth()
73      {
74          int ret = 0;
75  
76          TreeComponent c = this;
77  
78          while ( ( c = c.getFather() ) != null )
79          {
80              ret++;
81          }
82  
83          return ret;
84      }
85  
86      /** {@inheritDoc} */
87      public String toString()
88      {
89          return toString( "" );
90      }
91  
92      String toString( String indent )
93      {
94          StringBuffer sb = new StringBuffer();
95  
96          if ( father != null )
97          {
98              sb.append( indent );
99              sb.append( "- " );
100             sb.append( text );
101             sb.append( EOL );
102         }
103 
104         for ( TreeComponent lc : children )
105         {
106             sb.append( lc.toString( indent + "   " ) );
107         }
108 
109         return sb.toString();
110     }
111 
112     String getText()
113     {
114         return text;
115     }
116 
117     int getType()
118     {
119         return type;
120     }
121 }