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 <comphelper/compbase.hxx>
20 #include <cppuhelper/supportsservice.hxx>
21 #include <rtl/uri.hxx>
22 #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>]
39 public comphelper::WeakComponentImplHelper
<
40 css::lang::XServiceInfo
, css::ucb::XContentProvider
>
44 css::uno::Reference
<css::uno::XComponentContext
> context
):
45 context_(std::move(context
))
49 OUString SAL_CALL
getImplementationName() override
50 { return u
"com.sun.star.comp.ucb.ImageContentProvider"_ustr
; }
52 sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
53 { return cppu::supportsService(this, ServiceName
); }
55 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
57 return css::uno::Sequence
<OUString
>{
58 u
"com.sun.star.ucb.ImageContentProvider"_ustr
};
61 css::uno::Reference
<css::ucb::XContent
> SAL_CALL
queryContent(
62 css::uno::Reference
<css::ucb::XContentIdentifier
> const & Identifier
)
65 css::uno::Reference
<css::uno::XComponentContext
> context
;
67 std::unique_lock
g(m_aMutex
);
71 throw css::lang::DisposedException();
73 auto url(Identifier
->getContentIdentifier());
74 auto uri(css::uri::UriReferenceFactory::create(context
)->parse(url
));
76 && uri
->getScheme().equalsIgnoreAsciiCase(
77 "vnd.libreoffice.image")))
79 throw css::ucb::IllegalIdentifierException(url
);
83 uri
->getAuthority(), rtl_UriDecodeStrict
,
84 RTL_TEXTENCODING_UTF8
));
86 throw css::ucb::IllegalIdentifierException(url
);
88 auto path(uri
->getPath());
90 throw css::ucb::IllegalIdentifierException(url
);
93 assert(path
[0] == '/');
94 for (sal_Int32 i
= 1;;) {
95 auto j
= path
.indexOf('/', i
);
101 path
.copy(i
, j
- i
), rtl_UriDecodeStrict
,
102 RTL_TEXTENCODING_UTF8
));
104 throw css::ucb::IllegalIdentifierException(url
);
110 if (j
== path
.getLength()) {
115 auto decPath(buf
.makeStringAndClear());
117 if (uri
->hasQuery()) {
118 if (!uri
->getQuery().startsWith("lang=", &lang
)) {
119 throw css::ucb::IllegalIdentifierException(url
);
121 lang
= rtl::Uri::decode(
122 lang
, rtl_UriDecodeStrict
, RTL_TEXTENCODING_UTF8
);
123 if (lang
.isEmpty()) {
124 throw css::ucb::IllegalIdentifierException(url
);
130 newUrl
= ImageTree::get().getImageUrl(decPath
, auth
, lang
);
132 ucbhelper::Content content
;
134 ucbhelper::Content::create(
135 newUrl
, css::uno::Reference
<css::ucb::XCommandEnvironment
>(),
137 ? content
.get() : css::uno::Reference
<css::ucb::XContent
>();
140 sal_Int32 SAL_CALL
compareContentIds(
141 css::uno::Reference
<css::ucb::XContentIdentifier
> const & Id1
,
142 css::uno::Reference
<css::ucb::XContentIdentifier
> const & Id2
) override
144 return Id1
->getContentIdentifier().compareTo(
145 Id2
->getContentIdentifier());
148 void disposing(std::unique_lock
<std::mutex
>&) override
{
152 css::uno::Reference
<css::uno::XComponentContext
> context_
;
157 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
158 com_sun_star_comp_ucb_ImageContentProvider_get_implementation(
159 css::uno::XComponentContext
* context
,
160 css::uno::Sequence
<css::uno::Any
> const &)
162 return cppu::acquire(new Provider(context
));
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */