1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertyexport.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "propertyexport.hxx"
36 #include <xmloff/xmlexp.hxx>
37 #include "strings.hxx"
38 #include "xmlnmspe.hxx"
39 #include <xmloff/xmluconv.hxx>
40 #include <xmloff/families.hxx>
41 #include <osl/diagnose.h>
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <com/sun/star/beans/XPropertyState.hpp>
44 #include <com/sun/star/util/Date.hpp>
45 #include <com/sun/star/util/Time.hpp>
46 #include <com/sun/star/util/DateTime.hpp>
47 #include <osl/diagnose.h>
48 #include <comphelper/extract.hxx>
49 #include <comphelper/sequence.hxx>
50 #include <comphelper/types.hxx>
51 #include "callbacks.hxx"
52 #include <unotools/datetime.hxx>
53 #include <tools/date.hxx>
54 #include <tools/time.hxx>
55 #include <tools/datetime.hxx>
57 //.........................................................................
60 //.........................................................................
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::lang
;
64 using namespace ::com::sun::star::beans
;
66 // NO using namespace ...util !!!
67 // need a tools Date/Time/DateTime below, which would conflict with the uno types then
69 using namespace ::comphelper
;
71 //=====================================================================
73 //=====================================================================
74 //---------------------------------------------------------------------
75 OPropertyExport::OPropertyExport(IFormsExportContext
& _rContext
, const Reference
< XPropertySet
>& _rxProps
)
76 :m_rContext(_rContext
)
80 ::rtl::OUStringBuffer aBuffer
;
81 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertBool(aBuffer
, sal_True
);
82 m_sValueTrue
= aBuffer
.makeStringAndClear();
83 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertBool(aBuffer
, sal_False
);
84 m_sValueFalse
= aBuffer
.makeStringAndClear();
86 m_xPropertyInfo
= m_xProps
->getPropertySetInfo();
87 OSL_ENSURE(m_xPropertyInfo
.is(), "OPropertyExport::OPropertyExport: need an XPropertySetInfo!");
89 // collect the properties which need to be exported
93 //---------------------------------------------------------------------
94 void OPropertyExport::exportRemainingProperties()
96 // the properties tag (will be created if we have at least one no-default property)
97 SvXMLElementExport
* pPropertiesTag
= NULL
;
101 Reference
< XPropertyState
> xPropertyState( m_xProps
, UNO_QUERY
);
102 Reference
< XPropertySetInfo
> xPSI( m_xProps
->getPropertySetInfo() );
105 ::rtl::OUString sValue
;
107 // loop through all the properties which are yet to be exported
108 for ( ConstStringSetIterator aProperty
= m_aRemainingProps
.begin();
109 aProperty
!= m_aRemainingProps
.end();
113 DBG_CHECK_PROPERTY_NO_TYPE(*aProperty
);
115 #if OSL_DEBUG_LEVEL > 0
116 const ::rtl::OUString sPropertyName
= *aProperty
; (void)sPropertyName
;
118 // if the property state is DEFAULT, it does not need to be written - at least
119 // if it's a built-in property, and not a dynamically-added one.
120 bool bIsDefaultValue
= xPropertyState
.is()
121 && ( PropertyState_DEFAULT_VALUE
== xPropertyState
->getPropertyState( *aProperty
) );
122 bool bIsDynamicProperty
= xPSI
.is()
123 && ( ( xPSI
->getPropertyByName( *aProperty
).Attributes
& PropertyAttribute::REMOVEABLE
) != 0 );
124 if ( bIsDefaultValue
&& !bIsDynamicProperty
)
127 // now that we have the first sub-tag we need the form:properties element
129 pPropertiesTag
= new SvXMLElementExport(m_rContext
.getGlobalContext(), XML_NAMESPACE_FORM
, token::XML_PROPERTIES
, sal_True
, sal_True
);
131 // add the name attribute
132 AddAttribute(XML_NAMESPACE_FORM
, token::XML_PROPERTY_NAME
, *aProperty
);
135 aValue
= m_xProps
->getPropertyValue(*aProperty
);
137 // the type to export
141 sal_Bool bIsSequence
= TypeClass_SEQUENCE
== aValue
.getValueTypeClass();
142 // the type of the property, maybe reduced to the element type of a sequence
144 aExportType
= getSequenceElementType( aValue
.getValueType() );
146 aExportType
= aValue
.getValueType();
148 // the type attribute
149 // modified by BerryJia for Bug102407
150 bool bIsEmptyValue
= TypeClass_VOID
== aValue
.getValueType().getTypeClass();
153 com::sun::star::beans::Property aPropDesc
;
154 aPropDesc
= m_xPropertyInfo
->getPropertyByName( *aProperty
);
155 aExportType
= aPropDesc
.Type
;
157 token::XMLTokenEnum eValueType
= implGetPropertyXMLType( aExportType
);
160 AddAttribute( XML_NAMESPACE_OFFICE
, token::XML_VALUE_TYPE
, token::XML_VOID
);
162 AddAttribute( XML_NAMESPACE_OFFICE
, token::XML_VALUE_TYPE
, eValueType
);
164 token::XMLTokenEnum
eValueAttName( token::XML_VALUE
);
165 switch ( eValueType
)
167 case token::XML_BOOLEAN
: eValueAttName
= token::XML_BOOLEAN_VALUE
; break;
168 case token::XML_STRING
: eValueAttName
= token::XML_STRING_VALUE
; break;
172 if( !bIsSequence
&& !bIsEmptyValue
)
174 //add by BerryJia for Bug102407
175 sValue
= implConvertAny(aValue
);
176 AddAttribute(XML_NAMESPACE_OFFICE
, eValueAttName
, sValue
);
180 // start the property tag
181 SvXMLElementExport
aValueTag1(m_rContext
.getGlobalContext(),
183 bIsSequence
? token::XML_LIST_PROPERTY
184 : token::XML_PROPERTY
, sal_True
, sal_True
);
189 // the not-that-simple case, we need to iterate through the sequence elements
190 IIterator
* pSequenceIterator
= NULL
;
192 switch ( aExportType
.getTypeClass() )
194 case TypeClass_STRING
:
195 pSequenceIterator
= new OSequenceIterator
< ::rtl::OUString
>(aValue
);
197 case TypeClass_DOUBLE
:
198 pSequenceIterator
= new OSequenceIterator
< double >(aValue
);
200 case TypeClass_BOOLEAN
:
201 pSequenceIterator
= new OSequenceIterator
< sal_Bool
>(aValue
);
204 pSequenceIterator
= new OSequenceIterator
< sal_Int8
>(aValue
);
206 case TypeClass_SHORT
:
207 pSequenceIterator
= new OSequenceIterator
< sal_Int16
>(aValue
);
210 pSequenceIterator
= new OSequenceIterator
< sal_Int32
>(aValue
);
212 case TypeClass_HYPER
:
213 pSequenceIterator
= new OSequenceIterator
< sal_Int64
>(aValue
);
216 OSL_ENSURE(sal_False
, "OPropertyExport::exportRemainingProperties: unsupported sequence tyoe !");
219 if (pSequenceIterator
)
221 while (pSequenceIterator
->hasMoreElements())
224 implConvertAny(pSequenceIterator
->nextElement());
225 AddAttribute(XML_NAMESPACE_OFFICE
, eValueAttName
, sValue
);
226 SvXMLElementExport
aValueTag(
227 m_rContext
.getGlobalContext(),
228 XML_NAMESPACE_FORM
, token::XML_LIST_VALUE
,
229 sal_True
, sal_False
);
232 delete pSequenceIterator
;
237 delete pPropertiesTag
;
240 delete pPropertiesTag
;
243 //---------------------------------------------------------------------
244 void OPropertyExport::examinePersistence()
246 m_aRemainingProps
.clear();
247 Sequence
< Property
> aProperties
= m_xPropertyInfo
->getProperties();
248 const Property
* pProperties
= aProperties
.getConstArray();
249 for (sal_Int32 i
=0; i
<aProperties
.getLength(); ++i
, ++pProperties
)
251 // no transient props
252 if ( pProperties
->Attributes
& PropertyAttribute::TRANSIENT
)
254 // no read-only props
255 if ( ( pProperties
->Attributes
& PropertyAttribute::READONLY
) != 0 )
256 // except they're dynamically added
257 if ( ( pProperties
->Attributes
& PropertyAttribute::REMOVEABLE
) == 0 )
259 m_aRemainingProps
.insert(pProperties
->Name
);
263 //---------------------------------------------------------------------
264 void OPropertyExport::exportStringPropertyAttribute( const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
265 const ::rtl::OUString
& _rPropertyName
)
267 DBG_CHECK_PROPERTY( _rPropertyName
, ::rtl::OUString
);
269 // no try-catch here, this would be to expensive. The outer scope has to handle exceptions (which should not
270 // happen if we're used correctly :)
272 // this is way simple, as we don't need to convert anything (the property already is a string)
275 ::rtl::OUString sPropValue
;
276 m_xProps
->getPropertyValue( _rPropertyName
) >>= sPropValue
;
279 if ( sPropValue
.getLength() )
280 AddAttribute( _nNamespaceKey
, _pAttributeName
, sPropValue
);
282 // the property does not need to be handled anymore
283 exportedProperty( _rPropertyName
);
286 //---------------------------------------------------------------------
287 void OPropertyExport::exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
288 const ::rtl::OUString
& _rPropertyName
, const sal_Int8 _nBooleanAttributeFlags
)
290 DBG_CHECK_PROPERTY_NO_TYPE( _rPropertyName
);
291 // no check of the property value type: this method is allowed to be called with any interger properties
292 // (e.g. sal_Int32, sal_uInt16 etc)
294 sal_Bool bDefault
= (BOOLATTR_DEFAULT_TRUE
== (BOOLATTR_DEFAULT_MASK
& _nBooleanAttributeFlags
));
295 sal_Bool bDefaultVoid
= (BOOLATTR_DEFAULT_VOID
== (BOOLATTR_DEFAULT_MASK
& _nBooleanAttributeFlags
));
298 sal_Bool bCurrentValue
= bDefault
;
299 Any aCurrentValue
= m_xProps
->getPropertyValue( _rPropertyName
);
300 if (aCurrentValue
.hasValue())
302 bCurrentValue
= ::cppu::any2bool(aCurrentValue
);
303 // this will extract a boolean value even if the Any contains a int or short or something like that ...
305 if (_nBooleanAttributeFlags
& BOOLATTR_INVERSE_SEMANTICS
)
306 bCurrentValue
= !bCurrentValue
;
308 // we have a non-void current value
309 if (bDefaultVoid
|| (bDefault
!= bCurrentValue
))
310 // and (the default is void, or the non-void default does not equal the current value)
311 // -> write the attribute
312 AddAttribute(_nNamespaceKey
, _pAttributeName
, bCurrentValue
? m_sValueTrue
: m_sValueFalse
);
315 // we have a void current value
317 // and we have a non-void default
318 // -> write the attribute
319 AddAttribute(_nNamespaceKey
, _pAttributeName
, bCurrentValue
? m_sValueTrue
: m_sValueFalse
);
321 // the property does not need to be handled anymore
322 exportedProperty( _rPropertyName
);
325 //---------------------------------------------------------------------
326 void OPropertyExport::exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
327 const ::rtl::OUString
& _rPropertyName
, const sal_Int16 _nDefault
)
329 DBG_CHECK_PROPERTY( _rPropertyName
, sal_Int16
);
332 sal_Int16
nCurrentValue(_nDefault
);
333 m_xProps
->getPropertyValue( _rPropertyName
) >>= nCurrentValue
;
336 if (_nDefault
!= nCurrentValue
)
338 // let the formatter of the export context build a string
339 ::rtl::OUStringBuffer sBuffer
;
340 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertNumber(sBuffer
, (sal_Int32
)nCurrentValue
);
342 AddAttribute(_nNamespaceKey
, _pAttributeName
, sBuffer
.makeStringAndClear());
345 // the property does not need to be handled anymore
346 exportedProperty( _rPropertyName
);
349 //---------------------------------------------------------------------
350 void OPropertyExport::exportInt32PropertyAttribute( const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
351 const ::rtl::OUString
& _rPropertyName
, const sal_Int32 _nDefault
)
353 DBG_CHECK_PROPERTY( _rPropertyName
, sal_Int32
);
356 sal_Int32
nCurrentValue( _nDefault
);
357 m_xProps
->getPropertyValue( _rPropertyName
) >>= nCurrentValue
;
360 if ( _nDefault
!= nCurrentValue
)
362 // let the formatter of the export context build a string
363 ::rtl::OUStringBuffer sBuffer
;
364 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertNumber( sBuffer
, nCurrentValue
);
366 AddAttribute( _nNamespaceKey
, _pAttributeName
, sBuffer
.makeStringAndClear() );
369 // the property does not need to be handled anymore
370 exportedProperty( _rPropertyName
);
373 //---------------------------------------------------------------------
374 void OPropertyExport::exportEnumPropertyAttribute(
375 const sal_uInt16 _nNamespaceKey
, const sal_Char
* _pAttributeName
,
376 const sal_Char
* _pPropertyName
, const SvXMLEnumMapEntry
* _pValueMap
,
377 const sal_Int32 _nDefault
, const sal_Bool _bVoidDefault
)
380 sal_Int32
nCurrentValue(_nDefault
);
381 ::rtl::OUString
sPropertyName(::rtl::OUString::createFromAscii(_pPropertyName
));
382 Any aValue
= m_xProps
->getPropertyValue(sPropertyName
);
384 if (aValue
.hasValue())
385 { // we have a non-void current value
386 ::cppu::enum2int(nCurrentValue
, aValue
);
389 if ((_nDefault
!= nCurrentValue
) || _bVoidDefault
)
390 { // the default does not equal the value, or the default is void and the value isn't
392 // let the formatter of the export context build a string
393 ::rtl::OUStringBuffer sBuffer
;
394 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertEnum(sBuffer
, (sal_uInt16
)nCurrentValue
, _pValueMap
);
396 AddAttribute(_nNamespaceKey
, _pAttributeName
, sBuffer
.makeStringAndClear());
402 AddAttributeASCII(_nNamespaceKey
, _pAttributeName
, "");
405 // the property does not need to be handled anymore
406 exportedProperty(sPropertyName
);
409 //---------------------------------------------------------------------
410 void OPropertyExport::exportTargetFrameAttribute()
412 DBG_CHECK_PROPERTY( PROPERTY_TARGETFRAME
, ::rtl::OUString
);
414 ::rtl::OUString sTargetFrame
= comphelper::getString(m_xProps
->getPropertyValue(PROPERTY_TARGETFRAME
));
415 if (0 != sTargetFrame
.compareToAscii("_blank"))
416 { // an empty string and "_blank" have the same meaning and don't have to be written
417 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(CCA_TARGET_FRAME
)
418 ,OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME
)
422 exportedProperty(PROPERTY_TARGETFRAME
);
425 //---------------------------------------------------------------------
426 void OPropertyExport::exportRelativeTargetLocation(const ConstAsciiString
& _sPropertyName
,sal_Int32 _nProperty
)
428 DBG_CHECK_PROPERTY( _sPropertyName
, ::rtl::OUString
);
430 ::rtl::OUString sTargetLocation
= comphelper::getString(m_xProps
->getPropertyValue(_sPropertyName
));
431 if ( sTargetLocation
.getLength() )
432 // If this isn't a GraphicObject then GetRelativeReference
433 // will be called anyway ( in AddEmbeddedGraphic )
434 sTargetLocation
= m_rContext
.getGlobalContext().AddEmbeddedGraphicObject(sTargetLocation
);
435 AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(_nProperty
)
436 ,OAttributeMetaData::getCommonControlAttributeName(_nProperty
)
439 exportedProperty(_sPropertyName
);
441 //---------------------------------------------------------------------
442 void OPropertyExport::flagStyleProperties()
444 // flag all the properties which are part of the style as "handled"
445 UniReference
< XMLPropertySetMapper
> xStylePropertiesSupplier
= m_rContext
.getStylePropertyMapper()->getPropertySetMapper();
446 for (sal_Int32 i
=0; i
<xStylePropertiesSupplier
->GetEntryCount(); ++i
)
447 exportedProperty(xStylePropertiesSupplier
->GetEntryAPIName(i
));
449 // the font properties are exported as single properties, but there is a FontDescriptor property which
450 // collects them all-in-one, this has been exported implicitly
451 exportedProperty(PROPERTY_FONT
);
453 // for the DateFormat and TimeFormat, there exist wrapper properties which has been exported as
455 exportedProperty(PROPERTY_DATEFORMAT
);
456 exportedProperty(PROPERTY_TIMEFORMAT
);
458 // the following properties should have been exported at the shape already:
459 exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VerticalAlign" ) ) );
460 exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WritingMode" ) ) );
461 exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScaleMode" ) ) );
462 // ditto the TextWritingMode
463 exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WritingMode" ) ) );
466 //---------------------------------------------------------------------
467 void OPropertyExport::exportGenericPropertyAttribute(
468 const sal_uInt16 _nAttributeNamespaceKey
, const sal_Char
* _pAttributeName
, const sal_Char
* _pPropertyName
)
470 DBG_CHECK_PROPERTY_ASCII_NO_TYPE( _pPropertyName
);
472 ::rtl::OUString sPropertyName
= ::rtl::OUString::createFromAscii(_pPropertyName
);
473 exportedProperty(sPropertyName
);
475 Any aCurrentValue
= m_xProps
->getPropertyValue(sPropertyName
);
476 if (!aCurrentValue
.hasValue())
477 // nothing to do without a concrete value
480 ::rtl::OUString sValue
= implConvertAny(aCurrentValue
);
481 if (!sValue
.getLength() && (TypeClass_STRING
== aCurrentValue
.getValueTypeClass()))
483 // check whether or not the property is allowed to be VOID
484 Property aProperty
= m_xPropertyInfo
->getPropertyByName(sPropertyName
);
485 if ((aProperty
.Attributes
& PropertyAttribute::MAYBEVOID
) == 0)
486 // the string is empty, and the property is not allowed to be void
487 // -> don't need to write the attibute, 'cause missing it is unambiguous
491 // finally add the attribuite to the context
492 AddAttribute(_nAttributeNamespaceKey
, _pAttributeName
, sValue
);
495 //---------------------------------------------------------------------
496 void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey
, const sal_Char
* _pAttributeName
,
497 const ::rtl::OUString
& _rPropertyName
,
498 const sal_Unicode _aQuoteCharacter
, const sal_Unicode _aListSeparator
)
500 DBG_CHECK_PROPERTY( _rPropertyName
, Sequence
< ::rtl::OUString
> );
501 OSL_ENSURE(_aListSeparator
!= 0, "OPropertyExport::exportStringSequenceAttribute: invalid separator character!");
503 Sequence
< ::rtl::OUString
> aItems
;
504 m_xProps
->getPropertyValue( _rPropertyName
) >>= aItems
;
506 ::rtl::OUString sFinalList
;
508 // unfortunately the OUString can't append single sal_Unicode characters ...
509 const ::rtl::OUString
sQuote(&_aQuoteCharacter
, 1);
510 const ::rtl::OUString
sSeparator(&_aListSeparator
, 1);
511 const sal_Bool bQuote
= 0 != sQuote
.getLength();
513 // concatenate the string items
514 const ::rtl::OUString
* pItems
= aItems
.getConstArray();
515 const ::rtl::OUString
* pEnd
= pItems
+ aItems
.getLength();
516 const ::rtl::OUString
* pLastElement
= pEnd
- 1;
522 OSL_ENSURE(!_aQuoteCharacter
|| (-1 == pItems
->indexOf(_aQuoteCharacter
)),
523 "OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
524 OSL_ENSURE(_aQuoteCharacter
|| (-1 == pItems
->indexOf(_aListSeparator
)),
525 "OPropertyExport::exportStringSequenceAttribute: no quote character, but there is an item containing the separator character!");
528 sFinalList
+= sQuote
;
529 sFinalList
+= *pItems
;
531 sFinalList
+= sQuote
;
533 if (pItems
!= pLastElement
)
534 sFinalList
+= sSeparator
;
537 if (sFinalList
.getLength())
538 AddAttribute(_nAttributeNamespaceKey
, _pAttributeName
, sFinalList
);
540 exportedProperty( _rPropertyName
);
543 //---------------------------------------------------------------------
544 ::rtl::OUString
OPropertyExport::implConvertAny(const Any
& _rValue
)
546 ::rtl::OUStringBuffer aBuffer
;
547 switch (_rValue
.getValueTypeClass())
549 case TypeClass_STRING
:
550 { // extract the string
551 ::rtl::OUString sCurrentValue
;
552 _rValue
>>= sCurrentValue
;
553 aBuffer
.append(sCurrentValue
);
556 case TypeClass_DOUBLE
:
557 // let the unit converter format is as string
558 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertDouble(aBuffer
, getDouble(_rValue
));
560 case TypeClass_BOOLEAN
:
561 aBuffer
= getBOOL(_rValue
) ? m_sValueTrue
: m_sValueFalse
;
564 case TypeClass_SHORT
:
566 // let the unit converter format is as string
567 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertNumber(aBuffer
, getINT32(_rValue
));
569 case TypeClass_HYPER
:
571 OSL_ENSURE(sal_False
, "OPropertyExport::implConvertAny: missing implementation for sal_Int64!");
575 // convert it into an int32
576 sal_Int32 nValue
= 0;
577 ::cppu::enum2int(nValue
, _rValue
);
578 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertNumber(aBuffer
, nValue
);
582 { // hmmm .... what else do we know?
584 ::com::sun::star::util::Date aDate
;
585 ::com::sun::star::util::Time aTime
;
586 ::com::sun::star::util::DateTime aDateTime
;
587 if (_rValue
>>= aDate
)
590 ::utl::typeConvert(aDate
, aToolsDate
);
591 fValue
= aToolsDate
.GetDate();
593 else if (_rValue
>>= aTime
)
595 fValue
= ((aTime
.Hours
* 60 + aTime
.Minutes
) * 60 + aTime
.Seconds
) * 100 + aTime
.HundredthSeconds
;
596 fValue
= fValue
/ 8640000.0;
598 else if (_rValue
>>= aDateTime
)
600 DateTime aToolsDateTime
;
601 ::utl::typeConvert(aDateTime
, aToolsDateTime
);
602 // the time part (the digits behind the comma)
603 fValue
= ((aDateTime
.Hours
* 60 + aDateTime
.Minutes
) * 60 + aDateTime
.Seconds
) * 100 + aDateTime
.HundredthSeconds
;
604 fValue
= fValue
/ 8640000.0;
605 // plus the data part (the digits in front of the comma)
606 fValue
+= aToolsDateTime
.GetDate();
610 // if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
612 // no more options ...
613 OSL_ENSURE(sal_False
, "OPropertyExport::implConvertAny: unsupported value type!");
616 // let the unit converter format is as string
617 m_rContext
.getGlobalContext().GetMM100UnitConverter().convertDouble(aBuffer
, fValue
);
622 return aBuffer
.makeStringAndClear();
626 //---------------------------------------------------------------------
627 token::XMLTokenEnum
OPropertyExport::implGetPropertyXMLType(const ::com::sun::star::uno::Type
& _rType
)
629 // handle the type description
630 switch (_rType
.getTypeClass())
632 case TypeClass_STRING
:
633 return token::XML_STRING
;
634 case TypeClass_DOUBLE
:
636 case TypeClass_SHORT
:
638 case TypeClass_HYPER
:
640 return token::XML_FLOAT
;
641 case TypeClass_BOOLEAN
:
642 return token::XML_BOOLEAN
;
645 return token::XML_FLOAT
;
650 //---------------------------------------------------------------------
651 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix
, const sal_Char
* _pName
, const ::rtl::OUString
& _rValue
)
653 OSL_ENSURE(0 == m_rContext
.getGlobalContext().GetXAttrList()->getValueByName(::rtl::OUString::createFromAscii(_pName
)).getLength(),
654 "OPropertyExport::AddAttribute: already have such an attribute");
656 m_rContext
.getGlobalContext().AddAttribute(_nPrefix
, _pName
, _rValue
);
659 //---------------------------------------------------------------------
660 void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
, const ::rtl::OUString
& _rValue
)
662 OSL_ENSURE(0 == m_rContext
.getGlobalContext().GetXAttrList()->getValueByName( _rName
).getLength(),
663 "OPropertyExport::AddAttribute: already have such an attribute");
665 m_rContext
.getGlobalContext().AddAttribute( _nPrefix
, _rName
, _rValue
);
668 //---------------------------------------------------------------------
669 void OPropertyExport::AddAttributeASCII(sal_uInt16 _nPrefix
, const sal_Char
* _pName
, const sal_Char
*pValue
)
671 OSL_ENSURE(0 == m_rContext
.getGlobalContext().GetXAttrList()->getValueByName(::rtl::OUString::createFromAscii(_pName
)).getLength(),
672 "OPropertyExport::AddAttributeASCII: already have such an attribute");
674 m_rContext
.getGlobalContext().AddAttributeASCII(_nPrefix
, _pName
, pValue
);
677 //---------------------------------------------------------------------
678 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix
, ::xmloff::token::XMLTokenEnum _eName
, const ::rtl::OUString
& _rValue
)
680 OSL_ENSURE(0 == m_rContext
.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName
)).getLength(),
681 "OPropertyExport::AddAttribute: already have such an attribute");
683 m_rContext
.getGlobalContext().AddAttribute(_nPrefix
, _eName
, _rValue
);
686 //---------------------------------------------------------------------
687 void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix
, ::xmloff::token::XMLTokenEnum _eName
, ::xmloff::token::XMLTokenEnum _eValue
)
689 OSL_ENSURE(0 == m_rContext
.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName
)).getLength(),
690 "OPropertyExport::AddAttribute: already have such an attribute");
692 m_rContext
.getGlobalContext().AddAttribute(_nPrefix
, _eName
, _eValue
);
695 //---------------------------------------------------------------------
696 void OPropertyExport::dbg_implCheckProperty(const ::rtl::OUString
& _rPropertyName
, const Type
* _pType
)
700 // the property must exist
701 if (!m_xPropertyInfo
->hasPropertyByName(_rPropertyName
))
703 OSL_ENSURE(sal_False
,
704 ::rtl::OString("OPropertyExport::dbg_implCheckProperty: no property with the name ") +=
705 ::rtl::OString(_rPropertyName
.getStr(), _rPropertyName
.getLength(), RTL_TEXTENCODING_ASCII_US
) +=
706 ::rtl::OString("!"));
712 // and it must have the correct type
713 Property aPropertyDescription
= m_xPropertyInfo
->getPropertyByName(_rPropertyName
);
714 OSL_ENSURE(aPropertyDescription
.Type
.equals(*_pType
), "OPropertyExport::dbg_implCheckProperty: invalid property type!");
719 OSL_ENSURE(sal_False
, "OPropertyExport::dbg_implCheckProperty: caught an exception, could not check the property!");
722 #endif // DBG_UTIL - dbg_implCheckProperty
724 //.........................................................................
725 } // namespace xmloff
726 //.........................................................................