LibreOffice Module xmloff (master) 1
propertyexport.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23
24#include <set>
25
26#include "formattributes.hxx"
27#include <com/sun/star/beans/XPropertySet.hpp>
28#include <com/sun/star/beans/XPropertyState.hpp>
29#include <xmloff/xmltoken.hxx>
30#include <xmloff/xmlexp.hxx>
31#include "callbacks.hxx"
32#include "strings.hxx"
33
34enum class BoolAttrFlags {
35 DefaultFalse = 0x00,
36 DefaultTrue = 0x01,
37 DefaultVoid = 0x02,
38 InverseSemantics = 0x04,
39};
40namespace o3tl {
41 template<> struct typed_flags<BoolAttrFlags> : is_typed_flags<BoolAttrFlags, 0x07> {};
42}
43
44namespace xmloff
45{
46
47 // if sal_True, indicates that the semantic of the property referred by <arg>_pPropertyName</arg>
48 // is inverse to the semantic of the XML attribute.<br/>
49 // I.e. if the property value is <TRUE/>, <FALSE/> has to be written and vice versa.
50 // <p>Be careful with <arg>_bDefault</arg> and <arg>_bInverseSemantics</arg>: if <arg>_bInverseSemantics</arg>
51 // is <TRUE/>, the current property value is inverted <em>before</em> comparing it to the default.</p>
52
53 class IFormsExportContext;
54 //= OPropertyExport
61 {
62 private:
63 std::set<OUString> m_aRemainingProps;
64 // see examinePersistence
65
66 void exportRelativeTargetLocation(const OUString& _sPropertyName, CCAFlags _nProperty,bool _bAddType);
67
68 protected:
70
71 const css::uno::Reference< css::beans::XPropertySet >
73 const css::uno::Reference< css::beans::XPropertySetInfo >
75 const css::uno::Reference< css::beans::XPropertyState >
77
78 // caching
79 OUString m_sValueTrue;
80 OUString m_sValueFalse;
81
82 public:
90 const css::uno::Reference< css::beans::XPropertySet >& _rxProps);
91
92 protected:
98 void examinePersistence();
99
100 template< typename T > void exportRemainingPropertiesSequence(
101 css::uno::Any const & value,
102 token::XMLTokenEnum eValueAttName);
103
105
117 void exportedProperty(const OUString& _rPropertyName)
118 { m_aRemainingProps.erase(_rPropertyName); }
119
131 const sal_uInt16 _nNamespaceKey,
132 const OUString& _pAttributeName,
133 const OUString& _rPropertyName
134 );
135
149 const sal_uInt16 _nNamespaceKey,
150 const OUString& _pAttributeName,
151 const OUString& _rPropertyName,
152 const BoolAttrFlags _nBooleanAttributeFlags);
153
172 const sal_uInt16 _nNamespaceKey,
173 const OUString& _pAttributeName,
174 const OUString& _rPropertyName,
175 const sal_Int16 _nDefault,
176 const bool force = false);
177
192 const sal_uInt16 _nNamespaceKey,
193 const OUString& _pAttributeName,
194 const OUString& _rPropertyName,
195 const sal_Int32 _nDefault);
196
212 template<typename EnumT>
214 const sal_uInt16 _nNamespaceKey,
215 const OUString& _pAttributeName,
216 const OUString& _rPropertyName,
217 const SvXMLEnumMapEntry<EnumT>* _pValueMap,
218 const EnumT _nDefault,
219 const bool _bVoidDefault = false)
220 {
221 exportEnumPropertyAttributeImpl(_nNamespaceKey, _pAttributeName, _rPropertyName,
222 reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(_pValueMap),
223 static_cast<sal_Int16>(_nDefault), _bVoidDefault);
224 }
226 const sal_uInt16 _nNamespaceKey,
227 const OUString& _pAttributeName,
228 const OUString& _rPropertyName,
229 const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
230 const sal_uInt16 _nDefault,
231 const bool _bVoidDefault);
232
233 // some very special methods for some very special attribute/property pairs
234
243
253
261
267 void flagStyleProperties();
268
293 const sal_uInt16 _nAttributeNamespaceKey,
294 const OUString& _pAttributeName,
295 const OUString& _pPropertyName);
296
317 const sal_uInt16 _nAttributeNamespaceKey,
318 const OUString& _pAttributeName,
319 const OUString& _rPropertyName);
320
327 bool shouldExportProperty( const OUString& i_propertyName ) const;
328
337 OUString implConvertAny(
338 const css::uno::Any& _rValue);
339
355
356#ifdef DBG_UTIL
357 void AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue );
358 void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue);
359 void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue );
360#else
361 // in the product version, inline this, so it does not cost us extra time calling into our method
362 void AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue )
363 { m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue ); }
364 void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue)
365 { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue); }
366 void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
367 { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue); }
368#endif
369
370#ifdef DBG_UTIL
371 protected:
383 const OUString& _rPropertyName,
384 const css::uno::Type* _pType);
385
386// void dbg_implCheckProperty(
387// const char* _rPropertyName,
388// const css::uno::Type* _pType)
389// {
390// dbg_implCheckProperty(OUString::createFromAscii(_rPropertyName), _pType);
391// }
392#endif
393 };
394
395 //= helper
396#ifdef DBG_UTIL
397 #define DBG_CHECK_PROPERTY(name, type) \
398 dbg_implCheckProperty(name, &cppu::UnoType<type>::get())
399
400 #define DBG_CHECK_PROPERTY_NO_TYPE(name) \
401 dbg_implCheckProperty(name, nullptr)
402
403 #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name ) \
404 dbg_implCheckProperty( OUString::createFromAscii( name ), nullptr )
405#else
406 #define DBG_CHECK_PROPERTY(name, type)
407 #define DBG_CHECK_PROPERTY_NO_TYPE(name)
408 #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name )
409#endif
410
411} // namespace xmloff
412
413/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:907
virtual SvXMLExport & getGlobalContext()=0
provides export related tools for attribute handling
void exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName)
exports a property value, which is a string sequence, as attribute
void exportEnumPropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName, const SvXMLEnumMapEntry< EnumT > *_pValueMap, const EnumT _nDefault, const bool _bVoidDefault=false)
add an attribute which is represented by an enum property to the export context
OPropertyExport(IFormsExportContext &_rContext, const css::uno::Reference< css::beans::XPropertySet > &_rxProps)
constructs an object capable of handling attributes for export
void examinePersistence()
examines a property set given for all properties which's value are to made persistent
IFormsExportContext & m_rContext
void exportInt32PropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName, const sal_Int32 _nDefault)
add an attribute which is represented by a sal_Int32 property to the export context
void exportedProperty(const OUString &_rPropertyName)
indicates that a property has been handled by a derived class, without using the helper methods of th...
bool shouldExportProperty(const OUString &i_propertyName) const
determines whether the given property is to be exported
void flagStyleProperties()
flag the style properties as 'already exported'
std::set< OUString > m_aRemainingProps
void exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName, const sal_Int16 _nDefault, const bool force=false)
add an attribute which is represented by a sal_Int16 property to the export context
void exportImageDataAttribute()
add the form:image attribute to the export context.
const css::uno::Reference< css::beans::XPropertySet > m_xProps
const css::uno::Reference< css::beans::XPropertyState > m_xPropertyState
::xmloff::token::XMLTokenEnum implGetPropertyXMLType(const css::uno::Type &_rType)
void exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName, const BoolAttrFlags _nBooleanAttributeFlags)
add an attribute which is represented by a boolean property to the export context
void exportGenericPropertyAttribute(const sal_uInt16 _nAttributeNamespaceKey, const OUString &_pAttributeName, const OUString &_pPropertyName)
add an arbitrary attribute extracted from an arbitrary property to the export context
void exportEnumPropertyAttributeImpl(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName, const SvXMLEnumMapEntry< sal_uInt16 > *_pValueMap, const sal_uInt16 _nDefault, const bool _bVoidDefault)
OUString implConvertAny(const css::uno::Any &_rValue)
tries to convert an arbitrary <type scope="com.sun:star.uno">Any</type> into an string
void exportRelativeTargetLocation(const OUString &_sPropertyName, CCAFlags _nProperty, bool _bAddType)
void exportRemainingPropertiesSequence(css::uno::Any const &value, token::XMLTokenEnum eValueAttName)
void exportStringPropertyAttribute(const sal_uInt16 _nNamespaceKey, const OUString &_pAttributeName, const OUString &_rPropertyName)
add an attribute which is represented by a string property to the export context
const css::uno::Reference< css::beans::XPropertySetInfo > m_xPropertyInfo
void dbg_implCheckProperty(const OUString &_rPropertyName, const css::uno::Type *_pType)
check a given property set for the existence and type correctness of a given property
void AddAttribute(sal_uInt16 _nPrefix, const OUString &_rName, const OUString &_rValue)
void exportTargetLocationAttribute(bool _bAddType)
add the form:href attribute to the export context.
void exportTargetFrameAttribute()
add the hlink:target-frame attribute to the export context.
CCAFlags
@ TargetLocation
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
constexpr OUStringLiteral PROPERTY_GRAPHIC
Definition: strings.hxx:32
constexpr OUStringLiteral PROPERTY_TARGETURL
Definition: strings.hxx:35
BoolAttrFlags