bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / forms / propertyexport.cxx
blob4fd3d4f026588dd271f925c253296bd5406b2d4f
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 = NULL;
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 com::sun::star::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 sal_Int8 _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 = (BOOLATTR_DEFAULT_TRUE == (BOOLATTR_DEFAULT_MASK & _nBooleanAttributeFlags));
278 bool bDefaultVoid = (BOOLATTR_DEFAULT_VOID == (BOOLATTR_DEFAULT_MASK & _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 & BOOLATTR_INVERSE_SEMANTICS)
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(CCA_TARGET_FRAME)
396 ,OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME)
397 ,sTargetFrame);
400 exportedProperty(PROPERTY_TARGETFRAME);
403 void OPropertyExport::exportRelativeTargetLocation(const OUString& _sPropertyName,sal_Int32 _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 attribuite to the context
471 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sValue);
474 void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const sal_Char* _pAttributeName,
475 const OUString& _rPropertyName,
476 const sal_Unicode _aQuoteCharacter, const sal_Unicode _aListSeparator)
478 DBG_CHECK_PROPERTY( _rPropertyName, Sequence< OUString > );
479 OSL_ENSURE(_aListSeparator != 0, "OPropertyExport::exportStringSequenceAttribute: invalid separator character!");
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(!_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!");
505 if (bQuote)
506 sFinalList += sQuote;
507 sFinalList += *pItems;
508 if (bQuote)
509 sFinalList += sQuote;
511 if (pItems != pLastElement)
512 sFinalList += sSeparator;
515 if (!sFinalList.isEmpty())
516 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sFinalList);
518 exportedProperty( _rPropertyName );
521 OUString OPropertyExport::implConvertAny(const Any& _rValue)
523 OUStringBuffer aBuffer;
524 switch (_rValue.getValueTypeClass())
526 case TypeClass_STRING:
527 { // extract the string
528 OUString sCurrentValue;
529 _rValue >>= sCurrentValue;
530 aBuffer.append(sCurrentValue);
532 break;
533 case TypeClass_DOUBLE:
534 // let the unit converter format is as string
535 ::sax::Converter::convertDouble(aBuffer, getDouble(_rValue));
536 break;
537 case TypeClass_BOOLEAN:
538 aBuffer = getBOOL(_rValue) ? m_sValueTrue : m_sValueFalse;
539 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 ::sax::Converter::convertNumber(aBuffer, getINT32(_rValue));
546 break;
547 case TypeClass_UNSIGNED_LONG:
548 case TypeClass_HYPER:
549 ::sax::Converter::convertNumber(aBuffer, getINT64(_rValue));
550 break;
551 case TypeClass_UNSIGNED_HYPER:
552 ::sax::Converter::convertNumber(aBuffer, _rValue.get<sal_uInt64>());
553 break;
554 case TypeClass_ENUM:
556 // convert it into an int32
557 sal_Int32 nValue = 0;
558 ::cppu::enum2int(nValue, _rValue);
559 ::sax::Converter::convertNumber(aBuffer, nValue);
561 break;
562 default:
563 { // hmmm .... what else do we know?
564 double fValue = 0;
565 ::com::sun::star::util::Date aDate;
566 ::com::sun::star::util::Time aTime;
567 ::com::sun::star::util::DateTime aDateTime;
568 if (_rValue >>= aDate)
570 Date aToolsDate( Date::EMPTY );
571 ::utl::typeConvert(aDate, aToolsDate);
572 fValue = aToolsDate.GetDate();
574 else if (_rValue >>= aTime)
576 fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
577 aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
578 aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
579 aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
581 else if (_rValue >>= aDateTime)
583 DateTime aToolsDateTime( DateTime::EMPTY );
584 ::utl::typeConvert(aDateTime, aToolsDateTime);
585 // the time part (the digits behind the comma)
586 fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
587 aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
588 aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
589 aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
590 // plus the data part (the digits in front of the comma)
591 fValue += aToolsDateTime.GetDate();
593 else
595 // if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
597 // no more options ...
598 OSL_FAIL("OPropertyExport::implConvertAny: unsupported value type!");
599 break;
601 // let the unit converter format is as string
602 ::sax::Converter::convertDouble(aBuffer, fValue);
604 break;
607 return aBuffer.makeStringAndClear();
610 token::XMLTokenEnum OPropertyExport::implGetPropertyXMLType(const ::com::sun::star::uno::Type& _rType)
612 // handle the type description
613 switch (_rType.getTypeClass())
615 case TypeClass_STRING:
616 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 return token::XML_FLOAT;
624 case TypeClass_BOOLEAN:
625 return token::XML_BOOLEAN;
627 default:
628 return token::XML_FLOAT;
632 #ifdef DBG_UTIL
633 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, const sal_Char* _pName, const OUString& _rValue)
635 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(OUString::createFromAscii(_pName)).isEmpty(),
636 "OPropertyExport::AddAttribute: already have such an attribute");
638 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue);
641 void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue )
643 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName( _rName ).isEmpty(),
644 "OPropertyExport::AddAttribute: already have such an attribute");
646 m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue );
649 void OPropertyExport::AddAttributeASCII(sal_uInt16 _nPrefix, const sal_Char* _pName, const sal_Char *pValue)
651 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(OUString::createFromAscii(_pName)).isEmpty(),
652 "OPropertyExport::AddAttributeASCII: already have such an attribute");
654 m_rContext.getGlobalContext().AddAttributeASCII(_nPrefix, _pName, pValue);
657 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue)
659 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
660 "OPropertyExport::AddAttribute: already have such an attribute");
662 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue);
665 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
667 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
668 "OPropertyExport::AddAttribute: already have such an attribute");
670 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue);
673 void OPropertyExport::dbg_implCheckProperty(const OUString& _rPropertyName, const Type* _pType)
677 // the property must exist
678 if (!m_xPropertyInfo->hasPropertyByName(_rPropertyName))
680 SAL_WARN("xmloff.forms", "OPropertyExport: "
681 "no property with the name " + _rPropertyName + "!");
682 return;
685 if (_pType)
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!");
692 catch(Exception&)
694 OSL_FAIL("OPropertyExport::dbg_implCheckProperty: caught an exception, could not check the property!");
697 #endif // DBG_UTIL - dbg_implCheckProperty
699 } // namespace xmloff
701 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */