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