24#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
25#include <com/sun/star/ucb/OpenMode.hpp>
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>
41#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
44#include <osl/mutex.hxx>
58using namespace ::
cppu;
66class LocalNameApproval :
public IContainerApprove
71 void approveElement(
const OUString& _rName )
override;
76void LocalNameApproval::approveElement(
const OUString& _rName )
78 if ( _rName.indexOf(
'/' ) != -1 )
79 throw IllegalArgumentException(
89 ,
const Reference< XInterface >& _xParentContainer
91 ,
bool _bFormsContainer
95 ,m_bFormsContainer(_bFormsContainer)
106 if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
117 return css::uno::Sequence<sal_Int8>();
122 return ::comphelper::concatSequences(
124 OPropertyStateContainer::getTypes( ),
130 return "com.sun.star.comp.dba.ODocumentContainer";
135 for (
const OUString& s : aSupported)
136 if (s == _rServiceName)
143 Reference< XPropertySetInfo > xInfo( createPropertySetInfo(
getInfoHelper() ) );
152 css::uno::Sequence< css::beans::Property > aProps;
154 return new ::cppu::OPropertyArrayHelper(aProps);
172 OSL_ENSURE( aFind != rDefinitions.
end(),
"ODocumentContainer::createObject:Invalid entry in map!" );
173 if ( aFind->second->m_aProps.bIsFolder )
185 template<
class TYPE >
188 if ( io_rArguments.
has( i_rName ) )
191 io_rArguments.
remove( i_rName );
198 Reference< XInterface > xRet;
199 Reference< XContent > xContent;
206 Reference< XCommandProcessor > xCopyFrom;
207 Reference< XConnection > xConnection;
208 bool bAsTemplate(
false );
219 lcl_extractAndRemove( aArgs,
"DocumentServiceName" , sDocServiceName );
222 Any aClassIDArg = aArgs.
get(
"ClassID" );
223 if ( aClassIDArg.hasValue() )
225 if ( !( aClassIDArg >>=
aClassID ) )
228 OUString sClassIDString;
229 if ( !( aClassIDArg >>= sClassIDString ) )
230 throw IllegalArgumentException( OUString(), *
this, 2 );
235#if OSL_DEBUG_LEVEL > 0
237 (void)sClassIDString;
239 aArgs.
remove(
"ClassID" );
245 bool bNew = sPersistentName.isEmpty();
248 sPersistentName =
"Obj" + OUString::number(rDefinitions.
size() + 1);
250 if ( xElements.is() )
251 sPersistentName = ::dbtools::createUniqueName(xElements,sPersistentName);
253 const bool bNeedClassID = !
aClassID.hasElements() && sURL.isEmpty() ;
254 if ( xCopyFrom.is() )
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) )
276 else if ( !sDocServiceName.isEmpty() )
280 const ::comphelper::NamedValueCollection aMediaTypeProps( aProps );
281 aClassID = aMediaTypeProps.getOrDefault(
"ClassID", Sequence< sal_Int8 >() );
289 if ( bNew || ( aFind == rDefinitions.
end() ) )
291 pElementImpl = std::make_shared<OContentHelper_Impl>();
293 pElementImpl->m_aProps.aTitle =
sName;
295 pElementImpl->m_aProps.sPersistentName = sPersistentName;
296 pElementImpl->m_aProps.bAsTemplate = bAsTemplate;
297 pElementImpl->m_pDataSource =
m_pImpl->m_pDataSource;
300 pElementImpl = aFind->second;
305 pDocDef->initialLoad(
aClassID, aCreationArgs, xConnection );
309 OSL_ENSURE( !aCreationArgs.hasElements(),
"ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." );
311 xContent = pDocDef.get();
313 if ( !sURL.isEmpty() )
315 Sequence<Any> aIni{
Any(sURL) };
319 Reference< XCommandProcessor > xCommandProcessor(xContent,UNO_QUERY);
322 xCommandProcessor->execute(
aCommand,-1,Reference< XCommandEnvironment >());
328 const Any* pBegin = _aArguments.getConstArray();
329 const Any* pEnd = pBegin + _aArguments.getLength();
330 PropertyValue aValue;
332 Reference<XNameAccess> xCopyFrom;
333 for(;pBegin != pEnd;++pBegin)
338 aValue.Value >>=
sName;
342 xCopyFrom.set(aValue.Value,UNO_QUERY);
345 OSL_ENSURE(!
sName.isEmpty(),
"Invalid name for a document container!");
349 if ( aFind == rDefinitions.
end() )
351 pElementImpl = std::make_shared<ODefinitionContainer_Impl>();
352 pElementImpl->m_aProps.aTitle =
sName;
353 pElementImpl->m_pDataSource =
m_pImpl->m_pDataSource;
356 pElementImpl = aFind->second;
357 OSL_ENSURE( pElementImpl ,
" Invalid entry in map!");
361 if ( xCopyFrom.is() )
363 Sequence< OUString>
aSeq = xCopyFrom->getElementNames();
364 const OUString* elements =
aSeq.getConstArray();
365 const OUString* elementsEnd = elements +
aSeq.getLength();
366 Reference<XContent> xObjectToCopy;
368 Reference<XMultiServiceFactory> xORB(xContent,UNO_QUERY);
369 OSL_ENSURE(xORB.is(),
"No service factory given");
372 for(;elements != elementsEnd;++elements)
374 xCopyFrom->getByName(*elements) >>= xObjectToCopy;
377 {
"Name",
Any(*elements)},
378 {
"Parent",
Any(xContent)},
383 if ( Reference< XNameAccess >( xObjectToCopy, UNO_QUERY ).is() )
394 Reference<XNameContainer> xNameContainer(xContent,UNO_QUERY);
395 if ( xNameContainer.is() )
396 xNameContainer->insertByName(*elements,
Any(xNew));
421 OpenCommandArgument2 aOpenCommand;
422 if ( !(
aCommand.Argument >>= aOpenCommand ) )
424 OSL_FAIL(
"Wrong argument type!" );
426 Any( IllegalArgumentException(
434 ( ( aOpenCommand.Mode == OpenMode::ALL ) ||
435 ( aOpenCommand.Mode == OpenMode::FOLDERS ) ||
436 ( aOpenCommand.Mode == OpenMode::DOCUMENTS ) );
442 Reference< XDynamicResultSet > xSet
453 Any( UnsupportedOpenModeException(
456 sal_Int16( aOpenCommand.Mode ) ) ),
461 else if (
aCommand.Name ==
"insert" )
465 InsertCommandArgument arg;
466 if ( !(
aCommand.Argument >>= arg ) )
468 OSL_FAIL(
"Wrong argument type!" );
470 Any( IllegalArgumentException(
478 else if (
aCommand.Name ==
"delete" )
482 const OUString* pIter =
aSeq.getConstArray();
483 const OUString* pEnd = pIter +
aSeq.getLength();
484 for(;pIter != pEnd;++pIter)
496 bool lcl_queryContent(std::u16string_view _sName,Reference< XNameContainer >& _xNameContainer,Any& _rRet,OUString& _sSimpleName)
503 _sSimpleName =
sName;
505 while ( nIndex != -1 && bRet )
513 _sSimpleName =
sName;
520 _sSimpleName =
sName;
530 ,
const Sequence< PropertyValue >& Arguments )
535 Reference< XComponent > xComp;
539 Reference< XNameContainer > xNameContainer(
this);
541 if ( !lcl_queryContent(_sURL,xNameContainer,aContent,
sName) )
544 DBA_RES(RID_STR_NAME_NOT_FOUND).replaceFirst(
"$name$", _sURL));
545 throw IllegalArgumentException(
sMessage, *
this, 1 );
548 Reference< XCommandProcessor > xContent(aContent,UNO_QUERY);
555 aArgs.
remove(
"OpenMode" );
557 OpenCommandArgument2 aOpenCommand;
558 aOpenCommand.Mode = OpenMode::DOCUMENT;
559 aArgs.
put(
"OpenCommandArgument", aOpenCommand );
562 xComp.set(xContent->execute(
aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY);
565 catch(
const NoSuchElementException&)
567 throw IllegalArgumentException();
569 catch(
const WrappedTargetException &e)
571 throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException);
580 Reference< XNameContainer > xNameContainer(
this);
582 if ( lcl_queryContent(_sName,xNameContainer,aContent,
sName) )
584 throw NoSuchElementException(_sName,*
this);
591 Reference< XNameContainer > xNameContainer(
this);
593 return lcl_queryContent(_sName,xNameContainer,aContent,
sName);
599 Reference< XContent > xContent(_aElement,UNO_QUERY);
600 if ( !xContent.is() )
601 throw IllegalArgumentException();
605 Reference< XNameContainer > xNameContainer(
this);
607 if ( lcl_queryContent(_sName,xNameContainer,aContent,
sName) )
608 throw ElementExistException(_sName,*
this);
610 if ( !xNameContainer.is() )
614 DBA_RES(RID_STR_NO_SUB_FOLDER).replaceFirst(
"$folder$",
616 throw IllegalArgumentException(
sMessage, *
this, 1 );
619 xNameContainer->insertByName(
sName,_aElement);
624 if ( _sName.isEmpty() )
625 throw NoSuchElementException(_sName,*
this);
630 Reference< XNameContainer > xNameContainer(
this);
631 if ( !lcl_queryContent(_sName,xNameContainer,aContent,
sName) )
632 throw NoSuchElementException(_sName,*
this);
634 xNameContainer->removeByName(
sName);
640 Reference< XContent > xContent(_aElement,UNO_QUERY);
641 if ( !xContent.is() )
642 throw IllegalArgumentException();
647 Reference< XNameContainer > xNameContainer(
this);
648 if ( !lcl_queryContent(_sName,xNameContainer,aContent,
sName) )
649 throw NoSuchElementException(_sName,*
this);
651 xNameContainer->replaceByName(
sName,_aElement);
656 ::osl::MutexGuard aGuard(
m_aMutex );
689 Reference<XTransactedObject> xTrans(elem.second.get(),UNO_QUERY);
703 Reference<XTransactedObject> xTrans(elem.second.get(),UNO_QUERY);
716 : Reference< XStorage>();
721 ResettableMutexGuard aGuard(
m_aMutex);
724 if (_rName.isEmpty())
725 throw IllegalArgumentException();
728 throw NoSuchElementException(_rName,*
this);
730 Reference< XCommandProcessor > xContent(
implGetByName( _rName,
true ), UNO_QUERY );
736 xContent->execute(
aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
749 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex);
758 fire(&
nHandle, &aNew, &aOld, 1,
true );
760 fire(&
nHandle, &aNew, &aOld, 1,
false );
762 catch(
const PropertyVetoException&)
764 throw ElementExistException(
newName,*
this);
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
::cppu::IPropertyArrayHelper * getArrayHelper()
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
const_iterator end() const
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)
::connectivity::SQLError m_aErrors
Sequence< PropertyValue > aArguments
Reference< XNameContainer > _xNameContainer
Sequence< sal_Int8 > aSeq
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)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
const char *const aClassID
constexpr OUStringLiteral INFO_MEDIATYPE
constexpr OUStringLiteral PROPERTY_URL(u"URL")
constexpr OUStringLiteral SERVICE_NAME_FORM_COLLECTION
constexpr OUStringLiteral PROPERTY_PERSISTENT_NAME(u"PersistentName")
constexpr OUStringLiteral SERVICE_SDB_DOCUMENTDEFINITION
constexpr OUStringLiteral PROPERTY_ACTIVE_CONNECTION(u"ActiveConnection")
constexpr OUStringLiteral SERVICE_NAME_REPORT_COLLECTION
constexpr OUStringLiteral PROPERTY_AS_TEMPLATE(u"AsTemplate")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
constexpr OUStringLiteral PROPERTY_EMBEDDEDOBJECT(u"EmbeddedObject")
#define IMPLEMENT_FORWARD_XINTERFACE3(classname, refcountbase, baseclass2, baseclass3)
std::unique_ptr< char[]> aBuffer