fdo#46808, use XComponentContext in SfxLibraryContainer

Change-Id: I6f66fc69a40e2cd2ef2372e0413ff95b6202c5c5
This commit is contained in:
Noel Grandin 2013-05-13 16:51:26 +02:00
parent 67042f1f03
commit 4460f213df
4 changed files with 33 additions and 35 deletions

View file

@ -218,7 +218,7 @@ class SfxLibraryContainer : public SfxLibraryContainer_BASE, public ::utl::OEven
sal_Bool mbVBACompat;
OUString msProjectName;
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::util::XMacroExpander > mxMacroExpander;
::com::sun::star::uno::Reference< ::com::sun::star::util::XStringSubstitution > mxStringSubstitution;

View file

@ -87,7 +87,7 @@ SfxDialogLibraryContainer::SfxDialogLibraryContainer( const uno::Reference< embe
// Methods to get library instances of the correct type
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;
}
@ -96,7 +96,7 @@ SfxLibrary* SfxDialogLibraryContainer::implCreateLibraryLink
const OUString& StorageURL, sal_Bool ReadOnly )
{
SfxLibrary* pRet = new SfxDialogLibrary
( maModifiable, aName, comphelper::getComponentContext(mxMSF), mxSFI, aLibInfoFileURL, StorageURL, ReadOnly, this );
( maModifiable, aName, mxContext, mxSFI, aLibInfoFileURL, StorageURL, ReadOnly, this );
return pRet;
}
@ -236,17 +236,17 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e
if ( xISP.is() )
{
Reference< io::XInputStream > xInput( xISP->createInputStream() );
Reference< XNameContainer > xDialogModel( mxMSF->createInstance
( OUString( "com.sun.star.awt.UnoControlDialogModel" ) ) , UNO_QUERY );
Reference< XComponentContext > xContext( comphelper::getComponentContext( mxMSF ) );
::xmlscript::importDialogModel( xInput, xDialogModel, xContext, mxOwnerDocument );
Reference< XNameContainer > xDialogModel(
mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext),
UNO_QUERY );
::xmlscript::importDialogModel( xInput, xDialogModel, mxContext, mxOwnerDocument );
std::vector< OUString > vEmbeddedImageURLs;
GraphicObject::InspectForGraphicObjectImageURL( Reference< XInterface >( xDialogModel, UNO_QUERY ), vEmbeddedImageURLs );
if ( !vEmbeddedImageURLs.empty() )
{
// Export the images to the storage
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_end = vEmbeddedImageURLs.end();
if ( xGraphicResolver.is() )
@ -278,10 +278,11 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement
// 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
( OUString( "com.sun.star.awt.UnoControlDialogModel" ) ), UNO_QUERY );
Reference< XNameContainer > xDialogModel(
mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext),
UNO_QUERY );
if( !xDialogModel.is() )
{
OSL_FAIL( "### couldn't create com.sun.star.awt.UnoControlDialogModel component\n" );
@ -312,16 +313,13 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement
if( !xInput.is() )
return aRetAny;
Reference< XComponentContext > xContext(
comphelper::getComponentContext( mxMSF ) );
InputSource source;
source.aInputStream = xInput;
source.sSystemId = aFile;
try {
// start parsing
xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, xContext, mxOwnerDocument ) );
xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, mxContext, mxOwnerDocument ) );
xParser->parseStream( source );
}
catch(const Exception& )
@ -335,7 +333,7 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement
// Create InputStream, TODO: Implement own InputStreamProvider
// to avoid creating the DialogModel here!
Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, mxOwnerDocument );
Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, mxContext, mxOwnerDocument );
aRetAny <<= xISP;
return aRetAny;
}
@ -377,8 +375,9 @@ Reference< ::com::sun::star::resource::XStringResourcePersistence >
aArgs[4] <<= aComment;
// TODO: Ctor
xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance
( OUString("com.sun.star.resource.StringResourceWithStorage") ), UNO_QUERY );
xRet = Reference< resource::XStringResourcePersistence >(
mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.resource.StringResourceWithStorage", mxContext),
UNO_QUERY );
uno::Reference< embed::XStorage > xLibrariesStor;
uno::Reference< embed::XStorage > xLibraryStor;
@ -425,8 +424,9 @@ Reference< ::com::sun::star::resource::XStringResourcePersistence >
aArgs[5] <<= xDummyHandler;
// TODO: Ctor
xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance
( OUString("com.sun.star.resource.StringResourceWithLocation") ), UNO_QUERY );
xRet = Reference< resource::XStringResourcePersistence >(
mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.resource.StringResourceWithLocation", mxContext),
UNO_QUERY );
// TODO: Ctor
if( xRet.is() )

