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

Generated by: LCOV version 1.10