/** * Return true if <code>source</code> is valid and false otherwise. * * @param source * @throws IOException */ private void checkInputSource(InputSource source) throws IOException { Reader reader = source.getCharacterStream(); InputStream stream = source.getByteStream(); if (reader == null && stream == null) throw new IOException( "CharacterStream or ByteStream cannot be null for the InputSource."); }
/** * Convert the source into a Reader. Used only by DOM Level 2 parser methods. */ private Reader getReader(InputSource source) throws IOException { if (source.getCharacterStream() != null) { return source.getCharacterStream(); } else if (source.getByteStream() != null) { // My DOM level 2 implementation doesn't use this case. if (source.getEncoding() == null) { // unknown encoding, use ASCII as default. return new InputStreamReader(source.getByteStream(), "ASCII"); } else { return new InputStreamReader(source.getByteStream(), source.getEncoding()); } } else { // systemId // @@TODO throw new CSSException("not yet implemented"); } }
/** * Convert the source into a Reader. Used only by DOM Level 2 parser methods. */ private Reader getReader(InputSource source) throws IOException { if (source.getCharacterStream() != null) { return source.getCharacterStream(); } else if (source.getByteStream() != null) { // My DOM level 2 implementation doesn't use this case. if (source.getEncoding() == null) { // unknown encoding, use ASCII as default. return new InputStreamReader(source.getByteStream(), "ASCII"); } else { return new InputStreamReader(source.getByteStream(), source.getEncoding()); } } else { // systemId // @@TODO throw new CSSException("not yet implemented"); } }
/** * Convert the source into a Reader. Used only by DOM Level 2 parser methods. */ private Reader getReader( InputSource source ) throws IOException { if ( source.getCharacterStream() != null ) { return source.getCharacterStream(); } else if ( source.getByteStream() != null ) { // My DOM level 2 implementation doesn't use this case. if ( source.getEncoding() == null ) { // unknown encoding, use ASCII as default. return new InputStreamReader( source.getByteStream(), "ASCII" ); } else { return new InputStreamReader( source.getByteStream(), source.getEncoding() ); } } else { // systemId // @@TODO throw new CSSException( "not yet implemented" ); } }
private CharStream getCharStream(final InputSource source) throws IOException { if (source.getCharacterStream() != null) { return new CssCharStream(source.getCharacterStream(), 1, 1); } if (source.getByteStream() != null) { final InputStreamReader reader; final String encoding = source.getEncoding(); if (encoding == null || encoding.length() < 1) { reader = new InputStreamReader(source.getByteStream(), Charset.defaultCharset()); } else { reader = new InputStreamReader(source.getByteStream(), encoding); } return new CssCharStream(reader, 1, 1); } if (source.getURI() != null) { final InputStreamReader reader = new InputStreamReader(new URL(source.getURI()).openStream()); return new CssCharStream(reader, 1, 1); } return null; }
} else if (source.getByteStream() == null) { InputStream input = source.getByteStream(); if (!input.markSupported()) { source.setCharacterStream(new InputStreamReader(source.getByteStream(), Encoding.getJavaEncoding(encoding)));
} else if (source.getByteStream() == null) { InputStream input = source.getByteStream(); char c = ' '; source.setCharacterStream(new InputStreamReader(source.getByteStream(), Encoding.getJavaEncoding(encoding)));
} else if ( source.getByteStream() == null ) { InputStream input = source.getByteStream(); char c = ' '; source.setCharacterStream( new InputStreamReader( source.getByteStream(), Encoding.getJavaEncoding( encoding ) ) );
InputStream is = source.getByteStream(); if (is != null) { return new Scanner(is, source.getEncoding());
InputStream is = source.getByteStream(); if (is != null) { return new Scanner(is, source.getEncoding());
/** * Creates a scanner, given an InputSource. */ protected Scanner createScanner(InputSource source) { documentURI = source.getURI(); if (documentURI == null) { documentURI = ""; } Reader r = source.getCharacterStream(); if (r != null) { return new Scanner(r); } InputStream is = source.getByteStream(); if (is != null) { return new Scanner(is, source.getEncoding()); } String uri = source.getURI(); if (uri == null) { throw new CSSException(formatMessage("empty.source", null)); } try { ParsedURL purl = new ParsedURL(uri); is = purl.openStreamRaw(CSSConstants.CSS_MIME_TYPE); return new Scanner(is, source.getEncoding()); } catch (IOException e) { throw new CSSException(e); } }
/** * Creates a scanner, given an InputSource. */ protected Scanner createScanner(InputSource source) { documentURI = source.getURI(); if (documentURI == null) { documentURI = ""; } Reader r = source.getCharacterStream(); if (r != null) { return new Scanner(r); } InputStream is = source.getByteStream(); if (is != null) { return new Scanner(is, source.getEncoding()); } String uri = source.getURI(); if (uri == null) { throw new CSSException(formatMessage("empty.source", null)); } try { ParsedURL purl = new ParsedURL(uri); is = purl.openStreamRaw(CSSConstants.CSS_MIME_TYPE); return new Scanner(is, source.getEncoding()); } catch (IOException e) { throw new CSSException(e); } }
/** * Creates a scanner, given an InputSource. */ protected Scanner createScanner(InputSource source) { documentURI = source.getURI(); if (documentURI == null) { documentURI = ""; } Reader r = source.getCharacterStream(); if (r != null) { return new Scanner(r); } InputStream is = source.getByteStream(); if (is != null) { return new Scanner(is, source.getEncoding()); } String uri = source.getURI(); if (uri == null) { throw new CSSException(formatMessage("empty.source", null)); } try { ParsedURL purl = new ParsedURL(uri); is = purl.openStreamRaw(CSSConstants.CSS_MIME_TYPE); return new Scanner(is, source.getEncoding()); } catch (IOException e) { throw new CSSException(e); } }