xref: /trunk/main/dbaccess/source/filter/xml/xmlExport.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
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 
24 #ifndef DBA_XMLEXPORT_HXX
25 #define DBA_XMLEXPORT_HXX
26 
27 #ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_
28 #include <com/sun/star/container/XNamed.hpp>
29 #endif
30 #ifndef _COM_SUN_STAR_DOCUMENT_XFILTER_HPP_
31 #include <com/sun/star/document/XFilter.hpp>
32 #endif
33 #ifndef _COM_SUN_STAR_DOCUMENT_XIMPORTER_HPP_
34 #include <com/sun/star/document/XImporter.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_DOCUMENT_XEXPORTER_HPP_
37 #include <com/sun/star/document/XExporter.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
40 #include <com/sun/star/lang/XInitialization.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
49 #include <com/sun/star/lang/XComponent.hpp>
50 #endif
51 #ifndef _CPPUHELPER_IMPLBASE1_HXX_
52 #include <cppuhelper/implbase1.hxx>
53 #endif
54 #ifndef _CPPUHELPER_IMPLBASE5_HXX_
55 #include <cppuhelper/implbase5.hxx>
56 #endif
57 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
58 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
61 #include <com/sun/star/io/XActiveDataSource.hpp>
62 #endif
63 #ifndef _OSL_DIAGNOSE_H_
64 #include <osl/diagnose.h>
65 #endif
66 #ifndef _UNOTOOLS_TEMPFILE_HXX
67 #include <unotools/tempfile.hxx>
68 #endif
69 #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX
70 #include <unotools/localfilehelper.hxx>
71 #endif
72 #ifndef _UNTOOLS_UCBSTREAMHELPER_HXX
73 #include <unotools/ucbstreamhelper.hxx>
74 #endif
75 #ifndef _XMLOFF_XMLEXP_HXX
76 #include <xmloff/xmlexp.hxx>
77 #endif
78 #ifndef _XMLOFF_XMLIMP_HXX
79 #include <xmloff/xmlimp.hxx>
80 #endif
81 #ifndef _DBASHARED_APITOOLS_HXX_
82 #include "apitools.hxx"
83 #endif
84 #include "dsntypes.hxx"
85 #ifndef _COMPHELPER_STLTYPES_HXX_
86 #include <comphelper/stl_types.hxx>
87 #endif
88 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
89 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
90 #endif
91 
92 #include <memory>
93 
94 namespace dbaxml
95 {
96 using namespace ::xmloff::token;
97 using namespace ::com::sun::star::uno;
98 using namespace ::com::sun::star::container;
99 using namespace ::com::sun::star::lang;
100 using namespace ::com::sun::star::beans;
101 using namespace ::com::sun::star::document;
102 using namespace ::com::sun::star::sdbcx;
103 using namespace ::com::sun::star::text;
104 using namespace ::com::sun::star::io;
105 using namespace ::com::sun::star::xml::sax;
106 // -------------
107 // - ODBExport -
108 // -------------
109 #define PROGRESS_BAR_STEP 20
110 
111 class ODBExport : public SvXMLExport
112 {
113     typedef ::std::map< ::xmloff::token::XMLTokenEnum, ::rtl::OUString> TSettingsMap;
114 
115     typedef ::std::pair< ::rtl::OUString ,::rtl::OUString> TStringPair;
116     struct TDelimiter
117     {
118         ::rtl::OUString sText;
119         ::rtl::OUString sField;
120         ::rtl::OUString sDecimal;
121         ::rtl::OUString sThousand;
122         bool            bUsed;
123 
TDelimiterdbaxml::ODBExport::TDelimiter124         TDelimiter() : bUsed( false ) { }
125     };
126     typedef ::std::map< Reference<XPropertySet> ,::rtl::OUString >          TPropertyStyleMap;
127     typedef ::std::map< Reference<XPropertySet> ,Reference<XPropertySet> >  TTableColumnMap;
128 
129     struct TypedPropertyValue
130     {
131         ::rtl::OUString               Name;
132         ::com::sun::star::uno::Type   Type;
133         ::com::sun::star::uno::Any    Value;
134 
TypedPropertyValuedbaxml::ODBExport::TypedPropertyValue135         TypedPropertyValue( const ::rtl::OUString& _name, const ::com::sun::star::uno::Type& _type, const ::com::sun::star::uno::Any& _value )
136             :Name( _name )
137             ,Type( _type )
138             ,Value( _value )
139         {
140         }
141     };
142 
143     ::std::auto_ptr< TStringPair >                  m_aAutoIncrement;
144     ::std::auto_ptr< TDelimiter >                   m_aDelimiter;
145     ::std::vector< TypedPropertyValue >             m_aDataSourceSettings;
146     ::std::vector< XMLPropertyState >               m_aCurrentPropertyStates;
147     TPropertyStyleMap                               m_aAutoStyleNames;
148     TPropertyStyleMap                               m_aCellAutoStyleNames;
149     TPropertyStyleMap                               m_aRowAutoStyleNames;
150     TTableColumnMap                                 m_aTableDummyColumns;
151     ::rtl::OUString                                 m_sCharSet;
152     UniReference < SvXMLExportPropertyMapper>       m_xExportHelper;
153     UniReference < SvXMLExportPropertyMapper>       m_xColumnExportHelper;
154     UniReference < SvXMLExportPropertyMapper>       m_xCellExportHelper;
155     UniReference < SvXMLExportPropertyMapper>       m_xRowExportHelper;
156 
157     mutable UniReference < XMLPropertySetMapper >   m_xTableStylesPropertySetMapper;
158     mutable UniReference < XMLPropertySetMapper >   m_xColumnStylesPropertySetMapper;
159     mutable UniReference < XMLPropertySetMapper >   m_xCellStylesPropertySetMapper;
160     mutable UniReference < XMLPropertySetMapper >   m_xRowStylesPropertySetMapper;
161 
162     Reference<XPropertySet>                         m_xDataSource;
163     ::dbaccess::ODsnTypeCollection                  m_aTypeCollection;
164     sal_Bool                                        m_bAllreadyFilled;
165 
166     void                    exportDataSource();
167     void                    exportConnectionData();
168     void                    exportDriverSettings(const TSettingsMap& _aSettings);
169     void                    exportApplicationConnectionSettings(const TSettingsMap& _aSettings);
170     void                    exportLogin();
171     void                    exportSequence(const Sequence< ::rtl::OUString>& _aValue
172                                         ,::xmloff::token::XMLTokenEnum _eTokenFilter
173                                         ,::xmloff::token::XMLTokenEnum _eTokenType);
174     void                    exportDelimiter();
175     void                    exportAutoIncrement();
176     void                    exportCharSet();
177     void                    exportDataSourceSettings();
178     void                    exportForms();
179     void                    exportReports();
180     void                    exportQueries(sal_Bool _bExportContext);
181     void                    exportTables(sal_Bool _bExportContext);
182     void                    exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt);
183     void                    exportStyleName(const ::xmloff::token::XMLTokenEnum _eToken,const Reference<XPropertySet>& _xProp,SvXMLAttributeList& _rAtt,TPropertyStyleMap& _rMap);
184     void                    exportCollection(const Reference< XNameAccess >& _xCollection
185                                             ,enum ::xmloff::token::XMLTokenEnum _eComponents
186                                             ,enum ::xmloff::token::XMLTokenEnum _eSubComponents
187                                             ,sal_Bool _bExportContext
188                                             ,const ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >& _aMemFunc
189                                             );
190     void                    exportComponent(XPropertySet* _xProp);
191     void                    exportQuery(XPropertySet* _xProp);
192     void                    exportTable(XPropertySet* _xProp);
193     void                    exportFilter(XPropertySet* _xProp
194                                         ,const ::rtl::OUString& _sProp
195                                         ,enum ::xmloff::token::XMLTokenEnum _eStatementType);
196     void                    exportTableName(XPropertySet* _xProp,sal_Bool _bUpdate);
197     void                    exportAutoStyle(XPropertySet* _xProp);
198     void                    exportColumns(const Reference<XColumnsSupplier>& _xColSup);
199     void                    collectComponentStyles();
200 
201     ::rtl::OUString         implConvertAny(const Any& _rValue);
202 
203     UniReference < XMLPropertySetMapper > GetTableStylesPropertySetMapper() const;
204 
205 private:
206                             ODBExport();
207 protected:
208 
209     virtual void                    _ExportStyles( sal_Bool bUsed );
210     virtual void                    _ExportAutoStyles();
211     virtual void                    _ExportContent();
212     virtual void                    _ExportMasterStyles();
213     virtual void                    _ExportFontDecls();
214     virtual sal_uInt32              exportDoc( enum ::xmloff::token::XMLTokenEnum eClass );
215     virtual SvXMLAutoStylePoolP*    CreateAutoStylePool();
216 
217     virtual void GetViewSettings(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aProps);
218     virtual void GetConfigurationSettings(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aProps);
219 
~ODBExport()220     virtual                 ~ODBExport(){};
221 public:
222 
223     ODBExport(const Reference< XMultiServiceFactory >& _rxMSF, sal_uInt16 nExportFlag = EXPORT_CONTENT | EXPORT_AUTOSTYLES | EXPORT_PRETTY | EXPORT_FONTDECLS | EXPORT_SCRIPTS );
224     // XServiceInfo
225     DECLARE_SERVICE_INFO_STATIC( );
226 
227     UniReference < XMLPropertySetMapper > GetColumnStylesPropertySetMapper() const;
228     UniReference < XMLPropertySetMapper > GetCellStylesPropertySetMapper() const;
229 
230     // XExporter
231     virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
232 
getDataSource() const233     inline Reference<XPropertySet> getDataSource() const { return m_xDataSource; }
234 };
235 
236 // -----------------------------------------------------------------------------
237 } // dbaxml
238 // -----------------------------------------------------------------------------
239 #endif // DBA_XMLEXPORT_HXX
240