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>
43#include <com/sun/star/xml/sax/InputSource.hpp>
44#include <com/sun/star/beans/PropertyAttribute.hpp>
52#include <com/sun/star/io/XInputStream.hpp>
67using ::com::sun::star::uno::Reference;
82class RptMLMasterStylesContext_Impl:
90 RptMLMasterStylesContext_Impl( ORptFilter& rImport );
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;
99RptMLMasterStylesContext_Impl::RptMLMasterStylesContext_Impl( ORptFilter& rImport ) :
104void RptMLMasterStylesContext_Impl::endFastElement(sal_Int32 )
106 FinishStyles(
true );
107 GetImport().FinishStyles();
112 const uno::Reference<XInputStream>& xInputStream,
113 const uno::Reference<XComponent>& xModelComponent,
114 const uno::Reference<XComponentContext> & rContext,
115 const uno::Reference<XFastParser>& rFastParser )
117 OSL_ENSURE(xInputStream.is(),
"input stream missing");
118 OSL_ENSURE(xModelComponent.is(),
"document missing");
119 OSL_ENSURE(rContext.is(),
"factory missing");
122 InputSource aParserInput;
123 aParserInput.aInputStream = xInputStream;
126 SAL_WARN_IF( !rFastParser.is(),
"reportdesign",
"Can't instantiate filter component." );
127 if( !rFastParser.is() )
131 uno::Reference < XImporter > xImporter( rFastParser, UNO_QUERY );
132 xImporter->setTargetDocument( xModelComponent );
137 rFastParser->parseStream( aParserInput );
139 catch (
const SAXParseException&)
144 catch (
const SAXException&)
148 catch (
const packages::zip::ZipIOException&)
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)
178 OSL_ENSURE( xStorage.is(),
"Need storage!");
179 OSL_ENSURE(
nullptr != pStreamName,
"Please, please, give me a name!");
185 uno::Reference< io::XStream > xDocStream;
190 OUString sStreamName = OUString::createFromAscii(pStreamName);
191 if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) )
198 xDocStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
200 catch (
const packages::WrongPasswordException&)
204 catch (
const uno::Exception&)
210 if (rxGraphicStorageHandler.is())
212 if( _xEmbeddedObjectResolver.is())
217 uno::Sequence< uno::Any > aFilterCompArgs( nArgs );
218 auto aFilterCompArgsRange = asNonConstRange(aFilterCompArgs);
221 if (rxGraphicStorageHandler.is())
222 aFilterCompArgsRange[nArgs++] <<= rxGraphicStorageHandler;
223 if( _xEmbeddedObjectResolver.is())
224 aFilterCompArgsRange[ nArgs++ ] <<= _xEmbeddedObjectResolver;
226 aFilterCompArgsRange[ nArgs++ ] <<= _xProp;
229 Reference< XFastParser > xFastParser(
230 rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(_sFilterName, aFilterCompArgs, rxContext),
231 uno::UNO_QUERY_THROW );
232 uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream();
245extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
247 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
251 SvXMLImportFlags::SETTINGS ));
258extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
260 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
264 SvXMLImportFlags::AUTOSTYLES | SvXMLImportFlags::CONTENT | SvXMLImportFlags::SCRIPTS | SvXMLImportFlags::FONTDECLS ));
271extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
273 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
277 SvXMLImportFlags::STYLES | SvXMLImportFlags::MASTERSTYLES | SvXMLImportFlags::AUTOSTYLES |
278 SvXMLImportFlags::FONTDECLS ));
285extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
287 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
291 SvXMLImportFlags::META ));
295ORptFilter::ORptFilter(
const uno::Reference< XComponentContext >& _rxContext, OUString
const & rImplementationName,
SvXMLImportFlags nImportFlags )
296 :SvXMLImport(_rxContext, rImplementationName, nImportFlags)
298 GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_100TH);
299 GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM);
300 GetNamespaceMap().Add(
"_report",
304 GetNamespaceMap().Add(
"__report",
319extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
321 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
324 "com.sun.star.comp.report.OReportFilter",
325 SvXMLImportFlags::ALL ));
336 if ( GetModel().is() )
348 uno::Reference< embed::XStorage > xStorage;
349 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier;
351 for(
const PropertyValue& rProp : rDescriptor)
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" )
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)
367 uno::Reference<sdbc::XConnection> xCon(pComponentIter->Value, uno::UNO_QUERY);
368 xNumberFormatsSupplier = ::dbtools::getNumberFormats(xCon);
373 if ( !sFileName.isEmpty() )
376 sFileName, ( StreamMode::READ | StreamMode::NOCREATE ) );
382 xStorage = pMedium->GetStorage();
389 bool bRet = xStorage.
is();
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)
405 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
406 uno::Reference<document::XEmbeddedObjectResolver> xEmbeddedObjectResolver;
407 uno::Reference< uno::XComponentContext > xContext = GetComponentContext();
409 uno::Sequence<uno::Any> aArgs{
uno::Any(xStorage) };
410 xGraphicStorageHandler.set(
411 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
"com.sun.star.comp.Svx.GraphicImportHelper", aArgs, xContext),
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);
418 static constexpr OUStringLiteral s_sOld =
u"OldFormat";
430 assert(!sVal.isEmpty());
431 xProp->setPropertyValue(
"BaseURI",
uno::Any(sVal));
432 const OUString
sHierarchicalDocumentName( aDescriptor.getUnpackedValueOrDefault(
"HierarchicalDocumentName",OUString()) );
435 uno::Reference<XComponent>
xModel = GetModel();
436 static constexpr OUStringLiteral s_sMeta =
u"meta.xml";
437 static constexpr OUStringLiteral s_sStreamName =
u"StreamName";
438 xProp->setPropertyValue(s_sStreamName,
uno::Any(OUString(s_sMeta)));
442 ,GetComponentContext()
443 ,xGraphicStorageHandler
444 ,xEmbeddedObjectResolver
452 xProp->setPropertyValue(s_sOld,
uno::Any(!(xStorage->hasByName(s_sMeta) || xStorage->isStreamElement( s_sMeta ))));
454 catch (
const uno::Exception&)
456 xProp->setPropertyValue(s_sOld,
uno::Any(
true));
461 xProp->setPropertyValue(s_sStreamName,
uno::Any(OUString(
"settings.xml")));
465 ,GetComponentContext()
466 ,xGraphicStorageHandler
467 ,xEmbeddedObjectResolver
474 xProp->setPropertyValue(s_sStreamName,
uno::Any(OUString(
"styles.xml")));
478 ,GetComponentContext()
479 ,xGraphicStorageHandler
480 ,xEmbeddedObjectResolver
487 xProp->setPropertyValue(s_sStreamName,
uno::Any(OUString(
"content.xml")));
491 ,GetComponentContext()
492 ,xGraphicStorageHandler
493 ,xEmbeddedObjectResolver
528 RptXMLDocumentSettingsContext(SvXMLImport & rImport)
533 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
534 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
override
547 RptXMLDocumentStylesContext(SvXMLImport & rImport)
552 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
553 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
override
555 ORptFilter & rImport(
static_cast<ORptFilter&
>(GetImport()));
560 return rImport.CreateFontDeclsContext();
564 rImport.SetMasterStyles(pStyleContext);
565 return pStyleContext;
569 return rImport.CreateStylesContext(
false);
572 return rImport.CreateStylesContext(true);
582 const uno::Reference<xml::sax::XFastAttributeList> & xAttrList)
607 RptXMLDocumentContentContext(SvXMLImport & rImport)
612 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
613 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
override
615 ORptFilter & rImport(
static_cast<ORptFilter&
>(GetImport()));
619 return new RptXMLDocumentBodyContext(rImport);
622 return rImport.CreateFontDeclsContext();
625 return rImport.CreateStylesContext(
true);
634 const uno::Reference< xml::sax::XFastAttributeList >& )
645 pContext =
new RptXMLDocumentContentContext(*
this);
648 pContext =
new RptXMLDocumentStylesContext(*
this);
652 pContext =
new RptXMLDocumentSettingsContext(*
this);
676 SetFontDecls( pFSContext );
688 GetStyles()->FinishStyles(
true );
702 SvXMLImport::startDocument();
707 OSL_ENSURE( GetModel().is(),
"model missing; maybe startDocument wasn't called?" );
708 if( !GetModel().is() )
716 if( HasShapeImport() )
720 SvXMLImport::endDocument();
737 if ( getImportFlags() & SvXMLImportFlags::META )
739 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(), uno::UNO_QUERY_THROW);
747 bool bOldFormat =
true;
748 uno::Reference<beans::XPropertySet> xProp = getImportInfo();
751 static constexpr OUStringLiteral s_sOld =
u"OldFormat";
752 if ( xProp->getPropertySetInfo()->hasPropertyByName(s_sOld))
754 xProp->getPropertyValue(s_sOld) >>= bOldFormat;
constexpr OUStringLiteral sHierarchicalDocumentName
static vcl::Window * GetFocusWindow()
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
SvXMLImport & GetImport()
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
css::uno::Type const & get()
static std::shared_ptr< rptui::OReportModel > getSdrModel(const css::uno::Reference< css::report::XReportDefinition > &_xReportDefinition)
bool implImport(const Sequence< PropertyValue > &rDescriptor)
void removeFunction(const OUString &_sFunctionName)
virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue > &rDescriptor) override
static const OUString & convertFormula(const OUString &_sFormula)
rtl::Reference< XMLPropertySetMapper > m_xRowStylesPropertySetMapper
std::shared_ptr< rptui::OReportModel > m_pReportModel
rtl::Reference< XMLPropertySetMapper > m_xColumnStylesPropertySetMapper
SvXMLImportContext * CreateMetaContext(const sal_Int32 nElement)
SvXMLImportContext * CreateStylesContext(bool bIsAutoStyle)
SvXMLImportContext * CreateFontDeclsContext()
virtual void SAL_CALL startDocument() override
TGroupFunctionMap m_aFunctions
virtual SvXMLImportContext * CreateFastContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
void insertFunction(const css::uno::Reference< css::report::XFunction > &_xFunction)
inserts a new function
const Reference< XReportDefinition > & getReportDefinition() const
virtual XMLShapeImportHelper * CreateShapeImport() override
rtl::Reference< XMLPropertyHandlerFactory > m_xPropHdlFactory
virtual ~ORptFilter() noexcept override
virtual void SAL_CALL endDocument() override
rtl::Reference< XMLPropertySetMapper > m_xCellStylesPropertySetMapper
Reference< XReportDefinition > m_xReportDefinition
static const XMLPropertyMapEntry * GetColumnStyleProps()
static const XMLPropertyMapEntry * GetRowStyleProps()
static rtl::Reference< XMLPropertySetMapper > GetCellStylePropertyMap(bool _bOldFormat, bool bForExport)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32, const css::uno::Reference< css::xml::sax::XFastAttributeList > &) override
#define TOOLS_WARN_EXCEPTION(area, stream)
#define ERRCODE_IO_BROKENPACKAGE
Sequence< sal_Int8 > aSeq
#define SAL_WARN_IF(condition, area, stream)
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_ORptImportHelper_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Imports only settings.
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.
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_OReportFilter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_ORptStylesImportHelper_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Imports only styles.
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_XMLOasisContentImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Imports only content.
static ErrCode ReadThroughComponent(const uno::Reference< embed::XStorage > &xStorage, const uno::Reference< XComponent > &xModelComponent, const char *pStreamName, const uno::Reference< XComponentContext > &rxContext, const Reference< document::XGraphicStorageHandler > &rxGraphicStorageHandler, const Reference< document::XEmbeddedObjectResolver > &_xEmbeddedObjectResolver, const OUString &_sFilterName, const uno::Reference< beans::XPropertySet > &_xProp)
read a component (storage version)
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)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
#define ERRCODE_SFX_WRONGPASSWORD
constexpr OUStringLiteral SERVICE_STYLESIMPORTER
constexpr OUStringLiteral SERVICE_SETTINGSIMPORTER
constexpr OUStringLiteral SERVICE_METAIMPORTER
constexpr OUStringLiteral SERVICE_CONTENTIMPORTER
Reference< XModel > xModel
#define PROGRESS_BAR_STEP
#define XML_ELEMENT(prefix, name)
constexpr sal_uInt16 XML_NAMESPACE_REPORT