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