Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "sal/config.h"
30 : : #include "cppuhelper/factory.hxx"
31 : : #include "cppuhelper/implementationentry.hxx"
32 : : #include "cppuhelper/implbase3.hxx"
33 : : #include "com/sun/star/lang/XServiceInfo.hpp"
34 : : #include "com/sun/star/inspection/XStringRepresentation.hpp"
35 : : #include "com/sun/star/lang/XInitialization.hpp"
36 : : #include "com/sun/star/script/XTypeConverter.hpp"
37 : : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
38 : : #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
39 : : #include <com/sun/star/beans/XIntrospection.hpp>
40 : : #include <com/sun/star/util/DateTime.hpp>
41 : : #include <com/sun/star/util/Date.hpp>
42 : : #include <com/sun/star/util/Time.hpp>
43 : : #include <comphelper/sequence.hxx>
44 : : #include <connectivity/dbconversion.hxx>
45 : : #include "formresid.hrc"
46 : : #include <tools/debug.hxx>
47 : : #include <tools/string.hxx>
48 : : #include <tools/StringListResource.hxx>
49 : : #include <comphelper/types.hxx>
50 : : #include "modulepcr.hxx"
51 : :
52 : : #include <functional>
53 : : #include <algorithm>
54 : :
55 : : // component helper namespace
56 : : namespace comp_StringRepresentation {
57 : :
58 : : using namespace ::com::sun::star;
59 : :
60 : : // component and service helper functions:
61 : : ::rtl::OUString SAL_CALL _getImplementationName();
62 : : uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames();
63 : : uno::Reference< uno::XInterface > SAL_CALL _create( uno::Reference< uno::XComponentContext > const & context );
64 : :
65 : : } // closing component helper namespace
66 : :
67 : :
68 : : namespace pcr{
69 : :
70 : : using namespace ::com::sun::star;
71 : : using namespace ::com::sun::star::uno;
72 : :
73 : : class StringRepresentation:
74 : : public ::cppu::WeakImplHelper3<
75 : : lang::XServiceInfo,
76 : : inspection::XStringRepresentation,
77 : : lang::XInitialization>
78 : : {
79 : : public:
80 : : explicit StringRepresentation(uno::Reference< uno::XComponentContext > const & context);
81 : :
82 : : // lang::XServiceInfo:
83 : : virtual ::rtl::OUString SAL_CALL getImplementationName() throw (uno::RuntimeException);
84 : : virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (uno::RuntimeException);
85 : : virtual uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException);
86 : :
87 : : // inspection::XStringRepresentation:
88 : : virtual ::rtl::OUString SAL_CALL convertToControlValue(const uno::Any & PropertyValue) throw (uno::RuntimeException, uno::Exception);
89 : : virtual uno::Any SAL_CALL convertToPropertyValue(const ::rtl::OUString & ControlValue, const uno::Type & ControlValueType) throw (uno::RuntimeException, uno::Exception);
90 : :
91 : : // lang::XInitialization:
92 : : virtual void SAL_CALL initialize(const uno::Sequence< uno::Any > & aArguments) throw (uno::RuntimeException, uno::Exception);
93 : :
94 : : private:
95 : : StringRepresentation(StringRepresentation &); // not defined
96 : : void operator =(StringRepresentation &); // not defined
97 : :
98 : 0 : virtual ~StringRepresentation() {}
99 : :
100 : : /** converts a generic value into a string representation
101 : :
102 : : If you want to convert values whose string representation does not depend
103 : : on a concrete property, use this version
104 : :
105 : : @return <TRUE/>
106 : : if and only if the value could be converted
107 : : */
108 : : bool convertGenericValueToString(
109 : : const uno::Any& _rValue,
110 : : ::rtl::OUString& _rStringRep
111 : : );
112 : :
113 : : /** converts string representation into generic value
114 : :
115 : : If you want to convert values whose string representation does not depend
116 : : on a concrete property, use this version
117 : :
118 : : @return <TRUE/>
119 : : if and only if the value could be converted
120 : : */
121 : : bool convertStringToGenericValue(
122 : : const ::rtl::OUString& _rStringRep,
123 : : uno::Any& _rValue,
124 : : const uno::Type& _rTargetType
125 : : );
126 : :
127 : : /** uses the simple convert method from the type converter
128 : : *
129 : : * \param _rValue the value to be converted
130 : : * \return the converted string.
131 : : */
132 : : ::rtl::OUString convertSimpleToString( const uno::Any& _rValue );
133 : :
134 : : /** converts a string into his constant value if it exists, otherwise the type converter is used.
135 : : * \param _rValue the value to be converted
136 : : * \param _ePropertyType teh type of the propery to be converted into
137 : : * \return the converted value
138 : : */
139 : : uno::Any convertStringToSimple( const ::rtl::OUString& _rValue,const uno::TypeClass& _ePropertyType );
140 : :
141 : : uno::Reference< uno::XComponentContext > m_xContext;
142 : : uno::Reference< script::XTypeConverter > m_xTypeConverter;
143 : : uno::Reference< reflection::XConstantsTypeDescription > m_xTypeDescription;
144 : : uno::Sequence< ::rtl::OUString > m_aValues;
145 : : uno::Sequence< uno::Reference< reflection::XConstantTypeDescription> > m_aConstants;
146 : :
147 : : };
148 : :
149 : 0 : StringRepresentation::StringRepresentation(uno::Reference< uno::XComponentContext > const & context) :
150 : 0 : m_xContext(context)
151 : 0 : {}
152 : :
153 : : // com.sun.star.uno.XServiceInfo:
154 : 0 : ::rtl::OUString SAL_CALL StringRepresentation::getImplementationName() throw (uno::RuntimeException)
155 : : {
156 : 0 : return comp_StringRepresentation::_getImplementationName();
157 : : }
158 : :
159 : 0 : ::sal_Bool SAL_CALL StringRepresentation::supportsService(::rtl::OUString const & serviceName) throw (uno::RuntimeException)
160 : : {
161 : 0 : return ::comphelper::existsValue(serviceName,comp_StringRepresentation::_getSupportedServiceNames());
162 : : }
163 : :
164 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL StringRepresentation::getSupportedServiceNames() throw (uno::RuntimeException)
165 : : {
166 : 0 : return comp_StringRepresentation::_getSupportedServiceNames();
167 : : }
168 : :
169 : : // inspection::XStringRepresentation:
170 : 0 : ::rtl::OUString SAL_CALL StringRepresentation::convertToControlValue(const uno::Any & PropertyValue) throw (uno::RuntimeException, uno::Exception)
171 : : {
172 : 0 : ::rtl::OUString sReturn;
173 : 0 : if ( !convertGenericValueToString( PropertyValue, sReturn ) )
174 : : {
175 : 0 : sReturn = convertSimpleToString( PropertyValue );
176 : : #ifdef DBG_UTIL
177 : : if ( sReturn.isEmpty() && PropertyValue.hasValue() )
178 : : {
179 : : ::rtl::OString sMessage( "StringRepresentation::convertPropertyValueToStringRepresentation: cannot convert values of type '" );
180 : : sMessage += ::rtl::OString( PropertyValue.getValueType().getTypeName().getStr(), PropertyValue.getValueType().getTypeName().getLength(), RTL_TEXTENCODING_ASCII_US );
181 : : sMessage += ::rtl::OString( "'!" );
182 : : OSL_FAIL( sMessage.getStr() );
183 : : }
184 : : #endif
185 : : }
186 : :
187 : 0 : return sReturn;
188 : : }
189 : :
190 : 0 : uno::Any SAL_CALL StringRepresentation::convertToPropertyValue(const ::rtl::OUString & ControlValue, const uno::Type & ControlValueType) throw (uno::RuntimeException, uno::Exception)
191 : : {
192 : 0 : uno::Any aReturn;
193 : :
194 : 0 : uno::TypeClass ePropertyType = ControlValueType.getTypeClass();
195 : 0 : switch ( ePropertyType )
196 : : {
197 : : case uno::TypeClass_FLOAT:
198 : : case uno::TypeClass_DOUBLE:
199 : : case uno::TypeClass_BYTE:
200 : : case uno::TypeClass_SHORT:
201 : : case uno::TypeClass_LONG:
202 : : case uno::TypeClass_HYPER:
203 : : case uno::TypeClass_UNSIGNED_SHORT:
204 : : case uno::TypeClass_UNSIGNED_LONG:
205 : : case uno::TypeClass_UNSIGNED_HYPER:
206 : : try
207 : : {
208 : 0 : aReturn = convertStringToSimple(ControlValue, ePropertyType);
209 : : }
210 : 0 : catch( const script::CannotConvertException& ) { }
211 : 0 : catch( const lang::IllegalArgumentException& ) { }
212 : 0 : break;
213 : :
214 : : default:
215 : : #if OSL_DEBUG_LEVEL > 0
216 : : bool bCanConvert =
217 : : #endif
218 : 0 : convertStringToGenericValue( ControlValue, aReturn, ControlValueType );
219 : :
220 : : #if OSL_DEBUG_LEVEL > 0
221 : : // could not convert ...
222 : : if ( !bCanConvert && !ControlValue.isEmpty() )
223 : : {
224 : : ::rtl::OString sMessage( "StringRepresentation::convertStringRepresentationToPropertyValue: cannot convert into values of type '" );
225 : : sMessage += ::rtl::OString( ControlValueType.getTypeName().getStr(), ControlValueType.getTypeName().getLength(), RTL_TEXTENCODING_ASCII_US );
226 : : sMessage += ::rtl::OString( "'!" );
227 : : OSL_FAIL( sMessage.getStr() );
228 : : }
229 : : #endif
230 : : }
231 : :
232 : 0 : return aReturn;
233 : : }
234 : :
235 : : // lang::XInitialization:
236 : 0 : void SAL_CALL StringRepresentation::initialize(const uno::Sequence< uno::Any > & aArguments) throw (uno::RuntimeException, uno::Exception)
237 : : {
238 : 0 : sal_Int32 nLength = aArguments.getLength();
239 : 0 : if ( nLength )
240 : : {
241 : 0 : const uno::Any* pIter = aArguments.getConstArray();
242 : 0 : m_xTypeConverter.set(*pIter++,uno::UNO_QUERY);
243 : 0 : if ( nLength == 3 )
244 : : {
245 : 0 : ::rtl::OUString sConstantName;
246 : 0 : *pIter++ >>= sConstantName;
247 : 0 : *pIter >>= m_aValues;
248 : :
249 : 0 : if ( m_xContext.is() )
250 : : {
251 : : uno::Reference< container::XHierarchicalNameAccess > xTypeDescProv(
252 : 0 : m_xContext->getValueByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.reflection.theTypeDescriptionManager" ) ) ),
253 : 0 : uno::UNO_QUERY_THROW );
254 : :
255 : 0 : m_xTypeDescription.set( xTypeDescProv->getByHierarchicalName( sConstantName ), uno::UNO_QUERY_THROW );
256 : 0 : m_aConstants = m_xTypeDescription->getConstants();
257 : 0 : }
258 : : }
259 : : }
260 : 0 : }
261 : : //------------------------------------------------------------------------
262 : 0 : ::rtl::OUString StringRepresentation::convertSimpleToString( const uno::Any& _rValue )
263 : : {
264 : 0 : ::rtl::OUString sReturn;
265 : 0 : if ( m_xTypeConverter.is() && _rValue.hasValue() )
266 : : {
267 : : try
268 : : {
269 : 0 : if ( m_aConstants.getLength() )
270 : : {
271 : 0 : sal_Int16 nConstantValue = 0;
272 : 0 : if ( _rValue >>= nConstantValue )
273 : : {
274 : 0 : const uno::Reference< reflection::XConstantTypeDescription>* pIter = m_aConstants.getConstArray();
275 : 0 : const uno::Reference< reflection::XConstantTypeDescription>* pEnd = pIter + m_aConstants.getLength();
276 : 0 : for(sal_Int32 i = 0;pIter != pEnd;++pIter,++i)
277 : : {
278 : 0 : if ( (*pIter)->getConstantValue() == _rValue )
279 : : {
280 : : OSL_ENSURE(i < m_aValues.getLength() ,"StringRepresentation::convertSimpleToString: Index is not in range of m_aValues");
281 : 0 : sReturn = m_aValues[i];
282 : 0 : break;
283 : : }
284 : : }
285 : : }
286 : : }
287 : :
288 : 0 : if ( sReturn.isEmpty() )
289 : 0 : m_xTypeConverter->convertToSimpleType( _rValue, uno::TypeClass_STRING ) >>= sReturn;
290 : : }
291 : 0 : catch( const script::CannotConvertException& ) { }
292 : 0 : catch( const lang::IllegalArgumentException& ) { }
293 : : }
294 : 0 : return sReturn;
295 : : }
296 : :
297 : : //--------------------------------------------------------------------
298 : : namespace
299 : : {
300 : : struct ConvertIntegerFromAndToString
301 : : {
302 : 0 : ::rtl::OUString operator()( sal_Int32 _rIntValue ) const
303 : : {
304 : 0 : return ::rtl::OUString::valueOf( (sal_Int32)_rIntValue );
305 : : }
306 : 0 : sal_Int32 operator()( const ::rtl::OUString& _rStringValue ) const
307 : : {
308 : 0 : return _rStringValue.toInt32();
309 : : }
310 : : };
311 : :
312 : : struct StringIdentity
313 : : {
314 : 0 : ::rtl::OUString operator()( const ::rtl::OUString& _rValue ) const
315 : : {
316 : 0 : return _rValue;
317 : : }
318 : : };
319 : :
320 : : template < class ElementType, class Transformer >
321 : 0 : ::rtl::OUString composeSequenceElements( const Sequence< ElementType >& _rElements, const Transformer& _rTransformer )
322 : : {
323 : 0 : String sCompose;
324 : :
325 : : // loop through the elements and concatenate the string representations of the integers
326 : : // (separated by a line break)
327 : 0 : const ElementType* pElements = _rElements.getConstArray();
328 : 0 : const ElementType* pElementsEnd = pElements + _rElements.getLength();
329 : 0 : for ( ; pElements != pElementsEnd; ++pElements )
330 : : {
331 : 0 : sCompose += String( _rTransformer( *pElements ) );
332 : 0 : if ( pElements != pElementsEnd )
333 : 0 : sCompose += '\n';
334 : : }
335 : :
336 : 0 : return sCompose;
337 : : }
338 : :
339 : : template < class ElementType, class Transformer >
340 : 0 : void splitComposedStringToSequence( const ::rtl::OUString& _rComposed, Sequence< ElementType >& _out_SplitUp, const Transformer& _rTransformer )
341 : : {
342 : 0 : _out_SplitUp.realloc( 0 );
343 : 0 : if ( _rComposed.isEmpty() )
344 : 0 : return;
345 : 0 : sal_Int32 tokenPos = 0;
346 : 0 : do
347 : : {
348 : 0 : _out_SplitUp.realloc( _out_SplitUp.getLength() + 1 );
349 : 0 : _out_SplitUp[ _out_SplitUp.getLength() - 1 ] = (ElementType)_rTransformer( _rComposed.getToken( 0, '\n', tokenPos ) );
350 : : }
351 : : while ( tokenPos != -1 );
352 : : }
353 : : }
354 : :
355 : : //--------------------------------------------------------------------
356 : 0 : bool StringRepresentation::convertGenericValueToString( const uno::Any& _rValue, ::rtl::OUString& _rStringRep )
357 : : {
358 : 0 : bool bCanConvert = true;
359 : :
360 : 0 : switch ( _rValue.getValueTypeClass() )
361 : : {
362 : : case uno::TypeClass_STRING:
363 : 0 : _rValue >>= _rStringRep;
364 : 0 : break;
365 : :
366 : : case uno::TypeClass_BOOLEAN:
367 : : {
368 : 0 : ::std::vector< ::rtl::OUString > aListEntries;
369 : 0 : tools::StringListResource aRes(PcrRes(RID_RSC_ENUM_YESNO),aListEntries);
370 : 0 : sal_Bool bValue = sal_False;
371 : 0 : _rValue >>= bValue;
372 : 0 : _rStringRep = bValue ? aListEntries[1] : aListEntries[0];
373 : : }
374 : 0 : break;
375 : :
376 : : // some sequence types
377 : : case uno::TypeClass_SEQUENCE:
378 : : {
379 : 0 : Sequence< ::rtl::OUString > aStringValues;
380 : 0 : Sequence< sal_Int8 > aInt8Values;
381 : 0 : Sequence< sal_uInt16 > aUInt16Values;
382 : 0 : Sequence< sal_Int16 > aInt16Values;
383 : 0 : Sequence< sal_uInt32 > aUInt32Values;
384 : 0 : Sequence< sal_Int32 > aInt32Values;
385 : :
386 : : // string sequences
387 : 0 : if ( _rValue >>= aStringValues )
388 : : {
389 : 0 : _rStringRep = composeSequenceElements( aStringValues, StringIdentity() );
390 : : }
391 : : // byte sequences
392 : 0 : else if ( _rValue >>= aInt8Values )
393 : : {
394 : 0 : _rStringRep = composeSequenceElements( aInt8Values, ConvertIntegerFromAndToString() );
395 : : }
396 : : // uInt16 sequences
397 : 0 : else if ( _rValue >>= aUInt16Values )
398 : : {
399 : 0 : _rStringRep = composeSequenceElements( aUInt16Values, ConvertIntegerFromAndToString() );
400 : : }
401 : : // Int16 sequences
402 : 0 : else if ( _rValue >>= aInt16Values )
403 : : {
404 : 0 : _rStringRep = composeSequenceElements( aInt16Values, ConvertIntegerFromAndToString() );
405 : : }
406 : : // uInt32 sequences
407 : 0 : else if ( _rValue >>= aUInt32Values )
408 : : {
409 : 0 : _rStringRep = composeSequenceElements( aUInt32Values, ConvertIntegerFromAndToString() );
410 : : }
411 : : // Int32 sequences
412 : 0 : else if ( _rValue >>= aInt32Values )
413 : : {
414 : 0 : _rStringRep = composeSequenceElements( aInt32Values, ConvertIntegerFromAndToString() );
415 : : }
416 : : else
417 : 0 : bCanConvert = false;
418 : : }
419 : 0 : break;
420 : : case uno::TypeClass_CONSTANT:
421 : : {
422 : 0 : int i = 0;
423 : 0 : ++i;
424 : : }
425 : 0 : break;
426 : :
427 : : // some structs
428 : : case uno::TypeClass_STRUCT:
429 : : OSL_FAIL( "StringRepresentation::convertGenericValueToString(STRUCT): this is dead code - isn't it?" );
430 : 0 : if ( _rValue.getValueType().equals( ::getCppuType( static_cast< util::Date* >( NULL ) ) ) )
431 : : {
432 : : // weird enough, the string representation of dates, as used
433 : : // by the control displaying dates, and thus as passed through the layers,
434 : : // is YYYYMMDD.
435 : 0 : util::Date aUnoDate;
436 : 0 : _rValue >>= aUnoDate;
437 : 0 : _rStringRep = ::dbtools::DBTypeConversion::toDateString(aUnoDate);
438 : : }
439 : 0 : else if ( _rValue.getValueType().equals( ::getCppuType( static_cast< util::Time* >( NULL ) ) ) )
440 : : {
441 : : // similar for time (HHMMSSHH)
442 : 0 : util::Time aUnoTime;
443 : 0 : _rValue >>= aUnoTime;
444 : 0 : _rStringRep = ::dbtools::DBTypeConversion::toTimeString(aUnoTime);
445 : : }
446 : 0 : else if ( _rValue.getValueType().equals( ::getCppuType( static_cast< util::DateTime* >( NULL ) ) ) )
447 : : {
448 : 0 : util::DateTime aUnoDateTime;
449 : 0 : _rValue >>= aUnoDateTime;
450 : 0 : _rStringRep = ::dbtools::DBTypeConversion::toDateTimeString(aUnoDateTime);
451 : : }
452 : : else
453 : 0 : bCanConvert = false;
454 : 0 : break;
455 : :
456 : : default:
457 : 0 : bCanConvert = false;
458 : 0 : break;
459 : : }
460 : :
461 : 0 : return bCanConvert;
462 : : }
463 : : //------------------------------------------------------------------------
464 : 0 : uno::Any StringRepresentation::convertStringToSimple( const ::rtl::OUString& _rValue,const uno::TypeClass& _ePropertyType )
465 : : {
466 : 0 : uno::Any aReturn;
467 : 0 : if ( m_xTypeConverter.is() && !_rValue.isEmpty() )
468 : : {
469 : : try
470 : : {
471 : 0 : if ( m_aConstants.getLength() && m_aValues.getLength() )
472 : : {
473 : 0 : const ::rtl::OUString* pIter = m_aValues.getConstArray();
474 : 0 : const ::rtl::OUString* pEnd = pIter + m_aValues.getLength();
475 : 0 : for(sal_Int32 i = 0;pIter != pEnd;++pIter,++i)
476 : : {
477 : 0 : if ( *pIter == _rValue )
478 : : {
479 : : OSL_ENSURE(i < m_aConstants.getLength() ,"StringRepresentation::convertSimpleToString: Index is not in range of m_aValues");
480 : 0 : aReturn <<= m_aConstants[i]->getConstantValue();
481 : 0 : break;
482 : : }
483 : : }
484 : : }
485 : :
486 : 0 : if ( !aReturn.hasValue() )
487 : 0 : aReturn = m_xTypeConverter->convertToSimpleType( makeAny( _rValue ), _ePropertyType );
488 : : }
489 : 0 : catch( const script::CannotConvertException& ) { }
490 : 0 : catch( const lang::IllegalArgumentException& ) { }
491 : : }
492 : 0 : return aReturn;
493 : : }
494 : : //--------------------------------------------------------------------
495 : 0 : bool StringRepresentation::convertStringToGenericValue( const ::rtl::OUString& _rStringRep, uno::Any& _rValue, const uno::Type& _rTargetType )
496 : : {
497 : 0 : bool bCanConvert = true;
498 : :
499 : 0 : switch ( _rTargetType.getTypeClass() )
500 : : {
501 : : case uno::TypeClass_STRING:
502 : 0 : _rValue <<= _rStringRep;
503 : 0 : break;
504 : :
505 : : case uno::TypeClass_BOOLEAN:
506 : : {
507 : 0 : ::std::vector< ::rtl::OUString > aListEntries;
508 : 0 : tools::StringListResource aRes(PcrRes(RID_RSC_ENUM_YESNO),aListEntries);
509 : 0 : if ( aListEntries[0] == _rStringRep )
510 : 0 : _rValue <<= (sal_Bool)sal_False;
511 : : else
512 : 0 : _rValue <<= (sal_Bool)sal_True;
513 : : }
514 : 0 : break;
515 : :
516 : : case uno::TypeClass_SEQUENCE:
517 : : {
518 : 0 : uno::Type aElementType = ::comphelper::getSequenceElementType( _rTargetType );
519 : :
520 : 0 : String aStr( _rStringRep );
521 : 0 : switch ( aElementType.getTypeClass() )
522 : : {
523 : : case uno::TypeClass_STRING:
524 : : {
525 : 0 : Sequence< ::rtl::OUString > aElements;
526 : 0 : splitComposedStringToSequence( aStr, aElements, StringIdentity() );
527 : 0 : _rValue <<= aElements;
528 : : }
529 : 0 : break;
530 : : case uno::TypeClass_SHORT:
531 : : {
532 : 0 : Sequence< sal_Int16 > aElements;
533 : 0 : splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
534 : 0 : _rValue <<= aElements;
535 : : }
536 : 0 : break;
537 : : case uno::TypeClass_UNSIGNED_SHORT:
538 : : {
539 : 0 : Sequence< sal_uInt16 > aElements;
540 : 0 : splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
541 : 0 : _rValue <<= aElements;
542 : : }
543 : 0 : break;
544 : : case uno::TypeClass_LONG:
545 : : {
546 : 0 : Sequence< sal_Int32 > aElements;
547 : 0 : splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
548 : 0 : _rValue <<= aElements;
549 : : }
550 : 0 : break;
551 : : case uno::TypeClass_UNSIGNED_LONG:
552 : : {
553 : 0 : Sequence< sal_uInt32 > aElements;
554 : 0 : splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
555 : 0 : _rValue <<= aElements;
556 : : }
557 : 0 : break;
558 : : case uno::TypeClass_BYTE:
559 : : {
560 : 0 : Sequence< sal_Int8 > aElements;
561 : 0 : splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
562 : 0 : _rValue <<= aElements;
563 : : }
564 : 0 : break;
565 : : default:
566 : 0 : bCanConvert = false;
567 : 0 : break;
568 : 0 : }
569 : : }
570 : 0 : break;
571 : :
572 : : case uno::TypeClass_STRUCT:
573 : : OSL_FAIL( "StringRepresentation::convertStringToGenericValue(STRUCT): this is dead code - isn't it?" );
574 : 0 : if ( _rTargetType.equals( ::getCppuType( static_cast< util::Date* >( NULL ) ) ) )
575 : : {
576 : : // weird enough, the string representation of dates, as used
577 : : // by the control displaying dates, and thus as passed through the layers,
578 : : // is YYYYMMDD.
579 : :
580 : 0 : _rValue <<= ::dbtools::DBTypeConversion::toDate(_rStringRep);
581 : : }
582 : 0 : else if ( _rTargetType.equals( ::getCppuType( static_cast< util::Time* >( NULL ) ) ) )
583 : : {
584 : : // similar for time (HHMMSSHH)
585 : 0 : _rValue <<= ::dbtools::DBTypeConversion::toTime(_rStringRep);
586 : : }
587 : 0 : else if ( _rTargetType.equals( ::getCppuType( static_cast< util::DateTime* >( NULL ) ) ) )
588 : : {
589 : 0 : _rValue <<= ::dbtools::DBTypeConversion::toDateTime(_rStringRep);
590 : : }
591 : : else
592 : 0 : bCanConvert = false;
593 : 0 : break;
594 : :
595 : : default:
596 : 0 : bCanConvert = false;
597 : 0 : break;
598 : : }
599 : :
600 : 0 : return bCanConvert;
601 : : }
602 : : //------------------------------------------------------------------------
603 : : //------------------------------------------------------------------------
604 : : } // pcr
605 : : //------------------------------------------------------------------------
606 : :
607 : :
608 : : // component helper namespace
609 : : namespace comp_StringRepresentation {
610 : :
611 : 0 : ::rtl::OUString SAL_CALL _getImplementationName() {
612 : : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
613 : 0 : "StringRepresentation"));
614 : : }
615 : :
616 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames()
617 : : {
618 : 0 : uno::Sequence< ::rtl::OUString > s(1);
619 : 0 : s[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
620 : 0 : "com.sun.star.inspection.StringRepresentation"));
621 : 0 : return s;
622 : : }
623 : :
624 : 0 : uno::Reference< uno::XInterface > SAL_CALL _create(
625 : : const uno::Reference< uno::XComponentContext > & context)
626 : : SAL_THROW((uno::Exception))
627 : : {
628 : 0 : return static_cast< ::cppu::OWeakObject * >(new pcr::StringRepresentation(context));
629 : : }
630 : :
631 : : } // closing component helper namespace
632 : :
633 : : //------------------------------------------------------------------------
634 : 0 : extern "C" void SAL_CALL createRegistryInfo_StringRepresentation()
635 : : {
636 : 0 : ::pcr::PcrModule::getInstance().registerImplementation(
637 : : comp_StringRepresentation::_getImplementationName(),
638 : : comp_StringRepresentation::_getSupportedServiceNames(),
639 : : comp_StringRepresentation::_create
640 : 0 : );
641 : 0 : }
642 : :
643 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|