Update ooo320-m1
[ooovba.git] / sfx2 / source / bastyp / helper.cxx
blob80ac52b9027d9c82230bbad2c540178cf38c4225
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: helper.cxx,v $
10 * $Revision: 1.30 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include "helper.hxx"
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/sdbc/XResultSet.hpp>
37 #include <com/sun/star/sdbc/XRow.hpp>
38 #include <com/sun/star/ucb/CommandAbortedException.hpp>
39 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
40 #include <com/sun/star/ucb/NameClash.hpp>
41 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
42 #include <com/sun/star/ucb/TransferInfo.hpp>
43 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
44 #include <com/sun/star/ucb/XCommandInfo.hpp>
45 #include <com/sun/star/ucb/XContentAccess.hpp>
46 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
47 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
48 #include <com/sun/star/util/DateTime.hpp>
49 #include <com/sun/star/io/XInputStream.hpp>
50 #include <unotools/localedatawrapper.hxx>
51 #include <rtl/strbuf.hxx>
53 #include <tools/ref.hxx>
54 #include <tools/debug.hxx>
55 #include <tools/urlobj.hxx>
56 #include <tools/datetime.hxx>
57 #include <vcl/svapp.hxx>
58 #include <ucbhelper/content.hxx>
59 #include <ucbhelper/commandenvironment.hxx>
60 #include <comphelper/processfactory.hxx>
61 #include <osl/file.hxx>
63 using namespace com::sun::star;
64 using namespace rtl;
65 using namespace comphelper;
66 using namespace osl;
68 DECLARE_LIST( StringList_Impl, OUString* )
70 #define CONVERT_DATETIME( aUnoDT, aToolsDT ) \
71 aToolsDT = DateTime( Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ), \
72 Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ) );
74 void AppendDateTime_Impl( const util::DateTime rDT,
75 String& rRow, const LocaleDataWrapper& rWrapper )
77 DateTime aDT;
78 CONVERT_DATETIME( rDT, aDT );
79 String aDateStr = rWrapper.getDate( aDT );
80 aDateStr += String::CreateFromAscii( ", " );
81 aDateStr += rWrapper.getTime( aDT );
82 rRow += aDateStr;
85 // SfxContentHelper ------------------------------------------------------
87 sal_Bool SfxContentHelper::Transfer_Impl( const String& rSource, const String& rDest, sal_Bool bMoveData, sal_Int32 nNameClash )
89 sal_Bool bRet = sal_True, bKillSource = sal_False;
90 INetURLObject aSourceObj( rSource );
91 DBG_ASSERT( aSourceObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
93 INetURLObject aDestObj( rDest );
94 DBG_ASSERT( aDestObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
95 if ( bMoveData && aSourceObj.GetProtocol() != aDestObj.GetProtocol() )
97 bMoveData = sal_False;
98 bKillSource = sal_True;
100 String aName = aDestObj.getName();
101 aDestObj.removeSegment();
102 aDestObj.setFinalSlash();
106 ::ucbhelper::Content aDestPath( aDestObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
107 uno::Reference< ucb::XCommandInfo > xInfo = aDestPath.getCommands();
108 OUString aTransferName = OUString::createFromAscii( "transfer" );
109 if ( xInfo->hasCommandByName( aTransferName ) )
111 aDestPath.executeCommand( aTransferName, uno::makeAny(
112 ucb::TransferInfo( bMoveData, aSourceObj.GetMainURL( INetURLObject::NO_DECODE ), aName, nNameClash ) ) );
114 else
116 DBG_ERRORFILE( "transfer command not available" );
119 catch( ucb::CommandAbortedException& )
121 bRet = sal_False;
123 catch( uno::Exception& )
125 DBG_ERRORFILE( "Any other exception" );
126 bRet = sal_False;
129 if ( bKillSource )
130 SfxContentHelper::Kill( rSource );
132 return bRet;
135 // -----------------------------------------------------------------------
137 sal_Bool SfxContentHelper::IsDocument( const String& rContent )
139 sal_Bool bRet = sal_False;
140 INetURLObject aObj( rContent );
141 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
145 ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
146 bRet = aCnt.isDocument();
148 catch( ucb::CommandAbortedException& )
150 DBG_WARNING( "CommandAbortedException" );
152 catch( ucb::IllegalIdentifierException& )
154 DBG_WARNING( "IllegalIdentifierException" );
156 catch( ucb::ContentCreationException& )
158 DBG_WARNING( "IllegalIdentifierException" );
160 catch( uno::Exception& )
162 DBG_ERRORFILE( "Any other exception" );
165 return bRet;
168 // -----------------------------------------------------------------------
170 sal_Bool SfxContentHelper::IsFolder( const String& rContent )
172 sal_Bool bRet = sal_False;
173 INetURLObject aObj( rContent );
174 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
177 ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
178 bRet = aCnt.isFolder();
180 catch( ucb::CommandAbortedException& )
182 DBG_WARNING( "CommandAbortedException" );
184 catch( ucb::IllegalIdentifierException& )
186 DBG_WARNING( "IllegalIdentifierException" );
188 catch( ucb::ContentCreationException& )
190 DBG_WARNING( "IllegalIdentifierException" );
192 catch( uno::Exception& )
194 DBG_ERRORFILE( "Any other exception" );
197 return bRet;
200 // -----------------------------------------------------------------------
202 sal_Bool SfxContentHelper::GetTitle( const String& rContent, String& rTitle )
204 sal_Bool bRet = sal_False;
205 INetURLObject aObj( rContent );
206 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
209 ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
210 OUString aTemp;
211 aCnt.getPropertyValue( OUString::createFromAscii( "Title" ) ) >>= aTemp;
212 rTitle = String( aTemp );
213 bRet = sal_True;
215 catch( ucb::CommandAbortedException& )
217 DBG_ERRORFILE( "CommandAbortedException" );
219 catch( uno::Exception& )
221 DBG_ERRORFILE( "Any other exception" );
223 return bRet;
226 // -----------------------------------------------------------------------
228 sal_Bool SfxContentHelper::Kill( const String& rContent )
230 sal_Bool bRet = sal_True;
231 INetURLObject aDeleteObj( rContent );
232 DBG_ASSERT( aDeleteObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
236 ::ucbhelper::Content aCnt( aDeleteObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
237 aCnt.executeCommand( OUString::createFromAscii( "delete" ), uno::makeAny( sal_Bool( sal_True ) ) );
239 catch( ucb::CommandAbortedException& )
241 DBG_WARNING( "CommandAbortedException" );
242 bRet = sal_False;
244 catch( uno::Exception& )
246 DBG_ERRORFILE( "Any other exception" );
247 bRet = sal_False;
250 return bRet;
253 // -----------------------------------------------------------------------
255 uno::Sequence < OUString > SfxContentHelper::GetFolderContents( const String& rFolder, sal_Bool bFolder, sal_Bool bSorted )
257 StringList_Impl* pFiles = NULL;
258 INetURLObject aFolderObj( rFolder );
259 DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
262 ::ucbhelper::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
263 uno::Reference< sdbc::XResultSet > xResultSet;
264 uno::Sequence< OUString > aProps(2);
265 OUString* pProps = aProps.getArray();
266 pProps[0] = OUString::createFromAscii( "Title" );
267 pProps[1] = OUString::createFromAscii( "IsFolder" );
271 ::ucbhelper::ResultSetInclude eInclude = bFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY;
272 if ( !bSorted )
274 xResultSet = aCnt.createCursor( aProps, eInclude );
276 else
278 uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
279 xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude );
281 uno::Reference < ucb::XAnyCompareFactory > xFactory;
282 uno::Reference < lang::XMultiServiceFactory > xMgr = getProcessServiceFactory();
283 uno::Reference < ucb::XSortedDynamicResultSetFactory > xSRSFac(
284 xMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SortedDynamicResultSetFactory") ), uno::UNO_QUERY );
286 uno::Sequence< ucb::NumberedSortingInfo > aSortInfo( 2 );
287 ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray();
288 pInfo[ 0 ].ColumnIndex = 2;
289 pInfo[ 0 ].Ascending = sal_False;
290 pInfo[ 1 ].ColumnIndex = 1;
291 pInfo[ 1 ].Ascending = sal_True;
293 uno::Reference< ucb::XDynamicResultSet > xDynamicResultSet;
294 xDynamicResultSet =
295 xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xFactory );
296 if ( xDynamicResultSet.is() )
298 xResultSet = xDynamicResultSet->getStaticResultSet();
302 catch( ucb::CommandAbortedException& )
304 DBG_ERRORFILE( "createCursor: CommandAbortedException" );
306 catch( uno::Exception& )
308 DBG_ERRORFILE( "createCursor: Any other exception" );
311 if ( xResultSet.is() )
313 pFiles = new StringList_Impl;
314 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
317 while ( xResultSet->next() )
319 OUString aId = xContentAccess->queryContentIdentifierString();
320 OUString* pFile = new OUString( aId );
321 pFiles->Insert( pFile, LIST_APPEND );
324 catch( ucb::CommandAbortedException& )
326 DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" );
328 catch( uno::Exception& )
330 DBG_ERRORFILE( "XContentAccess::next(): Any other exception" );
334 catch( uno::Exception& )
336 DBG_ERRORFILE( "GetFolderContents: Any other exception" );
339 if ( pFiles )
341 ULONG nCount = pFiles->Count();
342 uno::Sequence < OUString > aRet( nCount );
343 OUString* pRet = aRet.getArray();
344 for ( ULONG i = 0; i < nCount; ++i )
346 OUString* pFile = pFiles->GetObject(i);
347 pRet[i] = *( pFile );
348 delete pFile;
350 delete pFiles;
351 return aRet;
353 else
354 return uno::Sequence < OUString > ();
357 // -----------------------------------------------------------------------
359 uno::Sequence < OUString > SfxContentHelper::GetFolderContentProperties( const String& rFolder, sal_Bool bIsFolder )
361 StringList_Impl* pProperties = NULL;
362 INetURLObject aFolderObj( rFolder );
363 DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
366 uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
367 uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
368 xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY );
370 ::ucbhelper::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
371 uno::Reference< sdbc::XResultSet > xResultSet;
372 uno::Sequence< OUString > aProps(5);
373 OUString* pProps = aProps.getArray();
374 pProps[0] = OUString::createFromAscii( "Title" );
375 pProps[1] = OUString::createFromAscii( "ContentType" );
376 pProps[2] = OUString::createFromAscii( "Size" );
377 pProps[3] = OUString::createFromAscii( "DateModified" );
378 pProps[4] = OUString::createFromAscii( "IsFolder" );
382 uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
383 ::ucbhelper::ResultSetInclude eInclude = bIsFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY;
384 xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude );
386 uno::Reference < ucb::XAnyCompareFactory > xCmpFactory;
387 uno::Reference < lang::XMultiServiceFactory > xMgr = getProcessServiceFactory();
388 uno::Reference < ucb::XSortedDynamicResultSetFactory > xSRSFac(
389 xMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SortedDynamicResultSetFactory") ), uno::UNO_QUERY );
391 uno::Sequence< ucb::NumberedSortingInfo > aSortInfo( 2 );
392 ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray();
393 pInfo[ 0 ].ColumnIndex = 5;
394 pInfo[ 0 ].Ascending = sal_False;
395 pInfo[ 1 ].ColumnIndex = 1;
396 pInfo[ 1 ].Ascending = sal_True;
398 uno::Reference< ucb::XDynamicResultSet > xDynamicResultSet;
399 xDynamicResultSet =
400 xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xCmpFactory );
401 if ( xDynamicResultSet.is() )
403 xResultSet = xDynamicResultSet->getStaticResultSet();
406 // if ( xDynResultSet.is() )
407 // xResultSet = xDynResultSet->getStaticResultSet();
409 catch( ucb::CommandAbortedException& )
411 DBG_ERRORFILE( "createCursor: CommandAbortedException" );
413 catch( uno::Exception& )
415 DBG_ERRORFILE( "createCursor: Any other exception" );
418 if ( xResultSet.is() )
420 LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
421 pProperties = new StringList_Impl;
422 uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
423 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
424 ULONG nFolderPos = LIST_APPEND;
428 while ( xResultSet->next() )
430 String aTitle( xRow->getString(1) );
431 String aType( xRow->getString(2) );
432 sal_Int64 nSize = xRow->getLong(3);
433 util::DateTime aDT = xRow->getTimestamp(4);
434 sal_Bool bFolder = xRow->getBoolean(5);
436 String aRow = aTitle;
437 aRow += '\t';
438 //! aRow += aType;
439 //! aRow += '\t';
440 aRow += String::CreateFromInt64( nSize );
441 aRow += '\t';
442 AppendDateTime_Impl( aDT, aRow, aLocaleWrapper );
443 aRow += '\t';
444 aRow += String( xContentAccess->queryContentIdentifierString() );
445 aRow += '\t';
446 aRow += bFolder ? '1' : '0';
447 OUString* pRow = new OUString( aRow );
448 ULONG nPos = LIST_APPEND;
449 if ( bFolder )
451 if ( LIST_APPEND == nFolderPos )
452 nFolderPos = 0;
453 else
454 nFolderPos++;
455 nPos = nFolderPos;
457 pProperties->Insert( pRow, nPos );
460 catch( ucb::CommandAbortedException& )
462 DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" );
464 catch( uno::Exception& )
466 DBG_ERRORFILE( "XContentAccess::next(): Any other exception" );
470 catch( uno::Exception& )
472 DBG_ERRORFILE( "GetFolderContents: Any other exception" );
475 if ( pProperties )
477 ULONG nCount = pProperties->Count();
478 uno::Sequence < OUString > aRet( nCount );
479 OUString* pRet = aRet.getArray();
480 for ( ULONG i = 0; i < nCount; ++i )
482 OUString* pProperty = pProperties->GetObject(i);
483 pRet[i] = *( pProperty );
484 delete pProperty;
486 delete pProperties;
487 return aRet;
489 else
490 return uno::Sequence < OUString > ();
493 // -----------------------------------------------------------------------
495 uno::Sequence < OUString > SfxContentHelper::GetResultSet( const String& rURL )
497 StringList_Impl* pList = NULL;
500 ::ucbhelper::Content aCnt( rURL, uno::Reference< ucb::XCommandEnvironment >() );
501 uno::Reference< sdbc::XResultSet > xResultSet;
502 uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
503 uno::Sequence< OUString > aProps(3);
504 OUString* pProps = aProps.getArray();
505 pProps[0] = OUString::createFromAscii( "Title" );
506 pProps[1] = OUString::createFromAscii( "ContentType" );
507 pProps[2] = OUString::createFromAscii( "IsFolder" );
511 xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
512 if ( xDynResultSet.is() )
513 xResultSet = xDynResultSet->getStaticResultSet();
515 catch( ucb::CommandAbortedException& )
517 DBG_ERRORFILE( "createCursor: CommandAbortedException" );
519 catch( uno::Exception& )
521 DBG_ERRORFILE( "createCursor: Any other exception" );
524 if ( xResultSet.is() )
526 pList = new StringList_Impl;
527 uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
528 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
532 while ( xResultSet->next() )
534 String aTitle( xRow->getString(1) );
535 String aType( xRow->getString(2) );
536 String aRow = aTitle;
537 aRow += '\t';
538 aRow += aType;
539 aRow += '\t';
540 aRow += String( xContentAccess->queryContentIdentifierString() );
541 OUString* pRow = new OUString( aRow );
542 pList->Insert( pRow, LIST_APPEND );
545 catch( ucb::CommandAbortedException& )
547 DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" );
549 catch( uno::Exception& )
551 DBG_ERRORFILE( "XContentAccess::next(): Any other exception" );
555 catch( uno::Exception& )
557 DBG_ERRORFILE( "GetResultSet: Any other exception" );
560 if ( pList )
562 ULONG nCount = pList->Count();
563 uno::Sequence < OUString > aRet( nCount );
564 OUString* pRet = aRet.getArray();
565 for ( ULONG i = 0; i < nCount; ++i )
567 OUString* pEntry = pList->GetObject(i);
568 pRet[i] = *( pEntry );
569 delete pEntry;
571 delete pList;
572 return aRet;
574 else
575 return uno::Sequence < OUString > ();
578 // -----------------------------------------------------------------------
580 uno::Sequence< OUString > SfxContentHelper::GetHelpTreeViewContents( const String& rURL )
582 StringList_Impl* pProperties = NULL;
585 uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
586 uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
587 xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY );
589 ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
590 uno::Reference< sdbc::XResultSet > xResultSet;
591 uno::Sequence< OUString > aProps(2);
592 OUString* pProps = aProps.getArray();
593 pProps[0] = OUString::createFromAscii( "Title" );
594 pProps[1] = OUString::createFromAscii( "IsFolder" );
598 uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
599 xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
600 if ( xDynResultSet.is() )
601 xResultSet = xDynResultSet->getStaticResultSet();
603 catch( ucb::CommandAbortedException& )
606 catch( uno::Exception& )
610 if ( xResultSet.is() )
612 pProperties = new StringList_Impl;
613 uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
614 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
618 while ( xResultSet->next() )
620 String aTitle( xRow->getString(1) );
621 sal_Bool bFolder = xRow->getBoolean(2);
622 String aRow = aTitle;
623 aRow += '\t';
624 aRow += String( xContentAccess->queryContentIdentifierString() );
625 aRow += '\t';
626 aRow += bFolder ? '1' : '0';
627 OUString* pRow = new OUString( aRow );
628 pProperties->Insert( pRow, LIST_APPEND );
631 catch( ucb::CommandAbortedException& )
634 catch( uno::Exception& )
639 catch( uno::Exception& )
643 if ( pProperties )
645 ULONG nCount = pProperties->Count();
646 uno::Sequence < OUString > aRet( nCount );
647 OUString* pRet = aRet.getArray();
648 for ( ULONG i = 0; i < nCount; ++i )
650 OUString* pProperty = pProperties->GetObject(i);
651 pRet[i] = *( pProperty );
652 delete pProperty;
654 delete pProperties;
655 return aRet;
657 else
658 return uno::Sequence < OUString > ();
661 // -----------------------------------------------------------------------
663 String SfxContentHelper::GetActiveHelpString( const String& rURL )
665 String aRet;
668 uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
669 uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
670 xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY );
671 ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
672 // open the "active help" stream
673 uno::Reference< io::XInputStream > xStream = aCnt.openStream();
674 // and convert it to a String
675 uno::Sequence< sal_Int8 > lData;
676 sal_Int32 nRead = xStream->readBytes( lData, 1024 );
677 while ( nRead > 0 )
679 OStringBuffer sBuffer( nRead );
680 for( sal_Int32 i = 0; i < nRead; ++i )
681 sBuffer.append( (sal_Char)lData[i] );
682 OUString sString = OStringToOUString( sBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
683 aRet += String( sString );
685 nRead = xStream->readBytes( lData, 1024 );
688 catch( uno::Exception& )
692 return aRet;
695 // -----------------------------------------------------------------------
697 sal_Bool SfxContentHelper::IsHelpErrorDocument( const String& rURL )
699 sal_Bool bRet = sal_False;
702 ::ucbhelper::Content aCnt( INetURLObject( rURL ).GetMainURL( INetURLObject::NO_DECODE ),
703 uno::Reference< ucb::XCommandEnvironment > () );
704 if ( !( aCnt.getPropertyValue( OUString::createFromAscii( "IsErrorDocument" ) ) >>= bRet ) )
706 DBG_ERRORFILE( "Property 'IsErrorDocument' is missing" );
709 catch( uno::Exception& )
713 return bRet;
716 // -----------------------------------------------------------------------
718 sal_Bool SfxContentHelper::CopyTo( const String& rSource, const String& rDest )
720 return Transfer_Impl( rSource, rDest, sal_False, ucb::NameClash::ERROR );
723 // -----------------------------------------------------------------------
725 sal_Bool SfxContentHelper::MoveTo( const String& rSource, const String& rDest, sal_Int32 nNameClash )
727 return Transfer_Impl( rSource, rDest, sal_True, nNameClash );
730 // -----------------------------------------------------------------------
732 sal_Bool SfxContentHelper::MakeFolder( const String& rFolder )
734 INetURLObject aURL( rFolder );
735 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
736 String aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
737 aURL.removeSegment();
738 uno::Sequence < OUString > aNames(2);
739 OUString* pNames = aNames.getArray();
740 pNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
741 pNames[1] = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) );
742 uno::Sequence<uno::Any> aValues(2);
743 uno::Any* pValues = aValues.getArray();
744 pValues[0] = uno::makeAny( OUString( aTitle ) );
745 pValues[1] = uno::makeAny( sal_Bool( sal_True ) );
746 uno::Reference< ucb::XCommandEnvironment > aCmdEnv;
747 sal_Bool bRet = sal_False;
750 ::ucbhelper::Content aCnt( aURL.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv );
751 ::ucbhelper::Content aNewFolder;
752 OUString aType( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.staroffice.fsys-folder" ) );
753 bRet = aCnt.insertNewContent( aType, aNames, aValues, aNewFolder );
755 catch( ucb::CommandAbortedException& )
757 // double name?
759 catch( ucb::IllegalIdentifierException& )
761 DBG_ERRORFILE( "Illegal identifier" );
763 catch( uno::Exception& )
765 DBG_ERRORFILE( "Any other exception" );
768 return bRet;
771 // -----------------------------------------------------------------------
773 ErrCode SfxContentHelper::QueryDiskSpace( const String& rPath, sal_Int64& rFreeBytes )
775 ErrCode nErr = 0;
776 rFreeBytes = 0;
777 INetURLObject aObj( rPath );
778 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
781 ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
782 aCnt.getPropertyValue( OUString::createFromAscii( "FreeSpace" ) ) >>= rFreeBytes;
784 catch( ucb::CommandAbortedException& )
786 DBG_ERRORFILE( "CommandAbortedException" );
787 nErr = ERRCODE_IO_GENERAL;
789 catch( uno::Exception& )
791 DBG_ERRORFILE( "Any other exception" );
792 nErr = ERRCODE_IO_GENERAL;
794 return nErr;
797 // -----------------------------------------------------------------------
799 ULONG SfxContentHelper::GetSize( const String& rContent )
801 ULONG nSize = 0;
802 sal_Int64 nTemp = 0;
803 INetURLObject aObj( rContent );
804 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
807 ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
808 aCnt.getPropertyValue( OUString::createFromAscii( "Size" ) ) >>= nTemp;
810 catch( ucb::CommandAbortedException& )
812 DBG_ERRORFILE( "CommandAbortedException" );
814 catch( uno::Exception& )
816 DBG_ERRORFILE( "Any other exception" );
818 nSize = (UINT32)nTemp;
819 return nSize;
822 // -----------------------------------------------------------------------
823 // please don't use it (only used in appbas.cxx and appcfg.cxx)
824 sal_Bool SfxContentHelper::Exists( const String& rContent )
826 sal_Bool bRet = sal_False;
827 INetURLObject aObj( rContent );
828 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
832 ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
833 // just try to get the property; if no exception is thrown, the content exists!
834 aCnt.isDocument();
835 bRet = sal_True;
837 catch( ucb::CommandAbortedException& )
839 DBG_WARNING( "CommandAbortedException" );
841 catch( ucb::IllegalIdentifierException& )
843 DBG_WARNING( "IllegalIdentifierException" );
845 catch( ucb::ContentCreationException& )
847 DBG_WARNING( "IllegalIdentifierException" );
849 catch( uno::Exception& )
851 DBG_ERRORFILE( "Any other exception" );
854 return bRet;
858 // -----------------------------------------------------------------------
860 sal_Bool SfxContentHelper::Find( const String& rFolder, const String& rName, String& rFile )
862 sal_Bool bRet = sal_False;
863 rtl::OUString aFile;
865 if ( FileBase::searchFileURL( rName, rFolder, aFile ) == FileBase::E_None )
867 rFile = aFile;
868 bRet = sal_True;
871 return bRet;