1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: elementimport.cxx,v $
10 * $Revision: 1.60.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "elementimport.hxx"
36 #include <xmloff/xmlimp.hxx>
37 #include <xmloff/nmspmap.hxx>
38 #include <xmloff/xmluconv.hxx>
39 #include "strings.hxx"
40 #include "callbacks.hxx"
41 #include "attriblistmerge.hxx"
42 #include "xmlnmspe.hxx"
43 #include "eventimport.hxx"
44 #include <xmloff/txtstyli.hxx>
45 #include "formenums.hxx"
46 #include <xmloff/xmltoken.hxx>
47 #include "gridcolumnproptranslator.hxx"
48 #include <comphelper/extract.hxx>
49 #include <comphelper/types.hxx>
51 /** === begin UNO includes === **/
52 #include <com/sun/star/text/XText.hpp>
53 #include <com/sun/star/util/XCloneable.hpp>
54 #include <com/sun/star/form/FormComponentType.hpp>
55 #include <com/sun/star/awt/ImagePosition.hpp>
56 #include <com/sun/star/beans/XMultiPropertySet.hpp>
57 #include <com/sun/star/beans/XPropertyContainer.hpp>
58 #include <com/sun/star/beans/PropertyAttribute.hpp>
59 /** === end UNO includes === **/
60 #include <tools/urlobj.hxx>
61 #include <tools/time.hxx>
62 #include <rtl/logfile.hxx>
67 //.........................................................................
70 //.........................................................................
72 using namespace ::xmloff::token
;
73 using namespace ::com::sun::star
;
74 using namespace ::com::sun::star::uno
;
75 using namespace ::com::sun::star::awt
;
76 using namespace ::com::sun::star::container
;
77 using namespace ::com::sun::star::beans
;
78 using namespace ::com::sun::star::script
;
79 using namespace ::com::sun::star::lang
;
80 using namespace ::com::sun::star::form
;
81 using namespace ::com::sun::star::xml
;
82 using namespace ::com::sun::star::util
;
83 using namespace ::com::sun::star::text
;
84 using namespace ::comphelper
;
86 #define PROPID_VALUE 1
87 #define PROPID_CURRENT_VALUE 2
88 #define PROPID_MIN_VALUE 3
89 #define PROPID_MAX_VALUE 4
91 //=====================================================================
92 struct PropertyValueLess
94 sal_Bool
operator()(const PropertyValue
& _rLeft
, const PropertyValue
& _rRight
)
96 return _rLeft
.Name
< _rRight
.Name
;
100 //=====================================================================
101 struct PropertyValueCompare
: public ::std::binary_function
< PropertyValue
, ::rtl::OUString
, bool>
103 bool operator() (const PropertyValue
& lhs
, const ::rtl::OUString
& rhs
) const
105 return lhs
.Name
== rhs
;
107 bool operator() (const ::rtl::OUString
& lhs
, const PropertyValue
& rhs
) const
109 return lhs
== rhs
.Name
;
113 //=====================================================================
114 template <class ELEMENT
>
115 void pushBackSequenceElement(Sequence
< ELEMENT
>& _rContainer
, const ELEMENT
& _rElement
)
117 sal_Int32 nLen
= _rContainer
.getLength();
118 _rContainer
.realloc(nLen
+ 1);
119 _rContainer
[nLen
] = _rElement
;
122 //=====================================================================
124 //=====================================================================
125 //---------------------------------------------------------------------
126 OElementNameMap::MapString2Element
OElementNameMap::s_sElementTranslations
;
128 //---------------------------------------------------------------------
129 const OControlElement::ElementType
& operator ++(OControlElement::ElementType
& _e
)
131 OControlElement::ElementType e
= _e
;
132 sal_Int32 nAsInt
= static_cast<sal_Int32
>(e
);
133 _e
= static_cast<OControlElement::ElementType
>( ++nAsInt
);
137 //---------------------------------------------------------------------
138 OControlElement::ElementType
OElementNameMap::getElementType(const ::rtl::OUString
& _rName
)
140 if ( s_sElementTranslations
.empty() )
142 for (ElementType eType
=(ElementType
)0; eType
<UNKNOWN
; ++eType
)
143 s_sElementTranslations
[::rtl::OUString::createFromAscii(getElementName(eType
))] = eType
;
145 ConstMapString2ElementIterator aPos
= s_sElementTranslations
.find(_rName
);
146 if (s_sElementTranslations
.end() != aPos
)
152 //=====================================================================
154 //=====================================================================
155 //---------------------------------------------------------------------
156 OElementImport::OElementImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
157 const Reference
< XNameContainer
>& _rxParentContainer
)
158 :OPropertyImport(_rImport
, _nPrefix
, _rName
)
159 ,m_rFormImport(_rImport
)
160 ,m_rEventManager(_rEventManager
)
161 ,m_pStyleElement( NULL
)
162 ,m_xParentContainer(_rxParentContainer
)
164 OSL_ENSURE(m_xParentContainer
.is(), "OElementImport::OElementImport: invalid parent container!");
167 //---------------------------------------------------------------------
168 OElementImport::~OElementImport()
172 //---------------------------------------------------------------------
173 void OElementImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
175 ENTER_LOG_CONTEXT( "xmloff::OElementImport - importing one element" );
176 // call the base class. This should give us enough information (especially the service name)
177 // to create our UNO element
178 OPropertyImport::StartElement(_rxAttrList
);
180 // create the element
181 m_xElement
= createElement();
182 if ( !m_xInfo
.is() && m_xElement
.is() )
183 m_xInfo
= m_xElement
->getPropertySetInfo();
186 //---------------------------------------------------------------------
187 SvXMLImportContext
* OElementImport::CreateChildContext(sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rLocalName
,
188 const Reference
< sax::XAttributeList
>& _rxAttrList
)
190 if( token::IsXMLToken(_rLocalName
, token::XML_EVENT_LISTENERS
) && (XML_NAMESPACE_OFFICE
== _nPrefix
))
191 return new OFormEventsImportContext(m_rFormImport
.getGlobalContext(), _nPrefix
, _rLocalName
, *this);
193 return OPropertyImport::CreateChildContext(_nPrefix
, _rLocalName
, _rxAttrList
);
196 //---------------------------------------------------------------------
197 void OElementImport::EndElement()
199 OSL_ENSURE(m_xElement
.is(), "OElementImport::EndElement: invalid element created!");
200 if (!m_xElement
.is())
203 // set all the properties we collected
204 #if OSL_DEBUG_LEVEL > 0
205 // check if the object has all the properties
206 // (We do this in the non-pro version only. Doing it all the time would be much to expensive)
209 PropertyValueArray::iterator aEnd
= m_aValues
.end();
210 for ( PropertyValueArray::iterator aCheck
= m_aValues
.begin();
215 OSL_ENSURE(m_xInfo
->hasPropertyByName(aCheck
->Name
),
216 ::rtl::OString("OElementImport::EndElement: read a property (")
217 += ::rtl::OString(aCheck
->Name
.getStr(), aCheck
->Name
.getLength(), RTL_TEXTENCODING_ASCII_US
)
218 += ::rtl::OString(") which does not exist on the element!"));
222 OSL_ENSURE(!m_aValues
.empty(), "OElementImport::EndElement: no properties read!");
224 // set the properties
225 const Reference
< XMultiPropertySet
> xMultiProps(m_xElement
, UNO_QUERY
);
226 sal_Bool bSuccess
= sal_False
;
227 if (xMultiProps
.is())
229 // translate our properties so that the XMultiPropertySet can handle them
231 // sort our property value array so that we can use it in a setPropertyValues
232 ::std::sort( m_aValues
.begin(), m_aValues
.end(), PropertyValueLess());
235 Sequence
< ::rtl::OUString
> aNames(m_aValues
.size());
236 ::rtl::OUString
* pNames
= aNames
.getArray();
238 Sequence
< Any
> aValues(m_aValues
.size());
239 Any
* pValues
= aValues
.getArray();
242 PropertyValueArray::iterator aEnd
= m_aValues
.end();
243 for ( PropertyValueArray::iterator aPropValues
= m_aValues
.begin();
245 ++aPropValues
, ++pNames
, ++pValues
248 *pNames
= aPropValues
->Name
;
249 *pValues
= aPropValues
->Value
;
254 xMultiProps
->setPropertyValues(aNames
, aValues
);
259 OSL_ENSURE(sal_False
, "OElementImport::EndElement: could not set the properties (using the XMultiPropertySet)!");
264 { // no XMultiPropertySet or setting all properties at once failed
265 PropertyValueArray::iterator aEnd
= m_aValues
.end();
266 for ( PropertyValueArray::iterator aPropValues
= m_aValues
.begin();
271 // this try/catch here is expensive, but because this is just a fallback which should normally not be
272 // used it's acceptable this way ...
275 m_xElement
->setPropertyValue(aPropValues
->Name
, aPropValues
->Value
);
279 OSL_ENSURE(sal_False
,
280 ::rtl::OString("OElementImport::EndElement: could not set the property \"")
281 += ::rtl::OString(aPropValues
->Name
.getStr(), aPropValues
->Name
.getLength(), RTL_TEXTENCODING_ASCII_US
)
282 += ::rtl::OString("\"!"));
287 // set the generic properties
288 implImportGenericProperties();
290 // set the style properties
291 if ( m_pStyleElement
&& m_xElement
.is() )
293 Reference
< XPropertySet
> xPropTranslation
=
294 new OGridColumnPropertyTranslator( Reference
< XMultiPropertySet
>( m_xElement
, UNO_QUERY
) );
295 const_cast< XMLTextStyleContext
* >( m_pStyleElement
)->FillPropertySet( xPropTranslation
);
297 const ::rtl::OUString sNumberStyleName
= const_cast< XMLTextStyleContext
* >( m_pStyleElement
)->GetDataStyleName( );
298 if ( sNumberStyleName
.getLength() )
299 // the style also has a number (sub) style
300 m_rContext
.applyControlNumberStyle( m_xElement
, sNumberStyleName
);
303 // insert the element into the parent container
304 if (!m_sName
.getLength())
306 OSL_ENSURE(sal_False
, "OElementImport::EndElement: did not find a name attribute!");
307 m_sName
= implGetDefaultName();
310 m_xParentContainer
->insertByName(m_sName
, makeAny(m_xElement
));
311 LEAVE_LOG_CONTEXT( );
314 //---------------------------------------------------------------------
315 void OElementImport::implImportGenericProperties()
317 if ( m_aGenericValues
.empty() )
320 Reference
< XPropertyContainer
> xDynamicProperties( m_xElement
, UNO_QUERY
);
322 PropertyValueArray::iterator aEnd
= m_aGenericValues
.end();
323 for ( PropertyValueArray::iterator aPropValues
=
324 m_aGenericValues
.begin();
329 // check property type for numeric types before setting
333 // if such a property does not yet exist at the element, create it if necessary
334 const bool bExistentProperty
= m_xInfo
->hasPropertyByName( aPropValues
->Name
);
335 if ( !bExistentProperty
)
337 if ( !xDynamicProperties
.is() )
339 #if OSL_DEBUG_LEVEL > 0
340 ::rtl::OString
aMessage( "OElementImport::implImportGenericProperties: encountered an unknown property (" );
341 aMessage
+= ::rtl::OUStringToOString( aPropValues
->Name
, RTL_TEXTENCODING_ASCII_US
);
342 aMessage
+= "), but component is no PropertyBag!";
343 OSL_ENSURE( false, aMessage
.getStr() );
348 xDynamicProperties
->addProperty(
350 PropertyAttribute::BOUND
| PropertyAttribute::REMOVEABLE
,
354 // re-fetch the PropertySetInfo
355 m_xInfo
= m_xElement
->getPropertySetInfo();
358 // determine the type of the value (source forthe following conversion)
359 TypeClass eValueTypeClass
= aPropValues
->Value
.getValueTypeClass();
360 const sal_Bool bValueIsSequence
= TypeClass_SEQUENCE
== eValueTypeClass
;
361 if ( bValueIsSequence
)
363 uno::Type
aSimpleType( getSequenceElementType( aPropValues
->Value
.getValueType() ) );
364 eValueTypeClass
= aSimpleType
.getTypeClass();
367 // determine the type of the property (target forthe following conversion)
368 const Property
aProperty( m_xInfo
->getPropertyByName( aPropValues
->Name
) );
369 TypeClass ePropTypeClass
= aProperty
.Type
.getTypeClass();
370 const sal_Bool bPropIsSequence
= TypeClass_SEQUENCE
== ePropTypeClass
;
371 if( bPropIsSequence
)
373 uno::Type
aSimpleType( ::comphelper::getSequenceElementType( aProperty
.Type
) );
374 ePropTypeClass
= aSimpleType
.getTypeClass();
377 if ( bPropIsSequence
!= bValueIsSequence
)
379 OSL_ENSURE( false, "OElementImport::implImportGenericProperties: either both value and property should be a sequence, or none of them!" );
383 if ( bValueIsSequence
)
385 OSL_ENSURE( eValueTypeClass
== TypeClass_ANY
,
386 "OElementImport::implImportGenericProperties: only ANYs should have been imported as generic list property!" );
387 // (OPropertyImport should produce only Sequencer< Any >, since it cannot know the real type
389 OSL_ENSURE( ePropTypeClass
== TypeClass_SHORT
,
390 "OElementImport::implImportGenericProperties: conversion to sequences other than 'sequence< short >' not implemented, yet!" );
392 Sequence
< Any
> aXMLValueList
;
393 aPropValues
->Value
>>= aXMLValueList
;
394 Sequence
< sal_Int16
> aPropertyValueList( aXMLValueList
.getLength() );
396 const Any
* pXMLValue
= aXMLValueList
.getConstArray();
397 sal_Int16
* pPropValue
= aPropertyValueList
.getArray();
399 for ( sal_Int32 i
=0; i
<aXMLValueList
.getLength(); ++i
, ++pXMLValue
, ++pPropValue
)
401 // only value sequences of numeric types implemented so far.
403 OSL_VERIFY( *pXMLValue
>>= nVal
);
404 *pPropValue
= static_cast< sal_Int16
>( nVal
);
407 aPropValues
->Value
<<= aPropertyValueList
;
409 else if ( ePropTypeClass
!= eValueTypeClass
)
411 switch ( eValueTypeClass
)
413 case TypeClass_DOUBLE
:
416 aPropValues
->Value
>>= nVal
;
417 switch( ePropTypeClass
)
420 aPropValues
->Value
<<= static_cast< sal_Int8
>( nVal
);
422 case TypeClass_SHORT
:
423 aPropValues
->Value
<<= static_cast< sal_Int16
>( nVal
);
427 aPropValues
->Value
<<= static_cast< sal_Int32
>( nVal
);
429 case TypeClass_HYPER
:
430 aPropValues
->Value
<<= static_cast< sal_Int64
>( nVal
);
433 OSL_ENSURE( false, "OElementImport::implImportGenericProperties: unsupported value type!" );
439 OSL_ENSURE( false, "OElementImport::implImportGenericProperties: non-double values not supported!" );
444 m_xElement
->setPropertyValue( aPropValues
->Name
, aPropValues
->Value
);
448 OSL_ENSURE(sal_False
,
449 ::rtl::OString("OElementImport::EndElement: could not set the property \"")
450 += ::rtl::OString(aPropValues
->Name
.getStr(), aPropValues
->Name
.getLength(), RTL_TEXTENCODING_ASCII_US
)
451 += ::rtl::OString("\"!"));
456 //---------------------------------------------------------------------
457 ::rtl::OUString
OElementImport::implGetDefaultName() const
459 // no optimization here. If this method gets called, the XML stream did not contain a name for the
460 // element, which is a heavy error. So in this case we don't care for performance
461 Sequence
< ::rtl::OUString
> aNames
= m_xParentContainer
->getElementNames();
462 static const ::rtl::OUString sUnnamedName
= ::rtl::OUString::createFromAscii("unnamed");
464 ::rtl::OUString sReturn
;
465 const ::rtl::OUString
* pNames
= NULL
;
466 const ::rtl::OUString
* pNamesEnd
= aNames
.getConstArray() + aNames
.getLength();
467 for (sal_Int32 i
=0; i
<32768; ++i
) // the limit is nearly arbitrary ...
469 // assemble the new name (suggestion)
470 sReturn
= sUnnamedName
;
471 sReturn
+= ::rtl::OUString::valueOf(i
);
472 // check the existence (this is the bad performance part ....)
473 for (pNames
= aNames
.getConstArray(); pNames
<pNamesEnd
; ++pNames
)
475 if (*pNames
== sReturn
)
480 if (pNames
<pNamesEnd
)
485 OSL_ENSURE(sal_False
, "OElementImport::implGetDefaultName: did not find a free name!");
489 //---------------------------------------------------------------------
490 void OElementImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
, const ::rtl::OUString
& _rValue
)
492 if (!m_sServiceName
.getLength() &&
493 token::IsXMLToken( _rLocalName
, token::XML_CONTROL_IMPLEMENTATION
))
494 { // it's the service name
496 ::rtl::OUString sImplName
;
497 const sal_uInt16 nImplPrefix
=
498 GetImport().GetNamespaceMap().GetKeyByAttrName( _rValue
,
500 m_sServiceName
= XML_NAMESPACE_OOO
==nImplPrefix
? sImplName
505 if (!m_sName
.getLength() &&
506 token::IsXMLToken( _rLocalName
, token::XML_NAME
))
507 // remember the name for later use in EndElement
510 // maybe it's the style attribute?
511 if ( token::IsXMLToken( _rLocalName
, token::XML_TEXT_STYLE_NAME
) )
513 const SvXMLStyleContext
* pStyleContext
= m_rContext
.getStyleElement( _rValue
);
514 OSL_ENSURE( pStyleContext
, "OPropertyImport::handleAttribute: do not know the style!" );
515 // remember the element for later usage.
516 m_pStyleElement
= PTR_CAST( XMLTextStyleContext
, pStyleContext
);
519 // let the base class handle it
520 OPropertyImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
524 //---------------------------------------------------------------------
525 Reference
< XPropertySet
> OElementImport::createElement()
527 Reference
< XPropertySet
> xReturn
;
528 if (m_sServiceName
.getLength())
530 Reference
< XInterface
> xPure
= m_rFormImport
.getGlobalContext().getServiceFactory()->createInstance(m_sServiceName
);
531 OSL_ENSURE(xPure
.is(),
532 ::rtl::OString("OElementImport::createElement: service factory gave me no object (service name: ")
533 += ::rtl::OString(m_sServiceName
.getStr(), m_sServiceName
.getLength(), RTL_TEXTENCODING_ASCII_US
)
534 += ::rtl::OString(")!"));
535 xReturn
= Reference
< XPropertySet
>(xPure
, UNO_QUERY
);
538 OSL_ENSURE(sal_False
, "OElementImport::createElement: no service name to create an element!");
543 //---------------------------------------------------------------------
544 void OElementImport::registerEvents(const Sequence
< ScriptEventDescriptor
>& _rEvents
)
546 OSL_ENSURE(m_xElement
.is(), "OElementImport::registerEvents: no element to register events for!");
547 m_rEventManager
.registerEvents(m_xElement
, _rEvents
);
550 //---------------------------------------------------------------------
551 void OElementImport::simulateDefaultedAttribute(const sal_Char
* _pAttributeName
, const ::rtl::OUString
& _rPropertyName
, const sal_Char
* _pAttributeDefault
)
553 OSL_ENSURE( m_xInfo
.is(), "OPropertyImport::simulateDefaultedAttribute: the component should be more gossipy about it's properties!" );
555 if ( !m_xInfo
.is() || m_xInfo
->hasPropertyByName( _rPropertyName
) )
557 ::rtl::OUString sLocalAttrName
= ::rtl::OUString::createFromAscii(_pAttributeName
);
558 if ( !encounteredAttribute( sLocalAttrName
) )
559 handleAttribute( XML_NAMESPACE_FORM
, sLocalAttrName
, ::rtl::OUString::createFromAscii( _pAttributeDefault
) );
563 //=====================================================================
565 //=====================================================================
566 //---------------------------------------------------------------------
567 OControlImport::OControlImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
568 const Reference
< XNameContainer
>& _rxParentContainer
)
569 :OElementImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
)
570 ,m_eElementType(OControlElement::UNKNOWN
)
574 //---------------------------------------------------------------------
575 OControlImport::OControlImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
576 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
577 :OElementImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
)
578 ,m_eElementType(_eType
)
582 //---------------------------------------------------------------------
583 void OControlImport::addOuterAttributes(const Reference
< sax::XAttributeList
>& _rxOuterAttribs
)
585 OSL_ENSURE(!m_xOuterAttributes
.is(), "OControlImport::addOuterAttributes: already have these attributes!");
586 m_xOuterAttributes
= _rxOuterAttribs
;
589 //---------------------------------------------------------------------
590 void OControlImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
, const ::rtl::OUString
& _rValue
)
592 static const sal_Char
* pControlIdAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCA_CONTROL_ID
);
593 static const sal_Char
* pLinkedCellAttributeName
= OAttributeMetaData::getBindingAttributeName(BA_LINKED_CELL
);
595 if ( !m_sControlId
.getLength() && _rLocalName
.equalsAscii( pControlIdAttributeName
) )
596 { // it's the control id
597 m_sControlId
= _rValue
;
599 else if ( _rLocalName
.equalsAscii( pLinkedCellAttributeName
) )
600 { // it's the address of a spreadsheet cell
601 m_sBoundCellAddress
= _rValue
;
603 else if ( _nNamespaceKey
== XML_NAMESPACE_XFORMS
&& IsXMLToken( _rLocalName
, XML_BIND
) )
605 m_sBindingID
= _rValue
;
607 else if ( _nNamespaceKey
== XML_NAMESPACE_FORM
&& IsXMLToken( _rLocalName
, XML_XFORMS_LIST_SOURCE
) )
609 m_sListBindingID
= _rValue
;
611 else if ( (_nNamespaceKey
== XML_NAMESPACE_FORM
&& IsXMLToken( _rLocalName
, XML_XFORMS_SUBMISSION
) ) ||
612 ( _nNamespaceKey
== XML_NAMESPACE_XFORMS
&& IsXMLToken( _rLocalName
, XML_SUBMISSION
) ) )
614 m_sSubmissionID
= _rValue
;
618 static const sal_Char
* pValueAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCA_VALUE
);
619 static const sal_Char
* pCurrentValueAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_VALUE
);
620 static const sal_Char
* pMinValueAttributeName
= OAttributeMetaData::getSpecialAttributeName(SCA_MIN_VALUE
);
621 static const sal_Char
* pMaxValueAttributeName
= OAttributeMetaData::getSpecialAttributeName(SCA_MAX_VALUE
);
622 static const sal_Char
* pRepeatDelayAttributeName
= OAttributeMetaData::getSpecialAttributeName( SCA_REPEAT_DELAY
);
624 sal_Int32 nHandle
= -1;
625 if ( _rLocalName
.equalsAscii( pValueAttributeName
) )
626 nHandle
= PROPID_VALUE
;
627 else if ( _rLocalName
.equalsAscii( pCurrentValueAttributeName
) )
628 nHandle
= PROPID_CURRENT_VALUE
;
629 else if ( _rLocalName
.equalsAscii( pMinValueAttributeName
) )
630 nHandle
= PROPID_MIN_VALUE
;
631 else if ( _rLocalName
.equalsAscii( pMaxValueAttributeName
) )
632 nHandle
= PROPID_MAX_VALUE
;
635 // for the moment, simply remember the name and the value
637 aProp
.Name
= _rLocalName
;
638 aProp
.Handle
= nHandle
;
639 aProp
.Value
<<= _rValue
;
640 m_aValueProperties
.push_back(aProp
);
642 else if ( _rLocalName
.equalsAscii( pRepeatDelayAttributeName
) )
645 sal_Int32 nFractions
= 0;
646 if ( SvXMLUnitConverter::convertTimeDuration( _rValue
, aTime
, &nFractions
) )
649 aProp
.Name
= PROPERTY_REPEAT_DELAY
;
650 aProp
.Value
<<= (sal_Int32
)( ( ( aTime
.GetMSFromTime() / 1000 ) * 1000 ) + nFractions
);
652 implPushBackPropertyValue(aProp
);
656 OElementImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
660 //---------------------------------------------------------------------
661 void OControlImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
663 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
> xAttributes
;
664 if( m_xOuterAttributes
.is() )
666 // merge the attribute lists
667 OAttribListMerger
* pMerger
= new OAttribListMerger
;
669 pMerger
->addList(_rxAttrList
);
670 // and the ones of our enclosing element
671 pMerger
->addList(m_xOuterAttributes
);
672 xAttributes
= pMerger
;
676 xAttributes
= _rxAttrList
;
679 // let the base class handle all the attributes
680 OElementImport::StartElement(xAttributes
);
682 if ( !m_aValueProperties
.empty() && m_xElement
.is())
684 // get the property set info
687 OSL_ENSURE(sal_False
, "OControlImport::StartElement: no PropertySetInfo!");
691 const sal_Char
* pValueProperty
= NULL
;
692 const sal_Char
* pCurrentValueProperty
= NULL
;
693 const sal_Char
* pMinValueProperty
= NULL
;
694 const sal_Char
* pMaxValueProperty
= NULL
;
696 sal_Bool bRetrievedValues
= sal_False
;
697 sal_Bool bRetrievedValueLimits
= sal_False
;
699 // get the class id of our element
700 sal_Int16 nClassId
= FormComponentType::CONTROL
;
701 m_xElement
->getPropertyValue(PROPERTY_CLASSID
) >>= nClassId
;
703 // translate the value properties we collected in handleAttributes
704 PropertyValueArray::iterator aEnd
= m_aValueProperties
.end();
705 for ( PropertyValueArray::iterator aValueProps
= m_aValueProperties
.begin();
710 switch (aValueProps
->Handle
)
713 case PROPID_CURRENT_VALUE
:
715 // get the property names
716 if (!bRetrievedValues
)
718 getValuePropertyNames(m_eElementType
, nClassId
, pCurrentValueProperty
, pValueProperty
);
719 bRetrievedValues
= sal_True
;
721 OSL_ENSURE((PROPID_VALUE
!= aValueProps
->Handle
) || pValueProperty
,
722 "OControlImport::StartElement: the control does not have a value property!");
723 OSL_ENSURE((PROPID_CURRENT_VALUE
!= aValueProps
->Handle
) || pCurrentValueProperty
,
724 "OControlImport::StartElement: the control does not have a current-value property!");
727 if (PROPID_VALUE
== aValueProps
->Handle
)
728 aValueProps
->Name
= ::rtl::OUString::createFromAscii(pValueProperty
);
730 aValueProps
->Name
= ::rtl::OUString::createFromAscii(pCurrentValueProperty
);
733 case PROPID_MIN_VALUE
:
734 case PROPID_MAX_VALUE
:
736 // get the property names
737 if (!bRetrievedValueLimits
)
739 getValueLimitPropertyNames(nClassId
, pMinValueProperty
, pMaxValueProperty
);
740 bRetrievedValueLimits
= sal_True
;
742 OSL_ENSURE((PROPID_MIN_VALUE
!= aValueProps
->Handle
) || pMinValueProperty
,
743 "OControlImport::StartElement: the control does not have a value property!");
744 OSL_ENSURE((PROPID_MAX_VALUE
!= aValueProps
->Handle
) || pMaxValueProperty
,
745 "OControlImport::StartElement: the control does not have a current-value property!");
748 if (PROPID_MIN_VALUE
== aValueProps
->Handle
)
749 aValueProps
->Name
= ::rtl::OUString::createFromAscii(pMinValueProperty
);
751 aValueProps
->Name
= ::rtl::OUString::createFromAscii(pMaxValueProperty
);
756 // translate the value
757 implTranslateValueProperty(m_xInfo
, *aValueProps
);
758 // add the property to the base class' array
759 implPushBackPropertyValue(*aValueProps
);
764 //---------------------------------------------------------------------
765 void OControlImport::implTranslateValueProperty(const Reference
< XPropertySetInfo
>& _rxPropInfo
,
766 PropertyValue
& _rPropValue
)
768 OSL_ENSURE(_rxPropInfo
->hasPropertyByName(_rPropValue
.Name
),
769 "OControlImport::implTranslateValueProperty: invalid property name!");
771 // retrieve the type of the property
772 Property aProp
= _rxPropInfo
->getPropertyByName(_rPropValue
.Name
);
773 // the untranslated string value as read in handleAttribute
774 ::rtl::OUString sValue
;
775 #if OSL_DEBUG_LEVEL > 0
778 _rPropValue
.Value
>>= sValue
;
779 OSL_ENSURE(bSuccess
, "OControlImport::implTranslateValueProperty: supposed to be called with non-translated string values!");
781 if (TypeClass_ANY
== aProp
.Type
.getTypeClass())
783 // we have exactly 2 properties where this type class is allowed:
785 (0 == _rPropValue
.Name
.compareToAscii(PROPERTY_EFFECTIVE_VALUE
))
786 || (0 == _rPropValue
.Name
.compareToAscii(PROPERTY_EFFECTIVE_DEFAULT
)),
787 "OControlImport::implTranslateValueProperty: invalid property type/name combination!");
789 // Both properties are allowed to have a double or a string value,
790 // so first try to convert the string into a number
792 if (GetImport().GetMM100UnitConverter().convertDouble(nValue
, sValue
))
793 _rPropValue
.Value
<<= nValue
;
795 _rPropValue
.Value
<<= sValue
;
798 _rPropValue
.Value
= PropertyConversion::convertString(GetImport(), aProp
.Type
, sValue
);
801 //---------------------------------------------------------------------
802 void OControlImport::EndElement()
804 OSL_ENSURE(m_xElement
.is(), "OControlImport::EndElement: invalid control!");
805 if ( !m_xElement
.is() )
808 // register our control with it's id
809 if (m_sControlId
.getLength())
810 m_rFormImport
.registerControlId(m_xElement
, m_sControlId
);
811 // it's allowed to have no control id. In this case we're importing a column
813 // one more pre-work to do:
814 // when we set default values, then by definition the respective value is set
815 // to this default value, too. This means if the sequence contains for example
816 // a DefaultText value, then the Text will be affected by this, too.
817 // In case the Text is not part of the property sequence (or occurs _before_
818 // the DefaultText, which can happen for other value/default-value property names),
819 // this means that the Text (the value property) is incorrectly imported.
820 // #102475# - 04.09.2002 - fs@openoffice.org
822 sal_Bool bRestoreValuePropertyValue
= sal_False
;
823 Any aValuePropertyValue
;
825 sal_Int16 nClassId
= FormComponentType::CONTROL
;
828 // get the class id of our element
829 m_xElement
->getPropertyValue(PROPERTY_CLASSID
) >>= nClassId
;
831 catch( const Exception
& )
833 OSL_ENSURE( sal_False
, "OControlImport::EndElement: caught an exception while retrieving the class id!" );
836 const sal_Char
* pValueProperty
= NULL
;
837 const sal_Char
* pDefaultValueProperty
= NULL
;
838 getRuntimeValuePropertyNames(m_eElementType
, nClassId
, pValueProperty
, pDefaultValueProperty
);
839 if ( pDefaultValueProperty
&& pValueProperty
)
841 sal_Bool bNonDefaultValuePropertyValue
= sal_False
;
842 // is the "value property" part of the sequence?
844 // look up this property in our sequence
845 PropertyValueArray::iterator aEnd
= m_aValues
.end();
846 for ( PropertyValueArray::iterator aCheck
= m_aValues
.begin();
851 if ( aCheck
->Name
.equalsAscii( pDefaultValueProperty
) )
852 bRestoreValuePropertyValue
= sal_True
;
853 else if ( aCheck
->Name
.equalsAscii( pValueProperty
) )
855 bNonDefaultValuePropertyValue
= sal_True
;
856 // we need to restore the value property we found here, nothing else
857 aValuePropertyValue
= aCheck
->Value
;
861 if ( bRestoreValuePropertyValue
&& !bNonDefaultValuePropertyValue
)
863 // found it -> need to remember (and restore) the "value property value", which is not set explicitly
866 aValuePropertyValue
= m_xElement
->getPropertyValue( ::rtl::OUString::createFromAscii( pValueProperty
) );
868 catch( const Exception
& )
870 OSL_ENSURE( sal_False
, "OControlImport::EndElement: caught an exception while retrieving the current value property!" );
875 // let the base class set all the values
876 OElementImport::EndElement();
878 // restore the "value property value", if necessary
879 if ( bRestoreValuePropertyValue
&& pValueProperty
)
883 m_xElement
->setPropertyValue( ::rtl::OUString::createFromAscii( pValueProperty
), aValuePropertyValue
);
885 catch( const Exception
& )
887 OSL_ENSURE( sal_False
, "OControlImport::EndElement: caught an exception while restoring the value property!" );
891 // the external cell binding, if applicable
892 if ( m_xElement
.is() && m_sBoundCellAddress
.getLength() )
893 doRegisterCellValueBinding( m_sBoundCellAddress
);
895 // XForms binding, if applicable
896 if ( m_xElement
.is() && m_sBindingID
.getLength() )
897 doRegisterXFormsValueBinding( m_sBindingID
);
899 // XForms list binding, if applicable
900 if ( m_xElement
.is() && m_sListBindingID
.getLength() )
901 doRegisterXFormsListBinding( m_sListBindingID
);
903 // XForms submission, if applicable
904 if ( m_xElement
.is() && m_sSubmissionID
.getLength() )
905 doRegisterXFormsSubmission( m_sSubmissionID
);
908 //---------------------------------------------------------------------
909 void OControlImport::doRegisterCellValueBinding( const ::rtl::OUString
& _rBoundCellAddress
)
911 OSL_PRECOND( m_xElement
.is(), "OControlImport::doRegisterCellValueBinding: invalid element!" );
912 OSL_PRECOND( _rBoundCellAddress
.getLength(),
913 "OControlImport::doRegisterCellValueBinding: invalid address!" );
915 m_rContext
.registerCellValueBinding( m_xElement
, _rBoundCellAddress
);
918 //---------------------------------------------------------------------
919 void OControlImport::doRegisterXFormsValueBinding( const ::rtl::OUString
& _rBindingID
)
921 OSL_PRECOND( m_xElement
.is(), "need element" );
922 OSL_PRECOND( _rBindingID
.getLength() > 0, "binding ID is not valid" );
924 m_rContext
.registerXFormsValueBinding( m_xElement
, _rBindingID
);
927 //---------------------------------------------------------------------
928 void OControlImport::doRegisterXFormsListBinding( const ::rtl::OUString
& _rBindingID
)
930 OSL_PRECOND( m_xElement
.is(), "need element" );
931 OSL_PRECOND( _rBindingID
.getLength() > 0, "binding ID is not valid" );
933 m_rContext
.registerXFormsListBinding( m_xElement
, _rBindingID
);
936 //---------------------------------------------------------------------
937 void OControlImport::doRegisterXFormsSubmission( const ::rtl::OUString
& _rSubmissionID
)
939 OSL_PRECOND( m_xElement
.is(), "need element" );
940 OSL_PRECOND( _rSubmissionID
.getLength() > 0, "binding ID is not valid" );
942 m_rContext
.registerXFormsSubmission( m_xElement
, _rSubmissionID
);
945 //---------------------------------------------------------------------
946 //added by BerryJia for fixing bug102407 2002-11-5
947 Reference
< XPropertySet
> OControlImport::createElement()
949 const Reference
<XPropertySet
> xPropSet
= OElementImport::createElement();
952 m_xInfo
= xPropSet
->getPropertySetInfo();
953 if ( m_xInfo
.is() && m_xInfo
->hasPropertyByName(PROPERTY_ALIGN
) )
956 xPropSet
->setPropertyValue(PROPERTY_ALIGN
,aValue
);
962 //=====================================================================
963 //= OImagePositionImport
964 //=====================================================================
965 //---------------------------------------------------------------------
966 OImagePositionImport::OImagePositionImport( OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
,
967 sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
, const Reference
< XNameContainer
>& _rxParentContainer
,
968 OControlElement::ElementType _eType
)
969 :OControlImport( _rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
970 ,m_nImagePosition( -1 )
972 ,m_bHaveImagePosition( sal_False
)
976 //---------------------------------------------------------------------
977 void OImagePositionImport::handleAttribute( sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
,
978 const ::rtl::OUString
& _rValue
)
980 if ( _rLocalName
== GetXMLToken( XML_IMAGE_POSITION
) )
982 OSL_VERIFY( PropertyConversion::convertString(
983 m_rContext
.getGlobalContext(), ::getCppuType( &m_nImagePosition
),
984 _rValue
, OEnumMapper::getEnumMap( OEnumMapper::epImagePosition
)
985 ) >>= m_nImagePosition
);
986 m_bHaveImagePosition
= sal_True
;
988 else if ( _rLocalName
== GetXMLToken( XML_IMAGE_ALIGN
) )
990 OSL_VERIFY( PropertyConversion::convertString(
991 m_rContext
.getGlobalContext(), ::getCppuType( &m_nImageAlign
),
992 _rValue
, OEnumMapper::getEnumMap( OEnumMapper::epImageAlign
)
993 ) >>= m_nImageAlign
);
996 OControlImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
999 //---------------------------------------------------------------------
1000 void OImagePositionImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
1002 OControlImport::StartElement( _rxAttrList
);
1004 if ( m_bHaveImagePosition
)
1006 sal_Int16 nUnoImagePosition
= ImagePosition::Centered
;
1007 if ( m_nImagePosition
>= 0 )
1009 OSL_ENSURE( ( m_nImagePosition
<= 3 ) && ( m_nImageAlign
>= 0 ) && ( m_nImageAlign
< 3 ),
1010 "OImagePositionImport::StartElement: unknown image align and/or position!" );
1011 nUnoImagePosition
= m_nImagePosition
* 3 + m_nImageAlign
;
1014 PropertyValue aImagePosition
;
1015 aImagePosition
.Name
= PROPERTY_IMAGE_POSITION
;
1016 aImagePosition
.Value
<<= nUnoImagePosition
;
1017 implPushBackPropertyValue( aImagePosition
);
1021 //=====================================================================
1022 //= OReferredControlImport
1023 //=====================================================================
1024 //---------------------------------------------------------------------
1025 OReferredControlImport::OReferredControlImport(
1026 OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1027 const Reference
< XNameContainer
>& _rxParentContainer
,
1028 OControlElement::ElementType
)
1029 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
)
1033 //---------------------------------------------------------------------
1034 void OReferredControlImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
1036 OControlImport::StartElement(_rxAttrList
);
1038 // the base class should have created the control, so we can register it
1039 if ( m_sReferringControls
.getLength() )
1040 m_rFormImport
.registerControlReferences(m_xElement
, m_sReferringControls
);
1043 //---------------------------------------------------------------------
1044 void OReferredControlImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
,
1045 const ::rtl::OUString
& _rValue
)
1047 static const ::rtl::OUString s_sReferenceAttributeName
= ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_FOR
));
1048 if (_rLocalName
== s_sReferenceAttributeName
)
1049 m_sReferringControls
= _rValue
;
1051 OControlImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1054 //=====================================================================
1056 //=====================================================================
1057 //---------------------------------------------------------------------
1058 OPasswordImport::OPasswordImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1059 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1060 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1064 //---------------------------------------------------------------------
1065 void OPasswordImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
, const ::rtl::OUString
& _rValue
)
1067 static const ::rtl::OUString s_sEchoCharAttributeName
= ::rtl::OUString::createFromAscii(OAttributeMetaData::getSpecialAttributeName(SCA_ECHO_CHAR
));
1068 if (_rLocalName
== s_sEchoCharAttributeName
)
1070 // need a special handling for the EchoChar property
1071 PropertyValue aEchoChar
;
1072 aEchoChar
.Name
= PROPERTY_ECHOCHAR
;
1073 OSL_ENSURE(_rValue
.getLength() == 1, "OPasswordImport::handleAttribute: invalid echo char attribute!");
1074 // we ourself should not have written values other than of length 1
1075 if (_rValue
.getLength() >= 1)
1076 aEchoChar
.Value
<<= (sal_Int16
)_rValue
.getStr()[0];
1078 aEchoChar
.Value
<<= (sal_Int16
)0;
1079 implPushBackPropertyValue(aEchoChar
);
1082 OControlImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1085 //=====================================================================
1087 //=====================================================================
1088 //---------------------------------------------------------------------
1089 ORadioImport::ORadioImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1090 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1091 :OImagePositionImport( _rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1095 //---------------------------------------------------------------------
1096 void ORadioImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
, const ::rtl::OUString
& _rValue
)
1098 // need special handling for the State & CurrentState properties:
1099 // they're stored as booleans, but expected to be int16 properties
1100 static const sal_Char
* pCurrentSelectedAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED
);
1101 static const sal_Char
* pSelectedAttributeName
= OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED
);
1102 if ( _rLocalName
.equalsAscii( pCurrentSelectedAttributeName
)
1103 || _rLocalName
.equalsAscii( pSelectedAttributeName
)
1106 const OAttribute2Property::AttributeAssignment
* pProperty
= m_rContext
.getAttributeMap().getAttributeTranslation(_rLocalName
);
1107 OSL_ENSURE(pProperty
, "ORadioImport::handleAttribute: invalid property map!");
1110 const Any
aBooleanValue( PropertyConversion::convertString(m_rContext
.getGlobalContext(), pProperty
->aPropertyType
, _rValue
, pProperty
->pEnumMap
) );
1112 // create and store a new PropertyValue
1113 PropertyValue aNewValue
;
1114 aNewValue
.Name
= pProperty
->sPropertyName
;
1115 aNewValue
.Value
<<= (sal_Int16
)::cppu::any2bool(aBooleanValue
);
1117 implPushBackPropertyValue(aNewValue
);
1121 OImagePositionImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1124 //=====================================================================
1125 //= OURLReferenceImport
1126 //=====================================================================
1127 OURLReferenceImport::OURLReferenceImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1128 const Reference
< XNameContainer
>& _rxParentContainer
,
1129 OControlElement::ElementType _eType
)
1130 :OImagePositionImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1134 //---------------------------------------------------------------------
1135 void OURLReferenceImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
, const ::rtl::OUString
& _rValue
)
1137 static const sal_Char
* s_pTargetLocationAttributeName
= OAttributeMetaData::getCommonControlAttributeName( CCA_TARGET_LOCATION
);
1138 static const sal_Char
* s_pImageDataAttributeName
= OAttributeMetaData::getCommonControlAttributeName( CCA_IMAGE_DATA
);
1140 // need to make the URL absolute if
1141 // * it's the image-data attribute
1142 // * it's the target-location attribute, and we're dealign with an object which has the respective property
1143 sal_Bool bMakeAbsolute
=
1144 ( 0 == _rLocalName
.compareToAscii( s_pImageDataAttributeName
) )
1145 || ( ( 0 == _rLocalName
.compareToAscii( s_pTargetLocationAttributeName
) )
1146 && ( ( OControlElement::BUTTON
== m_eElementType
)
1147 || ( OControlElement::IMAGE
== m_eElementType
)
1151 if ( bMakeAbsolute
&& ( _rValue
.getLength() > 0 ) )
1153 // make a global URL out of the local one
1154 ::rtl::OUString sAdjustedValue
;
1155 // only resolve image related url
1156 // we don't want say form url targets to be resolved
1157 // using ResolveGraphicObjectURL
1158 if ( 0 == _rLocalName
.compareToAscii( s_pImageDataAttributeName
) )
1159 sAdjustedValue
= m_rContext
.getGlobalContext().ResolveGraphicObjectURL( _rValue
, FALSE
);
1161 sAdjustedValue
= m_rContext
.getGlobalContext().GetAbsoluteReference( _rValue
);
1162 OImagePositionImport::handleAttribute( _nNamespaceKey
, _rLocalName
, sAdjustedValue
);
1165 OImagePositionImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1168 //=====================================================================
1170 //=====================================================================
1171 //---------------------------------------------------------------------
1172 OButtonImport::OButtonImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1173 const Reference
< XNameContainer
>& _rxParentContainer
,
1174 OControlElement::ElementType _eType
)
1175 :OURLReferenceImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1177 enableTrackAttributes();
1180 //---------------------------------------------------------------------
1181 void OButtonImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
1183 OURLReferenceImport::StartElement(_rxAttrList
);
1185 // handle the target-frame attribute
1186 simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME
), PROPERTY_TARGETFRAME
, "_blank");
1189 //=====================================================================
1190 //= OValueRangeImport
1191 //=====================================================================
1192 //---------------------------------------------------------------------
1193 OValueRangeImport::OValueRangeImport( OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1194 const Reference
< XNameContainer
>& _rxParentContainer
, OControlElement::ElementType _eType
)
1195 :OControlImport( _rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1196 ,m_nStepSizeValue( 1 )
1201 //---------------------------------------------------------------------
1202 void OValueRangeImport::handleAttribute( sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
, const ::rtl::OUString
& _rValue
)
1204 if ( _rLocalName
.equalsAscii( OAttributeMetaData::getSpecialAttributeName( SCA_STEP_SIZE
) ) )
1206 GetImport().GetMM100UnitConverter().convertNumber( m_nStepSizeValue
, _rValue
);
1209 OControlImport::handleAttribute( _nNamespaceKey
, _rLocalName
, _rValue
);
1212 //---------------------------------------------------------------------
1213 void OValueRangeImport::StartElement( const Reference
< sax::XAttributeList
>& _rxAttrList
)
1215 OControlImport::StartElement( _rxAttrList
);
1219 if ( m_xInfo
->hasPropertyByName( PROPERTY_SPIN_INCREMENT
) )
1220 m_xElement
->setPropertyValue( PROPERTY_SPIN_INCREMENT
, makeAny( m_nStepSizeValue
) );
1221 else if ( m_xInfo
->hasPropertyByName( PROPERTY_LINE_INCREMENT
) )
1222 m_xElement
->setPropertyValue( PROPERTY_LINE_INCREMENT
, makeAny( m_nStepSizeValue
) );
1226 //=====================================================================
1228 //=====================================================================
1229 //---------------------------------------------------------------------
1230 OTextLikeImport::OTextLikeImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1231 const Reference
< XNameContainer
>& _rxParentContainer
,
1232 OControlElement::ElementType _eType
)
1233 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1234 ,m_bEncounteredTextPara( false )
1236 enableTrackAttributes();
1239 //---------------------------------------------------------------------
1240 SvXMLImportContext
* OTextLikeImport::CreateChildContext( sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rLocalName
,
1241 const Reference
< sax::XAttributeList
>& _rxAttrList
)
1243 if ( ( XML_NAMESPACE_TEXT
== _nPrefix
) && _rLocalName
.equalsIgnoreAsciiCaseAscii( "p" ) )
1245 OSL_ENSURE( m_eElementType
== OControlElement::TEXT_AREA
,
1246 "OTextLikeImport::CreateChildContext: text paragraphs in a non-text-area?" );
1248 if ( m_eElementType
== OControlElement::TEXT_AREA
)
1250 Reference
< XText
> xTextElement( m_xElement
, UNO_QUERY
);
1251 if ( xTextElement
.is() )
1253 UniReference
< XMLTextImportHelper
> xTextImportHelper( m_rContext
.getGlobalContext().GetTextImport() );
1255 if ( !m_xCursor
.is() )
1257 m_xOldCursor
= xTextImportHelper
->GetCursor();
1258 m_xCursor
= xTextElement
->createTextCursor();
1260 if ( m_xCursor
.is() )
1261 xTextImportHelper
->SetCursor( m_xCursor
);
1263 if ( m_xCursor
.is() )
1265 m_bEncounteredTextPara
= true;
1266 return xTextImportHelper
->CreateTextChildContext( m_rContext
.getGlobalContext(), _nPrefix
, _rLocalName
, _rxAttrList
);
1271 // in theory, we could accumulate all the text portions (without formatting),
1272 // and set it as Text property at the model ...
1277 return OControlImport::CreateChildContext( _nPrefix
, _rLocalName
, _rxAttrList
);
1280 //---------------------------------------------------------------------
1281 void OTextLikeImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
1283 OControlImport::StartElement(_rxAttrList
);
1285 // handle the convert-empty-to-null attribute, whose default is different from the property default
1286 // unfortunately, different classes are imported by this class ('cause they're represented by the
1287 // same XML element), though not all of them know this property.
1288 // So we have to do a check ...
1289 if (m_xElement
.is() && m_xInfo
.is() && m_xInfo
->hasPropertyByName(PROPERTY_EMPTY_IS_NULL
) )
1290 simulateDefaultedAttribute(OAttributeMetaData::getDatabaseAttributeName(DA_CONVERT_EMPTY
), PROPERTY_EMPTY_IS_NULL
, "false");
1293 //---------------------------------------------------------------------
1294 struct EqualHandle
: public ::std::unary_function
< PropertyValue
, bool >
1296 const sal_Int32 m_nHandle
;
1297 EqualHandle( sal_Int32 _nHandle
) : m_nHandle( _nHandle
) { }
1299 inline bool operator()( const PropertyValue
& _rProp
)
1301 return _rProp
.Handle
== m_nHandle
;
1305 //---------------------------------------------------------------------
1306 void OTextLikeImport::removeRedundantCurrentValue()
1308 if ( m_bEncounteredTextPara
)
1310 // In case the text is written in the text:p elements, we need to ignore what we read as
1311 // current-value attribute, since it's redundant.
1312 // fortunately, OElementImport tagged the value property with the PROPID_CURRENT_VALUE
1313 // handle, so we do not need to determine the name of our value property here
1314 // (normally, it should be "Text", since no other controls than the edit field should
1315 // have the text:p elements)
1316 PropertyValueArray::iterator aValuePropertyPos
= ::std::find_if(
1319 EqualHandle( PROPID_CURRENT_VALUE
)
1321 if ( aValuePropertyPos
!= m_aValues
.end() )
1323 OSL_ENSURE( aValuePropertyPos
->Name
== PROPERTY_TEXT
, "OTextLikeImport::EndElement: text:p was present, but our value property is *not* 'Text'!" );
1324 if ( aValuePropertyPos
->Name
== PROPERTY_TEXT
)
1327 aValuePropertyPos
+ 1,
1331 m_aValues
.resize( m_aValues
.size() - 1 );
1335 // additionally, we need to set the "RichText" property of our element to TRUE
1336 // (the presence of the text:p is used as indicator for the value of the RichText property)
1337 sal_Bool bHasRichTextProperty
= sal_False
;
1339 bHasRichTextProperty
= m_xInfo
->hasPropertyByName( PROPERTY_RICH_TEXT
);
1340 OSL_ENSURE( bHasRichTextProperty
, "OTextLikeImport::EndElement: text:p, but no rich text control?" );
1341 if ( bHasRichTextProperty
)
1342 m_xElement
->setPropertyValue( PROPERTY_RICH_TEXT
, makeAny( (sal_Bool
)sal_True
) );
1344 // Note that we do *not* set the RichText property (in case our element has one) to sal_False here
1345 // since this is the default of this property, anyway.
1348 //---------------------------------------------------------------------
1349 struct EqualName
: public ::std::unary_function
< PropertyValue
, bool >
1351 const ::rtl::OUString m_sName
;
1352 EqualName( const ::rtl::OUString
& _rName
) : m_sName( _rName
) { }
1354 inline bool operator()( const PropertyValue
& _rProp
)
1356 return _rProp
.Name
== m_sName
;
1360 //---------------------------------------------------------------------
1361 void OTextLikeImport::adjustDefaultControlProperty()
1363 // In OpenOffice.org 2.0, we changed the implementation of the css.form.component.TextField (the model of a text field control),
1364 // so that it now uses another default control. So if we encounter a text field where the *old* default
1365 // control property is writting, we are not allowed to use it
1366 PropertyValueArray::iterator aDefaultControlPropertyPos
= ::std::find_if(
1369 EqualName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultControl" ) ) )
1371 if ( aDefaultControlPropertyPos
!= m_aValues
.end() )
1373 ::rtl::OUString sDefaultControl
;
1374 OSL_VERIFY( aDefaultControlPropertyPos
->Value
>>= sDefaultControl
);
1375 if ( sDefaultControl
.equalsAscii( "stardiv.one.form.control.Edit" ) )
1377 // complete remove this property value from the array. Today's "default value" of the "DefaultControl"
1378 // property is sufficient
1380 aDefaultControlPropertyPos
+ 1,
1382 aDefaultControlPropertyPos
1384 m_aValues
.resize( m_aValues
.size() - 1 );
1389 //---------------------------------------------------------------------
1390 void OTextLikeImport::EndElement()
1392 removeRedundantCurrentValue();
1393 adjustDefaultControlProperty();
1395 // let the base class do the stuff
1396 OControlImport::EndElement();
1399 UniReference
< XMLTextImportHelper
> xTextImportHelper( m_rContext
.getGlobalContext().GetTextImport() );
1400 if ( m_xCursor
.is() )
1402 // delete the newline which has been imported errornously
1403 // TODO (fs): stole this code somewhere - why don't we fix the text import??
1404 m_xCursor
->gotoEnd( sal_False
);
1405 m_xCursor
->goLeft( 1, sal_True
);
1406 m_xCursor
->setString( ::rtl::OUString() );
1409 xTextImportHelper
->ResetCursor();
1412 if ( m_xOldCursor
.is() )
1413 xTextImportHelper
->SetCursor( m_xOldCursor
);
1417 //=====================================================================
1418 //= OListAndComboImport
1419 //=====================================================================
1420 //---------------------------------------------------------------------
1421 OListAndComboImport::OListAndComboImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1422 const Reference
< XNameContainer
>& _rxParentContainer
,
1423 OControlElement::ElementType _eType
)
1424 :OControlImport(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, _eType
)
1425 ,m_nEmptyListItems( 0 )
1426 ,m_nEmptyValueItems( 0 )
1427 ,m_bEncounteredLSAttrib( sal_False
)
1428 ,m_bLinkWithIndexes( sal_False
)
1430 if (OControlElement::COMBOBOX
== m_eElementType
)
1431 enableTrackAttributes();
1434 //---------------------------------------------------------------------
1435 SvXMLImportContext
* OListAndComboImport::CreateChildContext(sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rLocalName
,
1436 const Reference
< sax::XAttributeList
>& _rxAttrList
)
1438 // is it the "option" sub tag of a listbox ?
1439 static const ::rtl::OUString s_sOptionElementName
= ::rtl::OUString::createFromAscii("option");
1440 if (s_sOptionElementName
== _rLocalName
)
1441 return new OListOptionImport(GetImport(), _nPrefix
, _rLocalName
, this);
1443 // is it the "item" sub tag of a combobox ?
1444 static const ::rtl::OUString s_sItemElementName
= ::rtl::OUString::createFromAscii("item");
1445 if (s_sItemElementName
== _rLocalName
)
1446 return new OComboItemImport(GetImport(), _nPrefix
, _rLocalName
, this);
1449 return OControlImport::CreateChildContext(_nPrefix
, _rLocalName
, _rxAttrList
);
1452 //---------------------------------------------------------------------
1453 void OListAndComboImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
1455 m_bLinkWithIndexes
= sal_False
;
1457 OControlImport::StartElement(_rxAttrList
);
1459 if (OControlElement::COMBOBOX
== m_eElementType
)
1461 // for the auto-completion
1462 // the attribute default does not equal the property default, so in case we did not read this attribute,
1463 // we have to simulate it
1464 simulateDefaultedAttribute( OAttributeMetaData::getSpecialAttributeName( SCA_AUTOMATIC_COMPLETION
), PROPERTY_AUTOCOMPLETE
, "false");
1466 // same for the convert-empty-to-null attribute, which's default is different from the property default
1467 simulateDefaultedAttribute( OAttributeMetaData::getDatabaseAttributeName( DA_CONVERT_EMPTY
), PROPERTY_EMPTY_IS_NULL
, "false");
1471 //---------------------------------------------------------------------
1472 void OListAndComboImport::EndElement()
1474 // append the list source property the the properties sequence of our importer
1475 // the string item list
1476 PropertyValue aItemList
;
1477 aItemList
.Name
= PROPERTY_STRING_ITEM_LIST
;
1478 aItemList
.Value
<<= m_aListSource
;
1479 implPushBackPropertyValue(aItemList
);
1481 if (OControlElement::LISTBOX
== m_eElementType
)
1483 OSL_ENSURE((m_aListSource
.getLength() + m_nEmptyListItems
) == (m_aValueList
.getLength() + m_nEmptyValueItems
),
1484 "OListAndComboImport::EndElement: inconsistence between labels and values!");
1486 if ( !m_bEncounteredLSAttrib
)
1488 // the value sequence
1489 PropertyValue aValueList
;
1490 aValueList
.Name
= PROPERTY_LISTSOURCE
;
1491 aValueList
.Value
<<= m_aValueList
;
1492 implPushBackPropertyValue(aValueList
);
1495 // the select sequence
1496 PropertyValue aSelected
;
1497 aSelected
.Name
= PROPERTY_SELECT_SEQ
;
1498 aSelected
.Value
<<= m_aSelectedSeq
;
1499 implPushBackPropertyValue(aSelected
);
1501 // the default select sequence
1502 PropertyValue aDefaultSelected
;
1503 aDefaultSelected
.Name
= PROPERTY_DEFAULT_SELECT_SEQ
;
1504 aDefaultSelected
.Value
<<= m_aDefaultSelectedSeq
;
1505 implPushBackPropertyValue(aDefaultSelected
);
1508 OControlImport::EndElement();
1510 // the external list source, if applicable
1511 if ( m_xElement
.is() && m_sCellListSource
.getLength() )
1512 m_rContext
.registerCellRangeListSource( m_xElement
, m_sCellListSource
);
1515 //---------------------------------------------------------------------
1516 void OListAndComboImport::doRegisterCellValueBinding( const ::rtl::OUString
& _rBoundCellAddress
)
1518 ::rtl::OUString
sBoundCellAddress( _rBoundCellAddress
);
1519 if ( m_bLinkWithIndexes
)
1521 // This is a HACK. We register a string which is no valid address, but allows
1522 // (somewhere else) to determine that a non-standard binding should be created.
1523 // This hack is acceptable for OOo 1.1.1, since the file format for value
1524 // bindings of form controls is to be changed afterwards, anyway.
1525 sBoundCellAddress
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":index" ) );
1528 OControlImport::doRegisterCellValueBinding( sBoundCellAddress
);
1531 //---------------------------------------------------------------------
1532 void OListAndComboImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
, const ::rtl::OUString
& _rValue
)
1534 static const sal_Char
* pListSourceAttributeName
= OAttributeMetaData::getDatabaseAttributeName(DA_LIST_SOURCE
);
1535 if ( _rLocalName
.equalsAscii(pListSourceAttributeName
) )
1537 PropertyValue aListSource
;
1538 aListSource
.Name
= PROPERTY_LISTSOURCE
;
1540 // it's the ListSource attribute
1541 m_bEncounteredLSAttrib
= sal_True
;
1542 if ( OControlElement::COMBOBOX
== m_eElementType
)
1544 aListSource
.Value
<<= _rValue
;
1548 // a listbox which has a list-source attribute must have a list-source-type of something
1549 // not equal to ValueList.
1550 // In this case, the list-source value is simply the one and only element of the ListSource property.
1551 Sequence
< ::rtl::OUString
> aListSourcePropValue( 1 );
1552 aListSourcePropValue
[0] = _rValue
;
1553 aListSource
.Value
<<= aListSourcePropValue
;
1556 implPushBackPropertyValue( aListSource
);
1558 else if ( _rLocalName
.equalsAscii( OAttributeMetaData::getBindingAttributeName( BA_LIST_CELL_RANGE
) ) )
1560 m_sCellListSource
= _rValue
;
1562 else if ( _rLocalName
.equalsAscii( OAttributeMetaData::getBindingAttributeName( BA_LIST_LINKING_TYPE
) ) )
1564 sal_Int16 nLinkageType
= 0;
1565 PropertyConversion::convertString(
1566 m_rContext
.getGlobalContext(),
1567 ::getCppuType( static_cast< sal_Int16
* >( NULL
) ),
1569 OEnumMapper::getEnumMap( OEnumMapper::epListLinkageType
)
1572 m_bLinkWithIndexes
= ( nLinkageType
!= 0 );
1575 OControlImport::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1578 //---------------------------------------------------------------------
1579 void OListAndComboImport::implPushBackLabel(const ::rtl::OUString
& _rLabel
)
1581 OSL_ENSURE(!m_nEmptyListItems
, "OListAndComboImport::implPushBackValue: label list is already done!");
1582 if (!m_nEmptyListItems
)
1583 pushBackSequenceElement(m_aListSource
, _rLabel
);
1586 //---------------------------------------------------------------------
1587 void OListAndComboImport::implPushBackValue(const ::rtl::OUString
& _rValue
)
1589 OSL_ENSURE(!m_nEmptyValueItems
, "OListAndComboImport::implPushBackValue: value list is already done!");
1590 if (!m_nEmptyValueItems
)
1592 OSL_ENSURE( !m_bEncounteredLSAttrib
, "OListAndComboImport::implPushBackValue: invalid structure! Did you save this document with a version prior SRC641 m?" );
1593 // We already had the list-source attribute, which means that the ListSourceType is
1594 // not ValueList, which means that the ListSource should contain only one string in
1595 // the first element of the sequence
1596 // All other values in the file are invalid
1598 pushBackSequenceElement( m_aValueList
, _rValue
);
1602 //---------------------------------------------------------------------
1603 void OListAndComboImport::implEmptyLabelFound()
1605 ++m_nEmptyListItems
;
1608 //---------------------------------------------------------------------
1609 void OListAndComboImport::implEmptyValueFound()
1611 ++m_nEmptyValueItems
;
1614 //---------------------------------------------------------------------
1615 void OListAndComboImport::implSelectCurrentItem()
1617 OSL_ENSURE((m_aListSource
.getLength() + m_nEmptyListItems
) == (m_aValueList
.getLength() + m_nEmptyValueItems
),
1618 "OListAndComboImport::implSelectCurrentItem: inconsistence between labels and values!");
1620 sal_Int16 nItemNumber
= (sal_Int16
)(m_aListSource
.getLength() - 1 + m_nEmptyListItems
);
1621 pushBackSequenceElement(m_aSelectedSeq
, nItemNumber
);
1624 //---------------------------------------------------------------------
1625 void OListAndComboImport::implDefaultSelectCurrentItem()
1627 OSL_ENSURE((m_aListSource
.getLength() + m_nEmptyListItems
) == (m_aValueList
.getLength() + m_nEmptyValueItems
),
1628 "OListAndComboImport::implDefaultSelectCurrentItem: inconsistence between labels and values!");
1630 sal_Int16 nItemNumber
= (sal_Int16
)(m_aListSource
.getLength() - 1 + m_nEmptyListItems
);
1631 pushBackSequenceElement(m_aDefaultSelectedSeq
, nItemNumber
);
1634 //=====================================================================
1635 //= OListOptionImport
1636 //=====================================================================
1637 //---------------------------------------------------------------------
1638 OListOptionImport::OListOptionImport(SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1639 const OListAndComboImportRef
& _rListBox
)
1640 :SvXMLImportContext(_rImport
, _nPrefix
, _rName
)
1641 ,m_xListBoxImport(_rListBox
)
1645 //---------------------------------------------------------------------
1646 void OListOptionImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
1648 // the label and the value
1649 const SvXMLNamespaceMap
& rMap
= GetImport().GetNamespaceMap();
1650 const ::rtl::OUString sLabelAttribute
= rMap
.GetQNameByKey(
1651 GetPrefix(), ::rtl::OUString::createFromAscii("label"));
1652 const ::rtl::OUString sValueAttribute
= rMap
.GetQNameByKey(
1653 GetPrefix(), ::rtl::OUString::createFromAscii("value"));
1655 // -------------------
1656 // the label attribute
1657 ::rtl::OUString sValue
= _rxAttrList
->getValueByName(sLabelAttribute
);
1658 sal_Bool bNonexistentAttribute
= sal_False
;
1659 if (!sValue
.getLength())
1660 if (0 == _rxAttrList
->getTypeByName(sLabelAttribute
).getLength())
1661 // this attribute does not really exist
1662 bNonexistentAttribute
= sal_True
;
1664 if (bNonexistentAttribute
)
1665 m_xListBoxImport
->implEmptyLabelFound();
1667 m_xListBoxImport
->implPushBackLabel( sValue
);
1669 // -------------------
1670 // the value attribute
1671 sValue
= _rxAttrList
->getValueByName(sValueAttribute
);
1672 bNonexistentAttribute
= sal_False
;
1673 if (!sValue
.getLength())
1674 if (0 == _rxAttrList
->getTypeByName(sValueAttribute
).getLength())
1675 // this attribute does not really exist
1676 bNonexistentAttribute
= sal_True
;
1678 if (bNonexistentAttribute
)
1679 m_xListBoxImport
->implEmptyValueFound();
1681 m_xListBoxImport
->implPushBackValue( sValue
);
1683 // the current-selected and selected
1684 const ::rtl::OUString sSelectedAttribute
= rMap
.GetQNameByKey(
1685 GetPrefix(), ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED
)));
1686 const ::rtl::OUString sDefaultSelectedAttribute
= rMap
.GetQNameByKey(
1687 GetPrefix(), ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED
)));
1689 // propagate the selected flag
1691 GetImport().GetMM100UnitConverter().convertBool(bSelected
, _rxAttrList
->getValueByName(sSelectedAttribute
));
1693 m_xListBoxImport
->implSelectCurrentItem();
1695 // same for the default selected
1696 sal_Bool bDefaultSelected
;
1697 GetImport().GetMM100UnitConverter().convertBool(bDefaultSelected
, _rxAttrList
->getValueByName(sDefaultSelectedAttribute
));
1698 if (bDefaultSelected
)
1699 m_xListBoxImport
->implDefaultSelectCurrentItem();
1701 SvXMLImportContext::StartElement(_rxAttrList
);
1704 //=====================================================================
1705 //= OComboItemImport
1706 //=====================================================================
1707 //---------------------------------------------------------------------
1708 OComboItemImport::OComboItemImport(SvXMLImport
& _rImport
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1709 const OListAndComboImportRef
& _rListBox
)
1710 :SvXMLImportContext(_rImport
, _nPrefix
, _rName
)
1711 ,m_xListBoxImport(_rListBox
)
1715 //---------------------------------------------------------------------
1716 void OComboItemImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
1718 const ::rtl::OUString sLabelAttributeName
= GetImport().GetNamespaceMap().GetQNameByKey(
1719 GetPrefix(), ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_LABEL
)));
1720 m_xListBoxImport
->implPushBackLabel(_rxAttrList
->getValueByName(sLabelAttributeName
));
1722 SvXMLImportContext::StartElement(_rxAttrList
);
1726 //=====================================================================
1727 //= OColumnWrapperImport
1728 //=====================================================================
1729 //---------------------------------------------------------------------
1730 OColumnWrapperImport::OColumnWrapperImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1731 const Reference
< XNameContainer
>& _rxParentContainer
)
1732 :SvXMLImportContext(_rImport
.getGlobalContext(), _nPrefix
, _rName
)
1733 ,m_xParentContainer(_rxParentContainer
)
1734 ,m_rFormImport(_rImport
)
1735 ,m_rEventManager(_rEventManager
)
1738 //---------------------------------------------------------------------
1739 SvXMLImportContext
* OColumnWrapperImport::CreateChildContext(sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rLocalName
,
1740 const Reference
< sax::XAttributeList
>&)
1742 OControlImport
* pReturn
= implCreateChildContext(_nPrefix
, _rLocalName
, OElementNameMap::getElementType(_rLocalName
));
1745 OSL_ENSURE(m_xOwnAttributes
.is(), "OColumnWrapperImport::CreateChildContext: had no form:column element!");
1746 pReturn
->addOuterAttributes(m_xOwnAttributes
);
1750 //---------------------------------------------------------------------
1751 void OColumnWrapperImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
1753 OSL_ENSURE(!m_xOwnAttributes
.is(), "OColumnWrapperImport::StartElement: aready have the cloned list!");
1755 // clone the attributes
1756 Reference
< XCloneable
> xCloneList(_rxAttrList
, UNO_QUERY
);
1757 OSL_ENSURE(xCloneList
.is(), "OColumnWrapperImport::StartElement: AttributeList not cloneable!");
1758 if ( xCloneList
.is() )
1759 m_xOwnAttributes
= Reference
< sax::XAttributeList
>(xCloneList
->createClone(), UNO_QUERY
);
1760 OSL_ENSURE(m_xOwnAttributes
.is(), "OColumnWrapperImport::StartElement: no cloned list!");
1763 //---------------------------------------------------------------------
1764 OControlImport
* OColumnWrapperImport::implCreateChildContext(
1765 sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rLocalName
,
1766 OControlElement::ElementType _eType
)
1768 OSL_ENSURE( (OControlElement::TEXT
== _eType
)
1769 || (OControlElement::TEXT_AREA
== _eType
)
1770 || (OControlElement::FORMATTED_TEXT
== _eType
)
1771 || (OControlElement::CHECKBOX
== _eType
)
1772 || (OControlElement::LISTBOX
== _eType
)
1773 || (OControlElement::COMBOBOX
== _eType
),
1774 "OColumnWrapperImport::implCreateChildContext: invalid or unrecognized sub element!");
1778 case OControlElement::COMBOBOX
:
1779 case OControlElement::LISTBOX
:
1780 return new OColumnImport
<OListAndComboImport
>(m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1782 case OControlElement::PASSWORD
:
1783 return new OColumnImport
<OPasswordImport
>(m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1785 case OControlElement::TEXT
:
1786 case OControlElement::TEXT_AREA
:
1787 case OControlElement::FORMATTED_TEXT
:
1788 return new OColumnImport
< OTextLikeImport
>( m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1791 return new OColumnImport
<OControlImport
>(m_rFormImport
, m_rEventManager
, _nPrefix
, _rLocalName
, m_xParentContainer
, _eType
);
1795 //=====================================================================
1797 //=====================================================================
1798 //---------------------------------------------------------------------
1799 OGridImport::OGridImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1800 const Reference
< XNameContainer
>& _rxParentContainer
,
1801 OControlElement::ElementType _eType
)
1802 :OGridImport_Base(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, "column")
1804 setElementType(_eType
);
1807 //---------------------------------------------------------------------
1808 SvXMLImportContext
* OGridImport::implCreateControlWrapper(sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rLocalName
)
1810 return new OColumnWrapperImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
);
1813 //=====================================================================
1815 //=====================================================================
1816 //---------------------------------------------------------------------
1817 OFormImport::OFormImport(OFormLayerXMLImport_Impl
& _rImport
, IEventAttacherManager
& _rEventManager
, sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rName
,
1818 const Reference
< XNameContainer
>& _rxParentContainer
)
1819 :OFormImport_Base(_rImport
, _rEventManager
, _nPrefix
, _rName
, _rxParentContainer
, "control")
1821 enableTrackAttributes();
1824 //---------------------------------------------------------------------
1825 SvXMLImportContext
* OFormImport::CreateChildContext(sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rLocalName
,
1826 const Reference
< sax::XAttributeList
>& _rxAttrList
)
1828 if( token::IsXMLToken(_rLocalName
, token::XML_FORM
) )
1829 return new OFormImport( m_rFormImport
, *this, _nPrefix
, _rLocalName
,
1831 else if ( token::IsXMLToken(_rLocalName
, token::XML_CONNECTION_RESOURCE
) )
1832 return new OXMLDataSourceImport(GetImport(), _nPrefix
, _rLocalName
, _rxAttrList
,m_xElement
);
1833 else if( (token::IsXMLToken(_rLocalName
, token::XML_EVENT_LISTENERS
) &&
1834 (XML_NAMESPACE_OFFICE
== _nPrefix
)) ||
1835 token::IsXMLToken( _rLocalName
, token::XML_PROPERTIES
) )
1836 return OElementImport::CreateChildContext( _nPrefix
, _rLocalName
,
1839 return implCreateChildContext( _nPrefix
, _rLocalName
,
1840 OElementNameMap::getElementType(_rLocalName
) );
1843 //---------------------------------------------------------------------
1844 void OFormImport::StartElement(const Reference
< sax::XAttributeList
>& _rxAttrList
)
1846 m_rFormImport
.enterEventContext();
1847 OFormImport_Base::StartElement(_rxAttrList
);
1849 // handle the target-frame attribute
1850 simulateDefaultedAttribute(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME
), PROPERTY_TARGETFRAME
, "_blank");
1853 //---------------------------------------------------------------------
1854 void OFormImport::EndElement()
1856 OFormImport_Base::EndElement();
1857 m_rFormImport
.leaveEventContext();
1860 //---------------------------------------------------------------------
1861 SvXMLImportContext
* OFormImport::implCreateControlWrapper(sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rLocalName
)
1863 OSL_ENSURE( !this, "illegal call to OFormImport::implCreateControlWrapper" );
1864 return new SvXMLImportContext(GetImport(), _nPrefix
, _rLocalName
);
1867 //---------------------------------------------------------------------
1868 void OFormImport::handleAttribute(sal_uInt16 _nNamespaceKey
, const ::rtl::OUString
& _rLocalName
, const ::rtl::OUString
& _rValue
)
1870 // handle the master/details field attributes (they're way too special to let the OPropertyImport handle them)
1871 static const ::rtl::OUString s_sMasterFieldsAttributeName
= ::rtl::OUString::createFromAscii(OAttributeMetaData::getFormAttributeName(faMasterFields
));
1872 static const ::rtl::OUString s_sDetailFieldsAttributeName
= ::rtl::OUString::createFromAscii(OAttributeMetaData::getFormAttributeName(faDetailFiels
));
1874 if (s_sMasterFieldsAttributeName
== _rLocalName
)
1875 implTranslateStringListProperty(PROPERTY_MASTERFIELDS
, _rValue
);
1876 else if (s_sDetailFieldsAttributeName
== _rLocalName
)
1877 implTranslateStringListProperty(PROPERTY_DETAILFIELDS
, _rValue
);
1880 OFormImport_Base::handleAttribute(_nNamespaceKey
, _rLocalName
, _rValue
);
1883 //---------------------------------------------------------------------
1884 void OFormImport::implTranslateStringListProperty(const ::rtl::OUString
& _rPropertyName
, const ::rtl::OUString
& _rValue
)
1886 PropertyValue aProp
;
1887 aProp
.Name
= _rPropertyName
;
1889 Sequence
< ::rtl::OUString
> aList
;
1891 // split up the value string
1892 if (_rValue
.getLength())
1894 // For the moment, we build a vector instead of a Sequence. It's easier to handle because of it's
1896 ::std::vector
< ::rtl::OUString
> aElements
;
1897 // estimate the number of tokens
1898 sal_Int32 nEstimate
= 0, nLength
= _rValue
.getLength();
1899 const sal_Unicode
* pChars
= _rValue
.getStr();
1900 for (sal_Int32 i
=0; i
<nLength
; ++i
, ++pChars
)
1903 aElements
.reserve(nEstimate
+ 1);
1904 // that's the worst case. If the string contains the separator character _quoted_, we reserved to much ...
1907 sal_Int32 nElementStart
= 0;
1908 sal_Int32 nNextSep
= 0;
1909 sal_Int32 nElementLength
;
1910 ::rtl::OUString sElement
;
1913 // extract the current element
1914 nNextSep
= SvXMLUnitConverter::indexOfComma(
1915 _rValue
, nElementStart
);
1918 sElement
= _rValue
.copy(nElementStart
, nNextSep
- nElementStart
);
1920 nElementLength
= sElement
.getLength();
1921 // when writing the sequence, we quoted the single elements with " characters
1922 OSL_ENSURE( (nElementLength
>= 2)
1923 && (sElement
.getStr()[0] == '"')
1924 && (sElement
.getStr()[nElementLength
- 1] == '"'),
1925 "OFormImport::implTranslateStringListProperty: invalid quoted element name.");
1926 sElement
= sElement
.copy(1, nElementLength
- 2);
1928 aElements
.push_back(sElement
);
1930 // swith to the next element
1931 nElementStart
= 1 + nNextSep
;
1933 while (nElementStart
< nLength
);
1935 ::rtl::OUString
*pElements
= aElements
.empty() ? 0 : &aElements
[0];
1936 aList
= Sequence
< ::rtl::OUString
>(pElements
, aElements
.size());
1940 OSL_ENSURE(sal_False
, "OFormImport::implTranslateStringListProperty: invalid value (empty)!");
1943 aProp
.Value
<<= aList
;
1945 // add the property to the base class' array
1946 implPushBackPropertyValue(aProp
);
1948 //=====================================================================
1949 //= OXMLDataSourceImport
1950 //=====================================================================
1951 OXMLDataSourceImport::OXMLDataSourceImport(
1952 SvXMLImport
& _rImport
1954 , const ::rtl::OUString
& _sLocalName
1955 ,const Reference
< ::com::sun::star::xml::sax::XAttributeList
> & _xAttrList
1956 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xElement
) :
1957 SvXMLImportContext( _rImport
, nPrfx
, _sLocalName
)
1959 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
1960 const SvXMLNamespaceMap
& rMap
= _rImport
.GetNamespaceMap();
1962 sal_Int16 nLength
= (_xElement
.is() && _xAttrList
.is()) ? _xAttrList
->getLength() : 0;
1963 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
1965 ::rtl::OUString sLocalName
;
1966 ::rtl::OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
1967 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
, &sLocalName
);
1969 if ( ( nPrefix
== OAttributeMetaData::getCommonControlAttributeNamespace( CCA_TARGET_LOCATION
) )
1970 && ( sLocalName
.equalsAscii( OAttributeMetaData::getCommonControlAttributeName( CCA_TARGET_LOCATION
) ) )
1973 ::rtl::OUString sValue
= _xAttrList
->getValueByIndex( i
);
1975 INetURLObject
aURL(sValue
);
1976 if ( aURL
.GetProtocol() == INET_PROT_FILE
)
1977 _xElement
->setPropertyValue(PROPERTY_DATASOURCENAME
,makeAny(sValue
));
1979 _xElement
->setPropertyValue(PROPERTY_URL
,makeAny(sValue
)); // the url is the "sdbc:" string
1984 //---------------------------------------------------------------------
1985 OControlImport
* OFormImport::implCreateChildContext(
1986 sal_uInt16 _nPrefix
, const ::rtl::OUString
& _rLocalName
,
1987 OControlElement::ElementType _eType
)
1991 case OControlElement::TEXT
:
1992 case OControlElement::TEXT_AREA
:
1993 case OControlElement::FORMATTED_TEXT
:
1994 return new OTextLikeImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
1996 case OControlElement::BUTTON
:
1997 case OControlElement::IMAGE
:
1998 case OControlElement::IMAGE_FRAME
:
1999 return new OButtonImport( m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2001 case OControlElement::COMBOBOX
:
2002 case OControlElement::LISTBOX
:
2003 return new OListAndComboImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2005 case OControlElement::RADIO
:
2006 return new ORadioImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2008 case OControlElement::CHECKBOX
:
2009 return new OImagePositionImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2011 case OControlElement::PASSWORD
:
2012 return new OPasswordImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2014 case OControlElement::FRAME
:
2015 case OControlElement::FIXED_TEXT
:
2016 return new OReferredControlImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2018 case OControlElement::GRID
:
2019 return new OGridImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2021 case OControlElement::VALUERANGE
:
2022 return new OValueRangeImport( m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2025 return new OControlImport(m_rFormImport
, *this, _nPrefix
, _rLocalName
, m_xMeAsContainer
, _eType
);
2029 //.........................................................................
2030 } // namespace xmloff
2031 //.........................................................................