Bump for 3.6-28
[LibreOffice.git] / xmloff / source / style / xmlprmap.cxx
blob3b19a7a596206863db13c6f93704fcaa795e7db1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <tools/debug.hxx>
30 #include <xmloff/xmlprhdl.hxx>
31 #include "xmlbahdl.hxx"
32 #include <xmloff/xmlprmap.hxx>
33 #include <xmloff/xmltypes.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/beans/XPropertyState.hpp>
36 #include <com/sun/star/uno/Any.hxx>
37 #include <xmloff/xmltoken.hxx>
40 using namespace ::std;
41 using ::rtl::OUString;
42 using ::rtl::OUStringBuffer;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::beans;
46 using ::xmloff::token::GetXMLToken;
48 XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
49 const XMLPropertyMapEntry& rMapEntry,
50 const UniReference< XMLPropertyHandlerFactory >& rFactory ) :
51 sXMLAttributeName( GetXMLToken(rMapEntry.meXMLName) ),
52 sAPIPropertyName( OUString(rMapEntry.msApiName, rMapEntry.nApiNameLength,
53 RTL_TEXTENCODING_ASCII_US ) ),
54 nXMLNameSpace( rMapEntry.mnNameSpace ),
55 nType( rMapEntry.mnType ),
56 nContextId( rMapEntry.mnContextId ),
57 nEarliestODFVersionForExport( rMapEntry.mnEarliestODFVersionForExport ),
58 pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) )
62 XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
63 const XMLPropertySetMapperEntry_Impl& rEntry ) :
64 sXMLAttributeName( rEntry.sXMLAttributeName),
65 sAPIPropertyName( rEntry.sAPIPropertyName),
66 nXMLNameSpace( rEntry.nXMLNameSpace),
67 nType( rEntry.nType),
68 nContextId( rEntry.nContextId),
69 nEarliestODFVersionForExport( rEntry.nEarliestODFVersionForExport ),
70 pHdl( rEntry.pHdl)
72 DBG_ASSERT( pHdl, "Unknown XML property type handler!" );
75 ///////////////////////////////////////////////////////////////////////////
77 // Ctor
79 XMLPropertySetMapper::XMLPropertySetMapper(
80 const XMLPropertyMapEntry* pEntries,
81 const UniReference< XMLPropertyHandlerFactory >& rFactory )
83 aHdlFactories.push_back( rFactory );
84 if( pEntries )
86 const XMLPropertyMapEntry* pIter = pEntries;
88 // count entries
89 while( pIter->msApiName )
91 XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
92 aMapEntries.push_back( aEntry );
93 pIter++;
98 XMLPropertySetMapper::~XMLPropertySetMapper()
102 void XMLPropertySetMapper::AddMapperEntry(
103 const UniReference < XMLPropertySetMapper >& rMapper )
105 for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator
106 aFIter = rMapper->aHdlFactories.begin();
107 aFIter != rMapper->aHdlFactories.end();
108 ++aFIter )
110 aHdlFactories.push_back( *aFIter );
113 for( vector < XMLPropertySetMapperEntry_Impl >::iterator
114 aEIter = rMapper->aMapEntries.begin();
115 aEIter != rMapper->aMapEntries.end();
116 ++aEIter )
118 aMapEntries.push_back( *aEIter );
122 ///////////////////////////////////////////////////////////////////////////
124 // Export a Property
126 sal_Bool XMLPropertySetMapper::exportXML(
127 OUString& rStrExpValue,
128 const XMLPropertyState& rProperty,
129 const SvXMLUnitConverter& rUnitConverter ) const
131 sal_Bool bRet = sal_False;
133 const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
135 DBG_ASSERT( pHdl, "Unknown XML Type!" );
136 if( pHdl )
137 bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue,
138 rUnitConverter );
140 return bRet;
143 ///////////////////////////////////////////////////////////////////////////
145 // Import a Property
147 sal_Bool XMLPropertySetMapper::importXML(
148 const OUString& rStrImpValue,
149 XMLPropertyState& rProperty,
150 const SvXMLUnitConverter& rUnitConverter ) const
152 sal_Bool bRet = sal_False;
154 const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
156 if( pHdl )
157 bRet = pHdl->importXML( rStrImpValue, rProperty.maValue,
158 rUnitConverter );
160 return bRet;
163 ///////////////////////////////////////////////////////////////////////////
165 // Search for the given name and the namespace in the list and return
166 // the index of the entry
167 // If there is no matching entry the method returns -1
169 sal_Int32 XMLPropertySetMapper::GetEntryIndex(
170 sal_uInt16 nNamespace,
171 const OUString& rStrName,
172 sal_uInt32 nPropType,
173 sal_Int32 nStartAt /* = -1 */ ) const
175 sal_Int32 nEntries = GetEntryCount();
176 sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1;
178 if ( nEntries )
182 const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
183 if( (!nPropType || nPropType == rEntry.GetPropType()) &&
184 rEntry.nXMLNameSpace == nNamespace &&
185 rStrName == rEntry.sXMLAttributeName )
186 return nIndex;
187 else
188 nIndex++;
190 } while( nIndex<nEntries );
193 return -1;
197 /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
198 sal_Int32 XMLPropertySetMapper::FindEntryIndex(
199 const sal_Char* sApiName,
200 sal_uInt16 nNameSpace,
201 const OUString& sXMLName ) const
203 sal_Int32 nIndex = 0;
204 sal_Int32 nEntries = GetEntryCount();
208 const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
209 if( rEntry.nXMLNameSpace == nNameSpace &&
210 rEntry.sXMLAttributeName.equals( sXMLName ) &&
211 0 == rEntry.sAPIPropertyName.compareToAscii( sApiName ) )
212 return nIndex;
213 else
214 nIndex++;
216 } while( nIndex < nEntries );
218 return -1;
221 sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const
223 const sal_Int32 nEntries = GetEntryCount();
225 if ( nEntries )
227 sal_Int32 nIndex = 0;
230 const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
231 if( rEntry.nContextId == nContextId )
232 return nIndex;
233 else
234 nIndex++;
236 } while( nIndex < nEntries );
239 return -1;
242 void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex )
244 const sal_Int32 nEntries = GetEntryCount();
245 if( nIndex>=nEntries || nIndex<0 )
246 return;
247 vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin();
248 for( sal_Int32 nN=0; nN<nIndex; nN++ )
249 ++aEIter;
250 aMapEntries.erase( aEIter );
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */