Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : /** @#file
21 : *
22 : * XML import of all variable related text fields plus database display field
23 : */
24 :
25 : #ifndef _XMLOFF_TXTVFLDI_HXX
26 : #define _XMLOFF_TXTVFLDI_HXX
27 :
28 : #include "txtvfldi.hxx"
29 : #include "txtfldi.hxx"
30 : #include <com/sun/star/beans/XPropertySet.hpp>
31 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
32 :
33 :
34 :
35 : /// variable type (for XMLSetVarFieldImportContext)
36 : enum VarType
37 : {
38 : VarTypeSimple,
39 : VarTypeUserField,
40 : VarTypeSequence
41 : };
42 :
43 :
44 :
45 : /** helper class: parses value-type and associated value attributes */
46 : class XMLValueImportHelper
47 : {
48 :
49 : const OUString sPropertyContent;
50 : const OUString sPropertyValue;
51 : const OUString sPropertyFormula;
52 : const OUString sPropertyNumberFormat;
53 : const OUString sPropertyIsFixedLanguage;
54 :
55 : SvXMLImport& rImport;
56 : XMLTextImportHelper& rHelper;
57 :
58 : OUString sValue; /// string value (only valid if bStringValueOK)
59 : double fValue; /// double value (only valid if bFloatValueOK)
60 : sal_Int32 nFormatKey; /// format key (only valid of bFormatOK)
61 : OUString sFormula; /// formula string
62 : OUString sDefault; /// default (see bStringDefault/bFormulaDef.)
63 : sal_Bool bIsDefaultLanguage;/// format (of nFormatKey) has system language?
64 :
65 : sal_Bool bStringType; /// is this a string (or a float) type?
66 : sal_Bool bFormatOK; /// have we read a style:data-style-name attr.?
67 : sal_Bool bTypeOK; /// have we read a value-type attribute?
68 : sal_Bool bStringValueOK; /// have we read a string-value attr.?
69 : sal_Bool bFloatValueOK; /// have we read any of the float attr.s?
70 : sal_Bool bFormulaOK; /// have we read the formula attribute?
71 :
72 : const sal_Bool bSetType; /// should PrepareField set the SetExp subtype?
73 : const sal_Bool bSetValue; /// should PrepareField set content/value?
74 : const sal_Bool bSetStyle; /// should PrepareField set NumberFormat?
75 : const sal_Bool bSetFormula; /// should PrepareField set Formula?
76 :
77 : const sal_Bool bStringDefault; /// default: string-value = content
78 : const sal_Bool bFormulaDefault; /// default: formula = content
79 :
80 : public:
81 : XMLValueImportHelper(
82 : SvXMLImport& rImprt, /// XML Import
83 : XMLTextImportHelper& rHlp, /// text import helper
84 : sal_Bool bType, /// process type (PrepareField)
85 : sal_Bool bStyle, /// process data style (P.F.)
86 : sal_Bool bValue, /// process value (Prep.Field)
87 : sal_Bool bFormula); /// process formula (Prep.F.)
88 :
89 : virtual ~XMLValueImportHelper();
90 :
91 : /// process attribute values
92 : virtual void ProcessAttribute( sal_uInt16 nAttrToken,
93 : const OUString& sAttrValue );
94 :
95 : /// prepare XTextField for insertion into document
96 : virtual void PrepareField(
97 : const ::com::sun::star::uno::Reference<
98 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
99 :
100 : /// is value a string (rather than double)?
101 24 : inline sal_Bool IsStringValue() { return bStringType; }
102 :
103 : /// has format been read?
104 0 : inline sal_Bool IsFormatOK() { return bFormatOK; }
105 :
106 1 : inline void SetDefault(const OUString& sStr) { sDefault = sStr; }
107 : };
108 :
109 :
110 :
111 : /**
112 : * abstract parent class for all variable related fields
113 : * - variable-set/get/decl (not -decls),
114 : * - user-field-get/decl (not -decls),
115 : * - sequence/-decl (not -decls),
116 : * - expression,
117 : * - text-input
118 : *
119 : * Processes the following attributes:
120 : * - name
121 : * - formula
122 : * - display
123 : * - value, value-type, data-style-name (via XMLValueImportHelper)
124 : * - description.
125 : *
126 : * Each attribute has a corresponding member, a bool variable to indicate
127 : * whether it was set or not, and a bool variable whether it should be set
128 : * using the standard property name.
129 : *
130 : * bValid is set true, when name is found!
131 : * (Most variable related fields are valid, if a name is
132 : * found. However, some are always valid. In this case, setting bValid
133 : * does not matter.)
134 : */
135 1 : class XMLVarFieldImportContext : public XMLTextFieldImportContext
136 : {
137 : protected:
138 : const OUString sPropertyContent;
139 : const OUString sPropertyHint;
140 : const OUString sPropertyHelp;
141 : const OUString sPropertyTooltip;
142 : const OUString sPropertyIsVisible;
143 : const OUString sPropertyIsDisplayFormula;
144 : const OUString sPropertyCurrentPresentation;
145 :
146 : private:
147 : OUString sName; /// name attribute
148 : OUString sFormula; /// formula attribute
149 : OUString sDescription; /// description
150 : OUString sHelp; /// help text
151 : OUString sHint; /// hint
152 : XMLValueImportHelper aValueHelper; /// value, value-type, and style
153 : sal_Bool bDisplayFormula; /// display formula?(rather than value)
154 : sal_Bool bDisplayNone; /// hide field?
155 :
156 : sal_Bool bNameOK; /// sName was set
157 : sal_Bool bFormulaOK; /// sFormula was set
158 : sal_Bool bDescriptionOK; /// sDescription was set
159 : sal_Bool bHelpOK; /// sHelp was set
160 : sal_Bool bHintOK; /// sHint was set
161 : sal_Bool bDisplayOK; /// sDisplayFormula/-None were set
162 :
163 : sal_Bool bSetFormula; /// set Formula property
164 : sal_Bool bSetFormulaDefault; /// use content as default for formula
165 : sal_Bool bSetDescription; /// set sDescription with Hint-property
166 : sal_Bool bSetHelp;
167 : sal_Bool bSetHint;
168 : sal_Bool bSetVisible; /// set IsVisible
169 : sal_Bool bSetDisplayFormula; /// set DisplayFormula (sub type???)
170 : sal_Bool bSetPresentation; /// set presentation frm elem. content?
171 :
172 : public:
173 :
174 : TYPEINFO();
175 :
176 : XMLVarFieldImportContext(
177 : // for XMLTextFieldImportContext:
178 : SvXMLImport& rImport, /// XML Import
179 : XMLTextImportHelper& rHlp, /// text import helper
180 : const sal_Char* pServiceName, /// name of SO API service
181 : sal_uInt16 nPrfx, /// namespace prefix
182 : const OUString& rLocalName, /// element name w/o prefix
183 : // config variables for PrepareField behavior:
184 : sal_Bool bFormula, /// set Formula property
185 : sal_Bool bFormulaDefault, /// use content as default for formula
186 : sal_Bool bDescription, /// set sDescription with Hint-property
187 : sal_Bool bHelp,
188 : sal_Bool bHint,
189 : sal_Bool bVisible, /// set IsVisible (display attr)
190 : sal_Bool bDisplayFormula, /// set ??? (display attr.)
191 : sal_Bool bType, /// set value type with ???-property
192 : sal_Bool bStyle, /// set data style (NumberFormat-Prop.)
193 : sal_Bool bValue, /// set value with Content/Value-Prop.
194 : sal_Bool bPresentation); /// set presentation from elem. content
195 :
196 : protected:
197 : /// process attribute values
198 : virtual void ProcessAttribute( sal_uInt16 nAttrToken,
199 : const OUString& sAttrValue );
200 :
201 : /// prepare XTextField for insertion into document
202 : virtual void PrepareField(
203 : const ::com::sun::star::uno::Reference<
204 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
205 :
206 : // various accessor methods:
207 1 : inline OUString GetName() { return sName; }
208 1 : inline sal_Bool IsStringValue() { return aValueHelper.IsStringValue();}
209 : inline sal_Bool IsNameOK() { return bNameOK; }
210 : inline sal_Bool IsFormulaOK() { return bFormulaOK; }
211 : inline sal_Bool IsDescriptionOK() { return bDescriptionOK; }
212 : inline sal_Bool IsDisplayOK() { return bDisplayOK; }
213 : };
214 :
215 :
216 :
217 : /** import variable get fields (<text:variable-get>) */
218 0 : class XMLVariableGetFieldImportContext : public XMLVarFieldImportContext
219 : {
220 : const OUString sPropertySubType;
221 :
222 : public:
223 :
224 : TYPEINFO();
225 :
226 : XMLVariableGetFieldImportContext(
227 : SvXMLImport& rImport, /// XML Import
228 : XMLTextImportHelper& rHlp, /// Text import helper
229 : sal_uInt16 nPrfx, /// namespace prefix
230 : const OUString& rLocalName); /// element name w/o prefix
231 :
232 :
233 : protected:
234 : /// prepare XTextField for insertion into document
235 : virtual void PrepareField(
236 : const ::com::sun::star::uno::Reference<
237 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
238 : };
239 :
240 :
241 :
242 : /** import expression fields (<text:expression>) */
243 0 : class XMLExpressionFieldImportContext : public XMLVarFieldImportContext
244 : {
245 : const OUString sPropertySubType;
246 :
247 : public:
248 :
249 : TYPEINFO();
250 :
251 : XMLExpressionFieldImportContext(
252 : SvXMLImport& rImport, /// XML Import
253 : XMLTextImportHelper& rHlp, /// Text import helper
254 : sal_uInt16 nPrfx, /// namespace prefix
255 : const OUString& sLocalName); /// element name w/o prefix
256 :
257 : protected:
258 : virtual void PrepareField(
259 : const ::com::sun::star::uno::Reference<
260 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
261 : };
262 :
263 : /*** import text input fields (<text:text-input>) */
264 0 : class XMLTextInputFieldImportContext : public XMLVarFieldImportContext
265 : {
266 : const OUString sPropertyContent;
267 :
268 : public:
269 :
270 : TYPEINFO();
271 :
272 : XMLTextInputFieldImportContext(
273 : SvXMLImport& rImport, /// XML Import
274 : XMLTextImportHelper& rHlp, /// Text import helper
275 : sal_uInt16 nPrfx, /// namespace prefix
276 : const OUString& sLocalName); /// element name w/o prefix
277 :
278 : protected:
279 : virtual void PrepareField(
280 : const ::com::sun::star::uno::Reference<
281 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
282 : };
283 :
284 :
285 :
286 :
287 :
288 :
289 : /**
290 : * uperclass for variable/user-set, var/user-input, and sequence fields
291 : * inds field master of appropriate type and attaches field to it.
292 : */
293 1 : class XMLSetVarFieldImportContext : public XMLVarFieldImportContext
294 : {
295 : const VarType eFieldType;
296 :
297 : public:
298 :
299 : TYPEINFO();
300 :
301 : XMLSetVarFieldImportContext(
302 : // for XMLTextFieldImportContext:
303 : SvXMLImport& rImport, /// see XMLTextFieldImportContext
304 : XMLTextImportHelper& rHlp, /// see XMLTextFieldImportContext
305 : const sal_Char* pServiceName, /// see XMLTextFieldImportContext
306 : sal_uInt16 nPrfx, /// see XMLTextFieldImportContext
307 : const OUString& rLocalName, /// see XMLTextFieldImportContext
308 : // for finding appropriate field master (see EndElement())
309 : VarType eVarType, /// variable type
310 : // config variables:
311 : sal_Bool bFormula, /// see XMLTextFieldImportContext
312 : sal_Bool bFormulaDefault, /// see XMLTextFieldImportContext
313 : sal_Bool bDescription, /// see XMLTextFieldImportContext
314 : sal_Bool bHelp, /// see XMLTextFieldImportContext
315 : sal_Bool bHint, /// see XMLTextFieldImportContext
316 : sal_Bool bVisible, /// see XMLTextFieldImportContext
317 : sal_Bool bDisplayFormula, /// see XMLTextFieldImportContext
318 : sal_Bool bType, /// see XMLTextFieldImportContext
319 : sal_Bool bStyle, /// see XMLTextFieldImportContext
320 : sal_Bool bValue, /// see XMLTextFieldImportContext
321 : sal_Bool bPresentation); /// see XMLTextFieldImportContext
322 :
323 : protected:
324 :
325 : /// create XTextField, attach master and insert into document;
326 : /// also calls PrepareTextField
327 : virtual void EndElement();
328 :
329 : /// find appropriate field master
330 : sal_Bool FindFieldMaster(
331 : ::com::sun::star::uno::Reference<
332 : ::com::sun::star::beans::XPropertySet> & xMaster);
333 : };
334 :
335 :
336 :
337 : /** import variable set fields (<text:variable-set>) */
338 2 : class XMLVariableSetFieldImportContext : public XMLSetVarFieldImportContext
339 : {
340 : const OUString sPropertySubType;
341 :
342 : public:
343 :
344 : TYPEINFO();
345 :
346 : XMLVariableSetFieldImportContext(
347 : SvXMLImport& rImport, /// XML Import
348 : XMLTextImportHelper& rHlp, /// Text import helper
349 : sal_uInt16 nPrfx, /// namespace prefix
350 : const OUString& rLocalName); /// element name w/o prefix
351 :
352 : protected:
353 : /// prepare XTextField for insertion into document
354 : virtual void PrepareField(
355 : const ::com::sun::star::uno::Reference<
356 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
357 : };
358 :
359 :
360 :
361 : /** variable input fields (<text:variable-input>) */
362 0 : class XMLVariableInputFieldImportContext : public XMLSetVarFieldImportContext
363 : {
364 : const OUString sPropertySubType;
365 : const OUString sPropertyIsInput;
366 :
367 : public:
368 :
369 : TYPEINFO();
370 :
371 : XMLVariableInputFieldImportContext(
372 : SvXMLImport& rImport, /// XML Import
373 : XMLTextImportHelper& rHlp, /// Text import helper
374 : sal_uInt16 nPrfx, /// namespace prefix
375 : const OUString& rLocalName); /// element name w/o prefix
376 :
377 : protected:
378 :
379 : /// prepare XTextField for insertion into document
380 : virtual void PrepareField(
381 : const ::com::sun::star::uno::Reference<
382 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
383 : };
384 :
385 :
386 :
387 : /** user fields (<text:user-field-get>) */
388 0 : class XMLUserFieldImportContext : public XMLSetVarFieldImportContext
389 : {
390 :
391 : public:
392 :
393 : TYPEINFO();
394 :
395 : XMLUserFieldImportContext(
396 : SvXMLImport& rImport, /// XML Import
397 : XMLTextImportHelper& rHlp, /// Text import helper
398 : sal_uInt16 nPrfx, /// namespace prefix
399 : const OUString& rLocalName); /// element name w/o prefix
400 : };
401 :
402 : /** user input fields (<text:user-field-input>) */
403 0 : class XMLUserFieldInputImportContext : public XMLVarFieldImportContext
404 : {
405 :
406 : public:
407 :
408 : TYPEINFO();
409 :
410 : XMLUserFieldInputImportContext(
411 : SvXMLImport& rImport, /// XML Import
412 : XMLTextImportHelper& rHlp, /// Text import helper
413 : sal_uInt16 nPrfx, /// namespace prefix
414 : const OUString& rLocalName); /// element name w/o prefix
415 :
416 : virtual void PrepareField(
417 : const ::com::sun::star::uno::Reference<
418 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
419 : };
420 :
421 :
422 :
423 : /** sequence fields (<text:sequence>) */
424 0 : class XMLSequenceFieldImportContext : public XMLSetVarFieldImportContext
425 : {
426 : const OUString sPropertyFormula;
427 : const OUString sPropertyNumberFormat;
428 : const OUString sPropertySequenceValue;
429 : OUString sFormula;
430 : OUString sNumFormat;
431 : OUString sNumFormatSync;
432 : OUString sRefName;
433 :
434 : sal_Bool bRefNameOK;
435 :
436 : public:
437 :
438 : TYPEINFO();
439 :
440 : XMLSequenceFieldImportContext(
441 : SvXMLImport& rImport, /// XML Import
442 : XMLTextImportHelper& rHlp, /// Text import helper
443 : sal_uInt16 nPrfx, /// namespace prefix
444 : const OUString& rLocalName); /// element name w/o prefix
445 :
446 : protected:
447 :
448 : /// process attribute values
449 : virtual void ProcessAttribute( sal_uInt16 nAttrToken,
450 : const OUString& sAttrValue );
451 :
452 : /// prepare XTextField for insertion into document
453 : virtual void PrepareField(
454 : const ::com::sun::star::uno::Reference<
455 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
456 : };
457 :
458 :
459 :
460 :
461 :
462 :
463 : /**
464 : * variable declaration container for all variable fields
465 : * (variable-decls, user-field-decls, sequence-decls)
466 : */
467 108 : class XMLVariableDeclsImportContext : public SvXMLImportContext
468 : {
469 : enum VarType eVarDeclsContextType;
470 : XMLTextImportHelper& rImportHelper;
471 :
472 : public:
473 :
474 : TYPEINFO();
475 :
476 : XMLVariableDeclsImportContext(
477 : SvXMLImport& rImport, /// XML Import
478 : XMLTextImportHelper& rHlp, /// text import helper
479 : sal_uInt16 nPrfx, /// namespace prefix
480 : const OUString& rLocalName, /// element name w/o prefix
481 : enum VarType eVarType); /// variable type
482 :
483 : virtual SvXMLImportContext *CreateChildContext(
484 : sal_uInt16 nPrefix,
485 : const OUString& rLocalName,
486 : const ::com::sun::star::uno::Reference<
487 : ::com::sun::star::xml::sax::XAttributeList> & xAttrList );
488 : };
489 :
490 : /**
491 : * variable field declarations
492 : * (variable-decl, user-field-decl, sequence-decl)
493 : */
494 446 : class XMLVariableDeclImportContext : public SvXMLImportContext
495 : {
496 : const OUString sPropertyName;
497 : const OUString sPropertySubType;
498 : const OUString sPropertyNumberingLevel;
499 : const OUString sPropertyNumberingSeparator;
500 : const OUString sPropertyIsExpression;
501 :
502 : OUString sName;
503 : XMLValueImportHelper aValueHelper;
504 : sal_Int8 nNumLevel;
505 : sal_Unicode cSeparationChar;
506 :
507 : public:
508 :
509 : TYPEINFO();
510 :
511 : XMLVariableDeclImportContext(
512 : SvXMLImport& rImport, /// XML Import
513 : XMLTextImportHelper& rHlp, /// text import helper
514 : sal_uInt16 nPrfx, /// namespace prefix
515 : const OUString& rLocalName, /// element name w/o prefix
516 : const ::com::sun::star::uno::Reference< /// list of element attributes
517 : ::com::sun::star::xml::sax::XAttributeList> & xAttrList,
518 : enum VarType eVarType); /// variable type
519 :
520 : /// get field master for name and rename if appropriate
521 : static sal_Bool FindFieldMaster(::com::sun::star::uno::Reference<
522 : ::com::sun::star::beans::XPropertySet> & xMaster,
523 : SvXMLImport& rImport,
524 : XMLTextImportHelper& rHelper,
525 : const OUString& sVarName,
526 : enum VarType eVarType);
527 : };
528 :
529 :
530 :
531 : /** import table formula fields (deprecated; for Writer 2.0 compatibility) */
532 : class XMLTableFormulaImportContext : public XMLTextFieldImportContext
533 : {
534 : const OUString sPropertyNumberFormat;
535 : const OUString sPropertyContent;
536 : const OUString sPropertyIsShowFormula;
537 : const OUString sPropertyCurrentPresentation;
538 :
539 : XMLValueImportHelper aValueHelper;
540 :
541 : OUString sFormula;
542 :
543 : sal_Bool bIsShowFormula;
544 :
545 : public:
546 :
547 : TYPEINFO();
548 :
549 : XMLTableFormulaImportContext(
550 : SvXMLImport& rImport, /// XML Import
551 : XMLTextImportHelper& rHlp, /// text import helper
552 : sal_uInt16 nPrfx, /// namespace prefix
553 : const OUString& rLocalName); /// element name w/o prefix
554 : virtual ~XMLTableFormulaImportContext();
555 :
556 : protected:
557 :
558 : /// process attribute values
559 : virtual void ProcessAttribute( sal_uInt16 nAttrToken,
560 : const OUString& sAttrValue );
561 :
562 : /// prepare XTextField for insertion into document
563 : virtual void PrepareField(
564 : const ::com::sun::star::uno::Reference<
565 : ::com::sun::star::beans::XPropertySet> & xPropertySet);
566 : };
567 :
568 :
569 :
570 : /** import database display fields (<text:database-display>) */
571 0 : class XMLDatabaseDisplayImportContext : public XMLDatabaseFieldImportContext
572 : {
573 : const OUString sPropertyColumnName;
574 : const OUString sPropertyDatabaseFormat;
575 : const OUString sPropertyCurrentPresentation;
576 : const OUString sPropertyIsVisible;
577 :
578 : XMLValueImportHelper aValueHelper;
579 :
580 : OUString sColumnName;
581 : sal_Bool bColumnOK;
582 :
583 : sal_Bool bDisplay;
584 : sal_Bool bDisplayOK;
585 :
586 : public:
587 :
588 : TYPEINFO();
589 :
590 : XMLDatabaseDisplayImportContext(
591 : SvXMLImport& rImport, /// XML Import
592 : XMLTextImportHelper& rHlp, /// text import helper
593 : sal_uInt16 nPrfx, /// namespace prefix
594 : const OUString& rLocalName); /// element name w/o prefix
595 :
596 : protected:
597 :
598 : /// process attribute values
599 : virtual void ProcessAttribute( sal_uInt16 nAttrToken,
600 : const OUString& sAttrValue );
601 :
602 : /// create, prepare and insert database field master and database field
603 : virtual void EndElement();
604 : };
605 :
606 : #endif
607 :
608 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|