List of usage examples for org.xml.sax SAXParseException getColumnNumber
public int getColumnNumber()
From source file:com.jkoolcloud.jesl.simulator.TNT4JSimulator.java
public static void main(String[] args) { boolean isTTY = (System.console() != null); long startTime = System.currentTimeMillis(); try {//from w w w.j a v a 2s .c o m SAXParserFactory parserFactory = SAXParserFactory.newInstance(); SAXParser theParser = parserFactory.newSAXParser(); TNT4JSimulatorParserHandler xmlHandler = new TNT4JSimulatorParserHandler(); processArgs(xmlHandler, args); TrackerConfig simConfig = DefaultConfigFactory.getInstance().getConfig(TNT4JSimulator.class.getName()); logger = TrackingLogger.getInstance(simConfig.build()); if (logger.isSet(OpLevel.TRACE)) traceLevel = OpLevel.TRACE; else if (logger.isSet(OpLevel.DEBUG)) traceLevel = OpLevel.DEBUG; if (runType == SimulatorRunType.RUN_SIM) { if (StringUtils.isEmpty(simFileName)) { simFileName = "tnt4j-sim.xml"; String fileName = readFromConsole("Simulation file [" + simFileName + "]: "); if (!StringUtils.isEmpty(fileName)) simFileName = fileName; } StringBuffer simDef = new StringBuffer(); BufferedReader simLoader = new BufferedReader(new FileReader(simFileName)); String line; while ((line = simLoader.readLine()) != null) simDef.append(line).append("\n"); simLoader.close(); info("jKool Activity Simulator Run starting: file=" + simFileName + ", iterations=" + numIterations + ", ttl.sec=" + ttl); startTime = System.currentTimeMillis(); if (isTTY && numIterations > 1) System.out.print("Iteration: "); int itTrcWidth = 0; for (iteration = 1; iteration <= numIterations; iteration++) { itTrcWidth = printProgress("Executing Iteration", iteration, itTrcWidth); theParser.parse(new InputSource(new StringReader(simDef.toString())), xmlHandler); if (!Utils.isEmpty(jkFileName)) { PrintWriter gwFile = new PrintWriter(new FileOutputStream(jkFileName, true)); gwFile.println(""); gwFile.close(); } } if (numIterations > 1) System.out.println(""); info("jKool Activity Simulator Run finished, elapsed time = " + DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - startTime)); printMetrics(xmlHandler.getSinkStats(), "Total Sink Statistics"); } else if (runType == SimulatorRunType.REPLAY_SIM) { info("jKool Activity Simulator Replay starting: file=" + jkFileName + ", iterations=" + numIterations); connect(); startTime = System.currentTimeMillis(); // Determine number of lines in file BufferedReader gwFile = new BufferedReader(new java.io.FileReader(jkFileName)); for (numIterations = 0; gwFile.readLine() != null; numIterations++) ; gwFile.close(); // Reopen the file and gwFile = new BufferedReader(new java.io.FileReader(jkFileName)); if (isTTY && numIterations > 1) System.out.print("Processing Line: "); int itTrcWidth = 0; String gwMsg; iteration = 0; while ((gwMsg = gwFile.readLine()) != null) { iteration++; if (isTTY) itTrcWidth = printProgress("Processing Line", iteration, itTrcWidth); gwConn.write(gwMsg); } if (isTTY && numIterations > 1) System.out.println(""); long endTime = System.currentTimeMillis(); info("jKool Activity Simulator Replay finished, elasped.time = " + DurationFormatUtils.formatDurationHMS(endTime - startTime)); } } catch (Exception e) { if (e instanceof SAXParseException) { SAXParseException spe = (SAXParseException) e; error("Error at line: " + spe.getLineNumber() + ", column: " + spe.getColumnNumber(), e); } else { error("Error running simulator", e); } } finally { try { Thread.sleep(1000L); } catch (Exception e) { } TNT4JSimulator.disconnect(); } System.exit(0); }
From source file:MainClass.java
static void fail(SAXException e) { if (e instanceof SAXParseException) { SAXParseException spe = (SAXParseException) e; System.err.printf("%s:%d:%d: %s%n", spe.getSystemId(), spe.getLineNumber(), spe.getColumnNumber(), spe.getMessage());/*from w w w .j av a2 s. co m*/ } else { System.err.println(e.getMessage()); } System.exit(1); }
From source file:info.magnolia.module.model.reader.BetwixtModuleDefinitionReader.java
private static String getSaxParseExceptionMessage(SAXParseException e) { return "at line " + e.getLineNumber() + " column " + e.getColumnNumber() + ": " + e.getMessage(); }
From source file:com.aol.advertising.qiao.util.XmlConfigUtil.java
/** * Validate an XML document against the given schema. * * @param xmlFileLocationUri//from w ww. j a v a2 s . com * Location URI of the document to be validated. * @param schemaLocationUri * Location URI of the XML schema in W3C XML Schema Language. * @return true if valid, false otherwise. */ public static boolean validateXml(String xmlFileLocationUri, String schemaLocationUri) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); InputStream is = null; try { Schema schema = factory.newSchema(CommonUtils.uriToURL(schemaLocationUri)); Validator validator = schema.newValidator(); URL url = CommonUtils.uriToURL(xmlFileLocationUri); is = url.openStream(); Source source = new StreamSource(is); validator.validate(source); logger.info(">> successfully validated configuration file: " + xmlFileLocationUri); return true; } catch (SAXParseException e) { logger.error(e.getMessage() + " (line:" + e.getLineNumber() + ", col:" + e.getColumnNumber() + ")"); } catch (Exception e) { if (e instanceof SAXParseException) { SAXParseException e2 = (SAXParseException) e; logger.error(e2.getMessage() + "at line:" + e2.getLineNumber() + ", col:" + e2.getColumnNumber()); } else { logger.error(e.getMessage()); } } finally { IOUtils.closeQuietly(is); } return false; }
From source file:net.sf.nmedit.jpatch.clavia.nordmodular.NM1ModuleDescriptions.java
public static NM1ModuleDescriptions parse(ClassLoader loader, InputStream stream) throws ParserConfigurationException, SAXException, IOException { NM1ModuleDescriptions mod = new NM1ModuleDescriptions(loader); try {// w ww . jav a2s .c o m ModuleDescriptionsParser.parse(mod, stream); } catch (SAXParseException spe) { Log log = LogFactory.getLog(NM1ModuleDescriptions.class); if (log.isErrorEnabled()) { log.error("error in parse(" + loader + "," + stream + "); " + "@" + spe.getLineNumber() + ":" + spe.getColumnNumber(), spe); } } return mod; }
From source file:eu.delving.x3ml.X3MLEngine.java
private static String errorMessage(SAXParseException e) { return String.format("%d:%d - %s", e.getLineNumber(), e.getColumnNumber(), e.getMessage()); }
From source file:net.ontopia.topicmaps.entry.XMLConfigSource.java
private static List<TopicMapSourceIF> readSources(InputSource inp_source, Map<String, String> environ) { ConfigHandler handler = new ConfigHandler(environ); try {// w w w . jav a 2 s. c o m XMLReader parser = DefaultXMLReaderFactory.createXMLReader(); parser.setContentHandler(handler); parser.setErrorHandler(new Slf4jSaxErrorHandler(log)); parser.parse(inp_source); } catch (SAXParseException e) { String msg = "" + e.getSystemId() + ":" + e.getLineNumber() + ":" + e.getColumnNumber() + ": " + e.getMessage(); throw new OntopiaRuntimeException(msg, e); } catch (Exception e) { throw new OntopiaRuntimeException(e); } return handler.sources; }
From source file:Main.java
/** * Builds a prettier exception message.//from ww w .j a v a 2s . co m * * @param ex the SAXParseException * @return an easier to read exception message */ public static String getPrettyParseExceptionInfo(SAXParseException ex) { final StringBuilder sb = new StringBuilder(); if (ex.getSystemId() != null) { sb.append("systemId=").append(ex.getSystemId()).append(", "); } if (ex.getPublicId() != null) { sb.append("publicId=").append(ex.getPublicId()).append(", "); } if (ex.getLineNumber() > 0) { sb.append("Line=").append(ex.getLineNumber()); } if (ex.getColumnNumber() > 0) { sb.append(", Column=").append(ex.getColumnNumber()); } sb.append(": ").append(ex.getMessage()); return sb.toString(); }
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//ww w .ja v a 2 s .c o m * 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/* ww w.ja v a2s.com*/ * @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); } }