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