Branch data Line data Source code
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 : : #ifndef _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
21 : : #define _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
22 : :
23 : : #include <xmloff/xmlictxt.hxx>
24 : : #include "formattributes.hxx"
25 : : #include <rtl/ref.hxx>
26 : : #include <comphelper/stl_types.hxx>
27 : : #include <com/sun/star/beans/PropertyValue.hpp>
28 : : #include "layerimport.hxx"
29 : :
30 : : namespace com { namespace sun { namespace star { namespace util {
31 : : struct Time;
32 : : struct Date;
33 : : } } } }
34 : :
35 : : //.........................................................................
36 : : namespace xmloff
37 : : {
38 : : //.........................................................................
39 : :
40 : : //=====================================================================
41 : : //= PropertyConversion
42 : : //=====================================================================
43 : : class PropertyConversion
44 : : {
45 : : public:
46 : : static ::com::sun::star::uno::Any convertString(
47 : : SvXMLImport& _rImporter,
48 : : const ::com::sun::star::uno::Type& _rExpectedType,
49 : : const ::rtl::OUString& _rReadCharacters,
50 : : const SvXMLEnumMapEntry* _pEnumMap = NULL,
51 : : const sal_Bool _bInvertBoolean = sal_False
52 : : );
53 : :
54 : : static ::com::sun::star::uno::Type xmlTypeToUnoType( const ::rtl::OUString& _rType );
55 : : };
56 : :
57 : : class OFormLayerXMLImport_Impl;
58 : : //=====================================================================
59 : : //= OPropertyImport
60 : : //=====================================================================
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 [ - + ]: 49 : class OPropertyImport : public SvXMLImportContext
67 : : {
68 : : friend class OSinglePropertyContext;
69 : : friend class OListPropertyContext;
70 : :
71 : : protected:
72 : : typedef ::std::vector< ::com::sun::star::beans::PropertyValue > PropertyValueArray;
73 : : PropertyValueArray m_aValues;
74 : : PropertyValueArray m_aGenericValues;
75 : : // the values which the instance collects between StartElement and EndElement
76 : :
77 : : DECLARE_STL_STDKEY_SET( ::rtl::OUString, StringSet );
78 : : StringSet m_aEncounteredAttributes;
79 : :
80 : : OFormLayerXMLImport_Impl& m_rContext;
81 : :
82 : : sal_Bool m_bTrackAttributes;
83 : :
84 : : // TODO: think about the restriction that the class does not know anything about the object it is importing.
85 : : // Perhaps this object should be known to the class, so setting the properties ('normal' ones as well as
86 : : // style properties) can be done in our own EndElement instead of letting derived classes do this.
87 : :
88 : : public:
89 : : OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName);
90 : :
91 : : virtual SvXMLImportContext* CreateChildContext(
92 : : sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
93 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
94 : :
95 : : virtual void StartElement(
96 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
97 : : virtual void Characters(const ::rtl::OUString& _rChars);
98 : :
99 : : protected:
100 : : /** handle one single attribute.
101 : :
102 : : <p>This is called for every attribute of the element. This class' implementaion 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_uInt16 _nNamespaceKey,
115 : : const ::rtl::OUString& _rLocalName,
116 : : const ::rtl::OUString& _rValue);
117 : :
118 : : /** determine if the element imported by the object had an given attribute.
119 : : <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
120 : : All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
121 : : */
122 : : sal_Bool encounteredAttribute(const ::rtl::OUString& _rAttributeName) const;
123 : :
124 : : /** determine if the element imported by the object had an given attribute.
125 : : <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
126 : : All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
127 : : */
128 : : sal_Bool encounteredAttribute(const sal_Char* _pAttributeName) const { return encounteredAttribute(::rtl::OUString::createFromAscii(_pAttributeName)); }
129 : :
130 : : /** enables the tracking of the encountered attributes
131 : : <p>The tracking will raise the import costs a little bit, but it's cheaper than
132 : : derived classes tracking this themself.</p>
133 : : */
134 : 39 : void enableTrackAttributes() { m_bTrackAttributes = sal_True; }
135 : :
136 : 168 : inline void implPushBackPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
137 : : {
138 : 168 : m_aValues.push_back(_rProp);
139 : 168 : }
140 : :
141 : 0 : inline void implPushBackPropertyValue( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& _rValue )
142 : : {
143 : : m_aValues.push_back( ::com::sun::star::beans::PropertyValue(
144 [ # # ]: 0 : _rName, -1, _rValue, ::com::sun::star::beans::PropertyState_DIRECT_VALUE ) );
145 : 0 : }
146 : :
147 : 82 : inline void implPushBackGenericPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
148 : : {
149 : 82 : m_aGenericValues.push_back(_rProp);
150 : 82 : }
151 : : };
152 [ + - ][ + - ]: 434 : SV_DECL_IMPL_REF( OPropertyImport )
[ + - ]
153 : :
154 : : //=====================================================================
155 : : //= OPropertyElementsContext
156 : : //=====================================================================
157 : : /** helper class for importing the <form:properties> element
158 : : */
159 [ + - ][ - + ]: 94 : class OPropertyElementsContext : public SvXMLImportContext
160 : : {
161 : : protected:
162 : : OPropertyImportRef m_xPropertyImporter; // to add the properties
163 : :
164 : : public:
165 : : OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
166 : : const OPropertyImportRef& _rPropertyImporter);
167 : :
168 : : virtual SvXMLImportContext* CreateChildContext(
169 : : sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
170 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
171 : :
172 : : #if OSL_DEBUG_LEVEL > 0
173 : : virtual void StartElement(
174 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
175 : : virtual void Characters(const ::rtl::OUString& _rChars);
176 : : #endif
177 : : };
178 : :
179 : : //=====================================================================
180 : : //= OSinglePropertyContext
181 : : //=====================================================================
182 : : /** helper class for importing a single <form:property> element
183 : : */
184 [ + - ][ - + ]: 164 : class OSinglePropertyContext : public SvXMLImportContext
185 : : {
186 : : OPropertyImportRef m_xPropertyImporter; // to add the properties
187 : :
188 : : public:
189 : : OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
190 : : const OPropertyImportRef& _rPropertyImporter);
191 : :
192 : : virtual SvXMLImportContext* CreateChildContext(
193 : : sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
194 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
195 : :
196 : : virtual void StartElement(
197 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
198 : : };
199 : :
200 : : //=====================================================================
201 : : //= OListPropertyContext
202 : : //=====================================================================
203 [ # # ][ # # ]: 0 : class OListPropertyContext : public SvXMLImportContext
204 : : {
205 : : OPropertyImportRef m_xPropertyImporter;
206 : : ::rtl::OUString m_sPropertyName;
207 : : ::rtl::OUString m_sPropertyType;
208 : : ::std::vector< ::rtl::OUString > m_aListValues;
209 : :
210 : : public:
211 : : OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
212 : : const OPropertyImportRef& _rPropertyImporter );
213 : :
214 : : virtual void StartElement(
215 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
216 : :
217 : : virtual void EndElement();
218 : :
219 : : virtual SvXMLImportContext* CreateChildContext(
220 : : sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
221 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
222 : : };
223 : :
224 : : //=====================================================================
225 : : //= OListValueContext
226 : : //=====================================================================
227 [ # # ]: 0 : class OListValueContext : public SvXMLImportContext
228 : : {
229 : : ::rtl::OUString& m_rListValueHolder;
230 : :
231 : : public:
232 : : OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
233 : : ::rtl::OUString& _rListValueHolder );
234 : :
235 : : virtual void StartElement(
236 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
237 : : };
238 : :
239 : : //.........................................................................
240 : : } // namespace xmloff
241 : : //.........................................................................
242 : :
243 : : #endif // _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
244 : :
245 : :
246 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|