2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-10-18 10:42:10 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 15:12:43 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2001-10-18 10:42:10 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2001-10-18 10:42:10 +00:00
|
|
|
*
|
2008-04-10 15:12:43 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-10-18 10:42:10 +00:00
|
|
|
*
|
2008-04-10 15:12:43 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2001-10-18 10:42:10 +00:00
|
|
|
*
|
2008-04-10 15:12:43 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2001-10-18 10:42:10 +00:00
|
|
|
*
|
2008-04-10 15:12:43 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2001-10-18 10:42:10 +00:00
|
|
|
*
|
2008-04-10 15:12:43 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2001-10-18 10:42:10 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-16 20:55:04 +00:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_sw.hxx"
|
2001-10-18 10:42:10 +00:00
|
|
|
|
|
|
|
#define _SVSTDARR_STRINGS
|
|
|
|
#include <com/sun/star/uno/Sequence.h>
|
|
|
|
#include <com/sun/star/uno/Exception.hpp>
|
|
|
|
#include <com/sun/star/ucb/XContentIdentifier.hpp>
|
|
|
|
#include <com/sun/star/ucb/XContentProvider.hpp>
|
|
|
|
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
|
|
|
|
#include <com/sun/star/ucb/TransferInfo.hpp>
|
|
|
|
#include <com/sun/star/ucb/NameClash.hdl>
|
|
|
|
#include <com/sun/star/sdbc/XResultSet.hpp>
|
|
|
|
#include <com/sun/star/sdbc/XRow.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <comphelper/types.hxx>
|
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
#include <tools/datetime.hxx>
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#include <ucbhelper/contentidentifier.hxx>
|
|
|
|
#include <ucbhelper/contentbroker.hxx>
|
|
|
|
#include <ucbhelper/content.hxx>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/svstdarr.hxx>
|
2001-10-18 10:42:10 +00:00
|
|
|
#include <swunohelper.hxx>
|
|
|
|
#include <swunodef.hxx>
|
|
|
|
|
|
|
|
namespace SWUnoHelper {
|
|
|
|
|
|
|
|
sal_Int32 GetEnumAsInt32( const UNO_NMSPC::Any& rVal )
|
|
|
|
{
|
|
|
|
sal_Int32 eVal;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
eVal = comphelper::getEnumAsINT32( rVal );
|
|
|
|
}
|
|
|
|
catch( UNO_NMSPC::Exception & )
|
|
|
|
{
|
|
|
|
eVal = 0;
|
2011-03-14 16:51:14 +00:00
|
|
|
OSL_ENSURE( sal_False, "can't get EnumAsInt32" );
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
return eVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// methods for UCB actions
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool UCB_DeleteFile( const String& rURL )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bRemoved;
|
2001-10-18 10:42:10 +00:00
|
|
|
try
|
|
|
|
{
|
2007-06-05 16:31:33 +00:00
|
|
|
ucbhelper::Content aTempContent( rURL,
|
2001-10-18 10:42:10 +00:00
|
|
|
STAR_REFERENCE( ucb::XCommandEnvironment )());
|
|
|
|
aTempContent.executeCommand(
|
2010-10-27 11:38:46 +01:00
|
|
|
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("delete")),
|
2001-10-18 10:42:10 +00:00
|
|
|
UNO_NMSPC::makeAny( sal_Bool( sal_True ) ) );
|
2011-01-17 15:06:54 +01:00
|
|
|
bRemoved = sal_True;
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
catch( UNO_NMSPC::Exception& )
|
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
bRemoved = sal_False;
|
2011-03-14 16:51:14 +00:00
|
|
|
OSL_ENSURE( sal_False, "Exeception from executeCommand( delete )" );
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
return bRemoved;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool UCB_CopyFile( const String& rURL, const String& rNewURL, sal_Bool bCopyIsMove )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bCopyCompleted = sal_True;
|
2001-10-18 10:42:10 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
INetURLObject aURL( rNewURL );
|
|
|
|
String sName( aURL.GetName() );
|
|
|
|
aURL.removeSegment();
|
|
|
|
String sMainURL( aURL.GetMainURL(INetURLObject::NO_DECODE) );
|
|
|
|
|
2007-06-05 16:31:33 +00:00
|
|
|
ucbhelper::Content aTempContent( sMainURL,
|
2001-10-18 10:42:10 +00:00
|
|
|
STAR_REFERENCE( ucb::XCommandEnvironment )());
|
|
|
|
|
|
|
|
UNO_NMSPC::Any aAny;
|
|
|
|
STAR_NMSPC::ucb::TransferInfo aInfo;
|
|
|
|
aInfo.NameClash = STAR_NMSPC::ucb::NameClash::ERROR;
|
|
|
|
aInfo.NewTitle = sName;
|
|
|
|
aInfo.SourceURL = rURL;
|
|
|
|
aInfo.MoveData = bCopyIsMove;
|
|
|
|
aAny <<= aInfo;
|
|
|
|
aTempContent.executeCommand(
|
2010-10-27 11:38:46 +01:00
|
|
|
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("transfer")),
|
2001-10-18 10:42:10 +00:00
|
|
|
aAny );
|
|
|
|
}
|
|
|
|
catch( UNO_NMSPC::Exception& )
|
|
|
|
{
|
2011-03-14 16:51:14 +00:00
|
|
|
OSL_ENSURE( sal_False, "Exeception from executeCommand( transfer )" );
|
2011-01-17 15:06:54 +01:00
|
|
|
bCopyCompleted = sal_False;
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
return bCopyCompleted;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool UCB_IsCaseSensitiveFileName( const String& rURL )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bCaseSensitive;
|
2001-10-18 10:42:10 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
STAR_REFERENCE( lang::XMultiServiceFactory ) xMSF =
|
|
|
|
comphelper::getProcessServiceFactory();
|
|
|
|
|
|
|
|
INetURLObject aTempObj( rURL );
|
2004-12-13 11:35:41 +00:00
|
|
|
aTempObj.SetBase( aTempObj.GetBase().toAsciiLowerCase() );
|
2001-10-18 10:42:10 +00:00
|
|
|
STAR_REFERENCE( ucb::XContentIdentifier ) xRef1 = new
|
2007-06-05 16:31:33 +00:00
|
|
|
ucbhelper::ContentIdentifier( xMSF,
|
2001-10-18 10:42:10 +00:00
|
|
|
aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
|
|
|
|
|
2004-12-13 11:35:41 +00:00
|
|
|
aTempObj.SetBase(aTempObj.GetBase().toAsciiUpperCase());
|
2001-10-18 10:42:10 +00:00
|
|
|
STAR_REFERENCE( ucb::XContentIdentifier ) xRef2 = new
|
2007-06-05 16:31:33 +00:00
|
|
|
ucbhelper::ContentIdentifier( xMSF,
|
2001-10-18 10:42:10 +00:00
|
|
|
aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
|
|
|
|
|
|
|
|
STAR_REFERENCE( ucb::XContentProvider ) xProv =
|
2007-06-05 16:31:33 +00:00
|
|
|
ucbhelper::ContentBroker::get()->getContentProviderInterface();
|
2001-10-18 10:42:10 +00:00
|
|
|
|
|
|
|
sal_Int32 nCompare = xProv->compareContentIds( xRef1, xRef2 );
|
|
|
|
bCaseSensitive = 0 != nCompare;
|
|
|
|
}
|
|
|
|
catch( UNO_NMSPC::Exception& )
|
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
bCaseSensitive = sal_False;
|
2011-03-14 16:51:14 +00:00
|
|
|
OSL_ENSURE( sal_False, "Exeception from compareContentIds()" );
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
return bCaseSensitive;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool UCB_IsReadOnlyFileName( const String& rURL )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bIsReadOnly = sal_False;
|
2001-10-18 10:42:10 +00:00
|
|
|
try
|
|
|
|
{
|
2007-06-05 16:31:33 +00:00
|
|
|
ucbhelper::Content aCnt( rURL, STAR_REFERENCE( ucb::XCommandEnvironment )());
|
2001-10-18 10:42:10 +00:00
|
|
|
UNO_NMSPC::Any aAny = aCnt.getPropertyValue(
|
2010-10-27 11:38:46 +01:00
|
|
|
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsReadOnly")));
|
2001-10-18 10:42:10 +00:00
|
|
|
if(aAny.hasValue())
|
|
|
|
bIsReadOnly = *(sal_Bool*)aAny.getValue();
|
|
|
|
}
|
|
|
|
catch( UNO_NMSPC::Exception& )
|
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
bIsReadOnly = sal_False;
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
return bIsReadOnly;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool UCB_IsFile( const String& rURL )
|
2004-09-24 15:13:36 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bExists = sal_False;
|
2004-09-24 15:13:36 +00:00
|
|
|
try
|
|
|
|
{
|
2007-06-05 16:31:33 +00:00
|
|
|
::ucbhelper::Content aContent( rURL, STAR_REFERENCE( ucb::XCommandEnvironment )() );
|
2004-09-24 15:13:36 +00:00
|
|
|
bExists = aContent.isDocument();
|
|
|
|
}
|
|
|
|
catch (UNO_NMSPC::Exception &)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return bExists;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool UCB_IsDirectory( const String& rURL )
|
2003-03-27 14:45:43 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bExists = sal_False;
|
2003-03-27 14:45:43 +00:00
|
|
|
try
|
|
|
|
{
|
2007-06-05 16:31:33 +00:00
|
|
|
::ucbhelper::Content aContent( rURL, STAR_REFERENCE( ucb::XCommandEnvironment )() );
|
2003-03-27 14:45:43 +00:00
|
|
|
bExists = aContent.isFolder();
|
|
|
|
}
|
|
|
|
catch (UNO_NMSPC::Exception &)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return bExists;
|
|
|
|
}
|
2001-10-18 10:42:10 +00:00
|
|
|
|
|
|
|
// get a list of files from the folder of the URL
|
|
|
|
// options: pExtension = 0 -> all, else this specific extension
|
|
|
|
// pDateTime != 0 -> returns also the modified date/time of
|
|
|
|
// the files in a SvPtrarr -->
|
|
|
|
// !! objects must be deleted from the caller!!
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool UCB_GetFileListOfFolder( const String& rURL, SvStrings& rList,
|
2001-10-18 10:42:10 +00:00
|
|
|
const String* pExtension,
|
|
|
|
SvPtrarr* pDateTimeList )
|
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bOk = sal_False;
|
2001-10-18 10:42:10 +00:00
|
|
|
try
|
|
|
|
{
|
2007-06-05 16:31:33 +00:00
|
|
|
ucbhelper::Content aCnt( rURL, STAR_REFERENCE( ucb::XCommandEnvironment )());
|
2001-10-18 10:42:10 +00:00
|
|
|
STAR_REFERENCE( sdbc::XResultSet ) xResultSet;
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nSeqSize = pDateTimeList ? 2 : 1;
|
2001-10-18 10:42:10 +00:00
|
|
|
UNO_NMSPC::Sequence < rtl::OUString > aProps( nSeqSize );
|
|
|
|
rtl::OUString* pProps = aProps.getArray();
|
2010-10-27 11:38:46 +01:00
|
|
|
pProps[ 0 ] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title"));
|
2001-10-18 10:42:10 +00:00
|
|
|
if( pDateTimeList )
|
2010-10-27 11:38:46 +01:00
|
|
|
pProps[ 1 ] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DateModified"));
|
2001-10-18 10:42:10 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2007-06-05 16:31:33 +00:00
|
|
|
xResultSet = aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
catch( UNO_NMSPC::Exception& )
|
|
|
|
{
|
|
|
|
DBG_ERRORFILE( "create cursor failed!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( xResultSet.is() )
|
|
|
|
{
|
|
|
|
STAR_REFERENCE( sdbc::XRow ) xRow( xResultSet, UNO_NMSPC::UNO_QUERY );
|
|
|
|
xub_StrLen nExtLen = pExtension ? pExtension->Len() : 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( xResultSet->first() )
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
String sTitle( xRow->getString( 1 ) );
|
|
|
|
if( !nExtLen ||
|
|
|
|
( sTitle.Len() > nExtLen &&
|
|
|
|
sTitle.Equals( *pExtension,
|
|
|
|
sTitle.Len() - nExtLen, nExtLen )) )
|
|
|
|
{
|
|
|
|
String* pStr = new String( sTitle );
|
|
|
|
rList.Insert( pStr, rList.Count() );
|
|
|
|
|
|
|
|
if( pDateTimeList )
|
|
|
|
{
|
|
|
|
STAR_NMSPC::util::DateTime aStamp = xRow->getTimestamp(2);
|
|
|
|
::DateTime* pDateTime = new ::DateTime(
|
|
|
|
::Date( aStamp.Day,
|
|
|
|
aStamp.Month,
|
|
|
|
aStamp.Year ),
|
|
|
|
::Time( aStamp.Hours,
|
|
|
|
aStamp.Minutes,
|
|
|
|
aStamp.Seconds,
|
|
|
|
aStamp.HundredthSeconds ));
|
|
|
|
void* p = pDateTime;
|
|
|
|
pDateTimeList->Insert( p,
|
|
|
|
pDateTimeList->Count() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while( xResultSet->next() );
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
bOk = sal_True;
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
catch( UNO_NMSPC::Exception& )
|
|
|
|
{
|
|
|
|
DBG_ERRORFILE( "Exception caught!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( UNO_NMSPC::Exception& )
|
|
|
|
{
|
|
|
|
DBG_ERRORFILE( "Exception caught!" );
|
2011-01-17 15:06:54 +01:00
|
|
|
bOk = sal_False;
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
return bOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-10-14 08:30:41 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|