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 )
182  // TODO/LATER: better error handling
183  return ErrCode(1);
184 
185  uno::Reference< io::XStream > xDocStream;
186 
187  try
188  {
189  // open stream (and set parser input)
190  OUString sStreamName = OUString::createFromAscii(pStreamName);
191  if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) )
192  {
193  // stream name not found! return immediately with OK signal
194  return ERRCODE_NONE;
195  }
196 
197  // get input stream
198  xDocStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
199  }
200  catch (const packages::WrongPasswordException&)
201  {
203  }
204  catch (const uno::Exception&)
205  {
206  return ErrCode(1); // TODO/LATER: error handling
207  }
208 
209  sal_Int32 nArgs = 0;
210  if (rxGraphicStorageHandler.is())
211  nArgs++;
212  if( _xEmbeddedObjectResolver.is())
213  nArgs++;
214  if ( _xProp.is() )
215  nArgs++;
216 
217  uno::Sequence< uno::Any > aFilterCompArgs( nArgs );
218  auto aFilterCompArgsRange = asNonConstRange(aFilterCompArgs);
219 
220  nArgs = 0;
221  if (rxGraphicStorageHandler.is())
222  aFilterCompArgsRange[nArgs++] <<= rxGraphicStorageHandler;
223  if( _xEmbeddedObjectResolver.is())
224  aFilterCompArgsRange[ nArgs++ ] <<= _xEmbeddedObjectResolver;
225  if ( _xProp.is() )
226  aFilterCompArgsRange[ nArgs++ ] <<= _xProp;
227 
228  // the underlying SvXMLImport implements XFastParser, XImporter, XFastDocumentHandler
229  Reference< XFastParser > xFastParser(
230  rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(_sFilterName, aFilterCompArgs, rxContext),
231  uno::UNO_QUERY_THROW );
232  uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream();
233  // read from the stream
234  return ReadThroughComponent( xInputStream
235  ,xModelComponent
236  ,rxContext
237  ,xFastParser );
238 }
239 
240 
245 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
247  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
248 {
249  return cppu::acquire(new ORptFilter(context,
251  SvXMLImportFlags::SETTINGS ));
252 }
253 
258 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
260  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
261 {
262  return cppu::acquire(new ORptFilter(context,
264  SvXMLImportFlags::AUTOSTYLES | SvXMLImportFlags::CONTENT | SvXMLImportFlags::SCRIPTS | SvXMLImportFlags::FONTDECLS ));
265 }
266 
271 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
273  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
274 {
275  return cppu::acquire(new ORptFilter(context,
277  SvXMLImportFlags::STYLES | SvXMLImportFlags::MASTERSTYLES | SvXMLImportFlags::AUTOSTYLES |
278  SvXMLImportFlags::FONTDECLS ));
279 }
280 
285 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
287  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
288 {
289  return cppu::acquire(new ORptFilter(context,
291  SvXMLImportFlags::META ));
292 }
293 
294 
295 ORptFilter::ORptFilter( const uno::Reference< XComponentContext >& _rxContext, OUString const & rImplementationName, SvXMLImportFlags nImportFlags )
296  :SvXMLImport(_rxContext, rImplementationName, nImportFlags)
297 {
298  GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_100TH);
299  GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM);
300  GetNamespaceMap().Add( "_report",
303 
304  GetNamespaceMap().Add( "__report",
307 
312 }
313 
314 
316 {
317 }
318 
319 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
321  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
322 {
323  return cppu::acquire(new ORptFilter(context,
324  "com.sun.star.comp.report.OReportFilter",
325  SvXMLImportFlags::ALL ));
326 }
327 
328 sal_Bool SAL_CALL ORptFilter::filter( const Sequence< PropertyValue >& rDescriptor )
329 {
330  vcl::Window* pFocusWindow = Application::GetFocusWindow();
331  bool bRet = false;
332 
333  if( pFocusWindow )
334  pFocusWindow->EnterWait();
335 
336  if ( GetModel().is() )
337  bRet = implImport( rDescriptor );
338 
339  if ( pFocusWindow )
340  pFocusWindow->LeaveWait();
341 
342  return bRet;
343 }
344 
345 bool ORptFilter::implImport( const Sequence< PropertyValue >& rDescriptor )
346 {
347  OUString sFileName;
348  uno::Reference< embed::XStorage > xStorage;
349  uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier;
350 
351  for(const PropertyValue& rProp : rDescriptor)
352  {
353  if ( rProp.Name == "FileName" )
354  rProp.Value >>= sFileName;
355  else if ( rProp.Name == "Storage" )
356  rProp.Value >>= xStorage;
357  else if ( rProp.Name == "ComponentData" )
358  {
359  Sequence< PropertyValue > aComponent;
360  rProp.Value >>= aComponent;
361  const PropertyValue* pComponentIter = aComponent.getConstArray();
362  const PropertyValue* pComponentEnd = pComponentIter + aComponent.getLength();
363  pComponentIter = std::find_if(pComponentIter, pComponentEnd,
364  [](const PropertyValue& rComponent) { return rComponent.Name == "ActiveConnection"; });
365  if (pComponentIter != pComponentEnd)
366  {
367  uno::Reference<sdbc::XConnection> xCon(pComponentIter->Value, uno::UNO_QUERY);
368  xNumberFormatsSupplier = ::dbtools::getNumberFormats(xCon);
369  }
370  }
371  }
372 
373  if ( !sFileName.isEmpty() )
374  {
375  tools::SvRef<SfxMedium> pMedium = new SfxMedium(
376  sFileName, ( StreamMode::READ | StreamMode::NOCREATE ) );
377 
378  if( pMedium.is() )
379  {
380  try
381  {
382  xStorage = pMedium->GetStorage();
383  }
384  catch (const Exception&)
385  {
386  }
387  }
388  }
389  bool bRet = xStorage.is();
390  if ( bRet )
391  {
392  m_xReportDefinition.set(GetModel(),UNO_QUERY_THROW);
393 
394 #if OSL_DEBUG_LEVEL > 1
395  uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
396  uno::Sequence< OUString> aSeq = xAccess->getElementNames();
397  const OUString* pDebugIter = aSeq.getConstArray();
398  const OUString* pDebugEnd = pDebugIter + aSeq.getLength();
399  for(;pDebugIter != pDebugEnd;++pDebugIter)
400  {
401  (void)*pDebugIter;
402  }
403 #endif
404 
405  uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
406  uno::Reference<document::XEmbeddedObjectResolver> xEmbeddedObjectResolver;
407  uno::Reference< uno::XComponentContext > xContext = GetComponentContext();
408 
409  uno::Sequence<uno::Any> aArgs{ uno::Any(xStorage) };
410  xGraphicStorageHandler.set(
411  xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.Svx.GraphicImportHelper", aArgs, xContext),
412  uno::UNO_QUERY);
413 
414  uno::Reference< lang::XMultiServiceFactory > xReportServiceFactory( m_xReportDefinition, uno::UNO_QUERY);
415  aArgs.getArray()[0] <<= beans::NamedValue("Storage", uno::Any(xStorage));
416  xEmbeddedObjectResolver.set( xReportServiceFactory->createInstanceWithArguments("com.sun.star.document.ImportEmbeddedObjectResolver",aArgs) , uno::UNO_QUERY);
417 
418  static constexpr OUStringLiteral s_sOld = u"OldFormat";
419  static comphelper::PropertyMapEntry const pMap[] =
420  {
421  { OUString("OldFormat") , 1, cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::BOUND, 0 },
422  { OUString("StreamName"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
423  { OUString("PrivateData"),0, cppu::UnoType<XInterface>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
424  { OUString("BaseURI"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
425  { OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
426  { OUString(), 0, css::uno::Type(), 0, 0 }
427  };
428  utl::MediaDescriptor aDescriptor(rDescriptor);
429  uno::Reference<beans::XPropertySet> xProp = comphelper::GenericPropertySet_CreateInstance(new comphelper::PropertySetInfo(pMap));
430  const OUString sVal( aDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_DOCUMENTBASEURL, OUString()) );
431  assert(!sVal.isEmpty()); // needed for relative URLs
432  xProp->setPropertyValue("BaseURI", uno::Any(sVal));
433  const OUString sHierarchicalDocumentName( aDescriptor.getUnpackedValueOrDefault("HierarchicalDocumentName",OUString()) );
434  xProp->setPropertyValue("StreamRelPath", uno::Any(sHierarchicalDocumentName));
435 
436  uno::Reference<XComponent> xModel = GetModel();
437  static constexpr OUStringLiteral s_sMeta = u"meta.xml";
438  static constexpr OUStringLiteral s_sStreamName = u"StreamName";
439  xProp->setPropertyValue(s_sStreamName, uno::Any(OUString(s_sMeta)));
440  ErrCode nRet = ReadThroughComponent( xStorage
441  ,xModel
442  ,"meta.xml"
444  ,xGraphicStorageHandler
445  ,xEmbeddedObjectResolver
447  ,xProp
448  );
449 
450 
451  try
452  {
453  xProp->setPropertyValue(s_sOld,uno::Any(!(xStorage->hasByName(s_sMeta) || xStorage->isStreamElement( s_sMeta ))));
454  }
455  catch (const uno::Exception&)
456  {
457  xProp->setPropertyValue(s_sOld,uno::Any(true));
458  }
459 
460  if ( nRet == ERRCODE_NONE )
461  {
462  xProp->setPropertyValue(s_sStreamName, uno::Any(OUString("settings.xml")));
463  nRet = ReadThroughComponent( xStorage
464  ,xModel
465  ,"settings.xml"
467  ,xGraphicStorageHandler
468  ,xEmbeddedObjectResolver
470  ,xProp
471  );
472  }
473  if ( nRet == ERRCODE_NONE )
474  {
475  xProp->setPropertyValue(s_sStreamName, uno::Any(OUString("styles.xml")));
476  nRet = ReadThroughComponent(xStorage
477  ,xModel
478  ,"styles.xml"
480  ,xGraphicStorageHandler
481  ,xEmbeddedObjectResolver
483  ,xProp);
484  }
485 
486  if ( nRet == ERRCODE_NONE )
487  {
488  xProp->setPropertyValue(s_sStreamName, uno::Any(OUString("content.xml")));
489  nRet = ReadThroughComponent( xStorage
490  ,xModel
491  ,"content.xml"
493  ,xGraphicStorageHandler
494  ,xEmbeddedObjectResolver
496  ,xProp
497  );
498  }
499 
500 
501  bRet = nRet == ERRCODE_NONE;
502 
503  if ( bRet )
504  {
505  m_xReportDefinition->setModified(false);
506  }
507  else
508  {
509  if( nRet == ERRCODE_IO_BROKENPACKAGE && xStorage.is() )
510  ; // TODO/LATER: no way to transport the error outside from the filter!
511  else
512  {
513  // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way!
515  if( nRet.IsWarning() )
516  bRet = true;
517  }
518  }
519  }
520 
521  return bRet;
522 }
523 
524 namespace {
525 
526 class RptXMLDocumentSettingsContext : public SvXMLImportContext
527 {
528 public:
529  RptXMLDocumentSettingsContext(SvXMLImport & rImport)
530  : SvXMLImportContext(rImport)
531  {
532  }
533 
534  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
535  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override
536  {
537  if (nElement == XML_ELEMENT(OFFICE, XML_SETTINGS))
538  {
539  return new XMLDocumentSettingsContext(GetImport());
540  }
541  return nullptr;
542  }
543 };
544 
545 class RptXMLDocumentStylesContext : public SvXMLImportContext
546 {
547 public:
548  RptXMLDocumentStylesContext(SvXMLImport & rImport)
549  : SvXMLImportContext(rImport)
550  {
551  }
552 
553  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
554  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override
555  {
556  ORptFilter & rImport(static_cast<ORptFilter&>(GetImport()));
557  switch (nElement)
558  {
559  case XML_ELEMENT(OFFICE, XML_FONT_FACE_DECLS):
560  rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
561  return rImport.CreateFontDeclsContext();
562  case XML_ELEMENT(OFFICE, XML_MASTER_STYLES):
563  {
564  SvXMLStylesContext* pStyleContext = new RptMLMasterStylesContext_Impl(rImport);
565  rImport.SetMasterStyles(pStyleContext);
566  return pStyleContext;
567  }
568  case XML_ELEMENT(OFFICE, XML_STYLES):
569  rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
570  return rImport.CreateStylesContext(false);
571  case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES):
572  // don't use the autostyles from the styles-document for the progress
573  return rImport.CreateStylesContext(true);
574  }
575  return nullptr;
576  }
577 };
578 
579 }
580 
581 css::uno::Reference< css::xml::sax::XFastContextHandler > RptXMLDocumentBodyContext::createFastChildContext(
582  sal_Int32 nElement,
583  const uno::Reference<xml::sax::XFastAttributeList> & xAttrList)
584 {
585  ORptFilter & rImport(static_cast<ORptFilter&>(GetImport()));
586  if (nElement == XML_ELEMENT(OFFICE, XML_REPORT) || nElement == XML_ELEMENT(OOO, XML_REPORT))
587  {
589  const SvXMLStylesContext* pAutoStyles = rImport.GetAutoStyles();
590  if (pAutoStyles)
591  {
592  XMLPropStyleContext* pAutoStyle = const_cast<XMLPropStyleContext*>(dynamic_cast<const XMLPropStyleContext *>(pAutoStyles->FindStyleChildContext(XmlStyleFamily::PAGE_MASTER, "pm1")));
593  if (pAutoStyle)
594  {
595  pAutoStyle->FillPropertySet(rImport.getReportDefinition());
596  }
597  }
598  return new OXMLReport(rImport, xAttrList, rImport.getReportDefinition());
599  }
600  return nullptr;
601 }
602 
603 namespace {
604 
605 class RptXMLDocumentContentContext : public SvXMLImportContext
606 {
607 public:
608  RptXMLDocumentContentContext(SvXMLImport & rImport)
609  : SvXMLImportContext(rImport)
610  {
611  }
612 
613  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
614  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override
615  {
616  ORptFilter & rImport(static_cast<ORptFilter&>(GetImport()));
617  switch (nElement)
618  {
619  case XML_ELEMENT(OFFICE, XML_BODY):
620  return new RptXMLDocumentBodyContext(rImport);
621  case XML_ELEMENT(OFFICE, XML_FONT_FACE_DECLS):
622  rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
623  return rImport.CreateFontDeclsContext();
624  case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES):
625  rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
626  return rImport.CreateStylesContext(true);
627  }
628  return nullptr;
629  }
630 };
631 
632 }
633 
635  const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
636 {
637  SvXMLImportContext *pContext = nullptr;
638 
639  switch (nElement)
640  {
643  pContext = CreateMetaContext( nElement );
644  break;
646  pContext = new RptXMLDocumentContentContext(*this);
647  break;
649  pContext = new RptXMLDocumentStylesContext(*this);
650  break;
653  pContext = new RptXMLDocumentSettingsContext(*this);
654  break;
655  }
656  return pContext;
657 }
658 
660 {
661  SvXMLImportContext* pContext = bIsAutoStyle ? GetAutoStyles() : GetStyles();
662  if ( !pContext )
663  {
664  pContext = new OReportStylesContext(*this, bIsAutoStyle);
665  if (bIsAutoStyle)
666  SetAutoStyles(static_cast<SvXMLStylesContext*>(pContext));
667  else
668  SetStyles(static_cast<SvXMLStylesContext*>(pContext));
669  }
670  return pContext;
671 }
672 
674 {
675  XMLFontStylesContext *pFSContext =
676  new XMLFontStylesContext( *this, osl_getThreadTextEncoding() );
677  SetFontDecls( pFSContext );
678  return pFSContext;
679 }
680 
682 {
683  return new XMLShapeImportHelper( *this,GetModel() );
684 }
685 
687 {
688  if( GetStyles() )
689  GetStyles()->FinishStyles( true );
690 }
691 
692 const OUString& ORptFilter::convertFormula(const OUString& _sFormula)
693 {
694  return _sFormula;
695 }
696 
698 {
699  m_xReportDefinition.set(GetModel(),UNO_QUERY_THROW);
701  OSL_ENSURE(m_pReportModel,"Report model is NULL!");
702 
704 }
705 
707 {
708  OSL_ENSURE( GetModel().is(), "model missing; maybe startDocument wasn't called?" );
709  if( !GetModel().is() )
710  return;
711 
712  // this method will modify the document directly -> lock SolarMutex
713  SolarMutexGuard aGuard;
714  // Clear the shape import to sort the shapes (and not in the
715  // destructor that might be called after the import has finished
716  // for Java filters.
717  if( HasShapeImport() )
719 
720  // delegate to parent: takes care of error handling
722 }
723 
724 void ORptFilter::removeFunction(const OUString& _sFunctionName)
725 {
726  m_aFunctions.erase(_sFunctionName);
727 }
728 
729 void ORptFilter::insertFunction(const css::uno::Reference< css::report::XFunction > & _xFunction)
730 {
731  m_aFunctions.emplace(_xFunction->getName(),_xFunction);
732 }
733 
734 SvXMLImportContext* ORptFilter::CreateMetaContext(const sal_Int32 /*nElement*/)
735 {
736  SvXMLImportContext* pContext = nullptr;
737 
738  if ( getImportFlags() & SvXMLImportFlags::META )
739  {
740  uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(), uno::UNO_QUERY_THROW);
741  pContext = new SvXMLMetaDocumentContext(*this, xDPS->getDocumentProperties());
742  }
743  return pContext;
744 }
745 
747 {
748  bool bOldFormat = true;
749  uno::Reference<beans::XPropertySet> xProp = getImportInfo();
750  if ( xProp.is() )
751  {
752  static constexpr OUStringLiteral s_sOld = u"OldFormat";
753  if ( xProp->getPropertySetInfo()->hasPropertyByName(s_sOld))
754  {
755  xProp->getPropertyValue(s_sOld) >>= bOldFormat;
756  }
757  }
758  return bOldFormat;
759 }
760 
761 
762 }// rptxml
763 
764 
765 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool is() const
XML_DOCUMENT_CONTENT
static constexpr OUStringLiteral PROP_DOCUMENTBASEURL
void SetStyles(SvXMLStylesContext *pStyles)
void ClearShapeImport()
const Reference< XReportDefinition > & getReportDefinition() const
Definition: xmlfilter.hxx:92
static const XMLPropertyMapEntry * GetColumnStyleProps()
Definition: xmlHelper.cxx:175
#define ERRCODE_SFX_WRONGPASSWORD
void EnterWait()
SvXMLImport & GetImport()
XML_DOCUMENT_STYLES
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:581
static const XMLPropertyMapEntry * GetRowStyleProps()
Definition: xmlHelper.cxx:164
SvXMLNamespaceMap & GetNamespaceMap()
void SetXMLMeasureUnit(sal_Int16 const eXMLMeasureUnit)
constexpr OUStringLiteral SERVICE_STYLESIMPORTER
Definition: strings.hxx:271
Reference< XReportDefinition > m_xReportDefinition
Definition: xmlfilter.hxx:66
virtual void SAL_CALL startDocument() override
Definition: xmlfilter.cxx:697
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:315
XML_REPORT
rtl::Reference< XMLPropertyHandlerFactory > m_xPropHdlFactory
Definition: xmlfilter.hxx:61
XML_N_RPT
static const OUString & convertFormula(const OUString &_sFormula)
Definition: xmlfilter.cxx:692
SvXMLImportContext * CreateFontDeclsContext()
Definition: xmlfilter.cxx:673
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:259
SvXMLStylesContext * GetStyles()
SvXMLImportContext * CreateStylesContext(bool bIsAutoStyle)
Definition: xmlfilter.cxx:659
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:295
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:272
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
virtual void SAL_CALL endDocument() override
Definition: xmlfilter.cxx:706
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:729
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
bool isOldFormat() const
Definition: xmlfilter.cxx:746
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:634
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:246
css::uno::Type const & get()
static rtl::Reference< XMLPropertySetMapper > GetCellStylePropertyMap(bool _bOldFormat, bool bForExport)
Definition: xmlHelper.cxx:106
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_OReportFilter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlfilter.cxx:320
#define ERRCODE_IO_BROKENPACKAGE
static std::shared_ptr< rptui::OReportModel > getSdrModel(const css::uno::Reference< css::report::XReportDefinition > &_xReportDefinition)
virtual void SAL_CALL startDocument() override
constexpr OUStringLiteral SERVICE_CONTENTIMPORTER
Definition: strings.hxx:272
XML_DOCUMENT_META
static vcl::Window * GetFocusWindow()
XML_N_RPT_OASIS
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
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
Reference< XModel > xModel
constexpr OUStringLiteral SERVICE_SETTINGSIMPORTER
Definition: strings.hxx:270
TGroupFunctionMap m_aFunctions
Definition: xmlfilter.hxx:59
bool implImport(const Sequence< PropertyValue > &rDescriptor)
Definition: xmlfilter.cxx:345
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:286
void removeFunction(const OUString &_sFunctionName)
Definition: xmlfilter.cxx:724
void LeaveWait()
virtual XMLShapeImportHelper * CreateShapeImport() override
Definition: xmlfilter.cxx:681
SvXMLStylesContext * GetAutoStyles()
SvXMLImportContext * CreateMetaContext(const sal_Int32 nElement)
Definition: xmlfilter.cxx:734
XML_DOCUMENT_SETTINGS
virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue > &rDescriptor) override
Definition: xmlfilter.cxx:328
void FinishStyles(bool bOverwrite)
virtual void SAL_CALL endDocument() override
constexpr OUStringLiteral sHierarchicalDocumentName
rtl::Reference< XMLPropertySetMapper > m_xCellStylesPropertySetMapper
Definition: xmlfilter.hxx:62
constexpr OUStringLiteral SERVICE_METAIMPORTER
Definition: strings.hxx:273
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo