[2674] | 1 | /* |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 4 | * this work for additional information regarding copyright ownership. |
---|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 6 | * (the "License"); you may not use this file except in compliance with |
---|
| 7 | * the License. You may obtain a copy of the License at |
---|
| 8 | * |
---|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | * |
---|
| 11 | * Unless required by applicable law or agreed to in writing, software |
---|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | * See the License for the specific language governing permissions and |
---|
| 15 | * limitations under the License. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | /* |
---|
| 19 | * $Id: InputSource.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | #ifndef INPUTSOURCE_HPP |
---|
| 24 | #define INPUTSOURCE_HPP |
---|
| 25 | |
---|
| 26 | #include <xercesc/util/PlatformUtils.hpp> |
---|
| 27 | |
---|
| 28 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 29 | |
---|
| 30 | class BinInputStream; |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * A single input source for an XML entity. |
---|
| 35 | * |
---|
| 36 | * <p>This class encapsulates information about an input source in a |
---|
| 37 | * single object, which may include a public identifier or a system |
---|
| 38 | * identifier</p> |
---|
| 39 | * |
---|
| 40 | * <p>There are two places that the application will deliver this input |
---|
| 41 | * source to the parser: as the argument to the Parser::parse method, or as |
---|
| 42 | * the return value of the EntityResolver::resolveEntity method.</p> |
---|
| 43 | * |
---|
| 44 | * <p>InputSource is never used directly, but is the base class for a number |
---|
| 45 | * of derived classes for particular types of input sources. Derivatives are |
---|
| 46 | * provided (in the framework/ directory) for URL input sources, memory buffer |
---|
| 47 | * input sources, and so on.</p> |
---|
| 48 | * |
---|
| 49 | * <p>When it is time to parse the input described by an input source, it |
---|
| 50 | * will be asked to create a binary stream for that source. That stream will |
---|
| 51 | * be used to input the data of the source. The derived class provides the |
---|
| 52 | * implementation of the makeStream() method, and provides a type of stream |
---|
| 53 | * of the correct type for the input source it represents. |
---|
| 54 | * |
---|
| 55 | * <p>An InputSource object belongs to the application: the parser never |
---|
| 56 | * modifies them in any way. They are always passed by const reference so |
---|
| 57 | * the parser will make a copy of any input sources that it must keep |
---|
| 58 | * around beyond the call.</p> |
---|
| 59 | * |
---|
| 60 | * @see Parser#parse |
---|
| 61 | * @see EntityResolver#resolveEntity |
---|
| 62 | */ |
---|
| 63 | class SAX_EXPORT InputSource : public XMemory |
---|
| 64 | { |
---|
| 65 | public: |
---|
| 66 | // ----------------------------------------------------------------------- |
---|
| 67 | // All constructors are hidden, just the destructor is available |
---|
| 68 | // ----------------------------------------------------------------------- |
---|
| 69 | /** @name Destructor */ |
---|
| 70 | //@{ |
---|
| 71 | /** |
---|
| 72 | * Destructor |
---|
| 73 | * |
---|
| 74 | */ |
---|
| 75 | virtual ~InputSource(); |
---|
| 76 | //@} |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | // ----------------------------------------------------------------------- |
---|
| 80 | /** @name Virtual input source interface */ |
---|
| 81 | //@{ |
---|
| 82 | /** |
---|
| 83 | * Makes the byte stream for this input source. |
---|
| 84 | * |
---|
| 85 | * <p>The derived class must create and return a binary input stream of an |
---|
| 86 | * appropriate type for its kind of data source. The returned stream must |
---|
| 87 | * be dynamically allocated and becomes the parser's property. |
---|
| 88 | * </p> |
---|
| 89 | * |
---|
| 90 | * @see BinInputStream |
---|
| 91 | */ |
---|
| 92 | virtual BinInputStream* makeStream() const = 0; |
---|
| 93 | |
---|
| 94 | //@} |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | // ----------------------------------------------------------------------- |
---|
| 98 | /** @name Getter methods */ |
---|
| 99 | //@{ |
---|
| 100 | /** |
---|
| 101 | * An input source can be set to force the parser to assume a particular |
---|
| 102 | * encoding for the data that input source reprsents, via the setEncoding() |
---|
| 103 | * method. This method returns name of the encoding that is to be forced. |
---|
| 104 | * If the encoding has never been forced, it returns a null pointer. |
---|
| 105 | * |
---|
| 106 | * @return The forced encoding, or null if none was supplied. |
---|
| 107 | * @see #setEncoding |
---|
| 108 | */ |
---|
| 109 | virtual const XMLCh* getEncoding() const; |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | * Get the public identifier for this input source. |
---|
| 114 | * |
---|
| 115 | * @return The public identifier, or null if none was supplied. |
---|
| 116 | * @see #setPublicId |
---|
| 117 | */ |
---|
| 118 | virtual const XMLCh* getPublicId() const; |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * Get the system identifier for this input source. |
---|
| 123 | * |
---|
| 124 | * <p>If the system ID is a URL, it will be fully resolved.</p> |
---|
| 125 | * |
---|
| 126 | * @return The system identifier. |
---|
| 127 | * @see #setSystemId |
---|
| 128 | */ |
---|
| 129 | virtual const XMLCh* getSystemId() const; |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | * Get the flag that indicates if the parser should issue fatal error if this input source |
---|
| 133 | * is not found. |
---|
| 134 | * |
---|
| 135 | * @return True if the parser should issue fatal error if this input source is not found. |
---|
| 136 | * False if the parser issue warning message instead. |
---|
| 137 | * @see #setIssueFatalErrorIfNotFound |
---|
| 138 | */ |
---|
| 139 | virtual bool getIssueFatalErrorIfNotFound() const; |
---|
| 140 | |
---|
| 141 | MemoryManager* getMemoryManager() const; |
---|
| 142 | |
---|
| 143 | //@} |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | // ----------------------------------------------------------------------- |
---|
| 147 | /** @name Setter methods */ |
---|
| 148 | //@{ |
---|
| 149 | |
---|
| 150 | /** |
---|
| 151 | * Set the encoding which will be required for use with the XML text read |
---|
| 152 | * via a stream opened by this input source. |
---|
| 153 | * |
---|
| 154 | * <p>This is usually not set, allowing the encoding to be sensed in the |
---|
| 155 | * usual XML way. However, in some cases, the encoding in the file is known |
---|
| 156 | * to be incorrect because of intermediate transcoding, for instance |
---|
| 157 | * encapsulation within a MIME document. |
---|
| 158 | * |
---|
| 159 | * @param encodingStr The name of the encoding to force. |
---|
| 160 | */ |
---|
| 161 | virtual void setEncoding(const XMLCh* const encodingStr); |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | /** |
---|
| 165 | * Set the public identifier for this input source. |
---|
| 166 | * |
---|
| 167 | * <p>The public identifier is always optional: if the application writer |
---|
| 168 | * includes one, it will be provided as part of the location information.</p> |
---|
| 169 | * |
---|
| 170 | * @param publicId The public identifier as a string. |
---|
| 171 | * @see Locator#getPublicId |
---|
| 172 | * @see SAXParseException#getPublicId |
---|
| 173 | * @see #getPublicId |
---|
| 174 | */ |
---|
| 175 | virtual void setPublicId(const XMLCh* const publicId); |
---|
| 176 | |
---|
| 177 | /** |
---|
| 178 | * Set the system identifier for this input source. |
---|
| 179 | * |
---|
| 180 | * <p>Set the system identifier for this input source. |
---|
| 181 | * |
---|
| 182 | * </p>The system id is always required. The public id may be used to map |
---|
| 183 | * to another system id, but the system id must always be present as a fall |
---|
| 184 | * back. |
---|
| 185 | * |
---|
| 186 | * <p>If the system ID is a URL, it must be fully resolved.</p> |
---|
| 187 | * |
---|
| 188 | * @param systemId The system identifier as a string. |
---|
| 189 | * @see #getSystemId |
---|
| 190 | * @see Locator#getSystemId |
---|
| 191 | * @see SAXParseException#getSystemId |
---|
| 192 | */ |
---|
| 193 | virtual void setSystemId(const XMLCh* const systemId); |
---|
| 194 | |
---|
| 195 | /** |
---|
| 196 | * Indicates if the parser should issue fatal error if this input source |
---|
| 197 | * is not found. If set to false, the parser issue warning message instead. |
---|
| 198 | * |
---|
| 199 | * @param flag True if the parser should issue fatal error if this input source is not found. |
---|
| 200 | * If set to false, the parser issue warning message instead. (Default: true) |
---|
| 201 | * |
---|
| 202 | * @see #getIssueFatalErrorIfNotFound |
---|
| 203 | */ |
---|
| 204 | virtual void setIssueFatalErrorIfNotFound(const bool flag); |
---|
| 205 | |
---|
| 206 | //@} |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | protected : |
---|
| 210 | // ----------------------------------------------------------------------- |
---|
| 211 | // Hidden constructors |
---|
| 212 | // ----------------------------------------------------------------------- |
---|
| 213 | /** @name Constructors and Destructor */ |
---|
| 214 | //@{ |
---|
| 215 | /** Default constructor */ |
---|
| 216 | InputSource(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
| 217 | |
---|
| 218 | /** Constructor with a system identifier as XMLCh type. |
---|
| 219 | * @param systemId The system identifier (URI). |
---|
| 220 | * @param manager Pointer to the memory manager to be used to |
---|
| 221 | * allocate objects. |
---|
| 222 | */ |
---|
| 223 | InputSource(const XMLCh* const systemId, |
---|
| 224 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
| 225 | |
---|
| 226 | /** Constructor with a system and public identifiers |
---|
| 227 | * @param systemId The system identifier (URI). |
---|
| 228 | * @param publicId The public identifier as in the entity definition. |
---|
| 229 | * @param manager Pointer to the memory manager to be used to |
---|
| 230 | * allocate objects. |
---|
| 231 | */ |
---|
| 232 | InputSource |
---|
| 233 | ( |
---|
| 234 | const XMLCh* const systemId |
---|
| 235 | , const XMLCh* const publicId |
---|
| 236 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 237 | ); |
---|
| 238 | |
---|
| 239 | /** Constructor witha system identifier as string |
---|
| 240 | * @param systemId The system identifier (URI). |
---|
| 241 | * @param manager Pointer to the memory manager to be used to |
---|
| 242 | * allocate objects. |
---|
| 243 | */ |
---|
| 244 | InputSource(const char* const systemId, |
---|
| 245 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
| 246 | |
---|
| 247 | /** Constructor witha system and public identifiers. Both as string |
---|
| 248 | * @param systemId The system identifier (URI). |
---|
| 249 | * @param publicId The public identifier as in the entity definition. |
---|
| 250 | * @param manager Pointer to the memory manager to be used to |
---|
| 251 | * allocate objects. |
---|
| 252 | */ |
---|
| 253 | InputSource |
---|
| 254 | ( |
---|
| 255 | const char* const systemId |
---|
| 256 | , const char* const publicId |
---|
| 257 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 258 | ); |
---|
| 259 | |
---|
| 260 | //@} |
---|
| 261 | |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | private: |
---|
| 267 | // ----------------------------------------------------------------------- |
---|
| 268 | // Unimplemented constructors and operators |
---|
| 269 | // ----------------------------------------------------------------------- |
---|
| 270 | InputSource(const InputSource&); |
---|
| 271 | InputSource& operator=(const InputSource&); |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | // ----------------------------------------------------------------------- |
---|
| 275 | // Private data members |
---|
| 276 | // |
---|
| 277 | // fEncoding |
---|
| 278 | // This is the encoding to use. Usually this is null, which means |
---|
| 279 | // to use the information found in the file itself. But, if set, |
---|
| 280 | // this encoding will be used without question. |
---|
| 281 | // |
---|
| 282 | // fPublicId |
---|
| 283 | // This is the optional public id for the input source. It can be |
---|
| 284 | // null if none is desired. |
---|
| 285 | // |
---|
| 286 | // fSystemId |
---|
| 287 | // This is the system id for the input source. This is what is |
---|
| 288 | // actually used to open the source. |
---|
| 289 | // |
---|
| 290 | // fFatalErrorIfNotFound |
---|
| 291 | // ----------------------------------------------------------------------- |
---|
| 292 | MemoryManager* const fMemoryManager; |
---|
| 293 | XMLCh* fEncoding; |
---|
| 294 | XMLCh* fPublicId; |
---|
| 295 | XMLCh* fSystemId; |
---|
| 296 | bool fFatalErrorIfNotFound; |
---|
| 297 | }; |
---|
| 298 | |
---|
| 299 | |
---|
| 300 | // --------------------------------------------------------------------------- |
---|
| 301 | // InputSource: Getter methods |
---|
| 302 | // --------------------------------------------------------------------------- |
---|
| 303 | inline const XMLCh* InputSource::getEncoding() const |
---|
| 304 | { |
---|
| 305 | return fEncoding; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | inline const XMLCh* InputSource::getPublicId() const |
---|
| 309 | { |
---|
| 310 | return fPublicId; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | inline const XMLCh* InputSource::getSystemId() const |
---|
| 314 | { |
---|
| 315 | return fSystemId; |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | inline bool InputSource::getIssueFatalErrorIfNotFound() const |
---|
| 319 | { |
---|
| 320 | return fFatalErrorIfNotFound; |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | inline MemoryManager* InputSource::getMemoryManager() const |
---|
| 324 | { |
---|
| 325 | return fMemoryManager; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | // --------------------------------------------------------------------------- |
---|
| 329 | // InputSource: Setter methods |
---|
| 330 | // --------------------------------------------------------------------------- |
---|
| 331 | inline void InputSource::setIssueFatalErrorIfNotFound(const bool flag) |
---|
| 332 | { |
---|
| 333 | fFatalErrorIfNotFound = flag; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | XERCES_CPP_NAMESPACE_END |
---|
| 337 | |
---|
| 338 | #endif |
---|