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/Exception.hpp>
22 #include <com/sun/star/uno/Reference.hxx>
23 #include <com/sun/star/uno/RuntimeException.hpp>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <com/sun/star/uno/XInterface.hpp>
27 #include <com/sun/star/uri/UriReferenceFactory.hpp>
28 #include <com/sun/star/uri/XUriReference.hpp>
29 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
30 #include <com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp>
31 #include <cppuhelper/implbase.hxx>
32 #include <cppuhelper/supportsservice.hxx>
33 #include <cppuhelper/weak.hxx>
34 #include <rtl/string.h>
35 #include <rtl/textenc.h>
37 #include <rtl/uri.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <rtl/ustring.hxx>
40 #include <osl/diagnose.h>
41 #include <sal/types.h>
46 public cppu::WeakImplHelper
<
47 css::lang::XServiceInfo
, css::uri::XVndSunStarPkgUrlReferenceFactory
>
51 css::uno::Reference
< css::uno::XComponentContext
> const & context
):
54 Factory(const Factory
&) = delete;
55 Factory
& operator=(const Factory
&) = delete;
57 virtual OUString SAL_CALL
getImplementationName() override
;
59 virtual sal_Bool SAL_CALL
supportsService(OUString
const & serviceName
) override
;
61 virtual css::uno::Sequence
< OUString
> SAL_CALL
62 getSupportedServiceNames() override
;
64 virtual css::uno::Reference
< css::uri::XUriReference
> SAL_CALL
65 createVndSunStarPkgUrlReference(
66 css::uno::Reference
< css::uri::XUriReference
> const & authority
) override
;
69 virtual ~Factory() override
{}
71 css::uno::Reference
< css::uno::XComponentContext
> m_context
;
74 OUString
Factory::getImplementationName()
76 return OUString("com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory");
79 sal_Bool
Factory::supportsService(OUString
const & serviceName
)
81 return cppu::supportsService(this, serviceName
);
84 css::uno::Sequence
< OUString
> Factory::getSupportedServiceNames()
86 css::uno::Sequence
< OUString
> s
{ "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory" };
90 css::uno::Reference
< css::uri::XUriReference
>
91 Factory::createVndSunStarPkgUrlReference(
92 css::uno::Reference
< css::uri::XUriReference
> const & authority
)
94 OSL_ASSERT(authority
.is());
95 if (authority
->isAbsolute() && !authority
->hasFragment()) {
97 buf
.append("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(
104 buf
.makeStringAndClear()));
105 OSL_ASSERT(uriRef
.is());
108 return css::uno::Reference
< css::uri::XUriReference
>();
114 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
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: */