Methods Summary |
---|
public void | handleComment(char[] text, int position)
try {
out.write("<!-- ");
out.write(text);
out.write(" -->");
out.flush();
}
catch (IOException e) {
System.err.println(e);
}
|
public void | handleEndTag(javax.swing.text.html.HTML$Tag tag, int position)
try {
out.write("</" + tag + ">");
if (tag.breaksFlow()) out.write("\r\n");
out.flush();
}
catch (IOException e) {
System.err.println(e);
}
|
public void | handleSimpleTag(javax.swing.text.html.HTML$Tag tag, javax.swing.text.MutableAttributeSet attributes, int position)
try {
out.write("<" + tag);
this.writeAttributes(tag, attributes);
out.write(">");
}
catch (IOException e) {
System.err.println(e);
e.printStackTrace();
}
|
public void | handleStartTag(javax.swing.text.html.HTML$Tag tag, javax.swing.text.MutableAttributeSet attributes, int position)
try {
out.write("<" + tag);
this.writeAttributes(tag, attributes);
out.write(">");
out.flush();
}
catch (IOException e) {
System.err.println(e);
e.printStackTrace();
}
|
public void | handleText(char[] text, int position)
try {
out.write(text);
out.flush();
}
catch (IOException e) {
System.err.println(e);
e.printStackTrace();
}
|
public static void | main(java.lang.String[] args)
for (int i = 0; i < args.length; i++) {
// The ParserGetter class is from Chapter 8
ParserGetter kit = new ParserGetter();
HTMLEditorKit.Parser parser = kit.getParser();
try {
URL u = new URL(args[0]);
InputStream in = u.openStream();
InputStreamReader r = new InputStreamReader(in);
HTMLEditorKit.ParserCallback callback
= new ImageSizer(new OutputStreamWriter(System.out), u);
parser.parse(r, callback, false);
}
catch (IOException e) {
System.err.println(e);
e.printStackTrace();
}
}
|
private void | writeAttributes(javax.swing.text.html.HTML$Tag tag, javax.swing.text.AttributeSet attributes)
Enumeration e = attributes.getAttributeNames();
while (e.hasMoreElements()) {
Object name = e.nextElement();
String value = (String) attributes.getAttribute(name);
out.write(" " + name + "=\"" + value + "\"");
}
// for the IMG tag we may have to add HEIGHT and WIDTH attributes
if (tag == HTML.Tag.IMG) {
try {
if (attributes.getAttribute(HTML.Attribute.HEIGHT) == null
|| attributes.getAttribute(HTML.Attribute.WIDTH) == null) {
URL u = new URL(base, (String) attributes.getAttribute(HTML.Attribute.SRC));
Image img = Toolkit.getDefaultToolkit().getImage(u);
Component temp = new Label();
MediaTracker tracker = new MediaTracker(temp);
tracker.addImage(img, 1);
try {
tracker.waitForID(1);
if (attributes.getAttribute(HTML.Attribute.WIDTH) == null) {
out.write(" WIDTH=\"" + img.getWidth(temp) + "\"");
}
if (attributes.getAttribute(HTML.Attribute.HEIGHT) == null) {
out.write(" HEIGHT=\"" + img.getHeight(temp) + "\"");
}
}
catch (InterruptedException ex) {
}
}
}
catch (MalformedURLException ex) {
// SRC attribute is malformed
}
}
|