Bump version to 21.06.18.1
[LibreOffice.git] / stoc / source / uriproc / VndSunStarPkgUrlReferenceFactory.cxx
blobb6e926bd2e7c32594a1b20986efe3d6ac53b6cf7
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 .
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>
31 #include <rtl/uri.h>
32 #include <rtl/uri.hxx>
33 #include <rtl/ustrbuf.hxx>
34 #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; }
40 namespace {
42 class Factory:
43 public cppu::WeakImplHelper<
44 css::lang::XServiceInfo, css::uri::XVndSunStarPkgUrlReferenceFactory>
46 public:
47 explicit Factory(
48 css::uno::Reference< css::uno::XComponentContext > const & context):
49 m_context(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;
65 private:
66 virtual ~Factory() override {}
68 css::uno::Reference< css::uno::XComponentContext > m_context;
71 OUString Factory::getImplementationName()
73 return "com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory";
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 { "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory" };
84 return s;
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 "null authority passed to"
94 " XVndSunStarPkgUrlReferenceFactory.createVndSunStarPkgUrlReference");
96 if (authority->isAbsolute() && !authority->hasFragment()) {
97 OUStringBuffer buf(128);
98 buf.append("vnd.sun.star.pkg://");
99 buf.append(
100 rtl::Uri::encode(
101 authority->getUriReference(), rtl_UriCharClassRegName,
102 rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8));
103 css::uno::Reference< css::uri::XUriReference > uriRef(
104 css::uri::UriReferenceFactory::create(m_context)->parse(
105 buf.makeStringAndClear()));
106 return uriRef;
107 } else {
108 return css::uno::Reference< css::uri::XUriReference >();
114 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
115 com_sun_star_comp_uri_VndSunStarPkgUrlReferenceFactory_get_implementation(css::uno::XComponentContext* rxContext,
116 css::uno::Sequence<css::uno::Any> const &)
118 return ::cppu::acquire(new Factory(rxContext));
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */