KickJava   Java API By Example, From Geeks To Geeks.

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


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 <code>CharSequence</code>.
27  * <p>
28  * This class has been deprecated as of version 2.2 and the functionality replaced with the
29  * {@link OutputDocument#replace(Segment, CharSequence text)} method.
30  *
31  * @deprecated Use the {@link OutputDocument#replace(Segment, CharSequence text)} method instead.
32  */

33 public final class StringOutputSegment implements OutputSegment {
34     private int begin;
35     private int end;
36     private CharSequence JavaDoc text;
37
38     /**
39      * Constructs a new <code>StringOutputSegment</code> with the specified begin and end positions and the specified content.
40      * <p>
41      * Specifying a <code>null</code> argument to the <code>text</code> parameter is exactly equivalent to specifying an empty string,
42      * and results in the segment being completely removed from the output document.
43      *
44      * @param begin the position in the <code>OutputDocument</code> where this output segment begins.
45      * @param end the position in the <code>OutputDocument</code> where this output segment ends.
46      * @param text the textual content of the new output segment, or <code>null</code> if no content.
47      */

48     public StringOutputSegment(final int begin, final int end, final CharSequence JavaDoc text) {
49         this.begin=begin;
50         this.end=end;
51         this.text=(text==null ? "" : text);
52     }
53
54     /**
55      * Constructs a new StringOutputSegment</code> with the same span as the specified {@link Segment}.
56      * <p>
57      * Specifying a <code>null</code> argument to the <code>text</code> parameter is exactly equivalent to specifying an empty string,
58      * and results in the segment being completely removed from the output document.
59      *
60      * @param segment a segment defining the beginning and ending positions of the new output segment.
61      * @param text the textual content of the new output segment, or <code>null</code> if no content.
62      */

63     public StringOutputSegment(final Segment segment, final CharSequence JavaDoc text) {
64         this(segment.begin,segment.end,text);
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         Util.appendTo(writer,text);
77     }
78
79     public long getEstimatedMaximumOutputLength() {
80         return text.length();
81     }
82
83     public String JavaDoc toString() {
84         return text.toString();
85     }
86
87     public String JavaDoc getDebugInfo() {
88         return "("+begin+','+end+"):\""+text+'"';
89     }
90
91     public void output(final Writer writer) throws IOException {
92         writeTo(writer);
93     }
94 }
95
Popular Tags