1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef DBAUI_TOKENWRITER_HXX 28*cdf0e10cSrcweir #define DBAUI_TOKENWRITER_HXX 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "DExport.hxx" 31*cdf0e10cSrcweir #include "moduledbu.hxx" 32*cdf0e10cSrcweir #include "commontypes.hxx" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetUpdate.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XRowLocate.hpp> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 46*cdf0e10cSrcweir #include <tools/stream.hxx> 47*cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #include <memory> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir namespace com { namespace sun { namespace star { 52*cdf0e10cSrcweir namespace sdbc{ 53*cdf0e10cSrcweir class XRowUpdate; 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir }}} 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir namespace dbaui 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir // ========================================================================= 60*cdf0e10cSrcweir // ODatabaseImportExport Basisklasse f"ur Import/Export 61*cdf0e10cSrcweir // ========================================================================= 62*cdf0e10cSrcweir class ODatabaseExport; 63*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener> ODatabaseImportExport_BASE; 64*cdf0e10cSrcweir class ODatabaseImportExport : public ODatabaseImportExport_BASE 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir private: 67*cdf0e10cSrcweir void impl_initializeRowMember_throw(); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir protected: 70*cdf0e10cSrcweir ::com::sun::star::lang::Locale m_aLocale; 71*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> m_aSelection; 72*cdf0e10cSrcweir sal_Bool m_bBookmarkSelection; 73*cdf0e10cSrcweir SvStream* m_pStream; 74*cdf0e10cSrcweir ::com::sun::star::awt::FontDescriptor m_aFont; 75*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xObject; // table/query 76*cdf0e10cSrcweir SharedConnection m_xConnection; 77*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > m_xResultSet; 78*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > m_xRow; 79*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate > m_xRowLocate; 80*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > m_xResultSetMetaData; 81*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > m_xRowSetColumns; 82*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier 83*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory> m_xFactory; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir ::rtl::OUString m_sName; 86*cdf0e10cSrcweir //dyf add 20070601 87*cdf0e10cSrcweir //for transfor the tablename 88*cdf0e10cSrcweir ::rtl::OUString m_sDefaultTableName; 89*cdf0e10cSrcweir //dyf add end 90*cdf0e10cSrcweir ::rtl::OUString m_sDataSourceName; 91*cdf0e10cSrcweir sal_Int32 m_nCommandType; 92*cdf0e10cSrcweir bool m_bNeedToReInitialize; 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir #if defined UNX 95*cdf0e10cSrcweir static const char __FAR_DATA sNewLine; 96*cdf0e10cSrcweir #else 97*cdf0e10cSrcweir static const char __FAR_DATA sNewLine[]; 98*cdf0e10cSrcweir #endif 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir ODatabaseExport* m_pReader; 101*cdf0e10cSrcweir sal_Int32* m_pRowMarker; // wenn gesetzt, dann nur diese Rows kopieren 102*cdf0e10cSrcweir rtl_TextEncoding m_eDestEnc; 103*cdf0e10cSrcweir sal_Bool m_bInInitialize; 104*cdf0e10cSrcweir sal_Bool m_bCheckOnly; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // export data 107*cdf0e10cSrcweir ODatabaseImportExport( const ::svx::ODataAccessDescriptor& _aDataDescriptor, 108*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM, 109*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF, 110*cdf0e10cSrcweir const String& rExchange = String()); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // import data 113*cdf0e10cSrcweir ODatabaseImportExport( const SharedConnection& _rxConnection, 114*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF, 115*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir virtual ~ODatabaseImportExport(); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir virtual void initialize(); 120*cdf0e10cSrcweir public: 121*cdf0e10cSrcweir void setStream(SvStream* _pStream){ m_pStream = _pStream; } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir //dyf add 20070601 124*cdf0e10cSrcweir //for set the tablename 125*cdf0e10cSrcweir void setSTableName(const ::rtl::OUString &_sTableName){ m_sDefaultTableName = _sTableName; } 126*cdf0e10cSrcweir //dyf add end 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir virtual sal_Bool Write(); // Export 129*cdf0e10cSrcweir virtual sal_Bool Read(); // Import 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir void initialize(const ::svx::ODataAccessDescriptor& _aDataDescriptor); 132*cdf0e10cSrcweir void dispose(); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir void enableCheckOnly() { m_bCheckOnly = sal_True; } 135*cdf0e10cSrcweir sal_Bool isCheckEnabled() const { return m_bCheckOnly; } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir private: 139*cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 140*cdf0e10cSrcweir void impl_initFromDescriptor( const ::svx::ODataAccessDescriptor& _aDataDescriptor, bool _bPlusDefaultInit ); 141*cdf0e10cSrcweir }; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir // ========================================================================= 144*cdf0e10cSrcweir // RTF Im- und Export 145*cdf0e10cSrcweir // ========================================================================= 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir class ORTFImportExport : public ODatabaseImportExport 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir void appendRow(::rtl::OString* pHorzChar,sal_Int32 _nColumnCount,sal_Int32& k,sal_Int32& kk); 150*cdf0e10cSrcweir public: 151*cdf0e10cSrcweir // export data 152*cdf0e10cSrcweir ORTFImportExport( const ::svx::ODataAccessDescriptor& _aDataDescriptor, 153*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM, 154*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF, 155*cdf0e10cSrcweir const String& rExchange = String()) 156*cdf0e10cSrcweir : ODatabaseImportExport(_aDataDescriptor,_rM,_rxNumberF,rExchange) {}; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // import data 159*cdf0e10cSrcweir ORTFImportExport( const SharedConnection& _rxConnection, 160*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF, 161*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM) 162*cdf0e10cSrcweir : ODatabaseImportExport(_rxConnection,_rxNumberF,_rM) 163*cdf0e10cSrcweir {} 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir virtual sal_Bool Write(); 166*cdf0e10cSrcweir virtual sal_Bool Read(); 167*cdf0e10cSrcweir }; 168*cdf0e10cSrcweir // ========================================================================= 169*cdf0e10cSrcweir // HTML Im- und Export 170*cdf0e10cSrcweir // ========================================================================= 171*cdf0e10cSrcweir #define SBA_HTML_FONTSIZES 7 172*cdf0e10cSrcweir const sal_Int16 nIndentMax = 23; 173*cdf0e10cSrcweir class OHTMLImportExport : public ODatabaseImportExport 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir // default HtmlFontSz[1-7] 176*cdf0e10cSrcweir static const sal_Int16 nDefaultFontSize[SBA_HTML_FONTSIZES]; 177*cdf0e10cSrcweir // HtmlFontSz[1-7] in s*3.ini [user] 178*cdf0e10cSrcweir static sal_Int16 nFontSize[SBA_HTML_FONTSIZES]; 179*cdf0e10cSrcweir static const sal_Int16 nCellSpacing; 180*cdf0e10cSrcweir static const char __FAR_DATA sIndentSource[]; 181*cdf0e10cSrcweir char sIndent[nIndentMax+1]; 182*cdf0e10cSrcweir sal_Int16 m_nIndent; 183*cdf0e10cSrcweir #ifdef DBG_UTIL 184*cdf0e10cSrcweir sal_Bool m_bCheckFont; 185*cdf0e10cSrcweir #endif 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir void WriteHeader(); 188*cdf0e10cSrcweir void WriteBody(); 189*cdf0e10cSrcweir void WriteTables(); 190*cdf0e10cSrcweir void WriteCell( sal_Int32 nFormat,sal_Int32 nWidthPixel,sal_Int32 nHeightPixel,const char* pChar,const String& rValue,const char* pHtmlTag); 191*cdf0e10cSrcweir void IncIndent( sal_Int16 nVal ); 192*cdf0e10cSrcweir const char* GetIndentStr() { return sIndent; } 193*cdf0e10cSrcweir void FontOn(); 194*cdf0e10cSrcweir inline void FontOff(); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir public: 197*cdf0e10cSrcweir // export data 198*cdf0e10cSrcweir OHTMLImportExport( const ::svx::ODataAccessDescriptor& _aDataDescriptor, 199*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM, 200*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF, 201*cdf0e10cSrcweir const String& rExchange = String()); 202*cdf0e10cSrcweir // import data 203*cdf0e10cSrcweir OHTMLImportExport( const SharedConnection& _rxConnection, 204*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF, 205*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM) 206*cdf0e10cSrcweir : ODatabaseImportExport(_rxConnection,_rxNumberF,_rM) 207*cdf0e10cSrcweir {} 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir virtual sal_Bool Write(); 210*cdf0e10cSrcweir virtual sal_Bool Read(); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir }; 213*cdf0e10cSrcweir // ========================================================================= 214*cdf0e10cSrcweir // normal RowSet Im- und Export 215*cdf0e10cSrcweir // ========================================================================= 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir class ORowSetImportExport : public ODatabaseImportExport 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir OModuleClient m_aModuleClient; 220*cdf0e10cSrcweir ::std::vector<sal_Int32> m_aColumnMapping; 221*cdf0e10cSrcweir ::std::vector<sal_Int32> m_aColumnTypes; 222*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate > m_xTargetResultSetUpdate; // 223*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowUpdate > m_xTargetRowUpdate; // 224*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > m_xTargetResultSetMetaData; // 225*cdf0e10cSrcweir Window* m_pParent; 226*cdf0e10cSrcweir sal_Bool m_bAlreadyAsked; 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir sal_Bool insertNewRow(); 229*cdf0e10cSrcweir protected: 230*cdf0e10cSrcweir virtual void initialize(); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir public: 233*cdf0e10cSrcweir // export data 234*cdf0e10cSrcweir ORowSetImportExport(Window* _pParent, 235*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate >& _xResultSetUpdate, 236*cdf0e10cSrcweir const ::svx::ODataAccessDescriptor& _aDataDescriptor, 237*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM, 238*cdf0e10cSrcweir const String& rExchange = String()); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir // import data 241*cdf0e10cSrcweir ORowSetImportExport(const SharedConnection& _rxConnection, 242*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM) 243*cdf0e10cSrcweir : ODatabaseImportExport(_rxConnection,NULL,_rM) 244*cdf0e10cSrcweir {} 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir virtual sal_Bool Write(); 247*cdf0e10cSrcweir virtual sal_Bool Read(); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir private: 250*cdf0e10cSrcweir using ODatabaseImportExport::initialize; 251*cdf0e10cSrcweir }; 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir #endif // DBAUI_TOKENWRITER_HXX 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir 258