1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VndSunStarPkgUrlReferenceFactory.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_stoc.hxx"
34 #include "stocservices.hxx"
36 #include "supportsService.hxx"
38 #include "com/sun/star/lang/XServiceInfo.hpp"
39 #include "com/sun/star/uno/Exception.hpp"
40 #include "com/sun/star/uno/Reference.hxx"
41 #include "com/sun/star/uno/RuntimeException.hpp"
42 #include "com/sun/star/uno/Sequence.hxx"
43 #include "com/sun/star/uno/XComponentContext.hpp"
44 #include "com/sun/star/uno/XInterface.hpp"
45 #include "com/sun/star/uri/UriReferenceFactory.hpp"
46 #include "com/sun/star/uri/XUriReference.hpp"
47 #include "com/sun/star/uri/XUriReferenceFactory.hpp"
48 #include "com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp"
49 #include "cppuhelper/implbase2.hxx"
50 #include "cppuhelper/weak.hxx"
51 #include "rtl/string.h"
52 #include "rtl/textenc.h"
54 #include "rtl/uri.hxx"
55 #include "rtl/ustrbuf.hxx"
56 #include "rtl/ustring.hxx"
57 #include "sal/types.h"
61 namespace css
= com::sun::star
;
65 class Factory
: public cppu::WeakImplHelper2
<
66 css::lang::XServiceInfo
, css::uri::XVndSunStarPkgUrlReferenceFactory
>
70 css::uno::Reference
< css::uno::XComponentContext
> const & context
):
73 virtual rtl::OUString SAL_CALL
getImplementationName()
74 throw (css::uno::RuntimeException
);
76 virtual sal_Bool SAL_CALL
supportsService(rtl::OUString
const & serviceName
)
77 throw (css::uno::RuntimeException
);
79 virtual css::uno::Sequence
< rtl::OUString
> SAL_CALL
80 getSupportedServiceNames() throw (css::uno::RuntimeException
);
82 virtual css::uno::Reference
< css::uri::XUriReference
> SAL_CALL
83 createVndSunStarPkgUrlReference(
84 css::uno::Reference
< css::uri::XUriReference
> const & authority
)
85 throw (css::uno::RuntimeException
);
88 Factory(Factory
&); // not implemented
89 void operator =(Factory
); // not implemented
93 css::uno::Reference
< css::uno::XComponentContext
> m_context
;
96 rtl::OUString
Factory::getImplementationName()
97 throw (css::uno::RuntimeException
)
100 stoc_services::VndSunStarPkgUrlReferenceFactory::
101 getImplementationName();
104 sal_Bool
Factory::supportsService(rtl::OUString
const & serviceName
)
105 throw (css::uno::RuntimeException
)
107 return stoc::uriproc::supportsService(
108 getSupportedServiceNames(), serviceName
);
111 css::uno::Sequence
< rtl::OUString
> Factory::getSupportedServiceNames()
112 throw (css::uno::RuntimeException
)
114 return stoc_services::VndSunStarPkgUrlReferenceFactory::
115 getSupportedServiceNames();
118 css::uno::Reference
< css::uri::XUriReference
>
119 Factory::createVndSunStarPkgUrlReference(
120 css::uno::Reference
< css::uri::XUriReference
> const & authority
)
121 throw (css::uno::RuntimeException
)
123 OSL_ASSERT(authority
.is());
124 if (authority
->isAbsolute() && !authority
->hasFragment()) {
125 rtl::OUStringBuffer buf
;
126 buf
.appendAscii(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pkg://"));
129 authority
->getUriReference(), rtl_UriCharClassRegName
,
130 rtl_UriEncodeIgnoreEscapes
, RTL_TEXTENCODING_UTF8
));
131 css::uno::Reference
< css::uri::XUriReference
> uriRef(
132 css::uri::UriReferenceFactory::create(m_context
)->parse(
133 buf
.makeStringAndClear()));
134 OSL_ASSERT(uriRef
.is());
137 return css::uno::Reference
< css::uri::XUriReference
>();
143 namespace stoc_services
{ namespace VndSunStarPkgUrlReferenceFactory
146 css::uno::Reference
< css::uno::XInterface
> create(
147 css::uno::Reference
< css::uno::XComponentContext
> const & context
)
148 SAL_THROW((css::uno::Exception
))
151 return static_cast< cppu::OWeakObject
* >(new Factory(context
));
152 } catch (std::bad_alloc
&) {
153 throw css::uno::RuntimeException(
154 rtl::OUString::createFromAscii("std::bad_alloc"), 0);
158 rtl::OUString
getImplementationName() {
159 return rtl::OUString::createFromAscii(
160 "com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory");
163 css::uno::Sequence
< rtl::OUString
> getSupportedServiceNames() {
164 css::uno::Sequence
< rtl::OUString
> s(1);
165 s
[0] = rtl::OUString::createFromAscii(
166 "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory");