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 
  26 import java.io.InputStream;
  27 import java.io.Reader;
  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     //
  67     // Constructors
  68     //
  69 
  70     /**
  71      * Constructs an input source from just the public and system
  72      * identifiers, leaving resolution of the entity and opening of
  73      * the input stream up to the caller.
  74      *
  75      * @param publicId     The public identifier, if known.
  76      * @param systemId     The system identifier. This value should
  77      *                     always be set, if possible, and can be
  78      *                     relative or absolute. If the system identifier
  79      *                     is relative, then the base system identifier
  80      *                     should be set.
  81      * @param baseSystemId The base system identifier. This value should
  82      *                     always be set to the fully expanded URI of the
  83      *                     base system identifier, if possible.
  84      */
  85     public XMLInputSource(String publicId, String systemId,
  86                           String baseSystemId) {
  87         fPublicId = publicId;
  88         fSystemId = systemId;
  89         fBaseSystemId = baseSystemId;
  90     } // <init>(String,String,String)
  91 
  92     /**
  93      * Constructs an input source from a XMLResourceIdentifier
  94      * object, leaving resolution of the entity and opening of
  95      * the input stream up to the caller.
  96      *
  97      * @param resourceIdentifier    the XMLResourceIdentifier containing the information
  98      */
  99     public XMLInputSource(XMLResourceIdentifier resourceIdentifier) {
 100 
 101         fPublicId = resourceIdentifier.getPublicId();
 102         fSystemId = resourceIdentifier.getLiteralSystemId();
 103         fBaseSystemId = resourceIdentifier.getBaseSystemId();
 104     } // <init>(XMLResourceIdentifier)
 105 
 106     /**
 107      * Constructs an input source from a byte stream.
 108      *
 109      * @param publicId     The public identifier, if known.
 110      * @param systemId     The system identifier. This value should
 111      *                     always be set, if possible, and can be
 112      *                     relative or absolute. If the system identifier
 113      *                     is relative, then the base system identifier
 114      *                     should be set.
 115      * @param baseSystemId The base system identifier. This value should
 116      *                     always be set to the fully expanded URI of the
 117      *                     base system identifier, if possible.
 118      * @param byteStream   The byte stream.
 119      * @param encoding     The encoding of the byte stream, if known.
 120      */
 121     public XMLInputSource(String publicId, String systemId,
 122                           String baseSystemId, InputStream byteStream,
 123                           String encoding) {
 124         fPublicId = publicId;
 125         fSystemId = systemId;
 126         fBaseSystemId = baseSystemId;
 127         fByteStream = byteStream;
 128         fEncoding = encoding;
 129     } // <init>(String,String,String,InputStream,String)
 130 
 131     /**
 132      * Constructs an input source from a character stream.
 133      *
 134      * @param publicId     The public identifier, if known.
 135      * @param systemId     The system identifier. This value should
 136      *                     always be set, if possible, and can be
 137      *                     relative or absolute. If the system identifier
 138      *                     is relative, then the base system identifier
 139      *                     should be set.
 140      * @param baseSystemId The base system identifier. This value should
 141      *                     always be set to the fully expanded URI of the
 142      *                     base system identifier, if possible.
 143      * @param charStream   The character stream.
 144      * @param encoding     The original encoding of the byte stream
 145      *                     used by the reader, if known.
 146      */
 147     public XMLInputSource(String publicId, String systemId,
 148                           String baseSystemId, Reader charStream,
 149                           String encoding) {
 150         fPublicId = publicId;
 151         fSystemId = systemId;
 152         fBaseSystemId = baseSystemId;
 153         fCharStream = charStream;
 154         fEncoding = encoding;
 155     } // <init>(String,String,String,Reader,String)
 156 
 157     //
 158     // Public methods
 159     //
 160 
 161     /**
 162      * Sets the public identifier.
 163      *
 164      * @param publicId The new public identifier.
 165      */
 166     public void setPublicId(String publicId) {
 167         fPublicId = publicId;
 168     } // setPublicId(String)
 169 
 170     /** Returns the public identifier. */
 171     public String getPublicId() {
 172         return fPublicId;
 173     } // getPublicId():String
 174 
 175     /**
 176      * Sets the system identifier.
 177      *
 178      * @param systemId The new system identifier.
 179      */
 180     public void setSystemId(String systemId) {
 181         fSystemId = systemId;
 182     } // setSystemId(String)
 183 
 184     /** Returns the system identifier. */
 185     public String getSystemId() {
 186         return fSystemId;
 187     } // getSystemId():String
 188 
 189     /**
 190      * Sets the base system identifier.
 191      *
 192      * @param baseSystemId The new base system identifier.
 193      */
 194     public void setBaseSystemId(String baseSystemId) {
 195         fBaseSystemId = baseSystemId;
 196     } // setBaseSystemId(String)
 197 
 198     /** Returns the base system identifier. */
 199     public String getBaseSystemId() {
 200         return fBaseSystemId;
 201     } // getBaseSystemId():String
 202 
 203     /**
 204      * Sets the byte stream. If the byte stream is not already opened
 205      * when this object is instantiated, then the code that opens the
 206      * stream should also set the byte stream on this object. Also, if
 207      * the encoding is auto-detected, then the encoding should also be
 208      * set on this object.
 209      *
 210      * @param byteStream The new byte stream.
 211      */
 212     public void setByteStream(InputStream byteStream) {
 213         fByteStream = byteStream;
 214     } // setByteStream(InputSource)
 215 
 216     /** Returns the byte stream. */
 217     public InputStream getByteStream() {
 218         return fByteStream;
 219     } // getByteStream():InputStream
 220 
 221     /**
 222      * Sets the character stream. If the character stream is not already
 223      * opened when this object is instantiated, then the code that opens
 224      * the stream should also set the character stream on this object.
 225      * Also, the encoding of the byte stream used by the reader should
 226      * also be set on this object, if known.
 227      *
 228      * @param charStream The new character stream.
 229      *
 230      * @see #setEncoding
 231      */
 232     public void setCharacterStream(Reader charStream) {
 233         fCharStream = charStream;
 234     } // setCharacterStream(Reader)
 235 
 236     /** Returns the character stream. */
 237     public Reader getCharacterStream() {
 238         return fCharStream;
 239     } // getCharacterStream():Reader
 240 
 241     /**
 242      * Sets the encoding of the stream.
 243      *
 244      * @param encoding The new encoding.
 245      */
 246     public void setEncoding(String encoding) {
 247         fEncoding = encoding;
 248     } // setEncoding(String)
 249 
 250     /** Returns the encoding of the stream, or null if not known. */
 251     public String getEncoding() {
 252         return fEncoding;
 253     } // getEncoding():String
 254 
 255 } // class XMLInputSource