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 ::com::sun::star::uno::Any
convertString(
46 const ::com::sun::star::uno::Type
& _rExpectedType
,
47 const OUString
& _rReadCharacters
,
48 const SvXMLEnumMapEntry
* _pEnumMap
= NULL
,
49 const bool _bInvertBoolean
= false
52 static ::com::sun::star::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
< ::com::sun::star::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 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& _rxAttrList
) SAL_OVERRIDE
;
91 virtual void StartElement(
92 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& _rxAttrList
) SAL_OVERRIDE
;
93 virtual void Characters(const OUString
& _rChars
) SAL_OVERRIDE
;
96 /** handle one single attribute.
98 <p>This is called for every attribute of the element. This class' implementaion 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 /** determine if the element imported by the object had an given attribute.
121 <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
122 All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
124 bool encounteredAttribute(const sal_Char
* _pAttributeName
) const { return encounteredAttribute(OUString::createFromAscii(_pAttributeName
)); }
126 /** enables the tracking of the encountered attributes
127 <p>The tracking will raise the import costs a little bit, but it's cheaper than
128 derived classes tracking this themself.</p>
130 void enableTrackAttributes() { m_bTrackAttributes
= true; }
132 inline void implPushBackPropertyValue(const ::com::sun::star::beans::PropertyValue
& _rProp
)
134 m_aValues
.push_back(_rProp
);
137 inline void implPushBackPropertyValue( const OUString
& _rName
, const ::com::sun::star::uno::Any
& _rValue
)
139 m_aValues
.push_back( ::com::sun::star::beans::PropertyValue(
140 _rName
, -1, _rValue
, ::com::sun::star::beans::PropertyState_DIRECT_VALUE
) );
143 inline void implPushBackGenericPropertyValue(const ::com::sun::star::beans::PropertyValue
& _rProp
)
145 m_aGenericValues
.push_back(_rProp
);
148 typedef tools::SvRef
<OPropertyImport
> OPropertyImportRef
;
150 //= OPropertyElementsContext
151 /** helper class for importing the <form:properties> element
153 class OPropertyElementsContext
: public SvXMLImportContext
156 OPropertyImportRef m_xPropertyImporter
; // to add the properties
159 OPropertyElementsContext(SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
160 const OPropertyImportRef
& _rPropertyImporter
);
162 virtual SvXMLImportContext
* CreateChildContext(
163 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
164 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& _rxAttrList
) SAL_OVERRIDE
;
166 #if OSL_DEBUG_LEVEL > 0
167 virtual void StartElement(
168 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& _rxAttrList
) SAL_OVERRIDE
;
169 virtual void Characters(const OUString
& _rChars
) SAL_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
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
182 const OPropertyImportRef
& _rPropertyImporter
);
184 virtual SvXMLImportContext
* CreateChildContext(
185 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
186 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& _rxAttrList
) SAL_OVERRIDE
;
188 virtual void StartElement(
189 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& _rxAttrList
) SAL_OVERRIDE
;
192 //= OListPropertyContext
193 class OListPropertyContext
: public SvXMLImportContext
195 OPropertyImportRef m_xPropertyImporter
;
196 OUString m_sPropertyName
;
197 OUString m_sPropertyType
;
198 ::std::vector
< OUString
> m_aListValues
;
201 OListPropertyContext( SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
202 const OPropertyImportRef
& _rPropertyImporter
);
204 virtual void StartElement(
205 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& _rxAttrList
) SAL_OVERRIDE
;
207 virtual void EndElement() SAL_OVERRIDE
;
209 virtual SvXMLImportContext
* CreateChildContext(
210 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
211 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& _rxAttrList
) SAL_OVERRIDE
;
214 //= OListValueContext
215 class OListValueContext
: public SvXMLImportContext
217 OUString
& m_rListValueHolder
;
220 OListValueContext( SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
221 OUString
& _rListValueHolder
);
223 virtual void StartElement(
224 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& _rxAttrList
) SAL_OVERRIDE
;
227 } // namespace xmloff
229 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYIMPORT_HXX
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */