tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / ucb / source / ucp / expand / ucpexpand.cxx
blob46378b6dfebd671b44ea6ea5f914ee83077de04f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <rtl/uri.hxx>
22 #include <comphelper/compbase.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <ucbhelper/content.hxx>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/util/theMacroExpander.hpp>
29 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
30 #include <com/sun/star/ucb/XContentProvider.hpp>
31 #include <comphelper/diagnose_ex.hxx>
34 using namespace ::com::sun::star;
36 namespace
39 typedef comphelper::WeakComponentImplHelper<
40 lang::XServiceInfo, ucb::XContentProvider > t_impl_helper;
43 class ExpandContentProviderImpl : public t_impl_helper
45 uno::Reference< uno::XComponentContext > m_xComponentContext;
46 uno::Reference< util::XMacroExpander > m_xMacroExpander;
47 OUString expandUri(
48 uno::Reference< ucb::XContentIdentifier > const & xIdentifier ) const;
50 protected:
51 void check() const;
53 public:
54 explicit ExpandContentProviderImpl(
55 uno::Reference< uno::XComponentContext > const & xComponentContext )
56 : m_xComponentContext( xComponentContext ),
57 m_xMacroExpander( util::theMacroExpander::get(xComponentContext) )
60 // XServiceInfo
61 virtual OUString SAL_CALL getImplementationName() override;
62 virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName ) override;
63 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
65 // XContentProvider
66 virtual uno::Reference< ucb::XContent > SAL_CALL queryContent(
67 uno::Reference< ucb::XContentIdentifier > const & xIdentifier ) override;
68 virtual sal_Int32 SAL_CALL compareContentIds(
69 uno::Reference< ucb::XContentIdentifier > const & xId1,
70 uno::Reference< ucb::XContentIdentifier > const & xId2 ) override;
74 void ExpandContentProviderImpl::check() const
76 // xxx todo guard?
77 // MutexGuard guard( m_mutex );
78 if (m_bDisposed)
80 throw lang::DisposedException(
81 u"expand content provider instance has "
82 "already been disposed!"_ustr,
83 const_cast< ExpandContentProviderImpl * >(this)->getXWeak() );
87 // XServiceInfo
89 OUString ExpandContentProviderImpl::getImplementationName()
91 check();
92 return u"com.sun.star.comp.ucb.ExpandContentProvider"_ustr;
96 uno::Sequence< OUString > ExpandContentProviderImpl::getSupportedServiceNames()
98 check();
99 return {
100 u"com.sun.star.ucb.ExpandContentProvider"_ustr,
101 u"com.sun.star.ucb.ContentProvider"_ustr
105 sal_Bool ExpandContentProviderImpl::supportsService(OUString const & serviceName )
107 return cppu::supportsService(this, serviceName);
110 OUString ExpandContentProviderImpl::expandUri(
111 uno::Reference< ucb::XContentIdentifier > const & xIdentifier ) const
113 OUString uri( xIdentifier->getContentIdentifier() );
114 if (!uri.startsWithIgnoreAsciiCase("vnd.sun.star.expand:", &uri))
116 throw ucb::IllegalIdentifierException(
117 u"expected protocol vnd.sun.star.expand!"_ustr,
118 const_cast< ExpandContentProviderImpl * >(this)->getXWeak() );
120 // decode uric class chars
121 OUString str = ::rtl::Uri::decode(uri, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8);
122 // expand macro string
123 return m_xMacroExpander->expandMacros( str );
126 // XContentProvider
128 uno::Reference< ucb::XContent > ExpandContentProviderImpl::queryContent(
129 uno::Reference< ucb::XContentIdentifier > const & xIdentifier )
131 check();
132 OUString uri( expandUri( xIdentifier ) );
134 ::ucbhelper::Content ucb_content;
135 if (::ucbhelper::Content::create(
136 uri, uno::Reference< ucb::XCommandEnvironment >(),
137 m_xComponentContext, ucb_content ))
139 return ucb_content.get();
141 else
143 return uno::Reference< ucb::XContent >();
148 sal_Int32 ExpandContentProviderImpl::compareContentIds(
149 uno::Reference< ucb::XContentIdentifier > const & xId1,
150 uno::Reference< ucb::XContentIdentifier > const & xId2 )
152 check();
155 OUString uri1( expandUri( xId1 ) );
156 OUString uri2( expandUri( xId2 ) );
157 return uri1.compareTo( uri2 );
159 catch (const ucb::IllegalIdentifierException &)
161 TOOLS_WARN_EXCEPTION( "ucb", "" );
162 return -1;
169 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
170 ucb_expand_ExpandContentProviderImpl_get_implementation(
171 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
173 return cppu::acquire(new ExpandContentProviderImpl(context));
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */