xref: /trunk/main/ucb/source/ucp/file/bc.cxx (revision 88c764bff9c8901fbd5e0d89dee3bedcded6f1b3)
12f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52f86921cSAndrew Rist  * distributed with this work for additional information
62f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
92f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142f86921cSAndrew Rist  * software distributed under the License is distributed on an
152f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
172f86921cSAndrew Rist  * specific language governing permissions and limitations
182f86921cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202f86921cSAndrew Rist  *************************************************************/
212f86921cSAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23421ed02eSdamjan #include "precompiled_file.hxx"
24cdf0e10cSrcweir #include <rtl/uri.hxx>
25cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
26cdf0e10cSrcweir #include <osl/file.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "osl/diagnose.h"
29cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
30cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_
31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <com/sun/star/ucb/XProgressHandler.hpp>
34cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
35cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataStreamer.hpp>
36cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
38cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/PropertyChangeEvent.hpp>
40cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChange.hpp>
41cdf0e10cSrcweir #include <com/sun/star/ucb/ContentAction.hpp>
42cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
43cdf0e10cSrcweir #include "filglob.hxx"
44cdf0e10cSrcweir #include "filid.hxx"
45cdf0e10cSrcweir #include "filrow.hxx"
46cdf0e10cSrcweir #include "bc.hxx"
47cdf0e10cSrcweir #include "prov.hxx"
48cdf0e10cSrcweir #ifndef _FILERROR_HXX_
49cdf0e10cSrcweir #include "filerror.hxx"
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #include "filinsreq.hxx"
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir using namespace fileaccess;
55cdf0e10cSrcweir using namespace com::sun::star;
56cdf0e10cSrcweir using namespace com::sun::star::uno;
57cdf0e10cSrcweir using namespace com::sun::star::ucb;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // PropertyListeners
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir typedef cppu::OMultiTypeInterfaceContainerHelperVar< rtl::OUString,hashOUString,equalOUString >
63cdf0e10cSrcweir PropertyListeners_impl;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir class fileaccess::PropertyListeners
66cdf0e10cSrcweir     : public PropertyListeners_impl
67cdf0e10cSrcweir {
68cdf0e10cSrcweir public:
PropertyListeners(::osl::Mutex & aMutex)69cdf0e10cSrcweir     PropertyListeners( ::osl::Mutex& aMutex )
70cdf0e10cSrcweir         : PropertyListeners_impl( aMutex )
71cdf0e10cSrcweir     {
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir };
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir /****************************************************************************************/
77cdf0e10cSrcweir /*                    BaseContent                                                       */
78cdf0e10cSrcweir /****************************************************************************************/
79cdf0e10cSrcweir 
80cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
81cdf0e10cSrcweir // Private Constructor for just inserted Contents
82cdf0e10cSrcweir 
BaseContent(shell * pMyShell,const rtl::OUString & parentName,sal_Bool bFolder)83cdf0e10cSrcweir BaseContent::BaseContent( shell* pMyShell,
84cdf0e10cSrcweir                           const rtl::OUString& parentName,
85cdf0e10cSrcweir                           sal_Bool bFolder )
86cdf0e10cSrcweir     : m_pMyShell( pMyShell ),
87cdf0e10cSrcweir       m_xContentIdentifier( 0 ),
88cdf0e10cSrcweir       m_aUncPath( parentName ),
89cdf0e10cSrcweir       m_bFolder( bFolder ),
90cdf0e10cSrcweir       m_nState( JustInserted ),
91cdf0e10cSrcweir       m_pDisposeEventListeners( 0 ),
92cdf0e10cSrcweir       m_pContentEventListeners( 0 ),
93cdf0e10cSrcweir       m_pPropertySetInfoChangeListeners( 0 ),
94cdf0e10cSrcweir       m_pPropertyListener( 0 )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     m_pMyShell->m_pProvider->acquire();
97cdf0e10cSrcweir     // No registering, since we have no name
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
102cdf0e10cSrcweir // Constructor for full featured Contents
103cdf0e10cSrcweir 
BaseContent(shell * pMyShell,const Reference<XContentIdentifier> & xContentIdentifier,const rtl::OUString & aUncPath)104cdf0e10cSrcweir BaseContent::BaseContent( shell* pMyShell,
105cdf0e10cSrcweir                           const Reference< XContentIdentifier >& xContentIdentifier,
106cdf0e10cSrcweir                           const rtl::OUString& aUncPath )
107cdf0e10cSrcweir     : m_pMyShell( pMyShell ),
108cdf0e10cSrcweir       m_xContentIdentifier( xContentIdentifier ),
109cdf0e10cSrcweir       m_aUncPath( aUncPath ),
110cdf0e10cSrcweir       m_bFolder( false ),
111cdf0e10cSrcweir       m_nState( FullFeatured ),
112cdf0e10cSrcweir       m_pDisposeEventListeners( 0 ),
113cdf0e10cSrcweir       m_pContentEventListeners( 0 ),
114cdf0e10cSrcweir       m_pPropertySetInfoChangeListeners( 0 ),
115cdf0e10cSrcweir       m_pPropertyListener( 0 )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     m_pMyShell->m_pProvider->acquire();
118cdf0e10cSrcweir     m_pMyShell->registerNotifier( m_aUncPath,this );
119cdf0e10cSrcweir     m_pMyShell->insertDefaultProperties( m_aUncPath );
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
~BaseContent()123cdf0e10cSrcweir BaseContent::~BaseContent( )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     if( ( m_nState & FullFeatured ) || ( m_nState & Deleted ) )
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         m_pMyShell->deregisterNotifier( m_aUncPath,this );
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir     m_pMyShell->m_pProvider->release();
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     delete m_pDisposeEventListeners;
132cdf0e10cSrcweir     delete m_pContentEventListeners;
133cdf0e10cSrcweir     delete m_pPropertyListener;
134cdf0e10cSrcweir     delete m_pPropertySetInfoChangeListeners;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
138cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
139cdf0e10cSrcweir // XInterface
140cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
141cdf0e10cSrcweir 
142cdf0e10cSrcweir void SAL_CALL
acquire(void)143cdf0e10cSrcweir BaseContent::acquire( void )
144cdf0e10cSrcweir     throw()
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     OWeakObject::acquire();
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 
150cdf0e10cSrcweir void SAL_CALL
release(void)151cdf0e10cSrcweir BaseContent::release( void )
152cdf0e10cSrcweir     throw()
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     OWeakObject::release();
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
158cdf0e10cSrcweir Any SAL_CALL
queryInterface(const Type & rType)159cdf0e10cSrcweir BaseContent::queryInterface( const Type& rType )
160cdf0e10cSrcweir     throw( RuntimeException )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     Any aRet = cppu::queryInterface( rType,
163cdf0e10cSrcweir                                      SAL_STATIC_CAST( lang::XComponent*, this ),
164cdf0e10cSrcweir                                      SAL_STATIC_CAST( lang::XTypeProvider*, this ),
165cdf0e10cSrcweir                                      SAL_STATIC_CAST( lang::XServiceInfo*, this ),
166cdf0e10cSrcweir                                      SAL_STATIC_CAST( XCommandProcessor*, this ),
167cdf0e10cSrcweir                                      SAL_STATIC_CAST( container::XChild*, this ),
168cdf0e10cSrcweir                                      SAL_STATIC_CAST( beans::XPropertiesChangeNotifier*, this ),
169cdf0e10cSrcweir                                      SAL_STATIC_CAST( beans::XPropertyContainer*, this ),
170cdf0e10cSrcweir                                      SAL_STATIC_CAST( XContentCreator*,this ),
171cdf0e10cSrcweir                                      SAL_STATIC_CAST( beans::XPropertySetInfoChangeNotifier*, this ),
172cdf0e10cSrcweir                                      SAL_STATIC_CAST( XContent*,this) );
173cdf0e10cSrcweir     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
179cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
180cdf0e10cSrcweir // XComponent
181cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////
182cdf0e10cSrcweir 
183cdf0e10cSrcweir void SAL_CALL
addEventListener(const Reference<lang::XEventListener> & Listener)184cdf0e10cSrcweir BaseContent::addEventListener( const Reference< lang::XEventListener >& Listener )
185cdf0e10cSrcweir     throw( RuntimeException )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     if ( ! m_pDisposeEventListeners )
190cdf0e10cSrcweir         m_pDisposeEventListeners =
191cdf0e10cSrcweir             new cppu::OInterfaceContainerHelper( m_aEventListenerMutex );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     m_pDisposeEventListeners->addInterface( Listener );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 
197cdf0e10cSrcweir void SAL_CALL
removeEventListener(const Reference<lang::XEventListener> & Listener)198cdf0e10cSrcweir BaseContent::removeEventListener( const Reference< lang::XEventListener >& Listener )
199cdf0e10cSrcweir     throw( RuntimeException )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     if ( m_pDisposeEventListeners )
204cdf0e10cSrcweir         m_pDisposeEventListeners->removeInterface( Listener );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 
208cdf0e10cSrcweir void SAL_CALL
dispose()209cdf0e10cSrcweir BaseContent::dispose()
210cdf0e10cSrcweir     throw( RuntimeException )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     lang::EventObject aEvt;
213cdf0e10cSrcweir     cppu::OInterfaceContainerHelper* pDisposeEventListeners;
214cdf0e10cSrcweir     cppu::OInterfaceContainerHelper* pContentEventListeners;
215cdf0e10cSrcweir     cppu::OInterfaceContainerHelper* pPropertySetInfoChangeListeners;
216cdf0e10cSrcweir     PropertyListeners* pPropertyListener;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     {
219cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
220cdf0e10cSrcweir         aEvt.Source = static_cast< XContent* >( this );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         pDisposeEventListeners =
224cdf0e10cSrcweir             m_pDisposeEventListeners, m_pDisposeEventListeners = 0;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir         pContentEventListeners =
227cdf0e10cSrcweir             m_pContentEventListeners, m_pContentEventListeners = 0;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         pPropertySetInfoChangeListeners =
230cdf0e10cSrcweir             m_pPropertySetInfoChangeListeners,
231cdf0e10cSrcweir             m_pPropertySetInfoChangeListeners = 0;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         pPropertyListener =
234cdf0e10cSrcweir             m_pPropertyListener, m_pPropertyListener = 0;
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     if ( pDisposeEventListeners && pDisposeEventListeners->getLength() )
238cdf0e10cSrcweir         pDisposeEventListeners->disposeAndClear( aEvt );
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     if ( pContentEventListeners && pContentEventListeners->getLength() )
241cdf0e10cSrcweir         pContentEventListeners->disposeAndClear( aEvt );
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     if( pPropertyListener )
244cdf0e10cSrcweir         pPropertyListener->disposeAndClear( aEvt );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     if( pPropertySetInfoChangeListeners )
247cdf0e10cSrcweir         pPropertySetInfoChangeListeners->disposeAndClear( aEvt );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     delete pDisposeEventListeners;
250cdf0e10cSrcweir     delete pContentEventListeners;
251cdf0e10cSrcweir     delete pPropertyListener;
252cdf0e10cSrcweir     delete pPropertySetInfoChangeListeners;
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 
257cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
258cdf0e10cSrcweir // XServiceInfo
259cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
260cdf0e10cSrcweir 
261cdf0e10cSrcweir rtl::OUString SAL_CALL
getImplementationName()262cdf0e10cSrcweir BaseContent::getImplementationName()
263cdf0e10cSrcweir     throw( RuntimeException)
264cdf0e10cSrcweir {
265cdf0e10cSrcweir     return rtl::OUString::createFromAscii( "com.sun.star.comp.ucb.FileContent" );
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 
270cdf0e10cSrcweir sal_Bool SAL_CALL
supportsService(const rtl::OUString & ServiceName)271cdf0e10cSrcweir BaseContent::supportsService( const rtl::OUString& ServiceName )
272cdf0e10cSrcweir     throw( RuntimeException)
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     if( ServiceName.compareToAscii( "com.sun.star.ucb.FileContent" ) == 0 )
275cdf0e10cSrcweir         return true;
276cdf0e10cSrcweir     else
277cdf0e10cSrcweir         return false;
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 
282cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()283cdf0e10cSrcweir BaseContent::getSupportedServiceNames()
284cdf0e10cSrcweir     throw( RuntimeException )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir     Sequence< rtl::OUString > ret( 1 );
287cdf0e10cSrcweir     ret[0] = rtl::OUString::createFromAscii( "com.sun.star.ucb.FileContent" );
288cdf0e10cSrcweir     return ret;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 
293cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
294cdf0e10cSrcweir // XTypeProvider
295cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
296cdf0e10cSrcweir 
XTYPEPROVIDER_IMPL_10(BaseContent,lang::XComponent,lang::XTypeProvider,lang::XServiceInfo,XCommandProcessor,XContentCreator,XContent,container::XChild,beans::XPropertiesChangeNotifier,beans::XPropertyContainer,beans::XPropertySetInfoChangeNotifier)297cdf0e10cSrcweir XTYPEPROVIDER_IMPL_10( BaseContent,
298cdf0e10cSrcweir                        lang::XComponent,
299cdf0e10cSrcweir                        lang::XTypeProvider,
300cdf0e10cSrcweir                        lang::XServiceInfo,
301cdf0e10cSrcweir                        XCommandProcessor,
302cdf0e10cSrcweir                        XContentCreator,
303cdf0e10cSrcweir                        XContent,
304cdf0e10cSrcweir                        container::XChild,
305cdf0e10cSrcweir                        beans::XPropertiesChangeNotifier,
306cdf0e10cSrcweir                        beans::XPropertyContainer,
307cdf0e10cSrcweir                        beans::XPropertySetInfoChangeNotifier )
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 
310cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
311cdf0e10cSrcweir // XCommandProcessor
312cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
313cdf0e10cSrcweir 
314cdf0e10cSrcweir sal_Int32 SAL_CALL
315cdf0e10cSrcweir BaseContent::createCommandIdentifier( void )
316cdf0e10cSrcweir     throw( RuntimeException )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir     return m_pMyShell->getCommandId();
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 
322cdf0e10cSrcweir void SAL_CALL
abort(sal_Int32 CommandId)323cdf0e10cSrcweir BaseContent::abort( sal_Int32 CommandId )
324cdf0e10cSrcweir     throw( RuntimeException )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir     m_pMyShell->abort( CommandId );
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 
330cdf0e10cSrcweir Any SAL_CALL
execute(const Command & aCommand,sal_Int32 CommandId,const Reference<XCommandEnvironment> & Environment)331cdf0e10cSrcweir BaseContent::execute( const Command& aCommand,
332cdf0e10cSrcweir                       sal_Int32 CommandId,
333cdf0e10cSrcweir                       const Reference< XCommandEnvironment >& Environment )
334cdf0e10cSrcweir     throw( Exception,
335cdf0e10cSrcweir            CommandAbortedException,
336cdf0e10cSrcweir            RuntimeException )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir     if( ! CommandId )
339cdf0e10cSrcweir         // A Command with commandid zero cannot be aborted
340cdf0e10cSrcweir         CommandId = createCommandIdentifier();
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     m_pMyShell->startTask( CommandId,
343cdf0e10cSrcweir                            Environment );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     Any aAny;
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     if( ! aCommand.Name.compareToAscii( "getPropertySetInfo" ) ) // No exceptions
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         aAny <<= getPropertySetInfo( CommandId );
350cdf0e10cSrcweir     }
351cdf0e10cSrcweir     else if( ! aCommand.Name.compareToAscii( "getCommandInfo" ) ) // no exceptions
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         aAny <<= getCommandInfo();
354cdf0e10cSrcweir     }
355cdf0e10cSrcweir     else if( ! aCommand.Name.compareToAscii( "setPropertyValues" ) )
356cdf0e10cSrcweir     {
357cdf0e10cSrcweir         Sequence< beans::PropertyValue > sPropertyValues;
358cdf0e10cSrcweir 
359cdf0e10cSrcweir         if( ! ( aCommand.Argument >>= sPropertyValues ) )
360cdf0e10cSrcweir             m_pMyShell->installError( CommandId,
361cdf0e10cSrcweir                                       TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT );
362cdf0e10cSrcweir         else
363cdf0e10cSrcweir             aAny <<= setPropertyValues( CommandId,sPropertyValues ); // calls endTask by itself
364cdf0e10cSrcweir     }
365cdf0e10cSrcweir     else if( ! aCommand.Name.compareToAscii( "getPropertyValues" ) )
366cdf0e10cSrcweir     {
367cdf0e10cSrcweir         Sequence< beans::Property > ListOfRequestedProperties;
368cdf0e10cSrcweir 
369cdf0e10cSrcweir         if( ! ( aCommand.Argument >>= ListOfRequestedProperties ) )
370cdf0e10cSrcweir             m_pMyShell->installError( CommandId,
371cdf0e10cSrcweir                                       TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT );
372cdf0e10cSrcweir         else
373cdf0e10cSrcweir             aAny <<= getPropertyValues( CommandId,
374cdf0e10cSrcweir                                         ListOfRequestedProperties );
375cdf0e10cSrcweir     }
376cdf0e10cSrcweir     else if( ! aCommand.Name.compareToAscii( "open" ) )
377cdf0e10cSrcweir     {
378cdf0e10cSrcweir         OpenCommandArgument2 aOpenArgument;
379cdf0e10cSrcweir         if( ! ( aCommand.Argument >>= aOpenArgument ) )
380cdf0e10cSrcweir             m_pMyShell->installError( CommandId,
381cdf0e10cSrcweir                                       TASKHANDLING_WRONG_OPEN_ARGUMENT );
382cdf0e10cSrcweir         else
383cdf0e10cSrcweir         {
384cdf0e10cSrcweir             Reference< XDynamicResultSet > result = open( CommandId,aOpenArgument );
385cdf0e10cSrcweir             if( result.is() )
386cdf0e10cSrcweir                 aAny <<= result;
387cdf0e10cSrcweir         }
388cdf0e10cSrcweir     }
389cdf0e10cSrcweir     else if( ! aCommand.Name.compareToAscii( "delete" ) )
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         if( ! aCommand.Argument.has< sal_Bool >() )
392cdf0e10cSrcweir             m_pMyShell->installError( CommandId,
393cdf0e10cSrcweir                                       TASKHANDLING_WRONG_DELETE_ARGUMENT );
394cdf0e10cSrcweir         else
395cdf0e10cSrcweir             deleteContent( CommandId );
396cdf0e10cSrcweir     }
397cdf0e10cSrcweir     else if( ! aCommand.Name.compareToAscii( "transfer" ) )
398cdf0e10cSrcweir     {
399cdf0e10cSrcweir         TransferInfo aTransferInfo;
400cdf0e10cSrcweir         if( ! ( aCommand.Argument >>= aTransferInfo ) )
401cdf0e10cSrcweir             m_pMyShell->installError( CommandId,
402cdf0e10cSrcweir                                       TASKHANDLING_WRONG_TRANSFER_ARGUMENT );
403cdf0e10cSrcweir         else
404cdf0e10cSrcweir             transfer( CommandId, aTransferInfo );
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir     else if( ! aCommand.Name.compareToAscii( "insert" ) )
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir         InsertCommandArgument aInsertArgument;
409cdf0e10cSrcweir         if( ! ( aCommand.Argument >>= aInsertArgument ) )
410cdf0e10cSrcweir             m_pMyShell->installError( CommandId,
411cdf0e10cSrcweir                                       TASKHANDLING_WRONG_INSERT_ARGUMENT );
412cdf0e10cSrcweir         else
413cdf0e10cSrcweir             insert( CommandId,aInsertArgument );
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir     else if( ! aCommand.Name.compareToAscii( "getCasePreservingURL" ) )
416cdf0e10cSrcweir     {
417cdf0e10cSrcweir         Sequence< beans::Property > seq(1);
418cdf0e10cSrcweir         seq[0] = beans::Property(
419cdf0e10cSrcweir             rtl::OUString::createFromAscii("CasePreservingURL"),
420cdf0e10cSrcweir             -1,
421cdf0e10cSrcweir             getCppuType( static_cast< sal_Bool* >(0) ),
422cdf0e10cSrcweir             0 );
423cdf0e10cSrcweir         Reference< sdbc::XRow > xRow = getPropertyValues( CommandId,seq );
424cdf0e10cSrcweir         rtl::OUString CasePreservingURL = xRow->getString(1);
425cdf0e10cSrcweir         if(!xRow->wasNull())
426cdf0e10cSrcweir             aAny <<= CasePreservingURL;
427cdf0e10cSrcweir     }
428cdf0e10cSrcweir     else if( ! aCommand.Name.compareToAscii( "createNewContent" ) )
429cdf0e10cSrcweir     {
430cdf0e10cSrcweir         ucb::ContentInfo aArg;
431cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aArg ) )
432cdf0e10cSrcweir             m_pMyShell->installError( CommandId,
433cdf0e10cSrcweir                                       TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT );
434cdf0e10cSrcweir         else
435cdf0e10cSrcweir             aAny <<= createNewContent( aArg );
436cdf0e10cSrcweir     }
437cdf0e10cSrcweir     else
438cdf0e10cSrcweir         m_pMyShell->installError( CommandId,
439cdf0e10cSrcweir                                   TASKHANDLER_UNSUPPORTED_COMMAND );
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 
442cdf0e10cSrcweir     // This is the only function allowed to throw an exception
443cdf0e10cSrcweir     endTask( CommandId );
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     return aAny;
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 
450cdf0e10cSrcweir void SAL_CALL
addPropertiesChangeListener(const Sequence<rtl::OUString> & PropertyNames,const Reference<beans::XPropertiesChangeListener> & Listener)451cdf0e10cSrcweir BaseContent::addPropertiesChangeListener(
452cdf0e10cSrcweir     const Sequence< rtl::OUString >& PropertyNames,
453cdf0e10cSrcweir     const Reference< beans::XPropertiesChangeListener >& Listener )
454cdf0e10cSrcweir     throw( RuntimeException )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir     if( ! Listener.is() )
457cdf0e10cSrcweir         return;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
460cdf0e10cSrcweir 
461cdf0e10cSrcweir     if( ! m_pPropertyListener )
462cdf0e10cSrcweir         m_pPropertyListener = new PropertyListeners( m_aEventListenerMutex );
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     if( PropertyNames.getLength() == 0 )
466cdf0e10cSrcweir         m_pPropertyListener->addInterface( rtl::OUString(),Listener );
467cdf0e10cSrcweir     else
468cdf0e10cSrcweir     {
469cdf0e10cSrcweir         Reference< beans::XPropertySetInfo > xProp = m_pMyShell->info_p( m_aUncPath );
470cdf0e10cSrcweir         for( sal_Int32 i = 0; i < PropertyNames.getLength(); ++i )
471cdf0e10cSrcweir             if( xProp->hasPropertyByName( PropertyNames[i] ) )
472cdf0e10cSrcweir                 m_pPropertyListener->addInterface( PropertyNames[i],Listener );
473cdf0e10cSrcweir     }
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 
477cdf0e10cSrcweir void SAL_CALL
removePropertiesChangeListener(const Sequence<rtl::OUString> & PropertyNames,const Reference<beans::XPropertiesChangeListener> & Listener)478cdf0e10cSrcweir BaseContent::removePropertiesChangeListener( const Sequence< rtl::OUString >& PropertyNames,
479cdf0e10cSrcweir                                              const Reference< beans::XPropertiesChangeListener >& Listener )
480cdf0e10cSrcweir     throw( RuntimeException )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir     if( ! Listener.is() )
483cdf0e10cSrcweir         return;
484cdf0e10cSrcweir 
485cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
486cdf0e10cSrcweir 
487cdf0e10cSrcweir     if( ! m_pPropertyListener )
488cdf0e10cSrcweir         return;
489cdf0e10cSrcweir 
490cdf0e10cSrcweir     for( sal_Int32 i = 0; i < PropertyNames.getLength(); ++i )
491cdf0e10cSrcweir         m_pPropertyListener->removeInterface( PropertyNames[i],Listener );
492cdf0e10cSrcweir 
493cdf0e10cSrcweir     m_pPropertyListener->removeInterface( rtl::OUString(), Listener );
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 
497cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////////////////
498cdf0e10cSrcweir // XContent
499cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////////////////
500cdf0e10cSrcweir 
501cdf0e10cSrcweir Reference< ucb::XContentIdentifier > SAL_CALL
getIdentifier()502cdf0e10cSrcweir BaseContent::getIdentifier()
503cdf0e10cSrcweir     throw( RuntimeException )
504cdf0e10cSrcweir {
505cdf0e10cSrcweir     return m_xContentIdentifier;
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 
509cdf0e10cSrcweir rtl::OUString SAL_CALL
getContentType()510cdf0e10cSrcweir BaseContent::getContentType()
511cdf0e10cSrcweir     throw( RuntimeException )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir     if( !( m_nState & Deleted ) )
514cdf0e10cSrcweir     {
515cdf0e10cSrcweir         if( m_nState & JustInserted )
516cdf0e10cSrcweir         {
517cdf0e10cSrcweir             if ( m_bFolder )
518cdf0e10cSrcweir                 return m_pMyShell->FolderContentType;
519cdf0e10cSrcweir             else
520cdf0e10cSrcweir                 return m_pMyShell->FileContentType;
521cdf0e10cSrcweir         }
522cdf0e10cSrcweir         else
523cdf0e10cSrcweir         {
524cdf0e10cSrcweir             try
525cdf0e10cSrcweir             {
526cdf0e10cSrcweir                 // Who am I ?
527cdf0e10cSrcweir                 Sequence< beans::Property > seq(1);
528cdf0e10cSrcweir                 seq[0] = beans::Property( rtl::OUString::createFromAscii("IsDocument"),
529cdf0e10cSrcweir                                           -1,
530cdf0e10cSrcweir                                           getCppuType( static_cast< sal_Bool* >(0) ),
531cdf0e10cSrcweir                                           0 );
532cdf0e10cSrcweir                 Reference< sdbc::XRow > xRow = getPropertyValues( -1,seq );
533cdf0e10cSrcweir                 sal_Bool IsDocument = xRow->getBoolean( 1 );
534cdf0e10cSrcweir 
535cdf0e10cSrcweir                 if ( !xRow->wasNull() )
536cdf0e10cSrcweir                 {
537cdf0e10cSrcweir                     if ( IsDocument )
538cdf0e10cSrcweir                         return m_pMyShell->FileContentType;
539cdf0e10cSrcweir                     else
540cdf0e10cSrcweir                         return m_pMyShell->FolderContentType;
541cdf0e10cSrcweir                 }
542cdf0e10cSrcweir                 else
543cdf0e10cSrcweir                 {
544cdf0e10cSrcweir                     OSL_ENSURE( false,
545cdf0e10cSrcweir                                 "BaseContent::getContentType - Property value was null!" );
546cdf0e10cSrcweir                 }
547cdf0e10cSrcweir             }
548cdf0e10cSrcweir             catch ( sdbc::SQLException const & )
549cdf0e10cSrcweir             {
550cdf0e10cSrcweir                 OSL_ENSURE( false,
551cdf0e10cSrcweir                             "BaseContent::getContentType - Caught SQLException!" );
552cdf0e10cSrcweir             }
553cdf0e10cSrcweir         }
554cdf0e10cSrcweir     }
555cdf0e10cSrcweir 
556cdf0e10cSrcweir     return rtl::OUString();
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 
561cdf0e10cSrcweir void SAL_CALL
addContentEventListener(const Reference<XContentEventListener> & Listener)562cdf0e10cSrcweir BaseContent::addContentEventListener(
563cdf0e10cSrcweir     const Reference< XContentEventListener >& Listener )
564cdf0e10cSrcweir     throw( RuntimeException )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
567cdf0e10cSrcweir 
568cdf0e10cSrcweir     if ( ! m_pContentEventListeners )
569cdf0e10cSrcweir         m_pContentEventListeners =
570cdf0e10cSrcweir             new cppu::OInterfaceContainerHelper( m_aEventListenerMutex );
571cdf0e10cSrcweir 
572cdf0e10cSrcweir 
573cdf0e10cSrcweir     m_pContentEventListeners->addInterface( Listener );
574cdf0e10cSrcweir }
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 
577cdf0e10cSrcweir void SAL_CALL
removeContentEventListener(const Reference<XContentEventListener> & Listener)578cdf0e10cSrcweir BaseContent::removeContentEventListener(
579cdf0e10cSrcweir     const Reference< XContentEventListener >& Listener )
580cdf0e10cSrcweir     throw( RuntimeException )
581cdf0e10cSrcweir {
582cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
583cdf0e10cSrcweir 
584cdf0e10cSrcweir     if ( m_pContentEventListeners )
585cdf0e10cSrcweir         m_pContentEventListeners->removeInterface( Listener );
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 
590cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
591cdf0e10cSrcweir // XPropertyContainer
592cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 
595cdf0e10cSrcweir void SAL_CALL
addProperty(const rtl::OUString & Name,sal_Int16 Attributes,const Any & DefaultValue)596cdf0e10cSrcweir BaseContent::addProperty(
597cdf0e10cSrcweir     const rtl::OUString& Name,
598cdf0e10cSrcweir     sal_Int16 Attributes,
599cdf0e10cSrcweir     const Any& DefaultValue )
600cdf0e10cSrcweir     throw( beans::PropertyExistException,
601cdf0e10cSrcweir            beans::IllegalTypeException,
602cdf0e10cSrcweir            lang::IllegalArgumentException,
603cdf0e10cSrcweir            RuntimeException)
604cdf0e10cSrcweir {
605cdf0e10cSrcweir     if( ( m_nState & JustInserted ) || ( m_nState & Deleted ) || Name == rtl::OUString() )
606cdf0e10cSrcweir     {
607cdf0e10cSrcweir         throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
608cdf0e10cSrcweir     }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir     m_pMyShell->associate( m_aUncPath,Name,DefaultValue,Attributes );
611cdf0e10cSrcweir }
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 
614cdf0e10cSrcweir void SAL_CALL
removeProperty(const rtl::OUString & Name)615cdf0e10cSrcweir BaseContent::removeProperty(
616cdf0e10cSrcweir     const rtl::OUString& Name )
617cdf0e10cSrcweir     throw( beans::UnknownPropertyException,
618cdf0e10cSrcweir            beans::NotRemoveableException,
619cdf0e10cSrcweir            RuntimeException)
620cdf0e10cSrcweir {
621cdf0e10cSrcweir 
622cdf0e10cSrcweir     if( m_nState & Deleted )
623cdf0e10cSrcweir         throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
624cdf0e10cSrcweir 
625cdf0e10cSrcweir     m_pMyShell->deassociate( m_aUncPath, Name );
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
629cdf0e10cSrcweir // XContentCreator
630cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
631cdf0e10cSrcweir 
632cdf0e10cSrcweir Sequence< ContentInfo > SAL_CALL
queryCreatableContentsInfo(void)633cdf0e10cSrcweir BaseContent::queryCreatableContentsInfo(
634cdf0e10cSrcweir     void )
635cdf0e10cSrcweir     throw( RuntimeException )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir     return m_pMyShell->queryCreatableContentsInfo();
638cdf0e10cSrcweir }
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 
641cdf0e10cSrcweir Reference< XContent > SAL_CALL
createNewContent(const ContentInfo & Info)642cdf0e10cSrcweir BaseContent::createNewContent(
643cdf0e10cSrcweir     const ContentInfo& Info )
644cdf0e10cSrcweir     throw( RuntimeException )
645cdf0e10cSrcweir {
646cdf0e10cSrcweir     // Check type.
647cdf0e10cSrcweir     if ( !Info.Type.getLength() )
648cdf0e10cSrcweir         return Reference< XContent >();
649cdf0e10cSrcweir 
650cdf0e10cSrcweir     sal_Bool bFolder
651cdf0e10cSrcweir         = ( Info.Type.compareTo( m_pMyShell->FolderContentType ) == 0 );
652cdf0e10cSrcweir     if ( !bFolder )
653cdf0e10cSrcweir     {
654cdf0e10cSrcweir         if ( Info.Type.compareTo( m_pMyShell->FileContentType ) != 0 )
655cdf0e10cSrcweir         {
656cdf0e10cSrcweir             // Neither folder nor file to create!
657cdf0e10cSrcweir             return Reference< XContent >();
658cdf0e10cSrcweir         }
659cdf0e10cSrcweir     }
660cdf0e10cSrcweir 
661cdf0e10cSrcweir     // Who am I ?
662cdf0e10cSrcweir     sal_Bool IsDocument = false;
663cdf0e10cSrcweir 
664cdf0e10cSrcweir     try
665cdf0e10cSrcweir     {
666cdf0e10cSrcweir         Sequence< beans::Property > seq(1);
667cdf0e10cSrcweir         seq[0] = beans::Property( rtl::OUString::createFromAscii("IsDocument"),
668cdf0e10cSrcweir                                   -1,
669cdf0e10cSrcweir                                   getCppuType( static_cast< sal_Bool* >(0) ),
670cdf0e10cSrcweir                                   0 );
671cdf0e10cSrcweir         Reference< sdbc::XRow > xRow = getPropertyValues( -1,seq );
672cdf0e10cSrcweir         IsDocument = xRow->getBoolean( 1 );
673cdf0e10cSrcweir 
674cdf0e10cSrcweir         if ( xRow->wasNull() )
675cdf0e10cSrcweir         {
676cdf0e10cSrcweir             IsDocument = false;
677cdf0e10cSrcweir //              OSL_ENSURE( false,
678cdf0e10cSrcweir //                          "BaseContent::createNewContent - Property value was null!" );
679cdf0e10cSrcweir //              return Reference< XContent >();
680cdf0e10cSrcweir         }
681cdf0e10cSrcweir     }
682cdf0e10cSrcweir     catch ( sdbc::SQLException const & )
683cdf0e10cSrcweir     {
684cdf0e10cSrcweir         OSL_ENSURE( false,
685cdf0e10cSrcweir                     "BaseContent::createNewContent - Caught SQLException!" );
686cdf0e10cSrcweir         return Reference< XContent >();
687cdf0e10cSrcweir     }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir     rtl::OUString dstUncPath;
690cdf0e10cSrcweir 
691cdf0e10cSrcweir     if( IsDocument )
692cdf0e10cSrcweir     {
693cdf0e10cSrcweir         // KSO: Why is a document a XContentCreator? This is quite unusual.
694cdf0e10cSrcweir         dstUncPath = getParentName( m_aUncPath );
695cdf0e10cSrcweir     }
696cdf0e10cSrcweir     else
697cdf0e10cSrcweir         dstUncPath = m_aUncPath;
698cdf0e10cSrcweir 
699cdf0e10cSrcweir     BaseContent* p = new BaseContent( m_pMyShell, dstUncPath, bFolder );
700cdf0e10cSrcweir     return Reference< XContent >( p );
701cdf0e10cSrcweir }
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 
704cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
705cdf0e10cSrcweir // XPropertySetInfoChangeNotifier
706cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 
709cdf0e10cSrcweir void SAL_CALL
addPropertySetInfoChangeListener(const Reference<beans::XPropertySetInfoChangeListener> & Listener)710cdf0e10cSrcweir BaseContent::addPropertySetInfoChangeListener(
711cdf0e10cSrcweir     const Reference< beans::XPropertySetInfoChangeListener >& Listener )
712cdf0e10cSrcweir     throw( RuntimeException )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
715cdf0e10cSrcweir     if( ! m_pPropertySetInfoChangeListeners )
716cdf0e10cSrcweir         m_pPropertySetInfoChangeListeners = new cppu::OInterfaceContainerHelper( m_aEventListenerMutex );
717cdf0e10cSrcweir 
718cdf0e10cSrcweir     m_pPropertySetInfoChangeListeners->addInterface( Listener );
719cdf0e10cSrcweir }
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 
722cdf0e10cSrcweir void SAL_CALL
removePropertySetInfoChangeListener(const Reference<beans::XPropertySetInfoChangeListener> & Listener)723cdf0e10cSrcweir BaseContent::removePropertySetInfoChangeListener(
724cdf0e10cSrcweir     const Reference< beans::XPropertySetInfoChangeListener >& Listener )
725cdf0e10cSrcweir     throw( RuntimeException )
726cdf0e10cSrcweir {
727cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
728cdf0e10cSrcweir 
729cdf0e10cSrcweir     if( m_pPropertySetInfoChangeListeners )
730cdf0e10cSrcweir         m_pPropertySetInfoChangeListeners->removeInterface( Listener );
731cdf0e10cSrcweir }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir 
734cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
735cdf0e10cSrcweir // XChild
736cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
737cdf0e10cSrcweir 
738cdf0e10cSrcweir Reference< XInterface > SAL_CALL
getParent(void)739cdf0e10cSrcweir BaseContent::getParent(
740cdf0e10cSrcweir     void )
741cdf0e10cSrcweir     throw( RuntimeException )
742cdf0e10cSrcweir {
743cdf0e10cSrcweir     rtl::OUString ParentUnq = getParentName( m_aUncPath );
744cdf0e10cSrcweir     rtl::OUString ParentUrl;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 
747cdf0e10cSrcweir     sal_Bool err = m_pMyShell->getUrlFromUnq( ParentUnq, ParentUrl );
748cdf0e10cSrcweir     if( err )
749cdf0e10cSrcweir         return Reference< XInterface >( 0 );
750cdf0e10cSrcweir 
751cdf0e10cSrcweir     FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,ParentUnq );
752cdf0e10cSrcweir     Reference< XContentIdentifier > Identifier( p );
753cdf0e10cSrcweir 
754cdf0e10cSrcweir     try
755cdf0e10cSrcweir     {
756cdf0e10cSrcweir         Reference< XContent > content = m_pMyShell->m_pProvider->queryContent( Identifier );
757cdf0e10cSrcweir         return Reference<XInterface>(content,UNO_QUERY);
758cdf0e10cSrcweir     }
759cdf0e10cSrcweir     catch( IllegalIdentifierException )
760cdf0e10cSrcweir     {
761cdf0e10cSrcweir         return Reference< XInterface >();
762cdf0e10cSrcweir     }
763cdf0e10cSrcweir }
764cdf0e10cSrcweir 
765cdf0e10cSrcweir 
766cdf0e10cSrcweir void SAL_CALL
setParent(const Reference<XInterface> &)767cdf0e10cSrcweir BaseContent::setParent(
768cdf0e10cSrcweir     const Reference< XInterface >& )
769cdf0e10cSrcweir     throw( lang::NoSupportException,
770cdf0e10cSrcweir            RuntimeException)
771cdf0e10cSrcweir {
772cdf0e10cSrcweir     throw lang::NoSupportException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
773cdf0e10cSrcweir }
774cdf0e10cSrcweir 
775cdf0e10cSrcweir 
776cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
777cdf0e10cSrcweir // Private Methods
778cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////////////////
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 
781cdf0e10cSrcweir Reference< XCommandInfo > SAL_CALL
getCommandInfo()782cdf0e10cSrcweir BaseContent::getCommandInfo()
783cdf0e10cSrcweir     throw( RuntimeException )
784cdf0e10cSrcweir {
785cdf0e10cSrcweir     if( m_nState & Deleted )
786cdf0e10cSrcweir         return Reference< XCommandInfo >();
787cdf0e10cSrcweir 
788cdf0e10cSrcweir     return m_pMyShell->info_c();
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 
792cdf0e10cSrcweir Reference< beans::XPropertySetInfo > SAL_CALL
getPropertySetInfo(sal_Int32)793cdf0e10cSrcweir BaseContent::getPropertySetInfo(
794cdf0e10cSrcweir     sal_Int32 )
795cdf0e10cSrcweir     throw( RuntimeException )
796cdf0e10cSrcweir {
797cdf0e10cSrcweir     if( m_nState & Deleted )
798cdf0e10cSrcweir         return Reference< beans::XPropertySetInfo >();
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     return m_pMyShell->info_p( m_aUncPath );
801cdf0e10cSrcweir }
802cdf0e10cSrcweir 
803cdf0e10cSrcweir 
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 
806cdf0e10cSrcweir Reference< sdbc::XRow > SAL_CALL
getPropertyValues(sal_Int32 nMyCommandIdentifier,const Sequence<beans::Property> & PropertySet)807cdf0e10cSrcweir BaseContent::getPropertyValues(
808cdf0e10cSrcweir     sal_Int32 nMyCommandIdentifier,
809cdf0e10cSrcweir     const Sequence< beans::Property >& PropertySet )
810cdf0e10cSrcweir     throw( RuntimeException )
811cdf0e10cSrcweir {
812cdf0e10cSrcweir     sal_Int32 nProps = PropertySet.getLength();
813cdf0e10cSrcweir     if ( !nProps )
814cdf0e10cSrcweir         return Reference< sdbc::XRow >();
815cdf0e10cSrcweir 
816cdf0e10cSrcweir     if( m_nState & Deleted )
817cdf0e10cSrcweir     {
818cdf0e10cSrcweir         Sequence< Any > aValues( nProps );
819cdf0e10cSrcweir         return Reference< sdbc::XRow >( new XRow_impl( m_pMyShell, aValues ) );
820cdf0e10cSrcweir     }
821cdf0e10cSrcweir 
822cdf0e10cSrcweir     if( m_nState & JustInserted )
823cdf0e10cSrcweir     {
824cdf0e10cSrcweir         Sequence< Any > aValues( nProps );
825cdf0e10cSrcweir         Any* pValues = aValues.getArray();
826cdf0e10cSrcweir 
827cdf0e10cSrcweir         const beans::Property* pProps = PropertySet.getConstArray();
828cdf0e10cSrcweir 
829cdf0e10cSrcweir         for ( sal_Int32 n = 0; n < nProps; ++n )
830cdf0e10cSrcweir         {
831cdf0e10cSrcweir             const beans::Property& rProp = pProps[ n ];
832cdf0e10cSrcweir             Any& rValue = pValues[ n ];
833cdf0e10cSrcweir 
834cdf0e10cSrcweir             if( rProp.Name.compareToAscii( "ContentType" ) == 0 )
835cdf0e10cSrcweir             {
836cdf0e10cSrcweir                 rValue <<= m_bFolder ? m_pMyShell->FolderContentType
837cdf0e10cSrcweir                     : m_pMyShell->FileContentType;
838cdf0e10cSrcweir             }
839cdf0e10cSrcweir             else if( rProp.Name.compareToAscii( "IsFolder" ) == 0 )
840cdf0e10cSrcweir             {
841cdf0e10cSrcweir                 rValue <<= m_bFolder;
842cdf0e10cSrcweir             }
843cdf0e10cSrcweir             else if( rProp.Name.compareToAscii( "IsDocument" ) == 0 )
844cdf0e10cSrcweir             {
845cdf0e10cSrcweir                 rValue <<= sal_Bool( !m_bFolder );
846cdf0e10cSrcweir             }
847cdf0e10cSrcweir         }
848cdf0e10cSrcweir 
849cdf0e10cSrcweir         return Reference< sdbc::XRow >(
850cdf0e10cSrcweir             new XRow_impl( m_pMyShell, aValues ) );
851cdf0e10cSrcweir     }
852cdf0e10cSrcweir 
853cdf0e10cSrcweir     return m_pMyShell->getv( nMyCommandIdentifier,
854cdf0e10cSrcweir                              m_aUncPath,
855cdf0e10cSrcweir                              PropertySet );
856cdf0e10cSrcweir }
857cdf0e10cSrcweir 
858cdf0e10cSrcweir 
859cdf0e10cSrcweir Sequence< Any > SAL_CALL
setPropertyValues(sal_Int32 nMyCommandIdentifier,const Sequence<beans::PropertyValue> & Values)860cdf0e10cSrcweir BaseContent::setPropertyValues(
861cdf0e10cSrcweir     sal_Int32 nMyCommandIdentifier,
862cdf0e10cSrcweir     const Sequence< beans::PropertyValue >& Values )
863cdf0e10cSrcweir     throw()
864cdf0e10cSrcweir {
865cdf0e10cSrcweir     if( m_nState & Deleted )
866cdf0e10cSrcweir     {   // To do
867cdf0e10cSrcweir         return Sequence< Any >( Values.getLength() );
868cdf0e10cSrcweir     }
869cdf0e10cSrcweir 
870cdf0e10cSrcweir     const rtl::OUString Title = rtl::OUString::createFromAscii( "Title" );
871cdf0e10cSrcweir 
872cdf0e10cSrcweir     // Special handling for files which have to be inserted
873cdf0e10cSrcweir     if( m_nState & JustInserted )
874cdf0e10cSrcweir     {
875cdf0e10cSrcweir         for( sal_Int32 i = 0; i < Values.getLength(); ++i )
876cdf0e10cSrcweir         {
877cdf0e10cSrcweir             if( Values[i].Name == Title )
878cdf0e10cSrcweir             {
879cdf0e10cSrcweir                 rtl::OUString NewTitle;
880cdf0e10cSrcweir                 if( Values[i].Value >>= NewTitle )
881cdf0e10cSrcweir                 {
882cdf0e10cSrcweir                     if ( m_nState & NameForInsertionSet )
883cdf0e10cSrcweir                     {
884cdf0e10cSrcweir                         // User wants to set another Title before "insert".
885cdf0e10cSrcweir                         // m_aUncPath contains previous own URI.
886cdf0e10cSrcweir 
887cdf0e10cSrcweir                         sal_Int32 nLastSlash = m_aUncPath.lastIndexOf( '/' );
888cdf0e10cSrcweir                         bool bTrailingSlash = false;
889cdf0e10cSrcweir                         if ( nLastSlash == m_aUncPath.getLength() - 1 )
890cdf0e10cSrcweir                         {
891cdf0e10cSrcweir                             bTrailingSlash = true;
892cdf0e10cSrcweir                             nLastSlash
893cdf0e10cSrcweir                                 = m_aUncPath.lastIndexOf( '/', nLastSlash );
894cdf0e10cSrcweir                         }
895cdf0e10cSrcweir 
896cdf0e10cSrcweir                         OSL_ENSURE( nLastSlash != -1,
897cdf0e10cSrcweir                                     "BaseContent::setPropertyValues: "
898cdf0e10cSrcweir                                     "Invalid URL!" );
899cdf0e10cSrcweir 
900cdf0e10cSrcweir                         rtl::OUStringBuffer aBuf(
901cdf0e10cSrcweir                             m_aUncPath.copy( 0, nLastSlash + 1 ) );
902cdf0e10cSrcweir 
903cdf0e10cSrcweir                         if ( NewTitle.getLength() > 0 )
904cdf0e10cSrcweir                         {
905cdf0e10cSrcweir                             aBuf.append( NewTitle );
906cdf0e10cSrcweir                             if ( bTrailingSlash )
907cdf0e10cSrcweir                                 aBuf.append( sal_Unicode( '/' ) );
908cdf0e10cSrcweir                         }
909cdf0e10cSrcweir                         else
910cdf0e10cSrcweir                         {
911cdf0e10cSrcweir                             m_nState &= ~NameForInsertionSet;
912cdf0e10cSrcweir                         }
913cdf0e10cSrcweir 
914cdf0e10cSrcweir                         m_aUncPath = aBuf.makeStringAndClear();
915cdf0e10cSrcweir                     }
916cdf0e10cSrcweir                     else
917cdf0e10cSrcweir                     {
918cdf0e10cSrcweir                         if ( NewTitle.getLength() > 0 )
919cdf0e10cSrcweir                         {
920cdf0e10cSrcweir                             // Initial Title before "insert".
921cdf0e10cSrcweir                             // m_aUncPath contains parent's URI.
922cdf0e10cSrcweir 
923cdf0e10cSrcweir                             if( m_aUncPath.lastIndexOf( sal_Unicode('/') ) != m_aUncPath.getLength() - 1 )
924cdf0e10cSrcweir                                 m_aUncPath += rtl::OUString::createFromAscii("/");
925cdf0e10cSrcweir 
926cdf0e10cSrcweir                             m_aUncPath += rtl::Uri::encode( NewTitle,
927cdf0e10cSrcweir                                                             rtl_UriCharClassPchar,
928cdf0e10cSrcweir                                                             rtl_UriEncodeIgnoreEscapes,
929cdf0e10cSrcweir                                                             RTL_TEXTENCODING_UTF8 );
930cdf0e10cSrcweir                             m_nState |= NameForInsertionSet;
931cdf0e10cSrcweir                         }
932cdf0e10cSrcweir                     }
933cdf0e10cSrcweir                 }
934cdf0e10cSrcweir             }
935cdf0e10cSrcweir         }
936cdf0e10cSrcweir 
937cdf0e10cSrcweir         return Sequence< Any >( Values.getLength() );
938cdf0e10cSrcweir     }
939cdf0e10cSrcweir     else
940cdf0e10cSrcweir     {
941cdf0e10cSrcweir         Sequence< Any > ret = m_pMyShell->setv( m_aUncPath, // Does not handle Title
942cdf0e10cSrcweir                                                 Values );
943cdf0e10cSrcweir 
944cdf0e10cSrcweir         // Special handling Title: Setting Title is equivalent to a renaming of the underlying file
945cdf0e10cSrcweir         for( sal_Int32 i = 0; i < Values.getLength(); ++i )
946cdf0e10cSrcweir         {
947cdf0e10cSrcweir             if( Values[i].Name != Title )
948cdf0e10cSrcweir                 continue;                  // handled by setv
949cdf0e10cSrcweir 
950cdf0e10cSrcweir             rtl::OUString NewTitle;
951cdf0e10cSrcweir             if( !( Values[i].Value >>= NewTitle ) )
952cdf0e10cSrcweir             {
953cdf0e10cSrcweir                 ret[i] <<= beans::IllegalTypeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
954cdf0e10cSrcweir                 break;
955cdf0e10cSrcweir             }
956cdf0e10cSrcweir             else if( ! NewTitle.getLength() )
957cdf0e10cSrcweir             {
958cdf0e10cSrcweir                 ret[i] <<= lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
959cdf0e10cSrcweir                 break;
960cdf0e10cSrcweir             }
961cdf0e10cSrcweir 
962cdf0e10cSrcweir 
963cdf0e10cSrcweir             rtl::OUString aDstName = getParentName( m_aUncPath );
964cdf0e10cSrcweir             if( aDstName.lastIndexOf( sal_Unicode('/') ) != aDstName.getLength() - 1 )
965cdf0e10cSrcweir                 aDstName += rtl::OUString::createFromAscii("/");
966cdf0e10cSrcweir 
967cdf0e10cSrcweir             aDstName += rtl::Uri::encode( NewTitle,
968cdf0e10cSrcweir                                           rtl_UriCharClassPchar,
969cdf0e10cSrcweir                                           rtl_UriEncodeIgnoreEscapes,
970cdf0e10cSrcweir                                           RTL_TEXTENCODING_UTF8 );
971cdf0e10cSrcweir 
972cdf0e10cSrcweir             m_pMyShell->move( nMyCommandIdentifier, // move notifies the childs also;
973cdf0e10cSrcweir                               m_aUncPath,
974cdf0e10cSrcweir                               aDstName,
975cdf0e10cSrcweir                               NameClash::KEEP );
976cdf0e10cSrcweir 
977cdf0e10cSrcweir             try
978cdf0e10cSrcweir             {
979cdf0e10cSrcweir                 endTask( nMyCommandIdentifier );
980cdf0e10cSrcweir             }
981cdf0e10cSrcweir             catch( const Exception& e )
982cdf0e10cSrcweir             {
983cdf0e10cSrcweir                 ret[i] <<= e;
984cdf0e10cSrcweir             }
985cdf0e10cSrcweir 
986*88c764bfSmseidel             // NameChanges come back through a ContentEvent
987cdf0e10cSrcweir             break; // only handling Title
988cdf0e10cSrcweir         } // end for
989cdf0e10cSrcweir 
990cdf0e10cSrcweir         return ret;
991cdf0e10cSrcweir     }
992cdf0e10cSrcweir }
993cdf0e10cSrcweir 
994cdf0e10cSrcweir 
995cdf0e10cSrcweir 
996cdf0e10cSrcweir Reference< XDynamicResultSet > SAL_CALL
open(sal_Int32 nMyCommandIdentifier,const OpenCommandArgument2 & aCommandArgument)997cdf0e10cSrcweir BaseContent::open(
998cdf0e10cSrcweir     sal_Int32 nMyCommandIdentifier,
999cdf0e10cSrcweir     const OpenCommandArgument2& aCommandArgument )
1000cdf0e10cSrcweir     throw()
1001cdf0e10cSrcweir {
1002cdf0e10cSrcweir     Reference< XDynamicResultSet > retValue( 0 );
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir     if( ( m_nState & Deleted ) )
1005cdf0e10cSrcweir     {
1006cdf0e10cSrcweir         m_pMyShell->installError( nMyCommandIdentifier,
1007cdf0e10cSrcweir                                   TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND );
1008cdf0e10cSrcweir     }
1009cdf0e10cSrcweir     else if( m_nState & JustInserted )
1010cdf0e10cSrcweir     {
1011cdf0e10cSrcweir         m_pMyShell->installError( nMyCommandIdentifier,
1012cdf0e10cSrcweir                                   TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND );
1013cdf0e10cSrcweir     }
1014cdf0e10cSrcweir     else
1015cdf0e10cSrcweir     {
1016cdf0e10cSrcweir         if( aCommandArgument.Mode == OpenMode::DOCUMENT ||
1017cdf0e10cSrcweir             aCommandArgument.Mode == OpenMode::DOCUMENT_SHARE_DENY_NONE )
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir         {
1020cdf0e10cSrcweir             Reference< io::XOutputStream > outputStream( aCommandArgument.Sink,UNO_QUERY );
1021cdf0e10cSrcweir             if( outputStream.is() )
1022cdf0e10cSrcweir             {
1023cdf0e10cSrcweir                 m_pMyShell->page( nMyCommandIdentifier,
1024cdf0e10cSrcweir                                   m_aUncPath,
1025cdf0e10cSrcweir                                   outputStream );
1026cdf0e10cSrcweir             }
1027cdf0e10cSrcweir 
1028cdf0e10cSrcweir             sal_Bool bLock = ( aCommandArgument.Mode != OpenMode::DOCUMENT_SHARE_DENY_NONE );
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir             Reference< io::XActiveDataSink > activeDataSink( aCommandArgument.Sink,UNO_QUERY );
1031cdf0e10cSrcweir             if( activeDataSink.is() )
1032cdf0e10cSrcweir             {
1033cdf0e10cSrcweir                 activeDataSink->setInputStream( m_pMyShell->open( nMyCommandIdentifier,
1034cdf0e10cSrcweir                                                                   m_aUncPath,
1035cdf0e10cSrcweir                                                                   bLock ) );
1036cdf0e10cSrcweir             }
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir             Reference< io::XActiveDataStreamer > activeDataStreamer( aCommandArgument.Sink,UNO_QUERY );
1039cdf0e10cSrcweir             if( activeDataStreamer.is() )
1040cdf0e10cSrcweir             {
1041cdf0e10cSrcweir                 activeDataStreamer->setStream( m_pMyShell->open_rw( nMyCommandIdentifier,
1042cdf0e10cSrcweir                                                                     m_aUncPath,
1043cdf0e10cSrcweir                                                                     bLock ) );
1044cdf0e10cSrcweir             }
1045cdf0e10cSrcweir         }
1046cdf0e10cSrcweir         else if ( aCommandArgument.Mode == OpenMode::ALL        ||
1047cdf0e10cSrcweir                   aCommandArgument.Mode == OpenMode::FOLDERS    ||
1048cdf0e10cSrcweir                   aCommandArgument.Mode == OpenMode::DOCUMENTS )
1049cdf0e10cSrcweir         {
1050cdf0e10cSrcweir             retValue = m_pMyShell->ls( nMyCommandIdentifier,
1051cdf0e10cSrcweir                                        m_aUncPath,
1052cdf0e10cSrcweir                                        aCommandArgument.Mode,
1053cdf0e10cSrcweir                                        aCommandArgument.Properties,
1054cdf0e10cSrcweir                                        aCommandArgument.SortingInfo );
1055cdf0e10cSrcweir         }
1056cdf0e10cSrcweir //          else if(  aCommandArgument.Mode ==
1057cdf0e10cSrcweir //                    OpenMode::DOCUMENT_SHARE_DENY_NONE ||
1058cdf0e10cSrcweir //                    aCommandArgument.Mode ==
1059cdf0e10cSrcweir //                    OpenMode::DOCUMENT_SHARE_DENY_WRITE )
1060cdf0e10cSrcweir //              m_pMyShell->installError( nMyCommandIdentifier,
1061cdf0e10cSrcweir //                                        TASKHANDLING_UNSUPPORTED_OPEN_MODE,
1062cdf0e10cSrcweir //                                        aCommandArgument.Mode);
1063cdf0e10cSrcweir         else
1064cdf0e10cSrcweir             m_pMyShell->installError( nMyCommandIdentifier,
1065cdf0e10cSrcweir                                       TASKHANDLING_UNSUPPORTED_OPEN_MODE,
1066cdf0e10cSrcweir                                       aCommandArgument.Mode);
1067cdf0e10cSrcweir     }
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir     return retValue;
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir void SAL_CALL
deleteContent(sal_Int32 nMyCommandIdentifier)1075cdf0e10cSrcweir BaseContent::deleteContent( sal_Int32 nMyCommandIdentifier )
1076cdf0e10cSrcweir     throw()
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir     if( m_nState & Deleted )
1079cdf0e10cSrcweir         return;
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir     if( m_pMyShell->remove( nMyCommandIdentifier,m_aUncPath ) )
1082cdf0e10cSrcweir     {
1083cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
1084cdf0e10cSrcweir         m_nState |= Deleted;
1085cdf0e10cSrcweir     }
1086cdf0e10cSrcweir }
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir void SAL_CALL
transfer(sal_Int32 nMyCommandIdentifier,const TransferInfo & aTransferInfo)1091cdf0e10cSrcweir BaseContent::transfer( sal_Int32 nMyCommandIdentifier,
1092cdf0e10cSrcweir                        const TransferInfo& aTransferInfo )
1093cdf0e10cSrcweir     throw()
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir     if( m_nState & Deleted )
1096cdf0e10cSrcweir         return;
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir     if( aTransferInfo.SourceURL.compareToAscii( "file:",5 ) != 0 )
1099cdf0e10cSrcweir     {
1100cdf0e10cSrcweir         m_pMyShell->installError( nMyCommandIdentifier,
1101cdf0e10cSrcweir                                   TASKHANDLING_TRANSFER_INVALIDSCHEME );
1102cdf0e10cSrcweir         return;
1103cdf0e10cSrcweir     }
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir     rtl::OUString srcUnc;
1106cdf0e10cSrcweir     if( m_pMyShell->getUnqFromUrl( aTransferInfo.SourceURL,srcUnc ) )
1107cdf0e10cSrcweir     {
1108cdf0e10cSrcweir         m_pMyShell->installError( nMyCommandIdentifier,
1109cdf0e10cSrcweir                                   TASKHANDLING_TRANSFER_INVALIDURL );
1110cdf0e10cSrcweir         return;
1111cdf0e10cSrcweir     }
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir     rtl::OUString srcUncPath = srcUnc;
1114cdf0e10cSrcweir 
1115cdf0e10cSrcweir     // Determine the new title !
1116cdf0e10cSrcweir     rtl::OUString NewTitle;
1117cdf0e10cSrcweir     if( aTransferInfo.NewTitle.getLength() )
1118cdf0e10cSrcweir         NewTitle = rtl::Uri::encode( aTransferInfo.NewTitle,
1119cdf0e10cSrcweir                                      rtl_UriCharClassPchar,
1120cdf0e10cSrcweir                                      rtl_UriEncodeIgnoreEscapes,
1121cdf0e10cSrcweir                                      RTL_TEXTENCODING_UTF8 );
1122cdf0e10cSrcweir     else
1123cdf0e10cSrcweir         NewTitle = srcUncPath.copy( 1 + srcUncPath.lastIndexOf( sal_Unicode('/') ) );
1124cdf0e10cSrcweir 
1125cdf0e10cSrcweir     // Is destination a document or a folder ?
1126cdf0e10cSrcweir     Sequence< beans::Property > seq(1);
1127cdf0e10cSrcweir     seq[0] = beans::Property( rtl::OUString::createFromAscii("IsDocument"),
1128cdf0e10cSrcweir                               -1,
1129cdf0e10cSrcweir                               getCppuType( static_cast< sal_Bool* >(0) ),
1130cdf0e10cSrcweir                               0 );
1131cdf0e10cSrcweir     Reference< sdbc::XRow > xRow = getPropertyValues( nMyCommandIdentifier,seq );
1132cdf0e10cSrcweir     sal_Bool IsDocument = xRow->getBoolean( 1 );
1133cdf0e10cSrcweir     if( xRow->wasNull() )
1134cdf0e10cSrcweir     {   // Destination file type could not be determined
1135cdf0e10cSrcweir         m_pMyShell->installError( nMyCommandIdentifier,
1136cdf0e10cSrcweir                                   TASKHANDLING_TRANSFER_DESTFILETYPE );
1137cdf0e10cSrcweir         return;
1138cdf0e10cSrcweir     }
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir     rtl::OUString dstUncPath;
1141cdf0e10cSrcweir     if( IsDocument )
1142cdf0e10cSrcweir     {   // as sibling
1143cdf0e10cSrcweir         sal_Int32 lastSlash = m_aUncPath.lastIndexOf( sal_Unicode('/') );
1144cdf0e10cSrcweir         dstUncPath = m_aUncPath.copy(0,lastSlash );
1145cdf0e10cSrcweir     }
1146cdf0e10cSrcweir     else
1147cdf0e10cSrcweir         // as child
1148cdf0e10cSrcweir         dstUncPath = m_aUncPath;
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir     dstUncPath += ( rtl::OUString::createFromAscii( "/" ) + NewTitle );
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir     sal_Int32 NameClash = aTransferInfo.NameClash;
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir     if( aTransferInfo.MoveData )
1155cdf0e10cSrcweir         m_pMyShell->move( nMyCommandIdentifier,srcUncPath,dstUncPath,NameClash );
1156cdf0e10cSrcweir     else
1157cdf0e10cSrcweir         m_pMyShell->copy( nMyCommandIdentifier,srcUncPath,dstUncPath,NameClash );
1158cdf0e10cSrcweir }
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 
insert(sal_Int32 nMyCommandIdentifier,const InsertCommandArgument & aInsertArgument)1163cdf0e10cSrcweir void SAL_CALL BaseContent::insert( sal_Int32 nMyCommandIdentifier,
1164cdf0e10cSrcweir                                    const InsertCommandArgument& aInsertArgument )
1165cdf0e10cSrcweir     throw()
1166cdf0e10cSrcweir {
1167cdf0e10cSrcweir     if( m_nState & FullFeatured )
1168cdf0e10cSrcweir     {
1169cdf0e10cSrcweir         m_pMyShell->write( nMyCommandIdentifier,
1170cdf0e10cSrcweir                            m_aUncPath,
1171cdf0e10cSrcweir                            aInsertArgument.ReplaceExisting,
1172cdf0e10cSrcweir                            aInsertArgument.Data );
1173cdf0e10cSrcweir         return;
1174cdf0e10cSrcweir     }
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir     if( ! ( m_nState & JustInserted ) )
1177cdf0e10cSrcweir     {
1178cdf0e10cSrcweir         m_pMyShell->installError( nMyCommandIdentifier,
1179cdf0e10cSrcweir                                   TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND );
1180cdf0e10cSrcweir         return;
1181cdf0e10cSrcweir     }
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir     // Inserts the content, which has the flag m_bIsFresh
1184cdf0e10cSrcweir 
118547e5fad4SPedro Giffuni     if ( !m_nState | !NameForInsertionSet )
1186cdf0e10cSrcweir     {
1187cdf0e10cSrcweir         m_pMyShell->installError( nMyCommandIdentifier,
1188cdf0e10cSrcweir                                   TASKHANDLING_NONAMESET_INSERT_COMMAND );
1189cdf0e10cSrcweir         return;
1190cdf0e10cSrcweir     }
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir     // Inserting a document or a file?
1193cdf0e10cSrcweir     sal_Bool bDocument = false;
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir     Sequence< beans::Property > seq(1);
1196cdf0e10cSrcweir     seq[0] = beans::Property( rtl::OUString::createFromAscii("IsDocument"),
1197cdf0e10cSrcweir                               -1,
1198cdf0e10cSrcweir                               getCppuType( static_cast< sal_Bool* >(0) ),
1199cdf0e10cSrcweir                               0 );
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir     Reference< sdbc::XRow > xRow = getPropertyValues( -1,seq );
1202cdf0e10cSrcweir 
1203cdf0e10cSrcweir     bool contentTypeSet = true; // is set to false, if contentType not set
1204cdf0e10cSrcweir     try
1205cdf0e10cSrcweir     {
1206cdf0e10cSrcweir         bDocument = xRow->getBoolean( 1 );
1207cdf0e10cSrcweir         if( xRow->wasNull() )
1208cdf0e10cSrcweir             contentTypeSet = false;
1209cdf0e10cSrcweir 
1210cdf0e10cSrcweir     }
1211cdf0e10cSrcweir     catch ( sdbc::SQLException const & )
1212cdf0e10cSrcweir     {
1213cdf0e10cSrcweir         OSL_ENSURE( false,
1214cdf0e10cSrcweir                     "BaseContent::insert - Caught SQLException!" );
1215cdf0e10cSrcweir         contentTypeSet = false;
1216cdf0e10cSrcweir     }
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir     if( ! contentTypeSet )
1219cdf0e10cSrcweir     {
1220cdf0e10cSrcweir         m_pMyShell->installError( nMyCommandIdentifier,
1221cdf0e10cSrcweir                                   TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND );
1222cdf0e10cSrcweir         return;
1223cdf0e10cSrcweir     }
1224cdf0e10cSrcweir 
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir     sal_Bool success = false;
1227cdf0e10cSrcweir     if( bDocument )
1228cdf0e10cSrcweir         success = m_pMyShell->mkfil( nMyCommandIdentifier,
1229cdf0e10cSrcweir                                      m_aUncPath,
1230cdf0e10cSrcweir                                      aInsertArgument.ReplaceExisting,
1231cdf0e10cSrcweir                                      aInsertArgument.Data );
1232cdf0e10cSrcweir     else
1233cdf0e10cSrcweir     {
1234cdf0e10cSrcweir         while( ! success )
1235cdf0e10cSrcweir         {
1236cdf0e10cSrcweir             success = m_pMyShell->mkdir( nMyCommandIdentifier,
1237cdf0e10cSrcweir                                          m_aUncPath,
1238cdf0e10cSrcweir                                          aInsertArgument.ReplaceExisting );
1239cdf0e10cSrcweir             if( success )
1240cdf0e10cSrcweir                 break;
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir             XInteractionRequestImpl *aRequestImpl =
1243cdf0e10cSrcweir                 new XInteractionRequestImpl(
1244cdf0e10cSrcweir                     rtl::Uri::decode(
1245cdf0e10cSrcweir                         getTitle(m_aUncPath),
1246cdf0e10cSrcweir                         rtl_UriDecodeWithCharset,
1247cdf0e10cSrcweir                         RTL_TEXTENCODING_UTF8),
1248cdf0e10cSrcweir                     (cppu::OWeakObject*)this,
1249cdf0e10cSrcweir                     m_pMyShell,nMyCommandIdentifier);
1250cdf0e10cSrcweir             uno::Reference< task::XInteractionRequest > aReq( aRequestImpl );
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir             m_pMyShell->handleTask( nMyCommandIdentifier,aReq );
1253cdf0e10cSrcweir             if(  aRequestImpl->aborted() ||
1254cdf0e10cSrcweir                  !aRequestImpl->newName().getLength() )
1255cdf0e10cSrcweir                 // means aborting
1256cdf0e10cSrcweir                 break;
1257cdf0e10cSrcweir 
1258cdf0e10cSrcweir             // determine new uncpath
1259cdf0e10cSrcweir             m_pMyShell->clearError( nMyCommandIdentifier );
1260cdf0e10cSrcweir             m_aUncPath = getParentName( m_aUncPath );
1261cdf0e10cSrcweir             if( m_aUncPath.lastIndexOf( sal_Unicode('/') ) != m_aUncPath.getLength() - 1 )
1262cdf0e10cSrcweir                 m_aUncPath += rtl::OUString::createFromAscii("/");
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir             m_aUncPath += rtl::Uri::encode( aRequestImpl->newName(),
1265cdf0e10cSrcweir                                             rtl_UriCharClassPchar,
1266cdf0e10cSrcweir                                             rtl_UriEncodeIgnoreEscapes,
1267cdf0e10cSrcweir                                             RTL_TEXTENCODING_UTF8 );
1268cdf0e10cSrcweir         }
1269cdf0e10cSrcweir     }
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir     if ( ! success )
1272cdf0e10cSrcweir         return;
1273cdf0e10cSrcweir 
1274cdf0e10cSrcweir     FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,m_aUncPath );
1275cdf0e10cSrcweir     m_xContentIdentifier = Reference< XContentIdentifier >( p );
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir     m_pMyShell->registerNotifier( m_aUncPath,this );
1278cdf0e10cSrcweir     m_pMyShell->insertDefaultProperties( m_aUncPath );
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
1281cdf0e10cSrcweir     m_nState = FullFeatured;
1282cdf0e10cSrcweir }
1283cdf0e10cSrcweir 
1284cdf0e10cSrcweir 
1285cdf0e10cSrcweir 
endTask(sal_Int32 CommandId)1286cdf0e10cSrcweir void SAL_CALL BaseContent::endTask( sal_Int32 CommandId )
1287cdf0e10cSrcweir {
1288cdf0e10cSrcweir     // This is the only function allowed to throw an exception
1289cdf0e10cSrcweir     m_pMyShell->endTask( CommandId,m_aUncPath,this );
1290cdf0e10cSrcweir }
1291cdf0e10cSrcweir 
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir ContentEventNotifier*
cDEL(void)1295cdf0e10cSrcweir BaseContent::cDEL( void )
1296cdf0e10cSrcweir {
1297cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
1298cdf0e10cSrcweir 
1299cdf0e10cSrcweir     m_nState |= Deleted;
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir     ContentEventNotifier* p;
1302cdf0e10cSrcweir     if( m_pContentEventListeners )
1303cdf0e10cSrcweir         p = new ContentEventNotifier( m_pMyShell,
1304cdf0e10cSrcweir                                       this,
1305cdf0e10cSrcweir                                       m_xContentIdentifier,
1306cdf0e10cSrcweir                                       m_pContentEventListeners->getElements() );
1307cdf0e10cSrcweir     else
1308cdf0e10cSrcweir         p = 0;
1309cdf0e10cSrcweir 
1310cdf0e10cSrcweir     return p;
1311cdf0e10cSrcweir }
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir ContentEventNotifier*
cEXC(const rtl::OUString aNewName)1315cdf0e10cSrcweir BaseContent::cEXC( const rtl::OUString aNewName )
1316cdf0e10cSrcweir {
1317cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir     Reference< XContentIdentifier > xOldRef = m_xContentIdentifier;
1320cdf0e10cSrcweir     m_aUncPath = aNewName;
1321cdf0e10cSrcweir     FileContentIdentifier* pp = new FileContentIdentifier( m_pMyShell,aNewName );
1322cdf0e10cSrcweir     m_xContentIdentifier = Reference< XContentIdentifier >( pp );
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir     ContentEventNotifier* p = 0;
1325cdf0e10cSrcweir     if( m_pContentEventListeners )
1326cdf0e10cSrcweir         p = new ContentEventNotifier( m_pMyShell,
1327cdf0e10cSrcweir                                       this,
1328cdf0e10cSrcweir                                       m_xContentIdentifier,
1329cdf0e10cSrcweir                                       xOldRef,
1330cdf0e10cSrcweir                                       m_pContentEventListeners->getElements() );
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir     return p;
1333cdf0e10cSrcweir }
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir ContentEventNotifier*
cCEL(void)1337cdf0e10cSrcweir BaseContent::cCEL( void )
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
1340cdf0e10cSrcweir     ContentEventNotifier* p = 0;
1341cdf0e10cSrcweir     if( m_pContentEventListeners )
1342cdf0e10cSrcweir         p = new ContentEventNotifier( m_pMyShell,
1343cdf0e10cSrcweir                                       this,
1344cdf0e10cSrcweir                                       m_xContentIdentifier,
1345cdf0e10cSrcweir                                       m_pContentEventListeners->getElements() );
1346cdf0e10cSrcweir 
1347cdf0e10cSrcweir     return p;
1348cdf0e10cSrcweir }
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir PropertySetInfoChangeNotifier*
cPSL(void)1351cdf0e10cSrcweir BaseContent::cPSL( void )
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
1354cdf0e10cSrcweir     PropertySetInfoChangeNotifier* p = 0;
1355cdf0e10cSrcweir     if( m_pPropertySetInfoChangeListeners )
1356cdf0e10cSrcweir         p = new PropertySetInfoChangeNotifier( m_pMyShell,
1357cdf0e10cSrcweir                                                this,
1358cdf0e10cSrcweir                                                m_xContentIdentifier,
1359cdf0e10cSrcweir                                                m_pPropertySetInfoChangeListeners->getElements() );
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir     return p;
1362cdf0e10cSrcweir }
1363cdf0e10cSrcweir 
1364cdf0e10cSrcweir 
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir PropertyChangeNotifier*
cPCL(void)1367cdf0e10cSrcweir BaseContent::cPCL( void )
1368cdf0e10cSrcweir {
1369cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
1370cdf0e10cSrcweir 
1371cdf0e10cSrcweir     Sequence< rtl::OUString > seqNames;
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir     if( m_pPropertyListener )
1374cdf0e10cSrcweir         seqNames = m_pPropertyListener->getContainedTypes();
1375cdf0e10cSrcweir 
1376cdf0e10cSrcweir     PropertyChangeNotifier* p = 0;
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir     sal_Int32 length = seqNames.getLength();
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir     if( length )
1381cdf0e10cSrcweir     {
1382cdf0e10cSrcweir         ListenerMap* listener = new ListenerMap();
1383cdf0e10cSrcweir         for( sal_Int32 i = 0; i < length; ++i )
1384cdf0e10cSrcweir         {
1385cdf0e10cSrcweir             (*listener)[seqNames[i]] = m_pPropertyListener->getContainer( seqNames[i] )->getElements();
1386cdf0e10cSrcweir         }
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir         p = new PropertyChangeNotifier( m_pMyShell,
1389cdf0e10cSrcweir                                         this,
1390cdf0e10cSrcweir                                         m_xContentIdentifier,
1391cdf0e10cSrcweir                                         listener );
1392cdf0e10cSrcweir     }
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir     return p;
1395cdf0e10cSrcweir }
1396cdf0e10cSrcweir 
1397cdf0e10cSrcweir 
getKey(void)1398cdf0e10cSrcweir rtl::OUString BaseContent::getKey( void )
1399cdf0e10cSrcweir {
1400cdf0e10cSrcweir     return m_aUncPath;
1401cdf0e10cSrcweir }
1402*88c764bfSmseidel 
1403*88c764bfSmseidel /* vim: set noet sw=4 ts=4: */
1404