1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "docprophandler.hxx"
25
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/beans/PropertyExistException.hpp>
28 #include <com/sun/star/lang/Locale.hpp>
29
30 #include <osl/time.h>
31
32 #include "oox/helper/attributelist.hxx"
33
34 using namespace ::com::sun::star;
35
36 namespace oox {
37 namespace docprop {
38
39 // ------------------------------------------------
OOXMLDocPropHandler(const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<document::XDocumentProperties> xDocProp)40 OOXMLDocPropHandler::OOXMLDocPropHandler( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< document::XDocumentProperties > xDocProp )
41 : m_xContext( xContext )
42 , m_xDocProp( xDocProp )
43 , m_nState( 0 )
44 , m_nBlock( 0 )
45 , m_nType( 0 )
46 , m_nInBlock( 0 )
47 {
48 if ( !xContext.is() || !xDocProp.is() )
49 throw uno::RuntimeException();
50 }
51
52 // ------------------------------------------------
~OOXMLDocPropHandler()53 OOXMLDocPropHandler::~OOXMLDocPropHandler()
54 {
55 }
56
57 // ------------------------------------------------
InitNew()58 void OOXMLDocPropHandler::InitNew()
59 {
60 m_nState = 0;
61 m_nBlock = 0;
62 m_aCustomPropertyName = ::rtl::OUString();
63 m_nType = 0;
64 m_nInBlock = 0;
65 }
66
67 // ------------------------------------------------
AddCustomProperty(const uno::Any & aAny)68 void OOXMLDocPropHandler::AddCustomProperty( const uno::Any& aAny )
69 {
70 if ( m_aCustomPropertyName.getLength() )
71 {
72 const uno::Reference< beans::XPropertyContainer > xUserProps =
73 m_xDocProp->getUserDefinedProperties();
74 if ( !xUserProps.is() )
75 throw uno::RuntimeException();
76
77 try
78 {
79 xUserProps->addProperty( m_aCustomPropertyName,
80 beans::PropertyAttribute::REMOVEABLE, aAny );
81 }
82 catch( beans::PropertyExistException& )
83 {
84 // conflicts with core and extended properties are possible
85 }
86 catch( uno::Exception& )
87 {
88 OSL_ASSERT( "Can not add custom property!" );
89 }
90 }
91 }
92
93 // ------------------------------------------------
GetDateTimeFromW3CDTF(const::rtl::OUString & aChars)94 util::DateTime OOXMLDocPropHandler::GetDateTimeFromW3CDTF( const ::rtl::OUString& aChars )
95 {
96 oslDateTime aOslDTime = { 0, 0, 0, 0, 0, 0, 0, 0 };
97 sal_Int32 nLen = aChars.getLength();
98 if ( nLen >= 4 )
99 {
100 aOslDTime.Year = (sal_uInt16)aChars.copy( 0, 4 ).toInt32();
101
102 if ( nLen >= 7 && aChars.getStr()[4] == (sal_Unicode)'-' )
103 {
104 aOslDTime.Month = (sal_uInt16)aChars.copy( 5, 2 ).toInt32();
105
106 if ( nLen >= 10 && aChars.getStr()[7] == (sal_Unicode)'-' )
107 {
108 aOslDTime.Day = (sal_uInt16)aChars.copy( 8, 2 ).toInt32();
109
110 if ( nLen >= 16 && aChars.getStr()[10] == (sal_Unicode)'T' && aChars.getStr()[13] == (sal_Unicode)':' )
111 {
112 aOslDTime.Hours = (sal_uInt16)aChars.copy( 11, 2 ).toInt32();
113 aOslDTime.Minutes = (sal_uInt16)aChars.copy( 14, 2 ).toInt32();
114
115 sal_Int32 nOptTime = 0;
116 if ( nLen >= 19 && aChars.getStr()[16] == (sal_Unicode)':' )
117 {
118 aOslDTime.Seconds = (sal_uInt16)aChars.copy( 17, 2 ).toInt32();
119 nOptTime += 3;
120 if ( nLen >= 21 && aChars.getStr()[19] == (sal_Unicode)'.' )
121 {
122 aOslDTime.NanoSeconds = (sal_uInt32)(aChars.copy( 20, 1 ).toInt32() * 10e8);
123 nOptTime += 2;
124 }
125 }
126
127 sal_Int32 nModif = 0;
128 if ( nLen >= 16 + nOptTime + 6 )
129 {
130 if ( ( aChars.getStr()[16 + nOptTime] == (sal_Unicode)'+' || aChars.getStr()[16 + nOptTime] == (sal_Unicode)'-' )
131 && aChars.getStr()[16 + nOptTime + 3] == (sal_Unicode)':' )
132
133 {
134 nModif = aChars.copy( 16 + nOptTime + 1, 2 ).toInt32() * 3600;
135 nModif += aChars.copy( 16 + nOptTime + 4, 2 ).toInt32() * 60;
136 if ( aChars.getStr()[16 + nOptTime] == (sal_Unicode)'-' )
137 nModif *= -1;
138 }
139 }
140
141 if ( nModif )
142 {
143 // convert to UTC time
144 TimeValue aTmp;
145 if ( osl_getTimeValueFromDateTime( &aOslDTime, &aTmp ) )
146 {
147 aTmp.Seconds += nModif;
148 osl_getDateTimeFromTimeValue( &aTmp, &aOslDTime );
149 }
150 }
151 }
152 }
153 }
154 }
155
156 return util::DateTime( (sal_uInt16)( aOslDTime.NanoSeconds / 1e7 ), aOslDTime.Seconds, aOslDTime.Minutes, aOslDTime.Hours, aOslDTime.Day, aOslDTime.Month, aOslDTime.Year );
157 }
158
159 // ------------------------------------------------
GetKeywordsSet(const::rtl::OUString & aChars)160 uno::Sequence< ::rtl::OUString > OOXMLDocPropHandler::GetKeywordsSet( const ::rtl::OUString& aChars )
161 {
162 if ( aChars.getLength() )
163 {
164 uno::Sequence< ::rtl::OUString > aResult( 20 );
165 sal_Int32 nCounter = 0;
166
167 const sal_Unicode* pStr = aChars.getStr();
168 for( sal_Int32 nInd = 0; nInd < aChars.getLength() && pStr[nInd] != 0; nInd++ )
169 {
170 switch( pStr[nInd] )
171 {
172 case (sal_Unicode)' ':
173 case (sal_Unicode)',':
174 case (sal_Unicode)';':
175 case (sal_Unicode)':':
176 case (sal_Unicode)'\t':
177 // this is a delimiter
178 // unfortunately I did not find any specification for the possible delimiters
179 if ( aResult[nCounter].getLength() )
180 {
181 if ( nCounter >= aResult.getLength() )
182 aResult.realloc( nCounter + 10 );
183 nCounter++;
184 }
185 break;
186
187 default:
188 // this should be a part of keyword
189 aResult[nCounter] += ::rtl::OUString( (sal_Unicode)pStr[nInd] );
190 }
191 }
192
193 aResult.realloc( nCounter + 1 );
194 return aResult;
195 }
196
197 return uno::Sequence< ::rtl::OUString >();
198 }
199 // ------------------------------------------------
GetLanguage(const::rtl::OUString & aChars)200 lang::Locale OOXMLDocPropHandler::GetLanguage( const ::rtl::OUString& aChars )
201 {
202 lang::Locale aResult;
203 if ( aChars.getLength() >= 2 )
204 {
205 aResult.Language = aChars.copy( 0, 2 );
206 if ( aChars.getLength() >= 5 && aChars.getStr()[2] == (sal_Unicode)'-' )
207 aResult.Country = aChars.copy( 3, 2 );
208
209 // TODO/LATER: the variant could be also detected
210 }
211
212 return aResult;
213 }
214
215 // ------------------------------------------------
UpdateDocStatistic(const::rtl::OUString & aChars)216 void OOXMLDocPropHandler::UpdateDocStatistic( const ::rtl::OUString& aChars )
217 {
218 uno::Sequence< beans::NamedValue > aSet = m_xDocProp->getDocumentStatistics();
219 ::rtl::OUString aName;
220
221 switch( m_nBlock )
222 {
223 case EXTPR_TOKEN( Characters ):
224 aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterCount" ) );
225 break;
226
227 case EXTPR_TOKEN( Pages ):
228 aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageCount" ) );
229 break;
230
231 case EXTPR_TOKEN( Words ):
232 aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WordCount" ) );
233 break;
234
235 case EXTPR_TOKEN( Paragraphs ):
236 aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphCount" ) );
237 break;
238
239 default:
240 OSL_ASSERT( "Unexpected statistic!" );
241 break;
242 }
243
244 if ( aName.getLength() )
245 {
246 sal_Bool bFound = sal_False;
247 sal_Int32 nLen = aSet.getLength();
248 for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
249 if ( aSet[nInd].Name.equals( aName ) )
250 {
251 aSet[nInd].Value = uno::makeAny( aChars.toInt32() );
252 bFound = sal_True;
253 break;
254 }
255
256 if ( !bFound )
257 {
258 aSet.realloc( nLen + 1 );
259 aSet[nLen].Name = aName;
260 aSet[nLen].Value = uno::makeAny( aChars.toInt32() );
261 }
262
263 m_xDocProp->setDocumentStatistics( aSet );
264 }
265 }
266
267 // ------------------------------------------------
268 // com.sun.star.xml.sax.XFastDocumentHandler
269 // ------------------------------------------------
startDocument()270 void SAL_CALL OOXMLDocPropHandler::startDocument()
271 {
272 }
273
274 // ------------------------------------------------
endDocument()275 void SAL_CALL OOXMLDocPropHandler::endDocument()
276 {
277 InitNew();
278 }
279
280 // ------------------------------------------------
setDocumentLocator(const uno::Reference<xml::sax::XLocator> &)281 void SAL_CALL OOXMLDocPropHandler::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& )
282 {
283 }
284
285
286 // com.sun.star.xml.sax.XFastContextHandler
287 // ------------------------------------------------
startFastElement(::sal_Int32 nElement,const uno::Reference<xml::sax::XFastAttributeList> & xAttribs)288 void SAL_CALL OOXMLDocPropHandler::startFastElement( ::sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs )
289 {
290 if ( !m_nInBlock && !m_nState )
291 {
292 if ( nElement == COREPR_TOKEN( coreProperties )
293 || nElement == EXTPR_TOKEN( Properties )
294 || nElement == CUSTPR_TOKEN( Properties ) )
295 {
296 m_nState = nElement;
297 }
298 else
299 {
300 OSL_ASSERT( "Unexpected file format!" );
301 }
302 }
303 else if ( m_nState && m_nInBlock == 1 ) // that tag should contain the property name
304 {
305 // Currently the attributes are ignored for the core properties since the only
306 // known attribute is xsi:type that can only be used with dcterms:created and
307 // dcterms:modified, and this element is allowed currently to have only one value dcterms:W3CDTF
308 m_nBlock = nElement;
309
310 if ( xAttribs.is() && xAttribs->hasAttribute( XML_name ) )
311 m_aCustomPropertyName = xAttribs->getValue( XML_name );
312 }
313 else if ( m_nState && m_nInBlock && m_nInBlock == 2 && getNamespace( nElement ) == NMSP_officeDocPropsVT )
314 {
315 m_nType = nElement;
316 }
317 else
318 {
319 OSL_ASSERT( "For now unexpected tags are ignored!" );
320 }
321
322 if ( m_nInBlock == SAL_MAX_INT32 )
323 throw uno::RuntimeException();
324
325 m_nInBlock++;
326 }
327
328 // ------------------------------------------------
startUnknownElement(const::rtl::OUString & aNamespace,const::rtl::OUString & aName,const uno::Reference<xml::sax::XFastAttributeList> &)329 void SAL_CALL OOXMLDocPropHandler::startUnknownElement( const ::rtl::OUString& aNamespace, const ::rtl::OUString& aName, const uno::Reference< xml::sax::XFastAttributeList >& )
330 {
331 ::rtl::OUString aUnknown = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown element" ) );
332 aUnknown += aNamespace;
333 aUnknown += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":" ) );
334 aUnknown += aName;
335 OSL_ASSERT( ::rtl::OUStringToOString( aUnknown, RTL_TEXTENCODING_UTF8 ).getStr() );
336
337 if ( m_nInBlock == SAL_MAX_INT32 )
338 throw uno::RuntimeException();
339
340 m_nInBlock++;
341 }
342
343 // ------------------------------------------------
endFastElement(::sal_Int32)344 void SAL_CALL OOXMLDocPropHandler::endFastElement( ::sal_Int32 )
345 {
346 if ( m_nInBlock )
347 {
348 m_nInBlock--;
349
350 if ( !m_nInBlock )
351 m_nState = 0;
352 else if ( m_nInBlock == 1 )
353 {
354 m_nBlock = 0;
355 m_aCustomPropertyName = ::rtl::OUString();
356 }
357 else if ( m_nInBlock == 2 )
358 m_nType = 0;
359 }
360 }
361
362 // ------------------------------------------------
endUnknownElement(const::rtl::OUString &,const::rtl::OUString &)363 void SAL_CALL OOXMLDocPropHandler::endUnknownElement( const ::rtl::OUString&, const ::rtl::OUString& )
364 {
365 if ( m_nInBlock )
366 m_nInBlock--;
367 }
368
369 // ------------------------------------------------
createFastChildContext(::sal_Int32,const uno::Reference<xml::sax::XFastAttributeList> &)370 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createFastChildContext( ::sal_Int32, const uno::Reference< xml::sax::XFastAttributeList >& )
371 {
372 // Should the arguments be parsed?
373 return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) );
374 }
375
376 // ------------------------------------------------
createUnknownChildContext(const::rtl::OUString &,const::rtl::OUString &,const uno::Reference<xml::sax::XFastAttributeList> &)377 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createUnknownChildContext( const ::rtl::OUString&, const ::rtl::OUString&, const uno::Reference< xml::sax::XFastAttributeList >& )
378 {
379 return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) );
380 }
381
382 // ------------------------------------------------
characters(const::rtl::OUString & aChars)383 void SAL_CALL OOXMLDocPropHandler::characters( const ::rtl::OUString& aChars )
384 {
385 try
386 {
387 if ( (m_nInBlock == 2) || ((m_nInBlock == 3) && m_nType) )
388 {
389 if ( m_nState == COREPR_TOKEN( coreProperties ) )
390 {
391 switch( m_nBlock )
392 {
393 case COREPR_TOKEN( category ):
394 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "category" ) );
395 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
396 break;
397
398 case COREPR_TOKEN( contentStatus ):
399 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentStatus" ) );
400 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
401 break;
402
403 case COREPR_TOKEN( contentType ):
404 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentType" ) );
405 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
406 break;
407
408 case COREPR_TOKEN( identifier ):
409 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "identifier" ) );
410 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
411 break;
412
413 case COREPR_TOKEN( version ):
414 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "version" ) );
415 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
416 break;
417
418 case DCT_TOKEN( created ):
419 if ( aChars.getLength() >= 4 )
420 m_xDocProp->setCreationDate( GetDateTimeFromW3CDTF( aChars ) );
421 break;
422
423 case DC_TOKEN( creator ):
424 m_xDocProp->setAuthor( aChars );
425 break;
426
427 case DC_TOKEN( description ):
428 m_xDocProp->setDescription( aChars );
429 break;
430
431 case COREPR_TOKEN( keywords ):
432 m_xDocProp->setKeywords( GetKeywordsSet( aChars ) );
433 break;
434
435 case DC_TOKEN( language ):
436 if ( aChars.getLength() >= 2 )
437 m_xDocProp->setLanguage( GetLanguage( aChars ) );
438 break;
439
440 case COREPR_TOKEN( lastModifiedBy ):
441 m_xDocProp->setModifiedBy( aChars );
442 break;
443
444 case COREPR_TOKEN( lastPrinted ):
445 if ( aChars.getLength() >= 4 )
446 m_xDocProp->setPrintDate( GetDateTimeFromW3CDTF( aChars ) );
447 break;
448
449 case DCT_TOKEN( modified ):
450 if ( aChars.getLength() >= 4 )
451 m_xDocProp->setModificationDate( GetDateTimeFromW3CDTF( aChars ) );
452 break;
453
454 case COREPR_TOKEN( revision ):
455 try
456 {
457 m_xDocProp->setEditingCycles(
458 static_cast<sal_Int16>(aChars.toInt32()) );
459 }
460 catch (lang::IllegalArgumentException &)
461 {
462 // ignore
463 }
464 break;
465
466 case DC_TOKEN( subject ):
467 m_xDocProp->setSubject( aChars );
468 break;
469
470 case DC_TOKEN( title ):
471 m_xDocProp->setTitle( aChars );
472 break;
473
474 default:
475 OSL_ASSERT( "Unexpected core property!" );
476 }
477 }
478 else if ( m_nState == EXTPR_TOKEN( Properties ) )
479 {
480 switch( m_nBlock )
481 {
482 case EXTPR_TOKEN( Application ):
483 m_xDocProp->setGenerator( aChars );
484 break;
485
486 case EXTPR_TOKEN( Template ):
487 m_xDocProp->setTemplateName( aChars );
488 break;
489
490 case EXTPR_TOKEN( TotalTime ):
491 try
492 {
493 m_xDocProp->setEditingDuration( aChars.toInt32() );
494 }
495 catch (lang::IllegalArgumentException &)
496 {
497 // ignore
498 }
499 break;
500
501 case EXTPR_TOKEN( Characters ):
502 case EXTPR_TOKEN( Pages ):
503 case EXTPR_TOKEN( Words ):
504 case EXTPR_TOKEN( Paragraphs ):
505 UpdateDocStatistic( aChars );
506 break;
507
508 case EXTPR_TOKEN( HyperlinksChanged ):
509 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinksChanged" ) );
510 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
511 break;
512
513 case EXTPR_TOKEN( LinksUpToDate ):
514 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LinksUpToDate" ) );
515 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
516 break;
517
518 case EXTPR_TOKEN( ScaleCrop ):
519 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScaleCrop" ) );
520 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
521 break;
522
523 case EXTPR_TOKEN( SharedDoc ):
524 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShareDoc" ) );
525 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
526 break;
527
528 case EXTPR_TOKEN( DocSecurity ):
529 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocSecurity" ) );
530 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
531 break;
532
533 case EXTPR_TOKEN( HiddenSlides ):
534 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HiddenSlides" ) );
535 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
536 break;
537
538 case EXTPR_TOKEN( MMClips ):
539 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MMClips" ) );
540 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
541 break;
542
543 case EXTPR_TOKEN( Notes ):
544 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Notes" ) );
545 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
546 break;
547
548 case EXTPR_TOKEN( Slides ):
549 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Slides" ) );
550 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
551 break;
552
553 case EXTPR_TOKEN( AppVersion ):
554 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AppVersion" ) );
555 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
556 break;
557
558 case EXTPR_TOKEN( Company ):
559 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Company" ) );
560 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
561 break;
562
563 case EXTPR_TOKEN( HyperlinkBase ):
564 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinkBase" ) );
565 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
566 break;
567
568 case EXTPR_TOKEN( Manager ):
569 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Manager" ) );
570 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
571 break;
572
573 case EXTPR_TOKEN( PresentationFormat ):
574 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PresentationFormat" ) );
575 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
576 break;
577
578 case EXTPR_TOKEN( CharactersWithSpaces ):
579 case EXTPR_TOKEN( Lines ):
580 case EXTPR_TOKEN( DigSig ):
581 case EXTPR_TOKEN( HeadingPairs ):
582 case EXTPR_TOKEN( HLinks ):
583 case EXTPR_TOKEN( TitlesOfParts ):
584 // ignored during the import currently
585 break;
586
587 default:
588 OSL_ASSERT( "Unexpected extended property!" );
589 }
590 }
591 else if ( m_nState == CUSTPR_TOKEN( Properties ) )
592 {
593 if ( m_nBlock == CUSTPR_TOKEN( property ) )
594 {
595 // this is a custom property
596 switch( m_nType )
597 {
598 case VT_TOKEN( bool ):
599 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) );
600 break;
601
602 case VT_TOKEN( bstr ):
603 case VT_TOKEN( lpstr ):
604 case VT_TOKEN( lpwstr ):
605 AddCustomProperty( uno::makeAny( AttributeConversion::decodeXString( aChars ) ) ); // the property has string type
606 break;
607
608 case VT_TOKEN( date ):
609 case VT_TOKEN( filetime ):
610 AddCustomProperty( uno::makeAny( GetDateTimeFromW3CDTF( aChars ) ) );
611
612 case VT_TOKEN( i1 ):
613 case VT_TOKEN( i2 ):
614 AddCustomProperty( uno::makeAny( (sal_Int16)aChars.toInt32() ) );
615 break;
616
617 case VT_TOKEN( i4 ):
618 case VT_TOKEN( int ):
619 AddCustomProperty( uno::makeAny( aChars.toInt32() ) );
620 break;
621
622 case VT_TOKEN( i8 ):
623 AddCustomProperty( uno::makeAny( aChars.toInt64() ) );
624 break;
625
626 case VT_TOKEN( r4 ):
627 AddCustomProperty( uno::makeAny( aChars.toFloat() ) );
628 break;
629
630 case VT_TOKEN( r8 ):
631 AddCustomProperty( uno::makeAny( aChars.toDouble() ) );
632 break;
633
634 default:
635 // all the other types are ignored;
636 break;
637 }
638 }
639 else
640 {
641 OSL_ASSERT( "Unexpected tag in custom property!" );
642 }
643 }
644 }
645 }
646 catch( uno::RuntimeException& )
647 {
648 throw;
649 }
650 catch( xml::sax::SAXException& )
651 {
652 throw;
653 }
654 catch( uno::Exception& e )
655 {
656 throw xml::sax::SAXException(
657 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Error while setting document property!" ) ),
658 uno::Reference< uno::XInterface >(),
659 uno::makeAny( e ) );
660 }
661 }
662
663 // ------------------------------------------------
ignorableWhitespace(const::rtl::OUString &)664 void SAL_CALL OOXMLDocPropHandler::ignorableWhitespace( const ::rtl::OUString& )
665 {
666 }
667
668 // ------------------------------------------------
processingInstruction(const::rtl::OUString &,const::rtl::OUString &)669 void SAL_CALL OOXMLDocPropHandler::processingInstruction( const ::rtl::OUString&, const ::rtl::OUString& )
670 {
671 }
672
673 } // namespace docprop
674 } // namespace oox
675