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