home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / text / html / parser / DocumentParser.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  3.4 KB  |  110 lines

  1. package javax.swing.text.html.parser;
  2.  
  3. import java.io.IOException;
  4. import java.io.Reader;
  5. import javax.swing.text.ChangedCharSetException;
  6. import javax.swing.text.SimpleAttributeSet;
  7. import javax.swing.text.html.HTMLEditorKit;
  8. import javax.swing.text.html.HTML.Attribute;
  9.  
  10. public class DocumentParser extends Parser {
  11.    private int inbody;
  12.    private int intitle;
  13.    private int inhead;
  14.    private boolean seentitle;
  15.    private HTMLEditorKit.ParserCallback callback = null;
  16.    private boolean ignoreCharSet = false;
  17.    private static final boolean debugFlag = false;
  18.  
  19.    public DocumentParser(DTD var1) {
  20.       super(var1);
  21.    }
  22.  
  23.    private void debug(String var1) {
  24.       System.out.println(var1);
  25.    }
  26.  
  27.    protected void handleComment(char[] var1) {
  28.       this.callback.handleComment(var1, ((Parser)this).getCurrentPos());
  29.    }
  30.  
  31.    protected void handleEmptyTag(TagElement var1) throws ChangedCharSetException {
  32.       Element var2 = var1.getElement();
  33.       if (var2 == super.dtd.meta && !this.ignoreCharSet) {
  34.          SimpleAttributeSet var3 = ((Parser)this).getAttributes();
  35.          if (var3 != null) {
  36.             String var4 = (String)var3.getAttribute(Attribute.CONTENT);
  37.             if (var4 != null) {
  38.                if ("content-type".equalsIgnoreCase((String)var3.getAttribute(Attribute.HTTPEQUIV))) {
  39.                   throw new ChangedCharSetException(var4, false);
  40.                }
  41.  
  42.                if ("charset".equalsIgnoreCase((String)var3.getAttribute(Attribute.HTTPEQUIV))) {
  43.                   throw new ChangedCharSetException(var4, true);
  44.                }
  45.             }
  46.          }
  47.       } else if (this.inbody != 0 || var2 == super.dtd.meta || var2 == super.dtd.base || var2 == super.dtd.isindex) {
  48.          if (var1.fictional()) {
  49.             this.callback.handleSimpleTag(var1.getHTMLTag(), new SimpleAttributeSet(), ((Parser)this).getCurrentPos());
  50.          } else {
  51.             this.callback.handleSimpleTag(var1.getHTMLTag(), ((Parser)this).getAttributes(), ((Parser)this).getCurrentPos());
  52.             ((Parser)this).flushAttributes();
  53.          }
  54.       }
  55.  
  56.    }
  57.  
  58.    protected void handleEndTag(TagElement var1) {
  59.       Element var2 = var1.getElement();
  60.       if (var2 == super.dtd.body) {
  61.          --this.inbody;
  62.       } else if (var2 == super.dtd.title) {
  63.          --this.intitle;
  64.          this.seentitle = true;
  65.       } else if (var2 == super.dtd.head) {
  66.          --this.inhead;
  67.       }
  68.  
  69.       this.callback.handleEndTag(var1.getHTMLTag(), ((Parser)this).getCurrentPos());
  70.    }
  71.  
  72.    protected void handleError(int var1, String var2) {
  73.       this.callback.handleError(var2, ((Parser)this).getCurrentPos());
  74.    }
  75.  
  76.    protected void handleStartTag(TagElement var1) {
  77.       Element var2 = var1.getElement();
  78.       if (var2 == super.dtd.body) {
  79.          ++this.inbody;
  80.       } else if (var2 != super.dtd.html) {
  81.          if (var2 == super.dtd.head) {
  82.             ++this.inhead;
  83.          } else if (var2 == super.dtd.title) {
  84.             ++this.intitle;
  85.          }
  86.       }
  87.  
  88.       if (var1.fictional()) {
  89.          this.callback.handleStartTag(var1.getHTMLTag(), new SimpleAttributeSet(), ((Parser)this).getCurrentPos());
  90.       } else {
  91.          this.callback.handleStartTag(var1.getHTMLTag(), ((Parser)this).getAttributes(), ((Parser)this).getCurrentPos());
  92.          ((Parser)this).flushAttributes();
  93.       }
  94.  
  95.    }
  96.  
  97.    protected void handleText(char[] var1) {
  98.       if (var1 != null && (this.inbody != 0 || this.intitle != 0 && !this.seentitle)) {
  99.          this.callback.handleText(var1, ((Parser)this).getCurrentPos());
  100.       }
  101.  
  102.    }
  103.  
  104.    public void parse(Reader var1, HTMLEditorKit.ParserCallback var2, boolean var3) throws IOException {
  105.       this.ignoreCharSet = var3;
  106.       this.callback = var2;
  107.       ((Parser)this).parse(var1);
  108.    }
  109. }
  110.