xref: /AOO41X/main/xmloff/source/style/xmlexppr.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
27cdf0e10cSrcweir #include <com/sun/star/xml/AttributeData.hpp>
28cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
31cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/XTolerantMultiPropertySet.hpp>
33cdf0e10cSrcweir #include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
34cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
35cdf0e10cSrcweir #include <list>
36cdf0e10cSrcweir #include <hash_map>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <xmloff/xmlexppr.hxx>
39cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
40cdf0e10cSrcweir #include <xmloff/attrlist.hxx>
41cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
42cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
43cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
44cdf0e10cSrcweir #include <xmloff/xmlprmap.hxx>
45cdf0e10cSrcweir #include <xmloff/PropertySetInfoHash.hxx>
46cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #ifndef _SVSTDARR_USHORTS
49cdf0e10cSrcweir #define _SVSTDARR_USHORTS
50cdf0e10cSrcweir #include <svl/svstdarr.hxx>
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir 
53cdf0e10cSrcweir using ::rtl::OUString;
54cdf0e10cSrcweir using ::rtl::OUStringBuffer;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir using namespace ::std;
57cdf0e10cSrcweir using namespace ::com::sun::star;
58cdf0e10cSrcweir using namespace ::com::sun::star::beans;
59cdf0e10cSrcweir using namespace ::com::sun::star::uno;
60cdf0e10cSrcweir using namespace ::com::sun::star::lang;
61cdf0e10cSrcweir using namespace ::xmloff::token;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #define GET_PROP_TYPE( f ) static_cast<sal_uInt16>((f & XML_TYPE_PROP_MASK) >> XML_TYPE_PROP_SHIFT)
64cdf0e10cSrcweir 
65cdf0e10cSrcweir struct XMLPropTokens_Impl
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	sal_uInt16 nType;
68cdf0e10cSrcweir 	XMLTokenEnum eToken;
69cdf0e10cSrcweir };
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #define ENTRY(t) { GET_PROP_TYPE(XML_TYPE_PROP_##t), XML_##t##_PROPERTIES }
72cdf0e10cSrcweir const sal_uInt16 MAX_PROP_TYPES =
73cdf0e10cSrcweir 	(XML_TYPE_PROP_END >> XML_TYPE_PROP_SHIFT) -
74cdf0e10cSrcweir 	(XML_TYPE_PROP_START >> XML_TYPE_PROP_SHIFT);
75cdf0e10cSrcweir 
76cdf0e10cSrcweir static  XMLPropTokens_Impl aPropTokens[MAX_PROP_TYPES] =
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	ENTRY(CHART),
79cdf0e10cSrcweir 	ENTRY(GRAPHIC),
80cdf0e10cSrcweir 	ENTRY(TABLE),
81cdf0e10cSrcweir 	ENTRY(TABLE_COLUMN),
82cdf0e10cSrcweir 	ENTRY(TABLE_ROW),
83cdf0e10cSrcweir 	ENTRY(TABLE_CELL),
84cdf0e10cSrcweir 	ENTRY(LIST_LEVEL),
85cdf0e10cSrcweir 	ENTRY(PARAGRAPH),
86cdf0e10cSrcweir 	ENTRY(TEXT),
87cdf0e10cSrcweir 	ENTRY(DRAWING_PAGE),
88cdf0e10cSrcweir 	ENTRY(PAGE_LAYOUT),
89cdf0e10cSrcweir 	ENTRY(HEADER_FOOTER),
90cdf0e10cSrcweir 	ENTRY(RUBY),
91cdf0e10cSrcweir 	ENTRY(SECTION)
92cdf0e10cSrcweir };
93cdf0e10cSrcweir 
94cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
95cdf0e10cSrcweir //
96cdf0e10cSrcweir // public methods
97cdf0e10cSrcweir //
98cdf0e10cSrcweir 
99cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
100cdf0e10cSrcweir //
101cdf0e10cSrcweir // Take all properties of the XPropertySet which are also found in the
102cdf0e10cSrcweir // XMLPropertyMapEntry-array and which are not set to their default-value,
103cdf0e10cSrcweir // if a state is available.
104cdf0e10cSrcweir //
105cdf0e10cSrcweir // After that I call the method 'ContextFilter'.
106cdf0e10cSrcweir //
107cdf0e10cSrcweir 
108cdf0e10cSrcweir typedef std::list<XMLPropertyState> XMLPropertyStateList_Impl;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir class XMLPropertyStates_Impl
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	XMLPropertyStateList_Impl			aPropStates;
113cdf0e10cSrcweir 	XMLPropertyStateList_Impl::iterator	aLastItr;
114cdf0e10cSrcweir 	sal_uInt32							nCount;
115cdf0e10cSrcweir public:
116cdf0e10cSrcweir 	XMLPropertyStates_Impl();
117cdf0e10cSrcweir 	void AddPropertyState(const XMLPropertyState& rPropState);
118cdf0e10cSrcweir 	void FillPropertyStateVector(std::vector<XMLPropertyState>& rVector);
119cdf0e10cSrcweir };
120cdf0e10cSrcweir 
XMLPropertyStates_Impl()121cdf0e10cSrcweir XMLPropertyStates_Impl::XMLPropertyStates_Impl() :
122cdf0e10cSrcweir 	aPropStates(),
123cdf0e10cSrcweir 	nCount(0)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	aLastItr = aPropStates.begin();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
AddPropertyState(const XMLPropertyState & rPropState)128cdf0e10cSrcweir void XMLPropertyStates_Impl::AddPropertyState(
129cdf0e10cSrcweir 		const XMLPropertyState& rPropState)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir 	XMLPropertyStateList_Impl::iterator aItr = aPropStates.begin();
132cdf0e10cSrcweir 	sal_Bool bInserted(sal_False);
133cdf0e10cSrcweir 	if (nCount)
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		if (aLastItr->mnIndex < rPropState.mnIndex)
136cdf0e10cSrcweir 			aItr = ++aLastItr;
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 	do
139cdf0e10cSrcweir 	{
140cdf0e10cSrcweir 		// TODO: one path required only
141cdf0e10cSrcweir 		if (aItr == aPropStates.end())
142cdf0e10cSrcweir 		{
143cdf0e10cSrcweir 			aLastItr = aPropStates.insert(aPropStates.end(), rPropState);
144cdf0e10cSrcweir 			bInserted = sal_True;
145cdf0e10cSrcweir 			nCount++;
146cdf0e10cSrcweir 		}
147cdf0e10cSrcweir 		else if (aItr->mnIndex > rPropState.mnIndex)
148cdf0e10cSrcweir 		{
149cdf0e10cSrcweir 			aLastItr = aPropStates.insert(aItr, rPropState);
150cdf0e10cSrcweir 			bInserted = sal_True;
151cdf0e10cSrcweir 			nCount++;
152cdf0e10cSrcweir 		}
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 	while(!bInserted && (aItr++ != aPropStates.end()));
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
FillPropertyStateVector(std::vector<XMLPropertyState> & rVector)157cdf0e10cSrcweir void XMLPropertyStates_Impl::FillPropertyStateVector(
158cdf0e10cSrcweir 		std::vector<XMLPropertyState>& rVector)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	if (nCount)
161cdf0e10cSrcweir 	{
162cdf0e10cSrcweir 		rVector.resize(nCount, XMLPropertyState(-1));
163cdf0e10cSrcweir         ::std::copy( aPropStates.begin(), aPropStates.end(), rVector.begin() );
164cdf0e10cSrcweir 	}
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir class FilterPropertyInfo_Impl
168cdf0e10cSrcweir {
169cdf0e10cSrcweir 	const rtl::OUString		sApiName;
170cdf0e10cSrcweir 	std::list<sal_uInt32>	aIndexes;
171cdf0e10cSrcweir 	sal_uInt32				nCount;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir public:
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	FilterPropertyInfo_Impl( const rtl::OUString& rApiName,
176cdf0e10cSrcweir 							 const sal_uInt32 nIndex);
177cdf0e10cSrcweir 
GetApiName() const178cdf0e10cSrcweir 	const OUString& GetApiName() const { return sApiName; }
GetIndexes()179cdf0e10cSrcweir 	std::list<sal_uInt32>& GetIndexes() { return aIndexes; }
180cdf0e10cSrcweir 
AddIndex(sal_uInt32 nIndex)181cdf0e10cSrcweir 	void AddIndex( sal_uInt32 nIndex )
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 		aIndexes.push_back(nIndex);
184cdf0e10cSrcweir 		nCount++;
185cdf0e10cSrcweir 	}
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     // for sort
operator <(const FilterPropertyInfo_Impl & rArg) const188cdf0e10cSrcweir     sal_Bool operator< ( const FilterPropertyInfo_Impl& rArg ) const
189cdf0e10cSrcweir     {
190cdf0e10cSrcweir         return (GetApiName() < rArg.GetApiName());
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir };
193cdf0e10cSrcweir 
FilterPropertyInfo_Impl(const rtl::OUString & rApiName,const sal_uInt32 nIndex)194cdf0e10cSrcweir FilterPropertyInfo_Impl::FilterPropertyInfo_Impl(
195cdf0e10cSrcweir 		const rtl::OUString& rApiName,
196cdf0e10cSrcweir 		const sal_uInt32 nIndex ) :
197cdf0e10cSrcweir 	sApiName( rApiName ),
198cdf0e10cSrcweir 	aIndexes(),
199cdf0e10cSrcweir 	nCount(1)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	aIndexes.push_back(nIndex);
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir typedef std::list<FilterPropertyInfo_Impl> FilterPropertyInfoList_Impl;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir // ----------------------------------------------------------------------------
207cdf0e10cSrcweir 
208cdf0e10cSrcweir class FilterPropertiesInfo_Impl
209cdf0e10cSrcweir {
210cdf0e10cSrcweir 	sal_uInt32								nCount;
211cdf0e10cSrcweir 	FilterPropertyInfoList_Impl				aPropInfos;
212cdf0e10cSrcweir 	FilterPropertyInfoList_Impl::iterator	aLastItr;
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 	Sequence <OUString> 					*pApiNames;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir public:
217cdf0e10cSrcweir 	FilterPropertiesInfo_Impl();
218cdf0e10cSrcweir 	~FilterPropertiesInfo_Impl();
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	void AddProperty(const rtl::OUString& rApiName, const sal_uInt32 nIndex);
221cdf0e10cSrcweir 	const uno::Sequence<OUString>& GetApiNames();
222cdf0e10cSrcweir 	void FillPropertyStateArray(
223cdf0e10cSrcweir 			vector< XMLPropertyState >& rPropStates,
224cdf0e10cSrcweir 			const Reference< XPropertySet >& xPropSet,
225cdf0e10cSrcweir 			const UniReference< XMLPropertySetMapper >& maPropMapper,
226cdf0e10cSrcweir 			const sal_Bool bDefault = sal_False);
GetPropertyCount() const227cdf0e10cSrcweir 	sal_uInt32 GetPropertyCount() const { return nCount; }
228cdf0e10cSrcweir };
229cdf0e10cSrcweir 
230cdf0e10cSrcweir // ----------------------------------------------------------------------------
231cdf0e10cSrcweir 
232cdf0e10cSrcweir typedef std::hash_map
233cdf0e10cSrcweir <
234cdf0e10cSrcweir 	PropertySetInfoKey,
235cdf0e10cSrcweir 	FilterPropertiesInfo_Impl *,
236cdf0e10cSrcweir 	PropertySetInfoHash,
237cdf0e10cSrcweir 	PropertySetInfoHash
238cdf0e10cSrcweir >
239cdf0e10cSrcweir FilterOropertiesHashMap_Impl;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir class FilterPropertiesInfos_Impl : public FilterOropertiesHashMap_Impl
242cdf0e10cSrcweir {
243cdf0e10cSrcweir public:
244cdf0e10cSrcweir 	~FilterPropertiesInfos_Impl ();
245cdf0e10cSrcweir };
246cdf0e10cSrcweir 
~FilterPropertiesInfos_Impl()247cdf0e10cSrcweir FilterPropertiesInfos_Impl::~FilterPropertiesInfos_Impl ()
248cdf0e10cSrcweir {
249cdf0e10cSrcweir 	FilterOropertiesHashMap_Impl::iterator aIter = begin();
250cdf0e10cSrcweir 	FilterOropertiesHashMap_Impl::iterator aEnd = end();
251cdf0e10cSrcweir 	while( aIter != aEnd )
252cdf0e10cSrcweir 	{
253cdf0e10cSrcweir 		delete (*aIter).second;
254cdf0e10cSrcweir 		(*aIter).second = 0;
255cdf0e10cSrcweir 		++aIter;
256cdf0e10cSrcweir 	}
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir // ----------------------------------------------------------------------------
260cdf0e10cSrcweir 
FilterPropertiesInfo_Impl()261cdf0e10cSrcweir FilterPropertiesInfo_Impl::FilterPropertiesInfo_Impl() :
262cdf0e10cSrcweir 	nCount(0),
263cdf0e10cSrcweir 	aPropInfos(),
264cdf0e10cSrcweir 	pApiNames( 0 )
265cdf0e10cSrcweir {
266cdf0e10cSrcweir 	aLastItr = aPropInfos.begin();
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
~FilterPropertiesInfo_Impl()269cdf0e10cSrcweir FilterPropertiesInfo_Impl::~FilterPropertiesInfo_Impl()
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	delete pApiNames;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
AddProperty(const rtl::OUString & rApiName,const sal_uInt32 nIndex)274cdf0e10cSrcweir void FilterPropertiesInfo_Impl::AddProperty(
275cdf0e10cSrcweir 		const rtl::OUString& rApiName, const sal_uInt32 nIndex)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir     aPropInfos.push_back(FilterPropertyInfo_Impl(rApiName, nIndex));
278cdf0e10cSrcweir     nCount++;
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 	OSL_ENSURE( !pApiNames, "perfomance warning: API names already retrieved" );
281cdf0e10cSrcweir 	if( pApiNames )
282cdf0e10cSrcweir 	{
283cdf0e10cSrcweir 		delete pApiNames;
284cdf0e10cSrcweir 		pApiNames = NULL;
285cdf0e10cSrcweir 	}
286cdf0e10cSrcweir }
GetApiNames()287cdf0e10cSrcweir const uno::Sequence<OUString>& FilterPropertiesInfo_Impl::GetApiNames()
288cdf0e10cSrcweir {
289cdf0e10cSrcweir 	OSL_ENSURE(nCount == aPropInfos.size(), "wrong property count");
290cdf0e10cSrcweir 	if( !pApiNames )
291cdf0e10cSrcweir 	{
292cdf0e10cSrcweir         // we have to do three things:
293cdf0e10cSrcweir         // 1) sort API names,
294cdf0e10cSrcweir         // 2) merge duplicates,
295cdf0e10cSrcweir         // 3) construct sequence
296cdf0e10cSrcweir 
297cdf0e10cSrcweir         // sort names
298cdf0e10cSrcweir         aPropInfos.sort();
299cdf0e10cSrcweir 
300cdf0e10cSrcweir         // merge duplicates
301cdf0e10cSrcweir         if ( nCount > 1 )
302cdf0e10cSrcweir         {
303cdf0e10cSrcweir             FilterPropertyInfoList_Impl::iterator aOld = aPropInfos.begin();
304cdf0e10cSrcweir             FilterPropertyInfoList_Impl::iterator aEnd = aPropInfos.end();
305cdf0e10cSrcweir             FilterPropertyInfoList_Impl::iterator aCurrent = aOld;
306cdf0e10cSrcweir             aCurrent++;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir             while ( aCurrent != aEnd )
309cdf0e10cSrcweir             {
310cdf0e10cSrcweir                 // equal to next element?
311cdf0e10cSrcweir                 if ( aOld->GetApiName().equals( aCurrent->GetApiName() ) )
312cdf0e10cSrcweir                 {
313cdf0e10cSrcweir                     // if equal: merge index lists
314cdf0e10cSrcweir                     aOld->GetIndexes().merge( aCurrent->GetIndexes() );
315cdf0e10cSrcweir                     // erase element, and continue with next
316cdf0e10cSrcweir                     aCurrent = aPropInfos.erase( aCurrent );
317cdf0e10cSrcweir 					nCount--;
318cdf0e10cSrcweir                 }
319cdf0e10cSrcweir                 else
320cdf0e10cSrcweir                 {
321cdf0e10cSrcweir                     // remember old element and continue with next
322cdf0e10cSrcweir                     aOld = aCurrent;
323cdf0e10cSrcweir                     aCurrent++;
324cdf0e10cSrcweir                 }
325cdf0e10cSrcweir             }
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir         // construct sequence
329cdf0e10cSrcweir 		pApiNames = new Sequence < OUString >( nCount );
330cdf0e10cSrcweir 		OUString *pNames = pApiNames->getArray();
331cdf0e10cSrcweir 		FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
332cdf0e10cSrcweir 		FilterPropertyInfoList_Impl::iterator aEnd = aPropInfos.end();
333cdf0e10cSrcweir 		for ( ; aItr != aEnd; aItr++, pNames++)
334cdf0e10cSrcweir 			*pNames = aItr->GetApiName();
335cdf0e10cSrcweir 	}
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 	return *pApiNames;
338cdf0e10cSrcweir }
339cdf0e10cSrcweir 
FillPropertyStateArray(vector<XMLPropertyState> & rPropStates,const Reference<XPropertySet> & rPropSet,const UniReference<XMLPropertySetMapper> & rPropMapper,const sal_Bool bDefault)340cdf0e10cSrcweir void FilterPropertiesInfo_Impl::FillPropertyStateArray(
341cdf0e10cSrcweir 		vector< XMLPropertyState >& rPropStates,
342cdf0e10cSrcweir 		const Reference< XPropertySet >& rPropSet,
343cdf0e10cSrcweir 		const UniReference< XMLPropertySetMapper >& rPropMapper,
344cdf0e10cSrcweir 		const sal_Bool bDefault )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir 	XMLPropertyStates_Impl aPropStates;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 	const uno::Sequence<OUString>& rApiNames = GetApiNames();
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     Reference < XTolerantMultiPropertySet > xTolPropSet( rPropSet, UNO_QUERY );
351cdf0e10cSrcweir     if (xTolPropSet.is())
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir         if (!bDefault)
354cdf0e10cSrcweir         {
355cdf0e10cSrcweir             Sequence < beans::GetDirectPropertyTolerantResult > aResults(xTolPropSet->getDirectPropertyValuesTolerant(rApiNames));
356cdf0e10cSrcweir             sal_Int32 nResultCount(aResults.getLength());
357cdf0e10cSrcweir             if (nResultCount > 0)
358cdf0e10cSrcweir             {
359cdf0e10cSrcweir 		        const beans::GetDirectPropertyTolerantResult *pResults = aResults.getConstArray();
360cdf0e10cSrcweir 		        FilterPropertyInfoList_Impl::iterator aPropIter(aPropInfos.begin());
361cdf0e10cSrcweir 		        XMLPropertyState aNewProperty( -1 );
362cdf0e10cSrcweir                 sal_uInt32 i = 0;
363cdf0e10cSrcweir                 while (nResultCount > 0 && i < nCount)
364cdf0e10cSrcweir 		        {
365cdf0e10cSrcweir                     if (pResults->Name == aPropIter->GetApiName())
366cdf0e10cSrcweir                     {
367cdf0e10cSrcweir 			            aNewProperty.mnIndex = -1;
368cdf0e10cSrcweir 			            aNewProperty.maValue = pResults->Value;
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 			            for( std::list<sal_uInt32>::iterator aIndexItr(aPropIter->GetIndexes().begin());
371cdf0e10cSrcweir 				            aIndexItr != aPropIter->GetIndexes().end();
372cdf0e10cSrcweir 				            ++aIndexItr )
373cdf0e10cSrcweir 			            {
374cdf0e10cSrcweir 				            aNewProperty.mnIndex = *aIndexItr;
375cdf0e10cSrcweir 				            aPropStates.AddPropertyState( aNewProperty );
376cdf0e10cSrcweir 			            }
377cdf0e10cSrcweir     			        ++pResults;
378cdf0e10cSrcweir                         --nResultCount;
379cdf0e10cSrcweir                     }
380cdf0e10cSrcweir 		            ++aPropIter;
381cdf0e10cSrcweir                     ++i;
382cdf0e10cSrcweir                 }
383cdf0e10cSrcweir 		    }
384cdf0e10cSrcweir         }
385cdf0e10cSrcweir         else
386cdf0e10cSrcweir         {
387cdf0e10cSrcweir             Sequence < beans::GetPropertyTolerantResult > aResults(xTolPropSet->getPropertyValuesTolerant(rApiNames));
388cdf0e10cSrcweir             OSL_ENSURE( rApiNames.getLength() == aResults.getLength(), "wrong implemented XTolerantMultiPropertySet" );
389cdf0e10cSrcweir 		    const beans::GetPropertyTolerantResult *pResults = aResults.getConstArray();
390cdf0e10cSrcweir 		    FilterPropertyInfoList_Impl::iterator aPropIter(aPropInfos.begin());
391cdf0e10cSrcweir 		    XMLPropertyState aNewProperty( -1 );
392cdf0e10cSrcweir             sal_uInt32 nResultCount(aResults.getLength());
393cdf0e10cSrcweir             OSL_ENSURE( nCount == nResultCount, "wrong implemented XTolerantMultiPropertySet??" );
394cdf0e10cSrcweir 		    for( sal_uInt32 i = 0; i < nResultCount; ++i )
395cdf0e10cSrcweir 		    {
396cdf0e10cSrcweir                 if ((pResults->Result == beans::TolerantPropertySetResultType::SUCCESS) &&
397cdf0e10cSrcweir                     ((pResults->State == PropertyState_DIRECT_VALUE) || (pResults->State == PropertyState_DEFAULT_VALUE)))
398cdf0e10cSrcweir                 {
399cdf0e10cSrcweir 			        aNewProperty.mnIndex = -1;
400cdf0e10cSrcweir 			        aNewProperty.maValue = pResults->Value;
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 			        for( std::list<sal_uInt32>::iterator aIndexItr(aPropIter->GetIndexes().begin());
403cdf0e10cSrcweir 				        aIndexItr != aPropIter->GetIndexes().end();
404cdf0e10cSrcweir 				        ++aIndexItr )
405cdf0e10cSrcweir 			        {
406cdf0e10cSrcweir 				        aNewProperty.mnIndex = *aIndexItr;
407cdf0e10cSrcweir 				        aPropStates.AddPropertyState( aNewProperty );
408cdf0e10cSrcweir 			        }
409cdf0e10cSrcweir                 }
410cdf0e10cSrcweir     			++pResults;
411cdf0e10cSrcweir     		    ++aPropIter;
412cdf0e10cSrcweir 		    }
413cdf0e10cSrcweir         }
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir     else
416cdf0e10cSrcweir     {
417cdf0e10cSrcweir 	    Sequence < PropertyState > aStates;
418cdf0e10cSrcweir 	    const PropertyState *pStates = 0;
419cdf0e10cSrcweir 	    Reference< XPropertyState > xPropState( rPropSet, UNO_QUERY );
420cdf0e10cSrcweir    	    if( xPropState.is() )
421cdf0e10cSrcweir 	    {
422cdf0e10cSrcweir 		    aStates = xPropState->getPropertyStates( rApiNames );
423cdf0e10cSrcweir 		    pStates = aStates.getConstArray();
424cdf0e10cSrcweir 	    }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 	    Reference < XMultiPropertySet > xMultiPropSet( rPropSet, UNO_QUERY );
427cdf0e10cSrcweir 	    if( xMultiPropSet.is() && !bDefault )
428cdf0e10cSrcweir 	    {
429cdf0e10cSrcweir 		    Sequence < Any > aValues;
430cdf0e10cSrcweir 		    if( pStates )
431cdf0e10cSrcweir 		    {
432cdf0e10cSrcweir 			    // step 1: get value count
433cdf0e10cSrcweir 			    sal_uInt32 nValueCount = 0;
434cdf0e10cSrcweir 			    sal_uInt32 i;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 			    for( i = 0; i < nCount; ++i, ++pStates )
437cdf0e10cSrcweir 			    {
438cdf0e10cSrcweir 				    if( (*pStates == PropertyState_DIRECT_VALUE)/* || (bDefault && (*pStates == PropertyState_DEFAULT_VALUE))*/ )
439cdf0e10cSrcweir 					    nValueCount++;
440cdf0e10cSrcweir 			    }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 			    if( nValueCount )
443cdf0e10cSrcweir 			    {
444cdf0e10cSrcweir 				    // step 2: collect property names
445cdf0e10cSrcweir 				    Sequence < OUString > aAPINames( nValueCount );
446cdf0e10cSrcweir 				    OUString *pAPINames = aAPINames.getArray();
447cdf0e10cSrcweir 
448cdf0e10cSrcweir                     ::std::vector< FilterPropertyInfoList_Impl::iterator > aPropIters;
449cdf0e10cSrcweir                     aPropIters.reserve( nValueCount );
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 				    FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
452cdf0e10cSrcweir     				OSL_ENSURE(aItr != aPropInfos.end(),"Invalid iterator!");
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 				    pStates = aStates.getConstArray();
455cdf0e10cSrcweir 				    i = 0;
456cdf0e10cSrcweir 				    while( i < nValueCount )
457cdf0e10cSrcweir 				    {
458cdf0e10cSrcweir 					    if( (*pStates == PropertyState_DIRECT_VALUE)/* || (bDefault && (*pStates == PropertyState_DEFAULT_VALUE))*/ )
459cdf0e10cSrcweir 					    {
460cdf0e10cSrcweir 						    *pAPINames++ = aItr->GetApiName();
461cdf0e10cSrcweir                             aPropIters.push_back( aItr );
462cdf0e10cSrcweir 						    ++i;
463cdf0e10cSrcweir 					    }
464cdf0e10cSrcweir                         ++aItr;
465cdf0e10cSrcweir 					    ++pStates;
466cdf0e10cSrcweir 				    }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 				    aValues = xMultiPropSet->getPropertyValues( aAPINames );
469cdf0e10cSrcweir 				    const Any *pValues = aValues.getConstArray();
470cdf0e10cSrcweir 
471cdf0e10cSrcweir                     ::std::vector< FilterPropertyInfoList_Impl::iterator >::const_iterator
472cdf0e10cSrcweir                         pPropIter = aPropIters.begin();
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 				    XMLPropertyState aNewProperty( -1 );
475cdf0e10cSrcweir 				    for( i = 0; i < nValueCount; i++ )
476cdf0e10cSrcweir 				    {
477cdf0e10cSrcweir 					    aNewProperty.mnIndex = -1;
478cdf0e10cSrcweir 					    aNewProperty.maValue = *pValues;
479cdf0e10cSrcweir 
480cdf0e10cSrcweir                         const ::std::list< sal_uInt32 >& rIndexes( (*pPropIter)->GetIndexes() );
481cdf0e10cSrcweir 					    for (   std::list<sal_uInt32>::const_iterator aIndexItr = rIndexes.begin();
482cdf0e10cSrcweir 						        aIndexItr != rIndexes.end();
483cdf0e10cSrcweir 						        ++aIndexItr
484cdf0e10cSrcweir                             )
485cdf0e10cSrcweir 					    {
486cdf0e10cSrcweir 						    aNewProperty.mnIndex = *aIndexItr;
487cdf0e10cSrcweir 						    aPropStates.AddPropertyState( aNewProperty );
488cdf0e10cSrcweir 					    }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 					    ++pPropIter;
491cdf0e10cSrcweir 					    ++pValues;
492cdf0e10cSrcweir 				    }
493cdf0e10cSrcweir 			    }
494cdf0e10cSrcweir 		    }
495cdf0e10cSrcweir 		    else
496cdf0e10cSrcweir 		    {
497cdf0e10cSrcweir 			    aValues = xMultiPropSet->getPropertyValues( rApiNames );
498cdf0e10cSrcweir 			    const Any *pValues = aValues.getConstArray();
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 			    FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
501cdf0e10cSrcweir 			    for(sal_uInt32 i = 0; i < nCount; i++ )
502cdf0e10cSrcweir 			    {
503cdf0e10cSrcweir 				    // The value is stored in the PropertySet itself, add to list.
504cdf0e10cSrcweir 				    XMLPropertyState aNewProperty( -1 );
505cdf0e10cSrcweir 				    aNewProperty.maValue = *pValues;
506cdf0e10cSrcweir 				    ++pValues;
507cdf0e10cSrcweir 				    for( std::list<sal_uInt32>::iterator aIndexItr =
508cdf0e10cSrcweir 						    aItr->GetIndexes().begin();
509cdf0e10cSrcweir 					    aIndexItr != aItr->GetIndexes().end();
510cdf0e10cSrcweir 					    aIndexItr++ )
511cdf0e10cSrcweir 				    {
512cdf0e10cSrcweir 					    aNewProperty.mnIndex = *aIndexItr;
513cdf0e10cSrcweir 					    aPropStates.AddPropertyState( aNewProperty );
514cdf0e10cSrcweir 				    }
515cdf0e10cSrcweir 				    aItr++;
516cdf0e10cSrcweir 			    }
517cdf0e10cSrcweir 		    }
518cdf0e10cSrcweir 	    }
519cdf0e10cSrcweir 	    else
520cdf0e10cSrcweir 	    {
521cdf0e10cSrcweir 		    FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
522cdf0e10cSrcweir 		    for(sal_uInt32 i = 0; i < nCount; i++ )
523cdf0e10cSrcweir 		    {
524cdf0e10cSrcweir 			    sal_Bool bDirectValue =
525cdf0e10cSrcweir 				    !pStates || *pStates == PropertyState_DIRECT_VALUE;
526cdf0e10cSrcweir 			    if( bDirectValue || bDefault )
527cdf0e10cSrcweir 			    {
528cdf0e10cSrcweir 				    // The value is stored in the PropertySet itself, add to list.
529cdf0e10cSrcweir 				    sal_Bool bGotValue = sal_False;
530cdf0e10cSrcweir 				    XMLPropertyState aNewProperty( -1 );
531cdf0e10cSrcweir 				    for( std::list<sal_uInt32>::const_iterator aIndexItr =
532cdf0e10cSrcweir 						    aItr->GetIndexes().begin();
533cdf0e10cSrcweir 					    aIndexItr != aItr->GetIndexes().end();
534cdf0e10cSrcweir 					    aIndexItr++ )
535cdf0e10cSrcweir 				    {
536cdf0e10cSrcweir 					    if( bDirectValue ||
537cdf0e10cSrcweir 						    (rPropMapper->GetEntryFlags( *aIndexItr ) &
538cdf0e10cSrcweir 										    MID_FLAG_DEFAULT_ITEM_EXPORT) != 0 )
539cdf0e10cSrcweir 					    {
540cdf0e10cSrcweir 						    try
541cdf0e10cSrcweir 						    {
542cdf0e10cSrcweir 							    if( !bGotValue )
543cdf0e10cSrcweir 							    {
544cdf0e10cSrcweir 								    aNewProperty.maValue =
545cdf0e10cSrcweir 									    rPropSet->getPropertyValue( aItr->GetApiName() );
546cdf0e10cSrcweir 								    bGotValue = sal_True;
547cdf0e10cSrcweir 							    }
548cdf0e10cSrcweir 							    aNewProperty.mnIndex = *aIndexItr;
549cdf0e10cSrcweir 							    aPropStates.AddPropertyState( aNewProperty );
550cdf0e10cSrcweir 						    }
551cdf0e10cSrcweir 						    catch( UnknownPropertyException& )
552cdf0e10cSrcweir 						    {
553cdf0e10cSrcweir 							    // might be a problem of getImplemenetationId
554cdf0e10cSrcweir 							    OSL_ENSURE( !this, "unknown property in getPropertyValue" );
555cdf0e10cSrcweir 						    }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 					    }
558cdf0e10cSrcweir 				    }
559cdf0e10cSrcweir 			    }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 			    aItr++;
562cdf0e10cSrcweir 			    if( pStates )
563cdf0e10cSrcweir 				    pStates++;
564cdf0e10cSrcweir 		    }
565cdf0e10cSrcweir 	    }
566cdf0e10cSrcweir     }
567cdf0e10cSrcweir 	aPropStates.FillPropertyStateVector(rPropStates);
568cdf0e10cSrcweir }
569cdf0e10cSrcweir 
570cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
571cdf0e10cSrcweir //
572cdf0e10cSrcweir // ctor/dtor , class SvXMLExportPropertyMapper
573cdf0e10cSrcweir //
574cdf0e10cSrcweir 
SvXMLExportPropertyMapper(const UniReference<XMLPropertySetMapper> & rMapper)575cdf0e10cSrcweir SvXMLExportPropertyMapper::SvXMLExportPropertyMapper(
576cdf0e10cSrcweir 		const UniReference< XMLPropertySetMapper >& rMapper ) :
577cdf0e10cSrcweir 	pCache( 0 ),
578cdf0e10cSrcweir 	maPropMapper( rMapper )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir }
581cdf0e10cSrcweir 
~SvXMLExportPropertyMapper()582cdf0e10cSrcweir SvXMLExportPropertyMapper::~SvXMLExportPropertyMapper()
583cdf0e10cSrcweir {
584cdf0e10cSrcweir 	delete pCache;
585cdf0e10cSrcweir 	mxNextMapper = 0;
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
ChainExportMapper(const UniReference<SvXMLExportPropertyMapper> & rMapper)588cdf0e10cSrcweir void SvXMLExportPropertyMapper::ChainExportMapper(
589cdf0e10cSrcweir 		const UniReference< SvXMLExportPropertyMapper>& rMapper )
590cdf0e10cSrcweir {
591cdf0e10cSrcweir 	// add map entries from rMapper to current map
592cdf0e10cSrcweir 	maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() );
593cdf0e10cSrcweir 	// rMapper uses the same map as 'this'
594cdf0e10cSrcweir 	rMapper->maPropMapper = maPropMapper;
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 	// set rMapper as last mapper in current chain
597cdf0e10cSrcweir 	UniReference< SvXMLExportPropertyMapper > xNext = mxNextMapper;
598cdf0e10cSrcweir 	if( xNext.is())
599cdf0e10cSrcweir 	{
600cdf0e10cSrcweir 		while( xNext->mxNextMapper.is())
601cdf0e10cSrcweir 			xNext = xNext->mxNextMapper;
602cdf0e10cSrcweir 		xNext->mxNextMapper = rMapper;
603cdf0e10cSrcweir 	}
604cdf0e10cSrcweir 	else
605cdf0e10cSrcweir 		mxNextMapper = rMapper;
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 	// if rMapper was already chained, correct
608cdf0e10cSrcweir 	// map pointer of successors
609cdf0e10cSrcweir 	xNext = rMapper;
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 	while( xNext->mxNextMapper.is())
612cdf0e10cSrcweir 	{
613cdf0e10cSrcweir 		xNext = xNext->mxNextMapper;
614cdf0e10cSrcweir 		xNext->maPropMapper = maPropMapper;
615cdf0e10cSrcweir 	}
616cdf0e10cSrcweir }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 
_Filter(const Reference<XPropertySet> xPropSet,const sal_Bool bDefault) const619cdf0e10cSrcweir vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter(
620cdf0e10cSrcweir 		const Reference< XPropertySet > xPropSet,
621cdf0e10cSrcweir 		const sal_Bool bDefault ) const
622cdf0e10cSrcweir {
623cdf0e10cSrcweir 	vector< XMLPropertyState > aPropStateArray;
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 	// Retrieve XPropertySetInfo and XPropertyState
626cdf0e10cSrcweir 	Reference< XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
627cdf0e10cSrcweir 	if( !xInfo.is() )
628cdf0e10cSrcweir 		return aPropStateArray;
629cdf0e10cSrcweir 
630cdf0e10cSrcweir 	sal_Int32 nProps = maPropMapper->GetEntryCount();
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 	FilterPropertiesInfo_Impl *pFilterInfo = 0;
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 	Reference < XTypeProvider > xTypeProv( xPropSet, UNO_QUERY );
635cdf0e10cSrcweir 	Sequence< sal_Int8 > aImplId;
636cdf0e10cSrcweir 	if( xTypeProv.is() )
637cdf0e10cSrcweir 	{
638cdf0e10cSrcweir 		aImplId = xTypeProv->getImplementationId();
639cdf0e10cSrcweir 		if( aImplId.getLength() == 16 )
640cdf0e10cSrcweir 		{
641cdf0e10cSrcweir 			if( pCache )
642cdf0e10cSrcweir 			{
643cdf0e10cSrcweir 				// The key must not be created outside this block, because it
644cdf0e10cSrcweir 				// keeps a reference to the property set info.
645cdf0e10cSrcweir 				PropertySetInfoKey aKey( xInfo, aImplId );
646cdf0e10cSrcweir 				FilterPropertiesInfos_Impl::iterator aIter =
647cdf0e10cSrcweir 					pCache->find( aKey );
648cdf0e10cSrcweir 				if( aIter != pCache->end() )
649cdf0e10cSrcweir 					pFilterInfo = (*aIter).second;
650cdf0e10cSrcweir 			}
651cdf0e10cSrcweir 		}
652cdf0e10cSrcweir 	}
653cdf0e10cSrcweir 
654cdf0e10cSrcweir 	sal_Bool bDelInfo = sal_False;
655cdf0e10cSrcweir 	if( !pFilterInfo )
656cdf0e10cSrcweir 	{
657cdf0e10cSrcweir 		pFilterInfo = new FilterPropertiesInfo_Impl;
658cdf0e10cSrcweir 		for( sal_Int32 i=0; i < nProps; i++ )
659cdf0e10cSrcweir 		{
660cdf0e10cSrcweir 			// Are we allowed to ask for the property? (MID_FLAG_NO_PROP..)
661cdf0e10cSrcweir 			// Does the PropertySet contain name of mpEntries-array ?
662cdf0e10cSrcweir 			const OUString& rAPIName = maPropMapper->GetEntryAPIName( i );
663cdf0e10cSrcweir 			const sal_Int32 nFlags = maPropMapper->GetEntryFlags( i );
664cdf0e10cSrcweir 			if( (0 == (nFlags & MID_FLAG_NO_PROPERTY_EXPORT)) &&
665cdf0e10cSrcweir 				( (0 != (nFlags & MID_FLAG_MUST_EXIST)) ||
666cdf0e10cSrcweir 				  xInfo->hasPropertyByName( rAPIName ) ) )
667cdf0e10cSrcweir             {
668cdf0e10cSrcweir                 const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
669cdf0e10cSrcweir                 const SvtSaveOptions::ODFDefaultVersion nEarliestODFVersionForExport(
670cdf0e10cSrcweir                         maPropMapper->GetEarliestODFVersionForExport( i ) );
671cdf0e10cSrcweir                 if( nCurrentVersion >= nEarliestODFVersionForExport
672cdf0e10cSrcweir                         || nCurrentVersion == SvtSaveOptions::ODFVER_UNKNOWN
673cdf0e10cSrcweir                         || nEarliestODFVersionForExport == SvtSaveOptions::ODFVER_UNKNOWN )
674cdf0e10cSrcweir                     pFilterInfo->AddProperty(rAPIName, i);
675cdf0e10cSrcweir             }
676cdf0e10cSrcweir 		}
677cdf0e10cSrcweir 
678cdf0e10cSrcweir 		if( xTypeProv.is() && aImplId.getLength() == 16 )
679cdf0e10cSrcweir 		{
680cdf0e10cSrcweir 			// Check whether the property set info is destroyed if it is
681cdf0e10cSrcweir 			// assigned to a weak reference only. If it is destroyed, then
682cdf0e10cSrcweir 			// every instance of getPropertySetInfo returns a new object.
683cdf0e10cSrcweir 			// Such property set infos must not be cached.
684cdf0e10cSrcweir 			WeakReference < XPropertySetInfo > xWeakInfo( xInfo );
685cdf0e10cSrcweir 			xInfo = 0;
686cdf0e10cSrcweir 			xInfo = xWeakInfo;
687cdf0e10cSrcweir 			if( xInfo.is() )
688cdf0e10cSrcweir 			{
689cdf0e10cSrcweir 				if( !pCache )
690cdf0e10cSrcweir 					((SvXMLExportPropertyMapper *)this)->pCache =
691cdf0e10cSrcweir 						new FilterPropertiesInfos_Impl;
692cdf0e10cSrcweir 				PropertySetInfoKey aKey( xInfo, aImplId );
693cdf0e10cSrcweir 				(*pCache)[aKey] = pFilterInfo;
694cdf0e10cSrcweir 			}
695cdf0e10cSrcweir 			else
696cdf0e10cSrcweir 				bDelInfo = sal_True;
697cdf0e10cSrcweir 		}
698cdf0e10cSrcweir 		else
699cdf0e10cSrcweir 		{
700cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "here is no TypeProvider or the ImplId is wrong");
701cdf0e10cSrcweir 			bDelInfo = sal_True;
702cdf0e10cSrcweir 		}
703cdf0e10cSrcweir 	}
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 	if( pFilterInfo->GetPropertyCount() )
706cdf0e10cSrcweir 	{
707cdf0e10cSrcweir 		try
708cdf0e10cSrcweir 		{
709cdf0e10cSrcweir 			pFilterInfo->FillPropertyStateArray(aPropStateArray,
710cdf0e10cSrcweir 												xPropSet, maPropMapper,
711cdf0e10cSrcweir 												bDefault);
712cdf0e10cSrcweir 		}
713cdf0e10cSrcweir 		catch( UnknownPropertyException& )
714cdf0e10cSrcweir 		{
715cdf0e10cSrcweir 			// might be a problem of getImplemenetationId
716cdf0e10cSrcweir 			OSL_ENSURE( !this, "unknown property in getPropertyStates" );
717cdf0e10cSrcweir 		}
718cdf0e10cSrcweir 	}
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 	// Call centext-filter
721cdf0e10cSrcweir 	if( !aPropStateArray.empty() )
722cdf0e10cSrcweir 		ContextFilter( aPropStateArray, xPropSet );
723cdf0e10cSrcweir 
724cdf0e10cSrcweir 	// Have to do if we change from a vector to a list or something like that
725cdf0e10cSrcweir 	/*vector< XMLPropertyState >::iterator aItr = aPropStateArray.begin();
726cdf0e10cSrcweir 	while (aItr != aPropStateArray.end())
727cdf0e10cSrcweir 	{
728cdf0e10cSrcweir 		if (aItr->mnIndex == -1)
729cdf0e10cSrcweir 			aItr = aPropStateArray.erase(aItr);
730cdf0e10cSrcweir 		else
731cdf0e10cSrcweir 			aItr++;
732cdf0e10cSrcweir 	}*/
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 	if( bDelInfo )
735cdf0e10cSrcweir 		delete pFilterInfo;
736cdf0e10cSrcweir 
737cdf0e10cSrcweir 	return aPropStateArray;
738cdf0e10cSrcweir }
739cdf0e10cSrcweir 
ContextFilter(vector<XMLPropertyState> & rProperties,Reference<XPropertySet> rPropSet) const740cdf0e10cSrcweir void SvXMLExportPropertyMapper::ContextFilter(
741cdf0e10cSrcweir 		vector< XMLPropertyState >& rProperties,
742cdf0e10cSrcweir 		Reference< XPropertySet > rPropSet ) const
743cdf0e10cSrcweir {
744cdf0e10cSrcweir 	// Derived class could implement this.
745cdf0e10cSrcweir 	if( mxNextMapper.is() )
746cdf0e10cSrcweir 		mxNextMapper->ContextFilter( rProperties, rPropSet );
747cdf0e10cSrcweir }
748cdf0e10cSrcweir 
749cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
750cdf0e10cSrcweir //
751cdf0e10cSrcweir // Compares two Sequences of XMLPropertyState:
752cdf0e10cSrcweir //	1.Number of elements equal ?
753cdf0e10cSrcweir //	2.Index of each element equal ? (So I know whether the propertynames are the same)
754cdf0e10cSrcweir //	3.Value of each element equal ?
755cdf0e10cSrcweir //
Equals(const vector<XMLPropertyState> & aProperties1,const vector<XMLPropertyState> & aProperties2) const756cdf0e10cSrcweir sal_Bool SvXMLExportPropertyMapper::Equals(
757cdf0e10cSrcweir 		const vector< XMLPropertyState >& aProperties1,
758cdf0e10cSrcweir 	    const vector< XMLPropertyState >& aProperties2 ) const
759cdf0e10cSrcweir {
760cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
761cdf0e10cSrcweir 	sal_uInt32 nCount = aProperties1.size();
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 	if( nCount == aProperties2.size() )
764cdf0e10cSrcweir 	{
765cdf0e10cSrcweir 		sal_uInt32 nIndex = 0;
766cdf0e10cSrcweir 		while( bRet && nIndex < nCount )
767cdf0e10cSrcweir 		{
768cdf0e10cSrcweir 			const XMLPropertyState& rProp1 = aProperties1[ nIndex ];
769cdf0e10cSrcweir 			const XMLPropertyState& rProp2 = aProperties2[ nIndex ];
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 			// Compare index. If equal, compare value
772cdf0e10cSrcweir 			if( rProp1.mnIndex == rProp2.mnIndex )
773cdf0e10cSrcweir 			{
774cdf0e10cSrcweir 				if( rProp1.mnIndex != -1 )
775cdf0e10cSrcweir 				{
776cdf0e10cSrcweir 					// Now compare values
777cdf0e10cSrcweir 					if( ( maPropMapper->GetEntryType( rProp1.mnIndex ) &
778cdf0e10cSrcweir 						  XML_TYPE_BUILDIN_CMP ) != 0 )
779cdf0e10cSrcweir 						// simple type ( binary compare )
780cdf0e10cSrcweir 						bRet = ( rProp1.maValue == rProp2.maValue );
781cdf0e10cSrcweir 					else
782cdf0e10cSrcweir 						// complex type ( ask for compare-function )
783cdf0e10cSrcweir 						bRet = maPropMapper->GetPropertyHandler(
784cdf0e10cSrcweir 									rProp1.mnIndex )->equals( rProp1.maValue,
785cdf0e10cSrcweir 															  rProp2.maValue );
786cdf0e10cSrcweir 				}
787cdf0e10cSrcweir 			}
788cdf0e10cSrcweir 			else
789cdf0e10cSrcweir 				bRet = sal_False;
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 			nIndex++;
792cdf0e10cSrcweir 		}
793cdf0e10cSrcweir 	}
794cdf0e10cSrcweir 	else
795cdf0e10cSrcweir 		bRet = sal_False;
796cdf0e10cSrcweir 
797cdf0e10cSrcweir 	return bRet;
798cdf0e10cSrcweir }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 
801cdf0e10cSrcweir /** fills the given attribute list with the items in the given set
802cdf0e10cSrcweir void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList,
803cdf0e10cSrcweir 		const ::std::vector< XMLPropertyState >& rProperties,
804cdf0e10cSrcweir 		const SvXMLUnitConverter& rUnitConverter,
805cdf0e10cSrcweir 		const SvXMLNamespaceMap& rNamespaceMap,
806cdf0e10cSrcweir 		sal_uInt16 nFlags ) const
807cdf0e10cSrcweir {
808cdf0e10cSrcweir 	_exportXML( rAttrList, rProperties, rUnitConverter, rNamespaceMap,
809cdf0e10cSrcweir 				nFlags, 0, -1, -1 );
810cdf0e10cSrcweir }
811cdf0e10cSrcweir 
812cdf0e10cSrcweir 
813cdf0e10cSrcweir void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList,
814cdf0e10cSrcweir 		const ::std::vector< XMLPropertyState >& rProperties,
815cdf0e10cSrcweir 		const SvXMLUnitConverter& rUnitConverter,
816cdf0e10cSrcweir 		const SvXMLNamespaceMap& rNamespaceMap,
817cdf0e10cSrcweir 		sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx,
818cdf0e10cSrcweir 		sal_uInt16 nFlags ) const
819cdf0e10cSrcweir {
820cdf0e10cSrcweir 	_exportXML( rAttrList, rProperties, rUnitConverter, rNamespaceMap,
821cdf0e10cSrcweir 				nFlags, 0, nPropMapStartIdx, nPropMapEndIdx );
822cdf0e10cSrcweir }
823cdf0e10cSrcweir */
824cdf0e10cSrcweir 
825cdf0e10cSrcweir 
exportXML(SvXMLAttributeList & rAttrList,const XMLPropertyState & rProperty,const SvXMLUnitConverter & rUnitConverter,const SvXMLNamespaceMap & rNamespaceMap,sal_uInt16 nFlags) const826cdf0e10cSrcweir void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList,
827cdf0e10cSrcweir 		const XMLPropertyState& rProperty,
828cdf0e10cSrcweir 		const SvXMLUnitConverter& rUnitConverter,
829cdf0e10cSrcweir 		const SvXMLNamespaceMap& rNamespaceMap,
830cdf0e10cSrcweir 		sal_uInt16 nFlags ) const
831cdf0e10cSrcweir {
832cdf0e10cSrcweir 	if( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
833cdf0e10cSrcweir 				MID_FLAG_ELEMENT_ITEM_EXPORT ) == 0 )
834cdf0e10cSrcweir 		_exportXML( rAttrList, rProperty, rUnitConverter, rNamespaceMap,
835cdf0e10cSrcweir 					nFlags );
836cdf0e10cSrcweir }
837cdf0e10cSrcweir 
exportXML(SvXMLExport & rExport,const::std::vector<XMLPropertyState> & rProperties,sal_uInt16 nFlags) const838cdf0e10cSrcweir void SvXMLExportPropertyMapper::exportXML(
839cdf0e10cSrcweir         SvXMLExport& rExport,
840cdf0e10cSrcweir 		const ::std::vector< XMLPropertyState >& rProperties,
841cdf0e10cSrcweir 		sal_uInt16 nFlags ) const
842cdf0e10cSrcweir {
843cdf0e10cSrcweir 	exportXML( rExport, rProperties, -1, -1,  nFlags );
844cdf0e10cSrcweir }
845cdf0e10cSrcweir 
exportXML(SvXMLExport & rExport,const::std::vector<XMLPropertyState> & rProperties,sal_Int32 nPropMapStartIdx,sal_Int32 nPropMapEndIdx,sal_uInt16 nFlags) const846cdf0e10cSrcweir void SvXMLExportPropertyMapper::exportXML(
847cdf0e10cSrcweir         SvXMLExport& rExport,
848cdf0e10cSrcweir 		const ::std::vector< XMLPropertyState >& rProperties,
849cdf0e10cSrcweir 		sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx,
850cdf0e10cSrcweir 		sal_uInt16 nFlags ) const
851cdf0e10cSrcweir {
852cdf0e10cSrcweir 	sal_uInt16 nPropTypeFlags = 0;
853cdf0e10cSrcweir 	for( sal_uInt16 i=0; i<MAX_PROP_TYPES; ++i )
854cdf0e10cSrcweir 	{
855cdf0e10cSrcweir 		sal_uInt16 nPropType = aPropTokens[i].nType;
856cdf0e10cSrcweir 		if( 0==i || (nPropTypeFlags & (1 << nPropType)) != 0 )
857cdf0e10cSrcweir 		{
858cdf0e10cSrcweir 			SvUShorts aIndexArray;
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 			_exportXML( nPropType, nPropTypeFlags,
861cdf0e10cSrcweir 						rExport.GetAttrList(), rProperties,
862cdf0e10cSrcweir 						rExport.GetMM100UnitConverter(),
863cdf0e10cSrcweir 						rExport.GetNamespaceMap(),
864cdf0e10cSrcweir 						nFlags, &aIndexArray,
865cdf0e10cSrcweir 						nPropMapStartIdx, nPropMapEndIdx );
866cdf0e10cSrcweir 
867cdf0e10cSrcweir 			if( rExport.GetAttrList().getLength() > 0L ||
868cdf0e10cSrcweir 				(nFlags & XML_EXPORT_FLAG_EMPTY) != 0 ||
869cdf0e10cSrcweir 				aIndexArray.Count() != 0 )
870cdf0e10cSrcweir 			{
871cdf0e10cSrcweir 				SvXMLElementExport aElem( rExport, XML_NAMESPACE_STYLE,
872cdf0e10cSrcweir 								  aPropTokens[i].eToken,
873cdf0e10cSrcweir 								  (nFlags & XML_EXPORT_FLAG_IGN_WS) != 0,
874cdf0e10cSrcweir 								  sal_False );
875cdf0e10cSrcweir 
876cdf0e10cSrcweir 				exportElementItems( rExport, rProperties, nFlags, aIndexArray );
877cdf0e10cSrcweir 			}
878cdf0e10cSrcweir 		}
879cdf0e10cSrcweir 	}
880cdf0e10cSrcweir }
881cdf0e10cSrcweir 
882cdf0e10cSrcweir /** this method is called for every item that has the
883cdf0e10cSrcweir     MID_FLAG_SPECIAL_ITEM_EXPORT flag set */
handleSpecialItem(SvXMLAttributeList & rAttrList,const XMLPropertyState & rProperty,const SvXMLUnitConverter & rUnitConverter,const SvXMLNamespaceMap & rNamespaceMap,const::std::vector<XMLPropertyState> * pProperties,sal_uInt32 nIdx) const884cdf0e10cSrcweir void SvXMLExportPropertyMapper::handleSpecialItem(
885cdf0e10cSrcweir 		SvXMLAttributeList& rAttrList,
886cdf0e10cSrcweir 		const XMLPropertyState& rProperty,
887cdf0e10cSrcweir 		const SvXMLUnitConverter& rUnitConverter,
888cdf0e10cSrcweir 		const SvXMLNamespaceMap& rNamespaceMap,
889cdf0e10cSrcweir 		const ::std::vector< XMLPropertyState > *pProperties,
890cdf0e10cSrcweir 		sal_uInt32 nIdx ) const
891cdf0e10cSrcweir {
892cdf0e10cSrcweir 	OSL_ENSURE( mxNextMapper.is(), "special item not handled in xml export" );
893cdf0e10cSrcweir 	if( mxNextMapper.is() )
894cdf0e10cSrcweir 		mxNextMapper->handleSpecialItem( rAttrList, rProperty, rUnitConverter,
895cdf0e10cSrcweir 										rNamespaceMap, pProperties, nIdx );
896cdf0e10cSrcweir }
897cdf0e10cSrcweir 
898cdf0e10cSrcweir /** this method is called for every item that has the
899cdf0e10cSrcweir     MID_FLAG_ELEMENT_EXPORT flag set */
handleElementItem(SvXMLExport & rExport,const XMLPropertyState & rProperty,sal_uInt16 nFlags,const::std::vector<XMLPropertyState> * pProperties,sal_uInt32 nIdx) const900cdf0e10cSrcweir void SvXMLExportPropertyMapper::handleElementItem(
901cdf0e10cSrcweir         SvXMLExport& rExport,
902cdf0e10cSrcweir 		const XMLPropertyState& rProperty,
903cdf0e10cSrcweir 		sal_uInt16 nFlags,
904cdf0e10cSrcweir 		const ::std::vector< XMLPropertyState > *pProperties,
905cdf0e10cSrcweir 		sal_uInt32 nIdx ) const
906cdf0e10cSrcweir {
907cdf0e10cSrcweir 	OSL_ENSURE( mxNextMapper.is(), "element item not handled in xml export" );
908cdf0e10cSrcweir 	if( mxNextMapper.is() )
909cdf0e10cSrcweir 		mxNextMapper->handleElementItem( rExport, rProperty, nFlags,
910cdf0e10cSrcweir                                          pProperties, nIdx );
911cdf0e10cSrcweir }
912cdf0e10cSrcweir 
913cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
914cdf0e10cSrcweir //
915cdf0e10cSrcweir // protected methods
916cdf0e10cSrcweir //
917cdf0e10cSrcweir 
918cdf0e10cSrcweir /** fills the given attribute list with the items in the given set */
_exportXML(sal_uInt16 nPropType,sal_uInt16 & rPropTypeFlags,SvXMLAttributeList & rAttrList,const::std::vector<XMLPropertyState> & rProperties,const SvXMLUnitConverter & rUnitConverter,const SvXMLNamespaceMap & rNamespaceMap,sal_uInt16 nFlags,SvUShorts * pIndexArray,sal_Int32 nPropMapStartIdx,sal_Int32 nPropMapEndIdx) const919cdf0e10cSrcweir void SvXMLExportPropertyMapper::_exportXML(
920cdf0e10cSrcweir 		sal_uInt16 nPropType, sal_uInt16& rPropTypeFlags,
921cdf0e10cSrcweir 		SvXMLAttributeList& rAttrList,
922cdf0e10cSrcweir 		const ::std::vector< XMLPropertyState >& rProperties,
923cdf0e10cSrcweir 		const SvXMLUnitConverter& rUnitConverter,
924cdf0e10cSrcweir 		const SvXMLNamespaceMap& rNamespaceMap,
925cdf0e10cSrcweir 		sal_uInt16 nFlags,
926cdf0e10cSrcweir 		SvUShorts* pIndexArray,
927cdf0e10cSrcweir 		sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx ) const
928cdf0e10cSrcweir {
929cdf0e10cSrcweir 	const sal_uInt32 nCount = rProperties.size();
930cdf0e10cSrcweir 	sal_uInt32 nIndex = 0;
931cdf0e10cSrcweir 
932cdf0e10cSrcweir 	if( -1 == nPropMapStartIdx )
933cdf0e10cSrcweir 		nPropMapStartIdx = 0;
934cdf0e10cSrcweir 	if( -1 == nPropMapEndIdx )
935cdf0e10cSrcweir 		nPropMapEndIdx = maPropMapper->GetEntryCount();
936cdf0e10cSrcweir 
937cdf0e10cSrcweir 	while( nIndex < nCount )
938cdf0e10cSrcweir 	{
939cdf0e10cSrcweir 		sal_Int32 nPropMapIdx = rProperties[nIndex].mnIndex;
940cdf0e10cSrcweir 		if( nPropMapIdx >= nPropMapStartIdx &&
941cdf0e10cSrcweir 			nPropMapIdx < nPropMapEndIdx  )// valid entry?
942cdf0e10cSrcweir 		{
943cdf0e10cSrcweir 			sal_uInt32 nEFlags = maPropMapper->GetEntryFlags( nPropMapIdx );
944cdf0e10cSrcweir 			sal_uInt16 nEPType = GET_PROP_TYPE(nEFlags);
945cdf0e10cSrcweir 			OSL_ENSURE( nEPType >= (XML_TYPE_PROP_START>>XML_TYPE_PROP_SHIFT),
946cdf0e10cSrcweir 						"no prop type sepcified" );
947cdf0e10cSrcweir 			rPropTypeFlags |= (1 << nEPType);
948cdf0e10cSrcweir 			if( nEPType == nPropType )
949cdf0e10cSrcweir 			{
950cdf0e10cSrcweir 				// we have a valid map entry here, so lets use it...
951cdf0e10cSrcweir 				if( ( nEFlags & MID_FLAG_ELEMENT_ITEM_EXPORT ) != 0 )
952cdf0e10cSrcweir 				{
953cdf0e10cSrcweir 					// element items do not add any properties,
954cdf0e10cSrcweir 					// we export it later
955cdf0e10cSrcweir 					if( pIndexArray )
956cdf0e10cSrcweir 						pIndexArray->Insert( (sal_uInt16)nIndex, pIndexArray->Count() );
957cdf0e10cSrcweir 				}
958cdf0e10cSrcweir 				else
959cdf0e10cSrcweir 				{
960cdf0e10cSrcweir 					_exportXML( rAttrList, rProperties[nIndex], rUnitConverter,
961cdf0e10cSrcweir 								rNamespaceMap, nFlags, &rProperties, nIndex );
962cdf0e10cSrcweir 				}
963cdf0e10cSrcweir 			}
964cdf0e10cSrcweir 		}
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 		nIndex++;
967cdf0e10cSrcweir 	}
968cdf0e10cSrcweir }
969cdf0e10cSrcweir 
_exportXML(SvXMLAttributeList & rAttrList,const XMLPropertyState & rProperty,const SvXMLUnitConverter & rUnitConverter,const SvXMLNamespaceMap & rNamespaceMap,sal_uInt16,const::std::vector<XMLPropertyState> * pProperties,sal_uInt32 nIdx) const970cdf0e10cSrcweir void SvXMLExportPropertyMapper::_exportXML(
971cdf0e10cSrcweir 		SvXMLAttributeList& rAttrList,
972cdf0e10cSrcweir 		const XMLPropertyState& rProperty,
973cdf0e10cSrcweir 		const SvXMLUnitConverter& rUnitConverter,
974cdf0e10cSrcweir 		const SvXMLNamespaceMap& rNamespaceMap,
975cdf0e10cSrcweir 		sal_uInt16 /*nFlags*/,
976cdf0e10cSrcweir 		const ::std::vector< XMLPropertyState > *pProperties,
977cdf0e10cSrcweir 		sal_uInt32 nIdx ) const
978cdf0e10cSrcweir {
979cdf0e10cSrcweir 	OUString sCDATA( GetXMLToken(XML_CDATA) );
980cdf0e10cSrcweir 
981cdf0e10cSrcweir 	if ( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
982cdf0e10cSrcweir 				MID_FLAG_SPECIAL_ITEM_EXPORT ) != 0 )
983cdf0e10cSrcweir 	{
984cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xAttrContainer;
985cdf0e10cSrcweir 		if( (rProperty.maValue >>= xAttrContainer) && xAttrContainer.is() )
986cdf0e10cSrcweir 		{
987cdf0e10cSrcweir 			SvXMLNamespaceMap *pNewNamespaceMap = 0;
988cdf0e10cSrcweir 			const SvXMLNamespaceMap *pNamespaceMap = &rNamespaceMap;
989cdf0e10cSrcweir 
990cdf0e10cSrcweir 			uno::Sequence< OUString > aAttribNames( xAttrContainer->getElementNames() );
991cdf0e10cSrcweir 			const OUString* pAttribName = aAttribNames.getConstArray();
992cdf0e10cSrcweir 
993cdf0e10cSrcweir 			const sal_Int32 nCount = aAttribNames.getLength();
994cdf0e10cSrcweir 
995cdf0e10cSrcweir 			OUStringBuffer sNameBuffer;
996cdf0e10cSrcweir 			xml::AttributeData aData;
997cdf0e10cSrcweir 			for( sal_Int32 i=0; i < nCount; i++, pAttribName++ )
998cdf0e10cSrcweir 			{
999cdf0e10cSrcweir 				xAttrContainer->getByName( *pAttribName ) >>= aData;
1000cdf0e10cSrcweir 				OUString sAttribName( *pAttribName );
1001cdf0e10cSrcweir 
1002cdf0e10cSrcweir 				// extract namespace prefix from attribute name if it exists
1003cdf0e10cSrcweir 				OUString sPrefix;
1004cdf0e10cSrcweir 				const sal_Int32 nColonPos =
1005cdf0e10cSrcweir 					pAttribName->indexOf( sal_Unicode(':') );
1006cdf0e10cSrcweir 				if( nColonPos != -1 )
1007cdf0e10cSrcweir 					sPrefix = pAttribName->copy( 0, nColonPos );
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir 				if( sPrefix.getLength() )
1010cdf0e10cSrcweir 				{
1011cdf0e10cSrcweir 					OUString sNamespace( aData.Namespace );
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir 					// if the prefix isn't defined yet or has another meaning,
1014cdf0e10cSrcweir 					// we have to redefine it now.
1015cdf0e10cSrcweir 					sal_uInt16 nKey = pNamespaceMap->GetKeyByPrefix( sPrefix );
1016cdf0e10cSrcweir 					if( USHRT_MAX == nKey || pNamespaceMap->GetNameByKey( nKey ) != sNamespace )
1017cdf0e10cSrcweir 					{
1018cdf0e10cSrcweir 						sal_Bool bAddNamespace = sal_False;
1019cdf0e10cSrcweir 						if( USHRT_MAX == nKey )
1020cdf0e10cSrcweir 						{
1021cdf0e10cSrcweir 							// The prefix is unused, so it is sufficient
1022cdf0e10cSrcweir 							// to add it to the namespace map.
1023cdf0e10cSrcweir 							bAddNamespace = sal_True;
1024cdf0e10cSrcweir 						}
1025cdf0e10cSrcweir 						else
1026cdf0e10cSrcweir 						{
1027cdf0e10cSrcweir 							// check if there is a prefix registered for the
1028cdf0e10cSrcweir 							// namepsace URI
1029cdf0e10cSrcweir 							nKey = pNamespaceMap->GetKeyByName( sNamespace );
1030cdf0e10cSrcweir 							if( XML_NAMESPACE_UNKNOWN == nKey )
1031cdf0e10cSrcweir 							{
1032cdf0e10cSrcweir 								// There is no prefix for the namespace, so
1033cdf0e10cSrcweir 								// we have to generate one and have to add it.
1034cdf0e10cSrcweir 								sal_Int32 n=0;
1035cdf0e10cSrcweir 								OUString sOrigPrefix( sPrefix );
1036cdf0e10cSrcweir 								do
1037cdf0e10cSrcweir 								{
1038cdf0e10cSrcweir 									sNameBuffer.append( sOrigPrefix );
1039cdf0e10cSrcweir 									sNameBuffer.append( ++n );
1040cdf0e10cSrcweir 									sPrefix = sNameBuffer.makeStringAndClear();
1041cdf0e10cSrcweir 									nKey = pNamespaceMap->GetKeyByPrefix( sPrefix );
1042cdf0e10cSrcweir 								}
1043cdf0e10cSrcweir 								while( nKey != USHRT_MAX );
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir 								bAddNamespace = sal_True;
1046cdf0e10cSrcweir 							}
1047cdf0e10cSrcweir 							else
1048cdf0e10cSrcweir 							{
1049cdf0e10cSrcweir 								// If there is a prefix for the namespace,
1050cdf0e10cSrcweir 								// we reuse that.
1051cdf0e10cSrcweir 								sPrefix = pNamespaceMap->GetPrefixByKey( nKey );
1052cdf0e10cSrcweir 							}
1053cdf0e10cSrcweir 							// In any case, the attribute name has to be adapted.
1054cdf0e10cSrcweir 							sNameBuffer.append( sPrefix );
1055cdf0e10cSrcweir 							sNameBuffer.append( sal_Unicode(':') );
1056cdf0e10cSrcweir 							sNameBuffer.append( pAttribName->copy( nColonPos+1 ) );
1057cdf0e10cSrcweir 							sAttribName = sNameBuffer.makeStringAndClear();
1058cdf0e10cSrcweir 						}
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir 						if( bAddNamespace )
1061cdf0e10cSrcweir 						{
1062cdf0e10cSrcweir 							if( !pNewNamespaceMap )
1063cdf0e10cSrcweir 							{
1064cdf0e10cSrcweir 								pNewNamespaceMap = new SvXMLNamespaceMap( rNamespaceMap );
1065cdf0e10cSrcweir 								pNamespaceMap = pNewNamespaceMap;
1066cdf0e10cSrcweir 							}
1067cdf0e10cSrcweir 							pNewNamespaceMap->Add( sPrefix, sNamespace );
1068cdf0e10cSrcweir 							sNameBuffer.append( GetXMLToken(XML_XMLNS) );
1069cdf0e10cSrcweir 							sNameBuffer.append( sal_Unicode(':') );
1070cdf0e10cSrcweir 							sNameBuffer.append( sPrefix );
1071cdf0e10cSrcweir 							rAttrList.AddAttribute( sNameBuffer.makeStringAndClear(),
1072cdf0e10cSrcweir 													sNamespace );
1073cdf0e10cSrcweir 						}
1074cdf0e10cSrcweir 					}
1075cdf0e10cSrcweir 				}
1076cdf0e10cSrcweir 				OUString sOldValue( rAttrList.getValueByName( sAttribName ) );
1077cdf0e10cSrcweir 				OSL_ENSURE( sOldValue.getLength() == 0, "alien attribute exists already" );
1078cdf0e10cSrcweir                 OSL_ENSURE(aData.Type == GetXMLToken(XML_CDATA), "different type to our default type which should be written out");
1079cdf0e10cSrcweir 				if( !sOldValue.getLength() )
1080cdf0e10cSrcweir 					rAttrList.AddAttribute( sAttribName, aData.Value );
1081cdf0e10cSrcweir 			}
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir 			delete pNewNamespaceMap;
1084cdf0e10cSrcweir 		}
1085cdf0e10cSrcweir 		else
1086cdf0e10cSrcweir 		{
1087cdf0e10cSrcweir 			handleSpecialItem( rAttrList, rProperty, rUnitConverter,
1088cdf0e10cSrcweir 							   rNamespaceMap, pProperties, nIdx );
1089cdf0e10cSrcweir 		}
1090cdf0e10cSrcweir 	}
1091cdf0e10cSrcweir 	else if ( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
1092cdf0e10cSrcweir 					MID_FLAG_ELEMENT_ITEM_EXPORT ) == 0 )
1093cdf0e10cSrcweir 	{
1094cdf0e10cSrcweir 		OUString aValue;
1095cdf0e10cSrcweir 		const OUString sName( rNamespaceMap.GetQNameByKey(
1096cdf0e10cSrcweir 					maPropMapper->GetEntryNameSpace( rProperty.mnIndex ),
1097cdf0e10cSrcweir 				    maPropMapper->GetEntryXMLName( rProperty.mnIndex ) ) );
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir 		sal_Bool bRemove = sal_False;
1100cdf0e10cSrcweir 		if( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
1101cdf0e10cSrcweir 					MID_FLAG_MERGE_ATTRIBUTE ) != 0 )
1102cdf0e10cSrcweir 		{
1103cdf0e10cSrcweir 			aValue = rAttrList.getValueByName( sName );
1104cdf0e10cSrcweir 			bRemove = sal_True; //aValue.getLength() != 0;
1105cdf0e10cSrcweir 		}
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir 		if( maPropMapper->exportXML( aValue, rProperty, rUnitConverter ) )
1108cdf0e10cSrcweir 		{
1109cdf0e10cSrcweir 			if( bRemove )
1110cdf0e10cSrcweir 				rAttrList.RemoveAttribute( sName );
1111cdf0e10cSrcweir 			rAttrList.AddAttribute( sName, aValue );
1112cdf0e10cSrcweir 		}
1113cdf0e10cSrcweir 	}
1114cdf0e10cSrcweir }
1115cdf0e10cSrcweir 
exportElementItems(SvXMLExport & rExport,const::std::vector<XMLPropertyState> & rProperties,sal_uInt16 nFlags,const SvUShorts & rIndexArray) const1116cdf0e10cSrcweir void SvXMLExportPropertyMapper::exportElementItems(
1117cdf0e10cSrcweir         SvXMLExport& rExport,
1118cdf0e10cSrcweir 		const ::std::vector< XMLPropertyState >& rProperties,
1119cdf0e10cSrcweir 		sal_uInt16 nFlags,
1120cdf0e10cSrcweir 		const SvUShorts& rIndexArray ) const
1121cdf0e10cSrcweir {
1122cdf0e10cSrcweir 	const sal_uInt16 nCount = rIndexArray.Count();
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir 	sal_Bool bItemsExported = sal_False;
1125cdf0e10cSrcweir 	OUString sWS( GetXMLToken(XML_WS) );
1126cdf0e10cSrcweir 	for( sal_uInt16 nIndex = 0; nIndex < nCount; nIndex++ )
1127cdf0e10cSrcweir 	{
1128cdf0e10cSrcweir 		const sal_uInt16 nElement = rIndexArray.GetObject( nIndex );
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 		OSL_ENSURE( 0 != ( maPropMapper->GetEntryFlags(
1131cdf0e10cSrcweir 				rProperties[nElement].mnIndex ) & MID_FLAG_ELEMENT_ITEM_EXPORT),
1132cdf0e10cSrcweir 				"wrong mid flag!" );
1133cdf0e10cSrcweir 
1134cdf0e10cSrcweir 		rExport.IgnorableWhitespace();
1135cdf0e10cSrcweir 		handleElementItem( rExport, rProperties[nElement],
1136cdf0e10cSrcweir                            nFlags, &rProperties, nElement );
1137cdf0e10cSrcweir 		bItemsExported = sal_True;
1138cdf0e10cSrcweir 	}
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir 	if( bItemsExported )
1141cdf0e10cSrcweir 		rExport.IgnorableWhitespace();
1142cdf0e10cSrcweir }
1143