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

Generated by: LCOV version 1.10