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