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 .
22 #include <sal/config.h>
24 #include <o3tl/sorted_vector.hxx>
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"
32 namespace com::sun::star::util
{
40 //= PropertyConversion
41 class PropertyConversion
44 template<typename EnumT
>
45 static css::uno::Any
convertString(
46 const css::uno::Type
& _rExpectedType
,
47 const OUString
& _rReadCharacters
,
48 const SvXMLEnumMapEntry
<EnumT
>* _pEnumMap
= nullptr
51 return convertString(_rExpectedType
, _rReadCharacters
,
52 reinterpret_cast<const SvXMLEnumMapEntry
<sal_uInt16
>*>(_pEnumMap
), /*_bInvertBoolean*/false);
54 static css::uno::Any
convertString(
55 const css::uno::Type
& _rExpectedType
,
56 const OUString
& _rReadCharacters
,
57 const SvXMLEnumMapEntry
<sal_uInt16
>* _pEnumMap
= nullptr,
58 const bool _bInvertBoolean
= false
61 static css::uno::Type
xmlTypeToUnoType( const OUString
& _rType
);
64 class OFormLayerXMLImport_Impl
;
66 /** Helper class for importing property values
68 <p>This class imports properties which are stored as attributes as well as properties which
69 are stored in </em><form:properties></em> elements.</p>
71 class OPropertyImport
: public SvXMLImportContext
73 friend class OSinglePropertyContext
;
74 friend class OListPropertyContext
;
77 typedef ::std::vector
< css::beans::PropertyValue
> PropertyValueArray
;
78 PropertyValueArray m_aValues
;
79 PropertyValueArray m_aGenericValues
;
80 // the values which the instance collects between StartElement and EndElement
82 o3tl::sorted_vector
<sal_Int32
> m_aEncounteredAttributes
;
84 OFormLayerXMLImport_Impl
& m_rContext
;
86 bool m_bTrackAttributes
;
88 // TODO: think about the restriction that the class does not know anything about the object it is importing.
89 // Perhaps this object should be known to the class, so setting the properties ('normal' ones as well as
90 // style properties) can be done in our own EndElement instead of letting derived classes do this.
93 OPropertyImport(OFormLayerXMLImport_Impl
& _rImport
);
95 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
97 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& AttrList
) override
;
99 virtual void SAL_CALL
startFastElement(
101 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& _rxAttrList
) override
;
102 virtual void SAL_CALL
characters(const OUString
& _rChars
) override
;
105 /** handle one single attribute.
107 <p>This is called for every attribute of the element. This class' implementation checks if the attribute
108 describes a property, if so, it is added to <member>m_aValues</member>.</p>
110 <p>All non-property attributes should be handled in derived classes.</p>
112 @param _nNamespaceKey
113 key of the namespace used in the attribute
115 local (relative to the namespace) attribute name
119 virtual bool handleAttribute(sal_Int32 nElement
, const OUString
& _rValue
);
121 /** determine if the element imported by the object had a given attribute.
122 <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
123 All form relevant attributes are in the same namespace, so this would be a redundant information.</p>
125 bool encounteredAttribute(sal_Int32 nElement
) const;
127 /** enables the tracking of the encountered attributes
128 <p>The tracking will raise the import costs a little bit, but it's cheaper than
129 derived classes tracking this themself.</p>
131 void enableTrackAttributes() { m_bTrackAttributes
= true; }
133 void implPushBackPropertyValue(const css::beans::PropertyValue
& _rProp
)
135 m_aValues
.push_back(_rProp
);
138 void implPushBackPropertyValue( const OUString
& _rName
, const css::uno::Any
& _rValue
)
140 m_aValues
.push_back( css::beans::PropertyValue(
141 _rName
, -1, _rValue
, css::beans::PropertyState_DIRECT_VALUE
) );
144 void implPushBackGenericPropertyValue(const css::beans::PropertyValue
& _rProp
)
146 m_aGenericValues
.push_back(_rProp
);
149 typedef rtl::Reference
<OPropertyImport
> OPropertyImportRef
;
151 //= OPropertyElementsContext
152 /** helper class for importing the <form:properties> element
154 class OPropertyElementsContext
: public SvXMLImportContext
156 OPropertyImportRef m_xPropertyImporter
; // to add the properties
159 OPropertyElementsContext(SvXMLImport
& _rImport
,
160 OPropertyImportRef _xPropertyImporter
);
162 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
163 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& AttrList
) override
;
165 #if OSL_DEBUG_LEVEL > 0
166 virtual void SAL_CALL
startFastElement(
168 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
169 virtual void SAL_CALL
characters(const OUString
& _rChars
) override
;
173 //= OSinglePropertyContext
174 /** helper class for importing a single <form:property> element
176 class OSinglePropertyContext
: public SvXMLImportContext
178 OPropertyImportRef m_xPropertyImporter
; // to add the properties
181 OSinglePropertyContext(SvXMLImport
& _rImport
,
182 OPropertyImportRef _xPropertyImporter
);
184 virtual void SAL_CALL
startFastElement(
186 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
189 //= OListPropertyContext
190 class OListPropertyContext
: public SvXMLImportContext
192 OPropertyImportRef m_xPropertyImporter
;
193 OUString m_sPropertyName
;
194 OUString m_sPropertyType
;
195 ::std::vector
< OUString
> m_aListValues
;
198 OListPropertyContext( SvXMLImport
& _rImport
,
199 OPropertyImportRef _xPropertyImporter
);
201 virtual void SAL_CALL
startFastElement(
203 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
205 virtual void SAL_CALL
endFastElement(sal_Int32 nElement
) override
;
207 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
createFastChildContext(
208 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& AttrList
) override
;
211 //= OListValueContext
212 class OListValueContext
: public SvXMLImportContext
214 OUString
& m_rListValueHolder
;
217 OListValueContext( SvXMLImport
& _rImport
, OUString
& _rListValueHolder
);
219 virtual void SAL_CALL
startFastElement(
221 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
224 } // namespace xmloff
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */