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