xref: /trunk/main/ucbhelper/source/client/content.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_ucbhelper.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir /**************************************************************************
32*cdf0e10cSrcweir                                 TODO
33*cdf0e10cSrcweir  **************************************************************************
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir  *************************************************************************/
36*cdf0e10cSrcweir #include <osl/diagnose.h>
37*cdf0e10cSrcweir #include <osl/mutex.hxx>
38*cdf0e10cSrcweir #include <salhelper/simplereferenceobject.hxx>
39*cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
42*cdf0e10cSrcweir #include <com/sun/star/ucb/ContentCreationError.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandProcessor.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/ucb/Command.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/ucb/CommandInfo.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/ucb/ContentAction.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/ucb/GlobalTransferCommandArgument.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentCreator.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentEventListener.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProviderManager.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/ucb/XDynamicResultSet.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
67*cdf0e10cSrcweir #include <com/sun/star/beans/UnknownPropertyException.hpp>
68*cdf0e10cSrcweir #include <ucbhelper/macros.hxx>
69*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
70*cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
71*cdf0e10cSrcweir #include <ucbhelper/activedatasink.hxx>
72*cdf0e10cSrcweir #include <ucbhelper/activedatastreamer.hxx>
73*cdf0e10cSrcweir #include <ucbhelper/interactionrequest.hxx>
74*cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx>
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir using namespace com::sun::star::container;
77*cdf0e10cSrcweir using namespace com::sun::star::beans;
78*cdf0e10cSrcweir using namespace com::sun::star::io;
79*cdf0e10cSrcweir using namespace com::sun::star::lang;
80*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
81*cdf0e10cSrcweir using namespace com::sun::star::task;
82*cdf0e10cSrcweir using namespace com::sun::star::ucb;
83*cdf0e10cSrcweir using namespace com::sun::star::uno;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir namespace ucbhelper
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir class EmptyInputStream : public ::cppu::WeakImplHelper1< XInputStream >
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir public:
91*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readBytes(
92*cdf0e10cSrcweir         Sequence< sal_Int8 > & data, sal_Int32 nBytesToRead )
93*cdf0e10cSrcweir         throw (IOException, RuntimeException);
94*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readSomeBytes(
95*cdf0e10cSrcweir         Sequence< sal_Int8 > & data, sal_Int32 nMaxBytesToRead )
96*cdf0e10cSrcweir         throw (IOException, RuntimeException);
97*cdf0e10cSrcweir     virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
98*cdf0e10cSrcweir         throw (IOException, RuntimeException);
99*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL available()
100*cdf0e10cSrcweir         throw (IOException, RuntimeException);
101*cdf0e10cSrcweir     virtual void SAL_CALL closeInput()
102*cdf0e10cSrcweir         throw (IOException, RuntimeException);
103*cdf0e10cSrcweir };
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir sal_Int32 EmptyInputStream::readBytes(
106*cdf0e10cSrcweir     Sequence< sal_Int8 > & data, sal_Int32 )
107*cdf0e10cSrcweir     throw (IOException, RuntimeException)
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     data.realloc( 0 );
110*cdf0e10cSrcweir     return 0;
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir sal_Int32 EmptyInputStream::readSomeBytes(
114*cdf0e10cSrcweir     Sequence< sal_Int8 > & data, sal_Int32 )
115*cdf0e10cSrcweir     throw (IOException, RuntimeException)
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     data.realloc( 0 );
118*cdf0e10cSrcweir     return 0;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir void EmptyInputStream::skipBytes( sal_Int32 )
122*cdf0e10cSrcweir     throw (IOException, RuntimeException)
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir sal_Int32 EmptyInputStream::available()
127*cdf0e10cSrcweir     throw (IOException, RuntimeException)
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     return 0;
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir void EmptyInputStream::closeInput()
133*cdf0e10cSrcweir     throw (IOException, RuntimeException)
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir //=========================================================================
139*cdf0e10cSrcweir //=========================================================================
140*cdf0e10cSrcweir //
141*cdf0e10cSrcweir // class ContentEventListener_Impl.
142*cdf0e10cSrcweir //
143*cdf0e10cSrcweir //=========================================================================
144*cdf0e10cSrcweir //=========================================================================
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir class ContentEventListener_Impl : public cppu::OWeakObject,
147*cdf0e10cSrcweir                                       public XContentEventListener
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     Content_Impl& m_rContent;
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir public:
152*cdf0e10cSrcweir     ContentEventListener_Impl( Content_Impl& rContent )
153*cdf0e10cSrcweir     : m_rContent( rContent ) {}
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     // XInterface
156*cdf0e10cSrcweir     XINTERFACE_DECL()
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     // XContentEventListener
159*cdf0e10cSrcweir     virtual void SAL_CALL contentEvent( const ContentEvent& evt )
160*cdf0e10cSrcweir         throw( RuntimeException );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     // XEventListener ( base of XContentEventListener )
163*cdf0e10cSrcweir     virtual void SAL_CALL disposing( const EventObject& Source )
164*cdf0e10cSrcweir         throw( RuntimeException );
165*cdf0e10cSrcweir };
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir //=========================================================================
168*cdf0e10cSrcweir //=========================================================================
169*cdf0e10cSrcweir //
170*cdf0e10cSrcweir // class Content_Impl.
171*cdf0e10cSrcweir //
172*cdf0e10cSrcweir //=========================================================================
173*cdf0e10cSrcweir //=========================================================================
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir class Content_Impl : public salhelper::SimpleReferenceObject
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir friend class ContentEventListener_Impl;
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir     mutable rtl::OUString               m_aURL;
180*cdf0e10cSrcweir     Reference< XMultiServiceFactory >   m_xSMgr;
181*cdf0e10cSrcweir     Reference< XContent >               m_xContent;
182*cdf0e10cSrcweir     Reference< XCommandProcessor >          m_xCommandProcessor;
183*cdf0e10cSrcweir     Reference< XCommandEnvironment >    m_xEnv;
184*cdf0e10cSrcweir     Reference< XContentEventListener >  m_xContentEventListener;
185*cdf0e10cSrcweir     mutable osl::Mutex                  m_aMutex;
186*cdf0e10cSrcweir     sal_Int32                           m_nCommandId;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir private:
189*cdf0e10cSrcweir     void reinit( const Reference< XContent >& xContent );
190*cdf0e10cSrcweir     void disposing(const EventObject& Source);
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir public:
193*cdf0e10cSrcweir     Content_Impl() : m_nCommandId( 0 ) {};
194*cdf0e10cSrcweir     Content_Impl( const Reference< XMultiServiceFactory >& rSMgr,
195*cdf0e10cSrcweir                   const Reference< XContent >& rContent,
196*cdf0e10cSrcweir                   const Reference< XCommandEnvironment >& rEnv );
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     virtual ~Content_Impl();
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     const rtl::OUString&           getURL() const;
201*cdf0e10cSrcweir     Reference< XContent >          getContent();
202*cdf0e10cSrcweir     Reference< XCommandProcessor > getCommandProcessor();
203*cdf0e10cSrcweir     sal_Int32 getCommandId();
204*cdf0e10cSrcweir     Reference< XMultiServiceFactory > getServiceManager() { return m_xSMgr; }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir     Any  executeCommand( const Command& rCommand );
207*cdf0e10cSrcweir     void abortCommand();
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir     inline const Reference< XCommandEnvironment >& getEnvironment() const;
210*cdf0e10cSrcweir     inline void setEnvironment(
211*cdf0e10cSrcweir                         const Reference< XCommandEnvironment >& xNewEnv );
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     void inserted();
214*cdf0e10cSrcweir };
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir //=========================================================================
217*cdf0e10cSrcweir // Helpers.
218*cdf0e10cSrcweir //=========================================================================
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir static void ensureContentProviderForURL( const ContentBroker & rBroker,
221*cdf0e10cSrcweir                                          const rtl::OUString & rURL )
222*cdf0e10cSrcweir     throw ( ContentCreationException, RuntimeException )
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir     Reference< XContentProviderManager > xMgr
225*cdf0e10cSrcweir         = rBroker.getContentProviderManagerInterface();
226*cdf0e10cSrcweir     if ( !xMgr.is() )
227*cdf0e10cSrcweir     {
228*cdf0e10cSrcweir         throw RuntimeException(
229*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
230*cdf0e10cSrcweir                 "UCB does not implement mandatory interface "
231*cdf0e10cSrcweir                 "XContentProviderManager!" ),
232*cdf0e10cSrcweir             Reference< XInterface >() );
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir     else
235*cdf0e10cSrcweir     {
236*cdf0e10cSrcweir         Reference< XContentProvider > xProv
237*cdf0e10cSrcweir             = xMgr->queryContentProvider( rURL );
238*cdf0e10cSrcweir         if ( !xProv.is() )
239*cdf0e10cSrcweir         {
240*cdf0e10cSrcweir             throw ContentCreationException(
241*cdf0e10cSrcweir                 rtl::OUString::createFromAscii(
242*cdf0e10cSrcweir                     "No Content Provider available for given URL!" ),
243*cdf0e10cSrcweir                 Reference< XInterface >(),
244*cdf0e10cSrcweir                 ContentCreationError_NO_CONTENT_PROVIDER );
245*cdf0e10cSrcweir         }
246*cdf0e10cSrcweir     }
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir //=========================================================================
250*cdf0e10cSrcweir static ContentBroker* getContentBroker( bool bThrow )
251*cdf0e10cSrcweir     throw ( ContentCreationException, RuntimeException )
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     ContentBroker* pBroker = ContentBroker::get();
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir     if ( !pBroker )
256*cdf0e10cSrcweir     {
257*cdf0e10cSrcweir         if ( bThrow )
258*cdf0e10cSrcweir             throw RuntimeException(
259*cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "No Content Broker!" ),
260*cdf0e10cSrcweir                     Reference< XInterface >() );
261*cdf0e10cSrcweir     }
262*cdf0e10cSrcweir     else
263*cdf0e10cSrcweir     {
264*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
265*cdf0e10cSrcweir         Reference< XContentProviderManager > xMgr
266*cdf0e10cSrcweir             = pBroker->getContentProviderManagerInterface();
267*cdf0e10cSrcweir         if ( !xMgr.is() )
268*cdf0e10cSrcweir         {
269*cdf0e10cSrcweir             if ( bThrow )
270*cdf0e10cSrcweir                 throw RuntimeException(
271*cdf0e10cSrcweir                         rtl::OUString::createFromAscii(
272*cdf0e10cSrcweir                             "UCB does not implement mandatory interface "
273*cdf0e10cSrcweir                             "XContentProviderManager!" ),
274*cdf0e10cSrcweir                         Reference< XInterface >() );
275*cdf0e10cSrcweir         }
276*cdf0e10cSrcweir         else
277*cdf0e10cSrcweir         {
278*cdf0e10cSrcweir             OSL_ENSURE( xMgr->queryContentProviders().getLength(),
279*cdf0e10cSrcweir                         "Content Broker not configured (no providers)!" );
280*cdf0e10cSrcweir         }
281*cdf0e10cSrcweir #endif
282*cdf0e10cSrcweir     }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir     return pBroker;
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir //=========================================================================
288*cdf0e10cSrcweir static Reference< XContentIdentifier > getContentIdentifier(
289*cdf0e10cSrcweir                                     const ContentBroker & rBroker,
290*cdf0e10cSrcweir                                     const rtl::OUString & rURL,
291*cdf0e10cSrcweir                                     bool bThrow )
292*cdf0e10cSrcweir     throw ( ContentCreationException, RuntimeException )
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir     Reference< XContentIdentifierFactory > xIdFac
295*cdf0e10cSrcweir                         = rBroker.getContentIdentifierFactoryInterface();
296*cdf0e10cSrcweir     if ( xIdFac.is() )
297*cdf0e10cSrcweir     {
298*cdf0e10cSrcweir         Reference< XContentIdentifier > xId
299*cdf0e10cSrcweir             = xIdFac->createContentIdentifier( rURL );
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir         if ( xId.is() )
302*cdf0e10cSrcweir             return xId;
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir         if ( bThrow )
305*cdf0e10cSrcweir         {
306*cdf0e10cSrcweir             ensureContentProviderForURL( rBroker, rURL );
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir             throw ContentCreationException(
309*cdf0e10cSrcweir                 rtl::OUString::createFromAscii(
310*cdf0e10cSrcweir                     "Unable to create Content Identifier!" ),
311*cdf0e10cSrcweir                 Reference< XInterface >(),
312*cdf0e10cSrcweir                 ContentCreationError_IDENTIFIER_CREATION_FAILED );
313*cdf0e10cSrcweir         }
314*cdf0e10cSrcweir     }
315*cdf0e10cSrcweir     else
316*cdf0e10cSrcweir     {
317*cdf0e10cSrcweir         if ( bThrow )
318*cdf0e10cSrcweir             throw RuntimeException(
319*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
320*cdf0e10cSrcweir                         "UCB does not implement mandatory interface "
321*cdf0e10cSrcweir                         "XContentIdentifierFactory!" ),
322*cdf0e10cSrcweir                     Reference< XInterface >() );
323*cdf0e10cSrcweir     }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir     return Reference< XContentIdentifier >();
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir //=========================================================================
329*cdf0e10cSrcweir static Reference< XContent > getContent(
330*cdf0e10cSrcweir                                     const ContentBroker & rBroker,
331*cdf0e10cSrcweir                                     const Reference< XContentIdentifier > & xId,
332*cdf0e10cSrcweir                                     bool bThrow )
333*cdf0e10cSrcweir     throw ( ContentCreationException, RuntimeException )
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir     Reference< XContentProvider > xProvider
336*cdf0e10cSrcweir         = rBroker.getContentProviderInterface();
337*cdf0e10cSrcweir     if ( xProvider.is() )
338*cdf0e10cSrcweir     {
339*cdf0e10cSrcweir         Reference< XContent > xContent;
340*cdf0e10cSrcweir         rtl::OUString msg;
341*cdf0e10cSrcweir         try
342*cdf0e10cSrcweir         {
343*cdf0e10cSrcweir             xContent = xProvider->queryContent( xId );
344*cdf0e10cSrcweir         }
345*cdf0e10cSrcweir         catch ( IllegalIdentifierException const & e )
346*cdf0e10cSrcweir         {
347*cdf0e10cSrcweir             msg = e.Message;
348*cdf0e10cSrcweir             // handled below.
349*cdf0e10cSrcweir         }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         if ( xContent.is() )
352*cdf0e10cSrcweir             return xContent;
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir         if ( bThrow )
355*cdf0e10cSrcweir         {
356*cdf0e10cSrcweir             ensureContentProviderForURL( rBroker, xId->getContentIdentifier() );
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir             throw ContentCreationException(
359*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
360*cdf0e10cSrcweir                         "Unable to create Content! " ) + msg,
361*cdf0e10cSrcweir                     Reference< XInterface >(),
362*cdf0e10cSrcweir                     ContentCreationError_CONTENT_CREATION_FAILED );
363*cdf0e10cSrcweir         }
364*cdf0e10cSrcweir     }
365*cdf0e10cSrcweir     else
366*cdf0e10cSrcweir     {
367*cdf0e10cSrcweir         if ( bThrow )
368*cdf0e10cSrcweir             throw RuntimeException(
369*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
370*cdf0e10cSrcweir                         "UCB does not implement mandatory interface "
371*cdf0e10cSrcweir                         "XContentProvider!" ),
372*cdf0e10cSrcweir                     Reference< XInterface >() );
373*cdf0e10cSrcweir     }
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir     return Reference< XContent >();
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir //=========================================================================
379*cdf0e10cSrcweir //=========================================================================
380*cdf0e10cSrcweir //
381*cdf0e10cSrcweir // Content Implementation.
382*cdf0e10cSrcweir //
383*cdf0e10cSrcweir //=========================================================================
384*cdf0e10cSrcweir //=========================================================================
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir Content::Content()
387*cdf0e10cSrcweir : m_xImpl( new Content_Impl )
388*cdf0e10cSrcweir {
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir //=========================================================================
392*cdf0e10cSrcweir Content::Content( const rtl::OUString& rURL,
393*cdf0e10cSrcweir                   const Reference< XCommandEnvironment >& rEnv )
394*cdf0e10cSrcweir     throw ( ContentCreationException, RuntimeException )
395*cdf0e10cSrcweir {
396*cdf0e10cSrcweir     ContentBroker* pBroker = getContentBroker( true );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir     Reference< XContentIdentifier > xId
399*cdf0e10cSrcweir         = getContentIdentifier( *pBroker, rURL, true );
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir     Reference< XContent > xContent = getContent( *pBroker, xId, true );
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir     m_xImpl = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir //=========================================================================
407*cdf0e10cSrcweir Content::Content( const Reference< XContentIdentifier >& rId,
408*cdf0e10cSrcweir                   const Reference< XCommandEnvironment >& rEnv )
409*cdf0e10cSrcweir     throw ( ContentCreationException, RuntimeException )
410*cdf0e10cSrcweir {
411*cdf0e10cSrcweir     ContentBroker* pBroker = getContentBroker( true );
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir     Reference< XContent > xContent = getContent( *pBroker, rId, true );
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir     m_xImpl = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir //=========================================================================
419*cdf0e10cSrcweir Content::Content( const Reference< XContent >& rContent,
420*cdf0e10cSrcweir                   const Reference< XCommandEnvironment >& rEnv )
421*cdf0e10cSrcweir     throw ( ContentCreationException, RuntimeException )
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir     ContentBroker* pBroker = getContentBroker( true );
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir     m_xImpl = new Content_Impl( pBroker->getServiceManager(), rContent, rEnv );
426*cdf0e10cSrcweir }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir //=========================================================================
429*cdf0e10cSrcweir Content::Content( const Content& rOther )
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir     m_xImpl = rOther.m_xImpl;
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir //=========================================================================
435*cdf0e10cSrcweir // static
436*cdf0e10cSrcweir sal_Bool Content::create( const rtl::OUString& rURL,
437*cdf0e10cSrcweir                           const Reference< XCommandEnvironment >& rEnv,
438*cdf0e10cSrcweir                           Content& rContent )
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir     ContentBroker* pBroker = getContentBroker( false );
441*cdf0e10cSrcweir     if ( !pBroker )
442*cdf0e10cSrcweir         return sal_False;
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     Reference< XContentIdentifier > xId
445*cdf0e10cSrcweir         = getContentIdentifier( *pBroker, rURL, false );
446*cdf0e10cSrcweir     if ( !xId.is() )
447*cdf0e10cSrcweir         return sal_False;
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir     Reference< XContent > xContent = getContent( *pBroker, xId, false );
450*cdf0e10cSrcweir     if ( !xContent.is() )
451*cdf0e10cSrcweir         return sal_False;
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir     rContent.m_xImpl
454*cdf0e10cSrcweir         = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir     return sal_True;
457*cdf0e10cSrcweir }
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir //=========================================================================
460*cdf0e10cSrcweir // static
461*cdf0e10cSrcweir sal_Bool Content::create( const Reference< XContentIdentifier >& rId,
462*cdf0e10cSrcweir                           const Reference< XCommandEnvironment >& rEnv,
463*cdf0e10cSrcweir                           Content& rContent )
464*cdf0e10cSrcweir {
465*cdf0e10cSrcweir     ContentBroker* pBroker = getContentBroker( false );
466*cdf0e10cSrcweir     if ( !pBroker )
467*cdf0e10cSrcweir         return sal_False;
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir     Reference< XContent > xContent = getContent( *pBroker, rId, false );
470*cdf0e10cSrcweir     if ( !xContent.is() )
471*cdf0e10cSrcweir         return sal_False;
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir     rContent.m_xImpl
474*cdf0e10cSrcweir         = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir     return sal_True;
477*cdf0e10cSrcweir }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir //=========================================================================
480*cdf0e10cSrcweir // static
481*cdf0e10cSrcweir sal_Bool Content::create( const Reference< XContent >& xContent,
482*cdf0e10cSrcweir                           const Reference< XCommandEnvironment >& rEnv,
483*cdf0e10cSrcweir                           Content& rContent )
484*cdf0e10cSrcweir {
485*cdf0e10cSrcweir     ContentBroker* pBroker = getContentBroker( false );
486*cdf0e10cSrcweir     if ( !pBroker )
487*cdf0e10cSrcweir         return sal_False;
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir     rContent.m_xImpl
490*cdf0e10cSrcweir         = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir     return sal_True;
493*cdf0e10cSrcweir }
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir //=========================================================================
496*cdf0e10cSrcweir Content::~Content()
497*cdf0e10cSrcweir {
498*cdf0e10cSrcweir }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir //=========================================================================
501*cdf0e10cSrcweir Content& Content::operator=( const Content& rOther )
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir     m_xImpl = rOther.m_xImpl;
504*cdf0e10cSrcweir     return *this;
505*cdf0e10cSrcweir }
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir //=========================================================================
508*cdf0e10cSrcweir Reference< XContent > Content::get() const
509*cdf0e10cSrcweir {
510*cdf0e10cSrcweir     return m_xImpl->getContent();
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir //=========================================================================
514*cdf0e10cSrcweir const rtl::OUString& Content::getURL() const
515*cdf0e10cSrcweir {
516*cdf0e10cSrcweir     return m_xImpl->getURL();
517*cdf0e10cSrcweir }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir //=========================================================================
520*cdf0e10cSrcweir const Reference< XCommandEnvironment >& Content::getCommandEnvironment() const
521*cdf0e10cSrcweir {
522*cdf0e10cSrcweir     return m_xImpl->getEnvironment();
523*cdf0e10cSrcweir }
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir //=========================================================================
526*cdf0e10cSrcweir void Content::setCommandEnvironment(
527*cdf0e10cSrcweir                         const Reference< XCommandEnvironment >& xNewEnv )
528*cdf0e10cSrcweir {
529*cdf0e10cSrcweir     m_xImpl->setEnvironment( xNewEnv );
530*cdf0e10cSrcweir }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir //=========================================================================
533*cdf0e10cSrcweir Reference< XCommandInfo > Content::getCommands()
534*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
535*cdf0e10cSrcweir {
536*cdf0e10cSrcweir     Command aCommand;
537*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "getCommandInfo" );
538*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
539*cdf0e10cSrcweir     aCommand.Argument = Any();
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir     Any aResult = m_xImpl->executeCommand( aCommand );
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir     Reference< XCommandInfo > xInfo;
544*cdf0e10cSrcweir     aResult >>= xInfo;
545*cdf0e10cSrcweir     return xInfo;
546*cdf0e10cSrcweir }
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir //=========================================================================
549*cdf0e10cSrcweir Reference< XPropertySetInfo > Content::getProperties()
550*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
551*cdf0e10cSrcweir {
552*cdf0e10cSrcweir     Command aCommand;
553*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "getPropertySetInfo" );
554*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
555*cdf0e10cSrcweir     aCommand.Argument = Any();
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir     Any aResult = m_xImpl->executeCommand( aCommand );
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir     Reference< XPropertySetInfo > xInfo;
560*cdf0e10cSrcweir     aResult >>= xInfo;
561*cdf0e10cSrcweir     return xInfo;
562*cdf0e10cSrcweir }
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir //=========================================================================
565*cdf0e10cSrcweir Any Content::getPropertyValue( const rtl::OUString& rPropertyName )
566*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
567*cdf0e10cSrcweir {
568*cdf0e10cSrcweir     Sequence< rtl::OUString > aNames( 1 );
569*cdf0e10cSrcweir     aNames.getArray()[ 0 ] = rPropertyName;
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir     Sequence< Any > aRet = getPropertyValues( aNames );
572*cdf0e10cSrcweir     return aRet.getConstArray()[ 0 ];
573*cdf0e10cSrcweir }
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir //=========================================================================
576*cdf0e10cSrcweir Any Content::getPropertyValue( sal_Int32 nPropertyHandle )
577*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
578*cdf0e10cSrcweir {
579*cdf0e10cSrcweir     Sequence< sal_Int32 > aHandles( 1 );
580*cdf0e10cSrcweir     aHandles.getArray()[ 0 ] = nPropertyHandle;
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir     Sequence< Any > aRet = getPropertyValues( aHandles );
583*cdf0e10cSrcweir     return aRet.getConstArray()[ 0 ];
584*cdf0e10cSrcweir }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir //=========================================================================
587*cdf0e10cSrcweir Any Content::setPropertyValue( const rtl::OUString& rName,
588*cdf0e10cSrcweir                                 const Any& rValue )
589*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
590*cdf0e10cSrcweir {
591*cdf0e10cSrcweir     Sequence< rtl::OUString > aNames( 1 );
592*cdf0e10cSrcweir     aNames.getArray()[ 0 ] = rName;
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     Sequence< Any > aValues( 1 );
595*cdf0e10cSrcweir     aValues.getArray()[ 0 ] = rValue;
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir     Sequence< Any > aErrors = setPropertyValues( aNames, aValues );
598*cdf0e10cSrcweir     return aErrors.getConstArray()[ 0 ];
599*cdf0e10cSrcweir }
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir //=========================================================================
602*cdf0e10cSrcweir Any Content::setPropertyValue( const sal_Int32 nPropertyHandle,
603*cdf0e10cSrcweir                                 const Any& rValue )
604*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
605*cdf0e10cSrcweir {
606*cdf0e10cSrcweir     Sequence< sal_Int32 > aHandles( 1 );
607*cdf0e10cSrcweir     aHandles.getArray()[ 0 ] = nPropertyHandle;
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir     Sequence< Any > aValues( 1 );
610*cdf0e10cSrcweir     aValues.getArray()[ 0 ] = rValue;
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir     Sequence< Any > aErrors = setPropertyValues( aHandles, aValues );
613*cdf0e10cSrcweir     return aErrors.getConstArray()[ 0 ];
614*cdf0e10cSrcweir }
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir //=========================================================================
617*cdf0e10cSrcweir Sequence< Any > Content::getPropertyValues(
618*cdf0e10cSrcweir                             const Sequence< rtl::OUString >& rPropertyNames )
619*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
620*cdf0e10cSrcweir {
621*cdf0e10cSrcweir     Reference< XRow > xRow = getPropertyValuesInterface( rPropertyNames );
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir     sal_Int32 nCount = rPropertyNames.getLength();
624*cdf0e10cSrcweir     Sequence< Any > aValues( nCount );
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir     if ( xRow.is() )
627*cdf0e10cSrcweir     {
628*cdf0e10cSrcweir         Any* pValues = aValues.getArray();
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir         for ( sal_Int32 n = 0; n < nCount; ++n )
631*cdf0e10cSrcweir             pValues[ n ] = xRow->getObject( n + 1, Reference< XNameAccess >() );
632*cdf0e10cSrcweir     }
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir     return aValues;
635*cdf0e10cSrcweir }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir //=========================================================================
638*cdf0e10cSrcweir Sequence< Any > Content::getPropertyValues(
639*cdf0e10cSrcweir                             const Sequence< sal_Int32 >& nPropertyHandles )
640*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
641*cdf0e10cSrcweir {
642*cdf0e10cSrcweir     Reference< XRow > xRow = getPropertyValuesInterface( nPropertyHandles );
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir     sal_Int32 nCount = nPropertyHandles.getLength();
645*cdf0e10cSrcweir     Sequence< Any > aValues( nCount );
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir     if ( xRow.is() )
648*cdf0e10cSrcweir     {
649*cdf0e10cSrcweir         Any* pValues = aValues.getArray();
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir         for ( sal_Int32 n = 0; n < nCount; ++n )
652*cdf0e10cSrcweir             pValues[ n ] = xRow->getObject( n + 1, Reference< XNameAccess >() );
653*cdf0e10cSrcweir     }
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir     return aValues;
656*cdf0e10cSrcweir }
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir //=========================================================================
659*cdf0e10cSrcweir Reference< XRow > Content::getPropertyValuesInterface(
660*cdf0e10cSrcweir                             const Sequence< rtl::OUString >& rPropertyNames )
661*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
662*cdf0e10cSrcweir {
663*cdf0e10cSrcweir     sal_Int32 nCount = rPropertyNames.getLength();
664*cdf0e10cSrcweir     Sequence< Property > aProps( nCount );
665*cdf0e10cSrcweir     Property* pProps = aProps.getArray();
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir     const rtl::OUString* pNames  = rPropertyNames.getConstArray();
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n< nCount; ++n )
670*cdf0e10cSrcweir     {
671*cdf0e10cSrcweir         Property& rProp = pProps[ n ];
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir         rProp.Name       = pNames[ n ];
674*cdf0e10cSrcweir         rProp.Handle     = -1; // n/a
675*cdf0e10cSrcweir //        rProp.Type       =
676*cdf0e10cSrcweir //        rProp.Attributes = ;
677*cdf0e10cSrcweir     }
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir     Command aCommand;
680*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "getPropertyValues" );
681*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
682*cdf0e10cSrcweir     aCommand.Argument <<= aProps;
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir     Any aResult = m_xImpl->executeCommand( aCommand );
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir     Reference< XRow > xRow;
687*cdf0e10cSrcweir     aResult >>= xRow;
688*cdf0e10cSrcweir     return xRow;
689*cdf0e10cSrcweir }
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir //=========================================================================
692*cdf0e10cSrcweir Reference< XRow > Content::getPropertyValuesInterface(
693*cdf0e10cSrcweir                             const Sequence< sal_Int32 >& nPropertyHandles )
694*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
695*cdf0e10cSrcweir {
696*cdf0e10cSrcweir     sal_Int32 nCount = nPropertyHandles.getLength();
697*cdf0e10cSrcweir     Sequence< Property > aProps( nCount );
698*cdf0e10cSrcweir     Property* pProps = aProps.getArray();
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir     const sal_Int32* pHandles  = nPropertyHandles.getConstArray();
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n< nCount; ++n )
703*cdf0e10cSrcweir     {
704*cdf0e10cSrcweir         Property& rProp = pProps[ n ];
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir         rProp.Name       = rtl::OUString(); // n/a
707*cdf0e10cSrcweir         rProp.Handle     = pHandles[ n ];
708*cdf0e10cSrcweir //        rProp.Type       =
709*cdf0e10cSrcweir //        rProp.Attributes = ;
710*cdf0e10cSrcweir     }
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir     Command aCommand;
713*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "getPropertyValues" );
714*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
715*cdf0e10cSrcweir     aCommand.Argument <<= aProps;
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir     Any aResult = m_xImpl->executeCommand( aCommand );
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir     Reference< XRow > xRow;
720*cdf0e10cSrcweir     aResult >>= xRow;
721*cdf0e10cSrcweir     return xRow;
722*cdf0e10cSrcweir }
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir //=========================================================================
725*cdf0e10cSrcweir Sequence< Any > Content::setPropertyValues(
726*cdf0e10cSrcweir                             const Sequence< rtl::OUString >& rPropertyNames,
727*cdf0e10cSrcweir                                 const Sequence< Any >& rValues )
728*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
729*cdf0e10cSrcweir {
730*cdf0e10cSrcweir     if ( rPropertyNames.getLength() != rValues.getLength() )
731*cdf0e10cSrcweir     {
732*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
733*cdf0e10cSrcweir             makeAny( IllegalArgumentException(
734*cdf0e10cSrcweir                         rtl::OUString::createFromAscii(
735*cdf0e10cSrcweir                             "Length of property names sequence and value "
736*cdf0e10cSrcweir                             "sequence are unequal!" ),
737*cdf0e10cSrcweir                         get(),
738*cdf0e10cSrcweir                         -1 ) ),
739*cdf0e10cSrcweir             m_xImpl->getEnvironment() );
740*cdf0e10cSrcweir         // Unreachable
741*cdf0e10cSrcweir     }
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir     sal_Int32 nCount = rValues.getLength();
744*cdf0e10cSrcweir     Sequence< PropertyValue > aProps( nCount );
745*cdf0e10cSrcweir     PropertyValue* pProps = aProps.getArray();
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir     const rtl::OUString* pNames  = rPropertyNames.getConstArray();
748*cdf0e10cSrcweir     const Any* pValues = rValues.getConstArray();
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n< nCount; ++n )
751*cdf0e10cSrcweir     {
752*cdf0e10cSrcweir         PropertyValue& rProp = pProps[ n ];
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir         rProp.Name   = pNames[ n ];
755*cdf0e10cSrcweir         rProp.Handle = -1; // n/a
756*cdf0e10cSrcweir         rProp.Value  = pValues[ n ];
757*cdf0e10cSrcweir //        rProp.State  = ;
758*cdf0e10cSrcweir     }
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir     Command aCommand;
761*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "setPropertyValues" );
762*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
763*cdf0e10cSrcweir     aCommand.Argument <<= aProps;
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir     Any aResult = m_xImpl->executeCommand( aCommand );
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir     Sequence< Any > aErrors;
768*cdf0e10cSrcweir     aResult >>= aErrors;
769*cdf0e10cSrcweir     return aErrors;
770*cdf0e10cSrcweir }
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir //=========================================================================
773*cdf0e10cSrcweir Sequence< Any > Content::setPropertyValues(
774*cdf0e10cSrcweir                             const Sequence< sal_Int32 >& nPropertyHandles,
775*cdf0e10cSrcweir                                 const Sequence< Any >& rValues )
776*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
777*cdf0e10cSrcweir {
778*cdf0e10cSrcweir     if ( nPropertyHandles.getLength() != rValues.getLength() )
779*cdf0e10cSrcweir     {
780*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
781*cdf0e10cSrcweir             makeAny( IllegalArgumentException(
782*cdf0e10cSrcweir                         rtl::OUString::createFromAscii(
783*cdf0e10cSrcweir                             "Length of property handles sequence and value "
784*cdf0e10cSrcweir                             "sequence are unequal!" ),
785*cdf0e10cSrcweir                         get(),
786*cdf0e10cSrcweir                         -1 ) ),
787*cdf0e10cSrcweir             m_xImpl->getEnvironment() );
788*cdf0e10cSrcweir         // Unreachable
789*cdf0e10cSrcweir     }
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir     sal_Int32 nCount = rValues.getLength();
792*cdf0e10cSrcweir     Sequence< PropertyValue > aProps( nCount );
793*cdf0e10cSrcweir     PropertyValue* pProps = aProps.getArray();
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir     const sal_Int32* pHandles = nPropertyHandles.getConstArray();
796*cdf0e10cSrcweir     const Any*       pValues  = rValues.getConstArray();
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n< nCount; ++n )
799*cdf0e10cSrcweir     {
800*cdf0e10cSrcweir         PropertyValue& rProp = pProps[ n ];
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir         rProp.Name   = rtl::OUString(); // n/a
803*cdf0e10cSrcweir         rProp.Handle = pHandles[ n ];
804*cdf0e10cSrcweir         rProp.Value  = pValues[ n ];
805*cdf0e10cSrcweir //        rProp.State  = ;
806*cdf0e10cSrcweir     }
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir     Command aCommand;
809*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "setPropertyValues" );
810*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
811*cdf0e10cSrcweir     aCommand.Argument <<= aProps;
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir     Any aResult = m_xImpl->executeCommand( aCommand );
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir     Sequence< Any > aErrors;
816*cdf0e10cSrcweir     aResult >>= aErrors;
817*cdf0e10cSrcweir     return aErrors;
818*cdf0e10cSrcweir }
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir //=========================================================================
821*cdf0e10cSrcweir Any Content::executeCommand( const rtl::OUString& rCommandName,
822*cdf0e10cSrcweir                              const Any& rCommandArgument )
823*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
824*cdf0e10cSrcweir {
825*cdf0e10cSrcweir     Command aCommand;
826*cdf0e10cSrcweir     aCommand.Name     = rCommandName;
827*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
828*cdf0e10cSrcweir     aCommand.Argument = rCommandArgument;
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir     return m_xImpl->executeCommand( aCommand );
831*cdf0e10cSrcweir }
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir //=========================================================================
834*cdf0e10cSrcweir Any Content::executeCommand( sal_Int32 nCommandHandle,
835*cdf0e10cSrcweir                              const Any& rCommandArgument )
836*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
837*cdf0e10cSrcweir {
838*cdf0e10cSrcweir     Command aCommand;
839*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString(); // n/a
840*cdf0e10cSrcweir     aCommand.Handle   = nCommandHandle;
841*cdf0e10cSrcweir     aCommand.Argument = rCommandArgument;
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir     return m_xImpl->executeCommand( aCommand );
844*cdf0e10cSrcweir }
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir //=========================================================================
847*cdf0e10cSrcweir void Content::abortCommand()
848*cdf0e10cSrcweir {
849*cdf0e10cSrcweir     m_xImpl->abortCommand();
850*cdf0e10cSrcweir }
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir //=========================================================================
853*cdf0e10cSrcweir Any Content::createCursorAny( const Sequence< rtl::OUString >& rPropertyNames,
854*cdf0e10cSrcweir                               ResultSetInclude eMode )
855*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
856*cdf0e10cSrcweir {
857*cdf0e10cSrcweir     sal_Int32 nCount = rPropertyNames.getLength();
858*cdf0e10cSrcweir     Sequence< Property > aProps( nCount );
859*cdf0e10cSrcweir     Property* pProps = aProps.getArray();
860*cdf0e10cSrcweir     const rtl::OUString* pNames = rPropertyNames.getConstArray();
861*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n )
862*cdf0e10cSrcweir     {
863*cdf0e10cSrcweir         Property& rProp = pProps[ n ];
864*cdf0e10cSrcweir         rProp.Name   = pNames[ n ];
865*cdf0e10cSrcweir         rProp.Handle = -1; // n/a
866*cdf0e10cSrcweir     }
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir     OpenCommandArgument2 aArg;
869*cdf0e10cSrcweir     aArg.Mode       = ( eMode == INCLUDE_FOLDERS_ONLY )
870*cdf0e10cSrcweir                         ? OpenMode::FOLDERS
871*cdf0e10cSrcweir                         : ( eMode == INCLUDE_DOCUMENTS_ONLY )
872*cdf0e10cSrcweir                             ? OpenMode::DOCUMENTS : OpenMode::ALL;
873*cdf0e10cSrcweir     aArg.Priority   = 0; // unused
874*cdf0e10cSrcweir     aArg.Sink       = Reference< XInterface >(); // unused
875*cdf0e10cSrcweir     aArg.Properties = aProps;
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir     Command aCommand;
878*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "open" );
879*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
880*cdf0e10cSrcweir     aCommand.Argument <<= aArg;
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir     return m_xImpl->executeCommand( aCommand );
883*cdf0e10cSrcweir }
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir //=========================================================================
886*cdf0e10cSrcweir Any Content::createCursorAny( const Sequence< sal_Int32 >& rPropertyHandles,
887*cdf0e10cSrcweir                               ResultSetInclude eMode )
888*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
889*cdf0e10cSrcweir {
890*cdf0e10cSrcweir     sal_Int32 nCount = rPropertyHandles.getLength();
891*cdf0e10cSrcweir     Sequence< Property > aProps( nCount );
892*cdf0e10cSrcweir     Property* pProps = aProps.getArray();
893*cdf0e10cSrcweir     const sal_Int32* pHandles = rPropertyHandles.getConstArray();
894*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n )
895*cdf0e10cSrcweir     {
896*cdf0e10cSrcweir         Property& rProp = pProps[ n ];
897*cdf0e10cSrcweir         rProp.Name   = rtl::OUString(); // n/a
898*cdf0e10cSrcweir         rProp.Handle = pHandles[ n ];
899*cdf0e10cSrcweir     }
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir     OpenCommandArgument2 aArg;
902*cdf0e10cSrcweir     aArg.Mode       = ( eMode == INCLUDE_FOLDERS_ONLY )
903*cdf0e10cSrcweir                         ? OpenMode::FOLDERS
904*cdf0e10cSrcweir                         : ( eMode == INCLUDE_DOCUMENTS_ONLY )
905*cdf0e10cSrcweir                             ? OpenMode::DOCUMENTS : OpenMode::ALL;
906*cdf0e10cSrcweir     aArg.Priority   = 0; // unused
907*cdf0e10cSrcweir     aArg.Sink       = Reference< XInterface >(); // unused
908*cdf0e10cSrcweir     aArg.Properties = aProps;
909*cdf0e10cSrcweir 
910*cdf0e10cSrcweir     Command aCommand;
911*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "open" );
912*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
913*cdf0e10cSrcweir     aCommand.Argument <<= aArg;
914*cdf0e10cSrcweir 
915*cdf0e10cSrcweir     return m_xImpl->executeCommand( aCommand );
916*cdf0e10cSrcweir }
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir //=========================================================================
919*cdf0e10cSrcweir Reference< XResultSet > Content::createCursor(
920*cdf0e10cSrcweir                             const Sequence< rtl::OUString >& rPropertyNames,
921*cdf0e10cSrcweir                             ResultSetInclude eMode )
922*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
923*cdf0e10cSrcweir {
924*cdf0e10cSrcweir     Any aCursorAny = createCursorAny( rPropertyNames, eMode );
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir     Reference< XDynamicResultSet > xDynSet;
927*cdf0e10cSrcweir     Reference< XResultSet > aResult;
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir     aCursorAny >>= xDynSet;
930*cdf0e10cSrcweir     if ( xDynSet.is() )
931*cdf0e10cSrcweir         aResult = xDynSet->getStaticResultSet();
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir     OSL_ENSURE( aResult.is(), "Content::createCursor - no cursor!" );
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir     if ( !aResult.is() )
936*cdf0e10cSrcweir     {
937*cdf0e10cSrcweir         // Former, the open command directly returned a XResultSet.
938*cdf0e10cSrcweir         aCursorAny >>= aResult;
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir         OSL_ENSURE( !aResult.is(),
941*cdf0e10cSrcweir                     "Content::createCursor - open-Command must "
942*cdf0e10cSrcweir                     "return a Reference< XDynnamicResultSet >!" );
943*cdf0e10cSrcweir     }
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir     return aResult;
946*cdf0e10cSrcweir }
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir //=========================================================================
949*cdf0e10cSrcweir Reference< XResultSet > Content::createCursor(
950*cdf0e10cSrcweir                             const Sequence< sal_Int32 >& rPropertyHandles,
951*cdf0e10cSrcweir                             ResultSetInclude eMode )
952*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
953*cdf0e10cSrcweir {
954*cdf0e10cSrcweir     Any aCursorAny = createCursorAny( rPropertyHandles, eMode );
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir     Reference< XDynamicResultSet > xDynSet;
957*cdf0e10cSrcweir     Reference< XResultSet > aResult;
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir     aCursorAny >>= xDynSet;
960*cdf0e10cSrcweir     if ( xDynSet.is() )
961*cdf0e10cSrcweir         aResult = xDynSet->getStaticResultSet();
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir     OSL_ENSURE( aResult.is(), "Content::createCursor - no cursor!" );
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir     if ( !aResult.is() )
966*cdf0e10cSrcweir     {
967*cdf0e10cSrcweir         // Former, the open command directly returned a XResultSet.
968*cdf0e10cSrcweir         aCursorAny >>= aResult;
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir         OSL_ENSURE( !aResult.is(),
971*cdf0e10cSrcweir                     "Content::createCursor - open-Command must "
972*cdf0e10cSrcweir                     "return a Reference< XDynnamicResultSet >!" );
973*cdf0e10cSrcweir     }
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir     return aResult;
976*cdf0e10cSrcweir }
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir //=========================================================================
979*cdf0e10cSrcweir Reference< XDynamicResultSet > Content::createDynamicCursor(
980*cdf0e10cSrcweir                             const Sequence< rtl::OUString >& rPropertyNames,
981*cdf0e10cSrcweir                             ResultSetInclude eMode )
982*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
983*cdf0e10cSrcweir {
984*cdf0e10cSrcweir     Reference< XDynamicResultSet > aResult;
985*cdf0e10cSrcweir     createCursorAny( rPropertyNames, eMode ) >>= aResult;
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir     OSL_ENSURE( aResult.is(), "Content::createDynamicCursor - no cursor!" );
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir     return aResult;
990*cdf0e10cSrcweir }
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir //=========================================================================
993*cdf0e10cSrcweir Reference< XDynamicResultSet > Content::createDynamicCursor(
994*cdf0e10cSrcweir                             const Sequence< sal_Int32 >& rPropertyHandles,
995*cdf0e10cSrcweir                             ResultSetInclude eMode )
996*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
997*cdf0e10cSrcweir {
998*cdf0e10cSrcweir     Reference< XDynamicResultSet > aResult;
999*cdf0e10cSrcweir     createCursorAny( rPropertyHandles, eMode ) >>= aResult;
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir     OSL_ENSURE( aResult.is(), "Content::createDynamicCursor - no cursor!" );
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir     return aResult;
1004*cdf0e10cSrcweir }
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir //=========================================================================
1007*cdf0e10cSrcweir Reference< XDynamicResultSet > Content::createSortedDynamicCursor(
1008*cdf0e10cSrcweir                             const Sequence< rtl::OUString >& rPropertyNames,
1009*cdf0e10cSrcweir                             const Sequence< NumberedSortingInfo >& rSortInfo,
1010*cdf0e10cSrcweir                             Reference< XAnyCompareFactory > rAnyCompareFactory,
1011*cdf0e10cSrcweir                             ResultSetInclude eMode )
1012*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1013*cdf0e10cSrcweir {
1014*cdf0e10cSrcweir     Reference< XDynamicResultSet > aResult;
1015*cdf0e10cSrcweir     Reference< XDynamicResultSet > aOrigCursor = createDynamicCursor( rPropertyNames, eMode );
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir     if( aOrigCursor.is() )
1018*cdf0e10cSrcweir     {
1019*cdf0e10cSrcweir         Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
1020*cdf0e10cSrcweir 
1021*cdf0e10cSrcweir         if( aServiceManager.is() )
1022*cdf0e10cSrcweir         {
1023*cdf0e10cSrcweir             Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
1024*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii( "com.sun.star.ucb.SortedDynamicResultSetFactory" )),
1025*cdf0e10cSrcweir                                 UNO_QUERY );
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir             aResult = aSortFactory->createSortedDynamicResultSet( aOrigCursor,
1028*cdf0e10cSrcweir                                                               rSortInfo,
1029*cdf0e10cSrcweir                                                               rAnyCompareFactory );
1030*cdf0e10cSrcweir         }
1031*cdf0e10cSrcweir 
1032*cdf0e10cSrcweir         OSL_ENSURE( aResult.is(), "Content::createSortedDynamicCursor - no sorted cursor!\n" );
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir         if( !aResult.is() )
1035*cdf0e10cSrcweir             aResult = aOrigCursor;
1036*cdf0e10cSrcweir     }
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir     return aResult;
1039*cdf0e10cSrcweir }
1040*cdf0e10cSrcweir 
1041*cdf0e10cSrcweir //=========================================================================
1042*cdf0e10cSrcweir Reference< XDynamicResultSet > Content::createSortedDynamicCursor(
1043*cdf0e10cSrcweir                             const Sequence< sal_Int32 >& rPropertyHandles,
1044*cdf0e10cSrcweir                             const Sequence< NumberedSortingInfo >& rSortInfo,
1045*cdf0e10cSrcweir                             Reference< XAnyCompareFactory > rAnyCompareFactory,
1046*cdf0e10cSrcweir                             ResultSetInclude eMode )
1047*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1048*cdf0e10cSrcweir {
1049*cdf0e10cSrcweir     Reference< XDynamicResultSet > aResult;
1050*cdf0e10cSrcweir     Reference< XDynamicResultSet > aOrigCursor = createDynamicCursor( rPropertyHandles, eMode );
1051*cdf0e10cSrcweir 
1052*cdf0e10cSrcweir     if( aOrigCursor.is() )
1053*cdf0e10cSrcweir     {
1054*cdf0e10cSrcweir         Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir         if( aServiceManager.is() )
1057*cdf0e10cSrcweir         {
1058*cdf0e10cSrcweir             Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
1059*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii( "com.sun.star.ucb.SortedDynamicResultSetFactory" )),
1060*cdf0e10cSrcweir                                 UNO_QUERY );
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir             aResult = aSortFactory->createSortedDynamicResultSet( aOrigCursor,
1063*cdf0e10cSrcweir                                                               rSortInfo,
1064*cdf0e10cSrcweir                                                               rAnyCompareFactory );
1065*cdf0e10cSrcweir         }
1066*cdf0e10cSrcweir 
1067*cdf0e10cSrcweir         OSL_ENSURE( aResult.is(), "Content::createSortedDynamicCursor - no sorted cursor!\n" );
1068*cdf0e10cSrcweir 
1069*cdf0e10cSrcweir         if( !aResult.is() )
1070*cdf0e10cSrcweir             aResult = aOrigCursor;
1071*cdf0e10cSrcweir     }
1072*cdf0e10cSrcweir 
1073*cdf0e10cSrcweir     return aResult;
1074*cdf0e10cSrcweir }
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir //=========================================================================
1077*cdf0e10cSrcweir Reference< XResultSet > Content::createSortedCursor(
1078*cdf0e10cSrcweir                             const Sequence< rtl::OUString >& rPropertyNames,
1079*cdf0e10cSrcweir                             const Sequence< NumberedSortingInfo >& rSortInfo,
1080*cdf0e10cSrcweir                             Reference< XAnyCompareFactory > rAnyCompareFactory,
1081*cdf0e10cSrcweir                             ResultSetInclude eMode )
1082*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1083*cdf0e10cSrcweir {
1084*cdf0e10cSrcweir     Reference< XResultSet > aResult;
1085*cdf0e10cSrcweir     Reference< XDynamicResultSet > aDynSet;
1086*cdf0e10cSrcweir 
1087*cdf0e10cSrcweir     Any aCursorAny = createCursorAny( rPropertyNames, eMode );
1088*cdf0e10cSrcweir 
1089*cdf0e10cSrcweir     aCursorAny >>= aDynSet;
1090*cdf0e10cSrcweir 
1091*cdf0e10cSrcweir     if( aDynSet.is() )
1092*cdf0e10cSrcweir     {
1093*cdf0e10cSrcweir         Reference< XDynamicResultSet > aDynResult;
1094*cdf0e10cSrcweir         Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir         if( aServiceManager.is() )
1097*cdf0e10cSrcweir         {
1098*cdf0e10cSrcweir             Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
1099*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii( "com.sun.star.ucb.SortedDynamicResultSetFactory" )),
1100*cdf0e10cSrcweir                                 UNO_QUERY );
1101*cdf0e10cSrcweir 
1102*cdf0e10cSrcweir             aDynResult = aSortFactory->createSortedDynamicResultSet( aDynSet,
1103*cdf0e10cSrcweir                                                               rSortInfo,
1104*cdf0e10cSrcweir                                                               rAnyCompareFactory );
1105*cdf0e10cSrcweir         }
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir         OSL_ENSURE( aDynResult.is(), "Content::createSortedCursor - no sorted cursor!\n" );
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir         if( aDynResult.is() )
1110*cdf0e10cSrcweir             aResult = aDynResult->getStaticResultSet();
1111*cdf0e10cSrcweir         else
1112*cdf0e10cSrcweir             aResult = aDynSet->getStaticResultSet();
1113*cdf0e10cSrcweir     }
1114*cdf0e10cSrcweir 
1115*cdf0e10cSrcweir     OSL_ENSURE( aResult.is(), "Content::createSortedCursor - no cursor!" );
1116*cdf0e10cSrcweir 
1117*cdf0e10cSrcweir     if ( !aResult.is() )
1118*cdf0e10cSrcweir     {
1119*cdf0e10cSrcweir         // Former, the open command directly returned a XResultSet.
1120*cdf0e10cSrcweir         aCursorAny >>= aResult;
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir         OSL_ENSURE( !aResult.is(),
1123*cdf0e10cSrcweir                     "Content::createCursor - open-Command must "
1124*cdf0e10cSrcweir                     "return a Reference< XDynnamicResultSet >!" );
1125*cdf0e10cSrcweir     }
1126*cdf0e10cSrcweir 
1127*cdf0e10cSrcweir     return aResult;
1128*cdf0e10cSrcweir }
1129*cdf0e10cSrcweir 
1130*cdf0e10cSrcweir //=========================================================================
1131*cdf0e10cSrcweir Reference< XResultSet > Content::createSortedCursor(
1132*cdf0e10cSrcweir                             const Sequence< sal_Int32 >& rPropertyHandles,
1133*cdf0e10cSrcweir                             const Sequence< NumberedSortingInfo >& rSortInfo,
1134*cdf0e10cSrcweir                             Reference< XAnyCompareFactory > rAnyCompareFactory,
1135*cdf0e10cSrcweir                             ResultSetInclude eMode )
1136*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1137*cdf0e10cSrcweir {
1138*cdf0e10cSrcweir     Reference< XResultSet > aResult;
1139*cdf0e10cSrcweir     Reference< XDynamicResultSet > aDynSet;
1140*cdf0e10cSrcweir 
1141*cdf0e10cSrcweir     Any aCursorAny = createCursorAny( rPropertyHandles, eMode );
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir     aCursorAny >>= aDynSet;
1144*cdf0e10cSrcweir 
1145*cdf0e10cSrcweir     if( aDynSet.is() )
1146*cdf0e10cSrcweir     {
1147*cdf0e10cSrcweir         Reference< XDynamicResultSet > aDynResult;
1148*cdf0e10cSrcweir         Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir         if( aServiceManager.is() )
1151*cdf0e10cSrcweir         {
1152*cdf0e10cSrcweir             Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
1153*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii( "com.sun.star.ucb.SortedDynamicResultSetFactory" )),
1154*cdf0e10cSrcweir                                 UNO_QUERY );
1155*cdf0e10cSrcweir 
1156*cdf0e10cSrcweir             aDynResult = aSortFactory->createSortedDynamicResultSet( aDynSet,
1157*cdf0e10cSrcweir                                                               rSortInfo,
1158*cdf0e10cSrcweir                                                               rAnyCompareFactory );
1159*cdf0e10cSrcweir         }
1160*cdf0e10cSrcweir 
1161*cdf0e10cSrcweir         OSL_ENSURE( aDynResult.is(), "Content::createSortedCursor - no sorted cursor!\n" );
1162*cdf0e10cSrcweir 
1163*cdf0e10cSrcweir         if( aDynResult.is() )
1164*cdf0e10cSrcweir             aResult = aDynResult->getStaticResultSet();
1165*cdf0e10cSrcweir         else
1166*cdf0e10cSrcweir             aResult = aDynSet->getStaticResultSet();
1167*cdf0e10cSrcweir     }
1168*cdf0e10cSrcweir 
1169*cdf0e10cSrcweir     OSL_ENSURE( aResult.is(), "Content::createSortedCursor - no cursor!" );
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir     if ( !aResult.is() )
1172*cdf0e10cSrcweir     {
1173*cdf0e10cSrcweir         // Former, the open command directly returned a XResultSet.
1174*cdf0e10cSrcweir         aCursorAny >>= aResult;
1175*cdf0e10cSrcweir 
1176*cdf0e10cSrcweir         OSL_ENSURE( !aResult.is(),
1177*cdf0e10cSrcweir                     "Content::createCursor - open-Command must "
1178*cdf0e10cSrcweir                     "return a Reference< XDynnamicResultSet >!" );
1179*cdf0e10cSrcweir     }
1180*cdf0e10cSrcweir 
1181*cdf0e10cSrcweir     return aResult;
1182*cdf0e10cSrcweir }
1183*cdf0e10cSrcweir 
1184*cdf0e10cSrcweir //=========================================================================
1185*cdf0e10cSrcweir Reference< XInputStream > Content::openStream()
1186*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1187*cdf0e10cSrcweir {
1188*cdf0e10cSrcweir     if ( !isDocument() )
1189*cdf0e10cSrcweir         return Reference< XInputStream >();
1190*cdf0e10cSrcweir 
1191*cdf0e10cSrcweir     Reference< XActiveDataSink > xSink = new ActiveDataSink;
1192*cdf0e10cSrcweir 
1193*cdf0e10cSrcweir     OpenCommandArgument2 aArg;
1194*cdf0e10cSrcweir     aArg.Mode       = OpenMode::DOCUMENT;
1195*cdf0e10cSrcweir     aArg.Priority   = 0; // unused
1196*cdf0e10cSrcweir     aArg.Sink       = xSink;
1197*cdf0e10cSrcweir     aArg.Properties = Sequence< Property >( 0 ); // unused
1198*cdf0e10cSrcweir 
1199*cdf0e10cSrcweir     Command aCommand;
1200*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "open" );
1201*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1202*cdf0e10cSrcweir     aCommand.Argument <<= aArg;
1203*cdf0e10cSrcweir 
1204*cdf0e10cSrcweir     m_xImpl->executeCommand( aCommand );
1205*cdf0e10cSrcweir 
1206*cdf0e10cSrcweir     return xSink->getInputStream();
1207*cdf0e10cSrcweir }
1208*cdf0e10cSrcweir 
1209*cdf0e10cSrcweir //=========================================================================
1210*cdf0e10cSrcweir Reference< XInputStream > Content::openStreamNoLock()
1211*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1212*cdf0e10cSrcweir {
1213*cdf0e10cSrcweir     if ( !isDocument() )
1214*cdf0e10cSrcweir         return Reference< XInputStream >();
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir     Reference< XActiveDataSink > xSink = new ActiveDataSink;
1217*cdf0e10cSrcweir 
1218*cdf0e10cSrcweir     OpenCommandArgument2 aArg;
1219*cdf0e10cSrcweir     aArg.Mode       = OpenMode::DOCUMENT_SHARE_DENY_NONE;
1220*cdf0e10cSrcweir     aArg.Priority   = 0; // unused
1221*cdf0e10cSrcweir     aArg.Sink       = xSink;
1222*cdf0e10cSrcweir     aArg.Properties = Sequence< Property >( 0 ); // unused
1223*cdf0e10cSrcweir 
1224*cdf0e10cSrcweir     Command aCommand;
1225*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "open" );
1226*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1227*cdf0e10cSrcweir     aCommand.Argument <<= aArg;
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir     m_xImpl->executeCommand( aCommand );
1230*cdf0e10cSrcweir 
1231*cdf0e10cSrcweir     return xSink->getInputStream();
1232*cdf0e10cSrcweir }
1233*cdf0e10cSrcweir 
1234*cdf0e10cSrcweir //=========================================================================
1235*cdf0e10cSrcweir Reference< XStream > Content::openWriteableStream()
1236*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1237*cdf0e10cSrcweir {
1238*cdf0e10cSrcweir     if ( !isDocument() )
1239*cdf0e10cSrcweir         return Reference< XStream >();
1240*cdf0e10cSrcweir 
1241*cdf0e10cSrcweir     Reference< XActiveDataStreamer > xStreamer = new ActiveDataStreamer;
1242*cdf0e10cSrcweir 
1243*cdf0e10cSrcweir     OpenCommandArgument2 aArg;
1244*cdf0e10cSrcweir     aArg.Mode       = OpenMode::DOCUMENT;
1245*cdf0e10cSrcweir     aArg.Priority   = 0; // unused
1246*cdf0e10cSrcweir     aArg.Sink       = xStreamer;
1247*cdf0e10cSrcweir     aArg.Properties = Sequence< Property >( 0 ); // unused
1248*cdf0e10cSrcweir 
1249*cdf0e10cSrcweir     Command aCommand;
1250*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "open" );
1251*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1252*cdf0e10cSrcweir     aCommand.Argument <<= aArg;
1253*cdf0e10cSrcweir 
1254*cdf0e10cSrcweir     m_xImpl->executeCommand( aCommand );
1255*cdf0e10cSrcweir 
1256*cdf0e10cSrcweir     return xStreamer->getStream();
1257*cdf0e10cSrcweir }
1258*cdf0e10cSrcweir 
1259*cdf0e10cSrcweir //=========================================================================
1260*cdf0e10cSrcweir Reference< XStream > Content::openWriteableStreamNoLock()
1261*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1262*cdf0e10cSrcweir {
1263*cdf0e10cSrcweir     if ( !isDocument() )
1264*cdf0e10cSrcweir         return Reference< XStream >();
1265*cdf0e10cSrcweir 
1266*cdf0e10cSrcweir     Reference< XActiveDataStreamer > xStreamer = new ActiveDataStreamer;
1267*cdf0e10cSrcweir 
1268*cdf0e10cSrcweir     OpenCommandArgument2 aArg;
1269*cdf0e10cSrcweir     aArg.Mode       = OpenMode::DOCUMENT_SHARE_DENY_NONE;
1270*cdf0e10cSrcweir     aArg.Priority   = 0; // unused
1271*cdf0e10cSrcweir     aArg.Sink       = xStreamer;
1272*cdf0e10cSrcweir     aArg.Properties = Sequence< Property >( 0 ); // unused
1273*cdf0e10cSrcweir 
1274*cdf0e10cSrcweir     Command aCommand;
1275*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "open" );
1276*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1277*cdf0e10cSrcweir     aCommand.Argument <<= aArg;
1278*cdf0e10cSrcweir 
1279*cdf0e10cSrcweir     m_xImpl->executeCommand( aCommand );
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir     return xStreamer->getStream();
1282*cdf0e10cSrcweir }
1283*cdf0e10cSrcweir 
1284*cdf0e10cSrcweir //=========================================================================
1285*cdf0e10cSrcweir sal_Bool Content::openStream( const Reference< XActiveDataSink >& rSink )
1286*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1287*cdf0e10cSrcweir {
1288*cdf0e10cSrcweir     if ( !isDocument() )
1289*cdf0e10cSrcweir         return sal_False;
1290*cdf0e10cSrcweir 
1291*cdf0e10cSrcweir     OpenCommandArgument2 aArg;
1292*cdf0e10cSrcweir     aArg.Mode       = OpenMode::DOCUMENT;
1293*cdf0e10cSrcweir     aArg.Priority   = 0; // unused
1294*cdf0e10cSrcweir     aArg.Sink       = rSink;
1295*cdf0e10cSrcweir     aArg.Properties = Sequence< Property >( 0 ); // unused
1296*cdf0e10cSrcweir 
1297*cdf0e10cSrcweir     Command aCommand;
1298*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "open" );
1299*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1300*cdf0e10cSrcweir     aCommand.Argument <<= aArg;
1301*cdf0e10cSrcweir 
1302*cdf0e10cSrcweir     m_xImpl->executeCommand( aCommand );
1303*cdf0e10cSrcweir 
1304*cdf0e10cSrcweir     return sal_True;
1305*cdf0e10cSrcweir }
1306*cdf0e10cSrcweir 
1307*cdf0e10cSrcweir //=========================================================================
1308*cdf0e10cSrcweir sal_Bool Content::openStream( const Reference< XOutputStream >& rStream )
1309*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1310*cdf0e10cSrcweir {
1311*cdf0e10cSrcweir     if ( !isDocument() )
1312*cdf0e10cSrcweir         return sal_False;
1313*cdf0e10cSrcweir 
1314*cdf0e10cSrcweir     OpenCommandArgument2 aArg;
1315*cdf0e10cSrcweir     aArg.Mode       = OpenMode::DOCUMENT;
1316*cdf0e10cSrcweir     aArg.Priority   = 0; // unused
1317*cdf0e10cSrcweir     aArg.Sink       = rStream;
1318*cdf0e10cSrcweir     aArg.Properties = Sequence< Property >( 0 ); // unused
1319*cdf0e10cSrcweir 
1320*cdf0e10cSrcweir     Command aCommand;
1321*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "open" );
1322*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1323*cdf0e10cSrcweir     aCommand.Argument <<= aArg;
1324*cdf0e10cSrcweir 
1325*cdf0e10cSrcweir     m_xImpl->executeCommand( aCommand );
1326*cdf0e10cSrcweir 
1327*cdf0e10cSrcweir     return sal_True;
1328*cdf0e10cSrcweir }
1329*cdf0e10cSrcweir 
1330*cdf0e10cSrcweir //=========================================================================
1331*cdf0e10cSrcweir void Content::writeStream( const Reference< XInputStream >& rStream,
1332*cdf0e10cSrcweir                            sal_Bool bReplaceExisting )
1333*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1334*cdf0e10cSrcweir {
1335*cdf0e10cSrcweir     InsertCommandArgument aArg;
1336*cdf0e10cSrcweir     aArg.Data            = rStream.is() ? rStream : new EmptyInputStream;
1337*cdf0e10cSrcweir     aArg.ReplaceExisting = bReplaceExisting;
1338*cdf0e10cSrcweir 
1339*cdf0e10cSrcweir     Command aCommand;
1340*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "insert" );
1341*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1342*cdf0e10cSrcweir     aCommand.Argument <<= aArg;
1343*cdf0e10cSrcweir 
1344*cdf0e10cSrcweir     m_xImpl->executeCommand( aCommand );
1345*cdf0e10cSrcweir 
1346*cdf0e10cSrcweir     m_xImpl->inserted();
1347*cdf0e10cSrcweir }
1348*cdf0e10cSrcweir 
1349*cdf0e10cSrcweir //=========================================================================
1350*cdf0e10cSrcweir Sequence< ContentInfo > Content::queryCreatableContentsInfo()
1351*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1352*cdf0e10cSrcweir {
1353*cdf0e10cSrcweir     // First, try it using "CreatableContentsInfo" property -> the "new" way.
1354*cdf0e10cSrcweir     Sequence< ContentInfo > aInfo;
1355*cdf0e10cSrcweir     if ( getPropertyValue(
1356*cdf0e10cSrcweir              rtl::OUString::createFromAscii( "CreatableContentsInfo" ) )
1357*cdf0e10cSrcweir          >>= aInfo )
1358*cdf0e10cSrcweir         return aInfo;
1359*cdf0e10cSrcweir 
1360*cdf0e10cSrcweir     // Second, try it using XContentCreator interface -> the "old" way (not
1361*cdf0e10cSrcweir     // providing the chance to supply an XCommandEnvironment.
1362*cdf0e10cSrcweir     Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY );
1363*cdf0e10cSrcweir     if ( xCreator.is() )
1364*cdf0e10cSrcweir         aInfo = xCreator->queryCreatableContentsInfo();
1365*cdf0e10cSrcweir 
1366*cdf0e10cSrcweir     return aInfo;
1367*cdf0e10cSrcweir }
1368*cdf0e10cSrcweir 
1369*cdf0e10cSrcweir //=========================================================================
1370*cdf0e10cSrcweir sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
1371*cdf0e10cSrcweir                                     const Sequence< rtl::OUString >&
1372*cdf0e10cSrcweir                                         rPropertyNames,
1373*cdf0e10cSrcweir                                     const Sequence< Any >& rPropertyValues,
1374*cdf0e10cSrcweir                                     Content& rNewContent )
1375*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1376*cdf0e10cSrcweir {
1377*cdf0e10cSrcweir     return insertNewContent( rContentType,
1378*cdf0e10cSrcweir                              rPropertyNames,
1379*cdf0e10cSrcweir                              rPropertyValues,
1380*cdf0e10cSrcweir                              new EmptyInputStream,
1381*cdf0e10cSrcweir                              rNewContent );
1382*cdf0e10cSrcweir }
1383*cdf0e10cSrcweir 
1384*cdf0e10cSrcweir //=========================================================================
1385*cdf0e10cSrcweir sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
1386*cdf0e10cSrcweir                                     const Sequence< sal_Int32 >&
1387*cdf0e10cSrcweir                                         nPropertyHandles,
1388*cdf0e10cSrcweir                                     const Sequence< Any >& rPropertyValues,
1389*cdf0e10cSrcweir                                     Content& rNewContent )
1390*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1391*cdf0e10cSrcweir {
1392*cdf0e10cSrcweir     return insertNewContent( rContentType,
1393*cdf0e10cSrcweir                              nPropertyHandles,
1394*cdf0e10cSrcweir                              rPropertyValues,
1395*cdf0e10cSrcweir                              new EmptyInputStream,
1396*cdf0e10cSrcweir                              rNewContent );
1397*cdf0e10cSrcweir }
1398*cdf0e10cSrcweir 
1399*cdf0e10cSrcweir //=========================================================================
1400*cdf0e10cSrcweir sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
1401*cdf0e10cSrcweir                                     const Sequence< rtl::OUString >&
1402*cdf0e10cSrcweir                                         rPropertyNames,
1403*cdf0e10cSrcweir                                     const Sequence< Any >& rPropertyValues,
1404*cdf0e10cSrcweir                                     const Reference< XInputStream >& rData,
1405*cdf0e10cSrcweir                                     Content& rNewContent )
1406*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1407*cdf0e10cSrcweir {
1408*cdf0e10cSrcweir     if ( rContentType.getLength() == 0 )
1409*cdf0e10cSrcweir         return sal_False;
1410*cdf0e10cSrcweir 
1411*cdf0e10cSrcweir     // First, try it using "createNewContent" command -> the "new" way.
1412*cdf0e10cSrcweir     ContentInfo aInfo;
1413*cdf0e10cSrcweir     aInfo.Type = rContentType;
1414*cdf0e10cSrcweir     aInfo.Attributes = 0;
1415*cdf0e10cSrcweir 
1416*cdf0e10cSrcweir     Command aCommand;
1417*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "createNewContent" );
1418*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1419*cdf0e10cSrcweir     aCommand.Argument <<= aInfo;
1420*cdf0e10cSrcweir 
1421*cdf0e10cSrcweir     Reference< XContent > xNew;
1422*cdf0e10cSrcweir     try
1423*cdf0e10cSrcweir     {
1424*cdf0e10cSrcweir         m_xImpl->executeCommand( aCommand ) >>= xNew;
1425*cdf0e10cSrcweir     }
1426*cdf0e10cSrcweir     catch ( RuntimeException const & )
1427*cdf0e10cSrcweir     {
1428*cdf0e10cSrcweir         throw;
1429*cdf0e10cSrcweir     }
1430*cdf0e10cSrcweir     catch ( Exception const & )
1431*cdf0e10cSrcweir     {
1432*cdf0e10cSrcweir     }
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir     if ( !xNew.is() )
1435*cdf0e10cSrcweir     {
1436*cdf0e10cSrcweir         // Second, try it using XContentCreator interface -> the "old"
1437*cdf0e10cSrcweir         // way (not providing the chance to supply an XCommandEnvironment.
1438*cdf0e10cSrcweir         Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY );
1439*cdf0e10cSrcweir 
1440*cdf0e10cSrcweir         if ( !xCreator.is() )
1441*cdf0e10cSrcweir             return sal_False;
1442*cdf0e10cSrcweir 
1443*cdf0e10cSrcweir         xNew = xCreator->createNewContent( aInfo );
1444*cdf0e10cSrcweir 
1445*cdf0e10cSrcweir         if ( !xNew.is() )
1446*cdf0e10cSrcweir             return sal_False;
1447*cdf0e10cSrcweir     }
1448*cdf0e10cSrcweir 
1449*cdf0e10cSrcweir     Content aNewContent( xNew, m_xImpl->getEnvironment() );
1450*cdf0e10cSrcweir     aNewContent.setPropertyValues( rPropertyNames, rPropertyValues );
1451*cdf0e10cSrcweir     aNewContent.executeCommand( rtl::OUString::createFromAscii( "insert" ),
1452*cdf0e10cSrcweir                                 makeAny(
1453*cdf0e10cSrcweir                                     InsertCommandArgument(
1454*cdf0e10cSrcweir                                         rData.is() ? rData : new EmptyInputStream,
1455*cdf0e10cSrcweir                                         sal_False /* ReplaceExisting */ ) ) );
1456*cdf0e10cSrcweir     aNewContent.m_xImpl->inserted();
1457*cdf0e10cSrcweir 
1458*cdf0e10cSrcweir     rNewContent = aNewContent;
1459*cdf0e10cSrcweir     return sal_True;
1460*cdf0e10cSrcweir }
1461*cdf0e10cSrcweir 
1462*cdf0e10cSrcweir //=========================================================================
1463*cdf0e10cSrcweir sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
1464*cdf0e10cSrcweir                                     const Sequence< sal_Int32 >&
1465*cdf0e10cSrcweir                                         nPropertyHandles,
1466*cdf0e10cSrcweir                                     const Sequence< Any >& rPropertyValues,
1467*cdf0e10cSrcweir                                     const Reference< XInputStream >& rData,
1468*cdf0e10cSrcweir                                     Content& rNewContent )
1469*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1470*cdf0e10cSrcweir {
1471*cdf0e10cSrcweir     if ( rContentType.getLength() == 0 )
1472*cdf0e10cSrcweir         return sal_False;
1473*cdf0e10cSrcweir 
1474*cdf0e10cSrcweir     // First, try it using "createNewContent" command -> the "new" way.
1475*cdf0e10cSrcweir     ContentInfo aInfo;
1476*cdf0e10cSrcweir     aInfo.Type = rContentType;
1477*cdf0e10cSrcweir     aInfo.Attributes = 0;
1478*cdf0e10cSrcweir 
1479*cdf0e10cSrcweir     Command aCommand;
1480*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "createNewContent" );
1481*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1482*cdf0e10cSrcweir     aCommand.Argument <<= aInfo;
1483*cdf0e10cSrcweir 
1484*cdf0e10cSrcweir     Reference< XContent > xNew;
1485*cdf0e10cSrcweir     try
1486*cdf0e10cSrcweir     {
1487*cdf0e10cSrcweir         m_xImpl->executeCommand( aCommand ) >>= xNew;
1488*cdf0e10cSrcweir     }
1489*cdf0e10cSrcweir     catch ( RuntimeException const & )
1490*cdf0e10cSrcweir     {
1491*cdf0e10cSrcweir         throw;
1492*cdf0e10cSrcweir     }
1493*cdf0e10cSrcweir     catch ( Exception const & )
1494*cdf0e10cSrcweir     {
1495*cdf0e10cSrcweir     }
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir     if ( !xNew.is() )
1498*cdf0e10cSrcweir     {
1499*cdf0e10cSrcweir         // Second, try it using XContentCreator interface -> the "old"
1500*cdf0e10cSrcweir         // way (not providing the chance to supply an XCommandEnvironment.
1501*cdf0e10cSrcweir         Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY );
1502*cdf0e10cSrcweir 
1503*cdf0e10cSrcweir         if ( !xCreator.is() )
1504*cdf0e10cSrcweir             return sal_False;
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir         xNew = xCreator->createNewContent( aInfo );
1507*cdf0e10cSrcweir 
1508*cdf0e10cSrcweir         if ( !xNew.is() )
1509*cdf0e10cSrcweir             return sal_False;
1510*cdf0e10cSrcweir     }
1511*cdf0e10cSrcweir 
1512*cdf0e10cSrcweir     Content aNewContent( xNew, m_xImpl->getEnvironment() );
1513*cdf0e10cSrcweir     aNewContent.setPropertyValues( nPropertyHandles, rPropertyValues );
1514*cdf0e10cSrcweir     aNewContent.executeCommand( rtl::OUString::createFromAscii( "insert" ),
1515*cdf0e10cSrcweir                                 makeAny(
1516*cdf0e10cSrcweir                                     InsertCommandArgument(
1517*cdf0e10cSrcweir                                         rData.is() ? rData : new EmptyInputStream,
1518*cdf0e10cSrcweir                                         sal_False /* ReplaceExisting */ ) ) );
1519*cdf0e10cSrcweir     aNewContent.m_xImpl->inserted();
1520*cdf0e10cSrcweir 
1521*cdf0e10cSrcweir     rNewContent = aNewContent;
1522*cdf0e10cSrcweir     return sal_True;
1523*cdf0e10cSrcweir }
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir //=========================================================================
1526*cdf0e10cSrcweir sal_Bool Content::transferContent( const Content& rSourceContent,
1527*cdf0e10cSrcweir                                    InsertOperation eOperation,
1528*cdf0e10cSrcweir                                    const rtl::OUString & rTitle,
1529*cdf0e10cSrcweir                                    const sal_Int32 nNameClashAction )
1530*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1531*cdf0e10cSrcweir {
1532*cdf0e10cSrcweir     ContentBroker* pBroker = ContentBroker::get();
1533*cdf0e10cSrcweir     if ( !pBroker )
1534*cdf0e10cSrcweir     {
1535*cdf0e10cSrcweir         OSL_ENSURE( sal_False,
1536*cdf0e10cSrcweir                     "Content::transferContent - No Content Broker!" );
1537*cdf0e10cSrcweir         return sal_False;
1538*cdf0e10cSrcweir     }
1539*cdf0e10cSrcweir 
1540*cdf0e10cSrcweir     Reference< XCommandProcessor > xCmdProc(
1541*cdf0e10cSrcweir                                     pBroker->getCommandProcessorInterface() );
1542*cdf0e10cSrcweir     if ( !xCmdProc.is() )
1543*cdf0e10cSrcweir     {
1544*cdf0e10cSrcweir         OSL_ENSURE( sal_False,
1545*cdf0e10cSrcweir                     "Content::transferContent - No XCommandProcessor!" );
1546*cdf0e10cSrcweir         return sal_False;
1547*cdf0e10cSrcweir     }
1548*cdf0e10cSrcweir 
1549*cdf0e10cSrcweir     // Execute command "globalTransfer" at UCB.
1550*cdf0e10cSrcweir 
1551*cdf0e10cSrcweir     TransferCommandOperation eTransOp = TransferCommandOperation();
1552*cdf0e10cSrcweir     switch ( eOperation )
1553*cdf0e10cSrcweir     {
1554*cdf0e10cSrcweir         case InsertOperation_COPY:
1555*cdf0e10cSrcweir             eTransOp = TransferCommandOperation_COPY;
1556*cdf0e10cSrcweir             break;
1557*cdf0e10cSrcweir 
1558*cdf0e10cSrcweir         case InsertOperation_MOVE:
1559*cdf0e10cSrcweir             eTransOp = TransferCommandOperation_MOVE;
1560*cdf0e10cSrcweir             break;
1561*cdf0e10cSrcweir 
1562*cdf0e10cSrcweir         case InsertOperation_LINK:
1563*cdf0e10cSrcweir             eTransOp = TransferCommandOperation_LINK;
1564*cdf0e10cSrcweir             break;
1565*cdf0e10cSrcweir 
1566*cdf0e10cSrcweir         default:
1567*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
1568*cdf0e10cSrcweir                 makeAny( IllegalArgumentException(
1569*cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1570*cdf0e10cSrcweir                                 "Unknown transfer operation!" ),
1571*cdf0e10cSrcweir                             get(),
1572*cdf0e10cSrcweir                             -1 ) ),
1573*cdf0e10cSrcweir                          m_xImpl->getEnvironment() );
1574*cdf0e10cSrcweir             // Unreachable
1575*cdf0e10cSrcweir     }
1576*cdf0e10cSrcweir 
1577*cdf0e10cSrcweir     GlobalTransferCommandArgument aTransferArg(
1578*cdf0e10cSrcweir                                         eTransOp,
1579*cdf0e10cSrcweir                                         rSourceContent.getURL(), // SourceURL
1580*cdf0e10cSrcweir                                         getURL(),   // TargetFolderURL,
1581*cdf0e10cSrcweir                                         rTitle,
1582*cdf0e10cSrcweir                                         nNameClashAction );
1583*cdf0e10cSrcweir     Command aCommand;
1584*cdf0e10cSrcweir     aCommand.Name     = rtl::OUString::createFromAscii( "globalTransfer" );
1585*cdf0e10cSrcweir     aCommand.Handle   = -1; // n/a
1586*cdf0e10cSrcweir     aCommand.Argument <<= aTransferArg;
1587*cdf0e10cSrcweir 
1588*cdf0e10cSrcweir     xCmdProc->execute( aCommand, 0, m_xImpl->getEnvironment() );
1589*cdf0e10cSrcweir     return sal_True;
1590*cdf0e10cSrcweir }
1591*cdf0e10cSrcweir 
1592*cdf0e10cSrcweir //=========================================================================
1593*cdf0e10cSrcweir sal_Bool Content::isFolder()
1594*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1595*cdf0e10cSrcweir {
1596*cdf0e10cSrcweir     sal_Bool bFolder = sal_False;
1597*cdf0e10cSrcweir     if ( getPropertyValue( rtl::OUString::createFromAscii( "IsFolder" ) )
1598*cdf0e10cSrcweir         >>= bFolder )
1599*cdf0e10cSrcweir         return bFolder;
1600*cdf0e10cSrcweir 
1601*cdf0e10cSrcweir      ucbhelper::cancelCommandExecution(
1602*cdf0e10cSrcweir          makeAny( UnknownPropertyException(
1603*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
1604*cdf0e10cSrcweir                         "Unable to retreive value of property 'IsFolder'!" ),
1605*cdf0e10cSrcweir                     get() ) ),
1606*cdf0e10cSrcweir          m_xImpl->getEnvironment() );
1607*cdf0e10cSrcweir 
1608*cdf0e10cSrcweir     // Unreachable - cancelCommandExecution always throws an exception.
1609*cdf0e10cSrcweir     // But some compilers complain...
1610*cdf0e10cSrcweir     return sal_False;
1611*cdf0e10cSrcweir }
1612*cdf0e10cSrcweir 
1613*cdf0e10cSrcweir //=========================================================================
1614*cdf0e10cSrcweir sal_Bool Content::isDocument()
1615*cdf0e10cSrcweir     throw( CommandAbortedException, RuntimeException, Exception )
1616*cdf0e10cSrcweir {
1617*cdf0e10cSrcweir     sal_Bool bDoc = sal_False;
1618*cdf0e10cSrcweir     if ( getPropertyValue( rtl::OUString::createFromAscii( "IsDocument" ) )
1619*cdf0e10cSrcweir         >>= bDoc )
1620*cdf0e10cSrcweir         return bDoc;
1621*cdf0e10cSrcweir 
1622*cdf0e10cSrcweir      ucbhelper::cancelCommandExecution(
1623*cdf0e10cSrcweir          makeAny( UnknownPropertyException(
1624*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
1625*cdf0e10cSrcweir                         "Unable to retreive value of property 'IsDocument'!" ),
1626*cdf0e10cSrcweir                     get() ) ),
1627*cdf0e10cSrcweir          m_xImpl->getEnvironment() );
1628*cdf0e10cSrcweir 
1629*cdf0e10cSrcweir     // Unreachable - cancelCommandExecution always throws an exception,
1630*cdf0e10cSrcweir     // But some compilers complain...
1631*cdf0e10cSrcweir     return sal_False;
1632*cdf0e10cSrcweir }
1633*cdf0e10cSrcweir 
1634*cdf0e10cSrcweir //=========================================================================
1635*cdf0e10cSrcweir //=========================================================================
1636*cdf0e10cSrcweir //
1637*cdf0e10cSrcweir // Content_Impl Implementation.
1638*cdf0e10cSrcweir //
1639*cdf0e10cSrcweir //=========================================================================
1640*cdf0e10cSrcweir //=========================================================================
1641*cdf0e10cSrcweir 
1642*cdf0e10cSrcweir Content_Impl::Content_Impl( const Reference< XMultiServiceFactory >& rSMgr,
1643*cdf0e10cSrcweir                             const Reference< XContent >& rContent,
1644*cdf0e10cSrcweir                             const Reference< XCommandEnvironment >& rEnv )
1645*cdf0e10cSrcweir : m_xSMgr( rSMgr ),
1646*cdf0e10cSrcweir   m_xContent( rContent ),
1647*cdf0e10cSrcweir   m_xEnv( rEnv ),
1648*cdf0e10cSrcweir   m_nCommandId( 0 )
1649*cdf0e10cSrcweir {
1650*cdf0e10cSrcweir     if ( m_xContent.is() )
1651*cdf0e10cSrcweir     {
1652*cdf0e10cSrcweir         m_xContentEventListener = new ContentEventListener_Impl( *this );
1653*cdf0e10cSrcweir         m_xContent->addContentEventListener( m_xContentEventListener );
1654*cdf0e10cSrcweir 
1655*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1656*cdf0e10cSrcweir         // Only done on demand in product version for performance reasons,
1657*cdf0e10cSrcweir         // but a nice debug helper.
1658*cdf0e10cSrcweir         getURL();
1659*cdf0e10cSrcweir #endif
1660*cdf0e10cSrcweir     }
1661*cdf0e10cSrcweir }
1662*cdf0e10cSrcweir 
1663*cdf0e10cSrcweir //=========================================================================
1664*cdf0e10cSrcweir void Content_Impl::reinit( const Reference< XContent >& xContent )
1665*cdf0e10cSrcweir {
1666*cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
1667*cdf0e10cSrcweir 
1668*cdf0e10cSrcweir     m_xCommandProcessor = 0;
1669*cdf0e10cSrcweir     m_nCommandId = 0;
1670*cdf0e10cSrcweir 
1671*cdf0e10cSrcweir     // #92581# - Don't reset m_aURL!!!
1672*cdf0e10cSrcweir 
1673*cdf0e10cSrcweir     if ( m_xContent.is() )
1674*cdf0e10cSrcweir     {
1675*cdf0e10cSrcweir         try
1676*cdf0e10cSrcweir         {
1677*cdf0e10cSrcweir             m_xContent->removeContentEventListener( m_xContentEventListener );
1678*cdf0e10cSrcweir         }
1679*cdf0e10cSrcweir         catch ( RuntimeException const & )
1680*cdf0e10cSrcweir         {
1681*cdf0e10cSrcweir         }
1682*cdf0e10cSrcweir     }
1683*cdf0e10cSrcweir 
1684*cdf0e10cSrcweir     if ( xContent.is() )
1685*cdf0e10cSrcweir     {
1686*cdf0e10cSrcweir         m_xContent = xContent;
1687*cdf0e10cSrcweir         m_xContent->addContentEventListener( m_xContentEventListener );
1688*cdf0e10cSrcweir 
1689*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1690*cdf0e10cSrcweir         // Only done on demand in product version for performance reasons,
1691*cdf0e10cSrcweir         // but a nice debug helper.
1692*cdf0e10cSrcweir         getURL();
1693*cdf0e10cSrcweir #endif
1694*cdf0e10cSrcweir     }
1695*cdf0e10cSrcweir     else
1696*cdf0e10cSrcweir     {
1697*cdf0e10cSrcweir         // We need m_xContent's URL in order to be able to create the
1698*cdf0e10cSrcweir         // content object again if demanded ( --> Content_Impl::getContent() )
1699*cdf0e10cSrcweir         getURL();
1700*cdf0e10cSrcweir 
1701*cdf0e10cSrcweir         m_xContent = 0;
1702*cdf0e10cSrcweir     }
1703*cdf0e10cSrcweir }
1704*cdf0e10cSrcweir 
1705*cdf0e10cSrcweir //=========================================================================
1706*cdf0e10cSrcweir // virtual
1707*cdf0e10cSrcweir Content_Impl::~Content_Impl()
1708*cdf0e10cSrcweir {
1709*cdf0e10cSrcweir     if ( m_xContent.is() )
1710*cdf0e10cSrcweir     {
1711*cdf0e10cSrcweir         try
1712*cdf0e10cSrcweir         {
1713*cdf0e10cSrcweir             m_xContent->removeContentEventListener( m_xContentEventListener );
1714*cdf0e10cSrcweir         }
1715*cdf0e10cSrcweir         catch ( RuntimeException const & )
1716*cdf0e10cSrcweir         {
1717*cdf0e10cSrcweir         }
1718*cdf0e10cSrcweir     }
1719*cdf0e10cSrcweir }
1720*cdf0e10cSrcweir 
1721*cdf0e10cSrcweir //=========================================================================
1722*cdf0e10cSrcweir void Content_Impl::disposing( const EventObject& Source )
1723*cdf0e10cSrcweir {
1724*cdf0e10cSrcweir     Reference<XContent> xContent;
1725*cdf0e10cSrcweir 
1726*cdf0e10cSrcweir     {
1727*cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
1728*cdf0e10cSrcweir         if(Source.Source != m_xContent)
1729*cdf0e10cSrcweir             return;
1730*cdf0e10cSrcweir 
1731*cdf0e10cSrcweir         xContent = m_xContent;
1732*cdf0e10cSrcweir 
1733*cdf0e10cSrcweir         m_nCommandId = 0;
1734*cdf0e10cSrcweir         m_aURL = rtl::OUString();
1735*cdf0e10cSrcweir         m_xCommandProcessor = 0;
1736*cdf0e10cSrcweir         m_xContent = 0;
1737*cdf0e10cSrcweir     }
1738*cdf0e10cSrcweir 
1739*cdf0e10cSrcweir     if ( xContent.is() )
1740*cdf0e10cSrcweir     {
1741*cdf0e10cSrcweir         try
1742*cdf0e10cSrcweir         {
1743*cdf0e10cSrcweir             xContent->removeContentEventListener( m_xContentEventListener );
1744*cdf0e10cSrcweir         }
1745*cdf0e10cSrcweir         catch ( RuntimeException const & )
1746*cdf0e10cSrcweir         {
1747*cdf0e10cSrcweir         }
1748*cdf0e10cSrcweir     }
1749*cdf0e10cSrcweir }
1750*cdf0e10cSrcweir 
1751*cdf0e10cSrcweir //=========================================================================
1752*cdf0e10cSrcweir const rtl::OUString& Content_Impl::getURL() const
1753*cdf0e10cSrcweir {
1754*cdf0e10cSrcweir     if ( !m_aURL.getLength() && m_xContent.is() )
1755*cdf0e10cSrcweir     {
1756*cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
1757*cdf0e10cSrcweir 
1758*cdf0e10cSrcweir         if ( !m_aURL.getLength() && m_xContent.is() )
1759*cdf0e10cSrcweir         {
1760*cdf0e10cSrcweir             Reference< XContentIdentifier > xId = m_xContent->getIdentifier();
1761*cdf0e10cSrcweir             if ( xId.is() )
1762*cdf0e10cSrcweir                 m_aURL = xId->getContentIdentifier();
1763*cdf0e10cSrcweir         }
1764*cdf0e10cSrcweir     }
1765*cdf0e10cSrcweir 
1766*cdf0e10cSrcweir     return m_aURL;
1767*cdf0e10cSrcweir }
1768*cdf0e10cSrcweir 
1769*cdf0e10cSrcweir //=========================================================================
1770*cdf0e10cSrcweir Reference< XContent > Content_Impl::getContent()
1771*cdf0e10cSrcweir {
1772*cdf0e10cSrcweir     if ( !m_xContent.is() && m_aURL.getLength() )
1773*cdf0e10cSrcweir     {
1774*cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
1775*cdf0e10cSrcweir 
1776*cdf0e10cSrcweir         if ( !m_xContent.is() && m_aURL.getLength() )
1777*cdf0e10cSrcweir         {
1778*cdf0e10cSrcweir             ContentBroker* pBroker = ContentBroker::get();
1779*cdf0e10cSrcweir 
1780*cdf0e10cSrcweir             OSL_ENSURE( pBroker, "No Content Broker!" );
1781*cdf0e10cSrcweir 
1782*cdf0e10cSrcweir             if ( pBroker )
1783*cdf0e10cSrcweir             {
1784*cdf0e10cSrcweir                 OSL_ENSURE( pBroker->getContentProviderManagerInterface()
1785*cdf0e10cSrcweir                                         ->queryContentProviders().getLength(),
1786*cdf0e10cSrcweir                             "Content Broker not configured (no providers)!" );
1787*cdf0e10cSrcweir 
1788*cdf0e10cSrcweir                 Reference< XContentIdentifierFactory > xIdFac
1789*cdf0e10cSrcweir                             = pBroker->getContentIdentifierFactoryInterface();
1790*cdf0e10cSrcweir 
1791*cdf0e10cSrcweir                 OSL_ENSURE( xIdFac.is(), "No Content Identifier factory!" );
1792*cdf0e10cSrcweir 
1793*cdf0e10cSrcweir                 if ( xIdFac.is() )
1794*cdf0e10cSrcweir                 {
1795*cdf0e10cSrcweir                     Reference< XContentIdentifier > xId
1796*cdf0e10cSrcweir                                 = xIdFac->createContentIdentifier( m_aURL );
1797*cdf0e10cSrcweir 
1798*cdf0e10cSrcweir                     OSL_ENSURE( xId.is(), "No Content Identifier!" );
1799*cdf0e10cSrcweir 
1800*cdf0e10cSrcweir                     if ( xId.is() )
1801*cdf0e10cSrcweir                     {
1802*cdf0e10cSrcweir                         Reference< XContentProvider > xProvider
1803*cdf0e10cSrcweir                             = pBroker->getContentProviderInterface();
1804*cdf0e10cSrcweir 
1805*cdf0e10cSrcweir                         OSL_ENSURE( xProvider.is(), "No Content Provider!" );
1806*cdf0e10cSrcweir 
1807*cdf0e10cSrcweir                         if ( xProvider.is() )
1808*cdf0e10cSrcweir                         {
1809*cdf0e10cSrcweir                             try
1810*cdf0e10cSrcweir                             {
1811*cdf0e10cSrcweir                                 m_xContent = xProvider->queryContent( xId );
1812*cdf0e10cSrcweir                             }
1813*cdf0e10cSrcweir                             catch ( IllegalIdentifierException const & )
1814*cdf0e10cSrcweir                             {
1815*cdf0e10cSrcweir                             }
1816*cdf0e10cSrcweir 
1817*cdf0e10cSrcweir                             if ( m_xContent.is() )
1818*cdf0e10cSrcweir                                 m_xContent->addContentEventListener(
1819*cdf0e10cSrcweir                                                 m_xContentEventListener );
1820*cdf0e10cSrcweir                         }
1821*cdf0e10cSrcweir                     }
1822*cdf0e10cSrcweir                 }
1823*cdf0e10cSrcweir             }
1824*cdf0e10cSrcweir         }
1825*cdf0e10cSrcweir     }
1826*cdf0e10cSrcweir 
1827*cdf0e10cSrcweir     return m_xContent;
1828*cdf0e10cSrcweir }
1829*cdf0e10cSrcweir 
1830*cdf0e10cSrcweir //=========================================================================
1831*cdf0e10cSrcweir Reference< XCommandProcessor > Content_Impl::getCommandProcessor()
1832*cdf0e10cSrcweir {
1833*cdf0e10cSrcweir     if ( !m_xCommandProcessor.is() )
1834*cdf0e10cSrcweir     {
1835*cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
1836*cdf0e10cSrcweir 
1837*cdf0e10cSrcweir         if ( !m_xCommandProcessor.is() )
1838*cdf0e10cSrcweir             m_xCommandProcessor
1839*cdf0e10cSrcweir                 = Reference< XCommandProcessor >( getContent(), UNO_QUERY );
1840*cdf0e10cSrcweir     }
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir     return m_xCommandProcessor;
1843*cdf0e10cSrcweir }
1844*cdf0e10cSrcweir 
1845*cdf0e10cSrcweir //=========================================================================
1846*cdf0e10cSrcweir sal_Int32 Content_Impl::getCommandId()
1847*cdf0e10cSrcweir {
1848*cdf0e10cSrcweir     if ( m_nCommandId == 0 )
1849*cdf0e10cSrcweir     {
1850*cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
1851*cdf0e10cSrcweir 
1852*cdf0e10cSrcweir         if ( m_nCommandId == 0 )
1853*cdf0e10cSrcweir         {
1854*cdf0e10cSrcweir             Reference< XCommandProcessor > xProc = getCommandProcessor();
1855*cdf0e10cSrcweir             if ( xProc.is() )
1856*cdf0e10cSrcweir                 m_nCommandId = xProc->createCommandIdentifier();
1857*cdf0e10cSrcweir         }
1858*cdf0e10cSrcweir     }
1859*cdf0e10cSrcweir 
1860*cdf0e10cSrcweir     return m_nCommandId;
1861*cdf0e10cSrcweir }
1862*cdf0e10cSrcweir 
1863*cdf0e10cSrcweir //=========================================================================
1864*cdf0e10cSrcweir Any Content_Impl::executeCommand( const Command& rCommand )
1865*cdf0e10cSrcweir {
1866*cdf0e10cSrcweir     Reference< XCommandProcessor > xProc = getCommandProcessor();
1867*cdf0e10cSrcweir     if ( !xProc.is() )
1868*cdf0e10cSrcweir         return Any();
1869*cdf0e10cSrcweir 
1870*cdf0e10cSrcweir     // Execute command
1871*cdf0e10cSrcweir     return xProc->execute( rCommand, getCommandId(), m_xEnv );
1872*cdf0e10cSrcweir }
1873*cdf0e10cSrcweir 
1874*cdf0e10cSrcweir //=========================================================================
1875*cdf0e10cSrcweir void Content_Impl::abortCommand()
1876*cdf0e10cSrcweir {
1877*cdf0e10cSrcweir     sal_Int32 nCommandId;
1878*cdf0e10cSrcweir     Reference< XCommandProcessor > xCommandProcessor;
1879*cdf0e10cSrcweir     {
1880*cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
1881*cdf0e10cSrcweir         nCommandId = m_nCommandId;
1882*cdf0e10cSrcweir         xCommandProcessor = m_xCommandProcessor;
1883*cdf0e10cSrcweir     }
1884*cdf0e10cSrcweir 
1885*cdf0e10cSrcweir     if ( ( nCommandId != 0 ) && xCommandProcessor.is() )
1886*cdf0e10cSrcweir         xCommandProcessor->abort( nCommandId );
1887*cdf0e10cSrcweir }
1888*cdf0e10cSrcweir 
1889*cdf0e10cSrcweir //=========================================================================
1890*cdf0e10cSrcweir inline const Reference< XCommandEnvironment >&
1891*cdf0e10cSrcweir                                         Content_Impl::getEnvironment() const
1892*cdf0e10cSrcweir {
1893*cdf0e10cSrcweir     return m_xEnv;
1894*cdf0e10cSrcweir }
1895*cdf0e10cSrcweir 
1896*cdf0e10cSrcweir //=========================================================================
1897*cdf0e10cSrcweir inline void Content_Impl::setEnvironment(
1898*cdf0e10cSrcweir                         const Reference< XCommandEnvironment >& xNewEnv )
1899*cdf0e10cSrcweir {
1900*cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
1901*cdf0e10cSrcweir     m_xEnv = xNewEnv;
1902*cdf0e10cSrcweir }
1903*cdf0e10cSrcweir 
1904*cdf0e10cSrcweir //=========================================================================
1905*cdf0e10cSrcweir void Content_Impl::inserted()
1906*cdf0e10cSrcweir {
1907*cdf0e10cSrcweir     // URL might have changed during 'insert' => recalculate in next getURL()
1908*cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
1909*cdf0e10cSrcweir     m_aURL = ::rtl::OUString();
1910*cdf0e10cSrcweir }
1911*cdf0e10cSrcweir 
1912*cdf0e10cSrcweir //=========================================================================
1913*cdf0e10cSrcweir //=========================================================================
1914*cdf0e10cSrcweir //
1915*cdf0e10cSrcweir // ContentEventListener_Impl Implementation.
1916*cdf0e10cSrcweir //
1917*cdf0e10cSrcweir //=========================================================================
1918*cdf0e10cSrcweir //=========================================================================
1919*cdf0e10cSrcweir 
1920*cdf0e10cSrcweir //=========================================================================
1921*cdf0e10cSrcweir //
1922*cdf0e10cSrcweir // XInterface methods.
1923*cdf0e10cSrcweir //
1924*cdf0e10cSrcweir //=========================================================================
1925*cdf0e10cSrcweir 
1926*cdf0e10cSrcweir XINTERFACE_IMPL_2( ContentEventListener_Impl,
1927*cdf0e10cSrcweir                    XContentEventListener,
1928*cdf0e10cSrcweir                    XEventListener ); /* base of XContentEventListener */
1929*cdf0e10cSrcweir 
1930*cdf0e10cSrcweir //=========================================================================
1931*cdf0e10cSrcweir //
1932*cdf0e10cSrcweir // XContentEventListener methods.
1933*cdf0e10cSrcweir //
1934*cdf0e10cSrcweir //=========================================================================
1935*cdf0e10cSrcweir 
1936*cdf0e10cSrcweir // virtual
1937*cdf0e10cSrcweir void SAL_CALL ContentEventListener_Impl::contentEvent( const ContentEvent& evt )
1938*cdf0e10cSrcweir     throw( RuntimeException )
1939*cdf0e10cSrcweir {
1940*cdf0e10cSrcweir     if ( evt.Source == m_rContent.m_xContent )
1941*cdf0e10cSrcweir     {
1942*cdf0e10cSrcweir         switch ( evt.Action )
1943*cdf0e10cSrcweir         {
1944*cdf0e10cSrcweir             case ContentAction::DELETED:
1945*cdf0e10cSrcweir                 m_rContent.reinit( Reference< XContent >() );
1946*cdf0e10cSrcweir                 break;
1947*cdf0e10cSrcweir 
1948*cdf0e10cSrcweir             case ContentAction::EXCHANGED:
1949*cdf0e10cSrcweir                 m_rContent.reinit( evt.Content );
1950*cdf0e10cSrcweir                 break;
1951*cdf0e10cSrcweir 
1952*cdf0e10cSrcweir             default:
1953*cdf0e10cSrcweir                 break;
1954*cdf0e10cSrcweir         }
1955*cdf0e10cSrcweir     }
1956*cdf0e10cSrcweir }
1957*cdf0e10cSrcweir 
1958*cdf0e10cSrcweir //=========================================================================
1959*cdf0e10cSrcweir //
1960*cdf0e10cSrcweir // XEventListenr methods.
1961*cdf0e10cSrcweir //
1962*cdf0e10cSrcweir //=========================================================================
1963*cdf0e10cSrcweir 
1964*cdf0e10cSrcweir // virtual
1965*cdf0e10cSrcweir void SAL_CALL ContentEventListener_Impl::disposing( const EventObject& Source )
1966*cdf0e10cSrcweir     throw( RuntimeException )
1967*cdf0e10cSrcweir {
1968*cdf0e10cSrcweir     m_rContent.disposing(Source);
1969*cdf0e10cSrcweir }
1970*cdf0e10cSrcweir 
1971*cdf0e10cSrcweir } /* namespace ucbhelper */
1972*cdf0e10cSrcweir 
1973