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 : #ifndef INCLUDED_EXTENSIONS_SOURCE_RESOURCE_OOORESOURCELOADER_HXX
21 : #define INCLUDED_EXTENSIONS_SOURCE_RESOURCE_OOORESOURCELOADER_HXX
22 :
23 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 : #include <com/sun/star/resource/XResourceBundleLoader.hpp>
25 : #include <com/sun/star/uno/XComponentContext.hpp>
26 : #include <cppuhelper/implbase1.hxx>
27 :
28 : #include <functional>
29 : #include <map>
30 : #include <utility>
31 :
32 : namespace extensions { namespace resource
33 : {
34 : typedef ::std::pair< OUString, ::com::sun::star::lang::Locale> ResourceBundleDescriptor;
35 :
36 : struct ResourceBundleDescriptorLess : public ::std::binary_function<ResourceBundleDescriptor, ResourceBundleDescriptor, bool>
37 : {
38 16 : bool operator()( const ResourceBundleDescriptor& _lhs, const ResourceBundleDescriptor& _rhs ) const
39 : {
40 16 : if ( _lhs.first < _rhs.first )
41 0 : return true;
42 16 : if ( _lhs.second.Language < _rhs.second.Language )
43 0 : return true;
44 16 : if ( _lhs.second.Country < _rhs.second.Country )
45 0 : return true;
46 16 : if ( _lhs.second.Variant < _rhs.second.Variant )
47 0 : return true;
48 16 : return false;
49 : }
50 : };
51 :
52 5 : class OpenOfficeResourceLoader : public ::cppu::WeakImplHelper1< ::com::sun::star::resource::XResourceBundleLoader>
53 : {
54 : public:
55 : typedef ::std::map<
56 : ResourceBundleDescriptor,
57 : ::com::sun::star::uno::WeakReference< ::com::sun::star::resource::XResourceBundle>,
58 : ResourceBundleDescriptorLess> ResourceBundleCache;
59 :
60 : OpenOfficeResourceLoader(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const&);
61 : // XResourceBundleLoader
62 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::resource::XResourceBundle> SAL_CALL loadBundle_Default( const OUString& aBaseName ) throw (::com::sun::star::resource::MissingResourceException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
63 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::resource::XResourceBundle> SAL_CALL loadBundle( const OUString& abaseName, const ::com::sun::star::lang::Locale& aLocale ) throw (::com::sun::star::resource::MissingResourceException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 :
65 : private:
66 : OpenOfficeResourceLoader( const OpenOfficeResourceLoader& ) SAL_DELETED_FUNCTION;
67 : OpenOfficeResourceLoader& operator=( const OpenOfficeResourceLoader& ) SAL_DELETED_FUNCTION;
68 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> m_xContext;
69 : ::osl::Mutex m_aMutex;
70 : ResourceBundleCache m_aBundleCache;
71 : };
72 : }}
73 :
74 : #endif // INCLUDED_EXTENSIONS_SOURCE_RESOURCE_OOORESOURCELOADER_HXX
75 :
76 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|