| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | /*************************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  $RCSfile: xmlprmap.cxx,v $ | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-07-13 07:28:32 +00:00
										 |  |  |  *  $Revision: 1.6 $ | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-07-13 07:28:32 +00:00
										 |  |  |  *  last change: $Author: rt $ $Date: 2004-07-13 08:28:32 $ | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  The Contents of this file are made available subject to the terms of | 
					
						
							|  |  |  |  *  either of the following licenses | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *         - GNU Lesser General Public License Version 2.1 | 
					
						
							|  |  |  |  *         - Sun Industry Standards Source License Version 1.1 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Sun Microsystems Inc., October, 2000 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  GNU Lesser General Public License Version 2.1 | 
					
						
							|  |  |  |  *  ============================================= | 
					
						
							|  |  |  |  *  Copyright 2000 by Sun Microsystems, Inc. | 
					
						
							|  |  |  |  *  901 San Antonio Road, Palo Alto, CA 94303, USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  *  modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  *  License version 2.1, as published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  *  Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  *  License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, | 
					
						
							|  |  |  |  *  MA  02111-1307  USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Sun Industry Standards Source License Version 1.1 | 
					
						
							|  |  |  |  *  ================================================= | 
					
						
							|  |  |  |  *  The contents of this file are subject to the Sun Industry Standards | 
					
						
							|  |  |  |  *  Source License Version 1.1 (the "License"); You may not use this file | 
					
						
							|  |  |  |  *  except in compliance with the License. You may obtain a copy of the | 
					
						
							|  |  |  |  *  License at http://www.openoffice.org/license.html.
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Software provided under this License is provided on an "AS IS" basis, | 
					
						
							|  |  |  |  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, | 
					
						
							|  |  |  |  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, | 
					
						
							|  |  |  |  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. | 
					
						
							|  |  |  |  *  See the License for the specific provisions governing your rights and | 
					
						
							|  |  |  |  *  obligations concerning the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  The Initial Developer of the Original Code is: Sun Microsystems, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Copyright: 2000 by Sun Microsystems, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Contributor(s): _______________________________________ | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  ************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _TOOLS_DEBUG_HXX
 | 
					
						
							|  |  |  | #include <tools/debug.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _XMLOFF_PROPERTYHANDLERBASE_HXX
 | 
					
						
							|  |  |  | #include "xmlprhdl.hxx"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _XMLOFF_PROPERTYHANDLER_BASICTYPES_HXX
 | 
					
						
							|  |  |  | #include "xmlbahdl.hxx"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _XMLOFF_PROPERTYSETMAPPER_HXX
 | 
					
						
							|  |  |  | #include "xmlprmap.hxx"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _XMLOFF_XMLTYPES_HXX
 | 
					
						
							|  |  |  | #include "xmltypes.hxx"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
 | 
					
						
							|  |  |  | #include <com/sun/star/beans/XPropertySet.hpp>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSTATE_HPP_
 | 
					
						
							|  |  |  | #include <com/sun/star/beans/XPropertyState.hpp>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _COM_SUN_STAR_UNO_ANY_HXX_
 | 
					
						
							|  |  |  | #include <com/sun/star/uno/Any.hxx>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  | #ifndef _XMLOFF_XMLTOKEN_HXX
 | 
					
						
							|  |  |  | #include "xmltoken.hxx"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | using namespace ::std; | 
					
						
							|  |  |  | using namespace ::rtl; | 
					
						
							|  |  |  | using namespace ::com::sun::star::uno; | 
					
						
							|  |  |  | using namespace ::com::sun::star::beans; | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  | using ::xmloff::token::GetXMLToken; | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  | XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl( | 
					
						
							|  |  |  |     const XMLPropertyMapEntry& rMapEntry, | 
					
						
							|  |  |  |     const UniReference< XMLPropertyHandlerFactory >& rFactory ) : | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |     sXMLAttributeName( GetXMLToken(rMapEntry.meXMLName) ), | 
					
						
							| 
									
										
										
										
											2001-07-25 12:55:54 +00:00
										 |  |  |     sAPIPropertyName( OUString(rMapEntry.msApiName, rMapEntry.nApiNameLength, | 
					
						
							|  |  |  |                                RTL_TEXTENCODING_ASCII_US ) ), | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |     nXMLNameSpace( rMapEntry.mnNameSpace ), | 
					
						
							|  |  |  |     nType( rMapEntry.mnType ), | 
					
						
							|  |  |  |     nContextId( rMapEntry.mnContextId ), | 
					
						
							|  |  |  |     pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl( | 
					
						
							|  |  |  |         const XMLPropertySetMapperEntry_Impl& rEntry ) : | 
					
						
							|  |  |  |     sXMLAttributeName( rEntry.sXMLAttributeName), | 
					
						
							|  |  |  |     sAPIPropertyName( rEntry.sAPIPropertyName), | 
					
						
							|  |  |  |     nXMLNameSpace( rEntry.nXMLNameSpace), | 
					
						
							|  |  |  |     nType( rEntry.nType), | 
					
						
							|  |  |  |     nContextId( rEntry.nContextId), | 
					
						
							|  |  |  |     pHdl( rEntry.pHdl) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DBG_ASSERT( pHdl, "Unknown XML property type handler!" ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Ctor
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | XMLPropertySetMapper::XMLPropertySetMapper( | 
					
						
							|  |  |  |         const XMLPropertyMapEntry* pEntries, | 
					
						
							|  |  |  |         const UniReference< XMLPropertyHandlerFactory >& rFactory ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |     aHdlFactories.push_back( rFactory ); | 
					
						
							|  |  |  |     if( pEntries ) | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |         const XMLPropertyMapEntry* pIter = pEntries; | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // count entries
 | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |         while( pIter->msApiName ) | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |             XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory ); | 
					
						
							|  |  |  |             aMapEntries.push_back( aEntry ); | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |             pIter++; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | XMLPropertySetMapper::~XMLPropertySetMapper() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  | void XMLPropertySetMapper::AddMapperEntry( | 
					
						
							|  |  |  |     const UniReference < XMLPropertySetMapper >& rMapper ) | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |     for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator | 
					
						
							|  |  |  |             aFIter = rMapper->aHdlFactories.begin(); | 
					
						
							|  |  |  |          aFIter != rMapper->aHdlFactories.end(); | 
					
						
							|  |  |  |          aFIter++ ) | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |         aHdlFactories.push_back( *aFIter ); | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |     for( vector < XMLPropertySetMapperEntry_Impl >::iterator | 
					
						
							|  |  |  |             aEIter = rMapper->aMapEntries.begin(); | 
					
						
							|  |  |  |          aEIter != rMapper->aMapEntries.end(); | 
					
						
							|  |  |  |          aEIter++ ) | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |         aMapEntries.push_back( *aEIter ); | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Export a Property
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | sal_Bool XMLPropertySetMapper::exportXML( | 
					
						
							|  |  |  |         OUString& rStrExpValue, | 
					
						
							|  |  |  |         const XMLPropertyState& rProperty, | 
					
						
							|  |  |  |         const SvXMLUnitConverter& rUnitConverter ) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     sal_Bool bRet = sal_False; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     DBG_ASSERT( pHdl, "Unknown XML Type!" ); | 
					
						
							|  |  |  |     if( pHdl ) | 
					
						
							|  |  |  |         bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue, | 
					
						
							|  |  |  |                                 rUnitConverter ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return bRet; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Import a Property
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | sal_Bool XMLPropertySetMapper::importXML( | 
					
						
							|  |  |  |         const OUString& rStrImpValue, | 
					
						
							|  |  |  |         XMLPropertyState& rProperty, | 
					
						
							|  |  |  |         const SvXMLUnitConverter& rUnitConverter ) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     sal_Bool bRet = sal_False; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if( pHdl ) | 
					
						
							|  |  |  |         bRet = pHdl->importXML( rStrImpValue, rProperty.maValue, | 
					
						
							|  |  |  |                                 rUnitConverter ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return bRet; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Search for the given name and the namespace in the list and return
 | 
					
						
							|  |  |  | // the index of the entry
 | 
					
						
							|  |  |  | // If there is no matching entry the method returns -1
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | const sal_Int32 XMLPropertySetMapper::GetEntryIndex( | 
					
						
							|  |  |  |         sal_uInt16 nNamespace, | 
					
						
							|  |  |  |         const OUString& rStrName, | 
					
						
							| 
									
										
										
										
											2004-07-13 07:28:32 +00:00
										 |  |  |         sal_uInt32 nPropType, | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |         sal_Int32 nStartAt /* = -1 */ ) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |     sal_Int32 nEntries = GetEntryCount(); | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |     sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     do | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |         const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex]; | 
					
						
							| 
									
										
										
										
											2004-07-13 07:28:32 +00:00
										 |  |  |         if( (!nPropType || nPropType == rEntry.GetPropType()) && | 
					
						
							|  |  |  |             rEntry.nXMLNameSpace == nNamespace && | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |             rStrName == rEntry.sXMLAttributeName ) | 
					
						
							|  |  |  |             return nIndex; | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |         else | 
					
						
							|  |  |  |             nIndex++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |     } while( nIndex<nEntries ); | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */ | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  | sal_Int32 XMLPropertySetMapper::FindEntryIndex( | 
					
						
							|  |  |  |         const sal_Char* sApiName, | 
					
						
							|  |  |  |         sal_uInt16 nNameSpace, | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |         const OUString& sXMLName ) const | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     sal_Int32 nIndex = 0; | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |     sal_Int32 nEntries = GetEntryCount(); | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |     do | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |         const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex]; | 
					
						
							|  |  |  |         if( rEntry.nXMLNameSpace == nNameSpace && | 
					
						
							| 
									
										
										
										
											2001-06-29 20:07:26 +00:00
										 |  |  |             rEntry.sXMLAttributeName.equals( sXMLName ) && | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |             0 == rEntry.sAPIPropertyName.compareToAscii( sApiName ) ) | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  |             return nIndex; | 
					
						
							| 
									
										
										
										
											2000-11-07 12:33:09 +00:00
										 |  |  |         else | 
					
						
							|  |  |  |             nIndex++; | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-01 12:15:04 +00:00
										 |  |  |     } while( nIndex < nEntries ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     sal_Int32 nIndex = 0; | 
					
						
							|  |  |  |     sal_Int32 nEntries = GetEntryCount(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     do | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex]; | 
					
						
							|  |  |  |         if( rEntry.nContextId == nContextId ) | 
					
						
							|  |  |  |             return nIndex; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             nIndex++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } while( nIndex < nEntries ); | 
					
						
							| 
									
										
										
										
											2000-09-18 16:07:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return -1; | 
					
						
							|  |  |  | } |