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>
55 using namespace ::
std;
57 using ::com::sun::star::lang::IllegalArgumentException;
58 using ::com::sun::star::lang::WrappedTargetException;
59 using ::com::sun::star::beans::UnknownPropertyException;
60 using ::com::sun::star::beans::PropertyVetoException;
67 maPropMapper ( rMapper )
80 maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() );
88 while( xNext->mxNextMapper.is())
89 xNext = xNext->mxNextMapper;
90 xNext->mxNextMapper = rMapper;
99 while( xNext->mxNextMapper.is())
101 xNext = xNext->mxNextMapper;
108 vector< XMLPropertyState >& rProperties,
109 const Reference< XFastAttributeList >& xAttrList,
112 sal_uInt32 nPropType,
114 sal_Int32 nEndIdx )
const
116 Reference< XNameContainer > xAttrContainer;
118 if( -1 == nStartIdx )
125 sal_Int32
nToken = aIter.getToken();
132 if ( !aPrefix.isEmpty() )
135 const OUString sValue = aIter.toString();
138 nPropType, nStartIdx, nEndIdx, xAttrContainer,
139 sAttrName, aNamespaceURI, sValue);
142 const css::uno::Sequence< css::xml::Attribute > unknownAttribs = xAttrList->getUnknownAttributes();
143 for (
const css::xml::Attribute& rAttribute : unknownAttribs)
149 OUString aPrefix = rAttribute.Name.copy(0, nSepIndex);
156 nPropType, nStartIdx, nEndIdx, xAttrContainer,
157 rAttribute.Name, rAttribute.NamespaceURL, rAttribute.Value);
160 finished( rProperties, nStartIdx, nEndIdx );
164 vector< XMLPropertyState >& rProperties,
167 const sal_uInt32 nPropType,
168 const sal_Int32 nStartIdx,
169 const sal_Int32 nEndIdx,
170 Reference< XNameContainer >& xAttrContainer,
171 const OUString& rAttrName,
172 const OUString& aNamespaceURI,
173 const OUString& sValue)
const
175 OUString aLocalName, aPrefix, aNamespace;
177 &aLocalName, &aNamespace );
184 sal_Int32
nIndex = nStartIdx - 1;
185 sal_uInt32 nFlags = 0;
190 bool bNoWarning =
false;
195 nIndex =
maPropMapper->GetEntryIndex( nPrefix, aLocalName,
198 if( nIndex > -1 && nIndex < nEndIdx )
206 sal_Int32 nReference = -1;
212 const OUString aAPIName(
maPropMapper->GetEntryAPIName( nIndex ) );
213 const sal_Int32 nSize = rProperties.size();
214 for( nReference = 0; nReference < nSize; nReference++ )
216 sal_Int32 nRefIdx = rProperties[nReference].mnIndex;
217 if( (nRefIdx != -1) && (nIndex != nRefIdx) &&
218 (
maPropMapper->GetEntryAPIName( nRefIdx ) == aAPIName ))
220 aNewProperty = rProperties[nReference];
226 if( nReference == nSize )
239 sal_uInt32 nOldSize = rProperties.size();
242 sValue, rUnitConverter,
246 bNoWarning |= ( nOldSize != rProperties.size() );
256 if( nReference == -1 )
257 rProperties.push_back( aNewProperty );
259 rProperties[nReference] = aNewProperty;
287 "unknown attribute: \"" << rAttrName <<
"\"");
290 if( !xAttrContainer.is() )
294 xAttrContainer = xNew;
319 if( nIndex != -1 && nIndex >= nStartIdx && nIndex < nEndIdx)
324 rProperties.push_back( aNewProperty );
328 if( xAttrContainer.is() )
332 aData.Value = sValue;
337 aData.Namespace = aNamespaceURI;
341 xAttrContainer->insertByName( sName,
Any(aData) );
352 vector< XMLPropertyState >& rProperties,
357 OSL_ENSURE(
mxNextMapper.is(),
"unsupported special item in xml import" );
359 return mxNextMapper->handleSpecialItem( rProperty, rProperties, rValue,
360 rUnitConverter, rNamespaceMap );
366 const ::std::vector< XMLPropertyState >& rProperties,
367 css::uno::Sequence< css::beans::PropertyValue >& rValues )
370 sal_Int32
nCount = rProperties.size();
371 sal_Int32 nValueCount = 0;
372 rValues.realloc( nCount );
373 PropertyValue *pProps = rValues.getArray();
374 for( sal_Int32
i=0;
i < nCount;
i++ )
377 sal_Int32 nIdx = rProp.
mnIndex;
381 if( !pProps->Name.isEmpty() )
388 if( nValueCount < nCount )
389 rValues.realloc( nValueCount );
393 const ::std::vector< XMLPropertyState >& aProperties,
394 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
397 OSL_ENSURE( rPropSet.is(),
"need an XPropertySet" );
398 sal_Int32
nCount = aProperties.size();
400 for( sal_Int32
i=0;
i < nCount;
i++ )
403 sal_Int32 nIdx = rProp.
mnIndex;
409 const sal_Int32 nPropFlags =
maPropMapper->GetEntryFlags( nIdx );
412 if( ( pSpecialContextIds !=
nullptr ) &&
417 sal_Int16 nContextId =
maPropMapper->GetEntryContextId(nIdx);
419 for ( sal_Int32
n = 0;
424 if ( pSpecialContextIds[
n].nContextID == nContextId )
436 const vector< XMLPropertyState >& aProperties,
442 Reference< XTolerantMultiPropertySet > xTolPropSet( rPropSet, UNO_QUERY );
443 if (xTolPropSet.is())
445 pSpecialContextIds );
450 Reference< XPropertySetInfo > xInfo(rPropSet->getPropertySetInfo());
453 Reference<XMultiPropertySet> xMultiPropSet( rPropSet, UNO_QUERY );
454 if ( xMultiPropSet.is() )
459 pSpecialContextIds );
468 pSpecialContextIds );
475 const vector<XMLPropertyState> & rProperties,
477 const Reference<XPropertySetInfo> & rPropSetInfo,
482 OSL_ENSURE( rPropSet.is(),
"need an XPropertySet" );
483 OSL_ENSURE( rPropSetInfo.is(),
"need an XPropertySetInfo" );
487 sal_Int32
nCount = rProperties.size();
490 for( sal_Int32
i=0;
i < nCount;
i++ )
493 sal_Int32 nIdx = rProp.
mnIndex;
499 const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
500 const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
504 rPropSetInfo->hasPropertyByName( rPropName ) ) )
509 rPropSet->setPropertyValue( rPropName, rProp.
maValue );
512 catch (
const IllegalArgumentException& e )
521 aSeq, e.Message,
nullptr );
524 catch (
const UnknownPropertyException& e )
530 aSeq, e.Message,
nullptr );
532 catch (
const PropertyVetoException& e )
538 aSeq, e.Message,
nullptr );
540 catch (
const WrappedTargetException& e )
546 aSeq, e.Message,
nullptr );
551 if( ( pSpecialContextIds !=
nullptr ) &&
556 sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
558 for ( sal_Int32
n = 0;
563 if ( pSpecialContextIds[
n].nContextID == nContextId )
581 struct PropertyPairLessFunctor
585 return (*a.first < *b.first);
592 const vector<XMLPropertyState> & rProperties,
593 const Reference<XPropertySetInfo> & rPropSetInfo,
597 Sequence<Any>& rValues)
599 sal_Int32
nCount = rProperties.size();
603 aPropertyPairs.reserve( nCount );
607 for( i = 0; i < nCount; i++ )
610 sal_Int32 nIdx = rProp.
mnIndex;
616 const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
617 const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
621 !rPropSetInfo.is() ||
622 rPropSetInfo->hasPropertyByName(rPropName) ) )
625 aPropertyPairs.emplace_back( &rPropName, &rProp.
maValue );
629 if( ( pSpecialContextIds !=
nullptr ) &&
634 sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
635 for ( sal_Int32
n = 0;
640 if ( pSpecialContextIds[
n].nContextID == nContextId )
642 pSpecialContextIds[
n].
nIndex = i;
653 sort( aPropertyPairs.begin(), aPropertyPairs.end(),
654 PropertyPairLessFunctor());
657 rNames.realloc( aPropertyPairs.size() );
658 OUString* pNamesArray = rNames.getArray();
659 rValues.realloc( aPropertyPairs.size() );
660 Any* pValuesArray = rValues.getArray();
664 for(
const auto& rPropertyPair : aPropertyPairs )
666 pNamesArray[i] = *(rPropertyPair.first);
667 pValuesArray[i++] = *(rPropertyPair.second);
672 const vector<XMLPropertyState> & rProperties,
673 const Reference<XMultiPropertySet> & rMultiPropSet,
674 const Reference<XPropertySetInfo> & rPropSetInfo,
678 OSL_ENSURE( rMultiPropSet.is(),
"Need multi property set. ");
679 OSL_ENSURE( rPropSetInfo.is(),
"Need property set info." );
681 bool bSuccessful =
false;
684 Sequence<Any> aValues;
692 rMultiPropSet->setPropertyValues( aNames, aValues );
697 OSL_ENSURE(bSuccessful,
"Exception caught; style may not be imported correctly.");
704 const vector<XMLPropertyState> & rProperties,
705 const Reference<XTolerantMultiPropertySet> & rTolMultiPropSet,
710 OSL_ENSURE( rTolMultiPropSet.is(),
"Need tolerant multi property set. ");
712 bool bSuccessful =
false;
715 Sequence<Any> aValues;
723 const Sequence< SetPropertyTolerantFailed > aResults(rTolMultiPropSet->setPropertyValuesTolerant( aNames, aValues ));
724 bSuccessful = !aResults.hasElements();
725 for(
const auto& rResult : aResults)
729 switch (rResult.Result)
731 case TolerantPropertySetResultType::UNKNOWN_PROPERTY :
732 sMessage =
"UNKNOWN_PROPERTY";
734 case TolerantPropertySetResultType::ILLEGAL_ARGUMENT :
735 sMessage =
"ILLEGAL_ARGUMENT";
737 case TolerantPropertySetResultType::PROPERTY_VETO :
738 sMessage =
"PROPERTY_VETO";
740 case TolerantPropertySetResultType::WRAPPED_TARGET :
741 sMessage =
"WRAPPED_TARGET";
746 aSeq, sMessage,
nullptr );
751 OSL_ENSURE(bSuccessful,
"Exception caught; style may not be imported correctly.");
758 vector< XMLPropertyState >& rProperties,
759 sal_Int32 nStartIndex, sal_Int32 nEndIndex )
const
763 mxNextMapper->finished( rProperties, nStartIndex, nEndIndex );
void CheckSpecialContext(const ::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::beans::XPropertySet > &rPropSet, ContextID_Index_Pair *pSpecialContextIds) const
sal_uInt16 GetKeyByPrefix(const OUString &rPrefix) const
vector< PropertyPair > PropertyPairs
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
SvXMLImportPropertyMapper(SvXMLImportPropertyMapper const &)=delete
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
#define MID_FLAG_NO_PROPERTY_IMPORT
#define SAL_INFO_IF(condition, area, stream)
#define XMLERROR_STYLE_ATTR_VALUE
bool FillPropertySet(const ::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::beans::XPropertySet > &rPropSet, ContextID_Index_Pair *pSpecialContextIds=nullptr) const
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
css::uno::Any const & rValue
const sal_uInt16 XML_NAMESPACE_XMLNS
static OUString getNamespaceURIFromToken(sal_Int32 nToken)
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.
#define XMLERROR_STYLE_PROP_UNKNOWN
#define XML_TYPE_PROP_PARAGRAPH
static constexpr OUStringLiteral aNamespaceSeparator
#define XMLERROR_STYLE_PROP_OTHER
#define MID_FLAG_MULTI_PROPERTY
void FillPropertySequence(const ::std::vector< XMLPropertyState > &aProperties, css::uno::Sequence< css::beans::PropertyValue > &rValues) const
#define XMLERROR_FLAG_WARNING
constexpr OUStringLiteral aData
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 ...
#define XMLERROR_STYLE_PROP_VALUE
uno::Reference< uno::XInterface > SvUnoAttributeContainer_CreateInstance()
constexpr sal_uInt16 XML_NAMESPACE_TEXT
virtual void finished(::std::vector< XMLPropertyState > &rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex) const
This method is called when all attributes have benn processed.
const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG
#define MID_FLAG_NO_PROPERTY
static OUString getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap *pMap)
rtl::Reference< XMLPropertySetMapper > maPropMapper
#define XML_TYPE_PROP_TEXT
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.
const sal_uInt16 XML_NAMESPACE_NONE
#define XML_TYPE_PROP_CHART
#define MID_FLAG_MERGE_PROPERTY
static const OUString & getNameFromToken(sal_Int32 nToken)
#define MID_FLAG_PROPERTY_MAY_THROW
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Handling of tokens in XML:
#define MID_FLAG_ELEMENT_ITEM_IMPORT
virtual ~SvXMLImportPropertyMapper() override
#define XMLERROR_FLAG_ERROR
Smart struct to transport an Any with an index to the appropriate property-name.
void SetError(sal_Int32 nId, const css::uno::Sequence< OUString > &rMsgParams, const OUString &rExceptionMessage, const css::uno::Reference< css::xml::sax::XLocator > &rLocator)
Record an error condition that occurred during import.
Sequence< sal_Int8 > aSeq
This struct is used as an optional parameter to the static _FillPropertySet() methods.
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.
#define MID_FLAG_MUST_EXIST
void ChainImportMapper(const rtl::Reference< SvXMLImportPropertyMapper > &rMapper)
rtl::Reference< SvXMLImportPropertyMapper > mxNextMapper
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)
#define MID_FLAG_SPECIAL_ITEM_IMPORT
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...
pair< const OUString *, const Any * > PropertyPair