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