1*9ee13d13SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9ee13d13SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9ee13d13SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9ee13d13SAndrew Rist  * distributed with this work for additional information
6*9ee13d13SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9ee13d13SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9ee13d13SAndrew Rist  * "License"); you may not use this file except in compliance
9*9ee13d13SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9ee13d13SAndrew Rist  *
11*9ee13d13SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9ee13d13SAndrew Rist  *
13*9ee13d13SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9ee13d13SAndrew Rist  * software distributed under the License is distributed on an
15*9ee13d13SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9ee13d13SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9ee13d13SAndrew Rist  * specific language governing permissions and limitations
18*9ee13d13SAndrew Rist  * under the License.
19*9ee13d13SAndrew Rist  *
20*9ee13d13SAndrew Rist  *************************************************************/
21*9ee13d13SAndrew Rist 
22*9ee13d13SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef RPT_XMLEXPORT_HXX
25cdf0e10cSrcweir #define RPT_XMLEXPORT_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
28cdf0e10cSrcweir #include <com/sun/star/document/XFilter.hpp>
29cdf0e10cSrcweir #include <com/sun/star/document/XImporter.hpp>
30cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
32cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
33cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
34cdf0e10cSrcweir #include <com/sun/star/report/XReportDefinition.hpp>
35cdf0e10cSrcweir #include <com/sun/star/report/XSection.hpp>
36cdf0e10cSrcweir #include <com/sun/star/report/XReportControlModel.hpp>
37cdf0e10cSrcweir #include <com/sun/star/report/XFormattedField.hpp>
38cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
39cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
40cdf0e10cSrcweir #include <cppuhelper/implbase5.hxx>
41cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
43cdf0e10cSrcweir #include <osl/diagnose.h>
44cdf0e10cSrcweir #include <unotools/tempfile.hxx>
45cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
46cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
47cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
48cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
49cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
50cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
51cdf0e10cSrcweir #include <memory>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir namespace rptxml
54cdf0e10cSrcweir {
55cdf0e10cSrcweir using namespace ::xmloff::token;
56cdf0e10cSrcweir using namespace ::com::sun::star::uno;
57cdf0e10cSrcweir using namespace ::com::sun::star::container;
58cdf0e10cSrcweir using namespace ::com::sun::star::lang;
59cdf0e10cSrcweir using namespace ::com::sun::star::beans;
60cdf0e10cSrcweir using namespace ::com::sun::star::document;
61cdf0e10cSrcweir using namespace ::com::sun::star::text;
62cdf0e10cSrcweir using namespace ::com::sun::star::report;
63cdf0e10cSrcweir using namespace ::com::sun::star::io;
64cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
65cdf0e10cSrcweir // -------------
66cdf0e10cSrcweir // - ORptExport -
67cdf0e10cSrcweir // -------------
68cdf0e10cSrcweir #define PROGRESS_BAR_STEP 20
69cdf0e10cSrcweir 
70cdf0e10cSrcweir class ORptExport : public SvXMLExport
71cdf0e10cSrcweir {
72cdf0e10cSrcweir public:
73cdf0e10cSrcweir     struct TCell
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         sal_Int32 nWidth;
76cdf0e10cSrcweir         sal_Int32 nHeight;
77cdf0e10cSrcweir         sal_Int32 nColSpan;
78cdf0e10cSrcweir         sal_Int32 nRowSpan;
79cdf0e10cSrcweir         Reference<XReportComponent> xElement;
80cdf0e10cSrcweir         bool      bSet;
TCellrptxml::ORptExport::TCell81cdf0e10cSrcweir         TCell(  sal_Int32 _nWidth,
82cdf0e10cSrcweir                 sal_Int32 _nHeight,
83cdf0e10cSrcweir                 sal_Int32 _nColSpan,
84cdf0e10cSrcweir                 sal_Int32 _nRowSpan,
85cdf0e10cSrcweir                 Reference<XReportComponent> _xElement = Reference<XReportComponent>()) :
86cdf0e10cSrcweir         nWidth(_nWidth)
87cdf0e10cSrcweir         ,nHeight(_nHeight)
88cdf0e10cSrcweir         ,nColSpan(_nColSpan)
89cdf0e10cSrcweir         ,nRowSpan(_nRowSpan)
90cdf0e10cSrcweir         ,xElement(_xElement)
91cdf0e10cSrcweir         ,bSet(xElement.is())
92cdf0e10cSrcweir         {}
93cdf0e10cSrcweir 
TCellrptxml::ORptExport::TCell94cdf0e10cSrcweir         TCell( ) :
95cdf0e10cSrcweir         nWidth(0)
96cdf0e10cSrcweir         ,nHeight(0)
97cdf0e10cSrcweir         ,nColSpan(1)
98cdf0e10cSrcweir         ,nRowSpan(1)
99cdf0e10cSrcweir         ,bSet(true)
100cdf0e10cSrcweir         {}
101cdf0e10cSrcweir     };
102cdf0e10cSrcweir 	typedef ::std::pair< ::rtl::OUString ,::rtl::OUString> TStringPair;
103cdf0e10cSrcweir 	typedef struct
104cdf0e10cSrcweir 	{
105cdf0e10cSrcweir 		::rtl::OUString sText;
106cdf0e10cSrcweir 		::rtl::OUString sField;
107cdf0e10cSrcweir 		::rtl::OUString sDecimal;
108cdf0e10cSrcweir 		::rtl::OUString sThousand;
109cdf0e10cSrcweir 	} TDelimiter;
110cdf0e10cSrcweir     typedef ::std::vector< ::rtl::OUString>                         TStringVec;
111cdf0e10cSrcweir 	typedef ::std::map< Reference<XPropertySet> ,::rtl::OUString >  TPropertyStyleMap;
112cdf0e10cSrcweir     typedef ::std::map< Reference<XPropertySet> ,  TStringVec>      TGridStyleMap;
113cdf0e10cSrcweir     typedef ::std::vector< TCell >                                  TRow;
114cdf0e10cSrcweir     typedef ::std::vector< ::std::pair< sal_Bool, TRow > >          TGrid;
115cdf0e10cSrcweir     typedef ::std::map< Reference<XPropertySet> ,TGrid >            TSectionsGrid;
116cdf0e10cSrcweir     typedef ::std::map< Reference<XGroup> ,Reference<XFunction> >   TGroupFunctionMap;
117cdf0e10cSrcweir private:
118cdf0e10cSrcweir 	::std::auto_ptr< TStringPair >					m_aAutoIncrement;
119cdf0e10cSrcweir 	::std::auto_ptr< TDelimiter >					m_aDelimiter;
120cdf0e10cSrcweir 	::std::vector< Any >							m_aDataSourceSettings;
121cdf0e10cSrcweir     TSectionsGrid                                   m_aSectionsGrid;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	TPropertyStyleMap								m_aAutoStyleNames;
124cdf0e10cSrcweir     TGridStyleMap                                   m_aColumnStyleNames;
125cdf0e10cSrcweir     TGridStyleMap                                   m_aRowStyleNames;
126cdf0e10cSrcweir     TGroupFunctionMap                               m_aGroupFunctionMap;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	::rtl::OUString									m_sCharSet;
129cdf0e10cSrcweir     ::rtl::OUString                                 m_sTableStyle;
130cdf0e10cSrcweir     ::rtl::OUString                                 m_sCellStyle;
131cdf0e10cSrcweir     ::rtl::OUString                                 m_sColumnStyle;
132cdf0e10cSrcweir 	Any												m_aPreviewMode;
133cdf0e10cSrcweir 	UniReference < SvXMLExportPropertyMapper>		m_xExportHelper;
134cdf0e10cSrcweir 	UniReference < SvXMLExportPropertyMapper>		m_xSectionPropMapper;
135cdf0e10cSrcweir     UniReference < SvXMLExportPropertyMapper>		m_xTableStylesExportPropertySetMapper;
136cdf0e10cSrcweir     UniReference < SvXMLExportPropertyMapper>		m_xCellStylesExportPropertySetMapper;
137cdf0e10cSrcweir     UniReference < SvXMLExportPropertyMapper>		m_xColumnStylesExportPropertySetMapper;
138cdf0e10cSrcweir     UniReference < SvXMLExportPropertyMapper>		m_xRowStylesExportPropertySetMapper;
139cdf0e10cSrcweir     UniReference < SvXMLExportPropertyMapper >      m_xParaPropMapper;
140cdf0e10cSrcweir     UniReference < XMLPropertyHandlerFactory >	    m_xPropHdlFactory;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	mutable UniReference < XMLPropertySetMapper >	m_xControlStylePropertyMapper;
143cdf0e10cSrcweir 	mutable UniReference < XMLPropertySetMapper >	m_xColumnStylesPropertySetMapper;
144cdf0e10cSrcweir     mutable UniReference < XMLPropertySetMapper >   m_xCellStylesPropertySetMapper;
145cdf0e10cSrcweir 	Reference<XReportDefinition>					m_xReportDefinition;
146cdf0e10cSrcweir 	sal_Bool										m_bAllreadyFilled;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	void					exportReport(const Reference<XReportDefinition>& _xReportDefinition); /// <element name="office:report">
149cdf0e10cSrcweir     void                    exportReportAttributes(const Reference<XReportDefinition>& _xReport);
150cdf0e10cSrcweir     void					exportFunctions(const Reference<XIndexAccess>& _xFunctions); /// <ref name="rpt-function"/>
151cdf0e10cSrcweir     void                    exportFunction(const Reference< XFunction>& _xFunction);
152cdf0e10cSrcweir     void					exportMasterDetailFields(const Reference<XReportComponent>& _xReportComponet);
153cdf0e10cSrcweir 	void					exportComponent(const Reference<XReportComponent>& _xReportComponent);
154cdf0e10cSrcweir 	sal_Bool				exportGroup(const Reference<XReportDefinition>& _xReportDefinition,sal_Int32 _nPos,sal_Bool _bExportAutoStyle = sal_False);
155cdf0e10cSrcweir 	void					exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt,const ::rtl::OUString& _sName);
156cdf0e10cSrcweir 	void					exportSection(const Reference<XSection>& _xProp,bool bHeader = false);
157cdf0e10cSrcweir     void                    exportContainer(const Reference< XSection>& _xSection);
158cdf0e10cSrcweir     void                    exportShapes(const Reference< XSection>& _xSection,bool _bAddParagraph = true);
159cdf0e10cSrcweir     void                    exportTableColumns(const Reference< XSection>& _xSection);
160cdf0e10cSrcweir 	void					exportSectionAutoStyle(const Reference<XSection>& _xProp);
161cdf0e10cSrcweir 	void					exportReportElement(const Reference<XReportControlModel>& _xReportElement);
162cdf0e10cSrcweir 	void					exportFormatConditions(const Reference<XReportControlModel>& _xReportElement);
163cdf0e10cSrcweir 	void					exportAutoStyle(XPropertySet* _xProp,const Reference<XFormattedField>& _xParentFormattedField = Reference<XFormattedField>());
164cdf0e10cSrcweir 	void					exportAutoStyle(const Reference<XSection>& _xProp);
165cdf0e10cSrcweir     void                    exportReportComponentAutoStyles(const Reference<XSection>& _xProp);
166cdf0e10cSrcweir 	void					collectComponentStyles();
167cdf0e10cSrcweir     void                    collectStyleNames(sal_Int32 _nFamily,const ::std::vector< sal_Int32>& _aSize, ORptExport::TStringVec& _rStyleNames);
168cdf0e10cSrcweir     void                    exportParagraph(const Reference< XReportControlModel >& _xReportElement);
169cdf0e10cSrcweir     bool                    exportFormula(enum ::xmloff::token::XMLTokenEnum eName,const ::rtl::OUString& _sFormula);
170cdf0e10cSrcweir     void                    exportGroupsExpressionAsFunction(const Reference< XGroups>& _xGroups);
171cdf0e10cSrcweir     ::rtl::OUString         convertFormula(const ::rtl::OUString& _sFormula);
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	::rtl::OUString			implConvertNumber(sal_Int32 _nValue);
174cdf0e10cSrcweir 
175cdf0e10cSrcweir private:
176cdf0e10cSrcweir 									ORptExport();
177cdf0e10cSrcweir 	virtual void					SetBodyAttributes();
178cdf0e10cSrcweir protected:
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	virtual void					_ExportStyles( sal_Bool bUsed );
181cdf0e10cSrcweir 	virtual void					_ExportAutoStyles();
182cdf0e10cSrcweir 	virtual void					_ExportContent();
183cdf0e10cSrcweir 	virtual void					_ExportMasterStyles();
184cdf0e10cSrcweir 	virtual void					_ExportFontDecls();
185cdf0e10cSrcweir 	virtual sal_uInt32				exportDoc( enum ::xmloff::token::XMLTokenEnum eClass );
186cdf0e10cSrcweir 	virtual SvXMLAutoStylePoolP*	CreateAutoStylePool();
187cdf0e10cSrcweir     virtual XMLShapeExport*         CreateShapeExport();
188cdf0e10cSrcweir 
~ORptExport()189cdf0e10cSrcweir 	virtual					~ORptExport(){};
190cdf0e10cSrcweir public:
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	ORptExport(const Reference< XMultiServiceFactory >& _rxMSF, sal_uInt16 nExportFlag = (EXPORT_CONTENT | EXPORT_AUTOSTYLES | EXPORT_FONTDECLS));
193cdf0e10cSrcweir 	// XServiceInfo
194cdf0e10cSrcweir 	virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
195cdf0e10cSrcweir 	virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
196cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
199cdf0e10cSrcweir 	static ::rtl::OUString getImplementationName_Static(void) throw( ::com::sun::star::uno::RuntimeException );
200cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
201cdf0e10cSrcweir 		create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 	// XExporter
204cdf0e10cSrcweir 	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);
205cdf0e10cSrcweir 
getReportDefinition() const206cdf0e10cSrcweir 	inline Reference<XReportDefinition> getReportDefinition() const { return m_xReportDefinition; }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     UniReference < XMLPropertySetMapper > GetCellStylePropertyMapper() const;
209cdf0e10cSrcweir };
210cdf0e10cSrcweir 
211cdf0e10cSrcweir /** Exports only settings
212cdf0e10cSrcweir  * \ingroup reportdesign_source_filter_xml
213cdf0e10cSrcweir  *
214cdf0e10cSrcweir  */
215cdf0e10cSrcweir class ORptExportHelper
216cdf0e10cSrcweir {
217cdf0e10cSrcweir public:
218cdf0e10cSrcweir 	static ::rtl::OUString getImplementationName_Static(  ) throw (::com::sun::star::uno::RuntimeException);
219cdf0e10cSrcweir 	static Sequence< ::rtl::OUString > getSupportedServiceNames_Static(  ) throw(::com::sun::star::uno::RuntimeException);
220cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
221cdf0e10cSrcweir 		create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
222cdf0e10cSrcweir };
223cdf0e10cSrcweir 
224cdf0e10cSrcweir /** Exports only content
225cdf0e10cSrcweir  * \ingroup reportdesign_source_filter_xml
226cdf0e10cSrcweir  *
227cdf0e10cSrcweir  */
228cdf0e10cSrcweir class ORptContentExportHelper
229cdf0e10cSrcweir {
230cdf0e10cSrcweir public:
231cdf0e10cSrcweir 	static ::rtl::OUString getImplementationName_Static(  ) throw (::com::sun::star::uno::RuntimeException);
232cdf0e10cSrcweir 	static Sequence< ::rtl::OUString > getSupportedServiceNames_Static(  ) throw(::com::sun::star::uno::RuntimeException);
233cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
234cdf0e10cSrcweir 		create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
235cdf0e10cSrcweir };
236cdf0e10cSrcweir 
237cdf0e10cSrcweir /** Exports only styles
238cdf0e10cSrcweir  * \ingroup reportdesign_source_filter_xml
239cdf0e10cSrcweir  *
240cdf0e10cSrcweir  */
241cdf0e10cSrcweir class ORptStylesExportHelper
242cdf0e10cSrcweir {
243cdf0e10cSrcweir public:
244cdf0e10cSrcweir 	static ::rtl::OUString getImplementationName_Static(  ) throw (::com::sun::star::uno::RuntimeException);
245cdf0e10cSrcweir 	static Sequence< ::rtl::OUString > getSupportedServiceNames_Static(  ) throw(::com::sun::star::uno::RuntimeException);
246cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
247cdf0e10cSrcweir 		create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
248cdf0e10cSrcweir };
249cdf0e10cSrcweir 
250cdf0e10cSrcweir /** Exports only meta data
251cdf0e10cSrcweir  * \ingroup reportdesign_source_filter_xml
252cdf0e10cSrcweir  *
253cdf0e10cSrcweir  */
254cdf0e10cSrcweir class ORptMetaExportHelper
255cdf0e10cSrcweir {
256cdf0e10cSrcweir public:
257cdf0e10cSrcweir 	static ::rtl::OUString getImplementationName_Static(  ) throw (::com::sun::star::uno::RuntimeException);
258cdf0e10cSrcweir 	static Sequence< ::rtl::OUString > getSupportedServiceNames_Static(  ) throw(::com::sun::star::uno::RuntimeException);
259cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
260cdf0e10cSrcweir 		create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
261cdf0e10cSrcweir };
262cdf0e10cSrcweir /** Exports all
263cdf0e10cSrcweir  * \ingroup reportdesign_source_filter_xml
264cdf0e10cSrcweir  *
265cdf0e10cSrcweir  */
266cdf0e10cSrcweir class ODBFullExportHelper
267cdf0e10cSrcweir {
268cdf0e10cSrcweir public:
269cdf0e10cSrcweir 	static ::rtl::OUString getImplementationName_Static(  ) throw (::com::sun::star::uno::RuntimeException);
270cdf0e10cSrcweir 	static Sequence< ::rtl::OUString > getSupportedServiceNames_Static(  ) throw(::com::sun::star::uno::RuntimeException);
271cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
272cdf0e10cSrcweir 		create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext);
273cdf0e10cSrcweir };
274cdf0e10cSrcweir // -----------------------------------------------------------------------------
275cdf0e10cSrcweir } // rptxml
276cdf0e10cSrcweir // -----------------------------------------------------------------------------
277cdf0e10cSrcweir #endif // RPT_XMLEXPORT_HXX
278