21#include <rtl/ustrbuf.hxx>
25#include <com/sun/star/lang/NoSupportException.hpp>
26#include <com/sun/star/sdbc/SQLException.hpp>
27#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
28#include <com/sun/star/ucb/OpenMode.hpp>
29#include <com/sun/star/beans/IllegalTypeException.hpp>
30#include <com/sun/star/io/XActiveDataStreamer.hpp>
31#include <com/sun/star/io/XOutputStream.hpp>
32#include <com/sun/star/io/XActiveDataSink.hpp>
33#include <com/sun/star/ucb/NameClash.hpp>
50#if OSL_DEBUG_LEVEL > 0
51#define THROW_WHERE SAL_WHERE
59 std::unordered_map<OUString, ContainerHelper>
m_aMap;
62 void disposeAndClear(std::unique_lock<std::mutex>& rGuard,
const lang::EventObject& rEvt)
65 std::unordered_map<OUString, ContainerHelper> tempMap = std::move(
m_aMap);
66 for (
auto& rPair : tempMap)
67 rPair.second.disposeAndClear(rGuard, rEvt);
69 void addInterface(std::unique_lock<std::mutex>& rGuard,
const OUString& rKey,
const uno::Reference<beans::XPropertiesChangeListener>& rListener)
71 m_aMap[rKey].addInterface(rGuard, rListener);
73 void removeInterface(std::unique_lock<std::mutex>& rGuard,
const OUString& rKey,
const uno::Reference<beans::XPropertiesChangeListener>& rListener)
76 auto iter =
m_aMap.find(rKey);
79 iter->second.removeInterface(rGuard, rListener);
83 std::vector<OUString> aInterfaceTypes;
84 aInterfaceTypes.reserve(
m_aMap.size());
85 for (
const auto& rPair :
m_aMap)
87 if (rPair.second.getLength(rGuard))
89 aInterfaceTypes.push_back(rPair.first);
90 return aInterfaceTypes;
94 auto iter =
m_aMap.find(rKey);
114 : m_pMyShell( pMyShell ),
115 m_aUncPath(
std::move( parentName )),
116 m_bFolder( bFolder ),
117 m_nState( JustInserted )
129 : m_pMyShell( pMyShell ),
130 m_xContentIdentifier( xContentIdentifier ),
131 m_aUncPath(
std::move( aUncPath )),
133 m_nState( FullFeatured )
157 std::unique_lock aGuard(
m_aMutex );
166 std::unique_lock aGuard(
m_aMutex );
175 lang::EventObject aEvt;
176 aEvt.Source =
static_cast< XContent*
>( this );
178 std::unique_lock aGuard(
m_aMutex );
185 if( pPropertyListener )
186 pPropertyListener->disposeAndClear( aGuard, aEvt );
195 return "com.sun.star.comp.ucb.FileContent";
241 if (
aCommand.Name ==
"getPropertySetInfo")
245 else if (
aCommand.Name ==
"getCommandInfo")
249 else if (
aCommand.Name ==
"setPropertyValues" )
253 if( ! (
aCommand.Argument >>= sPropertyValues ) )
259 else if (
aCommand.Name ==
"getPropertyValues" )
263 if( ! (
aCommand.Argument >>= ListOfRequestedProperties ) )
268 ListOfRequestedProperties );
272 OpenCommandArgument2 aOpenArgument;
273 if( ! (
aCommand.Argument >>= aOpenArgument ) )
283 else if (
aCommand.Name ==
"delete" )
285 if( !
aCommand.Argument.has<
bool >() )
291 else if (
aCommand.Name ==
"transfer" )
293 TransferInfo aTransferInfo;
294 if( ! (
aCommand.Argument >>= aTransferInfo ) )
298 transfer( CommandId, aTransferInfo );
300 else if (
aCommand.Name ==
"insert" )
302 InsertCommandArgument aInsertArgument;
303 if( ! (
aCommand.Argument >>= aInsertArgument ) )
307 insert( CommandId,aInsertArgument );
309 else if (
aCommand.Name ==
"getCasePreservingURL" )
316 else if (
aCommand.Name ==
"createNewContent" )
318 ucb::ContentInfo aArg;
319 if ( !(
aCommand.Argument >>= aArg ) )
342 if( ! Listener.is() )
345 std::unique_lock aGuard(
m_aMutex );
351 if( !PropertyNames.hasElements() )
356 for(
const auto& rName : PropertyNames )
357 if( xProp->hasPropertyByName( rName ) )
367 if( ! Listener.is() )
370 std::unique_lock aGuard(
m_aMutex );
375 for(
const auto& rName : PropertyNames )
412 if ( !xRow->wasNull() )
421 OSL_FAIL(
"BaseContent::getContentType - Property value was null!" );
424 catch (
const sdbc::SQLException&)
439 std::unique_lock aGuard(
m_aMutex );
449 std::unique_lock aGuard(
m_aMutex );
460 const OUString& Name,
461 sal_Int16 Attributes,
462 const Any& DefaultValue )
466 throw lang::IllegalArgumentException(
THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
478 throw beans::UnknownPropertyException(
Name );
498 if (
Info.Type.isEmpty() )
519 if ( xRow->wasNull() )
526 catch (
const sdbc::SQLException&)
553 std::unique_lock aGuard(
m_aMutex );
563 std::unique_lock aGuard(
m_aMutex );
589 catch (
const IllegalIdentifierException&)
628 sal_Int32 nMyCommandIdentifier,
631 sal_Int32 nProps = PropertySet.getLength();
646 const beans::Property* pProps = PropertySet.getConstArray();
648 for ( sal_Int32
n = 0;
n < nProps; ++
n )
650 const beans::Property& rProp = pProps[
n ];
653 if ( rProp.Name ==
"ContentType" )
658 else if ( rProp.Name ==
"IsFolder" )
662 else if ( rProp.Name ==
"IsDocument" )
680 sal_Int32 nMyCommandIdentifier,
688 static constexpr OUStringLiteral
Title(
u"Title");
693 for(
const auto& rValue :
Values )
695 if( rValue.Name ==
Title )
698 if( rValue.Value >>= NewTitle )
705 sal_Int32 nLastSlash =
m_aUncPath.lastIndexOf(
'/' );
706 bool bTrailingSlash =
false;
707 if ( nLastSlash ==
m_aUncPath.getLength() - 1 )
709 bTrailingSlash =
true;
714 OSL_ENSURE( nLastSlash != -1,
715 "BaseContent::setPropertyValues: "
721 if ( !NewTitle.isEmpty() )
723 aBuf.append( NewTitle );
724 if ( bTrailingSlash )
736 if ( !NewTitle.isEmpty() )
745 rtl_UriCharClassPchar,
746 rtl_UriEncodeIgnoreEscapes,
747 RTL_TEXTENCODING_UTF8 );
761 auto retRange = asNonConstRange(ret);
764 for( sal_Int32
i = 0;
i <
Values.getLength(); ++
i )
772 retRange[
i] <<= beans::IllegalTypeException(
THROW_WHERE );
775 else if( NewTitle.isEmpty() )
777 retRange[
i] <<= lang::IllegalArgumentException(
THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
783 if( !aDstName.endsWith(
"/") )
786 aDstName += rtl::Uri::encode( NewTitle,
787 rtl_UriCharClassPchar,
788 rtl_UriEncodeIgnoreEscapes,
789 RTL_TEXTENCODING_UTF8 );
798 endTask( nMyCommandIdentifier );
816 sal_Int32 nMyCommandIdentifier,
817 const OpenCommandArgument2& aCommandArgument )
834 aCommandArgument.Mode == OpenMode::DOCUMENT_SHARE_DENY_NONE )
838 if( outputStream.is() )
845 bool bLock = ( aCommandArgument.Mode != OpenMode::DOCUMENT_SHARE_DENY_NONE );
848 if( activeDataSink.is() )
850 activeDataSink->setInputStream(
m_pMyShell->
open( nMyCommandIdentifier,
856 if( activeDataStreamer.is() )
863 else if ( aCommandArgument.Mode == OpenMode::ALL ||
864 aCommandArgument.Mode == OpenMode::FOLDERS ||
865 aCommandArgument.Mode == OpenMode::DOCUMENTS )
869 aCommandArgument.Mode,
870 aCommandArgument.Properties,
871 aCommandArgument.SortingInfo );
883 aCommandArgument.Mode);
898 std::unique_lock aGuard(
m_aMutex );
906 const TransferInfo& aTransferInfo )
926 OUString srcUncPath = srcUnc;
930 if( !aTransferInfo.NewTitle.isEmpty() )
931 NewTitle = rtl::Uri::encode( aTransferInfo.NewTitle,
932 rtl_UriCharClassPchar,
933 rtl_UriEncodeIgnoreEscapes,
934 RTL_TEXTENCODING_UTF8 );
936 NewTitle = srcUncPath.copy( 1 + srcUncPath.lastIndexOf(
'/' ) );
941 if( xRow->wasNull() )
951 sal_Int32 lastSlash =
m_aUncPath.lastIndexOf(
'/' );
958 dstUncPath +=
"/" + NewTitle;
960 sal_Int32 NameClash = aTransferInfo.NameClash;
962 if( aTransferInfo.MoveData )
963 m_pMyShell->
move( nMyCommandIdentifier,srcUncPath,dstUncPath,NameClash );
965 m_pMyShell->
copy( nMyCommandIdentifier,srcUncPath,dstUncPath,NameClash );
970 const InsertCommandArgument& aInsertArgument )
976 aInsertArgument.ReplaceExisting,
977 aInsertArgument.Data );
998 bool bDocument =
false;
1002 bool contentTypeSet =
true;
1005 bDocument = xRow->getBoolean( 1 );
1006 if( xRow->wasNull() )
1007 contentTypeSet =
false;
1010 catch (
const sdbc::SQLException&)
1013 contentTypeSet =
false;
1016 if( ! contentTypeSet )
1024 bool success =
false;
1028 aInsertArgument.ReplaceExisting,
1029 aInsertArgument.Data );
1036 aInsertArgument.ReplaceExisting );
1043 rtl_UriDecodeWithCharset,
1044 RTL_TEXTENCODING_UTF8),
1047 uno::Reference<task::XInteractionRequest>
const& xReq(aRequestImpl.
getRequest());
1061 rtl_UriCharClassPchar,
1062 rtl_UriEncodeIgnoreEscapes,
1063 RTL_TEXTENCODING_UTF8 );
1075 std::unique_lock aGuard(
m_aMutex );
1087std::optional<ContentEventNotifier>
1090 std::unique_lock aGuard(
m_aMutex );
1104std::optional<ContentEventNotifier>
1107 std::unique_lock aGuard(
m_aMutex );
1123std::optional<ContentEventNotifier>
1126 std::unique_lock aGuard(
m_aMutex );
1135std::optional<PropertySetInfoChangeNotifier>
1138 std::unique_lock aGuard(
m_aMutex );
1145std::optional<PropertyChangeNotifier>
1148 std::unique_lock aGuard(
m_aMutex );
1154 if( seqNames.empty() )
1158 for(
const auto& rName : seqNames )
1163 listener[rName] = pContainer->
getElements(aGuard);
const PropertyValue * pValues
std::vector< css::uno::Reference< ListenerT > > getElements(std::unique_lock< std::mutex > &rGuard) const
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 getLength(std::unique_lock< std::mutex > &rGuard) const
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
css::uno::Type const & get()
std::unique_ptr< PropertyListeners > m_pPropertyListener
void endTask(sal_Int32 CommandId)
css::uno::Reference< css::ucb::XDynamicResultSet > open(sal_Int32 nMyCommandIdentifier, const css::ucb::OpenCommandArgument2 &aCommandArgument)
virtual void SAL_CALL removePropertySetInfoChangeListener(const css::uno::Reference< css::beans::XPropertySetInfoChangeListener > &Listener) override
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
void deleteContent(sal_Int32 nMyCommandIdentifier)
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createNewContent(const css::ucb::ContentInfo &Info) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
css::uno::Sequence< css::uno::Any > setPropertyValues(sal_Int32 nMyCommandIdentifier, const css::uno::Sequence< css::beans::PropertyValue > &Values)
std::optional< PropertySetInfoChangeNotifier > cPSL() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
comphelper::OInterfaceContainerHelper4< css::ucb::XContentEventListener > m_aContentEventListeners
void insert(sal_Int32 nMyCommandIdentifier, const css::ucb::InsertCommandArgument &aInsertArgument)
BaseContent(TaskManager *pMyShell, OUString parentName, bool bFolder)
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL getIdentifier() override
virtual void SAL_CALL removePropertiesChangeListener(const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &Listener) override
comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aDisposeEventListeners
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL addContentEventListener(const css::uno::Reference< css::ucb::XContentEventListener > &Listener) override
virtual ~BaseContent() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual sal_Int32 SAL_CALL createCommandIdentifier() override
virtual void SAL_CALL abort(sal_Int32 CommandId) override
std::optional< ContentEventNotifier > cCEL() override
std::optional< PropertyChangeNotifier > cPCL() override
css::uno::Reference< css::ucb::XCommandInfo > getCommandInfo()
comphelper::OInterfaceContainerHelper4< css::beans::XPropertySetInfoChangeListener > m_aPropertySetInfoChangeListeners
std::optional< ContentEventNotifier > cEXC(const OUString &aNewName) override
virtual void SAL_CALL addProperty(const OUString &Name, sal_Int16 Attributes, const css::uno::Any &DefaultValue) override
std::optional< ContentEventNotifier > cDEL() override
virtual void SAL_CALL removeProperty(const OUString &Name) override
friend class ContentEventNotifier
virtual void SAL_CALL addPropertySetInfoChangeListener(const css::uno::Reference< css::beans::XPropertySetInfoChangeListener > &Listener) override
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL queryCreatableContentsInfo() override
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
virtual void SAL_CALL dispose() override
void transfer(sal_Int32 nMyCommandIdentifier, const css::ucb::TransferInfo &aTransferInfo)
css::uno::Reference< css::sdbc::XRow > getPropertyValues(sal_Int32 nMyCommandIdentifier, const css::uno::Sequence< css::beans::Property > &PropertySet)
virtual void SAL_CALL removeContentEventListener(const css::uno::Reference< css::ucb::XContentEventListener > &Listener) override
virtual OUString SAL_CALL getContentType() override
virtual void SAL_CALL addPropertiesChangeListener(const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &Listener) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
css::uno::Reference< css::ucb::XContentIdentifier > m_xContentIdentifier
css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo()
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
void addInterface(std::unique_lock< std::mutex > &rGuard, const OUString &rKey, const uno::Reference< beans::XPropertiesChangeListener > &rListener)
std::unordered_map< OUString, ContainerHelper > m_aMap
void disposeAndClear(std::unique_lock< std::mutex > &rGuard, const lang::EventObject &rEvt)
comphelper::OInterfaceContainerHelper4< beans::XPropertiesChangeListener > ContainerHelper
void removeInterface(std::unique_lock< std::mutex > &rGuard, const OUString &rKey, const uno::Reference< beans::XPropertiesChangeListener > &rListener)
std::vector< OUString > getContainedTypes(std::unique_lock< std::mutex > &rGuard) const
comphelper::OInterfaceContainerHelper4< beans::XPropertiesChangeListener > * getContainer(std::unique_lock< std::mutex > &, const OUString &rKey)
static css::uno::Sequence< css::ucb::ContentInfo > queryCreatableContentsInfo()
bool mkdir(sal_Int32 CommandId, const OUString &aDirectoryName, bool OverWrite)
Creates new directory with given URL, recursively if necessary Return:: success of operation.
void endTask(sal_Int32 CommandId, const OUString &aUnqPath, BaseContent *pContent)
Deinstalls the task and evaluates a possibly set error code.
css::uno::Sequence< css::uno::Any > setv(const OUString &aUnqPath, const css::uno::Sequence< css::beans::PropertyValue > &values)
Sets the values of the properties belonging to fileURL aUnqPath.
bool write(sal_Int32 CommandId, const OUString &aUnqPath, bool OverWrite, const css::uno::Reference< css::io::XInputStream > &aInputStream)
writes to the file with given URL.
void registerNotifier(const OUString &aUnqPath, Notifier *pNotifier)
This two methods register and deregister a change listener for the content belonging to URL aUnqPath.
css::uno::Reference< css::ucb::XDynamicResultSet > ls(sal_Int32 CommandId, const OUString &aUnqPath, const sal_Int32 OpenMode, const css::uno::Sequence< css::beans::Property > &sProperty, const css::uno::Sequence< css::ucb::NumberedSortingInfo > &sSortingInfo)
This method returns the result set containing the children of the directory belonging to file URL aUn...
static constexpr OUStringLiteral FolderContentType
FileProvider * m_pProvider
void installError(sal_Int32 CommandId, sal_Int32 ErrorCode, sal_Int32 minorCode=TASKHANDLER_NO_ERROR)
The error code may be one of the error codes defined in filerror.hxx.
bool mkfil(sal_Int32 CommandId, const OUString &aFileName, bool OverWrite, const css::uno::Reference< css::io::XInputStream > &aInputStream)
Creates new file with given URL.
void deregisterNotifier(const OUString &aUnqPath, Notifier *pNotifier)
void handleTask(sal_Int32 CommandId, const css::uno::Reference< css::task::XInteractionRequest > &request)
Handles an interactionrequest.
static bool getUnqFromUrl(const OUString &Url, OUString &Unq)
static bool getUrlFromUnq(const OUString &Unq, OUString &Url)
css::uno::Reference< css::beans::XPropertySetInfo > info_p(const OUString &aUnqPath)
css::uno::Reference< css::io::XStream > open_rw(sal_Int32 CommandId, const OUString &aUnqPath, bool bLock)
Given a file URL aUnqPath, this methods returns a XStream which can be used to read and write from/to...
void startTask(sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &xCommandEnv)
void clearError(sal_Int32)
Clears any error which are set on the commandid.
css::uno::Reference< css::io::XInputStream > open(sal_Int32 CommandId, const OUString &aUnqPath, bool bLock)
Given a file URL aUnqPath, this methods returns a XInputStream which reads from the open file.
void insertDefaultProperties(const OUString &aUnqPath)
bool remove(sal_Int32 CommandId, const OUString &aUnqPath, FileUrlType eTypeToMove=FileUrlType::Unknown, bool MustExist=true)
Deletes the content belonging to fileURL aUnqPath( recursively in case of directory )
void move(sal_Int32 CommandId, const OUString &srcUnqPath, const OUString &dstUnqPath, const sal_Int32 NameClash)
Moves the content belonging to fileURL srcUnqPath to fileURL dstUnqPath( files and directories )
void copy(sal_Int32 CommandId, const OUString &srcUnqPath, const OUString &dstUnqPath, sal_Int32 NameClash)
Copies the content belonging to fileURL srcUnqPath to fileURL dstUnqPath ( files and directories )
void deassociate(const OUString &UnqPath, const OUString &PropertyName)
css::uno::Reference< css::ucb::XCommandInfo > info_c()
Info methods.
void page(sal_Int32 CommandId, const OUString &aUnqPath, const css::uno::Reference< css::io::XOutputStream > &xOutputStream)
Given an xOutputStream, this method writes the content of the file belonging to URL aUnqPath into the...
css::uno::Reference< css::sdbc::XRow > getv(sal_Int32 CommandId, const OUString &aUnqPath, const css::uno::Sequence< css::beans::Property > &properties)
Reads the values of the properties belonging to fileURL aUnqPath; Returns an XRow object containing t...
static constexpr OUStringLiteral FileContentType
void associate(const OUString &UnqPath, const OUString &PropertyName, const css::uno::Any &DefaultValue, const sal_Int16 Attributes)
Used to associate and deassociate a new property with the content belonging to URL UnqPath.
css::uno::Reference< css::task::XInteractionRequest > const & getRequest() const
#define TOOLS_WARN_EXCEPTION(area, stream)
#define TASKHANDLING_TRANSFER_INVALIDURL
#define TASKHANDLING_UNSUPPORTED_OPEN_MODE
#define TASKHANDLING_WRONG_OPEN_ARGUMENT
#define TASKHANDLING_WRONG_GETPROPERTYVALUES_ARGUMENT
#define TASKHANDLING_WRONG_SETPROPERTYVALUES_ARGUMENT
#define TASKHANDLING_WRONG_DELETE_ARGUMENT
#define TASKHANDLING_WRONG_TRANSFER_ARGUMENT
#define TASKHANDLING_NONAMESET_INSERT_COMMAND
#define TASKHANDLING_WRONG_INSERT_ARGUMENT
#define TASKHANDLING_DELETED_STATE_IN_OPEN_COMMAND
#define TASKHANDLER_UNSUPPORTED_COMMAND
#define TASKHANDLING_NOFRESHINSERT_IN_INSERT_COMMAND
#define TASKHANDLING_NOCONTENTTYPE_INSERT_COMMAND
#define TASKHANDLING_TRANSFER_INVALIDSCHEME
#define TASKHANDLING_INSERTED_STATE_IN_OPEN_COMMAND
#define TASKHANDLING_TRANSFER_DESTFILETYPE
#define TASKHANDLING_WRONG_CREATENEWCONTENT_ARGUMENT
constexpr OUStringLiteral IsDocument(u"IsDocument")
constexpr OUStringLiteral CasePreservingURL(u"CasePreservingURL")
COMPHELPER_DLLPUBLIC bool isFileUrl(std::u16string_view url)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString getParentName(std::u16string_view aFileName)
std::unordered_map< OUString, std::vector< css::uno::Reference< css::beans::XPropertiesChangeListener > > > ListenerMap
std::u16string_view getTitle(std::u16string_view aPath)