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