bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / forms / propertyimport.hxx
blobe813d383e3483bf0b80768527cac335583a67401
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
21 #define _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
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"
30 namespace com { namespace sun { namespace star { namespace util {
31 struct Time;
32 struct Date;
33 } } } }
35 //.........................................................................
36 namespace xmloff
38 //.........................................................................
40 //=====================================================================
41 //= PropertyConversion
42 //=====================================================================
43 class PropertyConversion
45 public:
46 static ::com::sun::star::uno::Any convertString(
47 SvXMLImport& _rImporter,
48 const ::com::sun::star::uno::Type& _rExpectedType,
49 const OUString& _rReadCharacters,
50 const SvXMLEnumMapEntry* _pEnumMap = NULL,
51 const sal_Bool _bInvertBoolean = sal_False
54 static ::com::sun::star::uno::Type xmlTypeToUnoType( const OUString& _rType );
57 class OFormLayerXMLImport_Impl;
58 //=====================================================================
59 //= OPropertyImport
60 //=====================================================================
61 /** Helper class for importing property values
63 <p>This class imports properties which are stored as attributes as well as properties which
64 are stored in </em>&lt;form:properties&gt;</em> elements.</p>
66 class OPropertyImport : public SvXMLImportContext
68 friend class OSinglePropertyContext;
69 friend class OListPropertyContext;
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
77 DECLARE_STL_STDKEY_SET( OUString, StringSet );
78 StringSet m_aEncounteredAttributes;
80 OFormLayerXMLImport_Impl& m_rContext;
82 sal_Bool m_bTrackAttributes;
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.
88 public:
89 OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const OUString& _rName);
91 virtual SvXMLImportContext* CreateChildContext(
92 sal_uInt16 _nPrefix, const OUString& _rLocalName,
93 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
95 virtual void StartElement(
96 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
97 virtual void Characters(const OUString& _rChars);
99 protected:
100 /** handle one single attribute.
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>
105 <p>All non-property attributes should be handled in derived classes.</p>
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
114 virtual bool handleAttribute(sal_uInt16 _nNamespaceKey,
115 const OUString& _rLocalName,
116 const OUString& _rValue);
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>
122 sal_Bool encounteredAttribute(const OUString& _rAttributeName) const;
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>
128 sal_Bool encounteredAttribute(const sal_Char* _pAttributeName) const { return encounteredAttribute(OUString::createFromAscii(_pAttributeName)); }
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>
134 void enableTrackAttributes() { m_bTrackAttributes = sal_True; }
136 inline void implPushBackPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
138 m_aValues.push_back(_rProp);
141 inline void implPushBackPropertyValue( const OUString& _rName, const ::com::sun::star::uno::Any& _rValue )
143 m_aValues.push_back( ::com::sun::star::beans::PropertyValue(
144 _rName, -1, _rValue, ::com::sun::star::beans::PropertyState_DIRECT_VALUE ) );
147 inline void implPushBackGenericPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
149 m_aGenericValues.push_back(_rProp);
152 SV_DECL_IMPL_REF( OPropertyImport )
154 //=====================================================================
155 //= OPropertyElementsContext
156 //=====================================================================
157 /** helper class for importing the &lt;form:properties&gt; element
159 class OPropertyElementsContext : public SvXMLImportContext
161 protected:
162 OPropertyImportRef m_xPropertyImporter; // to add the properties
164 public:
165 OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
166 const OPropertyImportRef& _rPropertyImporter);
168 virtual SvXMLImportContext* CreateChildContext(
169 sal_uInt16 _nPrefix, const OUString& _rLocalName,
170 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
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 OUString& _rChars);
176 #endif
179 //=====================================================================
180 //= OSinglePropertyContext
181 //=====================================================================
182 /** helper class for importing a single &lt;form:property&gt; element
184 class OSinglePropertyContext : public SvXMLImportContext
186 OPropertyImportRef m_xPropertyImporter; // to add the properties
188 public:
189 OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
190 const OPropertyImportRef& _rPropertyImporter);
192 virtual SvXMLImportContext* CreateChildContext(
193 sal_uInt16 _nPrefix, const OUString& _rLocalName,
194 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
196 virtual void StartElement(
197 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
200 //=====================================================================
201 //= OListPropertyContext
202 //=====================================================================
203 class OListPropertyContext : public SvXMLImportContext
205 OPropertyImportRef m_xPropertyImporter;
206 OUString m_sPropertyName;
207 OUString m_sPropertyType;
208 ::std::vector< OUString > m_aListValues;
210 public:
211 OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
212 const OPropertyImportRef& _rPropertyImporter );
214 virtual void StartElement(
215 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
217 virtual void EndElement();
219 virtual SvXMLImportContext* CreateChildContext(
220 sal_uInt16 _nPrefix, const OUString& _rLocalName,
221 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
224 //=====================================================================
225 //= OListValueContext
226 //=====================================================================
227 class OListValueContext : public SvXMLImportContext
229 OUString& m_rListValueHolder;
231 public:
232 OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
233 OUString& _rListValueHolder );
235 virtual void StartElement(
236 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
239 //.........................................................................
240 } // namespace xmloff
241 //.........................................................................
243 #endif // _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */