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