merge the formfield patch from ooo-build
[ooovba.git] / binfilter / inc / bf_xmloff / xmlprmap.hxx
bloba743094dfe35c4a5d1225e69a4db78240766ff00
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlprmap.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _XMLOFF_PROPERTYSETMAPPER_HXX
32 #define _XMLOFF_PROPERTYSETMAPPER_HXX
34 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
35 #include <com/sun/star/uno/Sequence.hxx>
36 #endif
38 #ifndef _COM_SUN_STAR_UNO_ANY_HXX_
39 #include <com/sun/star/uno/Any.hxx>
40 #endif
42 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #endif
46 #ifndef __SGI_STL_VECTOR
47 #include <vector>
48 #endif
50 #ifndef _UNIVERSALL_REFERENCE_HXX
51 #include <bf_xmloff/uniref.hxx>
52 #endif
54 #ifndef _XMLOFF_PROPMAPPINGTYPES_HXX
55 #include <bf_xmloff/maptype.hxx>
56 #endif
58 #ifndef _XMLOFF_XMLTYPES_HXX
59 #include <bf_xmloff/xmltypes.hxx>
60 #endif
62 #ifndef _XMLOFF_PROPERTYHANDLERFACTORY_HXX
63 #include <bf_xmloff/prhdlfac.hxx>
64 #endif
65 namespace binfilter {
67 class SvXMLUnitConverter;
68 class XMLPropertyHandler;
70 ///////////////////////////////////////////////////////////////////////////
72 /** Helper-class for XML-im/export:
73 - Holds a pointer to a given array of XMLPropertyMapEntry
74 - Provides several methods to access data from this array
75 - Holds a Sequence of XML-names (for properties)
76 - The filter takes all properties of the XPropertySet which are also
77 in the XMLPropertyMapEntry and which are have not a default value
78 and put them into a vector of XMLPropertyStae
79 - this class knows how to compare, im/export properties
81 Attention: At all methods, which get an index as parameter, there is no
82 range validation to save runtime !!
84 struct XMLPropertySetMapperEntry_Impl
86 ::rtl::OUString sXMLAttributeName;
87 ::rtl::OUString sAPIPropertyName;
88 sal_uInt16 nXMLNameSpace;
89 sal_Int32 nType;
90 sal_Int16 nContextId;
91 const XMLPropertyHandler *pHdl;
93 XMLPropertySetMapperEntry_Impl(
94 const XMLPropertyMapEntry& rMapEntry,
95 const UniReference< XMLPropertyHandlerFactory >& rFactory );
97 XMLPropertySetMapperEntry_Impl(
98 const XMLPropertySetMapperEntry_Impl& rEntry );
101 class XMLPropertySetMapper : public UniRefBase
103 ::std::vector< XMLPropertySetMapperEntry_Impl > aMapEntries;
104 ::std::vector< UniReference < XMLPropertyHandlerFactory > > aHdlFactories;
106 public:
107 /** The last element of the XMLPropertyMapEntry-array must contain NULL-values */
108 XMLPropertySetMapper(
109 const XMLPropertyMapEntry* pEntries,
110 const UniReference< XMLPropertyHandlerFactory >& rFactory );
111 virtual ~XMLPropertySetMapper();
113 void AddMapperEntry( const UniReference < XMLPropertySetMapper >& rMapper );
115 /** Return number of entries in input-array */
116 const sal_Int32 GetEntryCount() const { return aMapEntries.size(); }
118 /** Returns the flags of an entry */
119 const sal_uInt32 GetEntryFlags( sal_Int32 nIndex ) const
121 return aMapEntries[nIndex].nType & ~MID_FLAG_MASK;
124 /** Returns the type of an entry */
125 const sal_uInt32 GetEntryType( sal_Int32 nIndex,
126 sal_Bool bWithFlags = sal_True ) const
128 sal_uInt32 nType = aMapEntries[nIndex].nType;
129 if( !bWithFlags )
130 nType = nType & MID_FLAG_MASK;
131 return nType;
134 /** Returns the namespace-key of an entry */
135 const sal_uInt16 GetEntryNameSpace( sal_Int32 nIndex ) const
137 return aMapEntries[nIndex].nXMLNameSpace;
140 /** Returns the 'local' XML-name of the entry */
141 const ::rtl::OUString& GetEntryXMLName( sal_Int32 nIndex ) const
143 return aMapEntries[nIndex].sXMLAttributeName;
146 /** Returns the entry API name */
147 const ::rtl::OUString& GetEntryAPIName( sal_Int32 nIndex ) const
149 return aMapEntries[nIndex].sAPIPropertyName;
152 /** returns the entry context id */
153 const sal_Int16 GetEntryContextId( sal_Int32 nIndex ) const
155 return nIndex == -1 ? 0 : aMapEntries[nIndex].nContextId;
158 /** Returns the index of an entry with the given XML-name and namespace
159 If there is no matching entry the method returns -1 */
160 const sal_Int32 GetEntryIndex( sal_uInt16 nNamespace,
161 const ::rtl::OUString& rStrName,
162 sal_Int32 nStartAt = -1 ) const;
164 /** Retrieves a PropertyHandler for that property wich placed at nIndex in the XMLPropertyMapEntry-array */
165 const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nIndex ) const
167 return aMapEntries[nIndex].pHdl;
170 /** import/export
171 This methods calls the respective im/export-method of the respective PropertyHandler. */
172 virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue,
173 const XMLPropertyState& rProperty,
174 const SvXMLUnitConverter& rUnitConverter ) const;
175 virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue,
176 XMLPropertyState& rProperty,
177 const SvXMLUnitConverter& rUnitConverter ) const;
179 /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
180 sal_Int32 FindEntryIndex( const sal_Char* sApiName,
181 sal_uInt16 nNameSpace,
182 const ::rtl::OUString& sXMLName ) const;
184 /** searches for an entry that matches the given ContextId or gives -1 if nothing found */
185 sal_Int32 FindEntryIndex( const sal_Int16 nContextId ) const;
188 }//end of namespace binfilter
189 #endif // _XMLOFF_PROPERTYSETMAPPER_HXX