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 /** 00029 * @file QtXMLReaderAdaptor.C 00030 * @brief Implementation of class qgxml::QtXMLReaderAdaptor. 00031 * 00032 * See file QtXMLReaderAdaptor.H for the interface. 00033 * 00034 * @author <a href="mailto:qgar-contact@loria.fr?subject=Qgar fwd Jan Rendek">Jan Rendek</a> 00035 * @date March 11, 2003 11:08 00036 * @since Qgar 2.1 00037 */ 00038 00039 00040 // For RCS/CVS use: Do not delete 00041 /* $Id: QtXMLReaderAdaptor.C,v 1.3 2004/07/01 22:19:21 masini Exp $ */ 00042 00043 00044 #include <qgarlib/qtimpl/QtXMLReaderAdaptor.H> 00045 00046 // QGAR 00047 #include <qgarlib/qtimpl/QtQgarContentHandlerAdaptor.H> 00048 #include <qgarlib/qtimpl/QtQgarDTDHandlerAdaptor.H> 00049 #include <qgarlib/qtimpl/QtQgarEntityResolverAdaptor.H> 00050 #include <qgarlib/qtimpl/QtQgarErrorHandlerAdaptor.H> 00051 #include <qgarlib/qtimpl/QtQgarInputSourceAdaptor.H> 00052 #include <qgarlib/sax/ContentHandler.H> 00053 #include <qgarlib/sax/DTDHandler.H> 00054 #include <qgarlib/sax/EntityResolver.H> 00055 #include <qgarlib/sax/ErrorHandler.H> 00056 00057 00058 // STD 00059 #include <stdexcept> 00060 00061 00062 using namespace std; 00063 00064 namespace qgxml { 00065 00066 00067 // --------------------------------------------------------------------- 00068 // C O N S T R U C T O R S 00069 // --------------------------------------------------------------------- 00070 00071 QtXMLReaderAdaptor::QtXMLReaderAdaptor() 00072 { 00073 _impl = new QXmlSimpleReader(); 00074 00075 00076 //-- Initialize handler pointers 00077 00078 _contentHandler = 0; 00079 _dtdHandler = 0; 00080 _entityRes = 0; 00081 _errorHandler = 0; 00082 00083 00084 //-- Initialize wrapper objs 00085 00086 _contentHandlerA = 0; 00087 _dtdHandlerA = 0; 00088 _entityResA = 0; 00089 _errorHandlerA = 0; 00090 } 00091 00092 00093 // --------------------------------------------------------------------- 00094 // D E S T R U C T O R 00095 // --------------------------------------------------------------------- 00096 00097 QtXMLReaderAdaptor::~QtXMLReaderAdaptor() 00098 { 00099 delete _impl; 00100 00101 delete _contentHandlerA; 00102 delete _dtdHandlerA; 00103 delete _entityResA; 00104 delete _errorHandlerA; 00105 } 00106 00107 00108 00109 // --------------------------------------------------------------------- 00110 // A C C E S S 00111 // --------------------------------------------------------------------- 00112 00113 ContentHandler * 00114 QtXMLReaderAdaptor::getContentHandler() const 00115 { 00116 return _contentHandler; 00117 } 00118 00119 // --------------------------------------------------------------------- 00120 00121 DTDHandler * 00122 QtXMLReaderAdaptor::getDTDHandler() const 00123 { 00124 return _dtdHandler; 00125 } 00126 00127 // --------------------------------------------------------------------- 00128 00129 EntityResolver * 00130 QtXMLReaderAdaptor::getEntityResolver() const 00131 { 00132 return _entityRes; 00133 } 00134 00135 // --------------------------------------------------------------------- 00136 00137 ErrorHandler * 00138 QtXMLReaderAdaptor::getErrorHandler() const 00139 { 00140 return _errorHandler; 00141 } 00142 00143 // --------------------------------------------------------------------- 00144 00145 bool 00146 QtXMLReaderAdaptor::getFeature(const string& name) const 00147 { 00148 return _impl->hasFeature(_sc.convert(name)); 00149 } 00150 00151 // --------------------------------------------------------------------- 00152 00153 void * 00154 QtXMLReaderAdaptor::getProperty(const string& name) const 00155 { 00156 return _impl->property(_sc.convert(name)); 00157 } 00158 00159 00160 00161 // --------------------------------------------------------------------- 00162 // T R A N S F O R M A T I O N 00163 // ---------------------------------------------------------------------- 00164 00165 void 00166 QtXMLReaderAdaptor::setContentHandler(ContentHandler * handler) 00167 { 00168 _contentHandler = handler; 00169 00170 delete _contentHandlerA; 00171 _contentHandlerA = new QtQgarContentHandlerAdaptor(handler); 00172 00173 _impl->setContentHandler(_contentHandlerA); 00174 } 00175 00176 // --------------------------------------------------------------------- 00177 00178 void 00179 QtXMLReaderAdaptor::setDTDHandler(DTDHandler * handler) 00180 { 00181 _dtdHandler = handler; 00182 00183 delete _dtdHandlerA; 00184 _dtdHandlerA = new QtQgarDTDHandlerAdaptor(handler); 00185 00186 _impl->setDTDHandler(_dtdHandlerA); 00187 } 00188 00189 // --------------------------------------------------------------------- 00190 00191 void 00192 QtXMLReaderAdaptor::setEntityResolver(EntityResolver * resolver) 00193 { 00194 _entityRes = resolver; 00195 00196 delete _entityResA; 00197 _entityResA = new QtQgarEntityResolverAdaptor(resolver); 00198 00199 _impl->setEntityResolver(_entityResA); 00200 } 00201 00202 // --------------------------------------------------------------------- 00203 00204 void 00205 QtXMLReaderAdaptor::setErrorHandler(ErrorHandler * handler) 00206 { 00207 _errorHandler = handler; 00208 00209 delete _errorHandlerA; 00210 _errorHandlerA = new QtQgarErrorHandlerAdaptor(handler); 00211 00212 _impl->setErrorHandler(_errorHandlerA); 00213 } 00214 00215 // --------------------------------------------------------------------- 00216 00217 void 00218 QtXMLReaderAdaptor::setFeature(const string& name, bool value) 00219 { 00220 _impl->setFeature(_sc(name), value); 00221 } 00222 00223 // --------------------------------------------------------------------- 00224 00225 void 00226 QtXMLReaderAdaptor::setProperty(const string& name, void * value) 00227 { 00228 _impl->setProperty(_sc(name), value); 00229 } 00230 00231 00232 // ------------------------------------------------------------------- 00233 // O T H E R 00234 // ------------------------------------------------------------------- 00235 00236 void 00237 QtXMLReaderAdaptor::parse(InputSource& input) 00238 { 00239 QtQgarInputSourceAdaptor * source = 00240 new QtQgarInputSourceAdaptor(&input); 00241 00242 _impl->parse(source); 00243 00244 delete source; 00245 } 00246 00247 // --------------------------------------------------------------------- 00248 00249 void 00250 QtXMLReaderAdaptor::parse(const string& systemId) 00251 { 00252 throw runtime_error("Feature unsupported by Qt\n"); 00253 } 00254 00255 00256 // ---------------------------------------------------------------------- 00257 00258 } // namespace qgxml