1 21 package au.id.jericho.lib.html; 22 23 import java.util.*; 24 import java.io.*; 25 26 68 public class AttributesOutputSegment implements OutputSegment { 69 private int begin; 70 private int end; 71 private Map map; 72 73 96 public AttributesOutputSegment(final Attributes attributes, final boolean convertNamesToLowerCase) { 97 this(attributes,attributes.getMap(convertNamesToLowerCase)); 98 } 99 100 113 public AttributesOutputSegment(final Attributes attributes, final Map map) { 114 if (map==null || attributes==null) throw new IllegalArgumentException ("both arguments must be non-null"); 115 begin=attributes.getBegin(); 116 end=attributes.getEnd(); 117 this.map=map; 118 } 119 120 public int getBegin() { 121 return begin; 122 } 123 124 public int getEnd() { 125 return end; 126 } 127 128 132 public Map getMap() { 133 return map; 134 } 135 136 146 public void writeTo(final Writer writer) throws IOException { 147 Attributes.appendHTML(writer,map); 148 } 149 150 public long getEstimatedMaximumOutputLength() { 151 return (end-begin)*2; 152 } 153 154 public String toString() { 155 return Attributes.generateHTML(map); 156 } 157 158 public String getDebugInfo() { 159 StringWriter stringWriter=new StringWriter(); 160 stringWriter.getBuffer().append('(').append(begin).append(',').append(end).append("):"); 161 try {output(stringWriter);} catch (IOException ex) {} return stringWriter.toString(); 163 } 164 165 172 public void output(final Writer writer) throws IOException { 173 writeTo(writer); 174 } 175 } 176 | Popular Tags |