21#include <com/sun/star/container/XContentEnumerationAccess.hpp>
22#include <com/sun/star/frame/XModel.hpp>
23#include <com/sun/star/lang/XComponent.hpp>
24#include <com/sun/star/lang/XSingleComponentFactory.hpp>
25#include <com/sun/star/sheet/XFilterFormulaParser.hpp>
28#include <document.hxx>
38class ScParserFactoryMap
41 explicit ScParserFactoryMap();
43 Reference< XFormulaParser > createFormulaParser(
44 const Reference< XComponent >& rxComponent,
45 const OUString& rNamespace );
48 typedef std::unordered_map<
49 OUString, Reference< XSingleComponentFactory > >
FactoryMap;
55ScParserFactoryMap::ScParserFactoryMap() :
64 Reference< XContentEnumerationAccess > xFactoryEA(
mxContext->getServiceManager(), UNO_QUERY_THROW );
65 Reference< XEnumeration > xEnum( xFactoryEA->createContentEnumeration(
"com.sun.star.sheet.FilterFormulaParser" ), UNO_SET_THROW );
66 while( xEnum->hasMoreElements() )
try
69 Reference< XSingleComponentFactory > xCompFactory( xEnum->nextElement(), UNO_QUERY_THROW );
70 Reference< XFilterFormulaParser > xParser( xCompFactory->createInstanceWithContext( mxContext ), UNO_QUERY_THROW );
73 OUString aNamespace = xParser->getSupportedNamespace();
74 if( !aNamespace.isEmpty() )
75 maFactories[ aNamespace ] = xCompFactory;
86Reference< XFormulaParser > ScParserFactoryMap::createFormulaParser(
87 const Reference< XComponent >& rxComponent,
const OUString& rNamespace )
89 Reference< XFormulaParser > xParser;
90 FactoryMap::const_iterator aIt = maFactories.find( rNamespace );
91 if( aIt != maFactories.end() )
try
93 Sequence< Any > aArgs{
Any(rxComponent) };
94 xParser.set( aIt->second->createInstanceWithArgumentsAndContext( aArgs, mxContext ), UNO_QUERY_THROW );
121 ParserMap::iterator aIt =
maParsers.find( rNamespace );
126 Reference< XFormulaParser >& rxParser =
maParsers[ rNamespace ];
131 static ScParserFactoryMap theScParserFactoryMap;
133 Reference< XComponent > xComponent( pDocShell->GetModel(), UNO_QUERY_THROW );
134 rxParser = theScParserFactoryMap.createFormulaParser( xComponent, rNamespace );
::std::map< OUString, std::unique_ptr< XMLEventContextFactory > > FactoryMap
SfxObjectShell * GetDocumentShell() const
Reference< XComponentContext > getProcessComponentContext()