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 #ifndef INCLUDED_DBACCESS_SOURCE_FILTER_XML_XMLFILTER_HXX
21 #define INCLUDED_DBACCESS_SOURCE_FILTER_XML_XMLFILTER_HXX
22 
23 #include <com/sun/star/container/XNamed.hpp>
24 #include <com/sun/star/document/XFilter.hpp>
25 #include <com/sun/star/document/XImporter.hpp>
26 #include <com/sun/star/document/XExporter.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/lang/XComponent.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/io/XActiveDataSource.hpp>
33 #include <osl/diagnose.h>
34 #include <unotools/tempfile.hxx>
35 #include <unotools/localfilehelper.hxx>
36 #include <xmloff/xmlimp.hxx>
37 #include <xmloff/xmlprmap.hxx>
38 
39 #include <map>
40 #include <memory>
41 
42 
43 namespace dbaxml
44 {
45 
46 using namespace ::xmloff::token;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::document;
52 using namespace ::com::sun::star::text;
53 using namespace ::com::sun::star::io;
54 using namespace ::com::sun::star::xml::sax;
55 
56 
57 class ODBFilter : public SvXMLImport
58 {
59 public:
60     typedef std::map< OUString, Sequence<PropertyValue> > TPropertyNameMap;
61 private:
62     TPropertyNameMap                                m_aQuerySettings;
63     TPropertyNameMap                                m_aTablesSettings;
64     std::vector< css::beans::PropertyValue>         m_aInfoSequence;
65 
66     mutable std::unique_ptr<SvXMLTokenMap>          m_pDocElemTokenMap;
67     mutable std::unique_ptr<SvXMLTokenMap>          m_pDocContentElemTokenMap;
68     mutable std::unique_ptr<SvXMLTokenMap>          m_pDatabaseElemTokenMap;
69     mutable std::unique_ptr<SvXMLTokenMap>          m_pDataSourceElemTokenMap;
70     mutable std::unique_ptr<SvXMLTokenMap>          m_pLoginElemTokenMap;
71     mutable std::unique_ptr<SvXMLTokenMap>          m_pDatabaseDescriptionElemTokenMap;
72     mutable std::unique_ptr<SvXMLTokenMap>          m_pDataSourceInfoElemTokenMap;
73     mutable std::unique_ptr<SvXMLTokenMap>          m_pDocumentsElemTokenMap;
74     mutable std::unique_ptr<SvXMLTokenMap>          m_pComponentElemTokenMap;
75     mutable std::unique_ptr<SvXMLTokenMap>          m_pQueryElemTokenMap;
76     mutable std::unique_ptr<SvXMLTokenMap>          m_pColumnElemTokenMap;
77 
78     mutable rtl::Reference < XMLPropertySetMapper >   m_xTableStylesPropertySetMapper;
79     mutable rtl::Reference < XMLPropertySetMapper >   m_xColumnStylesPropertySetMapper;
80     mutable rtl::Reference < XMLPropertySetMapper >   m_xCellStylesPropertySetMapper;
81     Reference<XPropertySet>                         m_xDataSource;
82     bool                                            m_bNewFormat;
83 
84     /// @throws RuntimeException
85     bool                            implImport( const Sequence< PropertyValue >& rDescriptor );
86 
87     /** fills the map with the Properties
88         @param  _rValue
89             The Any where the sequence resists in.
90         @param  _rMap
91             The map to fill.
92     */
93     static void fillPropertyMap(const Any& _rValue,TPropertyNameMap& _rMap);
94 
95 public:
96     SvXMLImportContext* CreateStylesContext(sal_uInt16 nPrefix,const OUString& rLocalName,
97                                      const Reference< XAttributeList>& xAttrList, bool bIsAutoStyle );
98 
99 protected:
100     // SvXMLImport
101     virtual SvXMLImportContext *CreateDocumentContext(sal_uInt16 nPrefix,
102                                       const OUString& rLocalName,
103                                       const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
104 
105     virtual ~ODBFilter()  throw() override;
106 public:
107 
108     explicit ODBFilter( const Reference< XComponentContext >& _rxContext );
109 
110     // XFilter
111     virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) override;
112 
113     /// @throws css::uno::RuntimeException
114     static OUString getImplementationName_Static();
115 
116     /// @throws css::uno::RuntimeException
117     static css::uno::Sequence<OUString>
118     getSupportedServiceNames_Static();
119 
120     static css::uno::Reference<css::uno::XInterface> Create(
121         css::uno::Reference<css::lang::XMultiServiceFactory> const & _rxORB);
122 
123     // helper class
124     virtual void SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
125     virtual void SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps) override;
126 
getDataSource() const127     const Reference<XPropertySet>& getDataSource() const { return m_xDataSource; }
128 
getQuerySettings() const129     const TPropertyNameMap& getQuerySettings() const { return m_aQuerySettings;}
130 
131     const SvXMLTokenMap& GetDocElemTokenMap() const;
132     const SvXMLTokenMap& GetDocContentElemTokenMap() const;
133     const SvXMLTokenMap& GetDatabaseElemTokenMap() const;
134     const SvXMLTokenMap& GetDataSourceElemTokenMap() const;
135     const SvXMLTokenMap& GetLoginElemTokenMap() const;
136     const SvXMLTokenMap& GetDatabaseDescriptionElemTokenMap() const;
137     const SvXMLTokenMap& GetDataSourceInfoElemTokenMap() const;
138     const SvXMLTokenMap& GetDocumentsElemTokenMap() const;
139     const SvXMLTokenMap& GetComponentElemTokenMap() const;
140     const SvXMLTokenMap& GetQueryElemTokenMap() const;
141     const SvXMLTokenMap& GetColumnElemTokenMap() const;
142 
143     rtl::Reference < XMLPropertySetMapper > const & GetTableStylesPropertySetMapper() const;
144     rtl::Reference < XMLPropertySetMapper > const & GetColumnStylesPropertySetMapper() const;
145     rtl::Reference < XMLPropertySetMapper > const & GetCellStylesPropertySetMapper() const;
146 
147     /** add an Info to the sequence which will be appended to the data source
148         @param  _rInfo The property to append.
149     */
addInfo(const css::beans::PropertyValue & _rInfo)150     void addInfo(const css::beans::PropertyValue& _rInfo)
151     {
152         m_aInfoSequence.push_back(_rInfo);
153     }
154 
155     void setPropertyInfo();
156 
isNewFormat() const157     bool isNewFormat() const { return m_bNewFormat; }
setNewFormat(bool _bNewFormat)158     void setNewFormat(bool _bNewFormat) { m_bNewFormat = _bNewFormat; }
159 };
160 
161 } // namespace dbaxml
162 #endif // INCLUDED_DBACCESS_SOURCE_FILTER_XML_XMLFILTER_HXX
163 
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
165