Example usage for org.xml.sax SAXParseException getColumnNumber

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

Introduction

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

Prototype

public int getColumnNumber() 

Source Link

Document

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

Usage

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Create a window to edit subjective scores.
 *//*from  w ww. j a va 2s .  c  o m*/
public SubjectiveFrame() {
    super("Subjective Score Entry");
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    getContentPane().setLayout(new BorderLayout());

    final JPanel topPanel = new JPanel();
    getContentPane().add(topPanel, BorderLayout.NORTH);

    final JButton quitButton = new JButton("Quit");
    topPanel.add(quitButton);
    quitButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent ae) {
            quit();
        }
    });

    final JButton saveButton = new JButton("Save");
    topPanel.add(saveButton);
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent ae) {
            try {
                save();
            } catch (final IOException ioe) {
                JOptionPane.showMessageDialog(null, "Error writing to data file: " + ioe.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
            }

        }
    });

    final JButton summaryButton = new JButton("Summary");
    topPanel.add(summaryButton);
    summaryButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent ae) {
            final SummaryDialog dialog = new SummaryDialog(SubjectiveFrame.this);

            dialog.pack();
            dialog.setVisible(true);
        }
    });

    final JButton compareButton = new JButton("Compare Scores");
    topPanel.add(compareButton);
    compareButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent ae) {
            final File compareFile = chooseSubjectiveFile("Choose the file to compare with");
            if (null != compareFile) {
                try {
                    save();
                } catch (final IOException ioe) {
                    JOptionPane.showMessageDialog(null, "Error writing to data file: " + ioe.getMessage(),
                            "Error", JOptionPane.ERROR_MESSAGE);
                }

                try {
                    final Collection<SubjectiveScoreDifference> diffs = SubjectiveUtils
                            .compareSubjectiveFiles(getFile(), compareFile);
                    if (null == diffs) {
                        JOptionPane.showMessageDialog(null,
                                "Challenge descriptors are different, comparison failed", "Error",
                                JOptionPane.ERROR_MESSAGE);

                    } else if (!diffs.isEmpty()) {
                        showDifferencesDialog(diffs);
                    } else {
                        JOptionPane.showMessageDialog(null, "No differences found", "No Differences",
                                JOptionPane.INFORMATION_MESSAGE);

                    }
                } 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());
                    LOGGER.error(errorMessage, spe);
                    JOptionPane.showMessageDialog(null, errorMessage, "Error", JOptionPane.ERROR_MESSAGE);
                } 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";
                    LOGGER.error(errorMessage, se);
                    JOptionPane.showMessageDialog(null, errorMessage, "Error", JOptionPane.ERROR_MESSAGE);
                } catch (final IOException e) {
                    LOGGER.error("Error reading compare file", e);
                    JOptionPane.showMessageDialog(null, "Error reading compare file: " + e.getMessage(),
                            "Error", JOptionPane.ERROR_MESSAGE);

                }
            }
        }
    });

    tabbedPane = new JTabbedPane();
    getContentPane().add(tabbedPane, BorderLayout.CENTER);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent e) {
            quit();
        }
    });

    pack();
}

From source file:Counter.java

/** Prints the error message. */
protected void printError(String type, SAXParseException ex) {

    System.err.print("[");
    System.err.print(type);/*from   w  w  w.  j a  va  2  s  .  c o m*/
    System.err.print("] ");
    if (ex == null) {
        System.out.println("!!!");
    }
    String systemId = ex.getSystemId();
    if (systemId != null) {
        int index = systemId.lastIndexOf('/');
        if (index != -1)
            systemId = systemId.substring(index + 1);
        System.err.print(systemId);
    }
    System.err.print(':');
    System.err.print(ex.getLineNumber());
    System.err.print(':');
    System.err.print(ex.getColumnNumber());
    System.err.print(": ");
    System.err.print(ex.getMessage());
    System.err.println();
    System.err.flush();

}

From source file:catalina.startup.ContextConfig.java

/**
 * Process the application configuration file, if it exists.
 *//* ww w  . j  a va 2 s.  c  om*/
private void applicationConfig() {

    // Open the application web.xml file, if it exists
    InputStream stream = null;
    ServletContext servletContext = context.getServletContext();
    if (servletContext != null)
        stream = servletContext.getResourceAsStream(Constants.ApplicationWebXml);
    if (stream == null) {
        log(sm.getString("contextConfig.applicationMissing"));
        return;
    }

    // Process the application web.xml file
    synchronized (webDigester) {
        try {
            URL url = servletContext.getResource(Constants.ApplicationWebXml);

            InputSource is = new InputSource(url.toExternalForm());
            is.setByteStream(stream);
            webDigester.setDebug(getDebug());
            if (context instanceof StandardContext) {
                ((StandardContext) context).setReplaceWelcomeFiles(true);
            }
            webDigester.clear();
            webDigester.push(context);
            webDigester.parse(is);
        } catch (SAXParseException e) {
            log(sm.getString("contextConfig.applicationParse"), e);
            log(sm.getString("contextConfig.applicationPosition", "" + e.getLineNumber(),
                    "" + e.getColumnNumber()));
            ok = false;
        } catch (Exception e) {
            log(sm.getString("contextConfig.applicationParse"), e);
            ok = false;
        } finally {
            try {
                if (stream != null) {
                    stream.close();
                }
            } catch (IOException e) {
                log(sm.getString("contextConfig.applicationClose"), e);
            }
        }
    }

}

