au.id.jericho.lib.html
Interface OutputSegment
- CharStreamSource
- AttributesOutputSegment, StringOutputSegment
public interface OutputSegment
Defines the interface for an output segment, which is used in an
OutputDocument
to
replace segments of the source document with other text.
All text in the
OutputDocument
between the character positions defined by
getBegin()
and
getEnd()
is replaced by the content of this output segment.
If the begin and end character positions are the same, the content is simply
inserted at this position without replacing any text.
COMPARATOR
public static final Comparator COMPARATOR
The comparator used to sort output segments in the
OutputDocument
before output.
The following rules are applied in order compare two output segments:
- The output segment that begins earlier in the document comes first.
- If both output segments begin at the same position, the one that has zero-length comes first.
- If both output segments are zero-length, neither is guaranteed to come before the other.
- If neither segment is zero-length, the result is undefined as the segments are overlapping.
Note that this condition is detected at a later stage, so this comparator returns normally without throwing a
OverlappingOutputSegmentsException
.
Note: this comparator has a natural ordering that may be inconsistent with the
equals
method of classes implementing this interface.
This means that the comparator may treat two output segments as equal where calling the
equals(Object)
method with the same two output segments returns
false
.
getBegin
public int getBegin()
getDebugInfo
public String getDebugInfo()
Returns a string representation of this object useful for debugging purposes.
- a string representation of this object useful for debugging purposes.
getEnd
public int getEnd()
toString
public String toString()
Returns the content of this output segment as a
String
.
Note that before version 2.0 this returned a representation of this object useful for debugging purposes,
which can now be obtained via the
getDebugInfo()
method.
- the content of this output segment as a
String
, guaranteed not null
.
writeTo
public void writeTo(Writer writer)
throws IOException
Writes the content of this output segment to the specified Writer
.
- writeTo in interface CharStreamSource
writer
- the destination java.io.Writer
for the output.