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