00001 /*---------------------------------------------------------------------* 00002 | Library QgarLib, graphics analysis and recognition | 00003 | Copyright (C) 2003 Qgar Project, LORIA | 00004 | | 00005 | This library is free software; you can redistribute it and/or | 00006 | modify it under the terms of the GNU Lesser General Public | 00007 | License version 2.1, as published by the Free Software Foundation. | 00008 | | 00009 | This library is distributed in the hope that it will be useful, | 00010 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00011 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 00012 | See the GNU Lesser General Public License for more details. | 00013 | | 00014 | The GNU Lesser General Public License is included in the file | 00015 | LICENSE.LGPL, in the root directory of the Qgar packaging. See | 00016 | http://www.gnu.org/licenses/lgpl.html for the terms of the license. | 00017 | To receive a paper copy, write to the Free Software Foundation, | 00018 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 00019 | | 00020 | Contact Project Qgar for any information: | 00021 | LORIA - équipe Qgar | 00022 | B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France | 00023 | email: qgar-contact@loria.fr | 00024 | http://www.qgar.org/ | 00025 *---------------------------------------------------------------------*/ 00026 00027 00028 #ifndef __INPUTSOURCE_H_INCLUDED__ 00029 #define __INPUTSOURCE_H_INCLUDED__ 00030 00031 00032 /** 00033 * @file InputSource.H 00034 * @brief Header file of class qgxml::InputSource 00035 * 00036 * @author <a href="mailto:qgar-contact@loria.fr?subject=Qgar fwd Jan Rendek">Jan Rendek</a> 00037 * @date March 12, 2003 10:00 00038 * @since Qgar 2.1.1 00039 */ 00040 00041 00042 // For RCS/CVS use: Do not delete 00043 /* $Id: InputSource.H,v 1.5 2004/07/02 20:36:43 masini Exp $ */ 00044 00045 00046 #include <istream> 00047 #include <string> 00048 00049 namespace qgxml { 00050 00051 00052 /** 00053 * @class InputSource InputSource.H <qgarlib/sax/InputSource.H> 00054 * @ingroup XML 00055 * @brief A single input source for an XML entity. 00056 * 00057 * This class allows a SAX application to encapsulate information 00058 * about an input source in a single object, which may include a 00059 * public identifier, a system identifier, and/or a byte stream. 00060 * 00061 * <b> This class is an adaptation for C++ of the interface of the same 00062 * name implemented in the Java SAX API (http://www.saxproject.org). 00063 * </b> 00064 * 00065 * @author <a href="mailto:qgar-contact@loria.fr?subject=Qgar fwd Jan Rendek">Jan Rendek</a> (Adaptation) 00066 * @date March 12, 2003 10:00 00067 * @since Qgar 2.1.1 00068 */ 00069 class InputSource { 00070 00071 // ------------------------------------------------------------------- 00072 // P U B L I C M E M B E R S 00073 // ------------------------------------------------------------------- 00074 public: 00075 00076 00077 00078 /** @name Constructors */ 00079 // ============ 00080 //@{ 00081 00082 /** 00083 * @brief Default constructor 00084 */ 00085 InputSource() : _byteStream(0) 00086 { /* EMPTY */ } 00087 00088 00089 /** 00090 * @brief Create a new input source from an input stream 00091 * 00092 * @param byteStream The raw byte stream containing the document. 00093 */ 00094 InputSource(std::istream& byteStream) 00095 : _byteStream(&byteStream) 00096 { /* EMPTY */ } 00097 00098 00099 /** 00100 * @brief Create a new input source with a system identifier. 00101 * 00102 * @param systemId The system identifier (URI). 00103 */ 00104 InputSource(const std::string& systemId) 00105 : _byteStream(0), _systemId(systemId) 00106 { /* EMPTY */ } 00107 00108 00109 /** 00110 * @brief Copy-constructor 00111 */ 00112 InputSource(const InputSource& rhs) 00113 : _byteStream(rhs._byteStream), 00114 _systemId(rhs._systemId), 00115 _publicId(rhs._publicId), 00116 _encoding(rhs._encoding) 00117 { /* EMPTY */ } 00118 00119 //@} 00120 00121 00122 /** @name Destructor */ 00123 // ========== 00124 //@{ 00125 00126 /** 00127 * @brief Destructor 00128 */ 00129 virtual ~InputSource() 00130 { /* EMPTY */ } 00131 00132 //@} 00133 00134 00135 /** @name Access */ 00136 // ====== 00137 //@{ 00138 00139 /** 00140 * @brief Get the byte stream for this input source. 00141 * 00142 * @return The byte stream, or null if none was supplied. 00143 */ 00144 virtual std::istream* getByteStream() 00145 { return _byteStream; } 00146 00147 00148 /** 00149 * @brief Get the character encoding for a byte stream or URI. 00150 * 00151 * @return The encoding. 00152 */ 00153 virtual std::string getEncoding() 00154 { return _encoding; } 00155 00156 /** 00157 * @brief Get the public identifier for this input source. 00158 * 00159 * @return The public identifier, or an empty string if none was supplied. 00160 */ 00161 virtual std::string getPublicId() 00162 { return _publicId; } 00163 00164 /** 00165 * @brief Get the system identifier for this input source. 00166 * 00167 * @return The system identifier, or an empty string if none was 00168 * supplied. 00169 */ 00170 virtual std::string getSystemId() 00171 { return _systemId; } 00172 00173 00174 //@} 00175 00176 00177 /** @name Transformation */ 00178 // ============== 00179 //@{ 00180 00181 /** 00182 * @brief Set the byte stream for this input source. 00183 * 00184 * @param byteStream An std::inputstream containing an XML document or 00185 * other entity. 00186 */ 00187 virtual void setByteStream(std::istream& byteStream) 00188 { _byteStream = &byteStream; } 00189 00190 /** 00191 * @brief Set the character encoding, if known. 00192 * 00193 * @param encoding A string describing the character encoding. 00194 */ 00195 virtual void setEncoding(const std::string& encoding) 00196 { _encoding = encoding; } 00197 00198 /** 00199 * @brief Set the public identifier for this input source. 00200 * 00201 * @param publicId The public identifier as a string. 00202 */ 00203 virtual void setPublicId(const std::string& publicId) 00204 { _publicId = publicId; } 00205 00206 /** 00207 * @brief Set the system identifier for this input source. 00208 * 00209 * @param systemId The system identifier as a string. 00210 */ 00211 virtual void setSystemId(const std::string& systemId) 00212 { _systemId = systemId; } 00213 00214 //@} 00215 00216 00217 /** @name Operators */ 00218 // ========= 00219 //@{ 00220 /** 00221 * @brief Assignment operator 00222 */ 00223 InputSource& operator=(const InputSource& rhs) 00224 { 00225 if (this != &rhs) { 00226 _byteStream = rhs._byteStream; 00227 00228 _systemId = rhs._systemId; 00229 _publicId = rhs._publicId; 00230 _encoding = rhs._encoding; 00231 } 00232 00233 return *this; 00234 } 00235 //@} 00236 00237 00238 // ------------------------------------------------------------------- 00239 // P R O T E C T E D M E M B E R S 00240 // ------------------------------------------------------------------- 00241 protected: 00242 00243 /// The input stream the input source gets its data from. 00244 std::istream * _byteStream; 00245 00246 /// The system ID of this input source, empty if unknown. 00247 std::string _systemId; 00248 00249 /// The public TD of this input source, empty if unknown. 00250 std::string _publicId; 00251 00252 /// The encoding of this input source, empty if unknown. 00253 std::string _encoding; 00254 00255 00256 // ------------------------------------------------------------------- 00257 00258 }; // class InputSource 00259 00260 } // namespace qgxml 00261 00262 00263 #endif /* __INPUTSOURCE_H_INCLUDED__ */