1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_extensions.hxx"
30*cdf0e10cSrcweir #include "res_services.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <vos/mutex.hxx>
33*cdf0e10cSrcweir #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
34*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>	// helper for factories
35*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>	// helper for implementations
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/script/XInvocation.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/script/XTypeConverter.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/reflection/InvocationTargetException.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/beans/XExactName.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <tools/resmgr.hxx>
46*cdf0e10cSrcweir #include <tools/rcid.h>
47*cdf0e10cSrcweir #include <tools/resary.hxx>
48*cdf0e10cSrcweir #include <vcl/svapp.hxx>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <rtl/ustring.hxx>
51*cdf0e10cSrcweir #include <rtl/strbuf.hxx>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir using namespace vos;
54*cdf0e10cSrcweir using namespace rtl;
55*cdf0e10cSrcweir using namespace com::sun::star::uno;
56*cdf0e10cSrcweir using namespace com::sun::star::lang;
57*cdf0e10cSrcweir using namespace com::sun::star::registry;
58*cdf0e10cSrcweir using namespace com::sun::star::script;
59*cdf0e10cSrcweir using namespace com::sun::star::beans;
60*cdf0e10cSrcweir using namespace com::sun::star::reflection;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir //------------------------------------------------------------------------
63*cdf0e10cSrcweir //------------------------------------------------------------------------
64*cdf0e10cSrcweir //------------------------------------------------------------------------
65*cdf0e10cSrcweir class ResourceService : public cppu::WeakImplHelper3< XInvocation, XExactName, XServiceInfo >
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir public:
68*cdf0e10cSrcweir 								ResourceService( const Reference< XMultiServiceFactory > & );
69*cdf0e10cSrcweir 								~ResourceService();
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	// XServiceInfo
72*cdf0e10cSrcweir 	OUString SAL_CALL			getImplementationName() throw();
73*cdf0e10cSrcweir     sal_Bool 	 SAL_CALL			supportsService(const OUString& ServiceName) throw();
74*cdf0e10cSrcweir     Sequence< OUString > SAL_CALL	getSupportedServiceNames(void) throw();
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     static Sequence< OUString > getSupportedServiceNames_Static(void) throw();
77*cdf0e10cSrcweir 	static OUString 			getImplementationName_Static() throw()
78*cdf0e10cSrcweir 								{
79*cdf0e10cSrcweir 									return OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.extensions.ResourceService"));
80*cdf0e10cSrcweir 								}
81*cdf0e10cSrcweir     static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext );
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	// XExactName
84*cdf0e10cSrcweir 	OUString  SAL_CALL			getExactName( const OUString & ApproximateName ) throw(RuntimeException);
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	// XInvokation
87*cdf0e10cSrcweir     Reference< XIntrospectionAccess >  SAL_CALL getIntrospection(void)  throw(RuntimeException);
88*cdf0e10cSrcweir     Any  SAL_CALL				invoke(const OUString& FunctionName, const Sequence< Any >& Params, Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam) throw(IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException);
89*cdf0e10cSrcweir     void  SAL_CALL				setValue(const OUString& PropertyName, const Any& Value) throw(UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException);
90*cdf0e10cSrcweir     Any  SAL_CALL				getValue(const OUString& PropertyName) throw(UnknownPropertyException, RuntimeException);
91*cdf0e10cSrcweir     sal_Bool  SAL_CALL				hasMethod(const OUString& Name)  throw(RuntimeException);
92*cdf0e10cSrcweir     sal_Bool  SAL_CALL				hasProperty(const OUString& Name)  throw(RuntimeException);
93*cdf0e10cSrcweir private:
94*cdf0e10cSrcweir 	Reference< XTypeConverter >			getTypeConverter() const;
95*cdf0e10cSrcweir 	Reference< XInvocation >			getDefaultInvocation() const;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	Reference< XMultiServiceFactory >	xSMgr;
98*cdf0e10cSrcweir 	Reference< XInvocation >			xDefaultInvocation;
99*cdf0e10cSrcweir 	Reference< XTypeConverter >			xTypeConverter;
100*cdf0e10cSrcweir 	OUString								aFileName;
101*cdf0e10cSrcweir 	ResMgr *							pResMgr;
102*cdf0e10cSrcweir };
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir //-----------------------------------------------------------------------------
106*cdf0e10cSrcweir ResourceService::ResourceService( const Reference< XMultiServiceFactory > & rSMgr )
107*cdf0e10cSrcweir 	: xSMgr( rSMgr )
108*cdf0e10cSrcweir 	, pResMgr( NULL )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir //-----------------------------------------------------------------------------
113*cdf0e10cSrcweir Reference< XInterface > ResourceService::Create( const Reference< XComponentContext >& _rxContext )
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     Reference< XMultiServiceFactory > xFactory( _rxContext->getServiceManager(), UNO_QUERY_THROW );
116*cdf0e10cSrcweir     return *( new ResourceService( xFactory ) );
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir //-----------------------------------------------------------------------------
120*cdf0e10cSrcweir ResourceService::~ResourceService()
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	delete pResMgr;
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir // XServiceInfo
126*cdf0e10cSrcweir OUString ResourceService::getImplementationName() throw()
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir 	return getImplementationName_Static();
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir // XServiceInfo
132*cdf0e10cSrcweir sal_Bool SAL_CALL ResourceService::supportsService(const OUString& ServiceName) throw()
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir 	Sequence< OUString > aSNL = getSupportedServiceNames();
135*cdf0e10cSrcweir 	const OUString * pArray = aSNL.getConstArray();
136*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
137*cdf0e10cSrcweir 		if( pArray[i] == ServiceName )
138*cdf0e10cSrcweir 			return sal_True;
139*cdf0e10cSrcweir 	return sal_False;
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir // XServiceInfo
143*cdf0e10cSrcweir Sequence< OUString > SAL_CALL ResourceService::getSupportedServiceNames(void) throw()
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
146*cdf0e10cSrcweir }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir // ResourceService
149*cdf0e10cSrcweir Sequence< OUString > ResourceService::getSupportedServiceNames_Static(void) throw()
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir 	Sequence< OUString > aSNS( 1 );
152*cdf0e10cSrcweir 	aSNS.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.resource.VclStringResourceLoader"));
153*cdf0e10cSrcweir 	return aSNS;
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir // ResourceService
157*cdf0e10cSrcweir Reference< XTypeConverter > ResourceService::getTypeConverter() const
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
160*cdf0e10cSrcweir 	if( xSMgr.is() )
161*cdf0e10cSrcweir 	{
162*cdf0e10cSrcweir 		Reference< XTypeConverter > xConv( xSMgr->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter" ))), UNO_QUERY );
163*cdf0e10cSrcweir 		((ResourceService*)this)->xTypeConverter = xConv;
164*cdf0e10cSrcweir 	}
165*cdf0e10cSrcweir 	return xTypeConverter;
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir // ResourceService
169*cdf0e10cSrcweir Reference< XInvocation > ResourceService::getDefaultInvocation() const
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
172*cdf0e10cSrcweir 	/* f�hrt zur Zeit noch zu einer rekursion
173*cdf0e10cSrcweir 	if( xSMgr.is() )
174*cdf0e10cSrcweir 	{
175*cdf0e10cSrcweir 		Reference< XSingleServiceFactory > xFact( xSMgr->createInstance( OUString::createFromAscii("com.sun.star.script.Invocation") ), UNO_QUERY );
176*cdf0e10cSrcweir 		if( xFact.is() )
177*cdf0e10cSrcweir 		{
178*cdf0e10cSrcweir 			Sequence< Any > aArgs( 1 );
179*cdf0e10cSrcweir 			Reference< XInterface > xThis( *this );
180*cdf0e10cSrcweir 			aArgs.getArray()[0].set( &xThis, XInterface_Reference< get >lection() );
181*cdf0e10cSrcweir 			Reference< XInvokation > xI( xFact->createInstanceWithArguments( aArgs ), UNO_QUERY );
182*cdf0e10cSrcweir 			((ResourceService*)this)->xDefaultInvocation = xI;
183*cdf0e10cSrcweir 		}
184*cdf0e10cSrcweir 	}
185*cdf0e10cSrcweir 	*/
186*cdf0e10cSrcweir 	return xDefaultInvocation;
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir // XExactName
190*cdf0e10cSrcweir OUString	SAL_CALL ResourceService::getExactName( const OUString & ApproximateName ) throw(RuntimeException)
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir 	OUString aName( ApproximateName );
193*cdf0e10cSrcweir 	aName = aName.toAsciiLowerCase();
194*cdf0e10cSrcweir 	if( aName.equalsAscii("filename") )
195*cdf0e10cSrcweir 		return OUString(RTL_CONSTASCII_USTRINGPARAM("FileName"));
196*cdf0e10cSrcweir 	else if( aName.equalsAscii("getstring" ))
197*cdf0e10cSrcweir 		return OUString(RTL_CONSTASCII_USTRINGPARAM("getString"));
198*cdf0e10cSrcweir 	else if( aName.equalsAscii("getstrings" ))
199*cdf0e10cSrcweir 		return OUString(RTL_CONSTASCII_USTRINGPARAM("getStrings"));
200*cdf0e10cSrcweir 	else if( aName.equalsAscii("hasstring") )
201*cdf0e10cSrcweir 		return OUString(RTL_CONSTASCII_USTRINGPARAM("hasString"));
202*cdf0e10cSrcweir 	else if( aName.equalsAscii("hasstrings") )
203*cdf0e10cSrcweir 		return OUString(RTL_CONSTASCII_USTRINGPARAM("hasStrings"));
204*cdf0e10cSrcweir 	else if( aName.equalsAscii("getstringlist") )
205*cdf0e10cSrcweir 		return OUString(RTL_CONSTASCII_USTRINGPARAM("getStringList"));
206*cdf0e10cSrcweir 	else if( aName.equalsAscii("hasStringList") )
207*cdf0e10cSrcweir 		return OUString(RTL_CONSTASCII_USTRINGPARAM("hasStringList"));
208*cdf0e10cSrcweir 	Reference< XExactName > xEN( getDefaultInvocation(), UNO_QUERY );
209*cdf0e10cSrcweir 	if( xEN.is() )
210*cdf0e10cSrcweir 		return xEN->getExactName( ApproximateName );
211*cdf0e10cSrcweir 	return OUString();
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir // XInvokation
215*cdf0e10cSrcweir Reference< XIntrospectionAccess > SAL_CALL ResourceService::getIntrospection(void)
216*cdf0e10cSrcweir 	throw(RuntimeException)
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir 	Reference< XInvocation > xI = getDefaultInvocation();
219*cdf0e10cSrcweir 	if( xI.is() )
220*cdf0e10cSrcweir 		return xI->getIntrospection();
221*cdf0e10cSrcweir 	return Reference< XIntrospectionAccess >();
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir // XInvokation
225*cdf0e10cSrcweir Any SAL_CALL ResourceService::invoke
226*cdf0e10cSrcweir (
227*cdf0e10cSrcweir 	const OUString& FunctionName,
228*cdf0e10cSrcweir 	const Sequence< Any >& Params,
229*cdf0e10cSrcweir 	Sequence< sal_Int16 >& OutParamIndex,
230*cdf0e10cSrcweir 	Sequence< Any >& OutParam
231*cdf0e10cSrcweir )
232*cdf0e10cSrcweir 	throw(IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException)
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     Any aRet;
235*cdf0e10cSrcweir 	if( FunctionName.equalsAscii("getString")
236*cdf0e10cSrcweir         || FunctionName.equalsAscii("getStrings" )
237*cdf0e10cSrcweir         || FunctionName.equalsAscii("hasString" )
238*cdf0e10cSrcweir         || FunctionName.equalsAscii("hasStrings" )
239*cdf0e10cSrcweir         )
240*cdf0e10cSrcweir 	{
241*cdf0e10cSrcweir         sal_Int32 nElements = Params.getLength();
242*cdf0e10cSrcweir         if( nElements < 1 )
243*cdf0e10cSrcweir             throw IllegalArgumentException();
244*cdf0e10cSrcweir         if( nElements > 1 && (FunctionName.equalsAscii("getString") || FunctionName.equalsAscii("hasString") ) )
245*cdf0e10cSrcweir             throw IllegalArgumentException();
246*cdf0e10cSrcweir         if( !pResMgr )
247*cdf0e10cSrcweir             throw IllegalArgumentException();
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir         Sequence< OUString > aStrings( Params.getLength() );
250*cdf0e10cSrcweir         Sequence< sal_Bool > aBools( Params.getLength() );
251*cdf0e10cSrcweir         const Any* pIn = Params.getConstArray();
252*cdf0e10cSrcweir         OUString* pOutString = aStrings.getArray();
253*cdf0e10cSrcweir         sal_Bool* pOutBool = aBools.getArray();
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir         Reference< XTypeConverter > xC = getTypeConverter();
256*cdf0e10cSrcweir         bool bGetBranch = FunctionName.equalsAscii( "getString" ) || FunctionName.equalsAscii( "getStrings" );
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir         OGuard aGuard( Application::GetSolarMutex() );
259*cdf0e10cSrcweir         for( sal_Int32 n = 0; n < nElements; n++ )
260*cdf0e10cSrcweir         {
261*cdf0e10cSrcweir             sal_Int32 nId = 0;
262*cdf0e10cSrcweir             if( !(pIn[n] >>= nId) )
263*cdf0e10cSrcweir             {
264*cdf0e10cSrcweir                 if( xC.is() )
265*cdf0e10cSrcweir                 {
266*cdf0e10cSrcweir                     xC->convertToSimpleType( pIn[n], TypeClass_LONG ) >>= nId;
267*cdf0e10cSrcweir                 }
268*cdf0e10cSrcweir                 else
269*cdf0e10cSrcweir                     throw CannotConvertException();
270*cdf0e10cSrcweir             }
271*cdf0e10cSrcweir             if( nId > 0xFFFF || nId < 0 )
272*cdf0e10cSrcweir                 throw IllegalArgumentException();
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir             if( bGetBranch )
275*cdf0e10cSrcweir             {
276*cdf0e10cSrcweir                 ResId aId( (sal_uInt16)nId, *pResMgr );
277*cdf0e10cSrcweir                 aId.SetRT( RSC_STRING );
278*cdf0e10cSrcweir                 if( pResMgr->IsAvailable( aId ) )
279*cdf0e10cSrcweir                 {
280*cdf0e10cSrcweir                     String aStr( aId );
281*cdf0e10cSrcweir                     pOutString[n] = aStr;
282*cdf0e10cSrcweir                 }
283*cdf0e10cSrcweir                 else
284*cdf0e10cSrcweir                     throw IllegalArgumentException();
285*cdf0e10cSrcweir             }
286*cdf0e10cSrcweir             else // hasString(s)
287*cdf0e10cSrcweir             {
288*cdf0e10cSrcweir                 sal_Bool bRet = sal_False;
289*cdf0e10cSrcweir                 if( pResMgr )
290*cdf0e10cSrcweir                 {
291*cdf0e10cSrcweir                     ResId aId( (sal_uInt16)nId, *pResMgr );
292*cdf0e10cSrcweir                     aId.SetRT( RSC_STRING );
293*cdf0e10cSrcweir                     bRet = pResMgr->IsAvailable( aId );
294*cdf0e10cSrcweir                 }
295*cdf0e10cSrcweir                 pOutBool[n] = bRet;
296*cdf0e10cSrcweir             }
297*cdf0e10cSrcweir         }
298*cdf0e10cSrcweir         if( FunctionName.equalsAscii("getString") )
299*cdf0e10cSrcweir             aRet <<= pOutString[0];
300*cdf0e10cSrcweir         else if( FunctionName.equalsAscii("getStrings" ) )
301*cdf0e10cSrcweir             aRet <<= aStrings;
302*cdf0e10cSrcweir         else if( FunctionName.equalsAscii("hasString" ) )
303*cdf0e10cSrcweir             aRet <<= pOutBool[0];
304*cdf0e10cSrcweir         else
305*cdf0e10cSrcweir             aRet <<= aBools;
306*cdf0e10cSrcweir     }
307*cdf0e10cSrcweir     else if( FunctionName.equalsAscii("getStringList") || FunctionName.equalsAscii("hasStringList" ) )
308*cdf0e10cSrcweir     {
309*cdf0e10cSrcweir         if( Params.getLength() != 1 )
310*cdf0e10cSrcweir             throw IllegalArgumentException();
311*cdf0e10cSrcweir         Reference< XTypeConverter > xC = getTypeConverter();
312*cdf0e10cSrcweir         OGuard aGuard( Application::GetSolarMutex() );
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir         sal_Int32 nId = 0;
315*cdf0e10cSrcweir         if( !(Params.getConstArray()[0] >>= nId) )
316*cdf0e10cSrcweir         {
317*cdf0e10cSrcweir             if( xC.is() )
318*cdf0e10cSrcweir             {
319*cdf0e10cSrcweir                 xC->convertToSimpleType( Params.getConstArray()[0], TypeClass_LONG ) >>= nId;
320*cdf0e10cSrcweir             }
321*cdf0e10cSrcweir             else
322*cdf0e10cSrcweir                 throw CannotConvertException();
323*cdf0e10cSrcweir         }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir         if( FunctionName.equalsAscii("getStringList") )
326*cdf0e10cSrcweir         {
327*cdf0e10cSrcweir             ResId aId( (sal_uInt16)nId, *pResMgr );
328*cdf0e10cSrcweir             aId.SetRT( RSC_STRINGARRAY );
329*cdf0e10cSrcweir             if( pResMgr->IsAvailable( aId ) )
330*cdf0e10cSrcweir             {
331*cdf0e10cSrcweir                 ResStringArray aStr( aId );
332*cdf0e10cSrcweir                 int nEntries = aStr.Count();
333*cdf0e10cSrcweir                 Sequence< PropertyValue > aPropSeq( nEntries );
334*cdf0e10cSrcweir                 PropertyValue* pOut = aPropSeq.getArray();
335*cdf0e10cSrcweir                 for( int i = 0; i < nEntries; i++ )
336*cdf0e10cSrcweir                 {
337*cdf0e10cSrcweir                     pOut[i].Name        = aStr.GetString( i );
338*cdf0e10cSrcweir                     pOut[i].Handle      = -1;
339*cdf0e10cSrcweir                     pOut[i].Value     <<= aStr.GetValue( i );
340*cdf0e10cSrcweir                     pOut[i].State       = PropertyState_DIRECT_VALUE;
341*cdf0e10cSrcweir                 }
342*cdf0e10cSrcweir                 aRet <<= aPropSeq;
343*cdf0e10cSrcweir             }
344*cdf0e10cSrcweir             else
345*cdf0e10cSrcweir                 throw IllegalArgumentException();
346*cdf0e10cSrcweir         }
347*cdf0e10cSrcweir         else // hasStringList
348*cdf0e10cSrcweir         {
349*cdf0e10cSrcweir             sal_Bool bRet = sal_False;
350*cdf0e10cSrcweir             if( pResMgr )
351*cdf0e10cSrcweir             {
352*cdf0e10cSrcweir                 ResId aId( (sal_uInt16)nId, *pResMgr );
353*cdf0e10cSrcweir                 aId.SetRT( RSC_STRINGARRAY );
354*cdf0e10cSrcweir                 bRet = pResMgr->IsAvailable( aId );
355*cdf0e10cSrcweir             }
356*cdf0e10cSrcweir             aRet <<= bRet;
357*cdf0e10cSrcweir         }
358*cdf0e10cSrcweir     }
359*cdf0e10cSrcweir 	else
360*cdf0e10cSrcweir 	{
361*cdf0e10cSrcweir 		Reference< XInvocation > xI = getDefaultInvocation();
362*cdf0e10cSrcweir 		if( xI.is() )
363*cdf0e10cSrcweir 			return xI->invoke( FunctionName, Params, OutParamIndex, OutParam );
364*cdf0e10cSrcweir 		else
365*cdf0e10cSrcweir 			throw IllegalArgumentException();
366*cdf0e10cSrcweir 	}
367*cdf0e10cSrcweir 	return aRet;
368*cdf0e10cSrcweir }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir // XInvokation
371*cdf0e10cSrcweir void SAL_CALL ResourceService::setValue(const OUString& PropertyName, const Any& Value)
372*cdf0e10cSrcweir 	throw(UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException)
373*cdf0e10cSrcweir {
374*cdf0e10cSrcweir 	if( PropertyName.equalsAscii("FileName") )
375*cdf0e10cSrcweir 	{
376*cdf0e10cSrcweir 		OUString aName;
377*cdf0e10cSrcweir 		if( !(Value >>= aName) )
378*cdf0e10cSrcweir 		{
379*cdf0e10cSrcweir 			Reference< XTypeConverter > xC = getTypeConverter();
380*cdf0e10cSrcweir 			if( xC.is() )
381*cdf0e10cSrcweir 				xC->convertToSimpleType( Value, TypeClass_STRING ) >>= aName;
382*cdf0e10cSrcweir 			else
383*cdf0e10cSrcweir 				throw CannotConvertException();
384*cdf0e10cSrcweir 		}
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 		OGuard aGuard( Application::GetSolarMutex() );
387*cdf0e10cSrcweir         OStringBuffer aBuf( aName.getLength()+8 );
388*cdf0e10cSrcweir         aBuf.append( OUStringToOString( aName, osl_getThreadTextEncoding() ) );
389*cdf0e10cSrcweir 		ResMgr * pRM = ResMgr::CreateResMgr( aBuf.getStr() );
390*cdf0e10cSrcweir 		if( !pRM )
391*cdf0e10cSrcweir 			throw InvocationTargetException();
392*cdf0e10cSrcweir 		if( pResMgr )
393*cdf0e10cSrcweir 			delete pResMgr;
394*cdf0e10cSrcweir 		pResMgr = pRM;
395*cdf0e10cSrcweir 		aFileName = OStringToOUString( aBuf.makeStringAndClear(), osl_getThreadTextEncoding() );
396*cdf0e10cSrcweir 	}
397*cdf0e10cSrcweir 	else
398*cdf0e10cSrcweir 	{
399*cdf0e10cSrcweir 		Reference< XInvocation > xI = getDefaultInvocation();
400*cdf0e10cSrcweir 		if( xI.is() )
401*cdf0e10cSrcweir 			xI->setValue( PropertyName, Value );
402*cdf0e10cSrcweir 		else
403*cdf0e10cSrcweir 			throw UnknownPropertyException();
404*cdf0e10cSrcweir 	}
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir // XInvokation
408*cdf0e10cSrcweir Any SAL_CALL ResourceService::getValue(const OUString& PropertyName)
409*cdf0e10cSrcweir 	throw(UnknownPropertyException, RuntimeException)
410*cdf0e10cSrcweir {
411*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
412*cdf0e10cSrcweir 	if( PropertyName.equalsAscii("FileName" ))
413*cdf0e10cSrcweir 		return makeAny( aFileName );
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	Reference< XInvocation > xI = getDefaultInvocation();
416*cdf0e10cSrcweir 	if( xI.is() )
417*cdf0e10cSrcweir 		return xI->getValue( PropertyName );
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 	throw UnknownPropertyException();
420*cdf0e10cSrcweir }
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir // XInvokation
423*cdf0e10cSrcweir sal_Bool SAL_CALL ResourceService::hasMethod(const OUString& Name)
424*cdf0e10cSrcweir 	throw(RuntimeException)
425*cdf0e10cSrcweir {
426*cdf0e10cSrcweir 	if( Name.equalsAscii("getString")     ||
427*cdf0e10cSrcweir         Name.equalsAscii("getStrings")    ||
428*cdf0e10cSrcweir         Name.equalsAscii("hasString")     ||
429*cdf0e10cSrcweir         Name.equalsAscii("hasStrings")    ||
430*cdf0e10cSrcweir         Name.equalsAscii("getStringList") ||
431*cdf0e10cSrcweir         Name.equalsAscii("hasStringList")
432*cdf0e10cSrcweir         )
433*cdf0e10cSrcweir 		return sal_True;
434*cdf0e10cSrcweir 	else
435*cdf0e10cSrcweir 	{
436*cdf0e10cSrcweir 		Reference< XInvocation > xI = getDefaultInvocation();
437*cdf0e10cSrcweir 		if( xI.is() )
438*cdf0e10cSrcweir 			return xI->hasMethod( Name );
439*cdf0e10cSrcweir 		else
440*cdf0e10cSrcweir 			return sal_False;
441*cdf0e10cSrcweir 	}
442*cdf0e10cSrcweir }
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir // XInvokation
445*cdf0e10cSrcweir sal_Bool SAL_CALL ResourceService::hasProperty(const OUString& Name)
446*cdf0e10cSrcweir 	throw(RuntimeException)
447*cdf0e10cSrcweir {
448*cdf0e10cSrcweir 	if( Name.equalsAscii("FileName") )
449*cdf0e10cSrcweir 		return sal_True;
450*cdf0e10cSrcweir 	else
451*cdf0e10cSrcweir 	{
452*cdf0e10cSrcweir 		Reference< XInvocation > xI = getDefaultInvocation();
453*cdf0e10cSrcweir 		if( xI.is() )
454*cdf0e10cSrcweir 			return xI->hasProperty( Name );
455*cdf0e10cSrcweir 		else
456*cdf0e10cSrcweir 			return sal_False;
457*cdf0e10cSrcweir 	}
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir namespace res
461*cdf0e10cSrcweir {
462*cdf0e10cSrcweir     ComponentInfo getComponentInfo_VclStringResourceLoader()
463*cdf0e10cSrcweir     {
464*cdf0e10cSrcweir         ComponentInfo aInfo;
465*cdf0e10cSrcweir         aInfo.aSupportedServices = ResourceService::getSupportedServiceNames_Static();
466*cdf0e10cSrcweir         aInfo.sImplementationName = ResourceService::getImplementationName_Static();
467*cdf0e10cSrcweir         aInfo.pFactory = &ResourceService::Create;
468*cdf0e10cSrcweir         return aInfo;
469*cdf0e10cSrcweir     }
470*cdf0e10cSrcweir }
471*cdf0e10cSrcweir 
472