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>
69beans::Property makeProperty(
const OUString& n, sal_Int32 h,
uno::Type t = {}, sal_Int16
a = {})
71 return {
n,
h,
t,
a };
77struct TransferCommandContext
79 uno::Reference< uno::XComponentContext >
m_xContext;
80 uno::Reference< ucb::XCommandProcessor >
xProcessor;
81 uno::Reference< ucb::XCommandEnvironment > xEnv;
82 uno::Reference< ucb::XCommandEnvironment > xOrigEnv;
83 ucb::GlobalTransferCommandArgument2 aArg;
85 TransferCommandContext(
86 const uno::Reference< uno::XComponentContext > & xContext,
87 const uno::Reference< ucb::XCommandProcessor > & rxProcessor,
88 const uno::Reference< ucb::XCommandEnvironment > & rxEnv,
89 const uno::Reference< ucb::XCommandEnvironment > & rxOrigEnv,
90 const ucb::GlobalTransferCommandArgument2 & rArg )
92 xOrigEnv( rxOrigEnv ), aArg( rArg ) {}
98class InteractionHandlerProxy :
99 public cppu::WeakImplHelper< task::XInteractionHandler >
101 uno::Reference< task::XInteractionHandler > m_xOrig;
104 explicit InteractionHandlerProxy(
105 const uno::Reference< task::XInteractionHandler > & xOrig )
106 : m_xOrig( xOrig ) {}
109 virtual void SAL_CALL handle(
110 const uno::Reference< task::XInteractionRequest >& Request )
override;
115void SAL_CALL InteractionHandlerProxy::handle(
116 const uno::Reference< task::XInteractionRequest >& Request )
122 uno::Any aRequest = Request->getRequest();
125 ucb::InteractiveBadTransferURLException aBadTransferURLEx;
126 if ( aRequest >>= aBadTransferURLEx )
133 ucb::UnsupportedNameClashException aUnsupportedNameClashEx;
134 if ( aRequest >>= aUnsupportedNameClashEx )
136 if ( aUnsupportedNameClashEx.NameClash
137 != ucb::NameClash::ERROR )
143 ucb::NameClashException aNameClashEx;
144 if ( aRequest >>= aNameClashEx )
151 ucb::UnsupportedCommandException aUnsupportedCommandEx;
152 if ( aRequest >>= aUnsupportedCommandEx )
161 m_xOrig->handle( Request );
167class ActiveDataSink :
public cppu::WeakImplHelper< io::XActiveDataSink >
169 uno::Reference< io::XInputStream >
m_xStream;
173 virtual void SAL_CALL setInputStream(
174 const uno::Reference< io::XInputStream >& aStream )
override;
175 virtual uno::Reference< io::XInputStream > SAL_CALL getInputStream()
override;
180void SAL_CALL ActiveDataSink::setInputStream(
181 const uno::Reference< io::XInputStream >& aStream )
188uno::Reference< io::XInputStream > SAL_CALL ActiveDataSink::getInputStream()
196class CommandProcessorInfo :
197 public cppu::WeakImplHelper< ucb::XCommandInfo >
199 uno::Sequence< ucb::CommandInfo >
m_xInfo;
202 CommandProcessorInfo();
205 virtual uno::Sequence< ucb::CommandInfo > SAL_CALL getCommands()
override;
206 virtual ucb::CommandInfo SAL_CALL
207 getCommandInfoByName(
const OUString& Name )
override;
208 virtual ucb::CommandInfo SAL_CALL
209 getCommandInfoByHandle( sal_Int32 Handle )
override;
210 virtual sal_Bool SAL_CALL hasCommandByName(
const OUString& Name )
override;
211 virtual sal_Bool SAL_CALL hasCommandByHandle( sal_Int32 Handle )
override;
215CommandProcessorInfo::CommandProcessorInfo()
224 cppu::UnoType<
ucb::GlobalTransferCommandArgument>::
get() ),
228 cppu::UnoType<
ucb::CheckinArgument>::
get() ) }
234uno::Sequence< ucb::CommandInfo > SAL_CALL
235CommandProcessorInfo::getCommands()
242ucb::CommandInfo SAL_CALL
243CommandProcessorInfo::getCommandInfoByName(
const OUString& Name )
245 auto pInfo = std::find_if(std::cbegin(m_xInfo), std::cend(m_xInfo),
246 [&Name](
const ucb::CommandInfo& rInfo) {
return rInfo.Name ==
Name; });
247 if (pInfo != std::cend(m_xInfo))
250 throw ucb::UnsupportedCommandException();
255ucb::CommandInfo SAL_CALL
256CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
258 auto pInfo = std::find_if(std::cbegin(m_xInfo), std::cend(m_xInfo),
259 [&Handle](
const ucb::CommandInfo& rInfo) {
return rInfo.Handle ==
Handle; });
260 if (pInfo != std::cend(m_xInfo))
263 throw ucb::UnsupportedCommandException();
268sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
269 const OUString& Name )
271 return std::any_of(std::cbegin(m_xInfo), std::cend(m_xInfo),
272 [&Name](
const ucb::CommandInfo& rInfo) {
return rInfo.Name ==
Name; });
277sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle )
279 return std::any_of(std::cbegin(m_xInfo), std::cend(m_xInfo),
280 [&Handle](
const ucb::CommandInfo& rInfo) {
return rInfo.Handle ==
Handle; });
284OUString createDesiredName(
285 const OUString & rSourceURL,
const OUString & rNewTitle )
287 OUString
aName( rNewTitle );
288 if (
aName.isEmpty() )
300 sal_Int32 nLastSlash = rSourceURL.lastIndexOf(
'/' );
301 bool bTrailingSlash =
false;
302 if ( nLastSlash == rSourceURL.getLength() - 1 )
304 nLastSlash = rSourceURL.lastIndexOf(
'/', nLastSlash );
305 bTrailingSlash =
true;
308 if ( nLastSlash != -1 )
310 if ( bTrailingSlash )
311 aName = rSourceURL.copy(
313 rSourceURL.getLength() - nLastSlash - 2 );
315 aName = rSourceURL.copy( nLastSlash + 1 );
333OUString createDesiredName(
334 const ucb::GlobalTransferCommandArgument & rArg )
336 return createDesiredName( rArg.SourceURL, rArg.NewTitle );
339OUString createDesiredName(
340 const ucb::TransferInfo & rArg )
342 return createDesiredName( rArg.SourceURL, rArg.NewTitle );
348NameClashContinuation interactiveNameClashResolve(
349 const uno::Reference< ucb::XCommandEnvironment > & xEnv,
350 const OUString & rTargetURL,
351 const OUString & rClashingName,
353 OUString & rNewName )
356 new ucbhelper::SimpleNameClashResolveRequest(
361 rException = xRequest->getRequest();
364 uno::Reference< task::XInteractionHandler > xIH
365 = xEnv->getInteractionHandler();
369 xIH->handle( xRequest );
372 xSelection( xRequest->getSelection() );
374 if ( xSelection.is() )
377 uno::Reference< task::XInteractionAbort > xAbort(
378 xSelection.get(), uno::UNO_QUERY );
387 ucb::XInteractionReplaceExistingData >
389 xSelection.get(), uno::UNO_QUERY );
398 ucb::XInteractionSupplyName >
400 xSelection.get(), uno::UNO_QUERY );
401 if ( xSupplyName.is() )
404 rNewName = xRequest->getNewName();
409 OSL_FAIL(
"Unknown interaction continuation!" );
422 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessor,
423 const uno::Reference< ucb::XCommandEnvironment > & xEnv,
424 const OUString & rNewTitle )
428 uno::Sequence< beans::PropertyValue > aPropValues{ {
"Title",
433 ucb::Command aSetPropsCommand(
439 = xCommandProcessor->execute( aSetPropsCommand, 0, xEnv );
441 uno::Sequence< uno::Any > aErrors;
444 OSL_ENSURE( aErrors.getLength() == 1,
445 "getPropertyValues return value invalid!" );
447 if ( aErrors[ 0 ].hasValue() )
450 OSL_FAIL(
"error setting Title property!" );
454 catch ( uno::RuntimeException
const & )
458 catch ( uno::Exception
const & )
467uno::Reference< ucb::XContent > createNew(
468 const TransferCommandContext & rContext,
469 const uno::Reference< ucb::XContent > & xTarget,
470 bool bSourceIsFolder,
471 bool bSourceIsDocument,
482 uno::Reference< ucb::XCommandProcessor > xCommandProcessorT(
483 xTarget, uno::UNO_QUERY );
484 if ( !xCommandProcessorT.is() )
488 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
491 ucb::IOErrorCode_CANT_CREATE,
494 "Target is no XCommandProcessor!",
495 rContext.xProcessor );
499 uno::Sequence< beans::Property > aPropsToObtain{ makeProperty(
"CreatableContentsInfo", -1) };
501 ucb::Command aGetPropsCommand(
506 uno::Reference< sdbc::XRow >
xRow;
507 xCommandProcessorT->execute( aGetPropsCommand, 0, rContext.xEnv ) >>=
xRow;
509 uno::Sequence< ucb::ContentInfo > aTypesInfo;
510 bool bGotTypesInfo =
false;
515 1, uno::Reference< container::XNameAccess >() );
516 if ( aValue.
hasValue() && ( aValue >>= aTypesInfo ) )
518 bGotTypesInfo =
true;
522 uno::Reference< ucb::XContentCreator > xCreator;
524 if ( !bGotTypesInfo )
529 xCreator.set( xTarget, uno::UNO_QUERY );
531 if ( !xCreator.is() )
535 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
538 ucb::IOErrorCode_CANT_CREATE,
541 "Target is no XContentCreator!",
542 rContext.xProcessor );
546 aTypesInfo = xCreator->queryCreatableContentsInfo();
549 if ( !aTypesInfo.hasElements() )
553 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
556 ucb::IOErrorCode_CANT_CREATE,
559 "No types creatable!",
560 rContext.xProcessor );
566 std::function<bool(
const sal_Int32)> lCompare;
568 if ( rContext.aArg.Operation == ucb::TransferCommandOperation_LINK )
571 lCompare = [](
const sal_Int32 nAttribs) {
return !!( nAttribs & ucb::ContentInfoAttribute::KIND_LINK ); };
573 else if ( ( rContext.aArg.Operation == ucb::TransferCommandOperation_COPY ) ||
574 ( rContext.aArg.Operation == ucb::TransferCommandOperation_MOVE ) )
580 lCompare = [](
const sal_Int32 nAttribs) {
return !!( nAttribs & ucb::ContentInfoAttribute::KIND_LINK ); };
586 lCompare = [bSourceIsFolder, bSourceIsDocument](
const sal_Int32 nAttribs) {
587 return ( bSourceIsFolder == !!( nAttribs & ucb::ContentInfoAttribute::KIND_FOLDER ) )
588 && ( bSourceIsDocument == !!( nAttribs & ucb::ContentInfoAttribute::KIND_DOCUMENT ) ) ;
595 uno::Any( lang::IllegalArgumentException(
596 "Unknown transfer operation!",
603 uno::Reference< ucb::XContent > xNew;
604 auto pTypeInfo = std::find_if(std::cbegin(aTypesInfo), std::cend(aTypesInfo),
605 [&lCompare](
const ucb::ContentInfo& rTypeInfo) {
return lCompare(rTypeInfo.Attributes); });
606 if (pTypeInfo != std::cend(aTypesInfo))
610 if ( !xCreator.is() )
614 ucb::Command aCreateNewCommand(
619 xCommandProcessorT->execute( aCreateNewCommand, 0, rContext.xEnv )
627 xNew = xCreator->createNewContent( *pTypeInfo );
634 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
637 ucb::IOErrorCode_CANT_CREATE,
640 "createNewContent failed!",
641 rContext.xProcessor );
650void transferProperties(
651 const TransferCommandContext & rContext,
652 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorS,
653 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorN )
655 ucb::Command aGetPropertySetInfoCommand(
656 "getPropertySetInfo",
660 uno::Reference< beans::XPropertySetInfo > xInfo;
661 xCommandProcessorS->execute( aGetPropertySetInfoCommand, 0, rContext.xEnv )
668 {
"Uri",
uno::Any(rContext.aArg.SourceURL)}
671 ucb::IOErrorCode_CANT_READ,
674 "Unable to get propertyset info from source object!",
675 rContext.xProcessor );
679 uno::Sequence< beans::Property > aAllProps = xInfo->getProperties();
681 ucb::Command aGetPropsCommand1(
686 uno::Reference< sdbc::XRow > xRow1;
687 xCommandProcessorS->execute(
688 aGetPropsCommand1, 0, rContext.xEnv ) >>= xRow1;
694 {
"Uri",
uno::Any(rContext.aArg.SourceURL)}
697 ucb::IOErrorCode_CANT_READ,
700 "Unable to get properties from source object!",
701 rContext.xProcessor );
708 uno::Sequence< beans::PropertyValue > aPropValues(
709 aAllProps.getLength() + 2 );
710 auto pPropValues = aPropValues.getArray();
712 bool bHasTitle = rContext.aArg.NewTitle.isEmpty();
713 bool bHasTargetURL = ( rContext.aArg.Operation
714 != ucb::TransferCommandOperation_LINK );
716 sal_Int32 nWritePos = 0;
717 for ( sal_Int32 m = 0;
m < aAllProps.getLength(); ++
m )
719 const beans::Property & rCurrProp = aAllProps[
m ];
720 beans::PropertyValue & rCurrValue = pPropValues[ nWritePos ];
724 if ( rCurrProp.Name ==
"Title" )
730 aValue <<= rContext.aArg.NewTitle;
733 else if ( rCurrProp.Name ==
"TargetURL" )
736 if ( !bHasTargetURL )
738 bHasTargetURL =
true;
739 aValue <<= rContext.aArg.SourceURL;
747 aValue = xRow1->getObject(
748 m + 1, uno::Reference< container::XNameAccess >() );
750 catch ( sdbc::SQLException
const & )
759 rCurrValue.Name = rCurrProp.Name;
760 rCurrValue.Handle = rCurrProp.Handle;
761 rCurrValue.
Value = aValue;
769 if ( !bHasTitle && !rContext.aArg.NewTitle.isEmpty() )
771 pPropValues[ nWritePos ].Name =
"Title";
772 pPropValues[ nWritePos ].Handle = -1;
773 pPropValues[ nWritePos ].
Value <<= rContext.aArg.NewTitle;
779 if ( !bHasTargetURL && ( rContext.aArg.Operation
780 == ucb::TransferCommandOperation_LINK ) )
782 pPropValues[ nWritePos ].Name =
"TargetURL";
783 pPropValues[ nWritePos ].Handle = -1;
784 pPropValues[ nWritePos ].Value <<= rContext.aArg.SourceURL;
789 aPropValues.realloc( nWritePos );
793 ucb::Command aSetPropsCommand(
798 xCommandProcessorN->execute( aSetPropsCommand, 0, rContext.xEnv );
805uno::Reference< io::XInputStream > getInputStream(
806 const TransferCommandContext & rContext,
807 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorS )
809 uno::Reference< io::XInputStream > xInputStream;
817 uno::Reference< io::XActiveDataSink >
xSink =
new ActiveDataSink;
819 ucb::OpenCommandArgument2 aArg;
823 aArg.Properties = uno::Sequence< beans::Property >( 0 );
825 ucb::Command aOpenCommand(
830 xCommandProcessorS->execute( aOpenCommand, 0, rContext.xEnv );
831 xInputStream =
xSink->getInputStream();
833 catch ( uno::RuntimeException
const & )
837 catch ( uno::Exception
const & )
842 if ( !xInputStream.is() )
851 uno::Reference< io::XOutputStream > xOutputStream( io::Pipe::create(rContext.m_xContext), uno::UNO_QUERY_THROW );
853 ucb::OpenCommandArgument2 aArg;
856 aArg.Sink = xOutputStream;
857 aArg.Properties = uno::Sequence< beans::Property >( 0 );
859 ucb::Command aOpenCommand(
864 xCommandProcessorS->execute( aOpenCommand, 0, rContext.xEnv );
866 xInputStream.set( xOutputStream, uno::UNO_QUERY );
868 catch ( uno::RuntimeException
const & )
872 catch ( uno::Exception
const & )
874 OSL_FAIL(
"unable to get input stream from document!" );
882uno::Reference< sdbc::XResultSet > getResultSet(
883 const TransferCommandContext & rContext,
884 const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorS )
886 uno::Reference< sdbc::XResultSet > xResultSet;
888 uno::Sequence< beans::Property > aProps{ makeProperty(
"IsFolder", -1 ),
889 makeProperty(
"IsDocument", -1 ),
890 makeProperty(
"TargetURL", -1 ) };
892 ucb::OpenCommandArgument2 aArg;
893 aArg.Mode = ucb::OpenMode::ALL;
896 aArg.Properties = aProps;
898 ucb::Command aOpenCommand(
"open",
903 uno::Reference< ucb::XDynamicResultSet > xSet;
904 xCommandProcessorS->execute( aOpenCommand, 0, rContext.xEnv ) >>= xSet;
907 xResultSet = xSet->getStaticResultSet();
909 catch ( uno::RuntimeException
const & )
913 catch ( uno::Exception
const & )
915 OSL_FAIL(
"unable to get result set from folder!" );
922void handleNameClashRename(
923 const TransferCommandContext & rContext,
924 const uno::Reference< ucb::XContent > & xNew,
925 const uno::Reference<
926 ucb::XCommandProcessor > & xCommandProcessorN,
927 const uno::Reference<
928 ucb::XCommandProcessor > & xCommandProcessorS,
929 uno::Reference< io::XInputStream > & xInputStream )
934 uno::Sequence< beans::Property > aProps{ makeProperty(
"Title", -1) };
936 ucb::Command aGetPropsCommand(
941 uno::Reference< sdbc::XRow >
xRow;
942 xCommandProcessorN->execute( aGetPropsCommand, 0, rContext.xEnv ) >>=
xRow;
948 {
"Uri",
uno::Any(xNew->getIdentifier()->getContentIdentifier())}
951 ucb::IOErrorCode_CANT_READ,
954 "Unable to get properties from new object!",
955 rContext.xProcessor );
959 OUString aOldTitle =
xRow->getString( 1 );
960 if ( aOldTitle.isEmpty() )
963 uno::Any( beans::UnknownPropertyException(
964 "Unable to get property 'Title' from new object!",
965 rContext.xProcessor ) ),
971 OUString aOldTitlePre;
972 OUString aOldTitlePost;
973 sal_Int32
nPos = aOldTitle.lastIndexOf(
'.' );
976 aOldTitlePre = aOldTitle.copy( 0, nPos );
977 aOldTitlePost = aOldTitle.copy( nPos );
980 aOldTitlePre = aOldTitle;
985 bool bContinue =
true;
990 OUString aNewTitle = aOldTitlePre + OUString::number( nTry ) +
994 setTitle( xCommandProcessorN, rContext.xEnv, aNewTitle );
1001 if ( xInputStream.is() )
1003 uno::Reference< io::XSeekable > xSeekable(
1004 xInputStream, uno::UNO_QUERY );
1005 if ( xSeekable.is() )
1009 xSeekable->seek( 0 );
1011 catch ( lang::IllegalArgumentException
const & )
1013 xInputStream.clear();
1015 catch ( io::IOException
const & )
1017 xInputStream.clear();
1021 xInputStream.clear();
1023 if ( !xInputStream.is() )
1026 = getInputStream( rContext, xCommandProcessorS );
1027 if ( !xInputStream.is() )
1031 {
"Uri",
uno::Any(xNew->getIdentifier()->getContentIdentifier())}
1034 ucb::IOErrorCode_CANT_READ,
1037 "Got no data stream from source!",
1038 rContext.xProcessor );
1044 ucb::InsertCommandArgument2 aArg;
1045 aArg.Data = xInputStream;
1046 aArg.ReplaceExisting =
false;
1048 ucb::Command aInsertCommand(
1053 xCommandProcessorN->execute( aInsertCommand, 0, rContext.xEnv );
1058 catch ( uno::RuntimeException
const & )
1062 catch ( uno::Exception
const & )
1066 while ( bContinue && ( nTry < 50 ) );
1072 ucb::UnsupportedNameClashException(
1073 "Unable to resolve name clash!",
1074 rContext.xProcessor,
1075 ucb::NameClash::RENAME ) ),
1076 rContext.xOrigEnv );
1082void globalTransfer_(
1083 const TransferCommandContext & rContext,
1084 const uno::Reference< ucb::XContent > & xSource,
1085 const uno::Reference< ucb::XContent > & xTarget,
1086 const uno::Reference< sdbc::XRow > & xSourceProps )
1089 bool bSourceIsFolder = xSourceProps->getBoolean( 1 );
1090 if ( !bSourceIsFolder && xSourceProps->wasNull() )
1093 uno::Any( beans::UnknownPropertyException(
1094 "Unable to get property 'IsFolder' from source object!",
1095 rContext.xProcessor ) ),
1096 rContext.xOrigEnv );
1101 bool bSourceIsDocument = xSourceProps->getBoolean( 2 );
1102 if ( !bSourceIsDocument && xSourceProps->wasNull() )
1105 uno::Any( beans::UnknownPropertyException(
1106 "Unable to get property 'IsDocument' from source object!",
1107 rContext.xProcessor ) ),
1108 rContext.xOrigEnv );
1113 bool bSourceIsLink = !xSourceProps->getString( 3 ).isEmpty();
1120 uno::Reference< ucb::XContent > xNew = createNew( rContext,
1129 {
"Folder",
uno::Any(rContext.aArg.TargetURL)}
1132 ucb::IOErrorCode_CANT_CREATE,
1135 "No matching content type at target!",
1136 rContext.xProcessor );
1144 uno::Reference< ucb::XCommandProcessor > xCommandProcessorN(
1145 xNew, uno::UNO_QUERY );
1146 if ( !xCommandProcessorN.is() )
1148 uno::Any aProps(beans::PropertyValue(
1152 xNew->getIdentifier()->
1153 getContentIdentifier()),
1154 beans::PropertyState_DIRECT_VALUE));
1156 ucb::IOErrorCode_CANT_WRITE,
1157 uno::Sequence< uno::Any >(&aProps, 1),
1159 "New content is not a XCommandProcessor!",
1160 rContext.xProcessor );
1166 uno::Reference< ucb::XCommandProcessor > xCommandProcessorS(
1167 xSource, uno::UNO_QUERY );
1168 if ( !xCommandProcessorS.is() )
1172 {
"Uri",
uno::Any(rContext.aArg.SourceURL)}
1175 ucb::IOErrorCode_CANT_READ,
1178 "Source content is not a XCommandProcessor!",
1179 rContext.xProcessor );
1183 transferProperties( rContext, xCommandProcessorS, xCommandProcessorN );
1189 uno::Reference< io::XInputStream > xInputStream;
1191 if ( bSourceIsDocument && ( rContext.aArg.Operation
1192 != ucb::TransferCommandOperation_LINK ) )
1193 xInputStream = getInputStream( rContext, xCommandProcessorS );
1199 uno::Reference< sdbc::XResultSet > xResultSet;
1201 if ( bSourceIsFolder && ( rContext.aArg.Operation
1202 != ucb::TransferCommandOperation_LINK ) )
1203 xResultSet = getResultSet( rContext, xCommandProcessorS );
1209 ucb::InsertCommandArgument2 aArg;
1210 aArg.Data = xInputStream;
1211 aArg.MimeType = rContext.aArg.MimeType;
1212 aArg.DocumentId = rContext.aArg.DocumentId;
1214 switch ( rContext.aArg.NameClash )
1216 case ucb::NameClash::OVERWRITE:
1217 aArg.ReplaceExisting =
true;
1220 case ucb::NameClash::ERROR:
1221 case ucb::NameClash::RENAME:
1222 case ucb::NameClash::KEEP:
1223 case ucb::NameClash::ASK:
1224 aArg.ReplaceExisting =
false;
1228 aArg.ReplaceExisting =
false;
1229 OSL_FAIL(
"Unknown nameclash directive!" );
1233 OUString aDesiredName = createDesiredName( rContext.aArg );
1242 ucb::Command aInsertCommand(
1247 xCommandProcessorN->execute( aInsertCommand, 0, rContext.xEnv );
1249 catch ( ucb::UnsupportedNameClashException
const & exc )
1251 OSL_ENSURE( !aArg.ReplaceExisting,
1252 "BUG: UnsupportedNameClashException not allowed here!" );
1254 if (exc.NameClash != ucb::NameClash::ERROR) {
1255 OSL_FAIL(
"BUG: NameClash::ERROR expected!" );
1260 throw ucb::UnsupportedNameClashException(
1261 "Unable to resolve name clashes, no chance to detect "
1262 "that there is one!",
1263 rContext.xProcessor,
1264 rContext.aArg.NameClash );
1266 catch ( ucb::NameClashException
const & )
1281 switch ( rContext.aArg.NameClash )
1283 case ucb::NameClash::OVERWRITE:
1287 ucb::UnsupportedNameClashException(
1288 "BUG: insert + replace == true MUST NOT "
1289 "throw NameClashException.",
1290 rContext.xProcessor,
1291 rContext.aArg.NameClash ) ),
1292 rContext.xOrigEnv );
1296 case ucb::NameClash::ERROR:
1299 case ucb::NameClash::RENAME:
1302 handleNameClashRename( rContext,
1310 case ucb::NameClash::ASK:
1314 NameClashContinuation eCont
1315 = interactiveNameClashResolve(
1317 rContext.aArg.TargetURL,
1334 throw ucb::CommandFailedException(
1335 "abort requested via interaction "
1337 uno::Reference< uno::XInterface >(),
1342 OSL_ENSURE( !aArg.ReplaceExisting,
1343 "Hu? ReplaceExisting already true?"
1345 aArg.ReplaceExisting =
true;
1352 if ( setTitle( xCommandProcessorN,
1357 aDesiredName = aNewTitle;
1365 throw ucb::CommandFailedException(
1366 "error setting Title property!",
1367 uno::Reference< uno::XInterface >(),
1374 OSL_ENSURE( bRetry,
"bRetry must be true here!!!" );
1378 case ucb::NameClash::KEEP:
1383 ucb::UnsupportedNameClashException(
1384 "default action, don't know how to "
1385 "handle name clash",
1386 rContext.xProcessor,
1387 rContext.aArg.NameClash ) ),
1388 rContext.xOrigEnv );
1400 if ( xResultSet.is() )
1406 uno::Reference< sdbc::XRow > xChildRow(
1407 xResultSet, uno::UNO_QUERY );
1409 if ( !xChildRow.is() )
1412 beans::PropertyValue(
1416 beans::PropertyState_DIRECT_VALUE));
1418 ucb::IOErrorCode_CANT_READ,
1419 uno::Sequence< uno::Any >(&aProps, 1),
1421 "Unable to get properties from children of source!",
1422 rContext.xProcessor );
1426 uno::Reference< ucb::XContentAccess > xChildAccess(
1427 xResultSet, uno::UNO_QUERY );
1429 if ( !xChildAccess.is() )
1433 {
"Uri",
uno::Any(rContext.aArg.SourceURL)}
1436 ucb::IOErrorCode_CANT_READ,
1439 "Unable to get children of source!",
1440 rContext.xProcessor );
1444 if ( xResultSet->first() )
1446 ucb::GlobalTransferCommandArgument2 aTransArg(
1447 rContext.aArg.Operation,
1449 xNew->getIdentifier()
1450 ->getContentIdentifier(),
1452 rContext.aArg.NameClash,
1453 rContext.aArg.MimeType,
1454 rContext.aArg.DocumentId);
1456 TransferCommandContext aSubCtx(
1457 rContext.m_xContext,
1458 rContext.xProcessor,
1464 uno::Reference< ucb::XContent > xChild
1465 = xChildAccess->queryContent();
1470 aSubCtx.aArg.SourceURL
1471 = xChild->getIdentifier()->getContentIdentifier();
1473 globalTransfer_( aSubCtx,
1479 while ( xResultSet->next() );
1482 catch ( sdbc::SQLException
const & )
1488 uno::Reference< ucb::XCommandProcessor > xcp(
1489 xTarget, uno::UNO_QUERY );
1492 uno::Reference< ucb::XCommandInfo > xci;
1503 static const OUStringLiteral cmdName(u
"flush");
1504 if((aAny >>= xci) && xci->hasCommandByName(cmdName))
1513 catch( uno::Exception
const & )
1524uno::Reference< ucb::XCommandInfo >
1527 return uno::Reference< ucb::XCommandInfo >(
new CommandProcessorInfo() );
1532 const ucb::GlobalTransferCommandArgument2 & rArg,
1533 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1538 uno::Reference< ucb::XCommandEnvironment > xLocalEnv;
1541 xLocalEnv.set( ucb::CommandEnvironment::create(
1543 new InteractionHandlerProxy( xEnv->getInteractionHandler() ),
1544 xEnv->getProgressHandler() ) );
1551 uno::Reference< ucb::XContent >
xTarget;
1552 uno::Reference< ucb::XContentIdentifier >
xId
1560 catch ( ucb::IllegalIdentifierException
const & )
1572 ucb::IOErrorCode_CANT_READ,
1575 "Can't instantiate target object!",
1580 if ( ( rArg.Operation == ucb::TransferCommandOperation_COPY ) ||
1581 ( rArg.Operation == ucb::TransferCommandOperation_MOVE ) )
1583 uno::Reference< ucb::XCommandProcessor > xCommandProcessor(
1585 if ( !xCommandProcessor.is() )
1592 ucb::IOErrorCode_CANT_READ,
1595 "Target content is not a XCommandProcessor!",
1600 ucb::TransferInfo2 aTransferArg(
1602 == ucb::TransferCommandOperation_MOVE ),
1620 xCommandProcessor->execute(
aCommand, 0, xLocalEnv );
1625 catch ( ucb::InteractiveBadTransferURLException
const & )
1630 catch ( ucb::UnsupportedCommandException
const & )
1635 catch ( ucb::UnsupportedNameClashException
const & exc )
1637 OSL_ENSURE( aTransferArg.NameClash == exc.NameClash,
1638 "nameclash mismatch!" );
1639 if ( exc.NameClash == ucb::NameClash::ASK )
1645 ucb::TransferInfo2 aTransferArg1(
1646 aTransferArg.MoveData,
1647 aTransferArg.SourceURL,
1648 aTransferArg.NewTitle,
1649 ucb::NameClash::ERROR,
1650 aTransferArg.MimeType );
1652 ucb::Command aCommand1(
1657 xCommandProcessor->execute( aCommand1, 0, xLocalEnv );
1662 catch ( ucb::UnsupportedNameClashException
const & )
1668 catch ( ucb::NameClashException
const & )
1674 NameClashContinuation eCont
1675 = interactiveNameClashResolve(
1695 throw ucb::CommandFailedException(
1696 "abort requested via interaction "
1698 uno::Reference< uno::XInterface >(),
1703 aTransferArg.NameClash
1704 = ucb::NameClash::OVERWRITE;
1709 aTransferArg.NewTitle = aNewTitle;
1714 OSL_ENSURE( bRetry,
"bRetry must be true here!!!" );
1730 uno::Reference< ucb::XContent > xSource;
1733 uno::Reference< ucb::XContentIdentifier > xId2
1738 catch ( ucb::IllegalIdentifierException
const & )
1743 if ( !xSource.is() )
1750 ucb::IOErrorCode_CANT_READ,
1753 "Can't instantiate source object!",
1758 uno::Reference< ucb::XCommandProcessor > xCommandProcessor(
1759 xSource, uno::UNO_QUERY );
1760 if ( !xCommandProcessor.is() )
1767 ucb::IOErrorCode_CANT_READ,
1770 "Source content is not a XCommandProcessor!",
1777 uno::Sequence< beans::Property > aProps{ makeProperty(
"IsFolder", -1 ),
1778 makeProperty(
"IsDocument", -1 ),
1779 makeProperty(
"TargetURL", -1 ),
1780 makeProperty(
"BaseURI", -1 ) };
1782 ucb::Command aGetPropsCommand(
1783 "getPropertyValues",
1787 uno::Reference< sdbc::XRow >
xRow;
1788 xCommandProcessor->execute( aGetPropsCommand, 0, xLocalEnv ) >>=
xRow;
1797 ucb::IOErrorCode_CANT_READ,
1800 "Unable to get properties from source object!",
1805 TransferCommandContext aTransferCtx(
1808 if ( rArg.NewTitle.isEmpty() )
1811 OUString aBaseURI(
xRow->getString( 4 ) );
1812 if ( !aBaseURI.isEmpty() )
1814 aTransferCtx.aArg.NewTitle
1815 = createDesiredName( aBaseURI, OUString() );
1820 globalTransfer_( aTransferCtx, xSource,
xTarget,
xRow );
1826 if ( rArg.Operation != ucb::TransferCommandOperation_MOVE )
1836 xCommandProcessor->execute(
aCommand, 0, xLocalEnv );
1838 catch ( uno::Exception
const & )
1840 OSL_FAIL(
"Cannot delete source object!" );
1846 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1852 uno::Reference< ucb::XCommandEnvironment > xLocalEnv;
1855 xLocalEnv.set( ucb::CommandEnvironment::create(
1857 new InteractionHandlerProxy( xEnv->getInteractionHandler() ),
1858 xEnv->getProgressHandler() ) );
1861 uno::Reference< ucb::XContent >
xTarget;
1862 uno::Reference< ucb::XContentIdentifier >
xId
1870 catch ( ucb::IllegalIdentifierException
const & )
1882 ucb::IOErrorCode_CANT_READ,
1885 "Can't instantiate target object!",
1890 uno::Reference< ucb::XCommandProcessor > xCommandProcessor(
1892 if ( !xCommandProcessor.is() )
1899 ucb::IOErrorCode_CANT_READ,
1902 "Target content is not a XCommandProcessor!",
1913 aRet = xCommandProcessor->execute(
aCommand, 0, xLocalEnv );
1915 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
Reference< XContentIdentifier > xId
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