List of usage examples for org.xml.sax InputSource getByteStream
public InputStream getByteStream()
From source file:org.exist.collections.Collection.java
/** Stores an XML document in the database. {@link #validateXMLResourceInternal(org.exist.storage.txn.Txn, * org.exist.storage.DBBroker, org.exist.xmldb.XmldbURI, CollectionConfiguration, org.exist.collections.Collection.ValidateBlock)} * should have been called previously in order to acquire a write lock for the document. Launches the finish trigger. * /*from w w w.j a v a2s. co m*/ * @param transaction * @param broker * @param info * @param source * @param privileged * * @throws EXistException * @throws PermissionDeniedException * @throws TriggerException * @throws SAXException * @throws LockException */ public void store(final Txn transaction, final DBBroker broker, final IndexInfo info, final InputSource source, boolean privileged) throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException { storeXMLInternal(transaction, broker, info, privileged, new StoreBlock() { @Override public void run() throws EXistException, SAXException { try { final InputStream is = source.getByteStream(); if (is != null && is.markSupported()) { is.reset(); } else { final Reader cs = source.getCharacterStream(); if (cs != null && cs.markSupported()) { cs.reset(); } } } catch (final IOException e) { // mark is not supported: exception is expected, do nothing LOG.debug( "InputStream or CharacterStream underlying the InputSource does not support marking and therefore cannot be re-read."); } final XMLReader reader = getReader(broker, false, info.getCollectionConfig()); info.setReader(reader, null); try { reader.parse(source); } catch (final IOException e) { throw new EXistException(e); } finally { releaseReader(broker, info, reader); } } }); }
From source file:org.exist.collections.Collection.java
private InputSource closeShieldInputSource(final InputSource source) { final InputSource protectedInputSource = new InputSource(); protectedInputSource.setEncoding(source.getEncoding()); protectedInputSource.setSystemId(source.getSystemId()); protectedInputSource.setPublicId(source.getPublicId()); if (source.getByteStream() != null) { //TODO consider AutoCloseInputStream final InputStream closeShieldByteStream = new CloseShieldInputStream(source.getByteStream()); protectedInputSource.setByteStream(closeShieldByteStream); }//from w w w. j a va 2s . co m if (source.getCharacterStream() != null) { //TODO consider AutoCloseReader final Reader closeShieldReader = new CloseShieldReader(source.getCharacterStream()); protectedInputSource.setCharacterStream(closeShieldReader); } return protectedInputSource; }
From source file:org.exist.collections.MutableCollection.java
@Override public void store(final Txn transaction, final DBBroker broker, final IndexInfo info, final InputSource source) throws EXistException, PermissionDeniedException, TriggerException, SAXException, LockException { storeXMLInternal(transaction, broker, info, storeInfo -> { try {// w ww . ja v a 2 s.c o m final InputStream is = source.getByteStream(); if (is != null && is.markSupported()) { is.reset(); } else { final Reader cs = source.getCharacterStream(); if (cs != null && cs.markSupported()) { cs.reset(); } } } catch (final IOException e) { // mark is not supported: exception is expected, do nothing LOG.debug( "InputStream or CharacterStream underlying the InputSource does not support marking and therefore cannot be re-read."); } final XMLReader reader = getReader(broker, false, storeInfo.getCollectionConfig()); storeInfo.setReader(reader, null); try { reader.parse(source); } catch (final IOException e) { throw new EXistException(e); } finally { releaseReader(broker, storeInfo, reader); } }); }
From source file:org.exist.collections.MutableCollection.java
private InputSource closeShieldInputSource(final InputSource source) { final InputSource protectedInputSource = new InputSource(); protectedInputSource.setEncoding(source.getEncoding()); protectedInputSource.setSystemId(source.getSystemId()); protectedInputSource.setPublicId(source.getPublicId()); if (source.getByteStream() != null) { //TODO consider AutoCloseInputStream final InputStream closeShieldByteStream = new CloseShieldInputStream(source.getByteStream()); protectedInputSource.setByteStream(closeShieldByteStream); }//from ww w .j a v a 2 s . c o m if (source.getCharacterStream() != null) { //TODO consider AutoCloseReader final Reader closeShieldReader = new CloseShieldReader(source.getCharacterStream()); protectedInputSource.setCharacterStream(closeShieldReader); } return protectedInputSource; }
From source file:org.exist.dom.XMLUtil.java
public static String readFile(InputSource is) throws IOException { // read the file into a string return readFile(is.getByteStream(), is.getEncoding()); }
From source file:org.exist.xmldb.LocalBinaryResource.java
private byte[] readFile(InputSource is) throws XMLDBException { return readFile(is.getByteStream()); }
From source file:org.jboss.bpm.console.server.util.DOMUtils.java
/** Parse the given input source and return the root Element *///ww w . ja va 2s . c o m public static Element parse(InputSource source) throws IOException { try { return getDocumentBuilder().parse(source).getDocumentElement(); } catch (SAXException se) { throw new IOException(se.toString()); } finally { InputStream is = source.getByteStream(); if (is != null) { is.close(); } Reader r = source.getCharacterStream(); if (r != null) { r.close(); } } }
From source file:org.jbpm.bpel.xml.ProcessWsdlLocator.java
private void upgradeWsdlDocumentIfNeeded(InputSource source) { // get the thread-local document parser DocumentBuilder documentParser = XmlUtil.getDocumentBuilder(); // install our problem handler as document parser's error handler documentParser.setErrorHandler(problemHandler.asSaxErrorHandler()); // parse content Document document;// ww w.ja v a 2 s . c o m try { document = documentParser.parse(source); // halt on parse errors if (problemHandler.getProblemCount() > 0) return; } catch (IOException e) { Problem problem = new Problem(Problem.LEVEL_ERROR, "document is not readable", e); problem.setResource(latestImportURI); problemHandler.add(problem); return; } catch (SAXException e) { Problem problem = new Problem(Problem.LEVEL_ERROR, "document contains invalid xml", e); problem.setResource(latestImportURI); problemHandler.add(problem); return; } finally { // reset error handling behavior documentParser.setErrorHandler(null); } // check whether the wsdl document requires upgrading if (hasUpgradableElements(document)) { try { // create wsdl upgrader Transformer wsdlUpgrader = getWsdlUpgradeTemplates().newTransformer(); // install our problem handler as transformer's error listener wsdlUpgrader.setErrorListener(problemHandler.asTraxErrorListener()); // upgrade into memory stream ByteArrayOutputStream resultStream = new ByteArrayOutputStream(); wsdlUpgrader.transform(new DOMSource(document), new StreamResult(resultStream)); // replace existing source with upgraded document source.setByteStream(new ByteArrayInputStream(resultStream.toByteArray())); log.debug("upgraded wsdl document: " + latestImportURI); } catch (TransformerException e) { Problem problem = new Problem(Problem.LEVEL_ERROR, "wsdl upgrade failed", e); problem.setResource(latestImportURI); problemHandler.add(problem); } } else { // if the source is a stream, reset it InputStream sourceStream = source.getByteStream(); if (sourceStream != null) { try { sourceStream.reset(); } catch (IOException e) { log.error("could not reset source stream: " + latestImportURI, e); } } } }
From source file:org.kitodo.production.plugin.opac.pica.GetOpac.java
/** * Helper method that parses an InputSource and returns a DOM Document. * * @param source/*from w w w . ja v a2s .co m*/ * The InputSource to parse * @return The resulting document */ private Document getParsedDocument(InputSource source) { try { return this.docBuilder.parse(source); } catch (SAXException e) { logger.info("Dokument?"); InputStream bs = source.getByteStream(); logger.info(bs.toString()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.mule.config.spring.MuleDocumentLoader.java
/** * Load the {@link Document} at the supplied {@link InputSource} using the standard JAXP-configured XML parser. *///from w ww.j a va2s . com @Override public Document loadDocument(InputSource inputSource, EntityResolver entityResolver, ErrorHandler errorHandler, int validationMode, boolean namespaceAware) throws Exception { ByteArrayOutputStream output = new ByteArrayOutputStream(); IOUtils.copy(inputSource.getByteStream(), output); InputSource defaultInputSource = new InputSource(new ByteArrayInputStream(output.toByteArray())); InputSource enrichInputSource = new InputSource(new ByteArrayInputStream(output.toByteArray())); Document doc = defaultLoader.loadDocument(defaultInputSource, entityResolver, errorHandler, validationMode, namespaceAware); createSaxAnnotator(doc).parse(enrichInputSource); return doc; }