LibreOffice Module stoc (master) 1
VndSunStarPkgUrlReferenceFactory.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
29#include <cppuhelper/weak.hxx>
30#include <rtl/textenc.h>
31#include <rtl/uri.h>
32#include <rtl/uri.hxx>
33#include <rtl/ustring.hxx>
34#include <utility>
35#include <sal/types.h>
36
37namespace com::sun::star::uno { class XComponentContext; }
38namespace com::sun::star::uno { class XInterface; }
39
40namespace {
41
42class Factory:
43 public cppu::WeakImplHelper<
44 css::lang::XServiceInfo, css::uri::XVndSunStarPkgUrlReferenceFactory>
45{
46public:
47 explicit Factory(
48 css::uno::Reference< css::uno::XComponentContext > context):
49 m_context(std::move(context)) {}
50
51 Factory(const Factory&) = delete;
52 Factory& operator=(const Factory&) = delete;
53
54 virtual OUString SAL_CALL getImplementationName() override;
55
56 virtual sal_Bool SAL_CALL supportsService(OUString const & serviceName) override;
57
58 virtual css::uno::Sequence< OUString > SAL_CALL
59 getSupportedServiceNames() override;
60
61 virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
62 createVndSunStarPkgUrlReference(
63 css::uno::Reference< css::uri::XUriReference > const & authority) override;
64
65private:
66 virtual ~Factory() override {}
67
68 css::uno::Reference< css::uno::XComponentContext > m_context;
69};
70
71OUString Factory::getImplementationName()
72{
73 return "com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory";
74}
75
76sal_Bool Factory::supportsService(OUString const & serviceName)
77{
78 return cppu::supportsService(this, serviceName);
79}
80
81css::uno::Sequence< OUString > Factory::getSupportedServiceNames()
82{
83 css::uno::Sequence< OUString > s { "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory" };
84 return s;
85}
86
87css::uno::Reference< css::uri::XUriReference >
88Factory::createVndSunStarPkgUrlReference(
89 css::uno::Reference< css::uri::XUriReference > const & authority)
90{
91 if (!authority.is()) {
92 throw css::uno::RuntimeException(
93 "null authority passed to"
94 " XVndSunStarPkgUrlReferenceFactory.createVndSunStarPkgUrlReference");
95 }
96 if (authority->isAbsolute() && !authority->hasFragment()) {
97 OUString buf =
98 "vnd.sun.star.pkg://" +
99 rtl::Uri::encode(
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(
104 buf));
105 return uriRef;
106 } else {
107 return css::uno::Reference< css::uri::XUriReference >();
108 }
109}
110
111}
112
113extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
115 css::uno::Sequence<css::uno::Any> const &)
116{
117 return ::cppu::acquire(new Factory(rxContext));
118}
119
120/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_uri_VndSunStarPkgUrlReferenceFactory_get_implementation(css::uno::XComponentContext *rxContext, css::uno::Sequence< css::uno::Any > const &)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
bool parse(OUString const &uri, SourceProviderScannerData *data)
unsigned char sal_Bool