20#include <com/sun/star/xml/AttributeData.hpp>
21#include <com/sun/star/beans/XMultiPropertySet.hpp>
22#include <com/sun/star/lang/IllegalArgumentException.hpp>
23#include <com/sun/star/lang/WrappedTargetException.hpp>
24#include <com/sun/star/beans/UnknownPropertyException.hpp>
25#include <com/sun/star/beans/PropertyVetoException.hpp>
26#include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
27#include <com/sun/star/beans/XTolerantMultiPropertySet.hpp>
28#include <com/sun/star/beans/XPropertySet.hpp>
29#include <rtl/ustrbuf.hxx>
31#include <osl/diagnose.h>
56using ::com::sun::star::lang::IllegalArgumentException;
57using ::com::sun::star::lang::WrappedTargetException;
58using ::com::sun::star::beans::UnknownPropertyException;
59using ::com::sun::star::beans::PropertyVetoException;
66 maPropMapper (
std::move( xMapper ))
79 maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() );
87 while( xNext->mxNextMapper.is())
88 xNext = xNext->mxNextMapper;
89 xNext->mxNextMapper = rMapper;
98 while( xNext->mxNextMapper.is())
100 xNext = xNext->mxNextMapper;
107 std::vector< XMLPropertyState >& rProperties,
108 const Reference< XFastAttributeList >& xAttrList,
111 sal_uInt32 nPropType,
113 sal_Int32 nEndIdx )
const
115 Reference< XNameContainer > xAttrContainer;
117 if( -1 == nStartIdx )
124 sal_Int32
nToken = aIter.getToken();
128 const OUString aPrefix = SvXMLImport::getNamespacePrefixFromToken(
nToken, &rNamespaceMap);
129 const OUString aNamespaceURI = SvXMLImport::getNamespaceURIFromToken(
nToken);
130 OUString sAttrName = SvXMLImport::getNameFromToken(
nToken );
131 if ( !aPrefix.isEmpty() )
132 sAttrName = aPrefix + SvXMLImport::aNamespaceSeparator + sAttrName;
134 const OUString sValue = aIter.toString();
137 nPropType, nStartIdx, nEndIdx, xAttrContainer,
138 sAttrName, aNamespaceURI, sValue);
141 const css::uno::Sequence< css::xml::Attribute > unknownAttribs = xAttrList->getUnknownAttributes();
142 for (
const css::xml::Attribute& rAttribute : unknownAttribs)
144 int nSepIndex = rAttribute.Name.indexOf(SvXMLImport::aNamespaceSeparator);
148 OUString aPrefix = rAttribute.Name.copy(0, nSepIndex);
155 nPropType, nStartIdx, nEndIdx, xAttrContainer,
156 rAttribute.Name, rAttribute.NamespaceURL, rAttribute.Value);
159 finished( rProperties, nStartIdx, nEndIdx );
163 std::vector< XMLPropertyState >& rProperties,
166 const sal_uInt32 nPropType,
167 const sal_Int32 nStartIdx,
168 const sal_Int32 nEndIdx,
169 Reference< XNameContainer >& xAttrContainer,
170 const OUString& rAttrName,
171 const OUString& aNamespaceURI,
172 const OUString& sValue)
const
174 OUString aLocalName, aPrefix, aNamespace;
176 &aLocalName, &aNamespace );
183 sal_Int32
nIndex = nStartIdx - 1;
184 sal_uInt32 nFlags = 0;
189 bool bNoWarning =
false;
205 sal_Int32 nReference = -1;
212 const sal_Int32 nSize = rProperties.size();
213 for( nReference = 0; nReference < nSize; nReference++ )
215 sal_Int32 nRefIdx = rProperties[nReference].mnIndex;
216 if( (nRefIdx != -1) && (
nIndex != nRefIdx) &&
217 (
maPropMapper->GetEntryAPIName( nRefIdx ) == aAPIName ))
219 aNewProperty = rProperties[nReference];
225 if( nReference == nSize )
238 sal_uInt32 nOldSize = rProperties.size();
241 sValue, rUnitConverter,
245 bNoWarning |= ( nOldSize != rProperties.size() );
255 if( nReference == -1 )
256 rProperties.push_back( aNewProperty );
258 rProperties[nReference] = aNewProperty;
270 { rAttrName, sValue } );
283 "unknown attribute: \"" << rAttrName <<
"\"");
286 if( !xAttrContainer.is() )
290 xAttrContainer = xNew;
320 rProperties.push_back( aNewProperty );
324 if( xAttrContainer.is() )
328 aData.Value = sValue;
333 aData.Namespace = aNamespaceURI;
348 std::vector< XMLPropertyState >& rProperties,
349 const OUString& rValue,
353 OSL_ENSURE(
mxNextMapper.is(),
"unsupported special item in xml import" );
355 return mxNextMapper->handleSpecialItem( rProperty, rProperties, rValue,
356 rUnitConverter, rNamespaceMap );
362 const ::std::vector< XMLPropertyState >& rProperties,
363 css::uno::Sequence< css::beans::PropertyValue >& rValues )
366 sal_Int32
nCount = rProperties.size();
367 sal_Int32 nValueCount = 0;
368 rValues.realloc(
nCount );
369 PropertyValue *pProps = rValues.getArray();
373 sal_Int32 nIdx = rProp.
mnIndex;
377 if( !pProps->Name.isEmpty() )
384 if( nValueCount <
nCount )
385 rValues.realloc( nValueCount );
389 const ::std::vector< XMLPropertyState >& aProperties,
390 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
393 OSL_ENSURE( rPropSet.is(),
"need an XPropertySet" );
399 sal_Int32 nIdx = rProp.
mnIndex;
405 const sal_Int32 nPropFlags =
maPropMapper->GetEntryFlags( nIdx );
408 if( ( pSpecialContextIds !=
nullptr ) &&
413 sal_Int16 nContextId =
maPropMapper->GetEntryContextId(nIdx);
415 for ( sal_Int32
n = 0;
420 if ( pSpecialContextIds[
n].nContextID == nContextId )
432 const std::vector< XMLPropertyState >& aProperties,
433 const Reference< XPropertySet >& rPropSet,
438 Reference< XTolerantMultiPropertySet > xTolPropSet( rPropSet, UNO_QUERY );
439 if (xTolPropSet.is())
441 pSpecialContextIds );
446 Reference< XPropertySetInfo > xInfo(rPropSet->getPropertySetInfo());
449 Reference<XMultiPropertySet> xMultiPropSet( rPropSet, UNO_QUERY );
450 if ( xMultiPropSet.is() )
455 pSpecialContextIds );
464 pSpecialContextIds );
471 const std::vector<XMLPropertyState> & rProperties,
472 const Reference<XPropertySet> & rPropSet,
473 const Reference<XPropertySetInfo> & rPropSetInfo,
475 SvXMLImport& rImport,
478 OSL_ENSURE( rPropSet.is(),
"need an XPropertySet" );
479 OSL_ENSURE( rPropSetInfo.is(),
"need an XPropertySetInfo" );
483 sal_Int32
nCount = rProperties.size();
489 sal_Int32 nIdx = rProp.
mnIndex;
495 const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
496 const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
500 rPropSetInfo->hasPropertyByName( rPropName ) ) )
505 rPropSet->setPropertyValue( rPropName, rProp.
maValue );
508 catch (
const IllegalArgumentException& e )
514 Sequence<OUString>
aSeq { rPropName };
517 aSeq, e.Message,
nullptr );
520 catch (
const UnknownPropertyException& e )
523 Sequence<OUString>
aSeq { rPropName };
526 aSeq, e.Message,
nullptr );
528 catch (
const PropertyVetoException& e )
531 Sequence<OUString>
aSeq { rPropName };
534 aSeq, e.Message,
nullptr );
536 catch (
const WrappedTargetException& e )
539 Sequence<OUString>
aSeq { rPropName };
542 aSeq, e.Message,
nullptr );
547 if( ( pSpecialContextIds !=
nullptr ) &&
552 sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
554 for ( sal_Int32
n = 0;
559 if ( pSpecialContextIds[
n].nContextID == nContextId )
576struct PropertyPairLessFunctor
580 return (*
a.first < *b.first);
587 const std::vector<XMLPropertyState> & rProperties,
588 const Reference<XPropertySetInfo> & rPropSetInfo,
591 Sequence<OUString>& rNames,
592 Sequence<Any>& rValues)
594 sal_Int32
nCount = rProperties.size();
597 std::vector<PropertyPair> aPropertyPairs;
598 aPropertyPairs.reserve(
nCount );
605 sal_Int32 nIdx = rProp.
mnIndex;
611 const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
612 const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
616 !rPropSetInfo.is() ||
617 rPropSetInfo->hasPropertyByName(rPropName) ) )
620 aPropertyPairs.emplace_back( &rPropName, &rProp.
maValue );
624 if( ( pSpecialContextIds !=
nullptr ) &&
629 sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
630 for ( sal_Int32
n = 0;
635 if ( pSpecialContextIds[
n].nContextID == nContextId )
648 sort( aPropertyPairs.begin(), aPropertyPairs.end(),
649 PropertyPairLessFunctor());
652 rNames.realloc( aPropertyPairs.size() );
653 OUString* pNamesArray = rNames.getArray();
654 rValues.realloc( aPropertyPairs.size() );
655 Any* pValuesArray = rValues.getArray();
659 for(
const auto& rPropertyPair : aPropertyPairs )
661 pNamesArray[
i] = *(rPropertyPair.first);
662 pValuesArray[
i++] = *(rPropertyPair.second);
667 const std::vector<XMLPropertyState> & rProperties,
668 const Reference<XMultiPropertySet> & rMultiPropSet,
669 const Reference<XPropertySetInfo> & rPropSetInfo,
673 OSL_ENSURE( rMultiPropSet.is(),
"Need multi property set. ");
674 OSL_ENSURE( rPropSetInfo.is(),
"Need property set info." );
676 bool bSuccessful =
false;
678 Sequence<OUString> aNames;
679 Sequence<Any> aValues;
687 rMultiPropSet->setPropertyValues( aNames, aValues );
692 OSL_ENSURE(bSuccessful,
"Exception caught; style may not be imported correctly.");
699 const std::vector<XMLPropertyState> & rProperties,
700 const Reference<XTolerantMultiPropertySet> & rTolMultiPropSet,
702 SvXMLImport& rImport,
705 OSL_ENSURE( rTolMultiPropSet.is(),
"Need tolerant multi property set. ");
707 bool bSuccessful =
false;
709 Sequence<OUString> aNames;
710 Sequence<Any> aValues;
718 const Sequence< SetPropertyTolerantFailed > aResults(rTolMultiPropSet->setPropertyValuesTolerant( aNames, aValues ));
719 bSuccessful = !aResults.hasElements();
720 for(
const auto& rResult : aResults)
722 Sequence<OUString>
aSeq { rResult.Name };
724 switch (rResult.Result)
726 case TolerantPropertySetResultType::UNKNOWN_PROPERTY :
729 case TolerantPropertySetResultType::ILLEGAL_ARGUMENT :
732 case TolerantPropertySetResultType::PROPERTY_VETO :
735 case TolerantPropertySetResultType::WRAPPED_TARGET :
746 OSL_ENSURE(bSuccessful,
"Exception caught; style may not be imported correctly.");
753 std::vector< XMLPropertyState >& rProperties,
754 sal_Int32 nStartIndex, sal_Int32 nEndIndex )
const
758 mxNextMapper->finished( rProperties, nStartIndex, nEndIndex );
const SvXMLImport & m_rImport
PropertiesInfo aProperties
bool FillPropertySet(const ::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::beans::XPropertySet > &rPropSet, ContextID_Index_Pair *pSpecialContextIds=nullptr) const
void importXML(::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap, sal_uInt32 nPropType, sal_Int32 nStartIdx, sal_Int32 nEndIdx) const
fills the given itemset with the attributes in the given list the map is only searched within the ran...
void FillPropertySequence(const ::std::vector< XMLPropertyState > &aProperties, css::uno::Sequence< css::beans::PropertyValue > &rValues) const
rtl::Reference< SvXMLImportPropertyMapper > mxNextMapper
virtual bool handleSpecialItem(XMLPropertyState &rProperty, ::std::vector< XMLPropertyState > &rProperties, const OUString &rValue, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) const
this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set
void ChainImportMapper(const rtl::Reference< SvXMLImportPropertyMapper > &rMapper)
virtual void finished(::std::vector< XMLPropertyState > &rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex) const
This method is called when all attributes have benn processed.
static void PrepareForMultiPropertySet_(const ::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::beans::XPropertySetInfo > &rPropSetInfo, const rtl::Reference< XMLPropertySetMapper > &rPropMapper, ContextID_Index_Pair *pSpecialContextIds, css::uno::Sequence< OUString > &rNames, css::uno::Sequence< css::uno::Any > &rValues)
static bool FillTolerantMultiPropertySet_(const ::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::beans::XTolerantMultiPropertySet > &rTolPropSet, const rtl::Reference< XMLPropertySetMapper > &rPropMapper, SvXMLImport &rImport, ContextID_Index_Pair *pSpecialContextIds)
implementation helper for FillPropertySet: fill an XTolerantMultiPropertySet.
void importXMLAttribute(std::vector< XMLPropertyState > &rProperties, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap, sal_uInt32 nPropType, sal_Int32 nStartIdx, sal_Int32 nEndIdx, css::uno::Reference< css::container::XNameContainer > &xAttrContainer, const OUString &sAttrName, const OUString &aNamespaceURI, const OUString &sValue) const
rtl::Reference< XMLPropertySetMapper > maPropMapper
static bool FillMultiPropertySet_(const ::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::beans::XMultiPropertySet > &rMultiPropSet, const css::uno::Reference< css::beans::XPropertySetInfo > &rPropSetInfo, const rtl::Reference< XMLPropertySetMapper > &rPropMapper, ContextID_Index_Pair *pSpecialContextIds)
implementation helper for FillPropertySet: fill an XMultiPropertySet.
void CheckSpecialContext(const ::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::beans::XPropertySet > &rPropSet, ContextID_Index_Pair *pSpecialContextIds) const
SvXMLImportPropertyMapper(SvXMLImportPropertyMapper const &)=delete
virtual ~SvXMLImportPropertyMapper() override
static bool FillPropertySet_(const ::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::beans::XPropertySet > &rPropSet, const css::uno::Reference< css::beans::XPropertySetInfo > &rPropSetInfo, const rtl::Reference< XMLPropertySetMapper > &rPropMapper, SvXMLImport &rImport, ContextID_Index_Pair *pSpecialContextIds)
implementation helper for FillPropertySet: fill an XPropertySet.
sal_uInt16 GetKeyByPrefix(const OUString &rPrefix) const
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Sequence< sal_Int8 > aSeq
#define SAL_INFO_IF(condition, area, stream)
constexpr OUStringLiteral aData
const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG
const sal_uInt16 XML_NAMESPACE_NONE
const sal_uInt16 XML_NAMESPACE_XMLNS
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
This struct is used as an optional parameter to the static _FillPropertySet() methods.
Smart struct to transport an Any with an index to the appropriate property-name.
uno::Reference< uno::XInterface > SvUnoAttributeContainer_CreateInstance()
#define XMLERROR_STYLE_PROP_VALUE
#define XMLERROR_STYLE_PROP_OTHER
#define XMLERROR_STYLE_PROP_UNKNOWN
#define XMLERROR_FLAG_ERROR
#define XMLERROR_STYLE_ATTR_VALUE
#define XMLERROR_FLAG_WARNING
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
std::pair< const OUString *, const Any * > PropertyPair
constexpr sal_uInt16 XML_NAMESPACE_TEXT
#define XML_TYPE_PROP_CHART
#define MID_FLAG_MERGE_PROPERTY
#define XML_TYPE_PROP_PARAGRAPH
#define MID_FLAG_NO_PROPERTY_IMPORT
#define MID_FLAG_SPECIAL_ITEM_IMPORT
#define MID_FLAG_MULTI_PROPERTY
#define XML_TYPE_PROP_TEXT
#define MID_FLAG_NO_PROPERTY
#define MID_FLAG_ELEMENT_ITEM_IMPORT
#define MID_FLAG_MUST_EXIST
#define MID_FLAG_PROPERTY_MAY_THROW