LibreOffice Module xmloff (master)  1
elementimport.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 "elementimport.hxx"
21 #include <xmloff/xmlimp.hxx>
22 #include <xmloff/namespacemap.hxx>
23 #include "strings.hxx"
24 #include "callbacks.hxx"
25 #include "attriblistmerge.hxx"
26 #include <xmloff/xmlnamespace.hxx>
27 #include "eventimport.hxx"
28 #include <xmloff/txtstyli.hxx>
29 #include "formenums.hxx"
30 #include <xmloff/xmltoken.hxx>
32 #include "property_description.hxx"
33 #include "property_meta_data.hxx"
34 
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <com/sun/star/text/XText.hpp>
37 #include <com/sun/star/util/XCloneable.hpp>
38 #include <com/sun/star/util/Duration.hpp>
39 #include <com/sun/star/form/FormComponentType.hpp>
40 #include <com/sun/star/awt/ImagePosition.hpp>
41 #include <com/sun/star/beans/XMultiPropertySet.hpp>
42 #include <com/sun/star/beans/XPropertyContainer.hpp>
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 
45 #include <sax/tools/converter.hxx>
46 #include <tools/urlobj.hxx>
47 #include <tools/diagnose_ex.h>
48 #include <rtl/strbuf.hxx>
49 #include <sal/log.hxx>
50 #include <comphelper/extract.hxx>
51 #include <comphelper/types.hxx>
52 #include <comphelper/sequence.hxx>
53 
54 #include <algorithm>
55 
56 namespace xmloff
57 {
58 
59  using namespace ::xmloff::token;
60  using namespace ::com::sun::star;
61  using namespace ::com::sun::star::uno;
62  using namespace ::com::sun::star::awt;
63  using namespace ::com::sun::star::container;
64  using namespace ::com::sun::star::beans;
65  using namespace ::com::sun::star::script;
66  using namespace ::com::sun::star::lang;
67  using namespace ::com::sun::star::form;
68  using namespace ::com::sun::star::xml;
69  using namespace ::com::sun::star::util;
70  using namespace ::com::sun::star::text;
71  using namespace ::comphelper;
72  using ::com::sun::star::xml::sax::XAttributeList;
73 
74 #define PROPID_VALUE 1
75 #define PROPID_CURRENT_VALUE 2
76 #define PROPID_MIN_VALUE 3
77 #define PROPID_MAX_VALUE 4
78 
79  namespace {
80 
81  struct PropertyValueLess
82  {
83  bool operator()(const PropertyValue& _rLeft, const PropertyValue& _rRight)
84  {
85  return _rLeft.Name < _rRight.Name;
86  }
87  };
88 
89  }
90 
91  //= OElementNameMap
93 
95  {
97  sal_Int32 nAsInt = static_cast<sal_Int32>(e);
98  _e = static_cast<OControlElement::ElementType>( ++nAsInt );
99  return _e;
100  }
101 
103  {
104  if ( s_sElementTranslations.empty() )
105  { // initialize
107  s_sElementTranslations[OUString::createFromAscii(getElementName(eType))] = eType;
108  }
109  MapString2Element::const_iterator aPos = s_sElementTranslations.find(_rName);
110  if (s_sElementTranslations.end() != aPos)
111  return aPos->second;
112 
113  return UNKNOWN;
114  }
115 
116  //= OElementImport
117  OElementImport::OElementImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
118  const Reference< XNameContainer >& _rxParentContainer)
119  :OPropertyImport(_rImport, _nPrefix, _rName)
120  ,m_rFormImport(_rImport)
121  ,m_rEventManager(_rEventManager)
122  ,m_pStyleElement( nullptr )
123  ,m_xParentContainer(_rxParentContainer)
124  ,m_bImplicitGenericAttributeHandling( true )
125  {
126  OSL_ENSURE(m_xParentContainer.is(), "OElementImport::OElementImport: invalid parent container!");
127  }
128 
130  {
131  }
132 
134  {
135  return OUString();
136  }
137 
138  void OElementImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
139  {
140  ENTER_LOG_CONTEXT( "xmloff::OElementImport - importing one element" );
141 
143  const OUString sImplNameAttribute = rMap.GetQNameByKey( XML_NAMESPACE_FORM, GetXMLToken( XML_CONTROL_IMPLEMENTATION ) );
144  const OUString sControlImplementation = _rxAttrList->getValueByName( sImplNameAttribute );
145 
146  // retrieve the service name
147  if ( !sControlImplementation.isEmpty() )
148  {
149  OUString sOOoImplementationName;
150  const sal_uInt16 nImplPrefix = GetImport().GetNamespaceMap().GetKeyByAttrValueQName( sControlImplementation, &sOOoImplementationName );
151  m_sServiceName = ( nImplPrefix == XML_NAMESPACE_OOO ) ? sOOoImplementationName : sControlImplementation;
152  }
153 
154  if ( m_sServiceName.isEmpty() )
156 
157  // create the object *now*. This allows setting properties in the various handleAttribute methods.
158  // (Though currently not all code is migrated to this pattern, most attributes are still handled
159  // by remembering the value (via implPushBackPropertyValue), and setting the correct property value
160  // later (in OControlImport::StartElement).)
162  if ( m_xElement.is() )
163  m_xInfo = m_xElement->getPropertySetInfo();
164 
165  // call the base class
166  OPropertyImport::StartElement( _rxAttrList );
167  }
168 
169  SvXMLImportContextRef OElementImport::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
170  const Reference< XAttributeList >& _rxAttrList)
171  {
172  if( token::IsXMLToken(_rLocalName, token::XML_EVENT_LISTENERS) && (XML_NAMESPACE_OFFICE == _nPrefix))
173  return new OFormEventsImportContext(m_rFormImport.getGlobalContext(), _nPrefix, _rLocalName, *this);
174 
175  return OPropertyImport::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
176  }
177 
179  {
180  OSL_ENSURE(m_xElement.is(), "OElementImport::EndElement: invalid element created!");
181  if (!m_xElement.is())
182  return;
183 
184  // apply the non-generic properties
186 
187  // set the generic properties
189 
190  // set the style properties
191  if ( m_pStyleElement && m_xElement.is() )
192  {
193  Reference< XPropertySet > xPropTranslation =
194  new OGridColumnPropertyTranslator( Reference< XMultiPropertySet >( m_xElement, UNO_QUERY ) );
195  const_cast< XMLTextStyleContext* >( m_pStyleElement )->FillPropertySet( xPropTranslation );
196 
197  const OUString sNumberStyleName = m_pStyleElement->GetDataStyleName( );
198  if ( !sNumberStyleName.isEmpty() )
199  // the style also has a number (sub) style
200  m_rContext.applyControlNumberStyle( m_xElement, sNumberStyleName );
201  }
202 
203  // insert the element into the parent container
204  if (m_sName.isEmpty())
205  {
206  OSL_FAIL("OElementImport::EndElement: did not find a name attribute!");
208  }
209 
210  if (m_xParentContainer.is())
211  m_xParentContainer->insertByName(m_sName, makeAny(m_xElement));
212 
214  }
215 
217  {
218  if ( m_aValues.empty() )
219  return;
220 
221  // set all the properties we collected
222 #if OSL_DEBUG_LEVEL > 0
223  // check if the object has all the properties
224  // (We do this in the non-pro version only. Doing it all the time would be too much expensive)
225  if ( m_xInfo.is() )
226  {
227  for ( const auto& rCheck : m_aValues )
228  {
229  OSL_ENSURE(m_xInfo->hasPropertyByName(rCheck.Name),
230  OStringBuffer("OElementImport::implApplySpecificProperties: read a property (").
231  append(OUStringToOString(rCheck.Name, RTL_TEXTENCODING_ASCII_US)).
232  append(") which does not exist on the element!").getStr());
233  }
234  }
235 #endif
236 
237  // set the properties
238  const Reference< XMultiPropertySet > xMultiProps(m_xElement, UNO_QUERY);
239  bool bSuccess = false;
240  if (xMultiProps.is())
241  {
242  // translate our properties so that the XMultiPropertySet can handle them
243 
244  // sort our property value array so that we can use it in a setPropertyValues
245  ::std::sort( m_aValues.begin(), m_aValues.end(), PropertyValueLess());
246 
247  // the names
248  Sequence< OUString > aNames(m_aValues.size());
249  OUString* pNames = aNames.getArray();
250  // the values
251  Sequence< Any > aValues(m_aValues.size());
252  Any* pValues = aValues.getArray();
253  // copy
254 
255  for ( const auto& rPropValues : m_aValues )
256  {
257  *pNames = rPropValues.Name;
258  *pValues = rPropValues.Value;
259  ++pNames;
260  ++pValues;
261  }
262 
263  try
264  {
265  xMultiProps->setPropertyValues(aNames, aValues);
266  bSuccess = true;
267  }
268  catch(const Exception&)
269  {
270  DBG_UNHANDLED_EXCEPTION("xmloff.forms");
271  OSL_FAIL("OElementImport::implApplySpecificProperties: could not set the properties (using the XMultiPropertySet)!");
272  }
273  }
274 
275  if (bSuccess)
276  return;
277 
278  // no XMultiPropertySet or setting all properties at once failed
279  for ( const auto& rPropValues : m_aValues )
280  {
281  // this try/catch here is expensive, but because this is just a fallback which should normally not be
282  // used it's acceptable this way ...
283  try
284  {
285  m_xElement->setPropertyValue(rPropValues.Name, rPropValues.Value);
286  }
287  catch(const Exception&)
288  {
289  DBG_UNHANDLED_EXCEPTION("xmloff.forms");
290  OSL_FAIL(OStringBuffer("OElementImport::implApplySpecificProperties: could not set the property \"").
291  append(OUStringToOString(rPropValues.Name, RTL_TEXTENCODING_ASCII_US)).
292  append("\"!").getStr());
293  }
294  }
295  }
296 
298  {
299  if ( m_aGenericValues.empty() )
300  return;
301 
302  Reference< XPropertyContainer > xDynamicProperties( m_xElement, UNO_QUERY );
303 
304  // PropertyValueArray::iterator aEnd = m_aGenericValues.end();
305  for ( auto& rPropValues : m_aGenericValues )
306  {
307  // check property type for numeric types before setting
308  // the property
309  try
310  {
311  // if such a property does not yet exist at the element, create it if necessary
312  const bool bExistentProperty = m_xInfo->hasPropertyByName( rPropValues.Name );
313  if ( !bExistentProperty )
314  {
315  if ( !xDynamicProperties.is() )
316  {
317  SAL_WARN( "xmloff", "OElementImport::implApplyGenericProperties: encountered an unknown property ("
318  << rPropValues.Name << "), but component is no PropertyBag!");
319  continue;
320  }
321 
322  xDynamicProperties->addProperty(
323  rPropValues.Name,
324  PropertyAttribute::BOUND | PropertyAttribute::REMOVABLE,
325  rPropValues.Value
326  );
327 
328  // re-fetch the PropertySetInfo
329  m_xInfo = m_xElement->getPropertySetInfo();
330  }
331 
332  // determine the type of the value (source for the following conversion)
333  TypeClass eValueTypeClass = rPropValues.Value.getValueTypeClass();
334  const bool bValueIsSequence = TypeClass_SEQUENCE == eValueTypeClass;
335  if ( bValueIsSequence )
336  {
337  uno::Type aSimpleType( getSequenceElementType( rPropValues.Value.getValueType() ) );
338  eValueTypeClass = aSimpleType.getTypeClass();
339  }
340 
341  // determine the type of the property (target for the following conversion)
342  const Property aProperty( m_xInfo->getPropertyByName( rPropValues.Name ) );
343  TypeClass ePropTypeClass = aProperty.Type.getTypeClass();
344  const bool bPropIsSequence = TypeClass_SEQUENCE == ePropTypeClass;
345  if( bPropIsSequence )
346  {
347  uno::Type aSimpleType( ::comphelper::getSequenceElementType( aProperty.Type ) );
348  ePropTypeClass = aSimpleType.getTypeClass();
349  }
350 
351  if ( bPropIsSequence != bValueIsSequence )
352  {
353  OSL_FAIL( "OElementImport::implImportGenericProperties: either both value and property should be a sequence, or none of them!" );
354  continue;
355  }
356 
357  if ( bValueIsSequence )
358  {
359  OSL_ENSURE( eValueTypeClass == TypeClass_ANY,
360  "OElementImport::implApplyGenericProperties: only ANYs should have been imported as generic list property!" );
361  // (OPropertyImport should produce only Sequencer< Any >, since it cannot know the real type
362 
363  OSL_ENSURE( ePropTypeClass == TypeClass_SHORT,
364  "OElementImport::implApplyGenericProperties: conversion to sequences other than 'sequence< short >' not implemented, yet!" );
365 
366  Sequence< Any > aXMLValueList;
367  rPropValues.Value >>= aXMLValueList;
368  Sequence< sal_Int16 > aPropertyValueList( aXMLValueList.getLength() );
369 
370  std::transform(aXMLValueList.begin(), aXMLValueList.end(), aPropertyValueList.begin(),
371  [](const Any& rXMLValue) -> sal_Int16 {
372  // only value sequences of numeric types implemented so far.
373  double nVal( 0 );
374  OSL_VERIFY( rXMLValue >>= nVal );
375  return static_cast< sal_Int16 >( nVal );
376  });
377 
378  rPropValues.Value <<= aPropertyValueList;
379  }
380  else if ( ePropTypeClass != eValueTypeClass )
381  {
382  switch ( eValueTypeClass )
383  {
384  case TypeClass_DOUBLE:
385  {
386  double nVal = 0;
387  rPropValues.Value >>= nVal;
388  switch( ePropTypeClass )
389  {
390  case TypeClass_BYTE:
391  rPropValues.Value <<= static_cast< sal_Int8 >( nVal );
392  break;
393  case TypeClass_SHORT:
394  rPropValues.Value <<= static_cast< sal_Int16 >( nVal );
395  break;
396  case TypeClass_UNSIGNED_SHORT:
397  rPropValues.Value <<= static_cast< sal_uInt16 >( nVal );
398  break;
399  case TypeClass_LONG:
400  case TypeClass_ENUM:
401  rPropValues.Value <<= static_cast< sal_Int32 >( nVal );
402  break;
403  case TypeClass_UNSIGNED_LONG:
404  rPropValues.Value <<= static_cast< sal_uInt32 >( nVal );
405  break;
406  case TypeClass_UNSIGNED_HYPER:
407  rPropValues.Value <<= static_cast< sal_uInt64 >( nVal );
408  break;
409  case TypeClass_HYPER:
410  rPropValues.Value <<= static_cast< sal_Int64 >( nVal );
411  break;
412  default:
413  OSL_FAIL( "OElementImport::implImportGenericProperties: unsupported value type!" );
414  break;
415  }
416  }
417  break;
418  default:
419  OSL_FAIL( "OElementImport::implImportGenericProperties: non-double values not supported!" );
420  break;
421  }
422  }
423 
424  m_xElement->setPropertyValue( rPropValues.Name, rPropValues.Value );
425  }
426  catch(const Exception&)
427  {
428  DBG_UNHANDLED_EXCEPTION("xmloff.forms");
429  OSL_FAIL(OStringBuffer("OElementImport::EndElement: could not set the property \"").
430  append(OUStringToOString(rPropValues.Name, RTL_TEXTENCODING_ASCII_US)).
431  append("\"!").getStr());
432  }
433  }
434  }
435 
437  {
438  // no optimization here. If this method gets called, the XML stream did not contain a name for the
439  // element, which is a heavy error. So in this case we don't care for performance
440  static const char sUnnamedName[] = "unnamed";
441  OSL_ENSURE(m_xParentContainer.is(), "OElementImport::implGetDefaultName: no parent container!");
442  if (!m_xParentContainer.is())
443  return sUnnamedName;
444  Sequence< OUString > aNames = m_xParentContainer->getElementNames();
445 
446  for (sal_Int32 i=0; i<32768; ++i) // the limit is nearly arbitrary...
447  {
448  // assemble the new name (suggestion)
449  OUString sReturn = sUnnamedName + OUString::number(i);
450  // check the existence (this is the bad performance part...)
451  if (comphelper::findValue(aNames, sReturn) == -1)
452  // not found the name
453  return sReturn;
454  }
455  OSL_FAIL("OElementImport::implGetDefaultName: did not find a free name!");
456  return sUnnamedName;
457  }
458 
459  PropertyGroups::const_iterator OElementImport::impl_matchPropertyGroup( const PropertyGroups& i_propertyGroups ) const
460  {
461  ENSURE_OR_RETURN( m_xInfo.is(), "OElementImport::impl_matchPropertyGroup: no property set info!", i_propertyGroups.end() );
462 
463  return std::find_if(i_propertyGroups.cbegin(), i_propertyGroups.cend(), [&](const PropertyDescriptionList& rGroup) {
464  return std::all_of(rGroup.cbegin(), rGroup.cend(), [&](const PropertyDescription* prop) {
465  return m_xInfo->hasPropertyByName( prop->propertyName );
466  });
467  });
468  }
469 
470  bool OElementImport::tryGenericAttribute( sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue )
471  {
472  // the generic approach (which I hope all props will be migrated to, on the medium term): property handlers
473  const AttributeDescription attribute( metadata::getAttributeDescription( _nNamespaceKey, _rLocalName ) );
474  if ( attribute.attributeToken != XML_TOKEN_INVALID )
475  {
476  PropertyGroups propertyGroups;
477  metadata::getPropertyGroupList( attribute, propertyGroups );
478  const PropertyGroups::const_iterator pos = impl_matchPropertyGroup( propertyGroups );
479  if ( pos == propertyGroups.end() )
480  return false;
481 
482  do
483  {
484  const PropertyDescriptionList& rProperties( *pos );
485  const PropertyDescription* first = *rProperties.begin();
486  if ( !first )
487  {
488  SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property description!" );
489  break;
490  }
491 
492  const PPropertyHandler handler = (*first->factory)( first->propertyId );
493  if ( !handler )
494  {
495  SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property handler!" );
496  break;
497  }
498 
499  PropertyValues aValues;
500  for ( const auto& propDesc : rProperties )
501  {
502  aValues[ propDesc->propertyId ] = Any();
503  }
504  if ( handler->getPropertyValues( _rValue, aValues ) )
505  {
506  for ( const auto& propDesc : rProperties )
507  {
508  implPushBackPropertyValue( propDesc->propertyName, aValues[ propDesc->propertyId ] );
509  }
510  }
511  }
512  while ( false );
513 
514  // handled
515  return true;
516  }
517  return false;
518  }
519 
520  bool OElementImport::handleAttribute(sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue)
521  {
523  // ignore this, it has already been handled in OElementImport::StartElement
524  return true;
525 
526  if ( token::IsXMLToken( _rLocalName, token::XML_NAME ) )
527  {
528  if ( m_sName.isEmpty() )
529  // remember the name for later use in EndElement
530  m_sName = _rValue;
531  return true;
532  }
533 
534  // maybe it's the style attribute?
535  if ( token::IsXMLToken( _rLocalName, token::XML_TEXT_STYLE_NAME ) )
536  {
537  const SvXMLStyleContext* pStyleContext = m_rContext.getStyleElement( _rValue );
538  OSL_ENSURE( pStyleContext, "OElementImport::handleAttribute: do not know the style!" );
539  // remember the element for later usage.
540  m_pStyleElement = dynamic_cast<const XMLTextStyleContext*>( pStyleContext );
541  return true;
542  }
543 
545  if ( tryGenericAttribute( _nNamespaceKey, _rLocalName, _rValue ) )
546  return true;
547 
548  // let the base class handle it
549  return OPropertyImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
550  }
551 
553  {
555  if (!m_sServiceName.isEmpty())
556  {
558  Reference< XInterface > xPure = xContext->getServiceManager()->createInstanceWithContext(m_sServiceName, xContext);
559  OSL_ENSURE(xPure.is(),
560  OStringBuffer("OElementImport::createElement: service factory gave me no object (service name: ").append(OUStringToOString(m_sServiceName, RTL_TEXTENCODING_ASCII_US)).append(")!").getStr());
561  xReturn.set(xPure, UNO_QUERY);
562  }
563  else
564  OSL_FAIL("OElementImport::createElement: no service name to create an element!");
565 
566  return xReturn;
567  }
568 
569  void OElementImport::registerEvents(const Sequence< ScriptEventDescriptor >& _rEvents)
570  {
571  OSL_ENSURE(m_xElement.is(), "OElementImport::registerEvents: no element to register events for!");
573  }
574 
575  void OElementImport::simulateDefaultedAttribute(const char* _pAttributeName, const OUString& _rPropertyName, const char* _pAttributeDefault)
576  {
577  OSL_ENSURE( m_xInfo.is(), "OPropertyImport::simulateDefaultedAttribute: the component should be more gossipy about it's properties!" );
578 
579  if ( !m_xInfo.is() || m_xInfo->hasPropertyByName( _rPropertyName ) )
580  {
581  OUString sLocalAttrName = OUString::createFromAscii(_pAttributeName);
582  if ( !encounteredAttribute( sLocalAttrName ) )
583  OSL_VERIFY( handleAttribute( XML_NAMESPACE_FORM, sLocalAttrName, OUString::createFromAscii( _pAttributeDefault ) ) );
584  }
585  }
586 
587  //= OControlImport
588  OControlImport::OControlImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
589  const Reference< XNameContainer >& _rxParentContainer)
590  :OElementImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
591  ,m_eElementType(OControlElement::UNKNOWN)
592  {
594  }
595 
596  OControlImport::OControlImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
597  const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType)
598  :OElementImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
599  ,m_eElementType(_eType)
600  {
602  }
603 
605  {
606  const char* pServiceName = nullptr;
607  switch ( m_eElementType )
608  {
611  case OControlElement::PASSWORD: pServiceName = "com.sun.star.form.component.TextField"; break;
612  case OControlElement::FILE: pServiceName = "com.sun.star.form.component.FileControl"; break;
613  case OControlElement::FORMATTED_TEXT: pServiceName = "com.sun.star.form.component.FormattedField"; break;
614  case OControlElement::FIXED_TEXT: pServiceName = "com.sun.star.form.component.FixedText"; break;
615  case OControlElement::COMBOBOX: pServiceName = "com.sun.star.form.component.ComboBox"; break;
616  case OControlElement::LISTBOX: pServiceName = "com.sun.star.form.component.ListBox"; break;
617  case OControlElement::BUTTON: pServiceName = "com.sun.star.form.component.CommandButton"; break;
618  case OControlElement::IMAGE: pServiceName = "com.sun.star.form.component.ImageButton"; break;
619  case OControlElement::CHECKBOX: pServiceName = "com.sun.star.form.component.CheckBox"; break;
620  case OControlElement::RADIO: pServiceName = "com.sun.star.form.component.RadioButton"; break;
621  case OControlElement::FRAME: pServiceName = "com.sun.star.form.component.GroupBox"; break;
622  case OControlElement::IMAGE_FRAME: pServiceName = "com.sun.star.form.component.DatabaseImageControl"; break;
623  case OControlElement::HIDDEN: pServiceName = "com.sun.star.form.component.HiddenControl"; break;
624  case OControlElement::GRID: pServiceName = "com.sun.star.form.component.GridControl"; break;
625  case OControlElement::VALUERANGE: pServiceName = "com.sun.star.form.component.ScrollBar"; break;
626  case OControlElement::TIME: pServiceName = "com.sun.star.form.component.TimeField"; break;
627  case OControlElement::DATE: pServiceName = "com.sun.star.form.component.DateField"; break;
628  default: break;
629  }
630  if ( pServiceName != nullptr )
631  return OUString::createFromAscii( pServiceName );
632  return OUString();
633  }
634 
635  void OControlImport::addOuterAttributes(const Reference< XAttributeList >& _rxOuterAttribs)
636  {
637  OSL_ENSURE(!m_xOuterAttributes.is(), "OControlImport::addOuterAttributes: already have these attributes!");
638  m_xOuterAttributes = _rxOuterAttribs;
639  }
640 
641  bool OControlImport::handleAttribute(sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue)
642  {
643  static const char* pLinkedCellAttributeName = OAttributeMetaData::getBindingAttributeName(BAFlags::LinkedCell);
644 
645  if (IsXMLToken(_rLocalName, XML_ID))
646  { // it's the control id
647  if (XML_NAMESPACE_XML == _nNamespaceKey)
648  {
649  m_sControlId = _rValue;
650  }
651  else if (XML_NAMESPACE_FORM == _nNamespaceKey)
652  {
653  if (m_sControlId.isEmpty())
654  {
655  m_sControlId = _rValue;
656  }
657  }
658  return true;
659  }
660 
661  if ( _rLocalName.equalsAscii( pLinkedCellAttributeName ) )
662  { // it's the address of a spreadsheet cell
663  m_sBoundCellAddress = _rValue;
664  return true;
665  }
666 
667  if ( _nNamespaceKey == XML_NAMESPACE_XFORMS && IsXMLToken( _rLocalName, XML_BIND ) )
668  {
669  m_sBindingID = _rValue;
670  return true;
671  }
672 
673  if ( _nNamespaceKey == XML_NAMESPACE_FORM && IsXMLToken( _rLocalName, XML_XFORMS_LIST_SOURCE ) )
674  {
675  m_sListBindingID = _rValue;
676  return true;
677  }
678 
679  if ( ( ( _nNamespaceKey == XML_NAMESPACE_FORM )
680  && IsXMLToken( _rLocalName, XML_XFORMS_SUBMISSION )
681  )
682  || ( ( _nNamespaceKey == XML_NAMESPACE_XFORMS )
683  && IsXMLToken( _rLocalName, XML_SUBMISSION )
684  )
685  )
686  {
687  m_sSubmissionID = _rValue;
688  return true;
689  }
690 
691  if ( OElementImport::tryGenericAttribute( _nNamespaceKey, _rLocalName, _rValue ) )
692  return true;
693 
694  static const char* pValueAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Value);
695  static const char* pCurrentValueAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCAFlags::CurrentValue);
696  static const char* pMinValueAttributeName = OAttributeMetaData::getSpecialAttributeName(SCAFlags::MinValue);
697  static const char* pMaxValueAttributeName = OAttributeMetaData::getSpecialAttributeName(SCAFlags::MaxValue);
698  static const char* pRepeatDelayAttributeName = OAttributeMetaData::getSpecialAttributeName( SCAFlags::RepeatDelay );
699 
700  sal_Int32 nHandle = -1;
701  if ( _rLocalName.equalsAscii( pValueAttributeName ) )
702  nHandle = PROPID_VALUE;
703  else if ( _rLocalName.equalsAscii( pCurrentValueAttributeName ) )
704  nHandle = PROPID_CURRENT_VALUE;
705  else if ( _rLocalName.equalsAscii( pMinValueAttributeName ) )
706  nHandle = PROPID_MIN_VALUE;
707  else if ( _rLocalName.equalsAscii( pMaxValueAttributeName ) )
708  nHandle = PROPID_MAX_VALUE;
709  if ( nHandle != -1 )
710  {
711  // for the moment, simply remember the name and the value
712  PropertyValue aProp;
713  aProp.Name = _rLocalName;
714  aProp.Handle = nHandle;
715  aProp.Value <<= _rValue;
716  m_aValueProperties.push_back(aProp);
717  return true;
718  }
719 
720  if ( _rLocalName.equalsAscii( pRepeatDelayAttributeName ) )
721  {
722  util::Duration aDuration;
723  if (::sax::Converter::convertDuration(aDuration, _rValue))
724  {
725  PropertyValue aProp;
726  aProp.Name = PROPERTY_REPEAT_DELAY;
727  sal_Int32 const nMS =
728  ((aDuration.Hours * 60 + aDuration.Minutes) * 60
729  + aDuration.Seconds) * 1000 + aDuration.NanoSeconds/1000000;
730  aProp.Value <<= nMS;
731 
733  }
734  return true;
735  }
736 
737  return OElementImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
738  }
739 
740  void OControlImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
741  {
742  css::uno::Reference< css::xml::sax::XAttributeList > xAttributes;
743  if( m_xOuterAttributes.is() )
744  {
745  // merge the attribute lists
746  OAttribListMerger* pMerger = new OAttribListMerger;
747  // our own one
748  pMerger->addList(_rxAttrList);
749  // and the ones of our enclosing element
750  pMerger->addList(m_xOuterAttributes);
751  xAttributes = pMerger;
752  }
753  else
754  {
755  xAttributes = _rxAttrList;
756  }
757 
758  // let the base class handle all the attributes
759  OElementImport::StartElement(xAttributes);
760 
761  if ( m_aValueProperties.empty() || !m_xElement.is())
762  return;
763 
764  // get the property set info
765  if (!m_xInfo.is())
766  {
767  OSL_FAIL("OControlImport::StartElement: no PropertySetInfo!");
768  return;
769  }
770 
771  const char* pValueProperty = nullptr;
772  const char* pCurrentValueProperty = nullptr;
773  const char* pMinValueProperty = nullptr;
774  const char* pMaxValueProperty = nullptr;
775 
776  bool bRetrievedValues = false;
777  bool bRetrievedValueLimits = false;
778 
779  // get the class id of our element
780  sal_Int16 nClassId = FormComponentType::CONTROL;
781  m_xElement->getPropertyValue(PROPERTY_CLASSID) >>= nClassId;
782 
783  // translate the value properties we collected in handleAttributes
784  for ( auto& rValueProps : m_aValueProperties )
785  {
786  bool bSuccess = false;
787  switch (rValueProps.Handle)
788  {
789  case PROPID_VALUE:
791  {
792  // get the property names
793  if (!bRetrievedValues)
794  {
795  getValuePropertyNames(m_eElementType, nClassId, pCurrentValueProperty, pValueProperty);
796  if ( !pCurrentValueProperty && !pValueProperty )
797  {
798  SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value property names!" );
799  break;
800  }
801 
802  bRetrievedValues = true;
803  }
804  if ( PROPID_VALUE == rValueProps.Handle && !pValueProperty )
805  {
806  SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a value property!");
807  break;
808  }
809 
810  if ( PROPID_CURRENT_VALUE == rValueProps.Handle && !pCurrentValueProperty )
811  {
812  SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a current-value property!");
813  break;
814  }
815 
816  // transfer the name
817  if (PROPID_VALUE == rValueProps.Handle)
818  rValueProps.Name = OUString::createFromAscii(pValueProperty);
819  else
820  rValueProps.Name = OUString::createFromAscii(pCurrentValueProperty);
821  bSuccess = true;
822  }
823  break;
824  case PROPID_MIN_VALUE:
825  case PROPID_MAX_VALUE:
826  {
827  // get the property names
828  if (!bRetrievedValueLimits)
829  {
830  getValueLimitPropertyNames(nClassId, pMinValueProperty, pMaxValueProperty);
831  if ( !pMinValueProperty || !pMaxValueProperty )
832  {
833  SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value limit property names!" );
834  break;
835  }
836 
837  bRetrievedValueLimits = true;
838  }
839  OSL_ENSURE((PROPID_MIN_VALUE != rValueProps.Handle) || pMinValueProperty,
840  "OControlImport::StartElement: the control does not have a value property!");
841  OSL_ENSURE((PROPID_MAX_VALUE != rValueProps.Handle) || pMaxValueProperty,
842  "OControlImport::StartElement: the control does not have a current-value property!");
843 
844  // transfer the name
845  if (PROPID_MIN_VALUE == rValueProps.Handle)
846  rValueProps.Name = OUString::createFromAscii(pMinValueProperty);
847  else
848  rValueProps.Name = OUString::createFromAscii(pMaxValueProperty);
849  bSuccess = true;
850  }
851  break;
852  }
853 
854  if ( !bSuccess )
855  continue;
856 
857  // translate the value
858  implTranslateValueProperty(m_xInfo, rValueProps);
859  // add the property to the base class' array
860  implPushBackPropertyValue(rValueProps);
861  }
862 
863  }
864 
865  void OControlImport::implTranslateValueProperty(const Reference< XPropertySetInfo >& _rxPropInfo,
866  PropertyValue& _rPropValue)
867  {
868  OSL_ENSURE(_rxPropInfo->hasPropertyByName(_rPropValue.Name),
869  "OControlImport::implTranslateValueProperty: invalid property name!");
870 
871  // retrieve the type of the property
872  Property aProp = _rxPropInfo->getPropertyByName(_rPropValue.Name);
873  // the untranslated string value as read in handleAttribute
874  OUString sValue;
875  bool bSuccess = _rPropValue.Value >>= sValue;
876  OSL_ENSURE(bSuccess, "OControlImport::implTranslateValueProperty: supposed to be called with non-translated string values!");
877 
878  if (TypeClass_ANY == aProp.Type.getTypeClass())
879  {
880  // we have exactly 2 properties where this type class is allowed:
881  SAL_WARN_IF(
882  _rPropValue.Name == PROPERTY_EFFECTIVE_VALUE
883  || _rPropValue.Name == PROPERTY_EFFECTIVE_DEFAULT, "xmloff",
884  "OControlImport::implTranslateValueProperty: invalid property type/name combination, Any and " << _rPropValue.Name);
885 
886  // Both properties are allowed to have a double or a string value,
887  // so first try to convert the string into a number
888  double nValue;
889  if (::sax::Converter::convertDouble(nValue, sValue))
890  _rPropValue.Value <<= nValue;
891  else
892  _rPropValue.Value <<= sValue;
893  }
894  else
895  _rPropValue.Value = PropertyConversion::convertString(aProp.Type, sValue);
896  }
897 
899  {
900  OSL_ENSURE(m_xElement.is(), "OControlImport::EndElement: invalid control!");
901  if ( !m_xElement.is() )
902  return;
903 
904  // register our control with its id
905  if (!m_sControlId.isEmpty())
907  // it's allowed to have no control id. In this case we're importing a column
908 
909  // one more pre-work to do:
910  // when we set default values, then by definition the respective value is set
911  // to this default value, too. This means if the sequence contains for example
912  // a DefaultText value, then the Text will be affected by this, too.
913  // In case the Text is not part of the property sequence (or occurs _before_
914  // the DefaultText, which can happen for other value/default-value property names),
915  // this means that the Text (the value property) is incorrectly imported.
916 
917  bool bRestoreValuePropertyValue = false;
918  Any aValuePropertyValue;
919 
920  sal_Int16 nClassId = FormComponentType::CONTROL;
921  try
922  {
923  // get the class id of our element
924  m_xElement->getPropertyValue(PROPERTY_CLASSID) >>= nClassId;
925  }
926  catch( const Exception& )
927  {
928  TOOLS_WARN_EXCEPTION("xmloff.forms",
929  "caught an exception while retrieving the class id!");
930  }
931 
932  const char* pValueProperty = nullptr;
933  const char* pDefaultValueProperty = nullptr;
934  getRuntimeValuePropertyNames(m_eElementType, nClassId, pValueProperty, pDefaultValueProperty);
935  if ( pDefaultValueProperty && pValueProperty )
936  {
937  bool bNonDefaultValuePropertyValue = false;
938  // is the "value property" part of the sequence?
939 
940  // look up this property in our sequence
941  for ( const auto& rCheck : m_aValues )
942  {
943  if ( rCheck.Name.equalsAscii( pDefaultValueProperty ) )
944  bRestoreValuePropertyValue = true;
945  else if ( rCheck.Name.equalsAscii( pValueProperty ) )
946  {
947  bNonDefaultValuePropertyValue = true;
948  // we need to restore the value property we found here, nothing else
949  aValuePropertyValue = rCheck.Value;
950  }
951  }
952 
953  if ( bRestoreValuePropertyValue && !bNonDefaultValuePropertyValue )
954  {
955  // found it -> need to remember (and restore) the "value property value", which is not set explicitly
956  try
957  {
958  aValuePropertyValue = m_xElement->getPropertyValue( OUString::createFromAscii( pValueProperty ) );
959  }
960  catch( const Exception& )
961  {
963  "xmloff.forms",
964  "caught an exception while retrieving the current value property!");
965  }
966  }
967  }
968 
969  // let the base class set all the values
971 
972  // restore the "value property value", if necessary
973  if ( bRestoreValuePropertyValue && pValueProperty )
974  {
975  try
976  {
977  m_xElement->setPropertyValue( OUString::createFromAscii( pValueProperty ), aValuePropertyValue );
978  }
979  catch( const Exception& )
980  {
981  TOOLS_WARN_EXCEPTION("xmloff.forms",
982  "caught an exception while restoring the value property!");
983  }
984  }
985 
986  // the external cell binding, if applicable
987  if ( m_xElement.is() && !m_sBoundCellAddress.isEmpty() )
989 
990  // XForms binding, if applicable
991  if ( m_xElement.is() && !m_sBindingID.isEmpty() )
993 
994  // XForms list binding, if applicable
995  if ( m_xElement.is() && !m_sListBindingID.isEmpty() )
997 
998  // XForms submission, if applicable
999  if ( m_xElement.is() && !m_sSubmissionID.isEmpty() )
1001  }
1002 
1003  void OControlImport::doRegisterCellValueBinding( const OUString& _rBoundCellAddress )
1004  {
1005  OSL_PRECOND( m_xElement.is(), "OControlImport::doRegisterCellValueBinding: invalid element!" );
1006  OSL_PRECOND( !_rBoundCellAddress.isEmpty(),
1007  "OControlImport::doRegisterCellValueBinding: invalid address!" );
1008 
1009  m_rContext.registerCellValueBinding( m_xElement, _rBoundCellAddress );
1010  }
1011 
1012  void OControlImport::doRegisterXFormsValueBinding( const OUString& _rBindingID )
1013  {
1014  OSL_PRECOND( m_xElement.is(), "need element" );
1015  OSL_PRECOND( !_rBindingID.isEmpty(), "binding ID is not valid" );
1016 
1018  }
1019 
1020  void OControlImport::doRegisterXFormsListBinding( const OUString& _rBindingID )
1021  {
1022  OSL_PRECOND( m_xElement.is(), "need element" );
1023  OSL_PRECOND( !_rBindingID.isEmpty(), "binding ID is not valid" );
1024 
1026  }
1027 
1028  void OControlImport::doRegisterXFormsSubmission( const OUString& _rSubmissionID )
1029  {
1030  OSL_PRECOND( m_xElement.is(), "need element" );
1031  OSL_PRECOND( !_rSubmissionID.isEmpty(), "binding ID is not valid" );
1032 
1033  m_rContext.registerXFormsSubmission( m_xElement, _rSubmissionID );
1034  }
1035 
1037  {
1039  if ( xPropSet.is() )
1040  {
1041  m_xInfo = xPropSet->getPropertySetInfo();
1042  if ( m_xInfo.is() && m_xInfo->hasPropertyByName(PROPERTY_ALIGN) )
1043  {
1044  Any aValue;
1045  xPropSet->setPropertyValue(PROPERTY_ALIGN,aValue);
1046  }
1047  }
1048  return xPropSet;
1049  }
1050 
1051  //= OImagePositionImport
1053  sal_uInt16 _nPrefix, const OUString& _rName, const Reference< XNameContainer >& _rxParentContainer,
1055  :OControlImport( _rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType )
1056  ,m_nImagePosition( -1 )
1057  ,m_nImageAlign( 0 )
1058  ,m_bHaveImagePosition( false )
1059  {
1060  }
1061 
1062  bool OImagePositionImport::handleAttribute( sal_uInt16 _nNamespaceKey, const OUString& _rLocalName,
1063  const OUString& _rValue )
1064  {
1065  static const char* s_pImageDataAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCAFlags::ImageData);
1066 
1067  if (_rLocalName.equalsAscii(s_pImageDataAttributeName))
1068  {
1070  return true;
1071  }
1072  else if ( _rLocalName == GetXMLToken( XML_IMAGE_POSITION ) )
1073  {
1075  cppu::UnoType<decltype(m_nImagePosition)>::get(),
1076  _rValue, aImagePositionMap
1077  ) >>= m_nImagePosition );
1078  m_bHaveImagePosition = true;
1079  return true;
1080  }
1081  else if ( _rLocalName == GetXMLToken( XML_IMAGE_ALIGN ) )
1082  {
1084  cppu::UnoType<decltype(m_nImageAlign)>::get(),
1085  _rValue, aImageAlignMap
1086  ) >>= m_nImageAlign );
1087  return true;
1088  }
1089 
1090  return OControlImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
1091  }
1092 
1093  void OImagePositionImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
1094  {
1095  OControlImport::StartElement( _rxAttrList );
1096 
1097  if (m_xGraphic.is())
1098  {
1099  PropertyValue aGraphicProperty;
1100  aGraphicProperty.Name = PROPERTY_GRAPHIC;
1101  aGraphicProperty.Value <<= m_xGraphic;
1102  implPushBackPropertyValue(aGraphicProperty);
1103  }
1104  if ( !m_bHaveImagePosition )
1105  return;
1106 
1107  sal_Int16 nUnoImagePosition = ImagePosition::Centered;
1108  if ( m_nImagePosition >= 0 )
1109  {
1110  OSL_ENSURE( ( m_nImagePosition <= 3 ) && ( m_nImageAlign >= 0 ) && ( m_nImageAlign < 3 ),
1111  "OImagePositionImport::StartElement: unknown image align and/or position!" );
1112  nUnoImagePosition = m_nImagePosition * 3 + m_nImageAlign;
1113  }
1114 
1115  PropertyValue aImagePosition;
1116  aImagePosition.Name = PROPERTY_IMAGE_POSITION;
1117  aImagePosition.Value <<= nUnoImagePosition;
1118  implPushBackPropertyValue( aImagePosition );
1119  }
1120 
1121  //= OReferredControlImport
1123  OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1124  const Reference< XNameContainer >& _rxParentContainer )
1125  :OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
1126  {
1127  }
1128 
1129  void OReferredControlImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
1130  {
1131  OControlImport::StartElement(_rxAttrList);
1132 
1133  // the base class should have created the control, so we can register it
1134  if ( !m_sReferringControls.isEmpty() )
1136  }
1137 
1138  bool OReferredControlImport::handleAttribute(sal_uInt16 _nNamespaceKey, const OUString& _rLocalName,
1139  const OUString& _rValue)
1140  {
1141  static const char * s_sReferenceAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCAFlags::For);
1142  if (_rLocalName.equalsAscii(s_sReferenceAttributeName))
1143  {
1144  m_sReferringControls = _rValue;
1145  return true;
1146  }
1147  return OControlImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
1148  }
1149 
1150  //= OPasswordImport
1151  OPasswordImport::OPasswordImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1152  const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType)
1153  :OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1154  {
1155  }
1156 
1157  bool OPasswordImport::handleAttribute(sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue)
1158  {
1159  static const char * s_sEchoCharAttributeName = OAttributeMetaData::getSpecialAttributeName(SCAFlags::EchoChar);
1160  if (_rLocalName.equalsAscii(s_sEchoCharAttributeName))
1161  {
1162  // need a special handling for the EchoChar property
1163  PropertyValue aEchoChar;
1164  aEchoChar.Name = PROPERTY_ECHOCHAR;
1165  OSL_ENSURE(_rValue.getLength() == 1, "OPasswordImport::handleAttribute: invalid echo char attribute!");
1166  // we ourself should not have written values other than of length 1
1167  if (_rValue.getLength() >= 1)
1168  aEchoChar.Value <<= static_cast<sal_Int16>(_rValue[0]);
1169  else
1170  aEchoChar.Value <<= sal_Int16(0);
1171  implPushBackPropertyValue(aEchoChar);
1172  return true;
1173  }
1174  return OControlImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
1175  }
1176 
1177  //= ORadioImport
1178  ORadioImport::ORadioImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1179  const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType)
1180  :OImagePositionImport( _rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType )
1181  {
1182  }
1183 
1184  bool ORadioImport::handleAttribute(sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue)
1185  {
1186  // need special handling for the State & CurrentState properties:
1187  // they're stored as booleans, but expected to be int16 properties
1188  static const char* pCurrentSelectedAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCAFlags::CurrentSelected);
1189  static const char* pSelectedAttributeName = OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Selected);
1190  if ( _rLocalName.equalsAscii( pCurrentSelectedAttributeName )
1191  || _rLocalName.equalsAscii( pSelectedAttributeName )
1192  )
1193  {
1195  OSL_ENSURE(pProperty, "ORadioImport::handleAttribute: invalid property map!");
1196  if (pProperty)
1197  {
1198  const Any aBooleanValue( PropertyConversion::convertString(pProperty->aPropertyType, _rValue, pProperty->pEnumMap) );
1199 
1200  // create and store a new PropertyValue
1201  PropertyValue aNewValue;
1202  aNewValue.Name = pProperty->sPropertyName;
1203  aNewValue.Value <<= static_cast<sal_Int16>(::cppu::any2bool(aBooleanValue));
1204 
1205  implPushBackPropertyValue(aNewValue);
1206  }
1207  return true;
1208  }
1209  return OImagePositionImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
1210  }
1211 
1212  //= OURLReferenceImport
1213  OURLReferenceImport::OURLReferenceImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1214  const Reference< XNameContainer >& _rxParentContainer,
1216  :OImagePositionImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1217  {
1218  }
1219 
1220  bool OURLReferenceImport::handleAttribute(sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue)
1221  {
1222  static const char* s_pTargetLocationAttributeName = OAttributeMetaData::getCommonControlAttributeName( CCAFlags::TargetLocation );
1223  static const char* s_pImageDataAttributeName = OAttributeMetaData::getCommonControlAttributeName( CCAFlags::ImageData );
1224 
1225  // need to make the URL absolute if
1226  // * it's the image-data attribute
1227  // * it's the target-location attribute, and we're dealing with an object which has the respective property
1228  bool bMakeAbsolute =
1229  _rLocalName.equalsAscii( s_pImageDataAttributeName )
1230  || ( _rLocalName.equalsAscii( s_pTargetLocationAttributeName )
1233  )
1234  );
1235 
1236  if (bMakeAbsolute && !_rValue.isEmpty())
1237  {
1238  OUString sAdjustedValue = _rValue;
1239  if (!_rLocalName.equalsAscii(s_pImageDataAttributeName))
1240  sAdjustedValue = m_rContext.getGlobalContext().GetAbsoluteReference( _rValue );
1241  return OImagePositionImport::handleAttribute( _nNamespaceKey, _rLocalName, sAdjustedValue );
1242  }
1243 
1244  return OImagePositionImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
1245  }
1246 
1247  //= OButtonImport
1248  OButtonImport::OButtonImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1249  const Reference< XNameContainer >& _rxParentContainer,
1251  :OURLReferenceImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1252  {
1254  }
1255 
1256  void OButtonImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
1257  {
1258  OURLReferenceImport::StartElement(_rxAttrList);
1259 
1260  // handle the target-frame attribute
1262  }
1263 
1264  //= OValueRangeImport
1265  OValueRangeImport::OValueRangeImport( OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1266  const Reference< XNameContainer >& _rxParentContainer, OControlElement::ElementType _eType )
1267  :OControlImport( _rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType )
1268  ,m_nStepSizeValue( 1 )
1269  {
1270 
1271  }
1272 
1273  bool OValueRangeImport::handleAttribute( sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue )
1274  {
1275  if ( _rLocalName.equalsAscii( OAttributeMetaData::getSpecialAttributeName( SCAFlags::StepSize ) ) )
1276  {
1278  return true;
1279  }
1280  return OControlImport::handleAttribute( _nNamespaceKey, _rLocalName, _rValue );
1281  }
1282 
1283  void OValueRangeImport::StartElement( const Reference< XAttributeList >& _rxAttrList )
1284  {
1285  OControlImport::StartElement( _rxAttrList );
1286 
1287  if ( m_xInfo.is() )
1288  {
1289  if ( m_xInfo->hasPropertyByName( PROPERTY_SPIN_INCREMENT ) )
1291  else if ( m_xInfo->hasPropertyByName( PROPERTY_LINE_INCREMENT ) )
1293  }
1294  }
1295 
1296  //= OTextLikeImport
1297  OTextLikeImport::OTextLikeImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1298  const Reference< XNameContainer >& _rxParentContainer,
1300  :OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1301  ,m_bEncounteredTextPara( false )
1302  {
1304  }
1305 
1306  SvXMLImportContextRef OTextLikeImport::CreateChildContext( sal_uInt16 _nPrefix, const OUString& _rLocalName,
1307  const Reference< XAttributeList >& _rxAttrList )
1308  {
1309  if ( ( XML_NAMESPACE_TEXT == _nPrefix ) && _rLocalName.equalsIgnoreAsciiCase("p") )
1310  {
1312  "OTextLikeImport::CreateChildContext: text paragraphs in a non-text-area?" );
1313 
1315  {
1316  Reference< XText > xTextElement( m_xElement, UNO_QUERY );
1317  if ( xTextElement.is() )
1318  {
1320 
1321  if ( !m_xCursor.is() )
1322  {
1323  m_xOldCursor = xTextImportHelper->GetCursor();
1324  m_xCursor = xTextElement->createTextCursor();
1325 
1326  if ( m_xCursor.is() )
1327  xTextImportHelper->SetCursor( m_xCursor );
1328  }
1329  if ( m_xCursor.is() )
1330  {
1331  m_bEncounteredTextPara = true;
1332  return xTextImportHelper->CreateTextChildContext( m_rContext.getGlobalContext(), _nPrefix, _rLocalName, _rxAttrList );
1333  }
1334  }
1335  else
1336  {
1337  // in theory, we could accumulate all the text portions (without formatting),
1338  // and set it as Text property at the model ...
1339  }
1340  }
1341  }
1342 
1343  return OControlImport::CreateChildContext( _nPrefix, _rLocalName, _rxAttrList );
1344  }
1345 
1346  void OTextLikeImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
1347  {
1348  OControlImport::StartElement(_rxAttrList);
1349 
1350  // handle the convert-empty-to-null attribute, whose default is different from the property default
1351  // unfortunately, different classes are imported by this class ('cause they're represented by the
1352  // same XML element), though not all of them know this property.
1353  // So we have to do a check ...
1354  if (m_xElement.is() && m_xInfo.is() && m_xInfo->hasPropertyByName(PROPERTY_EMPTY_IS_NULL) )
1356  }
1357 
1358  namespace {
1359 
1360  struct EqualHandle
1361  {
1362  const sal_Int32 m_nHandle;
1363  explicit EqualHandle( sal_Int32 _nHandle ) : m_nHandle( _nHandle ) { }
1364 
1365  bool operator()( const PropertyValue& _rProp )
1366  {
1367  return _rProp.Handle == m_nHandle;
1368  }
1369  };
1370 
1371  }
1372 
1374  {
1375  if ( !m_bEncounteredTextPara )
1376  return;
1377 
1378  // In case the text is written in the text:p elements, we need to ignore what we read as
1379  // current-value attribute, since it's redundant.
1380  // fortunately, OElementImport tagged the value property with the PROPID_CURRENT_VALUE
1381  // handle, so we do not need to determine the name of our value property here
1382  // (normally, it should be "Text", since no other controls than the edit field should
1383  // have the text:p elements)
1384  PropertyValueArray::iterator aValuePropertyPos = ::std::find_if(
1385  m_aValues.begin(),
1386  m_aValues.end(),
1387  EqualHandle( PROPID_CURRENT_VALUE )
1388  );
1389  if ( aValuePropertyPos != m_aValues.end() )
1390  {
1391  OSL_ENSURE( aValuePropertyPos->Name == PROPERTY_TEXT, "OTextLikeImport::EndElement: text:p was present, but our value property is *not* 'Text'!" );
1392  if ( aValuePropertyPos->Name == PROPERTY_TEXT )
1393  {
1394  m_aValues.erase(aValuePropertyPos);
1395  }
1396  }
1397 
1398  // additionally, we need to set the "RichText" property of our element to sal_True
1399  // (the presence of the text:p is used as indicator for the value of the RichText property)
1400  bool bHasRichTextProperty = false;
1401  if ( m_xInfo.is() )
1402  bHasRichTextProperty = m_xInfo->hasPropertyByName( PROPERTY_RICH_TEXT );
1403  OSL_ENSURE( bHasRichTextProperty, "OTextLikeImport::EndElement: text:p, but no rich text control?" );
1404  if ( bHasRichTextProperty )
1405  m_xElement->setPropertyValue( PROPERTY_RICH_TEXT, makeAny( true ) );
1406  // Note that we do *not* set the RichText property (in case our element has one) to sal_False here
1407  // since this is the default of this property, anyway.
1408  }
1409 
1410  namespace {
1411 
1412  struct EqualName
1413  {
1414  const OUString & m_sName;
1415  explicit EqualName( const OUString& _rName ) : m_sName( _rName ) { }
1416 
1417  bool operator()( const PropertyValue& _rProp )
1418  {
1419  return _rProp.Name == m_sName;
1420  }
1421  };
1422 
1423  }
1424 
1426  {
1427  // In OpenOffice.org 2.0, we changed the implementation of the css.form.component.TextField (the model of a text field control),
1428  // so that it now uses another default control. So if we encounter a text field where the *old* default
1429  // control property is writing, we are not allowed to use it
1430  PropertyValueArray::iterator aDefaultControlPropertyPos = ::std::find_if(
1431  m_aValues.begin(),
1432  m_aValues.end(),
1433  EqualName( "DefaultControl" )
1434  );
1435  if ( aDefaultControlPropertyPos != m_aValues.end() )
1436  {
1437  OUString sDefaultControl;
1438  OSL_VERIFY( aDefaultControlPropertyPos->Value >>= sDefaultControl );
1439  if ( sDefaultControl == "stardiv.one.form.control.Edit" )
1440  {
1441  // complete remove this property value from the array. Today's "default value" of the "DefaultControl"
1442  // property is sufficient
1443  m_aValues.erase(aDefaultControlPropertyPos);
1444  }
1445  }
1446  }
1447 
1449  {
1452 
1453  // let the base class do the stuff
1455 
1456  // some cleanups
1458  if ( m_xCursor.is() )
1459  {
1460  // delete the newline which has been imported erroneously
1461  // TODO (fs): stole this code somewhere - why don't we fix the text import??
1462  m_xCursor->gotoEnd( false );
1463  m_xCursor->goLeft( 1, true );
1464  m_xCursor->setString( OUString() );
1465 
1466  // reset cursor
1467  xTextImportHelper->ResetCursor();
1468  }
1469 
1470  if ( m_xOldCursor.is() )
1471  xTextImportHelper->SetCursor( m_xOldCursor );
1472 
1473  }
1474 
1475  //= OListAndComboImport
1476  OListAndComboImport::OListAndComboImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1477  const Reference< XNameContainer >& _rxParentContainer,
1479  :OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
1480  ,m_nEmptyListItems( 0 )
1481  ,m_nEmptyValueItems( 0 )
1482  ,m_bEncounteredLSAttrib( false )
1483  ,m_bLinkWithIndexes( false )
1484  {
1487  }
1488 
1489  SvXMLImportContextRef OListAndComboImport::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
1490  const Reference< XAttributeList >& _rxAttrList)
1491  {
1492  // is it the "option" sub tag of a listbox ?
1493  if (_rLocalName == "option")
1494  return new OListOptionImport(GetImport(), _nPrefix, _rLocalName, this);
1495 
1496  // is it the "item" sub tag of a combobox ?
1497  if (_rLocalName == "item")
1498  return new OComboItemImport(GetImport(), _nPrefix, _rLocalName, this);
1499 
1500  // everything else
1501  return OControlImport::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
1502  }
1503 
1504  void OListAndComboImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
1505  {
1506  m_bLinkWithIndexes = false;
1507 
1508  OControlImport::StartElement(_rxAttrList);
1509 
1511  {
1512  // for the auto-completion
1513  // the attribute default does not equal the property default, so in case we did not read this attribute,
1514  // we have to simulate it
1516 
1517  // same for the convert-empty-to-null attribute, which's default is different from the property default
1519  }
1520  }
1521 
1523  {
1524  // append the list source property the properties sequence of our importer
1525  // the string item list
1526  PropertyValue aItemList;
1527  aItemList.Name = PROPERTY_STRING_ITEM_LIST;
1528  aItemList.Value <<= comphelper::containerToSequence(m_aListSource);
1529  implPushBackPropertyValue(aItemList);
1530 
1532  {
1533  OSL_ENSURE((m_aListSource.size() + m_nEmptyListItems) == (m_aValueList.size() + m_nEmptyValueItems),
1534  "OListAndComboImport::EndElement: inconsistence between labels and values!");
1535 
1536  if ( !m_bEncounteredLSAttrib )
1537  {
1538  // the value sequence
1539  PropertyValue aValueList;
1540  aValueList.Name = PROPERTY_LISTSOURCE;
1541  aValueList.Value <<= comphelper::containerToSequence(m_aValueList);
1542  implPushBackPropertyValue(aValueList);
1543  }
1544 
1545  // the select sequence
1546  PropertyValue aSelected;
1547  aSelected.Name = PROPERTY_SELECT_SEQ;
1548  aSelected.Value <<= comphelper::containerToSequence(m_aSelectedSeq);
1549  implPushBackPropertyValue(aSelected);
1550 
1551  // the default select sequence
1552  PropertyValue aDefaultSelected;
1553  aDefaultSelected.Name = PROPERTY_DEFAULT_SELECT_SEQ;
1554  aDefaultSelected.Value <<= comphelper::containerToSequence(m_aDefaultSelectedSeq);
1555  implPushBackPropertyValue(aDefaultSelected);
1556  }
1557 
1559 
1560  // the external list source, if applicable
1561  if ( m_xElement.is() && !m_sCellListSource.isEmpty() )
1563  }
1564 
1565  void OListAndComboImport::doRegisterCellValueBinding( const OUString& _rBoundCellAddress )
1566  {
1567  OUString sBoundCellAddress( _rBoundCellAddress );
1568  if ( m_bLinkWithIndexes )
1569  {
1570  // This is a HACK. We register a string which is no valid address, but allows
1571  // (somewhere else) to determine that a non-standard binding should be created.
1572  // This hack is acceptable for OOo 1.1.1, since the file format for value
1573  // bindings of form controls is to be changed afterwards, anyway.
1574  sBoundCellAddress += ":index";
1575  }
1576 
1577  OControlImport::doRegisterCellValueBinding( sBoundCellAddress );
1578  }
1579 
1580  bool OListAndComboImport::handleAttribute(sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue)
1581  {
1582  static const char* pListSourceAttributeName = OAttributeMetaData::getDatabaseAttributeName(DAFlags::ListSource);
1583  if ( _rLocalName.equalsAscii(pListSourceAttributeName) )
1584  {
1585  PropertyValue aListSource;
1586  aListSource.Name = PROPERTY_LISTSOURCE;
1587 
1588  // it's the ListSource attribute
1589  m_bEncounteredLSAttrib = true;
1591  {
1592  aListSource.Value <<= _rValue;
1593  }
1594  else
1595  {
1596  // a listbox which has a list-source attribute must have a list-source-type of something
1597  // not equal to ValueList.
1598  // In this case, the list-source value is simply the one and only element of the ListSource property.
1599  Sequence<OUString> aListSourcePropValue { _rValue };
1600  aListSource.Value <<= aListSourcePropValue;
1601  }
1602 
1603  implPushBackPropertyValue( aListSource );
1604  return true;
1605  }
1606 
1607  if ( _rLocalName.equalsAscii( OAttributeMetaData::getBindingAttributeName( BAFlags::ListCellRange ) ) )
1608  {
1609  m_sCellListSource = _rValue;
1610  return true;
1611  }
1612 
1613  if ( _rLocalName.equalsAscii( OAttributeMetaData::getBindingAttributeName( BAFlags::ListLinkingType ) ) )
1614  {
1615  sal_Int16 nLinkageType = 0;
1618  _rValue,
1620  ) >>= nLinkageType;
1621 
1622  m_bLinkWithIndexes = ( nLinkageType != 0 );
1623  return true;
1624  }
1625 
1626  return OControlImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
1627  }
1628 
1629  void OListAndComboImport::implPushBackLabel(const OUString& _rLabel)
1630  {
1631  OSL_ENSURE(!m_nEmptyListItems, "OListAndComboImport::implPushBackValue: label list is already done!");
1632  if (!m_nEmptyListItems)
1633  m_aListSource.push_back(_rLabel);
1634  }
1635 
1636  void OListAndComboImport::implPushBackValue(const OUString& _rValue)
1637  {
1638  OSL_ENSURE(!m_nEmptyValueItems, "OListAndComboImport::implPushBackValue: value list is already done!");
1639  if (!m_nEmptyValueItems)
1640  {
1641  OSL_ENSURE( !m_bEncounteredLSAttrib, "OListAndComboImport::implPushBackValue: invalid structure! Did you save this document with a version prior SRC641 m?" );
1642  // We already had the list-source attribute, which means that the ListSourceType is
1643  // not ValueList, which means that the ListSource should contain only one string in
1644  // the first element of the sequence
1645  // All other values in the file are invalid
1646 
1647  m_aValueList.push_back( _rValue );
1648  }
1649  }
1650 
1652  {
1654  }
1655 
1657  {
1659  }
1660 
1662  {
1663  OSL_ENSURE((m_aListSource.size() + m_nEmptyListItems) == (m_aValueList.size() + m_nEmptyValueItems),
1664  "OListAndComboImport::implSelectCurrentItem: inconsistence between labels and values!");
1665 
1666  sal_Int16 nItemNumber = static_cast<sal_Int16>(m_aListSource.size() - 1 + m_nEmptyListItems);
1667  m_aSelectedSeq.push_back(nItemNumber);
1668  }
1669 
1671  {
1672  OSL_ENSURE((m_aListSource.size() + m_nEmptyListItems) == (m_aValueList.size() + m_nEmptyValueItems),
1673  "OListAndComboImport::implDefaultSelectCurrentItem: inconsistence between labels and values!");
1674 
1675  sal_Int16 nItemNumber = static_cast<sal_Int16>(m_aListSource.size() - 1 + m_nEmptyListItems);
1676  m_aDefaultSelectedSeq.push_back(nItemNumber);
1677  }
1678 
1679  //= OListOptionImport
1680  OListOptionImport::OListOptionImport(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
1681  const OListAndComboImportRef& _rListBox)
1682  :SvXMLImportContext(_rImport, _nPrefix, _rName)
1683  ,m_xListBoxImport(_rListBox)
1684  {
1685  }
1686 
1687  void OListOptionImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
1688  {
1689  // the label and the value
1690  const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
1691  const OUString sLabelAttribute = rMap.GetQNameByKey(
1692  GetPrefix(), "label");
1693  const OUString sValueAttribute = rMap.GetQNameByKey(
1694  GetPrefix(), "value");
1695 
1696  // the label attribute
1697  OUString sValue = _rxAttrList->getValueByName(sLabelAttribute);
1698  bool bNonexistentAttribute = false;
1699  if (sValue.isEmpty())
1700  if (_rxAttrList->getTypeByName(sLabelAttribute).isEmpty())
1701  // this attribute does not really exist
1702  bNonexistentAttribute = true;
1703 
1704  if (bNonexistentAttribute)
1705  m_xListBoxImport->implEmptyLabelFound();
1706  else
1707  m_xListBoxImport->implPushBackLabel( sValue );
1708 
1709  // the value attribute
1710  sValue = _rxAttrList->getValueByName(sValueAttribute);
1711  bNonexistentAttribute = false;
1712  if (sValue.isEmpty())
1713  if (_rxAttrList->getTypeByName(sValueAttribute).isEmpty())
1714  // this attribute does not really exist
1715  bNonexistentAttribute = true;
1716 
1717  if (bNonexistentAttribute)
1718  m_xListBoxImport->implEmptyValueFound();
1719  else
1720  m_xListBoxImport->implPushBackValue( sValue );
1721 
1722  // the current-selected and selected
1723  const OUString sSelectedAttribute = rMap.GetQNameByKey(
1725  const OUString sDefaultSelectedAttribute = rMap.GetQNameByKey(
1727 
1728  // propagate the selected flag
1729  bool bSelected(false);
1730  (void)::sax::Converter::convertBool(bSelected,
1731  _rxAttrList->getValueByName(sSelectedAttribute));
1732  if (bSelected)
1733  m_xListBoxImport->implSelectCurrentItem();
1734 
1735  // same for the default selected
1736  bool bDefaultSelected(false);
1737  (void)::sax::Converter::convertBool(bDefaultSelected,
1738  _rxAttrList->getValueByName(sDefaultSelectedAttribute));
1739  if (bDefaultSelected)
1740  m_xListBoxImport->implDefaultSelectCurrentItem();
1741 
1742  SvXMLImportContext::StartElement(_rxAttrList);
1743  }
1744 
1745  //= OComboItemImport
1746  OComboItemImport::OComboItemImport(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
1747  const OListAndComboImportRef& _rListBox)
1748  :SvXMLImportContext(_rImport, _nPrefix, _rName)
1749  ,m_xListBoxImport(_rListBox)
1750  {
1751  }
1752 
1753  void OComboItemImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
1754  {
1755  const OUString sLabelAttributeName = GetImport().GetNamespaceMap().GetQNameByKey(
1757  m_xListBoxImport->implPushBackLabel(_rxAttrList->getValueByName(sLabelAttributeName));
1758 
1759  SvXMLImportContext::StartElement(_rxAttrList);
1760  }
1761 
1762  //= OColumnWrapperImport
1763  OColumnWrapperImport::OColumnWrapperImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1764  const Reference< XNameContainer >& _rxParentContainer)
1765  :SvXMLImportContext(_rImport.getGlobalContext(), _nPrefix, _rName)
1766  ,m_xParentContainer(_rxParentContainer)
1767  ,m_rFormImport(_rImport)
1768  ,m_rEventManager(_rEventManager)
1769  {
1770  }
1771  SvXMLImportContextRef OColumnWrapperImport::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
1772  const Reference< XAttributeList >&)
1773  {
1774  OControlImport* pReturn = implCreateChildContext(_nPrefix, _rLocalName, OElementNameMap::getElementType(_rLocalName));
1775  if (pReturn)
1776  {
1777  OSL_ENSURE(m_xOwnAttributes.is(), "OColumnWrapperImport::CreateChildContext: had no form:column element!");
1779  }
1780  return pReturn;
1781  }
1782  void OColumnWrapperImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
1783  {
1784  OSL_ENSURE(!m_xOwnAttributes.is(), "OColumnWrapperImport::StartElement: already have the cloned list!");
1785 
1786  // clone the attributes
1787  Reference< XCloneable > xCloneList(_rxAttrList, UNO_QUERY);
1788  OSL_ENSURE(xCloneList.is(), "OColumnWrapperImport::StartElement: AttributeList not clonable!");
1789  if ( xCloneList.is() )
1790  m_xOwnAttributes.set(xCloneList->createClone(), UNO_QUERY);
1791  OSL_ENSURE(m_xOwnAttributes.is(), "OColumnWrapperImport::StartElement: no cloned list!");
1792  }
1793 
1795  sal_uInt16 _nPrefix, const OUString& _rLocalName,
1797  {
1798  OSL_ENSURE( (OControlElement::TEXT == _eType)
1799  || (OControlElement::TEXT_AREA == _eType)
1800  || (OControlElement::FORMATTED_TEXT == _eType)
1801  || (OControlElement::CHECKBOX == _eType)
1802  || (OControlElement::LISTBOX == _eType)
1803  || (OControlElement::COMBOBOX == _eType)
1804  || (OControlElement::TIME == _eType)
1805  || (OControlElement::DATE == _eType),
1806  "OColumnWrapperImport::implCreateChildContext: invalid or unrecognized sub element!");
1807 
1808  switch (_eType)
1809  {
1812  return new OColumnImport<OListAndComboImport>(m_rFormImport, m_rEventManager, _nPrefix, _rLocalName, m_xParentContainer, _eType );
1813 
1815  return new OColumnImport<OPasswordImport>(m_rFormImport, m_rEventManager, _nPrefix, _rLocalName, m_xParentContainer, _eType );
1816 
1817  case OControlElement::TEXT:
1820  return new OColumnImport< OTextLikeImport >( m_rFormImport, m_rEventManager, _nPrefix, _rLocalName, m_xParentContainer, _eType );
1821 
1822  default:
1823  return new OColumnImport<OControlImport>(m_rFormImport, m_rEventManager, _nPrefix, _rLocalName, m_xParentContainer, _eType );
1824  }
1825  }
1826 
1827  //= OGridImport
1828  OGridImport::OGridImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1829  const Reference< XNameContainer >& _rxParentContainer,
1831  :OControlImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
1832  {
1833  setElementType(_eType);
1834  }
1835 
1837  sal_uInt16 _nPrefix, const OUString& _rLocalName,
1838  const css::uno::Reference< css::xml::sax::XAttributeList >& _rxAttrList)
1839  {
1840  // maybe it's a sub control
1841  if (_rLocalName == "column")
1842  {
1843  if (m_xMeAsContainer.is())
1844  return new OColumnWrapperImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer);
1845  else
1846  {
1847  OSL_FAIL("OGridImport::CreateChildContext: don't have an element!");
1848  return nullptr;
1849  }
1850  }
1851 
1852  return OControlImport::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
1853  }
1854 
1856  {
1858 
1859  // now that we have all children, attach the events
1860  css::uno::Reference< css::container::XIndexAccess > xIndexContainer(m_xMeAsContainer, css::uno::UNO_QUERY);
1861  if (xIndexContainer.is())
1862  ODefaultEventAttacherManager::setEvents(xIndexContainer);
1863  }
1864 
1865  css::uno::Reference< css::beans::XPropertySet > OGridImport::createElement()
1866  {
1867  // let the base class create the object
1868  css::uno::Reference< css::beans::XPropertySet > xReturn = OControlImport::createElement();
1869  if (!xReturn.is())
1870  return xReturn;
1871 
1872  // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
1873  m_xMeAsContainer.set(xReturn, css::uno::UNO_QUERY);
1874  if (!m_xMeAsContainer.is())
1875  {
1876  OSL_FAIL("OContainerImport::createElement: invalid element (no XNameContainer) created!");
1877  xReturn.clear();
1878  }
1879 
1880  return xReturn;
1881  }
1882 
1883  //= OFormImport
1884  OFormImport::OFormImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const OUString& _rName,
1885  const Reference< XNameContainer >& _rxParentContainer)
1886  :OElementImport(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer)
1887  {
1889  }
1890 
1891  SvXMLImportContextRef OFormImport::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
1892  const Reference< XAttributeList >& _rxAttrList)
1893  {
1894  if( token::IsXMLToken(_rLocalName, token::XML_FORM) )
1895  return new OFormImport( m_rFormImport, *this, _nPrefix, _rLocalName,
1897  else if ( token::IsXMLToken(_rLocalName, token::XML_CONNECTION_RESOURCE) )
1898  return new OXMLDataSourceImport(GetImport(), _nPrefix, _rLocalName, _rxAttrList,m_xElement);
1899  else if( (token::IsXMLToken(_rLocalName, token::XML_EVENT_LISTENERS) &&
1900  (XML_NAMESPACE_OFFICE == _nPrefix)) ||
1901  token::IsXMLToken( _rLocalName, token::XML_PROPERTIES) )
1902  return OElementImport::CreateChildContext( _nPrefix, _rLocalName,
1903  _rxAttrList );
1904  else
1905  return implCreateChildContext( _nPrefix, _rLocalName,
1906  OElementNameMap::getElementType(_rLocalName) );
1907  }
1908 
1909  void OFormImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
1910  {
1912  OElementImport::StartElement(_rxAttrList);
1913 
1914  // handle the target-frame attribute
1916  }
1917 
1919  {
1921 
1922  // now that we have all children, attach the events
1923  css::uno::Reference< css::container::XIndexAccess > xIndexContainer(m_xMeAsContainer, css::uno::UNO_QUERY);
1924  if (xIndexContainer.is())
1925  ODefaultEventAttacherManager::setEvents(xIndexContainer);
1926 
1928  }
1929 
1930  css::uno::Reference< css::beans::XPropertySet > OFormImport::createElement()
1931  {
1932  // let the base class create the object
1933  css::uno::Reference< css::beans::XPropertySet > xReturn = OElementImport::createElement();
1934  if (!xReturn.is())
1935  return xReturn;
1936 
1937  // ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
1938  m_xMeAsContainer.set(xReturn, css::uno::UNO_QUERY);
1939  if (!m_xMeAsContainer.is())
1940  {
1941  OSL_FAIL("OContainerImport::createElement: invalid element (no XNameContainer) created!");
1942  xReturn.clear();
1943  }
1944 
1945  return xReturn;
1946  }
1947 
1948  bool OFormImport::handleAttribute(sal_uInt16 _nNamespaceKey, const OUString& _rLocalName, const OUString& _rValue)
1949  {
1950  // handle the master/details field attributes (they're way too special to let the OPropertyImport handle them)
1951  static const char* s_sMasterFieldsAttributeName = OAttributeMetaData::getFormAttributeName(faMasterFields);
1952  static const char* s_sDetailFieldsAttributeName = OAttributeMetaData::getFormAttributeName(faDetailFields);
1953 
1954  if ( _rLocalName.equalsAscii(s_sMasterFieldsAttributeName) )
1955  {
1957  return true;
1958  }
1959 
1960  if ( _rLocalName.equalsAscii(s_sDetailFieldsAttributeName) )
1961  {
1963  return true;
1964  }
1965 
1966  return OElementImport::handleAttribute(_nNamespaceKey, _rLocalName, _rValue);
1967  }
1968 
1969  void OFormImport::implTranslateStringListProperty(const OUString& _rPropertyName, const OUString& _rValue)
1970  {
1971  PropertyValue aProp;
1972  aProp.Name = _rPropertyName;
1973 
1974  Sequence< OUString > aList;
1975 
1976  // split up the value string
1977  if (!_rValue.isEmpty())
1978  {
1979  // For the moment, we build a vector instead of a Sequence. It's easier to handle because of its
1980  // push_back method
1981  ::std::vector< OUString > aElements;
1982  // estimate the number of tokens
1983  sal_Int32 nEstimate = 0, nLength = _rValue.getLength();
1984  const sal_Unicode* pChars = _rValue.getStr();
1985  for (sal_Int32 i=0; i<nLength; ++i, ++pChars)
1986  if (*pChars == ',')
1987  ++nEstimate;
1988  aElements.reserve(nEstimate + 1);
1989  // that's the worst case. If the string contains the separator character _quoted_, we reserved too much...
1990 
1991  sal_Int32 nElementStart = 0;
1992  sal_Int32 nNextSep = 0;
1993  sal_Int32 nElementLength;
1994  OUString sElement;
1995  do
1996  {
1997  // extract the current element
1998  nNextSep = ::sax::Converter::indexOfComma(
1999  _rValue, nElementStart);
2000  if (-1 == nNextSep)
2001  nNextSep = nLength;
2002  sElement = _rValue.copy(nElementStart, nNextSep - nElementStart);
2003 
2004  nElementLength = sElement.getLength();
2005  // when writing the sequence, we quoted the single elements with " characters
2006  OSL_ENSURE( sElement.startsWith("\"") && sElement.endsWith("\""),
2007  "OFormImport::implTranslateStringListProperty: invalid quoted element name.");
2008  sElement = sElement.copy(1, nElementLength - 2);
2009 
2010  aElements.push_back(sElement);
2011 
2012  // switch to the next element
2013  nElementStart = 1 + nNextSep;
2014  }
2015  while (nElementStart < nLength);
2016 
2017  aList = Sequence< OUString >(aElements.data(), aElements.size());
2018  }
2019  else
2020  {
2021  OSL_FAIL("OFormImport::implTranslateStringListProperty: invalid value (empty)!");
2022  }
2023 
2024  aProp.Value <<= aList;
2025 
2026  // add the property to the base class' array
2028  }
2029  //= OXMLDataSourceImport
2031  SvXMLImport& _rImport
2032  ,sal_uInt16 nPrfx
2033  , const OUString& _sLocalName
2034  ,const Reference< css::xml::sax::XAttributeList > & _xAttrList
2035  ,const css::uno::Reference< css::beans::XPropertySet >& _xElement) :
2036  SvXMLImportContext( _rImport, nPrfx, _sLocalName )
2037  {
2038  OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
2039  const SvXMLNamespaceMap& rMap = _rImport.GetNamespaceMap();
2040 
2041  sal_Int16 nLength = (_xElement.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
2042  for(sal_Int16 i = 0; i < nLength; ++i)
2043  {
2044  OUString sLocalName;
2045  OUString sAttrName = _xAttrList->getNameByIndex( i );
2046  sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName, &sLocalName );
2047 
2050  )
2051  {
2052  OUString sValue = _xAttrList->getValueByIndex( i );
2053  sValue = _rImport.GetAbsoluteReference(sValue);
2054  INetURLObject aURL(sValue);
2055  if ( aURL.GetProtocol() == INetProtocol::File )
2056  _xElement->setPropertyValue(PROPERTY_DATASOURCENAME,makeAny(sValue));
2057  else
2058  _xElement->setPropertyValue(PROPERTY_URL,makeAny(sValue)); // the url is the "sdbc:" string
2059  break;
2060  }
2061  }
2062  }
2064  sal_uInt16 _nPrefix, const OUString& _rLocalName,
2066  {
2067  switch (_eType)
2068  {
2069  case OControlElement::TEXT:
2072  return new OTextLikeImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2073 
2077  return new OButtonImport( m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType );
2078 
2081  return new OListAndComboImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2082 
2084  return new ORadioImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2085 
2087  return new OImagePositionImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2088 
2090  return new OPasswordImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2091 
2094  return new OReferredControlImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer);
2095 
2096  case OControlElement::GRID:
2097  return new OGridImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2098 
2100  return new OValueRangeImport( m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType );
2101 
2102  default:
2103  return new OControlImport(m_rFormImport, *this, _nPrefix, _rLocalName, m_xMeAsContainer, _eType);
2104  }
2105  }
2106 
2108  {
2109  return "com.sun.star.form.component.Form";
2110  }
2111 
2112 } // namespace xmloff
2113 
2114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type getSequenceElementType(const Type &_rSequenceType)
void registerCellValueBinding(const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const OUString &_rCellAddress)
OUString m_sListBindingID
name of a list binding (form:xforms-list-source attribute)
::std::map< PropertyId, css::uno::Any > PropertyValues
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
#define PROPERTY_MASTERFIELDS
Definition: strings.hxx:103
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
void simulateDefaultedAttribute(const char *_pAttributeName, const OUString &_rPropertyName, const char *_pAttributeDefault)
can be used to handle properties where the attribute default and the property default differ...
OControlImport * implCreateChildContext(sal_uInt16 _nPrefix, const OUString &_rLocalName, OControlElement::ElementType _eType)
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
#define PROPERTY_LISTSOURCE
Definition: strings.hxx:67
virtual OUString determineDefaultServiceName() const
static sal_uInt16 getCommonControlAttributeNamespace(CCAFlags _nId)
calculates the xml namespace key to use for a common control attribute
URL aURL
ORadioImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer, OControlElement::ElementType _eType)
void registerXFormsValueBinding(const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const OUString &_rBindingID)
IEventAttacherManager & m_rEventManager
::std::vector< PropertyDescriptionList > PropertyGroups
std::map< OUString, ElementType > MapString2Element
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
OListAndComboImportRef m_xListBoxImport
css::uno::Reference< css::container::XNameContainer > m_xMeAsContainer
static css::uno::Any convertString(const css::uno::Type &_rExpectedType, const OUString &_rReadCharacters, const SvXMLEnumMapEntry< EnumT > *_pEnumMap=nullptr)
#define PROPID_MAX_VALUE
const SvXMLEnumMapEntry< sal_uInt16 > * pEnumMap
#define PROPERTY_DETAILFIELDS
Definition: strings.hxx:104
OImagePositionImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer, OControlElement::ElementType _eType)
static const char * getBindingAttributeName(BAFlags _nId)
calculates the xml attribute representation of a binding attribute.
static bool convertBool(bool &rBool, const OUString &rString)
#define PROPID_MIN_VALUE
constexpr sal_uInt16 XML_NAMESPACE_XFORMS
OUString m_sSubmissionID
name of a submission (xforms:submission attribute)
void registerCellRangeListSource(const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const OUString &_rCellRangeAddress)
const AttributeAssignment * getAttributeTranslation(const OUString &_rAttribName)
return the AttributeAssignment which corresponds to the given attribute
signed char sal_Int8
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 _nPrefix, const OUString &_rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
Create a children element context.
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
bool tryGenericAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue)
to be called from within handleAttribute, checks whether the given attribute is covered by our generi...
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
::std::vector< const PropertyDescription * > PropertyDescriptionList
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
static const char * getCommonControlAttributeName(CCAFlags _nId)
calculates the xml attribute representation of a common control attribute.
css::uno::Reference< css::text::XTextCursor > m_xCursor
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
#define PROPERTY_DEFAULT_SELECT_SEQ
Definition: strings.hxx:78
helper class importing a single grid column (without the element wrapping the column)...
#define PROPID_VALUE
constexpr sal_uInt16 XML_NAMESPACE_OOO
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
helper for translating between control types and XML tags
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:394
PropertyValueArray m_aGenericValues
AttributeDescription getAttributeDescription(const sal_uInt16 i_namespacePrefix, const OUString &i_attributeName)
retrieves the attribute descriptor for the attribute given by namespace prefix and attribute name ...
#define LEAVE_LOG_CONTEXT()
Definition: logging.hxx:54
void addList(const css::uno::Reference< css::xml::sax::XAttributeList > &_rList)
#define PROPERTY_AUTOCOMPLETE
Definition: strings.hxx:71
A specialized version of the OControlImport class, which handles the target frame for im...
static void implTranslateValueProperty(const css::uno::Reference< css::beans::XPropertySetInfo > &_rxPropInfo, css::beans::PropertyValue &_rPropValue)
void implTranslateStringListProperty(const OUString &_rPropertyName, const OUString &_rValue)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 _nPrefix, const OUString &_rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
Create a children element context.
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
OButtonImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer, OControlElement::ElementType _eType)
css::uno::Reference< css::graphic::XGraphic > loadGraphicByURL(OUString const &rURL)
Definition: xmlimp.cxx:1334
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
StartElement is called after a context has been constructed and before an elements context is parsed...
Definition: xmlictxt.cxx:58
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:592
OComboItemImport(SvXMLImport &_rImport, sal_uInt16 _nPrefix, const OUString &_rName, const OListAndComboImportRef &_rListBox)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
#define PROPERTY_SPIN_INCREMENT
Definition: strings.hxx:128
static sal_Int32 indexOfComma(const OUString &rStr, sal_Int32 nPos)
#define PROPERTY_DATASOURCENAME
Definition: strings.hxx:48
helper class importing a single element
virtual css::uno::Reference< css::beans::XPropertySet > createElement() override
create the (uninitialized) element which is to represent the read data
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
a specialized version of the OControlImport class, which is able to handle attributes wh...
sal_uInt16 sal_Unicode
#define PROPERTY_URL
Definition: strings.hxx:100
#define PROPERTY_RICH_TEXT
Definition: strings.hxx:142
const PropertyId propertyId
the unique ID of the property. The property meta data table must not contain two entries with the sam...
sal_Int32 m_nEmptyValueItems
number of empty list items encountered during reading
OFormLayerXMLImport_Impl & m_rFormImport
#define PROPERTY_IMAGE_POSITION
Definition: strings.hxx:133
A specialized version of the OControlImport class, which handles text like controls whic...
size_t pos
OTextLikeImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer, OControlElement::ElementType _eType)
implements the XAttributeList list by merging different source attribute lists
A specialized version of the OControlImport class, which handles attributes / sub elemen...
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
css::uno::Reference< css::container::XNameContainer > m_xParentContainer
void doRegisterXFormsListBinding(const OUString &)
register the given XForms list binding
constexpr sal_uInt16 XML_NAMESPACE_FORM
const SvXMLEnumMapEntry< sal_Int16 > aImagePositionMap[]
Definition: formenums.cxx:164
css::uno::Reference< css::graphic::XGraphic > m_xGraphic
virtual OUString determineDefaultServiceName() const override
OControlImport * implCreateChildContext(sal_uInt16 _nPrefix, const OUString &_rLocalName, OControlElement::ElementType _eType)
void getPropertyGroupList(const AttributeDescription &i_attribute, PropertyGroups &o_propertyGroups)
retrieves all known property groups which are mapped to the given attribute
void setEvents(const css::uno::Reference< css::container::XIndexAccess > &_rxContainer)
sal_uInt16 GetKeyByAttrValueQName(const OUString &rAttrName, OUString *pLocalName) const
#define PROPERTY_SELECT_SEQ
Definition: strings.hxx:79
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
UNKNOWN
static const char * getElementName(ElementType _eType)
retrieves the tag name to be used to describe a control of the given type
sal_Int32 nHandle
void registerControlId(const css::uno::Reference< css::beans::XPropertySet > &_rxControl, const OUString &_rId)
OReferredControlImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer)
DocumentType eType
::xmloff::token::XMLTokenEnum attributeToken
const OControlElement::ElementType & operator++(OControlElement::ElementType &_e)
#define PROPERTY_LINE_INCREMENT
Definition: strings.hxx:121
OListAndComboImportRef m_xListBoxImport
constexpr sal_uInt16 XML_NAMESPACE_XML
OFormImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer)
const OUString & m_sName
OGridImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer, OControlElement::ElementType _eType)
#define DBG_UNHANDLED_EXCEPTION(...)
void addOuterAttributes(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxOuterAttribs)
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
#define TOOLS_WARN_EXCEPTION(area, stream)
void enableTrackAttributes()
enables the tracking of the encountered attributes
void registerControlReferences(const css::uno::Reference< css::beans::XPropertySet > &_rxControl, const OUString &_rReferringControls)
static const char * getSpecialAttributeName(SCAFlags _nId)
calculates the xml attribute representation of a special attribute.
int i
css::uno::Reference< css::xml::sax::XAttributeList > m_xOuterAttributes
css::uno::Reference< css::xml::sax::XAttributeList > m_xOwnAttributes
constexpr sal_uInt16 XML_NAMESPACE_TEXT
OControlImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer)
bool m_bEncounteredLSAttrib
number of empty value items encountered during reading
sal_Int32 m_nEmptyListItems
the cell range which acts as list source for the control
virtual css::uno::Reference< css::beans::XPropertySet > createElement() override
create the (uninitialized) element which is to represent the read data
#define PROPERTY_EFFECTIVE_DEFAULT
Definition: strings.hxx:98
void registerXFormsSubmission(const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const OUString &_rSubmissionID)
OUString implGetDefaultName() const
#define PROPERTY_CLASSID
Definition: strings.hxx:27
virtual void registerEvents(const css::uno::Reference< css::beans::XPropertySet > &_rxElement, const css::uno::Sequence< css::script::ScriptEventDescriptor > &_rEvents)=0
Reference< XContent > m_xParentContainer
#define ENSURE_OR_RETURN(c, m, r)
static void getRuntimeValuePropertyNames(OControlElement::ElementType _eType, sal_Int16 _nFormComponentType, char const *&_rpValuePropertyName, char const *&_rpDefaultValuePropertyName)
calculate the names of the properties which, at runtime, are used for value and default value...
#define PROPERTY_ALIGN
Definition: strings.hxx:107
OUString m_sBindingID
name of a value binding (xforms:bind attribute)
void implPushBackLabel(const OUString &_rLabel)
A specialized version of the OControlImport class, which imports the value-range element...
#define PROPERTY_REPEAT_DELAY
Definition: strings.hxx:123
const SvXMLEnumMapEntry< sal_uInt16 > aImageAlignMap[]
Definition: formenums.cxx:173
virtual OUString determineDefaultServiceName() const override
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
PropertyGroups::const_iterator impl_matchPropertyGroup(const PropertyGroups &i_propertyGroups) const
static const char * getDatabaseAttributeName(DAFlags _nId)
calculates the xml attribute representation of a database attribute.
virtual void doRegisterCellValueBinding(const OUString &_rBoundCellAddress)
registers the given cell address as value binding address for our element
void applyControlNumberStyle(const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const OUString &_rControlNumberStyleName)
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
IEventAttacherManager & m_rEventManager
OPasswordImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer, OControlElement::ElementType _eType)
#define PROPERTY_GRAPHIC
Definition: strings.hxx:31
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 _nPrefix, const OUString &_rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
Create a children element context.
std::vector< OUString > m_aListSource
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 _nPrefix, const OUString &_rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
Create a children element context.
static void getValueLimitPropertyNames(sal_Int16 _nFormComponentType, char const *&_rpMinValuePropertyName, char const *&_rpMaxValuePropertyName)
calculate the property names for the min-value and the max-value attribute.
virtual void doRegisterCellValueBinding(const OUString &_rBoundCellAddress) override
registers the given cell address as value binding address for our element
void doRegisterXFormsValueBinding(const OUString &)
register the given XForms binding
#define PROPERTY_EFFECTIVE_VALUE
Definition: strings.hxx:97
OControlElement::ElementType m_eElementType
void setElementType(OControlElement::ElementType _eType)
sal_Int32 attribute
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
OFormLayerXMLImport_Impl & m_rFormImport
OFormLayerXMLImport_Impl & m_rContext
PropertyValueArray m_aValues
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
helper class for importing the description of a single control
OListAndComboImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer, OControlElement::ElementType _eType)
if and only if we should use a cell value binding which exchanges the selection index (instead...
#define PROPERTY_TARGETFRAME
Definition: strings.hxx:33
const PropertyValue * pValues
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
static ElementType getElementType(const OUString &_rName)
void implPushBackPropertyValue(const css::beans::PropertyValue &_rProp)
#define PROPERTY_ECHOCHAR
Definition: strings.hxx:28
virtual ~OElementImport() override
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
implements common behaviour for importing forms, controls and columns
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
std::vector< sal_Int16 > m_aSelectedSeq
std::vector< sal_Int16 > m_aDefaultSelectedSeq
css::uno::Reference< css::uno::XComponentContext > const & GetComponentContext() const
Definition: xmlimp.cxx:1858
OUString GetAbsoluteReference(const OUString &rValue) const
Definition: xmlimp.cxx:1665
OURLReferenceImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer, OControlElement::ElementType _eType)
#define SAL_WARN_IF(condition, area, stream)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3378
PropertyValueArray m_aValueProperties
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue)
handle one single attribute.
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 _nPrefix, const OUString &_rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
Create a children element context.
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Helper class for importing property values.
Handling of tokens in XML:
OAttribute2Property & getAttributeMap()
Definition: layerimport.hxx:95
const SvXMLEnumMapEntry< sal_Int16 > aListLinkageMap[]
Definition: formenums.cxx:145
virtual void registerEvents(const css::uno::Sequence< css::script::ScriptEventDescriptor > &_rEvents) override
INetProtocol GetProtocol() const
virtual css::uno::Reference< css::beans::XPropertySet > createElement()
create the (uninitialized) element which is to represent the read data
const OUString & GetDataStyleName() const
Definition: txtstyli.hxx:77
void registerXFormsListBinding(const css::uno::Reference< css::beans::XPropertySet > &_rxControlModel, const OUString &_rBindingID)
virtual css::uno::Reference< css::beans::XPropertySet > createElement() override
create the (uninitialized) element which is to represent the read data
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 _nPrefix, const OUString &_rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
Create a children element context.
OColumnWrapperImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer)
const sal_Int32 m_nHandle
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
css::uno::Reference< css::beans::XPropertySet > m_xElement
the element we're creating. Valid after StartElement
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 _nPrefix, const OUString &_rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
Create a children element context.
css::uno::Reference< css::text::XTextCursor > m_xOldCursor
#define ENTER_LOG_CONTEXT(name)
Definition: logging.hxx:53
#define PROPID_CURRENT_VALUE
OUString m_sBoundCellAddress
the address of the calc cell which the control model should be bound to, if applicable ...
void implPushBackValue(const OUString &_rValue)
css::uno::Reference< css::beans::XPropertySetInfo > m_xInfo
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
#define SAL_WARN(area, stream)
#define PROPERTY_STRING_ITEM_LIST
Definition: strings.hxx:76
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
sal_Int32 nLength
Definition: xmltoken.cxx:36
void disableImplicitGenericAttributeHandling()
controls whether |handleAttribute| implicitly calls |tryGenericAttribute|, or whether the derived cla...
void doRegisterXFormsSubmission(const OUString &)
register the given XForms submission
OXMLDataSourceImport(SvXMLImport &_rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, const css::uno::Reference< css::beans::XPropertySet > &_xElement)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
static void getValuePropertyNames(OControlElement::ElementType _eType, sal_Int16 _nFormComponentType, char const *&_rpCurrentValuePropertyName, char const *&_rpValuePropertyName)
calculate the property names for the current-value and the value attribute.
#define PROPERTY_TEXT
Definition: strings.hxx:96
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &_rxAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
#define PROPERTY_EMPTY_IS_NULL
Definition: strings.hxx:65
static MapString2Element s_sElementTranslations
css::uno::Reference< css::container::XNameContainer > m_xMeAsContainer
OElementImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer)
ctor
const XMLTextStyleContext * m_pStyleElement
OValueRangeImport(OFormLayerXMLImport_Impl &_rImport, IEventAttacherManager &_rEventManager, sal_uInt16 _nPrefix, const OUString &_rName, const css::uno::Reference< css::container::XNameContainer > &_rxParentContainer, OControlElement::ElementType _eType)
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
bool encounteredAttribute(const OUString &_rAttributeName) const
determine if the element imported by the object had a given attribute.
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
sal_uInt16 GetPrefix() const
Definition: xmlictxt.hxx:68
static const char * getFormAttributeName(FormAttributes _eAttrib)
retrieves the name of an attribute of a form xml representation
std::vector< OUString > m_aValueList
const PropertyHandlerFactory factory
is the factory for creating a handler for reading and writing the property
OListOptionImport(SvXMLImport &_rImport, sal_uInt16 _nPrefix, const OUString &_rName, const OListAndComboImportRef &_rListBox)
const char first[]
sal_Int16 nValue
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, const OUString &_rLocalName, const OUString &_rValue) override
handle one single attribute.
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
css::uno::Reference< css::container::XNameContainer > m_xParentContainer
the parent container to insert the new element into
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)
const SvXMLStyleContext * getStyleElement(const OUString &_rStyleName) const