bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / xmlimppr.cxx
blobb85e0c7f7b71d9856c17a576e47d56fc84780700
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
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 <rtl/ustrbuf.hxx>
28 #include <osl/diagnose.h>
29 #include <xmloff/xmlprmap.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include <xmloff/xmlimppr.hxx>
32 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/unoatrcn.hxx>
35 #include <xmloff/xmlnmspe.hxx>
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmlerror.hxx>
38 #include <xmloff/contextid.hxx>
39 #include <xmloff/xmltypes.hxx>
40 #include <xmloff/maptype.hxx>
42 #include <algorithm>
43 #include <functional>
44 #include <utility>
45 #include <vector>
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::container;
50 using namespace ::com::sun::star::xml;
51 using namespace ::com::sun::star::xml::sax;
53 using namespace ::std;
54 using namespace ::xmloff::token;
55 using ::com::sun::star::lang::IllegalArgumentException;
56 using ::com::sun::star::lang::WrappedTargetException;
57 using ::com::sun::star::beans::UnknownPropertyException;
58 using ::com::sun::star::beans::PropertyVetoException;
61 SvXMLImportPropertyMapper::SvXMLImportPropertyMapper(
62 const rtl::Reference< XMLPropertySetMapper >& rMapper,
63 SvXMLImport& rImp ):
64 rImport(rImp),
65 maPropMapper ( rMapper )
69 SvXMLImportPropertyMapper::~SvXMLImportPropertyMapper()
71 mxNextMapper = 0;
74 void SvXMLImportPropertyMapper::ChainImportMapper(
75 const rtl::Reference< SvXMLImportPropertyMapper>& rMapper )
77 // add map entries from rMapper to current map
78 maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() );
79 // rMapper uses the same map as 'this'
80 rMapper->maPropMapper = maPropMapper;
82 // set rMapper as last mapper in current chain
83 rtl::Reference< SvXMLImportPropertyMapper > xNext = mxNextMapper;
84 if( xNext.is())
86 while( xNext->mxNextMapper.is())
87 xNext = xNext->mxNextMapper;
88 xNext->mxNextMapper = rMapper;
90 else
91 mxNextMapper = rMapper;
93 // if rMapper was already chained, correct
94 // map pointer of successors
95 xNext = rMapper;
97 while( xNext->mxNextMapper.is())
99 xNext = xNext->mxNextMapper;
100 xNext->maPropMapper = maPropMapper;
104 /** fills the given itemset with the attributes in the given list */
105 void SvXMLImportPropertyMapper::importXML(
106 vector< XMLPropertyState >& rProperties,
107 Reference< XAttributeList > xAttrList,
108 const SvXMLUnitConverter& rUnitConverter,
109 const SvXMLNamespaceMap& rNamespaceMap,
110 sal_uInt32 nPropType,
111 sal_Int32 nStartIdx,
112 sal_Int32 nEndIdx ) const
114 sal_Int16 nAttr = xAttrList->getLength();
116 Reference< XNameContainer > xAttrContainer;
118 if( -1 == nStartIdx )
119 nStartIdx = 0;
120 if( -1 == nEndIdx )
121 nEndIdx = maPropMapper->GetEntryCount();
122 for( sal_Int16 i=0; i < nAttr; i++ )
124 const OUString& rAttrName = xAttrList->getNameByIndex( i );
125 OUString aLocalName, aPrefix, aNamespace;
126 sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix,
127 &aLocalName, &aNamespace );
129 if( XML_NAMESPACE_XMLNS == nPrefix )
130 continue;
132 const OUString& rValue = xAttrList->getValueByIndex( i );
134 // index of actual property map entry
135 // This looks very strange, but it works well:
136 // If the start index is 0, the new value will become -1, and
137 // GetEntryIndex will start searching with position 0.
138 // Otherwise GetEntryIndex will start with the next position specified.
139 sal_Int32 nIndex = nStartIdx - 1;
140 sal_uInt32 nFlags = 0; // flags of actual property map entry
141 bool bFound = false;
143 // for better error reporting: this should be set true if no
144 // warning is needed
145 bool bNoWarning = false;
146 bool bAlienImport = false;
150 // find an entry for this attribute
151 nIndex = maPropMapper->GetEntryIndex( nPrefix, aLocalName,
152 nPropType, nIndex );
154 if( nIndex > -1 && nIndex < nEndIdx )
156 // create a XMLPropertyState with an empty value
158 nFlags = maPropMapper->GetEntryFlags( nIndex );
159 if( (( nFlags & MID_FLAG_NO_PROPERTY ) == MID_FLAG_NO_PROPERTY) && (maPropMapper->GetEntryContextId( nIndex ) == CTF_ALIEN_ATTRIBUTE_IMPORT) )
161 bAlienImport = true;
162 nIndex = -1;
164 else
166 if( ( nFlags & MID_FLAG_ELEMENT_ITEM_IMPORT ) == 0 )
168 XMLPropertyState aNewProperty( nIndex );
169 sal_Int32 nReference = -1;
171 // if this is a multi attribute check if another attribute already set
172 // this any. If so use this as a initial value
173 if( ( nFlags & MID_FLAG_MERGE_PROPERTY ) != 0 )
175 const OUString aAPIName( maPropMapper->GetEntryAPIName( nIndex ) );
176 const sal_Int32 nSize = rProperties.size();
177 for( nReference = 0; nReference < nSize; nReference++ )
179 sal_Int32 nRefIdx = rProperties[nReference].mnIndex;
180 if( (nRefIdx != -1) && (nIndex != nRefIdx) &&
181 (maPropMapper->GetEntryAPIName( nRefIdx ) == aAPIName ))
183 aNewProperty = rProperties[nReference];
184 aNewProperty.mnIndex = nIndex;
185 break;
189 if( nReference == nSize )
190 nReference = -1;
193 bool bSet = false;
194 if( ( nFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) == 0 )
196 // let the XMLPropertySetMapper decide how to import the value
197 bSet = maPropMapper->importXML( rValue, aNewProperty,
198 rUnitConverter );
200 else
202 sal_uInt32 nOldSize = rProperties.size();
204 bSet = handleSpecialItem( aNewProperty, rProperties,
205 rValue, rUnitConverter,
206 rNamespaceMap );
208 // no warning if handleSpecialItem added properties
209 bNoWarning |= ( nOldSize != rProperties.size() );
212 // no warning if we found could set the item. This
213 // 'remembers' bSet across multi properties.
214 bNoWarning |= bSet;
216 // store the property in the given vector
217 if( bSet )
219 if( nReference == -1 )
220 rProperties.push_back( aNewProperty );
221 else
222 rProperties[nReference] = aNewProperty;
224 else
226 // warn about unknown value. Unless it's a
227 // multi property: Then we get another chance
228 // to set the value.
229 if( !bNoWarning &&
230 ((nFlags & MID_FLAG_MULTI_PROPERTY) == 0) )
232 Sequence<OUString> aSeq(2);
233 aSeq[0] = rAttrName;
234 aSeq[1] = rValue;
235 rImport.SetError( XMLERROR_FLAG_WARNING |
236 XMLERROR_STYLE_ATTR_VALUE,
237 aSeq );
241 bFound = true;
242 continue;
246 if( !bFound )
248 SAL_INFO_IF((XML_NAMESPACE_NONE != nPrefix) &&
249 !(XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) &&
250 !bAlienImport, "xmloff.style",
251 "unknown attribute: \"" << rAttrName << "\"");
252 if( (XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) || (XML_NAMESPACE_NONE == nPrefix) || bAlienImport )
254 if( !xAttrContainer.is() )
256 // add an unknown attribute container to the properties
257 Reference< XNameContainer > xNew( SvUnoAttributeContainer_CreateInstance(), UNO_QUERY );
258 xAttrContainer = xNew;
260 // find map entry and create new property state
261 if( -1 == nIndex )
263 switch( nPropType )
265 case XML_TYPE_PROP_CHART:
266 nIndex = maPropMapper->FindEntryIndex( "ChartUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
267 break;
268 case XML_TYPE_PROP_PARAGRAPH:
269 nIndex = maPropMapper->FindEntryIndex( "ParaUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
270 break;
271 case XML_TYPE_PROP_TEXT:
272 nIndex = maPropMapper->FindEntryIndex( "TextUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
273 break;
274 default:
275 break;
277 // other property type or property not found
278 if( -1 == nIndex )
279 nIndex = maPropMapper->FindEntryIndex( "UserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
282 // #106963#; use userdefined attribute only if it is in the specified property range
283 if( nIndex != -1 && nIndex >= nStartIdx && nIndex < nEndIdx)
285 Any aAny;
286 aAny <<= xAttrContainer;
287 XMLPropertyState aNewProperty( nIndex, aAny );
289 // push it on our stack so we export it later
290 rProperties.push_back( aNewProperty );
294 if( xAttrContainer.is() )
296 AttributeData aData;
297 aData.Type = GetXMLToken( XML_CDATA );
298 aData.Value = rValue;
300 OUStringBuffer sName;
301 if( XML_NAMESPACE_NONE != nPrefix )
303 sName.append( aPrefix );
304 sName.append( ':' );
305 aData.Namespace = aNamespace;
308 sName.append( aLocalName );
310 Any aAny;
311 aAny <<= aData;
312 xAttrContainer->insertByName( sName.makeStringAndClear(), aAny );
317 while( ( nIndex >= 0 && nIndex + 1 < nEndIdx ) && (( nFlags & MID_FLAG_MULTI_PROPERTY ) != 0 ) );
320 finished( rProperties, nStartIdx, nEndIdx );
323 /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */
324 bool SvXMLImportPropertyMapper::handleSpecialItem(
325 XMLPropertyState& rProperty,
326 vector< XMLPropertyState >& rProperties,
327 const OUString& rValue,
328 const SvXMLUnitConverter& rUnitConverter,
329 const SvXMLNamespaceMap& rNamespaceMap ) const
331 OSL_ENSURE( mxNextMapper.is(), "unsupported special item in xml import" );
332 if( mxNextMapper.is() )
333 return mxNextMapper->handleSpecialItem( rProperty, rProperties, rValue,
334 rUnitConverter, rNamespaceMap );
335 else
336 return false;
339 void SvXMLImportPropertyMapper::FillPropertySequence(
340 const ::std::vector< XMLPropertyState >& rProperties,
341 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rValues )
342 const
344 sal_Int32 nCount = rProperties.size();
345 sal_Int32 nValueCount = 0;
346 rValues.realloc( nCount );
347 PropertyValue *pProps = rValues.getArray();
348 for( sal_Int32 i=0; i < nCount; i++ )
350 const XMLPropertyState& rProp = rProperties[i];
351 sal_Int32 nIdx = rProp.mnIndex;
352 if( nIdx == -1 )
353 continue;
354 pProps->Name = maPropMapper->GetEntryAPIName( nIdx );
355 if( !pProps->Name.isEmpty() )
357 pProps->Value <<= rProp.maValue;
358 ++pProps;
359 ++nValueCount;
362 if( nValueCount < nCount )
363 rValues.realloc( nValueCount );
366 void SvXMLImportPropertyMapper::CheckSpecialContext(
367 const ::std::vector< XMLPropertyState >& aProperties,
368 const ::com::sun::star::uno::Reference<
369 ::com::sun::star::beans::XPropertySet >& rPropSet,
370 _ContextID_Index_Pair* pSpecialContextIds ) const
372 OSL_ENSURE( rPropSet.is(), "need an XPropertySet" );
373 sal_Int32 nCount = aProperties.size();
375 Reference< XPropertySetInfo > xInfo(rPropSet->getPropertySetInfo());
377 for( sal_Int32 i=0; i < nCount; i++ )
379 const XMLPropertyState& rProp = aProperties[i];
380 sal_Int32 nIdx = rProp.mnIndex;
382 // disregard property state if it has an invalid index
383 if( -1 == nIdx )
384 continue;
386 const sal_Int32 nPropFlags = maPropMapper->GetEntryFlags( nIdx );
388 // handle no-property and special items
389 if( ( pSpecialContextIds != NULL ) &&
390 ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) ||
391 ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) ) ) )
393 // maybe it's one of our special context ids?
394 sal_Int16 nContextId = maPropMapper->GetEntryContextId(nIdx);
396 for ( sal_Int32 n = 0;
397 pSpecialContextIds[n].nContextID != -1;
398 n++ )
400 // found: set index in pSpecialContextIds array
401 if ( pSpecialContextIds[n].nContextID == nContextId )
403 pSpecialContextIds[n].nIndex = i;
404 break; // early out
412 bool SvXMLImportPropertyMapper::FillPropertySet(
413 const vector< XMLPropertyState >& aProperties,
414 const Reference< XPropertySet >& rPropSet,
415 _ContextID_Index_Pair* pSpecialContextIds ) const
417 bool bSet = false;
419 Reference< XTolerantMultiPropertySet > xTolPropSet( rPropSet, UNO_QUERY );
420 if (xTolPropSet.is())
421 bSet = _FillTolerantMultiPropertySet( aProperties, xTolPropSet, maPropMapper, rImport,
422 pSpecialContextIds );
424 if (!bSet)
426 // get property set info
427 Reference< XPropertySetInfo > xInfo(rPropSet->getPropertySetInfo());
429 // check for multi-property set
430 Reference<XMultiPropertySet> xMultiPropSet( rPropSet, UNO_QUERY );
431 if ( xMultiPropSet.is() )
433 // Try XMultiPropertySet. If that fails, try the regular route.
434 bSet = _FillMultiPropertySet( aProperties, xMultiPropSet,
435 xInfo, maPropMapper,
436 pSpecialContextIds );
437 if ( !bSet )
438 bSet = _FillPropertySet( aProperties, rPropSet,
439 xInfo, maPropMapper, rImport,
440 pSpecialContextIds);
442 else
443 bSet = _FillPropertySet( aProperties, rPropSet, xInfo,
444 maPropMapper, rImport,
445 pSpecialContextIds );
448 return bSet;
451 bool SvXMLImportPropertyMapper::_FillPropertySet(
452 const vector<XMLPropertyState> & rProperties,
453 const Reference<XPropertySet> & rPropSet,
454 const Reference<XPropertySetInfo> & rPropSetInfo,
455 const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
456 SvXMLImport& rImport,
457 _ContextID_Index_Pair* pSpecialContextIds )
459 OSL_ENSURE( rPropSet.is(), "need an XPropertySet" );
460 OSL_ENSURE( rPropSetInfo.is(), "need an XPropertySetInfo" );
462 // preliminaries
463 bool bSet = false;
464 sal_Int32 nCount = rProperties.size();
466 // iterate over property states that we want to set
467 for( sal_Int32 i=0; i < nCount; i++ )
469 const XMLPropertyState& rProp = rProperties[i];
470 sal_Int32 nIdx = rProp.mnIndex;
472 // disregard property state if it has an invalid index
473 if( -1 == nIdx )
474 continue;
476 const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
477 const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
479 if ( ( 0 == ( nPropFlags & MID_FLAG_NO_PROPERTY ) ) &&
480 ( ( 0 != ( nPropFlags & MID_FLAG_MUST_EXIST ) ) ||
481 rPropSetInfo->hasPropertyByName( rPropName ) ) )
483 // try setting the property
486 rPropSet->setPropertyValue( rPropName, rProp.maValue );
487 bSet = true;
489 catch ( const IllegalArgumentException& e )
491 // illegal value: check whether this property is
492 // allowed to throw this exception
493 if ( 0 == ( nPropFlags & MID_FLAG_PROPERTY_MAY_THROW ) )
495 Sequence<OUString> aSeq(1);
496 aSeq[0] = rPropName;
497 rImport.SetError(
498 XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_ERROR,
499 aSeq, e.Message, NULL );
502 catch ( const UnknownPropertyException& e )
504 // unknown property: This is always an error!
505 Sequence<OUString> aSeq(1);
506 aSeq[0] = rPropName;
507 rImport.SetError(
508 XMLERROR_STYLE_PROP_UNKNOWN | XMLERROR_FLAG_ERROR,
509 aSeq, e.Message, NULL );
511 catch ( const PropertyVetoException& e )
513 // property veto: this shouldn't happen
514 Sequence<OUString> aSeq(1);
515 aSeq[0] = rPropName;
516 rImport.SetError(
517 XMLERROR_STYLE_PROP_OTHER | XMLERROR_FLAG_ERROR,
518 aSeq, e.Message, NULL );
520 catch ( const WrappedTargetException& e )
522 // wrapped target: this shouldn't happen either
523 Sequence<OUString> aSeq(1);
524 aSeq[0] = rPropName;
525 rImport.SetError(
526 XMLERROR_STYLE_PROP_OTHER | XMLERROR_FLAG_ERROR,
527 aSeq, e.Message, NULL );
531 // handle no-property and special items
532 if( ( pSpecialContextIds != NULL ) &&
533 ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) ||
534 ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) ) ) )
536 // maybe it's one of our special context ids?
537 sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
539 for ( sal_Int32 n = 0;
540 pSpecialContextIds[n].nContextID != -1;
541 n++ )
543 // found: set index in pSpecialContextIds array
544 if ( pSpecialContextIds[n].nContextID == nContextId )
546 pSpecialContextIds[n].nIndex = i;
547 break; // early out
553 return bSet;
558 typedef pair<const OUString*, const Any* > PropertyPair;
559 typedef vector<PropertyPair> PropertyPairs;
561 struct PropertyPairLessFunctor :
562 public std::binary_function<PropertyPair, PropertyPair, bool>
564 bool operator()( const PropertyPair& a, const PropertyPair& b ) const
566 return (*a.first < *b.first);
570 void SvXMLImportPropertyMapper::_PrepareForMultiPropertySet(
571 const vector<XMLPropertyState> & rProperties,
572 const Reference<XPropertySetInfo> & rPropSetInfo,
573 const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
574 _ContextID_Index_Pair* pSpecialContextIds,
575 Sequence<OUString>& rNames,
576 Sequence<Any>& rValues)
578 sal_Int32 nCount = rProperties.size();
580 // property pairs structure stores names + values of properties to be set.
581 PropertyPairs aPropertyPairs;
582 aPropertyPairs.reserve( nCount );
584 // iterate over property states that we want to set
585 sal_Int32 i;
586 for( i = 0; i < nCount; i++ )
588 const XMLPropertyState& rProp = rProperties[i];
589 sal_Int32 nIdx = rProp.mnIndex;
591 // disregard property state if it has an invalid index
592 if( -1 == nIdx )
593 continue;
595 const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
596 const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
598 if ( ( 0 == ( nPropFlags & MID_FLAG_NO_PROPERTY ) ) &&
599 ( ( 0 != ( nPropFlags & MID_FLAG_MUST_EXIST ) ) ||
600 !rPropSetInfo.is() ||
601 (rPropSetInfo.is() && rPropSetInfo->hasPropertyByName( rPropName )) ) )
603 // save property into property pair structure
604 aPropertyPairs.push_back( PropertyPair( &rPropName, &rProp.maValue ) );
607 // handle no-property and special items
608 if( ( pSpecialContextIds != NULL ) &&
609 ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) ||
610 ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) ) ) )
612 // maybe it's one of our special context ids?
613 sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
614 for ( sal_Int32 n = 0;
615 pSpecialContextIds[n].nContextID != -1;
616 n++ )
618 // found: set index in pSpecialContextIds array
619 if ( pSpecialContextIds[n].nContextID == nContextId )
621 pSpecialContextIds[n].nIndex = i;
622 break; // early out
628 // We now need to construct the sequences and actually the set
629 // values.
631 // sort the property pairs
632 sort( aPropertyPairs.begin(), aPropertyPairs.end(),
633 PropertyPairLessFunctor());
635 // create sequences
636 rNames.realloc( aPropertyPairs.size() );
637 OUString* pNamesArray = rNames.getArray();
638 rValues.realloc( aPropertyPairs.size() );
639 Any* pValuesArray = rValues.getArray();
641 // copy values into sequences
642 i = 0;
643 for( PropertyPairs::iterator aIter = aPropertyPairs.begin();
644 aIter != aPropertyPairs.end();
645 ++aIter )
647 pNamesArray[i] = *(aIter->first);
648 pValuesArray[i++] = *(aIter->second);
652 bool SvXMLImportPropertyMapper::_FillMultiPropertySet(
653 const vector<XMLPropertyState> & rProperties,
654 const Reference<XMultiPropertySet> & rMultiPropSet,
655 const Reference<XPropertySetInfo> & rPropSetInfo,
656 const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
657 _ContextID_Index_Pair* pSpecialContextIds )
659 OSL_ENSURE( rMultiPropSet.is(), "Need multi property set. ");
660 OSL_ENSURE( rPropSetInfo.is(), "Need property set info." );
662 bool bSuccessful = false;
664 Sequence<OUString> aNames;
665 Sequence<Any> aValues;
667 _PrepareForMultiPropertySet(rProperties, rPropSetInfo, rPropMapper, pSpecialContextIds,
668 aNames, aValues);
670 // and, finally, try to set the values
673 rMultiPropSet->setPropertyValues( aNames, aValues );
674 bSuccessful = true;
676 catch ( ... )
678 OSL_ENSURE(bSuccessful, "Exception caught; style may not be imported correctly.");
681 return bSuccessful;
684 bool SvXMLImportPropertyMapper::_FillTolerantMultiPropertySet(
685 const vector<XMLPropertyState> & rProperties,
686 const Reference<XTolerantMultiPropertySet> & rTolMultiPropSet,
687 const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
688 SvXMLImport& rImport,
689 _ContextID_Index_Pair* pSpecialContextIds )
691 OSL_ENSURE( rTolMultiPropSet.is(), "Need tolerant multi property set. ");
693 bool bSuccessful = false;
695 Sequence<OUString> aNames;
696 Sequence<Any> aValues;
698 _PrepareForMultiPropertySet(rProperties, Reference<XPropertySetInfo>(NULL), rPropMapper, pSpecialContextIds,
699 aNames, aValues);
701 // and, finally, try to set the values
704 Sequence< SetPropertyTolerantFailed > aResults(rTolMultiPropSet->setPropertyValuesTolerant( aNames, aValues ));
705 if (aResults.getLength() == 0)
706 bSuccessful = true;
707 else
709 sal_Int32 nCount(aResults.getLength());
710 for( sal_Int32 i = 0; i < nCount; ++i)
712 Sequence<OUString> aSeq(1);
713 aSeq[0] = aResults[i].Name;
714 OUString sMessage;
715 switch (aResults[i].Result)
717 case TolerantPropertySetResultType::UNKNOWN_PROPERTY :
718 sMessage = "UNKNOWN_PROPERTY";
719 break;
720 case TolerantPropertySetResultType::ILLEGAL_ARGUMENT :
721 sMessage = "ILLEGAL_ARGUMENT";
722 break;
723 case TolerantPropertySetResultType::PROPERTY_VETO :
724 sMessage = "PROPERTY_VETO";
725 break;
726 case TolerantPropertySetResultType::WRAPPED_TARGET :
727 sMessage = "WRAPPED_TARGET";
728 break;
730 rImport.SetError(
731 XMLERROR_STYLE_PROP_OTHER | XMLERROR_FLAG_ERROR,
732 aSeq, sMessage, NULL );
736 catch ( ... )
738 OSL_ENSURE(bSuccessful, "Exception caught; style may not be imported correctly.");
741 return bSuccessful;
744 void SvXMLImportPropertyMapper::finished(
745 vector< XMLPropertyState >& rProperties,
746 sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
748 // nothing to do here
749 if( mxNextMapper.is() )
750 mxNextMapper->finished( rProperties, nStartIndex, nEndIndex );
753 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */