/** * Method called to read in the internal subset definition. */ public static DTDSubset readInternalSubset(WstxInputData srcData, WstxInputSource input, ReaderConfig cfg, boolean constructFully, int xmlVersion) throws XMLStreamException { FullDTDReader r = new FullDTDReader(input, cfg, constructFully, xmlVersion); // Need to read using the same low-level reader interface: r.copyBufferStateFrom(srcData); DTDSubset ss; try { ss = r.parseDTD(); } finally { /* And then need to restore changes back to owner (line nrs etc); * effectively means that we'll stop reading external DTD subset, * if so. */ srcData.copyBufferStateFrom(r); } return ss; }
private void throwDTDAttrError(String msg, DTDElement elem, PrefixedName attrName) throws XMLStreamException { _reportWFCViolation(attrDesc(elem, attrName) + ": " + msg); }
boolean isPublic = checkPublicSystemKeyword(c); c = skipObligatoryDtdWs(); if (c != '"' && c != '\'') { throwDTDUnexpectedChar(c, "; expected a quote to start the public identifier"); pubId = parsePublicId(c, getErrorMsg()); c = getNextExpanded(); if (c <= CHAR_SPACE) { // good c = skipDtdWs(true); } else { // not good... c = skipObligatoryDtdWs(); _reportWFCViolation("Unexpected end of ENTITY declaration (expected a system id after public id): trying to use an SGML DTD instead of XML one?"); c = skipObligatoryDtdWs(); throwDTDUnexpectedChar(c, "; expected a quote to start the system identifier"); String sysId = parseSystemId(c, mNormalizeLFs, getErrorMsg()); c = skipDtdWs(true); } else { int i = peekNext(); if (i == '>') { // good c = '>';
/** * Method called to read in the external subset definition. */ public static DTDSubset readExternalSubset (WstxInputSource src, ReaderConfig cfg, DTDSubset intSubset, boolean constructFully, int xmlVersion) throws XMLStreamException { FullDTDReader r = new FullDTDReader(src, cfg, intSubset, constructFully, xmlVersion); return r.parseDTD(); }
/** * @return True, if input contains 'PUBLIC' keyword; false if it * contains 'SYSTEM'; otherwise throws an exception. */ private boolean checkPublicSystemKeyword(char c) throws XMLStreamException { String errId; if (c == 'P') { errId = checkDTDKeyword("UBLIC"); if (errId == null) { return true; } errId = "P" + errId; } else if (c == 'S') { errId = checkDTDKeyword("YSTEM"); if (errId == null) { return false; } errId = "S" + errId; } else { if (!isNameStartChar(c)) { throwDTDUnexpectedChar(c, "; expected 'PUBLIC' or 'SYSTEM' keyword"); } errId = readDTDKeyword(String.valueOf(c)); } _reportWFCViolation("Unrecognized keyword '"+errId+"'; expected 'PUBLIC' or 'SYSTEM'"); return false; // never gets here }
char c = dtdNextFromCurr(); boolean gotSeparator = false; boolean isParam = false; char d = dtdNextIfAvailable(); if (d == CHAR_NULL || isSpaceChar(d)) { // ok, PE declaration isParam = true; if (d == '\n' || c == '\r') { skipCRLF(d); if (!isNameStartChar(d)) { throwDTDUnexpectedChar(d, "; expected a space (for PE declaration) or PE reference name"); expandPE(); c = dtdNextChar(); } else if (!isSpaceChar(c)) { // non-PE entity? break; } else { gotSeparator = true; c = dtdNextFromCurr(); throwDTDUnexpectedChar(c, "; expected a space separating ENTITY keyword and entity name"); c = skipDtdWs(true); String id = readDTDName(c); Location evtLoc = getStartLocation();
PrefixedName attrName = readDTDQName(c); c = skipObligatoryDtdWs(); enumValues = parseEnumerated(elem, attrName, false); type = DTDAttribute.TYPE_ENUMERATED; } else { String typeStr = readDTDName(c); c = skipObligatoryDtdWs(); if (c != '(') { throwDTDUnexpectedChar(c, "Excepted '(' to start the list of NOTATION ids"); enumValues = parseEnumerated(elem, attrName, true); break dummy; } else if (typeStr == "NMTOKEN") { throwDTDAttrError("Unrecognized attribute type '"+typeStr+"'" +ErrorConsts.ERR_DTD_ATTR_TYPE, elem, attrName); c = skipObligatoryDtdWs(); if (c == '#') { String defTypeStr = readDTDName(getNextExpanded()); if (defTypeStr == "REQUIRED") { defVal = DefaultAttrValue.constructRequired(); } else if (defTypeStr == "FIXED") { defVal = DefaultAttrValue.constructFixed();
throws XMLStreamException char c = skipObligatoryDtdWs(); String id = readDTDName(c); c = skipObligatoryDtdWs(); boolean isPublic = checkPublicSystemKeyword(c); c = skipObligatoryDtdWs(); throwDTDUnexpectedChar(c, "; expected a quote to start the public identifier"); pubId = parsePublicId(c, getErrorMsg()); c = skipDtdWs(true); } else { pubId = null; sysId = parseSystemId(c, mNormalizeLFs, getErrorMsg()); c = skipDtdWs(true); } else { if (!isPublic) { throwDTDUnexpectedChar(c, "; expected a quote to start the system identifier"); throwDTDUnexpectedChar(c, "; expected closing '>' after NOTATION declaration"); Location evtLoc = getStartLocation(); NotationDeclaration nd = new WNotationDeclaration(evtLoc, id, pubId, sysId, baseURL);
char c = dtdNextFromCurr(); if (c == '?') { // xml decl? readPI(); return; throwDTDUnexpectedChar(c, "; expected '!' to start a directive"); c = dtdNextFromCurr(); if (c == '-') { // plain comment c = dtdNextFromCurr(); if (c != '-') { throwDTDUnexpectedChar(c, "; expected '-' for a comment"); readComment(mEventListener); } else { skipComment(); checkInclusion(); } else if (c >= 'A' && c <= 'Z') { handleDeclaration(c); } else { throwDTDUnexpectedChar(c, ErrorConsts.ERR_DTD_MAINLEVEL_KEYWORD);
char c = dtdNextFromCurr(); if (c == '?') { // xml decl? mFlattenWriter.enableOutput(mInputPtr); mFlattenWriter.output("<?"); readPI(); throwDTDUnexpectedChar(c, ErrorConsts.ERR_DTD_MAINLEVEL_KEYWORD); c = dtdNextFromCurr(); if (c == '-') { // plain comment c = dtdNextFromCurr(); if (c != '-') { throwDTDUnexpectedChar(c, "; expected '-' for a comment"); skipComment(); } finally { if (!comm) { checkInclusion(); } finally { if (!cond) { handleSuppressedDeclaration(); } else if (c >= 'A' && c <= 'Z') { mFlattenWriter.enableOutput(mInputPtr); mFlattenWriter.output("<!"); mFlattenWriter.output(c); handleDeclaration(c); } else {
char c = skipObligatoryDtdWs(); final PrefixedName elemName = readDTDQName(c); Location loc = getStartLocation(); c = skipObligatoryDtdWs(); c = skipDtdWs(true); if (c == '#') { val = readMixedSpec(elemName, mCfgFullyValidating); ContentSpec spec = readContentSpec(elemName, true, mCfgFullyValidating); val = spec.getSimpleValidator(); if (val == null) { } else if (isNameStartChar(c)) { do { // dummy loop to allow break: String keyw = null; if (c == 'A') { keyw = checkDTDKeyword("NY"); if (keyw == null) { val = null; keyw = checkDTDKeyword("MPTY"); if (keyw == null) { val = EmptyValidator.getPcdataInstance(); } else { --mInputPtr;
char c = skipDtdWs(true); if (c == ')') { _reportWFCViolation("Empty content specification for '"+elemName+"' (need at least one entry)"); } else { if (isChoice != newChoice) { _reportWFCViolation("Can not mix content spec separators ('|' and ','); need to use parenthesis groups"); c = skipDtdWs(true); } else { throwDTDUnexpectedChar(c, " (missing separator '|' or ','?)"); ContentSpec cs = readContentSpec(elemName, false, construct); subSpecs.add(cs); continue; throwDTDUnexpectedChar(c, " (missing element name?)"); PrefixedName thisName = readDTDQName(c); char arity = readArity(); ContentSpec cs = construct ? TokenContentSpec.construct(arity, thisName) char arity = readArity(); char otherArity = cs.getArity();
do { // dummy loop, for break if (c == 'A') { // ATTLIST? keyw = checkDTDKeyword("TTLIST"); if (keyw == null) { mCurrDeclaration = "ATTLIST"; handleAttlistDecl(); break; c = dtdNextFromCurr(); if (c == 'N') { keyw = checkDTDKeyword("TITY"); if (keyw == null) { mCurrDeclaration = "ENTITY"; handleEntityDecl(false); break; keyw = checkDTDKeyword("EMENT"); if (keyw == null) { mCurrDeclaration = "ELEMENT"; handleElementDecl(); break; keyw = readDTDKeyword("E"); keyw = checkDTDKeyword("OTATION"); if (keyw == null) { mCurrDeclaration = "NOTATION"; handleNotationDecl(); break;
char c = skipDtdWs(true); if (c == ')') { reportWFCViolation("Empty content specification for '"+elemName+"' (need at least one entry)"); } else { if (isChoice != newChoice) { reportWFCViolation("Can not mix content spec separators ('|' and ','); need to use parenthesis groups"); c = skipDtdWs(true); } else { throwDTDUnexpectedChar(c, " (missing separator '|' or ','?)"); ContentSpec cs = readContentSpec(elemName, false, construct); subSpecs.add(cs); continue; throwDTDUnexpectedChar(c, " (missing element name?)"); NameKey thisName = readDTDQName(c); char arity = readArity(); ContentSpec cs = construct ? TokenContentSpec.construct(arity, thisName) char arity = readArity(); char otherArity = cs.getArity();
String keyw = checkDTDKeyword("PCDATA"); if (keyw != null) { _reportWFCViolation("Unrecognized directive #"+keyw+"'; expected #PCDATA (or element name)"); char c = skipDtdWs(true); if (c == ')') { break; c = skipDtdWs(true); } else if (c == ',') { throwDTDUnexpectedChar(c, " (sequences not allowed within mixed content)"); } else if (c == '(') { throwDTDUnexpectedChar(c, " (sub-content specs not allowed within mixed content)"); } else { throwDTDUnexpectedChar(c, "; expected either '|' to separate elements, or ')' to close the list"); PrefixedName n = readDTDQName(c); Object old = m.put(n, TokenContentSpec.construct(' ', n)); if (old != null) { throwDTDElemError("duplicate child element <"+n+"> in mixed content model", elemName); mInputBuffer[mInputPtr++] : getNextChar(getErrorMsg()); if (c != '*') { if (m.size() > 0) { _reportWFCViolation("Missing trailing '*' after a non-empty mixed content specification");
char c = dtdNextFromCurr(); keyw = checkDTDKeyword("TITY"); if (keyw == null) { handleEntityDecl(true); return; keyw = checkDTDKeyword("EMENT"); if (keyw == null) { handleElementDecl(); return; keyw = readDTDKeyword("E"); _reportBadDirective(keyw);
_reportWFCViolation("Internal DTD subset can not use (INCLUDE/IGNORE) directives (except via external entities)"); char c = skipDtdWs(true); if (c != 'I') { keyword = readDTDKeyword(String.valueOf(c)); } else { c = dtdNextFromCurr(); if (c == 'G') { keyword = checkDTDKeyword("NORE"); if (keyword == null) { handleIgnored(); return; keyword = checkDTDKeyword("CLUDE"); if (keyword == null) { handleIncluded(); return; } else { --mInputPtr; keyword = readDTDKeyword("I"); _reportWFCViolation("Unrecognized directive '"+keyword+"'; expected either 'IGNORE' or 'INCLUDE'");
/** * @return True, if input contains 'PUBLIC' keyword; false if it * contains 'SYSTEM'; otherwise throws an exception. */ private boolean checkPublicSystemKeyword(char c) throws IOException, XMLStreamException { String errId; if (c == 'P') { errId = checkDTDKeyword("UBLIC"); if (errId == null) { return true; } errId = "P" + errId; } else if (c == 'S') { errId = checkDTDKeyword("YSTEM"); if (errId == null) { return false; } errId = "S" + errId; } else { if (!isNameStartChar(c)) { throwDTDUnexpectedChar(c, "; expected 'PUBLIC' or 'SYSTEM' keyword"); } errId = readDTDKeyword(String.valueOf(c)); } reportWFCViolation("Unrecognized keyword '"+errId+"'; expected 'PUBLIC' or 'SYSTEM'"); return false; // never gets here }
FullDTDReader r = new FullDTDReader(src, cfg, null, true, XmlConsts.XML_V_UNKNOWN); r.setFlattenWriter(flattenWriter, inclComments, inclConditionals, inclPEs); DTDSubset ss = r.parseDTD(); r.flushFlattenWriter(); flattenWriter.flush(); return ss;
char c = dtdNextFromCurr(); keyw = checkDTDKeyword("TITY"); if (keyw == null) { handleEntityDecl(true); return; keyw = checkDTDKeyword("EMENT"); if (keyw == null) { handleElementDecl(); return; keyw = readDTDKeyword("E"); reportBadDirective(keyw);