Example usage for org.xml.sax SAXParseException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Return a detail message for this exception.

Usage

From source file:SAXTreeValidator.java

/**
 * <p>/*from   w  w w. ja v  a  2 s  .com*/
 * This will report an error that has occurred; this indicates
 *   that a rule was broken, typically in validation, but that
 *   parsing can reasonably continue.
 * </p>
 *
 * @param exception <code>SAXParseException</code> that occurred.
 * @throws <code>SAXException</code> when things go wrong 
 */
public void error(SAXParseException exception) throws SAXException {

    System.out.println("**Parsing Error**\n" + "  Line:    " + exception.getLineNumber() + "\n" + "  URI:     "
            + exception.getSystemId() + "\n" + "  Message: " + exception.getMessage());
    throw new SAXException("Error encountered");
}

From source file:SAXTreeValidator.java

/**
 * <p>/*from   w w  w. ja v  a2s  .c  o  m*/
 * This will report a warning that has occurred; this indicates
 *   that while no XML rules were "broken", something appears
 *   to be incorrect or missing.
 * </p>
 *
 * @param exception <code>SAXParseException</code> that occurred.
 * @throws <code>SAXException</code> when things go wrong 
 */
public void warning(SAXParseException exception) throws SAXException {

    System.out.println("**Parsing Warning**\n" + "  Line:    " + exception.getLineNumber() + "\n"
            + "  URI:     " + exception.getSystemId() + "\n" + "  Message: " + exception.getMessage());
    throw new SAXException("Warning encountered");
}

From source file:SAXTreeValidator.java

/**
 * <p>/*from  w w  w  .j  a v a 2  s .  co m*/
 * This will report a fatal error that has occurred; this indicates
 *   that a rule has been broken that makes continued parsing either
 *   impossible or an almost certain waste of time.
 * </p>
 *
 * @param exception <code>SAXParseException</code> that occurred.
 * @throws <code>SAXException</code> when things go wrong 
 */
public void fatalError(SAXParseException exception) throws SAXException {

    System.out.println("**Parsing Fatal Error**\n" + "  Line:    " + exception.getLineNumber() + "\n"
            + "  URI:     " + exception.getSystemId() + "\n" + "  Message: " + exception.getMessage());
    throw new SAXException("Fatal Error encountered");
}

From source file:InlineSchemaValidator.java

public void validate(Validator validator, Source source, String systemId, int repetitions,
        boolean memoryUsage) {
    try {/* w  ww  .  jav  a  2  s.  c  o m*/
        long timeBefore = System.currentTimeMillis();
        long memoryBefore = Runtime.getRuntime().freeMemory();
        for (int j = 0; j < repetitions; ++j) {
            validator.validate(source);
        }
        long memoryAfter = Runtime.getRuntime().freeMemory();
        long timeAfter = System.currentTimeMillis();

        long time = timeAfter - timeBefore;
        long memory = memoryUsage ? memoryBefore - memoryAfter : Long.MIN_VALUE;
        printResults(fOut, systemId, time, memory, repetitions);
    } catch (SAXParseException e) {
        // ignore
    } catch (Exception e) {
        System.err.println("error: Parse error occurred - " + e.getMessage());
        Exception se = e;
        if (e instanceof SAXException) {
            se = ((SAXException) e).getException();
        }
        if (se != null)
            se.printStackTrace(System.err);
        else
            e.printStackTrace(System.err);

    }
}

From source file:fll.web.admin.UploadSubjectiveData.java

