Files
libreoffice/sw/source/core/unocore/swunohelper.cxx

269 lines
9.5 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
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 .
*/
#include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/uno/Exception.hpp>
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
#include <com/sun/star/ucb/XContentIdentifier.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <com/sun/star/ucb/TransferInfo.hpp>
#include <com/sun/star/ucb/NameClash.hpp>
#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/string.hxx>
#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 )
{
sal_Int32 eVal;
try
{
eVal = comphelper::getEnumAsINT32( rVal );
}
2012-02-20 17:32:53 +01:00
catch( ::com::sun::star::uno::Exception & )
{
eVal = 0;
OSL_FAIL( "can't get EnumAsInt32" );
}
return eVal;
}
// methods for UCB actions
sal_Bool UCB_DeleteFile( const String& rURL )
{
sal_Bool bRemoved;
try
{
ucbhelper::Content aTempContent( rURL,
::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
comphelper::getProcessComponentContext() );
aTempContent.executeCommand(OUString("delete"),
::com::sun::star::uno::makeAny( sal_True ) );
bRemoved = sal_True;
}
2012-02-20 17:32:53 +01:00
catch( ::com::sun::star::uno::Exception& )
{
bRemoved = sal_False;
OSL_FAIL( "Exeception from executeCommand( delete )" );
}
return bRemoved;
}
sal_Bool UCB_CopyFile( const String& rURL, const String& rNewURL, sal_Bool bCopyIsMove )
{
sal_Bool bCopyCompleted = sal_True;
try
{
INetURLObject aURL( rNewURL );
String sName( aURL.GetName() );
aURL.removeSegment();
String sMainURL( aURL.GetMainURL(INetURLObject::NO_DECODE) );
ucbhelper::Content aTempContent( sMainURL,
::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;
2012-02-20 17:29:44 +01:00
::com::sun::star::ucb::TransferInfo aInfo;
aInfo.NameClash = ::com::sun::star::ucb::NameClash::ERROR;
aInfo.NewTitle = sName;
aInfo.SourceURL = rURL;
aInfo.MoveData = bCopyIsMove;
aAny <<= aInfo;
aTempContent.executeCommand( OUString("transfer"),
aAny );
}
2012-02-20 17:32:53 +01:00
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL( "Exeception from executeCommand( transfer )" );
bCopyCompleted = sal_False;
}
return bCopyCompleted;
}
sal_Bool UCB_IsCaseSensitiveFileName( const String& rURL )
{
sal_Bool bCaseSensitive;
try
{
INetURLObject aTempObj( rURL );
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
ucbhelper::ContentIdentifier( aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
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
ucbhelper::ContentIdentifier( aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
::com::sun::star::uno::Reference< ::com::sun::star::ucb::XUniversalContentBroker > xUcb =
com::sun::star::ucb::UniversalContentBroker::create(comphelper::getProcessComponentContext());
sal_Int32 nCompare = xUcb->compareContentIds( xRef1, xRef2 );
bCaseSensitive = 0 != nCompare;
}
2012-02-20 17:32:53 +01:00
catch( ::com::sun::star::uno::Exception& )
{
bCaseSensitive = sal_False;
OSL_FAIL( "Exeception from compareContentIds()" );
}
return bCaseSensitive;
}
sal_Bool UCB_IsReadOnlyFileName( const String& rURL )
{
sal_Bool bIsReadOnly = sal_False;
try
{
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(
OUString("IsReadOnly"));
if(aAny.hasValue())
bIsReadOnly = *(sal_Bool*)aAny.getValue();
}
2012-02-20 17:32:53 +01:00
catch( ::com::sun::star::uno::Exception& )
{
bIsReadOnly = sal_False;
}
return bIsReadOnly;
}
sal_Bool UCB_IsFile( const String& rURL )
{
sal_Bool bExists = sal_False;
try
{
::ucbhelper::Content aContent( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
bExists = aContent.isDocument();
}
2012-02-20 17:32:53 +01:00
catch (::com::sun::star::uno::Exception &)
{
}
return bExists;
}
sal_Bool UCB_IsDirectory( const String& rURL )
{
sal_Bool bExists = sal_False;
try
{
::ucbhelper::Content aContent( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
bExists = aContent.isFolder();
}
2012-02-20 17:32:53 +01:00
catch (::com::sun::star::uno::Exception &)
{
}
return bExists;
}
// 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 std::vector<String*> -->
// !! objects must be deleted from the caller!!
bool UCB_GetFileListOfFolder( const String& rURL,
2011-12-29 22:25:11 +13:00
std::vector<String*>& rList,
const String* pExtension,
std::vector< ::DateTime* >* pDateTimeList )
{
bool bOk = false;
try
{
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;
sal_uInt16 nSeqSize = pDateTimeList ? 2 : 1;
::com::sun::star::uno::Sequence < OUString > aProps( nSeqSize );
OUString* pProps = aProps.getArray();
pProps[ 0 ] = OUString("Title");
if( pDateTimeList )
pProps[ 1 ] = OUString("DateModified");
try
{
xResultSet = aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
}
2012-02-20 17:32:53 +01:00
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL( "create cursor failed!" );
}
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 );
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) );
if( pDateTimeList )
{
2012-02-20 17:29:44 +01:00
::com::sun::star::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 ));
pDateTimeList->push_back( pDateTime );
}
}
} while( xResultSet->next() );
}
bOk = true;
}
2012-02-20 17:32:53 +01:00
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL( "Exception caught!" );
}
}
}
2012-02-20 17:32:53 +01:00
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL( "Exception caught!" );
bOk = false;
}
return bOk;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */