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