33#include <osl/diagnose.h>
39#include <com/sun/star/util/Date.hpp>
40#include <com/sun/star/util/Time.hpp>
41#include <com/sun/star/util/DateTime.hpp>
43#include <rtl/strbuf.hxx>
53 using ::com::sun::star::xml::sax::XFastAttributeList;
60#define TYPE_DATETIME 3
65 css::util::Time lcl_getTime(
double _nValue)
67 css::util::Time aTime;
75 OSL_ENSURE(nIntValue < 24,
"lcl_getTime: more than a day?");
76 aTime.Hours = nIntValue;
81 css::util::Date lcl_getDate(
double _nValue )
84 css::util::Date aDate;
85 ::utl::typeConvert(aToolsDate, aDate);
94 bool bEnumAsInt =
false;
95 switch (_rExpectedType.getTypeClass())
97 case TypeClass_BOOLEAN:
103 OStringBuffer(
"PropertyConversion::convertString: could not convert \"" +
105 "\" into a boolean!").getStr());
106 aReturn <<= (_bInvertBoolean ? !bValue : bValue);
109 case TypeClass_SHORT:
117 OStringBuffer(
"PropertyConversion::convertString: could not convert \"" +
119 "\" into an integer!").getStr());
120 if (TypeClass_SHORT == _rExpectedType.getTypeClass())
121 aReturn <<= static_cast<sal_Int16>(
nValue);
130 sal_uInt16 nEnumValue(0);
132 OSL_ENSURE(bSuccess,
"PropertyConversion::convertString: could not convert to an enum value!");
135 if (TypeClass_SHORT == _rExpectedType.getTypeClass())
136 aReturn <<= static_cast<sal_Int16>(nEnumValue);
138 aReturn <<= static_cast<sal_Int32>(nEnumValue);
140 aReturn = ::cppu::int2enum(
static_cast<sal_Int32
>(nEnumValue), _rExpectedType);
143 case TypeClass_HYPER:
145 OSL_FAIL(
"PropertyConversion::convertString: 64-bit integers not implemented yet!");
148 case TypeClass_DOUBLE:
154 OStringBuffer(OString::Concat(
"PropertyConversion::convertString: could not convert \"") +
156 "\" into a double!").getStr());
160 case TypeClass_STRING:
161 aReturn <<= _rReadCharacters;
163 case TypeClass_STRUCT:
180 OStringBuffer(
"PropertyConversion::convertString: could not convert \"" +
182 "\" into a double!").getStr());
190 "PropertyConversion::convertString: a Date value with a fractional part?");
191 aReturn <<= lcl_getDate(
nValue);
196 OSL_ENSURE((
static_cast<sal_uInt32
>(
nValue)) == 0,
197 "PropertyConversion::convertString: a tools::Time value with more than a fractional part?");
198 aReturn <<= lcl_getTime(
nValue);
203 css::util::Time aTime = lcl_getTime(
nValue);
204 css::util::Date aDate = lcl_getDate(
nValue);
206 css::util::DateTime aDateTime;
207 aDateTime.NanoSeconds = aTime.NanoSeconds;
208 aDateTime.Seconds = aTime.Seconds;
209 aDateTime.Minutes = aTime.Minutes;
210 aDateTime.Hours = aTime.Hours;
211 aDateTime.Day = aDate.Day;
212 aDateTime.Month = aDate.Month;
213 aDateTime.Year = aDate.Year;
214 aReturn <<= aDateTime;
220 OSL_FAIL(
"PropertyConversion::convertString: unsupported property type!");
224 OSL_FAIL(
"PropertyConversion::convertString: invalid type class!");
234 static std::map< OUString, css::uno::Type > s_aTypeNameMap
247 const std::map< OUString, css::uno::Type >::iterator aTypePos = s_aTypeNameMap.find( _rType );
248 OSL_ENSURE( s_aTypeNameMap.end() != aTypePos,
"PropertyConversion::xmlTypeToUnoType: invalid property name!" );
249 if ( s_aTypeNameMap.end() != aTypePos )
250 aUnoType = aTypePos->second;
259 ,m_bTrackAttributes(false)
265 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
272 SAL_WARN(
"xmloff",
"unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
298 OSL_ENSURE(
m_bTrackAttributes,
"OPropertyImport::encounteredAttribute: attribute tracking not enabled!");
305 OSL_ENSURE(
o3tl::trim(_rChars).empty(),
"OPropertyImport::Characters: non-whitespace characters!");
314 PropertyValue aNewValue;
333 SAL_WARN(
"xmloff",
"OPropertyImport::handleAttribute: Can't handle "
334 << SvXMLImport::getPrefixAndNameFromToken(nAttributeToken) <<
"=" << _rValue );
344 ,m_xPropertyImporter(
std::move(_xPropertyImporter))
349 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
362#if OSL_DEBUG_LEVEL > 0
365 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
367 OSL_ENSURE(0 == xAttrList->getFastAttributes().getLength(),
"OPropertyElementsContext::StartElement: the form:properties element should not have attributes!");
372 OSL_ENSURE(
o3tl::trim(_rChars).empty(),
"OPropertyElementsContext::Characters: non-whitespace characters detected!");
380 ,m_xPropertyImporter(
std::move(_xPropertyImporter))
386 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
388 css::beans::PropertyValue aPropValue;
389 css::uno::Type aPropType;
391 OUString
sType, sValue;
394 switch (aIter.getToken())
397 aPropValue.Name = aIter.toString();
400 sType = aIter.toString();
405 sValue = aIter.toString();
413 OSL_ENSURE(!aPropValue.Name.isEmpty(),
"OSinglePropertyContext::StartElement: invalid property name!");
417 if( TypeClass_VOID == aPropType.getTypeClass() )
419 aPropValue.Value =
Any();
429 if( !aPropValue.Name.isEmpty() )
437 ,m_xPropertyImporter(
std::move( _rPropertyImporter ))
443 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
447 switch (aIter.getToken())
464 "OListPropertyContext::EndElement: no property name or type!" );
470 Any* pListElement = aListElements.getArray();
478 PropertyValue aSequenceValue;
480 aSequenceValue.Value <<= aListElements;
486 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
499 ,m_rListValueHolder( _rListValueHolder )
505 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
509 switch(aIter.getToken())
This class deliberately does not support XWeak, to improve performance when loading large documents.
SvXMLImport & GetImport()
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...
css::uno::Type const & get()
const_iterator find(const Value &x) const
const_iterator end() const
std::pair< const_iterator, bool > insert(Value &&x)
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
static bool convertBool(bool &rBool, std::u16string_view rString)
const AttributeAssignment * getAttributeTranslation(sal_Int32 nAttributeToken)
return the AttributeAssignment which corresponds to the given attribute
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
OPropertyImportRef m_xPropertyImporter
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
::std::vector< OUString > m_aListValues
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
OListPropertyContext(SvXMLImport &_rImport, OPropertyImportRef _xPropertyImporter)
OListValueContext(SvXMLImport &_rImport, OUString &_rListValueHolder)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
OUString & m_rListValueHolder
helper class for importing the <form:properties> element
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
OPropertyElementsContext(SvXMLImport &_rImport, OPropertyImportRef _xPropertyImporter)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
OPropertyImportRef m_xPropertyImporter
virtual void SAL_CALL characters(const OUString &_rChars) override
This method is called for all characters that are contained in the current element.
PropertyValueArray m_aValues
void implPushBackPropertyValue(const css::beans::PropertyValue &_rProp)
virtual bool handleAttribute(sal_Int32 nElement, const OUString &_rValue)
handle one single attribute.
o3tl::sorted_vector< sal_Int32 > m_aEncounteredAttributes
OPropertyImport(OFormLayerXMLImport_Impl &_rImport)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
bool encounteredAttribute(sal_Int32 nElement) const
determine if the element imported by the object had a given attribute.
virtual void SAL_CALL characters(const OUString &_rChars) override
This method is called for all characters that are contained in the current element.
OFormLayerXMLImport_Impl & m_rContext
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &_rxAttrList) override
helper class for importing a single <form:property> element
OPropertyImportRef m_xPropertyImporter
OSinglePropertyContext(SvXMLImport &_rImport, OPropertyImportRef _xPropertyImporter)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
static css::uno::Any convertString(const css::uno::Type &_rExpectedType, const OUString &_rReadCharacters, const SvXMLEnumMapEntry< EnumT > *_pEnumMap=nullptr)
static css::uno::Type xmlTypeToUnoType(const OUString &_rType)
#define SAL_WARN(area, stream)
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)
constexpr T & temporary(T &&x)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
const SvXMLEnumMapEntry< sal_uInt16 > * pEnumMap
css::uno::Type aPropertyType
const Reference< XComponentContext > & m_rContext
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)
constexpr sal_Int32 TOKEN_MASK