1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: helper.cxx,v $
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"
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
;
65 using namespace comphelper
;
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
)
78 CONVERT_DATETIME( rDT
, aDT
);
79 String aDateStr
= rWrapper
.getDate( aDT
);
80 aDateStr
+= String::CreateFromAscii( ", " );
81 aDateStr
+= rWrapper
.getTime( aDT
);
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
) ) );
116 DBG_ERRORFILE( "transfer command not available" );
119 catch( ucb::CommandAbortedException
& )
123 catch( uno::Exception
& )
125 DBG_ERRORFILE( "Any other exception" );
130 SfxContentHelper::Kill( rSource
);
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" );
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" );
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
> () );
211 aCnt
.getPropertyValue( OUString::createFromAscii( "Title" ) ) >>= aTemp
;
212 rTitle
= String( aTemp
);
215 catch( ucb::CommandAbortedException
& )
217 DBG_ERRORFILE( "CommandAbortedException" );
219 catch( uno::Exception
& )
221 DBG_ERRORFILE( "Any other exception" );
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" );
244 catch( uno::Exception
& )
246 DBG_ERRORFILE( "Any other exception" );
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
;
274 xResultSet
= aCnt
.createCursor( aProps
, eInclude
);
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
;
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" );
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
);
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
;
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
;
440 aRow
+= String::CreateFromInt64( nSize
);
442 AppendDateTime_Impl( aDT
, aRow
, aLocaleWrapper
);
444 aRow
+= String( xContentAccess
->queryContentIdentifierString() );
446 aRow
+= bFolder
? '1' : '0';
447 OUString
* pRow
= new OUString( aRow
);
448 ULONG nPos
= LIST_APPEND
;
451 if ( LIST_APPEND
== 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" );
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
);
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
;
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" );
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
);
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
;
624 aRow
+= String( xContentAccess
->queryContentIdentifierString() );
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
& )
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
);
658 return uno::Sequence
< OUString
> ();
661 // -----------------------------------------------------------------------
663 String
SfxContentHelper::GetActiveHelpString( const String
& rURL
)
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 );
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
& )
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
& )
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
& )
759 catch( ucb::IllegalIdentifierException
& )
761 DBG_ERRORFILE( "Illegal identifier" );
763 catch( uno::Exception
& )
765 DBG_ERRORFILE( "Any other exception" );
771 // -----------------------------------------------------------------------
773 ErrCode
SfxContentHelper::QueryDiskSpace( const String
& rPath
, sal_Int64
& rFreeBytes
)
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
;
797 // -----------------------------------------------------------------------
799 ULONG
SfxContentHelper::GetSize( const String
& rContent
)
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
;
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!
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" );
858 // -----------------------------------------------------------------------
860 sal_Bool
SfxContentHelper::Find( const String
& rFolder
, const String
& rName
, String
& rFile
)
862 sal_Bool bRet
= sal_False
;
865 if ( FileBase::searchFileURL( rName
, rFolder
, aFile
) == FileBase::E_None
)