[Libreoffice-commits] .: Branch 'feature/gsoc2011_wizards' - 2 commits - extensions/source wizards/com

Bjoern Michaelsen bmichaelsen at kemper.freedesktop.org
Fri May 27 13:13:33 PDT 2011


 extensions/source/resource/ResourceIndexAccess.cxx       |  208 +++++++++++++++
 extensions/source/resource/ResourceIndexAccess.hxx       |   75 +++++
 extensions/source/resource/ResourceStringIndexAccess.cxx |   94 ------
 extensions/source/resource/ResourceStringIndexAccess.hxx |   71 -----
 extensions/source/resource/makefile.mk                   |    2 
 extensions/source/resource/res.component                 |    4 
 extensions/source/resource/resourceservices.cxx          |   14 -
 wizards/com/sun/star/wizards/common/Resource.java        |   87 +++---
 8 files changed, 335 insertions(+), 220 deletions(-)

New commits:
commit 54355514409030e64b37226459a8c6109d70227a
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri May 27 21:57:23 2011 +0200

    fdo#37290: migrate Java to new resource service

diff --git a/wizards/com/sun/star/wizards/common/Resource.java b/wizards/com/sun/star/wizards/common/Resource.java
index 39607a2..7d9365b 100644
--- a/wizards/com/sun/star/wizards/common/Resource.java
+++ b/wizards/com/sun/star/wizards/common/Resource.java
@@ -27,47 +27,75 @@
 
 package com.sun.star.wizards.common;
 
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XNameAccess;
 import com.sun.star.lang.IllegalArgumentException;
 import com.sun.star.lang.XMultiServiceFactory;
 import com.sun.star.script.XInvocation;
 import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.UnoRuntime;
 
 public class Resource
 {
 
-    XInvocation xInvocation;
     XMultiServiceFactory xMSF;
-    String Unit;
     String Module;
+    XIndexAccess xStringIndexAccess;
+    XIndexAccess xStringListIndexAccess;
 
     /** Creates a new instance of Resource
      * @param _xMSF
      * @param _Unit
      * @param _Module
      */
-    public Resource(XMultiServiceFactory _xMSF, String _Unit, String _Module)
+    public Resource(XMultiServiceFactory _xMSF, String _Unit /* unused */, String _Module)
     {
         this.xMSF = _xMSF;
-        this.Unit = _Unit;
         this.Module = _Module;
-        this.xInvocation = initResources();
+        try
+        {
+            Object[] aArgs = new Object[1];
+            aArgs[0] = this.Module;
+            XInterface xResource = (XInterface) xMSF.createInstanceWithArguments(
+                "org.libreoffice.resource.ResourceIndexAccess",
+                aArgs);
+            if (xResource == null)
+                throw new Exception("could not initialize ResourceIndexAccess");
+            XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(
+                XNameAccess.class,
+                xResource);
+            if (xNameAccess == null)
+                throw new Exception("ResourceIndexAccess is no XNameAccess");
+            this.xStringIndexAccess = (XIndexAccess)UnoRuntime.queryInterface(
+                XIndexAccess.class,
+                xNameAccess.getByName("String"));
+            this.xStringListIndexAccess = (XIndexAccess)UnoRuntime.queryInterface(
+                XIndexAccess.class,
+                xNameAccess.getByName("StringList"));
+            if(this.xStringListIndexAccess == null)
+                throw new Exception("could not initialize xStringListIndexAccess");
+            if(this.xStringIndexAccess == null)
+                throw new Exception("could not initialize xStringIndexAccess");
+        }
+        catch (Exception exception)
+        {
+            exception.printStackTrace();
+            showCommonResourceError(xMSF);
+        }
     }
 
     public String getResText(int nID)
     {
         try
         {
-            short[][] PointerArray = new short[1][];
-            Object[][] DummyArray = new Object[1][];
-            Object[] nIDArray = new Object[1];
-            nIDArray[0] = new Integer(nID);
-            final String IDString = (String) xInvocation.invoke("getString", nIDArray, PointerArray, DummyArray);
-            return IDString;
+            return (String)this.xStringIndexAccess.getByIndex(nID);
         }
         catch (Exception exception)
         {
             exception.printStackTrace();
-            throw new java.lang.IllegalArgumentException("Resource with ID not" + String.valueOf(nID) + "not found");
+            throw new java.lang.IllegalArgumentException("Resource with ID not " + String.valueOf(nID) + "not found");
         }
     }
 
@@ -75,18 +103,12 @@ public class Resource
     {
         try
         {
-            short[][] PointerArray = new short[1][];
-            Object[][] DummyArray = new Object[1][];
-            Object[] nIDArray = new Object[1];
-            nIDArray[0] = new Integer(nID);
-            //Object bla = xInvocation.invoke("getStringList", nIDArray, PointerArray, DummyArray);
-            PropertyValue[] ResProp = (PropertyValue[]) xInvocation.invoke("getStringList", nIDArray, PointerArray, DummyArray);
-            return ResProp;
+            return (PropertyValue[])this.xStringListIndexAccess.getByIndex(nID);
         }
         catch (Exception exception)
         {
             exception.printStackTrace();
-            throw new java.lang.IllegalArgumentException("Resource with ID not" + String.valueOf(nID) + "not found");
+            throw new java.lang.IllegalArgumentException("Resource with ID not " + String.valueOf(nID) + "not found");
         }
     }
 
@@ -108,31 +130,6 @@ public class Resource
         }
     }
 
