javax.xml.stream.XMLReporter Java Examples

The following examples show how to use javax.xml.stream.XMLReporter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseStreamWriter.java    From woodstox with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #2
Source File: StreamScanner.java    From woodstox with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #3
Source File: ReaderBootstrapper.java    From woodstox with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #4
Source File: StreamScanner.java    From woodstox with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #5
Source File: StreamScanner.java    From woodstox with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #6
Source File: StreamScanner.java    From woodstox with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #7
Source File: StreamScanner.java    From woodstox with Apache License 2.0 5 votes vote down vote up
/**
 *<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);
        }
    }
}
 
Example #8
Source File: FullDTDReader.java    From woodstox with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #9
Source File: BaseStreamWriter.java    From woodstox with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example #10
Source File: BaseStreamWriter.java    From woodstox with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #11
Source File: SAX2StAXBaseWriter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setXMLReporter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #12
Source File: SAX2StAXBaseWriter.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public SAX2StAXBaseWriter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #13
Source File: SAX2StAXBaseWriter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public SAX2StAXBaseWriter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #14
Source File: SAX2StAXBaseWriter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void setXMLReporter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #15
Source File: StaxErrorReporter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 *One must call reset before using any of the function.
 */
public void reset(PropertyManager propertyManager){
    fXMLReporter = (XMLReporter)propertyManager.getProperty(XMLInputFactory.REPORTER);
}
 
Example #16
Source File: SAX2StAXBaseWriter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public SAX2StAXBaseWriter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #17
Source File: SAX2StAXBaseWriter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void setXMLReporter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #18
Source File: StaxErrorReporter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 *One must call reset before using any of the function.
 */
public void reset(PropertyManager propertyManager){
    fXMLReporter = (XMLReporter)propertyManager.getProperty(XMLInputFactory.REPORTER);
}
 
Example #19
Source File: SAX2StAXBaseWriter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public SAX2StAXBaseWriter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #20
Source File: WriterConfig.java    From woodstox with Apache License 2.0 4 votes vote down vote up
public XMLReporter getProblemReporter() {
    return (XMLReporter) getSpecialProperty(SP_IX_PROBLEM_REPORTER);
}
 
Example #21
Source File: StaxErrorReporter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *One must call reset before using any of the function.
 */
public void reset(PropertyManager propertyManager){
    fXMLReporter = (XMLReporter)propertyManager.getProperty(XMLInputFactory.REPORTER);
}
 
Example #22
Source File: AbstractXMLInputFactory.java    From jettison with Apache License 2.0 4 votes vote down vote up
public XMLReporter getXMLReporter() {
    return null;
}
 
Example #23
Source File: XMLInputFactoryImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public XMLReporter getXMLReporter() {
    return null;
}
 
Example #24
Source File: WriterConfig.java    From woodstox with Apache License 2.0 4 votes vote down vote up
public void setProblemReporter(XMLReporter rep) {
    setSpecialProperty(SP_IX_PROBLEM_REPORTER, rep);
}
 
Example #25
Source File: WriterConfig.java    From woodstox with Apache License 2.0 4 votes vote down vote up
/**
 * @return True, if the specified property was <b>succesfully</b>
 *    set to specified value; false if its value was not changed
 */
@Override
public boolean setProperty(String name, int id, Object value)
{
    switch (id) {
    // First, Stax 1.0 properties:

    case PROP_AUTOMATIC_NS:
        enableAutomaticNamespaces(ArgUtil.convertToBoolean(name, value));
        break;

   // // // Then Stax2 ones:

    case PROP_ENABLE_NS:
        doSupportNamespaces(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_PROBLEM_REPORTER:
        setProblemReporter((XMLReporter) value);
        break;

    case PROP_AUTOMATIC_EMPTY_ELEMENTS:
        enableAutomaticEmptyElements(ArgUtil.convertToBoolean(name, value));
        break;

    case PROP_AUTO_CLOSE_OUTPUT:
        doAutoCloseOutput(ArgUtil.convertToBoolean(name, value));
        break;

    case PROP_AUTOMATIC_NS_PREFIX:
        // value should be a String, but let's verify that:
        setAutomaticNsPrefix(value.toString());
        break;

    case PROP_TEXT_ESCAPER:
        setTextEscaperFactory((EscapingWriterFactory) value);
        break;

    case PROP_ATTR_VALUE_ESCAPER:
        setAttrValueEscaperFactory((EscapingWriterFactory) value);
        break;

        // // // Then Woodstox-specific ones:

    case PROP_USE_DOUBLE_QUOTES_IN_XML_DECL:
        doUseDoubleQuotesInXmlDecl(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_OUTPUT_CDATA_AS_TEXT:
        doOutputCDataAsText(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_COPY_DEFAULT_ATTRS:
        doCopyDefaultAttrs(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_ESCAPE_CR:
        doEscapeCr(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_ADD_SPACE_AFTER_EMPTY_ELEM:
        doAddSpaceAfterEmptyElem(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_AUTOMATIC_END_ELEMENTS:
        enableAutomaticEndElements(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_VALIDATE_STRUCTURE:
        doValidateStructure(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_VALIDATE_CONTENT:
        doValidateContent(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_VALIDATE_ATTR:
        doValidateAttributes(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_VALIDATE_NAMES:
        doValidateNames(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_FIX_CONTENT:
        doFixContent(ArgUtil.convertToBoolean(name, value));
        break;
    case PROP_OUTPUT_INVALID_CHAR_HANDLER:
        setInvalidCharHandler((InvalidCharHandler) value);
        break;
    case PROP_OUTPUT_EMPTY_ELEMENT_HANDLER:
        setEmptyElementHandler((EmptyElementHandler) value);
        break;

    case PROP_UNDERLYING_STREAM:
    case PROP_UNDERLYING_WRITER:
        throw new IllegalStateException("Can not modify per-stream-writer properties via factory");

    default:
        throw new IllegalStateException("Internal error: no handler for property with internal id "+id+".");
    }

    return true;
}
 
Example #26
Source File: XMLInputFactoryWrapper.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public XMLReporter getXMLReporter() {
    return defaultImpl.getXMLReporter();
}
 
Example #27
Source File: SAX2StAXBaseWriter.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public void setXMLReporter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #28
Source File: SAX2StAXBaseWriter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public SAX2StAXBaseWriter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #29
Source File: SAX2StAXBaseWriter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setXMLReporter(XMLReporter reporter) {
        this.reporter = reporter;
}
 
Example #30
Source File: StaxErrorReporter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *One must call reset before using any of the function.
 */
public void reset(PropertyManager propertyManager){
    fXMLReporter = (XMLReporter)propertyManager.getProperty(XMLInputFactory.REPORTER);
}