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 #include "precompiled_configmgr.hxx" 29 #include "sal/config.h" 30 31 #include <set> 32 33 #include "boost/noncopyable.hpp" 34 #include "com/sun/star/configuration/XUpdate.hpp" 35 #include "com/sun/star/uno/Reference.hxx" 36 #include "com/sun/star/uno/RuntimeException.hpp" 37 #include "com/sun/star/uno/Sequence.hxx" 38 #include "com/sun/star/uno/XComponentContext.hpp" 39 #include "com/sun/star/uno/XInterface.hpp" 40 #include "cppuhelper/implbase1.hxx" 41 #include "cppuhelper/weak.hxx" 42 #include "osl/mutex.hxx" 43 #include "rtl/ref.hxx" 44 #include "rtl/ustring.h" 45 #include "rtl/ustring.hxx" 46 #include "sal/types.h" 47 48 #include "broadcaster.hxx" 49 #include "components.hxx" 50 #include "lock.hxx" 51 #include "modifications.hxx" 52 #include "rootaccess.hxx" 53 #include "update.hxx" 54 55 namespace configmgr { namespace update { 56 57 namespace { 58 59 namespace css = com::sun::star; 60 61 std::set< rtl::OUString > seqToSet( 62 css::uno::Sequence< rtl::OUString > const & sequence) 63 { 64 return std::set< rtl::OUString >( 65 sequence.getConstArray(), 66 sequence.getConstArray() + sequence.getLength()); 67 } 68 69 class Service: 70 public cppu::WeakImplHelper1< css::configuration::XUpdate >, 71 private boost::noncopyable 72 { 73 public: 74 Service(css::uno::Reference< css::uno::XComponentContext > const context): 75 context_(context) 76 { 77 OSL_ASSERT(context.is()); 78 } 79 80 private: 81 virtual ~Service() {} 82 83 virtual void SAL_CALL insertExtensionXcsFile( 84 sal_Bool shared, rtl::OUString const & fileUri) 85 throw (css::uno::RuntimeException); 86 87 virtual void SAL_CALL insertExtensionXcuFile( 88 sal_Bool shared, rtl::OUString const & fileUri) 89 throw (css::uno::RuntimeException); 90 91 virtual void SAL_CALL removeExtensionXcuFile(rtl::OUString const & fileUri) 92 throw (css::uno::RuntimeException); 93 94 virtual void SAL_CALL insertModificationXcuFile( 95 rtl::OUString const & fileUri, 96 css::uno::Sequence< rtl::OUString > const & includedPaths, 97 css::uno::Sequence< rtl::OUString > const & excludedPaths) 98 throw (css::uno::RuntimeException); 99 100 css::uno::Reference< css::uno::XComponentContext > context_; 101 }; 102 103 void Service::insertExtensionXcsFile( 104 sal_Bool shared, rtl::OUString const & fileUri) 105 throw (css::uno::RuntimeException) 106 { 107 osl::MutexGuard g(lock); 108 Components::getSingleton(context_).insertExtensionXcsFile(shared, fileUri); 109 } 110 111 void Service::insertExtensionXcuFile( 112 sal_Bool shared, rtl::OUString const & fileUri) 113 throw (css::uno::RuntimeException) 114 { 115 Broadcaster bc; 116 { 117 osl::MutexGuard g(lock); 118 Components & components = Components::getSingleton(context_); 119 Modifications mods; 120 components.insertExtensionXcuFile(shared, fileUri, &mods); 121 components.initGlobalBroadcaster( 122 mods, rtl::Reference< RootAccess >(), &bc); 123 } 124 bc.send(); 125 } 126 127 void Service::removeExtensionXcuFile(rtl::OUString const & fileUri) 128 throw (css::uno::RuntimeException) 129 { 130 Broadcaster bc; 131 { 132 osl::MutexGuard g(lock); 133 Components & components = Components::getSingleton(context_); 134 Modifications mods; 135 components.removeExtensionXcuFile(fileUri, &mods); 136 components.initGlobalBroadcaster( 137 mods, rtl::Reference< RootAccess >(), &bc); 138 } 139 bc.send(); 140 } 141 142 void Service::insertModificationXcuFile( 143 rtl::OUString const & fileUri, 144 css::uno::Sequence< rtl::OUString > const & includedPaths, 145 css::uno::Sequence< rtl::OUString > const & excludedPaths) 146 throw (css::uno::RuntimeException) 147 { 148 Broadcaster bc; 149 { 150 osl::MutexGuard g(lock); 151 Components & components = Components::getSingleton(context_); 152 Modifications mods; 153 components.insertModificationXcuFile( 154 fileUri, seqToSet(includedPaths), seqToSet(excludedPaths), &mods); 155 components.initGlobalBroadcaster( 156 mods, rtl::Reference< RootAccess >(), &bc); 157 } 158 bc.send(); 159 } 160 161 } 162 163 css::uno::Reference< css::uno::XInterface > create( 164 css::uno::Reference< css::uno::XComponentContext > const & context) 165 { 166 return static_cast< cppu::OWeakObject * >(new Service(context)); 167 } 168 169 rtl::OUString getImplementationName() { 170 return rtl::OUString( 171 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.configuration.Update")); 172 } 173 174 css::uno::Sequence< rtl::OUString > getSupportedServiceNames() { 175 rtl::OUString name( 176 RTL_CONSTASCII_USTRINGPARAM( 177 "com.sun.star.configuration.Update_Service")); 178 return css::uno::Sequence< rtl::OUString >(&name, 1); 179 } 180 181 } } 182