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