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