2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: xmlexppr.cxx,v $
|
|
|
|
*
|
2001-01-29 13:58:16 +00:00
|
|
|
* $Revision: 1.13 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2001-01-29 13:58:16 +00:00
|
|
|
* last change: $Author: dvo $ $Date: 2001-01-29 14:58:16 $
|
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): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2000-10-20 13:53:32 +00:00
|
|
|
#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
|
|
|
|
#include <com/sun/star/container/XNameContainer.hpp>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _COM_SUN_STAR_XML_ATTRIBUTEDATA_HPP_
|
|
|
|
#include <com/sun/star/xml/AttributeData.hpp>
|
|
|
|
#endif
|
|
|
|
|
2000-11-07 12:33:09 +00:00
|
|
|
#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
|
|
|
|
|
2000-10-20 13:53:32 +00:00
|
|
|
#ifndef _RTL_USTRBUF_HXX_
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#endif
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "xmlexppr.hxx"
|
|
|
|
|
|
|
|
#ifndef _XMLOFF_XMLKYWD_HXX
|
|
|
|
#include "xmlkywd.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _XMLOFF_ATTRLIST_HXX
|
|
|
|
#include "attrlist.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _XMLOFF_NMSPMAP_HXX
|
|
|
|
#include "nmspmap.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _XMLOFF_XMLNMSPE_HXX
|
|
|
|
#include "xmlnmspe.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _XMLOFF_XMLCNITM_HXX
|
|
|
|
#include "xmlcnitm.hxx"
|
|
|
|
#endif
|
2000-11-07 12:33:09 +00:00
|
|
|
#ifndef _XMLOFF_PROPERTYSETMAPPER_HXX
|
|
|
|
#include "xmlprmap.hxx"
|
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
#ifndef _SVSTDARR_USHORTS
|
|
|
|
#define _SVSTDARR_USHORTS
|
|
|
|
#include <svtools/svstdarr.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace ::rtl;
|
2000-11-07 12:33:09 +00:00
|
|
|
using namespace ::std;
|
2000-09-18 16:07:07 +00:00
|
|
|
using namespace ::com::sun::star;
|
2000-11-07 12:33:09 +00:00
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::uno;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ctor/dtor , class SvXMLExportPropertyMapper
|
|
|
|
//
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
SvXMLExportPropertyMapper::SvXMLExportPropertyMapper(
|
|
|
|
const UniReference< XMLPropertySetMapper >& rMapper )
|
2000-09-18 16:07:07 +00:00
|
|
|
: maPropMapper( rMapper )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLExportPropertyMapper::~SvXMLExportPropertyMapper()
|
|
|
|
{
|
2001-01-17 09:51:33 +00:00
|
|
|
mxNextMapper = 0;
|
2000-11-07 12:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SvXMLExportPropertyMapper::ChainExportMapper(
|
|
|
|
const UniReference< SvXMLExportPropertyMapper>& rMapper )
|
|
|
|
{
|
2001-01-17 09:51:33 +00:00
|
|
|
// add map entries from rMapper to current map
|
2000-11-07 12:33:09 +00:00
|
|
|
maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() );
|
2001-01-17 09:51:33 +00:00
|
|
|
// rMapper uses the same map as 'this'
|
2000-11-07 12:33:09 +00:00
|
|
|
rMapper->maPropMapper = maPropMapper;
|
|
|
|
|
2001-01-17 09:51:33 +00:00
|
|
|
// set rMapper as last mapper in current chain
|
|
|
|
UniReference< SvXMLExportPropertyMapper > xNext = mxNextMapper;
|
|
|
|
if( xNext.is())
|
|
|
|
{
|
|
|
|
while( xNext->mxNextMapper.is())
|
|
|
|
xNext = xNext->mxNextMapper;
|
|
|
|
xNext->mxNextMapper = rMapper;
|
|
|
|
}
|
2001-01-22 15:39:27 +00:00
|
|
|
else
|
|
|
|
mxNextMapper = rMapper;
|
2000-11-07 12:33:09 +00:00
|
|
|
|
2001-01-17 09:51:33 +00:00
|
|
|
// if rMapper was already chained, correct
|
|
|
|
// map pointer of successors
|
|
|
|
xNext = rMapper;
|
2000-11-07 12:33:09 +00:00
|
|
|
|
2001-01-17 09:51:33 +00:00
|
|
|
while( xNext->mxNextMapper.is())
|
|
|
|
{
|
|
|
|
xNext = xNext->mxNextMapper;
|
|
|
|
xNext->maPropMapper = maPropMapper;
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// public methods
|
|
|
|
//
|
|
|
|
|
2000-11-07 12:33:09 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Take all properties of the XPropertySet which are also found in the
|
|
|
|
// XMLPropertyMapEntry-array and which are not set to their default-value,
|
|
|
|
// if a state is available.
|
|
|
|
//
|
|
|
|
// After that I call the method 'ContextFilter'.
|
|
|
|
//
|
|
|
|
vector< XMLPropertyState > SvXMLExportPropertyMapper::Filter(
|
|
|
|
const Reference< XPropertySet > xPropSet ) const
|
|
|
|
{
|
|
|
|
vector< XMLPropertyState > aPropStateArray;
|
|
|
|
|
|
|
|
// Retrieve XPropertySetInfo and XPropertyState
|
|
|
|
Reference< XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
|
|
|
|
|
|
|
|
if( xInfo.is() )
|
|
|
|
{
|
|
|
|
Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
|
|
|
|
sal_Int32 nProps = maPropMapper->GetEntryCount();
|
|
|
|
|
|
|
|
if( xPropState.is() )
|
|
|
|
{
|
|
|
|
Sequence<OUString> aApiNames( nProps );
|
|
|
|
Sequence<sal_uInt32> aIndexes( nProps );
|
|
|
|
OUString *pNames = aApiNames.getArray();
|
|
|
|
sal_uInt32 *pIndexes = aIndexes.getArray();
|
|
|
|
|
|
|
|
sal_Int32 nCount = 0;
|
|
|
|
for( sal_Int32 i=0; i < nProps; i++ )
|
|
|
|
{
|
2001-01-29 13:58:16 +00:00
|
|
|
// Are we allowed to ask for the property? (MID_FLAG_NO_PROP..)
|
2000-11-07 12:33:09 +00:00
|
|
|
// Does the PropertySet contain name of mpEntries-array ?
|
|
|
|
const OUString& rAPIName = maPropMapper->GetEntryAPIName( i );
|
2001-01-29 13:58:16 +00:00
|
|
|
const sal_Int32 nFlags = maPropMapper->GetEntryFlags( i );
|
|
|
|
if( (0 == (nFlags & MID_FLAG_NO_PROPERTY_EXPORT)) &&
|
|
|
|
xInfo->hasPropertyByName( rAPIName ) )
|
2000-11-07 12:33:09 +00:00
|
|
|
{
|
|
|
|
pNames[nCount] = rAPIName;
|
|
|
|
pIndexes[nCount] = i;
|
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aApiNames.realloc( nCount );
|
|
|
|
aIndexes.realloc( nCount );
|
|
|
|
|
|
|
|
Sequence < PropertyState > aStates =
|
|
|
|
xPropState->getPropertyStates( aApiNames );
|
|
|
|
|
|
|
|
const PropertyState *pStates = aStates.getArray();
|
|
|
|
for( i = 0; i < nCount; i++ )
|
|
|
|
{
|
|
|
|
if( pStates[i] == PropertyState_DIRECT_VALUE )
|
|
|
|
{
|
|
|
|
// The value is stored in the PropertySet itself, add to list.
|
|
|
|
XMLPropertyState aNewProperty( pIndexes[i],
|
|
|
|
xPropSet->getPropertyValue(
|
|
|
|
aApiNames[i] ) );
|
|
|
|
aPropStateArray.push_back( aNewProperty );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( sal_Int32 i=0; i < nProps; i++ )
|
|
|
|
{
|
2001-01-29 13:58:16 +00:00
|
|
|
// Are we allowed to ask for the property? (MID_FLAG_NO_PROP..)
|
2000-11-07 12:33:09 +00:00
|
|
|
// Does the PropertySet contain name of mpEntries-array ?
|
|
|
|
const OUString& rAPIName = maPropMapper->GetEntryAPIName( i );
|
2001-01-29 13:58:16 +00:00
|
|
|
const sal_Int32 nFlags = maPropMapper->GetEntryFlags( i );
|
|
|
|
if( (0 == (nFlags & MID_FLAG_NO_PROPERTY_EXPORT)) &&
|
|
|
|
xInfo->hasPropertyByName( rAPIName ) )
|
2000-11-07 12:33:09 +00:00
|
|
|
{
|
|
|
|
// If there isn't a XPropertyState we can't filter by its state
|
|
|
|
if( !xPropState.is() ||
|
|
|
|
xPropState->getPropertyState( rAPIName ) ==
|
|
|
|
PropertyState_DIRECT_VALUE )
|
|
|
|
{
|
|
|
|
// The value is stored in the PropertySet itself, add to list.
|
|
|
|
XMLPropertyState aNewProperty( i,
|
|
|
|
xPropSet->getPropertyValue( rAPIName ) );
|
|
|
|
aPropStateArray.push_back( aNewProperty );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call centext-filter
|
|
|
|
ContextFilter( aPropStateArray, xPropSet );
|
2000-12-15 12:52:14 +00:00
|
|
|
|
|
|
|
// Have to do if we change from a vector to a list or something like that
|
|
|
|
/*vector< XMLPropertyState >::iterator aItr = aPropStateArray.begin();
|
2000-12-15 10:50:34 +00:00
|
|
|
while (aItr != aPropStateArray.end())
|
|
|
|
{
|
|
|
|
if (aItr->mnIndex == -1)
|
|
|
|
aItr = aPropStateArray.erase(aItr);
|
|
|
|
else
|
|
|
|
aItr++;
|
2000-12-15 12:52:14 +00:00
|
|
|
}*/
|
2000-11-07 12:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return aPropStateArray;
|
|
|
|
}
|
|
|
|
|
2001-01-05 09:02:58 +00:00
|
|
|
vector< XMLPropertyState > SvXMLExportPropertyMapper::FilterDefaults(
|
|
|
|
const Reference< XPropertySet > xPropSet ) const
|
|
|
|
{
|
|
|
|
vector< XMLPropertyState > aPropStateArray;
|
|
|
|
|
|
|
|
// Retrieve XPropertySetInfo and XPropertyState
|
|
|
|
Reference< XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
|
|
|
|
Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
|
|
|
|
|
|
|
|
if( xInfo.is() && xPropState.is() )
|
|
|
|
{
|
|
|
|
sal_Int32 nProps = maPropMapper->GetEntryCount();
|
|
|
|
|
|
|
|
for( sal_Int32 i=0; i < nProps; i++ )
|
|
|
|
{
|
|
|
|
// Does the PropertySet contain name of mpEntries-array ?
|
|
|
|
if( (maPropMapper->GetEntryFlags( i ) &
|
|
|
|
MID_FLAG_DEFAULT_ITEM_EXPORT) != 0 )
|
|
|
|
{
|
|
|
|
const OUString& rAPIName = maPropMapper->GetEntryAPIName( i );
|
|
|
|
if( xInfo->hasPropertyByName( rAPIName ) )
|
|
|
|
{
|
|
|
|
XMLPropertyState aNewProperty( i,
|
|
|
|
xPropState->getPropertyDefault( rAPIName ) );
|
|
|
|
aPropStateArray.push_back( aNewProperty );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call centext-filter
|
|
|
|
ContextFilter( aPropStateArray, xPropSet );
|
|
|
|
|
|
|
|
// Have to do if we change from a vector to a list or something like that
|
|
|
|
/*vector< XMLPropertyState >::iterator aItr = aPropStateArray.begin();
|
|
|
|
while (aItr != aPropStateArray.end())
|
|
|
|
{
|
|
|
|
if (aItr->mnIndex == -1)
|
|
|
|
aItr = aPropStateArray.erase(aItr);
|
|
|
|
else
|
|
|
|
aItr++;
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
return aPropStateArray;
|
|
|
|
}
|
|
|
|
|
2000-11-07 12:33:09 +00:00
|
|
|
void SvXMLExportPropertyMapper::ContextFilter(
|
|
|
|
vector< XMLPropertyState >& rProperties,
|
|
|
|
Reference< XPropertySet > rPropSet ) const
|
|
|
|
{
|
|
|
|
// Derived class could implement this.
|
2001-01-17 09:51:33 +00:00
|
|
|
if( mxNextMapper.is() )
|
|
|
|
mxNextMapper->ContextFilter( rProperties, rPropSet );
|
2000-11-07 12:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Compares two Sequences of XMLPropertyState:
|
|
|
|
// 1.Number of elements equal ?
|
|
|
|
// 2.Index of each element equal ? (So I know whether the propertynames are the same)
|
|
|
|
// 3.Value of each element equal ?
|
|
|
|
//
|
|
|
|
sal_Bool SvXMLExportPropertyMapper::Equals(
|
|
|
|
const vector< XMLPropertyState >& aProperties1,
|
|
|
|
const vector< XMLPropertyState >& aProperties2 ) const
|
|
|
|
{
|
|
|
|
sal_Bool bRet = sal_True;
|
|
|
|
sal_Int32 nCount = aProperties1.size();
|
|
|
|
|
|
|
|
if( nCount == aProperties2.size() )
|
|
|
|
{
|
|
|
|
sal_Int32 nIndex = 0;
|
|
|
|
while( bRet && nIndex < nCount )
|
|
|
|
{
|
|
|
|
const XMLPropertyState& rProp1 = aProperties1[ nIndex ];
|
|
|
|
const XMLPropertyState& rProp2 = aProperties2[ nIndex ];
|
|
|
|
|
|
|
|
// Compare index. If equal, compare value
|
|
|
|
if( rProp1.mnIndex == rProp2.mnIndex )
|
|
|
|
{
|
|
|
|
if( rProp1.mnIndex != -1 )
|
|
|
|
{
|
|
|
|
// Now compare values
|
|
|
|
if( ( maPropMapper->GetEntryType( rProp1.mnIndex ) &
|
|
|
|
XML_TYPE_BUILDIN_CMP ) != 0 )
|
|
|
|
// simple type ( binary compare )
|
|
|
|
bRet = ( rProp1.maValue == rProp2.maValue );
|
|
|
|
else
|
|
|
|
// complex type ( ask for compare-function )
|
|
|
|
bRet = maPropMapper->GetPropertyHandler(
|
|
|
|
rProp1.mnIndex )->equals( rProp1.maValue,
|
|
|
|
rProp2.maValue );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bRet = sal_False;
|
|
|
|
|
|
|
|
nIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bRet = sal_False;
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
/** fills the given attribute list with the items in the given set */
|
|
|
|
void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList,
|
2000-10-19 13:25:20 +00:00
|
|
|
const ::std::vector< XMLPropertyState >& rProperties,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
sal_uInt16 nFlags ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-10-19 13:25:20 +00:00
|
|
|
_exportXML( rAttrList, rProperties, rUnitConverter, rNamespaceMap,
|
2000-10-25 11:39:31 +00:00
|
|
|
nFlags, 0, -1, -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList,
|
|
|
|
const ::std::vector< XMLPropertyState >& rProperties,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx,
|
|
|
|
sal_uInt16 nFlags ) const
|
|
|
|
{
|
|
|
|
_exportXML( rAttrList, rProperties, rUnitConverter, rNamespaceMap,
|
|
|
|
nFlags, 0, nPropMapStartIdx, nPropMapEndIdx );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList,
|
2000-10-19 13:25:20 +00:00
|
|
|
const XMLPropertyState& rProperty,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
sal_uInt16 nFlags ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-10-19 13:25:20 +00:00
|
|
|
if( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
|
|
|
|
MID_FLAG_ELEMENT_ITEM_EXPORT ) == 0 )
|
|
|
|
_exportXML( rAttrList, rProperty, rUnitConverter, rNamespaceMap,
|
|
|
|
nFlags );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
void SvXMLExportPropertyMapper::exportXML(
|
|
|
|
const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
|
|
|
|
const ::std::vector< XMLPropertyState >& rProperties,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
sal_uInt16 nFlags ) const
|
2000-10-25 11:39:31 +00:00
|
|
|
{
|
|
|
|
exportXML( rHandler, rProperties, rUnitConverter, rNamespaceMap,
|
|
|
|
-1, -1, nFlags );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SvXMLExportPropertyMapper::exportXML(
|
|
|
|
const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
|
|
|
|
const ::std::vector< XMLPropertyState >& rProperties,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx,
|
|
|
|
sal_uInt16 nFlags ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
SvXMLAttributeList *pAttrList = new SvXMLAttributeList();
|
2000-10-19 13:25:20 +00:00
|
|
|
uno::Reference< xml::sax::XAttributeList > xAttrList( pAttrList );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
SvUShorts aIndexArray;
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
_exportXML( *pAttrList, rProperties, rUnitConverter, rNamespaceMap,
|
2000-10-25 11:39:31 +00:00
|
|
|
nFlags, &aIndexArray, nPropMapStartIdx, nPropMapEndIdx );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
if( pAttrList->getLength() > 0L || (nFlags & XML_EXPORT_FLAG_EMPTY) != 0 ||
|
|
|
|
aIndexArray.Count() != 0 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
if( (nFlags & XML_EXPORT_FLAG_IGN_WS) != 0 )
|
|
|
|
{
|
|
|
|
OUString sWS( OUString::createFromAscii(sXML_WS) );
|
|
|
|
rHandler->ignorableWhitespace( sWS );
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString sLName( OUString::createFromAscii(sXML_properties) );
|
2000-10-19 13:25:20 +00:00
|
|
|
OUString sName = rNamespaceMap.GetQNameByKey( XML_NAMESPACE_STYLE,
|
|
|
|
sLName );
|
2000-09-18 16:07:07 +00:00
|
|
|
rHandler->startElement( sName, xAttrList );
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
exportElementItems( rHandler, rUnitConverter, rNamespaceMap,
|
|
|
|
rProperties, nFlags, aIndexArray );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
rHandler->endElement( sName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
/** this method is called for every item that has the
|
|
|
|
MID_FLAG_SPECIAL_ITEM_EXPORT flag set */
|
|
|
|
void SvXMLExportPropertyMapper::handleSpecialItem(
|
|
|
|
SvXMLAttributeList& rAttrList,
|
|
|
|
const XMLPropertyState& rProperty,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
const ::std::vector< XMLPropertyState > *pProperties,
|
|
|
|
sal_uInt32 nIdx ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-01-17 09:51:33 +00:00
|
|
|
DBG_ASSERT( mxNextMapper.is(), "special item not handled in xml export" );
|
|
|
|
if( mxNextMapper.is() )
|
|
|
|
mxNextMapper->handleSpecialItem( rAttrList, rProperty, rUnitConverter,
|
2000-11-07 12:33:09 +00:00
|
|
|
rNamespaceMap, pProperties, nIdx );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
/** this method is called for every item that has the
|
|
|
|
MID_FLAG_ELEMENT_EXPORT flag set */
|
|
|
|
void SvXMLExportPropertyMapper::handleElementItem(
|
|
|
|
const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
|
|
|
|
const XMLPropertyState& rProperty,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
sal_uInt16 nFlags,
|
|
|
|
const ::std::vector< XMLPropertyState > *pProperties,
|
|
|
|
sal_uInt32 nIdx ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-01-17 09:51:33 +00:00
|
|
|
DBG_ASSERT( mxNextMapper.is(), "element item not handled in xml export" );
|
|
|
|
if( mxNextMapper.is() )
|
|
|
|
mxNextMapper->handleElementItem( rHandler, rProperty, rUnitConverter,
|
2000-11-07 12:33:09 +00:00
|
|
|
rNamespaceMap, nFlags, pProperties,
|
|
|
|
nIdx );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// protected methods
|
|
|
|
//
|
|
|
|
|
|
|
|
/** fills the given attribute list with the items in the given set */
|
2000-10-19 13:25:20 +00:00
|
|
|
void SvXMLExportPropertyMapper::_exportXML(
|
|
|
|
SvXMLAttributeList& rAttrList,
|
|
|
|
const ::std::vector< XMLPropertyState >& rProperties,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
sal_uInt16 nFlags,
|
2000-10-25 11:39:31 +00:00
|
|
|
SvUShorts* pIndexArray,
|
|
|
|
sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-10-19 13:25:20 +00:00
|
|
|
const sal_uInt32 nCount = rProperties.size();
|
|
|
|
sal_uInt32 nIndex = 0;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-10-25 11:39:31 +00:00
|
|
|
if( -1 == nPropMapStartIdx )
|
|
|
|
nPropMapStartIdx = 0;
|
|
|
|
if( -1 == nPropMapEndIdx )
|
|
|
|
nPropMapEndIdx = maPropMapper->GetEntryCount();
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
while( nIndex < nCount )
|
|
|
|
{
|
2000-10-25 11:39:31 +00:00
|
|
|
sal_Int32 nPropMapIdx = rProperties[nIndex].mnIndex;
|
|
|
|
if( nPropMapIdx >= nPropMapStartIdx &&
|
|
|
|
nPropMapIdx < nPropMapEndIdx )// valid entry?
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// we have a valid map entry here, so lets use it...
|
2000-10-25 11:39:31 +00:00
|
|
|
if( ( maPropMapper->GetEntryFlags( nPropMapIdx )
|
2001-01-29 13:58:16 +00:00
|
|
|
& MID_FLAG_ELEMENT_ITEM_EXPORT ) != 0 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-01-29 13:58:16 +00:00
|
|
|
// element items do not add any properties,
|
|
|
|
// we export it later
|
|
|
|
if( pIndexArray )
|
|
|
|
pIndexArray->Insert( nIndex, pIndexArray->Count() );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-29 13:58:16 +00:00
|
|
|
_exportXML( rAttrList, rProperties[nIndex], rUnitConverter,
|
|
|
|
rNamespaceMap, nFlags, &rProperties, nIndex );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
void SvXMLExportPropertyMapper::_exportXML(
|
|
|
|
SvXMLAttributeList& rAttrList,
|
|
|
|
const XMLPropertyState& rProperty,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
sal_uInt16 nFlags,
|
|
|
|
const ::std::vector< XMLPropertyState > *pProperties,
|
|
|
|
sal_uInt32 nIdx ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
OUString sCDATA( OUString::createFromAscii( sXML_CDATA ) );
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
if ( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
|
|
|
|
MID_FLAG_SPECIAL_ITEM_EXPORT ) != 0 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-10-20 13:53:32 +00:00
|
|
|
uno::Reference< container::XNameContainer > xAttrContainer;
|
2000-10-30 12:34:13 +00:00
|
|
|
if( (rProperty.maValue >>= xAttrContainer) && xAttrContainer.is() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
SvXMLNamespaceMap *pNewNamespaceMap = 0;
|
|
|
|
const SvXMLNamespaceMap *pNamespaceMap = &rNamespaceMap;
|
|
|
|
|
2000-10-20 13:53:32 +00:00
|
|
|
uno::Sequence< OUString > aAttribNames( xAttrContainer->getElementNames() );
|
|
|
|
const OUString* pAttribName = aAttribNames.getConstArray();
|
|
|
|
|
|
|
|
const sal_Int32 nCount = aAttribNames.getLength();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
OUStringBuffer sName;
|
2000-10-20 13:53:32 +00:00
|
|
|
xml::AttributeData aData;
|
|
|
|
for( sal_Int32 i=0; i < nCount; i++, pAttribName++ )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-10-20 13:53:32 +00:00
|
|
|
xAttrContainer->getByName( *pAttribName ) >>= aData;
|
|
|
|
|
|
|
|
// extract namespace prefix from attribute name if it exists
|
|
|
|
OUString sPrefix;
|
|
|
|
const sal_Int32 nPos = pAttribName->indexOf( sal_Unicode(':') );
|
|
|
|
if( nPos != -1 )
|
|
|
|
sPrefix = pAttribName->copy( 0, nPos );
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
if( sPrefix.getLength() )
|
|
|
|
{
|
2000-10-20 13:53:32 +00:00
|
|
|
OUString sNamespace( aData.Namespace );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// if the prefix isn't defined yet or has another meaning,
|
|
|
|
// we have to redefine it now.
|
2000-10-20 13:53:32 +00:00
|
|
|
sal_uInt16 nIdx = pNamespaceMap->GetIndexByPrefix( sPrefix );
|
|
|
|
if( USHRT_MAX == nIdx || pNamespaceMap->GetNameByIndex( nIdx ) != sNamespace )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
if( !pNewNamespaceMap )
|
|
|
|
{
|
2000-10-20 13:53:32 +00:00
|
|
|
pNewNamespaceMap = new SvXMLNamespaceMap( rNamespaceMap );
|
2000-09-18 16:07:07 +00:00
|
|
|
pNamespaceMap = pNewNamespaceMap;
|
|
|
|
}
|
|
|
|
pNewNamespaceMap->Add( sPrefix, sNamespace );
|
|
|
|
|
|
|
|
sName.appendAscii( sXML_xmlns );
|
|
|
|
sName.append( sal_Unicode(':') );
|
|
|
|
sName.append( sPrefix );
|
|
|
|
rAttrList.AddAttribute( sName.makeStringAndClear(), sCDATA,
|
|
|
|
sNamespace );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-20 13:53:32 +00:00
|
|
|
rAttrList.AddAttribute( *pAttribName, aData.Type, aData.Value );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete pNewNamespaceMap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-19 13:25:20 +00:00
|
|
|
handleSpecialItem( rAttrList, rProperty, rUnitConverter,
|
|
|
|
rNamespaceMap, pProperties, nIdx );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-19 13:25:20 +00:00
|
|
|
else if ( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
|
|
|
|
MID_FLAG_ELEMENT_ITEM_EXPORT ) == 0 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
OUString aValue;
|
2000-10-19 13:25:20 +00:00
|
|
|
const OUString sName( rNamespaceMap.GetQNameByKey(
|
|
|
|
maPropMapper->GetEntryNameSpace( rProperty.mnIndex ),
|
|
|
|
maPropMapper->GetEntryXMLName( rProperty.mnIndex ) ) );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
sal_Bool bRemove = sal_False;
|
2000-10-19 13:25:20 +00:00
|
|
|
if( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) &
|
|
|
|
MID_FLAG_MERGE_ATTRIBUTE ) != 0 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
aValue = rAttrList.getValueByName( sName );
|
2000-10-20 15:35:00 +00:00
|
|
|
bRemove = sal_True; //aValue.getLength() != 0;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
if( maPropMapper->exportXML( aValue, rProperty, rUnitConverter ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
if( bRemove )
|
|
|
|
rAttrList.RemoveAttribute( sName );
|
|
|
|
rAttrList.AddAttribute( sName, sCDATA, aValue );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
void SvXMLExportPropertyMapper::exportElementItems(
|
|
|
|
const uno::Reference< xml::sax::XDocumentHandler > & rHandler,
|
|
|
|
const SvXMLUnitConverter& rUnitConverter,
|
|
|
|
const SvXMLNamespaceMap& rNamespaceMap,
|
|
|
|
const ::std::vector< XMLPropertyState >& rProperties,
|
|
|
|
sal_uInt16 nFlags,
|
|
|
|
const SvUShorts& rIndexArray ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
const sal_uInt16 nCount = rIndexArray.Count();
|
|
|
|
|
|
|
|
sal_Bool bItemsExported = sal_False;
|
|
|
|
OUString sWS( OUString::createFromAscii(sXML_WS) );
|
|
|
|
for( sal_uInt16 nIndex = 0; nIndex < nCount; nIndex++ )
|
|
|
|
{
|
|
|
|
const sal_uInt16 nElement = rIndexArray.GetObject( nIndex );
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
DBG_ASSERT( 0 != ( maPropMapper->GetEntryFlags(
|
|
|
|
rProperties[nElement].mnIndex ) & MID_FLAG_ELEMENT_ITEM_EXPORT),
|
|
|
|
"wrong mid flag!" );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
rHandler->ignorableWhitespace( sWS );
|
2000-10-19 13:25:20 +00:00
|
|
|
handleElementItem( rHandler, rProperties[nElement], rUnitConverter,
|
|
|
|
rNamespaceMap, nFlags, &rProperties, nElement );
|
2000-09-18 16:07:07 +00:00
|
|
|
bItemsExported = sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bItemsExported )
|
|
|
|
rHandler->ignorableWhitespace( sWS );
|
|
|
|
}
|