LibreOffice Module reportdesign (master)  1
xmlfilter.cxx
Go to the documentation of this file.
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/util/MeasureUnit.hpp>
28 #include <com/sun/star/xml/sax/SAXParseException.hpp>
29 #include <com/sun/star/document/XGraphicStorageHandler.hpp>
30 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
31 #include "xmlfilter.hxx"
32 #include "xmlReport.hxx"
33 #include <vcl/errinf.hxx>
34 #include "xmlHelper.hxx"
35 #include <vcl/svapp.hxx>
36 #include <vcl/window.hxx>
37 #include <connectivity/dbtools.hxx>
38 #include <xmloff/xmlnamespace.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/txtimp.hxx>
41 #include <xmloff/namespacemap.hxx>
43 #include <com/sun/star/xml/sax/InputSource.hpp>
44 #include <com/sun/star/beans/PropertyAttribute.hpp>
45 
51 #include <sfx2/docfile.hxx>
52 #include <com/sun/star/io/XInputStream.hpp>
54 #include <xmloff/xmluconv.hxx>
55 #include <xmloff/xmlmetai.hxx>
56 #include <tools/diagnose_ex.h>
57 #include <svtools/sfxecode.hxx>
58 #include "xmlEnums.hxx"
59 #include "xmlStyleImport.hxx"
60 #include <strings.hxx>
61 #include "xmlPropertyHandler.hxx"
62 #include <ReportDefinition.hxx>
63 
64 namespace rptxml
65 {
66 using namespace ::com::sun::star::uno;
67 using ::com::sun::star::uno::Reference;
68 using namespace ::com::sun::star;
69 using namespace ::com::sun::star::container;
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::beans;
72 using namespace ::com::sun::star::document;
73 using namespace ::com::sun::star::text;
74 using namespace ::com::sun::star::io;
75 using namespace ::com::sun::star::report;
76 using namespace ::com::sun::star::xml::sax;
77 using namespace xmloff;
78 using namespace ::com::sun::star::util;
79 
80 namespace {
81 
82 class RptMLMasterStylesContext_Impl:
84 {
85  ORptFilter& GetImport() { return static_cast<ORptFilter&>(XMLTextMasterStylesContext::GetImport()); }
86 
87 public:
88 
89 
90  RptMLMasterStylesContext_Impl( ORptFilter& rImport );
91 
92  RptMLMasterStylesContext_Impl(const RptMLMasterStylesContext_Impl&) = delete;
93  RptMLMasterStylesContext_Impl& operator=(const RptMLMasterStylesContext_Impl&) = delete;
94  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
95 };
96 
97 }
98 
99 RptMLMasterStylesContext_Impl::RptMLMasterStylesContext_Impl( ORptFilter& rImport ) :
100  XMLTextMasterStylesContext( rImport )
101 {
102 }
103 
104 void RptMLMasterStylesContext_Impl::endFastElement(sal_Int32 )
105 {
106  FinishStyles( true );
107  GetImport().FinishStyles();
108 }
109 
112  const uno::Reference<XInputStream>& xInputStream,
113  const uno::Reference<XComponent>& xModelComponent,
114  const uno::Reference<XComponentContext> & rContext,
115  const uno::Reference<XFastParser>& rFastParser )
116 {
117  OSL_ENSURE(xInputStream.is(), "input stream missing");
118  OSL_ENSURE(xModelComponent.is(), "document missing");
119  OSL_ENSURE(rContext.is(), "factory missing");
120 
121  // prepare Parser InputSource
122  InputSource aParserInput;
123  aParserInput.aInputStream = xInputStream;
124 
125  // get filter
126  SAL_WARN_IF( !rFastParser.is(), "reportdesign", "Can't instantiate filter component." );
127  if( !rFastParser.is() )
128  return ErrCode(1);
129 
130  // connect model and filter
131  uno::Reference < XImporter > xImporter( rFastParser, UNO_QUERY );
132  xImporter->setTargetDocument( xModelComponent );
133 
134  // finally, parser the stream
135  try
136  {
137  rFastParser->parseStream( aParserInput );
138  }
139  catch (const SAXParseException&)
140  {
141  TOOLS_WARN_EXCEPTION( "reportdesign", "");
142  return ErrCode(1);
143  }
144  catch (const SAXException&)
145  {
146  return ErrCode(1);
147  }
148  catch (const packages::zip::ZipIOException&)
149  {
151  }
152  catch (const IOException&)
153  {
154  TOOLS_WARN_EXCEPTION( "reportdesign", "");
155  return ErrCode(1);
156  }
157  catch (const Exception&)
158  {
159  TOOLS_WARN_EXCEPTION( "reportdesign", "");
160  return ErrCode(1);
161  }
162 
163  // success!
164  return ERRCODE_NONE;
165 }
166 
169  const uno::Reference< embed::XStorage >& xStorage,
170  const uno::Reference<XComponent>& xModelComponent,
171  const char* pStreamName,
172  const uno::Reference<XComponentContext> & rxContext,
173  const Reference<document::XGraphicStorageHandler> & rxGraphicStorageHandler,
174  const Reference<document::XEmbeddedObjectResolver>& _xEmbeddedObjectResolver,
175  const OUString& _sFilterName
176  ,const uno::Reference<beans::XPropertySet>& _xProp)
177 {
178  OSL_ENSURE( xStorage.is(), "Need storage!");
179  OSL_ENSURE(nullptr != pStreamName, "Please, please, give me a name!");
180 
181  if ( xStorage.is() )
182  {
183  uno::Reference< io::XStream > xDocStream;
184 
185  try
186  {
187  // open stream (and set parser input)
188  OUString sStreamName = OUString::createFromAscii(pStreamName);
189  if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) )
190  {
191  // stream name not found! return immediately with OK signal
192  return ERRCODE_NONE;
193  }
194 
195  // get input stream
196  xDocStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
197  }
198  catch (const packages::WrongPasswordException&)
199  {
201  }
202  catch (const uno::Exception&)
203  {
204  return ErrCode(1); // TODO/LATER: error handling
205  }
206 
207  sal_Int32 nArgs = 0;
208  if (rxGraphicStorageHandler.is())
209  nArgs++;
210  if( _xEmbeddedObjectResolver.is())
211  nArgs++;
212  if ( _xProp.is() )
213  nArgs++;
214 
215  uno::Sequence< uno::Any > aFilterCompArgs( nArgs );
216 
217  nArgs = 0;
218  if (rxGraphicStorageHandler.is())
219  aFilterCompArgs[nArgs++] <<= rxGraphicStorageHandler;
220  if( _xEmbeddedObjectResolver.is())
221  aFilterCompArgs[ nArgs++ ] <<= _xEmbeddedObjectResolver;
222  if ( _xProp.is() )
223  aFilterCompArgs[ nArgs++ ] <<= _xProp;
224 
225  // the underlying SvXMLImport implements XFastParser, XImporter, XFastDocumentHandler
226  Reference< XFastParser > xFastParser(
227  rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(_sFilterName, aFilterCompArgs, rxContext),
228  uno::UNO_QUERY_THROW );
229  uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream();
230  // read from the stream
231  return ReadThroughComponent( xInputStream
232  ,xModelComponent
233  ,rxContext
234  ,xFastParser );
235  }
236 
237  // TODO/LATER: better error handling
238  return ErrCode(1);
239 }
240 
241 
246 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
248  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
249 {
250  return cppu::acquire(new ORptFilter(context,
252  SvXMLImportFlags::SETTINGS ));
253 }
254 
259 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
261  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
262 {
263  return cppu::acquire(new ORptFilter(context,
265  SvXMLImportFlags::AUTOSTYLES | SvXMLImportFlags::CONTENT | SvXMLImportFlags::SCRIPTS | SvXMLImportFlags::FONTDECLS ));
266 }
267 
272 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
274  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
275 {
276  return cppu::acquire(new ORptFilter(context,
278  SvXMLImportFlags::STYLES | SvXMLImportFlags::MASTERSTYLES | SvXMLImportFlags::AUTOSTYLES |
279  SvXMLImportFlags::FONTDECLS ));
280 }
281 
286 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
288  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
289 {
290  return cppu::acquire(new ORptFilter(context,
292  SvXMLImportFlags::META ));
293 }
294 
295 
296 ORptFilter::ORptFilter( const uno::Reference< XComponentContext >& _rxContext, OUString const & rImplementationName, SvXMLImportFlags nImportFlags )
297  :SvXMLImport(_rxContext, rImplementationName, nImportFlags)
298 {
299  GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_100TH);
300  GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM);
301  GetNamespaceMap().Add( "_report",
304 
305  GetNamespaceMap().Add( "__report",
308 
313 }
314 
315 
317 {
318 }
319 
320 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
322  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
323 {
324  return cppu::acquire(new ORptFilter(context,
325  "com.sun.star.comp.report.OReportFilter",
326  SvXMLImportFlags::ALL ));
327 }
328 
329 sal_Bool SAL_CALL ORptFilter::filter( const Sequence< PropertyValue >& rDescriptor )
330 {
331  vcl::Window* pFocusWindow = Application::GetFocusWindow();
332  bool bRet = false;
333 
334  if( pFocusWindow )
335  pFocusWindow->EnterWait();
336 
337  if ( GetModel().is() )
338  bRet = implImport( rDescriptor );
339 
340  if ( pFocusWindow )
341  pFocusWindow->LeaveWait();
342 
343  return bRet;
344 }
345 
346 bool ORptFilter::implImport( const Sequence< PropertyValue >& rDescriptor )
347 {
348  OUString sFileName;
349  uno::Reference< embed::XStorage > xStorage;
350  uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier;
351 
352  for(const PropertyValue& rProp : rDescriptor)
353  {
354  if ( rProp.Name == "FileName" )
355  rProp.Value >>= sFileName;
356  else if ( rProp.Name == "Storage" )
357  rProp.Value >>= xStorage;
358  else if ( rProp.Name == "ComponentData" )
359  {
360  Sequence< PropertyValue > aComponent;
361  rProp.Value >>= aComponent;
362  const PropertyValue* pComponentIter = aComponent.getConstArray();
363  const PropertyValue* pComponentEnd = pComponentIter + aComponent.getLength();
364  pComponentIter = std::find_if(pComponentIter, pComponentEnd,
365  [](const PropertyValue& rComponent) { return rComponent.Name == "ActiveConnection"; });
366  if (pComponentIter != pComponentEnd)
367  {
368  uno::Reference<sdbc::XConnection> xCon(pComponentIter->Value, uno::UNO_QUERY);
369  xNumberFormatsSupplier = ::dbtools::getNumberFormats(xCon);
370  }
371  }
372  }
373 
374  if ( !sFileName.isEmpty() )
375  {
376  tools::SvRef<SfxMedium> pMedium = new SfxMedium(
377  sFileName, ( StreamMode::READ | StreamMode::NOCREATE ) );
378 
379  if( pMedium.is() )
380  {
381  try
382  {
383  xStorage = pMedium->GetStorage();
384  }
385  catch (const Exception&)
386  {
387  }
388  }
389  }
390  bool bRet = xStorage.is();
391  if ( bRet )
392  {
393  m_xReportDefinition.set(GetModel(),UNO_QUERY_THROW);
394 
395 #if OSL_DEBUG_LEVEL > 1
396  uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
397  uno::Sequence< OUString> aSeq = xAccess->getElementNames();
398  const OUString* pDebugIter = aSeq.getConstArray();
399  const OUString* pDebugEnd = pDebugIter + aSeq.getLength();
400  for(;pDebugIter != pDebugEnd;++pDebugIter)
401  {
402  (void)*pDebugIter;
403  }
404 #endif
405 
406  uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
407  uno::Reference<document::XEmbeddedObjectResolver> xEmbeddedObjectResolver;
408  uno::Reference< uno::XComponentContext > xContext = GetComponentContext();
409 
410  uno::Sequence<uno::Any> aArgs(1);
411  aArgs[0] <<= xStorage;
412  xGraphicStorageHandler.set(
413  xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.Svx.GraphicImportHelper", aArgs, xContext),
414  uno::UNO_QUERY);
415 
416  uno::Reference< lang::XMultiServiceFactory > xReportServiceFactory( m_xReportDefinition, uno::UNO_QUERY);
417  aArgs[0] <<= beans::NamedValue("Storage",uno::makeAny(xStorage));
418  xEmbeddedObjectResolver.set( xReportServiceFactory->createInstanceWithArguments("com.sun.star.document.ImportEmbeddedObjectResolver",aArgs) , uno::UNO_QUERY);
419 
420  static constexpr OUStringLiteral s_sOld = u"OldFormat";
421  static comphelper::PropertyMapEntry const pMap[] =
422  {
423  { OUString("OldFormat") , 1, cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::BOUND, 0 },
424  { OUString("StreamName"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
425  { OUString("PrivateData"),0, cppu::UnoType<XInterface>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
426  { OUString("BaseURI"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
427  { OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
428  { OUString(), 0, css::uno::Type(), 0, 0 }
429  };
430  utl::MediaDescriptor aDescriptor(rDescriptor);
431  uno::Reference<beans::XPropertySet> xProp = comphelper::GenericPropertySet_CreateInstance(new comphelper::PropertySetInfo(pMap));
432  const OUString sVal( aDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_DOCUMENTBASEURL(),OUString()) );
433  assert(!sVal.isEmpty()); // needed for relative URLs
434  xProp->setPropertyValue("BaseURI", uno::makeAny(sVal));
435  const OUString sHierarchicalDocumentName( aDescriptor.getUnpackedValueOrDefault("HierarchicalDocumentName",OUString()) );
436  xProp->setPropertyValue("StreamRelPath", uno::makeAny(sHierarchicalDocumentName));
437 
438  uno::Reference<XComponent> xModel = GetModel();
439  static constexpr OUStringLiteral s_sMeta = u"meta.xml";
440  static constexpr OUStringLiteral s_sStreamName = u"StreamName";
441  xProp->setPropertyValue(s_sStreamName, uno::makeAny(OUString(s_sMeta)));
442  ErrCode nRet = ReadThroughComponent( xStorage
443  ,xModel
444  ,"meta.xml"
446  ,xGraphicStorageHandler
447  ,xEmbeddedObjectResolver
449  ,xProp
450  );
451 
452 
453  try
454  {
455  xProp->setPropertyValue(s_sOld,uno::makeAny(!(xStorage->hasByName(s_sMeta) || xStorage->isStreamElement( s_sMeta ))));
456  }
457  catch (const uno::Exception&)
458  {
459  xProp->setPropertyValue(s_sOld,uno::makeAny(true));
460  }
461 
462  if ( nRet == ERRCODE_NONE )
463  {
464  xProp->setPropertyValue(s_sStreamName, uno::makeAny(OUString("settings.xml")));
465  nRet = ReadThroughComponent( xStorage
466  ,xModel
467  ,"settings.xml"
469  ,xGraphicStorageHandler
470  ,xEmbeddedObjectResolver
472  ,xProp
473  );
474  }
475  if ( nRet == ERRCODE_NONE )
476  {
477  xProp->setPropertyValue(s_sStreamName, uno::makeAny(OUString("styles.xml")));
478  nRet = ReadThroughComponent(xStorage
479  ,xModel
480  ,"styles.xml"
482  ,xGraphicStorageHandler
483  ,xEmbeddedObjectResolver
485  ,xProp);
486  }
487 
488  if ( nRet == ERRCODE_NONE )
489  {
490  xProp->setPropertyValue(s_sStreamName, uno::makeAny(OUString("content.xml")));
491  nRet = ReadThroughComponent( xStorage
492  ,xModel
493  ,"content.xml"
495  ,xGraphicStorageHandler
496  ,xEmbeddedObjectResolver
498  ,xProp
499  );
500  }
501 
502 
503  bRet = nRet == ERRCODE_NONE;
504 
505  if ( bRet )
506  {
507  m_xReportDefinition->setModified(false);
508  }
509  else
510  {
511  if( nRet == ERRCODE_IO_BROKENPACKAGE && xStorage.is() )
512  ; // TODO/LATER: no way to transport the error outside from the filter!
513  else
514  {
515  // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way!
517  if( nRet.IsWarning() )
518  bRet = true;
519  }
520  }
521  }
522 
523  return bRet;
524 }
525 
526 namespace {
527 
528 class RptXMLDocumentSettingsContext : public SvXMLImportContext
529 {
530 public:
531  RptXMLDocumentSettingsContext(SvXMLImport & rImport)
532  : SvXMLImportContext(rImport)
533  {
534  }
535 
536  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
537  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override
538  {
539  if (nElement == XML_ELEMENT(OFFICE, XML_SETTINGS))
540  {
541  return new XMLDocumentSettingsContext(GetImport());
542  }
543  return nullptr;
544  }
545 };
546 
547 class RptXMLDocumentStylesContext : public SvXMLImportContext
548 {
549 public:
550  RptXMLDocumentStylesContext(SvXMLImport & rImport)
551  : SvXMLImportContext(rImport)
552  {
553  }
554 
555  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
556  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override
557  {
558  ORptFilter & rImport(static_cast<ORptFilter&>(GetImport()));
559  switch (nElement)
560  {
561  case XML_ELEMENT(OFFICE, XML_FONT_FACE_DECLS):
562  rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
563  return rImport.CreateFontDeclsContext();
564  case XML_ELEMENT(OFFICE, XML_MASTER_STYLES):
565  {
566  SvXMLStylesContext* pStyleContext = new RptMLMasterStylesContext_Impl(rImport);
567  rImport.SetMasterStyles(pStyleContext);
568  return pStyleContext;
569  }
570  case XML_ELEMENT(OFFICE, XML_STYLES):
571  rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
572  return rImport.CreateStylesContext(false);
573  case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES):
574  // don't use the autostyles from the styles-document for the progress
575  return rImport.CreateStylesContext(true);
576  }
577  return nullptr;
578  }
579 };
580 
581 }
582 
583 css::uno::Reference< css::xml::sax::XFastContextHandler > RptXMLDocumentBodyContext::createFastChildContext(
584  sal_Int32 nElement,
585  const uno::Reference<xml::sax::XFastAttributeList> & xAttrList)
586 {
587  ORptFilter & rImport(static_cast<ORptFilter&>(GetImport()));
588  if (nElement == XML_ELEMENT(OFFICE, XML_REPORT) || nElement == XML_ELEMENT(OOO, XML_REPORT))
589  {
591  const SvXMLStylesContext* pAutoStyles = rImport.GetAutoStyles();
592  if (pAutoStyles)
593  {
594  XMLPropStyleContext* pAutoStyle = const_cast<XMLPropStyleContext*>(dynamic_cast<const XMLPropStyleContext *>(pAutoStyles->FindStyleChildContext(XmlStyleFamily::PAGE_MASTER, "pm1")));
595  if (pAutoStyle)
596  {
597  pAutoStyle->FillPropertySet(rImport.getReportDefinition());
598  }
599  }
600  return new OXMLReport(rImport, xAttrList, rImport.getReportDefinition());
601  }
602  return nullptr;
603 }
604 
605 namespace {
606 
607 class RptXMLDocumentContentContext : public SvXMLImportContext
608 {
609 public:
610  RptXMLDocumentContentContext(SvXMLImport & rImport)
611  : SvXMLImportContext(rImport)
612  {
613  }
614 
615  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
616  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override
617  {
618  ORptFilter & rImport(static_cast<ORptFilter&>(GetImport()));
619  switch (nElement)
620  {
621  case XML_ELEMENT(OFFICE, XML_BODY):
622  return new RptXMLDocumentBodyContext(rImport);
623  case XML_ELEMENT(OFFICE, XML_FONT_FACE_DECLS):
624  rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
625  return rImport.CreateFontDeclsContext();
626  case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES):
627  rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
628  return rImport.CreateStylesContext(true);
629  }
630  return nullptr;
631  }
632 };
633 
634 }
635 
637  const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
638 {
639  SvXMLImportContext *pContext = nullptr;
640 
641  switch (nElement)
642  {
645  pContext = CreateMetaContext( nElement );
646  break;
648  pContext = new RptXMLDocumentContentContext(*this);
649  break;
651  pContext = new RptXMLDocumentStylesContext(*this);
652  break;
655  pContext = new RptXMLDocumentSettingsContext(*this);
656  break;
657  }
658  return pContext;
659 }
660 
662 {
663  SvXMLImportContext* pContext = bIsAutoStyle ? GetAutoStyles() : GetStyles();
664  if ( !pContext )
665  {
666  pContext = new OReportStylesContext(*this, bIsAutoStyle);
667  if (bIsAutoStyle)
668  SetAutoStyles(static_cast<SvXMLStylesContext*>(pContext));
669  else
670  SetStyles(static_cast<SvXMLStylesContext*>(pContext));
671  }
672  return pContext;
673 }
674 
676 {
677  XMLFontStylesContext *pFSContext =
678  new XMLFontStylesContext( *this, osl_getThreadTextEncoding() );
679  SetFontDecls( pFSContext );
680  return pFSContext;
681 }
682 
684 {
685  return new XMLShapeImportHelper( *this,GetModel() );
686 }
687 
689 {
690  if( GetStyles() )
691  GetStyles()->FinishStyles( true );
692 }
693 
694 const OUString& ORptFilter::convertFormula(const OUString& _sFormula)
695 {
696  return _sFormula;
697 }
698 
700 {
701  m_xReportDefinition.set(GetModel(),UNO_QUERY_THROW);
703  OSL_ENSURE(m_pReportModel,"Report model is NULL!");
704 
706 }
707 
709 {
710  OSL_ENSURE( GetModel().is(), "model missing; maybe startDocument wasn't called?" );
711  if( !GetModel().is() )
712  return;
713 
714  // this method will modify the document directly -> lock SolarMutex
715  SolarMutexGuard aGuard;
716  // Clear the shape import to sort the shapes (and not in the
717  // destructor that might be called after the import has finished
718  // for Java filters.
719  if( HasShapeImport() )
721 
722  // delegate to parent: takes care of error handling
724 }
725 
726 void ORptFilter::removeFunction(const OUString& _sFunctionName)
727 {
728  m_aFunctions.erase(_sFunctionName);
729 }
730 
731 void ORptFilter::insertFunction(const css::uno::Reference< css::report::XFunction > & _xFunction)
732 {
733  m_aFunctions.emplace(_xFunction->getName(),_xFunction);
734 }
735 
736 SvXMLImportContext* ORptFilter::CreateMetaContext(const sal_Int32 /*nElement*/)
737 {
738  SvXMLImportContext* pContext = nullptr;
739 
740  if ( getImportFlags() & SvXMLImportFlags::META )
741  {
742  uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(), uno::UNO_QUERY_THROW);
743  pContext = new SvXMLMetaDocumentContext(*this, xDPS->getDocumentProperties());
744  }
745  return pContext;
746 }
747 
749 {
750  bool bOldFormat = true;
751  uno::Reference<beans::XPropertySet> xProp = getImportInfo();
752  if ( xProp.is() )
753  {
754  static constexpr OUStringLiteral s_sOld = u"OldFormat";
755  if ( xProp->getPropertySetInfo()->hasPropertyByName(s_sOld))
756  {
757  xProp->getPropertyValue(s_sOld) >>= bOldFormat;
758  }
759  }
760  return bOldFormat;
761 }
762 
763 
764 }// rptxml
765 
766 
767 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool is() const
static const OUString & PROP_DOCUMENTBASEURL()
void SetStyles(SvXMLStylesContext *pStyles)
void ClearShapeImport()
XML_DOCUMENT_META
XML_DOCUMENT_STYLES
const Reference< XReportDefinition > & getReportDefinition() const
Definition: xmlfilter.hxx:92
static const XMLPropertyMapEntry * GetColumnStyleProps()
Definition: xmlHelper.cxx:176
#define ERRCODE_SFX_WRONGPASSWORD
void EnterWait()
SvXMLImport & GetImport()
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32, const css::uno::Reference< css::xml::sax::XFastAttributeList > &) override
Definition: xmlfilter.cxx:583
static const XMLPropertyMapEntry * GetRowStyleProps()
Definition: xmlHelper.cxx:165
SvXMLNamespaceMap & GetNamespaceMap()
void SetXMLMeasureUnit(sal_Int16 const eXMLMeasureUnit)
Reference< XReportDefinition > m_xReportDefinition
Definition: xmlfilter.hxx:66
virtual void SAL_CALL startDocument() override
Definition: xmlfilter.cxx:699
void SetFontDecls(XMLFontStylesContext *pFontDecls)
std::shared_ptr< rptui::OReportModel > m_pReportModel
Definition: xmlfilter.hxx:67
void SetCoreMeasureUnit(sal_Int16 const eCoreMeasureUnit)
SvXMLImportFlags
virtual ~ORptFilter() noexcept override
Definition: xmlfilter.cxx:316
rtl::Reference< XMLPropertyHandlerFactory > m_xPropHdlFactory
Definition: xmlfilter.hxx:61
static const OUString & convertFormula(const OUString &_sFormula)
Definition: xmlfilter.cxx:694
XML_DOCUMENT_SETTINGS
SvXMLImportContext * CreateFontDeclsContext()
Definition: xmlfilter.cxx:675
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_XMLOasisContentImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Imports only content.
Definition: xmlfilter.cxx:260
SvXMLStylesContext * GetStyles()
SvXMLImportContext * CreateStylesContext(bool bIsAutoStyle)
Definition: xmlfilter.cxx:661
bool HasShapeImport() const
void Increment(sal_Int32 nInc=1)
#define TOOLS_WARN_EXCEPTION(area, stream)
ORptFilter(const Reference< XComponentContext > &_rxContext, OUString const &rImplementationName, SvXMLImportFlags nImportFlags)
Definition: xmlfilter.cxx:296
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_ORptStylesImportHelper_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Imports only styles.
Definition: xmlfilter.cxx:273
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
virtual void SAL_CALL endDocument() override
Definition: xmlfilter.cxx:708
#define SERVICE_STYLESIMPORTER
Definition: strings.hxx:278
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
void insertFunction(const css::uno::Reference< css::report::XFunction > &_xFunction)
inserts a new function
Definition: xmlfilter.cxx:731
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
bool isOldFormat() const
Definition: xmlfilter.cxx:748
float u
unsigned char sal_Bool
rtl::Reference< XMLPropertySetMapper > m_xRowStylesPropertySetMapper
Definition: xmlfilter.hxx:64
ProgressBarHelper * GetProgressBarHelper()
virtual SvXMLImportContext * CreateFastContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlfilter.cxx:636
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_ORptImportHelper_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Imports only settings.
Definition: xmlfilter.cxx:247
css::uno::Type const & get()
static rtl::Reference< XMLPropertySetMapper > GetCellStylePropertyMap(bool _bOldFormat, bool bForExport)
Definition: xmlHelper.cxx:107
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_OReportFilter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlfilter.cxx:321
#define SERVICE_SETTINGSIMPORTER
Definition: strings.hxx:277
#define ERRCODE_IO_BROKENPACKAGE
XML_N_RPT_OASIS
static std::shared_ptr< rptui::OReportModel > getSdrModel(const css::uno::Reference< css::report::XReportDefinition > &_xReportDefinition)
virtual void SAL_CALL startDocument() override
static vcl::Window * GetFocusWindow()
rtl::Reference< XMLPropertySetMapper > m_xColumnStylesPropertySetMapper
Definition: xmlfilter.hxx:63
css::uno::Reference< css::embed::XStorage > GetStorage(bool bCreateTempFile=true)
css::uno::Reference< css::uno::XComponentContext > const & GetComponentContext() const
XML_DOCUMENT_CONTENT
SvXMLImportFlags getImportFlags() const
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
constexpr sal_uInt16 XML_NAMESPACE_REPORT
static ErrCode ReadThroughComponent(const uno::Reference< XInputStream > &xInputStream, const uno::Reference< XComponent > &xModelComponent, const uno::Reference< XComponentContext > &rContext, const uno::Reference< XFastParser > &rFastParser)
read a component (file + filter version)
Definition: xmlfilter.cxx:111
#define XML_ELEMENT(prefix, name)
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
const SvXMLUnitConverter & GetMM100UnitConverter() const
bool IsWarning() const
#define PROGRESS_BAR_STEP
Definition: xmlEnums.hxx:22
const css::uno::Reference< css::frame::XModel > & GetModel() const
Sequence< sal_Int8 > aSeq
void SetAutoStyles(SvXMLStylesContext *pAutoStyles)
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
const css::uno::Reference< css::beans::XPropertySet > & getImportInfo() const
XML_REPORT
Reference< XModel > xModel
TGroupFunctionMap m_aFunctions
Definition: xmlfilter.hxx:59
bool implImport(const Sequence< PropertyValue > &rDescriptor)
Definition: xmlfilter.cxx:346
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_ORptMetaImportHelper_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Imports only meta data.
Definition: xmlfilter.cxx:287
void removeFunction(const OUString &_sFunctionName)
Definition: xmlfilter.cxx:726
void LeaveWait()
virtual XMLShapeImportHelper * CreateShapeImport() override
Definition: xmlfilter.cxx:683
SvXMLStylesContext * GetAutoStyles()
SvXMLImportContext * CreateMetaContext(const sal_Int32 nElement)
Definition: xmlfilter.cxx:736
#define SERVICE_METAIMPORTER
Definition: strings.hxx:281
virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue > &rDescriptor) override
Definition: xmlfilter.cxx:329
void FinishStyles(bool bOverwrite)
#define SERVICE_CONTENTIMPORTER
Definition: strings.hxx:279
virtual void SAL_CALL endDocument() override
constexpr OUStringLiteral sHierarchicalDocumentName
rtl::Reference< XMLPropertySetMapper > m_xCellStylesPropertySetMapper
Definition: xmlfilter.hxx:62
XML_N_RPT
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo