2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: xmlexppr.cxx,v $
|
|
|
|
*
|
2003-03-27 17:21:03 +00:00
|
|
|
* $Revision: 1.39 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2003-03-27 17:21:03 +00:00
|
|
|
* last change: $Author: hr $ $Date: 2003-03-27 18:20:35 $
|
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
|
2001-03-29 13:24:33 +00:00
|
|
|
#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_
|
|
|
|
#include <com/sun/star/lang/XTypeProvider.hpp>
|
|
|
|
#endif
|
2001-04-04 05:28:26 +00:00
|
|
|
#ifndef _COM_SUN_STAR_BEANS_XMULTIPROPERTYSET_HPP_
|
|
|
|
#include <com/sun/star/beans/XMultiPropertySet.hpp>
|
|
|
|
#endif
|
2000-11-07 12:33:09 +00:00
|
|
|
|
2000-10-20 13:53:32 +00:00
|
|
|
#ifndef _RTL_USTRBUF_HXX_
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#endif
|
2001-02-23 15:35:33 +00:00
|
|
|
#include <list>
|
2001-04-19 12:52:21 +00:00
|
|
|
#include <hash_map>
|
2000-10-20 13:53:32 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "xmlexppr.hxx"
|
|
|
|
|
2001-06-29 20:07:26 +00:00
|
|
|
#ifndef _XMLOFF_XMLTOKEN_HXX
|
|
|
|
#include "xmltoken.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#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
|
|
|
|
|
2001-10-25 19:57:03 +00:00
|
|
|
#ifndef _XMLOFF_XMLEXP_HXX
|
|
|
|
#include "xmlexp.hxx"
|
|
|
|
#endif
|
|
|
|
|
2000-11-07 12:33:09 +00:00
|
|
|
#ifndef _XMLOFF_PROPERTYSETMAPPER_HXX
|
|
|
|
#include "xmlprmap.hxx"
|
|
|
|
#endif
|
2003-03-27 17:21:03 +00:00
|
|
|
#ifndef _XMLOFF_PROPERTYSETINFOHASH_HXX
|
|
|
|
#include "PropertySetInfoHash.hxx"
|
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-07-25 14:31:11 +00:00
|
|
|
#ifndef _COMPHELPER_STLTYPES_HXX_
|
|
|
|
#include <comphelper/stl_types.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;
|
2001-03-29 13:24:33 +00:00
|
|
|
using namespace ::com::sun::star::lang;
|
2001-06-29 20:07:26 +00:00
|
|
|
using namespace ::xmloff::token;
|
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'.
|
|
|
|
//
|
2001-03-02 07:55:06 +00:00
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
typedef std::list<XMLPropertyState> XMLPropertyStateList_Impl;
|
2001-03-02 07:55:06 +00:00
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
class XMLPropertyStates_Impl
|
2001-03-02 07:55:06 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
XMLPropertyStateList_Impl aPropStates;
|
|
|
|
XMLPropertyStateList_Impl::iterator aLastItr;
|
|
|
|
sal_uInt32 nCount;
|
2001-03-02 07:55:06 +00:00
|
|
|
public:
|
2001-04-04 05:28:26 +00:00
|
|
|
XMLPropertyStates_Impl();
|
|
|
|
void AddPropertyState(const XMLPropertyState& rPropState);
|
|
|
|
void FillPropertyStateVector(std::vector<XMLPropertyState>& rVector);
|
2001-03-02 07:55:06 +00:00
|
|
|
};
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
XMLPropertyStates_Impl::XMLPropertyStates_Impl() :
|
|
|
|
aPropStates(),
|
2001-03-02 07:55:06 +00:00
|
|
|
nCount(0)
|
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
aLastItr = aPropStates.begin();
|
2001-03-02 07:55:06 +00:00
|
|
|
}
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
void XMLPropertyStates_Impl::AddPropertyState(
|
|
|
|
const XMLPropertyState& rPropState)
|
2001-03-02 07:55:06 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
XMLPropertyStateList_Impl::iterator aItr = aPropStates.begin();
|
2001-03-02 07:55:06 +00:00
|
|
|
sal_Bool bInserted(sal_False);
|
|
|
|
if (nCount)
|
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
if (aLastItr->mnIndex < rPropState.mnIndex)
|
2001-03-02 07:55:06 +00:00
|
|
|
aItr = ++aLastItr;
|
|
|
|
}
|
|
|
|
do
|
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
// TODO: one path required only
|
|
|
|
if (aItr == aPropStates.end())
|
2001-03-02 07:55:06 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
aLastItr = aPropStates.insert(aPropStates.end(), rPropState);
|
2001-03-02 07:55:06 +00:00
|
|
|
bInserted = sal_True;
|
|
|
|
nCount++;
|
|
|
|
}
|
2001-04-04 05:28:26 +00:00
|
|
|
else if (aItr->mnIndex > rPropState.mnIndex)
|
2001-03-02 07:55:06 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
aLastItr = aPropStates.insert(aItr, rPropState);
|
2001-03-02 07:55:06 +00:00
|
|
|
bInserted = sal_True;
|
|
|
|
nCount++;
|
|
|
|
}
|
|
|
|
}
|
2001-04-04 05:28:26 +00:00
|
|
|
while(!bInserted && (aItr++ != aPropStates.end()));
|
2001-03-02 07:55:06 +00:00
|
|
|
}
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
void XMLPropertyStates_Impl::FillPropertyStateVector(
|
|
|
|
std::vector<XMLPropertyState>& rVector)
|
2001-03-02 07:55:06 +00:00
|
|
|
{
|
|
|
|
if (nCount)
|
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
rVector.resize(nCount, XMLPropertyState(-1));
|
|
|
|
XMLPropertyStateList_Impl::iterator aItr = aPropStates.begin();
|
|
|
|
sal_Int32 i (0);
|
|
|
|
while (aItr != aPropStates.end())
|
2001-03-02 07:55:06 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
rVector[i] = *aItr;
|
2001-03-02 07:55:06 +00:00
|
|
|
aItr++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
class FilterPropertyInfo_Impl
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
const rtl::OUString sApiName;
|
2001-02-23 15:35:33 +00:00
|
|
|
std::list<sal_uInt32> aIndexes;
|
|
|
|
sal_uInt32 nCount;
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
FilterPropertyInfo_Impl( const rtl::OUString& rApiName,
|
|
|
|
const sal_uInt32 nIndex);
|
|
|
|
|
|
|
|
const OUString& GetApiName() const { return sApiName; }
|
|
|
|
std::list<sal_uInt32>& GetIndexes() { return aIndexes; }
|
|
|
|
|
|
|
|
void AddIndex( sal_uInt32 nIndex )
|
|
|
|
{
|
|
|
|
aIndexes.push_back(nIndex);
|
|
|
|
nCount++;
|
|
|
|
}
|
2001-09-14 14:44:16 +00:00
|
|
|
|
|
|
|
// for sort
|
2002-02-08 12:12:45 +00:00
|
|
|
sal_Bool operator< ( const FilterPropertyInfo_Impl& rArg ) const
|
2001-09-14 14:44:16 +00:00
|
|
|
{
|
|
|
|
return (GetApiName() < rArg.GetApiName());
|
|
|
|
}
|
2001-02-23 15:35:33 +00:00
|
|
|
};
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
FilterPropertyInfo_Impl::FilterPropertyInfo_Impl(
|
|
|
|
const rtl::OUString& rApiName,
|
|
|
|
const sal_uInt32 nIndex ) :
|
|
|
|
sApiName( rApiName ),
|
|
|
|
aIndexes(),
|
|
|
|
nCount(1)
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
aIndexes.push_back(nIndex);
|
2001-02-23 15:35:33 +00:00
|
|
|
}
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
typedef std::list<FilterPropertyInfo_Impl> FilterPropertyInfoList_Impl;
|
2001-02-23 15:35:33 +00:00
|
|
|
|
2001-04-19 12:52:21 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FilterPropertiesInfo_Impl
|
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
sal_uInt32 nCount;
|
|
|
|
FilterPropertyInfoList_Impl aPropInfos;
|
|
|
|
FilterPropertyInfoList_Impl::iterator aLastItr;
|
|
|
|
|
|
|
|
Sequence <OUString> *pApiNames;
|
|
|
|
|
2001-02-23 15:35:33 +00:00
|
|
|
public:
|
2001-04-04 05:28:26 +00:00
|
|
|
FilterPropertiesInfo_Impl();
|
|
|
|
~FilterPropertiesInfo_Impl();
|
2001-02-23 15:35:33 +00:00
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
void AddProperty(const rtl::OUString& rApiName, const sal_uInt32 nIndex);
|
|
|
|
const uno::Sequence<OUString>& GetApiNames();
|
|
|
|
void FillPropertyStateArray(
|
|
|
|
vector< XMLPropertyState >& rPropStates,
|
|
|
|
const Reference< XPropertySet >& xPropSet,
|
|
|
|
const UniReference< XMLPropertySetMapper >& maPropMapper,
|
|
|
|
const sal_Bool bDefault = sal_False);
|
|
|
|
sal_uInt32 GetPropertyCount() const { return nCount; }
|
2001-02-23 15:35:33 +00:00
|
|
|
};
|
|
|
|
|
2001-04-19 12:52:21 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2001-03-29 13:24:33 +00:00
|
|
|
|
2001-04-19 12:52:21 +00:00
|
|
|
typedef std::hash_map
|
|
|
|
<
|
2003-03-27 17:21:03 +00:00
|
|
|
PropertySetInfoKey,
|
2001-04-19 12:52:21 +00:00
|
|
|
FilterPropertiesInfo_Impl *,
|
2003-03-27 17:21:03 +00:00
|
|
|
PropertySetInfoHash,
|
|
|
|
PropertySetInfoHash
|
2001-04-19 12:52:21 +00:00
|
|
|
>
|
|
|
|
FilterOropertiesHashMap_Impl;
|
2001-03-29 13:24:33 +00:00
|
|
|
|
2001-04-19 12:52:21 +00:00
|
|
|
class FilterPropertiesInfos_Impl : public FilterOropertiesHashMap_Impl
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-04-19 12:52:21 +00:00
|
|
|
public:
|
|
|
|
~FilterPropertiesInfos_Impl ();
|
|
|
|
};
|
|
|
|
|
|
|
|
FilterPropertiesInfos_Impl::~FilterPropertiesInfos_Impl ()
|
|
|
|
{
|
|
|
|
FilterOropertiesHashMap_Impl::iterator aIter = begin();
|
|
|
|
FilterOropertiesHashMap_Impl::iterator aEnd = end();
|
|
|
|
while( aIter != aEnd )
|
|
|
|
{
|
|
|
|
delete (*aIter).second;
|
|
|
|
(*aIter).second = 0;
|
2003-03-27 17:21:03 +00:00
|
|
|
++aIter;
|
2001-04-19 12:52:21 +00:00
|
|
|
}
|
2001-02-23 15:35:33 +00:00
|
|
|
}
|
|
|
|
|
2001-04-19 12:52:21 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
FilterPropertiesInfo_Impl::FilterPropertiesInfo_Impl() :
|
2001-04-04 05:28:26 +00:00
|
|
|
aPropInfos(),
|
|
|
|
nCount(0),
|
|
|
|
pApiNames( 0 )
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
aLastItr = aPropInfos.begin();
|
2001-02-23 15:35:33 +00:00
|
|
|
}
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
FilterPropertiesInfo_Impl::~FilterPropertiesInfo_Impl()
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
delete pApiNames;
|
2001-03-29 13:24:33 +00:00
|
|
|
}
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
void FilterPropertiesInfo_Impl::AddProperty(
|
|
|
|
const rtl::OUString& rApiName, const sal_uInt32 nIndex)
|
2001-03-29 13:24:33 +00:00
|
|
|
{
|
2001-07-25 14:31:11 +00:00
|
|
|
aPropInfos.push_back(FilterPropertyInfo_Impl(rApiName, nIndex));
|
|
|
|
nCount++;
|
2001-04-04 05:28:26 +00:00
|
|
|
|
|
|
|
OSL_ENSURE( !pApiNames, "perfomance warning: API names already retrieved" );
|
|
|
|
if( pApiNames )
|
|
|
|
{
|
|
|
|
delete pApiNames;
|
2001-07-25 14:31:11 +00:00
|
|
|
pApiNames = NULL;
|
2001-04-04 05:28:26 +00:00
|
|
|
}
|
2001-02-23 15:35:33 +00:00
|
|
|
}
|
2001-04-04 05:28:26 +00:00
|
|
|
const uno::Sequence<OUString>& FilterPropertiesInfo_Impl::GetApiNames()
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-07-04 12:52:07 +00:00
|
|
|
OSL_ENSURE(nCount == aPropInfos.size(), "wrong property count");
|
2001-04-04 05:28:26 +00:00
|
|
|
if( !pApiNames )
|
|
|
|
{
|
2001-07-25 14:31:11 +00:00
|
|
|
// we have to do three things:
|
|
|
|
// 1) sort API names,
|
|
|
|
// 2) merge duplicates,
|
|
|
|
// 3) construct sequence
|
|
|
|
|
|
|
|
// sort names
|
2001-09-14 14:44:16 +00:00
|
|
|
aPropInfos.sort();
|
2001-07-25 14:31:11 +00:00
|
|
|
|
|
|
|
// merge duplicates
|
|
|
|
if ( nCount > 1 )
|
|
|
|
{
|
|
|
|
FilterPropertyInfoList_Impl::iterator aOld = aPropInfos.begin();
|
|
|
|
FilterPropertyInfoList_Impl::iterator aEnd = aPropInfos.end();
|
|
|
|
FilterPropertyInfoList_Impl::iterator aCurrent = aOld;
|
|
|
|
aCurrent++;
|
|
|
|
|
|
|
|
while ( aCurrent != aEnd )
|
|
|
|
{
|
|
|
|
// equal to next element?
|
|
|
|
if ( aOld->GetApiName().equals( aCurrent->GetApiName() ) )
|
|
|
|
{
|
|
|
|
// if equal: merge index lists
|
|
|
|
aOld->GetIndexes().merge( aCurrent->GetIndexes() );
|
|
|
|
// erase element, and continue with next
|
|
|
|
aCurrent = aPropInfos.erase( aCurrent );
|
|
|
|
nCount--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// remember old element and continue with next
|
|
|
|
aOld = aCurrent;
|
|
|
|
aCurrent++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// construct sequence
|
2001-04-04 05:28:26 +00:00
|
|
|
pApiNames = new Sequence < OUString >( nCount );
|
|
|
|
OUString *pNames = pApiNames->getArray();
|
|
|
|
FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
|
2001-07-25 14:31:11 +00:00
|
|
|
FilterPropertyInfoList_Impl::iterator aEnd = aPropInfos.end();
|
|
|
|
for ( ; aItr != aEnd; aItr++, pNames++)
|
|
|
|
*pNames = aItr->GetApiName();
|
2001-04-04 05:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return *pApiNames;
|
2001-02-23 15:35:33 +00:00
|
|
|
}
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
void FilterPropertiesInfo_Impl::FillPropertyStateArray(
|
|
|
|
vector< XMLPropertyState >& rPropStates,
|
|
|
|
const Reference< XPropertySet >& rPropSet,
|
|
|
|
const UniReference< XMLPropertySetMapper >& rPropMapper,
|
|
|
|
const sal_Bool bDefault )
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
XMLPropertyStates_Impl aPropStates;
|
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
const uno::Sequence<OUString>& rApiNames = GetApiNames();
|
|
|
|
|
|
|
|
Sequence < PropertyState > aStates;
|
|
|
|
const PropertyState *pStates = 0;
|
|
|
|
Reference< XPropertyState > xPropState( rPropSet, UNO_QUERY );
|
|
|
|
if( xPropState.is() )
|
|
|
|
{
|
|
|
|
aStates = xPropState->getPropertyStates( rApiNames );
|
|
|
|
pStates = aStates.getConstArray();
|
|
|
|
}
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
Reference < XMultiPropertySet > xMultiPropSet( rPropSet, UNO_QUERY );
|
|
|
|
if( xMultiPropSet.is() && !bDefault )
|
|
|
|
{
|
2001-04-18 07:53:19 +00:00
|
|
|
Sequence < Any > aValues;
|
|
|
|
if( pStates )
|
2001-04-04 05:28:26 +00:00
|
|
|
{
|
2001-04-18 07:53:19 +00:00
|
|
|
// step 1: get value count
|
|
|
|
sal_uInt32 nValueCount = 0;
|
|
|
|
for( sal_uInt32 i = 0; i < nCount; i++, pStates++ )
|
|
|
|
{
|
|
|
|
if( *pStates == PropertyState_DIRECT_VALUE )
|
|
|
|
nValueCount++;
|
|
|
|
}
|
2001-04-04 05:28:26 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
if( nValueCount )
|
|
|
|
{
|
|
|
|
// step 2: collect property names
|
|
|
|
Sequence < OUString > aAPINames( nValueCount );
|
|
|
|
OUString *pAPINames = aAPINames.getArray();
|
2001-04-04 05:28:26 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
FilterPropertyInfoList_Impl::iterator *aPropIters =
|
|
|
|
new FilterPropertyInfoList_Impl::iterator[nValueCount];
|
|
|
|
FilterPropertyInfoList_Impl::iterator *pPropIter = aPropIters;
|
2001-04-04 05:28:26 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
|
2001-04-04 05:28:26 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
pStates = aStates.getConstArray();
|
|
|
|
i = 0;
|
|
|
|
while( i < nValueCount )
|
2001-04-04 05:28:26 +00:00
|
|
|
{
|
2001-04-18 07:53:19 +00:00
|
|
|
if( *pStates == PropertyState_DIRECT_VALUE )
|
|
|
|
{
|
|
|
|
*pAPINames++ = aItr->GetApiName();
|
|
|
|
*pPropIter++ = aItr;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
aItr++;
|
|
|
|
pStates++;
|
2001-04-04 05:28:26 +00:00
|
|
|
}
|
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
aValues = xMultiPropSet->getPropertyValues( aAPINames );
|
|
|
|
const Any *pValues = aValues.getConstArray();
|
|
|
|
pPropIter = aPropIters;
|
2001-06-07 08:43:41 +00:00
|
|
|
XMLPropertyState aNewProperty( -1 );
|
2001-04-18 07:53:19 +00:00
|
|
|
for( i = 0; i < nValueCount; i++ )
|
|
|
|
{
|
2001-06-07 08:43:41 +00:00
|
|
|
aNewProperty.mnIndex = -1;
|
2001-04-18 07:53:19 +00:00
|
|
|
aNewProperty.maValue = *pValues;
|
|
|
|
|
|
|
|
for( std::list<sal_uInt32>::iterator aIndexItr =
|
|
|
|
(*pPropIter)->GetIndexes().begin();
|
|
|
|
aIndexItr != (*pPropIter)->GetIndexes().end();
|
|
|
|
aIndexItr++ )
|
|
|
|
{
|
|
|
|
aNewProperty.mnIndex = *aIndexItr;
|
|
|
|
aPropStates.AddPropertyState( aNewProperty );
|
|
|
|
}
|
|
|
|
|
|
|
|
pPropIter++;
|
|
|
|
pValues++;
|
|
|
|
}
|
2002-04-24 09:43:44 +00:00
|
|
|
delete[] aPropIters;
|
2001-04-18 07:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aValues = xMultiPropSet->getPropertyValues( rApiNames );
|
2001-04-04 05:28:26 +00:00
|
|
|
const Any *pValues = aValues.getConstArray();
|
2001-04-18 07:53:19 +00:00
|
|
|
|
|
|
|
FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
|
|
|
|
for(sal_uInt32 i = 0; i < nCount; i++ )
|
2001-04-04 05:28:26 +00:00
|
|
|
{
|
2001-04-18 07:53:19 +00:00
|
|
|
// The value is stored in the PropertySet itself, add to list.
|
|
|
|
sal_Bool bGotValue = sal_False;
|
2001-04-04 05:28:26 +00:00
|
|
|
XMLPropertyState aNewProperty( -1 );
|
|
|
|
aNewProperty.maValue = *pValues;
|
|
|
|
for( std::list<sal_uInt32>::iterator aIndexItr =
|
2001-04-18 07:53:19 +00:00
|
|
|
aItr->GetIndexes().begin();
|
|
|
|
aIndexItr != aItr->GetIndexes().end();
|
2001-04-04 05:28:26 +00:00
|
|
|
aIndexItr++ )
|
|
|
|
{
|
|
|
|
aNewProperty.mnIndex = *aIndexItr;
|
|
|
|
aPropStates.AddPropertyState( aNewProperty );
|
|
|
|
}
|
2001-04-18 07:53:19 +00:00
|
|
|
aItr++;
|
2001-04-04 05:28:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin();
|
2001-04-18 07:53:19 +00:00
|
|
|
for(sal_uInt32 i = 0; i < nCount; i++ )
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-04-18 07:53:19 +00:00
|
|
|
sal_Bool bDirectValue =
|
|
|
|
!pStates || *pStates == PropertyState_DIRECT_VALUE;
|
2001-04-04 05:28:26 +00:00
|
|
|
if( bDirectValue || bDefault )
|
2001-02-23 15:35:33 +00:00
|
|
|
{
|
2001-04-04 05:28:26 +00:00
|
|
|
// The value is stored in the PropertySet itself, add to list.
|
|
|
|
sal_Bool bGotValue = sal_False;
|
|
|
|
XMLPropertyState aNewProperty( -1 );
|
|
|
|
for( std::list<sal_uInt32>::iterator aIndexItr =
|
|
|
|
aItr->GetIndexes().begin();
|
|
|
|
aIndexItr != aItr->GetIndexes().end();
|
|
|
|
aIndexItr++ )
|
|
|
|
{
|
|
|
|
if( bDirectValue ||
|
|
|
|
(rPropMapper->GetEntryFlags( *aIndexItr ) &
|
|
|
|
MID_FLAG_DEFAULT_ITEM_EXPORT) != 0 )
|
|
|
|
{
|
2001-04-04 12:23:01 +00:00
|
|
|
try
|
2001-04-04 05:28:26 +00:00
|
|
|
{
|
2001-04-04 12:23:01 +00:00
|
|
|
if( !bGotValue )
|
|
|
|
{
|
|
|
|
aNewProperty.maValue =
|
|
|
|
rPropSet->getPropertyValue( aItr->GetApiName() );
|
|
|
|
bGotValue = sal_True;
|
|
|
|
}
|
|
|
|
aNewProperty.mnIndex = *aIndexItr;
|
|
|
|
aPropStates.AddPropertyState( aNewProperty );
|
2001-04-04 05:28:26 +00:00
|
|
|
}
|
2001-04-04 12:23:01 +00:00
|
|
|
catch( UnknownPropertyException& )
|
|
|
|
{
|
|
|
|
// might be a problem of getImplemenetationId
|
|
|
|
OSL_ENSURE( !this, "unknown property in getPropertyValue" );
|
|
|
|
}
|
|
|
|
|
2001-04-04 05:28:26 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-23 15:35:33 +00:00
|
|
|
}
|
2001-04-18 07:53:19 +00:00
|
|
|
|
|
|
|
aItr++;
|
|
|
|
if( pStates )
|
|
|
|
pStates++;
|
2001-02-23 15:35:33 +00:00
|
|
|
}
|
|
|
|
}
|
2001-04-04 05:28:26 +00:00
|
|
|
aPropStates.FillPropertyStateVector(rPropStates);
|
2001-02-23 15:35:33 +00:00
|
|
|
}
|
|
|
|
|
2001-03-29 13:24:33 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ctor/dtor , class SvXMLExportPropertyMapper
|
|
|
|
//
|
|
|
|
|
|
|
|
SvXMLExportPropertyMapper::SvXMLExportPropertyMapper(
|
|
|
|
const UniReference< XMLPropertySetMapper >& rMapper ) :
|
|
|
|
maPropMapper( rMapper ),
|
|
|
|
pCache( 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SvXMLExportPropertyMapper::~SvXMLExportPropertyMapper()
|
|
|
|
{
|
|
|
|
delete pCache;
|
|
|
|
mxNextMapper = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SvXMLExportPropertyMapper::ChainExportMapper(
|
|
|
|
const UniReference< SvXMLExportPropertyMapper>& rMapper )
|
|
|
|
{
|
|
|
|
// add map entries from rMapper to current map
|
|
|
|
maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() );
|
|
|
|
// rMapper uses the same map as 'this'
|
|
|
|
rMapper->maPropMapper = maPropMapper;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mxNextMapper = rMapper;
|
|
|
|
|
|
|
|
// if rMapper was already chained, correct
|
|
|
|
// map pointer of successors
|
|
|
|
xNext = rMapper;
|
|
|
|
|
|
|
|
while( xNext->mxNextMapper.is())
|
|
|
|
{
|
|
|
|
xNext = xNext->mxNextMapper;
|
|
|
|
xNext->maPropMapper = maPropMapper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-27 15:39:44 +00:00
|
|
|
vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter(
|
|
|
|
const Reference< XPropertySet > xPropSet,
|
|
|
|
const sal_Bool bDefault ) const
|
2000-11-07 12:33:09 +00:00
|
|
|
{
|
|
|
|
vector< XMLPropertyState > aPropStateArray;
|
|
|
|
|
|
|
|
// Retrieve XPropertySetInfo and XPropertyState
|
|
|
|
Reference< XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
|
2001-04-18 07:53:19 +00:00
|
|
|
if( !xInfo.is() )
|
|
|
|
return aPropStateArray;
|
2000-11-07 12:33:09 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
sal_Int32 nProps = maPropMapper->GetEntryCount();
|
2000-11-07 12:33:09 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
FilterPropertiesInfo_Impl *pFilterInfo = 0;
|
2001-04-03 09:13:07 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
Reference < XTypeProvider > xTypeProv( xPropSet, UNO_QUERY );
|
2001-04-19 12:52:21 +00:00
|
|
|
Sequence< sal_Int8 > aImplId;
|
2001-04-18 07:53:19 +00:00
|
|
|
if( xTypeProv.is() )
|
|
|
|
{
|
2001-04-19 12:52:21 +00:00
|
|
|
aImplId = xTypeProv->getImplementationId();
|
2001-04-18 07:53:19 +00:00
|
|
|
if( aImplId.getLength() == 16 )
|
|
|
|
{
|
|
|
|
if( pCache )
|
2000-11-07 12:33:09 +00:00
|
|
|
{
|
2001-04-19 12:52:21 +00:00
|
|
|
// The key must not be created outside this block, because it
|
|
|
|
// keeps a reference to the property set info.
|
2003-03-27 17:21:03 +00:00
|
|
|
PropertySetInfoKey aKey( xInfo, aImplId );
|
2001-04-19 12:52:21 +00:00
|
|
|
FilterPropertiesInfos_Impl::iterator aIter =
|
|
|
|
pCache->find( aKey );
|
|
|
|
if( aIter != pCache->end() )
|
|
|
|
pFilterInfo = (*aIter).second;
|
2000-11-07 12:33:09 +00:00
|
|
|
}
|
2001-04-18 07:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2000-11-07 12:33:09 +00:00
|
|
|
|
2001-04-19 12:52:21 +00:00
|
|
|
sal_Bool bDelInfo = sal_False;
|
|
|
|
if( !pFilterInfo )
|
2001-04-18 07:53:19 +00:00
|
|
|
{
|
2001-04-19 12:52:21 +00:00
|
|
|
pFilterInfo = new FilterPropertiesInfo_Impl;
|
2001-04-18 07:53:19 +00:00
|
|
|
for( sal_Int32 i=0; i < nProps; i++ )
|
|
|
|
{
|
|
|
|
// Are we allowed to ask for the property? (MID_FLAG_NO_PROP..)
|
|
|
|
// Does the PropertySet contain name of mpEntries-array ?
|
|
|
|
const OUString& rAPIName = maPropMapper->GetEntryAPIName( i );
|
|
|
|
const sal_Int32 nFlags = maPropMapper->GetEntryFlags( i );
|
|
|
|
if( (0 == (nFlags & MID_FLAG_NO_PROPERTY_EXPORT)) &&
|
|
|
|
( (0 != (nFlags & MID_FLAG_MUST_EXIST)) ||
|
|
|
|
xInfo->hasPropertyByName( rAPIName ) ) )
|
|
|
|
pFilterInfo->AddProperty(rAPIName, i);
|
|
|
|
}
|
2001-04-19 12:52:21 +00:00
|
|
|
|
|
|
|
if( xTypeProv.is() && aImplId.getLength() == 16 )
|
|
|
|
{
|
|
|
|
// Check whether the property set info is destroyed if it is
|
|
|
|
// assigned to a weak reference only. If it is destroyed, then
|
|
|
|
// every instance of getPropertySetInfo returns a new object.
|
|
|
|
// Such property set infos must not be cached.
|
|
|
|
WeakReference < XPropertySetInfo > xWeakInfo( xInfo );
|
|
|
|
xInfo = 0;
|
|
|
|
xInfo = xWeakInfo;
|
|
|
|
if( xInfo.is() )
|
|
|
|
{
|
|
|
|
if( !pCache )
|
|
|
|
((SvXMLExportPropertyMapper *)this)->pCache =
|
|
|
|
new FilterPropertiesInfos_Impl;
|
2003-03-27 17:21:03 +00:00
|
|
|
PropertySetInfoKey aKey( xInfo, aImplId );
|
2001-04-19 12:52:21 +00:00
|
|
|
(*pCache)[aKey] = pFilterInfo;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bDelInfo = sal_True;
|
2001-12-06 18:41:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_ENSURE(sal_False, "here is no TypeProvider or the ImplId is wrong");
|
|
|
|
bDelInfo = sal_True;
|
2001-04-19 12:52:21 +00:00
|
|
|
}
|
2001-04-18 07:53:19 +00:00
|
|
|
}
|
2000-11-07 12:33:09 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
if( pFilterInfo->GetPropertyCount() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pFilterInfo->FillPropertyStateArray(aPropStateArray,
|
|
|
|
xPropSet, maPropMapper,
|
|
|
|
bDefault);
|
2000-11-07 12:33:09 +00:00
|
|
|
}
|
2001-04-18 07:53:19 +00:00
|
|
|
catch( UnknownPropertyException& )
|
2000-11-07 12:33:09 +00:00
|
|
|
{
|
2001-04-18 07:53:19 +00:00
|
|
|
// might be a problem of getImplemenetationId
|
|
|
|
OSL_ENSURE( !this, "unknown property in getPropertyStates" );
|
2000-11-07 12:33:09 +00:00
|
|
|
}
|
2001-04-18 07:53:19 +00:00
|
|
|
}
|
2000-11-07 12:33:09 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
// Call centext-filter
|
2001-11-01 12:34:16 +00:00
|
|
|
if( aPropStateArray.size() > 0 )
|
|
|
|
ContextFilter( aPropStateArray, xPropSet );
|
2000-12-15 12:52:14 +00:00
|
|
|
|
2001-04-18 07:53:19 +00:00
|
|
|
// 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++;
|
|
|
|
}*/
|
2000-11-07 12:33:09 +00:00
|
|
|
|
2001-04-19 12:52:21 +00:00
|
|
|
if( bDelInfo )
|
|
|
|
delete pFilterInfo;
|
|
|
|
|
2000-11-07 12:33:09 +00:00
|
|
|
return aPropStateArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2001-03-29 13:24:33 +00:00
|
|
|
sal_uInt32 nCount = aProperties1.size();
|
2000-11-07 12:33:09 +00:00
|
|
|
|
|
|
|
if( nCount == aProperties2.size() )
|
|
|
|
{
|
2001-03-29 13:24:33 +00:00
|
|
|
sal_uInt32 nIndex = 0;
|
2000-11-07 12:33:09 +00:00
|
|
|
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(
|
2001-10-25 19:57:03 +00:00
|
|
|
SvXMLExport& rExport,
|
2000-10-19 13:25:20 +00:00
|
|
|
const ::std::vector< XMLPropertyState >& rProperties,
|
|
|
|
sal_uInt16 nFlags ) const
|
2000-10-25 11:39:31 +00:00
|
|
|
{
|
2001-10-25 19:57:03 +00:00
|
|
|
exportXML( rExport, rProperties, -1, -1, nFlags );
|
2000-10-25 11:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SvXMLExportPropertyMapper::exportXML(
|
2001-10-25 19:57:03 +00:00
|
|
|
SvXMLExport& rExport,
|
2000-10-25 11:39:31 +00:00
|
|
|
const ::std::vector< XMLPropertyState >& rProperties,
|
|
|
|
sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx,
|
|
|
|
sal_uInt16 nFlags ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
SvUShorts aIndexArray;
|
|
|
|
|
2001-10-25 19:57:03 +00:00
|
|
|
_exportXML( rExport.GetAttrList(), rProperties,
|
|
|
|
rExport.GetMM100UnitConverter(), rExport.GetNamespaceMap(),
|
2000-10-25 11:39:31 +00:00
|
|
|
nFlags, &aIndexArray, nPropMapStartIdx, nPropMapEndIdx );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-10-25 19:57:03 +00:00
|
|
|
if( rExport.GetAttrList().getLength() > 0L ||
|
|
|
|
(nFlags & XML_EXPORT_FLAG_EMPTY) != 0 ||
|
2000-10-19 13:25:20 +00:00
|
|
|
aIndexArray.Count() != 0 )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-10-25 19:57:03 +00:00
|
|
|
SvXMLElementExport aElem( rExport, XML_NAMESPACE_STYLE, XML_PROPERTIES,
|
|
|
|
(nFlags & XML_EXPORT_FLAG_IGN_WS) != 0,
|
|
|
|
sal_False );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-10-25 19:57:03 +00:00
|
|
|
exportElementItems( rExport, rProperties, nFlags, aIndexArray );
|
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_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-07-04 12:52:07 +00:00
|
|
|
OSL_ENSURE( mxNextMapper.is(), "special item not handled in xml export" );
|
2001-01-17 09:51:33 +00:00
|
|
|
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(
|
2001-10-25 19:57:03 +00:00
|
|
|
SvXMLExport& rExport,
|
2000-10-19 13:25:20 +00:00
|
|
|
const XMLPropertyState& rProperty,
|
|
|
|
sal_uInt16 nFlags,
|
|
|
|
const ::std::vector< XMLPropertyState > *pProperties,
|
|
|
|
sal_uInt32 nIdx ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-07-04 12:52:07 +00:00
|
|
|
OSL_ENSURE( mxNextMapper.is(), "element item not handled in xml export" );
|
2001-01-17 09:51:33 +00:00
|
|
|
if( mxNextMapper.is() )
|
2001-10-25 19:57:03 +00:00
|
|
|
mxNextMapper->handleElementItem( rExport, rProperty, 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 )
|
2001-04-18 07:53:19 +00:00
|
|
|
pIndexArray->Insert( (sal_uInt16)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
|
|
|
{
|
2001-06-29 20:07:26 +00:00
|
|
|
OUString sCDATA( GetXMLToken(XML_CDATA) );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
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.
|
2001-07-10 16:12:09 +00:00
|
|
|
sal_uInt16 nKey = pNamespaceMap->GetKeyByPrefix( sPrefix );
|
|
|
|
if( USHRT_MAX == nKey || pNamespaceMap->GetNameByKey( nKey ) != 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 );
|
|
|
|
|
2001-06-29 20:07:26 +00:00
|
|
|
sName.append( GetXMLToken(XML_XMLNS) );
|
2000-09-18 16:07:07 +00:00
|
|
|
sName.append( sal_Unicode(':') );
|
|
|
|
sName.append( sPrefix );
|
2003-03-27 17:21:03 +00:00
|
|
|
rAttrList.AddAttribute( sName.makeStringAndClear(),
|
2000-09-18 16:07:07 +00:00
|
|
|
sNamespace );
|
|
|
|
}
|
|
|
|
}
|
2003-03-27 17:21:03 +00:00
|
|
|
OSL_ENSURE(aData.Type == GetXMLToken(XML_CDATA), "different type to our default type which should be written out");
|
|
|
|
rAttrList.AddAttribute( *pAttribName, 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 );
|
2003-03-27 17:21:03 +00:00
|
|
|
rAttrList.AddAttribute( sName, aValue );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-19 13:25:20 +00:00
|
|
|
void SvXMLExportPropertyMapper::exportElementItems(
|
2001-10-25 19:57:03 +00:00
|
|
|
SvXMLExport& rExport,
|
2000-10-19 13:25:20 +00:00
|
|
|
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;
|
2001-06-29 20:07:26 +00:00
|
|
|
OUString sWS( GetXMLToken(XML_WS) );
|
2000-09-18 16:07:07 +00:00
|
|
|
for( sal_uInt16 nIndex = 0; nIndex < nCount; nIndex++ )
|
|
|
|
{
|
|
|
|
const sal_uInt16 nElement = rIndexArray.GetObject( nIndex );
|
|
|
|
|
2001-07-04 12:52:07 +00:00
|
|
|
OSL_ENSURE( 0 != ( maPropMapper->GetEntryFlags(
|
2000-10-19 13:25:20 +00:00
|
|
|
rProperties[nElement].mnIndex ) & MID_FLAG_ELEMENT_ITEM_EXPORT),
|
|
|
|
"wrong mid flag!" );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-10-25 19:57:03 +00:00
|
|
|
rExport.IgnorableWhitespace();
|
|
|
|
handleElementItem( rExport, rProperties[nElement],
|
|
|
|
nFlags, &rProperties, nElement );
|
2000-09-18 16:07:07 +00:00
|
|
|
bItemsExported = sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bItemsExported )
|
2001-10-25 19:57:03 +00:00
|
|
|
rExport.IgnorableWhitespace();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|