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