home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / text / html / parser / DocumentParser.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.6 KB  |  123 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. import javax.swing.text.html.HTMLEditorKit.ParserCallback;
  10.  
  11. public class DocumentParser extends Parser {
  12.    private int inbody;
  13.    private int intitle;
  14.    private int inhead;
  15.    private int instyle;
  16.    private boolean seentitle;
  17.    private HTMLEditorKit.ParserCallback callback = null;
  18.    private boolean ignoreCharSet = false;
  19.    private static final boolean debugFlag = false;
  20.  
  21.    public DocumentParser(DTD var1) {
  22.       super(var1);
  23.    }
  24.  
  25.    public void parse(Reader var1, HTMLEditorKit.ParserCallback var2, boolean var3) throws IOException {
  26.       this.ignoreCharSet = var3;
  27.       this.callback = var2;
  28.       ((Parser)this).parse(var1);
  29.       var2.handleEndOfLineString(((Parser)this).getEndOfLineString());
  30.    }
  31.  
  32.    protected void handleStartTag(TagElement var1) {
  33.       Element var2 = var1.getElement();
  34.       if (var2 == super.dtd.body) {
  35.          ++this.inbody;
  36.       } else if (var2 != super.dtd.html) {
  37.          if (var2 == super.dtd.head) {
  38.             ++this.inhead;
  39.          } else if (var2 == super.dtd.title) {
  40.             ++this.intitle;
  41.          } else if (var2 == super.dtd.style) {
  42.             ++this.instyle;
  43.          }
  44.       }
  45.  
  46.       if (var1.fictional()) {
  47.          SimpleAttributeSet var3 = new SimpleAttributeSet();
  48.          var3.addAttribute(ParserCallback.IMPLIED, Boolean.TRUE);
  49.          this.callback.handleStartTag(var1.getHTMLTag(), var3, ((Parser)this).getBlockStartPosition());
  50.       } else {
  51.          this.callback.handleStartTag(var1.getHTMLTag(), ((Parser)this).getAttributes(), ((Parser)this).getBlockStartPosition());
  52.          ((Parser)this).flushAttributes();
  53.       }
  54.  
  55.    }
  56.  
  57.    protected void handleComment(char[] var1) {
  58.       this.callback.handleComment(var1, ((Parser)this).getBlockStartPosition());
  59.    }
  60.  
  61.    protected void handleEmptyTag(TagElement var1) throws ChangedCharSetException {
  62.       Element var2 = var1.getElement();
  63.       if (var2 == super.dtd.meta && !this.ignoreCharSet) {
  64.          SimpleAttributeSet var3 = ((Parser)this).getAttributes();
  65.          if (var3 != null) {
  66.             String var4 = (String)var3.getAttribute(Attribute.CONTENT);
  67.             if (var4 != null) {
  68.                if ("content-type".equalsIgnoreCase((String)var3.getAttribute(Attribute.HTTPEQUIV))) {
  69.                   throw new ChangedCharSetException(var4, false);
  70.                }
  71.  
  72.                if ("charset".equalsIgnoreCase((String)var3.getAttribute(Attribute.HTTPEQUIV))) {
  73.                   throw new ChangedCharSetException(var4, true);
  74.                }
  75.             }
  76.          }
  77.       }
  78.  
  79.       if (this.inbody != 0 || var2 == super.dtd.meta || var2 == super.dtd.base || var2 == super.dtd.isindex || var2 == super.dtd.style || var2 == super.dtd.link) {
  80.          if (var1.fictional()) {
  81.             SimpleAttributeSet var5 = new SimpleAttributeSet();
  82.             var5.addAttribute(ParserCallback.IMPLIED, Boolean.TRUE);
  83.             this.callback.handleSimpleTag(var1.getHTMLTag(), var5, ((Parser)this).getBlockStartPosition());
  84.          } else {
  85.             this.callback.handleSimpleTag(var1.getHTMLTag(), ((Parser)this).getAttributes(), ((Parser)this).getBlockStartPosition());
  86.             ((Parser)this).flushAttributes();
  87.          }
  88.       }
  89.  
  90.    }
  91.  
  92.    protected void handleEndTag(TagElement var1) {
  93.       Element var2 = var1.getElement();
  94.       if (var2 == super.dtd.body) {
  95.          --this.inbody;
  96.       } else if (var2 == super.dtd.title) {
  97.          --this.intitle;
  98.          this.seentitle = true;
  99.       } else if (var2 == super.dtd.head) {
  100.          --this.inhead;
  101.       } else if (var2 == super.dtd.style) {
  102.          --this.instyle;
  103.       }
  104.  
  105.       this.callback.handleEndTag(var1.getHTMLTag(), ((Parser)this).getBlockStartPosition());
  106.    }
  107.  
  108.    protected void handleText(char[] var1) {
  109.       if (var1 != null && (this.inbody != 0 || this.instyle != 0 || this.intitle != 0 && !this.seentitle)) {
  110.          this.callback.handleText(var1, ((Parser)this).getBlockStartPosition());
  111.       }
  112.  
  113.    }
  114.  
  115.    protected void handleError(int var1, String var2) {
  116.       this.callback.handleError(var2, ((Parser)this).getCurrentPos());
  117.    }
  118.  
  119.    private void debug(String var1) {
  120.       System.out.println(var1);
  121.    }
  122. }
  123.