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