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/xmlnmspe.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <xmloff/xmlexppr.hxx>
29 #include <xmloff/xmlprmap.hxx>
30 #include <sax/tools/converter.hxx>
31 #include <osl/diagnose.h>
32 #include <sal/log.hxx>
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
59  OPropertyExport::OPropertyExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxProps)
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  DBG_CHECK_PROPERTY( _sPropertyName, OUString );
390 
391  Any aAny = m_xProps->getPropertyValue(_sPropertyName);
392 
393  OUString sTargetLocation;
394  if (aAny.has<uno::Reference<graphic::XGraphic>>())
395  {
396  auto xGraphic = aAny.get<uno::Reference<graphic::XGraphic>>();
397  OUString sOutMimeType;
398  sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedXGraphic(xGraphic, sOutMimeType);
399  }
400  else if (aAny.has<OUString>())
401  {
402  auto sURL = aAny.get<OUString>();
403  sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedObject(sURL);
404  }
405 
406  if (!sTargetLocation.isEmpty())
407  {
410  , sTargetLocation);
411 
412  // #i110911# add xlink:type="simple" if required
413  if (_bAddType)
415 
416  exportedProperty(_sPropertyName);
417  }
418  }
420  {
421  // flag all the properties which are part of the style as "handled"
422  rtl::Reference< XMLPropertySetMapper > xStylePropertiesSupplier = m_rContext.getStylePropertyMapper()->getPropertySetMapper();
423  for (sal_Int32 i=0; i<xStylePropertiesSupplier->GetEntryCount(); ++i)
424  exportedProperty(xStylePropertiesSupplier->GetEntryAPIName(i));
425 
426  // the font properties are exported as single properties, but there is a FontDescriptor property which
427  // collects them all-in-one, this has been exported implicitly
429 
430  // for the DateFormat and TimeFormat, there exist wrapper properties which has been exported as
431  // style, too
434 
435  // the following properties should have been exported at the shape already:
436  exportedProperty( "VerticalAlign" );
437  exportedProperty( "WritingMode" );
438  exportedProperty( "ScaleMode" );
439  // ditto the TextWritingMode
440  exportedProperty( "WritingMode" );
441  }
442 
444  const sal_uInt16 _nAttributeNamespaceKey, const char* _pAttributeName, const char* _pPropertyName)
445  {
446  DBG_CHECK_PROPERTY_ASCII_NO_TYPE( _pPropertyName );
447 
448  OUString sPropertyName = OUString::createFromAscii(_pPropertyName);
449  exportedProperty(sPropertyName);
450 
451  Any aCurrentValue = m_xProps->getPropertyValue(sPropertyName);
452  if (!aCurrentValue.hasValue())
453  // nothing to do without a concrete value
454  return;
455 
456  OUString sValue = implConvertAny(aCurrentValue);
457  if (sValue.isEmpty() && (TypeClass_STRING == aCurrentValue.getValueTypeClass()))
458  {
459  // check whether or not the property is allowed to be VOID
460  Property aProperty = m_xPropertyInfo->getPropertyByName(sPropertyName);
461  if ((aProperty.Attributes & PropertyAttribute::MAYBEVOID) == 0)
462  // the string is empty, and the property is not allowed to be void
463  // -> don't need to write the attribute, 'cause missing it is unambiguous
464  return;
465  }
466 
467  // finally add the attribute to the context
468  AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sValue);
469  }
470 
471  void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const char* _pAttributeName,
472  const OUString& _rPropertyName)
473  {
474  const sal_Unicode _aListSeparator = ',';
475  const sal_Unicode _aQuoteCharacter = '"';
476  DBG_CHECK_PROPERTY( _rPropertyName, Sequence< OUString > );
477 
478  Sequence< OUString > aItems;
479  m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
480 
481  OUStringBuffer sFinalList;
482 
483  // unfortunately the OUString can't append single sal_Unicode characters ...
484  const OUString sQuote(&_aQuoteCharacter, 1);
485  const OUString sSeparator(&_aListSeparator, 1);
486  const bool bQuote = !sQuote.isEmpty();
487 
488  // concatenate the string items
489  const OUString* pItems = aItems.getConstArray();
490  const OUString* pEnd = pItems + aItems.getLength();
491  const OUString* pLastElement = pEnd - 1;
492  for ( ;
493  pItems != pEnd;
494  ++pItems
495  )
496  {
497  OSL_ENSURE(-1 == pItems->indexOf(_aQuoteCharacter),
498  "OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
499 
500  if (bQuote)
501  sFinalList.append(sQuote);
502  sFinalList.append(*pItems);
503  if (bQuote)
504  sFinalList.append(sQuote);
505 
506  if (pItems != pLastElement)
507  sFinalList.append(sSeparator);
508  }
509 
510  if (!sFinalList.isEmpty())
511  AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sFinalList.makeStringAndClear());
512 
513  exportedProperty( _rPropertyName );
514  }
515 
516  OUString OPropertyExport::implConvertAny(const Any& _rValue)
517  {
518  OUStringBuffer aBuffer;
519  switch (_rValue.getValueTypeClass())
520  {
521  case TypeClass_STRING:
522  { // extract the string
523  OUString sCurrentValue;
524  _rValue >>= sCurrentValue;
525  aBuffer.append(sCurrentValue);
526  }
527  break;
528  case TypeClass_DOUBLE:
529  // let the unit converter format is as string
530  ::sax::Converter::convertDouble(aBuffer, getDouble(_rValue));
531  break;
532  case TypeClass_BOOLEAN:
533  aBuffer = getBOOL(_rValue) ? m_sValueTrue : m_sValueFalse;
534  break;
535  case TypeClass_BYTE:
536  case TypeClass_UNSIGNED_SHORT:
537  case TypeClass_SHORT:
538  case TypeClass_LONG:
539  // let the unit converter format is as string
540  aBuffer.append(getINT32(_rValue));
541  break;
542  case TypeClass_UNSIGNED_LONG:
543  case TypeClass_HYPER:
544  aBuffer.append(getINT64(_rValue));
545  break;
546  case TypeClass_UNSIGNED_HYPER:
547  aBuffer.append(OUString::number(_rValue.get<sal_uInt64>()));
548  break;
549  case TypeClass_ENUM:
550  {
551  // convert it into an int32
552  sal_Int32 nValue = 0;
553  ::cppu::enum2int(nValue, _rValue);
554  aBuffer.append(nValue);
555  }
556  break;
557  default:
558  { // hmmm... what else do we know?
559  double fValue = 0;
560  css::util::Date aDate;
561  css::util::Time aTime;
562  css::util::DateTime aDateTime;
563  if (_rValue >>= aDate)
564  {
565  Date aToolsDate( Date::EMPTY );
566  ::utl::typeConvert(aDate, aToolsDate);
567  fValue = aToolsDate.GetDate();
568  }
569  else if (_rValue >>= aTime)
570  {
571  fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
572  aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
573  aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
574  aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
575  }
576  else if (_rValue >>= aDateTime)
577  {
578  DateTime aToolsDateTime( DateTime::EMPTY );
579  ::utl::typeConvert(aDateTime, aToolsDateTime);
580  // the time part (the digits behind the comma)
581  fValue = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
582  aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
583  aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
584  aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
585  // plus the data part (the digits in front of the comma)
586  fValue += aToolsDateTime.GetDate();
587  }
588  else
589  {
590  // if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
591 
592  // no more options ...
593  OSL_FAIL("OPropertyExport::implConvertAny: unsupported value type!");
594  break;
595  }
596  // let the unit converter format is as string
597  ::sax::Converter::convertDouble(aBuffer, fValue);
598  }
599  break;
600  }
601 
602  return aBuffer.makeStringAndClear();
603  }
604 
606  {
607  // handle the type description
608  switch (_rType.getTypeClass())
609  {
610  case TypeClass_STRING:
611  return token::XML_STRING;
612  case TypeClass_DOUBLE:
613  case TypeClass_BYTE:
614  case TypeClass_SHORT:
615  case TypeClass_LONG:
616  case TypeClass_HYPER:
617  case TypeClass_ENUM:
618  return token::XML_FLOAT;
619  case TypeClass_BOOLEAN:
620  return token::XML_BOOLEAN;
621 
622  default:
623  return token::XML_FLOAT;
624  }
625  }
626 
627 #ifdef DBG_UTIL
628  void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, const char* _pName, const OUString& _rValue)
629  {
630  OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(OUString::createFromAscii(_pName)).isEmpty(),
631  "OPropertyExport::AddAttribute: already have such an attribute");
632 
633  m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue);
634  }
635 
636  void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix, const OUString& _rName, const OUString& _rValue )
637  {
638  OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName( _rName ).isEmpty(),
639  "OPropertyExport::AddAttribute: already have such an attribute");
640 
641  m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue );
642  }
643 
644  void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const OUString& _rValue)
645  {
646  OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
647  "OPropertyExport::AddAttribute: already have such an attribute");
648 
649  m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue);
650  }
651 
653  {
654  OSL_ENSURE(m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).isEmpty(),
655  "OPropertyExport::AddAttribute: already have such an attribute");
656 
657  m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue);
658  }
659 
660  void OPropertyExport::dbg_implCheckProperty(const OUString& _rPropertyName, const Type* _pType)
661  {
662  try
663  {
664  // the property must exist
665  if (!m_xPropertyInfo->hasPropertyByName(_rPropertyName))
666  {
667  SAL_WARN("xmloff.forms", "OPropertyExport: "
668  "no property with the name " + _rPropertyName + "!");
669  return;
670  }
671 
672  if (_pType)
673  {
674  // and it must have the correct type
675  Property aPropertyDescription = m_xPropertyInfo->getPropertyByName(_rPropertyName);
676  OSL_ENSURE(aPropertyDescription.Type.equals(*_pType), "OPropertyExport::dbg_implCheckProperty: invalid property type!");
677  }
678  }
679  catch(Exception&)
680  {
681  OSL_FAIL("OPropertyExport::dbg_implCheckProperty: caught an exception, could not check the property!");
682  }
683  }
684 #endif // DBG_UTIL - dbg_implCheckProperty
685 
686 } // namespace xmloff
687 
688 /* 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
#define PROPERTY_TIMEFORMAT
Definition: strings.hxx:115
static bool convertEnum(EnumT &rEnum, const OUString &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:128
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 ...
static bool convertBool(bool &rBool, const OUString &rString)
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:382
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
const Reference< XComponentContext > & m_rContext
#define DBG_CHECK_PROPERTY(name, type)
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:926
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:1863
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:47
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 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:1920
constexpr sal_uInt16 XML_NAMESPACE_FORM
Definition: xmlnmspe.hxx:44
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 ...
constexpr sal_uInt16 XML_NAMESPACE_XLINK
Definition: xmlnmspe.hxx:35
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:3366
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
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
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
Definition: xmlnmspe.hxx:29
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)
static const sal_Int64 secondPerDay