2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 21:49:25 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:49:25 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:49:25 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:49:25 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:49:25 +00:00
|
|
|
* OpenOffice.org 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 version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 21:49:25 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <tools/debug.hxx>
|
2007-06-27 14:49:00 +00:00
|
|
|
#include <xmloff/xmlprhdl.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "xmlbahdl.hxx"
|
2007-06-27 14:49:00 +00:00
|
|
|
#include <xmloff/xmlprmap.hxx>
|
|
|
|
#include <xmloff/xmltypes.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertyState.hpp>
|
|
|
|
#include <com/sun/star/uno/Any.hxx>
|
2007-06-27 14:49:00 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
2001-06-29 20:07:26 +00:00
|
|
|
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
using namespace ::std;
|
2008-03-12 09:58:02 +00:00
|
|
|
using ::rtl::OUString;
|
|
|
|
using ::rtl::OUStringBuffer;
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
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 ),
|
2008-06-04 08:49:39 +00:00
|
|
|
nEarliestODFVersionForExport( rMapEntry.mnEarliestODFVersionForExport ),
|
2000-11-07 12:33:09 +00:00
|
|
|
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),
|
2008-06-04 08:49:39 +00:00
|
|
|
nEarliestODFVersionForExport( rEntry.nEarliestODFVersionForExport ),
|
2000-11-07 12:33:09 +00:00
|
|
|
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();
|
2010-12-23 21:07:04 +00:00
|
|
|
++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();
|
2010-12-23 21:07:04 +00:00
|
|
|
++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
|
|
|
|
//
|
2008-10-10 13:02:43 +00:00
|
|
|
sal_Int32 XMLPropertySetMapper::GetEntryIndex(
|
2000-09-18 16:07:07 +00:00
|
|
|
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;
|
|
|
|
|
2008-05-05 14:34:05 +00:00
|
|
|
if ( nEntries )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-05-05 14:34:05 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
|
|
|
|
if( (!nPropType || nPropType == rEntry.GetPropType()) &&
|
|
|
|
rEntry.nXMLNameSpace == nNamespace &&
|
|
|
|
rStrName == rEntry.sXMLAttributeName )
|
|
|
|
return nIndex;
|
|
|
|
else
|
|
|
|
nIndex++;
|
|
|
|
|
|
|
|
} 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
|
|
|
|
{
|
2008-05-05 14:34:05 +00:00
|
|
|
const sal_Int32 nEntries = GetEntryCount();
|
2001-03-01 12:15:04 +00:00
|
|
|
|
2008-05-05 14:34:05 +00:00
|
|
|
if ( nEntries )
|
2001-03-01 12:15:04 +00:00
|
|
|
{
|
2011-07-30 23:51:40 +02:00
|
|
|
sal_Int32 nIndex = 0;
|
2008-05-05 14:34:05 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex];
|
|
|
|
if( rEntry.nContextId == nContextId )
|
|
|
|
return nIndex;
|
|
|
|
else
|
|
|
|
nIndex++;
|
2001-03-01 12:15:04 +00:00
|
|
|
|
2008-05-05 14:34:05 +00:00
|
|
|
} while( nIndex < nEntries );
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2008-11-26 15:19:48 +00:00
|
|
|
|
|
|
|
void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex )
|
|
|
|
{
|
|
|
|
const sal_Int32 nEntries = GetEntryCount();
|
|
|
|
if( nIndex>=nEntries || nIndex<0 )
|
|
|
|
return;
|
|
|
|
vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin();
|
|
|
|
for( sal_Int32 nN=0; nN<nIndex; nN++ )
|
2010-12-23 21:07:04 +00:00
|
|
|
++aEIter;
|
2008-11-26 15:19:48 +00:00
|
|
|
aMapEntries.erase( aEIter );
|
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|