LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - stringrepresentation.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 218 0.0 %
Date: 2014-04-14 Functions: 0 33 0.0 %
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             : #include "cppuhelper/factory.hxx"
      22             : #include "cppuhelper/implementationentry.hxx"
      23             : #include "cppuhelper/implbase3.hxx"
      24             : #include <cppuhelper/supportsservice.hxx>
      25             : #include "com/sun/star/lang/XServiceInfo.hpp"
      26             : #include "com/sun/star/inspection/XStringRepresentation.hpp"
      27             : #include "com/sun/star/lang/XInitialization.hpp"
      28             : #include "com/sun/star/script/XTypeConverter.hpp"
      29             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      30             : #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
      31             : #include <com/sun/star/beans/XIntrospection.hpp>
      32             : #include <com/sun/star/util/DateTime.hpp>
      33             : #include <com/sun/star/util/Date.hpp>
      34             : #include <com/sun/star/util/Time.hpp>
      35             : #include <comphelper/sequenceasvector.hxx>
      36             : #include <connectivity/dbconversion.hxx>
      37             : #include "formresid.hrc"
      38             : #include <tools/debug.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             : OUString SAL_CALL _getImplementationName();
      53             : uno::Sequence< 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 OUString SAL_CALL getImplementationName() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      75             :     virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      76             :     virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      77             : 
      78             :     // inspection::XStringRepresentation:
      79             :     virtual OUString SAL_CALL convertToControlValue(const uno::Any & PropertyValue) throw (uno::RuntimeException, uno::Exception, std::exception) SAL_OVERRIDE;
      80             :     virtual uno::Any SAL_CALL convertToPropertyValue(const OUString & ControlValue, const uno::Type & ControlValueType) throw (uno::RuntimeException, uno::Exception, std::exception) SAL_OVERRIDE;
      81             : 
      82             :     // lang::XInitialization:
      83             :     virtual void SAL_CALL initialize(const uno::Sequence< uno::Any > & aArguments) throw (uno::RuntimeException, uno::Exception, std::exception) SAL_OVERRIDE;
      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             :                                 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 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             :                 comphelper::SequenceAsVector<
     266             :                     uno::Reference< reflection::XConstantTypeDescription > >
     267           0 :                     cs(m_xTypeDescription->getConstants());
     268           0 :                 std::sort(cs.begin(), cs.end(), CompareConstants());
     269           0 :                 cs >> m_aConstants;
     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 ] = (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 :         sal_Bool bValue = sal_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( ::getCppuType( static_cast< util::Date* >( NULL ) ) ) )
     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( ::getCppuType( static_cast< util::Time* >( NULL ) ) ) )
     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( ::getCppuType( static_cast< util::DateTime* >( NULL ) ) ) )
     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 :         if ( aListEntries[0] == _rStringRep )
     523           0 :             _rValue <<= (sal_Bool)sal_False;
     524             :         else
     525           0 :             _rValue <<= (sal_Bool)sal_True;
     526             :     }
     527           0 :     break;
     528             : 
     529             :     case uno::TypeClass_SEQUENCE:
     530             :     {
     531           0 :         uno::Type aElementType = ::comphelper::getSequenceElementType( _rTargetType );
     532             : 
     533           0 :         OUString aStr( _rStringRep );
     534           0 :         switch ( aElementType.getTypeClass() )
     535             :         {
     536             :             case uno::TypeClass_STRING:
     537             :             {
     538           0 :                 Sequence< OUString > aElements;
     539           0 :                 splitComposedStringToSequence( aStr, aElements, StringIdentity() );
     540           0 :                 _rValue <<= aElements;
     541             :             }
     542           0 :             break;
     543             :             case uno::TypeClass_SHORT:
     544             :             {
     545           0 :                 Sequence< sal_Int16 > aElements;
     546           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     547           0 :                 _rValue <<= aElements;
     548             :             }
     549           0 :             break;
     550             :             case uno::TypeClass_UNSIGNED_SHORT:
     551             :             {
     552           0 :                 Sequence< sal_uInt16 > aElements;
     553           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     554           0 :                 _rValue <<= aElements;
     555             :             }
     556           0 :             break;
     557             :             case uno::TypeClass_LONG:
     558             :             {
     559           0 :                 Sequence< sal_Int32 > aElements;
     560           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     561           0 :                 _rValue <<= aElements;
     562             :             }
     563           0 :             break;
     564             :             case uno::TypeClass_UNSIGNED_LONG:
     565             :             {
     566           0 :                 Sequence< sal_uInt32 > aElements;
     567           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     568           0 :                 _rValue <<= aElements;
     569             :             }
     570           0 :             break;
     571             :             case uno::TypeClass_BYTE:
     572             :             {
     573           0 :                 Sequence< sal_Int8 > aElements;
     574           0 :                 splitComposedStringToSequence( aStr, aElements, ConvertIntegerFromAndToString() );
     575           0 :                 _rValue <<= aElements;
     576             :             }
     577           0 :             break;
     578             :             default:
     579           0 :                 bCanConvert = false;
     580           0 :                 break;
     581           0 :         }
     582             :     }
     583           0 :     break;
     584             : 
     585             :     case uno::TypeClass_STRUCT:
     586             :         OSL_FAIL( "StringRepresentation::convertStringToGenericValue(STRUCT): this is dead code - isn't it?" );
     587           0 :         if ( _rTargetType.equals( ::getCppuType( static_cast< util::Date* >( NULL ) ) ) )
     588             :         {
     589             :             // weird enough, the string representation of dates, as used
     590             :             // by the control displaying dates, and thus as passed through the layers,
     591             :             // is YYYYMMDD.
     592             : 
     593           0 :             _rValue <<= ::dbtools::DBTypeConversion::toDate(_rStringRep);
     594             :         }
     595           0 :         else if ( _rTargetType.equals( ::getCppuType( static_cast< util::Time* >( NULL ) ) ) )
     596             :         {
     597             :             // similar for time (HHMMSSHH)
     598           0 :             _rValue <<= ::dbtools::DBTypeConversion::toTime(_rStringRep);
     599             :         }
     600           0 :         else if ( _rTargetType.equals( ::getCppuType( static_cast< util::DateTime* >( NULL ) ) ) )
     601             :         {
     602           0 :             _rValue <<= ::dbtools::DBTypeConversion::toDateTime(_rStringRep);
     603             :         }
     604             :         else
     605           0 :             bCanConvert = false;
     606           0 :         break;
     607             : 
     608             :     default:
     609           0 :         bCanConvert = false;
     610           0 :         break;
     611             :     }
     612             : 
     613           0 :     return bCanConvert;
     614             : }
     615             : 
     616             : 
     617             : } // pcr
     618             : 
     619             : 
     620             : 
     621             : // component helper namespace
     622             : namespace comp_StringRepresentation {
     623             : 
     624           0 : OUString SAL_CALL _getImplementationName() {
     625             :     return OUString(
     626           0 :         "StringRepresentation");
     627             : }
     628             : 
     629           0 : uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames()
     630             : {
     631           0 :     uno::Sequence< OUString > s(1);
     632           0 :     s[0] = OUString(
     633           0 :         "com.sun.star.inspection.StringRepresentation");
     634           0 :     return s;
     635             : }
     636             : 
     637           0 : uno::Reference< uno::XInterface > SAL_CALL _create(
     638             :     const uno::Reference< uno::XComponentContext > & context)
     639             :         SAL_THROW((uno::Exception))
     640             : {
     641           0 :     return static_cast< ::cppu::OWeakObject * >(new pcr::StringRepresentation(context));
     642             : }
     643             : 
     644             : } // closing component helper namespace
     645             : 
     646             : 
     647           0 : extern "C" void SAL_CALL createRegistryInfo_StringRepresentation()
     648             : {
     649           0 :     ::pcr::PcrModule::getInstance().registerImplementation(
     650             :             comp_StringRepresentation::_getImplementationName(),
     651             :             comp_StringRepresentation::_getSupportedServiceNames(),
     652             :             comp_StringRepresentation::_create
     653           0 :         );
     654           0 : }
     655             : 
     656             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10