Kaydet (Commit) 21cdeb7b authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen

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
üst 639f9c68
/* -*- 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: */
/* -*- 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: */
......@@ -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) \
......
......@@ -26,64 +26,62 @@
*
************************************************************************/
// 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 === **/
#ifndef EXTENSIONS_RESOURCE_OOORESOURCELOADER_HXX
#define EXTENSIONS_RESOURCE_OOORESOURCELOADER_HXX
#include <vector>
#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>
namespace res
{
::std::vector< ComponentInfo > getComponentInfos()
{
::std::vector< ::res::ComponentInfo > aComponentInfos;
aComponentInfos.push_back( getComponentInfo_VclStringResourceLoader() );
aComponentInfos.push_back( getComponentInfo_OpenOfficeResourceLoader() );
return aComponentInfos;
}
}
#include <functional>
#include <map>
#include <utility>
extern "C" {
SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
namespace extensions { namespace resource
{
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}
typedef ::std::pair< ::rtl::OUString, ::com::sun::star::lang::Locale> ResourceBundleDescriptor;
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
)
struct ResourceBundleDescriptorLess : public ::std::binary_function<ResourceBundleDescriptor, ResourceBundleDescriptor, bool>
{
if ( 0 == loop->sImplementationName.compareToAscii( pImplName ) )
bool operator()( const ResourceBundleDescriptor& _lhs, const ResourceBundleDescriptor& _rhs ) const
{
// 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();
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;
}
}
return pRet;
}
};
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;
};
}}
} // extern "C"
#endif // EXTENSIONS_RESOURCE_OOORESOURCELOADER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -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>
/* -*- 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: */
This diff is collapsed.
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment