1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_stoc.hxx" 30 31 #include "stocservices.hxx" 32 33 #include "supportsService.hxx" 34 35 #include "com/sun/star/lang/XServiceInfo.hpp" 36 #include "com/sun/star/uno/Exception.hpp" 37 #include "com/sun/star/uno/Reference.hxx" 38 #include "com/sun/star/uno/RuntimeException.hpp" 39 #include "com/sun/star/uno/Sequence.hxx" 40 #include "com/sun/star/uno/XComponentContext.hpp" 41 #include "com/sun/star/uno/XInterface.hpp" 42 #include "com/sun/star/uri/UriReferenceFactory.hpp" 43 #include "com/sun/star/uri/XUriReference.hpp" 44 #include "com/sun/star/uri/XUriReferenceFactory.hpp" 45 #include "com/sun/star/uri/XVndSunStarPkgUrlReferenceFactory.hpp" 46 #include "cppuhelper/implbase2.hxx" 47 #include "cppuhelper/weak.hxx" 48 #include "rtl/string.h" 49 #include "rtl/textenc.h" 50 #include "rtl/uri.h" 51 #include "rtl/uri.hxx" 52 #include "rtl/ustrbuf.hxx" 53 #include "rtl/ustring.hxx" 54 #include "sal/types.h" 55 56 #include <new> 57 58 namespace css = com::sun::star; 59 60 namespace { 61 62 class Factory: public cppu::WeakImplHelper2< 63 css::lang::XServiceInfo, css::uri::XVndSunStarPkgUrlReferenceFactory > 64 { 65 public: 66 explicit Factory( 67 css::uno::Reference< css::uno::XComponentContext > const & context): 68 m_context(context) {} 69 70 virtual rtl::OUString SAL_CALL getImplementationName() 71 throw (css::uno::RuntimeException); 72 73 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName) 74 throw (css::uno::RuntimeException); 75 76 virtual css::uno::Sequence< rtl::OUString > SAL_CALL 77 getSupportedServiceNames() throw (css::uno::RuntimeException); 78 79 virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL 80 createVndSunStarPkgUrlReference( 81 css::uno::Reference< css::uri::XUriReference > const & authority) 82 throw (css::uno::RuntimeException); 83 84 private: 85 Factory(Factory &); // not implemented 86 void operator =(Factory); // not implemented 87 88 virtual ~Factory() {} 89 90 css::uno::Reference< css::uno::XComponentContext > m_context; 91 }; 92 93 rtl::OUString Factory::getImplementationName() 94 throw (css::uno::RuntimeException) 95 { 96 return 97 stoc_services::VndSunStarPkgUrlReferenceFactory:: 98 getImplementationName(); 99 } 100 101 sal_Bool Factory::supportsService(rtl::OUString const & serviceName) 102 throw (css::uno::RuntimeException) 103 { 104 return stoc::uriproc::supportsService( 105 getSupportedServiceNames(), serviceName); 106 } 107 108 css::uno::Sequence< rtl::OUString > Factory::getSupportedServiceNames() 109 throw (css::uno::RuntimeException) 110 { 111 return stoc_services::VndSunStarPkgUrlReferenceFactory:: 112 getSupportedServiceNames(); 113 } 114 115 css::uno::Reference< css::uri::XUriReference > 116 Factory::createVndSunStarPkgUrlReference( 117 css::uno::Reference< css::uri::XUriReference > const & authority) 118 throw (css::uno::RuntimeException) 119 { 120 OSL_ASSERT(authority.is()); 121 if (authority->isAbsolute() && !authority->hasFragment()) { 122 rtl::OUStringBuffer buf; 123 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pkg://")); 124 buf.append( 125 rtl::Uri::encode( 126 authority->getUriReference(), rtl_UriCharClassRegName, 127 rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8)); 128 css::uno::Reference< css::uri::XUriReference > uriRef( 129 css::uri::UriReferenceFactory::create(m_context)->parse( 130 buf.makeStringAndClear())); 131 OSL_ASSERT(uriRef.is()); 132 return uriRef; 133 } else { 134 return css::uno::Reference< css::uri::XUriReference >(); 135 } 136 } 137 138 } 139 140 namespace stoc_services { namespace VndSunStarPkgUrlReferenceFactory 141 { 142 143 css::uno::Reference< css::uno::XInterface > create( 144 css::uno::Reference< css::uno::XComponentContext > const & context) 145 SAL_THROW((css::uno::Exception)) 146 { 147 try { 148 return static_cast< cppu::OWeakObject * >(new Factory(context)); 149 } catch (std::bad_alloc &) { 150 throw css::uno::RuntimeException( 151 rtl::OUString::createFromAscii("std::bad_alloc"), 0); 152 } 153 } 154 155 rtl::OUString getImplementationName() { 156 return rtl::OUString::createFromAscii( 157 "com.sun.star.comp.uri.VndSunStarPkgUrlReferenceFactory"); 158 } 159 160 css::uno::Sequence< rtl::OUString > getSupportedServiceNames() { 161 css::uno::Sequence< rtl::OUString > s(1); 162 s[0] = rtl::OUString::createFromAscii( 163 "com.sun.star.uri.VndSunStarPkgUrlReferenceFactory"); 164 return s; 165 } 166 167 } } 168