Example usage for org.xml.sax SAXParseException getLineNumber

List of usage examples for org.xml.sax SAXParseException getLineNumber

Introduction

In this page you can find the example usage for org.xml.sax SAXParseException getLineNumber.

Prototype

public int getLineNumber() 

Source Link

Document

The line number of the end of the text where the exception occurred.

Usage

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.StreamsConfigSAXParser.java

/**
 * Reads the configuration and invokes the (SAX-based) parser to parse the configuration file contents.
 *
 * @param config//from  w  w w .j  a v a 2 s .c om
 *            input stream to get configuration data from
 * @param validate
 *            flag indicating whether to validate configuration XML against XSD schema
 * @return streams configuration data
 * @throws ParserConfigurationException
 *             if there is an inconsistency in the configuration
 * @throws SAXException
 *             if there was an error parsing the configuration
 * @throws IOException
 *             if there is an error reading the configuration data
 */
public static StreamsConfigData parse(InputStream config, boolean validate)
        throws ParserConfigurationException, SAXException, IOException {
    if (validate) {
        config = config.markSupported() ? config : new ByteArrayInputStream(IOUtils.toByteArray(config));

        Map<OpLevel, List<SAXParseException>> validationErrors = validate(config);

        if (MapUtils.isNotEmpty(validationErrors)) {
            for (Map.Entry<OpLevel, List<SAXParseException>> vee : validationErrors.entrySet()) {
                for (SAXParseException ve : vee.getValue()) {
                    LOGGER.log(OpLevel.WARNING,
                            StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME,
                                    "StreamsConfigSAXParser.xml.validation.error"),
                            ve.getLineNumber(), ve.getColumnNumber(), vee.getKey(), ve.getLocalizedMessage());
                }
            }
        }
    }

    Properties p = Utils.loadPropertiesResource("sax.properties"); // NON-NLS

    SAXParserFactory parserFactory = SAXParserFactory.newInstance();
    SAXParser parser = parserFactory.newSAXParser();
    ConfigParserHandler hndlr = null;
    try {
        String handlerClassName = p.getProperty(HANDLER_PROP_KEY, ConfigParserHandler.class.getName());
        if (StringUtils.isNotEmpty(handlerClassName)) {
            hndlr = (ConfigParserHandler) Utils.createInstance(handlerClassName);
        }
    } catch (Exception exc) {
    }

    if (hndlr == null) {
        hndlr = new ConfigParserHandler();
    }

    parser.parse(config, hndlr);

    return hndlr.getStreamsConfigData();
}

From source file:com.puppycrawl.tools.checkstyle.ConfigurationLoader.java

/**
 * Returns the module configurations from a specified input source.
 * Note that if the source does wrap an open byte or character
 * stream, clients are required to close that stream by themselves
 *
 * @param configSource the input stream to the Checkstyle configuration
 * @param overridePropsResolver overriding properties
 * @param omitIgnoredModules {@code true} if modules with severity
 *            'ignore' should be omitted, {@code false} otherwise
 * @return the check configurations//from   w w w .  jav  a2 s.c  om
 * @throws CheckstyleException if an error occurs
 */
public static Configuration loadConfiguration(InputSource configSource, PropertyResolver overridePropsResolver,
        boolean omitIgnoredModules) throws CheckstyleException {
    try {
        final ConfigurationLoader loader = new ConfigurationLoader(overridePropsResolver, omitIgnoredModules);
        loader.parseInputSource(configSource);
        return loader.configuration;
    } catch (final SAXParseException e) {
        final String message = String.format(Locale.ROOT, "%s - %s:%s:%s", UNABLE_TO_PARSE_EXCEPTION_PREFIX,
                e.getMessage(), e.getLineNumber(), e.getColumnNumber());
        throw new CheckstyleException(message, e);
    } catch (final ParserConfigurationException | IOException | SAXException e) {
        throw new CheckstyleException(UNABLE_TO_PARSE_EXCEPTION_PREFIX, e);
    }
}

From source file:edu.osu.ling.pep.Pep.java

/**
 * Prints a throwable.//from w  w w. j a  v a  2  s.c  o  m
 * 
 * @param error
 *            The throwable that was intercepted.
 * @see #printError(String)
 */
private static void printError(final Throwable error) {
    if (error instanceof SAXParseException) {
        final SAXParseException spe = (SAXParseException) error;
        Pep.printError("line " + spe.getLineNumber() + ": " + spe.getMessage());
    } else {
        String msg = error.getMessage();
        final Throwable cause = error.getCause();
        if (cause != null && !cause.equals(error)) {
            msg += ": " + cause.getMessage();
        }

        Pep.printError(msg);
    }
}

From source file:Main.java

public void error(SAXParseException ex) throws SAXException {
    System.out.println("ERROR: [at " + ex.getLineNumber() + "] " + ex);
}

From source file:Main.java

public void warning(SAXParseException ex) throws SAXException {
    System.out.println("WARNING: [at " + ex.getLineNumber() + "] " + ex);
}

From source file:Main.java

  public void error(SAXParseException ex) throws SAXException {
  System.out.println("ERROR: [at " + ex.getLineNumber() + "] " + ex);
}

From source file:Main.java

public void fatalError(SAXParseException ex) throws SAXException {
    System.out.println("FATAL_ERROR: [at " + ex.getLineNumber() + "] " + ex);
}

From source file:Main.java

  public void warning(SAXParseException ex) throws SAXException {
  System.out.println("WARNING: [at " + ex.getLineNumber() + "] " + ex);
}

From source file:Main.java

  public void fatalError(SAXParseException ex) throws SAXException {
  System.out.println("FATAL_ERROR: [at " + ex.getLineNumber() + "] " + ex);
}

From source file:MainClass.java

public void error(SAXParseException spe) {
    System.out.println("Error at line " + spe.getLineNumber());
    System.out.println(spe.getMessage());
}