List of usage examples for org.xml.sax SAXParseException getLineNumber
public int getLineNumber()
From source file:com.wwidesigner.gui.StudyView.java
/** * Display a message box reporting a processing exception. * /*from w ww . j a v a2s.co m*/ * @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 www.ja v a2 s . 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> *///from w w w . j a v a2 s. c o m 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 {//from 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:com.stratelia.webactiv.util.XMLConfigurationStore.java
private void load(String configFileName, InputStream configFileInputStream, String rootString) throws Exception { this.configFileName = configFileName; try {//from ww w. j ava 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()); } }
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 *//* w w w. java 2 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: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 {/* w w w. jav a 2 s. com*/ 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:com.meidusa.amoeba.context.ProxyRuntimeContext.java
private ProxyServerConfig loadConfig(String configFileName) { DocumentBuilder db;/*from ww w .j ava 2 s. c om*/ 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:jade.mtp.http.XMLCodec.java
/** This method is called when warning occur*/ //#DOTNET_EXCLUDE_BEGIN public void warning(SAXParseException exception) { //#DOTNET_EXCLUDE_END /*#DOTNET_INCLUDE_BEGIN public void warning(ParseException exception) { #DOTNET_INCLUDE_END*//*from ww w .j a va2 s . co m*/ if (logger.isLoggable(Logger.WARNING)) //#DOTNET_EXCLUDE_BEGIN logger.log(Logger.WARNING, " line " + exception.getLineNumber() + ": " + exception.getMessage()); //#DOTNET_EXCLUDE_END /*#DOTNET_INCLUDE_BEGIN logger.log(Logger.WARNING," line " + exception.getError() + ": " + exception.get_Message()); #DOTNET_INCLUDE_END*/ }
From source file:jade.mtp.http.XMLCodec.java
/** This method is called when errors occur*/ //#DOTNET_EXCLUDE_BEGIN public void error(SAXParseException exception) { //#DOTNET_EXCLUDE_END /*#DOTNET_INCLUDE_BEGIN public void error(ParseException exception) { #DOTNET_INCLUDE_END*///from w ww.j av a2s. c o m if (logger.isLoggable(Logger.WARNING)) //#DOTNET_EXCLUDE_BEGIN logger.log(Logger.WARNING, "ERROR: line " + exception.getLineNumber() + ": " + exception.getMessage()); //#DOTNET_EXCLUDE_END /*#DOTNET_INCLUDE_BEGIN logger.log(Logger.WARNING,"ERROR: line " + exception.getError() + ": " + exception.get_Message()); #DOTNET_INCLUDE_END*/ }