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