xref: /trunk/main/ucb/workben/ucb/ucbdemo.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_ucb.hxx"
30 
31 #include <stack>
32 #include <rtl/ustrbuf.hxx>
33 #include <vos/mutex.hxx>
34 #include <vos/process.hxx>
35 #include <cppuhelper/weak.hxx>
36 #include <cppuhelper/bootstrap.hxx>
37 #include <com/sun/star/ucb/ContentAction.hpp>
38 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
39 #include <com/sun/star/ucb/ContentResultSetCapability.hpp>
40 #include <com/sun/star/ucb/SearchCommandArgument.hpp>
41 #include <com/sun/star/ucb/NameClash.hpp>
42 #include <com/sun/star/ucb/TransferInfo.hpp>
43 #include <com/sun/star/ucb/GlobalTransferCommandArgument.hpp>
44 #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
45 #include <com/sun/star/ucb/CommandInfo.hpp>
46 #include <com/sun/star/ucb/XContentProviderManager.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #include <com/sun/star/beans/Property.hpp>
49 #include <com/sun/star/lang/XComponent.hpp>
50 #include <com/sun/star/ucb/CHAOSProgressStart.hpp>
51 #include <com/sun/star/ucb/OpenMode.hpp>
52 #include <com/sun/star/ucb/ResultSetException.hpp>
53 #include <com/sun/star/io/XOutputStream.hpp>
54 #include <com/sun/star/beans/XPropertySet.hpp>
55 #include <com/sun/star/beans/XPropertyContainer.hpp>
56 #include <com/sun/star/ucb/XProgressHandler.hpp>
57 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
58 #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
59 #include <com/sun/star/beans/XPropertiesChangeNotifier.hpp>
60 #include <com/sun/star/ucb/XCommandProcessor.hpp>
61 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
62 #include <com/sun/star/sdbc/XRow.hpp>
63 #include <com/sun/star/ucb/XContentAccess.hpp>
64 #include <com/sun/star/ucb/XCommandInfo.hpp>
65 #include <com/sun/star/beans/PropertyValue.hpp>
66 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
67 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
68 #include <comphelper/processfactory.hxx>
69 #include <ucbhelper/configurationkeys.hxx>
70 #include <ucbhelper/fileidentifierconverter.hxx>
71 #include <ucbhelper/contentbroker.hxx>
72 #include <tools/debug.hxx>
73 
74 #include "tools/time.hxx"
75 #include <vcl/wrkwin.hxx>
76 #include <vcl/toolbox.hxx>
77 #include <vcl/edit.hxx>
78 #include <vcl/lstbox.hxx>
79 #include <vcl/svapp.hxx>
80 #include <vcl/help.hxx>
81 #include <srcharg.hxx>
82 
83 using ucbhelper::getLocalFileURL;
84 using ucbhelper::getSystemPathFromFileURL;
85 using ucbhelper::getFileURLFromSystemPath;
86 
87 using namespace com::sun::star;
88 
89 /*========================================================================
90  *
91  * MyOutWindow.
92  *
93  *======================================================================*/
94 
95 #define MYOUTWINDOW_MAXLINES 4096
96 
97 class MyOutWindow : public ListBox
98 {
99 public:
100     MyOutWindow( Window *pParent, WinBits nWinStyle )
101     : ListBox ( pParent, nWinStyle | WB_AUTOHSCROLL ) {}
102     ~MyOutWindow() {}
103 
104     void Append( const String &rLine );
105 };
106 
107 //-------------------------------------------------------------------------
108 void MyOutWindow::Append( const String &rLine )
109 {
110     String aLine( rLine );
111 
112     xub_StrLen nPos = aLine.Search( '\n' );
113     while ( nPos != STRING_NOTFOUND )
114     {
115         if ( GetEntryCount() >= MYOUTWINDOW_MAXLINES )
116             RemoveEntry( 0 );
117 
118         InsertEntry( aLine.Copy( 0, nPos ) );
119 
120         aLine.Erase( 0, nPos + 1 );
121         nPos = aLine.Search( '\n' );
122     }
123 
124     if ( GetEntryCount() >= MYOUTWINDOW_MAXLINES )
125         RemoveEntry( 0 );
126 
127     InsertEntry( aLine );
128 
129     SetTopEntry( MYOUTWINDOW_MAXLINES - 1 );
130 }
131 
132 /*========================================================================
133  *
134  * MessagePrinter.
135  *
136  *=======================================================================*/
137 
138 class MessagePrinter
139 {
140 protected:
141     MyOutWindow* m_pOutEdit;
142 
143 public:
144     MessagePrinter( MyOutWindow* pOutEdit = NULL )
145     : m_pOutEdit( pOutEdit ) {}
146     void setOutEdit( MyOutWindow* pOutEdit )
147     { m_pOutEdit = pOutEdit; }
148     void print( const sal_Char* pText );
149     void print( const UniString& rText );
150 };
151 
152 //-------------------------------------------------------------------------
153 void MessagePrinter::print( const sal_Char* pText )
154 {
155     print( UniString::CreateFromAscii( pText ) );
156 }
157 
158 //-------------------------------------------------------------------------
159 void MessagePrinter::print( const UniString& rText )
160 {
161     vos::OGuard aGuard( Application::GetSolarMutex() );
162 
163     if ( m_pOutEdit )
164     {
165         m_pOutEdit->Append( rText );
166         m_pOutEdit->Update();
167     }
168 }
169 
170 //============================================================================
171 //
172 //  TestOutputStream
173 //
174 //============================================================================
175 
176 class TestOutputStream:
177     public cppu::OWeakObject,
178     public io::XOutputStream
179 {
180     rtl::OUString m_sStart;
181     bool m_bMore;
182 
183 public:
184     TestOutputStream(): m_bMore(false) {}
185 
186     virtual uno::Any SAL_CALL queryInterface(const uno::Type & rType)
187     throw(uno::RuntimeException);
188     virtual void SAL_CALL acquire() throw ()
189     { OWeakObject::acquire(); }
190 
191     virtual void SAL_CALL release() throw ()
192     { OWeakObject::release(); }
193 
194     virtual void SAL_CALL writeBytes(const uno::Sequence< sal_Int8 > & rData)
195         throw(uno::RuntimeException);
196 
197     virtual void SAL_CALL flush() throw() {}
198 
199     virtual void SAL_CALL closeOutput() throw() {};
200 
201     rtl::OUString getStart() const;
202 };
203 
204 //============================================================================
205 // virtual
206 uno::Any SAL_CALL
207 TestOutputStream::queryInterface(const uno::Type & rType)
208     throw(uno::RuntimeException)
209 {
210     uno::Any aRet = cppu::queryInterface(rType,
211                         static_cast< io::XOutputStream * >(this));
212     return aRet.hasValue() ? aRet : OWeakObject::queryInterface(rType);
213 }
214 
215 //============================================================================
216 // virtual
217 void SAL_CALL TestOutputStream::writeBytes(
218                                     const uno::Sequence< sal_Int8 > & rData)
219     throw(uno::RuntimeException)
220 {
221     sal_Int32 nLen = rData.getLength();
222     if (m_sStart.getLength() + nLen > 500)
223     {
224         nLen = 500 - m_sStart.getLength();
225         m_bMore = true;
226     }
227     m_sStart
228         += rtl::OUString(reinterpret_cast< const sal_Char * >(rData.
229                                                               getConstArray()),
230                          nLen, RTL_TEXTENCODING_ISO_8859_1);
231 }
232 
233 //============================================================================
234 rtl::OUString TestOutputStream::getStart() const
235 {
236     rtl::OUString sResult = m_sStart;
237     if (m_bMore)
238         sResult += rtl::OUString::createFromAscii("...");
239     return sResult;
240 }
241 
242 /*========================================================================
243  *
244  * ProgressHandler.
245  *
246  *=======================================================================*/
247 
248 class ProgressHandler:
249     public cppu::OWeakObject,
250     public ucb::XProgressHandler
251 {
252     MessagePrinter & m_rPrinter;
253 
254     rtl::OUString toString(const uno::Any & rStatus);
255 
256 public:
257     ProgressHandler(MessagePrinter & rThePrinter): m_rPrinter(rThePrinter) {}
258 
259     virtual uno::Any SAL_CALL queryInterface(
260                                 const uno::Type & rType)
261         throw(uno::RuntimeException);
262 
263     virtual void SAL_CALL acquire() throw ()
264     { OWeakObject::acquire(); }
265 
266     virtual void SAL_CALL release() throw ()
267     { OWeakObject::release(); }
268 
269     virtual void SAL_CALL push(const uno::Any & rStatus)
270         throw (uno::RuntimeException);
271 
272     virtual void SAL_CALL update(const uno::Any & rStatus)
273         throw (uno::RuntimeException);
274 
275     virtual void SAL_CALL pop() throw (uno::RuntimeException);
276 };
277 
278 rtl::OUString ProgressHandler::toString(const uno::Any & rStatus)
279 {
280     ucb::CHAOSProgressStart aStart;
281     if (rStatus >>= aStart)
282     {
283         rtl::OUString sResult;
284         if (aStart.Text.getLength() > 0)
285         {
286             sResult = aStart.Text;
287             sResult += rtl::OUString::createFromAscii(" ");
288         }
289         sResult += rtl::OUString::createFromAscii("[");
290         sResult += rtl::OUString::valueOf(aStart.Minimum);
291         sResult += rtl::OUString::createFromAscii("..");
292         sResult += rtl::OUString::valueOf(aStart.Maximum);
293         sResult += rtl::OUString::createFromAscii("]");
294         return sResult;
295     }
296 
297     rtl::OUString sText;
298     if (rStatus >>= sText)
299         return sText;
300 
301     sal_Int32 nValue;
302     if (rStatus >>= nValue)
303     {
304         rtl::OUString sResult = rtl::OUString::createFromAscii("..");
305         sResult += rtl::OUString::valueOf(nValue);
306         sResult += rtl::OUString::createFromAscii("..");
307         return rtl::OUString(sResult);
308     }
309 
310     return rtl::OUString::createFromAscii("(Unknown object)");
311 }
312 
313 //============================================================================
314 // virtual
315 uno::Any SAL_CALL
316 ProgressHandler::queryInterface( const uno::Type & rType )
317     throw(uno::RuntimeException)
318 {
319     uno::Any aRet = cppu::queryInterface(
320                         rType,
321                         static_cast< ucb::XProgressHandler* >(this));
322     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
323 }
324 
325 //============================================================================
326 // virtual
327 void SAL_CALL ProgressHandler::push(const uno::Any & rStatus)
328     throw (uno::RuntimeException)
329 {
330     rtl::OUString sMessage = rtl::OUString::createFromAscii("Status push: ");
331     sMessage += toString(rStatus);
332     m_rPrinter.print(sMessage);
333 }
334 
335 //============================================================================
336 // virtual
337 void SAL_CALL ProgressHandler::update(const uno::Any & rStatus)
338     throw (uno::RuntimeException)
339 {
340     rtl::OUString sMessage = rtl::OUString::createFromAscii("Status update: ");
341     sMessage += toString(rStatus);
342     m_rPrinter.print(sMessage);
343 }
344 
345 //============================================================================
346 // virtual
347 void SAL_CALL ProgressHandler::pop() throw (uno::RuntimeException)
348 {
349     m_rPrinter.print("Status pop");
350 }
351 
352 /*========================================================================
353  *
354  * Ucb.
355  *
356  *=======================================================================*/
357 
358 #define UCB_MODULE_NAME  "ucb1"
359 
360 class Ucb : public MessagePrinter
361 {
362 private:
363     uno::Reference< lang::XMultiServiceFactory >      m_xFac;
364     uno::Reference< ucb::XContentProvider >          m_xProv;
365     uno::Reference< ucb::XContentIdentifierFactory > m_xIdFac;
366     rtl::OUString m_aConfigurationKey1;
367     rtl::OUString m_aConfigurationKey2;
368     sal_Bool m_bInited : 1;
369 
370     static rtl::OUString getUnoURL();
371 
372 public:
373     Ucb( uno::Reference< lang::XMultiServiceFactory >& rxFactory,
374          rtl::OUString const & rConfigurationKey1,
375          rtl::OUString const & rConfigurationKey2 );
376     ~Ucb();
377 
378     sal_Bool init();
379 
380     uno::Reference< lang::XMultiServiceFactory > getServiceFactory() const
381     { return m_xFac; }
382 
383     uno::Reference< ucb::XContentIdentifierFactory >
384     getContentIdentifierFactory();
385     uno::Reference< ucb::XContentProvider >
386     getContentProvider();
387 
388     static rtl::OUString m_aProtocol;
389 };
390 
391 // static
392 rtl::OUString Ucb::m_aProtocol;
393 
394 //-------------------------------------------------------------------------
395 // static
396 rtl::OUString Ucb::getUnoURL()
397 {
398     rtl::OUString aUnoURL(rtl::OUString::createFromAscii(
399                          "uno:socket,host=localhost,port=8121;"));
400     if (m_aProtocol.getLength() == 0)
401         aUnoURL += rtl::OUString::createFromAscii("urp");
402     else
403         aUnoURL += m_aProtocol;
404     aUnoURL += rtl::OUString::createFromAscii(";UCB.Factory");
405     return aUnoURL;
406 }
407 
408 //-------------------------------------------------------------------------
409 Ucb::Ucb( uno::Reference< lang::XMultiServiceFactory >& rxFactory,
410           rtl::OUString const & rConfigurationKey1,
411           rtl::OUString const & rConfigurationKey2 )
412 : m_xFac( rxFactory ),
413   m_aConfigurationKey1( rConfigurationKey1 ),
414   m_aConfigurationKey2( rConfigurationKey2 ),
415   m_bInited( sal_False )
416 {
417 }
418 
419 //-------------------------------------------------------------------------
420 Ucb::~Ucb()
421 {
422 }
423 
424 //-------------------------------------------------------------------------
425 sal_Bool Ucb::init()
426 {
427     if ( m_bInited )
428         return sal_True;
429 
430     // Create auto configured UCB:
431     if (m_xFac.is())
432         try
433         {
434             rtl::OUString aPipe;
435             vos::OSecurity().getUserIdent(aPipe);
436             uno::Sequence< uno::Any > aArgs(4);
437             aArgs[0] <<= m_aConfigurationKey1;
438             aArgs[1] <<= m_aConfigurationKey2;
439             aArgs[2] <<= rtl::OUString::createFromAscii("PIPE");
440             aArgs[3] <<= aPipe;
441 #if 0
442             m_xProv
443                 = uno::Reference< XContentProvider >(
444                       m_xFac->
445                           createInstanceWithArguments(
446                               rtl::OUString::createFromAscii(
447                                   "com.sun.star.ucb."
448                                       "UniversalContentBroker"),
449                               aArgs),
450                          uno::UNO_QUERY);
451 #else
452             ::ucbhelper::ContentBroker::initialize( m_xFac, aArgs );
453             m_xProv
454                 = ::ucbhelper::ContentBroker::get()->getContentProviderInterface();
455 #endif
456         }
457         catch (uno::Exception const &) {}
458 
459     if (m_xProv.is())
460     {
461         print("UCB initialized");
462         uno::Reference< ucb::XContentProviderManager > xProvMgr(
463             m_xProv, uno::UNO_QUERY);
464         if (xProvMgr.is())
465         {
466             print("Registered schemes:");
467             uno::Sequence< ucb::ContentProviderInfo >
468                 aInfos(xProvMgr->queryContentProviders());
469             for (sal_Int32 i = 0; i < aInfos.getLength(); ++i)
470             {
471                 String aText(RTL_CONSTASCII_USTRINGPARAM("    "));
472                 aText += UniString(aInfos[i].Scheme);
473                 print(aText);
474             }
475         }
476     }
477     else
478         print("Error initializing UCB");
479 
480     m_bInited = m_xProv.is();
481     return m_bInited;
482 }
483 
484 //-------------------------------------------------------------------------
485 uno::Reference< ucb::XContentIdentifierFactory >
486 Ucb::getContentIdentifierFactory()
487 {
488     if ( !m_xIdFac.is() )
489     {
490         if ( init() )
491             m_xIdFac = uno::Reference< ucb::XContentIdentifierFactory >(
492                             m_xProv, uno::UNO_QUERY );
493     }
494 
495     return m_xIdFac;
496 }
497 
498 //-------------------------------------------------------------------------
499 uno::Reference< ucb::XContentProvider > Ucb::getContentProvider()
500 {
501     if ( !m_xProv.is() )
502         init();
503 
504     return m_xProv;
505 }
506 
507 /*========================================================================
508  *
509  * UcbTaskEnvironment.
510  *
511  *=======================================================================*/
512 
513 class UcbTaskEnvironment : public cppu::OWeakObject,
514                            public ucb::XCommandEnvironment
515 {
516     uno::Reference< task::XInteractionHandler > m_xInteractionHandler;
517     uno::Reference< ucb::XProgressHandler > m_xProgressHandler;
518 
519 public:
520     UcbTaskEnvironment( const uno::Reference< task::XInteractionHandler>&
521                          rxInteractionHandler,
522                         const uno::Reference< ucb::XProgressHandler>&
523                          rxProgressHandler );
524     virtual ~UcbTaskEnvironment();
525 
526     // Interface implementations...
527 
528     // XInterface
529 
530     virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType )
531         throw( uno::RuntimeException );
532     virtual void SAL_CALL acquire()
533         throw();
534     virtual void SAL_CALL release()
535         throw();
536 
537     // XCommandEnvironemnt
538 
539     virtual uno::Reference<task::XInteractionHandler> SAL_CALL
540     getInteractionHandler()
541         throw (uno::RuntimeException)
542     { return m_xInteractionHandler; }
543 
544     virtual uno::Reference<ucb::XProgressHandler> SAL_CALL
545     getProgressHandler()
546         throw (uno::RuntimeException)
547     { return m_xProgressHandler; }
548  };
549 
550 //-------------------------------------------------------------------------
551 UcbTaskEnvironment::UcbTaskEnvironment(
552                     const uno::Reference< task::XInteractionHandler >&
553                      rxInteractionHandler,
554                     const uno::Reference< ucb::XProgressHandler >&
555                      rxProgressHandler )
556 : m_xInteractionHandler( rxInteractionHandler ),
557   m_xProgressHandler( rxProgressHandler )
558 {
559 }
560 
561 //-------------------------------------------------------------------------
562 // virtual
563 UcbTaskEnvironment::~UcbTaskEnvironment()
564 {
565 }
566 
567 //----------------------------------------------------------------------------
568 //
569 // XInterface methods
570 //
571 //----------------------------------------------------------------------------
572 
573 // virtual
574 uno::Any SAL_CALL
575 UcbTaskEnvironment::queryInterface( const uno::Type & rType )
576     throw( uno::RuntimeException )
577 {
578     uno::Any aRet = cppu::queryInterface(
579             rType, static_cast< ucb::XCommandEnvironment* >( this ) );
580     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
581 }
582 
583 //----------------------------------------------------------------------------
584 // virtual
585 void SAL_CALL UcbTaskEnvironment::acquire()
586     throw()
587 {
588     OWeakObject::acquire();
589 }
590 
591 //----------------------------------------------------------------------------
592 // virtual
593 void SAL_CALL UcbTaskEnvironment::release()
594     throw()
595 {
596     OWeakObject::release();
597 }
598 
599 /*========================================================================
600  *
601  * UcbCommandProcessor.
602  *
603  *=======================================================================*/
604 
605 class UcbCommandProcessor : public MessagePrinter
606 {
607 protected:
608     Ucb& m_rUCB;
609 
610 private:
611     uno::Reference< ucb::XCommandProcessor > m_xProcessor;
612     sal_Int32 m_aCommandId;
613 
614 public:
615     UcbCommandProcessor( Ucb& rUCB,
616                          const uno::Reference<
617                             ucb::XCommandProcessor >& rxProcessor,
618                          MyOutWindow* pOutEdit );
619 
620     virtual ~UcbCommandProcessor();
621 
622     uno::Any executeCommand( const rtl::OUString& rName,
623                              const uno::Any& rArgument,
624                              bool bPrint = true );
625 };
626 
627 //-------------------------------------------------------------------------
628 UcbCommandProcessor::UcbCommandProcessor( Ucb& rUCB,
629                                           const uno::Reference<
630                                             ucb::XCommandProcessor >&
631                                               rxProcessor,
632                                           MyOutWindow* pOutEdit)
633 : MessagePrinter( pOutEdit ),
634   m_rUCB( rUCB ),
635   m_xProcessor( rxProcessor ),
636   m_aCommandId( 0 )
637 {
638     if ( m_xProcessor.is() )
639     {
640         // Generally, one command identifier per thread is enough. It
641         // can be used for all commands executed by the processor which
642         // created this id.
643         m_aCommandId = m_xProcessor->createCommandIdentifier();
644     }
645 }
646 
647 //----------------------------------------------------------------------------
648 // virtual
649 UcbCommandProcessor::~UcbCommandProcessor()
650 {
651 }
652 
653 //----------------------------------------------------------------------------
654 uno::Any UcbCommandProcessor::executeCommand( const rtl::OUString& rName,
655                                               const uno::Any& rArgument,
656                                               bool bPrint )
657 {
658     if ( m_xProcessor.is() )
659     {
660         ucb::Command aCommand;
661         aCommand.Name     = rName;
662         aCommand.Handle   = -1; /* unknown */
663         aCommand.Argument = rArgument;
664 
665         uno::Reference< task::XInteractionHandler > xInteractionHandler;
666         if (m_rUCB.getServiceFactory().is())
667             xInteractionHandler
668                 = uno::Reference< task::XInteractionHandler >(
669                       m_rUCB.getServiceFactory()->
670                           createInstance(
671                               rtl::OUString::createFromAscii(
672                                   "com.sun.star.task.InteractionHandler")),
673                       uno::UNO_QUERY);
674         uno::Reference< ucb::XProgressHandler >
675             xProgressHandler(new ProgressHandler(m_rUCB));
676         uno::Reference< ucb::XCommandEnvironment > xEnv(
677             new UcbTaskEnvironment( xInteractionHandler, xProgressHandler ) );
678 
679         if ( bPrint )
680         {
681             UniString aText( UniString::CreateFromAscii(
682                                 RTL_CONSTASCII_STRINGPARAM(
683                                     "Executing command: " ) ) );
684             aText += UniString( rName );
685             print( aText );
686         }
687 
688         // Execute command
689         uno::Any aResult;
690         bool bException = false;
691         bool bAborted = false;
692         try
693         {
694             aResult = m_xProcessor->execute( aCommand, m_aCommandId, xEnv );
695         }
696         catch ( ucb::CommandAbortedException const & )
697         {
698             bAborted = true;
699         }
700         catch ( uno::Exception const & )
701         {
702             bException = true;
703         }
704 
705         if ( bPrint )
706         {
707             if ( bException )
708                 print( "execute(...) threw an exception!" );
709 
710             if ( bAborted )
711                 print( "execute(...) aborted!" );
712 
713             if ( !bException && !bAborted )
714                 print( "execute() finished." );
715         }
716 
717         return aResult;
718     }
719 
720     print( "executeCommand failed!" );
721     return uno::Any();
722 }
723 
724 /*========================================================================
725  *
726  * UcbContent.
727  *
728  *=======================================================================*/
729 
730 class UcbContent : public UcbCommandProcessor,
731                    public cppu::OWeakObject,
732                    public ucb::XContentEventListener,
733                    public beans::XPropertiesChangeListener
734 {
735     uno::Reference< ucb::XContent > m_xContent;
736 
737     struct OpenStackEntry
738     {
739         uno::Reference< ucb::XContentIdentifier > m_xIdentifier;
740         uno::Reference< ucb::XContent > m_xContent;
741         sal_uInt32 m_nLevel;
742         bool m_bUseIdentifier;
743 
744         OpenStackEntry(uno::Reference< ucb::XContentIdentifier > const &
745                         rTheIdentifier,
746                        sal_uInt32 nTheLevel):
747             m_xIdentifier(rTheIdentifier), m_nLevel(nTheLevel),
748             m_bUseIdentifier(true) {}
749 
750         OpenStackEntry(uno::Reference< ucb::XContent > const & rTheContent,
751                        sal_uInt32 nTheLevel):
752             m_xContent(rTheContent), m_nLevel(nTheLevel),
753             m_bUseIdentifier(false) {}
754     };
755     typedef std::stack< OpenStackEntry > OpenStack;
756 
757 private:
758     UcbContent( Ucb& rUCB,
759                 uno::Reference< ucb::XContent >& rxContent,
760                 MyOutWindow* pOutEdit );
761 
762 protected:
763     virtual ~UcbContent();
764 
765 public:
766     static UcbContent* create(
767             Ucb& rUCB, const UniString& rURL, MyOutWindow* pOutEdit );
768     void dispose();
769 
770     const UniString getURL() const;
771     const UniString getType() const;
772 
773     uno::Sequence< ucb::CommandInfo > getCommands();
774     uno::Sequence< beans::Property >    getProperties();
775 
776     uno::Any  getPropertyValue( const rtl::OUString& rName );
777     void setPropertyValue( const rtl::OUString& rName, const uno::Any& rValue );
778     void addProperty     ( const rtl::OUString& rName, const uno::Any& rValue );
779     void removeProperty  ( const rtl::OUString& rName );
780 
781     rtl::OUString getStringPropertyValue( const rtl::OUString& rName );
782     void setStringPropertyValue( const rtl::OUString& rName,
783                                  const rtl::OUString& rValue );
784     void addStringProperty( const rtl::OUString& rName,
785                             const rtl::OUString& rValue );
786     void open( const rtl::OUString & rName, const UniString& rInput,
787                bool bPrint, bool bTiming, bool bSort,
788                OpenStack * pStack = 0, sal_uInt32 nLevel = 0,
789                sal_Int32 nFetchSize = 0 );
790     void openAll( Ucb& rUCB, bool bPrint, bool bTiming, bool bSort,
791                   sal_Int32 nFetchSize );
792     void transfer( const rtl::OUString& rSourceURL, sal_Bool bMove );
793     void destroy();
794 
795     // XInterface
796     virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType )
797         throw( uno::RuntimeException );
798     virtual void SAL_CALL
799     acquire()
800         throw();
801     virtual void SAL_CALL
802     release()
803         throw();
804 
805     // XEventListener
806     // ( base interface of XContentEventListener, XPropertiesChangeListener )
807     virtual void SAL_CALL
808     disposing( const lang::EventObject& Source )
809         throw( uno::RuntimeException );
810 
811     // XContentEventListener
812     virtual void SAL_CALL
813     contentEvent( const ucb::ContentEvent& evt )
814         throw( uno::RuntimeException );
815 
816     // XPropertiesChangeListener
817     virtual void SAL_CALL
818     propertiesChange( const uno::Sequence< beans::PropertyChangeEvent >& evt )
819         throw( uno::RuntimeException );
820 };
821 
822 //-------------------------------------------------------------------------
823 UcbContent::UcbContent( Ucb& rUCB,
824                         uno::Reference< ucb::XContent >& rxContent,
825                         MyOutWindow* pOutEdit)
826 : UcbCommandProcessor( rUCB,
827                        uno::Reference< ucb::XCommandProcessor >(
828                                                 rxContent, uno::UNO_QUERY ),
829                        pOutEdit ),
830   m_xContent( rxContent )
831 {
832 }
833 
834 //----------------------------------------------------------------------------
835 // virtual
836 UcbContent::~UcbContent()
837 {
838 }
839 
840 //-------------------------------------------------------------------------
841 // static
842 UcbContent* UcbContent::create(
843         Ucb& rUCB, const UniString& rURL, MyOutWindow* pOutEdit )
844 {
845     if ( !rURL.Len() )
846         return NULL;
847 
848     //////////////////////////////////////////////////////////////////////
849     // Get XContentIdentifier interface from UCB and let it create an
850     // identifer for the given URL.
851     //////////////////////////////////////////////////////////////////////
852 
853     uno::Reference< ucb::XContentIdentifierFactory > xIdFac =
854                                         rUCB.getContentIdentifierFactory();
855     if ( !xIdFac.is() )
856         return NULL;
857 
858     uno::Reference< ucb::XContentIdentifier > xId =
859                             xIdFac->createContentIdentifier( rURL );
860     if ( !xId.is() )
861         return NULL;
862 
863     //////////////////////////////////////////////////////////////////////
864     // Get XContentProvider interface from UCB and let it create a
865     // content for the given identifier.
866     //////////////////////////////////////////////////////////////////////
867 
868     uno::Reference< ucb::XContentProvider > xProv
869         = rUCB.getContentProvider();
870     if ( !xProv.is() )
871         return NULL;
872 
873     uno::Reference< ucb::XContent > xContent;
874     try
875     {
876         xContent = xProv->queryContent( xId );
877     }
878     catch (ucb::IllegalIdentifierException const &) {}
879     if ( !xContent.is() )
880         return NULL;
881 
882     UcbContent* pNew = new UcbContent( rUCB, xContent, pOutEdit );
883     pNew->acquire();
884 
885     // Register listener(s).
886     xContent->addContentEventListener( pNew );
887 
888     uno::Reference< beans::XPropertiesChangeNotifier > xNotifier(
889         xContent, uno::UNO_QUERY );
890     if ( xNotifier.is() )
891     {
892         // Empty sequence -> interested in any property changes.
893         xNotifier->addPropertiesChangeListener(
894             uno::Sequence< rtl::OUString >(), pNew );
895     }
896 
897     return pNew;
898 }
899 
900 //-------------------------------------------------------------------------
901 const UniString UcbContent::getURL() const
902 {
903     uno::Reference< ucb::XContentIdentifier > xId(
904         m_xContent->getIdentifier() );
905     if ( xId.is() )
906         return UniString( xId->getContentIdentifier() );
907 
908     return UniString();
909 }
910 
911 //-------------------------------------------------------------------------
912 const UniString UcbContent::getType() const
913 {
914     const UniString aType( m_xContent->getContentType() );
915     return aType;
916 }
917 
918 //-------------------------------------------------------------------------
919 void UcbContent::dispose()
920 {
921     uno::Reference< lang::XComponent > xComponent( m_xContent, uno::UNO_QUERY );
922     if ( xComponent.is() )
923         xComponent->dispose();
924 }
925 
926 //----------------------------------------------------------------------------
927 void UcbContent::open( const rtl::OUString & rName, const UniString& rInput,
928                        bool bPrint, bool bTiming, bool bSort,
929                        OpenStack * pStack, sal_uInt32 nLevel,
930                        sal_Int32 nFetchSize )
931 {
932     uno::Any aArg;
933 
934     bool bDoSort = false;
935 
936     ucb::OpenCommandArgument2 aOpenArg;
937     if (rName.compareToAscii("search") == 0)
938     {
939         ucb::SearchCommandArgument aArgument;
940         if (!parseSearchArgument(rInput, aArgument.Info))
941         {
942             print("Can't parse search argument");
943             return;
944         }
945         aArgument.Properties.realloc(5);
946         aArgument.Properties[0].Name = rtl::OUString::createFromAscii("Title");
947         aArgument.Properties[0].Handle = -1;
948         aArgument.Properties[1].Name
949             = rtl::OUString::createFromAscii("DateCreated");
950         aArgument.Properties[1].Handle = -1;
951         aArgument.Properties[2].Name = rtl::OUString::createFromAscii("Size");
952         aArgument.Properties[2].Handle = -1;
953         aArgument.Properties[3].Name
954             = rtl::OUString::createFromAscii("IsFolder");
955         aArgument.Properties[3].Handle = -1;
956         aArgument.Properties[4].Name
957             = rtl::OUString::createFromAscii("IsDocument");
958         aArgument.Properties[4].Handle = -1;
959         aArg <<= aArgument;
960     }
961     else
962     {
963         aOpenArg.Mode = ucb::OpenMode::ALL;
964         aOpenArg.Priority = 32768;
965 //      if ( bFolder )
966         {
967             // Property values which shall be in the result set...
968             uno::Sequence< beans::Property > aProps( 5 );
969             beans::Property* pProps = aProps.getArray();
970             pProps[ 0 ].Name   = rtl::OUString::createFromAscii( "Title" );
971             pProps[ 0 ].Handle = -1; // Important!
972 /**/        pProps[ 0 ].Type = getCppuType(static_cast< rtl::OUString * >(0));
973                 // HACK for sorting...
974             pProps[ 1 ].Name   = rtl::OUString::createFromAscii( "DateCreated" );
975             pProps[ 1 ].Handle = -1; // Important!
976             pProps[ 2 ].Name   = rtl::OUString::createFromAscii( "Size" );
977             pProps[ 2 ].Handle = -1; // Important!
978             pProps[ 3 ].Name   = rtl::OUString::createFromAscii( "IsFolder" );
979             pProps[ 3 ].Handle = -1; // Important!
980 /**/        pProps[ 3 ].Type = getCppuType(static_cast< sal_Bool * >(0));
981                 // HACK for sorting...
982             pProps[ 4 ].Name   = rtl::OUString::createFromAscii( "IsDocument" );
983             pProps[ 4 ].Handle = -1; // Important!
984             aOpenArg.Properties = aProps;
985 
986             bDoSort = bSort;
987             if (bDoSort)
988             {
989                 // Sort criteria... Note that column numbering starts with 1!
990                 aOpenArg.SortingInfo.realloc(2);
991                 // primary sort criterium: column 4 --> IsFolder
992                 aOpenArg.SortingInfo[ 0 ].ColumnIndex = 4;
993                 aOpenArg.SortingInfo[ 0 ].Ascending   = sal_False;
994                 // secondary sort criterium: column 1 --> Title
995                 aOpenArg.SortingInfo[ 1 ].ColumnIndex = 1;
996                 aOpenArg.SortingInfo[ 1 ].Ascending   = sal_True;
997             }
998         }
999 //      else
1000             aOpenArg.Sink
1001                 = static_cast< cppu::OWeakObject * >(new TestOutputStream);
1002         aArg <<= aOpenArg;
1003     }
1004 
1005 //  putenv("PROT_REMOTE_ACTIVATE=1"); // to log remote uno traffic
1006 
1007     ULONG nTime = 0;
1008     if ( bTiming )
1009         nTime = Time::GetSystemTicks();
1010 
1011     uno::Any aResult = executeCommand( rName, aArg, bPrint );
1012 
1013     uno::Reference< ucb::XDynamicResultSet > xDynamicResultSet;
1014     if ( ( aResult >>= xDynamicResultSet ) && xDynamicResultSet.is() )
1015     {
1016         if (bDoSort)
1017         {
1018             sal_Int16 nCaps = xDynamicResultSet->getCapabilities();
1019             if (!(nCaps & ucb::ContentResultSetCapability::SORTED))
1020             {
1021                 if (bPrint)
1022                     print("Result set rows are not sorted"
1023                               "---using sorting cursor");
1024 
1025                 uno::Reference< ucb::XSortedDynamicResultSetFactory >
1026                     xSortedFactory;
1027                 if (m_rUCB.getServiceFactory().is())
1028                     xSortedFactory
1029                         = uno::Reference<
1030                             ucb::XSortedDynamicResultSetFactory >(
1031                               m_rUCB.
1032                                   getServiceFactory()->
1033                                       createInstance(
1034                                           rtl::OUString::createFromAscii(
1035                                               "com.sun.star.ucb.SortedDynamic"
1036                                                   "ResultSetFactory")),
1037                               uno::UNO_QUERY);
1038                 uno::Reference< ucb::XDynamicResultSet > xSorted;
1039                 if (xSortedFactory.is())
1040                     xSorted
1041                         = xSortedFactory->
1042                               createSortedDynamicResultSet(xDynamicResultSet,
1043                                                            aOpenArg.
1044                                                                SortingInfo,
1045                                                            0);
1046                 if (xSorted.is())
1047                     xDynamicResultSet = xSorted;
1048                 else
1049                     print("Sorting cursor not available!");
1050             }
1051         }
1052 
1053         uno::Reference< sdbc::XResultSet > xResultSet(
1054                                     xDynamicResultSet->getStaticResultSet() );
1055         if ( xResultSet.is() )
1056         {
1057             if ( bPrint )
1058             {
1059                 print( "Folder object opened - iterating:" );
1060                 print( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(
1061                     "Content-ID : Title : Size : IsFolder : IsDocument\n"
1062                     "-------------------------------------------------" ) ) );
1063             }
1064 
1065             if (nFetchSize > 0)
1066             {
1067                 bool bSet = false;
1068                 uno::Reference< beans::XPropertySet > xProperties(
1069                     xResultSet, uno::UNO_QUERY);
1070                 if (xProperties.is())
1071                     try
1072                     {
1073                         xProperties->
1074                             setPropertyValue(rtl::OUString::createFromAscii(
1075                                                  "FetchSize"),
1076                                              uno::makeAny(nFetchSize));
1077                         bSet = true;
1078                     }
1079                     catch (beans::UnknownPropertyException const &) {}
1080                     catch (beans::PropertyVetoException const &) {}
1081                     catch (lang::IllegalArgumentException const &) {}
1082                     catch (lang::WrappedTargetException const &) {}
1083                 if (!bSet)
1084                     print("Fetch size not set!");
1085             }
1086 
1087             try
1088             {
1089                 ULONG n = 0;
1090                 uno::Reference< ucb::XContentAccess > xContentAccess(
1091                                                 xResultSet, uno::UNO_QUERY );
1092                 uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
1093 
1094                 while ( xResultSet->next() )
1095                 {
1096                     UniString aText;
1097 
1098                     if ( bPrint )
1099                     {
1100                         rtl::OUString aId( xContentAccess->
1101                                           queryContentIdentifierString() );
1102                         aText += UniString::CreateFromInt32( ++n );
1103                         aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(
1104                                                ") " ) );
1105                         aText += UniString( aId );
1106                         aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(
1107                                                " : " ) );
1108                     }
1109 
1110                     // Title:
1111                     UniString aTitle( xRow->getString( 1 ) );
1112                     if ( bPrint )
1113                     {
1114                         if ( aTitle.Len() == 0 && xRow->wasNull() )
1115                             aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(
1116                                                    "<null>" ) );
1117                         else
1118                             aText += aTitle;
1119                         aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(
1120                                                " : " ) );
1121                     }
1122 
1123                     // Size:
1124                     sal_Int32 nSize = xRow->getInt( 3 );
1125                     if ( bPrint )
1126                     {
1127                         if ( nSize == 0 && xRow->wasNull() )
1128                             aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(
1129                                                    "<null>" ) );
1130                         else
1131                             aText += UniString::CreateFromInt32( nSize );
1132                         aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(
1133                                                " : " ) );
1134                     }
1135 
1136                     // IsFolder:
1137                     sal_Bool bFolder = xRow->getBoolean( 4 );
1138                     if ( bPrint )
1139                     {
1140                         if ( !bFolder && xRow->wasNull() )
1141                             aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(
1142                                                    "<null>" ) );
1143                         else
1144                             aText
1145                                 += bFolder ?
1146                                        UniString::CreateFromAscii(
1147                                            RTL_CONSTASCII_STRINGPARAM(
1148                                                "true" ) ) :
1149                                        UniString::CreateFromAscii(
1150                                            RTL_CONSTASCII_STRINGPARAM(
1151                                                "false" ) );
1152                         aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(
1153                                                " : " ) );
1154                     }
1155 
1156                     // IsDocument:
1157                     sal_Bool bDocument = xRow->getBoolean( 5 );
1158                     if ( bPrint )
1159                     {
1160                         if ( !bFolder && xRow->wasNull() )
1161                             aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(
1162                                 "<null>" ) );
1163                         else
1164                             aText
1165                                 += bDocument ?
1166                                        UniString::CreateFromAscii(
1167                                            RTL_CONSTASCII_STRINGPARAM(
1168                                                "true" ) ) :
1169                                        UniString::CreateFromAscii(
1170                                            RTL_CONSTASCII_STRINGPARAM(
1171                                                "false" ) ); //  IsDocument
1172                     }
1173 
1174                     if ( bPrint )
1175                         print( aText );
1176 
1177                     if ( pStack && bFolder )
1178                         pStack->push( OpenStackEntry(
1179 #if 1
1180                                           xContentAccess->
1181                                               queryContentIdentifier(),
1182 #else
1183                                           xContentAccess->queryContent(),
1184 #endif
1185                                           nLevel + 1 ) );
1186                 }
1187             }
1188             catch ( ucb::ResultSetException )
1189             {
1190                 print( "ResultSetException caught!" );
1191             }
1192 
1193             if ( bPrint )
1194                 print( "Iteration done." );
1195         }
1196     }
1197 
1198     uno::Reference< lang::XComponent > xComponent(
1199         xDynamicResultSet, uno::UNO_QUERY);
1200     if (xComponent.is())
1201         xComponent->dispose();
1202 
1203 //  putenv("PROT_REMOTE_ACTIVATE="); // to log remote uno traffic
1204 
1205     if ( bTiming )
1206     {
1207         nTime = Time::GetSystemTicks() - nTime;
1208         UniString
1209             aText( UniString::CreateFromAscii(
1210                        RTL_CONSTASCII_STRINGPARAM( "Operation took " ) ) );
1211         aText += UniString::CreateFromInt64( nTime );
1212         aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ms." ) );
1213         print( aText );
1214     }
1215 }
1216 
1217 //----------------------------------------------------------------------------
1218 void UcbContent::openAll( Ucb& rUCB, bool bPrint, bool bTiming, bool bSort,
1219                           sal_Int32 nFetchSize )
1220 {
1221     ULONG nTime = 0;
1222     if ( bTiming )
1223         nTime = Time::GetSystemTicks();
1224 
1225     OpenStack aStack;
1226     aStack.push( OpenStackEntry( m_xContent, 0 ) );
1227 
1228     while ( !aStack.empty() )
1229     {
1230         OpenStackEntry aEntry( aStack.top() );
1231         aStack.pop();
1232 
1233         if ( bPrint )
1234         {
1235             UniString aText;
1236             for ( sal_uInt32 i = aEntry.m_nLevel; i != 0; --i )
1237                 aText += '=';
1238             aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "LEVEL " ) );
1239             aText += UniString::CreateFromInt64( aEntry.m_nLevel );
1240 
1241             uno::Reference< ucb::XContentIdentifier > xID;
1242             if ( aEntry.m_bUseIdentifier )
1243                 xID = aEntry.m_xIdentifier;
1244             else if ( aEntry.m_xContent.is() )
1245                 xID = aEntry.m_xContent->getIdentifier();
1246             if ( xID.is() )
1247             {
1248                 aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) );
1249                 aText += UniString( xID->getContentIdentifier() );
1250             }
1251 
1252             print( aText );
1253         }
1254 
1255         uno::Reference< ucb::XContent > xChild;
1256         if ( aEntry.m_bUseIdentifier )
1257         {
1258             uno::Reference< ucb::XContentProvider > xProv
1259                 = rUCB.getContentProvider();
1260             if ( !xProv.is() )
1261             {
1262                 print( "No content provider" );
1263                 return;
1264             }
1265 
1266             try
1267             {
1268                 xChild = xProv->queryContent( aEntry.m_xIdentifier );
1269             }
1270             catch (ucb::IllegalIdentifierException const &) {}
1271         }
1272         else
1273             xChild = aEntry.m_xContent;
1274         if ( !xChild.is() )
1275         {
1276             print( "No content" );
1277             return;
1278         }
1279 
1280         UcbContent( m_rUCB, xChild, m_pOutEdit ).
1281             open( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(
1282                                                   "open" ) ),
1283                   UniString(), bPrint, false, bSort, &aStack,
1284                   aEntry.m_nLevel, nFetchSize );
1285     }
1286 
1287     if ( bTiming )
1288     {
1289         nTime = Time::GetSystemTicks() - nTime;
1290         UniString
1291             aText( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(
1292                                                    "Operation took " ) ) );
1293         aText += UniString::CreateFromInt64( nTime );
1294         aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ms." ) );
1295         print( aText );
1296     }
1297 }
1298 
1299 //----------------------------------------------------------------------------
1300 void UcbContent::transfer( const rtl::OUString& rSourceURL, sal_Bool bMove  )
1301 {
1302     if ( bMove )
1303         print( "Moving content..." );
1304     else
1305         print( "Copying content..." );
1306 
1307 #if 1 /* globalTransfer */
1308 
1309     uno::Reference< ucb::XCommandProcessor > xCommandProcessor(
1310                                 m_rUCB.getContentProvider(), uno::UNO_QUERY );
1311     if ( xCommandProcessor.is() )
1312     {
1313 
1314 #if 0
1315         ucb::Command aCommand(
1316             rtl::OUString::createFromAscii( "getCommandInfo" ), -1, Any() );
1317         uno::Reference< ucb::XCommandInfo > xInfo;
1318         xCommandProcessor->execute(
1319             aCommand, 0, uno::Reference< ucb::XCommandEnvironment >() )
1320                 >>= xInfo;
1321         if ( xInfo.is() )
1322         {
1323             ucb::CommandInfo aInfo
1324                 = xInfo->getCommandInfoByName(
1325                     rtl::OUString::createFromAscii( "globalTransfer" ) );
1326 
1327             uno::Sequence< ucb::CommandInfo > aCommands
1328                 = xInfo->getCommands();
1329             const ucb::CommandInfo* pCommands = aCommands.getConstArray();
1330 
1331             String aText( UniString::CreateFromAscii(
1332                             RTL_CONSTASCII_STRINGPARAM( "Commands:\n" ) ) );
1333             sal_uInt32 nCount = aCommands.getLength();
1334             for ( sal_uInt32 n = 0; n < nCount; ++n )
1335             {
1336                 aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "    " ) );
1337                 aText += String( pCommands[ n ].Name );
1338                 aText += '\n';
1339             }
1340             print( aText );
1341         }
1342 #endif
1343         ucb::GlobalTransferCommandArgument aArg(
1344                             bMove ? ucb::TransferCommandOperation_MOVE
1345                                   : ucb::TransferCommandOperation_COPY,
1346                             rSourceURL,
1347                             getURL(),
1348                             rtl::OUString(),
1349                             //rtl::OUString::createFromAscii( "NewTitle" ),
1350                             ucb::NameClash::ERROR );
1351 
1352         ucb::Command aTransferCommand( rtl::OUString::createFromAscii(
1353                                                 "globalTransfer" ),
1354                                              -1,
1355                                              uno::makeAny( aArg ) );
1356 
1357         uno::Reference< task::XInteractionHandler > xInteractionHandler;
1358         if (m_rUCB.getServiceFactory().is())
1359             xInteractionHandler
1360                 = uno::Reference< task::XInteractionHandler >(
1361                         m_rUCB.getServiceFactory()->
1362                             createInstance(
1363                                 rtl::OUString::createFromAscii(
1364                                     "com.sun.star.task.InteractionHandler")),
1365                         uno::UNO_QUERY);
1366         uno::Reference< ucb::XProgressHandler > xProgressHandler(
1367             new ProgressHandler(m_rUCB));
1368         uno::Reference< ucb::XCommandEnvironment > xEnv(
1369             new UcbTaskEnvironment( xInteractionHandler, xProgressHandler ) );
1370 
1371         try
1372         {
1373             xCommandProcessor->execute( aTransferCommand, 0, xEnv );
1374         }
1375         catch ( uno::Exception const & )
1376         {
1377             print( "globalTransfer threw exception!" );
1378             return;
1379         }
1380 
1381         print( "globalTransfer finished successfully" );
1382     }
1383 
1384 #else /* transfer */
1385 
1386     uno::Any aArg;
1387     aArg <<= ucb::TransferInfo(
1388             bMove, rSourceURL, rtl::OUString(), ucb::NameClash::ERROR );
1389     executeCommand( rtl::OUString::createFromAscii( "transfer" ), aArg );
1390 
1391 //  executeCommand( rtl::OUString::createFromAscii( "flush" ), Any() );
1392 
1393 #endif
1394 }
1395 
1396 //----------------------------------------------------------------------------
1397 void UcbContent::destroy()
1398 {
1399     print( "Deleting content..." );
1400 
1401     uno::Any aArg;
1402     aArg <<= sal_Bool( sal_True ); // delete physically, not only to trash.
1403     executeCommand( rtl::OUString::createFromAscii( "delete" ), aArg );
1404 
1405 //  executeCommand( rtl::OUString::createFromAscii( "flush" ), Any() );
1406 }
1407 
1408 //-------------------------------------------------------------------------
1409 uno::Sequence< ucb::CommandInfo > UcbContent::getCommands()
1410 {
1411     uno::Any aResult = executeCommand(
1412             rtl::OUString::createFromAscii( "getCommandInfo" ), uno::Any() );
1413 
1414     uno::Reference< ucb::XCommandInfo > xInfo;
1415     if ( aResult >>= xInfo )
1416     {
1417         uno::Sequence< ucb::CommandInfo > aCommands(
1418             xInfo->getCommands() );
1419         const ucb::CommandInfo* pCommands = aCommands.getConstArray();
1420 
1421         String aText( UniString::CreateFromAscii(
1422                         RTL_CONSTASCII_STRINGPARAM( "Commands:\n" ) ) );
1423         sal_uInt32 nCount = aCommands.getLength();
1424         for ( sal_uInt32 n = 0; n < nCount; ++n )
1425         {
1426             aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "    " ) );
1427             aText += String( pCommands[ n ].Name );
1428             aText += '\n';
1429         }
1430         print( aText );
1431 
1432         return aCommands;
1433     }
1434 
1435     print( "getCommands failed!" );
1436     return uno::Sequence< ucb::CommandInfo >();
1437 }
1438 
1439 //-------------------------------------------------------------------------
1440 uno::Sequence< beans::Property > UcbContent::getProperties()
1441 {
1442     uno::Any aResult = executeCommand(
1443         rtl::OUString::createFromAscii( "getPropertySetInfo" ), uno::Any() );
1444 
1445     uno::Reference< beans::XPropertySetInfo > xInfo;
1446     if ( aResult >>= xInfo )
1447     {
1448         uno::Sequence< beans::Property > aProps( xInfo->getProperties() );
1449         const beans::Property* pProps = aProps.getConstArray();
1450 
1451         String aText( UniString::CreateFromAscii(
1452                         RTL_CONSTASCII_STRINGPARAM( "Properties:\n" ) ) );
1453         sal_uInt32 nCount = aProps.getLength();
1454         for ( sal_uInt32 n = 0; n < nCount; ++n )
1455         {
1456             aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "    " ) );
1457             aText += UniString( pProps[ n ].Name );
1458             aText += '\n';
1459         }
1460         print( aText );
1461 
1462         return aProps;
1463     }
1464 
1465     print( "getProperties failed!" );
1466     return uno::Sequence< beans::Property >();
1467 }
1468 
1469 //----------------------------------------------------------------------------
1470 uno::Any UcbContent::getPropertyValue( const rtl::OUString& rName )
1471 {
1472     uno::Sequence< beans::Property > aProps( 1 );
1473     beans::Property& rProp = aProps.getArray()[ 0 ];
1474 
1475     rProp.Name       = rName;
1476     rProp.Handle     = -1; /* unknown */
1477 //  rProp.Type       = ;
1478 //  rProp.Attributes = ;
1479 
1480     uno::Any aArg;
1481     aArg <<= aProps;
1482 
1483     uno::Any aResult = executeCommand(
1484         rtl::OUString::createFromAscii( "getPropertyValues" ), aArg );
1485 
1486     uno::Reference< sdbc::XRow > xValues;
1487     if ( aResult >>= xValues )
1488         return xValues->getObject(
1489             1, uno::Reference< container::XNameAccess>() );
1490 
1491     print( "getPropertyValue failed!" );
1492     return uno::Any();
1493 }
1494 
1495 //----------------------------------------------------------------------------
1496 rtl::OUString UcbContent::getStringPropertyValue( const rtl::OUString& rName )
1497 {
1498     uno::Any aAny = getPropertyValue( rName );
1499     if ( aAny.getValueType() == getCppuType( (const ::rtl::OUString *)0 ) )
1500     {
1501         const rtl::OUString aValue(
1502             * static_cast< const rtl::OUString * >( aAny.getValue() ) );
1503 
1504         UniString aText( rName );
1505         aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " value: '" ) );
1506         aText += UniString( aValue );
1507         aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "'" ) );
1508         print( aText );
1509 
1510         return aValue;
1511     }
1512 
1513     print( "getStringPropertyValue failed!" );
1514     return rtl::OUString();
1515 }
1516 
1517 //----------------------------------------------------------------------------
1518 void UcbContent::setPropertyValue( const rtl::OUString& rName,
1519                                    const uno::Any& rValue )
1520 {
1521     uno::Sequence< beans::PropertyValue > aProps( 1 );
1522     beans::PropertyValue& rProp = aProps.getArray()[ 0 ];
1523 
1524     rProp.Name       = rName;
1525     rProp.Handle     = -1; /* unknown */
1526     rProp.Value      = rValue;
1527 //  rProp.State      = ;
1528 
1529     uno::Any aArg;
1530     aArg <<= aProps;
1531 
1532     executeCommand( rtl::OUString::createFromAscii( "setPropertyValues" ),
1533                     aArg );
1534 
1535 //  executeCommand( rtl::OUString::createFromAscii( "flush" ), Any() );
1536 }
1537 
1538 //----------------------------------------------------------------------------
1539 void UcbContent::setStringPropertyValue( const rtl::OUString& rName,
1540                                          const rtl::OUString& rValue )
1541 {
1542     uno::Any aAny;
1543     aAny <<= rValue;
1544     setPropertyValue( rName, aAny );
1545 
1546     UniString aText( rName );
1547     aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " value set to: '" ) );
1548     aText += UniString( rValue );
1549     aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "'" ) );
1550     print( aText );
1551 }
1552 
1553 //----------------------------------------------------------------------------
1554 void UcbContent::addProperty( const rtl::OUString& rName,
1555                               const uno::Any& rValue )
1556 {
1557     uno::Reference< beans::XPropertyContainer > xContainer( m_xContent,
1558                                                             uno::UNO_QUERY );
1559     if ( xContainer.is() )
1560     {
1561         UniString aText( UniString::CreateFromAscii(
1562                             RTL_CONSTASCII_STRINGPARAM(
1563                                 "Adding property: " ) ) );
1564         aText += UniString( rName );
1565         print( aText );
1566 
1567         try
1568         {
1569             xContainer->addProperty( rName, 0, rValue );
1570         }
1571         catch ( beans::PropertyExistException const & )
1572         {
1573             print( "Adding property failed. Already exists!" );
1574             return;
1575         }
1576         catch ( beans::IllegalTypeException const & )
1577         {
1578             print( "Adding property failed. Illegal Type!" );
1579             return;
1580         }
1581         catch ( lang::IllegalArgumentException const & )
1582         {
1583             print( "Adding property failed. Illegal Argument!" );
1584             return;
1585         }
1586 
1587         print( "Adding property succeeded." );
1588         return;
1589     }
1590 
1591     print( "Adding property failed. No XPropertyContainer!" );
1592 }
1593 
1594 //----------------------------------------------------------------------------
1595 void UcbContent::addStringProperty(
1596                     const rtl::OUString& rName, const rtl::OUString& rValue )
1597 {
1598     uno::Any aValue;
1599     aValue <<= rValue;
1600     addProperty( rName, aValue );
1601 }
1602 
1603 //----------------------------------------------------------------------------
1604 void UcbContent::removeProperty( const rtl::OUString& rName )
1605 {
1606     uno::Reference< beans::XPropertyContainer > xContainer( m_xContent,
1607                                                             uno::UNO_QUERY );
1608     if ( xContainer.is() )
1609     {
1610         UniString aText( UniString::CreateFromAscii(
1611                             RTL_CONSTASCII_STRINGPARAM(
1612                                 "Removing property: " ) ) );
1613         aText += UniString( rName );
1614         print( aText );
1615 
1616         try
1617         {
1618             xContainer->removeProperty( rName );
1619         }
1620         catch ( beans::UnknownPropertyException const & )
1621         {
1622             print( "Adding property failed. Unknown!" );
1623             return;
1624         }
1625 
1626         print( "Removing property succeeded." );
1627         return;
1628     }
1629 
1630     print( "Removing property failed. No XPropertyContainer!" );
1631 }
1632 
1633 //----------------------------------------------------------------------------
1634 //
1635 // XInterface methods
1636 //
1637 //----------------------------------------------------------------------------
1638 
1639 // virtual
1640 uno::Any SAL_CALL UcbContent::queryInterface( const uno::Type & rType )
1641     throw(uno::RuntimeException)
1642 {
1643     uno::Any aRet = cppu::queryInterface(
1644                 rType,
1645                 static_cast< lang::XEventListener* >(
1646                     static_cast< ucb::XContentEventListener* >( this ) ),
1647                 static_cast< ucb::XContentEventListener* >( this ),
1648                 static_cast< beans::XPropertiesChangeListener* >( this ) );
1649     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
1650 }
1651 
1652 //----------------------------------------------------------------------------
1653 // virtual
1654 void SAL_CALL UcbContent::acquire()
1655     throw()
1656 {
1657     OWeakObject::acquire();
1658 }
1659 
1660 //----------------------------------------------------------------------------
1661 // virtual
1662 void SAL_CALL UcbContent::release()
1663     throw()
1664 {
1665     OWeakObject::release();
1666 }
1667 
1668 //----------------------------------------------------------------------------
1669 //
1670 // XEventListener methods.
1671 //
1672 //----------------------------------------------------------------------------
1673 
1674 // virtual
1675 void SAL_CALL UcbContent::disposing( const lang::EventObject& /*Source*/ )
1676     throw( uno::RuntimeException )
1677 {
1678     print ( "Content: disposing..." );
1679 }
1680 
1681 //----------------------------------------------------------------------------
1682 //
1683 // XContentEventListener methods,
1684 //
1685 //----------------------------------------------------------------------------
1686 
1687 // virtual
1688 void SAL_CALL UcbContent::contentEvent( const ucb::ContentEvent& evt )
1689     throw( uno::RuntimeException )
1690 {
1691     switch ( evt.Action )
1692     {
1693         case ucb::ContentAction::INSERTED:
1694         {
1695             UniString aText( UniString::CreateFromAscii(
1696                                 RTL_CONSTASCII_STRINGPARAM(
1697                                     "contentEvent: INSERTED: " ) ) );
1698             if ( evt.Content.is() )
1699             {
1700                 uno::Reference< ucb::XContentIdentifier > xId(
1701                                         evt.Content->getIdentifier() );
1702                 aText += UniString( xId->getContentIdentifier() );
1703                 aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ) );
1704                 aText += UniString( evt.Content->getContentType() );
1705             }
1706 
1707             print( aText );
1708             break;
1709         }
1710         case ucb::ContentAction::REMOVED:
1711             print( "contentEvent: REMOVED" );
1712             break;
1713 
1714         case ucb::ContentAction::DELETED:
1715             print( "contentEvent: DELETED" );
1716             break;
1717 
1718         case ucb::ContentAction::EXCHANGED:
1719             print( "contentEvent: EXCHANGED" );
1720             break;
1721 
1722         case ucb::ContentAction::SEARCH_MATCHED:
1723         {
1724             String aMatch(RTL_CONSTASCII_USTRINGPARAM(
1725                               "contentEvent: SEARCH MATCHED "));
1726             if (evt.Id.is())
1727             {
1728                 aMatch += String(evt.Id->getContentIdentifier());
1729                 if (evt.Content.is())
1730                 {
1731                     aMatch.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" - "));
1732                     aMatch += String(evt.Content->getContentType());
1733                 }
1734             }
1735             else
1736                 aMatch.AppendAscii(RTL_CONSTASCII_STRINGPARAM("<no id>"));
1737             print(aMatch);
1738             break;
1739         }
1740 
1741         default:
1742             print( "contentEvent..." );
1743             break;
1744     }
1745 }
1746 
1747 //----------------------------------------------------------------------------
1748 //
1749 // XPropertiesChangeListener methods.
1750 //
1751 //----------------------------------------------------------------------------
1752 
1753 // virtual
1754 void SAL_CALL UcbContent::propertiesChange(
1755                     const uno::Sequence< beans::PropertyChangeEvent >& evt )
1756     throw( uno::RuntimeException )
1757 {
1758     print( "propertiesChange..." );
1759 
1760     sal_uInt32 nCount = evt.getLength();
1761     if ( nCount )
1762     {
1763         const beans::PropertyChangeEvent* pEvents = evt.getConstArray();
1764         for ( sal_uInt32 n = 0; n < nCount; ++n )
1765         {
1766             UniString aText( UniString::CreateFromAscii(
1767                                 RTL_CONSTASCII_STRINGPARAM( "    " ) ) );
1768             aText += UniString( pEvents[ n ].PropertyName );
1769             print( aText );
1770         }
1771     }
1772 }
1773 
1774 /*========================================================================
1775  *
1776  * MyWin.
1777  *
1778  *=======================================================================*/
1779 
1780 #define MYWIN_ITEMID_CLEAR          1
1781 #define MYWIN_ITEMID_CREATE         2
1782 #define MYWIN_ITEMID_RELEASE        3
1783 #define MYWIN_ITEMID_COMMANDS       4
1784 #define MYWIN_ITEMID_PROPS          5
1785 #define MYWIN_ITEMID_ADD_PROP       6
1786 #define MYWIN_ITEMID_REMOVE_PROP    7
1787 #define MYWIN_ITEMID_GET_PROP       8
1788 #define MYWIN_ITEMID_SET_PROP       9
1789 #define MYWIN_ITEMID_OPEN           10
1790 #define MYWIN_ITEMID_OPEN_ALL       11
1791 #define MYWIN_ITEMID_UPDATE         12
1792 #define MYWIN_ITEMID_SYNCHRONIZE    13
1793 #define MYWIN_ITEMID_COPY           14
1794 #define MYWIN_ITEMID_MOVE           15
1795 #define MYWIN_ITEMID_DELETE         16
1796 #define MYWIN_ITEMID_SEARCH         17
1797 #define MYWIN_ITEMID_TIMING         18
1798 #define MYWIN_ITEMID_SORT           19
1799 #define MYWIN_ITEMID_FETCHSIZE      20
1800 #define MYWIN_ITEMID_SYS2URI        21
1801 #define MYWIN_ITEMID_URI2SYS        22
1802 #define MYWIN_ITEMID_OFFLINE        23
1803 #define MYWIN_ITEMID_ONLINE         24
1804 #define MYWIN_ITEMID_REORGANIZE     25
1805 
1806 //-------------------------------------------------------------------------
1807 class MyWin : public WorkWindow
1808 {
1809 private:
1810     ToolBox*            m_pTool;
1811     Edit*               m_pCmdEdit;
1812     MyOutWindow*        m_pOutEdit;
1813 
1814     Ucb         m_aUCB;
1815     UcbContent* m_pContent;
1816 
1817     sal_Int32 m_nFetchSize;
1818     bool m_bTiming;
1819     bool m_bSort;
1820 
1821 public:
1822     MyWin( Window *pParent, WinBits nWinStyle,
1823            uno::Reference< lang::XMultiServiceFactory >& rxFactory,
1824            rtl::OUString const & rConfigurationKey1,
1825            rtl::OUString const & rConfigurationKey2 );
1826     virtual ~MyWin();
1827 
1828     void Resize( void );
1829     DECL_LINK ( ToolBarHandler, ToolBox* );
1830 
1831     void print( const UniString& rText );
1832     void print( const sal_Char* pText );
1833 };
1834 
1835 //-------------------------------------------------------------------------
1836 MyWin::MyWin( Window *pParent, WinBits nWinStyle,
1837               uno::Reference< lang::XMultiServiceFactory >& rxFactory,
1838               rtl::OUString const & rConfigurationKey1,
1839               rtl::OUString const & rConfigurationKey2 )
1840 : WorkWindow( pParent, nWinStyle ),
1841   m_pTool( NULL ),
1842   m_pOutEdit( NULL ),
1843   m_aUCB( rxFactory, rConfigurationKey1, rConfigurationKey2 ),
1844   m_pContent( NULL ),
1845   m_nFetchSize( 0 ),
1846   m_bTiming( false ),
1847   m_bSort( false )
1848 {
1849     // ToolBox.
1850     m_pTool = new ToolBox( this, WB_3DLOOK | WB_BORDER  | WB_SCROLL );
1851 
1852     m_pTool->InsertItem ( MYWIN_ITEMID_CLEAR,
1853                           UniString::CreateFromAscii(
1854                             RTL_CONSTASCII_STRINGPARAM(
1855                                 "Clear" ) ) );
1856     m_pTool->SetHelpText( MYWIN_ITEMID_CLEAR,
1857                           UniString::CreateFromAscii(
1858                             RTL_CONSTASCII_STRINGPARAM(
1859                                 "Clear the Output Window" ) ) );
1860     m_pTool->InsertSeparator();
1861     m_pTool->InsertItem ( MYWIN_ITEMID_CREATE,
1862                           UniString::CreateFromAscii(
1863                             RTL_CONSTASCII_STRINGPARAM(
1864                                 "Create" ) ) );
1865     m_pTool->SetHelpText( MYWIN_ITEMID_CREATE,
1866                           UniString::CreateFromAscii(
1867                             RTL_CONSTASCII_STRINGPARAM(
1868                                 "Create a content" ) ) );
1869     m_pTool->InsertItem ( MYWIN_ITEMID_RELEASE,
1870                           UniString::CreateFromAscii(
1871                             RTL_CONSTASCII_STRINGPARAM(
1872                                 "Release" ) ) );
1873     m_pTool->SetHelpText( MYWIN_ITEMID_RELEASE,
1874                           UniString::CreateFromAscii(
1875                             RTL_CONSTASCII_STRINGPARAM(
1876                                 "Release current content" ) ) );
1877     m_pTool->InsertSeparator();
1878     m_pTool->InsertItem ( MYWIN_ITEMID_COMMANDS,
1879                           UniString::CreateFromAscii(
1880                             RTL_CONSTASCII_STRINGPARAM(
1881                                 "Commands" ) ) );
1882     m_pTool->SetHelpText( MYWIN_ITEMID_COMMANDS,
1883                           UniString::CreateFromAscii(
1884                             RTL_CONSTASCII_STRINGPARAM(
1885                                 "Get Commands supported by the content" ) ) );
1886     m_pTool->InsertItem ( MYWIN_ITEMID_PROPS,
1887                           UniString::CreateFromAscii(
1888                             RTL_CONSTASCII_STRINGPARAM(
1889                                 "Properties" ) ) );
1890     m_pTool->SetHelpText( MYWIN_ITEMID_PROPS,
1891                           UniString::CreateFromAscii(
1892                             RTL_CONSTASCII_STRINGPARAM(
1893                                 "Get Properties supported by the content" ) ) );
1894     m_pTool->InsertSeparator();
1895     m_pTool->InsertItem ( MYWIN_ITEMID_ADD_PROP,
1896                           UniString::CreateFromAscii(
1897                             RTL_CONSTASCII_STRINGPARAM(
1898                                 "addProperty" ) ) );
1899     m_pTool->SetHelpText( MYWIN_ITEMID_ADD_PROP,
1900                           UniString::CreateFromAscii(
1901                             RTL_CONSTASCII_STRINGPARAM(
1902                                 "Add a new string(!) property to the content. "
1903                                 "Type the property name in the entry field and "
1904                                 "push this button. The default value for the "
1905                                 "property will be set to the string 'DefaultValue'" ) ) );
1906     m_pTool->InsertItem ( MYWIN_ITEMID_REMOVE_PROP,
1907                           UniString::CreateFromAscii(
1908                             RTL_CONSTASCII_STRINGPARAM(
1909                                 "removeProperty" ) ) );
1910     m_pTool->SetHelpText( MYWIN_ITEMID_REMOVE_PROP,
1911                           UniString::CreateFromAscii(
1912                             RTL_CONSTASCII_STRINGPARAM(
1913                                 "Removes a property from the content. "
1914                                 "Type the property name in the entry field and "
1915                                 "push this button." ) ) );
1916     m_pTool->InsertItem ( MYWIN_ITEMID_GET_PROP,
1917                           UniString::CreateFromAscii(
1918                             RTL_CONSTASCII_STRINGPARAM(
1919                                 "getPropertyValue" ) ) );
1920     m_pTool->SetHelpText( MYWIN_ITEMID_GET_PROP,
1921                           UniString::CreateFromAscii(
1922                             RTL_CONSTASCII_STRINGPARAM(
1923                                 "Get a string(!) property value from the content. "
1924                                 "Type the property name in the entry field and "
1925                                 "push this button to obtain the value" ) ) );
1926     m_pTool->InsertItem ( MYWIN_ITEMID_SET_PROP,
1927                           UniString::CreateFromAscii(
1928                             RTL_CONSTASCII_STRINGPARAM(
1929                                 "setPropertyValue" ) ) );
1930     m_pTool->SetHelpText( MYWIN_ITEMID_SET_PROP,
1931                           UniString::CreateFromAscii(
1932                             RTL_CONSTASCII_STRINGPARAM(
1933                                 "Set a string(!) property value of the content."
1934                                 "Type the property name in the entry field and "
1935                                 "push this button to set the value to the string "
1936                                 "'NewValue'" ) ) );
1937     m_pTool->InsertSeparator();
1938     m_pTool->InsertItem ( MYWIN_ITEMID_OPEN,
1939                           UniString::CreateFromAscii(
1940                             RTL_CONSTASCII_STRINGPARAM(
1941                                 "Open" ) ) );
1942     m_pTool->SetHelpText( MYWIN_ITEMID_OPEN,
1943                           UniString::CreateFromAscii(
1944                             RTL_CONSTASCII_STRINGPARAM(
1945                                 "Open the content" ) ) );
1946     m_pTool->InsertItem ( MYWIN_ITEMID_OPEN_ALL,
1947                           UniString::CreateFromAscii(
1948                             RTL_CONSTASCII_STRINGPARAM(
1949                                 "Open All" ) ) );
1950     m_pTool->SetHelpText( MYWIN_ITEMID_OPEN_ALL,
1951                           UniString::CreateFromAscii(
1952                             RTL_CONSTASCII_STRINGPARAM(
1953                                 "Open the content and all of its"
1954                                     " children" ) ) );
1955     m_pTool->InsertItem ( MYWIN_ITEMID_UPDATE,
1956                           UniString::CreateFromAscii(
1957                             RTL_CONSTASCII_STRINGPARAM(
1958                                 "Update" ) ) );
1959     m_pTool->SetHelpText( MYWIN_ITEMID_UPDATE,
1960                           UniString::CreateFromAscii(
1961                             RTL_CONSTASCII_STRINGPARAM(
1962                                 "Update the content" ) ) );
1963     m_pTool->InsertItem ( MYWIN_ITEMID_SYNCHRONIZE,
1964                           UniString::CreateFromAscii(
1965                             RTL_CONSTASCII_STRINGPARAM(
1966                                 "Synchronize" ) ) );
1967     m_pTool->SetHelpText( MYWIN_ITEMID_SYNCHRONIZE,
1968                           UniString::CreateFromAscii(
1969                             RTL_CONSTASCII_STRINGPARAM(
1970                                 "Synchronize the content" ) ) );
1971     m_pTool->InsertItem ( MYWIN_ITEMID_SEARCH,
1972                           UniString::CreateFromAscii(
1973                             RTL_CONSTASCII_STRINGPARAM(
1974                                 "Search" ) ) );
1975     m_pTool->SetHelpText( MYWIN_ITEMID_SEARCH,
1976                           UniString::CreateFromAscii(
1977                             RTL_CONSTASCII_STRINGPARAM(
1978                                 "Search the content" ) ) );
1979 
1980     m_pTool->InsertItem ( MYWIN_ITEMID_REORGANIZE,
1981                           UniString::CreateFromAscii(
1982                             RTL_CONSTASCII_STRINGPARAM(
1983                                 "Reorganize" ) ) );
1984     m_pTool->SetHelpText( MYWIN_ITEMID_REORGANIZE,
1985                           UniString::CreateFromAscii(
1986                             RTL_CONSTASCII_STRINGPARAM(
1987                                 "Reorganize the content storage" ) ) );
1988 
1989     m_pTool->InsertSeparator();
1990     m_pTool->InsertItem ( MYWIN_ITEMID_COPY,
1991                           UniString::CreateFromAscii(
1992                             RTL_CONSTASCII_STRINGPARAM(
1993                                 "Copy" ) ) );
1994     m_pTool->SetHelpText( MYWIN_ITEMID_COPY,
1995                           UniString::CreateFromAscii(
1996                             RTL_CONSTASCII_STRINGPARAM(
1997                                 "Copy a content. Type the URL of the source "
1998                                 "content into the entry field." ) ) );
1999     m_pTool->InsertItem ( MYWIN_ITEMID_MOVE,
2000                           UniString::CreateFromAscii(
2001                             RTL_CONSTASCII_STRINGPARAM(
2002                                 "Move" ) ) );
2003     m_pTool->SetHelpText( MYWIN_ITEMID_MOVE,
2004                           UniString::CreateFromAscii(
2005                             RTL_CONSTASCII_STRINGPARAM(
2006                                 "Move a content. Type the URL of the source "
2007                                 "content into the entry field." ) ) );
2008     m_pTool->InsertItem ( MYWIN_ITEMID_DELETE,
2009                           UniString::CreateFromAscii(
2010                             RTL_CONSTASCII_STRINGPARAM(
2011                                 "Delete" ) ) );
2012     m_pTool->SetHelpText( MYWIN_ITEMID_DELETE,
2013                           UniString::CreateFromAscii(
2014                             RTL_CONSTASCII_STRINGPARAM(
2015                                 "Delete the content." ) ) );
2016 
2017     m_pTool->InsertSeparator();
2018     m_pTool->InsertItem ( MYWIN_ITEMID_TIMING,
2019                           UniString::CreateFromAscii(
2020                             RTL_CONSTASCII_STRINGPARAM(
2021                                 "Timing" ) ),
2022                           TIB_CHECKABLE | TIB_AUTOCHECK );
2023     m_pTool->SetHelpText( MYWIN_ITEMID_TIMING,
2024                           UniString::CreateFromAscii(
2025                             RTL_CONSTASCII_STRINGPARAM(
2026                                 "Display execution times instead of"
2027                                     " output" ) ) );
2028     m_pTool->InsertItem ( MYWIN_ITEMID_SORT,
2029                           UniString::CreateFromAscii(
2030                             RTL_CONSTASCII_STRINGPARAM(
2031                                 "Sort" ) ),
2032                           TIB_CHECKABLE | TIB_AUTOCHECK );
2033     m_pTool->SetHelpText( MYWIN_ITEMID_SORT,
2034                           UniString::CreateFromAscii(
2035                             RTL_CONSTASCII_STRINGPARAM(
2036                                 "Sort result sets" ) ) );
2037     m_pTool->InsertItem ( MYWIN_ITEMID_FETCHSIZE,
2038                           UniString::CreateFromAscii(
2039                             RTL_CONSTASCII_STRINGPARAM(
2040                                 "Fetch Size" ) ) );
2041     m_pTool->SetHelpText( MYWIN_ITEMID_FETCHSIZE,
2042                           UniString::CreateFromAscii(
2043                             RTL_CONSTASCII_STRINGPARAM(
2044                                 "Set cached cursor fetch size to positive value" ) ) );
2045 
2046     m_pTool->InsertSeparator();
2047     m_pTool->InsertItem ( MYWIN_ITEMID_SYS2URI,
2048                           UniString::CreateFromAscii(
2049                             RTL_CONSTASCII_STRINGPARAM(
2050                                 "UNC>URI" ) ) );
2051     m_pTool->SetHelpText( MYWIN_ITEMID_SYS2URI,
2052                           UniString::CreateFromAscii(
2053                             RTL_CONSTASCII_STRINGPARAM(
2054                                 "Translate 'System File Path' to URI,"
2055                                     " if possible" ) ) );
2056     m_pTool->InsertItem ( MYWIN_ITEMID_URI2SYS,
2057                           UniString::CreateFromAscii(
2058                             RTL_CONSTASCII_STRINGPARAM(
2059                                 "URI>UNC" ) ) );
2060     m_pTool->SetHelpText( MYWIN_ITEMID_URI2SYS,
2061                           UniString::CreateFromAscii(
2062                             RTL_CONSTASCII_STRINGPARAM(
2063                                 "Translate URI to 'System File Path',"
2064                                     " if possible" ) ) );
2065 
2066     m_pTool->InsertSeparator();
2067     m_pTool->InsertItem ( MYWIN_ITEMID_OFFLINE,
2068                           UniString::CreateFromAscii(
2069                             RTL_CONSTASCII_STRINGPARAM(
2070                                 "Offline" ) ) );
2071     m_pTool->SetHelpText( MYWIN_ITEMID_OFFLINE,
2072                           UniString::CreateFromAscii(
2073                             RTL_CONSTASCII_STRINGPARAM(
2074                                 "Go offline" ) ) );
2075     m_pTool->InsertItem ( MYWIN_ITEMID_ONLINE,
2076                           UniString::CreateFromAscii(
2077                             RTL_CONSTASCII_STRINGPARAM(
2078                                 "Online" ) ) );
2079     m_pTool->SetHelpText( MYWIN_ITEMID_ONLINE,
2080                           UniString::CreateFromAscii(
2081                             RTL_CONSTASCII_STRINGPARAM(
2082                                 "Go back online" ) ) );
2083 
2084     m_pTool->SetSelectHdl( LINK( this, MyWin, ToolBarHandler ) );
2085     m_pTool->Show();
2086 
2087     // Edit.
2088     m_pCmdEdit = new Edit( this );
2089     m_pCmdEdit->SetReadOnly( FALSE );
2090     m_pCmdEdit->SetText( UniString::CreateFromAscii(
2091                             RTL_CONSTASCII_STRINGPARAM( "file:///" ) ) );
2092     m_pCmdEdit->Show();
2093 
2094     // MyOutWindow.
2095     m_pOutEdit = new MyOutWindow( this, WB_HSCROLL | WB_VSCROLL | WB_BORDER );
2096     m_pOutEdit->SetReadOnly( TRUE );
2097     m_pOutEdit->Show();
2098 
2099     m_aUCB.setOutEdit( m_pOutEdit );
2100 }
2101 
2102 //-------------------------------------------------------------------------
2103 // virtual
2104 MyWin::~MyWin()
2105 {
2106     if ( m_pContent )
2107     {
2108         m_pContent->dispose();
2109         m_pContent->release();
2110     }
2111 
2112     delete m_pTool;
2113     delete m_pCmdEdit;
2114     delete m_pOutEdit;
2115 }
2116 
2117 //-------------------------------------------------------------------------
2118 void MyWin::Resize()
2119 {
2120     Size aWinSize = GetOutputSizePixel();
2121     int nWinW = aWinSize.Width();
2122     int nWinH = aWinSize.Height();
2123     int nBoxH = m_pTool->CalcWindowSizePixel().Height();
2124 
2125     m_pTool->SetPosSizePixel   (
2126         Point( 0, 0 ), Size ( nWinW, nBoxH ) );
2127     m_pCmdEdit->SetPosSizePixel(
2128         Point( 0, nBoxH ), Size( nWinW, nBoxH ) );
2129     m_pOutEdit->SetPosSizePixel(
2130         Point( 0, nBoxH + nBoxH ), Size ( nWinW, nWinH - ( nBoxH + nBoxH ) ) );
2131 }
2132 
2133 //-------------------------------------------------------------------------
2134 void MyWin::print( const sal_Char* pText )
2135 {
2136     print( UniString::CreateFromAscii( pText ) );
2137 }
2138 
2139 //-------------------------------------------------------------------------
2140 void MyWin::print( const UniString& rText )
2141 {
2142     vos::OGuard aGuard( Application::GetSolarMutex() );
2143 
2144     if ( m_pOutEdit )
2145     {
2146         m_pOutEdit->Append( rText );
2147         m_pOutEdit->Update();
2148     }
2149 }
2150 
2151 //-------------------------------------------------------------------------
2152 IMPL_LINK( MyWin, ToolBarHandler, ToolBox*, pToolBox )
2153 {
2154     USHORT nItemId   = pToolBox->GetCurItemId();
2155     UniString aCmdLine = m_pCmdEdit->GetText();
2156 
2157     ULONG n = Application::ReleaseSolarMutex();
2158 
2159     switch( nItemId )
2160     {
2161         case MYWIN_ITEMID_CLEAR:
2162         {
2163             vos::OGuard aGuard( Application::GetSolarMutex() );
2164 
2165             m_pOutEdit->Clear();
2166             m_pOutEdit->Show();
2167             break;
2168         }
2169 
2170         case MYWIN_ITEMID_CREATE:
2171             if ( m_pContent )
2172             {
2173                 UniString aText( UniString::CreateFromAscii(
2174                                     RTL_CONSTASCII_STRINGPARAM(
2175                                         "Content released: " ) ) );
2176                 aText += m_pContent->getURL();
2177 
2178                 m_pContent->dispose();
2179                 m_pContent->release();
2180                 m_pContent = NULL;
2181 
2182                 print( aText );
2183             }
2184 
2185             m_pContent = UcbContent::create( m_aUCB, aCmdLine, m_pOutEdit );
2186             if ( m_pContent )
2187             {
2188                 String aText( UniString::CreateFromAscii(
2189                                 RTL_CONSTASCII_STRINGPARAM(
2190                                     "Created content: " ) ) );
2191                 aText += String( m_pContent->getURL() );
2192                 aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ) );
2193                 aText += String( m_pContent->getType() );
2194                 print( aText );
2195             }
2196             else
2197             {
2198                 String aText( UniString::CreateFromAscii(
2199                                 RTL_CONSTASCII_STRINGPARAM(
2200                                     "Creation failed for content: " ) ) );
2201                 aText += String( aCmdLine );
2202                 print( aText );
2203             }
2204             break;
2205 
2206         case MYWIN_ITEMID_RELEASE:
2207             if ( m_pContent )
2208             {
2209                 UniString aText( UniString::CreateFromAscii(
2210                                     RTL_CONSTASCII_STRINGPARAM(
2211                                         "Content released: " ) ) );
2212                 aText += m_pContent->getURL();
2213 
2214                 m_pContent->dispose();
2215                 m_pContent->release();
2216                 m_pContent = NULL;
2217 
2218                 print( aText );
2219             }
2220             else
2221                 print( "No content!" );
2222 
2223             break;
2224 
2225         case MYWIN_ITEMID_COMMANDS:
2226             if ( m_pContent )
2227                 m_pContent->getCommands();
2228             else
2229                 print( "No content!" );
2230 
2231             break;
2232 
2233         case MYWIN_ITEMID_PROPS:
2234             if ( m_pContent )
2235                 m_pContent->getProperties();
2236             else
2237                 print( "No content!" );
2238 
2239             break;
2240 
2241         case MYWIN_ITEMID_ADD_PROP:
2242             if ( m_pContent )
2243                 m_pContent->addStringProperty(
2244                         aCmdLine,
2245                         rtl::OUString::createFromAscii( "DefaultValue" ) );
2246             else
2247                 print( "No content!" );
2248 
2249             break;
2250 
2251         case MYWIN_ITEMID_REMOVE_PROP:
2252             if ( m_pContent )
2253                 m_pContent->removeProperty( aCmdLine );
2254             else
2255                 print( "No content!" );
2256 
2257             break;
2258 
2259         case MYWIN_ITEMID_GET_PROP:
2260             if ( m_pContent )
2261                 m_pContent->getStringPropertyValue( aCmdLine );
2262             else
2263                 print( "No content!" );
2264 
2265             break;
2266 
2267         case MYWIN_ITEMID_SET_PROP:
2268             if ( m_pContent )
2269                 m_pContent->setStringPropertyValue(
2270                                 aCmdLine,
2271                                 rtl::OUString::createFromAscii( "NewValue" ) );
2272             else
2273                 print( "No content!" );
2274 
2275             break;
2276 
2277         case MYWIN_ITEMID_OPEN:
2278             if ( m_pContent )
2279                 m_pContent->open(rtl::OUString::createFromAscii("open"),
2280                                  aCmdLine, !m_bTiming, m_bTiming, m_bSort, 0,
2281                                  0, m_nFetchSize);
2282             else
2283                 print( "No content!" );
2284 
2285             break;
2286 
2287         case MYWIN_ITEMID_OPEN_ALL:
2288             if ( m_pContent )
2289                 m_pContent->openAll(m_aUCB, !m_bTiming, m_bTiming, m_bSort,
2290                                     m_nFetchSize);
2291             else
2292                 print( "No content!" );
2293 
2294             break;
2295 
2296         case MYWIN_ITEMID_UPDATE:
2297             if ( m_pContent )
2298                 m_pContent->open(rtl::OUString::createFromAscii("update"),
2299                                  aCmdLine, !m_bTiming, m_bTiming, m_bSort, 0,
2300                                  0, m_nFetchSize);
2301             else
2302                 print( "No content!" );
2303 
2304             break;
2305 
2306         case MYWIN_ITEMID_SYNCHRONIZE:
2307             if ( m_pContent )
2308                 m_pContent->open(rtl::OUString::createFromAscii("synchronize"),
2309                                  aCmdLine, !m_bTiming, m_bTiming, m_bSort, 0,
2310                                  0, m_nFetchSize);
2311             else
2312                 print( "No content!" );
2313 
2314             break;
2315 
2316         case MYWIN_ITEMID_SEARCH:
2317             if ( m_pContent )
2318                 m_pContent->open(rtl::OUString::createFromAscii("search"),
2319                                  aCmdLine, !m_bTiming, m_bTiming, m_bSort, 0,
2320                                  0, m_nFetchSize);
2321             else
2322                 print( "No content!" );
2323 
2324             break;
2325 
2326         case MYWIN_ITEMID_REORGANIZE:
2327             if ( m_pContent )
2328                 m_pContent->executeCommand (
2329                     rtl::OUString::createFromAscii ("reorganizeData"),
2330                     uno::Any());
2331             else
2332                 print( "No content!" );
2333 
2334             break;
2335 
2336         case MYWIN_ITEMID_COPY:
2337             if ( m_pContent )
2338                 m_pContent->transfer( aCmdLine, sal_False );
2339             else
2340                 print( "No content!" );
2341 
2342             break;
2343 
2344         case MYWIN_ITEMID_MOVE:
2345             if ( m_pContent )
2346                 m_pContent->transfer( aCmdLine, sal_True );
2347             else
2348                 print( "No content!" );
2349 
2350             break;
2351 
2352         case MYWIN_ITEMID_DELETE:
2353             if ( m_pContent )
2354                 m_pContent->destroy();
2355             else
2356                 print( "No content!" );
2357 
2358             break;
2359 
2360         case MYWIN_ITEMID_TIMING:
2361             m_bTiming = m_pTool->IsItemChecked(MYWIN_ITEMID_TIMING) != false;
2362             break;
2363 
2364         case MYWIN_ITEMID_SORT:
2365             m_bSort = m_pTool->IsItemChecked(MYWIN_ITEMID_SORT) != false;
2366             break;
2367 
2368         case MYWIN_ITEMID_FETCHSIZE:
2369         {
2370             m_nFetchSize = aCmdLine.ToInt32();
2371             String aText;
2372             if (m_nFetchSize > 0)
2373             {
2374                 aText.AssignAscii("Fetch size set to ");
2375                 aText += String::CreateFromInt32(m_nFetchSize);
2376             }
2377             else
2378                 aText.AssignAscii("Fetch size reset to default");
2379             print(aText);
2380             break;
2381         }
2382 
2383         case MYWIN_ITEMID_SYS2URI:
2384         {
2385             uno::Reference< ucb::XContentProviderManager >
2386                 xManager(m_aUCB.getContentProvider(), uno::UNO_QUERY);
2387             DBG_ASSERT(xManager.is(),
2388                        "MyWin::ToolBarHandler(): Service lacks interface");
2389 
2390             rtl::OUString aURL(getLocalFileURL(xManager));
2391 
2392             String aText(RTL_CONSTASCII_USTRINGPARAM("Local file URL: "));
2393             aText += String(aURL);
2394             aText.AppendAscii("\nConversion: ");
2395             aText += aCmdLine;
2396             aText.AppendAscii(" to ");
2397             aText += String(getFileURLFromSystemPath(xManager,
2398                                                           aURL,
2399                                                           aCmdLine));
2400             print(aText);
2401             break;
2402         }
2403 
2404         case MYWIN_ITEMID_URI2SYS:
2405         {
2406             uno::Reference< ucb::XContentProviderManager >
2407                 xManager(m_aUCB.getContentProvider(), uno::UNO_QUERY);
2408             DBG_ASSERT(xManager.is(),
2409                        "MyWin::ToolBarHandler(): Service lacks interface");
2410 
2411             String aText(RTL_CONSTASCII_USTRINGPARAM("Conversion: "));
2412             aText += aCmdLine;
2413             aText.AppendAscii(" to ");
2414             aText += String(getSystemPathFromFileURL(xManager,
2415                                                           aCmdLine));
2416             print(aText);
2417             break;
2418         }
2419 
2420         case MYWIN_ITEMID_OFFLINE:
2421         case MYWIN_ITEMID_ONLINE:
2422         {
2423             uno::Reference< ucb::XContentProviderManager >
2424                 xManager(m_aUCB.getContentProvider(), uno::UNO_QUERY);
2425             uno::Reference< ucb::XCommandProcessor > xProcessor;
2426             if (xManager.is())
2427                 xProcessor
2428                     = uno::Reference< ucb::XCommandProcessor >(
2429                         xManager->queryContentProvider(aCmdLine),
2430                         uno::UNO_QUERY);
2431             if (!xProcessor.is())
2432             {
2433                 String aText(RTL_CONSTASCII_USTRINGPARAM(
2434                                  "No offline support for URL "));
2435                 aText += aCmdLine;
2436                 print(aText);
2437                 break;
2438             }
2439 
2440             rtl::OUString aName;
2441             uno::Any aArgument;
2442             if (nItemId == MYWIN_ITEMID_OFFLINE)
2443             {
2444                 aName = rtl::OUString::createFromAscii("goOffline");
2445 
2446                 uno::Sequence<
2447                     uno::Reference< ucb::XContentIdentifier > >
2448                         aIdentifiers(1);
2449                 aIdentifiers[0]
2450                     = m_aUCB.getContentIdentifierFactory()->
2451                                  createContentIdentifier(aCmdLine);
2452                 aArgument <<= aIdentifiers;
2453             }
2454             else
2455                 aName = rtl::OUString::createFromAscii("goOnline");
2456 
2457             UcbCommandProcessor(m_aUCB, xProcessor, m_pOutEdit).
2458                 executeCommand(aName, aArgument);
2459             break;
2460         }
2461 
2462         default: // Ignored.
2463             break;
2464     }
2465 
2466     Application::AcquireSolarMutex( n );
2467     return 0;
2468 }
2469 
2470 /*========================================================================
2471  *
2472  * MyApp.
2473  *
2474  *=======================================================================*/
2475 class MyApp : public Application
2476 {
2477 public:
2478     virtual void Main();
2479 };
2480 
2481 MyApp aMyApp;
2482 
2483 //-------------------------------------------------------------------------
2484 // virtual
2485 void MyApp::Main()
2486 {
2487     //////////////////////////////////////////////////////////////////////
2488     // Read command line params.
2489     //////////////////////////////////////////////////////////////////////
2490 
2491     rtl::OUString aConfigurationKey1(rtl::OUString::createFromAscii(
2492                                          UCB_CONFIGURATION_KEY1_LOCAL));
2493     rtl::OUString aConfigurationKey2(rtl::OUString::createFromAscii(
2494                                          UCB_CONFIGURATION_KEY2_OFFICE));
2495 
2496     USHORT nParams = Application::GetCommandLineParamCount();
2497     for ( USHORT n = 0; n < nParams; ++n )
2498     {
2499         String aParam( Application::GetCommandLineParam( n ) );
2500         if (aParam.CompareIgnoreCaseToAscii("-key=",
2501                                             RTL_CONSTASCII_LENGTH("-key="))
2502                 == COMPARE_EQUAL)
2503         {
2504             xub_StrLen nSlash
2505                 = aParam.Search('/', RTL_CONSTASCII_LENGTH("-key="));
2506             if (nSlash == STRING_NOTFOUND)
2507             {
2508                 aConfigurationKey1
2509                     = aParam.Copy(RTL_CONSTASCII_LENGTH("-key="));
2510                 aConfigurationKey2 = rtl::OUString();
2511             }
2512             else
2513             {
2514                 aConfigurationKey1
2515                     = aParam.Copy(RTL_CONSTASCII_LENGTH("-key="),
2516                                   nSlash - RTL_CONSTASCII_LENGTH("-key="));
2517                 aConfigurationKey2
2518                     = aParam.Copy(nSlash + 1);
2519             }
2520         }
2521     }
2522 
2523     //////////////////////////////////////////////////////////////////////
2524     // Initialize local Service Manager and basic services.
2525     //////////////////////////////////////////////////////////////////////
2526 
2527     uno::Reference< lang::XMultiServiceFactory > xFac;
2528     try
2529     {
2530         uno::Reference< uno::XComponentContext > xCtx(
2531             cppu::defaultBootstrap_InitialComponentContext() );
2532         if ( !xCtx.is() )
2533         {
2534             DBG_ERROR( "Error creating initial component context!" );
2535             return;
2536         }
2537 
2538         xFac = uno::Reference< lang::XMultiServiceFactory >(
2539             xCtx->getServiceManager(), uno::UNO_QUERY );
2540 
2541         if ( !xFac.is() )
2542         {
2543             DBG_ERROR( "No service manager!" );
2544             return;
2545         }
2546     }
2547     catch ( uno::Exception )
2548     {
2549         DBG_ERROR( "Exception during creation of initial component context!" );
2550         return;
2551     }
2552 
2553     comphelper::setProcessServiceFactory( xFac );
2554 
2555     uno::Reference< lang::XComponent > xComponent( xFac, uno::UNO_QUERY );
2556 
2557     //////////////////////////////////////////////////////////////////////
2558     // Create Application Window...
2559     //////////////////////////////////////////////////////////////////////
2560 
2561     Help::EnableBalloonHelp();
2562 
2563     MyWin *pMyWin = new MyWin( NULL, WB_APP | WB_STDWORK, xFac,
2564                                aConfigurationKey1, aConfigurationKey2 );
2565 
2566     pMyWin->
2567         SetText(
2568             UniString::CreateFromAscii(
2569                 RTL_CONSTASCII_STRINGPARAM( "UCB Demo/Test Application" ) ) );
2570 
2571     pMyWin->SetPosSizePixel( 0, 0, 1024, 768 );
2572 
2573     pMyWin->Show();
2574 
2575     //////////////////////////////////////////////////////////////////////
2576     // Go...
2577     //////////////////////////////////////////////////////////////////////
2578 
2579     Execute();
2580 
2581     //////////////////////////////////////////////////////////////////////
2582     // Destroy Application Window...
2583     //////////////////////////////////////////////////////////////////////
2584 
2585     delete pMyWin;
2586 
2587     //////////////////////////////////////////////////////////////////////
2588     // Cleanup.
2589     //////////////////////////////////////////////////////////////////////
2590 
2591     ::ucbhelper::ContentBroker::deinitialize();
2592 
2593     // Dispose local service manager.
2594     if ( xComponent.is() )
2595         xComponent->dispose();
2596 }
2597 
2598