xref: /trunk/main/ucb/source/core/ucbcmds.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_ucb.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir /**************************************************************************
32*cdf0e10cSrcweir                                 TODO
33*cdf0e10cSrcweir  **************************************************************************
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir  *************************************************************************/
36*cdf0e10cSrcweir #include <osl/diagnose.h>
37*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
38*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
39*cdf0e10cSrcweir #include <rtl/ustring.h>
40*cdf0e10cSrcweir #include <rtl/ustring.hxx>
41*cdf0e10cSrcweir #include <com/sun/star/uno/XInterface.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/ucb/CommandEnvironment.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/ucb/CommandFailedException.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/ucb/GlobalTransferCommandArgument.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentCreator.hpp>
67*cdf0e10cSrcweir #include <com/sun/star/ucb/XDynamicResultSet.hpp>
68*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
69*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
70*cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx>
71*cdf0e10cSrcweir #include <ucbhelper/simplenameclashresolverequest.hxx>
72*cdf0e10cSrcweir #include "ucbcmds.hxx"
73*cdf0e10cSrcweir #include "ucb.hxx"
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir using namespace com::sun::star;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir namespace
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir //=========================================================================
81*cdf0e10cSrcweir //
82*cdf0e10cSrcweir // struct TransferCommandContext.
83*cdf0e10cSrcweir //
84*cdf0e10cSrcweir //=========================================================================
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir struct TransferCommandContext
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMgr;
89*cdf0e10cSrcweir     uno::Reference< ucb::XCommandProcessor >     xProcessor;
90*cdf0e10cSrcweir     uno::Reference< ucb::XCommandEnvironment >   xEnv;
91*cdf0e10cSrcweir     uno::Reference< ucb::XCommandEnvironment >   xOrigEnv;
92*cdf0e10cSrcweir     ucb::GlobalTransferCommandArgument           aArg;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     TransferCommandContext(
95*cdf0e10cSrcweir         const uno::Reference< lang::XMultiServiceFactory > & rxSMgr,
96*cdf0e10cSrcweir         const uno::Reference< ucb::XCommandProcessor > & rxProcessor,
97*cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment > & rxEnv,
98*cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment > & rxOrigEnv,
99*cdf0e10cSrcweir         const ucb::GlobalTransferCommandArgument & rArg )
100*cdf0e10cSrcweir     : xSMgr( rxSMgr ), xProcessor( rxProcessor ), xEnv( rxEnv ),
101*cdf0e10cSrcweir       xOrigEnv( rxOrigEnv ), aArg( rArg ) {}
102*cdf0e10cSrcweir };
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir //=========================================================================
105*cdf0e10cSrcweir //
106*cdf0e10cSrcweir // class InteractionHandlerProxy.
107*cdf0e10cSrcweir //
108*cdf0e10cSrcweir //=========================================================================
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir class InteractionHandlerProxy :
111*cdf0e10cSrcweir     public cppu::WeakImplHelper1< task::XInteractionHandler >
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir     uno::Reference< task::XInteractionHandler > m_xOrig;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir public:
116*cdf0e10cSrcweir     InteractionHandlerProxy(
117*cdf0e10cSrcweir         const uno::Reference< task::XInteractionHandler > & xOrig )
118*cdf0e10cSrcweir     : m_xOrig( xOrig ) {}
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     // XInteractionHandler methods.
121*cdf0e10cSrcweir     virtual void SAL_CALL handle(
122*cdf0e10cSrcweir             const uno::Reference< task::XInteractionRequest >& Request )
123*cdf0e10cSrcweir         throw ( uno::RuntimeException );
124*cdf0e10cSrcweir };
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir //=========================================================================
127*cdf0e10cSrcweir // virtual
128*cdf0e10cSrcweir void SAL_CALL InteractionHandlerProxy::handle(
129*cdf0e10cSrcweir             const uno::Reference< task::XInteractionRequest >& Request )
130*cdf0e10cSrcweir     throw ( uno::RuntimeException )
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir     if ( !m_xOrig.is() )
133*cdf0e10cSrcweir         return;
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     // Filter unwanted requests by just not handling them.
136*cdf0e10cSrcweir     uno::Any aRequest = Request->getRequest();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     // "transfer"
139*cdf0e10cSrcweir     ucb::InteractiveBadTransferURLException aBadTransferURLEx;
140*cdf0e10cSrcweir     if ( aRequest >>= aBadTransferURLEx )
141*cdf0e10cSrcweir     {
142*cdf0e10cSrcweir         return;
143*cdf0e10cSrcweir     }
144*cdf0e10cSrcweir     else
145*cdf0e10cSrcweir     {
146*cdf0e10cSrcweir         // "transfer"
147*cdf0e10cSrcweir         ucb::UnsupportedNameClashException aUnsupportedNameClashEx;
148*cdf0e10cSrcweir         if ( aRequest >>= aUnsupportedNameClashEx )
149*cdf0e10cSrcweir         {
150*cdf0e10cSrcweir             if ( aUnsupportedNameClashEx.NameClash
151*cdf0e10cSrcweir                     != ucb::NameClash::ERROR )
152*cdf0e10cSrcweir                 return;
153*cdf0e10cSrcweir         }
154*cdf0e10cSrcweir         else
155*cdf0e10cSrcweir         {
156*cdf0e10cSrcweir             // "insert"
157*cdf0e10cSrcweir             ucb::NameClashException aNameClashEx;
158*cdf0e10cSrcweir             if ( aRequest >>= aNameClashEx )
159*cdf0e10cSrcweir             {
160*cdf0e10cSrcweir                 return;
161*cdf0e10cSrcweir             }
162*cdf0e10cSrcweir             else
163*cdf0e10cSrcweir             {
164*cdf0e10cSrcweir                 // "transfer"
165*cdf0e10cSrcweir                 ucb::UnsupportedCommandException aUnsupportedCommandEx;
166*cdf0e10cSrcweir                 if ( aRequest >>= aUnsupportedCommandEx )
167*cdf0e10cSrcweir                 {
168*cdf0e10cSrcweir                     return;
169*cdf0e10cSrcweir                 }
170*cdf0e10cSrcweir             }
171*cdf0e10cSrcweir         }
172*cdf0e10cSrcweir     }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir     // not filtered; let the original handler do the work.
175*cdf0e10cSrcweir     m_xOrig->handle( Request );
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir //=========================================================================
179*cdf0e10cSrcweir //
180*cdf0e10cSrcweir // class ActiveDataSink.
181*cdf0e10cSrcweir //
182*cdf0e10cSrcweir //=========================================================================
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir class ActiveDataSink : public cppu::WeakImplHelper1< io::XActiveDataSink >
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir     uno::Reference< io::XInputStream > m_xStream;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir public:
189*cdf0e10cSrcweir     // XActiveDataSink methods.
190*cdf0e10cSrcweir     virtual void SAL_CALL setInputStream(
191*cdf0e10cSrcweir                         const uno::Reference< io::XInputStream >& aStream )
192*cdf0e10cSrcweir         throw( uno::RuntimeException );
193*cdf0e10cSrcweir     virtual uno::Reference< io::XInputStream > SAL_CALL getInputStream()
194*cdf0e10cSrcweir         throw( uno::RuntimeException );
195*cdf0e10cSrcweir };
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir //=========================================================================
198*cdf0e10cSrcweir // virtual
199*cdf0e10cSrcweir void SAL_CALL ActiveDataSink::setInputStream(
200*cdf0e10cSrcweir                         const uno::Reference< io::XInputStream >& aStream )
201*cdf0e10cSrcweir     throw( uno::RuntimeException )
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     m_xStream = aStream;
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir //=========================================================================
207*cdf0e10cSrcweir // virtual
208*cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL ActiveDataSink::getInputStream()
209*cdf0e10cSrcweir     throw( uno::RuntimeException )
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     return m_xStream;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir //=========================================================================
215*cdf0e10cSrcweir //
216*cdf0e10cSrcweir // class CommandProcessorInfo.
217*cdf0e10cSrcweir //
218*cdf0e10cSrcweir //=========================================================================
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir class CommandProcessorInfo :
221*cdf0e10cSrcweir     public cppu::WeakImplHelper1< ucb::XCommandInfo >
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir     uno::Sequence< ucb::CommandInfo > * m_pInfo;
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir public:
226*cdf0e10cSrcweir     CommandProcessorInfo();
227*cdf0e10cSrcweir     virtual ~CommandProcessorInfo();
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     // XCommandInfo methods
230*cdf0e10cSrcweir     virtual uno::Sequence< ucb::CommandInfo > SAL_CALL getCommands()
231*cdf0e10cSrcweir         throw( uno::RuntimeException );
232*cdf0e10cSrcweir     virtual ucb::CommandInfo SAL_CALL
233*cdf0e10cSrcweir     getCommandInfoByName( const rtl::OUString& Name )
234*cdf0e10cSrcweir         throw( ucb::UnsupportedCommandException, uno::RuntimeException );
235*cdf0e10cSrcweir     virtual ucb::CommandInfo SAL_CALL
236*cdf0e10cSrcweir     getCommandInfoByHandle( sal_Int32 Handle )
237*cdf0e10cSrcweir         throw( ucb::UnsupportedCommandException, uno::RuntimeException );
238*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasCommandByName( const rtl::OUString& Name )
239*cdf0e10cSrcweir         throw( uno::RuntimeException );
240*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasCommandByHandle( sal_Int32 Handle )
241*cdf0e10cSrcweir         throw( uno::RuntimeException );
242*cdf0e10cSrcweir };
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir //=========================================================================
245*cdf0e10cSrcweir CommandProcessorInfo::CommandProcessorInfo()
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir     m_pInfo = new uno::Sequence< ucb::CommandInfo >( 2 );
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir     (*m_pInfo)[ 0 ]
250*cdf0e10cSrcweir         = ucb::CommandInfo(
251*cdf0e10cSrcweir             rtl::OUString::createFromAscii( GETCOMMANDINFO_NAME ), // Name
252*cdf0e10cSrcweir             GETCOMMANDINFO_HANDLE, // Handle
253*cdf0e10cSrcweir             getCppuVoidType() ); // ArgType
254*cdf0e10cSrcweir     (*m_pInfo)[ 1 ]
255*cdf0e10cSrcweir         = ucb::CommandInfo(
256*cdf0e10cSrcweir             rtl::OUString::createFromAscii( GLOBALTRANSFER_NAME ), // Name
257*cdf0e10cSrcweir             GLOBALTRANSFER_HANDLE, // Handle
258*cdf0e10cSrcweir             getCppuType(
259*cdf0e10cSrcweir                 static_cast<
260*cdf0e10cSrcweir                     ucb::GlobalTransferCommandArgument * >( 0 ) ) ); // ArgType
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir //=========================================================================
264*cdf0e10cSrcweir // virtual
265*cdf0e10cSrcweir CommandProcessorInfo::~CommandProcessorInfo()
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir     delete m_pInfo;
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir //=========================================================================
271*cdf0e10cSrcweir // virtual
272*cdf0e10cSrcweir uno::Sequence< ucb::CommandInfo > SAL_CALL
273*cdf0e10cSrcweir CommandProcessorInfo::getCommands()
274*cdf0e10cSrcweir     throw( uno::RuntimeException )
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     return uno::Sequence< ucb::CommandInfo >( *m_pInfo );
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir //=========================================================================
280*cdf0e10cSrcweir // virtual
281*cdf0e10cSrcweir ucb::CommandInfo SAL_CALL
282*cdf0e10cSrcweir CommandProcessorInfo::getCommandInfoByName( const rtl::OUString& Name )
283*cdf0e10cSrcweir     throw( ucb::UnsupportedCommandException, uno::RuntimeException )
284*cdf0e10cSrcweir {
285*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < m_pInfo->getLength(); ++n )
286*cdf0e10cSrcweir     {
287*cdf0e10cSrcweir         if ( (*m_pInfo)[ n ].Name == Name )
288*cdf0e10cSrcweir             return ucb::CommandInfo( (*m_pInfo)[ n ] );
289*cdf0e10cSrcweir     }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     throw ucb::UnsupportedCommandException();
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir //=========================================================================
295*cdf0e10cSrcweir // virtual
296*cdf0e10cSrcweir ucb::CommandInfo SAL_CALL
297*cdf0e10cSrcweir CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
298*cdf0e10cSrcweir     throw( ucb::UnsupportedCommandException, uno::RuntimeException )
299*cdf0e10cSrcweir {
300*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < m_pInfo->getLength(); ++n )
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir         if ( (*m_pInfo)[ n ].Handle == Handle )
303*cdf0e10cSrcweir             return ucb::CommandInfo( (*m_pInfo)[ n ] );
304*cdf0e10cSrcweir     }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir     throw ucb::UnsupportedCommandException();
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir //=========================================================================
310*cdf0e10cSrcweir // virtual
311*cdf0e10cSrcweir sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
312*cdf0e10cSrcweir                                                 const rtl::OUString& Name )
313*cdf0e10cSrcweir     throw( uno::RuntimeException )
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < m_pInfo->getLength(); ++n )
316*cdf0e10cSrcweir     {
317*cdf0e10cSrcweir         if ( (*m_pInfo)[ n ].Name == Name )
318*cdf0e10cSrcweir             return sal_True;
319*cdf0e10cSrcweir     }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     return sal_False;
322*cdf0e10cSrcweir }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir //=========================================================================
325*cdf0e10cSrcweir // virtual
326*cdf0e10cSrcweir sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle )
327*cdf0e10cSrcweir     throw( uno::RuntimeException )
328*cdf0e10cSrcweir {
329*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < m_pInfo->getLength(); ++n )
330*cdf0e10cSrcweir     {
331*cdf0e10cSrcweir         if ( (*m_pInfo)[ n ].Handle == Handle )
332*cdf0e10cSrcweir             return sal_True;
333*cdf0e10cSrcweir     }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir     return sal_False;
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir //=========================================================================
339*cdf0e10cSrcweir //=========================================================================
340*cdf0e10cSrcweir //=========================================================================
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir rtl::OUString createDesiredName(
343*cdf0e10cSrcweir     const rtl::OUString & rSourceURL, const rtl::OUString & rNewTitle )
344*cdf0e10cSrcweir {
345*cdf0e10cSrcweir     rtl::OUString aName( rNewTitle );
346*cdf0e10cSrcweir     if ( aName.getLength() == 0 )
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         // calculate name using source URL
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir         // @@@ It's not guaranteed that slashes contained in the URL are
351*cdf0e10cSrcweir         // actually path separators. This depends on the fact whether the
352*cdf0e10cSrcweir         // URL is hierarchical. Only then the slashes are path separators.
353*cdf0e10cSrcweir         // Therefore this algorithm is not guaranteed to work! But, ATM
354*cdf0e10cSrcweir         // I don't know a better solution. It would have been better to
355*cdf0e10cSrcweir         // have a member for the clashing name in
356*cdf0e10cSrcweir         // UnsupportedNameClashException...
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir         sal_Int32 nLastSlash = rSourceURL.lastIndexOf( '/' );
359*cdf0e10cSrcweir         bool bTrailingSlash = false;
360*cdf0e10cSrcweir         if ( nLastSlash == rSourceURL.getLength() - 1 )
361*cdf0e10cSrcweir         {
362*cdf0e10cSrcweir             nLastSlash = rSourceURL.lastIndexOf( '/', nLastSlash );
363*cdf0e10cSrcweir             bTrailingSlash = true;
364*cdf0e10cSrcweir         }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir         if ( nLastSlash != -1 )
367*cdf0e10cSrcweir         {
368*cdf0e10cSrcweir             if ( bTrailingSlash )
369*cdf0e10cSrcweir                 aName = rSourceURL.copy(
370*cdf0e10cSrcweir                             nLastSlash + 1,
371*cdf0e10cSrcweir                             rSourceURL.getLength() - nLastSlash - 2 );
372*cdf0e10cSrcweir             else
373*cdf0e10cSrcweir                 aName = rSourceURL.copy( nLastSlash + 1 );
374*cdf0e10cSrcweir         }
375*cdf0e10cSrcweir         else
376*cdf0e10cSrcweir         {
377*cdf0e10cSrcweir             aName = rSourceURL;
378*cdf0e10cSrcweir         }
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir         // query, fragment present?
381*cdf0e10cSrcweir     sal_Int32  nPos = aName.indexOf( '?' );
382*cdf0e10cSrcweir     if ( nPos == -1 )
383*cdf0e10cSrcweir       nPos = aName.indexOf( '#' );
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir     if ( nPos != -1 )
386*cdf0e10cSrcweir       aName = aName.copy( 0, nPos );
387*cdf0e10cSrcweir     }
388*cdf0e10cSrcweir     return rtl::OUString( aName );
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir rtl::OUString createDesiredName(
392*cdf0e10cSrcweir     const ucb::GlobalTransferCommandArgument & rArg )
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir     return createDesiredName( rArg.SourceURL, rArg.NewTitle );
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir rtl::OUString createDesiredName(
398*cdf0e10cSrcweir     const ucb::TransferInfo & rArg )
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir     return createDesiredName( rArg.SourceURL, rArg.NewTitle );
401*cdf0e10cSrcweir }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir //=========================================================================
404*cdf0e10cSrcweir enum NameClashContinuation { NOT_HANDLED, ABORT, OVERWRITE, NEW_NAME, UNKNOWN };
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir NameClashContinuation interactiveNameClashResolve(
407*cdf0e10cSrcweir     const uno::Reference< ucb::XCommandEnvironment > & xEnv,
408*cdf0e10cSrcweir     const rtl::OUString & rTargetURL,
409*cdf0e10cSrcweir     const rtl::OUString & rClashingName,
410*cdf0e10cSrcweir     /* [out] */ uno::Any & rException,
411*cdf0e10cSrcweir     /* [out] */ rtl::OUString & rNewName )
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir     rtl::Reference< ucbhelper::SimpleNameClashResolveRequest > xRequest(
414*cdf0e10cSrcweir         new ucbhelper::SimpleNameClashResolveRequest(
415*cdf0e10cSrcweir             rTargetURL,  // target folder URL
416*cdf0e10cSrcweir             rClashingName,   // clashing name
417*cdf0e10cSrcweir             rtl::OUString(), // no proposal for new name
418*cdf0e10cSrcweir             sal_True /* bSupportsOverwriteData */ ) );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     rException = xRequest->getRequest();
421*cdf0e10cSrcweir     if ( xEnv.is() )
422*cdf0e10cSrcweir     {
423*cdf0e10cSrcweir         uno::Reference< task::XInteractionHandler > xIH
424*cdf0e10cSrcweir             = xEnv->getInteractionHandler();
425*cdf0e10cSrcweir         if ( xIH.is() )
426*cdf0e10cSrcweir         {
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir             xIH->handle( xRequest.get() );
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir             rtl::Reference< ucbhelper::InteractionContinuation >
431*cdf0e10cSrcweir                 xSelection( xRequest->getSelection() );
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir             if ( xSelection.is() )
434*cdf0e10cSrcweir             {
435*cdf0e10cSrcweir                 // Handler handled the request.
436*cdf0e10cSrcweir                 uno::Reference< task::XInteractionAbort > xAbort(
437*cdf0e10cSrcweir                     xSelection.get(), uno::UNO_QUERY );
438*cdf0e10cSrcweir                 if ( xAbort.is() )
439*cdf0e10cSrcweir                 {
440*cdf0e10cSrcweir                     // Abort.
441*cdf0e10cSrcweir                     return ABORT;
442*cdf0e10cSrcweir                 }
443*cdf0e10cSrcweir                 else
444*cdf0e10cSrcweir                 {
445*cdf0e10cSrcweir                     uno::Reference<
446*cdf0e10cSrcweir                         ucb::XInteractionReplaceExistingData >
447*cdf0e10cSrcweir                             xReplace(
448*cdf0e10cSrcweir                                 xSelection.get(), uno::UNO_QUERY );
449*cdf0e10cSrcweir                     if ( xReplace.is() )
450*cdf0e10cSrcweir                     {
451*cdf0e10cSrcweir                         // Try again: Replace existing data.
452*cdf0e10cSrcweir                         return OVERWRITE;
453*cdf0e10cSrcweir                     }
454*cdf0e10cSrcweir                     else
455*cdf0e10cSrcweir                     {
456*cdf0e10cSrcweir                         uno::Reference<
457*cdf0e10cSrcweir                             ucb::XInteractionSupplyName >
458*cdf0e10cSrcweir                                 xSupplyName(
459*cdf0e10cSrcweir                                     xSelection.get(), uno::UNO_QUERY );
460*cdf0e10cSrcweir                         if ( xSupplyName.is() )
461*cdf0e10cSrcweir                         {
462*cdf0e10cSrcweir                             // Try again: Use new name.
463*cdf0e10cSrcweir                             rNewName = xRequest->getNewName();
464*cdf0e10cSrcweir                             return NEW_NAME;
465*cdf0e10cSrcweir                         }
466*cdf0e10cSrcweir                         else
467*cdf0e10cSrcweir                         {
468*cdf0e10cSrcweir                             OSL_ENSURE( sal_False,
469*cdf0e10cSrcweir                                         "Unknown interaction continuation!" );
470*cdf0e10cSrcweir                             return UNKNOWN;
471*cdf0e10cSrcweir                         }
472*cdf0e10cSrcweir                     }
473*cdf0e10cSrcweir                 }
474*cdf0e10cSrcweir             }
475*cdf0e10cSrcweir         }
476*cdf0e10cSrcweir     }
477*cdf0e10cSrcweir     return NOT_HANDLED;
478*cdf0e10cSrcweir }
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir //=========================================================================
481*cdf0e10cSrcweir bool setTitle(
482*cdf0e10cSrcweir         const uno::Reference< ucb::XCommandProcessor > & xCommandProcessor,
483*cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment > & xEnv,
484*cdf0e10cSrcweir         const rtl::OUString & rNewTitle )
485*cdf0e10cSrcweir     throw( uno::RuntimeException )
486*cdf0e10cSrcweir {
487*cdf0e10cSrcweir     try
488*cdf0e10cSrcweir     {
489*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aPropValues( 1 );
490*cdf0e10cSrcweir         aPropValues[ 0 ].Name
491*cdf0e10cSrcweir             = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
492*cdf0e10cSrcweir         aPropValues[ 0 ].Handle = -1;
493*cdf0e10cSrcweir         aPropValues[ 0 ].Value  = uno::makeAny( rNewTitle );
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir         ucb::Command aSetPropsCommand(
496*cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
497*cdf0e10cSrcweir             -1,
498*cdf0e10cSrcweir             uno::makeAny( aPropValues ) );
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir         uno::Any aResult
501*cdf0e10cSrcweir             = xCommandProcessor->execute( aSetPropsCommand, 0, xEnv );
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir         uno::Sequence< uno::Any > aErrors;
504*cdf0e10cSrcweir         aResult >>= aErrors;
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir         OSL_ENSURE( aErrors.getLength() == 1,
507*cdf0e10cSrcweir                     "getPropertyValues return value invalid!" );
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir         if ( aErrors[ 0 ].hasValue() )
510*cdf0e10cSrcweir         {
511*cdf0e10cSrcweir             // error occured.
512*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "error setting Title property!" );
513*cdf0e10cSrcweir             return false;
514*cdf0e10cSrcweir         }
515*cdf0e10cSrcweir     }
516*cdf0e10cSrcweir     catch ( uno::RuntimeException const & )
517*cdf0e10cSrcweir     {
518*cdf0e10cSrcweir         throw;
519*cdf0e10cSrcweir     }
520*cdf0e10cSrcweir     catch ( uno::Exception const & )
521*cdf0e10cSrcweir     {
522*cdf0e10cSrcweir         return false;
523*cdf0e10cSrcweir     }
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir     return true;
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir //=========================================================================
529*cdf0e10cSrcweir uno::Reference< ucb::XContent > createNew(
530*cdf0e10cSrcweir                     const TransferCommandContext & rContext,
531*cdf0e10cSrcweir                     const uno::Reference< ucb::XContent > & xTarget,
532*cdf0e10cSrcweir                     sal_Bool bSourceIsFolder,
533*cdf0e10cSrcweir                     sal_Bool bSourceIsDocument,
534*cdf0e10cSrcweir                     sal_Bool bSourceIsLink )
535*cdf0e10cSrcweir     throw( uno::Exception )
536*cdf0e10cSrcweir {
537*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
538*cdf0e10cSrcweir     //
539*cdf0e10cSrcweir     // (1) Obtain creatable types from target.
540*cdf0e10cSrcweir     //
541*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir     // First, try it using "CreatabeleContentsInfo" property and
544*cdf0e10cSrcweir     // "createNewContent" command -> the "new" way.
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir     uno::Reference< ucb::XCommandProcessor > xCommandProcessorT(
547*cdf0e10cSrcweir                                                     xTarget, uno::UNO_QUERY );
548*cdf0e10cSrcweir     if ( !xCommandProcessorT.is() )
549*cdf0e10cSrcweir     {
550*cdf0e10cSrcweir         uno::Any aProps
551*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
552*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
553*cdf0e10cSrcweir                                                     "Folder")),
554*cdf0e10cSrcweir                                   -1,
555*cdf0e10cSrcweir                                   uno::makeAny(rContext.aArg.TargetURL),
556*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
557*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
558*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_CREATE,
559*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
560*cdf0e10cSrcweir             rContext.xOrigEnv,
561*cdf0e10cSrcweir             rtl::OUString::createFromAscii( "Target is no XCommandProcessor!" ),
562*cdf0e10cSrcweir             rContext.xProcessor );
563*cdf0e10cSrcweir         // Unreachable
564*cdf0e10cSrcweir     }
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir     uno::Sequence< beans::Property > aPropsToObtain( 1 );
567*cdf0e10cSrcweir     aPropsToObtain[ 0 ].Name
568*cdf0e10cSrcweir         = rtl::OUString::createFromAscii( "CreatableContentsInfo" );
569*cdf0e10cSrcweir     aPropsToObtain[ 0 ].Handle
570*cdf0e10cSrcweir         = -1;
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir     ucb::Command aGetPropsCommand(
573*cdf0e10cSrcweir             rtl::OUString::createFromAscii( "getPropertyValues" ),
574*cdf0e10cSrcweir             -1,
575*cdf0e10cSrcweir             uno::makeAny( aPropsToObtain ) );
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir     uno::Reference< sdbc::XRow > xRow;
578*cdf0e10cSrcweir     xCommandProcessorT->execute( aGetPropsCommand, 0, rContext.xEnv )  >>= xRow;
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir     uno::Sequence< ucb::ContentInfo > aTypesInfo;
581*cdf0e10cSrcweir     bool bGotTypesInfo = false;
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir     if ( xRow.is() )
584*cdf0e10cSrcweir     {
585*cdf0e10cSrcweir         uno::Any  aValue = xRow->getObject(
586*cdf0e10cSrcweir             1, uno::Reference< container::XNameAccess >() );
587*cdf0e10cSrcweir         if ( aValue.hasValue() && ( aValue >>= aTypesInfo ) )
588*cdf0e10cSrcweir         {
589*cdf0e10cSrcweir             bGotTypesInfo = true;
590*cdf0e10cSrcweir         }
591*cdf0e10cSrcweir     }
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir     uno::Reference< ucb::XContentCreator > xCreator;
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir     if ( !bGotTypesInfo )
596*cdf0e10cSrcweir     {
597*cdf0e10cSrcweir         // Second, try it using XContentCreator interface -> the "old" way (not
598*cdf0e10cSrcweir         // providing the chance to supply an XCommandEnvironment.
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir         xCreator.set( xTarget, uno::UNO_QUERY );
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir         if ( !xCreator.is() )
603*cdf0e10cSrcweir         {
604*cdf0e10cSrcweir             uno::Any aProps
605*cdf0e10cSrcweir                 = uno::makeAny(beans::PropertyValue(
606*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
607*cdf0e10cSrcweir                                                     "Folder")),
608*cdf0e10cSrcweir                                   -1,
609*cdf0e10cSrcweir                                   uno::makeAny(rContext.aArg.TargetURL),
610*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
611*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
612*cdf0e10cSrcweir                 ucb::IOErrorCode_CANT_CREATE,
613*cdf0e10cSrcweir                 uno::Sequence< uno::Any >(&aProps, 1),
614*cdf0e10cSrcweir                 rContext.xOrigEnv,
615*cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "Target is no XContentCreator!" ),
616*cdf0e10cSrcweir                 rContext.xProcessor );
617*cdf0e10cSrcweir             // Unreachable
618*cdf0e10cSrcweir         }
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir         aTypesInfo  = xCreator->queryCreatableContentsInfo();
621*cdf0e10cSrcweir     }
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir     sal_Int32 nCount = aTypesInfo.getLength();
624*cdf0e10cSrcweir     if ( !nCount )
625*cdf0e10cSrcweir     {
626*cdf0e10cSrcweir         uno::Any aProps
627*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
628*cdf0e10cSrcweir                               rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Folder")),
629*cdf0e10cSrcweir                               -1,
630*cdf0e10cSrcweir                               uno::makeAny(rContext.aArg.TargetURL),
631*cdf0e10cSrcweir                               beans::PropertyState_DIRECT_VALUE));
632*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
633*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_CREATE,
634*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
635*cdf0e10cSrcweir             rContext.xOrigEnv,
636*cdf0e10cSrcweir             rtl::OUString::createFromAscii( "No types creatable!" ),
637*cdf0e10cSrcweir             rContext.xProcessor );
638*cdf0e10cSrcweir         // Unreachable
639*cdf0e10cSrcweir     }
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
642*cdf0e10cSrcweir     //
643*cdf0e10cSrcweir     // (2) Try to find a matching target type for the source object.
644*cdf0e10cSrcweir     //
645*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir     uno::Reference< ucb::XContent > xNew;
648*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n )
649*cdf0e10cSrcweir     {
650*cdf0e10cSrcweir         sal_Int32 nAttribs = aTypesInfo[ n ].Attributes;
651*cdf0e10cSrcweir         sal_Bool  bMatch   = sal_False;
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir         if ( rContext.aArg.Operation == ucb::TransferCommandOperation_LINK )
654*cdf0e10cSrcweir         {
655*cdf0e10cSrcweir             // Create link
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir             if ( nAttribs & ucb::ContentInfoAttribute::KIND_LINK )
658*cdf0e10cSrcweir             {
659*cdf0e10cSrcweir                 // Match!
660*cdf0e10cSrcweir                 bMatch = sal_True;
661*cdf0e10cSrcweir             }
662*cdf0e10cSrcweir         }
663*cdf0e10cSrcweir         else if ( ( rContext.aArg.Operation
664*cdf0e10cSrcweir                         == ucb::TransferCommandOperation_COPY ) ||
665*cdf0e10cSrcweir                   ( rContext.aArg.Operation
666*cdf0e10cSrcweir                         == ucb::TransferCommandOperation_MOVE ) )
667*cdf0e10cSrcweir         {
668*cdf0e10cSrcweir             // Copy / Move
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir             // Is source a link? Create link in target folder then.
671*cdf0e10cSrcweir             if ( bSourceIsLink )
672*cdf0e10cSrcweir             {
673*cdf0e10cSrcweir                 if ( nAttribs & ucb::ContentInfoAttribute::KIND_LINK )
674*cdf0e10cSrcweir                 {
675*cdf0e10cSrcweir                     // Match!
676*cdf0e10cSrcweir                     bMatch = sal_True;
677*cdf0e10cSrcweir                 }
678*cdf0e10cSrcweir             }
679*cdf0e10cSrcweir             else
680*cdf0e10cSrcweir             {
681*cdf0e10cSrcweir                 // (not a and not b) or (a and b)
682*cdf0e10cSrcweir                 // not( a or b) or (a and b)
683*cdf0e10cSrcweir                 //
684*cdf0e10cSrcweir                 if ( ( !!bSourceIsFolder ==
685*cdf0e10cSrcweir                         !!( nAttribs
686*cdf0e10cSrcweir                             & ucb::ContentInfoAttribute::KIND_FOLDER ) )
687*cdf0e10cSrcweir                      &&
688*cdf0e10cSrcweir                      ( !!bSourceIsDocument ==
689*cdf0e10cSrcweir                         !!( nAttribs
690*cdf0e10cSrcweir                             & ucb::ContentInfoAttribute::KIND_DOCUMENT ) )
691*cdf0e10cSrcweir                    )
692*cdf0e10cSrcweir                 {
693*cdf0e10cSrcweir                     // Match!
694*cdf0e10cSrcweir                     bMatch = sal_True;
695*cdf0e10cSrcweir                 }
696*cdf0e10cSrcweir             }
697*cdf0e10cSrcweir         }
698*cdf0e10cSrcweir         else
699*cdf0e10cSrcweir         {
700*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
701*cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
702*cdf0e10cSrcweir                                         rtl::OUString::createFromAscii(
703*cdf0e10cSrcweir                                             "Unknown transfer operation!" ),
704*cdf0e10cSrcweir                                         rContext.xProcessor,
705*cdf0e10cSrcweir                                         -1 ) ),
706*cdf0e10cSrcweir                               rContext.xOrigEnv );
707*cdf0e10cSrcweir             // Unreachable
708*cdf0e10cSrcweir         }
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir         if ( bMatch )
711*cdf0e10cSrcweir         {
712*cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
713*cdf0e10cSrcweir             //
714*cdf0e10cSrcweir             // (3) Create a new, empty object of matched type.
715*cdf0e10cSrcweir             //
716*cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir             if ( !xCreator.is() )
719*cdf0e10cSrcweir             {
720*cdf0e10cSrcweir                 // First, try it using "CreatabeleContentsInfo" property and
721*cdf0e10cSrcweir                 // "createNewContent" command -> the "new" way.
722*cdf0e10cSrcweir                 ucb::Command aCreateNewCommand(
723*cdf0e10cSrcweir                    rtl::OUString::createFromAscii( "createNewContent" ),
724*cdf0e10cSrcweir                    -1,
725*cdf0e10cSrcweir                    uno::makeAny( aTypesInfo[ n ] ) );
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir                 xCommandProcessorT->execute( aCreateNewCommand, 0, rContext.xEnv )
728*cdf0e10cSrcweir                     >>= xNew;
729*cdf0e10cSrcweir             }
730*cdf0e10cSrcweir             else
731*cdf0e10cSrcweir             {
732*cdf0e10cSrcweir                 // Second, try it using XContentCreator interface -> the "old"
733*cdf0e10cSrcweir                 // way (not providing the chance to supply an XCommandEnvironment.
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir                 xNew = xCreator->createNewContent( aTypesInfo[ n ] );
736*cdf0e10cSrcweir             }
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir             if ( !xNew.is() )
739*cdf0e10cSrcweir             {
740*cdf0e10cSrcweir                 uno::Any aProps
741*cdf0e10cSrcweir                     = uno::makeAny(
742*cdf0e10cSrcweir                              beans::PropertyValue(
743*cdf0e10cSrcweir                                  rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
744*cdf0e10cSrcweir                                                    "Folder")),
745*cdf0e10cSrcweir                                  -1,
746*cdf0e10cSrcweir                                  uno::makeAny(rContext.aArg.TargetURL),
747*cdf0e10cSrcweir                                  beans::PropertyState_DIRECT_VALUE));
748*cdf0e10cSrcweir                 ucbhelper::cancelCommandExecution(
749*cdf0e10cSrcweir                     ucb::IOErrorCode_CANT_CREATE,
750*cdf0e10cSrcweir                     uno::Sequence< uno::Any >(&aProps, 1),
751*cdf0e10cSrcweir                     rContext.xOrigEnv,
752*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
753*cdf0e10cSrcweir                         "createNewContent failed!" ),
754*cdf0e10cSrcweir                     rContext.xProcessor );
755*cdf0e10cSrcweir                 // Unreachable
756*cdf0e10cSrcweir             }
757*cdf0e10cSrcweir             break; // escape from 'for' loop
758*cdf0e10cSrcweir         }
759*cdf0e10cSrcweir     } // for
760*cdf0e10cSrcweir 
761*cdf0e10cSrcweir     return xNew;
762*cdf0e10cSrcweir }
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir //=========================================================================
765*cdf0e10cSrcweir void transferProperties(
766*cdf0e10cSrcweir     const TransferCommandContext & rContext,
767*cdf0e10cSrcweir     const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorS,
768*cdf0e10cSrcweir     const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorN )
769*cdf0e10cSrcweir         throw( uno::Exception )
770*cdf0e10cSrcweir {
771*cdf0e10cSrcweir     ucb::Command aGetPropertySetInfoCommand(
772*cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "getPropertySetInfo" ),
773*cdf0e10cSrcweir                 -1,
774*cdf0e10cSrcweir                 uno::Any() );
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir     uno::Reference< beans::XPropertySetInfo > xInfo;
777*cdf0e10cSrcweir     xCommandProcessorS->execute( aGetPropertySetInfoCommand, 0, rContext.xEnv )
778*cdf0e10cSrcweir         >>= xInfo;
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir     if ( !xInfo.is() )
781*cdf0e10cSrcweir     {
782*cdf0e10cSrcweir         uno::Any aProps
783*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
784*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
785*cdf0e10cSrcweir                                                     "Uri")),
786*cdf0e10cSrcweir                                   -1,
787*cdf0e10cSrcweir                                   uno::makeAny(rContext.aArg.SourceURL),
788*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
789*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
790*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_READ,
791*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
792*cdf0e10cSrcweir             rContext.xOrigEnv,
793*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
794*cdf0e10cSrcweir                 "Unable to get propertyset info from source object!" ),
795*cdf0e10cSrcweir             rContext.xProcessor );
796*cdf0e10cSrcweir         // Unreachable
797*cdf0e10cSrcweir     }
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir     uno::Sequence< beans::Property > aAllProps = xInfo->getProperties();
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir     ucb::Command aGetPropsCommand1(
802*cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "getPropertyValues" ),
803*cdf0e10cSrcweir                 -1,
804*cdf0e10cSrcweir                 uno::makeAny( aAllProps ) );
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir     uno::Reference< sdbc::XRow > xRow1;
807*cdf0e10cSrcweir     xCommandProcessorS->execute(
808*cdf0e10cSrcweir         aGetPropsCommand1, 0, rContext.xEnv ) >>= xRow1;
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir     if ( !xRow1.is() )
811*cdf0e10cSrcweir     {
812*cdf0e10cSrcweir         uno::Any aProps
813*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
814*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
815*cdf0e10cSrcweir                                                     "Uri")),
816*cdf0e10cSrcweir                                   -1,
817*cdf0e10cSrcweir                                   uno::makeAny(rContext.aArg.SourceURL),
818*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
819*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
820*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_READ,
821*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
822*cdf0e10cSrcweir             rContext.xOrigEnv,
823*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
824*cdf0e10cSrcweir                 "Unable to get properties from source object!" ),
825*cdf0e10cSrcweir             rContext.xProcessor );
826*cdf0e10cSrcweir         // Unreachable
827*cdf0e10cSrcweir     }
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir     // Assemble data structure for setPropertyValues command.
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir     // Note: Make room for additional Title and TargetURL too. -> + 2
832*cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aPropValues(
833*cdf0e10cSrcweir                                                 aAllProps.getLength() + 2 );
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir     sal_Bool bHasTitle = ( rContext.aArg.NewTitle.getLength() == 0 );
836*cdf0e10cSrcweir     sal_Bool bHasTargetURL = ( rContext.aArg.Operation
837*cdf0e10cSrcweir                                 != ucb::TransferCommandOperation_LINK );
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir     sal_Int32 nWritePos = 0;
840*cdf0e10cSrcweir     for ( sal_Int32 m = 0; m < aAllProps.getLength(); ++m )
841*cdf0e10cSrcweir     {
842*cdf0e10cSrcweir         const beans::Property & rCurrProp = aAllProps[ m ];
843*cdf0e10cSrcweir         beans::PropertyValue & rCurrValue = aPropValues[ nWritePos ];
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir         uno::Any aValue;
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir         if ( rCurrProp.Name.compareToAscii( "Title" ) == 0 )
848*cdf0e10cSrcweir         {
849*cdf0e10cSrcweir             // Supply new title, if given.
850*cdf0e10cSrcweir             if ( !bHasTitle )
851*cdf0e10cSrcweir             {
852*cdf0e10cSrcweir                 bHasTitle = sal_True;
853*cdf0e10cSrcweir                 aValue <<= rContext.aArg.NewTitle;
854*cdf0e10cSrcweir             }
855*cdf0e10cSrcweir         }
856*cdf0e10cSrcweir         else if ( rCurrProp.Name.compareToAscii( "TargetURL" ) == 0 )
857*cdf0e10cSrcweir         {
858*cdf0e10cSrcweir             // Supply source URL as link target for the new link to create.
859*cdf0e10cSrcweir             if ( !bHasTargetURL )
860*cdf0e10cSrcweir             {
861*cdf0e10cSrcweir                 bHasTargetURL = sal_True;
862*cdf0e10cSrcweir                 aValue <<= rContext.aArg.SourceURL;
863*cdf0e10cSrcweir             }
864*cdf0e10cSrcweir         }
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir         if ( !aValue.hasValue() )
867*cdf0e10cSrcweir         {
868*cdf0e10cSrcweir             try
869*cdf0e10cSrcweir             {
870*cdf0e10cSrcweir                 aValue = xRow1->getObject(
871*cdf0e10cSrcweir                             m + 1, uno::Reference< container::XNameAccess >() );
872*cdf0e10cSrcweir             }
873*cdf0e10cSrcweir             catch ( sdbc::SQLException const & )
874*cdf0e10cSrcweir             {
875*cdf0e10cSrcweir                 // Argh! But try to bring things to an end. Perhaps the
876*cdf0e10cSrcweir                 // mad property is not really important...
877*cdf0e10cSrcweir             }
878*cdf0e10cSrcweir         }
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir         if ( aValue.hasValue() )
881*cdf0e10cSrcweir         {
882*cdf0e10cSrcweir             rCurrValue.Name   = rCurrProp.Name;
883*cdf0e10cSrcweir             rCurrValue.Handle = rCurrProp.Handle;
884*cdf0e10cSrcweir             rCurrValue.Value  = aValue;
885*cdf0e10cSrcweir //          rCurrValue.State  =
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir             nWritePos++;
888*cdf0e10cSrcweir         }
889*cdf0e10cSrcweir     }
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir     // Title needed, but not set yet?
892*cdf0e10cSrcweir     if ( !bHasTitle && ( rContext.aArg.NewTitle.getLength() > 0 ) )
893*cdf0e10cSrcweir     {
894*cdf0e10cSrcweir         aPropValues[ nWritePos ].Name
895*cdf0e10cSrcweir             = rtl::OUString::createFromAscii( "Title" );
896*cdf0e10cSrcweir         aPropValues[ nWritePos ].Handle = -1;
897*cdf0e10cSrcweir         aPropValues[ nWritePos ].Value <<= rContext.aArg.NewTitle;
898*cdf0e10cSrcweir 
899*cdf0e10cSrcweir         nWritePos++;
900*cdf0e10cSrcweir     }
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir     // TargetURL needed, but not set yet?
903*cdf0e10cSrcweir     if ( !bHasTargetURL && ( rContext.aArg.Operation
904*cdf0e10cSrcweir                                 == ucb::TransferCommandOperation_LINK ) )
905*cdf0e10cSrcweir     {
906*cdf0e10cSrcweir         aPropValues[ nWritePos ].Name
907*cdf0e10cSrcweir             = rtl::OUString::createFromAscii( "TargetURL" );
908*cdf0e10cSrcweir         aPropValues[ nWritePos ].Handle = -1;
909*cdf0e10cSrcweir         aPropValues[ nWritePos ].Value <<= rContext.aArg.SourceURL;
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir         nWritePos++;
912*cdf0e10cSrcweir     }
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir     aPropValues.realloc( nWritePos );
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir     // Set properties at new object.
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir     ucb::Command aSetPropsCommand(
919*cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "setPropertyValues" ),
920*cdf0e10cSrcweir                 -1,
921*cdf0e10cSrcweir                 uno::makeAny( aPropValues ) );
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir     xCommandProcessorN->execute( aSetPropsCommand, 0, rContext.xEnv );
924*cdf0e10cSrcweir 
925*cdf0e10cSrcweir     // @@@ What to do with source props that are not supported by the
926*cdf0e10cSrcweir     //     new object? addProperty ???
927*cdf0e10cSrcweir }
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir //=========================================================================
930*cdf0e10cSrcweir uno::Reference< io::XInputStream > getInputStream(
931*cdf0e10cSrcweir     const TransferCommandContext & rContext,
932*cdf0e10cSrcweir     const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorS )
933*cdf0e10cSrcweir         throw( uno::Exception )
934*cdf0e10cSrcweir {
935*cdf0e10cSrcweir     uno::Reference< io::XInputStream > xInputStream;
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
938*cdf0e10cSrcweir     //
939*cdf0e10cSrcweir     // (1) Try to get data as XInputStream via XActiveDataSink.
940*cdf0e10cSrcweir     //
941*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir     try
944*cdf0e10cSrcweir     {
945*cdf0e10cSrcweir         uno::Reference< io::XActiveDataSink > xSink = new ActiveDataSink;
946*cdf0e10cSrcweir 
947*cdf0e10cSrcweir         ucb::OpenCommandArgument2 aArg;
948*cdf0e10cSrcweir         aArg.Mode       = ucb::OpenMode::DOCUMENT;
949*cdf0e10cSrcweir         aArg.Priority   = 0; // unused
950*cdf0e10cSrcweir         aArg.Sink       = xSink;
951*cdf0e10cSrcweir         aArg.Properties = uno::Sequence< beans::Property >( 0 ); // unused
952*cdf0e10cSrcweir 
953*cdf0e10cSrcweir         ucb::Command aOpenCommand(
954*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii( "open" ),
955*cdf0e10cSrcweir                                 -1,
956*cdf0e10cSrcweir                                 uno::makeAny( aArg ) );
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir         xCommandProcessorS->execute( aOpenCommand, 0, rContext.xEnv );
959*cdf0e10cSrcweir         xInputStream = xSink->getInputStream();
960*cdf0e10cSrcweir     }
961*cdf0e10cSrcweir     catch ( uno::RuntimeException const & )
962*cdf0e10cSrcweir     {
963*cdf0e10cSrcweir         throw;
964*cdf0e10cSrcweir     }
965*cdf0e10cSrcweir     catch ( uno::Exception const & )
966*cdf0e10cSrcweir     {
967*cdf0e10cSrcweir         // will be handled below.
968*cdf0e10cSrcweir     }
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir     if ( !xInputStream.is() )
971*cdf0e10cSrcweir     {
972*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
973*cdf0e10cSrcweir         //
974*cdf0e10cSrcweir         // (2) Try to get data via XOutputStream.
975*cdf0e10cSrcweir         //
976*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir         try
979*cdf0e10cSrcweir         {
980*cdf0e10cSrcweir             uno::Reference< io::XOutputStream > xOutputStream(
981*cdf0e10cSrcweir                 rContext.xSMgr->createInstance(
982*cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "com.sun.star.io.Pipe" ) ),
983*cdf0e10cSrcweir                 uno::UNO_QUERY );
984*cdf0e10cSrcweir 
985*cdf0e10cSrcweir             if ( xOutputStream.is() )
986*cdf0e10cSrcweir             {
987*cdf0e10cSrcweir                 ucb::OpenCommandArgument2 aArg;
988*cdf0e10cSrcweir                 aArg.Mode       = ucb::OpenMode::DOCUMENT;
989*cdf0e10cSrcweir                 aArg.Priority   = 0; // unused
990*cdf0e10cSrcweir                 aArg.Sink       = xOutputStream;
991*cdf0e10cSrcweir                 aArg.Properties = uno::Sequence< beans::Property >( 0 );
992*cdf0e10cSrcweir 
993*cdf0e10cSrcweir                 ucb::Command aOpenCommand(
994*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii( "open" ),
995*cdf0e10cSrcweir                                     -1,
996*cdf0e10cSrcweir                                     uno::makeAny( aArg ) );
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir                 xCommandProcessorS->execute( aOpenCommand, 0, rContext.xEnv );
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir                 xInputStream = uno::Reference< io::XInputStream >(
1001*cdf0e10cSrcweir                                         xOutputStream, uno::UNO_QUERY );
1002*cdf0e10cSrcweir             }
1003*cdf0e10cSrcweir         }
1004*cdf0e10cSrcweir         catch ( uno::RuntimeException const & )
1005*cdf0e10cSrcweir         {
1006*cdf0e10cSrcweir             throw;
1007*cdf0e10cSrcweir         }
1008*cdf0e10cSrcweir         catch ( uno::Exception const & )
1009*cdf0e10cSrcweir         {
1010*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "unable to get input stream from document!" );
1011*cdf0e10cSrcweir         }
1012*cdf0e10cSrcweir     }
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir     return xInputStream;
1015*cdf0e10cSrcweir }
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir //=========================================================================
1018*cdf0e10cSrcweir uno::Reference< sdbc::XResultSet > getResultSet(
1019*cdf0e10cSrcweir     const TransferCommandContext & rContext,
1020*cdf0e10cSrcweir     const uno::Reference< ucb::XCommandProcessor > & xCommandProcessorS )
1021*cdf0e10cSrcweir         throw( uno::Exception )
1022*cdf0e10cSrcweir {
1023*cdf0e10cSrcweir     uno::Reference< sdbc::XResultSet > xResultSet;
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir     uno::Sequence< beans::Property > aProps( 3 );
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir     aProps[ 0 ].Name   = rtl::OUString::createFromAscii( "IsFolder" );
1028*cdf0e10cSrcweir     aProps[ 0 ].Handle = -1; /* unknown */
1029*cdf0e10cSrcweir     aProps[ 1 ].Name   = rtl::OUString::createFromAscii( "IsDocument" );
1030*cdf0e10cSrcweir     aProps[ 1 ].Handle = -1; /* unknown */
1031*cdf0e10cSrcweir     aProps[ 2 ].Name   = rtl::OUString::createFromAscii( "TargetURL" );
1032*cdf0e10cSrcweir     aProps[ 2 ].Handle = -1; /* unknown */
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir     ucb::OpenCommandArgument2 aArg;
1035*cdf0e10cSrcweir     aArg.Mode       = ucb::OpenMode::ALL;
1036*cdf0e10cSrcweir     aArg.Priority   = 0; // unused
1037*cdf0e10cSrcweir     aArg.Sink       = 0;
1038*cdf0e10cSrcweir     aArg.Properties = aProps;
1039*cdf0e10cSrcweir 
1040*cdf0e10cSrcweir     ucb::Command aOpenCommand( rtl::OUString::createFromAscii( "open" ),
1041*cdf0e10cSrcweir                                      -1,
1042*cdf0e10cSrcweir                                      uno::makeAny( aArg ) );
1043*cdf0e10cSrcweir     try
1044*cdf0e10cSrcweir     {
1045*cdf0e10cSrcweir         uno::Reference< ucb::XDynamicResultSet > xSet;
1046*cdf0e10cSrcweir         xCommandProcessorS->execute( aOpenCommand, 0, rContext.xEnv ) >>= xSet;
1047*cdf0e10cSrcweir 
1048*cdf0e10cSrcweir         if ( xSet.is() )
1049*cdf0e10cSrcweir             xResultSet = xSet->getStaticResultSet();
1050*cdf0e10cSrcweir     }
1051*cdf0e10cSrcweir     catch ( uno::RuntimeException const & )
1052*cdf0e10cSrcweir     {
1053*cdf0e10cSrcweir         throw;
1054*cdf0e10cSrcweir     }
1055*cdf0e10cSrcweir     catch ( uno::Exception const & )
1056*cdf0e10cSrcweir     {
1057*cdf0e10cSrcweir          OSL_ENSURE( sal_False, "unable to get result set from folder!" );
1058*cdf0e10cSrcweir     }
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir     return xResultSet;
1061*cdf0e10cSrcweir }
1062*cdf0e10cSrcweir 
1063*cdf0e10cSrcweir //=========================================================================
1064*cdf0e10cSrcweir void handleNameClashRename(
1065*cdf0e10cSrcweir         const TransferCommandContext & rContext,
1066*cdf0e10cSrcweir         const uno::Reference< ucb::XContent > & xNew,
1067*cdf0e10cSrcweir         const uno::Reference<
1068*cdf0e10cSrcweir             ucb::XCommandProcessor > & xCommandProcessorN,
1069*cdf0e10cSrcweir         const uno::Reference<
1070*cdf0e10cSrcweir             ucb::XCommandProcessor > & xCommandProcessorS,
1071*cdf0e10cSrcweir         /* [inout] */ uno::Reference< io::XInputStream > & xInputStream )
1072*cdf0e10cSrcweir     throw( uno::Exception )
1073*cdf0e10cSrcweir {
1074*cdf0e10cSrcweir     sal_Int32 nTry = 0;
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir     // Obtain old title.
1077*cdf0e10cSrcweir     uno::Sequence< beans::Property > aProps( 1 );
1078*cdf0e10cSrcweir     aProps[ 0 ].Name   = rtl::OUString::createFromAscii( "Title" );
1079*cdf0e10cSrcweir     aProps[ 0 ].Handle = -1;
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir     ucb::Command aGetPropsCommand(
1082*cdf0e10cSrcweir             rtl::OUString::createFromAscii( "getPropertyValues" ),
1083*cdf0e10cSrcweir             -1,
1084*cdf0e10cSrcweir             uno::makeAny( aProps ) );
1085*cdf0e10cSrcweir 
1086*cdf0e10cSrcweir     uno::Reference< sdbc::XRow > xRow;
1087*cdf0e10cSrcweir     xCommandProcessorN->execute( aGetPropsCommand, 0, rContext.xEnv )  >>= xRow;
1088*cdf0e10cSrcweir 
1089*cdf0e10cSrcweir     if ( !xRow.is() )
1090*cdf0e10cSrcweir     {
1091*cdf0e10cSrcweir         uno::Any aProps2
1092*cdf0e10cSrcweir             = uno::makeAny(
1093*cdf0e10cSrcweir                      beans::PropertyValue(
1094*cdf0e10cSrcweir                          rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Uri" ) ),
1095*cdf0e10cSrcweir                          -1,
1096*cdf0e10cSrcweir                          uno::makeAny(
1097*cdf0e10cSrcweir                              xNew->getIdentifier()->getContentIdentifier() ),
1098*cdf0e10cSrcweir                          beans::PropertyState_DIRECT_VALUE ) );
1099*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1100*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_READ,
1101*cdf0e10cSrcweir             uno::Sequence< uno::Any >( &aProps2, 1 ),
1102*cdf0e10cSrcweir             rContext.xOrigEnv,
1103*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
1104*cdf0e10cSrcweir                 "Unable to get properties from new object!" ),
1105*cdf0e10cSrcweir             rContext.xProcessor );
1106*cdf0e10cSrcweir         // Unreachable
1107*cdf0e10cSrcweir     }
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir     rtl::OUString aOldTitle = xRow->getString( 1 );
1110*cdf0e10cSrcweir     if ( !aOldTitle.getLength() )
1111*cdf0e10cSrcweir     {
1112*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1113*cdf0e10cSrcweir             uno::makeAny( beans::UnknownPropertyException(
1114*cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1115*cdf0e10cSrcweir                                 "Unable to get property 'Title' "
1116*cdf0e10cSrcweir                                 "from new object!" ),
1117*cdf0e10cSrcweir                             rContext.xProcessor ) ),
1118*cdf0e10cSrcweir             rContext.xOrigEnv );
1119*cdf0e10cSrcweir         // Unreachable
1120*cdf0e10cSrcweir     }
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir     // Some pseudo-intelligence for not destroying file extensions.
1123*cdf0e10cSrcweir     rtl::OUString aOldTitlePre;
1124*cdf0e10cSrcweir     rtl::OUString aOldTitlePost;
1125*cdf0e10cSrcweir     sal_Int32 nPos = aOldTitle.lastIndexOf( '.' );
1126*cdf0e10cSrcweir     if ( nPos != -1 )
1127*cdf0e10cSrcweir     {
1128*cdf0e10cSrcweir         aOldTitlePre = aOldTitle.copy( 0, nPos );
1129*cdf0e10cSrcweir         aOldTitlePost = aOldTitle.copy( nPos );
1130*cdf0e10cSrcweir     }
1131*cdf0e10cSrcweir     else
1132*cdf0e10cSrcweir         aOldTitlePre = aOldTitle;
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir     if ( nPos > 0 )
1135*cdf0e10cSrcweir         aOldTitlePre += rtl::OUString::createFromAscii( "_" );
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir     sal_Bool bContinue = sal_True;
1138*cdf0e10cSrcweir     do
1139*cdf0e10cSrcweir     {
1140*cdf0e10cSrcweir         nTry++;
1141*cdf0e10cSrcweir 
1142*cdf0e10cSrcweir         rtl::OUString aNewTitle = aOldTitlePre;
1143*cdf0e10cSrcweir         aNewTitle += rtl::OUString::valueOf( nTry );
1144*cdf0e10cSrcweir         aNewTitle += aOldTitlePost;
1145*cdf0e10cSrcweir 
1146*cdf0e10cSrcweir         // Set new title
1147*cdf0e10cSrcweir         setTitle( xCommandProcessorN, rContext.xEnv, aNewTitle );
1148*cdf0e10cSrcweir 
1149*cdf0e10cSrcweir         // Retry inserting the content.
1150*cdf0e10cSrcweir         try
1151*cdf0e10cSrcweir         {
1152*cdf0e10cSrcweir             // Previous try may have read from stream. Seek to begin (if
1153*cdf0e10cSrcweir             // optional interface XSeekable is supported) or get a new stream.
1154*cdf0e10cSrcweir             if ( xInputStream.is() )
1155*cdf0e10cSrcweir             {
1156*cdf0e10cSrcweir                 uno::Reference< io::XSeekable > xSeekable(
1157*cdf0e10cSrcweir                     xInputStream, uno::UNO_QUERY );
1158*cdf0e10cSrcweir                 if ( xSeekable.is() )
1159*cdf0e10cSrcweir                 {
1160*cdf0e10cSrcweir                     try
1161*cdf0e10cSrcweir                     {
1162*cdf0e10cSrcweir                         xSeekable->seek( 0 );
1163*cdf0e10cSrcweir                     }
1164*cdf0e10cSrcweir                     catch ( lang::IllegalArgumentException const & )
1165*cdf0e10cSrcweir                     {
1166*cdf0e10cSrcweir                         xInputStream.clear();
1167*cdf0e10cSrcweir                     }
1168*cdf0e10cSrcweir                     catch ( io::IOException const & )
1169*cdf0e10cSrcweir                     {
1170*cdf0e10cSrcweir                         xInputStream.clear();
1171*cdf0e10cSrcweir                     }
1172*cdf0e10cSrcweir                 }
1173*cdf0e10cSrcweir                 else
1174*cdf0e10cSrcweir                     xInputStream.clear();
1175*cdf0e10cSrcweir 
1176*cdf0e10cSrcweir                 if ( !xInputStream.is() )
1177*cdf0e10cSrcweir                 {
1178*cdf0e10cSrcweir                     xInputStream
1179*cdf0e10cSrcweir                         = getInputStream( rContext, xCommandProcessorS );
1180*cdf0e10cSrcweir                     if ( !xInputStream.is() )
1181*cdf0e10cSrcweir                     {
1182*cdf0e10cSrcweir                         uno::Any aProps2
1183*cdf0e10cSrcweir                             = uno::makeAny(
1184*cdf0e10cSrcweir                                 beans::PropertyValue(
1185*cdf0e10cSrcweir                                     rtl::OUString(
1186*cdf0e10cSrcweir                                         RTL_CONSTASCII_USTRINGPARAM( "Uri" ) ),
1187*cdf0e10cSrcweir                                     -1,
1188*cdf0e10cSrcweir                                     uno::makeAny(
1189*cdf0e10cSrcweir                                         xNew->getIdentifier()->
1190*cdf0e10cSrcweir                                             getContentIdentifier() ),
1191*cdf0e10cSrcweir                                     beans::PropertyState_DIRECT_VALUE ) );
1192*cdf0e10cSrcweir                         ucbhelper::cancelCommandExecution(
1193*cdf0e10cSrcweir                             ucb::IOErrorCode_CANT_READ,
1194*cdf0e10cSrcweir                             uno::Sequence< uno::Any >( &aProps2, 1 ),
1195*cdf0e10cSrcweir                             rContext.xOrigEnv,
1196*cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1197*cdf0e10cSrcweir                                 "Got no data stream from source!" ),
1198*cdf0e10cSrcweir                             rContext.xProcessor );
1199*cdf0e10cSrcweir                         // Unreachable
1200*cdf0e10cSrcweir                     }
1201*cdf0e10cSrcweir                 }
1202*cdf0e10cSrcweir             }
1203*cdf0e10cSrcweir 
1204*cdf0e10cSrcweir             ucb::InsertCommandArgument aArg;
1205*cdf0e10cSrcweir             aArg.Data = xInputStream;
1206*cdf0e10cSrcweir             aArg.ReplaceExisting = sal_False;
1207*cdf0e10cSrcweir 
1208*cdf0e10cSrcweir             ucb::Command aInsertCommand(
1209*cdf0e10cSrcweir                         rtl::OUString::createFromAscii( "insert" ),
1210*cdf0e10cSrcweir                         -1,
1211*cdf0e10cSrcweir                         uno::makeAny( aArg ) );
1212*cdf0e10cSrcweir 
1213*cdf0e10cSrcweir             xCommandProcessorN->execute( aInsertCommand, 0, rContext.xEnv );
1214*cdf0e10cSrcweir 
1215*cdf0e10cSrcweir             // Success!
1216*cdf0e10cSrcweir             bContinue = sal_False;
1217*cdf0e10cSrcweir         }
1218*cdf0e10cSrcweir         catch ( uno::RuntimeException const & )
1219*cdf0e10cSrcweir         {
1220*cdf0e10cSrcweir             throw;
1221*cdf0e10cSrcweir         }
1222*cdf0e10cSrcweir         catch ( uno::Exception const & )
1223*cdf0e10cSrcweir         {
1224*cdf0e10cSrcweir         }
1225*cdf0e10cSrcweir     }
1226*cdf0e10cSrcweir     while ( bContinue && ( nTry < 50 ) );
1227*cdf0e10cSrcweir 
1228*cdf0e10cSrcweir     if ( nTry == 50 )
1229*cdf0e10cSrcweir     {
1230*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1231*cdf0e10cSrcweir             uno::makeAny(
1232*cdf0e10cSrcweir                 ucb::UnsupportedNameClashException(
1233*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
1234*cdf0e10cSrcweir                         "Unable to resolve name clash!" ),
1235*cdf0e10cSrcweir                     rContext.xProcessor,
1236*cdf0e10cSrcweir                     ucb::NameClash::RENAME ) ),
1237*cdf0e10cSrcweir             rContext.xOrigEnv );
1238*cdf0e10cSrcweir         // Unreachable
1239*cdf0e10cSrcweir     }
1240*cdf0e10cSrcweir }
1241*cdf0e10cSrcweir 
1242*cdf0e10cSrcweir //=========================================================================
1243*cdf0e10cSrcweir void globalTransfer_(
1244*cdf0e10cSrcweir         const TransferCommandContext & rContext,
1245*cdf0e10cSrcweir         const uno::Reference< ucb::XContent > & xSource,
1246*cdf0e10cSrcweir         const uno::Reference< ucb::XContent > & xTarget,
1247*cdf0e10cSrcweir         const uno::Reference< sdbc::XRow > & xSourceProps )
1248*cdf0e10cSrcweir     throw( uno::Exception )
1249*cdf0e10cSrcweir {
1250*cdf0e10cSrcweir     // IsFolder: property is required.
1251*cdf0e10cSrcweir     sal_Bool bSourceIsFolder = xSourceProps->getBoolean( 1 );
1252*cdf0e10cSrcweir     if ( !bSourceIsFolder && xSourceProps->wasNull() )
1253*cdf0e10cSrcweir     {
1254*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1255*cdf0e10cSrcweir             uno::makeAny( beans::UnknownPropertyException(
1256*cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1257*cdf0e10cSrcweir                                 "Unable to get property 'IsFolder' "
1258*cdf0e10cSrcweir                                 "from source object!" ),
1259*cdf0e10cSrcweir                             rContext.xProcessor ) ),
1260*cdf0e10cSrcweir             rContext.xOrigEnv );
1261*cdf0e10cSrcweir         // Unreachable
1262*cdf0e10cSrcweir     }
1263*cdf0e10cSrcweir 
1264*cdf0e10cSrcweir     // IsDocument: property is required.
1265*cdf0e10cSrcweir     sal_Bool bSourceIsDocument = xSourceProps->getBoolean( 2 );
1266*cdf0e10cSrcweir     if ( !bSourceIsDocument && xSourceProps->wasNull() )
1267*cdf0e10cSrcweir     {
1268*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1269*cdf0e10cSrcweir             uno::makeAny( beans::UnknownPropertyException(
1270*cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1271*cdf0e10cSrcweir                                 "Unable to get property 'IsDocument' "
1272*cdf0e10cSrcweir                                 "from source object!" ),
1273*cdf0e10cSrcweir                             rContext.xProcessor ) ),
1274*cdf0e10cSrcweir             rContext.xOrigEnv );
1275*cdf0e10cSrcweir         // Unreachable
1276*cdf0e10cSrcweir     }
1277*cdf0e10cSrcweir 
1278*cdf0e10cSrcweir     // TargetURL: property is optional.
1279*cdf0e10cSrcweir     sal_Bool bSourceIsLink = ( xSourceProps->getString( 3 ).getLength() > 0 );
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1282*cdf0e10cSrcweir     //
1283*cdf0e10cSrcweir     // (1) Try to find a matching target type for the source object and
1284*cdf0e10cSrcweir     //     create a new, empty object of that type.
1285*cdf0e10cSrcweir     //
1286*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1287*cdf0e10cSrcweir 
1288*cdf0e10cSrcweir     uno::Reference< ucb::XContent > xNew = createNew( rContext,
1289*cdf0e10cSrcweir                                                       xTarget,
1290*cdf0e10cSrcweir                                                       bSourceIsFolder,
1291*cdf0e10cSrcweir                                                       bSourceIsDocument,
1292*cdf0e10cSrcweir                                                       bSourceIsLink );
1293*cdf0e10cSrcweir     if ( !xNew.is() )
1294*cdf0e10cSrcweir     {
1295*cdf0e10cSrcweir         uno::Any aProps
1296*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
1297*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1298*cdf0e10cSrcweir                                       "Folder")),
1299*cdf0e10cSrcweir                                   -1,
1300*cdf0e10cSrcweir                                   uno::makeAny(rContext.aArg.TargetURL),
1301*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
1302*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1303*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_CREATE,
1304*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
1305*cdf0e10cSrcweir             rContext.xOrigEnv,
1306*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
1307*cdf0e10cSrcweir                 "No matching content type at target!" ),
1308*cdf0e10cSrcweir             rContext.xProcessor );
1309*cdf0e10cSrcweir         // Unreachable
1310*cdf0e10cSrcweir     }
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1313*cdf0e10cSrcweir     //
1314*cdf0e10cSrcweir     // (2) Transfer property values from source to new object.
1315*cdf0e10cSrcweir     //
1316*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1317*cdf0e10cSrcweir 
1318*cdf0e10cSrcweir     uno::Reference< ucb::XCommandProcessor > xCommandProcessorN(
1319*cdf0e10cSrcweir                                                     xNew, uno::UNO_QUERY );
1320*cdf0e10cSrcweir     if ( !xCommandProcessorN.is() )
1321*cdf0e10cSrcweir     {
1322*cdf0e10cSrcweir         uno::Any aProps
1323*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
1324*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1325*cdf0e10cSrcweir                                                     "Uri")),
1326*cdf0e10cSrcweir                                   -1,
1327*cdf0e10cSrcweir                                   uno::makeAny(
1328*cdf0e10cSrcweir                                       xNew->getIdentifier()->
1329*cdf0e10cSrcweir                                                 getContentIdentifier()),
1330*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
1331*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1332*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_WRITE,
1333*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
1334*cdf0e10cSrcweir             rContext.xOrigEnv,
1335*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
1336*cdf0e10cSrcweir                 "New content is not a XCommandProcessor!" ),
1337*cdf0e10cSrcweir             rContext.xProcessor );
1338*cdf0e10cSrcweir         // Unreachable
1339*cdf0e10cSrcweir     }
1340*cdf0e10cSrcweir 
1341*cdf0e10cSrcweir     // Obtain all properties from source.
1342*cdf0e10cSrcweir 
1343*cdf0e10cSrcweir     uno::Reference< ucb::XCommandProcessor > xCommandProcessorS(
1344*cdf0e10cSrcweir                                                     xSource, uno::UNO_QUERY );
1345*cdf0e10cSrcweir     if ( !xCommandProcessorS.is() )
1346*cdf0e10cSrcweir     {
1347*cdf0e10cSrcweir         uno::Any aProps
1348*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
1349*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1350*cdf0e10cSrcweir                                                     "Uri")),
1351*cdf0e10cSrcweir                                   -1,
1352*cdf0e10cSrcweir                                   uno::makeAny(rContext.aArg.SourceURL),
1353*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
1354*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1355*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_READ,
1356*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
1357*cdf0e10cSrcweir             rContext.xOrigEnv,
1358*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
1359*cdf0e10cSrcweir                 "Source content is not a XCommandProcessor!" ),
1360*cdf0e10cSrcweir             rContext.xProcessor );
1361*cdf0e10cSrcweir         // Unreachable
1362*cdf0e10cSrcweir     }
1363*cdf0e10cSrcweir 
1364*cdf0e10cSrcweir     transferProperties( rContext, xCommandProcessorS, xCommandProcessorN );
1365*cdf0e10cSrcweir 
1366*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1367*cdf0e10cSrcweir     //
1368*cdf0e10cSrcweir     // (3) Try to obtain a data stream from source.
1369*cdf0e10cSrcweir     //
1370*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1371*cdf0e10cSrcweir 
1372*cdf0e10cSrcweir     uno::Reference< io::XInputStream > xInputStream;
1373*cdf0e10cSrcweir 
1374*cdf0e10cSrcweir     if ( bSourceIsDocument && ( rContext.aArg.Operation
1375*cdf0e10cSrcweir                                 != ucb::TransferCommandOperation_LINK ) )
1376*cdf0e10cSrcweir         xInputStream = getInputStream( rContext, xCommandProcessorS );
1377*cdf0e10cSrcweir 
1378*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1379*cdf0e10cSrcweir     //
1380*cdf0e10cSrcweir     // (4) Try to obtain a resultset (children) from source.
1381*cdf0e10cSrcweir     //
1382*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1383*cdf0e10cSrcweir 
1384*cdf0e10cSrcweir     uno::Reference< sdbc::XResultSet > xResultSet;
1385*cdf0e10cSrcweir 
1386*cdf0e10cSrcweir     if ( bSourceIsFolder && ( rContext.aArg.Operation
1387*cdf0e10cSrcweir                                 != ucb::TransferCommandOperation_LINK ) )
1388*cdf0e10cSrcweir         xResultSet = getResultSet( rContext, xCommandProcessorS );
1389*cdf0e10cSrcweir 
1390*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1391*cdf0e10cSrcweir     //
1392*cdf0e10cSrcweir     // (5) Insert (store) new content.
1393*cdf0e10cSrcweir     //
1394*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1395*cdf0e10cSrcweir 
1396*cdf0e10cSrcweir     ucb::InsertCommandArgument aArg;
1397*cdf0e10cSrcweir     aArg.Data = xInputStream;
1398*cdf0e10cSrcweir 
1399*cdf0e10cSrcweir     switch ( rContext.aArg.NameClash )
1400*cdf0e10cSrcweir     {
1401*cdf0e10cSrcweir         case ucb::NameClash::OVERWRITE:
1402*cdf0e10cSrcweir             aArg.ReplaceExisting = sal_True;
1403*cdf0e10cSrcweir             break;
1404*cdf0e10cSrcweir 
1405*cdf0e10cSrcweir         case ucb::NameClash::ERROR:
1406*cdf0e10cSrcweir         case ucb::NameClash::RENAME:
1407*cdf0e10cSrcweir         case ucb::NameClash::KEEP: // deprecated
1408*cdf0e10cSrcweir         case ucb::NameClash::ASK:
1409*cdf0e10cSrcweir             aArg.ReplaceExisting = sal_False;
1410*cdf0e10cSrcweir             break;
1411*cdf0e10cSrcweir 
1412*cdf0e10cSrcweir         default:
1413*cdf0e10cSrcweir             aArg.ReplaceExisting = sal_False;
1414*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "Unknown nameclash directive!" );
1415*cdf0e10cSrcweir             break;
1416*cdf0e10cSrcweir     }
1417*cdf0e10cSrcweir 
1418*cdf0e10cSrcweir     rtl::OUString aDesiredName = createDesiredName( rContext.aArg );
1419*cdf0e10cSrcweir 
1420*cdf0e10cSrcweir     bool bRetry;
1421*cdf0e10cSrcweir     do
1422*cdf0e10cSrcweir     {
1423*cdf0e10cSrcweir         bRetry = false;
1424*cdf0e10cSrcweir 
1425*cdf0e10cSrcweir         try
1426*cdf0e10cSrcweir         {
1427*cdf0e10cSrcweir             ucb::Command aInsertCommand(
1428*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii( "insert" ),
1429*cdf0e10cSrcweir                                     -1,
1430*cdf0e10cSrcweir                                     uno::makeAny( aArg ) );
1431*cdf0e10cSrcweir 
1432*cdf0e10cSrcweir             xCommandProcessorN->execute( aInsertCommand, 0, rContext.xEnv );
1433*cdf0e10cSrcweir         }
1434*cdf0e10cSrcweir         catch ( ucb::UnsupportedNameClashException const & exc )
1435*cdf0e10cSrcweir         {
1436*cdf0e10cSrcweir             OSL_ENSURE( !aArg.ReplaceExisting,
1437*cdf0e10cSrcweir                         "BUG: UnsupportedNameClashException not allowed here!" );
1438*cdf0e10cSrcweir 
1439*cdf0e10cSrcweir             if (exc.NameClash != ucb::NameClash::ERROR) {
1440*cdf0e10cSrcweir                 OSL_ENSURE( false, "BUG: NameClash::ERROR expected!" );
1441*cdf0e10cSrcweir             }
1442*cdf0e10cSrcweir 
1443*cdf0e10cSrcweir             // No chance to solve name clashes, because I'm not able to detect
1444*cdf0e10cSrcweir             // whether there is one.
1445*cdf0e10cSrcweir             throw ucb::UnsupportedNameClashException(
1446*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
1447*cdf0e10cSrcweir                         "Unable to resolve name clashes, no chance to detect "
1448*cdf0e10cSrcweir                         "that there is one!" ),
1449*cdf0e10cSrcweir                     rContext.xProcessor,
1450*cdf0e10cSrcweir                     rContext.aArg.NameClash );
1451*cdf0e10cSrcweir         }
1452*cdf0e10cSrcweir         catch ( ucb::NameClashException const & )
1453*cdf0e10cSrcweir         {
1454*cdf0e10cSrcweir             // The 'insert' command throws a NameClashException if the parameter
1455*cdf0e10cSrcweir             // ReplaceExisting of the command's argument was set to false and
1456*cdf0e10cSrcweir             // there exists a resource with a clashing name in the target folder
1457*cdf0e10cSrcweir             // of the operation.
1458*cdf0e10cSrcweir 
1459*cdf0e10cSrcweir             // 'insert' command has no direct support for name clashes other
1460*cdf0e10cSrcweir             // than ERROR ( ReplaceExisting == false ) and OVERWRITE
1461*cdf0e10cSrcweir             // ( ReplaceExisting == true ). So we have to implement the
1462*cdf0e10cSrcweir             // other name clash handling directives on top of the content.
1463*cdf0e10cSrcweir 
1464*cdf0e10cSrcweir             // @@@ 'insert' command should be extended that it accepts a
1465*cdf0e10cSrcweir             //     name clash handling directive, exactly like 'transfer' command.
1466*cdf0e10cSrcweir 
1467*cdf0e10cSrcweir             switch ( rContext.aArg.NameClash )
1468*cdf0e10cSrcweir             {
1469*cdf0e10cSrcweir                 case ucb::NameClash::OVERWRITE:
1470*cdf0e10cSrcweir                 {
1471*cdf0e10cSrcweir                     ucbhelper::cancelCommandExecution(
1472*cdf0e10cSrcweir                         uno::makeAny(
1473*cdf0e10cSrcweir                             ucb::UnsupportedNameClashException(
1474*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1475*cdf0e10cSrcweir                                     "BUG: insert + replace == true MUST NOT "
1476*cdf0e10cSrcweir                                     "throw NameClashException." ),
1477*cdf0e10cSrcweir                                 rContext.xProcessor,
1478*cdf0e10cSrcweir                                 rContext.aArg.NameClash ) ),
1479*cdf0e10cSrcweir                         rContext.xOrigEnv );
1480*cdf0e10cSrcweir                     // Unreachable
1481*cdf0e10cSrcweir                 }
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir                 case ucb::NameClash::ERROR:
1484*cdf0e10cSrcweir                     throw;
1485*cdf0e10cSrcweir 
1486*cdf0e10cSrcweir                 case ucb::NameClash::RENAME:
1487*cdf0e10cSrcweir                 {
1488*cdf0e10cSrcweir                     // "invent" a new valid title.
1489*cdf0e10cSrcweir                     handleNameClashRename( rContext,
1490*cdf0e10cSrcweir                                            xNew,
1491*cdf0e10cSrcweir                                            xCommandProcessorN,
1492*cdf0e10cSrcweir                                            xCommandProcessorS,
1493*cdf0e10cSrcweir                                            xInputStream );
1494*cdf0e10cSrcweir                     break;
1495*cdf0e10cSrcweir                 }
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir                 case ucb::NameClash::ASK:
1498*cdf0e10cSrcweir                     {
1499*cdf0e10cSrcweir                         uno::Any aExc;
1500*cdf0e10cSrcweir                         rtl::OUString aNewTitle;
1501*cdf0e10cSrcweir                         NameClashContinuation eCont
1502*cdf0e10cSrcweir                             = interactiveNameClashResolve(
1503*cdf0e10cSrcweir                                 rContext.xOrigEnv, // always use original environment!
1504*cdf0e10cSrcweir                                 rContext.aArg.TargetURL, // target folder URL
1505*cdf0e10cSrcweir                                 aDesiredName,
1506*cdf0e10cSrcweir                                 aExc,
1507*cdf0e10cSrcweir                                 aNewTitle );
1508*cdf0e10cSrcweir 
1509*cdf0e10cSrcweir                         switch ( eCont )
1510*cdf0e10cSrcweir                         {
1511*cdf0e10cSrcweir                             case NOT_HANDLED:
1512*cdf0e10cSrcweir                                 // Not handled.
1513*cdf0e10cSrcweir                                 cppu::throwException( aExc );
1514*cdf0e10cSrcweir     //                            break;
1515*cdf0e10cSrcweir 
1516*cdf0e10cSrcweir                             case UNKNOWN:
1517*cdf0e10cSrcweir                                 // Handled, but not clear, how...
1518*cdf0e10cSrcweir                                 // fall-thru intended.
1519*cdf0e10cSrcweir 
1520*cdf0e10cSrcweir                             case ABORT:
1521*cdf0e10cSrcweir                                 throw ucb::CommandFailedException(
1522*cdf0e10cSrcweir                                     rtl::OUString(
1523*cdf0e10cSrcweir                                         RTL_CONSTASCII_USTRINGPARAM(
1524*cdf0e10cSrcweir                                             "abort requested via interaction "
1525*cdf0e10cSrcweir                                             "handler" ) ),
1526*cdf0e10cSrcweir                                     uno::Reference< uno::XInterface >(),
1527*cdf0e10cSrcweir                                     aExc );
1528*cdf0e10cSrcweir     //                            break;
1529*cdf0e10cSrcweir 
1530*cdf0e10cSrcweir                             case OVERWRITE:
1531*cdf0e10cSrcweir                                 OSL_ENSURE( aArg.ReplaceExisting == sal_False,
1532*cdf0e10cSrcweir                                             "Hu? ReplaceExisting already true?"
1533*cdf0e10cSrcweir                                           );
1534*cdf0e10cSrcweir                                 aArg.ReplaceExisting = sal_True;
1535*cdf0e10cSrcweir                                 bRetry = true;
1536*cdf0e10cSrcweir                                 break;
1537*cdf0e10cSrcweir 
1538*cdf0e10cSrcweir                             case NEW_NAME:
1539*cdf0e10cSrcweir                             {
1540*cdf0e10cSrcweir                                 // set new name -> set "Title" property...
1541*cdf0e10cSrcweir                                 if ( setTitle( xCommandProcessorN,
1542*cdf0e10cSrcweir                                                rContext.xEnv,
1543*cdf0e10cSrcweir                                                aNewTitle ) )
1544*cdf0e10cSrcweir                                 {
1545*cdf0e10cSrcweir                                     // remember suggested title...
1546*cdf0e10cSrcweir                                     aDesiredName = aNewTitle;
1547*cdf0e10cSrcweir 
1548*cdf0e10cSrcweir                                     // ... and try again.
1549*cdf0e10cSrcweir                                     bRetry = true;
1550*cdf0e10cSrcweir                                 }
1551*cdf0e10cSrcweir                                 else
1552*cdf0e10cSrcweir                                 {
1553*cdf0e10cSrcweir                                     // error setting title. Abort.
1554*cdf0e10cSrcweir                                     throw ucb::CommandFailedException(
1555*cdf0e10cSrcweir                                         rtl::OUString(
1556*cdf0e10cSrcweir                                             RTL_CONSTASCII_USTRINGPARAM(
1557*cdf0e10cSrcweir                                                 "error setting Title property!"
1558*cdf0e10cSrcweir                                             ) ),
1559*cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >(),
1560*cdf0e10cSrcweir                                         aExc );
1561*cdf0e10cSrcweir                                 }
1562*cdf0e10cSrcweir                                 break;
1563*cdf0e10cSrcweir                             }
1564*cdf0e10cSrcweir                         }
1565*cdf0e10cSrcweir 
1566*cdf0e10cSrcweir                         OSL_ENSURE( bRetry, "bRetry must be true here!!!" );
1567*cdf0e10cSrcweir                     }
1568*cdf0e10cSrcweir                     break;
1569*cdf0e10cSrcweir 
1570*cdf0e10cSrcweir                 case ucb::NameClash::KEEP: // deprecated
1571*cdf0e10cSrcweir                 default:
1572*cdf0e10cSrcweir                 {
1573*cdf0e10cSrcweir                     ucbhelper::cancelCommandExecution(
1574*cdf0e10cSrcweir                         uno::makeAny(
1575*cdf0e10cSrcweir                             ucb::UnsupportedNameClashException(
1576*cdf0e10cSrcweir                                 rtl::OUString(
1577*cdf0e10cSrcweir                                     RTL_CONSTASCII_USTRINGPARAM(
1578*cdf0e10cSrcweir                                         "default action, don't know how to "
1579*cdf0e10cSrcweir                                         "handle name clash" ) ),
1580*cdf0e10cSrcweir                                 rContext.xProcessor,
1581*cdf0e10cSrcweir                                 rContext.aArg.NameClash ) ),
1582*cdf0e10cSrcweir                         rContext.xOrigEnv );
1583*cdf0e10cSrcweir                     // Unreachable
1584*cdf0e10cSrcweir                 }
1585*cdf0e10cSrcweir             }
1586*cdf0e10cSrcweir         }
1587*cdf0e10cSrcweir     }
1588*cdf0e10cSrcweir     while ( bRetry );
1589*cdf0e10cSrcweir 
1590*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1591*cdf0e10cSrcweir     //
1592*cdf0e10cSrcweir     // (6) Process children of source.
1593*cdf0e10cSrcweir     //
1594*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1595*cdf0e10cSrcweir 
1596*cdf0e10cSrcweir     if ( xResultSet.is() )
1597*cdf0e10cSrcweir     {
1598*cdf0e10cSrcweir         try
1599*cdf0e10cSrcweir         {
1600*cdf0e10cSrcweir             // Iterate over children...
1601*cdf0e10cSrcweir 
1602*cdf0e10cSrcweir             uno::Reference< sdbc::XRow > xChildRow(
1603*cdf0e10cSrcweir                                             xResultSet, uno::UNO_QUERY );
1604*cdf0e10cSrcweir 
1605*cdf0e10cSrcweir             if ( !xChildRow.is() )
1606*cdf0e10cSrcweir             {
1607*cdf0e10cSrcweir                 uno::Any aProps
1608*cdf0e10cSrcweir                     = uno::makeAny(
1609*cdf0e10cSrcweir                              beans::PropertyValue(
1610*cdf0e10cSrcweir                                  rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1611*cdf0e10cSrcweir                                                    "Uri")),
1612*cdf0e10cSrcweir                                  -1,
1613*cdf0e10cSrcweir                                  uno::makeAny(rContext.aArg.SourceURL),
1614*cdf0e10cSrcweir                                  beans::PropertyState_DIRECT_VALUE));
1615*cdf0e10cSrcweir                 ucbhelper::cancelCommandExecution(
1616*cdf0e10cSrcweir                     ucb::IOErrorCode_CANT_READ,
1617*cdf0e10cSrcweir                     uno::Sequence< uno::Any >(&aProps, 1),
1618*cdf0e10cSrcweir                     rContext.xOrigEnv,
1619*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
1620*cdf0e10cSrcweir                         "Unable to get properties from children of source!" ),
1621*cdf0e10cSrcweir                     rContext.xProcessor );
1622*cdf0e10cSrcweir                 // Unreachable
1623*cdf0e10cSrcweir             }
1624*cdf0e10cSrcweir 
1625*cdf0e10cSrcweir             uno::Reference< ucb::XContentAccess > xChildAccess(
1626*cdf0e10cSrcweir                                                 xResultSet, uno::UNO_QUERY );
1627*cdf0e10cSrcweir 
1628*cdf0e10cSrcweir             if ( !xChildAccess.is() )
1629*cdf0e10cSrcweir             {
1630*cdf0e10cSrcweir                 uno::Any aProps
1631*cdf0e10cSrcweir                     = uno::makeAny(
1632*cdf0e10cSrcweir                              beans::PropertyValue(
1633*cdf0e10cSrcweir                                  rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1634*cdf0e10cSrcweir                                      "Uri")),
1635*cdf0e10cSrcweir                                  -1,
1636*cdf0e10cSrcweir                                  uno::makeAny(rContext.aArg.SourceURL),
1637*cdf0e10cSrcweir                                  beans::PropertyState_DIRECT_VALUE));
1638*cdf0e10cSrcweir                 ucbhelper::cancelCommandExecution(
1639*cdf0e10cSrcweir                     ucb::IOErrorCode_CANT_READ,
1640*cdf0e10cSrcweir                     uno::Sequence< uno::Any >(&aProps, 1),
1641*cdf0e10cSrcweir                     rContext.xOrigEnv,
1642*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
1643*cdf0e10cSrcweir                         "Unable to get children of source!" ),
1644*cdf0e10cSrcweir                     rContext.xProcessor );
1645*cdf0e10cSrcweir                 // Unreachable
1646*cdf0e10cSrcweir             }
1647*cdf0e10cSrcweir 
1648*cdf0e10cSrcweir             if ( xResultSet->first() )
1649*cdf0e10cSrcweir             {
1650*cdf0e10cSrcweir                 ucb::GlobalTransferCommandArgument aTransArg(
1651*cdf0e10cSrcweir                         rContext.aArg.Operation,      // Operation
1652*cdf0e10cSrcweir                         rtl::OUString(),              // SourceURL; filled later
1653*cdf0e10cSrcweir                         xNew->getIdentifier()
1654*cdf0e10cSrcweir                             ->getContentIdentifier(), // TargetURL
1655*cdf0e10cSrcweir                         rtl::OUString(),              // NewTitle;
1656*cdf0e10cSrcweir                         rContext.aArg.NameClash );    // NameClash
1657*cdf0e10cSrcweir 
1658*cdf0e10cSrcweir                 TransferCommandContext aSubCtx(
1659*cdf0e10cSrcweir                         rContext.xSMgr,
1660*cdf0e10cSrcweir                         rContext.xProcessor,
1661*cdf0e10cSrcweir                         rContext.xEnv,
1662*cdf0e10cSrcweir                         rContext.xOrigEnv,
1663*cdf0e10cSrcweir                         aTransArg );
1664*cdf0e10cSrcweir                 do
1665*cdf0e10cSrcweir                 {
1666*cdf0e10cSrcweir                     uno::Reference< ucb::XContent > xChild
1667*cdf0e10cSrcweir                                         = xChildAccess->queryContent();
1668*cdf0e10cSrcweir                     if ( xChild.is() )
1669*cdf0e10cSrcweir                     {
1670*cdf0e10cSrcweir                         // Recursion!
1671*cdf0e10cSrcweir 
1672*cdf0e10cSrcweir                         aSubCtx.aArg.SourceURL
1673*cdf0e10cSrcweir                             = xChild->getIdentifier()->getContentIdentifier();
1674*cdf0e10cSrcweir 
1675*cdf0e10cSrcweir                         globalTransfer_( aSubCtx,
1676*cdf0e10cSrcweir                                          xChild,
1677*cdf0e10cSrcweir                                          xNew,
1678*cdf0e10cSrcweir                                          xChildRow );
1679*cdf0e10cSrcweir                     }
1680*cdf0e10cSrcweir                 }
1681*cdf0e10cSrcweir                 while ( xResultSet->next() );
1682*cdf0e10cSrcweir             }
1683*cdf0e10cSrcweir         }
1684*cdf0e10cSrcweir         catch ( sdbc::SQLException const & )
1685*cdf0e10cSrcweir         {
1686*cdf0e10cSrcweir         }
1687*cdf0e10cSrcweir     }
1688*cdf0e10cSrcweir 
1689*cdf0e10cSrcweir     try {
1690*cdf0e10cSrcweir         uno::Reference< ucb::XCommandProcessor > xcp(
1691*cdf0e10cSrcweir             xTarget, uno::UNO_QUERY );
1692*cdf0e10cSrcweir 
1693*cdf0e10cSrcweir         uno::Any aAny;
1694*cdf0e10cSrcweir         uno::Reference< ucb::XCommandInfo > xci;
1695*cdf0e10cSrcweir         if(xcp.is())
1696*cdf0e10cSrcweir             aAny =
1697*cdf0e10cSrcweir                 xcp->execute(
1698*cdf0e10cSrcweir                     ucb::Command(
1699*cdf0e10cSrcweir                         rtl::OUString::createFromAscii("getCommandInfo"),
1700*cdf0e10cSrcweir                         -1,
1701*cdf0e10cSrcweir                         uno::Any()),
1702*cdf0e10cSrcweir                     0,
1703*cdf0e10cSrcweir                     rContext.xEnv );
1704*cdf0e10cSrcweir 
1705*cdf0e10cSrcweir         const rtl::OUString cmdName =
1706*cdf0e10cSrcweir             rtl::OUString::createFromAscii("flush");
1707*cdf0e10cSrcweir         if((aAny >>= xci) && xci->hasCommandByName(cmdName))
1708*cdf0e10cSrcweir             xcp->execute(
1709*cdf0e10cSrcweir                 ucb::Command(
1710*cdf0e10cSrcweir                     cmdName,
1711*cdf0e10cSrcweir                     -1,
1712*cdf0e10cSrcweir                     uno::Any()) ,
1713*cdf0e10cSrcweir                 0,
1714*cdf0e10cSrcweir                 rContext.xEnv );
1715*cdf0e10cSrcweir     }
1716*cdf0e10cSrcweir     catch( uno::Exception const & )
1717*cdf0e10cSrcweir     {
1718*cdf0e10cSrcweir     }
1719*cdf0e10cSrcweir }
1720*cdf0e10cSrcweir 
1721*cdf0e10cSrcweir } /* namescpace */
1722*cdf0e10cSrcweir 
1723*cdf0e10cSrcweir //=========================================================================
1724*cdf0e10cSrcweir //
1725*cdf0e10cSrcweir // UniversalContentBroker implementation ( XCommandProcessor commands ).
1726*cdf0e10cSrcweir //
1727*cdf0e10cSrcweir //=========================================================================
1728*cdf0e10cSrcweir 
1729*cdf0e10cSrcweir uno::Reference< ucb::XCommandInfo >
1730*cdf0e10cSrcweir UniversalContentBroker::getCommandInfo()
1731*cdf0e10cSrcweir {
1732*cdf0e10cSrcweir     return uno::Reference< ucb::XCommandInfo >( new CommandProcessorInfo() );
1733*cdf0e10cSrcweir }
1734*cdf0e10cSrcweir 
1735*cdf0e10cSrcweir //=========================================================================
1736*cdf0e10cSrcweir void UniversalContentBroker::globalTransfer(
1737*cdf0e10cSrcweir             const ucb::GlobalTransferCommandArgument & rArg,
1738*cdf0e10cSrcweir             const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1739*cdf0e10cSrcweir     throw( uno::Exception )
1740*cdf0e10cSrcweir {
1741*cdf0e10cSrcweir     // Use own command environment with own interaction handler intercepting
1742*cdf0e10cSrcweir     // some interaction requests that shall not be handled by the user-supplied
1743*cdf0e10cSrcweir     // interaction handler.
1744*cdf0e10cSrcweir     uno::Reference< ucb::XCommandEnvironment > xLocalEnv;
1745*cdf0e10cSrcweir     if (xEnv.is())
1746*cdf0e10cSrcweir     {
1747*cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > const xProps(
1748*cdf0e10cSrcweir             m_xSMgr, uno::UNO_QUERY_THROW );
1749*cdf0e10cSrcweir         uno::Reference< uno::XComponentContext > xCtx;
1750*cdf0e10cSrcweir             xCtx.set( xProps->getPropertyValue(
1751*cdf0e10cSrcweir                 rtl::OUString(
1752*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ),
1753*cdf0e10cSrcweir                 uno::UNO_QUERY_THROW );
1754*cdf0e10cSrcweir 
1755*cdf0e10cSrcweir             xLocalEnv.set( ucb::CommandEnvironment::create(
1756*cdf0e10cSrcweir                xCtx,
1757*cdf0e10cSrcweir                new InteractionHandlerProxy( xEnv->getInteractionHandler() ),
1758*cdf0e10cSrcweir                xEnv->getProgressHandler() ) );
1759*cdf0e10cSrcweir     }
1760*cdf0e10cSrcweir 
1761*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1762*cdf0e10cSrcweir     //
1763*cdf0e10cSrcweir     // (1) Try to transfer the content using 'transfer' command.
1764*cdf0e10cSrcweir     //
1765*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1766*cdf0e10cSrcweir 
1767*cdf0e10cSrcweir     uno::Reference< ucb::XContent > xTarget;
1768*cdf0e10cSrcweir     uno::Reference< ucb::XContentIdentifier > xId
1769*cdf0e10cSrcweir             = createContentIdentifier( rArg.TargetURL );
1770*cdf0e10cSrcweir     if ( xId.is() )
1771*cdf0e10cSrcweir     {
1772*cdf0e10cSrcweir         try
1773*cdf0e10cSrcweir         {
1774*cdf0e10cSrcweir             xTarget = queryContent( xId );
1775*cdf0e10cSrcweir         }
1776*cdf0e10cSrcweir         catch ( ucb::IllegalIdentifierException const & )
1777*cdf0e10cSrcweir         {
1778*cdf0e10cSrcweir         }
1779*cdf0e10cSrcweir     }
1780*cdf0e10cSrcweir 
1781*cdf0e10cSrcweir     if ( !xTarget.is() )
1782*cdf0e10cSrcweir     {
1783*cdf0e10cSrcweir         uno::Any aProps
1784*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
1785*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1786*cdf0e10cSrcweir                                       "Uri")),
1787*cdf0e10cSrcweir                                   -1,
1788*cdf0e10cSrcweir                                   uno::makeAny(rArg.TargetURL),
1789*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
1790*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1791*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_READ,
1792*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
1793*cdf0e10cSrcweir             xEnv,
1794*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
1795*cdf0e10cSrcweir                 "Can't instanciate target object!" ),
1796*cdf0e10cSrcweir             this );
1797*cdf0e10cSrcweir         // Unreachable
1798*cdf0e10cSrcweir     }
1799*cdf0e10cSrcweir 
1800*cdf0e10cSrcweir     if ( ( rArg.Operation == ucb::TransferCommandOperation_COPY ) ||
1801*cdf0e10cSrcweir          ( rArg.Operation == ucb::TransferCommandOperation_MOVE ) )
1802*cdf0e10cSrcweir     {
1803*cdf0e10cSrcweir         uno::Reference< ucb::XCommandProcessor > xCommandProcessor(
1804*cdf0e10cSrcweir                                                     xTarget, uno::UNO_QUERY );
1805*cdf0e10cSrcweir         if ( !xCommandProcessor.is() )
1806*cdf0e10cSrcweir         {
1807*cdf0e10cSrcweir             uno::Any aProps
1808*cdf0e10cSrcweir                 = uno::makeAny(
1809*cdf0e10cSrcweir                          beans::PropertyValue(
1810*cdf0e10cSrcweir                              rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1811*cdf0e10cSrcweir                                                "Uri")),
1812*cdf0e10cSrcweir                              -1,
1813*cdf0e10cSrcweir                              uno::makeAny(rArg.TargetURL),
1814*cdf0e10cSrcweir                              beans::PropertyState_DIRECT_VALUE));
1815*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
1816*cdf0e10cSrcweir                 ucb::IOErrorCode_CANT_READ,
1817*cdf0e10cSrcweir                 uno::Sequence< uno::Any >(&aProps, 1),
1818*cdf0e10cSrcweir                 xEnv,
1819*cdf0e10cSrcweir                 rtl::OUString::createFromAscii(
1820*cdf0e10cSrcweir                     "Target content is not a XCommandProcessor!" ),
1821*cdf0e10cSrcweir                 this );
1822*cdf0e10cSrcweir             // Unreachable
1823*cdf0e10cSrcweir         }
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir         ucb::TransferInfo aTransferArg(
1826*cdf0e10cSrcweir             ( rArg.Operation
1827*cdf0e10cSrcweir                 == ucb::TransferCommandOperation_MOVE ), // MoveData
1828*cdf0e10cSrcweir             rArg.SourceURL,   // SourceURL
1829*cdf0e10cSrcweir             rArg.NewTitle,    // NewTitle
1830*cdf0e10cSrcweir             rArg.NameClash ); // NameClash
1831*cdf0e10cSrcweir 
1832*cdf0e10cSrcweir         bool bRetry;
1833*cdf0e10cSrcweir         do
1834*cdf0e10cSrcweir         {
1835*cdf0e10cSrcweir             bRetry = false;
1836*cdf0e10cSrcweir 
1837*cdf0e10cSrcweir             try
1838*cdf0e10cSrcweir             {
1839*cdf0e10cSrcweir                 ucb::Command aCommand(
1840*cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "transfer" ), // Name
1841*cdf0e10cSrcweir                     -1,                                           // Handle
1842*cdf0e10cSrcweir                     uno::makeAny( aTransferArg ) );               // Argument
1843*cdf0e10cSrcweir 
1844*cdf0e10cSrcweir                 xCommandProcessor->execute( aCommand, 0, xLocalEnv );
1845*cdf0e10cSrcweir 
1846*cdf0e10cSrcweir                 // Command succeeded. We're done.
1847*cdf0e10cSrcweir                 return;
1848*cdf0e10cSrcweir             }
1849*cdf0e10cSrcweir             catch ( ucb::InteractiveBadTransferURLException const & )
1850*cdf0e10cSrcweir             {
1851*cdf0e10cSrcweir                 // Source URL is not supported by target. Try to transfer
1852*cdf0e10cSrcweir                 // the content "manually".
1853*cdf0e10cSrcweir             }
1854*cdf0e10cSrcweir             catch ( ucb::UnsupportedCommandException const & )
1855*cdf0e10cSrcweir             {
1856*cdf0e10cSrcweir                 // 'transfer' command is not supported by commandprocessor.
1857*cdf0e10cSrcweir                 // Try to transfer manually.
1858*cdf0e10cSrcweir             }
1859*cdf0e10cSrcweir             catch ( ucb::UnsupportedNameClashException const & exc )
1860*cdf0e10cSrcweir             {
1861*cdf0e10cSrcweir                 OSL_ENSURE( aTransferArg.NameClash == exc.NameClash,
1862*cdf0e10cSrcweir                             "nameclash mismatch!" );
1863*cdf0e10cSrcweir                 if ( exc.NameClash == ucb::NameClash::ASK )
1864*cdf0e10cSrcweir                 {
1865*cdf0e10cSrcweir                     // Try to detect a name clash by invoking "transfer" with
1866*cdf0e10cSrcweir                     // NameClash::ERROR.
1867*cdf0e10cSrcweir                     try
1868*cdf0e10cSrcweir                     {
1869*cdf0e10cSrcweir                         ucb::TransferInfo aTransferArg1(
1870*cdf0e10cSrcweir                             aTransferArg.MoveData,
1871*cdf0e10cSrcweir                             aTransferArg.SourceURL,
1872*cdf0e10cSrcweir                             aTransferArg.NewTitle,
1873*cdf0e10cSrcweir                             ucb::NameClash::ERROR );
1874*cdf0e10cSrcweir 
1875*cdf0e10cSrcweir                         ucb::Command aCommand1(
1876*cdf0e10cSrcweir                             rtl::OUString::createFromAscii( "transfer" ),
1877*cdf0e10cSrcweir                             -1,
1878*cdf0e10cSrcweir                             uno::makeAny( aTransferArg1 ) );
1879*cdf0e10cSrcweir 
1880*cdf0e10cSrcweir                         xCommandProcessor->execute( aCommand1, 0, xLocalEnv );
1881*cdf0e10cSrcweir 
1882*cdf0e10cSrcweir                         // Command succeeded. We're done.
1883*cdf0e10cSrcweir                         return;
1884*cdf0e10cSrcweir                     }
1885*cdf0e10cSrcweir                     catch ( ucb::UnsupportedNameClashException const & )
1886*cdf0e10cSrcweir                     {
1887*cdf0e10cSrcweir                         // No chance to solve name clashes, because I'm not
1888*cdf0e10cSrcweir                         // able to detect whether there is one.
1889*cdf0e10cSrcweir                         throw exc; // Not just 'throw;'!
1890*cdf0e10cSrcweir                     }
1891*cdf0e10cSrcweir                     catch ( ucb::NameClashException const & )
1892*cdf0e10cSrcweir                     {
1893*cdf0e10cSrcweir                         // There's a clash. Use interaction handler to solve it.
1894*cdf0e10cSrcweir 
1895*cdf0e10cSrcweir                         uno::Any aExc;
1896*cdf0e10cSrcweir                         rtl::OUString aNewTitle;
1897*cdf0e10cSrcweir                         NameClashContinuation eCont
1898*cdf0e10cSrcweir                             = interactiveNameClashResolve(
1899*cdf0e10cSrcweir                                 xEnv, // always use original environment!
1900*cdf0e10cSrcweir                                 rArg.TargetURL,  // target folder URL
1901*cdf0e10cSrcweir                                 createDesiredName(
1902*cdf0e10cSrcweir                                   aTransferArg ),   // clashing name
1903*cdf0e10cSrcweir                                 aExc,
1904*cdf0e10cSrcweir                                 aNewTitle );
1905*cdf0e10cSrcweir 
1906*cdf0e10cSrcweir                         switch ( eCont )
1907*cdf0e10cSrcweir                         {
1908*cdf0e10cSrcweir                             case NOT_HANDLED:
1909*cdf0e10cSrcweir                                 // Not handled.
1910*cdf0e10cSrcweir                                 cppu::throwException( aExc );
1911*cdf0e10cSrcweir //                                break;
1912*cdf0e10cSrcweir 
1913*cdf0e10cSrcweir                             case UNKNOWN:
1914*cdf0e10cSrcweir                                 // Handled, but not clear, how...
1915*cdf0e10cSrcweir                                 // fall-thru intended.
1916*cdf0e10cSrcweir 
1917*cdf0e10cSrcweir                             case ABORT:
1918*cdf0e10cSrcweir                                 throw ucb::CommandFailedException(
1919*cdf0e10cSrcweir                                     rtl::OUString(
1920*cdf0e10cSrcweir                                         RTL_CONSTASCII_USTRINGPARAM(
1921*cdf0e10cSrcweir                                             "abort requested via interaction "
1922*cdf0e10cSrcweir                                             "handler" ) ),
1923*cdf0e10cSrcweir                                     uno::Reference< uno::XInterface >(),
1924*cdf0e10cSrcweir                                     aExc );
1925*cdf0e10cSrcweir //                                break;
1926*cdf0e10cSrcweir 
1927*cdf0e10cSrcweir                             case OVERWRITE:
1928*cdf0e10cSrcweir                                 aTransferArg.NameClash
1929*cdf0e10cSrcweir                                     = ucb::NameClash::OVERWRITE;
1930*cdf0e10cSrcweir                                 bRetry = true;
1931*cdf0e10cSrcweir                                 break;
1932*cdf0e10cSrcweir 
1933*cdf0e10cSrcweir                             case NEW_NAME:
1934*cdf0e10cSrcweir                                 aTransferArg.NewTitle = aNewTitle;
1935*cdf0e10cSrcweir                                 bRetry = true;
1936*cdf0e10cSrcweir                                 break;
1937*cdf0e10cSrcweir                         }
1938*cdf0e10cSrcweir 
1939*cdf0e10cSrcweir                         OSL_ENSURE( bRetry, "bRetry must be true here!!!" );
1940*cdf0e10cSrcweir                     }
1941*cdf0e10cSrcweir                 }
1942*cdf0e10cSrcweir                 else
1943*cdf0e10cSrcweir                 {
1944*cdf0e10cSrcweir                     throw;
1945*cdf0e10cSrcweir                 }
1946*cdf0e10cSrcweir             }
1947*cdf0e10cSrcweir         }
1948*cdf0e10cSrcweir         while ( bRetry );
1949*cdf0e10cSrcweir     }
1950*cdf0e10cSrcweir 
1951*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1952*cdf0e10cSrcweir     //
1953*cdf0e10cSrcweir     // (2) Try to transfer the content "manually".
1954*cdf0e10cSrcweir     //
1955*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1956*cdf0e10cSrcweir 
1957*cdf0e10cSrcweir     uno::Reference< ucb::XContent > xSource;
1958*cdf0e10cSrcweir     try
1959*cdf0e10cSrcweir     {
1960*cdf0e10cSrcweir         uno::Reference< ucb::XContentIdentifier > xId2
1961*cdf0e10cSrcweir             = createContentIdentifier( rArg.SourceURL );
1962*cdf0e10cSrcweir         if ( xId2.is() )
1963*cdf0e10cSrcweir             xSource = queryContent( xId2 );
1964*cdf0e10cSrcweir     }
1965*cdf0e10cSrcweir     catch ( ucb::IllegalIdentifierException const & )
1966*cdf0e10cSrcweir     {
1967*cdf0e10cSrcweir         // Error handling via "if ( !xSource.is() )" below.
1968*cdf0e10cSrcweir     }
1969*cdf0e10cSrcweir 
1970*cdf0e10cSrcweir     if ( !xSource.is() )
1971*cdf0e10cSrcweir     {
1972*cdf0e10cSrcweir         uno::Any aProps
1973*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
1974*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1975*cdf0e10cSrcweir                                                     "Uri")),
1976*cdf0e10cSrcweir                                   -1,
1977*cdf0e10cSrcweir                                   uno::makeAny(rArg.SourceURL),
1978*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
1979*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1980*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_READ,
1981*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
1982*cdf0e10cSrcweir             xEnv,
1983*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
1984*cdf0e10cSrcweir                 "Can't instanciate source object!" ),
1985*cdf0e10cSrcweir             this );
1986*cdf0e10cSrcweir         // Unreachable
1987*cdf0e10cSrcweir     }
1988*cdf0e10cSrcweir 
1989*cdf0e10cSrcweir     uno::Reference< ucb::XCommandProcessor > xCommandProcessor(
1990*cdf0e10cSrcweir                                                 xSource, uno::UNO_QUERY );
1991*cdf0e10cSrcweir     if ( !xCommandProcessor.is() )
1992*cdf0e10cSrcweir     {
1993*cdf0e10cSrcweir         uno::Any aProps
1994*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
1995*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1996*cdf0e10cSrcweir                                                     "Uri")),
1997*cdf0e10cSrcweir                                   -1,
1998*cdf0e10cSrcweir                                   uno::makeAny(rArg.SourceURL),
1999*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
2000*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
2001*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_READ,
2002*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
2003*cdf0e10cSrcweir             xEnv,
2004*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
2005*cdf0e10cSrcweir                 "Source content is not a XCommandProcessor!" ),
2006*cdf0e10cSrcweir             this );
2007*cdf0e10cSrcweir         // Unreachable
2008*cdf0e10cSrcweir     }
2009*cdf0e10cSrcweir 
2010*cdf0e10cSrcweir     // Obtain interesting property values from source...
2011*cdf0e10cSrcweir 
2012*cdf0e10cSrcweir     uno::Sequence< beans::Property > aProps( 4 );
2013*cdf0e10cSrcweir 
2014*cdf0e10cSrcweir     aProps[ 0 ].Name   = rtl::OUString::createFromAscii( "IsFolder" );
2015*cdf0e10cSrcweir     aProps[ 0 ].Handle = -1; /* unknown */
2016*cdf0e10cSrcweir     aProps[ 1 ].Name   = rtl::OUString::createFromAscii( "IsDocument" );
2017*cdf0e10cSrcweir     aProps[ 1 ].Handle = -1; /* unknown */
2018*cdf0e10cSrcweir     aProps[ 2 ].Name   = rtl::OUString::createFromAscii( "TargetURL" );
2019*cdf0e10cSrcweir     aProps[ 2 ].Handle = -1; /* unknown */
2020*cdf0e10cSrcweir     aProps[ 3 ].Name   = rtl::OUString::createFromAscii( "BaseURI" );
2021*cdf0e10cSrcweir     aProps[ 3 ].Handle = -1; /* unknown */
2022*cdf0e10cSrcweir 
2023*cdf0e10cSrcweir     ucb::Command aGetPropsCommand(
2024*cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "getPropertyValues" ),
2025*cdf0e10cSrcweir                 -1,
2026*cdf0e10cSrcweir                 uno::makeAny( aProps ) );
2027*cdf0e10cSrcweir 
2028*cdf0e10cSrcweir     uno::Reference< sdbc::XRow > xRow;
2029*cdf0e10cSrcweir     xCommandProcessor->execute( aGetPropsCommand, 0, xLocalEnv ) >>= xRow;
2030*cdf0e10cSrcweir 
2031*cdf0e10cSrcweir     if ( !xRow.is() )
2032*cdf0e10cSrcweir     {
2033*cdf0e10cSrcweir         uno::Any aProps2
2034*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
2035*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
2036*cdf0e10cSrcweir                                                     "Uri")),
2037*cdf0e10cSrcweir                                   -1,
2038*cdf0e10cSrcweir                                   uno::makeAny(rArg.SourceURL),
2039*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
2040*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
2041*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_READ,
2042*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps2, 1),
2043*cdf0e10cSrcweir             xEnv,
2044*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
2045*cdf0e10cSrcweir                 "Unable to get properties from source object!" ),
2046*cdf0e10cSrcweir             this );
2047*cdf0e10cSrcweir         // Unreachable
2048*cdf0e10cSrcweir     }
2049*cdf0e10cSrcweir 
2050*cdf0e10cSrcweir     TransferCommandContext aTransferCtx(
2051*cdf0e10cSrcweir         m_xSMgr, this, xLocalEnv, xEnv, rArg );
2052*cdf0e10cSrcweir 
2053*cdf0e10cSrcweir     if ( rArg.NewTitle.getLength() == 0 )
2054*cdf0e10cSrcweir     {
2055*cdf0e10cSrcweir         // BaseURI: property is optional.
2056*cdf0e10cSrcweir         rtl::OUString aBaseURI( xRow->getString( 4 ) );
2057*cdf0e10cSrcweir         if ( aBaseURI.getLength() )
2058*cdf0e10cSrcweir         {
2059*cdf0e10cSrcweir             aTransferCtx.aArg.NewTitle
2060*cdf0e10cSrcweir                 = createDesiredName( aBaseURI, rtl::OUString() );
2061*cdf0e10cSrcweir         }
2062*cdf0e10cSrcweir     }
2063*cdf0e10cSrcweir 
2064*cdf0e10cSrcweir     // Do it!
2065*cdf0e10cSrcweir     globalTransfer_( aTransferCtx, xSource, xTarget, xRow );
2066*cdf0e10cSrcweir 
2067*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
2068*cdf0e10cSrcweir     //
2069*cdf0e10cSrcweir     // (3) Delete source, if operation is MOVE.
2070*cdf0e10cSrcweir     //
2071*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
2072*cdf0e10cSrcweir 
2073*cdf0e10cSrcweir     if ( rArg.Operation == ucb::TransferCommandOperation_MOVE )
2074*cdf0e10cSrcweir     {
2075*cdf0e10cSrcweir         try
2076*cdf0e10cSrcweir         {
2077*cdf0e10cSrcweir             ucb::Command aCommand(
2078*cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "delete" ), // Name
2079*cdf0e10cSrcweir                 -1,                                         // Handle
2080*cdf0e10cSrcweir                 uno::makeAny( sal_Bool( sal_True ) ) );     // Argument
2081*cdf0e10cSrcweir 
2082*cdf0e10cSrcweir             xCommandProcessor->execute( aCommand, 0, xLocalEnv );
2083*cdf0e10cSrcweir         }
2084*cdf0e10cSrcweir         catch ( uno::Exception const & )
2085*cdf0e10cSrcweir         {
2086*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "Cannot delete source object!" );
2087*cdf0e10cSrcweir             throw;
2088*cdf0e10cSrcweir         }
2089*cdf0e10cSrcweir     }
2090*cdf0e10cSrcweir }
2091