/src/libreoffice/xmloff/source/forms/propertyimport.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <sal/config.h> |
23 | | |
24 | | #include <o3tl/sorted_vector.hxx> |
25 | | |
26 | | #include <xmloff/xmlictxt.hxx> |
27 | | #include "formattributes.hxx" |
28 | | #include <rtl/ref.hxx> |
29 | | #include <com/sun/star/beans/PropertyValue.hpp> |
30 | | #include "layerimport.hxx" |
31 | | |
32 | | namespace xmloff |
33 | | { |
34 | | |
35 | | //= PropertyConversion |
36 | | class PropertyConversion |
37 | | { |
38 | | public: |
39 | | template<typename EnumT> |
40 | | static css::uno::Any convertString( |
41 | | const css::uno::Type& _rExpectedType, |
42 | | const OUString& _rReadCharacters, |
43 | | const SvXMLEnumMapEntry<EnumT>* _pEnumMap = nullptr |
44 | | ) |
45 | 0 | { |
46 | 0 | return convertString(_rExpectedType, _rReadCharacters, |
47 | 0 | reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(_pEnumMap), /*_bInvertBoolean*/false); |
48 | 0 | } |
49 | | static css::uno::Any convertString( |
50 | | const css::uno::Type& _rExpectedType, |
51 | | const OUString& _rReadCharacters, |
52 | | const SvXMLEnumMapEntry<sal_uInt16>* _pEnumMap = nullptr, |
53 | | const bool _bInvertBoolean = false |
54 | | ); |
55 | | |
56 | | static css::uno::Type xmlTypeToUnoType( const OUString& _rType ); |
57 | | }; |
58 | | |
59 | | class OFormLayerXMLImport_Impl; |
60 | | //= OPropertyImport |
61 | | /** Helper class for importing property values |
62 | | |
63 | | <p>This class imports properties which are stored as attributes as well as properties which |
64 | | are stored in </em><form:properties></em> elements.</p> |
65 | | */ |
66 | | class OPropertyImport : public SvXMLImportContext |
67 | | { |
68 | | friend class OSinglePropertyContext; |
69 | | friend class OListPropertyContext; |
70 | | |
71 | | protected: |
72 | | typedef ::std::vector< css::beans::PropertyValue > PropertyValueArray; |
73 | | PropertyValueArray m_aValues; |
74 | | PropertyValueArray m_aGenericValues; |
75 | | // the values which the instance collects between StartElement and EndElement |
76 | | |
77 | | o3tl::sorted_vector<sal_Int32> m_aEncounteredAttributes; |
78 | | |
79 | | OFormLayerXMLImport_Impl& m_rContext; |
80 | | |
81 | | bool m_bTrackAttributes; |
82 | | |
83 | | // TODO: think about the restriction that the class does not know anything about the object it is importing. |
84 | | // Perhaps this object should be known to the class, so setting the properties ('normal' ones as well as |
85 | | // style properties) can be done in our own EndElement instead of letting derived classes do this. |
86 | | |
87 | | public: |
88 | | OPropertyImport(OFormLayerXMLImport_Impl& _rImport); |
89 | | |
90 | | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( |
91 | | sal_Int32 nElement, |
92 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; |
93 | | |
94 | | virtual void SAL_CALL startFastElement( |
95 | | sal_Int32 nElement, |
96 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& _rxAttrList) override; |
97 | | virtual void SAL_CALL characters(const OUString& _rChars) override; |
98 | | |
99 | | protected: |
100 | | /** handle one single attribute. |
101 | | |
102 | | <p>This is called for every attribute of the element. This class' implementation checks if the attribute |
103 | | describes a property, if so, it is added to <member>m_aValues</member>.</p> |
104 | | |
105 | | <p>All non-property attributes should be handled in derived classes.</p> |
106 | | |
107 | | @param _nNamespaceKey |
108 | | key of the namespace used in the attribute |
109 | | @param _rLocalName |
110 | | local (relative to the namespace) attribute name |
111 | | @param _rValue |
112 | | attribute value |
113 | | */ |
114 | | virtual bool handleAttribute(sal_Int32 nElement, const OUString& _rValue); |
115 | | |
116 | | /** determine if the element imported by the object had a given attribute. |
117 | | <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace. |
118 | | All form relevant attributes are in the same namespace, so this would be a redundant information.</p> |
119 | | */ |
120 | | bool encounteredAttribute(sal_Int32 nElement) const; |
121 | | |
122 | | /** enables the tracking of the encountered attributes |
123 | | <p>The tracking will raise the import costs a little bit, but it's cheaper than |
124 | | derived classes tracking this themself.</p> |
125 | | */ |
126 | 0 | void enableTrackAttributes() { m_bTrackAttributes = true; } |
127 | | |
128 | | void implPushBackPropertyValue(const css::beans::PropertyValue& _rProp) |
129 | 0 | { |
130 | 0 | m_aValues.push_back(_rProp); |
131 | 0 | } |
132 | | |
133 | | void implPushBackPropertyValue( const OUString& _rName, const css::uno::Any& _rValue ) |
134 | 0 | { |
135 | 0 | m_aValues.push_back( css::beans::PropertyValue( |
136 | 0 | _rName, -1, _rValue, css::beans::PropertyState_DIRECT_VALUE ) ); |
137 | 0 | } |
138 | | |
139 | | void implPushBackGenericPropertyValue(const css::beans::PropertyValue& _rProp) |
140 | 0 | { |
141 | 0 | m_aGenericValues.push_back(_rProp); |
142 | 0 | } |
143 | | }; |
144 | | typedef rtl::Reference<OPropertyImport> OPropertyImportRef; |
145 | | |
146 | | //= OPropertyElementsContext |
147 | | /** helper class for importing the <form:properties> element |
148 | | */ |
149 | | class OPropertyElementsContext : public SvXMLImportContext |
150 | | { |
151 | | OPropertyImportRef m_xPropertyImporter; // to add the properties |
152 | | |
153 | | public: |
154 | | OPropertyElementsContext(SvXMLImport& _rImport, |
155 | | OPropertyImportRef _xPropertyImporter); |
156 | | |
157 | | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( |
158 | | sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; |
159 | | |
160 | | #if OSL_DEBUG_LEVEL > 0 |
161 | | virtual void SAL_CALL startFastElement( |
162 | | sal_Int32 nElement, |
163 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; |
164 | | virtual void SAL_CALL characters(const OUString& _rChars) override; |
165 | | #endif |
166 | | }; |
167 | | |
168 | | //= OSinglePropertyContext |
169 | | /** helper class for importing a single <form:property> element |
170 | | */ |
171 | | class OSinglePropertyContext : public SvXMLImportContext |
172 | | { |
173 | | OPropertyImportRef m_xPropertyImporter; // to add the properties |
174 | | |
175 | | public: |
176 | | OSinglePropertyContext(SvXMLImport& _rImport, |
177 | | OPropertyImportRef _xPropertyImporter); |
178 | | |
179 | | virtual void SAL_CALL startFastElement( |
180 | | sal_Int32 nElement, |
181 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; |
182 | | }; |
183 | | |
184 | | //= OListPropertyContext |
185 | | class OListPropertyContext : public SvXMLImportContext |
186 | | { |
187 | | OPropertyImportRef m_xPropertyImporter; |
188 | | OUString m_sPropertyName; |
189 | | OUString m_sPropertyType; |
190 | | ::std::vector< OUString > m_aListValues; |
191 | | |
192 | | public: |
193 | | OListPropertyContext( SvXMLImport& _rImport, |
194 | | OPropertyImportRef _xPropertyImporter ); |
195 | | |
196 | | virtual void SAL_CALL startFastElement( |
197 | | sal_Int32 nElement, |
198 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; |
199 | | |
200 | | virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; |
201 | | |
202 | | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( |
203 | | sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; |
204 | | }; |
205 | | |
206 | | //= OListValueContext |
207 | | class OListValueContext : public SvXMLImportContext |
208 | | { |
209 | | OUString& m_rListValueHolder; |
210 | | |
211 | | public: |
212 | | OListValueContext( SvXMLImport& _rImport, OUString& _rListValueHolder ); |
213 | | |
214 | | virtual void SAL_CALL startFastElement( |
215 | | sal_Int32 nElement, |
216 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; |
217 | | }; |
218 | | |
219 | | } // namespace xmloff |
220 | | |
221 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |