List of usage examples for org.xml.sax SAXParseException getColumnNumber
public int getColumnNumber()
From source file:com.tc.config.schema.setup.StandardXMLFileConfigurationCreator.java
private TcConfiguration getConfigFromSourceStream(InputStream in, boolean trustedSource, String descrip, String source, ClassLoader loader) throws ConfigurationSetupException { TcConfiguration tcConfigDoc;//from w ww . j av a2s . c o m try { ByteArrayOutputStream dataCopy = new ByteArrayOutputStream(); IOUtils.copy(in, dataCopy); in.close(); InputStream copyIn = new ByteArrayInputStream(dataCopy.toByteArray()); BeanWithErrors beanWithErrors = beanFactory.createBean(copyIn, descrip, source, loader); if (beanWithErrors.errors() != null && beanWithErrors.errors().length > 0) { logger.debug("Configuration didn't parse; it had " + beanWithErrors.errors().length + " error(s)."); StringBuffer buf = new StringBuffer(); for (int i = 0; i < beanWithErrors.errors().length; ++i) { SAXParseException error = beanWithErrors.errors()[i]; buf.append(" [" + i + "]: Line " + error.getLineNumber() + ", column " + error.getColumnNumber() + ": " + error.getMessage() + "\n"); } throw new ConfigurationSetupException("The configuration data in the " + descrip + " does not obey the Terracotta schema:\n" + buf); } else { logger.debug("Configuration is valid."); } tcConfigDoc = ((TcConfiguration) beanWithErrors.bean()); this.providedTcConfigDocument = tcConfigDoc; } catch (IOException ioe) { throw new ConfigurationSetupException("We were unable to read configuration data from the " + descrip + ": " + ioe.getLocalizedMessage(), ioe); } catch (SAXException saxe) { throw new ConfigurationSetupException("The configuration data in the " + descrip + " is not well-formed XML: " + saxe.getLocalizedMessage(), saxe); } catch (ParserConfigurationException pce) { throw Assert.failure("The XML parser can't be configured correctly; this should not happen.", pce); } return tcConfigDoc; }
From source file:com.wwidesigner.gui.StudyView.java
/** * Display a message box reporting a processing exception. * //ww w. j a v a 2 s .c om * @param ex * - the exception encountered. */ public void showException(Exception ex) { Exception exception = ex; Throwable cause = exception.getCause(); if (exception instanceof DataModelException && cause instanceof Exception) { // We use DataModelExceptions as a wrapper for more specific cause // exception. exception = (Exception) cause; cause = exception.getCause(); } int messageType = MessageDialogRequest.ERROR_STYLE; // Message box // style. final String exceptionType; // Message box title. String exceptionMessage = exception.getMessage(); // Message box text. boolean withTrace = false; // true to print on console log. if (exception instanceof DataOpenException) { DataOpenException doException = (DataOpenException) exception; exceptionType = doException.getType(); messageType = doException.isWarning() ? MessageDialogRequest.WARNING_STYLE : MessageDialogRequest.ERROR_STYLE; } else if (exception instanceof InvalidFieldException) { InvalidFieldException fldException = (InvalidFieldException) exception; exceptionType = fldException.getLabel(); fldException.printMessages(); } else if (exception instanceof HoleNumberMismatchException) { exceptionType = "Hole number mismatch"; messageType = MessageDialogRequest.WARNING_STYLE; } else if (exception instanceof UnmarshalException || exception instanceof MarshalException) { exceptionType = "Invalid XML Definition"; exceptionMessage = "Invalid XML structure.\n"; exceptionMessage += exception.getCause().getMessage(); if (cause instanceof SAXParseException) { SAXParseException parseEx = (SAXParseException) cause; exceptionMessage += "\nAt line " + parseEx.getLineNumber() + ", column " + parseEx.getColumnNumber() + "."; } } else if (exception instanceof DataModelException) { withTrace = true; exceptionType = "Error in data model"; } else if (exception instanceof ZeroException) { exceptionType = "Operation cannot be performed"; exceptionMessage = "Optimization requires at least 1 variable."; messageType = MessageDialogRequest.ERROR_STYLE; } else if (exception instanceof OperationCancelledException) { exceptionType = "Operation cancelled"; messageType = MessageDialogRequest.WARNING_STYLE; } else if (exception instanceof OptimizerMismatchException) { exceptionType = "Operation cancelled"; messageType = MessageDialogRequest.ERROR_STYLE; } else { withTrace = true; exceptionType = "Operation failed"; } // showException can be called on any thread, but message dialog must // run on the AWT thread. final String dialogMessage = exceptionMessage; final int dialogType = messageType; SwingUtilities.invokeLater(new Runnable() { public void run() { MessageDialogRequest.showMessageDialog(getApplication(), dialogMessage, exceptionType, dialogType); } }); if (withTrace) { System.out.println(exception.getClass().getName() + " Exception: " + exceptionMessage); exception.printStackTrace(); } }
From source file:edu.ku.brc.specify.toycode.mexconabio.FileMakerToMySQL.java
/** * <p>Handles any non-fatal errors generated by incorrect user input.</p> *//*from w w w .jav a2s . co 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 va 2 s. com public void fatalError(SAXParseException exception) { System.err.println("line " + exception.getLineNumber() + ": col. " + exception.getColumnNumber() + ": " + exception.getMessage()); }
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 {/* w w w. j a v a2s . c o m*/ // 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:net.billylieurance.azuresearch.AbstractAzureSearchQuery.java
/** * * @param is An InputStream holding some XML that needs parsing * @return a parsed Document from the XML in the stream *//*from w w w. ja v a2 s . c o m*/ public Document loadXMLFromStream(InputStream is) { DocumentBuilderFactory factory; DocumentBuilder builder; BOMInputStream bis; String dumpable = ""; try { factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); bis = new BOMInputStream(is); if (_debug) { java.util.Scanner s = new java.util.Scanner(bis).useDelimiter("\\A"); dumpable = s.hasNext() ? s.next() : ""; // convert String into InputStream InputStream istwo = new java.io.ByteArrayInputStream(dumpable.getBytes()); return builder.parse(istwo); } else { return builder.parse(bis); } } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { if (e instanceof SAXParseException) { SAXParseException ex = (SAXParseException) e; System.out.println("Line: " + ex.getLineNumber()); System.out.println("Col: " + ex.getColumnNumber()); System.out.println("Data: " + dumpable); } e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return null; }
From source file:com.meidusa.amoeba.context.ProxyRuntimeContext.java
private ProxyServerConfig loadConfig(String configFileName) { DocumentBuilder db;/*from ww w. j av a2 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:org.kite9.diagram.server.AbstractKite9Controller.java
protected void handleException(Exception ee, OutputStream os) { StringBuilder out = new StringBuilder(); if (ee instanceof SAXParseException) { SAXParseException e = (SAXParseException) ee; out.append("<html><head><title>Validation Error</title></head><body>\n"); out.append("<h1>Validation Error</h1>\n"); out.append("<p>Line: " + e.getLineNumber() + "</p>\n"); out.append("<p>Column: " + e.getColumnNumber() + "</p>\n"); formatMessage(out, e.getMessage()); } else {/*www . ja v a 2 s . c o m*/ out.append("<html><head><title>XML Error</title></head><body>\n"); out.append("<h1>Validation Error</h1>\n"); formatMessage(out, ee.getMessage()); } PrintWriter psw = new PrintWriter(os); psw.append(out.toString()); psw.append("<h2>Detail: </h2>\n"); psw.append("<pre>/n"); ee.printStackTrace(psw); psw.append("</pre></body></html>"); psw.close(); }
From source file:info.extensiblecatalog.OAIToolkit.api.Importer.java
private boolean checkXml(File xmlFile) { try {/*from w w w. j a va2s . c o m*/ // Check for well formedness of the document boolean isWellFormed = XMLUtil.isWellFormed2(xmlFile); if (!isWellFormed) { prglog.error("[PRG] The file " + xmlFile.getName() + " is an invalid XML file"); libloadlog.error("[LIB] The file " + xmlFile.getName() + " is an invalid XML file"); return false; } // Check if the file complies to the MARC schema List<SAXParseException> errors = XMLUtil.validate(xmlFile, configuration.getMarcSchema()); // If errors are found, log them if (errors.size() != 0) { prglog.error("[PRG] The file " + xmlFile.getName() + " is an invalid MARCXML file"); libloadlog.error("[LIB] The file " + xmlFile.getName() + " is an invalid MARCXML file"); libloadlog.error("[LIB] The following errors were encountered during validation."); for (SAXParseException parseException : errors) { libloadlog.error("[LIB] Location: " + parseException.getLineNumber() + ":" + parseException.getColumnNumber()); libloadlog.error("[LIB] Error: " + parseException.getMessage()); } return false; } //boolean isValid = XMLUtil.validate(xmlFile, schemaFile, configuration.isNeedLogDetail()); if (configuration.isNeedLogDetail()) { prglog.info("[PRG] This file " + xmlFile.getName() + "is a valid MARCXML file."); } return true; } catch (Exception e) { String error = "The XML file (" + xmlFile.getName() + ") " + "isn't well formed. Please correct the errors and " + "load again. Error description: " + e.getMessage(); if (e instanceof SAXParseException) { error += " Location: " + ((SAXParseException) e).getLineNumber() + ":" + ((SAXParseException) e).getColumnNumber() + "."; } libloadlog.error("[LIB] " + error); File xmlErrorFile = new File(dirNameGiver.getLoadError(), xmlFile.getName()); if (xmlErrorFile.exists()) { boolean deleted = xmlErrorFile.delete(); prglog.info("[PRG] Delete " + xmlErrorFile + " - " + deleted); } boolean remove = xmlFile.renameTo(xmlErrorFile); if (configuration.isNeedLogDetail()) { prglog.info("[PRG] Remove XML file (" + xmlFile.getName() + ") to error_xml directory: " + remove); } importStatistics.add(ImportType.INVALID_FILES); return false; } }
From source file:fll.subjective.SubjectiveFrame.java
/** * Load data. Meant for testing. Most users should use #promptForFile(). * /* www .j ava 2 s . c o m*/ * @param file where to read the data in from and where to save data to * @throws IOException */ public void load(final File file) throws IOException { _file = file; ZipFile zipfile = null; try { zipfile = new ZipFile(file); final ZipEntry challengeEntry = zipfile.getEntry(DownloadSubjectiveData.CHALLENGE_ENTRY_NAME); if (null == challengeEntry) { throw new FLLRuntimeException( "Unable to find challenge descriptor in file, you probably choose the wrong file or it is corrupted"); } final InputStream challengeStream = zipfile.getInputStream(challengeEntry); _challengeDocument = ChallengeParser .parse(new InputStreamReader(challengeStream, Utilities.DEFAULT_CHARSET)); challengeStream.close(); _challengeDescription = new ChallengeDescription(_challengeDocument.getDocumentElement()); final ZipEntry scoreEntry = zipfile.getEntry(DownloadSubjectiveData.SCORE_ENTRY_NAME); if (null == scoreEntry) { throw new FLLRuntimeException( "Unable to find score data in file, you probably choose the wrong file or it is corrupted"); } final InputStream scoreStream = zipfile.getInputStream(scoreEntry); _scoreDocument = XMLUtils.parseXMLDocument(scoreStream); scoreStream.close(); final ZipEntry scheduleEntry = zipfile.getEntry(DownloadSubjectiveData.SCHEDULE_ENTRY_NAME); if (null != scheduleEntry) { ObjectInputStream scheduleStream = null; try { scheduleStream = new ObjectInputStream(zipfile.getInputStream(scheduleEntry)); _schedule = (TournamentSchedule) scheduleStream.readObject(); } finally { IOUtils.closeQuietly(scheduleStream); } } else { _schedule = null; } final ZipEntry mappingEntry = zipfile.getEntry(DownloadSubjectiveData.MAPPING_ENTRY_NAME); if (null != mappingEntry) { ObjectInputStream mappingStream = null; try { mappingStream = new ObjectInputStream(zipfile.getInputStream(mappingEntry)); // ObjectStream isn't type safe @SuppressWarnings("unchecked") final Collection<CategoryColumnMapping> mappings = (Collection<CategoryColumnMapping>) mappingStream .readObject(); _scheduleColumnMappings = mappings; } finally { IOUtils.closeQuietly(mappingStream); } } else { _scheduleColumnMappings = null; } } catch (final ClassNotFoundException e) { throw new FLLInternalException("Internal error loading schedule from data file", e); } 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()); throw new FLLRuntimeException(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"; throw new FLLRuntimeException(errorMessage, se); } finally { if (null != zipfile) { try { zipfile.close(); } catch (final IOException e) { LOGGER.debug("Error closing zipfile", e); } } } for (final ScoreCategory subjectiveCategory : getChallengeDescription().getSubjectiveCategories()) { createSubjectiveTable(tabbedPane, subjectiveCategory); } // get the name and location of the tournament final Element top = _scoreDocument.getDocumentElement(); final String tournamentName = top.getAttribute("tournamentName"); if (top.hasAttribute("tournamentLocation")) { final String tournamentLocation = top.getAttribute("tournamentName"); setTitle(String.format("Subjective Score Entry - %s @ %s", tournamentName, tournamentLocation)); } else { setTitle(String.format("Subjective Score Entry - %s", tournamentName)); } pack(); }