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 "propertyimport.hxx"
22 :
23 : #include <sax/tools/converter.hxx>
24 :
25 : #include <xmloff/xmlimp.hxx>
26 : #include <xmloff/xmluconv.hxx>
27 : #include <xmloff/nmspmap.hxx>
28 : #include <osl/diagnose.h>
29 : #include <comphelper/extract.hxx>
30 : #include "callbacks.hxx"
31 : #include "xmloff/xmlnmspe.hxx"
32 : #include <tools/date.hxx>
33 : #include <tools/time.hxx>
34 : #include <com/sun/star/util/Date.hpp>
35 : #include <com/sun/star/util/Time.hpp>
36 : #include <com/sun/star/util/DateTime.hpp>
37 : #include <unotools/datetime.hxx>
38 : #include <rtl/logfile.hxx>
39 : #include <rtl/strbuf.hxx>
40 :
41 : #if OSL_DEBUG_LEVEL > 0
42 : #include <osl/thread.h>
43 : #endif
44 :
45 : //.........................................................................
46 : namespace xmloff
47 : {
48 : //.........................................................................
49 :
50 : using namespace ::com::sun::star::uno;
51 : using namespace ::com::sun::star::beans;
52 : using namespace ::com::sun::star::xml;
53 : using ::com::sun::star::xml::sax::XAttributeList;
54 :
55 : // NO using namespace ...util !!!
56 : // need a tools Date/Time/DateTime below, which would conflict with the uno types then
57 :
58 : #define TYPE_DATE 1
59 : #define TYPE_TIME 2
60 : #define TYPE_DATETIME 3
61 :
62 : //=====================================================================
63 : //= PropertyConversion
64 : //=====================================================================
65 : namespace
66 : {
67 : //---------------------------------------------------------------------
68 0 : ::com::sun::star::util::Time lcl_getTime(double _nValue)
69 : {
70 0 : ::com::sun::star::util::Time aTime;
71 0 : sal_uInt64 nIntValue = static_cast<sal_uInt64>(_nValue * ::Time::nanoSecPerDay);
72 0 : aTime.NanoSeconds = nIntValue % ::Time::nanoSecPerSec;
73 0 : nIntValue /= ::Time::nanoSecPerSec;
74 0 : aTime.Seconds = nIntValue % ::Time::secondPerMinute;
75 0 : nIntValue /= ::Time::secondPerMinute;
76 0 : aTime.Minutes = nIntValue % ::Time::minutePerHour;
77 0 : nIntValue /= ::Time::minutePerHour;
78 : OSL_ENSURE(nIntValue < 24, "lcl_getTime: more than a day?");
79 0 : aTime.Hours = nIntValue;
80 :
81 0 : return aTime;
82 : }
83 :
84 : //---------------------------------------------------------------------
85 0 : static ::com::sun::star::util::Date lcl_getDate( double _nValue )
86 : {
87 0 : Date aToolsDate((sal_uInt32)_nValue);
88 0 : ::com::sun::star::util::Date aDate;
89 0 : ::utl::typeConvert(aToolsDate, aDate);
90 0 : return aDate;
91 : }
92 : }
93 :
94 : //---------------------------------------------------------------------
95 159 : Any PropertyConversion::convertString( SvXMLImport& _rImporter, const ::com::sun::star::uno::Type& _rExpectedType,
96 : const OUString& _rReadCharacters, const SvXMLEnumMapEntry* _pEnumMap, const sal_Bool _bInvertBoolean )
97 : {
98 159 : Any aReturn;
99 159 : sal_Bool bEnumAsInt = sal_False;
100 159 : switch (_rExpectedType.getTypeClass())
101 : {
102 : case TypeClass_BOOLEAN: // sal_Bool
103 : {
104 : bool bValue;
105 : #if OSL_DEBUG_LEVEL > 0
106 : sal_Bool bSuccess =
107 : #endif
108 10 : ::sax::Converter::convertBool(bValue, _rReadCharacters);
109 : OSL_ENSURE(bSuccess,
110 : OStringBuffer("PropertyConversion::convertString: could not convert \"").
111 : append(OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US)).
112 : append("\" into a boolean!").getStr());
113 10 : aReturn = ::cppu::bool2any(_bInvertBoolean ? !bValue : bValue);
114 : }
115 10 : break;
116 : case TypeClass_SHORT: // sal_Int16
117 : case TypeClass_LONG: // sal_Int32
118 15 : if (!_pEnumMap)
119 : { // it's a real int32/16 property
120 0 : sal_Int32 nValue(0);
121 : #if OSL_DEBUG_LEVEL > 0
122 : sal_Bool bSuccess =
123 : #endif
124 0 : ::sax::Converter::convertNumber(nValue, _rReadCharacters);
125 : OSL_ENSURE(bSuccess,
126 : OStringBuffer("PropertyConversion::convertString: could not convert \"").
127 : append(OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US)).
128 : append("\" into an integer!").getStr());
129 0 : if (TypeClass_SHORT == _rExpectedType.getTypeClass())
130 0 : aReturn <<= (sal_Int16)nValue;
131 : else
132 0 : aReturn <<= (sal_Int32)nValue;
133 0 : break;
134 : }
135 15 : bEnumAsInt = sal_True;
136 : // NO BREAK! handle it as enum
137 : case TypeClass_ENUM:
138 : {
139 15 : sal_uInt16 nEnumValue(0);
140 : #if OSL_DEBUG_LEVEL > 0
141 : sal_Bool bSuccess =
142 : #endif
143 15 : _rImporter.GetMM100UnitConverter().convertEnum(nEnumValue, _rReadCharacters, _pEnumMap);
144 : OSL_ENSURE(bSuccess, "PropertyConversion::convertString: could not convert to an enum value!");
145 15 : if (bEnumAsInt)
146 15 : if (TypeClass_SHORT == _rExpectedType.getTypeClass())
147 7 : aReturn <<= (sal_Int16)nEnumValue;
148 : else
149 8 : aReturn <<= (sal_Int32)nEnumValue;
150 : else
151 0 : aReturn = ::cppu::int2enum((sal_Int32)nEnumValue, _rExpectedType);
152 : }
153 15 : break;
154 : case TypeClass_HYPER:
155 : {
156 : OSL_FAIL("PropertyConversion::convertString: 64-bit integers not implemented yet!");
157 : }
158 0 : break;
159 : case TypeClass_DOUBLE:
160 : {
161 : double nValue;
162 : #if OSL_DEBUG_LEVEL > 0
163 : sal_Bool bSuccess =
164 : #endif
165 6 : ::sax::Converter::convertDouble(nValue, _rReadCharacters);
166 : OSL_ENSURE(bSuccess,
167 : OStringBuffer("PropertyConversion::convertString: could not convert \"").
168 : append(OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US)).
169 : append("\" into a double!").getStr());
170 6 : aReturn <<= (double)nValue;
171 : }
172 6 : break;
173 : case TypeClass_STRING:
174 128 : aReturn <<= _rReadCharacters;
175 128 : break;
176 : case TypeClass_STRUCT:
177 : {
178 0 : sal_Int32 nType = 0;
179 0 : if ( _rExpectedType.equals( ::cppu::UnoType< ::com::sun::star::util::Date >::get() ) )
180 0 : nType = TYPE_DATE;
181 0 : else if ( _rExpectedType.equals( ::cppu::UnoType< ::com::sun::star::util::Time >::get() ) )
182 0 : nType = TYPE_TIME;
183 0 : else if ( _rExpectedType.equals( ::cppu::UnoType< ::com::sun::star::util::DateTime >::get() ) )
184 0 : nType = TYPE_DATETIME;
185 :
186 0 : if ( nType )
187 : {
188 : // first extract the double
189 0 : double nValue = 0;
190 : #if OSL_DEBUG_LEVEL > 0
191 : sal_Bool bSuccess =
192 : #endif
193 0 : ::sax::Converter::convertDouble(nValue, _rReadCharacters);
194 : OSL_ENSURE(bSuccess,
195 : OStringBuffer("PropertyConversion::convertString: could not convert \"").
196 : append(OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US)).
197 : append("\" into a double!").getStr());
198 :
199 : // then convert it into the target type
200 0 : switch (nType)
201 : {
202 : case TYPE_DATE:
203 : {
204 : OSL_ENSURE(((sal_uInt32)nValue) - nValue == 0,
205 : "PropertyConversion::convertString: a Date value with a fractional part?");
206 0 : aReturn <<= lcl_getDate(nValue);
207 : }
208 0 : break;
209 : case TYPE_TIME:
210 : {
211 : OSL_ENSURE(((sal_uInt32)nValue) == 0,
212 : "PropertyConversion::convertString: a Time value with more than a fractional part?");
213 0 : aReturn <<= lcl_getTime(nValue);
214 : }
215 0 : break;
216 : case TYPE_DATETIME:
217 : {
218 0 : ::com::sun::star::util::Time aTime = lcl_getTime(nValue);
219 0 : ::com::sun::star::util::Date aDate = lcl_getDate(nValue);
220 :
221 0 : ::com::sun::star::util::DateTime aDateTime;
222 0 : aDateTime.NanoSeconds = aTime.NanoSeconds;
223 0 : aDateTime.Seconds = aTime.Seconds;
224 0 : aDateTime.Minutes = aTime.Minutes;
225 0 : aDateTime.Hours = aTime.Hours;
226 0 : aDateTime.Day = aDate.Day;
227 0 : aDateTime.Month = aDate.Month;
228 0 : aDateTime.Year = aDate.Year;
229 0 : aReturn <<= aDateTime;
230 : }
231 0 : break;
232 : }
233 : }
234 : else
235 : OSL_FAIL("PropertyConversion::convertString: unsupported property type!");
236 : }
237 0 : break;
238 : default:
239 : OSL_FAIL("PropertyConversion::convertString: invalid type class!");
240 : }
241 :
242 159 : return aReturn;
243 : }
244 :
245 : //---------------------------------------------------------------------
246 65 : Type PropertyConversion::xmlTypeToUnoType( const OUString& _rType )
247 : {
248 65 : Type aUnoType( ::getVoidCppuType() );
249 :
250 65 : static std::map< OUString, css::uno::Type > s_aTypeNameMap;
251 65 : if ( s_aTypeNameMap.empty() )
252 : {
253 4 : s_aTypeNameMap[ token::GetXMLToken( token::XML_BOOLEAN ) ] = ::getBooleanCppuType();
254 4 : s_aTypeNameMap[ token::GetXMLToken( token::XML_FLOAT ) ] = ::getCppuType( static_cast< double* >(NULL) );
255 4 : s_aTypeNameMap[ token::GetXMLToken( token::XML_STRING ) ] = ::getCppuType( static_cast< OUString* >(NULL) );
256 4 : s_aTypeNameMap[ token::GetXMLToken( token::XML_VOID ) ] = ::getVoidCppuType();
257 : }
258 :
259 65 : const std::map< OUString, css::uno::Type >::iterator aTypePos = s_aTypeNameMap.find( _rType );
260 : OSL_ENSURE( s_aTypeNameMap.end() != aTypePos, "PropertyConversion::xmlTypeToUnoType: invalid property name!" );
261 65 : if ( s_aTypeNameMap.end() != aTypePos )
262 65 : aUnoType = aTypePos->second;
263 :
264 65 : return aUnoType;
265 : }
266 :
267 : //=====================================================================
268 : //= OPropertyImport
269 : //=====================================================================
270 : //---------------------------------------------------------------------
271 36 : OPropertyImport::OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const OUString& _rName)
272 36 : :SvXMLImportContext(_rImport.getGlobalContext(), _nPrefix, _rName)
273 : ,m_rContext(_rImport)
274 72 : ,m_bTrackAttributes(sal_False)
275 : {
276 36 : }
277 :
278 : //---------------------------------------------------------------------
279 35 : SvXMLImportContext* OPropertyImport::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
280 : const Reference< XAttributeList >& _rxAttrList)
281 : {
282 35 : if( token::IsXMLToken( _rLocalName, token::XML_PROPERTIES) )
283 : {
284 35 : return new OPropertyElementsContext( m_rContext.getGlobalContext(),
285 35 : _nPrefix, _rLocalName, this);
286 : }
287 : else
288 : {
289 : OSL_FAIL(OStringBuffer("OPropertyImport::CreateChildContext: unknown sub element (only \"properties\" is recognized, but it is ").
290 : append(OUStringToOString(_rLocalName, RTL_TEXTENCODING_ASCII_US)).
291 : append(")!").getStr());
292 0 : return SvXMLImportContext::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
293 : }
294 : }
295 :
296 : //---------------------------------------------------------------------
297 36 : void OPropertyImport::StartElement(const Reference< XAttributeList >& _rxAttrList)
298 : {
299 : OSL_ENSURE(_rxAttrList.is(), "OPropertyImport::StartElement: invalid attribute list!");
300 36 : const sal_Int32 nAttributeCount = _rxAttrList->getLength();
301 :
302 : // assume the 'worst' case: all attributes describe properties. This should save our property array
303 : // some reallocs
304 36 : m_aValues.reserve(nAttributeCount);
305 :
306 36 : const SvXMLNamespaceMap& rMap = m_rContext.getGlobalContext().GetNamespaceMap();
307 : sal_uInt16 nNamespace;
308 36 : OUString sLocalName;
309 244 : for (sal_Int16 i=0; i<nAttributeCount; ++i)
310 : {
311 208 : nNamespace = rMap.GetKeyByAttrName(_rxAttrList->getNameByIndex(i), &sLocalName);
312 208 : handleAttribute(nNamespace, sLocalName, _rxAttrList->getValueByIndex(i));
313 :
314 208 : if (m_bTrackAttributes)
315 168 : m_aEncounteredAttributes.insert(sLocalName);
316 36 : }
317 :
318 : // TODO: create PropertyValues for all the attributes which were not present, because they were implied
319 : // this is necessary as soon as we have properties where the XML default is different from the property
320 : // default
321 36 : }
322 :
323 : //---------------------------------------------------------------------
324 26 : sal_Bool OPropertyImport::encounteredAttribute(const OUString& _rAttributeName) const
325 : {
326 : OSL_ENSURE(m_bTrackAttributes, "OPropertyImport::encounteredAttribute: attribute tracking not enabled!");
327 26 : return m_aEncounteredAttributes.end() != m_aEncounteredAttributes.find(_rAttributeName);
328 : }
329 :
330 : //---------------------------------------------------------------------
331 42 : void OPropertyImport::Characters(const OUString&
332 : #if OSL_DEBUG_LEVEL > 0
333 : _rChars
334 : #endif
335 : )
336 : {
337 : // ignore them (should be whitespaces only)
338 : OSL_ENSURE(_rChars.trim().isEmpty(), "OPropertyImport::Characters: non-whitespace characters!");
339 42 : }
340 :
341 : //---------------------------------------------------------------------
342 92 : bool OPropertyImport::handleAttribute(sal_uInt16 /*_nNamespaceKey*/, const OUString& _rLocalName, const OUString& _rValue)
343 : {
344 92 : const OAttribute2Property::AttributeAssignment* pProperty = m_rContext.getAttributeMap().getAttributeTranslation(_rLocalName);
345 92 : if (pProperty)
346 : {
347 : // create and store a new PropertyValue
348 91 : PropertyValue aNewValue;
349 91 : aNewValue.Name = pProperty->sPropertyName;
350 :
351 : // convert the value string into the target type
352 91 : aNewValue.Value = PropertyConversion::convertString(m_rContext.getGlobalContext(), pProperty->aPropertyType, _rValue, pProperty->pEnumMap, pProperty->bInverseSemantics);
353 91 : implPushBackPropertyValue( aNewValue );
354 91 : return true;
355 : }
356 1 : if (!token::IsXMLToken(_rLocalName, token::XML_TYPE)) // xlink:type is valid but ignored for <form:form>
357 : {
358 : #if OSL_DEBUG_LEVEL > 0
359 : OString sMessage( "OPropertyImport::handleAttribute: Can't handle the following:\n" );
360 : sMessage += OString( " Attribute name: " );
361 : sMessage += OString( _rLocalName.getStr(), _rLocalName.getLength(), osl_getThreadTextEncoding() );
362 : sMessage += OString( "\n value: " );
363 : sMessage += OString( _rValue.getStr(), _rValue.getLength(), osl_getThreadTextEncoding() );
364 : OSL_FAIL( sMessage.getStr() );
365 : #endif
366 0 : return false;
367 : }
368 1 : return true;
369 : }
370 :
371 : //=====================================================================
372 : //= OPropertyElementsContext
373 : //=====================================================================
374 : //---------------------------------------------------------------------
375 35 : OPropertyElementsContext::OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
376 : const OPropertyImportRef& _rPropertyImporter)
377 : :SvXMLImportContext(_rImport, _nPrefix, _rName)
378 35 : ,m_xPropertyImporter(_rPropertyImporter)
379 : {
380 35 : }
381 :
382 : //---------------------------------------------------------------------
383 65 : SvXMLImportContext* OPropertyElementsContext::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
384 : const Reference< XAttributeList >&)
385 : {
386 65 : if( token::IsXMLToken( _rLocalName, token::XML_PROPERTY ) )
387 : {
388 65 : return new OSinglePropertyContext(GetImport(), _nPrefix, _rLocalName, m_xPropertyImporter);
389 : }
390 0 : else if( token::IsXMLToken( _rLocalName, token::XML_LIST_PROPERTY ) )
391 : {
392 0 : return new OListPropertyContext( GetImport(), _nPrefix, _rLocalName, m_xPropertyImporter );
393 : }
394 : else
395 : {
396 : OSL_FAIL(OStringBuffer("OPropertyElementsContext::CreateChildContext: unknown child element (\"").
397 : append(OUStringToOString(_rLocalName, RTL_TEXTENCODING_ASCII_US)).
398 : append("\")!").getStr());
399 0 : return new SvXMLImportContext(GetImport(), _nPrefix, _rLocalName);
400 : }
401 : }
402 :
403 : #if OSL_DEBUG_LEVEL > 0
404 : //---------------------------------------------------------------------
405 : void OPropertyElementsContext::StartElement(const Reference< XAttributeList >& _rxAttrList)
406 : {
407 : OSL_ENSURE(0 == _rxAttrList->getLength(), "OPropertyElementsContext::StartElement: the form:properties element should not have attributes!");
408 : SvXMLImportContext::StartElement(_rxAttrList);
409 : }
410 :
411 : //---------------------------------------------------------------------
412 : void OPropertyElementsContext::Characters(const OUString& _rChars)
413 : {
414 : OSL_ENSURE(0 == _rChars.trim(), "OPropertyElementsContext::Characters: non-whitespace characters detected!");
415 : SvXMLImportContext::Characters(_rChars);
416 : }
417 :
418 : #endif
419 :
420 : //=====================================================================
421 : //= OSinglePropertyContext
422 : //=====================================================================
423 : //---------------------------------------------------------------------
424 65 : OSinglePropertyContext::OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
425 : const OPropertyImportRef& _rPropertyImporter)
426 : :SvXMLImportContext(_rImport, _nPrefix, _rName)
427 65 : ,m_xPropertyImporter(_rPropertyImporter)
428 : {
429 65 : }
430 :
431 : //---------------------------------------------------------------------
432 0 : SvXMLImportContext* OSinglePropertyContext::CreateChildContext(sal_uInt16 _nPrefix, const OUString& _rLocalName,
433 : const Reference< XAttributeList >&)
434 : {
435 : OSL_FAIL(OStringBuffer("OSinglePropertyContext::CreateChildContext: unknown child element (\"").
436 : append(OUStringToOString(_rLocalName, RTL_TEXTENCODING_ASCII_US)).
437 : append("\")!").getStr());
438 0 : return new SvXMLImportContext(GetImport(), _nPrefix, _rLocalName);
439 : }
440 :
441 : //---------------------------------------------------------------------
442 65 : void OSinglePropertyContext::StartElement(const Reference< XAttributeList >& _rxAttrList)
443 : {
444 65 : ::com::sun::star::beans::PropertyValue aPropValue; // the property the instance imports currently
445 130 : ::com::sun::star::uno::Type aPropType; // the type of the property the instance imports currently
446 :
447 130 : OUString sType, sValue;
448 65 : const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
449 65 : const sal_Int16 nAttrCount = _rxAttrList.is() ? _rxAttrList->getLength() : 0;
450 255 : for( sal_Int16 i=0; i < nAttrCount; i++ )
451 : {
452 190 : const OUString& rAttrName = _rxAttrList->getNameByIndex( i );
453 :
454 380 : OUString aLocalName;
455 : sal_uInt16 nPrefix =
456 : rMap.GetKeyByAttrName( rAttrName,
457 190 : &aLocalName );
458 190 : if( XML_NAMESPACE_FORM == nPrefix )
459 : {
460 65 : if( token::IsXMLToken( aLocalName, token::XML_PROPERTY_NAME ) )
461 65 : aPropValue.Name = _rxAttrList->getValueByIndex( i );
462 :
463 : }
464 125 : else if( XML_NAMESPACE_OFFICE == nPrefix )
465 : {
466 125 : if( token::IsXMLToken( aLocalName, token::XML_VALUE_TYPE ) )
467 65 : sType = _rxAttrList->getValueByIndex( i );
468 60 : else if( token::IsXMLToken( aLocalName,
469 114 : token::XML_VALUE ) ||
470 : token::IsXMLToken( aLocalName,
471 113 : token::XML_BOOLEAN_VALUE ) ||
472 : token::IsXMLToken( aLocalName,
473 53 : token::XML_STRING_VALUE ) )
474 60 : sValue = _rxAttrList->getValueByIndex( i );
475 : }
476 190 : }
477 :
478 : // the name of the property
479 : OSL_ENSURE(!aPropValue.Name.isEmpty(), "OSinglePropertyContext::StartElement: invalid property name!");
480 :
481 : // needs to be translated into a ::com::sun::star::uno::Type
482 65 : aPropType = PropertyConversion::xmlTypeToUnoType( sType );
483 65 : if( TypeClass_VOID == aPropType.getTypeClass() )
484 : {
485 5 : aPropValue.Value = Any();
486 : }
487 : else
488 : {
489 120 : aPropValue.Value =
490 60 : PropertyConversion::convertString(GetImport(), aPropType,
491 60 : sValue);
492 : }
493 :
494 : // now that we finally have our property value, add it to our parent object
495 65 : if( !aPropValue.Name.isEmpty() )
496 130 : m_xPropertyImporter->implPushBackGenericPropertyValue(aPropValue);
497 65 : }
498 :
499 : //=====================================================================
500 : //= OListPropertyContext
501 : //=====================================================================
502 : //---------------------------------------------------------------------
503 0 : OListPropertyContext::OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
504 : const OPropertyImportRef& _rPropertyImporter )
505 : :SvXMLImportContext( _rImport, _nPrefix, _rName )
506 0 : ,m_xPropertyImporter( _rPropertyImporter )
507 : {
508 0 : }
509 :
510 : //---------------------------------------------------------------------
511 0 : void OListPropertyContext::StartElement( const Reference< XAttributeList >& _rxAttrList )
512 : {
513 0 : sal_Int32 nAttributeCount = _rxAttrList->getLength();
514 :
515 : sal_uInt16 nNamespace;
516 0 : OUString sAttributeName;
517 0 : const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
518 0 : for ( sal_Int16 i = 0; i < nAttributeCount; ++i )
519 : {
520 0 : nNamespace = rMap.GetKeyByAttrName( _rxAttrList->getNameByIndex( i ), &sAttributeName );
521 0 : if ( ( XML_NAMESPACE_FORM == nNamespace )
522 0 : && ( token::IsXMLToken( sAttributeName, token::XML_PROPERTY_NAME ) )
523 : )
524 : {
525 0 : m_sPropertyName = _rxAttrList->getValueByIndex( i );
526 : }
527 0 : else if ( ( XML_NAMESPACE_OFFICE == nNamespace )
528 0 : && ( token::IsXMLToken( sAttributeName, token::XML_VALUE_TYPE ) )
529 : )
530 : {
531 0 : m_sPropertyType = _rxAttrList->getValueByIndex( i );
532 : }
533 : else
534 : {
535 : OSL_FAIL( OStringBuffer( "OListPropertyContext::StartElement: unknown child element (\"").
536 : append(OUStringToOString(sAttributeName, RTL_TEXTENCODING_ASCII_US)).
537 : append("\")!").getStr() );
538 : }
539 0 : }
540 0 : }
541 :
542 : //---------------------------------------------------------------------
543 0 : void OListPropertyContext::EndElement()
544 : {
545 : OSL_ENSURE( !m_sPropertyName.isEmpty() && !m_sPropertyType.isEmpty(),
546 : "OListPropertyContext::EndElement: no property name or type!" );
547 :
548 0 : if ( m_sPropertyName.isEmpty() || m_sPropertyType.isEmpty() )
549 0 : return;
550 :
551 0 : Sequence< Any > aListElements( m_aListValues.size() );
552 0 : Any* pListElement = aListElements.getArray();
553 0 : com::sun::star::uno::Type aType = PropertyConversion::xmlTypeToUnoType( m_sPropertyType );
554 0 : for ( ::std::vector< OUString >::const_iterator values = m_aListValues.begin();
555 0 : values != m_aListValues.end();
556 : ++values, ++pListElement
557 : )
558 : {
559 0 : *pListElement = PropertyConversion::convertString( GetImport(), aType, *values );
560 : }
561 :
562 0 : PropertyValue aSequenceValue;
563 0 : aSequenceValue.Name = m_sPropertyName;
564 0 : aSequenceValue.Value <<= aListElements;
565 :
566 0 : m_xPropertyImporter->implPushBackGenericPropertyValue( aSequenceValue );
567 : }
568 :
569 : //---------------------------------------------------------------------
570 0 : SvXMLImportContext* OListPropertyContext::CreateChildContext( sal_uInt16 _nPrefix, const OUString& _rLocalName, const Reference< XAttributeList >& /*_rxAttrList*/ )
571 : {
572 0 : if ( token::IsXMLToken( _rLocalName, token::XML_LIST_VALUE ) )
573 : {
574 0 : m_aListValues.resize( m_aListValues.size() + 1 );
575 0 : return new OListValueContext( GetImport(), _nPrefix, _rLocalName, *m_aListValues.rbegin() );
576 : }
577 : else
578 : {
579 : OSL_FAIL( OStringBuffer("OListPropertyContext::CreateChildContext: unknown child element (\"").
580 : append(OUStringToOString(_rLocalName.getStr(), RTL_TEXTENCODING_ASCII_US)).
581 : append("\")!").getStr() );
582 0 : return new SvXMLImportContext( GetImport(), _nPrefix, _rLocalName );
583 : }
584 : }
585 :
586 : //=====================================================================
587 : //= OListValueContext
588 : //=====================================================================
589 : //---------------------------------------------------------------------
590 0 : OListValueContext::OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName, OUString& _rListValueHolder )
591 : :SvXMLImportContext( _rImport, _nPrefix, _rName )
592 0 : ,m_rListValueHolder( _rListValueHolder )
593 : {
594 0 : }
595 :
596 : //---------------------------------------------------------------------
597 0 : void OListValueContext::StartElement( const Reference< XAttributeList >& _rxAttrList )
598 : {
599 0 : const sal_Int32 nAttributeCount = _rxAttrList->getLength();
600 :
601 : sal_uInt16 nNamespace;
602 0 : OUString sAttributeName;
603 0 : const SvXMLNamespaceMap& rMap = GetImport().GetNamespaceMap();
604 0 : for ( sal_Int16 i = 0; i < nAttributeCount; ++i )
605 : {
606 0 : nNamespace = rMap.GetKeyByAttrName( _rxAttrList->getNameByIndex( i ), &sAttributeName );
607 0 : if ( XML_NAMESPACE_OFFICE == nNamespace )
608 : {
609 0 : if ( token::IsXMLToken( sAttributeName, token::XML_VALUE )
610 0 : || token::IsXMLToken( sAttributeName, token::XML_STRING_VALUE )
611 0 : || token::IsXMLToken( sAttributeName, token::XML_BOOLEAN_VALUE )
612 : )
613 : {
614 0 : m_rListValueHolder = _rxAttrList->getValueByIndex( i );
615 0 : continue;
616 : }
617 : }
618 :
619 : OSL_FAIL( OStringBuffer( "OListValueContext::StartElement: unknown child element (\"").
620 : append(OUStringToOString(sAttributeName, RTL_TEXTENCODING_ASCII_US)).
621 : append("\")!").getStr() );
622 0 : }
623 0 : }
624 :
625 : //.........................................................................
626 : } // namespace xmloff
627 : //.........................................................................
628 :
629 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|