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>
43#include <tools/datetime.hxx>
62 ,m_xPropertyInfo(
m_xProps->getPropertySetInfo() )
63 ,m_xPropertyState( _rxProps, UNO_QUERY )
72 OSL_ENSURE(
m_xPropertyInfo.is(),
"OPropertyExport::OPropertyExport: need an XPropertySetInfo!");
83 && ( PropertyState_DEFAULT_VALUE ==
m_xPropertyState->getPropertyState( i_propertyName ) );
85 && ( (
m_xPropertyInfo->getPropertyByName( i_propertyName ).Attributes & PropertyAttribute::REMOVABLE ) != 0 );
86 return ( !bIsDefaultValue || bIsDynamicProperty );
89 template<
typename T >
void
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))
109 std::unique_ptr<SvXMLElementExport> pPropertiesTag;
130 aValue =
m_xProps->getPropertyValue(rProperty);
136 bool bIsSequence = TypeClass_SEQUENCE == aValue.getValueTypeClass();
141 aExportType = aValue.getValueType();
145 bool bIsEmptyValue = TypeClass_VOID == aValue.getValueType().getTypeClass();
148 css::beans::Property aPropDesc =
m_xPropertyInfo->getPropertyByName( rProperty );
149 aExportType = aPropDesc.Type;
159 switch ( eValueType )
166 if( !bIsSequence && !bIsEmptyValue )
183 switch ( aExportType.getTypeClass() )
185 case TypeClass_STRING:
186 exportRemainingPropertiesSequence< OUString >(
187 aValue, eValueAttName);
189 case TypeClass_DOUBLE:
190 exportRemainingPropertiesSequence< double >(
191 aValue, eValueAttName);
193 case TypeClass_BOOLEAN:
194 exportRemainingPropertiesSequence< sal_Bool >(
195 aValue, eValueAttName);
198 exportRemainingPropertiesSequence< sal_Int8 >(
199 aValue, eValueAttName);
201 case TypeClass_SHORT:
202 exportRemainingPropertiesSequence< sal_Int16 >(
203 aValue, eValueAttName);
206 exportRemainingPropertiesSequence< sal_Int32 >(
207 aValue, eValueAttName);
209 case TypeClass_HYPER:
210 exportRemainingPropertiesSequence< sal_Int64 >(
211 aValue, eValueAttName);
214 OSL_FAIL(
"OPropertyExport::exportRemainingProperties: unsupported sequence type !");
227 if ( rProp.Attributes & PropertyAttribute::TRANSIENT )
230 if ( ( rProp.Attributes & PropertyAttribute::READONLY ) != 0 )
232 if ( ( rProp.Attributes & PropertyAttribute::REMOVABLE ) == 0 )
239 const OUString& _rPropertyName )
250 m_xProps->getPropertyValue( _rPropertyName ) >>= sPropValue;
253 if ( !sPropValue.isEmpty() )
254 AddAttribute( _nNamespaceKey, _pAttributeName, sPropValue );
261 const OUString& _rPropertyName,
const BoolAttrFlags _nBooleanAttributeFlags)
271 bool bCurrentValue = bDefault;
272 Any aCurrentValue =
m_xProps->getPropertyValue( _rPropertyName );
273 if (aCurrentValue.hasValue())
275 bCurrentValue = ::cppu::any2bool(aCurrentValue);
279 bCurrentValue = !bCurrentValue;
282 if (bDefaultVoid || (bDefault != bCurrentValue))
299 const OUString& _rPropertyName,
const sal_Int16 _nDefault,
bool force)
304 sal_Int16 nCurrentValue(_nDefault);
305 m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
308 if (force || _nDefault != nCurrentValue)
311 AddAttribute(_nNamespaceKey, _pAttributeName, OUString::number(nCurrentValue));
319 const OUString& _rPropertyName,
const sal_Int32 _nDefault )
324 sal_Int32 nCurrentValue( _nDefault );
325 m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
328 if ( _nDefault != nCurrentValue )
331 AddAttribute( _nNamespaceKey, _pAttributeName, OUString::number(nCurrentValue) );
339 const sal_uInt16 _nNamespaceKey,
const OUString& _pAttributeName,
341 const sal_uInt16 _nDefault,
const bool _bVoidDefault)
344 Any aValue =
m_xProps->getPropertyValue(rPropertyName);
346 if (aValue.hasValue())
348 sal_Int32 nCurrentValue(_nDefault);
349 ::cppu::enum2int(nCurrentValue, aValue);
352 if ((_nDefault != nCurrentValue) || _bVoidDefault)
356 OUStringBuffer sBuffer;
359 AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
365 AddAttribute(_nNamespaceKey, _pAttributeName, OUString());
377 if( sTargetFrame !=
"_blank" )
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;
398 else if (aAny.has<OUString>())
400 auto sURL = aAny.get<OUString>();
405 SAL_WARN(
"xmloff.forms",
"OPropertyExport::exportRelativeTargetLocation: "
406 "Value of " << _sPropertyName <<
" not found!");
409 if (!sTargetLocation.isEmpty())
426 for (sal_Int32
i=0;
i<xStylePropertiesSupplier->GetEntryCount(); ++
i)
447 const sal_uInt16 _nAttributeNamespaceKey,
const OUString& _pAttributeName,
const OUString& sPropertyName)
453 Any aCurrentValue =
m_xProps->getPropertyValue(sPropertyName);
454 if (!aCurrentValue.hasValue())
459 if (sValue.isEmpty() && (TypeClass_STRING == aCurrentValue.getValueTypeClass()))
463 if ((aProperty.Attributes & PropertyAttribute::MAYBEVOID) == 0)
470 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sValue);
474 const OUString& _rPropertyName)
480 Sequence< OUString > aItems;
481 m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
483 OUStringBuffer sFinalList;
486 const OUString
sQuote(&_aQuoteCharacter, 1);
487 const OUString sSeparator(&_aListSeparator, 1);
488 const bool bQuote = !
sQuote.isEmpty();
491 const OUString* pItems = aItems.getConstArray();
492 const OUString* pEnd = pItems + aItems.getLength();
493 const OUString* pLastElement = pEnd - 1;
499 OSL_ENSURE(-1 == pItems->indexOf(_aQuoteCharacter),
500 "OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
503 sFinalList.append(
sQuote);
504 sFinalList.append(*pItems);
506 sFinalList.append(
sQuote);
508 if (pItems != pLastElement)
509 sFinalList.append(sSeparator);
512 if (!sFinalList.isEmpty())
513 AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sFinalList.makeStringAndClear());
521 switch (_rValue.getValueTypeClass())
523 case TypeClass_STRING:
525 OUString sCurrentValue;
526 _rValue >>= sCurrentValue;
530 case TypeClass_DOUBLE:
534 case TypeClass_BOOLEAN:
538 case TypeClass_UNSIGNED_SHORT:
539 case TypeClass_SHORT:
544 case TypeClass_UNSIGNED_LONG:
545 case TypeClass_HYPER:
548 case TypeClass_UNSIGNED_HYPER:
549 aBuffer.append(
static_cast<sal_Int64
>(_rValue.get<sal_uInt64>()));
555 ::cppu::enum2int(
nValue, _rValue);
562 css::util::Date aDate;
563 css::util::Time aTime;
564 css::util::DateTime aDateTime;
565 if (_rValue >>= aDate)
568 ::utl::typeConvert(aDate, aToolsDate);
571 else if (_rValue >>= aTime)
578 else if (_rValue >>= aDateTime)
581 ::utl::typeConvert(aDateTime, aToolsDateTime);
588 fValue += aToolsDateTime.
GetDate();
595 OSL_FAIL(
"OPropertyExport::implConvertAny: unsupported value type!");
604 return aBuffer.makeStringAndClear();
610 switch (_rType.getTypeClass())
612 case TypeClass_STRING:
614 case TypeClass_DOUBLE:
616 case TypeClass_SHORT:
618 case TypeClass_HYPER:
621 case TypeClass_BOOLEAN:
633 "OPropertyExport::AddAttribute: already have such an attribute");
641 "OPropertyExport::AddAttribute: already have such an attribute");
649 "OPropertyExport::AddAttribute: already have such an attribute");
661 SAL_WARN(
"xmloff.forms",
"OPropertyExport: "
662 "no property with the name " + _rPropertyName +
"!");
670 OSL_ENSURE(aPropertyDescription.Type.equals(*_pType),
"OPropertyExport::dbg_implCheckProperty: invalid property type!");
PropertiesInfo aProperties
sal_Int32 GetDate() const
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
OUString AddEmbeddedObject(const OUString &rEmbeddedObjectURL)
css::uno::Reference< css::xml::sax::XAttributeList > GetXAttrList() const
OUString AddEmbeddedXGraphic(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic, OUString &rOutMimeType, OUString const &rRequestedName=OUString())
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
static bool convertBool(bool &rBool, std::u16string_view rString)
virtual SvXMLExport & getGlobalContext()=0
virtual ::rtl::Reference< SvXMLExportPropertyMapper > getStylePropertyMapper()=0
void exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName)
exports a property value, which is a string sequence, as attribute
OPropertyExport(IFormsExportContext &_rContext, const css::uno::Reference< css::beans::XPropertySet > &_rxProps)
constructs an object capable of handling attributes for export
void examinePersistence()
examines a property set given for all properties which's value are to made persistent
IFormsExportContext & m_rContext
void exportInt32PropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName, const sal_Int32 _nDefault)
add an attribute which is represented by a sal_Int32 property to the export context
void exportedProperty(const OUString &_rPropertyName)
indicates that a property has been handled by a derived class, without using the helper methods of th...
bool shouldExportProperty(const OUString &i_propertyName) const
determines whether the given property is to be exported
void flagStyleProperties()
flag the style properties as 'already exported'
std::set< OUString > m_aRemainingProps
void exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName, const sal_Int16 _nDefault, const bool force=false)
add an attribute which is represented by a sal_Int16 property to the export context
const css::uno::Reference< css::beans::XPropertySet > m_xProps
const css::uno::Reference< css::beans::XPropertyState > m_xPropertyState
::xmloff::token::XMLTokenEnum implGetPropertyXMLType(const css::uno::Type &_rType)
void exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName, const BoolAttrFlags _nBooleanAttributeFlags)
add an attribute which is represented by a boolean property to the export context
void exportGenericPropertyAttribute(const sal_uInt16 _nAttributeNamespaceKey, const OUString &_pAttributeName, const OUString &_pPropertyName)
add an arbitrary attribute extracted from an arbitrary property to the export context
void exportEnumPropertyAttributeImpl(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName, const SvXMLEnumMapEntry< sal_uInt16 > *_pValueMap, const sal_uInt16 _nDefault, const bool _bVoidDefault)
void exportRemainingProperties()
OUString implConvertAny(const css::uno::Any &_rValue)
tries to convert an arbitrary <type scope="com.sun:star.uno">Any</type> into an string
void exportRelativeTargetLocation(const OUString &_sPropertyName, CCAFlags _nProperty, bool _bAddType)
void exportRemainingPropertiesSequence(css::uno::Any const &value, token::XMLTokenEnum eValueAttName)
void exportStringPropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName)
add an attribute which is represented by a string property to the export context
const css::uno::Reference< css::beans::XPropertySetInfo > m_xPropertyInfo
void dbg_implCheckProperty(const OUString &_rPropertyName, const css::uno::Type *_pType)
check a given property set for the existence and type correctness of a given property
void AddAttribute(sal_uInt16 _nPrefix, const OUString &_rName, const OUString &_rValue)
void exportTargetFrameAttribute()
add the hlink:target-frame attribute to the export context.
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
bool getBOOL(const Any &_rAny)
sal_Int64 getINT64(const Any &_rAny)
Type getSequenceElementType(const Type &_rSequenceType)
double getDouble(const Any &_rAny)
sal_Int32 getINT32(const Any &_rAny)
OUString getString(const Any &_rAny)
XMLTokenEnum
The enumeration of all XML tokens.
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
constexpr OUStringLiteral PROPERTY_TARGETFRAME
constexpr OUStringLiteral PROPERTY_FONT
constexpr OUStringLiteral PROPERTY_DATEFORMAT
constexpr OUStringLiteral PROPERTY_TIMEFORMAT
#define DBG_CHECK_PROPERTY_NO_TYPE(name)
#define DBG_CHECK_PROPERTY(name, type)
const Reference< XComponentContext > & m_rContext
std::unique_ptr< char[]> aBuffer
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_FORM
constexpr sal_uInt16 XML_NAMESPACE_OFFICE