-    public XInvocation initResources()
-    {
-        try
-        {
-            com.sun.star.uno.XInterface xResource = (com.sun.star.uno.XInterface) xMSF.createInstance("com.sun.star.resource.VclStringResourceLoader");
-            if (xResource == null)
-            {
-                showCommonResourceError(xMSF);
-                throw new IllegalArgumentException();
-            }
-            else
-            {
-                XInvocation xResInvoke = (XInvocation) com.sun.star.uno.UnoRuntime.queryInterface(XInvocation.class, xResource);
-                xResInvoke.setValue("FileName", Module);
-                return xResInvoke;
-            }
-        }
-        catch (Exception exception)
-        {
-            exception.printStackTrace(System.out);
-            showCommonResourceError(xMSF);
-            return null;
-        }
-    }
-
     public static void showCommonResourceError(XMultiServiceFactory xMSF)
     {
         String ProductName = Configuration.getProductName(xMSF);
commit 52434fa95d0aeefa9a6b561f6b6bcc2857d38e56
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri May 27 19:54:53 2011 +0200

    fdo#37290: allow also access to StringList resources

diff --git a/extensions/source/resource/ResourceIndexAccess.cxx b/extensions/source/resource/ResourceIndexAccess.cxx
new file mode 100644
index 0000000..31a244b
--- /dev/null
+++ b/extensions/source/resource/ResourceIndexAccess.cxx
@@ -0,0 +1,208 @@
+/* -*- 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 at 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 <ResourceIndexAccess.hxx>
+
+#include <com/sun/star/container/XIndexAccess.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <comphelper/stlunosequence.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 namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::container;
+
+using ::comphelper::stl_begin;
+using ::comphelper::stl_end;
+using ::rtl::OString;
+using ::rtl::OUString;
+using ::rtl::OUStringToOString;
+
+namespace
+{
+    static ::boost::shared_ptr<ResMgr> GetResMgr(Sequence<Any> const& rArgs)
+    {
+        if(rArgs.getLength()!=1)
+            return ::boost::shared_ptr<ResMgr>();
+        OUString sFilename;
+        rArgs[0] >>= sFilename;
+        SolarMutexGuard aGuard;
+        const OString sEncName(OUStringToOString(sFilename, osl_getThreadTextEncoding()));
+        return ::boost::shared_ptr<ResMgr>(ResMgr::CreateResMgr(sEncName));
+    }
+
+    class ResourceIndexAccessBase : public cppu::WeakImplHelper1< ::com::sun::star::container::XIndexAccess>
+    {
+        public:
+            ResourceIndexAccessBase( ::boost::shared_ptr<ResMgr> pResMgr)
+                : m_pResMgr(pResMgr)
+            {
+                OSL_ENSURE(m_pResMgr, "no ressource manager given");
+            }
+
+            // XIndexAccess
+            virtual ::sal_Int32 SAL_CALL getCount(  ) throw (::com::sun::star::uno::RuntimeException)
+                { return m_pResMgr.get() ? SAL_MAX_UINT16 : 0; };
+            // XElementAccess
+            virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException)
+                { return static_cast<bool>(m_pResMgr.get()); };
+
+        protected:
+            // m_pResMgr should never be NULL
+            const ::boost::shared_ptr<ResMgr> m_pResMgr;
+    };
+
+    class ResourceStringIndexAccess : public ResourceIndexAccessBase
+    {
+        public:
+            ResourceStringIndexAccess( ::boost::shared_ptr<ResMgr> pResMgr)
+                : ResourceIndexAccessBase(pResMgr) {}
+            // XIndexAccess
+            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);
+            // XElementAccessBase
+            virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException)
+                { return ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)); };
+    };
+
+    class ResourceStringListIndexAccess : public ResourceIndexAccessBase
+    {
+        public:
+            ResourceStringListIndexAccess( ::boost::shared_ptr<ResMgr> pResMgr)
+                : ResourceIndexAccessBase(pResMgr) {}
+            // XIndexAccess
+            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);
+            // XElementAccessBase
+            virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException)
+                { return ::getCppuType(reinterpret_cast<Sequence<PropertyValue> * >(NULL)); };
+    };
+}
+
+ResourceIndexAccess::ResourceIndexAccess(Sequence<Any> const& rArgs, Reference<XComponentContext> const&)
+    : m_pResMgr(GetResMgr(rArgs))
+{};
+
+Reference<XInterface> initResourceIndexAccess(ResourceIndexAccess* pResourceIndexAccess)
+{
+    Reference<XInterface> xResult(static_cast<cppu::OWeakObject*>(pResourceIndexAccess));
+    if(!pResourceIndexAccess->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 ResourceIndexAccess::getByName(const OUString& aName)
+    throw (NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    const Sequence<OUString> aNames(getElementNames());
+    Reference<XIndexAccess> xResult;
+    switch(::std::find(stl_begin(aNames), stl_end(aNames), aName)-stl_begin(aNames))
+    {
+        case 0:
+            xResult = Reference<XIndexAccess>(new ResourceStringIndexAccess(m_pResMgr));
+            break;
+        case 1:
+            xResult = Reference<XIndexAccess>(new ResourceStringListIndexAccess(m_pResMgr));
+            break;
+        default:
+            throw NoSuchElementException();
+    }
+    return makeAny(xResult);
+}
+
+Sequence<OUString> SAL_CALL ResourceIndexAccess::getElementNames(  )
+    throw (RuntimeException)
+{
+    static Sequence<OUString> aResult;
+    if( aResult.getLength() == 0)
+    {
+        aResult.realloc(2);
+        aResult[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("String"));
+        aResult[1] = OUString(RTL_CONSTASCII_USTRINGPARAM("StringList"));
+    }
+    return aResult;
+}
+
+::sal_Bool SAL_CALL ResourceIndexAccess::hasByName(const OUString& aName)
+    throw (RuntimeException)
+{
+    const Sequence<OUString> aNames(getElementNames());
+    return (::std::find(stl_begin(aNames), stl_end(aNames), aName) != stl_end(aNames));
+}
+
+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)));
+}
+
+Any SAL_CALL ResourceStringListIndexAccess::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_STRINGARRAY);
+    if(!m_pResMgr->IsAvailable(aId))
+        throw RuntimeException(
+            OUString(RTL_CONSTASCII_USTRINGPARAM("string list ressource for id not available")),
+            Reference<XInterface>());
+    const ResStringArray aStringList(aId);
+    Sequence<PropertyValue> aPropList(aStringList.Count());
+    for(sal_Int32 nCount = 0; nCount != aPropList.getLength(); ++nCount)
+    {
+        aPropList[nCount].Name = aStringList.GetString(nCount);
+        aPropList[nCount].Handle = -1;
+        aPropList[nCount].Value <<= aStringList.GetValue(nCount);
+        aPropList[nCount].State = PropertyState_DIRECT_VALUE;
+    }
+    return makeAny(aPropList);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/resource/ResourceIndexAccess.hxx b/extensions/source/resource/ResourceIndexAccess.hxx
new file mode 100644
index 0000000..4163259
--- /dev/null
+++ b/extensions/source/resource/ResourceIndexAccess.hxx
@@ -0,0 +1,75 @@
+/* -*- 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 at 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 <boost/shared_ptr.hpp>
+#include <com/sun/star/container/XNameAccess.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>
+
+class ResMgr;
+
+namespace extensions { namespace resource
+{
+    /** This class provides access to tools library text resources */
+    class ResourceIndexAccess : public cppu::WeakImplHelper1< ::com::sun::star::container::XNameAccess>
+    {
+        public:
+            /** The ctor takes a sequence with one element: the name of the resource, e.g. svt */
+            ResourceIndexAccess(::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> const& rArgs, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const&);
+            // XNameAccess
+            // The XNameAccess provides access to two named elements:
+            //    "String" returns a XIndexAccess to String resources
+            //    "StringList" returns a XIndexAccess to StringList/StringArray resources
+            virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
+            virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw (::com::sun::star::uno::RuntimeException);
+            virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::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< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>*>(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
+            const ::boost::shared_ptr<ResMgr> m_pResMgr;
+    };
+}}
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> initResourceIndexAccess(::extensions::resource::ResourceIndexAccess*);
+
+#endif
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/extensions/source/resource/ResourceStringIndexAccess.cxx b/extensions/source/resource/ResourceStringIndexAccess.cxx
deleted file mode 100644
index d48d636..0000000
--- a/extensions/source/resource/ResourceStringIndexAccess.cxx
+++ /dev/null
@@ -1,94 +0,0 @@
-/* -*- 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 at 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
deleted file mode 100644
index e1a01e3..0000000
--- a/extensions/source/resource/ResourceStringIndexAccess.hxx
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- 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 at 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 d9143d2..4839ec0 100644
--- a/extensions/source/resource/makefile.mk
+++ b/extensions/source/resource/makefile.mk
@@ -40,7 +40,7 @@ ENABLE_EXCEPTIONS=TRUE
 # --- Files --------------------------------------------------------
 
 SLOFILES= \
-    $(SLO)$/ResourceStringIndexAccess.obj \
+    $(SLO)$/ResourceIndexAccess.obj \
     $(SLO)$/oooresourceloader.obj \
     $(SLO)$/resourceservices.obj
 
diff --git a/extensions/source/resource/res.component b/extensions/source/resource/res.component
index 3622787..b5df974 100644
--- a/extensions/source/resource/res.component
+++ b/extensions/source/resource/res.component
@@ -32,7 +32,7 @@
     <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 name="org.libreoffice.extensions.resource.ResourceIndexAccess">
+    <service name="org.libreoffice.resource.ResourceIndexAccess"/>
   </implementation>
 </component>
diff --git a/extensions/source/resource/resourceservices.cxx b/extensions/source/resource/resourceservices.cxx
index 1ed2714..0a08bb5 100644
--- a/extensions/source/resource/resourceservices.cxx
+++ b/extensions/source/resource/resourceservices.cxx
@@ -30,20 +30,20 @@
 
 #include "precompiled_extensions.hxx"
 
-#include <ResourceStringIndexAccess.hxx>
+#include <ResourceIndexAccess.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::ResourceIndexAccess, sdecl::with_args<true> > ResourceIndexAccessServiceImpl;
 sdecl::class_< ::extensions::resource::OpenOfficeResourceLoader> OpenOfficeResourceLoaderServiceImpl;
 
-const sdecl::ServiceDecl ResourceStringIndexAccessDecl(
-    ResourceStringIndexAccessServiceImpl,
-    "org.libreoffice.extensions.resource.ResourceStringIndexAccess",
-    "org.libreoffice.resource.ResourceStringIndexAccess");
+const sdecl::ServiceDecl ResourceIndexAccessDecl(
+    ResourceIndexAccessServiceImpl,
+    "org.libreoffice.extensions.resource.ResourceIndexAccess",
+    "org.libreoffice.resource.ResourceIndexAccess");
 
 const sdecl::ServiceDecl OpenOfficeResourceLoaderDecl(
     OpenOfficeResourceLoaderServiceImpl,
@@ -51,7 +51,7 @@ const sdecl::ServiceDecl OpenOfficeResourceLoaderDecl(
     "com.sun.star.resource.OfficeResourceLoader");
 
 COMPHELPER_SERVICEDECL_EXPORTS2(
-    ResourceStringIndexAccessDecl,
+    ResourceIndexAccessDecl,
     OpenOfficeResourceLoaderDecl
 );
 


More information about the Libreoffice-commits mailing list