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