xref: /AOO41X/main/xmloff/source/style/xmlimppr.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/xml/AttributeData.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetException.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/beans/UnknownPropertyException.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyVetoException.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
37*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
38*cdf0e10cSrcweir #include <xmloff/xmlprmap.hxx>
39*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
40*cdf0e10cSrcweir #include <xmloff/xmlimppr.hxx>
41*cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include "xmloff/unoatrcn.hxx"
44*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
45*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
46*cdf0e10cSrcweir #include "xmloff/xmlerror.hxx"
47*cdf0e10cSrcweir #include <tools/debug.hxx>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include "xmloff/contextid.hxx"
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir // STL includes
52*cdf0e10cSrcweir #include <algorithm>
53*cdf0e10cSrcweir #include <functional>
54*cdf0e10cSrcweir #include <utility>
55*cdf0e10cSrcweir #include <vector>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
58*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
59*cdf0e10cSrcweir using namespace ::com::sun::star::container;
60*cdf0e10cSrcweir using namespace ::com::sun::star::xml;
61*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
62*cdf0e10cSrcweir using ::rtl::OUString;
63*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir using namespace ::std;
66*cdf0e10cSrcweir using namespace ::xmloff::token;
67*cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException;
68*cdf0e10cSrcweir using ::com::sun::star::lang::WrappedTargetException;
69*cdf0e10cSrcweir using ::com::sun::star::beans::UnknownPropertyException;
70*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyVetoException;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir SvXMLImportPropertyMapper::SvXMLImportPropertyMapper(
74*cdf0e10cSrcweir         const UniReference< XMLPropertySetMapper >& rMapper,
75*cdf0e10cSrcweir         SvXMLImport& rImp ):
76*cdf0e10cSrcweir     rImport(rImp),
77*cdf0e10cSrcweir 	maPropMapper  ( rMapper )
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir SvXMLImportPropertyMapper::~SvXMLImportPropertyMapper()
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir 	mxNextMapper = 0;
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir void SvXMLImportPropertyMapper::ChainImportMapper(
87*cdf0e10cSrcweir 		const UniReference< SvXMLImportPropertyMapper>& rMapper )
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	// add map entries from rMapper to current map
90*cdf0e10cSrcweir 	maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() );
91*cdf0e10cSrcweir 	// rMapper uses the same map as 'this'
92*cdf0e10cSrcweir 	rMapper->maPropMapper = maPropMapper;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	// set rMapper as last mapper in current chain
95*cdf0e10cSrcweir 	UniReference< SvXMLImportPropertyMapper > xNext = mxNextMapper;
96*cdf0e10cSrcweir 	if( xNext.is())
97*cdf0e10cSrcweir 	{
98*cdf0e10cSrcweir 		while( xNext->mxNextMapper.is())
99*cdf0e10cSrcweir 			xNext = xNext->mxNextMapper;
100*cdf0e10cSrcweir 		xNext->mxNextMapper = rMapper;
101*cdf0e10cSrcweir 	}
102*cdf0e10cSrcweir 	else
103*cdf0e10cSrcweir 		mxNextMapper = rMapper;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	// if rMapper was already chained, correct
106*cdf0e10cSrcweir 	// map pointer of successors
107*cdf0e10cSrcweir 	xNext = rMapper;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 	while( xNext->mxNextMapper.is())
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		xNext = xNext->mxNextMapper;
112*cdf0e10cSrcweir 		xNext->maPropMapper = maPropMapper;
113*cdf0e10cSrcweir 	}
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir void SvXMLImportPropertyMapper::importXML(
117*cdf0e10cSrcweir 		vector< XMLPropertyState >& rProperties,
118*cdf0e10cSrcweir 	   	Reference< XAttributeList > xAttrList,
119*cdf0e10cSrcweir 	   	const SvXMLUnitConverter& rUnitConverter,
120*cdf0e10cSrcweir 	    const SvXMLNamespaceMap& rNamespaceMap,
121*cdf0e10cSrcweir 	    sal_uInt32 nPropType ) const
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	importXML( rProperties, xAttrList, rUnitConverter, rNamespaceMap,
124*cdf0e10cSrcweir 			   nPropType,-1, -1 );
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir /** fills the given itemset with the attributes in the given list */
128*cdf0e10cSrcweir void SvXMLImportPropertyMapper::importXML(
129*cdf0e10cSrcweir 		vector< XMLPropertyState >& rProperties,
130*cdf0e10cSrcweir 	   	Reference< XAttributeList > xAttrList,
131*cdf0e10cSrcweir 	   	const SvXMLUnitConverter& rUnitConverter,
132*cdf0e10cSrcweir 	    const SvXMLNamespaceMap& rNamespaceMap,
133*cdf0e10cSrcweir 		sal_uInt32 nPropType,
134*cdf0e10cSrcweir 		sal_Int32 nStartIdx,
135*cdf0e10cSrcweir 		sal_Int32 nEndIdx ) const
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir 	sal_Int16 nAttr = xAttrList->getLength();
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	Reference< XNameContainer > xAttrContainer;
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	if( -1 == nStartIdx )
142*cdf0e10cSrcweir 		nStartIdx = 0;
143*cdf0e10cSrcweir 	if( -1 == nEndIdx )
144*cdf0e10cSrcweir 		nEndIdx = maPropMapper->GetEntryCount();
145*cdf0e10cSrcweir 	for( sal_Int16 i=0; i < nAttr; i++ )
146*cdf0e10cSrcweir 	{
147*cdf0e10cSrcweir 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
148*cdf0e10cSrcweir 		OUString aLocalName, aPrefix, aNamespace;
149*cdf0e10cSrcweir 		sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix,
150*cdf0e10cSrcweir 													&aLocalName, &aNamespace );
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 		if( XML_NAMESPACE_XMLNS == nPrefix )
153*cdf0e10cSrcweir 			continue;
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 		const OUString& rValue = xAttrList->getValueByIndex( i );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 		// index of actual property map entry
158*cdf0e10cSrcweir 		// This looks very strange, but it works well:
159*cdf0e10cSrcweir 		// If the start index is 0, the new value will become -1, and
160*cdf0e10cSrcweir 		// GetEntryIndex will start searching with position 0.
161*cdf0e10cSrcweir 		// Otherwise GetEntryIndex will start with the next position specified.
162*cdf0e10cSrcweir 		sal_Int32 nIndex =  nStartIdx - 1;
163*cdf0e10cSrcweir 		sal_uInt32 nFlags = 0;	// flags of actual property map entry
164*cdf0e10cSrcweir 		sal_Bool bFound = sal_False;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir         // for better error reporting: this should be set true if no
167*cdf0e10cSrcweir         // warning is needed
168*cdf0e10cSrcweir         sal_Bool bNoWarning = sal_False;
169*cdf0e10cSrcweir 		bool bAlienImport = false;
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 		do
172*cdf0e10cSrcweir 		{
173*cdf0e10cSrcweir 			// find an entry for this attribute
174*cdf0e10cSrcweir 			nIndex = maPropMapper->GetEntryIndex( nPrefix, aLocalName,
175*cdf0e10cSrcweir 												  nPropType, nIndex );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 			if( nIndex > -1 && nIndex < nEndIdx  )
178*cdf0e10cSrcweir 			{
179*cdf0e10cSrcweir 				// create a XMLPropertyState with an empty value
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 				nFlags = maPropMapper->GetEntryFlags( nIndex );
182*cdf0e10cSrcweir 				if( (( nFlags & MID_FLAG_NO_PROPERTY ) == MID_FLAG_NO_PROPERTY) && (maPropMapper->GetEntryContextId( nIndex ) == CTF_ALIEN_ATTRIBUTE_IMPORT) )
183*cdf0e10cSrcweir 				{
184*cdf0e10cSrcweir 					bAlienImport = true;
185*cdf0e10cSrcweir 					nIndex = -1;
186*cdf0e10cSrcweir 				}
187*cdf0e10cSrcweir 				else
188*cdf0e10cSrcweir 				{
189*cdf0e10cSrcweir 					if( ( nFlags & MID_FLAG_ELEMENT_ITEM_IMPORT ) == 0 )
190*cdf0e10cSrcweir 					{
191*cdf0e10cSrcweir 						XMLPropertyState aNewProperty( nIndex );
192*cdf0e10cSrcweir 						sal_Int32 nReference = -1;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 						// if this is a multi attribute check if another attribute already set
195*cdf0e10cSrcweir 						// this any. If so use this as a initial value
196*cdf0e10cSrcweir 						if( ( nFlags & MID_FLAG_MERGE_PROPERTY ) != 0 )
197*cdf0e10cSrcweir 						{
198*cdf0e10cSrcweir 							const OUString aAPIName( maPropMapper->GetEntryAPIName( nIndex ) );
199*cdf0e10cSrcweir 							const sal_Int32 nSize = rProperties.size();
200*cdf0e10cSrcweir 							for( nReference = 0; nReference < nSize; nReference++ )
201*cdf0e10cSrcweir 							{
202*cdf0e10cSrcweir 								sal_Int32 nRefIdx = rProperties[nReference].mnIndex;
203*cdf0e10cSrcweir 								if( (nRefIdx != -1) && (nIndex != nRefIdx) &&
204*cdf0e10cSrcweir 									(maPropMapper->GetEntryAPIName( nRefIdx ) == aAPIName ))
205*cdf0e10cSrcweir 								{
206*cdf0e10cSrcweir 									aNewProperty = rProperties[nReference];
207*cdf0e10cSrcweir 									aNewProperty.mnIndex = nIndex;
208*cdf0e10cSrcweir 									break;
209*cdf0e10cSrcweir 								}
210*cdf0e10cSrcweir 							}
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 							if( nReference == nSize )
213*cdf0e10cSrcweir 								nReference = -1;
214*cdf0e10cSrcweir 						}
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 						sal_Bool bSet = sal_False;
217*cdf0e10cSrcweir 						if( ( nFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) == 0 )
218*cdf0e10cSrcweir 						{
219*cdf0e10cSrcweir 							// let the XMLPropertySetMapper decide how to import the value
220*cdf0e10cSrcweir 							bSet = maPropMapper->importXML( rValue, aNewProperty,
221*cdf0e10cSrcweir 													 rUnitConverter );
222*cdf0e10cSrcweir 						}
223*cdf0e10cSrcweir 						else
224*cdf0e10cSrcweir 						{
225*cdf0e10cSrcweir 							sal_uInt32 nOldSize = rProperties.size();
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 							bSet = handleSpecialItem( aNewProperty, rProperties,
228*cdf0e10cSrcweir 													  rValue, rUnitConverter,
229*cdf0e10cSrcweir 									   				  rNamespaceMap );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 							// no warning if handleSpecialItem added properties
232*cdf0e10cSrcweir 							bNoWarning |= ( nOldSize != rProperties.size() );
233*cdf0e10cSrcweir 						}
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 						// no warning if we found could set the item. This
236*cdf0e10cSrcweir 						// 'remembers' bSet across multi properties.
237*cdf0e10cSrcweir 						bNoWarning |= bSet;
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 						// store the property in the given vector
240*cdf0e10cSrcweir 						if( bSet )
241*cdf0e10cSrcweir 						{
242*cdf0e10cSrcweir 							if( nReference == -1 )
243*cdf0e10cSrcweir 								rProperties.push_back( aNewProperty );
244*cdf0e10cSrcweir 							else
245*cdf0e10cSrcweir 								rProperties[nReference] = aNewProperty;
246*cdf0e10cSrcweir 						}
247*cdf0e10cSrcweir 						else
248*cdf0e10cSrcweir 						{
249*cdf0e10cSrcweir 							// warn about unknown value. Unless it's a
250*cdf0e10cSrcweir 							// multi property: Then we get another chance
251*cdf0e10cSrcweir 							// to set the value.
252*cdf0e10cSrcweir 							if( !bNoWarning &&
253*cdf0e10cSrcweir 								((nFlags & MID_FLAG_MULTI_PROPERTY) == 0) )
254*cdf0e10cSrcweir 							{
255*cdf0e10cSrcweir 								Sequence<OUString> aSeq(2);
256*cdf0e10cSrcweir 								aSeq[0] = rAttrName;
257*cdf0e10cSrcweir 								aSeq[1] = rValue;
258*cdf0e10cSrcweir 								rImport.SetError( XMLERROR_FLAG_WARNING |
259*cdf0e10cSrcweir 												  XMLERROR_STYLE_ATTR_VALUE,
260*cdf0e10cSrcweir 												  aSeq );
261*cdf0e10cSrcweir 							}
262*cdf0e10cSrcweir 						}
263*cdf0e10cSrcweir 					}
264*cdf0e10cSrcweir 					bFound = sal_True;
265*cdf0e10cSrcweir 					continue;
266*cdf0e10cSrcweir 				}
267*cdf0e10cSrcweir 			}
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 			if( !bFound )
270*cdf0e10cSrcweir 			{
271*cdf0e10cSrcweir 				if( (XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) || (XML_NAMESPACE_NONE == nPrefix) || bAlienImport )
272*cdf0e10cSrcweir 				{
273*cdf0e10cSrcweir 					OSL_ENSURE( XML_NAMESPACE_NONE == nPrefix ||
274*cdf0e10cSrcweir 								(XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) ||
275*cdf0e10cSrcweir 								bAlienImport,
276*cdf0e10cSrcweir 								"unknown attribute - might be a new feature?" );
277*cdf0e10cSrcweir 					if( !xAttrContainer.is() )
278*cdf0e10cSrcweir 					{
279*cdf0e10cSrcweir 						// add an unknown attribute container to the properties
280*cdf0e10cSrcweir 						Reference< XNameContainer > xNew( SvUnoAttributeContainer_CreateInstance(), UNO_QUERY );
281*cdf0e10cSrcweir 						xAttrContainer = xNew;
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir 						// find map entry and create new property state
284*cdf0e10cSrcweir                         if( -1 == nIndex )
285*cdf0e10cSrcweir                         {
286*cdf0e10cSrcweir                             switch( nPropType )
287*cdf0e10cSrcweir                             {
288*cdf0e10cSrcweir                                 case XML_TYPE_PROP_CHART:
289*cdf0e10cSrcweir                                     nIndex = maPropMapper->FindEntryIndex( "ChartUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
290*cdf0e10cSrcweir                                     break;
291*cdf0e10cSrcweir                                 case XML_TYPE_PROP_PARAGRAPH:
292*cdf0e10cSrcweir                                     nIndex = maPropMapper->FindEntryIndex( "ParaUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
293*cdf0e10cSrcweir                                     break;
294*cdf0e10cSrcweir                                 case  XML_TYPE_PROP_TEXT:
295*cdf0e10cSrcweir                                     nIndex = maPropMapper->FindEntryIndex( "TextUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
296*cdf0e10cSrcweir                                     break;
297*cdf0e10cSrcweir                                 default:
298*cdf0e10cSrcweir                                     break;
299*cdf0e10cSrcweir                             }
300*cdf0e10cSrcweir                             // other property type or property not found
301*cdf0e10cSrcweir                             if( -1 == nIndex )
302*cdf0e10cSrcweir                                 nIndex = maPropMapper->FindEntryIndex( "UserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) );
303*cdf0e10cSrcweir                         }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 						// #106963#; use userdefined attribute only if it is in the specified property range
306*cdf0e10cSrcweir 						if( nIndex != -1 && nIndex >= nStartIdx && nIndex < nEndIdx)
307*cdf0e10cSrcweir 						{
308*cdf0e10cSrcweir 							Any aAny;
309*cdf0e10cSrcweir 							aAny <<= xAttrContainer;
310*cdf0e10cSrcweir 							XMLPropertyState aNewProperty( nIndex, aAny );
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 							// push it on our stack so we export it later
313*cdf0e10cSrcweir 							rProperties.push_back( aNewProperty );
314*cdf0e10cSrcweir 						}
315*cdf0e10cSrcweir 					}
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 					if( xAttrContainer.is() )
318*cdf0e10cSrcweir 					{
319*cdf0e10cSrcweir 						AttributeData aData;
320*cdf0e10cSrcweir 						aData.Type = GetXMLToken( XML_CDATA );
321*cdf0e10cSrcweir 						aData.Value = rValue;
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 						OUStringBuffer sName;
324*cdf0e10cSrcweir 						if( XML_NAMESPACE_NONE != nPrefix )
325*cdf0e10cSrcweir 						{
326*cdf0e10cSrcweir 							sName.append( aPrefix );
327*cdf0e10cSrcweir 							sName.append( sal_Unicode(':') );
328*cdf0e10cSrcweir 							aData.Namespace = aNamespace;
329*cdf0e10cSrcweir 						}
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 						sName.append( aLocalName );
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir 						Any aAny;
334*cdf0e10cSrcweir 						aAny <<= aData;
335*cdf0e10cSrcweir 						xAttrContainer->insertByName( sName.makeStringAndClear(), aAny );
336*cdf0e10cSrcweir 					}
337*cdf0e10cSrcweir 				}
338*cdf0e10cSrcweir 			}
339*cdf0e10cSrcweir 		}
340*cdf0e10cSrcweir 		while( ( nIndex >= 0 ) && (( nFlags & MID_FLAG_MULTI_PROPERTY ) != 0 ) );
341*cdf0e10cSrcweir 	}
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 	finished( rProperties, nStartIdx, nEndIdx );
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	// Have to do if we change from a vector to a list or something like that
346*cdf0e10cSrcweir 	/*std::vector <XMLPropertyState>::iterator aItr = rProperties.begin();
347*cdf0e10cSrcweir 	while (aItr != rProperties.end())
348*cdf0e10cSrcweir 	{
349*cdf0e10cSrcweir 		if (aItr->mnIndex == -1)
350*cdf0e10cSrcweir 			aItr = rProperties.erase(aItr);
351*cdf0e10cSrcweir 		else
352*cdf0e10cSrcweir 			aItr++;
353*cdf0e10cSrcweir 	}*/
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */
357*cdf0e10cSrcweir sal_Bool SvXMLImportPropertyMapper::handleSpecialItem(
358*cdf0e10cSrcweir 		XMLPropertyState& rProperty,
359*cdf0e10cSrcweir 		vector< XMLPropertyState >& rProperties,
360*cdf0e10cSrcweir 		const OUString& rValue,
361*cdf0e10cSrcweir 		const SvXMLUnitConverter& rUnitConverter,
362*cdf0e10cSrcweir 		const SvXMLNamespaceMap& rNamespaceMap ) const
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir 	OSL_ENSURE( mxNextMapper.is(), "unsuported special item in xml import" );
365*cdf0e10cSrcweir 	if( mxNextMapper.is() )
366*cdf0e10cSrcweir 		return mxNextMapper->handleSpecialItem( rProperty, rProperties, rValue,
367*cdf0e10cSrcweir 											   rUnitConverter, rNamespaceMap );
368*cdf0e10cSrcweir 	else
369*cdf0e10cSrcweir 		return sal_False;
370*cdf0e10cSrcweir }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir void SvXMLImportPropertyMapper::FillPropertySequence(
373*cdf0e10cSrcweir 			const ::std::vector< XMLPropertyState >& rProperties,
374*cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rValues )
375*cdf0e10cSrcweir             const
376*cdf0e10cSrcweir {
377*cdf0e10cSrcweir 	sal_Int32 nCount = rProperties.size();
378*cdf0e10cSrcweir     sal_Int32 nValueCount = 0;
379*cdf0e10cSrcweir     rValues.realloc( nCount );
380*cdf0e10cSrcweir 	PropertyValue *pProps = rValues.getArray();
381*cdf0e10cSrcweir 	for( sal_Int32 i=0; i < nCount; i++ )
382*cdf0e10cSrcweir 	{
383*cdf0e10cSrcweir 		const XMLPropertyState& rProp = rProperties[i];
384*cdf0e10cSrcweir 		sal_Int32 nIdx = rProp.mnIndex;
385*cdf0e10cSrcweir         if( nIdx == -1 )
386*cdf0e10cSrcweir             continue;
387*cdf0e10cSrcweir 		pProps->Name = maPropMapper->GetEntryAPIName( nIdx );
388*cdf0e10cSrcweir         if( pProps->Name.getLength() )
389*cdf0e10cSrcweir         {
390*cdf0e10cSrcweir             pProps->Value <<= rProp.maValue;
391*cdf0e10cSrcweir             ++pProps;
392*cdf0e10cSrcweir             ++nValueCount;
393*cdf0e10cSrcweir         }
394*cdf0e10cSrcweir     }
395*cdf0e10cSrcweir     if( nValueCount < nCount )
396*cdf0e10cSrcweir         rValues.realloc( nValueCount );
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir void SvXMLImportPropertyMapper::CheckSpecialContext(
400*cdf0e10cSrcweir 			const ::std::vector< XMLPropertyState >& aProperties,
401*cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference<
402*cdf0e10cSrcweir 					::com::sun::star::beans::XPropertySet > rPropSet,
403*cdf0e10cSrcweir         	_ContextID_Index_Pair* pSpecialContextIds ) const
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir     OSL_ENSURE( rPropSet.is(), "need an XPropertySet" );
406*cdf0e10cSrcweir 	sal_Int32 nCount = aProperties.size();
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 	Reference< XPropertySetInfo > xInfo(rPropSet->getPropertySetInfo());
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 	for( sal_Int32 i=0; i < nCount; i++ )
411*cdf0e10cSrcweir 	{
412*cdf0e10cSrcweir 		const XMLPropertyState& rProp = aProperties[i];
413*cdf0e10cSrcweir 		sal_Int32 nIdx = rProp.mnIndex;
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 		// disregard property state if it has an invalid index
416*cdf0e10cSrcweir 		if( -1 == nIdx )
417*cdf0e10cSrcweir 			continue;
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 		const sal_Int32 nPropFlags = maPropMapper->GetEntryFlags( nIdx );
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir         // handle no-property and special items
422*cdf0e10cSrcweir         if( ( pSpecialContextIds != NULL ) &&
423*cdf0e10cSrcweir             ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) ||
424*cdf0e10cSrcweir               ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) )   ) )
425*cdf0e10cSrcweir         {
426*cdf0e10cSrcweir             // maybe it's one of our special context ids?
427*cdf0e10cSrcweir             sal_Int16 nContextId = maPropMapper->GetEntryContextId(nIdx);
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir             for ( sal_Int32 n = 0;
430*cdf0e10cSrcweir                   pSpecialContextIds[n].nContextID != -1;
431*cdf0e10cSrcweir                   n++ )
432*cdf0e10cSrcweir             {
433*cdf0e10cSrcweir                 // found: set index in pSpecialContextIds array
434*cdf0e10cSrcweir                 if ( pSpecialContextIds[n].nContextID == nContextId )
435*cdf0e10cSrcweir                 {
436*cdf0e10cSrcweir                     pSpecialContextIds[n].nIndex = i;
437*cdf0e10cSrcweir                     break; // early out
438*cdf0e10cSrcweir                 }
439*cdf0e10cSrcweir             }
440*cdf0e10cSrcweir         }
441*cdf0e10cSrcweir     }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir sal_Bool SvXMLImportPropertyMapper::FillPropertySet(
446*cdf0e10cSrcweir 			const vector< XMLPropertyState >& aProperties,
447*cdf0e10cSrcweir 			const Reference< XPropertySet > rPropSet,
448*cdf0e10cSrcweir     		_ContextID_Index_Pair* pSpecialContextIds ) const
449*cdf0e10cSrcweir {
450*cdf0e10cSrcweir     sal_Bool bSet = sal_False;
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir     Reference< XTolerantMultiPropertySet > xTolPropSet( rPropSet, UNO_QUERY );
453*cdf0e10cSrcweir     if (xTolPropSet.is())
454*cdf0e10cSrcweir         bSet = _FillTolerantMultiPropertySet( aProperties, xTolPropSet, maPropMapper, rImport,
455*cdf0e10cSrcweir                                             pSpecialContextIds );
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir     if (!bSet)
458*cdf0e10cSrcweir     {
459*cdf0e10cSrcweir 	    // get property set info
460*cdf0e10cSrcweir 	    Reference< XPropertySetInfo > xInfo(rPropSet->getPropertySetInfo());
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir         // check for multi-property set
463*cdf0e10cSrcweir 	    Reference<XMultiPropertySet> xMultiPropSet( rPropSet, UNO_QUERY );
464*cdf0e10cSrcweir 	    if ( xMultiPropSet.is() )
465*cdf0e10cSrcweir         {
466*cdf0e10cSrcweir             // Try XMultiPropertySet. If that fails, try the regular route.
467*cdf0e10cSrcweir             bSet = _FillMultiPropertySet( aProperties, xMultiPropSet,
468*cdf0e10cSrcweir                                         xInfo, maPropMapper,
469*cdf0e10cSrcweir                                         pSpecialContextIds );
470*cdf0e10cSrcweir             if ( !bSet )
471*cdf0e10cSrcweir                 bSet = _FillPropertySet( aProperties, rPropSet,
472*cdf0e10cSrcweir                                         xInfo, maPropMapper, rImport,
473*cdf0e10cSrcweir                                         pSpecialContextIds);
474*cdf0e10cSrcweir         }
475*cdf0e10cSrcweir         else
476*cdf0e10cSrcweir             bSet = _FillPropertySet( aProperties, rPropSet, xInfo,
477*cdf0e10cSrcweir                                     maPropMapper, rImport,
478*cdf0e10cSrcweir                                     pSpecialContextIds );
479*cdf0e10cSrcweir     }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 	return bSet;
482*cdf0e10cSrcweir }
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir sal_Bool SvXMLImportPropertyMapper::_FillPropertySet(
485*cdf0e10cSrcweir     const vector<XMLPropertyState> & rProperties,
486*cdf0e10cSrcweir     const Reference<XPropertySet> & rPropSet,
487*cdf0e10cSrcweir     const Reference<XPropertySetInfo> & rPropSetInfo,
488*cdf0e10cSrcweir     const UniReference<XMLPropertySetMapper> & rPropMapper,
489*cdf0e10cSrcweir     SvXMLImport& rImport,
490*cdf0e10cSrcweir     _ContextID_Index_Pair* pSpecialContextIds )
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir     OSL_ENSURE( rPropSet.is(), "need an XPropertySet" );
493*cdf0e10cSrcweir     OSL_ENSURE( rPropSetInfo.is(), "need an XPropertySetInfo" );
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 	// preliminaries
496*cdf0e10cSrcweir 	sal_Bool bSet = sal_False;
497*cdf0e10cSrcweir 	sal_Int32 nCount = rProperties.size();
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir 	// iterate over property states that we want to set
500*cdf0e10cSrcweir 	for( sal_Int32 i=0; i < nCount; i++ )
501*cdf0e10cSrcweir 	{
502*cdf0e10cSrcweir 		const XMLPropertyState& rProp = rProperties[i];
503*cdf0e10cSrcweir 		sal_Int32 nIdx = rProp.mnIndex;
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 		// disregard property state if it has an invalid index
506*cdf0e10cSrcweir 		if( -1 == nIdx )
507*cdf0e10cSrcweir 			continue;
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 		const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
510*cdf0e10cSrcweir 		const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 		if ( ( 0 == ( nPropFlags & MID_FLAG_NO_PROPERTY ) ) &&
513*cdf0e10cSrcweir              ( ( 0 != ( nPropFlags & MID_FLAG_MUST_EXIST ) ) ||
514*cdf0e10cSrcweir                rPropSetInfo->hasPropertyByName( rPropName ) )    )
515*cdf0e10cSrcweir 		{
516*cdf0e10cSrcweir             // try setting the property
517*cdf0e10cSrcweir             try
518*cdf0e10cSrcweir             {
519*cdf0e10cSrcweir                 rPropSet->setPropertyValue( rPropName, rProp.maValue );
520*cdf0e10cSrcweir                 bSet = sal_True;
521*cdf0e10cSrcweir             }
522*cdf0e10cSrcweir             catch ( IllegalArgumentException& e )
523*cdf0e10cSrcweir             {
524*cdf0e10cSrcweir                 // illegal value: check whether this property is
525*cdf0e10cSrcweir                 // allowed to throw this exception
526*cdf0e10cSrcweir                 if ( 0 == ( nPropFlags & MID_FLAG_PROPERTY_MAY_EXCEPT ) )
527*cdf0e10cSrcweir                 {
528*cdf0e10cSrcweir                     Sequence<OUString> aSeq(1);
529*cdf0e10cSrcweir                     aSeq[0] = rPropName;
530*cdf0e10cSrcweir                     rImport.SetError(
531*cdf0e10cSrcweir                         XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_ERROR,
532*cdf0e10cSrcweir                         aSeq, e.Message, NULL );
533*cdf0e10cSrcweir                 }
534*cdf0e10cSrcweir             }
535*cdf0e10cSrcweir             catch ( UnknownPropertyException& e )
536*cdf0e10cSrcweir             {
537*cdf0e10cSrcweir                 // unknown property: This is always an error!
538*cdf0e10cSrcweir                 Sequence<OUString> aSeq(1);
539*cdf0e10cSrcweir                 aSeq[0] = rPropName;
540*cdf0e10cSrcweir                 rImport.SetError(
541*cdf0e10cSrcweir                     XMLERROR_STYLE_PROP_UNKNOWN | XMLERROR_FLAG_ERROR,
542*cdf0e10cSrcweir                     aSeq, e.Message, NULL );
543*cdf0e10cSrcweir             }
544*cdf0e10cSrcweir             catch ( PropertyVetoException& e )
545*cdf0e10cSrcweir             {
546*cdf0e10cSrcweir                 // property veto: this shouldn't happen
547*cdf0e10cSrcweir                 Sequence<OUString> aSeq(1);
548*cdf0e10cSrcweir                 aSeq[0] = rPropName;
549*cdf0e10cSrcweir                 rImport.SetError(
550*cdf0e10cSrcweir                     XMLERROR_STYLE_PROP_OTHER | XMLERROR_FLAG_ERROR,
551*cdf0e10cSrcweir                     aSeq, e.Message, NULL );
552*cdf0e10cSrcweir             }
553*cdf0e10cSrcweir             catch ( WrappedTargetException& e )
554*cdf0e10cSrcweir             {
555*cdf0e10cSrcweir                 // wrapped target: this shouldn't happen either
556*cdf0e10cSrcweir                 Sequence<OUString> aSeq(1);
557*cdf0e10cSrcweir                 aSeq[0] = rPropName;
558*cdf0e10cSrcweir                 rImport.SetError(
559*cdf0e10cSrcweir                     XMLERROR_STYLE_PROP_OTHER | XMLERROR_FLAG_ERROR,
560*cdf0e10cSrcweir                     aSeq, e.Message, NULL );
561*cdf0e10cSrcweir             }
562*cdf0e10cSrcweir         }
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir         // handle no-property and special items
565*cdf0e10cSrcweir         if( ( pSpecialContextIds != NULL ) &&
566*cdf0e10cSrcweir             ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) ||
567*cdf0e10cSrcweir               ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) )   ) )
568*cdf0e10cSrcweir         {
569*cdf0e10cSrcweir             // maybe it's one of our special context ids?
570*cdf0e10cSrcweir             sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir             for ( sal_Int32 n = 0;
573*cdf0e10cSrcweir                   pSpecialContextIds[n].nContextID != -1;
574*cdf0e10cSrcweir                   n++ )
575*cdf0e10cSrcweir             {
576*cdf0e10cSrcweir                 // found: set index in pSpecialContextIds array
577*cdf0e10cSrcweir                 if ( pSpecialContextIds[n].nContextID == nContextId )
578*cdf0e10cSrcweir                 {
579*cdf0e10cSrcweir                     pSpecialContextIds[n].nIndex = i;
580*cdf0e10cSrcweir                     break; // early out
581*cdf0e10cSrcweir                 }
582*cdf0e10cSrcweir             }
583*cdf0e10cSrcweir         }
584*cdf0e10cSrcweir     }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir     return bSet;
587*cdf0e10cSrcweir }
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir typedef pair<const OUString*, const Any* > PropertyPair;
592*cdf0e10cSrcweir typedef vector<PropertyPair> PropertyPairs;
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir struct PropertyPairLessFunctor :
595*cdf0e10cSrcweir 	public binary_function<PropertyPair, PropertyPair, bool>
596*cdf0e10cSrcweir {
597*cdf0e10cSrcweir 	bool operator()( const PropertyPair& a, const PropertyPair& b ) const
598*cdf0e10cSrcweir 	{
599*cdf0e10cSrcweir 		return (*a.first < *b.first ? true : false);
600*cdf0e10cSrcweir 	}
601*cdf0e10cSrcweir };
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir void SvXMLImportPropertyMapper::_PrepareForMultiPropertySet(
604*cdf0e10cSrcweir     const vector<XMLPropertyState> & rProperties,
605*cdf0e10cSrcweir     const Reference<XPropertySetInfo> & rPropSetInfo,
606*cdf0e10cSrcweir     const UniReference<XMLPropertySetMapper> & rPropMapper,
607*cdf0e10cSrcweir     _ContextID_Index_Pair* pSpecialContextIds,
608*cdf0e10cSrcweir     Sequence<OUString>& rNames,
609*cdf0e10cSrcweir     Sequence<Any>& rValues)
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir     sal_Int32 nCount = rProperties.size();
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir     // property pairs structure stores names + values of properties to be set.
614*cdf0e10cSrcweir 	PropertyPairs aPropertyPairs;
615*cdf0e10cSrcweir     aPropertyPairs.reserve( nCount );
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 	// iterate over property states that we want to set
618*cdf0e10cSrcweir 	sal_Int32 i;
619*cdf0e10cSrcweir 	for( i = 0; i < nCount; i++ )
620*cdf0e10cSrcweir 	{
621*cdf0e10cSrcweir 		const XMLPropertyState& rProp = rProperties[i];
622*cdf0e10cSrcweir 		sal_Int32 nIdx = rProp.mnIndex;
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir 		// disregard property state if it has an invalid index
625*cdf0e10cSrcweir 		if( -1 == nIdx )
626*cdf0e10cSrcweir 			continue;
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir 		const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx );
629*cdf0e10cSrcweir 		const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx );
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir 		if ( ( 0 == ( nPropFlags & MID_FLAG_NO_PROPERTY ) ) &&
632*cdf0e10cSrcweir              ( ( 0 != ( nPropFlags & MID_FLAG_MUST_EXIST ) ) ||
633*cdf0e10cSrcweir                !rPropSetInfo.is() ||
634*cdf0e10cSrcweir                (rPropSetInfo.is() && rPropSetInfo->hasPropertyByName( rPropName )) ) )
635*cdf0e10cSrcweir 		{
636*cdf0e10cSrcweir 			// save property into property pair structure
637*cdf0e10cSrcweir             aPropertyPairs.push_back( PropertyPair( &rPropName, &rProp.maValue ) );
638*cdf0e10cSrcweir 		}
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir         // handle no-property and special items
641*cdf0e10cSrcweir         if( ( pSpecialContextIds != NULL ) &&
642*cdf0e10cSrcweir             ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) ||
643*cdf0e10cSrcweir               ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) )   ) )
644*cdf0e10cSrcweir         {
645*cdf0e10cSrcweir             // maybe it's one of our special context ids?
646*cdf0e10cSrcweir             sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx);
647*cdf0e10cSrcweir             for ( sal_Int32 n = 0;
648*cdf0e10cSrcweir                   pSpecialContextIds[n].nContextID != -1;
649*cdf0e10cSrcweir                   n++ )
650*cdf0e10cSrcweir             {
651*cdf0e10cSrcweir                 // found: set index in pSpecialContextIds array
652*cdf0e10cSrcweir                 if ( pSpecialContextIds[n].nContextID == nContextId )
653*cdf0e10cSrcweir                 {
654*cdf0e10cSrcweir                     pSpecialContextIds[n].nIndex = i;
655*cdf0e10cSrcweir                     break; // early out
656*cdf0e10cSrcweir                 }
657*cdf0e10cSrcweir             }
658*cdf0e10cSrcweir         }
659*cdf0e10cSrcweir 	}
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir 	// We now need to construct the sequences and actually the set
662*cdf0e10cSrcweir 	// values.
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir     // sort the property pairs
665*cdf0e10cSrcweir     sort( aPropertyPairs.begin(), aPropertyPairs.end(),
666*cdf0e10cSrcweir           PropertyPairLessFunctor());
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir     // create sequences
669*cdf0e10cSrcweir     rNames.realloc( aPropertyPairs.size() );
670*cdf0e10cSrcweir     OUString* pNamesArray = rNames.getArray();
671*cdf0e10cSrcweir     rValues.realloc( aPropertyPairs.size() );
672*cdf0e10cSrcweir     Any* pValuesArray = rValues.getArray();
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir     // copy values into sequences
675*cdf0e10cSrcweir     i = 0;
676*cdf0e10cSrcweir     for( PropertyPairs::iterator aIter = aPropertyPairs.begin();
677*cdf0e10cSrcweir          aIter != aPropertyPairs.end();
678*cdf0e10cSrcweir          ++aIter )
679*cdf0e10cSrcweir     {
680*cdf0e10cSrcweir         pNamesArray[i] = *(aIter->first);
681*cdf0e10cSrcweir         pValuesArray[i++] = *(aIter->second);
682*cdf0e10cSrcweir     }
683*cdf0e10cSrcweir }
684*cdf0e10cSrcweir 
685*cdf0e10cSrcweir sal_Bool SvXMLImportPropertyMapper::_FillMultiPropertySet(
686*cdf0e10cSrcweir     const vector<XMLPropertyState> & rProperties,
687*cdf0e10cSrcweir     const Reference<XMultiPropertySet> & rMultiPropSet,
688*cdf0e10cSrcweir     const Reference<XPropertySetInfo> & rPropSetInfo,
689*cdf0e10cSrcweir     const UniReference<XMLPropertySetMapper> & rPropMapper,
690*cdf0e10cSrcweir     _ContextID_Index_Pair* pSpecialContextIds )
691*cdf0e10cSrcweir {
692*cdf0e10cSrcweir     OSL_ENSURE( rMultiPropSet.is(), "Need multi property set. ");
693*cdf0e10cSrcweir     OSL_ENSURE( rPropSetInfo.is(), "Need property set info." );
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir     sal_Bool bSuccessful = sal_False;
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir     Sequence<OUString> aNames;
698*cdf0e10cSrcweir     Sequence<Any> aValues;
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir     _PrepareForMultiPropertySet(rProperties, rPropSetInfo, rPropMapper, pSpecialContextIds,
701*cdf0e10cSrcweir         aNames, aValues);
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir     // and, finally, try to set the values
704*cdf0e10cSrcweir     try
705*cdf0e10cSrcweir     {
706*cdf0e10cSrcweir         rMultiPropSet->setPropertyValues( aNames, aValues );
707*cdf0e10cSrcweir         bSuccessful = sal_True;
708*cdf0e10cSrcweir     }
709*cdf0e10cSrcweir     catch ( ... )
710*cdf0e10cSrcweir 	{
711*cdf0e10cSrcweir 		OSL_ENSURE(bSuccessful, "Exception caught; style may not be imported correctly.");
712*cdf0e10cSrcweir     }
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir 	return bSuccessful;
715*cdf0e10cSrcweir }
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir sal_Bool SvXMLImportPropertyMapper::_FillTolerantMultiPropertySet(
718*cdf0e10cSrcweir     const vector<XMLPropertyState> & rProperties,
719*cdf0e10cSrcweir     const Reference<XTolerantMultiPropertySet> & rTolMultiPropSet,
720*cdf0e10cSrcweir     const UniReference<XMLPropertySetMapper> & rPropMapper,
721*cdf0e10cSrcweir     SvXMLImport& rImport,
722*cdf0e10cSrcweir     _ContextID_Index_Pair* pSpecialContextIds )
723*cdf0e10cSrcweir {
724*cdf0e10cSrcweir     OSL_ENSURE( rTolMultiPropSet.is(), "Need tolerant multi property set. ");
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir     sal_Bool bSuccessful = sal_False;
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir     Sequence<OUString> aNames;
729*cdf0e10cSrcweir     Sequence<Any> aValues;
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir     _PrepareForMultiPropertySet(rProperties, Reference<XPropertySetInfo>(NULL), rPropMapper, pSpecialContextIds,
732*cdf0e10cSrcweir         aNames, aValues);
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir     // and, finally, try to set the values
735*cdf0e10cSrcweir     try
736*cdf0e10cSrcweir     {
737*cdf0e10cSrcweir         Sequence< SetPropertyTolerantFailed > aResults(rTolMultiPropSet->setPropertyValuesTolerant( aNames, aValues ));
738*cdf0e10cSrcweir         if (aResults.getLength() == 0)
739*cdf0e10cSrcweir             bSuccessful = sal_True;
740*cdf0e10cSrcweir         else
741*cdf0e10cSrcweir         {
742*cdf0e10cSrcweir             sal_Int32 nCount(aResults.getLength());
743*cdf0e10cSrcweir             for( sal_Int32 i = 0; i < nCount; ++i)
744*cdf0e10cSrcweir             {
745*cdf0e10cSrcweir                 Sequence<OUString> aSeq(1);
746*cdf0e10cSrcweir                 aSeq[0] = aResults[i].Name;
747*cdf0e10cSrcweir                 rtl::OUString sMessage;
748*cdf0e10cSrcweir                 switch (aResults[i].Result)
749*cdf0e10cSrcweir                 {
750*cdf0e10cSrcweir                 case TolerantPropertySetResultType::UNKNOWN_PROPERTY :
751*cdf0e10cSrcweir                     sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UNKNOWN_PROPERTY"));
752*cdf0e10cSrcweir                     break;
753*cdf0e10cSrcweir                 case TolerantPropertySetResultType::ILLEGAL_ARGUMENT :
754*cdf0e10cSrcweir                     sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ILLEGAL_ARGUMENT"));
755*cdf0e10cSrcweir                     break;
756*cdf0e10cSrcweir                 case TolerantPropertySetResultType::PROPERTY_VETO :
757*cdf0e10cSrcweir                     sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PROPERTY_VETO"));
758*cdf0e10cSrcweir                     break;
759*cdf0e10cSrcweir                 case TolerantPropertySetResultType::WRAPPED_TARGET :
760*cdf0e10cSrcweir                     sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WRAPPED_TARGET"));
761*cdf0e10cSrcweir                     break;
762*cdf0e10cSrcweir                 };
763*cdf0e10cSrcweir                 rImport.SetError(
764*cdf0e10cSrcweir                     XMLERROR_STYLE_PROP_OTHER | XMLERROR_FLAG_ERROR,
765*cdf0e10cSrcweir                     aSeq, sMessage, NULL );
766*cdf0e10cSrcweir             }
767*cdf0e10cSrcweir         }
768*cdf0e10cSrcweir     }
769*cdf0e10cSrcweir     catch ( ... )
770*cdf0e10cSrcweir 	{
771*cdf0e10cSrcweir 		OSL_ENSURE(bSuccessful, "Exception caught; style may not be imported correctly.");
772*cdf0e10cSrcweir     }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir 	return bSuccessful;
775*cdf0e10cSrcweir }
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir void SvXMLImportPropertyMapper::finished(
778*cdf0e10cSrcweir 		vector< XMLPropertyState >& rProperties,
779*cdf0e10cSrcweir 		sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
780*cdf0e10cSrcweir {
781*cdf0e10cSrcweir 	// nothing to do here
782*cdf0e10cSrcweir 	if( mxNextMapper.is() )
783*cdf0e10cSrcweir 		mxNextMapper->finished( rProperties, nStartIndex, nEndIndex );
784*cdf0e10cSrcweir }
785