List of usage examples for org.xml.sax InputSource setByteStream
public void setByteStream(InputStream byteStream)
From source file:org.apache.catalina.ant.ValidatorTask.java
/** * Execute the specified command. This logic only performs the common * attribute validation required by all subclasses; it does not perform * any functional logic directly.// w w w . j av a 2 s. c o m * * @exception BuildException if a validation error occurs */ public void execute() throws BuildException { if (path == null) { throw new BuildException("Must specify 'path'"); } File file = new File(path, Constants.ApplicationWebXml); if ((!file.exists()) || (!file.canRead())) { throw new BuildException("Cannot find web.xml"); } // Commons-logging likes having the context classloader set ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(ValidatorTask.class.getClassLoader()); Digester digester = DigesterFactory.newDigester(true, true, null); try { file = file.getCanonicalFile(); InputStream stream = new BufferedInputStream(new FileInputStream(file)); InputSource is = new InputSource(file.toURL().toExternalForm()); is.setByteStream(stream); digester.parse(is); System.out.println("web.xml validated"); } catch (Throwable t) { throw new BuildException("Validation failure", t); } finally { Thread.currentThread().setContextClassLoader(oldCL); } }
From source file:org.apache.myfaces.custom.skin.config.ConfigParser.java
/** * *///from w w w. ja v a 2 s .co m static public RequestContextBean parseConfigFile(ExternalContext externalContext) { RequestContextBean bean = new RequestContextBean(); InputStream in = externalContext.getResourceAsStream(_SKINS_CONFIG_FILE); if (in == null) { in = externalContext.getResourceAsStream(_TRINIDAD_CONFIG_FILE); } if (in != null) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); Digester digester = new Digester(factory.newSAXParser()); digester.setValidating(false); digester.setNamespaceAware(true); digester.setUseContextClassLoader(true); RequestContextBean.addXmlRules(digester); InputSource input = new InputSource(); input.setByteStream(in); input.setPublicId(_SKINS_CONFIG_FILE); digester.parse(input); bean = (RequestContextBean) digester.getRoot(); } catch (IOException ioe) { _LOG.warning(ioe); } catch (ParserConfigurationException pce) { _LOG.warning(pce); } catch (SAXException saxe) { _LOG.warning(saxe); } finally { try { in.close(); } catch (IOException ioe) { // Ignore ; } } } return bean; }
From source file:org.apache.ode.axis2.util.Axis2WSDLLocator.java
public InputSource getBaseInputSource() { try {/*from ww w . j a v a2s.c o m*/ InputSource is = new InputSource(); is.setByteStream(openResource(_baseUri)); is.setSystemId(_baseUri.toString()); return is; } catch (IOException e) { LOG.error("Unable to create InputSource for " + _baseUri, e); return null; } }
From source file:org.apache.ode.axis2.util.Axis2WSDLLocator.java
public InputSource getImportInputSource(String parent, String imprt) { URI uri;//from w ww . j a v a2s .com try { uri = parent == null ? _baseUri.resolve(imprt) : new URI(parent).resolve(imprt); } catch (URISyntaxException e1) { LOG.error("URI syntax error: parent=" + parent + " error=" + e1); return null; } if (LOG.isDebugEnabled()) { LOG.debug("Get import: import=" + imprt + " parent=" + parent); } InputSource is = new InputSource(); try { is.setByteStream(openResource(uri)); } catch (Exception e) { LOG.error("Unable to open import resource: " + uri, e); return null; } is.setSystemId(uri.toString()); _latest = uri.toString(); return is; }
From source file:org.apache.ode.bpel.compiler.WSDLLocatorImpl.java
public InputSource getBaseInputSource() { try {/*w w w . j a v a 2 s . c om*/ InputSource is = new InputSource(); is.setByteStream(_resourceFinder.openResource(_base)); is.setSystemId(_base.toString()); return is; } catch (MalformedURLException e) { return null; } catch (IOException e) { return null; } }
From source file:org.apache.ode.bpel.compiler.WSDLLocatorImpl.java
public InputSource getImportInputSource(String parent, String imprt) { URI uri;/* ww w . j a v a 2 s .com*/ try { uri = parent == null ? _base.resolve(imprt) : new URI(parent).resolve(imprt); } catch (URISyntaxException e1) { __log.error("URI syntax error: " + parent); return null; } __log.debug("getImportInputSource: parent=" + parent + ", imprt=" + imprt + ", uri=" + uri); InputSource is = new InputSource(); try { is.setByteStream(_resourceFinder.openResource(uri)); } catch (Exception e) { return null; } is.setSystemId(uri.toString()); _latest = uri.toString(); return is; }
From source file:org.apache.ojb.broker.metadata.RepositoryPersistor.java
/** * * TODO: We should re-design the configuration file reading *///w w w . j av a2s .c om private Object buildRepository(String repositoryFileName, Class targetRepository) throws MalformedURLException, ParserConfigurationException, SAXException, IOException { URL url = buildURL(repositoryFileName); /* arminw: strange, when using 'url.openStream()' argument repository could not be parsed ipriha: parser needs a base url to find referenced entities. */ // InputSource source = new InputSource(url.openStream()); String pathName = url.toExternalForm(); log.info("Building repository from :" + pathName); InputSource source = new InputSource(pathName); URLConnection conn = url.openConnection(); conn.setUseCaches(false); conn.connect(); InputStream in = conn.getInputStream(); source.setByteStream(in); try { return readMetadataFromXML(source, targetRepository); } finally { try { in.close(); } catch (IOException x) { log.warn("unable to close repository input stream [" + x.getMessage() + "]", x); } } }
From source file:org.apache.xmlgraphics.image.loader.util.ImageUtil.java
/** * Removes any references to InputStreams or Readers from the given Source to prohibit * accidental/unwanted use by a component further downstream. * @param src the Source object//w w w . j av a 2 s . c o m */ public static void removeStreams(Source src) { if (src instanceof ImageSource) { ImageSource isrc = (ImageSource) src; isrc.setImageInputStream(null); } else if (src instanceof StreamSource) { StreamSource ssrc = (StreamSource) src; ssrc.setInputStream(null); ssrc.setReader(null); } else if (src instanceof SAXSource) { InputSource is = ((SAXSource) src).getInputSource(); if (is != null) { is.setByteStream(null); is.setCharacterStream(null); } } }
From source file:org.apache.xmlgraphics.image.loader.util.ImageUtil.java
/** * Closes the InputStreams or ImageInputStreams of Source objects. Any exception occurring * while closing the stream is ignored.//from w w w . ja v a2 s .c o m * @param src the Source object */ public static void closeQuietly(Source src) { if (src == null) { return; } else if (src instanceof StreamSource) { StreamSource streamSource = (StreamSource) src; IOUtils.closeQuietly(streamSource.getInputStream()); streamSource.setInputStream(null); IOUtils.closeQuietly(streamSource.getReader()); streamSource.setReader(null); } else if (src instanceof ImageSource) { ImageSource imageSource = (ImageSource) src; if (imageSource.getImageInputStream() != null) { try { imageSource.getImageInputStream().close(); } catch (IOException ioe) { //ignore } imageSource.setImageInputStream(null); } } else if (src instanceof SAXSource) { InputSource is = ((SAXSource) src).getInputSource(); if (is != null) { IOUtils.closeQuietly(is.getByteStream()); is.setByteStream(null); IOUtils.closeQuietly(is.getCharacterStream()); is.setCharacterStream(null); } } }
From source file:org.dhatim.delivery.AbstractParser.java
protected InputSource createInputSource(Source source, String contentEncoding) { // Also attach the underlying stream to the InputSource... if (source instanceof StreamSource) { StreamSource streamSource = (StreamSource) source; InputStream inputStream;// www . j a v a2 s . c o m Reader reader; inputStream = getInputStream(streamSource); reader = streamSource.getReader(); if (reader == null) { if (inputStream == null) { throw new SmooksException( "Invalid StreamSource. Unable to extract an InputStream (even by systemId) or Reader instance."); } reader = streamToReader(inputStream, contentEncoding); } InputSource inputSource = new InputSource(); inputSource.setByteStream(inputStream); inputSource.setCharacterStream(reader); return inputSource; } else { return new InputSource(getReader(source, contentEncoding)); } }