LCOV - code coverage report
Current view: top level - dbaccess/source/core/dataaccess - documentcontainer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 67 397 16.9 %
Date: 2014-11-03 Functions: 17 46 37.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "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>
      42             : 
      43             : #include <vcl/svapp.hxx>
      44             : #include <osl/mutex.hxx>
      45             : 
      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;
      58             : 
      59             : namespace dbaccess
      60             : {
      61             : 
      62             : // LocalNameApproval
      63             : class LocalNameApproval : public IContainerApprove
      64             : {
      65             :     ::connectivity::SQLError    m_aErrors;
      66             : 
      67             : public:
      68         374 :     LocalNameApproval( const Reference< XComponentContext >& _rxContext )
      69         374 :         :m_aErrors( _rxContext )
      70             :     {
      71         374 :     }
      72         748 :     virtual ~LocalNameApproval()
      73         374 :     {
      74         748 :     }
      75             : 
      76             :     void SAL_CALL   approveElement( const OUString& _rName, const Reference< XInterface >& _rxElement ) SAL_OVERRIDE;
      77             : };
      78             : 
      79           0 : void SAL_CALL LocalNameApproval::approveElement( const OUString& _rName, const Reference< XInterface >& /*_rxElement*/ )
      80             : {
      81           0 :     if ( _rName.indexOf( '/' ) != -1 )
      82             :         throw IllegalArgumentException(
      83             :             m_aErrors.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES ),
      84             :             NULL,
      85             :             0
      86           0 :         );
      87           0 : }
      88             : 
      89             : // ODocumentContainer
      90             : 
      91         374 : ODocumentContainer::ODocumentContainer(const Reference< XComponentContext >& _xORB
      92             :                                     ,const Reference< XInterface >& _xParentContainer
      93             :                                     ,const TContentPtr& _pImpl
      94             :                                     , bool _bFormsContainer
      95             :                                     )
      96             :     :ODefinitionContainer(_xORB,_xParentContainer,_pImpl)
      97             :     ,OPropertyStateContainer(OContentHelper::rBHelper)
      98         374 :     ,m_bFormsContainer(_bFormsContainer)
      99             : {
     100             :     registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED,
     101         374 :                     &m_pImpl->m_aProps.aTitle, ::getCppuType(&m_pImpl->m_aProps.aTitle));
     102             : 
     103         374 :     setElementApproval( PContainerApprove( new LocalNameApproval ( _xORB ) ) );
     104         374 : }
     105             : 
     106        1122 : ODocumentContainer::~ODocumentContainer()
     107             : {
     108             : 
     109         374 :     if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
     110             :     {
     111           0 :         acquire();
     112           0 :         dispose();
     113             :     }
     114         748 : }
     115             : 
     116       10674 : IMPLEMENT_FORWARD_XINTERFACE3( ODocumentContainer,ODefinitionContainer,ODocumentContainer_Base,OPropertyStateContainer)
     117             : 
     118           0 : css::uno::Sequence<sal_Int8> ODocumentContainer::getImplementationId()
     119             :     throw (css::uno::RuntimeException, std::exception)
     120             : {
     121           0 :     return css::uno::Sequence<sal_Int8>();
     122             : }
     123             : 
     124           0 : IMPLEMENT_GETTYPES3(ODocumentContainer,ODefinitionContainer,OPropertyStateContainer,ODocumentContainer_Base);
     125           0 : IMPLEMENT_SERVICE_INFO_IMPLNAME(ODocumentContainer, "com.sun.star.comp.dba.ODocumentContainer");
     126           0 : IMPLEMENT_SERVICE_INFO_SUPPORTS(ODocumentContainer);
     127           0 : IMPLEMENT_PROPERTYCONTAINER_DEFAULTS(ODocumentContainer)
     128             : 
     129           0 : Sequence< OUString > SAL_CALL ODocumentContainer::getSupportedServiceNames(  ) throw(RuntimeException, std::exception)
     130             : {
     131           0 :     Sequence< OUString > aSupported(1);
     132           0 :     aSupported[0] = m_bFormsContainer ? OUString(SERVICE_NAME_FORM_COLLECTION) : OUString(SERVICE_NAME_REPORT_COLLECTION);
     133           0 :     return aSupported;
     134             : }
     135             : 
     136           0 : OUString ODocumentContainer::determineContentType() const
     137             : {
     138           0 :     return OUString();
     139             : }
     140             : 
     141          12 : Reference< XContent > ODocumentContainer::createObject( const OUString& _rName)
     142             : {
     143          12 :     const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
     144          12 :     ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( _rName );
     145             :     OSL_ENSURE( aFind != rDefinitions.end(), "ODocumentContainer::createObject:Invalid entry in map!" );
     146          12 :     if ( aFind->second->m_aProps.bIsFolder )
     147           0 :         return new ODocumentContainer( m_aContext, *this, aFind->second, m_bFormsContainer );
     148          12 :     return new ODocumentDefinition( *this, m_aContext, aFind->second, m_bFormsContainer );
     149             : }
     150             : 
     151           0 : Reference< XInterface > SAL_CALL ODocumentContainer::createInstance( const OUString& aServiceSpecifier ) throw (Exception, RuntimeException, std::exception)
     152             : {
     153           0 :     return createInstanceWithArguments( aServiceSpecifier, Sequence< Any >() );
     154             : }
     155             : 
     156             : namespace
     157             : {
     158             :     template< class TYPE >
     159          96 :     void lcl_extractAndRemove( ::comphelper::NamedValueCollection& io_rArguments, const OUString& i_rName, TYPE& o_rValue )
     160             :     {
     161          96 :         if ( io_rArguments.has( i_rName ) )
     162             :         {
     163          36 :             io_rArguments.get_ensureType( i_rName, o_rValue );
     164          36 :             io_rArguments.remove( i_rName );
     165             :         }
     166          96 :     }
     167             : }
     168             : 
     169          12 : Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments( const OUString& ServiceSpecifier, const Sequence< Any >& _aArguments ) throw (Exception, RuntimeException, std::exception)
     170             : {
     171          12 :     Reference< XInterface > xRet;
     172          24 :     Reference< XContent > xContent;
     173          12 :     if ( ServiceSpecifier == SERVICE_SDB_DOCUMENTDEFINITION )
     174             :     {
     175          12 :         MutexGuard aGuard(m_aMutex);
     176             : 
     177             :         // extract known arguments
     178          24 :         OUString sName, sPersistentName, sURL, sMediaType, sDocServiceName;
     179          24 :         Reference< XCommandProcessor > xCopyFrom;
     180          24 :         Reference< XConnection > xConnection;
     181          12 :         bool bAsTemplate( false );
     182          24 :         Sequence< sal_Int8 > aClassID;
     183             : 
     184          24 :         ::comphelper::NamedValueCollection aArgs( _aArguments );
     185          12 :         lcl_extractAndRemove( aArgs, PROPERTY_NAME, sName );
     186          12 :         lcl_extractAndRemove( aArgs, PROPERTY_PERSISTENT_NAME, sPersistentName );
     187          12 :         lcl_extractAndRemove( aArgs, PROPERTY_URL, sURL );
     188          12 :         lcl_extractAndRemove( aArgs, PROPERTY_EMBEDDEDOBJECT, xCopyFrom );
     189          12 :         lcl_extractAndRemove( aArgs, PROPERTY_ACTIVE_CONNECTION, xConnection );
     190          12 :         lcl_extractAndRemove( aArgs, PROPERTY_AS_TEMPLATE, bAsTemplate );
     191          12 :         lcl_extractAndRemove( aArgs, INFO_MEDIATYPE, sMediaType );
     192          12 :         lcl_extractAndRemove( aArgs, "DocumentServiceName" , sDocServiceName );
     193             : 
     194             :         // ClassID has two allowed types, so a special treatment here
     195          24 :         Any aClassIDArg = aArgs.get( "ClassID" );
     196          12 :         if ( aClassIDArg.hasValue() )
     197             :         {
     198           0 :             if ( !( aClassIDArg >>= aClassID ) )
     199             :             {
     200             :                 // Extended for usage also with a string
     201           0 :                 OUString sClassIDString;
     202           0 :                 if ( !( aClassIDArg >>= sClassIDString ) )
     203           0 :                     throw IllegalArgumentException( OUString(), *this, 2 );
     204             : 
     205           0 :                 aClassID = ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( sClassIDString );
     206             :             }
     207             : 
     208             : #if OSL_DEBUG_LEVEL > 0
     209             :             OUString sClassIDString = ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation( aClassID );
     210             :             (void)sClassIDString;
     211             : #endif
     212           0 :             aArgs.remove( "ClassID" );
     213             :         }
     214             :         // Everything which now is still present in the arguments is passed to the embedded object
     215          24 :         const Sequence< PropertyValue > aCreationArgs( aArgs.getPropertyValues() );
     216             : 
     217          12 :         const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
     218          12 :         bool bNew = sPersistentName.isEmpty();
     219          12 :         if ( bNew )
     220             :         {
     221           0 :             const static OUString sBaseName("Obj");
     222             : 
     223           0 :             sPersistentName = sBaseName;
     224           0 :             sPersistentName += OUString::number(rDefinitions.size() + 1);
     225           0 :             Reference<XNameAccess> xElements(getContainerStorage(),UNO_QUERY);
     226           0 :             if ( xElements.is() )
     227           0 :                 sPersistentName = ::dbtools::createUniqueName(xElements,sPersistentName);
     228             : 
     229           0 :             const bool bNeedClassID = (0 == aClassID.getLength()) && sURL.isEmpty() ;
     230           0 :             if ( xCopyFrom.is() )
     231             :             {
     232           0 :                 Sequence<Any> aIni(2);
     233           0 :                 aIni[0] <<= getContainerStorage();
     234           0 :                 aIni[1] <<= sPersistentName;
     235           0 :                 Command aCommand;
     236           0 :                 aCommand.Name = "copyTo";
     237           0 :                 aCommand.Argument <<= aIni;
     238             : 
     239           0 :                 xCopyFrom->execute(aCommand,-1,Reference< XCommandEnvironment >());
     240           0 :                 Reference<XPropertySet> xProp(xCopyFrom,UNO_QUERY);
     241           0 :                 if ( xProp.is() && xProp->getPropertySetInfo().is() && xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE) )
     242           0 :                     xProp->getPropertyValue(PROPERTY_AS_TEMPLATE) >>= bAsTemplate;
     243             : 
     244             :                 // if we do not have an own class ID, see if we can determine one from the copy we just created
     245           0 :                 if ( bNeedClassID )
     246           0 :                     ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName, m_aContext, aClassID );
     247             :             }
     248             :             else
     249             :             {
     250           0 :                 if ( bNeedClassID )
     251             :                 {
     252           0 :                     if ( !sMediaType.isEmpty() )
     253           0 :                         ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType, m_aContext, aClassID );
     254           0 :                     else if ( !sDocServiceName.isEmpty() )
     255             :                     {
     256           0 :                         ::comphelper::MimeConfigurationHelper aConfigHelper( m_aContext );
     257           0 :                         const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByDocumentName( sDocServiceName ) );
     258           0 :                         const ::comphelper::NamedValueCollection aMediaTypeProps( aProps );
     259           0 :                         aClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() );
     260             :                     }
     261             :                 }
     262           0 :             }
     263             :         }
     264             : 
     265          12 :         ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( sName );
     266          24 :         TContentPtr pElementImpl;
     267          12 :         if ( bNew || ( aFind == rDefinitions.end() ) )
     268             :         {
     269          12 :             pElementImpl.reset( new OContentHelper_Impl );
     270          12 :             if ( !bNew )
     271          12 :                 pElementImpl->m_aProps.aTitle = sName;
     272             : 
     273          12 :             pElementImpl->m_aProps.sPersistentName = sPersistentName;
     274          12 :             pElementImpl->m_aProps.bAsTemplate = bAsTemplate;
     275          12 :             pElementImpl->m_pDataSource = m_pImpl->m_pDataSource;
     276             :         }
     277             :         else
     278           0 :             pElementImpl = aFind->second;
     279             : 
     280          24 :         ::rtl::Reference< ODocumentDefinition > pDocDef = new ODocumentDefinition( *this, m_aContext, pElementImpl, m_bFormsContainer );
     281          12 :         if ( aClassID.getLength() )
     282             :         {
     283           0 :             pDocDef->initialLoad( aClassID, aCreationArgs, xConnection );
     284             :         }
     285             :         else
     286             :         {
     287             :             OSL_ENSURE( aCreationArgs.getLength() == 0, "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." );
     288             :         }
     289          12 :         xContent = pDocDef.get();
     290             : 
     291          12 :         if ( !sURL.isEmpty() )
     292             :         {
     293           0 :             Sequence<Any> aIni(2);
     294           0 :             aIni[0] <<= sURL;
     295           0 :             Command aCommand;
     296           0 :             aCommand.Name = "insert";
     297           0 :             aCommand.Argument <<= aIni;
     298           0 :             Reference< XCommandProcessor > xCommandProcessor(xContent,UNO_QUERY);
     299           0 :             if ( xContent.is() )
     300             :             {
     301           0 :                 xCommandProcessor->execute(aCommand,-1,Reference< XCommandEnvironment >());
     302           0 :             }
     303          12 :         }
     304             :     }
     305           0 :     else if ( ServiceSpecifier == SERVICE_NAME_FORM_COLLECTION || SERVICE_NAME_REPORT_COLLECTION == ServiceSpecifier )
     306             :     {
     307           0 :         const Any* pBegin = _aArguments.getConstArray();
     308           0 :         const Any* pEnd = pBegin + _aArguments.getLength();
     309           0 :         PropertyValue aValue;
     310           0 :         OUString sName;
     311           0 :         Reference<XNameAccess> xCopyFrom;
     312           0 :         for(;pBegin != pEnd;++pBegin)
     313             :         {
     314           0 :             *pBegin >>= aValue;
     315           0 :             if ( aValue.Name == PROPERTY_NAME)
     316             :             {
     317           0 :                 aValue.Value >>= sName;
     318             :             }
     319           0 :             else if ( aValue.Name == PROPERTY_EMBEDDEDOBJECT)
     320             :             {
     321           0 :                 xCopyFrom.set(aValue.Value,UNO_QUERY);
     322             :             }
     323             :         }
     324             :         OSL_ENSURE(!sName.isEmpty(),"Invalid name for a document container!");
     325           0 :         const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
     326           0 :         ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( sName );
     327           0 :         TContentPtr pElementImpl;
     328           0 :         if ( aFind == rDefinitions.end() )
     329             :         {
     330           0 :             pElementImpl.reset(new ODefinitionContainer_Impl);
     331           0 :             pElementImpl->m_aProps.aTitle = sName;
     332           0 :             pElementImpl->m_pDataSource = m_pImpl->m_pDataSource;
     333             :         }
     334             :         else
     335           0 :             pElementImpl = aFind->second;
     336             :         OSL_ENSURE( pElementImpl ," Invalid entry in map!");
     337           0 :         xContent = new ODocumentContainer( m_aContext, *this, pElementImpl, ServiceSpecifier == SERVICE_NAME_FORM_COLLECTION );
     338             : 
     339             :         // copy children
     340           0 :         if ( xCopyFrom.is() )
     341             :         {
     342           0 :             Sequence< OUString> aSeq = xCopyFrom->getElementNames();
     343           0 :             const OUString* elements = aSeq.getConstArray();
     344           0 :             const OUString* elementsEnd = elements + aSeq.getLength();
     345           0 :             Reference<XContent> xObjectToCopy;
     346             : 
     347           0 :             Reference<XMultiServiceFactory> xORB(xContent,UNO_QUERY);
     348             :             OSL_ENSURE(xORB.is(),"No service factory given");
     349           0 :             if ( xORB.is() )
     350             :             {
     351           0 :                 for(;elements != elementsEnd;++elements)
     352             :                 {
     353           0 :                     xCopyFrom->getByName(*elements) >>= xObjectToCopy;
     354           0 :                     Sequence< Any > aArguments(3);
     355           0 :                     PropertyValue aArgument;
     356             :                     // set as folder
     357           0 :                     aArgument.Name = "Name";
     358           0 :                     aArgument.Value <<= *elements;
     359           0 :                     aArguments[0] <<= aArgument;
     360             :                     //parent
     361           0 :                     aArgument.Name = "Parent";
     362           0 :                     aArgument.Value <<= xContent;
     363           0 :                     aArguments[1] <<= aArgument;
     364             : 
     365           0 :                     aArgument.Name = PROPERTY_EMBEDDEDOBJECT;
     366           0 :                     aArgument.Value <<= xObjectToCopy;
     367           0 :                     aArguments[2] <<= aArgument;
     368             : 
     369           0 :                     OUString sServiceName;
     370           0 :                     if ( Reference< XNameAccess >( xObjectToCopy, UNO_QUERY ).is() )
     371             :                     {
     372           0 :                         if ( m_bFormsContainer )
     373           0 :                             sServiceName = SERVICE_NAME_FORM_COLLECTION;
     374             :                         else
     375           0 :                             sServiceName = SERVICE_NAME_REPORT_COLLECTION;
     376             :                     }
     377             :                     else
     378           0 :                         sServiceName = SERVICE_SDB_DOCUMENTDEFINITION;
     379             : 
     380           0 :                     Reference<XContent > xNew(xORB->createInstanceWithArguments(sServiceName,aArguments),UNO_QUERY);
     381           0 :                     Reference<XNameContainer> xNameContainer(xContent,UNO_QUERY);
     382           0 :                     if ( xNameContainer.is() )
     383           0 :                         xNameContainer->insertByName(*elements,makeAny(xNew));
     384           0 :                 }
     385           0 :             }
     386           0 :         }
     387             :     }
     388          12 :     xRet = xContent;
     389          24 :     return xRet;
     390             : }
     391             : 
     392           0 : Sequence< OUString > SAL_CALL ODocumentContainer::getAvailableServiceNames(  ) throw (RuntimeException, std::exception)
     393             : {
     394           0 :     Sequence< OUString > aSe(3);
     395           0 :     aSe[0] = SERVICE_SDB_DOCUMENTDEFINITION;
     396           0 :     aSe[1] = SERVICE_NAME_FORM_COLLECTION;
     397           0 :     aSe[2] = SERVICE_NAME_REPORT_COLLECTION;
     398           0 :     return aSe;
     399             : }
     400             : 
     401           0 : Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException, std::exception)
     402             : {
     403           0 :     Any aRet;
     404           0 :     if ( aCommand.Name.equalsAscii( "open" ) )
     405             :     {
     406             :         // open command for a folder content
     407           0 :         OpenCommandArgument2 aOpenCommand;
     408           0 :           if ( !( aCommand.Argument >>= aOpenCommand ) )
     409             :         {
     410             :             OSL_FAIL( "Wrong argument type!" );
     411             :             ucbhelper::cancelCommandExecution(
     412             :                 makeAny( IllegalArgumentException(
     413             :                                     OUString(),
     414             :                                     static_cast< cppu::OWeakObject * >( this ),
     415             :                                     -1 ) ),
     416           0 :                 Environment );
     417             :             // Unreachable
     418             :         }
     419             :         bool bOpenFolder =
     420           0 :             ( ( aOpenCommand.Mode == OpenMode::ALL ) ||
     421           0 :               ( aOpenCommand.Mode == OpenMode::FOLDERS ) ||
     422           0 :               ( aOpenCommand.Mode == OpenMode::DOCUMENTS ) );
     423             : 
     424           0 :         if ( bOpenFolder )
     425             :         {
     426             :             // open as folder - return result set
     427             : 
     428             :             Reference< XDynamicResultSet > xSet
     429             :                             = new DynamicResultSet( m_aContext,
     430             :                                                     this,
     431             :                                                     aOpenCommand,
     432           0 :                                                     Environment );
     433           0 :             aRet <<= xSet;
     434             :           }
     435             :         else
     436             :         {
     437             :             // Unsupported.
     438             :             ucbhelper::cancelCommandExecution(
     439             :                 makeAny( UnsupportedOpenModeException(
     440             :                                 OUString(),
     441             :                                 static_cast< cppu::OWeakObject * >( this ),
     442             :                                 sal_Int16( aOpenCommand.Mode ) ) ),
     443           0 :                 Environment );
     444             :                 // Unreachable
     445           0 :         }
     446             :     }
     447           0 :     else if ( aCommand.Name == "insert" )
     448             :     {
     449             :         // insert
     450             : 
     451           0 :         InsertCommandArgument arg;
     452           0 :           if ( !( aCommand.Argument >>= arg ) )
     453             :         {
     454             :               OSL_FAIL( "Wrong argument type!" );
     455             :             ucbhelper::cancelCommandExecution(
     456             :                 makeAny( IllegalArgumentException(
     457             :                                     OUString(),
     458             :                                     static_cast< cppu::OWeakObject * >( this ),
     459             :                                     -1 ) ),
     460           0 :                 Environment );
     461             :             // Unreachable
     462           0 :         }
     463             :     }
     464           0 :     else if ( aCommand.Name == "delete" )
     465             :     {
     466             :         // delete
     467           0 :         Sequence< OUString> aSeq = getElementNames();
     468           0 :         const OUString* pIter = aSeq.getConstArray();
     469           0 :         const OUString* pEnd   = pIter + aSeq.getLength();
     470           0 :         for(;pIter != pEnd;++pIter)
     471           0 :             removeByName(*pIter);
     472             : 
     473           0 :         dispose();
     474             :     }
     475             :     else
     476           0 :         aRet = OContentHelper::execute(aCommand,CommandId,Environment);
     477           0 :     return aRet;
     478             : }
     479             : 
     480             : namespace
     481             : {
     482           0 :     bool lcl_queryContent(const OUString& _sName,Reference< XNameContainer >& _xNameContainer,Any& _rRet,OUString& _sSimpleName)
     483             :     {
     484           0 :         sal_Int32 nIndex = 0;
     485           0 :         OUString sName = _sName.getToken(0,'/',nIndex);
     486           0 :         bool bRet = _xNameContainer->hasByName(sName);
     487           0 :         if ( bRet )
     488             :         {
     489           0 :             _rRet = _xNameContainer->getByName(_sSimpleName = sName);
     490           0 :             while ( nIndex != -1 && bRet )
     491             :             {
     492           0 :                 sName = _sName.getToken(0,'/',nIndex);
     493           0 :                 _xNameContainer.set(_rRet,UNO_QUERY);
     494           0 :                 bRet = _xNameContainer.is();
     495           0 :                 if ( bRet )
     496             :                 {
     497           0 :                     bRet = _xNameContainer->hasByName(sName);
     498           0 :                     _sSimpleName = sName;
     499           0 :                     if ( bRet )
     500           0 :                         _rRet = _xNameContainer->getByName(sName);
     501             :                 }
     502             :             }
     503             :         }
     504           0 :         if ( nIndex == -1 )
     505           0 :             _sSimpleName = sName; // a content
     506             :         else
     507           0 :             _xNameContainer.clear(); // a sub folder doesn't exist
     508           0 :         return bRet;
     509             :     }
     510             : }
     511             : 
     512           0 : 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)
     516             : {
     517           0 :     ::SolarMutexGuard aSolarGuard;
     518             : 
     519           0 :     MutexGuard aGuard(m_aMutex);
     520           0 :     Reference< XComponent > xComp;
     521             :     try
     522             :     {
     523           0 :         Any aContent;
     524           0 :         Reference< XNameContainer > xNameContainer(this);
     525           0 :         OUString sName;
     526           0 :         if ( !lcl_queryContent(_sURL,xNameContainer,aContent,sName) )
     527             :         {
     528             :             OUString sMessage(
     529           0 :                 DBA_RES(RID_STR_NAME_NOT_FOUND).replaceFirst("$name$", _sURL));
     530           0 :             throw IllegalArgumentException( sMessage, *this, 1 );
     531             :         }
     532             : 
     533           0 :         Reference< XCommandProcessor > xContent(aContent,UNO_QUERY);
     534           0 :         if ( xContent.is() )
     535             :         {
     536           0 :             Command aCommand;
     537             : 
     538           0 :             ::comphelper::NamedValueCollection aArgs( Arguments );
     539           0 :             aCommand.Name = aArgs.getOrDefault( "OpenMode", OUString("open") );
     540           0 :             aArgs.remove( "OpenMode" );
     541             : 
     542           0 :             OpenCommandArgument2 aOpenCommand;
     543           0 :             aOpenCommand.Mode = OpenMode::DOCUMENT;
     544           0 :             aArgs.put( "OpenCommandArgument", aOpenCommand );
     545             : 
     546           0 :             aCommand.Argument <<= aArgs.getPropertyValues();
     547           0 :             xComp.set(xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY);
     548           0 :         }
     549             :     }
     550           0 :     catch(const NoSuchElementException&)
     551             :     {
     552           0 :         throw IllegalArgumentException();
     553             :     }
     554           0 :     catch(const WrappedTargetException &e)
     555             :     {
     556           0 :         throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException);
     557             :     }
     558           0 :     return xComp;
     559             : }
     560             : 
     561           0 : Any SAL_CALL ODocumentContainer::getByHierarchicalName( const OUString& _sName ) throw (NoSuchElementException, RuntimeException, std::exception)
     562             : {
     563           0 :     MutexGuard aGuard(m_aMutex);
     564           0 :     Any aContent;
     565           0 :     Reference< XNameContainer > xNameContainer(this);
     566           0 :     OUString sName;
     567           0 :     if ( lcl_queryContent(_sName,xNameContainer,aContent,sName) )
     568           0 :         return aContent;
     569           0 :     throw NoSuchElementException(_sName,*this);
     570             : }
     571             : 
     572           0 : sal_Bool SAL_CALL ODocumentContainer::hasByHierarchicalName( const OUString& _sName ) throw (RuntimeException, std::exception)
     573             : {
     574           0 :     MutexGuard aGuard(m_aMutex);
     575           0 :     Any aContent;
     576           0 :     Reference< XNameContainer > xNameContainer(this);
     577           0 :     OUString sName;
     578           0 :     return lcl_queryContent(_sName,xNameContainer,aContent,sName);
     579             : }
     580             : 
     581             : // XHierarchicalNameContainer
     582           0 : void SAL_CALL ODocumentContainer::insertByHierarchicalName( const OUString& _sName, const Any& _aElement ) throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException, std::exception)
     583             : {
     584           0 :     Reference< XContent > xContent(_aElement,UNO_QUERY);
     585           0 :     if ( !xContent.is() )
     586           0 :         throw IllegalArgumentException();
     587             : 
     588           0 :     ClearableMutexGuard aGuard(m_aMutex);
     589           0 :     Any aContent;
     590           0 :     Reference< XNameContainer > xNameContainer(this);
     591           0 :     OUString sName;
     592           0 :     if ( lcl_queryContent(_sName,xNameContainer,aContent,sName) )
     593           0 :         throw ElementExistException(_sName,*this);
     594             : 
     595           0 :     if ( !xNameContainer.is() )
     596             :     {
     597           0 :         sal_Int32 index = sName.getLength();
     598             :         OUString sMessage(
     599             :             DBA_RES(RID_STR_NO_SUB_FOLDER).replaceFirst("$folder$",
     600           0 :                 _sName.getToken(0,'/',index)));
     601           0 :         throw IllegalArgumentException( sMessage, *this, 1 );
     602             :     }
     603             : 
     604           0 :     xNameContainer->insertByName(sName,_aElement);
     605           0 : }
     606             : 
     607           0 : void SAL_CALL ODocumentContainer::removeByHierarchicalName( const OUString& _sName ) throw (NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
     608             : {
     609           0 :     if ( _sName.isEmpty() )
     610           0 :         throw NoSuchElementException(_sName,*this);
     611             : 
     612           0 :     ClearableMutexGuard aGuard(m_aMutex);
     613           0 :     Any aContent;
     614           0 :     OUString sName;
     615           0 :     Reference< XNameContainer > xNameContainer(this);
     616           0 :     if ( !lcl_queryContent(_sName,xNameContainer,aContent,sName) )
     617           0 :         throw NoSuchElementException(_sName,*this);
     618             : 
     619           0 :     xNameContainer->removeByName(sName);
     620           0 : }
     621             : 
     622             : // XHierarchicalNameReplace
     623           0 : void SAL_CALL ODocumentContainer::replaceByHierarchicalName( const OUString& _sName, const Any& _aElement ) throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
     624             : {
     625           0 :     Reference< XContent > xContent(_aElement,UNO_QUERY);
     626           0 :     if ( !xContent.is() )
     627           0 :         throw IllegalArgumentException();
     628             : 
     629           0 :     ClearableMutexGuard aGuard(m_aMutex);
     630           0 :     Any aContent;
     631           0 :     OUString sName;
     632           0 :     Reference< XNameContainer > xNameContainer(this);
     633           0 :     if ( !lcl_queryContent(_sName,xNameContainer,aContent,sName) )
     634           0 :         throw NoSuchElementException(_sName,*this);
     635             : 
     636           0 :     xNameContainer->replaceByName(sName,_aElement);
     637           0 : }
     638             : 
     639           0 : OUString SAL_CALL ODocumentContainer::getHierarchicalName() throw (RuntimeException, std::exception)
     640             : {
     641           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     642           0 :     return impl_getHierarchicalName( false );
     643             : }
     644             : 
     645           0 : OUString SAL_CALL ODocumentContainer::composeHierarchicalName( const OUString& i_rRelativeName ) throw (IllegalArgumentException, NoSupportException, RuntimeException, std::exception)
     646             : {
     647           0 :     OUStringBuffer aBuffer;
     648           0 :     aBuffer.append( getHierarchicalName() );
     649           0 :     aBuffer.append( '/' );
     650           0 :     aBuffer.append( i_rRelativeName );
     651           0 :     return aBuffer.makeStringAndClear();
     652             : }
     653             : 
     654           0 : ::rtl::Reference<OContentHelper> ODocumentContainer::getContent(const OUString& _sName) const
     655             : {
     656           0 :     ::rtl::Reference<OContentHelper> pContent = NULL;
     657             :     try
     658             :     {
     659           0 :         Reference<XUnoTunnel> xUnoTunnel(const_cast<ODocumentContainer*>(this)->implGetByName( _sName, true ), UNO_QUERY );
     660           0 :         if ( xUnoTunnel.is() )
     661           0 :             pContent = reinterpret_cast<OContentHelper*>(xUnoTunnel->getSomething(OContentHelper::getUnoTunnelImplementationId()));
     662             :     }
     663           0 :     catch(const Exception&)
     664             :     {
     665             :     }
     666           0 :     return pContent;
     667             : }
     668             : 
     669           0 : void ODocumentContainer::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
     670             : {
     671           0 :     _rDefault.clear();
     672           0 : }
     673             : 
     674           0 : void SAL_CALL ODocumentContainer::commit(  ) throw (::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     675             : {
     676           0 :     MutexGuard aGuard(m_aMutex);
     677           0 :     Documents::iterator aIter = m_aDocumentMap.begin();
     678           0 :     Documents::iterator aEnd = m_aDocumentMap.end();
     679           0 :     for (; aIter != aEnd ; ++aIter)
     680             :     {
     681           0 :         Reference<XTransactedObject> xTrans(aIter->second.get(),UNO_QUERY);
     682           0 :         if ( xTrans.is() )
     683           0 :             xTrans->commit();
     684           0 :     }
     685           0 :     Reference<XTransactedObject> xTrans(getContainerStorage(),UNO_QUERY);
     686           0 :     if ( xTrans.is() )
     687           0 :         xTrans->commit();
     688           0 : }
     689             : 
     690           0 : void SAL_CALL ODocumentContainer::revert(  ) throw (::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception)
     691             : {
     692           0 :     MutexGuard aGuard(m_aMutex);
     693           0 :     Documents::iterator aIter = m_aDocumentMap.begin();
     694           0 :     Documents::iterator aEnd = m_aDocumentMap.end();
     695           0 :     for (; aIter != aEnd ; ++aIter)
     696             :     {
     697           0 :         Reference<XTransactedObject> xTrans(aIter->second.get(),UNO_QUERY);
     698           0 :         if ( xTrans.is() )
     699           0 :             xTrans->revert();
     700           0 :     }
     701           0 :     Reference<XTransactedObject> xTrans(getContainerStorage(),UNO_QUERY);
     702           0 :     if ( xTrans.is() )
     703           0 :         xTrans->revert();
     704           0 : }
     705             : 
     706           0 : Reference< XStorage> ODocumentContainer::getContainerStorage() const
     707             : {
     708           0 :     return  m_pImpl->m_pDataSource
     709           0 :         ?   m_pImpl->m_pDataSource->getStorage( m_bFormsContainer ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT )
     710           0 :         :   Reference< XStorage>();
     711             : }
     712             : 
     713           0 : void SAL_CALL ODocumentContainer::removeByName( const OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
     714             : {
     715           0 :     ResettableMutexGuard aGuard(m_aMutex);
     716             : 
     717             :     // check the arguments
     718           0 :     if (_rName.isEmpty())
     719           0 :         throw IllegalArgumentException();
     720             : 
     721           0 :     if (!checkExistence(_rName))
     722           0 :         throw NoSuchElementException(_rName,*this);
     723             : 
     724           0 :     Reference< XCommandProcessor > xContent( implGetByName( _rName, true ), UNO_QUERY );
     725           0 :     if ( xContent.is() )
     726             :     {
     727           0 :         Command aCommand;
     728             : 
     729           0 :         aCommand.Name = "delete";
     730           0 :         xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
     731             :     }
     732             : 
     733             :     // do the removal
     734           0 :     implRemove(_rName);
     735             : 
     736           0 :     notifyByName( aGuard, _rName, NULL, NULL, E_REMOVED, ContainerListemers );
     737           0 : }
     738             : 
     739           0 : void SAL_CALL ODocumentContainer::rename( const OUString& newName ) throw (SQLException, ElementExistException, RuntimeException, std::exception)
     740             : {
     741             :     try
     742             :     {
     743           0 :         osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
     744           0 :         if ( newName.equals( m_pImpl->m_aProps.aTitle ) )
     745           0 :             return;
     746             : 
     747           0 :         sal_Int32 nHandle = PROPERTY_ID_NAME;
     748           0 :         Any aOld = makeAny(m_pImpl->m_aProps.aTitle);
     749           0 :         Any aNew = makeAny(newName);
     750             : 
     751           0 :         aGuard.clear();
     752           0 :         fire(&nHandle, &aNew, &aOld, 1, sal_True );
     753           0 :         m_pImpl->m_aProps.aTitle = newName;
     754           0 :         fire(&nHandle, &aNew, &aOld, 1, sal_False );
     755             :     }
     756           0 :     catch(const PropertyVetoException&)
     757             :     {
     758           0 :         throw ElementExistException(newName,*this);
     759             :     }
     760             : }
     761             : 
     762         168 : }   // namespace dbaccess
     763             : 
     764             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10