20#include <osl/diagnose.h>
24#include <rtl/ustring.hxx>
25#include <com/sun/star/uno/XInterface.hpp>
26#include <com/sun/star/beans/PropertyState.hpp>
27#include <com/sun/star/beans/PropertyValue.hpp>
28#include <com/sun/star/beans/XPropertySetInfo.hpp>
29#include <com/sun/star/io/IOException.hpp>
30#include <com/sun/star/io/Pipe.hpp>
31#include <com/sun/star/io/XActiveDataSink.hpp>
32#include <com/sun/star/io/XOutputStream.hpp>
33#include <com/sun/star/io/XSeekable.hpp>
34#include <com/sun/star/lang/IllegalArgumentException.hpp>
35#include <com/sun/star/sdbc/SQLException.hpp>
36#include <com/sun/star/sdbc/XRow.hpp>
37#include <com/sun/star/task/XInteractionHandler.hpp>
38#include <com/sun/star/ucb/CommandEnvironment.hpp>
39#include <com/sun/star/ucb/CommandFailedException.hpp>
40#include <com/sun/star/ucb/ContentInfoAttribute.hpp>
41#include <com/sun/star/ucb/GlobalTransferCommandArgument2.hpp>
42#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
43#include <com/sun/star/ucb/InsertCommandArgument2.hpp>
44#include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
45#include <com/sun/star/ucb/NameClash.hpp>
46#include <com/sun/star/ucb/NameClashException.hpp>
47#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
48#include <com/sun/star/ucb/OpenMode.hpp>
49#include <com/sun/star/ucb/TransferInfo2.hpp>
50#include <com/sun/star/ucb/UnsupportedCommandException.hpp>
51#include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
52#include <com/sun/star/ucb/XCommandInfo.hpp>
53#include <com/sun/star/ucb/XContentAccess.hpp>
54#include <com/sun/star/ucb/XContentCreator.hpp>
55#include <com/sun/star/ucb/XDynamicResultSet.hpp>
56#include <com/sun/star/ucb/XInteractionSupplyName.hpp>
57#include <com/sun/star/uno/Any.hxx>
58#include <com/sun/star/uno/Sequence.hxx>
70beans::Property makeProperty(
const OUString& n, sal_Int32 h,
uno::Type t = {}, sal_Int16
a = {})
72 return {
n,
h,
t,
a };
78struct TransferCommandContext
80 uno::Reference< uno::XComponentContext >
m_xContext;
81 uno::Reference< ucb::XCommandProcessor >
xProcessor;
82 uno::Reference< ucb::XCommandEnvironment > xEnv;
83 uno::Reference< ucb::XCommandEnvironment > xOrigEnv;
84 ucb::GlobalTransferCommandArgument2 aArg;
86 TransferCommandContext(
87 uno::Reference< uno::XComponentContext > xContext,
88 uno::Reference< ucb::XCommandProcessor > _xProcessor,
89 uno::Reference< ucb::XCommandEnvironment > _xEnv,
90 uno::Reference< ucb::XCommandEnvironment > _xOrigEnv,
91 ucb::GlobalTransferCommandArgument2 _aArg )
93 xOrigEnv(
std::move( _xOrigEnv )), aArg(
std::move( _aArg )) {}
99class InteractionHandlerProxy :
100 public cppu::WeakImplHelper< task::XInteractionHandler >
102 uno::Reference< task::XInteractionHandler > m_xOrig;
105 explicit InteractionHandlerProxy(
106 uno::Reference< task::XInteractionHandler > xOrig )
107 : m_xOrig(
std::move( xOrig )) {}
110 virtual void SAL_CALL handle(
111 const uno::Reference< task::XInteractionRequest >& Request )
override;
116void SAL_CALL InteractionHandlerProxy::handle(
117 const uno::Reference< task::XInteractionRequest >& Request )
123 uno::Any aRequest = Request->getRequest();
126 ucb::InteractiveBadTransferURLException aBadTransferURLEx;
127 if ( aRequest >>= aBadTransferURLEx )
134 ucb::UnsupportedNameClashException aUnsupportedNameClashEx;
135 if ( aRequest >>= aUnsupportedNameClashEx )
137 if ( aUnsupportedNameClashEx.NameClash
138 != ucb::NameClash::ERROR )
144 ucb::NameClashException aNameClashEx;
145 if ( aRequest >>= aNameClashEx )
152 ucb::UnsupportedCommandException aUnsupportedCommandEx;
153 if ( aRequest >>= aUnsupportedCommandEx )
162 m_xOrig->handle( Request );
168class ActiveDataSink :
public cppu::WeakImplHelper< io::XActiveDataSink >
170 uno::Reference< io::XInputStream >
m_xStream;
174 virtual void SAL_CALL setInputStream(
175 const uno::Reference< io::XInputStream >& aStream )
override;
176 virtual uno::Reference< io::XInputStream > SAL_CALL getInputStream()
override;
181void SAL_CALL ActiveDataSink::setInputStream(
182 const uno::Reference< io::XInputStream >& aStream )
189uno::Reference< io::XInputStream > SAL_CALL ActiveDataSink::getInputStream()
197class CommandProcessorInfo :
198 public cppu::WeakImplHelper< ucb::XCommandInfo >
200 uno::Sequence< ucb::CommandInfo >
m_xInfo;
203 CommandProcessorInfo();
206 virtual uno::Sequence< ucb::CommandInfo > SAL_CALL getCommands()
override;
207 virtual ucb::CommandInfo SAL_CALL
208 getCommandInfoByName(
const OUString& Name )
override;
209 virtual ucb::CommandInfo SAL_CALL
210 getCommandInfoByHandle( sal_Int32 Handle )
override;
211 virtual sal_Bool SAL_CALL hasCommandByName(
const OUString& Name )
override;
212 virtual sal_Bool SAL_CALL hasCommandByHandle( sal_Int32 Handle )
override;
216CommandProcessorInfo::CommandProcessorInfo()
225 cppu::UnoType<
ucb::GlobalTransferCommandArgument>::
get() ),
229 cppu::UnoType<
ucb::CheckinArgument>::
get() ) }
235uno::Sequence< ucb::CommandInfo > SAL_CALL
236CommandProcessorInfo::getCommands()
243ucb::CommandInfo SAL_CALL
244CommandProcessorInfo::getCommandInfoByName(
const OUString& Name )
246 auto pInfo = std::find_if(std::cbegin(m_xInfo), std::cend(m_xInfo),
247 [&Name](
const ucb::CommandInfo& rInfo) {
return rInfo.Name ==
Name; });
248 if (pInfo != std::cend(m_xInfo))
251 throw ucb::UnsupportedCommandException();
256ucb::CommandInfo SAL_CALL
257CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
259 auto pInfo = std::find_if(std::cbegin(m_xInfo), std::cend(m_xInfo),
260 [&Handle](
const ucb::CommandInfo& rInfo) {
return rInfo.Handle ==
Handle; });
261 if (pInfo != std::cend(m_xInfo))
264 throw ucb::UnsupportedCommandException();
269sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
270 const OUString& Name )
272 return std::any_of(std::cbegin(m_xInfo), std::cend(m_xInfo),
273 [&Name](
const ucb::CommandInfo& rInfo) {
return rInfo.Name ==
Name; });
278sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle )
280 return std::any_of(std::cbegin(m_xInfo), std::cend(m_xInfo),
281 [&Handle](
const ucb::CommandInfo& rInfo) {
return rInfo.Handle ==
Handle; });
285OUString createDesiredName(
286 const OUString & rSourceURL,
const OUString & rNewTitle )
288 OUString
aName( rNewTitle );
289 if (
aName.isEmpty() )
301 sal_Int32 nLastSlash = rSourceURL.lastIndexOf(
'/' );
302 bool bTrailingSlash =
false;
303 if ( nLastSlash == rSourceURL.getLength() - 1 )
305 nLastSlash = rSourceURL.lastIndexOf(
'/', nLastSlash );
306 bTrailingSlash =
true;
309 if ( nLastSlash != -1 )
311 if ( bTrailingSlash )
312 aName = rSourceURL.copy(
314 rSourceURL.getLength() - nLastSlash - 2 );
316 aName = rSourceURL.copy( nLastSlash + 1 );
334OUString createDesiredName(
335 const ucb::GlobalTransferCommandArgument & rArg )
337 return createDesiredName( rArg.SourceURL, rArg.NewTitle );
340OUString createDesiredName(
341 const ucb::TransferInfo & rArg )
343 return createDesiredName( rArg.SourceURL, rArg.NewTitle );
349NameClashContinuation interactiveNameClashResolve(
350 const uno::Reference< ucb::XCommandEnvironment > & xEnv,
351 const OUString & rTargetURL,
352 const OUString & rClashingName,
354 OUString & rNewName )
357 new ucbhelper::SimpleNameClashResolveRequest(
362 rException = xRequest->getRequest();
365 uno::Reference< task::XInteractionHandler > xIH
366 = xEnv->getInteractionHandler();
370 xIH->handle( xRequest );
373 xSelection( xRequest->getSelection() );
375 if ( xSelection.is() )
378 uno::Reference< task::XInteractionAbort > xAbort(
379 xSelection.get(), uno::UNO_QUERY );
388 ucb::XInteractionReplaceExistingData >
390 xSelection.get(), uno::UNO_QUERY );
399 ucb::XInteractionSupplyName >
401 xSelection.get(), uno::UNO_QUERY );
402 if ( xSupplyName.is() )
405 rNewName = xRequest->getNewName();
410 OSL_FAIL(
"Unknown interaction continuation!" );
423 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessor,
424 const uno::Reference< ucb::XCommandEnvironment > & xEnv,
425 const OUString & rNewTitle )
429 uno::Sequence< beans::PropertyValue > aPropValues{ {
"Title",
434 ucb::Command aSetPropsCommand(
440 = xCommandProcessor->execute( aSetPropsCommand, 0, xEnv );
442 uno::Sequence< uno::Any > aErrors;
445 OSL_ENSURE( aErrors.getLength() == 1,
446 "getPropertyValues return value invalid!" );
448 if ( aErrors[ 0 ].hasValue() )
451 OSL_FAIL(
"error setting Title property!" );
455 catch ( uno::RuntimeException
const & )
459 catch ( uno::Exception
const & )
468uno::Reference< ucb::XContent > createNew(
469 const TransferCommandContext & rContext,
470 const uno::Reference< ucb::XContent > & xTarget,
471 bool bSourceIsFolder,
472 bool bSourceIsDocument,
483 uno::Reference< ucb::XCommandProcessor > xCommandProcessorT(
484 xTarget, uno::UNO_QUERY );
485 if ( !xCommandProcessorT.is() )
489 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
492 ucb::IOErrorCode_CANT_CREATE,
495 "Target is no XCommandProcessor!",
496 rContext.xProcessor );
500 uno::Sequence< beans::Property > aPropsToObtain{ makeProperty(
"CreatableContentsInfo", -1) };
502 ucb::Command aGetPropsCommand(
507 uno::Reference< sdbc::XRow > xRow;
508 xCommandProcessorT->execute( aGetPropsCommand, 0, rContext.xEnv ) >>= xRow;
510 uno::Sequence< ucb::ContentInfo > aTypesInfo;
511 bool bGotTypesInfo =
false;
516 1, uno::Reference< container::XNameAccess >() );
517 if ( aValue.
hasValue() && ( aValue >>= aTypesInfo ) )
519 bGotTypesInfo =
true;
523 uno::Reference< ucb::XContentCreator > xCreator;
525 if ( !bGotTypesInfo )
530 xCreator.set( xTarget, uno::UNO_QUERY );
532 if ( !xCreator.is() )
536 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
539 ucb::IOErrorCode_CANT_CREATE,
542 "Target is no XContentCreator!",
543 rContext.xProcessor );
547 aTypesInfo = xCreator->queryCreatableContentsInfo();
550 if ( !aTypesInfo.hasElements() )
554 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
557 ucb::IOErrorCode_CANT_CREATE,
560 "No types creatable!",
561 rContext.xProcessor );
567 std::function<bool(
const sal_Int32)> lCompare;
569 if ( rContext.aArg.Operation == ucb::TransferCommandOperation_LINK )
572 lCompare = [](
const sal_Int32 nAttribs) {
return !!( nAttribs & ucb::ContentInfoAttribute::KIND_LINK ); };
574 else if ( ( rContext.aArg.Operation == ucb::TransferCommandOperation_COPY ) ||
575 ( rContext.aArg.Operation == ucb::TransferCommandOperation_MOVE ) )
581 lCompare = [](
const sal_Int32 nAttribs) {
return !!( nAttribs & ucb::ContentInfoAttribute::KIND_LINK ); };
587 lCompare = [bSourceIsFolder, bSourceIsDocument](
const sal_Int32 nAttribs) {
588 return ( bSourceIsFolder == !!( nAttribs & ucb::ContentInfoAttribute::KIND_FOLDER ) )
589 && ( bSourceIsDocument == !!( nAttribs & ucb::ContentInfoAttribute::KIND_DOCUMENT ) ) ;
596 uno::Any( lang::IllegalArgumentException(
597 "Unknown transfer operation!",
604 uno::Reference< ucb::XContent > xNew;
605 auto pTypeInfo = std::find_if(std::cbegin(aTypesInfo), std::cend(aTypesInfo),
606 [&lCompare](
const ucb::ContentInfo& rTypeInfo) {
return lCompare(rTypeInfo.Attributes); });
607 if (pTypeInfo != std::cend(aTypesInfo))
611 if ( !xCreator.is() )
615 ucb::Command aCreateNewCommand(
620 xCommandProcessorT->execute( aCreateNewCommand, 0, rContext.xEnv )
628 xNew = xCreator->createNewContent( *pTypeInfo );
635 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
638 ucb::IOErrorCode_CANT_CREATE,
641 "createNewContent failed!",
642 rContext.xProcessor );
651void transferProperties(
652 const TransferCommandContext & rContext,
653 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorS,
654 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorN )
656 ucb::Command aGetPropertySetInfoCommand(
657 "getPropertySetInfo",
661 uno::Reference< beans::XPropertySetInfo > xInfo;
662 xCommandProcessorS->execute( aGetPropertySetInfoCommand, 0, rContext.xEnv )
669 {
"Uri",
uno::Any(rContext.aArg.SourceURL)}
672 ucb::IOErrorCode_CANT_READ,
675 "Unable to get propertyset info from source object!",
676 rContext.xProcessor );
680 uno::Sequence< beans::Property > aAllProps = xInfo->getProperties();
682 ucb::Command aGetPropsCommand1(
687 uno::Reference< sdbc::XRow > xRow1;
688 xCommandProcessorS->execute(
689 aGetPropsCommand1, 0, rContext.xEnv ) >>= xRow1;
695 {
"Uri",
uno::Any(rContext.aArg.SourceURL)}
698 ucb::IOErrorCode_CANT_READ,
701 "Unable to get properties from source object!",
702 rContext.xProcessor );
709 uno::Sequence< beans::PropertyValue > aPropValues(
710 aAllProps.getLength() + 2 );
711 auto pPropValues = aPropValues.getArray();
713 bool bHasTitle = rContext.aArg.NewTitle.isEmpty();
714 bool bHasTargetURL = ( rContext.aArg.Operation
715 != ucb::TransferCommandOperation_LINK );
717 sal_Int32 nWritePos = 0;
718 for ( sal_Int32 m = 0;
m < aAllProps.getLength(); ++
m )
720 const beans::Property & rCurrProp = aAllProps[
m ];
721 beans::PropertyValue & rCurrValue = pPropValues[ nWritePos ];
725 if ( rCurrProp.Name ==
"Title" )
731 aValue <<= rContext.aArg.NewTitle;
734 else if ( rCurrProp.Name ==
"TargetURL" )
737 if ( !bHasTargetURL )
739 bHasTargetURL =
true;
740 aValue <<= rContext.aArg.SourceURL;
748 aValue = xRow1->getObject(
749 m + 1, uno::Reference< container::XNameAccess >() );
751 catch ( sdbc::SQLException
const & )
760 rCurrValue.Name = rCurrProp.Name;
761 rCurrValue.Handle = rCurrProp.Handle;
762 rCurrValue.
Value = aValue;
770 if ( !bHasTitle && !rContext.aArg.NewTitle.isEmpty() )
772 pPropValues[ nWritePos ].Name =
"Title";
773 pPropValues[ nWritePos ].Handle = -1;
774 pPropValues[ nWritePos ].
Value <<= rContext.aArg.NewTitle;
780 if ( !bHasTargetURL && ( rContext.aArg.Operation
781 == ucb::TransferCommandOperation_LINK ) )
783 pPropValues[ nWritePos ].Name =
"TargetURL";
784 pPropValues[ nWritePos ].Handle = -1;
785 pPropValues[ nWritePos ].Value <<= rContext.aArg.SourceURL;
790 aPropValues.realloc( nWritePos );
794 ucb::Command aSetPropsCommand(
799 xCommandProcessorN->execute( aSetPropsCommand, 0, rContext.xEnv );
806uno::Reference< io::XInputStream > getInputStream(
807 const TransferCommandContext & rContext,
808 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorS )
810 uno::Reference< io::XInputStream > xInputStream;
818 uno::Reference< io::XActiveDataSink >
xSink =
new ActiveDataSink;
820 ucb::OpenCommandArgument2 aArg;
824 aArg.Properties = uno::Sequence< beans::Property >( 0 );
826 ucb::Command aOpenCommand(
831 xCommandProcessorS->execute( aOpenCommand, 0, rContext.xEnv );
832 xInputStream =
xSink->getInputStream();
834 catch ( uno::RuntimeException
const & )
838 catch ( uno::Exception
const & )
843 if ( !xInputStream.is() )
852 uno::Reference< io::XOutputStream > xOutputStream( io::Pipe::create(rContext.m_xContext), uno::UNO_QUERY_THROW );
854 ucb::OpenCommandArgument2 aArg;
857 aArg.Sink = xOutputStream;
858 aArg.Properties = uno::Sequence< beans::Property >( 0 );
860 ucb::Command aOpenCommand(
865 xCommandProcessorS->execute( aOpenCommand, 0, rContext.xEnv );
867 xInputStream.set( xOutputStream, uno::UNO_QUERY );
869 catch ( uno::RuntimeException
const & )
873 catch ( uno::Exception
const & )
875 OSL_FAIL(
"unable to get input stream from document!" );
883uno::Reference< sdbc::XResultSet > getResultSet(
884 const TransferCommandContext & rContext,
885 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorS )
887 uno::Reference< sdbc::XResultSet > xResultSet;
889 uno::Sequence< beans::Property > aProps{ makeProperty(
"IsFolder", -1 ),
890 makeProperty(
"IsDocument", -1 ),
891 makeProperty(
"TargetURL", -1 ) };
893 ucb::OpenCommandArgument2 aArg;
894 aArg.Mode = ucb::OpenMode::ALL;
897 aArg.Properties = aProps;
899 ucb::Command aOpenCommand(
"open",
904 uno::Reference< ucb::XDynamicResultSet > xSet;
905 xCommandProcessorS->execute( aOpenCommand, 0, rContext.xEnv ) >>= xSet;
908 xResultSet = xSet->getStaticResultSet();
910 catch ( uno::RuntimeException
const & )
914 catch ( uno::Exception
const & )
916 OSL_FAIL(
"unable to get result set from folder!" );
923void handleNameClashRename(
924 const TransferCommandContext & rContext,
925 const uno::Reference< ucb::XContent > & xNew,
926 const uno::Reference<
927 ucb::XCommandProcessor > & xCommandProcessorN,
928 const uno::Reference<
929 ucb::XCommandProcessor > & xCommandProcessorS,
930 uno::Reference< io::XInputStream > & xInputStream )
935 uno::Sequence< beans::Property > aProps{ makeProperty(
"Title", -1) };
937 ucb::Command aGetPropsCommand(
942 uno::Reference< sdbc::XRow > xRow;
943 xCommandProcessorN->execute( aGetPropsCommand, 0, rContext.xEnv ) >>= xRow;
949 {
"Uri",
uno::Any(xNew->getIdentifier()->getContentIdentifier())}
952 ucb::IOErrorCode_CANT_READ,
955 "Unable to get properties from new object!",
956 rContext.xProcessor );
960 OUString aOldTitle = xRow->getString( 1 );
961 if ( aOldTitle.isEmpty() )
964 uno::Any( beans::UnknownPropertyException(
965 "Unable to get property 'Title' from new object!",
966 rContext.xProcessor ) ),
972 OUString aOldTitlePre;
973 OUString aOldTitlePost;
974 sal_Int32
nPos = aOldTitle.lastIndexOf(
'.' );
977 aOldTitlePre = aOldTitle.copy( 0, nPos );
978 aOldTitlePost = aOldTitle.copy( nPos );
981 aOldTitlePre = aOldTitle;
986 bool bContinue =
true;
991 OUString aNewTitle = aOldTitlePre + OUString::number( nTry ) +
995 setTitle( xCommandProcessorN, rContext.xEnv, aNewTitle );
1002 if ( xInputStream.is() )
1004 uno::Reference< io::XSeekable > xSeekable(
1005 xInputStream, uno::UNO_QUERY );
1006 if ( xSeekable.is() )
1010 xSeekable->seek( 0 );
1012 catch ( lang::IllegalArgumentException
const & )
1014 xInputStream.clear();
1016 catch ( io::IOException
const & )
1018 xInputStream.clear();
1022 xInputStream.clear();
1024 if ( !xInputStream.is() )
1027 = getInputStream( rContext, xCommandProcessorS );
1028 if ( !xInputStream.is() )
1032 {
"Uri",
uno::Any(xNew->getIdentifier()->getContentIdentifier())}
1035 ucb::IOErrorCode_CANT_READ,
1038 "Got no data stream from source!",
1039 rContext.xProcessor );
1045 ucb::InsertCommandArgument2 aArg;
1046 aArg.Data = xInputStream;
1047 aArg.ReplaceExisting =
false;
1049 ucb::Command aInsertCommand(
1054 xCommandProcessorN->execute( aInsertCommand, 0, rContext.xEnv );
1059 catch ( uno::RuntimeException
const & )
1063 catch ( uno::Exception
const & )
1067 while ( bContinue && ( nTry < 50 ) );
1073 ucb::UnsupportedNameClashException(
1074 "Unable to resolve name clash!",
1075 rContext.xProcessor,
1076 ucb::NameClash::RENAME ) ),
1077 rContext.xOrigEnv );
1083void globalTransfer_(
1084 const TransferCommandContext & rContext,
1085 const uno::Reference< ucb::XContent > & xSource,
1086 const uno::Reference< ucb::XContent > & xTarget,
1087 const uno::Reference< sdbc::XRow > & xSourceProps )
1090 bool bSourceIsFolder = xSourceProps->getBoolean( 1 );
1091 if ( !bSourceIsFolder && xSourceProps->wasNull() )
1094 uno::Any( beans::UnknownPropertyException(
1095 "Unable to get property 'IsFolder' from source object!",
1096 rContext.xProcessor ) ),
1097 rContext.xOrigEnv );
1102 bool bSourceIsDocument = xSourceProps->getBoolean( 2 );
1103 if ( !bSourceIsDocument && xSourceProps->wasNull() )
1106 uno::Any( beans::UnknownPropertyException(
1107 "Unable to get property 'IsDocument' from source object!",
1108 rContext.xProcessor ) ),
1109 rContext.xOrigEnv );
1114 bool bSourceIsLink = !xSourceProps->getString( 3 ).isEmpty();
1121 uno::Reference< ucb::XContent > xNew = createNew( rContext,
1130 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
1133 ucb::IOErrorCode_CANT_CREATE,
1136 "No matching content type at target!",
1137 rContext.xProcessor );
1145 uno::Reference< ucb::XCommandProcessor > xCommandProcessorN(
1146 xNew, uno::UNO_QUERY );
1147 if ( !xCommandProcessorN.is() )
1149 uno::Any aProps(beans::PropertyValue(
1153 xNew->getIdentifier()->
1154 getContentIdentifier()),
1155 beans::PropertyState_DIRECT_VALUE));
1157 ucb::IOErrorCode_CANT_WRITE,
1158 uno::Sequence< uno::Any >(&aProps, 1),
1160 "New content is not a XCommandProcessor!",
1161 rContext.xProcessor );
1167 uno::Reference< ucb::XCommandProcessor > xCommandProcessorS(
1168 xSource, uno::UNO_QUERY );
1169 if ( !xCommandProcessorS.is() )
1173 {
"Uri",
uno::Any(rContext.aArg.SourceURL)}
1176 ucb::IOErrorCode_CANT_READ,
1179 "Source content is not a XCommandProcessor!",
1180 rContext.xProcessor );
1184 transferProperties( rContext, xCommandProcessorS, xCommandProcessorN );
1190 uno::Reference< io::XInputStream > xInputStream;
1192 if ( bSourceIsDocument && ( rContext.aArg.Operation
1193 != ucb::TransferCommandOperation_LINK ) )
1194 xInputStream = getInputStream( rContext, xCommandProcessorS );
1200 uno::Reference< sdbc::XResultSet > xResultSet;
1202 if ( bSourceIsFolder && ( rContext.aArg.Operation
1203 != ucb::TransferCommandOperation_LINK ) )
1204 xResultSet = getResultSet( rContext, xCommandProcessorS );
1210 ucb::InsertCommandArgument2 aArg;
1211 aArg.Data = xInputStream;
1212 aArg.MimeType = rContext.aArg.MimeType;
1213 aArg.DocumentId = rContext.aArg.DocumentId;
1215 switch ( rContext.aArg.NameClash )
1217 case ucb::NameClash::OVERWRITE:
1218 aArg.ReplaceExisting =
true;
1221 case ucb::NameClash::ERROR:
1222 case ucb::NameClash::RENAME:
1223 case ucb::NameClash::KEEP:
1224 case ucb::NameClash::ASK:
1225 aArg.ReplaceExisting =
false;
1229 aArg.ReplaceExisting =
false;
1230 OSL_FAIL(
"Unknown nameclash directive!" );
1234 OUString aDesiredName = createDesiredName( rContext.aArg );
1243 ucb::Command aInsertCommand(
1248 xCommandProcessorN->execute( aInsertCommand, 0, rContext.xEnv );
1250 catch ( ucb::UnsupportedNameClashException
const & exc )
1252 OSL_ENSURE( !aArg.ReplaceExisting,
1253 "BUG: UnsupportedNameClashException not allowed here!" );
1255 if (exc.NameClash != ucb::NameClash::ERROR) {
1256 OSL_FAIL(
"BUG: NameClash::ERROR expected!" );
1261 throw ucb::UnsupportedNameClashException(
1262 "Unable to resolve name clashes, no chance to detect "
1263 "that there is one!",
1264 rContext.xProcessor,
1265 rContext.aArg.NameClash );
1267 catch ( ucb::NameClashException
const & )
1282 switch ( rContext.aArg.NameClash )
1284 case ucb::NameClash::OVERWRITE:
1288 ucb::UnsupportedNameClashException(
1289 "BUG: insert + replace == true MUST NOT "
1290 "throw NameClashException.",
1291 rContext.xProcessor,
1292 rContext.aArg.NameClash ) ),
1293 rContext.xOrigEnv );
1297 case ucb::NameClash::ERROR:
1300 case ucb::NameClash::RENAME:
1303 handleNameClashRename( rContext,
1311 case ucb::NameClash::ASK:
1315 NameClashContinuation eCont
1316 = interactiveNameClashResolve(
1318 rContext.aArg.TargetURL,
1335 throw ucb::CommandFailedException(
1336 "abort requested via interaction "
1338 uno::Reference< uno::XInterface >(),
1343 OSL_ENSURE( !aArg.ReplaceExisting,
1344 "Hu? ReplaceExisting already true?"
1346 aArg.ReplaceExisting =
true;
1353 if ( setTitle( xCommandProcessorN,
1358 aDesiredName = aNewTitle;
1366 throw ucb::CommandFailedException(
1367 "error setting Title property!",
1368 uno::Reference< uno::XInterface >(),
1375 OSL_ENSURE( bRetry,
"bRetry must be true here!!!" );
1379 case ucb::NameClash::KEEP:
1384 ucb::UnsupportedNameClashException(
1385 "default action, don't know how to "
1386 "handle name clash",
1387 rContext.xProcessor,
1388 rContext.aArg.NameClash ) ),
1389 rContext.xOrigEnv );
1401 if ( xResultSet.is() )
1407 uno::Reference< sdbc::XRow > xChildRow(
1408 xResultSet, uno::UNO_QUERY );
1410 if ( !xChildRow.is() )
1413 beans::PropertyValue(
1417 beans::PropertyState_DIRECT_VALUE));
1419 ucb::IOErrorCode_CANT_READ,
1420 uno::Sequence< uno::Any >(&aProps, 1),
1422 "Unable to get properties from children of source!",
1423 rContext.xProcessor );
1427 uno::Reference< ucb::XContentAccess > xChildAccess(
1428 xResultSet, uno::UNO_QUERY );
1430 if ( !xChildAccess.is() )
1434 {
"Uri",
uno::Any(rContext.aArg.SourceURL)}
1437 ucb::IOErrorCode_CANT_READ,
1440 "Unable to get children of source!",
1441 rContext.xProcessor );
1445 if ( xResultSet->first() )
1447 ucb::GlobalTransferCommandArgument2 aTransArg(
1448 rContext.aArg.Operation,
1450 xNew->getIdentifier()
1451 ->getContentIdentifier(),
1453 rContext.aArg.NameClash,
1454 rContext.aArg.MimeType,
1455 rContext.aArg.DocumentId);
1457 TransferCommandContext aSubCtx(
1458 rContext.m_xContext,
1459 rContext.xProcessor,
1462 std::move(aTransArg) );
1465 uno::Reference< ucb::XContent > xChild
1466 = xChildAccess->queryContent();
1471 aSubCtx.aArg.SourceURL
1472 = xChild->getIdentifier()->getContentIdentifier();
1474 globalTransfer_( aSubCtx,
1480 while ( xResultSet->next() );
1483 catch ( sdbc::SQLException
const & )
1489 uno::Reference< ucb::XCommandProcessor > xcp(
1490 xTarget, uno::UNO_QUERY );
1493 uno::Reference< ucb::XCommandInfo > xci;
1504 static constexpr OUStringLiteral cmdName(u
"flush");
1505 if((aAny >>= xci) && xci->hasCommandByName(cmdName))
1514 catch( uno::Exception
const & )
1525uno::Reference< ucb::XCommandInfo >
1528 return uno::Reference< ucb::XCommandInfo >(
new CommandProcessorInfo() );
1533 const ucb::GlobalTransferCommandArgument2 & rArg,
1534 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1539 uno::Reference< ucb::XCommandEnvironment > xLocalEnv;
1542 xLocalEnv.set( ucb::CommandEnvironment::create(
1544 new InteractionHandlerProxy( xEnv->getInteractionHandler() ),
1545 xEnv->getProgressHandler() ) );
1552 uno::Reference< ucb::XContent >
xTarget;
1553 uno::Reference< ucb::XContentIdentifier > xId
1561 catch ( ucb::IllegalIdentifierException
const & )
1573 ucb::IOErrorCode_CANT_READ,
1576 "Can't instantiate target object!",
1581 if ( ( rArg.Operation == ucb::TransferCommandOperation_COPY ) ||
1582 ( rArg.Operation == ucb::TransferCommandOperation_MOVE ) )
1584 uno::Reference< ucb::XCommandProcessor > xCommandProcessor(
1586 if ( !xCommandProcessor.is() )
1593 ucb::IOErrorCode_CANT_READ,
1596 "Target content is not a XCommandProcessor!",
1601 ucb::TransferInfo2 aTransferArg(
1603 == ucb::TransferCommandOperation_MOVE ),
1621 xCommandProcessor->execute(
aCommand, 0, xLocalEnv );
1626 catch ( ucb::InteractiveBadTransferURLException
const & )
1631 catch ( ucb::UnsupportedCommandException
const & )
1636 catch ( ucb::UnsupportedNameClashException
const & exc )
1638 OSL_ENSURE( aTransferArg.NameClash == exc.NameClash,
1639 "nameclash mismatch!" );
1640 if ( exc.NameClash == ucb::NameClash::ASK )
1646 ucb::TransferInfo2 aTransferArg1(
1647 aTransferArg.MoveData,
1648 aTransferArg.SourceURL,
1649 aTransferArg.NewTitle,
1650 ucb::NameClash::ERROR,
1651 aTransferArg.MimeType );
1653 ucb::Command aCommand1(
1658 xCommandProcessor->execute( aCommand1, 0, xLocalEnv );
1663 catch ( ucb::UnsupportedNameClashException
const & )
1669 catch ( ucb::NameClashException
const & )
1675 NameClashContinuation eCont
1676 = interactiveNameClashResolve(
1696 throw ucb::CommandFailedException(
1697 "abort requested via interaction "
1699 uno::Reference< uno::XInterface >(),
1704 aTransferArg.NameClash
1705 = ucb::NameClash::OVERWRITE;
1710 aTransferArg.NewTitle = aNewTitle;
1715 OSL_ENSURE( bRetry,
"bRetry must be true here!!!" );
1731 uno::Reference< ucb::XContent > xSource;
1734 uno::Reference< ucb::XContentIdentifier > xId2
1739 catch ( ucb::IllegalIdentifierException
const & )
1744 if ( !xSource.is() )
1751 ucb::IOErrorCode_CANT_READ,
1754 "Can't instantiate source object!",
1759 uno::Reference< ucb::XCommandProcessor > xCommandProcessor(
1760 xSource, uno::UNO_QUERY );
1761 if ( !xCommandProcessor.is() )
1768 ucb::IOErrorCode_CANT_READ,
1771 "Source content is not a XCommandProcessor!",
1778 uno::Sequence< beans::Property > aProps{ makeProperty(
"IsFolder", -1 ),
1779 makeProperty(
"IsDocument", -1 ),
1780 makeProperty(
"TargetURL", -1 ),
1781 makeProperty(
"BaseURI", -1 ) };
1783 ucb::Command aGetPropsCommand(
1784 "getPropertyValues",
1788 uno::Reference< sdbc::XRow > xRow;
1789 xCommandProcessor->execute( aGetPropsCommand, 0, xLocalEnv ) >>= xRow;
1798 ucb::IOErrorCode_CANT_READ,
1801 "Unable to get properties from source object!",
1806 TransferCommandContext aTransferCtx(
1809 if ( rArg.NewTitle.isEmpty() )
1812 OUString aBaseURI( xRow->getString( 4 ) );
1813 if ( !aBaseURI.isEmpty() )
1815 aTransferCtx.aArg.NewTitle
1816 = createDesiredName( aBaseURI, OUString() );
1821 globalTransfer_( aTransferCtx, xSource,
xTarget, xRow );
1827 if ( rArg.Operation != ucb::TransferCommandOperation_MOVE )
1837 xCommandProcessor->execute(
aCommand, 0, xLocalEnv );
1839 catch ( uno::Exception
const & )
1841 OSL_FAIL(
"Cannot delete source object!" );
1847 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1853 uno::Reference< ucb::XCommandEnvironment > xLocalEnv;
1856 xLocalEnv.set( ucb::CommandEnvironment::create(
1858 new InteractionHandlerProxy( xEnv->getInteractionHandler() ),
1859 xEnv->getProgressHandler() ) );
1862 uno::Reference< ucb::XContent >
xTarget;
1863 uno::Reference< ucb::XContentIdentifier > xId
1871 catch ( ucb::IllegalIdentifierException
const & )
1883 ucb::IOErrorCode_CANT_READ,
1886 "Can't instantiate target object!",
1891 uno::Reference< ucb::XCommandProcessor > xCommandProcessor(
1893 if ( !xCommandProcessor.is() )
1900 ucb::IOErrorCode_CANT_READ,
1903 "Target content is not a XCommandProcessor!",
1914 aRet = xCommandProcessor->execute(
aCommand, 0, xLocalEnv );
1916 catch ( ucb::UnsupportedCommandException
const & )
Reference< XComponentContext > m_xContext
::rtl::Reference< IEventProcessor > xProcessor
static css::uno::Reference< css::ucb::XCommandInfo > getCommandInfo()
css::uno::Reference< css::uno::XComponentContext > m_xContext
void globalTransfer(const css::ucb::GlobalTransferCommandArgument2 &rArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
css::uno::Any checkIn(const css::ucb::CheckinArgument &rArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL createContentIdentifier(const OUString &ContentId) override
Reference< XInterface > xTarget
Reference< beans::XPropertySetInfo > m_xInfo
tools::SvRef< SvBaseLink > xSink
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
void SAL_CALL throwException(Any const &exc)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
constexpr OUStringLiteral GLOBALTRANSFER_NAME
constexpr OUStringLiteral CHECKIN_NAME
#define GLOBALTRANSFER_HANDLE
constexpr OUStringLiteral GETCOMMANDINFO_NAME
#define GETCOMMANDINFO_HANDLE
Reference< XStream > m_xStream