1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYIMPORT_HXX
21 #define INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYIMPORT_HXX
23 #include <sal/config.h>
27 #include <xmloff/xmlictxt.hxx>
28 #include "formattributes.hxx"
29 #include <rtl/ref.hxx>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include "layerimport.hxx"
33 namespace com
{ namespace sun
{ namespace star
{ namespace util
{
41 //= PropertyConversion
42 class PropertyConversion
45 static css::uno::Any
convertString(
46 const css::uno::Type
& _rExpectedType
,
47 const OUString
& _rReadCharacters
,
48 const SvXMLEnumMapEntry
* _pEnumMap
= nullptr,
49 const bool _bInvertBoolean
= false
52 static css::uno::Type
xmlTypeToUnoType( const OUString
& _rType
);
55 class OFormLayerXMLImport_Impl
;
57 /** Helper class for importing property values
59 <p>This class imports properties which are stored as attributes as well as properties which
60 are stored in </em><form:properties></em> elements.</p>
62 class OPropertyImport
: public SvXMLImportContext
64 friend class OSinglePropertyContext
;
65 friend class OListPropertyContext
;
68 typedef ::std::vector
< css::beans::PropertyValue
> PropertyValueArray
;
69 PropertyValueArray m_aValues
;
70 PropertyValueArray m_aGenericValues
;
71 // the values which the instance collects between StartElement and EndElement
73 typedef std::set
<OUString
> StringSet
;
74 StringSet m_aEncounteredAttributes
;
76 OFormLayerXMLImport_Impl
& m_rContext
;
78 bool m_bTrackAttributes
;
80 // TODO: think about the restriction that the class does not know anything about the object it is importing.
81 // Perhaps this object should be known to the class, so setting the properties ('normal' ones as well as
82 // style properties) can be done in our own EndElement instead of letting derived classes do this.
85 OPropertyImport(OFormLayerXMLImport_Impl
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
);
87 virtual SvXMLImportContext
* CreateChildContext(
88 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
89 const css::uno::Reference
< css::xml::sax::XAttributeList
>& _rxAttrList
) override
;
91 virtual void StartElement(
92 const css::uno::Reference
< css::xml::sax::XAttributeList
>& _rxAttrList
) override
;
93 virtual void Characters(const OUString
& _rChars
) override
;
96 /** handle one single attribute.
98 <p>This is called for every attribute of the element. This class' implementation checks if the attribute
99 describes a property, if so, it is added to <member>m_aValues</member>.</p>
101 <p>All non-property attributes should be handled in derived classes.</p>
103 @param _nNamespaceKey
104 key of the namespace used in the attribute
106 local (relative to the namespace) attribute name
110 virtual bool handleAttribute(sal_uInt16 _nNamespaceKey
,
111 const OUString
& _rLocalName
,
112 const OUString
& _rValue
);
114 /** determine if the element imported by the object had an given attribute.
115 <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
116 All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
118 bool encounteredAttribute(const OUString
& _rAttributeName
) const;
120 /** enables the tracking of the encountered attributes
121 <p>The tracking will raise the import costs a little bit, but it's cheaper than
122 derived classes tracking this themself.</p>
124 void enableTrackAttributes() { m_bTrackAttributes
= true; }
126 inline void implPushBackPropertyValue(const css::beans::PropertyValue
& _rProp
)
128 m_aValues
.push_back(_rProp
);
131 inline void implPushBackPropertyValue( const OUString
& _rName
, const css::uno::Any
& _rValue
)
133 m_aValues
.push_back( css::beans::PropertyValue(
134 _rName
, -1, _rValue
, css::beans::PropertyState_DIRECT_VALUE
) );
137 inline void implPushBackGenericPropertyValue(const css::beans::PropertyValue
& _rProp
)
139 m_aGenericValues
.push_back(_rProp
);
142 typedef tools::SvRef
<OPropertyImport
> OPropertyImportRef
;
144 //= OPropertyElementsContext
145 /** helper class for importing the <form:properties> element
147 class OPropertyElementsContext
: public SvXMLImportContext
150 OPropertyImportRef m_xPropertyImporter
; // to add the properties
153 OPropertyElementsContext(SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
154 const OPropertyImportRef
& _rPropertyImporter
);
156 virtual SvXMLImportContext
* CreateChildContext(
157 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
158 const css::uno::Reference
< css::xml::sax::XAttributeList
>& _rxAttrList
) override
;
160 #if OSL_DEBUG_LEVEL > 0
161 virtual void StartElement(
162 const css::uno::Reference
< css::xml::sax::XAttributeList
>& _rxAttrList
) override
;
163 virtual void Characters(const OUString
& _rChars
) override
;
167 //= OSinglePropertyContext
168 /** helper class for importing a single <form:property> element
170 class OSinglePropertyContext
: public SvXMLImportContext
172 OPropertyImportRef m_xPropertyImporter
; // to add the properties
175 OSinglePropertyContext(SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
176 const OPropertyImportRef
& _rPropertyImporter
);
178 virtual SvXMLImportContext
* CreateChildContext(
179 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
180 const css::uno::Reference
< css::xml::sax::XAttributeList
>& _rxAttrList
) override
;
182 virtual void StartElement(
183 const css::uno::Reference
< css::xml::sax::XAttributeList
>& _rxAttrList
) override
;
186 //= OListPropertyContext
187 class OListPropertyContext
: public SvXMLImportContext
189 OPropertyImportRef m_xPropertyImporter
;
190 OUString m_sPropertyName
;
191 OUString m_sPropertyType
;
192 ::std::vector
< OUString
> m_aListValues
;
195 OListPropertyContext( SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
196 const OPropertyImportRef
& _rPropertyImporter
);
198 virtual void StartElement(
199 const css::uno::Reference
< css::xml::sax::XAttributeList
>& _rxAttrList
) override
;
201 virtual void EndElement() override
;
203 virtual SvXMLImportContext
* CreateChildContext(
204 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
205 const css::uno::Reference
< css::xml::sax::XAttributeList
>& _rxAttrList
) override
;
208 //= OListValueContext
209 class OListValueContext
: public SvXMLImportContext
211 OUString
& m_rListValueHolder
;
214 OListValueContext( SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
215 OUString
& _rListValueHolder
);
217 virtual void StartElement(
218 const css::uno::Reference
< css::xml::sax::XAttributeList
>& _rxAttrList
) override
;
221 } // namespace xmloff
223 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYIMPORT_HXX
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */