summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@canonical.com>2011-05-26 11:04:53 +0200
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2011-05-26 11:04:53 +0200
commit21cdeb7b93bfbf8093f6d67aface05ca38a9ab11 (patch)
tree09b5afeb286321435bb61ab4bc648bc79746e91e /extensions
parent639f9c682b74981f83d88969b7f06295b080758a (diff)
remove broken VclStringResourceLoader, add ResourceStringIndexAccess
* remove com.sun.star.resource.VclStringResourceLoader, it is broken beyond repair * implement org.libreoffice.resource.ResourceStringIndexAccess * same functionality, better interface * migrate libresXXXX to comphelper/servicedecl.hxx component registration
Diffstat (limited to 'extensions')
-rw-r--r--extensions/source/resource/ResourceStringIndexAccess.cxx94
-rw-r--r--extensions/source/resource/ResourceStringIndexAccess.hxx71
-rw-r--r--extensions/source/resource/makefile.mk8
-rw-r--r--extensions/source/resource/oooresourceloader.cxx169
-rw-r--r--extensions/source/resource/oooresourceloader.hxx87
-rw-r--r--extensions/source/resource/res.component6
-rw-r--r--extensions/source/resource/res_services.cxx89
-rw-r--r--extensions/source/resource/res_services.hxx67
-rw-r--r--extensions/source/resource/resource.cxx476
-rw-r--r--extensions/source/resource/resourceservices.cxx58
10 files changed, 327 insertions, 798 deletions
diff --git a/extensions/source/resource/ResourceStringIndexAccess.cxx b/extensions/source/resource/ResourceStringIndexAccess.cxx
new file mode 100644
index 000000000000..d48d636bfa11
--- /dev/null
+++ b/extensions/source/resource/ResourceStringIndexAccess.cxx
@@ -0,0 +1,94 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * Bjoern Michaelsen <bjoern.michaelsen@canonical.com>
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Major Contributor(s):
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include <ResourceStringIndexAccess.hxx>
+
+#include <osl/mutex.hxx>
+#include <tools/rcid.h>
+#include <tools/resary.hxx>
+#include <tools/resmgr.hxx>
+#include <vcl/svapp.hxx>
+
+using namespace ::extensions::resource;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+
+using ::rtl::OUString;
+using ::rtl::OString;
+using ::rtl::OUStringToOString;
+
+namespace
+{
+ static ::std::auto_ptr<ResMgr> GetResMgr(Sequence<Any> const& rArgs)
+ {
+ if(rArgs.getLength()!=1)
+ return ::std::auto_ptr<ResMgr>();
+ OUString sFilename;
+ rArgs[0] >>= sFilename;
+ SolarMutexGuard aGuard;
+ const OString sEncName(OUStringToOString(sFilename, osl_getThreadTextEncoding()));
+ return ::std::auto_ptr<ResMgr>(ResMgr::CreateResMgr(sEncName));
+ }
+}
+
+
+ResourceStringIndexAccess::ResourceStringIndexAccess(Sequence<Any> const& rArgs, Reference<XComponentContext> const&)
+ : m_pResMgr(GetResMgr(rArgs))
+{};
+
+Reference<XInterface> initResourceStringIndexAccess(ResourceStringIndexAccess* pResourceStringIndexAccess)
+{
+ Reference<XInterface> xResult(static_cast<cppu::OWeakObject*>(pResourceStringIndexAccess));
+ if(!pResourceStringIndexAccess->hasElements())
+ // xResult does not help the client to analyse the problem
+ // and will crash on getByIndex calls, better just give back an empty Reference
+ // so that such ResourceStringIndexAccess instances are never release into the wild
+ throw RuntimeException(
+ OUString(RTL_CONSTASCII_USTRINGPARAM("ressource manager could not get initialized")),
+ /* xResult */ Reference<XInterface>());
+ return xResult;
+}
+
+Any SAL_CALL ResourceStringIndexAccess::getByIndex(sal_Int32 nIdx)
+ throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
+{
+ if(nIdx > SAL_MAX_UINT16 || nIdx < 0)
+ throw IndexOutOfBoundsException();
+ SolarMutexGuard aGuard;
+ const ResId aId(static_cast<sal_uInt16>(nIdx), *m_pResMgr);
+ aId.SetRT(RSC_STRING);
+ if(!m_pResMgr->IsAvailable(aId))
+ throw RuntimeException(
+ OUString(RTL_CONSTASCII_USTRINGPARAM("string ressource for id not available")),
+ Reference<XInterface>());
+ return makeAny(OUString(String(aId)));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/resource/ResourceStringIndexAccess.hxx b/extensions/source/resource/ResourceStringIndexAccess.hxx
new file mode 100644
index 000000000000..e1a01e3a5de0
--- /dev/null
+++ b/extensions/source/resource/ResourceStringIndexAccess.hxx
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * Bjoern Michaelsen <bjoern.michaelsen@canonical.com>
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Major Contributor(s):
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef EXTENSIONS_RESOURCE_RESOURCESTRINGINDEXACCESS_HXX
+#define EXTENSIONS_RESOURCE_RESOURCESTRINGINDEXACCESS_HXX
+
+#include "precompiled_extensions.hxx"
+
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/XInterface.hpp>
+#include <cppuhelper/implbase1.hxx>
+#include <memory>
+
+class ResMgr;
+
+namespace extensions { namespace resource
+{
+ class ResourceStringIndexAccess : public cppu::WeakImplHelper1< ::com::sun::star::container::XIndexAccess>
+ {
+ public:
+ ResourceStringIndexAccess(::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> const& rArgs, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const&);
+ // XIndexAccess
+ virtual ::sal_Int32 SAL_CALL getCount( ) throw (::com::sun::star::uno::RuntimeException)
+ { return m_pResMgr.get() ? SAL_MAX_UINT16 : 0; };
+ virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
+ // XElementAccess
+ virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException)
+ { return ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)); };
+ virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException)
+ { return static_cast<bool>(m_pResMgr.get()); };
+
+ private:
+ // m_pResMgr should never be NULL, see initResourceStringIndexAccess
+ const ::std::auto_ptr<ResMgr> m_pResMgr;
+ };
+
+}}
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> initResourceStringIndexAccess(::extensions::resource::ResourceStringIndexAccess*);
+
+#endif
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/resource/makefile.mk b/extensions/source/resource/makefile.mk
index adeec5fd09dc..d9143d2d37be 100644
--- a/extensions/source/resource/makefile.mk
+++ b/extensions/source/resource/makefile.mk
@@ -39,9 +39,10 @@ ENABLE_EXCEPTIONS=TRUE
# --- Files --------------------------------------------------------
-SLOFILES= $(SLO)$/resource.obj \
- $(SLO)$/oooresourceloader.obj \
- $(SLO)$/res_services.obj
+SLOFILES= \
+ $(SLO)$/ResourceStringIndexAccess.obj \
+ $(SLO)$/oooresourceloader.obj \
+ $(SLO)$/resourceservices.obj
LIB1TARGET= $(SLB)$/$(TARGET).lib
LIB1OBJFILES= $(SLOFILES)
@@ -49,6 +50,7 @@ LIB1OBJFILES= $(SLOFILES)
SHL1TARGET= $(TARGET)$(DLLPOSTFIX)
SHL1STDLIBS= \
+ $(COMPHELPERLIB) \
$(CPPULIB) \
$(CPPUHELPERLIB) \
$(SALLIB) \
diff --git a/extensions/source/resource/oooresourceloader.cxx b/extensions/source/resource/oooresourceloader.cxx
index ee5cc2a0ea3f..6e89ff24168b 100644
--- a/extensions/source/resource/oooresourceloader.cxx
+++ b/extensions/source/resource/oooresourceloader.cxx
@@ -29,15 +29,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_extensions.hxx"
-#ifndef EXTENSIONS_SOURCE_RESOURCE_OOORESOURCELOADER_CXX
-#define EXTENSIONS_SOURCE_RESOURCE_OOORESOURCELOADER_CXX
-#include "res_services.hxx"
-
-/** === begin UNO includes === **/
-#include <com/sun/star/resource/XResourceBundleLoader.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/uno/XComponentContext.hpp>
-/** === end UNO includes === **/
+#include <oooresourceloader.hxx>
#include <vcl/svapp.hxx>
#include <tools/simplerm.hxx>
#include <tools/rcid.h>
@@ -47,87 +39,14 @@
#include <boost/shared_ptr.hpp>
#include <map>
-//........................................................................
-namespace res
-{
-//........................................................................
-
- /** === begin UNO using === **/
- using ::com::sun::star::uno::Reference;
- using ::com::sun::star::resource::XResourceBundleLoader;
- using ::com::sun::star::resource::XResourceBundle;
- using ::com::sun::star::resource::MissingResourceException;
- using ::com::sun::star::uno::XComponentContext;
- using ::com::sun::star::uno::Sequence;
- using ::com::sun::star::uno::XInterface;
- using ::com::sun::star::uno::RuntimeException;
- using ::com::sun::star::lang::Locale;
- using ::com::sun::star::uno::Any;
- using ::com::sun::star::container::NoSuchElementException;
- using ::com::sun::star::lang::WrappedTargetException;
- using ::com::sun::star::uno::Type;
- using ::com::sun::star::uno::WeakReference;
- /** === end UNO using === **/
-
- //====================================================================
- //= helper
- //====================================================================
- typedef ::std::pair< ::rtl::OUString, Locale > ResourceBundleDescriptor;
-
- struct ResourceBundleDescriptorLess : public ::std::binary_function< ResourceBundleDescriptor, ResourceBundleDescriptor, bool >
- {
- bool operator()( const ResourceBundleDescriptor& _lhs, const ResourceBundleDescriptor& _rhs ) const
- {
- if ( _lhs.first < _rhs.first )
- return true;
- if ( _lhs.second.Language < _rhs.second.Language )
- return true;
- if ( _lhs.second.Country < _rhs.second.Country )
- return true;
- if ( _lhs.second.Variant < _rhs.second.Variant )
- return true;
- return false;
- }
- };
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::resource;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
- //====================================================================
- //= OpenOfficeResourceLoader
- //====================================================================
- typedef ::cppu::WeakImplHelper1 < XResourceBundleLoader
- > OpenOfficeResourceLoader_Base;
- class OpenOfficeResourceLoader : public OpenOfficeResourceLoader_Base
- {
- private:
- typedef ::std::map< ResourceBundleDescriptor, WeakReference< XResourceBundle >, ResourceBundleDescriptorLess >
- ResourceBundleCache;
-
- private:
- Reference< XComponentContext > m_xContext;
- ::osl::Mutex m_aMutex;
- ResourceBundleCache m_aBundleCache;
-
- protected:
- OpenOfficeResourceLoader( const Reference< XComponentContext >& _rxContext );
-
- public:
- static Sequence< ::rtl::OUString > getSupportedServiceNames_static();
- static ::rtl::OUString getImplementationName_static();
- static ::rtl::OUString getSingletonName_static();
- static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext );
- // XResourceBundleLoader
- virtual Reference< XResourceBundle > SAL_CALL loadBundle_Default( const ::rtl::OUString& aBaseName ) throw (MissingResourceException, RuntimeException);
- virtual Reference< XResourceBundle > SAL_CALL loadBundle( const ::rtl::OUString& abaseName, const Locale& aLocale ) throw (MissingResourceException, RuntimeException);
-
- private:
- OpenOfficeResourceLoader(); // never implemented
- OpenOfficeResourceLoader( const OpenOfficeResourceLoader& ); // never implemented
- OpenOfficeResourceLoader& operator=( const OpenOfficeResourceLoader& ); // never implemented
- };
-
- //====================================================================
- //= IResourceType
- //====================================================================
+namespace extensions { namespace resource
+{
/** encapsulates access to a fixed resource type
*/
class IResourceType
@@ -153,9 +72,6 @@ namespace res
virtual ~IResourceType() { };
};
- //====================================================================
- //= StringResourceAccess
- //====================================================================
class StringResourceAccess : public IResourceType
{
public:
@@ -166,18 +82,15 @@ namespace res
virtual Any getResource( SimpleResMgr& _resourceManager, sal_Int32 _resourceId ) const;
};
- //--------------------------------------------------------------------
StringResourceAccess::StringResourceAccess()
{
}
- //--------------------------------------------------------------------
RESOURCE_TYPE StringResourceAccess::getResourceType() const
{
return RSC_STRING;
}
- //--------------------------------------------------------------------
Any StringResourceAccess::getResource( SimpleResMgr& _resourceManager, sal_Int32 _resourceId ) const
{
OSL_PRECOND( _resourceManager.IsAvailable( getResourceType(), _resourceId ), "StringResourceAccess::getResource: precondition not met!" );
@@ -186,9 +99,6 @@ namespace res
return aResource;
}
- //====================================================================
- //= OpenOfficeResourceBundle
- //====================================================================
typedef ::cppu::WeakImplHelper1 < XResourceBundle
> OpenOfficeResourceBundle_Base;
class OpenOfficeResourceBundle : public OpenOfficeResourceBundle_Base
@@ -257,42 +167,12 @@ namespace res
bool impl_getResourceTypeAndId_nothrow( const ::rtl::OUString& _key, ResourceTypePtr& _out_resourceType, sal_Int32& _out_resourceId ) const;
};
- //====================================================================
- //= OpenOfficeResourceLoader
- //====================================================================
- //--------------------------------------------------------------------
- OpenOfficeResourceLoader::OpenOfficeResourceLoader( const Reference< XComponentContext >& _rxContext )
+ OpenOfficeResourceLoader::OpenOfficeResourceLoader( Reference< XComponentContext > const& _rxContext )
:m_xContext( _rxContext )
{
}
//--------------------------------------------------------------------
- Sequence< ::rtl::OUString > OpenOfficeResourceLoader::getSupportedServiceNames_static()
- {
- Sequence< ::rtl::OUString > aServices( 1 );
- aServices[ 0 ] = getSingletonName_static();
- return aServices;
- }
-
- //--------------------------------------------------------------------
- ::rtl::OUString OpenOfficeResourceLoader::getImplementationName_static()
- {
- return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.resource.OpenOfficeResourceLoader" ) );
- }
-
- //--------------------------------------------------------------------
- ::rtl::OUString OpenOfficeResourceLoader::getSingletonName_static()
- {
- return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.resource.OfficeResourceLoader" ) );
- }
-
- //--------------------------------------------------------------------
- Reference< XInterface > OpenOfficeResourceLoader::Create( const Reference< XComponentContext >& _rxContext )
- {
- return *( new OpenOfficeResourceLoader( _rxContext ) );
- }
-
- //--------------------------------------------------------------------
Reference< XResourceBundle > SAL_CALL OpenOfficeResourceLoader::loadBundle_Default( const ::rtl::OUString& _baseName ) throw (MissingResourceException, RuntimeException)
{
return loadBundle( _baseName, Application::GetSettings().GetUILocale() );
@@ -319,21 +199,6 @@ namespace res
return xBundle;
}
- //--------------------------------------------------------------------
- ComponentInfo getComponentInfo_OpenOfficeResourceLoader()
- {
- ComponentInfo aInfo;
- aInfo.aSupportedServices = OpenOfficeResourceLoader::getSupportedServiceNames_static();
- aInfo.sImplementationName = OpenOfficeResourceLoader::getImplementationName_static();
- aInfo.sSingletonName = OpenOfficeResourceLoader::getSingletonName_static();
- aInfo.pFactory = &OpenOfficeResourceLoader::Create;
- return aInfo;
- }
-
- //====================================================================
- //= OpenOfficeResourceBundle
- //====================================================================
- //--------------------------------------------------------------------
OpenOfficeResourceBundle::OpenOfficeResourceBundle( const Reference< XComponentContext >& /*_rxContext*/, const ::rtl::OUString& _rBaseName, const Locale& _rLocale )
:m_aLocale( _rLocale )
,m_pResourceManager( NULL )
@@ -352,34 +217,29 @@ namespace res
ResourceTypePtr( new StringResourceAccess );
}
- //--------------------------------------------------------------------
OpenOfficeResourceBundle::~OpenOfficeResourceBundle()
{
delete m_pResourceManager;
}
- //--------------------------------------------------------------------
Reference< XResourceBundle > SAL_CALL OpenOfficeResourceBundle::getParent() throw (RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
return m_xParent;
}
- //--------------------------------------------------------------------
void SAL_CALL OpenOfficeResourceBundle::setParent( const Reference< XResourceBundle >& _parent ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
m_xParent = _parent;
}
- //--------------------------------------------------------------------
Locale SAL_CALL OpenOfficeResourceBundle::getLocale( ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
return m_aLocale;
}
- //--------------------------------------------------------------------
bool OpenOfficeResourceBundle::impl_getResourceTypeAndId_nothrow( const ::rtl::OUString& _key, ResourceTypePtr& _out_resourceType, sal_Int32& _out_resourceId ) const
{
sal_Int32 typeSeparatorPos = _key.indexOf( ':' );
@@ -399,7 +259,6 @@ namespace res
return true;
}
- //--------------------------------------------------------------------
bool OpenOfficeResourceBundle::impl_getDirectElement_nothrow( const ::rtl::OUString& _key, Any& _out_Element ) const
{
ResourceTypePtr resourceType;
@@ -415,7 +274,6 @@ namespace res
return _out_Element.hasValue();
}
- //--------------------------------------------------------------------
Any SAL_CALL OpenOfficeResourceBundle::getDirectElement( const ::rtl::OUString& _key ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -425,7 +283,6 @@ namespace res
return aElement;
}
- //--------------------------------------------------------------------
Any SAL_CALL OpenOfficeResourceBundle::getByName( const ::rtl::OUString& _key ) throw (NoSuchElementException, WrappedTargetException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -443,7 +300,6 @@ namespace res
return aElement;
}
- //--------------------------------------------------------------------
Sequence< ::rtl::OUString > SAL_CALL OpenOfficeResourceBundle::getElementNames( ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -452,7 +308,6 @@ namespace res
return Sequence< ::rtl::OUString >( );
}
- //--------------------------------------------------------------------
::sal_Bool SAL_CALL OpenOfficeResourceBundle::hasByName( const ::rtl::OUString& _key ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -468,13 +323,11 @@ namespace res
return sal_True;
}
- //--------------------------------------------------------------------
Type SAL_CALL OpenOfficeResourceBundle::getElementType( ) throw (RuntimeException)
{
return ::cppu::UnoType< Any >::get();
}
- //--------------------------------------------------------------------
::sal_Bool SAL_CALL OpenOfficeResourceBundle::hasElements( ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
@@ -483,10 +336,6 @@ namespace res
return ::sal_Bool( );
}
-//........................................................................
-} // namespace res
-//........................................................................
-
-#endif // EXTENSIONS_SOURCE_RESOURCE_OOORESOURCELOADER_CXX
+}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/resource/oooresourceloader.hxx b/extensions/source/resource/oooresourceloader.hxx
new file mode 100644
index 000000000000..fd7f526ce30b
--- /dev/null
+++ b/extensions/source/resource/oooresourceloader.hxx
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+
+#ifndef EXTENSIONS_RESOURCE_OOORESOURCELOADER_HXX
+#define EXTENSIONS_RESOURCE_OOORESOURCELOADER_HXX
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/resource/XResourceBundleLoader.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <cppuhelper/implbase1.hxx>
+
+#include <functional>
+#include <map>
+#include <utility>
+
+namespace extensions { namespace resource
+{
+ typedef ::std::pair< ::rtl::OUString, ::com::sun::star::lang::Locale> ResourceBundleDescriptor;
+
+ struct ResourceBundleDescriptorLess : public ::std::binary_function<ResourceBundleDescriptor, ResourceBundleDescriptor, bool>
+ {
+ bool operator()( const ResourceBundleDescriptor& _lhs, const ResourceBundleDescriptor& _rhs ) const
+ {
+ if ( _lhs.first < _rhs.first )
+ return true;
+ if ( _lhs.second.Language < _rhs.second.Language )
+ return true;
+ if ( _lhs.second.Country < _rhs.second.Country )
+ return true;
+ if ( _lhs.second.Variant < _rhs.second.Variant )
+ return true;
+ return false;
+ }
+ };
+
+ class OpenOfficeResourceLoader : public ::cppu::WeakImplHelper1< ::com::sun::star::resource::XResourceBundleLoader>
+ {
+ public:
+ typedef ::std::map<
+ ResourceBundleDescriptor,
+ ::com::sun::star::uno::WeakReference< ::com::sun::star::resource::XResourceBundle>,
+ ResourceBundleDescriptorLess> ResourceBundleCache;
+
+ OpenOfficeResourceLoader(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const&);
+ // XResourceBundleLoader
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::resource::XResourceBundle> SAL_CALL loadBundle_Default( const ::rtl::OUString& aBaseName ) throw (::com::sun::star::resource::MissingResourceException, ::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::resource::XResourceBundle> SAL_CALL loadBundle( const ::rtl::OUString& abaseName, const ::com::sun::star::lang::Locale& aLocale ) throw (::com::sun::star::resource::MissingResourceException, ::com::sun::star::uno::RuntimeException);
+
+ private:
+ OpenOfficeResourceLoader(); // never implemented
+ OpenOfficeResourceLoader( const OpenOfficeResourceLoader& ); // never implemented
+ OpenOfficeResourceLoader& operator=( const OpenOfficeResourceLoader& ); // never implemented
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> m_xContext;
+ ::osl::Mutex m_aMutex;
+ ResourceBundleCache m_aBundleCache;
+ };
+}}
+
+#endif // EXTENSIONS_RESOURCE_OOORESOURCELOADER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/resource/res.component b/extensions/source/resource/res.component
index 57f96609d5df..36227874216d 100644
--- a/extensions/source/resource/res.component
+++ b/extensions/source/resource/res.component
@@ -28,11 +28,11 @@
<component loader="com.sun.star.loader.SharedLibrary"
xmlns="http://openoffice.org/2010/uno-components">
- <implementation name="com.sun.star.comp.extensions.ResourceService">
- <service name="com.sun.star.resource.VclStringResourceLoader"/>
- </implementation>
<implementation name="com.sun.star.comp.resource.OpenOfficeResourceLoader">
<service name="com.sun.star.resource.OfficeResourceLoader"/>
<singleton name="com.sun.star.resource.OfficeResourceLoader"/>
</implementation>
+ <implementation name="org.libreoffice.extensions.resource.ResourceStringIndexAccess">
+ <service name="org.libreoffice.resource.ResourceStringIndexAccess"/>
+ </implementation>
</component>
diff --git a/extensions/source/resource/res_services.cxx b/extensions/source/resource/res_services.cxx
deleted file mode 100644
index 91315d0162f0..000000000000
--- a/extensions/source/resource/res_services.cxx
+++ /dev/null
@@ -1,89 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_extensions.hxx"
-#include "res_services.hxx"
-
-/** === begin UNO using === **/
-using ::com::sun::star::uno::Reference;
-using ::com::sun::star::uno::Sequence;
-using ::com::sun::star::uno::Exception;
-using ::com::sun::star::lang::XMultiServiceFactory;
-using ::com::sun::star::lang::XSingleServiceFactory;
-using ::com::sun::star::uno::UNO_QUERY;
-/** === end UNO using === **/
-
-#include <vector>
-
-namespace res
-{
- ::std::vector< ComponentInfo > getComponentInfos()
- {
- ::std::vector< ::res::ComponentInfo > aComponentInfos;
- aComponentInfos.push_back( getComponentInfo_VclStringResourceLoader() );
- aComponentInfos.push_back( getComponentInfo_OpenOfficeResourceLoader() );
- return aComponentInfos;
- }
-}
-
-extern "C" {
-
-SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
- const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
-{
- *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
-}
-
-SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
- const sal_Char * pImplName, XMultiServiceFactory * /*pServiceManager*/, void * /*pRegistryKey*/ )
-{
- void * pRet = 0;
- ::std::vector< ::res::ComponentInfo > aComponentInfos( ::res::getComponentInfos() );
- for ( ::std::vector< ::res::ComponentInfo >::const_iterator loop = aComponentInfos.begin();
- loop != aComponentInfos.end();
- ++loop
- )
- {
- if ( 0 == loop->sImplementationName.compareToAscii( pImplName ) )
- {
- // create the factory
- Reference< XSingleServiceFactory > xFactory( ::cppu::createSingleComponentFactory(
- loop->pFactory, loop->sImplementationName, loop->aSupportedServices ),
- UNO_QUERY );
- // acquire, because we return an interface pointer instead of a reference
- xFactory->acquire();
- pRet = xFactory.get();
- }
- }
- return pRet;
-}
-
-} // extern "C"
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/resource/res_services.hxx b/extensions/source/resource/res_services.hxx
deleted file mode 100644
index ac61f0e423ac..000000000000
--- a/extensions/source/resource/res_services.hxx
+++ /dev/null
@@ -1,67 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef EXTENSIONS_RESOURCE_SERVICES_HXX
-#define EXTENSIONS_RESOURCE_SERVICES_HXX
-
-/** === begin UNO includes === **/
-#include <com/sun/star/uno/Sequence.hxx>
-#include <com/sun/star/uno/Reference.hxx>
-#include <com/sun/star/uno/XInterface.hpp>
-/** === end UNO includes === **/
-#include <cppuhelper/factory.hxx>
-
-//........................................................................
-namespace res
-{
-//........................................................................
-
- struct ComponentInfo
- {
- /// services supported by the component
- ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupportedServices;
- /// implementation name of the component
- ::rtl::OUString sImplementationName;
- /** name of the singleton instance of the component, if it is a singleton, empty otherwise
- If the component is a singleton, aSupportedServices must contain exactly one element.
- */
- ::rtl::OUString sSingletonName;
- /// factory for creating the component
- ::cppu::ComponentFactoryFunc pFactory;
- };
-
- ComponentInfo getComponentInfo_VclStringResourceLoader();
- ComponentInfo getComponentInfo_OpenOfficeResourceLoader();
-
-//........................................................................
-} // namespace res
-//........................................................................
-
-#endif // EXTENSIONS_RESOURCE_SERVICES_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/resource/resource.cxx b/extensions/source/resource/resource.cxx
deleted file mode 100644
index 01943a68fceb..000000000000
--- a/extensions/source/resource/resource.cxx
+++ /dev/null
@@ -1,476 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_extensions.hxx"
-#include "res_services.hxx"
-
-#include <osl/mutex.hxx>
-#include <uno/lbnames.h> // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
-#include <cppuhelper/factory.hxx> // helper for factories
-#include <cppuhelper/implbase3.hxx> // helper for implementations
-
-#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <com/sun/star/script/XInvocation.hpp>
-#include <com/sun/star/script/XTypeConverter.hpp>
-#include <com/sun/star/reflection/InvocationTargetException.hpp>
-#include <com/sun/star/beans/XExactName.hpp>
-#include <com/sun/star/beans/PropertyValue.hpp>
-#include <com/sun/star/beans/PropertyState.hpp>
-
-#include <tools/resmgr.hxx>
-#include <tools/rcid.h>
-#include <tools/resary.hxx>
-#include <vcl/svapp.hxx>
-
-#include <rtl/ustring.hxx>
-#include <rtl/strbuf.hxx>
-
-using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
-using namespace com::sun::star::registry;
-using namespace com::sun::star::script;
-using namespace com::sun::star::beans;
-using namespace com::sun::star::reflection;
-
-using ::rtl::OUString;
-using ::rtl::OStringBuffer;
-using ::rtl::OUStringToOString;
-using ::rtl::OStringToOUString;
-
-//------------------------------------------------------------------------
-//------------------------------------------------------------------------
-//------------------------------------------------------------------------
-class ResourceService : public cppu::WeakImplHelper3< XInvocation, XExactName, XServiceInfo >
-{
-public:
- ResourceService( const Reference< XMultiServiceFactory > & );
- ~ResourceService();
-
- // XServiceInfo
- OUString SAL_CALL getImplementationName() throw();
- sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw();
- Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw();
-
- static Sequence< OUString > getSupportedServiceNames_Static(void) throw();
- static OUString getImplementationName_Static() throw()
- {
- return OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.extensions.ResourceService"));
- }
- static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext );
-
- // XExactName
- OUString SAL_CALL getExactName( const OUString & ApproximateName ) throw(RuntimeException);
-
- // XInvokation
- Reference< XIntrospectionAccess > SAL_CALL getIntrospection(void) throw(RuntimeException);
- Any SAL_CALL invoke(const OUString& FunctionName, const Sequence< Any >& Params, Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam) throw(IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException);
- void SAL_CALL setValue(const OUString& PropertyName, const Any& Value) throw(UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException);
- Any SAL_CALL getValue(const OUString& PropertyName) throw(UnknownPropertyException, RuntimeException);
- sal_Bool SAL_CALL hasMethod(const OUString& Name) throw(RuntimeException);
- sal_Bool SAL_CALL hasProperty(const OUString& Name) throw(RuntimeException);
-private:
- Reference< XTypeConverter > getTypeConverter() const;
- Reference< XInvocation > getDefaultInvocation() const;
-
- Reference< XMultiServiceFactory > xSMgr;
- Reference< XInvocation > xDefaultInvocation;
- Reference< XTypeConverter > xTypeConverter;
- OUString aFileName;
- ResMgr * pResMgr;
-};
-
-
-//-----------------------------------------------------------------------------
-ResourceService::ResourceService( const Reference< XMultiServiceFactory > & rSMgr )
- : xSMgr( rSMgr )
- , pResMgr( NULL )
-{
-}
-
-//-----------------------------------------------------------------------------
-Reference< XInterface > ResourceService::Create( const Reference< XComponentContext >& _rxContext )
-{
- Reference< XMultiServiceFactory > xFactory( _rxContext->getServiceManager(), UNO_QUERY_THROW );
- return *( new ResourceService( xFactory ) );
-}
-
-//-----------------------------------------------------------------------------
-ResourceService::~ResourceService()
-{
- delete pResMgr;
-}
-
-// XServiceInfo
-OUString ResourceService::getImplementationName() throw()
-{
- return getImplementationName_Static();
-}
-
-// XServiceInfo
-sal_Bool SAL_CALL ResourceService::supportsService(const OUString& ServiceName) throw()
-{
- Sequence< OUString > aSNL = getSupportedServiceNames();
- const OUString * pArray = aSNL.getConstArray();
- for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
- if( pArray[i] == ServiceName )
- return sal_True;
- return sal_False;
-}
-
-// XServiceInfo
-Sequence< OUString > SAL_CALL ResourceService::getSupportedServiceNames(void) throw()
-{
- return getSupportedServiceNames_Static();
-}
-
-// ResourceService
-Sequence< OUString > ResourceService::getSupportedServiceNames_Static(void) throw()
-{
- Sequence< OUString > aSNS( 1 );
- aSNS.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.resource.VclStringResourceLoader"));
- return aSNS;
-}
-
-// ResourceService
-Reference< XTypeConverter > ResourceService::getTypeConverter() const
-{
- SolarMutexGuard aGuard;
- if( xSMgr.is() )
- {
- Reference< XTypeConverter > xConv( xSMgr->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter" ))), UNO_QUERY );
- ((ResourceService*)this)->xTypeConverter = xConv;
- }
- return xTypeConverter;
-}
-
-// ResourceService
-Reference< XInvocation > ResourceService::getDefaultInvocation() const
-{
- SolarMutexGuard aGuard;
- /* f�hrt zur Zeit noch zu einer rekursion
- if( xSMgr.is() )
- {
- Reference< XSingleServiceFactory > xFact( xSMgr->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Invocation")) ), UNO_QUERY );
- if( xFact.is() )
- {
- Sequence< Any > aArgs( 1 );
- Reference< XInterface > xThis( *this );
- aArgs.getArray()[0].set( &xThis, XInterface_Reference< get >lection() );
- Reference< XInvokation > xI( xFact->createInstanceWithArguments( aArgs ), UNO_QUERY );
- ((ResourceService*)this)->xDefaultInvocation = xI;
- }
- }
- */
- return xDefaultInvocation;
-}
-
-// XExactName
-OUString SAL_CALL ResourceService::getExactName( const OUString & ApproximateName ) throw(RuntimeException)
-{
- OUString aName( ApproximateName );
- aName = aName.toAsciiLowerCase();
- if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("filename")) )
- return OUString(RTL_CONSTASCII_USTRINGPARAM("FileName"));
- else if( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("getstring" ) ))
- return OUString(RTL_CONSTASCII_USTRINGPARAM("getString"));
- else if( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("getstrings" ) ))
- return OUString(RTL_CONSTASCII_USTRINGPARAM("getStrings"));
- else if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("hasstring")) )
- return OUString(RTL_CONSTASCII_USTRINGPARAM("hasString"));
- else if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("hasstrings")) )
- return OUString(RTL_CONSTASCII_USTRINGPARAM("hasStrings"));
- else if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("getstringlist")) )
- return OUString(RTL_CONSTASCII_USTRINGPARAM("getStringList"));
- else if( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("hasStringList")) )
- return OUString(RTL_CONSTASCII_USTRINGPARAM("hasStringList"));
- Reference< XExactName > xEN( getDefaultInvocation(), UNO_QUERY );
- if( xEN.is() )
- return xEN->getExactName( ApproximateName );
- return OUString();
-}
-
-// XInvokation
-Reference< XIntrospectionAccess > SAL_CALL ResourceService::getIntrospection(void)
- throw(RuntimeException)
-{
- Reference< XInvocation > xI = getDefaultInvocation();
- if( xI.is() )
- return xI->getIntrospection();
- return Reference< XIntrospectionAccess >();
-}
-
-// XInvokation
-Any SAL_CALL ResourceService::invoke
-(
- const OUString& FunctionName,
- const Sequence< Any >& Params,
- Sequence< sal_Int16 >& OutParamIndex,
- Sequence< Any >& OutParam
-)
- throw(IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException)
-{
- Any aRet;
- if( FunctionName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("getString"))
- || FunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("getStrings" ) )
- || FunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("hasString" ) )
- || FunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("hasStrings" ) )
- )
- {
- sal_Int32 nElements = Params.getLength();
- if( nElements < 1 )
- throw IllegalArgumentException();
- if( nElements > 1 && (FunctionName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("getString")) || FunctionName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("hasString")) ) )
- throw IllegalArgumentException();
- if( !pResMgr )
- throw IllegalArgumentException();
-
- Sequence< OUString > aStrings( Params.getLength() );
- Sequence< sal_Bool > aBools( Params.getLength() );
- const Any* pIn = Params.getConstArray();
- OUString* pOutString = aStrings.getArray();
- sal_Bool* pOutBool = aBools.getArray();
-
- Reference< XTypeConverter > xC = getTypeConverter();
- bool bGetBranch = FunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getString" ) ) || FunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getStrings" ) );
-
- SolarMutexGuard aGuard;
- for( sal_Int32 n = 0; n < nElements; n++ )
- {
- sal_Int32 nId = 0;
- if( !(pIn[n] >>= nId) )
- {
- if( xC.is() )
- {
- xC->convertToSimpleType( pIn[n], TypeClass_LONG ) >>= nId;
- }
- else
- throw CannotConvertException();
- }
- if( nId > 0xFFFF || nId < 0 )
- throw IllegalArgumentException();
-
- if( bGetBranch )
- {
- ResId aId( (sal_uInt16)nId, *pResMgr );
- aId.SetRT( RSC_STRING );
- if( pResMgr->IsAvailable( aId ) )
- {
- String aStr( aId );
- pOutString[n] = aStr;
- }
- else
- throw IllegalArgumentException();
- }
- else // hasString(s)
- {
- sal_Bool bRet = sal_False;
- if( pResMgr )
- {
- ResId aId( (sal_uInt16)nId, *pResMgr );
- aId.SetRT( RSC_STRING );
- bRet = pResMgr->IsAvailable( aId );
- }
- pOutBool[n] = bRet;
- }
- }
- if( FunctionName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("getString")) )
- aRet <<= pOutString[0];
- else if( FunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("getStrings" ) ) )
- aRet <<= aStrings;
- else if( FunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("hasString" ) ) )
- aRet <<= pOutBool[0];
- else
- aRet <<= aBools;
- }
- else if( FunctionName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("getStringList")) || FunctionName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("hasStringList" ) ) )
- {
- if( Params.getLength() != 1 )
- throw IllegalArgumentException();
- Reference< XTypeConverter > xC = getTypeConverter();
- SolarMutexGuard aGuard;
-
- sal_Int32 nId = 0;
- if( !(Params.getConstArray()[0] >>= nId) )
- {
- if( xC.is() )
- {
- xC->convertToSimpleType( Params.getConstArray()[0], TypeClass_LONG ) >>= nId;
- }
- else
- throw CannotConvertException();
- }
-
- if( FunctionName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("getStringList")) )
- {
- ResId aId( (sal_uInt16)nId, *pResMgr );
- aId.SetRT( RSC_STRINGARRAY );
- if( pResMgr->IsAvailable( aId ) )
- {
- ResStringArray aStr( aId );
- int nEntries = aStr.Count();
- Sequence< PropertyValue > aPropSeq( nEntries );
- PropertyValue* pOut = aPropSeq.getArray();
- for( int i = 0; i < nEntries; i++ )
- {
- pOut[i].Name = aStr.GetString( i );
- pOut[i].Handle = -1;
- pOut[i].Value <<= aStr.GetValue( i );
- pOut[i].State = PropertyState_DIRECT_VALUE;
- }
- aRet <<= aPropSeq;
- }
- else
- throw IllegalArgumentException();
- }
- else // hasStringList
- {
- sal_Bool bRet = sal_False;
- if( pResMgr )
- {
- ResId aId( (sal_uInt16)nId, *pResMgr );
- aId.SetRT( RSC_STRINGARRAY );
- bRet = pResMgr->IsAvailable( aId );
- }
- aRet <<= bRet;
- }
- }
- else
- {
- Reference< XInvocation > xI = getDefaultInvocation();
- if( xI.is() )
- return xI->invoke( FunctionName, Params, OutParamIndex, OutParam );
- else
- throw IllegalArgumentException();
- }
- return aRet;
-}
-
-// XInvokation
-void SAL_CALL ResourceService::setValue(const OUString& PropertyName, const Any& Value)
- throw(UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException)
-{
- if( PropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("FileName")) )
- {
- OUString aName;
- if( !(Value >>= aName) )
- {
- Reference< XTypeConverter > xC = getTypeConverter();
- if( xC.is() )
- xC->convertToSimpleType( Value, TypeClass_STRING ) >>= aName;
- else
- throw CannotConvertException();
- }
-
- SolarMutexGuard aGuard;
- OStringBuffer aBuf( aName.getLength()+8 );
- aBuf.append( OUStringToOString( aName, osl_getThreadTextEncoding() ) );
- ResMgr * pRM = ResMgr::CreateResMgr( aBuf.getStr() );
- if( !pRM )
- throw InvocationTargetException();
- if( pResMgr )
- delete pResMgr;
- pResMgr = pRM;
- aFileName = OStringToOUString( aBuf.makeStringAndClear(), osl_getThreadTextEncoding() );
- }
- else
- {
- Reference< XInvocation > xI = getDefaultInvocation();
- if( xI.is() )
- xI->setValue( PropertyName, Value );
- else
- throw UnknownPropertyException();
- }
-}
-
-// XInvokation
-Any SAL_CALL ResourceService::getValue(const OUString& PropertyName)
- throw(UnknownPropertyException, RuntimeException)
-{
- SolarMutexGuard aGuard;
- if( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("FileName" ) ))
- return makeAny( aFileName );
-
- Reference< XInvocation > xI = getDefaultInvocation();
- if( xI.is() )
- return xI->getValue( PropertyName );
-
- throw UnknownPropertyException();
-}
-
-// XInvokation
-sal_Bool SAL_CALL ResourceService::hasMethod(const OUString& Name)
- throw(RuntimeException)
-{
- if( Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("getString")) ||
- Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("getStrings")) ||
- Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("hasString")) ||
- Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("hasStrings")) ||
- Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("getStringList")) ||
- Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("hasStringList"))
- )
- return sal_True;
- else
- {
- Reference< XInvocation > xI = getDefaultInvocation();
- if( xI.is() )
- return xI->hasMethod( Name );
- else
- return sal_False;
- }
-}
-
-// XInvokation
-sal_Bool SAL_CALL ResourceService::hasProperty(const OUString& Name)
- throw(RuntimeException)
-{
- if( Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("FileName")) )
- return sal_True;
- else
- {
- Reference< XInvocation > xI = getDefaultInvocation();
- if( xI.is() )
- return xI->hasProperty( Name );
- else
- return sal_False;
- }
-}
-
-namespace res
-{
- ComponentInfo getComponentInfo_VclStringResourceLoader()
- {
- ComponentInfo aInfo;
- aInfo.aSupportedServices = ResourceService::getSupportedServiceNames_Static();
- aInfo.sImplementationName = ResourceService::getImplementationName_Static();
- aInfo.pFactory = &ResourceService::Create;
- return aInfo;
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/resource/resourceservices.cxx b/extensions/source/resource/resourceservices.cxx
new file mode 100644
index 000000000000..1ed27148ab9d
--- /dev/null
+++ b/extensions/source/resource/resourceservices.cxx
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * Bjoern Michaelsen <bjoern.michaelsen@canonical.com>
+ * Portions created by the Initial Developer are Copyright (C) 2010 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Major Contributor(s):
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "precompiled_extensions.hxx"
+
+#include <ResourceStringIndexAccess.hxx>
+#include <oooresourceloader.hxx>
+#include <comphelper/servicedecl.hxx>
+#include <uno/environment.h>
+
+namespace sdecl = ::comphelper::service_decl;
+
+sdecl::class_< ::extensions::resource::ResourceStringIndexAccess, sdecl::with_args<true> > ResourceStringIndexAccessServiceImpl;
+sdecl::class_< ::extensions::resource::OpenOfficeResourceLoader> OpenOfficeResourceLoaderServiceImpl;
+
+const sdecl::ServiceDecl ResourceStringIndexAccessDecl(
+ ResourceStringIndexAccessServiceImpl,
+ "org.libreoffice.extensions.resource.ResourceStringIndexAccess",
+ "org.libreoffice.resource.ResourceStringIndexAccess");
+
+const sdecl::ServiceDecl OpenOfficeResourceLoaderDecl(
+ OpenOfficeResourceLoaderServiceImpl,
+ "com.sun.star.comp.resource.OpenOfficeResourceLoader",
+ "com.sun.star.resource.OfficeResourceLoader");
+
+COMPHELPER_SERVICEDECL_EXPORTS2(
+ ResourceStringIndexAccessDecl,
+ OpenOfficeResourceLoaderDecl
+);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */