1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <rtl/uri.hxx>
21 #include <rtl/ustrbuf.hxx>
22 #include <osl/file.hxx>
24 #include "osl/diagnose.h"
25 #include <com/sun/star/ucb/OpenMode.hpp>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/ucb/XProgressHandler.hpp>
28 #include <com/sun/star/task/XInteractionHandler.hpp>
29 #include <com/sun/star/io/XActiveDataStreamer.hpp>
30 #include <com/sun/star/io/XOutputStream.hpp>
31 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
32 #include <com/sun/star/io/XActiveDataSink.hpp>
33 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
34 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
35 #include <com/sun/star/ucb/ContentAction.hpp>
36 #include <com/sun/star/ucb/NameClash.hpp>
37 #include "filglob.hxx"
42 #include "filerror.hxx"
43 #include "filinsreq.hxx"
46 using namespace fileaccess
;
47 using namespace com::sun::star
;
48 using namespace com::sun::star::uno
;
49 using namespace com::sun::star::ucb
;
54 typedef cppu::OMultiTypeInterfaceContainerHelperVar
< OUString
,hashOUString
,equalOUString
>
55 PropertyListeners_impl
;
57 class fileaccess::PropertyListeners
58 : public PropertyListeners_impl
61 PropertyListeners( ::osl::Mutex
& aMutex
)
62 : PropertyListeners_impl( aMutex
)
68 /****************************************************************************************/
72 /****************************************************************************************/
74 ////////////////////////////////////////////////////////////////////////////////
75 // Private Constructor for just inserted Contents
77 BaseContent::BaseContent( shell
* pMyShell
,
78 const OUString
& parentName
,
80 : m_pMyShell( pMyShell
),
81 m_xContentIdentifier( 0 ),
82 m_aUncPath( parentName
),
84 m_nState( JustInserted
),
85 m_pDisposeEventListeners( 0 ),
86 m_pContentEventListeners( 0 ),
87 m_pPropertySetInfoChangeListeners( 0 ),
88 m_pPropertyListener( 0 )
90 m_pMyShell
->m_pProvider
->acquire();
91 // No registering, since we have no name
95 ////////////////////////////////////////////////////////////////////////////////
96 // Constructor for full featured Contents
98 BaseContent::BaseContent( shell
* pMyShell
,
99 const Reference
< XContentIdentifier
>& xContentIdentifier
,
100 const OUString
& aUncPath
)
101 : m_pMyShell( pMyShell
),
102 m_xContentIdentifier( xContentIdentifier
),
103 m_aUncPath( aUncPath
),
105 m_nState( FullFeatured
),
106 m_pDisposeEventListeners( 0 ),
107 m_pContentEventListeners( 0 ),
108 m_pPropertySetInfoChangeListeners( 0 ),
109 m_pPropertyListener( 0 )
111 m_pMyShell
->m_pProvider
->acquire();
112 m_pMyShell
->registerNotifier( m_aUncPath
,this );
113 m_pMyShell
->insertDefaultProperties( m_aUncPath
);
117 BaseContent::~BaseContent( )
119 if( ( m_nState
& FullFeatured
) || ( m_nState
& Deleted
) )
121 m_pMyShell
->deregisterNotifier( m_aUncPath
,this );
123 m_pMyShell
->m_pProvider
->release();
125 delete m_pDisposeEventListeners
;
126 delete m_pContentEventListeners
;
127 delete m_pPropertyListener
;
128 delete m_pPropertySetInfoChangeListeners
;
132 //////////////////////////////////////////////////////////////////////////
134 //////////////////////////////////////////////////////////////////////////
137 BaseContent::acquire( void )
140 OWeakObject::acquire();
145 BaseContent::release( void )
148 OWeakObject::release();
153 BaseContent::queryInterface( const Type
& rType
)
154 throw( RuntimeException
)
156 Any aRet
= cppu::queryInterface( rType
,
157 (static_cast< lang::XComponent
* >(this)),
158 (static_cast< lang::XTypeProvider
* >(this)),
159 (static_cast< lang::XServiceInfo
* >(this)),
160 (static_cast< XCommandProcessor
* >(this)),
161 (static_cast< container::XChild
* >(this)),
162 (static_cast< beans::XPropertiesChangeNotifier
* >(this)),
163 (static_cast< beans::XPropertyContainer
* >(this)),
164 (static_cast< XContentCreator
* >(this)),
165 (static_cast< beans::XPropertySetInfoChangeNotifier
* >(this)),
166 (static_cast< XContent
* >(this)) );
167 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
173 //////////////////////////////////////////////////////////////////////////////////////////
175 ////////////////////////////////////////////////////////////////////////////////////////
178 BaseContent::addEventListener( const Reference
< lang::XEventListener
>& Listener
)
179 throw( RuntimeException
)
181 osl::MutexGuard
aGuard( m_aMutex
);
183 if ( ! m_pDisposeEventListeners
)
184 m_pDisposeEventListeners
=
185 new cppu::OInterfaceContainerHelper( m_aEventListenerMutex
);
187 m_pDisposeEventListeners
->addInterface( Listener
);
192 BaseContent::removeEventListener( const Reference
< lang::XEventListener
>& Listener
)
193 throw( RuntimeException
)
195 osl::MutexGuard
aGuard( m_aMutex
);
197 if ( m_pDisposeEventListeners
)
198 m_pDisposeEventListeners
->removeInterface( Listener
);
203 BaseContent::dispose()
204 throw( RuntimeException
)
206 lang::EventObject aEvt
;
207 cppu::OInterfaceContainerHelper
* pDisposeEventListeners
;
208 cppu::OInterfaceContainerHelper
* pContentEventListeners
;
209 cppu::OInterfaceContainerHelper
* pPropertySetInfoChangeListeners
;
210 PropertyListeners
* pPropertyListener
;
213 osl::MutexGuard
aGuard( m_aMutex
);
214 aEvt
.Source
= static_cast< XContent
* >( this );
217 pDisposeEventListeners
=
218 m_pDisposeEventListeners
, m_pDisposeEventListeners
= 0;
220 pContentEventListeners
=
221 m_pContentEventListeners
, m_pContentEventListeners
= 0;
223 pPropertySetInfoChangeListeners
=
224 m_pPropertySetInfoChangeListeners
,
225 m_pPropertySetInfoChangeListeners
= 0;
228 m_pPropertyListener
, m_pPropertyListener
= 0;
231 if ( pDisposeEventListeners
&& pDisposeEventListeners
->getLength() )
232 pDisposeEventListeners
->disposeAndClear( aEvt
);
234 if ( pContentEventListeners
&& pContentEventListeners
->getLength() )
235 pContentEventListeners
->disposeAndClear( aEvt
);
237 if( pPropertyListener
)
238 pPropertyListener
->disposeAndClear( aEvt
);
240 if( pPropertySetInfoChangeListeners
)
241 pPropertySetInfoChangeListeners
->disposeAndClear( aEvt
);
243 delete pDisposeEventListeners
;
244 delete pContentEventListeners
;
245 delete pPropertyListener
;
246 delete pPropertySetInfoChangeListeners
;
251 //////////////////////////////////////////////////////////////////////////////////////////
253 //////////////////////////////////////////////////////////////////////////////////////////
256 BaseContent::getImplementationName()
257 throw( RuntimeException
)
259 return OUString("com.sun.star.comp.ucb.FileContent");
265 BaseContent::supportsService( const OUString
& ServiceName
)
266 throw( RuntimeException
)
268 if ( ServiceName
== "com.sun.star.ucb.FileContent" )
276 Sequence
< OUString
> SAL_CALL
277 BaseContent::getSupportedServiceNames()
278 throw( RuntimeException
)
280 Sequence
< OUString
> ret( 1 );
281 ret
[0] = "com.sun.star.ucb.FileContent";
287 //////////////////////////////////////////////////////////////////////////////////////////
289 //////////////////////////////////////////////////////////////////////////////////////////
291 XTYPEPROVIDER_IMPL_10( BaseContent
,
299 beans::XPropertiesChangeNotifier
,
300 beans::XPropertyContainer
,
301 beans::XPropertySetInfoChangeNotifier
)
304 //////////////////////////////////////////////////////////////////////////////////////////
306 //////////////////////////////////////////////////////////////////////////////////////////
309 BaseContent::createCommandIdentifier( void )
310 throw( RuntimeException
)
312 return m_pMyShell
->getCommandId();
317 BaseContent::abort( sal_Int32 CommandId
)
318 throw( RuntimeException
)
320 m_pMyShell
->abort( CommandId
);
325 BaseContent::execute( const Command
& aCommand
,
327 const Reference
< XCommandEnvironment
>& Environment
)
329 CommandAbortedException
,
333 // A Command with commandid zero cannot be aborted
334 CommandId
= createCommandIdentifier();
336 m_pMyShell
->startTask( CommandId
,
341 if (aCommand
.Name
== "getPropertySetInfo") // No exceptions
343 aAny
<<= getPropertySetInfo( CommandId
);
345 else if (aCommand
.Name
== "getCommandInfo") // no exceptions
347 aAny
<<= getCommandInfo();
349 else if ( aCommand
.Name
== "setPropertyValues" )
351 Sequence
< beans::PropertyValue
> sPropertyValues
;
353 if( ! ( aCommand
.Argument
>>= sPropertyValues
) )
354 m_pMyShell
->installError( CommandId
,
355 TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT
);
357 aAny
<<= setPropertyValues( CommandId
,sPropertyValues
); // calls endTask by itself
359 else if ( aCommand
.Name
== "getPropertyValues" )
361 Sequence
< beans::Property
> ListOfRequestedProperties
;
363 if( ! ( aCommand
.Argument
>>= ListOfRequestedProperties
) )
364 m_pMyShell
->installError( CommandId
,
365 TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT
);
367 aAny
<<= getPropertyValues( CommandId
,
368 ListOfRequestedProperties
);
370 else if ( aCommand
.Name
== "open" )
372 OpenCommandArgument2 aOpenArgument
;
373 if( ! ( aCommand
.Argument
>>= aOpenArgument
) )
374 m_pMyShell
->installError( CommandId
,
375 TASKHANDLING_WRONG_OPEN_ARGUMENT
);
378 Reference
< XDynamicResultSet
> result
= open( CommandId
,aOpenArgument
);
383 else if ( aCommand
.Name
== "delete" )
385 if( ! aCommand
.Argument
.has
< sal_Bool
>() )
386 m_pMyShell
->installError( CommandId
,
387 TASKHANDLING_WRONG_DELETE_ARGUMENT
);
389 deleteContent( CommandId
);
391 else if ( aCommand
.Name
== "transfer" )
393 TransferInfo aTransferInfo
;
394 if( ! ( aCommand
.Argument
>>= aTransferInfo
) )
395 m_pMyShell
->installError( CommandId
,
396 TASKHANDLING_WRONG_TRANSFER_ARGUMENT
);
398 transfer( CommandId
, aTransferInfo
);
400 else if ( aCommand
.Name
== "insert" )
402 InsertCommandArgument aInsertArgument
;
403 if( ! ( aCommand
.Argument
>>= aInsertArgument
) )
404 m_pMyShell
->installError( CommandId
,
405 TASKHANDLING_WRONG_INSERT_ARGUMENT
);
407 insert( CommandId
,aInsertArgument
);
409 else if ( aCommand
.Name
== "getCasePreservingURL" )
411 Sequence
< beans::Property
> seq(1);
412 seq
[0] = beans::Property(
413 OUString("CasePreservingURL"),
415 getCppuType( static_cast< sal_Bool
* >(0) ),
417 Reference
< sdbc::XRow
> xRow
= getPropertyValues( CommandId
,seq
);
418 OUString CasePreservingURL
= xRow
->getString(1);
420 aAny
<<= CasePreservingURL
;
422 else if ( aCommand
.Name
== "createNewContent" )
424 ucb::ContentInfo aArg
;
425 if ( !( aCommand
.Argument
>>= aArg
) )
426 m_pMyShell
->installError( CommandId
,
427 TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT
);
429 aAny
<<= createNewContent( aArg
);
432 m_pMyShell
->installError( CommandId
,
433 TASKHANDLER_UNSUPPORTED_COMMAND
);
436 // This is the only function allowed to throw an exception
437 endTask( CommandId
);
445 BaseContent::addPropertiesChangeListener(
446 const Sequence
< OUString
>& PropertyNames
,
447 const Reference
< beans::XPropertiesChangeListener
>& Listener
)
448 throw( RuntimeException
)
450 if( ! Listener
.is() )
453 osl::MutexGuard
aGuard( m_aMutex
);
455 if( ! m_pPropertyListener
)
456 m_pPropertyListener
= new PropertyListeners( m_aEventListenerMutex
);
459 if( PropertyNames
.getLength() == 0 )
460 m_pPropertyListener
->addInterface( OUString(),Listener
);
463 Reference
< beans::XPropertySetInfo
> xProp
= m_pMyShell
->info_p( m_aUncPath
);
464 for( sal_Int32 i
= 0; i
< PropertyNames
.getLength(); ++i
)
465 if( xProp
->hasPropertyByName( PropertyNames
[i
] ) )
466 m_pPropertyListener
->addInterface( PropertyNames
[i
],Listener
);
472 BaseContent::removePropertiesChangeListener( const Sequence
< OUString
>& PropertyNames
,
473 const Reference
< beans::XPropertiesChangeListener
>& Listener
)
474 throw( RuntimeException
)
476 if( ! Listener
.is() )
479 osl::MutexGuard
aGuard( m_aMutex
);
481 if( ! m_pPropertyListener
)
484 for( sal_Int32 i
= 0; i
< PropertyNames
.getLength(); ++i
)
485 m_pPropertyListener
->removeInterface( PropertyNames
[i
],Listener
);
487 m_pPropertyListener
->removeInterface( OUString(), Listener
);
491 /////////////////////////////////////////////////////////////////////////////////////////
493 /////////////////////////////////////////////////////////////////////////////////////////
495 Reference
< ucb::XContentIdentifier
> SAL_CALL
496 BaseContent::getIdentifier()
497 throw( RuntimeException
)
499 return m_xContentIdentifier
;
504 BaseContent::getContentType()
505 throw( RuntimeException
)
507 if( !( m_nState
& Deleted
) )
509 if( m_nState
& JustInserted
)
512 return m_pMyShell
->FolderContentType
;
514 return m_pMyShell
->FileContentType
;
521 Sequence
< beans::Property
> seq(1);
522 seq
[0] = beans::Property( OUString("IsDocument"),
524 getCppuType( static_cast< sal_Bool
* >(0) ),
526 Reference
< sdbc::XRow
> xRow
= getPropertyValues( -1,seq
);
527 sal_Bool IsDocument
= xRow
->getBoolean( 1 );
529 if ( !xRow
->wasNull() )
532 return m_pMyShell
->FileContentType
;
534 return m_pMyShell
->FolderContentType
;
538 OSL_FAIL( "BaseContent::getContentType - Property value was null!" );
541 catch (const sdbc::SQLException
&)
543 OSL_FAIL( "BaseContent::getContentType - Caught SQLException!" );
554 BaseContent::addContentEventListener(
555 const Reference
< XContentEventListener
>& Listener
)
556 throw( RuntimeException
)
558 osl::MutexGuard
aGuard( m_aMutex
);
560 if ( ! m_pContentEventListeners
)
561 m_pContentEventListeners
=
562 new cppu::OInterfaceContainerHelper( m_aEventListenerMutex
);
565 m_pContentEventListeners
->addInterface( Listener
);
570 BaseContent::removeContentEventListener(
571 const Reference
< XContentEventListener
>& Listener
)
572 throw( RuntimeException
)
574 osl::MutexGuard
aGuard( m_aMutex
);
576 if ( m_pContentEventListeners
)
577 m_pContentEventListeners
->removeInterface( Listener
);
582 ////////////////////////////////////////////////////////////////////////////////
583 // XPropertyContainer
584 ////////////////////////////////////////////////////////////////////////////////
588 BaseContent::addProperty(
589 const OUString
& Name
,
590 sal_Int16 Attributes
,
591 const Any
& DefaultValue
)
592 throw( beans::PropertyExistException
,
593 beans::IllegalTypeException
,
594 lang::IllegalArgumentException
,
597 if( ( m_nState
& JustInserted
) || ( m_nState
& Deleted
) || Name
.isEmpty() )
599 throw lang::IllegalArgumentException( OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), 0 );
602 m_pMyShell
->associate( m_aUncPath
,Name
,DefaultValue
,Attributes
);
607 BaseContent::removeProperty(
608 const OUString
& Name
)
609 throw( beans::UnknownPropertyException
,
610 beans::NotRemoveableException
,
614 if( m_nState
& Deleted
)
615 throw beans::UnknownPropertyException( OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>() );
617 m_pMyShell
->deassociate( m_aUncPath
, Name
);
620 ////////////////////////////////////////////////////////////////////////////////
622 ////////////////////////////////////////////////////////////////////////////////
624 Sequence
< ContentInfo
> SAL_CALL
625 BaseContent::queryCreatableContentsInfo(
627 throw( RuntimeException
)
629 return m_pMyShell
->queryCreatableContentsInfo();
633 Reference
< XContent
> SAL_CALL
634 BaseContent::createNewContent(
635 const ContentInfo
& Info
)
636 throw( RuntimeException
)
639 if ( Info
.Type
.isEmpty() )
640 return Reference
< XContent
>();
643 = ( Info
.Type
.compareTo( m_pMyShell
->FolderContentType
) == 0 );
646 if ( Info
.Type
.compareTo( m_pMyShell
->FileContentType
) != 0 )
648 // Neither folder nor file to create!
649 return Reference
< XContent
>();
654 sal_Bool IsDocument
= false;
658 Sequence
< beans::Property
> seq(1);
659 seq
[0] = beans::Property( OUString("IsDocument"),
661 getCppuType( static_cast< sal_Bool
* >(0) ),
663 Reference
< sdbc::XRow
> xRow
= getPropertyValues( -1,seq
);
664 IsDocument
= xRow
->getBoolean( 1 );
666 if ( xRow
->wasNull() )
669 // OSL_FAIL( // "BaseContent::createNewContent - Property value was null!" );
670 // return Reference< XContent >();
673 catch (const sdbc::SQLException
&)
675 OSL_FAIL( "BaseContent::createNewContent - Caught SQLException!" );
676 return Reference
< XContent
>();
683 // KSO: Why is a document a XContentCreator? This is quite unusual.
684 dstUncPath
= getParentName( m_aUncPath
);
687 dstUncPath
= m_aUncPath
;
689 BaseContent
* p
= new BaseContent( m_pMyShell
, dstUncPath
, bFolder
);
690 return Reference
< XContent
>( p
);
694 ////////////////////////////////////////////////////////////////////////////////
695 // XPropertySetInfoChangeNotifier
696 ////////////////////////////////////////////////////////////////////////////////
700 BaseContent::addPropertySetInfoChangeListener(
701 const Reference
< beans::XPropertySetInfoChangeListener
>& Listener
)
702 throw( RuntimeException
)
704 osl::MutexGuard
aGuard( m_aMutex
);
705 if( ! m_pPropertySetInfoChangeListeners
)
706 m_pPropertySetInfoChangeListeners
= new cppu::OInterfaceContainerHelper( m_aEventListenerMutex
);
708 m_pPropertySetInfoChangeListeners
->addInterface( Listener
);
713 BaseContent::removePropertySetInfoChangeListener(
714 const Reference
< beans::XPropertySetInfoChangeListener
>& Listener
)
715 throw( RuntimeException
)
717 osl::MutexGuard
aGuard( m_aMutex
);
719 if( m_pPropertySetInfoChangeListeners
)
720 m_pPropertySetInfoChangeListeners
->removeInterface( Listener
);
724 ////////////////////////////////////////////////////////////////////////////////
726 ////////////////////////////////////////////////////////////////////////////////
728 Reference
< XInterface
> SAL_CALL
729 BaseContent::getParent(
731 throw( RuntimeException
)
733 OUString ParentUnq
= getParentName( m_aUncPath
);
737 sal_Bool err
= m_pMyShell
->getUrlFromUnq( ParentUnq
, ParentUrl
);
739 return Reference
< XInterface
>( 0 );
741 FileContentIdentifier
* p
= new FileContentIdentifier( m_pMyShell
,ParentUnq
);
742 Reference
< XContentIdentifier
> Identifier( p
);
746 return m_pMyShell
->m_pProvider
->queryContent( Identifier
);
748 catch (const IllegalIdentifierException
&)
750 return Reference
< XInterface
>();
756 BaseContent::setParent(
757 const Reference
< XInterface
>& )
758 throw( lang::NoSupportException
,
761 throw lang::NoSupportException( OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>() );
765 //////////////////////////////////////////////////////////////////////////////////////////
767 //////////////////////////////////////////////////////////////////////////////////////////
770 Reference
< XCommandInfo
> SAL_CALL
771 BaseContent::getCommandInfo()
772 throw( RuntimeException
)
774 if( m_nState
& Deleted
)
775 return Reference
< XCommandInfo
>();
777 return m_pMyShell
->info_c();
781 Reference
< beans::XPropertySetInfo
> SAL_CALL
782 BaseContent::getPropertySetInfo(
784 throw( RuntimeException
)
786 if( m_nState
& Deleted
)
787 return Reference
< beans::XPropertySetInfo
>();
789 return m_pMyShell
->info_p( m_aUncPath
);
795 Reference
< sdbc::XRow
> SAL_CALL
796 BaseContent::getPropertyValues(
797 sal_Int32 nMyCommandIdentifier
,
798 const Sequence
< beans::Property
>& PropertySet
)
799 throw( RuntimeException
)
801 sal_Int32 nProps
= PropertySet
.getLength();
803 return Reference
< sdbc::XRow
>();
805 if( m_nState
& Deleted
)
807 Sequence
< Any
> aValues( nProps
);
808 return Reference
< sdbc::XRow
>( new XRow_impl( m_pMyShell
, aValues
) );
811 if( m_nState
& JustInserted
)
813 Sequence
< Any
> aValues( nProps
);
814 Any
* pValues
= aValues
.getArray();
816 const beans::Property
* pProps
= PropertySet
.getConstArray();
818 for ( sal_Int32 n
= 0; n
< nProps
; ++n
)
820 const beans::Property
& rProp
= pProps
[ n
];
821 Any
& rValue
= pValues
[ n
];
823 if ( rProp
.Name
== "ContentType" )
825 rValue
<<= m_bFolder
? m_pMyShell
->FolderContentType
826 : m_pMyShell
->FileContentType
;
828 else if ( rProp
.Name
== "IsFolder" )
830 rValue
<<= m_bFolder
;
832 else if ( rProp
.Name
== "IsDocument" )
834 rValue
<<= sal_Bool( !m_bFolder
);
838 return Reference
< sdbc::XRow
>(
839 new XRow_impl( m_pMyShell
, aValues
) );
842 return m_pMyShell
->getv( nMyCommandIdentifier
,
848 Sequence
< Any
> SAL_CALL
849 BaseContent::setPropertyValues(
850 sal_Int32 nMyCommandIdentifier
,
851 const Sequence
< beans::PropertyValue
>& Values
)
854 if( m_nState
& Deleted
)
856 return Sequence
< Any
>( Values
.getLength() );
859 const OUString
Title("Title");
861 // Special handling for files which have to be inserted
862 if( m_nState
& JustInserted
)
864 for( sal_Int32 i
= 0; i
< Values
.getLength(); ++i
)
866 if( Values
[i
].Name
== Title
)
869 if( Values
[i
].Value
>>= NewTitle
)
871 if ( m_nState
& NameForInsertionSet
)
873 // User wants to set another Title before "insert".
874 // m_aUncPath contains previous own URI.
876 sal_Int32 nLastSlash
= m_aUncPath
.lastIndexOf( '/' );
877 bool bTrailingSlash
= false;
878 if ( nLastSlash
== m_aUncPath
.getLength() - 1 )
880 bTrailingSlash
= true;
882 = m_aUncPath
.lastIndexOf( '/', nLastSlash
);
885 OSL_ENSURE( nLastSlash
!= -1,
886 "BaseContent::setPropertyValues: "
890 m_aUncPath
.copy( 0, nLastSlash
+ 1 ) );
892 if ( !NewTitle
.isEmpty() )
894 aBuf
.append( NewTitle
);
895 if ( bTrailingSlash
)
900 m_nState
&= ~NameForInsertionSet
;
903 m_aUncPath
= aBuf
.makeStringAndClear();
907 if ( !NewTitle
.isEmpty() )
909 // Initial Title before "insert".
910 // m_aUncPath contains parent's URI.
912 if( !m_aUncPath
.endsWith( "/" ) )
915 m_aUncPath
+= rtl::Uri::encode( NewTitle
,
916 rtl_UriCharClassPchar
,
917 rtl_UriEncodeIgnoreEscapes
,
918 RTL_TEXTENCODING_UTF8
);
919 m_nState
|= NameForInsertionSet
;
926 return Sequence
< Any
>( Values
.getLength() );
930 Sequence
< Any
> ret
= m_pMyShell
->setv( m_aUncPath
, // Does not handle Title
933 // Special handling Title: Setting Title is equivalent to a renaming of the underlying file
934 for( sal_Int32 i
= 0; i
< Values
.getLength(); ++i
)
936 if( Values
[i
].Name
!= Title
)
937 continue; // handled by setv
940 if( !( Values
[i
].Value
>>= NewTitle
) )
942 ret
[i
] <<= beans::IllegalTypeException( OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>() );
945 else if( NewTitle
.isEmpty() )
947 ret
[i
] <<= lang::IllegalArgumentException( OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), 0 );
952 OUString aDstName
= getParentName( m_aUncPath
);
953 if( !aDstName
.endsWith("/") )
956 aDstName
+= rtl::Uri::encode( NewTitle
,
957 rtl_UriCharClassPchar
,
958 rtl_UriEncodeIgnoreEscapes
,
959 RTL_TEXTENCODING_UTF8
);
961 m_pMyShell
->move( nMyCommandIdentifier
, // move notifies the children also;
968 endTask( nMyCommandIdentifier
);
970 catch(const Exception
& e
)
975 // NameChanges come back trough a ContentEvent
976 break; // only handling Title
985 Reference
< XDynamicResultSet
> SAL_CALL
987 sal_Int32 nMyCommandIdentifier
,
988 const OpenCommandArgument2
& aCommandArgument
)
991 Reference
< XDynamicResultSet
> retValue( 0 );
993 if( ( m_nState
& Deleted
) )
995 m_pMyShell
->installError( nMyCommandIdentifier
,
996 TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND
);
998 else if( m_nState
& JustInserted
)
1000 m_pMyShell
->installError( nMyCommandIdentifier
,
1001 TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND
);
1005 if( aCommandArgument
.Mode
== OpenMode::DOCUMENT
||
1006 aCommandArgument
.Mode
== OpenMode::DOCUMENT_SHARE_DENY_NONE
)
1009 Reference
< io::XOutputStream
> outputStream( aCommandArgument
.Sink
,UNO_QUERY
);
1010 if( outputStream
.is() )
1012 m_pMyShell
->page( nMyCommandIdentifier
,
1017 sal_Bool bLock
= ( aCommandArgument
.Mode
!= OpenMode::DOCUMENT_SHARE_DENY_NONE
);
1019 Reference
< io::XActiveDataSink
> activeDataSink( aCommandArgument
.Sink
,UNO_QUERY
);
1020 if( activeDataSink
.is() )
1022 activeDataSink
->setInputStream( m_pMyShell
->open( nMyCommandIdentifier
,
1027 Reference
< io::XActiveDataStreamer
> activeDataStreamer( aCommandArgument
.Sink
,UNO_QUERY
);
1028 if( activeDataStreamer
.is() )
1030 activeDataStreamer
->setStream( m_pMyShell
->open_rw( nMyCommandIdentifier
,
1035 else if ( aCommandArgument
.Mode
== OpenMode::ALL
||
1036 aCommandArgument
.Mode
== OpenMode::FOLDERS
||
1037 aCommandArgument
.Mode
== OpenMode::DOCUMENTS
)
1039 retValue
= m_pMyShell
->ls( nMyCommandIdentifier
,
1041 aCommandArgument
.Mode
,
1042 aCommandArgument
.Properties
,
1043 aCommandArgument
.SortingInfo
);
1045 // else if( aCommandArgument.Mode ==
1046 // OpenMode::DOCUMENT_SHARE_DENY_NONE ||
1047 // aCommandArgument.Mode ==
1048 // OpenMode::DOCUMENT_SHARE_DENY_WRITE )
1049 // m_pMyShell->installError( nMyCommandIdentifier,
1050 // TASKHANDLING_UNSUPPORTED_OPEN_MODE,
1051 // aCommandArgument.Mode);
1053 m_pMyShell
->installError( nMyCommandIdentifier
,
1054 TASKHANDLING_UNSUPPORTED_OPEN_MODE
,
1055 aCommandArgument
.Mode
);
1064 BaseContent::deleteContent( sal_Int32 nMyCommandIdentifier
)
1067 if( m_nState
& Deleted
)
1070 if( m_pMyShell
->remove( nMyCommandIdentifier
,m_aUncPath
) )
1072 osl::MutexGuard
aGuard( m_aMutex
);
1073 m_nState
|= Deleted
;
1080 BaseContent::transfer( sal_Int32 nMyCommandIdentifier
,
1081 const TransferInfo
& aTransferInfo
)
1084 if( m_nState
& Deleted
)
1087 if( !aTransferInfo
.SourceURL
.startsWith( "file:" ) )
1089 m_pMyShell
->installError( nMyCommandIdentifier
,
1090 TASKHANDLING_TRANSFER_INVALIDSCHEME
);
1095 if( m_pMyShell
->getUnqFromUrl( aTransferInfo
.SourceURL
,srcUnc
) )
1097 m_pMyShell
->installError( nMyCommandIdentifier
,
1098 TASKHANDLING_TRANSFER_INVALIDURL
);
1102 OUString srcUncPath
= srcUnc
;
1104 // Determine the new title !
1106 if( !aTransferInfo
.NewTitle
.isEmpty() )
1107 NewTitle
= rtl::Uri::encode( aTransferInfo
.NewTitle
,
1108 rtl_UriCharClassPchar
,
1109 rtl_UriEncodeIgnoreEscapes
,
1110 RTL_TEXTENCODING_UTF8
);
1112 NewTitle
= srcUncPath
.copy( 1 + srcUncPath
.lastIndexOf( '/' ) );
1114 // Is destination a document or a folder ?
1115 Sequence
< beans::Property
> seq(1);
1116 seq
[0] = beans::Property( OUString("IsDocument"),
1118 getCppuType( static_cast< sal_Bool
* >(0) ),
1120 Reference
< sdbc::XRow
> xRow
= getPropertyValues( nMyCommandIdentifier
,seq
);
1121 sal_Bool IsDocument
= xRow
->getBoolean( 1 );
1122 if( xRow
->wasNull() )
1123 { // Destination file type could not be determined
1124 m_pMyShell
->installError( nMyCommandIdentifier
,
1125 TASKHANDLING_TRANSFER_DESTFILETYPE
);
1129 OUString dstUncPath
;
1132 sal_Int32 lastSlash
= m_aUncPath
.lastIndexOf( '/' );
1133 dstUncPath
= m_aUncPath
.copy(0,lastSlash
);
1137 dstUncPath
= m_aUncPath
;
1139 dstUncPath
+= ( OUString("/") + NewTitle
);
1141 sal_Int32 NameClash
= aTransferInfo
.NameClash
;
1143 if( aTransferInfo
.MoveData
)
1144 m_pMyShell
->move( nMyCommandIdentifier
,srcUncPath
,dstUncPath
,NameClash
);
1146 m_pMyShell
->copy( nMyCommandIdentifier
,srcUncPath
,dstUncPath
,NameClash
);
1152 void SAL_CALL
BaseContent::insert( sal_Int32 nMyCommandIdentifier
,
1153 const InsertCommandArgument
& aInsertArgument
)
1156 if( m_nState
& FullFeatured
)
1158 m_pMyShell
->write( nMyCommandIdentifier
,
1160 aInsertArgument
.ReplaceExisting
,
1161 aInsertArgument
.Data
);
1165 if( ! ( m_nState
& JustInserted
) )
1167 m_pMyShell
->installError( nMyCommandIdentifier
,
1168 TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND
);
1172 // Inserts the content, which has the flag m_bIsFresh
1174 if( ! (m_nState
& NameForInsertionSet
) )
1176 m_pMyShell
->installError( nMyCommandIdentifier
,
1177 TASKHANDLING_NONAMESET_INSERT_COMMAND
);
1181 // Inserting a document or a file?
1182 sal_Bool bDocument
= false;
1184 Sequence
< beans::Property
> seq(1);
1185 seq
[0] = beans::Property( OUString("IsDocument"),
1187 getCppuType( static_cast< sal_Bool
* >(0) ),
1190 Reference
< sdbc::XRow
> xRow
= getPropertyValues( -1,seq
);
1192 bool contentTypeSet
= true; // is set to false, if contentType not set
1195 bDocument
= xRow
->getBoolean( 1 );
1196 if( xRow
->wasNull() )
1197 contentTypeSet
= false;
1200 catch (const sdbc::SQLException
&)
1202 OSL_FAIL( "BaseContent::insert - Caught SQLException!" );
1203 contentTypeSet
= false;
1206 if( ! contentTypeSet
)
1208 m_pMyShell
->installError( nMyCommandIdentifier
,
1209 TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND
);
1214 sal_Bool success
= false;
1216 success
= m_pMyShell
->mkfil( nMyCommandIdentifier
,
1218 aInsertArgument
.ReplaceExisting
,
1219 aInsertArgument
.Data
);
1224 success
= m_pMyShell
->mkdir( nMyCommandIdentifier
,
1226 aInsertArgument
.ReplaceExisting
);
1230 XInteractionRequestImpl
*aRequestImpl
=
1231 new XInteractionRequestImpl(
1233 getTitle(m_aUncPath
),
1234 rtl_UriDecodeWithCharset
,
1235 RTL_TEXTENCODING_UTF8
),
1236 (cppu::OWeakObject
*)this,
1237 m_pMyShell
,nMyCommandIdentifier
);
1238 uno::Reference
< task::XInteractionRequest
> aReq( aRequestImpl
);
1240 m_pMyShell
->handleTask( nMyCommandIdentifier
,aReq
);
1241 if( aRequestImpl
->aborted() ||
1242 aRequestImpl
->newName().isEmpty() )
1246 // determine new uncpath
1247 m_pMyShell
->clearError( nMyCommandIdentifier
);
1248 m_aUncPath
= getParentName( m_aUncPath
);
1249 if( !m_aUncPath
.endsWith( "/" ) )
1252 m_aUncPath
+= rtl::Uri::encode( aRequestImpl
->newName(),
1253 rtl_UriCharClassPchar
,
1254 rtl_UriEncodeIgnoreEscapes
,
1255 RTL_TEXTENCODING_UTF8
);
1262 FileContentIdentifier
* p
= new FileContentIdentifier( m_pMyShell
,m_aUncPath
);
1263 m_xContentIdentifier
= Reference
< XContentIdentifier
>( p
);
1265 m_pMyShell
->registerNotifier( m_aUncPath
,this );
1266 m_pMyShell
->insertDefaultProperties( m_aUncPath
);
1268 osl::MutexGuard
aGuard( m_aMutex
);
1269 m_nState
= FullFeatured
;
1274 void SAL_CALL
BaseContent::endTask( sal_Int32 CommandId
)
1276 // This is the only function allowed to throw an exception
1277 m_pMyShell
->endTask( CommandId
,m_aUncPath
,this );
1282 ContentEventNotifier
*
1283 BaseContent::cDEL( void )
1285 osl::MutexGuard
aGuard( m_aMutex
);
1287 m_nState
|= Deleted
;
1289 ContentEventNotifier
* p
;
1290 if( m_pContentEventListeners
)
1291 p
= new ContentEventNotifier( m_pMyShell
,
1293 m_xContentIdentifier
,
1294 m_pContentEventListeners
->getElements() );
1302 ContentEventNotifier
*
1303 BaseContent::cEXC( const OUString aNewName
)
1305 osl::MutexGuard
aGuard( m_aMutex
);
1307 Reference
< XContentIdentifier
> xOldRef
= m_xContentIdentifier
;
1308 m_aUncPath
= aNewName
;
1309 FileContentIdentifier
* pp
= new FileContentIdentifier( m_pMyShell
,aNewName
);
1310 m_xContentIdentifier
= Reference
< XContentIdentifier
>( pp
);
1312 ContentEventNotifier
* p
= 0;
1313 if( m_pContentEventListeners
)
1314 p
= new ContentEventNotifier( m_pMyShell
,
1316 m_xContentIdentifier
,
1318 m_pContentEventListeners
->getElements() );
1324 ContentEventNotifier
*
1325 BaseContent::cCEL( void )
1327 osl::MutexGuard
aGuard( m_aMutex
);
1328 ContentEventNotifier
* p
= 0;
1329 if( m_pContentEventListeners
)
1330 p
= new ContentEventNotifier( m_pMyShell
,
1332 m_xContentIdentifier
,
1333 m_pContentEventListeners
->getElements() );
1338 PropertySetInfoChangeNotifier
*
1339 BaseContent::cPSL( void )
1341 osl::MutexGuard
aGuard( m_aMutex
);
1342 PropertySetInfoChangeNotifier
* p
= 0;
1343 if( m_pPropertySetInfoChangeListeners
)
1344 p
= new PropertySetInfoChangeNotifier( this,
1345 m_xContentIdentifier
,
1346 m_pPropertySetInfoChangeListeners
->getElements() );
1353 PropertyChangeNotifier
*
1354 BaseContent::cPCL( void )
1356 osl::MutexGuard
aGuard( m_aMutex
);
1358 Sequence
< OUString
> seqNames
;
1360 if( m_pPropertyListener
)
1361 seqNames
= m_pPropertyListener
->getContainedTypes();
1363 PropertyChangeNotifier
* p
= 0;
1365 sal_Int32 length
= seqNames
.getLength();
1369 ListenerMap
* listener
= new ListenerMap();
1370 for( sal_Int32 i
= 0; i
< length
; ++i
)
1372 (*listener
)[seqNames
[i
]] = m_pPropertyListener
->getContainer( seqNames
[i
] )->getElements();
1375 p
= new PropertyChangeNotifier( this,
1376 m_xContentIdentifier
,
1384 OUString
BaseContent::getKey( void )
1389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */