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
21 /** @#file
22 *
23 * Import of all text fields except those from txtvfldi.cxx
24 * (variable related text fields and database display fields)
25 */
26 #include <txtfldi.hxx>
27 #include <txtvfldi.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/txtimp.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/xmluconv.hxx>
34 #include <xmloff/xmlement.hxx>
35 #include <XMLStringBufferImportContext.hxx>
36 #include <xmloff/XMLEventsImportContext.hxx>
37 #include <com/sun/star/xml/sax/XAttributeList.hpp>
38 #include <com/sun/star/text/UserDataPart.hpp>
39 #include <com/sun/star/style/NumberingType.hpp>
40 #include <com/sun/star/text/PlaceholderType.hpp>
41 #include <com/sun/star/text/ReferenceFieldPart.hpp>
42 #include <com/sun/star/text/ReferenceFieldSource.hpp>
43 #include <com/sun/star/text/XTextContent.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/beans/XPropertySetInfo.hpp>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
48 #include <com/sun/star/text/XDependentTextField.hpp>
49 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
50 #include <com/sun/star/text/ChapterFormat.hpp>
51 #include <com/sun/star/text/TemplateDisplayFormat.hpp>
52 #include <com/sun/star/beans/PropertyValue.hpp>
53 #include <com/sun/star/text/BibliographyDataType.hpp>
54 #include <com/sun/star/util/XUpdatable.hpp>
55 #include <com/sun/star/sdb/CommandType.hpp>
56 #include <com/sun/star/container/XIndexReplace.hpp>
57
58 #include <sax/tools/converter.hxx>
59
60 #include <rtl/ustring.hxx>
61 #include <rtl/ustrbuf.hxx>
62 #include <sal/log.hxx>
63 #include <rtl/math.hxx>
64 #include <tools/debug.hxx>
65 #include <osl/diagnose.h>
66
67
68 using namespace ::com::sun::star;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::text;
71 using namespace ::com::sun::star::lang;
72 using namespace ::com::sun::star::beans;
73 using namespace ::com::sun::star::document;
74 using namespace ::com::sun::star::util;
75 using namespace ::com::sun::star::xml::sax;
76 using namespace ::xmloff::token;
77
78
79 // SO API string constants
80
81
82 // service prefix and service names
83 const sal_Char sAPI_textfield_prefix[] = "com.sun.star.text.TextField.";
84 const sal_Char sAPI_fieldmaster_prefix[] = "com.sun.star.text.FieldMaster.";
85 const sal_Char sAPI_presentation_prefix[] = "com.sun.star.presentation.TextField.";
86
87 const sal_Char sAPI_date_time[] = "DateTime";
88 const sal_Char sAPI_page_number[] = "PageNumber";
89 const sal_Char sAPI_docinfo_change_date_time[] = "DocInfo.ChangeDateTime";
90 const sal_Char sAPI_docinfo_create_date_time[] = "DocInfo.CreateDateTime";
91 const sal_Char sAPI_docinfo_custom[] = "DocInfo.Custom";
92 const sal_Char sAPI_docinfo_print_date_time[] = "DocInfo.PrintDateTime";
93 const sal_Char sAPI_dde[] = "DDE";
94 const sal_Char sAPI_url[] = "URL";
95
96 // property names
97 const sal_Char sAPI_is_fixed[] = "IsFixed";
98 const sal_Char sAPI_content[] = "Content";
99 const sal_Char sAPI_author[] = "Author";
100 const sal_Char sAPI_hint[] = "Hint";
101 const sal_Char sAPI_name[] = "Name";
102 const sal_Char sAPI_sub_type[] = "SubType";
103 const sal_Char sAPI_date_time_value[] = "DateTimeValue";
104 const sal_Char sAPI_number_format[] = "NumberFormat";
105 const sal_Char sAPI_numbering_type[] = "NumberingType";
106 const sal_Char sAPI_offset[] = "Offset";
107 const sal_Char sAPI_condition[] = "Condition";
108 const sal_Char sAPI_set_number[] = "SetNumber";
109 const sal_Char sAPI_file_format[] = "FileFormat";
110 const sal_Char sAPI_is_date[] = "IsDate";
111 const sal_Char sAPI_current_presentation[] = "CurrentPresentation";
112 const sal_Char sAPI_is_hidden[] = "IsHidden";
113 const sal_Char sAPI_is_fixed_language[] = "IsFixedLanguage";
114
115 const sal_Char sAPI_true[] = "TRUE";
116
117
XMLTextFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,const sal_Char * pService,sal_uInt16 nPrefix,const OUString & rElementName)118 XMLTextFieldImportContext::XMLTextFieldImportContext(
119 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
120 const sal_Char* pService,
121 sal_uInt16 nPrefix, const OUString& rElementName)
122 : SvXMLImportContext( rImport, nPrefix, rElementName )
123 , rTextImportHelper(rHlp)
124 , sServicePrefix(sAPI_textfield_prefix)
125 , bValid(false)
126 {
127 DBG_ASSERT(nullptr != pService, "Need service name!");
128 sServiceName = OUString::createFromAscii(pService);
129 }
130
StartElement(const Reference<XAttributeList> & xAttrList)131 void XMLTextFieldImportContext::StartElement(
132 const Reference<XAttributeList> & xAttrList)
133 {
134 // process attributes
135 sal_Int16 nLength = xAttrList->getLength();
136 for(sal_Int16 i=0; i<nLength; i++) {
137
138 OUString sLocalName;
139 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
140 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
141
142 ProcessAttribute(rTextImportHelper.GetTextFieldAttrTokenMap().
143 Get(nPrefix, sLocalName),
144 xAttrList->getValueByIndex(i) );
145 }
146 }
147
GetContent()148 OUString const & XMLTextFieldImportContext::GetContent()
149 {
150 if (sContent.isEmpty())
151 {
152 sContent = sContentBuffer.makeStringAndClear();
153 }
154
155 return sContent;
156 }
157
EndElement()158 void XMLTextFieldImportContext::EndElement()
159 {
160 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
161 if (bValid)
162 {
163
164 // create field/Service
165 Reference<XPropertySet> xPropSet;
166 if (CreateField(xPropSet, sServicePrefix + GetServiceName()))
167 {
168 // set field properties
169 PrepareField(xPropSet);
170
171 // attach field to document
172 Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
173
174 // workaround for #80606#
175 try
176 {
177 rTextImportHelper.InsertTextContent(xTextContent);
178 }
179 catch (const lang::IllegalArgumentException&)
180 {
181 // ignore
182 }
183 return;
184 }
185 }
186
187 // in case of error: write element content
188 rTextImportHelper.InsertString(GetContent());
189 }
190
Characters(const OUString & rContent)191 void XMLTextFieldImportContext::Characters(const OUString& rContent)
192 {
193 sContentBuffer.append(rContent);
194 }
195
CreateField(Reference<XPropertySet> & xField,const OUString & rServiceName)196 bool XMLTextFieldImportContext::CreateField(
197 Reference<XPropertySet> & xField,
198 const OUString& rServiceName)
199 {
200 // instantiate new XTextField:
201 // ask import for model, model is factory, ask factory to create service
202
203 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
204 if( xFactory.is() )
205 {
206 Reference<XInterface> xIfc = xFactory->createInstance(rServiceName);
207 if( xIfc.is() )
208 {
209 Reference<XPropertySet> xTmp( xIfc, UNO_QUERY );
210
211 xField = xTmp;
212 } else {
213 return false; // can't create instance
214 }
215 } else {
216 return false; // can't get MultiServiceFactory
217 }
218
219 return true;
220 }
221
222 /// create the appropriate field context from
223 XMLTextFieldImportContext*
CreateTextFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrefix,const OUString & rName,sal_uInt16 nToken)224 XMLTextFieldImportContext::CreateTextFieldImportContext(
225 SvXMLImport& rImport,
226 XMLTextImportHelper& rHlp,
227 sal_uInt16 nPrefix,
228 const OUString& rName,
229 sal_uInt16 nToken)
230 {
231 XMLTextFieldImportContext* pContext = nullptr;
232
233 switch (nToken)
234 {
235 case XML_TOK_TEXT_SENDER_FIRSTNAME:
236 case XML_TOK_TEXT_SENDER_LASTNAME:
237 case XML_TOK_TEXT_SENDER_INITIALS:
238 case XML_TOK_TEXT_SENDER_TITLE:
239 case XML_TOK_TEXT_SENDER_POSITION:
240 case XML_TOK_TEXT_SENDER_EMAIL:
241 case XML_TOK_TEXT_SENDER_PHONE_PRIVATE:
242 case XML_TOK_TEXT_SENDER_FAX:
243 case XML_TOK_TEXT_SENDER_COMPANY:
244 case XML_TOK_TEXT_SENDER_PHONE_WORK:
245 case XML_TOK_TEXT_SENDER_STREET:
246 case XML_TOK_TEXT_SENDER_CITY:
247 case XML_TOK_TEXT_SENDER_POSTAL_CODE:
248 case XML_TOK_TEXT_SENDER_COUNTRY:
249 case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE:
250 pContext =
251 new XMLSenderFieldImportContext( rImport, rHlp,
252 nPrefix, rName, nToken );
253 break;
254
255 case XML_TOK_TEXT_AUTHOR_NAME:
256 case XML_TOK_TEXT_AUTHOR_INITIALS:
257 pContext =
258 new XMLAuthorFieldImportContext( rImport, rHlp,
259 nPrefix, rName, nToken );
260 break;
261
262 case XML_TOK_TEXT_PLACEHOLDER:
263 pContext =
264 new XMLPlaceholderFieldImportContext( rImport, rHlp,
265 nPrefix, rName);
266 break;
267 case XML_TOK_TEXT_SEQUENCE:
268 pContext =
269 new XMLSequenceFieldImportContext( rImport, rHlp,
270 nPrefix, rName );
271 break;
272 case XML_TOK_TEXT_TEXT_INPUT:
273 pContext =
274 new XMLTextInputFieldImportContext( rImport, rHlp,
275 nPrefix, rName );
276 break;
277 case XML_TOK_TEXT_EXPRESSION:
278 pContext =
279 new XMLExpressionFieldImportContext( rImport, rHlp,
280 nPrefix, rName );
281 break;
282 case XML_TOK_TEXT_VARIABLE_SET:
283 pContext =
284 new XMLVariableSetFieldImportContext( rImport, rHlp,
285 nPrefix, rName );
286 break;
287 case XML_TOK_TEXT_VARIABLE_INPUT:
288 pContext =
289 new XMLVariableInputFieldImportContext( rImport, rHlp,
290 nPrefix, rName );
291 break;
292 case XML_TOK_TEXT_VARIABLE_GET:
293 pContext =
294 new XMLVariableGetFieldImportContext( rImport, rHlp,
295 nPrefix, rName );
296 break;
297 case XML_TOK_TEXT_USER_FIELD_GET:
298 pContext = new XMLUserFieldImportContext( rImport, rHlp,
299 nPrefix, rName );
300 break;
301 case XML_TOK_TEXT_USER_FIELD_INPUT:
302 pContext = new XMLUserFieldInputImportContext( rImport, rHlp,
303 nPrefix, rName );
304 break;
305 case XML_TOK_TEXT_TIME:
306 pContext = new XMLTimeFieldImportContext( rImport, rHlp,
307 nPrefix, rName );
308 break;
309 case XML_TOK_TEXT_PAGE_CONTINUATION_STRING:
310 case XML_TOK_TEXT_PAGE_CONTINUATION:
311 pContext = new XMLPageContinuationImportContext( rImport, rHlp,
312 nPrefix, rName );
313 break;
314
315 case XML_TOK_TEXT_PAGE_NUMBER:
316 pContext = new XMLPageNumberImportContext( rImport, rHlp,
317 nPrefix, rName );
318 break;
319
320 case XML_TOK_TEXT_DATE:
321 pContext = new XMLDateFieldImportContext( rImport, rHlp,
322 nPrefix, rName );
323 break;
324
325 case XML_TOK_TEXT_DATABASE_NAME:
326 pContext = new XMLDatabaseNameImportContext( rImport, rHlp,
327 nPrefix, rName );
328 break;
329 case XML_TOK_TEXT_DATABASE_NEXT:
330 pContext = new XMLDatabaseNextImportContext( rImport, rHlp,
331 nPrefix, rName );
332 break;
333 case XML_TOK_TEXT_DATABASE_SELECT:
334 pContext = new XMLDatabaseSelectImportContext( rImport, rHlp,
335 nPrefix, rName );
336 break;
337 case XML_TOK_TEXT_DATABASE_ROW_NUMBER:
338 pContext = new XMLDatabaseNumberImportContext( rImport, rHlp,
339 nPrefix, rName );
340 break;
341 case XML_TOK_TEXT_DATABASE_DISPLAY:
342 pContext = new XMLDatabaseDisplayImportContext( rImport, rHlp,
343 nPrefix, rName );
344 break;
345 case XML_TOK_TEXT_CONDITIONAL_TEXT:
346 pContext = new XMLConditionalTextImportContext( rImport, rHlp,
347 nPrefix, rName );
348 break;
349 case XML_TOK_TEXT_HIDDEN_TEXT:
350 pContext = new XMLHiddenTextImportContext( rImport, rHlp,
351 nPrefix, rName );
352 break;
353 case XML_TOK_TEXT_HIDDEN_PARAGRAPH:
354 pContext = new XMLHiddenParagraphImportContext( rImport, rHlp,
355 nPrefix, rName );
356 break;
357 case XML_TOK_TEXT_DOCUMENT_DESCRIPTION:
358 case XML_TOK_TEXT_DOCUMENT_TITLE:
359 case XML_TOK_TEXT_DOCUMENT_SUBJECT:
360 case XML_TOK_TEXT_DOCUMENT_KEYWORDS:
361 pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
362 nPrefix, rName,
363 nToken, true,
364 false );
365 break;
366 case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR:
367 case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR:
368 case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR:
369 pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
370 nPrefix, rName,
371 nToken, false,
372 true );
373 break;
374
375 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE:
376 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME:
377 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE:
378 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME:
379 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE:
380 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME:
381 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION:
382 pContext = new XMLDateTimeDocInfoImportContext( rImport, rHlp,
383 nPrefix, rName,
384 nToken );
385 break;
386
387 case XML_TOK_TEXT_DOCUMENT_REVISION:
388 pContext = new XMLRevisionDocInfoImportContext( rImport, rHlp,
389 nPrefix, rName,
390 nToken );
391 break;
392
393 case XML_TOK_TEXT_DOCUMENT_USER_DEFINED:
394 pContext = new XMLUserDocInfoImportContext( rImport, rHlp,
395 nPrefix, rName,
396 nToken );
397 break;
398
399 case XML_TOK_TEXT_FILENAME:
400 pContext = new XMLFileNameImportContext( rImport, rHlp,
401 nPrefix, rName );
402 break;
403
404 case XML_TOK_TEXT_CHAPTER:
405 pContext = new XMLChapterImportContext( rImport, rHlp,
406 nPrefix, rName );
407 break;
408
409 case XML_TOK_TEXT_TEMPLATENAME:
410 pContext = new XMLTemplateNameImportContext( rImport, rHlp,
411 nPrefix, rName );
412 break;
413
414 case XML_TOK_TEXT_WORD_COUNT:
415 case XML_TOK_TEXT_PARAGRAPH_COUNT:
416 case XML_TOK_TEXT_TABLE_COUNT:
417 case XML_TOK_TEXT_CHARACTER_COUNT:
418 case XML_TOK_TEXT_IMAGE_COUNT:
419 case XML_TOK_TEXT_OBJECT_COUNT:
420 case XML_TOK_TEXT_PAGE_COUNT:
421 pContext = new XMLCountFieldImportContext( rImport, rHlp,
422 nPrefix, rName, nToken);
423 break;
424
425 case XML_TOK_TEXT_GET_PAGE_VAR:
426 pContext = new XMLPageVarGetFieldImportContext( rImport, rHlp,
427 nPrefix, rName );
428 break;
429
430 case XML_TOK_TEXT_SET_PAGE_VAR:
431 pContext = new XMLPageVarSetFieldImportContext( rImport, rHlp,
432 nPrefix, rName );
433 break;
434
435 case XML_TOK_TEXT_MACRO:
436 pContext = new XMLMacroFieldImportContext( rImport, rHlp,
437 nPrefix, rName );
438 break;
439
440 case XML_TOK_TEXT_DDE:
441 pContext = new XMLDdeFieldImportContext( rImport, rHlp,
442 nPrefix, rName );
443 break;
444
445 case XML_TOK_TEXT_REFERENCE_REF:
446 case XML_TOK_TEXT_BOOKMARK_REF:
447 case XML_TOK_TEXT_NOTE_REF:
448 case XML_TOK_TEXT_SEQUENCE_REF:
449 pContext = new XMLReferenceFieldImportContext( rImport, rHlp,
450 nToken,
451 nPrefix, rName );
452 break;
453
454 case XML_TOK_TEXT_SHEET_NAME:
455 pContext = new XMLSheetNameImportContext( rImport, rHlp,
456 nPrefix, rName );
457 break;
458
459 case XML_TOK_TEXT_PAGE_NAME:
460 pContext = new XMLPageNameFieldImportContext( rImport, rHlp,
461 nPrefix, rName );
462 break;
463
464 case XML_TOK_TEXT_BIBLIOGRAPHY_MARK:
465 pContext = new XMLBibliographyFieldImportContext( rImport, rHlp,
466 nPrefix, rName );
467 break;
468
469 case XML_TOK_TEXT_ANNOTATION:
470 case XML_TOK_TEXT_ANNOTATION_END:
471 pContext = new XMLAnnotationImportContext( rImport, rHlp,
472 nToken,
473 nPrefix, rName);
474 break;
475
476 case XML_TOK_TEXT_SCRIPT:
477 pContext = new XMLScriptImportContext( rImport, rHlp,
478 nPrefix, rName);
479 break;
480
481 case XML_TOK_TEXT_MEASURE:
482 pContext = new XMLMeasureFieldImportContext( rImport, rHlp,
483 nPrefix, rName );
484 break;
485
486 case XML_TOK_TEXT_TABLE_FORMULA:
487 pContext = new XMLTableFormulaImportContext( rImport, rHlp,
488 nPrefix, rName );
489 break;
490 case XML_TOK_TEXT_DROP_DOWN:
491 pContext = new XMLDropDownFieldImportContext( rImport, rHlp,
492 nPrefix, rName );
493 break;
494 case XML_TOK_DRAW_HEADER:
495 pContext = new XMLHeaderFieldImportContext( rImport, rHlp,
496 nPrefix, rName );
497 break;
498 case XML_TOK_DRAW_FOOTER:
499 pContext = new XMLFooterFieldImportContext( rImport, rHlp,
500 nPrefix, rName );
501 break;
502 case XML_TOK_DRAW_DATE_TIME:
503 pContext = new XMLDateTimeFieldImportContext( rImport, rHlp,
504 nPrefix, rName );
505 break;
506
507 default:
508 // ignore! May not even be a textfield.
509 // (Reminder: This method is called inside default:-branch)
510 pContext = nullptr;
511 break;
512 }
513
514 return pContext;
515 }
516
517
ForceUpdate(const Reference<XPropertySet> & rPropertySet)518 void XMLTextFieldImportContext::ForceUpdate(
519 const Reference<XPropertySet> & rPropertySet)
520 {
521 // force update
522 Reference<XUpdatable> xUpdate(rPropertySet, UNO_QUERY);
523 if (xUpdate.is())
524 {
525 xUpdate->update();
526 }
527 else
528 {
529 OSL_FAIL("Expected XUpdatable support!");
530 }
531 }
532
533
534 // XMLSenderFieldImportContext
535
536
537 static const OUStringLiteral gsPropertyFieldSubType("UserDataType");
538
XMLSenderFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName,sal_uInt16 nToken)539 XMLSenderFieldImportContext::XMLSenderFieldImportContext(
540 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
541 sal_uInt16 nPrfx, const OUString& sLocalName,
542 sal_uInt16 nToken)
543 : XMLTextFieldImportContext(rImport, rHlp, "ExtendedUser", nPrfx, sLocalName)
544 , nSubType(0)
545 , sPropertyFixed(sAPI_is_fixed)
546 , sPropertyContent(sAPI_content)
547 , bFixed(true)
548 , nElementToken(nToken)
549 {
550 }
551
StartElement(const Reference<XAttributeList> & xAttrList)552 void XMLSenderFieldImportContext::StartElement(
553 const Reference<XAttributeList> & xAttrList)
554 {
555 bValid = true;
556 switch (nElementToken) {
557 case XML_TOK_TEXT_SENDER_FIRSTNAME:
558 nSubType = UserDataPart::FIRSTNAME;
559 break;
560 case XML_TOK_TEXT_SENDER_LASTNAME:
561 nSubType = UserDataPart::NAME;
562 break;
563 case XML_TOK_TEXT_SENDER_INITIALS:
564 nSubType = UserDataPart::SHORTCUT;
565 break;
566 case XML_TOK_TEXT_SENDER_TITLE:
567 nSubType = UserDataPart::TITLE;
568 break;
569 case XML_TOK_TEXT_SENDER_POSITION:
570 nSubType = UserDataPart::POSITION;
571 break;
572 case XML_TOK_TEXT_SENDER_EMAIL:
573 nSubType = UserDataPart::EMAIL;
574 break;
575 case XML_TOK_TEXT_SENDER_PHONE_PRIVATE:
576 nSubType = UserDataPart::PHONE_PRIVATE;
577 break;
578 case XML_TOK_TEXT_SENDER_FAX:
579 nSubType = UserDataPart::FAX;
580 break;
581 case XML_TOK_TEXT_SENDER_COMPANY:
582 nSubType = UserDataPart::COMPANY;
583 break;
584 case XML_TOK_TEXT_SENDER_PHONE_WORK:
585 nSubType = UserDataPart::PHONE_COMPANY;
586 break;
587 case XML_TOK_TEXT_SENDER_STREET:
588 nSubType = UserDataPart::STREET;
589 break;
590 case XML_TOK_TEXT_SENDER_CITY:
591 nSubType = UserDataPart::CITY;
592 break;
593 case XML_TOK_TEXT_SENDER_POSTAL_CODE:
594 nSubType = UserDataPart::ZIP;
595 break;
596 case XML_TOK_TEXT_SENDER_COUNTRY:
597 nSubType = UserDataPart::COUNTRY;
598 break;
599 case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE:
600 nSubType = UserDataPart::STATE;
601 break;
602 default:
603 bValid = false;
604 break;
605 }
606
607 // process Attributes
608 XMLTextFieldImportContext::StartElement(xAttrList);
609 }
610
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)611 void XMLSenderFieldImportContext::ProcessAttribute(
612 sal_uInt16 nAttrToken,
613 const OUString& sAttrValue)
614 {
615 if (XML_TOK_TEXTFIELD_FIXED == nAttrToken) {
616
617 // set bVal
618 bool bVal(false);
619 bool const bRet = ::sax::Converter::convertBool(bVal, sAttrValue);
620
621 // set bFixed if successful
622 if (bRet) {
623 bFixed = bVal;
624 }
625 }
626 }
627
PrepareField(const Reference<XPropertySet> & rPropSet)628 void XMLSenderFieldImportContext::PrepareField(
629 const Reference<XPropertySet> & rPropSet)
630 {
631 // set members
632 rPropSet->setPropertyValue(gsPropertyFieldSubType, Any(nSubType));
633
634 // set fixed
635 rPropSet->setPropertyValue(sPropertyFixed, Any(bFixed));
636
637 // set content if fixed
638 if (bFixed)
639 {
640 // in organizer or styles-only mode: force update
641 if (GetImport().GetTextImport()->IsOrganizerMode() ||
642 GetImport().GetTextImport()->IsStylesOnlyMode() )
643 {
644 ForceUpdate(rPropSet);
645 }
646 else
647 {
648 rPropSet->setPropertyValue(sPropertyContent, Any(GetContent()));
649 }
650 }
651 }
652
653
654 // XMLAuthorFieldImportContext
655
656 static const OUStringLiteral gsPropertyAuthorFullName("FullName");
657
XMLAuthorFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName,sal_uInt16 nToken)658 XMLAuthorFieldImportContext::XMLAuthorFieldImportContext(
659 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
660 sal_uInt16 nPrfx, const OUString& sLocalName,
661 sal_uInt16 nToken)
662 : XMLSenderFieldImportContext(rImport, rHlp, nPrfx, sLocalName, nToken)
663 , bAuthorFullName(true)
664 , sPropertyFixed(sAPI_is_fixed)
665 , sPropertyContent(sAPI_content)
666 {
667 // overwrite service name from XMLSenderFieldImportContext
668 SetServiceName(sAPI_author);
669 }
670
StartElement(const Reference<XAttributeList> & xAttrList)671 void XMLAuthorFieldImportContext::StartElement(
672 const Reference<XAttributeList> & xAttrList) {
673
674 bAuthorFullName = (XML_TOK_TEXT_AUTHOR_INITIALS != nElementToken);
675 bValid = true;
676
677 // process Attributes
678 XMLTextFieldImportContext::StartElement(xAttrList);
679 }
680
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)681 void XMLAuthorFieldImportContext::ProcessAttribute(sal_uInt16 nAttrToken, const OUString& sAttrValue)
682 {
683 if(nAttrToken == XML_TOK_TEXTFIELD_FIXED)
684 {
685 bool bTmp(false);
686 if (::sax::Converter::convertBool(bTmp, sAttrValue))
687 bFixed = bTmp;
688 }
689 }
690
PrepareField(const Reference<XPropertySet> & rPropSet)691 void XMLAuthorFieldImportContext::PrepareField(
692 const Reference<XPropertySet> & rPropSet)
693 {
694 // set members
695 Any aAny;
696 rPropSet->setPropertyValue(gsPropertyAuthorFullName, Any(bAuthorFullName));
697
698 rPropSet->setPropertyValue(sPropertyFixed, Any(bFixed));
699
700 // set content if fixed
701 if (bFixed)
702 {
703 // organizer or styles-only mode: force update
704 if (GetImport().GetTextImport()->IsOrganizerMode() ||
705 GetImport().GetTextImport()->IsStylesOnlyMode() )
706 {
707 ForceUpdate(rPropSet);
708 }
709 else
710 {
711 aAny <<= GetContent();
712 rPropSet->setPropertyValue(sPropertyContent, aAny);
713 }
714 }
715 }
716
717
718 // page continuation string
719
720
721 static SvXMLEnumMapEntry<PageNumberType> const lcl_aSelectPageAttrMap[] =
722 {
723 { XML_PREVIOUS, PageNumberType_PREV },
724 { XML_CURRENT, PageNumberType_CURRENT },
725 { XML_NEXT, PageNumberType_NEXT },
726 { XML_TOKEN_INVALID, PageNumberType(0) },
727 };
728
729 static const OUStringLiteral gsPropertyUserText("UserText");
730
XMLPageContinuationImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)731 XMLPageContinuationImportContext::XMLPageContinuationImportContext(
732 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
733 const OUString& sLocalName)
734 : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number, nPrfx, sLocalName)
735 , sPropertySubType(sAPI_sub_type)
736 , sPropertyNumberingType(sAPI_numbering_type)
737 , eSelectPage(PageNumberType_CURRENT)
738 , sStringOK(false)
739 {
740 bValid = true;
741 }
742
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)743 void XMLPageContinuationImportContext::ProcessAttribute(
744 sal_uInt16 nAttrToken, const OUString& sAttrValue )
745 {
746 switch(nAttrToken)
747 {
748 case XML_TOK_TEXTFIELD_SELECT_PAGE:
749 {
750 PageNumberType nTmp;
751 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
752 lcl_aSelectPageAttrMap)
753 && (PageNumberType_CURRENT != nTmp) )
754 {
755 eSelectPage = nTmp;
756 }
757 break;
758 }
759 case XML_TOK_TEXTFIELD_STRING_VALUE:
760 sString = sAttrValue;
761 sStringOK = true;
762 break;
763 }
764 }
765
PrepareField(const Reference<XPropertySet> & xPropertySet)766 void XMLPageContinuationImportContext::PrepareField(
767 const Reference<XPropertySet> & xPropertySet)
768 {
769 Any aAny;
770
771 xPropertySet->setPropertyValue(sPropertySubType, Any(eSelectPage));
772
773 aAny <<= (sStringOK ? sString : GetContent());
774 xPropertySet->setPropertyValue(gsPropertyUserText, aAny);
775
776 aAny <<= style::NumberingType::CHAR_SPECIAL;
777 xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
778 }
779
780
781 // page number field
782
783
XMLPageNumberImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)784 XMLPageNumberImportContext::XMLPageNumberImportContext(
785 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
786 const OUString& sLocalName)
787 : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number, nPrfx, sLocalName)
788 , sPropertySubType(sAPI_sub_type)
789 , sPropertyNumberingType(sAPI_numbering_type)
790 , sPropertyOffset(sAPI_offset)
791 , sNumberSync(GetXMLToken(XML_FALSE))
792 , nPageAdjust(0)
793 , eSelectPage(PageNumberType_CURRENT)
794 , sNumberFormatOK(false)
795 {
796 bValid = true;
797 }
798
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)799 void XMLPageNumberImportContext::ProcessAttribute(
800 sal_uInt16 nAttrToken,
801 const OUString& sAttrValue )
802 {
803 switch (nAttrToken)
804 {
805 case XML_TOK_TEXTFIELD_NUM_FORMAT:
806 sNumberFormat = sAttrValue;
807 sNumberFormatOK = true;
808 break;
809 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
810 sNumberSync = sAttrValue;
811 break;
812 case XML_TOK_TEXTFIELD_SELECT_PAGE:
813 SvXMLUnitConverter::convertEnum(eSelectPage, sAttrValue,
814 lcl_aSelectPageAttrMap);
815 break;
816 case XML_TOK_TEXTFIELD_PAGE_ADJUST:
817 {
818 sal_Int32 nTmp;
819 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
820 {
821 nPageAdjust = static_cast<sal_Int16>(nTmp);
822 }
823 break;
824 }
825 }
826 }
827
PrepareField(const Reference<XPropertySet> & xPropertySet)828 void XMLPageNumberImportContext::PrepareField(
829 const Reference<XPropertySet> & xPropertySet)
830 {
831 // all properties are optional
832 Reference<XPropertySetInfo> xPropertySetInfo(
833 xPropertySet->getPropertySetInfo());
834
835 if (xPropertySetInfo->hasPropertyByName(sPropertyNumberingType))
836 {
837 sal_Int16 nNumType;
838 if( sNumberFormatOK )
839 {
840 nNumType= style::NumberingType::ARABIC;
841 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
842 sNumberFormat,
843 sNumberSync );
844 }
845 else
846 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
847
848 xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType));
849 }
850
851 if (xPropertySetInfo->hasPropertyByName(sPropertyOffset))
852 {
853 // adjust offset
854 switch (eSelectPage)
855 {
856 case PageNumberType_PREV:
857 nPageAdjust--;
858 break;
859 case PageNumberType_CURRENT:
860 break;
861 case PageNumberType_NEXT:
862 nPageAdjust++;
863 break;
864 default:
865 SAL_WARN("xmloff.text", "unknown page number type");
866 }
867 xPropertySet->setPropertyValue(sPropertyOffset, Any(nPageAdjust));
868 }
869
870 if (xPropertySetInfo->hasPropertyByName(sPropertySubType))
871 {
872 xPropertySet->setPropertyValue(sPropertySubType, Any(eSelectPage));
873 }
874 }
875
876
877 // Placeholder
878
879
880 static const OUStringLiteral gsPropertyPlaceholderType("PlaceHolderType");
881 static const OUStringLiteral gsPropertyPlaceholder("PlaceHolder");
882
XMLPlaceholderFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)883 XMLPlaceholderFieldImportContext::XMLPlaceholderFieldImportContext(
884 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
885 sal_uInt16 nPrfx, const OUString& sLocalName)
886 : XMLTextFieldImportContext(rImport, rHlp, "JumpEdit", nPrfx, sLocalName)
887 , sPropertyHint(sAPI_hint)
888 , nPlaceholderType(PlaceholderType::TEXT)
889 {
890 }
891
892 /// process attribute values
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)893 void XMLPlaceholderFieldImportContext::ProcessAttribute(
894 sal_uInt16 nAttrToken, const OUString& sAttrValue )
895 {
896 switch (nAttrToken) {
897 case XML_TOK_TEXTFIELD_DESCRIPTION:
898 sDescription = sAttrValue;
899 break;
900
901 case XML_TOK_TEXTFIELD_PLACEHOLDER_TYPE:
902 bValid = true;
903 if (IsXMLToken(sAttrValue, XML_TABLE))
904 {
905 nPlaceholderType = PlaceholderType::TABLE;
906 }
907 else if (IsXMLToken(sAttrValue, XML_TEXT))
908 {
909 nPlaceholderType = PlaceholderType::TEXT;
910 }
911 else if (IsXMLToken(sAttrValue, XML_TEXT_BOX))
912 {
913 nPlaceholderType = PlaceholderType::TEXTFRAME;
914 }
915 else if (IsXMLToken(sAttrValue, XML_IMAGE))
916 {
917 nPlaceholderType = PlaceholderType::GRAPHIC;
918 }
919 else if (IsXMLToken(sAttrValue, XML_OBJECT))
920 {
921 nPlaceholderType = PlaceholderType::OBJECT;
922 }
923 else
924 {
925 bValid = false;
926 }
927 break;
928
929 default:
930 ; // ignore
931 }
932 }
933
PrepareField(const Reference<XPropertySet> & xPropertySet)934 void XMLPlaceholderFieldImportContext::PrepareField(
935 const Reference<XPropertySet> & xPropertySet) {
936
937 Any aAny;
938 xPropertySet->setPropertyValue(sPropertyHint, Any(sDescription));
939
940 // remove <...> around content (if present)
941 OUString aContent = GetContent();
942 sal_Int32 nStart = 0;
943 sal_Int32 nLength = aContent.getLength();
944 if (aContent.startsWith("<"))
945 {
946 --nLength;
947 ++nStart;
948 }
949 if (aContent.endsWith(">"))
950 {
951 --nLength;
952 }
953 aAny <<= aContent.copy(nStart, nLength);
954 xPropertySet->setPropertyValue(gsPropertyPlaceholder, aAny);
955
956 xPropertySet->setPropertyValue(gsPropertyPlaceholderType, Any(nPlaceholderType));
957 }
958
959
960 // time field
961
962 static const OUStringLiteral gsPropertyAdjust("Adjust");
963
XMLTimeFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)964 XMLTimeFieldImportContext::XMLTimeFieldImportContext(
965 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
966 sal_uInt16 nPrfx, const OUString& sLocalName)
967 : XMLTextFieldImportContext(rImport, rHlp, sAPI_date_time, nPrfx, sLocalName)
968 , sPropertyNumberFormat(sAPI_number_format)
969 , sPropertyFixed(sAPI_is_fixed)
970 , sPropertyDateTimeValue(sAPI_date_time_value)
971 , sPropertyDateTime(sAPI_date_time)
972 , sPropertyIsDate(sAPI_is_date)
973 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
974 , nAdjust(0)
975 , nFormatKey(0)
976 , bTimeOK(false)
977 , bFormatOK(false)
978 , bFixed(false)
979 , bIsDate(false)
980 , bIsDefaultLanguage( true )
981 {
982 bValid = true; // always valid!
983 }
984
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)985 void XMLTimeFieldImportContext::ProcessAttribute(
986 sal_uInt16 nAttrToken, const OUString& sAttrValue )
987 {
988 switch (nAttrToken)
989 {
990 case XML_TOK_TEXTFIELD_TIME_VALUE:
991 {
992 if (::sax::Converter::parseTimeOrDateTime(aDateTimeValue, sAttrValue))
993 {
994 bTimeOK = true;
995 }
996 break;
997 }
998 case XML_TOK_TEXTFIELD_FIXED:
999 {
1000 bool bTmp(false);
1001 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1002 {
1003 bFixed = bTmp;
1004 }
1005 break;
1006 }
1007 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1008 {
1009 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1010 sAttrValue, &bIsDefaultLanguage);
1011 if (-1 != nKey)
1012 {
1013 nFormatKey = nKey;
1014 bFormatOK = true;
1015 }
1016 break;
1017 }
1018 case XML_TOK_TEXTFIELD_TIME_ADJUST:
1019 {
1020 double fTmp;
1021
1022 if (::sax::Converter::convertDuration(fTmp, sAttrValue))
1023 {
1024 // convert to minutes
1025 nAdjust = static_cast<sal_Int32>(::rtl::math::approxFloor(fTmp * 60 * 24));
1026 }
1027 break;
1028 }
1029 }
1030 }
1031
PrepareField(const Reference<XPropertySet> & rPropertySet)1032 void XMLTimeFieldImportContext::PrepareField(
1033 const Reference<XPropertySet> & rPropertySet)
1034 {
1035 // all properties are optional (except IsDate)
1036 Reference<XPropertySetInfo> xPropertySetInfo(
1037 rPropertySet->getPropertySetInfo());
1038
1039 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
1040 {
1041 rPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed));
1042 }
1043
1044 rPropertySet->setPropertyValue(sPropertyIsDate, Any(bIsDate));
1045
1046 if (xPropertySetInfo->hasPropertyByName(gsPropertyAdjust))
1047 {
1048 rPropertySet->setPropertyValue(gsPropertyAdjust, Any(nAdjust));
1049 }
1050
1051 // set value
1052 if (bFixed)
1053 {
1054 // organizer or styles-only mode: force update
1055 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1056 GetImport().GetTextImport()->IsStylesOnlyMode() )
1057 {
1058 ForceUpdate(rPropertySet);
1059 }
1060 else
1061 {
1062 // normal mode: set value (if present)
1063 if (bTimeOK)
1064 {
1065 if (xPropertySetInfo->hasPropertyByName(sPropertyDateTimeValue))
1066 {
1067 rPropertySet->setPropertyValue(sPropertyDateTimeValue, Any(aDateTimeValue));
1068 }
1069 else if (xPropertySetInfo->hasPropertyByName(sPropertyDateTime))
1070 {
1071 rPropertySet->setPropertyValue(sPropertyDateTime, Any(aDateTimeValue));
1072 }
1073 }
1074 }
1075 }
1076
1077 if (bFormatOK &&
1078 xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
1079 {
1080 rPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormatKey));
1081
1082 if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
1083 {
1084 bool bIsFixedLanguage = ! bIsDefaultLanguage;
1085 rPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) );
1086 }
1087 }
1088 }
1089
1090
1091 // date field
1092
1093
XMLDateFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)1094 XMLDateFieldImportContext::XMLDateFieldImportContext(
1095 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1096 sal_uInt16 nPrfx, const OUString& sLocalName) :
1097 XMLTimeFieldImportContext(rImport, rHlp, nPrfx, sLocalName)
1098 {
1099 bIsDate = true; // always a date!
1100 }
1101
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1102 void XMLDateFieldImportContext::ProcessAttribute(
1103 sal_uInt16 nAttrToken,
1104 const OUString& sAttrValue )
1105 {
1106 switch (nAttrToken)
1107 {
1108 case XML_TOK_TEXTFIELD_DATE_VALUE:
1109 {
1110 if (::sax::Converter::parseDateTime(aDateTimeValue, sAttrValue))
1111 {
1112 bTimeOK = true;
1113 }
1114 break;
1115 }
1116 case XML_TOK_TEXTFIELD_DATE_ADJUST:
1117 // delegate to superclass, pretending it was a time-adjust attr.
1118 XMLTimeFieldImportContext::ProcessAttribute(
1119 XML_TOK_TEXTFIELD_TIME_ADJUST,
1120 sAttrValue);
1121 break;
1122 case XML_TOK_TEXTFIELD_TIME_VALUE:
1123 case XML_TOK_TEXTFIELD_TIME_ADJUST:
1124 ; // ignore time-adjust and time-value attributes
1125 break;
1126 default:
1127 // all others: delegate to super-class
1128 XMLTimeFieldImportContext::ProcessAttribute(nAttrToken,
1129 sAttrValue);
1130 break;
1131 }
1132 }
1133
1134
1135 // database field superclass
1136
1137
1138 static const OUStringLiteral gsPropertyDataBaseName("DataBaseName");
1139 static const OUStringLiteral gsPropertyDataBaseURL("DataBaseURL");
1140 static const OUStringLiteral gsPropertyTableName("DataTableName");
1141 static const OUStringLiteral gsPropertyDataCommandType("DataCommandType");
1142 static const OUStringLiteral gsPropertyIsVisible("IsVisible");
1143
XMLDatabaseFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,const sal_Char * pServiceName,sal_uInt16 nPrfx,const OUString & sLocalName,bool bUseDisply)1144 XMLDatabaseFieldImportContext::XMLDatabaseFieldImportContext(
1145 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1146 const sal_Char* pServiceName, sal_uInt16 nPrfx,
1147 const OUString& sLocalName, bool bUseDisply)
1148 : XMLTextFieldImportContext(rImport, rHlp, pServiceName, nPrfx, sLocalName)
1149 , nCommandType( sdb::CommandType::TABLE )
1150 , bCommandTypeOK(false)
1151 , bDisplay( true )
1152 , bDisplayOK( false )
1153 , bUseDisplay( bUseDisply )
1154 , bDatabaseOK(false)
1155 , bDatabaseNameOK(false)
1156 , bDatabaseURLOK(false)
1157 , bTableOK(false)
1158 {
1159 }
1160
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1161 void XMLDatabaseFieldImportContext::ProcessAttribute(
1162 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1163 {
1164 switch (nAttrToken)
1165 {
1166 case XML_TOK_TEXTFIELD_DATABASE_NAME:
1167 sDatabaseName = sAttrValue;
1168 bDatabaseOK = true;
1169 bDatabaseNameOK = true;
1170 break;
1171 case XML_TOK_TEXTFIELD_TABLE_NAME:
1172 sTableName = sAttrValue;
1173 bTableOK = true;
1174 break;
1175 case XML_TOK_TEXTFIELD_TABLE_TYPE:
1176 if( IsXMLToken( sAttrValue, XML_TABLE ) )
1177 {
1178 nCommandType = sdb::CommandType::TABLE;
1179 bCommandTypeOK = true;
1180 }
1181 else if( IsXMLToken( sAttrValue, XML_QUERY ) )
1182 {
1183 nCommandType = sdb::CommandType::QUERY;
1184 bCommandTypeOK = true;
1185 }
1186 else if( IsXMLToken( sAttrValue, XML_COMMAND ) )
1187 {
1188 nCommandType = sdb::CommandType::COMMAND;
1189 bCommandTypeOK = true;
1190 }
1191 break;
1192 case XML_TOK_TEXTFIELD_DISPLAY:
1193 if( IsXMLToken( sAttrValue, XML_NONE ) )
1194 {
1195 bDisplay = false;
1196 bDisplayOK = true;
1197 }
1198 else if( IsXMLToken( sAttrValue, XML_VALUE ) )
1199 {
1200 bDisplay = true;
1201 bDisplayOK = true;
1202 }
1203 break;
1204 }
1205 }
1206
CreateChildContext(sal_uInt16 p_nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)1207 SvXMLImportContextRef XMLDatabaseFieldImportContext::CreateChildContext(
1208 sal_uInt16 p_nPrefix,
1209 const OUString& rLocalName,
1210 const Reference<XAttributeList>& xAttrList )
1211 {
1212 if( ( p_nPrefix == XML_NAMESPACE_FORM ) &&
1213 IsXMLToken( rLocalName, XML_CONNECTION_RESOURCE ) )
1214 {
1215 // process attribute list directly
1216 sal_Int16 nLength = xAttrList->getLength();
1217 for( sal_Int16 n = 0; n < nLength; n++ )
1218 {
1219 OUString sLocalName;
1220 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1221 GetKeyByAttrName( xAttrList->getNameByIndex(n), &sLocalName );
1222
1223 if( ( nPrefix == XML_NAMESPACE_XLINK ) &&
1224 IsXMLToken( sLocalName, XML_HREF ) )
1225 {
1226 sDatabaseURL = xAttrList->getValueByIndex(n);
1227 bDatabaseOK = true;
1228 bDatabaseURLOK = true;
1229 }
1230 }
1231
1232 // we call ProcessAttribute in order to set bValid appropriately
1233 ProcessAttribute( XML_TOKEN_INVALID, OUString() );
1234 }
1235
1236 return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName,
1237 xAttrList);
1238 }
1239
1240
PrepareField(const Reference<XPropertySet> & xPropertySet)1241 void XMLDatabaseFieldImportContext::PrepareField(
1242 const Reference<XPropertySet> & xPropertySet)
1243 {
1244 xPropertySet->setPropertyValue(gsPropertyTableName, Any(sTableName));
1245
1246 if( bDatabaseNameOK )
1247 {
1248 xPropertySet->setPropertyValue(gsPropertyDataBaseName, Any(sDatabaseName));
1249 }
1250 else if( bDatabaseURLOK )
1251 {
1252 xPropertySet->setPropertyValue(gsPropertyDataBaseURL, Any(sDatabaseURL));
1253 }
1254
1255 // #99980# load/save command type for all fields; also load
1256 // old documents without command type
1257 if( bCommandTypeOK )
1258 {
1259 xPropertySet->setPropertyValue( gsPropertyDataCommandType, Any(nCommandType) );
1260 }
1261
1262 if( bUseDisplay && bDisplayOK )
1263 {
1264 xPropertySet->setPropertyValue( gsPropertyIsVisible, Any(bDisplay) );
1265 }
1266 }
1267
1268
1269 // database name field
1270
1271
XMLDatabaseNameImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)1272 XMLDatabaseNameImportContext::XMLDatabaseNameImportContext(
1273 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1274 sal_uInt16 nPrfx, const OUString& sLocalName) :
1275 XMLDatabaseFieldImportContext(rImport, rHlp, "DatabaseName",
1276 nPrfx, sLocalName, true)
1277 {
1278 }
1279
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1280 void XMLDatabaseNameImportContext::ProcessAttribute(
1281 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1282 {
1283 // delegate to superclass and check for success
1284 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1285 bValid = bDatabaseOK && bTableOK;
1286 }
1287
1288
1289 // database next field
1290
1291
XMLDatabaseNextImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,const sal_Char * pServiceName,sal_uInt16 nPrfx,const OUString & sLocalName)1292 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1293 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1294 const sal_Char* pServiceName, sal_uInt16 nPrfx,
1295 const OUString& sLocalName) :
1296 XMLDatabaseFieldImportContext(rImport, rHlp, pServiceName,
1297 nPrfx, sLocalName, false),
1298 sPropertyCondition(sAPI_condition),
1299 sTrue(sAPI_true),
1300 sCondition(),
1301 bConditionOK(false)
1302 {
1303 }
1304
XMLDatabaseNextImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)1305 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1306 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1307 sal_uInt16 nPrfx, const OUString& sLocalName)
1308 : XMLDatabaseFieldImportContext(rImport, rHlp, "DatabaseNextSet", nPrfx, sLocalName, false)
1309 , sPropertyCondition(sAPI_condition)
1310 , sTrue(sAPI_true)
1311 , bConditionOK(false)
1312 {
1313 }
1314
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1315 void XMLDatabaseNextImportContext::ProcessAttribute(
1316 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1317 {
1318 if (XML_TOK_TEXTFIELD_CONDITION == nAttrToken)
1319 {
1320 OUString sTmp;
1321 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName_(
1322 sAttrValue, &sTmp );
1323 if( XML_NAMESPACE_OOOW == nPrefix )
1324 {
1325 sCondition = sTmp;
1326 bConditionOK = true;
1327 }
1328 else
1329 sCondition = sAttrValue;
1330 }
1331 else
1332 {
1333 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1334 sAttrValue);
1335 }
1336
1337 bValid = bDatabaseOK && bTableOK;
1338 }
1339
PrepareField(const Reference<XPropertySet> & xPropertySet)1340 void XMLDatabaseNextImportContext::PrepareField(
1341 const Reference<XPropertySet> & xPropertySet)
1342 {
1343 Any aAny;
1344
1345 aAny <<= bConditionOK ? sCondition : sTrue;
1346 xPropertySet->setPropertyValue(sPropertyCondition, aAny);
1347
1348 XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1349 }
1350
1351
1352 // database select field
1353
1354
XMLDatabaseSelectImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)1355 XMLDatabaseSelectImportContext::XMLDatabaseSelectImportContext(
1356 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1357 sal_uInt16 nPrfx, const OUString& sLocalName) :
1358 XMLDatabaseNextImportContext(rImport, rHlp, "DatabaseNumberOfSet",
1359 nPrfx, sLocalName),
1360 sPropertySetNumber(sAPI_set_number),
1361 nNumber(0),
1362 bNumberOK(false)
1363 {
1364 }
1365
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1366 void XMLDatabaseSelectImportContext::ProcessAttribute(
1367 sal_uInt16 nAttrToken,
1368 const OUString& sAttrValue )
1369 {
1370 if (XML_TOK_TEXTFIELD_ROW_NUMBER == nAttrToken)
1371 {
1372 sal_Int32 nTmp;
1373 if (::sax::Converter::convertNumber( nTmp, sAttrValue
1374 /* , nMin, nMax ??? */ ))
1375 {
1376 nNumber = nTmp;
1377 bNumberOK = true;
1378 }
1379 }
1380 else
1381 {
1382 XMLDatabaseNextImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1383 }
1384
1385 bValid = bTableOK && bDatabaseOK && bNumberOK;
1386 }
1387
PrepareField(const Reference<XPropertySet> & xPropertySet)1388 void XMLDatabaseSelectImportContext::PrepareField(
1389 const Reference<XPropertySet> & xPropertySet)
1390 {
1391 xPropertySet->setPropertyValue(sPropertySetNumber, Any(nNumber));
1392
1393 XMLDatabaseNextImportContext::PrepareField(xPropertySet);
1394 }
1395
1396
1397 // database display row number field
1398
1399
XMLDatabaseNumberImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)1400 XMLDatabaseNumberImportContext::XMLDatabaseNumberImportContext(
1401 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1402 sal_uInt16 nPrfx, const OUString& sLocalName) :
1403 XMLDatabaseFieldImportContext(rImport, rHlp, "DatabaseSetNumber",
1404 nPrfx, sLocalName, true),
1405 sPropertyNumberingType(
1406 sAPI_numbering_type),
1407 sPropertySetNumber(sAPI_set_number),
1408 sNumberFormat("1"),
1409 sNumberSync(GetXMLToken(XML_FALSE)),
1410 nValue(0),
1411 bValueOK(false)
1412 {
1413 }
1414
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1415 void XMLDatabaseNumberImportContext::ProcessAttribute(
1416 sal_uInt16 nAttrToken,
1417 const OUString& sAttrValue )
1418 {
1419 switch (nAttrToken)
1420 {
1421 case XML_TOK_TEXTFIELD_NUM_FORMAT:
1422 sNumberFormat = sAttrValue;
1423 break;
1424 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
1425 sNumberSync = sAttrValue;
1426 break;
1427 case XML_TOK_TEXTFIELD_VALUE:
1428 {
1429 sal_Int32 nTmp;
1430 if (::sax::Converter::convertNumber( nTmp, sAttrValue ))
1431 {
1432 nValue = nTmp;
1433 bValueOK = true;
1434 }
1435 break;
1436 }
1437 default:
1438 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1439 sAttrValue);
1440 break;
1441 }
1442
1443 bValid = bTableOK && bDatabaseOK;
1444 }
1445
PrepareField(const Reference<XPropertySet> & xPropertySet)1446 void XMLDatabaseNumberImportContext::PrepareField(
1447 const Reference<XPropertySet> & xPropertySet)
1448 {
1449 sal_Int16 nNumType = style::NumberingType::ARABIC;
1450 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
1451 sNumberFormat,
1452 sNumberSync );
1453 xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType));
1454
1455 if (bValueOK)
1456 {
1457 xPropertySet->setPropertyValue(sPropertySetNumber, Any(nValue));
1458 }
1459
1460 XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1461 }
1462
1463
1464 // Simple doc info fields
1465
1466
XMLSimpleDocInfoImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName,sal_uInt16 nToken,bool bContent,bool bAuthor)1467 XMLSimpleDocInfoImportContext::XMLSimpleDocInfoImportContext(
1468 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1469 sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken,
1470 bool bContent, bool bAuthor)
1471 : XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nToken),nPrfx, sLocalName)
1472 , sPropertyFixed(sAPI_is_fixed)
1473 , sPropertyContent(sAPI_content)
1474 , sPropertyAuthor(sAPI_author)
1475 , sPropertyCurrentPresentation(sAPI_current_presentation)
1476 , bFixed(false)
1477 , bHasAuthor(bAuthor)
1478 , bHasContent(bContent)
1479 {
1480 bValid = true;
1481 }
1482
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1483 void XMLSimpleDocInfoImportContext::ProcessAttribute(
1484 sal_uInt16 nAttrToken,
1485 const OUString& sAttrValue )
1486 {
1487 if (XML_TOK_TEXTFIELD_FIXED == nAttrToken)
1488 {
1489 bool bTmp(false);
1490 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1491 {
1492 bFixed = bTmp;
1493 }
1494 }
1495 }
1496
PrepareField(const Reference<XPropertySet> & rPropertySet)1497 void XMLSimpleDocInfoImportContext::PrepareField(
1498 const Reference<XPropertySet> & rPropertySet)
1499 {
1500 // title field in Calc has no Fixed property
1501 Reference<XPropertySetInfo> xPropertySetInfo(rPropertySet->getPropertySetInfo());
1502 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
1503 {
1504 Any aAny;
1505 rPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed));
1506
1507 // set Content and CurrentPresentation (if fixed)
1508 if (bFixed)
1509 {
1510 // in organizer-mode or styles-only-mode, only force update
1511 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1512 GetImport().GetTextImport()->IsStylesOnlyMode() )
1513 {
1514 ForceUpdate(rPropertySet);
1515 }
1516 else
1517 {
1518 // set content (author, if that's the name) and current
1519 // presentation
1520 aAny <<= GetContent();
1521
1522 if (bFixed && bHasAuthor)
1523 {
1524 rPropertySet->setPropertyValue(sPropertyAuthor, aAny);
1525 }
1526
1527 if (bFixed && bHasContent)
1528 {
1529 rPropertySet->setPropertyValue(sPropertyContent, aAny);
1530 }
1531
1532 rPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
1533 }
1534 }
1535 }
1536 }
1537
MapTokenToServiceName(sal_uInt16 nToken)1538 const sal_Char* XMLSimpleDocInfoImportContext::MapTokenToServiceName(
1539 sal_uInt16 nToken)
1540 {
1541 const sal_Char* pServiceName = nullptr;
1542
1543 switch(nToken)
1544 {
1545 case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR:
1546 pServiceName = "DocInfo.CreateAuthor";
1547 break;
1548 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE:
1549 pServiceName = sAPI_docinfo_create_date_time;
1550 break;
1551 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME:
1552 pServiceName = sAPI_docinfo_create_date_time;
1553 break;
1554 case XML_TOK_TEXT_DOCUMENT_DESCRIPTION:
1555 pServiceName = "DocInfo.Description";
1556 break;
1557 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION:
1558 pServiceName = "DocInfo.EditTime";
1559 break;
1560 case XML_TOK_TEXT_DOCUMENT_USER_DEFINED:
1561 pServiceName = sAPI_docinfo_custom;
1562 break;
1563 case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR:
1564 pServiceName = "DocInfo.PrintAuthor";
1565 break;
1566 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE:
1567 pServiceName = sAPI_docinfo_print_date_time;
1568 break;
1569 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME:
1570 pServiceName = sAPI_docinfo_print_date_time;
1571 break;
1572 case XML_TOK_TEXT_DOCUMENT_KEYWORDS:
1573 pServiceName = "DocInfo.KeyWords";
1574 break;
1575 case XML_TOK_TEXT_DOCUMENT_SUBJECT:
1576 pServiceName = "DocInfo.Subject";
1577 break;
1578 case XML_TOK_TEXT_DOCUMENT_REVISION:
1579 pServiceName = "DocInfo.Revision";
1580 break;
1581 case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR:
1582 pServiceName = "DocInfo.ChangeAuthor";
1583 break;
1584 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE:
1585 pServiceName = sAPI_docinfo_change_date_time;
1586 break;
1587 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME:
1588 pServiceName = sAPI_docinfo_change_date_time;
1589 break;
1590 case XML_TOK_TEXT_DOCUMENT_TITLE:
1591 pServiceName = "DocInfo.Title";
1592 break;
1593
1594 default:
1595 OSL_FAIL("no docinfo field token");
1596 pServiceName = nullptr;
1597 break;
1598 }
1599
1600 return pServiceName;
1601 }
1602
1603
1604 // revision field
1605
1606 static const OUStringLiteral sPropertyRevision("Revision");
1607
XMLRevisionDocInfoImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName,sal_uInt16 nToken)1608 XMLRevisionDocInfoImportContext::XMLRevisionDocInfoImportContext(
1609 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
1610 const OUString& sLocalName, sal_uInt16 nToken) :
1611 XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx, sLocalName,
1612 nToken, false, false)
1613 {
1614 bValid = true;
1615 }
1616
PrepareField(const Reference<XPropertySet> & rPropertySet)1617 void XMLRevisionDocInfoImportContext::PrepareField(
1618 const Reference<XPropertySet> & rPropertySet)
1619 {
1620 XMLSimpleDocInfoImportContext::PrepareField(rPropertySet);
1621
1622 // set revision number
1623 // if fixed, if not in organizer-mode, if not in styles-only-mode
1624 if (bFixed)
1625 {
1626 if ( GetImport().GetTextImport()->IsOrganizerMode() ||
1627 GetImport().GetTextImport()->IsStylesOnlyMode() )
1628 {
1629 ForceUpdate(rPropertySet);
1630 }
1631 else
1632 {
1633 sal_Int32 nTmp;
1634 if (::sax::Converter::convertNumber(nTmp, GetContent()))
1635 {
1636 rPropertySet->setPropertyValue(sPropertyRevision, Any(nTmp));
1637 }
1638 }
1639 }
1640 }
1641
1642
1643 // DocInfo fields with date/time attributes
1644
1645
XMLDateTimeDocInfoImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName,sal_uInt16 nToken)1646 XMLDateTimeDocInfoImportContext::XMLDateTimeDocInfoImportContext(
1647 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
1648 const OUString& sLocalName, sal_uInt16 nToken)
1649 : XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx, sLocalName,nToken, false, false)
1650 , sPropertyNumberFormat(sAPI_number_format)
1651 , sPropertyIsDate(sAPI_is_date)
1652 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
1653 , nFormat(0)
1654 , bFormatOK(false)
1655 , bIsDate(false)
1656 , bHasDateTime(false)
1657 , bIsDefaultLanguage(true)
1658 {
1659 // we allow processing of EDIT_DURATION here, because import of actual
1660 // is not supported anyway. If it was, we'd need an extra import class
1661 // because times and time durations are presented differently!
1662
1663 bValid = true;
1664 switch (nToken)
1665 {
1666 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE:
1667 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE:
1668 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE:
1669 bIsDate = true;
1670 bHasDateTime = true;
1671 break;
1672 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME:
1673 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME:
1674 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME:
1675 bIsDate = false;
1676 bHasDateTime = true;
1677 break;
1678 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION:
1679 bIsDate = false;
1680 bHasDateTime = false;
1681 break;
1682 default:
1683 OSL_FAIL(
1684 "XMLDateTimeDocInfoImportContext needs date/time doc. fields");
1685 bValid = false;
1686 break;
1687 }
1688 }
1689
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1690 void XMLDateTimeDocInfoImportContext::ProcessAttribute(
1691 sal_uInt16 nAttrToken,
1692 const OUString& sAttrValue )
1693 {
1694 switch (nAttrToken)
1695 {
1696 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1697 {
1698 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1699 sAttrValue, &bIsDefaultLanguage);
1700 if (-1 != nKey)
1701 {
1702 nFormat = nKey;
1703 bFormatOK = true;
1704 }
1705 break;
1706 }
1707 case XML_TOK_TEXTFIELD_FIXED:
1708 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
1709 sAttrValue);
1710 break;
1711 default:
1712 // ignore -> we can't set date/time value anyway!
1713 break;
1714 }
1715 }
1716
PrepareField(const Reference<XPropertySet> & xPropertySet)1717 void XMLDateTimeDocInfoImportContext::PrepareField(
1718 const Reference<XPropertySet> & xPropertySet)
1719 {
1720 // process fixed and presentation
1721 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
1722
1723 if (bHasDateTime)
1724 {
1725 xPropertySet->setPropertyValue(sPropertyIsDate, Any(bIsDate));
1726 }
1727
1728 if (bFormatOK)
1729 {
1730 xPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormat));
1731
1732 if( xPropertySet->getPropertySetInfo()->
1733 hasPropertyByName( sPropertyIsFixedLanguage ) )
1734 {
1735 bool bIsFixedLanguage = ! bIsDefaultLanguage;
1736 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) );
1737 }
1738 }
1739
1740 // can't set date/time/duration value! Sorry.
1741 }
1742
1743
1744 // user defined docinfo fields
1745
1746
XMLUserDocInfoImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName,sal_uInt16 nToken)1747 XMLUserDocInfoImportContext::XMLUserDocInfoImportContext(
1748 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1749 sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken) :
1750 XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx,
1751 sLocalName, nToken,
1752 false, false)
1753 , sPropertyName(sAPI_name)
1754 , sPropertyNumberFormat(sAPI_number_format)
1755 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
1756 , nFormat(0)
1757 , bFormatOK(false)
1758 , bIsDefaultLanguage( true )
1759 {
1760 bValid = false;
1761 }
1762
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1763 void XMLUserDocInfoImportContext::ProcessAttribute(
1764 sal_uInt16 nAttrToken,
1765 const OUString& sAttrValue )
1766 {
1767 switch (nAttrToken)
1768 {
1769 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1770 {
1771 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1772 sAttrValue, &bIsDefaultLanguage);
1773 if (-1 != nKey)
1774 {
1775 nFormat = nKey;
1776 bFormatOK = true;
1777 }
1778 break;
1779 }
1780 case XML_TOK_TEXTFIELD_NAME:
1781 {
1782 if (!bValid)
1783 {
1784 SetServiceName(sAPI_docinfo_custom );
1785 aName = sAttrValue;
1786 bValid = true;
1787 }
1788 break;
1789 }
1790
1791 default:
1792 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
1793 sAttrValue);
1794 break;
1795 }
1796 }
1797
PrepareField(const css::uno::Reference<css::beans::XPropertySet> & xPropertySet)1798 void XMLUserDocInfoImportContext::PrepareField(
1799 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet)
1800 {
1801 if ( !aName.isEmpty() )
1802 {
1803 xPropertySet->setPropertyValue(sPropertyName, Any(aName));
1804 }
1805 Reference<XPropertySetInfo> xPropertySetInfo(
1806 xPropertySet->getPropertySetInfo());
1807 if (bFormatOK &&
1808 xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
1809 {
1810 xPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormat));
1811
1812 if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
1813 {
1814 bool bIsFixedLanguage = ! bIsDefaultLanguage;
1815 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) );
1816 }
1817 }
1818
1819 // call superclass to handle "fixed"
1820 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
1821 }
1822
1823
1824 // import hidden paragraph fields
1825
1826
XMLHiddenParagraphImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)1827 XMLHiddenParagraphImportContext::XMLHiddenParagraphImportContext(
1828 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1829 sal_uInt16 nPrfx, const OUString& sLocalName) :
1830 XMLTextFieldImportContext(rImport, rHlp, "HiddenParagraph",
1831 nPrfx, sLocalName),
1832 sPropertyCondition(sAPI_condition),
1833 sPropertyIsHidden(sAPI_is_hidden),
1834 sCondition(),
1835 bIsHidden(false)
1836 {
1837 }
1838
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1839 void XMLHiddenParagraphImportContext::ProcessAttribute(
1840 sal_uInt16 nAttrToken,
1841 const OUString& sAttrValue )
1842 {
1843 if (XML_TOK_TEXTFIELD_CONDITION == nAttrToken)
1844 {
1845 OUString sTmp;
1846 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName_(
1847 sAttrValue, &sTmp );
1848 if( XML_NAMESPACE_OOOW == nPrefix )
1849 {
1850 sCondition = sTmp;
1851 bValid = true;
1852 }
1853 else
1854 sCondition = sAttrValue;
1855 }
1856 else if (XML_TOK_TEXTFIELD_IS_HIDDEN == nAttrToken)
1857 {
1858 bool bTmp(false);
1859 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1860 {
1861 bIsHidden = bTmp;
1862 }
1863 }
1864 }
1865
PrepareField(const Reference<XPropertySet> & xPropertySet)1866 void XMLHiddenParagraphImportContext::PrepareField(
1867 const Reference<XPropertySet> & xPropertySet)
1868 {
1869 xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition));
1870 xPropertySet->setPropertyValue(sPropertyIsHidden, Any(bIsHidden));
1871 }
1872
1873
1874 // import conditional text (<text:conditional-text>)
1875
1876 static const OUStringLiteral gsPropertyTrueContent("TrueContent");
1877 static const OUStringLiteral gsPropertyFalseContent("FalseContent");
1878 static const OUStringLiteral gsPropertyIsConditionTrue("IsConditionTrue");
1879
XMLConditionalTextImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)1880 XMLConditionalTextImportContext::XMLConditionalTextImportContext(
1881 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1882 sal_uInt16 nPrfx, const OUString& sLocalName) :
1883 XMLTextFieldImportContext(rImport, rHlp, "ConditionalText",
1884 nPrfx, sLocalName),
1885 sPropertyCondition(sAPI_condition),
1886 sPropertyCurrentPresentation(sAPI_current_presentation),
1887 bConditionOK(false),
1888 bTrueOK(false),
1889 bFalseOK(false),
1890 bCurrentValue(false)
1891 {
1892 }
1893
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1894 void XMLConditionalTextImportContext::ProcessAttribute(
1895 sal_uInt16 nAttrToken,
1896 const OUString& sAttrValue )
1897 {
1898 switch (nAttrToken)
1899 {
1900 case XML_TOK_TEXTFIELD_CONDITION:
1901 {
1902 OUString sTmp;
1903 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1904 GetKeyByAttrName_( sAttrValue, &sTmp );
1905 if( XML_NAMESPACE_OOOW == nPrefix )
1906 {
1907 sCondition = sTmp;
1908 bConditionOK = true;
1909 }
1910 else
1911 sCondition = sAttrValue;
1912 }
1913 break;
1914 case XML_TOK_TEXTFIELD_STRING_VALUE_IF_FALSE:
1915 sFalseContent = sAttrValue;
1916 bFalseOK = true;
1917 break;
1918 case XML_TOK_TEXTFIELD_STRING_VALUE_IF_TRUE:
1919 sTrueContent = sAttrValue;
1920 bTrueOK = true;
1921 break;
1922 case XML_TOK_TEXTFIELD_CURRENT_VALUE:
1923 {
1924 bool bTmp(false);
1925 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1926 {
1927 bCurrentValue = bTmp;
1928 }
1929 break;
1930 }
1931 }
1932
1933 bValid = bConditionOK && bFalseOK && bTrueOK;
1934 }
1935
PrepareField(const Reference<XPropertySet> & xPropertySet)1936 void XMLConditionalTextImportContext::PrepareField(
1937 const Reference<XPropertySet> & xPropertySet)
1938 {
1939 xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition));
1940 xPropertySet->setPropertyValue(gsPropertyFalseContent, Any(sFalseContent));
1941 xPropertySet->setPropertyValue(gsPropertyTrueContent, Any(sTrueContent));
1942 xPropertySet->setPropertyValue(gsPropertyIsConditionTrue, Any(bCurrentValue));
1943 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, Any(GetContent()));
1944 }
1945
1946
1947 // hidden text
1948
1949
XMLHiddenTextImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)1950 XMLHiddenTextImportContext::XMLHiddenTextImportContext(
1951 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1952 sal_uInt16 nPrfx, const OUString& sLocalName) :
1953 XMLTextFieldImportContext(rImport, rHlp, "HiddenText",
1954 nPrfx, sLocalName),
1955 sPropertyCondition(sAPI_condition),
1956 sPropertyContent(sAPI_content),
1957 sPropertyIsHidden(sAPI_is_hidden),
1958 bConditionOK(false),
1959 bStringOK(false),
1960 bIsHidden(false)
1961 {
1962 }
1963
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)1964 void XMLHiddenTextImportContext::ProcessAttribute(
1965 sal_uInt16 nAttrToken,
1966 const OUString& sAttrValue )
1967 {
1968 switch (nAttrToken)
1969 {
1970 case XML_TOK_TEXTFIELD_CONDITION:
1971 {
1972 OUString sTmp;
1973 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1974 GetKeyByAttrName_( sAttrValue, &sTmp );
1975 if( XML_NAMESPACE_OOOW == nPrefix )
1976 {
1977 sCondition = sTmp;
1978 bConditionOK = true;
1979 }
1980 else
1981 sCondition = sAttrValue;
1982 }
1983 break;
1984 case XML_TOK_TEXTFIELD_STRING_VALUE:
1985 sString = sAttrValue;
1986 bStringOK = true;
1987 break;
1988 case XML_TOK_TEXTFIELD_IS_HIDDEN:
1989 {
1990 bool bTmp(false);
1991 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1992 {
1993 bIsHidden = bTmp;
1994 }
1995 break;
1996 }
1997 }
1998
1999 bValid = bConditionOK && bStringOK;
2000 }
2001
PrepareField(const Reference<XPropertySet> & xPropertySet)2002 void XMLHiddenTextImportContext::PrepareField(
2003 const Reference<XPropertySet> & xPropertySet)
2004 {
2005 xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition));
2006 xPropertySet->setPropertyValue(sPropertyContent, Any(sString));
2007 xPropertySet->setPropertyValue(sPropertyIsHidden, Any(bIsHidden));
2008 }
2009
2010
2011 // file name fields
2012
2013
2014 static const SvXMLEnumMapEntry<sal_uInt16> aFilenameDisplayMap[] =
2015 {
2016 { XML_PATH, FilenameDisplayFormat::PATH },
2017 { XML_NAME, FilenameDisplayFormat::NAME },
2018 { XML_NAME_AND_EXTENSION, FilenameDisplayFormat::NAME_AND_EXT },
2019 { XML_FULL, FilenameDisplayFormat::FULL },
2020 { XML_TOKEN_INVALID, 0 }
2021 };
2022
XMLFileNameImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2023 XMLFileNameImportContext::XMLFileNameImportContext(
2024 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2025 const OUString& sLocalName) :
2026 XMLTextFieldImportContext(rImport, rHlp, "FileName",
2027 nPrfx, sLocalName),
2028 sPropertyFixed(sAPI_is_fixed),
2029 sPropertyFileFormat(sAPI_file_format),
2030 sPropertyCurrentPresentation(
2031 sAPI_current_presentation),
2032 nFormat(FilenameDisplayFormat::FULL),
2033 bFixed(false)
2034 {
2035 bValid = true;
2036 }
2037
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2038 void XMLFileNameImportContext::ProcessAttribute(
2039 sal_uInt16 nAttrToken,
2040 const OUString& sAttrValue )
2041 {
2042 switch (nAttrToken)
2043 {
2044 case XML_TOK_TEXTFIELD_FIXED:
2045 {
2046 bool bTmp(false);
2047 if (::sax::Converter::convertBool(bTmp, sAttrValue))
2048 {
2049 bFixed = bTmp;
2050 }
2051 break;
2052 }
2053 case XML_TOK_TEXTFIELD_DISPLAY:
2054 {
2055 sal_uInt16 nTmp;
2056 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2057 aFilenameDisplayMap))
2058 {
2059 nFormat = nTmp;
2060 }
2061 break;
2062 }
2063 default:
2064 ; // unknown attribute: ignore
2065 break;
2066 }
2067 }
2068
PrepareField(const Reference<XPropertySet> & xPropertySet)2069 void XMLFileNameImportContext::PrepareField(
2070 const Reference<XPropertySet> & xPropertySet)
2071 {
2072 // properties are optional
2073 Reference<XPropertySetInfo> xPropertySetInfo(
2074 xPropertySet->getPropertySetInfo());
2075
2076 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
2077 {
2078 xPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed));
2079 }
2080
2081 if (xPropertySetInfo->hasPropertyByName(sPropertyFileFormat))
2082 {
2083 xPropertySet->setPropertyValue(sPropertyFileFormat, Any(nFormat));
2084 }
2085
2086 if (xPropertySetInfo->hasPropertyByName(sPropertyCurrentPresentation))
2087 {
2088 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, Any(GetContent()));
2089 }
2090 }
2091
2092
2093 // template name field
2094
2095
2096 static const SvXMLEnumMapEntry<sal_uInt16> aTemplateDisplayMap[] =
2097 {
2098 { XML_FULL, TemplateDisplayFormat::FULL },
2099 { XML_PATH, TemplateDisplayFormat::PATH },
2100 { XML_NAME, TemplateDisplayFormat::NAME },
2101 { XML_NAME_AND_EXTENSION, TemplateDisplayFormat::NAME_AND_EXT },
2102 { XML_AREA, TemplateDisplayFormat::AREA },
2103 { XML_TITLE, TemplateDisplayFormat::TITLE },
2104 { XML_TOKEN_INVALID, 0 }
2105 };
2106
2107
XMLTemplateNameImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2108 XMLTemplateNameImportContext::XMLTemplateNameImportContext(
2109 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2110 const OUString& sLocalName) :
2111 XMLTextFieldImportContext(rImport, rHlp, "TemplateName",
2112 nPrfx, sLocalName),
2113 sPropertyFileFormat(sAPI_file_format),
2114 nFormat(TemplateDisplayFormat::FULL)
2115 {
2116 bValid = true;
2117 }
2118
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2119 void XMLTemplateNameImportContext::ProcessAttribute(
2120 sal_uInt16 nAttrToken,
2121 const OUString& sAttrValue )
2122 {
2123 switch (nAttrToken)
2124 {
2125 case XML_TOK_TEXTFIELD_DISPLAY:
2126 {
2127 sal_uInt16 nTmp;
2128 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2129 aTemplateDisplayMap))
2130 {
2131 nFormat = nTmp;
2132 }
2133 break;
2134 }
2135 default:
2136 ; // unknown attribute: ignore
2137 break;
2138 }
2139 }
2140
PrepareField(const Reference<XPropertySet> & xPropertySet)2141 void XMLTemplateNameImportContext::PrepareField(
2142 const Reference<XPropertySet> & xPropertySet)
2143 {
2144 xPropertySet->setPropertyValue(sPropertyFileFormat, Any(nFormat));
2145 }
2146
2147
2148 // import chapter fields
2149
2150
2151 static const SvXMLEnumMapEntry<sal_uInt16> aChapterDisplayMap[] =
2152 {
2153 { XML_NAME, ChapterFormat::NAME },
2154 { XML_NUMBER, ChapterFormat::NUMBER },
2155 { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
2156 { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
2157 { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
2158 { XML_TOKEN_INVALID, 0 }
2159 };
2160
2161 static const OUStringLiteral gsPropertyChapterFormat("ChapterFormat");
2162 static const OUStringLiteral gsPropertyLevel("Level");
2163
XMLChapterImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2164 XMLChapterImportContext::XMLChapterImportContext(
2165 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2166 sal_uInt16 nPrfx, const OUString& sLocalName) :
2167 XMLTextFieldImportContext(rImport, rHlp, "Chapter",
2168 nPrfx, sLocalName),
2169 nFormat(ChapterFormat::NAME_NUMBER),
2170 nLevel(0)
2171 {
2172 bValid = true;
2173 }
2174
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2175 void XMLChapterImportContext::ProcessAttribute(
2176 sal_uInt16 nAttrToken,
2177 const OUString& sAttrValue )
2178 {
2179 switch (nAttrToken)
2180 {
2181 case XML_TOK_TEXTFIELD_DISPLAY:
2182 {
2183 sal_uInt16 nTmp;
2184 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2185 aChapterDisplayMap))
2186 {
2187 nFormat = static_cast<sal_Int16>(nTmp);
2188 }
2189 break;
2190 }
2191 case XML_TOK_TEXTFIELD_OUTLINE_LEVEL:
2192 {
2193 sal_Int32 nTmp;
2194 if (::sax::Converter::convertNumber(
2195 nTmp, sAttrValue, 1,
2196 GetImport().GetTextImport()->GetChapterNumbering()->getCount()
2197 ))
2198 {
2199 // API numbers 0..9, we number 1..10
2200 nLevel = static_cast<sal_Int8>(nTmp);
2201 nLevel--;
2202 }
2203 break;
2204 }
2205 default:
2206 ; // unknown attribute: ignore
2207 break;
2208 }
2209 }
2210
PrepareField(const Reference<XPropertySet> & xPropertySet)2211 void XMLChapterImportContext::PrepareField(
2212 const Reference<XPropertySet> & xPropertySet)
2213 {
2214 xPropertySet->setPropertyValue(gsPropertyChapterFormat, Any(nFormat));
2215 xPropertySet->setPropertyValue(gsPropertyLevel, Any(nLevel));
2216 }
2217
2218
2219 // counting fields
2220
2221
XMLCountFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName,sal_uInt16 nToken)2222 XMLCountFieldImportContext::XMLCountFieldImportContext(
2223 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2224 sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken) :
2225 XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nToken),
2226 nPrfx, sLocalName),
2227 sPropertyNumberingType(
2228 sAPI_numbering_type),
2229 sNumberFormat(),
2230 sLetterSync(),
2231 bNumberFormatOK(false)
2232 {
2233 bValid = true;
2234 }
2235
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2236 void XMLCountFieldImportContext::ProcessAttribute(
2237 sal_uInt16 nAttrToken,
2238 const OUString& sAttrValue )
2239 {
2240 switch (nAttrToken)
2241 {
2242 case XML_TOK_TEXTFIELD_NUM_FORMAT:
2243 sNumberFormat = sAttrValue;
2244 bNumberFormatOK = true;
2245 break;
2246 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
2247 sLetterSync = sAttrValue;
2248 break;
2249 }
2250 }
2251
PrepareField(const Reference<XPropertySet> & xPropertySet)2252 void XMLCountFieldImportContext::PrepareField(
2253 const Reference<XPropertySet> & xPropertySet)
2254 {
2255 // properties optional
2256 // (only page count, but do for all to save common implementation)
2257
2258 if (xPropertySet->getPropertySetInfo()->
2259 hasPropertyByName(sPropertyNumberingType))
2260 {
2261 sal_Int16 nNumType;
2262 if( bNumberFormatOK )
2263 {
2264 nNumType= style::NumberingType::ARABIC;
2265 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2266 sNumberFormat,
2267 sLetterSync );
2268 }
2269 else
2270 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2271 xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType));
2272 }
2273 }
2274
MapTokenToServiceName(sal_uInt16 nToken)2275 const sal_Char* XMLCountFieldImportContext::MapTokenToServiceName(
2276 sal_uInt16 nToken)
2277 {
2278 const sal_Char* pServiceName = nullptr;
2279
2280 switch (nToken)
2281 {
2282 case XML_TOK_TEXT_WORD_COUNT:
2283 pServiceName = "WordCount";
2284 break;
2285 case XML_TOK_TEXT_PARAGRAPH_COUNT:
2286 pServiceName = "ParagraphCount";
2287 break;
2288 case XML_TOK_TEXT_TABLE_COUNT:
2289 pServiceName = "TableCount";
2290 break;
2291 case XML_TOK_TEXT_CHARACTER_COUNT:
2292 pServiceName = "CharacterCount";
2293 break;
2294 case XML_TOK_TEXT_IMAGE_COUNT:
2295 pServiceName = "GraphicObjectCount";
2296 break;
2297 case XML_TOK_TEXT_OBJECT_COUNT:
2298 pServiceName = "EmbeddedObjectCount";
2299 break;
2300 case XML_TOK_TEXT_PAGE_COUNT:
2301 pServiceName = "PageCount";
2302 break;
2303 default:
2304 pServiceName = nullptr;
2305 OSL_FAIL("unknown count field!");
2306 break;
2307 }
2308
2309 return pServiceName;
2310 }
2311
2312
2313 // page variable import
2314
2315
XMLPageVarGetFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2316 XMLPageVarGetFieldImportContext::XMLPageVarGetFieldImportContext(
2317 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2318 sal_uInt16 nPrfx, const OUString& sLocalName) :
2319 XMLTextFieldImportContext(rImport, rHlp, "ReferencePageGet",
2320 nPrfx, sLocalName),
2321 sNumberFormat(),
2322 sLetterSync(),
2323 bNumberFormatOK(false)
2324 {
2325 bValid = true;
2326 }
2327
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2328 void XMLPageVarGetFieldImportContext::ProcessAttribute(
2329 sal_uInt16 nAttrToken,
2330 const OUString& sAttrValue )
2331 {
2332 switch (nAttrToken)
2333 {
2334 case XML_TOK_TEXTFIELD_NUM_FORMAT:
2335 sNumberFormat = sAttrValue;
2336 bNumberFormatOK = true;
2337 break;
2338 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
2339 sLetterSync = sAttrValue;
2340 break;
2341 }
2342 }
2343
PrepareField(const Reference<XPropertySet> & xPropertySet)2344 void XMLPageVarGetFieldImportContext::PrepareField(
2345 const Reference<XPropertySet> & xPropertySet)
2346 {
2347 sal_Int16 nNumType;
2348 if( bNumberFormatOK )
2349 {
2350 nNumType= style::NumberingType::ARABIC;
2351 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2352 sNumberFormat,
2353 sLetterSync );
2354 }
2355 else
2356 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2357 xPropertySet->setPropertyValue(sAPI_numbering_type, Any(nNumType));
2358
2359 // display old content (#96657#)
2360 xPropertySet->setPropertyValue( sAPI_current_presentation, Any(GetContent()) );
2361 }
2362
2363
2364 // page variable set fields
2365
2366
XMLPageVarSetFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2367 XMLPageVarSetFieldImportContext::XMLPageVarSetFieldImportContext(
2368 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2369 const OUString& sLocalName) :
2370 XMLTextFieldImportContext(rImport, rHlp, "ReferencePageSet",
2371 nPrfx, sLocalName),
2372 nAdjust(0),
2373 bActive(true)
2374 {
2375 bValid = true;
2376 }
2377
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2378 void XMLPageVarSetFieldImportContext::ProcessAttribute(
2379 sal_uInt16 nAttrToken,
2380 const OUString& sAttrValue )
2381 {
2382 switch (nAttrToken)
2383 {
2384 case XML_TOK_TEXTFIELD_ACTIVE:
2385 {
2386 bool bTmp(false);
2387 if (::sax::Converter::convertBool(bTmp, sAttrValue))
2388 {
2389 bActive = bTmp;
2390 }
2391 break;
2392 }
2393 case XML_TOK_TEXTFIELD_PAGE_ADJUST:
2394 {
2395 sal_Int32 nTmp(0);
2396 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
2397 {
2398 nAdjust = static_cast<sal_Int16>(nTmp);
2399 }
2400 break;
2401 }
2402 default:
2403 break;
2404 }
2405 }
2406
PrepareField(const Reference<XPropertySet> & xPropertySet)2407 void XMLPageVarSetFieldImportContext::PrepareField(
2408 const Reference<XPropertySet> & xPropertySet)
2409 {
2410 xPropertySet->setPropertyValue("On", Any(bActive));
2411 xPropertySet->setPropertyValue(sAPI_offset, Any(nAdjust));
2412 }
2413
2414
2415 // macro fields
2416
2417
XMLMacroFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2418 XMLMacroFieldImportContext::XMLMacroFieldImportContext(
2419 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2420 const OUString& sLocalName) :
2421 XMLTextFieldImportContext(rImport, rHlp, "Macro",
2422 nPrfx, sLocalName),
2423 bDescriptionOK(false)
2424 {
2425 }
2426
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)2427 SvXMLImportContextRef XMLMacroFieldImportContext::CreateChildContext(
2428 sal_uInt16 nPrefix,
2429 const OUString& rLocalName,
2430 const Reference<XAttributeList> & xAttrList )
2431 {
2432 SvXMLImportContextRef xContext;
2433
2434 if ( (nPrefix == XML_NAMESPACE_OFFICE) &&
2435 IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
2436 {
2437 // create events context and remember it!
2438 xContext = new XMLEventsImportContext(
2439 GetImport(), nPrefix, rLocalName );
2440 xEventContext = xContext;
2441 bValid = true;
2442 }
2443 else
2444 xContext = SvXMLImportContext::CreateChildContext(
2445 nPrefix, rLocalName, xAttrList);
2446
2447 return xContext;
2448 }
2449
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2450 void XMLMacroFieldImportContext::ProcessAttribute(
2451 sal_uInt16 nAttrToken,
2452 const OUString& sAttrValue )
2453 {
2454 switch (nAttrToken)
2455 {
2456 case XML_TOK_TEXTFIELD_DESCRIPTION:
2457 sDescription = sAttrValue;
2458 bDescriptionOK = true;
2459 break;
2460 case XML_TOK_TEXTFIELD_NAME:
2461 sMacro = sAttrValue;
2462 bValid = true;
2463 break;
2464 }
2465 }
2466
PrepareField(const Reference<XPropertySet> & xPropertySet)2467 void XMLMacroFieldImportContext::PrepareField(
2468 const Reference<XPropertySet> & xPropertySet)
2469 {
2470 Any aAny;
2471 aAny <<= (bDescriptionOK ? sDescription : GetContent());
2472 xPropertySet->setPropertyValue(sAPI_hint, aAny);
2473
2474 // if we have an events child element, we'll look for the OnClick
2475 // event if not, it may be an old (pre-638i) document. Then, we'll
2476 // have to look at the name attribute.
2477 OUString sMacroName;
2478 OUString sLibraryName;
2479 OUString sScriptURL;
2480
2481 if ( xEventContext.is() )
2482 {
2483 // get event sequence
2484 XMLEventsImportContext* pEvents =
2485 static_cast<XMLEventsImportContext*>(xEventContext.get());
2486 Sequence<PropertyValue> aValues;
2487 pEvents->GetEventSequence( "OnClick", aValues );
2488
2489 for( const auto& rValue : std::as_const(aValues) )
2490 {
2491 if ( rValue.Name == "ScriptType" )
2492 {
2493 // ignore ScriptType
2494 }
2495 else if ( rValue.Name == "Library" )
2496 {
2497 rValue.Value >>= sLibraryName;
2498 }
2499 else if ( rValue.Name == "MacroName" )
2500 {
2501 rValue.Value >>= sMacroName;
2502 }
2503 if ( rValue.Name == "Script" )
2504 {
2505 rValue.Value >>= sScriptURL;
2506 }
2507 }
2508 }
2509 else
2510 {
2511 // disassemble old-style macro-name: Everything before the
2512 // third-last dot is the library
2513 sal_Int32 nPos = sMacro.getLength() + 1; // the loop starts with nPos--
2514 const sal_Unicode* pBuf = sMacro.getStr();
2515 for( sal_Int32 i = 0; (i < 3) && (nPos > 0); i++ )
2516 {
2517 nPos--;
2518 while ( (pBuf[nPos] != '.') && (nPos > 0) )
2519 nPos--;
2520 }
2521
2522 if (nPos > 0)
2523 {
2524 sLibraryName = sMacro.copy(0, nPos);
2525 sMacroName = sMacro.copy(nPos+1);
2526 }
2527 else
2528 sMacroName = sMacro;
2529 }
2530
2531 xPropertySet->setPropertyValue("ScriptURL", Any(sScriptURL));
2532 xPropertySet->setPropertyValue("MacroName", Any(sMacroName));
2533 xPropertySet->setPropertyValue("MacroLibrary", Any(sLibraryName));
2534 }
2535
2536
2537 // reference field import
2538
2539
XMLReferenceFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nToken,sal_uInt16 nPrfx,const OUString & sLocalName)2540 XMLReferenceFieldImportContext::XMLReferenceFieldImportContext(
2541 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2542 sal_uInt16 nToken, sal_uInt16 nPrfx, const OUString& sLocalName)
2543 : XMLTextFieldImportContext(rImport, rHlp, "GetReference", nPrfx, sLocalName)
2544 , nElementToken(nToken)
2545 , nSource(0)
2546 , nType(ReferenceFieldPart::PAGE_DESC)
2547 , bNameOK(false)
2548 , bTypeOK(false)
2549 {
2550 }
2551
2552 static SvXMLEnumMapEntry<sal_uInt16> const lcl_aReferenceTypeTokenMap[] =
2553 {
2554 { XML_PAGE, ReferenceFieldPart::PAGE},
2555 { XML_CHAPTER, ReferenceFieldPart::CHAPTER },
2556 { XML_TEXT, ReferenceFieldPart::TEXT },
2557 { XML_DIRECTION, ReferenceFieldPart::UP_DOWN },
2558 { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
2559 { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION },
2560 { XML_VALUE, ReferenceFieldPart::ONLY_SEQUENCE_NUMBER },
2561 // Core implementation for direct cross-references (#i81002#)
2562 { XML_NUMBER, ReferenceFieldPart::NUMBER },
2563 { XML_NUMBER_NO_SUPERIOR, ReferenceFieldPart::NUMBER_NO_CONTEXT },
2564 { XML_NUMBER_ALL_SUPERIOR, ReferenceFieldPart::NUMBER_FULL_CONTEXT },
2565 { XML_TOKEN_INVALID, 0 }
2566 };
2567
StartElement(const Reference<XAttributeList> & xAttrList)2568 void XMLReferenceFieldImportContext::StartElement(
2569 const Reference<XAttributeList> & xAttrList)
2570 {
2571 bTypeOK = true;
2572 switch (nElementToken)
2573 {
2574 case XML_TOK_TEXT_REFERENCE_REF:
2575 nSource = ReferenceFieldSource::REFERENCE_MARK;
2576 break;
2577 case XML_TOK_TEXT_BOOKMARK_REF:
2578 nSource = ReferenceFieldSource::BOOKMARK;
2579 break;
2580 case XML_TOK_TEXT_NOTE_REF:
2581 nSource = ReferenceFieldSource::FOOTNOTE;
2582 break;
2583 case XML_TOK_TEXT_SEQUENCE_REF:
2584 nSource = ReferenceFieldSource::SEQUENCE_FIELD;
2585 break;
2586 default:
2587 bTypeOK = false;
2588 OSL_FAIL("unknown reference field");
2589 break;
2590 }
2591
2592 XMLTextFieldImportContext::StartElement(xAttrList);
2593 }
2594
2595
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2596 void XMLReferenceFieldImportContext::ProcessAttribute(
2597 sal_uInt16 nAttrToken,
2598 const OUString& sAttrValue )
2599 {
2600 switch (nAttrToken)
2601 {
2602 case XML_TOK_TEXTFIELD_NOTE_CLASS:
2603 if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
2604 nSource = ReferenceFieldSource::ENDNOTE;
2605 break;
2606 case XML_TOK_TEXTFIELD_REF_NAME:
2607 sName = sAttrValue;
2608 bNameOK = true;
2609 break;
2610 case XML_TOK_TEXTFIELD_REFERENCE_FORMAT:
2611 {
2612 sal_uInt16 nToken;
2613 if (SvXMLUnitConverter::convertEnum(nToken, sAttrValue,
2614 lcl_aReferenceTypeTokenMap))
2615 {
2616 nType = nToken;
2617 }
2618
2619 // check for sequence-only-attributes
2620 if ( (XML_TOK_TEXT_SEQUENCE_REF != nElementToken) &&
2621 ( (nType == ReferenceFieldPart::CATEGORY_AND_NUMBER) ||
2622 (nType == ReferenceFieldPart::ONLY_CAPTION) ||
2623 (nType == ReferenceFieldPart::ONLY_SEQUENCE_NUMBER) ) )
2624 {
2625 nType = ReferenceFieldPart::PAGE_DESC;
2626 }
2627
2628 break;
2629 }
2630 case XML_TOK_TEXTFIELD_REFERENCE_LANGUAGE:
2631 sLanguage = sAttrValue;
2632 break;
2633 }
2634
2635 // bValid: we need proper element type and name
2636 bValid = bTypeOK && bNameOK;
2637 }
2638
PrepareField(const Reference<XPropertySet> & xPropertySet)2639 void XMLReferenceFieldImportContext::PrepareField(
2640 const Reference<XPropertySet> & xPropertySet)
2641 {
2642 xPropertySet->setPropertyValue("ReferenceFieldPart", Any(nType));
2643
2644 xPropertySet->setPropertyValue("ReferenceFieldSource", Any(nSource));
2645
2646 xPropertySet->setPropertyValue("ReferenceFieldLanguage", Any(sLanguage));
2647 switch (nElementToken)
2648 {
2649 case XML_TOK_TEXT_REFERENCE_REF:
2650 case XML_TOK_TEXT_BOOKMARK_REF:
2651 xPropertySet->setPropertyValue("SourceName", Any(sName));
2652 break;
2653
2654 case XML_TOK_TEXT_NOTE_REF:
2655 GetImportHelper().ProcessFootnoteReference(sName, xPropertySet);
2656 break;
2657
2658 case XML_TOK_TEXT_SEQUENCE_REF:
2659 GetImportHelper().ProcessSequenceReference(sName, xPropertySet);
2660 break;
2661 }
2662
2663 xPropertySet->setPropertyValue(sAPI_current_presentation, Any(GetContent()));
2664 }
2665
2666
2667 // field declarations container
2668
2669
2670 enum DdeFieldDeclAttrs
2671 {
2672 XML_TOK_DDEFIELD_NAME,
2673 XML_TOK_DDEFIELD_APPLICATION,
2674 XML_TOK_DDEFIELD_TOPIC,
2675 XML_TOK_DDEFIELD_ITEM,
2676 XML_TOK_DDEFIELD_UPDATE
2677 };
2678
2679 static const SvXMLTokenMapEntry aDdeDeclAttrTokenMap[] =
2680 {
2681 { XML_NAMESPACE_OFFICE, XML_NAME, XML_TOK_DDEFIELD_NAME },
2682 { XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, XML_TOK_DDEFIELD_APPLICATION },
2683 { XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, XML_TOK_DDEFIELD_TOPIC },
2684 { XML_NAMESPACE_OFFICE, XML_DDE_ITEM, XML_TOK_DDEFIELD_ITEM },
2685 { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE, XML_TOK_DDEFIELD_UPDATE },
2686 XML_TOKEN_MAP_END
2687 };
2688
2689
XMLDdeFieldDeclsImportContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & sLocalName)2690 XMLDdeFieldDeclsImportContext::XMLDdeFieldDeclsImportContext(
2691 SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& sLocalName) :
2692 SvXMLImportContext(rImport, nPrfx, sLocalName)
2693 {
2694 }
2695
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)2696 SvXMLImportContextRef XMLDdeFieldDeclsImportContext::CreateChildContext(
2697 sal_uInt16 nPrefix,
2698 const OUString& rLocalName,
2699 const Reference<XAttributeList> & xAttrList )
2700 {
2701 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
2702 (IsXMLToken(rLocalName, XML_DDE_CONNECTION_DECL)) )
2703 {
2704 static const SvXMLTokenMap aTokenMap(aDdeDeclAttrTokenMap);
2705 return new XMLDdeFieldDeclImportContext(GetImport(), nPrefix,
2706 rLocalName, aTokenMap);
2707 }
2708 else
2709 {
2710 return SvXMLImportContext::CreateChildContext(nPrefix,
2711 rLocalName,
2712 xAttrList);
2713 }
2714 }
2715
2716
2717 // import dde field declaration
2718
2719
XMLDdeFieldDeclImportContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & sLocalName,const SvXMLTokenMap & rMap)2720 XMLDdeFieldDeclImportContext::XMLDdeFieldDeclImportContext(
2721 SvXMLImport& rImport, sal_uInt16 nPrfx,
2722 const OUString& sLocalName, const SvXMLTokenMap& rMap)
2723 : SvXMLImportContext(rImport, nPrfx, sLocalName)
2724 , rTokenMap(rMap)
2725 {
2726 DBG_ASSERT(XML_NAMESPACE_TEXT == nPrfx, "wrong prefix");
2727 DBG_ASSERT(IsXMLToken(sLocalName, XML_DDE_CONNECTION_DECL), "wrong name");
2728 }
2729
StartElement(const Reference<XAttributeList> & xAttrList)2730 void XMLDdeFieldDeclImportContext::StartElement(
2731 const Reference<XAttributeList> & xAttrList)
2732 {
2733 OUString sName;
2734 OUString sCommandApplication;
2735 OUString sCommandTopic;
2736 OUString sCommandItem;
2737
2738 bool bUpdate = false;
2739 bool bNameOK = false;
2740 bool bCommandApplicationOK = false;
2741 bool bCommandTopicOK = false;
2742 bool bCommandItemOK = false;
2743
2744 // process attributes
2745 sal_Int16 nLength = xAttrList->getLength();
2746 for(sal_Int16 i=0; i<nLength; i++)
2747 {
2748
2749 OUString sLocalName;
2750 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
2751 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
2752
2753 switch (rTokenMap.Get(nPrefix, sLocalName))
2754 {
2755 case XML_TOK_DDEFIELD_NAME:
2756 sName = xAttrList->getValueByIndex(i);
2757 bNameOK = true;
2758 break;
2759 case XML_TOK_DDEFIELD_APPLICATION:
2760 sCommandApplication = xAttrList->getValueByIndex(i);
2761 bCommandApplicationOK = true;
2762 break;
2763 case XML_TOK_DDEFIELD_TOPIC:
2764 sCommandTopic = xAttrList->getValueByIndex(i);
2765 bCommandTopicOK = true;
2766 break;
2767 case XML_TOK_DDEFIELD_ITEM:
2768 sCommandItem = xAttrList->getValueByIndex(i);
2769 bCommandItemOK = true;
2770 break;
2771 case XML_TOK_DDEFIELD_UPDATE:
2772 {
2773 bool bTmp(false);
2774 if (::sax::Converter::convertBool(
2775 bTmp, xAttrList->getValueByIndex(i)) )
2776 {
2777 bUpdate = bTmp;
2778 }
2779 break;
2780 }
2781 }
2782 }
2783
2784 // valid data?
2785 if (bNameOK && bCommandApplicationOK && bCommandTopicOK && bCommandItemOK)
2786 {
2787 // create DDE TextFieldMaster
2788 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),
2789 UNO_QUERY);
2790 if( xFactory.is() )
2791 {
2792 /* #i6432# There might be multiple occurrences of one DDE
2793 declaration if it is used in more than one of
2794 header/footer/body. createInstance will throw an exception if we
2795 try to create the second, third, etc. instance of such a
2796 declaration. Thus we ignore the exception. Otherwise this will
2797 lead to an unloadable document. */
2798 try
2799 {
2800 Reference<XInterface> xIfc =
2801 xFactory->createInstance(OUStringLiteral(sAPI_fieldmaster_prefix) + sAPI_dde);
2802 if( xIfc.is() )
2803 {
2804 Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
2805 if (xPropSet.is() &&
2806 xPropSet->getPropertySetInfo()->hasPropertyByName(
2807 "DDECommandType"))
2808 {
2809 xPropSet->setPropertyValue(sAPI_name, Any(sName));
2810
2811 xPropSet->setPropertyValue("DDECommandType", Any(sCommandApplication));
2812
2813 xPropSet->setPropertyValue("DDECommandFile", Any(sCommandTopic));
2814
2815 xPropSet->setPropertyValue("DDECommandElement",
2816 Any(sCommandItem));
2817
2818 xPropSet->setPropertyValue("IsAutomaticUpdate",
2819 Any(bUpdate));
2820 }
2821 // else: ignore (can't get XPropertySet, or DDE
2822 // properties are not supported)
2823 }
2824 // else: ignore
2825 }
2826 catch (const Exception&)
2827 {
2828 //ignore
2829 }
2830 }
2831 // else: ignore
2832 }
2833 // else: ignore
2834 }
2835
2836
2837 // DDE field import
2838
2839
XMLDdeFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2840 XMLDdeFieldImportContext::XMLDdeFieldImportContext(
2841 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2842 sal_uInt16 nPrfx, const OUString& sLocalName) :
2843 XMLTextFieldImportContext(rImport, rHlp, sAPI_dde,
2844 nPrfx, sLocalName),
2845 sName()
2846 ,sPropertyContent(sAPI_content)
2847 {
2848 }
2849
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2850 void XMLDdeFieldImportContext::ProcessAttribute(
2851 sal_uInt16 nAttrToken,
2852 const OUString& sAttrValue )
2853 {
2854 if (XML_TOK_TEXTFIELD_CONNECTION_NAME == nAttrToken)
2855 {
2856 sName = sAttrValue;
2857 bValid = true;
2858 }
2859 }
2860
EndElement()2861 void XMLDdeFieldImportContext::EndElement()
2862 {
2863 if (bValid)
2864 {
2865 // find master
2866 OUStringBuffer sBuf;
2867 sBuf.append(sAPI_fieldmaster_prefix);
2868 sBuf.append(sAPI_dde);
2869 sBuf.append('.');
2870 sBuf.append(sName);
2871 OUString sMasterName = sBuf.makeStringAndClear();
2872
2873 Reference<XTextFieldsSupplier> xTextFieldsSupp(GetImport().GetModel(),
2874 UNO_QUERY);
2875 Reference<container::XNameAccess> xFieldMasterNameAccess =
2876 xTextFieldsSupp->getTextFieldMasters();
2877
2878 if (xFieldMasterNameAccess->hasByName(sMasterName))
2879 {
2880 Reference<XPropertySet> xMaster;
2881 Any aAny = xFieldMasterNameAccess->getByName(sMasterName);
2882 aAny >>= xMaster;
2883 //apply the content to the master
2884 xMaster->setPropertyValue( sPropertyContent, uno::makeAny( GetContent()));
2885 // master exists: create text field and attach
2886 Reference<XPropertySet> xField;
2887 sBuf.append(sAPI_textfield_prefix);
2888 sBuf.append(sAPI_dde);
2889 if (CreateField(xField, sBuf.makeStringAndClear()))
2890 {
2891 Reference<XDependentTextField> xDepTextField(xField,UNO_QUERY);
2892 xDepTextField->attachTextFieldMaster(xMaster);
2893
2894 // attach field to document
2895 Reference<XTextContent> xTextContent(xField, UNO_QUERY);
2896 if (xTextContent.is())
2897 {
2898 GetImportHelper().InsertTextContent(xTextContent);
2899
2900 // we're lucky. nothing else to prepare.
2901 }
2902 // else: fail, because text content could not be created
2903 }
2904 // else: fail, because field could not be created
2905 }
2906 // else: fail, because no master was found (faulty document?!)
2907 }
2908 // not valid: ignore
2909 }
2910
PrepareField(const Reference<XPropertySet> &)2911 void XMLDdeFieldImportContext::PrepareField(
2912 const Reference<XPropertySet> &)
2913 {
2914 // empty, since not needed.
2915 }
2916
2917
2918 // sheet name fields
2919
2920
XMLSheetNameImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2921 XMLSheetNameImportContext::XMLSheetNameImportContext(
2922 SvXMLImport& rImport,
2923 XMLTextImportHelper& rHlp,
2924 sal_uInt16 nPrfx,
2925 const OUString& sLocalName) :
2926 XMLTextFieldImportContext(rImport, rHlp, "SheetName",
2927 nPrfx, sLocalName)
2928 {
2929 bValid = true; // always valid!
2930 }
2931
ProcessAttribute(sal_uInt16,const OUString &)2932 void XMLSheetNameImportContext::ProcessAttribute(
2933 sal_uInt16,
2934 const OUString& )
2935 {
2936 // no attributes -> nothing to be done
2937 }
2938
PrepareField(const Reference<XPropertySet> &)2939 void XMLSheetNameImportContext::PrepareField(
2940 const Reference<XPropertySet> &)
2941 {
2942 // no attributes -> nothing to be done
2943 }
2944
2945 /** import page|slide name fields (<text:page-name>) */
2946
XMLPageNameFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2947 XMLPageNameFieldImportContext::XMLPageNameFieldImportContext(
2948 SvXMLImport& rImport, /// XML Import
2949 XMLTextImportHelper& rHlp, /// Text import helper
2950 sal_uInt16 nPrfx, /// namespace prefix
2951 const OUString& sLocalName) /// element name w/o prefix
2952 : XMLTextFieldImportContext(rImport, rHlp, "PageName", nPrfx, sLocalName )
2953 {
2954 bValid = true;
2955 }
2956
2957 /// process attribute values
ProcessAttribute(sal_uInt16,const OUString &)2958 void XMLPageNameFieldImportContext::ProcessAttribute( sal_uInt16,
2959 const OUString& )
2960 {
2961 }
2962
2963 /// prepare XTextField for insertion into document
PrepareField(const css::uno::Reference<css::beans::XPropertySet> &)2964 void XMLPageNameFieldImportContext::PrepareField(
2965 const css::uno::Reference<css::beans::XPropertySet> &)
2966 {
2967 }
2968
2969
2970 // URL fields (Calc, Impress, Draw)
2971
2972
XMLUrlFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)2973 XMLUrlFieldImportContext::XMLUrlFieldImportContext(
2974 SvXMLImport& rImport,
2975 XMLTextImportHelper& rHlp,
2976 sal_uInt16 nPrfx,
2977 const OUString& sLocalName) :
2978 XMLTextFieldImportContext(rImport, rHlp, sAPI_url,
2979 nPrfx, sLocalName),
2980 bFrameOK(false)
2981 {
2982 }
2983
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)2984 void XMLUrlFieldImportContext::ProcessAttribute(
2985 sal_uInt16 nAttrToken,
2986 const OUString& sAttrValue )
2987 {
2988 switch (nAttrToken)
2989 {
2990 case XML_TOK_TEXTFIELD_HREF:
2991 sURL = GetImport().GetAbsoluteReference( sAttrValue );
2992 bValid = true;
2993 break;
2994 case XML_TOK_TEXTFIELD_TARGET_FRAME:
2995 sFrame = sAttrValue;
2996 bFrameOK = true;
2997 break;
2998 default:
2999 // ignore
3000 break;
3001 }
3002 }
3003
PrepareField(const Reference<XPropertySet> & xPropertySet)3004 void XMLUrlFieldImportContext::PrepareField(
3005 const Reference<XPropertySet> & xPropertySet)
3006 {
3007 xPropertySet->setPropertyValue(sAPI_url, Any(sURL));
3008
3009 if (bFrameOK)
3010 {
3011 xPropertySet->setPropertyValue("TargetFrame", Any(sFrame));
3012 }
3013
3014 xPropertySet->setPropertyValue("Representation", Any(GetContent()));
3015 }
3016
3017
XMLBibliographyFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)3018 XMLBibliographyFieldImportContext::XMLBibliographyFieldImportContext(
3019 SvXMLImport& rImport,
3020 XMLTextImportHelper& rHlp,
3021 sal_uInt16 nPrfx,
3022 const OUString& sLocalName) :
3023 XMLTextFieldImportContext(rImport, rHlp, "Bibliography",
3024 nPrfx, sLocalName),
3025 aValues()
3026 {
3027 bValid = true;
3028 }
3029
3030 // TODO: this is the same map as is used in the text field export
3031 static SvXMLEnumMapEntry<sal_uInt16> const aBibliographyDataTypeMap[] =
3032 {
3033 { XML_ARTICLE, BibliographyDataType::ARTICLE },
3034 { XML_BOOK, BibliographyDataType::BOOK },
3035 { XML_BOOKLET, BibliographyDataType::BOOKLET },
3036 { XML_CONFERENCE, BibliographyDataType::CONFERENCE },
3037 { XML_CUSTOM1, BibliographyDataType::CUSTOM1 },
3038 { XML_CUSTOM2, BibliographyDataType::CUSTOM2 },
3039 { XML_CUSTOM3, BibliographyDataType::CUSTOM3 },
3040 { XML_CUSTOM4, BibliographyDataType::CUSTOM4 },
3041 { XML_CUSTOM5, BibliographyDataType::CUSTOM5 },
3042 { XML_EMAIL, BibliographyDataType::EMAIL },
3043 { XML_INBOOK, BibliographyDataType::INBOOK },
3044 { XML_INCOLLECTION, BibliographyDataType::INCOLLECTION },
3045 { XML_INPROCEEDINGS, BibliographyDataType::INPROCEEDINGS },
3046 { XML_JOURNAL, BibliographyDataType::JOURNAL },
3047 { XML_MANUAL, BibliographyDataType::MANUAL },
3048 { XML_MASTERSTHESIS, BibliographyDataType::MASTERSTHESIS },
3049 { XML_MISC, BibliographyDataType::MISC },
3050 { XML_PHDTHESIS, BibliographyDataType::PHDTHESIS },
3051 { XML_PROCEEDINGS, BibliographyDataType::PROCEEDINGS },
3052 { XML_TECHREPORT, BibliographyDataType::TECHREPORT },
3053 { XML_UNPUBLISHED, BibliographyDataType::UNPUBLISHED },
3054 { XML_WWW, BibliographyDataType::WWW },
3055 { XML_TOKEN_INVALID, 0 }
3056 };
3057
3058
3059 // we'll process attributes on our own and for fit the standard
3060 // textfield mechanism, because our attributes have zero overlap with
3061 // all the other textfields.
StartElement(const Reference<XAttributeList> & xAttrList)3062 void XMLBibliographyFieldImportContext::StartElement(
3063 const Reference<XAttributeList> & xAttrList)
3064 {
3065 // iterate over attributes
3066 sal_Int16 nLength = xAttrList->getLength();
3067 for(sal_Int16 i=0; i<nLength; i++) {
3068
3069 OUString sLocalName;
3070 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
3071 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
3072
3073 if (nPrefix == XML_NAMESPACE_TEXT)
3074 {
3075 PropertyValue aValue;
3076 aValue.Name = OUString::createFromAscii(
3077 MapBibliographyFieldName(sLocalName));
3078 Any aAny;
3079
3080 // special treatment for bibliography type
3081 // biblio vs bibilio: #96658#; also read old documents
3082 if (IsXMLToken(sLocalName, XML_BIBILIOGRAPHIC_TYPE) ||
3083 IsXMLToken(sLocalName, XML_BIBLIOGRAPHY_TYPE) )
3084 {
3085 sal_uInt16 nTmp;
3086 if (SvXMLUnitConverter::convertEnum(
3087 nTmp, xAttrList->getValueByIndex(i),
3088 aBibliographyDataTypeMap))
3089 {
3090 aAny <<= static_cast<sal_Int16>(nTmp);
3091 aValue.Value = aAny;
3092
3093 aValues.push_back(aValue);
3094 }
3095 }
3096 else
3097 {
3098 aAny <<= xAttrList->getValueByIndex(i);
3099 aValue.Value = aAny;
3100
3101 aValues.push_back(aValue);
3102 }
3103 }
3104 // else: unknown namespace -> ignore
3105 }
3106 }
3107
ProcessAttribute(sal_uInt16,const OUString &)3108 void XMLBibliographyFieldImportContext::ProcessAttribute(
3109 sal_uInt16,
3110 const OUString& )
3111 {
3112 // attributes are handled in StartElement
3113 OSL_FAIL("This should not have happened.");
3114 }
3115
3116
PrepareField(const Reference<XPropertySet> & xPropertySet)3117 void XMLBibliographyFieldImportContext::PrepareField(
3118 const Reference<XPropertySet> & xPropertySet)
3119 {
3120 // convert vector into sequence
3121 sal_Int32 nCount = aValues.size();
3122 Sequence<PropertyValue> aValueSequence(nCount);
3123 for(sal_Int32 i = 0; i < nCount; i++)
3124 {
3125 aValueSequence[i] = aValues[i];
3126 }
3127
3128 // set sequence
3129 xPropertySet->setPropertyValue("Fields", Any(aValueSequence));
3130 }
3131
MapBibliographyFieldName(const OUString & sName)3132 const sal_Char* XMLBibliographyFieldImportContext::MapBibliographyFieldName(
3133 const OUString& sName)
3134 {
3135 const sal_Char* pName = nullptr;
3136
3137 if (IsXMLToken(sName, XML_IDENTIFIER))
3138 {
3139 pName = "Identifier";
3140 }
3141 else if (IsXMLToken(sName, XML_BIBILIOGRAPHIC_TYPE) ||
3142 IsXMLToken(sName, XML_BIBLIOGRAPHY_TYPE) )
3143 {
3144 // biblio... vs bibilio...: #96658#: also read old documents
3145 pName = "BibiliographicType";
3146 }
3147 else if (IsXMLToken(sName, XML_ADDRESS))
3148 {
3149 pName = "Address";
3150 }
3151 else if (IsXMLToken(sName, XML_ANNOTE))
3152 {
3153 pName = "Annote";
3154 }
3155 else if (IsXMLToken(sName, XML_AUTHOR))
3156 {
3157 pName = "Author";
3158 }
3159 else if (IsXMLToken(sName, XML_BOOKTITLE))
3160 {
3161 pName = "Booktitle";
3162 }
3163 else if (IsXMLToken(sName, XML_CHAPTER))
3164 {
3165 pName = "Chapter";
3166 }
3167 else if (IsXMLToken(sName, XML_EDITION))
3168 {
3169 pName = "Edition";
3170 }
3171 else if (IsXMLToken(sName, XML_EDITOR))
3172 {
3173 pName = "Editor";
3174 }
3175 else if (IsXMLToken(sName, XML_HOWPUBLISHED))
3176 {
3177 pName = "Howpublished";
3178 }
3179 else if (IsXMLToken(sName, XML_INSTITUTION))
3180 {
3181 pName = "Institution";
3182 }
3183 else if (IsXMLToken(sName, XML_JOURNAL))
3184 {
3185 pName = "Journal";
3186 }
3187 else if (IsXMLToken(sName, XML_MONTH))
3188 {
3189 pName = "Month";
3190 }
3191 else if (IsXMLToken(sName, XML_NOTE))
3192 {
3193 pName = "Note";
3194 }
3195 else if (IsXMLToken(sName, XML_NUMBER))
3196 {
3197 pName = "Number";
3198 }
3199 else if (IsXMLToken(sName, XML_ORGANIZATIONS))
3200 {
3201 pName = "Organizations";
3202 }
3203 else if (IsXMLToken(sName, XML_PAGES))
3204 {
3205 pName = "Pages";
3206 }
3207 else if (IsXMLToken(sName, XML_PUBLISHER))
3208 {
3209 pName = "Publisher";
3210 }
3211 else if (IsXMLToken(sName, XML_SCHOOL))
3212 {
3213 pName = "School";
3214 }
3215 else if (IsXMLToken(sName, XML_SERIES))
3216 {
3217 pName = "Series";
3218 }
3219 else if (IsXMLToken(sName, XML_TITLE))
3220 {
3221 pName = "Title";
3222 }
3223 else if (IsXMLToken(sName, XML_REPORT_TYPE))
3224 {
3225 pName = "Report_Type";
3226 }
3227 else if (IsXMLToken(sName, XML_VOLUME))
3228 {
3229 pName = "Volume";
3230 }
3231 else if (IsXMLToken(sName, XML_YEAR))
3232 {
3233 pName = "Year";
3234 }
3235 else if (IsXMLToken(sName, XML_URL))
3236 {
3237 pName = "URL";
3238 }
3239 else if (IsXMLToken(sName, XML_CUSTOM1))
3240 {
3241 pName = "Custom1";
3242 }
3243 else if (IsXMLToken(sName, XML_CUSTOM2))
3244 {
3245 pName = "Custom2";
3246 }
3247 else if (IsXMLToken(sName, XML_CUSTOM3))
3248 {
3249 pName = "Custom3";
3250 }
3251 else if (IsXMLToken(sName, XML_CUSTOM4))
3252 {
3253 pName = "Custom4";
3254 }
3255 else if (IsXMLToken(sName, XML_CUSTOM5))
3256 {
3257 pName = "Custom5";
3258 }
3259 else if (IsXMLToken(sName, XML_ISBN))
3260 {
3261 pName = "ISBN";
3262 }
3263 else
3264 {
3265 OSL_FAIL("Unknown bibliography info data");
3266 pName = nullptr;
3267 }
3268
3269 return pName;
3270 }
3271
3272
3273 // Annotation Field
3274
3275
XMLAnnotationImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nToken,sal_uInt16 nPrfx,const OUString & sLocalName)3276 XMLAnnotationImportContext::XMLAnnotationImportContext(
3277 SvXMLImport& rImport,
3278 XMLTextImportHelper& rHlp,
3279 sal_uInt16 nToken,
3280 sal_uInt16 nPrfx,
3281 const OUString& sLocalName) :
3282 XMLTextFieldImportContext(rImport, rHlp, "Annotation",
3283 nPrfx, sLocalName),
3284 m_nToken(nToken)
3285 {
3286 bValid = true;
3287
3288 // remember old list item and block (#91964#) and reset them
3289 // for the text frame
3290 // do this in the constructor, not in CreateChildContext (#i93392#)
3291 GetImport().GetTextImport()->PushListContext();
3292 }
3293
ProcessAttribute(sal_uInt16 nToken,const OUString & rValue)3294 void XMLAnnotationImportContext::ProcessAttribute(
3295 sal_uInt16 nToken,
3296 const OUString& rValue )
3297 {
3298 if (nToken == XML_TOK_TEXT_NAME)
3299 aName = rValue;
3300 if (nToken == XML_TOK_TEXT_RESOLVED)
3301 aResolved = rValue;
3302 }
3303
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)3304 SvXMLImportContextRef XMLAnnotationImportContext::CreateChildContext(
3305 sal_uInt16 nPrefix,
3306 const OUString& rLocalName,
3307 const Reference<XAttributeList >& xAttrList )
3308 {
3309 SvXMLImportContext *pContext = nullptr;
3310 if( XML_NAMESPACE_DC == nPrefix )
3311 {
3312 if( IsXMLToken( rLocalName, XML_CREATOR ) )
3313 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix,
3314 rLocalName, aAuthorBuffer);
3315 else if( IsXMLToken( rLocalName, XML_DATE ) )
3316 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix,
3317 rLocalName, aDateBuffer);
3318 }
3319 else if (((XML_NAMESPACE_TEXT == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix)
3320 && IsXMLToken(rLocalName, XML_SENDER_INITIALS))
3321 || (XML_NAMESPACE_META == nPrefix
3322 && IsXMLToken(rLocalName, XML_CREATOR_INITIALS)))
3323 {
3324 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix,
3325 rLocalName, aInitialsBuffer);
3326 }
3327
3328 if( !pContext )
3329 {
3330 try
3331 {
3332 bool bOK = true;
3333 if ( !mxField.is() )
3334 bOK = CreateField( mxField, sServicePrefix + GetServiceName() );
3335 if (bOK)
3336 {
3337 Any aAny = mxField->getPropertyValue( "TextRange" );
3338 Reference< XText > xText;
3339 aAny >>= xText;
3340 if( xText.is() )
3341 {
3342 rtl::Reference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport();
3343 if( !mxCursor.is() )
3344 {
3345 mxOldCursor = xTxtImport->GetCursor();
3346 mxCursor = xText->createTextCursor();
3347 }
3348
3349 if( mxCursor.is() )
3350 {
3351 xTxtImport->SetCursor( mxCursor );
3352 pContext = xTxtImport->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
3353 }
3354 }
3355 }
3356 }
3357 catch (const Exception&)
3358 {
3359 }
3360
3361 if( !pContext )
3362 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, aTextBuffer);
3363 }
3364
3365 return pContext;
3366 }
3367
EndElement()3368 void XMLAnnotationImportContext::EndElement()
3369 {
3370 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
3371 if( mxCursor.is() )
3372 {
3373 // delete addition newline
3374 mxCursor->gotoEnd( false );
3375 mxCursor->goLeft( 1, true );
3376 mxCursor->setString( "" );
3377
3378 // reset cursor
3379 GetImport().GetTextImport()->ResetCursor();
3380 }
3381
3382 if( mxOldCursor.is() )
3383 GetImport().GetTextImport()->SetCursor( mxOldCursor );
3384
3385 // reinstall old list item #91964#
3386 GetImport().GetTextImport()->PopListContext();
3387
3388 if ( bValid )
3389 {
3390 if ( m_nToken == XML_TOK_TEXT_ANNOTATION_END )
3391 {
3392 // Search for a previous annotation with the same name.
3393 uno::Reference< text::XTextContent > xPrevField;
3394 {
3395 Reference<XTextFieldsSupplier> xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY);
3396 uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
3397 uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
3398 while (xFields->hasMoreElements())
3399 {
3400 uno::Reference<beans::XPropertySet> xCurrField(xFields->nextElement(), uno::UNO_QUERY);
3401 uno::Reference<beans::XPropertySetInfo> const xInfo(
3402 xCurrField->getPropertySetInfo());
3403 if (xInfo->hasPropertyByName(sAPI_name))
3404 {
3405 OUString aFieldName;
3406 xCurrField->getPropertyValue(sAPI_name) >>= aFieldName;
3407 if (aFieldName == aName)
3408 {
3409 xPrevField.set( xCurrField, uno::UNO_QUERY );
3410 break;
3411 }
3412 }
3413 }
3414 }
3415 if ( xPrevField.is() )
3416 {
3417 // So we are ending a previous annotation,
3418 // let's create a text range covering the old and the current position.
3419 uno::Reference<text::XText> xText = GetImportHelper().GetText();
3420 uno::Reference<text::XTextCursor> xCursor =
3421 xText->createTextCursorByRange(GetImportHelper().GetCursorAsRange());
3422 xCursor->gotoRange(xPrevField->getAnchor(), true);
3423
3424 xText->insertTextContent(xCursor, xPrevField, !xCursor->isCollapsed());
3425 }
3426 }
3427 else
3428 {
3429 if ( mxField.is() || CreateField( mxField, sServicePrefix + GetServiceName() ) )
3430 {
3431 // set field properties
3432 PrepareField( mxField );
3433
3434 // attach field to document
3435 Reference < XTextContent > xTextContent( mxField, UNO_QUERY );
3436
3437 // workaround for #80606#
3438 try
3439 {
3440 GetImportHelper().InsertTextContent( xTextContent );
3441 }
3442 catch (const lang::IllegalArgumentException&)
3443 {
3444 // ignore
3445 }
3446 }
3447 }
3448 }
3449 else
3450 GetImportHelper().InsertString(GetContent());
3451 }
3452
PrepareField(const Reference<XPropertySet> & xPropertySet)3453 void XMLAnnotationImportContext::PrepareField(
3454 const Reference<XPropertySet> & xPropertySet )
3455 {
3456 // import (possibly empty) author
3457 OUString sAuthor( aAuthorBuffer.makeStringAndClear() );
3458 xPropertySet->setPropertyValue(sAPI_author, makeAny(sAuthor));
3459
3460 // import (possibly empty) initials
3461 OUString sInitials( aInitialsBuffer.makeStringAndClear() );
3462 xPropertySet->setPropertyValue("Initials", makeAny(sInitials));
3463
3464 //import resolved flag
3465 bool bTmp(false);
3466 (void)::sax::Converter::convertBool(bTmp, aResolved);
3467 xPropertySet->setPropertyValue("Resolved", makeAny(bTmp));
3468
3469 util::DateTime aDateTime;
3470 if (::sax::Converter::parseDateTime(aDateTime,
3471 aDateBuffer.makeStringAndClear()))
3472 {
3473 /*
3474 Date aDate;
3475 aDate.Year = aDateTime.Year;
3476 aDate.Month = aDateTime.Month;
3477 aDate.Day = aDateTime.Day;
3478 xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDate));
3479 */
3480 // why is there no UNO_NAME_DATE_TIME, but only UNO_NAME_DATE_TIME_VALUE?
3481 xPropertySet->setPropertyValue(sAPI_date_time_value, makeAny(aDateTime));
3482 }
3483
3484 OUString sBuffer = aTextBuffer.makeStringAndClear();
3485 if ( sBuffer.getLength() )
3486 {
3487 // delete last paragraph mark (if necessary)
3488 if (sal_Char(0x0a) == sBuffer[sBuffer.getLength()-1])
3489 sBuffer = sBuffer.copy(0, sBuffer.getLength()-1);
3490 xPropertySet->setPropertyValue(sAPI_content, makeAny(sBuffer));
3491 }
3492
3493 if (!aName.isEmpty())
3494 xPropertySet->setPropertyValue(sAPI_name, makeAny(aName));
3495 }
3496
3497
3498 // script field
3499
3500
XMLScriptImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)3501 XMLScriptImportContext::XMLScriptImportContext(
3502 SvXMLImport& rImport,
3503 XMLTextImportHelper& rHlp,
3504 sal_uInt16 nPrfx,
3505 const OUString& sLocalName)
3506 : XMLTextFieldImportContext(rImport, rHlp, "Script", nPrfx, sLocalName)
3507 , bContentOK(false)
3508 {
3509 }
3510
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)3511 void XMLScriptImportContext::ProcessAttribute(
3512 sal_uInt16 nAttrToken,
3513 const OUString& sAttrValue )
3514 {
3515 switch (nAttrToken)
3516 {
3517 case XML_TOK_TEXTFIELD_HREF:
3518 sContent = GetImport().GetAbsoluteReference( sAttrValue );
3519 bContentOK = true;
3520 break;
3521
3522 case XML_TOK_TEXTFIELD_LANGUAGE:
3523 sScriptType = sAttrValue;
3524 break;
3525
3526 default:
3527 // ignore
3528 break;
3529 }
3530
3531 // always valid (even without ScriptType; cf- #96531#)
3532 bValid = true;
3533 }
3534
PrepareField(const Reference<XPropertySet> & xPropertySet)3535 void XMLScriptImportContext::PrepareField(
3536 const Reference<XPropertySet> & xPropertySet)
3537 {
3538 // if href attribute was present, we use it. Else we use element content
3539 if (! bContentOK)
3540 {
3541 sContent = GetContent();
3542 }
3543 xPropertySet->setPropertyValue(sAPI_content, Any(sContent));
3544
3545 // URL or script text? We use URL if we have an href-attribute
3546 xPropertySet->setPropertyValue("URLContent", Any(bContentOK));
3547
3548 xPropertySet->setPropertyValue("ScriptType", Any(sScriptType));
3549 }
3550
3551
3552 // measure field
3553
3554
XMLMeasureFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)3555 XMLMeasureFieldImportContext::XMLMeasureFieldImportContext(
3556 SvXMLImport& rImport,
3557 XMLTextImportHelper& rHlp,
3558 sal_uInt16 nPrfx,
3559 const OUString& sLocalName) :
3560 XMLTextFieldImportContext(rImport, rHlp, "Measure",
3561 nPrfx, sLocalName),
3562 mnKind( 0 )
3563 {
3564 }
3565
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)3566 void XMLMeasureFieldImportContext::ProcessAttribute(
3567 sal_uInt16 nAttrToken,
3568 const OUString& sAttrValue )
3569 {
3570 switch (nAttrToken)
3571 {
3572 case XML_TOK_TEXTFIELD_MEASURE_KIND:
3573 if( IsXMLToken( sAttrValue, XML_VALUE ) )
3574 {
3575 mnKind = 0; bValid = true;
3576 }
3577 else if( IsXMLToken( sAttrValue, XML_UNIT ) )
3578 {
3579 mnKind = 1; bValid = true;
3580 }
3581 else if( IsXMLToken( sAttrValue, XML_GAP ) )
3582 {
3583 mnKind = 2; bValid = true;
3584 }
3585 break;
3586 }
3587 }
3588
PrepareField(const Reference<XPropertySet> & xPropertySet)3589 void XMLMeasureFieldImportContext::PrepareField(
3590 const Reference<XPropertySet> & xPropertySet)
3591 {
3592 xPropertySet->setPropertyValue("Kind", Any(mnKind));
3593 }
3594
3595
3596 // dropdown field
3597
3598
XMLDropDownFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)3599 XMLDropDownFieldImportContext::XMLDropDownFieldImportContext(
3600 SvXMLImport& rImport,
3601 XMLTextImportHelper& rHlp,
3602 sal_uInt16 nPrfx,
3603 const OUString& sLocalName) :
3604 XMLTextFieldImportContext( rImport, rHlp, "DropDown",
3605 nPrfx, sLocalName ),
3606 aLabels(),
3607 sName(),
3608 nSelected( -1 ),
3609 bNameOK( false ),
3610 bHelpOK(false),
3611 bHintOK(false)
3612 {
3613 bValid = true;
3614 }
3615
lcl_ProcessLabel(const SvXMLImport & rImport,const Reference<XAttributeList> & xAttrList,OUString & rLabel,bool & rIsSelected)3616 static bool lcl_ProcessLabel( const SvXMLImport& rImport,
3617 const Reference<XAttributeList>& xAttrList,
3618 OUString& rLabel,
3619 bool& rIsSelected )
3620 {
3621 bool bValid = false;
3622 sal_Int16 nLength = xAttrList->getLength();
3623 for( sal_Int16 n = 0; n < nLength; n++ )
3624 {
3625 OUString sLocalName;
3626 sal_uInt16 nPrefix = rImport.GetNamespaceMap().
3627 GetKeyByAttrName( xAttrList->getNameByIndex(n), &sLocalName );
3628 OUString sValue = xAttrList->getValueByIndex(n);
3629
3630 if( nPrefix == XML_NAMESPACE_TEXT )
3631 {
3632 if( IsXMLToken( sLocalName, XML_VALUE ) )
3633 {
3634 rLabel = sValue;
3635 bValid = true;
3636 }
3637 else if( IsXMLToken( sLocalName, XML_CURRENT_SELECTED ) )
3638 {
3639 bool bTmp(false);
3640 if (::sax::Converter::convertBool( bTmp, sValue ))
3641 rIsSelected = bTmp;
3642 }
3643 }
3644 }
3645 return bValid;
3646 }
3647
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)3648 SvXMLImportContextRef XMLDropDownFieldImportContext::CreateChildContext(
3649 sal_uInt16 nPrefix,
3650 const OUString& rLocalName,
3651 const Reference<XAttributeList>& xAttrList )
3652 {
3653 if( nPrefix == XML_NAMESPACE_TEXT &&
3654 IsXMLToken( rLocalName, XML_LABEL ) )
3655 {
3656 OUString sLabel;
3657 bool bIsSelected = false;
3658 if( lcl_ProcessLabel( GetImport(), xAttrList, sLabel, bIsSelected ) )
3659 {
3660 if( bIsSelected )
3661 nSelected = static_cast<sal_Int32>( aLabels.size() );
3662 aLabels.push_back( sLabel );
3663 }
3664 }
3665 return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
3666 }
3667
ProcessAttribute(sal_uInt16 nAttrToken,const OUString & sAttrValue)3668 void XMLDropDownFieldImportContext::ProcessAttribute(
3669 sal_uInt16 nAttrToken,
3670 const OUString& sAttrValue )
3671 {
3672 if( nAttrToken == XML_TOK_TEXTFIELD_NAME )
3673 {
3674 sName = sAttrValue;
3675 bNameOK = true;
3676 }
3677 else if (nAttrToken == XML_TOK_TEXTFIELD_HELP)
3678 {
3679 sHelp = sAttrValue;
3680 bHelpOK = true;
3681 }
3682 else if (nAttrToken == XML_TOK_TEXTFIELD_HINT)
3683 {
3684 sHint = sAttrValue;
3685 bHintOK = true;
3686 }
3687 }
3688
PrepareField(const Reference<XPropertySet> & xPropertySet)3689 void XMLDropDownFieldImportContext::PrepareField(
3690 const Reference<XPropertySet>& xPropertySet)
3691 {
3692 // create sequence
3693 sal_Int32 nLength = static_cast<sal_Int32>( aLabels.size() );
3694 Sequence<OUString> aSequence( nLength );
3695 OUString* pSequence = aSequence.getArray();
3696 for( sal_Int32 n = 0; n < nLength; n++ )
3697 pSequence[n] = aLabels[n];
3698
3699 // now set values:
3700
3701 xPropertySet->setPropertyValue( "Items", Any(aSequence) );
3702
3703 if( nSelected >= 0 && nSelected < nLength )
3704 {
3705 xPropertySet->setPropertyValue( "SelectedItem", Any(pSequence[nSelected]) );
3706 }
3707
3708 // set name
3709 if( bNameOK )
3710 {
3711 xPropertySet->setPropertyValue( "Name", Any(sName) );
3712 }
3713 // set help
3714 if( bHelpOK )
3715 {
3716 xPropertySet->setPropertyValue( "Help", Any(sHelp) );
3717 }
3718 // set hint
3719 if( bHintOK )
3720 {
3721 xPropertySet->setPropertyValue( "Tooltip", Any(sHint) );
3722 }
3723
3724 }
3725
3726 /** import header fields (<draw:header>) */
3727
XMLHeaderFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)3728 XMLHeaderFieldImportContext::XMLHeaderFieldImportContext(
3729 SvXMLImport& rImport, /// XML Import
3730 XMLTextImportHelper& rHlp, /// Text import helper
3731 sal_uInt16 nPrfx, /// namespace prefix
3732 const OUString& sLocalName) /// element name w/o prefix
3733 : XMLTextFieldImportContext(rImport, rHlp, "Header", nPrfx, sLocalName )
3734 {
3735 sServicePrefix = sAPI_presentation_prefix;
3736 bValid = true;
3737 }
3738
3739 /// process attribute values
ProcessAttribute(sal_uInt16,const OUString &)3740 void XMLHeaderFieldImportContext::ProcessAttribute( sal_uInt16, const OUString& )
3741 {
3742 }
3743
3744 /// prepare XTextField for insertion into document
PrepareField(const Reference<XPropertySet> &)3745 void XMLHeaderFieldImportContext::PrepareField(const Reference<XPropertySet> &)
3746 {
3747 }
3748
3749 /** import footer fields (<draw:footer>) */
3750
XMLFooterFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)3751 XMLFooterFieldImportContext::XMLFooterFieldImportContext(
3752 SvXMLImport& rImport, /// XML Import
3753 XMLTextImportHelper& rHlp, /// Text import helper
3754 sal_uInt16 nPrfx, /// namespace prefix
3755 const OUString& sLocalName) /// element name w/o prefix
3756 : XMLTextFieldImportContext(rImport, rHlp, "Footer", nPrfx, sLocalName )
3757 {
3758 sServicePrefix = sAPI_presentation_prefix;
3759 bValid = true;
3760 }
3761
3762 /// process attribute values
ProcessAttribute(sal_uInt16,const OUString &)3763 void XMLFooterFieldImportContext::ProcessAttribute( sal_uInt16, const OUString& )
3764 {
3765 }
3766
3767 /// prepare XTextField for insertion into document
PrepareField(const Reference<XPropertySet> &)3768 void XMLFooterFieldImportContext::PrepareField(const Reference<XPropertySet> &)
3769 {
3770 }
3771
3772
3773 /** import footer fields (<draw:date-and-time>) */
3774
XMLDateTimeFieldImportContext(SvXMLImport & rImport,XMLTextImportHelper & rHlp,sal_uInt16 nPrfx,const OUString & sLocalName)3775 XMLDateTimeFieldImportContext::XMLDateTimeFieldImportContext(
3776 SvXMLImport& rImport, /// XML Import
3777 XMLTextImportHelper& rHlp, /// Text import helper
3778 sal_uInt16 nPrfx, /// namespace prefix
3779 const OUString& sLocalName) /// element name w/o prefix
3780 : XMLTextFieldImportContext(rImport, rHlp, "DateTime", nPrfx, sLocalName )
3781 {
3782 sServicePrefix = sAPI_presentation_prefix;
3783 bValid = true;
3784 }
3785
3786 /// process attribute values
ProcessAttribute(sal_uInt16,const OUString &)3787 void XMLDateTimeFieldImportContext::ProcessAttribute( sal_uInt16,
3788 const OUString& )
3789 {
3790 }
3791
3792 /// prepare XTextField for insertion into document
PrepareField(const css::uno::Reference<css::beans::XPropertySet> &)3793 void XMLDateTimeFieldImportContext::PrepareField(
3794 const css::uno::Reference<
3795 css::beans::XPropertySet> &)
3796 {
3797 }
3798
3799 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
3800