List of usage examples for org.xml.sax SAXParseException getException
public Exception getException()
From source file:org.openrdf.rio.trix.TriXParser.java
private void parse(Object inputStreamOrReader) throws IOException, RDFParseException, RDFHandlerException { if (rdfHandler != null) { rdfHandler.startRDF();/*from w w w. j av a 2 s . co 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.sakaibrary.osid.repository.xserver.AssetIterator.java
/** * This method parses the xml StringBuilder and creates Assets, Records * and Parts in the Repository with the given repositoryId. * * @param xml input xml in "sakaibrary" format * @param log the log being used by the Repository * @param repositoryId the Id of the Repository in which to create Assets, * Records and Parts./*from ww w . j a v a2s. c om*/ * * @throws org.osid.repository.RepositoryException */ private void createAssets(java.io.ByteArrayInputStream xml, org.osid.shared.Id repositoryId) throws org.osid.repository.RepositoryException { this.repositoryId = repositoryId; recordStructureId = RecordStructure.getInstance().getId(); textBuffer = new StringBuilder(); // use a SAX parser javax.xml.parsers.SAXParserFactory factory; javax.xml.parsers.SAXParser saxParser; // set up the parser factory = javax.xml.parsers.SAXParserFactory.newInstance(); factory.setNamespaceAware(true); // start parsing try { saxParser = factory.newSAXParser(); saxParser.parse(xml, this); xml.close(); } catch (SAXParseException spe) { // Use the contained exception, if any Exception x = spe; if (spe.getException() != null) { x = spe.getException(); } // Error generated by the parser LOG.warn("createAssets() parsing exception: " + spe.getMessage() + " - xml line " + spe.getLineNumber() + ", uri " + spe.getSystemId(), x); } catch (SAXException sxe) { // Error generated by this application // (or a parser-initialization error) Exception x = sxe; if (sxe.getException() != null) { x = sxe.getException(); } LOG.warn("createAssets() SAX exception: " + sxe.getMessage(), x); } catch (ParserConfigurationException pce) { // Parser with specified options can't be built LOG.warn("createAssets() SAX parser cannot be built with " + "specified options"); } catch (IOException ioe) { // I/O error LOG.warn("createAssets() IO exception", ioe); } }
From source file:org.sakaibrary.xserver.XMLCleanup.java
public ByteArrayOutputStream cleanup(InputStream xml) throws XServerException { inputXml = xml;/*from w w w .ja v a 2 s. c o m*/ // Use the default (non-validating) parser SAXParserFactory factory = SAXParserFactory.newInstance(); try { // Parse the input SAXParser saxParser = factory.newSAXParser(); saxParser.parse(inputXml, this); // close the stream inputXml.close(); } catch (SAXParseException spe) { // Use the contained exception, if any Exception x = spe; if (spe.getException() != null) { x = spe.getException(); } // Error generated by the parser LOG.warn("XMLCleanup.cleanup() parsing exception: " + spe.getMessage() + " - xml line " + spe.getLineNumber() + ", uri " + spe.getSystemId(), x); } catch (SAXException sxe) { // Error generated by this application // (or a parser-initialization error) Exception x = sxe; if (sxe.getException() != null) { x = sxe.getException(); } LOG.warn("XMLCleanup.cleanup() SAX exception: " + sxe.getMessage(), x); } catch (ParserConfigurationException pce) { // Parser with specified options can't be built LOG.warn("XMLCleanup.cleanup() SAX parser cannot be built with " + "specified options"); } catch (IOException ioe) { // I/O error LOG.warn("XMLCleanup.cleanup() IO exception", ioe); } catch (Throwable t) { LOG.warn("XMLCleanup.cleanup() exception", t); } if (error) { throw new XServerException(error_code, error_text); } return bytes; }