1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include "propertyexport.hxx"
23 #include <xmloff/xmlexp.hxx>
24 #include "strings.hxx"
25 #include "xmloff/xmlnmspe.hxx"
26 #include <xmloff/xmluconv.hxx>
27 #include <xmloff/families.hxx>
28 #include <sax/tools/converter.hxx>
29 #include <osl/diagnose.h>
30 #include <rtl/strbuf.hxx>
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/util/Date.hpp>
33 #include <com/sun/star/util/Time.hpp>
34 #include <com/sun/star/util/DateTime.hpp>
35 #include <comphelper/extract.hxx>
36 #include <comphelper/sequence.hxx>
37 #include <comphelper/types.hxx>
38 #include "callbacks.hxx"
39 #include <unotools/datetime.hxx>
40 #include <tools/date.hxx>
41 #include <tools/datetime.hxx>
43 //.........................................................................
46 //.........................................................................
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::lang
;
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 //=====================================================================
59 //=====================================================================
60 //---------------------------------------------------------------------
61 OPropertyExport::OPropertyExport(IFormsExportContext
& _rContext
, const Reference
< XPropertySet
>& _rxProps
)
62 :m_rContext(_rContext
)
64 ,m_xPropertyInfo( m_xProps
->getPropertySetInfo() )
65 ,m_xPropertyState( _rxProps
, UNO_QUERY
)
68 OUStringBuffer aBuffer
;
69 ::sax::Converter::convertBool(aBuffer
, true);
70 m_sValueTrue
= aBuffer
.makeStringAndClear();
71 ::sax::Converter::convertBool(aBuffer
, false);
72 m_sValueFalse
= aBuffer
.makeStringAndClear();
74 OSL_ENSURE(m_xPropertyInfo
.is(), "OPropertyExport::OPropertyExport: need an XPropertySetInfo!");
76 // collect the properties which need to be exported
80 //---------------------------------------------------------------------
81 bool OPropertyExport::shouldExportProperty( const OUString
& i_propertyName
) const
83 // if the property state is DEFAULT, it does not need to be written - at least
84 // if it's a built-in property, and not a dynamically-added one.
85 bool bIsDefaultValue
= m_xPropertyState
.is()
86 && ( PropertyState_DEFAULT_VALUE
== m_xPropertyState
->getPropertyState( i_propertyName
) );
87 bool bIsDynamicProperty
= m_xPropertyInfo
.is()
88 && ( ( m_xPropertyInfo
->getPropertyByName( i_propertyName
).Attributes
& PropertyAttribute::REMOVABLE
) != 0 );
89 return ( !bIsDefaultValue
|| bIsDynamicProperty
);
92 template< typename T
> void
93 OPropertyExport::exportRemainingPropertiesSequence(
94 Any
const & value
, token::XMLTokenEnum eValueAttName
)
96 OSequenceIterator
< T
> i(value
);
97 while (i
.hasMoreElements())
99 OUString
sValue(implConvertAny(i
.nextElement()));
100 AddAttribute(XML_NAMESPACE_OFFICE
, eValueAttName
, sValue
);
101 SvXMLElementExport
aValueTag(
102 m_rContext
.getGlobalContext(), XML_NAMESPACE_FORM
,
103 token::XML_LIST_VALUE
, sal_True
, sal_False
);
107 void OPropertyExport::exportRemainingProperties()
109 // the properties tag (will be created if we have at least one no-default property)
110 SvXMLElementExport
* pPropertiesTag
= NULL
;
117 // loop through all the properties which are yet to be exported
118 for ( ConstStringSetIterator aProperty
= m_aRemainingProps
.begin();
119 aProperty
!= m_aRemainingProps
.end();
123 DBG_CHECK_PROPERTY_NO_TYPE(*aProperty
);
125 #if OSL_DEBUG_LEVEL > 0
126 const OUString sPropertyName
= *aProperty
; (void)sPropertyName
;
128 if ( !shouldExportProperty( *aProperty
) )
131 // now that we have the first sub-tag we need the form:properties element
133 pPropertiesTag
= new SvXMLElementExport(m_rContext
.getGlobalContext(), XML_NAMESPACE_FORM
, token::XML_PROPERTIES
, sal_True
, sal_True
);
135 // add the name attribute
136 AddAttribute(XML_NAMESPACE_FORM
, token::XML_PROPERTY_NAME
, *aProperty
);
139 aValue
= m_xProps
->getPropertyValue(*aProperty
);
141 // the type to export
145 sal_Bool bIsSequence
= TypeClass_SEQUENCE
== aValue
.getValueTypeClass();
146 // the type of the property, maybe reduced to the element type of a sequence
148 aExportType
= getSequenceElementType( aValue
.getValueType() );
150 aExportType
= aValue
.getValueType();
152 // the type attribute
154 bool bIsEmptyValue
= TypeClass_VOID
== aValue
.getValueType().getTypeClass();
157 com::sun::star::beans::Property aPropDesc
;
158 aPropDesc
= m_xPropertyInfo
->getPropertyByName( *aProperty
);
159 aExportType
= aPropDesc
.Type
;
161 token::XMLTokenEnum eValueType
= implGetPropertyXMLType( aExportType
);
164 AddAttribute( XML_NAMESPACE_OFFICE
, token::XML_VALUE_TYPE
, token::XML_VOID
);
166 AddAttribute( XML_NAMESPACE_OFFICE
, token::XML_VALUE_TYPE
, eValueType
);
168 token::XMLTokenEnum
eValueAttName( token::XML_VALUE
);
169 switch ( eValueType
)
171 case token::XML_BOOLEAN
: eValueAttName
= token::XML_BOOLEAN_VALUE
; break;
172 case token::XML_STRING
: eValueAttName
= token::XML_STRING_VALUE
; break;
176 if( !bIsSequence
&& !bIsEmptyValue
)
179 sValue
= implConvertAny(aValue
);
180 AddAttribute(XML_NAMESPACE_OFFICE
, eValueAttName
, sValue
);
184 // start the property tag
185 SvXMLElementExport
aValueTag1(m_rContext
.getGlobalContext(),
187 bIsSequence
? token::XML_LIST_PROPERTY
188 : token::XML_PROPERTY
, sal_True
, sal_True
);
193 // the not-that-simple case, we need to iterate through the sequence elements
194 switch ( aExportType
.getTypeClass() )
196 case TypeClass_STRING
:
197 exportRemainingPropertiesSequence
< OUString
>(
198 aValue
, eValueAttName
);
200 case TypeClass_DOUBLE
:
201 exportRemainingPropertiesSequence
< double >(
202 aValue
, eValueAttName
);
204 case TypeClass_BOOLEAN
:
205 exportRemainingPropertiesSequence
< sal_Bool
>(
206 aValue
, eValueAttName
);
209 exportRemainingPropertiesSequence
< sal_Int8
>(
210 aValue
, eValueAttName
);
212 case TypeClass_SHORT
:
213 exportRemainingPropertiesSequence
< sal_Int16
>(
214 aValue
, eValueAttName
);
217 exportRemainingPropertiesSequence
< sal_Int32
>(
218 aValue
, eValueAttName
);
220 case TypeClass_HYPER
:
221 exportRemainingPropertiesSequence
< sal_Int64
>(
222 aValue
, eValueAttName
);
225 OSL_FAIL("OPropertyExport::exportRemainingProperties: unsupported sequence tyoe !");
232 delete pPropertiesTag
;
235 delete pPropertiesTag
;
238 //---------------------------------------------------------------------
239 void OPropertyExport::examinePersistence()
241 m_aRemainingProps
.clear();
242 Sequence
< Property
> aProperties
= m_xPropertyInfo
->getProperties();
243 const Property
* pProperties
= aProperties
.getConstArray();
244 for (sal_Int32 i
=0; i
<aProperties
.getLength(); ++i
, ++pProperties
)
246 // no transient props
247 if ( pProperties
->Attributes
& PropertyAttribute::TRANSIENT
)
249 // no read-only props
250 if ( ( pProperties
->Attributes
& PropertyAttribute::READONLY
) != 0 )
251 // except they're dynamically added
252 if ( ( pProperties
->Attributes
& PropertyAttribute::REMOVABLE
) == 0 )
254 m_aRemainingProps
.insert(pProperties
->Name
);
258 //---------------------------------------------------------------------
259 void OPropertyExport::exportStringPropertyAttribute( const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
260 const OUString
& _rPropertyName
)
262 DBG_CHECK_PROPERTY( _rPropertyName
, OUString
);
264 // no try-catch here, this would be to expensive. The outer scope has to handle exceptions (which should not
265 // happen if we're used correctly :)
267 // this is way simple, as we don't need to convert anything (the property already is a string)
271 m_xProps
->getPropertyValue( _rPropertyName
) >>= sPropValue
;
274 if ( !sPropValue
.isEmpty() )
275 AddAttribute( _nNamespaceKey
, _pAttributeName
, sPropValue
);
277 // the property does not need to be handled anymore
278 exportedProperty( _rPropertyName
);
281 //---------------------------------------------------------------------
282 void OPropertyExport::exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
283 const OUString
& _rPropertyName
, const sal_Int8 _nBooleanAttributeFlags
)
285 DBG_CHECK_PROPERTY_NO_TYPE( _rPropertyName
);
286 // no check of the property value type: this method is allowed to be called with any interger properties
287 // (e.g. sal_Int32, sal_uInt16 etc)
289 sal_Bool bDefault
= (BOOLATTR_DEFAULT_TRUE
== (BOOLATTR_DEFAULT_MASK
& _nBooleanAttributeFlags
));
290 sal_Bool bDefaultVoid
= (BOOLATTR_DEFAULT_VOID
== (BOOLATTR_DEFAULT_MASK
& _nBooleanAttributeFlags
));
293 sal_Bool bCurrentValue
= bDefault
;
294 Any aCurrentValue
= m_xProps
->getPropertyValue( _rPropertyName
);
295 if (aCurrentValue
.hasValue())
297 bCurrentValue
= ::cppu::any2bool(aCurrentValue
);
298 // this will extract a boolean value even if the Any contains a int or short or something like that ...
300 if (_nBooleanAttributeFlags
& BOOLATTR_INVERSE_SEMANTICS
)
301 bCurrentValue
= !bCurrentValue
;
303 // we have a non-void current value
304 if (bDefaultVoid
|| (bDefault
!= bCurrentValue
))
305 // and (the default is void, or the non-void default does not equal the current value)
306 // -> write the attribute
307 AddAttribute(_nNamespaceKey
, _pAttributeName
, bCurrentValue
? m_sValueTrue
: m_sValueFalse
);
310 // we have a void current value
312 // and we have a non-void default
313 // -> write the attribute
314 AddAttribute(_nNamespaceKey
, _pAttributeName
, bCurrentValue
? m_sValueTrue
: m_sValueFalse
);
316 // the property does not need to be handled anymore
317 exportedProperty( _rPropertyName
);
320 //---------------------------------------------------------------------
321 void OPropertyExport::exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
322 const OUString
& _rPropertyName
, const sal_Int16 _nDefault
, bool force
)
324 DBG_CHECK_PROPERTY( _rPropertyName
, sal_Int16
);
327 sal_Int16
nCurrentValue(_nDefault
);
328 m_xProps
->getPropertyValue( _rPropertyName
) >>= nCurrentValue
;
331 if (force
|| _nDefault
!= nCurrentValue
)
333 // let the formatter of the export context build a string
334 OUStringBuffer sBuffer
;
335 ::sax::Converter::convertNumber(sBuffer
, (sal_Int32
)nCurrentValue
);
337 AddAttribute(_nNamespaceKey
, _pAttributeName
, sBuffer
.makeStringAndClear());
340 // the property does not need to be handled anymore
341 exportedProperty( _rPropertyName
);
344 //---------------------------------------------------------------------
345 void OPropertyExport::exportInt32PropertyAttribute( const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
346 const OUString
& _rPropertyName
, const sal_Int32 _nDefault
)
348 DBG_CHECK_PROPERTY( _rPropertyName
, sal_Int32
);
351 sal_Int32
nCurrentValue( _nDefault
);
352 m_xProps
->getPropertyValue( _rPropertyName
) >>= nCurrentValue
;
355 if ( _nDefault
!= nCurrentValue
)
357 // let the formatter of the export context build a string
358 OUStringBuffer sBuffer
;
359 ::sax::Converter::convertNumber( sBuffer
, nCurrentValue
);
361 AddAttribute( _nNamespaceKey
, _pAttributeName
, sBuffer
.makeStringAndClear() );
364 // the property does not need to be handled anymore
365 exportedProperty( _rPropertyName
);
368 //---------------------------------------------------------------------
369 void OPropertyExport::exportEnumPropertyAttribute(
370 const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
371 const OUString
&rPropertyName
, const SvXMLEnumMapEntry
* _pValueMap
,
372 const sal_Int32 _nDefault
, const sal_Bool _bVoidDefault
)
375 sal_Int32
nCurrentValue(_nDefault
);
376 Any aValue
= m_xProps
->getPropertyValue(rPropertyName
);
378 if (aValue
.hasValue())
379 { // we have a non-void current value
380 ::cppu::enum2int(nCurrentValue
, aValue
);
383 if ((_nDefault
!= nCurrentValue
) || _bVoidDefault
)
384 { // the default does not equal the value, or the default is void and the value isn't
386 // let the formatter of the export context build a string
387 OUStringBuffer sBuffer
;
388 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertEnum(sBuffer
, (sal_uInt16
)nCurrentValue
, _pValueMap
);
390 AddAttribute(_nNamespaceKey
, _pAttributeName
, sBuffer
.makeStringAndClear());
396 AddAttributeASCII(_nNamespaceKey
, _pAttributeName
, "");
399 // the property does not need to be handled anymore
400 exportedProperty(rPropertyName
);
403 //---------------------------------------------------------------------
404 void OPropertyExport::exportTargetFrameAttribute()
406 DBG_CHECK_PROPERTY( PROPERTY_TARGETFRAME
, OUString
);
408 OUString sTargetFrame
= comphelper::getString(m_xProps
->getPropertyValue(PROPERTY_TARGETFRAME
));
409 if (0 != sTargetFrame
.compareToAscii("_blank"))
410 { // an empty string and "_blank" have the same meaning and don't have to be written
411 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(CCA_TARGET_FRAME
)
412 ,OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME
)
416 exportedProperty(PROPERTY_TARGETFRAME
);
419 //---------------------------------------------------------------------
420 void OPropertyExport::exportRelativeTargetLocation(const OUString
& _sPropertyName
,sal_Int32 _nProperty
,bool _bAddType
)
422 DBG_CHECK_PROPERTY( _sPropertyName
, OUString
);
424 OUString sTargetLocation
= comphelper::getString(m_xProps
->getPropertyValue(_sPropertyName
));
425 if ( !sTargetLocation
.isEmpty() )
426 // If this isn't a GraphicObject then GetRelativeReference
427 // will be called anyway ( in AddEmbeddedGraphic )
428 sTargetLocation
= m_rContext
.getGlobalContext().AddEmbeddedGraphicObject(sTargetLocation
);
429 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(_nProperty
)
430 ,OAttributeMetaData::getCommonControlAttributeName(_nProperty
)
433 // #i110911# add xlink:type="simple" if required
435 AddAttribute(XML_NAMESPACE_XLINK
, token::XML_TYPE
, token::XML_SIMPLE
);
437 exportedProperty(_sPropertyName
);
439 //---------------------------------------------------------------------
440 void OPropertyExport::flagStyleProperties()
442 // flag all the properties which are part of the style as "handled"
443 UniReference
< XMLPropertySetMapper
> xStylePropertiesSupplier
= m_rContext
.getStylePropertyMapper()->getPropertySetMapper();
444 for (sal_Int32 i
=0; i
<xStylePropertiesSupplier
->GetEntryCount(); ++i
)
445 exportedProperty(xStylePropertiesSupplier
->GetEntryAPIName(i
));
447 // the font properties are exported as single properties, but there is a FontDescriptor property which
448 // collects them all-in-one, this has been exported implicitly
449 exportedProperty(PROPERTY_FONT
);
451 // for the DateFormat and TimeFormat, there exist wrapper properties which has been exported as
453 exportedProperty(PROPERTY_DATEFORMAT
);
454 exportedProperty(PROPERTY_TIMEFORMAT
);
456 // the following properties should have been exported at the shape already:
457 exportedProperty( "VerticalAlign" );
458 exportedProperty( "WritingMode" );
459 exportedProperty( "ScaleMode" );
460 // ditto the TextWritingMode
461 exportedProperty( "WritingMode" );
464 //---------------------------------------------------------------------
465 void OPropertyExport::exportGenericPropertyAttribute(
466 const sal_uInt16 _nAttributeNamespaceKey
, const sal_Char
* _pAttributeName
, const sal_Char
* _pPropertyName
)
468 DBG_CHECK_PROPERTY_ASCII_NO_TYPE( _pPropertyName
);
470 OUString sPropertyName
= OUString::createFromAscii(_pPropertyName
);
471 exportedProperty(sPropertyName
);
473 Any aCurrentValue
= m_xProps
->getPropertyValue(sPropertyName
);
474 if (!aCurrentValue
.hasValue())
475 // nothing to do without a concrete value
478 OUString sValue
= implConvertAny(aCurrentValue
);
479 if (sValue
.isEmpty() && (TypeClass_STRING
== aCurrentValue
.getValueTypeClass()))
481 // check whether or not the property is allowed to be VOID
482 Property aProperty
= m_xPropertyInfo
->getPropertyByName(sPropertyName
);
483 if ((aProperty
.Attributes
& PropertyAttribute::MAYBEVOID
) == 0)
484 // the string is empty, and the property is not allowed to be void
485 // -> don't need to write the attibute, 'cause missing it is unambiguous
489 // finally add the attribuite to the context
490 AddAttribute(_nAttributeNamespaceKey
, _pAttributeName
, sValue
);
493 //---------------------------------------------------------------------
494 void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey
, const sal_Char
* _pAttributeName
,
495 const OUString
& _rPropertyName
,
496 const sal_Unicode _aQuoteCharacter
, const sal_Unicode _aListSeparator
)
498 DBG_CHECK_PROPERTY( _rPropertyName
, Sequence
< OUString
> );
499 OSL_ENSURE(_aListSeparator
!= 0, "OPropertyExport::exportStringSequenceAttribute: invalid separator character!");
501 Sequence
< OUString
> aItems
;
502 m_xProps
->getPropertyValue( _rPropertyName
) >>= aItems
;
506 // unfortunately the OUString can't append single sal_Unicode characters ...
507 const OUString
sQuote(&_aQuoteCharacter
, 1);
508 const OUString
sSeparator(&_aListSeparator
, 1);
509 const sal_Bool bQuote
= !sQuote
.isEmpty();
511 // concatenate the string items
512 const OUString
* pItems
= aItems
.getConstArray();
513 const OUString
* pEnd
= pItems
+ aItems
.getLength();
514 const OUString
* pLastElement
= pEnd
- 1;
520 OSL_ENSURE(!_aQuoteCharacter
|| (-1 == pItems
->indexOf(_aQuoteCharacter
)),
521 "OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
522 OSL_ENSURE(_aQuoteCharacter
|| (-1 == pItems
->indexOf(_aListSeparator
)),
523 "OPropertyExport::exportStringSequenceAttribute: no quote character, but there is an item containing the separator character!");
526 sFinalList
+= sQuote
;
527 sFinalList
+= *pItems
;
529 sFinalList
+= sQuote
;
531 if (pItems
!= pLastElement
)
532 sFinalList
+= sSeparator
;
535 if (!sFinalList
.isEmpty())
536 AddAttribute(_nAttributeNamespaceKey
, _pAttributeName
, sFinalList
);
538 exportedProperty( _rPropertyName
);
541 //---------------------------------------------------------------------
542 OUString
OPropertyExport::implConvertAny(const Any
& _rValue
)
544 OUStringBuffer aBuffer
;
545 switch (_rValue
.getValueTypeClass())
547 case TypeClass_STRING
:
548 { // extract the string
549 OUString sCurrentValue
;
550 _rValue
>>= sCurrentValue
;
551 aBuffer
.append(sCurrentValue
);
554 case TypeClass_DOUBLE
:
555 // let the unit converter format is as string
556 ::sax::Converter::convertDouble(aBuffer
, getDouble(_rValue
));
558 case TypeClass_BOOLEAN
:
559 aBuffer
= getBOOL(_rValue
) ? m_sValueTrue
: m_sValueFalse
;
562 case TypeClass_SHORT
:
564 // let the unit converter format is as string
565 ::sax::Converter::convertNumber(aBuffer
, getINT32(_rValue
));
567 case TypeClass_HYPER
:
569 OSL_FAIL("OPropertyExport::implConvertAny: missing implementation for sal_Int64!");
573 // convert it into an int32
574 sal_Int32 nValue
= 0;
575 ::cppu::enum2int(nValue
, _rValue
);
576 ::sax::Converter::convertNumber(aBuffer
, nValue
);
580 { // hmmm .... what else do we know?
582 ::com::sun::star::util::Date aDate
;
583 ::com::sun::star::util::Time aTime
;
584 ::com::sun::star::util::DateTime aDateTime
;
585 if (_rValue
>>= aDate
)
587 Date
aToolsDate( Date::EMPTY
);
588 ::utl::typeConvert(aDate
, aToolsDate
);
589 fValue
= aToolsDate
.GetDate();
591 else if (_rValue
>>= aTime
)
593 fValue
= aTime
.Hours
/ static_cast<double>(::Time::hourPerDay
) +
594 aTime
.Minutes
/ static_cast<double>(::Time::minutePerDay
) +
595 aTime
.Seconds
/ static_cast<double>(::Time::secondPerDay
) +
596 aTime
.NanoSeconds
/ static_cast<double>(::Time::nanoSecPerDay
);
598 else if (_rValue
>>= aDateTime
)
600 DateTime
aToolsDateTime( DateTime::EMPTY
);
601 ::utl::typeConvert(aDateTime
, aToolsDateTime
);
602 // the time part (the digits behind the comma)
603 fValue
= aTime
.Hours
/ static_cast<double>(::Time::hourPerDay
) +
604 aTime
.Minutes
/ static_cast<double>(::Time::minutePerDay
) +
605 aTime
.Seconds
/ static_cast<double>(::Time::secondPerDay
) +
606 aTime
.NanoSeconds
/ static_cast<double>(::Time::nanoSecPerDay
);
607 // plus the data part (the digits in front of the comma)
608 fValue
+= aToolsDateTime
.GetDate();
612 // if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
614 // no more options ...
615 OSL_FAIL("OPropertyExport::implConvertAny: unsupported value type!");
618 // let the unit converter format is as string
619 ::sax::Converter::convertDouble(aBuffer
, fValue
);
624 return aBuffer
.makeStringAndClear();
628 //---------------------------------------------------------------------
629 token::XMLTokenEnum
OPropertyExport::implGetPropertyXMLType(const ::com::sun::star::uno::Type
& _rType
)
631 // handle the type description
632 switch (_rType
.getTypeClass())
634 case TypeClass_STRING
:
635 return token::XML_STRING
;
636 case TypeClass_DOUBLE
:
638 case TypeClass_SHORT
:
640 case TypeClass_HYPER
:
642 return token::XML_FLOAT
;
643 case TypeClass_BOOLEAN
:
644 return token::XML_BOOLEAN
;
647 return token::XML_FLOAT
;
652 //---------------------------------------------------------------------
653 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix
, const sal_Char
* _pName
, const OUString
& _rValue
)
655 OSL_ENSURE(m_rContext
.getGlobalContext().GetXAttrList()->getValueByName(OUString::createFromAscii(_pName
)).isEmpty(),
656 "OPropertyExport::AddAttribute: already have such an attribute");
658 m_rContext
.getGlobalContext().AddAttribute(_nPrefix
, _pName
, _rValue
);
661 //---------------------------------------------------------------------
662 void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix
, const OUString
& _rName
, const OUString
& _rValue
)
664 OSL_ENSURE(m_rContext
.getGlobalContext().GetXAttrList()->getValueByName( _rName
).isEmpty(),
665 "OPropertyExport::AddAttribute: already have such an attribute");
667 m_rContext
.getGlobalContext().AddAttribute( _nPrefix
, _rName
, _rValue
);
670 //---------------------------------------------------------------------
671 void OPropertyExport::AddAttributeASCII(sal_uInt16 _nPrefix
, const sal_Char
* _pName
, const sal_Char
*pValue
)
673 OSL_ENSURE(m_rContext
.getGlobalContext().GetXAttrList()->getValueByName(OUString::createFromAscii(_pName
)).isEmpty(),
674 "OPropertyExport::AddAttributeASCII: already have such an attribute");
676 m_rContext
.getGlobalContext().AddAttributeASCII(_nPrefix
, _pName
, pValue
);
679 //---------------------------------------------------------------------
680 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix
, ::xmloff::token::XMLTokenEnum _eName
, const OUString
& _rValue
)
682 OSL_ENSURE(m_rContext
.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName
)).isEmpty(),
683 "OPropertyExport::AddAttribute: already have such an attribute");
685 m_rContext
.getGlobalContext().AddAttribute(_nPrefix
, _eName
, _rValue
);
688 //---------------------------------------------------------------------
689 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix
, ::xmloff::token::XMLTokenEnum _eName
, ::xmloff::token::XMLTokenEnum _eValue
)
691 OSL_ENSURE(m_rContext
.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName
)).isEmpty(),
692 "OPropertyExport::AddAttribute: already have such an attribute");
694 m_rContext
.getGlobalContext().AddAttribute(_nPrefix
, _eName
, _eValue
);
697 //---------------------------------------------------------------------
698 void OPropertyExport::dbg_implCheckProperty(const OUString
& _rPropertyName
, const Type
* _pType
)
702 // the property must exist
703 if (!m_xPropertyInfo
->hasPropertyByName(_rPropertyName
))
705 OStringBuffer
aBuf("OPropertyExport::dbg_implCheckProperty: no property with the name ");
706 aBuf
.append(OUStringToOString(_rPropertyName
, RTL_TEXTENCODING_ASCII_US
)).append('!');
707 OSL_FAIL(aBuf
.getStr());
713 // and it must have the correct type
714 Property aPropertyDescription
= m_xPropertyInfo
->getPropertyByName(_rPropertyName
);
715 OSL_ENSURE(aPropertyDescription
.Type
.equals(*_pType
), "OPropertyExport::dbg_implCheckProperty: invalid property type!");
720 OSL_FAIL("OPropertyExport::dbg_implCheckProperty: caught an exception, could not check the property!");
723 #endif // DBG_UTIL - dbg_implCheckProperty
725 //.........................................................................
726 } // namespace xmloff
727 //.........................................................................
730 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */