List of usage examples for org.xml.sax SAXParseException getLineNumber
public int getLineNumber()
From source file:ORG.oclc.os.SRW.SRUServerTester.java
public Document renderXML(String record) { Document document;/*from w w w .j ava 2s . c o m*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //factory.setValidating(true); factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(new org.xml.sax.ErrorHandler() { // ignore fatal errors (an exception is guaranteed) @Override public void fatalError(SAXParseException exception) throws SAXException { } // treat validation errors as fatal @Override public void error(SAXParseException e) throws SAXParseException { throw e; } // dump warnings too @Override public void warning(SAXParseException err) throws SAXParseException { out("** Warning"); out(", line "); out(err.getLineNumber()); out(", uri "); out(err.getSystemId()); out('\n'); out(" "); out(err.getMessage()); out('\n'); } }); document = builder.parse(new InputSource(new StringReader(record))); } catch (java.io.IOException e) { out("</pre><pre class='red'>"); out("test failed: unable to parse record: "); out(e.getMessage()); out('\n'); out(record); out('\n'); out("</pre><pre>"); return null; } catch (javax.xml.parsers.ParserConfigurationException e) { out("</pre><pre class='red'>"); out("test failed: unable to parse record: "); out(e.getMessage()); out('\n'); out(record); out('\n'); out("</pre><pre>"); return null; } catch (org.xml.sax.SAXException e) { out("</pre><pre class='red'>"); out("test failed: unable to parse record: "); out(e.getMessage()); out('\n'); out(record); out('\n'); out("</pre><pre>"); return null; } return document; }
From source file:org.omegat.core.data.RealProject.java
/** Finds and loads project's TMX file with translations (project_save.tmx). */ private void loadTranslations() throws Exception { File file = new File(m_config.getProjectInternalDir(), OConsts.STATUS_EXTENSION); try {// www . ja v a 2 s. c om Core.getMainWindow().showStatusMessageRB("CT_LOAD_TMX"); projectTMX = new ProjectTMX(m_config.getSourceLanguage(), m_config.getTargetLanguage(), m_config.isSentenceSegmentingEnabled(), file, checkOrphanedCallback); if (file.exists()) { // RFE 1001918 - backing up project's TMX upon successful read // TODO check for repositories FileUtil.backupFile(file); FileUtil.removeOldBackups(file, OConsts.MAX_BACKUPS); } } catch (SAXParseException ex) { Log.logErrorRB(ex, "TMXR_FATAL_ERROR_WHILE_PARSING", ex.getLineNumber(), ex.getColumnNumber()); throw ex; } catch (Exception ex) { Log.logErrorRB(ex, "TMXR_EXCEPTION_WHILE_PARSING", file.getAbsolutePath(), Log.getLogLocation()); throw ex; } }
From source file:org.onehippo.repository.xml.EnhancedSystemViewImportHandler.java
public void warning(SAXParseException e) throws SAXException { log.warn("warning encountered at line: " + e.getLineNumber() + ", column: " + e.getColumnNumber() + " while parsing XML stream", e); }
From source file:org.onehippo.repository.xml.EnhancedSystemViewImportHandler.java
public void error(SAXParseException e) throws SAXException { log.error("error encountered at line: " + e.getLineNumber() + ", column: " + e.getColumnNumber() + " while parsing XML stream: " + e.toString()); }
From source file:org.onehippo.repository.xml.EnhancedSystemViewImportHandler.java
public void fatalError(SAXParseException e) throws SAXException { log.error("fatal error encountered at line: " + e.getLineNumber() + ", column: " + e.getColumnNumber() + " while parsing XML stream: " + e.toString()); throw e;// ww w .ja v a2 s . c o m }
From source file:org.opencms.util.ant.CmsAntTaskReadXMLProperty.java
/** * Run the task.<p>/* ww w . j a va 2s .c o m*/ * * Sets the given property to <code>__ABORT__</code> if canceled, or to a list of selected * modules if not.<p> * * @throws BuildException if something goes wrong * * @see org.apache.tools.ant.Task#execute() */ public void execute() throws BuildException { boolean isAttr = ((m_attribute != null) && (m_attribute.trim().length() > 0)); // instantiate Digester and enable XML validation Digester digester = new Digester(); digester.setValidating(false); digester.setEntityResolver(null); digester.setRuleNamespaceURI(null); digester.setErrorHandler(new ErrorHandler() { /** * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) */ public void error(SAXParseException exception) { log(exception.getMessage(), exception.getLineNumber()); } /** * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) */ public void fatalError(SAXParseException exception) { log(exception.getMessage(), exception.getLineNumber()); } /** * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException) */ public void warning(SAXParseException exception) { log(exception.getMessage(), exception.getLineNumber()); } }); // add this class to the Digester digester.push(this); if (!isAttr) { digester.addCallMethod(m_element, "setValue", 0); } else { digester.addCallMethod(m_element, "setValue", 1); digester.addCallParam(m_element, 0, m_attribute); } // start the parsing process try { digester.parse(new File(getXmlFile())); } catch (Exception e) { throw new BuildException(e); } getProject().setProperty(m_property, m_value.substring(1)); }
From source file:org.openhab.tools.analysis.checkstyle.EshInfXmlValidationCheck.java
private void validateXmlAgainstSchema(File xmlFile, Schema schema) { if (schema != null) { try {//from www . j a va 2s . co m Validator validator = schema.newValidator(); validator.validate(new StreamSource(xmlFile)); } catch (SAXParseException exception) { String message = exception.getMessage(); // Removing the type of the logged message (For example - "cvc-complex-type.2.4.b: ..."). message = message.substring(message.indexOf(":") + 2); int lineNumber = exception.getLineNumber(); log(lineNumber, message, xmlFile.getPath()); } catch (IOException | SAXException e) { logger.error("Problem occurred while parsing the file " + xmlFile.getName(), e); } } else { logger.warn("XML validation will be skipped as the schema file download failed."); } }
From source file:org.openrdf.rio.trix.TriXParser.java
private void parse(Object inputStreamOrReader) throws IOException, RDFParseException, RDFHandlerException { if (rdfHandler != null) { rdfHandler.startRDF();/* www . j av a2 s.c o m*/ } try { SimpleSAXParser saxParser = new SimpleSAXParser(); saxParser.setPreserveWhitespace(true); saxParser.setListener(new TriXSAXHandler()); if (inputStreamOrReader instanceof InputStream) { saxParser.parse((InputStream) inputStreamOrReader); } else { saxParser.parse((Reader) inputStreamOrReader); } } catch (SAXParseException e) { Exception wrappedExc = e.getException(); if (wrappedExc == null) { reportFatalError(e, e.getLineNumber(), e.getColumnNumber()); } else { reportFatalError(wrappedExc, e.getLineNumber(), e.getColumnNumber()); } } catch (SAXException e) { Exception wrappedExc = e.getException(); if (wrappedExc == null) { reportFatalError(e); } else if (wrappedExc instanceof RDFParseException) { throw (RDFParseException) wrappedExc; } else if (wrappedExc instanceof RDFHandlerException) { throw (RDFHandlerException) wrappedExc; } else { reportFatalError(wrappedExc); } } finally { clear(); } if (rdfHandler != null) { rdfHandler.endRDF(); } }
From source file:org.orbeon.oxf.xml.dom4j.LocationData.java
public LocationData(SAXParseException exception) { systemID = exception.getSystemId(); line = exception.getLineNumber(); col = exception.getColumnNumber(); }
From source file:org.osaf.cosmo.calendar.hcalendar.HCalendarParser.java
private void parse(InputSource in, ContentHandler handler) throws IOException, ParserException { try {/* www .j a v a 2 s.co m*/ Document d = BUILDER_FACTORY.newDocumentBuilder().parse(in); buildCalendar(d, handler); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (SAXException e) { if (e instanceof SAXParseException) { SAXParseException pe = (SAXParseException) e; throw new ParserException("Could not parse XML", pe.getLineNumber(), e); } throw new ParserException(e.getMessage(), -1, e); } }