KickJava   Java API By Example, From Geeks To Geeks.

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


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 string of spaces with the same length as the segment.
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#ReplaceWithSpaces(int begin, int end)} method.
30  */

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

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

49     public BlankOutputSegment(final Segment segment) {
50         this(segment.getBegin(),segment.getEnd());
51     }
52
53     public int getBegin() {
54         return begin;
55     }
56
57     public int getEnd() {
58         return end;
59     }
60
61     public void writeTo(final Writer writer) throws IOException {
62         for (int i=begin; i<end; i++) writer.write(' ');
63     }
64
65     public long getEstimatedMaximumOutputLength() {
66         return end-begin;
67     }
68
69     public String JavaDoc toString() {
70         StringBuffer JavaDoc sb=new StringBuffer JavaDoc(end-begin);
71         for (int i=begin; i<end; i++) sb.append(' ');
72         return sb.toString();
73     }
74
75     public String JavaDoc getDebugInfo() {
76         return "("+begin+','+end+')';
77     }
78 }
79
Popular Tags