1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22*a0b927b4Smseidel
23*a0b927b4Smseidel
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #define _SVSTDARR_STRINGS
28cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h>
29cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
30cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifier.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp>
32cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
33cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
34cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hdl>
35cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
36cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
39cdf0e10cSrcweir #include <comphelper/types.hxx>
40cdf0e10cSrcweir #include <tools/urlobj.hxx>
41cdf0e10cSrcweir #include <tools/datetime.hxx>
42cdf0e10cSrcweir #include <tools/debug.hxx>
43cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
44cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
45cdf0e10cSrcweir #include <ucbhelper/content.hxx>
46cdf0e10cSrcweir #include <svl/svstdarr.hxx>
47cdf0e10cSrcweir #include <swunohelper.hxx>
48cdf0e10cSrcweir #include <swunodef.hxx>
49cdf0e10cSrcweir #include <errhdl.hxx>
50cdf0e10cSrcweir
5156b35d86SArmin Le Grand //UUUU
5256b35d86SArmin Le Grand #include <svx/xfillit0.hxx>
5356b35d86SArmin Le Grand #include <svl/itemset.hxx>
5456b35d86SArmin Le Grand
5556b35d86SArmin Le Grand namespace SWUnoHelper
5656b35d86SArmin Le Grand {
57cdf0e10cSrcweir
GetEnumAsInt32(const UNO_NMSPC::Any & rVal)58cdf0e10cSrcweir sal_Int32 GetEnumAsInt32( const UNO_NMSPC::Any& rVal )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir sal_Int32 eVal;
61cdf0e10cSrcweir try
62cdf0e10cSrcweir {
63cdf0e10cSrcweir eVal = comphelper::getEnumAsINT32( rVal );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir catch( UNO_NMSPC::Exception & )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir eVal = 0;
68cdf0e10cSrcweir ASSERT( sal_False, "can't get EnumAsInt32" );
69cdf0e10cSrcweir }
70cdf0e10cSrcweir return eVal;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
73cdf0e10cSrcweir
74cdf0e10cSrcweir // methods for UCB actions
UCB_DeleteFile(const String & rURL)75cdf0e10cSrcweir sal_Bool UCB_DeleteFile( const String& rURL )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir sal_Bool bRemoved;
78cdf0e10cSrcweir try
79cdf0e10cSrcweir {
80cdf0e10cSrcweir ucbhelper::Content aTempContent( rURL,
81cdf0e10cSrcweir STAR_REFERENCE( ucb::XCommandEnvironment )());
82cdf0e10cSrcweir aTempContent.executeCommand(
83cdf0e10cSrcweir rtl::OUString::createFromAscii( "delete" ),
84cdf0e10cSrcweir UNO_NMSPC::makeAny( sal_Bool( sal_True ) ) );
85cdf0e10cSrcweir bRemoved = sal_True;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir catch( UNO_NMSPC::Exception& )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir bRemoved = sal_False;
90*a0b927b4Smseidel ASSERT( sal_False, "Exception from executeCommand( delete )" );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir return bRemoved;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
UCB_CopyFile(const String & rURL,const String & rNewURL,sal_Bool bCopyIsMove)95cdf0e10cSrcweir sal_Bool UCB_CopyFile( const String& rURL, const String& rNewURL, sal_Bool bCopyIsMove )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir sal_Bool bCopyCompleted = sal_True;
98cdf0e10cSrcweir try
99cdf0e10cSrcweir {
100cdf0e10cSrcweir INetURLObject aURL( rNewURL );
101cdf0e10cSrcweir String sName( aURL.GetName() );
102cdf0e10cSrcweir aURL.removeSegment();
103cdf0e10cSrcweir String sMainURL( aURL.GetMainURL(INetURLObject::NO_DECODE) );
104cdf0e10cSrcweir
105cdf0e10cSrcweir ucbhelper::Content aTempContent( sMainURL,
106cdf0e10cSrcweir STAR_REFERENCE( ucb::XCommandEnvironment )());
107cdf0e10cSrcweir
108cdf0e10cSrcweir UNO_NMSPC::Any aAny;
109cdf0e10cSrcweir STAR_NMSPC::ucb::TransferInfo aInfo;
110cdf0e10cSrcweir aInfo.NameClash = STAR_NMSPC::ucb::NameClash::ERROR;
111cdf0e10cSrcweir aInfo.NewTitle = sName;
112cdf0e10cSrcweir aInfo.SourceURL = rURL;
113cdf0e10cSrcweir aInfo.MoveData = bCopyIsMove;
114cdf0e10cSrcweir aAny <<= aInfo;
115cdf0e10cSrcweir aTempContent.executeCommand(
116cdf0e10cSrcweir rtl::OUString::createFromAscii( "transfer" ),
117cdf0e10cSrcweir aAny );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir catch( UNO_NMSPC::Exception& )
120cdf0e10cSrcweir {
121*a0b927b4Smseidel ASSERT( sal_False, "Exception from executeCommand( transfer )" );
122cdf0e10cSrcweir bCopyCompleted = sal_False;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir return bCopyCompleted;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
UCB_IsCaseSensitiveFileName(const String & rURL)127cdf0e10cSrcweir sal_Bool UCB_IsCaseSensitiveFileName( const String& rURL )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir sal_Bool bCaseSensitive;
130cdf0e10cSrcweir try
131cdf0e10cSrcweir {
132cdf0e10cSrcweir STAR_REFERENCE( lang::XMultiServiceFactory ) xMSF =
133cdf0e10cSrcweir comphelper::getProcessServiceFactory();
134cdf0e10cSrcweir
135cdf0e10cSrcweir INetURLObject aTempObj( rURL );
136cdf0e10cSrcweir aTempObj.SetBase( aTempObj.GetBase().toAsciiLowerCase() );
137cdf0e10cSrcweir STAR_REFERENCE( ucb::XContentIdentifier ) xRef1 = new
138cdf0e10cSrcweir ucbhelper::ContentIdentifier( xMSF,
139cdf0e10cSrcweir aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
140cdf0e10cSrcweir
141cdf0e10cSrcweir aTempObj.SetBase(aTempObj.GetBase().toAsciiUpperCase());
142cdf0e10cSrcweir STAR_REFERENCE( ucb::XContentIdentifier ) xRef2 = new
143cdf0e10cSrcweir ucbhelper::ContentIdentifier( xMSF,
144cdf0e10cSrcweir aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
145cdf0e10cSrcweir
146cdf0e10cSrcweir STAR_REFERENCE( ucb::XContentProvider ) xProv =
147cdf0e10cSrcweir ucbhelper::ContentBroker::get()->getContentProviderInterface();
148cdf0e10cSrcweir
149cdf0e10cSrcweir sal_Int32 nCompare = xProv->compareContentIds( xRef1, xRef2 );
150cdf0e10cSrcweir bCaseSensitive = 0 != nCompare;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir catch( UNO_NMSPC::Exception& )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir bCaseSensitive = sal_False;
155*a0b927b4Smseidel ASSERT( sal_False, "Exception from compareContentIds()" );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir return bCaseSensitive;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
UCB_IsReadOnlyFileName(const String & rURL)160cdf0e10cSrcweir sal_Bool UCB_IsReadOnlyFileName( const String& rURL )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir sal_Bool bIsReadOnly = sal_False;
163cdf0e10cSrcweir try
164cdf0e10cSrcweir {
165cdf0e10cSrcweir ucbhelper::Content aCnt( rURL, STAR_REFERENCE( ucb::XCommandEnvironment )());
166cdf0e10cSrcweir UNO_NMSPC::Any aAny = aCnt.getPropertyValue(
167cdf0e10cSrcweir rtl::OUString::createFromAscii( "IsReadOnly" ));
168cdf0e10cSrcweir if(aAny.hasValue())
169cdf0e10cSrcweir bIsReadOnly = *(sal_Bool*)aAny.getValue();
170cdf0e10cSrcweir }
171cdf0e10cSrcweir catch( UNO_NMSPC::Exception& )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir bIsReadOnly = sal_False;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir return bIsReadOnly;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
UCB_IsFile(const String & rURL)178cdf0e10cSrcweir sal_Bool UCB_IsFile( const String& rURL )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir sal_Bool bExists = sal_False;
181cdf0e10cSrcweir try
182cdf0e10cSrcweir {
183cdf0e10cSrcweir ::ucbhelper::Content aContent( rURL, STAR_REFERENCE( ucb::XCommandEnvironment )() );
184cdf0e10cSrcweir bExists = aContent.isDocument();
185cdf0e10cSrcweir }
186cdf0e10cSrcweir catch (UNO_NMSPC::Exception &)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir }
189cdf0e10cSrcweir return bExists;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
UCB_IsDirectory(const String & rURL)192cdf0e10cSrcweir sal_Bool UCB_IsDirectory( const String& rURL )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir sal_Bool bExists = sal_False;
195cdf0e10cSrcweir try
196cdf0e10cSrcweir {
197cdf0e10cSrcweir ::ucbhelper::Content aContent( rURL, STAR_REFERENCE( ucb::XCommandEnvironment )() );
198cdf0e10cSrcweir bExists = aContent.isFolder();
199cdf0e10cSrcweir }
200cdf0e10cSrcweir catch (UNO_NMSPC::Exception &)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir }
203cdf0e10cSrcweir return bExists;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir // get a list of files from the folder of the URL
207cdf0e10cSrcweir // options: pExtension = 0 -> all, else this specific extension
208cdf0e10cSrcweir // pDateTime != 0 -> returns also the modified date/time of
209cdf0e10cSrcweir // the files in a SvPtrarr -->
210cdf0e10cSrcweir // !! objects must be deleted from the caller!!
UCB_GetFileListOfFolder(const String & rURL,SvStrings & rList,const String * pExtension,SvPtrarr * pDateTimeList)211cdf0e10cSrcweir sal_Bool UCB_GetFileListOfFolder( const String& rURL, SvStrings& rList,
212cdf0e10cSrcweir const String* pExtension,
213cdf0e10cSrcweir SvPtrarr* pDateTimeList )
214cdf0e10cSrcweir {
215cdf0e10cSrcweir sal_Bool bOk = sal_False;
216cdf0e10cSrcweir try
217cdf0e10cSrcweir {
218cdf0e10cSrcweir ucbhelper::Content aCnt( rURL, STAR_REFERENCE( ucb::XCommandEnvironment )());
219cdf0e10cSrcweir STAR_REFERENCE( sdbc::XResultSet ) xResultSet;
220cdf0e10cSrcweir
221cdf0e10cSrcweir sal_uInt16 nSeqSize = pDateTimeList ? 2 : 1;
222cdf0e10cSrcweir UNO_NMSPC::Sequence < rtl::OUString > aProps( nSeqSize );
223cdf0e10cSrcweir rtl::OUString* pProps = aProps.getArray();
224cdf0e10cSrcweir pProps[ 0 ] = rtl::OUString::createFromAscii( "Title" );
225cdf0e10cSrcweir if( pDateTimeList )
226cdf0e10cSrcweir pProps[ 1 ] = rtl::OUString::createFromAscii( "DateModified" );
227cdf0e10cSrcweir
228cdf0e10cSrcweir try
229cdf0e10cSrcweir {
230cdf0e10cSrcweir xResultSet = aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
231cdf0e10cSrcweir }
232cdf0e10cSrcweir catch( UNO_NMSPC::Exception& )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir DBG_ERRORFILE( "create cursor failed!" );
235cdf0e10cSrcweir }
236cdf0e10cSrcweir
237cdf0e10cSrcweir if( xResultSet.is() )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir STAR_REFERENCE( sdbc::XRow ) xRow( xResultSet, UNO_NMSPC::UNO_QUERY );
240cdf0e10cSrcweir xub_StrLen nExtLen = pExtension ? pExtension->Len() : 0;
241cdf0e10cSrcweir try
242cdf0e10cSrcweir {
243cdf0e10cSrcweir if( xResultSet->first() )
244cdf0e10cSrcweir {
245cdf0e10cSrcweir do {
246cdf0e10cSrcweir String sTitle( xRow->getString( 1 ) );
247cdf0e10cSrcweir if( !nExtLen ||
248cdf0e10cSrcweir ( sTitle.Len() > nExtLen &&
249cdf0e10cSrcweir sTitle.Equals( *pExtension,
250cdf0e10cSrcweir sTitle.Len() - nExtLen, nExtLen )) )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir String* pStr = new String( sTitle );
253cdf0e10cSrcweir rList.Insert( pStr, rList.Count() );
254cdf0e10cSrcweir
255cdf0e10cSrcweir if( pDateTimeList )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir STAR_NMSPC::util::DateTime aStamp = xRow->getTimestamp(2);
258cdf0e10cSrcweir ::DateTime* pDateTime = new ::DateTime(
259cdf0e10cSrcweir ::Date( aStamp.Day,
260cdf0e10cSrcweir aStamp.Month,
261cdf0e10cSrcweir aStamp.Year ),
262cdf0e10cSrcweir ::Time( aStamp.Hours,
263cdf0e10cSrcweir aStamp.Minutes,
264cdf0e10cSrcweir aStamp.Seconds,
265cdf0e10cSrcweir aStamp.HundredthSeconds ));
266cdf0e10cSrcweir void* p = pDateTime;
267cdf0e10cSrcweir pDateTimeList->Insert( p,
268cdf0e10cSrcweir pDateTimeList->Count() );
269cdf0e10cSrcweir }
270cdf0e10cSrcweir }
271cdf0e10cSrcweir
272cdf0e10cSrcweir } while( xResultSet->next() );
273cdf0e10cSrcweir }
274cdf0e10cSrcweir bOk = sal_True;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir catch( UNO_NMSPC::Exception& )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir DBG_ERRORFILE( "Exception caught!" );
279cdf0e10cSrcweir }
280cdf0e10cSrcweir }
281cdf0e10cSrcweir }
282cdf0e10cSrcweir catch( UNO_NMSPC::Exception& )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir DBG_ERRORFILE( "Exception caught!" );
285cdf0e10cSrcweir bOk = sal_False;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir return bOk;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir
29056b35d86SArmin Le Grand //UUUU
needToMapFillItemsToSvxBrushItemTypes(const SfxItemSet & rSet)29156b35d86SArmin Le Grand bool needToMapFillItemsToSvxBrushItemTypes(const SfxItemSet& rSet)
29256b35d86SArmin Le Grand {
29356b35d86SArmin Le Grand const XFillStyleItem* pXFillStyleItem(static_cast< const XFillStyleItem* >(rSet.GetItem(XATTR_FILLSTYLE, false)));
29456b35d86SArmin Le Grand
29556b35d86SArmin Le Grand if(!pXFillStyleItem)
29656b35d86SArmin Le Grand {
29756b35d86SArmin Le Grand return false;
298cdf0e10cSrcweir }
29956b35d86SArmin Le Grand
30056b35d86SArmin Le Grand // here different FillStyles can be excluded for export; it will depend on the
30156b35d86SArmin Le Grand // quality these fallbacks can reach. That again is done in getSvxBrushItemFromSourceSet,
30256b35d86SArmin Le Grand // take a look there how the superset of DrawObject FillStyles is mapped to SvxBrushItem.
30356b35d86SArmin Le Grand // For now, take them all - except XFILL_NONE
30456b35d86SArmin Le Grand
30556b35d86SArmin Le Grand if(XFILL_NONE != pXFillStyleItem->GetValue())
30656b35d86SArmin Le Grand {
30756b35d86SArmin Le Grand return true;
30856b35d86SArmin Le Grand }
30956b35d86SArmin Le Grand
31056b35d86SArmin Le Grand // if(XFILL_SOLID == pXFillStyleItem->GetValue() || XFILL_BITMAP == pXFillStyleItem->GetValue())
31156b35d86SArmin Le Grand // {
31256b35d86SArmin Le Grand // return true;
31356b35d86SArmin Le Grand // }
31456b35d86SArmin Le Grand
31556b35d86SArmin Le Grand return false;
31656b35d86SArmin Le Grand }
31756b35d86SArmin Le Grand
31856b35d86SArmin Le Grand }
31956b35d86SArmin Le Grand
32056b35d86SArmin Le Grand // eof
321