merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / style / xmlprmap.cxx
blob6fbb674697539c589c1e174299759c6712a1d5a9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlprmap.cxx,v $
10 * $Revision: 1.13.74.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <tools/debug.hxx>
34 #include <xmloff/xmlprhdl.hxx>
35 #include "xmlbahdl.hxx"
36 #include <xmloff/xmlprmap.hxx>
37 #include <xmloff/xmltypes.hxx>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/beans/XPropertyState.hpp>
40 #include <com/sun/star/uno/Any.hxx>
41 #include <xmloff/xmltoken.hxx>
44 using namespace ::std;
45 using ::rtl::OUString;
46 using ::rtl::OUStringBuffer;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::beans;
50 using ::xmloff::token::GetXMLToken;
52 XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
53 const XMLPropertyMapEntry& rMapEntry,
54 const UniReference< XMLPropertyHandlerFactory >& rFactory ) :
55 sXMLAttributeName( GetXMLToken(rMapEntry.meXMLName) ),
56 sAPIPropertyName( OUString(rMapEntry.msApiName, rMapEntry.nApiNameLength,
57 RTL_TEXTENCODING_ASCII_US ) ),
58 nXMLNameSpace( rMapEntry.mnNameSpace ),
59 nType( rMapEntry.mnType ),
60 nContextId( rMapEntry.mnContextId ),
61 nEarliestODFVersionForExport( rMapEntry.mnEarliestODFVersionForExport ),
62 pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) )
66 XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
67 const XMLPropertySetMapperEntry_Impl& rEntry ) :
68 sXMLAttributeName( rEntry.sXMLAttributeName),
69 sAPIPropertyName( rEntry.sAPIPropertyName),
70 nXMLNameSpace( rEntry.nXMLNameSpace),
71 nType( rEntry.nType),
72 nContextId( rEntry.nContextId),
73 nEarliestODFVersionForExport( rEntry.nEarliestODFVersionForExport ),
74 pHdl( rEntry.pHdl)
76 DBG_ASSERT( pHdl, "Unknown XML property type handler!" );
79 ///////////////////////////////////////////////////////////////////////////
81 // Ctor
83 XMLPropertySetMapper::XMLPropertySetMapper(
84 const XMLPropertyMapEntry* pEntries,
85 const UniReference< XMLPropertyHandlerFactory >& rFactory )
87 aHdlFactories.push_back( rFactory );
88 if( pEntries )
90 const XMLPropertyMapEntry* pIter = pEntries;
92 // count entries
93 while( pIter->msApiName )
95 XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
96 aMapEntries.push_back( aEntry );
97 pIter++;
102 XMLPropertySetMapper::~XMLPropertySetMapper()
106 void XMLPropertySetMapper::AddMapperEntry(
107 const UniReference < XMLPropertySetMapper >& rMapper )
109 for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator
110 aFIter = rMapper->aHdlFactories.begin();
111 aFIter != rMapper->aHdlFactories.end();
112 aFIter++ )
114 aHdlFactories.push_back( *aFIter );
117 for( vector < XMLPropertySetMapperEntry_Impl >::iterator
118 aEIter = rMapper->aMapEntries.begin();
119 aEIter != rMapper->aMapEntries.end();
120 aEIter++ )
122 aMapEntries.push_back( *aEIter );
126 ///////////////////////////////////////////////////////////////////////////
128 // Export a Property
130 sal_Bool XMLPropertySetMapper::exportXML(
131 OUString& rStrExpValue,
132 const XMLPropertyState& rProperty,
133 const SvXMLUnitConverter& rUnitConverter ) const
135 sal_Bool bRet = sal_False;
137 const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
139 DBG_ASSERT( pHdl, "Unknown XML Type!" );
140 if( pHdl )
141 bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue,
142 rUnitConverter );
144 return bRet;
147 ///////////////////////////////////////////////////////////////////////////
149 // Import a Property
151 sal_Bool XMLPropertySetMapper::importXML(
152 const OUString& rStrImpValue,
153 XMLPropertyState& rProperty,
154 const SvXMLUnitConverter& rUnitConverter ) const
156 sal_Bool bRet = sal_False;
158 const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
160 if( pHdl )
161 bRet = pHdl->importXML( rStrImpValue, rProperty.maValue,
162 rUnitConverter );
164 return bRet;
167 ///////////////////////////////////////////////////////////////////////////
169 // Search for the given name and the namespace in the list and return
170 // the index of the entry
171 // If there is no matching entry the method returns -1
173 sal_Int32 XMLPropertySetMapper::GetEntryIndex(
174 sal_uInt16 nNamespace,
175 const OUString& rStrName,
176 sal_uInt32 nPropType,
177 sal_Int32 nStartAt /* = -1 */ ) const
179 sal_Int32 nEntries = GetEntryCount();
180 sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1;
182 if ( nEntries )
186 const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
187 if( (!nPropType || nPropType == rEntry.GetPropType()) &&
188 rEntry.nXMLNameSpace == nNamespace &&
189 rStrName == rEntry.sXMLAttributeName )
190 return nIndex;
191 else
192 nIndex++;
194 } while( nIndex<nEntries );
197 return -1;
201 /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
202 sal_Int32 XMLPropertySetMapper::FindEntryIndex(
203 const sal_Char* sApiName,
204 sal_uInt16 nNameSpace,
205 const OUString& sXMLName ) const
207 sal_Int32 nIndex = 0;
208 sal_Int32 nEntries = GetEntryCount();
212 const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
213 if( rEntry.nXMLNameSpace == nNameSpace &&
214 rEntry.sXMLAttributeName.equals( sXMLName ) &&
215 0 == rEntry.sAPIPropertyName.compareToAscii( sApiName ) )
216 return nIndex;
217 else
218 nIndex++;
220 } while( nIndex < nEntries );
222 return -1;
225 sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const
227 sal_Int32 nIndex = 0;
228 const sal_Int32 nEntries = GetEntryCount();
230 if ( nEntries )
234 const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
235 if( rEntry.nContextId == nContextId )
236 return nIndex;
237 else
238 nIndex++;
240 } while( nIndex < nEntries );
243 return -1;
246 void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex )
248 const sal_Int32 nEntries = GetEntryCount();
249 if( nIndex>=nEntries || nIndex<0 )
250 return;
251 vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin();
252 for( sal_Int32 nN=0; nN<nIndex; nN++ )
253 aEIter++;
254 aMapEntries.erase( aEIter );