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 #include <sal/config.h>
21 #include <sal/log.hxx>
22 
23 #include <com/sun/star/packages/WrongPasswordException.hpp>
24 #include <com/sun/star/packages/zip/ZipIOException.hpp>
25 #include <com/sun/star/embed/ElementModes.hpp>
26 #include <com/sun/star/beans/NamedValue.hpp>
27 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
28 #include <com/sun/star/util/MeasureUnit.hpp>
29 #include <com/sun/star/xml/sax/Parser.hpp>
30 #include <com/sun/star/xml/sax/SAXParseException.hpp>
31 #include <com/sun/star/document/GraphicStorageHandler.hpp>
32 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
33 #include "xmlfilter.hxx"
34 #include "xmlGroup.hxx"
35 #include "xmlReport.hxx"
36 #include <vcl/errinf.hxx>
37 #include "xmlHelper.hxx"
38 #include <vcl/svapp.hxx>
39 #include <vcl/window.hxx>
40 #include <connectivity/dbtools.hxx>
41 #include <xmloff/xmlnmspe.hxx>
42 #include <xmloff/xmltoken.hxx>
43 #include <xmloff/txtimp.hxx>
44 #include <xmloff/nmspmap.hxx>
45 #include <xmloff/XMLFontStylesContext.hxx>
46 #include <com/sun/star/xml/sax/InputSource.hpp>
47 #include <com/sun/star/xml/sax/XParser.hpp>
48 #include <com/sun/star/beans/PropertyAttribute.hpp>
49 
50 #include <comphelper/genericpropertyset.hxx>
51 #include <comphelper/propertysetinfo.hxx>
52 #include <unotools/mediadescriptor.hxx>
53 #include <xmloff/ProgressBarHelper.hxx>
54 #include <sfx2/docfile.hxx>
55 #include <com/sun/star/io/XInputStream.hpp>
56 #include <com/sun/star/uno/XNamingService.hpp>
57 #include <xmloff/DocumentSettingsContext.hxx>
58 #include <xmloff/xmluconv.hxx>
59 #include <xmloff/xmlmetai.hxx>
60 #include <tools/diagnose_ex.h>
61 #include <com/sun/star/util/XModifiable.hpp>
62 #include <svtools/sfxecode.hxx>
63 #include "xmlEnums.hxx"
64 #include "xmlStyleImport.hxx"
65 #include <strings.hxx>
66 #include "xmlPropertyHandler.hxx"
67 #include <xmloff/txtprmap.hxx>
68 #include <ReportDefinition.hxx>
69 
70 namespace rptxml
71 {
72 using namespace ::com::sun::star::uno;
73 using ::com::sun::star::uno::Reference;
74 using namespace ::com::sun::star;
75 using namespace ::com::sun::star::container;
76 using namespace ::com::sun::star::lang;
77 using namespace ::com::sun::star::beans;
78 using namespace ::com::sun::star::document;
79 using namespace ::com::sun::star::text;
80 using namespace ::com::sun::star::io;
81 using namespace ::com::sun::star::report;
82 using namespace ::com::sun::star::xml::sax;
83 using namespace xmloff;
84 using namespace ::com::sun::star::util;
85 
86 class RptMLMasterStylesContext_Impl:
87     public XMLTextMasterStylesContext
88 {
GetImport()89     ORptFilter& GetImport() { return static_cast<ORptFilter&>(XMLTextMasterStylesContext::GetImport()); }
90 
91 public:
92 
93 
94     RptMLMasterStylesContext_Impl(
95             ORptFilter& rImport, sal_uInt16 nPrfx,
96             const OUString& rLName ,
97             const uno::Reference< xml::sax::XAttributeList > & xAttrList );
98 
99     RptMLMasterStylesContext_Impl(const RptMLMasterStylesContext_Impl&) = delete;
100     RptMLMasterStylesContext_Impl& operator=(const RptMLMasterStylesContext_Impl&) = delete;
101     virtual void EndElement() override;
102 };
103 
RptMLMasterStylesContext_Impl(ORptFilter & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)104 RptMLMasterStylesContext_Impl::RptMLMasterStylesContext_Impl(
105         ORptFilter& rImport, sal_uInt16 nPrfx,
106         const OUString& rLName ,
107         const uno::Reference< xml::sax::XAttributeList > & xAttrList ) :
108     XMLTextMasterStylesContext( rImport, nPrfx, rLName, xAttrList )
109 {
110 }
111 
EndElement()112 void RptMLMasterStylesContext_Impl::EndElement()
113 {
114     FinishStyles( true );
115     GetImport().FinishStyles();
116 }
117 
118     /// read a component (file + filter version)
ReadThroughComponent(const uno::Reference<XInputStream> & xInputStream,const uno::Reference<XComponent> & xModelComponent,const uno::Reference<XComponentContext> & rContext,const uno::Reference<XDocumentHandler> & _xFilter)119 static ErrCode ReadThroughComponent(
120     const uno::Reference<XInputStream>& xInputStream,
121     const uno::Reference<XComponent>& xModelComponent,
122     const uno::Reference<XComponentContext> & rContext,
123     const uno::Reference< XDocumentHandler >& _xFilter )
124 {
125     OSL_ENSURE(xInputStream.is(), "input stream missing");
126     OSL_ENSURE(xModelComponent.is(), "document missing");
127     OSL_ENSURE(rContext.is(), "factory missing");
128 
129     // prepare ParserInputSrouce
130     InputSource aParserInput;
131     aParserInput.aInputStream = xInputStream;
132 
133     // get parser
134     uno::Reference< XParser > xParser = xml::sax::Parser::create(rContext);
135     SAL_INFO( "reportdesign", "parser created" );
136     // get filter
137     OSL_ENSURE( _xFilter.is(), "Can't instantiate filter component." );
138     if( !_xFilter.is() )
139         return ErrCode(1);
140 
141     // connect parser and filter
142     xParser->setDocumentHandler( _xFilter );
143 
144     // connect model and filter
145     uno::Reference < XImporter > xImporter( _xFilter, UNO_QUERY );
146     xImporter->setTargetDocument( xModelComponent );
147 
148     // finally, parser the stream
149     try
150     {
151         xParser->parseStream( aParserInput );
152     }
153     catch (const SAXParseException&)
154     {
155         TOOLS_WARN_EXCEPTION( "reportdesign", "SAX parse exception caught while importing");
156         return ErrCode(1);
157     }
158     catch (const SAXException&)
159     {
160         return ErrCode(1);
161     }
162     catch (const packages::zip::ZipIOException&)
163     {
164         return ERRCODE_IO_BROKENPACKAGE;
165     }
166     catch (const IOException&)
167     {
168         return ErrCode(1);
169     }
170     catch (const Exception&)
171     {
172         return ErrCode(1);
173     }
174 
175     // success!
176     return ERRCODE_NONE;
177 }
178 
179 /// read a component (storage version)
ReadThroughComponent(const uno::Reference<embed::XStorage> & xStorage,const uno::Reference<XComponent> & xModelComponent,const sal_Char * pStreamName,const sal_Char * pCompatibilityStreamName,const uno::Reference<XComponentContext> & rxContext,const Reference<document::XGraphicStorageHandler> & rxGraphicStorageHandler,const Reference<document::XEmbeddedObjectResolver> & _xEmbeddedObjectResolver,const OUString & _sFilterName,const uno::Reference<beans::XPropertySet> & _xProp)180 static ErrCode ReadThroughComponent(
181     const uno::Reference< embed::XStorage >& xStorage,
182     const uno::Reference<XComponent>& xModelComponent,
183     const sal_Char* pStreamName,
184     const sal_Char* pCompatibilityStreamName,
185     const uno::Reference<XComponentContext> & rxContext,
186     const Reference<document::XGraphicStorageHandler> & rxGraphicStorageHandler,
187     const Reference<document::XEmbeddedObjectResolver>& _xEmbeddedObjectResolver,
188     const OUString& _sFilterName
189     ,const uno::Reference<beans::XPropertySet>& _xProp)
190 {
191     OSL_ENSURE( xStorage.is(), "Need storage!");
192     OSL_ENSURE(nullptr != pStreamName, "Please, please, give me a name!");
193 
194     if ( xStorage.is() )
195     {
196         uno::Reference< io::XStream > xDocStream;
197 
198         try
199         {
200             // open stream (and set parser input)
201             OUString sStreamName = OUString::createFromAscii(pStreamName);
202             if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) )
203             {
204                 // stream name not found! Then try the compatibility name.
205                 // if no stream can be opened, return immediately with OK signal
206 
207                 // do we even have an alternative name?
208                 if ( nullptr == pCompatibilityStreamName )
209                     return ERRCODE_NONE;
210 
211                 // if so, does the stream exist?
212                 sStreamName = OUString::createFromAscii(pCompatibilityStreamName);
213                 if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) )
214                     return ERRCODE_NONE;
215             }
216 
217             // get input stream
218             xDocStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
219         }
220         catch (const packages::WrongPasswordException&)
221         {
222             return ERRCODE_SFX_WRONGPASSWORD;
223         }
224         catch (const uno::Exception&)
225         {
226             return ErrCode(1); // TODO/LATER: error handling
227         }
228 
229         sal_Int32 nArgs = 0;
230         if (rxGraphicStorageHandler.is())
231             nArgs++;
232         if( _xEmbeddedObjectResolver.is())
233             nArgs++;
234         if ( _xProp.is() )
235             nArgs++;
236 
237         uno::Sequence< uno::Any > aFilterCompArgs( nArgs );
238 
239         nArgs = 0;
240         if (rxGraphicStorageHandler.is())
241             aFilterCompArgs[nArgs++] <<= rxGraphicStorageHandler;
242         if( _xEmbeddedObjectResolver.is())
243             aFilterCompArgs[ nArgs++ ] <<= _xEmbeddedObjectResolver;
244         if ( _xProp.is() )
245             aFilterCompArgs[ nArgs++ ] <<= _xProp;
246 
247         Reference< xml::sax::XDocumentHandler > xDocHandler(
248             rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(_sFilterName, aFilterCompArgs, rxContext),
249             uno::UNO_QUERY_THROW );
250         uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream();
251         // read from the stream
252         return ReadThroughComponent( xInputStream
253                                     ,xModelComponent
254                                     ,rxContext
255                                     ,xDocHandler );
256     }
257 
258     // TODO/LATER: better error handling
259     return ErrCode(1);
260 }
261 
262 
create(uno::Reference<uno::XComponentContext> const & xContext)263 uno::Reference< uno::XInterface > ORptImportHelper::create(uno::Reference< uno::XComponentContext > const & xContext)
264 {
265     return static_cast< XServiceInfo* >(new ORptFilter(xContext, SvXMLImportFlags::SETTINGS ));
266 }
267 
getImplementationName_Static()268 OUString ORptImportHelper::getImplementationName_Static(  )
269 {
270     return SERVICE_SETTINGSIMPORTER;
271 }
272 
getSupportedServiceNames_Static()273 Sequence< OUString > ORptImportHelper::getSupportedServiceNames_Static(  )
274 {
275     Sequence< OUString > aSupported { SERVICE_IMPORTFILTER };
276     return aSupported;
277 }
278 
create(const Reference<XComponentContext> & xContext)279 Reference< XInterface > ORptContentImportHelper::create(const Reference< XComponentContext > & xContext)
280 {
281     return static_cast< XServiceInfo* >(new ORptFilter(xContext, SvXMLImportFlags::AUTOSTYLES | SvXMLImportFlags::CONTENT | SvXMLImportFlags::SCRIPTS |
282         SvXMLImportFlags::FONTDECLS ));
283 }
284 
getImplementationName_Static()285 OUString ORptContentImportHelper::getImplementationName_Static(  )
286 {
287     return SERVICE_CONTENTIMPORTER;
288 }
289 
getSupportedServiceNames_Static()290 Sequence< OUString > ORptContentImportHelper::getSupportedServiceNames_Static(  )
291 {
292     Sequence< OUString > aSupported { SERVICE_IMPORTFILTER };
293     return aSupported;
294 }
295 
296 
create(Reference<XComponentContext> const & xContext)297 Reference< XInterface > ORptStylesImportHelper::create(Reference< XComponentContext > const & xContext)
298 {
299     return static_cast< XServiceInfo* >(new ORptFilter(xContext,
300         SvXMLImportFlags::STYLES | SvXMLImportFlags::MASTERSTYLES | SvXMLImportFlags::AUTOSTYLES |
301         SvXMLImportFlags::FONTDECLS ));
302 }
303 
getImplementationName_Static()304 OUString ORptStylesImportHelper::getImplementationName_Static(  )
305 {
306     return SERVICE_STYLESIMPORTER;
307 }
308 
getSupportedServiceNames_Static()309 Sequence< OUString > ORptStylesImportHelper::getSupportedServiceNames_Static(  )
310 {
311     Sequence< OUString > aSupported { SERVICE_IMPORTFILTER };
312     return aSupported;
313 }
314 
315 
create(Reference<XComponentContext> const & xContext)316 Reference< XInterface > ORptMetaImportHelper::create(Reference< XComponentContext > const & xContext)
317 {
318     return static_cast< XServiceInfo* >(new ORptFilter(xContext,
319         SvXMLImportFlags::META));
320 }
321 
getImplementationName_Static()322 OUString ORptMetaImportHelper::getImplementationName_Static(  )
323 {
324     return SERVICE_METAIMPORTER;
325 }
326 
getSupportedServiceNames_Static()327 Sequence< OUString > ORptMetaImportHelper::getSupportedServiceNames_Static(  )
328 {
329     Sequence< OUString > aSupported { SERVICE_IMPORTFILTER };
330     return aSupported;
331 }
332 
333 
ORptFilter(const uno::Reference<XComponentContext> & _rxContext,SvXMLImportFlags nImportFlags)334 ORptFilter::ORptFilter( const uno::Reference< XComponentContext >& _rxContext, SvXMLImportFlags nImportFlags )
335     :SvXMLImport(_rxContext, getImplementationName_Static(), nImportFlags)
336 {
337     GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_100TH);
338     GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM);
339     GetNamespaceMap().Add( "_report",
340                         GetXMLToken(XML_N_RPT),
341                         XML_NAMESPACE_REPORT );
342 
343     GetNamespaceMap().Add( "__report",
344                         GetXMLToken(XML_N_RPT_OASIS),
345                         XML_NAMESPACE_REPORT );
346 
347     m_xPropHdlFactory = new OXMLRptPropHdlFactory;
348     m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylePropertyMap(true, false);
349     m_xColumnStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetColumnStyleProps(), m_xPropHdlFactory, false);
350     m_xRowStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetRowStyleProps(), m_xPropHdlFactory, false);
351 }
352 
353 
~ORptFilter()354 ORptFilter::~ORptFilter() throw()
355 {
356 }
357 
create(uno::Reference<XComponentContext> const & xContext)358 uno::Reference< XInterface > ORptFilter::create(uno::Reference< XComponentContext > const & xContext)
359 {
360     return *(new ORptFilter(xContext));
361 }
362 
363 
getImplementationName_Static()364 OUString ORptFilter::getImplementationName_Static(  )
365 {
366     return "com.sun.star.comp.report.OReportFilter";
367 }
368 
getSupportedServiceNames_Static()369 uno::Sequence< OUString > ORptFilter::getSupportedServiceNames_Static(  )
370 {
371     uno::Sequence< OUString > aServices { SERVICE_IMPORTFILTER };
372 
373     return aServices;
374 }
375 
filter(const Sequence<PropertyValue> & rDescriptor)376 sal_Bool SAL_CALL ORptFilter::filter( const Sequence< PropertyValue >& rDescriptor )
377 {
378     vcl::Window*     pFocusWindow = Application::GetFocusWindow();
379     bool    bRet = false;
380 
381     if( pFocusWindow )
382         pFocusWindow->EnterWait();
383 
384     if ( GetModel().is() )
385         bRet = implImport( rDescriptor );
386 
387     if ( pFocusWindow )
388         pFocusWindow->LeaveWait();
389 
390     return bRet;
391 }
392 
implImport(const Sequence<PropertyValue> & rDescriptor)393 bool ORptFilter::implImport( const Sequence< PropertyValue >& rDescriptor )
394 {
395     OUString                     sFileName;
396     uno::Reference< embed::XStorage >   xStorage;
397     uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier;
398 
399     for(const PropertyValue& rProp : rDescriptor)
400     {
401         if ( rProp.Name == "FileName" )
402             rProp.Value >>= sFileName;
403         else if ( rProp.Name == "Storage" )
404             rProp.Value >>= xStorage;
405         else if ( rProp.Name == "ComponentData" )
406         {
407             Sequence< PropertyValue > aComponent;
408             rProp.Value >>= aComponent;
409             const PropertyValue* pComponentIter = aComponent.getConstArray();
410             const PropertyValue* pComponentEnd  = pComponentIter + aComponent.getLength();
411             pComponentIter = std::find_if(pComponentIter, pComponentEnd,
412                 [](const PropertyValue& rComponent) { return rComponent.Name == "ActiveConnection"; });
413             if (pComponentIter != pComponentEnd)
414             {
415                 uno::Reference<sdbc::XConnection> xCon(pComponentIter->Value, uno::UNO_QUERY);
416                 xNumberFormatsSupplier = ::dbtools::getNumberFormats(xCon);
417             }
418         }
419     }
420 
421     if ( !sFileName.isEmpty() )
422     {
423         uno::Reference<XComponent> xCom = GetModel();
424 
425         tools::SvRef<SfxMedium> pMedium = new SfxMedium(
426                 sFileName, ( StreamMode::READ | StreamMode::NOCREATE ) );
427 
428         if( pMedium.is() )
429         {
430             try
431             {
432                 xStorage = pMedium->GetStorage();
433             }
434             catch (const Exception&)
435             {
436             }
437         }
438     }
439     bool bRet = xStorage.is();
440     if ( bRet )
441     {
442         m_xReportDefinition.set(GetModel(),UNO_QUERY_THROW);
443 
444 #if OSL_DEBUG_LEVEL > 1
445         uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
446         uno::Sequence< OUString> aSeq = xAccess->getElementNames();
447         const OUString* pDebugIter = aSeq.getConstArray();
448         const OUString* pDebugEnd      = pDebugIter + aSeq.getLength();
449         for(;pDebugIter != pDebugEnd;++pDebugIter)
450         {
451             (void)*pDebugIter;
452         }
453 #endif
454 
455         uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
456         uno::Reference<document::XEmbeddedObjectResolver> xEmbeddedObjectResolver;
457         uno::Reference< uno::XComponentContext > xContext = GetComponentContext();
458 
459         uno::Sequence<uno::Any> aArgs(1);
460         aArgs[0] <<= xStorage;
461         xGraphicStorageHandler.set(
462                 xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.Svx.GraphicImportHelper", aArgs, xContext),
463                 uno::UNO_QUERY);
464 
465         uno::Reference< lang::XMultiServiceFactory > xReportServiceFactory( m_xReportDefinition, uno::UNO_QUERY);
466         aArgs[0] <<= beans::NamedValue("Storage",uno::makeAny(xStorage));
467         xEmbeddedObjectResolver.set( xReportServiceFactory->createInstanceWithArguments("com.sun.star.document.ImportEmbeddedObjectResolver",aArgs) , uno::UNO_QUERY);
468 
469         static const char s_sOld[] = "OldFormat";
470         static comphelper::PropertyMapEntry const pMap[] =
471         {
472             { OUString("OldFormat") , 1,    cppu::UnoType<sal_Bool>::get(),                 beans::PropertyAttribute::BOUND,     0 },
473             { OUString("StreamName"), 0,    cppu::UnoType<OUString>::get(),             beans::PropertyAttribute::MAYBEVOID, 0 },
474             { OUString("PrivateData"),0,    cppu::UnoType<XInterface>::get(),  beans::PropertyAttribute::MAYBEVOID, 0 },
475             { OUString("BaseURI"),    0,    cppu::UnoType<OUString>::get(),             beans::PropertyAttribute::MAYBEVOID, 0 },
476             { OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(),             beans::PropertyAttribute::MAYBEVOID, 0 },
477             { OUString(), 0, css::uno::Type(), 0, 0 }
478         };
479         utl::MediaDescriptor aDescriptor(rDescriptor);
480         uno::Reference<beans::XPropertySet> xProp = comphelper::GenericPropertySet_CreateInstance(new comphelper::PropertySetInfo(pMap));
481         const OUString sVal( aDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_DOCUMENTBASEURL(),OUString()) );
482         assert(!sVal.isEmpty()); // needed for relative URLs
483         xProp->setPropertyValue("BaseURI", uno::makeAny(sVal));
484         const OUString sHierarchicalDocumentName( aDescriptor.getUnpackedValueOrDefault("HierarchicalDocumentName",OUString()) );
485         xProp->setPropertyValue("StreamRelPath", uno::makeAny(sHierarchicalDocumentName));
486 
487         uno::Reference<XComponent> xModel = GetModel();
488         static const char s_sMeta[] = "meta.xml";
489         static const char s_sStreamName[] = "StreamName";
490         xProp->setPropertyValue(s_sStreamName, uno::makeAny(OUString(s_sMeta)));
491         ErrCode nRet = ReadThroughComponent( xStorage
492                                     ,xModel
493                                     ,"meta.xml"
494                                     ,"Meta.xml"
495                                     ,GetComponentContext()
496                                     ,xGraphicStorageHandler
497                                     ,xEmbeddedObjectResolver
498                                     ,SERVICE_METAIMPORTER
499                                     ,xProp
500                                     );
501 
502 
503         try
504         {
505             xProp->setPropertyValue(s_sOld,uno::makeAny(!(xStorage->hasByName(s_sMeta) || xStorage->isStreamElement( s_sMeta ))));
506         }
507         catch (const uno::Exception&)
508         {
509             xProp->setPropertyValue(s_sOld,uno::makeAny(true));
510         }
511 
512         if ( nRet == ERRCODE_NONE )
513         {
514             xProp->setPropertyValue(s_sStreamName, uno::makeAny(OUString("settings.xml")));
515             nRet = ReadThroughComponent( xStorage
516                                     ,xModel
517                                     ,"settings.xml"
518                                     ,"Settings.xml"
519                                     ,GetComponentContext()
520                                     ,xGraphicStorageHandler
521                                     ,xEmbeddedObjectResolver
522                                     ,SERVICE_SETTINGSIMPORTER
523                                     ,xProp
524                                     );
525         }
526         if ( nRet == ERRCODE_NONE )
527         {
528             xProp->setPropertyValue(s_sStreamName, uno::makeAny(OUString("styles.xml")));
529             nRet = ReadThroughComponent(xStorage
530                                     ,xModel
531                                     ,"styles.xml"
532                                     ,"Styles.xml"
533                                     ,GetComponentContext()
534                                     ,xGraphicStorageHandler
535                                     ,xEmbeddedObjectResolver
536                                     ,SERVICE_STYLESIMPORTER
537                                     ,xProp);
538         }
539 
540         if ( nRet == ERRCODE_NONE )
541         {
542             xProp->setPropertyValue(s_sStreamName, uno::makeAny(OUString("content.xml")));
543             nRet = ReadThroughComponent( xStorage
544                                     ,xModel
545                                     ,"content.xml"
546                                     ,"Content.xml"
547                                     ,GetComponentContext()
548                                     ,xGraphicStorageHandler
549                                     ,xEmbeddedObjectResolver
550                                     ,SERVICE_CONTENTIMPORTER
551                                     ,xProp
552                                     );
553         }
554 
555 
556         bRet = nRet == ERRCODE_NONE;
557 
558         if ( bRet )
559         {
560             m_xReportDefinition->setModified(false);
561         }
562         else
563         {
564             if( nRet == ERRCODE_IO_BROKENPACKAGE && xStorage.is() )
565                 ; // TODO/LATER: no way to transport the error outside from the filter!
566             else
567             {
568                 // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way!
569                 ErrorHandler::HandleError( nRet );
570                 if( nRet.IsWarning() )
571                     bRet = true;
572             }
573         }
574     }
575 
576     return bRet;
577 }
578 
579 class RptXMLDocumentSettingsContext : public SvXMLImportContext
580 {
581 public:
RptXMLDocumentSettingsContext(SvXMLImport & rImport,sal_uInt16 const nPrefix,const OUString & rLocalName)582     RptXMLDocumentSettingsContext(SvXMLImport & rImport,
583            sal_uInt16 const nPrefix,
584            const OUString& rLocalName)
585         : SvXMLImportContext(rImport, nPrefix, rLocalName)
586     {
587     }
588 
CreateChildContext(sal_uInt16 const nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)589     virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 const nPrefix,
590            const OUString& rLocalName,
591            const uno::Reference<xml::sax::XAttributeList> & xAttrList) override
592     {
593         if (nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken(rLocalName, XML_SETTINGS))
594         {
595             return new XMLDocumentSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList);
596         }
597         else
598         {
599             return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
600         }
601     }
602 };
603 
604 class RptXMLDocumentStylesContext : public SvXMLImportContext
605 {
606 public:
RptXMLDocumentStylesContext(SvXMLImport & rImport,sal_uInt16 const nPrefix,const OUString & rLocalName)607     RptXMLDocumentStylesContext(SvXMLImport & rImport,
608             sal_uInt16 const nPrefix,
609             const OUString& rLocalName)
610         : SvXMLImportContext(rImport, nPrefix, rLocalName)
611     {
612     }
613 
CreateChildContext(sal_uInt16 const nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)614     virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 const nPrefix,
615         const OUString& rLocalName,
616         const uno::Reference<xml::sax::XAttributeList> & xAttrList) override
617     {
618         SvXMLImportContext *pContext = nullptr;
619 
620         ORptFilter & rImport(static_cast<ORptFilter&>(GetImport()));
621         const SvXMLTokenMap& rTokenMap = rImport.GetDocContentElemTokenMap();
622         switch (rTokenMap.Get(nPrefix, rLocalName))
623         {
624             case XML_TOK_CONTENT_STYLES:
625                 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
626                 pContext = rImport.CreateStylesContext(rLocalName, xAttrList, false);
627                 break;
628             case XML_TOK_CONTENT_AUTOSTYLES:
629                 // don't use the autostyles from the styles-document for the progress
630                 pContext = rImport.CreateStylesContext(rLocalName, xAttrList, true);
631                 break;
632             case XML_TOK_CONTENT_FONTDECLS:
633                 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
634                 pContext = rImport.CreateFontDeclsContext(rLocalName, xAttrList);
635                 break;
636             case XML_TOK_CONTENT_MASTERSTYLES:
637                 {
638                     SvXMLStylesContext* pStyleContext = new RptMLMasterStylesContext_Impl(rImport, nPrefix, rLocalName, xAttrList);//CreateMasterStylesContext( rLocalName,xAttrList );
639                     pContext = pStyleContext;
640                     rImport.SetMasterStyles(pStyleContext);
641                 }
642                 break;
643             default:
644                 break;
645         }
646 
647         if (!pContext)
648             pContext = new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
649 
650         return pContext;
651     }
652 };
653 
CreateChildContext(sal_uInt16 const nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)654 SvXMLImportContextRef RptXMLDocumentBodyContext::CreateChildContext(
655         sal_uInt16 const nPrefix,
656         const OUString& rLocalName,
657         const uno::Reference<xml::sax::XAttributeList> & xAttrList)
658 {
659     ORptFilter & rImport(static_cast<ORptFilter&>(GetImport()));
660     if ((XML_NAMESPACE_OFFICE == nPrefix || XML_NAMESPACE_OOO == nPrefix)
661         && IsXMLToken(rLocalName, XML_REPORT))
662     {
663         rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
664         const SvXMLStylesContext* pAutoStyles = rImport.GetAutoStyles();
665         if (pAutoStyles)
666         {
667             XMLPropStyleContext* pAutoStyle = const_cast<XMLPropStyleContext*>(dynamic_cast<const XMLPropStyleContext *>(pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_PAGE_MASTER, "pm1")));
668             if (pAutoStyle)
669             {
670                 pAutoStyle->FillPropertySet(rImport.getReportDefinition().get());
671             }
672         }
673         return new OXMLReport(rImport, nPrefix, rLocalName, xAttrList, rImport.getReportDefinition());
674     }
675     else
676     {
677         return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
678     }
679 }
680 
681 class RptXMLDocumentContentContext : public SvXMLImportContext
682 {
683 public:
RptXMLDocumentContentContext(SvXMLImport & rImport,sal_uInt16 const nPrefix,const OUString & rLocalName)684     RptXMLDocumentContentContext(SvXMLImport & rImport,
685             sal_uInt16 const nPrefix,
686             const OUString& rLocalName)
687         : SvXMLImportContext(rImport, nPrefix, rLocalName)
688     {
689     }
690 
CreateChildContext(sal_uInt16 const nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)691     virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 const nPrefix,
692         const OUString& rLocalName,
693         const uno::Reference<xml::sax::XAttributeList> & xAttrList) override
694     {
695         SvXMLImportContext *pContext = nullptr;
696 
697         ORptFilter & rImport(static_cast<ORptFilter&>(GetImport()));
698         const SvXMLTokenMap& rTokenMap = rImport.GetDocContentElemTokenMap();
699         switch (rTokenMap.Get(nPrefix, rLocalName))
700         {
701             case XML_TOK_CONTENT_AUTOSTYLES:
702                 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
703                 pContext = rImport.CreateStylesContext(rLocalName, xAttrList, true);
704                 break;
705             case XML_TOK_CONTENT_FONTDECLS:
706                 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
707                 pContext = rImport.CreateFontDeclsContext(rLocalName, xAttrList);
708                 break;
709             case XML_TOK_CONTENT_BODY:
710                 pContext = new RptXMLDocumentBodyContext(rImport, nPrefix, rLocalName);
711                 break;
712             default:
713                 break;
714         }
715 
716         if (!pContext)
717             pContext = new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
718 
719         return pContext;
720     }
721 };
722 
CreateDocumentContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)723 SvXMLImportContext* ORptFilter::CreateDocumentContext( sal_uInt16 nPrefix,
724                                       const OUString& rLocalName,
725                                       const uno::Reference< xml::sax::XAttributeList >& xAttrList )
726 {
727     SvXMLImportContext *pContext = nullptr;
728 
729     const SvXMLTokenMap& rTokenMap = GetDocElemTokenMap();
730     switch( rTokenMap.Get( nPrefix, rLocalName ) )
731     {
732         case XML_TOK_DOC_SETTINGS:
733             GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
734             pContext = new RptXMLDocumentSettingsContext(*this, nPrefix, rLocalName);
735             break;
736         case XML_TOK_DOC_STYLES:
737             pContext = new RptXMLDocumentStylesContext(*this, nPrefix, rLocalName);
738             break;
739         case XML_TOK_DOC_CONTENT:
740             pContext = new RptXMLDocumentContentContext(*this, nPrefix, rLocalName);
741             break;
742         default:
743             break;
744     }
745 
746     if ( !pContext )
747         pContext = SvXMLImport::CreateDocumentContext( nPrefix, rLocalName, xAttrList );
748 
749     return pContext;
750 }
751 
CreateFastContext(sal_Int32 nElement,const uno::Reference<xml::sax::XFastAttributeList> &)752 SvXMLImportContext *ORptFilter::CreateFastContext( sal_Int32 nElement,
753         const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
754 {
755     SvXMLImportContext *pContext = nullptr;
756 
757     switch (nElement)
758     {
759         case XML_ELEMENT( OFFICE, XML_DOCUMENT_META ):
760             GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
761             pContext = CreateMetaContext( nElement );
762             break;
763         default:
764             pContext = new SvXMLImportContext(*this);
765     }
766     return pContext;
767 }
768 
GetDocElemTokenMap() const769 const SvXMLTokenMap& ORptFilter::GetDocElemTokenMap() const
770 {
771     if (!m_pDocElemTokenMap)
772     {
773         static const SvXMLTokenMapEntry aElemTokenMap[]=
774         {
775             { XML_NAMESPACE_OFFICE, XML_DOCUMENT_SETTINGS,  XML_TOK_DOC_SETTINGS    },
776             { XML_NAMESPACE_OFFICE, XML_DOCUMENT_CONTENT,   XML_TOK_DOC_CONTENT     },
777             { XML_NAMESPACE_OFFICE, XML_DOCUMENT_STYLES,    XML_TOK_DOC_STYLES      },
778             { XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,      XML_TOK_DOC_META        },
779             XML_TOKEN_MAP_END
780         };
781         m_pDocElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
782     }
783     return *m_pDocElemTokenMap;
784 }
785 
GetDocContentElemTokenMap() const786 const SvXMLTokenMap& ORptFilter::GetDocContentElemTokenMap() const
787 {
788     if (!m_pDocContentElemTokenMap)
789     {
790         static const SvXMLTokenMapEntry aElemTokenMap[]=
791         {
792             { XML_NAMESPACE_OFFICE, XML_STYLES,             XML_TOK_CONTENT_STYLES      },
793             { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES,   XML_TOK_CONTENT_AUTOSTYLES  },
794             { XML_NAMESPACE_OFFICE, XML_FONT_FACE_DECLS,    XML_TOK_CONTENT_FONTDECLS   },
795             { XML_NAMESPACE_OFFICE, XML_MASTER_STYLES,      XML_TOK_CONTENT_MASTERSTYLES},
796             { XML_NAMESPACE_OFFICE, XML_BODY,               XML_TOK_CONTENT_BODY        },
797             XML_TOKEN_MAP_END
798         };
799         m_pDocContentElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
800     }
801     return *m_pDocContentElemTokenMap;
802 }
803 
GetReportElemTokenMap() const804 const SvXMLTokenMap& ORptFilter::GetReportElemTokenMap() const
805 {
806     if (!m_pReportElemTokenMap)
807         m_pReportElemTokenMap = OXMLHelper::GetReportElemTokenMap();
808     return *m_pReportElemTokenMap;
809 }
810 
GetSubDocumentElemTokenMap() const811 const SvXMLTokenMap& ORptFilter::GetSubDocumentElemTokenMap() const
812 {
813     if (!m_pSubDocumentElemTokenMap)
814         m_pSubDocumentElemTokenMap = OXMLHelper::GetSubDocumentElemTokenMap();
815     return *m_pSubDocumentElemTokenMap;
816 }
817 
GetFunctionElemTokenMap() const818 const SvXMLTokenMap& ORptFilter::GetFunctionElemTokenMap() const
819 {
820     if (!m_pFunctionElemTokenMap)
821     {
822         static const SvXMLTokenMapEntry aElemTokenMap[]=
823         {
824             { XML_NAMESPACE_REPORT, XML_NAME,           XML_TOK_FUNCTION_NAME   },
825             { XML_NAMESPACE_REPORT, XML_FORMULA,        XML_TOK_FUNCTION_FORMULA},
826             { XML_NAMESPACE_REPORT, XML_PRE_EVALUATED,  XML_TOK_PRE_EVALUATED   },
827             { XML_NAMESPACE_REPORT, XML_INITIAL_FORMULA,XML_TOK_INITIAL_FORMULA   },
828             { XML_NAMESPACE_REPORT, XML_DEEP_TRAVERSING,XML_TOK_DEEP_TRAVERSING   },
829             XML_TOKEN_MAP_END
830         };
831         m_pFunctionElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
832     }
833     return *m_pFunctionElemTokenMap;
834 }
835 
GetFormatElemTokenMap() const836 const SvXMLTokenMap& ORptFilter::GetFormatElemTokenMap() const
837 {
838     if (!m_pFormatElemTokenMap)
839     {
840         static const SvXMLTokenMapEntry aElemTokenMap[]=
841         {
842             { XML_NAMESPACE_REPORT, XML_ENABLED     , XML_TOK_ENABLED           },
843             { XML_NAMESPACE_REPORT, XML_FORMULA     , XML_TOK_FORMULA           },
844             { XML_NAMESPACE_REPORT, XML_STYLE_NAME  , XML_TOK_FORMAT_STYLE_NAME },
845             XML_TOKEN_MAP_END
846         };
847         m_pFormatElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
848     }
849     return *m_pFormatElemTokenMap;
850 }
851 
GetGroupElemTokenMap() const852 const SvXMLTokenMap& ORptFilter::GetGroupElemTokenMap() const
853 {
854     if (!m_pGroupElemTokenMap)
855     {
856         static const SvXMLTokenMapEntry aElemTokenMap[]=
857         {
858             { XML_NAMESPACE_REPORT, XML_START_NEW_COLUMN            ,   XML_TOK_START_NEW_COLUMN            },
859             { XML_NAMESPACE_REPORT, XML_RESET_PAGE_NUMBER           ,   XML_TOK_RESET_PAGE_NUMBER           },
860             { XML_NAMESPACE_REPORT, XML_PRINT_HEADER_ON_EACH_PAGE   ,   XML_TOK_PRINT_HEADER_ON_EACH_PAGE   },
861             { XML_NAMESPACE_REPORT, XML_RESET_PAGE_NUMBER           ,   XML_TOK_RESET_PAGE_NUMBER           },
862             { XML_NAMESPACE_REPORT, XML_SORT_EXPRESSION             ,   XML_TOK_SORT_EXPRESSION             },
863             { XML_NAMESPACE_REPORT, XML_GROUP_EXPRESSION            ,   XML_TOK_GROUP_EXPRESSION            },
864             { XML_NAMESPACE_REPORT, XML_GROUP_HEADER                ,   XML_TOK_GROUP_HEADER                },
865             { XML_NAMESPACE_REPORT, XML_GROUP                       ,   XML_TOK_GROUP_GROUP                 },
866             { XML_NAMESPACE_REPORT, XML_DETAIL                      ,   XML_TOK_GROUP_DETAIL                },
867             { XML_NAMESPACE_REPORT, XML_GROUP_FOOTER                ,   XML_TOK_GROUP_FOOTER                },
868             { XML_NAMESPACE_REPORT, XML_SORT_ASCENDING              ,   XML_TOK_SORT_ASCENDING              },
869             { XML_NAMESPACE_REPORT, XML_KEEP_TOGETHER               ,   XML_TOK_GROUP_KEEP_TOGETHER         },
870             { XML_NAMESPACE_REPORT, XML_FUNCTION                    ,   XML_TOK_GROUP_FUNCTION              },
871             XML_TOKEN_MAP_END
872         };
873         m_pGroupElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
874     }
875     return *m_pGroupElemTokenMap;
876 }
877 
GetReportElementElemTokenMap() const878 const SvXMLTokenMap& ORptFilter::GetReportElementElemTokenMap() const
879 {
880     if (!m_pElemTokenMap)
881     {
882         static const SvXMLTokenMapEntry aElemTokenMap[]=
883         {
884             { XML_NAMESPACE_REPORT, XML_PRINT_REPEATED_VALUES       ,XML_TOK_PRINT_REPEATED_VALUES              },
885             { XML_NAMESPACE_REPORT, XML_PRINT_WHEN_GROUP_CHANGE     ,XML_TOK_PRINT_WHEN_GROUP_CHANGE            },
886             { XML_NAMESPACE_REPORT, XML_CONDITIONAL_PRINT_EXPRESSION,XML_TOK_REP_CONDITIONAL_PRINT_EXPRESSION   },
887             { XML_NAMESPACE_REPORT, XML_REPORT_COMPONENT            ,XML_TOK_COMPONENT                          },
888             { XML_NAMESPACE_REPORT, XML_FORMAT_CONDITION            ,XML_TOK_FORMATCONDITION                    },
889             XML_TOKEN_MAP_END
890         };
891         m_pElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
892     }
893     return *m_pElemTokenMap;
894 }
895 
GetControlElemTokenMap() const896 const SvXMLTokenMap& ORptFilter::GetControlElemTokenMap() const
897 {
898     if (!m_pControlElemTokenMap)
899     {
900         static const SvXMLTokenMapEntry aElemTokenMap[]=
901         {
902             { XML_NAMESPACE_FORM,   XML_LABEL               ,XML_TOK_LABEL              },
903             { XML_NAMESPACE_FORM,   XML_PROPERTIES          ,XML_TOK_PROPERTIES         },
904             { XML_NAMESPACE_FORM,   XML_SIZE                ,XML_TOK_SIZE               },
905             { XML_NAMESPACE_FORM,   XML_IMAGE_DATA          ,XML_TOK_IMAGE_DATA         },
906             { XML_NAMESPACE_REPORT, XML_SCALE               ,XML_TOK_SCALE              },
907             { XML_NAMESPACE_REPORT, XML_REPORT_ELEMENT      ,XML_TOK_REPORT_ELEMENT     },
908             { XML_NAMESPACE_REPORT, XML_FORMULA             ,XML_TOK_DATA_FORMULA       },
909             { XML_NAMESPACE_REPORT, XML_PRESERVE_IRI        ,XML_TOK_PRESERVE_IRI       },
910             { XML_NAMESPACE_REPORT, XML_SELECT_PAGE         ,XML_TOK_SELECT_PAGE        },
911             XML_TOKEN_MAP_END
912         };
913         m_pControlElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
914     }
915     return *m_pControlElemTokenMap;
916 }
917 
GetControlPropertyElemTokenMap() const918 const SvXMLTokenMap& ORptFilter::GetControlPropertyElemTokenMap() const
919 {
920     if (!m_pControlElemTokenMap)
921     {
922         static const SvXMLTokenMapEntry aElemTokenMap[]=
923         {
924             { XML_NAMESPACE_FORM,   XML_PROPERTY_NAME   ,XML_TOK_PROPERTY_NAME          },
925             { XML_NAMESPACE_OOO,    XML_VALUE_TYPE      ,XML_TOK_VALUE_TYPE             },
926             { XML_NAMESPACE_FORM,   XML_LIST_PROPERTY   ,XML_TOK_LIST_PROPERTY          },
927             { XML_NAMESPACE_OOO,    XML_VALUE           ,XML_TOK_VALUE                  },
928             { XML_NAMESPACE_OOO,    XML_CURRENCY        ,XML_TOK_CURRENCY               },
929             { XML_NAMESPACE_OOO,    XML_DATE_VALUE      ,XML_TOK_DATE_VALUE             },
930             { XML_NAMESPACE_OOO,    XML_TIME_VALUE      ,XML_TOK_TIME_VALUE             },
931             { XML_NAMESPACE_OOO,    XML_STRING_VALUE    ,XML_TOK_STRING_VALUE           },
932             { XML_NAMESPACE_OOO,    XML_BOOLEAN_VALUE   ,XML_TOK_BOOLEAN_VALUE          },
933             XML_TOKEN_MAP_END
934         };
935         m_pControlElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
936     }
937     return *m_pControlElemTokenMap;
938 }
939 
GetComponentElemTokenMap() const940 const SvXMLTokenMap& ORptFilter::GetComponentElemTokenMap() const
941 {
942     if (!m_pComponentElemTokenMap)
943     {
944         static const SvXMLTokenMapEntry aElemTokenMap[]=
945         {
946             { XML_NAMESPACE_DRAW,   XML_NAME                        ,   XML_TOK_NAME                        },
947             { XML_NAMESPACE_DRAW,   XML_TEXT_STYLE_NAME             ,   XML_TOK_TEXT_STYLE_NAME             },
948             { XML_NAMESPACE_REPORT, XML_TRANSFORM                   ,   XML_TOK_TRANSFORM                   },
949             XML_TOKEN_MAP_END
950         };
951         m_pComponentElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
952     }
953     return *m_pComponentElemTokenMap;
954 }
955 
GetColumnTokenMap() const956 const SvXMLTokenMap& ORptFilter::GetColumnTokenMap() const
957 {
958     if (!m_pColumnTokenMap)
959     {
960         static const SvXMLTokenMapEntry aElemTokenMap[]=
961         {
962             { XML_NAMESPACE_TABLE,  XML_NAME                        ,   XML_TOK_NAME                        },
963             { XML_NAMESPACE_TABLE,  XML_STYLE_NAME                  ,   XML_TOK_COLUMN_STYLE_NAME           },
964             { XML_NAMESPACE_TABLE,  XML_TABLE_COLUMN                ,   XML_TOK_COLUMN                      },
965             { XML_NAMESPACE_TABLE,  XML_TABLE_ROW                   ,   XML_TOK_ROW                         },
966             { XML_NAMESPACE_TABLE,  XML_TABLE_CELL                  ,   XML_TOK_CELL                        },
967             { XML_NAMESPACE_TABLE,  XML_TABLE_COLUMNS               ,   XML_TOK_TABLE_COLUMNS               },
968             { XML_NAMESPACE_TABLE,  XML_TABLE_ROWS                  ,   XML_TOK_TABLE_ROWS                  },
969             { XML_NAMESPACE_TABLE,  XML_COVERED_TABLE_CELL          ,   XML_TOK_COV_CELL                    },
970             { XML_NAMESPACE_TABLE,  XML_NUMBER_COLUMNS_SPANNED      ,   XML_TOK_NUMBER_COLUMNS_SPANNED      },
971             { XML_NAMESPACE_TABLE,  XML_NUMBER_ROWS_SPANNED         ,   XML_TOK_NUMBER_ROWS_SPANNED         },
972             { XML_NAMESPACE_REPORT, XML_CONDITIONAL_PRINT_EXPRESSION,   XML_TOK_CONDITIONAL_PRINT_EXPRESSION},
973             XML_TOKEN_MAP_END
974         };
975         m_pColumnTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
976     }
977     return *m_pColumnTokenMap;
978 }
979 
GetSectionElemTokenMap() const980 const SvXMLTokenMap& ORptFilter::GetSectionElemTokenMap() const
981 {
982     if (!m_pSectionElemTokenMap)
983     {
984         static const SvXMLTokenMapEntry aElemTokenMap[]=
985         {
986             { XML_NAMESPACE_TABLE,  XML_TABLE                       ,   XML_TOK_TABLE                       },
987             { XML_NAMESPACE_TABLE,  XML_NAME                        ,   XML_TOK_SECTION_NAME                },
988             { XML_NAMESPACE_REPORT, XML_VISIBLE                     ,   XML_TOK_VISIBLE                     },
989             { XML_NAMESPACE_REPORT, XML_FORCE_NEW_PAGE              ,   XML_TOK_FORCE_NEW_PAGE              },
990             { XML_NAMESPACE_REPORT, XML_FORCE_NEW_COLUMN            ,   XML_TOK_FORCE_NEW_COLUMN            },
991             { XML_NAMESPACE_REPORT, XML_KEEP_TOGETHER               ,   XML_TOK_KEEP_TOGETHER               },
992             { XML_NAMESPACE_REPORT, XML_REPEAT_SECTION              ,   XML_TOK_REPEAT_SECTION              },
993             { XML_NAMESPACE_TABLE,  XML_STYLE_NAME                  ,   XML_TOK_SECT_STYLE_NAME             },
994             { XML_NAMESPACE_REPORT, XML_PAGE_PRINT_OPTION           ,   XML_TOK_PAGE_PRINT_OPTION           },
995 
996             XML_TOKEN_MAP_END
997         };
998         m_pSectionElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
999     }
1000     return *m_pSectionElemTokenMap;
1001 }
1002 
GetCellElemTokenMap() const1003 const SvXMLTokenMap& ORptFilter::GetCellElemTokenMap() const
1004 {
1005     if (!m_pCellElemTokenMap)
1006     {
1007         static const SvXMLTokenMapEntry aElemTokenMap[]=
1008         {
1009             { XML_NAMESPACE_TEXT,   XML_P                           ,   XML_TOK_P                           },
1010             { XML_NAMESPACE_REPORT, XML_FIXED_CONTENT               ,   XML_TOK_FIXED_CONTENT               },
1011             { XML_NAMESPACE_REPORT, XML_FORMATTED_TEXT              ,   XML_TOK_FORMATTED_TEXT              },
1012             { XML_NAMESPACE_REPORT, XML_IMAGE                       ,   XML_TOK_IMAGE                       },
1013             { XML_NAMESPACE_REPORT, XML_SUB_DOCUMENT                ,   XML_TOK_SUB_DOCUMENT                },
1014             { XML_NAMESPACE_DRAW,   XML_CUSTOM_SHAPE                ,   XML_TOK_CUSTOM_SHAPE                },
1015             { XML_NAMESPACE_DRAW,   XML_FRAME                       ,   XML_TOK_FRAME                       },
1016             { XML_NAMESPACE_TEXT,   XML_PAGE_NUMBER                 ,   XML_TOK_PAGE_NUMBER                 },
1017             { XML_NAMESPACE_TEXT,   XML_PAGE_COUNT                  ,   XML_TOK_PAGE_COUNT                  },
1018             { XML_NAMESPACE_TEXT,   XML_TAB                         ,   XML_TOK_TEXT_TAB_STOP               },
1019             { XML_NAMESPACE_TEXT,   XML_LINE_BREAK                  ,   XML_TOK_TEXT_LINE_BREAK             },
1020             { XML_NAMESPACE_TEXT,   XML_S                           ,   XML_TOK_TEXT_S                      },
1021             XML_TOKEN_MAP_END
1022         };
1023         m_pCellElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
1024     }
1025     return *m_pCellElemTokenMap;
1026 }
1027 
CreateStylesContext(const OUString & rLocalName,const uno::Reference<XAttributeList> & xAttrList,bool bIsAutoStyle)1028 SvXMLImportContext* ORptFilter::CreateStylesContext(const OUString& rLocalName,
1029                                      const uno::Reference< XAttributeList>& xAttrList, bool bIsAutoStyle )
1030 {
1031     SvXMLImportContext* pContext = bIsAutoStyle ? GetAutoStyles() : GetStyles();
1032     if ( !pContext )
1033     {
1034         pContext = new OReportStylesContext(*this, XML_NAMESPACE_OFFICE, rLocalName, xAttrList, bIsAutoStyle);
1035         if (bIsAutoStyle)
1036             SetAutoStyles(static_cast<SvXMLStylesContext*>(pContext));
1037         else
1038             SetStyles(static_cast<SvXMLStylesContext*>(pContext));
1039     }
1040     return pContext;
1041 }
1042 
CreateFontDeclsContext(const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)1043 SvXMLImportContext *ORptFilter::CreateFontDeclsContext(
1044         const OUString& rLocalName,
1045         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
1046 {
1047     XMLFontStylesContext *pFSContext =
1048             new XMLFontStylesContext( *this, XML_NAMESPACE_OFFICE,
1049                                       rLocalName, xAttrList,
1050                                       osl_getThreadTextEncoding() );
1051     SetFontDecls( pFSContext );
1052     return pFSContext;
1053 }
1054 
CreateShapeImport()1055 XMLShapeImportHelper* ORptFilter::CreateShapeImport()
1056 {
1057     return new XMLShapeImportHelper( *this,GetModel() );
1058 }
1059 
FinishStyles()1060 void ORptFilter::FinishStyles()
1061 {
1062     if( GetStyles() )
1063         GetStyles()->FinishStyles( true );
1064 }
1065 
convertFormula(const OUString & _sFormula)1066 const OUString& ORptFilter::convertFormula(const OUString& _sFormula)
1067 {
1068     return _sFormula;
1069 }
1070 
startDocument()1071 void SAL_CALL ORptFilter::startDocument()
1072 {
1073     m_xReportDefinition.set(GetModel(),UNO_QUERY_THROW);
1074     m_pReportModel = reportdesign::OReportDefinition::getSdrModel(m_xReportDefinition);
1075     OSL_ENSURE(m_pReportModel,"Report model is NULL!");
1076 
1077     SvXMLImport::startDocument();
1078 }
1079 
endDocument()1080 void ORptFilter::endDocument()
1081 {
1082     OSL_ENSURE( GetModel().is(), "model missing; maybe startDocument wasn't called?" );
1083     if( !GetModel().is() )
1084         return;
1085 
1086     // this method will modify the document directly -> lock SolarMutex
1087     SolarMutexGuard aGuard;
1088     // Clear the shape import to sort the shapes  (and not in the
1089     // destructor that might be called after the import has finished
1090     // for Java filters.
1091     if( HasShapeImport() )
1092         ClearShapeImport();
1093 
1094     // delegate to parent: takes care of error handling
1095     SvXMLImport::endDocument();
1096 }
1097 
removeFunction(const OUString & _sFunctionName)1098 void ORptFilter::removeFunction(const OUString& _sFunctionName)
1099 {
1100     m_aFunctions.erase(_sFunctionName);
1101 }
1102 
insertFunction(const css::uno::Reference<css::report::XFunction> & _xFunction)1103 void ORptFilter::insertFunction(const css::uno::Reference< css::report::XFunction > & _xFunction)
1104 {
1105     m_aFunctions.emplace(_xFunction->getName(),_xFunction);
1106 }
1107 
CreateMetaContext(const sal_Int32)1108 SvXMLImportContext* ORptFilter::CreateMetaContext(const sal_Int32 /*nElement*/)
1109 {
1110     SvXMLImportContext* pContext = nullptr;
1111 
1112     if ( getImportFlags() & SvXMLImportFlags::META )
1113     {
1114         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(), uno::UNO_QUERY_THROW);
1115         pContext = new SvXMLMetaDocumentContext(*this, xDPS->getDocumentProperties());
1116     }
1117     return pContext;
1118 }
1119 
isOldFormat() const1120 bool ORptFilter::isOldFormat() const
1121 {
1122     bool bOldFormat = true;
1123     uno::Reference<beans::XPropertySet> xProp = getImportInfo();
1124     if ( xProp.is() )
1125     {
1126         static const char s_sOld[] = "OldFormat";
1127         if ( xProp->getPropertySetInfo()->hasPropertyByName(s_sOld))
1128         {
1129             xProp->getPropertyValue(s_sOld) >>= bOldFormat;
1130         }
1131     }
1132     return bOldFormat;
1133 }
1134 
1135 
1136 }// rptxml
1137 
1138 
1139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1140