LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/forms - propertyexport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 255 0.0 %
Date: 2012-12-27 Functions: 0 23 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <stdio.h>
      22             : #include "propertyexport.hxx"
      23             : #include <xmloff/xmlexp.hxx>
      24             : #include "strings.hxx"
      25             : #include "xmloff/xmlnmspe.hxx"
      26             : #include <xmloff/xmluconv.hxx>
      27             : #include <xmloff/families.hxx>
      28             : #include <sax/tools/converter.hxx>
      29             : #include <osl/diagnose.h>
      30             : #include <rtl/strbuf.hxx>
      31             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      32             : #include <com/sun/star/util/Date.hpp>
      33             : #include <com/sun/star/util/Time.hpp>
      34             : #include <com/sun/star/util/DateTime.hpp>
      35             : #include <comphelper/extract.hxx>
      36             : #include <comphelper/sequence.hxx>
      37             : #include <comphelper/types.hxx>
      38             : #include "callbacks.hxx"
      39             : #include <unotools/datetime.hxx>
      40             : #include <tools/date.hxx>
      41             : #include <tools/datetime.hxx>
      42             : 
      43             : //.........................................................................
      44             : namespace xmloff
      45             : {
      46             : //.........................................................................
      47             : 
      48             :     using namespace ::com::sun::star::uno;
      49             :     using namespace ::com::sun::star::lang;
      50             :     using namespace ::com::sun::star::beans;
      51             : 
      52             :     // NO using namespace ...util !!!
      53             :     // need a tools Date/Time/DateTime below, which would conflict with the uno types then
      54             : 
      55             :     using namespace ::comphelper;
      56             : 
      57             :     //=====================================================================
      58             :     //= OPropertyExport
      59             :     //=====================================================================
      60             :     //---------------------------------------------------------------------
      61           0 :     OPropertyExport::OPropertyExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxProps)
      62             :         :m_rContext(_rContext)
      63             :         ,m_xProps(_rxProps)
      64           0 :         ,m_xPropertyInfo( m_xProps->getPropertySetInfo() )
      65           0 :         ,m_xPropertyState( _rxProps, UNO_QUERY )
      66             :     {
      67             :         // caching
      68           0 :         ::rtl::OUStringBuffer aBuffer;
      69           0 :         ::sax::Converter::convertBool(aBuffer, true);
      70           0 :         m_sValueTrue = aBuffer.makeStringAndClear();
      71           0 :         ::sax::Converter::convertBool(aBuffer, false);
      72           0 :         m_sValueFalse = aBuffer.makeStringAndClear();
      73             : 
      74             :         OSL_ENSURE(m_xPropertyInfo.is(), "OPropertyExport::OPropertyExport: need an XPropertySetInfo!");
      75             : 
      76             :         // collect the properties which need to be exported
      77           0 :         examinePersistence();
      78           0 :     }
      79             : 
      80             :     //---------------------------------------------------------------------
      81           0 :     bool OPropertyExport::shouldExportProperty( const ::rtl::OUString& i_propertyName ) const
      82             :     {
      83             :         // if the property state is DEFAULT, it does not need to be written - at least
      84             :         // if it's a built-in property, and not a dynamically-added one.
      85           0 :         bool bIsDefaultValue =    m_xPropertyState.is()
      86           0 :                             &&  ( PropertyState_DEFAULT_VALUE == m_xPropertyState->getPropertyState( i_propertyName ) );
      87           0 :         bool bIsDynamicProperty =  m_xPropertyInfo.is()
      88           0 :                                 && ( ( m_xPropertyInfo->getPropertyByName( i_propertyName ).Attributes & PropertyAttribute::REMOVEABLE ) != 0 );
      89           0 :         return ( !bIsDefaultValue || bIsDynamicProperty );
      90             :     }
      91             : 
      92             :     template< typename T > void
      93           0 :     OPropertyExport::exportRemainingPropertiesSequence(
      94             :         Any const & value, token::XMLTokenEnum eValueAttName)
      95             :     {
      96           0 :         OSequenceIterator< T > i(value);
      97           0 :         while (i.hasMoreElements())
      98             :         {
      99           0 :             ::rtl::OUString sValue(implConvertAny(i.nextElement()));
     100           0 :             AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
     101             :             SvXMLElementExport aValueTag(
     102             :                 m_rContext.getGlobalContext(), XML_NAMESPACE_FORM,
     103           0 :                 token::XML_LIST_VALUE, sal_True, sal_False);
     104             :         }
     105           0 :     }
     106             : 
     107           0 :     void OPropertyExport::exportRemainingProperties()
     108             :     {
     109             :         // the properties tag (will be created if we have at least one no-default property)
     110           0 :         SvXMLElementExport* pPropertiesTag = NULL;
     111             : 
     112             :         try
     113             :         {
     114           0 :             Any aValue;
     115           0 :             ::rtl::OUString sValue;
     116             : 
     117             :             // loop through all the properties which are yet to be exported
     118           0 :             for (   ConstStringSetIterator  aProperty = m_aRemainingProps.begin();
     119           0 :                     aProperty != m_aRemainingProps.end();
     120             :                     ++aProperty
     121             :                 )
     122             :             {
     123             :                 DBG_CHECK_PROPERTY_NO_TYPE(*aProperty);
     124             : 
     125             :     #if OSL_DEBUG_LEVEL > 0
     126             :                 const ::rtl::OUString sPropertyName = *aProperty; (void)sPropertyName;
     127             :     #endif
     128           0 :                 if ( !shouldExportProperty( *aProperty ) )
     129           0 :                     continue;
     130             : 
     131             :                 // now that we have the first sub-tag we need the form:properties element
     132           0 :                 if (!pPropertiesTag)
     133           0 :                     pPropertiesTag = new SvXMLElementExport(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, token::XML_PROPERTIES, sal_True, sal_True);
     134             : 
     135             :                 // add the name attribute
     136           0 :                 AddAttribute(XML_NAMESPACE_FORM, token::XML_PROPERTY_NAME, *aProperty);
     137             : 
     138             :                 // get the value
     139           0 :                 aValue = m_xProps->getPropertyValue(*aProperty);
     140             : 
     141             :                 // the type to export
     142           0 :                 Type aExportType;
     143             : 
     144             :                 // is it a sequence
     145           0 :                 sal_Bool bIsSequence = TypeClass_SEQUENCE == aValue.getValueTypeClass();
     146             :                 // the type of the property, maybe reduced to the element type of a sequence
     147           0 :                 if (bIsSequence)
     148           0 :                     aExportType = getSequenceElementType( aValue.getValueType() );
     149             :                 else
     150           0 :                     aExportType = aValue.getValueType();
     151             : 
     152             :                 // the type attribute
     153             : 
     154           0 :                 bool bIsEmptyValue = TypeClass_VOID == aValue.getValueType().getTypeClass();
     155           0 :                 if ( bIsEmptyValue )
     156             :                 {
     157           0 :                     com::sun::star::beans::Property aPropDesc;
     158           0 :                     aPropDesc = m_xPropertyInfo->getPropertyByName( *aProperty );
     159           0 :                     aExportType = aPropDesc.Type;
     160             :                 }
     161           0 :                 token::XMLTokenEnum eValueType = implGetPropertyXMLType( aExportType );
     162             : 
     163           0 :                 if ( bIsEmptyValue )
     164           0 :                     AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, token::XML_VOID );
     165             :                 else
     166           0 :                     AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, eValueType );
     167             : 
     168           0 :                 token::XMLTokenEnum eValueAttName( token::XML_VALUE );
     169           0 :                 switch ( eValueType )
     170             :                 {
     171           0 :                 case token::XML_BOOLEAN:    eValueAttName = token::XML_BOOLEAN_VALUE; break;
     172           0 :                 case token::XML_STRING:     eValueAttName = token::XML_STRING_VALUE;  break;
     173           0 :                 default:    break;
     174             :                 }
     175             : 
     176           0 :                 if( !bIsSequence && !bIsEmptyValue )
     177             :                 {   // the simple case
     178             : 
     179           0 :                     sValue = implConvertAny(aValue);
     180           0 :                     AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
     181             :                 }
     182             : 
     183             : 
     184             :                 // start the property tag
     185           0 :                 SvXMLElementExport aValueTag1(m_rContext.getGlobalContext(),
     186             :                         XML_NAMESPACE_FORM,
     187             :                         bIsSequence ? token::XML_LIST_PROPERTY
     188           0 :                                     : token::XML_PROPERTY, sal_True, sal_True);
     189             : 
     190           0 :                 if (!bIsSequence)
     191           0 :                     continue;
     192             : 
     193             :                 // the not-that-simple case, we need to iterate through the sequence elements
     194           0 :                 switch ( aExportType.getTypeClass() )
     195             :                 {
     196             :                     case TypeClass_STRING:
     197             :                         exportRemainingPropertiesSequence< ::rtl::OUString >(
     198           0 :                             aValue, eValueAttName);
     199           0 :                         break;
     200             :                     case TypeClass_DOUBLE:
     201             :                         exportRemainingPropertiesSequence< double >(
     202           0 :                             aValue, eValueAttName);
     203           0 :                         break;
     204             :                     case TypeClass_BOOLEAN:
     205             :                         exportRemainingPropertiesSequence< sal_Bool >(
     206           0 :                             aValue, eValueAttName);
     207           0 :                         break;
     208             :                     case TypeClass_BYTE:
     209             :                         exportRemainingPropertiesSequence< sal_Int8 >(
     210           0 :                             aValue, eValueAttName);
     211           0 :                         break;
     212             :                     case TypeClass_SHORT:
     213             :                         exportRemainingPropertiesSequence< sal_Int16 >(
     214           0 :                             aValue, eValueAttName);
     215           0 :                         break;
     216             :                     case TypeClass_LONG:
     217             :                         exportRemainingPropertiesSequence< sal_Int32 >(
     218           0 :                             aValue, eValueAttName);
     219           0 :                         break;
     220             :                     case TypeClass_HYPER:
     221             :                         exportRemainingPropertiesSequence< sal_Int64 >(
     222           0 :                             aValue, eValueAttName);
     223           0 :                         break;
     224             :                     default:
     225             :                         OSL_FAIL("OPropertyExport::exportRemainingProperties: unsupported sequence tyoe !");
     226           0 :                         break;
     227             :                 }
     228           0 :             }
     229             :         }
     230           0 :         catch(...)
     231             :         {
     232           0 :             delete pPropertiesTag;
     233           0 :             throw;
     234             :         }
     235           0 :         delete pPropertiesTag;
     236           0 :     }
     237             : 
     238             :     //---------------------------------------------------------------------
     239           0 :     void OPropertyExport::examinePersistence()
     240             :     {
     241           0 :         m_aRemainingProps.clear();
     242           0 :         Sequence< Property > aProperties = m_xPropertyInfo->getProperties();
     243           0 :         const Property* pProperties = aProperties.getConstArray();
     244           0 :         for (sal_Int32 i=0; i<aProperties.getLength(); ++i, ++pProperties)
     245             :         {
     246             :             // no transient props
     247           0 :             if ( pProperties->Attributes & PropertyAttribute::TRANSIENT )
     248           0 :                 continue;
     249             :             // no read-only props
     250           0 :             if ( ( pProperties->Attributes & PropertyAttribute::READONLY ) != 0 )
     251             :                 // except they're dynamically added
     252           0 :                 if ( ( pProperties->Attributes & PropertyAttribute::REMOVEABLE ) == 0 )
     253           0 :                     continue;
     254           0 :             m_aRemainingProps.insert(pProperties->Name);
     255           0 :         }
     256           0 :     }
     257             : 
     258             :     //---------------------------------------------------------------------
     259           0 :     void OPropertyExport::exportStringPropertyAttribute( const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
     260             :             const ::rtl::OUString& _rPropertyName )
     261             :     {
     262             :         DBG_CHECK_PROPERTY( _rPropertyName, ::rtl::OUString );
     263             : 
     264             :         // no try-catch here, this would be to expensive. The outer scope has to handle exceptions (which should not
     265             :         // happen if we're used correctly :)
     266             : 
     267             :         // this is way simple, as we don't need to convert anything (the property already is a string)
     268             : 
     269             :         // get the string
     270           0 :         ::rtl::OUString sPropValue;
     271           0 :         m_xProps->getPropertyValue( _rPropertyName ) >>= sPropValue;
     272             : 
     273             :         // add the attribute
     274           0 :         if ( !sPropValue.isEmpty() )
     275           0 :             AddAttribute( _nNamespaceKey, _pAttributeName, sPropValue );
     276             : 
     277             :         // the property does not need to be handled anymore
     278           0 :         exportedProperty( _rPropertyName );
     279           0 :     }
     280             : 
     281             :     //---------------------------------------------------------------------
     282           0 :     void OPropertyExport::exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
     283             :             const ::rtl::OUString& _rPropertyName, const sal_Int8 _nBooleanAttributeFlags)
     284             :     {
     285             :         DBG_CHECK_PROPERTY_NO_TYPE( _rPropertyName );
     286             :         // no check of the property value type: this method is allowed to be called with any interger properties
     287             :         // (e.g. sal_Int32, sal_uInt16 etc)
     288             : 
     289           0 :         sal_Bool bDefault = (BOOLATTR_DEFAULT_TRUE == (BOOLATTR_DEFAULT_MASK & _nBooleanAttributeFlags));
     290           0 :         sal_Bool bDefaultVoid = (BOOLATTR_DEFAULT_VOID == (BOOLATTR_DEFAULT_MASK & _nBooleanAttributeFlags));
     291             : 
     292             :         // get the value
     293           0 :         sal_Bool bCurrentValue = bDefault;
     294           0 :         Any aCurrentValue = m_xProps->getPropertyValue( _rPropertyName );
     295           0 :         if (aCurrentValue.hasValue())
     296             :         {
     297           0 :             bCurrentValue = ::cppu::any2bool(aCurrentValue);
     298             :             // this will extract a boolean value even if the Any contains a int or short or something like that ...
     299             : 
     300           0 :             if (_nBooleanAttributeFlags & BOOLATTR_INVERSE_SEMANTICS)
     301           0 :                 bCurrentValue = !bCurrentValue;
     302             : 
     303             :             // we have a non-void current value
     304           0 :             if (bDefaultVoid || (bDefault != bCurrentValue))
     305             :                 // and (the default is void, or the non-void default does not equal the current value)
     306             :                 // -> write the attribute
     307           0 :                 AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
     308             :         }
     309             :         else
     310             :             // we have a void current value
     311           0 :             if (!bDefaultVoid)
     312             :                 // and we have a non-void default
     313             :                 // -> write the attribute
     314           0 :                 AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
     315             : 
     316             :         // the property does not need to be handled anymore
     317           0 :         exportedProperty( _rPropertyName );
     318           0 :     }
     319             : 
     320             :     //---------------------------------------------------------------------
     321           0 :     void OPropertyExport::exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
     322             :         const ::rtl::OUString& _rPropertyName, const sal_Int16 _nDefault)
     323             :     {
     324             :         DBG_CHECK_PROPERTY( _rPropertyName, sal_Int16 );
     325             : 
     326             :         // get the value
     327           0 :         sal_Int16 nCurrentValue(_nDefault);
     328           0 :         m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
     329             : 
     330             :         // add the attribute
     331           0 :         if (_nDefault != nCurrentValue)
     332             :         {
     333             :             // let the formatter of the export context build a string
     334           0 :             ::rtl::OUStringBuffer sBuffer;
     335           0 :             ::sax::Converter::convertNumber(sBuffer, (sal_Int32)nCurrentValue);
     336             : 
     337           0 :             AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
     338             :         }
     339             : 
     340             :         // the property does not need to be handled anymore
     341           0 :         exportedProperty( _rPropertyName );
     342           0 :     }
     343             : 
     344             :     //---------------------------------------------------------------------
     345           0 :     void OPropertyExport::exportInt32PropertyAttribute( const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
     346             :         const ::rtl::OUString& _rPropertyName, const sal_Int32 _nDefault )
     347             :     {
     348             :         DBG_CHECK_PROPERTY( _rPropertyName, sal_Int32 );
     349             : 
     350             :         // get the value
     351           0 :         sal_Int32 nCurrentValue( _nDefault );
     352           0 :         m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
     353             : 
     354             :         // add the attribute
     355           0 :         if ( _nDefault != nCurrentValue )
     356             :         {
     357             :             // let the formatter of the export context build a string
     358           0 :             ::rtl::OUStringBuffer sBuffer;
     359           0 :             ::sax::Converter::convertNumber( sBuffer, nCurrentValue );
     360             : 
     361           0 :             AddAttribute( _nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear() );
     362             :         }
     363             : 
     364             :         // the property does not need to be handled anymore
     365           0 :         exportedProperty( _rPropertyName );
     366           0 :     }
     367             : 
     368             :     //---------------------------------------------------------------------
     369           0 :     void OPropertyExport::exportEnumPropertyAttribute(
     370             :             const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
     371             :             const rtl::OUString &rPropertyName, const SvXMLEnumMapEntry* _pValueMap,
     372             :             const sal_Int32 _nDefault, const sal_Bool _bVoidDefault)
     373             :     {
     374             :         // get the value
     375           0 :         sal_Int32 nCurrentValue(_nDefault);
     376           0 :         Any aValue = m_xProps->getPropertyValue(rPropertyName);
     377             : 
     378           0 :         if (aValue.hasValue())
     379             :         {   // we have a non-void current value
     380           0 :             ::cppu::enum2int(nCurrentValue, aValue);
     381             : 
     382             :             // add the attribute
     383           0 :             if ((_nDefault != nCurrentValue) || _bVoidDefault)
     384             :             {   // the default does not equal the value, or the default is void and the value isn't
     385             : 
     386             :                 // let the formatter of the export context build a string
     387           0 :                 ::rtl::OUStringBuffer sBuffer;
     388           0 :                 m_rContext.getGlobalContext().GetMM100UnitConverter().convertEnum(sBuffer, (sal_uInt16)nCurrentValue, _pValueMap);
     389             : 
     390           0 :                 AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
     391             :             }
     392             :         }
     393             :         else
     394             :         {
     395           0 :             if (!_bVoidDefault)
     396           0 :                 AddAttributeASCII(_nNamespaceKey, _pAttributeName, "");
     397             :         }
     398             : 
     399             :         // the property does not need to be handled anymore
     400           0 :         exportedProperty(rPropertyName);
     401           0 :     }
     402             : 
     403             :     //---------------------------------------------------------------------
     404           0 :     void OPropertyExport::exportTargetFrameAttribute()
     405             :     {
     406             :         DBG_CHECK_PROPERTY( PROPERTY_TARGETFRAME, ::rtl::OUString );
     407             : 
     408           0 :         ::rtl::OUString sTargetFrame = comphelper::getString(m_xProps->getPropertyValue(PROPERTY_TARGETFRAME));
     409           0 :         if (0 != sTargetFrame.compareToAscii("_blank"))
     410             :         {   // an empty string and "_blank" have the same meaning and don't have to be written
     411           0 :             AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(CCA_TARGET_FRAME)
     412             :                         ,OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME)
     413           0 :                         ,sTargetFrame);
     414             :         }
     415             : 
     416           0 :         exportedProperty(PROPERTY_TARGETFRAME);
     417           0 :     }
     418             : 
     419             :     //---------------------------------------------------------------------
     420           0 :     void OPropertyExport::exportRelativeTargetLocation(const ConstAsciiString& _sPropertyName,sal_Int32 _nProperty,bool _bAddType)
     421             :     {
     422             :         DBG_CHECK_PROPERTY( _sPropertyName, ::rtl::OUString );
     423             : 
     424           0 :         ::rtl::OUString sTargetLocation = comphelper::getString(m_xProps->getPropertyValue(_sPropertyName));
     425           0 :         if ( !sTargetLocation.isEmpty() )
     426             :                     // If this isn't a GraphicObject then GetRelativeReference
     427             :                     // will be called anyway ( in AddEmbeddedGraphic )
     428           0 :             sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedGraphicObject(sTargetLocation);
     429           0 :         AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(_nProperty)
     430             :                     ,OAttributeMetaData::getCommonControlAttributeName(_nProperty)
     431           0 :                     , sTargetLocation);
     432             : 
     433             :         // #i110911# add xlink:type="simple" if required
     434           0 :         if (_bAddType)
     435           0 :             AddAttribute(XML_NAMESPACE_XLINK, token::XML_TYPE, token::XML_SIMPLE);
     436             : 
     437           0 :         exportedProperty(_sPropertyName);
     438           0 :     }
     439             :     //---------------------------------------------------------------------
     440           0 :     void OPropertyExport::flagStyleProperties()
     441             :     {
     442             :         // flag all the properties which are part of the style as "handled"
     443           0 :         UniReference< XMLPropertySetMapper > xStylePropertiesSupplier = m_rContext.getStylePropertyMapper()->getPropertySetMapper();
     444           0 :         for (sal_Int32 i=0; i<xStylePropertiesSupplier->GetEntryCount(); ++i)
     445           0 :             exportedProperty(xStylePropertiesSupplier->GetEntryAPIName(i));
     446             : 
     447             :         // the font properties are exported as single properties, but there is a FontDescriptor property which
     448             :         // collects them all-in-one, this has been exported implicitly
     449           0 :         exportedProperty(PROPERTY_FONT);
     450             : 
     451             :         // for the DateFormat and TimeFormat, there exist wrapper properties which has been exported as
     452             :         // style, too
     453           0 :         exportedProperty(PROPERTY_DATEFORMAT);
     454           0 :         exportedProperty(PROPERTY_TIMEFORMAT);
     455             : 
     456             :         // the following properties should have been exported at the shape already:
     457           0 :         exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VerticalAlign" ) ) );
     458           0 :         exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WritingMode" ) ) );
     459           0 :         exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScaleMode" ) ) );
     460             :         // ditto the TextWritingMode
     461           0 :         exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WritingMode" ) ) );
     462           0 :     }
     463             : 
     464             :     //---------------------------------------------------------------------
     465           0 :     void OPropertyExport::exportGenericPropertyAttribute(
     466             :             const sal_uInt16 _nAttributeNamespaceKey, const sal_Char* _pAttributeName, const sal_Char* _pPropertyName)
     467             :     {
     468             :         DBG_CHECK_PROPERTY_ASCII_NO_TYPE( _pPropertyName );
     469             : 
     470           0 :         ::rtl::OUString sPropertyName = ::rtl::OUString::createFromAscii(_pPropertyName);
     471           0 :         exportedProperty(sPropertyName);
     472             : 
     473           0 :         Any aCurrentValue = m_xProps->getPropertyValue(sPropertyName);
     474           0 :         if (!aCurrentValue.hasValue())
     475             :             // nothing to do without a concrete value
     476             :             return;
     477             : 
     478           0 :         ::rtl::OUString sValue = implConvertAny(aCurrentValue);
     479           0 :         if (sValue.isEmpty() && (TypeClass_STRING == aCurrentValue.getValueTypeClass()))
     480             :         {
     481             :             // check whether or not the property is allowed to be VOID
     482           0 :             Property aProperty = m_xPropertyInfo->getPropertyByName(sPropertyName);
     483           0 :             if ((aProperty.Attributes & PropertyAttribute::MAYBEVOID) == 0)
     484             :                 // the string is empty, and the property is not allowed to be void
     485             :                 // -> don't need to write the attibute, 'cause missing it is unambiguous
     486           0 :                 return;
     487             :         }
     488             : 
     489             :         // finally add the attribuite to the context
     490           0 :         AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sValue);
     491             :     }
     492             : 
     493             :     //---------------------------------------------------------------------
     494           0 :     void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const sal_Char* _pAttributeName,
     495             :         const ::rtl::OUString& _rPropertyName,
     496             :         const sal_Unicode _aQuoteCharacter, const sal_Unicode _aListSeparator)
     497             :     {
     498             :         DBG_CHECK_PROPERTY( _rPropertyName, Sequence< ::rtl::OUString > );
     499             :         OSL_ENSURE(_aListSeparator != 0, "OPropertyExport::exportStringSequenceAttribute: invalid separator character!");
     500             : 
     501           0 :         Sequence< ::rtl::OUString > aItems;
     502           0 :         m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
     503             : 
     504           0 :         ::rtl::OUString sFinalList;
     505             : 
     506             :         // unfortunately the OUString can't append single sal_Unicode characters ...
     507           0 :         const ::rtl::OUString sQuote(&_aQuoteCharacter, 1);
     508           0 :         const ::rtl::OUString sSeparator(&_aListSeparator, 1);
     509           0 :         const sal_Bool bQuote = !sQuote.isEmpty();
     510             : 
     511             :         // concatenate the string items
     512           0 :         const ::rtl::OUString* pItems = aItems.getConstArray();
     513           0 :         const ::rtl::OUString* pEnd = pItems + aItems.getLength();
     514           0 :         const ::rtl::OUString* pLastElement = pEnd - 1;
     515           0 :         for (   ;
     516             :                 pItems != pEnd;
     517             :                 ++pItems
     518             :             )
     519             :         {
     520             :             OSL_ENSURE(!_aQuoteCharacter || (-1 == pItems->indexOf(_aQuoteCharacter)),
     521             :                 "OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
     522             :             OSL_ENSURE(_aQuoteCharacter || (-1 == pItems->indexOf(_aListSeparator)),
     523             :                 "OPropertyExport::exportStringSequenceAttribute: no quote character, but there is an item containing the separator character!");
     524             : 
     525           0 :             if (bQuote)
     526           0 :                 sFinalList += sQuote;
     527           0 :             sFinalList += *pItems;
     528           0 :             if (bQuote)
     529           0 :                 sFinalList += sQuote;
     530             : 
     531           0 :             if (pItems != pLastElement)
     532           0 :                 sFinalList += sSeparator;
     533             :         }
     534             : 
     535           0 :         if (!sFinalList.isEmpty())
     536           0 :             AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sFinalList);
     537             : 
     538           0 :         exportedProperty( _rPropertyName );
     539           0 :     }
     540             : 
     541             :     //---------------------------------------------------------------------
     542           0 :     ::rtl::OUString OPropertyExport::implConvertAny(const Any& _rValue)
     543             :     {
     544           0 :         ::rtl::OUStringBuffer aBuffer;
     545           0 :         switch (_rValue.getValueTypeClass())
     546             :         {
     547             :             case TypeClass_STRING:
     548             :             {   // extract the string
     549           0 :                 ::rtl::OUString sCurrentValue;
     550           0 :                 _rValue >>= sCurrentValue;
     551           0 :                 aBuffer.append(sCurrentValue);
     552             :             }
     553           0 :             break;
     554             :             case TypeClass_DOUBLE:
     555             :                 // let the unit converter format is as string
     556           0 :                 ::sax::Converter::convertDouble(aBuffer, getDouble(_rValue));
     557           0 :                 break;
     558             :             case TypeClass_BOOLEAN:
     559           0 :                 aBuffer = getBOOL(_rValue) ? m_sValueTrue : m_sValueFalse;
     560           0 :                 break;
     561             :             case TypeClass_BYTE:
     562             :             case TypeClass_SHORT:
     563             :             case TypeClass_LONG:
     564             :                 // let the unit converter format is as string
     565           0 :                 ::sax::Converter::convertNumber(aBuffer, getINT32(_rValue));
     566           0 :                 break;
     567             :             case TypeClass_HYPER:
     568             :                 // TODO
     569             :                 OSL_FAIL("OPropertyExport::implConvertAny: missing implementation for sal_Int64!");
     570           0 :                 break;
     571             :             case TypeClass_ENUM:
     572             :             {
     573             :                 // convert it into an int32
     574           0 :                 sal_Int32 nValue = 0;
     575           0 :                 ::cppu::enum2int(nValue, _rValue);
     576           0 :                 ::sax::Converter::convertNumber(aBuffer, nValue);
     577             :             }
     578           0 :             break;
     579             :             default:
     580             :             {   // hmmm .... what else do we know?
     581           0 :                 double fValue = 0;
     582           0 :                 ::com::sun::star::util::Date aDate;
     583           0 :                 ::com::sun::star::util::Time aTime;
     584           0 :                 ::com::sun::star::util::DateTime aDateTime;
     585           0 :                 if (_rValue >>= aDate)
     586             :                 {
     587           0 :                     Date aToolsDate( Date::EMPTY );
     588           0 :                     ::utl::typeConvert(aDate, aToolsDate);
     589           0 :                     fValue = aToolsDate.GetDate();
     590             :                 }
     591           0 :                 else if (_rValue >>= aTime)
     592             :                 {
     593           0 :                     fValue = ((aTime.Hours * 60 + aTime.Minutes) * 60 + aTime.Seconds) * 100 + aTime.HundredthSeconds;
     594           0 :                     fValue = fValue / 8640000.0;
     595             :                 }
     596           0 :                 else if (_rValue >>= aDateTime)
     597             :                 {
     598           0 :                     DateTime aToolsDateTime( DateTime::EMPTY );
     599           0 :                     ::utl::typeConvert(aDateTime, aToolsDateTime);
     600             :                     // the time part (the digits behind the comma)
     601           0 :                     fValue = ((aDateTime.Hours * 60 + aDateTime.Minutes) * 60 + aDateTime.Seconds) * 100 + aDateTime.HundredthSeconds;
     602           0 :                     fValue = fValue / 8640000.0;
     603             :                     // plus the data part (the digits in front of the comma)
     604           0 :                     fValue += aToolsDateTime.GetDate();
     605             :                 }
     606             :                 else
     607             :                 {
     608             :                     // if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
     609             : 
     610             :                     // no more options ...
     611             :                     OSL_FAIL("OPropertyExport::implConvertAny: unsupported value type!");
     612             :                     break;
     613             :                 }
     614             :                 // let the unit converter format is as string
     615           0 :                 ::sax::Converter::convertDouble(aBuffer, fValue);
     616             :             }
     617           0 :             break;
     618             :         }
     619             : 
     620           0 :         return aBuffer.makeStringAndClear();
     621             :     }
     622             : 
     623             : 
     624             :     //---------------------------------------------------------------------
     625           0 :     token::XMLTokenEnum OPropertyExport::implGetPropertyXMLType(const ::com::sun::star::uno::Type& _rType)
     626             :     {
     627             :         // handle the type description
     628           0 :         switch (_rType.getTypeClass())
     629             :         {
     630             :             case TypeClass_STRING:
     631           0 :                 return token::XML_STRING;
     632             :             case TypeClass_DOUBLE:
     633             :             case TypeClass_BYTE:
     634             :             case TypeClass_SHORT:
     635             :             case TypeClass_LONG:
     636             :             case TypeClass_HYPER:
     637             :             case TypeClass_ENUM:
     638           0 :                 return token::XML_FLOAT;
     639             :             case TypeClass_BOOLEAN:
     640           0 :                 return token::XML_BOOLEAN;
     641             : 
     642             :             default:
     643           0 :                 return token::XML_FLOAT;
     644             :         }
     645             :     }
     646             : 
     647             : #ifdef DBG_UTIL
     648             :     //---------------------------------------------------------------------
     649             :     void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, const sal_Char* _pName, const ::rtl::OUString& _rValue)
     650             :     {
     651             :         OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::rtl::OUString::createFromAscii(_pName)).isEmpty(),
     652             :             "OPropertyExport::AddAttribute: already have such an attribute");
     653             : 
     654             :         m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue);
     655             :     }
     656             : 
     657             :     //---------------------------------------------------------------------
     658             :     void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, const ::rtl::OUString& _rValue )
     659             :     {
     660             :         OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName( _rName ).isEmpty(),
     661             :             "OPropertyExport::AddAttribute: already have such an attribute");
     662             : 
     663             :         m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue );
     664             :     }
     665             : 
     666             :     //---------------------------------------------------------------------
     667             :     void OPropertyExport::AddAttributeASCII(sal_uInt16 _nPrefix, const sal_Char* _pName, const sal_Char *pValue)
     668             :     {
     669             :         OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::rtl::OUString::createFromAscii(_pName)).isEmpty(),
     670             :             "OPropertyExport::AddAttributeASCII: already have such an attribute");
     671             : 
     672             :         m_rContext.getGlobalContext().AddAttributeASCII(_nPrefix, _pName, pValue);
     673             :     }
     674             : 
     675             :     //---------------------------------------------------------------------
     676             :     void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const ::rtl::OUString& _rValue)
     677             :     {
     678             :         OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
     679             :             "OPropertyExport::AddAttribute: already have such an attribute");
     680             : 
     681             :         m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue);
     682             :     }
     683             : 
     684             :     //---------------------------------------------------------------------
     685             :     void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
     686             :     {
     687             :         OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
     688             :             "OPropertyExport::AddAttribute: already have such an attribute");
     689             : 
     690             :         m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue);
     691             :     }
     692             : 
     693             :     //---------------------------------------------------------------------
     694             :     void OPropertyExport::dbg_implCheckProperty(const ::rtl::OUString& _rPropertyName, const Type* _pType)
     695             :     {
     696             :         try
     697             :         {
     698             :             // the property must exist
     699             :             if (!m_xPropertyInfo->hasPropertyByName(_rPropertyName))
     700             :             {
     701             :                 rtl::OStringBuffer aBuf(RTL_CONSTASCII_STRINGPARAM(
     702             :                     "OPropertyExport::dbg_implCheckProperty: no property with the name "));
     703             :                 aBuf.append(rtl::OUStringToOString(_rPropertyName, RTL_TEXTENCODING_ASCII_US)).append('!');
     704             :                 OSL_FAIL(aBuf.getStr());
     705             :                 return;
     706             :             }
     707             : 
     708             :             if (_pType)
     709             :             {
     710             :                 // and it must have the correct type
     711             :                 Property aPropertyDescription = m_xPropertyInfo->getPropertyByName(_rPropertyName);
     712             :                 OSL_ENSURE(aPropertyDescription.Type.equals(*_pType), "OPropertyExport::dbg_implCheckProperty: invalid property type!");
     713             :             }
     714             :         }
     715             :         catch(Exception&)
     716             :         {
     717             :             OSL_FAIL("OPropertyExport::dbg_implCheckProperty: caught an exception, could not check the property!");
     718             :         }
     719             :     }
     720             : #endif // DBG_UTIL - dbg_implCheckProperty
     721             : 
     722             : //.........................................................................
     723             : }   // namespace xmloff
     724             : //.........................................................................
     725             : 
     726             : 
     727             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10