| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectau.id.jericho.lib.html.AttributesOutputSegmentOutputSegment 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, AttributesFields inherited from interface au.id.jericho.lib.html.OutputSegment | |
COMPARATOR | |
Constructor Summary | |
| |
| |
Method Summary | |
int |
|
String | |
int |
|
long | |
Map |
|
void |
|
String |
|
void | |
public AttributesOutputSegment(Attributes attributes, Map map)
Constructs a newAttributesOutputSegmentwith the same span as the specified sourceAttributes, using the specifiedMapto store the entries. This constructor might be used if theMapcontaining the new attribute values should not be preloaded with the same entries as the source attributes, or a map implementation other thanLinkedHashMapis required.
- Parameters:
attributes- theAttributesdefining the span of the newAttributesOutputSegment.map- theMapcontaining the name/value entries.
- See Also:
AttributesOutputSegment(Attributes, boolean convertNamesToLowerCase)
public AttributesOutputSegment(Attributes attributes, boolean convertNamesToLowerCase)
Constructs a newAttributesOutputSegmentwith the same span and initial name/value entries as the specified sourceAttributes. Specifying a value oftrueas an argument to theconvertNamesToLowerCaseparameter 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:is logically equivalent to calling:new AttributesOutputSegment(attributes, convertNamesToLowerCase)The use ofnew AttributesOutputSegment(attributes, attributes.populateMap(new LinkedHashMap(), convertNamesToLowerCase))LinkedHashMapto 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.
- Parameters:
attributes- theAttributesdefining the span and initial name/value entries of the newAttributesOutputSegment.convertNamesToLowerCase- specifies whether all attribute names are converted to lower case in the map.
public long getEstimatedMaximumOutputLength()
- Specified by:
- getEstimatedMaximumOutputLength in interface CharStreamSource
public Map getMap()
Returns theMapcontaining the name/value entries to be output.
- Returns:
- the
Mapcontaining the name/value entries to be output.
public void output(Writer writer)
throws IOExceptionDeprecated. Use
writeTo(Writer)instead.Outputs the contents of the map as HTML attribute name/value pairs to the specifiedWriter.
- Parameters:
writer- the destinationjava.io.Writerfor the output.
public void writeTo(Writer writer)
throws IOExceptionWrites the contents of the map as HTML attribute name/value pairs to the specifiedWriter. Each attribute is preceded by a single space, and all values are encoded and enclosed in double quotes.
- Specified by:
- writeTo in interface OutputSegment
- writeTo in interface CharStreamSource
- Parameters:
writer- the destinationjava.io.Writerfor the output.
- See Also:
Attributes.generateHTML(Map attributesMap)