LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - stringrepresentation.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 10 215 4.7 %
Date: 2015-06-13 12:38:46 Functions: 3 33 9.1 %
Legend: Lines: hit not hit

          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             : 
      22             : #include "boost/noncopyable.hpp"
      23             : #include "cppuhelper/factory.hxx"
      24             : #include "cppuhelper/implementationentry.hxx"
      25             : #include "cppuhelper/implbase3.hxx"
      26             : #include <cppuhelper/supportsservice.hxx>
      27             : #include "com/sun/star/lang/XServiceInfo.hpp"
      28             : #include "com/sun/star/inspection/XStringRepresentation.hpp"
      29             : #include "com/sun/star/lang/XInitialization.hpp"
      30             : #include "com/sun/star/script/XTypeConverter.hpp"
      31             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      32             : #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
      33             : #include <com/sun/star/beans/XIntrospection.hpp>
      34             : #include <com/sun/star/util/DateTime.hpp>
      35             : #include <com/sun/star/util/Date.hpp>
      36             : #include <com/sun/star/util/Time.hpp>
      37             : #include <comphelper/sequence.hxx>
      38             : #include <connectivity/dbconversion.hxx>
      39             : #include "formresid.hrc"
      40             : #include "pcrservices.hxx"
      41             : #include <tools/StringListResource.hxx>
      42             : #include <comphelper/types.hxx>
      43             : #include "modulepcr.hxx"
      44             : 
      45             : #include <functional>
      46             : #include <algorithm>
      47             : 
      48             : // component helper namespace
      49             : namespace comp_StringRepresentation {
      50             : 
      51             : using namespace ::com::sun::star;
      52             : 
      53             : // component and service helper functions:
      54             : OUString SAL_CALL _getImplementationName();
      55             : uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames();
      56             : uno::Reference< uno::XInterface > SAL_CALL _create( uno::Reference< uno::XComponentContext > const & context );
      57             : 
      58             : } // closing component helper namespace
      59             : 
      60             : 
      61             : namespace pcr{
      62             : 
      63             : using namespace ::com::sun::star;
      64             : using namespace ::com::sun::star::uno;
      65             : 
      66             : class StringRepresentation:
      67             :     public ::cppu::WeakImplHelper3<
      68             :         lang::XServiceInfo,
      69             :         inspection::XStringRepresentation,
      70             :         lang::XInitialization>,
      71             :     private boost::noncopyable
      72             : {
      73             : public:
      74             :     explicit StringRepresentation(uno::Reference< uno::XComponentContext > const & context);
      75             : 
      76             :     // lang::XServiceInfo:
      77             :     virtual OUString SAL_CALL getImplementationName() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      78             :     virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      79             :     virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      80             : 
      81             :     // inspection::XStringRepresentation:
      82             :     virtual OUString SAL_CALL convertToControlValue(const uno::Any & PropertyValue) throw (uno::RuntimeException, uno::Exception, std::exception) SAL_OVERRIDE;
      83             :     virtual uno::Any SAL_CALL convertToPropertyValue(const OUString & ControlValue, const uno::Type & ControlValueType) throw (uno::RuntimeException, uno::Exception, std::exception) SAL_OVERRIDE;
      84             : 
      85             :     // lang::XInitialization:
      86             :     virtual void SAL_CALL initialize(const uno::Sequence< uno::Any > & aArguments) throw (uno::RuntimeException, uno::Exception, std::exception) SAL_OVERRIDE;
      87             : 
      88             : private:
      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             :     static bool     convertGenericValueToString(
     100             :                         const uno::Any&   _rValue,
     101             :                                 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             :     static bool    convertStringToGenericValue(
     113             :                         const 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             :     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 the type of the propery to be converted into
     128             :     * \return the converted value
     129             :     */
     130             :     uno::Any convertStringToSimple( const 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< 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 : OUString  SAL_CALL StringRepresentation::getImplementationName() throw (uno::RuntimeException, std::exception)
     146             : {
     147           0 :     return comp_StringRepresentation::_getImplementationName();
     148             : }
     149             : 
     150           0 : sal_Bool SAL_CALL StringRepresentation::supportsService(OUString const & serviceName) throw (uno::RuntimeException, std::exception)
     151             : {
     152           0 :     return cppu::supportsService(this, serviceName);
     153             : }
     154             : 
     155           0 : uno::Sequence< OUString >  SAL_CALL StringRepresentation::getSupportedServiceNames() throw (uno::RuntimeException, std::exception)
     156             : {
     157           0 :     return comp_StringRepresentation::_getSupportedServiceNames();
     158             : }
     159             : 
     160             : // inspection::XStringRepresentation:
     161           0 : OUString SAL_CALL StringRepresentation::convertToControlValue(const uno::Any & PropertyValue) throw (uno::RuntimeException, uno::Exception, std::exception)
     162             : {
     163           0 :     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             :             OString sMessage( "StringRepresentation::convertPropertyValueToStringRepresentation: cannot convert values of type '" );
     171             :             sMessage += OString( PropertyValue.getValueType().getTypeName().getStr(), PropertyValue.getValueType().getTypeName().getLength(), RTL_TEXTENCODING_ASCII_US );
     172             :             sMessage += 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 OUString & ControlValue, const uno::Type & ControlValueType) throw (uno::RuntimeException, uno::Exception, std::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             :             OString sMessage( "StringRepresentation::convertStringRepresentationToPropertyValue: cannot convert into values of type '" );
     216             :             sMessage += OString( ControlValueType.getTypeName().getStr(), ControlValueType.getTypeName().getLength(), RTL_TEXTENCODING_ASCII_US );
     217             :             sMessage += OString( "'!" );
     218             :             OSL_FAIL( sMessage.getStr() );
     219             :         }
     220             :     #endif
     221             :     }
     222             : 
     223           0 :     return aReturn;
     224             : }
     225             : 
     226             : namespace {
     227             : 
     228             : // This comparison functor assumes an underlying set of constants with pairwise
     229             : // unequal values that are all of UNO SHORT or LONG type:
     230             : struct CompareConstants {
     231           0 :     bool operator ()(
     232             :         css::uno::Reference< css::reflection::XConstantTypeDescription > const &
     233             :             c1,
     234             :         css::uno::Reference< css::reflection::XConstantTypeDescription > const &
     235             :             c2) const
     236             :     {
     237           0 :         return c1->getConstantValue().get<sal_Int32>()
     238           0 :             < c2->getConstantValue().get<sal_Int32>();
     239             :     }
     240             : };
     241             : 
     242             : }
     243             : 
     244             : // lang::XInitialization:
     245           0 : void SAL_CALL StringRepresentation::initialize(const uno::Sequence< uno::Any > & aArguments) throw (uno::RuntimeException, uno::Exception, std::exception)
     246             : {
     247           0 :     sal_Int32 nLength = aArguments.getLength();
     248           0 :     if ( nLength )
     249             :     {
     250           0 :         const uno::Any* pIter = aArguments.getConstArray();
     251           0 :         m_xTypeConverter.set(*pIter++,uno::UNO_QUERY);
     252           0 :         if ( nLength == 3 )
     253             :         {
     254           0 :             OUString sConstantName;
     255           0 :             *pIter++ >>= sConstantName;
     256           0 :             *pIter >>= m_aValues;
     257             : 
     258           0 :             if ( m_xContext.is() )
     259             :             {
     260             :                 uno::Reference< container::XHierarchicalNameAccess > xTypeDescProv(
     261           0 :                     m_xContext->getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager"),
     262           0 :                     uno::UNO_QUERY_THROW );
     263             : 
     264           0 :                 m_xTypeDescription.set( xTypeDescProv->getByHierarchicalName( sConstantName ), uno::UNO_QUERY_THROW );
     265             :                 uno::Sequence<
     266             :                     uno::Reference< reflection::XConstantTypeDescription > >
     267           0 :                     cs(m_xTypeDescription->getConstants());
     268           0 :                 std::sort(cs.begin(), cs.end(), CompareConstants());
     269           0 :                 m_aConstants = cs;
     270           0 :             }
     271             :         }
     272             :     }
     273           0 : }
     274             : 
     275           0 : OUString StringRepresentation::convertSimpleToString( const uno::Any& _rValue )
     276             : {
     277           0 :     OUString sReturn;
     278           0 :     if ( m_xTypeConverter.is() && _rValue.hasValue() )
     279             :     {
     280             :         try
     281             :         {
     282           0 :             if ( m_aConstants.getLength() )
     283             :             {
     284           0 :                 sal_Int16 nConstantValue = 0;
     285           0 :                 if ( _rValue >>= nConstantValue )
     286             :                 {
     287           0 :                     const uno::Reference< reflection::XConstantTypeDescription>* pIter = m_aConstants.getConstArray();
     288           0 :                     const uno::Reference< reflection::XConstantTypeDescription>* pEnd  = pIter + m_aConstants.getLength();
     289           0 :                     for(sal_Int32 i = 0;pIter != pEnd;++pIter,++i)
     290             :                     {
     291           0 :                         if ( (*pIter)->getConstantValue() == _rValue )
     292             :                         {
     293             :                             OSL_ENSURE(i < m_aValues.getLength() ,"StringRepresentation::convertSimpleToString: Index is not in range of m_aValues");
     294           0 :                             sReturn = m_aValues[i];
     295           0 :                             break;
     296             :                         }
     297             :                     }
     298             :                 }
     299             :             }
     300             : 
     301           0 :             if ( sReturn.isEmpty() )
     302           0 :                 m_xTypeConverter->convertToSimpleType( _rValue, uno::TypeClass_STRING ) >>= sReturn;
     303             :         }
     304           0 :         catch( const script::CannotConvertException& ) { }
     305           0 :         catch( const lang::IllegalArgumentException& ) { }
     306             :     }
     307           0 :     return sReturn;
     308             : }
     309             : 
     310             : 
     311             : namespace
     312             : {
     313             :     struct ConvertIntegerFromAndToString
     314             :     {
     315           0 :         OUString operator()( sal_Int32 _rIntValue ) const
     316             :         {
     317           0 :             return OUString::number( _rIntValue );
     318             :         }
     319           0 :         sal_Int32 operator()( const OUString& _rStringValue ) const
     320             :         {
     321           0 :             return _rStringValue.toInt32();
     322             :         }
     323             :     };
     324             : 
     325             :     struct StringIdentity
     326             :     {
     327           0 :         OUString operator()( const OUString& _rValue ) const
     328             :         {
     329           0 :             return _rValue;
     330             :         }
     331             :     };
     332             : 
     333             :     template < class ElementType, class Transformer >
     334           0 :     OUString composeSequenceElements( const Sequence< ElementType >& _rElements, const Transformer& _rTransformer )
     335             :     {
     336           0 :         OUString sCompose;
     337             : 
     338             :         // loop through the elements and concatenate the string representations of the integers
     339             :         // (separated by a line break)
     340           0 :         const ElementType* pElements = _rElements.getConstArray();
     341           0 :         const ElementType* pElementsEnd = pElements + _rElements.getLength();
     342           0 :         for ( ; pElements != pElementsEnd; ++pElements )
     343             :         {
     344           0 :             sCompose += OUString( _rTransformer( *pElements ) );
     345           0 :             if ( pElements != pElementsEnd )
     346           0 :                 sCompose += "\n";
     347             :         }
     348             : 
     349           0 :         return sCompose;
     350             :     }
     351             : 
     352             :     template < class ElementType, class Transformer >
     353           0 :     void splitComposedStringToSequence( const OUString& _rComposed, Sequence< ElementType >& _out_SplitUp, const Transformer& _rTransformer )
     354             :     {
     355           0 :         _out_SplitUp.realloc( 0 );
     356           0 :         if ( _rComposed.isEmpty() )
     357           0 :             return;
     358           0 :         sal_Int32 tokenPos = 0;
     359           0 :         do
     360             :         {
     361           0 :             _out_SplitUp.realloc( _out_SplitUp.getLength() + 1 );
     362           0 :             _out_SplitUp[ _out_SplitUp.getLength() - 1 ] = static_cast<ElementType>(_rTransformer( _rComposed.getToken( 0, '\n', tokenPos ) ));
     363             :         }
     364             :         while ( tokenPos != -1 );
     365             :     }
     366             : }
     367             : 
     368             : 
     369           0 : bool StringRepresentation::convertGenericValueToString( const uno::Any& _rValue, OUString& _rStringRep )
     370             : {
     371           0 :     bool bCanConvert = true;
     372             : 
     373           0 :     switch ( _rValue.getValueTypeClass() )
     374             :     {
     375             :     case uno::TypeClass_STRING:
     376           0 :         _rValue >>= _rStringRep;
     377           0 :         break;
     378             : 
     379             :     case uno::TypeClass_BOOLEAN:
     380             :     {
     381           0 :         ::std::vector< OUString > aListEntries;
     382           0 :         tools::StringListResource aRes(PcrRes(RID_RSC_ENUM_YESNO),aListEntries);
     383           0 :         bool bValue = false;
     384           0 :         _rValue >>= bValue;
     385           0 :         _rStringRep = bValue ? aListEntries[1] : aListEntries[0];
     386             :     }
     387           0 :     break;
     388             : 
     389             :     // some sequence types
     390             :     case uno::TypeClass_SEQUENCE:
     391             :     {
     392           0 :         Sequence< OUString > aStringValues;
     393           0 :         Sequence< sal_Int8 > aInt8Values;
     394           0 :         Sequence< sal_uInt16 > aUInt16Values;
     395           0 :         Sequence< sal_Int16 > aInt16Values;
     396           0 :         Sequence< sal_uInt32 > aUInt32Values;
     397           0 :         Sequence< sal_Int32 > aInt32Values;
     398             : 
     399             :         // string sequences
     400           0 :         if ( _rValue >>= aStringValues )
     401             :         {
     402           0 :             _rStringRep = composeSequenceElements( aStringValues, StringIdentity() );
     403             :         }
     404             :         // byte sequences
     405           0 :         else if ( _rValue >>= aInt8Values )
     406             :         {
     407           0 :             _rStringRep = composeSequenceElements( aInt8Values, ConvertIntegerFromAndToString() );
     408             :         }
     409             :         // uInt16 sequences
     410           0 :         else if ( _rValue >>= aUInt16Values )
     411             :         {
     412           0 :             _rStringRep = composeSequenceElements( aUInt16Values, ConvertIntegerFromAndToString() );
     413             :         }
     414             :         // Int16 sequences
     415           0 :         else if ( _rValue >>= aInt16Values )
     416             :         {
     417           0 :             _rStringRep = composeSequenceElements( aInt16Values, ConvertIntegerFromAndToString() );
     418             :         }
     419             :         // uInt32 sequences
     420           0 :         else if ( _rValue >>= aUInt32Values )
     421             :         {
     422           0 :             _rStringRep = composeSequenceElements( aUInt32Values, ConvertIntegerFromAndToString() );
     423             :         }
     424             :         // Int32 sequences
     425           0 :         else if ( _rValue >>= aInt32Values )
     426             :         {
     427           0 :             _rStringRep = composeSequenceElements( aInt32Values, ConvertIntegerFromAndToString() );
     428             :         }
     429             :         else
     430           0 :             bCanConvert = false;
     431             :     }
     432           0 :     break;
     433             :     case uno::TypeClass_CONSTANT:
     434             :         {
     435           0 :             int i = 0;
     436           0 :             ++i;
     437             :         }
     438           0 :         break;
     439             : 
     440             :     // some structs
     441             :     case uno::TypeClass_STRUCT:
     442             :         OSL_FAIL( "StringRepresentation::convertGenericValueToString(STRUCT): this is dead code - isn't it?" );
     443           0 :         if ( _rValue.getValueType().equals( cppu::UnoType< util::Date >::get() ))
     444             :         {
     445             :             // weird enough, the string representation of dates, as used
     446             :             // by the control displaying dates, and thus as passed through the layers,
     447             :             // is YYYYMMDD.
     448           0 :             util::Date aUnoDate;
     449           0 :             _rValue >>= aUnoDate;
     450           0 :             _rStringRep = ::dbtools::DBTypeConversion::toDateString(aUnoDate);
     451             :         }
     452           0 :         else if ( _rValue.getValueType().equals( cppu::UnoType< util::Time >::get() ))
     453             :         {
     454             :             // similar for time (HHMMSSHH)
     455           0 :             util::Time aUnoTime;
     456           0 :             _rValue >>= aUnoTime;
     457           0 :             _rStringRep = ::dbtools::DBTypeConversion::toTimeString(aUnoTime);
     458             :         }
     459           0 :         else if ( _rValue.getValueType().equals( cppu::UnoType< util::DateTime >::get() ))
     460             :         {
     461           0 :             util::DateTime aUnoDateTime;
     462           0 :             _rValue >>= aUnoDateTime;
     463           0 :             _rStringRep = ::dbtools::DBTypeConversion::toDateTimeString(aUnoDateTime);
     464             :         }
     465             :         else
     466           0 :             bCanConvert = false;
     467           0 :         break;
     468             : 
     469             :     default:
     470           0 :         bCanConvert = false;
     471           0 :         break;
     472             :     }
     473             : 
     474           0 :     return bCanConvert;
     475             : }
     476             : 
     477           0 : uno::Any StringRepresentation::convertStringToSimple( const OUString& _rValue,const uno::TypeClass& _ePropertyType )
     478             : {
     479           0 :     uno::Any aReturn;
     480           0 :     if ( m_xTypeConverter.is() && !_rValue.isEmpty() )
     481             :     {
     482             :         try
     483             :         {
     484           0 :             if ( m_aConstants.getLength() && m_aValues.getLength() )
     485             :             {
     486           0 :                 const OUString* pIter = m_aValues.getConstArray();
     487           0 :                 const OUString* pEnd   = pIter + m_aValues.getLength();
     488           0 :                 for(sal_Int32 i = 0;pIter != pEnd;++pIter,++i)
     489             :                 {
     490           0 :                     if ( *pIter == _rValue )
     491             :                     {
     492             :                         OSL_ENSURE(i < m_aConstants.getLength() ,"StringRepresentation::convertSimpleToString: Index is not in range of m_aValues");
     493           0 :                         aReturn <<= m_aConstants[i]->getConstantValue();
     494           0 :                         break;
     495             :                     }
     496             :                 }
     497             :             }
     498             : 
     499           0 :             if ( !aReturn.hasValue() )
     500           0 :                 aReturn = m_xTypeConverter->convertToSimpleType( makeAny( _rValue ), _ePropertyType );
     501             :         }
     502           0 :         catch( const script::CannotConvertException& ) { }
     503           0 :         catch( const lang::IllegalArgumentException& ) { }
     504             :     }
     505           0 :     return aReturn;
     506             : }
     507             : 
     508           0 : bool StringRepresentation::convertStringToGenericValue( const OUString& _rStringRep, uno::Any& _rValue, const uno::Type& _rTargetType )
     509             : {
     510           0 :     bool bCanConvert = true;
     511             : 
     512           0 :     switch ( _rTargetType.getTypeClass() )
     513             :     {
     514             :     case uno::TypeClass_STRING:
     515           0 :         _rValue <<= _rStringRep;
     516           0 :         break;
     517             : 
     518             :     case uno::TypeClass_BOOLEAN:
     519             :     {
     520           0 :         ::std::vector< OUString > aListEntries;
     521           0 :         tools::StringListResource aRes(PcrRes(RID_RSC_ENUM_YESNO),aListEntries);
     522           0 :         _rValue <<= aListEntries[0] != _rStringRep;
     523             :     }
     524           0 :     break;
     525             : 
     526             :     case uno::TypeClass_SEQUENCE:
     527             :     {
     528           0 :         uno::Type aElementType = ::comphelper::getSequenceElementType( _rTargetType );
     529             : 
     530           0 :         OUString aStr( _rStringRep );
     531           0 :         switch ( aElementType.getTypeClass() )
     532             :         {
     533             :             case uno::TypeClass_STRING:
     534             :             {
     535           0 :                 Sequence< OUString > aElements;
     536           0 :                 splitComposedStringToSequence( aStr, aElements, StringIdentity() );
     537           0 :                 _rValue <<= aElements;
     538             :             }
     539           0 :             break;
     540             :             case uno::TypeClass_SHORT:
     541             :             {
     542           0 :                 Sequence< sal_Int16 > aElements;
     543           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     544           0 :                 _rValue <<= aElements;
     545             :             }
     546           0 :             break;
     547             :             case uno::TypeClass_UNSIGNED_SHORT:
     548             :             {
     549           0 :                 Sequence< sal_uInt16 > aElements;
     550           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     551           0 :                 _rValue <<= aElements;
     552             :             }
     553           0 :             break;
     554             :             case uno::TypeClass_LONG:
     555             :             {
     556           0 :                 Sequence< sal_Int32 > aElements;
     557           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     558           0 :                 _rValue <<= aElements;
     559             :             }
     560           0 :             break;
     561             :             case uno::TypeClass_UNSIGNED_LONG:
     562             :             {
     563           0 :                 Sequence< sal_uInt32 > aElements;
     564           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     565           0 :                 _rValue <<= aElements;
     566             :             }
     567           0 :             break;
     568             :             case uno::TypeClass_BYTE:
     569             :             {
     570           0 :                 Sequence< sal_Int8 > aElements;
     571           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     572           0 :                 _rValue <<= aElements;
     573             :             }
     574           0 :             break;
     575             :             default:
     576           0 :                 bCanConvert = false;
     577           0 :                 break;
     578           0 :         }
     579             :     }
     580           0 :     break;
     581             : 
     582             :     case uno::TypeClass_STRUCT:
     583             :         OSL_FAIL( "StringRepresentation::convertStringToGenericValue(STRUCT): this is dead code - isn't it?" );
     584           0 :         if ( _rTargetType.equals( cppu::UnoType< util::Date >::get() ))
     585             :         {
     586             :             // weird enough, the string representation of dates, as used
     587             :             // by the control displaying dates, and thus as passed through the layers,
     588             :             // is YYYYMMDD.
     589             : 
     590           0 :             _rValue <<= ::dbtools::DBTypeConversion::toDate(_rStringRep);
     591             :         }
     592           0 :         else if ( _rTargetType.equals( cppu::UnoType< util::Time >::get() ))
     593             :         {
     594             :             // similar for time (HHMMSSHH)
     595           0 :             _rValue <<= ::dbtools::DBTypeConversion::toTime(_rStringRep);
     596             :         }
     597           0 :         else if ( _rTargetType.equals( cppu::UnoType< util::DateTime >::get() ))
     598             :         {
     599           0 :             _rValue <<= ::dbtools::DBTypeConversion::toDateTime(_rStringRep);
     600             :         }
     601             :         else
     602           0 :             bCanConvert = false;
     603           0 :         break;
     604             : 
     605             :     default:
     606           0 :         bCanConvert = false;
     607           0 :         break;
     608             :     }
     609             : 
     610           0 :     return bCanConvert;
     611             : }
     612             : 
     613             : 
     614             : } // pcr
     615             : 
     616             : 
     617             : 
     618             : // component helper namespace
     619             : namespace comp_StringRepresentation {
     620             : 
     621           2 : OUString SAL_CALL _getImplementationName() {
     622             :     return OUString(
     623           2 :         "StringRepresentation");
     624             : }
     625             : 
     626           2 : uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames()
     627             : {
     628           2 :     uno::Sequence< OUString > s(1);
     629           2 :     s[0] = "com.sun.star.inspection.StringRepresentation";
     630           2 :     return s;
     631             : }
     632             : 
     633           0 : uno::Reference< uno::XInterface > SAL_CALL _create(
     634             :     const uno::Reference< uno::XComponentContext > & context)
     635             : {
     636           0 :     return static_cast< ::cppu::OWeakObject * >(new pcr::StringRepresentation(context));
     637             : }
     638             : 
     639             : } // closing component helper namespace
     640             : 
     641             : 
     642           2 : extern "C" void SAL_CALL createRegistryInfo_StringRepresentation()
     643             : {
     644           2 :     ::pcr::PcrModule::getInstance().registerImplementation(
     645             :             comp_StringRepresentation::_getImplementationName(),
     646             :             comp_StringRepresentation::_getSupportedServiceNames(),
     647             :             comp_StringRepresentation::_create
     648           4 :         );
     649           2 : }
     650             : 
     651             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11