writeStartDocument(sr.getVersion(), sr.getCharacterEncodingScheme(), sr.isStandalone()); } else { writeStartDocument(sr.getCharacterEncodingScheme(), sr.getVersion()); writeEndDocument(); return; if (sr instanceof StreamReaderImpl) { StreamReaderImpl impl = (StreamReaderImpl) sr; copyStartElement(impl.getInputElementStack(), impl.getAttributeCollector()); } else { // otherwise impl from Stax ref. impl (Stax2WriterImpl) has to do: super.copyStartElement(sr); writeEndElement(); return; closeStartElement(mEmptyElement); sr.getText(wrapAsRawWriter(), preserveEventData); closeStartElement(mEmptyElement); if (inPrologOrEpilog()) { reportNwfStructure(ErrorConsts.WERR_PROLOG_CDATA); sr.getText(wrapAsRawWriter(), preserveEventData);
protected void doReportProblem(XMLReporter rep, String probType, String msg, Location loc) throws XMLStreamException { if (loc == null) { loc = getLocation(); } doReportProblem(rep, new XMLValidationProblem(loc, msg, XMLValidationProblem.SEVERITY_ERROR, probType)); }
public void writeStartDocument(String encoding, String version) throws XMLStreamException { doWriteStartDocument(version, encoding, null); }
protected final void verifyWriteCData() throws XMLStreamException { // Not legal outside main element tree: if (mCheckStructure) { if (inPrologOrEpilog()) { reportNwfStructure(ErrorConsts.WERR_PROLOG_CDATA); } } // 08-Dec-2005, TSa: validator-based validation? if (mVldContent <= XMLValidator.CONTENT_ALLOW_WS) { // there's no ignorable white space CDATA... reportInvalidContent(CDATA); } }
public void reportValidationProblem(String msg) throws XMLStreamException { reportProblem(new XMLValidationProblem(getValidationLocation(), msg, XMLValidationProblem.SEVERITY_ERROR)); }
closeStartElement(mEmptyElement); if (inPrologOrEpilog()) { reportNwfStructure("Trying to output an entity reference outside main element tree (in prolog or epilog)"); reportInvalidContent(ENTITY_REFERENCE);
writeCharacters(data); return; closeStartElement(mEmptyElement); verifyWriteCData(); if (mVldContent == XMLValidator.CONTENT_ALLOW_VALIDATABLE_TEXT && mValidator != null) { reportNwfContent(ErrorConsts.WERR_CDATA_CONTENT, DataUtil.Integer(ix)); mEncoding = WstxOutputProperties.DEFAULT_OUTPUT_ENCODING; writeStartDocument(mEncoding, WstxOutputProperties.DEFAULT_XML_VERSION);
protected void reportInvalidContent(int evtType) throws XMLStreamException { switch (mVldContent) { case XMLValidator.CONTENT_ALLOW_NONE: reportValidationProblem(ErrorConsts.ERR_VLD_EMPTY, getTopElementDesc(), ErrorConsts.tokenTypeDesc(evtType)); break; case XMLValidator.CONTENT_ALLOW_WS: reportValidationProblem(ErrorConsts.ERR_VLD_NON_MIXED, getTopElementDesc()); break; case XMLValidator.CONTENT_ALLOW_VALIDATABLE_TEXT: case XMLValidator.CONTENT_ALLOW_ANY_TEXT: /* Not 100% sure if this should ever happen... depends on * interpretation of 'any' content model? */ reportValidationProblem(ErrorConsts.ERR_VLD_ANY, getTopElementDesc(), ErrorConsts.tokenTypeDesc(evtType)); break; default: // should never occur: reportValidationProblem("Internal error: trying to report invalid content for "+evtType); } }
if (isValidating()) { reportValidationProblem(ErrorConsts.ERR_VLD_WRONG_ROOT, wrongElem, mDtdRootElem);
writeCharacters(cbuf, start, len); return; closeStartElement(mEmptyElement); verifyWriteCData(); if (mVldContent == XMLValidator.CONTENT_ALLOW_VALIDATABLE_TEXT && mValidator != null) { throwOutputError(ErrorConsts.WERR_CDATA_CONTENT, DataUtil.Integer(ix));
public void writeComment(String data) throws XMLStreamException { mAnyOutput = true; // Need to finish an open start element? if (mStartElementOpen) { closeStartElement(mEmptyElement); } // 08-Dec-2005, TSa: validator-based validation? if (mVldContent == XMLValidator.CONTENT_ALLOW_NONE) { reportInvalidContent(COMMENT); } /* No structural validation needed per se, for comments; they are * allowed anywhere in XML content. However, content may need to * be checked (by XmlWriter) */ int ix; try { ix = mWriter.writeComment(data); } catch (IOException ioe) { throw new WstxIOException(ioe); } if (ix >= 0) { reportNwfContent(ErrorConsts.WERR_COMMENT_CONTENT, DataUtil.Integer(ix)); } }
reportNwfStructure("Trying to write END_DOCUMENT when document has no root (ie. trying to output empty document)."); closeStartElement(mEmptyElement); writeEndElement(); } while (mState == STATE_TREE);
public void reportProblem(XMLValidationProblem prob) throws XMLValidationException { // Custom handler set? If so, it'll take care of it: if (mVldProbHandler != null) { mVldProbHandler.reportProblem(prob); return; } /* For now let's implement basic functionality: warnings get * reported via XMLReporter, errors and fatal errors result in * immediate exceptions. */ if (prob.getSeverity() >= XMLValidationProblem.SEVERITY_ERROR) { if (isValidating()) { throw WstxValidationException.create(prob); } } XMLReporter rep = mConfig.getProblemReporter(); if (rep != null) { doReportProblem(rep, ErrorConsts.WT_VALIDATION, prob.getMessage(), prob.getLocation()); } }
public Location getValidationLocation() { return getLocation(); }
public void writeProcessingInstruction(String target, String data) throws XMLStreamException { mAnyOutput = true; // Need to finish an open start element? if (mStartElementOpen) { closeStartElement(mEmptyElement); } // Structurally, PIs are always ok (content might not be) // 08-Dec-2005, TSa: validator-based validation? if (mVldContent == XMLValidator.CONTENT_ALLOW_NONE) { reportInvalidContent(PROCESSING_INSTRUCTION); } int ix; try { ix = mWriter.writePI(target, data); } catch (IOException ioe) { throw new WstxIOException(ioe); } if (ix >= 0) { throw new XMLStreamException("Illegal input: processing instruction content has embedded '?>' in it (index "+ix+")"); } }
public void writeRaw(String text) throws XMLStreamException { mAnyOutput = true; if (mStartElementOpen) { closeStartElement(mEmptyElement); } try { mWriter.writeRaw(text, 0, text.length()); } catch (IOException ioe) { throw new WstxIOException(ioe); } }
doReportProblem(rep, prob); } else {
closeStartElement(mEmptyElement); if (inPrologOrEpilog()) { if (!StringUtil.isAllWhitespace(text, start, len)) { reportNwfStructure(ErrorConsts.WERR_PROLOG_NONWS_TEXT); reportInvalidContent(CHARACTERS); } else { // all-ws is ok... if (!StringUtil.isAllWhitespace(text, start, len)) { reportInvalidContent(CHARACTERS); if (inPrologOrEpilog()) { mWriter.writeRaw(text, start, len); } else {
protected final void verifyWriteCData() throws XMLStreamException { // Not legal outside main element tree: if (mCheckStructure) { if (inPrologOrEpilog()) { reportNwfStructure(ErrorConsts.WERR_PROLOG_CDATA); } } // 08-Dec-2005, TSa: validator-based validation? if (mVldContent <= XMLValidator.CONTENT_ALLOW_WS) { // there's no ignorable white space CDATA... reportInvalidContent(CDATA); } }
public void reportValidationProblem(Location loc, String msg) throws XMLStreamException { reportProblem(new XMLValidationProblem(getValidationLocation(), msg)); }