📄 parser.java
字号:
break; case 'o': dtdnot(); // parse notation declaration break; default: panic(FAULT); // unsupported markup declaration break; } st = 1; // read the end of declaration break; default: panic(FAULT); break; } break; case '%': // A parameter entity reference pent(' '); break; case ']': // End of DTD internal subset st = -1; break; case ' ': // Skip white spaces break; default: panic(FAULT); } break; case 1: // read the end of declaration switch (ch) { case '>': // there is no notation st = 0; // skip white spaces before a declaration break; case ' ': case '\n': case '\r': case '\t': // Skip white spaces break; default: panic(FAULT); break; } break; default: panic(FAULT); } } } /** * Parses an entity declaration. * This method fills the general (<code>mEnt</code>) and parameter * (<code>mPEnt</code>) entity look up table. * * @exception SAXException * @exception IOException */ private void dtdent() throws SAXException, IOException { String str = null; char[] val = null; Input inp = null; Pair ids = null; char ch; for (short st = 0; st >= 0;) { ch = next(); switch (st) { case 0: // skip white spaces before entity name switch (chtyp(ch)) { case ' ': // Skip white spaces break; case '%': // Parameter entity or parameter entity declaration. ch = next(); back(); if (chtyp(ch) == ' ') { // Parameter entity declaration. wsskip(); str = name(false); switch (chtyp(wsskip())) { case 'A': // Read the external identifier ids = pubsys(' '); if (wsskip() == '>') { // External parsed entity inp = new Input(); inp.pubid = ids.name; inp.sysid = ids.value; mPEnt.put(str, inp); } else { panic(FAULT); } del(ids); st = -1; // the end of declaration break; case '\"': case '\'': // Read the parameter entity value bqstr('-'); // Create the parameter entity value val = new char[mBuffIdx + 1]; System.arraycopy(mBuff, 1, val, 1, val.length - 1); // Add surrounding spaces [#4.4.8] val[0] = ' '; // Add the entity to the entity look up table inp = new Input(val); inp.pubid = mInp.pubid; inp.sysid = mInp.sysid; mPEnt.put(str, inp); st = -1; // the end of declaration break; default: panic(FAULT); break; } } else { // Parameter entity reference. pent(' '); } break; default: back(); str = name(false); st = 1; // read entity declaration value break; } break; case 1: // read entity declaration value switch (chtyp(ch)) { case '\"': // internal entity case '\'': back(); bqstr('-'); // read a string into the buffer if (mEnt.get(str) == null) { // Create general entity value val = new char[mBuffIdx]; System.arraycopy(mBuff, 1, val, 0, val.length); // Add the entity to the entity look up table inp = new Input(val); inp.pubid = mInp.pubid; inp.sysid = mInp.sysid; mEnt.put(str, inp); } st = -1; // the end of declaration break; case 'A': // external entity back(); ids = pubsys(' '); switch (wsskip()) { case '>': // external parsed entity inp = new Input(); inp.pubid = ids.name; inp.sysid = ids.value; mEnt.put(str, inp); break; case 'N': // external general unparsed entity if ("NDATA".equals(name(false)) == true) { wsskip(); mHand.unparsedEntityDecl( str, ids.name, ids.value, name(false)); break; } default: panic(FAULT); break; } del(ids); st = -1; // the end of declaration break; case ' ': // Skip white spaces break; default: panic(FAULT); break; } break; default: panic(FAULT); } } } /** * Parses an element declaration. * * This method parses the declaration up to the closing angle * bracket. * * @exception SAXException * @exception IOException */ private void dtdelm() throws SAXException, IOException { // This is stub implementation which skips an element // declaration. wsskip(); name(mIsNSAware); char ch; while (true) { ch = next(); switch (ch) { case '>': back(); return; case EOS: panic(FAULT); default: break; } } } /** * Parses an attribute list declaration. * * This method parses the declaration up to the closing angle * bracket. * * @exception SAXException * @exception IOException */ private void dtdattl() throws SAXException, IOException { char elmqn[] = null; Pair elm = null; char ch; for (short st = 0; st >= 0;) { ch = next(); switch (st) { case 0: // read the element name switch (chtyp(ch)) { case 'a': case 'A': case '_': case 'X': case ':': back(); // Get the element from the list or add a new one. elmqn = qname(mIsNSAware); elm = find(mAttL, elmqn); if (elm == null) { elm = pair(mAttL); elm.chars = elmqn; mAttL = elm; } st = 1; // read an attribute declaration break; case ' ': break; case '%': pent(' '); break; default: panic(FAULT); break; } break; case 1: // read an attribute declaration switch (chtyp(ch)) { case 'a': case 'A': case '_': case 'X': case ':': back(); dtdatt(elm); if (wsskip() == '>') return; break; case ' ': break; case '%': pent(' '); break; default: panic(FAULT); break; } break; default: panic(FAULT); break; } } } /** * Parses an attribute declaration. * * The attribut uses the following fields of Pair object: * chars - characters of qualified name * id - the type identifier of the attribute * list - a pair which holds the default value (chars field) * * @param elm An object which reprecents all defined attributes on an element. * @exception SAXException * @exception IOException */ private void dtdatt(Pair elm) throws SAXException, IOException { char attqn[] = null; Pair att = null; char ch; for (short st = 0; st >= 0;) { ch = next(); switch (st) { case 0: // the attribute name switch (chtyp(ch)) { case 'a': case 'A': case '_': case 'X': case ':': back(); // Get the attribut from the list or add a new one. attqn = qname(mIsNSAware); att = find(elm.list, attqn); if (att == null) { att = pair(elm.list); att.chars = attqn; elm.list = att; } else { att.id = 'c'; if (att.list != null) del(att.list); att.list = null; } wsskip(); st = 1; break; case '%': pent(' '); break; case ' ': break; default: panic(FAULT); break; } break; case 1: // the attribute type switch (ch) { case '(': back(); att.id = 'u'; // enumeration type st = 2; // read the first element of the list break; case '%': pent(' '); break; case ' ': break; default: back(); bntok(); // read type id att.id = bkeyword(); switch (att.id) { case 'o': // NOTATION if (wsskip() != '(') panic(FAULT); st = 2; // read the first element of the list break; case 'i': // ID case 'r': // IDREF case 'R': // IDREFS case 'n': // ENTITY case 'N': // ENTITIES case 't': // NMTOKEN case 'T': // NMTOKENS case 'c': // CDATA wsskip(); st = 4; // read default declaration break; default: panic(FAULT); break; } break; } break; case 2: // read the first element of the list if (ch != '(') panic(FAULT); ch = wsskip(); switch (chtyp(ch)) { case 'a': case 'A': case 'd': case '.': case ':': case '-': case '_': case 'X': switch (att.id) { case 'u': // enumeration type bntok(); break; case 'o': // NOTATION mBuffIdx = -1; bname(false); break; default: panic(FAULT); break; } wsskip(); st = 3; // read next element of the list break; case '%': next(); pent(' '); break; default: panic(FAULT); break; } break; case 3: // read next element of the list switch (ch) { case ')': wsskip(); st = 4; // read default declaration break; case '|': wsskip(); switch (att.id) { case 'u': // enumeration type bntok(); break; case 'o': // NOTATION mBuffIdx = -1; bname(false); break; default: panic(FAULT); break; } wsskip(); break; case '%': pent(' '); break; default: panic(FAULT); break; } break; case 4: // read default declaration switch (ch) { case '#': bntok(); switch (bkeyword()) { case 'F': // FIXED switch (wsskip()) { case '\"': case '\'': st = 5; // read the default value break; default: st = -1; break; } break; case 'Q': // REQUIRED case 'I': // IMPLIED st = -1; break; default: panic(FAULT); break; } break; case '\"': case '\'': back(); st = 5; // read the default value break; case ' ': case '\n': case '\r': case '\t': break; case '%': pent(' '); break; default: back(); st = -1; break; } break; case 5: // read the default value switch (ch) { case '\"': case '\'': back(); bqstr('-'); // the value in the mBuff now att.list = pair(null); // Create a string like "attqname='value' " att.list.chars = new char[att.chars.length + mBuffIdx + 3]; System.arraycopy( att.chars, 1, att.list.chars, 0, att.chars.length - 1); att.list.chars[att.chars.length - 1] = '='; att.list.chars[att.chars.length] = ch; System.arraycopy( mBuff, 1, att.list.chars, att.chars.length + 1, mBuffIdx); att.list.chars[att.chars.length + mBuffIdx + 1] = ch; att.list.chars[att.chars.length + mBuffIdx + 2] = ' '; st = -1; break; default: panic(FAULT); break; } break; default: panic(FAULT); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -