fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / style / xmlprmap.cxx
blob1ea9a6f913fec47d9e1655217139341d2401a7e9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
21 #include <xmloff/xmlprhdl.hxx>
22 #include "xmlbahdl.hxx"
23 #include <xmloff/xmlprmap.hxx>
24 #include <xmloff/xmltypes.hxx>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/beans/XPropertyState.hpp>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <xmloff/xmltoken.hxx>
31 using namespace ::std;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 using ::xmloff::token::GetXMLToken;
37 XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
38 const XMLPropertyMapEntry& rMapEntry,
39 const UniReference< XMLPropertyHandlerFactory >& rFactory ) :
40 sXMLAttributeName( GetXMLToken(rMapEntry.meXMLName) ),
41 sAPIPropertyName( OUString(rMapEntry.msApiName, rMapEntry.nApiNameLength,
42 RTL_TEXTENCODING_ASCII_US ) ),
43 nType( rMapEntry.mnType ),
44 nXMLNameSpace( rMapEntry.mnNameSpace ),
45 nContextId( rMapEntry.mnContextId ),
46 nEarliestODFVersionForExport( rMapEntry.mnEarliestODFVersionForExport ),
47 bImportOnly( rMapEntry.mbImportOnly),
48 pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) )
52 XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl(
53 const XMLPropertySetMapperEntry_Impl& rEntry ) :
54 sXMLAttributeName( rEntry.sXMLAttributeName),
55 sAPIPropertyName( rEntry.sAPIPropertyName),
56 nType( rEntry.nType),
57 nXMLNameSpace( rEntry.nXMLNameSpace),
58 nContextId( rEntry.nContextId),
59 nEarliestODFVersionForExport( rEntry.nEarliestODFVersionForExport ),
60 bImportOnly( rEntry.bImportOnly),
61 pHdl( rEntry.pHdl)
63 DBG_ASSERT( pHdl, "Unknown XML property type handler!" );
66 ///////////////////////////////////////////////////////////////////////////
68 // Ctor
70 XMLPropertySetMapper::XMLPropertySetMapper(
71 const XMLPropertyMapEntry* pEntries,
72 const UniReference< XMLPropertyHandlerFactory >& rFactory,
73 bool bForExport )
75 mbOnlyExportMappings( bForExport)
77 aHdlFactories.push_back( rFactory );
78 if( pEntries )
80 const XMLPropertyMapEntry* pIter = pEntries;
82 if (mbOnlyExportMappings)
84 while( pIter->msApiName )
86 if (!pIter->mbImportOnly)
88 XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
89 aMapEntries.push_back( aEntry );
91 pIter++;
94 else
96 while( pIter->msApiName )
98 XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory );
99 aMapEntries.push_back( aEntry );
100 pIter++;
106 XMLPropertySetMapper::~XMLPropertySetMapper()
110 void XMLPropertySetMapper::AddMapperEntry(
111 const UniReference < XMLPropertySetMapper >& rMapper )
113 for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator
114 aFIter = rMapper->aHdlFactories.begin();
115 aFIter != rMapper->aHdlFactories.end();
116 ++aFIter )
118 aHdlFactories.push_back( *aFIter );
121 for( vector < XMLPropertySetMapperEntry_Impl >::iterator
122 aEIter = rMapper->aMapEntries.begin();
123 aEIter != rMapper->aMapEntries.end();
124 ++aEIter )
126 if (!mbOnlyExportMappings || !(*aEIter).bImportOnly)
127 aMapEntries.push_back( *aEIter );
131 ///////////////////////////////////////////////////////////////////////////
133 // Export a Property
135 sal_Bool XMLPropertySetMapper::exportXML(
136 OUString& rStrExpValue,
137 const XMLPropertyState& rProperty,
138 const SvXMLUnitConverter& rUnitConverter ) const
140 sal_Bool bRet = sal_False;
142 const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
144 DBG_ASSERT( pHdl, "Unknown XML Type!" );
145 if( pHdl )
146 bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue,
147 rUnitConverter );
149 return bRet;
152 ///////////////////////////////////////////////////////////////////////////
154 // Import a Property
156 sal_Bool XMLPropertySetMapper::importXML(
157 const OUString& rStrImpValue,
158 XMLPropertyState& rProperty,
159 const SvXMLUnitConverter& rUnitConverter ) const
161 sal_Bool bRet = sal_False;
163 const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex );
165 if( pHdl )
166 bRet = pHdl->importXML( rStrImpValue, rProperty.maValue,
167 rUnitConverter );
169 return bRet;
172 ///////////////////////////////////////////////////////////////////////////
174 // Search for the given name and the namespace in the list and return
175 // the index of the entry
176 // If there is no matching entry the method returns -1
178 sal_Int32 XMLPropertySetMapper::GetEntryIndex(
179 sal_uInt16 nNamespace,
180 const OUString& rStrName,
181 sal_uInt32 nPropType,
182 sal_Int32 nStartAt /* = -1 */ ) const
184 sal_Int32 nEntries = GetEntryCount();
185 sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1;
187 if ( nEntries )
191 const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
192 if( (!nPropType || nPropType == rEntry.GetPropType()) &&
193 rEntry.nXMLNameSpace == nNamespace &&
194 rStrName == rEntry.sXMLAttributeName )
195 return nIndex;
196 else
197 nIndex++;
199 } while( nIndex<nEntries );
202 return -1;
206 /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
207 sal_Int32 XMLPropertySetMapper::FindEntryIndex(
208 const sal_Char* sApiName,
209 sal_uInt16 nNameSpace,
210 const OUString& sXMLName ) const
212 sal_Int32 nIndex = 0;
213 sal_Int32 nEntries = GetEntryCount();
217 const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
218 if( rEntry.nXMLNameSpace == nNameSpace &&
219 rEntry.sXMLAttributeName.equals( sXMLName ) &&
220 0 == rEntry.sAPIPropertyName.compareToAscii( sApiName ) )
221 return nIndex;
222 else
223 nIndex++;
225 } while( nIndex < nEntries );
227 return -1;
230 sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const
232 const sal_Int32 nEntries = GetEntryCount();
234 if ( nEntries )
236 sal_Int32 nIndex = 0;
239 const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
240 if( rEntry.nContextId == nContextId )
241 return nIndex;
242 else
243 nIndex++;
245 } while( nIndex < nEntries );
248 return -1;
251 void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex )
253 const sal_Int32 nEntries = GetEntryCount();
254 if( nIndex>=nEntries || nIndex<0 )
255 return;
256 vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin();
257 for( sal_Int32 nN=0; nN<nIndex; nN++ )
258 ++aEIter;
259 aMapEntries.erase( aEIter );
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */