Line data Source code
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 RPT_XMLEXPORT_HXX
21 : #define RPT_XMLEXPORT_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/report/XReportDefinition.hpp>
31 : #include <com/sun/star/report/XSection.hpp>
32 : #include <com/sun/star/report/XReportControlModel.hpp>
33 : #include <com/sun/star/report/XFormattedField.hpp>
34 : #include <com/sun/star/lang/XComponent.hpp>
35 : #include <cppuhelper/implbase1.hxx>
36 : #include <cppuhelper/implbase5.hxx>
37 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 : #include <com/sun/star/io/XActiveDataSource.hpp>
39 : #include <osl/diagnose.h>
40 : #include <unotools/tempfile.hxx>
41 : #include <unotools/localfilehelper.hxx>
42 : #include <unotools/ucbstreamhelper.hxx>
43 : #include <xmloff/xmlexp.hxx>
44 : #include <xmloff/xmlimp.hxx>
45 : #include <comphelper/stl_types.hxx>
46 : #include <com/sun/star/uno/XComponentContext.hpp>
47 : #include <memory>
48 :
49 : namespace rptxml
50 : {
51 : using namespace ::xmloff::token;
52 : using namespace ::com::sun::star::uno;
53 : using namespace ::com::sun::star::container;
54 : using namespace ::com::sun::star::lang;
55 : using namespace ::com::sun::star::beans;
56 : using namespace ::com::sun::star::document;
57 : using namespace ::com::sun::star::text;
58 : using namespace ::com::sun::star::report;
59 : using namespace ::com::sun::star::io;
60 : using namespace ::com::sun::star::xml::sax;
61 : // -------------
62 : // - ORptExport -
63 : // -------------
64 : #define PROGRESS_BAR_STEP 20
65 :
66 : class ORptExport : public SvXMLExport
67 : {
68 : public:
69 0 : struct TCell
70 : {
71 : sal_Int32 nWidth;
72 : sal_Int32 nHeight;
73 : sal_Int32 nColSpan;
74 : sal_Int32 nRowSpan;
75 : Reference<XReportComponent> xElement;
76 : bool bSet;
77 0 : TCell( sal_Int32 _nWidth,
78 : sal_Int32 _nHeight,
79 : sal_Int32 _nColSpan,
80 : sal_Int32 _nRowSpan,
81 : Reference<XReportComponent> _xElement = Reference<XReportComponent>()) :
82 : nWidth(_nWidth)
83 : ,nHeight(_nHeight)
84 : ,nColSpan(_nColSpan)
85 : ,nRowSpan(_nRowSpan)
86 : ,xElement(_xElement)
87 0 : ,bSet(xElement.is())
88 0 : {}
89 :
90 0 : TCell( ) :
91 : nWidth(0)
92 : ,nHeight(0)
93 : ,nColSpan(1)
94 : ,nRowSpan(1)
95 0 : ,bSet(true)
96 0 : {}
97 : };
98 : typedef ::std::pair< ::rtl::OUString ,::rtl::OUString> TStringPair;
99 : typedef struct
100 : {
101 : ::rtl::OUString sText;
102 : ::rtl::OUString sField;
103 : ::rtl::OUString sDecimal;
104 : ::rtl::OUString sThousand;
105 0 : } TDelimiter;
106 : typedef ::std::vector< ::rtl::OUString> TStringVec;
107 : typedef ::std::map< Reference<XPropertySet> ,::rtl::OUString > TPropertyStyleMap;
108 : typedef ::std::map< Reference<XPropertySet> , TStringVec> TGridStyleMap;
109 : typedef ::std::vector< TCell > TRow;
110 : typedef ::std::vector< ::std::pair< sal_Bool, TRow > > TGrid;
111 : typedef ::std::map< Reference<XPropertySet> ,TGrid > TSectionsGrid;
112 : typedef ::std::map< Reference<XGroup> ,Reference<XFunction> > TGroupFunctionMap;
113 : private:
114 : ::std::auto_ptr< TStringPair > m_aAutoIncrement;
115 : ::std::auto_ptr< TDelimiter > m_aDelimiter;
116 : ::std::vector< Any > m_aDataSourceSettings;
117 : TSectionsGrid m_aSectionsGrid;
118 :
119 : TPropertyStyleMap m_aAutoStyleNames;
120 : TGridStyleMap m_aColumnStyleNames;
121 : TGridStyleMap m_aRowStyleNames;
122 : TGroupFunctionMap m_aGroupFunctionMap;
123 :
124 : ::rtl::OUString m_sCharSet;
125 : ::rtl::OUString m_sTableStyle;
126 : ::rtl::OUString m_sCellStyle;
127 : ::rtl::OUString m_sColumnStyle;
128 : Any m_aPreviewMode;
129 : UniReference < SvXMLExportPropertyMapper> m_xExportHelper;
130 : UniReference < SvXMLExportPropertyMapper> m_xSectionPropMapper;
131 : UniReference < SvXMLExportPropertyMapper> m_xTableStylesExportPropertySetMapper;
132 : UniReference < SvXMLExportPropertyMapper> m_xCellStylesExportPropertySetMapper;
133 : UniReference < SvXMLExportPropertyMapper> m_xColumnStylesExportPropertySetMapper;
134 : UniReference < SvXMLExportPropertyMapper> m_xRowStylesExportPropertySetMapper;
135 : UniReference < SvXMLExportPropertyMapper > m_xParaPropMapper;
136 : UniReference < XMLPropertyHandlerFactory > m_xPropHdlFactory;
137 :
138 : mutable UniReference < XMLPropertySetMapper > m_xControlStylePropertyMapper;
139 : mutable UniReference < XMLPropertySetMapper > m_xColumnStylesPropertySetMapper;
140 : mutable UniReference < XMLPropertySetMapper > m_xCellStylesPropertySetMapper;
141 : Reference<XReportDefinition> m_xReportDefinition;
142 : sal_Bool m_bAllreadyFilled;
143 :
144 : void exportReport(const Reference<XReportDefinition>& _xReportDefinition); /// <element name="office:report">
145 : void exportReportAttributes(const Reference<XReportDefinition>& _xReport);
146 : void exportFunctions(const Reference<XIndexAccess>& _xFunctions); /// <ref name="rpt-function"/>
147 : void exportFunction(const Reference< XFunction>& _xFunction);
148 : void exportMasterDetailFields(const Reference<XReportComponent>& _xReportComponet);
149 : void exportComponent(const Reference<XReportComponent>& _xReportComponent);
150 : sal_Bool exportGroup(const Reference<XReportDefinition>& _xReportDefinition,sal_Int32 _nPos,sal_Bool _bExportAutoStyle = sal_False);
151 : void exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt,const ::rtl::OUString& _sName);
152 : void exportSection(const Reference<XSection>& _xProp,bool bHeader = false);
153 : void exportContainer(const Reference< XSection>& _xSection);
154 : void exportShapes(const Reference< XSection>& _xSection,bool _bAddParagraph = true);
155 : void exportTableColumns(const Reference< XSection>& _xSection);
156 : void exportSectionAutoStyle(const Reference<XSection>& _xProp);
157 : void exportReportElement(const Reference<XReportControlModel>& _xReportElement);
158 : void exportFormatConditions(const Reference<XReportControlModel>& _xReportElement);
159 : void exportAutoStyle(XPropertySet* _xProp,const Reference<XFormattedField>& _xParentFormattedField = Reference<XFormattedField>());
160 : void exportAutoStyle(const Reference<XSection>& _xProp);
161 : void exportReportComponentAutoStyles(const Reference<XSection>& _xProp);
162 : void collectComponentStyles();
163 : void collectStyleNames(sal_Int32 _nFamily,const ::std::vector< sal_Int32>& _aSize, ORptExport::TStringVec& _rStyleNames);
164 : void exportParagraph(const Reference< XReportControlModel >& _xReportElement);
165 : bool exportFormula(enum ::xmloff::token::XMLTokenEnum eName,const ::rtl::OUString& _sFormula);
166 : void exportGroupsExpressionAsFunction(const Reference< XGroups>& _xGroups);
167 : ::rtl::OUString convertFormula(const ::rtl::OUString& _sFormula);
168 :
169 : ::rtl::OUString implConvertNumber(sal_Int32 _nValue);
170 :
171 : private:
172 : ORptExport();
173 : virtual void SetBodyAttributes();
174 : protected:
175 :
176 : virtual void _ExportStyles( sal_Bool bUsed );
177 : virtual void _ExportAutoStyles();
178 : virtual void _ExportContent();
179 : virtual void _ExportMasterStyles();
180 : virtual void _ExportFontDecls();
181 : virtual sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum eClass );
182 : virtual SvXMLAutoStylePoolP* CreateAutoStylePool();
183 : virtual XMLShapeExport* CreateShapeExport();
184 :
185 0 : virtual ~ORptExport(){};
186 : public:
187 :
188 : ORptExport(const Reference< XMultiServiceFactory >& _rxMSF, sal_uInt16 nExportFlag = (EXPORT_CONTENT | EXPORT_AUTOSTYLES | EXPORT_FONTDECLS));
189 : // XServiceInfo
190 : virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
191 : virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
192 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
193 :
194 : static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
195 : static ::rtl::OUString getImplementationName_Static(void) throw( ::com::sun::star::uno::RuntimeException );
196 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
197 : create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
198 :
199 : // XExporter
200 : 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);
201 :
202 0 : inline Reference<XReportDefinition> getReportDefinition() const { return m_xReportDefinition; }
203 :
204 : UniReference < XMLPropertySetMapper > GetCellStylePropertyMapper() const;
205 : };
206 :
207 : /** Exports only settings
208 : * \ingroup reportdesign_source_filter_xml
209 : *
210 : */
211 : class ORptExportHelper
212 : {
213 : public:
214 : static ::rtl::OUString getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException);
215 : static Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException);
216 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
217 : create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
218 : };
219 :
220 : /** Exports only content
221 : * \ingroup reportdesign_source_filter_xml
222 : *
223 : */
224 : class ORptContentExportHelper
225 : {
226 : public:
227 : static ::rtl::OUString getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException);
228 : static Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException);
229 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
230 : create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
231 : };
232 :
233 : /** Exports only styles
234 : * \ingroup reportdesign_source_filter_xml
235 : *
236 : */
237 : class ORptStylesExportHelper
238 : {
239 : public:
240 : static ::rtl::OUString getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException);
241 : static Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException);
242 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
243 : create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
244 : };
245 :
246 : /** Exports only meta data
247 : * \ingroup reportdesign_source_filter_xml
248 : *
249 : */
250 : class ORptMetaExportHelper
251 : {
252 : public:
253 : static ::rtl::OUString getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException);
254 : static Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException);
255 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
256 : create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
257 : };
258 : /** Exports all
259 : * \ingroup reportdesign_source_filter_xml
260 : *
261 : */
262 : class ODBFullExportHelper
263 : {
264 : public:
265 : static ::rtl::OUString getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException);
266 : static Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException);
267 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
268 : create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
269 : };
270 : // -----------------------------------------------------------------------------
271 : } // rptxml
272 : // -----------------------------------------------------------------------------
273 : #endif // RPT_XMLEXPORT_HXX
274 :
275 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|