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