if (!ensureInput(3)) { checkCData(); skipCommentOrCData(SUFFIX_IN_CDATA, ']', false); i = getNext(); } else if (i < 0) { // eof return i; } else { // nah, normal text, gotta skip i = skipTokenText(i);
loadMore(SUFFIX_IN_CDATA); inputBuf = mInputBuffer; inputPtr = mInputPtr; markLF(inputPtr); } else if (c == '\r') { mInputPtr = inputPtr; if (skipCRLF(c)) { // got 2 char LF if (!mNormalizeLFs) { inputLen = mInputEnd; } else if (c != '\t') { throwInvalidSpace(c); if (checkCDataEnd(outBuf, outPtr)) { return true;
int i = getNext(); if (i < 0) { throwUnexpectedEOF(SUFFIX_IN_PROLOG); String keyw = checkKeyword('D', "DOCTYPE"); if (keyw != null) { throwParseError("Unrecognized XML directive '<!"+keyw+"' (misspelled DOCTYPE?)."); mCurrToken = handleMultiDocStart(DTD); return; throwParseError(ErrorConsts.ERR_DTD_IN_EPILOG); throwParseError(ErrorConsts.ERR_DTD_DUP); startDTD(); return; } else if (i == '-') { // comment char c = getNextChar(isProlog ? SUFFIX_IN_PROLOG : SUFFIX_IN_EPILOG); if (c != '-') { throwUnexpectedChar(i, " (malformed comment?)"); return; } else if (i == '[') { // erroneous CDATA? i = peekNext(); throwUnexpectedChar(i, ErrorConsts.ERR_CDATA_IN_EPILOG); throwUnexpectedChar(i, " after '<!' (malformed comment?)");
public final XMLStreamLocation2 getEndLocation() throws XMLStreamException { // Need to get to the end of the token, if not there yet if (mTokenState < mStTextThreshold) { finishToken(false); } // And then we just need the current location! return getCurrentLocation(); }
protected void checkCData() throws XMLStreamException { String wrong = checkKeyword(getNextCharFromCurrent(SUFFIX_IN_CDATA), "CDATA"); if (wrong != null) { throwParseError("Unrecognized XML directive '"+wrong+"'; expected 'CDATA'."); } // Plus, need the bracket too: char c = getNextCharFromCurrent(SUFFIX_IN_CDATA); if (c != '[') { throwUnexpectedChar(c, "excepted '[' after '<![CDATA'"); } // Cool, that's it! }
protected void safeFinishToken() { try { /* 24-Sep-2006, TSa: Let's try to reduce number of unchecked * (wrapped) exceptions we throw, and defer some. For now, * this is only for CHARACTERS (since it's always legal to * split CHARACTERS segment); could be expanded in future. */ boolean deferErrors = (mCurrToken == CHARACTERS); finishToken(deferErrors); } catch (XMLStreamException strex) { throwLazyError(strex); } }
mScanner.fireSaxCommentEvent(mLexicalHandler); break; case XMLStreamConstants.CDATA: if (mLexicalHandler != null) { mLexicalHandler.startCDATA(); mScanner.fireSaxCharacterEvents(mContentHandler); mLexicalHandler.endCDATA(); } else { mScanner.fireSaxCharacterEvents(mContentHandler); String rootName = mScanner.getDTDRootName(); String sysId = mScanner.getDTDSystemId(); String pubId = mScanner.getDTDPublicId(); mLexicalHandler.startDTD(rootName, pubId, sysId); /*DTDInfo dtdInfo =*/ mScanner.getDTDInfo(); } catch (WrappedSaxException wse) { throw wse.getSaxException(); mScanner.fireSaxPIEvent(mContentHandler); break; case XMLStreamConstants.SPACE: mScanner.fireSaxSpaceEvents(mContentHandler); mContentHandler.skippedEntity(mScanner.getLocalName());
case CDATA: if (mCfgCoalesceText) { readCoalescedText(mCurrToken, deferErrors); } else { if (readCDataSecondary(mShortestTextSegment)) { mTokenState = TOKEN_FULL_SINGLE; } else { readCoalescedText(mCurrToken, deferErrors); } else { if (readTextSecondary(mShortestTextSegment, deferErrors)) { mTokenState = TOKEN_FULL_SINGLE; } else { readSpaceSecondary(prolog); mTokenState = TOKEN_FULL_COALESCED; readComment(); mTokenState = TOKEN_FULL_COALESCED; return; finishDTD(true); } finally { mTokenState = TOKEN_FULL_COALESCED; readPI(); mTokenState = TOKEN_FULL_COALESCED; return;
String enc2 = mScanner.getEncoding(); if (enc2 == null) { enc2 = mScanner.getCharacterEncodingScheme(); mXmlVersion = mScanner.getVersion(); mStandalone = mScanner.standaloneSet(); mAttrCollector = mScanner.getAttributeCollector(); mElemStack = mScanner.getInputElementStack(); fireEvents(); } catch (IOException io) { mScanner = null; try { sr.close(); } catch (XMLStreamException sex) { }
char c = getNextInCurrAfterWS(SUFFIX_IN_DTD); if (mCfgNsEnabled) { String str = parseLocalName(c); c = getNextChar(SUFFIX_IN_DTD); if (c == ':') { // Ok, got namespace and local name mRootPrefix = str; mRootLName = parseLocalName(getNextChar(SUFFIX_EOF_EXP_NAME)); } else if (c <= CHAR_SPACE || c == '[' || c == '>') { mRootLName = str; } else { throwUnexpectedChar(c, " in DOCTYPE declaration; expected '[' or white space."); mRootLName = parseFullName(c); mRootPrefix = null; c = getNextInCurrAfterWS(SUFFIX_IN_DTD); if (c != '[' && c != '>') { String keyw = null; keyw = checkKeyword(getNextChar(SUFFIX_IN_DTD), "UBLIC"); if (keyw != null) { keyw = "P" + keyw; } else { if (!skipWS(getNextChar(SUFFIX_IN_DTD))) { throwUnexpectedChar(c, SUFFIX_IN_DTD+"; expected a space between PUBLIC keyword and public id"); c = getNextCharFromCurrent(SUFFIX_IN_DTD); if (c != '"' && c != '\'') {
skipCommentOrCData(SUFFIX_IN_CDATA, ']', false); result = getNext(); result = skipCoalescedText(result); skipCommentOrCData(SUFFIX_IN_COMMENT, '-', true); result = 0; break; result = skipTokenText(getNext()); result = skipCoalescedText(result); finishDTD(false); result = 0; break; while (true) { char c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++] : getNextCharFromCurrent(SUFFIX_IN_PROC_INSTR); if (c == '?') { do { c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++] : getNextCharFromCurrent(SUFFIX_IN_PROC_INSTR); } while (c == '?'); if (c == '>') { skipCRLF(c);
/** *<p> * Note: According to StAX 1.0, coalesced text events are always to be * returned as CHARACTERS, never as CDATA. And since at this point we * don't really know if there's anything to coalesce (but there may * be), let's convert CDATA if necessary. */ private int nextFromTreeCommentOrCData() throws XMLStreamException { char c = getNextCharFromCurrent(SUFFIX_IN_DOC); if (c == '[') { checkCData(); /* Good enough; it is a CDATA section... but let's just also * parse the easy ("free") stuff: */ c = (mInputPtr < mInputEnd) ? mInputBuffer[mInputPtr++] : getNextCharFromCurrent(SUFFIX_IN_CDATA); readCDataPrimary(c); // sets token state appropriately... return CDATA; } if (c == '-' && getNextCharFromCurrent(SUFFIX_IN_DOC) == '-') { mTokenState = TOKEN_STARTED; return COMMENT; } throwParseError("Unrecognized XML directive; expected CDATA or comment ('<![CDATA[' or '<!--')."); return 0; // never gets here, but compilers don't know it... }
while (true) { if (mInputPtr >= mInputEnd) { if (!loadMore()) { if (!ensureInput(3)) { // likewise, probably an error... break main_loop; checkCData(); count += readAndWriteCData(w); wasCData = true; } else { // text break; count += readAndWriteText(w); wasCData = false;
char c = getNextInCurrAfterWS(SUFFIX_IN_XML_DECL); String wrong = checkKeyword(c, XmlConsts.XML_DECL_KW_VERSION); if (wrong != null) { throwParseError(ErrorConsts.ERR_UNEXP_KEYWORD, wrong, XmlConsts.XML_DECL_KW_VERSION); c = skipEquals(XmlConsts.XML_DECL_KW_VERSION, SUFFIX_IN_XML_DECL); TextBuffer tb = mTextBuffer; tb.resetInitialized(); parseQuoted(XmlConsts.XML_DECL_KW_VERSION, c, tb); mDocXmlVersion = XmlConsts.XML_V_UNKNOWN; mXml11 = false; throwParseError("Unexpected xml version '"+tb.toString()+"'; expected '"+XmlConsts.XML_V_10_STR+"' or '"+XmlConsts.XML_V_11_STR+"'"); c = getNextInCurrAfterWS(SUFFIX_IN_XML_DECL); wrong = checkKeyword(c, XmlConsts.XML_DECL_KW_ENCODING); if (wrong != null) { throwParseError(ErrorConsts.ERR_UNEXP_KEYWORD, wrong, XmlConsts.XML_DECL_KW_ENCODING); c = skipEquals(XmlConsts.XML_DECL_KW_ENCODING, SUFFIX_IN_XML_DECL); tb.resetWithEmpty(); parseQuoted(XmlConsts.XML_DECL_KW_ENCODING, c, tb); mDocXmlEncoding = tb.toString(); c = getNextInCurrAfterWS(SUFFIX_IN_XML_DECL); } else if (c != 's') { throwUnexpectedChar(c, " in xml declaration; expected either 'encoding' or 'standalone' pseudo-attribute");
readTextSecondary(Integer.MAX_VALUE, deferErrors); wasCData = false; } else if (currType == CDATA) { readCDataSecondary(Integer.MAX_VALUE); throw new IllegalStateException("Internal error: unexpected token "+tokenTypeDesc(mCurrToken)+"; expected CHARACTERS, CDATA or SPACE."); if (mInputPtr >= mInputEnd) { mTextBuffer.ensureNotShared(); if (!loadMore()) { if (!ensureInput(3)) { break; checkCData(); readCDataSecondary(Integer.MAX_VALUE); wasCData = true; } else { // text readTextSecondary(Integer.MAX_VALUE, deferErrors); wasCData = false;
throwParseError(ErrorConsts.ERR_STATE_NOT_STELEM, null, null); int type = next(); if (type == END_ELEMENT) { return ""; throw _constructUnexpectedInTyped(type); readCoalescedText(mCurrToken, false); readEndElem(); int type; while ((type = next()) != END_ELEMENT) { if (((1 << type) & MASK_GET_ELEMENT_TEXT) != 0) { if (mTokenState < mStTextThreshold) { finishToken(false); verifyLimit("Text size", mConfig.getMaxTextLength(), sb.length()); mTextBuffer.contentsToStringBuffer(sb); continue; throw _constructUnexpectedInTyped(type);
while ((type = mScanner.next()) != XMLStreamConstants.START_ELEMENT) { fireAuxEvent(type, false); type = mScanner.next(); if (type == XMLStreamConstants.START_ELEMENT) { fireStartTag(); ++depth; } else if (type == XMLStreamConstants.END_ELEMENT) { mScanner.fireSaxEndElement(mContentHandler); if (--depth < 1) { break; mScanner.fireSaxCharacterEvents(mContentHandler); } else { fireAuxEvent(type, true); type = mScanner.next(); if (type == XMLStreamConstants.END_DOCUMENT) { break;
int type = nextFromTree(); mCurrToken = type; if (mTokenState < mStTextThreshold) { // incomplete? finishToken(false); verifyLimit("Text size", mConfig.getMaxTextLength(), mCurrTextLength); } else if (type == CHARACTERS) { if (mValidateText) { verifyLimit("Text size", mConfig.getMaxTextLength(), mCurrTextLength); } else if (type == START_ELEMENT || type == END_ELEMENT) { this.mCurrTextLength = 0; nextFromProlog(true); } else if (mParseState == STATE_EPILOG) { if (nextFromProlog(false)) { mCurrToken = nextFromMultiDocState(); } else { // == STATE_CLOSED if (mSecondaryToken == END_DOCUMENT) { // marker
int next = next(); finishToken(false); continue; throwParseError("Received non-all-whitespace CHARACTERS or CDATA event in nextTag()."); break; // never gets here, but jikes complains without case START_ELEMENT: return next; throwParseError("Received event "+ErrorConsts.tokenTypeDesc(next) +", instead of START_ELEMENT or END_ELEMENT.");
public void closeCompletely() throws XMLStreamException { closeAllInput(true); }