1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001, 2002,2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.dom; 22 23 import org.w3c.dom.ls.LSInput; 24 25 import java.io.Reader; 26 import java.io.InputStream; 27 28 /** 29 * This Class <code>DOMInputImpl</code> represents a single input source for an XML entity. 30 * <p> This Class allows an application to encapsulate information about 31 * an input source in a single object, which may include a public 32 * identifier, a system identifier, a byte stream (possibly with a specified 33 * encoding), and/or a character stream. 34 * <p> The exact definitions of a byte stream and a character stream are 35 * binding dependent. 36 * <p> There are two places that the application will deliver this input 37 * source to the parser: as the argument to the <code>parse</code> method, 38 * or as the return value of the <code>DOMResourceResolver.resolveEntity</code> 39 * method. 40 * <p> The <code>DOMParser</code> will use the <code>LSInput</code> 41 * object to determine how to read XML input. If there is a character stream 42 * available, the parser will read that stream directly; if not, the parser 43 * will use a byte stream, if available; if neither a character stream nor a 44 * byte stream is available, the parser will attempt to open a URI 45 * connection to the resource identified by the system identifier. 46 * <p> An <code>LSInput</code> object belongs to the application: the 47 * parser shall never modify it in any way (it may modify a copy if 48 * necessary). Eventhough all attributes in this interface are writable the 49 * DOM implementation is expected to never mutate a LSInput. 50 * <p>See also the <a href='http://www.w3.org/TR/2001/WD-DOM-Level-3-ASLS-20011025'>Document Object Model (DOM) Level 3 Abstract Schemas and Load 51 and Save Specification</a>. 52 * 53 * @xerces.internal 54 * 55 * @author Gopal Sharma, SUN Microsystems Inc. 56 */ 57 58 // REVISIT: 59 // 1. it should be possible to do the following 60 // DOMInputImpl extends XMLInputSource implements LSInput 61 // 2. we probably need only the default constructor. -- el 62 63 public class DOMInputImpl implements LSInput { 64 65 // 66 // Data 67 // 68 69 protected String fPublicId = null; 70 protected String fSystemId = null; 71 protected String fBaseSystemId = null; 72 73 protected InputStream fByteStream = null; 74 protected Reader fCharStream = null; 75 protected String fData = null; 76 77 protected String fEncoding = null; 78 79 protected boolean fCertifiedText = false; 80 81 /** 82 * Default Constructor, constructs an input source 83 * 84 * 85 */ 86 public DOMInputImpl() {} 87 88 /** 89 * Constructs an input source from just the public and system 90 * identifiers, leaving resolution of the entity and opening of 91 * the input stream up to the caller. 92 * 93 * @param publicId The public identifier, if known. 94 * @param systemId The system identifier. This value should 95 * always be set, if possible, and can be 96 * relative or absolute. If the system identifier 97 * is relative, then the base system identifier 98 * should be set. 99 * @param baseSystemId The base system identifier. This value should 100 * always be set to the fully expanded URI of the 101 * base system identifier, if possible. 102 */ 103 104 public DOMInputImpl(String publicId, String systemId, 105 String baseSystemId) { 106 107 fPublicId = publicId; 108 fSystemId = systemId; 109 fBaseSystemId = baseSystemId; 110 111 } // DOMInputImpl(String,String,String) 112 113 /** 114 * Constructs an input source from a byte stream. 115 * 116 * @param publicId The public identifier, if known. 117 * @param systemId The system identifier. This value should 118 * always be set, if possible, and can be 119 * relative or absolute. If the system identifier 120 * is relative, then the base system identifier 121 * should be set. 122 * @param baseSystemId The base system identifier. This value should 123 * always be set to the fully expanded URI of the 124 * base system identifier, if possible. 125 * @param byteStream The byte stream. 126 * @param encoding The encoding of the byte stream, if known. 127 */ 128 129 public DOMInputImpl(String publicId, String systemId, 130 String baseSystemId, InputStream byteStream, 131 String encoding) { 132 133 fPublicId = publicId; 134 fSystemId = systemId; 135 fBaseSystemId = baseSystemId; 136 fByteStream = byteStream; 137 fEncoding = encoding; 138 139 } // DOMInputImpl(String,String,String,InputStream,String) 140 141 /** 142 * Constructs an input source from a character stream. 143 * 144 * @param publicId The public identifier, if known. 145 * @param systemId The system identifier. This value should 146 * always be set, if possible, and can be 147 * relative or absolute. If the system identifier 148 * is relative, then the base system identifier 149 * should be set. 150 * @param baseSystemId The base system identifier. This value should 151 * always be set to the fully expanded URI of the 152 * base system identifier, if possible. 153 * @param charStream The character stream. 154 * @param encoding The original encoding of the byte stream 155 * used by the reader, if known. 156 */ 157 158 public DOMInputImpl(String publicId, String systemId, 159 String baseSystemId, Reader charStream, 160 String encoding) { 161 162 fPublicId = publicId; 163 fSystemId = systemId; 164 fBaseSystemId = baseSystemId; 165 fCharStream = charStream; 166 fEncoding = encoding; 167 168 } // DOMInputImpl(String,String,String,Reader,String) 169 170 /** 171 * Constructs an input source from a String. 172 * 173 * @param publicId The public identifier, if known. 174 * @param systemId The system identifier. This value should 175 * always be set, if possible, and can be 176 * relative or absolute. If the system identifier 177 * is relative, then the base system identifier 178 * should be set. 179 * @param baseSystemId The base system identifier. This value should 180 * always be set to the fully expanded URI of the 181 * base system identifier, if possible. 182 * @param data The String Data. 183 * @param encoding The original encoding of the byte stream 184 * used by the reader, if known. 185 */ 186 187 public DOMInputImpl(String publicId, String systemId, 188 String baseSystemId, String data, 189 String encoding) { 190 fPublicId = publicId; 191 fSystemId = systemId; 192 fBaseSystemId = baseSystemId; 193 fData = data; 194 fEncoding = encoding; 195 } // DOMInputImpl(String,String,String,String,String) 196 197 /** 198 * An attribute of a language-binding dependent type that represents a 199 * stream of bytes. 200 * <br>The parser will ignore this if there is also a character stream 201 * specified, but it will use a byte stream in preference to opening a 202 * URI connection itself. 203 * <br>If the application knows the character encoding of the byte stream, 204 * it should set the encoding property. Setting the encoding in this way 205 * will override any encoding specified in the XML declaration itself. 206 */ 207 208 public InputStream getByteStream(){ 209 return fByteStream; 210 } 211 212 /** 213 * An attribute of a language-binding dependent type that represents a 214 * stream of bytes. 215 * <br>The parser will ignore this if there is also a character stream 216 * specified, but it will use a byte stream in preference to opening a 217 * URI connection itself. 218 * <br>If the application knows the character encoding of the byte stream, 219 * it should set the encoding property. Setting the encoding in this way 220 * will override any encoding specified in the XML declaration itself. 221 */ 222 223 public void setByteStream(InputStream byteStream){ 224 fByteStream = byteStream; 225 } 226 227 /** 228 * An attribute of a language-binding dependent type that represents a 229 * stream of 16-bit units. Application must encode the stream using 230 * UTF-16 (defined in and Amendment 1 of ). 231 * <br>If a character stream is specified, the parser will ignore any byte 232 * stream and will not attempt to open a URI connection to the system 233 * identifier. 234 */ 235 public Reader getCharacterStream(){ 236 return fCharStream; 237 } 238 /** 239 * An attribute of a language-binding dependent type that represents a 240 * stream of 16-bit units. Application must encode the stream using 241 * UTF-16 (defined in and Amendment 1 of ). 242 * <br>If a character stream is specified, the parser will ignore any byte 243 * stream and will not attempt to open a URI connection to the system 244 * identifier. 245 */ 246 247 public void setCharacterStream(Reader characterStream){ 248 fCharStream = characterStream; 249 } 250 251 /** 252 * A string attribute that represents a sequence of 16 bit units (utf-16 253 * encoded characters). 254 * <br>If string data is available in the input source, the parser will 255 * ignore the character stream and the byte stream and will not attempt 256 * to open a URI connection to the system identifier. 257 */ 258 public String getStringData(){ 259 return fData; 260 } 261 262 /** 263 * A string attribute that represents a sequence of 16 bit units (utf-16 264 * encoded characters). 265 * <br>If string data is available in the input source, the parser will 266 * ignore the character stream and the byte stream and will not attempt 267 * to open a URI connection to the system identifier. 268 */ 269 270 public void setStringData(String stringData){ 271 fData = stringData; 272 } 273 274 /** 275 * The character encoding, if known. The encoding must be a string 276 * acceptable for an XML encoding declaration ( section 4.3.3 "Character 277 * Encoding in Entities"). 278 * <br>This attribute has no effect when the application provides a 279 * character stream. For other sources of input, an encoding specified 280 * by means of this attribute will override any encoding specified in 281 * the XML claration or the Text Declaration, or an encoding obtained 282 * from a higher level protocol, such as HTTP . 283 */ 284 285 public String getEncoding(){ 286 return fEncoding; 287 } 288 289 /** 290 * The character encoding, if known. The encoding must be a string 291 * acceptable for an XML encoding declaration ( section 4.3.3 "Character 292 * Encoding in Entities"). 293 * <br>This attribute has no effect when the application provides a 294 * character stream. For other sources of input, an encoding specified 295 * by means of this attribute will override any encoding specified in 296 * the XML claration or the Text Declaration, or an encoding obtained 297 * from a higher level protocol, such as HTTP . 298 */ 299 public void setEncoding(String encoding){ 300 fEncoding = encoding; 301 } 302 303 /** 304 * The public identifier for this input source. The public identifier is 305 * always optional: if the application writer includes one, it will be 306 * provided as part of the location information. 307 */ 308 public String getPublicId(){ 309 return fPublicId; 310 } 311 /** 312 * The public identifier for this input source. The public identifier is 313 * always optional: if the application writer includes one, it will be 314 * provided as part of the location information. 315 */ 316 public void setPublicId(String publicId){ 317 fPublicId = publicId; 318 } 319 320 /** 321 * The system identifier, a URI reference , for this input source. The 322 * system identifier is optional if there is a byte stream or a 323 * character stream, but it is still useful to provide one, since the 324 * application can use it to resolve relative URIs and can include it in 325 * error messages and warnings (the parser will attempt to fetch the 326 * ressource identifier by the URI reference only if there is no byte 327 * stream or character stream specified). 328 * <br>If the application knows the character encoding of the object 329 * pointed to by the system identifier, it can register the encoding by 330 * setting the encoding attribute. 331 * <br>If the system ID is a relative URI reference (see section 5 in ), 332 * the behavior is implementation dependent. 333 */ 334 public String getSystemId(){ 335 return fSystemId; 336 } 337 /** 338 * The system identifier, a URI reference , for this input source. The 339 * system identifier is optional if there is a byte stream or a 340 * character stream, but it is still useful to provide one, since the 341 * application can use it to resolve relative URIs and can include it in 342 * error messages and warnings (the parser will attempt to fetch the 343 * ressource identifier by the URI reference only if there is no byte 344 * stream or character stream specified). 345 * <br>If the application knows the character encoding of the object 346 * pointed to by the system identifier, it can register the encoding by 347 * setting the encoding attribute. 348 * <br>If the system ID is a relative URI reference (see section 5 in ), 349 * the behavior is implementation dependent. 350 */ 351 public void setSystemId(String systemId){ 352 fSystemId = systemId; 353 } 354 355 /** 356 * The base URI to be used (see section 5.1.4 in ) for resolving relative 357 * URIs to absolute URIs. If the baseURI is itself a relative URI, the 358 * behavior is implementation dependent. 359 */ 360 public String getBaseURI(){ 361 return fBaseSystemId; 362 } 363 /** 364 * The base URI to be used (see section 5.1.4 in ) for resolving relative 365 * URIs to absolute URIs. If the baseURI is itself a relative URI, the 366 * behavior is implementation dependent. 367 */ 368 public void setBaseURI(String baseURI){ 369 fBaseSystemId = baseURI; 370 } 371 372 /** 373 * If set to true, assume that the input is certified (see section 2.13 374 * in [<a href='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]) when 375 * parsing [<a href='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]. 376 */ 377 public boolean getCertifiedText(){ 378 return fCertifiedText; 379 } 380 381 /** 382 * If set to true, assume that the input is certified (see section 2.13 383 * in [<a href='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]) when 384 * parsing [<a href='http://www.w3.org/TR/2002/CR-xml11-20021015/'>XML 1.1</a>]. 385 */ 386 387 public void setCertifiedText(boolean certifiedText){ 388 fCertifiedText = certifiedText; 389 } 390 391 }// class DOMInputImpl