bump product version to 7.6.3.2-android
[LibreOffice.git] / xmloff / source / forms / propertyexport.cxx
blob4015a67a7129b5c8d0e27f2702f6fc8572bc6592
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"
22 #include <memory>
24 #include <xmloff/xmlexp.hxx>
25 #include "strings.hxx"
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <xmloff/xmlexppr.hxx>
29 #include <xmloff/xmlprmap.hxx>
30 #include <sax/tools/converter.hxx>
31 #include <sal/log.hxx>
32 #include <comphelper/diagnose_ex.hxx>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/util/Date.hpp>
35 #include <com/sun/star/graphic/XGraphic.hpp>
36 #include <com/sun/star/util/Time.hpp>
37 #include <com/sun/star/util/DateTime.hpp>
38 #include <comphelper/extract.hxx>
39 #include <comphelper/types.hxx>
40 #include "callbacks.hxx"
41 #include <unotools/datetime.hxx>
42 #include <tools/date.hxx>
43 #include <tools/datetime.hxx>
45 namespace xmloff
48 using namespace css;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::lang;
51 using namespace ::com::sun::star::beans;
53 // NO using namespace ...util !!!
54 // need a tools Date/Time/DateTime below, which would conflict with the uno types then
56 using namespace ::comphelper;
58 //= OPropertyExport
59 OPropertyExport::OPropertyExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxProps)
60 :m_rContext(_rContext)
61 ,m_xProps(_rxProps)
62 ,m_xPropertyInfo( m_xProps->getPropertySetInfo() )
63 ,m_xPropertyState( _rxProps, UNO_QUERY )
65 // caching
66 OUStringBuffer aBuffer;
67 ::sax::Converter::convertBool(aBuffer, true);
68 m_sValueTrue = aBuffer.makeStringAndClear();
69 ::sax::Converter::convertBool(aBuffer, false);
70 m_sValueFalse = aBuffer.makeStringAndClear();
72 OSL_ENSURE(m_xPropertyInfo.is(), "OPropertyExport::OPropertyExport: need an XPropertySetInfo!");
74 // collect the properties which need to be exported
75 examinePersistence();
78 bool OPropertyExport::shouldExportProperty( const OUString& i_propertyName ) const
80 // if the property state is DEFAULT, it does not need to be written - at least
81 // if it's a built-in property, and not a dynamically-added one.
82 bool bIsDefaultValue = m_xPropertyState.is()
83 && ( PropertyState_DEFAULT_VALUE == m_xPropertyState->getPropertyState( i_propertyName ) );
84 bool bIsDynamicProperty = m_xPropertyInfo.is()
85 && ( ( m_xPropertyInfo->getPropertyByName( i_propertyName ).Attributes & PropertyAttribute::REMOVABLE ) != 0 );
86 return ( !bIsDefaultValue || bIsDynamicProperty );
89 template< typename T > void
90 OPropertyExport::exportRemainingPropertiesSequence(
91 Any const & value, token::XMLTokenEnum eValueAttName)
93 css::uno::Sequence<T> anySeq;
94 bool bSuccess = value >>= anySeq;
95 assert(bSuccess); (void)bSuccess;
96 for (T const & i : std::as_const(anySeq))
98 OUString sValue(implConvertAny(Any(i)));
99 AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
100 SvXMLElementExport aValueTag(
101 m_rContext.getGlobalContext(), XML_NAMESPACE_FORM,
102 token::XML_LIST_VALUE, true, false);
106 void OPropertyExport::exportRemainingProperties()
108 // the properties tag (will be created if we have at least one no-default property)
109 std::unique_ptr<SvXMLElementExport> pPropertiesTag;
111 Any aValue;
112 OUString sValue;
114 // loop through all the properties which are yet to be exported
115 for ( const auto& rProperty : m_aRemainingProps )
117 DBG_CHECK_PROPERTY_NO_TYPE(rProperty);
119 if ( !shouldExportProperty( rProperty ) )
120 continue;
122 // now that we have the first sub-tag we need the form:properties element
123 if (!pPropertiesTag)
124 pPropertiesTag = std::make_unique<SvXMLElementExport>(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, token::XML_PROPERTIES, true, true);
126 // add the name attribute
127 AddAttribute(XML_NAMESPACE_FORM, token::XML_PROPERTY_NAME, rProperty);
129 // get the value
130 aValue = m_xProps->getPropertyValue(rProperty);
132 // the type to export
133 Type aExportType;
135 // is it a sequence
136 bool bIsSequence = TypeClass_SEQUENCE == aValue.getValueTypeClass();
137 // the type of the property, maybe reduced to the element type of a sequence
138 if (bIsSequence)
139 aExportType = getSequenceElementType( aValue.getValueType() );
140 else
141 aExportType = aValue.getValueType();
143 // the type attribute
145 bool bIsEmptyValue = TypeClass_VOID == aValue.getValueType().getTypeClass();
146 if ( bIsEmptyValue )
148 css::beans::Property aPropDesc = m_xPropertyInfo->getPropertyByName( rProperty );
149 aExportType = aPropDesc.Type;
151 token::XMLTokenEnum eValueType = implGetPropertyXMLType( aExportType );
153 if ( bIsEmptyValue )
154 AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, token::XML_VOID );
155 else
156 AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, eValueType );
158 token::XMLTokenEnum eValueAttName( token::XML_VALUE );
159 switch ( eValueType )
161 case token::XML_BOOLEAN: eValueAttName = token::XML_BOOLEAN_VALUE; break;
162 case token::XML_STRING: eValueAttName = token::XML_STRING_VALUE; break;
163 default: break;
166 if( !bIsSequence && !bIsEmptyValue )
167 { // the simple case
169 sValue = implConvertAny(aValue);
170 AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
173 // start the property tag
174 SvXMLElementExport aValueTag1(m_rContext.getGlobalContext(),
175 XML_NAMESPACE_FORM,
176 bIsSequence ? token::XML_LIST_PROPERTY
177 : token::XML_PROPERTY, true, true);
179 if (!bIsSequence)
180 continue;
182 // the not-that-simple case, we need to iterate through the sequence elements
183 switch ( aExportType.getTypeClass() )
185 case TypeClass_STRING:
186 exportRemainingPropertiesSequence< OUString >(
187 aValue, eValueAttName);
188 break;
189 case TypeClass_DOUBLE:
190 exportRemainingPropertiesSequence< double >(
191 aValue, eValueAttName);
192 break;
193 case TypeClass_BOOLEAN:
194 exportRemainingPropertiesSequence< sal_Bool >(
195 aValue, eValueAttName);
196 break;
197 case TypeClass_BYTE:
198 exportRemainingPropertiesSequence< sal_Int8 >(
199 aValue, eValueAttName);
200 break;
201 case TypeClass_SHORT:
202 exportRemainingPropertiesSequence< sal_Int16 >(
203 aValue, eValueAttName);
204 break;
205 case TypeClass_LONG:
206 exportRemainingPropertiesSequence< sal_Int32 >(
207 aValue, eValueAttName);
208 break;
209 case TypeClass_HYPER:
210 exportRemainingPropertiesSequence< sal_Int64 >(
211 aValue, eValueAttName);
212 break;
213 default:
214 OSL_FAIL("OPropertyExport::exportRemainingProperties: unsupported sequence type !");
215 break;
220 void OPropertyExport::examinePersistence()
222 m_aRemainingProps.clear();
223 const Sequence< Property > aProperties = m_xPropertyInfo->getProperties();
224 for (const auto& rProp : aProperties)
226 // no transient props
227 if ( rProp.Attributes & PropertyAttribute::TRANSIENT )
228 continue;
229 // no read-only props
230 if ( ( rProp.Attributes & PropertyAttribute::READONLY ) != 0 )
231 // except they're dynamically added
232 if ( ( rProp.Attributes & PropertyAttribute::REMOVABLE ) == 0 )
233 continue;
234 m_aRemainingProps.insert(rProp.Name);
238 void OPropertyExport::exportStringPropertyAttribute( const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
239 const OUString& _rPropertyName )
241 DBG_CHECK_PROPERTY( _rPropertyName, OUString );
243 // no try-catch here, this would be too expensive. The outer scope has to handle exceptions (which should not
244 // happen if we're used correctly :)
246 // this is way simple, as we don't need to convert anything (the property already is a string)
248 // get the string
249 OUString sPropValue;
250 m_xProps->getPropertyValue( _rPropertyName ) >>= sPropValue;
252 // add the attribute
253 if ( !sPropValue.isEmpty() )
254 AddAttribute( _nNamespaceKey, _pAttributeName, sPropValue );
256 // the property does not need to be handled anymore
257 exportedProperty( _rPropertyName );
260 void OPropertyExport::exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
261 const OUString& _rPropertyName, const BoolAttrFlags _nBooleanAttributeFlags)
263 DBG_CHECK_PROPERTY_NO_TYPE( _rPropertyName );
264 // no check of the property value type: this method is allowed to be called with any integer properties
265 // (e.g. sal_Int32, sal_uInt16 etc)
267 bool bDefault(BoolAttrFlags::DefaultTrue & _nBooleanAttributeFlags);
268 bool bDefaultVoid(BoolAttrFlags::DefaultVoid & _nBooleanAttributeFlags);
270 // get the value
271 bool bCurrentValue = bDefault;
272 Any aCurrentValue = m_xProps->getPropertyValue( _rPropertyName );
273 if (aCurrentValue.hasValue())
275 bCurrentValue = ::cppu::any2bool(aCurrentValue);
276 // this will extract a boolean value even if the Any contains a int or short or something like that ...
278 if (_nBooleanAttributeFlags & BoolAttrFlags::InverseSemantics)
279 bCurrentValue = !bCurrentValue;
281 // we have a non-void current value
282 if (bDefaultVoid || (bDefault != bCurrentValue))
283 // and (the default is void, or the non-void default does not equal the current value)
284 // -> write the attribute
285 AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
287 else
288 // we have a void current value
289 if (!bDefaultVoid)
290 // and we have a non-void default
291 // -> write the attribute
292 AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
294 // the property does not need to be handled anymore
295 exportedProperty( _rPropertyName );
298 void OPropertyExport::exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
299 const OUString& _rPropertyName, const sal_Int16 _nDefault, bool force)
301 DBG_CHECK_PROPERTY( _rPropertyName, sal_Int16 );
303 // get the value
304 sal_Int16 nCurrentValue(_nDefault);
305 m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
307 // add the attribute
308 if (force || _nDefault != nCurrentValue)
310 // let the formatter of the export context build a string
311 AddAttribute(_nNamespaceKey, _pAttributeName, OUString::number(nCurrentValue));
314 // the property does not need to be handled anymore
315 exportedProperty( _rPropertyName );
318 void OPropertyExport::exportInt32PropertyAttribute( const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
319 const OUString& _rPropertyName, const sal_Int32 _nDefault )
321 DBG_CHECK_PROPERTY( _rPropertyName, sal_Int32 );
323 // get the value
324 sal_Int32 nCurrentValue( _nDefault );
325 m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
327 // add the attribute
328 if ( _nDefault != nCurrentValue )
330 // let the formatter of the export context build a string
331 AddAttribute( _nNamespaceKey, _pAttributeName, OUString::number(nCurrentValue) );
334 // the property does not need to be handled anymore
335 exportedProperty( _rPropertyName );
338 void OPropertyExport::exportEnumPropertyAttributeImpl(
339 const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
340 const OUString &rPropertyName, const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
341 const sal_uInt16 _nDefault, const bool _bVoidDefault)
343 // get the value
344 Any aValue = m_xProps->getPropertyValue(rPropertyName);
346 if (aValue.hasValue())
347 { // we have a non-void current value
348 sal_Int32 nCurrentValue(_nDefault);
349 ::cppu::enum2int(nCurrentValue, aValue);
351 // add the attribute
352 if ((_nDefault != nCurrentValue) || _bVoidDefault)
353 { // the default does not equal the value, or the default is void and the value isn't
355 // let the formatter of the export context build a string
356 OUStringBuffer sBuffer;
357 SvXMLUnitConverter::convertEnum(sBuffer, static_cast<sal_uInt16>(nCurrentValue), _pValueMap);
359 AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
362 else
364 if (!_bVoidDefault)
365 AddAttribute(_nNamespaceKey, _pAttributeName, OUString());
368 // the property does not need to be handled anymore
369 exportedProperty(rPropertyName);
372 void OPropertyExport::exportTargetFrameAttribute()
374 DBG_CHECK_PROPERTY( PROPERTY_TARGETFRAME, OUString );
376 OUString sTargetFrame = comphelper::getString(m_xProps->getPropertyValue(PROPERTY_TARGETFRAME));
377 if( sTargetFrame != "_blank" )
378 { // an empty string and "_blank" have the same meaning and don't have to be written
379 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::TargetFrame)
380 ,OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetFrame)
381 ,sTargetFrame);
384 exportedProperty(PROPERTY_TARGETFRAME);
387 void OPropertyExport::exportRelativeTargetLocation(const OUString& _sPropertyName,CCAFlags _nProperty,bool _bAddType)
389 Any aAny = m_xProps->getPropertyValue(_sPropertyName);
391 OUString sTargetLocation;
392 if (aAny.has<uno::Reference<graphic::XGraphic>>())
394 auto xGraphic = aAny.get<uno::Reference<graphic::XGraphic>>();
395 OUString sOutMimeType;
396 sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedXGraphic(xGraphic, sOutMimeType);
398 else if (aAny.has<OUString>())
400 auto sURL = aAny.get<OUString>();
401 sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedObject(sURL);
403 else
405 SAL_WARN("xmloff.forms", "OPropertyExport::exportRelativeTargetLocation: "
406 "Value of " << _sPropertyName << " not found!");
409 if (!sTargetLocation.isEmpty())
411 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(_nProperty)
412 ,OAttributeMetaData::getCommonControlAttributeName(_nProperty)
413 , sTargetLocation);
415 // #i110911# add xlink:type="simple" if required
416 if (_bAddType)
417 AddAttribute(XML_NAMESPACE_XLINK, token::XML_TYPE, token::XML_SIMPLE);
419 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 OUString& _pAttributeName, const OUString& sPropertyName)
449 DBG_CHECK_PROPERTY_NO_TYPE( sPropertyName );
451 exportedProperty(sPropertyName);
453 Any aCurrentValue = m_xProps->getPropertyValue(sPropertyName);
454 if (!aCurrentValue.hasValue())
455 // nothing to do without a concrete value
456 return;
458 OUString sValue = implConvertAny(aCurrentValue);
459 if (sValue.isEmpty() && (TypeClass_STRING == aCurrentValue.getValueTypeClass()))
461 // check whether or not the property is allowed to be VOID
462 Property aProperty = m_xPropertyInfo->getPropertyByName(sPropertyName);
463 if ((aProperty.Attributes & PropertyAttribute::MAYBEVOID) == 0)
464 // the string is empty, and the property is not allowed to be void
465 // -> don't need to write the attribute, 'cause missing it is unambiguous
466 return;
469 // finally add the attribute to the context
470 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sValue);
473 void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const OUString& _pAttributeName,
474 const OUString& _rPropertyName)
476 const sal_Unicode _aListSeparator = ',';
477 const sal_Unicode _aQuoteCharacter = '"';
478 DBG_CHECK_PROPERTY( _rPropertyName, Sequence< OUString > );
480 Sequence< OUString > aItems;
481 m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
483 OUStringBuffer sFinalList;
485 // unfortunately the OUString can't append single sal_Unicode characters ...
486 const OUString sQuote(&_aQuoteCharacter, 1);
487 const OUString sSeparator(&_aListSeparator, 1);
488 const bool bQuote = !sQuote.isEmpty();
490 // concatenate the string items
491 const OUString* pItems = aItems.getConstArray();
492 const OUString* pEnd = pItems + aItems.getLength();
493 const OUString* pLastElement = pEnd - 1;
494 for ( ;
495 pItems != pEnd;
496 ++pItems
499 OSL_ENSURE(-1 == pItems->indexOf(_aQuoteCharacter),
500 "OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
502 if (bQuote)
503 sFinalList.append(sQuote);
504 sFinalList.append(*pItems);
505 if (bQuote)
506 sFinalList.append(sQuote);
508 if (pItems != pLastElement)
509 sFinalList.append(sSeparator);
512 if (!sFinalList.isEmpty())
513 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sFinalList.makeStringAndClear());
515 exportedProperty( _rPropertyName );
518 OUString OPropertyExport::implConvertAny(const Any& _rValue)
520 OUStringBuffer aBuffer;
521 switch (_rValue.getValueTypeClass())
523 case TypeClass_STRING:
524 { // extract the string
525 OUString sCurrentValue;
526 _rValue >>= sCurrentValue;
527 aBuffer.append(sCurrentValue);
529 break;
530 case TypeClass_DOUBLE:
531 // let the unit converter format is as string
532 ::sax::Converter::convertDouble(aBuffer, getDouble(_rValue));
533 break;
534 case TypeClass_BOOLEAN:
535 aBuffer = getBOOL(_rValue) ? m_sValueTrue : m_sValueFalse;
536 break;
537 case TypeClass_BYTE:
538 case TypeClass_UNSIGNED_SHORT:
539 case TypeClass_SHORT:
540 case TypeClass_LONG:
541 // let the unit converter format is as string
542 aBuffer.append(getINT32(_rValue));
543 break;
544 case TypeClass_UNSIGNED_LONG:
545 case TypeClass_HYPER:
546 aBuffer.append(getINT64(_rValue));
547 break;
548 case TypeClass_UNSIGNED_HYPER:
549 aBuffer.append(static_cast<sal_Int64>(_rValue.get<sal_uInt64>()));
550 break;
551 case TypeClass_ENUM:
553 // convert it into an int32
554 sal_Int32 nValue = 0;
555 ::cppu::enum2int(nValue, _rValue);
556 aBuffer.append(nValue);
558 break;
559 default:
560 { // hmmm... what else do we know?
561 double fValue = 0;
562 css::util::Date aDate;
563 css::util::Time aTime;
564 css::util::DateTime aDateTime;
565 if (_rValue >>= aDate)
567 Date aToolsDate( Date::EMPTY );
568 ::utl::typeConvert(aDate, aToolsDate);
569 fValue = aToolsDate.GetDate();
571 else if (_rValue >>= aTime)
573 fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
574 aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
575 aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
576 aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
578 else if (_rValue >>= aDateTime)
580 DateTime aToolsDateTime( DateTime::EMPTY );
581 ::utl::typeConvert(aDateTime, aToolsDateTime);
582 // the time part (the digits behind the comma)
583 fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
584 aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
585 aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
586 aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
587 // plus the data part (the digits in front of the comma)
588 fValue += aToolsDateTime.GetDate();
590 else
592 // if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
594 // no more options ...
595 OSL_FAIL("OPropertyExport::implConvertAny: unsupported value type!");
596 break;
598 // let the unit converter format is as string
599 ::sax::Converter::convertDouble(aBuffer, fValue);
601 break;
604 return aBuffer.makeStringAndClear();
607 token::XMLTokenEnum OPropertyExport::implGetPropertyXMLType(const css::uno::Type& _rType)
609 // handle the type description
610 switch (_rType.getTypeClass())
612 case TypeClass_STRING:
613 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 return token::XML_FLOAT;
621 case TypeClass_BOOLEAN:
622 return token::XML_BOOLEAN;
624 default:
625 return token::XML_FLOAT;
629 #ifdef DBG_UTIL
630 void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue )
632 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName( _rName ).isEmpty(),
633 "OPropertyExport::AddAttribute: already have such an attribute");
635 m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue );
638 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue)
640 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
641 "OPropertyExport::AddAttribute: already have such an attribute");
643 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue);
646 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
648 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
649 "OPropertyExport::AddAttribute: already have such an attribute");
651 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue);
654 void OPropertyExport::dbg_implCheckProperty(const OUString& _rPropertyName, const Type* _pType)
658 // the property must exist
659 if (!m_xPropertyInfo->hasPropertyByName(_rPropertyName))
661 SAL_WARN("xmloff.forms", "OPropertyExport: "
662 "no property with the name " + _rPropertyName + "!");
663 return;
666 if (_pType)
668 // and it must have the correct type
669 Property aPropertyDescription = m_xPropertyInfo->getPropertyByName(_rPropertyName);
670 OSL_ENSURE(aPropertyDescription.Type.equals(*_pType), "OPropertyExport::dbg_implCheckProperty: invalid property type!");
673 catch(Exception&)
675 TOOLS_WARN_EXCEPTION("xmloff.forms", "could not check the property!");
678 #endif // DBG_UTIL - dbg_implCheckProperty
680 } // namespace xmloff
682 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */