KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > au > id > jericho > lib > html > CharOutputSegment


1 // Jericho HTML Parser - Java based library for analysing and manipulating HTML
2
// Version 2.2
3
// Copyright (C) 2006 Martin Jericho
4
// http://sourceforge.net/projects/jerichohtml/
5
//
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 2.1 of the License, or (at your option) any later version.
10
// http://www.gnu.org/copyleft/lesser.html
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20

21 package au.id.jericho.lib.html;
22
23 import java.io.*;
24
25 /**
26  * Implements an {@link OutputSegment} whose content is a single character constant.
27  * <p>
28  * This class has been removed from the public API as of version 2.2 and the functionality replaced with the
29  * {@link OutputDocument#Replace(int begin, int end, char ch)} method.
30  */

31 final class CharOutputSegment implements OutputSegment {
32     private int begin;
33     private int end;
34     private char ch;
35
36     /**
37      * Constructs a new <code>CharOutputSegment</code> with the specified begin and end character positions and the specified content.
38      * @param begin the position in the {@link OutputDocument} where this <code>OutputSegment</code> begins.
39      * @param end the position in the {@link OutputDocument} where this <code>OutputSegment</code> ends.
40      * @param ch the character output of the new <code>OutputSegment</code>.
41      */

42     public CharOutputSegment(final int begin, final int end, final char ch) {
43         this.begin=begin;
44         this.end=end;
45         this.ch=ch;
46     }
47
48     /**
49      * Constructs a new <code>CharOutputSegment</code> with the same span as the specified {@link Segment}.
50      * @param segment a {@link Segment} defining the begin and end character positions of the new <code>OutputSegment</code>.
51      * @param ch the character output of the new <code>OutputSegment</code>.
52      */

53     public CharOutputSegment(final Segment segment, final char ch) {
54         begin=segment.begin;
55         end=segment.end;
56         this.ch=ch;
57     }
58
59     /**
60      * Constructs a new <code>CharOutputSegment</code> which converts the specified {@link CharacterReference} to a normal character.
61      * @param characterReference the character reference to convert.
62      */

63     public CharOutputSegment(final CharacterReference characterReference) {
64         this(characterReference,characterReference.getChar());
65     }
66
67     public int getBegin() {
68         return begin;
69     }
70
71     public int getEnd() {
72         return end;
73     }
74
75     public void writeTo(final Writer writer) throws IOException {
76         writer.write(ch);
77     }
78
79     public long getEstimatedMaximumOutputLength() {
80         return 1;
81     }
82
83     public String JavaDoc toString() {
84         return Character.toString(ch);
85     }
86
87     public String JavaDoc getDebugInfo() {
88         return "("+begin+','+end+"):"+ch;
89     }
90 }
91
Popular Tags