Example usage for javax.xml.stream XMLStreamException getLocation

List of usage examples for javax.xml.stream XMLStreamException getLocation

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamException getLocation.

Prototype

public Location getLocation() 

Source Link

Document

Gets the location of the exception

Usage

From source file:org.biopax.validator.api.AbstractAspect.java

/**
 * Registers other (external) exceptions.
 * //  w w w  .  j av a2s  .  c om
 * The exception class, i.e., simple name in lower case, 
 * is used as the error code, and the 'object' is to
 * find the corresponding validation result where this 
 * problem should be added.
 * 
 * This must be public method (for unclear reason, otherwise causes an AOP exception...)
 * 
 * @param t
 * @param obj model, element, or another related to the BioPAX data object
 * @param errorCode
 * @param reportedBy 
 * @param details extra message to be added at the end of the original error message if not null
 */
public void reportException(Throwable t, Object obj, String errorCode, String reportedBy, String details) {

    StringBuilder msg = new StringBuilder(t.toString());

    if (t instanceof XMLStreamException) {
        XMLStreamException ex = (XMLStreamException) t;
        msg.append("; ").append(ex.getLocation().toString());
    } else {
        if ("exception".equals(errorCode)) //catch a bug
            msg.append(" - stack:").append(getStackTrace(t)).append(" - ");
    }

    if (details != null)
        msg.append("; ").append(details);

    if (validator != null) {
        validator.report(obj, errorCode, reportedBy, false, msg.toString());
    } else {
        log.error("utils is null (not initialized?); skipping " + "an intercepted 'syntax.error': "
                + msg.toString() + " reported by: " + reportedBy);
    }
}

From source file:org.onehippo.repository.scxml.RepositorySCXMLRegistry.java

private String naturalizeXMLStreamExceptionMessage(final XMLStreamException xse) {
    String naturalized = xse.getLocalizedMessage();
    final Matcher m = XML_STREAM_EXCEPTION_MESSAGE_PATTERN.matcher(naturalized);

    if (m.find()) {
        final String errorInfo = m.group(2);
        if (StringUtils.isNotEmpty(errorInfo)) {
            final String[] tokens = StringUtils.split(errorInfo, "#?&");
            if (!ArrayUtils.isEmpty(tokens)) {
                final Location location = xse.getLocation();
                final StringBuilder sbTemp = new StringBuilder().append("XML Stream Error at (L")
                        .append(location.getLineNumber()).append(":C").append(location.getColumnNumber())
                        .append("). Cause: ")
                        .append(StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(tokens[0]), " "));
                if (tokens.length > 1) {
                    sbTemp.append(" (").append(StringUtils.join(tokens, ", ", 1, tokens.length)).append(")");
                }/* ww  w. j  a  v a 2  s  .c om*/
                naturalized = sbTemp.toString();
            }
        }
    }

    return naturalized;
}

From source file:org.osaf.cosmo.model.text.BaseXhtmlFormat.java

protected void handleXmlException(String message, XMLStreamException e) throws ParseException {
    message += ": " + e.getMessage();
    handleException(message, e.getLocation());
}