LibreOffice Module oox (master)  1
docprophandler.cxx
Go to the documentation of this file.
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 #include "docprophandler.hxx"
21 
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <com/sun/star/beans/PropertyExistException.hpp>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <com/sun/star/xml/sax/SAXException.hpp>
26 #include <cppuhelper/exc_hlp.hxx>
27 
28 #include <o3tl/safeint.hxx>
29 #include <osl/time.h>
30 #include <osl/diagnose.h>
31 #include <sal/log.hxx>
33 
34 #include <vector>
35 #include <boost/algorithm/string.hpp>
36 
38 
39 using namespace ::com::sun::star;
40 
41 namespace oox::docprop {
42 
43 OOXMLDocPropHandler::OOXMLDocPropHandler( const uno::Reference< uno::XComponentContext >& xContext,
44  const uno::Reference< document::XDocumentProperties >& rDocProp )
45  : m_xDocProp( rDocProp )
46  , m_nState( 0 )
47  , m_nBlock( 0 )
48  , m_nType( 0 )
49  , m_nInBlock( 0 )
50  , m_CustomStringPropertyState(NONE)
51 {
52  if ( !xContext.is() || !rDocProp.is() )
53  throw uno::RuntimeException();
54 }
55 
57 {
58 }
59 
61 {
62  m_nState = 0;
63  m_nBlock = 0;
64  m_aCustomPropertyName.clear();
65  m_nType = 0;
66  m_nInBlock = 0;
68 }
69 
71 {
72  if ( m_aCustomPropertyName.isEmpty() )
73  return;
74 
75  const uno::Reference< beans::XPropertyContainer > xUserProps =
76  m_xDocProp->getUserDefinedProperties();
77  if ( !xUserProps.is() )
78  throw uno::RuntimeException();
79 
80  try
81  {
82  xUserProps->addProperty( m_aCustomPropertyName,
83  beans::PropertyAttribute::REMOVABLE, aAny );
84  }
85  catch( beans::PropertyExistException& )
86  {
87  // conflicts with core and extended properties are possible
88  }
89  catch( uno::Exception& )
90  {
91  OSL_FAIL( "Can not add custom property!" );
92  }
93 }
94 
95 util::DateTime OOXMLDocPropHandler::GetDateTimeFromW3CDTF( const OUString& aChars )
96 {
97  oslDateTime aOslDTime = { 0, 0, 0, 0, 0, 0, 0, 0 };
98  const sal_Int32 nLen = aChars.getLength();
99  if ( nLen >= 4 )
100  {
101  aOslDTime.Year = static_cast<sal_Int16>(aChars.copy( 0, 4 ).toInt32());
102 
103  if ( nLen >= 7 && aChars[4] == '-' )
104  {
105  aOslDTime.Month = static_cast<sal_uInt16>(aChars.copy( 5, 2 ).toInt32());
106 
107  if ( nLen >= 10 && aChars[7] == '-' )
108  {
109  aOslDTime.Day = static_cast<sal_uInt16>(aChars.copy( 8, 2 ).toInt32());
110 
111  if ( nLen >= 16 && aChars[10] == 'T' && aChars[13] == ':' )
112  {
113  aOslDTime.Hours = static_cast<sal_uInt16>(aChars.copy( 11, 2 ).toInt32());
114  aOslDTime.Minutes = static_cast<sal_uInt16>(aChars.copy( 14, 2 ).toInt32());
115 
116  sal_Int32 nOptTime = 0;
117  if ( nLen >= 19 && aChars[16] == ':' )
118  {
119  aOslDTime.Seconds = static_cast<sal_uInt16>(aChars.copy( 17, 2 ).toInt32());
120  nOptTime += 3;
121  if ( nLen >= 20 && aChars[19] == '.' )
122  {
123  nOptTime += 1;
124  sal_Int32 digitPos = 20;
125  while (nLen > digitPos && digitPos < 29)
126  {
127  sal_Unicode c = aChars[digitPos];
128  if ( c < '0' || c > '9')
129  break;
130  aOslDTime.NanoSeconds *= 10;
131  aOslDTime.NanoSeconds += c - '0';
132  ++digitPos;
133  }
134  if ( digitPos < 29 )
135  {
136  // read less digits than 9
137  // add correct exponent of 10
138  nOptTime += digitPos - 20;
139  for(; digitPos<29; ++digitPos)
140  {
141  aOslDTime.NanoSeconds *= 10;
142  }
143  }
144  else
145  {
146  //skip digits with more precision than we can handle
147  while(nLen > digitPos)
148  {
149  sal_Unicode c = aChars[digitPos];
150  if ( c < '0' || c > '9')
151  break;
152  ++digitPos;
153  }
154  nOptTime += digitPos - 20;
155  }
156  }
157  }
158 
159  sal_Int32 nModif = 0;
160  if ( nLen >= 16 + nOptTime + 6 )
161  {
162  if ( ( aChars[16 + nOptTime] == '+' || aChars[16 + nOptTime] == '-' )
163  && aChars[16 + nOptTime + 3] == ':' )
164  {
165  nModif = aChars.copy( 16 + nOptTime + 1, 2 ).toInt32() * 3600;
166  nModif += aChars.copy( 16 + nOptTime + 4, 2 ).toInt32() * 60;
167  if ( aChars[16 + nOptTime] == '-' )
168  nModif *= -1;
169  }
170  }
171 
172  if ( nModif )
173  {
174  // convert to UTC time
175  TimeValue aTmp;
176  if ( osl_getTimeValueFromDateTime( &aOslDTime, &aTmp ) )
177  {
178  aTmp.Seconds -= nModif;
179  osl_getDateTimeFromTimeValue( &aTmp, &aOslDTime );
180  }
181  }
182  }
183  }
184  }
185  }
186 
187  return util::DateTime( aOslDTime.NanoSeconds, aOslDTime.Seconds,
188  aOslDTime.Minutes, aOslDTime.Hours,
189  aOslDTime.Day, aOslDTime.Month, aOslDTime.Year, false);
190 }
191 
192 uno::Sequence< OUString > OOXMLDocPropHandler::GetKeywordsSet( std::u16string_view aChars )
193 {
194  if ( !aChars.empty() )
195  {
196  std::string aUtf8Chars = OUStringToOString( aChars, RTL_TEXTENCODING_UTF8 ).getStr();
197  std::vector<std::string> aUtf8Result;
198  boost::split( aUtf8Result, aUtf8Chars, boost::is_any_of(" ,;:\t"), boost::token_compress_on );
199 
200  if (!aUtf8Result.empty())
201  {
202  uno::Sequence< OUString > aResult( aUtf8Result.size() );
203  OUString* pResultValues = aResult.getArray();
204  for (auto const& elem : aUtf8Result)
205  {
206  *pResultValues = OUString( elem.c_str(), static_cast< sal_Int32 >( elem.size() ),RTL_TEXTENCODING_UTF8 );
207  ++pResultValues;
208  }
209 
210  return aResult;
211  }
212  }
213  return uno::Sequence< OUString >();
214 }
215 
216 void OOXMLDocPropHandler::UpdateDocStatistic( const OUString& aChars )
217 {
218  uno::Sequence< beans::NamedValue > aSet = m_xDocProp->getDocumentStatistics();
219  OUString aName;
220 
221  switch( m_nBlock )
222  {
223  case EXTPR_TOKEN( Characters ):
224  aName = "NonWhitespaceCharacterCount";
225  break;
226 
227  case EXTPR_TOKEN( CharactersWithSpaces ):
228  aName = "CharacterCount";
229  break;
230 
231  case EXTPR_TOKEN( Pages ):
232  aName = "PageCount";
233  break;
234 
235  case EXTPR_TOKEN( Words ):
236  aName = "WordCount";
237  break;
238 
239  case EXTPR_TOKEN( Paragraphs ):
240  aName = "ParagraphCount";
241  break;
242 
243  default:
244  OSL_FAIL( "Unexpected statistic!" );
245  break;
246  }
247 
248  if ( aName.isEmpty() )
249  return;
250 
251  sal_Int32 nInd = 0;
252  for ( auto pProp = aSet.getConstArray(); nInd < aSet.getLength(); ++nInd )
253  if ( pProp[nInd].Name == aName )
254  break;
255 
256  if (nInd == aSet.getLength())
257  aSet.realloc( nInd + 1 );
258 
259  beans::NamedValue aProp;
260  aProp.Name = aName;
261  aProp.Value <<= aChars.toInt32();
262 
263  aSet[nInd] = aProp;
264 
265  m_xDocProp->setDocumentStatistics( aSet );
266 }
267 
268 // com.sun.star.xml.sax.XFastDocumentHandler
269 
271 {
272 }
273 
275 {
276  InitNew();
277 }
278 
279 void OOXMLDocPropHandler::processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ )
280 {
281 }
282 
283 void SAL_CALL OOXMLDocPropHandler::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& )
284 {
285 }
286 
287 // com.sun.star.xml.sax.XFastContextHandler
288 
289 void SAL_CALL OOXMLDocPropHandler::startFastElement( ::sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs )
290 {
291  if ( !m_nInBlock && !m_nState )
292  {
293  if ( nElement == COREPR_TOKEN( coreProperties )
294  || nElement == EXTPR_TOKEN( Properties )
295  || nElement == CUSTPR_TOKEN( Properties ) )
296  {
297  m_nState = nElement;
298  }
299  else
300  {
301  OSL_FAIL( "Unexpected file format!" );
302  }
303  }
304  else if ( m_nState && m_nInBlock == 1 ) // that tag should contain the property name
305  {
306  // Currently the attributes are ignored for the core properties since the only
307  // known attribute is xsi:type that can only be used with dcterms:created and
308  // dcterms:modified, and this element is allowed currently to have only one value dcterms:W3CDTF
309  m_nBlock = nElement;
310 
311  if ( xAttribs.is() && xAttribs->hasAttribute( XML_name ) )
312  m_aCustomPropertyName = xAttribs->getValue( XML_name );
313  }
314  else if ( m_nState && m_nInBlock == 2 && getNamespace( nElement ) == NMSP_officeDocPropsVT )
315  {
316  m_nType = nElement;
317  }
318  // variant tags in vector
319  else if ( m_nState && m_nInBlock == 3 && getNamespace( nElement ) == NMSP_officeDocPropsVT )
320  {
321  m_nType = nElement;
322  }
323  // lpstr or i4 tags in vector
324  else if ( m_nState && m_nInBlock == 4 && getNamespace( nElement ) == NMSP_officeDocPropsVT )
325  {
326  m_nType = nElement;
327  }
328  else
329  {
330  SAL_WARN("oox", "OOXMLDocPropHandler::startFastElement: unknown element " << getBaseToken(nElement) << " m_nState=" << m_nState << " m_nInBlock=" << m_nInBlock);
331  }
332 
333  if ( m_nInBlock == SAL_MAX_INT32 )
334  throw uno::RuntimeException();
335 
336  m_nInBlock++;
337 }
338 
339 void SAL_CALL OOXMLDocPropHandler::startUnknownElement( const OUString& aNamespace, const OUString& aName, const uno::Reference< xml::sax::XFastAttributeList >& )
340 {
341  SAL_WARN("oox", "Unknown element " << aNamespace << ":" << aName);
342 
343  if ( m_nInBlock == SAL_MAX_INT32 )
344  throw uno::RuntimeException();
345 
346  m_nInBlock++;
347 }
348 
349 void SAL_CALL OOXMLDocPropHandler::endFastElement( ::sal_Int32 )
350 {
351  if ( !m_nInBlock )
352  return;
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.clear();
362  }
363  else if ( m_nInBlock == 2 )
364  {
367  {
368  switch (m_nType)
369  {
370  case VT_TOKEN(bstr):
371  case VT_TOKEN(lpstr):
372  case VT_TOKEN(lpwstr):
373  if (!m_aCustomPropertyName.isEmpty() &&
375  {
376  // the property has string type, so it is valid
377  // even with an empty value - characters() has
378  // not been called in that case
379  AddCustomProperty(uno::makeAny(OUString()));
380  }
381  break;
382  }
383  }
385  m_nType = 0;
386  }
387 }
388 
389 void SAL_CALL OOXMLDocPropHandler::endUnknownElement( const OUString&, const OUString& )
390 {
391  if ( m_nInBlock )
392  m_nInBlock--;
393 }
394 
395 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createFastChildContext( ::sal_Int32, const uno::Reference< xml::sax::XFastAttributeList >& )
396 {
397  // Should the arguments be parsed?
398  return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) );
399 }
400 
401 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createUnknownChildContext( const OUString&, const OUString&, const uno::Reference< xml::sax::XFastAttributeList >& )
402 {
403  return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) );
404 }
405 
406 void SAL_CALL OOXMLDocPropHandler::characters( const OUString& aChars )
407 {
408  try
409  {
410  if ( (m_nInBlock == 2) || ((m_nInBlock == 3) && m_nType) )
411  {
412  if ( m_nState == COREPR_TOKEN( coreProperties ) )
413  {
414  switch( m_nBlock )
415  {
416  case COREPR_TOKEN( category ):
417  m_aCustomPropertyName = "OOXMLCorePropertyCategory";
418  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
419  break;
420 
421  case COREPR_TOKEN( contentStatus ):
422  m_aCustomPropertyName = "OOXMLCorePropertyContentStatus";
423  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
424  break;
425 
426  case COREPR_TOKEN( contentType ):
427  m_aCustomPropertyName = "OOXMLCorePropertyContentType";
428  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
429  break;
430 
431  case DC_TOKEN( identifier ):
432  m_aCustomPropertyName = "OOXMLCorePropertyIdentifier";
433  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
434  break;
435 
436  case COREPR_TOKEN( version ):
437  m_aCustomPropertyName = "OOXMLCorePropertyVersion";
438  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
439  break;
440 
441  case DCT_TOKEN( created ):
442  if ( aChars.getLength() >= 4 )
443  m_xDocProp->setCreationDate( GetDateTimeFromW3CDTF( aChars ) );
444  break;
445 
446  case DC_TOKEN( creator ):
447  m_xDocProp->setAuthor( aChars );
448  break;
449 
450  case DC_TOKEN( description ):
451  m_xDocProp->setDescription( aChars );
452  break;
453 
454  case COREPR_TOKEN( keywords ):
455  m_xDocProp->setKeywords( GetKeywordsSet( aChars ) );
456  break;
457 
458  case DC_TOKEN( language ):
459  if ( aChars.getLength() >= 2 )
460  m_xDocProp->setLanguage( LanguageTag::convertToLocale( aChars) );
461  break;
462 
463  case COREPR_TOKEN( lastModifiedBy ):
464  m_xDocProp->setModifiedBy( aChars );
465  break;
466 
467  case COREPR_TOKEN( lastPrinted ):
468  if ( aChars.getLength() >= 4 )
469  m_xDocProp->setPrintDate( GetDateTimeFromW3CDTF( aChars ) );
470  break;
471 
472  case DCT_TOKEN( modified ):
473  if ( aChars.getLength() >= 4 )
474  m_xDocProp->setModificationDate( GetDateTimeFromW3CDTF( aChars ) );
475  break;
476 
477  case COREPR_TOKEN( revision ):
478  try
479  {
480  m_xDocProp->setEditingCycles(
481  static_cast<sal_Int16>(aChars.toInt32()) );
482  }
483  catch (lang::IllegalArgumentException &)
484  {
485  // ignore
486  }
487  break;
488 
489  case DC_TOKEN( subject ):
490  m_xDocProp->setSubject( m_xDocProp->getSubject() + aChars );
491  break;
492 
493  case DC_TOKEN( title ):
494  m_xDocProp->setTitle( m_xDocProp->getTitle() + aChars );
495  break;
496 
497  default:
498  OSL_FAIL( "Unexpected core property!" );
499  }
500  }
501  else if ( m_nState == EXTPR_TOKEN( Properties ) )
502  {
503  switch( m_nBlock )
504  {
505  case EXTPR_TOKEN( Application ):
506  m_xDocProp->setGenerator( aChars );
507  break;
508 
509  case EXTPR_TOKEN( Template ):
510  m_xDocProp->setTemplateName( aChars );
511  break;
512 
513  case EXTPR_TOKEN( TotalTime ):
514  {
515  sal_Int32 nDuration;
516  if (!o3tl::checked_multiply<sal_Int32>(aChars.toInt32(), 60, nDuration))
517  {
518  try
519  {
520  // The TotalTime is in mins as per ECMA specification.
521  m_xDocProp->setEditingDuration(nDuration);
522  }
523  catch (const lang::IllegalArgumentException&)
524  {
525  // ignore
526  }
527  }
528  break;
529  }
530  case EXTPR_TOKEN( Characters ):
531  case EXTPR_TOKEN( CharactersWithSpaces ):
532  case EXTPR_TOKEN( Pages ):
533  case EXTPR_TOKEN( Words ):
534  case EXTPR_TOKEN( Paragraphs ):
535  UpdateDocStatistic( aChars );
536  break;
537 
538  case EXTPR_TOKEN( HyperlinksChanged ):
539  m_aCustomPropertyName = "HyperlinksChanged";
540  // tdf#103987 Don't create custom property if the value is default
541  if ( aChars.toBoolean() )
542  AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
543  break;
544 
545  case EXTPR_TOKEN( LinksUpToDate ):
546  m_aCustomPropertyName = "LinksUpToDate";
547  // tdf#103987 Don't create custom property if the value is default
548  if ( aChars.toBoolean() )
549  AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
550  break;
551 
552  case EXTPR_TOKEN( ScaleCrop ):
553  m_aCustomPropertyName = "ScaleCrop";
554  // tdf#103987 Don't create custom property if the value is default
555  if ( aChars.toBoolean() )
556  AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
557  break;
558 
559  case EXTPR_TOKEN( SharedDoc ):
560  m_aCustomPropertyName = "ShareDoc";
561  // tdf#103987 Don't create custom property if the value is default
562  if ( aChars.toBoolean() )
563  AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
564  break;
565 
566  case EXTPR_TOKEN( DocSecurity ):
567  m_aCustomPropertyName = "DocSecurity";
568  // tdf#103987 Don't create custom property if the value is default
569  // OOXTODO Instead of storing value, enable security
570  // 1 - password protected, 2 - recommended read-only
571  // 4 - enforced read-only, 8 - locked for annotation
572  if ( aChars.toInt32() != 0 )
573  AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
574  break;
575 
576  case EXTPR_TOKEN( HiddenSlides ):
577  m_aCustomPropertyName = "HiddenSlides";
578  // tdf#103987 Don't create custom property if the value is default
579  if ( aChars.toInt32() != 0 )
580  AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
581  break;
582 
583  case EXTPR_TOKEN( MMClips ):
584  m_aCustomPropertyName = "MMClips";
585  // tdf#103987 Don't create custom property if the value is default
586  if ( aChars.toInt32() != 0 )
587  AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
588  break;
589 
590  case EXTPR_TOKEN( Notes ):
591  m_aCustomPropertyName = "Notes";
592  // tdf#103987 Don't create custom property if the value is default
593  if ( aChars.toInt32() != 0 )
594  AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
595  break;
596 
597  case EXTPR_TOKEN( Slides ):
598  m_aCustomPropertyName = "Slides";
599  // tdf#103987 Don't create custom property if the value is default
600  if ( aChars.toInt32() != 0 )
601  AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
602  break;
603 
604  case EXTPR_TOKEN( AppVersion ):
605  m_aCustomPropertyName = "AppVersion";
606  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
607  break;
608 
609  case EXTPR_TOKEN( Company ):
610  m_aCustomPropertyName = "Company";
611  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
612  break;
613 
614  case EXTPR_TOKEN( HyperlinkBase ):
615  m_aCustomPropertyName = "HyperlinkBase";
616  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
617  break;
618 
619  case EXTPR_TOKEN( Manager ):
620  m_aCustomPropertyName = "Manager";
621  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
622  break;
623 
624  case EXTPR_TOKEN( PresentationFormat ):
625  m_aCustomPropertyName = "PresentationFormat";
626  AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
627  break;
628 
629  case EXTPR_TOKEN( Lines ):
630  case EXTPR_TOKEN( DigSig ):
631  case EXTPR_TOKEN( HeadingPairs ):
632  case EXTPR_TOKEN( HLinks ):
633  case EXTPR_TOKEN( TitlesOfParts ):
634  // ignored during the import currently
635  break;
636 
637  default:
638  OSL_FAIL( "Unexpected extended property!" );
639  }
640  }
641  else if ( m_nState == CUSTPR_TOKEN( Properties ) )
642  {
643  if ( m_nBlock == CUSTPR_TOKEN( property ) )
644  {
645  // this is a custom property
646  switch( m_nType )
647  {
648  case VT_TOKEN( bool ):
649  AddCustomProperty( uno::makeAny( aChars.toBoolean() ) );
650  break;
651 
652  case VT_TOKEN( bstr ):
653  case VT_TOKEN( lpstr ):
654  case VT_TOKEN( lpwstr ):
655  // the property has string type
656  AddCustomProperty( uno::makeAny( AttributeConversion::decodeXString( aChars ) ) );
658  break;
659 
660  case VT_TOKEN( date ):
661  case VT_TOKEN( filetime ):
662  AddCustomProperty( uno::makeAny( GetDateTimeFromW3CDTF( aChars ) ) );
663  break;
664 
665  case VT_TOKEN( i1 ):
666  case VT_TOKEN( i2 ):
667  AddCustomProperty( uno::makeAny( static_cast<sal_Int16>(aChars.toInt32()) ) );
668  break;
669 
670  case VT_TOKEN( i4 ):
671  case VT_TOKEN( int ):
672  AddCustomProperty( uno::makeAny( aChars.toInt32() ) );
673  break;
674 
675  case VT_TOKEN( i8 ):
676  AddCustomProperty( uno::makeAny( aChars.toInt64() ) );
677  break;
678 
679  case VT_TOKEN( r4 ):
680  AddCustomProperty( uno::makeAny( aChars.toFloat() ) );
681  break;
682 
683  case VT_TOKEN( r8 ):
684  AddCustomProperty( uno::makeAny( aChars.toDouble() ) );
685  break;
686 
687  default:
688  // all the other types are ignored;
689  break;
690  }
691  }
692  else
693  {
694  OSL_FAIL( "Unexpected tag in custom property!" );
695  }
696  }
697  }
698  }
699  catch( uno::RuntimeException& )
700  {
701  throw;
702  }
703  catch( xml::sax::SAXException& )
704  {
705  throw;
706  }
707  catch( uno::Exception& )
708  {
709  css::uno::Any anyEx = cppu::getCaughtException();
710  throw xml::sax::SAXException(
711  "Error while setting document property!",
712  uno::Reference< uno::XInterface >(),
713  anyEx );
714  }
715 }
716 
717 } // namespace oox::docprop
718 
719 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< ParagraphInfo > Paragraphs
virtual void SAL_CALL startFastElement(::sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(::sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
void UpdateDocStatistic(const OUString &aChars)
static OUString decodeXString(const OUString &rValue)
Returns the decoded string value.
virtual void SAL_CALL endUnknownElement(const OUString &Namespace, const OUString &Name) override
static css::uno::Sequence< OUString > GetKeywordsSet(std::u16string_view aChars)
#define DC_TOKEN(token)
virtual void SAL_CALL endDocument() override
OUString Name
#define EXTPR_TOKEN(token)
enum oox::docprop::OOXMLDocPropHandler::@0 m_CustomStringPropertyState
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
NONE
sal_uInt16 sal_Unicode
Any SAL_CALL getCaughtException()
virtual void SAL_CALL startDocument() override
Notes
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
virtual void SAL_CALL startUnknownElement(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
#define SAL_MAX_INT32
#define COREPR_TOKEN(token)
static css::util::DateTime GetDateTimeFromW3CDTF(const OUString &aChars)
css::uno::Reference< css::document::XDocumentProperties > m_xDocProp
#define DCT_TOKEN(token)
OOXMLDocPropHandler(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::document::XDocumentProperties > &rDocProp)
::boost::spirit::classic::rule< ScannerT > identifier
#define VT_TOKEN(token)
OUString aName
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &rxLocator) override
virtual void SAL_CALL characters(const OUString &aChars) override
virtual void SAL_CALL endFastElement(::sal_Int32 Element) override
virtual ~OOXMLDocPropHandler() override
#define SAL_WARN(area, stream)
void AddCustomProperty(const css::uno::Any &aAny)
virtual void SAL_CALL processingInstruction(const OUString &rTarget, const OUString &rData) override
#define CUSTPR_TOKEN(token)
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)