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 
34 enum class BoolAttrFlags {
35  DefaultFalse = 0x00,
36  DefaultTrue = 0x01,
37  DefaultVoid = 0x02,
38  InverseSemantics = 0x04,
39 };
40 namespace o3tl {
41  template<> struct typed_flags<BoolAttrFlags> : is_typed_flags<BoolAttrFlags, 0x07> {};
42 }
43 
44 namespace 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 char* _pAttributeName,
133  const OUString& _rPropertyName
134  );
135 
149  const sal_uInt16 _nNamespaceKey,
150  const char* _pAttributeName,
151  const OUString& _rPropertyName,
152  const BoolAttrFlags _nBooleanAttributeFlags);
153 
172  const sal_uInt16 _nNamespaceKey,
173  const char* _pAttributeName,
174  const OUString& _rPropertyName,
175  const sal_Int16 _nDefault,
176  const bool force = false);
177 
192  const sal_uInt16 _nNamespaceKey,
193  const char* _pAttributeName,
194  const OUString& _rPropertyName,
195  const sal_Int32 _nDefault);
196 
212  template<typename EnumT>
214  const sal_uInt16 _nNamespaceKey,
215  const char* _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 char* _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 char* _pAttributeName,
295  const char* _pPropertyName);
296 
317  const sal_uInt16 _nAttributeNamespaceKey,
318  const char* _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 
354  static ::xmloff::token::XMLTokenEnum implGetPropertyXMLType(const css::uno::Type& _rType);
355 
356 #ifdef DBG_UTIL
357  void AddAttribute(sal_uInt16 _nPrefix, const char* _pName, const OUString& _rValue);
358  void AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue );
359  void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue);
360  void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue );
361 #else
362  // in the product version, inline this, so it does not cost us extra time calling into our method
363  void AddAttribute(sal_uInt16 _nPrefix, const char* _pName, const OUString& _rValue)
364  { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue); }
365  void AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue )
366  { m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue ); }
367  void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue)
368  { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue); }
369  void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
370  { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue); }
371 #endif
372 
373 #ifdef DBG_UTIL
374  protected:
386  const OUString& _rPropertyName,
387  const css::uno::Type* _pType);
388 
389 // void dbg_implCheckProperty(
390 // const char* _rPropertyName,
391 // const css::uno::Type* _pType)
392 // {
393 // dbg_implCheckProperty(OUString::createFromAscii(_rPropertyName), _pType);
394 // }
395 #endif
396  };
397 
398  //= helper
399 #ifdef DBG_UTIL
400  #define DBG_CHECK_PROPERTY(name, type) \
401  dbg_implCheckProperty(name, &cppu::UnoType<type>::get())
402 
403  #define DBG_CHECK_PROPERTY_NO_TYPE(name) \
404  dbg_implCheckProperty(name, nullptr)
405 
406  #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name ) \
407  dbg_implCheckProperty( OUString::createFromAscii( name ), nullptr )
408 #else
409  #define DBG_CHECK_PROPERTY(name, type)
410  #define DBG_CHECK_PROPERTY_NO_TYPE(name)
411  #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name )
412 #endif
413 
414 } // namespace xmloff
415 
416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Reference< css::beans::XPropertySetInfo > m_xPropertyInfo
void exportedProperty(const OUString &_rPropertyName)
indicates that a property has been handled by a derived class, without using the helper methods of th...
const css::uno::Reference< css::beans::XPropertyState > m_xPropertyState
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 exportEnumPropertyAttribute(const sal_uInt16 _nNamespaceKey, const char *_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
void exportEnumPropertyAttributeImpl(const sal_uInt16 _nNamespaceKey, const char *_pAttributeName, const OUString &_rPropertyName, const SvXMLEnumMapEntry< sal_uInt16 > *_pValueMap, const sal_uInt16 _nDefault, const bool _bVoidDefault)
provides export related tools for attribute handling
void exportRemainingPropertiesSequence(css::uno::Any const &value, token::XMLTokenEnum eValueAttName)
const css::uno::Reference< css::beans::XPropertySet > m_xProps
std::set< OUString > m_aRemainingProps
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:939
#define PROPERTY_TARGETURL
Definition: strings.hxx:33
IFormsExportContext & m_rContext
bool shouldExportProperty(const OUString &i_propertyName) const
determines whether the given property is to be exported
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
CCAFlags
void exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey, const char *_pAttributeName, const OUString &_rPropertyName, const BoolAttrFlags _nBooleanAttributeFlags)
add an attribute which is represented by a boolean property to the export context ...
void exportImageDataAttribute()
add the form:image attribute to the export context.
virtual SvXMLExport & getGlobalContext()=0
::xmloff::token::XMLTokenEnum implGetPropertyXMLType(const css::uno::Type &_rType)
#define PROPERTY_GRAPHIC
Definition: strings.hxx:30
void exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey, const char *_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 exportInt32PropertyAttribute(const sal_uInt16 _nNamespaceKey, const char *_pAttributeName, const OUString &_rPropertyName, const sal_Int32 _nDefault)
add an attribute which is represented by a sal_Int32 property to the export context ...
void exportRelativeTargetLocation(const OUString &_sPropertyName, CCAFlags _nProperty, bool _bAddType)
Map an XMLTokenEnum to an enum value.
Definition: ximpshap.hxx:39
OUString implConvertAny(const css::uno::Any &_rValue)
tries to convert an arbitrary Any into an string ...
void flagStyleProperties()
flag the style properties as 'already exported'
void exportTargetFrameAttribute()
add the hlink:target-frame attribute to the export context.
void exportGenericPropertyAttribute(const sal_uInt16 _nAttributeNamespaceKey, const char *_pAttributeName, const char *_pPropertyName)
add an arbitrary attribute extracted from an arbitrary property to the export context ...
void AddAttribute(sal_uInt16 _nPrefix, const char *_pName, const OUString &_rValue)
void exportStringPropertyAttribute(const sal_uInt16 _nNamespaceKey, const char *_pAttributeName, const OUString &_rPropertyName)
add an attribute which is represented by a string property to the export context
void exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const char *_pAttributeName, const OUString &_rPropertyName)
exports a property value, which is a string sequence, as attribute
BoolAttrFlags
void examinePersistence()
examines a property set given for all properties which's value are to made persistent ...
OPropertyExport(IFormsExportContext &_rContext, const css::uno::Reference< css::beans::XPropertySet > &_rxProps)
constructs an object capable of handling attributes for export
void exportTargetLocationAttribute(bool _bAddType)
add the form:href attribute to the export context.