LCOV - code coverage report
Current view: top level - xmloff/source/forms - propertyimport.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 219 0.0 %
Date: 2014-04-14 Functions: 0 21 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 "propertyimport.hxx"
      21             : 
      22             : #include <sax/tools/converter.hxx>
      23             : 
      24             : #include <xmloff/xmlimp.hxx>
      25             : #include <xmloff/xmluconv.hxx>
      26             : #include <xmloff/nmspmap.hxx>
      27             : #include <osl/diagnose.h>
      28             : #include <comphelper/extract.hxx>
      29             : #include "callbacks.hxx"
      30             : #include <xmloff/xmlnmspe.hxx>
      31             : #include <tools/date.hxx>
      32             : #include <tools/time.hxx>
      33             : #include <com/sun/star/util/Date.hpp>
      34             : #include <com/sun/star/util/Time.hpp>
      35             : #include <com/sun/star/util/DateTime.hpp>
      36             : #include <unotools/datetime.hxx>
      37             : #include <rtl/strbuf.hxx>
      38             : 
      39             : #if OSL_DEBUG_LEVEL > 0
      40             :     #include <osl/thread.h>
      41             : #endif
      42             : 
      43             : namespace xmloff
      44             : {
      45             : 
      46             :     using namespace ::com::sun::star::uno;
      47             :     using namespace ::com::sun::star::beans;
      48             :     using namespace ::com::sun::star::xml;
      49             :     using ::com::sun::star::xml::sax::XAttributeList;
      50             : 
      51             :     // NO using namespace ...util !!!
      52             :     // need a tools Date/Time/DateTime below, which would conflict with the uno types then
      53             : 
      54             : #define TYPE_DATE       1
      55             : #define TYPE_TIME       2
      56             : #define TYPE_DATETIME   3
      57             : 
      58             : //= PropertyConversion
      59             : namespace
      60             : {
      61           0 :     ::com::sun::star::util::Time lcl_getTime(double _nValue)
      62             :     {
      63           0 :         ::com::sun::star::util::Time aTime;
      64           0 :         sal_uInt64 nIntValue = static_cast<sal_uInt64>(_nValue * ::Time::nanoSecPerDay);
      65           0 :         aTime.NanoSeconds = nIntValue % ::Time::nanoSecPerSec;
      66           0 :         nIntValue /= ::Time::nanoSecPerSec;
      67           0 :         aTime.Seconds = nIntValue % ::Time::secondPerMinute;
      68           0 :         nIntValue /= ::Time::secondPerMinute;
      69           0 :         aTime.Minutes = nIntValue % ::Time::minutePerHour;
      70           0 :         nIntValue /= ::Time::minutePerHour;
      71             :         OSL_ENSURE(nIntValue < 24, "lcl_getTime: more than a day?");
      72           0 :         aTime.Hours = nIntValue;
      73             : 
      74           0 :         return aTime;
      75             :     }
      76             : 
      77           0 :     static ::com::sun::star::util::Date lcl_getDate( double _nValue )
      78             :     {
      79           0 :         Date aToolsDate((sal_uInt32)_nValue);
      80           0 :         ::com::sun::star::util::Date aDate;
      81           0 :         ::utl::typeConvert(aToolsDate, aDate);
      82           0 :         return aDate;
      83             :     }
      84             : }
      85             : 
      86           0 : Any PropertyConversion::convertString( SvXMLImport& _rImporter, const ::com::sun::star::uno::Type& _rExpectedType,
      87             :     const OUString& _rReadCharacters, const SvXMLEnumMapEntry* _pEnumMap, const sal_Bool _bInvertBoolean )
      88             : {
      89           0 :     Any aReturn;
      90           0 :     sal_Bool bEnumAsInt = sal_False;
      91           0 :     switch (_rExpectedType.getTypeClass())
      92             :     {
      93             :         case TypeClass_BOOLEAN:     // sal_Bool
      94             :         {
      95             :             bool bValue;
      96             :         #if OSL_DEBUG_LEVEL > 0
      97             :             sal_Bool bSuccess =
      98             :         #endif
      99           0 :             ::sax::Converter::convertBool(bValue, _rReadCharacters);
     100             :             OSL_ENSURE(bSuccess,
     101             :                     OStringBuffer("PropertyConversion::convertString: could not convert \"").
     102             :                 append(OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US)).
     103             :                 append("\" into a boolean!").getStr());
     104           0 :             aReturn <<= (_bInvertBoolean ? !bValue : bValue);
     105             :         }
     106           0 :         break;
     107             :         case TypeClass_SHORT:       // sal_Int16
     108             :         case TypeClass_LONG:        // sal_Int32
     109           0 :             if (!_pEnumMap)
     110             :             {   // it's a real int32/16 property
     111           0 :                 sal_Int32 nValue(0);
     112             :         #if OSL_DEBUG_LEVEL > 0
     113             :                 sal_Bool bSuccess =
     114             :         #endif
     115           0 :                 ::sax::Converter::convertNumber(nValue, _rReadCharacters);
     116             :                 OSL_ENSURE(bSuccess,
     117             :                         OStringBuffer("PropertyConversion::convertString: could not convert \"").
     118             :                     append(OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US)).
     119             :                     append("\" into an integer!").getStr());
     120           0 :                 if (TypeClass_SHORT == _rExpectedType.getTypeClass())
     121           0 :                     aReturn <<= (sal_Int16)nValue;
     122             :                 else
     123           0 :                     aReturn <<= (sal_Int32)nValue;
     124           0 :                 break;
     125             :             }
     126           0 :             bEnumAsInt = sal_True;
     127             :             // NO BREAK! handle it as enum
     128             :         case TypeClass_ENUM:
     129             :         {
     130           0 :             sal_uInt16 nEnumValue(0);
     131             :         #if OSL_DEBUG_LEVEL > 0
     132             :             sal_Bool bSuccess =
     133             :         #endif
     134           0 :             _rImporter.GetMM100UnitConverter().convertEnum(nEnumValue, _rReadCharacters, _pEnumMap);
     135             :             OSL_ENSURE(bSuccess, "PropertyConversion::convertString: could not convert to an enum value!");
     136           0 :             if (bEnumAsInt)
     137           0 :                 if (TypeClass_SHORT == _rExpectedType.getTypeClass())
     138           0 :                     aReturn <<= (sal_Int16)nEnumValue;
     139             :                 else
     140           0 :                     aReturn <<= (sal_Int32)nEnumValue;
     141             :             else
     142           0 :                 aReturn = ::cppu::int2enum((sal_Int32)nEnumValue, _rExpectedType);
     143             :         }
     144           0 :         break;
     145             :         case TypeClass_HYPER:
     146             :         {
     147             :             OSL_FAIL("PropertyConversion::convertString: 64-bit integers not implemented yet!");
     148             :         }
     149           0 :         break;
     150             :         case TypeClass_DOUBLE:
     151             :         {
     152             :             double nValue;
     153             :         #if OSL_DEBUG_LEVEL > 0
     154             :             sal_Bool bSuccess =
     155             :         #endif
     156           0 :             ::sax::Converter::convertDouble(nValue, _rReadCharacters);
     157             :             OSL_ENSURE(bSuccess,
     158             :                     OStringBuffer("PropertyConversion::convertString: could not convert \"").
     159             :                 append(OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US)).
     160             :                 append("\" into a double!").getStr());
     161           0 :             aReturn <<= (double)nValue;
     162             :         }
     163           0 :         break;
     164             :         case TypeClass_STRING:
     165           0 :             aReturn <<= _rReadCharacters;
     166           0 :             break;
     167             :         case TypeClass_STRUCT:
     168             :         {
     169           0 :             sal_Int32 nType = 0;
     170           0 :             if ( _rExpectedType.equals( ::cppu::UnoType< ::com::sun::star::util::Date >::get() ) )
     171           0 :                 nType = TYPE_DATE;
     172           0 :             else if ( _rExpectedType.equals( ::cppu::UnoType< ::com::sun::star::util::Time >::get() ) )
     173           0 :                 nType = TYPE_TIME;
     174           0 :             else  if ( _rExpectedType.equals( ::cppu::UnoType< ::com::sun::star::util::DateTime >::get() ) )
     175           0 :                 nType = TYPE_DATETIME;
     176             : 
     177           0 :             if ( nType )
     178             :             {
     179             :                 // first extract the double
     180           0 :                 double nValue = 0;
     181             :             #if OSL_DEBUG_LEVEL > 0
     182             :                 sal_Bool bSuccess =
     183             :             #endif
     184           0 :                 ::sax::Converter::convertDouble(nValue, _rReadCharacters);
     185             :                 OSL_ENSURE(bSuccess,
     186             :                         OStringBuffer("PropertyConversion::convertString: could not convert \"").
     187             :                     append(OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US)).
     188             :                     append("\" into a double!").getStr());
     189             : 
     190             :                 // then convert it into the target type
     191           0 :                 switch (nType)
     192             :                 {
     193             :                     case TYPE_DATE:
     194             :                     {
     195             :                         OSL_ENSURE(((sal_uInt32)nValue) - nValue == 0,
     196             :                             "PropertyConversion::convertString: a Date value with a fractional part?");
     197           0 :                         aReturn <<= lcl_getDate(nValue);
     198             :                     }
     199           0 :                     break;
     200             :                     case TYPE_TIME:
     201             :                     {
     202             :                         OSL_ENSURE(((sal_uInt32)nValue) == 0,
     203             :                             "PropertyConversion::convertString: a Time value with more than a fractional part?");
     204           0 :                         aReturn <<= lcl_getTime(nValue);
     205             :                     }
     206           0 :                     break;
     207             :                     case TYPE_DATETIME:
     208             :                     {
     209           0 :                         ::com::sun::star::util::Time aTime = lcl_getTime(nValue);
     210           0 :                         ::com::sun::star::util::Date aDate = lcl_getDate(nValue);
     211             : 
     212           0 :                         ::com::sun::star::util::DateTime aDateTime;
     213           0 :                         aDateTime.NanoSeconds = aTime.NanoSeconds;
     214           0 :                         aDateTime.Seconds = aTime.Seconds;
     215           0 :                         aDateTime.Minutes = aTime.Minutes;
     216           0 :                         aDateTime.Hours = aTime.Hours;
     217           0 :                         aDateTime.Day = aDate.Day;
     218           0 :                         aDateTime.Month = aDate.Month;
     219           0 :                         aDateTime.Year = aDate.Year;
     220           0 :                         aReturn <<= aDateTime;
     221             :                     }
     222           0 :                     break;
     223             :                 }
     224             :             }
     225             :             else
     226             :                 OSL_FAIL("PropertyConversion::convertString: unsupported property type!");
     227             :         }
     228           0 :         break;
     229             :         default:
     230             :             OSL_FAIL("PropertyConversion::convertString: invalid type class!");
     231             :     }
     232             : 
     233           0 :     return aReturn;
     234             : }
     235             : 
     236           0 : Type PropertyConversion::xmlTypeToUnoType( const OUString& _rType )
     237             : {
     238           0 :     Type aUnoType( ::getVoidCppuType() );
     239             : 
     240           0 :     static std::map< OUString, css::uno::Type > s_aTypeNameMap;
     241           0 :     if ( s_aTypeNameMap.empty() )
     242             :     {
     243           0 :         s_aTypeNameMap[ token::GetXMLToken( token::XML_BOOLEAN ) ] = ::getBooleanCppuType();
     244           0 :         s_aTypeNameMap[ token::GetXMLToken( token::XML_FLOAT )   ] = ::getCppuType( static_cast< double* >(NULL) );
     245           0 :         s_aTypeNameMap[ token::GetXMLToken( token::XML_STRING )  ] = ::getCppuType( static_cast< OUString* >(NULL) );
     246           0 :         s_aTypeNameMap[ token::GetXMLToken( token::XML_VOID )    ] = ::getVoidCppuType();
     247             :     }
     248             : 
     249           0 :     const std::map< OUString, css::uno::Type >::iterator aTypePos = s_aTypeNameMap.find( _rType );
     250             :     OSL_ENSURE( s_aTypeNameMap.end() != aTypePos, "PropertyConversion::xmlTypeToUnoType: invalid property name!" );
     251           0 :     if ( s_aTypeNameMap.end() != aTypePos )
     252           0 :         aUnoType = aTypePos->second;
     253             : 
     254           0 :     return aUnoType;
     255             : }
     256             : 
     257             : //= OPropertyImport
     258           0 : OPropertyImport::OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const OUString& _rName)
     259           0 :     :SvXMLImportContext(_rImport.getGlobalContext(), _nPrefix, _rName)
     260             :     ,m_rContext(_rImport)
     261           0 :     ,m_bTrackAttributes(sal_False)
     262             : {
     263           0 : }
     264             : 
     265           0 : SvXMLImportContext* OPropertyImport::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
     266             :     const Reference< XAttributeList >& _rxAttrList)
     267             : {
     268           0 :     if( token::IsXMLToken( _rLocalName, token::XML_PROPERTIES) )
     269             :     {
     270           0 :         return new OPropertyElementsContext( m_rContext.getGlobalContext(),
     271           0 :                                              _nPrefix, _rLocalName, this);
     272             :     }
     273             :     else
     274             :     {
     275             :         OSL_FAIL(OStringBuffer("OPropertyImport::CreateChildContext: unknown sub element (only \"properties\" is recognized, but it is ").
     276             :             append(OUStringToOString(_rLocalName, RTL_TEXTENCODING_ASCII_US)).
     277             :             append(")!").getStr());
     278           0 :         return SvXMLImportContext::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
     279             :     }
     280             : }
     281             : 
     282           0 : void OPropertyImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
     283             : {
     284             :     OSL_ENSURE(_rxAttrList.is(), "OPropertyImport::StartElement: invalid attribute list!");
     285           0 :     const sal_Int32 nAttributeCount = _rxAttrList->getLength();
     286             : 
     287             :     // assume the 'worst' case: all attributes describe properties. This should save our property array
     288             :     // some reallocs
     289           0 :     m_aValues.reserve(nAttributeCount);
     290             : 
     291           0 :     const SvXMLNamespaceMap& rMap = m_rContext.getGlobalContext().GetNamespaceMap();
     292             :     sal_uInt16 nNamespace;
     293           0 :     OUString sLocalName;
     294           0 :     for (sal_Int16 i=0; i<nAttributeCount; ++i)
     295             :     {
     296           0 :         nNamespace = rMap.GetKeyByAttrName(_rxAttrList->getNameByIndex(i), &sLocalName);
     297           0 :         handleAttribute(nNamespace, sLocalName, _rxAttrList->getValueByIndex(i));
     298             : 
     299           0 :         if (m_bTrackAttributes)
     300           0 :             m_aEncounteredAttributes.insert(sLocalName);
     301           0 :     }
     302             : 
     303             :     // TODO: create PropertyValues for all the attributes which were not present, because they were implied
     304             :     // this is necessary as soon as we have properties where the XML default is different from the property
     305             :     // default
     306           0 : }
     307             : 
     308           0 : sal_Bool OPropertyImport::encounteredAttribute(const OUString& _rAttributeName) const
     309             : {
     310             :     OSL_ENSURE(m_bTrackAttributes, "OPropertyImport::encounteredAttribute: attribute tracking not enabled!");
     311           0 :     return m_aEncounteredAttributes.end() != m_aEncounteredAttributes.find(_rAttributeName);
     312             : }
     313             : 
     314           0 : void OPropertyImport::Characters(const OUString&
     315             : #if OSL_DEBUG_LEVEL > 0
     316             : _rChars
     317             : #endif
     318             : )
     319             : {
     320             :     // ignore them (should be whitespaces only)
     321             :     OSL_ENSURE(_rChars.trim().isEmpty(), "OPropertyImport::Characters: non-whitespace characters!");
     322           0 : }
     323             : 
     324           0 : bool OPropertyImport::handleAttribute(sal_uInt16 /*_nNamespaceKey*/, const OUString& _rLocalName, const OUString& _rValue)
     325             : {
     326           0 :     const OAttribute2Property::AttributeAssignment* pProperty = m_rContext.getAttributeMap().getAttributeTranslation(_rLocalName);
     327           0 :     if (pProperty)
     328             :     {
     329             :         // create and store a new PropertyValue
     330           0 :         PropertyValue aNewValue;
     331           0 :         aNewValue.Name = pProperty->sPropertyName;
     332             : 
     333             :         // convert the value string into the target type
     334           0 :         aNewValue.Value = PropertyConversion::convertString(m_rContext.getGlobalContext(), pProperty->aPropertyType, _rValue, pProperty->pEnumMap, pProperty->bInverseSemantics);
     335           0 :         implPushBackPropertyValue( aNewValue );
     336           0 :         return true;
     337             :     }
     338           0 :     if (!token::IsXMLToken(_rLocalName, token::XML_TYPE))  // xlink:type is valid but ignored for <form:form>
     339             :     {
     340             : #if OSL_DEBUG_LEVEL > 0
     341             :         OString sMessage( "OPropertyImport::handleAttribute: Can't handle the following:\n" );
     342             :         sMessage += OString( "  Attribute name: " );
     343             :         sMessage += OString( _rLocalName.getStr(), _rLocalName.getLength(), osl_getThreadTextEncoding() );
     344             :         sMessage += OString( "\n  value: " );
     345             :         sMessage += OString( _rValue.getStr(), _rValue.getLength(), osl_getThreadTextEncoding() );
     346             :         OSL_FAIL( sMessage.getStr() );
     347             : #endif
     348           0 :         return false;
     349             :     }
     350           0 :     return true;
     351             : }
     352             : 
     353             : //= OPropertyElementsContext
     354           0 : OPropertyElementsContext::OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
     355             :         const OPropertyImportRef& _rPropertyImporter)
     356             :     :SvXMLImportContext(_rImport, _nPrefix, _rName)
     357           0 :     ,m_xPropertyImporter(_rPropertyImporter)
     358             : {
     359           0 : }
     360             : 
     361           0 : SvXMLImportContext* OPropertyElementsContext::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
     362             :     const Reference< XAttributeList >&)
     363             : {
     364           0 :     if( token::IsXMLToken( _rLocalName, token::XML_PROPERTY ) )
     365             :     {
     366           0 :         return new OSinglePropertyContext(GetImport(), _nPrefix, _rLocalName, m_xPropertyImporter);
     367             :     }
     368           0 :     else if( token::IsXMLToken( _rLocalName, token::XML_LIST_PROPERTY ) )
     369             :     {
     370           0 :         return new OListPropertyContext( GetImport(), _nPrefix, _rLocalName, m_xPropertyImporter );
     371             :     }
     372             :     else
     373             :     {
     374             :         OSL_FAIL(OStringBuffer("OPropertyElementsContext::CreateChildContext: unknown child element (\"").
     375             :             append(OUStringToOString(_rLocalName, RTL_TEXTENCODING_ASCII_US)).
     376             :             append("\")!").getStr());
     377           0 :         return new SvXMLImportContext(GetImport(), _nPrefix, _rLocalName);
     378             :     }
     379             : }
     380             : 
     381             : #if OSL_DEBUG_LEVEL > 0
     382             :     void OPropertyElementsContext::StartElement(const Reference< XAttributeList >& _rxAttrList)
     383             :     {
     384             :         OSL_ENSURE(0 == _rxAttrList->getLength(), "OPropertyElementsContext::StartElement: the form:properties element should not have attributes!");
     385             :         SvXMLImportContext::StartElement(_rxAttrList);
     386             :     }
     387             : 
     388             :     void OPropertyElementsContext::Characters(const OUString& _rChars)
     389             :     {
     390             :         OSL_ENSURE(0 == _rChars.trim(), "OPropertyElementsContext::Characters: non-whitespace characters detected!");
     391             :         SvXMLImportContext::Characters(_rChars);
     392             :     }
     393             : 
     394             : #endif
     395             : 
     396             : //= OSinglePropertyContext
     397           0 : OSinglePropertyContext::OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
     398             :         const OPropertyImportRef& _rPropertyImporter)
     399             :     :SvXMLImportContext(_rImport, _nPrefix, _rName)
     400           0 :     ,m_xPropertyImporter(_rPropertyImporter)
     401             : {
     402           0 : }
     403             : 
     404           0 : SvXMLImportContext* OSinglePropertyContext::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
     405             :         const Reference< XAttributeList >&)
     406             : {
     407             :     OSL_FAIL(OStringBuffer("OSinglePropertyContext::CreateChildContext: unknown child element (\"").
     408             :         append(OUStringToOString(_rLocalName, RTL_TEXTENCODING_ASCII_US)).
     409             :         append("\")!").getStr());
     410           0 :     return new SvXMLImportContext(GetImport(), _nPrefix, _rLocalName);
     411             : }
     412             : 
     413           0 : void OSinglePropertyContext::StartElement(const Reference< XAttributeList >& _rxAttrList)
     414             : {
     415           0 :     ::com::sun::star::beans::PropertyValue aPropValue;      // the property the instance imports currently
     416           0 :     ::com::sun::star::uno::Type aPropType;          // the type of the property the instance imports currently
     417             : 
     418           0 :     OUString sType, sValue;
     419           0 :     const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
     420           0 :     const sal_Int16 nAttrCount = _rxAttrList.is() ? _rxAttrList->getLength() : 0;
     421           0 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     422             :     {
     423           0 :         const OUString& rAttrName = _rxAttrList->getNameByIndex( i );
     424             : 
     425           0 :         OUString aLocalName;
     426             :         sal_uInt16 nPrefix =
     427             :             rMap.GetKeyByAttrName( rAttrName,
     428           0 :                                                             &aLocalName );
     429           0 :         if( XML_NAMESPACE_FORM == nPrefix )
     430             :         {
     431           0 :             if( token::IsXMLToken( aLocalName, token::XML_PROPERTY_NAME ) )
     432           0 :                 aPropValue.Name = _rxAttrList->getValueByIndex( i );
     433             : 
     434             :         }
     435           0 :         else if( XML_NAMESPACE_OFFICE == nPrefix )
     436             :         {
     437           0 :             if( token::IsXMLToken( aLocalName, token::XML_VALUE_TYPE ) )
     438           0 :                 sType = _rxAttrList->getValueByIndex( i );
     439           0 :             else if( token::IsXMLToken( aLocalName,
     440           0 :                                         token::XML_VALUE ) ||
     441             :                         token::IsXMLToken( aLocalName,
     442           0 :                                         token::XML_BOOLEAN_VALUE ) ||
     443             :                      token::IsXMLToken( aLocalName,
     444           0 :                                         token::XML_STRING_VALUE ) )
     445           0 :                 sValue = _rxAttrList->getValueByIndex( i );
     446             :         }
     447           0 :     }
     448             : 
     449             :     // the name of the property
     450             :     OSL_ENSURE(!aPropValue.Name.isEmpty(), "OSinglePropertyContext::StartElement: invalid property name!");
     451             : 
     452             :     // needs to be translated into a ::com::sun::star::uno::Type
     453           0 :     aPropType = PropertyConversion::xmlTypeToUnoType( sType );
     454           0 :     if( TypeClass_VOID == aPropType.getTypeClass() )
     455             :     {
     456           0 :         aPropValue.Value = Any();
     457             :     }
     458             :     else
     459             :     {
     460           0 :         aPropValue.Value =
     461           0 :             PropertyConversion::convertString(GetImport(), aPropType,
     462           0 :                                            sValue);
     463             :     }
     464             : 
     465             :     // now that we finally have our property value, add it to our parent object
     466           0 :     if( !aPropValue.Name.isEmpty() )
     467           0 :         m_xPropertyImporter->implPushBackGenericPropertyValue(aPropValue);
     468           0 : }
     469             : 
     470             : //= OListPropertyContext
     471           0 : OListPropertyContext::OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
     472             :     const OPropertyImportRef& _rPropertyImporter )
     473             :     :SvXMLImportContext( _rImport, _nPrefix, _rName )
     474           0 :     ,m_xPropertyImporter( _rPropertyImporter )
     475             : {
     476           0 : }
     477             : 
     478           0 : void OListPropertyContext::StartElement( const Reference< XAttributeList >& _rxAttrList )
     479             : {
     480           0 :     sal_Int32 nAttributeCount = _rxAttrList->getLength();
     481             : 
     482             :     sal_uInt16 nNamespace;
     483           0 :     OUString sAttributeName;
     484           0 :     const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
     485           0 :     for ( sal_Int16 i = 0; i < nAttributeCount; ++i )
     486             :     {
     487           0 :         nNamespace = rMap.GetKeyByAttrName( _rxAttrList->getNameByIndex( i ), &sAttributeName );
     488           0 :         if  (   ( XML_NAMESPACE_FORM == nNamespace )
     489           0 :             &&  ( token::IsXMLToken( sAttributeName, token::XML_PROPERTY_NAME ) )
     490             :             )
     491             :         {
     492           0 :             m_sPropertyName = _rxAttrList->getValueByIndex( i );
     493             :         }
     494           0 :         else if (   ( XML_NAMESPACE_OFFICE == nNamespace )
     495           0 :                 &&  ( token::IsXMLToken( sAttributeName, token::XML_VALUE_TYPE ) )
     496             :                 )
     497             :         {
     498           0 :             m_sPropertyType = _rxAttrList->getValueByIndex( i );
     499             :         }
     500             :         else
     501             :         {
     502             :             OSL_FAIL( OStringBuffer( "OListPropertyContext::StartElement: unknown child element (\"").
     503             :                 append(OUStringToOString(sAttributeName, RTL_TEXTENCODING_ASCII_US)).
     504             :                 append("\")!").getStr() );
     505             :         }
     506           0 :     }
     507           0 : }
     508             : 
     509           0 : void OListPropertyContext::EndElement()
     510             : {
     511             :     OSL_ENSURE( !m_sPropertyName.isEmpty() && !m_sPropertyType.isEmpty(),
     512             :         "OListPropertyContext::EndElement: no property name or type!" );
     513             : 
     514           0 :     if ( m_sPropertyName.isEmpty() || m_sPropertyType.isEmpty() )
     515           0 :         return;
     516             : 
     517           0 :     Sequence< Any > aListElements( m_aListValues.size() );
     518           0 :     Any* pListElement = aListElements.getArray();
     519           0 :     com::sun::star::uno::Type aType = PropertyConversion::xmlTypeToUnoType( m_sPropertyType );
     520           0 :     for (   ::std::vector< OUString >::const_iterator values = m_aListValues.begin();
     521           0 :             values != m_aListValues.end();
     522             :             ++values, ++pListElement
     523             :         )
     524             :     {
     525           0 :         *pListElement = PropertyConversion::convertString( GetImport(), aType, *values );
     526             :     }
     527             : 
     528           0 :     PropertyValue aSequenceValue;
     529           0 :     aSequenceValue.Name = m_sPropertyName;
     530           0 :     aSequenceValue.Value <<= aListElements;
     531             : 
     532           0 :     m_xPropertyImporter->implPushBackGenericPropertyValue( aSequenceValue );
     533             : }
     534             : 
     535           0 : SvXMLImportContext* OListPropertyContext::CreateChildContext( sal_uInt16 _nPrefix, const OUString& _rLocalName, const Reference< XAttributeList >& /*_rxAttrList*/ )
     536             : {
     537           0 :     if ( token::IsXMLToken( _rLocalName, token::XML_LIST_VALUE ) )
     538             :     {
     539           0 :         m_aListValues.resize( m_aListValues.size() + 1 );
     540           0 :         return new OListValueContext( GetImport(), _nPrefix, _rLocalName, *m_aListValues.rbegin() );
     541             :     }
     542             :     else
     543             :     {
     544             :         OSL_FAIL( OStringBuffer("OListPropertyContext::CreateChildContext: unknown child element (\"").
     545             :             append(OUStringToOString(_rLocalName.getStr(), RTL_TEXTENCODING_ASCII_US)).
     546             :             append("\")!").getStr() );
     547           0 :         return new SvXMLImportContext( GetImport(), _nPrefix, _rLocalName );
     548             :     }
     549             : }
     550             : 
     551             : //= OListValueContext
     552           0 : OListValueContext::OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName, OUString& _rListValueHolder )
     553             :     :SvXMLImportContext( _rImport, _nPrefix, _rName )
     554           0 :     ,m_rListValueHolder( _rListValueHolder )
     555             : {
     556           0 : }
     557             : 
     558           0 : void OListValueContext::StartElement( const Reference< XAttributeList >& _rxAttrList )
     559             : {
     560           0 :     const sal_Int32 nAttributeCount = _rxAttrList->getLength();
     561             : 
     562             :     sal_uInt16 nNamespace;
     563           0 :     OUString sAttributeName;
     564           0 :     const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
     565           0 :     for ( sal_Int16 i = 0; i < nAttributeCount; ++i )
     566             :     {
     567           0 :         nNamespace = rMap.GetKeyByAttrName( _rxAttrList->getNameByIndex( i ), &sAttributeName );
     568           0 :         if ( XML_NAMESPACE_OFFICE == nNamespace )
     569             :         {
     570           0 :             if  (   token::IsXMLToken( sAttributeName, token::XML_VALUE )
     571           0 :                ||   token::IsXMLToken( sAttributeName, token::XML_STRING_VALUE )
     572           0 :                ||   token::IsXMLToken( sAttributeName, token::XML_BOOLEAN_VALUE )
     573             :                 )
     574             :             {
     575           0 :                 m_rListValueHolder = _rxAttrList->getValueByIndex( i );
     576           0 :                 continue;
     577             :             }
     578             :         }
     579             : 
     580             :         OSL_FAIL( OStringBuffer( "OListValueContext::StartElement: unknown child element (\"").
     581             :             append(OUStringToOString(sAttributeName, RTL_TEXTENCODING_ASCII_US)).
     582             :             append("\")!").getStr() );
     583           0 :     }
     584           0 : }
     585             : 
     586             : }   // namespace xmloff
     587             : 
     588             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10