protected void processRequest(final HttpServletRequest request, final HttpServletResponse response,
        final ServletContext application, final HttpSession session) throws IOException, ServletException {

    final StringBuilder message = new StringBuilder();

    final File file = File.createTempFile("fll", null);
    Connection connection = null;
    try {//from  w  ww  .j  av a 2  s.c om
        // must be first to ensure the form parameters are set
        UploadProcessor.processUpload(request);

        final FileItem subjectiveFileItem = (FileItem) request.getAttribute("subjectiveFile");
        subjectiveFileItem.write(file);

        final DataSource datasource = ApplicationAttributes.getDataSource(application);
        connection = datasource.getConnection();
        saveSubjectiveData(file, Queries.getCurrentTournament(connection),
                ApplicationAttributes.getChallengeDescription(application), connection, application);
        message.append("<p id='success'><i>Subjective data uploaded successfully</i></p>");
    } catch (final SAXParseException spe) {
        final String errorMessage = String.format(
                "Error parsing file line: %d column: %d%n Message: %s%n This may be caused by using the wrong version of the software attempting to parse a file that is not subjective data.",
                spe.getLineNumber(), spe.getColumnNumber(), spe.getMessage());
        message.append("<p class='error'>" + errorMessage + "</p>");
        LOGGER.error(errorMessage, spe);
    } catch (final SAXException se) {
        final String errorMessage = "The subjective scores file was found to be invalid, check that you are parsing a subjective scores file and not something else";
        message.append("<p class='error'>" + errorMessage + "</p>");
        LOGGER.error(errorMessage, se);
    } catch (final SQLException sqle) {
        message.append("<p class='error'>Error saving subjective data into the database: " + sqle.getMessage()
                + "</p>");
        LOGGER.error(sqle, sqle);
        throw new RuntimeException("Error saving subjective data into the database", sqle);
    } catch (final ParseException e) {
        message.append(
                "<p class='error'>Error saving subjective data into the database: " + e.getMessage() + "</p>");
        LOGGER.error(e, e);
        throw new RuntimeException("Error saving subjective data into the database", e);
    } catch (final FileUploadException e) {
        message.append("<p class='error'>Error processing subjective data upload: " + e.getMessage() + "</p>");
        LOGGER.error(e, e);
        throw new RuntimeException("Error processing subjective data upload", e);
    } catch (final Exception e) {
        message.append(
                "<p class='error'>Error saving subjective data into the database: " + e.getMessage() + "</p>");
        LOGGER.error(e, e);
        throw new RuntimeException("Error saving subjective data into the database", e);
    } finally {
        if (!file.delete()) {
            LOGGER.warn("Unable to delete file " + file.getAbsolutePath() + ", setting to delete on exit");
            file.deleteOnExit();
        }
        SQLFunctions.close(connection);
    }

    session.setAttribute("message", message.toString());
    response.sendRedirect(response.encodeRedirectURL("index.jsp"));
}

From source file:edu.ku.brc.specify.toycode.mexconabio.FileMakerToMySQL.java

/**
 * <p>Handles any non-fatal errors generated by incorrect user input.</p>
 *//*w  w  w  . j  a  v  a2s  .  c  o  m*/
public void error(SAXParseException exception) {
    System.err.println("line " + exception.getLineNumber() + ": col. " + exception.getColumnNumber() + ": "
            + exception.getMessage());
}

From source file:edu.ku.brc.specify.toycode.mexconabio.FileMakerToMySQL.java

/**
 * <p>Handles any fatal errors generated by incorrect user input.</p>
 *//*  w w  w  .  j a  v a 2s  .  c  o m*/
public void fatalError(SAXParseException exception) {
    System.err.println("line " + exception.getLineNumber() + ": col. " + exception.getColumnNumber() + ": "
            + exception.getMessage());
}

From source file:manchester.synbiochem.datacapture.SeekConnector.java

private DocumentBuilder parser() throws ParserConfigurationException {
    DocumentBuilder builder = dbf.newDocumentBuilder();
    builder.setErrorHandler(new DefaultHandler() {
        @Override/*from   w  w w. j a  v a2s .  c  o m*/
        public void warning(SAXParseException exception) throws SAXException {
            log.warn(exception.getMessage());
        }

        @Override
        public void error(SAXParseException exception) throws SAXException {
            log.error(exception.getMessage(), exception);
        }
    });
    return builder;
}

