Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / forms / propertyexport.cxx
blobb5db7bb6ad7cd04c4471c6c23e39fcccca23cc20
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
41 namespace xmloff
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::beans;
48 // NO using namespace ...util !!!
49 // need a tools Date/Time/DateTime below, which would conflict with the uno types then
51 using namespace ::comphelper;
53 //= OPropertyExport
54 OPropertyExport::OPropertyExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxProps)
55 :m_rContext(_rContext)
56 ,m_xProps(_rxProps)
57 ,m_xPropertyInfo( m_xProps->getPropertySetInfo() )
58 ,m_xPropertyState( _rxProps, UNO_QUERY )
60 // caching
61 OUStringBuffer aBuffer;
62 ::sax::Converter::convertBool(aBuffer, true);
63 m_sValueTrue = aBuffer.makeStringAndClear();
64 ::sax::Converter::convertBool(aBuffer, false);
65 m_sValueFalse = aBuffer.makeStringAndClear();
67 OSL_ENSURE(m_xPropertyInfo.is(), "OPropertyExport::OPropertyExport: need an XPropertySetInfo!");
69 // collect the properties which need to be exported
70 examinePersistence();
73 bool OPropertyExport::shouldExportProperty( const OUString& i_propertyName ) const
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 bool bIsDefaultValue = m_xPropertyState.is()
78 && ( PropertyState_DEFAULT_VALUE == m_xPropertyState->getPropertyState( i_propertyName ) );
79 bool bIsDynamicProperty = m_xPropertyInfo.is()
80 && ( ( m_xPropertyInfo->getPropertyByName( i_propertyName ).Attributes & PropertyAttribute::REMOVABLE ) != 0 );
81 return ( !bIsDefaultValue || bIsDynamicProperty );
84 template< typename T > void
85 OPropertyExport::exportRemainingPropertiesSequence(
86 Any const & value, token::XMLTokenEnum eValueAttName)
88 OSequenceIterator< T > i(value);
89 while (i.hasMoreElements())
91 OUString sValue(implConvertAny(i.nextElement()));
92 AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
93 SvXMLElementExport aValueTag(
94 m_rContext.getGlobalContext(), XML_NAMESPACE_FORM,
95 token::XML_LIST_VALUE, true, false);
99 void OPropertyExport::exportRemainingProperties()
101 // the properties tag (will be created if we have at least one no-default property)
102 SvXMLElementExport* pPropertiesTag = nullptr;
106 Any aValue;
107 OUString sValue;
109 // loop through all the properties which are yet to be exported
110 for ( StringSet::const_iterator aProperty = m_aRemainingProps.begin();
111 aProperty != m_aRemainingProps.end();
112 ++aProperty
115 DBG_CHECK_PROPERTY_NO_TYPE(*aProperty);
117 #if OSL_DEBUG_LEVEL > 0
118 const OUString sPropertyName = *aProperty; (void)sPropertyName;
119 #endif
120 if ( !shouldExportProperty( *aProperty ) )
121 continue;
123 // now that we have the first sub-tag we need the form:properties element
124 if (!pPropertiesTag)
125 pPropertiesTag = new SvXMLElementExport(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, token::XML_PROPERTIES, true, true);
127 // add the name attribute
128 AddAttribute(XML_NAMESPACE_FORM, token::XML_PROPERTY_NAME, *aProperty);
130 // get the value
131 aValue = m_xProps->getPropertyValue(*aProperty);
133 // the type to export
134 Type aExportType;
136 // is it a sequence
137 bool bIsSequence = TypeClass_SEQUENCE == aValue.getValueTypeClass();
138 // the type of the property, maybe reduced to the element type of a sequence
139 if (bIsSequence)
140 aExportType = getSequenceElementType( aValue.getValueType() );
141 else
142 aExportType = aValue.getValueType();
144 // the type attribute
146 bool bIsEmptyValue = TypeClass_VOID == aValue.getValueType().getTypeClass();
147 if ( bIsEmptyValue )
149 css::beans::Property aPropDesc;
150 aPropDesc = m_xPropertyInfo->getPropertyByName( *aProperty );
151 aExportType = aPropDesc.Type;
153 token::XMLTokenEnum eValueType = implGetPropertyXMLType( aExportType );
155 if ( bIsEmptyValue )
156 AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, token::XML_VOID );
157 else
158 AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, eValueType );
160 token::XMLTokenEnum eValueAttName( token::XML_VALUE );
161 switch ( eValueType )
163 case token::XML_BOOLEAN: eValueAttName = token::XML_BOOLEAN_VALUE; break;
164 case token::XML_STRING: eValueAttName = token::XML_STRING_VALUE; break;
165 default: break;
168 if( !bIsSequence && !bIsEmptyValue )
169 { // the simple case
171 sValue = implConvertAny(aValue);
172 AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
175 // start the property tag
176 SvXMLElementExport aValueTag1(m_rContext.getGlobalContext(),
177 XML_NAMESPACE_FORM,
178 bIsSequence ? token::XML_LIST_PROPERTY
179 : token::XML_PROPERTY, true, true);
181 if (!bIsSequence)
182 continue;
184 // the not-that-simple case, we need to iterate through the sequence elements
185 switch ( aExportType.getTypeClass() )
187 case TypeClass_STRING:
188 exportRemainingPropertiesSequence< OUString >(
189 aValue, eValueAttName);
190 break;
191 case TypeClass_DOUBLE:
192 exportRemainingPropertiesSequence< double >(
193 aValue, eValueAttName);
194 break;
195 case TypeClass_BOOLEAN:
196 exportRemainingPropertiesSequence< sal_Bool >(
197 aValue, eValueAttName);
198 break;
199 case TypeClass_BYTE:
200 exportRemainingPropertiesSequence< sal_Int8 >(
201 aValue, eValueAttName);
202 break;
203 case TypeClass_SHORT:
204 exportRemainingPropertiesSequence< sal_Int16 >(
205 aValue, eValueAttName);
206 break;
207 case TypeClass_LONG:
208 exportRemainingPropertiesSequence< sal_Int32 >(
209 aValue, eValueAttName);
210 break;
211 case TypeClass_HYPER:
212 exportRemainingPropertiesSequence< sal_Int64 >(
213 aValue, eValueAttName);
214 break;
215 default:
216 OSL_FAIL("OPropertyExport::exportRemainingProperties: unsupported sequence tyoe !");
217 break;
221 catch(...)
223 delete pPropertiesTag;
224 throw;
226 delete pPropertiesTag;
229 void OPropertyExport::examinePersistence()
231 m_aRemainingProps.clear();
232 Sequence< Property > aProperties = m_xPropertyInfo->getProperties();
233 const Property* pProperties = aProperties.getConstArray();
234 for (sal_Int32 i=0; i<aProperties.getLength(); ++i, ++pProperties)
236 // no transient props
237 if ( pProperties->Attributes & PropertyAttribute::TRANSIENT )
238 continue;
239 // no read-only props
240 if ( ( pProperties->Attributes & PropertyAttribute::READONLY ) != 0 )
241 // except they're dynamically added
242 if ( ( pProperties->Attributes & PropertyAttribute::REMOVABLE ) == 0 )
243 continue;
244 m_aRemainingProps.insert(pProperties->Name);
248 void OPropertyExport::exportStringPropertyAttribute( const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
249 const OUString& _rPropertyName )
251 DBG_CHECK_PROPERTY( _rPropertyName, OUString );
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 :)
256 // this is way simple, as we don't need to convert anything (the property already is a string)
258 // get the string
259 OUString sPropValue;
260 m_xProps->getPropertyValue( _rPropertyName ) >>= sPropValue;
262 // add the attribute
263 if ( !sPropValue.isEmpty() )
264 AddAttribute( _nNamespaceKey, _pAttributeName, sPropValue );
266 // the property does not need to be handled anymore
267 exportedProperty( _rPropertyName );
270 void OPropertyExport::exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
271 const OUString& _rPropertyName, const BoolAttrFlags _nBooleanAttributeFlags)
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)
277 bool bDefault = (BoolAttrFlags::DefaultTrue == (BoolAttrFlags::DefaultMask & _nBooleanAttributeFlags));
278 bool bDefaultVoid = (BoolAttrFlags::DefaultVoid == (BoolAttrFlags::DefaultMask & _nBooleanAttributeFlags));
280 // get the value
281 bool bCurrentValue = bDefault;
282 Any aCurrentValue = m_xProps->getPropertyValue( _rPropertyName );
283 if (aCurrentValue.hasValue())
285 bCurrentValue = ::cppu::any2bool(aCurrentValue);
286 // this will extract a boolean value even if the Any contains a int or short or something like that ...
288 if (_nBooleanAttributeFlags & BoolAttrFlags::InverseSemantics)
289 bCurrentValue = !bCurrentValue;
291 // we have a non-void current value
292 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 AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
297 else
298 // we have a void current value
299 if (!bDefaultVoid)
300 // and we have a non-void default
301 // -> write the attribute
302 AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
304 // the property does not need to be handled anymore
305 exportedProperty( _rPropertyName );
308 void OPropertyExport::exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
309 const OUString& _rPropertyName, const sal_Int16 _nDefault, bool force)
311 DBG_CHECK_PROPERTY( _rPropertyName, sal_Int16 );
313 // get the value
314 sal_Int16 nCurrentValue(_nDefault);
315 m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
317 // add the attribute
318 if (force || _nDefault != nCurrentValue)
320 // let the formatter of the export context build a string
321 OUStringBuffer sBuffer;
322 ::sax::Converter::convertNumber(sBuffer, (sal_Int32)nCurrentValue);
324 AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
327 // the property does not need to be handled anymore
328 exportedProperty( _rPropertyName );
331 void OPropertyExport::exportInt32PropertyAttribute( const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
332 const OUString& _rPropertyName, const sal_Int32 _nDefault )
334 DBG_CHECK_PROPERTY( _rPropertyName, sal_Int32 );
336 // get the value
337 sal_Int32 nCurrentValue( _nDefault );
338 m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
340 // add the attribute
341 if ( _nDefault != nCurrentValue )
343 // let the formatter of the export context build a string
344 OUStringBuffer sBuffer;
345 ::sax::Converter::convertNumber( sBuffer, nCurrentValue );
347 AddAttribute( _nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear() );
350 // the property does not need to be handled anymore
351 exportedProperty( _rPropertyName );
354 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)
359 // get the value
360 sal_Int32 nCurrentValue(_nDefault);
361 Any aValue = m_xProps->getPropertyValue(rPropertyName);
363 if (aValue.hasValue())
364 { // we have a non-void current value
365 ::cppu::enum2int(nCurrentValue, aValue);
367 // add the attribute
368 if ((_nDefault != nCurrentValue) || _bVoidDefault)
369 { // the default does not equal the value, or the default is void and the value isn't
371 // let the formatter of the export context build a string
372 OUStringBuffer sBuffer;
373 SvXMLUnitConverter::convertEnum(sBuffer, (sal_uInt16)nCurrentValue, _pValueMap);
375 AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
378 else
380 if (!_bVoidDefault)
381 AddAttributeASCII(_nNamespaceKey, _pAttributeName, "");
384 // the property does not need to be handled anymore
385 exportedProperty(rPropertyName);
388 void OPropertyExport::exportTargetFrameAttribute()
390 DBG_CHECK_PROPERTY( PROPERTY_TARGETFRAME, OUString );
392 OUString sTargetFrame = comphelper::getString(m_xProps->getPropertyValue(PROPERTY_TARGETFRAME));
393 if( sTargetFrame != "_blank" )
394 { // an empty string and "_blank" have the same meaning and don't have to be written
395 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::TargetFrame)
396 ,OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetFrame)
397 ,sTargetFrame);
400 exportedProperty(PROPERTY_TARGETFRAME);
403 void OPropertyExport::exportRelativeTargetLocation(const OUString& _sPropertyName,CCAFlags _nProperty,bool _bAddType)
405 DBG_CHECK_PROPERTY( _sPropertyName, OUString );
407 OUString sTargetLocation = comphelper::getString(m_xProps->getPropertyValue(_sPropertyName));
408 if ( !sTargetLocation.isEmpty() )
409 // If this isn't a GraphicObject then GetRelativeReference
410 // will be called anyway ( in AddEmbeddedGraphic )
411 sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedGraphicObject(sTargetLocation);
412 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(_nProperty)
413 ,OAttributeMetaData::getCommonControlAttributeName(_nProperty)
414 , sTargetLocation);
416 // #i110911# add xlink:type="simple" if required
417 if (_bAddType)
418 AddAttribute(XML_NAMESPACE_XLINK, token::XML_TYPE, token::XML_SIMPLE);
420 exportedProperty(_sPropertyName);
422 void OPropertyExport::flagStyleProperties()
424 // flag all the properties which are part of the style as "handled"
425 rtl::Reference< XMLPropertySetMapper > xStylePropertiesSupplier = m_rContext.getStylePropertyMapper()->getPropertySetMapper();
426 for (sal_Int32 i=0; i<xStylePropertiesSupplier->GetEntryCount(); ++i)
427 exportedProperty(xStylePropertiesSupplier->GetEntryAPIName(i));
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 exportedProperty(PROPERTY_FONT);
433 // for the DateFormat and TimeFormat, there exist wrapper properties which has been exported as
434 // style, too
435 exportedProperty(PROPERTY_DATEFORMAT);
436 exportedProperty(PROPERTY_TIMEFORMAT);
438 // the following properties should have been exported at the shape already:
439 exportedProperty( "VerticalAlign" );
440 exportedProperty( "WritingMode" );
441 exportedProperty( "ScaleMode" );
442 // ditto the TextWritingMode
443 exportedProperty( "WritingMode" );
446 void OPropertyExport::exportGenericPropertyAttribute(
447 const sal_uInt16 _nAttributeNamespaceKey, const sal_Char* _pAttributeName, const sal_Char* _pPropertyName)
449 DBG_CHECK_PROPERTY_ASCII_NO_TYPE( _pPropertyName );
451 OUString sPropertyName = OUString::createFromAscii(_pPropertyName);
452 exportedProperty(sPropertyName);
454 Any aCurrentValue = m_xProps->getPropertyValue(sPropertyName);
455 if (!aCurrentValue.hasValue())
456 // nothing to do without a concrete value
457 return;
459 OUString sValue = implConvertAny(aCurrentValue);
460 if (sValue.isEmpty() && (TypeClass_STRING == aCurrentValue.getValueTypeClass()))
462 // check whether or not the property is allowed to be VOID
463 Property aProperty = m_xPropertyInfo->getPropertyByName(sPropertyName);
464 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 return;
470 // finally add the attribute to the context
471 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sValue);
474 void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const sal_Char* _pAttributeName,
475 const OUString& _rPropertyName)
477 const sal_Unicode _aListSeparator = ',';
478 const sal_Unicode _aQuoteCharacter = '"';
479 DBG_CHECK_PROPERTY( _rPropertyName, Sequence< OUString > );
481 Sequence< OUString > aItems;
482 m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
484 OUString sFinalList;
486 // unfortunately the OUString can't append single sal_Unicode characters ...
487 const OUString sQuote(&_aQuoteCharacter, 1);
488 const OUString sSeparator(&_aListSeparator, 1);
489 const bool bQuote = !sQuote.isEmpty();
491 // concatenate the string items
492 const OUString* pItems = aItems.getConstArray();
493 const OUString* pEnd = pItems + aItems.getLength();
494 const OUString* pLastElement = pEnd - 1;
495 for ( ;
496 pItems != pEnd;
497 ++pItems
500 OSL_ENSURE(-1 == pItems->indexOf(_aQuoteCharacter),
501 "OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
503 if (bQuote)
504 sFinalList += sQuote;
505 sFinalList += *pItems;
506 if (bQuote)
507 sFinalList += sQuote;
509 if (pItems != pLastElement)
510 sFinalList += sSeparator;
513 if (!sFinalList.isEmpty())
514 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sFinalList);
516 exportedProperty( _rPropertyName );
519 OUString OPropertyExport::implConvertAny(const Any& _rValue)
521 OUStringBuffer aBuffer;
522 switch (_rValue.getValueTypeClass())
524 case TypeClass_STRING:
525 { // extract the string
526 OUString sCurrentValue;
527 _rValue >>= sCurrentValue;
528 aBuffer.append(sCurrentValue);
530 break;
531 case TypeClass_DOUBLE:
532 // let the unit converter format is as string
533 ::sax::Converter::convertDouble(aBuffer, getDouble(_rValue));
534 break;
535 case TypeClass_BOOLEAN:
536 aBuffer = getBOOL(_rValue) ? m_sValueTrue : m_sValueFalse;
537 break;
538 case TypeClass_BYTE:
539 case TypeClass_UNSIGNED_SHORT:
540 case TypeClass_SHORT:
541 case TypeClass_LONG:
542 // let the unit converter format is as string
543 ::sax::Converter::convertNumber(aBuffer, getINT32(_rValue));
544 break;
545 case TypeClass_UNSIGNED_LONG:
546 case TypeClass_HYPER:
547 ::sax::Converter::convertNumber(aBuffer, getINT64(_rValue));
548 break;
549 case TypeClass_UNSIGNED_HYPER:
550 ::sax::Converter::convertNumber(aBuffer, _rValue.get<sal_uInt64>());
551 break;
552 case TypeClass_ENUM:
554 // convert it into an int32
555 sal_Int32 nValue = 0;
556 ::cppu::enum2int(nValue, _rValue);
557 ::sax::Converter::convertNumber(aBuffer, nValue);
559 break;
560 default:
561 { // hmmm .... what else do we know?
562 double fValue = 0;
563 css::util::Date aDate;
564 css::util::Time aTime;
565 css::util::DateTime aDateTime;
566 if (_rValue >>= aDate)
568 Date aToolsDate( Date::EMPTY );
569 ::utl::typeConvert(aDate, aToolsDate);
570 fValue = aToolsDate.GetDate();
572 else if (_rValue >>= aTime)
574 fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
575 aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
576 aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
577 aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
579 else if (_rValue >>= aDateTime)
581 DateTime aToolsDateTime( DateTime::EMPTY );
582 ::utl::typeConvert(aDateTime, aToolsDateTime);
583 // the time part (the digits behind the comma)
584 fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
585 aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
586 aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
587 aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
588 // plus the data part (the digits in front of the comma)
589 fValue += aToolsDateTime.GetDate();
591 else
593 // if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
595 // no more options ...
596 OSL_FAIL("OPropertyExport::implConvertAny: unsupported value type!");
597 break;
599 // let the unit converter format is as string
600 ::sax::Converter::convertDouble(aBuffer, fValue);
602 break;
605 return aBuffer.makeStringAndClear();
608 token::XMLTokenEnum OPropertyExport::implGetPropertyXMLType(const css::uno::Type& _rType)
610 // handle the type description
611 switch (_rType.getTypeClass())
613 case TypeClass_STRING:
614 return token::XML_STRING;
615 case TypeClass_DOUBLE:
616 case TypeClass_BYTE:
617 case TypeClass_SHORT:
618 case TypeClass_LONG:
619 case TypeClass_HYPER:
620 case TypeClass_ENUM:
621 return token::XML_FLOAT;
622 case TypeClass_BOOLEAN:
623 return token::XML_BOOLEAN;
625 default:
626 return token::XML_FLOAT;
630 #ifdef DBG_UTIL
631 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, const sal_Char* _pName, const OUString& _rValue)
633 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(OUString::createFromAscii(_pName)).isEmpty(),
634 "OPropertyExport::AddAttribute: already have such an attribute");
636 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue);
639 void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue )
641 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName( _rName ).isEmpty(),
642 "OPropertyExport::AddAttribute: already have such an attribute");
644 m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue );
647 void OPropertyExport::AddAttributeASCII(sal_uInt16 _nPrefix, const sal_Char* _pName, const sal_Char *pValue)
649 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(OUString::createFromAscii(_pName)).isEmpty(),
650 "OPropertyExport::AddAttributeASCII: already have such an attribute");
652 m_rContext.getGlobalContext().AddAttributeASCII(_nPrefix, _pName, pValue);
655 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue)
657 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
658 "OPropertyExport::AddAttribute: already have such an attribute");
660 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue);
663 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
665 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
666 "OPropertyExport::AddAttribute: already have such an attribute");
668 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue);
671 void OPropertyExport::dbg_implCheckProperty(const OUString& _rPropertyName, const Type* _pType)
675 // the property must exist
676 if (!m_xPropertyInfo->hasPropertyByName(_rPropertyName))
678 SAL_WARN("xmloff.forms", "OPropertyExport: "
679 "no property with the name " + _rPropertyName + "!");
680 return;
683 if (_pType)
685 // and it must have the correct type
686 Property aPropertyDescription = m_xPropertyInfo->getPropertyByName(_rPropertyName);
687 OSL_ENSURE(aPropertyDescription.Type.equals(*_pType), "OPropertyExport::dbg_implCheckProperty: invalid property type!");
690 catch(Exception&)
692 OSL_FAIL("OPropertyExport::dbg_implCheckProperty: caught an exception, could not check the property!");
695 #endif // DBG_UTIL - dbg_implCheckProperty
697 } // namespace xmloff
699 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */