KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > util > SAXInputSource


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.util;
18
19 import java.io.InputStream JavaDoc;
20 import java.io.Reader JavaDoc;
21
22 import org.apache.xerces.xni.parser.XMLInputSource;
23 import org.xml.sax.InputSource JavaDoc;
24 import org.xml.sax.XMLReader JavaDoc;
25
26 /**
27  * <p>An <code>XMLInputSource</code> analogue to <code>javax.xml.transform.sax.SAXSource</code>.</p>
28  *
29  * @version $Id: SAXInputSource.java,v 1.1 2005/05/15 19:54:21 mrglavas Exp $
30  */

31 public final class SAXInputSource extends XMLInputSource {
32     
33     private XMLReader JavaDoc fXMLReader;
34     private InputSource fInputSource;
35     
36     public SAXInputSource() {
37         this(null);
38     }
39     
40     public SAXInputSource(InputSource inputSource) {
41         this(null, inputSource);
42     }
43     
44     public SAXInputSource(XMLReader JavaDoc reader, InputSource inputSource) {
45         super(inputSource != null ? inputSource.getPublicId() : null,
46                 inputSource != null ? inputSource.getSystemId() : null, null);
47         if (inputSource != null) {
48             setByteStream(inputSource.getByteStream());
49             setCharacterStream(inputSource.getCharacterStream());
50             setEncoding(inputSource.getEncoding());
51         }
52         fInputSource = inputSource;
53         fXMLReader = reader;
54     }
55     
56     public void setXMLReader(XMLReader JavaDoc reader) {
57         fXMLReader = reader;
58     }
59     
60     public XMLReader JavaDoc getXMLReader() {
61         return fXMLReader;
62     }
63     
64     public void setInputSource(InputSource inputSource) {
65         if (inputSource != null) {
66             setPublicId(inputSource.getPublicId());
67             setSystemId(inputSource.getSystemId());
68             setByteStream(inputSource.getByteStream());
69             setCharacterStream(inputSource.getCharacterStream());
70             setEncoding(inputSource.getEncoding());
71         }
72         else {
73             setPublicId(null);
74             setSystemId(null);
75             setByteStream(null);
76             setCharacterStream(null);
77             setEncoding(null);
78         }
79         fInputSource = inputSource;
80     }
81     
82     public InputSource getInputSource() {
83         return fInputSource;
84     }
85     
86     /**
87      * Sets the public identifier.
88      *
89      * @param publicId The new public identifier.
90      */

91     public void setPublicId(String JavaDoc publicId) {
92         super.setPublicId(publicId);
93         if (fInputSource == null) {
94             fInputSource = new InputSource();
95         }
96         fInputSource.setPublicId(publicId);
97     } // setPublicId(String)
98

99     /**
100      * Sets the system identifier.
101      *
102      * @param systemId The new system identifier.
103      */

104     public void setSystemId(String JavaDoc systemId) {
105         super.setSystemId(systemId);
106         if (fInputSource == null) {
107             fInputSource = new InputSource();
108         }
109         fInputSource.setSystemId(systemId);
110     } // setSystemId(String)
111

112     /**
113      * Sets the byte stream. If the byte stream is not already opened
114      * when this object is instantiated, then the code that opens the
115      * stream should also set the byte stream on this object. Also, if
116      * the encoding is auto-detected, then the encoding should also be
117      * set on this object.
118      *
119      * @param byteStream The new byte stream.
120      */

121     public void setByteStream(InputStream JavaDoc byteStream) {
122         super.setByteStream(byteStream);
123         if (fInputSource == null) {
124             fInputSource = new InputSource();
125         }
126         fInputSource.setByteStream(byteStream);
127     } // setByteStream(InputStream)
128

129     /**
130      * Sets the character stream. If the character stream is not already
131      * opened when this object is instantiated, then the code that opens
132      * the stream should also set the character stream on this object.
133      * Also, the encoding of the byte stream used by the reader should
134      * also be set on this object, if known.
135      *
136      * @param charStream The new character stream.
137      *
138      * @see #setEncoding
139      */

140     public void setCharacterStream(Reader JavaDoc charStream) {
141         super.setCharacterStream(charStream);
142         if (fInputSource == null) {
143             fInputSource = new InputSource();
144         }
145         fInputSource.setCharacterStream(charStream);
146     } // setCharacterStream(Reader)
147

148     /**
149      * Sets the encoding of the stream.
150      *
151      * @param encoding The new encoding.
152      */

153     public void setEncoding(String JavaDoc encoding) {
154         super.setEncoding(encoding);
155         if (fInputSource == null) {
156             fInputSource = new InputSource();
157         }
158         fInputSource.setEncoding(encoding);
159     } // setEncoding(String)
160

161 } // SAXInputSource
162
Popular Tags