1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.xerces.internal.xni.parser; 23 24 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 25 import java.io.InputStream; 26 import java.io.Reader; 27 import org.xml.sax.InputSource; 28 29 /** 30 * This class represents an input source for an XML document. The 31 * basic properties of an input source are the following: 32 * <ul> 33 * <li>public identifier</li> 34 * <li>system identifier</li> 35 * <li>byte stream or character stream</li> 36 * <li> 37 * </ul> 38 * 39 * @author Andy Clark, IBM 40 * 41 */ 42 public class XMLInputSource { 43 44 // 45 // Data 46 // 47 48 /** Public identifier. */ 49 protected String fPublicId; 50 51 /** System identifier. */ 52 protected String fSystemId; 53 54 /** Base system identifier. */ 55 protected String fBaseSystemId; 56 57 /** Byte stream. */ 58 protected InputStream fByteStream; 59 60 /** Character stream. */ 61 protected Reader fCharStream; 62 63 /** Encoding. */ 64 protected String fEncoding; 65 66 //indicates whether the source is created by a resolver 67 boolean fIsCreatedByResolver = false; 68 // 69 // Constructors 70 // 71 72 /** 73 * Constructs an input source from just the public and system 74 * identifiers, leaving resolution of the entity and opening of 75 * the input stream up to the caller. 76 * 77 * @param publicId The public identifier, if known. 78 * @param systemId The system identifier. This value should 79 * always be set, if possible, and can be 80 * relative or absolute. If the system identifier 81 * is relative, then the base system identifier 82 * should be set. 83 * @param baseSystemId The base system identifier. This value should 84 * always be set to the fully expanded URI of the 85 * base system identifier, if possible. 86 * @param isCreatedByResolver a flag to indicate whether the source is 87 * created by a resolver 88 */ XMLInputSource(String publicId, String systemId, String baseSystemId, boolean isCreatedByResolver)89 public XMLInputSource(String publicId, String systemId, 90 String baseSystemId, boolean isCreatedByResolver) { 91 fPublicId = publicId; 92 fSystemId = systemId; 93 fBaseSystemId = baseSystemId; 94 fIsCreatedByResolver = isCreatedByResolver; 95 } // <init>(String,String,String) 96 97 /** 98 * Constructs an input source from a XMLResourceIdentifier 99 * object, leaving resolution of the entity and opening of 100 * the input stream up to the caller. 101 * 102 * @param resourceIdentifier the XMLResourceIdentifier containing the information 103 */ XMLInputSource(XMLResourceIdentifier resourceIdentifier)104 public XMLInputSource(XMLResourceIdentifier resourceIdentifier) { 105 106 fPublicId = resourceIdentifier.getPublicId(); 107 fSystemId = resourceIdentifier.getLiteralSystemId(); 108 fBaseSystemId = resourceIdentifier.getBaseSystemId(); 109 } // <init>(XMLResourceIdentifier) 110 111 /** 112 * Constructs an input source from a SAX InputSource 113 * object. 114 * 115 * @param inputSource a SAX InputSource 116 * @param isCreatedByResolver a flag to indicate whether the source is 117 * created by a resolver 118 */ XMLInputSource(InputSource inputSource, boolean isCreatedByResolver)119 public XMLInputSource(InputSource inputSource, boolean isCreatedByResolver) { 120 fPublicId = inputSource.getPublicId(); 121 fSystemId = inputSource.getSystemId(); 122 fByteStream = inputSource.getByteStream(); 123 fCharStream = inputSource.getCharacterStream(); 124 fEncoding = inputSource.getEncoding(); 125 fIsCreatedByResolver = isCreatedByResolver; 126 } 127 128 /** 129 * Constructs an input source from a byte stream. 130 * 131 * @param publicId The public identifier, if known. 132 * @param systemId The system identifier. This value should 133 * always be set, if possible, and can be 134 * relative or absolute. If the system identifier 135 * is relative, then the base system identifier 136 * should be set. 137 * @param baseSystemId The base system identifier. This value should 138 * always be set to the fully expanded URI of the 139 * base system identifier, if possible. 140 * @param byteStream The byte stream. 141 * @param encoding The encoding of the byte stream, if known. 142 */ XMLInputSource(String publicId, String systemId, String baseSystemId, InputStream byteStream, String encoding)143 public XMLInputSource(String publicId, String systemId, 144 String baseSystemId, InputStream byteStream, 145 String encoding) { 146 fPublicId = publicId; 147 fSystemId = systemId; 148 fBaseSystemId = baseSystemId; 149 fByteStream = byteStream; 150 fEncoding = encoding; 151 } // <init>(String,String,String,InputStream,String) 152 153 /** 154 * Constructs an input source from a character stream. 155 * 156 * @param publicId The public identifier, if known. 157 * @param systemId The system identifier. This value should 158 * always be set, if possible, and can be 159 * relative or absolute. If the system identifier 160 * is relative, then the base system identifier 161 * should be set. 162 * @param baseSystemId The base system identifier. This value should 163 * always be set to the fully expanded URI of the 164 * base system identifier, if possible. 165 * @param charStream The character stream. 166 * @param encoding The original encoding of the byte stream 167 * used by the reader, if known. 168 */ XMLInputSource(String publicId, String systemId, String baseSystemId, Reader charStream, String encoding)169 public XMLInputSource(String publicId, String systemId, 170 String baseSystemId, Reader charStream, 171 String encoding) { 172 fPublicId = publicId; 173 fSystemId = systemId; 174 fBaseSystemId = baseSystemId; 175 fCharStream = charStream; 176 fEncoding = encoding; 177 } // <init>(String,String,String,Reader,String) 178 179 // 180 // Public methods 181 // 182 183 /** 184 * Sets the public identifier. 185 * 186 * @param publicId The new public identifier. 187 */ setPublicId(String publicId)188 public void setPublicId(String publicId) { 189 fPublicId = publicId; 190 } // setPublicId(String) 191 192 /** Returns the public identifier. */ getPublicId()193 public String getPublicId() { 194 return fPublicId; 195 } // getPublicId():String 196 197 /** 198 * Sets the system identifier. 199 * 200 * @param systemId The new system identifier. 201 */ setSystemId(String systemId)202 public void setSystemId(String systemId) { 203 fSystemId = systemId; 204 } // setSystemId(String) 205 206 /** Returns the system identifier. */ getSystemId()207 public String getSystemId() { 208 return fSystemId; 209 } // getSystemId():String 210 211 /** 212 * Sets the base system identifier. 213 * 214 * @param baseSystemId The new base system identifier. 215 */ setBaseSystemId(String baseSystemId)216 public void setBaseSystemId(String baseSystemId) { 217 fBaseSystemId = baseSystemId; 218 } // setBaseSystemId(String) 219 220 /** Returns the base system identifier. */ getBaseSystemId()221 public String getBaseSystemId() { 222 return fBaseSystemId; 223 } // getBaseSystemId():String 224 225 /** 226 * Sets the byte stream. If the byte stream is not already opened 227 * when this object is instantiated, then the code that opens the 228 * stream should also set the byte stream on this object. Also, if 229 * the encoding is auto-detected, then the encoding should also be 230 * set on this object. 231 * 232 * @param byteStream The new byte stream. 233 */ setByteStream(InputStream byteStream)234 public void setByteStream(InputStream byteStream) { 235 fByteStream = byteStream; 236 } // setByteStream(InputSource) 237 238 /** Returns the byte stream. */ getByteStream()239 public InputStream getByteStream() { 240 return fByteStream; 241 } // getByteStream():InputStream 242 243 /** 244 * Sets the character stream. If the character stream is not already 245 * opened when this object is instantiated, then the code that opens 246 * the stream should also set the character stream on this object. 247 * Also, the encoding of the byte stream used by the reader should 248 * also be set on this object, if known. 249 * 250 * @param charStream The new character stream. 251 * 252 * @see #setEncoding 253 */ setCharacterStream(Reader charStream)254 public void setCharacterStream(Reader charStream) { 255 fCharStream = charStream; 256 } // setCharacterStream(Reader) 257 258 /** Returns the character stream. */ getCharacterStream()259 public Reader getCharacterStream() { 260 return fCharStream; 261 } // getCharacterStream():Reader 262 263 /** 264 * Sets the encoding of the stream. 265 * 266 * @param encoding The new encoding. 267 */ setEncoding(String encoding)268 public void setEncoding(String encoding) { 269 fEncoding = encoding; 270 } // setEncoding(String) 271 272 /** Returns the encoding of the stream, or null if not known. */ getEncoding()273 public String getEncoding() { 274 return fEncoding; 275 } // getEncoding():String 276 277 /** 278 * Sets the flag to indicate whether this source is created by a resolver 279 * @param createdByResolver the flag 280 */ setCreatedByResolver(boolean createdByResolver)281 public void setCreatedByResolver(boolean createdByResolver) { 282 fIsCreatedByResolver = createdByResolver; 283 } 284 /** 285 * Returns a boolean to indicate whether this source is created by a resolver. 286 * @return true if the source is created by a resolver, false otherwise 287 */ isCreatedByResolver()288 public boolean isCreatedByResolver() { 289 return fIsCreatedByResolver; 290 } 291 292 } // class XMLInputSource 293