1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _DBA_COREDATAACCESS_DOCUMENTCONTAINER_HXX_
28cdf0e10cSrcweir #include "documentcontainer.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
31cdf0e10cSrcweir #include "dbastrings.hrc"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _DBA_COREDATAACCESS_DOCUMENTDEFINITION_HXX_
34cdf0e10cSrcweir #include "documentdefinition.hxx"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_
37cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
40cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
43cdf0e10cSrcweir #include <tools/debug.hxx>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_
46cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef DBA_UCPRESULTSET_HXX
49cdf0e10cSrcweir #include "myucp_resultset.hxx"
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef _UCBHELPER_CANCELCOMMANDEXECUTION_HXX_
52cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_UNSUPPORTEDOPENMODEEXCEPTION_HPP_
55cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_
58cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp>
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
61cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
62cdf0e10cSrcweir #endif
63cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_ERRORCONDITION_HPP_
64cdf0e10cSrcweir #include <com/sun/star/sdb/ErrorCondition.hpp>
65cdf0e10cSrcweir #endif
66cdf0e10cSrcweir #ifndef _DBA_COREDATAACCESS_DATASOURCE_HXX_
67cdf0e10cSrcweir #include "datasource.hxx"
68cdf0e10cSrcweir #endif
69cdf0e10cSrcweir #include <comphelper/classids.hxx>
70cdf0e10cSrcweir #ifndef _COMPHELPER_MIMECONFIGHELPER_HXX_
71cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx>
72cdf0e10cSrcweir #endif
73cdf0e10cSrcweir #ifndef INCLUDED_COMPHELPER_STRING_HXX
74cdf0e10cSrcweir #include <comphelper/string.hxx>
75cdf0e10cSrcweir #endif
76cdf0e10cSrcweir #ifndef CONNECTIVITY_SQLERROR_HXX
77cdf0e10cSrcweir #include <connectivity/sqlerror.hxx>
78cdf0e10cSrcweir #endif
79cdf0e10cSrcweir #include "core_resource.hxx"
80cdf0e10cSrcweir #include "core_resource.hrc"
81cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
82cdf0e10cSrcweir 
83cdf0e10cSrcweir #include <vcl/svapp.hxx>
84cdf0e10cSrcweir #include <vos/mutex.hxx>
85cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
86cdf0e10cSrcweir 
87cdf0e10cSrcweir using namespace ::com::sun::star::uno;
88cdf0e10cSrcweir using namespace ::com::sun::star::lang;
89cdf0e10cSrcweir using namespace ::com::sun::star::embed;
90cdf0e10cSrcweir using namespace ::com::sun::star::beans;
91cdf0e10cSrcweir using namespace ::com::sun::star::container;
92cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
93cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
94cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
95cdf0e10cSrcweir using namespace ::com::sun::star::io;
96cdf0e10cSrcweir using namespace ::osl;
97cdf0e10cSrcweir using namespace ::comphelper;
98cdf0e10cSrcweir using namespace ::cppu;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir //........................................................................
101cdf0e10cSrcweir namespace dbaccess
102cdf0e10cSrcweir {
103cdf0e10cSrcweir //........................................................................
104cdf0e10cSrcweir 
105cdf0e10cSrcweir //==========================================================================
106cdf0e10cSrcweir //= LocalNameApproval
107cdf0e10cSrcweir //==========================================================================
108cdf0e10cSrcweir class LocalNameApproval : public IContainerApprove
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     ::connectivity::SQLError    m_aErrors;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir public:
LocalNameApproval(const Reference<XMultiServiceFactory> & _rxFactory)113cdf0e10cSrcweir     LocalNameApproval( const Reference< XMultiServiceFactory >& _rxFactory )
114cdf0e10cSrcweir         :m_aErrors( ::comphelper::ComponentContext( _rxFactory ) )
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir     }
~LocalNameApproval()117cdf0e10cSrcweir     virtual ~LocalNameApproval()
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     void SAL_CALL   approveElement( const ::rtl::OUString& _rName, const Reference< XInterface >& _rxElement );
122cdf0e10cSrcweir };
123cdf0e10cSrcweir 
124cdf0e10cSrcweir //--------------------------------------------------------------------------
approveElement(const::rtl::OUString & _rName,const Reference<XInterface> &)125cdf0e10cSrcweir void SAL_CALL LocalNameApproval::approveElement( const ::rtl::OUString& _rName, const Reference< XInterface >& /*_rxElement*/ )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     if ( _rName.indexOf( '/' ) != -1 )
128cdf0e10cSrcweir         throw IllegalArgumentException(
129cdf0e10cSrcweir             m_aErrors.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES ),
130cdf0e10cSrcweir             NULL,
131cdf0e10cSrcweir             0
132cdf0e10cSrcweir         );
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir //==========================================================================
136cdf0e10cSrcweir //= ODocumentContainer
137cdf0e10cSrcweir //==========================================================================
DBG_NAME(ODocumentContainer)138cdf0e10cSrcweir DBG_NAME(ODocumentContainer)
139cdf0e10cSrcweir //--------------------------------------------------------------------------
140cdf0e10cSrcweir ODocumentContainer::ODocumentContainer(const Reference< XMultiServiceFactory >& _xORB
141cdf0e10cSrcweir 									,const Reference< XInterface >&	_xParentContainer
142cdf0e10cSrcweir 									,const TContentPtr& _pImpl
143cdf0e10cSrcweir 									, sal_Bool _bFormsContainer
144cdf0e10cSrcweir 									)
145cdf0e10cSrcweir 	:ODefinitionContainer(_xORB,_xParentContainer,_pImpl)
146cdf0e10cSrcweir     ,OPropertyStateContainer(OContentHelper::rBHelper)
147cdf0e10cSrcweir 	,m_bFormsContainer(_bFormsContainer)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	DBG_CTOR(ODocumentContainer, NULL);
150cdf0e10cSrcweir 	registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY | PropertyAttribute::CONSTRAINED,
151cdf0e10cSrcweir 					&m_pImpl->m_aProps.aTitle, ::getCppuType(&m_pImpl->m_aProps.aTitle));
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     setElementApproval( PContainerApprove( new LocalNameApproval ( _xORB ) ) );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir //--------------------------------------------------------------------------
~ODocumentContainer()157cdf0e10cSrcweir ODocumentContainer::~ODocumentContainer()
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	DBG_DTOR(ODocumentContainer, NULL);
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
162cdf0e10cSrcweir 	{
163cdf0e10cSrcweir 		acquire();
164cdf0e10cSrcweir 		dispose();
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir }
167cdf0e10cSrcweir // -----------------------------------------------------------------------------
168cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE3( ODocumentContainer,ODefinitionContainer,ODocumentContainer_Base,OPropertyStateContainer)
169cdf0e10cSrcweir IMPLEMENT_TYPEPROVIDER3(ODocumentContainer,ODefinitionContainer,OPropertyStateContainer,ODocumentContainer_Base);
170cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO_IMPLNAME(ODocumentContainer, "com.sun.star.comp.dba.ODocumentContainer");
171cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO_SUPPORTS(ODocumentContainer);
IMPLEMENT_PROPERTYCONTAINER_DEFAULTS(ODocumentContainer)172cdf0e10cSrcweir IMPLEMENT_PROPERTYCONTAINER_DEFAULTS(ODocumentContainer)
173cdf0e10cSrcweir 
174cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ODocumentContainer::getSupportedServiceNames(  ) throw(RuntimeException)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aSupported(1);
177cdf0e10cSrcweir 	aSupported[0] = m_bFormsContainer ? SERVICE_NAME_FORM_COLLECTION : SERVICE_NAME_REPORT_COLLECTION;
178cdf0e10cSrcweir 	return aSupported;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir // -----------------------------------------------------------------------------
determineContentType() const182cdf0e10cSrcweir ::rtl::OUString ODocumentContainer::determineContentType() const
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     return ::rtl::OUString();
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir //--------------------------------------------------------------------------
createObject(const::rtl::OUString & _rName)188cdf0e10cSrcweir Reference< XContent > ODocumentContainer::createObject( const ::rtl::OUString& _rName)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir 	const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
191cdf0e10cSrcweir 	ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( _rName );
192cdf0e10cSrcweir     OSL_ENSURE( aFind != rDefinitions.end(), "ODocumentContainer::createObject:Invalid entry in map!" );
193cdf0e10cSrcweir 	if ( aFind->second->m_aProps.bIsFolder )
194cdf0e10cSrcweir 		return new ODocumentContainer( m_aContext.getLegacyServiceFactory(), *this, aFind->second, m_bFormsContainer );
195cdf0e10cSrcweir 	return new ODocumentDefinition( *this, m_aContext.getLegacyServiceFactory(), aFind->second, m_bFormsContainer );
196cdf0e10cSrcweir }
197cdf0e10cSrcweir // -----------------------------------------------------------------------------
createInstance(const::rtl::OUString & aServiceSpecifier)198cdf0e10cSrcweir Reference< XInterface > SAL_CALL ODocumentContainer::createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (Exception, RuntimeException)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	return createInstanceWithArguments( aServiceSpecifier, Sequence< Any >() );
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir namespace
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     template< class TYPE >
lcl_extractAndRemove(::comphelper::NamedValueCollection & io_rArguments,const::rtl::OUString & i_rName,TYPE & o_rValue)206cdf0e10cSrcweir     void lcl_extractAndRemove( ::comphelper::NamedValueCollection& io_rArguments, const ::rtl::OUString& i_rName, TYPE& o_rValue )
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         if ( io_rArguments.has( i_rName ) )
209cdf0e10cSrcweir         {
210cdf0e10cSrcweir             io_rArguments.get_ensureType( i_rName, o_rValue );
211cdf0e10cSrcweir             io_rArguments.remove( i_rName );
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir // -----------------------------------------------------------------------------
createInstanceWithArguments(const::rtl::OUString & ServiceSpecifier,const Sequence<Any> & _aArguments)217cdf0e10cSrcweir Reference< XInterface > SAL_CALL ODocumentContainer::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& _aArguments ) throw (Exception, RuntimeException)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir 	Reference< XInterface > xRet;
220cdf0e10cSrcweir 	Reference< XContent > xContent;
221cdf0e10cSrcweir 	if ( ServiceSpecifier == SERVICE_SDB_DOCUMENTDEFINITION )
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		MutexGuard aGuard(m_aMutex);
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         // extrat known arguments
226cdf0e10cSrcweir         ::rtl::OUString sName, sPersistentName, sURL, sMediaType, sDocServiceName;
227cdf0e10cSrcweir 		Reference< XCommandProcessor > xCopyFrom;
228cdf0e10cSrcweir 		Reference< XConnection > xConnection;
229cdf0e10cSrcweir         sal_Bool bAsTemplate( sal_False );
230cdf0e10cSrcweir 		Sequence< sal_Int8 > aClassID;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         ::comphelper::NamedValueCollection aArgs( _aArguments );
233cdf0e10cSrcweir         lcl_extractAndRemove( aArgs, PROPERTY_NAME, sName );
234cdf0e10cSrcweir         lcl_extractAndRemove( aArgs, PROPERTY_PERSISTENT_NAME, sPersistentName );
235cdf0e10cSrcweir         lcl_extractAndRemove( aArgs, PROPERTY_URL, sURL );
236cdf0e10cSrcweir         lcl_extractAndRemove( aArgs, PROPERTY_EMBEDDEDOBJECT, xCopyFrom );
237cdf0e10cSrcweir         lcl_extractAndRemove( aArgs, PROPERTY_ACTIVE_CONNECTION, xConnection );
238cdf0e10cSrcweir         lcl_extractAndRemove( aArgs, PROPERTY_AS_TEMPLATE, bAsTemplate );
239cdf0e10cSrcweir         lcl_extractAndRemove( aArgs, INFO_MEDIATYPE, sMediaType );
240cdf0e10cSrcweir         lcl_extractAndRemove( aArgs, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentServiceName" ) ), sDocServiceName );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         // ClassID has two allowed types, so a special treatment here
243cdf0e10cSrcweir         Any aClassIDArg = aArgs.get( "ClassID" );
244cdf0e10cSrcweir         if ( aClassIDArg.hasValue() )
245cdf0e10cSrcweir         {
246cdf0e10cSrcweir             if ( !( aClassIDArg >>= aClassID ) )
247cdf0e10cSrcweir             {
248cdf0e10cSrcweir                 // Extended for usage also with a string
249cdf0e10cSrcweir                 ::rtl::OUString sClassIDString;
250cdf0e10cSrcweir                 if ( !( aClassIDArg >>= sClassIDString ) )
251cdf0e10cSrcweir                     throw IllegalArgumentException( ::rtl::OUString(), *this, 2 );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir                 aClassID = ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation( sClassIDString );
254cdf0e10cSrcweir 			}
255cdf0e10cSrcweir 
256cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
257cdf0e10cSrcweir             ::rtl::OUString sClassIDString = ::comphelper::MimeConfigurationHelper::GetStringClassIDRepresentation( aClassID );
258cdf0e10cSrcweir             (void)sClassIDString;
259cdf0e10cSrcweir #endif
260cdf0e10cSrcweir             aArgs.remove( "ClassID" );
261cdf0e10cSrcweir         }
262cdf0e10cSrcweir         // Everything which now is still present in the arguments is passed to the embedded object
263cdf0e10cSrcweir         const Sequence< PropertyValue > aCreationArgs( aArgs.getPropertyValues() );
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
266cdf0e10cSrcweir 		sal_Bool bNew = ( 0 == sPersistentName.getLength() );
267cdf0e10cSrcweir 		if ( bNew )
268cdf0e10cSrcweir 		{
269cdf0e10cSrcweir 			const static ::rtl::OUString sBaseName(RTL_CONSTASCII_USTRINGPARAM("Obj"));
270cdf0e10cSrcweir 			// -----------------------------------------------------------------------------
271cdf0e10cSrcweir 			sPersistentName = sBaseName;
272cdf0e10cSrcweir 			sPersistentName += ::rtl::OUString::valueOf(sal_Int32(rDefinitions.size() + 1));
273cdf0e10cSrcweir 			Reference<XNameAccess> xElements(getContainerStorage(),UNO_QUERY);
274cdf0e10cSrcweir 			if ( xElements.is() )
275cdf0e10cSrcweir 				sPersistentName = ::dbtools::createUniqueName(xElements,sPersistentName);
276cdf0e10cSrcweir 
277cdf0e10cSrcweir             const bool bNeedClassID = ( aClassID.getLength() == 0 ) && ( 0 == sURL.getLength() );
278cdf0e10cSrcweir             if ( xCopyFrom.is() )
279cdf0e10cSrcweir 			{
280cdf0e10cSrcweir 				Sequence<Any> aIni(2);
281cdf0e10cSrcweir 				aIni[0] <<= getContainerStorage();
282cdf0e10cSrcweir 				aIni[1] <<= sPersistentName;
283cdf0e10cSrcweir 				Command aCommand;
284cdf0e10cSrcweir 				aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("copyTo"));
285cdf0e10cSrcweir 				aCommand.Argument <<= aIni;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 				xCopyFrom->execute(aCommand,-1,Reference< XCommandEnvironment >());
288cdf0e10cSrcweir                 Reference<XPropertySet> xProp(xCopyFrom,UNO_QUERY);
289cdf0e10cSrcweir                 if ( xProp.is() && xProp->getPropertySetInfo().is() && xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_AS_TEMPLATE) )
290cdf0e10cSrcweir                     xProp->getPropertyValue(PROPERTY_AS_TEMPLATE) >>= bAsTemplate;
291cdf0e10cSrcweir 
292cdf0e10cSrcweir                 // if we do not have an own class ID, see if we can determine one from the copy we just created
293cdf0e10cSrcweir                 if ( bNeedClassID )
294cdf0e10cSrcweir                     ODocumentDefinition::GetDocumentServiceFromMediaType( getContainerStorage(), sPersistentName, m_aContext, aClassID );
295cdf0e10cSrcweir 			}
296cdf0e10cSrcweir             else
297cdf0e10cSrcweir             {
298cdf0e10cSrcweir                 if ( bNeedClassID )
299cdf0e10cSrcweir                 {
300cdf0e10cSrcweir                     if ( sMediaType.getLength() )
301cdf0e10cSrcweir                         ODocumentDefinition::GetDocumentServiceFromMediaType( sMediaType, m_aContext, aClassID );
302cdf0e10cSrcweir                     else if ( sDocServiceName.getLength() )
303cdf0e10cSrcweir                     {
304cdf0e10cSrcweir                         ::comphelper::MimeConfigurationHelper aConfigHelper( m_aContext.getLegacyServiceFactory() );
305cdf0e10cSrcweir                         const Sequence< NamedValue > aProps( aConfigHelper.GetObjectPropsByDocumentName( sDocServiceName ) );
306cdf0e10cSrcweir                         const ::comphelper::NamedValueCollection aMediaTypeProps( aProps );
307cdf0e10cSrcweir                         aClassID = aMediaTypeProps.getOrDefault( "ClassID", Sequence< sal_Int8 >() );
308cdf0e10cSrcweir                     }
309cdf0e10cSrcweir                 }
310cdf0e10cSrcweir             }
311cdf0e10cSrcweir 		}
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 		ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( sName );
314cdf0e10cSrcweir 		TContentPtr pElementImpl;
315cdf0e10cSrcweir 		if ( bNew || ( aFind == rDefinitions.end() ) )
316cdf0e10cSrcweir 		{
317cdf0e10cSrcweir 			pElementImpl.reset( new OContentHelper_Impl );
318cdf0e10cSrcweir 			if ( !bNew )
319cdf0e10cSrcweir 				pElementImpl->m_aProps.aTitle = sName;
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 			pElementImpl->m_aProps.sPersistentName = sPersistentName;
322cdf0e10cSrcweir 			pElementImpl->m_aProps.bAsTemplate = bAsTemplate;
323cdf0e10cSrcweir 			pElementImpl->m_pDataSource = m_pImpl->m_pDataSource;
324cdf0e10cSrcweir 		}
325cdf0e10cSrcweir 		else
326cdf0e10cSrcweir 			pElementImpl = aFind->second;
327cdf0e10cSrcweir 
328cdf0e10cSrcweir         ::rtl::Reference< ODocumentDefinition > pDocDef = new ODocumentDefinition( *this, m_aContext.getLegacyServiceFactory(), pElementImpl, m_bFormsContainer );
329cdf0e10cSrcweir         if ( aClassID.getLength() )
330cdf0e10cSrcweir         {
331cdf0e10cSrcweir             pDocDef->initialLoad( aClassID, aCreationArgs, xConnection );
332cdf0e10cSrcweir         }
333cdf0e10cSrcweir         else
334cdf0e10cSrcweir         {
335cdf0e10cSrcweir             OSL_ENSURE( aCreationArgs.getLength() == 0, "ODocumentContainer::createInstance: additional creation args are lost, if you do not provide a class ID." );
336cdf0e10cSrcweir         }
337cdf0e10cSrcweir         xContent = pDocDef.get();
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 		if ( sURL.getLength() )
340cdf0e10cSrcweir 		{
341cdf0e10cSrcweir 			Sequence<Any> aIni(2);
342cdf0e10cSrcweir 			aIni[0] <<= sURL;
343cdf0e10cSrcweir 			Command aCommand;
344cdf0e10cSrcweir 			aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("insert"));
345cdf0e10cSrcweir 			aCommand.Argument <<= aIni;
346cdf0e10cSrcweir 			Reference< XCommandProcessor > xCommandProcessor(xContent,UNO_QUERY);
347cdf0e10cSrcweir 			if ( xContent.is() )
348cdf0e10cSrcweir 			{
349cdf0e10cSrcweir 				xCommandProcessor->execute(aCommand,-1,Reference< XCommandEnvironment >());
350cdf0e10cSrcweir 			}
351cdf0e10cSrcweir 		}
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 		//	xRet = xContent;
354cdf0e10cSrcweir 	}
355cdf0e10cSrcweir 	else if ( ServiceSpecifier == SERVICE_NAME_FORM_COLLECTION || SERVICE_NAME_REPORT_COLLECTION == ServiceSpecifier )
356cdf0e10cSrcweir 	{
357cdf0e10cSrcweir 		const Any* pBegin = _aArguments.getConstArray();
358cdf0e10cSrcweir 		const Any* pEnd = pBegin + _aArguments.getLength();
359cdf0e10cSrcweir 		PropertyValue aValue;
360cdf0e10cSrcweir 		::rtl::OUString sName;
361cdf0e10cSrcweir 		Reference<XNameAccess> xCopyFrom;
362cdf0e10cSrcweir 		for(;pBegin != pEnd;++pBegin)
363cdf0e10cSrcweir 		{
364cdf0e10cSrcweir 			*pBegin >>= aValue;
365cdf0e10cSrcweir 			if ( aValue.Name.equalsAscii(PROPERTY_NAME) )
366cdf0e10cSrcweir 			{
367cdf0e10cSrcweir 				aValue.Value >>= sName;
368cdf0e10cSrcweir 			}
369cdf0e10cSrcweir 			else if ( aValue.Name.equalsAscii(PROPERTY_EMBEDDEDOBJECT) )
370cdf0e10cSrcweir 			{
371cdf0e10cSrcweir 				xCopyFrom.set(aValue.Value,UNO_QUERY);
372cdf0e10cSrcweir 			}
373cdf0e10cSrcweir 		}
374cdf0e10cSrcweir 		OSL_ENSURE(sName.getLength(),"Invalid name for a document container!");
375cdf0e10cSrcweir 	    const ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
376cdf0e10cSrcweir 		ODefinitionContainer_Impl::const_iterator aFind = rDefinitions.find( sName );
377cdf0e10cSrcweir 		TContentPtr pElementImpl;
378cdf0e10cSrcweir 		if ( aFind == rDefinitions.end() )
379cdf0e10cSrcweir 		{
380cdf0e10cSrcweir 			pElementImpl.reset(new ODefinitionContainer_Impl);
381cdf0e10cSrcweir 			pElementImpl->m_aProps.aTitle = sName;
382cdf0e10cSrcweir 			pElementImpl->m_pDataSource = m_pImpl->m_pDataSource;
383cdf0e10cSrcweir 		}
384cdf0e10cSrcweir 		else
385cdf0e10cSrcweir 			pElementImpl = aFind->second;
386cdf0e10cSrcweir 		OSL_ENSURE( pElementImpl ," Invalid entry in map!");
387cdf0e10cSrcweir 		xContent = new ODocumentContainer( m_aContext.getLegacyServiceFactory(), *this, pElementImpl, ServiceSpecifier == SERVICE_NAME_FORM_COLLECTION );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 		// copy children
390cdf0e10cSrcweir 		if ( xCopyFrom.is() )
391cdf0e10cSrcweir 		{
392cdf0e10cSrcweir 			Sequence< ::rtl::OUString> aSeq = xCopyFrom->getElementNames();
393cdf0e10cSrcweir 			const ::rtl::OUString* elements = aSeq.getConstArray();
394cdf0e10cSrcweir 			const ::rtl::OUString* elementsEnd = elements + aSeq.getLength();
395cdf0e10cSrcweir 			Reference<XContent> xObjectToCopy;
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 			Reference<XMultiServiceFactory> xORB(xContent,UNO_QUERY);
398cdf0e10cSrcweir 			OSL_ENSURE(xORB.is(),"No service factory given");
399cdf0e10cSrcweir 			if ( xORB.is() )
400cdf0e10cSrcweir 			{
401cdf0e10cSrcweir 				for(;elements != elementsEnd;++elements)
402cdf0e10cSrcweir 				{
403cdf0e10cSrcweir 					xCopyFrom->getByName(*elements) >>= xObjectToCopy;
404cdf0e10cSrcweir 					Sequence< Any > aArguments(3);
405cdf0e10cSrcweir 					PropertyValue aArgument;
406cdf0e10cSrcweir 					// set as folder
407cdf0e10cSrcweir 					aArgument.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
408cdf0e10cSrcweir 					aArgument.Value <<= *elements;
409cdf0e10cSrcweir 					aArguments[0] <<= aArgument;
410cdf0e10cSrcweir 					//parent
411cdf0e10cSrcweir 					aArgument.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
412cdf0e10cSrcweir 					aArgument.Value <<= xContent;
413cdf0e10cSrcweir 					aArguments[1] <<= aArgument;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 					aArgument.Name = PROPERTY_EMBEDDEDOBJECT;
416cdf0e10cSrcweir 					aArgument.Value <<= xObjectToCopy;
417cdf0e10cSrcweir 					aArguments[2] <<= aArgument;
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 					::rtl::OUString sServiceName;
420cdf0e10cSrcweir                     if ( Reference< XNameAccess >( xObjectToCopy, UNO_QUERY ).is() )
421cdf0e10cSrcweir                     {
422cdf0e10cSrcweir                         if ( m_bFormsContainer )
423cdf0e10cSrcweir                             sServiceName = SERVICE_NAME_FORM_COLLECTION;
424cdf0e10cSrcweir                         else
425cdf0e10cSrcweir                             sServiceName = SERVICE_NAME_REPORT_COLLECTION;
426cdf0e10cSrcweir                     }
427cdf0e10cSrcweir                     else
428cdf0e10cSrcweir                         sServiceName = SERVICE_SDB_DOCUMENTDEFINITION;
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 					Reference<XContent > xNew(xORB->createInstanceWithArguments(sServiceName,aArguments),UNO_QUERY);
431cdf0e10cSrcweir 					Reference<XNameContainer> xNameContainer(xContent,UNO_QUERY);
432cdf0e10cSrcweir 					if ( xNameContainer.is() )
433cdf0e10cSrcweir 						xNameContainer->insertByName(*elements,makeAny(xNew));
434cdf0e10cSrcweir 				}
435cdf0e10cSrcweir 			}
436cdf0e10cSrcweir 		}
437cdf0e10cSrcweir 	}
438cdf0e10cSrcweir 	xRet = xContent;
439cdf0e10cSrcweir 	return xRet;
440cdf0e10cSrcweir }
441cdf0e10cSrcweir // -----------------------------------------------------------------------------
getAvailableServiceNames()442cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ODocumentContainer::getAvailableServiceNames(  ) throw (RuntimeException)
443cdf0e10cSrcweir {
444cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aSe(3);
445cdf0e10cSrcweir 	aSe[0] = SERVICE_SDB_DOCUMENTDEFINITION;
446cdf0e10cSrcweir 	aSe[1] = SERVICE_NAME_FORM_COLLECTION;
447cdf0e10cSrcweir 	aSe[2] = SERVICE_NAME_REPORT_COLLECTION;
448cdf0e10cSrcweir 	return aSe;
449cdf0e10cSrcweir }
450cdf0e10cSrcweir // -----------------------------------------------------------------------------
execute(const Command & aCommand,sal_Int32 CommandId,const Reference<XCommandEnvironment> & Environment)451cdf0e10cSrcweir Any SAL_CALL ODocumentContainer::execute( const Command& aCommand, sal_Int32 CommandId, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException)
452cdf0e10cSrcweir {
453cdf0e10cSrcweir 	Any aRet;
454cdf0e10cSrcweir 	if ( aCommand.Name.compareToAscii( "open" ) == 0 )
455cdf0e10cSrcweir 	{
456cdf0e10cSrcweir 		//////////////////////////////////////////////////////////////////
457cdf0e10cSrcweir 		// open command for a folder content
458cdf0e10cSrcweir 		//////////////////////////////////////////////////////////////////
459cdf0e10cSrcweir 		OpenCommandArgument2 aOpenCommand;
460cdf0e10cSrcweir       	if ( !( aCommand.Argument >>= aOpenCommand ) )
461cdf0e10cSrcweir 		{
462cdf0e10cSrcweir             OSL_ENSURE( sal_False, "Wrong argument type!" );
463cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
464cdf0e10cSrcweir                 makeAny( IllegalArgumentException(
465cdf0e10cSrcweir                                     rtl::OUString(),
466cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
467cdf0e10cSrcweir                                     -1 ) ),
468cdf0e10cSrcweir                 Environment );
469cdf0e10cSrcweir             // Unreachable
470cdf0e10cSrcweir         }
471cdf0e10cSrcweir 		sal_Bool bOpenFolder =
472cdf0e10cSrcweir             ( ( aOpenCommand.Mode == OpenMode::ALL ) ||
473cdf0e10cSrcweir               ( aOpenCommand.Mode == OpenMode::FOLDERS ) ||
474cdf0e10cSrcweir               ( aOpenCommand.Mode == OpenMode::DOCUMENTS ) );
475cdf0e10cSrcweir 
476cdf0e10cSrcweir         if ( bOpenFolder )
477cdf0e10cSrcweir 		{
478cdf0e10cSrcweir             // open as folder - return result set
479cdf0e10cSrcweir 
480cdf0e10cSrcweir             Reference< XDynamicResultSet > xSet
481cdf0e10cSrcweir                             = new DynamicResultSet( m_aContext.getLegacyServiceFactory(),
482cdf0e10cSrcweir 													this,
483cdf0e10cSrcweir 													aOpenCommand,
484cdf0e10cSrcweir 													Environment );
485cdf0e10cSrcweir     		aRet <<= xSet;
486cdf0e10cSrcweir   		}
487cdf0e10cSrcweir 		else
488cdf0e10cSrcweir         {
489cdf0e10cSrcweir             // Unsupported.
490cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
491cdf0e10cSrcweir                 makeAny( UnsupportedOpenModeException(
492cdf0e10cSrcweir                                 rtl::OUString(),
493cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ),
494cdf0e10cSrcweir                                 sal_Int16( aOpenCommand.Mode ) ) ),
495cdf0e10cSrcweir                 Environment );
496cdf0e10cSrcweir                 // Unreachable
497cdf0e10cSrcweir 		}
498cdf0e10cSrcweir 	}
499cdf0e10cSrcweir 	else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "insert" ) ) )
500cdf0e10cSrcweir     {
501cdf0e10cSrcweir 		//////////////////////////////////////////////////////////////////
502cdf0e10cSrcweir 		// insert
503cdf0e10cSrcweir 		//////////////////////////////////////////////////////////////////
504cdf0e10cSrcweir 
505cdf0e10cSrcweir         InsertCommandArgument arg;
506cdf0e10cSrcweir       	if ( !( aCommand.Argument >>= arg ) )
507cdf0e10cSrcweir 		{
508cdf0e10cSrcweir 	  		OSL_ENSURE( sal_False, "Wrong argument type!" );
509cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
510cdf0e10cSrcweir                 makeAny( IllegalArgumentException(
511cdf0e10cSrcweir                                     rtl::OUString(),
512cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
513cdf0e10cSrcweir                                     -1 ) ),
514cdf0e10cSrcweir                 Environment );
515cdf0e10cSrcweir             // Unreachable
516cdf0e10cSrcweir 		}
517cdf0e10cSrcweir     }
518cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "delete" ) ) )
519cdf0e10cSrcweir     {
520cdf0e10cSrcweir 		//////////////////////////////////////////////////////////////////
521cdf0e10cSrcweir 		// delete
522cdf0e10cSrcweir 		//////////////////////////////////////////////////////////////////
523cdf0e10cSrcweir 		Sequence< ::rtl::OUString> aSeq = getElementNames();
524cdf0e10cSrcweir         const ::rtl::OUString* pIter = aSeq.getConstArray();
525cdf0e10cSrcweir         const ::rtl::OUString* pEnd	  = pIter + aSeq.getLength();
526cdf0e10cSrcweir         for(;pIter != pEnd;++pIter)
527cdf0e10cSrcweir             removeByName(*pIter);
528cdf0e10cSrcweir 
529cdf0e10cSrcweir         dispose();
530cdf0e10cSrcweir 	}
531cdf0e10cSrcweir 	else
532cdf0e10cSrcweir 		aRet = OContentHelper::execute(aCommand,CommandId,Environment);
533cdf0e10cSrcweir 	return aRet;
534cdf0e10cSrcweir }
535cdf0e10cSrcweir // -----------------------------------------------------------------------------
536cdf0e10cSrcweir namespace
537cdf0e10cSrcweir {
lcl_queryContent(const::rtl::OUString & _sName,Reference<XNameContainer> & _xNameContainer,Any & _rRet,::rtl::OUString & _sSimpleName)538cdf0e10cSrcweir 	sal_Bool lcl_queryContent(const ::rtl::OUString& _sName,Reference< XNameContainer >& _xNameContainer,Any& _rRet,::rtl::OUString& _sSimpleName)
539cdf0e10cSrcweir 	{
540cdf0e10cSrcweir 		sal_Bool bRet = sal_False;
541cdf0e10cSrcweir 		sal_Int32 nIndex = 0;
542cdf0e10cSrcweir 		::rtl::OUString sName = _sName.getToken(0,'/',nIndex);
543cdf0e10cSrcweir 		bRet = _xNameContainer->hasByName(sName);
544cdf0e10cSrcweir 		if ( bRet )
545cdf0e10cSrcweir 		{
546cdf0e10cSrcweir 			_rRet = _xNameContainer->getByName(_sSimpleName = sName);
547cdf0e10cSrcweir 			while ( nIndex != -1 && bRet )
548cdf0e10cSrcweir 			{
549cdf0e10cSrcweir 				sName = _sName.getToken(0,'/',nIndex);
550cdf0e10cSrcweir 				_xNameContainer.set(_rRet,UNO_QUERY);
551cdf0e10cSrcweir                 bRet = _xNameContainer.is();
552cdf0e10cSrcweir 				if ( bRet )
553cdf0e10cSrcweir 				{
554cdf0e10cSrcweir 					bRet = _xNameContainer->hasByName(sName);
555cdf0e10cSrcweir 					_sSimpleName = sName;
556cdf0e10cSrcweir 					if ( bRet )
557cdf0e10cSrcweir 						_rRet = _xNameContainer->getByName(sName);
558cdf0e10cSrcweir 				}
559cdf0e10cSrcweir 			}
560cdf0e10cSrcweir 		}
561cdf0e10cSrcweir 		if ( nIndex == -1 )
562cdf0e10cSrcweir 			_sSimpleName = sName; // a content
563cdf0e10cSrcweir         else
564cdf0e10cSrcweir             _xNameContainer.clear(); // a sub folder doesn't exist
565cdf0e10cSrcweir 		return bRet;
566cdf0e10cSrcweir 	}
567cdf0e10cSrcweir }
568cdf0e10cSrcweir // -----------------------------------------------------------------------------
loadComponentFromURL(const::rtl::OUString & _sURL,const::rtl::OUString &,sal_Int32,const Sequence<PropertyValue> & Arguments)569cdf0e10cSrcweir Reference< XComponent > SAL_CALL ODocumentContainer::loadComponentFromURL( const ::rtl::OUString& _sURL
570cdf0e10cSrcweir 																	   , const ::rtl::OUString& /*TargetFrameName*/
571cdf0e10cSrcweir 																	   , sal_Int32 /*SearchFlags*/
572cdf0e10cSrcweir 																	   , const Sequence< PropertyValue >& Arguments ) throw (IOException, IllegalArgumentException, RuntimeException)
573cdf0e10cSrcweir {
574cdf0e10cSrcweir 	vos::OGuard aSolarGuard(Application::GetSolarMutex());
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
577cdf0e10cSrcweir 	Reference< XComponent > xComp;
578cdf0e10cSrcweir 	try
579cdf0e10cSrcweir 	{
580cdf0e10cSrcweir 		Any aContent;
581cdf0e10cSrcweir 		Reference< XNameContainer > xNameContainer(this);
582cdf0e10cSrcweir 		::rtl::OUString sName;
583cdf0e10cSrcweir 		if ( !lcl_queryContent(_sURL,xNameContainer,aContent,sName) )
584cdf0e10cSrcweir         {
585cdf0e10cSrcweir             ::rtl::OUString sMessage( DBA_RES( RID_STR_NAME_NOT_FOUND ) );
586cdf0e10cSrcweir             ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$name$", _sURL );
587cdf0e10cSrcweir 			throw IllegalArgumentException( sMessage, *this, 1 );
588cdf0e10cSrcweir         }
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 		Reference< XCommandProcessor > xContent(aContent,UNO_QUERY);
591cdf0e10cSrcweir 		if ( xContent.is() )
592cdf0e10cSrcweir 		{
593cdf0e10cSrcweir 			Command aCommand;
594cdf0e10cSrcweir 
595cdf0e10cSrcweir             ::comphelper::NamedValueCollection aArgs( Arguments );
596cdf0e10cSrcweir             aCommand.Name = aArgs.getOrDefault( "OpenMode", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ) );
597cdf0e10cSrcweir             aArgs.remove( "OpenMode" );
598cdf0e10cSrcweir 
599cdf0e10cSrcweir             OpenCommandArgument2 aOpenCommand;
600cdf0e10cSrcweir 			aOpenCommand.Mode = OpenMode::DOCUMENT;
601cdf0e10cSrcweir             aArgs.put( "OpenCommandArgument", aOpenCommand );
602cdf0e10cSrcweir 
603cdf0e10cSrcweir             aCommand.Argument <<= aArgs.getPropertyValues();
604cdf0e10cSrcweir 			xComp.set(xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >()),UNO_QUERY);
605cdf0e10cSrcweir 		}
606cdf0e10cSrcweir     }
607cdf0e10cSrcweir 	catch(NoSuchElementException)
608cdf0e10cSrcweir 	{
609cdf0e10cSrcweir 		throw IllegalArgumentException();
610cdf0e10cSrcweir 	}
611cdf0e10cSrcweir 	catch(WrappedTargetException e)
612cdf0e10cSrcweir 	{
613cdf0e10cSrcweir 		// throw IllegalArgumentException();
614cdf0e10cSrcweir 		throw;
615cdf0e10cSrcweir 	}
616cdf0e10cSrcweir 	return xComp;
617cdf0e10cSrcweir }
618cdf0e10cSrcweir // -----------------------------------------------------------------------------
getByHierarchicalName(const::rtl::OUString & _sName)619cdf0e10cSrcweir Any SAL_CALL ODocumentContainer::getByHierarchicalName( const ::rtl::OUString& _sName ) throw (NoSuchElementException, RuntimeException)
620cdf0e10cSrcweir {
621cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
622cdf0e10cSrcweir 	Any aContent;
623cdf0e10cSrcweir 	Reference< XNameContainer > xNameContainer(this);
624cdf0e10cSrcweir 	::rtl::OUString sName;
625cdf0e10cSrcweir 	if ( lcl_queryContent(_sName,xNameContainer,aContent,sName) )
626cdf0e10cSrcweir 		return aContent;
627cdf0e10cSrcweir 	throw NoSuchElementException(_sName,*this);
628cdf0e10cSrcweir }
629cdf0e10cSrcweir // -----------------------------------------------------------------------------
hasByHierarchicalName(const::rtl::OUString & _sName)630cdf0e10cSrcweir sal_Bool SAL_CALL ODocumentContainer::hasByHierarchicalName( const ::rtl::OUString& _sName ) throw (RuntimeException)
631cdf0e10cSrcweir {
632cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
633cdf0e10cSrcweir 	Any aContent;
634cdf0e10cSrcweir 	Reference< XNameContainer > xNameContainer(this);
635cdf0e10cSrcweir 	::rtl::OUString sName;
636cdf0e10cSrcweir 	return lcl_queryContent(_sName,xNameContainer,aContent,sName);
637cdf0e10cSrcweir }
638cdf0e10cSrcweir // -----------------------------------------------------------------------------
639cdf0e10cSrcweir // XHierarchicalNameContainer
insertByHierarchicalName(const::rtl::OUString & _sName,const Any & _aElement)640cdf0e10cSrcweir void SAL_CALL ODocumentContainer::insertByHierarchicalName( const ::rtl::OUString& _sName, const Any& _aElement ) throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
641cdf0e10cSrcweir {
642cdf0e10cSrcweir     Reference< XContent > xContent(_aElement,UNO_QUERY);
643cdf0e10cSrcweir     if ( !xContent.is() )
644cdf0e10cSrcweir         throw IllegalArgumentException();
645cdf0e10cSrcweir 
646cdf0e10cSrcweir 	ClearableMutexGuard aGuard(m_aMutex);
647cdf0e10cSrcweir 	Any aContent;
648cdf0e10cSrcweir 	Reference< XNameContainer > xNameContainer(this);
649cdf0e10cSrcweir 	::rtl::OUString sName;
650cdf0e10cSrcweir 	if ( lcl_queryContent(_sName,xNameContainer,aContent,sName) )
651cdf0e10cSrcweir 		throw ElementExistException(_sName,*this);
652cdf0e10cSrcweir 
653cdf0e10cSrcweir     if ( !xNameContainer.is() )
654cdf0e10cSrcweir     {
655cdf0e10cSrcweir         ::rtl::OUString sMessage( DBA_RES( RID_STR_NO_SUB_FOLDER ) );
656cdf0e10cSrcweir         sal_Int32 index = sName.getLength();
657cdf0e10cSrcweir         ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$folder$", _sName.getToken(0,'/',index) );
658cdf0e10cSrcweir 		throw IllegalArgumentException( sMessage, *this, 1 );
659cdf0e10cSrcweir     }
660cdf0e10cSrcweir 
661cdf0e10cSrcweir 	xNameContainer->insertByName(sName,_aElement);
662cdf0e10cSrcweir }
663cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeByHierarchicalName(const::rtl::OUString & _sName)664cdf0e10cSrcweir void SAL_CALL ODocumentContainer::removeByHierarchicalName( const ::rtl::OUString& _sName ) throw (NoSuchElementException, WrappedTargetException, RuntimeException)
665cdf0e10cSrcweir {
666cdf0e10cSrcweir 	if ( !_sName.getLength() )
667cdf0e10cSrcweir 		throw NoSuchElementException(_sName,*this);
668cdf0e10cSrcweir 
669cdf0e10cSrcweir 	ClearableMutexGuard aGuard(m_aMutex);
670cdf0e10cSrcweir 	Any aContent;
671cdf0e10cSrcweir 	::rtl::OUString sName;
672cdf0e10cSrcweir 	Reference< XNameContainer > xNameContainer(this);
673cdf0e10cSrcweir 	if ( !lcl_queryContent(_sName,xNameContainer,aContent,sName) )
674cdf0e10cSrcweir 		throw NoSuchElementException(_sName,*this);
675cdf0e10cSrcweir 
676cdf0e10cSrcweir 	xNameContainer->removeByName(sName);
677cdf0e10cSrcweir }
678cdf0e10cSrcweir // -----------------------------------------------------------------------------
679cdf0e10cSrcweir // XHierarchicalNameReplace
replaceByHierarchicalName(const::rtl::OUString & _sName,const Any & _aElement)680cdf0e10cSrcweir void SAL_CALL ODocumentContainer::replaceByHierarchicalName( const ::rtl::OUString& _sName, const Any& _aElement ) throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
681cdf0e10cSrcweir {
682cdf0e10cSrcweir 	Reference< XContent > xContent(_aElement,UNO_QUERY);
683cdf0e10cSrcweir 	if ( !xContent.is() )
684cdf0e10cSrcweir 		throw IllegalArgumentException();
685cdf0e10cSrcweir 
686cdf0e10cSrcweir 	ClearableMutexGuard aGuard(m_aMutex);
687cdf0e10cSrcweir 	Any aContent;
688cdf0e10cSrcweir 	::rtl::OUString sName;
689cdf0e10cSrcweir 	Reference< XNameContainer > xNameContainer(this);
690cdf0e10cSrcweir 	if ( !lcl_queryContent(_sName,xNameContainer,aContent,sName) )
691cdf0e10cSrcweir 		throw NoSuchElementException(_sName,*this);
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 	xNameContainer->replaceByName(sName,_aElement);
694cdf0e10cSrcweir }
695cdf0e10cSrcweir 
696cdf0e10cSrcweir // -----------------------------------------------------------------------------
getHierarchicalName()697cdf0e10cSrcweir ::rtl::OUString SAL_CALL ODocumentContainer::getHierarchicalName() throw (RuntimeException)
698cdf0e10cSrcweir {
699cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
700cdf0e10cSrcweir     return impl_getHierarchicalName( false );
701cdf0e10cSrcweir }
702cdf0e10cSrcweir 
703cdf0e10cSrcweir // -----------------------------------------------------------------------------
composeHierarchicalName(const::rtl::OUString & i_rRelativeName)704cdf0e10cSrcweir ::rtl::OUString SAL_CALL ODocumentContainer::composeHierarchicalName( const ::rtl::OUString& i_rRelativeName ) throw (IllegalArgumentException, NoSupportException, RuntimeException)
705cdf0e10cSrcweir {
706cdf0e10cSrcweir     ::rtl::OUStringBuffer aBuffer;
707cdf0e10cSrcweir     aBuffer.append( getHierarchicalName() );
708cdf0e10cSrcweir     aBuffer.append( sal_Unicode( '/' ) );
709cdf0e10cSrcweir     aBuffer.append( i_rRelativeName );
710cdf0e10cSrcweir     return aBuffer.makeStringAndClear();
711cdf0e10cSrcweir }
712cdf0e10cSrcweir 
713cdf0e10cSrcweir // -----------------------------------------------------------------------------
getContent(const::rtl::OUString & _sName) const714cdf0e10cSrcweir ::rtl::Reference<OContentHelper> ODocumentContainer::getContent(const ::rtl::OUString& _sName) const
715cdf0e10cSrcweir {
716cdf0e10cSrcweir 	::rtl::Reference<OContentHelper> pContent = NULL;
717cdf0e10cSrcweir 	try
718cdf0e10cSrcweir 	{
719cdf0e10cSrcweir 		Reference<XUnoTunnel> xUnoTunnel(const_cast<ODocumentContainer*>(this)->implGetByName( _sName, sal_True ), UNO_QUERY );
720cdf0e10cSrcweir 		if ( xUnoTunnel.is() )
721cdf0e10cSrcweir 			pContent = reinterpret_cast<OContentHelper*>(xUnoTunnel->getSomething(OContentHelper::getUnoTunnelImplementationId()));
722cdf0e10cSrcweir 	}
723cdf0e10cSrcweir 	catch(Exception)
724cdf0e10cSrcweir 	{
725cdf0e10cSrcweir 	}
726cdf0e10cSrcweir 	return pContent;
727cdf0e10cSrcweir }
728cdf0e10cSrcweir // -----------------------------------------------------------------------------
getPropertyDefaultByHandle(sal_Int32,Any & _rDefault) const729cdf0e10cSrcweir void ODocumentContainer::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
730cdf0e10cSrcweir {
731cdf0e10cSrcweir 	_rDefault.clear();
732cdf0e10cSrcweir }
733cdf0e10cSrcweir // -----------------------------------------------------------------------------
commit()734cdf0e10cSrcweir void SAL_CALL ODocumentContainer::commit(  ) throw (::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
735cdf0e10cSrcweir {
736cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
737cdf0e10cSrcweir 	Documents::iterator aIter = m_aDocumentMap.begin();
738cdf0e10cSrcweir 	Documents::iterator aEnd = m_aDocumentMap.end();
739cdf0e10cSrcweir 	for (; aIter != aEnd ; ++aIter)
740cdf0e10cSrcweir 	{
741cdf0e10cSrcweir 		Reference<XTransactedObject> xTrans(aIter->second.get(),UNO_QUERY);
742cdf0e10cSrcweir 		if ( xTrans.is() )
743cdf0e10cSrcweir 			xTrans->commit();
744cdf0e10cSrcweir 	}
745cdf0e10cSrcweir 	Reference<XTransactedObject> xTrans(getContainerStorage(),UNO_QUERY);
746cdf0e10cSrcweir 	if ( xTrans.is() )
747cdf0e10cSrcweir 		xTrans->commit();
748cdf0e10cSrcweir }
749cdf0e10cSrcweir // -----------------------------------------------------------------------------
revert()750cdf0e10cSrcweir void SAL_CALL ODocumentContainer::revert(  ) throw (::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
751cdf0e10cSrcweir {
752cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
753cdf0e10cSrcweir 	Documents::iterator aIter = m_aDocumentMap.begin();
754cdf0e10cSrcweir 	Documents::iterator aEnd = m_aDocumentMap.end();
755cdf0e10cSrcweir 	for (; aIter != aEnd ; ++aIter)
756cdf0e10cSrcweir 	{
757cdf0e10cSrcweir 		Reference<XTransactedObject> xTrans(aIter->second.get(),UNO_QUERY);
758cdf0e10cSrcweir 		if ( xTrans.is() )
759cdf0e10cSrcweir 			xTrans->revert();
760cdf0e10cSrcweir 	}
761cdf0e10cSrcweir 	Reference<XTransactedObject> xTrans(getContainerStorage(),UNO_QUERY);
762cdf0e10cSrcweir 	if ( xTrans.is() )
763cdf0e10cSrcweir 		xTrans->revert();
764cdf0e10cSrcweir }
765cdf0e10cSrcweir // -----------------------------------------------------------------------------
getContainerStorage() const766cdf0e10cSrcweir Reference< XStorage> ODocumentContainer::getContainerStorage() const
767cdf0e10cSrcweir {
768cdf0e10cSrcweir 	return  m_pImpl->m_pDataSource
769cdf0e10cSrcweir         ?   m_pImpl->m_pDataSource->getStorage( m_bFormsContainer ? ODatabaseModelImpl::E_FORM : ODatabaseModelImpl::E_REPORT )
770cdf0e10cSrcweir         :   Reference< XStorage>();
771cdf0e10cSrcweir }
772cdf0e10cSrcweir 
773cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeByName(const::rtl::OUString & _rName)774cdf0e10cSrcweir void SAL_CALL ODocumentContainer::removeByName( const ::rtl::OUString& _rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
775cdf0e10cSrcweir {
776cdf0e10cSrcweir 	ResettableMutexGuard aGuard(m_aMutex);
777cdf0e10cSrcweir 
778cdf0e10cSrcweir 	// check the arguments
779cdf0e10cSrcweir 	if (!_rName.getLength())
780cdf0e10cSrcweir 		throw IllegalArgumentException();
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 	if (!checkExistence(_rName))
783cdf0e10cSrcweir 		throw NoSuchElementException(_rName,*this);
784cdf0e10cSrcweir 
785cdf0e10cSrcweir     Reference< XCommandProcessor > xContent( implGetByName( _rName, sal_True ), UNO_QUERY );
786cdf0e10cSrcweir 	if ( xContent.is() )
787cdf0e10cSrcweir 	{
788cdf0e10cSrcweir 		Command aCommand;
789cdf0e10cSrcweir 
790cdf0e10cSrcweir 		aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("delete"));
791cdf0e10cSrcweir 		xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
792cdf0e10cSrcweir 	}
793cdf0e10cSrcweir 
794cdf0e10cSrcweir     // do the removal
795cdf0e10cSrcweir 	implRemove(_rName);
796cdf0e10cSrcweir 
797cdf0e10cSrcweir 	//	disposeComponent(xContent); // no dispose here, the object may be inserted again under a different name
798cdf0e10cSrcweir 
799cdf0e10cSrcweir     notifyByName( aGuard, _rName, NULL, NULL, E_REMOVED, ContainerListemers );
800cdf0e10cSrcweir }
801cdf0e10cSrcweir // -----------------------------------------------------------------------------
802cdf0e10cSrcweir // -----------------------------------------------------------------------------
rename(const::rtl::OUString & newName)803cdf0e10cSrcweir void SAL_CALL ODocumentContainer::rename( const ::rtl::OUString& newName ) throw (SQLException, ElementExistException, RuntimeException)
804cdf0e10cSrcweir {
805cdf0e10cSrcweir 	try
806cdf0e10cSrcweir 	{
807cdf0e10cSrcweir 		osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
808cdf0e10cSrcweir         if ( newName.equals( m_pImpl->m_aProps.aTitle ) )
809cdf0e10cSrcweir             return;
810cdf0e10cSrcweir 
811cdf0e10cSrcweir         sal_Int32 nHandle = PROPERTY_ID_NAME;
812cdf0e10cSrcweir         Any aOld = makeAny(m_pImpl->m_aProps.aTitle);
813cdf0e10cSrcweir 		Any aNew = makeAny(newName);
814cdf0e10cSrcweir 
815cdf0e10cSrcweir 		aGuard.clear();
816cdf0e10cSrcweir 		fire(&nHandle, &aNew, &aOld, 1, sal_True );
817cdf0e10cSrcweir 		m_pImpl->m_aProps.aTitle = newName;
818cdf0e10cSrcweir 		fire(&nHandle, &aNew, &aOld, 1, sal_False );
819cdf0e10cSrcweir 	}
820cdf0e10cSrcweir 	catch(const PropertyVetoException&)
821cdf0e10cSrcweir 	{
822cdf0e10cSrcweir 		throw ElementExistException(newName,*this);
823cdf0e10cSrcweir 	}
824cdf0e10cSrcweir }
825cdf0e10cSrcweir 
826cdf0e10cSrcweir //........................................................................
827cdf0e10cSrcweir }	// namespace dbaccess
828cdf0e10cSrcweir //........................................................................
829cdf0e10cSrcweir 
830