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