LibreOffice Module dbaccess (master) 1
documentcontainer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "documentcontainer.hxx"
21#include <stringconstants.hxx>
23#include <ModelImpl.hxx>
24#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
25#include <com/sun/star/ucb/OpenMode.hpp>
27#include "myucp_resultset.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>
35#include <core_resource.hxx>
36#include <strings.hrc>
37#include <strings.hxx>
41#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
42
43#include <vcl/svapp.hxx>
44#include <osl/mutex.hxx>
45#include <o3tl/string_view.hxx>
46
47using namespace ::com::sun::star::uno;
48using namespace ::com::sun::star::lang;
49using namespace ::com::sun::star::embed;
50using namespace ::com::sun::star::beans;
51using namespace ::com::sun::star::container;
52using namespace ::com::sun::star::ucb;
53using namespace ::com::sun::star::sdbc;
54using namespace ::com::sun::star::sdb;
55using namespace ::com::sun::star::io;
56using namespace ::osl;
57using namespace ::comphelper;
58using namespace ::cppu;
59
60namespace dbaccess
61{
62
63namespace {
64
65// LocalNameApproval
66class LocalNameApproval : public IContainerApprove
67{
69
70public:
71 void approveElement( const OUString& _rName ) override;
72};
73
74}
75
76void LocalNameApproval::approveElement( const OUString& _rName )
77{
78 if ( _rName.indexOf( '/' ) != -1 )
79 throw IllegalArgumentException(
80 m_aErrors.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES ),
81 nullptr,
82 0
83 );
84}
85
86// ODocumentContainer
87
88ODocumentContainer::ODocumentContainer(const Reference< XComponentContext >& _xORB
89 ,const Reference< XInterface >& _xParentContainer
90 ,const TContentPtr& _pImpl
91 , bool _bFormsContainer
92 )
93 :ODefinitionContainer(_xORB,_xParentContainer,_pImpl)
95 ,m_bFormsContainer(_bFormsContainer)
96{
97 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED,
98 &m_pImpl->m_aProps.aTitle, cppu::UnoType<decltype(m_pImpl->m_aProps.aTitle)>::get());
99
100 setElementApproval( std::make_shared<LocalNameApproval>() );
101}
102
104{
105
106 if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
107 {
108 acquire();
109 dispose();
110 }
111}
112
114
115css::uno::Sequence<sal_Int8> ODocumentContainer::getImplementationId()
116{
117 return css::uno::Sequence<sal_Int8>();
118}
119
120css::uno::Sequence< css::uno::Type > ODocumentContainer::getTypes()
121{
122 return ::comphelper::concatSequences(
124 OPropertyStateContainer::getTypes( ),
126 );
127}
129 {
130 return "com.sun.star.comp.dba.ODocumentContainer";
131 };
132sal_Bool SAL_CALL ODocumentContainer::supportsService(const OUString& _rServiceName)
133 {
134 const css::uno::Sequence< OUString > aSupported(getSupportedServiceNames());
135 for (const OUString& s : aSupported)
136 if (s == _rServiceName)
137 return true;
138
139 return false;
140 };
141css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL ODocumentContainer::getPropertySetInfo()
142{
143 Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
144 return xInfo;
145}
147{
149}
151{
152 css::uno::Sequence< css::beans::Property > aProps;
153 describeProperties(aProps);
154 return new ::cppu::OPropertyArrayHelper(aProps);
155}
156
157
158Sequence< OUString > SAL_CALL ODocumentContainer::getSupportedServiceNames( )
159{
161}
162
164{
165 return OUString();
166}
167
168Reference< XContent > ODocumentContainer::createObject( const OUString& _rName)
169{
170 const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
171 ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( _rName );
172 OSL_ENSURE( aFind != rDefinitions.end(), "ODocumentContainer::createObject:Invalid entry in map!" );
173 if ( aFind->second->m_aProps.bIsFolder )
174 return new ODocumentContainer( m_aContext, *this, aFind->second, m_bFormsContainer );
175 return new ODocumentDefinition( *this, m_aContext, aFind->second, m_bFormsContainer );
176}
177
178Reference< XInterface > SAL_CALL ODocumentContainer::createInstance( const OUString& aServiceSpecifier )
179{
180 return createInstanceWithArguments( aServiceSpecifier, Sequence< Any >() );
181}
182
183namespace
184{
185 template< class TYPE >
186 void lcl_extractAndRemove( ::comphelper::NamedValueCollection& io_rArguments, const OUString& i_rName, TYPE& o_rValue )
187 {
188 if ( io_rArguments.has( i_rName ) )
189 {
190 io_rArguments.get_ensureType( i_rName, o_rValue );
191 io_rArguments.remove( i_rName );
192 }
193 }
194}
195
196Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments( const OUString& ServiceSpecifier, const Sequence< Any >& _aArguments )
197{
198 Reference< XInterface > xRet;
199 Reference< XContent > xContent;
200 if ( ServiceSpecifier == SERVICE_SDB_DOCUMENTDEFINITION )
201 {
202 MutexGuard aGuard(m_aMutex);
203
204 // extract known arguments
205 OUString sName, sPersistentName, sURL, sMediaType, sDocServiceName;
206 Reference< XCommandProcessor > xCopyFrom;
207 Reference< XConnection > xConnection;
208 bool bAsTemplate( false );
209 Sequence< sal_Int8 > aClassID;
210
211 ::comphelper::NamedValueCollection aArgs( _aArguments );
212 lcl_extractAndRemove( aArgs, PROPERTY_NAME, sName );
213 lcl_extractAndRemove( aArgs, PROPERTY_PERSISTENT_NAME, sPersistentName );
214 lcl_extractAndRemove( aArgs, PROPERTY_URL, sURL );
215 lcl_extractAndRemove( aArgs, PROPERTY_EMBEDDEDOBJECT, xCopyFrom );
216 lcl_extractAndRemove( aArgs, PROPERTY_ACTIVE_CONNECTION, xConnection );
217 lcl_extractAndRemove( aArgs, PROPERTY_AS_TEMPLATE, bAsTemplate );
218 lcl_extractAndRemove( aArgs, INFO_MEDIATYPE, sMediaType );
219 lcl_extractAndRemove( aArgs, "DocumentServiceName" , sDocServiceName );
220
221 // ClassID has two allowed types, so a special treatment here
222 Any aClassIDArg = aArgs.get( "ClassID" );
223 if ( aClassIDArg.hasValue() )
224 {
225 if ( !( aClassIDArg >>= aClassID ) )
226 {
227 // Extended for usage also with a string
228 OUString sClassIDString;
229 if ( !( aClassIDArg >>= sClassIDString ) )
230 throw IllegalArgumentException( OUString(), *this, 2 );
231
233 }
234
235#if OSL_DEBUG_LEVEL > 0
237 (void)sClassIDString;
238#endif
239 aArgs.remove( "ClassID" );
240 }
241 // Everything which now is still present in the arguments is passed to the embedded object
242 const Sequence< PropertyValue > aCreationArgs( aArgs.getPropertyValues() );
243
244 const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
245 bool bNew = sPersistentName.isEmpty();
246 if ( bNew )
247 {
248 sPersistentName = "Obj" + OUString::number(rDefinitions.size() + 1);
249 Reference<XNameAccess> xElements = getContainerStorage();
250 if ( xElements.is() )
251 sPersistentName = ::dbtools::createUniqueName(xElements,sPersistentName);
252
253 const bool bNeedClassID = !aClassID.hasElements() && sURL.isEmpty() ;
254 if ( xCopyFrom.is() )
255 {
256 Sequence<Any> aIni{ Any(getContainerStorage()), Any(sPersistentName) };
258 aCommand.Name = "copyTo";
259 aCommand.Argument <<= aIni;
260
261 xCopyFrom->execute(aCommand,-1,Reference< XCommandEnvironment >());
262 Reference<XPropertySet> xProp(xCopyFrom,UNO_QUERY);
263 if ( xProp.is() && xProp->getPropertySetInfo().is() && xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE) )
264 xProp->getPropertyValue(PROPERTY_AS_TEMPLATE) >>= bAsTemplate;
265
266 // if we do not have an own class ID, see if we can determine one from the copy we just created
267 if ( bNeedClassID )
269 }
270 else
271 {
272 if ( bNeedClassID )
273 {
274 if ( !sMediaType.isEmpty() )
276 else if ( !sDocServiceName.isEmpty() )
277 {
279 const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByDocumentName( sDocServiceName ) );
280 const ::comphelper::NamedValueCollection aMediaTypeProps( aProps );
281 aClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() );
282 }
283 }
284 }
285 }
286
288 TContentPtr pElementImpl;
289 if ( bNew || ( aFind == rDefinitions.end() ) )
290 {
291 pElementImpl = std::make_shared<OContentHelper_Impl>();
292 if ( !bNew )
293 pElementImpl->m_aProps.aTitle = sName;
294
295 pElementImpl->m_aProps.sPersistentName = sPersistentName;
296 pElementImpl->m_aProps.bAsTemplate = bAsTemplate;
297 pElementImpl->m_pDataSource = m_pImpl->m_pDataSource;
298 }
299 else
300 pElementImpl = aFind->second;
301
303 if ( aClassID.hasElements() )
304 {
305 pDocDef->initialLoad( aClassID, aCreationArgs, xConnection );
306 }
307 else
308 {
309 OSL_ENSURE( !aCreationArgs.hasElements(), "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." );
310 }
311 xContent = pDocDef.get();
312
313 if ( !sURL.isEmpty() )
314 {
315 Sequence<Any> aIni{ Any(sURL) };
317 aCommand.Name = "insert";
318 aCommand.Argument <<= aIni;
319 Reference< XCommandProcessor > xCommandProcessor(xContent,UNO_QUERY);
320 if ( xContent.is() )
321 {
322 xCommandProcessor->execute(aCommand,-1,Reference< XCommandEnvironment >());
323 }
324 }
325 }
326 else if ( ServiceSpecifier == SERVICE_NAME_FORM_COLLECTION || SERVICE_NAME_REPORT_COLLECTION == ServiceSpecifier )
327 {
328 const Any* pBegin = _aArguments.getConstArray();
329 const Any* pEnd = pBegin + _aArguments.getLength();
330 PropertyValue aValue;
331 OUString sName;
332 Reference<XNameAccess> xCopyFrom;
333 for(;pBegin != pEnd;++pBegin)
334 {
335 *pBegin >>= aValue;
336 if ( aValue.Name == PROPERTY_NAME)
337 {
338 aValue.Value >>= sName;
339 }
340 else if ( aValue.Name == PROPERTY_EMBEDDEDOBJECT)
341 {
342 xCopyFrom.set(aValue.Value,UNO_QUERY);
343 }
344 }
345 OSL_ENSURE(!sName.isEmpty(),"Invalid name for a document container!");
346 const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
348 TContentPtr pElementImpl;
349 if ( aFind == rDefinitions.end() )
350 {
351 pElementImpl = std::make_shared<ODefinitionContainer_Impl>();
352 pElementImpl->m_aProps.aTitle = sName;
353 pElementImpl->m_pDataSource = m_pImpl->m_pDataSource;
354 }
355 else
356 pElementImpl = aFind->second;
357 OSL_ENSURE( pElementImpl ," Invalid entry in map!");
358 xContent = new ODocumentContainer( m_aContext, *this, pElementImpl, ServiceSpecifier == SERVICE_NAME_FORM_COLLECTION );
359
360 // copy children
361 if ( xCopyFrom.is() )
362 {
363 Sequence< OUString> aSeq = xCopyFrom->getElementNames();
364 const OUString* elements = aSeq.getConstArray();
365 const OUString* elementsEnd = elements + aSeq.getLength();
366 Reference<XContent> xObjectToCopy;
367
368 Reference<XMultiServiceFactory> xORB(xContent,UNO_QUERY);
369 OSL_ENSURE(xORB.is(),"No service factory given");
370 if ( xORB.is() )
371 {
372 for(;elements != elementsEnd;++elements)
373 {
374 xCopyFrom->getByName(*elements) >>= xObjectToCopy;
376 {
377 {"Name", Any(*elements)}, // set as folder
378 {"Parent", Any(xContent)},
379 {PROPERTY_EMBEDDEDOBJECT, Any(xObjectToCopy)},
380 }));
381
382 OUString sServiceName;
383 if ( Reference< XNameAccess >( xObjectToCopy, UNO_QUERY ).is() )
384 {
385 if ( m_bFormsContainer )
387 else
389 }
390 else
392
393 Reference<XContent > xNew(xORB->createInstanceWithArguments(sServiceName,aArguments),UNO_QUERY);
394 Reference<XNameContainer> xNameContainer(xContent,UNO_QUERY);
395 if ( xNameContainer.is() )
396 xNameContainer->insertByName(*elements,Any(xNew));
397 }
398 }
399 }
400 }
401 xRet = xContent;
402 return xRet;
403}
404
405Sequence< OUString > SAL_CALL ODocumentContainer::getAvailableServiceNames( )
406{
407 return
408 {
412 };
413}
414
415Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment )
416{
417 Any aRet;
418 if ( aCommand.Name == "open" )
419 {
420 // open command for a folder content
421 OpenCommandArgument2 aOpenCommand;
422 if ( !( aCommand.Argument >>= aOpenCommand ) )
423 {
424 OSL_FAIL( "Wrong argument type!" );
426 Any( IllegalArgumentException(
427 OUString(),
428 static_cast< cppu::OWeakObject * >( this ),
429 -1 ) ),
430 Environment );
431 // Unreachable
432 }
433 bool bOpenFolder =
434 ( ( aOpenCommand.Mode == OpenMode::ALL ) ||
435 ( aOpenCommand.Mode == OpenMode::FOLDERS ) ||
436 ( aOpenCommand.Mode == OpenMode::DOCUMENTS ) );
437
438 if ( bOpenFolder )
439 {
440 // open as folder - return result set
441
442 Reference< XDynamicResultSet > xSet
444 this,
445 aOpenCommand,
446 Environment );
447 aRet <<= xSet;
448 }
449 else
450 {
451 // Unsupported.
453 Any( UnsupportedOpenModeException(
454 OUString(),
455 static_cast< cppu::OWeakObject * >( this ),
456 sal_Int16( aOpenCommand.Mode ) ) ),
457 Environment );
458 // Unreachable
459 }
460 }
461 else if ( aCommand.Name == "insert" )
462 {
463 // insert
464
465 InsertCommandArgument arg;
466 if ( !( aCommand.Argument >>= arg ) )
467 {
468 OSL_FAIL( "Wrong argument type!" );
470 Any( IllegalArgumentException(
471 OUString(),
472 static_cast< cppu::OWeakObject * >( this ),
473 -1 ) ),
474 Environment );
475 // Unreachable
476 }
477 }
478 else if ( aCommand.Name == "delete" )
479 {
480 // delete
481 Sequence< OUString> aSeq = getElementNames();
482 const OUString* pIter = aSeq.getConstArray();
483 const OUString* pEnd = pIter + aSeq.getLength();
484 for(;pIter != pEnd;++pIter)
485 removeByName(*pIter);
486
487 dispose();
488 }
489 else
491 return aRet;
492}
493
494namespace
495{
496 bool lcl_queryContent(std::u16string_view _sName,Reference< XNameContainer >& _xNameContainer,Any& _rRet,OUString& _sSimpleName)
497 {
498 sal_Int32 nIndex = 0;
499 OUString sName( o3tl::getToken(_sName,0,'/',nIndex) );
500 bool bRet = _xNameContainer->hasByName(sName);
501 if ( bRet )
502 {
503 _sSimpleName = sName;
504 _rRet = _xNameContainer->getByName(_sSimpleName);
505 while ( nIndex != -1 && bRet )
506 {
507 sName = o3tl::getToken(_sName,0,'/',nIndex);
508 _xNameContainer.set(_rRet,UNO_QUERY);
509 bRet = _xNameContainer.is();
510 if ( bRet )
511 {
512 bRet = _xNameContainer->hasByName(sName);
513 _sSimpleName = sName;
514 if ( bRet )
515 _rRet = _xNameContainer->getByName(sName);
516 }
517 }
518 }
519 if ( nIndex == -1 )
520 _sSimpleName = sName; // a content
521 else
522 _xNameContainer.clear(); // a sub folder doesn't exist
523 return bRet;
524 }
525}
526
527Reference< XComponent > SAL_CALL ODocumentContainer::loadComponentFromURL( const OUString& _sURL
528 , const OUString& /*TargetFrameName*/
529 , sal_Int32 /*SearchFlags*/
530 , const Sequence< PropertyValue >& Arguments )
531{
532 ::SolarMutexGuard aSolarGuard;
533
534 MutexGuard aGuard(m_aMutex);
535 Reference< XComponent > xComp;
536 try
537 {
538 Any aContent;
539 Reference< XNameContainer > xNameContainer(this);
540 OUString sName;
541 if ( !lcl_queryContent(_sURL,xNameContainer,aContent,sName) )
542 {
543 OUString sMessage(
544 DBA_RES(RID_STR_NAME_NOT_FOUND).replaceFirst("$name$", _sURL));
545 throw IllegalArgumentException( sMessage, *this, 1 );
546 }
547
548 Reference< XCommandProcessor > xContent(aContent,UNO_QUERY);
549 if ( xContent.is() )
550 {
552
553 ::comphelper::NamedValueCollection aArgs( Arguments );
554 aCommand.Name = aArgs.getOrDefault( "OpenMode", OUString("open") );
555 aArgs.remove( "OpenMode" );
556
557 OpenCommandArgument2 aOpenCommand;
558 aOpenCommand.Mode = OpenMode::DOCUMENT;
559 aArgs.put( "OpenCommandArgument", aOpenCommand );
560
561 aCommand.Argument <<= aArgs.getPropertyValues();
562 xComp.set(xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY);
563 }
564 }
565 catch(const NoSuchElementException&)
566 {
567 throw IllegalArgumentException();
568 }
569 catch(const WrappedTargetException &e)
570 {
571 throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException);
572 }
573 return xComp;
574}
575
576Any SAL_CALL ODocumentContainer::getByHierarchicalName( const OUString& _sName )
577{
578 MutexGuard aGuard(m_aMutex);
579 Any aContent;
580 Reference< XNameContainer > xNameContainer(this);
581 OUString sName;
582 if ( lcl_queryContent(_sName,xNameContainer,aContent,sName) )
583 return aContent;
584 throw NoSuchElementException(_sName,*this);
585}
586
587sal_Bool SAL_CALL ODocumentContainer::hasByHierarchicalName( const OUString& _sName )
588{
589 MutexGuard aGuard(m_aMutex);
590 Any aContent;
591 Reference< XNameContainer > xNameContainer(this);
592 OUString sName;
593 return lcl_queryContent(_sName,xNameContainer,aContent,sName);
594}
595
596// XHierarchicalNameContainer
597void SAL_CALL ODocumentContainer::insertByHierarchicalName( const OUString& _sName, const Any& _aElement )
598{
599 Reference< XContent > xContent(_aElement,UNO_QUERY);
600 if ( !xContent.is() )
601 throw IllegalArgumentException();
602
603 MutexGuard aGuard(m_aMutex);
604 Any aContent;
605 Reference< XNameContainer > xNameContainer(this);
606 OUString sName;
607 if ( lcl_queryContent(_sName,xNameContainer,aContent,sName) )
608 throw ElementExistException(_sName,*this);
609
610 if ( !xNameContainer.is() )
611 {
612 sal_Int32 index = sName.getLength();
613 OUString sMessage(
614 DBA_RES(RID_STR_NO_SUB_FOLDER).replaceFirst("$folder$",
615 o3tl::getToken(_sName, 0,'/',index)));
616 throw IllegalArgumentException( sMessage, *this, 1 );
617 }
618
619 xNameContainer->insertByName(sName,_aElement);
620}
621
622void SAL_CALL ODocumentContainer::removeByHierarchicalName( const OUString& _sName )
623{
624 if ( _sName.isEmpty() )
625 throw NoSuchElementException(_sName,*this);
626
627 MutexGuard aGuard(m_aMutex);
628 Any aContent;
629 OUString sName;
630 Reference< XNameContainer > xNameContainer(this);
631 if ( !lcl_queryContent(_sName,xNameContainer,aContent,sName) )
632 throw NoSuchElementException(_sName,*this);
633
634 xNameContainer->removeByName(sName);
635}
636
637// XHierarchicalNameReplace
638void SAL_CALL ODocumentContainer::replaceByHierarchicalName( const OUString& _sName, const Any& _aElement )
639{
640 Reference< XContent > xContent(_aElement,UNO_QUERY);
641 if ( !xContent.is() )
642 throw IllegalArgumentException();
643
644 MutexGuard aGuard(m_aMutex);
645 Any aContent;
646 OUString sName;
647 Reference< XNameContainer > xNameContainer(this);
648 if ( !lcl_queryContent(_sName,xNameContainer,aContent,sName) )
649 throw NoSuchElementException(_sName,*this);
650
651 xNameContainer->replaceByName(sName,_aElement);
652}
653
655{
656 ::osl::MutexGuard aGuard( m_aMutex );
657 return impl_getHierarchicalName( false );
658}
659
660OUString SAL_CALL ODocumentContainer::composeHierarchicalName( const OUString& i_rRelativeName )
661{
662 OUString aBuffer = getHierarchicalName() + "/" + i_rRelativeName;
663 return aBuffer;
664}
665
667{
669 try
670 {
671 pContent = dynamic_cast<OContentHelper*>(const_cast<ODocumentContainer*>(this)->implGetByName( _sName, true ).get());
672 }
673 catch(const Exception&)
674 {
675 }
676 return pContent;
677}
678
679void ODocumentContainer::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
680{
681 _rDefault.clear();
682}
683
685{
686 MutexGuard aGuard(m_aMutex);
687 for (auto const& elem : m_aDocumentMap)
688 {
689 Reference<XTransactedObject> xTrans(elem.second.get(),UNO_QUERY);
690 if ( xTrans.is() )
691 xTrans->commit();
692 }
693 Reference<XTransactedObject> xTrans(getContainerStorage(),UNO_QUERY);
694 if ( xTrans.is() )
695 xTrans->commit();
696}
697
699{
700 MutexGuard aGuard(m_aMutex);
701 for (auto const& elem : m_aDocumentMap)
702 {
703 Reference<XTransactedObject> xTrans(elem.second.get(),UNO_QUERY);
704 if ( xTrans.is() )
705 xTrans->revert();
706 }
707 Reference<XTransactedObject> xTrans(getContainerStorage(),UNO_QUERY);
708 if ( xTrans.is() )
709 xTrans->revert();
710}
711
712Reference< XStorage> ODocumentContainer::getContainerStorage() const
713{
714 return m_pImpl->m_pDataSource
716 : Reference< XStorage>();
717}
718
719void SAL_CALL ODocumentContainer::removeByName( const OUString& _rName )
720{
721 ResettableMutexGuard aGuard(m_aMutex);
722
723 // check the arguments
724 if (_rName.isEmpty())
725 throw IllegalArgumentException();
726
727 if (!checkExistence(_rName))
728 throw NoSuchElementException(_rName,*this);
729
730 Reference< XCommandProcessor > xContent( implGetByName( _rName, true ), UNO_QUERY );
731 if ( xContent.is() )
732 {
734
735 aCommand.Name = "delete";
736 xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
737 }
738
739 // do the removal
740 implRemove(_rName);
741
742 notifyByName( aGuard, _rName, nullptr, nullptr, E_REMOVED, ContainerListemers );
743}
744
745void SAL_CALL ODocumentContainer::rename( const OUString& newName )
746{
747 try
748 {
749 osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
750 if ( newName == m_pImpl->m_aProps.aTitle )
751 return;
752
753 sal_Int32 nHandle = PROPERTY_ID_NAME;
754 Any aOld(m_pImpl->m_aProps.aTitle);
755 Any aNew(newName);
756
757 aGuard.clear();
758 fire(&nHandle, &aNew, &aOld, 1, true );
759 m_pImpl->m_aProps.aTitle = newName;
760 fire(&nHandle, &aNew, &aOld, 1, false );
761 }
762 catch(const PropertyVetoException&)
763 {
764 throw ElementExistException(newName,*this);
765 }
766}
767
768} // namespace dbaccess
769
770/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sName
constexpr OUStringLiteral sServiceName
constexpr OUStringLiteral sMediaType
css::uno::Sequence< css::beans::NamedValue > GetObjectPropsByDocumentName(std::u16string_view aDocumentName)
static OUString GetStringClassIDRepresentation(const css::uno::Sequence< sal_Int8 > &aClassID)
static css::uno::Sequence< sal_Int8 > GetSequenceClassIDRepresentation(std::u16string_view aClassID)
bool has(const OUString &_rValueName) const
bool get_ensureType(const OUString &_rValueName, VALUE_TYPE &_out_rValue) const
const css::uno::Any & get(const OUString &_rValueName) const
bool remove(const OUString &_rValueName)
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
void describeProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
OUString getErrorMessage(const ErrorCondition _eCondition) const
mutable::osl::Mutex m_aMutex
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
OUString impl_getHierarchicalName(bool _includingRootContainer) const
const css::uno::Reference< css::uno::XComponentContext > m_aContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
NamedDefinitions::const_iterator const_iterator
const_iterator find(const OUString &_rName) const
const ODefinitionContainer_Impl & getDefinitions() const
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void notifyByName(::osl::ResettableMutexGuard &_rGuard, const OUString &_rName, const css::uno::Reference< css::ucb::XContent > &_xNewElement, const css::uno::Reference< css::ucb::XContent > &xOldElement, ContainerOperation _eOperation, ListenerType _eType)
notifies our container/approve listeners
void implRemove(const OUString &_rName)
remove all references to an object from the container.
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::ucb::XContent > implGetByName(const OUString &_rName, bool _bCreateIfNecessary)
get the object specified by the given name.
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual bool checkExistence(const OUString &_rName)
quickly checks if there already is an element with a given name.
void setElementApproval(PContainerApprove _pElementApproval)
Additionally to our own approvals which new elements must pass, derived classes can specify an additi...
virtual void SAL_CALL removeByName(const OUString &_rName) override
css::uno::Reference< css::embed::XStorage > getContainerStorage() const
virtual ~ODocumentContainer() override
ODocumentContainer(const css::uno::Reference< css::uno::XComponentContext > &_xORB, const css::uno::Reference< css::uno::XInterface > &_xParentContainer, const TContentPtr &_pImpl, bool _bFormsContainer)
constructs the container.
virtual void SAL_CALL removeByHierarchicalName(const OUString &Name) override
virtual OUString determineContentType() const override
OContentHelper.
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
virtual sal_Bool SAL_CALL hasByHierarchicalName(const OUString &_sName) override
virtual void SAL_CALL commit() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(const OUString &aServiceSpecifier) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void getPropertyDefaultByHandle(sal_Int32 _nHandle, css::uno::Any &_rDefault) const override
virtual void SAL_CALL insertByHierarchicalName(const OUString &aName, const css::uno::Any &aElement) override
::rtl::Reference< OContentHelper > getContent(const OUString &_sName) const
virtual css::uno::Any SAL_CALL getByHierarchicalName(const OUString &_sName) override
virtual void SAL_CALL rename(const OUString &newName) override
virtual OUString SAL_CALL getHierarchicalName() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(const OUString &ServiceSpecifier, const css::uno::Sequence< css::uno::Any > &Arguments) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL revert() override
virtual css::uno::Reference< css::ucb::XContent > createObject(const OUString &_rName) override
create an object from its persistent data within the configuration.
virtual void SAL_CALL replaceByHierarchicalName(const OUString &aName, const css::uno::Any &aElement) override
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() override
virtual OUString SAL_CALL composeHierarchicalName(const OUString &aRelativeName) override
virtual css::uno::Reference< css::lang::XComponent > SAL_CALL loadComponentFromURL(const OUString &URL, const OUString &TargetFrameName, sal_Int32 SearchFlags, const css::uno::Sequence< css::beans::PropertyValue > &Arguments) override
static OUString GetDocumentServiceFromMediaType(const OUString &_rMediaType, const css::uno::Reference< css::uno::XComponentContext > &_rxContext, css::uno::Sequence< sal_Int8 > &_rClassId)
#define DBA_RES(id)
::connectivity::SQLError m_aErrors
Sequence< PropertyValue > aArguments
Definition: intercept.cxx:88
Reference< XNameContainer > _xNameContainer
sal_Int32 nIndex
Sequence< sal_Int8 > aSeq
@ Exception
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
std::shared_ptr< OContentHelper_Impl > TContentPtr
OUString newName(std::u16string_view aNewPrefix, std::u16string_view aOldPrefix, std::u16string_view old_Name)
index
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
void dispose()
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
sal_Int32 nHandle
const char *const aClassID
OUString sMessage
Definition: sqlmessage.cxx:159
#define PROPERTY_ID_NAME
constexpr OUStringLiteral INFO_MEDIATYPE
Definition: strings.hxx:229
constexpr OUStringLiteral PROPERTY_URL(u"URL")
constexpr OUStringLiteral SERVICE_NAME_FORM_COLLECTION
Definition: strings.hxx:197
constexpr OUStringLiteral PROPERTY_PERSISTENT_NAME(u"PersistentName")
constexpr OUStringLiteral SERVICE_SDB_DOCUMENTDEFINITION
Definition: strings.hxx:196
constexpr OUStringLiteral PROPERTY_ACTIVE_CONNECTION(u"ActiveConnection")
constexpr OUStringLiteral SERVICE_NAME_REPORT_COLLECTION
Definition: strings.hxx:198
constexpr OUStringLiteral PROPERTY_AS_TEMPLATE(u"AsTemplate")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
constexpr OUStringLiteral PROPERTY_EMBEDDEDOBJECT(u"EmbeddedObject")
OUString aCommand
unsigned char sal_Bool
signed char sal_Int8
#define IMPLEMENT_FORWARD_XINTERFACE3(classname, refcountbase, baseclass2, baseclass3)
std::unique_ptr< char[]> aBuffer