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

Generated by: LCOV version 1.11