Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _XMLOFF_FORMS_PROPERTYEXPORT_HXX_
30 : : #define _XMLOFF_FORMS_PROPERTYEXPORT_HXX_
31 : :
32 : : #include "formattributes.hxx"
33 : : #include <comphelper/stl_types.hxx>
34 : : #include <com/sun/star/beans/XPropertySet.hpp>
35 : : #include <com/sun/star/beans/XPropertyState.hpp>
36 : : #include <callbacks.hxx>
37 : : #include <xmloff/xmlexp.hxx>
38 : : #include "callbacks.hxx"
39 : : #include "strings.hxx"
40 : :
41 : : //.........................................................................
42 : : namespace xmloff
43 : : {
44 : : //.........................................................................
45 : :
46 : : #define BOOLATTR_DEFAULT_FALSE 0x00
47 : : #define BOOLATTR_DEFAULT_TRUE 0x01
48 : : #define BOOLATTR_DEFAULT_VOID 0x02
49 : : #define BOOLATTR_DEFAULT_MASK 0x03
50 : :
51 : : #define BOOLATTR_INVERSE_SEMANTICS 0x04
52 : : // if sal_True, indicates that the semantic of the property refered by <arg>_pPropertyName</arg>
53 : : // is inverse to the semantic of the XML attribute.<br/>
54 : : // I.e. if the property value is <TRUE/>, <FALSE/> has to be written and vice versa.
55 : : // <p>Be careful with <arg>_bDefault</arg> and <arg>_bInverseSemantics</arg>: if <arg>_bInverseSemantics</arg>
56 : : // is <TRUE/>, the current property value is inverted <em>before</em> comparing it to the default.</p>
57 : :
58 : : class IFormsExportContext;
59 : : //=====================================================================
60 : : //= OPropertyExport
61 : : //=====================================================================
62 : : /** provides export related tools for attribute handling
63 : :
64 : : <p>(The name is somewhat misleading. It's not only a PropertyExport, but in real a ElementExport.
65 : : Anyway.)</p>
66 : : */
67 : 0 : class OPropertyExport
68 : : {
69 : : private:
70 : : DECLARE_STL_STDKEY_SET(::rtl::OUString, StringSet);
71 : : StringSet m_aRemainingProps;
72 : : // see examinePersistence
73 : :
74 : : void exportRelativeTargetLocation(const ConstAsciiString& _sPropertyName,sal_Int32 _nProperty,bool _bAddType);
75 : :
76 : : protected:
77 : : IFormsExportContext& m_rContext;
78 : :
79 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
80 : : m_xProps;
81 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
82 : : m_xPropertyInfo;
83 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >
84 : : m_xPropertyState;
85 : :
86 : : // caching
87 : : ::rtl::OUString m_sValueTrue;
88 : : ::rtl::OUString m_sValueFalse;
89 : :
90 : : public:
91 : : /** constructs an object capable of handling attributes for export
92 : : @param _rContext
93 : : the export context to which's attribute list the property translation should be added
94 : : @param m_xControl
95 : : the property set to be exported
96 : : */
97 : : OPropertyExport(IFormsExportContext& _rContext,
98 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxProps);
99 : :
100 : : protected:
101 : : /** examines a property set given for all properties which's value are to made persistent
102 : :
103 : : <p>upon return the <method>m_aRemainingProps</method> will be filled with the names of all properties
104 : : which need to be stored</p>
105 : : */
106 : : void examinePersistence();
107 : :
108 : : template< typename T > void exportRemainingPropertiesSequence(
109 : : com::sun::star::uno::Any const & value,
110 : : token::XMLTokenEnum eValueAttName);
111 : :
112 : : void exportRemainingProperties();
113 : :
114 : : /** indicates that a property has been handled by a derived class, without using the helper methods of this
115 : : class.
116 : :
117 : : <p>Calling this method is necessary in case you use the suggested mechanism for the generic export of
118 : : properties. This means that you want to use <method>exportRemainingProperties</method>, which exports
119 : : all properties which need to ('cause they haven't been exported with one of the other type-specific
120 : : methods).</p>
121 : :
122 : : <p>In this case you should call exportedProperty for every property you export yourself, so the property
123 : : will be flagged as <em>already handled</em></p>
124 : : */
125 : 0 : void exportedProperty(const ::rtl::OUString& _rPropertyName)
126 : 0 : { m_aRemainingProps.erase(_rPropertyName); }
127 : :
128 : : /** add an attribute which is represented by a string property to the export context
129 : :
130 : : @param _nNamespaceKey
131 : : the key of the namespace to use for the attribute name. Is used with the namespace map
132 : : provided by the export context.
133 : : @param _pAttributeName
134 : : the name of the attribute to add. Must not contain any namespace
135 : : @param _pPropertyName
136 : : the name of the property to ask the control for
137 : : */
138 : : void exportStringPropertyAttribute(
139 : : const sal_uInt16 _nNamespaceKey,
140 : : const sal_Char* _pAttributeName,
141 : : const ::rtl::OUString& _rPropertyName
142 : : );
143 : :
144 : : /** add an attribute which is represented by a boolean property to the export context
145 : :
146 : : @param _nNamespaceKey
147 : : the key of the namespace to use for the attribute name. Is used with the namespace map
148 : : provided by the export context.
149 : : @param _pAttributeName
150 : : the name of the attribute to add. Must not contain any namespace (it's added automatically)
151 : : @param _pPropertyName
152 : : the name of the property to ask the control for
153 : : @param _nBooleanAttributeFlags
154 : : specifies the default and the "alignment" (inverse semantics) of the boolean property
155 : : */
156 : : void exportBooleanPropertyAttribute(
157 : : const sal_uInt16 _nNamespaceKey,
158 : : const sal_Char* _pAttributeName,
159 : : const ::rtl::OUString& _rPropertyName,
160 : : const sal_Int8 _nBooleanAttributeFlags);
161 : :
162 : : /** add an attribute which is represented by a sal_Int16 property to the export context
163 : :
164 : : @param _nNamespaceKey
165 : : the key of the namespace to use for the attribute name. Is used with the namespace map
166 : : provided by the export context.
167 : : @param _pAttributeName
168 : : the name of the attribute to add. Must not contain any namespace (it's added automatically)
169 : : @param _pPropertyName
170 : : the name of the property to ask the control for
171 : : @param _nDefault
172 : : the default of the attribute. If the current property value equals this default, no
173 : : attribute is added.
174 : : */
175 : : void exportInt16PropertyAttribute(
176 : : const sal_uInt16 _nNamespaceKey,
177 : : const sal_Char* _pAttributeName,
178 : : const ::rtl::OUString& _rPropertyName,
179 : : const sal_Int16 _nDefault);
180 : :
181 : : /** add an attribute which is represented by a sal_Int32 property to the export context
182 : :
183 : : @param _nNamespaceKey
184 : : the key of the namespace to use for the attribute name. Is used with the namespace map
185 : : provided by the export context.
186 : : @param _pAttributeName
187 : : the name of the attribute to add. Must not contain any namespace (it's added automatically)
188 : : @param _pPropertyName
189 : : the name of the property to ask the control for
190 : : @param _nDefault
191 : : the default of the attribute. If the current property value equals this default, no
192 : : attribute is added.
193 : : */
194 : : void exportInt32PropertyAttribute(
195 : : const sal_uInt16 _nNamespaceKey,
196 : : const sal_Char* _pAttributeName,
197 : : const ::rtl::OUString& _rPropertyName,
198 : : const sal_Int32 _nDefault);
199 : :
200 : : /** add an attribute which is represented by a enum property to the export context
201 : :
202 : : @param _nNamespaceKey
203 : : the key of the namespace to use for the attribute name. Is used with the namespace map
204 : : provided by the export context.
205 : : @param _pAttributeName
206 : : the name of the attribute to add. Must not contain any namespace (it's added automatically)
207 : : @param _pPropertyName
208 : : the name of the property to ask the control for
209 : : @param _pValueMap
210 : : the map to use when converting the property value to an attribute value
211 : : @param _nDefault
212 : : the default of the attribute. If the current property value equals this default, no
213 : : attribute is added.
214 : : */
215 : : void exportEnumPropertyAttribute(
216 : : const sal_uInt16 _nNamespaceKey,
217 : : const sal_Char* _pAttributeName,
218 : : const rtl::OUString& _rPropertyName,
219 : : const SvXMLEnumMapEntry* _pValueMap,
220 : : const sal_Int32 _nDefault,
221 : : const sal_Bool _bVoidDefault = sal_False);
222 : :
223 : : // some very special methods for some very special attribute/property pairs
224 : :
225 : : /** add the hlink:target-frame attribute to the export context.
226 : :
227 : : <p>The value of this attribute is extracted from the TargetFrame property of the object given.</p>
228 : :
229 : : <p>The property needs a special handling because conflicts between the default values for the attribute
230 : : and the property.</p>
231 : : */
232 : : void exportTargetFrameAttribute();
233 : :
234 : : /** add the form:href attribute to the export context.
235 : :
236 : : <p>The value of this attribute is extracted from the TargetURL property of the object given.</p>
237 : :
238 : : <p>The property needs a special handling because the URL's need to be made relative</p>
239 : :
240 : : <p>If _bAddType is set, an additional xlink:type="simple" attribute is also added.</p>
241 : : */
242 : 0 : inline void exportTargetLocationAttribute(bool _bAddType) { exportRelativeTargetLocation(PROPERTY_TARGETURL,CCA_TARGET_LOCATION,_bAddType); }
243 : :
244 : : /** add the form:image attribute to the export context.
245 : :
246 : : <p>The value of this attribute is extracted from the ImageURL property of the object given.</p>
247 : :
248 : : <p>The property needs a special handling because the URL's need to be made relative</p>
249 : : */
250 : 0 : inline void exportImageDataAttribute() { exportRelativeTargetLocation(PROPERTY_IMAGEURL,CCA_IMAGE_DATA,false); }
251 : :
252 : : /** flag the style properties as 'already exported'
253 : :
254 : : <p>We don't have style support right now, so the only thing the method does is removing the style-relevant
255 : : properties from the list of yet-to-be-exported properties (<member>m_aRemainingProps</member>)</p>
256 : : */
257 : : void flagStyleProperties();
258 : :
259 : : /** add an arbitrary attribute extracted from an arbitrary property to the export context
260 : :
261 : : <p>The current value of the property specified wiht <arg>_pPropertyName</arg> is taken and converted
262 : : into a string, no matter what type it has. (Okay, there are the usual limitations: We know Date, Datetime,
263 : : double, integer ... to name just a few).</p>
264 : :
265 : : <p>In case the property value is <NULL/> (void), no attribute is added</p>
266 : :
267 : : <p>In case the property value is an empty string, and the property is a not allowed to be <NULL/> (void),
268 : : no attribute is added</p>
269 : :
270 : : <p>In case the property value is a sequence of any type, no attribute is added, 'cause sequences can't be
271 : : transported as attribute. In the debug version, an additional assertion will occur if you nonetheless try
272 : : to do this.</p>
273 : :
274 : : @param _nNamespaceKey
275 : : the key of the namespace to use for the attribute name. Is used with the namespace map
276 : : provided by the export context.
277 : : @param _pAttributeName
278 : : the name of the attribute to add. Must not contain any namespace (it's added automatically)
279 : : @param _pPropertyName
280 : : the name of the property to ask the object for
281 : : */
282 : : void exportGenericPropertyAttribute(
283 : : const sal_uInt16 _nAttributeNamespaceKey,
284 : : const sal_Char* _pAttributeName,
285 : : const sal_Char* _pPropertyName);
286 : :
287 : : /** exports a property value, which is a string sequence, as attribute
288 : :
289 : : <p>The elements of the string sequence given are quoted and concatenated, with the characters used for
290 : : this to be choosen by the caller</p>
291 : :
292 : : <p>If you use the quote character, no check (except assertions) is made if one of the list items
293 : : containes the quote character</p>
294 : :
295 : : <p>If you don't use the quote character, no check (except assertions) is made if one of the list items
296 : : containes the separator character (which would be deadly when reimporting the string)</p>
297 : :
298 : : @param _nNamespaceKey
299 : : the key of the namespace to use for the attribute name. Is used with the namespace map
300 : : provided by the export context.
301 : : @param _pAttributeName
302 : : the name of the attribute to add. Must not contain any namespace (it's added automatically)
303 : : @param _pPropertyName
304 : : the name of the property to ask the object for
305 : : @param _aQuoteCharacter
306 : : the character to use to quote the sequence elements with. May be 0, in this case no quoting happens
307 : : @param _aListSeparator
308 : : the character to use to separate the list entries
309 : : */
310 : : void exportStringSequenceAttribute(
311 : : const sal_uInt16 _nAttributeNamespaceKey,
312 : : const sal_Char* _pAttributeName,
313 : : const ::rtl::OUString& _rPropertyName,
314 : : const sal_Unicode _aQuoteCharacter = '"',
315 : : const sal_Unicode _aListSeparator = ',');
316 : :
317 : : /** determines whether the given property is to be exported
318 : :
319 : : <p>Currently, the method simply checks whether the property's state is <em>not</em> PropertyState.DEFAULT,
320 : : or whether the property is a dynamic property (i.e. added via an <code>XPropertyContainer</code>).
321 : : So, take care when using the method - the heuristics is not applicable for all properties.</p>
322 : : */
323 : : bool shouldExportProperty( const ::rtl::OUString& i_propertyName ) const;
324 : :
325 : : /** tries to convert an arbitrary <type scope="com.sun:star.uno">Any</type> into an string
326 : :
327 : : <p>If the type contained in the Any is not supported, the returned string will be empty. In the
328 : : debug version, an additional assertion occurs.</p>
329 : :
330 : : @param _rValue
331 : : the value to convert
332 : : */
333 : : ::rtl::OUString implConvertAny(
334 : : const ::com::sun::star::uno::Any& _rValue);
335 : :
336 : : /**
337 : : @return
338 : : token which can be used in the <code>form:property</code> element's <code>type</code> attribute
339 : : to describe the type of a value.<br/>
340 : : Possible types returned are
341 : : <ul>
342 : : <li><b>boolean</b>: <arg>_rValue</arg> was interpreted as boolean value before converting
343 : : it into a string</li>
344 : : <li><b>float</b>: <arg>_rValue</arg> was interpreted as 64 bit floating point 16bit integer, 32bit integer or 64 bit integer value before
345 : : converting it into a string</li>
346 : : <li><b>string</b>: <arg>_rValue</arg> did not need any conversion as it already was a string</li>
347 : : </ul>
348 : : If the type is not convertable, float is returned
349 : : */
350 : : ::xmloff::token::XMLTokenEnum implGetPropertyXMLType(const ::com::sun::star::uno::Type& _rType);
351 : :
352 : : #ifdef DBG_UTIL
353 : : void AddAttribute(sal_uInt16 _nPrefix, const sal_Char* _pName, const ::rtl::OUString& _rValue);
354 : : void AddAttribute( sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, const ::rtl::OUString& _rValue );
355 : : void AddAttributeASCII( sal_uInt16 nPrefix, const sal_Char *pName, const sal_Char *pValue );
356 : : void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const ::rtl::OUString& _rValue);
357 : : void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue );
358 : : #else
359 : : // in the product version, inline this, so it does not cost us extra time calling into our method
360 : 0 : inline void AddAttribute(sal_uInt16 _nPrefix, const sal_Char* _pName, const ::rtl::OUString& _rValue)
361 : 0 : { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue); }
362 : 0 : inline void AddAttribute( sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, const ::rtl::OUString& _rValue )
363 : 0 : { m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue ); }
364 : 0 : inline void AddAttributeASCII( sal_uInt16 _nPrefix, const sal_Char* _pName, const sal_Char *pValue )
365 : 0 : { m_rContext.getGlobalContext().AddAttributeASCII(_nPrefix, _pName, pValue); }
366 : 0 : inline void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const ::rtl::OUString& _rValue)
367 : 0 : { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue); }
368 : 0 : inline void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
369 : 0 : { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue); }
370 : : #endif
371 : :
372 : : #ifdef DBG_UTIL
373 : : protected:
374 : : /** check a given property set for the existence and type correctness of a given property
375 : :
376 : : <p>This method is available in the non-product version only.</p>
377 : :
378 : : @param _rPropertyName
379 : : the name of the property to ask the control model for
380 : : @param _pType
381 : : the expected type of the property. May be NULL, in this case no type check is made.
382 : : @return sal_True, if the property exists and is of the correct type
383 : : */
384 : : void dbg_implCheckProperty(
385 : : const ::rtl::OUString& _rPropertyName,
386 : : const ::com::sun::star::uno::Type* _pType);
387 : :
388 : : // void dbg_implCheckProperty(
389 : : // const sal_Char* _rPropertyName,
390 : : // const ::com::sun::star::uno::Type* _pType)
391 : : // {
392 : : // dbg_implCheckProperty(::rtl::OUString::createFromAscii(_rPropertyName), _pType);
393 : : // }
394 : : #endif
395 : : };
396 : :
397 : : //=====================================================================
398 : : //= helper
399 : : //=====================================================================
400 : : #ifdef DBG_UTIL
401 : : #define DBG_CHECK_PROPERTY(name, type) \
402 : : dbg_implCheckProperty(name, &::getCppuType(static_cast< type* >(NULL)))
403 : :
404 : : #define DBG_CHECK_PROPERTY_NO_TYPE(name) \
405 : : dbg_implCheckProperty(name, NULL)
406 : :
407 : : #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name ) \
408 : : dbg_implCheckProperty( ::rtl::OUString::createFromAscii( name ), NULL )
409 : : #else
410 : : #define DBG_CHECK_PROPERTY(name, type)
411 : : #define DBG_CHECK_PROPERTY_NO_TYPE(name)
412 : : #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name )
413 : : #endif
414 : :
415 : : //.........................................................................
416 : : } // namespace xmloff
417 : : //.........................................................................
418 : :
419 : : #endif // _XMLOFF_FORMS_PROPERTYEXPORT_HXX_
420 : :
421 : :
422 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|