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_unotools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "unotools/ucbhelper.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/XContentIdentifierFactory.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandProcessor.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/ucb/IllegalIdentifierException.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/ucb/NumberedSortingInfo.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/ucb/XAnyCompareFactory.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfo.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/ucb/XDynamicResultSet.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 54*cdf0e10cSrcweir #include <ucbhelper/commandenvironment.hxx> 55*cdf0e10cSrcweir #include <ucbhelper/content.hxx> 56*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 57*cdf0e10cSrcweir #include <osl/file.hxx> 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir #include <tools/wldcrd.hxx> 60*cdf0e10cSrcweir #include <tools/ref.hxx> 61*cdf0e10cSrcweir #include <tools/debug.hxx> 62*cdf0e10cSrcweir #include <tools/urlobj.hxx> 63*cdf0e10cSrcweir #include <tools/datetime.hxx> 64*cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx> 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir #include "unotools/localfilehelper.hxx" 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir using namespace ucbhelper; 69*cdf0e10cSrcweir using namespace com::sun::star; 70*cdf0e10cSrcweir using namespace com::sun::star::beans; 71*cdf0e10cSrcweir using namespace com::sun::star::container; 72*cdf0e10cSrcweir using namespace com::sun::star::lang; 73*cdf0e10cSrcweir using namespace com::sun::star::sdbc; 74*cdf0e10cSrcweir using namespace com::sun::star::task; 75*cdf0e10cSrcweir using namespace com::sun::star::uno; 76*cdf0e10cSrcweir using namespace com::sun::star::ucb; 77*cdf0e10cSrcweir using namespace rtl; 78*cdf0e10cSrcweir using namespace comphelper; 79*cdf0e10cSrcweir using namespace osl; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir DECLARE_LIST( StringList_Impl, OUString* ) 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir #define CONVERT_DATETIME( aUnoDT, aToolsDT ) \ 84*cdf0e10cSrcweir aToolsDT = DateTime( Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ), \ 85*cdf0e10cSrcweir Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ) ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir namespace utl 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir sal_Bool UCBContentHelper::Transfer_Impl( const String& rSource, const String& rDest, sal_Bool bMoveData, sal_Int32 nNameClash ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir sal_Bool bRet = sal_True, bKillSource = sal_False; 93*cdf0e10cSrcweir INetURLObject aSourceObj( rSource ); 94*cdf0e10cSrcweir DBG_ASSERT( aSourceObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir INetURLObject aDestObj( rDest ); 97*cdf0e10cSrcweir DBG_ASSERT( aDestObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 98*cdf0e10cSrcweir if ( bMoveData && aSourceObj.GetProtocol() != aDestObj.GetProtocol() ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir bMoveData = sal_False; 101*cdf0e10cSrcweir bKillSource = sal_True; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir String aName = aDestObj.getName(); 104*cdf0e10cSrcweir aDestObj.removeSegment(); 105*cdf0e10cSrcweir aDestObj.setFinalSlash(); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir try 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir Content aDestPath( aDestObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 110*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandInfo > xInfo = aDestPath.getCommands(); 111*cdf0e10cSrcweir OUString aTransferName = OUString::createFromAscii( "transfer" ); 112*cdf0e10cSrcweir if ( xInfo->hasCommandByName( aTransferName ) ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir aDestPath.executeCommand( aTransferName, makeAny( 115*cdf0e10cSrcweir ::com::sun::star::ucb::TransferInfo( bMoveData, aSourceObj.GetMainURL( INetURLObject::NO_DECODE ), aName, nNameClash ) ) ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir else 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir DBG_ERRORFILE( "transfer command not available" ); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir bRet = sal_False; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir bRet = sal_False; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir if ( bKillSource ) 132*cdf0e10cSrcweir UCBContentHelper::Kill( rSource ); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir return bRet; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // ----------------------------------------------------------------------- 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir sal_Bool UCBContentHelper::IsDocument( const String& rContent ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir sal_Bool bRet = sal_False; 142*cdf0e10cSrcweir INetURLObject aObj( rContent ); 143*cdf0e10cSrcweir DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir try 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 148*cdf0e10cSrcweir bRet = aCnt.isDocument(); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir DBG_WARNING( "CommandAbortedException" ); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir catch( ::com::sun::star::ucb::IllegalIdentifierException& ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir DBG_WARNING( "IllegalIdentifierException" ); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir catch( ContentCreationException& ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir DBG_WARNING( "IllegalIdentifierException" ); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir DBG_WARNING( "Any other exception" ); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir return bRet; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // ----------------------------------------------------------------------- 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir Any UCBContentHelper::GetProperty( const String& rContent, const ::rtl::OUString& rName ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir INetURLObject aObj( rContent ); 175*cdf0e10cSrcweir DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 176*cdf0e10cSrcweir try 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 179*cdf0e10cSrcweir return aCnt.getPropertyValue( rName ); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir DBG_WARNING( "CommandAbortedException" ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir catch( ::com::sun::star::ucb::IllegalIdentifierException& ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir DBG_WARNING( "IllegalIdentifierException" ); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir catch( ContentCreationException& ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir DBG_WARNING( "IllegalIdentifierException" ); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir DBG_WARNING( "Any other exception" ); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir return Any(); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir sal_Bool UCBContentHelper::IsFolder( const String& rContent ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir sal_Bool bRet = sal_False; 204*cdf0e10cSrcweir INetURLObject aObj( rContent ); 205*cdf0e10cSrcweir DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 206*cdf0e10cSrcweir try 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 209*cdf0e10cSrcweir bRet = aCnt.isFolder(); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir DBG_WARNING( "CommandAbortedException" ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir catch( ::com::sun::star::ucb::IllegalIdentifierException& ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir DBG_WARNING( "IllegalIdentifierException" ); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir catch( ContentCreationException& ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir DBG_WARNING( "IllegalIdentifierException" ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir DBG_WARNING( "Any other exception" ); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir return bRet; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir // ----------------------------------------------------------------------- 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir sal_Bool UCBContentHelper::GetTitle( const String& rContent, String& rTitle ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir sal_Bool bRet = sal_False; 236*cdf0e10cSrcweir INetURLObject aObj( rContent ); 237*cdf0e10cSrcweir DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 238*cdf0e10cSrcweir try 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 241*cdf0e10cSrcweir OUString aTemp; 242*cdf0e10cSrcweir if ( aCnt.getPropertyValue( OUString::createFromAscii( "Title" ) ) >>= aTemp ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir rTitle = String( aTemp ); 245*cdf0e10cSrcweir bRet = sal_True; 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir return bRet; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir // ----------------------------------------------------------------------- 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir sal_Bool UCBContentHelper::Kill( const String& rContent ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir sal_Bool bRet = sal_True; 262*cdf0e10cSrcweir INetURLObject aDeleteObj( rContent ); 263*cdf0e10cSrcweir DBG_ASSERT( aDeleteObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir try 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir Content aCnt( aDeleteObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 268*cdf0e10cSrcweir aCnt.executeCommand( OUString::createFromAscii( "delete" ), makeAny( sal_Bool( sal_True ) ) ); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir DBG_WARNING( "CommandAbortedException" ); 273*cdf0e10cSrcweir bRet = sal_False; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir DBG_WARNING( "Any other exception" ); 278*cdf0e10cSrcweir bRet = sal_False; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir return bRet; 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir // ----------------------------------------------------------------------- 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir Sequence < OUString > UCBContentHelper::GetFolderContents( const String& rFolder, sal_Bool bFolder, sal_Bool bSorted ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir StringList_Impl* pFiles = NULL; 289*cdf0e10cSrcweir INetURLObject aFolderObj( rFolder ); 290*cdf0e10cSrcweir DBG_ASSERT( aFolderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 291*cdf0e10cSrcweir try 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 294*cdf0e10cSrcweir uno::Reference< XResultSet > xResultSet; 295*cdf0e10cSrcweir Sequence< OUString > aProps( bSorted ? 2 : 1 ); 296*cdf0e10cSrcweir OUString* pProps = aProps.getArray(); 297*cdf0e10cSrcweir pProps[0] = OUString::createFromAscii( "Title" ); 298*cdf0e10cSrcweir if ( bSorted ) 299*cdf0e10cSrcweir pProps[1] = OUString::createFromAscii( "IsFolder" ); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir try 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir ResultSetInclude eInclude = bFolder ? INCLUDE_FOLDERS_AND_DOCUMENTS : INCLUDE_DOCUMENTS_ONLY; 304*cdf0e10cSrcweir if ( !bSorted ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir xResultSet = aCnt.createCursor( aProps, eInclude ); 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir else 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XDynamicResultSet > xDynResultSet; 311*cdf0e10cSrcweir xDynResultSet = aCnt.createDynamicCursor( aProps, eInclude ); 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir uno::Reference < com::sun::star::ucb::XAnyCompareFactory > xFactory; 314*cdf0e10cSrcweir uno::Reference < XMultiServiceFactory > xMgr = getProcessServiceFactory(); 315*cdf0e10cSrcweir uno::Reference < com::sun::star::ucb::XSortedDynamicResultSetFactory > xSRSFac( 316*cdf0e10cSrcweir xMgr->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.ucb.SortedDynamicResultSetFactory") ), UNO_QUERY ); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir Sequence< com::sun::star::ucb::NumberedSortingInfo > aSortInfo( 2 ); 319*cdf0e10cSrcweir com::sun::star::ucb::NumberedSortingInfo* pInfo = aSortInfo.getArray(); 320*cdf0e10cSrcweir pInfo[ 0 ].ColumnIndex = 2; 321*cdf0e10cSrcweir pInfo[ 0 ].Ascending = sal_False; 322*cdf0e10cSrcweir pInfo[ 1 ].ColumnIndex = 1; 323*cdf0e10cSrcweir pInfo[ 1 ].Ascending = sal_True; 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XDynamicResultSet > xDynamicResultSet; 326*cdf0e10cSrcweir xDynamicResultSet = 327*cdf0e10cSrcweir xSRSFac->createSortedDynamicResultSet( xDynResultSet, aSortInfo, xFactory ); 328*cdf0e10cSrcweir if ( xDynamicResultSet.is() ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir xResultSet = xDynamicResultSet->getStaticResultSet(); 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir // folder not exists? 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir if ( xResultSet.is() ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir pFiles = new StringList_Impl; 345*cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XContentAccess > xContentAccess( xResultSet, UNO_QUERY ); 346*cdf0e10cSrcweir try 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir while ( xResultSet->next() ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir OUString aId = xContentAccess->queryContentIdentifierString(); 351*cdf0e10cSrcweir OUString* pFile = new OUString( aId ); 352*cdf0e10cSrcweir pFiles->Insert( pFile, LIST_APPEND ); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir if ( pFiles ) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir sal_uLong nCount = pFiles->Count(); 370*cdf0e10cSrcweir Sequence < OUString > aRet( nCount ); 371*cdf0e10cSrcweir OUString* pRet = aRet.getArray(); 372*cdf0e10cSrcweir for ( sal_uLong i = 0; i < nCount; ++i ) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir OUString* pFile = pFiles->GetObject(i); 375*cdf0e10cSrcweir pRet[i] = *( pFile ); 376*cdf0e10cSrcweir delete pFile; 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir delete pFiles; 379*cdf0e10cSrcweir return aRet; 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir else 382*cdf0e10cSrcweir return Sequence < OUString > (); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir // ----------------------------------------------------------------------- 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir Sequence < OUString > UCBContentHelper::GetResultSet( const String& rURL ) 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir StringList_Impl* pList = NULL; 390*cdf0e10cSrcweir try 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir Content aCnt( rURL, uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ); 393*cdf0e10cSrcweir uno::Reference< XResultSet > xResultSet; 394*cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XDynamicResultSet > xDynResultSet; 395*cdf0e10cSrcweir Sequence< OUString > aProps(3); 396*cdf0e10cSrcweir OUString* pProps = aProps.getArray(); 397*cdf0e10cSrcweir pProps[0] = OUString::createFromAscii( "Title" ); 398*cdf0e10cSrcweir pProps[1] = OUString::createFromAscii( "ContentType" ); 399*cdf0e10cSrcweir // TODO: can be optimized, property never used: 400*cdf0e10cSrcweir pProps[2] = OUString::createFromAscii( "IsFolder" ); 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir try 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir xDynResultSet = aCnt.createDynamicCursor( aProps, INCLUDE_FOLDERS_AND_DOCUMENTS ); 405*cdf0e10cSrcweir if ( xDynResultSet.is() ) 406*cdf0e10cSrcweir xResultSet = xDynResultSet->getStaticResultSet(); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir if ( xResultSet.is() ) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir pList = new StringList_Impl; 418*cdf0e10cSrcweir uno::Reference< com::sun::star::sdbc::XRow > xRow( xResultSet, UNO_QUERY ); 419*cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XContentAccess > xContentAccess( xResultSet, UNO_QUERY ); 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir try 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir while ( xResultSet->next() ) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir String aTitle( xRow->getString(1) ); 426*cdf0e10cSrcweir String aType( xRow->getString(2) ); 427*cdf0e10cSrcweir String aRow = aTitle; 428*cdf0e10cSrcweir aRow += '\t'; 429*cdf0e10cSrcweir aRow += aType; 430*cdf0e10cSrcweir aRow += '\t'; 431*cdf0e10cSrcweir aRow += String( xContentAccess->queryContentIdentifierString() ); 432*cdf0e10cSrcweir OUString* pRow = new OUString( aRow ); 433*cdf0e10cSrcweir pList->Insert( pRow, LIST_APPEND ); 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 440*cdf0e10cSrcweir { 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir if ( pList ) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir sal_uLong nCount = pList->Count(); 451*cdf0e10cSrcweir Sequence < OUString > aRet( nCount ); 452*cdf0e10cSrcweir OUString* pRet = aRet.getArray(); 453*cdf0e10cSrcweir for ( sal_uLong i = 0; i < nCount; ++i ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir OUString* pEntry = pList->GetObject(i); 456*cdf0e10cSrcweir pRet[i] = *( pEntry ); 457*cdf0e10cSrcweir delete pEntry; 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir delete pList; 460*cdf0e10cSrcweir return aRet; 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir else 463*cdf0e10cSrcweir return Sequence < OUString > (); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir // ----------------------------------------------------------------------- 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir sal_Bool UCBContentHelper::CopyTo( const String& rSource, const String& rDest ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir return Transfer_Impl( rSource, rDest, sal_False, NameClash::ERROR ); 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir // ----------------------------------------------------------------------- 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir sal_Bool UCBContentHelper::MoveTo( const String& rSource, const String& rDest, sal_Int32 nNameClash ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir return Transfer_Impl( rSource, rDest, sal_True, nNameClash ); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir // ----------------------------------------------------------------------- 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir sal_Bool UCBContentHelper::CanMakeFolder( const String& rFolder ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir try 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir Content aCnt( rFolder, uno::Reference< XCommandEnvironment > () ); 487*cdf0e10cSrcweir Sequence< ContentInfo > aInfo = aCnt.queryCreatableContentsInfo(); 488*cdf0e10cSrcweir sal_Int32 nCount = aInfo.getLength(); 489*cdf0e10cSrcweir if ( nCount == 0 ) 490*cdf0e10cSrcweir return sal_False; 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i ) 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir // Simply look for the first KIND_FOLDER... 495*cdf0e10cSrcweir const ContentInfo & rCurr = aInfo[i]; 496*cdf0e10cSrcweir if ( rCurr.Attributes & ContentInfoAttribute::KIND_FOLDER ) 497*cdf0e10cSrcweir return sal_True; 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) {} 501*cdf0e10cSrcweir catch( RuntimeException& ) {} 502*cdf0e10cSrcweir catch( Exception& ) {} 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir return sal_False; 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir // ----------------------------------------------------------------------- 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir sal_Bool UCBContentHelper::MakeFolder( const String& rFolder, sal_Bool bNewOnly ) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir INetURLObject aURL( rFolder ); 512*cdf0e10cSrcweir DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 513*cdf0e10cSrcweir String aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 514*cdf0e10cSrcweir aURL.removeSegment(); 515*cdf0e10cSrcweir Content aCnt; 516*cdf0e10cSrcweir Content aNew; 517*cdf0e10cSrcweir uno::Reference< XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); 518*cdf0e10cSrcweir uno::Reference< XInteractionHandler > xInteractionHandler = uno::Reference< XInteractionHandler > ( 519*cdf0e10cSrcweir xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uui.InteractionHandler") ) ), UNO_QUERY ); 520*cdf0e10cSrcweir if ( Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ), new CommandEnvironment( xInteractionHandler, uno::Reference< XProgressHandler >() ), aCnt ) ) 521*cdf0e10cSrcweir return MakeFolder( aCnt, aTitle, aNew, bNewOnly ); 522*cdf0e10cSrcweir else 523*cdf0e10cSrcweir return sal_False; 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir sal_Bool UCBContentHelper::MakeFolder( Content& aCnt, const String& aTitle, Content& rNew, sal_Bool bNewOnly ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir sal_Bool bAlreadyExists = sal_False; 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir try 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir Sequence< ContentInfo > aInfo = aCnt.queryCreatableContentsInfo(); 533*cdf0e10cSrcweir sal_Int32 nCount = aInfo.getLength(); 534*cdf0e10cSrcweir if ( nCount == 0 ) 535*cdf0e10cSrcweir return sal_False; 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i ) 538*cdf0e10cSrcweir { 539*cdf0e10cSrcweir // Simply look for the first KIND_FOLDER... 540*cdf0e10cSrcweir const ContentInfo & rCurr = aInfo[i]; 541*cdf0e10cSrcweir if ( rCurr.Attributes & ContentInfoAttribute::KIND_FOLDER ) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir // Make sure the only required bootstrap property is "Title", 544*cdf0e10cSrcweir const Sequence< Property > & rProps = rCurr.Properties; 545*cdf0e10cSrcweir if ( rProps.getLength() != 1 ) 546*cdf0e10cSrcweir continue; 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir if ( !rProps[ 0 ].Name.equalsAsciiL( 549*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) 550*cdf0e10cSrcweir continue; 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir Sequence<OUString> aNames(1); 553*cdf0e10cSrcweir OUString* pNames = aNames.getArray(); 554*cdf0e10cSrcweir pNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ); 555*cdf0e10cSrcweir Sequence<Any> aValues(1); 556*cdf0e10cSrcweir Any* pValues = aValues.getArray(); 557*cdf0e10cSrcweir pValues[0] = makeAny( OUString( aTitle ) ); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir if ( !aCnt.insertNewContent( rCurr.Type, aNames, aValues, rNew ) ) 560*cdf0e10cSrcweir continue; 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir return sal_True; 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir catch ( InteractiveIOException& r ) 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir if ( r.Code == IOErrorCode_ALREADY_EXISTING ) 569*cdf0e10cSrcweir { 570*cdf0e10cSrcweir bAlreadyExists = sal_True; 571*cdf0e10cSrcweir } 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir catch ( NameClashException& ) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir bAlreadyExists = sal_True; 576*cdf0e10cSrcweir } 577*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir catch( RuntimeException& ) 581*cdf0e10cSrcweir { 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir catch( Exception& ) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir if( bAlreadyExists && !bNewOnly ) 588*cdf0e10cSrcweir { 589*cdf0e10cSrcweir INetURLObject aObj( aCnt.getURL() ); 590*cdf0e10cSrcweir aObj.Append( aTitle ); 591*cdf0e10cSrcweir rNew = Content( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference < XCommandEnvironment >() ); 592*cdf0e10cSrcweir return sal_True; 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir return sal_False; 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir // ----------------------------------------------------------------------- 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir sal_Bool UCBContentHelper::HasParentFolder( const String& rFolder ) 601*cdf0e10cSrcweir { 602*cdf0e10cSrcweir sal_Bool bRet = sal_False; 603*cdf0e10cSrcweir try 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir Content aCnt( rFolder, uno::Reference< XCommandEnvironment > () ); 606*cdf0e10cSrcweir uno::Reference< XChild > xChild( aCnt.get(), UNO_QUERY ); 607*cdf0e10cSrcweir if ( xChild.is() ) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir uno::Reference< XContent > xParent( xChild->getParent(), UNO_QUERY ); 610*cdf0e10cSrcweir if ( xParent.is() ) 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir String aParentURL = String( xParent->getIdentifier()->getContentIdentifier() ); 613*cdf0e10cSrcweir bRet = ( aParentURL.Len() > 0 && aParentURL != rFolder ); 614*cdf0e10cSrcweir } 615*cdf0e10cSrcweir } 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 618*cdf0e10cSrcweir { 619*cdf0e10cSrcweir } 620*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 621*cdf0e10cSrcweir { 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir return bRet; 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir // ----------------------------------------------------------------------- 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir sal_uLong UCBContentHelper::GetSize( const String& rContent ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir sal_uLong nSize = 0; 632*cdf0e10cSrcweir sal_Int64 nTemp = 0; 633*cdf0e10cSrcweir INetURLObject aObj( rContent ); 634*cdf0e10cSrcweir DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 635*cdf0e10cSrcweir try 636*cdf0e10cSrcweir { 637*cdf0e10cSrcweir Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 638*cdf0e10cSrcweir aCnt.getPropertyValue( OUString::createFromAscii( "Size" ) ) >>= nTemp; 639*cdf0e10cSrcweir } 640*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir } 643*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 644*cdf0e10cSrcweir { 645*cdf0e10cSrcweir } 646*cdf0e10cSrcweir nSize = (sal_uInt32)nTemp; 647*cdf0e10cSrcweir return nSize; 648*cdf0e10cSrcweir } 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir // ----------------------------------------------------------------------- 651*cdf0e10cSrcweir 652*cdf0e10cSrcweir sal_Bool UCBContentHelper::IsYounger( const String& rIsYoung, const String& rIsOlder ) 653*cdf0e10cSrcweir { 654*cdf0e10cSrcweir DateTime aYoungDate, aOlderDate; 655*cdf0e10cSrcweir INetURLObject aYoungObj( rIsYoung ); 656*cdf0e10cSrcweir DBG_ASSERT( aYoungObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 657*cdf0e10cSrcweir INetURLObject aOlderObj( rIsOlder ); 658*cdf0e10cSrcweir DBG_ASSERT( aOlderObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" ); 659*cdf0e10cSrcweir try 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > aCmdEnv; 662*cdf0e10cSrcweir Content aYoung( aYoungObj.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv ); 663*cdf0e10cSrcweir ::com::sun::star::util::DateTime aTempYoungDate; 664*cdf0e10cSrcweir aYoung.getPropertyValue( OUString::createFromAscii( "DateModified" ) ) >>= aTempYoungDate; 665*cdf0e10cSrcweir CONVERT_DATETIME( aTempYoungDate, aYoungDate ); 666*cdf0e10cSrcweir Content aOlder( aOlderObj.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv ); 667*cdf0e10cSrcweir ::com::sun::star::util::DateTime aTempOlderDate; 668*cdf0e10cSrcweir aOlder.getPropertyValue( OUString::createFromAscii( "DateModified" ) ) >>= aTempOlderDate; 669*cdf0e10cSrcweir CONVERT_DATETIME( aTempOlderDate, aOlderDate ); 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir catch( ::com::sun::star::ucb::CommandAbortedException& ) 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir } 674*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 675*cdf0e10cSrcweir { 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir return ( aYoungDate > aOlderDate ); 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir 681*cdf0e10cSrcweir // ----------------------------------------------------------------------- 682*cdf0e10cSrcweir sal_Bool UCBContentHelper::Find( const String& rFolder, const String& rName, String& rFile, sal_Bool bAllowWildCards ) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir sal_Bool bWild = bAllowWildCards && ( rName.Search( '*' ) != STRING_NOTFOUND || rName.Search( '?' ) != STRING_NOTFOUND ); 685*cdf0e10cSrcweir 686*cdf0e10cSrcweir sal_Bool bRet = sal_False; 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir // get a list of URLs for all children of rFolder 689*cdf0e10cSrcweir Sequence< ::rtl::OUString > aFiles = GetFolderContents( rFolder, sal_False ); 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir const ::rtl::OUString* pFiles = aFiles.getConstArray(); 692*cdf0e10cSrcweir sal_uInt32 i, nCount = aFiles.getLength(); 693*cdf0e10cSrcweir for ( i = 0; i < nCount; ++i ) 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir // get the last name of the URLs and compare it with rName 696*cdf0e10cSrcweir INetURLObject aFileObject( pFiles[i] ); 697*cdf0e10cSrcweir String aFile = aFileObject.getName( 698*cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ).toAsciiLowerCase(); 699*cdf0e10cSrcweir if ( (bWild && WildCard( rName ).Matches( aFile )) || aFile == rName ) 700*cdf0e10cSrcweir { 701*cdf0e10cSrcweir // names match 702*cdf0e10cSrcweir rFile = aFileObject.GetMainURL( INetURLObject::NO_DECODE ); 703*cdf0e10cSrcweir bRet = sal_True; 704*cdf0e10cSrcweir break; 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir return bRet; 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir 711*cdf0e10cSrcweir // ----------------------------------------------------------------------- 712*cdf0e10cSrcweir sal_Bool UCBContentHelper::Exists( const String& rURL ) 713*cdf0e10cSrcweir { 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir String sObjectPhysicalName; 716*cdf0e10cSrcweir sal_Bool bIsLocalFile = ::utl::LocalFileHelper::ConvertURLToPhysicalName( rURL, sObjectPhysicalName ); 717*cdf0e10cSrcweir // try to create a directory entry for the URL given 718*cdf0e10cSrcweir if ( bIsLocalFile ) 719*cdf0e10cSrcweir { 720*cdf0e10cSrcweir ::rtl::OUString sIn( sObjectPhysicalName ), sOut; 721*cdf0e10cSrcweir if ( osl_File_E_None == osl_getFileURLFromSystemPath( sIn.pData, &sOut.pData ) ) 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir // #106526 osl_getDirectoryItem is an existence check 724*cdf0e10cSrcweir // no further osl_getFileStatus call necessary 725*cdf0e10cSrcweir DirectoryItem aItem; 726*cdf0e10cSrcweir return (FileBase::E_None == DirectoryItem::get(sOut, aItem)); 727*cdf0e10cSrcweir } 728*cdf0e10cSrcweir return sal_False; 729*cdf0e10cSrcweir } 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir // divide URL into folder and name part 732*cdf0e10cSrcweir sal_Bool bRet = sal_False; 733*cdf0e10cSrcweir INetURLObject aObj( rURL ); 734*cdf0e10cSrcweir ::rtl::OUString aFileName = aObj.getName( 735*cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ).toAsciiLowerCase(); 736*cdf0e10cSrcweir aObj.removeSegment(); 737*cdf0e10cSrcweir aObj.removeFinalSlash(); 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir // get a list of URLs for all children of rFolder 740*cdf0e10cSrcweir Sequence< ::rtl::OUString > aFiles = GetFolderContents( aObj.GetMainURL( INetURLObject::NO_DECODE ), sal_True, sal_False ); 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir const ::rtl::OUString* pFiles = aFiles.getConstArray(); 743*cdf0e10cSrcweir sal_uInt32 i, nCount = aFiles.getLength(); 744*cdf0e10cSrcweir for ( i = 0; i < nCount; ++i ) 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir // get the last name of the URLs and compare it with rName 747*cdf0e10cSrcweir INetURLObject aFileObject( pFiles[i] ); 748*cdf0e10cSrcweir ::rtl::OUString aFile = aFileObject.getName( 749*cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ).toAsciiLowerCase(); 750*cdf0e10cSrcweir if ( aFile == aFileName ) 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir // names match 753*cdf0e10cSrcweir bRet = sal_True; 754*cdf0e10cSrcweir break; 755*cdf0e10cSrcweir } 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir return bRet; 759*cdf0e10cSrcweir } 760*cdf0e10cSrcweir 761*cdf0e10cSrcweir // ----------------------------------------------------------------------- 762*cdf0e10cSrcweir sal_Bool UCBContentHelper::FindInPath( const String& rPath, const String& rName, String& rFile, char cDelim, sal_Bool bAllowWildCards ) 763*cdf0e10cSrcweir { 764*cdf0e10cSrcweir // extract the single folder names from the path variable and try to find the file in one of these folders 765*cdf0e10cSrcweir sal_uInt16 nTokenCount = rPath.GetTokenCount( cDelim ); 766*cdf0e10cSrcweir for ( sal_uInt16 nToken = 0; nToken < nTokenCount; ++nToken ) 767*cdf0e10cSrcweir { 768*cdf0e10cSrcweir String aPath = rPath.GetToken( nToken, cDelim ); 769*cdf0e10cSrcweir if ( Find( aPath, rName, rFile, bAllowWildCards ) ) 770*cdf0e10cSrcweir return sal_True; 771*cdf0e10cSrcweir } 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir return sal_False; 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir 776*cdf0e10cSrcweir // ----------------------------------------------------------------------- 777*cdf0e10cSrcweir sal_Bool UCBContentHelper::IsSubPath( const ::rtl::OUString& rPath, const ::rtl::OUString& rSubfolderCandidate, const uno::Reference< ::com::sun::star::ucb::XContentProvider >& xProv ) 778*cdf0e10cSrcweir { 779*cdf0e10cSrcweir sal_Bool bResult = sal_False; 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XContentProvider > xContentProvider = xProv; 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir // the comparing is done in the following way: 784*cdf0e10cSrcweir // - first compare in case sensitive way 785*cdf0e10cSrcweir // - if name are different try a fallback comparing inf case insensitive way 786*cdf0e10cSrcweir // - if the last comparing succeeded get casepreserving normalized names for the files and compare them 787*cdf0e10cSrcweir // ( the second step is required because retrieving of the normalized names might be very expensive in some cases ) 788*cdf0e10cSrcweir 789*cdf0e10cSrcweir INetURLObject aCandidate( rSubfolderCandidate ); 790*cdf0e10cSrcweir INetURLObject aCandidateLowCase( rSubfolderCandidate.toAsciiLowerCase() ); // will be used for case insensitive comparing 791*cdf0e10cSrcweir INetURLObject aParentFolder( rPath ); 792*cdf0e10cSrcweir INetURLObject aParentFolderLowCase( rPath.toAsciiLowerCase() ); // will be used for case insensitive comparing 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir if ( aCandidate.GetProtocol() == aParentFolder.GetProtocol() ) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir if ( !xContentProvider.is() ) 797*cdf0e10cSrcweir { 798*cdf0e10cSrcweir ::ucbhelper::ContentBroker* pBroker = NULL; 799*cdf0e10cSrcweir if ( aCandidate.GetProtocol() == INET_PROT_FILE ) 800*cdf0e10cSrcweir { 801*cdf0e10cSrcweir pBroker = ::ucbhelper::ContentBroker::get(); 802*cdf0e10cSrcweir if ( pBroker ) 803*cdf0e10cSrcweir xContentProvider = pBroker->getContentProviderInterface(); 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir } 806*cdf0e10cSrcweir 807*cdf0e10cSrcweir INetURLObject aLastTmpObj; 808*cdf0e10cSrcweir do 809*cdf0e10cSrcweir { 810*cdf0e10cSrcweir if ( aParentFolder == aCandidate ) 811*cdf0e10cSrcweir { 812*cdf0e10cSrcweir // if case sensitive comparing succeeded there is no need for additional checks 813*cdf0e10cSrcweir bResult = sal_True; 814*cdf0e10cSrcweir } 815*cdf0e10cSrcweir else if ( xContentProvider.is() && aParentFolderLowCase == aCandidateLowCase ) 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir // the comparing was done using caseinsensitive way 818*cdf0e10cSrcweir // the case sensitive comparing have failed already 819*cdf0e10cSrcweir // the normalized urls must be retrieved 820*cdf0e10cSrcweir try 821*cdf0e10cSrcweir { 822*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XContent > xSecCont = 823*cdf0e10cSrcweir xContentProvider->queryContent( 824*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XContentIdentifierFactory >( 825*cdf0e10cSrcweir xContentProvider, ::com::sun::star::uno::UNO_QUERY_THROW )->createContentIdentifier( 826*cdf0e10cSrcweir aParentFolder.GetMainURL( INetURLObject::NO_DECODE ) ) ); 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XContent > xLocCont = 829*cdf0e10cSrcweir xContentProvider->queryContent( 830*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XContentIdentifierFactory >( 831*cdf0e10cSrcweir xContentProvider, ::com::sun::star::uno::UNO_QUERY_THROW )->createContentIdentifier( 832*cdf0e10cSrcweir aCandidate.GetMainURL( INetURLObject::NO_DECODE ) ) ); 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir if ( !xSecCont.is() || !xLocCont.is() ) 835*cdf0e10cSrcweir throw ::com::sun::star::uno::RuntimeException(); 836*cdf0e10cSrcweir 837*cdf0e10cSrcweir ::rtl::OUString aSecNormStr; 838*cdf0e10cSrcweir ::rtl::OUString aLocNormStr; 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir bResult = 841*cdf0e10cSrcweir ( ( uno::Reference< ::com::sun::star::ucb::XCommandProcessor >( 842*cdf0e10cSrcweir xSecCont, ::com::sun::star::uno::UNO_QUERY_THROW )->execute( 843*cdf0e10cSrcweir ::com::sun::star::ucb::Command( 844*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getCasePreservingURL" ) ), 845*cdf0e10cSrcweir -1, 846*cdf0e10cSrcweir ::com::sun::star::uno::Any() ), 847*cdf0e10cSrcweir 0, 848*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ) 849*cdf0e10cSrcweir >>= aSecNormStr ) 850*cdf0e10cSrcweir && ( uno::Reference< ::com::sun::star::ucb::XCommandProcessor >( 851*cdf0e10cSrcweir xLocCont, ::com::sun::star::uno::UNO_QUERY_THROW )->execute( 852*cdf0e10cSrcweir ::com::sun::star::ucb::Command( 853*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getCasePreservingURL" ) ), 854*cdf0e10cSrcweir -1, 855*cdf0e10cSrcweir ::com::sun::star::uno::Any() ), 856*cdf0e10cSrcweir 0, 857*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() ) 858*cdf0e10cSrcweir >>= aLocNormStr ) 859*cdf0e10cSrcweir && aLocNormStr.equals( aSecNormStr ) ); 860*cdf0e10cSrcweir } 861*cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 862*cdf0e10cSrcweir {} 863*cdf0e10cSrcweir } 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir // INetURLObject::removeSegment sometimes return true without exchanging URL, 866*cdf0e10cSrcweir // for example in case of "file:///" 867*cdf0e10cSrcweir aLastTmpObj = aCandidate; 868*cdf0e10cSrcweir 869*cdf0e10cSrcweir } while( aCandidate.removeSegment() && aCandidateLowCase.removeSegment() && aCandidate != aLastTmpObj && !bResult ); 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir 872*cdf0e10cSrcweir return bResult; 873*cdf0e10cSrcweir } 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir // ----------------------------------------------------------------------- 876*cdf0e10cSrcweir sal_Bool UCBContentHelper::EqualURLs( const ::rtl::OUString& aFirstURL, const ::rtl::OUString& aSecondURL ) 877*cdf0e10cSrcweir { 878*cdf0e10cSrcweir sal_Bool bResult = sal_False; 879*cdf0e10cSrcweir 880*cdf0e10cSrcweir if ( aFirstURL.getLength() && aSecondURL.getLength() ) 881*cdf0e10cSrcweir { 882*cdf0e10cSrcweir INetURLObject aFirst( aFirstURL ); 883*cdf0e10cSrcweir INetURLObject aSecond( aSecondURL ); 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir if ( aFirst.GetProtocol() != INET_PROT_NOT_VALID && aSecond.GetProtocol() != INET_PROT_NOT_VALID ) 886*cdf0e10cSrcweir { 887*cdf0e10cSrcweir try 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get(); 890*cdf0e10cSrcweir if ( !pBroker ) 891*cdf0e10cSrcweir throw uno::RuntimeException(); 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XContentIdentifierFactory > xIdFac 894*cdf0e10cSrcweir = pBroker->getContentIdentifierFactoryInterface(); 895*cdf0e10cSrcweir if ( !xIdFac.is() ) 896*cdf0e10cSrcweir throw uno::RuntimeException(); 897*cdf0e10cSrcweir 898*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xIdFirst 899*cdf0e10cSrcweir = xIdFac->createContentIdentifier( aFirst.GetMainURL( INetURLObject::NO_DECODE ) ); 900*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xIdSecond 901*cdf0e10cSrcweir = xIdFac->createContentIdentifier( aSecond.GetMainURL( INetURLObject::NO_DECODE ) ); 902*cdf0e10cSrcweir 903*cdf0e10cSrcweir if ( xIdFirst.is() && xIdSecond.is() ) 904*cdf0e10cSrcweir { 905*cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XContentProvider > xProvider = 906*cdf0e10cSrcweir pBroker->getContentProviderInterface(); 907*cdf0e10cSrcweir if ( !xProvider.is() ) 908*cdf0e10cSrcweir throw uno::RuntimeException(); 909*cdf0e10cSrcweir bResult = !xProvider->compareContentIds( xIdFirst, xIdSecond ); 910*cdf0e10cSrcweir } 911*cdf0e10cSrcweir } 912*cdf0e10cSrcweir catch( uno::Exception& ) 913*cdf0e10cSrcweir { 914*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can't compare URL's, treat as different!\n" ); 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir } 917*cdf0e10cSrcweir } 918*cdf0e10cSrcweir 919*cdf0e10cSrcweir return bResult; 920*cdf0e10cSrcweir } 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir 923*cdf0e10cSrcweir 924*cdf0e10cSrcweir } // namespace utl 925*cdf0e10cSrcweir 926