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 "dbastrings.hrc"
22 #include "documentdefinition.hxx"
23 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
24 #include <com/sun/star/ucb/OpenMode.hpp>
25 #include <tools/debug.hxx>
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 "datasource.hxx"
34 #include <comphelper/classids.hxx>
35 #include <comphelper/mimeconfighelper.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include <connectivity/sqlerror.hxx>
38 #include "core_resource.hxx"
39 #include "core_resource.hrc"
40 #include <comphelper/namedvaluecollection.hxx>
41 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
43 #include <vcl/svapp.hxx>
44 #include <osl/mutex.hxx>
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::lang
;
48 using namespace ::com::sun::star::embed
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::container
;
51 using namespace ::com::sun::star::ucb
;
52 using namespace ::com::sun::star::sdbc
;
53 using namespace ::com::sun::star::sdb
;
54 using namespace ::com::sun::star::io
;
55 using namespace ::osl
;
56 using namespace ::comphelper
;
57 using namespace ::cppu
;
63 class LocalNameApproval
: public IContainerApprove
65 ::connectivity::SQLError m_aErrors
;
68 LocalNameApproval( const Reference
< XComponentContext
>& _rxContext
)
69 :m_aErrors( _rxContext
)
72 virtual ~LocalNameApproval()
76 void SAL_CALL
approveElement( const OUString
& _rName
, const Reference
< XInterface
>& _rxElement
) SAL_OVERRIDE
;
79 void SAL_CALL
LocalNameApproval::approveElement( const OUString
& _rName
, const Reference
< XInterface
>& /*_rxElement*/ )
81 if ( _rName
.indexOf( '/' ) != -1 )
82 throw IllegalArgumentException(
83 m_aErrors
.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES
),
91 ODocumentContainer::ODocumentContainer(const Reference
< XComponentContext
>& _xORB
92 ,const Reference
< XInterface
>& _xParentContainer
93 ,const TContentPtr
& _pImpl
94 , bool _bFormsContainer
96 :ODefinitionContainer(_xORB
,_xParentContainer
,_pImpl
)
97 ,OPropertyStateContainer(OContentHelper::rBHelper
)
98 ,m_bFormsContainer(_bFormsContainer
)
100 registerProperty(PROPERTY_NAME
, PROPERTY_ID_NAME
, PropertyAttribute::BOUND
| PropertyAttribute::READONLY
| PropertyAttribute::CONSTRAINED
,
101 &m_pImpl
->m_aProps
.aTitle
, cppu::UnoType
<decltype(m_pImpl
->m_aProps
.aTitle
)>::get());
103 setElementApproval( PContainerApprove( new LocalNameApproval ( _xORB
) ) );
106 ODocumentContainer::~ODocumentContainer()
109 if ( !OContentHelper::rBHelper
.bInDispose
&& !OContentHelper::rBHelper
.bDisposed
)
116 IMPLEMENT_FORWARD_XINTERFACE3( ODocumentContainer
,ODefinitionContainer
,ODocumentContainer_Base
,OPropertyStateContainer
)
118 css::uno::Sequence
<sal_Int8
> ODocumentContainer::getImplementationId()
119 throw (css::uno::RuntimeException
, std::exception
)
121 return css::uno::Sequence
<sal_Int8
>();
124 IMPLEMENT_GETTYPES3(ODocumentContainer
,ODefinitionContainer
,OPropertyStateContainer
,ODocumentContainer_Base
);
125 IMPLEMENT_SERVICE_INFO_IMPLNAME(ODocumentContainer
, "com.sun.star.comp.dba.ODocumentContainer");
126 IMPLEMENT_SERVICE_INFO_SUPPORTS(ODocumentContainer
);
127 IMPLEMENT_PROPERTYCONTAINER_DEFAULTS(ODocumentContainer
)
129 Sequence
< OUString
> SAL_CALL
ODocumentContainer::getSupportedServiceNames( ) throw(RuntimeException
, std::exception
)
131 Sequence
< OUString
> aSupported(1);
132 aSupported
[0] = m_bFormsContainer
? OUString(SERVICE_NAME_FORM_COLLECTION
) : OUString(SERVICE_NAME_REPORT_COLLECTION
);
136 OUString
ODocumentContainer::determineContentType() const
141 Reference
< XContent
> ODocumentContainer::createObject( const OUString
& _rName
)
143 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
144 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( _rName
);
145 OSL_ENSURE( aFind
!= rDefinitions
.end(), "ODocumentContainer::createObject:Invalid entry in map!" );
146 if ( aFind
->second
->m_aProps
.bIsFolder
)
147 return new ODocumentContainer( m_aContext
, *this, aFind
->second
, m_bFormsContainer
);
148 return new ODocumentDefinition( *this, m_aContext
, aFind
->second
, m_bFormsContainer
);
151 Reference
< XInterface
> SAL_CALL
ODocumentContainer::createInstance( const OUString
& aServiceSpecifier
) throw (Exception
, RuntimeException
, std::exception
)
153 return createInstanceWithArguments( aServiceSpecifier
, Sequence
< Any
>() );
158 template< class TYPE
>
159 void lcl_extractAndRemove( ::comphelper::NamedValueCollection
& io_rArguments
, const OUString
& i_rName
, TYPE
& o_rValue
)
161 if ( io_rArguments
.has( i_rName
) )
163 io_rArguments
.get_ensureType( i_rName
, o_rValue
);
164 io_rArguments
.remove( i_rName
);
169 Reference
< XInterface
> SAL_CALL
ODocumentContainer::createInstanceWithArguments( const OUString
& ServiceSpecifier
, const Sequence
< Any
>& _aArguments
) throw (Exception
, RuntimeException
, std::exception
)
171 Reference
< XInterface
> xRet
;
172 Reference
< XContent
> xContent
;
173 if ( ServiceSpecifier
== SERVICE_SDB_DOCUMENTDEFINITION
)
175 MutexGuard
aGuard(m_aMutex
);
177 // extract known arguments
178 OUString sName
, sPersistentName
, sURL
, sMediaType
, sDocServiceName
;
179 Reference
< XCommandProcessor
> xCopyFrom
;
180 Reference
< XConnection
> xConnection
;
181 bool bAsTemplate( false );
182 Sequence
< sal_Int8
> aClassID
;
184 ::comphelper::NamedValueCollection
aArgs( _aArguments
);
185 lcl_extractAndRemove( aArgs
, PROPERTY_NAME
, sName
);
186 lcl_extractAndRemove( aArgs
, PROPERTY_PERSISTENT_NAME
, sPersistentName
);
187 lcl_extractAndRemove( aArgs
, PROPERTY_URL
, sURL
);
188 lcl_extractAndRemove( aArgs
, PROPERTY_EMBEDDEDOBJECT
, xCopyFrom
);
189 lcl_extractAndRemove( aArgs
, PROPERTY_ACTIVE_CONNECTION
, xConnection
);
190 lcl_extractAndRemove( aArgs
, PROPERTY_AS_TEMPLATE
, bAsTemplate
);
191 lcl_extractAndRemove( aArgs
, INFO_MEDIATYPE
, sMediaType
);
192 lcl_extractAndRemove( aArgs
, "DocumentServiceName" , sDocServiceName
);
194 // ClassID has two allowed types, so a special treatment here
195 Any aClassIDArg
= aArgs
.get( "ClassID" );
196 if ( aClassIDArg
.hasValue() )
198 if ( !( aClassIDArg
>>= aClassID
) )
200 // Extended for usage also with a string
201 OUString sClassIDString
;
202 if ( !( aClassIDArg
>>= sClassIDString
) )
203 throw IllegalArgumentException( OUString(), *this, 2 );
205 aClassID
= ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( sClassIDString
);
208 #if OSL_DEBUG_LEVEL > 0
209 OUString sClassIDString
= ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation( aClassID
);
210 (void)sClassIDString
;
212 aArgs
.remove( "ClassID" );
214 // Everything which now is still present in the arguments is passed to the embedded object
215 const Sequence
< PropertyValue
> aCreationArgs( aArgs
.getPropertyValues() );
217 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
218 bool bNew
= sPersistentName
.isEmpty();
221 static const char sBaseName
[] = "Obj";
223 sPersistentName
= sBaseName
;
224 sPersistentName
+= OUString::number(rDefinitions
.size() + 1);
225 Reference
<XNameAccess
> xElements(getContainerStorage(),UNO_QUERY
);
226 if ( xElements
.is() )
227 sPersistentName
= ::dbtools::createUniqueName(xElements
,sPersistentName
);
229 const bool bNeedClassID
= (0 == aClassID
.getLength()) && sURL
.isEmpty() ;
230 if ( xCopyFrom
.is() )
232 Sequence
<Any
> aIni(2);
233 aIni
[0] <<= getContainerStorage();
234 aIni
[1] <<= sPersistentName
;
236 aCommand
.Name
= "copyTo";
237 aCommand
.Argument
<<= aIni
;
239 xCopyFrom
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
240 Reference
<XPropertySet
> xProp(xCopyFrom
,UNO_QUERY
);
241 if ( xProp
.is() && xProp
->getPropertySetInfo().is() && xProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE
) )
242 xProp
->getPropertyValue(PROPERTY_AS_TEMPLATE
) >>= bAsTemplate
;
244 // if we do not have an own class ID, see if we can determine one from the copy we just created
246 ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName
, m_aContext
, aClassID
);
252 if ( !sMediaType
.isEmpty() )
253 ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType
, m_aContext
, aClassID
);
254 else if ( !sDocServiceName
.isEmpty() )
256 ::comphelper::MimeConfigurationHelper
aConfigHelper( m_aContext
);
257 const Sequence
< NamedValue
> aProps( aConfigHelper
.GetObjectPropsByDocumentName( sDocServiceName
) );
258 const ::comphelper::NamedValueCollection
aMediaTypeProps( aProps
);
259 aClassID
= aMediaTypeProps
.getOrDefault( "ClassID", Sequence
< sal_Int8
>() );
265 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
266 TContentPtr pElementImpl
;
267 if ( bNew
|| ( aFind
== rDefinitions
.end() ) )
269 pElementImpl
.reset( new OContentHelper_Impl
);
271 pElementImpl
->m_aProps
.aTitle
= sName
;
273 pElementImpl
->m_aProps
.sPersistentName
= sPersistentName
;
274 pElementImpl
->m_aProps
.bAsTemplate
= bAsTemplate
;
275 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
278 pElementImpl
= aFind
->second
;
280 ::rtl::Reference
< ODocumentDefinition
> pDocDef
= new ODocumentDefinition( *this, m_aContext
, pElementImpl
, m_bFormsContainer
);
281 if ( aClassID
.getLength() )
283 pDocDef
->initialLoad( aClassID
, aCreationArgs
, xConnection
);
287 OSL_ENSURE( aCreationArgs
.getLength() == 0, "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." );
289 xContent
= pDocDef
.get();
291 if ( !sURL
.isEmpty() )
293 Sequence
<Any
> aIni(2);
296 aCommand
.Name
= "insert";
297 aCommand
.Argument
<<= aIni
;
298 Reference
< XCommandProcessor
> xCommandProcessor(xContent
,UNO_QUERY
);
301 xCommandProcessor
->execute(aCommand
,-1,Reference
< XCommandEnvironment
>());
305 else if ( ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
|| SERVICE_NAME_REPORT_COLLECTION
== ServiceSpecifier
)
307 const Any
* pBegin
= _aArguments
.getConstArray();
308 const Any
* pEnd
= pBegin
+ _aArguments
.getLength();
309 PropertyValue aValue
;
311 Reference
<XNameAccess
> xCopyFrom
;
312 for(;pBegin
!= pEnd
;++pBegin
)
315 if ( aValue
.Name
== PROPERTY_NAME
)
317 aValue
.Value
>>= sName
;
319 else if ( aValue
.Name
== PROPERTY_EMBEDDEDOBJECT
)
321 xCopyFrom
.set(aValue
.Value
,UNO_QUERY
);
324 OSL_ENSURE(!sName
.isEmpty(),"Invalid name for a document container!");
325 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
326 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( sName
);
327 TContentPtr pElementImpl
;
328 if ( aFind
== rDefinitions
.end() )
330 pElementImpl
.reset(new ODefinitionContainer_Impl
);
331 pElementImpl
->m_aProps
.aTitle
= sName
;
332 pElementImpl
->m_pDataSource
= m_pImpl
->m_pDataSource
;
335 pElementImpl
= aFind
->second
;
336 OSL_ENSURE( pElementImpl
," Invalid entry in map!");
337 xContent
= new ODocumentContainer( m_aContext
, *this, pElementImpl
, ServiceSpecifier
== SERVICE_NAME_FORM_COLLECTION
);
340 if ( xCopyFrom
.is() )
342 Sequence
< OUString
> aSeq
= xCopyFrom
->getElementNames();
343 const OUString
* elements
= aSeq
.getConstArray();
344 const OUString
* elementsEnd
= elements
+ aSeq
.getLength();
345 Reference
<XContent
> xObjectToCopy
;
347 Reference
<XMultiServiceFactory
> xORB(xContent
,UNO_QUERY
);
348 OSL_ENSURE(xORB
.is(),"No service factory given");
351 for(;elements
!= elementsEnd
;++elements
)
353 xCopyFrom
->getByName(*elements
) >>= xObjectToCopy
;
354 Sequence
< Any
> aArguments(3);
355 PropertyValue aArgument
;
357 aArgument
.Name
= "Name";
358 aArgument
.Value
<<= *elements
;
359 aArguments
[0] <<= aArgument
;
361 aArgument
.Name
= "Parent";
362 aArgument
.Value
<<= xContent
;
363 aArguments
[1] <<= aArgument
;
365 aArgument
.Name
= PROPERTY_EMBEDDEDOBJECT
;
366 aArgument
.Value
<<= xObjectToCopy
;
367 aArguments
[2] <<= aArgument
;
369 OUString sServiceName
;
370 if ( Reference
< XNameAccess
>( xObjectToCopy
, UNO_QUERY
).is() )
372 if ( m_bFormsContainer
)
373 sServiceName
= SERVICE_NAME_FORM_COLLECTION
;
375 sServiceName
= SERVICE_NAME_REPORT_COLLECTION
;
378 sServiceName
= SERVICE_SDB_DOCUMENTDEFINITION
;
380 Reference
<XContent
> xNew(xORB
->createInstanceWithArguments(sServiceName
,aArguments
),UNO_QUERY
);
381 Reference
<XNameContainer
> xNameContainer(xContent
,UNO_QUERY
);
382 if ( xNameContainer
.is() )
383 xNameContainer
->insertByName(*elements
,makeAny(xNew
));
392 Sequence
< OUString
> SAL_CALL
ODocumentContainer::getAvailableServiceNames( ) throw (RuntimeException
, std::exception
)
394 Sequence
< OUString
> aSe(3);
395 aSe
[0] = SERVICE_SDB_DOCUMENTDEFINITION
;
396 aSe
[1] = SERVICE_NAME_FORM_COLLECTION
;
397 aSe
[2] = SERVICE_NAME_REPORT_COLLECTION
;
401 Any SAL_CALL
ODocumentContainer::execute( const Command
& aCommand
, sal_Int32 CommandId
, const Reference
< XCommandEnvironment
>& Environment
) throw (Exception
, CommandAbortedException
, RuntimeException
, std::exception
)
404 if ( aCommand
.Name
== "open" )
406 // open command for a folder content
407 OpenCommandArgument2 aOpenCommand
;
408 if ( !( aCommand
.Argument
>>= aOpenCommand
) )
410 OSL_FAIL( "Wrong argument type!" );
411 ucbhelper::cancelCommandExecution(
412 makeAny( IllegalArgumentException(
414 static_cast< cppu::OWeakObject
* >( this ),
420 ( ( aOpenCommand
.Mode
== OpenMode::ALL
) ||
421 ( aOpenCommand
.Mode
== OpenMode::FOLDERS
) ||
422 ( aOpenCommand
.Mode
== OpenMode::DOCUMENTS
) );
426 // open as folder - return result set
428 Reference
< XDynamicResultSet
> xSet
429 = new DynamicResultSet( m_aContext
,
438 ucbhelper::cancelCommandExecution(
439 makeAny( UnsupportedOpenModeException(
441 static_cast< cppu::OWeakObject
* >( this ),
442 sal_Int16( aOpenCommand
.Mode
) ) ),
447 else if ( aCommand
.Name
== "insert" )
451 InsertCommandArgument arg
;
452 if ( !( aCommand
.Argument
>>= arg
) )
454 OSL_FAIL( "Wrong argument type!" );
455 ucbhelper::cancelCommandExecution(
456 makeAny( IllegalArgumentException(
458 static_cast< cppu::OWeakObject
* >( this ),
464 else if ( aCommand
.Name
== "delete" )
467 Sequence
< OUString
> aSeq
= getElementNames();
468 const OUString
* pIter
= aSeq
.getConstArray();
469 const OUString
* pEnd
= pIter
+ aSeq
.getLength();
470 for(;pIter
!= pEnd
;++pIter
)
471 removeByName(*pIter
);
476 aRet
= OContentHelper::execute(aCommand
,CommandId
,Environment
);
482 bool lcl_queryContent(const OUString
& _sName
,Reference
< XNameContainer
>& _xNameContainer
,Any
& _rRet
,OUString
& _sSimpleName
)
484 sal_Int32 nIndex
= 0;
485 OUString sName
= _sName
.getToken(0,'/',nIndex
);
486 bool bRet
= _xNameContainer
->hasByName(sName
);
489 _rRet
= _xNameContainer
->getByName(_sSimpleName
= sName
);
490 while ( nIndex
!= -1 && bRet
)
492 sName
= _sName
.getToken(0,'/',nIndex
);
493 _xNameContainer
.set(_rRet
,UNO_QUERY
);
494 bRet
= _xNameContainer
.is();
497 bRet
= _xNameContainer
->hasByName(sName
);
498 _sSimpleName
= sName
;
500 _rRet
= _xNameContainer
->getByName(sName
);
505 _sSimpleName
= sName
; // a content
507 _xNameContainer
.clear(); // a sub folder doesn't exist
512 Reference
< XComponent
> SAL_CALL
ODocumentContainer::loadComponentFromURL( const OUString
& _sURL
513 , const OUString
& /*TargetFrameName*/
514 , sal_Int32
/*SearchFlags*/
515 , const Sequence
< PropertyValue
>& Arguments
) throw (IOException
, IllegalArgumentException
, RuntimeException
, std::exception
)
517 ::SolarMutexGuard aSolarGuard
;
519 MutexGuard
aGuard(m_aMutex
);
520 Reference
< XComponent
> xComp
;
524 Reference
< XNameContainer
> xNameContainer(this);
526 if ( !lcl_queryContent(_sURL
,xNameContainer
,aContent
,sName
) )
529 DBA_RES(RID_STR_NAME_NOT_FOUND
).replaceFirst("$name$", _sURL
));
530 throw IllegalArgumentException( sMessage
, *this, 1 );
533 Reference
< XCommandProcessor
> xContent(aContent
,UNO_QUERY
);
538 ::comphelper::NamedValueCollection
aArgs( Arguments
);
539 aCommand
.Name
= aArgs
.getOrDefault( "OpenMode", OUString("open") );
540 aArgs
.remove( "OpenMode" );
542 OpenCommandArgument2 aOpenCommand
;
543 aOpenCommand
.Mode
= OpenMode::DOCUMENT
;
544 aArgs
.put( "OpenCommandArgument", aOpenCommand
);
546 aCommand
.Argument
<<= aArgs
.getPropertyValues();
547 xComp
.set(xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>()),UNO_QUERY
);
550 catch(const NoSuchElementException
&)
552 throw IllegalArgumentException();
554 catch(const WrappedTargetException
&e
)
556 throw WrappedTargetRuntimeException(e
.Message
, e
.Context
, e
.TargetException
);
561 Any SAL_CALL
ODocumentContainer::getByHierarchicalName( const OUString
& _sName
) throw (NoSuchElementException
, RuntimeException
, std::exception
)
563 MutexGuard
aGuard(m_aMutex
);
565 Reference
< XNameContainer
> xNameContainer(this);
567 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
569 throw NoSuchElementException(_sName
,*this);
572 sal_Bool SAL_CALL
ODocumentContainer::hasByHierarchicalName( const OUString
& _sName
) throw (RuntimeException
, std::exception
)
574 MutexGuard
aGuard(m_aMutex
);
576 Reference
< XNameContainer
> xNameContainer(this);
578 return lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
);
581 // XHierarchicalNameContainer
582 void SAL_CALL
ODocumentContainer::insertByHierarchicalName( const OUString
& _sName
, const Any
& _aElement
) throw (IllegalArgumentException
, ElementExistException
, WrappedTargetException
, RuntimeException
, std::exception
)
584 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
585 if ( !xContent
.is() )
586 throw IllegalArgumentException();
588 ClearableMutexGuard
aGuard(m_aMutex
);
590 Reference
< XNameContainer
> xNameContainer(this);
592 if ( lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
593 throw ElementExistException(_sName
,*this);
595 if ( !xNameContainer
.is() )
597 sal_Int32 index
= sName
.getLength();
599 DBA_RES(RID_STR_NO_SUB_FOLDER
).replaceFirst("$folder$",
600 _sName
.getToken(0,'/',index
)));
601 throw IllegalArgumentException( sMessage
, *this, 1 );
604 xNameContainer
->insertByName(sName
,_aElement
);
607 void SAL_CALL
ODocumentContainer::removeByHierarchicalName( const OUString
& _sName
) throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
609 if ( _sName
.isEmpty() )
610 throw NoSuchElementException(_sName
,*this);
612 ClearableMutexGuard
aGuard(m_aMutex
);
615 Reference
< XNameContainer
> xNameContainer(this);
616 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
617 throw NoSuchElementException(_sName
,*this);
619 xNameContainer
->removeByName(sName
);
622 // XHierarchicalNameReplace
623 void SAL_CALL
ODocumentContainer::replaceByHierarchicalName( const OUString
& _sName
, const Any
& _aElement
) throw (IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
625 Reference
< XContent
> xContent(_aElement
,UNO_QUERY
);
626 if ( !xContent
.is() )
627 throw IllegalArgumentException();
629 ClearableMutexGuard
aGuard(m_aMutex
);
632 Reference
< XNameContainer
> xNameContainer(this);
633 if ( !lcl_queryContent(_sName
,xNameContainer
,aContent
,sName
) )
634 throw NoSuchElementException(_sName
,*this);
636 xNameContainer
->replaceByName(sName
,_aElement
);
639 OUString SAL_CALL
ODocumentContainer::getHierarchicalName() throw (RuntimeException
, std::exception
)
641 ::osl::MutexGuard
aGuard( m_aMutex
);
642 return impl_getHierarchicalName( false );
645 OUString SAL_CALL
ODocumentContainer::composeHierarchicalName( const OUString
& i_rRelativeName
) throw (IllegalArgumentException
, NoSupportException
, RuntimeException
, std::exception
)
647 OUStringBuffer aBuffer
;
648 aBuffer
.append( getHierarchicalName() );
649 aBuffer
.append( '/' );
650 aBuffer
.append( i_rRelativeName
);
651 return aBuffer
.makeStringAndClear();
654 ::rtl::Reference
<OContentHelper
> ODocumentContainer::getContent(const OUString
& _sName
) const
656 ::rtl::Reference
<OContentHelper
> pContent
= NULL
;
659 Reference
<XUnoTunnel
> xUnoTunnel(const_cast<ODocumentContainer
*>(this)->implGetByName( _sName
, true ), UNO_QUERY
);
660 if ( xUnoTunnel
.is() )
661 pContent
= reinterpret_cast<OContentHelper
*>(xUnoTunnel
->getSomething(OContentHelper::getUnoTunnelImplementationId()));
663 catch(const Exception
&)
669 void ODocumentContainer::getPropertyDefaultByHandle( sal_Int32
/*_nHandle*/, Any
& _rDefault
) const
674 void SAL_CALL
ODocumentContainer::commit( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
676 MutexGuard
aGuard(m_aMutex
);
677 Documents::iterator aIter
= m_aDocumentMap
.begin();
678 Documents::iterator aEnd
= m_aDocumentMap
.end();
679 for (; aIter
!= aEnd
; ++aIter
)
681 Reference
<XTransactedObject
> xTrans(aIter
->second
.get(),UNO_QUERY
);
685 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
690 void SAL_CALL
ODocumentContainer::revert( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::lang::WrappedTargetException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
692 MutexGuard
aGuard(m_aMutex
);
693 Documents::iterator aIter
= m_aDocumentMap
.begin();
694 Documents::iterator aEnd
= m_aDocumentMap
.end();
695 for (; aIter
!= aEnd
; ++aIter
)
697 Reference
<XTransactedObject
> xTrans(aIter
->second
.get(),UNO_QUERY
);
701 Reference
<XTransactedObject
> xTrans(getContainerStorage(),UNO_QUERY
);
706 Reference
< XStorage
> ODocumentContainer::getContainerStorage() const
708 return m_pImpl
->m_pDataSource
709 ? m_pImpl
->m_pDataSource
->getStorage( m_bFormsContainer
? ODatabaseModelImpl::E_FORM
: ODatabaseModelImpl::E_REPORT
)
710 : Reference
< XStorage
>();
713 void SAL_CALL
ODocumentContainer::removeByName( const OUString
& _rName
) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
715 ResettableMutexGuard
aGuard(m_aMutex
);
717 // check the arguments
718 if (_rName
.isEmpty())
719 throw IllegalArgumentException();
721 if (!checkExistence(_rName
))
722 throw NoSuchElementException(_rName
,*this);
724 Reference
< XCommandProcessor
> xContent( implGetByName( _rName
, true ), UNO_QUERY
);
729 aCommand
.Name
= "delete";
730 xContent
->execute(aCommand
,xContent
->createCommandIdentifier(),Reference
< XCommandEnvironment
>());
736 notifyByName( aGuard
, _rName
, NULL
, NULL
, E_REMOVED
, ContainerListemers
);
739 void SAL_CALL
ODocumentContainer::rename( const OUString
& newName
) throw (SQLException
, ElementExistException
, RuntimeException
, std::exception
)
743 osl::ClearableGuard
< osl::Mutex
> aGuard(m_aMutex
);
744 if ( newName
.equals( m_pImpl
->m_aProps
.aTitle
) )
747 sal_Int32 nHandle
= PROPERTY_ID_NAME
;
748 Any aOld
= makeAny(m_pImpl
->m_aProps
.aTitle
);
749 Any aNew
= makeAny(newName
);
752 fire(&nHandle
, &aNew
, &aOld
, 1, sal_True
);
753 m_pImpl
->m_aProps
.aTitle
= newName
;
754 fire(&nHandle
, &aNew
, &aOld
, 1, sal_False
);
756 catch(const PropertyVetoException
&)
758 throw ElementExistException(newName
,*this);
762 } // namespace dbaccess
764 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */