Update ooo320-m1
[ooovba.git] / xmloff / source / forms / propertyimport.hxx
blob2306bd80bd75f99b2c1b29f378c4e98217526877
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertyimport.hxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
32 #define _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
34 #include <xmloff/xmlictxt.hxx>
35 #include "formattributes.hxx"
36 #include <vos/ref.hxx>
37 #include <comphelper/stl_types.hxx>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include "layerimport.hxx"
41 namespace com { namespace sun { namespace star { namespace util {
42 struct Time;
43 struct Date;
44 } } } }
46 //.........................................................................
47 namespace xmloff
49 //.........................................................................
51 //=====================================================================
52 //= PropertyConversion
53 //=====================================================================
54 class PropertyConversion
56 public:
57 static ::com::sun::star::uno::Any convertString(
58 SvXMLImport& _rImporter,
59 const ::com::sun::star::uno::Type& _rExpectedType,
60 const ::rtl::OUString& _rReadCharacters,
61 const SvXMLEnumMapEntry* _pEnumMap = NULL,
62 const sal_Bool _bInvertBoolean = sal_False
65 static ::com::sun::star::uno::Type xmlTypeToUnoType( const ::rtl::OUString& _rType );
68 class OFormLayerXMLImport_Impl;
69 //=====================================================================
70 //= OPropertyImport
71 //=====================================================================
72 /** Helper class for importing property values
74 <p>This class imports properties which are stored as attributes as well as properties which
75 are stored in </em>&lt;form:properties&gt;</em> elements.</p>
77 class OPropertyImport : public SvXMLImportContext
79 friend class OSinglePropertyContext;
80 friend class OListPropertyContext;
82 protected:
83 typedef ::std::vector< ::com::sun::star::beans::PropertyValue > PropertyValueArray;
84 PropertyValueArray m_aValues;
85 PropertyValueArray m_aGenericValues;
86 // the values which the instance collects between StartElement and EndElement
88 DECLARE_STL_STDKEY_SET( ::rtl::OUString, StringSet );
89 StringSet m_aEncounteredAttributes;
91 OFormLayerXMLImport_Impl& m_rContext;
93 sal_Bool m_bTrackAttributes;
95 // TODO: think about the restriction that the class does not know anything about the object it is importing.
96 // Perhaps this object should be known to the class, so setting the properties ('normal' ones as well as
97 // style properties) can be done in our own EndElement instead of letting derived classes do this.
99 public:
100 OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName);
102 virtual SvXMLImportContext* CreateChildContext(
103 sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
104 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
106 virtual void StartElement(
107 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
108 virtual void Characters(const ::rtl::OUString& _rChars);
110 protected:
111 /** handle one single attribute.
113 <p>This is called for every attribute of the element. This class' implementaion checks if the attribute
114 describes a property, if so, it is added to <member>m_aValues</member>.</p>
116 <p>All non-property attributes should be handled in derived classes.</p>
118 @param _nNamespaceKey
119 key of the namespace used in the attribute
120 @param _rLocalName
121 local (relative to the namespace) attribute name
122 @param _rValue
123 attribute value
125 virtual void handleAttribute(sal_uInt16 _nNamespaceKey,
126 const ::rtl::OUString& _rLocalName,
127 const ::rtl::OUString& _rValue);
129 /** determine if the element imported by the object had an given attribute.
130 <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
131 All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
133 sal_Bool encounteredAttribute(const ::rtl::OUString& _rAttributeName) const;
135 /** determine if the element imported by the object had an given attribute.
136 <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
137 All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
139 sal_Bool encounteredAttribute(const sal_Char* _pAttributeName) const { return encounteredAttribute(::rtl::OUString::createFromAscii(_pAttributeName)); }
141 /** enables the tracking of the encountered attributes
142 <p>The tracking will raise the import costs a little bit, but it's cheaper than
143 derived classes tracking this themself.</p>
145 void enableTrackAttributes() { m_bTrackAttributes = sal_True; }
147 inline void implPushBackPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
149 m_aValues.push_back(_rProp);
152 inline void implPushBackPropertyValue( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& _rValue )
154 m_aValues.push_back( ::com::sun::star::beans::PropertyValue(
155 _rName, -1, _rValue, ::com::sun::star::beans::PropertyState_DIRECT_VALUE ) );
158 inline void implPushBackGenericPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
160 m_aGenericValues.push_back(_rProp);
163 SV_DECL_IMPL_REF( OPropertyImport )
165 //=====================================================================
166 //= OPropertyElementsContext
167 //=====================================================================
168 /** helper class for importing the &lt;form:properties&gt; element
170 class OPropertyElementsContext : public SvXMLImportContext
172 protected:
173 OPropertyImportRef m_xPropertyImporter; // to add the properties
175 public:
176 OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
177 const OPropertyImportRef& _rPropertyImporter);
179 virtual SvXMLImportContext* CreateChildContext(
180 sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
181 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
183 #if OSL_DEBUG_LEVEL > 0
184 virtual void StartElement(
185 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
186 virtual void Characters(const ::rtl::OUString& _rChars);
187 #endif
190 //=====================================================================
191 //= OSinglePropertyContext
192 //=====================================================================
193 /** helper class for importing a single &lt;form:property&gt; element
195 class OSinglePropertyContext : public SvXMLImportContext
197 OPropertyImportRef m_xPropertyImporter; // to add the properties
199 public:
200 OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
201 const OPropertyImportRef& _rPropertyImporter);
203 virtual SvXMLImportContext* CreateChildContext(
204 sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
205 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
207 virtual void StartElement(
208 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
211 //=====================================================================
212 //= OListPropertyContext
213 //=====================================================================
214 class OListPropertyContext : public SvXMLImportContext
216 OPropertyImportRef m_xPropertyImporter;
217 ::rtl::OUString m_sPropertyName;
218 ::rtl::OUString m_sPropertyType;
219 ::std::vector< ::rtl::OUString > m_aListValues;
221 public:
222 OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
223 const OPropertyImportRef& _rPropertyImporter );
225 virtual void StartElement(
226 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
228 virtual void EndElement();
230 virtual SvXMLImportContext* CreateChildContext(
231 sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
232 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
235 //=====================================================================
236 //= OListValueContext
237 //=====================================================================
238 class OListValueContext : public SvXMLImportContext
240 ::rtl::OUString& m_rListValueHolder;
242 public:
243 OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
244 ::rtl::OUString& _rListValueHolder );
246 virtual void StartElement(
247 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
250 //.........................................................................
251 } // namespace xmloff
252 //.........................................................................
254 #endif // _XMLOFF_FORMS_PROPERTYIMPORT_HXX_