home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.text.html;
-
- import java.util.Hashtable;
- import java.util.Stack;
- import java.util.Vector;
- import javax.swing.text.AbstractDocument;
- import javax.swing.text.AttributeSet;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.DefaultStyledDocument;
- 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;
-
- public class HTMLDocument$HTMLReader extends HTMLEditorKit.ParserCallback {
- // $FF: synthetic field
- private final HTMLDocument this$0;
- int threshold;
- int offset;
- int tableCount;
- boolean inParagraph;
- boolean impliedP;
- boolean inPre;
- boolean inTextArea;
- TextAreaDocument textAreaDocument;
- boolean inTitle;
- boolean lastWasNewline;
- boolean emptyAnchor;
- HTML.Tag insertTag;
- boolean foundInsertTag;
- int popDepth;
- int pushDepth;
- Option option;
- protected Vector parseBuffer;
- protected MutableAttributeSet charAttr;
- Stack charAttrStack;
- Hashtable tagMap;
- int inBlock;
-
- 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.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.parseBuffer = new Vector();
- this.charAttr = new SimpleAttributeSet();
- this.charAttrStack = new Stack();
- this.inBlock = 0;
- this.offset = var2;
- this.tableCount = 0;
- this.threshold = var1.getTokenThreshold();
- this.tagMap = new Hashtable(57);
- new HTMLDocument.HTMLReader.TagAction(this);
- HTMLDocument.HTMLReader.BlockAction var7 = new HTMLDocument.HTMLReader.BlockAction(this);
- HTMLDocument.HTMLReader.ParagraphAction var8 = new HTMLDocument.HTMLReader.ParagraphAction(this);
- HTMLDocument.HTMLReader.CharacterAction var9 = new HTMLDocument.HTMLReader.CharacterAction(this);
- HTMLDocument.HTMLReader.SpecialAction var10 = new HTMLDocument.HTMLReader.SpecialAction(this);
- HTMLDocument.HTMLReader.FormAction var11 = new HTMLDocument.HTMLReader.FormAction(this);
- HTMLDocument.HTMLReader.HiddenAction var12 = new HTMLDocument.HTMLReader.HiddenAction(this);
- this.tagMap.put(Tag.A, new HTMLDocument.HTMLReader.AnchorAction(this));
- this.tagMap.put(Tag.ADDRESS, var9);
- this.tagMap.put(Tag.APPLET, var12);
- this.tagMap.put(Tag.AREA, var12);
- this.tagMap.put(Tag.B, var9);
- this.tagMap.put(Tag.BASE, new HTMLDocument.HTMLReader.BaseAction(this));
- this.tagMap.put(Tag.BASEFONT, var9);
- this.tagMap.put(Tag.BIG, var9);
- this.tagMap.put(Tag.BLOCKQUOTE, var7);
- this.tagMap.put(Tag.BODY, var7);
- this.tagMap.put(Tag.BR, var10);
- this.tagMap.put(Tag.CAPTION, var7);
- this.tagMap.put(Tag.CENTER, var7);
- this.tagMap.put(Tag.CITE, var9);
- this.tagMap.put(Tag.CODE, var9);
- this.tagMap.put(Tag.DD, var7);
- this.tagMap.put(Tag.DFN, var9);
- this.tagMap.put(Tag.DIR, var7);
- this.tagMap.put(Tag.DIV, var7);
- this.tagMap.put(Tag.DL, var7);
- this.tagMap.put(Tag.DT, var8);
- this.tagMap.put(Tag.EM, var9);
- this.tagMap.put(Tag.FONT, var9);
- this.tagMap.put(Tag.FORM, var9);
- this.tagMap.put(Tag.FRAME, var10);
- this.tagMap.put(Tag.FRAMESET, var7);
- this.tagMap.put(Tag.H1, var8);
- this.tagMap.put(Tag.H2, var8);
- this.tagMap.put(Tag.H3, var8);
- this.tagMap.put(Tag.H4, var8);
- this.tagMap.put(Tag.H5, var8);
- this.tagMap.put(Tag.H6, var8);
- this.tagMap.put(Tag.HEAD, var12);
- this.tagMap.put(Tag.HR, var10);
- this.tagMap.put(Tag.HTML, var7);
- this.tagMap.put(Tag.I, var9);
- this.tagMap.put(Tag.IMG, var10);
- this.tagMap.put(Tag.INPUT, var11);
- this.tagMap.put(Tag.ISINDEX, new HTMLDocument.HTMLReader.IsindexAction(this));
- this.tagMap.put(Tag.KBD, var9);
- this.tagMap.put(Tag.LI, var7);
- this.tagMap.put(Tag.LINK, var12);
- this.tagMap.put(Tag.MAP, var12);
- this.tagMap.put(Tag.MENU, var7);
- this.tagMap.put(Tag.META, var12);
- this.tagMap.put(Tag.NOFRAMES, var7);
- this.tagMap.put(Tag.OBJECT, var10);
- this.tagMap.put(Tag.OL, var7);
- this.tagMap.put(Tag.OPTION, var11);
- this.tagMap.put(Tag.P, var8);
- 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, var9);
- this.tagMap.put(Tag.SCRIPT, var12);
- this.tagMap.put(Tag.SELECT, var11);
- this.tagMap.put(Tag.SMALL, var9);
- this.tagMap.put(Tag.STRIKE, var9);
- this.tagMap.put(Tag.S, var9);
- this.tagMap.put(Tag.STRONG, var9);
- this.tagMap.put(Tag.STYLE, var12);
- this.tagMap.put(Tag.SUB, var9);
- this.tagMap.put(Tag.SUP, var9);
- this.tagMap.put(Tag.TABLE, var7);
- this.tagMap.put(Tag.TD, var7);
- this.tagMap.put(Tag.TEXTAREA, var11);
- this.tagMap.put(Tag.TH, var7);
- this.tagMap.put(Tag.TITLE, new HTMLDocument.HTMLReader.TitleAction(this));
- this.tagMap.put(Tag.TR, var7);
- this.tagMap.put(Tag.TT, var9);
- this.tagMap.put(Tag.U, var9);
- this.tagMap.put(Tag.UL, var7);
- this.tagMap.put(Tag.VAR, var9);
- ((AbstractDocument)var1).putProperty("AdditionalComments", (Object)null);
- if (var5 != null) {
- this.insertTag = var5;
- this.popDepth = var3;
- this.pushDepth = var4;
- this.foundInsertTag = false;
- } else {
- this.foundInsertTag = true;
- }
-
- }
-
- // $FF: synthetic method
- static HTMLDocument access$0(HTMLDocument$HTMLReader var0) {
- return var0.this$0;
- }
-
- 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.tableCount == 0 && this.parseBuffer.size() > this.threshold) {
- try {
- this.flushBuffer();
- } catch (BadLocationException var7) {
- }
- }
-
- if (var3 > 0) {
- this.lastWasNewline = var1[var2 + var3 - 1] == '\n';
- }
-
- }
- }
-
- protected void addSpecialElement(HTML.Tag var1, MutableAttributeSet var2) {
- if (!this.foundInsertTag) {
- if (!this.isInsertTag(var1)) {
- return;
- }
-
- this.foundInsertTag();
- }
-
- if (var1 != Tag.FRAME && var1 != Tag.HR && !this.inParagraph && !this.inPre) {
- this.blockOpen(Tag.IMPLIED, new SimpleAttributeSet());
- this.inParagraph = true;
- this.impliedP = true;
- }
-
- 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;
- }
-
- }
-
- protected void blockClose(HTML.Tag var1) {
- if (this.foundInsertTag) {
- if (!this.lastWasNewline) {
- this.addContent(HTMLDocument.access$0(), 0, 1, this.insertTag != null);
- this.lastWasNewline = true;
- }
-
- if (this.impliedP) {
- this.impliedP = false;
- this.inParagraph = false;
- this.blockClose(Tag.IMPLIED);
- }
-
- --this.inBlock;
- 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);
- if (var1 == Tag.TABLE) {
- --this.tableCount;
- }
-
- }
- }
-
- protected void blockOpen(HTML.Tag var1, MutableAttributeSet var2) {
- if (var1 == Tag.TABLE) {
- ++this.tableCount;
- }
-
- if (this.impliedP) {
- this.impliedP = false;
- this.inParagraph = false;
- this.blockClose(Tag.IMPLIED);
- }
-
- ++this.inBlock;
- if (!this.foundInsertTag) {
- if (!this.isInsertTag(var1)) {
- return;
- }
-
- this.foundInsertTag();
- }
-
- this.lastWasNewline = false;
- var2.addAttribute(StyleConstants.NameAttribute, var1);
- DefaultStyledDocument.ElementSpec var3 = new DefaultStyledDocument.ElementSpec(var2.copyAttributes(), (short)1);
- this.parseBuffer.addElement(var3);
- }
-
- public void flush() throws BadLocationException {
- this.flushBuffer();
- }
-
- void flushBuffer() throws BadLocationException {
- int var1 = this.this$0.getLength();
- DefaultStyledDocument.ElementSpec[] var2 = new DefaultStyledDocument.ElementSpec[this.parseBuffer.size()];
- this.parseBuffer.copyInto(var2);
- if (var1 == 0 && this.insertTag == null) {
- this.this$0.create(var2);
- } else {
- this.this$0.insert(this.offset, var2);
- }
-
- this.parseBuffer.removeAllElements();
- this.offset += this.this$0.getLength() - var1;
- }
-
- private void foundInsertTag() {
- this.foundInsertTag = true;
- if (this.popDepth > 0 || this.pushDepth > 0) {
- try {
- if (this.offset > 0 && !this.this$0.getText(this.offset - 1, 1).equals("\n")) {
- DefaultStyledDocument.ElementSpec var1 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)3, HTMLDocument.access$0(), 0, HTMLDocument.access$0().length);
- var1.setDirection((short)4);
- this.parseBuffer.addElement(var1);
- }
- } catch (BadLocationException var4) {
- }
- }
-
- for(int var5 = 0; var5 < this.popDepth; ++var5) {
- this.parseBuffer.addElement(new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)2));
- }
-
- for(int var2 = 0; var2 < this.pushDepth; ++var2) {
- DefaultStyledDocument.ElementSpec var3 = new DefaultStyledDocument.ElementSpec((AttributeSet)null, (short)1);
- var3.setDirection((short)5);
- this.parseBuffer.addElement(var3);
- }
-
- }
-
- public void handleComment(char[] var1, int var2) {
- 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) {
- 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) {
- HTMLDocument.HTMLReader.TagAction var4 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
- if (var4 != null) {
- var4.start(var1, var2);
- var4.end(var1);
- } else if (this.this$0.getPreservesUnknownTags()) {
- this.addSpecialElement(var1, var2);
- }
-
- }
-
- public void handleStartTag(HTML.Tag var1, MutableAttributeSet var2, int var3) {
- HTMLDocument.HTMLReader.TagAction var4 = (HTMLDocument.HTMLReader.TagAction)this.tagMap.get(var1);
- if (var4 != null) {
- var4.start(var1, var2);
- }
-
- }
-
- public void handleText(char[] var1, int var2) {
- 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.inBlock > 0 && var1.length >= 1) {
- this.addContent(var1, 0, var1.length);
- }
-
- }
-
- private boolean isInsertTag(HTML.Tag var1) {
- return this.insertTag == var1 || var1 == Tag.IMPLIED && var1 == Tag.P;
- }
-
- protected void popCharacterStyle() {
- if (!this.charAttrStack.empty()) {
- this.charAttr = (MutableAttributeSet)this.charAttrStack.peek();
- this.charAttrStack.pop();
- }
-
- }
-
- 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 pushCharacterStyle() {
- this.charAttrStack.push(this.charAttr.copyAttributes());
- }
-
- protected void registerTag(HTML.Tag var1, HTMLDocument.HTMLReader.TagAction var2) {
- this.tagMap.put(var1, var2);
- }
-
- protected void textAreaContent(char[] var1) {
- try {
- this.textAreaDocument.insertString(this.textAreaDocument.getLength(), new String(var1), (AttributeSet)null);
- } catch (BadLocationException var2) {
- }
-
- }
- }
-