25#include <osl/diagnose.h>
33#include <com/sun/star/ucb/CheckinArgument.hpp>
34#include <com/sun/star/ucb/ContentCreationError.hpp>
35#include <com/sun/star/ucb/ContentCreationException.hpp>
36#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
37#include <com/sun/star/ucb/XCommandInfo.hpp>
38#include <com/sun/star/ucb/XCommandProcessor.hpp>
39#include <com/sun/star/ucb/Command.hpp>
40#include <com/sun/star/ucb/ContentAction.hpp>
41#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
42#include <com/sun/star/ucb/InsertCommandArgument.hpp>
43#include <com/sun/star/ucb/GlobalTransferCommandArgument2.hpp>
44#include <com/sun/star/ucb/OpenMode.hpp>
45#include <com/sun/star/ucb/XContentCreator.hpp>
46#include <com/sun/star/ucb/XContentEventListener.hpp>
47#include <com/sun/star/ucb/XDynamicResultSet.hpp>
48#include <com/sun/star/ucb/SortedDynamicResultSetFactory.hpp>
49#include <com/sun/star/ucb/UniversalContentBroker.hpp>
50#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
51#include <com/sun/star/beans/XPropertySetInfo.hpp>
52#include <com/sun/star/beans/Property.hpp>
53#include <com/sun/star/beans/PropertyValue.hpp>
54#include <com/sun/star/sdbc/XRow.hpp>
55#include <com/sun/star/lang/IllegalArgumentException.hpp>
56#include <com/sun/star/beans/UnknownPropertyException.hpp>
80class EmptyInputStream :
public ::cppu::WeakImplHelper< XInputStream >
83 virtual sal_Int32 SAL_CALL readBytes(
85 virtual sal_Int32 SAL_CALL readSomeBytes(
87 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
override;
88 virtual sal_Int32 SAL_CALL available()
override;
89 virtual void SAL_CALL closeInput()
override;
94sal_Int32 EmptyInputStream::readBytes(
101sal_Int32 EmptyInputStream::readSomeBytes(
108void EmptyInputStream::skipBytes( sal_Int32 )
112sal_Int32 EmptyInputStream::available()
117void EmptyInputStream::closeInput()
126 public XContentEventListener
131 explicit ContentEventListener_Impl( Content_Impl& rContent )
135 virtual css::uno::Any SAL_CALL
queryInterface(
const css::uno::Type & rType )
override;
136 virtual void SAL_CALL acquire()
138 virtual
void SAL_CALL release()
142 virtual
void SAL_CALL contentEvent( const ContentEvent& evt ) override;
145 virtual
void SAL_CALL disposing( const EventObject& Source ) override;
166 void disposing(
const EventObject& Source);
168 const OUString& getURL_NoLock()
const;
178 const OUString& getURL()
const;
187 inline void setEnvironment(
199 const OUString & rURL )
202 = rBroker->queryContentProvider( rURL );
205 throw ContentCreationException(
206 "No Content Provider available for URL: " + rURL,
208 ContentCreationError_NO_CONTENT_PROVIDER );
216 const OUString & rURL)
219 = rBroker->createContentIdentifier( rURL );
225 throw ContentCreationException(
226 "Unable to create Content Identifier!",
228 ContentCreationError_IDENTIFIER_CREATION_FAILED );
237 const OUString & rURL)
239 return rBroker->createContentIdentifier(rURL);
252 xContent = rBroker->queryContent( xId );
254 catch ( IllegalIdentifierException
const & e )
260 if ( !xContent.is() )
264 throw ContentCreationException(
265 "Unable to create Content for <" + xId->getContentIdentifier() +
">: " + msg,
267 ContentCreationError_CONTENT_CREATION_FAILED );
281 xContent = rBroker->queryContent( xId );
283 catch ( IllegalIdentifierException
const & e )
285 SAL_WARN(
"ucbhelper",
"getContentNoThrow: " << e);
306 UniversalContentBroker::create( rCtx ) );
321 m_xImpl =
new Content_Impl( rCtx, rContent, rEnv );
332 m_xImpl = std::move(rOther.m_xImpl);
342 UniversalContentBroker::create( rCtx ) );
350 if ( !xContent.is() )
373 m_xImpl = std::move(rOther.m_xImpl);
391 return m_xImpl->getEnvironment();
398 m_xImpl->setEnvironment( xNewEnv );
419 static constexpr OUStringLiteral sgetPropertySetInfo =
u"getPropertySetInfo";
421 aCommand.Name = sgetPropertySetInfo;
438 return aRet.getConstArray()[ 0 ];
448 aValues.getArray()[ 0 ] = rValue;
451 return aErrors.getConstArray()[ 0 ];
460 sal_Int32
nCount = rPropertyNames.getLength();
467 for ( sal_Int32 n = 0;
n <
nCount; ++
n )
478 sal_Int32
nCount = rPropertyNames.getLength();
480 Property* pProps = aProps.getArray();
482 const OUString* pNames = rPropertyNames.getConstArray();
488 rProp.Name = pNames[
n ];
494 static constexpr OUStringLiteral sgetPropertyValues =
u"getPropertyValues";
512 if ( rPropertyNames.getLength() != rValues.getLength() )
515 Any( IllegalArgumentException(
516 "Length of property names sequence and value "
517 "sequence are unequal!",
524 sal_Int32
nCount = rValues.getLength();
526 PropertyValue* pProps = aProps.getArray();
528 const OUString* pNames = rPropertyNames.getConstArray();
531 for ( sal_Int32 n = 0;
n<
nCount; ++
n )
533 PropertyValue& rProp = pProps[
n ];
535 rProp.Name = pNames[
n ];
542 aCommand.Name =
"setPropertyValues";
546 Any aResult =
m_xImpl->executeCommand( aCommand );
555 const Any& rCommandArgument )
560 aCommand.Argument = rCommandArgument;
569 sal_Int32
nCount = rPropertyNames.getLength();
571 Property* pProps = aProps.getArray();
572 const OUString* pNames = rPropertyNames.getConstArray();
576 rProp.Name = pNames[
n ];
580 OpenCommandArgument2 aArg;
584 ? OpenMode::DOCUMENTS : OpenMode::ALL;
587 aArg.Properties = aProps;
607 aCursorAny >>= xDynSet;
609 aResult = xDynSet->getStaticResultSet();
611 OSL_ENSURE( aResult.is(),
"Content::createCursor - no cursor!" );
616 aCursorAny >>= aResult;
618 OSL_ENSURE( !aResult.is(),
619 "Content::createCursor - open-Command must "
620 "return a Reference< XDynnamicResultSet >!" );
634 OSL_ENSURE( aResult.is(),
"Content::createDynamicCursor - no cursor!" );
651 aCursorAny >>= aDynSet;
657 if(
m_xImpl->getComponentContext().is() )
660 SortedDynamicResultSetFactory::create(
m_xImpl->getComponentContext());
662 aDynResult = aSortFactory->createSortedDynamicResultSet( aDynSet,
664 rAnyCompareFactory );
667 OSL_ENSURE( aDynResult.is(),
"Content::createSortedCursor - no sorted cursor!" );
669 if( aDynResult.is() )
670 aResult = aDynResult->getStaticResultSet();
672 aResult = aDynSet->getStaticResultSet();
675 OSL_ENSURE( aResult.is(),
"Content::createSortedCursor - no cursor!" );
680 aCursorAny >>= aResult;
682 OSL_ENSURE( !aResult.is(),
683 "Content::createCursor - open-Command must "
684 "return a Reference< XDynnamicResultSet >!" );
698 OpenCommandArgument2 aArg;
699 aArg.Mode = OpenMode::DOCUMENT;
711 return xSink->getInputStream();
722 OpenCommandArgument2 aArg;
723 aArg.Mode = OpenMode::DOCUMENT_SHARE_DENY_NONE;
735 return xSink->getInputStream();
746 OpenCommandArgument2 aArg;
747 aArg.Mode = OpenMode::DOCUMENT;
749 aArg.Sink = xStreamer;
759 return xStreamer->getStream();
770 OpenCommandArgument2 aArg;
771 aArg.Mode = OpenMode::DOCUMENT_SHARE_DENY_NONE;
773 aArg.Sink = xStreamer;
783 return xStreamer->getStream();
792 OpenCommandArgument2 aArg;
793 aArg.Mode = OpenMode::DOCUMENT;
803 m_xImpl->executeCommand( aCommand );
814 OpenCommandArgument2 aArg;
815 aArg.Mode = OpenMode::DOCUMENT;
825 m_xImpl->executeCommand( aCommand );
832 bool bReplaceExisting )
834 InsertCommandArgument aArg;
835 aArg.Data = rStream.is() ? rStream :
new EmptyInputStream;
836 aArg.ReplaceExisting = bReplaceExisting;
854 "CreatableContentsInfo" )
862 aInfo = xCreator->queryCreatableContentsInfo();
877 new EmptyInputStream,
887 Content& rNewContent )
889 if ( rContentType.isEmpty() )
894 aInfo.Type = rContentType;
895 aInfo.Attributes = 0;
905 m_xImpl->executeCommand( aCommand ) >>= xNew;
911 catch ( Exception
const & )
921 if ( !xCreator.is() )
924 xNew = xCreator->createNewContent( aInfo );
931 xNew,
m_xImpl->getEnvironment(),
m_xImpl->getComponentContext() );
932 aNewContent.setPropertyValues( rPropertyNames, rPropertyValues );
933 aNewContent.executeCommand(
"insert",
935 InsertCommandArgument(
936 rData.is() ? rData :
new EmptyInputStream,
938 aNewContent.m_xImpl->inserted();
940 rNewContent = aNewContent;
947 const OUString & rTitle,
948 const sal_Int32 nNameClashAction,
949 const OUString & rMimeType,
951 const OUString & rVersionComment,
952 OUString* pResultURL,
953 const OUString & rDocumentId )
const
956 UniversalContentBroker::create(
m_xImpl->getComponentContext() ) );
960 TransferCommandOperation eTransOp = TransferCommandOperation();
961 OUString sCommand(
"globalTransfer" );
962 bool bCheckIn =
false;
963 switch ( eOperation )
966 eTransOp = TransferCommandOperation_COPY;
970 eTransOp = TransferCommandOperation_MOVE;
974 eTransOp = TransferCommandOperation_COPY;
975 sCommand =
"checkin";
985 GlobalTransferCommandArgument2 aTransferArg(
997 CheckinArgument aCheckinArg( bMajorVersion, rVersionComment,
1003 if ( pResultURL !=
nullptr )
1004 aRet >>= *pResultURL;
1010 bool bFolder =
false;
1016 Any( UnknownPropertyException(
1017 "Unable to retrieve value of property 'IsFolder'!",
1033 Any( UnknownPropertyException(
1034 "Unable to retrieve value of property 'IsDocument'!",
1079#if OSL_DEBUG_LEVEL > 0
1090 std::unique_lock aGuard(
m_aMutex );
1107 if ( xContent.is() )
1112#if OSL_DEBUG_LEVEL > 0
1150 std::unique_lock aGuard(
m_aMutex );
1161 if ( xContent.is() )
1178 std::unique_lock aGuard(
m_aMutex );
1192 m_aURL = xId->getContentIdentifier();
1202 std::unique_lock aGuard(
m_aMutex );
1215 OSL_ENSURE( pBroker->queryContentProviders().hasElements(),
1216 "Content Broker not configured (no providers)!" );
1219 = pBroker->createContentIdentifier(
m_aURL );
1221 OSL_ENSURE( xId.is(),
"No Content Identifier!" );
1229 catch ( IllegalIdentifierException
const & )
1247 std::unique_lock aGuard(
m_aMutex );
1264 return xProc->execute( rCommand, 0,
m_xEnv );
1278 std::unique_lock aGuard(
m_aMutex );
1286 std::unique_lock aGuard(
m_aMutex );
1296void SAL_CALL ContentEventListener_Impl::acquire()
1299 OWeakObject::acquire();
1302void SAL_CALL ContentEventListener_Impl::release()
1305 OWeakObject::release();
1308css::uno::Any SAL_CALL ContentEventListener_Impl::queryInterface(
const css::uno::Type & rType )
1311 static_cast< XContentEventListener*
>(
this),
1312 static_cast< XEventListener*
>(
this)
1314 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
1321void SAL_CALL ContentEventListener_Impl::contentEvent(
const ContentEvent& evt )
1326 switch ( evt.Action )
1328 case ContentAction::DELETED:
1332 case ContentAction::EXCHANGED:
1346void SAL_CALL ContentEventListener_Impl::disposing(
const EventObject& Source )
const PropertyValue * pValues
Reference< XComponentContext > m_xCtx
uno::Reference< ucb::XContent > m_xContent
This class implements the interface css::io::XActiveDataStreamer.
const Reference< XContent > & getContent_NoLock()
const Reference< XCommandEnvironment > & getEnvironment() const
friend ContentEventListener_Impl
Any executeCommand(const Command &rCommand)
Reference< XCommandProcessor > getCommandProcessor()
virtual ~Content_Impl() override
Reference< XCommandProcessor > m_xCommandProcessor
Reference< XComponentContext > m_xCtx
Reference< XContent > getContent()
Reference< XContentEventListener > m_xContentEventListener
Reference< XContent > m_xContent
Reference< XComponentContext > const & getComponentContext() const
const OUString & getURL_NoLock() const
Reference< XCommandEnvironment > m_xEnv
const OUString & getURL() const
void reinit(const Reference< XContent > &xContent)
void setEnvironment(const Reference< XCommandEnvironment > &xNewEnv)
void disposing(const EventObject &Source)
This class simplifies access to UCB contents by providing a more convenient API for frequently used f...
bool isFolder()
This method returns the value of the content's property "IsFolder".
css::uno::Any setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue)
This method can be used to set a single property value.
const OUString & getURL() const
This method returns the URL of the content.
void transferContent(const Content &rSourceContent, InsertOperation eOperation, const OUString &rTitle, const sal_Int32 nNameClashAction, const OUString &rMimeType=OUString(), bool bMajorVersion=false, const OUString &rCommentVersion=OUString(), OUString *pResultURL=nullptr, const OUString &rDocumentId=OUString()) const
This method transfers (copies/moves) a content.
Content & operator=(const Content &rOther)
Assignment operator.
css::uno::Reference< css::sdbc::XRow > getPropertyValuesInterface(const css::uno::Sequence< OUString > &rPropertyNames)
This method can be used to read multiple property values.
const css::uno::Reference< css::ucb::XCommandEnvironment > & getCommandEnvironment() const
This method returns the environment to use when executing commands.
css::uno::Any getPropertyValue(const OUString &rPropertyName)
This method can be used to read a single property value.
css::uno::Reference< css::io::XStream > openWriteableStream()
This methods gives read/write access to the content stream of a content (i.e the content of a file lo...
css::uno::Reference< css::io::XInputStream > openStreamNoLock()
This methods gives read access to the content stream of a content (i.e the content of a file located ...
css::uno::Reference< css::beans::XPropertySetInfo > getProperties()
This methods provides access to meta data of the properties supported by this content.
void unlock()
This method unlock the resource.
css::uno::Any executeCommand(const OUString &rCommandName, const css::uno::Any &rCommandArgument)
This method can be used to execute any command supported by the content.
css::uno::Reference< css::ucb::XCommandInfo > getCommands()
This methods provides access to meta data of the commands supported by this content.
static bool create(const OUString &rURL, const css::uno::Reference< css::ucb::XCommandEnvironment > &rEnv, const css::uno::Reference< css::uno::XComponentContext > &rCtx, Content &rContent)
Constructor.
css::uno::Any createCursorAny(const css::uno::Sequence< OUString > &rPropertyNames, ResultSetInclude eMode)
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< OUString > &rPropertyNames, const css::uno::Sequence< css::uno::Any > &rValues)
This method can be used to set multiple property values.
void lock()
This method lock the resource.
css::uno::Reference< css::io::XStream > openWriteableStreamNoLock()
This methods gives read/write access to the content stream of a content (i.e the content of a file lo...
bool insertNewContent(const OUString &rContentType, const css::uno::Sequence< OUString > &rPropertyNames, const css::uno::Sequence< css::uno::Any > &rPropertyValues, Content &rNewContent)
This method creates, initializes and inserts ( commits ) a new content (i.e.
css::uno::Sequence< css::ucb::ContentInfo > queryCreatableContentsInfo()
This method returns the different types of contents this content can create.
bool isDocument()
This method returns the value of the content's property "IsDocument".
css::uno::Reference< css::ucb::XContent > get() const
This method provides access to the "native" UCB content interface(s).
css::uno::Reference< css::io::XInputStream > openStream()
This methods gives read access to the content stream of a content (i.e the content of a file located ...
css::uno::Reference< css::sdbc::XResultSet > createSortedCursor(const css::uno::Sequence< OUString > &rPropertyNames, const css::uno::Sequence< css::ucb::NumberedSortingInfo > &rSortInfo, const css::uno::Reference< css::ucb::XAnyCompareFactory > &rAnyCompareFactory, ResultSetInclude eMode=INCLUDE_FOLDERS_AND_DOCUMENTS)
css::uno::Reference< css::sdbc::XResultSet > createCursor(const css::uno::Sequence< OUString > &rPropertyNames, ResultSetInclude eMode=INCLUDE_FOLDERS_AND_DOCUMENTS)
This methods gives access to the children of a folder content.
void setCommandEnvironment(const css::uno::Reference< css::ucb::XCommandEnvironment > &xNewEnv)
This method sets a new command environment.
rtl::Reference< Content_Impl > m_xImpl
css::uno::Sequence< css::uno::Any > getPropertyValues(const css::uno::Sequence< OUString > &rPropertyNames)
This method can be used to read multiple property values.
css::uno::Reference< css::ucb::XDynamicResultSet > createDynamicCursor(const css::uno::Sequence< OUString > &rPropertyNames, ResultSetInclude eMode=INCLUDE_FOLDERS_AND_DOCUMENTS)
This methods gives access to the children of a folder content.
void writeStream(const css::uno::Reference< css::io::XInputStream > &rStream, bool bReplaceExisting)
This methods gives write access to the content stream of a content (i.e the content of a file located...
Content_Impl & m_rContent
tools::SvRef< SvBaseLink > xSink
DECL_LISTENERMULTIPLEXER_END void SAL_CALL inserted(::sal_Int32 ID) override
#define SAL_WARN(area, stream)
bool executeCommand(const OUString &rCommand)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
css::uno::Environment getEnvironment(OUString const &name, std::u16string_view implementation)
static Reference< XContent > getContentThrow(const Reference< XUniversalContentBroker > &rBroker, const Reference< XContentIdentifier > &xId)
InsertOperation
These are the possible values for the parameter eOperation of method ucbhelper::Content::insertNewCon...
static Reference< XContentIdentifier > getContentIdentifierThrow(const Reference< XUniversalContentBroker > &rBroker, const OUString &rURL)
static Reference< XContentIdentifier > getContentIdentifierNoThrow(const Reference< XUniversalContentBroker > &rBroker, const OUString &rURL)
ResultSetInclude
These are the possible values for the parameter eMode of method ucbhelper::Content::createCursor.
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
static Reference< XContent > getContentNoThrow(const Reference< XUniversalContentBroker > &rBroker, const Reference< XContentIdentifier > &xId)
static void ensureContentProviderForURL(const Reference< XUniversalContentBroker > &rBroker, const OUString &rURL)