public static CSSInputStream stringStream(String source) throws IOException { CSSInputStream stream = new CSSInputStream(); stream.rawData = source; stream.encoding = Charset.defaultCharset().name(); BufferedReader br = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(source.getBytes()), stream.encoding)); stream.input = new ANTLRReaderStream(br); return stream; }
/** * Creates input for CSSLexer * * @param source * Source, either raw data (String) or URL * @return Created stream * @throws IOException * When file is not found or other IO exception occurs */ protected static CSSInputStream getInput(Object source, NetworkProcessor network, String encoding, SourceType type) throws IOException { switch (type) { case INLINE: case EMBEDDED: return CSSInputStream.stringStream((String) source); case URL: return CSSInputStream.urlStream((URL) source, network, encoding); default: throw new RuntimeException("Coding error"); } }
try { log.debug("BASE: " + ((CSSInputStream) input).getBase()); URL base = ((CSSInputStream) input).getBase(); if (base != null) url = DataURLHandler.createURL(base, fileName); String enc = ((CSSInputStream) input).getEncoding(); setCharStream(CSSInputStream.urlStream(url, enc)); reset();
CSSInputStream input = CSSInputStream.stringStream(query); input.setBase(new URL("file://media/query/url")); //this URL should not be used, just for safety
@Override public CSSInputStream getInput(Object source, String encoding) throws IOException { return CSSInputStream.urlStream((URL) source, encoding); }
public CSSToken make() { CSSToken t = new CSSToken(input, state.type, state.channel, state.tokenStartCharIndex, input.index()-1, lexerClass); t.setLine(state.tokenStartLine); t.setText(state.text); t.setCharPositionInLine(state.tokenStartCharPositionInLine); t.setBase(input.getBase()); // clone lexer state t.setLexerState(new CSSLexerState(ls)); return t; } }
private static CSSTreeParser createParser(Object source, String encoding, SourceType type, Preparator preparator, StyleSheet stylesheet, URL base) throws IOException, CSSException { CSSInputStream input = type.getInput(source, encoding); input.setBase(base); CommonTokenStream tokens = feedLexer(input, stylesheet); CommonTree ast = feedParser(tokens, type, stylesheet); return feedAST(tokens, ast, preparator, stylesheet); }
@Override public CSSInputStream getInput(Object source, String encoding) throws IOException { return CSSInputStream.stringStream((String) source); }
((CSSInputStream) input).setEncoding(enc);
/** * Adds contextual information about n { esting into token. */ @Override public Token emit() { CSSToken t = new CSSToken(input, state.type, state.channel, state.tokenStartCharIndex, getCharIndex()-1); t.setLine(state.tokenStartLine); t.setText(state.text); t.setCharPositionInLine(state.tokenStartCharPositionInLine); t.setBase(((CSSInputStream) input).getBase()); // clone lexer state t.setLexerState(new LexerState(ls)); emit(t); return t; }
/** * Sets a new encoding for the input stream. <b>Warning:</b> this resets the stream * i.e. a new connection is opened and all the data is read again. * @param enc The new encoding name. * @throws IOException */ public void setEncoding(String enc) throws IOException { if (source != null) //applicapble to URL streams only { String current = encoding; if (current == null) current = Charset.defaultCharset().name(); if (!current.equalsIgnoreCase(enc)) { source.close(); encoding = enc; CSSInputStream newstream = urlStream(url, network, encoding); input = newstream.input; } } }
private static CSSTreeParser createTreeParser(Object source, NetworkProcessor network, String encoding, SourceType type, Preparator preparator, URL base, List<MediaQuery> media) throws IOException, CSSException { CSSInputStream input = getInput(source, network, encoding, type); input.setBase(base); CommonTokenStream tokens = feedLexer(input); CommonTree ast = feedParser(tokens, type); return feedAST(tokens, ast, preparator, media); }
@Override public CSSInputStream getInput(Object source, String encoding) throws IOException { return CSSInputStream.stringStream((String) source); }
((cz.vutbr.web.csskit.antlr.CSSInputStream) input).setEncoding(enc);
public static CSSInputStream stringStream(String source) throws IOException { CSSInputStream stream = new CSSInputStream(); stream.rawData = source; stream.encoding = Charset.defaultCharset().name(); BufferedReader br = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(source.getBytes()), stream.encoding)); stream.input = new ANTLRReaderStream(br); return stream; }
/** * Sets a new encoding for the input stream. <b>Warning:</b> this resets the stream * i.e. a new connection is opened and all the data is read again. * @param enc The new encoding name. * @throws IOException */ public void setEncoding(String enc) throws IOException { if (source != null) //applicapble to URL streams only { String current = encoding; if (current == null) current = Charset.defaultCharset().name(); if (!current.equalsIgnoreCase(enc)) { source.close(); encoding = enc; CSSInputStream newstream = urlStream(url, encoding); input = newstream.input; } } }
public static CSSInputStream urlStream(URL source, String encoding) throws IOException { CSSInputStream stream = new CSSInputStream(); stream.base = source; if (encoding != null) stream.encoding = encoding; else stream.encoding = Charset.defaultCharset().name(); URLConnection con = source.openConnection(); InputStream is; if ("gzip".equalsIgnoreCase(con.getContentEncoding())) is = new GZIPInputStream(con.getInputStream()); else is = con.getInputStream(); stream.input = new ANTLRInputStream(is, stream.encoding); stream.source = is; stream.url = source; return stream; }
public static CSSInputStream urlStream(URL source, NetworkProcessor network, String encoding) throws IOException { CSSInputStream stream = new CSSInputStream(); stream.base = source; if (encoding != null) stream.encoding = encoding; else stream.encoding = Charset.defaultCharset().name(); InputStream is = network.fetch(source); stream.input = new ANTLRInputStream(is, stream.encoding); stream.source = is; stream.url = source; return stream; }