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