From source file:com.hp.hpl.inkml.InkMLDOMParser.java

/** Prints the error message. */
private void printError(final String messageType, final SAXParseException exception) {

    System.err.print("[");
    System.err.print(messageType);
    System.err.print("] ");
    String systemId = exception.getSystemId();
    if (systemId != null) {
        final int index = systemId.lastIndexOf('/');
        if (index != -1) {
            systemId = systemId.substring(index + 1);
        }/*from  w  ww.j  av  a 2s . com*/
        System.err.print(systemId);
    }
    System.err.print(':');
    System.err.print(exception.getLineNumber());
    System.err.print(':');
    System.err.print(exception.getColumnNumber());
    System.err.print(": ");
    System.err.print(exception.getMessage());
    System.err.println();
    System.err.flush();

}

From source file:Writer.java

/** Prints the error message. */
protected void printError(String type, SAXParseException ex) {

    System.err.print("[");
    System.err.print(type);// www.  jav  a 2s  . c  o  m
    System.err.print("] ");
    String systemId = ex.getSystemId();
    if (systemId != null) {
        int index = systemId.lastIndexOf('/');
        if (index != -1)
            systemId = systemId.substring(index + 1);
        System.err.print(systemId);
    }
    System.err.print(':');
    System.err.print(ex.getLineNumber());
    System.err.print(':');
    System.err.print(ex.getColumnNumber());
    System.err.print(": ");
    System.err.print(ex.getMessage());
    System.err.println();
    System.err.flush();

}

From source file:de.escidoc.core.common.util.xml.XmlUtility.java

/**
 * Validates the provided XML data using the specified schema.<br> The provided {@code ByteArrayInputStream} is
 * reset after validation.// w  ww.  j av a2  s. c o  m
 *
 * @param byteArrayInputStream The XML data to validate in an {@code ByteArrayInputStream}.<br> This input
 *                             stream is reset after the validation.
 * @param schemaUri            The URL identifying the schema that shall be used for validation.
 * @throws XmlCorruptedException        Thrown if the XML data cannot be parsed.
 * @throws XmlSchemaValidationException Thrown if both validation fail or only one validation is executed and fails
 * @throws WebserverSystemException     Thrown in any other case.
 */
public void validate(final ByteArrayInputStream byteArrayInputStream, final String schemaUri)
        throws XmlCorruptedException, XmlSchemaValidationException, WebserverSystemException {

    try {
        final Validator validator = getSchema(schemaUri).newValidator();
        validator.validate(new SAXSource(new InputSource(byteArrayInputStream)));
    } catch (final SAXParseException e) {
        final String errorMsg = "Error in line " + e.getLineNumber() + ", column " + e.getColumnNumber() + ". "
                + e.getMessage();
        if (e.getMessage().startsWith("cvc")) {
            throw new XmlSchemaValidationException(errorMsg, e);
        } else {
            throw new XmlCorruptedException(errorMsg, e);
        }
    } catch (final Exception e) {
        throw new WebserverSystemException(e.getMessage(), e);
    } finally {
        if (byteArrayInputStream != null) {
            byteArrayInputStream.reset();
        }
    }
}

From source file:nl.b3p.viewer.admin.stripes.GeoServiceActionBean.java

