xref: /trunk/main/sfx2/source/bastyp/helper.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "helper.hxx"
32*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/ucb/XDynamicResultSet.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
47*cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
48*cdf0e10cSrcweir #include <rtl/strbuf.hxx>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <tools/ref.hxx>
51*cdf0e10cSrcweir #include <tools/debug.hxx>
52*cdf0e10cSrcweir #include <tools/urlobj.hxx>
53*cdf0e10cSrcweir #include <tools/datetime.hxx>
54*cdf0e10cSrcweir #include <vcl/svapp.hxx>
55*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
56*cdf0e10cSrcweir #include <ucbhelper/commandenvironment.hxx>
57*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
58*cdf0e10cSrcweir #include <osl/file.hxx>
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir using namespace com::sun::star;
61*cdf0e10cSrcweir using namespace rtl;
62*cdf0e10cSrcweir using namespace comphelper;
63*cdf0e10cSrcweir using namespace osl;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir DECLARE_LIST( StringList_Impl, OUString* )
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir #define CONVERT_DATETIME( aUnoDT, aToolsDT ) \
68*cdf0e10cSrcweir     aToolsDT = DateTime( Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ), \
69*cdf0e10cSrcweir                          Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ) );
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir void AppendDateTime_Impl( const util::DateTime rDT,
72*cdf0e10cSrcweir                           String& rRow, const LocaleDataWrapper& rWrapper )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir     DateTime aDT;
75*cdf0e10cSrcweir     CONVERT_DATETIME( rDT, aDT );
76*cdf0e10cSrcweir     String aDateStr = rWrapper.getDate( aDT );
77*cdf0e10cSrcweir     aDateStr += String::CreateFromAscii( ", " );
78*cdf0e10cSrcweir     aDateStr += rWrapper.getTime( aDT );
79*cdf0e10cSrcweir     rRow += aDateStr;
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir // SfxContentHelper ------------------------------------------------------
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir sal_Bool SfxContentHelper::Transfer_Impl( const String& rSource, const String& rDest, sal_Bool bMoveData, sal_Int32 nNameClash )
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     sal_Bool bRet = sal_True, bKillSource = sal_False;
87*cdf0e10cSrcweir     INetURLObject aSourceObj( rSource );
88*cdf0e10cSrcweir     DBG_ASSERT( aSourceObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     INetURLObject aDestObj( rDest );
91*cdf0e10cSrcweir     DBG_ASSERT( aDestObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
92*cdf0e10cSrcweir     if ( bMoveData && aSourceObj.GetProtocol() != aDestObj.GetProtocol() )
93*cdf0e10cSrcweir     {
94*cdf0e10cSrcweir         bMoveData = sal_False;
95*cdf0e10cSrcweir         bKillSource = sal_True;
96*cdf0e10cSrcweir     }
97*cdf0e10cSrcweir     String aName = aDestObj.getName();
98*cdf0e10cSrcweir     aDestObj.removeSegment();
99*cdf0e10cSrcweir     aDestObj.setFinalSlash();
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     try
102*cdf0e10cSrcweir     {
103*cdf0e10cSrcweir         ::ucbhelper::Content aDestPath( aDestObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
104*cdf0e10cSrcweir         uno::Reference< ucb::XCommandInfo > xInfo = aDestPath.getCommands();
105*cdf0e10cSrcweir         OUString aTransferName = OUString::createFromAscii( "transfer" );
106*cdf0e10cSrcweir         if ( xInfo->hasCommandByName( aTransferName ) )
107*cdf0e10cSrcweir         {
108*cdf0e10cSrcweir             aDestPath.executeCommand( aTransferName, uno::makeAny(
109*cdf0e10cSrcweir                 ucb::TransferInfo( bMoveData, aSourceObj.GetMainURL( INetURLObject::NO_DECODE ), aName, nNameClash ) ) );
110*cdf0e10cSrcweir         }
111*cdf0e10cSrcweir         else
112*cdf0e10cSrcweir         {
113*cdf0e10cSrcweir             DBG_ERRORFILE( "transfer command not available" );
114*cdf0e10cSrcweir         }
115*cdf0e10cSrcweir     }
116*cdf0e10cSrcweir     catch( ucb::CommandAbortedException& )
117*cdf0e10cSrcweir     {
118*cdf0e10cSrcweir         bRet = sal_False;
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir     catch( uno::Exception& )
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         DBG_ERRORFILE( "Any other exception" );
123*cdf0e10cSrcweir         bRet = sal_False;
124*cdf0e10cSrcweir     }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     if ( bKillSource )
127*cdf0e10cSrcweir         SfxContentHelper::Kill( rSource );
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     return bRet;
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir // -----------------------------------------------------------------------
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir sal_Bool SfxContentHelper::IsDocument( const String& rContent )
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
137*cdf0e10cSrcweir     INetURLObject aObj( rContent );
138*cdf0e10cSrcweir     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     try
141*cdf0e10cSrcweir     {
142*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
143*cdf0e10cSrcweir         bRet = aCnt.isDocument();
144*cdf0e10cSrcweir     }
145*cdf0e10cSrcweir     catch( ucb::CommandAbortedException& )
146*cdf0e10cSrcweir     {
147*cdf0e10cSrcweir         DBG_WARNING( "CommandAbortedException" );
148*cdf0e10cSrcweir     }
149*cdf0e10cSrcweir     catch( ucb::IllegalIdentifierException& )
150*cdf0e10cSrcweir     {
151*cdf0e10cSrcweir         DBG_WARNING( "IllegalIdentifierException" );
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir     catch( ucb::ContentCreationException& )
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         DBG_WARNING( "IllegalIdentifierException" );
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir     catch( uno::Exception& )
158*cdf0e10cSrcweir     {
159*cdf0e10cSrcweir         DBG_ERRORFILE( "Any other exception" );
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     return bRet;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir // -----------------------------------------------------------------------
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir sal_Bool SfxContentHelper::IsFolder( const String& rContent )
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
170*cdf0e10cSrcweir     INetURLObject aObj( rContent );
171*cdf0e10cSrcweir     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
172*cdf0e10cSrcweir     try
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
175*cdf0e10cSrcweir         bRet = aCnt.isFolder();
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir     catch( ucb::CommandAbortedException& )
178*cdf0e10cSrcweir     {
179*cdf0e10cSrcweir         DBG_WARNING( "CommandAbortedException" );
180*cdf0e10cSrcweir     }
181*cdf0e10cSrcweir     catch( ucb::IllegalIdentifierException& )
182*cdf0e10cSrcweir     {
183*cdf0e10cSrcweir         DBG_WARNING( "IllegalIdentifierException" );
184*cdf0e10cSrcweir     }
185*cdf0e10cSrcweir     catch( ucb::ContentCreationException& )
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         DBG_WARNING( "IllegalIdentifierException" );
188*cdf0e10cSrcweir     }
189*cdf0e10cSrcweir     catch( uno::Exception& )
190*cdf0e10cSrcweir     {
191*cdf0e10cSrcweir         DBG_ERRORFILE( "Any other exception" );
192*cdf0e10cSrcweir     }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     return bRet;
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir // -----------------------------------------------------------------------
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir sal_Bool SfxContentHelper::GetTitle( const String& rContent, String& rTitle )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
202*cdf0e10cSrcweir     INetURLObject aObj( rContent );
203*cdf0e10cSrcweir     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
204*cdf0e10cSrcweir     try
205*cdf0e10cSrcweir     {
206*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
207*cdf0e10cSrcweir         OUString aTemp;
208*cdf0e10cSrcweir         aCnt.getPropertyValue( OUString::createFromAscii( "Title" ) ) >>= aTemp;
209*cdf0e10cSrcweir         rTitle = String( aTemp );
210*cdf0e10cSrcweir         bRet = sal_True;
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir     catch( ucb::CommandAbortedException& )
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir         DBG_ERRORFILE( "CommandAbortedException" );
215*cdf0e10cSrcweir     }
216*cdf0e10cSrcweir     catch( uno::Exception& )
217*cdf0e10cSrcweir     {
218*cdf0e10cSrcweir         DBG_ERRORFILE( "Any other exception" );
219*cdf0e10cSrcweir     }
220*cdf0e10cSrcweir     return bRet;
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir // -----------------------------------------------------------------------
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir sal_Bool SfxContentHelper::Kill( const String& rContent )
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir     sal_Bool bRet = sal_True;
228*cdf0e10cSrcweir     INetURLObject aDeleteObj( rContent );
229*cdf0e10cSrcweir     DBG_ASSERT( aDeleteObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     try
232*cdf0e10cSrcweir     {
233*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aDeleteObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
234*cdf0e10cSrcweir         aCnt.executeCommand( OUString::createFromAscii( "delete" ), uno::makeAny( sal_Bool( sal_True ) ) );
235*cdf0e10cSrcweir     }
236*cdf0e10cSrcweir     catch( ucb::CommandAbortedException& )
237*cdf0e10cSrcweir     {
238*cdf0e10cSrcweir         DBG_WARNING( "CommandAbortedException" );
239*cdf0e10cSrcweir         bRet = sal_False;
240*cdf0e10cSrcweir     }
241*cdf0e10cSrcweir     catch( uno::Exception& )
242*cdf0e10cSrcweir     {
243*cdf0e10cSrcweir         DBG_ERRORFILE( "Any other exception" );
244*cdf0e10cSrcweir         bRet = sal_False;
245*cdf0e10cSrcweir     }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     return bRet;
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir // -----------------------------------------------------------------------
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir uno::Sequence < OUString > SfxContentHelper::GetFolderContents( const String& rFolder, sal_Bool bFolder, sal_Bool bSorted )
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir     StringList_Impl* pFiles = NULL;
255*cdf0e10cSrcweir     INetURLObject aFolderObj( rFolder );
256*cdf0e10cSrcweir     DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
257*cdf0e10cSrcweir     try
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
260*cdf0e10cSrcweir         uno::Reference< sdbc::XResultSet > xResultSet;
261*cdf0e10cSrcweir         uno::Sequence< OUString > aProps(2);
262*cdf0e10cSrcweir         OUString* pProps = aProps.getArray();
263*cdf0e10cSrcweir         pProps[0] = OUString::createFromAscii( "Title" );
264*cdf0e10cSrcweir         pProps[1] = OUString::createFromAscii( "IsFolder" );
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir         try
267*cdf0e10cSrcweir         {
268*cdf0e10cSrcweir             ::ucbhelper::ResultSetInclude eInclude = bFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY;
269*cdf0e10cSrcweir             if ( !bSorted )
270*cdf0e10cSrcweir             {
271*cdf0e10cSrcweir                 xResultSet = aCnt.createCursor( aProps, eInclude );
272*cdf0e10cSrcweir             }
273*cdf0e10cSrcweir             else
274*cdf0e10cSrcweir             {
275*cdf0e10cSrcweir                 uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
276*cdf0e10cSrcweir                 xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir                 uno::Reference < ucb::XAnyCompareFactory > xFactory;
279*cdf0e10cSrcweir                 uno::Reference < lang::XMultiServiceFactory > xMgr = getProcessServiceFactory();
280*cdf0e10cSrcweir                 uno::Reference < ucb::XSortedDynamicResultSetFactory > xSRSFac(
281*cdf0e10cSrcweir                     xMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SortedDynamicResultSetFactory") ), uno::UNO_QUERY );
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir                 uno::Sequence< ucb::NumberedSortingInfo > aSortInfo( 2 );
284*cdf0e10cSrcweir                 ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray();
285*cdf0e10cSrcweir                 pInfo[ 0 ].ColumnIndex = 2;
286*cdf0e10cSrcweir                 pInfo[ 0 ].Ascending   = sal_False;
287*cdf0e10cSrcweir                 pInfo[ 1 ].ColumnIndex = 1;
288*cdf0e10cSrcweir                 pInfo[ 1 ].Ascending   = sal_True;
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir                 uno::Reference< ucb::XDynamicResultSet > xDynamicResultSet;
291*cdf0e10cSrcweir                 xDynamicResultSet =
292*cdf0e10cSrcweir                     xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xFactory );
293*cdf0e10cSrcweir                 if ( xDynamicResultSet.is() )
294*cdf0e10cSrcweir                 {
295*cdf0e10cSrcweir                     xResultSet = xDynamicResultSet->getStaticResultSet();
296*cdf0e10cSrcweir                 }
297*cdf0e10cSrcweir             }
298*cdf0e10cSrcweir         }
299*cdf0e10cSrcweir         catch( ucb::CommandAbortedException& )
300*cdf0e10cSrcweir         {
301*cdf0e10cSrcweir             DBG_ERRORFILE( "createCursor: CommandAbortedException" );
302*cdf0e10cSrcweir         }
303*cdf0e10cSrcweir         catch( uno::Exception& )
304*cdf0e10cSrcweir         {
305*cdf0e10cSrcweir             DBG_ERRORFILE( "createCursor: Any other exception" );
306*cdf0e10cSrcweir         }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir         if ( xResultSet.is() )
309*cdf0e10cSrcweir         {
310*cdf0e10cSrcweir             pFiles = new StringList_Impl;
311*cdf0e10cSrcweir             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
312*cdf0e10cSrcweir             try
313*cdf0e10cSrcweir             {
314*cdf0e10cSrcweir                 while ( xResultSet->next() )
315*cdf0e10cSrcweir                 {
316*cdf0e10cSrcweir                     OUString aId = xContentAccess->queryContentIdentifierString();
317*cdf0e10cSrcweir                     OUString* pFile = new OUString( aId );
318*cdf0e10cSrcweir                     pFiles->Insert( pFile, LIST_APPEND );
319*cdf0e10cSrcweir                 }
320*cdf0e10cSrcweir             }
321*cdf0e10cSrcweir             catch( ucb::CommandAbortedException& )
322*cdf0e10cSrcweir             {
323*cdf0e10cSrcweir                 DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" );
324*cdf0e10cSrcweir             }
325*cdf0e10cSrcweir             catch( uno::Exception& )
326*cdf0e10cSrcweir             {
327*cdf0e10cSrcweir                 DBG_ERRORFILE( "XContentAccess::next(): Any other exception" );
328*cdf0e10cSrcweir             }
329*cdf0e10cSrcweir         }
330*cdf0e10cSrcweir     }
331*cdf0e10cSrcweir     catch( uno::Exception& )
332*cdf0e10cSrcweir     {
333*cdf0e10cSrcweir         DBG_ERRORFILE( "GetFolderContents: Any other exception" );
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     if ( pFiles )
337*cdf0e10cSrcweir     {
338*cdf0e10cSrcweir         sal_uIntPtr nCount = pFiles->Count();
339*cdf0e10cSrcweir         uno::Sequence < OUString > aRet( nCount );
340*cdf0e10cSrcweir         OUString* pRet = aRet.getArray();
341*cdf0e10cSrcweir         for ( sal_uIntPtr i = 0; i < nCount; ++i )
342*cdf0e10cSrcweir         {
343*cdf0e10cSrcweir             OUString* pFile = pFiles->GetObject(i);
344*cdf0e10cSrcweir             pRet[i] = *( pFile );
345*cdf0e10cSrcweir             delete pFile;
346*cdf0e10cSrcweir         }
347*cdf0e10cSrcweir         delete pFiles;
348*cdf0e10cSrcweir         return aRet;
349*cdf0e10cSrcweir     }
350*cdf0e10cSrcweir     else
351*cdf0e10cSrcweir         return uno::Sequence < OUString > ();
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir // -----------------------------------------------------------------------
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir uno::Sequence < OUString > SfxContentHelper::GetFolderContentProperties( const String& rFolder, sal_Bool bIsFolder )
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir     StringList_Impl* pProperties = NULL;
359*cdf0e10cSrcweir     INetURLObject aFolderObj( rFolder );
360*cdf0e10cSrcweir     DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
361*cdf0e10cSrcweir     try
362*cdf0e10cSrcweir     {
363*cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
364*cdf0e10cSrcweir         uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
365*cdf0e10cSrcweir                     xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY );
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
368*cdf0e10cSrcweir         uno::Reference< sdbc::XResultSet > xResultSet;
369*cdf0e10cSrcweir         uno::Sequence< OUString > aProps(5);
370*cdf0e10cSrcweir         OUString* pProps = aProps.getArray();
371*cdf0e10cSrcweir         pProps[0] = OUString::createFromAscii( "Title" );
372*cdf0e10cSrcweir         pProps[1] = OUString::createFromAscii( "ContentType" );
373*cdf0e10cSrcweir         pProps[2] = OUString::createFromAscii( "Size" );
374*cdf0e10cSrcweir         pProps[3] = OUString::createFromAscii( "DateModified" );
375*cdf0e10cSrcweir         pProps[4] = OUString::createFromAscii( "IsFolder" );
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir         try
378*cdf0e10cSrcweir         {
379*cdf0e10cSrcweir             uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
380*cdf0e10cSrcweir             ::ucbhelper::ResultSetInclude eInclude = bIsFolder ? ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ::ucbhelper::INCLUDE_DOCUMENTS_ONLY;
381*cdf0e10cSrcweir             xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude );
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir             uno::Reference < ucb::XAnyCompareFactory > xCmpFactory;
384*cdf0e10cSrcweir             uno::Reference < lang::XMultiServiceFactory > xMgr = getProcessServiceFactory();
385*cdf0e10cSrcweir             uno::Reference < ucb::XSortedDynamicResultSetFactory > xSRSFac(
386*cdf0e10cSrcweir                 xMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SortedDynamicResultSetFactory") ), uno::UNO_QUERY );
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir             uno::Sequence< ucb::NumberedSortingInfo > aSortInfo( 2 );
389*cdf0e10cSrcweir             ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray();
390*cdf0e10cSrcweir             pInfo[ 0 ].ColumnIndex = 5;
391*cdf0e10cSrcweir             pInfo[ 0 ].Ascending   = sal_False;
392*cdf0e10cSrcweir             pInfo[ 1 ].ColumnIndex = 1;
393*cdf0e10cSrcweir             pInfo[ 1 ].Ascending   = sal_True;
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir             uno::Reference< ucb::XDynamicResultSet > xDynamicResultSet;
396*cdf0e10cSrcweir             xDynamicResultSet =
397*cdf0e10cSrcweir                 xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xCmpFactory );
398*cdf0e10cSrcweir             if ( xDynamicResultSet.is() )
399*cdf0e10cSrcweir             {
400*cdf0e10cSrcweir                 xResultSet = xDynamicResultSet->getStaticResultSet();
401*cdf0e10cSrcweir             }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir //          if ( xDynResultSet.is() )
404*cdf0e10cSrcweir //              xResultSet = xDynResultSet->getStaticResultSet();
405*cdf0e10cSrcweir         }
406*cdf0e10cSrcweir         catch( ucb::CommandAbortedException& )
407*cdf0e10cSrcweir         {
408*cdf0e10cSrcweir             DBG_ERRORFILE( "createCursor: CommandAbortedException" );
409*cdf0e10cSrcweir         }
410*cdf0e10cSrcweir         catch( uno::Exception& )
411*cdf0e10cSrcweir         {
412*cdf0e10cSrcweir             DBG_ERRORFILE( "createCursor: Any other exception" );
413*cdf0e10cSrcweir         }
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir         if ( xResultSet.is() )
416*cdf0e10cSrcweir         {
417*cdf0e10cSrcweir             LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
418*cdf0e10cSrcweir             pProperties = new StringList_Impl;
419*cdf0e10cSrcweir             uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
420*cdf0e10cSrcweir             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
421*cdf0e10cSrcweir             sal_uIntPtr nFolderPos = LIST_APPEND;
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir             try
424*cdf0e10cSrcweir             {
425*cdf0e10cSrcweir                 while ( xResultSet->next() )
426*cdf0e10cSrcweir                 {
427*cdf0e10cSrcweir                     String aTitle( xRow->getString(1) );
428*cdf0e10cSrcweir                     String aType( xRow->getString(2) );
429*cdf0e10cSrcweir                     sal_Int64 nSize = xRow->getLong(3);
430*cdf0e10cSrcweir                     util::DateTime aDT = xRow->getTimestamp(4);
431*cdf0e10cSrcweir                     sal_Bool bFolder = xRow->getBoolean(5);
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir                     String aRow = aTitle;
434*cdf0e10cSrcweir                     aRow += '\t';
435*cdf0e10cSrcweir //!                 aRow += aType;
436*cdf0e10cSrcweir //!                 aRow += '\t';
437*cdf0e10cSrcweir                     aRow += String::CreateFromInt64( nSize );
438*cdf0e10cSrcweir                     aRow += '\t';
439*cdf0e10cSrcweir                     AppendDateTime_Impl( aDT, aRow, aLocaleWrapper );
440*cdf0e10cSrcweir                     aRow += '\t';
441*cdf0e10cSrcweir                     aRow += String( xContentAccess->queryContentIdentifierString() );
442*cdf0e10cSrcweir                     aRow += '\t';
443*cdf0e10cSrcweir                     aRow += bFolder ? '1' : '0';
444*cdf0e10cSrcweir                     OUString* pRow = new OUString( aRow );
445*cdf0e10cSrcweir                     sal_uIntPtr nPos = LIST_APPEND;
446*cdf0e10cSrcweir                     if ( bFolder )
447*cdf0e10cSrcweir                     {
448*cdf0e10cSrcweir                         if ( LIST_APPEND == nFolderPos )
449*cdf0e10cSrcweir                             nFolderPos = 0;
450*cdf0e10cSrcweir                         else
451*cdf0e10cSrcweir                             nFolderPos++;
452*cdf0e10cSrcweir                         nPos = nFolderPos;
453*cdf0e10cSrcweir                     }
454*cdf0e10cSrcweir                     pProperties->Insert( pRow, nPos );
455*cdf0e10cSrcweir                 }
456*cdf0e10cSrcweir             }
457*cdf0e10cSrcweir             catch( ucb::CommandAbortedException& )
458*cdf0e10cSrcweir             {
459*cdf0e10cSrcweir                 DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" );
460*cdf0e10cSrcweir             }
461*cdf0e10cSrcweir             catch( uno::Exception& )
462*cdf0e10cSrcweir             {
463*cdf0e10cSrcweir                 DBG_ERRORFILE( "XContentAccess::next(): Any other exception" );
464*cdf0e10cSrcweir             }
465*cdf0e10cSrcweir         }
466*cdf0e10cSrcweir     }
467*cdf0e10cSrcweir     catch( uno::Exception& )
468*cdf0e10cSrcweir     {
469*cdf0e10cSrcweir         DBG_ERRORFILE( "GetFolderContents: Any other exception" );
470*cdf0e10cSrcweir     }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir     if ( pProperties )
473*cdf0e10cSrcweir     {
474*cdf0e10cSrcweir         sal_uIntPtr nCount = pProperties->Count();
475*cdf0e10cSrcweir         uno::Sequence < OUString > aRet( nCount );
476*cdf0e10cSrcweir         OUString* pRet = aRet.getArray();
477*cdf0e10cSrcweir         for ( sal_uIntPtr i = 0; i < nCount; ++i )
478*cdf0e10cSrcweir         {
479*cdf0e10cSrcweir             OUString* pProperty = pProperties->GetObject(i);
480*cdf0e10cSrcweir             pRet[i] = *( pProperty );
481*cdf0e10cSrcweir             delete pProperty;
482*cdf0e10cSrcweir         }
483*cdf0e10cSrcweir         delete pProperties;
484*cdf0e10cSrcweir         return aRet;
485*cdf0e10cSrcweir     }
486*cdf0e10cSrcweir     else
487*cdf0e10cSrcweir         return uno::Sequence < OUString > ();
488*cdf0e10cSrcweir }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir // -----------------------------------------------------------------------
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir uno::Sequence < OUString > SfxContentHelper::GetResultSet( const String& rURL )
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir     StringList_Impl* pList = NULL;
495*cdf0e10cSrcweir     try
496*cdf0e10cSrcweir     {
497*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( rURL, uno::Reference< ucb::XCommandEnvironment >() );
498*cdf0e10cSrcweir         uno::Reference< sdbc::XResultSet > xResultSet;
499*cdf0e10cSrcweir         uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
500*cdf0e10cSrcweir         uno::Sequence< OUString > aProps(3);
501*cdf0e10cSrcweir         OUString* pProps = aProps.getArray();
502*cdf0e10cSrcweir         pProps[0] = OUString::createFromAscii( "Title" );
503*cdf0e10cSrcweir         pProps[1] = OUString::createFromAscii( "ContentType" );
504*cdf0e10cSrcweir         pProps[2] = OUString::createFromAscii( "IsFolder" );
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir         try
507*cdf0e10cSrcweir         {
508*cdf0e10cSrcweir             xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
509*cdf0e10cSrcweir             if ( xDynResultSet.is() )
510*cdf0e10cSrcweir                 xResultSet = xDynResultSet->getStaticResultSet();
511*cdf0e10cSrcweir         }
512*cdf0e10cSrcweir         catch( ucb::CommandAbortedException& )
513*cdf0e10cSrcweir         {
514*cdf0e10cSrcweir             DBG_ERRORFILE( "createCursor: CommandAbortedException" );
515*cdf0e10cSrcweir         }
516*cdf0e10cSrcweir         catch( uno::Exception& )
517*cdf0e10cSrcweir         {
518*cdf0e10cSrcweir             DBG_ERRORFILE( "createCursor: Any other exception" );
519*cdf0e10cSrcweir         }
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir         if ( xResultSet.is() )
522*cdf0e10cSrcweir         {
523*cdf0e10cSrcweir             pList = new StringList_Impl;
524*cdf0e10cSrcweir             uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
525*cdf0e10cSrcweir             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir             try
528*cdf0e10cSrcweir             {
529*cdf0e10cSrcweir                 while ( xResultSet->next() )
530*cdf0e10cSrcweir                 {
531*cdf0e10cSrcweir                     String aTitle( xRow->getString(1) );
532*cdf0e10cSrcweir                     String aType( xRow->getString(2) );
533*cdf0e10cSrcweir                     String aRow = aTitle;
534*cdf0e10cSrcweir                     aRow += '\t';
535*cdf0e10cSrcweir                     aRow += aType;
536*cdf0e10cSrcweir                     aRow += '\t';
537*cdf0e10cSrcweir                     aRow += String( xContentAccess->queryContentIdentifierString() );
538*cdf0e10cSrcweir                     OUString* pRow = new OUString( aRow );
539*cdf0e10cSrcweir                     pList->Insert( pRow, LIST_APPEND );
540*cdf0e10cSrcweir                 }
541*cdf0e10cSrcweir             }
542*cdf0e10cSrcweir             catch( ucb::CommandAbortedException& )
543*cdf0e10cSrcweir             {
544*cdf0e10cSrcweir                 DBG_ERRORFILE( "XContentAccess::next(): CommandAbortedException" );
545*cdf0e10cSrcweir             }
546*cdf0e10cSrcweir             catch( uno::Exception& )
547*cdf0e10cSrcweir             {
548*cdf0e10cSrcweir                 DBG_ERRORFILE( "XContentAccess::next(): Any other exception" );
549*cdf0e10cSrcweir             }
550*cdf0e10cSrcweir         }
551*cdf0e10cSrcweir     }
552*cdf0e10cSrcweir     catch( uno::Exception& e )
553*cdf0e10cSrcweir     {
554*cdf0e10cSrcweir         (void) e;
555*cdf0e10cSrcweir         DBG_ERRORFILE(
556*cdf0e10cSrcweir             rtl::OUStringToOString(
557*cdf0e10cSrcweir                 (rtl::OUString(
558*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
559*cdf0e10cSrcweir                         "GetResultSet: Any other exception: ")) +
560*cdf0e10cSrcweir                  e.Message),
561*cdf0e10cSrcweir                 RTL_TEXTENCODING_UTF8).
562*cdf0e10cSrcweir             getStr());
563*cdf0e10cSrcweir     }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir     if ( pList )
566*cdf0e10cSrcweir     {
567*cdf0e10cSrcweir         sal_uIntPtr nCount = pList->Count();
568*cdf0e10cSrcweir         uno::Sequence < OUString > aRet( nCount );
569*cdf0e10cSrcweir         OUString* pRet = aRet.getArray();
570*cdf0e10cSrcweir         for ( sal_uIntPtr i = 0; i < nCount; ++i )
571*cdf0e10cSrcweir         {
572*cdf0e10cSrcweir             OUString* pEntry = pList->GetObject(i);
573*cdf0e10cSrcweir             pRet[i] = *( pEntry );
574*cdf0e10cSrcweir             delete pEntry;
575*cdf0e10cSrcweir         }
576*cdf0e10cSrcweir         delete pList;
577*cdf0e10cSrcweir         return aRet;
578*cdf0e10cSrcweir     }
579*cdf0e10cSrcweir     else
580*cdf0e10cSrcweir         return uno::Sequence < OUString > ();
581*cdf0e10cSrcweir }
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir // -----------------------------------------------------------------------
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir uno::Sequence< OUString > SfxContentHelper::GetHelpTreeViewContents( const String& rURL )
586*cdf0e10cSrcweir {
587*cdf0e10cSrcweir     StringList_Impl* pProperties = NULL;
588*cdf0e10cSrcweir     try
589*cdf0e10cSrcweir     {
590*cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
591*cdf0e10cSrcweir         uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
592*cdf0e10cSrcweir                     xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY );
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
595*cdf0e10cSrcweir         uno::Reference< sdbc::XResultSet > xResultSet;
596*cdf0e10cSrcweir         uno::Sequence< OUString > aProps(2);
597*cdf0e10cSrcweir         OUString* pProps = aProps.getArray();
598*cdf0e10cSrcweir         pProps[0] = OUString::createFromAscii( "Title" );
599*cdf0e10cSrcweir         pProps[1] = OUString::createFromAscii( "IsFolder" );
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir         try
602*cdf0e10cSrcweir         {
603*cdf0e10cSrcweir             uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
604*cdf0e10cSrcweir             xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
605*cdf0e10cSrcweir             if ( xDynResultSet.is() )
606*cdf0e10cSrcweir                 xResultSet = xDynResultSet->getStaticResultSet();
607*cdf0e10cSrcweir         }
608*cdf0e10cSrcweir         catch( ucb::CommandAbortedException& )
609*cdf0e10cSrcweir         {
610*cdf0e10cSrcweir         }
611*cdf0e10cSrcweir         catch( uno::Exception& )
612*cdf0e10cSrcweir         {
613*cdf0e10cSrcweir         }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir         if ( xResultSet.is() )
616*cdf0e10cSrcweir         {
617*cdf0e10cSrcweir             pProperties = new StringList_Impl;
618*cdf0e10cSrcweir             uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
619*cdf0e10cSrcweir             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir             try
622*cdf0e10cSrcweir             {
623*cdf0e10cSrcweir                 while ( xResultSet->next() )
624*cdf0e10cSrcweir                 {
625*cdf0e10cSrcweir                     String aTitle( xRow->getString(1) );
626*cdf0e10cSrcweir                     sal_Bool bFolder = xRow->getBoolean(2);
627*cdf0e10cSrcweir                     String aRow = aTitle;
628*cdf0e10cSrcweir                     aRow += '\t';
629*cdf0e10cSrcweir                     aRow += String( xContentAccess->queryContentIdentifierString() );
630*cdf0e10cSrcweir                     aRow += '\t';
631*cdf0e10cSrcweir                     aRow += bFolder ? '1' : '0';
632*cdf0e10cSrcweir                     OUString* pRow = new OUString( aRow );
633*cdf0e10cSrcweir                     pProperties->Insert( pRow, LIST_APPEND );
634*cdf0e10cSrcweir                 }
635*cdf0e10cSrcweir             }
636*cdf0e10cSrcweir             catch( ucb::CommandAbortedException& )
637*cdf0e10cSrcweir             {
638*cdf0e10cSrcweir             }
639*cdf0e10cSrcweir             catch( uno::Exception& )
640*cdf0e10cSrcweir             {
641*cdf0e10cSrcweir             }
642*cdf0e10cSrcweir         }
643*cdf0e10cSrcweir     }
644*cdf0e10cSrcweir     catch( uno::Exception& )
645*cdf0e10cSrcweir     {
646*cdf0e10cSrcweir     }
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir     if ( pProperties )
649*cdf0e10cSrcweir     {
650*cdf0e10cSrcweir         sal_uIntPtr nCount = pProperties->Count();
651*cdf0e10cSrcweir         uno::Sequence < OUString > aRet( nCount );
652*cdf0e10cSrcweir         OUString* pRet = aRet.getArray();
653*cdf0e10cSrcweir         for ( sal_uIntPtr i = 0; i < nCount; ++i )
654*cdf0e10cSrcweir         {
655*cdf0e10cSrcweir             OUString* pProperty = pProperties->GetObject(i);
656*cdf0e10cSrcweir             pRet[i] = *( pProperty );
657*cdf0e10cSrcweir             delete pProperty;
658*cdf0e10cSrcweir         }
659*cdf0e10cSrcweir         delete pProperties;
660*cdf0e10cSrcweir         return aRet;
661*cdf0e10cSrcweir     }
662*cdf0e10cSrcweir     else
663*cdf0e10cSrcweir         return uno::Sequence < OUString > ();
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir // -----------------------------------------------------------------------
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir String SfxContentHelper::GetActiveHelpString( const String& rURL )
669*cdf0e10cSrcweir {
670*cdf0e10cSrcweir     String aRet;
671*cdf0e10cSrcweir     try
672*cdf0e10cSrcweir     {
673*cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
674*cdf0e10cSrcweir         uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
675*cdf0e10cSrcweir                     xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), uno::UNO_QUERY );
676*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
677*cdf0e10cSrcweir         // open the "active help" stream
678*cdf0e10cSrcweir         uno::Reference< io::XInputStream > xStream = aCnt.openStream();
679*cdf0e10cSrcweir         // and convert it to a String
680*cdf0e10cSrcweir         uno::Sequence< sal_Int8 > lData;
681*cdf0e10cSrcweir         sal_Int32 nRead = xStream->readBytes( lData, 1024 );
682*cdf0e10cSrcweir         while ( nRead > 0 )
683*cdf0e10cSrcweir         {
684*cdf0e10cSrcweir             OStringBuffer sBuffer( nRead );
685*cdf0e10cSrcweir             for( sal_Int32 i = 0; i < nRead; ++i )
686*cdf0e10cSrcweir                 sBuffer.append( (sal_Char)lData[i] );
687*cdf0e10cSrcweir             OUString sString = OStringToOUString( sBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
688*cdf0e10cSrcweir             aRet += String( sString );
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir             nRead = xStream->readBytes( lData, 1024 );
691*cdf0e10cSrcweir         }
692*cdf0e10cSrcweir     }
693*cdf0e10cSrcweir     catch( uno::Exception& )
694*cdf0e10cSrcweir     {
695*cdf0e10cSrcweir     }
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir     return aRet;
698*cdf0e10cSrcweir }
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir // -----------------------------------------------------------------------
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir sal_Bool SfxContentHelper::IsHelpErrorDocument( const String& rURL )
703*cdf0e10cSrcweir {
704*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
705*cdf0e10cSrcweir     try
706*cdf0e10cSrcweir     {
707*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( INetURLObject( rURL ).GetMainURL( INetURLObject::NO_DECODE ),
708*cdf0e10cSrcweir                       uno::Reference< ucb::XCommandEnvironment > () );
709*cdf0e10cSrcweir         if ( !( aCnt.getPropertyValue( OUString::createFromAscii( "IsErrorDocument" ) ) >>= bRet ) )
710*cdf0e10cSrcweir         {
711*cdf0e10cSrcweir             DBG_ERRORFILE( "Property 'IsErrorDocument' is missing" );
712*cdf0e10cSrcweir         }
713*cdf0e10cSrcweir     }
714*cdf0e10cSrcweir     catch( uno::Exception& )
715*cdf0e10cSrcweir     {
716*cdf0e10cSrcweir     }
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir     return bRet;
719*cdf0e10cSrcweir }
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir // -----------------------------------------------------------------------
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir sal_Bool SfxContentHelper::CopyTo( const String& rSource, const String& rDest )
724*cdf0e10cSrcweir {
725*cdf0e10cSrcweir     return Transfer_Impl( rSource, rDest, sal_False, ucb::NameClash::ERROR );
726*cdf0e10cSrcweir }
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir // -----------------------------------------------------------------------
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir sal_Bool SfxContentHelper::MoveTo( const String& rSource, const String& rDest, sal_Int32 nNameClash )
731*cdf0e10cSrcweir {
732*cdf0e10cSrcweir     return Transfer_Impl( rSource, rDest, sal_True, nNameClash );
733*cdf0e10cSrcweir }
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir // -----------------------------------------------------------------------
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir sal_Bool SfxContentHelper::MakeFolder( const String& rFolder )
738*cdf0e10cSrcweir {
739*cdf0e10cSrcweir     INetURLObject aURL( rFolder );
740*cdf0e10cSrcweir     DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
741*cdf0e10cSrcweir     String aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
742*cdf0e10cSrcweir     aURL.removeSegment();
743*cdf0e10cSrcweir     uno::Sequence < OUString > aNames(2);
744*cdf0e10cSrcweir     OUString* pNames = aNames.getArray();
745*cdf0e10cSrcweir     pNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
746*cdf0e10cSrcweir     pNames[1] = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) );
747*cdf0e10cSrcweir     uno::Sequence<uno::Any> aValues(2);
748*cdf0e10cSrcweir     uno::Any* pValues = aValues.getArray();
749*cdf0e10cSrcweir     pValues[0] = uno::makeAny( OUString( aTitle ) );
750*cdf0e10cSrcweir     pValues[1] = uno::makeAny( sal_Bool( sal_True ) );
751*cdf0e10cSrcweir     uno::Reference< ucb::XCommandEnvironment > aCmdEnv;
752*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
753*cdf0e10cSrcweir     try
754*cdf0e10cSrcweir     {
755*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aURL.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv );
756*cdf0e10cSrcweir         ::ucbhelper::Content aNewFolder;
757*cdf0e10cSrcweir         OUString aType( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.staroffice.fsys-folder" ) );
758*cdf0e10cSrcweir         bRet = aCnt.insertNewContent( aType, aNames, aValues, aNewFolder );
759*cdf0e10cSrcweir     }
760*cdf0e10cSrcweir     catch( ucb::CommandAbortedException& )
761*cdf0e10cSrcweir     {
762*cdf0e10cSrcweir         // double name?
763*cdf0e10cSrcweir     }
764*cdf0e10cSrcweir     catch( ucb::IllegalIdentifierException& )
765*cdf0e10cSrcweir     {
766*cdf0e10cSrcweir         DBG_ERRORFILE( "Illegal identifier" );
767*cdf0e10cSrcweir     }
768*cdf0e10cSrcweir     catch( uno::Exception& )
769*cdf0e10cSrcweir     {
770*cdf0e10cSrcweir         DBG_ERRORFILE( "Any other exception" );
771*cdf0e10cSrcweir     }
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir     return bRet;
774*cdf0e10cSrcweir }
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir // -----------------------------------------------------------------------
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir ErrCode SfxContentHelper::QueryDiskSpace( const String& rPath, sal_Int64& rFreeBytes )
779*cdf0e10cSrcweir {
780*cdf0e10cSrcweir     ErrCode nErr = 0;
781*cdf0e10cSrcweir     rFreeBytes = 0;
782*cdf0e10cSrcweir     INetURLObject aObj( rPath );
783*cdf0e10cSrcweir     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
784*cdf0e10cSrcweir     try
785*cdf0e10cSrcweir     {
786*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
787*cdf0e10cSrcweir         aCnt.getPropertyValue( OUString::createFromAscii( "FreeSpace" ) ) >>= rFreeBytes;
788*cdf0e10cSrcweir     }
789*cdf0e10cSrcweir     catch( ucb::CommandAbortedException& )
790*cdf0e10cSrcweir     {
791*cdf0e10cSrcweir         DBG_ERRORFILE( "CommandAbortedException" );
792*cdf0e10cSrcweir         nErr = ERRCODE_IO_GENERAL;
793*cdf0e10cSrcweir     }
794*cdf0e10cSrcweir     catch( uno::Exception& )
795*cdf0e10cSrcweir     {
796*cdf0e10cSrcweir         DBG_ERRORFILE( "Any other exception" );
797*cdf0e10cSrcweir         nErr = ERRCODE_IO_GENERAL;
798*cdf0e10cSrcweir     }
799*cdf0e10cSrcweir     return nErr;
800*cdf0e10cSrcweir }
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir // -----------------------------------------------------------------------
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir sal_uIntPtr SfxContentHelper::GetSize( const String& rContent )
805*cdf0e10cSrcweir {
806*cdf0e10cSrcweir     sal_uIntPtr nSize = 0;
807*cdf0e10cSrcweir     sal_Int64 nTemp = 0;
808*cdf0e10cSrcweir     INetURLObject aObj( rContent );
809*cdf0e10cSrcweir     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
810*cdf0e10cSrcweir     try
811*cdf0e10cSrcweir     {
812*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
813*cdf0e10cSrcweir         aCnt.getPropertyValue( OUString::createFromAscii( "Size" ) ) >>= nTemp;
814*cdf0e10cSrcweir     }
815*cdf0e10cSrcweir     catch( ucb::CommandAbortedException& )
816*cdf0e10cSrcweir     {
817*cdf0e10cSrcweir         DBG_ERRORFILE( "CommandAbortedException" );
818*cdf0e10cSrcweir     }
819*cdf0e10cSrcweir     catch( uno::Exception& )
820*cdf0e10cSrcweir     {
821*cdf0e10cSrcweir         DBG_ERRORFILE( "Any other exception" );
822*cdf0e10cSrcweir     }
823*cdf0e10cSrcweir     nSize = (sal_uInt32)nTemp;
824*cdf0e10cSrcweir     return nSize;
825*cdf0e10cSrcweir }
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir // -----------------------------------------------------------------------
828*cdf0e10cSrcweir // please don't use it (only used in appbas.cxx and appcfg.cxx)
829*cdf0e10cSrcweir sal_Bool SfxContentHelper::Exists( const String& rContent )
830*cdf0e10cSrcweir {
831*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
832*cdf0e10cSrcweir     INetURLObject aObj( rContent );
833*cdf0e10cSrcweir     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir     try
836*cdf0e10cSrcweir     {
837*cdf0e10cSrcweir         ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
838*cdf0e10cSrcweir         // just try to get the property; if no exception is thrown, the content exists!
839*cdf0e10cSrcweir         aCnt.isDocument();
840*cdf0e10cSrcweir         bRet = sal_True;
841*cdf0e10cSrcweir     }
842*cdf0e10cSrcweir     catch( ucb::CommandAbortedException& )
843*cdf0e10cSrcweir     {
844*cdf0e10cSrcweir             DBG_WARNING( "CommandAbortedException" );
845*cdf0e10cSrcweir     }
846*cdf0e10cSrcweir     catch( ucb::IllegalIdentifierException& )
847*cdf0e10cSrcweir     {
848*cdf0e10cSrcweir             DBG_WARNING( "IllegalIdentifierException" );
849*cdf0e10cSrcweir     }
850*cdf0e10cSrcweir     catch( ucb::ContentCreationException& )
851*cdf0e10cSrcweir     {
852*cdf0e10cSrcweir             DBG_WARNING( "IllegalIdentifierException" );
853*cdf0e10cSrcweir     }
854*cdf0e10cSrcweir     catch( uno::Exception& )
855*cdf0e10cSrcweir     {
856*cdf0e10cSrcweir         DBG_ERRORFILE( "Any other exception" );
857*cdf0e10cSrcweir     }
858*cdf0e10cSrcweir 
859*cdf0e10cSrcweir     return bRet;
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir }
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir // -----------------------------------------------------------------------
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir sal_Bool SfxContentHelper::Find( const String& rFolder, const String& rName, String& rFile )
866*cdf0e10cSrcweir {
867*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
868*cdf0e10cSrcweir     rtl::OUString aFile;
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir     if ( FileBase::searchFileURL( rName, rFolder, aFile ) == FileBase::E_None )
871*cdf0e10cSrcweir     {
872*cdf0e10cSrcweir         rFile = aFile;
873*cdf0e10cSrcweir         bRet = sal_True;
874*cdf0e10cSrcweir     }
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir     return bRet;
877*cdf0e10cSrcweir }
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir 
880