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