1   package org.daisy.pipeline.css;
2   
3   import java.io.IOException;
4   import java.io.Reader;
5   import java.net.URI;
6   import java.net.URL;
7   import java.nio.charset.Charset;
8   
9   public interface CssPreProcessor {
10  
11  	public boolean supportsMediaType(String mediaType, URL url);
12  
13  	public PreProcessingResult compile(PreProcessingSource source) throws IOException;
14  
15  	public static class PreProcessingSource {
16  
17  		/**
18  		 * The character stream.
19  		 */
20  		public final Reader stream;
21  
22  		/**
23  		 * The base.
24  		 */
25  		public final URI base;
26  
27  		/**
28  		 * Read the source again using a different character encoding. Closes {@code stream}.
29  		 *
30  		 * @throws IOException if the character encoding can not be changed or if the source can not
31  		 *                     be read a second time.
32  		 */
33  		public Reader reread(Charset encoding) throws IOException {
34  			throw new IOException();
35  		}
36  
37  		public PreProcessingSource(Reader stream, URI base) {
38  			this.stream = stream;
39  			this.base = base;
40  		}
41  	}
42  
43  	public static final class PreProcessingResult {
44  
45  		/**
46  		 * The CSS stream.
47  		 */
48  		public final Reader stream;
49  
50  		/**
51  		 * The source map (JSON).
52  		 */
53  		public final String sourceMap;
54  
55  		/**
56  		 * The base for resolving relative URIs in the CSS stream and source map.
57  		 */
58  		public final URI base;
59  
60  		public PreProcessingResult(Reader stream, String sourceMap, URI base) {
61  			this.stream = stream;
62  			this.sourceMap = sourceMap;
63  			this.base = base;
64  		}
65  	}
66  }