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/lang/XServiceInfo.hpp>
21 #include <com/sun/star/uno/Reference.hxx>
22 #include <com/sun/star/uno/RuntimeException.hpp>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <com/sun/star/uri/UriReferenceFactory.hpp>
25 #include <com/sun/star/uri/XUriReference.hpp>
26 #include <com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp>
27 #include <cppuhelper/implbase.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <cppuhelper/weak.hxx>
30 #include <rtl/textenc.h>
32 #include <rtl/uri.hxx>
33 #include <rtl/ustring.hxx>
35 #include <sal/types.h>
37 namespace com::sun::star::uno
{ class XComponentContext
; }
38 namespace com::sun::star::uno
{ class XInterface
; }
43 public cppu::WeakImplHelper
<
44 css::lang::XServiceInfo
, css::uri::XVndSunStarPkgUrlReferenceFactory
>
48 css::uno::Reference
< css::uno::XComponentContext
> context
):
49 m_context(std::move(context
)) {}
51 Factory(const Factory
&) = delete;
52 Factory
& operator=(const Factory
&) = delete;
54 virtual OUString SAL_CALL
getImplementationName() override
;
56 virtual sal_Bool SAL_CALL
supportsService(OUString
const & serviceName
) override
;
58 virtual css::uno::Sequence
< OUString
> SAL_CALL
59 getSupportedServiceNames() override
;
61 virtual css::uno::Reference
< css::uri::XUriReference
> SAL_CALL
62 createVndSunStarPkgUrlReference(
63 css::uno::Reference
< css::uri::XUriReference
> const & authority
) override
;
66 virtual ~Factory() override
{}
68 css::uno::Reference
< css::uno::XComponentContext
> m_context
;
71 OUString
Factory::getImplementationName()
73 return u
"com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory"_ustr
;
76 sal_Bool
Factory::supportsService(OUString
const & serviceName
)
78 return cppu::supportsService(this, serviceName
);
81 css::uno::Sequence
< OUString
> Factory::getSupportedServiceNames()
83 css::uno::Sequence
< OUString
> s
{ u
"com.sun.star.uri.VndSunStarPkgUrlReferenceFactory"_ustr
};
87 css::uno::Reference
< css::uri::XUriReference
>
88 Factory::createVndSunStarPkgUrlReference(
89 css::uno::Reference
< css::uri::XUriReference
> const & authority
)
91 if (!authority
.is()) {
92 throw css::uno::RuntimeException(
93 u
"null authority passed to"
94 " XVndSunStarPkgUrlReferenceFactory.createVndSunStarPkgUrlReference"_ustr
);
96 if (authority
->isAbsolute() && !authority
->hasFragment()) {
98 "vnd.sun.star.pkg://" +
100 authority
->getUriReference(), rtl_UriCharClassRegName
,
101 rtl_UriEncodeIgnoreEscapes
, RTL_TEXTENCODING_UTF8
);
102 css::uno::Reference
< css::uri::XUriReference
> uriRef(
103 css::uri::UriReferenceFactory::create(m_context
)->parse(
107 return css::uno::Reference
< css::uri::XUriReference
>();
113 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
114 com_sun_star_comp_uri_VndSunStarPkgUrlReferenceFactory_get_implementation(css::uno::XComponentContext
* rxContext
,
115 css::uno::Sequence
<css::uno::Any
> const &)
117 return ::cppu::acquire(new Factory(rxContext
));
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */