1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "documentcontainer.hxx"
21 #include <stringconstants.hxx>
22 #include "documentdefinition.hxx"
23 #include <ModelImpl.hxx>
24 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
25 #include <com/sun/star/ucb/OpenMode.hpp>
26 #include <connectivity/dbtools.hxx>
27 #include "myucp_resultset.hxx"
28 #include <ucbhelper/cancelcommandexecution.hxx>
29 #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
30 #include <com/sun/star/ucb/InsertCommandArgument.hpp>
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/sdb/ErrorCondition.hpp>
33 #include <comphelper/mimeconfighelper.hxx>
34 #include <connectivity/sqlerror.hxx>
35 #include <core_resource.hxx>
36 #include <strings.hrc>
37 #include <strings.hxx>
38 #include <comphelper/namedvaluecollection.hxx>
39 #include <comphelper/propertysequence.hxx>
40 #include <comphelper/servicehelper.hxx>
41 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
43 #include <vcl/svapp.hxx>
44 #include <osl/mutex.hxx>
45 #include <o3tl/string_view.hxx>
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::lang
;
49 using namespace ::com::sun::star::embed
;
50 using namespace ::com::sun::star::beans
;
51 using namespace ::com::sun::star::container
;
52 using namespace ::com::sun::star::ucb
;
53 using namespace ::com::sun::star::sdbc
;
54 using namespace ::com::sun::star::sdb
;
55 using namespace ::osl
;
56 using namespace ::comphelper
;
57 using namespace ::cppu
;
65 class LocalNameApproval
: public IContainerApprove
67 ::connectivity::SQLError m_aErrors
;
70 void approveElement( const OUString
& _rName
) override
;
75 void LocalNameApproval::approveElement( const OUString
& _rName
)
77 if ( _rName
.indexOf( '/' ) != -1 )
78 throw IllegalArgumentException(
79 m_aErrors
.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES
),
87 ODocumentContainer::ODocumentContainer(const Reference
< XComponentContext
>& _xORB
88 ,const Reference
< XInterface
>& _xParentContainer
89 ,const TContentPtr
& _pImpl
90 , bool _bFormsContainer
92 :ODefinitionContainer(_xORB
,_xParentContainer
,_pImpl
)
93 ,OPropertyStateContainer(OContentHelper::rBHelper
)
94 ,m_bFormsContainer(_bFormsContainer
)
96 registerProperty(PROPERTY_NAME
, PROPERTY_ID_NAME
, PropertyAttribute::BOUND
| PropertyAttribute::READONLY
| PropertyAttribute::CONSTRAINED
,
97 &m_pImpl
->m_aProps
.aTitle
, cppu::UnoType
<decltype(m_pImpl
->m_aProps
.aTitle
)>::get());
99 setElementApproval( std::make_shared
<LocalNameApproval
>() );
102 ODocumentContainer::~ODocumentContainer()
105 if ( !OContentHelper::rBHelper
.bInDispose
&& !OContentHelper::rBHelper
.bDisposed
)
112 IMPLEMENT_FORWARD_XINTERFACE3( ODocumentContainer
,ODefinitionContainer
,ODocumentContainer_Base
,OPropertyStateContainer
)
114 css::uno::Sequence
<sal_Int8
> ODocumentContainer::getImplementationId()
116 return css::uno::Sequence
<sal_Int8
>();
119 css::uno::Sequence
< css::uno::Type
> ODocumentContainer::getTypes()
121 return ::comphelper::concatSequences(
122 ODefinitionContainer::getTypes( ),
123 OPropertyStateContainer::getTypes( ),
124 ODocumentContainer_Base::getTypes( )
127 OUString SAL_CALL
ODocumentContainer::getImplementationName()
129 return u
"com.sun.star.comp.dba.ODocumentContainer"_ustr
;
131 sal_Bool SAL_CALL
ODocumentContainer::supportsService(const OUString
& _rServiceName
)
133 const css::uno::Sequence
< OUString
> aSupported(getSupportedServiceNames());
134 for (const OUString
& s
: aSupported
)
135 if (s
== _rServiceName
)
140 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
ODocumentContainer::getPropertySetInfo()
142 Reference
< XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
145 ::cppu::IPropertyArrayHelper
& ODocumentContainer::getInfoHelper()
147 return *ODocumentContainer::getArrayHelper();
149 ::cppu::IPropertyArrayHelper
* ODocumentContainer::createArrayHelper( ) const
151 css::uno::Sequence
< css::beans::Property
> aProps
;
152 describeProperties(aProps
);
153 return new ::cppu::OPropertyArrayHelper(aProps
);
157 Sequence
< OUString
> SAL_CALL
ODocumentContainer::getSupportedServiceNames( )
159 return { m_bFormsContainer
? SERVICE_NAME_FORM_COLLECTION
: SERVICE_NAME_REPORT_COLLECTION
};
162 OUString
ODocumentContainer::determineContentType() const
167 Reference
< XContent
> ODocumentContainer::createObject( const OUString
& _rName
)
169 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
170 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( _rName
);
171 OSL_ENSURE( aFind
!= rDefinitions
.end(), "ODocumentContainer::createObject:Invalid entry in map!" );
172 if ( aFind
->second
->m_aProps
.bIsFolder
)
173 return new ODocumentContainer( m_aContext
, *this, aFind
->second
, m_bFormsContainer
);
174 return new ODocumentDefinition( *this, m_aContext
, aFind
->second
, m_bFormsContainer
);
177 Reference
< XInterface
> SAL_CALL
ODocumentContainer::createInstance( const OUString
& aServiceSpecifier
)
179 return createInstanceWithArguments( aServiceSpecifier
, Sequence
< Any
>() );
184 template< class TYPE
>
185 void lcl_extractAndRemove( ::comphelper::NamedValueCollection
& io_rArguments
, const OUString
& i_rName
, TYPE
& o_rValue
)
187 if ( io_rArguments
.has( i_rName
) )
189 io_rArguments
.get_ensureType( i_rName
, o_rValue
);
190 io_rArguments
.remove( i_rName
);
195 Reference
< XInterface
> SAL_CALL
ODocumentContainer::createInstanceWithArguments( const OUString
& ServiceSpecifier
, const Sequence
< Any
>& _aArguments
)
197 Reference
< XInterface
> xRet
;
198 Reference
< XContent
> xContent
;
199 if ( ServiceSpecifier
== SERVICE_SDB_DOCUMENTDEFINITION
)
201 MutexGuard
aGuard(m_aMutex
);
203 // extract known arguments
204 OUString sName
, sPersistentName
, sURL
, sMediaType
, sDocServiceName
;
205 Reference
< XCommandProcessor
> xCopyFrom
;
206 Reference
< XConnection
> xConnection
;
207 bool bAsTemplate( false );
208 Sequence
< sal_Int8
> aClassID
;
210 ::comphelper::NamedValueCollection
aArgs( _aArguments
);
211 lcl_extractAndRemove( aArgs
, PROPERTY_NAME
, sName
);
212 lcl_extractAndRemove( aArgs
, PROPERTY_PERSISTENT_NAME
, sPersistentName
);
213 lcl_extractAndRemove( aArgs
, PROPERTY_URL
, sURL
);
214 lcl_extractAndRemove( aArgs
, PROPERTY_EMBEDDEDOBJECT
, xCopyFrom
);
215 lcl_extractAndRemove( aArgs
, PROPERTY_ACTIVE_CONNECTION
, xConnection
);
216 lcl_extractAndRemove( aArgs
, PROPERTY_AS_TEMPLATE
, bAsTemplate
);
217 lcl_extractAndRemove( aArgs
, INFO_MEDIATYPE
, sMediaType
);
218 lcl_extractAndRemove( aArgs
, u
"DocumentServiceName"_ustr
, sDocServiceName
);
220 // ClassID has two allowed types, so a special treatment here
221 Any aClassIDArg
= aArgs
.get( u
"ClassID"_ustr
);
222 if ( aClassIDArg
.hasValue() )
224 if ( !( aClassIDArg
>>= aClassID
) )
226 // Extended for usage also with a string
227 OUString sClassIDString
;
228 if ( !( aClassIDArg
>>= sClassIDString
) )
229 throw IllegalArgumentException( OUString(), *this, 2 );
231 aClassID
= ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( sClassIDString
);
234 #if OSL_DEBUG_LEVEL > 0
235 OUString sClassIDString
= ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation( aClassID
);
236 (void)sClassIDString
;
238 aArgs
.remove( u
"ClassID"_ustr
);
240 // Everything which now is still present in the arguments is passed to the embedded object
241 const Sequence
< PropertyValue
> aCreationArgs( aArgs
.getPropertyValues() );
243 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
244 bool bNew
= sPersistentName
.isEmpty();
247 sPersistentName
= "Obj" + OUString::number(rDefinitions
.size() + 1);
248 Reference
<XNameAccess
> xElements
= getContainerStorage();
249 if ( xElements
.is() )
250 sPersistentName
= ::dbtools::createUniqueName(xElements
,sPersistentName
);
252 const bool bNeedClassID
= !aClassID
.hasElements() && sURL
.isEmpty() ;
253 if ( xCopyFrom
.is() )
255 Sequence
<Any
> aIni
{ Any(getContainerStorage()), Any(sPersistentName
) };
257 aCommand
.Name
= "copyTo";
258 aCommand
.Argument
<<= aIni
;
260 xCopyFrom
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
261 Reference
<XPropertySet
> xProp(xCopyFrom
,UNO_QUERY
);
262 if ( xProp
.is() && xProp
->getPropertySetInfo().is() && xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE
) )
263 xProp
->getPropertyValue(PROPERTY_AS_TEMPLATE
) >>= bAsTemplate
;
265 // if we do not have an own class ID, see if we can determine one from the copy we just created
267 ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName
, m_aContext
, aClassID
);
273 if ( !sMediaType
.isEmpty() )
274 ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType
, m_aContext
, aClassID
);
275 else if ( !sDocServiceName
.isEmpty() )
277 ::comphelper::MimeConfigurationHelper
aConfigHelper( m_aContext
);
278 const Sequence
< NamedValue
> aProps( aConfigHelper
.GetObjectPropsByDocumentName( sDocServiceName
) );
279 const ::comphelper::NamedValueCollection
aMediaTypeProps( aProps
);
280 aClassID
= aMediaTypeProps
.getOrDefault( u
"ClassID"_ustr
, Sequence
< sal_Int8
>() );
286 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
287 TContentPtr pElementImpl
;
288 if ( bNew
|| ( aFind
== rDefinitions
.end() ) )
290 pElementImpl
= std::make_shared
<OContentHelper_Impl
>();
292 pElementImpl
->m_aProps
.aTitle
= sName
;
294 pElementImpl
->m_aProps
.sPersistentName
= sPersistentName
;
295 pElementImpl
->m_aProps
.bAsTemplate
= bAsTemplate
;
296 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
299 pElementImpl
= aFind
->second
;
301 ::rtl::Reference
< ODocumentDefinition
> pDocDef
= new ODocumentDefinition( *this, m_aContext
, pElementImpl
, m_bFormsContainer
);
302 if ( aClassID
.hasElements() )
304 pDocDef
->initialLoad( aClassID
, aCreationArgs
, xConnection
);
308 OSL_ENSURE( !aCreationArgs
.hasElements(), "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." );
310 xContent
= pDocDef
.get();
312 if ( !sURL
.isEmpty() )
314 Sequence
<Any
> aIni
{ Any(sURL
) };
316 aCommand
.Name
= "insert";
317 aCommand
.Argument
<<= aIni
;
318 Reference
< XCommandProcessor
> xCommandProcessor(xContent
,UNO_QUERY
);
321 xCommandProcessor
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
325 else if ( ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
|| SERVICE_NAME_REPORT_COLLECTION
== ServiceSpecifier
)
328 Reference
<XNameAccess
> xCopyFrom
;
329 for (auto& arg
: _aArguments
)
331 PropertyValue aValue
;
333 if ( aValue
.Name
== PROPERTY_NAME
)
335 aValue
.Value
>>= sName
;
337 else if ( aValue
.Name
== PROPERTY_EMBEDDEDOBJECT
)
339 xCopyFrom
.set(aValue
.Value
,UNO_QUERY
);
342 OSL_ENSURE(!sName
.isEmpty(),"Invalid name for a document container!");
343 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
344 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
345 TContentPtr pElementImpl
;
346 if ( aFind
== rDefinitions
.end() )
348 pElementImpl
= std::make_shared
<ODefinitionContainer_Impl
>();
349 pElementImpl
->m_aProps
.aTitle
= sName
;
350 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
353 pElementImpl
= aFind
->second
;
354 OSL_ENSURE( pElementImpl
," Invalid entry in map!");
355 xContent
= new ODocumentContainer( m_aContext
, *this, pElementImpl
, ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
);
358 if ( xCopyFrom
.is() )
360 Reference
<XContent
> xObjectToCopy
;
362 Reference
<XMultiServiceFactory
> xORB(xContent
,UNO_QUERY
);
363 OSL_ENSURE(xORB
.is(),"No service factory given");
366 for (auto& element
: xCopyFrom
->getElementNames())
368 xCopyFrom
->getByName(element
) >>= xObjectToCopy
;
369 Sequence
<Any
> aArguments(comphelper::InitAnyPropertySequence(
371 {"Name", Any(element
)}, // set as folder
372 {"Parent", Any(xContent
)},
373 {PROPERTY_EMBEDDEDOBJECT
, Any(xObjectToCopy
)},
376 OUString sServiceName
;
377 if ( Reference
< XNameAccess
>( xObjectToCopy
, UNO_QUERY
).is() )
379 if ( m_bFormsContainer
)
380 sServiceName
= SERVICE_NAME_FORM_COLLECTION
;
382 sServiceName
= SERVICE_NAME_REPORT_COLLECTION
;
385 sServiceName
= SERVICE_SDB_DOCUMENTDEFINITION
;
387 Reference
<XContent
> xNew(xORB
->createInstanceWithArguments(sServiceName
,aArguments
),UNO_QUERY
);
388 Reference
<XNameContainer
> xNameContainer(xContent
,UNO_QUERY
);
389 if ( xNameContainer
.is() )
390 xNameContainer
->insertByName(element
, Any(xNew
));
399 Sequence
< OUString
> SAL_CALL
ODocumentContainer::getAvailableServiceNames( )
403 SERVICE_SDB_DOCUMENTDEFINITION
,
404 SERVICE_NAME_FORM_COLLECTION
,
405 SERVICE_NAME_REPORT_COLLECTION
409 Any SAL_CALL
ODocumentContainer::execute( const Command
& aCommand
, sal_Int32 CommandId
, const Reference
< XCommandEnvironment
>& Environment
)
412 if ( aCommand
.Name
== "open" )
414 // open command for a folder content
415 OpenCommandArgument2 aOpenCommand
;
416 if ( !( aCommand
.Argument
>>= aOpenCommand
) )
418 OSL_FAIL( "Wrong argument type!" );
419 ucbhelper::cancelCommandExecution(
420 Any( IllegalArgumentException(
422 static_cast< cppu::OWeakObject
* >( this ),
428 ( ( aOpenCommand
.Mode
== OpenMode::ALL
) ||
429 ( aOpenCommand
.Mode
== OpenMode::FOLDERS
) ||
430 ( aOpenCommand
.Mode
== OpenMode::DOCUMENTS
) );
434 // open as folder - return result set
436 Reference
< XDynamicResultSet
> xSet
437 = new DynamicResultSet( m_aContext
,
446 ucbhelper::cancelCommandExecution(
447 Any( UnsupportedOpenModeException(
449 static_cast< cppu::OWeakObject
* >( this ),
450 sal_Int16( aOpenCommand
.Mode
) ) ),
455 else if ( aCommand
.Name
== "insert" )
459 InsertCommandArgument arg
;
460 if ( !( aCommand
.Argument
>>= arg
) )
462 OSL_FAIL( "Wrong argument type!" );
463 ucbhelper::cancelCommandExecution(
464 Any( IllegalArgumentException(
466 static_cast< cppu::OWeakObject
* >( this ),
472 else if ( aCommand
.Name
== "delete" )
475 for (auto& name
: getElementNames())
481 aRet
= OContentHelper::execute(aCommand
,CommandId
,Environment
);
487 bool lcl_queryContent(std::u16string_view _sName
,Reference
< XNameContainer
>& _xNameContainer
,Any
& _rRet
,OUString
& _sSimpleName
)
489 sal_Int32 nIndex
= 0;
490 OUString
sName( o3tl::getToken(_sName
,0,'/',nIndex
) );
491 bool bRet
= _xNameContainer
->hasByName(sName
);
494 _sSimpleName
= sName
;
495 _rRet
= _xNameContainer
->getByName(_sSimpleName
);
496 while ( nIndex
!= -1 && bRet
)
498 sName
= o3tl::getToken(_sName
,0,'/',nIndex
);
499 _xNameContainer
.set(_rRet
,UNO_QUERY
);
500 bRet
= _xNameContainer
.is();
503 bRet
= _xNameContainer
->hasByName(sName
);
504 _sSimpleName
= sName
;
506 _rRet
= _xNameContainer
->getByName(sName
);
511 _sSimpleName
= sName
; // a content
513 _xNameContainer
.clear(); // a sub folder doesn't exist
518 Reference
< XComponent
> SAL_CALL
ODocumentContainer::loadComponentFromURL( const OUString
& _sURL
519 , const OUString
& /*TargetFrameName*/
520 , sal_Int32
/*SearchFlags*/
521 , const Sequence
< PropertyValue
>& Arguments
)
523 ::SolarMutexGuard aSolarGuard
;
525 MutexGuard
aGuard(m_aMutex
);
526 Reference
< XComponent
> xComp
;
530 Reference
< XNameContainer
> xNameContainer(this);
532 if ( !lcl_queryContent(_sURL
,xNameContainer
,aContent
,sName
) )
535 DBA_RES(RID_STR_NAME_NOT_FOUND
).replaceFirst("$name$", _sURL
));
536 throw IllegalArgumentException( sMessage
, *this, 1 );
539 Reference
< XCommandProcessor
> xContent(aContent
,UNO_QUERY
);
544 ::comphelper::NamedValueCollection
aArgs( Arguments
);
545 aCommand
.Name
= aArgs
.getOrDefault( u
"OpenMode"_ustr
, u
"open"_ustr
);
546 aArgs
.remove( u
"OpenMode"_ustr
);
548 OpenCommandArgument2 aOpenCommand
;
549 aOpenCommand
.Mode
= OpenMode::DOCUMENT
;
550 aArgs
.put( u
"OpenCommandArgument"_ustr
, aOpenCommand
);
552 aCommand
.Argument
<<= aArgs
.getPropertyValues();
553 xComp
.set(xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>()),UNO_QUERY
);
556 catch(const NoSuchElementException
&)
558 throw IllegalArgumentException();
560 catch(const WrappedTargetException
&e
)
562 throw WrappedTargetRuntimeException(e
.Message
, e
.Context
, e
.TargetException
);
567 Any SAL_CALL
ODocumentContainer::getByHierarchicalName( const OUString
& _sName
)
569 MutexGuard
aGuard(m_aMutex
);
571 Reference
< XNameContainer
> xNameContainer(this);
573 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
575 throw NoSuchElementException(_sName
,*this);
578 sal_Bool SAL_CALL
ODocumentContainer::hasByHierarchicalName( const OUString
& _sName
)
580 MutexGuard
aGuard(m_aMutex
);
582 Reference
< XNameContainer
> xNameContainer(this);
584 return lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
);
587 // XHierarchicalNameContainer
588 void SAL_CALL
ODocumentContainer::insertByHierarchicalName( const OUString
& _sName
, const Any
& _aElement
)
590 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
591 if ( !xContent
.is() )
592 throw IllegalArgumentException();
594 MutexGuard
aGuard(m_aMutex
);
596 Reference
< XNameContainer
> xNameContainer(this);
598 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
599 throw ElementExistException(_sName
,*this);
601 if ( !xNameContainer
.is() )
603 sal_Int32 index
= sName
.getLength();
605 DBA_RES(RID_STR_NO_SUB_FOLDER
).replaceFirst("$folder$",
606 o3tl::getToken(_sName
, 0,'/',index
)));
607 throw IllegalArgumentException( sMessage
, *this, 1 );
610 xNameContainer
->insertByName(sName
,_aElement
);
613 void SAL_CALL
ODocumentContainer::removeByHierarchicalName( const OUString
& _sName
)
615 if ( _sName
.isEmpty() )
616 throw NoSuchElementException(_sName
,*this);
618 MutexGuard
aGuard(m_aMutex
);
621 Reference
< XNameContainer
> xNameContainer(this);
622 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
623 throw NoSuchElementException(_sName
,*this);
625 xNameContainer
->removeByName(sName
);
628 // XHierarchicalNameReplace
629 void SAL_CALL
ODocumentContainer::replaceByHierarchicalName( const OUString
& _sName
, const Any
& _aElement
)
631 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
632 if ( !xContent
.is() )
633 throw IllegalArgumentException();
635 MutexGuard
aGuard(m_aMutex
);
638 Reference
< XNameContainer
> xNameContainer(this);
639 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
640 throw NoSuchElementException(_sName
,*this);
642 xNameContainer
->replaceByName(sName
,_aElement
);
645 OUString SAL_CALL
ODocumentContainer::getHierarchicalName()
647 ::osl::MutexGuard
aGuard( m_aMutex
);
648 return impl_getHierarchicalName( false );
651 OUString SAL_CALL
ODocumentContainer::composeHierarchicalName( const OUString
& i_rRelativeName
)
653 OUString aBuffer
= getHierarchicalName() + "/" + i_rRelativeName
;
657 ::rtl::Reference
<OContentHelper
> ODocumentContainer::getContent(const OUString
& _sName
) const
659 ::rtl::Reference
<OContentHelper
> pContent
;
662 pContent
= dynamic_cast<OContentHelper
*>(const_cast<ODocumentContainer
*>(this)->implGetByName( _sName
, true ).get());
664 catch(const Exception
&)
670 void ODocumentContainer::getPropertyDefaultByHandle( sal_Int32
/*_nHandle*/, Any
& _rDefault
) const
675 void SAL_CALL
ODocumentContainer::commit( )
677 MutexGuard
aGuard(m_aMutex
);
678 for (auto const& elem
: m_aDocumentMap
)
680 Reference
<XTransactedObject
> xTrans(elem
.second
.get(),UNO_QUERY
);
684 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
689 void SAL_CALL
ODocumentContainer::revert( )
691 MutexGuard
aGuard(m_aMutex
);
692 for (auto const& elem
: m_aDocumentMap
)
694 Reference
<XTransactedObject
> xTrans(elem
.second
.get(),UNO_QUERY
);
698 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
703 Reference
< XStorage
> ODocumentContainer::getContainerStorage() const
705 return m_pImpl
->m_pDataSource
706 ? m_pImpl
->m_pDataSource
->getStorage( m_bFormsContainer
? ODatabaseModelImpl::ObjectType::Form
: ODatabaseModelImpl::ObjectType::Report
)
707 : Reference
< XStorage
>();
710 void SAL_CALL
ODocumentContainer::removeByName( const OUString
& _rName
)
712 ResettableMutexGuard
aGuard(m_aMutex
);
714 // check the arguments
715 if (_rName
.isEmpty())
716 throw IllegalArgumentException();
718 if (!checkExistence(_rName
))
719 throw NoSuchElementException(_rName
,*this);
721 Reference
< XCommandProcessor
> xContent( implGetByName( _rName
, true ), UNO_QUERY
);
726 aCommand
.Name
= "delete";
727 xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>());
733 notifyByName( aGuard
, _rName
, nullptr, nullptr, E_REMOVED
, ContainerListemers
);
736 void SAL_CALL
ODocumentContainer::rename( const OUString
& newName
)
740 osl::ClearableGuard
< osl::Mutex
> aGuard(m_aMutex
);
741 if ( newName
== m_pImpl
->m_aProps
.aTitle
)
744 sal_Int32 nHandle
= PROPERTY_ID_NAME
;
745 Any
aOld(m_pImpl
->m_aProps
.aTitle
);
749 fire(&nHandle
, &aNew
, &aOld
, 1, true );
750 m_pImpl
->m_aProps
.aTitle
= newName
;
751 fire(&nHandle
, &aNew
, &aOld
, 1, false );
753 catch(const PropertyVetoException
&)
755 throw ElementExistException(newName
,*this);
759 } // namespace dbaccess
761 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */