home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.text.html;
-
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Hashtable;
- import java.util.Stack;
- import java.util.Vector;
- import javax.swing.event.UndoableEditEvent;
- import javax.swing.event.DocumentEvent.EventType;
- import javax.swing.text.AbstractDocument;
- import javax.swing.text.AttributeSet;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.DefaultStyledDocument;
- import javax.swing.text.Element;
- import javax.swing.text.MutableAttributeSet;
- import javax.swing.text.SimpleAttributeSet;
- import javax.swing.text.StyleConstants;
- import javax.swing.text.html.HTML.Attribute;
- import javax.swing.text.html.HTML.Tag;
- import javax.swing.text.html.HTMLEditorKit.ParserCallback;
- import javax.swing.undo.CompoundEdit;
-
- public class HTMLDocument$HTMLReader extends HTMLEditorKit.ParserCallback {
- private int flushCount;
- private boolean insertAfterImplied;
- private boolean wantsTrailingNewline;
- int threshold;
- int offset;
- boolean inParagraph;
- boolean impliedP;
- boolean inPre;
- boolean inTextArea;
- TextAreaDocument textAreaDocument;
- boolean inTitle;
- boolean lastWasNewline;
- boolean emptyAnchor;
- boolean midInsert;
- boolean inBody;
- HTML.Tag insertTag;
- boolean insertInsertTag;
- boolean foundInsertTag;
- int insertTagDepthDelta;
- int popDepth;
- int pushDepth;
- Map lastMap;
- boolean inStyle;
- String defaultStyle;
- Vector styles;
- boolean inHead;
- boolean isStyleCSS;
- boolean emptyDocument;
- AttributeSet styleAttributes;
- Option option;
- protected Vector parseBuffer;
- protected MutableAttributeSet charAttr;
- Stack charAttrStack;
- Hashtable tagMap;
- int inBlock;
- // $FF: synthetic field
- private final HTMLDocument this$0;
-
- public HTMLDocument$HTMLReader(HTMLDocument var1, int var2) {
- this(var1, var2, 0, 0, (HTML.Tag)null);
- }
-
- public HTMLDocument$HTMLReader(HTMLDocument var1, int var2, int var3, int var4, HTML.Tag var5) {
- this(var1, var2, var3, var4, var5, true, false, true);
- }
-
- HTMLDocument$HTMLReader(HTMLDocument var1, int var2, int var3, int var4, HTML.Tag var5, boolean var6, boolean var7, boolean var8) {
- this.this$0 = var1;
- this.inParagraph = false;
- this.impliedP = false;
- this.inPre = false;
- this.inTextArea = false;
- this.textAreaDocument = null;
- this.inTitle = false;
- this.lastWasNewline = true;
- this.inStyle = false;
- this.inHead = false;
- this.parseBuffer = new Vector();
- this.charAttr = new SimpleAttributeSet();
- this.charAttrStack = new Stack();
- this.inBlock = 0;
- this.emptyDocument = ((AbstractDocument)var1).getLength() == 0;
- this.isStyleCSS = "text/css".equals(var1.getDefaultStyleSheetType());
- this.offset = var2;
- this.threshold = var1.getTokenThreshold();
- this.tagMap = new Hashtable(57);
- new HTMLDocument.HTMLReader.TagAction(this);
- HTMLDocument.HTMLReader.BlockAction var10 = new HTMLDocument.HTMLReader.BlockAction(this);
- HTMLDocument.HTMLReader.ParagraphAction var11 = new HTMLDocument.HTMLReader.ParagraphAction(this);
- HTMLDocument.HTMLReader.CharacterAction var12 = new HTMLDocument.HTMLReader.CharacterAction(this);
- HTMLDocument.HTMLReader.SpecialAction var13 = new HTMLDocument.HTMLReader.SpecialAction(this);
- HTMLDocument.HTMLReader.FormAction var14 = new HTMLDocument.HTMLReader.FormAction(this);
- HTMLDocument.HTMLReader.HiddenAction var15 = new HTMLDocument.HTMLReader.HiddenAction(this);
- HTMLDocument.HTMLReader.ConvertAction var16 = new HTMLDocument.HTMLReader.ConvertAction(this);
- this.tagMap.put(Tag.A, new HTMLDocument.HTMLReader.AnchorAction(this));
- this.tagMap.put(Tag.ADDRESS, var12);
- this.tagMap.put(Tag.APPLET, var15);
- this.tagMap.put(Tag.AREA, new HTMLDocument.HTMLReader.AreaAction(this));
- this.tagMap.put(Tag.B, var16);
- this.tagMap.put(Tag.BASE, new HTMLDocument.HTMLReader.BaseAction(this));
- this.tagMap.put(Tag.BASEFONT, var12);
- this.tagMap.put(Tag.BIG, var12);
- this.tagMap.put(Tag.BLOCKQUOTE, var10);
- this.tagMap.put(Tag.BODY, var10);
- this.tagMap.put(Tag.BR, var13);
- this.tagMap.put(Tag.CAPTION, var10);
- this.tagMap.put(Tag.CENTER, var10);
- this.tagMap.put(Tag.CITE, var12);
- this.tagMap.put(Tag.CODE, var12);
- this.tagMap.put(Tag.DD, var10);
- this.tagMap.put(Tag.DFN, var12);
- this.tagMap.put(Tag.DIR, var10);
- this.tagMap.put(Tag.DIV, var10);
- this.tagMap.put(Tag.DL, var10);
- this.tagMap.put(Tag.DT, var11);
- this.tagMap.put(Tag.EM, var12);
- this.tagMap.put(Tag.FONT, var16);
- this.tagMap.put(Tag.FORM, var12);
- this.tagMap.put(Tag.FRAME, var13);
- this.tagMap.put(Tag.FRAMESET, var10);
- this.tagMap.put(Tag.H1, var11);
- this.tagMap.put(Tag.H2, var11);
- this.tagMap.put(Tag.H3, var11);
- this.tagMap.put(Tag.H4, var11);
- this.tagMap.put(Tag.H5, var11);
- this.tagMap.put(Tag.H6, var11);
- this.tagMap.put(Tag.HEAD, new HTMLDocument.HTMLReader.HeadAction(this));
- this.tagMap.put(Tag.HR, var13);
- this.tagMap.put(Tag.HTML, var10);
- this.tagMap.put(Tag.I, var16);
- this.tagMap.put(Tag.IMG, var13);
- this.tagMap.put(Tag.INPUT, var14);
- this.tagMap.put(Tag.ISINDEX, new HTMLDocument.HTMLReader.IsindexAction(this));
- this.tagMap.put(Tag.KBD, var12);
- this.tagMap.put(Tag.LI, var10);
- this.tagMap.put(Tag.LINK, new HTMLDocument.HTMLReader.LinkAction(this));
- this.tagMap.put(Tag.MAP, new HTMLDocument.HTMLReader.MapAction(this));
- this.tagMap.put(Tag.MENU, var10);
- this.tagMap.put(Tag.META, new HTMLDocument.HTMLReader.MetaAction(this));
- this.tagMap.put(Tag.NOBR, var12);
- this.tagMap.put(Tag.NOFRAMES, var10);
- this.tagMap.put(Tag.OBJECT, var13);
- this.tagMap.put(Tag.OL, var10);
- this.tagMap.put(Tag.OPTION, var14);
- this.tagMap.put(Tag.P, var11);
- this.tagMap.put(Tag.PARAM, new HTMLDocument.HTMLReader.ObjectAction(this));
- this.tagMap.put(Tag.PRE, new HTMLDocument.HTMLReader.PreAction(this));
- this.tagMap.put(Tag.SAMP, var12);
- this.tagMap.put(Tag.SCRIPT, var15);
- this.tagMap.put(Tag.SELECT, var14);
- this.tagMap.put(Tag.SMALL, var12);
- this.tagMap.put(Tag.STRIKE, var16);
- this.tagMap.put(Tag.S, var12);
- this.tagMap.put(Tag.STRONG, var12);
- this.tagMap.put(Tag.STYLE, new HTMLDocument.HTMLReader.StyleAction(this));
- this.tagMap.put(Tag.SUB, var16);
- this.tagMap.put(Tag.SUP, var16);
- this.tagMap.put(Tag.TABLE, var10);
- this.tagMap.put(Tag.TD, var10);
- this.tagMap.put(Tag.TEXTAREA, var14);
- this.tagMap.put(Tag.TH, var10);
- this.tagMap.put(Tag.TITLE, new HTMLDocument.HTMLReader.TitleAction(this));
- this.tagMap.put(Tag.TR, var10);
- this.tagMap.put(Tag.TT, var12);
- this.tagMap.put(Tag.U, var16);
- this.tagMap.put(Tag.UL, var10);
- this.tagMap.put(Tag.VAR, var12);
- ((AbstractDocument)var1).putProperty("AdditionalComments", (Object)null);
- if (var5 != null) {
- this.insertTag = var5;
- this.popDepth = var3;
- this.pushDepth = var4;
- this.insertInsertTag = var6;
- this.foundInsertTag = false;
- } else {
- this.foundInsertTag = true;
- }
-
- if (var7) {
- this.popDepth = var3;
- this.pushDepth = var4;
- this.insertAfterImplied = true;
- this.foundInsertTag = false;
- this.midInsert = false;
- this.insertInsertTag = true;
- this.wantsTrailingNewline = var8;
- } else {
- this.midInsert = !this.emptyDocument && var5 == null;
- if (this.midInsert) {
- this.generateEndsSpecsForMidInsert();
- }
- }
-
- }
-
- private void generateEndsSpecsForMidInsert() {
- int var1 = this.heightToElementWithName(Tag.BODY, Math.max(0, this.offset - 1));
- boolean var2 = false;
- if (var1 == -1 && this.offset > 0) {
- var1 = this.heightToElementWithName(Tag.BODY, this.offset);
- if (var1 != -1) {
- var1 = this.depthTo(this.offset - 1) - 1;
- var2 = true;
- }
- }
-
- if (var1 == -1) {
- throw new RuntimeException("Must insert new content into body element-");
- } else {
- if (var1 != -1) {
- try {
- if (!var2 && this.offset > 0 && !this.this$0.getText(this.offset - 1, 1).equals("\n")) {
- SimpleAttributeSet var3 = new SimpleAttributeSet();
- var3.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
- DefaultStyledDocument.ElementSpec var4 = new DefaultStyledDocument.ElementSpec(var3, (short)3, HTMLDocument.access$000(), 0, 1);
- this.parseBuffer.addElement(var4);
- }
- } catch (BadLocationException var5) {
- }
-
- while(var1-- > 0) {
- this.parseBuffer.addElement(new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2));
- }
-
- if (var2) {
- DefaultStyledDocument.ElementSpec var6 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)1);
- var6.setDirection((short)5);
- this.parseBuffer.addElement(var6);
- }
- }
-
- }
- }
-
- private int depthTo(int var1) {
- Element var2 = this.this$0.getDefaultRootElement();
-
- int var3;
- for(var3 = 0; !var2.isLeaf(); var2 = var2.getElement(var2.getElementIndex(var1))) {
- ++var3;
- }
-
- return var3;
- }
-
- private int heightToElementWithName(Object var1, int var2) {
- Element var3 = this.this$0.getCharacterElement(var2).getParentElement();
-
- int var4;
- for(var4 = 0; var3 != null && var3.getAttributes().getAttribute(StyleConstants.NameAttribute) != var1; var3 = var3.getParentElement()) {
- ++var4;
- }
-
- return var3 == null ? -1 : var4;
- }
-
- private void adjustEndElement() {
- int var1 = this.this$0.getLength();
- if (var1 != 0) {
- this.this$0.obtainLock();
-
- try {
- Element[] var2 = this.getPathTo(var1 - 1);
- if (var2.length > 1 && var2[1].getAttributes().getAttribute(StyleConstants.NameAttribute) == Tag.BODY && var2[1].getEndOffset() == var1) {
- String var3 = this.this$0.getText(var1 - 1, 1);
- Element[] var5 = new Element[0];
- Element[] var6 = new Element[1];
- int var7 = var2[0].getElementIndex(var1);
- var6[0] = var2[0].getElement(var7);
- ((AbstractDocument.BranchElement)var2[0]).replace(var7, 1, var5);
- AbstractDocument.ElementEdit var8 = new AbstractDocument.ElementEdit(var2[0], var7, var6, var5);
- AbstractDocument.DefaultDocumentEvent var4;
- if (var2.length == 3 && (var2[2].getAttributes().getAttribute(StyleConstants.NameAttribute) == Tag.P || var2[2].getAttributes().getAttribute(StyleConstants.NameAttribute) == Tag.IMPLIED) && !var3.equals("\n")) {
- var7 = var2[2].getElementIndex(var1 - 1);
- AttributeSet var27 = var2[2].getElement(var7).getAttributes();
- if (var27.getAttributeCount() == 1 && var27.getAttribute(StyleConstants.NameAttribute) == Tag.CONTENT) {
- var5 = new Element[1];
- var6 = new Element[]{var2[2].getElement(var7)};
- int var29 = var6[0].getStartOffset();
- var5[0] = this.this$0.createLeafElement(var2[2], var27, var29, var1 + 1);
- ((AbstractDocument.BranchElement)var2[2]).replace(var7, 1, var5);
- var4 = new AbstractDocument.DefaultDocumentEvent(this.this$0, var29, var1 - var29 + 1, EventType.CHANGE);
- var4.addEdit(new AbstractDocument.ElementEdit(var2[2], var7, var6, var5));
- } else {
- SimpleAttributeSet var28 = new SimpleAttributeSet();
- var28.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
- var5 = new Element[]{this.this$0.createLeafElement(var2[2], var28, var1, var1 + 1)};
- ((AbstractDocument.BranchElement)var2[2]).replace(var7 + 1, 0, var5);
- var4 = new AbstractDocument.DefaultDocumentEvent(this.this$0, var1, 1, EventType.CHANGE);
- var6 = new Element[0];
- var4.addEdit(new AbstractDocument.ElementEdit(var2[2], var7 + 1, var6, var5));
- }
- } else {
- SimpleAttributeSet var9 = new SimpleAttributeSet();
- var9.addAttribute(StyleConstants.NameAttribute, Tag.P);
- AbstractDocument.BranchElement var10 = (AbstractDocument.BranchElement)this.this$0.createBranchElement(var2[1], var9);
- var5 = new Element[]{var10};
- var6 = new Element[0];
- var7 = var2[1].getElementIndex(var1 - 1) + 1;
- ((AbstractDocument.BranchElement)var2[1]).replace(var7, 0, var5);
- var4 = new AbstractDocument.DefaultDocumentEvent(this.this$0, var1, 1, EventType.CHANGE);
- var4.addEdit(new AbstractDocument.ElementEdit(var2[1], var7, var6, var5));
- var5 = new Element[1];
- var9 = new SimpleAttributeSet();
- var9.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
- var5[0] = this.this$0.createLeafElement(var10, var9, var1, var1 + 1);
- var10.replace(0, 0, var5);
- }
-
- var4.addEdit(var8);
- ((CompoundEdit)var4).end();
- this.this$0.fireChangedUpdate(var4);
- this.this$0.fireUndoableEditUpdate(new UndoableEditEvent(this, var4));
- }
- } catch (BadLocationException var15) {
- } finally {
- this.this$0.releaseLock();
- }
-
- }
- }
-
- private Element[] getPathTo(int var1) {
- Stack var2 = new Stack();
-
- for(Element var3 = this.this$0.getDefaultRootElement(); !var3.isLeaf(); var3 = var3.getElement(var3.getElementIndex(var1))) {
- var2.push(var3);
- }
-
- Element[] var5 = new Element[((Vector)var2).size()];
- ((Vector)var2).copyInto(var5);
- return var5;
- }
-
- public void flush() throws BadLocationException {
- this.flushBuffer(true);
- if (this.emptyDocument && !this.insertAfterImplied) {
- this.adjustEndElement();
- }
-
- }
-
- public void handleText(char[] var1, int var2) {
- if (!this.midInsert || this.inBody) {
- if (this.inTextArea) {
- this.textAreaContent(var1);
- } else if (this.inPre) {
- this.preContent(var1);
- } else if (this.inTitle) {
- this.this$0.putProperty("title", new String(var1));
- } else if (this.option != null) {
- this.option.setLabel(new String(var1));
- } else if (this.inStyle) {
- if (this.styles != null) {
- this.styles.addElement(new String(var1));
- }
- } else if (this.inBlock > 0) {
- if (!this.foundInsertTag && this.insertAfterImplied) {
- this.foundInsertTag(false);
- this.foundInsertTag = true;
- this.inParagraph = this.impliedP = true;
- }
-
- if (var1.length >= 1) {
- this.addContent(var1, 0, var1.length);
- }
- }
-
- }
- }
-
- public void handleStartTag(HTML.Tag var1, MutableAttributeSet var2, int var3) {
- if (this.midInsert && !this.inBody) {
- if (var1 == Tag.BODY) {
- this.inBody = true;
- ++this.inBlock;
- }
-
- } else {
- if (!this.inBody && var1 == Tag.BODY) {
- this.inBody = true;
- }
-
- if (this.isStyleCSS && var2.isDefined(Attribute.STYLE)) {
- String var4 = (String)var2.getAttribute(Attribute.STYLE);
- var2.removeAttribute(Attribute.STYLE);
- this.styleAttributes = this.this$0.getStyleSheet().getDeclaration(var4);
- var2.addAttributes(this.styleAttributes);
- } else {
- this.styleAttributes = null;
- }
-
- HTMLDocument.HTMLReader.TagAction var5 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
- if (var5 != null) {
- var5.start(var1, var2);
- }
-
- }
- }
-
- public void handleComment(char[] var1, int var2) {
- if (this.inStyle) {
- if (this.styles != null) {
- this.styles.addElement(new String(var1));
- }
- } else if (this.this$0.getPreservesUnknownTags()) {
- if (this.inBlock == 0) {
- Object var4 = this.this$0.getProperty("AdditionalComments");
- if (var4 != null && !(var4 instanceof Vector)) {
- return;
- }
-
- if (var4 == null) {
- var4 = new Vector();
- this.this$0.putProperty("AdditionalComments", var4);
- }
-
- ((Vector)var4).addElement(new String(var1));
- return;
- }
-
- SimpleAttributeSet var3 = new SimpleAttributeSet();
- var3.addAttribute(Attribute.COMMENT, new String(var1));
- this.addSpecialElement(Tag.COMMENT, var3);
- }
-
- }
-
- public void handleEndTag(HTML.Tag var1, int var2) {
- if (!this.midInsert || this.inBody) {
- if (var1 == Tag.BODY) {
- this.inBody = false;
- if (this.midInsert) {
- --this.inBlock;
- }
- }
-
- HTMLDocument.HTMLReader.TagAction var3 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
- if (var3 != null) {
- var3.end(var1);
- }
-
- }
- }
-
- public void handleSimpleTag(HTML.Tag var1, MutableAttributeSet var2, int var3) {
- if (!this.midInsert || this.inBody) {
- if (this.isStyleCSS && var2.isDefined(Attribute.STYLE)) {
- String var4 = (String)var2.getAttribute(Attribute.STYLE);
- var2.removeAttribute(Attribute.STYLE);
- this.styleAttributes = this.this$0.getStyleSheet().getDeclaration(var4);
- var2.addAttributes(this.styleAttributes);
- } else {
- this.styleAttributes = null;
- }
-
- HTMLDocument.HTMLReader.TagAction var5 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
- if (var5 != null) {
- var5.start(var1, var2);
- var5.end(var1);
- } else if (this.this$0.getPreservesUnknownTags()) {
- this.addSpecialElement(var1, var2);
- }
-
- }
- }
-
- public void handleEndOfLineString(String var1) {
- if (this.emptyDocument && var1 != null) {
- this.this$0.putProperty("__EndOfLine__", var1);
- }
-
- }
-
- protected void registerTag(HTML.Tag var1, HTMLDocument.HTMLReader.TagAction var2) {
- this.tagMap.put(var1, var2);
- }
-
- protected void pushCharacterStyle() {
- this.charAttrStack.push(this.charAttr.copyAttributes());
- }
-
- protected void popCharacterStyle() {
- if (!this.charAttrStack.empty()) {
- this.charAttr = (MutableAttributeSet)this.charAttrStack.peek();
- this.charAttrStack.pop();
- }
-
- }
-
- protected void textAreaContent(char[] var1) {
- try {
- this.textAreaDocument.insertString(this.textAreaDocument.getLength(), new String(var1), (AttributeSet)null);
- } catch (BadLocationException var3) {
- }
-
- }
-
- protected void preContent(char[] var1) {
- int var2 = 0;
-
- for(int var3 = 0; var3 < var1.length; ++var3) {
- if (var1[var3] == '\n') {
- this.addContent(var1, var2, var3 - var2 + 1);
- this.blockClose(Tag.IMPLIED);
- SimpleAttributeSet var4 = new SimpleAttributeSet();
- var4.addAttribute(javax.swing.text.html.CSS.Attribute.WHITE_SPACE, "pre");
- this.blockOpen(Tag.IMPLIED, var4);
- var2 = var3 + 1;
- }
- }
-
- if (var2 < var1.length) {
- this.addContent(var1, var2, var1.length - var2);
- }
-
- }
-
- protected void blockOpen(HTML.Tag var1, MutableAttributeSet var2) {
- if (this.impliedP) {
- this.impliedP = false;
- this.inParagraph = false;
- this.blockClose(Tag.IMPLIED);
- }
-
- ++this.inBlock;
- if (this.canInsertTag(var1, var2, true)) {
- if (var2.isDefined(ParserCallback.IMPLIED)) {
- var2.removeAttribute(ParserCallback.IMPLIED);
- }
-
- this.lastWasNewline = false;
- var2.addAttribute(StyleConstants.NameAttribute, var1);
- DefaultStyledDocument.ElementSpec var3 = new DefaultStyledDocument.ElementSpec(var2.copyAttributes(), (short)1);
- this.parseBuffer.addElement(var3);
- }
- }
-
- protected void blockClose(HTML.Tag var1) {
- --this.inBlock;
- if (this.foundInsertTag) {
- if (!this.lastWasNewline) {
- this.addContent(HTMLDocument.access$000(), 0, 1, false);
- this.lastWasNewline = true;
- }
-
- if (this.impliedP) {
- this.impliedP = false;
- this.inParagraph = false;
- this.blockClose(Tag.IMPLIED);
- }
-
- DefaultStyledDocument.ElementSpec var2 = this.parseBuffer.size() > 0 ? (DefaultStyledDocument.ElementSpec)this.parseBuffer.lastElement() : null;
- if (var2 != null && var2.getType() == 1) {
- char[] var3 = new char[]{' '};
- this.addContent(var3, 0, 1);
- }
-
- DefaultStyledDocument.ElementSpec var4 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2);
- this.parseBuffer.addElement(var4);
- }
- }
-
- protected void addContent(char[] var1, int var2, int var3) {
- this.addContent(var1, var2, var3, true);
- }
-
- protected void addContent(char[] var1, int var2, int var3, boolean var4) {
- if (this.foundInsertTag) {
- if (var4 && !this.inParagraph && !this.inPre) {
- this.blockOpen(Tag.IMPLIED, new SimpleAttributeSet());
- this.inParagraph = true;
- this.impliedP = true;
- }
-
- this.emptyAnchor = false;
- this.charAttr.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
- AttributeSet var5 = this.charAttr.copyAttributes();
- DefaultStyledDocument.ElementSpec var6 = new DefaultStyledDocument.ElementSpec(var5, (short)3, var1, var2, var3);
- this.parseBuffer.addElement(var6);
- if (this.parseBuffer.size() > this.threshold) {
- try {
- this.flushBuffer(false);
- } catch (BadLocationException var8) {
- }
- }
-
- if (var3 > 0) {
- this.lastWasNewline = var1[var2 + var3 - 1] == '\n';
- }
-
- }
- }
-
- protected void addSpecialElement(HTML.Tag var1, MutableAttributeSet var2) {
- if (var1 != Tag.FRAME && !this.inParagraph && !this.inPre) {
- this.blockOpen(Tag.IMPLIED, new SimpleAttributeSet());
- this.inParagraph = true;
- this.impliedP = true;
- }
-
- if (this.canInsertTag(var1, var2, true)) {
- if (var2.isDefined(ParserCallback.IMPLIED)) {
- var2.removeAttribute(ParserCallback.IMPLIED);
- }
-
- this.emptyAnchor = false;
- var2.addAttributes(this.charAttr);
- var2.addAttribute(StyleConstants.NameAttribute, var1);
- char[] var3 = new char[]{' '};
- DefaultStyledDocument.ElementSpec var4 = new DefaultStyledDocument.ElementSpec(var2.copyAttributes(), (short)3, var3, 0, 1);
- this.parseBuffer.addElement(var4);
- if (var1 == Tag.FRAME) {
- this.lastWasNewline = true;
- }
-
- }
- }
-
- void flushBuffer(boolean var1) throws BadLocationException {
- int var2 = this.this$0.getLength();
- int var3 = this.parseBuffer.size();
- if (var1 && (this.insertTag != null || this.insertAfterImplied) && var3 > 0) {
- this.adjustEndSpecsForPartialInsert();
- var3 = this.parseBuffer.size();
- }
-
- DefaultStyledDocument.ElementSpec[] var4 = new DefaultStyledDocument.ElementSpec[var3];
- this.parseBuffer.copyInto(var4);
- if (var2 == 0 && this.insertTag == null && !this.insertAfterImplied) {
- this.this$0.create(var4);
- } else {
- this.this$0.insert(this.offset, var4);
- }
-
- this.parseBuffer.removeAllElements();
- this.offset += this.this$0.getLength() - var2;
- ++this.flushCount;
- }
-
- private void adjustEndSpecsForPartialInsert() {
- int var1 = this.parseBuffer.size();
- if (this.insertTagDepthDelta < 0) {
- for(int var2 = this.insertTagDepthDelta; var2 < 0 && var1 >= 0 && ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(var1 - 1)).getType() == 2; ++var2) {
- --var1;
- this.parseBuffer.removeElementAt(var1);
- }
- }
-
- if (this.flushCount == 0 && (!this.insertAfterImplied || !this.wantsTrailingNewline)) {
- int var6 = 0;
- if (this.pushDepth > 0 && ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(0)).getType() == 3) {
- ++var6;
- }
-
- var6 += this.popDepth + this.pushDepth;
- int var3 = 0;
-
- int var4;
- for(var4 = var6; var6 < var1 && ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(var6)).getType() == 3; ++var3) {
- ++var6;
- }
-
- if (var3 > 1) {
- while(var6 < var1 && ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(var6)).getType() == 2) {
- ++var6;
- }
-
- if (var6 == var1) {
- char[] var5 = ((DefaultStyledDocument.ElementSpec)this.parseBuffer.elementAt(var4 + var3 - 1)).getArray();
- if (var5.length == 1 && var5[0] == HTMLDocument.access$000()[0]) {
- var6 = var4 + var3 - 1;
-
- while(var1 > var6) {
- --var1;
- this.parseBuffer.removeElementAt(var1);
- }
- }
- }
- }
- }
-
- }
-
- void addCSSRules(String var1) {
- StyleSheet var2 = this.this$0.getStyleSheet();
- var2.addRule(var1);
- }
-
- void linkCSSStyleSheet(String var1) {
- Object var2 = null;
-
- try {
- var7 = new URL(this.this$0.base, var1);
- } catch (MalformedURLException var6) {
- try {
- var7 = new URL(var1);
- } catch (MalformedURLException var5) {
- var7 = null;
- }
- }
-
- if (var7 != null) {
- this.this$0.getStyleSheet().importStyleSheet(var7);
- }
-
- }
-
- private boolean canInsertTag(HTML.Tag var1, AttributeSet var2, boolean var3) {
- if (!this.foundInsertTag) {
- if (this.insertTag != null && !this.isInsertTag(var1) || this.insertAfterImplied && (var2 == null || var2.isDefined(ParserCallback.IMPLIED))) {
- return false;
- }
-
- this.foundInsertTag(var3);
- if (!this.insertInsertTag) {
- return false;
- }
- }
-
- return true;
- }
-
- private boolean isInsertTag(HTML.Tag var1) {
- return this.insertTag == var1;
- }
-
- private void foundInsertTag(boolean var1) {
- this.foundInsertTag = true;
- if (!this.insertAfterImplied && (this.popDepth > 0 || this.pushDepth > 0)) {
- try {
- if (this.offset == 0 || !this.this$0.getText(this.offset - 1, 1).equals("\n")) {
- SimpleAttributeSet var2 = null;
- boolean var3 = true;
- if (this.offset != 0) {
- Element var4 = this.this$0.getCharacterElement(this.offset - 1);
- AttributeSet var5 = var4.getAttributes();
- if (var5.isDefined(StyleConstants.ComposedTextAttribute)) {
- var3 = false;
- } else {
- Object var6 = var5.getAttribute(StyleConstants.NameAttribute);
- if (var6 instanceof HTML.Tag) {
- HTML.Tag var7 = (HTML.Tag)var6;
- if (var7 == Tag.IMG || var7 == Tag.HR || var7 == Tag.COMMENT || var7 instanceof HTML.UnknownTag) {
- var3 = false;
- }
- }
- }
- }
-
- if (!var3) {
- var2 = new SimpleAttributeSet();
- ((SimpleAttributeSet)var2).addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
- }
-
- DefaultStyledDocument.ElementSpec var11 = new DefaultStyledDocument.ElementSpec(var2, (short)3, HTMLDocument.access$000(), 0, HTMLDocument.access$000().length);
- if (var3) {
- var11.setDirection((short)4);
- }
-
- this.parseBuffer.addElement(var11);
- }
- } catch (BadLocationException var8) {
- }
- }
-
- for(int var9 = 0; var9 < this.popDepth; ++var9) {
- this.parseBuffer.addElement(new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2));
- }
-
- for(int var10 = 0; var10 < this.pushDepth; ++var10) {
- DefaultStyledDocument.ElementSpec var12 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)1);
- var12.setDirection((short)5);
- this.parseBuffer.addElement(var12);
- }
-
- this.insertTagDepthDelta = this.depthTo(Math.max(0, this.offset - 1)) - this.popDepth + this.pushDepth - this.inBlock;
- if (var1) {
- ++this.insertTagDepthDelta;
- } else {
- --this.insertTagDepthDelta;
- }
-
- }
-
- // $FF: synthetic method
- static HTMLDocument access$100(HTMLDocument$HTMLReader var0) {
- return var0.this$0;
- }
-
- // $FF: synthetic method
- static boolean access$200(HTMLDocument$HTMLReader var0) {
- return var0.insertAfterImplied;
- }
-
- // $FF: synthetic method
- static boolean access$300(HTMLDocument$HTMLReader var0, HTML.Tag var1, AttributeSet var2, boolean var3) {
- return var0.canInsertTag(var1, var2, var3);
- }
- }
-