001    /*
002     *   Copyright (c) 2009 The JOMC Project
003     *   Copyright (c) 2005 Christian Schulte <cs@jomc.org>
004     *   All rights reserved.
005     *
006     *   Redistribution and use in source and binary forms, with or without
007     *   modification, are permitted provided that the following conditions
008     *   are met:
009     *
010     *     o Redistributions of source code must retain the above copyright
011     *       notice, this list of conditions and the following disclaimer.
012     *
013     *     o Redistributions in binary form must reproduce the above copyright
014     *       notice, this list of conditions and the following disclaimer in
015     *       the documentation and/or other materials provided with the
016     *       distribution.
017     *
018     *   THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS"
019     *   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020     *   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021     *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR
022     *   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023     *   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024     *   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025     *   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026     *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
027     *   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
028     *   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029     *
030     *   $Id: Section.java 891 2009-11-02 03:40:00Z schulte2005 $
031     *
032     */
033    package org.jomc.util;
034    
035    import java.util.ArrayList;
036    import java.util.List;
037    
038    /**
039     * Section of text.
040     *
041     * @author <a href="mailto:cs@jomc.org">Christian Schulte</a>
042     * @version $Id: Section.java 891 2009-11-02 03:40:00Z schulte2005 $
043     */
044    public class Section
045    {
046    
047        /** Constant for the mode during parsing the head content of a section. */
048        static final int MODE_HEAD = 1;
049    
050        /** Constant for the mode during parsing the tail content of a section. */
051        static final int MODE_TAIL = 2;
052    
053        /** The current parsing mode. */
054        private int mode = MODE_HEAD;
055    
056        /** The name of this section. */
057        private String name;
058    
059        /** The parsed head content of this section. */
060        private StringBuilder headContent;
061    
062        /** The parsed tail content of this section. */
063        private StringBuilder tailContent;
064    
065        /** Line marking the start of this section. */
066        private String startingLine;
067    
068        /** Line marking the end of this section. */
069        private String endingLine;
070    
071        /** The child sections of this section. */
072        private List<Section> sections;
073    
074        /** Creates a new {@code Section} instance. */
075        public Section()
076        {
077            super();
078        }
079    
080        /**
081         * Gets the name of this section.
082         *
083         * @return The name of this section or {@code null}.
084         */
085        public String getName()
086        {
087            return this.name;
088        }
089    
090        /**
091         * Sets the name of this section.
092         *
093         * @param value The new name of this section or {@code null}.
094         */
095        public void setName( final String value )
096        {
097            this.name = value;
098        }
099    
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    }