1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "commontypes.hxx"
23 #include <com/sun/star/awt/FontDescriptor.hpp>
24 #include <com/sun/star/sdbc/XResultSet.hpp>
25 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
26 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
27 #include <com/sun/star/sdbc/XRow.hpp>
28 #include <com/sun/star/lang/XEventListener.hpp>
29 #include <com/sun/star/container/XIndexAccess.hpp>
30 #include <com/sun/star/sdbcx/XRowLocate.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <com/sun/star/util/XNumberFormatter.hpp>
34 #include <cppuhelper/implbase.hxx>
35 #include <svx/dataaccessdescriptor.hxx>
36 #include <vcl/weld.hxx>
38 namespace com::sun::star
{
48 // ODatabaseImportExport base class for import/export
49 class ODatabaseExport
;
50 class ODatabaseImportExport
: public ::cppu::WeakImplHelper
< css::lang::XEventListener
>
53 css::uno::Sequence
< css::uno::Any
> m_aSelection
;
54 bool m_bBookmarkSelection
;
56 css::awt::FontDescriptor m_aFont
;
57 css::uno::Reference
< css::beans::XPropertySet
> m_xObject
; // table/query
58 SharedConnection m_xConnection
;
59 css::uno::Reference
< css::sdbc::XResultSet
> m_xResultSet
;
60 css::uno::Reference
< css::sdbc::XRow
> m_xRow
;
61 css::uno::Reference
< css::sdbcx::XRowLocate
> m_xRowLocate
;
62 css::uno::Reference
< css::sdbc::XResultSetMetaData
> m_xResultSetMetaData
;
63 css::uno::Reference
< css::container::XIndexAccess
> m_xRowSetColumns
;
64 css::uno::Reference
< css::util::XNumberFormatter
> m_xFormatter
; // a number formatter working with the connection's NumberFormatsSupplier
65 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
69 //for transfor the tablename
70 OUString m_sDefaultTableName
;
72 OUString m_sDataSourceName
;
73 sal_Int32 m_nCommandType
;
74 bool m_bNeedToReInitialize
;
76 rtl_TextEncoding m_eDestEnc
;
81 ODatabaseImportExport( const svx::ODataAccessDescriptor
& _aDataDescriptor
,
82 const css::uno::Reference
< css::uno::XComponentContext
>& _rM
,
83 const css::uno::Reference
< css::util::XNumberFormatter
>& _rxNumberF
);
86 ODatabaseImportExport( SharedConnection _xConnection
,
87 const css::uno::Reference
< css::util::XNumberFormatter
>& _rxNumberF
,
88 const css::uno::Reference
< css::uno::XComponentContext
>& _rM
);
90 virtual ~ODatabaseImportExport() override
;
92 virtual void initialize();
94 void setStream(SvStream
* _pStream
){ m_pStream
= _pStream
; }
96 //for set the tablename
97 void setSTableName(const OUString
&_sTableName
){ m_sDefaultTableName
= _sTableName
; }
99 virtual bool Write(); // Export
100 virtual bool Read(); // Import
102 void initialize(const svx::ODataAccessDescriptor
& _aDataDescriptor
);
105 void enableCheckOnly() { m_bCheckOnly
= true; }
106 bool isCheckEnabled() const { return m_bCheckOnly
; }
109 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
110 void impl_initFromDescriptor( const svx::ODataAccessDescriptor
& _aDataDescriptor
, bool _bPlusDefaultInit
);
113 // RTF Import and Export
115 class ORTFImportExport
: public ODatabaseImportExport
117 void appendRow(OString
const * pHorzChar
,sal_Int32 _nColumnCount
,sal_Int32
& k
,sal_Int32
& kk
);
120 ORTFImportExport( const svx::ODataAccessDescriptor
& _aDataDescriptor
,
121 const css::uno::Reference
< css::uno::XComponentContext
>& _rM
,
122 const css::uno::Reference
< css::util::XNumberFormatter
>& _rxNumberF
)
123 : ODatabaseImportExport(_aDataDescriptor
,_rM
,_rxNumberF
) {};
126 ORTFImportExport( const SharedConnection
& _rxConnection
,
127 const css::uno::Reference
< css::util::XNumberFormatter
>& _rxNumberF
,
128 const css::uno::Reference
< css::uno::XComponentContext
>& _rM
)
129 : ODatabaseImportExport(_rxConnection
,_rxNumberF
,_rM
)
132 virtual bool Write() override
;
133 virtual bool Read() override
;
135 // HTML Import and Export
136 #define SBA_HTML_FONTSIZES 7
137 const sal_Int16 nIndentMax
= 23;
138 class OHTMLImportExport
: public ODatabaseImportExport
140 static const sal_Int16 nCellSpacing
;
141 static const char sIndentSource
[];
142 char sIndent
[nIndentMax
+1];
144 #if OSL_DEBUG_LEVEL > 0
151 void WriteCell( sal_Int32 nFormat
,sal_Int32 nWidthPixel
,sal_Int32 nHeightPixel
,const char* pChar
,const OUString
& rValue
,const char* pHtmlTag
);
152 void IncIndent( sal_Int16 nVal
);
153 const char* GetIndentStr() const { return sIndent
; }
155 inline void FontOff();
159 OHTMLImportExport( const svx::ODataAccessDescriptor
& _aDataDescriptor
,
160 const css::uno::Reference
< css::uno::XComponentContext
>& _rM
,
161 const css::uno::Reference
< css::util::XNumberFormatter
>& _rxNumberF
);
163 OHTMLImportExport( const SharedConnection
& _rxConnection
,
164 const css::uno::Reference
< css::util::XNumberFormatter
>& _rxNumberF
,
165 const css::uno::Reference
< css::uno::XComponentContext
>& _rM
)
166 : ODatabaseImportExport(_rxConnection
,_rxNumberF
,_rM
)
170 virtual bool Write() override
;
171 virtual bool Read() override
;
174 // normal RowSet Import and Export
176 class ORowSetImportExport
: public ODatabaseImportExport
178 std::vector
<sal_Int32
> m_aColumnMapping
;
179 std::vector
<sal_Int32
> m_aColumnTypes
;
180 css::uno::Reference
< css::sdbc::XResultSetUpdate
> m_xTargetResultSetUpdate
;
181 css::uno::Reference
< css::sdbc::XRowUpdate
> m_xTargetRowUpdate
;
182 css::uno::Reference
< css::sdbc::XResultSetMetaData
> m_xTargetResultSetMetaData
;
183 weld::Window
* m_pParent
;
184 bool m_bAlreadyAsked
;
188 virtual void initialize() override
;
192 ORowSetImportExport(weld::Window
* pParent
,
193 const css::uno::Reference
< css::sdbc::XResultSetUpdate
>& xResultSetUpdate
,
194 const svx::ODataAccessDescriptor
& aDataDescriptor
,
195 const css::uno::Reference
< css::uno::XComponentContext
>& rM
);
197 virtual bool Write() override
;
198 virtual bool Read() override
;
201 using ODatabaseImportExport::initialize
;
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */