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

Generated by: LCOV version 1.11