2
* Copyright (c) 1999 World Wide Web Consortium
3
* (Massachusetts Institute of Technology, Institut National de Recherche
4
* en Informatique et en Automatique, Keio University).
5
* All Rights Reserved. http://www.w3.org/Consortium/Legal/
7
* The original version of this interface comes from SAX :
8
* http://www.megginson.com/SAX/
10
* $Id: InputSource.java,v 1.2 2000/11/10 17:14:20 hillion Exp $
12
package org.w3c.css.sac;
14
import java.io.InputStream;
15
import java.io.Reader;
18
* A single input source for a CSS source.
20
* <p>This class allows a CSS application to encapsulate information about an
21
* input source in a single object, which may include a URI, a byte stream
22
* (possibly with a specified encoding), and/or a character stream.</p>
24
* <p>The CSS parser will use the InputSource object to determine how
25
* to read CSS input. If there is a character stream available, the
26
* parser will read that stream directly; if not, the parser will use
27
* a byte stream, if available; if neither a character stream nor a
28
* byte stream is available, the parser will attempt to open a URI
29
* connection to the resource identified by the URI.</p>
31
* <p>An InputSource object belongs to the application: the CSS parser
32
* shall never modify it in any way (it may modify a copy if
35
* @version $Revision: 1.2 $
36
* @author Philippe Le Hegaret
38
public class InputSource {
41
private InputStream byteStream;
42
private String encoding;
43
private Reader characterStream;
48
* Zero-argument default constructor.
52
* @see #setCharacterStream
55
public InputSource() {
59
* Create a new input source with a URI.
61
* <p>The URI must be full resolved.</p>
67
* @see #setCharacterStream
69
public InputSource(String uri) {
74
* Create a new input source with a character stream.
76
* <p>Application writers may use setURI() to provide a base
77
* for resolving relative URIs, and setPublicId to include a
78
* public identifier.</p>
80
* <p>The character stream shall not include a byte order mark.</p>
84
* @see #setCharacterStream
86
public InputSource(Reader characterStream) {
87
setCharacterStream(characterStream);
91
* Set the URI for this input source.
93
* <p>The URI is optional if there is a byte stream or a character stream,
94
* but it is still useful to provide one, since the application can use it
95
* to resolve relative URIs and can include it in error messages and
96
* warnings (the parser will attempt to open a connection to the URI only
97
* if there is no byte stream or character stream specified).</p>
99
* <p>If the application knows the character encoding of the
100
* object pointed to by the URI, it can register
101
* the encoding using the setEncoding method.</p>
103
* <p>The URI must be fully resolved.</p>
105
* @param uri The URI as a string.
108
* @see Locator#getURI
109
* @see CSSParseException#getURI
111
public void setURI(String uri) {
116
* Get the URI for this input source.
118
* <p>The getEncoding method will return the character encoding
119
* of the object pointed to, or null if unknown.</p>
121
* <p>The URI will be fully resolved.</p>
127
public String getURI() {
132
* Set the byte stream for this input source.
134
* <p>The SAX parser will ignore this if there is also a character
135
* stream specified, but it will use a byte stream in preference
136
* to opening a URI connection itself.</p>
138
* <p>If the application knows the character encoding of the
139
* byte stream, it should set it with the setEncoding method.</p>
141
* @param byteStream A byte stream containing an CSS document or
144
* @see #getByteStream
147
public void setByteStream(InputStream byteStream) {
148
this.byteStream = byteStream;
152
* Get the byte stream for this input source.
154
* <p>The getEncoding method will return the character
155
* encoding for this byte stream, or null if unknown.</p>
157
* @return The byte stream, or null if none was supplied.
159
* @see #setByteStream
161
public InputStream getByteStream() {
166
* Set the character encoding, if known.
168
* <p>The encoding must be a string acceptable for an
169
* CHARSET encoding declaration (see section 4.4 of the CSS
170
* recommendation Level 2).</p>
172
* <p>This method has no effect when the application provides a
173
* character stream.</p>
175
* @param encoding A string describing the character encoding.
177
* @see #setByteStream
180
public void setEncoding(String encoding) {
181
this.encoding = encoding;
185
* Get the character encoding for a byte stream or URI.
187
* @return The encoding, or null if none was supplied.
188
* @see #setByteStream
190
* @see #getByteStream
192
public String getEncoding() {
197
* Set the character stream for this input source.
199
* <p>If there is a character stream specified, the SAX parser
200
* will ignore any byte stream and will not attempt to open
201
* a URI connection to the URI.</p>
203
* @param characterStream The character stream containing the
204
* CSS document or other entity.
205
* @see #getCharacterStream
207
public void setCharacterStream(Reader characterStream) {
208
this.characterStream = characterStream;
212
* Get the character stream for this input source.
214
* @return The character stream, or null if none was supplied.
215
* @see #setCharacterStream
217
public Reader getCharacterStream() {
218
return characterStream;
222
* Set the title for this input source.
223
* @param title The advisory title. See the title attribute definition
224
* for the <a href="http://www.w3.org/TR/REC-html40/struct/links.html#edef-LINK">LINK</A>
225
* element in HTML 4.0, and the title pseudo-attribute for the XML
226
* style sheet processing instruction.
228
public void setTitle(String title) {
233
* Returns the title for this input source.
235
public String getTitle() {
240
* Set the media for this input source.
241
* @param media A comma separated list with all media.
243
public void setMedia(String media) {
248
* Returns the media associated to the input source or <code>null</code>
249
* if media are currently unknown.
250
* @return the media associated to this input source.
252
public String getMedia() {