home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.text.html.parser;
-
- import java.io.CharArrayReader;
- import java.io.IOException;
- import java.io.InterruptedIOException;
- import java.io.Reader;
- import java.util.Enumeration;
- import java.util.Vector;
- import javax.swing.text.ChangedCharSetException;
- import javax.swing.text.SimpleAttributeSet;
- import javax.swing.text.html.HTML;
- import javax.swing.text.html.HTML.Attribute;
-
- public class Parser implements DTDConstants {
- private char[] text = new char[1024];
- private int textpos = 0;
- private TagElement last;
- private boolean space;
- private char[] str = new char[128];
- private int strpos = 0;
- protected DTD dtd = null;
- // $FF: renamed from: ch int
- private int field_0;
- // $FF: renamed from: ln int
- private int field_1;
- // $FF: renamed from: in java.io.Reader
- private Reader field_2;
- private Element recent;
- private TagStack stack;
- private boolean skipTag = false;
- private TagElement lastFormSent = null;
- private SimpleAttributeSet attributes = new SimpleAttributeSet();
- private boolean seenHtml = false;
- private boolean seenHead = false;
- private boolean seenBody = false;
- protected boolean strict = false;
- private int crlfCount;
- private int crCount;
- private int lfCount;
- private char[] buf = new char[256];
- private int pos;
- private int len;
- private int currentPosition;
-
- public Parser(DTD var1) {
- this.dtd = var1;
- }
-
- void addString(int var1) {
- if (this.strpos == this.str.length) {
- char[] var2 = new char[this.str.length + 128];
- System.arraycopy(this.str, 0, var2, 0, this.str.length);
- this.str = var2;
- }
-
- this.str[this.strpos++] = (char)var1;
- }
-
- protected void endTag(boolean var1) {
- this.handleText(this.stack.tag);
- if (var1 && !this.stack.elem.omitEnd()) {
- this.error("end.missing", this.stack.elem.getName());
- } else if (!this.stack.terminate()) {
- this.error("end.unexpected", this.stack.elem.getName());
- }
-
- this.handleEndTag(this.stack.tag);
- this.stack = this.stack.next;
- this.recent = this.stack != null ? this.stack.elem : null;
- }
-
- protected void error(String var1) {
- this.error(var1, "?", "?", "?");
- }
-
- protected void error(String var1, String var2) {
- this.error(var1, var2, "?", "?");
- }
-
- protected void error(String var1, String var2, String var3) {
- this.error(var1, var2, var3, "?");
- }
-
- protected void error(String var1, String var2, String var3, String var4) {
- this.handleError(this.field_1, var1 + var2 + var3 + var4);
- }
-
- void errorContext() throws ChangedCharSetException {
- while(this.stack != null && this.stack.tag.getElement() != this.dtd.body) {
- this.handleEndTag(this.stack.tag);
- this.stack = this.stack.next;
- }
-
- if (this.stack == null) {
- this.legalElementContext(this.dtd.body);
- this.startTag(this.makeTag(this.dtd.body, true));
- }
-
- }
-
- protected void flushAttributes() {
- this.attributes.removeAttributes(this.attributes);
- }
-
- protected SimpleAttributeSet getAttributes() {
- return this.attributes;
- }
-
- char[] getChars(int var1) {
- char[] var2 = new char[this.strpos - var1];
- System.arraycopy(this.str, var1, var2, 0, this.strpos - var1);
- this.strpos = var1;
- return var2;
- }
-
- char[] getChars(int var1, int var2) {
- char[] var3 = new char[var2 - var1];
- System.arraycopy(this.str, var1, var3, 0, var2 - var1);
- return var3;
- }
-
- protected int getCurrentLine() {
- return this.field_1;
- }
-
- protected int getCurrentPos() {
- return this.currentPosition;
- }
-
- String getEndOfLineString() {
- if (this.crlfCount >= this.crCount) {
- return this.lfCount >= this.crlfCount ? "\n" : "\r\n";
- } else {
- return this.crCount > this.lfCount ? "\r" : "\n";
- }
- }
-
- String getString(int var1) {
- char[] var2 = new char[this.strpos - var1];
- System.arraycopy(this.str, var1, var2, 0, this.strpos - var1);
- this.strpos = var1;
- return new String(var2);
- }
-
- protected void handleComment(char[] var1) {
- }
-
- protected void handleEOFInComment() {
- int var1 = this.strIndexOf('\n');
- if (var1 >= 0) {
- this.handleComment(this.getChars(0, var1));
-
- try {
- this.field_2.close();
- this.field_2 = new CharArrayReader(this.getChars(var1 + 1));
- this.field_0 = 62;
- } catch (IOException var2) {
- this.error("ioexception");
- }
-
- this.resetStrBuffer();
- } else {
- this.error("eof.comment");
- }
-
- }
-
- protected void handleEmptyTag(TagElement var1) throws ChangedCharSetException {
- }
-
- protected void handleEndTag(TagElement var1) {
- }
-
- protected void handleError(int var1, String var2) {
- Thread.dumpStack();
- System.out.println("**** " + this.stack);
- System.out.println("line " + var1 + ": error: " + var2);
- System.out.println();
- }
-
- protected void handleStartTag(TagElement var1) {
- }
-
- void handleText(TagElement var1) {
- if (var1.breaksFlow()) {
- this.space = false;
- }
-
- if (this.textpos != 0 || this.space && this.stack != null && !this.last.breaksFlow() && this.stack.advance(this.dtd.pcdata)) {
- if (this.space) {
- if (this.textpos + 1 > this.text.length) {
- char[] var2 = new char[this.text.length + 200];
- System.arraycopy(this.text, 0, var2, 0, this.text.length);
- this.text = var2;
- }
-
- this.text[this.textpos++] = ' ';
- this.space = false;
- }
-
- char[] var3 = new char[this.textpos];
- System.arraycopy(this.text, 0, var3, 0, this.textpos);
- if (var1.getElement().getName().equals("title")) {
- this.handleTitle(var3);
- } else {
- this.handleText(var3);
- }
-
- this.textpos = 0;
- this.last = var1;
- this.space = false;
- } else {
- this.last = var1;
- this.space = false;
- }
- }
-
- protected void handleText(char[] var1) {
- }
-
- protected void handleTitle(char[] var1) {
- this.handleText(var1);
- }
-
- boolean ignoreElement(Element var1) {
- String var2 = this.stack.elem.getName();
- String var3 = var1.getName();
- if ((!var3.equals("html") || !this.seenHtml) && (!var3.equals("head") || !this.seenHead) && (!var3.equals("body") || !this.seenBody)) {
- if (var3.equals("dt") || var3.equals("dd")) {
- TagStack var4;
- for(var4 = this.stack; var4 != null && !var4.elem.getName().equals("dl"); var4 = var4.next) {
- }
-
- if (var4 == null) {
- return true;
- }
- }
-
- return var2.equals("table") && !var3.equals("#pcdata") && !var3.equals("input") || var3.equals("font") && (var2.equals("ul") || var2.equals("ol")) || var3.equals("meta") && this.stack != null || var3.equals("style") || var2.equals("table") && var3.equals("a");
- } else {
- return true;
- }
- }
-
- boolean legalElementContext(Element var1) throws ChangedCharSetException {
- if (this.stack == null) {
- if (var1 != this.dtd.html) {
- this.startTag(this.makeTag(this.dtd.html, true));
- return this.legalElementContext(var1);
- } else {
- return true;
- }
- } else if (this.stack.advance(var1)) {
- this.markFirstTime(var1);
- return true;
- } else {
- boolean var2 = false;
- String var3 = this.stack.elem.getName();
- String var4 = var1.getName();
- if (!this.strict && (var3.equals("table") && var4.equals("td") || var3.equals("table") && var4.equals("th") || var3.equals("tr") && !var4.equals("tr"))) {
- var2 = true;
- }
-
- if (!this.strict && !var2 && (this.stack.elem.getName() != var1.getName() || var1.getName().equals("body")) && (this.skipTag = this.ignoreElement(var1))) {
- this.error("tag.ignore", var1.getName());
- return this.skipTag;
- } else if (!this.strict && var3.equals("table") && !var4.equals("tr") && !var4.equals("td") && !var4.equals("th") && !var4.equals("caption")) {
- Element var15 = this.dtd.getElement("tr");
- TagElement var17 = this.makeTag(var15, true);
- this.legalTagContext(var17);
- this.startTag(var17);
- this.error("start.missing", var1.getName());
- return this.legalElementContext(var1);
- } else {
- if (!var2 && this.stack.terminate() && (!this.strict || this.stack.elem.omitEnd())) {
- for(TagStack var5 = this.stack.next; var5 != null; var5 = var5.next) {
- if (var5.advance(var1)) {
- while(this.stack != var5) {
- this.endTag(true);
- }
-
- return true;
- }
-
- if (!var5.terminate() || this.strict && !var5.elem.omitEnd()) {
- break;
- }
- }
- }
-
- Element var14 = this.stack.first();
- if (var14 == null || this.strict && !var14.omitStart() || var14 == this.dtd.head && var1 == this.dtd.pcdata) {
- if (!this.strict) {
- ContentModel var16 = this.stack.contentModel();
- Vector var7 = new Vector();
- if (var16 != null) {
- var16.getElements(var7);
- Enumeration var8 = var7.elements();
-
- while(var8.hasMoreElements()) {
- Element var9 = (Element)var8.nextElement();
- if (!this.stack.excluded(var9.getIndex())) {
- boolean var10 = false;
-
- for(AttributeList var11 = var9.getAttributes(); var11 != null; var11 = var11.next) {
- if (var11.modifier == 2) {
- var10 = true;
- break;
- }
- }
-
- if (!var10) {
- ContentModel var12 = var9.getContent();
- if (var12 != null && var12.first(var1)) {
- TagElement var13 = this.makeTag(var9, true);
- this.legalTagContext(var13);
- this.startTag(var13);
- this.error("start.missing", var9.getName());
- return this.legalElementContext(var1);
- }
- }
- }
- }
- }
- }
-
- if (this.stack.terminate() && this.stack.elem != this.dtd.body && (!this.strict || this.stack.elem.omitEnd())) {
- if (!this.stack.elem.omitEnd()) {
- this.error("end.missing", var1.getName());
- }
-
- this.endTag(true);
- return this.legalElementContext(var1);
- } else {
- return false;
- }
- } else {
- TagElement var6 = this.makeTag(var14, true);
- this.legalTagContext(var6);
- this.startTag(var6);
- if (!var14.omitStart()) {
- this.error("start.missing", var1.getName());
- }
-
- return this.legalElementContext(var1);
- }
- }
- }
- }
-
- void legalTagContext(TagElement var1) throws ChangedCharSetException {
- if (this.legalElementContext(var1.getElement())) {
- this.markFirstTime(var1.getElement());
- } else if (var1.breaksFlow() && this.stack != null && !this.stack.tag.breaksFlow()) {
- this.endTag(true);
- this.legalTagContext(var1);
- } else {
- for(TagStack var2 = this.stack; var2 != null; var2 = var2.next) {
- if (var2.tag.getElement() == this.dtd.head) {
- while(this.stack != var2) {
- this.endTag(true);
- }
-
- this.endTag(true);
- this.legalTagContext(var1);
- return;
- }
- }
-
- this.error("tag.unexpected", var1.getElement().getName());
- }
- }
-
- protected TagElement makeTag(Element var1) {
- return this.makeTag(var1, false);
- }
-
- protected TagElement makeTag(Element var1, boolean var2) {
- return new TagElement(var1, var2);
- }
-
- protected void markFirstTime(Element var1) {
- String var2 = var1.getName();
- if (var2.equals("html")) {
- this.seenHtml = true;
- } else if (var2.equals("head")) {
- this.seenHead = true;
- } else if (var2.equals("body")) {
- this.seenBody = true;
- }
-
- }
-
- public synchronized void parse(Reader var1) throws IOException {
- this.field_2 = var1;
- this.field_1 = 1;
- this.seenHtml = false;
- this.seenHead = false;
- this.seenBody = false;
- this.crCount = this.lfCount = this.crlfCount = 0;
-
- try {
- try {
- this.field_0 = this.readCh();
- this.text = new char[1024];
- this.str = new char[128];
- this.parseContent();
-
- while(this.stack != null) {
- this.endTag(true);
- }
- } finally {
- var1.close();
- }
- } catch (IOException var17) {
- this.errorContext();
- this.error("ioexception");
- throw var17;
- } catch (Exception var18) {
- this.errorContext();
- this.error("exception", var18.getClass().getName(), ((Throwable)var18).getMessage());
- ((Throwable)var18).printStackTrace();
- } catch (ThreadDeath var19) {
- this.errorContext();
- this.error("terminated");
- ((Throwable)var19).printStackTrace();
- throw var19;
- } finally {
- while(this.stack != null) {
- this.handleEndTag(this.stack.tag);
- this.stack = this.stack.next;
- }
-
- this.text = null;
- this.str = null;
- }
-
- }
-
- void parseAttributeSpecificationList(Element var1) throws IOException {
- while(true) {
- this.skipSpace();
- switch (this.field_0) {
- case -1:
- case 47:
- case 60:
- case 62:
- return;
- case 45:
- if ((this.field_0 = this.readCh()) == 45) {
- this.field_0 = this.readCh();
- this.parseComment();
- this.strpos = 0;
- break;
- }
-
- this.error("invalid.tagchar", "-", var1.getName());
- this.field_0 = this.readCh();
- break;
- default:
- Object var2 = null;
- Object var3 = null;
- Object var4 = null;
- AttributeList var6;
- String var7;
- String var8;
- if (this.parseIdentifier(true)) {
- var7 = this.getString(0);
- this.skipSpace();
- if (this.field_0 == 61) {
- this.field_0 = this.readCh();
- this.skipSpace();
- var6 = var1.getAttribute(var7);
- var8 = this.parseAttributeValue(var6 != null && var6.type != 1 && var6.type != 11 && var6.type != 7);
- } else {
- var8 = var7;
- var6 = var1.getAttributeByValue(var7);
- if (var6 == null) {
- var6 = var1.getAttribute(var7);
- if (var6 != null) {
- var8 = var6.getValue();
- }
- }
- }
- } else {
- if (!this.strict && this.field_0 == 44) {
- this.field_0 = this.readCh();
- continue;
- }
-
- if (!this.strict && this.field_0 == 34) {
- this.field_0 = this.readCh();
- this.skipSpace();
- if (!this.parseIdentifier(true)) {
- char[] var10 = new char[]{(char)this.field_0};
- this.error("invalid.tagchar", new String(var10), var1.getName());
- this.field_0 = this.readCh();
- continue;
- }
-
- var7 = this.getString(0);
- if (this.field_0 == 34) {
- this.field_0 = this.readCh();
- }
-
- this.skipSpace();
- if (this.field_0 == 61) {
- this.field_0 = this.readCh();
- this.skipSpace();
- var6 = var1.getAttribute(var7);
- var8 = this.parseAttributeValue(var6 != null && var6.type != 1 && var6.type != 11);
- } else {
- var8 = var7;
- var6 = var1.getAttributeByValue(var7);
- if (var6 == null) {
- var6 = var1.getAttribute(var7);
- if (var6 != null) {
- var8 = var6.getValue();
- }
- }
- }
- } else {
- if (this.strict || !this.attributes.isEmpty() || this.field_0 != 61) {
- if (!this.strict && this.field_0 == 61) {
- this.field_0 = this.readCh();
- this.skipSpace();
- var8 = this.parseAttributeValue(true);
- this.error("attvalerr");
- return;
- }
-
- char[] var5 = new char[]{(char)this.field_0};
- this.error("invalid.tagchar", new String(var5), var1.getName());
- if (this.strict) {
- return;
- }
-
- this.field_0 = this.readCh();
- continue;
- }
-
- this.field_0 = this.readCh();
- this.skipSpace();
- var7 = var1.getName();
- var6 = var1.getAttribute(var7);
- var8 = this.parseAttributeValue(var6 != null && var6.type != 1 && var6.type != 11);
- }
- }
-
- if (var6 != null) {
- var7 = var6.getName();
- } else {
- this.error("invalid.tagatt", var7, var1.getName());
- }
-
- if (this.attributes.isDefined(var7)) {
- this.error("multi.tagatt", var7, var1.getName());
- }
-
- if (var8 == null) {
- var8 = var6 != null && var6.value != null ? var6.value : "#DEFAULT";
- } else if (var6 != null && var6.values != null && !var6.values.contains(var8)) {
- this.error("invalid.tagattval", var7, var1.getName());
- }
-
- HTML.Attribute var11 = HTML.getAttributeKey(var7);
- if (var11 == null) {
- this.attributes.addAttribute(var7, var8);
- } else {
- this.attributes.addAttribute(var11, var8);
- }
- }
- }
- }
-
- String parseAttributeValue(boolean var1) throws IOException {
- int var2 = -1;
- switch (this.field_0) {
- case 34:
- case 39:
- var2 = this.field_0;
- this.field_0 = this.readCh();
- case 35:
- case 36:
- case 37:
- case 38:
- }
-
- label96:
- while(true) {
- int var3 = this.field_0;
- switch (var3) {
- case -1:
- return this.getString(0);
- case 9:
- if (var2 < 0) {
- var3 = 32;
- }
- case 32:
- this.field_0 = this.readCh();
- if (var2 < 0) {
- return this.getString(0);
- }
- break;
- case 10:
- ++this.field_1;
- this.field_0 = this.readCh();
- ++this.lfCount;
- if (var2 < 0) {
- return this.getString(0);
- }
- break;
- case 13:
- ++this.field_1;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- } else {
- ++this.crCount;
- }
-
- if (var2 < 0) {
- return this.getString(0);
- }
- break;
- case 34:
- case 39:
- this.field_0 = this.readCh();
- if (var3 == var2) {
- return this.getString(0);
- }
-
- if (var2 == -1) {
- this.error("attvalerr");
- if (!this.strict && this.field_0 != 32) {
- continue;
- }
-
- return this.getString(0);
- }
- break;
- case 38:
- if (this.strict && var2 < 0) {
- this.field_0 = this.readCh();
- break;
- }
-
- char[] var4 = this.parseEntityReference();
- int var5 = 0;
-
- while(true) {
- if (var5 >= var4.length) {
- continue label96;
- }
-
- var3 = var4[var5];
- this.addString(var1 && var3 >= 65 && var3 <= 90 ? 97 + var3 - 65 : var3);
- ++var5;
- }
- case 60:
- case 62:
- if (var2 < 0) {
- return this.getString(0);
- }
-
- this.field_0 = this.readCh();
- break;
- case 61:
- if (var2 < 0) {
- this.error("attvalerr");
- if (this.strict) {
- return this.getString(0);
- }
- }
-
- this.field_0 = this.readCh();
- break;
- default:
- if (var1 && var3 >= 65 && var3 <= 90) {
- var3 = 97 + var3 - 65;
- }
-
- this.field_0 = this.readCh();
- }
-
- this.addString(var3);
- }
- }
-
- void parseComment() throws IOException {
- while(true) {
- int var1 = this.field_0;
- switch (var1) {
- case -1:
- this.handleEOFInComment();
- return;
- case 10:
- ++this.field_1;
- this.field_0 = this.readCh();
- ++this.lfCount;
- break;
- case 13:
- ++this.field_1;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- } else {
- ++this.crCount;
- }
-
- var1 = 10;
- break;
- case 45:
- if (!this.strict && this.strpos != 0 && this.str[this.strpos - 1] == '-') {
- if ((this.field_0 = this.readCh()) == 62) {
- return;
- }
-
- if (this.field_0 == 33) {
- if ((this.field_0 = this.readCh()) == 62) {
- return;
- }
-
- this.addString(45);
- this.addString(33);
- continue;
- }
- } else if ((this.field_0 = this.readCh()) == 45) {
- this.field_0 = this.readCh();
- if (this.strict || this.field_0 == 62) {
- return;
- }
-
- if (this.field_0 == 33) {
- if ((this.field_0 = this.readCh()) == 62) {
- return;
- }
-
- this.addString(45);
- this.addString(33);
- continue;
- } else {
- this.addString(45);
- }
- }
- break;
- case 62:
- this.field_0 = this.readCh();
- break;
- default:
- this.field_0 = this.readCh();
- }
-
- this.addString(var1);
- }
- }
-
- void parseContent() throws IOException {
- Thread var1 = Thread.currentThread();
-
- while(!var1.isInterrupted()) {
- int var2 = this.field_0;
- switch (var2) {
- case -1:
- return;
- case 9:
- case 32:
- this.field_0 = this.readCh();
- if (this.stack == null || !this.stack.pre) {
- this.space = true;
- continue;
- }
- break;
- case 10:
- ++this.field_1;
- ++this.lfCount;
- this.field_0 = this.readCh();
- if (this.stack == null || !this.stack.pre) {
- this.space = true;
- continue;
- }
- break;
- case 13:
- ++this.field_1;
- var2 = 10;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- } else {
- ++this.crCount;
- }
-
- if (this.stack == null || !this.stack.pre) {
- this.space = true;
- continue;
- }
- break;
- case 38:
- if (this.textpos == 0) {
- if (!this.legalElementContext(this.dtd.pcdata)) {
- this.error("unexpected.pcdata");
- }
-
- if (this.last.breaksFlow()) {
- this.space = false;
- }
- }
-
- char[] var3 = this.parseEntityReference();
- if (this.textpos + var3.length + 1 > this.text.length) {
- char[] var4 = new char[Math.max(this.textpos + var3.length + 128, this.text.length * 2)];
- System.arraycopy(this.text, 0, var4, 0, this.text.length);
- this.text = var4;
- }
-
- if (this.space) {
- this.space = false;
- this.text[this.textpos++] = ' ';
- }
-
- System.arraycopy(var3, 0, this.text, this.textpos, var3.length);
- this.textpos += var3.length;
- continue;
- case 47:
- this.field_0 = this.readCh();
- if (this.stack != null && this.stack.net) {
- this.endTag(false);
- continue;
- }
- break;
- case 60:
- this.parseTag();
- continue;
- default:
- if (this.textpos == 0) {
- if (!this.legalElementContext(this.dtd.pcdata)) {
- this.error("unexpected.pcdata");
- }
-
- if (this.last.breaksFlow()) {
- this.space = false;
- }
- }
-
- this.field_0 = this.readCh();
- }
-
- if (this.textpos + 2 > this.text.length) {
- char[] var5 = new char[this.text.length + 128];
- System.arraycopy(this.text, 0, var5, 0, this.text.length);
- this.text = var5;
- }
-
- if (this.space) {
- this.text[this.textpos++] = ' ';
- this.space = false;
- }
-
- this.text[this.textpos++] = (char)var2;
- }
-
- var1.interrupt();
- }
-
- public String parseDTDMarkup() throws IOException {
- StringBuffer var1 = new StringBuffer();
- this.field_0 = this.readCh();
-
- while(true) {
- switch (this.field_0) {
- case -1:
- this.error("invalid.markup");
- return var1.toString();
- case 10:
- ++this.field_1;
- this.field_0 = this.readCh();
- ++this.lfCount;
- break;
- case 13:
- ++this.field_1;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- } else {
- ++this.crCount;
- }
- break;
- case 34:
- this.field_0 = this.readCh();
- break;
- case 62:
- this.field_0 = this.readCh();
- return var1.toString();
- default:
- var1.append((char)(this.field_0 & 255));
- this.field_0 = this.readCh();
- }
- }
- }
-
- private char[] parseEntityReference() throws IOException {
- int var1 = this.strpos;
- if ((this.field_0 = this.readCh()) == 35) {
- int var2 = 0;
- this.field_0 = this.readCh();
- if (this.field_0 >= 48 && this.field_0 <= 57) {
- while(this.field_0 >= 48 && this.field_0 <= 57) {
- var2 = var2 * 10 + this.field_0 - 48;
- this.field_0 = this.readCh();
- }
-
- switch (this.field_0) {
- case 10:
- ++this.field_1;
- this.field_0 = this.readCh();
- ++this.lfCount;
- break;
- case 13:
- ++this.field_1;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- } else {
- ++this.crCount;
- }
- break;
- case 59:
- this.field_0 = this.readCh();
- }
-
- char[] var8 = new char[]{(char)var2};
- return var8;
- }
-
- this.addString(35);
- if (!this.parseIdentifier(false)) {
- this.error("ident.expected");
- this.strpos = var1;
- char[] var3 = new char[]{'&', '#'};
- return var3;
- }
- } else if (!this.parseIdentifier(false)) {
- char[] var7 = new char[]{'&'};
- return var7;
- }
-
- switch (this.field_0) {
- case 10:
- ++this.field_1;
- this.field_0 = this.readCh();
- ++this.lfCount;
- break;
- case 13:
- ++this.field_1;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- } else {
- ++this.crCount;
- }
- break;
- case 59:
- this.field_0 = this.readCh();
- }
-
- String var6 = this.getString(var1);
- Entity var9 = this.dtd.getEntity(var6);
- if (!this.strict && var9 == null) {
- var9 = this.dtd.getEntity(var6.toLowerCase());
- }
-
- if (var9 != null && var9.isGeneral()) {
- return var9.getData();
- } else if (var6.length() == 0) {
- this.error("invalid.entref", var6);
- return new char[0];
- } else {
- String var4 = "&" + var6;
- char[] var5 = new char[var4.length()];
- var4.getChars(0, var5.length, var5, 0);
- return var5;
- }
- }
-
- boolean parseIdentifier(boolean var1) throws IOException {
- switch (this.field_0) {
- case 65:
- case 66:
- case 67:
- case 68:
- case 69:
- case 70:
- case 71:
- case 72:
- case 73:
- case 74:
- case 75:
- case 76:
- case 77:
- case 78:
- case 79:
- case 80:
- case 81:
- case 82:
- case 83:
- case 84:
- case 85:
- case 86:
- case 87:
- case 88:
- case 89:
- case 90:
- if (var1) {
- this.field_0 = 97 + (this.field_0 - 65);
- }
- break;
- case 91:
- case 92:
- case 93:
- case 94:
- case 95:
- case 96:
- default:
- return false;
- case 97:
- case 98:
- case 99:
- case 100:
- case 101:
- case 102:
- case 103:
- case 104:
- case 105:
- case 106:
- case 107:
- case 108:
- case 109:
- case 110:
- case 111:
- case 112:
- case 113:
- case 114:
- case 115:
- case 116:
- case 117:
- case 118:
- case 119:
- case 120:
- case 121:
- case 122:
- }
-
- while(true) {
- this.addString(this.field_0);
- switch (this.field_0 = this.readCh()) {
- case 45:
- case 46:
- case 48:
- case 49:
- case 50:
- case 51:
- case 52:
- case 53:
- case 54:
- case 55:
- case 56:
- case 57:
- case 95:
- case 97:
- case 98:
- case 99:
- case 100:
- case 101:
- case 102:
- case 103:
- case 104:
- case 105:
- case 106:
- case 107:
- case 108:
- case 109:
- case 110:
- case 111:
- case 112:
- case 113:
- case 114:
- case 115:
- case 116:
- case 117:
- case 118:
- case 119:
- case 120:
- case 121:
- case 122:
- break;
- case 47:
- case 58:
- case 59:
- case 60:
- case 61:
- case 62:
- case 63:
- case 64:
- case 91:
- case 92:
- case 93:
- case 94:
- case 96:
- default:
- return true;
- case 65:
- case 66:
- case 67:
- case 68:
- case 69:
- case 70:
- case 71:
- case 72:
- case 73:
- case 74:
- case 75:
- case 76:
- case 77:
- case 78:
- case 79:
- case 80:
- case 81:
- case 82:
- case 83:
- case 84:
- case 85:
- case 86:
- case 87:
- case 88:
- case 89:
- case 90:
- if (var1) {
- this.field_0 = 97 + (this.field_0 - 65);
- }
- }
- }
- }
-
- void parseInvalidTag() throws IOException {
- while(true) {
- this.skipSpace();
- switch (this.field_0) {
- case -1:
- case 62:
- this.field_0 = this.readCh();
- return;
- case 60:
- return;
- default:
- this.field_0 = this.readCh();
- }
- }
- }
-
- void parseLiteral(boolean var1) throws IOException {
- while(true) {
- int var2 = this.field_0;
- switch (var2) {
- case -1:
- this.error("eof.literal", this.stack.elem.getName());
- this.endTag(true);
- return;
- case 10:
- ++this.field_1;
- this.field_0 = this.readCh();
- ++this.lfCount;
- break;
- case 13:
- ++this.field_1;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- } else {
- ++this.crCount;
- }
-
- var2 = 10;
- break;
- case 38:
- char[] var5 = this.parseEntityReference();
- if (this.textpos + var5.length > this.text.length) {
- char[] var6 = new char[Math.max(this.textpos + var5.length + 128, this.text.length * 2)];
- System.arraycopy(this.text, 0, var6, 0, this.text.length);
- this.text = var6;
- }
-
- System.arraycopy(var5, 0, this.text, this.textpos, var5.length);
- this.textpos += var5.length;
- continue;
- case 62:
- this.field_0 = this.readCh();
- int var3 = this.textpos - (this.stack.elem.name.length() + 2);
- int var4 = 0;
- if (var3 >= 0 && this.text[var3++] == '<' && this.text[var3] == '/') {
- do {
- ++var3;
- } while(var3 < this.textpos && Character.toLowerCase(this.text[var3]) == this.stack.elem.name.charAt(var4++));
-
- if (var3 == this.textpos) {
- this.textpos -= this.stack.elem.name.length() + 2;
- if (this.textpos > 0 && this.text[this.textpos - 1] == '\n') {
- --this.textpos;
- }
-
- this.endTag(false);
- return;
- }
- }
- break;
- default:
- this.field_0 = this.readCh();
- }
-
- if (this.textpos == this.text.length) {
- char[] var8 = new char[this.text.length + 128];
- System.arraycopy(this.text, 0, var8, 0, this.text.length);
- this.text = var8;
- }
-
- this.text[this.textpos++] = (char)var2;
- }
- }
-
- protected boolean parseMarkupDeclarations(StringBuffer var1) throws IOException {
- if (var1.length() == "DOCTYPE".length() && var1.toString().toUpperCase().equals("DOCTYPE")) {
- this.parseDTDMarkup();
- return true;
- } else {
- return false;
- }
- }
-
- void parseTag() throws IOException {
- Object var1 = null;
- boolean var2 = false;
- boolean var3 = false;
- boolean var4 = false;
- switch (this.field_0 = this.readCh()) {
- case -1:
- this.error("eof");
- return;
- case 33:
- switch (this.field_0 = this.readCh()) {
- case 45:
- while(true) {
- if (this.field_0 == 45) {
- if (!this.strict || (this.field_0 = this.readCh()) == 45) {
- this.field_0 = this.readCh();
- if (!this.strict && this.field_0 == 45) {
- this.field_0 = this.readCh();
- }
-
- if (this.textpos != 0) {
- char[] var13 = new char[this.textpos];
- System.arraycopy(this.text, 0, var13, 0, this.textpos);
- this.handleText(var13);
- this.textpos = 0;
- }
-
- this.parseComment();
- this.handleComment(this.getChars(0));
- continue;
- }
-
- if (!var3) {
- var3 = true;
- this.error("invalid.commentchar", "-");
- }
- }
-
- this.skipSpace();
- switch (this.field_0) {
- case 45:
- break;
- case 62:
- this.field_0 = this.readCh();
- case -1:
- return;
- default:
- this.field_0 = this.readCh();
- if (!var3) {
- var3 = true;
- this.error("invalid.commentchar", String.valueOf((char)this.field_0));
- }
- }
- }
- default:
- StringBuffer var14 = new StringBuffer();
-
- while(true) {
- var14.append((char)this.field_0);
- if (this.parseMarkupDeclarations(var14)) {
- return;
- }
-
- switch (this.field_0) {
- case 10:
- ++this.field_1;
- this.field_0 = this.readCh();
- ++this.lfCount;
- break;
- case 13:
- ++this.field_1;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- } else {
- ++this.crCount;
- }
- break;
- case 62:
- this.field_0 = this.readCh();
- case -1:
- this.error("invalid.markup");
- return;
- default:
- this.field_0 = this.readCh();
- }
- }
- }
- case 47:
- Element var7;
- switch (this.field_0 = this.readCh()) {
- case 61:
- default:
- if (!this.parseIdentifier(true)) {
- this.error("expected.endtagname");
- return;
- }
-
- this.skipSpace();
- switch (this.field_0) {
- case 60:
- break;
- case 61:
- default:
- this.error("expected", "'>'");
-
- while(this.field_0 != -1 && this.field_0 != 10 && this.field_0 != 62) {
- this.field_0 = this.readCh();
- }
-
- if (this.field_0 == 62) {
- this.field_0 = this.readCh();
- }
- break;
- case 62:
- this.field_0 = this.readCh();
- }
-
- String var5 = this.getString(0);
- if (!this.dtd.elementExists(var5)) {
- this.error("end.unrecognized", var5);
- if (this.textpos > 0 && this.text[this.textpos - 1] == '\n') {
- --this.textpos;
- }
-
- var7 = this.dtd.getElement("unknown");
- var7.name = var5;
- var4 = true;
- } else {
- var7 = this.dtd.getElement(var5);
- }
- break;
- case 62:
- this.field_0 = this.readCh();
- case 60:
- if (this.recent == null) {
- this.error("invalid.shortend");
- return;
- }
-
- var7 = this.recent;
- }
-
- if (this.stack == null) {
- this.error("end.extra.tag", var7.getName());
- return;
- } else {
- if (this.textpos > 0 && this.text[this.textpos - 1] == '\n') {
- if (this.stack.pre) {
- if (this.textpos > 1 && this.text[this.textpos - 2] != '\n') {
- --this.textpos;
- }
- } else {
- --this.textpos;
- }
- }
-
- if (!this.strict && var7.getName().equals("form")) {
- if (this.lastFormSent != null) {
- this.handleEndTag(this.lastFormSent);
- return;
- }
-
- return;
- } else if (var4) {
- TagElement var12 = this.makeTag(var7);
- this.handleText(var12);
- this.attributes.addAttribute(Attribute.ENDTAG, "true");
- this.handleEmptyTag(this.makeTag(var7));
- var4 = false;
- return;
- } else {
- if (!this.strict) {
- String var10 = this.stack.elem.getName();
- if (var10.equals("table") && !var7.getName().equals(var10)) {
- this.error("tag.ignore", var7.getName());
- return;
- }
-
- if ((var10.equals("tr") || var10.equals("td")) && !var7.getName().equals("table") && !var7.getName().equals(var10)) {
- this.error("tag.ignore", var7.getName());
- return;
- }
- }
-
- TagStack var11;
- for(var11 = this.stack; var11 != null && var7 != var11.elem; var11 = var11.next) {
- }
-
- if (var11 == null) {
- this.error("unmatched.endtag", var7.getName());
- return;
- } else {
- String var6 = var7.getName();
- if (this.stack == var11 || !var6.equals("font") && !var6.equals("center")) {
- while(this.stack != var11) {
- this.endTag(true);
- }
-
- this.endTag(false);
- return;
- }
-
- if (var6.equals("center")) {
- while(this.stack.elem.omitEnd() && this.stack != var11) {
- this.endTag(true);
- }
-
- if (this.stack.elem == var7) {
- this.endTag(false);
- }
- }
-
- return;
- }
- }
- }
- default:
- Element var8;
- if (!this.parseIdentifier(true)) {
- var8 = this.recent;
- if (this.field_0 != 62 || var8 == null) {
- this.error("expected.tagname");
- return;
- }
- } else {
- String var15 = this.getString(0);
- if (var15.equals("image")) {
- var15 = new String("img");
- }
-
- if (!this.dtd.elementExists(var15)) {
- this.error("tag.unrecognized ", var15);
- var8 = this.dtd.getElement("unknown");
- var8.name = var15;
- var4 = true;
- } else {
- var8 = this.dtd.getElement(var15);
- }
- }
-
- this.parseAttributeSpecificationList(var8);
- switch (this.field_0) {
- case 47:
- var2 = true;
- case 62:
- this.field_0 = this.readCh();
- case 60:
- break;
- default:
- this.error("expected", "'>'");
- }
-
- if (!this.strict && var8.getName().equals("script")) {
- this.error("javascript.unsupported");
- }
-
- if (!var8.isEmpty()) {
- if (this.field_0 == 10) {
- ++this.field_1;
- ++this.lfCount;
- this.field_0 = this.readCh();
- } else if (this.field_0 == 13) {
- ++this.field_1;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- } else {
- ++this.crCount;
- }
- }
- }
-
- TagElement var16 = this.makeTag(var8, false);
- if (!this.strict && var8.getName().equals("form")) {
- if (this.lastFormSent == null) {
- this.lastFormSent = var16;
- } else {
- this.handleEndTag(this.lastFormSent);
- this.lastFormSent = var16;
- }
- } else if (!var4) {
- this.legalTagContext(var16);
- if (!this.strict && this.skipTag) {
- this.skipTag = false;
- return;
- }
- }
-
- this.startTag(var16);
- if (!var8.isEmpty()) {
- switch (var8.getType()) {
- case 1:
- this.parseLiteral(false);
- break;
- case 16:
- this.parseLiteral(true);
- break;
- default:
- if (this.stack != null) {
- this.stack.net = var2;
- }
- }
- }
-
- }
- }
-
- private final int readCh() throws IOException {
- if (this.pos >= this.len) {
- try {
- this.len = this.field_2.read(this.buf);
- } catch (InterruptedIOException var2) {
- throw var2;
- }
-
- if (this.len <= 0) {
- return -1;
- }
-
- this.pos = 0;
- }
-
- ++this.currentPosition;
- return this.buf[this.pos++];
- }
-
- void resetStrBuffer() {
- this.strpos = 0;
- }
-
- void skipSpace() throws IOException {
- while(true) {
- switch (this.field_0) {
- case 9:
- case 32:
- this.field_0 = this.readCh();
- break;
- case 10:
- ++this.field_1;
- this.field_0 = this.readCh();
- ++this.lfCount;
- break;
- case 13:
- ++this.field_1;
- if ((this.field_0 = this.readCh()) == 10) {
- this.field_0 = this.readCh();
- ++this.crlfCount;
- break;
- }
-
- ++this.crCount;
- break;
- default:
- return;
- }
- }
- }
-
- protected void startTag(TagElement var1) throws ChangedCharSetException {
- Element var2 = var1.getElement();
- if (var2.isEmpty() && this.textpos == 0) {
- this.last = var1;
- } else {
- this.handleText(var1);
- }
-
- for(AttributeList var3 = var2.atts; var3 != null; var3 = var3.next) {
- if (var3.modifier == 2 && (this.attributes.isEmpty() || !this.attributes.isDefined(var3.name))) {
- this.error("req.att ", var3.getName(), var2.getName());
- }
- }
-
- if (var2.isEmpty()) {
- this.handleEmptyTag(var1);
- } else if (var2.getName().equals("form")) {
- this.handleStartTag(var1);
- } else {
- this.recent = var2;
- this.stack = new TagStack(var1, this.stack);
- this.handleStartTag(var1);
- }
-
- }
-
- int strIndexOf(char var1) {
- for(int var2 = 0; var2 < this.strpos; ++var2) {
- if (this.str[var2] == var1) {
- return var2;
- }
- }
-
- return -1;
- }
- }
-