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 / HTMLDocument$HTMLReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  17.2 KB  |  804 lines

  1. package javax.swing.text.html;
  2.  
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5. import java.util.Hashtable;
  6. import java.util.Stack;
  7. import java.util.Vector;
  8. import javax.swing.event.UndoableEditEvent;
  9. import javax.swing.event.DocumentEvent.EventType;
  10. import javax.swing.text.AbstractDocument;
  11. import javax.swing.text.AttributeSet;
  12. import javax.swing.text.BadLocationException;
  13. import javax.swing.text.DefaultStyledDocument;
  14. import javax.swing.text.Element;
  15. import javax.swing.text.MutableAttributeSet;
  16. import javax.swing.text.SimpleAttributeSet;
  17. import javax.swing.text.StyleConstants;
  18. import javax.swing.text.html.HTML.Attribute;
  19. import javax.swing.text.html.HTML.Tag;
  20. import javax.swing.text.html.HTMLEditorKit.ParserCallback;
  21. import javax.swing.undo.CompoundEdit;
  22.  
  23. public class HTMLDocument$HTMLReader extends HTMLEditorKit.ParserCallback {
  24.    private int flushCount;
  25.    private boolean insertAfterImplied;
  26.    private boolean wantsTrailingNewline;
  27.    int threshold;
  28.    int offset;
  29.    boolean inParagraph;
  30.    boolean impliedP;
  31.    boolean inPre;
  32.    boolean inTextArea;
  33.    TextAreaDocument textAreaDocument;
  34.    boolean inTitle;
  35.    boolean lastWasNewline;
  36.    boolean emptyAnchor;
  37.    boolean midInsert;
  38.    boolean inBody;
  39.    HTML.Tag insertTag;
  40.    boolean insertInsertTag;
  41.    boolean foundInsertTag;
  42.    int insertTagDepthDelta;
  43.    int popDepth;
  44.    int pushDepth;
  45.    Map lastMap;
  46.    boolean inStyle;
  47.    String defaultStyle;
  48.    Vector styles;
  49.    boolean inHead;
  50.    boolean isStyleCSS;
  51.    boolean emptyDocument;
  52.    AttributeSet styleAttributes;
  53.    Option option;
  54.    protected Vector parseBuffer;
  55.    protected MutableAttributeSet charAttr;
  56.    Stack charAttrStack;
  57.    Hashtable tagMap;
  58.    int inBlock;
  59.    // $FF: synthetic field
  60.    private final HTMLDocument this$0;
  61.  
  62.    public HTMLDocument$HTMLReader(HTMLDocument var1, int var2) {
  63.       this(var1, var2, 0, 0, (HTML.Tag)null);
  64.    }
  65.  
  66.    public HTMLDocument$HTMLReader(HTMLDocument var1, int var2, int var3, int var4, HTML.Tag var5) {
  67.       this(var1, var2, var3, var4, var5, true, false, true);
  68.    }
  69.  
  70.    HTMLDocument$HTMLReader(HTMLDocument var1, int var2, int var3, int var4, HTML.Tag var5, boolean var6, boolean var7, boolean var8) {
  71.       this.this$0 = var1;
  72.       this.inParagraph = false;
  73.       this.impliedP = false;
  74.       this.inPre = false;
  75.       this.inTextArea = false;
  76.       this.textAreaDocument = null;
  77.       this.inTitle = false;
  78.       this.lastWasNewline = true;
  79.       this.inStyle = false;
  80.       this.inHead = false;
  81.       this.parseBuffer = new Vector();
  82.       this.charAttr = new SimpleAttributeSet();
  83.       this.charAttrStack = new Stack();
  84.       this.inBlock = 0;
  85.       this.emptyDocument = ((AbstractDocument)var1).getLength() == 0;
  86.       this.isStyleCSS = "text/css".equals(var1.getDefaultStyleSheetType());
  87.       this.offset = var2;
  88.       this.threshold = var1.getTokenThreshold();
  89.       this.tagMap = new Hashtable(57);
  90.       new HTMLDocument.HTMLReader.TagAction(this);
  91.       HTMLDocument.HTMLReader.BlockAction var10 = new HTMLDocument.HTMLReader.BlockAction(this);
  92.       HTMLDocument.HTMLReader.ParagraphAction var11 = new HTMLDocument.HTMLReader.ParagraphAction(this);
  93.       HTMLDocument.HTMLReader.CharacterAction var12 = new HTMLDocument.HTMLReader.CharacterAction(this);
  94.       HTMLDocument.HTMLReader.SpecialAction var13 = new HTMLDocument.HTMLReader.SpecialAction(this);
  95.       HTMLDocument.HTMLReader.FormAction var14 = new HTMLDocument.HTMLReader.FormAction(this);
  96.       HTMLDocument.HTMLReader.HiddenAction var15 = new HTMLDocument.HTMLReader.HiddenAction(this);
  97.       HTMLDocument.HTMLReader.ConvertAction var16 = new HTMLDocument.HTMLReader.ConvertAction(this);
  98.       this.tagMap.put(Tag.A, new HTMLDocument.HTMLReader.AnchorAction(this));
  99.       this.tagMap.put(Tag.ADDRESS, var12);
  100.       this.tagMap.put(Tag.APPLET, var15);
  101.       this.tagMap.put(Tag.AREA, new HTMLDocument.HTMLReader.AreaAction(this));
  102.       this.tagMap.put(Tag.B, var16);
  103.       this.tagMap.put(Tag.BASE, new HTMLDocument.HTMLReader.BaseAction(this));
  104.       this.tagMap.put(Tag.BASEFONT, var12);
  105.       this.tagMap.put(Tag.BIG, var12);
  106.       this.tagMap.put(Tag.BLOCKQUOTE, var10);
  107.       this.tagMap.put(Tag.BODY, var10);
  108.       this.tagMap.put(Tag.BR, var13);
  109.       this.tagMap.put(Tag.CAPTION, var10);
  110.       this.tagMap.put(Tag.CENTER, var10);
  111.       this.tagMap.put(Tag.CITE, var12);
  112.       this.tagMap.put(Tag.CODE, var12);
  113.       this.tagMap.put(Tag.DD, var10);
  114.       this.tagMap.put(Tag.DFN, var12);
  115.       this.tagMap.put(Tag.DIR, var10);
  116.       this.tagMap.put(Tag.DIV, var10);
  117.       this.tagMap.put(Tag.DL, var10);
  118.       this.tagMap.put(Tag.DT, var11);
  119.       this.tagMap.put(Tag.EM, var12);
  120.       this.tagMap.put(Tag.FONT, var16);
  121.       this.tagMap.put(Tag.FORM, var12);
  122.       this.tagMap.put(Tag.FRAME, var13);
  123.       this.tagMap.put(Tag.FRAMESET, var10);
  124.       this.tagMap.put(Tag.H1, var11);
  125.       this.tagMap.put(Tag.H2, var11);
  126.       this.tagMap.put(Tag.H3, var11);
  127.       this.tagMap.put(Tag.H4, var11);
  128.       this.tagMap.put(Tag.H5, var11);
  129.       this.tagMap.put(Tag.H6, var11);
  130.       this.tagMap.put(Tag.HEAD, new HTMLDocument.HTMLReader.HeadAction(this));
  131.       this.tagMap.put(Tag.HR, var13);
  132.       this.tagMap.put(Tag.HTML, var10);
  133.       this.tagMap.put(Tag.I, var16);
  134.       this.tagMap.put(Tag.IMG, var13);
  135.       this.tagMap.put(Tag.INPUT, var14);
  136.       this.tagMap.put(Tag.ISINDEX, new HTMLDocument.HTMLReader.IsindexAction(this));
  137.       this.tagMap.put(Tag.KBD, var12);
  138.       this.tagMap.put(Tag.LI, var10);
  139.       this.tagMap.put(Tag.LINK, new HTMLDocument.HTMLReader.LinkAction(this));
  140.       this.tagMap.put(Tag.MAP, new HTMLDocument.HTMLReader.MapAction(this));
  141.       this.tagMap.put(Tag.MENU, var10);
  142.       this.tagMap.put(Tag.META, new HTMLDocument.HTMLReader.MetaAction(this));
  143.       this.tagMap.put(Tag.NOBR, var12);
  144.       this.tagMap.put(Tag.NOFRAMES, var10);
  145.       this.tagMap.put(Tag.OBJECT, var13);
  146.       this.tagMap.put(Tag.OL, var10);
  147.       this.tagMap.put(Tag.OPTION, var14);
  148.       this.tagMap.put(Tag.P, var11);
  149.       this.tagMap.put(Tag.PARAM, new HTMLDocument.HTMLReader.ObjectAction(this));
  150.       this.tagMap.put(Tag.PRE, new HTMLDocument.HTMLReader.PreAction(this));
  151.       this.tagMap.put(Tag.SAMP, var12);
  152.       this.tagMap.put(Tag.SCRIPT, var15);
  153.       this.tagMap.put(Tag.SELECT, var14);
  154.       this.tagMap.put(Tag.SMALL, var12);
  155.       this.tagMap.put(Tag.STRIKE, var16);
  156.       this.tagMap.put(Tag.S, var12);
  157.       this.tagMap.put(Tag.STRONG, var12);
  158.       this.tagMap.put(Tag.STYLE, new HTMLDocument.HTMLReader.StyleAction(this));
  159.       this.tagMap.put(Tag.SUB, var16);
  160.       this.tagMap.put(Tag.SUP, var16);
  161.       this.tagMap.put(Tag.TABLE, var10);
  162.       this.tagMap.put(Tag.TD, var10);
  163.       this.tagMap.put(Tag.TEXTAREA, var14);
  164.       this.tagMap.put(Tag.TH, var10);
  165.       this.tagMap.put(Tag.TITLE, new HTMLDocument.HTMLReader.TitleAction(this));
  166.       this.tagMap.put(Tag.TR, var10);
  167.       this.tagMap.put(Tag.TT, var12);
  168.       this.tagMap.put(Tag.U, var16);
  169.       this.tagMap.put(Tag.UL, var10);
  170.       this.tagMap.put(Tag.VAR, var12);
  171.       ((AbstractDocument)var1).putProperty("AdditionalComments", (Object)null);
  172.       if (var5 != null) {
  173.          this.insertTag = var5;
  174.          this.popDepth = var3;
  175.          this.pushDepth = var4;
  176.          this.insertInsertTag = var6;
  177.          this.foundInsertTag = false;
  178.       } else {
  179.          this.foundInsertTag = true;
  180.       }
  181.  
  182.       if (var7) {
  183.          this.popDepth = var3;
  184.          this.pushDepth = var4;
  185.          this.insertAfterImplied = true;
  186.          this.foundInsertTag = false;
  187.          this.midInsert = false;
  188.          this.insertInsertTag = true;
  189.          this.wantsTrailingNewline = var8;
  190.       } else {
  191.          this.midInsert = !this.emptyDocument && var5 == null;
  192.          if (this.midInsert) {
  193.             this.generateEndsSpecsForMidInsert();
  194.          }
  195.       }
  196.  
  197.    }
  198.  
  199.    private void generateEndsSpecsForMidInsert() {
  200.       int var1 = this.heightToElementWithName(Tag.BODY, Math.max(0, this.offset - 1));
  201.       boolean var2 = false;
  202.       if (var1 == -1 && this.offset > 0) {
  203.          var1 = this.heightToElementWithName(Tag.BODY, this.offset);
  204.          if (var1 != -1) {
  205.             var1 = this.depthTo(this.offset - 1) - 1;
  206.             var2 = true;
  207.          }
  208.       }
  209.  
  210.       if (var1 == -1) {
  211.          throw new RuntimeException("Must insert new content into body element-");
  212.       } else {
  213.          if (var1 != -1) {
  214.             try {
  215.                if (!var2 && this.offset > 0 && !this.this$0.getText(this.offset - 1, 1).equals("\n")) {
  216.                   SimpleAttributeSet var3 = new SimpleAttributeSet();
  217.                   var3.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  218.                   DefaultStyledDocument.ElementSpec var4 = new DefaultStyledDocument.ElementSpec(var3, (short)3, HTMLDocument.access$000(), 0, 1);
  219.                   this.parseBuffer.addElement(var4);
  220.                }
  221.             } catch (BadLocationException var5) {
  222.             }
  223.  
  224.             while(var1-- > 0) {
  225.                this.parseBuffer.addElement(new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2));
  226.             }
  227.  
  228.             if (var2) {
  229.                DefaultStyledDocument.ElementSpec var6 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)1);
  230.                var6.setDirection((short)5);
  231.                this.parseBuffer.addElement(var6);
  232.             }
  233.          }
  234.  
  235.       }
  236.    }
  237.  
  238.    private int depthTo(int var1) {
  239.       Element var2 = this.this$0.getDefaultRootElement();
  240.  
  241.       int var3;
  242.       for(var3 = 0; !var2.isLeaf(); var2 = var2.getElement(var2.getElementIndex(var1))) {
  243.          ++var3;
  244.       }
  245.  
  246.       return var3;
  247.    }
  248.  
  249.    private int heightToElementWithName(Object var1, int var2) {
  250.       Element var3 = this.this$0.getCharacterElement(var2).getParentElement();
  251.  
  252.       int var4;
  253.       for(var4 = 0; var3 != null && var3.getAttributes().getAttribute(StyleConstants.NameAttribute) != var1; var3 = var3.getParentElement()) {
  254.          ++var4;
  255.       }
  256.  
  257.       return var3 == null ? -1 : var4;
  258.    }
  259.  
  260.    private void adjustEndElement() {
  261.       int var1 = this.this$0.getLength();
  262.       if (var1 != 0) {
  263.          this.this$0.obtainLock();
  264.  
  265.          try {
  266.             Element[] var2 = this.getPathTo(var1 - 1);
  267.             if (var2.length > 1 && var2[1].getAttributes().getAttribute(StyleConstants.NameAttribute) == Tag.BODY && var2[1].getEndOffset() == var1) {
  268.                String var3 = this.this$0.getText(var1 - 1, 1);
  269.                Element[] var5 = new Element[0];
  270.                Element[] var6 = new Element[1];
  271.                int var7 = var2[0].getElementIndex(var1);
  272.                var6[0] = var2[0].getElement(var7);
  273.                ((AbstractDocument.BranchElement)var2[0]).replace(var7, 1, var5);
  274.                AbstractDocument.ElementEdit var8 = new AbstractDocument.ElementEdit(var2[0], var7, var6, var5);
  275.                AbstractDocument.DefaultDocumentEvent var4;
  276.                if (var2.length == 3 && (var2[2].getAttributes().getAttribute(StyleConstants.NameAttribute) == Tag.P || var2[2].getAttributes().getAttribute(StyleConstants.NameAttribute) == Tag.IMPLIED) && !var3.equals("\n")) {
  277.                   var7 = var2[2].getElementIndex(var1 - 1);
  278.                   AttributeSet var27 = var2[2].getElement(var7).getAttributes();
  279.                   if (var27.getAttributeCount() == 1 && var27.getAttribute(StyleConstants.NameAttribute) == Tag.CONTENT) {
  280.                      var5 = new Element[1];
  281.                      var6 = new Element[]{var2[2].getElement(var7)};
  282.                      int var29 = var6[0].getStartOffset();
  283.                      var5[0] = this.this$0.createLeafElement(var2[2], var27, var29, var1 + 1);
  284.                      ((AbstractDocument.BranchElement)var2[2]).replace(var7, 1, var5);
  285.                      var4 = new AbstractDocument.DefaultDocumentEvent(this.this$0, var29, var1 - var29 + 1, EventType.CHANGE);
  286.                      var4.addEdit(new AbstractDocument.ElementEdit(var2[2], var7, var6, var5));
  287.                   } else {
  288.                      SimpleAttributeSet var28 = new SimpleAttributeSet();
  289.                      var28.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  290.                      var5 = new Element[]{this.this$0.createLeafElement(var2[2], var28, var1, var1 + 1)};
  291.                      ((AbstractDocument.BranchElement)var2[2]).replace(var7 + 1, 0, var5);
  292.                      var4 = new AbstractDocument.DefaultDocumentEvent(this.this$0, var1, 1, EventType.CHANGE);
  293.                      var6 = new Element[0];
  294.                      var4.addEdit(new AbstractDocument.ElementEdit(var2[2], var7 + 1, var6, var5));
  295.                   }
  296.                } else {
  297.                   SimpleAttributeSet var9 = new SimpleAttributeSet();
  298.                   var9.addAttribute(StyleConstants.NameAttribute, Tag.P);
  299.                   AbstractDocument.BranchElement var10 = (AbstractDocument.BranchElement)this.this$0.createBranchElement(var2[1], var9);
  300.                   var5 = new Element[]{var10};
  301.                   var6 = new Element[0];
  302.                   var7 = var2[1].getElementIndex(var1 - 1) + 1;
  303.                   ((AbstractDocument.BranchElement)var2[1]).replace(var7, 0, var5);
  304.                   var4 = new AbstractDocument.DefaultDocumentEvent(this.this$0, var1, 1, EventType.CHANGE);
  305.                   var4.addEdit(new AbstractDocument.ElementEdit(var2[1], var7, var6, var5));
  306.                   var5 = new Element[1];
  307.                   var9 = new SimpleAttributeSet();
  308.                   var9.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  309.                   var5[0] = this.this$0.createLeafElement(var10, var9, var1, var1 + 1);
  310.                   var10.replace(0, 0, var5);
  311.                }
  312.  
  313.                var4.addEdit(var8);
  314.                ((CompoundEdit)var4).end();
  315.                this.this$0.fireChangedUpdate(var4);
  316.                this.this$0.fireUndoableEditUpdate(new UndoableEditEvent(this, var4));
  317.             }
  318.          } catch (BadLocationException var15) {
  319.          } finally {
  320.             this.this$0.releaseLock();
  321.          }
  322.  
  323.       }
  324.    }
  325.  
  326.    private Element[] getPathTo(int var1) {
  327.       Stack var2 = new Stack();
  328.  
  329.       for(Element var3 = this.this$0.getDefaultRootElement(); !var3.isLeaf(); var3 = var3.getElement(var3.getElementIndex(var1))) {
  330.          var2.push(var3);
  331.       }
  332.  
  333.       Element[] var5 = new Element[((Vector)var2).size()];
  334.       ((Vector)var2).copyInto(var5);
  335.       return var5;
  336.    }
  337.  
  338.    public void flush() throws BadLocationException {
  339.       this.flushBuffer(true);
  340.       if (this.emptyDocument && !this.insertAfterImplied) {
  341.          this.adjustEndElement();
  342.       }
  343.  
  344.    }
  345.  
  346.    public void handleText(char[] var1, int var2) {
  347.       if (!this.midInsert || this.inBody) {
  348.          if (this.inTextArea) {
  349.             this.textAreaContent(var1);
  350.          } else if (this.inPre) {
  351.             this.preContent(var1);
  352.          } else if (this.inTitle) {
  353.             this.this$0.putProperty("title", new String(var1));
  354.          } else if (this.option != null) {
  355.             this.option.setLabel(new String(var1));
  356.          } else if (this.inStyle) {
  357.             if (this.styles != null) {
  358.                this.styles.addElement(new String(var1));
  359.             }
  360.          } else if (this.inBlock > 0) {
  361.             if (!this.foundInsertTag && this.insertAfterImplied) {
  362.                this.foundInsertTag(false);
  363.                this.foundInsertTag = true;
  364.                this.inParagraph = this.impliedP = true;
  365.             }
  366.  
  367.             if (var1.length >= 1) {
  368.                this.addContent(var1, 0, var1.length);
  369.             }
  370.          }
  371.  
  372.       }
  373.    }
  374.  
  375.    public void handleStartTag(HTML.Tag var1, MutableAttributeSet var2, int var3) {
  376.       if (this.midInsert && !this.inBody) {
  377.          if (var1 == Tag.BODY) {
  378.             this.inBody = true;
  379.             ++this.inBlock;
  380.          }
  381.  
  382.       } else {
  383.          if (!this.inBody && var1 == Tag.BODY) {
  384.             this.inBody = true;
  385.          }
  386.  
  387.          if (this.isStyleCSS && var2.isDefined(Attribute.STYLE)) {
  388.             String var4 = (String)var2.getAttribute(Attribute.STYLE);
  389.             var2.removeAttribute(Attribute.STYLE);
  390.             this.styleAttributes = this.this$0.getStyleSheet().getDeclaration(var4);
  391.             var2.addAttributes(this.styleAttributes);
  392.          } else {
  393.             this.styleAttributes = null;
  394.          }
  395.  
  396.          HTMLDocument.HTMLReader.TagAction var5 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
  397.          if (var5 != null) {
  398.             var5.start(var1, var2);
  399.          }
  400.  
  401.       }
  402.    }
  403.  
  404.    public void handleComment(char[] var1, int var2) {
  405.       if (this.inStyle) {
  406.          if (this.styles != null) {
  407.             this.styles.addElement(new String(var1));
  408.          }
  409.       } else if (this.this$0.getPreservesUnknownTags()) {
  410.          if (this.inBlock == 0) {
  411.             Object var4 = this.this$0.getProperty("AdditionalComments");
  412.             if (var4 != null && !(var4 instanceof Vector)) {
  413.                return;
  414.             }
  415.  
  416.             if (var4 == null) {
  417.                var4 = new Vector();
  418.                this.this$0.putProperty("AdditionalComments", var4);
  419.             }
  420.  
  421.             ((Vector)var4).addElement(new String(var1));
  422.             return;
  423.          }
  424.  
  425.          SimpleAttributeSet var3 = new SimpleAttributeSet();
  426.          var3.addAttribute(Attribute.COMMENT, new String(var1));
  427.          this.addSpecialElement(Tag.COMMENT, var3);
  428.       }
  429.  
  430.    }
  431.  
  432.    public void handleEndTag(HTML.Tag var1, int var2) {
  433.       if (!this.midInsert || this.inBody) {
  434.          if (var1 == Tag.BODY) {
  435.             this.inBody = false;
  436.             if (this.midInsert) {
  437.                --this.inBlock;
  438.             }
  439.          }
  440.  
  441.          HTMLDocument.HTMLReader.TagAction var3 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
  442.          if (var3 != null) {
  443.             var3.end(var1);
  444.          }
  445.  
  446.       }
  447.    }
  448.  
  449.    public void handleSimpleTag(HTML.Tag var1, MutableAttributeSet var2, int var3) {
  450.       if (!this.midInsert || this.inBody) {
  451.          if (this.isStyleCSS && var2.isDefined(Attribute.STYLE)) {
  452.             String var4 = (String)var2.getAttribute(Attribute.STYLE);
  453.             var2.removeAttribute(Attribute.STYLE);
  454.             this.styleAttributes = this.this$0.getStyleSheet().getDeclaration(var4);
  455.             var2.addAttributes(this.styleAttributes);
  456.          } else {
  457.             this.styleAttributes = null;
  458.          }
  459.  
  460.          HTMLDocument.HTMLReader.TagAction var5 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
  461.          if (var5 != null) {
  462.             var5.start(var1, var2);
  463.             var5.end(var1);
  464.          } else if (this.this$0.getPreservesUnknownTags()) {
  465.             this.addSpecialElement(var1, var2);
  466.          }
  467.  
  468.       }
  469.    }
  470.  
  471.    public void handleEndOfLineString(String var1) {
  472.       if (this.emptyDocument && var1 != null) {
  473.          this.this$0.putProperty("__EndOfLine__", var1);
  474.       }
  475.  
  476.    }
  477.  
  478.    protected void registerTag(HTML.Tag var1, HTMLDocument.HTMLReader.TagAction var2) {
  479.       this.tagMap.put(var1, var2);
  480.    }
  481.  
  482.    protected void pushCharacterStyle() {
  483.       this.charAttrStack.push(this.charAttr.copyAttributes());
  484.    }
  485.  
  486.    protected void popCharacterStyle() {
  487.       if (!this.charAttrStack.empty()) {
  488.          this.charAttr = (MutableAttributeSet)this.charAttrStack.peek();
  489.          this.charAttrStack.pop();
  490.       }
  491.  
  492.    }
  493.  
  494.    protected void textAreaContent(char[] var1) {
  495.       try {
  496.          this.textAreaDocument.insertString(this.textAreaDocument.getLength(), new String(var1), (AttributeSet)null);
  497.       } catch (BadLocationException var3) {
  498.       }
  499.  
  500.    }
  501.  
  502.    protected void preContent(char[] var1) {
  503.       int var2 = 0;
  504.  
  505.       for(int var3 = 0; var3 < var1.length; ++var3) {
  506.          if (var1[var3] == '\n') {
  507.             this.addContent(var1, var2, var3 - var2 + 1);
  508.             this.blockClose(Tag.IMPLIED);
  509.             SimpleAttributeSet var4 = new SimpleAttributeSet();
  510.             var4.addAttribute(javax.swing.text.html.CSS.Attribute.WHITE_SPACE, "pre");
  511.             this.blockOpen(Tag.IMPLIED, var4);
  512.             var2 = var3 + 1;
  513.          }
  514.       }
  515.  
  516.       if (var2 < var1.length) {
  517.          this.addContent(var1, var2, var1.length - var2);
  518.       }
  519.  
  520.    }
  521.  
  522.    protected void blockOpen(HTML.Tag var1, MutableAttributeSet var2) {
  523.       if (this.impliedP) {
  524.          this.impliedP = false;
  525.          this.inParagraph = false;
  526.          this.blockClose(Tag.IMPLIED);
  527.       }
  528.  
  529.       ++this.inBlock;
  530.       if (this.canInsertTag(var1, var2, true)) {
  531.          if (var2.isDefined(ParserCallback.IMPLIED)) {
  532.             var2.removeAttribute(ParserCallback.IMPLIED);
  533.          }
  534.  
  535.          this.lastWasNewline = false;
  536.          var2.addAttribute(StyleConstants.NameAttribute, var1);
  537.          DefaultStyledDocument.ElementSpec var3 = new DefaultStyledDocument.ElementSpec(var2.copyAttributes(), (short)1);
  538.          this.parseBuffer.addElement(var3);
  539.       }
  540.    }
  541.  
  542.    protected void blockClose(HTML.Tag var1) {
  543.       --this.inBlock;
  544.       if (this.foundInsertTag) {
  545.          if (!this.lastWasNewline) {
  546.             this.addContent(HTMLDocument.access$000(), 0, 1, false);
  547.             this.lastWasNewline = true;
  548.          }
  549.  
  550.          if (this.impliedP) {
  551.             this.impliedP = false;
  552.             this.inParagraph = false;
  553.             this.blockClose(Tag.IMPLIED);
  554.          }
  555.  
  556.          DefaultStyledDocument.ElementSpec var2 = this.parseBuffer.size() > 0 ? (DefaultStyledDocument.ElementSpec)this.parseBuffer.lastElement() : null;
  557.          if (var2 != null && var2.getType() == 1) {
  558.             char[] var3 = new char[]{' '};
  559.             this.addContent(var3, 0, 1);
  560.          }
  561.  
  562.          DefaultStyledDocument.ElementSpec var4 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2);
  563.          this.parseBuffer.addElement(var4);
  564.       }
  565.    }
  566.  
  567.    protected void addContent(char[] var1, int var2, int var3) {
  568.       this.addContent(var1, var2, var3, true);
  569.    }
  570.  
  571.    protected void addContent(char[] var1, int var2, int var3, boolean var4) {
  572.       if (this.foundInsertTag) {
  573.          if (var4 && !this.inParagraph && !this.inPre) {
  574.             this.blockOpen(Tag.IMPLIED, new SimpleAttributeSet());
  575.             this.inParagraph = true;
  576.             this.impliedP = true;
  577.          }
  578.  
  579.          this.emptyAnchor = false;
  580.          this.charAttr.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  581.          AttributeSet var5 = this.charAttr.copyAttributes();
  582.          DefaultStyledDocument.ElementSpec var6 = new DefaultStyledDocument.ElementSpec(var5, (short)3, var1, var2, var3);
  583.          this.parseBuffer.addElement(var6);
  584.          if (this.parseBuffer.size() > this.threshold) {
  585.             try {
  586.                this.flushBuffer(false);
  587.             } catch (BadLocationException var8) {
  588.             }
  589.          }
  590.  
  591.          if (var3 > 0) {
  592.             this.lastWasNewline = var1[var2 + var3 - 1] == '\n';
  593.          }
  594.  
  595.       }
  596.    }
  597.  
  598.    protected void addSpecialElement(HTML.Tag var1, MutableAttributeSet var2) {
  599.       if (var1 != Tag.FRAME && !this.inParagraph && !this.inPre) {
  600.          this.blockOpen(Tag.IMPLIED, new SimpleAttributeSet());
  601.          this.inParagraph = true;
  602.          this.impliedP = true;
  603.       }
  604.  
  605.       if (this.canInsertTag(var1, var2, true)) {
  606.          if (var2.isDefined(ParserCallback.IMPLIED)) {
  607.             var2.removeAttribute(ParserCallback.IMPLIED);
  608.          }
  609.  
  610.          this.emptyAnchor = false;
  611.          var2.addAttributes(this.charAttr);
  612.          var2.addAttribute(StyleConstants.NameAttribute, var1);
  613.          char[] var3 = new char[]{' '};
  614.          DefaultStyledDocument.ElementSpec var4 = new DefaultStyledDocument.ElementSpec(var2.copyAttributes(), (short)3, var3, 0, 1);
  615.          this.parseBuffer.addElement(var4);
  616.          if (var1 == Tag.FRAME) {
  617.             this.lastWasNewline = true;
  618.          }
  619.  
  620.       }
  621.    }
  622.  
  623.    void flushBuffer(boolean var1) throws BadLocationException {
  624.       int var2 = this.this$0.getLength();
  625.       int var3 = this.parseBuffer.size();
  626.       if (var1 && (this.insertTag != null || this.insertAfterImplied) && var3 > 0) {
  627.          this.adjustEndSpecsForPartialInsert();
  628.          var3 = this.parseBuffer.size();
  629.       }
  630.  
  631.       DefaultStyledDocument.ElementSpec[] var4 = new DefaultStyledDocument.ElementSpec[var3];
  632.       this.parseBuffer.copyInto(var4);
  633.       if (var2 == 0 && this.insertTag == null && !this.insertAfterImplied) {
  634.          this.this$0.create(var4);
  635.       } else {
  636.          this.this$0.insert(this.offset, var4);
  637.       }
  638.  
  639.       this.parseBuffer.removeAllElements();
  640.       this.offset += this.this$0.getLength() - var2;
  641.       ++this.flushCount;
  642.    }
  643.  
  644.    private void adjustEndSpecsForPartialInsert() {
  645.       int var1 = this.parseBuffer.size();
  646.       if (this.insertTagDepthDelta < 0) {
  647.          for(int var2 = this.insertTagDepthDelta; var2 < 0 && var1 >= 0 && ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(var1 - 1)).getType() == 2; ++var2) {
  648.             --var1;
  649.             this.parseBuffer.removeElementAt(var1);
  650.          }
  651.       }
  652.  
  653.       if (this.flushCount == 0 && (!this.insertAfterImplied || !this.wantsTrailingNewline)) {
  654.          int var6 = 0;
  655.          if (this.pushDepth > 0 && ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(0)).getType() == 3) {
  656.             ++var6;
  657.          }
  658.  
  659.          var6 += this.popDepth + this.pushDepth;
  660.          int var3 = 0;
  661.  
  662.          int var4;
  663.          for(var4 = var6; var6 < var1 && ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(var6)).getType() == 3; ++var3) {
  664.             ++var6;
  665.          }
  666.  
  667.          if (var3 > 1) {
  668.             while(var6 < var1 && ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(var6)).getType() == 2) {
  669.                ++var6;
  670.             }
  671.  
  672.             if (var6 == var1) {
  673.                char[] var5 = ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(var4 + var3 - 1)).getArray();
  674.                if (var5.length == 1 && var5[0] == HTMLDocument.access$000()[0]) {
  675.                   var6 = var4 + var3 - 1;
  676.  
  677.                   while(var1 > var6) {
  678.                      --var1;
  679.                      this.parseBuffer.removeElementAt(var1);
  680.                   }
  681.                }
  682.             }
  683.          }
  684.       }
  685.  
  686.    }
  687.  
  688.    void addCSSRules(String var1) {
  689.       StyleSheet var2 = this.this$0.getStyleSheet();
  690.       var2.addRule(var1);
  691.    }
  692.  
  693.    void linkCSSStyleSheet(String var1) {
  694.       Object var2 = null;
  695.  
  696.       try {
  697.          var7 = new URL(this.this$0.base, var1);
  698.       } catch (MalformedURLException var6) {
  699.          try {
  700.             var7 = new URL(var1);
  701.          } catch (MalformedURLException var5) {
  702.             var7 = null;
  703.          }
  704.       }
  705.  
  706.       if (var7 != null) {
  707.          this.this$0.getStyleSheet().importStyleSheet(var7);
  708.       }
  709.  
  710.    }
  711.  
  712.    private boolean canInsertTag(HTML.Tag var1, AttributeSet var2, boolean var3) {
  713.       if (!this.foundInsertTag) {
  714.          if (this.insertTag != null && !this.isInsertTag(var1) || this.insertAfterImplied && (var2 == null || var2.isDefined(ParserCallback.IMPLIED))) {
  715.             return false;
  716.          }
  717.  
  718.          this.foundInsertTag(var3);
  719.          if (!this.insertInsertTag) {
  720.             return false;
  721.          }
  722.       }
  723.  
  724.       return true;
  725.    }
  726.  
  727.    private boolean isInsertTag(HTML.Tag var1) {
  728.       return this.insertTag == var1;
  729.    }
  730.  
  731.    private void foundInsertTag(boolean var1) {
  732.       this.foundInsertTag = true;
  733.       if (!this.insertAfterImplied && (this.popDepth > 0 || this.pushDepth > 0)) {
  734.          try {
  735.             if (this.offset == 0 || !this.this$0.getText(this.offset - 1, 1).equals("\n")) {
  736.                SimpleAttributeSet var2 = null;
  737.                boolean var3 = true;
  738.                if (this.offset != 0) {
  739.                   Element var4 = this.this$0.getCharacterElement(this.offset - 1);
  740.                   AttributeSet var5 = var4.getAttributes();
  741.                   if (var5.isDefined(StyleConstants.ComposedTextAttribute)) {
  742.                      var3 = false;
  743.                   } else {
  744.                      Object var6 = var5.getAttribute(StyleConstants.NameAttribute);
  745.                      if (var6 instanceof HTML.Tag) {
  746.                         HTML.Tag var7 = (HTML.Tag)var6;
  747.                         if (var7 == Tag.IMG || var7 == Tag.HR || var7 == Tag.COMMENT || var7 instanceof HTML.UnknownTag) {
  748.                            var3 = false;
  749.                         }
  750.                      }
  751.                   }
  752.                }
  753.  
  754.                if (!var3) {
  755.                   var2 = new SimpleAttributeSet();
  756.                   ((SimpleAttributeSet)var2).addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
  757.                }
  758.  
  759.                DefaultStyledDocument.ElementSpec var11 = new DefaultStyledDocument.ElementSpec(var2, (short)3, HTMLDocument.access$000(), 0, HTMLDocument.access$000().length);
  760.                if (var3) {
  761.                   var11.setDirection((short)4);
  762.                }
  763.  
  764.                this.parseBuffer.addElement(var11);
  765.             }
  766.          } catch (BadLocationException var8) {
  767.          }
  768.       }
  769.  
  770.       for(int var9 = 0; var9 < this.popDepth; ++var9) {
  771.          this.parseBuffer.addElement(new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2));
  772.       }
  773.  
  774.       for(int var10 = 0; var10 < this.pushDepth; ++var10) {
  775.          DefaultStyledDocument.ElementSpec var12 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)1);
  776.          var12.setDirection((short)5);
  777.          this.parseBuffer.addElement(var12);
  778.       }
  779.  
  780.       this.insertTagDepthDelta = this.depthTo(Math.max(0, this.offset - 1)) - this.popDepth + this.pushDepth - this.inBlock;
  781.       if (var1) {
  782.          ++this.insertTagDepthDelta;
  783.       } else {
  784.          --this.insertTagDepthDelta;
  785.       }
  786.  
  787.    }
  788.  
  789.    // $FF: synthetic method
  790.    static HTMLDocument access$100(HTMLDocument$HTMLReader var0) {
  791.       return var0.this$0;
  792.    }
  793.  
  794.    // $FF: synthetic method
  795.    static boolean access$200(HTMLDocument$HTMLReader var0) {
  796.       return var0.insertAfterImplied;
  797.    }
  798.  
  799.    // $FF: synthetic method
  800.    static boolean access$300(HTMLDocument$HTMLReader var0, HTML.Tag var1, AttributeSet var2, boolean var3) {
  801.       return var0.canInsertTag(var1, var2, var3);
  802.    }
  803. }
  804.