LCOV - code coverage report
Current view: top level - xmloff/source/forms - propertyimport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 107 218 49.1 %
Date: 2014-11-03 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         330 : Any PropertyConversion::convertString( const ::com::sun::star::uno::Type& _rExpectedType,
      87             :     const OUString& _rReadCharacters, const SvXMLEnumMapEntry* _pEnumMap, const bool _bInvertBoolean )
      88             : {
      89         330 :     Any aReturn;
      90         330 :     bool bEnumAsInt = false;
      91         330 :     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          26 :             ::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          26 :             aReturn <<= (_bInvertBoolean ? !bValue : bValue);
     105             :         }
     106          26 :         break;
     107             :         case TypeClass_SHORT:       // sal_Int16
     108             :         case TypeClass_LONG:        // sal_Int32
     109          34 :             if (!_pEnumMap)
     110             :             {   // it's a real int32/16 property
     111           0 :                 sal_Int32 nValue(0);
     112             :         #if OSL_DEBUG_LEVEL > 0
     113             :                 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          34 :             bEnumAsInt = true;
     127             :             // NO BREAK! handle it as enum
     128             :         case TypeClass_ENUM:
     129             :         {
     130          34 :             sal_uInt16 nEnumValue(0);
     131          34 :             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          34 :             if (bEnumAsInt)
     136          34 :                 if (TypeClass_SHORT == _rExpectedType.getTypeClass())
     137          16 :                     aReturn <<= (sal_Int16)nEnumValue;
     138             :                 else
     139          18 :                     aReturn <<= (sal_Int32)nEnumValue;
     140             :             else
     141           0 :                 aReturn = ::cppu::int2enum((sal_Int32)nEnumValue, _rExpectedType);
     142             :         }
     143          34 :         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          10 :             ::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          10 :             aReturn <<= (double)nValue;
     161             :         }
     162          10 :         break;
     163             :         case TypeClass_STRING:
     164         260 :             aReturn <<= _rReadCharacters;
     165         260 :             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         330 :     return aReturn;
     233             : }
     234             : 
     235         124 : Type PropertyConversion::xmlTypeToUnoType( const OUString& _rType )
     236             : {
     237         124 :     Type aUnoType( ::getVoidCppuType() );
     238             : 
     239         124 :     static std::map< OUString, css::uno::Type > s_aTypeNameMap;
     240         124 :     if ( s_aTypeNameMap.empty() )
     241             :     {
     242          10 :         s_aTypeNameMap[ token::GetXMLToken( token::XML_BOOLEAN ) ] = ::getBooleanCppuType();
     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 )    ] = ::getVoidCppuType();
     251             :     }
     252             : 
     253         124 :     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         124 :     if ( s_aTypeNameMap.end() != aTypePos )
     256         124 :         aUnoType = aTypePos->second;
     257             : 
     258         124 :     return aUnoType;
     259             : }
     260             : 
     261             : //= OPropertyImport
     262          76 : OPropertyImport::OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const OUString& _rName)
     263          76 :     :SvXMLImportContext(_rImport.getGlobalContext(), _nPrefix, _rName)
     264             :     ,m_rContext(_rImport)
     265         152 :     ,m_bTrackAttributes(false)
     266             : {
     267          76 : }
     268             : 
     269          74 : SvXMLImportContext* OPropertyImport::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
     270             :     const Reference< XAttributeList >& _rxAttrList)
     271             : {
     272          74 :     if( token::IsXMLToken( _rLocalName, token::XML_PROPERTIES) )
     273             :     {
     274          74 :         return new OPropertyElementsContext( m_rContext.getGlobalContext(),
     275          74 :                                              _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          76 : void OPropertyImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
     287             : {
     288             :     OSL_ENSURE(_rxAttrList.is(), "OPropertyImport::StartElement: invalid attribute list!");
     289          76 :     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          76 :     m_aValues.reserve(nAttributeCount);
     294             : 
     295          76 :     const SvXMLNamespaceMap& rMap = m_rContext.getGlobalContext().GetNamespaceMap();
     296             :     sal_uInt16 nNamespace;
     297          76 :     OUString sLocalName;
     298         536 :     for (sal_Int16 i=0; i<nAttributeCount; ++i)
     299             :     {
     300         460 :         nNamespace = rMap.GetKeyByAttrName(_rxAttrList->getNameByIndex(i), &sLocalName);
     301         460 :         handleAttribute(nNamespace, sLocalName, _rxAttrList->getValueByIndex(i));
     302             : 
     303         460 :         if (m_bTrackAttributes)
     304         380 :             m_aEncounteredAttributes.insert(sLocalName);
     305          76 :     }
     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          76 : }
     311             : 
     312          56 : bool OPropertyImport::encounteredAttribute(const OUString& _rAttributeName) const
     313             : {
     314             :     OSL_ENSURE(m_bTrackAttributes, "OPropertyImport::encounteredAttribute: attribute tracking not enabled!");
     315          56 :     return m_aEncounteredAttributes.end() != m_aEncounteredAttributes.find(_rAttributeName);
     316             : }
     317             : 
     318          84 : 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          84 : }
     327             : 
     328         204 : bool OPropertyImport::handleAttribute(sal_uInt16 /*_nNamespaceKey*/, const OUString& _rLocalName, const OUString& _rValue)
     329             : {
     330         204 :     const OAttribute2Property::AttributeAssignment* pProperty = m_rContext.getAttributeMap().getAttributeTranslation(_rLocalName);
     331         204 :     if (pProperty)
     332             :     {
     333             :         // create and store a new PropertyValue
     334         198 :         PropertyValue aNewValue;
     335         198 :         aNewValue.Name = pProperty->sPropertyName;
     336             : 
     337             :         // convert the value string into the target type
     338         198 :         aNewValue.Value = PropertyConversion::convertString(pProperty->aPropertyType, _rValue, pProperty->pEnumMap, pProperty->bInverseSemantics);
     339         198 :         implPushBackPropertyValue( aNewValue );
     340         198 :         return true;
     341             :     }
     342           6 :     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           6 :     return true;
     355             : }
     356             : 
     357             : //= OPropertyElementsContext
     358          74 : OPropertyElementsContext::OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
     359             :         const OPropertyImportRef& _rPropertyImporter)
     360             :     :SvXMLImportContext(_rImport, _nPrefix, _rName)
     361          74 :     ,m_xPropertyImporter(_rPropertyImporter)
     362             : {
     363          74 : }
     364             : 
     365         124 : SvXMLImportContext* OPropertyElementsContext::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
     366             :     const Reference< XAttributeList >&)
     367             : {
     368         124 :     if( token::IsXMLToken( _rLocalName, token::XML_PROPERTY ) )
     369             :     {
     370         124 :         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         124 : OSinglePropertyContext::OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
     402             :         const OPropertyImportRef& _rPropertyImporter)
     403             :     :SvXMLImportContext(_rImport, _nPrefix, _rName)
     404         124 :     ,m_xPropertyImporter(_rPropertyImporter)
     405             : {
     406         124 : }
     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         124 : void OSinglePropertyContext::StartElement(const Reference< XAttributeList >& _rxAttrList)
     418             : {
     419         124 :     ::com::sun::star::beans::PropertyValue aPropValue;      // the property the instance imports currently
     420         248 :     ::com::sun::star::uno::Type aPropType;          // the type of the property the instance imports currently
     421             : 
     422         248 :     OUString sType, sValue;
     423         124 :     const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
     424         124 :     const sal_Int16 nAttrCount = _rxAttrList.is() ? _rxAttrList->getLength() : 0;
     425         486 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     426             :     {
     427         362 :         const OUString& rAttrName = _rxAttrList->getNameByIndex( i );
     428             : 
     429         724 :         OUString aLocalName;
     430             :         sal_uInt16 nPrefix =
     431             :             rMap.GetKeyByAttrName( rAttrName,
     432         362 :                                                             &aLocalName );
     433         362 :         if( XML_NAMESPACE_FORM == nPrefix )
     434             :         {
     435         124 :             if( token::IsXMLToken( aLocalName, token::XML_PROPERTY_NAME ) )
     436         124 :                 aPropValue.Name = _rxAttrList->getValueByIndex( i );
     437             : 
     438             :         }
     439         238 :         else if( XML_NAMESPACE_OFFICE == nPrefix )
     440             :         {
     441         238 :             if( token::IsXMLToken( aLocalName, token::XML_VALUE_TYPE ) )
     442         124 :                 sType = _rxAttrList->getValueByIndex( i );
     443         114 :             else if( token::IsXMLToken( aLocalName,
     444         218 :                                         token::XML_VALUE ) ||
     445             :                         token::IsXMLToken( aLocalName,
     446         212 :                                         token::XML_BOOLEAN_VALUE ) ||
     447             :                      token::IsXMLToken( aLocalName,
     448          98 :                                         token::XML_STRING_VALUE ) )
     449         114 :                 sValue = _rxAttrList->getValueByIndex( i );
     450             :         }
     451         362 :     }
     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         124 :     aPropType = PropertyConversion::xmlTypeToUnoType( sType );
     458         124 :     if( TypeClass_VOID == aPropType.getTypeClass() )
     459             :     {
     460          10 :         aPropValue.Value = Any();
     461             :     }
     462             :     else
     463             :     {
     464         228 :         aPropValue.Value =
     465             :             PropertyConversion::convertString(aPropType,
     466         114 :                                            sValue);
     467             :     }
     468             : 
     469             :     // now that we finally have our property value, add it to our parent object
     470         124 :     if( !aPropValue.Name.isEmpty() )
     471         248 :         m_xPropertyImporter->implPushBackGenericPropertyValue(aPropValue);
     472         124 : }
     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_Int16 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_Int16 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.10