com.sun.org.apache.xerces.internal.util.MessageFormatter

Here are the examples of the java api class com.sun.org.apache.xerces.internal.util.MessageFormatter taken from open source projects.

1. XMLErrorReporter#reportError()

Project: openjdk
Source File: XMLErrorReporter.java
View license
// reportError(XMLLocator,String,String,Object[],short):String
/**
     * Reports an error at a specific location.
     *
     * @param location  The error location.
     * @param domain    The error domain.
     * @param key       The key of the error message.
     * @param arguments The replacement arguments for the error message,
     *                  if needed.
     * @param severity  The severity of the error.
     * @param exception The exception to wrap.
     * @return          The formatted error message.
     *
     * @see #SEVERITY_WARNING
     * @see #SEVERITY_ERROR
     * @see #SEVERITY_FATAL_ERROR
     */
public String reportError(XMLLocator location, String domain, String key, Object[] arguments, short severity, Exception exception) throws XNIException {
    // REVISIT: [Q] Should we do anything about invalid severity
    //              parameter? -Ac
    // format error message and create parse exception
    MessageFormatter messageFormatter = getMessageFormatter(domain);
    String message;
    if (messageFormatter != null) {
        message = messageFormatter.formatMessage(fLocale, key, arguments);
    } else {
        StringBuffer str = new StringBuffer();
        str.append(domain);
        str.append('#');
        str.append(key);
        int argCount = arguments != null ? arguments.length : 0;
        if (argCount > 0) {
            str.append('?');
            for (int i = 0; i < argCount; i++) {
                str.append(arguments[i]);
                if (i < argCount - 1) {
                    str.append('&');
                }
            }
        }
        message = str.toString();
    }
    XMLParseException parseException = (exception != null) ? new XMLParseException(location, message, exception) : new XMLParseException(location, message);
    // get error handler
    XMLErrorHandler errorHandler = fErrorHandler;
    if (errorHandler == null) {
        if (fDefaultErrorHandler == null) {
            fDefaultErrorHandler = new DefaultErrorHandler();
        }
        errorHandler = fDefaultErrorHandler;
    }
    // call error handler
    switch(severity) {
        case SEVERITY_WARNING:
            {
                errorHandler.warning(domain, key, parseException);
                break;
            }
        case SEVERITY_ERROR:
            {
                errorHandler.error(domain, key, parseException);
                break;
            }
        case SEVERITY_FATAL_ERROR:
            {
                errorHandler.fatalError(domain, key, parseException);
                if (!fContinueAfterFatalError) {
                    throw parseException;
                }
                break;
            }
    }
    return message;
}

2. XMLSchemaLoader#xsdToXMLInputSource()

Project: openjdk
Source File: XMLSchemaLoader.java
View license
//processJAXPSchemaSource
private XMLInputSource xsdToXMLInputSource(Object val) {
    if (val instanceof String) {
        // String value is treated as a URI that is passed through the
        // EntityResolver
        String loc = (String) val;
        fXSDDescription.reset();
        fXSDDescription.setValues(null, loc, null, null);
        XMLInputSource xis = null;
        try {
            xis = fEntityManager.resolveEntity(fXSDDescription);
        } catch (IOException ex) {
            fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "schema_reference.4", new Object[] { loc }, XMLErrorReporter.SEVERITY_ERROR);
        }
        if (xis == null) {
            // Treat value as a URI and pass in as systemId
            return new XMLInputSource(null, loc, null, false);
        }
        return xis;
    } else if (val instanceof InputSource) {
        return saxToXMLInputSource((InputSource) val);
    } else if (val instanceof InputStream) {
        return new XMLInputSource(null, null, null, (InputStream) val, null);
    } else if (val instanceof File) {
        File file = (File) val;
        InputStream is = null;
        try {
            is = new BufferedInputStream(new FileInputStream(file));
        } catch (FileNotFoundException ex) {
            fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "schema_reference.4", new Object[] { file.toString() }, XMLErrorReporter.SEVERITY_ERROR);
        }
        return new XMLInputSource(null, file.toURI().toString(), null, is, null);
    }
    MessageFormatter mf = fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN);
    throw new XMLConfigurationException(Status.NOT_SUPPORTED, mf.formatMessage(fErrorReporter.getLocale(), "jaxp12-schema-source-type.1", new Object[] { val != null ? val.getClass().getName() : "null" }));
}

3. StaxErrorReporter#reportError()

Project: openjdk
Source File: StaxErrorReporter.java
View license
/**
     * Reports an error at a specific location.
     *
     * @param location  The error location.
     * @param domain    The error domain.
     * @param key       The key of the error message.
     * @param arguments The replacement arguments for the error message,
     *                  if needed.
     * @param severity  The severity of the error.
     *
     * @see #SEVERITY_WARNING
     * @see #SEVERITY_ERROR
     * @see #SEVERITY_FATAL_ERROR
     */
public String reportError(XMLLocator location, String domain, String key, Object[] arguments, short severity) throws XNIException {
    // format error message and create parse exception
    MessageFormatter messageFormatter = getMessageFormatter(domain);
    String message;
    if (messageFormatter != null) {
        message = messageFormatter.formatMessage(fLocale, key, arguments);
    } else {
        StringBuffer str = new StringBuffer();
        str.append(domain);
        str.append('#');
        str.append(key);
        int argCount = arguments != null ? arguments.length : 0;
        if (argCount > 0) {
            str.append('?');
            for (int i = 0; i < argCount; i++) {
                str.append(arguments[i]);
                if (i < argCount - 1) {
                    str.append('&');
                }
            }
        }
        message = str.toString();
    }
    // call error handler
    switch(severity) {
        case SEVERITY_WARNING:
            {
                try {
                    if (fXMLReporter != null) {
                        fXMLReporter.report(message, "WARNING", null, convertToStaxLocation(location));
                    }
                } catch (XMLStreamException ex) {
                    throw new XNIException(ex);
                }
                break;
            }
        case SEVERITY_ERROR:
            {
                try {
                    if (fXMLReporter != null) {
                        fXMLReporter.report(message, "ERROR", null, convertToStaxLocation(location));
                    }
                } catch (XMLStreamException ex) {
                    throw new XNIException(ex);
                }
                break;
            }
        case SEVERITY_FATAL_ERROR:
            {
                if (!fContinueAfterFatalError) {
                    throw new XNIException(message);
                }
                break;
            }
    }
    return message;
}