1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
25 #define _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
26 
27 #include <xmloff/xmlictxt.hxx>
28 #include "formattributes.hxx"
29 #include <vos/ref.hxx>
30 #include <comphelper/stl_types.hxx>
31 #include <com/sun/star/beans/PropertyValue.hpp>
32 #include "layerimport.hxx"
33 
34 namespace com { namespace sun { namespace star { namespace util {
35 	struct Time;
36 	struct Date;
37 } } } }
38 
39 //.........................................................................
40 namespace xmloff
41 {
42 //.........................................................................
43 
44 	//=====================================================================
45 	//= PropertyConversion
46 	//=====================================================================
47     class PropertyConversion
48     {
49     public:
50 		static ::com::sun::star::uno::Any convertString(
51             SvXMLImport& _rImporter,
52             const ::com::sun::star::uno::Type& _rExpectedType,
53 			const ::rtl::OUString& _rReadCharacters,
54             const SvXMLEnumMapEntry* _pEnumMap = NULL,
55             const sal_Bool _bInvertBoolean = sal_False
56         );
57 
58         static ::com::sun::star::uno::Type xmlTypeToUnoType( const ::rtl::OUString& _rType );
59     };
60 
61 	class OFormLayerXMLImport_Impl;
62 	//=====================================================================
63 	//= OPropertyImport
64 	//=====================================================================
65 	/** Helper class for importing property values
66 
67 		<p>This class imports properties which are stored as attributes as well as properties which
68 		are stored in </em>&lt;form:properties&gt;</em> elements.</p>
69 	*/
70 	class OPropertyImport : public SvXMLImportContext
71 	{
72 		friend class OSinglePropertyContext;
73         friend class OListPropertyContext;
74 
75 	protected:
76         typedef ::std::vector< ::com::sun::star::beans::PropertyValue > PropertyValueArray;
77 		PropertyValueArray			m_aValues;
78 		PropertyValueArray			m_aGenericValues;
79 			// the values which the instance collects between StartElement and EndElement
80 
81 		DECLARE_STL_STDKEY_SET( ::rtl::OUString, StringSet );
82 		StringSet					m_aEncounteredAttributes;
83 
84 		OFormLayerXMLImport_Impl&		m_rContext;
85 
86 		sal_Bool					m_bTrackAttributes;
87 
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.
91 
92 	public:
93 		OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName);
94 
95 		virtual SvXMLImportContext* CreateChildContext(
96 			sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
97 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
98 
99 		virtual void StartElement(
100 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
101 		virtual void Characters(const ::rtl::OUString& _rChars);
102 
103 	protected:
104 		/** handle one single attribute.
105 
106 			<p>This is called for every attribute of the element. This class' implementaion checks if the attribute
107 			describes a property, if so, it is added to <member>m_aValues</member>.</p>
108 
109 			<p>All non-property attributes should be handled in derived classes.</p>
110 
111 			@param _nNamespaceKey
112 				key of the namespace used in the attribute
113 			@param _rLocalName
114 				local (relative to the namespace) attribute name
115 			@param _rValue
116 				attribute value
117 		*/
118 		virtual bool handleAttribute(sal_uInt16 _nNamespaceKey,
119 			const ::rtl::OUString& _rLocalName,
120 			const ::rtl::OUString& _rValue);
121 
122 		/** determine if the element imported by the object had an given attribute.
123 			<p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
124 			All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
125 		*/
126 		sal_Bool	encounteredAttribute(const ::rtl::OUString& _rAttributeName) const;
127 
128 		/** determine if the element imported by the object had an given attribute.
129 			<p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
130 			All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
131 		*/
encounteredAttribute(const sal_Char * _pAttributeName) const132 		sal_Bool	encounteredAttribute(const sal_Char* _pAttributeName) const { return encounteredAttribute(::rtl::OUString::createFromAscii(_pAttributeName)); }
133 
134 		/** enables the tracking of the encountered attributes
135 			<p>The tracking will raise the import costs a little bit, but it's cheaper than
136 			derived classes tracking this themself.</p>
137 		*/
enableTrackAttributes()138 		void		enableTrackAttributes() { m_bTrackAttributes = sal_True; }
139 
implPushBackPropertyValue(const::com::sun::star::beans::PropertyValue & _rProp)140 		inline void implPushBackPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
141 		{
142             m_aValues.push_back(_rProp);
143         }
144 
implPushBackPropertyValue(const::rtl::OUString & _rName,const::com::sun::star::uno::Any & _rValue)145         inline void implPushBackPropertyValue( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& _rValue )
146         {
147             m_aValues.push_back( ::com::sun::star::beans::PropertyValue(
148                 _rName, -1, _rValue, ::com::sun::star::beans::PropertyState_DIRECT_VALUE ) );
149         }
150 
implPushBackGenericPropertyValue(const::com::sun::star::beans::PropertyValue & _rProp)151         inline void implPushBackGenericPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
152 		{
153             m_aGenericValues.push_back(_rProp);
154         }
155 	};
156 	SV_DECL_IMPL_REF( OPropertyImport )
157 
158 	//=====================================================================
159 	//= OPropertyElementsContext
160 	//=====================================================================
161 	/** helper class for importing the &lt;form:properties&gt; element
162 	*/
163 	class OPropertyElementsContext : public SvXMLImportContext
164 	{
165 	protected:
166 		OPropertyImportRef	m_xPropertyImporter;	// to add the properties
167 
168 	public:
169 		OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
170 				const OPropertyImportRef& _rPropertyImporter);
171 
172 		virtual SvXMLImportContext* CreateChildContext(
173 			sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
174 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
175 
176 #if OSL_DEBUG_LEVEL > 0
177 		virtual void StartElement(
178 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
179 		virtual void Characters(const ::rtl::OUString& _rChars);
180 #endif
181 	};
182 
183 	//=====================================================================
184 	//= OSinglePropertyContext
185 	//=====================================================================
186 	/** helper class for importing a single &lt;form:property&gt; element
187 	*/
188 	class OSinglePropertyContext : public SvXMLImportContext
189 	{
190 		OPropertyImportRef			m_xPropertyImporter;	// to add the properties
191 
192 	public:
193 		OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
194 				const OPropertyImportRef& _rPropertyImporter);
195 
196 		virtual SvXMLImportContext* CreateChildContext(
197 			sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
198 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
199 
200 		virtual void StartElement(
201 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
202 	};
203 
204 	//=====================================================================
205 	//= OListPropertyContext
206 	//=====================================================================
207     class OListPropertyContext : public SvXMLImportContext
208     {
209 		OPropertyImportRef                  m_xPropertyImporter;
210         ::rtl::OUString                     m_sPropertyName;
211         ::rtl::OUString                     m_sPropertyType;
212         ::std::vector< ::rtl::OUString >    m_aListValues;
213 
214 	public:
215 		OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
216 				const OPropertyImportRef& _rPropertyImporter );
217 
218 		virtual void StartElement(
219 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
220 
221         virtual void EndElement();
222 
223         virtual SvXMLImportContext* CreateChildContext(
224 			sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
225 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList);
226     };
227 
228 	//=====================================================================
229 	//= OListValueContext
230 	//=====================================================================
231     class OListValueContext : public SvXMLImportContext
232     {
233         ::rtl::OUString& m_rListValueHolder;
234 
235 	public:
236 		OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
237             ::rtl::OUString& _rListValueHolder );
238 
239 		virtual void StartElement(
240 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList );
241     };
242 
243 //.........................................................................
244 }	// namespace xmloff
245 //.........................................................................
246 
247 #endif // _XMLOFF_FORMS_PROPERTYIMPORT_HXX_
248 
249 
250