From source file:com.meidusa.amoeba.context.ProxyRuntimeContext.java

private ProxyServerConfig loadConfig(String configFileName) {
    DocumentBuilder db;/*w w  w.j  ava  2 s  .  c  o  m*/

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);
        dbf.setNamespaceAware(false);

        db = dbf.newDocumentBuilder();
        db.setEntityResolver(new EntityResolver() {

            public InputSource resolveEntity(String publicId, String systemId) {
                if (systemId.endsWith("amoeba.dtd")) {
                    InputStream in = ProxyRuntimeContext.class
                            .getResourceAsStream("/com/meidusa/amoeba/xml/amoeba.dtd");
                    if (in == null) {
                        LogLog.error("Could not find [amoeba.dtd]. Used ["
                                + ProxyRuntimeContext.class.getClassLoader() + "] class loader in the search.");
                        return null;
                    } else {
                        return new InputSource(in);
                    }
                } else {
                    return null;
                }
            }
        });

        db.setErrorHandler(new ErrorHandler() {

            public void warning(SAXParseException exception) {
            }

            public void error(SAXParseException exception) throws SAXException {
                logger.error(exception.getMessage() + " at (" + exception.getLineNumber() + ":"
                        + exception.getColumnNumber() + ")");
                throw exception;
            }

            public void fatalError(SAXParseException exception) throws SAXException {
                logger.fatal(exception.getMessage() + " at (" + exception.getLineNumber() + ":"
                        + exception.getColumnNumber() + ")");
                throw exception;
            }
        });
        return loadConfigurationFile(configFileName, db);
    } catch (Exception e) {
        logger.fatal("Could not load configuration file, failing", e);
        throw new ConfigurationException("Error loading configuration file " + configFileName, e);
    }
}

From source file:com.stratelia.webactiv.util.XMLConfigurationStore.java

private void load(String configFileName, InputStream configFileInputStream, String rootString)
        throws Exception {
    this.configFileName = configFileName;
    try {// www  .j a  va 2 s  .c o m
        // if config file was found by the resource locator, it is an input
        // stream,
        // otherwise it is a file
        // javax.xml.parsers.DocumentBuilderFactory dbf =
        // DocumentBuilderFactory.newInstance();
        // javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
        DOMParser parser = new DOMParser();

        if (configFileInputStream == null) {
            // FileInputStream is = new FileInputStream(new File(configFileName));
            SilverTrace.debug("util", "ResourceLocator.locateResourceAsStream", "Parsing from file",
                    configFileName);

            // m_XMLConfig = db.parse(is);
            try {
                String cname = "file:///" + configFileName.replace('\\', '/');
                parser.parse(cname);
            } catch (SAXException se) {
                SilverTrace.error("util", "ResourceLocator.load", "root.EX_XML_PARSING_FAILED", se);
                throw se;
            } catch (IOException ioe) {
                SilverTrace.error("util", "ResourceLocator.load", "root.EX_LOAD_IO_EXCEPTION", ioe);
                throw ioe;
            }
        } else {
            org.xml.sax.InputSource ins = new org.xml.sax.InputSource(configFileInputStream);
            parser.parse(ins);
        }

        xmlConfigDOMDoc = parser.getDocument();
        doLoad(rootString);
    } catch (IOException e) {
        throw new Exception(
                "E6000-0020:Cannot open configuration file '" + configFileName + "': Error:" + e.getMessage());
    } catch (SAXParseException err) {
        throw new Exception(
                "E6000-0022:Cannot parse configuration file '" + configFileName + "'" + ": Error at line "
                        + err.getLineNumber() + ", uri '" + err.getSystemId() + "': " + err.getMessage());
    } catch (Exception e) {
        throw new Exception(
                "E6000-0021:Cannot open configuration file '" + configFileName + "': Error:" + e.getMessage());
    }
}