View file

@ -387,12 +387,11 @@ SfxLibraryContainer::SfxLibraryContainer( void )
{
DBG_CTOR( SfxLibraryContainer, NULL );
mxMSF = comphelper::getProcessServiceFactory();
SAL_WARN_IF(!mxMSF.is(), "basic", "couldn't get ProcessServiceFactory");
mxContext = comphelper::getProcessComponentContext();
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()
@ -686,7 +685,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
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;
@ -1578,7 +1577,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
Reference< XSimpleFileAccess3 > xToUseSFI )
{
// 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;
bool bStorage = xStorage.is() && !bLink;
@ -1678,7 +1677,7 @@ bool SfxLibraryContainer::implLoadLibraryIndexFile( SfxLibrary* pLib,
const uno::Reference< embed::XStorage >& xStorage,
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;
bool bStorage = false;
@ -2051,7 +2050,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
// Write library container info
// Create sax writer
Reference< XWriter > xWriter = xml::sax::Writer::create(comphelper::getComponentContext(mxMSF));
Reference< XWriter > xWriter = xml::sax::Writer::create(mxContext);
// Write info file
uno::Reference< io::XOutputStream > xOut;
@ -2800,7 +2799,7 @@ void SAL_CALL SfxLibraryContainer::exportLibrary( const OUString& Name, const OU
Reference< XSimpleFileAccess3 > xToUseSFI;
if( Handler.is() )
{
xToUseSFI = ucb::SimpleFileAccess::create( comphelper::getComponentContext(mxMSF) );
xToUseSFI = ucb::SimpleFileAccess::create( mxContext );
xToUseSFI->setInteractionHandler( Handler );
}
@ -2834,8 +2833,7 @@ OUString SfxLibraryContainer::expand_url( const OUString& url )
{
if( !mxMacroExpander.is() )
{
Reference< XComponentContext > xContext(comphelper::getComponentContext( mxMSF ) );
Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(xContext);
Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(mxContext);
MutexGuard guard( Mutex::getGlobalMutex() );
if( !mxMacroExpander.is() )
{

View file

@ -144,7 +144,7 @@ SfxScriptLibraryContainer::SfxScriptLibraryContainer( const uno::Reference< embe
SfxLibrary* SfxScriptLibraryContainer::implCreateLibrary( const OUString& aName )
{
(void)aName; // Only needed for SfxDialogLibrary
SfxLibrary* pRet = new SfxScriptLibrary( maModifiable, comphelper::getComponentContext(mxMSF), mxSFI );
SfxLibrary* pRet = new SfxScriptLibrary( maModifiable, mxContext, mxSFI );
return pRet;
}
@ -154,7 +154,7 @@ SfxLibrary* SfxScriptLibraryContainer::implCreateLibraryLink( const OUString& aN
sal_Bool ReadOnly )
{
(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 );
return pRet;
}
@ -178,7 +178,7 @@ void SAL_CALL SfxScriptLibraryContainer::writeLibraryElement( const Reference <
throw(Exception)
{
// 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 );
OSL_ENSURE( xTruncate.is(), "Currently only the streams that can be truncated are expected!" );
@ -229,7 +229,7 @@ Any SAL_CALL SfxScriptLibraryContainer::importLibraryElement
{
Any aRetAny;
Reference< XParser > xParser = xml::sax::Parser::create( comphelper::getComponentContext(mxMSF) );
Reference< XParser > xParser = xml::sax::Parser::create( mxContext );
// Read from storage?
sal_Bool bStorage = xInStream.is();