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::XAttributeList;
54 using ::com::sun::star::xml::sax::XFastAttributeList;
61#define TYPE_DATETIME 3
66 css::util::Time lcl_getTime(
double _nValue)
68 css::util::Time aTime;
76 OSL_ENSURE(nIntValue < 24,
"lcl_getTime: more than a day?");
77 aTime.Hours = nIntValue;
82 css::util::Date lcl_getDate(
double _nValue )
85 css::util::Date aDate;
86 ::utl::typeConvert(aToolsDate, aDate);
95 bool bEnumAsInt =
false;
96 switch (_rExpectedType.getTypeClass())
98 case TypeClass_BOOLEAN:
104 OStringBuffer(
"PropertyConversion::convertString: could not convert \"" +
106 "\" into a boolean!").getStr());
107 aReturn <<= (_bInvertBoolean ? !bValue : bValue);
110 case TypeClass_SHORT:
118 OStringBuffer(
"PropertyConversion::convertString: could not convert \"" +
120 "\" into an integer!").getStr());
121 if (TypeClass_SHORT == _rExpectedType.getTypeClass())
122 aReturn <<= static_cast<sal_Int16>(
nValue);
131 sal_uInt16 nEnumValue(0);
133 OSL_ENSURE(bSuccess,
"PropertyConversion::convertString: could not convert to an enum value!");
136 if (TypeClass_SHORT == _rExpectedType.getTypeClass())
137 aReturn <<= static_cast<sal_Int16>(nEnumValue);
139 aReturn <<= static_cast<sal_Int32>(nEnumValue);
141 aReturn = ::cppu::int2enum(
static_cast<sal_Int32
>(nEnumValue), _rExpectedType);
144 case TypeClass_HYPER:
146 OSL_FAIL(
"PropertyConversion::convertString: 64-bit integers not implemented yet!");
149 case TypeClass_DOUBLE:
155 OStringBuffer(OString::Concat(
"PropertyConversion::convertString: could not convert \"") +
157 "\" into a double!").getStr());
161 case TypeClass_STRING:
162 aReturn <<= _rReadCharacters;
164 case TypeClass_STRUCT:
181 OStringBuffer(
"PropertyConversion::convertString: could not convert \"" +
183 "\" into a double!").getStr());
191 "PropertyConversion::convertString: a Date value with a fractional part?");
192 aReturn <<= lcl_getDate(
nValue);
197 OSL_ENSURE((
static_cast<sal_uInt32
>(
nValue)) == 0,
198 "PropertyConversion::convertString: a tools::Time value with more than a fractional part?");
199 aReturn <<= lcl_getTime(
nValue);
204 css::util::Time aTime = lcl_getTime(
nValue);
205 css::util::Date aDate = lcl_getDate(
nValue);
207 css::util::DateTime aDateTime;
208 aDateTime.NanoSeconds = aTime.NanoSeconds;
209 aDateTime.Seconds = aTime.Seconds;
210 aDateTime.Minutes = aTime.Minutes;
211 aDateTime.Hours = aTime.Hours;
212 aDateTime.Day = aDate.Day;
213 aDateTime.Month = aDate.Month;
214 aDateTime.Year = aDate.Year;
215 aReturn <<= aDateTime;
221 OSL_FAIL(
"PropertyConversion::convertString: unsupported property type!");
225 OSL_FAIL(
"PropertyConversion::convertString: invalid type class!");
235 static std::map< OUString, css::uno::Type > s_aTypeNameMap
248 const std::map< OUString, css::uno::Type >::iterator aTypePos = s_aTypeNameMap.find( _rType );
249 OSL_ENSURE( s_aTypeNameMap.end() != aTypePos,
"PropertyConversion::xmlTypeToUnoType: invalid property name!" );
250 if ( s_aTypeNameMap.end() != aTypePos )
251 aUnoType = aTypePos->second;
260 ,m_bTrackAttributes(false)
266 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
273 SAL_WARN(
"xmloff",
"unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
299 OSL_ENSURE(
m_bTrackAttributes,
"OPropertyImport::encounteredAttribute: attribute tracking not enabled!");
306 OSL_ENSURE(_rChars.trim().isEmpty(),
"OPropertyImport::Characters: non-whitespace characters!");
315 PropertyValue aNewValue;
334 SAL_WARN(
"xmloff",
"OPropertyImport::handleAttribute: Can't handle "
335 << SvXMLImport::getPrefixAndNameFromToken(nAttributeToken) <<
"=" << _rValue );
345 ,m_xPropertyImporter(
std::move(_xPropertyImporter))
350 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
363#if OSL_DEBUG_LEVEL > 0
366 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
368 OSL_ENSURE(0 == xAttrList->getFastAttributes().getLength(),
"OPropertyElementsContext::StartElement: the form:properties element should not have attributes!");
373 OSL_ENSURE(_rChars.trim().isEmpty(),
"OPropertyElementsContext::Characters: non-whitespace characters detected!");
381 ,m_xPropertyImporter(
std::move(_xPropertyImporter))
387 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
389 css::beans::PropertyValue aPropValue;
390 css::uno::Type aPropType;
392 OUString
sType, sValue;
395 switch (aIter.getToken())
398 aPropValue.Name = aIter.toString();
401 sType = aIter.toString();
406 sValue = aIter.toString();
414 OSL_ENSURE(!aPropValue.Name.isEmpty(),
"OSinglePropertyContext::StartElement: invalid property name!");
418 if( TypeClass_VOID == aPropType.getTypeClass() )
420 aPropValue.Value =
Any();
430 if( !aPropValue.Name.isEmpty() )
438 ,m_xPropertyImporter(
std::move( _rPropertyImporter ))
444 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
448 switch (aIter.getToken())
465 "OListPropertyContext::EndElement: no property name or type!" );
471 Any* pListElement = aListElements.getArray();
479 PropertyValue aSequenceValue;
481 aSequenceValue.Value <<= aListElements;
487 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
500 ,m_rListValueHolder( _rListValueHolder )
506 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
510 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)
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