xref: /trunk/main/xmloff/inc/xmloff/xmlimppr.hxx (revision 055aaed46ae13807e8ff8b5002b11ec66f578b5d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _XMLOFF_XMLIMPPR_HXX
25 #define _XMLOFF_XMLIMPPR_HXX
26 
27 #include "sal/config.h"
28 #include "xmloff/dllapi.h"
29 #include "sal/types.h"
30 #include <tools/solar.h>
31 #include <com/sun/star/xml/sax/XAttributeList.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYVALUE_HPP_
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #endif
36 #include <com/sun/star/beans/XMultiPropertySet.hpp>
37 #include <com/sun/star/beans/XTolerantMultiPropertySet.hpp>
38 
39 #ifndef __SGI_STL_VECTOR
40 #include <vector>
41 #endif
42 #include <xmloff/uniref.hxx>
43 
44 struct XMLPropertyState;
45 class XMLPropertySetMapper;
46 
47 namespace rtl { class OUString; }
48 
49 class SvXMLUnitConverter;
50 class SvXMLNamespaceMap;
51 class SvXMLImport;
52 
53 /** This struct is used as an optional parameter to the static
54  * _FillPropertySet() methods.
55  *
56  * It should not be used in any other context.
57  */
58 struct _ContextID_Index_Pair
59 {
60     sal_Int16 nContextID;
61     sal_Int32 nIndex;
62 };
63 
64 class XMLOFF_DLLPUBLIC SvXMLImportPropertyMapper : public UniRefBase
65 {
66     UniReference< SvXMLImportPropertyMapper> mxNextMapper;
67 
68     SvXMLImport& rImport; // access to error handling
69 
70     SAL_DLLPRIVATE SvXMLImportPropertyMapper(SvXMLImportPropertyMapper &);
71         // not defined
72     SAL_DLLPRIVATE void operator =(SvXMLImportPropertyMapper &); // not defined
73 
74 protected:
75 
76     UniReference< XMLPropertySetMapper > maPropMapper;
GetImport() const77     SvXMLImport& GetImport() const { return rImport;}
78 
79 public:
80 
81     SvXMLImportPropertyMapper(
82             const UniReference< XMLPropertySetMapper >& rMapper,
83             SvXMLImport& rImport);
84     virtual ~SvXMLImportPropertyMapper();
85 
86     // Add a ImportPropertyMapper at the end of the import mapper chain.
87     // The added mapper MUST not be used outside the Mapper chain any longer,
88     // because its PropertyMapper will be replaced.
89     void ChainImportMapper(
90         const UniReference< SvXMLImportPropertyMapper>& rMapper );
91 
92     /** fills the given itemset with the attributes in the given list */
93     void importXML(
94             ::std::vector< XMLPropertyState >& rProperties,
95             ::com::sun::star::uno::Reference<
96                     ::com::sun::star::xml::sax::XAttributeList > xAttrList,
97             const SvXMLUnitConverter& rUnitConverter,
98             const SvXMLNamespaceMap& rNamespaceMap,
99             sal_uInt32 nPropType    ) const;
100 
101     /** like above, except that the map is only searched within the range
102      *  [nStartIdx, nEndIdx[
103      */
104     void importXML(
105             ::std::vector< XMLPropertyState >& rProperties,
106             ::com::sun::star::uno::Reference<
107                     ::com::sun::star::xml::sax::XAttributeList > xAttrList,
108             const SvXMLUnitConverter& rUnitConverter,
109             const SvXMLNamespaceMap& rNamespaceMap,
110             sal_uInt32 nPropType,
111             sal_Int32 nStartIdx, sal_Int32 nEndIdx ) const;
112 
113     /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */
114     virtual sal_Bool handleSpecialItem(
115             XMLPropertyState& rProperty,
116             ::std::vector< XMLPropertyState >& rProperties,
117             const ::rtl::OUString& rValue,
118             const SvXMLUnitConverter& rUnitConverter,
119             const SvXMLNamespaceMap& rNamespaceMap ) const;
120 
121     /** This method is called when all attributes have been processed. It may be used to remove items that are incomplete */
122     virtual void finished(
123             ::std::vector< XMLPropertyState >& rProperties,
124             sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const;
125 
126     void CheckSpecialContext(
127             const ::std::vector< XMLPropertyState >& aProperties,
128             const ::com::sun::star::uno::Reference<
129                     ::com::sun::star::beans::XPropertySet > rPropSet,
130             _ContextID_Index_Pair* pSpecialContextIds ) const;
131 
132     sal_Bool FillPropertySet(
133             const ::std::vector< XMLPropertyState >& aProperties,
134             const ::com::sun::star::uno::Reference<
135                     ::com::sun::star::beans::XPropertySet > rPropSet,
136             _ContextID_Index_Pair* pSpecialContextIds = NULL ) const;
137 
138     void FillPropertySequence(
139             const ::std::vector< XMLPropertyState >& aProperties,
140             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rValues )
141             const;
142 
143     inline const UniReference< XMLPropertySetMapper >&
144         getPropertySetMapper() const;
145 
146 
147 
148     /** implementation helper for FillPropertySet: fill an XPropertySet.
149      *  Exceptions will be asserted. */
150     static sal_Bool _FillPropertySet(
151         const ::std::vector<XMLPropertyState> & rProperties,
152         const ::com::sun::star::uno::Reference<
153             ::com::sun::star::beans::XPropertySet> & rPropSet,
154         const ::com::sun::star::uno::Reference<
155             ::com::sun::star::beans::XPropertySetInfo> & rPropSetInfo,
156         const UniReference<XMLPropertySetMapper> & rPropMapper,
157         SvXMLImport& rImport,
158 
159         // parameter for use by txtstyli.cxx; allows efficient
160         // catching the combined characters property
161         _ContextID_Index_Pair* pSpecialContextIds = NULL );
162 
163     /** implementation helper for FillPropertySet: fill an XMultiPropertySet.
164      *  If unsuccessful, set return value. */
165     static sal_Bool _FillMultiPropertySet(
166         const ::std::vector<XMLPropertyState> & rProperties,
167         const ::com::sun::star::uno::Reference<
168             ::com::sun::star::beans::XMultiPropertySet> & rMultiPropSet,
169         const ::com::sun::star::uno::Reference<
170             ::com::sun::star::beans::XPropertySetInfo> & rPropSetInfo,
171         const UniReference<XMLPropertySetMapper> & rPropMapper,
172 
173         // parameters for use by txtstyli.cxx; allows efficient
174         // catching the combined characters property
175         _ContextID_Index_Pair* pSpecialContextIds = NULL );
176 
177     /** implementation helper for FillPropertySet: fill an XTolerantMultiPropertySet.
178      *  If unsuccessful, set return value. */
179     static sal_Bool _FillTolerantMultiPropertySet(
180         const ::std::vector<XMLPropertyState> & rProperties,
181         const ::com::sun::star::uno::Reference<
182             ::com::sun::star::beans::XTolerantMultiPropertySet> & rTolPropSet,
183         const UniReference<XMLPropertySetMapper> & rPropMapper,
184         SvXMLImport& rImport,
185 
186         // parameters for use by txtstyli.cxx; allows efficient
187         // catching the combined characters property
188         _ContextID_Index_Pair* pSpecialContextIds = NULL );
189 
190 
191     static void _PrepareForMultiPropertySet(
192         const ::std::vector<XMLPropertyState> & rProperties,
193         const ::com::sun::star::uno::Reference<
194             ::com::sun::star::beans::XPropertySetInfo> & rPropSetInfo,
195         const UniReference<XMLPropertySetMapper> & rPropMapper,
196         _ContextID_Index_Pair* pSpecialContextIds,
197         ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames,
198         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues);
199 };
200 
201 
202 inline const UniReference< XMLPropertySetMapper >&
getPropertySetMapper() const203     SvXMLImportPropertyMapper::getPropertySetMapper() const
204 {
205     return maPropMapper;
206 }
207 
208 #endif // _XMLOFF_XMLIMPPR_HXX
209