1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/uno/Sequence.h>
21 #include <com/sun/star/uno/Exception.hpp>
22 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
23 #include <com/sun/star/ucb/XContentIdentifier.hpp>
24 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
25 #include <com/sun/star/ucb/TransferInfo.hpp>
26 #include <com/sun/star/ucb/NameClash.hpp>
27 #include <com/sun/star/sdbc/XResultSet.hpp>
28 #include <com/sun/star/sdbc/XRow.hpp>
29 #include <comphelper/processfactory.hxx>
30 #include <comphelper/extract.hxx>
31 #include <o3tl/any.hxx>
32 #include <tools/urlobj.hxx>
33 #include <tools/datetime.hxx>
34 #include <comphelper/diagnose_ex.hxx>
35 #include <rtl/ustring.hxx>
36 #include <osl/diagnose.h>
37 #include <ucbhelper/contentidentifier.hxx>
38 #include <ucbhelper/content.hxx>
39 #include <swunohelper.hxx>
40 #include <svx/xdef.hxx>
41 #include <svx/xfillit0.hxx>
42 #include <editeng/memberids.h>
43 #include <svl/itemset.hxx>
45 using namespace com::sun::star
;
50 sal_Int32
GetEnumAsInt32( const css::uno::Any
& rVal
)
52 sal_Int32 nReturn
= 0;
53 if (! ::cppu::enum2int(nReturn
,rVal
) )
54 OSL_FAIL( "can't get EnumAsInt32" );
58 // methods for UCB actions
59 bool UCB_DeleteFile( const OUString
& rURL
)
64 ucbhelper::Content
aTempContent( rURL
,
65 css::uno::Reference
< css::ucb::XCommandEnvironment
>(),
66 comphelper::getProcessComponentContext() );
67 aTempContent
.executeCommand("delete", css::uno::Any( true ) );
70 catch( css::uno::Exception
& )
73 TOOLS_WARN_EXCEPTION( "sw", "Exception from executeCommand( delete )" );
78 bool UCB_MoveFile( const OUString
& rURL
, std::u16string_view rNewURL
)
80 bool bCopyCompleted
= true;
83 INetURLObject
aURL( rNewURL
);
84 const OUString
sName(aURL
.GetLastName());
86 const OUString
sMainURL( aURL
.GetMainURL(INetURLObject::DecodeMechanism::NONE
) );
88 ucbhelper::Content
aTempContent( sMainURL
,
89 css::uno::Reference
< css::ucb::XCommandEnvironment
>(),
90 comphelper::getProcessComponentContext() );
92 css::ucb::TransferInfo aInfo
;
93 aInfo
.NameClash
= css::ucb::NameClash::ERROR
;
94 aInfo
.NewTitle
= sName
;
95 aInfo
.SourceURL
= rURL
;
96 aInfo
.MoveData
= true;
97 aTempContent
.executeCommand( "transfer", uno::Any(aInfo
) );
99 catch( css::uno::Exception
& )
101 TOOLS_WARN_EXCEPTION( "sw", "Exception from executeCommand( transfer )" );
102 bCopyCompleted
= false;
104 return bCopyCompleted
;
107 bool UCB_IsCaseSensitiveFileName( std::u16string_view rURL
)
112 INetURLObject
aTempObj( rURL
);
113 aTempObj
.SetBase( aTempObj
.GetBase().toAsciiLowerCase() );
114 css::uno::Reference
< css::ucb::XContentIdentifier
> xRef1
= new
115 ucbhelper::ContentIdentifier( aTempObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
));
117 aTempObj
.SetBase(aTempObj
.GetBase().toAsciiUpperCase());
118 css::uno::Reference
< css::ucb::XContentIdentifier
> xRef2
= new
119 ucbhelper::ContentIdentifier( aTempObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
));
121 css::uno::Reference
< css::ucb::XUniversalContentBroker
> xUcb
=
122 css::ucb::UniversalContentBroker::create(comphelper::getProcessComponentContext());
124 sal_Int32 nCompare
= xUcb
->compareContentIds( xRef1
, xRef2
);
125 bCaseSensitive
= 0 != nCompare
;
127 catch( css::uno::Exception
& )
129 bCaseSensitive
= false;
130 TOOLS_WARN_EXCEPTION( "sw", "compareContentIds()" );
132 return bCaseSensitive
;
135 bool UCB_IsReadOnlyFileName( const OUString
& rURL
)
137 bool bIsReadOnly
= false;
140 ucbhelper::Content
aCnt( rURL
, css::uno::Reference
< css::ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
141 css::uno::Any aAny
= aCnt
.getPropertyValue("IsReadOnly");
143 bIsReadOnly
= *o3tl::doAccess
<bool>(aAny
);
145 catch( css::uno::Exception
& )
152 bool UCB_IsFile( const OUString
& rURL
)
154 bool bExists
= false;
157 ::ucbhelper::Content
aContent( rURL
, css::uno::Reference
< css::ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
158 bExists
= aContent
.isDocument();
160 catch (css::uno::Exception
&)
166 bool UCB_IsDirectory( const OUString
& rURL
)
168 bool bExists
= false;
171 ::ucbhelper::Content
aContent( rURL
, css::uno::Reference
< css::ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
172 bExists
= aContent
.isFolder();
174 catch (css::uno::Exception
&)
180 // get a list of files from the folder of the URL
181 // options: pExtension = 0 -> all, else this specific extension
182 // pDateTime != 0 -> returns also the modified date/time of
183 // the files in a std::vector<OUString> -->
184 // !! objects must be deleted from the caller!!
185 bool UCB_GetFileListOfFolder( const OUString
& rURL
,
186 std::vector
<OUString
>& rList
,
187 const OUString
* pExtension
,
188 std::vector
< ::DateTime
>* pDateTimeList
)
193 ucbhelper::Content
aCnt( rURL
, css::uno::Reference
< css::ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
194 css::uno::Reference
< css::sdbc::XResultSet
> xResultSet
;
196 const sal_Int32 nSeqSize
= pDateTimeList
? 2 : 1;
197 css::uno::Sequence
< OUString
> aProps( nSeqSize
);
198 OUString
* pProps
= aProps
.getArray();
199 pProps
[ 0 ] = "Title";
201 pProps
[ 1 ] = "DateModified";
205 xResultSet
= aCnt
.createCursor( aProps
, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY
);
207 catch( css::uno::Exception
& )
209 OSL_FAIL( "create cursor failed!" );
212 if( xResultSet
.is() )
214 css::uno::Reference
< css::sdbc::XRow
> xRow( xResultSet
, css::uno::UNO_QUERY
);
215 const sal_Int32 nExtLen
= pExtension
? pExtension
->getLength() : 0;
218 if( xResultSet
->first() )
221 const OUString
sTitle( xRow
->getString( 1 ) );
223 ( sTitle
.getLength() > nExtLen
&&
224 sTitle
.endsWith( *pExtension
)) )
226 rList
.push_back( sTitle
);
230 css::util::DateTime aStamp
= xRow
->getTimestamp(2);
231 ::DateTime
aDateTime(
235 ::tools::Time( aStamp
.Hours
,
238 aStamp
.NanoSeconds
));
239 pDateTimeList
->push_back( aDateTime
);
243 } while( xResultSet
->next() );
247 catch( css::uno::Exception
& )
249 TOOLS_WARN_EXCEPTION( "sw", "" );
253 catch( css::uno::Exception
& )
255 TOOLS_WARN_EXCEPTION( "sw", "" );
261 bool needToMapFillItemsToSvxBrushItemTypes(const SfxItemSet
& rSet
,
262 sal_uInt16
const nMID
)
264 const XFillStyleItem
* pXFillStyleItem(rSet
.GetItem
<XFillStyleItem
>(XATTR_FILLSTYLE
, false));
271 // here different FillStyles can be excluded for export; it will depend on the
272 // quality these fallbacks can reach. That again is done in getSvxBrushItemFromSourceSet,
273 // take a look there how the superset of DrawObject FillStyles is mapped to SvxBrushItem.
274 const drawing::FillStyle eFill
= pXFillStyleItem
->GetValue();
277 case drawing::FillStyle_NONE
:
278 // claim that BackColor and BackTransparent are available so that
279 // fo:background="transparent" attribute is exported to override
280 // the parent style in case it is != NONE
284 case MID_BACK_COLOR_R_G_B
:
285 case MID_GRAPHIC_TRANSPARENT
: // this is *BackTransparent
291 case drawing::FillStyle_SOLID
:
292 case drawing::FillStyle_GRADIENT
: // gradient and hatch don't exist in
293 case drawing::FillStyle_HATCH
: // SvxBrushItem so average color is emulated
297 case MID_GRAPHIC_TRANSPARENT
: // this is *BackTransparent
298 // Gradient/Hatch always have emulated color
299 return (drawing::FillStyle_SOLID
!= eFill
)
300 || SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLCOLOR
)
301 || SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLTRANSPARENCE
)
302 || SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLFLOATTRANSPARENCE
);
303 case MID_BACK_COLOR_R_G_B
:
304 // Gradient/Hatch always have emulated color
305 return (drawing::FillStyle_SOLID
!= eFill
)
306 || SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLCOLOR
);
307 case MID_BACK_COLOR_TRANSPARENCY
:
308 return SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLTRANSPARENCE
)
309 || SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLFLOATTRANSPARENCE
);
312 case drawing::FillStyle_BITMAP
:
316 return SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLBITMAP
);
317 case MID_GRAPHIC_POSITION
:
318 return SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLBMP_STRETCH
)
319 || SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLBMP_TILE
)
320 || SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLBMP_POS
);
321 case MID_GRAPHIC_TRANSPARENT
:
322 case MID_GRAPHIC_TRANSPARENCY
:
323 return SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLTRANSPARENCE
)
324 || SfxItemState::SET
== rSet
.GetItemState(XATTR_FILLFLOATTRANSPARENCE
);
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */