1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "elementimport.hxx"
21 #include <xmloff/xmlimp.hxx>
22 #include <xmloff/nmspmap.hxx>
23 #include "strings.hxx"
24 #include "callbacks.hxx"
25 #include "attriblistmerge.hxx"
26 #include <xmloff/xmlnmspe.hxx>
27 #include "eventimport.hxx"
28 #include <xmloff/txtstyli.hxx>
29 #include "formenums.hxx"
30 #include <xmloff/xmltoken.hxx>
31 #include "gridcolumnproptranslator.hxx"
32 #include "property_description.hxx"
33 #include "property_meta_data.hxx"
35 #include <com/sun/star/text/XText.hpp>
36 #include <com/sun/star/util/XCloneable.hpp>
37 #include <com/sun/star/util/Duration.hpp>
38 #include <com/sun/star/form/FormComponentType.hpp>
39 #include <com/sun/star/awt/ImagePosition.hpp>
40 #include <com/sun/star/beans/XMultiPropertySet.hpp>
41 #include <com/sun/star/beans/XPropertyContainer.hpp>
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #include <sax/tools/converter.hxx>
45 #include <tools/urlobj.hxx>
46 #include <tools/diagnose_ex.h>
47 #include <rtl/strbuf.hxx>
48 #include <comphelper/extract.hxx>
49 #include <comphelper/types.hxx>
57 using namespace ::xmloff::token
;
58 using namespace ::com::sun::star
;
59 using namespace ::com::sun::star::uno
;
60 using namespace ::com::sun::star::awt
;
61 using namespace ::com::sun::star::container
;
62 using namespace ::com::sun::star::beans
;
63 using namespace ::com::sun::star::script
;
64 using namespace ::com::sun::star::lang
;
65 using namespace ::com::sun::star::form
;
66 using namespace ::com::sun::star::xml
;
67 using namespace ::com::sun::star::util
;
68 using namespace ::com::sun::star::text
;
69 using namespace ::comphelper
;
70 using ::com::sun::star::xml::sax::XAttributeList
;
72 #define PROPID_VALUE 1
73 #define PROPID_CURRENT_VALUE 2
74 #define PROPID_MIN_VALUE 3
75 #define PROPID_MAX_VALUE 4
77 struct PropertyValueLess
79 bool operator()(const PropertyValue
& _rLeft
, const PropertyValue
& _rRight
)
81 return _rLeft
.Name
< _rRight
.Name
;
85 template <class ELEMENT
>
86 void pushBackSequenceElement(Sequence
< ELEMENT
>& _rContainer
, const ELEMENT
& _rElement
)
88 sal_Int32 nLen
= _rContainer
.getLength();
89 _rContainer
.realloc(nLen
+ 1);
90 _rContainer
[nLen
] = _rElement
;
94 OElementNameMap::MapString2Element
OElementNameMap::s_sElementTranslations
;
96 const OControlElement::ElementType
& operator ++(OControlElement::ElementType
& _e
)
98 OControlElement::ElementType e
= _e
;
99 sal_Int32 nAsInt
= static_cast<sal_Int32
>(e
);
100 _e
= static_cast<OControlElement::ElementType
>( ++nAsInt
);
104 OControlElement::ElementType
OElementNameMap::getElementType(const OUString
& _rName
)
106 if ( s_sElementTranslations
.empty() )
108 for (ElementType eType
=(ElementType
)0; eType
<UNKNOWN
; ++eType
)
109 s_sElementTranslations
[OUString::createFromAscii(getElementName(eType
))] = eType
;
111 MapString2Element::const_iterator aPos
= s_sElementTranslations
.find(_rName
);
112 if (s_sElementTranslations
.end() != aPos
)
119 OElementImport::OElementImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
120 const Reference
< XNameContainer
>& _rxParentContainer
)
121 :OPropertyImport(_rImport
, _nPrefix
, _rName
)
122 ,m_rFormImport(_rImport
)
123 ,m_rEventManager(_rEventManager
)
124 ,m_pStyleElement( nullptr )
125 ,m_xParentContainer(_rxParentContainer
)
126 ,m_bImplicitGenericAttributeHandling( true )
128 OSL_ENSURE(m_xParentContainer
.is(), "OElementImport::OElementImport: invalid parent container!");
131 OElementImport::~OElementImport()
135 OUString
OElementImport::determineDefaultServiceName() const
140 void OElementImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
142 ENTER_LOG_CONTEXT( "xmloff::OElementImport - importing one element" );
144 const SvXMLNamespaceMap
& rMap
= m_rContext
.getGlobalContext().GetNamespaceMap();
145 const OUString sImplNameAttribute
= rMap
.GetQNameByKey( XML_NAMESPACE_FORM
, GetXMLToken( XML_CONTROL_IMPLEMENTATION
) );
146 const OUString sControlImplementation
= _rxAttrList
->getValueByName( sImplNameAttribute
);
148 // retrieve the service name
149 if ( !sControlImplementation
.isEmpty() )
151 OUString sOOoImplementationName
;
152 const sal_uInt16 nImplPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sControlImplementation
, &sOOoImplementationName
);
153 m_sServiceName
= ( nImplPrefix
== XML_NAMESPACE_OOO
) ? sOOoImplementationName
: sControlImplementation
;
156 if ( m_sServiceName
.isEmpty() )
157 m_sServiceName
= determineDefaultServiceName();
159 // create the object *now*. This allows setting properties in the various handleAttribute methods.
160 // (Though currently not all code is migrated to this pattern, most attributes are still handled
161 // by remembering the value (via implPushBackPropertyValue), and setting the correct property value
162 // later (in OControlImport::StartElement).)
163 m_xElement
= createElement();
164 if ( m_xElement
.is() )
165 m_xInfo
= m_xElement
->getPropertySetInfo();
167 // call the base class
168 OPropertyImport::StartElement( _rxAttrList
);
171 SvXMLImportContext
* OElementImport::CreateChildContext(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
172 const Reference
< XAttributeList
>& _rxAttrList
)
174 if( token::IsXMLToken(_rLocalName
, token::XML_EVENT_LISTENERS
) && (XML_NAMESPACE_OFFICE
== _nPrefix
))
175 return new OFormEventsImportContext(m_rFormImport
.getGlobalContext(), _nPrefix
, _rLocalName
, *this);
177 return OPropertyImport::CreateChildContext(_nPrefix
, _rLocalName
, _rxAttrList
);
180 void OElementImport::EndElement()
182 OSL_ENSURE(m_xElement
.is(), "OElementImport::EndElement: invalid element created!");
183 if (!m_xElement
.is())
186 // apply the non-generic properties
187 implApplySpecificProperties();
189 // set the generic properties
190 implApplyGenericProperties();
192 // set the style properties
193 if ( m_pStyleElement
&& m_xElement
.is() )
195 Reference
< XPropertySet
> xPropTranslation
=
196 new OGridColumnPropertyTranslator( Reference
< XMultiPropertySet
>( m_xElement
, UNO_QUERY
) );
197 const_cast< XMLTextStyleContext
* >( m_pStyleElement
)->FillPropertySet( xPropTranslation
);
199 const OUString sNumberStyleName
= m_pStyleElement
->GetDataStyleName( );
200 if ( !sNumberStyleName
.isEmpty() )
201 // the style also has a number (sub) style
202 m_rContext
.applyControlNumberStyle( m_xElement
, sNumberStyleName
);
205 // insert the element into the parent container
206 if (m_sName
.isEmpty())
208 OSL_FAIL("OElementImport::EndElement: did not find a name attribute!");
209 m_sName
= implGetDefaultName();
212 if (m_xParentContainer
.is())
213 m_xParentContainer
->insertByName(m_sName
, makeAny(m_xElement
));
215 LEAVE_LOG_CONTEXT( );
218 void OElementImport::implApplySpecificProperties()
220 if ( m_aValues
.empty() )
223 // set all the properties we collected
224 #if OSL_DEBUG_LEVEL > 0
225 // check if the object has all the properties
226 // (We do this in the non-pro version only. Doing it all the time would be much to expensive)
229 PropertyValueArray::const_iterator aEnd
= m_aValues
.end();
230 for ( PropertyValueArray::iterator aCheck
= m_aValues
.begin();
235 OSL_ENSURE(m_xInfo
->hasPropertyByName(aCheck
->Name
),
236 OStringBuffer("OElementImport::implApplySpecificProperties: read a property (").
237 append(OUStringToOString(aCheck
->Name
, RTL_TEXTENCODING_ASCII_US
)).
238 append(") which does not exist on the element!").getStr());
243 // set the properties
244 const Reference
< XMultiPropertySet
> xMultiProps(m_xElement
, UNO_QUERY
);
245 bool bSuccess
= false;
246 if (xMultiProps
.is())
248 // translate our properties so that the XMultiPropertySet can handle them
250 // sort our property value array so that we can use it in a setPropertyValues
251 ::std::sort( m_aValues
.begin(), m_aValues
.end(), PropertyValueLess());
254 Sequence
< OUString
> aNames(m_aValues
.size());
255 OUString
* pNames
= aNames
.getArray();
257 Sequence
< Any
> aValues(m_aValues
.size());
258 Any
* pValues
= aValues
.getArray();
261 PropertyValueArray::iterator aEnd
= m_aValues
.end();
262 for ( PropertyValueArray::iterator aPropValues
= m_aValues
.begin();
264 ++aPropValues
, ++pNames
, ++pValues
267 *pNames
= aPropValues
->Name
;
268 *pValues
= aPropValues
->Value
;
273 xMultiProps
->setPropertyValues(aNames
, aValues
);
276 catch(const Exception
&)
278 OSL_FAIL("OElementImport::implApplySpecificProperties: could not set the properties (using the XMultiPropertySet)!");
279 DBG_UNHANDLED_EXCEPTION();
284 { // no XMultiPropertySet or setting all properties at once failed
285 PropertyValueArray::iterator aEnd
= m_aValues
.end();
286 for ( PropertyValueArray::iterator aPropValues
= m_aValues
.begin();
291 // this try/catch here is expensive, but because this is just a fallback which should normally not be
292 // used it's acceptable this way ...
295 m_xElement
->setPropertyValue(aPropValues
->Name
, aPropValues
->Value
);
297 catch(const Exception
&)
299 OSL_FAIL(OStringBuffer("OElementImport::implApplySpecificProperties: could not set the property \"").
300 append(OUStringToOString(aPropValues
->Name
, RTL_TEXTENCODING_ASCII_US
)).
301 append("\"!").getStr());
302 DBG_UNHANDLED_EXCEPTION();
308 void OElementImport::implApplyGenericProperties()
310 if ( m_aGenericValues
.empty() )
313 Reference
< XPropertyContainer
> xDynamicProperties( m_xElement
, UNO_QUERY
);
315 PropertyValueArray::iterator aEnd
= m_aGenericValues
.end();
316 for ( PropertyValueArray::iterator aPropValues
=
317 m_aGenericValues
.begin();
322 // check property type for numeric types before setting
326 // if such a property does not yet exist at the element, create it if necessary
327 const bool bExistentProperty
= m_xInfo
->hasPropertyByName( aPropValues
->Name
);
328 if ( !bExistentProperty
)
330 if ( !xDynamicProperties
.is() )
332 #if OSL_DEBUG_LEVEL > 0
333 OString
aMessage( "OElementImport::implApplyGenericProperties: encountered an unknown property (" );
334 aMessage
+= OUStringToOString( aPropValues
->Name
, RTL_TEXTENCODING_ASCII_US
);
335 aMessage
+= "), but component is no PropertyBag!";
336 OSL_FAIL( aMessage
.getStr() );
341 xDynamicProperties
->addProperty(
343 PropertyAttribute::BOUND
| PropertyAttribute::REMOVABLE
,
347 // re-fetch the PropertySetInfo
348 m_xInfo
= m_xElement
->getPropertySetInfo();
351 // determine the type of the value (source for the following conversion)
352 TypeClass eValueTypeClass
= aPropValues
->Value
.getValueTypeClass();
353 const bool bValueIsSequence
= TypeClass_SEQUENCE
== eValueTypeClass
;
354 if ( bValueIsSequence
)
356 uno::Type
aSimpleType( getSequenceElementType( aPropValues
->Value
.getValueType() ) );
357 eValueTypeClass
= aSimpleType
.getTypeClass();
360 // determine the type of the property (target for the following conversion)
361 const Property
aProperty( m_xInfo
->getPropertyByName( aPropValues
->Name
) );
362 TypeClass ePropTypeClass
= aProperty
.Type
.getTypeClass();
363 const bool bPropIsSequence
= TypeClass_SEQUENCE
== ePropTypeClass
;
364 if( bPropIsSequence
)
366 uno::Type
aSimpleType( ::comphelper::getSequenceElementType( aProperty
.Type
) );
367 ePropTypeClass
= aSimpleType
.getTypeClass();
370 if ( bPropIsSequence
!= bValueIsSequence
)
372 OSL_FAIL( "OElementImport::implImportGenericProperties: either both value and property should be a sequence, or none of them!" );
376 if ( bValueIsSequence
)
378 OSL_ENSURE( eValueTypeClass
== TypeClass_ANY
,
379 "OElementImport::implApplyGenericProperties: only ANYs should have been imported as generic list property!" );
380 // (OPropertyImport should produce only Sequencer< Any >, since it cannot know the real type
382 OSL_ENSURE( ePropTypeClass
== TypeClass_SHORT
,
383 "OElementImport::implApplyGenericProperties: conversion to sequences other than 'sequence< short >' not implemented, yet!" );
385 Sequence
< Any
> aXMLValueList
;
386 aPropValues
->Value
>>= aXMLValueList
;
387 Sequence
< sal_Int16
> aPropertyValueList( aXMLValueList
.getLength() );
389 const Any
* pXMLValue
= aXMLValueList
.getConstArray();
390 sal_Int16
* pPropValue
= aPropertyValueList
.getArray();
392 for ( sal_Int32 i
=0; i
<aXMLValueList
.getLength(); ++i
, ++pXMLValue
, ++pPropValue
)
394 // only value sequences of numeric types implemented so far.
396 OSL_VERIFY( *pXMLValue
>>= nVal
);
397 *pPropValue
= static_cast< sal_Int16
>( nVal
);
400 aPropValues
->Value
<<= aPropertyValueList
;
402 else if ( ePropTypeClass
!= eValueTypeClass
)
404 switch ( eValueTypeClass
)
406 case TypeClass_DOUBLE
:
409 aPropValues
->Value
>>= nVal
;
410 switch( ePropTypeClass
)
413 aPropValues
->Value
<<= static_cast< sal_Int8
>( nVal
);
415 case TypeClass_SHORT
:
416 aPropValues
->Value
<<= static_cast< sal_Int16
>( nVal
);
418 case TypeClass_UNSIGNED_SHORT
:
419 aPropValues
->Value
<<= static_cast< sal_uInt16
>( nVal
);
423 aPropValues
->Value
<<= static_cast< sal_Int32
>( nVal
);
425 case TypeClass_UNSIGNED_LONG
:
426 aPropValues
->Value
<<= static_cast< sal_uInt32
>( nVal
);
428 case TypeClass_UNSIGNED_HYPER
:
429 aPropValues
->Value
<<= static_cast< sal_uInt64
>( nVal
);
431 case TypeClass_HYPER
:
432 aPropValues
->Value
<<= static_cast< sal_Int64
>( nVal
);
435 OSL_FAIL( "OElementImport::implImportGenericProperties: unsupported value type!" );
441 OSL_FAIL( "OElementImport::implImportGenericProperties: non-double values not supported!" );
446 m_xElement
->setPropertyValue( aPropValues
->Name
, aPropValues
->Value
);
448 catch(const Exception
&)
450 OSL_FAIL(OStringBuffer("OElementImport::EndElement: could not set the property \"").
451 append(OUStringToOString(aPropValues
->Name
, RTL_TEXTENCODING_ASCII_US
)).
452 append("\"!").getStr());
453 DBG_UNHANDLED_EXCEPTION();
458 OUString
OElementImport::implGetDefaultName() const
460 // no optimization here. If this method gets called, the XML stream did not contain a name for the
461 // element, which is a heavy error. So in this case we don't care for performance
462 static const char sUnnamedName
[] = "unnamed";
463 OSL_ENSURE(m_xParentContainer
.is(), "OElementImport::implGetDefaultName: no parent container!");
464 if (!m_xParentContainer
.is())
465 return OUString(sUnnamedName
);
466 Sequence
< OUString
> aNames
= m_xParentContainer
->getElementNames();
469 const OUString
* pNames
= nullptr;
470 const OUString
* pNamesEnd
= aNames
.getConstArray() + aNames
.getLength();
471 for (sal_Int32 i
=0; i
<32768; ++i
) // the limit is nearly arbitrary ...
473 // assemble the new name (suggestion)
474 sReturn
= sUnnamedName
;
475 sReturn
+= OUString::number(i
);
476 // check the existence (this is the bad performance part ....)
477 for (pNames
= aNames
.getConstArray(); pNames
<pNamesEnd
; ++pNames
)
479 if (*pNames
== sReturn
)
484 if (pNames
<pNamesEnd
)
489 OSL_FAIL("OElementImport::implGetDefaultName: did not find a free name!");
490 return OUString(sUnnamedName
);
493 PropertyGroups::const_iterator
OElementImport::impl_matchPropertyGroup( const PropertyGroups
& i_propertyGroups
) const
495 ENSURE_OR_RETURN( m_xInfo
.is(), "OElementImport::impl_matchPropertyGroup: no property set info!", i_propertyGroups
.end() );
497 for ( PropertyGroups::const_iterator group
= i_propertyGroups
.begin();
498 group
!= i_propertyGroups
.end();
502 bool missingProp
= false;
503 for ( PropertyDescriptionList::const_iterator prop
= group
->begin();
504 prop
!= group
->end();
508 if ( !m_xInfo
->hasPropertyByName( (*prop
)->propertyName
) )
522 return i_propertyGroups
.end();
525 bool OElementImport::tryGenericAttribute( sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
527 // the generic approach (which I hope all props will be migrated to, on the medium term): property handlers
528 const AttributeDescription
attribute( metadata::getAttributeDescription( _nNamespaceKey
, _rLocalName
) );
529 if ( attribute
.attributeToken
!= XML_TOKEN_INVALID
)
531 PropertyGroups propertyGroups
;
532 metadata::getPropertyGroupList( attribute
, propertyGroups
);
533 const PropertyGroups::const_iterator pos
= impl_matchPropertyGroup( propertyGroups
);
534 if ( pos
== propertyGroups
.end() )
539 const PropertyDescriptionList
& rProperties( *pos
);
540 const PropertyDescription
* first
= *rProperties
.begin();
543 SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property description!" );
547 const PPropertyHandler handler
= (*first
->factory
)( first
->propertyId
);
548 if ( !handler
.get() )
550 SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property handler!" );
554 PropertyValues aValues
;
555 for ( PropertyDescriptionList::const_iterator propDesc
= rProperties
.begin();
556 propDesc
!= rProperties
.end();
560 aValues
[ (*propDesc
)->propertyId
] = Any();
562 if ( handler
->getPropertyValues( _rValue
, aValues
) )
564 for ( PropertyDescriptionList::const_iterator propDesc
= rProperties
.begin();
565 propDesc
!= rProperties
.end();
569 implPushBackPropertyValue( (*propDesc
)->propertyName
, aValues
[ (*propDesc
)->propertyId
] );
581 bool OElementImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
583 if ( token::IsXMLToken( _rLocalName
, token::XML_CONTROL_IMPLEMENTATION
) )
584 // ignore this, it has already been handled in OElementImport::StartElement
587 if ( token::IsXMLToken( _rLocalName
, token::XML_NAME
) )
589 if ( m_sName
.isEmpty() )
590 // remember the name for later use in EndElement
595 // maybe it's the style attribute?
596 if ( token::IsXMLToken( _rLocalName
, token::XML_TEXT_STYLE_NAME
) )
598 const SvXMLStyleContext
* pStyleContext
= m_rContext
.getStyleElement( _rValue
);
599 OSL_ENSURE( pStyleContext
, "OElementImport::handleAttribute: do not know the style!" );
600 // remember the element for later usage.
601 m_pStyleElement
= dynamic_cast<const XMLTextStyleContext
*>( pStyleContext
);
605 if ( m_bImplicitGenericAttributeHandling
)
606 if ( tryGenericAttribute( _nNamespaceKey
, _rLocalName
, _rValue
) )
609 // let the base class handle it
610 return OPropertyImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
613 Reference
< XPropertySet
> OElementImport::createElement()
615 Reference
< XPropertySet
> xReturn
;
616 if (!m_sServiceName
.isEmpty())
618 Reference
< XComponentContext
> xContext
= m_rFormImport
.getGlobalContext().GetComponentContext();
619 Reference
< XInterface
> xPure
= xContext
->getServiceManager()->createInstanceWithContext(m_sServiceName
, xContext
);
620 OSL_ENSURE(xPure
.is(),
621 OStringBuffer("OElementImport::createElement: service factory gave me no object (service name: ").append(OUStringToOString(m_sServiceName
, RTL_TEXTENCODING_ASCII_US
)).append(")!").getStr());
622 xReturn
.set(xPure
, UNO_QUERY
);
625 OSL_FAIL("OElementImport::createElement: no service name to create an element!");
630 void OElementImport::registerEvents(const Sequence
< ScriptEventDescriptor
>& _rEvents
)
632 OSL_ENSURE(m_xElement
.is(), "OElementImport::registerEvents: no element to register events for!");
633 m_rEventManager
.registerEvents(m_xElement
, _rEvents
);
636 void OElementImport::simulateDefaultedAttribute(const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
, const sal_Char
* _pAttributeDefault
)
638 OSL_ENSURE( m_xInfo
.is(), "OPropertyImport::simulateDefaultedAttribute: the component should be more gossipy about it's properties!" );
640 if ( !m_xInfo
.is() || m_xInfo
->hasPropertyByName( _rPropertyName
) )
642 OUString sLocalAttrName
= OUString::createFromAscii(_pAttributeName
);
643 if ( !encounteredAttribute( sLocalAttrName
) )
644 OSL_VERIFY( handleAttribute( XML_NAMESPACE_FORM
, sLocalAttrName
, OUString::createFromAscii( _pAttributeDefault
) ) );
649 OControlImport::OControlImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
650 const Reference
< XNameContainer
>& _rxParentContainer
)
651 :OElementImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
)
652 ,m_eElementType(OControlElement::UNKNOWN
)
654 disableImplicitGenericAttributeHandling();
657 OControlImport::OControlImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
658 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
659 :OElementImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
)
660 ,m_eElementType(_eType
)
662 disableImplicitGenericAttributeHandling();
665 OUString
OControlImport::determineDefaultServiceName() const
667 const sal_Char
* pServiceName
= nullptr;
668 switch ( m_eElementType
)
670 case OControlElement::TEXT
:
671 case OControlElement::TEXT_AREA
:
672 case OControlElement::PASSWORD
: pServiceName
= "com.sun.star.form.component.TextField"; break;
673 case OControlElement::FILE: pServiceName
= "com.sun.star.form.component.FileControl"; break;
674 case OControlElement::FORMATTED_TEXT
: pServiceName
= "com.sun.star.form.component.FormattedField"; break;
675 case OControlElement::FIXED_TEXT
: pServiceName
= "com.sun.star.form.component.FixedText"; break;
676 case OControlElement::COMBOBOX
: pServiceName
= "com.sun.star.form.component.ComboBox"; break;
677 case OControlElement::LISTBOX
: pServiceName
= "com.sun.star.form.component.ListBox"; break;
678 case OControlElement::BUTTON
: pServiceName
= "com.sun.star.form.component.CommandButton"; break;
679 case OControlElement::IMAGE
: pServiceName
= "com.sun.star.form.component.ImageButton"; break;
680 case OControlElement::CHECKBOX
: pServiceName
= "com.sun.star.form.component.CheckBox"; break;
681 case OControlElement::RADIO
: pServiceName
= "com.sun.star.form.component.RadioButton"; break;
682 case OControlElement::FRAME
: pServiceName
= "com.sun.star.form.component.GroupBox"; break;
683 case OControlElement::IMAGE_FRAME
: pServiceName
= "com.sun.star.form.component.DatabaseImageControl"; break;
684 case OControlElement::HIDDEN
: pServiceName
= "com.sun.star.form.component.HiddenControl"; break;
685 case OControlElement::GRID
: pServiceName
= "com.sun.star.form.component.GridControl"; break;
686 case OControlElement::VALUERANGE
: pServiceName
= "com.sun.star.form.component.ScrollBar"; break;
687 case OControlElement::TIME
: pServiceName
= "com.sun.star.form.component.TimeField"; break;
688 case OControlElement::DATE
: pServiceName
= "com.sun.star.form.component.DateField"; break;
691 if ( pServiceName
!= nullptr )
692 return OUString::createFromAscii( pServiceName
);
696 void OControlImport::addOuterAttributes(const Reference
< XAttributeList
>& _rxOuterAttribs
)
698 OSL_ENSURE(!m_xOuterAttributes
.is(), "OControlImport::addOuterAttributes: already have these attributes!");
699 m_xOuterAttributes
= _rxOuterAttribs
;
702 bool OControlImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
704 static const sal_Char
* pLinkedCellAttributeName
= OAttributeMetaData::getBindingAttributeName(BAFlags::LinkedCell
);
706 if (IsXMLToken(_rLocalName
, XML_ID
))
707 { // it's the control id
708 if (XML_NAMESPACE_XML
== _nNamespaceKey
)
710 m_sControlId
= _rValue
;
712 else if (XML_NAMESPACE_FORM
== _nNamespaceKey
)
714 if (m_sControlId
.isEmpty())
716 m_sControlId
= _rValue
;
722 if ( _rLocalName
.equalsAscii( pLinkedCellAttributeName
) )
723 { // it's the address of a spreadsheet cell
724 m_sBoundCellAddress
= _rValue
;
728 if ( _nNamespaceKey
== XML_NAMESPACE_XFORMS
&& IsXMLToken( _rLocalName
, XML_BIND
) )
730 m_sBindingID
= _rValue
;
734 if ( _nNamespaceKey
== XML_NAMESPACE_FORM
&& IsXMLToken( _rLocalName
, XML_XFORMS_LIST_SOURCE
) )
736 m_sListBindingID
= _rValue
;
740 if ( ( ( _nNamespaceKey
== XML_NAMESPACE_FORM
)
741 && IsXMLToken( _rLocalName
, XML_XFORMS_SUBMISSION
)
743 || ( ( _nNamespaceKey
== XML_NAMESPACE_XFORMS
)
744 && IsXMLToken( _rLocalName
, XML_SUBMISSION
)
748 m_sSubmissionID
= _rValue
;
752 if ( OElementImport::tryGenericAttribute( _nNamespaceKey
, _rLocalName
, _rValue
) )
755 static const sal_Char
* pValueAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Value
);
756 static const sal_Char
* pCurrentValueAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCAFlags::CurrentValue
);
757 static const sal_Char
* pMinValueAttributeName
= OAttributeMetaData::getSpecialAttributeName(SCAFlags::MinValue
);
758 static const sal_Char
* pMaxValueAttributeName
= OAttributeMetaData::getSpecialAttributeName(SCAFlags::MaxValue
);
759 static const sal_Char
* pRepeatDelayAttributeName
= OAttributeMetaData::getSpecialAttributeName( SCAFlags::RepeatDelay
);
761 sal_Int32 nHandle
= -1;
762 if ( _rLocalName
.equalsAscii( pValueAttributeName
) )
763 nHandle
= PROPID_VALUE
;
764 else if ( _rLocalName
.equalsAscii( pCurrentValueAttributeName
) )
765 nHandle
= PROPID_CURRENT_VALUE
;
766 else if ( _rLocalName
.equalsAscii( pMinValueAttributeName
) )
767 nHandle
= PROPID_MIN_VALUE
;
768 else if ( _rLocalName
.equalsAscii( pMaxValueAttributeName
) )
769 nHandle
= PROPID_MAX_VALUE
;
772 // for the moment, simply remember the name and the value
774 aProp
.Name
= _rLocalName
;
775 aProp
.Handle
= nHandle
;
776 aProp
.Value
<<= _rValue
;
777 m_aValueProperties
.push_back(aProp
);
781 if ( _rLocalName
.equalsAscii( pRepeatDelayAttributeName
) )
783 util::Duration aDuration
;
784 if (::sax::Converter::convertDuration(aDuration
, _rValue
))
787 aProp
.Name
= PROPERTY_REPEAT_DELAY
;
788 sal_Int32
const nMS
=
789 ((aDuration
.Hours
* 60 + aDuration
.Minutes
) * 60
790 + aDuration
.Seconds
) * 1000 + aDuration
.NanoSeconds
/1000000;
793 implPushBackPropertyValue(aProp
);
798 return OElementImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
801 void OControlImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
803 css::uno::Reference
< css::xml::sax::XAttributeList
> xAttributes
;
804 if( m_xOuterAttributes
.is() )
806 // merge the attribute lists
807 OAttribListMerger
* pMerger
= new OAttribListMerger
;
809 pMerger
->addList(_rxAttrList
);
810 // and the ones of our enclosing element
811 pMerger
->addList(m_xOuterAttributes
);
812 xAttributes
= pMerger
;
816 xAttributes
= _rxAttrList
;
819 // let the base class handle all the attributes
820 OElementImport::StartElement(xAttributes
);
822 if ( !m_aValueProperties
.empty() && m_xElement
.is())
824 // get the property set info
827 OSL_FAIL("OControlImport::StartElement: no PropertySetInfo!");
831 const sal_Char
* pValueProperty
= nullptr;
832 const sal_Char
* pCurrentValueProperty
= nullptr;
833 const sal_Char
* pMinValueProperty
= nullptr;
834 const sal_Char
* pMaxValueProperty
= nullptr;
836 bool bRetrievedValues
= false;
837 bool bRetrievedValueLimits
= false;
839 // get the class id of our element
840 sal_Int16 nClassId
= FormComponentType::CONTROL
;
841 m_xElement
->getPropertyValue(PROPERTY_CLASSID
) >>= nClassId
;
843 // translate the value properties we collected in handleAttributes
844 PropertyValueArray::iterator aEnd
= m_aValueProperties
.end();
845 for ( PropertyValueArray::iterator aValueProps
= m_aValueProperties
.begin();
850 bool bSuccess
= false;
851 switch (aValueProps
->Handle
)
854 case PROPID_CURRENT_VALUE
:
856 // get the property names
857 if (!bRetrievedValues
)
859 getValuePropertyNames(m_eElementType
, nClassId
, pCurrentValueProperty
, pValueProperty
);
860 if ( !pCurrentValueProperty
&& !pValueProperty
)
862 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value property names!" );
866 bRetrievedValues
= true;
868 if ( PROPID_VALUE
== aValueProps
->Handle
&& !pValueProperty
)
870 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a value property!");
874 if ( PROPID_CURRENT_VALUE
== aValueProps
->Handle
&& !pCurrentValueProperty
)
876 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a current-value property!");
881 if (PROPID_VALUE
== aValueProps
->Handle
)
882 aValueProps
->Name
= OUString::createFromAscii(pValueProperty
);
884 aValueProps
->Name
= OUString::createFromAscii(pCurrentValueProperty
);
888 case PROPID_MIN_VALUE
:
889 case PROPID_MAX_VALUE
:
891 // get the property names
892 if (!bRetrievedValueLimits
)
894 getValueLimitPropertyNames(nClassId
, pMinValueProperty
, pMaxValueProperty
);
895 if ( !pMinValueProperty
|| !pMaxValueProperty
)
897 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value limit property names!" );
901 bRetrievedValueLimits
= true;
903 OSL_ENSURE((PROPID_MIN_VALUE
!= aValueProps
->Handle
) || pMinValueProperty
,
904 "OControlImport::StartElement: the control does not have a value property!");
905 OSL_ENSURE((PROPID_MAX_VALUE
!= aValueProps
->Handle
) || pMaxValueProperty
,
906 "OControlImport::StartElement: the control does not have a current-value property!");
909 if (PROPID_MIN_VALUE
== aValueProps
->Handle
)
910 aValueProps
->Name
= OUString::createFromAscii(pMinValueProperty
);
912 aValueProps
->Name
= OUString::createFromAscii(pMaxValueProperty
);
921 // translate the value
922 implTranslateValueProperty(m_xInfo
, *aValueProps
);
923 // add the property to the base class' array
924 implPushBackPropertyValue(*aValueProps
);
929 void OControlImport::implTranslateValueProperty(const Reference
< XPropertySetInfo
>& _rxPropInfo
,
930 PropertyValue
& _rPropValue
)
932 OSL_ENSURE(_rxPropInfo
->hasPropertyByName(_rPropValue
.Name
),
933 "OControlImport::implTranslateValueProperty: invalid property name!");
935 // retrieve the type of the property
936 Property aProp
= _rxPropInfo
->getPropertyByName(_rPropValue
.Name
);
937 // the untranslated string value as read in handleAttribute
939 bool bSuccess
= _rPropValue
.Value
>>= sValue
;
940 OSL_ENSURE(bSuccess
, "OControlImport::implTranslateValueProperty: supposed to be called with non-translated string values!");
942 if (TypeClass_ANY
== aProp
.Type
.getTypeClass())
944 // we have exactly 2 properties where this type class is allowed:
946 _rPropValue
.Name
!= PROPERTY_EFFECTIVE_VALUE
947 && _rPropValue
.Name
!= PROPERTY_EFFECTIVE_DEFAULT
,
948 "OControlImport::implTranslateValueProperty: invalid property type/name combination!");
950 // Both properties are allowed to have a double or a string value,
951 // so first try to convert the string into a number
953 if (::sax::Converter::convertDouble(nValue
, sValue
))
954 _rPropValue
.Value
<<= nValue
;
956 _rPropValue
.Value
<<= sValue
;
959 _rPropValue
.Value
= PropertyConversion::convertString(aProp
.Type
, sValue
);
962 void OControlImport::EndElement()
964 OSL_ENSURE(m_xElement
.is(), "OControlImport::EndElement: invalid control!");
965 if ( !m_xElement
.is() )
968 // register our control with its id
969 if (!m_sControlId
.isEmpty())
970 m_rFormImport
.registerControlId(m_xElement
, m_sControlId
);
971 // it's allowed to have no control id. In this case we're importing a column
973 // one more pre-work to do:
974 // when we set default values, then by definition the respective value is set
975 // to this default value, too. This means if the sequence contains for example
976 // a DefaultText value, then the Text will be affected by this, too.
977 // In case the Text is not part of the property sequence (or occurs _before_
978 // the DefaultText, which can happen for other value/default-value property names),
979 // this means that the Text (the value property) is incorrectly imported.
981 bool bRestoreValuePropertyValue
= false;
982 Any aValuePropertyValue
;
984 sal_Int16 nClassId
= FormComponentType::CONTROL
;
987 // get the class id of our element
988 m_xElement
->getPropertyValue(PROPERTY_CLASSID
) >>= nClassId
;
990 catch( const Exception
& )
992 OSL_FAIL( "OControlImport::EndElement: caught an exception while retrieving the class id!" );
993 DBG_UNHANDLED_EXCEPTION();
996 const sal_Char
* pValueProperty
= nullptr;
997 const sal_Char
* pDefaultValueProperty
= nullptr;
998 getRuntimeValuePropertyNames(m_eElementType
, nClassId
, pValueProperty
, pDefaultValueProperty
);
999 if ( pDefaultValueProperty
&& pValueProperty
)
1001 bool bNonDefaultValuePropertyValue
= false;
1002 // is the "value property" part of the sequence?
1004 // look up this property in our sequence
1005 PropertyValueArray::iterator aEnd
= m_aValues
.end();
1006 for ( PropertyValueArray::iterator aCheck
= m_aValues
.begin();
1011 if ( aCheck
->Name
.equalsAscii( pDefaultValueProperty
) )
1012 bRestoreValuePropertyValue
= true;
1013 else if ( aCheck
->Name
.equalsAscii( pValueProperty
) )
1015 bNonDefaultValuePropertyValue
= true;
1016 // we need to restore the value property we found here, nothing else
1017 aValuePropertyValue
= aCheck
->Value
;
1021 if ( bRestoreValuePropertyValue
&& !bNonDefaultValuePropertyValue
)
1023 // found it -> need to remember (and restore) the "value property value", which is not set explicitly
1026 aValuePropertyValue
= m_xElement
->getPropertyValue( OUString::createFromAscii( pValueProperty
) );
1028 catch( const Exception
& )
1030 OSL_FAIL( "OControlImport::EndElement: caught an exception while retrieving the current value property!" );
1031 DBG_UNHANDLED_EXCEPTION();
1036 // let the base class set all the values
1037 OElementImport::EndElement();
1039 // restore the "value property value", if necessary
1040 if ( bRestoreValuePropertyValue
&& pValueProperty
)
1044 m_xElement
->setPropertyValue( OUString::createFromAscii( pValueProperty
), aValuePropertyValue
);
1046 catch( const Exception
& )
1048 OSL_FAIL( "OControlImport::EndElement: caught an exception while restoring the value property!" );
1049 DBG_UNHANDLED_EXCEPTION();
1053 // the external cell binding, if applicable
1054 if ( m_xElement
.is() && !m_sBoundCellAddress
.isEmpty() )
1055 doRegisterCellValueBinding( m_sBoundCellAddress
);
1057 // XForms binding, if applicable
1058 if ( m_xElement
.is() && !m_sBindingID
.isEmpty() )
1059 doRegisterXFormsValueBinding( m_sBindingID
);
1061 // XForms list binding, if applicable
1062 if ( m_xElement
.is() && !m_sListBindingID
.isEmpty() )
1063 doRegisterXFormsListBinding( m_sListBindingID
);
1065 // XForms submission, if applicable
1066 if ( m_xElement
.is() && !m_sSubmissionID
.isEmpty() )
1067 doRegisterXFormsSubmission( m_sSubmissionID
);
1070 void OControlImport::doRegisterCellValueBinding( const OUString
& _rBoundCellAddress
)
1072 OSL_PRECOND( m_xElement
.is(), "OControlImport::doRegisterCellValueBinding: invalid element!" );
1073 OSL_PRECOND( !_rBoundCellAddress
.isEmpty(),
1074 "OControlImport::doRegisterCellValueBinding: invalid address!" );
1076 m_rContext
.registerCellValueBinding( m_xElement
, _rBoundCellAddress
);
1079 void OControlImport::doRegisterXFormsValueBinding( const OUString
& _rBindingID
)
1081 OSL_PRECOND( m_xElement
.is(), "need element" );
1082 OSL_PRECOND( !_rBindingID
.isEmpty(), "binding ID is not valid" );
1084 m_rContext
.registerXFormsValueBinding( m_xElement
, _rBindingID
);
1087 void OControlImport::doRegisterXFormsListBinding( const OUString
& _rBindingID
)
1089 OSL_PRECOND( m_xElement
.is(), "need element" );
1090 OSL_PRECOND( !_rBindingID
.isEmpty(), "binding ID is not valid" );
1092 m_rContext
.registerXFormsListBinding( m_xElement
, _rBindingID
);
1095 void OControlImport::doRegisterXFormsSubmission( const OUString
& _rSubmissionID
)
1097 OSL_PRECOND( m_xElement
.is(), "need element" );
1098 OSL_PRECOND( !_rSubmissionID
.isEmpty(), "binding ID is not valid" );
1100 m_rContext
.registerXFormsSubmission( m_xElement
, _rSubmissionID
);
1103 Reference
< XPropertySet
> OControlImport::createElement()
1105 const Reference
<XPropertySet
> xPropSet
= OElementImport::createElement();
1106 if ( xPropSet
.is() )
1108 m_xInfo
= xPropSet
->getPropertySetInfo();
1109 if ( m_xInfo
.is() && m_xInfo
->hasPropertyByName(PROPERTY_ALIGN
) )
1112 xPropSet
->setPropertyValue(PROPERTY_ALIGN
,aValue
);
1118 //= OImagePositionImport
1119 OImagePositionImport::OImagePositionImport( OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1120 sal_uInt16 _nPrefix
, const OUString
& _rName
, const Reference
< XNameContainer
>& _rxParentContainer
,
1121 OControlElement::ElementType _eType
)
1122 :OControlImport( _rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1123 ,m_nImagePosition( -1 )
1125 ,m_bHaveImagePosition( false )
1129 bool OImagePositionImport::handleAttribute( sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
,
1130 const OUString
& _rValue
)
1132 if ( _rLocalName
== GetXMLToken( XML_IMAGE_POSITION
) )
1134 OSL_VERIFY( PropertyConversion::convertString(
1135 cppu::UnoType
<decltype(m_nImagePosition
)>::get(),
1136 _rValue
, OEnumMapper::getEnumMap( OEnumMapper::epImagePosition
)
1137 ) >>= m_nImagePosition
);
1138 m_bHaveImagePosition
= true;
1142 if ( _rLocalName
== GetXMLToken( XML_IMAGE_ALIGN
) )
1144 OSL_VERIFY( PropertyConversion::convertString(
1145 cppu::UnoType
<decltype(m_nImageAlign
)>::get(),
1146 _rValue
, OEnumMapper::getEnumMap( OEnumMapper::epImageAlign
)
1147 ) >>= m_nImageAlign
);
1151 return OControlImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1154 void OImagePositionImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1156 OControlImport::StartElement( _rxAttrList
);
1158 if ( m_bHaveImagePosition
)
1160 sal_Int16 nUnoImagePosition
= ImagePosition::Centered
;
1161 if ( m_nImagePosition
>= 0 )
1163 OSL_ENSURE( ( m_nImagePosition
<= 3 ) && ( m_nImageAlign
>= 0 ) && ( m_nImageAlign
< 3 ),
1164 "OImagePositionImport::StartElement: unknown image align and/or position!" );
1165 nUnoImagePosition
= m_nImagePosition
* 3 + m_nImageAlign
;
1168 PropertyValue aImagePosition
;
1169 aImagePosition
.Name
= PROPERTY_IMAGE_POSITION
;
1170 aImagePosition
.Value
<<= nUnoImagePosition
;
1171 implPushBackPropertyValue( aImagePosition
);
1175 //= OReferredControlImport
1176 OReferredControlImport::OReferredControlImport(
1177 OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1178 const Reference
< XNameContainer
>& _rxParentContainer
,
1179 OControlElement::ElementType
)
1180 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
)
1184 void OReferredControlImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1186 OControlImport::StartElement(_rxAttrList
);
1188 // the base class should have created the control, so we can register it
1189 if ( !m_sReferringControls
.isEmpty() )
1190 m_rFormImport
.registerControlReferences(m_xElement
, m_sReferringControls
);
1193 bool OReferredControlImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
,
1194 const OUString
& _rValue
)
1196 static const char * s_sReferenceAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCAFlags::For
);
1197 if (_rLocalName
.equalsAscii(s_sReferenceAttributeName
))
1199 m_sReferringControls
= _rValue
;
1202 return OControlImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1206 OPasswordImport::OPasswordImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1207 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1208 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1212 bool OPasswordImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1214 static const char * s_sEchoCharAttributeName
= OAttributeMetaData::getSpecialAttributeName(SCAFlags::EchoChar
);
1215 if (_rLocalName
.equalsAscii(s_sEchoCharAttributeName
))
1217 // need a special handling for the EchoChar property
1218 PropertyValue aEchoChar
;
1219 aEchoChar
.Name
= PROPERTY_ECHOCHAR
;
1220 OSL_ENSURE(_rValue
.getLength() == 1, "OPasswordImport::handleAttribute: invalid echo char attribute!");
1221 // we ourself should not have written values other than of length 1
1222 if (_rValue
.getLength() >= 1)
1223 aEchoChar
.Value
<<= (sal_Int16
)_rValue
[0];
1225 aEchoChar
.Value
<<= (sal_Int16
)0;
1226 implPushBackPropertyValue(aEchoChar
);
1229 return OControlImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1233 ORadioImport::ORadioImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1234 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1235 :OImagePositionImport( _rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1239 bool ORadioImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1241 // need special handling for the State & CurrentState properties:
1242 // they're stored as booleans, but expected to be int16 properties
1243 static const sal_Char
* pCurrentSelectedAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCAFlags::CurrentSelected
);
1244 static const sal_Char
* pSelectedAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Selected
);
1245 if ( _rLocalName
.equalsAscii( pCurrentSelectedAttributeName
)
1246 || _rLocalName
.equalsAscii( pSelectedAttributeName
)
1249 const OAttribute2Property::AttributeAssignment
* pProperty
= m_rContext
.getAttributeMap().getAttributeTranslation(_rLocalName
);
1250 OSL_ENSURE(pProperty
, "ORadioImport::handleAttribute: invalid property map!");
1253 const Any
aBooleanValue( PropertyConversion::convertString(pProperty
->aPropertyType
, _rValue
, pProperty
->pEnumMap
) );
1255 // create and store a new PropertyValue
1256 PropertyValue aNewValue
;
1257 aNewValue
.Name
= pProperty
->sPropertyName
;
1258 aNewValue
.Value
<<= (sal_Int16
)::cppu::any2bool(aBooleanValue
);
1260 implPushBackPropertyValue(aNewValue
);
1264 return OImagePositionImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1267 //= OURLReferenceImport
1268 OURLReferenceImport::OURLReferenceImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1269 const Reference
< XNameContainer
>& _rxParentContainer
,
1270 OControlElement::ElementType _eType
)
1271 :OImagePositionImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1275 bool OURLReferenceImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1277 static const sal_Char
* s_pTargetLocationAttributeName
= OAttributeMetaData::getCommonControlAttributeName( CCAFlags::TargetLocation
);
1278 static const sal_Char
* s_pImageDataAttributeName
= OAttributeMetaData::getCommonControlAttributeName( CCAFlags::ImageData
);
1280 // need to make the URL absolute if
1281 // * it's the image-data attribute
1282 // * it's the target-location attribute, and we're dealing with an object which has the respective property
1283 bool bMakeAbsolute
=
1284 _rLocalName
.equalsAscii( s_pImageDataAttributeName
)
1285 || ( _rLocalName
.equalsAscii( s_pTargetLocationAttributeName
)
1286 && ( ( OControlElement::BUTTON
== m_eElementType
)
1287 || ( OControlElement::IMAGE
== m_eElementType
)
1291 if ( bMakeAbsolute
&& !_rValue
.isEmpty() )
1293 // make a global URL out of the local one
1294 OUString sAdjustedValue
;
1295 // only resolve image related url
1296 // we don't want say form url targets to be resolved
1297 // using ResolveGraphicObjectURL
1298 if ( _rLocalName
.equalsAscii( s_pImageDataAttributeName
) )
1299 sAdjustedValue
= m_rContext
.getGlobalContext().ResolveGraphicObjectURL( _rValue
, false );
1301 sAdjustedValue
= m_rContext
.getGlobalContext().GetAbsoluteReference( _rValue
);
1302 return OImagePositionImport::handleAttribute( _nNamespaceKey
, _rLocalName
, sAdjustedValue
);
1305 return OImagePositionImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1309 OButtonImport::OButtonImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1310 const Reference
< XNameContainer
>& _rxParentContainer
,
1311 OControlElement::ElementType _eType
)
1312 :OURLReferenceImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1314 enableTrackAttributes();
1317 void OButtonImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1319 OURLReferenceImport::StartElement(_rxAttrList
);
1321 // handle the target-frame attribute
1322 simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetFrame
), PROPERTY_TARGETFRAME
, "_blank");
1325 //= OValueRangeImport
1326 OValueRangeImport::OValueRangeImport( OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1327 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1328 :OControlImport( _rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1329 ,m_nStepSizeValue( 1 )
1334 bool OValueRangeImport::handleAttribute( sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1336 if ( _rLocalName
.equalsAscii( OAttributeMetaData::getSpecialAttributeName( SCAFlags::StepSize
) ) )
1338 ::sax::Converter::convertNumber( m_nStepSizeValue
, _rValue
);
1341 return OControlImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1344 void OValueRangeImport::StartElement( const Reference
< XAttributeList
>& _rxAttrList
)
1346 OControlImport::StartElement( _rxAttrList
);
1350 if ( m_xInfo
->hasPropertyByName( PROPERTY_SPIN_INCREMENT
) )
1351 m_xElement
->setPropertyValue( PROPERTY_SPIN_INCREMENT
, makeAny( m_nStepSizeValue
) );
1352 else if ( m_xInfo
->hasPropertyByName( PROPERTY_LINE_INCREMENT
) )
1353 m_xElement
->setPropertyValue( PROPERTY_LINE_INCREMENT
, makeAny( m_nStepSizeValue
) );
1358 OTextLikeImport::OTextLikeImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1359 const Reference
< XNameContainer
>& _rxParentContainer
,
1360 OControlElement::ElementType _eType
)
1361 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1362 ,m_bEncounteredTextPara( false )
1364 enableTrackAttributes();
1367 SvXMLImportContext
* OTextLikeImport::CreateChildContext( sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
1368 const Reference
< XAttributeList
>& _rxAttrList
)
1370 if ( ( XML_NAMESPACE_TEXT
== _nPrefix
) && _rLocalName
.equalsIgnoreAsciiCase("p") )
1372 OSL_ENSURE( m_eElementType
== OControlElement::TEXT_AREA
,
1373 "OTextLikeImport::CreateChildContext: text paragraphs in a non-text-area?" );
1375 if ( m_eElementType
== OControlElement::TEXT_AREA
)
1377 Reference
< XText
> xTextElement( m_xElement
, UNO_QUERY
);
1378 if ( xTextElement
.is() )
1380 rtl::Reference
< XMLTextImportHelper
> xTextImportHelper( m_rContext
.getGlobalContext().GetTextImport() );
1382 if ( !m_xCursor
.is() )
1384 m_xOldCursor
= xTextImportHelper
->GetCursor();
1385 m_xCursor
= xTextElement
->createTextCursor();
1387 if ( m_xCursor
.is() )
1388 xTextImportHelper
->SetCursor( m_xCursor
);
1390 if ( m_xCursor
.is() )
1392 m_bEncounteredTextPara
= true;
1393 return xTextImportHelper
->CreateTextChildContext( m_rContext
.getGlobalContext(), _nPrefix
, _rLocalName
, _rxAttrList
);
1398 // in theory, we could accumulate all the text portions (without formatting),
1399 // and set it as Text property at the model ...
1404 return OControlImport::CreateChildContext( _nPrefix
, _rLocalName
, _rxAttrList
);
1407 void OTextLikeImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1409 OControlImport::StartElement(_rxAttrList
);
1411 // handle the convert-empty-to-null attribute, whose default is different from the property default
1412 // unfortunately, different classes are imported by this class ('cause they're represented by the
1413 // same XML element), though not all of them know this property.
1414 // So we have to do a check ...
1415 if (m_xElement
.is() && m_xInfo
.is() && m_xInfo
->hasPropertyByName(PROPERTY_EMPTY_IS_NULL
) )
1416 simulateDefaultedAttribute(OAttributeMetaData::getDatabaseAttributeName(DAFlags::ConvertEmpty
), PROPERTY_EMPTY_IS_NULL
, "false");
1419 struct EqualHandle
: public ::std::unary_function
< PropertyValue
, bool >
1421 const sal_Int32 m_nHandle
;
1422 explicit EqualHandle( sal_Int32 _nHandle
) : m_nHandle( _nHandle
) { }
1424 inline bool operator()( const PropertyValue
& _rProp
)
1426 return _rProp
.Handle
== m_nHandle
;
1430 void OTextLikeImport::removeRedundantCurrentValue()
1432 if ( m_bEncounteredTextPara
)
1434 // In case the text is written in the text:p elements, we need to ignore what we read as
1435 // current-value attribute, since it's redundant.
1436 // fortunately, OElementImport tagged the value property with the PROPID_CURRENT_VALUE
1437 // handle, so we do not need to determine the name of our value property here
1438 // (normally, it should be "Text", since no other controls than the edit field should
1439 // have the text:p elements)
1440 PropertyValueArray::iterator aValuePropertyPos
= ::std::find_if(
1443 EqualHandle( PROPID_CURRENT_VALUE
)
1445 if ( aValuePropertyPos
!= m_aValues
.end() )
1447 OSL_ENSURE( aValuePropertyPos
->Name
== PROPERTY_TEXT
, "OTextLikeImport::EndElement: text:p was present, but our value property is *not* 'Text'!" );
1448 if ( aValuePropertyPos
->Name
== PROPERTY_TEXT
)
1451 aValuePropertyPos
+ 1,
1455 m_aValues
.resize( m_aValues
.size() - 1 );
1459 // additionally, we need to set the "RichText" property of our element to sal_True
1460 // (the presence of the text:p is used as indicator for the value of the RichText property)
1461 bool bHasRichTextProperty
= false;
1463 bHasRichTextProperty
= m_xInfo
->hasPropertyByName( PROPERTY_RICH_TEXT
);
1464 OSL_ENSURE( bHasRichTextProperty
, "OTextLikeImport::EndElement: text:p, but no rich text control?" );
1465 if ( bHasRichTextProperty
)
1466 m_xElement
->setPropertyValue( PROPERTY_RICH_TEXT
, makeAny( true ) );
1468 // Note that we do *not* set the RichText property (in case our element has one) to sal_False here
1469 // since this is the default of this property, anyway.
1472 struct EqualName
: public ::std::unary_function
< PropertyValue
, bool >
1474 const OUString m_sName
;
1475 explicit EqualName( const OUString
& _rName
) : m_sName( _rName
) { }
1477 inline bool operator()( const PropertyValue
& _rProp
)
1479 return _rProp
.Name
== m_sName
;
1483 void OTextLikeImport::adjustDefaultControlProperty()
1485 // In OpenOffice.org 2.0, we changed the implementation of the css.form.component.TextField (the model of a text field control),
1486 // so that it now uses another default control. So if we encounter a text field where the *old* default
1487 // control property is writing, we are not allowed to use it
1488 PropertyValueArray::iterator aDefaultControlPropertyPos
= ::std::find_if(
1491 EqualName( OUString( "DefaultControl" ) )
1493 if ( aDefaultControlPropertyPos
!= m_aValues
.end() )
1495 OUString sDefaultControl
;
1496 OSL_VERIFY( aDefaultControlPropertyPos
->Value
>>= sDefaultControl
);
1497 if ( sDefaultControl
== "stardiv.one.form.control.Edit" )
1499 // complete remove this property value from the array. Today's "default value" of the "DefaultControl"
1500 // property is sufficient
1502 aDefaultControlPropertyPos
+ 1,
1504 aDefaultControlPropertyPos
1506 m_aValues
.resize( m_aValues
.size() - 1 );
1511 void OTextLikeImport::EndElement()
1513 removeRedundantCurrentValue();
1514 adjustDefaultControlProperty();
1516 // let the base class do the stuff
1517 OControlImport::EndElement();
1520 rtl::Reference
< XMLTextImportHelper
> xTextImportHelper( m_rContext
.getGlobalContext().GetTextImport() );
1521 if ( m_xCursor
.is() )
1523 // delete the newline which has been imported erroneously
1524 // TODO (fs): stole this code somewhere - why don't we fix the text import??
1525 m_xCursor
->gotoEnd( false );
1526 m_xCursor
->goLeft( 1, true );
1527 m_xCursor
->setString( OUString() );
1530 xTextImportHelper
->ResetCursor();
1533 if ( m_xOldCursor
.is() )
1534 xTextImportHelper
->SetCursor( m_xOldCursor
);
1538 //= OListAndComboImport
1539 OListAndComboImport::OListAndComboImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1540 const Reference
< XNameContainer
>& _rxParentContainer
,
1541 OControlElement::ElementType _eType
)
1542 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1543 ,m_nEmptyListItems( 0 )
1544 ,m_nEmptyValueItems( 0 )
1545 ,m_bEncounteredLSAttrib( false )
1546 ,m_bLinkWithIndexes( false )
1548 if (OControlElement::COMBOBOX
== m_eElementType
)
1549 enableTrackAttributes();
1552 SvXMLImportContext
* OListAndComboImport::CreateChildContext(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
1553 const Reference
< XAttributeList
>& _rxAttrList
)
1555 // is it the "option" sub tag of a listbox ?
1556 static const char s_sOptionElementName
[] = "option";
1557 if (s_sOptionElementName
== _rLocalName
)
1558 return new OListOptionImport(GetImport(), _nPrefix
, _rLocalName
, this);
1560 // is it the "item" sub tag of a combobox ?
1561 static const char s_sItemElementName
[] = "item";
1562 if (s_sItemElementName
== _rLocalName
)
1563 return new OComboItemImport(GetImport(), _nPrefix
, _rLocalName
, this);
1566 return OControlImport::CreateChildContext(_nPrefix
, _rLocalName
, _rxAttrList
);
1569 void OListAndComboImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1571 m_bLinkWithIndexes
= false;
1573 OControlImport::StartElement(_rxAttrList
);
1575 if (OControlElement::COMBOBOX
== m_eElementType
)
1577 // for the auto-completion
1578 // the attribute default does not equal the property default, so in case we did not read this attribute,
1579 // we have to simulate it
1580 simulateDefaultedAttribute( OAttributeMetaData::getSpecialAttributeName( SCAFlags::AutoCompletion
), PROPERTY_AUTOCOMPLETE
, "false");
1582 // same for the convert-empty-to-null attribute, which's default is different from the property default
1583 simulateDefaultedAttribute( OAttributeMetaData::getDatabaseAttributeName( DAFlags::ConvertEmpty
), PROPERTY_EMPTY_IS_NULL
, "false");
1587 void OListAndComboImport::EndElement()
1589 // append the list source property the properties sequence of our importer
1590 // the string item list
1591 PropertyValue aItemList
;
1592 aItemList
.Name
= PROPERTY_STRING_ITEM_LIST
;
1593 aItemList
.Value
<<= m_aListSource
;
1594 implPushBackPropertyValue(aItemList
);
1596 if (OControlElement::LISTBOX
== m_eElementType
)
1598 OSL_ENSURE((m_aListSource
.getLength() + m_nEmptyListItems
) == (m_aValueList
.getLength() + m_nEmptyValueItems
),
1599 "OListAndComboImport::EndElement: inconsistence between labels and values!");
1601 if ( !m_bEncounteredLSAttrib
)
1603 // the value sequence
1604 PropertyValue aValueList
;
1605 aValueList
.Name
= PROPERTY_LISTSOURCE
;
1606 aValueList
.Value
<<= m_aValueList
;
1607 implPushBackPropertyValue(aValueList
);
1610 // the select sequence
1611 PropertyValue aSelected
;
1612 aSelected
.Name
= PROPERTY_SELECT_SEQ
;
1613 aSelected
.Value
<<= m_aSelectedSeq
;
1614 implPushBackPropertyValue(aSelected
);
1616 // the default select sequence
1617 PropertyValue aDefaultSelected
;
1618 aDefaultSelected
.Name
= PROPERTY_DEFAULT_SELECT_SEQ
;
1619 aDefaultSelected
.Value
<<= m_aDefaultSelectedSeq
;
1620 implPushBackPropertyValue(aDefaultSelected
);
1623 OControlImport::EndElement();
1625 // the external list source, if applicable
1626 if ( m_xElement
.is() && !m_sCellListSource
.isEmpty() )
1627 m_rContext
.registerCellRangeListSource( m_xElement
, m_sCellListSource
);
1630 void OListAndComboImport::doRegisterCellValueBinding( const OUString
& _rBoundCellAddress
)
1632 OUString
sBoundCellAddress( _rBoundCellAddress
);
1633 if ( m_bLinkWithIndexes
)
1635 // This is a HACK. We register a string which is no valid address, but allows
1636 // (somewhere else) to determine that a non-standard binding should be created.
1637 // This hack is acceptable for OOo 1.1.1, since the file format for value
1638 // bindings of form controls is to be changed afterwards, anyway.
1639 sBoundCellAddress
+= ":index";
1642 OControlImport::doRegisterCellValueBinding( sBoundCellAddress
);
1645 bool OListAndComboImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1647 static const sal_Char
* pListSourceAttributeName
= OAttributeMetaData::getDatabaseAttributeName(DAFlags::ListSource
);
1648 if ( _rLocalName
.equalsAscii(pListSourceAttributeName
) )
1650 PropertyValue aListSource
;
1651 aListSource
.Name
= PROPERTY_LISTSOURCE
;
1653 // it's the ListSource attribute
1654 m_bEncounteredLSAttrib
= true;
1655 if ( OControlElement::COMBOBOX
== m_eElementType
)
1657 aListSource
.Value
<<= _rValue
;
1661 // a listbox which has a list-source attribute must have a list-source-type of something
1662 // not equal to ValueList.
1663 // In this case, the list-source value is simply the one and only element of the ListSource property.
1664 Sequence
<OUString
> aListSourcePropValue
{ _rValue
};
1665 aListSource
.Value
<<= aListSourcePropValue
;
1668 implPushBackPropertyValue( aListSource
);
1672 if ( _rLocalName
.equalsAscii( OAttributeMetaData::getBindingAttributeName( BAFlags::ListCellRange
) ) )
1674 m_sCellListSource
= _rValue
;
1678 if ( _rLocalName
.equalsAscii( OAttributeMetaData::getBindingAttributeName( BAFlags::ListLinkingType
) ) )
1680 sal_Int16 nLinkageType
= 0;
1681 PropertyConversion::convertString(
1682 ::cppu::UnoType
<sal_Int16
>::get(),
1684 OEnumMapper::getEnumMap( OEnumMapper::epListLinkageType
)
1687 m_bLinkWithIndexes
= ( nLinkageType
!= 0 );
1691 return OControlImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1694 void OListAndComboImport::implPushBackLabel(const OUString
& _rLabel
)
1696 OSL_ENSURE(!m_nEmptyListItems
, "OListAndComboImport::implPushBackValue: label list is already done!");
1697 if (!m_nEmptyListItems
)
1698 pushBackSequenceElement(m_aListSource
, _rLabel
);
1701 void OListAndComboImport::implPushBackValue(const OUString
& _rValue
)
1703 OSL_ENSURE(!m_nEmptyValueItems
, "OListAndComboImport::implPushBackValue: value list is already done!");
1704 if (!m_nEmptyValueItems
)
1706 OSL_ENSURE( !m_bEncounteredLSAttrib
, "OListAndComboImport::implPushBackValue: invalid structure! Did you save this document with a version prior SRC641 m?" );
1707 // We already had the list-source attribute, which means that the ListSourceType is
1708 // not ValueList, which means that the ListSource should contain only one string in
1709 // the first element of the sequence
1710 // All other values in the file are invalid
1712 pushBackSequenceElement( m_aValueList
, _rValue
);
1716 void OListAndComboImport::implEmptyLabelFound()
1718 ++m_nEmptyListItems
;
1721 void OListAndComboImport::implEmptyValueFound()
1723 ++m_nEmptyValueItems
;
1726 void OListAndComboImport::implSelectCurrentItem()
1728 OSL_ENSURE((m_aListSource
.getLength() + m_nEmptyListItems
) == (m_aValueList
.getLength() + m_nEmptyValueItems
),
1729 "OListAndComboImport::implSelectCurrentItem: inconsistence between labels and values!");
1731 sal_Int16 nItemNumber
= (sal_Int16
)(m_aListSource
.getLength() - 1 + m_nEmptyListItems
);
1732 pushBackSequenceElement(m_aSelectedSeq
, nItemNumber
);
1735 void OListAndComboImport::implDefaultSelectCurrentItem()
1737 OSL_ENSURE((m_aListSource
.getLength() + m_nEmptyListItems
) == (m_aValueList
.getLength() + m_nEmptyValueItems
),
1738 "OListAndComboImport::implDefaultSelectCurrentItem: inconsistence between labels and values!");
1740 sal_Int16 nItemNumber
= (sal_Int16
)(m_aListSource
.getLength() - 1 + m_nEmptyListItems
);
1741 pushBackSequenceElement(m_aDefaultSelectedSeq
, nItemNumber
);
1744 //= OListOptionImport
1745 OListOptionImport::OListOptionImport(SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1746 const OListAndComboImportRef
& _rListBox
)
1747 :SvXMLImportContext(_rImport
, _nPrefix
, _rName
)
1748 ,m_xListBoxImport(_rListBox
)
1752 void OListOptionImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1754 // the label and the value
1755 const SvXMLNamespaceMap
& rMap
= GetImport().GetNamespaceMap();
1756 const OUString sLabelAttribute
= rMap
.GetQNameByKey(
1757 GetPrefix(), "label");
1758 const OUString sValueAttribute
= rMap
.GetQNameByKey(
1759 GetPrefix(), "value");
1761 // the label attribute
1762 OUString sValue
= _rxAttrList
->getValueByName(sLabelAttribute
);
1763 bool bNonexistentAttribute
= false;
1764 if (sValue
.isEmpty())
1765 if (_rxAttrList
->getTypeByName(sLabelAttribute
).isEmpty())
1766 // this attribute does not really exist
1767 bNonexistentAttribute
= true;
1769 if (bNonexistentAttribute
)
1770 m_xListBoxImport
->implEmptyLabelFound();
1772 m_xListBoxImport
->implPushBackLabel( sValue
);
1774 // the value attribute
1775 sValue
= _rxAttrList
->getValueByName(sValueAttribute
);
1776 bNonexistentAttribute
= false;
1777 if (sValue
.isEmpty())
1778 if (_rxAttrList
->getTypeByName(sValueAttribute
).isEmpty())
1779 // this attribute does not really exist
1780 bNonexistentAttribute
= true;
1782 if (bNonexistentAttribute
)
1783 m_xListBoxImport
->implEmptyValueFound();
1785 m_xListBoxImport
->implPushBackValue( sValue
);
1787 // the current-selected and selected
1788 const OUString sSelectedAttribute
= rMap
.GetQNameByKey(
1789 GetPrefix(), OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCAFlags::CurrentSelected
)));
1790 const OUString sDefaultSelectedAttribute
= rMap
.GetQNameByKey(
1791 GetPrefix(), OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Selected
)));
1793 // propagate the selected flag
1794 bool bSelected(false);
1795 ::sax::Converter::convertBool(bSelected
,
1796 _rxAttrList
->getValueByName(sSelectedAttribute
));
1798 m_xListBoxImport
->implSelectCurrentItem();
1800 // same for the default selected
1801 bool bDefaultSelected(false);
1802 ::sax::Converter::convertBool(bDefaultSelected
,
1803 _rxAttrList
->getValueByName(sDefaultSelectedAttribute
));
1804 if (bDefaultSelected
)
1805 m_xListBoxImport
->implDefaultSelectCurrentItem();
1807 SvXMLImportContext::StartElement(_rxAttrList
);
1810 //= OComboItemImport
1811 OComboItemImport::OComboItemImport(SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1812 const OListAndComboImportRef
& _rListBox
)
1813 :SvXMLImportContext(_rImport
, _nPrefix
, _rName
)
1814 ,m_xListBoxImport(_rListBox
)
1818 void OComboItemImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1820 const OUString sLabelAttributeName
= GetImport().GetNamespaceMap().GetQNameByKey(
1821 GetPrefix(), OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCAFlags::Label
)));
1822 m_xListBoxImport
->implPushBackLabel(_rxAttrList
->getValueByName(sLabelAttributeName
));
1824 SvXMLImportContext::StartElement(_rxAttrList
);
1827 //= OColumnWrapperImport
1828 OColumnWrapperImport::OColumnWrapperImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1829 const Reference
< XNameContainer
>& _rxParentContainer
)
1830 :SvXMLImportContext(_rImport
.getGlobalContext(), _nPrefix
, _rName
)
1831 ,m_xParentContainer(_rxParentContainer
)
1832 ,m_rFormImport(_rImport
)
1833 ,m_rEventManager(_rEventManager
)
1836 SvXMLImportContext
* OColumnWrapperImport::CreateChildContext(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
1837 const Reference
< XAttributeList
>&)
1839 OControlImport
* pReturn
= implCreateChildContext(_nPrefix
, _rLocalName
, OElementNameMap::getElementType(_rLocalName
));
1842 OSL_ENSURE(m_xOwnAttributes
.is(), "OColumnWrapperImport::CreateChildContext: had no form:column element!");
1843 pReturn
->addOuterAttributes(m_xOwnAttributes
);
1847 void OColumnWrapperImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1849 OSL_ENSURE(!m_xOwnAttributes
.is(), "OColumnWrapperImport::StartElement: already have the cloned list!");
1851 // clone the attributes
1852 Reference
< XCloneable
> xCloneList(_rxAttrList
, UNO_QUERY
);
1853 OSL_ENSURE(xCloneList
.is(), "OColumnWrapperImport::StartElement: AttributeList not cloneable!");
1854 if ( xCloneList
.is() )
1855 m_xOwnAttributes
.set(xCloneList
->createClone(), UNO_QUERY
);
1856 OSL_ENSURE(m_xOwnAttributes
.is(), "OColumnWrapperImport::StartElement: no cloned list!");
1859 OControlImport
* OColumnWrapperImport::implCreateChildContext(
1860 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
1861 OControlElement::ElementType _eType
)
1863 OSL_ENSURE( (OControlElement::TEXT
== _eType
)
1864 || (OControlElement::TEXT_AREA
== _eType
)
1865 || (OControlElement::FORMATTED_TEXT
== _eType
)
1866 || (OControlElement::CHECKBOX
== _eType
)
1867 || (OControlElement::LISTBOX
== _eType
)
1868 || (OControlElement::COMBOBOX
== _eType
)
1869 || (OControlElement::TIME
== _eType
)
1870 || (OControlElement::DATE
== _eType
),
1871 "OColumnWrapperImport::implCreateChildContext: invalid or unrecognized sub element!");
1875 case OControlElement::COMBOBOX
:
1876 case OControlElement::LISTBOX
:
1877 return new OColumnImport
<OListAndComboImport
>(m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1879 case OControlElement::PASSWORD
:
1880 return new OColumnImport
<OPasswordImport
>(m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1882 case OControlElement::TEXT
:
1883 case OControlElement::TEXT_AREA
:
1884 case OControlElement::FORMATTED_TEXT
:
1885 return new OColumnImport
< OTextLikeImport
>( m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1888 return new OColumnImport
<OControlImport
>(m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1893 OGridImport::OGridImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1894 const Reference
< XNameContainer
>& _rxParentContainer
,
1895 OControlElement::ElementType _eType
)
1896 :OGridImport_Base(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, "column")
1898 setElementType(_eType
);
1901 SvXMLImportContext
* OGridImport::implCreateControlWrapper(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
)
1903 return new OColumnWrapperImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
);
1907 OFormImport::OFormImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1908 const Reference
< XNameContainer
>& _rxParentContainer
)
1909 :OFormImport_Base(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, "control")
1911 enableTrackAttributes();
1914 SvXMLImportContext
* OFormImport::CreateChildContext(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
1915 const Reference
< XAttributeList
>& _rxAttrList
)
1917 if( token::IsXMLToken(_rLocalName
, token::XML_FORM
) )
1918 return new OFormImport( m_rFormImport
, *this, _nPrefix
, _rLocalName
,
1920 else if ( token::IsXMLToken(_rLocalName
, token::XML_CONNECTION_RESOURCE
) )
1921 return new OXMLDataSourceImport(GetImport(), _nPrefix
, _rLocalName
, _rxAttrList
,m_xElement
);
1922 else if( (token::IsXMLToken(_rLocalName
, token::XML_EVENT_LISTENERS
) &&
1923 (XML_NAMESPACE_OFFICE
== _nPrefix
)) ||
1924 token::IsXMLToken( _rLocalName
, token::XML_PROPERTIES
) )
1925 return OElementImport::CreateChildContext( _nPrefix
, _rLocalName
,
1928 return implCreateChildContext( _nPrefix
, _rLocalName
,
1929 OElementNameMap::getElementType(_rLocalName
) );
1932 void OFormImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1934 m_rFormImport
.enterEventContext();
1935 OFormImport_Base::StartElement(_rxAttrList
);
1937 // handle the target-frame attribute
1938 simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeName(CCAFlags::TargetFrame
), PROPERTY_TARGETFRAME
, "_blank");
1941 void OFormImport::EndElement()
1943 OFormImport_Base::EndElement();
1944 m_rFormImport
.leaveEventContext();
1947 SvXMLImportContext
* OFormImport::implCreateControlWrapper(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
)
1949 OSL_ENSURE( false, "illegal call to OFormImport::implCreateControlWrapper" );
1950 return new SvXMLImportContext(GetImport(), _nPrefix
, _rLocalName
);
1953 bool OFormImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1955 // handle the master/details field attributes (they're way too special to let the OPropertyImport handle them)
1956 static const char* s_sMasterFieldsAttributeName
= OAttributeMetaData::getFormAttributeName(faMasterFields
);
1957 static const char* s_sDetailFieldsAttributeName
= OAttributeMetaData::getFormAttributeName(faDetailFiels
);
1959 if ( _rLocalName
.equalsAscii(s_sMasterFieldsAttributeName
) )
1961 implTranslateStringListProperty(PROPERTY_MASTERFIELDS
, _rValue
);
1965 if ( _rLocalName
.equalsAscii(s_sDetailFieldsAttributeName
) )
1967 implTranslateStringListProperty(PROPERTY_DETAILFIELDS
, _rValue
);
1971 return OFormImport_Base::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1974 void OFormImport::implTranslateStringListProperty(const OUString
& _rPropertyName
, const OUString
& _rValue
)
1976 PropertyValue aProp
;
1977 aProp
.Name
= _rPropertyName
;
1979 Sequence
< OUString
> aList
;
1981 // split up the value string
1982 if (!_rValue
.isEmpty())
1984 // For the moment, we build a vector instead of a Sequence. It's easier to handle because of its
1986 ::std::vector
< OUString
> aElements
;
1987 // estimate the number of tokens
1988 sal_Int32 nEstimate
= 0, nLength
= _rValue
.getLength();
1989 const sal_Unicode
* pChars
= _rValue
.getStr();
1990 for (sal_Int32 i
=0; i
<nLength
; ++i
, ++pChars
)
1993 aElements
.reserve(nEstimate
+ 1);
1994 // that's the worst case. If the string contains the separator character _quoted_, we reserved to much ...
1996 sal_Int32 nElementStart
= 0;
1997 sal_Int32 nNextSep
= 0;
1998 sal_Int32 nElementLength
;
2002 // extract the current element
2003 nNextSep
= ::sax::Converter::indexOfComma(
2004 _rValue
, nElementStart
);
2007 sElement
= _rValue
.copy(nElementStart
, nNextSep
- nElementStart
);
2009 nElementLength
= sElement
.getLength();
2010 // when writing the sequence, we quoted the single elements with " characters
2011 OSL_ENSURE( sElement
.startsWith("\"") && sElement
.endsWith("\""),
2012 "OFormImport::implTranslateStringListProperty: invalid quoted element name.");
2013 sElement
= sElement
.copy(1, nElementLength
- 2);
2015 aElements
.push_back(sElement
);
2017 // switch to the next element
2018 nElementStart
= 1 + nNextSep
;
2020 while (nElementStart
< nLength
);
2022 aList
= Sequence
< OUString
>(aElements
.data(), aElements
.size());
2026 OSL_FAIL("OFormImport::implTranslateStringListProperty: invalid value (empty)!");
2029 aProp
.Value
<<= aList
;
2031 // add the property to the base class' array
2032 implPushBackPropertyValue(aProp
);
2034 //= OXMLDataSourceImport
2035 OXMLDataSourceImport::OXMLDataSourceImport(
2036 SvXMLImport
& _rImport
2038 , const OUString
& _sLocalName
2039 ,const Reference
< css::xml::sax::XAttributeList
> & _xAttrList
2040 ,const css::uno::Reference
< css::beans::XPropertySet
>& _xElement
) :
2041 SvXMLImportContext( _rImport
, nPrfx
, _sLocalName
)
2043 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
2044 const SvXMLNamespaceMap
& rMap
= _rImport
.GetNamespaceMap();
2046 sal_Int16 nLength
= (_xElement
.is() && _xAttrList
.is()) ? _xAttrList
->getLength() : 0;
2047 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
2049 OUString sLocalName
;
2050 OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
2051 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
, &sLocalName
);
2053 if ( ( nPrefix
== OAttributeMetaData::getCommonControlAttributeNamespace( CCAFlags::TargetLocation
) )
2054 && ( sLocalName
.equalsAscii( OAttributeMetaData::getCommonControlAttributeName( CCAFlags::TargetLocation
) ) )
2057 OUString sValue
= _xAttrList
->getValueByIndex( i
);
2059 INetURLObject
aURL(sValue
);
2060 if ( aURL
.GetProtocol() == INetProtocol::File
)
2061 _xElement
->setPropertyValue(PROPERTY_DATASOURCENAME
,makeAny(sValue
));
2063 _xElement
->setPropertyValue(PROPERTY_URL
,makeAny(sValue
)); // the url is the "sdbc:" string
2068 OControlImport
* OFormImport::implCreateChildContext(
2069 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
2070 OControlElement::ElementType _eType
)
2074 case OControlElement::TEXT
:
2075 case OControlElement::TEXT_AREA
:
2076 case OControlElement::FORMATTED_TEXT
:
2077 return new OTextLikeImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2079 case OControlElement::BUTTON
:
2080 case OControlElement::IMAGE
:
2081 case OControlElement::IMAGE_FRAME
:
2082 return new OButtonImport( m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2084 case OControlElement::COMBOBOX
:
2085 case OControlElement::LISTBOX
:
2086 return new OListAndComboImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2088 case OControlElement::RADIO
:
2089 return new ORadioImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2091 case OControlElement::CHECKBOX
:
2092 return new OImagePositionImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2094 case OControlElement::PASSWORD
:
2095 return new OPasswordImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2097 case OControlElement::FRAME
:
2098 case OControlElement::FIXED_TEXT
:
2099 return new OReferredControlImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2101 case OControlElement::GRID
:
2102 return new OGridImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2104 case OControlElement::VALUERANGE
:
2105 return new OValueRangeImport( m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2108 return new OControlImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2112 OUString
OFormImport::determineDefaultServiceName() const
2114 return OUString("com.sun.star.form.component.Form");
2117 } // namespace xmloff
2119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */