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 #ifndef INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYEXPORT_HXX
21 #define INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYEXPORT_HXX
22 
23 #include <sal/config.h>
24 
25 #include <set>
26 
27 #include "formattributes.hxx"
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/XPropertyState.hpp>
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/xmlexp.hxx>
32 #include "callbacks.hxx"
33 #include "strings.hxx"
34 
35 enum class BoolAttrFlags {
36  DefaultFalse = 0x00,
37  DefaultTrue = 0x01,
38  DefaultVoid = 0x02,
39  InverseSemantics = 0x04,
40 };
41 namespace o3tl {
42  template<> struct typed_flags<BoolAttrFlags> : is_typed_flags<BoolAttrFlags, 0x07> {};
43 }
44 
45 namespace xmloff
46 {
47 
48  // if sal_True, indicates that the semantic of the property referred by <arg>_pPropertyName</arg>
49  // is inverse to the semantic of the XML attribute.<br/>
50  // I.e. if the property value is <TRUE/>, <FALSE/> has to be written and vice versa.
51  // <p>Be careful with <arg>_bDefault</arg> and <arg>_bInverseSemantics</arg>: if <arg>_bInverseSemantics</arg>
52  // is <TRUE/>, the current property value is inverted <em>before</em> comparing it to the default.</p>
53 
54  class IFormsExportContext;
55  //= OPropertyExport
62  {
63  private:
64  std::set<OUString> m_aRemainingProps;
65  // see examinePersistence
66 
67  void exportRelativeTargetLocation(const OUString& _sPropertyName, CCAFlags _nProperty,bool _bAddType);
68 
69  protected:
71 
72  const css::uno::Reference< css::beans::XPropertySet >
74  const css::uno::Reference< css::beans::XPropertySetInfo >
76  const css::uno::Reference< css::beans::XPropertyState >
78 
79  // caching
80  OUString m_sValueTrue;
81  OUString m_sValueFalse;
82 
83  public:
91  const css::uno::Reference< css::beans::XPropertySet >& _rxProps);
92 
93  protected:
99  void examinePersistence();
100 
101  template< typename T > void exportRemainingPropertiesSequence(
102  css::uno::Any const & value,
103  token::XMLTokenEnum eValueAttName);
104 
106 
118  void exportedProperty(const OUString& _rPropertyName)
119  { m_aRemainingProps.erase(_rPropertyName); }
120 
132  const sal_uInt16 _nNamespaceKey,
133  const char* _pAttributeName,
134  const OUString& _rPropertyName
135  );
136 
150  const sal_uInt16 _nNamespaceKey,
151  const char* _pAttributeName,
152  const OUString& _rPropertyName,
153  const BoolAttrFlags _nBooleanAttributeFlags);
154 
173  const sal_uInt16 _nNamespaceKey,
174  const char* _pAttributeName,
175  const OUString& _rPropertyName,
176  const sal_Int16 _nDefault,
177  const bool force = false);
178 
193  const sal_uInt16 _nNamespaceKey,
194  const char* _pAttributeName,
195  const OUString& _rPropertyName,
196  const sal_Int32 _nDefault);
197 
213  template<typename EnumT>
215  const sal_uInt16 _nNamespaceKey,
216  const char* _pAttributeName,
217  const OUString& _rPropertyName,
218  const SvXMLEnumMapEntry<EnumT>* _pValueMap,
219  const EnumT _nDefault,
220  const bool _bVoidDefault = false)
221  {
222  exportEnumPropertyAttributeImpl(_nNamespaceKey, _pAttributeName, _rPropertyName,
223  reinterpret_cast<const SvXMLEnumMapEntry<sal_uInt16>*>(_pValueMap),
224  static_cast<sal_Int16>(_nDefault), _bVoidDefault);
225  }
227  const sal_uInt16 _nNamespaceKey,
228  const char* _pAttributeName,
229  const OUString& _rPropertyName,
230  const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
231  const sal_uInt16 _nDefault,
232  const bool _bVoidDefault);
233 
234  // some very special methods for some very special attribute/property pairs
235 
244 
254 
262 
268  void flagStyleProperties();
269 
294  const sal_uInt16 _nAttributeNamespaceKey,
295  const char* _pAttributeName,
296  const char* _pPropertyName);
297 
318  const sal_uInt16 _nAttributeNamespaceKey,
319  const char* _pAttributeName,
320  const OUString& _rPropertyName);
321 
328  bool shouldExportProperty( const OUString& i_propertyName ) const;
329 
338  OUString implConvertAny(
339  const css::uno::Any& _rValue);
340 
355  static ::xmloff::token::XMLTokenEnum implGetPropertyXMLType(const css::uno::Type& _rType);
356 
357 #ifdef DBG_UTIL
358  void AddAttribute(sal_uInt16 _nPrefix, const char* _pName, const OUString& _rValue);
359  void AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue );
360  void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue);
361  void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue );
362 #else
363  // in the product version, inline this, so it does not cost us extra time calling into our method
364  void AddAttribute(sal_uInt16 _nPrefix, const char* _pName, const OUString& _rValue)
365  { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue); }
366  void AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue )
367  { m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue ); }
368  void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue)
369  { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue); }
370  void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
371  { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue); }
372 #endif
373 
374 #ifdef DBG_UTIL
375  protected:
387  const OUString& _rPropertyName,
388  const css::uno::Type* _pType);
389 
390 // void dbg_implCheckProperty(
391 // const char* _rPropertyName,
392 // const css::uno::Type* _pType)
393 // {
394 // dbg_implCheckProperty(OUString::createFromAscii(_rPropertyName), _pType);
395 // }
396 #endif
397  };
398 
399  //= helper
400 #ifdef DBG_UTIL
401  #define DBG_CHECK_PROPERTY(name, type) \
402  dbg_implCheckProperty(name, &cppu::UnoType<type>::get())
403 
404  #define DBG_CHECK_PROPERTY_NO_TYPE(name) \
405  dbg_implCheckProperty(name, nullptr)
406 
407  #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name ) \
408  dbg_implCheckProperty( OUString::createFromAscii( name ), nullptr )
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 } // namespace xmloff
416 
417 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYEXPORT_HXX
418 
419 /* 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:909
#define PROPERTY_TARGETURL
Definition: strings.hxx:34
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:31
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:40
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.