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 .
21 #include "elementimport.hxx"
22 #include "xmloff/xmlimp.hxx"
23 #include "xmloff/nmspmap.hxx"
24 #include "strings.hxx"
25 #include "callbacks.hxx"
26 #include "attriblistmerge.hxx"
27 #include "xmloff/xmlnmspe.hxx"
28 #include "eventimport.hxx"
29 #include "xmloff/txtstyli.hxx"
30 #include "formenums.hxx"
31 #include "xmloff/xmltoken.hxx"
32 #include "gridcolumnproptranslator.hxx"
33 #include "property_description.hxx"
34 #include "property_meta_data.hxx"
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>
45 #include <sax/tools/converter.hxx>
46 #include <tools/urlobj.hxx>
47 #include <tools/diagnose_ex.h>
48 #include <rtl/logfile.hxx>
49 #include <rtl/strbuf.hxx>
50 #include <comphelper/extract.hxx>
51 #include <comphelper/types.hxx>
56 //.........................................................................
59 //.........................................................................
61 using namespace ::xmloff::token
;
62 using namespace ::com::sun::star
;
63 using namespace ::com::sun::star::uno
;
64 using namespace ::com::sun::star::awt
;
65 using namespace ::com::sun::star::container
;
66 using namespace ::com::sun::star::beans
;
67 using namespace ::com::sun::star::script
;
68 using namespace ::com::sun::star::lang
;
69 using namespace ::com::sun::star::form
;
70 using namespace ::com::sun::star::xml
;
71 using namespace ::com::sun::star::util
;
72 using namespace ::com::sun::star::text
;
73 using namespace ::comphelper
;
74 using ::com::sun::star::xml::sax::XAttributeList
;
76 #define PROPID_VALUE 1
77 #define PROPID_CURRENT_VALUE 2
78 #define PROPID_MIN_VALUE 3
79 #define PROPID_MAX_VALUE 4
81 //=====================================================================
82 struct PropertyValueLess
84 sal_Bool
operator()(const PropertyValue
& _rLeft
, const PropertyValue
& _rRight
)
86 return _rLeft
.Name
< _rRight
.Name
;
90 //=====================================================================
91 struct PropertyValueCompare
: public ::std::binary_function
< PropertyValue
, OUString
, bool>
93 bool operator() (const PropertyValue
& lhs
, const OUString
& rhs
) const
95 return lhs
.Name
== rhs
;
97 bool operator() (const OUString
& lhs
, const PropertyValue
& rhs
) const
99 return lhs
== rhs
.Name
;
103 //=====================================================================
104 template <class ELEMENT
>
105 void pushBackSequenceElement(Sequence
< ELEMENT
>& _rContainer
, const ELEMENT
& _rElement
)
107 sal_Int32 nLen
= _rContainer
.getLength();
108 _rContainer
.realloc(nLen
+ 1);
109 _rContainer
[nLen
] = _rElement
;
112 //=====================================================================
114 //=====================================================================
115 //---------------------------------------------------------------------
116 OElementNameMap::MapString2Element
OElementNameMap::s_sElementTranslations
;
118 //---------------------------------------------------------------------
119 const OControlElement::ElementType
& operator ++(OControlElement::ElementType
& _e
)
121 OControlElement::ElementType e
= _e
;
122 sal_Int32 nAsInt
= static_cast<sal_Int32
>(e
);
123 _e
= static_cast<OControlElement::ElementType
>( ++nAsInt
);
127 //---------------------------------------------------------------------
128 OControlElement::ElementType
OElementNameMap::getElementType(const OUString
& _rName
)
130 if ( s_sElementTranslations
.empty() )
132 for (ElementType eType
=(ElementType
)0; eType
<UNKNOWN
; ++eType
)
133 s_sElementTranslations
[OUString::createFromAscii(getElementName(eType
))] = eType
;
135 ConstMapString2ElementIterator aPos
= s_sElementTranslations
.find(_rName
);
136 if (s_sElementTranslations
.end() != aPos
)
142 //=====================================================================
144 //=====================================================================
145 //---------------------------------------------------------------------
146 OElementImport::OElementImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
147 const Reference
< XNameContainer
>& _rxParentContainer
)
148 :OPropertyImport(_rImport
, _nPrefix
, _rName
)
149 ,m_rFormImport(_rImport
)
150 ,m_rEventManager(_rEventManager
)
151 ,m_pStyleElement( NULL
)
152 ,m_xParentContainer(_rxParentContainer
)
153 ,m_bImplicitGenericAttributeHandling( true )
155 OSL_ENSURE(m_xParentContainer
.is(), "OElementImport::OElementImport: invalid parent container!");
158 //---------------------------------------------------------------------
159 OElementImport::~OElementImport()
163 //---------------------------------------------------------------------
164 OUString
OElementImport::determineDefaultServiceName() const
169 //---------------------------------------------------------------------
170 void OElementImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
172 ENTER_LOG_CONTEXT( "xmloff::OElementImport - importing one element" );
174 const SvXMLNamespaceMap
& rMap
= m_rContext
.getGlobalContext().GetNamespaceMap();
175 const OUString sImplNameAttribute
= rMap
.GetQNameByKey( XML_NAMESPACE_FORM
, GetXMLToken( XML_CONTROL_IMPLEMENTATION
) );
176 const OUString sControlImplementation
= _rxAttrList
->getValueByName( sImplNameAttribute
);
178 // retrieve the service name
179 if ( !sControlImplementation
.isEmpty() )
181 OUString sOOoImplementationName
;
182 const sal_uInt16 nImplPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sControlImplementation
, &sOOoImplementationName
);
183 m_sServiceName
= ( nImplPrefix
== XML_NAMESPACE_OOO
) ? sOOoImplementationName
: sControlImplementation
;
186 if ( m_sServiceName
.isEmpty() )
187 determineDefaultServiceName();
189 // create the object *now*. This allows setting properties in the various handleAttribute methods.
190 // (Though currently not all code is migrated to this pattern, most attributes are still handled
191 // by remembering the value (via implPushBackPropertyValue), and setting the correct property value
192 // later (in OControlImport::StartElement).)
193 m_xElement
= createElement();
194 if ( m_xElement
.is() )
195 m_xInfo
= m_xElement
->getPropertySetInfo();
197 // call the base class
198 OPropertyImport::StartElement( _rxAttrList
);
201 //---------------------------------------------------------------------
202 SvXMLImportContext
* OElementImport::CreateChildContext(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
203 const Reference
< XAttributeList
>& _rxAttrList
)
205 if( token::IsXMLToken(_rLocalName
, token::XML_EVENT_LISTENERS
) && (XML_NAMESPACE_OFFICE
== _nPrefix
))
206 return new OFormEventsImportContext(m_rFormImport
.getGlobalContext(), _nPrefix
, _rLocalName
, *this);
208 return OPropertyImport::CreateChildContext(_nPrefix
, _rLocalName
, _rxAttrList
);
211 //---------------------------------------------------------------------
212 void OElementImport::EndElement()
214 OSL_ENSURE(m_xElement
.is(), "OElementImport::EndElement: invalid element created!");
215 if (!m_xElement
.is())
218 // apply the non-generic properties
219 implApplySpecificProperties();
221 // set the generic properties
222 implApplyGenericProperties();
224 // set the style properties
225 if ( m_pStyleElement
&& m_xElement
.is() )
227 Reference
< XPropertySet
> xPropTranslation
=
228 new OGridColumnPropertyTranslator( Reference
< XMultiPropertySet
>( m_xElement
, UNO_QUERY
) );
229 const_cast< XMLTextStyleContext
* >( m_pStyleElement
)->FillPropertySet( xPropTranslation
);
231 const OUString sNumberStyleName
= const_cast< XMLTextStyleContext
* >( m_pStyleElement
)->GetDataStyleName( );
232 if ( !sNumberStyleName
.isEmpty() )
233 // the style also has a number (sub) style
234 m_rContext
.applyControlNumberStyle( m_xElement
, sNumberStyleName
);
237 // insert the element into the parent container
238 if (m_sName
.isEmpty())
240 OSL_FAIL("OElementImport::EndElement: did not find a name attribute!");
241 m_sName
= implGetDefaultName();
244 if (m_xParentContainer
.is())
245 m_xParentContainer
->insertByName(m_sName
, makeAny(m_xElement
));
247 LEAVE_LOG_CONTEXT( );
250 //---------------------------------------------------------------------
251 void OElementImport::implApplySpecificProperties()
253 if ( m_aValues
.empty() )
256 // set all the properties we collected
257 #if OSL_DEBUG_LEVEL > 0
258 // check if the object has all the properties
259 // (We do this in the non-pro version only. Doing it all the time would be much to expensive)
262 PropertyValueArray::const_iterator aEnd
= m_aValues
.end();
263 for ( PropertyValueArray::iterator aCheck
= m_aValues
.begin();
268 OSL_ENSURE(m_xInfo
->hasPropertyByName(aCheck
->Name
),
269 OStringBuffer("OElementImport::implApplySpecificProperties: read a property (").
270 append(OUStringToOString(aCheck
->Name
, RTL_TEXTENCODING_ASCII_US
)).
271 append(") which does not exist on the element!").getStr());
276 // set the properties
277 const Reference
< XMultiPropertySet
> xMultiProps(m_xElement
, UNO_QUERY
);
278 sal_Bool bSuccess
= sal_False
;
279 if (xMultiProps
.is())
281 // translate our properties so that the XMultiPropertySet can handle them
283 // sort our property value array so that we can use it in a setPropertyValues
284 ::std::sort( m_aValues
.begin(), m_aValues
.end(), PropertyValueLess());
287 Sequence
< OUString
> aNames(m_aValues
.size());
288 OUString
* pNames
= aNames
.getArray();
290 Sequence
< Any
> aValues(m_aValues
.size());
291 Any
* pValues
= aValues
.getArray();
294 PropertyValueArray::iterator aEnd
= m_aValues
.end();
295 for ( PropertyValueArray::iterator aPropValues
= m_aValues
.begin();
297 ++aPropValues
, ++pNames
, ++pValues
300 *pNames
= aPropValues
->Name
;
301 *pValues
= aPropValues
->Value
;
306 xMultiProps
->setPropertyValues(aNames
, aValues
);
311 OSL_FAIL("OElementImport::implApplySpecificProperties: could not set the properties (using the XMultiPropertySet)!");
316 { // no XMultiPropertySet or setting all properties at once failed
317 PropertyValueArray::iterator aEnd
= m_aValues
.end();
318 for ( PropertyValueArray::iterator aPropValues
= m_aValues
.begin();
323 // this try/catch here is expensive, but because this is just a fallback which should normally not be
324 // used it's acceptable this way ...
327 m_xElement
->setPropertyValue(aPropValues
->Name
, aPropValues
->Value
);
331 OSL_FAIL(OStringBuffer("OElementImport::implApplySpecificProperties: could not set the property \"").
332 append(OUStringToOString(aPropValues
->Name
, RTL_TEXTENCODING_ASCII_US
)).
333 append("\"!").getStr());
339 //---------------------------------------------------------------------
340 void OElementImport::implApplyGenericProperties()
342 if ( m_aGenericValues
.empty() )
345 Reference
< XPropertyContainer
> xDynamicProperties( m_xElement
, UNO_QUERY
);
347 PropertyValueArray::iterator aEnd
= m_aGenericValues
.end();
348 for ( PropertyValueArray::iterator aPropValues
=
349 m_aGenericValues
.begin();
354 // check property type for numeric types before setting
358 // if such a property does not yet exist at the element, create it if necessary
359 const bool bExistentProperty
= m_xInfo
->hasPropertyByName( aPropValues
->Name
);
360 if ( !bExistentProperty
)
362 if ( !xDynamicProperties
.is() )
364 #if OSL_DEBUG_LEVEL > 0
365 OString
aMessage( "OElementImport::implApplyGenericProperties: encountered an unknown property (" );
366 aMessage
+= OUStringToOString( aPropValues
->Name
, RTL_TEXTENCODING_ASCII_US
);
367 aMessage
+= "), but component is no PropertyBag!";
368 OSL_FAIL( aMessage
.getStr() );
373 xDynamicProperties
->addProperty(
375 PropertyAttribute::BOUND
| PropertyAttribute::REMOVABLE
,
379 // re-fetch the PropertySetInfo
380 m_xInfo
= m_xElement
->getPropertySetInfo();
383 // determine the type of the value (source for the following conversion)
384 TypeClass eValueTypeClass
= aPropValues
->Value
.getValueTypeClass();
385 const sal_Bool bValueIsSequence
= TypeClass_SEQUENCE
== eValueTypeClass
;
386 if ( bValueIsSequence
)
388 uno::Type
aSimpleType( getSequenceElementType( aPropValues
->Value
.getValueType() ) );
389 eValueTypeClass
= aSimpleType
.getTypeClass();
392 // determine the type of the property (target for the following conversion)
393 const Property
aProperty( m_xInfo
->getPropertyByName( aPropValues
->Name
) );
394 TypeClass ePropTypeClass
= aProperty
.Type
.getTypeClass();
395 const sal_Bool bPropIsSequence
= TypeClass_SEQUENCE
== ePropTypeClass
;
396 if( bPropIsSequence
)
398 uno::Type
aSimpleType( ::comphelper::getSequenceElementType( aProperty
.Type
) );
399 ePropTypeClass
= aSimpleType
.getTypeClass();
402 if ( bPropIsSequence
!= bValueIsSequence
)
404 OSL_FAIL( "OElementImport::implImportGenericProperties: either both value and property should be a sequence, or none of them!" );
408 if ( bValueIsSequence
)
410 OSL_ENSURE( eValueTypeClass
== TypeClass_ANY
,
411 "OElementImport::implApplyGenericProperties: only ANYs should have been imported as generic list property!" );
412 // (OPropertyImport should produce only Sequencer< Any >, since it cannot know the real type
414 OSL_ENSURE( ePropTypeClass
== TypeClass_SHORT
,
415 "OElementImport::implApplyGenericProperties: conversion to sequences other than 'sequence< short >' not implemented, yet!" );
417 Sequence
< Any
> aXMLValueList
;
418 aPropValues
->Value
>>= aXMLValueList
;
419 Sequence
< sal_Int16
> aPropertyValueList( aXMLValueList
.getLength() );
421 const Any
* pXMLValue
= aXMLValueList
.getConstArray();
422 sal_Int16
* pPropValue
= aPropertyValueList
.getArray();
424 for ( sal_Int32 i
=0; i
<aXMLValueList
.getLength(); ++i
, ++pXMLValue
, ++pPropValue
)
426 // only value sequences of numeric types implemented so far.
428 OSL_VERIFY( *pXMLValue
>>= nVal
);
429 *pPropValue
= static_cast< sal_Int16
>( nVal
);
432 aPropValues
->Value
<<= aPropertyValueList
;
434 else if ( ePropTypeClass
!= eValueTypeClass
)
436 switch ( eValueTypeClass
)
438 case TypeClass_DOUBLE
:
441 aPropValues
->Value
>>= nVal
;
442 switch( ePropTypeClass
)
445 aPropValues
->Value
<<= static_cast< sal_Int8
>( nVal
);
447 case TypeClass_SHORT
:
448 aPropValues
->Value
<<= static_cast< sal_Int16
>( nVal
);
452 aPropValues
->Value
<<= static_cast< sal_Int32
>( nVal
);
454 case TypeClass_HYPER
:
455 aPropValues
->Value
<<= static_cast< sal_Int64
>( nVal
);
458 OSL_FAIL( "OElementImport::implImportGenericProperties: unsupported value type!" );
464 OSL_FAIL( "OElementImport::implImportGenericProperties: non-double values not supported!" );
469 m_xElement
->setPropertyValue( aPropValues
->Name
, aPropValues
->Value
);
473 OSL_FAIL(OStringBuffer("OElementImport::EndElement: could not set the property \"").
474 append(OUStringToOString(aPropValues
->Name
, RTL_TEXTENCODING_ASCII_US
)).
475 append("\"!").getStr());
480 //---------------------------------------------------------------------
481 OUString
OElementImport::implGetDefaultName() const
483 // no optimization here. If this method gets called, the XML stream did not contain a name for the
484 // element, which is a heavy error. So in this case we don't care for performance
485 static const OUString
sUnnamedName("unnamed");
486 OSL_ENSURE(m_xParentContainer
.is(), "OElementImport::implGetDefaultName: no parent container!");
487 if (!m_xParentContainer
.is())
489 Sequence
< OUString
> aNames
= m_xParentContainer
->getElementNames();
492 const OUString
* pNames
= NULL
;
493 const OUString
* pNamesEnd
= aNames
.getConstArray() + aNames
.getLength();
494 for (sal_Int32 i
=0; i
<32768; ++i
) // the limit is nearly arbitrary ...
496 // assemble the new name (suggestion)
497 sReturn
= sUnnamedName
;
498 sReturn
+= OUString::valueOf(i
);
499 // check the existence (this is the bad performance part ....)
500 for (pNames
= aNames
.getConstArray(); pNames
<pNamesEnd
; ++pNames
)
502 if (*pNames
== sReturn
)
507 if (pNames
<pNamesEnd
)
512 OSL_FAIL("OElementImport::implGetDefaultName: did not find a free name!");
516 //---------------------------------------------------------------------
517 PropertyGroups::const_iterator
OElementImport::impl_matchPropertyGroup( const PropertyGroups
& i_propertyGroups
) const
519 ENSURE_OR_RETURN( m_xInfo
.is(), "OElementImport::impl_matchPropertyGroup: no property set info!", i_propertyGroups
.end() );
521 for ( PropertyGroups::const_iterator group
= i_propertyGroups
.begin();
522 group
!= i_propertyGroups
.end();
526 bool missingProp
= false;
527 for ( PropertyDescriptionList::const_iterator prop
= group
->begin();
528 prop
!= group
->end();
532 if ( !m_xInfo
->hasPropertyByName( (*prop
)->propertyName
) )
546 return i_propertyGroups
.end();
549 //---------------------------------------------------------------------
550 bool OElementImport::tryGenericAttribute( sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
552 // the generic approach (which I hope all props will be migrated to, on the medium term): property handlers
553 const AttributeDescription
attribute( metadata::getAttributeDescription( _nNamespaceKey
, _rLocalName
) );
554 if ( attribute
.attributeToken
!= XML_TOKEN_INVALID
)
556 PropertyGroups propertyGroups
;
557 metadata::getPropertyGroupList( attribute
, propertyGroups
);
558 const PropertyGroups::const_iterator pos
= impl_matchPropertyGroup( propertyGroups
);
559 if ( pos
== propertyGroups
.end() )
564 const PropertyDescriptionList
& rProperties( *pos
);
565 const PropertyDescription
* first
= *rProperties
.begin();
568 SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property description!" );
572 const PPropertyHandler handler
= (*first
->factory
)( first
->propertyId
);
573 if ( !handler
.get() )
575 SAL_WARN( "xmloff.forms", "OElementImport::handleAttribute: invalid property handler!" );
579 PropertyValues aValues
;
580 for ( PropertyDescriptionList::const_iterator propDesc
= rProperties
.begin();
581 propDesc
!= rProperties
.end();
585 aValues
[ (*propDesc
)->propertyId
] = Any();
587 if ( handler
->getPropertyValues( _rValue
, aValues
) )
589 for ( PropertyDescriptionList::const_iterator propDesc
= rProperties
.begin();
590 propDesc
!= rProperties
.end();
594 implPushBackPropertyValue( (*propDesc
)->propertyName
, aValues
[ (*propDesc
)->propertyId
] );
606 //---------------------------------------------------------------------
607 bool OElementImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
609 if ( token::IsXMLToken( _rLocalName
, token::XML_CONTROL_IMPLEMENTATION
) )
610 // ignore this, it has already been handled in OElementImport::StartElement
613 if ( token::IsXMLToken( _rLocalName
, token::XML_NAME
) )
615 if ( m_sName
.isEmpty() )
616 // remember the name for later use in EndElement
621 // maybe it's the style attribute?
622 if ( token::IsXMLToken( _rLocalName
, token::XML_TEXT_STYLE_NAME
) )
624 const SvXMLStyleContext
* pStyleContext
= m_rContext
.getStyleElement( _rValue
);
625 OSL_ENSURE( pStyleContext
, "OElementImport::handleAttribute: do not know the style!" );
626 // remember the element for later usage.
627 m_pStyleElement
= PTR_CAST( XMLTextStyleContext
, pStyleContext
);
631 if ( m_bImplicitGenericAttributeHandling
)
632 if ( tryGenericAttribute( _nNamespaceKey
, _rLocalName
, _rValue
) )
635 // let the base class handle it
636 return OPropertyImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
639 //---------------------------------------------------------------------
640 Reference
< XPropertySet
> OElementImport::createElement()
642 Reference
< XPropertySet
> xReturn
;
643 if (!m_sServiceName
.isEmpty())
645 Reference
< XComponentContext
> xContext
= m_rFormImport
.getGlobalContext().GetComponentContext();
646 Reference
< XInterface
> xPure
= xContext
->getServiceManager()->createInstanceWithContext(m_sServiceName
, xContext
);
647 OSL_ENSURE(xPure
.is(),
648 OStringBuffer("OElementImport::createElement: service factory gave me no object (service name: ").append(OUStringToOString(m_sServiceName
, RTL_TEXTENCODING_ASCII_US
)).append(")!").getStr());
649 xReturn
= Reference
< XPropertySet
>(xPure
, UNO_QUERY
);
652 OSL_FAIL("OElementImport::createElement: no service name to create an element!");
657 //---------------------------------------------------------------------
658 void OElementImport::registerEvents(const Sequence
< ScriptEventDescriptor
>& _rEvents
)
660 OSL_ENSURE(m_xElement
.is(), "OElementImport::registerEvents: no element to register events for!");
661 m_rEventManager
.registerEvents(m_xElement
, _rEvents
);
664 //---------------------------------------------------------------------
665 void OElementImport::simulateDefaultedAttribute(const sal_Char
* _pAttributeName
, const OUString
& _rPropertyName
, const sal_Char
* _pAttributeDefault
)
667 OSL_ENSURE( m_xInfo
.is(), "OPropertyImport::simulateDefaultedAttribute: the component should be more gossipy about it's properties!" );
669 if ( !m_xInfo
.is() || m_xInfo
->hasPropertyByName( _rPropertyName
) )
671 OUString sLocalAttrName
= OUString::createFromAscii(_pAttributeName
);
672 if ( !encounteredAttribute( sLocalAttrName
) )
673 OSL_VERIFY( handleAttribute( XML_NAMESPACE_FORM
, sLocalAttrName
, OUString::createFromAscii( _pAttributeDefault
) ) );
677 //=====================================================================
679 //=====================================================================
680 //---------------------------------------------------------------------
681 OControlImport::OControlImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
682 const Reference
< XNameContainer
>& _rxParentContainer
)
683 :OElementImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
)
684 ,m_eElementType(OControlElement::UNKNOWN
)
686 disableImplicitGenericAttributeHandling();
689 //---------------------------------------------------------------------
690 OControlImport::OControlImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
691 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
692 :OElementImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
)
693 ,m_eElementType(_eType
)
695 disableImplicitGenericAttributeHandling();
698 //---------------------------------------------------------------------
699 OUString
OControlImport::determineDefaultServiceName() const
701 const sal_Char
* pServiceName
= NULL
;
702 switch ( m_eElementType
)
704 case OControlElement::TEXT
:
705 case OControlElement::TEXT_AREA
:
706 case OControlElement::PASSWORD
: pServiceName
= "com.sun.star.form.component.TextField"; break;
707 case OControlElement::FILE: pServiceName
= "com.sun.star.form.component.FileControl"; break;
708 case OControlElement::FORMATTED_TEXT
: pServiceName
= "com.sun.star.form.component.FormattedField"; break;
709 case OControlElement::FIXED_TEXT
: pServiceName
= "com.sun.star.form.component.FixedText"; break;
710 case OControlElement::COMBOBOX
: pServiceName
= "com.sun.star.form.component.ComboBox"; break;
711 case OControlElement::LISTBOX
: pServiceName
= "com.sun.star.form.component.ListBox"; break;
712 case OControlElement::BUTTON
: pServiceName
= "com.sun.star.form.component.CommandButton"; break;
713 case OControlElement::IMAGE
: pServiceName
= "com.sun.star.form.component.ImageButton"; break;
714 case OControlElement::CHECKBOX
: pServiceName
= "com.sun.star.form.component.CheckBox"; break;
715 case OControlElement::RADIO
: pServiceName
= "com.sun.star.form.component.RadioButton"; break;
716 case OControlElement::FRAME
: pServiceName
= "com.sun.star.form.component.GroupBox"; break;
717 case OControlElement::IMAGE_FRAME
: pServiceName
= "com.sun.star.form.component.DatabaseImageControl"; break;
718 case OControlElement::HIDDEN
: pServiceName
= "com.sun.star.form.component.HiddenControl"; break;
719 case OControlElement::GRID
: pServiceName
= "com.sun.star.form.component.GridControl"; break;
720 case OControlElement::TIME
: pServiceName
= "com.sun.star.form.component.TimeField"; break;
721 case OControlElement::DATE
: pServiceName
= "com.sun.star.form.component.DateField"; break;
724 if ( pServiceName
!= NULL
)
725 return OUString::createFromAscii( pServiceName
);
729 //---------------------------------------------------------------------
730 void OControlImport::addOuterAttributes(const Reference
< XAttributeList
>& _rxOuterAttribs
)
732 OSL_ENSURE(!m_xOuterAttributes
.is(), "OControlImport::addOuterAttributes: already have these attributes!");
733 m_xOuterAttributes
= _rxOuterAttribs
;
736 //---------------------------------------------------------------------
737 bool OControlImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
739 static const sal_Char
* pLinkedCellAttributeName
= OAttributeMetaData::getBindingAttributeName(BA_LINKED_CELL
);
741 if (IsXMLToken(_rLocalName
, XML_ID
))
742 { // it's the control id
743 if (XML_NAMESPACE_XML
== _nNamespaceKey
)
745 m_sControlId
= _rValue
;
747 else if (XML_NAMESPACE_FORM
== _nNamespaceKey
)
749 if (m_sControlId
.isEmpty())
751 m_sControlId
= _rValue
;
757 if ( _rLocalName
.equalsAscii( pLinkedCellAttributeName
) )
758 { // it's the address of a spreadsheet cell
759 m_sBoundCellAddress
= _rValue
;
763 if ( _nNamespaceKey
== XML_NAMESPACE_XFORMS
&& IsXMLToken( _rLocalName
, XML_BIND
) )
765 m_sBindingID
= _rValue
;
769 if ( _nNamespaceKey
== XML_NAMESPACE_FORM
&& IsXMLToken( _rLocalName
, XML_XFORMS_LIST_SOURCE
) )
771 m_sListBindingID
= _rValue
;
775 if ( ( ( _nNamespaceKey
== XML_NAMESPACE_FORM
)
776 && IsXMLToken( _rLocalName
, XML_XFORMS_SUBMISSION
)
778 || ( ( _nNamespaceKey
== XML_NAMESPACE_XFORMS
)
779 && IsXMLToken( _rLocalName
, XML_SUBMISSION
)
783 m_sSubmissionID
= _rValue
;
787 if ( OElementImport::tryGenericAttribute( _nNamespaceKey
, _rLocalName
, _rValue
) )
790 static const sal_Char
* pValueAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCA_VALUE
);
791 static const sal_Char
* pCurrentValueAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_VALUE
);
792 static const sal_Char
* pMinValueAttributeName
= OAttributeMetaData::getSpecialAttributeName(SCA_MIN_VALUE
);
793 static const sal_Char
* pMaxValueAttributeName
= OAttributeMetaData::getSpecialAttributeName(SCA_MAX_VALUE
);
794 static const sal_Char
* pRepeatDelayAttributeName
= OAttributeMetaData::getSpecialAttributeName( SCA_REPEAT_DELAY
);
796 sal_Int32 nHandle
= -1;
797 if ( _rLocalName
.equalsAscii( pValueAttributeName
) )
798 nHandle
= PROPID_VALUE
;
799 else if ( _rLocalName
.equalsAscii( pCurrentValueAttributeName
) )
800 nHandle
= PROPID_CURRENT_VALUE
;
801 else if ( _rLocalName
.equalsAscii( pMinValueAttributeName
) )
802 nHandle
= PROPID_MIN_VALUE
;
803 else if ( _rLocalName
.equalsAscii( pMaxValueAttributeName
) )
804 nHandle
= PROPID_MAX_VALUE
;
807 // for the moment, simply remember the name and the value
809 aProp
.Name
= _rLocalName
;
810 aProp
.Handle
= nHandle
;
811 aProp
.Value
<<= _rValue
;
812 m_aValueProperties
.push_back(aProp
);
816 if ( _rLocalName
.equalsAscii( pRepeatDelayAttributeName
) )
818 util::Duration aDuration
;
819 if (::sax::Converter::convertDuration(aDuration
, _rValue
))
822 aProp
.Name
= PROPERTY_REPEAT_DELAY
;
823 sal_Int32
const nMS
=
824 ((aDuration
.Hours
* 60 + aDuration
.Minutes
) * 60
825 + aDuration
.Seconds
) * 1000 + aDuration
.NanoSeconds
/1000000;
828 implPushBackPropertyValue(aProp
);
833 return OElementImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
836 //---------------------------------------------------------------------
837 void OControlImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
839 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
> xAttributes
;
840 if( m_xOuterAttributes
.is() )
842 // merge the attribute lists
843 OAttribListMerger
* pMerger
= new OAttribListMerger
;
845 pMerger
->addList(_rxAttrList
);
846 // and the ones of our enclosing element
847 pMerger
->addList(m_xOuterAttributes
);
848 xAttributes
= pMerger
;
852 xAttributes
= _rxAttrList
;
855 // let the base class handle all the attributes
856 OElementImport::StartElement(xAttributes
);
858 if ( !m_aValueProperties
.empty() && m_xElement
.is())
860 // get the property set info
863 OSL_FAIL("OControlImport::StartElement: no PropertySetInfo!");
867 const sal_Char
* pValueProperty
= NULL
;
868 const sal_Char
* pCurrentValueProperty
= NULL
;
869 const sal_Char
* pMinValueProperty
= NULL
;
870 const sal_Char
* pMaxValueProperty
= NULL
;
872 sal_Bool bRetrievedValues
= sal_False
;
873 sal_Bool bRetrievedValueLimits
= sal_False
;
875 // get the class id of our element
876 sal_Int16 nClassId
= FormComponentType::CONTROL
;
877 m_xElement
->getPropertyValue(PROPERTY_CLASSID
) >>= nClassId
;
879 // translate the value properties we collected in handleAttributes
880 PropertyValueArray::iterator aEnd
= m_aValueProperties
.end();
881 for ( PropertyValueArray::iterator aValueProps
= m_aValueProperties
.begin();
886 bool bSuccess
= false;
887 switch (aValueProps
->Handle
)
890 case PROPID_CURRENT_VALUE
:
892 // get the property names
893 if (!bRetrievedValues
)
895 getValuePropertyNames(m_eElementType
, nClassId
, pCurrentValueProperty
, pValueProperty
);
896 if ( !pCurrentValueProperty
&& !pValueProperty
)
898 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value property names!" );
902 bRetrievedValues
= sal_True
;
904 if ( PROPID_VALUE
== aValueProps
->Handle
&& !pValueProperty
)
906 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a value property!");
910 if ( PROPID_CURRENT_VALUE
== aValueProps
->Handle
&& !pCurrentValueProperty
)
912 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: the control does not have a current-value property!");
917 if (PROPID_VALUE
== aValueProps
->Handle
)
918 aValueProps
->Name
= OUString::createFromAscii(pValueProperty
);
920 aValueProps
->Name
= OUString::createFromAscii(pCurrentValueProperty
);
924 case PROPID_MIN_VALUE
:
925 case PROPID_MAX_VALUE
:
927 // get the property names
928 if (!bRetrievedValueLimits
)
930 getValueLimitPropertyNames(nClassId
, pMinValueProperty
, pMaxValueProperty
);
931 if ( !pMinValueProperty
|| !pMaxValueProperty
)
933 SAL_WARN( "xmloff.forms", "OControlImport::StartElement: illegal value limit property names!" );
937 bRetrievedValueLimits
= sal_True
;
939 OSL_ENSURE((PROPID_MIN_VALUE
!= aValueProps
->Handle
) || pMinValueProperty
,
940 "OControlImport::StartElement: the control does not have a value property!");
941 OSL_ENSURE((PROPID_MAX_VALUE
!= aValueProps
->Handle
) || pMaxValueProperty
,
942 "OControlImport::StartElement: the control does not have a current-value property!");
945 if (PROPID_MIN_VALUE
== aValueProps
->Handle
)
946 aValueProps
->Name
= OUString::createFromAscii(pMinValueProperty
);
948 aValueProps
->Name
= OUString::createFromAscii(pMaxValueProperty
);
957 // translate the value
958 implTranslateValueProperty(m_xInfo
, *aValueProps
);
959 // add the property to the base class' array
960 implPushBackPropertyValue(*aValueProps
);
965 //---------------------------------------------------------------------
966 void OControlImport::implTranslateValueProperty(const Reference
< XPropertySetInfo
>& _rxPropInfo
,
967 PropertyValue
& _rPropValue
)
969 OSL_ENSURE(_rxPropInfo
->hasPropertyByName(_rPropValue
.Name
),
970 "OControlImport::implTranslateValueProperty: invalid property name!");
972 // retrieve the type of the property
973 Property aProp
= _rxPropInfo
->getPropertyByName(_rPropValue
.Name
);
974 // the untranslated string value as read in handleAttribute
976 #if OSL_DEBUG_LEVEL > 0
979 _rPropValue
.Value
>>= sValue
;
980 OSL_ENSURE(bSuccess
, "OControlImport::implTranslateValueProperty: supposed to be called with non-translated string values!");
982 if (TypeClass_ANY
== aProp
.Type
.getTypeClass())
984 // we have exactly 2 properties where this type class is allowed:
986 (0 == _rPropValue
.Name
.equals(PROPERTY_EFFECTIVE_VALUE
))
987 || (0 == _rPropValue
.Name
.equals(PROPERTY_EFFECTIVE_DEFAULT
)),
988 "OControlImport::implTranslateValueProperty: invalid property type/name combination!");
990 // Both properties are allowed to have a double or a string value,
991 // so first try to convert the string into a number
993 if (::sax::Converter::convertDouble(nValue
, sValue
))
994 _rPropValue
.Value
<<= nValue
;
996 _rPropValue
.Value
<<= sValue
;
999 _rPropValue
.Value
= PropertyConversion::convertString(GetImport(), aProp
.Type
, sValue
);
1002 //---------------------------------------------------------------------
1003 void OControlImport::EndElement()
1005 OSL_ENSURE(m_xElement
.is(), "OControlImport::EndElement: invalid control!");
1006 if ( !m_xElement
.is() )
1009 // register our control with it's id
1010 if (!m_sControlId
.isEmpty())
1011 m_rFormImport
.registerControlId(m_xElement
, m_sControlId
);
1012 // it's allowed to have no control id. In this case we're importing a column
1014 // one more pre-work to do:
1015 // when we set default values, then by definition the respective value is set
1016 // to this default value, too. This means if the sequence contains for example
1017 // a DefaultText value, then the Text will be affected by this, too.
1018 // In case the Text is not part of the property sequence (or occurs _before_
1019 // the DefaultText, which can happen for other value/default-value property names),
1020 // this means that the Text (the value property) is incorrectly imported.
1022 sal_Bool bRestoreValuePropertyValue
= sal_False
;
1023 Any aValuePropertyValue
;
1025 sal_Int16 nClassId
= FormComponentType::CONTROL
;
1028 // get the class id of our element
1029 m_xElement
->getPropertyValue(PROPERTY_CLASSID
) >>= nClassId
;
1031 catch( const Exception
& )
1033 OSL_FAIL( "OControlImport::EndElement: caught an exception while retrieving the class id!" );
1036 const sal_Char
* pValueProperty
= NULL
;
1037 const sal_Char
* pDefaultValueProperty
= NULL
;
1038 getRuntimeValuePropertyNames(m_eElementType
, nClassId
, pValueProperty
, pDefaultValueProperty
);
1039 if ( pDefaultValueProperty
&& pValueProperty
)
1041 sal_Bool bNonDefaultValuePropertyValue
= sal_False
;
1042 // is the "value property" part of the sequence?
1044 // look up this property in our sequence
1045 PropertyValueArray::iterator aEnd
= m_aValues
.end();
1046 for ( PropertyValueArray::iterator aCheck
= m_aValues
.begin();
1051 if ( aCheck
->Name
.equalsAscii( pDefaultValueProperty
) )
1052 bRestoreValuePropertyValue
= sal_True
;
1053 else if ( aCheck
->Name
.equalsAscii( pValueProperty
) )
1055 bNonDefaultValuePropertyValue
= sal_True
;
1056 // we need to restore the value property we found here, nothing else
1057 aValuePropertyValue
= aCheck
->Value
;
1061 if ( bRestoreValuePropertyValue
&& !bNonDefaultValuePropertyValue
)
1063 // found it -> need to remember (and restore) the "value property value", which is not set explicitly
1066 aValuePropertyValue
= m_xElement
->getPropertyValue( OUString::createFromAscii( pValueProperty
) );
1068 catch( const Exception
& )
1070 OSL_FAIL( "OControlImport::EndElement: caught an exception while retrieving the current value property!" );
1075 // let the base class set all the values
1076 OElementImport::EndElement();
1078 // restore the "value property value", if necessary
1079 if ( bRestoreValuePropertyValue
&& pValueProperty
)
1083 m_xElement
->setPropertyValue( OUString::createFromAscii( pValueProperty
), aValuePropertyValue
);
1085 catch( const Exception
& )
1087 OSL_FAIL( "OControlImport::EndElement: caught an exception while restoring the value property!" );
1091 // the external cell binding, if applicable
1092 if ( m_xElement
.is() && !m_sBoundCellAddress
.isEmpty() )
1093 doRegisterCellValueBinding( m_sBoundCellAddress
);
1095 // XForms binding, if applicable
1096 if ( m_xElement
.is() && !m_sBindingID
.isEmpty() )
1097 doRegisterXFormsValueBinding( m_sBindingID
);
1099 // XForms list binding, if applicable
1100 if ( m_xElement
.is() && !m_sListBindingID
.isEmpty() )
1101 doRegisterXFormsListBinding( m_sListBindingID
);
1103 // XForms submission, if applicable
1104 if ( m_xElement
.is() && !m_sSubmissionID
.isEmpty() )
1105 doRegisterXFormsSubmission( m_sSubmissionID
);
1108 //---------------------------------------------------------------------
1109 void OControlImport::doRegisterCellValueBinding( const OUString
& _rBoundCellAddress
)
1111 OSL_PRECOND( m_xElement
.is(), "OControlImport::doRegisterCellValueBinding: invalid element!" );
1112 OSL_PRECOND( !_rBoundCellAddress
.isEmpty(),
1113 "OControlImport::doRegisterCellValueBinding: invalid address!" );
1115 m_rContext
.registerCellValueBinding( m_xElement
, _rBoundCellAddress
);
1118 //---------------------------------------------------------------------
1119 void OControlImport::doRegisterXFormsValueBinding( const OUString
& _rBindingID
)
1121 OSL_PRECOND( m_xElement
.is(), "need element" );
1122 OSL_PRECOND( !_rBindingID
.isEmpty(), "binding ID is not valid" );
1124 m_rContext
.registerXFormsValueBinding( m_xElement
, _rBindingID
);
1127 //---------------------------------------------------------------------
1128 void OControlImport::doRegisterXFormsListBinding( const OUString
& _rBindingID
)
1130 OSL_PRECOND( m_xElement
.is(), "need element" );
1131 OSL_PRECOND( !_rBindingID
.isEmpty(), "binding ID is not valid" );
1133 m_rContext
.registerXFormsListBinding( m_xElement
, _rBindingID
);
1136 //---------------------------------------------------------------------
1137 void OControlImport::doRegisterXFormsSubmission( const OUString
& _rSubmissionID
)
1139 OSL_PRECOND( m_xElement
.is(), "need element" );
1140 OSL_PRECOND( !_rSubmissionID
.isEmpty(), "binding ID is not valid" );
1142 m_rContext
.registerXFormsSubmission( m_xElement
, _rSubmissionID
);
1145 //---------------------------------------------------------------------
1147 Reference
< XPropertySet
> OControlImport::createElement()
1149 const Reference
<XPropertySet
> xPropSet
= OElementImport::createElement();
1150 if ( xPropSet
.is() )
1152 m_xInfo
= xPropSet
->getPropertySetInfo();
1153 if ( m_xInfo
.is() && m_xInfo
->hasPropertyByName(PROPERTY_ALIGN
) )
1156 xPropSet
->setPropertyValue(PROPERTY_ALIGN
,aValue
);
1162 //=====================================================================
1163 //= OImagePositionImport
1164 //=====================================================================
1165 //---------------------------------------------------------------------
1166 OImagePositionImport::OImagePositionImport( OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
1167 sal_uInt16 _nPrefix
, const OUString
& _rName
, const Reference
< XNameContainer
>& _rxParentContainer
,
1168 OControlElement::ElementType _eType
)
1169 :OControlImport( _rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1170 ,m_nImagePosition( -1 )
1172 ,m_bHaveImagePosition( sal_False
)
1176 //---------------------------------------------------------------------
1177 bool OImagePositionImport::handleAttribute( sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
,
1178 const OUString
& _rValue
)
1180 if ( _rLocalName
== GetXMLToken( XML_IMAGE_POSITION
) )
1182 OSL_VERIFY( PropertyConversion::convertString(
1183 m_rContext
.getGlobalContext(), ::getCppuType( &m_nImagePosition
),
1184 _rValue
, OEnumMapper::getEnumMap( OEnumMapper::epImagePosition
)
1185 ) >>= m_nImagePosition
);
1186 m_bHaveImagePosition
= sal_True
;
1190 if ( _rLocalName
== GetXMLToken( XML_IMAGE_ALIGN
) )
1192 OSL_VERIFY( PropertyConversion::convertString(
1193 m_rContext
.getGlobalContext(), ::getCppuType( &m_nImageAlign
),
1194 _rValue
, OEnumMapper::getEnumMap( OEnumMapper::epImageAlign
)
1195 ) >>= m_nImageAlign
);
1199 return OControlImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1202 //---------------------------------------------------------------------
1203 void OImagePositionImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1205 OControlImport::StartElement( _rxAttrList
);
1207 if ( m_bHaveImagePosition
)
1209 sal_Int16 nUnoImagePosition
= ImagePosition::Centered
;
1210 if ( m_nImagePosition
>= 0 )
1212 OSL_ENSURE( ( m_nImagePosition
<= 3 ) && ( m_nImageAlign
>= 0 ) && ( m_nImageAlign
< 3 ),
1213 "OImagePositionImport::StartElement: unknown image align and/or position!" );
1214 nUnoImagePosition
= m_nImagePosition
* 3 + m_nImageAlign
;
1217 PropertyValue aImagePosition
;
1218 aImagePosition
.Name
= PROPERTY_IMAGE_POSITION
;
1219 aImagePosition
.Value
<<= nUnoImagePosition
;
1220 implPushBackPropertyValue( aImagePosition
);
1224 //=====================================================================
1225 //= OReferredControlImport
1226 //=====================================================================
1227 //---------------------------------------------------------------------
1228 OReferredControlImport::OReferredControlImport(
1229 OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1230 const Reference
< XNameContainer
>& _rxParentContainer
,
1231 OControlElement::ElementType
)
1232 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
)
1236 //---------------------------------------------------------------------
1237 void OReferredControlImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1239 OControlImport::StartElement(_rxAttrList
);
1241 // the base class should have created the control, so we can register it
1242 if ( !m_sReferringControls
.isEmpty() )
1243 m_rFormImport
.registerControlReferences(m_xElement
, m_sReferringControls
);
1246 //---------------------------------------------------------------------
1247 bool OReferredControlImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
,
1248 const OUString
& _rValue
)
1250 static const OUString s_sReferenceAttributeName
= OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_FOR
));
1251 if (_rLocalName
== s_sReferenceAttributeName
)
1253 m_sReferringControls
= _rValue
;
1256 return OControlImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1259 //=====================================================================
1261 //=====================================================================
1262 //---------------------------------------------------------------------
1263 OPasswordImport::OPasswordImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1264 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1265 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1269 //---------------------------------------------------------------------
1270 bool OPasswordImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1272 static const OUString s_sEchoCharAttributeName
= OUString::createFromAscii(OAttributeMetaData::getSpecialAttributeName(SCA_ECHO_CHAR
));
1273 if (_rLocalName
== s_sEchoCharAttributeName
)
1275 // need a special handling for the EchoChar property
1276 PropertyValue aEchoChar
;
1277 aEchoChar
.Name
= PROPERTY_ECHOCHAR
;
1278 OSL_ENSURE(_rValue
.getLength() == 1, "OPasswordImport::handleAttribute: invalid echo char attribute!");
1279 // we ourself should not have written values other than of length 1
1280 if (_rValue
.getLength() >= 1)
1281 aEchoChar
.Value
<<= (sal_Int16
)_rValue
.getStr()[0];
1283 aEchoChar
.Value
<<= (sal_Int16
)0;
1284 implPushBackPropertyValue(aEchoChar
);
1287 return OControlImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1290 //=====================================================================
1292 //=====================================================================
1293 //---------------------------------------------------------------------
1294 ORadioImport::ORadioImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1295 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1296 :OImagePositionImport( _rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1300 //---------------------------------------------------------------------
1301 bool ORadioImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1303 // need special handling for the State & CurrentState properties:
1304 // they're stored as booleans, but expected to be int16 properties
1305 static const sal_Char
* pCurrentSelectedAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED
);
1306 static const sal_Char
* pSelectedAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED
);
1307 if ( _rLocalName
.equalsAscii( pCurrentSelectedAttributeName
)
1308 || _rLocalName
.equalsAscii( pSelectedAttributeName
)
1311 const OAttribute2Property::AttributeAssignment
* pProperty
= m_rContext
.getAttributeMap().getAttributeTranslation(_rLocalName
);
1312 OSL_ENSURE(pProperty
, "ORadioImport::handleAttribute: invalid property map!");
1315 const Any
aBooleanValue( PropertyConversion::convertString(m_rContext
.getGlobalContext(), pProperty
->aPropertyType
, _rValue
, pProperty
->pEnumMap
) );
1317 // create and store a new PropertyValue
1318 PropertyValue aNewValue
;
1319 aNewValue
.Name
= pProperty
->sPropertyName
;
1320 aNewValue
.Value
<<= (sal_Int16
)::cppu::any2bool(aBooleanValue
);
1322 implPushBackPropertyValue(aNewValue
);
1326 return OImagePositionImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1329 //=====================================================================
1330 //= OURLReferenceImport
1331 //=====================================================================
1332 OURLReferenceImport::OURLReferenceImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1333 const Reference
< XNameContainer
>& _rxParentContainer
,
1334 OControlElement::ElementType _eType
)
1335 :OImagePositionImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1339 //---------------------------------------------------------------------
1340 bool OURLReferenceImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1342 static const sal_Char
* s_pTargetLocationAttributeName
= OAttributeMetaData::getCommonControlAttributeName( CCA_TARGET_LOCATION
);
1343 static const sal_Char
* s_pImageDataAttributeName
= OAttributeMetaData::getCommonControlAttributeName( CCA_IMAGE_DATA
);
1345 // need to make the URL absolute if
1346 // * it's the image-data attribute
1347 // * it's the target-location attribute, and we're dealign with an object which has the respective property
1348 sal_Bool bMakeAbsolute
=
1349 ( 0 == _rLocalName
.compareToAscii( s_pImageDataAttributeName
) )
1350 || ( ( 0 == _rLocalName
.compareToAscii( s_pTargetLocationAttributeName
) )
1351 && ( ( OControlElement::BUTTON
== m_eElementType
)
1352 || ( OControlElement::IMAGE
== m_eElementType
)
1356 if ( bMakeAbsolute
&& !_rValue
.isEmpty() )
1358 // make a global URL out of the local one
1359 OUString sAdjustedValue
;
1360 // only resolve image related url
1361 // we don't want say form url targets to be resolved
1362 // using ResolveGraphicObjectURL
1363 if ( 0 == _rLocalName
.compareToAscii( s_pImageDataAttributeName
) )
1364 sAdjustedValue
= m_rContext
.getGlobalContext().ResolveGraphicObjectURL( _rValue
, sal_False
);
1366 sAdjustedValue
= m_rContext
.getGlobalContext().GetAbsoluteReference( _rValue
);
1367 return OImagePositionImport::handleAttribute( _nNamespaceKey
, _rLocalName
, sAdjustedValue
);
1370 return OImagePositionImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1373 //=====================================================================
1375 //=====================================================================
1376 //---------------------------------------------------------------------
1377 OButtonImport::OButtonImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1378 const Reference
< XNameContainer
>& _rxParentContainer
,
1379 OControlElement::ElementType _eType
)
1380 :OURLReferenceImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1382 enableTrackAttributes();
1385 //---------------------------------------------------------------------
1386 void OButtonImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1388 OURLReferenceImport::StartElement(_rxAttrList
);
1390 // handle the target-frame attribute
1391 simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME
), PROPERTY_TARGETFRAME
, "_blank");
1394 //=====================================================================
1395 //= OValueRangeImport
1396 //=====================================================================
1397 //---------------------------------------------------------------------
1398 OValueRangeImport::OValueRangeImport( OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1399 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1400 :OControlImport( _rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1401 ,m_nStepSizeValue( 1 )
1406 //---------------------------------------------------------------------
1407 bool OValueRangeImport::handleAttribute( sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1409 if ( _rLocalName
.equalsAscii( OAttributeMetaData::getSpecialAttributeName( SCA_STEP_SIZE
) ) )
1411 ::sax::Converter::convertNumber( m_nStepSizeValue
, _rValue
);
1414 return OControlImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1417 //---------------------------------------------------------------------
1418 void OValueRangeImport::StartElement( const Reference
< XAttributeList
>& _rxAttrList
)
1420 OControlImport::StartElement( _rxAttrList
);
1424 if ( m_xInfo
->hasPropertyByName( PROPERTY_SPIN_INCREMENT
) )
1425 m_xElement
->setPropertyValue( PROPERTY_SPIN_INCREMENT
, makeAny( m_nStepSizeValue
) );
1426 else if ( m_xInfo
->hasPropertyByName( PROPERTY_LINE_INCREMENT
) )
1427 m_xElement
->setPropertyValue( PROPERTY_LINE_INCREMENT
, makeAny( m_nStepSizeValue
) );
1431 //=====================================================================
1433 //=====================================================================
1434 //---------------------------------------------------------------------
1435 OTextLikeImport::OTextLikeImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1436 const Reference
< XNameContainer
>& _rxParentContainer
,
1437 OControlElement::ElementType _eType
)
1438 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1439 ,m_bEncounteredTextPara( false )
1441 enableTrackAttributes();
1444 //---------------------------------------------------------------------
1445 SvXMLImportContext
* OTextLikeImport::CreateChildContext( sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
1446 const Reference
< XAttributeList
>& _rxAttrList
)
1448 if ( ( XML_NAMESPACE_TEXT
== _nPrefix
) && _rLocalName
.equalsIgnoreAsciiCase("p") )
1450 OSL_ENSURE( m_eElementType
== OControlElement::TEXT_AREA
,
1451 "OTextLikeImport::CreateChildContext: text paragraphs in a non-text-area?" );
1453 if ( m_eElementType
== OControlElement::TEXT_AREA
)
1455 Reference
< XText
> xTextElement( m_xElement
, UNO_QUERY
);
1456 if ( xTextElement
.is() )
1458 UniReference
< XMLTextImportHelper
> xTextImportHelper( m_rContext
.getGlobalContext().GetTextImport() );
1460 if ( !m_xCursor
.is() )
1462 m_xOldCursor
= xTextImportHelper
->GetCursor();
1463 m_xCursor
= xTextElement
->createTextCursor();
1465 if ( m_xCursor
.is() )
1466 xTextImportHelper
->SetCursor( m_xCursor
);
1468 if ( m_xCursor
.is() )
1470 m_bEncounteredTextPara
= true;
1471 return xTextImportHelper
->CreateTextChildContext( m_rContext
.getGlobalContext(), _nPrefix
, _rLocalName
, _rxAttrList
);
1476 // in theory, we could accumulate all the text portions (without formatting),
1477 // and set it as Text property at the model ...
1482 return OControlImport::CreateChildContext( _nPrefix
, _rLocalName
, _rxAttrList
);
1485 //---------------------------------------------------------------------
1486 void OTextLikeImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1488 OControlImport::StartElement(_rxAttrList
);
1490 // handle the convert-empty-to-null attribute, whose default is different from the property default
1491 // unfortunately, different classes are imported by this class ('cause they're represented by the
1492 // same XML element), though not all of them know this property.
1493 // So we have to do a check ...
1494 if (m_xElement
.is() && m_xInfo
.is() && m_xInfo
->hasPropertyByName(PROPERTY_EMPTY_IS_NULL
) )
1495 simulateDefaultedAttribute(OAttributeMetaData::getDatabaseAttributeName(DA_CONVERT_EMPTY
), PROPERTY_EMPTY_IS_NULL
, "false");
1498 //---------------------------------------------------------------------
1499 struct EqualHandle
: public ::std::unary_function
< PropertyValue
, bool >
1501 const sal_Int32 m_nHandle
;
1502 EqualHandle( sal_Int32 _nHandle
) : m_nHandle( _nHandle
) { }
1504 inline bool operator()( const PropertyValue
& _rProp
)
1506 return _rProp
.Handle
== m_nHandle
;
1510 //---------------------------------------------------------------------
1511 void OTextLikeImport::removeRedundantCurrentValue()
1513 if ( m_bEncounteredTextPara
)
1515 // In case the text is written in the text:p elements, we need to ignore what we read as
1516 // current-value attribute, since it's redundant.
1517 // fortunately, OElementImport tagged the value property with the PROPID_CURRENT_VALUE
1518 // handle, so we do not need to determine the name of our value property here
1519 // (normally, it should be "Text", since no other controls than the edit field should
1520 // have the text:p elements)
1521 PropertyValueArray::iterator aValuePropertyPos
= ::std::find_if(
1524 EqualHandle( PROPID_CURRENT_VALUE
)
1526 if ( aValuePropertyPos
!= m_aValues
.end() )
1528 OSL_ENSURE( aValuePropertyPos
->Name
== PROPERTY_TEXT
, "OTextLikeImport::EndElement: text:p was present, but our value property is *not* 'Text'!" );
1529 if ( aValuePropertyPos
->Name
== PROPERTY_TEXT
)
1532 aValuePropertyPos
+ 1,
1536 m_aValues
.resize( m_aValues
.size() - 1 );
1540 // additionally, we need to set the "RichText" property of our element to sal_True
1541 // (the presence of the text:p is used as indicator for the value of the RichText property)
1542 sal_Bool bHasRichTextProperty
= sal_False
;
1544 bHasRichTextProperty
= m_xInfo
->hasPropertyByName( PROPERTY_RICH_TEXT
);
1545 OSL_ENSURE( bHasRichTextProperty
, "OTextLikeImport::EndElement: text:p, but no rich text control?" );
1546 if ( bHasRichTextProperty
)
1547 m_xElement
->setPropertyValue( PROPERTY_RICH_TEXT
, makeAny( (sal_Bool
)sal_True
) );
1549 // Note that we do *not* set the RichText property (in case our element has one) to sal_False here
1550 // since this is the default of this property, anyway.
1553 //---------------------------------------------------------------------
1554 struct EqualName
: public ::std::unary_function
< PropertyValue
, bool >
1556 const OUString m_sName
;
1557 EqualName( const OUString
& _rName
) : m_sName( _rName
) { }
1559 inline bool operator()( const PropertyValue
& _rProp
)
1561 return _rProp
.Name
== m_sName
;
1565 //---------------------------------------------------------------------
1566 void OTextLikeImport::adjustDefaultControlProperty()
1568 // In OpenOffice.org 2.0, we changed the implementation of the css.form.component.TextField (the model of a text field control),
1569 // so that it now uses another default control. So if we encounter a text field where the *old* default
1570 // control property is writing, we are not allowed to use it
1571 PropertyValueArray::iterator aDefaultControlPropertyPos
= ::std::find_if(
1574 EqualName( OUString( "DefaultControl" ) )
1576 if ( aDefaultControlPropertyPos
!= m_aValues
.end() )
1578 OUString sDefaultControl
;
1579 OSL_VERIFY( aDefaultControlPropertyPos
->Value
>>= sDefaultControl
);
1580 if ( sDefaultControl
== "stardiv.one.form.control.Edit" )
1582 // complete remove this property value from the array. Today's "default value" of the "DefaultControl"
1583 // property is sufficient
1585 aDefaultControlPropertyPos
+ 1,
1587 aDefaultControlPropertyPos
1589 m_aValues
.resize( m_aValues
.size() - 1 );
1594 //---------------------------------------------------------------------
1595 void OTextLikeImport::EndElement()
1597 removeRedundantCurrentValue();
1598 adjustDefaultControlProperty();
1600 // let the base class do the stuff
1601 OControlImport::EndElement();
1604 UniReference
< XMLTextImportHelper
> xTextImportHelper( m_rContext
.getGlobalContext().GetTextImport() );
1605 if ( m_xCursor
.is() )
1607 // delete the newline which has been imported errornously
1608 // TODO (fs): stole this code somewhere - why don't we fix the text import??
1609 m_xCursor
->gotoEnd( sal_False
);
1610 m_xCursor
->goLeft( 1, sal_True
);
1611 m_xCursor
->setString( OUString() );
1614 xTextImportHelper
->ResetCursor();
1617 if ( m_xOldCursor
.is() )
1618 xTextImportHelper
->SetCursor( m_xOldCursor
);
1622 //=====================================================================
1623 //= OListAndComboImport
1624 //=====================================================================
1625 //---------------------------------------------------------------------
1626 OListAndComboImport::OListAndComboImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1627 const Reference
< XNameContainer
>& _rxParentContainer
,
1628 OControlElement::ElementType _eType
)
1629 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1630 ,m_nEmptyListItems( 0 )
1631 ,m_nEmptyValueItems( 0 )
1632 ,m_bEncounteredLSAttrib( sal_False
)
1633 ,m_bLinkWithIndexes( sal_False
)
1635 if (OControlElement::COMBOBOX
== m_eElementType
)
1636 enableTrackAttributes();
1639 //---------------------------------------------------------------------
1640 SvXMLImportContext
* OListAndComboImport::CreateChildContext(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
1641 const Reference
< XAttributeList
>& _rxAttrList
)
1643 // is it the "option" sub tag of a listbox ?
1644 static const OUString
s_sOptionElementName("option");
1645 if (s_sOptionElementName
== _rLocalName
)
1646 return new OListOptionImport(GetImport(), _nPrefix
, _rLocalName
, this);
1648 // is it the "item" sub tag of a combobox ?
1649 static const OUString
s_sItemElementName("item");
1650 if (s_sItemElementName
== _rLocalName
)
1651 return new OComboItemImport(GetImport(), _nPrefix
, _rLocalName
, this);
1654 return OControlImport::CreateChildContext(_nPrefix
, _rLocalName
, _rxAttrList
);
1657 //---------------------------------------------------------------------
1658 void OListAndComboImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1660 m_bLinkWithIndexes
= sal_False
;
1662 OControlImport::StartElement(_rxAttrList
);
1664 if (OControlElement::COMBOBOX
== m_eElementType
)
1666 // for the auto-completion
1667 // the attribute default does not equal the property default, so in case we did not read this attribute,
1668 // we have to simulate it
1669 simulateDefaultedAttribute( OAttributeMetaData::getSpecialAttributeName( SCA_AUTOMATIC_COMPLETION
), PROPERTY_AUTOCOMPLETE
, "false");
1671 // same for the convert-empty-to-null attribute, which's default is different from the property default
1672 simulateDefaultedAttribute( OAttributeMetaData::getDatabaseAttributeName( DA_CONVERT_EMPTY
), PROPERTY_EMPTY_IS_NULL
, "false");
1676 //---------------------------------------------------------------------
1677 void OListAndComboImport::EndElement()
1679 // append the list source property the properties sequence of our importer
1680 // the string item list
1681 PropertyValue aItemList
;
1682 aItemList
.Name
= PROPERTY_STRING_ITEM_LIST
;
1683 aItemList
.Value
<<= m_aListSource
;
1684 implPushBackPropertyValue(aItemList
);
1686 if (OControlElement::LISTBOX
== m_eElementType
)
1688 OSL_ENSURE((m_aListSource
.getLength() + m_nEmptyListItems
) == (m_aValueList
.getLength() + m_nEmptyValueItems
),
1689 "OListAndComboImport::EndElement: inconsistence between labels and values!");
1691 if ( !m_bEncounteredLSAttrib
)
1693 // the value sequence
1694 PropertyValue aValueList
;
1695 aValueList
.Name
= PROPERTY_LISTSOURCE
;
1696 aValueList
.Value
<<= m_aValueList
;
1697 implPushBackPropertyValue(aValueList
);
1700 // the select sequence
1701 PropertyValue aSelected
;
1702 aSelected
.Name
= PROPERTY_SELECT_SEQ
;
1703 aSelected
.Value
<<= m_aSelectedSeq
;
1704 implPushBackPropertyValue(aSelected
);
1706 // the default select sequence
1707 PropertyValue aDefaultSelected
;
1708 aDefaultSelected
.Name
= PROPERTY_DEFAULT_SELECT_SEQ
;
1709 aDefaultSelected
.Value
<<= m_aDefaultSelectedSeq
;
1710 implPushBackPropertyValue(aDefaultSelected
);
1713 OControlImport::EndElement();
1715 // the external list source, if applicable
1716 if ( m_xElement
.is() && !m_sCellListSource
.isEmpty() )
1717 m_rContext
.registerCellRangeListSource( m_xElement
, m_sCellListSource
);
1720 //---------------------------------------------------------------------
1721 void OListAndComboImport::doRegisterCellValueBinding( const OUString
& _rBoundCellAddress
)
1723 OUString
sBoundCellAddress( _rBoundCellAddress
);
1724 if ( m_bLinkWithIndexes
)
1726 // This is a HACK. We register a string which is no valid address, but allows
1727 // (somewhere else) to determine that a non-standard binding should be created.
1728 // This hack is acceptable for OOo 1.1.1, since the file format for value
1729 // bindings of form controls is to be changed afterwards, anyway.
1730 sBoundCellAddress
+= OUString( ":index" );
1733 OControlImport::doRegisterCellValueBinding( sBoundCellAddress
);
1736 //---------------------------------------------------------------------
1737 bool OListAndComboImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
1739 static const sal_Char
* pListSourceAttributeName
= OAttributeMetaData::getDatabaseAttributeName(DA_LIST_SOURCE
);
1740 if ( _rLocalName
.equalsAscii(pListSourceAttributeName
) )
1742 PropertyValue aListSource
;
1743 aListSource
.Name
= PROPERTY_LISTSOURCE
;
1745 // it's the ListSource attribute
1746 m_bEncounteredLSAttrib
= sal_True
;
1747 if ( OControlElement::COMBOBOX
== m_eElementType
)
1749 aListSource
.Value
<<= _rValue
;
1753 // a listbox which has a list-source attribute must have a list-source-type of something
1754 // not equal to ValueList.
1755 // In this case, the list-source value is simply the one and only element of the ListSource property.
1756 Sequence
< OUString
> aListSourcePropValue( 1 );
1757 aListSourcePropValue
[0] = _rValue
;
1758 aListSource
.Value
<<= aListSourcePropValue
;
1761 implPushBackPropertyValue( aListSource
);
1765 if ( _rLocalName
.equalsAscii( OAttributeMetaData::getBindingAttributeName( BA_LIST_CELL_RANGE
) ) )
1767 m_sCellListSource
= _rValue
;
1771 if ( _rLocalName
.equalsAscii( OAttributeMetaData::getBindingAttributeName( BA_LIST_LINKING_TYPE
) ) )
1773 sal_Int16 nLinkageType
= 0;
1774 PropertyConversion::convertString(
1775 m_rContext
.getGlobalContext(),
1776 ::getCppuType( static_cast< sal_Int16
* >( NULL
) ),
1778 OEnumMapper::getEnumMap( OEnumMapper::epListLinkageType
)
1781 m_bLinkWithIndexes
= ( nLinkageType
!= 0 );
1785 return OControlImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1788 //---------------------------------------------------------------------
1789 void OListAndComboImport::implPushBackLabel(const OUString
& _rLabel
)
1791 OSL_ENSURE(!m_nEmptyListItems
, "OListAndComboImport::implPushBackValue: label list is already done!");
1792 if (!m_nEmptyListItems
)
1793 pushBackSequenceElement(m_aListSource
, _rLabel
);
1796 //---------------------------------------------------------------------
1797 void OListAndComboImport::implPushBackValue(const OUString
& _rValue
)
1799 OSL_ENSURE(!m_nEmptyValueItems
, "OListAndComboImport::implPushBackValue: value list is already done!");
1800 if (!m_nEmptyValueItems
)
1802 OSL_ENSURE( !m_bEncounteredLSAttrib
, "OListAndComboImport::implPushBackValue: invalid structure! Did you save this document with a version prior SRC641 m?" );
1803 // We already had the list-source attribute, which means that the ListSourceType is
1804 // not ValueList, which means that the ListSource should contain only one string in
1805 // the first element of the sequence
1806 // All other values in the file are invalid
1808 pushBackSequenceElement( m_aValueList
, _rValue
);
1812 //---------------------------------------------------------------------
1813 void OListAndComboImport::implEmptyLabelFound()
1815 ++m_nEmptyListItems
;
1818 //---------------------------------------------------------------------
1819 void OListAndComboImport::implEmptyValueFound()
1821 ++m_nEmptyValueItems
;
1824 //---------------------------------------------------------------------
1825 void OListAndComboImport::implSelectCurrentItem()
1827 OSL_ENSURE((m_aListSource
.getLength() + m_nEmptyListItems
) == (m_aValueList
.getLength() + m_nEmptyValueItems
),
1828 "OListAndComboImport::implSelectCurrentItem: inconsistence between labels and values!");
1830 sal_Int16 nItemNumber
= (sal_Int16
)(m_aListSource
.getLength() - 1 + m_nEmptyListItems
);
1831 pushBackSequenceElement(m_aSelectedSeq
, nItemNumber
);
1834 //---------------------------------------------------------------------
1835 void OListAndComboImport::implDefaultSelectCurrentItem()
1837 OSL_ENSURE((m_aListSource
.getLength() + m_nEmptyListItems
) == (m_aValueList
.getLength() + m_nEmptyValueItems
),
1838 "OListAndComboImport::implDefaultSelectCurrentItem: inconsistence between labels and values!");
1840 sal_Int16 nItemNumber
= (sal_Int16
)(m_aListSource
.getLength() - 1 + m_nEmptyListItems
);
1841 pushBackSequenceElement(m_aDefaultSelectedSeq
, nItemNumber
);
1844 //=====================================================================
1845 //= OListOptionImport
1846 //=====================================================================
1847 //---------------------------------------------------------------------
1848 OListOptionImport::OListOptionImport(SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1849 const OListAndComboImportRef
& _rListBox
)
1850 :SvXMLImportContext(_rImport
, _nPrefix
, _rName
)
1851 ,m_xListBoxImport(_rListBox
)
1855 //---------------------------------------------------------------------
1856 void OListOptionImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1858 // the label and the value
1859 const SvXMLNamespaceMap
& rMap
= GetImport().GetNamespaceMap();
1860 const OUString sLabelAttribute
= rMap
.GetQNameByKey(
1861 GetPrefix(), OUString("label"));
1862 const OUString sValueAttribute
= rMap
.GetQNameByKey(
1863 GetPrefix(), OUString("value"));
1865 // -------------------
1866 // the label attribute
1867 OUString sValue
= _rxAttrList
->getValueByName(sLabelAttribute
);
1868 sal_Bool bNonexistentAttribute
= sal_False
;
1869 if (sValue
.isEmpty())
1870 if (_rxAttrList
->getTypeByName(sLabelAttribute
).isEmpty())
1871 // this attribute does not really exist
1872 bNonexistentAttribute
= sal_True
;
1874 if (bNonexistentAttribute
)
1875 m_xListBoxImport
->implEmptyLabelFound();
1877 m_xListBoxImport
->implPushBackLabel( sValue
);
1879 // -------------------
1880 // the value attribute
1881 sValue
= _rxAttrList
->getValueByName(sValueAttribute
);
1882 bNonexistentAttribute
= sal_False
;
1883 if (sValue
.isEmpty())
1884 if (_rxAttrList
->getTypeByName(sValueAttribute
).isEmpty())
1885 // this attribute does not really exist
1886 bNonexistentAttribute
= sal_True
;
1888 if (bNonexistentAttribute
)
1889 m_xListBoxImport
->implEmptyValueFound();
1891 m_xListBoxImport
->implPushBackValue( sValue
);
1893 // the current-selected and selected
1894 const OUString sSelectedAttribute
= rMap
.GetQNameByKey(
1895 GetPrefix(), OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED
)));
1896 const OUString sDefaultSelectedAttribute
= rMap
.GetQNameByKey(
1897 GetPrefix(), OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED
)));
1899 // propagate the selected flag
1900 bool bSelected(false);
1901 ::sax::Converter::convertBool(bSelected
,
1902 _rxAttrList
->getValueByName(sSelectedAttribute
));
1904 m_xListBoxImport
->implSelectCurrentItem();
1906 // same for the default selected
1907 bool bDefaultSelected(false);
1908 ::sax::Converter::convertBool(bDefaultSelected
,
1909 _rxAttrList
->getValueByName(sDefaultSelectedAttribute
));
1910 if (bDefaultSelected
)
1911 m_xListBoxImport
->implDefaultSelectCurrentItem();
1913 SvXMLImportContext::StartElement(_rxAttrList
);
1916 //=====================================================================
1917 //= OComboItemImport
1918 //=====================================================================
1919 //---------------------------------------------------------------------
1920 OComboItemImport::OComboItemImport(SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1921 const OListAndComboImportRef
& _rListBox
)
1922 :SvXMLImportContext(_rImport
, _nPrefix
, _rName
)
1923 ,m_xListBoxImport(_rListBox
)
1927 //---------------------------------------------------------------------
1928 void OComboItemImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1930 const OUString sLabelAttributeName
= GetImport().GetNamespaceMap().GetQNameByKey(
1931 GetPrefix(), OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_LABEL
)));
1932 m_xListBoxImport
->implPushBackLabel(_rxAttrList
->getValueByName(sLabelAttributeName
));
1934 SvXMLImportContext::StartElement(_rxAttrList
);
1938 //=====================================================================
1939 //= OColumnWrapperImport
1940 //=====================================================================
1941 //---------------------------------------------------------------------
1942 OColumnWrapperImport::OColumnWrapperImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
1943 const Reference
< XNameContainer
>& _rxParentContainer
)
1944 :SvXMLImportContext(_rImport
.getGlobalContext(), _nPrefix
, _rName
)
1945 ,m_xParentContainer(_rxParentContainer
)
1946 ,m_rFormImport(_rImport
)
1947 ,m_rEventManager(_rEventManager
)
1950 //---------------------------------------------------------------------
1951 SvXMLImportContext
* OColumnWrapperImport::CreateChildContext(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
1952 const Reference
< XAttributeList
>&)
1954 OControlImport
* pReturn
= implCreateChildContext(_nPrefix
, _rLocalName
, OElementNameMap::getElementType(_rLocalName
));
1957 OSL_ENSURE(m_xOwnAttributes
.is(), "OColumnWrapperImport::CreateChildContext: had no form:column element!");
1958 pReturn
->addOuterAttributes(m_xOwnAttributes
);
1962 //---------------------------------------------------------------------
1963 void OColumnWrapperImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
1965 OSL_ENSURE(!m_xOwnAttributes
.is(), "OColumnWrapperImport::StartElement: aready have the cloned list!");
1967 // clone the attributes
1968 Reference
< XCloneable
> xCloneList(_rxAttrList
, UNO_QUERY
);
1969 OSL_ENSURE(xCloneList
.is(), "OColumnWrapperImport::StartElement: AttributeList not cloneable!");
1970 if ( xCloneList
.is() )
1971 m_xOwnAttributes
= Reference
< XAttributeList
>(xCloneList
->createClone(), UNO_QUERY
);
1972 OSL_ENSURE(m_xOwnAttributes
.is(), "OColumnWrapperImport::StartElement: no cloned list!");
1975 //---------------------------------------------------------------------
1976 OControlImport
* OColumnWrapperImport::implCreateChildContext(
1977 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
1978 OControlElement::ElementType _eType
)
1980 OSL_ENSURE( (OControlElement::TEXT
== _eType
)
1981 || (OControlElement::TEXT_AREA
== _eType
)
1982 || (OControlElement::FORMATTED_TEXT
== _eType
)
1983 || (OControlElement::CHECKBOX
== _eType
)
1984 || (OControlElement::LISTBOX
== _eType
)
1985 || (OControlElement::COMBOBOX
== _eType
)
1986 || (OControlElement::TIME
== _eType
)
1987 || (OControlElement::DATE
== _eType
),
1988 "OColumnWrapperImport::implCreateChildContext: invalid or unrecognized sub element!");
1992 case OControlElement::COMBOBOX
:
1993 case OControlElement::LISTBOX
:
1994 return new OColumnImport
<OListAndComboImport
>(m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1996 case OControlElement::PASSWORD
:
1997 return new OColumnImport
<OPasswordImport
>(m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1999 case OControlElement::TEXT
:
2000 case OControlElement::TEXT_AREA
:
2001 case OControlElement::FORMATTED_TEXT
:
2002 return new OColumnImport
< OTextLikeImport
>( m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
2005 return new OColumnImport
<OControlImport
>(m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
2009 //=====================================================================
2011 //=====================================================================
2012 //---------------------------------------------------------------------
2013 OGridImport::OGridImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
2014 const Reference
< XNameContainer
>& _rxParentContainer
,
2015 OControlElement::ElementType _eType
)
2016 :OGridImport_Base(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, "column")
2018 setElementType(_eType
);
2021 //---------------------------------------------------------------------
2022 SvXMLImportContext
* OGridImport::implCreateControlWrapper(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
)
2024 return new OColumnWrapperImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
);
2027 //=====================================================================
2029 //=====================================================================
2030 //---------------------------------------------------------------------
2031 OFormImport::OFormImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const OUString
& _rName
,
2032 const Reference
< XNameContainer
>& _rxParentContainer
)
2033 :OFormImport_Base(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, "control")
2035 enableTrackAttributes();
2038 //---------------------------------------------------------------------
2039 SvXMLImportContext
* OFormImport::CreateChildContext(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
2040 const Reference
< XAttributeList
>& _rxAttrList
)
2042 if( token::IsXMLToken(_rLocalName
, token::XML_FORM
) )
2043 return new OFormImport( m_rFormImport
, *this, _nPrefix
, _rLocalName
,
2045 else if ( token::IsXMLToken(_rLocalName
, token::XML_CONNECTION_RESOURCE
) )
2046 return new OXMLDataSourceImport(GetImport(), _nPrefix
, _rLocalName
, _rxAttrList
,m_xElement
);
2047 else if( (token::IsXMLToken(_rLocalName
, token::XML_EVENT_LISTENERS
) &&
2048 (XML_NAMESPACE_OFFICE
== _nPrefix
)) ||
2049 token::IsXMLToken( _rLocalName
, token::XML_PROPERTIES
) )
2050 return OElementImport::CreateChildContext( _nPrefix
, _rLocalName
,
2053 return implCreateChildContext( _nPrefix
, _rLocalName
,
2054 OElementNameMap::getElementType(_rLocalName
) );
2057 //---------------------------------------------------------------------
2058 void OFormImport::StartElement(const Reference
< XAttributeList
>& _rxAttrList
)
2060 m_rFormImport
.enterEventContext();
2061 OFormImport_Base::StartElement(_rxAttrList
);
2063 // handle the target-frame attribute
2064 simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME
), PROPERTY_TARGETFRAME
, "_blank");
2067 //---------------------------------------------------------------------
2068 void OFormImport::EndElement()
2070 OFormImport_Base::EndElement();
2071 m_rFormImport
.leaveEventContext();
2074 //---------------------------------------------------------------------
2075 SvXMLImportContext
* OFormImport::implCreateControlWrapper(sal_uInt16 _nPrefix
, const OUString
& _rLocalName
)
2077 OSL_ENSURE( !this, "illegal call to OFormImport::implCreateControlWrapper" );
2078 return new SvXMLImportContext(GetImport(), _nPrefix
, _rLocalName
);
2081 //---------------------------------------------------------------------
2082 bool OFormImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const OUString
& _rLocalName
, const OUString
& _rValue
)
2084 // handle the master/details field attributes (they're way too special to let the OPropertyImport handle them)
2085 static const OUString s_sMasterFieldsAttributeName
= OUString::createFromAscii(OAttributeMetaData::getFormAttributeName(faMasterFields
));
2086 static const OUString s_sDetailFieldsAttributeName
= OUString::createFromAscii(OAttributeMetaData::getFormAttributeName(faDetailFiels
));
2088 if ( s_sMasterFieldsAttributeName
== _rLocalName
)
2090 implTranslateStringListProperty(PROPERTY_MASTERFIELDS
, _rValue
);
2094 if ( s_sDetailFieldsAttributeName
== _rLocalName
)
2096 implTranslateStringListProperty(PROPERTY_DETAILFIELDS
, _rValue
);
2100 return OFormImport_Base::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
2103 //---------------------------------------------------------------------
2104 void OFormImport::implTranslateStringListProperty(const OUString
& _rPropertyName
, const OUString
& _rValue
)
2106 PropertyValue aProp
;
2107 aProp
.Name
= _rPropertyName
;
2109 Sequence
< OUString
> aList
;
2111 // split up the value string
2112 if (!_rValue
.isEmpty())
2114 // For the moment, we build a vector instead of a Sequence. It's easier to handle because of it's
2116 ::std::vector
< OUString
> aElements
;
2117 // estimate the number of tokens
2118 sal_Int32 nEstimate
= 0, nLength
= _rValue
.getLength();
2119 const sal_Unicode
* pChars
= _rValue
.getStr();
2120 for (sal_Int32 i
=0; i
<nLength
; ++i
, ++pChars
)
2123 aElements
.reserve(nEstimate
+ 1);
2124 // that's the worst case. If the string contains the separator character _quoted_, we reserved to much ...
2127 sal_Int32 nElementStart
= 0;
2128 sal_Int32 nNextSep
= 0;
2129 sal_Int32 nElementLength
;
2133 // extract the current element
2134 nNextSep
= ::sax::Converter::indexOfComma(
2135 _rValue
, nElementStart
);
2138 sElement
= _rValue
.copy(nElementStart
, nNextSep
- nElementStart
);
2140 nElementLength
= sElement
.getLength();
2141 // when writing the sequence, we quoted the single elements with " characters
2142 OSL_ENSURE( (nElementLength
>= 2)
2143 && (sElement
.getStr()[0] == '"')
2144 && (sElement
.getStr()[nElementLength
- 1] == '"'),
2145 "OFormImport::implTranslateStringListProperty: invalid quoted element name.");
2146 sElement
= sElement
.copy(1, nElementLength
- 2);
2148 aElements
.push_back(sElement
);
2150 // swith to the next element
2151 nElementStart
= 1 + nNextSep
;
2153 while (nElementStart
< nLength
);
2155 OUString
*pElements
= aElements
.empty() ? 0 : &aElements
[0];
2156 aList
= Sequence
< OUString
>(pElements
, aElements
.size());
2160 OSL_FAIL("OFormImport::implTranslateStringListProperty: invalid value (empty)!");
2163 aProp
.Value
<<= aList
;
2165 // add the property to the base class' array
2166 implPushBackPropertyValue(aProp
);
2168 //=====================================================================
2169 //= OXMLDataSourceImport
2170 //=====================================================================
2171 OXMLDataSourceImport::OXMLDataSourceImport(
2172 SvXMLImport
& _rImport
2174 , const OUString
& _sLocalName
2175 ,const Reference
< ::com::sun::star::xml::sax::XAttributeList
> & _xAttrList
2176 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xElement
) :
2177 SvXMLImportContext( _rImport
, nPrfx
, _sLocalName
)
2179 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
2180 const SvXMLNamespaceMap
& rMap
= _rImport
.GetNamespaceMap();
2182 sal_Int16 nLength
= (_xElement
.is() && _xAttrList
.is()) ? _xAttrList
->getLength() : 0;
2183 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
2185 OUString sLocalName
;
2186 OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
2187 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
, &sLocalName
);
2189 if ( ( nPrefix
== OAttributeMetaData::getCommonControlAttributeNamespace( CCA_TARGET_LOCATION
) )
2190 && ( sLocalName
.equalsAscii( OAttributeMetaData::getCommonControlAttributeName( CCA_TARGET_LOCATION
) ) )
2193 OUString sValue
= _xAttrList
->getValueByIndex( i
);
2195 INetURLObject
aURL(sValue
);
2196 if ( aURL
.GetProtocol() == INET_PROT_FILE
)
2197 _xElement
->setPropertyValue(PROPERTY_DATASOURCENAME
,makeAny(sValue
));
2199 _xElement
->setPropertyValue(PROPERTY_URL
,makeAny(sValue
)); // the url is the "sdbc:" string
2204 //---------------------------------------------------------------------
2205 OControlImport
* OFormImport::implCreateChildContext(
2206 sal_uInt16 _nPrefix
, const OUString
& _rLocalName
,
2207 OControlElement::ElementType _eType
)
2211 case OControlElement::TEXT
:
2212 case OControlElement::TEXT_AREA
:
2213 case OControlElement::FORMATTED_TEXT
:
2214 return new OTextLikeImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2216 case OControlElement::BUTTON
:
2217 case OControlElement::IMAGE
:
2218 case OControlElement::IMAGE_FRAME
:
2219 return new OButtonImport( m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2221 case OControlElement::COMBOBOX
:
2222 case OControlElement::LISTBOX
:
2223 return new OListAndComboImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2225 case OControlElement::RADIO
:
2226 return new ORadioImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2228 case OControlElement::CHECKBOX
:
2229 return new OImagePositionImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2231 case OControlElement::PASSWORD
:
2232 return new OPasswordImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2234 case OControlElement::FRAME
:
2235 case OControlElement::FIXED_TEXT
:
2236 return new OReferredControlImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2238 case OControlElement::GRID
:
2239 return new OGridImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2241 case OControlElement::VALUERANGE
:
2242 return new OValueRangeImport( m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2245 return new OControlImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2249 //.........................................................................
2250 } // namespace xmloff
2251 //.........................................................................
2253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */