1 | /* |
2 | * Copyright (c) 2009 The JOMC Project |
3 | * Copyright (c) 2005 Christian Schulte <cs@jomc.org> |
4 | * All rights reserved. |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
9 | * |
10 | * o Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * |
13 | * o Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in |
15 | * the documentation and/or other materials provided with the |
16 | * distribution. |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS" |
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR |
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | * |
30 | * $Id: Section.java 891 2009-11-02 03:40:00Z schulte2005 $ |
31 | * |
32 | */ |
33 | package org.jomc.util; |
34 | |
35 | import java.util.ArrayList; |
36 | import java.util.List; |
37 | |
38 | /** |
39 | * Section of text. |
40 | * |
41 | * @author <a href="mailto:cs@jomc.org">Christian Schulte</a> |
42 | * @version $Id: Section.java 891 2009-11-02 03:40:00Z schulte2005 $ |
43 | */ |
44 | public class Section |
45 | { |
46 | |
47 | /** Constant for the mode during parsing the head content of a section. */ |
48 | static final int MODE_HEAD = 1; |
49 | |
50 | /** Constant for the mode during parsing the tail content of a section. */ |
51 | static final int MODE_TAIL = 2; |
52 | |
53 | /** The current parsing mode. */ |
54 | private int mode = MODE_HEAD; |
55 | |
56 | /** The name of this section. */ |
57 | private String name; |
58 | |
59 | /** The parsed head content of this section. */ |
60 | private StringBuilder headContent; |
61 | |
62 | /** The parsed tail content of this section. */ |
63 | private StringBuilder tailContent; |
64 | |
65 | /** Line marking the start of this section. */ |
66 | private String startingLine; |
67 | |
68 | /** Line marking the end of this section. */ |
69 | private String endingLine; |
70 | |
71 | /** The child sections of this section. */ |
72 | private List<Section> sections; |
73 | |
74 | /** Creates a new {@code Section} instance. */ |
75 | public Section() |
76 | { |
77 | super(); |
78 | } |
79 | |
80 | /** |
81 | * Gets the name of this section. |
82 | * |
83 | * @return The name of this section or {@code null}. |
84 | */ |
85 | public String getName() |
86 | { |
87 | return this.name; |
88 | } |
89 | |
90 | /** |
91 | * Sets the name of this section. |
92 | * |
93 | * @param value The new name of this section or {@code null}. |
94 | */ |
95 | public void setName( final String value ) |
96 | { |
97 | this.name = value; |
98 | } |
99 | |
100 | /** |
101 | * Gets the line marking the start of this section. |
102 | * |
103 | * @return The line marking the start of this section. |
104 | */ |
105 | public String getStartingLine() |
106 | { |
107 | return this.startingLine; |
108 | } |
109 | |
110 | /** |
111 | * Sets the line marking the start of this section. |
112 | * |
113 | * @param value The new line marking the start of this section. |
114 | */ |
115 | public void setStartingLine( final String value ) |
116 | { |
117 | this.startingLine = value; |
118 | } |
119 | |
120 | /** |
121 | * Gets the line marking the end of this section. |
122 | * |
123 | * @return The line marking the end of this section. |
124 | */ |
125 | public String getEndingLine() |
126 | { |
127 | return this.endingLine; |
128 | } |
129 | |
130 | /** |
131 | * Sets the line marking the end of this section. |
132 | * |
133 | * @param value The new line marking the end of this section. |
134 | */ |
135 | public void setEndingLine( final String value ) |
136 | { |
137 | this.endingLine = value; |
138 | } |
139 | |
140 | /** |
141 | * Gets the content of this section preceding any child section content. |
142 | * |
143 | * @return The content of this section preceding any child section content. |
144 | */ |
145 | public StringBuilder getHeadContent() |
146 | { |
147 | if ( this.headContent == null ) |
148 | { |
149 | this.headContent = new StringBuilder(); |
150 | } |
151 | |
152 | return this.headContent; |
153 | } |
154 | |
155 | /** |
156 | * Gets the content of this section succeeding any child section content. |
157 | * |
158 | * @return The content of this section succeeding any child section content. |
159 | */ |
160 | public StringBuilder getTailContent() |
161 | { |
162 | if ( this.tailContent == null ) |
163 | { |
164 | this.tailContent = new StringBuilder(); |
165 | } |
166 | |
167 | return this.tailContent; |
168 | } |
169 | |
170 | /** |
171 | * Gets the child sections of this section. |
172 | * |
173 | * @return A list of child sections of this section. |
174 | */ |
175 | public List<Section> getSections() |
176 | { |
177 | if ( this.sections == null ) |
178 | { |
179 | this.sections = new ArrayList<Section>(); |
180 | } |
181 | |
182 | return this.sections; |
183 | } |
184 | |
185 | /** |
186 | * Gets the parsing mode of the instance. |
187 | * |
188 | * @return The parsing mode of the instance. |
189 | * |
190 | * @see #MODE_HEAD |
191 | * @see #MODE_TAIL |
192 | */ |
193 | int getMode() |
194 | { |
195 | return this.mode; |
196 | } |
197 | |
198 | /** |
199 | * Sets the parsing mode of the instance. |
200 | * |
201 | * @param value The new parsing mode of the instance. |
202 | * |
203 | * @see #MODE_HEAD |
204 | * @see #MODE_TAIL |
205 | */ |
206 | void setMode( final int value ) |
207 | { |
208 | this.mode = value; |
209 | } |
210 | |
211 | } |