Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef DBAUI_TOKENWRITER_HXX
20 : #define DBAUI_TOKENWRITER_HXX
21 :
22 : #include "DExport.hxx"
23 : #include "moduledbu.hxx"
24 : #include "commontypes.hxx"
25 :
26 : #include <com/sun/star/awt/FontDescriptor.hpp>
27 : #include <com/sun/star/sdbc/XResultSet.hpp>
28 : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
29 : #include <com/sun/star/sdbc/XRow.hpp>
30 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 : #include <com/sun/star/lang/XEventListener.hpp>
32 : #include <com/sun/star/frame/XModel.hpp>
33 : #include <com/sun/star/beans/PropertyValue.hpp>
34 : #include <com/sun/star/sdb/CommandType.hpp>
35 : #include <com/sun/star/sdbcx/XRowLocate.hpp>
36 :
37 : #include <cppuhelper/implbase1.hxx>
38 : #include <tools/stream.hxx>
39 : #include <svx/dataaccessdescriptor.hxx>
40 :
41 : #include <memory>
42 :
43 : namespace com { namespace sun { namespace star {
44 : namespace sdbc{
45 : class XRowUpdate;
46 : }
47 : }}}
48 :
49 : namespace dbaui
50 : {
51 : // =========================================================================
52 : // ODatabaseImportExport base class for import/export
53 : // =========================================================================
54 : class ODatabaseExport;
55 : typedef ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener> ODatabaseImportExport_BASE;
56 : class ODatabaseImportExport : public ODatabaseImportExport_BASE
57 : {
58 : private:
59 : void impl_initializeRowMember_throw();
60 :
61 : protected:
62 : ::com::sun::star::lang::Locale m_aLocale;
63 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> m_aSelection;
64 : sal_Bool m_bBookmarkSelection;
65 : SvStream* m_pStream;
66 : ::com::sun::star::awt::FontDescriptor m_aFont;
67 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xObject; // table/query
68 : SharedConnection m_xConnection;
69 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > m_xResultSet;
70 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > m_xRow;
71 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XRowLocate > m_xRowLocate;
72 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > m_xResultSetMetaData;
73 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > m_xRowSetColumns;
74 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier
75 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory> m_xFactory;
76 :
77 : ::rtl::OUString m_sName;
78 :
79 : //for transfor the tablename
80 : ::rtl::OUString m_sDefaultTableName;
81 :
82 : ::rtl::OUString m_sDataSourceName;
83 : sal_Int32 m_nCommandType;
84 : bool m_bNeedToReInitialize;
85 :
86 : #if defined UNX
87 : static const char sNewLine;
88 : #else
89 : static const char sNewLine[];
90 : #endif
91 :
92 : ODatabaseExport* m_pReader;
93 : sal_Int32* m_pRowMarker; // if set, then copy only these rows
94 : rtl_TextEncoding m_eDestEnc;
95 : sal_Bool m_bInInitialize;
96 : sal_Bool m_bCheckOnly;
97 :
98 : // export data
99 : ODatabaseImportExport( const ::svx::ODataAccessDescriptor& _aDataDescriptor,
100 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM,
101 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
102 : const String& rExchange = String());
103 :
104 : // import data
105 : ODatabaseImportExport( const SharedConnection& _rxConnection,
106 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
107 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);
108 :
109 : virtual ~ODatabaseImportExport();
110 :
111 : virtual void initialize();
112 : public:
113 0 : void setStream(SvStream* _pStream){ m_pStream = _pStream; }
114 :
115 : //for set the tablename
116 0 : void setSTableName(const ::rtl::OUString &_sTableName){ m_sDefaultTableName = _sTableName; }
117 :
118 : virtual sal_Bool Write(); // Export
119 : virtual sal_Bool Read(); // Import
120 :
121 : void initialize(const ::svx::ODataAccessDescriptor& _aDataDescriptor);
122 : void dispose();
123 :
124 0 : void enableCheckOnly() { m_bCheckOnly = sal_True; }
125 0 : sal_Bool isCheckEnabled() const { return m_bCheckOnly; }
126 :
127 :
128 : private:
129 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
130 : void impl_initFromDescriptor( const ::svx::ODataAccessDescriptor& _aDataDescriptor, bool _bPlusDefaultInit );
131 : };
132 :
133 : // =========================================================================
134 : // RTF Import and Export
135 : // =========================================================================
136 :
137 0 : class ORTFImportExport : public ODatabaseImportExport
138 : {
139 : void appendRow(::rtl::OString* pHorzChar,sal_Int32 _nColumnCount,sal_Int32& k,sal_Int32& kk);
140 : public:
141 : // export data
142 0 : ORTFImportExport( const ::svx::ODataAccessDescriptor& _aDataDescriptor,
143 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM,
144 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
145 : const String& rExchange = String())
146 0 : : ODatabaseImportExport(_aDataDescriptor,_rM,_rxNumberF,rExchange) {};
147 :
148 : // import data
149 0 : ORTFImportExport( const SharedConnection& _rxConnection,
150 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
151 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM)
152 0 : : ODatabaseImportExport(_rxConnection,_rxNumberF,_rM)
153 0 : {}
154 :
155 : virtual sal_Bool Write();
156 : virtual sal_Bool Read();
157 : };
158 : // =========================================================================
159 : // HTML Import and Export
160 : // =========================================================================
161 : #define SBA_HTML_FONTSIZES 7
162 : const sal_Int16 nIndentMax = 23;
163 0 : class OHTMLImportExport : public ODatabaseImportExport
164 : {
165 : // default HtmlFontSz[1-7]
166 : static const sal_Int16 nDefaultFontSize[SBA_HTML_FONTSIZES];
167 : // HtmlFontSz[1-7] in s*3.ini [user]
168 : static sal_Int16 nFontSize[SBA_HTML_FONTSIZES];
169 : static const sal_Int16 nCellSpacing;
170 : static const char sIndentSource[];
171 : char sIndent[nIndentMax+1];
172 : sal_Int16 m_nIndent;
173 : #if OSL_DEBUG_LEVEL > 0
174 : sal_Bool m_bCheckFont;
175 : #endif
176 :
177 : void WriteHeader();
178 : void WriteBody();
179 : void WriteTables();
180 : void WriteCell( sal_Int32 nFormat,sal_Int32 nWidthPixel,sal_Int32 nHeightPixel,const char* pChar,const String& rValue,const char* pHtmlTag);
181 : void IncIndent( sal_Int16 nVal );
182 0 : const char* GetIndentStr() { return sIndent; }
183 : void FontOn();
184 : inline void FontOff();
185 :
186 : public:
187 : // export data
188 : OHTMLImportExport( const ::svx::ODataAccessDescriptor& _aDataDescriptor,
189 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM,
190 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
191 : const String& rExchange = String());
192 : // import data
193 0 : OHTMLImportExport( const SharedConnection& _rxConnection,
194 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
195 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM)
196 0 : : ODatabaseImportExport(_rxConnection,_rxNumberF,_rM)
197 0 : {}
198 :
199 : virtual sal_Bool Write();
200 : virtual sal_Bool Read();
201 :
202 : };
203 : // =========================================================================
204 : // normal RowSet Import and Export
205 : // =========================================================================
206 :
207 0 : class ORowSetImportExport : public ODatabaseImportExport
208 : {
209 : OModuleClient m_aModuleClient;
210 : ::std::vector<sal_Int32> m_aColumnMapping;
211 : ::std::vector<sal_Int32> m_aColumnTypes;
212 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate > m_xTargetResultSetUpdate; //
213 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowUpdate > m_xTargetRowUpdate; //
214 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > m_xTargetResultSetMetaData; //
215 : Window* m_pParent;
216 : sal_Bool m_bAlreadyAsked;
217 :
218 : sal_Bool insertNewRow();
219 : protected:
220 : virtual void initialize();
221 :
222 : public:
223 : // export data
224 : ORowSetImportExport(Window* _pParent,
225 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate >& _xResultSetUpdate,
226 : const ::svx::ODataAccessDescriptor& _aDataDescriptor,
227 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM,
228 : const String& rExchange = String());
229 :
230 : // import data
231 : ORowSetImportExport(const SharedConnection& _rxConnection,
232 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM)
233 : : ODatabaseImportExport(_rxConnection,NULL,_rM)
234 : {}
235 :
236 : virtual sal_Bool Write();
237 : virtual sal_Bool Read();
238 :
239 : private:
240 : using ODatabaseImportExport::initialize;
241 : };
242 :
243 : }
244 : #endif // DBAUI_TOKENWRITER_HXX
245 :
246 :
247 :
248 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|