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