tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / forms / propertyexport.cxx
blobe40652ade9cb684a6be48e204697114024007d1d
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::beans;
52 // NO using namespace ...util !!!
53 // need a tools Date/Time/DateTime below, which would conflict with the uno types then
55 using namespace ::comphelper;
57 //= OPropertyExport
58 OPropertyExport::OPropertyExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxProps)
59 :m_rContext(_rContext)
60 ,m_xProps(_rxProps)
61 ,m_xPropertyInfo( m_xProps->getPropertySetInfo() )
62 ,m_xPropertyState( _rxProps, UNO_QUERY )
64 // caching
65 OUStringBuffer aBuffer;
66 ::sax::Converter::convertBool(aBuffer, true);
67 m_sValueTrue = aBuffer.makeStringAndClear();
68 ::sax::Converter::convertBool(aBuffer, false);
69 m_sValueFalse = aBuffer.makeStringAndClear();
71 OSL_ENSURE(m_xPropertyInfo.is(), "OPropertyExport::OPropertyExport: need an XPropertySetInfo!");
73 // collect the properties which need to be exported
74 examinePersistence();
77 bool OPropertyExport::shouldExportProperty( const OUString& i_propertyName ) const
79 // if the property state is DEFAULT, it does not need to be written - at least
80 // if it's a built-in property, and not a dynamically-added one.
81 bool bIsDefaultValue = m_xPropertyState.is()
82 && ( PropertyState_DEFAULT_VALUE == m_xPropertyState->getPropertyState( i_propertyName ) );
83 bool bIsDynamicProperty = m_xPropertyInfo.is()
84 && ( ( m_xPropertyInfo->getPropertyByName( i_propertyName ).Attributes & PropertyAttribute::REMOVABLE ) != 0 );
85 return ( !bIsDefaultValue || bIsDynamicProperty );
88 template< typename T > void
89 OPropertyExport::exportRemainingPropertiesSequence(
90 Any const & value, token::XMLTokenEnum eValueAttName)
92 css::uno::Sequence<T> anySeq;
93 bool bSuccess = value >>= anySeq;
94 assert(bSuccess); (void)bSuccess;
95 for (T const& i : anySeq)
97 OUString sValue(implConvertAny(Any(i)));
98 AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
99 SvXMLElementExport aValueTag(
100 m_rContext.getGlobalContext(), XML_NAMESPACE_FORM,
101 token::XML_LIST_VALUE, true, false);
105 void OPropertyExport::exportRemainingProperties()
107 // the properties tag (will be created if we have at least one no-default property)
108 std::unique_ptr<SvXMLElementExport> pPropertiesTag;
110 Any aValue;
111 OUString sValue;
113 // loop through all the properties which are yet to be exported
114 for ( const auto& rProperty : m_aRemainingProps )
116 DBG_CHECK_PROPERTY_NO_TYPE(rProperty);
118 if ( !shouldExportProperty( rProperty ) )
119 continue;
121 // now that we have the first sub-tag we need the form:properties element
122 if (!pPropertiesTag)
123 pPropertiesTag = std::make_unique<SvXMLElementExport>(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, token::XML_PROPERTIES, true, true);
125 // add the name attribute
126 AddAttribute(XML_NAMESPACE_FORM, token::XML_PROPERTY_NAME, rProperty);
128 // get the value
129 aValue = m_xProps->getPropertyValue(rProperty);
131 // the type to export
132 Type aExportType;
134 // is it a sequence
135 bool bIsSequence = TypeClass_SEQUENCE == aValue.getValueTypeClass();
136 // the type of the property, maybe reduced to the element type of a sequence
137 if (bIsSequence)
138 aExportType = getSequenceElementType( aValue.getValueType() );
139 else
140 aExportType = aValue.getValueType();
142 // the type attribute
144 bool bIsEmptyValue = TypeClass_VOID == aValue.getValueTypeClass();
145 if ( bIsEmptyValue )
147 css::beans::Property aPropDesc = m_xPropertyInfo->getPropertyByName( rProperty );
148 aExportType = aPropDesc.Type;
150 token::XMLTokenEnum eValueType = implGetPropertyXMLType( aExportType );
152 if ( bIsEmptyValue )
153 AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, token::XML_VOID );
154 else
155 AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, eValueType );
157 token::XMLTokenEnum eValueAttName( token::XML_VALUE );
158 switch ( eValueType )
160 case token::XML_BOOLEAN: eValueAttName = token::XML_BOOLEAN_VALUE; break;
161 case token::XML_STRING: eValueAttName = token::XML_STRING_VALUE; break;
162 default: break;
165 if( !bIsSequence && !bIsEmptyValue )
166 { // the simple case
168 sValue = implConvertAny(aValue);
169 AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
172 // start the property tag
173 SvXMLElementExport aValueTag1(m_rContext.getGlobalContext(),
174 XML_NAMESPACE_FORM,
175 bIsSequence ? token::XML_LIST_PROPERTY
176 : token::XML_PROPERTY, true, true);
178 if (!bIsSequence)
179 continue;
181 // the not-that-simple case, we need to iterate through the sequence elements
182 switch ( aExportType.getTypeClass() )
184 case TypeClass_STRING:
185 exportRemainingPropertiesSequence< OUString >(
186 aValue, eValueAttName);
187 break;
188 case TypeClass_DOUBLE:
189 exportRemainingPropertiesSequence< double >(
190 aValue, eValueAttName);
191 break;
192 case TypeClass_BOOLEAN:
193 exportRemainingPropertiesSequence< sal_Bool >(
194 aValue, eValueAttName);
195 break;
196 case TypeClass_BYTE:
197 exportRemainingPropertiesSequence< sal_Int8 >(
198 aValue, eValueAttName);
199 break;
200 case TypeClass_SHORT:
201 exportRemainingPropertiesSequence< sal_Int16 >(
202 aValue, eValueAttName);
203 break;
204 case TypeClass_LONG:
205 exportRemainingPropertiesSequence< sal_Int32 >(
206 aValue, eValueAttName);
207 break;
208 case TypeClass_HYPER:
209 exportRemainingPropertiesSequence< sal_Int64 >(
210 aValue, eValueAttName);
211 break;
212 default:
213 OSL_FAIL("OPropertyExport::exportRemainingProperties: unsupported sequence type !");
214 break;
219 void OPropertyExport::examinePersistence()
221 m_aRemainingProps.clear();
222 const Sequence< Property > aProperties = m_xPropertyInfo->getProperties();
223 for (const auto& rProp : aProperties)
225 // no transient props
226 if ( rProp.Attributes & PropertyAttribute::TRANSIENT )
227 continue;
228 // no read-only props
229 if ( ( rProp.Attributes & PropertyAttribute::READONLY ) != 0 )
230 // except they're dynamically added
231 if ( ( rProp.Attributes & PropertyAttribute::REMOVABLE ) == 0 )
232 continue;
233 m_aRemainingProps.insert(rProp.Name);
237 void OPropertyExport::exportStringPropertyAttribute( const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
238 const OUString& _rPropertyName )
240 DBG_CHECK_PROPERTY( _rPropertyName, OUString );
242 // no try-catch here, this would be too expensive. The outer scope has to handle exceptions (which should not
243 // happen if we're used correctly :)
245 // this is way simple, as we don't need to convert anything (the property already is a string)
247 // get the string
248 OUString sPropValue;
249 m_xProps->getPropertyValue( _rPropertyName ) >>= sPropValue;
251 // add the attribute
252 if ( !sPropValue.isEmpty() )
253 AddAttribute( _nNamespaceKey, _pAttributeName, sPropValue );
255 // the property does not need to be handled anymore
256 exportedProperty( _rPropertyName );
259 void OPropertyExport::exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
260 const OUString& _rPropertyName, const BoolAttrFlags _nBooleanAttributeFlags)
262 DBG_CHECK_PROPERTY_NO_TYPE( _rPropertyName );
263 // no check of the property value type: this method is allowed to be called with any integer properties
264 // (e.g. sal_Int32, sal_uInt16 etc)
266 bool bDefault(BoolAttrFlags::DefaultTrue & _nBooleanAttributeFlags);
267 bool bDefaultVoid(BoolAttrFlags::DefaultVoid & _nBooleanAttributeFlags);
269 // get the value
270 bool bCurrentValue = bDefault;
271 Any aCurrentValue = m_xProps->getPropertyValue( _rPropertyName );
272 if (aCurrentValue.hasValue())
274 bCurrentValue = ::cppu::any2bool(aCurrentValue);
275 // this will extract a boolean value even if the Any contains a int or short or something like that ...
277 if (_nBooleanAttributeFlags & BoolAttrFlags::InverseSemantics)
278 bCurrentValue = !bCurrentValue;
280 // we have a non-void current value
281 if (bDefaultVoid || (bDefault != bCurrentValue))
282 // and (the default is void, or the non-void default does not equal the current value)
283 // -> write the attribute
284 AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
286 else
287 // we have a void current value
288 if (!bDefaultVoid)
289 // and we have a non-void default
290 // -> write the attribute
291 AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
293 // the property does not need to be handled anymore
294 exportedProperty( _rPropertyName );
297 void OPropertyExport::exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
298 const OUString& _rPropertyName, const sal_Int16 _nDefault, bool force)
300 DBG_CHECK_PROPERTY( _rPropertyName, sal_Int16 );
302 // get the value
303 sal_Int16 nCurrentValue(_nDefault);
304 m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
306 // add the attribute
307 if (force || _nDefault != nCurrentValue)
309 // let the formatter of the export context build a string
310 AddAttribute(_nNamespaceKey, _pAttributeName, OUString::number(nCurrentValue));
313 // the property does not need to be handled anymore
314 exportedProperty( _rPropertyName );
317 void OPropertyExport::exportInt32PropertyAttribute( const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
318 const OUString& _rPropertyName, const sal_Int32 _nDefault )
320 DBG_CHECK_PROPERTY( _rPropertyName, sal_Int32 );
322 // get the value
323 sal_Int32 nCurrentValue( _nDefault );
324 m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
326 // add the attribute
327 if ( _nDefault != nCurrentValue )
329 // let the formatter of the export context build a string
330 AddAttribute( _nNamespaceKey, _pAttributeName, OUString::number(nCurrentValue) );
333 // the property does not need to be handled anymore
334 exportedProperty( _rPropertyName );
337 void OPropertyExport::exportEnumPropertyAttributeImpl(
338 const sal_uInt16 _nNamespaceKey, const OUString& _pAttributeName,
339 const OUString &rPropertyName, const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
340 const sal_uInt16 _nDefault, const bool _bVoidDefault)
342 // get the value
343 Any aValue = m_xProps->getPropertyValue(rPropertyName);
345 if (aValue.hasValue())
346 { // we have a non-void current value
347 sal_Int32 nCurrentValue(_nDefault);
348 ::cppu::enum2int(nCurrentValue, aValue);
350 // add the attribute
351 if ((_nDefault != nCurrentValue) || _bVoidDefault)
352 { // the default does not equal the value, or the default is void and the value isn't
354 // let the formatter of the export context build a string
355 OUStringBuffer sBuffer;
356 SvXMLUnitConverter::convertEnum(sBuffer, static_cast<sal_uInt16>(nCurrentValue), _pValueMap);
358 AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
361 else
363 if (!_bVoidDefault)
364 AddAttribute(_nNamespaceKey, _pAttributeName, OUString());
367 // the property does not need to be handled anymore
368 exportedProperty(rPropertyName);
371 void OPropertyExport::exportTargetFrameAttribute()
373 DBG_CHECK_PROPERTY( PROPERTY_TARGETFRAME, OUString );
375 OUString sTargetFrame = comphelper::getString(m_xProps->getPropertyValue(PROPERTY_TARGETFRAME));
376 if( sTargetFrame != "_blank" )
377 { // an empty string and "_blank" have the same meaning and don't have to be written
378 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(CCAFlags::TargetFrame)
379 ,OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetFrame)
380 ,sTargetFrame);
383 exportedProperty(PROPERTY_TARGETFRAME);
386 void OPropertyExport::exportRelativeTargetLocation(const OUString& _sPropertyName,CCAFlags _nProperty,bool _bAddType)
388 Any aAny = m_xProps->getPropertyValue(_sPropertyName);
390 OUString sTargetLocation;
391 if (aAny.has<uno::Reference<graphic::XGraphic>>())
393 auto xGraphic = aAny.get<uno::Reference<graphic::XGraphic>>();
394 OUString sOutMimeType;
395 sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedXGraphic(xGraphic, sOutMimeType);
397 else if (aAny.has<OUString>())
399 auto sURL = aAny.get<OUString>();
400 sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedObject(sURL);
402 else
404 SAL_WARN("xmloff.forms", "OPropertyExport::exportRelativeTargetLocation: "
405 "Value of " << _sPropertyName << " not found!");
408 if (!sTargetLocation.isEmpty())
410 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(_nProperty)
411 ,OAttributeMetaData::getCommonControlAttributeName(_nProperty)
412 , sTargetLocation);
414 // #i110911# add xlink:type="simple" if required
415 if (_bAddType)
416 AddAttribute(XML_NAMESPACE_XLINK, token::XML_TYPE, token::XML_SIMPLE);
418 exportedProperty(_sPropertyName);
421 void OPropertyExport::flagStyleProperties()
423 // flag all the properties which are part of the style as "handled"
424 rtl::Reference< XMLPropertySetMapper > xStylePropertiesSupplier = m_rContext.getStylePropertyMapper()->getPropertySetMapper();
425 for (sal_Int32 i=0; i<xStylePropertiesSupplier->GetEntryCount(); ++i)
426 exportedProperty(xStylePropertiesSupplier->GetEntryAPIName(i));
428 // the font properties are exported as single properties, but there is a FontDescriptor property which
429 // collects them all-in-one, this has been exported implicitly
430 exportedProperty(PROPERTY_FONT);
432 // for the DateFormat and TimeFormat, there exist wrapper properties which has been exported as
433 // style, too
434 exportedProperty(PROPERTY_DATEFORMAT);
435 exportedProperty(PROPERTY_TIMEFORMAT);
437 // the following properties should have been exported at the shape already:
438 exportedProperty( u"VerticalAlign"_ustr );
439 exportedProperty( u"WritingMode"_ustr );
440 exportedProperty( u"ScaleMode"_ustr );
441 // ditto the TextWritingMode
442 exportedProperty( u"WritingMode"_ustr );
445 void OPropertyExport::exportGenericPropertyAttribute(
446 const sal_uInt16 _nAttributeNamespaceKey, const OUString& _pAttributeName, const OUString& sPropertyName)
448 DBG_CHECK_PROPERTY_NO_TYPE( sPropertyName );
450 exportedProperty(sPropertyName);
452 Any aCurrentValue = m_xProps->getPropertyValue(sPropertyName);
453 if (!aCurrentValue.hasValue())
454 // nothing to do without a concrete value
455 return;
457 OUString sValue = implConvertAny(aCurrentValue);
458 if (sValue.isEmpty() && (TypeClass_STRING == aCurrentValue.getValueTypeClass()))
460 // check whether or not the property is allowed to be VOID
461 Property aProperty = m_xPropertyInfo->getPropertyByName(sPropertyName);
462 if ((aProperty.Attributes & PropertyAttribute::MAYBEVOID) == 0)
463 // the string is empty, and the property is not allowed to be void
464 // -> don't need to write the attribute, 'cause missing it is unambiguous
465 return;
468 // finally add the attribute to the context
469 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sValue);
472 void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const OUString& _pAttributeName,
473 const OUString& _rPropertyName)
475 const sal_Unicode _aListSeparator = ',';
476 const sal_Unicode _aQuoteCharacter = '"';
477 DBG_CHECK_PROPERTY( _rPropertyName, Sequence< OUString > );
479 Sequence< OUString > aItems;
480 m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
482 OUStringBuffer sFinalList;
484 // unfortunately the OUString can't append single sal_Unicode characters ...
485 const OUString sQuote(&_aQuoteCharacter, 1);
486 const OUString sSeparator(&_aListSeparator, 1);
487 const bool bQuote = !sQuote.isEmpty();
489 // concatenate the string items
490 const OUString* pItems = aItems.getConstArray();
491 const OUString* pEnd = pItems + aItems.getLength();
492 const OUString* pLastElement = pEnd - 1;
493 for ( ;
494 pItems != pEnd;
495 ++pItems
498 OSL_ENSURE(-1 == pItems->indexOf(_aQuoteCharacter),
499 "OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
501 if (bQuote)
502 sFinalList.append(sQuote);
503 sFinalList.append(*pItems);
504 if (bQuote)
505 sFinalList.append(sQuote);
507 if (pItems != pLastElement)
508 sFinalList.append(sSeparator);
511 if (!sFinalList.isEmpty())
512 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sFinalList.makeStringAndClear());
514 exportedProperty( _rPropertyName );
517 OUString OPropertyExport::implConvertAny(const Any& _rValue)
519 OUStringBuffer aBuffer;
520 switch (_rValue.getValueTypeClass())
522 case TypeClass_STRING:
523 { // extract the string
524 OUString sCurrentValue;
525 _rValue >>= sCurrentValue;
526 aBuffer.append(sCurrentValue);
528 break;
529 case TypeClass_DOUBLE:
530 // let the unit converter format is as string
531 ::sax::Converter::convertDouble(aBuffer, getDouble(_rValue));
532 break;
533 case TypeClass_BOOLEAN:
534 aBuffer = getBOOL(_rValue) ? m_sValueTrue : m_sValueFalse;
535 break;
536 case TypeClass_BYTE:
537 case TypeClass_UNSIGNED_SHORT:
538 case TypeClass_SHORT:
539 case TypeClass_LONG:
540 // let the unit converter format is as string
541 aBuffer.append(getINT32(_rValue));
542 break;
543 case TypeClass_UNSIGNED_LONG:
544 case TypeClass_HYPER:
545 aBuffer.append(getINT64(_rValue));
546 break;
547 case TypeClass_UNSIGNED_HYPER:
548 aBuffer.append(static_cast<sal_Int64>(_rValue.get<sal_uInt64>()));
549 break;
550 case TypeClass_ENUM:
552 // convert it into an int32
553 sal_Int32 nValue = 0;
554 ::cppu::enum2int(nValue, _rValue);
555 aBuffer.append(nValue);
557 break;
558 default:
559 { // hmmm... what else do we know?
560 double fValue = 0;
561 css::util::Date aDate;
562 css::util::Time aTime;
563 css::util::DateTime aDateTime;
564 if (_rValue >>= aDate)
566 Date aToolsDate( Date::EMPTY );
567 ::utl::typeConvert(aDate, aToolsDate);
568 fValue = aToolsDate.GetDate();
570 else if (_rValue >>= aTime)
572 fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
573 aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
574 aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
575 aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
577 else if (_rValue >>= aDateTime)
579 DateTime aToolsDateTime( DateTime::EMPTY );
580 ::utl::typeConvert(aDateTime, aToolsDateTime);
581 // the time part (the digits behind the comma)
582 fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
583 aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
584 aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
585 aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
586 // plus the data part (the digits in front of the comma)
587 fValue += aToolsDateTime.GetDate();
589 else
591 // if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
593 // no more options ...
594 OSL_FAIL("OPropertyExport::implConvertAny: unsupported value type!");
595 break;
597 // let the unit converter format is as string
598 ::sax::Converter::convertDouble(aBuffer, fValue);
600 break;
603 return aBuffer.makeStringAndClear();
606 token::XMLTokenEnum OPropertyExport::implGetPropertyXMLType(const css::uno::Type& _rType)
608 // handle the type description
609 switch (_rType.getTypeClass())
611 case TypeClass_STRING:
612 return token::XML_STRING;
613 case TypeClass_DOUBLE:
614 case TypeClass_BYTE:
615 case TypeClass_SHORT:
616 case TypeClass_LONG:
617 case TypeClass_HYPER:
618 case TypeClass_ENUM:
619 return token::XML_FLOAT;
620 case TypeClass_BOOLEAN:
621 return token::XML_BOOLEAN;
623 default:
624 return token::XML_FLOAT;
628 #ifdef DBG_UTIL
629 void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue )
631 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName( _rName ).isEmpty(),
632 "OPropertyExport::AddAttribute: already have such an attribute");
634 m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue );
637 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue)
639 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
640 "OPropertyExport::AddAttribute: already have such an attribute");
642 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue);
645 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
647 OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
648 "OPropertyExport::AddAttribute: already have such an attribute");
650 m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue);
653 void OPropertyExport::dbg_implCheckProperty(const OUString& _rPropertyName, const Type* _pType)
657 // the property must exist
658 if (!m_xPropertyInfo->hasPropertyByName(_rPropertyName))
660 SAL_WARN("xmloff.forms", "OPropertyExport: "
661 "no property with the name " + _rPropertyName + "!");
662 return;
665 if (_pType)
667 // and it must have the correct type
668 Property aPropertyDescription = m_xPropertyInfo->getPropertyByName(_rPropertyName);
669 OSL_ENSURE(aPropertyDescription.Type.equals(*_pType), "OPropertyExport::dbg_implCheckProperty: invalid property type!");
672 catch(Exception&)
674 TOOLS_WARN_EXCEPTION("xmloff.forms", "could not check the property!");
677 #endif // DBG_UTIL - dbg_implCheckProperty
679 } // namespace xmloff
681 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */