Line data Source code
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 :
21 : #include "stocservices.hxx"
22 :
23 : #include "supportsService.hxx"
24 :
25 : #include "com/sun/star/lang/XServiceInfo.hpp"
26 : #include "com/sun/star/uno/Exception.hpp"
27 : #include "com/sun/star/uno/Reference.hxx"
28 : #include "com/sun/star/uno/RuntimeException.hpp"
29 : #include "com/sun/star/uno/Sequence.hxx"
30 : #include "com/sun/star/uno/XComponentContext.hpp"
31 : #include "com/sun/star/uno/XInterface.hpp"
32 : #include "com/sun/star/uri/UriReferenceFactory.hpp"
33 : #include "com/sun/star/uri/XUriReference.hpp"
34 : #include "com/sun/star/uri/XUriReferenceFactory.hpp"
35 : #include "com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp"
36 : #include "cppuhelper/implbase2.hxx"
37 : #include "cppuhelper/weak.hxx"
38 : #include "rtl/string.h"
39 : #include "rtl/textenc.h"
40 : #include "rtl/uri.h"
41 : #include "rtl/uri.hxx"
42 : #include "rtl/ustrbuf.hxx"
43 : #include "rtl/ustring.hxx"
44 : #include "sal/types.h"
45 :
46 : #include <new>
47 :
48 : namespace {
49 :
50 : class Factory: public cppu::WeakImplHelper2<
51 : css::lang::XServiceInfo, css::uri::XVndSunStarPkgUrlReferenceFactory >
52 : {
53 : public:
54 0 : explicit Factory(
55 : css::uno::Reference< css::uno::XComponentContext > const & context):
56 0 : m_context(context) {}
57 :
58 : virtual rtl::OUString SAL_CALL getImplementationName()
59 : throw (css::uno::RuntimeException);
60 :
61 : virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName)
62 : throw (css::uno::RuntimeException);
63 :
64 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL
65 : getSupportedServiceNames() throw (css::uno::RuntimeException);
66 :
67 : virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
68 : createVndSunStarPkgUrlReference(
69 : css::uno::Reference< css::uri::XUriReference > const & authority)
70 : throw (css::uno::RuntimeException);
71 :
72 : private:
73 : Factory(Factory &); // not implemented
74 : void operator =(Factory); // not implemented
75 :
76 0 : virtual ~Factory() {}
77 :
78 : css::uno::Reference< css::uno::XComponentContext > m_context;
79 : };
80 :
81 0 : rtl::OUString Factory::getImplementationName()
82 : throw (css::uno::RuntimeException)
83 : {
84 : return
85 : stoc_services::VndSunStarPkgUrlReferenceFactory::
86 0 : getImplementationName();
87 : }
88 :
89 0 : sal_Bool Factory::supportsService(rtl::OUString const & serviceName)
90 : throw (css::uno::RuntimeException)
91 : {
92 : return stoc::uriproc::supportsService(
93 0 : getSupportedServiceNames(), serviceName);
94 : }
95 :
96 0 : css::uno::Sequence< rtl::OUString > Factory::getSupportedServiceNames()
97 : throw (css::uno::RuntimeException)
98 : {
99 : return stoc_services::VndSunStarPkgUrlReferenceFactory::
100 0 : getSupportedServiceNames();
101 : }
102 :
103 : css::uno::Reference< css::uri::XUriReference >
104 0 : Factory::createVndSunStarPkgUrlReference(
105 : css::uno::Reference< css::uri::XUriReference > const & authority)
106 : throw (css::uno::RuntimeException)
107 : {
108 : OSL_ASSERT(authority.is());
109 0 : if (authority->isAbsolute() && !authority->hasFragment()) {
110 0 : rtl::OUStringBuffer buf;
111 0 : buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pkg://"));
112 : buf.append(
113 : rtl::Uri::encode(
114 0 : authority->getUriReference(), rtl_UriCharClassRegName,
115 0 : rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8));
116 : css::uno::Reference< css::uri::XUriReference > uriRef(
117 0 : css::uri::UriReferenceFactory::create(m_context)->parse(
118 0 : buf.makeStringAndClear()));
119 : OSL_ASSERT(uriRef.is());
120 0 : return uriRef;
121 : } else {
122 0 : return css::uno::Reference< css::uri::XUriReference >();
123 : }
124 : }
125 :
126 : }
127 :
128 : namespace stoc_services { namespace VndSunStarPkgUrlReferenceFactory
129 : {
130 :
131 0 : css::uno::Reference< css::uno::XInterface > create(
132 : css::uno::Reference< css::uno::XComponentContext > const & context)
133 : SAL_THROW((css::uno::Exception))
134 : {
135 : try {
136 0 : return static_cast< cppu::OWeakObject * >(new Factory(context));
137 0 : } catch (std::bad_alloc &) {
138 : throw css::uno::RuntimeException(
139 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")), 0);
140 : }
141 : }
142 :
143 28 : rtl::OUString getImplementationName() {
144 : return rtl::OUString(
145 28 : RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory"));
146 : }
147 :
148 0 : css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
149 0 : css::uno::Sequence< rtl::OUString > s(1);
150 0 : s[0] = rtl::OUString(
151 0 : RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uri.VndSunStarPkgUrlReferenceFactory"));
152 0 : return s;
153 : }
154 :
155 : } }
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|