summaryrefslogtreecommitdiff
path: root/basic/source/uno/namecont.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'basic/source/uno/namecont.cxx')
-rw-r--r--basic/source/uno/namecont.cxx310
1 files changed, 187 insertions, 123 deletions
diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index 98b999ecf29e..02c2e78e3f16 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -25,11 +25,14 @@
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/io/IOException.hpp>
+#include <com/sun/star/lang/NoSupportException.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/ucb/ContentCreationException.hpp>
#include <com/sun/star/xml/sax/SAXException.hpp>
+#include <utility>
#include <vcl/svapp.hxx>
+#include <o3tl/string_view.hxx>
#include <osl/mutex.hxx>
#include <vcl/errinf.hxx>
#include <rtl/ustring.hxx>
@@ -41,7 +44,7 @@
#include <namecont.hxx>
#include <basic/basicmanagerrepository.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <tools/urlobj.hxx>
#include <unotools/pathoptions.hxx>
#include <svtools/sfxecode.hxx>
@@ -87,7 +90,6 @@ using namespace com::sun::star::frame;
using namespace com::sun::star::deployment;
using namespace com::sun::star;
using namespace cppu;
-using namespace osl;
using com::sun::star::uno::Reference;
@@ -141,7 +143,7 @@ void NameContainer::replaceByName( const OUString& aName, const Any& aElement )
const Type& aAnyType = aElement.getValueType();
if( mType != aAnyType )
{
- throw IllegalArgumentException("types do not match", static_cast<cppu::OWeakObject*>(this), 2);
+ throw IllegalArgumentException(u"types do not match"_ustr, getXWeak(), 2);
}
NameContainerNameMap::iterator aIt = mHashMap.find( aName );
if( aIt == mHashMap.end() )
@@ -153,30 +155,29 @@ void NameContainer::replaceByName( const OUString& aName, const Any& aElement )
mValues[ iHashResult ] = aElement;
+ std::unique_lock aGuard(m_aMutex);
+
// Fire event
- if( maContainerListeners.getLength() > 0 )
+ if( maContainerListeners.getLength(aGuard) > 0 )
{
ContainerEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Accessor <<= aName;
aEvent.Element = aElement;
aEvent.ReplacedElement = aOldElement;
- maContainerListeners.notifyEach( &XContainerListener::elementReplaced, aEvent );
+ maContainerListeners.notifyEach( aGuard, &XContainerListener::elementReplaced, aEvent );
}
/* After the container event has been fired (one listener will update the
core Basic manager), fire change event. Listeners can rely on that the
Basic source code of the core Basic manager is up-to-date. */
- if( maChangesListeners.getLength() > 0 )
+ if( maChangesListeners.getLength(aGuard) > 0 )
{
ChangesEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Base <<= aEvent.Source;
- aEvent.Changes.realloc( 1 );
- aEvent.Changes[ 0 ].Accessor <<= aName;
- aEvent.Changes[ 0 ].Element = aElement;
- aEvent.Changes[ 0 ].ReplacedElement = aOldElement;
- maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
+ aEvent.Changes = { { Any(aName), aElement, aOldElement } };
+ maChangesListeners.notifyEach( aGuard, &XChangesListener::changesOccurred, aEvent );
}
}
@@ -195,7 +196,7 @@ void NameContainer::insertNoCheck(const OUString& aName, const Any& aElement)
const Type& aAnyType = aElement.getValueType();
if( mType != aAnyType )
{
- throw IllegalArgumentException("types do not match", static_cast<cppu::OWeakObject*>(this), 2);
+ throw IllegalArgumentException(u"types do not match"_ustr, getXWeak(), 2);
}
sal_Int32 nCount = mNames.size();
@@ -205,28 +206,28 @@ void NameContainer::insertNoCheck(const OUString& aName, const Any& aElement)
mHashMap[ aName ] = nCount;
mnElementCount++;
+ std::unique_lock aGuard(m_aMutex);
+
// Fire event
- if( maContainerListeners.getLength() > 0 )
+ if( maContainerListeners.getLength(aGuard) > 0 )
{
ContainerEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Accessor <<= aName;
aEvent.Element = aElement;
- maContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent );
+ maContainerListeners.notifyEach( aGuard, &XContainerListener::elementInserted, aEvent );
}
/* After the container event has been fired (one listener will update the
core Basic manager), fire change event. Listeners can rely on that the
Basic source code of the core Basic manager is up-to-date. */
- if( maChangesListeners.getLength() > 0 )
+ if( maChangesListeners.getLength(aGuard) > 0 )
{
ChangesEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Base <<= aEvent.Source;
- aEvent.Changes.realloc( 1 );
- aEvent.Changes[ 0 ].Accessor <<= aName;
- aEvent.Changes[ 0 ].Element = aElement;
- maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
+ aEvent.Changes = { { Any(aName), aElement, {} } };
+ maChangesListeners.notifyEach( aGuard, &XChangesListener::changesOccurred, aEvent );
}
}
@@ -259,29 +260,30 @@ void NameContainer::removeByName( const OUString& aName )
mValues.resize( iLast );
mnElementCount--;
+ std::unique_lock aGuard(m_aMutex);
+
// Fire event
- if( maContainerListeners.getLength() > 0 )
+ if( maContainerListeners.getLength(aGuard) > 0 )
{
ContainerEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Accessor <<= aName;
aEvent.Element = aOldElement;
- maContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent );
+ maContainerListeners.notifyEach( aGuard, &XContainerListener::elementRemoved, aEvent );
}
/* After the container event has been fired (one listener will update the
core Basic manager), fire change event. Listeners can rely on that the
Basic source code of the core Basic manager is up-to-date. */
- if( maChangesListeners.getLength() > 0 )
+ if( maChangesListeners.getLength(aGuard) > 0 )
{
ChangesEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Base <<= aEvent.Source;
- aEvent.Changes.realloc( 1 );
- aEvent.Changes[ 0 ].Accessor <<= aName;
- // aEvent.Changes[ 0 ].Element remains empty (meaning "replaced with nothing")
- aEvent.Changes[ 0 ].ReplacedElement = aOldElement;
- maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
+ aEvent.Changes = { { Any(aName),
+ {}, // Element remains empty (meaning "replaced with nothing")
+ aOldElement } };
+ maChangesListeners.notifyEach( aGuard, &XChangesListener::changesOccurred, aEvent );
}
}
@@ -291,18 +293,20 @@ void SAL_CALL NameContainer::addContainerListener( const Reference< XContainerLi
{
if( !xListener.is() )
{
- throw RuntimeException("addContainerListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException(u"addContainerListener called with null xListener"_ustr,getXWeak());
}
- maContainerListeners.addInterface( Reference<XInterface>(xListener, UNO_QUERY) );
+ std::unique_lock aGuard(m_aMutex);
+ maContainerListeners.addInterface( aGuard, xListener );
}
void SAL_CALL NameContainer::removeContainerListener( const Reference< XContainerListener >& xListener )
{
if( !xListener.is() )
{
- throw RuntimeException("removeContainerListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException(u"removeContainerListener called with null xListener"_ustr,getXWeak());
}
- maContainerListeners.removeInterface( Reference<XInterface>(xListener, UNO_QUERY) );
+ std::unique_lock aGuard(m_aMutex);
+ maContainerListeners.removeInterface( aGuard, xListener );
}
// Methods XChangesNotifier
@@ -310,18 +314,20 @@ void SAL_CALL NameContainer::addChangesListener( const Reference< XChangesListen
{
if( !xListener.is() )
{
- throw RuntimeException("addChangesListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException(u"addChangesListener called with null xListener"_ustr,getXWeak());
}
- maChangesListeners.addInterface( Reference<XInterface>(xListener, UNO_QUERY) );
+ std::unique_lock aGuard(m_aMutex);
+ maChangesListeners.addInterface( aGuard, xListener );
}
void SAL_CALL NameContainer::removeChangesListener( const Reference< XChangesListener >& xListener )
{
if( !xListener.is() )
{
- throw RuntimeException("removeChangesListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException(u"removeChangesListener called with null xListener"_ustr,getXWeak());
}
- maChangesListeners.removeInterface( Reference<XInterface>(xListener, UNO_QUERY) );
+ std::unique_lock aGuard(m_aMutex);
+ maChangesListeners.removeInterface( aGuard, xListener );
}
@@ -344,23 +350,13 @@ void ModifiableHelper::setModified( bool _bModified )
}
-VBAScriptListenerContainer::VBAScriptListenerContainer( ::osl::Mutex& rMutex ) :
- VBAScriptListenerContainer_BASE( rMutex )
-{
-}
-
-bool VBAScriptListenerContainer::implTypedNotify( const Reference< vba::XVBAScriptListener >& rxListener, const vba::VBAScriptEvent& rEvent )
-{
- rxListener->notifyVBAScriptEvent( rEvent );
- return true; // notify all other listeners too
-}
-
// Ctor
SfxLibraryContainer::SfxLibraryContainer()
: SfxLibraryContainer_BASE( m_aMutex )
, maVBAScriptListeners( m_aMutex )
, mnRunningVBAScripts( 0 )
, mbVBACompat( false )
+ , meVBATextEncoding( RTL_TEXTENCODING_DONTKNOW )
, maModifiable( *this, m_aMutex )
, maNameContainer( new NameContainer(cppu::UnoType<XNameAccess>::get()) )
, mbOldInfoFormat( false )
@@ -435,7 +431,7 @@ void SAL_CALL SfxLibraryContainer::setRootStorage( const Reference< XStorage >&
LibraryContainerMethodGuard aGuard( *this );
if ( !_rxRootStorage.is() )
{
- throw IllegalArgumentException("no root storage", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"no root storage"_ustr, getXWeak(), 1);
}
mxStorage = _rxRootStorage;
onNewRootStorage();
@@ -446,7 +442,7 @@ void SAL_CALL SfxLibraryContainer::storeLibrariesToStorage( const Reference< XSt
LibraryContainerMethodGuard aGuard( *this );
if ( !_rxRootStorage.is() )
{
- throw IllegalArgumentException("no root storage", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"no root storage"_ustr, getXWeak(), 1);
}
try
{
@@ -550,7 +546,9 @@ void SAL_CALL SfxLibraryContainer::storeLibraries( )
}
}
-static void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
+namespace
+{
+void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
const INetURLObject& rTargetFolderInetObj,
std::u16string_view rCheckFileName,
std::u16string_view rCheckExtension,
@@ -572,19 +570,23 @@ static void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
}
}
-static void createVariableURL( OUString& rStr, std::u16string_view rLibName,
+constexpr OUString sUserBasicVariablePrefix = u"$(USER)/basic/"_ustr;
+constexpr OUString sInstBasicVariablePrefix = u"$(INST)/" LIBO_SHARE_FOLDER "/basic/"_ustr;
+
+void createVariableURL( OUString& rStr, std::u16string_view rLibName,
std::u16string_view rInfoFileName, bool bUser )
{
if( bUser )
{
- rStr = "$(USER)/basic/";
+ rStr = sUserBasicVariablePrefix;
}
else
{
- rStr = "$(INST)/" LIBO_SHARE_FOLDER "/basic/";
+ rStr = sInstBasicVariablePrefix;
}
rStr += OUString::Concat(rLibName) + "/" + rInfoFileName + ".xlb/";
}
+}
void SfxLibraryContainer::init( const OUString& rInitialDocumentURL, const uno::Reference< embed::XStorage >& rxInitialStorage )
{
@@ -602,10 +604,10 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
uno::Reference< embed::XStorage > xStorage = rxInitialStorage;
maInitialDocumentURL = rInitialDocumentURL;
- maInfoFileName = OUString::createFromAscii( getInfoFileName() );
- maOldInfoFileName = OUString::createFromAscii( getOldInfoFileName() );
- maLibElementFileExtension = OUString::createFromAscii( getLibElementFileExtension() );
- maLibrariesDir = OUString::createFromAscii( getLibrariesDir() );
+ maInfoFileName = getInfoFileName();
+ maOldInfoFileName = getOldInfoFileName();
+ maLibElementFileExtension = getLibElementFileExtension();
+ maLibrariesDir = getLibrariesDir();
meInitMode = DEFAULT;
INetURLObject aInitUrlInetObj( maInitialDocumentURL );
@@ -663,8 +665,6 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
maLibraryPath = SvtPathOptions().GetBasicPath();
}
- Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
-
uno::Reference< io::XInputStream > xInput;
mxStorage = xStorage;
@@ -748,11 +748,11 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
{
if( nPass == 1 )
{
- pLibInfoInetObj.reset(new INetURLObject( maLibraryPath.getToken(0, ';') ));
+ pLibInfoInetObj.reset(new INetURLObject( o3tl::getToken(maLibraryPath, 0, ';') ));
}
else
{
- pLibInfoInetObj.reset(new INetURLObject( maLibraryPath.getToken(1, ';') ));
+ pLibInfoInetObj.reset(new INetURLObject( o3tl::getToken(maLibraryPath, 1, ';') ));
}
pLibInfoInetObj->insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
pLibInfoInetObj->setExtension( u"xlc" );
@@ -772,7 +772,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
// Old variant?
if( !xInput.is() && nPass == 0 )
{
- INetURLObject aLibInfoInetObj( maLibraryPath.getToken(1, ';') );
+ INetURLObject aLibInfoInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
aLibInfoInetObj.insertName( maOldInfoFileName, false, INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
aLibInfoInetObj.setExtension( u"xli" );
aFileName = aLibInfoInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
@@ -798,6 +798,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
// start parsing
auto pLibArray = std::make_unique<::xmlscript::LibDescriptorArray> ( );
+ Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
try
{
xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray.get() ) );
@@ -845,7 +846,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
else if( rLib.bLink )
{
// Check "share" path
- INetURLObject aShareInetObj( maLibraryPath.getToken(0, ';') );
+ INetURLObject aShareInetObj( o3tl::getToken(maLibraryPath, 0, ';') );
aShareInetObj.insertName( rLib.aName, true, INetURLObject::LAST_SEGMENT,
INetURLObject::EncodeMechanism::All );
OUString aShareLibDirPath = aShareInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
@@ -987,8 +988,12 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
if( meInitMode != DEFAULT )
return;
- INetURLObject aUserBasicInetObj( maLibraryPath.getToken(1, ';') );
- OUString aStandardStr("Standard");
+ // tdf#121740 speed up loading documents with lots of embedded documents by avoid the UCB work of updating non-existent VBA libraries
+ if (rInitialDocumentURL.isEmpty())
+ return;
+
+ INetURLObject aUserBasicInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
+ OUString aStandardStr(u"Standard"_ustr);
INetURLObject aPrevUserBasicInetObj_1( aUserBasicInetObj );
aPrevUserBasicInetObj_1.removeSegment();
@@ -1014,7 +1019,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
OUString aPrevStandardFolder = aPrevUserBasicStandardInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
if( mxSFI->isFolder( aPrevStandardFolder ) )
{
- OUString aXlbExtension( "xlb" );
+ OUString aXlbExtension( u"xlb"_ustr );
OUString aCheckFileName;
// Check if script.xlb exists
@@ -1271,6 +1276,17 @@ void SfxLibraryContainer::checkStorageURL( const OUString& aSourceURL,
{
aUnexpandedStorageURL = aSourceURL;
}
+ else
+ {
+ // try to re-create the variable URL: helps moving the profile
+ if (OUString aRest; aSourceURL.startsWith(expand_url(sUserBasicVariablePrefix), &aRest))
+ aUnexpandedStorageURL = sUserBasicVariablePrefix + aRest;
+ else if (aSourceURL.startsWith(expand_url(sInstBasicVariablePrefix), &aRest))
+ aUnexpandedStorageURL = sInstBasicVariablePrefix + aRest;
+ else
+ aUnexpandedStorageURL.clear(); // This will use eventual value of aLibInfoFileURL
+ }
+
INetURLObject aInetObj( aExpandedSourceURL );
OUString aExtension = aInetObj.getExtension();
if( aExtension == "xlb" )
@@ -1335,7 +1351,7 @@ OUString SfxLibraryContainer::createAppLibraryFolder( SfxLibrary* pLib, std::u16
OUString aLibDirPath = pLib->maStorageURL;
if( aLibDirPath.isEmpty() )
{
- INetURLObject aInetObj( maLibraryPath.getToken(1, ';') );
+ INetURLObject aInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
aInetObj.insertName( aName, true, INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
checkStorageURL( aInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ), pLib->maLibInfoFileURL,
pLib->maStorageURL, pLib->maUnexpandedStorageURL );
@@ -1362,14 +1378,14 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
{
Reference< XSimpleFileAccess3 > xDummySFA;
Reference< XInteractionHandler > xDummyHandler;
- implStoreLibrary( pLib, aName, xStorage, OUString(), xDummySFA, xDummyHandler );
+ implStoreLibrary( pLib, aName, xStorage, u"", xDummySFA, xDummyHandler );
}
// New variant for library export
void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
std::u16string_view aName,
const uno::Reference< embed::XStorage >& xStorage,
- const OUString& aTargetURL,
+ std::u16string_view aTargetURL,
const Reference< XSimpleFileAccess3 >& rToUseSFI,
const Reference< XInteractionHandler >& xHandler )
{
@@ -1409,10 +1425,10 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
if ( xProps.is() )
{
- xProps->setPropertyValue("MediaType", uno::Any( OUString( "text/xml" ) ) );
+ xProps->setPropertyValue(u"MediaType"_ustr, uno::Any( u"text/xml"_ustr ) );
// #87671 Allow encryption
- xProps->setPropertyValue("UseCommonStoragePasswordEncryption", uno::Any( true ) );
+ xProps->setPropertyValue(u"UseCommonStoragePasswordEncryption"_ustr, uno::Any( true ) );
Reference< XOutputStream > xOutput = xElementStream->getOutputStream();
Reference< XNameContainer > xLib( pLib );
@@ -1430,7 +1446,7 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
else
{
// Export?
- bool bExport = !aTargetURL.isEmpty();
+ bool bExport = !aTargetURL.empty();
try
{
Reference< XSimpleFileAccess3 > xSFI = mxSFI;
@@ -1514,14 +1530,14 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
const uno::Reference< embed::XStorage >& xStorage )
{
Reference< XSimpleFileAccess3 > xDummySFA;
- implStoreLibraryIndexFile( pLib, rLib, xStorage, OUString(), xDummySFA );
+ implStoreLibraryIndexFile( pLib, rLib, xStorage, u"", xDummySFA );
}
// New variant for library export
void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
const ::xmlscript::LibDescriptor& rLib,
const uno::Reference< embed::XStorage >& xStorage,
- const OUString& aTargetURL,
+ std::u16string_view aTargetURL,
const Reference< XSimpleFileAccess3 >& rToUseSFI )
{
// Create sax writer
@@ -1546,10 +1562,10 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
if ( xProps.is() )
{
- xProps->setPropertyValue("MediaType", uno::Any( OUString("text/xml") ) );
+ xProps->setPropertyValue(u"MediaType"_ustr, uno::Any( u"text/xml"_ustr ) );
// #87671 Allow encryption
- xProps->setPropertyValue("UseCommonStoragePasswordEncryption", uno::Any( true ) );
+ xProps->setPropertyValue(u"UseCommonStoragePasswordEncryption"_ustr, uno::Any( true ) );
xOut = xInfoStream->getOutputStream();
}
@@ -1563,7 +1579,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
else
{
// Export?
- bool bExport = !aTargetURL.isEmpty();
+ bool bExport = !aTargetURL.empty();
Reference< XSimpleFileAccess3 > xSFI = mxSFI;
if( rToUseSFI.is() )
{
@@ -1798,10 +1814,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
sal_Int32 index = 0;
do
{
- OUStringBuffer aTempTargetName( aTempTargetNameBase );
- aTempTargetName.append( index++ );
-
- sTargetLibrariesStoreName = aTempTargetName.makeStringAndClear();
+ sTargetLibrariesStoreName = aTempTargetNameBase + OUString::number( index++ );
if ( !i_rStorage->hasByName( sTargetLibrariesStoreName ) )
{
break;
@@ -2053,10 +2066,10 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
{
xInfoStream = xTargetLibrariesStor->openStreamElement( aStreamName, embed::ElementModes::READWRITE );
uno::Reference< beans::XPropertySet > xProps( xInfoStream, uno::UNO_QUERY_THROW );
- xProps->setPropertyValue("MediaType", uno::Any( OUString( "text/xml" ) ) );
+ xProps->setPropertyValue(u"MediaType"_ustr, uno::Any( u"text/xml"_ustr ) );
// #87671 Allow encryption
- xProps->setPropertyValue("UseCommonStoragePasswordEncryption", uno::Any( true ) );
+ xProps->setPropertyValue(u"UseCommonStoragePasswordEncryption"_ustr, uno::Any( true ) );
xOut = xInfoStream->getOutputStream();
}
@@ -2068,7 +2081,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
else
{
// Create Output stream
- INetURLObject aLibInfoInetObj( maLibraryPath.getToken(1, ';') );
+ INetURLObject aLibInfoInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
aLibInfoInetObj.insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
aLibInfoInetObj.setExtension( u"xlc" );
OUString aLibInfoPath( aLibInfoInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
@@ -2156,6 +2169,9 @@ Reference< XNameContainer > SAL_CALL SfxLibraryContainer::createLibrary( const O
pNewLib->maLibElementFileExtension = maLibElementFileExtension;
createVariableURL( pNewLib->maUnexpandedStorageURL, Name, maInfoFileName, true );
+ // tdf#151741 - fill various storage URLs for the newly created library
+ checkStorageURL(pNewLib->maUnexpandedStorageURL, pNewLib->maLibInfoFileURL,
+ pNewLib->maStorageURL, pNewLib->maUnexpandedStorageURL);
Reference< XNameAccess > xNameAccess( pNewLib );
Any aElement;
@@ -2221,7 +2237,7 @@ void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name )
SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
if( pImplLib->mbReadOnly && !pImplLib->mbLink )
{
- throw IllegalArgumentException("readonly && !link", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"readonly && !link"_ustr, getXWeak(), 1);
}
// Remove from container
maNameContainer->removeByName( Name );
@@ -2259,7 +2275,7 @@ void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name )
catch(const Exception& ) {}
// Delete folder if empty
- INetURLObject aInetObj( maLibraryPath.getToken(1, ';') );
+ INetURLObject aInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
aInetObj.insertName( Name, true, INetURLObject::LAST_SEGMENT,
INetURLObject::EncodeMechanism::All );
OUString aLibDirPath = aInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
@@ -2327,7 +2343,7 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
" storage!"));
if ( !xLibrariesStor.is() )
{
- throw uno::RuntimeException("null returned from openStorageElement",static_cast< cppu::OWeakObject * >(this));
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr,getXWeak());
}
xLibraryStor = xLibrariesStor->openStorageElement( Name, embed::ElementModes::READ );
@@ -2337,7 +2353,7 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
" storage!"));
if ( !xLibrariesStor.is() )
{
- throw uno::RuntimeException("null returned from openStorageElement",static_cast< cppu::OWeakObject * >(this));
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr,getXWeak());
}
#if OSL_DEBUG_LEVEL > 0
}
@@ -2396,7 +2412,7 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
"basic",
"couldn't open library element stream - attempted to"
" open library \"" << Name << '"');
- throw RuntimeException("couldn't open library element stream", *this);
+ throw RuntimeException(u"couldn't open library element stream"_ustr, *this);
}
}
else
@@ -2444,7 +2460,7 @@ OUString SAL_CALL SfxLibraryContainer::getLibraryLinkURL( const OUString& Name )
bool bLink = pImplLib->mbLink;
if( !bLink )
{
- throw IllegalArgumentException("!link", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"!link"_ustr, getXWeak(), 1);
}
OUString aRetStr = pImplLib->maLibInfoFileURL;
return aRetStr;
@@ -2501,10 +2517,6 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU
}
loadLibrary( Name );
- // Remove from container
- maNameContainer->removeByName( Name );
- maModifiable.setModified( true );
-
// Rename library folder, but not for linked libraries
bool bMovedSuccessful = true;
@@ -2515,15 +2527,23 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU
bMovedSuccessful = false;
OUString aLibDirPath = pImplLib->maStorageURL;
+ // tdf#151741 - fill various storage URLs for the library
+ // These URLs should not be empty for newly created libraries after
+ // the change in SfxLibraryContainer::createLibrary.
+ if (aLibDirPath.isEmpty())
+ {
+ checkStorageURL(pImplLib->maUnexpandedStorageURL, pImplLib->maLibInfoFileURL,
+ pImplLib->maStorageURL, pImplLib->maUnexpandedStorageURL);
+ }
- INetURLObject aDestInetObj( maLibraryPath.getToken(1, ';'));
+ INetURLObject aDestInetObj( o3tl::getToken(maLibraryPath, 1, ';'));
aDestInetObj.insertName( NewName, true, INetURLObject::LAST_SEGMENT,
INetURLObject::EncodeMechanism::All );
OUString aDestDirPath = aDestInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
// Store new URL
OUString aLibInfoFileURL = pImplLib->maLibInfoFileURL;
- checkStorageURL( aDestDirPath, pImplLib->maLibInfoFileURL, pImplLib->maStorageURL,
+ checkStorageURL(aDestDirPath, pImplLib->maLibInfoFileURL, pImplLib->maStorageURL,
pImplLib->maUnexpandedStorageURL );
try
@@ -2591,12 +2611,13 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU
bMovedSuccessful = true;
pImplLib->implSetModified( true );
+ // Remove old library from container
+ maNameContainer->removeByName( Name );
+ maModifiable.setModified( true );
}
}
catch(const Exception& )
{
- // Restore old library
- maNameContainer->insertByName( Name, aLibAny ) ;
}
}
@@ -2617,7 +2638,7 @@ void SAL_CALL SfxLibraryContainer::initialize( const Sequence< Any >& _rArgument
LibraryContainerMethodGuard aGuard( *this );
sal_Int32 nArgCount = _rArguments.getLength();
if ( nArgCount != 1 )
- throw IllegalArgumentException("too many args", static_cast<cppu::OWeakObject*>(this), -1);
+ throw IllegalArgumentException(u"too many args"_ustr, getXWeak(), -1);
OUString sInitialDocumentURL;
Reference< XStorageBasedDocument > xDocument;
@@ -2632,7 +2653,7 @@ void SAL_CALL SfxLibraryContainer::initialize( const Sequence< Any >& _rArgument
initializeFromDocument( xDocument );
return;
}
- throw IllegalArgumentException("arg1 unknown type", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"arg1 unknown type"_ustr, getXWeak(), 1);
}
@@ -2643,7 +2664,7 @@ void SfxLibraryContainer::initializeFromDocument( const Reference< XStorageBased
try
{
Reference< XServiceInfo > xSI( _rxDocument, UNO_QUERY_THROW );
- if ( xSI->supportsService("com.sun.star.document.OfficeDocument"))
+ if ( xSI->supportsService(u"com.sun.star.document.OfficeDocument"_ustr))
{
xDocStorage.set( _rxDocument->getDocumentStorage(), UNO_SET_THROW );
}
@@ -2657,7 +2678,7 @@ void SfxLibraryContainer::initializeFromDocument( const Reference< XStorageBased
if ( !xDocStorage.is() )
{
- throw IllegalArgumentException("no doc storage", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"no doc storage"_ustr, getXWeak(), 1);
}
init( OUString(), xDocStorage );
}
@@ -2681,7 +2702,7 @@ void SAL_CALL SfxLibraryContainer::disposing()
{
Reference< XModel > xModel = mxOwnerDocument;
EventObject aEvent( xModel );
- maVBAScriptListeners.disposing( aEvent );
+ maVBAScriptListeners.disposeAndClear( aEvent );
stopAllComponentListening();
mxOwnerDocument.clear();
}
@@ -2711,7 +2732,7 @@ void SAL_CALL SfxLibraryContainer::changeLibraryPassword(const OUString&, const
void SAL_CALL SfxLibraryContainer::addContainerListener( const Reference< XContainerListener >& xListener )
{
LibraryContainerMethodGuard aGuard( *this );
- maNameContainer->setEventSource( static_cast< XInterface* >( static_cast<OWeakObject*>(this) ) );
+ maNameContainer->setEventSource( getXWeak() );
maNameContainer->addContainerListener( xListener );
}
@@ -2783,7 +2804,7 @@ OUString SAL_CALL SfxLibraryContainer::getOriginalLibraryLinkURL( const OUString
bool bLink = pImplLib->mbLink;
if( !bLink )
{
- throw IllegalArgumentException("!link", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"!link"_ustr, getXWeak(), 1);
}
OUString aRetStr = pImplLib->maOriginalStorageURL;
return aRetStr;
@@ -2827,7 +2848,7 @@ void SAL_CALL SfxLibraryContainer::setVBACompatibilityMode( sal_Bool _vbacompatm
{
Reference< XModel > xModel( mxOwnerDocument ); // weak-ref -> ref
Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
- xFactory->createInstance("ooo.vba.VBAGlobals");
+ xFactory->createInstance(u"ooo.vba.VBAGlobals"_ustr);
}
catch(const Exception& )
{
@@ -2856,12 +2877,12 @@ sal_Int32 SAL_CALL SfxLibraryContainer::getRunningVBAScripts()
void SAL_CALL SfxLibraryContainer::addVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener )
{
- maVBAScriptListeners.addTypedListener( rxListener );
+ maVBAScriptListeners.addInterface( rxListener );
}
void SAL_CALL SfxLibraryContainer::removeVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener )
{
- maVBAScriptListeners.removeTypedListener( rxListener );
+ maVBAScriptListeners.removeInterface( rxListener );
}
void SAL_CALL SfxLibraryContainer::broadcastVBAScriptEvent( sal_Int32 nIdentifier, const OUString& rModuleName )
@@ -2881,7 +2902,52 @@ void SAL_CALL SfxLibraryContainer::broadcastVBAScriptEvent( sal_Int32 nIdentifie
Reference< XModel > xModel = mxOwnerDocument; // weak-ref -> ref
vba::VBAScriptEvent aEvent( Reference<XInterface>(xModel, UNO_QUERY), nIdentifier, rModuleName );
- maVBAScriptListeners.notify( aEvent );
+ maVBAScriptListeners.notifyEach( &css::script::vba::XVBAScriptListener::notifyVBAScriptEvent, aEvent );
+}
+
+// Methods XPropertySet
+css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL SfxLibraryContainer::getPropertySetInfo()
+{
+ return uno::Reference<beans::XPropertySetInfo>();
+}
+
+void SAL_CALL SfxLibraryContainer::setPropertyValue(const OUString& aPropertyName,
+ const uno::Any& aValue)
+{
+ if (aPropertyName != sVBATextEncodingPropName)
+ throw UnknownPropertyException(aPropertyName, getXWeak());
+ aValue >>= meVBATextEncoding;
+}
+
+css::uno::Any SAL_CALL SfxLibraryContainer::getPropertyValue(const OUString& aPropertyName)
+{
+ if (aPropertyName == sVBATextEncodingPropName)
+ return uno::Any(meVBATextEncoding);
+ throw UnknownPropertyException(aPropertyName, getXWeak());
+}
+
+void SAL_CALL SfxLibraryContainer::addPropertyChangeListener(
+ const OUString& /* aPropertyName */, const Reference<XPropertyChangeListener>& /* xListener */)
+{
+ throw NoSupportException();
+}
+
+void SAL_CALL SfxLibraryContainer::removePropertyChangeListener(
+ const OUString& /* aPropertyName */, const Reference<XPropertyChangeListener>& /* aListener */)
+{
+ throw NoSupportException();
+}
+
+void SAL_CALL SfxLibraryContainer::addVetoableChangeListener(
+ const OUString& /* PropertyName */, const Reference<XVetoableChangeListener>& /* aListener */)
+{
+ throw NoSupportException();
+}
+
+void SAL_CALL SfxLibraryContainer::removeVetoableChangeListener(
+ const OUString& /* PropertyName */, const Reference<XVetoableChangeListener>& /* aListener */)
+{
+ throw NoSupportException();
}
// Methods XServiceInfo
@@ -2895,8 +2961,7 @@ sal_Bool SAL_CALL SfxLibraryContainer::supportsService( const OUString& _rServic
// Ctor
SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
const Reference< XSimpleFileAccess3 >& xSFI )
- : OComponentHelper( m_aMutex )
- , mxSFI( xSFI )
+ : mxSFI( xSFI )
, mrModifiable( _rModifiable )
, maNameContainer( new NameContainer(aType) )
, mbLoaded( true )
@@ -2916,16 +2981,15 @@ SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
const Reference< XSimpleFileAccess3 >& xSFI,
- const OUString& aLibInfoFileURL, const OUString& aStorageURL, bool ReadOnly )
- : OComponentHelper( m_aMutex )
- , mxSFI( xSFI )
+ OUString aLibInfoFileURL, OUString aStorageURL, bool ReadOnly )
+ : mxSFI( xSFI )
, mrModifiable( _rModifiable )
, maNameContainer( new NameContainer(aType) )
, mbLoaded( false )
, mbIsModified( true )
, mbInitialised( false )
- , maLibInfoFileURL( aLibInfoFileURL )
- , maStorageURL( aStorageURL )
+ , maLibInfoFileURL(std::move( aLibInfoFileURL ))
+ , maStorageURL(std::move( aStorageURL ))
, mbLink( true )
, mbReadOnly( false )
, mbReadOnlyLink( ReadOnly )
@@ -2969,7 +3033,7 @@ Any SAL_CALL SfxLibrary::queryInterface( const Type& rType )
static_cast< XChangesNotifier * >( this ) );
if( !aRet.hasValue() )
{
- aRet = OComponentHelper::queryInterface( rType );
+ aRet = WeakComponentImplHelper::queryInterface( rType );
}
return aRet;
}
@@ -3011,7 +3075,7 @@ void SfxLibrary::impl_checkReadOnly()
if( mbReadOnly || (mbLink && mbReadOnlyLink) )
{
throw IllegalArgumentException(
- "Library is readonly.",
+ u"Library is readonly."_ustr,
// TODO: resource
*this, 0
);
@@ -3105,7 +3169,7 @@ Sequence< Type > SfxLibrary::getTypes()
cppu::UnoType<XNameContainer>::get(),
cppu::UnoType<XContainer>::get(),
cppu::UnoType<XChangesNotifier>::get(),
- OComponentHelper::getTypes() );
+ WeakComponentImplHelper::getTypes() );
return ourTypes_NameContainer.getTypes();
}
@@ -3119,7 +3183,7 @@ Sequence< sal_Int8 > SfxLibrary::getImplementationId()
// Methods XContainer
void SAL_CALL SfxLibrary::addContainerListener( const Reference< XContainerListener >& xListener )
{
- maNameContainer->setEventSource( static_cast< XInterface* >( static_cast<OWeakObject*>(this) ) );
+ maNameContainer->setEventSource( getXWeak() );
maNameContainer->addContainerListener( xListener );
}
@@ -3131,7 +3195,7 @@ void SAL_CALL SfxLibrary::removeContainerListener( const Reference< XContainerLi
// Methods XChangesNotifier
void SAL_CALL SfxLibrary::addChangesListener( const Reference< XChangesListener >& xListener )
{
- maNameContainer->setEventSource( static_cast< XInterface* >( static_cast<OWeakObject*>(this) ) );
+ maNameContainer->setEventSource( getXWeak() );
maNameContainer->addChangesListener( xListener );
}
@@ -3313,7 +3377,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextUserScript
try
{
Reference< XExtensionManager > xManager = ExtensionManager::get( m_xContext );
- m_aUserPackagesSeq = xManager->getDeployedExtensions("user",
+ m_aUserPackagesSeq = xManager->getDeployedExtensions(u"user"_ustr,
Reference< task::XAbortChannel >(),
Reference< ucb::XCommandEnvironment >() );
}
@@ -3365,7 +3429,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextSharedScri
try
{
Reference< XExtensionManager > xSharedManager = ExtensionManager::get( m_xContext );
- m_aSharedPackagesSeq = xSharedManager->getDeployedExtensions("shared",
+ m_aSharedPackagesSeq = xSharedManager->getDeployedExtensions(u"shared"_ustr,
Reference< task::XAbortChannel >(),
Reference< ucb::XCommandEnvironment >() );
}
@@ -3416,7 +3480,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextBundledScr
try
{
Reference< XExtensionManager > xManager = ExtensionManager::get( m_xContext );
- m_aBundledPackagesSeq = xManager->getDeployedExtensions("bundled",
+ m_aBundledPackagesSeq = xManager->getDeployedExtensions(u"bundled"_ustr,
Reference< task::XAbortChannel >(),
Reference< ucb::XCommandEnvironment >() );
}