edu.northwestern.at.utils.swing.html
Class HTMLStripper

java.lang.Object
  extended by javax.swing.text.html.HTMLEditorKit.ParserCallback
      extended by edu.northwestern.at.utils.swing.html.HTMLStripper

public class HTMLStripper
extends javax.swing.text.html.HTMLEditorKit.ParserCallback

Strips HTML tags.

Tags which cause line breaks such as <br>, <p>, etc. when the HTML is displayed are converted to user-specified line separator characters.


Field Summary
 
Fields inherited from class javax.swing.text.html.HTMLEditorKit.ParserCallback
IMPLIED
 
Constructor Summary
HTMLStripper(java.io.Writer out)
          Create HTML stripper using default end of line separator.
HTMLStripper(java.io.Writer out, java.lang.String lineSeparator)
          Create stripper using default end of line separator.
 
Method Summary
 void handleEndTag(javax.swing.text.html.HTML.Tag tag, int position)
          Handles an end tag (<br>, <p>, etc.)
 void handleSimpleTag(javax.swing.text.html.HTML.Tag tag, javax.swing.text.MutableAttributeSet attributes, int position)
          Handles simple tags.
 void handleText(char[] text, int position)
          Handles ordinary text in HTML input.
 
Methods inherited from class javax.swing.text.html.HTMLEditorKit.ParserCallback
flush, handleComment, handleEndOfLineString, handleError, handleStartTag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLStripper

public HTMLStripper(java.io.Writer out)
Create HTML stripper using default end of line separator.

Parameters:
out - Writer to which stripped text will be written.

HTMLStripper

public HTMLStripper(java.io.Writer out,
                    java.lang.String lineSeparator)
Create stripper using default end of line separator.

Parameters:
out - Writer to which stripped text will be written.
lineSeparator - Characters to separate lines.
Method Detail

handleText

public void handleText(char[] text,
                       int position)
Handles ordinary text in HTML input.

Overrides:
handleText in class javax.swing.text.html.HTMLEditorKit.ParserCallback
Parameters:
text - The text.
position - Position of the text in the file (not used here).

This is plain text, so it is written as it stands to the output.


handleEndTag

public void handleEndTag(javax.swing.text.html.HTML.Tag tag,
                         int position)
Handles an end tag (<br>, <p>, etc.)

Overrides:
handleEndTag in class javax.swing.text.html.HTMLEditorKit.ParserCallback
Parameters:
tag - The end tag.
position - Position of the tag in the file (not used here).

For a block type tag (e.g., <p>) two sets of line separator characters are written. For a text break tag (e.g., <br>) a single set of line separator characters is written.


handleSimpleTag

public void handleSimpleTag(javax.swing.text.html.HTML.Tag tag,
                            javax.swing.text.MutableAttributeSet attributes,
                            int position)
Handles simple tags.

Overrides:
handleSimpleTag in class javax.swing.text.html.HTMLEditorKit.ParserCallback
Parameters:
tag - The simple tag.
attributes - Tag attributes.
position - Position of the tag in the file (not used here).

For a block type tag (e.g., <p>) two sets of line separator characters are written. For a text break tag (e.g., <br>) a single set of line separator characters is written. For all other tags, a single blank is output.