LibreOffice Module xmloff (master)  1
propertyexport.cxx
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 #include "propertyexport.hxx"
21 
22 #include <memory>
23 
24 #include <xmloff/xmlexp.hxx>
25 #include "strings.hxx"
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <xmloff/xmlexppr.hxx>
29 #include <xmloff/xmlprmap.hxx>
30 #include <sax/tools/converter.hxx>
31 #include <sal/log.hxx>
32 #include <tools/diagnose_ex.h>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/util/Date.hpp>
35 #include <com/sun/star/graphic/XGraphic.hpp>
36 #include <com/sun/star/util/Time.hpp>
37 #include <com/sun/star/util/DateTime.hpp>
38 #include <comphelper/extract.hxx>
39 #include <comphelper/types.hxx>
40 #include "callbacks.hxx"
41 #include <unotools/datetime.hxx>
42 #include <tools/date.hxx>
43 #include <tools/datetime.hxx>
44 
45 namespace xmloff
46 {
47 
48  using namespace css;
49  using namespace ::com::sun::star::uno;
50  using namespace ::com::sun::star::lang;
51  using namespace ::com::sun::star::beans;
52 
53  // NO using namespace ...util !!!
54  // need a tools Date/Time/DateTime below, which would conflict with the uno types then
55 
56  using namespace ::comphelper;
57 
58  //= OPropertyExport
60  :m_rContext(_rContext)
61  ,m_xProps(_rxProps)
62  ,m_xPropertyInfo( m_xProps->getPropertySetInfo() )
63  ,m_xPropertyState( _rxProps, UNO_QUERY )
64  {
65  // caching
66  OUStringBuffer aBuffer;
67  ::sax::Converter::convertBool(aBuffer, true);
68  m_sValueTrue = aBuffer.makeStringAndClear();
69  ::sax::Converter::convertBool(aBuffer, false);
70  m_sValueFalse = aBuffer.makeStringAndClear();
71 
72  OSL_ENSURE(m_xPropertyInfo.is(), "OPropertyExport::OPropertyExport: need an XPropertySetInfo!");
73 
74  // collect the properties which need to be exported
76  }
77 
78  bool OPropertyExport::shouldExportProperty( const OUString& i_propertyName ) const
79  {
80  // if the property state is DEFAULT, it does not need to be written - at least
81  // if it's a built-in property, and not a dynamically-added one.
82  bool bIsDefaultValue = m_xPropertyState.is()
83  && ( PropertyState_DEFAULT_VALUE == m_xPropertyState->getPropertyState( i_propertyName ) );
84  bool bIsDynamicProperty = m_xPropertyInfo.is()
85  && ( ( m_xPropertyInfo->getPropertyByName( i_propertyName ).Attributes & PropertyAttribute::REMOVABLE ) != 0 );
86  return ( !bIsDefaultValue || bIsDynamicProperty );
87  }
88 
89  template< typename T > void
91  Any const & value, token::XMLTokenEnum eValueAttName)
92  {
93  css::uno::Sequence<T> anySeq;
94  bool bSuccess = value >>= anySeq;
95  assert(bSuccess); (void)bSuccess;
96  for (T const & i : anySeq)
97  {
98  OUString sValue(implConvertAny(makeAny(i)));
99  AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
100  SvXMLElementExport aValueTag(
102  token::XML_LIST_VALUE, true, false);
103  }
104  }
105 
107  {
108  // the properties tag (will be created if we have at least one no-default property)
109  std::unique_ptr<SvXMLElementExport> pPropertiesTag;
110 
111  Any aValue;
112  OUString sValue;
113 
114  // loop through all the properties which are yet to be exported
115  for ( const auto& rProperty : m_aRemainingProps )
116  {
117  DBG_CHECK_PROPERTY_NO_TYPE(rProperty);
118 
119  if ( !shouldExportProperty( rProperty ) )
120  continue;
121 
122  // now that we have the first sub-tag we need the form:properties element
123  if (!pPropertiesTag)
124  pPropertiesTag = std::make_unique<SvXMLElementExport>(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, token::XML_PROPERTIES, true, true);
125 
126  // add the name attribute
128 
129  // get the value
130  aValue = m_xProps->getPropertyValue(rProperty);
131 
132  // the type to export
133  Type aExportType;
134 
135  // is it a sequence
136  bool bIsSequence = TypeClass_SEQUENCE == aValue.getValueTypeClass();
137  // the type of the property, maybe reduced to the element type of a sequence
138  if (bIsSequence)
139  aExportType = getSequenceElementType( aValue.getValueType() );
140  else
141  aExportType = aValue.getValueType();
142 
143  // the type attribute
144 
145  bool bIsEmptyValue = TypeClass_VOID == aValue.getValueType().getTypeClass();
146  if ( bIsEmptyValue )
147  {
148  css::beans::Property aPropDesc = m_xPropertyInfo->getPropertyByName( rProperty );
149  aExportType = aPropDesc.Type;
150  }
151  token::XMLTokenEnum eValueType = implGetPropertyXMLType( aExportType );
152 
153  if ( bIsEmptyValue )
155  else
157 
158  token::XMLTokenEnum eValueAttName( token::XML_VALUE );
159  switch ( eValueType )
160  {
161  case token::XML_BOOLEAN: eValueAttName = token::XML_BOOLEAN_VALUE; break;
162  case token::XML_STRING: eValueAttName = token::XML_STRING_VALUE; break;
163  default: break;
164  }
165 
166  if( !bIsSequence && !bIsEmptyValue )
167  { // the simple case
168 
169  sValue = implConvertAny(aValue);
170  AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
171  }
172 
173  // start the property tag
176  bIsSequence ? token::XML_LIST_PROPERTY
177  : token::XML_PROPERTY, true, true);
178 
179  if (!bIsSequence)
180  continue;
181 
182  // the not-that-simple case, we need to iterate through the sequence elements
183  switch ( aExportType.getTypeClass() )
184  {
185  case TypeClass_STRING:
186  exportRemainingPropertiesSequence< OUString >(
187  aValue, eValueAttName);
188  break;
189  case TypeClass_DOUBLE:
190  exportRemainingPropertiesSequence< double >(
191  aValue, eValueAttName);
192  break;
193  case TypeClass_BOOLEAN:
194  exportRemainingPropertiesSequence< sal_Bool >(
195  aValue, eValueAttName);
196  break;
197  case TypeClass_BYTE:
198  exportRemainingPropertiesSequence< sal_Int8 >(
199  aValue, eValueAttName);
200  break;
201  case TypeClass_SHORT:
202  exportRemainingPropertiesSequence< sal_Int16 >(
203  aValue, eValueAttName);
204  break;
205  case TypeClass_LONG:
206  exportRemainingPropertiesSequence< sal_Int32 >(
207  aValue, eValueAttName);
208  break;
209  case TypeClass_HYPER:
210  exportRemainingPropertiesSequence< sal_Int64 >(
211  aValue, eValueAttName);
212  break;
213  default:
214  OSL_FAIL("OPropertyExport::exportRemainingProperties: unsupported sequence type !");
215  break;
216  }
217  }
218  }
219 
221  {
222  m_aRemainingProps.clear();
223  const Sequence< Property > aProperties = m_xPropertyInfo->getProperties();
224  for (const auto& rProp : aProperties)
225  {
226  // no transient props
227  if ( rProp.Attributes & PropertyAttribute::TRANSIENT )
228  continue;
229  // no read-only props
230  if ( ( rProp.Attributes & PropertyAttribute::READONLY ) != 0 )
231  // except they're dynamically added
232  if ( ( rProp.Attributes & PropertyAttribute::REMOVABLE ) == 0 )
233  continue;
234  m_aRemainingProps.insert(rProp.Name);
235  }
236  }
237 
238  void OPropertyExport::exportStringPropertyAttribute( const sal_uInt16 _nNamespaceKey, const char* _pAttributeName,
239  const OUString& _rPropertyName )
240  {
241  DBG_CHECK_PROPERTY( _rPropertyName, OUString );
242 
243  // no try-catch here, this would be too expensive. The outer scope has to handle exceptions (which should not
244  // happen if we're used correctly :)
245 
246  // this is way simple, as we don't need to convert anything (the property already is a string)
247 
248  // get the string
249  OUString sPropValue;
250  m_xProps->getPropertyValue( _rPropertyName ) >>= sPropValue;
251 
252  // add the attribute
253  if ( !sPropValue.isEmpty() )
254  AddAttribute( _nNamespaceKey, _pAttributeName, sPropValue );
255 
256  // the property does not need to be handled anymore
257  exportedProperty( _rPropertyName );
258  }
259 
260  void OPropertyExport::exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey, const char* _pAttributeName,
261  const OUString& _rPropertyName, const BoolAttrFlags _nBooleanAttributeFlags)
262  {
263  DBG_CHECK_PROPERTY_NO_TYPE( _rPropertyName );
264  // no check of the property value type: this method is allowed to be called with any integer properties
265  // (e.g. sal_Int32, sal_uInt16 etc)
266 
267  bool bDefault(BoolAttrFlags::DefaultTrue & _nBooleanAttributeFlags);
268  bool bDefaultVoid(BoolAttrFlags::DefaultVoid & _nBooleanAttributeFlags);
269 
270  // get the value
271  bool bCurrentValue = bDefault;
272  Any aCurrentValue = m_xProps->getPropertyValue( _rPropertyName );
273  if (aCurrentValue.hasValue())
274  {
275  bCurrentValue = ::cppu::any2bool(aCurrentValue);
276  // this will extract a boolean value even if the Any contains a int or short or something like that ...
277 
278  if (_nBooleanAttributeFlags & BoolAttrFlags::InverseSemantics)
279  bCurrentValue = !bCurrentValue;
280 
281  // we have a non-void current value
282  if (bDefaultVoid || (bDefault != bCurrentValue))
283  // and (the default is void, or the non-void default does not equal the current value)
284  // -> write the attribute
285  AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
286  }
287  else
288  // we have a void current value
289  if (!bDefaultVoid)
290  // and we have a non-void default
291  // -> write the attribute
292  AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
293 
294  // the property does not need to be handled anymore
295  exportedProperty( _rPropertyName );
296  }
297 
298  void OPropertyExport::exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey, const char* _pAttributeName,
299  const OUString& _rPropertyName, const sal_Int16 _nDefault, bool force)
300  {
301  DBG_CHECK_PROPERTY( _rPropertyName, sal_Int16 );
302 
303  // get the value
304  sal_Int16 nCurrentValue(_nDefault);
305  m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
306 
307  // add the attribute
308  if (force || _nDefault != nCurrentValue)
309  {
310  // let the formatter of the export context build a string
311  AddAttribute(_nNamespaceKey, _pAttributeName, OUString::number(nCurrentValue));
312  }
313 
314  // the property does not need to be handled anymore
315  exportedProperty( _rPropertyName );
316  }
317 
318  void OPropertyExport::exportInt32PropertyAttribute( const sal_uInt16 _nNamespaceKey, const char* _pAttributeName,
319  const OUString& _rPropertyName, const sal_Int32 _nDefault )
320  {
321  DBG_CHECK_PROPERTY( _rPropertyName, sal_Int32 );
322 
323  // get the value
324  sal_Int32 nCurrentValue( _nDefault );
325  m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
326 
327  // add the attribute
328  if ( _nDefault != nCurrentValue )
329  {
330  // let the formatter of the export context build a string
331  AddAttribute( _nNamespaceKey, _pAttributeName, OUString::number(nCurrentValue) );
332  }
333 
334  // the property does not need to be handled anymore
335  exportedProperty( _rPropertyName );
336  }
337 
339  const sal_uInt16 _nNamespaceKey, const char* _pAttributeName,
340  const OUString &rPropertyName, const SvXMLEnumMapEntry<sal_uInt16>* _pValueMap,
341  const sal_uInt16 _nDefault, const bool _bVoidDefault)
342  {
343  // get the value
344  Any aValue = m_xProps->getPropertyValue(rPropertyName);
345 
346  if (aValue.hasValue())
347  { // we have a non-void current value
348  sal_Int32 nCurrentValue(_nDefault);
349  ::cppu::enum2int(nCurrentValue, aValue);
350 
351  // add the attribute
352  if ((_nDefault != nCurrentValue) || _bVoidDefault)
353  { // the default does not equal the value, or the default is void and the value isn't
354 
355  // let the formatter of the export context build a string
356  OUStringBuffer sBuffer;
357  SvXMLUnitConverter::convertEnum(sBuffer, static_cast<sal_uInt16>(nCurrentValue), _pValueMap);
358 
359  AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
360  }
361  }
362  else
363  {
364  if (!_bVoidDefault)
365  AddAttribute(_nNamespaceKey, _pAttributeName, OUString());
366  }
367 
368  // the property does not need to be handled anymore
369  exportedProperty(rPropertyName);
370  }
371 
373  {
375 
376  OUString sTargetFrame = comphelper::getString(m_xProps->getPropertyValue(PROPERTY_TARGETFRAME));
377  if( sTargetFrame != "_blank" )
378  { // an empty string and "_blank" have the same meaning and don't have to be written
381  ,sTargetFrame);
382  }
383 
385  }
386 
387  void OPropertyExport::exportRelativeTargetLocation(const OUString& _sPropertyName,CCAFlags _nProperty,bool _bAddType)
388  {
389  Any aAny = m_xProps->getPropertyValue(_sPropertyName);
390 
391  OUString sTargetLocation;
392  if (aAny.has<uno::Reference<graphic::XGraphic>>())
393  {
394  auto xGraphic = aAny.get<uno::Reference<graphic::XGraphic>>();
395  OUString sOutMimeType;
396  sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedXGraphic(xGraphic, sOutMimeType);
397  }
398  else if (aAny.has<OUString>())
399  {
400  auto sURL = aAny.get<OUString>();
401  sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedObject(sURL);
402  }
403  else
404  {
405  SAL_WARN("xmloff.forms", "OPropertyExport::exportRelativeTargetLocation: "
406  "Value of " << _sPropertyName << " not found!");
407  }
408 
409  if (!sTargetLocation.isEmpty())
410  {
413  , sTargetLocation);
414 
415  // #i110911# add xlink:type="simple" if required
416  if (_bAddType)
418 
419  exportedProperty(_sPropertyName);
420  }
421  }
423  {
424  // flag all the properties which are part of the style as "handled"
425  rtl::Reference< XMLPropertySetMapper > xStylePropertiesSupplier = m_rContext.getStylePropertyMapper()->getPropertySetMapper();
426  for (sal_Int32 i=0; i<xStylePropertiesSupplier->GetEntryCount(); ++i)
427  exportedProperty(xStylePropertiesSupplier->GetEntryAPIName(i));
428 
429  // the font properties are exported as single properties, but there is a FontDescriptor property which
430  // collects them all-in-one, this has been exported implicitly
432 
433  // for the DateFormat and TimeFormat, there exist wrapper properties which has been exported as
434  // style, too
437 
438  // the following properties should have been exported at the shape already:
439  exportedProperty( "VerticalAlign" );
440  exportedProperty( "WritingMode" );
441  exportedProperty( "ScaleMode" );
442  // ditto the TextWritingMode
443  exportedProperty( "WritingMode" );
444  }
445 
447  const sal_uInt16 _nAttributeNamespaceKey, const char* _pAttributeName, const char* _pPropertyName)
448  {
449  DBG_CHECK_PROPERTY_ASCII_NO_TYPE( _pPropertyName );
450 
451  OUString sPropertyName = OUString::createFromAscii(_pPropertyName);
452  exportedProperty(sPropertyName);
453 
454  Any aCurrentValue = m_xProps->getPropertyValue(sPropertyName);
455  if (!aCurrentValue.hasValue())
456  // nothing to do without a concrete value
457  return;
458 
459  OUString sValue = implConvertAny(aCurrentValue);
460  if (sValue.isEmpty() && (TypeClass_STRING == aCurrentValue.getValueTypeClass()))
461  {
462  // check whether or not the property is allowed to be VOID
463  Property aProperty = m_xPropertyInfo->getPropertyByName(sPropertyName);
464  if ((aProperty.Attributes & PropertyAttribute::MAYBEVOID) == 0)
465  // the string is empty, and the property is not allowed to be void
466  // -> don't need to write the attribute, 'cause missing it is unambiguous
467  return;
468  }
469 
470  // finally add the attribute to the context
471  AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sValue);
472  }
473 
474  void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const char* _pAttributeName,
475  const OUString& _rPropertyName)
476  {
477  const sal_Unicode _aListSeparator = ',';
478  const sal_Unicode _aQuoteCharacter = '"';
479  DBG_CHECK_PROPERTY( _rPropertyName, Sequence< OUString > );
480 
481  Sequence< OUString > aItems;
482  m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
483 
484  OUStringBuffer sFinalList;
485 
486  // unfortunately the OUString can't append single sal_Unicode characters ...
487  const OUString sQuote(&_aQuoteCharacter, 1);
488  const OUString sSeparator(&_aListSeparator, 1);
489  const bool bQuote = !sQuote.isEmpty();
490 
491  // concatenate the string items
492  const OUString* pItems = aItems.getConstArray();
493  const OUString* pEnd = pItems + aItems.getLength();
494  const OUString* pLastElement = pEnd - 1;
495  for ( ;
496  pItems != pEnd;
497  ++pItems
498  )
499  {
500  OSL_ENSURE(-1 == pItems->indexOf(_aQuoteCharacter),
501  "OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
502 
503  if (bQuote)
504  sFinalList.append(sQuote);
505  sFinalList.append(*pItems);
506  if (bQuote)
507  sFinalList.append(sQuote);
508 
509  if (pItems != pLastElement)
510  sFinalList.append(sSeparator);
511  }
512 
513  if (!sFinalList.isEmpty())
514  AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sFinalList.makeStringAndClear());
515 
516  exportedProperty( _rPropertyName );
517  }
518 
519  OUString OPropertyExport::implConvertAny(const Any& _rValue)
520  {
521  OUStringBuffer aBuffer;
522  switch (_rValue.getValueTypeClass())
523  {
524  case TypeClass_STRING:
525  { // extract the string
526  OUString sCurrentValue;
527  _rValue >>= sCurrentValue;
528  aBuffer.append(sCurrentValue);
529  }
530  break;
531  case TypeClass_DOUBLE:
532  // let the unit converter format is as string
533  ::sax::Converter::convertDouble(aBuffer, getDouble(_rValue));
534  break;
535  case TypeClass_BOOLEAN:
536  aBuffer = getBOOL(_rValue) ? m_sValueTrue : m_sValueFalse;
537  break;
538  case TypeClass_BYTE:
539  case TypeClass_UNSIGNED_SHORT:
540  case TypeClass_SHORT:
541  case TypeClass_LONG:
542  // let the unit converter format is as string
543  aBuffer.append(getINT32(_rValue));
544  break;
545  case TypeClass_UNSIGNED_LONG:
546  case TypeClass_HYPER:
547  aBuffer.append(getINT64(_rValue));
548  break;
549  case TypeClass_UNSIGNED_HYPER:
550  aBuffer.append(OUString::number(_rValue.get<sal_uInt64>()));
551  break;
552  case TypeClass_ENUM:
553  {
554  // convert it into an int32
555  sal_Int32 nValue = 0;
556  ::cppu::enum2int(nValue, _rValue);
557  aBuffer.append(nValue);
558  }
559  break;
560  default:
561  { // hmmm... what else do we know?
562  double fValue = 0;
563  css::util::Date aDate;
564  css::util::Time aTime;
565  css::util::DateTime aDateTime;
566  if (_rValue >>= aDate)
567  {
568  Date aToolsDate( Date::EMPTY );
569  ::utl::typeConvert(aDate, aToolsDate);
570  fValue = aToolsDate.GetDate();
571  }
572  else if (_rValue >>= aTime)
573  {
574  fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
575  aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
576  aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
577  aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
578  }
579  else if (_rValue >>= aDateTime)
580  {
581  DateTime aToolsDateTime( DateTime::EMPTY );
582  ::utl::typeConvert(aDateTime, aToolsDateTime);
583  // the time part (the digits behind the comma)
584  fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
585  aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
586  aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
587  aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
588  // plus the data part (the digits in front of the comma)
589  fValue += aToolsDateTime.GetDate();
590  }
591  else
592  {
593  // if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
594 
595  // no more options ...
596  OSL_FAIL("OPropertyExport::implConvertAny: unsupported value type!");
597  break;
598  }
599  // let the unit converter format is as string
600  ::sax::Converter::convertDouble(aBuffer, fValue);
601  }
602  break;
603  }
604 
605  return aBuffer.makeStringAndClear();
606  }
607 
609  {
610  // handle the type description
611  switch (_rType.getTypeClass())
612  {
613  case TypeClass_STRING:
614  return token::XML_STRING;
615  case TypeClass_DOUBLE:
616  case TypeClass_BYTE:
617  case TypeClass_SHORT:
618  case TypeClass_LONG:
619  case TypeClass_HYPER:
620  case TypeClass_ENUM:
621  return token::XML_FLOAT;
622  case TypeClass_BOOLEAN:
623  return token::XML_BOOLEAN;
624 
625  default:
626  return token::XML_FLOAT;
627  }
628  }
629 
630 #ifdef DBG_UTIL
631  void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, const char* _pName, const OUString& _rValue)
632  {
633  OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(OUString::createFromAscii(_pName)).isEmpty(),
634  "OPropertyExport::AddAttribute: already have such an attribute");
635 
636  m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue);
637  }
638 
639  void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue )
640  {
641  OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName( _rName ).isEmpty(),
642  "OPropertyExport::AddAttribute: already have such an attribute");
643 
644  m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue );
645  }
646 
647  void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue)
648  {
649  OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
650  "OPropertyExport::AddAttribute: already have such an attribute");
651 
652  m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue);
653  }
654 
656  {
657  OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
658  "OPropertyExport::AddAttribute: already have such an attribute");
659 
660  m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue);
661  }
662 
663  void OPropertyExport::dbg_implCheckProperty(const OUString& _rPropertyName, const Type* _pType)
664  {
665  try
666  {
667  // the property must exist
668  if (!m_xPropertyInfo->hasPropertyByName(_rPropertyName))
669  {
670  SAL_WARN("xmloff.forms", "OPropertyExport: "
671  "no property with the name " + _rPropertyName + "!");
672  return;
673  }
674 
675  if (_pType)
676  {
677  // and it must have the correct type
678  Property aPropertyDescription = m_xPropertyInfo->getPropertyByName(_rPropertyName);
679  OSL_ENSURE(aPropertyDescription.Type.equals(*_pType), "OPropertyExport::dbg_implCheckProperty: invalid property type!");
680  }
681  }
682  catch(Exception&)
683  {
684  TOOLS_WARN_EXCEPTION("xmloff.forms", "could not check the property!");
685  }
686  }
687 #endif // DBG_UTIL - dbg_implCheckProperty
688 
689 } // namespace xmloff
690 
691 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type getSequenceElementType(const Type &_rSequenceType)
const css::uno::Reference< css::beans::XPropertySetInfo > m_xPropertyInfo
Type
static const sal_Int64 hourPerDay
void exportedProperty(const OUString &_rPropertyName)
indicates that a property has been handled by a derived class, without using the helper methods of th...
static sal_uInt16 getCommonControlAttributeNamespace(CCAFlags _nId)
calculates the xml namespace key to use for a common control attribute
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
#define PROPERTY_TIMEFORMAT
Definition: strings.hxx:115
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 exportEnumPropertyAttributeImpl(const sal_uInt16 _nNamespaceKey, const char *_pAttributeName, const OUString &_rPropertyName, const SvXMLEnumMapEntry< sal_uInt16 > *_pValueMap, const sal_uInt16 _nDefault, const bool _bVoidDefault)
sal_Int64 getINT64(const Any &_rAny)
static const char * getCommonControlAttributeName(CCAFlags _nId)
calculates the xml attribute representation of a common control attribute.
bool getBOOL(const Any &_rAny)
#define PROPERTY_FONT
Definition: strings.hxx:101
css::uno::Reference< css::xml::sax::XAttributeList > GetXAttrList()
Definition: xmlexp.hxx:381
constexpr sal_uInt16 XML_NAMESPACE_XLINK
static const sal_Int64 minutePerDay
void exportRemainingPropertiesSequence(css::uno::Any const &value, token::XMLTokenEnum eValueAttName)
const css::uno::Reference< css::beans::XPropertySet > m_xProps
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
sal_uInt16 sal_Unicode
PropertiesInfo aProperties
std::set< OUString > m_aRemainingProps
const Reference< XComponentContext > & m_rContext
#define DBG_CHECK_PROPERTY(name, type)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:909
constexpr sal_uInt16 XML_NAMESPACE_FORM
const char sQuote[]
IFormsExportContext & m_rContext
virtual ::rtl::Reference< SvXMLExportPropertyMapper > getStylePropertyMapper()=0
sal_Int32 GetDate() const
bool shouldExportProperty(const OUString &i_propertyName) const
determines whether the given property is to be exported
OUString AddEmbeddedXGraphic(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic, OUString &rOutMimeType, OUString const &rRequestedName=OUString())
Definition: xmlexp.cxx:1858
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 ...
#define TOOLS_WARN_EXCEPTION(area, stream)
#define PROPERTY_DATEFORMAT
Definition: strings.hxx:114
int i
virtual SvXMLExport & getGlobalContext()=0
::xmloff::token::XMLTokenEnum implGetPropertyXMLType(const css::uno::Type &_rType)
OUString AddEmbeddedObject(const OUString &rEmbeddedObjectURL)
Definition: xmlexp.cxx:1915
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 ...
static bool convertBool(bool &rBool, std::u16string_view rString)
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)
#define PROPERTY_TARGETFRAME
Definition: strings.hxx:33
#define DBG_CHECK_PROPERTY_NO_TYPE(name)
OUString implConvertAny(const css::uno::Any &_rValue)
tries to convert an arbitrary Any into an string ...
std::unique_ptr< char[]> aBuffer
void flagStyleProperties()
flag the style properties as 'already exported'
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3406
void exportTargetFrameAttribute()
add the hlink:target-frame attribute to the export context.
#define DBG_CHECK_PROPERTY_ASCII_NO_TYPE(name)
sal_Int32 getINT32(const Any &_rAny)
Reference< XPropertySet > m_xProps
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:138
double getDouble(const Any &_rAny)
static const sal_Int64 nanoSecPerDay
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 ...
#define SAL_WARN(area, stream)
void AddAttribute(sal_uInt16 _nPrefix, const char *_pName, const OUString &_rValue)
OUString getString(const Any &_rAny)
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 ...
Reference< XGraphic > xGraphic
OPropertyExport(IFormsExportContext &_rContext, const css::uno::Reference< css::beans::XPropertySet > &_rxProps)
constructs an object capable of handling attributes for export
sal_Int16 nValue
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)
static const sal_Int64 secondPerDay