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