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 <comphelper/namedvaluecollection.hxx>
38 #include <comphelper/propertysequence.hxx>
39 #include <comphelper/servicehelper.hxx>
40 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
42 #include <vcl/svapp.hxx>
43 #include <osl/mutex.hxx>
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::lang
;
47 using namespace ::com::sun::star::embed
;
48 using namespace ::com::sun::star::beans
;
49 using namespace ::com::sun::star::container
;
50 using namespace ::com::sun::star::ucb
;
51 using namespace ::com::sun::star::sdbc
;
52 using namespace ::com::sun::star::sdb
;
53 using namespace ::com::sun::star::io
;
54 using namespace ::osl
;
55 using namespace ::comphelper
;
56 using namespace ::cppu
;
64 class LocalNameApproval
: public IContainerApprove
66 ::connectivity::SQLError m_aErrors
;
69 void approveElement( const OUString
& _rName
) override
;
74 void LocalNameApproval::approveElement( const OUString
& _rName
)
76 if ( _rName
.indexOf( '/' ) != -1 )
77 throw IllegalArgumentException(
78 m_aErrors
.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES
),
86 ODocumentContainer::ODocumentContainer(const Reference
< XComponentContext
>& _xORB
87 ,const Reference
< XInterface
>& _xParentContainer
88 ,const TContentPtr
& _pImpl
89 , bool _bFormsContainer
91 :ODefinitionContainer(_xORB
,_xParentContainer
,_pImpl
)
92 ,OPropertyStateContainer(OContentHelper::rBHelper
)
93 ,m_bFormsContainer(_bFormsContainer
)
95 registerProperty(PROPERTY_NAME
, PROPERTY_ID_NAME
, PropertyAttribute::BOUND
| PropertyAttribute::READONLY
| PropertyAttribute::CONSTRAINED
,
96 &m_pImpl
->m_aProps
.aTitle
, cppu::UnoType
<decltype(m_pImpl
->m_aProps
.aTitle
)>::get());
98 setElementApproval( std::make_shared
<LocalNameApproval
>() );
101 ODocumentContainer::~ODocumentContainer()
104 if ( !OContentHelper::rBHelper
.bInDispose
&& !OContentHelper::rBHelper
.bDisposed
)
111 IMPLEMENT_FORWARD_XINTERFACE3( ODocumentContainer
,ODefinitionContainer
,ODocumentContainer_Base
,OPropertyStateContainer
)
113 css::uno::Sequence
<sal_Int8
> ODocumentContainer::getImplementationId()
115 return css::uno::Sequence
<sal_Int8
>();
118 IMPLEMENT_GETTYPES3(ODocumentContainer
,ODefinitionContainer
,OPropertyStateContainer
,ODocumentContainer_Base
);
119 IMPLEMENT_SERVICE_INFO_IMPLNAME(ODocumentContainer
, "com.sun.star.comp.dba.ODocumentContainer");
120 IMPLEMENT_SERVICE_INFO_SUPPORTS(ODocumentContainer
);
121 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS(ODocumentContainer
)
123 Sequence
< OUString
> SAL_CALL
ODocumentContainer::getSupportedServiceNames( )
125 return { m_bFormsContainer
? OUString(SERVICE_NAME_FORM_COLLECTION
) : OUString(SERVICE_NAME_REPORT_COLLECTION
) };
128 OUString
ODocumentContainer::determineContentType() const
133 Reference
< XContent
> ODocumentContainer::createObject( const OUString
& _rName
)
135 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
136 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( _rName
);
137 OSL_ENSURE( aFind
!= rDefinitions
.end(), "ODocumentContainer::createObject:Invalid entry in map!" );
138 if ( aFind
->second
->m_aProps
.bIsFolder
)
139 return new ODocumentContainer( m_aContext
, *this, aFind
->second
, m_bFormsContainer
);
140 return new ODocumentDefinition( *this, m_aContext
, aFind
->second
, m_bFormsContainer
);
143 Reference
< XInterface
> SAL_CALL
ODocumentContainer::createInstance( const OUString
& aServiceSpecifier
)
145 return createInstanceWithArguments( aServiceSpecifier
, Sequence
< Any
>() );
150 template< class TYPE
>
151 void lcl_extractAndRemove( ::comphelper::NamedValueCollection
& io_rArguments
, const OUString
& i_rName
, TYPE
& o_rValue
)
153 if ( io_rArguments
.has( i_rName
) )
155 io_rArguments
.get_ensureType( i_rName
, o_rValue
);
156 io_rArguments
.remove( i_rName
);
161 Reference
< XInterface
> SAL_CALL
ODocumentContainer::createInstanceWithArguments( const OUString
& ServiceSpecifier
, const Sequence
< Any
>& _aArguments
)
163 Reference
< XInterface
> xRet
;
164 Reference
< XContent
> xContent
;
165 if ( ServiceSpecifier
== SERVICE_SDB_DOCUMENTDEFINITION
)
167 MutexGuard
aGuard(m_aMutex
);
169 // extract known arguments
170 OUString sName
, sPersistentName
, sURL
, sMediaType
, sDocServiceName
;
171 Reference
< XCommandProcessor
> xCopyFrom
;
172 Reference
< XConnection
> xConnection
;
173 bool bAsTemplate( false );
174 Sequence
< sal_Int8
> aClassID
;
176 ::comphelper::NamedValueCollection
aArgs( _aArguments
);
177 lcl_extractAndRemove( aArgs
, PROPERTY_NAME
, sName
);
178 lcl_extractAndRemove( aArgs
, PROPERTY_PERSISTENT_NAME
, sPersistentName
);
179 lcl_extractAndRemove( aArgs
, PROPERTY_URL
, sURL
);
180 lcl_extractAndRemove( aArgs
, PROPERTY_EMBEDDEDOBJECT
, xCopyFrom
);
181 lcl_extractAndRemove( aArgs
, PROPERTY_ACTIVE_CONNECTION
, xConnection
);
182 lcl_extractAndRemove( aArgs
, PROPERTY_AS_TEMPLATE
, bAsTemplate
);
183 lcl_extractAndRemove( aArgs
, INFO_MEDIATYPE
, sMediaType
);
184 lcl_extractAndRemove( aArgs
, "DocumentServiceName" , sDocServiceName
);
186 // ClassID has two allowed types, so a special treatment here
187 Any aClassIDArg
= aArgs
.get( "ClassID" );
188 if ( aClassIDArg
.hasValue() )
190 if ( !( aClassIDArg
>>= aClassID
) )
192 // Extended for usage also with a string
193 OUString sClassIDString
;
194 if ( !( aClassIDArg
>>= sClassIDString
) )
195 throw IllegalArgumentException( OUString(), *this, 2 );
197 aClassID
= ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( sClassIDString
);
200 #if OSL_DEBUG_LEVEL > 0
201 OUString sClassIDString
= ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation( aClassID
);
202 (void)sClassIDString
;
204 aArgs
.remove( "ClassID" );
206 // Everything which now is still present in the arguments is passed to the embedded object
207 const Sequence
< PropertyValue
> aCreationArgs( aArgs
.getPropertyValues() );
209 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
210 bool bNew
= sPersistentName
.isEmpty();
213 sPersistentName
= "Obj" + OUString::number(rDefinitions
.size() + 1);
214 Reference
<XNameAccess
> xElements
= getContainerStorage();
215 if ( xElements
.is() )
216 sPersistentName
= ::dbtools::createUniqueName(xElements
,sPersistentName
);
218 const bool bNeedClassID
= !aClassID
.hasElements() && sURL
.isEmpty() ;
219 if ( xCopyFrom
.is() )
221 Sequence
<Any
> aIni(2);
222 aIni
[0] <<= getContainerStorage();
223 aIni
[1] <<= sPersistentName
;
225 aCommand
.Name
= "copyTo";
226 aCommand
.Argument
<<= aIni
;
228 xCopyFrom
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
229 Reference
<XPropertySet
> xProp(xCopyFrom
,UNO_QUERY
);
230 if ( xProp
.is() && xProp
->getPropertySetInfo().is() && xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE
) )
231 xProp
->getPropertyValue(PROPERTY_AS_TEMPLATE
) >>= bAsTemplate
;
233 // if we do not have an own class ID, see if we can determine one from the copy we just created
235 ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName
, m_aContext
, aClassID
);
241 if ( !sMediaType
.isEmpty() )
242 ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType
, m_aContext
, aClassID
);
243 else if ( !sDocServiceName
.isEmpty() )
245 ::comphelper::MimeConfigurationHelper
aConfigHelper( m_aContext
);
246 const Sequence
< NamedValue
> aProps( aConfigHelper
.GetObjectPropsByDocumentName( sDocServiceName
) );
247 const ::comphelper::NamedValueCollection
aMediaTypeProps( aProps
);
248 aClassID
= aMediaTypeProps
.getOrDefault( "ClassID", Sequence
< sal_Int8
>() );
254 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
255 TContentPtr pElementImpl
;
256 if ( bNew
|| ( aFind
== rDefinitions
.end() ) )
258 pElementImpl
= std::make_shared
<OContentHelper_Impl
>();
260 pElementImpl
->m_aProps
.aTitle
= sName
;
262 pElementImpl
->m_aProps
.sPersistentName
= sPersistentName
;
263 pElementImpl
->m_aProps
.bAsTemplate
= bAsTemplate
;
264 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
267 pElementImpl
= aFind
->second
;
269 ::rtl::Reference
< ODocumentDefinition
> pDocDef
= new ODocumentDefinition( *this, m_aContext
, pElementImpl
, m_bFormsContainer
);
270 if ( aClassID
.hasElements() )
272 pDocDef
->initialLoad( aClassID
, aCreationArgs
, xConnection
);
276 OSL_ENSURE( !aCreationArgs
.hasElements(), "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." );
278 xContent
= pDocDef
.get();
280 if ( !sURL
.isEmpty() )
282 Sequence
<Any
> aIni(2);
285 aCommand
.Name
= "insert";
286 aCommand
.Argument
<<= aIni
;
287 Reference
< XCommandProcessor
> xCommandProcessor(xContent
,UNO_QUERY
);
290 xCommandProcessor
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
294 else if ( ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
|| SERVICE_NAME_REPORT_COLLECTION
== ServiceSpecifier
)
296 const Any
* pBegin
= _aArguments
.getConstArray();
297 const Any
* pEnd
= pBegin
+ _aArguments
.getLength();
298 PropertyValue aValue
;
300 Reference
<XNameAccess
> xCopyFrom
;
301 for(;pBegin
!= pEnd
;++pBegin
)
304 if ( aValue
.Name
== PROPERTY_NAME
)
306 aValue
.Value
>>= sName
;
308 else if ( aValue
.Name
== PROPERTY_EMBEDDEDOBJECT
)
310 xCopyFrom
.set(aValue
.Value
,UNO_QUERY
);
313 OSL_ENSURE(!sName
.isEmpty(),"Invalid name for a document container!");
314 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
315 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
316 TContentPtr pElementImpl
;
317 if ( aFind
== rDefinitions
.end() )
319 pElementImpl
= std::make_shared
<ODefinitionContainer_Impl
>();
320 pElementImpl
->m_aProps
.aTitle
= sName
;
321 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
324 pElementImpl
= aFind
->second
;
325 OSL_ENSURE( pElementImpl
," Invalid entry in map!");
326 xContent
= new ODocumentContainer( m_aContext
, *this, pElementImpl
, ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
);
329 if ( xCopyFrom
.is() )
331 Sequence
< OUString
> aSeq
= xCopyFrom
->getElementNames();
332 const OUString
* elements
= aSeq
.getConstArray();
333 const OUString
* elementsEnd
= elements
+ aSeq
.getLength();
334 Reference
<XContent
> xObjectToCopy
;
336 Reference
<XMultiServiceFactory
> xORB(xContent
,UNO_QUERY
);
337 OSL_ENSURE(xORB
.is(),"No service factory given");
340 for(;elements
!= elementsEnd
;++elements
)
342 xCopyFrom
->getByName(*elements
) >>= xObjectToCopy
;
343 Sequence
<Any
> aArguments(comphelper::InitAnyPropertySequence(
345 {"Name", Any(*elements
)}, // set as folder
346 {"Parent", Any(xContent
)},
347 {PROPERTY_EMBEDDEDOBJECT
, Any(xObjectToCopy
)},
350 OUString sServiceName
;
351 if ( Reference
< XNameAccess
>( xObjectToCopy
, UNO_QUERY
).is() )
353 if ( m_bFormsContainer
)
354 sServiceName
= SERVICE_NAME_FORM_COLLECTION
;
356 sServiceName
= SERVICE_NAME_REPORT_COLLECTION
;
359 sServiceName
= SERVICE_SDB_DOCUMENTDEFINITION
;
361 Reference
<XContent
> xNew(xORB
->createInstanceWithArguments(sServiceName
,aArguments
),UNO_QUERY
);
362 Reference
<XNameContainer
> xNameContainer(xContent
,UNO_QUERY
);
363 if ( xNameContainer
.is() )
364 xNameContainer
->insertByName(*elements
,makeAny(xNew
));
373 Sequence
< OUString
> SAL_CALL
ODocumentContainer::getAvailableServiceNames( )
375 Sequence
< OUString
> aSe(3);
376 aSe
[0] = SERVICE_SDB_DOCUMENTDEFINITION
;
377 aSe
[1] = SERVICE_NAME_FORM_COLLECTION
;
378 aSe
[2] = SERVICE_NAME_REPORT_COLLECTION
;
382 Any SAL_CALL
ODocumentContainer::execute( const Command
& aCommand
, sal_Int32 CommandId
, const Reference
< XCommandEnvironment
>& Environment
)
385 if ( aCommand
.Name
== "open" )
387 // open command for a folder content
388 OpenCommandArgument2 aOpenCommand
;
389 if ( !( aCommand
.Argument
>>= aOpenCommand
) )
391 OSL_FAIL( "Wrong argument type!" );
392 ucbhelper::cancelCommandExecution(
393 makeAny( IllegalArgumentException(
395 static_cast< cppu::OWeakObject
* >( this ),
401 ( ( aOpenCommand
.Mode
== OpenMode::ALL
) ||
402 ( aOpenCommand
.Mode
== OpenMode::FOLDERS
) ||
403 ( aOpenCommand
.Mode
== OpenMode::DOCUMENTS
) );
407 // open as folder - return result set
409 Reference
< XDynamicResultSet
> xSet
410 = new DynamicResultSet( m_aContext
,
419 ucbhelper::cancelCommandExecution(
420 makeAny( UnsupportedOpenModeException(
422 static_cast< cppu::OWeakObject
* >( this ),
423 sal_Int16( aOpenCommand
.Mode
) ) ),
428 else if ( aCommand
.Name
== "insert" )
432 InsertCommandArgument arg
;
433 if ( !( aCommand
.Argument
>>= arg
) )
435 OSL_FAIL( "Wrong argument type!" );
436 ucbhelper::cancelCommandExecution(
437 makeAny( IllegalArgumentException(
439 static_cast< cppu::OWeakObject
* >( this ),
445 else if ( aCommand
.Name
== "delete" )
448 Sequence
< OUString
> aSeq
= getElementNames();
449 const OUString
* pIter
= aSeq
.getConstArray();
450 const OUString
* pEnd
= pIter
+ aSeq
.getLength();
451 for(;pIter
!= pEnd
;++pIter
)
452 removeByName(*pIter
);
457 aRet
= OContentHelper::execute(aCommand
,CommandId
,Environment
);
463 bool lcl_queryContent(const OUString
& _sName
,Reference
< XNameContainer
>& _xNameContainer
,Any
& _rRet
,OUString
& _sSimpleName
)
465 sal_Int32 nIndex
= 0;
466 OUString sName
= _sName
.getToken(0,'/',nIndex
);
467 bool bRet
= _xNameContainer
->hasByName(sName
);
470 _sSimpleName
= sName
;
471 _rRet
= _xNameContainer
->getByName(_sSimpleName
);
472 while ( nIndex
!= -1 && bRet
)
474 sName
= _sName
.getToken(0,'/',nIndex
);
475 _xNameContainer
.set(_rRet
,UNO_QUERY
);
476 bRet
= _xNameContainer
.is();
479 bRet
= _xNameContainer
->hasByName(sName
);
480 _sSimpleName
= sName
;
482 _rRet
= _xNameContainer
->getByName(sName
);
487 _sSimpleName
= sName
; // a content
489 _xNameContainer
.clear(); // a sub folder doesn't exist
494 Reference
< XComponent
> SAL_CALL
ODocumentContainer::loadComponentFromURL( const OUString
& _sURL
495 , const OUString
& /*TargetFrameName*/
496 , sal_Int32
/*SearchFlags*/
497 , const Sequence
< PropertyValue
>& Arguments
)
499 ::SolarMutexGuard aSolarGuard
;
501 MutexGuard
aGuard(m_aMutex
);
502 Reference
< XComponent
> xComp
;
506 Reference
< XNameContainer
> xNameContainer(this);
508 if ( !lcl_queryContent(_sURL
,xNameContainer
,aContent
,sName
) )
511 DBA_RES(RID_STR_NAME_NOT_FOUND
).replaceFirst("$name$", _sURL
));
512 throw IllegalArgumentException( sMessage
, *this, 1 );
515 Reference
< XCommandProcessor
> xContent(aContent
,UNO_QUERY
);
520 ::comphelper::NamedValueCollection
aArgs( Arguments
);
521 aCommand
.Name
= aArgs
.getOrDefault( "OpenMode", OUString("open") );
522 aArgs
.remove( "OpenMode" );
524 OpenCommandArgument2 aOpenCommand
;
525 aOpenCommand
.Mode
= OpenMode::DOCUMENT
;
526 aArgs
.put( "OpenCommandArgument", aOpenCommand
);
528 aCommand
.Argument
<<= aArgs
.getPropertyValues();
529 xComp
.set(xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>()),UNO_QUERY
);
532 catch(const NoSuchElementException
&)
534 throw IllegalArgumentException();
536 catch(const WrappedTargetException
&e
)
538 throw WrappedTargetRuntimeException(e
.Message
, e
.Context
, e
.TargetException
);
543 Any SAL_CALL
ODocumentContainer::getByHierarchicalName( const OUString
& _sName
)
545 MutexGuard
aGuard(m_aMutex
);
547 Reference
< XNameContainer
> xNameContainer(this);
549 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
551 throw NoSuchElementException(_sName
,*this);
554 sal_Bool SAL_CALL
ODocumentContainer::hasByHierarchicalName( const OUString
& _sName
)
556 MutexGuard
aGuard(m_aMutex
);
558 Reference
< XNameContainer
> xNameContainer(this);
560 return lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
);
563 // XHierarchicalNameContainer
564 void SAL_CALL
ODocumentContainer::insertByHierarchicalName( const OUString
& _sName
, const Any
& _aElement
)
566 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
567 if ( !xContent
.is() )
568 throw IllegalArgumentException();
570 MutexGuard
aGuard(m_aMutex
);
572 Reference
< XNameContainer
> xNameContainer(this);
574 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
575 throw ElementExistException(_sName
,*this);
577 if ( !xNameContainer
.is() )
579 sal_Int32 index
= sName
.getLength();
581 DBA_RES(RID_STR_NO_SUB_FOLDER
).replaceFirst("$folder$",
582 _sName
.getToken(0,'/',index
)));
583 throw IllegalArgumentException( sMessage
, *this, 1 );
586 xNameContainer
->insertByName(sName
,_aElement
);
589 void SAL_CALL
ODocumentContainer::removeByHierarchicalName( const OUString
& _sName
)
591 if ( _sName
.isEmpty() )
592 throw NoSuchElementException(_sName
,*this);
594 MutexGuard
aGuard(m_aMutex
);
597 Reference
< XNameContainer
> xNameContainer(this);
598 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
599 throw NoSuchElementException(_sName
,*this);
601 xNameContainer
->removeByName(sName
);
604 // XHierarchicalNameReplace
605 void SAL_CALL
ODocumentContainer::replaceByHierarchicalName( const OUString
& _sName
, const Any
& _aElement
)
607 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
608 if ( !xContent
.is() )
609 throw IllegalArgumentException();
611 MutexGuard
aGuard(m_aMutex
);
614 Reference
< XNameContainer
> xNameContainer(this);
615 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
616 throw NoSuchElementException(_sName
,*this);
618 xNameContainer
->replaceByName(sName
,_aElement
);
621 OUString SAL_CALL
ODocumentContainer::getHierarchicalName()
623 ::osl::MutexGuard
aGuard( m_aMutex
);
624 return impl_getHierarchicalName( false );
627 OUString SAL_CALL
ODocumentContainer::composeHierarchicalName( const OUString
& i_rRelativeName
)
629 OUString aBuffer
= getHierarchicalName() + "/" + i_rRelativeName
;
633 ::rtl::Reference
<OContentHelper
> ODocumentContainer::getContent(const OUString
& _sName
) const
635 ::rtl::Reference
<OContentHelper
> pContent
;
638 pContent
= comphelper::getUnoTunnelImplementation
<OContentHelper
>(const_cast<ODocumentContainer
*>(this)->implGetByName( _sName
, true ));
640 catch(const Exception
&)
646 void ODocumentContainer::getPropertyDefaultByHandle( sal_Int32
/*_nHandle*/, Any
& _rDefault
) const
651 void SAL_CALL
ODocumentContainer::commit( )
653 MutexGuard
aGuard(m_aMutex
);
654 for (auto const& elem
: m_aDocumentMap
)
656 Reference
<XTransactedObject
> xTrans(elem
.second
.get(),UNO_QUERY
);
660 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
665 void SAL_CALL
ODocumentContainer::revert( )
667 MutexGuard
aGuard(m_aMutex
);
668 for (auto const& elem
: m_aDocumentMap
)
670 Reference
<XTransactedObject
> xTrans(elem
.second
.get(),UNO_QUERY
);
674 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
679 Reference
< XStorage
> ODocumentContainer::getContainerStorage() const
681 return m_pImpl
->m_pDataSource
682 ? m_pImpl
->m_pDataSource
->getStorage( m_bFormsContainer
? ODatabaseModelImpl::E_FORM
: ODatabaseModelImpl::E_REPORT
)
683 : Reference
< XStorage
>();
686 void SAL_CALL
ODocumentContainer::removeByName( const OUString
& _rName
)
688 ResettableMutexGuard
aGuard(m_aMutex
);
690 // check the arguments
691 if (_rName
.isEmpty())
692 throw IllegalArgumentException();
694 if (!checkExistence(_rName
))
695 throw NoSuchElementException(_rName
,*this);
697 Reference
< XCommandProcessor
> xContent( implGetByName( _rName
, true ), UNO_QUERY
);
702 aCommand
.Name
= "delete";
703 xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>());
709 notifyByName( aGuard
, _rName
, nullptr, nullptr, E_REMOVED
, ContainerListemers
);
712 void SAL_CALL
ODocumentContainer::rename( const OUString
& newName
)
716 osl::ClearableGuard
< osl::Mutex
> aGuard(m_aMutex
);
717 if ( newName
== m_pImpl
->m_aProps
.aTitle
)
720 sal_Int32 nHandle
= PROPERTY_ID_NAME
;
721 Any aOld
= makeAny(m_pImpl
->m_aProps
.aTitle
);
722 Any aNew
= makeAny(newName
);
725 fire(&nHandle
, &aNew
, &aOld
, 1, true );
726 m_pImpl
->m_aProps
.aTitle
= newName
;
727 fire(&nHandle
, &aNew
, &aOld
, 1, false );
729 catch(const PropertyVetoException
&)
731 throw ElementExistException(newName
,*this);
735 } // namespace dbaccess
737 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */