1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*647a425cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*647a425cSAndrew Rist * distributed with this work for additional information
6*647a425cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*647a425cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist * with the License. You may obtain a copy of the License at
10*647a425cSAndrew Rist *
11*647a425cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist *
13*647a425cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist * software distributed under the License is distributed on an
15*647a425cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist * KIND, either express or implied. See the License for the
17*647a425cSAndrew Rist * specific language governing permissions and limitations
18*647a425cSAndrew Rist * under the License.
19*647a425cSAndrew Rist *
20*647a425cSAndrew Rist *************************************************************/
21*647a425cSAndrew Rist
22*647a425cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "stocservices.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "supportsService.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp"
32cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
33cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
34cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
35cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
36cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
37cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
38cdf0e10cSrcweir #include "com/sun/star/uri/UriReferenceFactory.hpp"
39cdf0e10cSrcweir #include "com/sun/star/uri/XUriReference.hpp"
40cdf0e10cSrcweir #include "com/sun/star/uri/XUriReferenceFactory.hpp"
41cdf0e10cSrcweir #include "com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp"
42cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
43cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
44cdf0e10cSrcweir #include "rtl/string.h"
45cdf0e10cSrcweir #include "rtl/textenc.h"
46cdf0e10cSrcweir #include "rtl/uri.h"
47cdf0e10cSrcweir #include "rtl/uri.hxx"
48cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
49cdf0e10cSrcweir #include "rtl/ustring.hxx"
50cdf0e10cSrcweir #include "sal/types.h"
51cdf0e10cSrcweir
52cdf0e10cSrcweir #include <new>
53cdf0e10cSrcweir
54cdf0e10cSrcweir namespace css = com::sun::star;
55cdf0e10cSrcweir
56cdf0e10cSrcweir namespace {
57cdf0e10cSrcweir
58cdf0e10cSrcweir class Factory: public cppu::WeakImplHelper2<
59cdf0e10cSrcweir css::lang::XServiceInfo, css::uri::XVndSunStarPkgUrlReferenceFactory >
60cdf0e10cSrcweir {
61cdf0e10cSrcweir public:
Factory(css::uno::Reference<css::uno::XComponentContext> const & context)62cdf0e10cSrcweir explicit Factory(
63cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & context):
64cdf0e10cSrcweir m_context(context) {}
65cdf0e10cSrcweir
66cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName()
67cdf0e10cSrcweir throw (css::uno::RuntimeException);
68cdf0e10cSrcweir
69cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName)
70cdf0e10cSrcweir throw (css::uno::RuntimeException);
71cdf0e10cSrcweir
72cdf0e10cSrcweir virtual css::uno::Sequence< rtl::OUString > SAL_CALL
73cdf0e10cSrcweir getSupportedServiceNames() throw (css::uno::RuntimeException);
74cdf0e10cSrcweir
75cdf0e10cSrcweir virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL
76cdf0e10cSrcweir createVndSunStarPkgUrlReference(
77cdf0e10cSrcweir css::uno::Reference< css::uri::XUriReference > const & authority)
78cdf0e10cSrcweir throw (css::uno::RuntimeException);
79cdf0e10cSrcweir
80cdf0e10cSrcweir private:
81cdf0e10cSrcweir Factory(Factory &); // not implemented
82cdf0e10cSrcweir void operator =(Factory); // not implemented
83cdf0e10cSrcweir
~Factory()84cdf0e10cSrcweir virtual ~Factory() {}
85cdf0e10cSrcweir
86cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > m_context;
87cdf0e10cSrcweir };
88cdf0e10cSrcweir
getImplementationName()89cdf0e10cSrcweir rtl::OUString Factory::getImplementationName()
90cdf0e10cSrcweir throw (css::uno::RuntimeException)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir return
93cdf0e10cSrcweir stoc_services::VndSunStarPkgUrlReferenceFactory::
94cdf0e10cSrcweir getImplementationName();
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
supportsService(rtl::OUString const & serviceName)97cdf0e10cSrcweir sal_Bool Factory::supportsService(rtl::OUString const & serviceName)
98cdf0e10cSrcweir throw (css::uno::RuntimeException)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir return stoc::uriproc::supportsService(
101cdf0e10cSrcweir getSupportedServiceNames(), serviceName);
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
getSupportedServiceNames()104cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > Factory::getSupportedServiceNames()
105cdf0e10cSrcweir throw (css::uno::RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir return stoc_services::VndSunStarPkgUrlReferenceFactory::
108cdf0e10cSrcweir getSupportedServiceNames();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
111cdf0e10cSrcweir css::uno::Reference< css::uri::XUriReference >
createVndSunStarPkgUrlReference(css::uno::Reference<css::uri::XUriReference> const & authority)112cdf0e10cSrcweir Factory::createVndSunStarPkgUrlReference(
113cdf0e10cSrcweir css::uno::Reference< css::uri::XUriReference > const & authority)
114cdf0e10cSrcweir throw (css::uno::RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir OSL_ASSERT(authority.is());
117cdf0e10cSrcweir if (authority->isAbsolute() && !authority->hasFragment()) {
118cdf0e10cSrcweir rtl::OUStringBuffer buf;
119cdf0e10cSrcweir buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pkg://"));
120cdf0e10cSrcweir buf.append(
121cdf0e10cSrcweir rtl::Uri::encode(
122cdf0e10cSrcweir authority->getUriReference(), rtl_UriCharClassRegName,
123cdf0e10cSrcweir rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8));
124cdf0e10cSrcweir css::uno::Reference< css::uri::XUriReference > uriRef(
125cdf0e10cSrcweir css::uri::UriReferenceFactory::create(m_context)->parse(
126cdf0e10cSrcweir buf.makeStringAndClear()));
127cdf0e10cSrcweir OSL_ASSERT(uriRef.is());
128cdf0e10cSrcweir return uriRef;
129cdf0e10cSrcweir } else {
130cdf0e10cSrcweir return css::uno::Reference< css::uri::XUriReference >();
131cdf0e10cSrcweir }
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir }
135cdf0e10cSrcweir
136cdf0e10cSrcweir namespace stoc_services { namespace VndSunStarPkgUrlReferenceFactory
137cdf0e10cSrcweir {
138cdf0e10cSrcweir
create(css::uno::Reference<css::uno::XComponentContext> const & context)139cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > create(
140cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & context)
141cdf0e10cSrcweir SAL_THROW((css::uno::Exception))
142cdf0e10cSrcweir {
143cdf0e10cSrcweir try {
144cdf0e10cSrcweir return static_cast< cppu::OWeakObject * >(new Factory(context));
145cdf0e10cSrcweir } catch (std::bad_alloc &) {
146cdf0e10cSrcweir throw css::uno::RuntimeException(
147cdf0e10cSrcweir rtl::OUString::createFromAscii("std::bad_alloc"), 0);
148cdf0e10cSrcweir }
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
getImplementationName()151cdf0e10cSrcweir rtl::OUString getImplementationName() {
152cdf0e10cSrcweir return rtl::OUString::createFromAscii(
153cdf0e10cSrcweir "com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory");
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
getSupportedServiceNames()156cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
157cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > s(1);
158cdf0e10cSrcweir s[0] = rtl::OUString::createFromAscii(
159cdf0e10cSrcweir "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory");
160cdf0e10cSrcweir return s;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163cdf0e10cSrcweir } }
164