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/.
10 #include <sal/config.h>
14 #include <com/sun/star/lang/XServiceInfo.hpp>
15 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
16 #include <com/sun/star/ucb/XContentProvider.hpp>
17 #include <com/sun/star/uno/XComponentContext.hpp>
18 #include <com/sun/star/uri/UriReferenceFactory.hpp>
19 #include <cppuhelper/compbase.hxx>
20 #include <cppuhelper/supportsservice.hxx>
21 #include <osl/mutex.hxx>
22 #include <rtl/uri.hxx>
23 #include <rtl/ustrbuf.hxx>
24 #include <vcl/ImageTree.hxx>
25 #include <vcl/svapp.hxx>
26 #include <ucbhelper/content.hxx>
28 // A LO-private ("implementation detail") UCP used to access images from help
29 // content, with theme fallback and localization support as provided by VCL's
34 // "vnd.libreoffice.image://"<theme><path>["?lang="<language-tag>]
40 public cppu::WeakComponentImplHelper
<
41 css::lang::XServiceInfo
, css::ucb::XContentProvider
>
45 css::uno::Reference
<css::uno::XComponentContext
> const & context
):
46 WeakComponentImplHelper(*static_cast<Mutex
*>(this)), context_(context
)
50 OUString SAL_CALL
getImplementationName() override
51 { return "com.sun.star.comp.ucb.ImageContentProvider"; }
53 sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
54 { return cppu::supportsService(this, ServiceName
); }
56 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
58 return css::uno::Sequence
<OUString
>{
59 "com.sun.star.ucb.ImageContentProvider"};
62 css::uno::Reference
<css::ucb::XContent
> SAL_CALL
queryContent(
63 css::uno::Reference
<css::ucb::XContentIdentifier
> const & Identifier
)
66 css::uno::Reference
<css::uno::XComponentContext
> context
;
68 osl::MutexGuard
g(*this);
72 throw css::lang::DisposedException();
74 auto url(Identifier
->getContentIdentifier());
75 auto uri(css::uri::UriReferenceFactory::create(context
)->parse(url
));
77 && uri
->getScheme().equalsIgnoreAsciiCase(
78 "vnd.libreoffice.image")))
80 throw css::ucb::IllegalIdentifierException(url
);
84 uri
->getAuthority(), rtl_UriDecodeStrict
,
85 RTL_TEXTENCODING_UTF8
));
87 throw css::ucb::IllegalIdentifierException(url
);
89 auto path(uri
->getPath());
91 throw css::ucb::IllegalIdentifierException(url
);
94 assert(path
[0] == '/');
95 for (sal_Int32 i
= 1;;) {
96 auto j
= path
.indexOf('/', i
);
102 path
.copy(i
, j
- i
), rtl_UriDecodeStrict
,
103 RTL_TEXTENCODING_UTF8
));
105 throw css::ucb::IllegalIdentifierException(url
);
111 if (j
== path
.getLength()) {
116 auto decPath(buf
.makeStringAndClear());
118 if (uri
->hasQuery()) {
119 if (!uri
->getQuery().startsWith("lang=", &lang
)) {
120 throw css::ucb::IllegalIdentifierException(url
);
122 lang
= rtl::Uri::decode(
123 lang
, rtl_UriDecodeStrict
, RTL_TEXTENCODING_UTF8
);
124 if (lang
.isEmpty()) {
125 throw css::ucb::IllegalIdentifierException(url
);
131 newUrl
= ImageTree::get().getImageUrl(decPath
, auth
, lang
);
133 ucbhelper::Content content
;
135 ucbhelper::Content::create(
136 newUrl
, css::uno::Reference
<css::ucb::XCommandEnvironment
>(),
138 ? content
.get() : css::uno::Reference
<css::ucb::XContent
>();
141 sal_Int32 SAL_CALL
compareContentIds(
142 css::uno::Reference
<css::ucb::XContentIdentifier
> const & Id1
,
143 css::uno::Reference
<css::ucb::XContentIdentifier
> const & Id2
) override
145 return Id1
->getContentIdentifier().compareTo(
146 Id2
->getContentIdentifier());
149 void SAL_CALL
disposing() override
{
153 css::uno::Reference
<css::uno::XComponentContext
> context_
;
158 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
159 com_sun_star_comp_ucb_ImageContentProvider_get_implementation(
160 css::uno::XComponentContext
* context
,
161 css::uno::Sequence
<css::uno::Any
> const &)
163 return cppu::acquire(new Provider(context
));
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */