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 
20 #pragma once
21 
22 #include <com/sun/star/container/XNamed.hpp>
23 #include <com/sun/star/document/XFilter.hpp>
24 #include <com/sun/star/document/XImporter.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/lang/XComponent.hpp>
27 #include <com/sun/star/io/XActiveDataSource.hpp>
28 #include <xmloff/maptype.hxx>
29 #include <xmloff/txtprmap.hxx>
30 #include <xmloff/xmlexp.hxx>
31 #include <xmloff/xmlexppr.hxx>
32 #include <dsntypes.hxx>
33 #include <comphelper/stl_types.hxx>
34 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
35 
36 #include <memory>
37 
38 
39 namespace dbaxml {
40 
41 using namespace ::xmloff::token;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::container;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::beans;
46 using namespace ::com::sun::star::document;
47 using namespace ::com::sun::star::sdbcx;
48 using namespace ::com::sun::star::text;
49 using namespace ::com::sun::star::io;
50 using namespace ::com::sun::star::xml::sax;
51 
52 
53 class ODBExport : public SvXMLExport
54 {
55     typedef std::map< ::xmloff::token::XMLTokenEnum, OUString> TSettingsMap;
56 
57     typedef std::pair< OUString ,OUString> TStringPair;
58     struct TDelimiter
59     {
60         OUString sText;
61         OUString sField;
62         OUString sDecimal;
63         OUString sThousand;
64         bool            bUsed;
65 
TDelimiterdbaxml::ODBExport::TDelimiter66         TDelimiter() : bUsed( false ) { }
67     };
68     typedef std::map< Reference<XPropertySet> ,OUString >          TPropertyStyleMap;
69     typedef std::map< Reference<XPropertySet> ,Reference<XPropertySet> >  TTableColumnMap;
70 
71     struct TypedPropertyValue
72     {
73         OUString         Name;
74         css::uno::Type   Type;
75         css::uno::Any    Value;
76 
TypedPropertyValuedbaxml::ODBExport::TypedPropertyValue77         TypedPropertyValue( const OUString& _name, const css::uno::Type& _type, const css::uno::Any& _value )
78             :Name( _name )
79             ,Type( _type )
80             ,Value( _value )
81         {
82         }
83     };
84 
85     std::unique_ptr< TStringPair >                  m_aAutoIncrement;
86     std::unique_ptr< TDelimiter >                   m_aDelimiter;
87     std::vector< TypedPropertyValue >             m_aDataSourceSettings;
88     std::vector< XMLPropertyState >               m_aCurrentPropertyStates;
89     TPropertyStyleMap                               m_aAutoStyleNames;
90     TPropertyStyleMap                               m_aCellAutoStyleNames;
91     TPropertyStyleMap                               m_aRowAutoStyleNames;
92     TTableColumnMap                                 m_aTableDummyColumns;
93     OUString                                 m_sCharSet;
94     rtl::Reference < SvXMLExportPropertyMapper>       m_xExportHelper;
95     rtl::Reference < SvXMLExportPropertyMapper>       m_xColumnExportHelper;
96     rtl::Reference < SvXMLExportPropertyMapper>       m_xCellExportHelper;
97     rtl::Reference < SvXMLExportPropertyMapper>       m_xRowExportHelper;
98 
99     mutable rtl::Reference < XMLPropertySetMapper >   m_xTableStylesPropertySetMapper;
100     mutable rtl::Reference < XMLPropertySetMapper >   m_xColumnStylesPropertySetMapper;
101     mutable rtl::Reference < XMLPropertySetMapper >   m_xCellStylesPropertySetMapper;
102 
103     Reference<XPropertySet>                         m_xDataSource;
104     ::dbaccess::ODsnTypeCollection                  m_aTypeCollection;
105     bool                                        m_bAllreadyFilled;
106 
107     void                    exportDataSource();
108     void                    exportConnectionData();
109     void                    exportDriverSettings(const TSettingsMap& _aSettings);
110     void                    exportApplicationConnectionSettings(const TSettingsMap& _aSettings);
111     void                    exportLogin();
112     void                    exportSequence(const Sequence< OUString>& _aValue
113                                         ,::xmloff::token::XMLTokenEnum _eTokenFilter
114                                         ,::xmloff::token::XMLTokenEnum _eTokenType);
115     void                    exportDelimiter();
116     void                    exportAutoIncrement();
117     void                    exportCharSet();
118     template< typename T > void exportDataSourceSettingsSequence(
119         std::vector< TypedPropertyValue >::iterator const & in);
120     void                    exportDataSourceSettings();
121     void                    exportForms();
122     void                    exportReports();
123     void                    exportQueries(bool _bExportContext);
124     void                    exportTables(bool _bExportContext);
125     void                    exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt);
126     void                    exportStyleName(const ::xmloff::token::XMLTokenEnum _eToken,const Reference<XPropertySet>& _xProp,SvXMLAttributeList& _rAtt,TPropertyStyleMap& _rMap);
127     void                    exportCollection(const Reference< XNameAccess >& _xCollection
128                                             ,enum ::xmloff::token::XMLTokenEnum _eComponents
129                                             ,enum ::xmloff::token::XMLTokenEnum _eSubComponents
130                                             ,bool _bExportContext
131                                             ,const ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >& _aMemFunc
132                                             );
133     void                    exportComponent(XPropertySet* _xProp);
134     void                    exportQuery(XPropertySet* _xProp);
135     void                    exportTable(XPropertySet* _xProp);
136     void                    exportFilter(XPropertySet* _xProp
137                                         ,const OUString& _sProp
138                                         ,enum ::xmloff::token::XMLTokenEnum _eStatementType);
139     void                    exportTableName(XPropertySet* _xProp,bool _bUpdate);
140     void                    exportAutoStyle(XPropertySet* _xProp);
141     void                    exportColumns(const Reference<XColumnsSupplier>& _xColSup);
142     void                    collectComponentStyles();
143 
144     static OUString         implConvertAny(const Any& _rValue);
145 
146     rtl::Reference < XMLPropertySetMapper > const & GetTableStylesPropertySetMapper() const;
147 
148                             ODBExport() = delete;
149 protected:
150 
151     virtual void                    ExportAutoStyles_() override;
152     virtual void                    ExportContent_() override;
153     virtual void                    ExportMasterStyles_() override;
154     virtual void                    ExportFontDecls_() override;
155     virtual SvXMLAutoStylePoolP*    CreateAutoStylePool() override;
156 
157     virtual void GetViewSettings(css::uno::Sequence<css::beans::PropertyValue>& aProps) override;
158     virtual void GetConfigurationSettings(css::uno::Sequence<css::beans::PropertyValue>& aProps) override;
159 
~ODBExport()160     virtual                 ~ODBExport() override {};
161 public:
162 
163     ODBExport(const Reference< XComponentContext >& _rxContext, OUString const & implementationName, SvXMLExportFlags nExportFlag = SvXMLExportFlags::CONTENT | SvXMLExportFlags::AUTOSTYLES | SvXMLExportFlags::PRETTY | SvXMLExportFlags::FONTDECLS | SvXMLExportFlags::SCRIPTS );
164 
165     rtl::Reference < XMLPropertySetMapper > const & GetColumnStylesPropertySetMapper() const;
166     rtl::Reference < XMLPropertySetMapper > const & GetCellStylesPropertySetMapper() const;
167 
168     // XExporter
169     virtual void SAL_CALL setSourceDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
170 
getDataSource() const171     const Reference<XPropertySet>& getDataSource() const { return m_xDataSource; }
172 };
173 
174 } // dbaxml
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
177