Kaydet (Commit) 4460f213 authored tarafından Noel Grandin's avatar Noel Grandin

fdo#46808, use XComponentContext in SfxLibraryContainer

Change-Id: I6f66fc69a40e2cd2ef2372e0413ff95b6202c5c5
üst 67042f1f
...@@ -218,7 +218,7 @@ class SfxLibraryContainer : public SfxLibraryContainer_BASE, public ::utl::OEven ...@@ -218,7 +218,7 @@ class SfxLibraryContainer : public SfxLibraryContainer_BASE, public ::utl::OEven
sal_Bool mbVBACompat; sal_Bool mbVBACompat;
OUString msProjectName; OUString msProjectName;
protected: protected:
::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess3 > mxSFI; ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess3 > mxSFI;
::com::sun::star::uno::Reference< ::com::sun::star::util::XMacroExpander > mxMacroExpander; ::com::sun::star::uno::Reference< ::com::sun::star::util::XMacroExpander > mxMacroExpander;
::com::sun::star::uno::Reference< ::com::sun::star::util::XStringSubstitution > mxStringSubstitution; ::com::sun::star::uno::Reference< ::com::sun::star::util::XStringSubstitution > mxStringSubstitution;
......
...@@ -87,7 +87,7 @@ SfxDialogLibraryContainer::SfxDialogLibraryContainer( const uno::Reference< embe ...@@ -87,7 +87,7 @@ SfxDialogLibraryContainer::SfxDialogLibraryContainer( const uno::Reference< embe
// Methods to get library instances of the correct type // Methods to get library instances of the correct type
SfxLibrary* SfxDialogLibraryContainer::implCreateLibrary( const OUString& aName ) SfxLibrary* SfxDialogLibraryContainer::implCreateLibrary( const OUString& aName )
{ {
SfxLibrary* pRet = new SfxDialogLibrary( maModifiable, aName, comphelper::getComponentContext(mxMSF), mxSFI, this ); SfxLibrary* pRet = new SfxDialogLibrary( maModifiable, aName, mxContext, mxSFI, this );
return pRet; return pRet;
} }
...@@ -96,7 +96,7 @@ SfxLibrary* SfxDialogLibraryContainer::implCreateLibraryLink ...@@ -96,7 +96,7 @@ SfxLibrary* SfxDialogLibraryContainer::implCreateLibraryLink
const OUString& StorageURL, sal_Bool ReadOnly ) const OUString& StorageURL, sal_Bool ReadOnly )
{ {
SfxLibrary* pRet = new SfxDialogLibrary SfxLibrary* pRet = new SfxDialogLibrary
( maModifiable, aName, comphelper::getComponentContext(mxMSF), mxSFI, aLibInfoFileURL, StorageURL, ReadOnly, this ); ( maModifiable, aName, mxContext, mxSFI, aLibInfoFileURL, StorageURL, ReadOnly, this );
return pRet; return pRet;
} }
...@@ -236,17 +236,17 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e ...@@ -236,17 +236,17 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e
if ( xISP.is() ) if ( xISP.is() )
{ {
Reference< io::XInputStream > xInput( xISP->createInputStream() ); Reference< io::XInputStream > xInput( xISP->createInputStream() );
Reference< XNameContainer > xDialogModel( mxMSF->createInstance Reference< XNameContainer > xDialogModel(
( OUString( "com.sun.star.awt.UnoControlDialogModel" ) ) , UNO_QUERY ); mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext),
Reference< XComponentContext > xContext( comphelper::getComponentContext( mxMSF ) ); UNO_QUERY );
::xmlscript::importDialogModel( xInput, xDialogModel, xContext, mxOwnerDocument ); ::xmlscript::importDialogModel( xInput, xDialogModel, mxContext, mxOwnerDocument );
std::vector< OUString > vEmbeddedImageURLs; std::vector< OUString > vEmbeddedImageURLs;
GraphicObject::InspectForGraphicObjectImageURL( Reference< XInterface >( xDialogModel, UNO_QUERY ), vEmbeddedImageURLs ); GraphicObject::InspectForGraphicObjectImageURL( Reference< XInterface >( xDialogModel, UNO_QUERY ), vEmbeddedImageURLs );
if ( !vEmbeddedImageURLs.empty() ) if ( !vEmbeddedImageURLs.empty() )
{ {
// Export the images to the storage // Export the images to the storage
Reference< document::XGraphicObjectResolver > xGraphicResolver = Reference< document::XGraphicObjectResolver > xGraphicResolver =
document::GraphicObjectResolver::createWithStorage( xContext, xStorage ); document::GraphicObjectResolver::createWithStorage( mxContext, xStorage );
std::vector< OUString >::iterator it = vEmbeddedImageURLs.begin(); std::vector< OUString >::iterator it = vEmbeddedImageURLs.begin();
std::vector< OUString >::iterator it_end = vEmbeddedImageURLs.end(); std::vector< OUString >::iterator it_end = vEmbeddedImageURLs.end();
if ( xGraphicResolver.is() ) if ( xGraphicResolver.is() )
...@@ -278,10 +278,11 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement ...@@ -278,10 +278,11 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement
// return aRetAny; // return aRetAny;
//} //}
Reference< XParser > xParser = xml::sax::Parser::create( comphelper::getComponentContext(mxMSF) ); Reference< XParser > xParser = xml::sax::Parser::create( mxContext );
Reference< XNameContainer > xDialogModel( mxMSF->createInstance Reference< XNameContainer > xDialogModel(
( OUString( "com.sun.star.awt.UnoControlDialogModel" ) ), UNO_QUERY ); mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext),
UNO_QUERY );
if( !xDialogModel.is() ) if( !xDialogModel.is() )
{ {
OSL_FAIL( "### couldn't create com.sun.star.awt.UnoControlDialogModel component\n" ); OSL_FAIL( "### couldn't create com.sun.star.awt.UnoControlDialogModel component\n" );
...@@ -312,16 +313,13 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement ...@@ -312,16 +313,13 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement
if( !xInput.is() ) if( !xInput.is() )
return aRetAny; return aRetAny;
Reference< XComponentContext > xContext(
comphelper::getComponentContext( mxMSF ) );
InputSource source; InputSource source;
source.aInputStream = xInput; source.aInputStream = xInput;
source.sSystemId = aFile; source.sSystemId = aFile;
try { try {
// start parsing // start parsing
xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, xContext, mxOwnerDocument ) ); xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, mxContext, mxOwnerDocument ) );
xParser->parseStream( source ); xParser->parseStream( source );
} }
catch(const Exception& ) catch(const Exception& )
...@@ -335,7 +333,7 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement ...@@ -335,7 +333,7 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement
// Create InputStream, TODO: Implement own InputStreamProvider // Create InputStream, TODO: Implement own InputStreamProvider
// to avoid creating the DialogModel here! // to avoid creating the DialogModel here!
Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, mxOwnerDocument ); Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, mxContext, mxOwnerDocument );
aRetAny <<= xISP; aRetAny <<= xISP;
return aRetAny; return aRetAny;
} }
...@@ -377,8 +375,9 @@ Reference< ::com::sun::star::resource::XStringResourcePersistence > ...@@ -377,8 +375,9 @@ Reference< ::com::sun::star::resource::XStringResourcePersistence >
aArgs[4] <<= aComment; aArgs[4] <<= aComment;
// TODO: Ctor // TODO: Ctor
xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance xRet = Reference< resource::XStringResourcePersistence >(
( OUString("com.sun.star.resource.StringResourceWithStorage") ), UNO_QUERY ); mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.resource.StringResourceWithStorage", mxContext),
UNO_QUERY );
uno::Reference< embed::XStorage > xLibrariesStor; uno::Reference< embed::XStorage > xLibrariesStor;
uno::Reference< embed::XStorage > xLibraryStor; uno::Reference< embed::XStorage > xLibraryStor;
...@@ -425,8 +424,9 @@ Reference< ::com::sun::star::resource::XStringResourcePersistence > ...@@ -425,8 +424,9 @@ Reference< ::com::sun::star::resource::XStringResourcePersistence >
aArgs[5] <<= xDummyHandler; aArgs[5] <<= xDummyHandler;
// TODO: Ctor // TODO: Ctor
xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance xRet = Reference< resource::XStringResourcePersistence >(
( OUString("com.sun.star.resource.StringResourceWithLocation") ), UNO_QUERY ); mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.resource.StringResourceWithLocation", mxContext),
UNO_QUERY );
// TODO: Ctor // TODO: Ctor
if( xRet.is() ) if( xRet.is() )
......
...@@ -387,12 +387,11 @@ SfxLibraryContainer::SfxLibraryContainer( void ) ...@@ -387,12 +387,11 @@ SfxLibraryContainer::SfxLibraryContainer( void )
{ {
DBG_CTOR( SfxLibraryContainer, NULL ); DBG_CTOR( SfxLibraryContainer, NULL );
mxMSF = comphelper::getProcessServiceFactory(); mxContext = comphelper::getProcessComponentContext();
SAL_WARN_IF(!mxMSF.is(), "basic", "couldn't get ProcessServiceFactory");
mxSFI = ucb::SimpleFileAccess::create( comphelper::getComponentContext(mxMSF) ); mxSFI = ucb::SimpleFileAccess::create( mxContext );
mxStringSubstitution = util::PathSubstitution::create( comphelper::getComponentContext(mxMSF) ); mxStringSubstitution = util::PathSubstitution::create( mxContext );
} }
SfxLibraryContainer::~SfxLibraryContainer() SfxLibraryContainer::~SfxLibraryContainer()
...@@ -686,7 +685,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL, ...@@ -686,7 +685,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
maLibraryPath = SvtPathOptions().GetBasicPath(); maLibraryPath = SvtPathOptions().GetBasicPath();
} }
Reference< XParser > xParser = xml::sax::Parser::create(comphelper::getComponentContext(mxMSF)); Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
uno::Reference< io::XInputStream > xInput; uno::Reference< io::XInputStream > xInput;
...@@ -1578,7 +1577,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib, ...@@ -1578,7 +1577,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
Reference< XSimpleFileAccess3 > xToUseSFI ) Reference< XSimpleFileAccess3 > xToUseSFI )
{ {
// Create sax writer // Create sax writer
Reference< XWriter > xWriter = xml::sax::Writer::create(comphelper::getComponentContext(mxMSF)); Reference< XWriter > xWriter = xml::sax::Writer::create(mxContext);
sal_Bool bLink = pLib->mbLink; sal_Bool bLink = pLib->mbLink;
bool bStorage = xStorage.is() && !bLink; bool bStorage = xStorage.is() && !bLink;
...@@ -1678,7 +1677,7 @@ bool SfxLibraryContainer::implLoadLibraryIndexFile( SfxLibrary* pLib, ...@@ -1678,7 +1677,7 @@ bool SfxLibraryContainer::implLoadLibraryIndexFile( SfxLibrary* pLib,
const uno::Reference< embed::XStorage >& xStorage, const uno::Reference< embed::XStorage >& xStorage,
const OUString& aIndexFileName ) const OUString& aIndexFileName )
{ {
Reference< XParser > xParser = xml::sax::Parser::create(comphelper::getComponentContext(mxMSF)); Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
sal_Bool bLink = sal_False; sal_Bool bLink = sal_False;
bool bStorage = false; bool bStorage = false;
...@@ -2051,7 +2050,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto ...@@ -2051,7 +2050,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
// Write library container info // Write library container info
// Create sax writer // Create sax writer
Reference< XWriter > xWriter = xml::sax::Writer::create(comphelper::getComponentContext(mxMSF)); Reference< XWriter > xWriter = xml::sax::Writer::create(mxContext);
// Write info file // Write info file
uno::Reference< io::XOutputStream > xOut; uno::Reference< io::XOutputStream > xOut;
...@@ -2800,7 +2799,7 @@ void SAL_CALL SfxLibraryContainer::exportLibrary( const OUString& Name, const OU ...@@ -2800,7 +2799,7 @@ void SAL_CALL SfxLibraryContainer::exportLibrary( const OUString& Name, const OU
Reference< XSimpleFileAccess3 > xToUseSFI; Reference< XSimpleFileAccess3 > xToUseSFI;
if( Handler.is() ) if( Handler.is() )
{ {
xToUseSFI = ucb::SimpleFileAccess::create( comphelper::getComponentContext(mxMSF) ); xToUseSFI = ucb::SimpleFileAccess::create( mxContext );
xToUseSFI->setInteractionHandler( Handler ); xToUseSFI->setInteractionHandler( Handler );
} }
...@@ -2834,8 +2833,7 @@ OUString SfxLibraryContainer::expand_url( const OUString& url ) ...@@ -2834,8 +2833,7 @@ OUString SfxLibraryContainer::expand_url( const OUString& url )
{ {
if( !mxMacroExpander.is() ) if( !mxMacroExpander.is() )
{ {
Reference< XComponentContext > xContext(comphelper::getComponentContext( mxMSF ) ); Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(mxContext);
Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(xContext);
MutexGuard guard( Mutex::getGlobalMutex() ); MutexGuard guard( Mutex::getGlobalMutex() );
if( !mxMacroExpander.is() ) if( !mxMacroExpander.is() )
{ {
......
...@@ -144,7 +144,7 @@ SfxScriptLibraryContainer::SfxScriptLibraryContainer( const uno::Reference< embe ...@@ -144,7 +144,7 @@ SfxScriptLibraryContainer::SfxScriptLibraryContainer( const uno::Reference< embe
SfxLibrary* SfxScriptLibraryContainer::implCreateLibrary( const OUString& aName ) SfxLibrary* SfxScriptLibraryContainer::implCreateLibrary( const OUString& aName )
{ {
(void)aName; // Only needed for SfxDialogLibrary (void)aName; // Only needed for SfxDialogLibrary
SfxLibrary* pRet = new SfxScriptLibrary( maModifiable, comphelper::getComponentContext(mxMSF), mxSFI ); SfxLibrary* pRet = new SfxScriptLibrary( maModifiable, mxContext, mxSFI );
return pRet; return pRet;
} }
...@@ -154,7 +154,7 @@ SfxLibrary* SfxScriptLibraryContainer::implCreateLibraryLink( const OUString& aN ...@@ -154,7 +154,7 @@ SfxLibrary* SfxScriptLibraryContainer::implCreateLibraryLink( const OUString& aN
sal_Bool ReadOnly ) sal_Bool ReadOnly )
{ {
(void)aName; // Only needed for SfxDialogLibrary (void)aName; // Only needed for SfxDialogLibrary
SfxLibrary* pRet = new SfxScriptLibrary( maModifiable, comphelper::getComponentContext(mxMSF), mxSFI, SfxLibrary* pRet = new SfxScriptLibrary( maModifiable, mxContext, mxSFI,
aLibInfoFileURL, StorageURL, ReadOnly ); aLibInfoFileURL, StorageURL, ReadOnly );
return pRet; return pRet;
} }
...@@ -178,7 +178,7 @@ void SAL_CALL SfxScriptLibraryContainer::writeLibraryElement( const Reference < ...@@ -178,7 +178,7 @@ void SAL_CALL SfxScriptLibraryContainer::writeLibraryElement( const Reference <
throw(Exception) throw(Exception)
{ {
// Create sax writer // Create sax writer
Reference< XWriter > xWriter = xml::sax::Writer::create(comphelper::getComponentContext(mxMSF)); Reference< XWriter > xWriter = xml::sax::Writer::create(mxContext);
Reference< XTruncate > xTruncate( xOutput, UNO_QUERY ); Reference< XTruncate > xTruncate( xOutput, UNO_QUERY );
OSL_ENSURE( xTruncate.is(), "Currently only the streams that can be truncated are expected!" ); OSL_ENSURE( xTruncate.is(), "Currently only the streams that can be truncated are expected!" );
...@@ -229,7 +229,7 @@ Any SAL_CALL SfxScriptLibraryContainer::importLibraryElement ...@@ -229,7 +229,7 @@ Any SAL_CALL SfxScriptLibraryContainer::importLibraryElement
{ {
Any aRetAny; Any aRetAny;
Reference< XParser > xParser = xml::sax::Parser::create( comphelper::getComponentContext(mxMSF) ); Reference< XParser > xParser = xml::sax::Parser::create( mxContext );
// Read from storage? // Read from storage?
sal_Bool bStorage = xInStream.is(); sal_Bool bStorage = xInStream.is();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment