LibreOffice Module xmloff (master) 1
xmlimppr.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
30#include <sal/log.hxx>
31#include <osl/diagnose.h>
32#include <utility>
33#include <xmloff/xmlprmap.hxx>
35#include <xmloff/xmlimppr.hxx>
36#include <xmloff/xmlimp.hxx>
37
38#include <xmloff/unoatrcn.hxx>
40#include <xmloff/xmltoken.hxx>
41#include <xmloff/xmlerror.hxx>
42#include <xmloff/contextid.hxx>
43#include <xmloff/xmltypes.hxx>
44#include <xmloff/maptype.hxx>
45
46#include <algorithm>
47#include <vector>
48
49using namespace ::com::sun::star::uno;
50using namespace ::com::sun::star::beans;
51using namespace ::com::sun::star::container;
52using namespace ::com::sun::star::xml;
53using namespace ::com::sun::star::xml::sax;
54
55using namespace ::xmloff::token;
56using ::com::sun::star::lang::IllegalArgumentException;
57using ::com::sun::star::lang::WrappedTargetException;
58using ::com::sun::star::beans::UnknownPropertyException;
59using ::com::sun::star::beans::PropertyVetoException;
60
61
64 SvXMLImport& rImp ):
65 m_rImport(rImp),
66 maPropMapper (std::move( xMapper ))
67{
68}
69
71{
72 mxNextMapper = nullptr;
73}
74
77{
78 // add map entries from rMapper to current map
79 maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() );
80 // rMapper uses the same map as 'this'
81 rMapper->maPropMapper = maPropMapper;
82
83 // set rMapper as last mapper in current chain
85 if( xNext.is())
86 {
87 while( xNext->mxNextMapper.is())
88 xNext = xNext->mxNextMapper;
89 xNext->mxNextMapper = rMapper;
90 }
91 else
92 mxNextMapper = rMapper;
93
94 // if rMapper was already chained, correct
95 // map pointer of successors
96 xNext = rMapper;
97
98 while( xNext->mxNextMapper.is())
99 {
100 xNext = xNext->mxNextMapper;
101 xNext->maPropMapper = maPropMapper;
102 }
103}
104
107 std::vector< XMLPropertyState >& rProperties,
108 const Reference< XFastAttributeList >& xAttrList,
109 const SvXMLUnitConverter& rUnitConverter,
110 const SvXMLNamespaceMap& rNamespaceMap,
111 sal_uInt32 nPropType,
112 sal_Int32 nStartIdx,
113 sal_Int32 nEndIdx ) const
114{
115 Reference< XNameContainer > xAttrContainer;
116
117 if( -1 == nStartIdx )
118 nStartIdx = 0;
119 if( -1 == nEndIdx )
120 nEndIdx = maPropMapper->GetEntryCount();
121
122 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
123 {
124 sal_Int32 nToken = aIter.getToken();
126 continue;
127
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;
133
134 const OUString sValue = aIter.toString();
135
136 importXMLAttribute(rProperties, rUnitConverter, rNamespaceMap,
137 nPropType, nStartIdx, nEndIdx, xAttrContainer,
138 sAttrName, aNamespaceURI, sValue);
139 }
140
141 const css::uno::Sequence< css::xml::Attribute > unknownAttribs = xAttrList->getUnknownAttributes();
142 for (const css::xml::Attribute& rAttribute : unknownAttribs)
143 {
144 int nSepIndex = rAttribute.Name.indexOf(SvXMLImport::aNamespaceSeparator);
145 if (nSepIndex != -1)
146 {
147 // If it's an unknown attribute in a known namespace, ignore it.
148 OUString aPrefix = rAttribute.Name.copy(0, nSepIndex);
149 auto nKey = rNamespaceMap.GetKeyByPrefix(aPrefix);
150 if (nKey != USHRT_MAX && !(nKey & XML_NAMESPACE_UNKNOWN_FLAG))
151 continue;
152 }
153
154 importXMLAttribute(rProperties, rUnitConverter, rNamespaceMap,
155 nPropType, nStartIdx, nEndIdx, xAttrContainer,
156 rAttribute.Name, rAttribute.NamespaceURL, rAttribute.Value);
157 }
158
159 finished( rProperties, nStartIdx, nEndIdx );
160}
161
163 std::vector< XMLPropertyState >& rProperties,
164 const SvXMLUnitConverter& rUnitConverter,
165 const SvXMLNamespaceMap& rNamespaceMap,
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
173{
174 OUString aLocalName, aPrefix, aNamespace;
175 sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix,
176 &aLocalName, &aNamespace );
177
178 // index of actual property map entry
179 // This looks very strange, but it works well:
180 // If the start index is 0, the new value will become -1, and
181 // GetEntryIndex will start searching with position 0.
182 // Otherwise GetEntryIndex will start with the next position specified.
183 sal_Int32 nIndex = nStartIdx - 1;
184 sal_uInt32 nFlags = 0; // flags of actual property map entry
185 bool bFound = false;
186
187 // for better error reporting: this should be set true if no
188 // warning is needed
189 bool bNoWarning = false;
190
191 do
192 {
193 // find an entry for this attribute
194 nIndex = maPropMapper->GetEntryIndex( nPrefix, aLocalName,
195 nPropType, nIndex );
196
197 if( nIndex > -1 && nIndex < nEndIdx )
198 {
199 // create a XMLPropertyState with an empty value
200
201 nFlags = maPropMapper->GetEntryFlags( nIndex );
202 if( ( nFlags & MID_FLAG_ELEMENT_ITEM_IMPORT ) == 0 )
203 {
204 XMLPropertyState aNewProperty( nIndex );
205 sal_Int32 nReference = -1;
206
207 // if this is a multi attribute check if another attribute already set
208 // this any. If so use this as an initial value
209 if( ( nFlags & MID_FLAG_MERGE_PROPERTY ) != 0 )
210 {
211 const OUString aAPIName( maPropMapper->GetEntryAPIName( nIndex ) );
212 const sal_Int32 nSize = rProperties.size();
213 for( nReference = 0; nReference < nSize; nReference++ )
214 {
215 sal_Int32 nRefIdx = rProperties[nReference].mnIndex;
216 if( (nRefIdx != -1) && (nIndex != nRefIdx) &&
217 (maPropMapper->GetEntryAPIName( nRefIdx ) == aAPIName ))
218 {
219 aNewProperty = rProperties[nReference];
220 aNewProperty.mnIndex = nIndex;
221 break;
222 }
223 }
224
225 if( nReference == nSize )
226 nReference = -1;
227 }
228
229 bool bSet = false;
230 if( ( nFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) == 0 )
231 {
232 // let the XMLPropertySetMapper decide how to import the value
233 bSet = maPropMapper->importXML( sValue, aNewProperty,
234 rUnitConverter );
235 }
236 else
237 {
238 sal_uInt32 nOldSize = rProperties.size();
239
240 bSet = handleSpecialItem( aNewProperty, rProperties,
241 sValue, rUnitConverter,
242 rNamespaceMap );
243
244 // no warning if handleSpecialItem added properties
245 bNoWarning |= ( nOldSize != rProperties.size() );
246 }
247
248 // no warning if we found could set the item. This
249 // 'remembers' bSet across multi properties.
250 bNoWarning |= bSet;
251
252 // store the property in the given vector
253 if( bSet )
254 {
255 if( nReference == -1 )
256 rProperties.push_back( aNewProperty );
257 else
258 rProperties[nReference] = aNewProperty;
259 }
260 else
261 {
262 // warn about unknown value. Unless it's a
263 // multi property: Then we get another chance
264 // to set the value.
265 if( !bNoWarning &&
266 ((nFlags & MID_FLAG_MULTI_PROPERTY) == 0) )
267 {
270 { rAttrName, sValue } );
271 }
272 }
273 }
274 bFound = true;
275 continue;
276 }
277
278 if( !bFound )
279 {
280 SAL_INFO_IF((XML_NAMESPACE_NONE != nPrefix) &&
281 !(XML_NAMESPACE_UNKNOWN_FLAG & nPrefix),
282 "xmloff.style",
283 "unknown attribute: \"" << rAttrName << "\"");
284 if( (XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) || (XML_NAMESPACE_NONE == nPrefix) )
285 {
286 if( !xAttrContainer.is() )
287 {
288 // add an unknown attribute container to the properties
289 Reference< XNameContainer > xNew( SvUnoAttributeContainer_CreateInstance(), UNO_QUERY );
290 xAttrContainer = xNew;
291
292 // find map entry and create new property state
293 if( -1 == nIndex )
294 {
295 switch( nPropType )
296 {
298 nIndex = maPropMapper->FindEntryIndex( "ChartUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
299 break;
301 nIndex = maPropMapper->FindEntryIndex( "ParaUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
302 break;
304 nIndex = maPropMapper->FindEntryIndex( "TextUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
305 break;
306 default:
307 break;
308 }
309 // other property type or property not found
310 if( -1 == nIndex )
311 nIndex = maPropMapper->FindEntryIndex( "UserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
312 }
313
314 // #106963#; use userdefined attribute only if it is in the specified property range
315 if( nIndex != -1 && nIndex >= nStartIdx && nIndex < nEndIdx)
316 {
317 XMLPropertyState aNewProperty( nIndex, Any(xAttrContainer) );
318
319 // push it on our stack so we export it later
320 rProperties.push_back( aNewProperty );
321 }
322 }
323
324 if( xAttrContainer.is() )
325 {
326 AttributeData aData;
327 aData.Type = GetXMLToken( XML_CDATA );
328 aData.Value = sValue;
329 OUString sName;
330 if( XML_NAMESPACE_NONE != nPrefix )
331 {
332 sName = rAttrName;
333 aData.Namespace = aNamespaceURI;
334 }
335 else
336 sName = aLocalName;
337 xAttrContainer->insertByName( sName, Any(aData) );
338 }
339 }
340 }
341 }
342 while( ( nIndex >= 0 && nIndex + 1 < nEndIdx ) && (( nFlags & MID_FLAG_MULTI_PROPERTY ) != 0 ) );
343}
344
347 XMLPropertyState& rProperty,
348 std::vector< XMLPropertyState >& rProperties,
349 const OUString& rValue,
350 const SvXMLUnitConverter& rUnitConverter,
351 const SvXMLNamespaceMap& rNamespaceMap ) const
352{
353 OSL_ENSURE( mxNextMapper.is(), "unsupported special item in xml import" );
354 if( mxNextMapper.is() )
355 return mxNextMapper->handleSpecialItem( rProperty, rProperties, rValue,
356 rUnitConverter, rNamespaceMap );
357 else
358 return false;
359}
360
362 const ::std::vector< XMLPropertyState >& rProperties,
363 css::uno::Sequence< css::beans::PropertyValue >& rValues )
364 const
365{
366 sal_Int32 nCount = rProperties.size();
367 sal_Int32 nValueCount = 0;
368 rValues.realloc( nCount );
369 PropertyValue *pProps = rValues.getArray();
370 for( sal_Int32 i=0; i < nCount; i++ )
371 {
372 const XMLPropertyState& rProp = rProperties[i];
373 sal_Int32 nIdx = rProp.mnIndex;
374 if( nIdx == -1 )
375 continue;
376 pProps->Name = maPropMapper->GetEntryAPIName( nIdx );
377 if( !pProps->Name.isEmpty() )
378 {
379 pProps->Value = rProp.maValue;
380 ++pProps;
381 ++nValueCount;
382 }
383 }
384 if( nValueCount < nCount )
385 rValues.realloc( nValueCount );
386}
387
389 const ::std::vector< XMLPropertyState >& aProperties,
390 const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
391 ContextID_Index_Pair* pSpecialContextIds ) const
392{
393 OSL_ENSURE( rPropSet.is(), "need an XPropertySet" );
394 sal_Int32 nCount = aProperties.size();
395
396 for( sal_Int32 i=0; i < nCount; i++ )
397 {
398 const XMLPropertyState& rProp = aProperties[i];
399 sal_Int32 nIdx = rProp.mnIndex;
400
401 // disregard property state if it has an invalid index
402 if( -1 == nIdx )
403 continue;
404
405 const sal_Int32 nPropFlags = maPropMapper->GetEntryFlags( nIdx );
406
407 // handle no-property and special items
408 if( ( pSpecialContextIds != nullptr ) &&
409 ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) ||
410 ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) ) ) )
411 {
412 // maybe it's one of our special context ids?
413 sal_Int16 nContextId = maPropMapper->GetEntryContextId(nIdx);
414
415 for ( sal_Int32 n = 0;
416 pSpecialContextIds[n].nContextID != -1;
417 n++ )
418 {
419 // found: set index in pSpecialContextIds array
420 if ( pSpecialContextIds[n].nContextID == nContextId )
421 {
422 pSpecialContextIds[n].nIndex = i;
423 break; // early out
424 }
425 }
426 }
427 }
428
429}
430
432 const std::vector< XMLPropertyState >& aProperties,
433 const Reference< XPropertySet >& rPropSet,
434 ContextID_Index_Pair* pSpecialContextIds ) const
435{
436 bool bSet = false;
437
438 Reference< XTolerantMultiPropertySet > xTolPropSet( rPropSet, UNO_QUERY );
439 if (xTolPropSet.is())
441 pSpecialContextIds );
442
443 if (!bSet)
444 {
445 // get property set info
446 Reference< XPropertySetInfo > xInfo(rPropSet->getPropertySetInfo());
447
448 // check for multi-property set
449 Reference<XMultiPropertySet> xMultiPropSet( rPropSet, UNO_QUERY );
450 if ( xMultiPropSet.is() )
451 {
452 // Try XMultiPropertySet. If that fails, try the regular route.
453 bSet = FillMultiPropertySet_( aProperties, xMultiPropSet,
454 xInfo, maPropMapper,
455 pSpecialContextIds );
456 if ( !bSet )
457 bSet = FillPropertySet_( aProperties, rPropSet,
458 xInfo, maPropMapper, m_rImport,
459 pSpecialContextIds);
460 }
461 else
462 bSet = FillPropertySet_( aProperties, rPropSet, xInfo,
464 pSpecialContextIds );
465 }
466
467 return bSet;
468}
469
471 const std::vector<XMLPropertyState> & rProperties,
472 const Reference<XPropertySet> & rPropSet,
473 const Reference<XPropertySetInfo> & rPropSetInfo,
474 const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
475 SvXMLImport& rImport,
476 ContextID_Index_Pair* pSpecialContextIds )
477{
478 OSL_ENSURE( rPropSet.is(), "need an XPropertySet" );
479 OSL_ENSURE( rPropSetInfo.is(), "need an XPropertySetInfo" );
480
481 // preliminaries
482 bool bSet = false;
483 sal_Int32 nCount = rProperties.size();
484
485 // iterate over property states that we want to set
486 for( sal_Int32 i=0; i < nCount; i++ )
487 {
488 const XMLPropertyState& rProp = rProperties[i];
489 sal_Int32 nIdx = rProp.mnIndex;
490
491 // disregard property state if it has an invalid index
492 if( -1 == nIdx )
493 continue;
494
495 const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
496 const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
497
498 if ( ( 0 == ( nPropFlags & MID_FLAG_NO_PROPERTY ) ) &&
499 ( ( 0 != ( nPropFlags & MID_FLAG_MUST_EXIST ) ) ||
500 rPropSetInfo->hasPropertyByName( rPropName ) ) )
501 {
502 // try setting the property
503 try
504 {
505 rPropSet->setPropertyValue( rPropName, rProp.maValue );
506 bSet = true;
507 }
508 catch ( const IllegalArgumentException& e )
509 {
510 // illegal value: check whether this property is
511 // allowed to throw this exception
512 if ( 0 == ( nPropFlags & MID_FLAG_PROPERTY_MAY_THROW ) )
513 {
514 Sequence<OUString> aSeq { rPropName };
515 rImport.SetError(
517 aSeq, e.Message, nullptr );
518 }
519 }
520 catch ( const UnknownPropertyException& e )
521 {
522 // unknown property: This is always an error!
523 Sequence<OUString> aSeq { rPropName };
524 rImport.SetError(
526 aSeq, e.Message, nullptr );
527 }
528 catch ( const PropertyVetoException& e )
529 {
530 // property veto: this shouldn't happen
531 Sequence<OUString> aSeq { rPropName };
532 rImport.SetError(
534 aSeq, e.Message, nullptr );
535 }
536 catch ( const WrappedTargetException& e )
537 {
538 // wrapped target: this shouldn't happen either
539 Sequence<OUString> aSeq { rPropName };
540 rImport.SetError(
542 aSeq, e.Message, nullptr );
543 }
544 }
545
546 // handle no-property and special items
547 if( ( pSpecialContextIds != nullptr ) &&
548 ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) ||
549 ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) ) ) )
550 {
551 // maybe it's one of our special context ids?
552 sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
553
554 for ( sal_Int32 n = 0;
555 pSpecialContextIds[n].nContextID != -1;
556 n++ )
557 {
558 // found: set index in pSpecialContextIds array
559 if ( pSpecialContextIds[n].nContextID == nContextId )
560 {
561 pSpecialContextIds[n].nIndex = i;
562 break; // early out
563 }
564 }
565 }
566 }
567
568 return bSet;
569}
570
571
572typedef std::pair<const OUString*, const Any* > PropertyPair;
573
574namespace {
575
576struct PropertyPairLessFunctor
577{
578 bool operator()( const PropertyPair& a, const PropertyPair& b ) const
579 {
580 return (*a.first < *b.first);
581 }
582};
583
584}
585
587 const std::vector<XMLPropertyState> & rProperties,
588 const Reference<XPropertySetInfo> & rPropSetInfo,
589 const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
590 ContextID_Index_Pair* pSpecialContextIds,
591 Sequence<OUString>& rNames,
592 Sequence<Any>& rValues)
593{
594 sal_Int32 nCount = rProperties.size();
595
596 // property pairs structure stores names + values of properties to be set.
597 std::vector<PropertyPair> aPropertyPairs;
598 aPropertyPairs.reserve( nCount );
599
600 // iterate over property states that we want to set
601 sal_Int32 i;
602 for( i = 0; i < nCount; i++ )
603 {
604 const XMLPropertyState& rProp = rProperties[i];
605 sal_Int32 nIdx = rProp.mnIndex;
606
607 // disregard property state if it has an invalid index
608 if( -1 == nIdx )
609 continue;
610
611 const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
612 const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
613
614 if ( ( 0 == ( nPropFlags & MID_FLAG_NO_PROPERTY ) ) &&
615 ( ( 0 != ( nPropFlags & MID_FLAG_MUST_EXIST ) ) ||
616 !rPropSetInfo.is() ||
617 rPropSetInfo->hasPropertyByName(rPropName) ) )
618 {
619 // save property into property pair structure
620 aPropertyPairs.emplace_back( &rPropName, &rProp.maValue );
621 }
622
623 // handle no-property and special items
624 if( ( pSpecialContextIds != nullptr ) &&
625 ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) ||
626 ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) ) ) )
627 {
628 // maybe it's one of our special context ids?
629 sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
630 for ( sal_Int32 n = 0;
631 pSpecialContextIds[n].nContextID != -1;
632 n++ )
633 {
634 // found: set index in pSpecialContextIds array
635 if ( pSpecialContextIds[n].nContextID == nContextId )
636 {
637 pSpecialContextIds[n].nIndex = i;
638 break; // early out
639 }
640 }
641 }
642 }
643
644 // We now need to construct the sequences and actually the set
645 // values.
646
647 // sort the property pairs
648 sort( aPropertyPairs.begin(), aPropertyPairs.end(),
649 PropertyPairLessFunctor());
650
651 // create sequences
652 rNames.realloc( aPropertyPairs.size() );
653 OUString* pNamesArray = rNames.getArray();
654 rValues.realloc( aPropertyPairs.size() );
655 Any* pValuesArray = rValues.getArray();
656
657 // copy values into sequences
658 i = 0;
659 for( const auto& rPropertyPair : aPropertyPairs )
660 {
661 pNamesArray[i] = *(rPropertyPair.first);
662 pValuesArray[i++] = *(rPropertyPair.second);
663 }
664}
665
667 const std::vector<XMLPropertyState> & rProperties,
668 const Reference<XMultiPropertySet> & rMultiPropSet,
669 const Reference<XPropertySetInfo> & rPropSetInfo,
670 const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
671 ContextID_Index_Pair* pSpecialContextIds )
672{
673 OSL_ENSURE( rMultiPropSet.is(), "Need multi property set. ");
674 OSL_ENSURE( rPropSetInfo.is(), "Need property set info." );
675
676 bool bSuccessful = false;
677
678 Sequence<OUString> aNames;
679 Sequence<Any> aValues;
680
681 PrepareForMultiPropertySet_(rProperties, rPropSetInfo, rPropMapper, pSpecialContextIds,
682 aNames, aValues);
683
684 // and, finally, try to set the values
685 try
686 {
687 rMultiPropSet->setPropertyValues( aNames, aValues );
688 bSuccessful = true;
689 }
690 catch ( ... )
691 {
692 OSL_ENSURE(bSuccessful, "Exception caught; style may not be imported correctly.");
693 }
694
695 return bSuccessful;
696}
697
699 const std::vector<XMLPropertyState> & rProperties,
700 const Reference<XTolerantMultiPropertySet> & rTolMultiPropSet,
701 const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
702 SvXMLImport& rImport,
703 ContextID_Index_Pair* pSpecialContextIds )
704{
705 OSL_ENSURE( rTolMultiPropSet.is(), "Need tolerant multi property set. ");
706
707 bool bSuccessful = false;
708
709 Sequence<OUString> aNames;
710 Sequence<Any> aValues;
711
712 PrepareForMultiPropertySet_(rProperties, Reference<XPropertySetInfo>(nullptr), rPropMapper, pSpecialContextIds,
713 aNames, aValues);
714
715 // and, finally, try to set the values
716 try
717 {
718 const Sequence< SetPropertyTolerantFailed > aResults(rTolMultiPropSet->setPropertyValuesTolerant( aNames, aValues ));
719 bSuccessful = !aResults.hasElements();
720 for( const auto& rResult : aResults)
721 {
722 Sequence<OUString> aSeq { rResult.Name };
723 OUString sMessage;
724 switch (rResult.Result)
725 {
726 case TolerantPropertySetResultType::UNKNOWN_PROPERTY :
727 sMessage = "UNKNOWN_PROPERTY";
728 break;
729 case TolerantPropertySetResultType::ILLEGAL_ARGUMENT :
730 sMessage = "ILLEGAL_ARGUMENT";
731 break;
732 case TolerantPropertySetResultType::PROPERTY_VETO :
733 sMessage = "PROPERTY_VETO";
734 break;
735 case TolerantPropertySetResultType::WRAPPED_TARGET :
736 sMessage = "WRAPPED_TARGET";
737 break;
738 }
739 rImport.SetError(
741 aSeq, sMessage, nullptr );
742 }
743 }
744 catch ( ... )
745 {
746 OSL_ENSURE(bSuccessful, "Exception caught; style may not be imported correctly.");
747 }
748
749 return bSuccessful;
750}
751
753 std::vector< XMLPropertyState >& rProperties,
754 sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
755{
756 // nothing to do here
757 if( mxNextMapper.is() )
758 mxNextMapper->finished( rProperties, nStartIndex, nEndIndex );
759}
760
761/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
Definition: xmlimppr.cxx:431
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...
Definition: xmlimppr.cxx:106
SvXMLImport & m_rImport
Definition: xmlimppr.hxx:68
void FillPropertySequence(const ::std::vector< XMLPropertyState > &aProperties, css::uno::Sequence< css::beans::PropertyValue > &rValues) const
Definition: xmlimppr.cxx:361
rtl::Reference< SvXMLImportPropertyMapper > mxNextMapper
Definition: xmlimppr.hxx:66
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
Definition: xmlimppr.cxx:346
void ChainImportMapper(const rtl::Reference< SvXMLImportPropertyMapper > &rMapper)
Definition: xmlimppr.cxx:75
virtual void finished(::std::vector< XMLPropertyState > &rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex) const
This method is called when all attributes have benn processed.
Definition: xmlimppr.cxx:752
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)
Definition: xmlimppr.cxx:586
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.
Definition: xmlimppr.cxx:698
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
Definition: xmlimppr.cxx:162
rtl::Reference< XMLPropertySetMapper > maPropMapper
Definition: xmlimppr.hxx:75
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.
Definition: xmlimppr.cxx:666
void CheckSpecialContext(const ::std::vector< XMLPropertyState > &rProperties, const css::uno::Reference< css::beans::XPropertySet > &rPropSet, ContextID_Index_Pair *pSpecialContextIds) const
Definition: xmlimppr.cxx:388
SvXMLImportPropertyMapper(SvXMLImportPropertyMapper const &)=delete
virtual ~SvXMLImportPropertyMapper() override
Definition: xmlimppr.cxx:70
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.
Definition: xmlimppr.cxx:470
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...
Definition: xmluconv.hxx:83
int nCount
OUString sName
sal_Int32 nIndex
sal_Int64 n
uno_Any a
Sequence< sal_Int8 > aSeq
#define SAL_INFO_IF(condition, area, stream)
constexpr OUStringLiteral aData
int i
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
Definition: xmltoken.cxx:3541
DefTokenId nToken
OUString sMessage
This struct is used as an optional parameter to the static _FillPropertySet() methods.
Definition: xmlimppr.hxx:58
sal_Int16 nContextID
Definition: xmlimppr.hxx:59
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:140
css::uno::Any maValue
Definition: maptype.hxx:142
sal_Int32 mnIndex
Definition: maptype.hxx:141
uno::Reference< uno::XInterface > SvUnoAttributeContainer_CreateInstance()
Definition: unoatrcn.cxx:36
#define XMLERROR_STYLE_PROP_VALUE
Definition: xmlerror.hxx:68
#define XMLERROR_STYLE_PROP_OTHER
Definition: xmlerror.hxx:70
#define XMLERROR_STYLE_PROP_UNKNOWN
Definition: xmlerror.hxx:69
#define XMLERROR_FLAG_ERROR
Definition: xmlerror.hxx:36
#define XMLERROR_STYLE_ATTR_VALUE
Definition: xmlerror.hxx:53
#define XMLERROR_FLAG_WARNING
Definition: xmlerror.hxx:35
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
Definition: xmlimp.hxx:104
std::pair< const OUString *, const Any * > PropertyPair
Definition: xmlimppr.cxx:572
constexpr sal_uInt16 XML_NAMESPACE_TEXT
#define XML_TYPE_PROP_CHART
Definition: xmltypes.hxx:107
#define MID_FLAG_MERGE_PROPERTY
Definition: xmltypes.hxx:61
#define XML_TYPE_PROP_PARAGRAPH
Definition: xmltypes.hxx:99
#define MID_FLAG_NO_PROPERTY_IMPORT
Definition: xmltypes.hxx:76
#define MID_FLAG_SPECIAL_ITEM_IMPORT
Definition: xmltypes.hxx:82
#define MID_FLAG_MULTI_PROPERTY
Definition: xmltypes.hxx:64
#define XML_TYPE_PROP_TEXT
Definition: xmltypes.hxx:98
#define MID_FLAG_NO_PROPERTY
Definition: xmltypes.hxx:78
#define MID_FLAG_ELEMENT_ITEM_IMPORT
Definition: xmltypes.hxx:68
#define MID_FLAG_MUST_EXIST
Definition: xmltypes.hxx:52
#define MID_FLAG_PROPERTY_MAY_THROW
Definition: xmltypes.hxx:44