public Resolution validateSldXml() {
    Resolution jsp = new ForwardResolution(JSP_EDIT_SLD);
    Document sldXmlDoc = null;//ww w.j a  v a  2s  . co m
    String stage = "Fout bij parsen XML document";
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder db = dbf.newDocumentBuilder();

        sldXmlDoc = db.parse(new ByteArrayInputStream(sld.getSldBody().getBytes("UTF-8")));

        stage = "Fout bij controleren SLD";

        Element root = sldXmlDoc.getDocumentElement();
        if (!"StyledLayerDescriptor".equals(root.getLocalName())) {
            throw new Exception("Root element moet StyledLayerDescriptor zijn");
        }
        String version = root.getAttribute("version");
        if (version == null || !("1.0.0".equals(version) || "1.1.0".equals(version))) {
            throw new Exception("Geen of ongeldige SLD versie!");
        }

        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema s = sf
                .newSchema(new URL("http://schemas.opengis.net/sld/" + version + "/StyledLayerDescriptor.xsd"));
        s.newValidator().validate(new DOMSource(sldXmlDoc));

    } catch (Exception e) {
        String extra = "";
        if (e instanceof SAXParseException) {
            SAXParseException spe = (SAXParseException) e;
            if (spe.getLineNumber() != -1) {
                extra = " (regel " + spe.getLineNumber();
                if (spe.getColumnNumber() != -1) {
                    extra += ", kolom " + spe.getColumnNumber();
                }
                extra += ")";
            }
        }
        getContext().getValidationErrors()
                .addGlobalError(new SimpleError("{2}: {3}{4}", stage, ExceptionUtils.getMessage(e), extra));
        return jsp;
    }

    getContext().getMessages().add(new SimpleMessage("SLD is valide!"));

    return jsp;
}

From source file:nl.nn.adapterframework.core.IbisException.java

public String getExceptionSpecificDetails(Throwable t) {
    String result = null;/*from  w  ww .  j  a va  2s  .  c  om*/
    if (t instanceof AddressException) {
        AddressException ae = (AddressException) t;
        String parsedString = ae.getRef();
        if (StringUtils.isNotEmpty(parsedString)) {
            result = addPart(result, " ", "[" + parsedString + "]");
        }
        int column = ae.getPos() + 1;
        if (column > 0) {
            result = addPart(result, " ", "at column [" + column + "]");
        }
    }
    if (t instanceof SAXParseException) {
        SAXParseException spe = (SAXParseException) t;
        int line = spe.getLineNumber();
        int col = spe.getColumnNumber();
        String sysid = spe.getSystemId();

        String locationInfo = null;
        if (StringUtils.isNotEmpty(sysid)) {
            locationInfo = "SystemId [" + sysid + "]";
        }
        if (line >= 0) {
            locationInfo = addPart(locationInfo, " ", "line [" + line + "]");
        }
        if (col >= 0) {
            locationInfo = addPart(locationInfo, " ", "column [" + col + "]");
        }
        result = addPart(locationInfo, ": ", result);
    }
    if (t instanceof TransformerException) {
        TransformerException te = (TransformerException) t;
        SourceLocator locator = te.getLocator();
        if (locator != null) {
            int line = locator.getLineNumber();
            int col = locator.getColumnNumber();
            String sysid = locator.getSystemId();

            String locationInfo = null;
            if (StringUtils.isNotEmpty(sysid)) {
                locationInfo = "SystemId [" + sysid + "]";
            }
            if (line >= 0) {
                locationInfo = addPart(locationInfo, " ", "line [" + line + "]");
            }
            if (col >= 0) {
                locationInfo = addPart(locationInfo, " ", "column [" + col + "]");
            }
            result = addPart(locationInfo, ": ", result);
        }
    }
    if (t instanceof SQLException) {
        SQLException sqle = (SQLException) t;
        int errorCode = sqle.getErrorCode();
        String sqlState = sqle.getSQLState();
        if (errorCode != 0) {
            result = addPart("errorCode [" + errorCode + "]", ", ", result);
        }
        if (StringUtils.isNotEmpty(sqlState)) {
            result = addPart("SQLState [" + sqlState + "]", ", ", result);
        }
    }
    return result;
}

From source file:nl.nn.adapterframework.validation.XmlValidatorErrorHandler.java

protected void addReason(Throwable t) {
    String location = null;//from   w  w  w.ja  v  a 2 s .  c om
    if (t instanceof SAXParseException) {
        SAXParseException spe = (SAXParseException) t;
        location = "at (" + spe.getLineNumber() + "," + spe.getColumnNumber() + ")";
    }
    String message;
    if (t instanceof SAXException) {
        message = t.getMessage();
    } else {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        t.printStackTrace(printWriter);
        printWriter.close();
        message = stringWriter.toString();
    }
    addReason(message, null, location);
}

From source file:org.adl.parsers.dom.ADLDOMParser.java

/**
 * Part of the org.xml.sax.ErrorHandler interface.  The parser
 * calls this method when it wants to generate a error.  It is an interface
 * that is implemented by the ADLDOMParser.
 *
 * @param iSPE    Exception object created by the parser.
 *///from  w  ww .j ava2s  .  c  o m
public void error(SAXParseException iSPE) {
    log.debug("error()");

    // determine what state we are in to set the appropriate flags
    if (mStateIsValidating) {
        mValidFlag = false;
    } else {
        mIsXMLWellformed = false;
    }

    String msgText = iSPE.getMessage() + " line: " + iSPE.getLineNumber() + ", col: " + iSPE.getColumnNumber();

    log.debug("FAILED: " + msgText);

    DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, msgText));

    log.debug("error()");
}