/** * Report an ignored element via the {@link XMLReporter} if available and the class * {@link org.apache.commons.logging.Log}. * * @param reader The {@link XMLStreamReader} providing the SCXML document to parse. * @param configuration The {@link Configuration} to use while parsing. * @param parent The parent element local name in the SCXML namespace. * @param nsURI The namespace URI of the ignored element. * @param name The local name of the ignored element. * * @throws XMLStreamException An exception processing the underlying {@link XMLStreamReader}. * @throws ModelException The Commons SCXML object model is incomplete or inconsistent (includes * errors in the SCXML document that may not be identified by the schema). */ private static void reportIgnoredElement(final XMLStreamReader reader, final Configuration configuration, final String parent, final String nsURI, final String name) throws XMLStreamException, ModelException { StringBuilder sb = new StringBuilder(); sb.append("Ignoring unknown or invalid element <").append(name) .append("> in namespace \"").append(nsURI) .append("\" as child of <").append(parent) .append("> at ").append(reader.getLocation()); if (!configuration.isSilent() && logger.isWarnEnabled()) { logger.warn(sb.toString()); } if (configuration.isStrict()) { throw new ModelException(sb.toString()); } XMLReporter reporter = configuration.reporter; if (reporter != null) { reporter.report(sb.toString(), "COMMONS_SCXML", null, reader.getLocation()); } skipToEndElement(reader); }
/** * Report an ignored attribute via the {@link XMLReporter} if available and * {@link org.apache.commons.logging.Log}. * * @param reader The {@link XMLStreamReader} providing the SCXML document to parse. * @param configuration The {@link Configuration} to use while parsing. * @param element The element name. * @param attr The attribute which is ignored. * @param value The value of the attribute which is ignored. * * @throws XMLStreamException An exception processing the underlying {@link XMLStreamReader}. * @throws ModelException The Commons SCXML object model is incomplete or inconsistent (includes * errors in the SCXML document that may not be identified by the schema). */ private static void reportIgnoredAttribute(final XMLStreamReader reader, final Configuration configuration, final String element, final String attr, final String value) throws XMLStreamException, ModelException { StringBuilder sb = new StringBuilder(); sb.append("Ignoring unknown or invalid <").append(element).append("> attribute ").append(attr) .append("=\"").append(value).append("\" at ").append(reader.getLocation()); if (!configuration.isSilent() && logger.isWarnEnabled()) { logger.warn(sb.toString()); } if (configuration.isStrict()) { throw new ModelException(sb.toString()); } XMLReporter reporter = configuration.reporter; if (reporter != null) { reporter.report(sb.toString(), "COMMONS_SCXML", null, reader.getLocation()); } }
/** * Report a conflicting attribute via the {@link XMLReporter} if available and * {@link org.apache.commons.logging.Log}. * * @param reader The {@link XMLStreamReader} providing the SCXML document to parse. * @param configuration The {@link Configuration} to use while parsing. * @param element The element name. * @param attr The attribute with which a conflict is detected. * @param conflictingAttr The conflicting attribute * * @throws XMLStreamException An exception processing the underlying {@link XMLStreamReader}. * @throws ModelException The Commons SCXML object model is incomplete or inconsistent (includes * errors in the SCXML document that may not be identified by the schema). */ private static void reportConflictingAttribute(final XMLStreamReader reader, final Configuration configuration, final String element, final String attr, final String conflictingAttr) throws XMLStreamException, ModelException { StringBuilder sb = new StringBuilder(); sb.append("Ignoring <").append(element).append("> attribute \"").append(conflictingAttr) .append("\" which conflicts with already defined attribute \"").append(attr) .append("\" at ").append(reader.getLocation()); if (!configuration.isSilent() && logger.isWarnEnabled()) { logger.warn(sb.toString()); } if (configuration.isStrict()) { throw new ModelException(sb.toString()); } XMLReporter reporter = configuration.reporter; if (reporter != null) { reporter.report(sb.toString(), "COMMONS_SCXML", null, reader.getLocation()); } }
protected void _reportProblem(XMLReporter rep, XMLValidationProblem prob) throws XMLStreamException { if (rep != null) { Location loc = prob.getLocation(); if (loc == null) { loc = getLastCharLocation(); prob.setLocation(loc); } // Backwards-compatibility fix: add non-null type, if missing: if (prob.getType() == null) { prob.setType(ErrorConsts.WT_VALIDATION); } // [WSTX-154]: was catching and dropping thrown exception: shouldn't. // [WTSX-157]: need to support XMLReporter2 if (rep instanceof XMLReporter2) { ((XMLReporter2) rep).report(prob); } else { rep.report(prob.getMessage(), prob.getType(), prob, loc); } } }
protected void doReportProblem(XMLReporter rep, XMLValidationProblem prob) throws XMLStreamException { if (rep != null) { Location loc = prob.getLocation(); if (loc == null) { loc = getLocation(); prob.setLocation(loc); } // Backwards-compatibility fix: add non-null type, if missing: if (prob.getType() == null) { prob.setType(ErrorConsts.WT_VALIDATION); } // [WSTX-154]: was catching and dropping thrown exception: shouldn't. rep.report(prob.getMessage(), prob.getType(), prob, loc); } }
@Override public void setErrorHandler(final ErrorHandler eh) { checkNotNull(eh, "Argument eh must not be null."); inputFactory.setXMLReporter(new XMLReporter() { @Override public void report(final String message, final String errorType, final Object relatedInformation, final Location location) throws XMLStreamException { try { eh.error(new SAXParseException(message, location.getPublicId(), location.getSystemId(), location .getLineNumber(), location.getColumnNumber())); } catch (final SAXException ex) { throw new XMLStreamException(ex); } } }); }
public void setProperty(String name, Object value) throws IllegalArgumentException { if (name.equals(IS_NAMESPACE_AWARE)) namespaceAware = ((Boolean) value).booleanValue(); else if (name.equals(IS_VALIDATING)) validating = ((Boolean) value).booleanValue(); else if (name.equals(IS_COALESCING)) coalescing = ((Boolean) value).booleanValue(); else if (name.equals(IS_REPLACING_ENTITY_REFERENCES)) replacingEntityReferences = ((Boolean) value).booleanValue(); else if (name.equals(IS_SUPPORTING_EXTERNAL_ENTITIES)) externalEntities = ((Boolean) value).booleanValue(); else if (name.equals(SUPPORT_DTD)) supportDTD = ((Boolean) value).booleanValue(); else if (name.equals(REPORTER)) reporter = (XMLReporter) value; else if (name.equals(RESOLVER)) resolver = (XMLResolver) value; else if (name.equals(ALLOCATOR)) allocator = (XMLEventAllocator) value; else if (name.equals("gnu.xml.stream.stringInterning")) stringInterning = ((Boolean) value).booleanValue(); else if (name.equals("gnu.xml.stream.baseAware")) baseAware = ((Boolean) value).booleanValue(); else if (name.equals("gnu.xml.stream.xIncludeAware")) xIncludeAware = ((Boolean) value).booleanValue(); else throw new IllegalArgumentException(name); }
public void reportProblem(String probType, String format, Object arg, Object arg2) throws XMLStreamException { XMLReporter rep = mConfig.getXMLReporter(); if (rep != null) { _reportProblem(rep, probType, MessageFormat.format(format, new Object[] { arg, arg2 }), null); } }
@Override public void reportProblem(Location loc, String probType, String format, Object arg, Object arg2) throws XMLStreamException { XMLReporter rep = mConfig.getXMLReporter(); if (rep != null) { String msg = (arg != null || arg2 != null) ? MessageFormat.format(format, new Object[] { arg, arg2 }) : format; _reportProblem(rep, probType, msg, loc); } }
protected void _reportProblem(XMLReporter rep, String probType, String msg, Location loc) throws XMLStreamException { if (loc == null) { loc = getLastCharLocation(); } _reportProblem(rep, new XMLValidationProblem(loc, msg, XMLValidationProblem.SEVERITY_ERROR, probType)); }
/** *<p> * Note: this is the base implementation used for implementing * <code>ValidationContext</code> */ @Override public void reportValidationProblem(XMLValidationProblem prob) throws XMLStreamException { // !!! TBI: Fail-fast vs. deferred modes? /* For now let's implement basic functionality: warnings get * reported via XMLReporter, errors and fatal errors result in * immediate exceptions. */ /* 27-May-2008, TSa: [WSTX-153] Above is incorrect: as per Stax * javadocs for XMLReporter, both warnings and non-fatal errors * (which includes all validation errors) should be reported via * XMLReporter interface, and only fatals should cause an * immediate stream exception (by-passing reporter) */ if (prob.getSeverity() > XMLValidationProblem.SEVERITY_ERROR) { throw WstxValidationException.create(prob); } XMLReporter rep = mConfig.getXMLReporter(); if (rep != null) { _reportProblem(rep, prob); } else { /* If no reporter, regular non-fatal errors are to be reported * as exceptions as well, for backwards compatibility */ if (prob.getSeverity() >= XMLValidationProblem.SEVERITY_ERROR) { throw WstxValidationException.create(prob); } } }
private void _reportWarning(XMLReporter rep, String probType, String msg, Location loc) throws XMLStreamException { if (rep != null) { /* Note: since the problem occurs at DTD (schema) parsing, * not during validation, can not set reporter. */ XMLValidationProblem prob = new XMLValidationProblem (loc, msg, XMLValidationProblem.SEVERITY_WARNING, probType); rep.report(msg, probType, prob, loc); } }
@Override public void reportProblem(XMLValidationProblem prob) throws XMLStreamException { // 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. */ /* 27-May-2008, TSa: [WSTX-153] Above is incorrect: as per Stax * javadocs for XMLReporter, both warnings and non-fatal errors * (which includes all validation errors) should be reported via * XMLReporter interface, and only fatals should cause an * immediate stream exception (by-passing reporter) */ if (prob.getSeverity() > XMLValidationProblem.SEVERITY_ERROR) { throw WstxValidationException.create(prob); } XMLReporter rep = mConfig.getProblemReporter(); if (rep != null) { doReportProblem(rep, prob); } else { /* If no reporter, regular non-fatal errors are to be reported * as exceptions as well, for backwards compatibility */ if (prob.getSeverity() >= XMLValidationProblem.SEVERITY_ERROR) { throw WstxValidationException.create(prob); } } }
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)); }
protected void verifyXmlEncoding(ReaderConfig cfg) throws XMLStreamException { String inputEnc = mInputEncoding; // Close enough? if (StringUtil.equalEncodings(inputEnc, mFoundEncoding)) { return; } /* Ok, maybe the difference is just with endianness indicator? * (UTF-16BE vs. UTF-16)? */ // !!! TBI XMLReporter rep = cfg.getXMLReporter(); if (rep != null) { Location loc = getLocation(); String msg = MessageFormat.format(ErrorConsts.W_MIXED_ENCODINGS, new Object[] { mFoundEncoding, inputEnc }); String type = ErrorConsts.WT_XML_DECL; /* 30-May-2008, tatus: Should wrap all the info as XMValidationProblem * since that's Woodstox' contract wrt. relatedInformation field. */ XMLValidationProblem prob = new XMLValidationProblem(loc, msg, XMLValidationProblem.SEVERITY_WARNING, type); rep.report(msg, type, prob, loc); } }
public SAX2StAXBaseWriter(XMLReporter reporter) { this.reporter = reporter; }
public void setXMLReporter(XMLReporter reporter) { this.reporter = reporter; }
/** *One must call reset before using any of the function. */ public void reset(PropertyManager propertyManager){ fXMLReporter = (XMLReporter)propertyManager.getProperty(XMLInputFactory.REPORTER); }
@Override public XMLReporter getXMLReporter() { throw new UnsupportedOperationException("Not supported yet."); }
@Override public void setXMLReporter(XMLReporter reporter) { throw new UnsupportedOperationException("Not supported yet."); }
@Override public XMLReporter getXMLReporter() { return defaultImpl.getXMLReporter(); }
@Override public void setXMLReporter(XMLReporter reporter) { defaultImpl.setXMLReporter(reporter); }
@Override public XMLReporter getXMLReporter() { return null; }
public XMLReporter getXMLReporter() { return reporter; }