001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.xni.parser;
019:
020: import org.apache.xerces.xni.XMLResourceIdentifier;
021:
022: import java.io.InputStream;
023: import java.io.Reader;
024:
025: /**
026: * This class represents an input source for an XML document. The
027: * basic properties of an input source are the following:
028: * <ul>
029: * <li>public identifier</li>
030: * <li>system identifier</li>
031: * <li>byte stream or character stream</li>
032: * <li>
033: * </ul>
034: *
035: * @author Andy Clark, IBM
036: *
037: * @version $Id: XMLInputSource.java 447244 2006-09-18 05:20:40Z mrglavas $
038: */
039: public class XMLInputSource {
040:
041: //
042: // Data
043: //
044:
045: /** Public identifier. */
046: protected String fPublicId;
047:
048: /** System identifier. */
049: protected String fSystemId;
050:
051: /** Base system identifier. */
052: protected String fBaseSystemId;
053:
054: /** Byte stream. */
055: protected InputStream fByteStream;
056:
057: /** Character stream. */
058: protected Reader fCharStream;
059:
060: /** Encoding. */
061: protected String fEncoding;
062:
063: //
064: // Constructors
065: //
066:
067: /**
068: * Constructs an input source from just the public and system
069: * identifiers, leaving resolution of the entity and opening of
070: * the input stream up to the caller.
071: *
072: * @param publicId The public identifier, if known.
073: * @param systemId The system identifier. This value should
074: * always be set, if possible, and can be
075: * relative or absolute. If the system identifier
076: * is relative, then the base system identifier
077: * should be set.
078: * @param baseSystemId The base system identifier. This value should
079: * always be set to the fully expanded URI of the
080: * base system identifier, if possible.
081: */
082: public XMLInputSource(String publicId, String systemId,
083: String baseSystemId) {
084: fPublicId = publicId;
085: fSystemId = systemId;
086: fBaseSystemId = baseSystemId;
087: } // <init>(String,String,String)
088:
089: /**
090: * Constructs an input source from a XMLResourceIdentifier
091: * object, leaving resolution of the entity and opening of
092: * the input stream up to the caller.
093: *
094: * @param resourceIdentifier the XMLResourceIdentifier containing the information
095: */
096: public XMLInputSource(XMLResourceIdentifier resourceIdentifier) {
097:
098: fPublicId = resourceIdentifier.getPublicId();
099: fSystemId = resourceIdentifier.getLiteralSystemId();
100: fBaseSystemId = resourceIdentifier.getBaseSystemId();
101: } // <init>(XMLResourceIdentifier)
102:
103: /**
104: * Constructs an input source from a byte stream.
105: *
106: * @param publicId The public identifier, if known.
107: * @param systemId The system identifier. This value should
108: * always be set, if possible, and can be
109: * relative or absolute. If the system identifier
110: * is relative, then the base system identifier
111: * should be set.
112: * @param baseSystemId The base system identifier. This value should
113: * always be set to the fully expanded URI of the
114: * base system identifier, if possible.
115: * @param byteStream The byte stream.
116: * @param encoding The encoding of the byte stream, if known.
117: */
118: public XMLInputSource(String publicId, String systemId,
119: String baseSystemId, InputStream byteStream, String encoding) {
120: fPublicId = publicId;
121: fSystemId = systemId;
122: fBaseSystemId = baseSystemId;
123: fByteStream = byteStream;
124: fEncoding = encoding;
125: } // <init>(String,String,String,InputStream,String)
126:
127: /**
128: * Constructs an input source from a character stream.
129: *
130: * @param publicId The public identifier, if known.
131: * @param systemId The system identifier. This value should
132: * always be set, if possible, and can be
133: * relative or absolute. If the system identifier
134: * is relative, then the base system identifier
135: * should be set.
136: * @param baseSystemId The base system identifier. This value should
137: * always be set to the fully expanded URI of the
138: * base system identifier, if possible.
139: * @param charStream The character stream.
140: * @param encoding The original encoding of the byte stream
141: * used by the reader, if known.
142: */
143: public XMLInputSource(String publicId, String systemId,
144: String baseSystemId, Reader charStream, String encoding) {
145: fPublicId = publicId;
146: fSystemId = systemId;
147: fBaseSystemId = baseSystemId;
148: fCharStream = charStream;
149: fEncoding = encoding;
150: } // <init>(String,String,String,Reader,String)
151:
152: //
153: // Public methods
154: //
155:
156: /**
157: * Sets the public identifier.
158: *
159: * @param publicId The new public identifier.
160: */
161: public void setPublicId(String publicId) {
162: fPublicId = publicId;
163: } // setPublicId(String)
164:
165: /** Returns the public identifier. */
166: public String getPublicId() {
167: return fPublicId;
168: } // getPublicId():String
169:
170: /**
171: * Sets the system identifier.
172: *
173: * @param systemId The new system identifier.
174: */
175: public void setSystemId(String systemId) {
176: fSystemId = systemId;
177: } // setSystemId(String)
178:
179: /** Returns the system identifier. */
180: public String getSystemId() {
181: return fSystemId;
182: } // getSystemId():String
183:
184: /**
185: * Sets the base system identifier.
186: *
187: * @param baseSystemId The new base system identifier.
188: */
189: public void setBaseSystemId(String baseSystemId) {
190: fBaseSystemId = baseSystemId;
191: } // setBaseSystemId(String)
192:
193: /** Returns the base system identifier. */
194: public String getBaseSystemId() {
195: return fBaseSystemId;
196: } // getBaseSystemId():String
197:
198: /**
199: * Sets the byte stream. If the byte stream is not already opened
200: * when this object is instantiated, then the code that opens the
201: * stream should also set the byte stream on this object. Also, if
202: * the encoding is auto-detected, then the encoding should also be
203: * set on this object.
204: *
205: * @param byteStream The new byte stream.
206: */
207: public void setByteStream(InputStream byteStream) {
208: fByteStream = byteStream;
209: } // setByteStream(InputSource)
210:
211: /** Returns the byte stream. */
212: public InputStream getByteStream() {
213: return fByteStream;
214: } // getByteStream():InputStream
215:
216: /**
217: * Sets the character stream. If the character stream is not already
218: * opened when this object is instantiated, then the code that opens
219: * the stream should also set the character stream on this object.
220: * Also, the encoding of the byte stream used by the reader should
221: * also be set on this object, if known.
222: *
223: * @param charStream The new character stream.
224: *
225: * @see #setEncoding
226: */
227: public void setCharacterStream(Reader charStream) {
228: fCharStream = charStream;
229: } // setCharacterStream(Reader)
230:
231: /** Returns the character stream. */
232: public Reader getCharacterStream() {
233: return fCharStream;
234: } // getCharacterStream():Reader
235:
236: /**
237: * Sets the encoding of the stream.
238: *
239: * @param encoding The new encoding.
240: */
241: public void setEncoding(String encoding) {
242: fEncoding = encoding;
243: } // setEncoding(String)
244:
245: /** Returns the encoding of the stream, or null if not known. */
246: public String getEncoding() {
247: return fEncoding;
248: } // getEncoding():String
249:
250: } // class XMLInputSource
|