|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectAttributesOutputSegment
OutputDocument.replace(Attributes, Map)
and OutputDocument.replace(Attributes, boolean convertNamesToLowerCase)
methods instead.
Implements an OutputSegment
whose content is a list of attribute name/value pairs.
This output segment is designed to replace the original Attributes
segment in the source,
providing a simple means of adding, modifying and removing attributes.
Each instance of this class contains a java.util.Map
of name/value pairs which can either be
specified directly in the constructor or initialised to the same entries as the source Attributes
specified in the constructor.
This map can be accessed via the getMap()
method, and its entries modified as required before output.
Keys in the map must be String
objects, and values must implement the CharSequence
interface.
An attribute with no value is represented by a map entry with a null
value.
Attribute values are stored unencoded in the map, and are automatically encoded if necessary during output.
The use of invalid characters in attribute names results in unspecified behaviour.
Note that methods in the Attributes
class treat attribute names as case insensitive,
whereas the Map
treats them as case sensitive.
Source source=new Source(htmlDocument); Attributes bodyAttributes =source.findNextStartTag(0,Tag.BODY).getAttributes(); AttributesOutputSegment bodyAttributesOutputSegment =new AttributesOutputSegment(bodyAttributes,true); bodyAttributesOutputSegment.getMap().put("bgcolor","green"); OutputDocument outputDocument=new OutputDocument(source); outputDocument.register(bodyAttributesOutputSegment); String htmlDocumentWithGreenBackground=outputDocument.toString();
This class has been deprecated as of version 2.2 and the functionality replaced with the
OutputDocument.replace(Attributes, Map)
and OutputDocument.replace(Attributes, boolean convertNamesToLowerCase)
methods.
OutputDocument
,
Attributes
Field Summary |
Fields inherited from interface OutputSegment |
COMPARATOR |
Constructor Summary | |
AttributesOutputSegment(Attributes attributes,
boolean convertNamesToLowerCase)
Deprecated. Constructs a new AttributesOutputSegment with the same span and initial name/value entries as the specified source Attributes . |
|
AttributesOutputSegment(Attributes attributes,
java.util.Map map)
Deprecated. Constructs a new AttributesOutputSegment with the same span
as the specified source Attributes , using the specified Map to
store the entries. |
Method Summary | |
int |
getBegin()
Deprecated. Returns the character position in the source text of the output document where this segment begins. |
java.lang.String |
getDebugInfo()
Deprecated. Returns a string representation of this object useful for debugging purposes. |
int |
getEnd()
Deprecated. Returns the character position in the source text of the output document where this segment ends. |
long |
getEstimatedMaximumOutputLength()
Deprecated. Returns the estimated maximum number of characters in the output, or -1 if no estimate is available. |
java.util.Map |
getMap()
Deprecated. Returns the Map containing the name/value entries to be output. |
void |
output(java.io.Writer writer)
Deprecated. Use writeTo(Writer) instead. |
java.lang.String |
toString()
Deprecated. Returns the content of this output segment as a String . |
void |
writeTo(java.io.Writer writer)
Deprecated. Writes the contents of the map as HTML attribute name/value pairs to the specified Writer . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public AttributesOutputSegment(Attributes attributes, boolean convertNamesToLowerCase)
AttributesOutputSegment
with the same span and initial name/value entries as the specified source Attributes
.
Specifying a value of true
as an argument to the convertNamesToLowerCase
parameter
causes all attribute names to be converted to lower case in the map.
This simplifies the process of finding/updating specific attributes since map keys are case sensitive.
Attribute values are automatically decoded before being loaded into the map.
Calling this constructor with the following code:
new AttributesOutputSegment(attributes, convertNamesToLowerCase)
new AttributesOutputSegment(attributes, attributes.populateMap(new LinkedHashMap(), convertNamesToLowerCase))
The use of LinkedHashMap
to implement the map ensures (probably unnecessarily) that
existing attributes are output in the same order as they appear in the source document, and new
attributes are output in the same order as they are added.
attributes
- the Attributes
defining the span and initial name/value entries of the new AttributesOutputSegment
.convertNamesToLowerCase
- specifies whether all attribute names are converted to lower case in the map.AttributesOutputSegment(Attributes,Map)
public AttributesOutputSegment(Attributes attributes, java.util.Map map)
AttributesOutputSegment
with the same span
as the specified source Attributes
, using the specified Map
to
store the entries.
This constructor might be used if the Map
containing the new attribute values
should not be preloaded with the same entries as the source attributes, or a map implementation
other than LinkedHashMap
is required.
attributes
- the Attributes
defining the span of the new AttributesOutputSegment
.map
- the Map
containing the name/value entries.AttributesOutputSegment(Attributes, boolean convertNamesToLowerCase)
Method Detail |
public int getBegin()
OutputSegment
getBegin
in interface OutputSegment
public int getEnd()
OutputSegment
getEnd
in interface OutputSegment
public java.util.Map getMap()
Map
containing the name/value entries to be output.
Map
containing the name/value entries to be output.public void writeTo(java.io.Writer writer) throws java.io.IOException
Writer
.
Each attribute is preceded by a single space, and all values are encoded and enclosed in double quotes.
writeTo
in interface OutputSegment
writer
- the destination java.io.Writer
for the output.
java.io.IOException
- if an I/O exception occurs.Attributes.generateHTML(Map attributesMap)
public long getEstimatedMaximumOutputLength()
CharStreamSource
-1
if no estimate is available.
The returned value should be used as a guide for efficiency purposes only, for example to set an initial StringBuffer
capacity.
There is no guarantee that the length of the output is indeed less than this value,
as classes implementing this method often use assumptions based on typical usage to calculate the estimate.
getEstimatedMaximumOutputLength
in interface CharStreamSource
-1
if no estimate is available.public java.lang.String toString()
OutputSegment
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.
toString
in interface OutputSegment
public java.lang.String getDebugInfo()
OutputSegment
getDebugInfo
in interface OutputSegment
public void output(java.io.Writer writer) throws java.io.IOException
writeTo(Writer)
instead.
Writer
.
writer
- the destination java.io.Writer
for the output.
java.io.IOException
- if an I/O exception occurs.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |