xref: /AOO41X/main/xmloff/inc/xmloff/xmlimppr.hxx (revision ecfe53c5d1886e1e0d215b0d140d05282ab1c477)
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 #ifndef _XMLOFF_XMLIMPPR_HXX
24 #define _XMLOFF_XMLIMPPR_HXX
25 
26 #include "sal/config.h"
27 #include "xmloff/dllapi.h"
28 #include "sal/types.h"
29 #include <tools/solar.h>
30 #include <com/sun/star/xml/sax/XAttributeList.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYVALUE_HPP_
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #endif
35 #include <com/sun/star/beans/XMultiPropertySet.hpp>
36 #include <com/sun/star/beans/XTolerantMultiPropertySet.hpp>
37 
38 #ifndef __SGI_STL_VECTOR
39 #include <vector>
40 #endif
41 #include <xmloff/uniref.hxx>
42 
43 struct XMLPropertyState;
44 class XMLPropertySetMapper;
45 
46 namespace rtl { class OUString; }
47 
48 class SvXMLUnitConverter;
49 class SvXMLNamespaceMap;
50 class SvXMLImport;
51 
52 /** This struct is used as an optional parameter to the static
53  * _FillPropertySet() methods.
54  *
55  * It should not be used in any other context.
56  */
57 struct _ContextID_Index_Pair
58 {
59     sal_Int16 nContextID;
60     sal_Int32 nIndex;
61 };
62 
63 class XMLOFF_DLLPUBLIC SvXMLImportPropertyMapper : public UniRefBase
64 {
65     UniReference< SvXMLImportPropertyMapper> mxNextMapper;
66 
67     SvXMLImport& rImport;   // access to error handling
68 
69     SAL_DLLPRIVATE SvXMLImportPropertyMapper(SvXMLImportPropertyMapper &);
70         // not defined
71     SAL_DLLPRIVATE void operator =(SvXMLImportPropertyMapper &); // not defined
72 
73 protected:
74 
75     UniReference< XMLPropertySetMapper > maPropMapper;
GetImport() const76     SvXMLImport& GetImport() const { return rImport;}
77 
78 public:
79 
80     SvXMLImportPropertyMapper(
81             const UniReference< XMLPropertySetMapper >& rMapper,
82             SvXMLImport& rImport);
83     virtual ~SvXMLImportPropertyMapper();
84 
85     // Add a ImportPropertyMapper at the end of the import mapper chain.
86     // The added mapper MUST not be used outside the Mapper chain any longer,
87     // because its PropertyMapper will be replaced.
88     void ChainImportMapper(
89         const UniReference< SvXMLImportPropertyMapper>& rMapper );
90 
91     /** fills the given itemset with the attributes in the given list */
92     void importXML(
93             ::std::vector< XMLPropertyState >& rProperties,
94             ::com::sun::star::uno::Reference<
95                     ::com::sun::star::xml::sax::XAttributeList > xAttrList,
96             const SvXMLUnitConverter& rUnitConverter,
97             const SvXMLNamespaceMap& rNamespaceMap,
98             sal_uInt32 nPropType    ) const;
99 
100     /** like above, except that the mart is only serached within the range
101       *  [nStartIdx, nEndIdx[
102       */
103     void importXML(
104             ::std::vector< XMLPropertyState >& rProperties,
105             ::com::sun::star::uno::Reference<
106                     ::com::sun::star::xml::sax::XAttributeList > xAttrList,
107             const SvXMLUnitConverter& rUnitConverter,
108             const SvXMLNamespaceMap& rNamespaceMap,
109             sal_uInt32 nPropType,
110             sal_Int32 nStartIdx, sal_Int32 nEndIdx ) const;
111 
112     /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */
113     virtual sal_Bool handleSpecialItem(
114             XMLPropertyState& rProperty,
115             ::std::vector< XMLPropertyState >& rProperties,
116             const ::rtl::OUString& rValue,
117             const SvXMLUnitConverter& rUnitConverter,
118             const SvXMLNamespaceMap& rNamespaceMap ) const;
119 
120     /** This method is called when all attributes have benn processed. It may be used to remove items that are incomplete */
121     virtual void finished(
122             ::std::vector< XMLPropertyState >& rProperties,
123             sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const;
124 
125     void CheckSpecialContext(
126             const ::std::vector< XMLPropertyState >& aProperties,
127             const ::com::sun::star::uno::Reference<
128                     ::com::sun::star::beans::XPropertySet > rPropSet,
129             _ContextID_Index_Pair* pSpecialContextIds ) const;
130 
131     sal_Bool FillPropertySet(
132             const ::std::vector< XMLPropertyState >& aProperties,
133             const ::com::sun::star::uno::Reference<
134                     ::com::sun::star::beans::XPropertySet > rPropSet,
135             _ContextID_Index_Pair* pSpecialContextIds = NULL ) const;
136 
137     void FillPropertySequence(
138             const ::std::vector< XMLPropertyState >& aProperties,
139             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rValues )
140             const;
141 
142     inline const UniReference< XMLPropertySetMapper >&
143         getPropertySetMapper() const;
144 
145 
146 
147     /** implementation helper for FillPropertySet: fill an XPropertySet.
148      * Exceptions will be asserted. */
149     static sal_Bool _FillPropertySet(
150         const ::std::vector<XMLPropertyState> & rProperties,
151         const ::com::sun::star::uno::Reference<
152             ::com::sun::star::beans::XPropertySet> & rPropSet,
153         const ::com::sun::star::uno::Reference<
154             ::com::sun::star::beans::XPropertySetInfo> & rPropSetInfo,
155         const UniReference<XMLPropertySetMapper> & rPropMapper,
156         SvXMLImport& rImport,
157 
158         // parameter for use by txtstyli.cxx; allows efficient
159         // catching the combined characters property
160         _ContextID_Index_Pair* pSpecialContextIds = NULL );
161 
162     /** implementation helper for FillPropertySet: fill an XMultiPropertySet.
163      * If unsuccessul, set return value. */
164     static sal_Bool _FillMultiPropertySet(
165         const ::std::vector<XMLPropertyState> & rProperties,
166         const ::com::sun::star::uno::Reference<
167             ::com::sun::star::beans::XMultiPropertySet> & rMultiPropSet,
168         const ::com::sun::star::uno::Reference<
169             ::com::sun::star::beans::XPropertySetInfo> & rPropSetInfo,
170         const UniReference<XMLPropertySetMapper> & rPropMapper,
171 
172         // parameters for use by txtstyli.cxx; allows efficient
173         // catching the combined characters property
174         _ContextID_Index_Pair* pSpecialContextIds = NULL );
175 
176     /** implementation helper for FillPropertySet: fill an XTolerantMultiPropertySet.
177      * If unsuccessul, set return value. */
178     static sal_Bool _FillTolerantMultiPropertySet(
179         const ::std::vector<XMLPropertyState> & rProperties,
180         const ::com::sun::star::uno::Reference<
181             ::com::sun::star::beans::XTolerantMultiPropertySet> & rTolPropSet,
182         const UniReference<XMLPropertySetMapper> & rPropMapper,
183         SvXMLImport& rImport,
184 
185         // parameters for use by txtstyli.cxx; allows efficient
186         // catching the combined characters property
187         _ContextID_Index_Pair* pSpecialContextIds = NULL );
188 
189 
190     static void _PrepareForMultiPropertySet(
191         const ::std::vector<XMLPropertyState> & rProperties,
192         const ::com::sun::star::uno::Reference<
193             ::com::sun::star::beans::XPropertySetInfo> & rPropSetInfo,
194         const UniReference<XMLPropertySetMapper> & rPropMapper,
195         _ContextID_Index_Pair* pSpecialContextIds,
196         ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames,
197         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues);
198 };
199 
200 
201 inline const UniReference< XMLPropertySetMapper >&
getPropertySetMapper() const202     SvXMLImportPropertyMapper::getPropertySetMapper() const
203 {
204     return maPropMapper;
205 }
206 
207 #endif  //  _XMLOFF_XMLIMPPR_HXX
208