xref: /aoo42x/main/xmloff/source/style/xmlprmap.cxx (revision 56b35d86)
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 <tools/debug.hxx>
27cdf0e10cSrcweir #include <xmloff/xmlprhdl.hxx>
28cdf0e10cSrcweir #include "xmlbahdl.hxx"
29cdf0e10cSrcweir #include <xmloff/xmlprmap.hxx>
30cdf0e10cSrcweir #include <xmloff/xmltypes.hxx>
31cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
33cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
34cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::std;
38cdf0e10cSrcweir using ::rtl::OUString;
39cdf0e10cSrcweir using ::rtl::OUStringBuffer;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir using namespace ::com::sun::star::beans;
43cdf0e10cSrcweir using ::xmloff::token::GetXMLToken;
44cdf0e10cSrcweir 
XMLPropertySetMapperEntry_Impl(const XMLPropertyMapEntry & rMapEntry,const UniReference<XMLPropertyHandlerFactory> & rFactory)45cdf0e10cSrcweir XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
46cdf0e10cSrcweir 	const XMLPropertyMapEntry& rMapEntry,
47cdf0e10cSrcweir 	const UniReference< XMLPropertyHandlerFactory >& rFactory ) :
48cdf0e10cSrcweir 	sXMLAttributeName( GetXMLToken(rMapEntry.meXMLName) ),
49cdf0e10cSrcweir 	sAPIPropertyName( OUString(rMapEntry.msApiName, rMapEntry.nApiNameLength,
50cdf0e10cSrcweir                                RTL_TEXTENCODING_ASCII_US ) ),
51cdf0e10cSrcweir 	nXMLNameSpace( rMapEntry.mnNameSpace ),
52cdf0e10cSrcweir 	nType( rMapEntry.mnType ),
53cdf0e10cSrcweir 	nContextId( rMapEntry.mnContextId ),
54cdf0e10cSrcweir     nEarliestODFVersionForExport( rMapEntry.mnEarliestODFVersionForExport ),
55cdf0e10cSrcweir 	pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
XMLPropertySetMapperEntry_Impl(const XMLPropertySetMapperEntry_Impl & rEntry)59cdf0e10cSrcweir XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
60cdf0e10cSrcweir 		const XMLPropertySetMapperEntry_Impl& rEntry ) :
61cdf0e10cSrcweir 	sXMLAttributeName( rEntry.sXMLAttributeName),
62cdf0e10cSrcweir 	sAPIPropertyName( rEntry.sAPIPropertyName),
63cdf0e10cSrcweir 	nXMLNameSpace( rEntry.nXMLNameSpace),
64cdf0e10cSrcweir 	nType( rEntry.nType),
65cdf0e10cSrcweir 	nContextId( rEntry.nContextId),
66cdf0e10cSrcweir     nEarliestODFVersionForExport( rEntry.nEarliestODFVersionForExport ),
67cdf0e10cSrcweir 	pHdl( rEntry.pHdl)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	DBG_ASSERT( pHdl, "Unknown XML property type handler!" );
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
73cdf0e10cSrcweir //
74cdf0e10cSrcweir // Ctor
75cdf0e10cSrcweir //
XMLPropertySetMapper(const XMLPropertyMapEntry * pEntries,const UniReference<XMLPropertyHandlerFactory> & rFactory)76cdf0e10cSrcweir XMLPropertySetMapper::XMLPropertySetMapper(
77cdf0e10cSrcweir 		const XMLPropertyMapEntry* pEntries,
78cdf0e10cSrcweir 		const UniReference< XMLPropertyHandlerFactory >& rFactory )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	aHdlFactories.push_back( rFactory );
81cdf0e10cSrcweir 	if( pEntries )
82cdf0e10cSrcweir 	{
83cdf0e10cSrcweir 		const XMLPropertyMapEntry* pIter = pEntries;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 		// count entries
86cdf0e10cSrcweir 		while( pIter->msApiName )
87cdf0e10cSrcweir 		{
88cdf0e10cSrcweir 			XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
89cdf0e10cSrcweir 			aMapEntries.push_back( aEntry );
90cdf0e10cSrcweir 			pIter++;
91cdf0e10cSrcweir 		}
92cdf0e10cSrcweir 	}
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
~XMLPropertySetMapper()95cdf0e10cSrcweir XMLPropertySetMapper::~XMLPropertySetMapper()
96cdf0e10cSrcweir {
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
AddMapperEntry(const UniReference<XMLPropertySetMapper> & rMapper)99cdf0e10cSrcweir void XMLPropertySetMapper::AddMapperEntry(
100cdf0e10cSrcweir 	const UniReference < XMLPropertySetMapper >& rMapper )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator
103cdf0e10cSrcweir 			aFIter = rMapper->aHdlFactories.begin();
104cdf0e10cSrcweir 		 aFIter != rMapper->aHdlFactories.end();
105cdf0e10cSrcweir 		 aFIter++ )
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		aHdlFactories.push_back( *aFIter );
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	for( vector < XMLPropertySetMapperEntry_Impl >::iterator
111cdf0e10cSrcweir 			aEIter = rMapper->aMapEntries.begin();
112cdf0e10cSrcweir 		 aEIter != rMapper->aMapEntries.end();
113cdf0e10cSrcweir 		 aEIter++ )
114cdf0e10cSrcweir 	{
115cdf0e10cSrcweir 		aMapEntries.push_back( *aEIter );
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
120cdf0e10cSrcweir //
121cdf0e10cSrcweir // Export a Property
122cdf0e10cSrcweir //
exportXML(OUString & rStrExpValue,const XMLPropertyState & rProperty,const SvXMLUnitConverter & rUnitConverter) const123cdf0e10cSrcweir sal_Bool XMLPropertySetMapper::exportXML(
124cdf0e10cSrcweir 		OUString& rStrExpValue,
125cdf0e10cSrcweir 		const XMLPropertyState& rProperty,
126cdf0e10cSrcweir 		const SvXMLUnitConverter& rUnitConverter ) const
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	DBG_ASSERT( pHdl, "Unknown XML Type!" );
133cdf0e10cSrcweir 	if( pHdl )
134cdf0e10cSrcweir 		bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue,
135cdf0e10cSrcweir 								rUnitConverter );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	return bRet;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
141cdf0e10cSrcweir //
142cdf0e10cSrcweir // Import a Property
143cdf0e10cSrcweir //
importXML(const OUString & rStrImpValue,XMLPropertyState & rProperty,const SvXMLUnitConverter & rUnitConverter) const144cdf0e10cSrcweir sal_Bool XMLPropertySetMapper::importXML(
145cdf0e10cSrcweir 		const OUString& rStrImpValue,
146cdf0e10cSrcweir 		XMLPropertyState& rProperty,
147cdf0e10cSrcweir 		const SvXMLUnitConverter& rUnitConverter ) const
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	if( pHdl )
154cdf0e10cSrcweir 		bRet = pHdl->importXML( rStrImpValue, rProperty.maValue,
155cdf0e10cSrcweir 								rUnitConverter );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	return bRet;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
161cdf0e10cSrcweir //
162cdf0e10cSrcweir // Search for the given name and the namespace in the list and return
163cdf0e10cSrcweir // the index of the entry
164cdf0e10cSrcweir // If there is no matching entry the method returns -1
165cdf0e10cSrcweir //
GetEntryIndex(sal_uInt16 nNamespace,const OUString & rStrName,sal_uInt32 nPropType,sal_Int32 nStartAt) const166cdf0e10cSrcweir sal_Int32 XMLPropertySetMapper::GetEntryIndex(
167cdf0e10cSrcweir 		sal_uInt16 nNamespace,
168cdf0e10cSrcweir 		const OUString& rStrName,
169cdf0e10cSrcweir 		sal_uInt32 nPropType,
170cdf0e10cSrcweir 		sal_Int32 nStartAt /* = -1 */ ) const
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	sal_Int32 nEntries = GetEntryCount();
173cdf0e10cSrcweir 	sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1;
174cdf0e10cSrcweir 
175*56b35d86SArmin Le Grand     if ( nEntries && nIndex < nEntries )
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir 	    do
178cdf0e10cSrcweir 	    {
179cdf0e10cSrcweir 		    const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
180cdf0e10cSrcweir 		    if( (!nPropType || nPropType == rEntry.GetPropType()) &&
181cdf0e10cSrcweir 			    rEntry.nXMLNameSpace == nNamespace &&
182cdf0e10cSrcweir 			    rStrName == rEntry.sXMLAttributeName )
183cdf0e10cSrcweir 			    return nIndex;
184cdf0e10cSrcweir 		    else
185cdf0e10cSrcweir 			    nIndex++;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 	    } while( nIndex<nEntries );
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	return -1;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 
194cdf0e10cSrcweir /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
FindEntryIndex(const sal_Char * sApiName,sal_uInt16 nNameSpace,const OUString & sXMLName) const195cdf0e10cSrcweir sal_Int32 XMLPropertySetMapper::FindEntryIndex(
196cdf0e10cSrcweir 		const sal_Char* sApiName,
197cdf0e10cSrcweir 		sal_uInt16 nNameSpace,
198cdf0e10cSrcweir 		const OUString& sXMLName ) const
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	sal_Int32 nIndex = 0;
201cdf0e10cSrcweir 	sal_Int32 nEntries = GetEntryCount();
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 	do
204cdf0e10cSrcweir 	{
205cdf0e10cSrcweir 		const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
206cdf0e10cSrcweir 		if( rEntry.nXMLNameSpace == nNameSpace &&
207cdf0e10cSrcweir 			rEntry.sXMLAttributeName.equals( sXMLName ) &&
208cdf0e10cSrcweir 			0 == rEntry.sAPIPropertyName.compareToAscii( sApiName ) )
209cdf0e10cSrcweir 			return nIndex;
210cdf0e10cSrcweir 		else
211cdf0e10cSrcweir 			nIndex++;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 	} while( nIndex < nEntries );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 	return -1;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
FindEntryIndex(const sal_Int16 nContextId) const218cdf0e10cSrcweir sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	sal_Int32 nIndex = 0;
221cdf0e10cSrcweir 	const sal_Int32 nEntries = GetEntryCount();
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     if ( nEntries )
224cdf0e10cSrcweir     {
225cdf0e10cSrcweir 	    do
226cdf0e10cSrcweir 	    {
227cdf0e10cSrcweir 		    const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
228cdf0e10cSrcweir 		    if( rEntry.nContextId == nContextId )
229cdf0e10cSrcweir 			    return nIndex;
230cdf0e10cSrcweir 		    else
231cdf0e10cSrcweir 			    nIndex++;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	    } while( nIndex < nEntries );
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	return -1;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
RemoveEntry(sal_Int32 nIndex)239cdf0e10cSrcweir void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     const sal_Int32 nEntries = GetEntryCount();
242cdf0e10cSrcweir     if( nIndex>=nEntries || nIndex<0 )
243cdf0e10cSrcweir         return;
244cdf0e10cSrcweir     vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin();
245cdf0e10cSrcweir     for( sal_Int32 nN=0; nN<nIndex; nN++ )
246cdf0e10cSrcweir         aEIter++;
247cdf0e10cSrcweir     aMapEntries.erase( aEIter );
248cdf0e10cSrcweir }
249