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