2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-03-31 10:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-09-16 20:55:04 +00:00
|
|
|
|
2001-10-18 10:42:10 +00:00
|
|
|
#include <com/sun/star/uno/Sequence.h>
|
|
|
|
#include <com/sun/star/uno/Exception.hpp>
|
2012-09-14 18:08:57 +02:00
|
|
|
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
|
2001-10-18 10:42:10 +00:00
|
|
|
#include <com/sun/star/ucb/XContentIdentifier.hpp>
|
|
|
|
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
|
|
|
|
#include <com/sun/star/ucb/TransferInfo.hpp>
|
2012-06-21 17:39:01 +01:00
|
|
|
#include <com/sun/star/ucb/NameClash.hpp>
|
2001-10-18 10:42:10 +00:00
|
|
|
#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>
|
2012-07-25 13:52:18 +02:00
|
|
|
#include <tools/string.hxx>
|
2001-10-18 10:42:10 +00:00
|
|
|
#include <ucbhelper/contentidentifier.hxx>
|
|
|
|
#include <ucbhelper/content.hxx>
|
|
|
|
#include <swunohelper.hxx>
|
|
|
|
|
|
|
|
namespace SWUnoHelper {
|
|
|
|
|
2012-02-20 17:32:53 +01:00
|
|
|
sal_Int32 GetEnumAsInt32( const ::com::sun::star::uno::Any& rVal )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
|
|
|
sal_Int32 eVal;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
eVal = comphelper::getEnumAsINT32( rVal );
|
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch( ::com::sun::star::uno::Exception & )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
|
|
|
eVal = 0;
|
2011-03-19 14:13:18 +01:00
|
|
|
OSL_FAIL( "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,
|
2012-09-14 18:08:57 +02:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
|
|
|
|
comphelper::getProcessComponentContext() );
|
2013-04-07 12:06:47 +02:00
|
|
|
aTempContent.executeCommand(OUString("delete"),
|
2012-12-13 21:52:13 +09:00
|
|
|
::com::sun::star::uno::makeAny( sal_True ) );
|
2011-01-17 15:06:54 +01:00
|
|
|
bRemoved = sal_True;
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch( ::com::sun::star::uno::Exception& )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
bRemoved = sal_False;
|
2011-03-19 14:13:18 +01:00
|
|
|
OSL_FAIL( "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,
|
2012-09-14 18:08:57 +02:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
|
|
|
|
comphelper::getProcessComponentContext() );
|
2001-10-18 10:42:10 +00:00
|
|
|
|
2012-02-20 17:32:53 +01:00
|
|
|
::com::sun::star::uno::Any aAny;
|
2012-02-20 17:29:44 +01:00
|
|
|
::com::sun::star::ucb::TransferInfo aInfo;
|
|
|
|
aInfo.NameClash = ::com::sun::star::ucb::NameClash::ERROR;
|
2001-10-18 10:42:10 +00:00
|
|
|
aInfo.NewTitle = sName;
|
|
|
|
aInfo.SourceURL = rURL;
|
|
|
|
aInfo.MoveData = bCopyIsMove;
|
|
|
|
aAny <<= aInfo;
|
2013-04-07 12:06:47 +02:00
|
|
|
aTempContent.executeCommand( OUString("transfer"),
|
2013-03-18 23:17:03 +01:00
|
|
|
aAny );
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch( ::com::sun::star::uno::Exception& )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-03-19 14:13:18 +01:00
|
|
|
OSL_FAIL( "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
|
|
|
|
{
|
|
|
|
INetURLObject aTempObj( rURL );
|
2004-12-13 11:35:41 +00:00
|
|
|
aTempObj.SetBase( aTempObj.GetBase().toAsciiLowerCase() );
|
2012-02-20 20:45:25 +01:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xRef1 = new
|
2012-11-01 15:01:34 +02:00
|
|
|
ucbhelper::ContentIdentifier( aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
|
2001-10-18 10:42:10 +00:00
|
|
|
|
2004-12-13 11:35:41 +00:00
|
|
|
aTempObj.SetBase(aTempObj.GetBase().toAsciiUpperCase());
|
2012-02-20 20:45:25 +01:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xRef2 = new
|
2012-11-01 15:01:34 +02:00
|
|
|
ucbhelper::ContentIdentifier( aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
|
2001-10-18 10:42:10 +00:00
|
|
|
|
2012-09-14 18:08:57 +02:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::ucb::XUniversalContentBroker > xUcb =
|
|
|
|
com::sun::star::ucb::UniversalContentBroker::create(comphelper::getProcessComponentContext());
|
2001-10-18 10:42:10 +00:00
|
|
|
|
2012-09-14 18:08:57 +02:00
|
|
|
sal_Int32 nCompare = xUcb->compareContentIds( xRef1, xRef2 );
|
2001-10-18 10:42:10 +00:00
|
|
|
bCaseSensitive = 0 != nCompare;
|
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch( ::com::sun::star::uno::Exception& )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
bCaseSensitive = sal_False;
|
2011-03-19 14:13:18 +01:00
|
|
|
OSL_FAIL( "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
|
|
|
|
{
|
2012-09-14 18:08:57 +02:00
|
|
|
ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
|
2012-02-20 17:32:53 +01:00
|
|
|
::com::sun::star::uno::Any aAny = aCnt.getPropertyValue(
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString("IsReadOnly"));
|
2001-10-18 10:42:10 +00:00
|
|
|
if(aAny.hasValue())
|
|
|
|
bIsReadOnly = *(sal_Bool*)aAny.getValue();
|
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch( ::com::sun::star::uno::Exception& )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
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
|
|
|
|
{
|
2012-09-14 18:08:57 +02:00
|
|
|
::ucbhelper::Content aContent( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
|
2004-09-24 15:13:36 +00:00
|
|
|
bExists = aContent.isDocument();
|
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch (::com::sun::star::uno::Exception &)
|
2004-09-24 15:13:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2012-09-14 18:08:57 +02:00
|
|
|
::ucbhelper::Content aContent( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
|
2003-03-27 14:45:43 +00:00
|
|
|
bExists = aContent.isFolder();
|
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch (::com::sun::star::uno::Exception &)
|
2003-03-27 14:45:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
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
|
2012-07-28 16:58:57 +01:00
|
|
|
// the files in a std::vector<String*> -->
|
2001-10-18 10:42:10 +00:00
|
|
|
// !! objects must be deleted from the caller!!
|
2012-06-20 17:01:04 +02:00
|
|
|
bool UCB_GetFileListOfFolder( const String& rURL,
|
2011-12-29 22:25:11 +13:00
|
|
|
std::vector<String*>& rList,
|
2001-10-18 10:42:10 +00:00
|
|
|
const String* pExtension,
|
2012-06-20 17:01:04 +02:00
|
|
|
std::vector< ::DateTime* >* pDateTimeList )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2012-12-13 21:52:13 +09:00
|
|
|
bool bOk = false;
|
2001-10-18 10:42:10 +00:00
|
|
|
try
|
|
|
|
{
|
2012-09-14 18:08:57 +02:00
|
|
|
ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
|
2012-02-20 20:45:25 +01:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > xResultSet;
|
2001-10-18 10:42:10 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nSeqSize = pDateTimeList ? 2 : 1;
|
2013-04-07 12:06:47 +02:00
|
|
|
::com::sun::star::uno::Sequence < OUString > aProps( nSeqSize );
|
|
|
|
OUString* pProps = aProps.getArray();
|
|
|
|
pProps[ 0 ] = OUString("Title");
|
2001-10-18 10:42:10 +00:00
|
|
|
if( pDateTimeList )
|
2013-04-07 12:06:47 +02:00
|
|
|
pProps[ 1 ] = OUString("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
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch( ::com::sun::star::uno::Exception& )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-05-08 22:14:45 +02:00
|
|
|
OSL_FAIL( "create cursor failed!" );
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( xResultSet.is() )
|
|
|
|
{
|
2012-02-20 20:45:25 +01:00
|
|
|
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > xRow( xResultSet, ::com::sun::star::uno::UNO_QUERY );
|
2001-10-18 10:42:10 +00:00
|
|
|
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 )) )
|
|
|
|
{
|
2011-12-29 22:25:11 +13:00
|
|
|
rList.push_back( new String(sTitle) );
|
2001-10-18 10:42:10 +00:00
|
|
|
|
|
|
|
if( pDateTimeList )
|
|
|
|
{
|
2012-02-20 17:29:44 +01:00
|
|
|
::com::sun::star::util::DateTime aStamp = xRow->getTimestamp(2);
|
2001-10-18 10:42:10 +00:00
|
|
|
::DateTime* pDateTime = new ::DateTime(
|
|
|
|
::Date( aStamp.Day,
|
|
|
|
aStamp.Month,
|
|
|
|
aStamp.Year ),
|
|
|
|
::Time( aStamp.Hours,
|
|
|
|
aStamp.Minutes,
|
|
|
|
aStamp.Seconds,
|
|
|
|
aStamp.HundredthSeconds ));
|
2012-06-20 17:01:04 +02:00
|
|
|
pDateTimeList->push_back( pDateTime );
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while( xResultSet->next() );
|
|
|
|
}
|
2012-12-13 21:52:13 +09:00
|
|
|
bOk = true;
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch( ::com::sun::star::uno::Exception& )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-05-08 22:14:45 +02:00
|
|
|
OSL_FAIL( "Exception caught!" );
|
2001-10-18 10:42:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 17:32:53 +01:00
|
|
|
catch( ::com::sun::star::uno::Exception& )
|
2001-10-18 10:42:10 +00:00
|
|
|
{
|
2011-05-08 22:14:45 +02:00
|
|
|
OSL_FAIL( "Exception caught!" );
|
2012-12-13 21:52:13 +09:00
|
|
|
bOk = 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: */
|