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 throw (xml::sax::SAXException, uno::RuntimeException)
272 {
273 }
274
275 // ------------------------------------------------
endDocument()276 void SAL_CALL OOXMLDocPropHandler::endDocument()
277 throw (xml::sax::SAXException, uno::RuntimeException)
278 {
279 InitNew();
280 }
281
282 // ------------------------------------------------
setDocumentLocator(const uno::Reference<xml::sax::XLocator> &)283 void SAL_CALL OOXMLDocPropHandler::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& )
284 throw (xml::sax::SAXException, uno::RuntimeException)
285 {
286 }
287
288
289 // com.sun.star.xml.sax.XFastContextHandler
290 // ------------------------------------------------
startFastElement(::sal_Int32 nElement,const uno::Reference<xml::sax::XFastAttributeList> & xAttribs)291 void SAL_CALL OOXMLDocPropHandler::startFastElement( ::sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs )
292 throw (xml::sax::SAXException, uno::RuntimeException)
293 {
294 if ( !m_nInBlock && !m_nState )
295 {
296 if ( nElement == COREPR_TOKEN( coreProperties )
297 || nElement == EXTPR_TOKEN( Properties )
298 || nElement == CUSTPR_TOKEN( Properties ) )
299 {
300 m_nState = nElement;
301 }
302 else
303 {
304 OSL_ASSERT( "Unexpected file format!" );
305 }
306 }
307 else if ( m_nState && m_nInBlock == 1 ) // that tag should contain the property name
308 {
309 // Currently the attributes are ignored for the core properties since the only
310 // known attribute is xsi:type that can only be used with dcterms:created and
311 // dcterms:modified, and this element is allowed currently to have only one value dcterms:W3CDTF
312 m_nBlock = nElement;
313
314 if ( xAttribs.is() && xAttribs->hasAttribute( XML_name ) )
315 m_aCustomPropertyName = xAttribs->getValue( XML_name );
316 }
317 else if ( m_nState && m_nInBlock && m_nInBlock == 2 && getNamespace( nElement ) == NMSP_officeDocPropsVT )
318 {
319 m_nType = nElement;
320 }
321 else
322 {
323 OSL_ASSERT( "For now unexpected tags are ignored!" );
324 }
325
326 if ( m_nInBlock == SAL_MAX_INT32 )
327 throw uno::RuntimeException();
328
329 m_nInBlock++;
330 }
331
332 // ------------------------------------------------
startUnknownElement(const::rtl::OUString & aNamespace,const::rtl::OUString & aName,const uno::Reference<xml::sax::XFastAttributeList> &)333 void SAL_CALL OOXMLDocPropHandler::startUnknownElement( const ::rtl::OUString& aNamespace, const ::rtl::OUString& aName, const uno::Reference< xml::sax::XFastAttributeList >& )
334 throw (xml::sax::SAXException, uno::RuntimeException)
335 {
336 ::rtl::OUString aUnknown = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown element" ) );
337 aUnknown += aNamespace;
338 aUnknown += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":" ) );
339 aUnknown += aName;
340 OSL_ASSERT( ::rtl::OUStringToOString( aUnknown, RTL_TEXTENCODING_UTF8 ).getStr() );
341
342 if ( m_nInBlock == SAL_MAX_INT32 )
343 throw uno::RuntimeException();
344
345 m_nInBlock++;
346 }
347
348 // ------------------------------------------------
endFastElement(::sal_Int32)349 void SAL_CALL OOXMLDocPropHandler::endFastElement( ::sal_Int32 )
350 throw (xml::sax::SAXException, uno::RuntimeException)
351 {
352 if ( m_nInBlock )
353 {
354 m_nInBlock--;
355
356 if ( !m_nInBlock )
357 m_nState = 0;
358 else if ( m_nInBlock == 1 )
359 {
360 m_nBlock = 0;
361 m_aCustomPropertyName = ::rtl::OUString();
362 }
363 else if ( m_nInBlock == 2 )
364 m_nType = 0;
365 }
366 }
367
368 // ------------------------------------------------
endUnknownElement(const::rtl::OUString &,const::rtl::OUString &)369 void SAL_CALL OOXMLDocPropHandler::endUnknownElement( const ::rtl::OUString&, const ::rtl::OUString& )
370 throw (xml::sax::SAXException, uno::RuntimeException)
371 {
372 if ( m_nInBlock )
373 m_nInBlock--;
374 }
375
376 // ------------------------------------------------
createFastChildContext(::sal_Int32,const uno::Reference<xml::sax::XFastAttributeList> &)377 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createFastChildContext( ::sal_Int32, const uno::Reference< xml::sax::XFastAttributeList >& )
378 throw (xml::sax::SAXException, uno::RuntimeException)
379 {
380 // Should the arguments be parsed?
381 return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) );
382 }
383
384 // ------------------------------------------------
createUnknownChildContext(const::rtl::OUString &,const::rtl::OUString &,const uno::Reference<xml::sax::XFastAttributeList> &)385 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createUnknownChildContext( const ::rtl::OUString&, const ::rtl::OUString&, const uno::Reference< xml::sax::XFastAttributeList >& )
386 throw (xml::sax::SAXException, uno::RuntimeException)
387 {
388 return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) );
389 }
390
391 // ------------------------------------------------
characters(const::rtl::OUString & aChars)392 void SAL_CALL OOXMLDocPropHandler::characters( const ::rtl::OUString& aChars )
393 throw (xml::sax::SAXException, uno::RuntimeException)
394 {
395 try
396 {
397 if ( (m_nInBlock == 2) || ((m_nInBlock == 3) && m_nType) )
398 {
399 if ( m_nState == COREPR_TOKEN( coreProperties ) )
400 {
401 switch( m_nBlock )
402 {
403 case COREPR_TOKEN( category ):
404 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "category" ) );
405 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
406 break;
407
408 case COREPR_TOKEN( contentStatus ):
409 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentStatus" ) );
410 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
411 break;
412
413 case COREPR_TOKEN( contentType ):
414 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentType" ) );
415 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
416 break;
417
418 case COREPR_TOKEN( identifier ):
419 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "identifier" ) );
420 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
421 break;
422
423 case COREPR_TOKEN( version ):
424 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "version" ) );
425 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
426 break;
427
428 case DCT_TOKEN( created ):
429 if ( aChars.getLength() >= 4 )
430 m_xDocProp->setCreationDate( GetDateTimeFromW3CDTF( aChars ) );
431 break;
432
433 case DC_TOKEN( creator ):
434 m_xDocProp->setAuthor( aChars );
435 break;
436
437 case DC_TOKEN( description ):
438 m_xDocProp->setDescription( aChars );
439 break;
440
441 case COREPR_TOKEN( keywords ):
442 m_xDocProp->setKeywords( GetKeywordsSet( aChars ) );
443 break;
444
445 case DC_TOKEN( language ):
446 if ( aChars.getLength() >= 2 )
447 m_xDocProp->setLanguage( GetLanguage( aChars ) );
448 break;
449
450 case COREPR_TOKEN( lastModifiedBy ):
451 m_xDocProp->setModifiedBy( aChars );
452 break;
453
454 case COREPR_TOKEN( lastPrinted ):
455 if ( aChars.getLength() >= 4 )
456 m_xDocProp->setPrintDate( GetDateTimeFromW3CDTF( aChars ) );
457 break;
458
459 case DCT_TOKEN( modified ):
460 if ( aChars.getLength() >= 4 )
461 m_xDocProp->setModificationDate( GetDateTimeFromW3CDTF( aChars ) );
462 break;
463
464 case COREPR_TOKEN( revision ):
465 try
466 {
467 m_xDocProp->setEditingCycles(
468 static_cast<sal_Int16>(aChars.toInt32()) );
469 }
470 catch (lang::IllegalArgumentException &)
471 {
472 // ignore
473 }
474 break;
475
476 case DC_TOKEN( subject ):
477 m_xDocProp->setSubject( aChars );
478 break;
479
480 case DC_TOKEN( title ):
481 m_xDocProp->setTitle( aChars );
482 break;
483
484 default:
485 OSL_ASSERT( "Unexpected core property!" );
486 }
487 }
488 else if ( m_nState == EXTPR_TOKEN( Properties ) )
489 {
490 switch( m_nBlock )
491 {
492 case EXTPR_TOKEN( Application ):
493 m_xDocProp->setGenerator( aChars );
494 break;
495
496 case EXTPR_TOKEN( Template ):
497 m_xDocProp->setTemplateName( aChars );
498 break;
499
500 case EXTPR_TOKEN( TotalTime ):
501 try
502 {
503 m_xDocProp->setEditingDuration( aChars.toInt32() );
504 }
505 catch (lang::IllegalArgumentException &)
506 {
507 // ignore
508 }
509 break;
510
511 case EXTPR_TOKEN( Characters ):
512 case EXTPR_TOKEN( Pages ):
513 case EXTPR_TOKEN( Words ):
514 case EXTPR_TOKEN( Paragraphs ):
515 UpdateDocStatistic( aChars );
516 break;
517
518 case EXTPR_TOKEN( HyperlinksChanged ):
519 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinksChanged" ) );
520 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
521 break;
522
523 case EXTPR_TOKEN( LinksUpToDate ):
524 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LinksUpToDate" ) );
525 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
526 break;
527
528 case EXTPR_TOKEN( ScaleCrop ):
529 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScaleCrop" ) );
530 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
531 break;
532
533 case EXTPR_TOKEN( SharedDoc ):
534 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShareDoc" ) );
535 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
536 break;
537
538 case EXTPR_TOKEN( DocSecurity ):
539 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocSecurity" ) );
540 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
541 break;
542
543 case EXTPR_TOKEN( HiddenSlides ):
544 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HiddenSlides" ) );
545 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
546 break;
547
548 case EXTPR_TOKEN( MMClips ):
549 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MMClips" ) );
550 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
551 break;
552
553 case EXTPR_TOKEN( Notes ):
554 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Notes" ) );
555 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
556 break;
557
558 case EXTPR_TOKEN( Slides ):
559 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Slides" ) );
560 AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
561 break;
562
563 case EXTPR_TOKEN( AppVersion ):
564 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AppVersion" ) );
565 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
566 break;
567
568 case EXTPR_TOKEN( Company ):
569 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Company" ) );
570 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
571 break;
572
573 case EXTPR_TOKEN( HyperlinkBase ):
574 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinkBase" ) );
575 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
576 break;
577
578 case EXTPR_TOKEN( Manager ):
579 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Manager" ) );
580 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
581 break;
582
583 case EXTPR_TOKEN( PresentationFormat ):
584 m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PresentationFormat" ) );
585 AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
586 break;
587
588 case EXTPR_TOKEN( CharactersWithSpaces ):
589 case EXTPR_TOKEN( Lines ):
590 case EXTPR_TOKEN( DigSig ):
591 case EXTPR_TOKEN( HeadingPairs ):
592 case EXTPR_TOKEN( HLinks ):
593 case EXTPR_TOKEN( TitlesOfParts ):
594 // ignored during the import currently
595 break;
596
597 default:
598 OSL_ASSERT( "Unexpected extended property!" );
599 }
600 }
601 else if ( m_nState == CUSTPR_TOKEN( Properties ) )
602 {
603 if ( m_nBlock == CUSTPR_TOKEN( property ) )
604 {
605 // this is a custom property
606 switch( m_nType )
607 {
608 case VT_TOKEN( bool ):
609 AddCustomProperty( uno::makeAny( aChars.toBoolean() ) );
610 break;
611
612 case VT_TOKEN( bstr ):
613 case VT_TOKEN( lpstr ):
614 case VT_TOKEN( lpwstr ):
615 AddCustomProperty( uno::makeAny( AttributeConversion::decodeXString( aChars ) ) ); // the property has string type
616 break;
617
618 case VT_TOKEN( date ):
619 case VT_TOKEN( filetime ):
620 AddCustomProperty( uno::makeAny( GetDateTimeFromW3CDTF( aChars ) ) );
621
622 case VT_TOKEN( i1 ):
623 case VT_TOKEN( i2 ):
624 AddCustomProperty( uno::makeAny( (sal_Int16)aChars.toInt32() ) );
625 break;
626
627 case VT_TOKEN( i4 ):
628 case VT_TOKEN( int ):
629 AddCustomProperty( uno::makeAny( aChars.toInt32() ) );
630 break;
631
632 case VT_TOKEN( i8 ):
633 AddCustomProperty( uno::makeAny( aChars.toInt64() ) );
634 break;
635
636 case VT_TOKEN( r4 ):
637 AddCustomProperty( uno::makeAny( aChars.toFloat() ) );
638 break;
639
640 case VT_TOKEN( r8 ):
641 AddCustomProperty( uno::makeAny( aChars.toDouble() ) );
642 break;
643
644 default:
645 // all the other types are ignored;
646 break;
647 }
648 }
649 else
650 {
651 OSL_ASSERT( "Unexpected tag in custom property!" );
652 }
653 }
654 }
655 }
656 catch( uno::RuntimeException& )
657 {
658 throw;
659 }
660 catch( xml::sax::SAXException& )
661 {
662 throw;
663 }
664 catch( uno::Exception& e )
665 {
666 throw xml::sax::SAXException(
667 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Error while setting document property!" ) ),
668 uno::Reference< uno::XInterface >(),
669 uno::makeAny( e ) );
670 }
671 }
672
673 // ------------------------------------------------
ignorableWhitespace(const::rtl::OUString &)674 void SAL_CALL OOXMLDocPropHandler::ignorableWhitespace( const ::rtl::OUString& )
675 throw (xml::sax::SAXException, uno::RuntimeException)
676 {
677 }
678
679 // ------------------------------------------------
processingInstruction(const::rtl::OUString &,const::rtl::OUString &)680 void SAL_CALL OOXMLDocPropHandler::processingInstruction( const ::rtl::OUString&, const ::rtl::OUString& )
681 throw (xml::sax::SAXException, uno::RuntimeException)
682 {
683 }
684
685 } // namespace docprop
686 } // namespace oox
687
688