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 : #include "xmlcvali.hxx"
21 : #include "xmlimprt.hxx"
22 : #include "xmlconti.hxx"
23 : #include "document.hxx"
24 : #include "XMLConverter.hxx"
25 :
26 : #include <xmloff/xmltkmap.hxx>
27 : #include <xmloff/nmspmap.hxx>
28 : #include <xmloff/xmltoken.hxx>
29 : #include <xmloff/xmlnmspe.hxx>
30 : #include <xmloff/XMLEventsImportContext.hxx>
31 : #include <com/sun/star/sheet/TableValidationVisibility.hpp>
32 :
33 : using namespace com::sun::star;
34 : using namespace xmloff::token;
35 : using namespace ::formula;
36 :
37 : class ScXMLContentValidationContext : public SvXMLImportContext
38 : {
39 : OUString sName;
40 : OUString sHelpTitle;
41 : OUString sHelpMessage;
42 : OUString sErrorTitle;
43 : OUString sErrorMessage;
44 : OUString sErrorMessageType;
45 : OUString sBaseCellAddress;
46 : OUString sCondition;
47 : sal_Int16 nShowList;
48 : bool bAllowEmptyCell;
49 : bool bDisplayHelp;
50 : bool bDisplayError;
51 :
52 : SvXMLImportContextRef xEventContext;
53 :
54 4 : const ScXMLImport& GetScImport() const { return static_cast<const ScXMLImport&>(GetImport()); }
55 36 : ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
56 :
57 : com::sun::star::sheet::ValidationAlertStyle GetAlertStyle() const;
58 : void SetFormula( OUString& rFormula, OUString& rFormulaNmsp, FormulaGrammar::Grammar& reGrammar,
59 : const OUString& rCondition, const OUString& rGlobNmsp, FormulaGrammar::Grammar eGlobGrammar, bool bHasNmsp ) const;
60 : void GetCondition( ScMyImportValidation& rValidation ) const;
61 :
62 : public:
63 :
64 : ScXMLContentValidationContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
65 : const OUString& rLName,
66 : const ::com::sun::star::uno::Reference<
67 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList);
68 :
69 : virtual ~ScXMLContentValidationContext();
70 :
71 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
72 : const OUString& rLocalName,
73 : const ::com::sun::star::uno::Reference<
74 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
75 :
76 : virtual void EndElement() SAL_OVERRIDE;
77 :
78 : void SetHelpMessage(const OUString& sTitle, const OUString& sMessage, const bool bDisplay);
79 : void SetErrorMessage(const OUString& sTitle, const OUString& sMessage, const OUString& sMessageType, const bool bDisplay);
80 : void SetErrorMacro(const bool bExecute);
81 : };
82 :
83 : class ScXMLHelpMessageContext : public SvXMLImportContext
84 : {
85 : OUString sTitle;
86 : OUStringBuffer sMessage;
87 : sal_Int32 nParagraphCount;
88 : bool bDisplay;
89 :
90 : ScXMLContentValidationContext* pValidationContext;
91 :
92 0 : ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
93 :
94 : public:
95 :
96 : ScXMLHelpMessageContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
97 : const OUString& rLName,
98 : const ::com::sun::star::uno::Reference<
99 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
100 : ScXMLContentValidationContext* pValidationContext);
101 :
102 : virtual ~ScXMLHelpMessageContext();
103 :
104 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
105 : const OUString& rLocalName,
106 : const ::com::sun::star::uno::Reference<
107 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
108 :
109 : virtual void EndElement() SAL_OVERRIDE;
110 : };
111 :
112 : class ScXMLErrorMessageContext : public SvXMLImportContext
113 : {
114 : OUString sTitle;
115 : OUStringBuffer sMessage;
116 : OUString sMessageType;
117 : sal_Int32 nParagraphCount;
118 : bool bDisplay;
119 :
120 : ScXMLContentValidationContext* pValidationContext;
121 :
122 24 : ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
123 :
124 : public:
125 :
126 : ScXMLErrorMessageContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
127 : const OUString& rLName,
128 : const ::com::sun::star::uno::Reference<
129 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
130 : ScXMLContentValidationContext* pValidationContext);
131 :
132 : virtual ~ScXMLErrorMessageContext();
133 :
134 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
135 : const OUString& rLocalName,
136 : const ::com::sun::star::uno::Reference<
137 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
138 :
139 : virtual void EndElement() SAL_OVERRIDE;
140 : };
141 :
142 : class ScXMLErrorMacroContext : public SvXMLImportContext
143 : {
144 : OUString sName;
145 : bool bExecute;
146 :
147 : ScXMLContentValidationContext* pValidationContext;
148 :
149 0 : ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
150 :
151 : public:
152 :
153 : ScXMLErrorMacroContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
154 : const OUString& rLName,
155 : const ::com::sun::star::uno::Reference<
156 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
157 : ScXMLContentValidationContext* pValidationContext);
158 :
159 : virtual ~ScXMLErrorMacroContext();
160 :
161 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
162 : const OUString& rLocalName,
163 : const ::com::sun::star::uno::Reference<
164 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
165 : virtual void EndElement() SAL_OVERRIDE;
166 : };
167 :
168 2 : ScXMLContentValidationsContext::ScXMLContentValidationsContext( ScXMLImport& rImport,
169 : sal_uInt16 nPrfx,
170 : const OUString& rLName,
171 : const ::com::sun::star::uno::Reference<
172 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
173 2 : SvXMLImportContext( rImport, nPrfx, rLName )
174 : {
175 : // here are no attributes
176 2 : }
177 :
178 4 : ScXMLContentValidationsContext::~ScXMLContentValidationsContext()
179 : {
180 4 : }
181 :
182 4 : SvXMLImportContext *ScXMLContentValidationsContext::CreateChildContext( sal_uInt16 nPrefix,
183 : const OUString& rLName,
184 : const ::com::sun::star::uno::Reference<
185 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
186 : {
187 4 : SvXMLImportContext *pContext = 0;
188 :
189 4 : const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationsElemTokenMap();
190 4 : switch( rTokenMap.Get( nPrefix, rLName ) )
191 : {
192 : case XML_TOK_CONTENT_VALIDATION:
193 4 : pContext = new ScXMLContentValidationContext( GetScImport(), nPrefix, rLName, xAttrList);
194 4 : break;
195 : }
196 :
197 4 : if( !pContext )
198 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
199 :
200 4 : return pContext;
201 : }
202 :
203 2 : void ScXMLContentValidationsContext::EndElement()
204 : {
205 2 : }
206 :
207 4 : ScXMLContentValidationContext::ScXMLContentValidationContext( ScXMLImport& rImport,
208 : sal_uInt16 nPrfx,
209 : const OUString& rLName,
210 : const ::com::sun::star::uno::Reference<
211 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
212 : SvXMLImportContext( rImport, nPrfx, rLName ),
213 : nShowList(sheet::TableValidationVisibility::UNSORTED),
214 : bAllowEmptyCell(true),
215 : bDisplayHelp(false),
216 4 : bDisplayError(false)
217 : {
218 4 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
219 4 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationAttrTokenMap();
220 20 : for( sal_Int16 i=0; i < nAttrCount; ++i )
221 : {
222 16 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
223 32 : OUString aLocalName;
224 16 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
225 16 : sAttrName, &aLocalName );
226 32 : const OUString& sValue(xAttrList->getValueByIndex( i ));
227 :
228 16 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
229 : {
230 : case XML_TOK_CONTENT_VALIDATION_NAME:
231 4 : sName = sValue;
232 4 : break;
233 : case XML_TOK_CONTENT_VALIDATION_CONDITION:
234 4 : sCondition = sValue;
235 4 : break;
236 : case XML_TOK_CONTENT_VALIDATION_BASE_CELL_ADDRESS:
237 4 : sBaseCellAddress = sValue;
238 4 : break;
239 : case XML_TOK_CONTENT_VALIDATION_ALLOW_EMPTY_CELL:
240 4 : if (IsXMLToken(sValue, XML_FALSE))
241 0 : bAllowEmptyCell = false;
242 4 : break;
243 : case XML_TOK_CONTENT_VALIDATION_DISPLAY_LIST:
244 : {
245 0 : if (IsXMLToken(sValue, XML_NO))
246 : {
247 0 : nShowList = sheet::TableValidationVisibility::INVISIBLE;
248 : }
249 0 : else if (IsXMLToken(sValue, XML_UNSORTED))
250 : {
251 0 : nShowList = sheet::TableValidationVisibility::UNSORTED;
252 : }
253 0 : else if (IsXMLToken(sValue, XML_SORT_ASCENDING))
254 : {
255 0 : nShowList = sheet::TableValidationVisibility::SORTEDASCENDING;
256 : }
257 0 : else if (IsXMLToken(sValue, XML_SORTED_ASCENDING))
258 : {
259 : // Read old wrong value, fdo#72548
260 0 : nShowList = sheet::TableValidationVisibility::SORTEDASCENDING;
261 : }
262 : }
263 0 : break;
264 : }
265 16 : }
266 4 : }
267 :
268 8 : ScXMLContentValidationContext::~ScXMLContentValidationContext()
269 : {
270 8 : }
271 :
272 4 : SvXMLImportContext *ScXMLContentValidationContext::CreateChildContext( sal_uInt16 nPrefix,
273 : const OUString& rLName,
274 : const ::com::sun::star::uno::Reference<
275 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
276 : {
277 4 : SvXMLImportContext *pContext = 0;
278 :
279 4 : const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationElemTokenMap();
280 4 : switch( rTokenMap.Get( nPrefix, rLName ) )
281 : {
282 : case XML_TOK_CONTENT_VALIDATION_ELEM_HELP_MESSAGE:
283 0 : pContext = new ScXMLHelpMessageContext( GetScImport(), nPrefix, rLName, xAttrList, this);
284 0 : break;
285 : case XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MESSAGE:
286 4 : pContext = new ScXMLErrorMessageContext( GetScImport(), nPrefix, rLName, xAttrList, this);
287 4 : break;
288 : case XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MACRO:
289 0 : pContext = new ScXMLErrorMacroContext( GetScImport(), nPrefix, rLName, xAttrList, this);
290 0 : break;
291 : case XML_TOK_CONTENT_VALIDATION_ELEM_EVENT_LISTENERS:
292 0 : pContext = new XMLEventsImportContext( GetImport(), nPrefix, rLName );
293 0 : xEventContext = pContext;
294 0 : break;
295 : }
296 :
297 4 : if( !pContext )
298 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
299 :
300 4 : return pContext;
301 : }
302 :
303 4 : sheet::ValidationAlertStyle ScXMLContentValidationContext::GetAlertStyle() const
304 : {
305 4 : if (IsXMLToken(sErrorMessageType, XML_MACRO))
306 0 : return sheet::ValidationAlertStyle_MACRO;
307 4 : if (IsXMLToken(sErrorMessageType, XML_STOP))
308 2 : return sheet::ValidationAlertStyle_STOP;
309 2 : if (IsXMLToken(sErrorMessageType, XML_WARNING))
310 2 : return sheet::ValidationAlertStyle_WARNING;
311 0 : if (IsXMLToken(sErrorMessageType, XML_INFORMATION))
312 0 : return sheet::ValidationAlertStyle_INFO;
313 : // default for unknown
314 0 : return sheet::ValidationAlertStyle_STOP;
315 : }
316 :
317 8 : void ScXMLContentValidationContext::SetFormula( OUString& rFormula, OUString& rFormulaNmsp, FormulaGrammar::Grammar& reGrammar,
318 : const OUString& rCondition, const OUString& rGlobNmsp, FormulaGrammar::Grammar eGlobGrammar, bool bHasNmsp ) const
319 : {
320 8 : reGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
321 8 : if( bHasNmsp )
322 : {
323 : // the entire attribute contains a namespace: internal namespace not allowed
324 8 : rFormula = rCondition;
325 8 : rFormulaNmsp = rGlobNmsp;
326 8 : reGrammar = eGlobGrammar;
327 : }
328 : else
329 : {
330 : // the attribute does not contain a namespace: try to find a namespace of an external grammar
331 0 : GetScImport().ExtractFormulaNamespaceGrammar( rFormula, rFormulaNmsp, reGrammar, rCondition, true );
332 0 : if( reGrammar != FormulaGrammar::GRAM_EXTERNAL )
333 0 : reGrammar = eGlobGrammar;
334 : }
335 8 : }
336 :
337 4 : void ScXMLContentValidationContext::GetCondition( ScMyImportValidation& rValidation ) const
338 : {
339 4 : rValidation.aValidationType = sheet::ValidationType_ANY; // default if no condition is given
340 4 : rValidation.aOperator = sheet::ConditionOperator_NONE;
341 :
342 4 : if( !sCondition.isEmpty() )
343 : {
344 : // extract leading namespace from condition string
345 8 : OUString aCondition, aConditionNmsp;
346 4 : FormulaGrammar::Grammar eGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
347 4 : GetScImport().ExtractFormulaNamespaceGrammar( aCondition, aConditionNmsp, eGrammar, sCondition );
348 4 : bool bHasNmsp = aCondition.getLength() < sCondition.getLength();
349 :
350 : // parse a condition from the attribute string
351 8 : ScXMLConditionParseResult aParseResult;
352 4 : ScXMLConditionHelper::parseCondition( aParseResult, aCondition, 0 );
353 :
354 : /* Check the result. A valid value in aParseResult.meToken implies
355 : that the other members of aParseResult are filled with valid data
356 : for that token. */
357 4 : bool bSecondaryPart = false;
358 4 : switch( aParseResult.meToken )
359 : {
360 : case XML_COND_TEXTLENGTH: // condition is 'cell-content-text-length()<operator><expression>'
361 : case XML_COND_TEXTLENGTH_ISBETWEEN: // condition is 'cell-content-text-length-is-between(<expression1>,<expression2>)'
362 : case XML_COND_TEXTLENGTH_ISNOTBETWEEN: // condition is 'cell-content-text-length-is-not-between(<expression1>,<expression2>)'
363 : case XML_COND_ISINLIST: // condition is 'cell-content-is-in-list(<expression>)'
364 0 : rValidation.aValidationType = aParseResult.meValidation;
365 0 : rValidation.aOperator = aParseResult.meOperator;
366 0 : break;
367 :
368 : case XML_COND_ISWHOLENUMBER: // condition is 'cell-content-is-whole-number() and <condition>'
369 : case XML_COND_ISDECIMALNUMBER: // condition is 'cell-content-is-decimal-number() and <condition>'
370 : case XML_COND_ISDATE: // condition is 'cell-content-is-date() and <condition>'
371 : case XML_COND_ISTIME: // condition is 'cell-content-is-time() and <condition>'
372 4 : rValidation.aValidationType = aParseResult.meValidation;
373 4 : bSecondaryPart = true;
374 4 : break;
375 :
376 : default:; // unacceptable or unknown condition
377 : }
378 :
379 : /* Parse the following 'and <condition>' part of some conditions. This
380 : updates the members of aParseResult that will contain the operands
381 : and comparison operator then. */
382 4 : if( bSecondaryPart )
383 : {
384 4 : ScXMLConditionHelper::parseCondition( aParseResult, aCondition, aParseResult.mnEndIndex );
385 4 : if( aParseResult.meToken == XML_COND_AND )
386 : {
387 4 : ScXMLConditionHelper::parseCondition( aParseResult, aCondition, aParseResult.mnEndIndex );
388 4 : switch( aParseResult.meToken )
389 : {
390 : case XML_COND_CELLCONTENT: // condition is 'and cell-content()<operator><expression>'
391 : case XML_COND_ISBETWEEN: // condition is 'and cell-content-is-between(<expression1>,<expression2>)'
392 : case XML_COND_ISNOTBETWEEN: // condition is 'and cell-content-is-not-between(<expression1>,<expression2>)'
393 4 : rValidation.aOperator = aParseResult.meOperator;
394 4 : break;
395 : default:; // unacceptable or unknown condition
396 : }
397 : }
398 : }
399 :
400 : // a validation type (date, integer) without a condition isn't possible
401 4 : if( rValidation.aOperator == sheet::ConditionOperator_NONE )
402 0 : rValidation.aValidationType = sheet::ValidationType_ANY;
403 :
404 : // parse the formulas
405 4 : if( rValidation.aValidationType != sheet::ValidationType_ANY )
406 : {
407 : SetFormula( rValidation.sFormula1, rValidation.sFormulaNmsp1, rValidation.eGrammar1,
408 4 : aParseResult.maOperand1, aConditionNmsp, eGrammar, bHasNmsp );
409 : SetFormula( rValidation.sFormula2, rValidation.sFormulaNmsp2, rValidation.eGrammar2,
410 4 : aParseResult.maOperand2, aConditionNmsp, eGrammar, bHasNmsp );
411 4 : }
412 : }
413 4 : }
414 :
415 4 : void ScXMLContentValidationContext::EndElement()
416 : {
417 : // #i36650# event-listeners element moved up one level
418 4 : if (xEventContext.Is())
419 : {
420 0 : OUString sOnError("OnError");
421 : XMLEventsImportContext* pEvents =
422 0 : static_cast<XMLEventsImportContext*>(&xEventContext);
423 0 : uno::Sequence<beans::PropertyValue> aValues;
424 0 : pEvents->GetEventSequence( sOnError, aValues );
425 :
426 0 : sal_Int32 nLength = aValues.getLength();
427 0 : for( sal_Int32 i = 0; i < nLength; i++ )
428 : {
429 : // #i47525# must allow "MacroName" or "Script"
430 0 : if ( aValues[i].Name == "MacroName" ||
431 0 : aValues[i].Name == "Script" )
432 : {
433 0 : aValues[i].Value >>= sErrorTitle;
434 0 : break;
435 : }
436 0 : }
437 : }
438 :
439 4 : ScMyImportValidation aValidation;
440 4 : aValidation.eGrammar1 = aValidation.eGrammar2 = GetScImport().GetDocument()->GetStorageGrammar();
441 4 : aValidation.sName = sName;
442 4 : aValidation.sBaseCellAddress = sBaseCellAddress;
443 4 : aValidation.sImputTitle = sHelpTitle;
444 4 : aValidation.sImputMessage = sHelpMessage;
445 4 : aValidation.sErrorTitle = sErrorTitle;
446 4 : aValidation.sErrorMessage = sErrorMessage;
447 4 : GetCondition( aValidation );
448 4 : aValidation.aAlertStyle = GetAlertStyle();
449 4 : aValidation.bShowErrorMessage = bDisplayError;
450 4 : aValidation.bShowImputMessage = bDisplayHelp;
451 4 : aValidation.bIgnoreBlanks = bAllowEmptyCell;
452 4 : aValidation.nShowList = nShowList;
453 4 : GetScImport().AddValidation(aValidation);
454 4 : }
455 :
456 0 : void ScXMLContentValidationContext::SetHelpMessage(const OUString& sTitle, const OUString& sMessage, const bool bDisplay)
457 : {
458 0 : sHelpTitle = sTitle;
459 0 : sHelpMessage = sMessage;
460 0 : bDisplayHelp = bDisplay;
461 0 : }
462 :
463 4 : void ScXMLContentValidationContext::SetErrorMessage(const OUString& sTitle, const OUString& sMessage,
464 : const OUString& sMessageType, const bool bDisplay)
465 : {
466 4 : sErrorTitle = sTitle;
467 4 : sErrorMessage = sMessage;
468 4 : sErrorMessageType = sMessageType;
469 4 : bDisplayError = bDisplay;
470 4 : }
471 :
472 0 : void ScXMLContentValidationContext::SetErrorMacro(const bool bExecute)
473 : {
474 0 : sErrorMessageType = "macro";
475 0 : bDisplayError = bExecute;
476 0 : }
477 :
478 0 : ScXMLHelpMessageContext::ScXMLHelpMessageContext( ScXMLImport& rImport,
479 : sal_uInt16 nPrfx,
480 : const OUString& rLName,
481 : const ::com::sun::star::uno::Reference<
482 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
483 : ScXMLContentValidationContext* pTempValidationContext) :
484 : SvXMLImportContext( rImport, nPrfx, rLName ),
485 : sTitle(),
486 : sMessage(),
487 : nParagraphCount(0),
488 0 : bDisplay(false)
489 : {
490 0 : pValidationContext = pTempValidationContext;
491 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
492 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationHelpMessageAttrTokenMap();
493 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
494 : {
495 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
496 0 : OUString aLocalName;
497 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
498 0 : sAttrName, &aLocalName );
499 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
500 :
501 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
502 : {
503 : case XML_TOK_HELP_MESSAGE_ATTR_TITLE:
504 0 : sTitle = sValue;
505 0 : break;
506 : case XML_TOK_HELP_MESSAGE_ATTR_DISPLAY:
507 0 : bDisplay = IsXMLToken(sValue, XML_TRUE);
508 0 : break;
509 : }
510 0 : }
511 0 : }
512 :
513 0 : ScXMLHelpMessageContext::~ScXMLHelpMessageContext()
514 : {
515 0 : }
516 :
517 0 : SvXMLImportContext *ScXMLHelpMessageContext::CreateChildContext( sal_uInt16 nPrefix,
518 : const OUString& rLName,
519 : const ::com::sun::star::uno::Reference<
520 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
521 : {
522 0 : SvXMLImportContext *pContext = 0;
523 :
524 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationMessageElemTokenMap();
525 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
526 : {
527 : case XML_TOK_P:
528 : {
529 0 : if(nParagraphCount)
530 0 : sMessage.append('\n');
531 0 : ++nParagraphCount;
532 0 : pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLName, xAttrList, sMessage);
533 : }
534 0 : break;
535 : }
536 :
537 0 : if( !pContext )
538 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
539 :
540 0 : return pContext;
541 : }
542 :
543 0 : void ScXMLHelpMessageContext::EndElement()
544 : {
545 0 : pValidationContext->SetHelpMessage(sTitle, sMessage.makeStringAndClear(), bDisplay);
546 0 : }
547 :
548 4 : ScXMLErrorMessageContext::ScXMLErrorMessageContext( ScXMLImport& rImport,
549 : sal_uInt16 nPrfx,
550 : const OUString& rLName,
551 : const ::com::sun::star::uno::Reference<
552 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
553 : ScXMLContentValidationContext* pTempValidationContext) :
554 : SvXMLImportContext( rImport, nPrfx, rLName ),
555 : sTitle(),
556 : sMessage(),
557 : sMessageType(),
558 : nParagraphCount(0),
559 4 : bDisplay(false)
560 : {
561 4 : pValidationContext = pTempValidationContext;
562 4 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
563 4 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationErrorMessageAttrTokenMap();
564 16 : for( sal_Int16 i=0; i < nAttrCount; ++i )
565 : {
566 12 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
567 24 : OUString aLocalName;
568 12 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
569 12 : sAttrName, &aLocalName );
570 24 : const OUString& sValue(xAttrList->getValueByIndex( i ));
571 :
572 12 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
573 : {
574 : case XML_TOK_ERROR_MESSAGE_ATTR_TITLE:
575 4 : sTitle = sValue;
576 4 : break;
577 : case XML_TOK_ERROR_MESSAGE_ATTR_MESSAGE_TYPE:
578 4 : sMessageType = sValue;
579 4 : break;
580 : case XML_TOK_ERROR_MESSAGE_ATTR_DISPLAY:
581 4 : bDisplay = IsXMLToken(sValue, XML_TRUE);
582 4 : break;
583 : }
584 12 : }
585 4 : }
586 :
587 8 : ScXMLErrorMessageContext::~ScXMLErrorMessageContext()
588 : {
589 8 : }
590 :
591 4 : SvXMLImportContext *ScXMLErrorMessageContext::CreateChildContext( sal_uInt16 nPrefix,
592 : const OUString& rLName,
593 : const ::com::sun::star::uno::Reference<
594 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
595 : {
596 4 : SvXMLImportContext *pContext = 0;
597 :
598 4 : const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationMessageElemTokenMap();
599 4 : switch( rTokenMap.Get( nPrefix, rLName ) )
600 : {
601 : case XML_TOK_P:
602 : {
603 4 : if(nParagraphCount)
604 0 : sMessage.append('\n');
605 4 : ++nParagraphCount;
606 4 : pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLName, xAttrList, sMessage);
607 : }
608 4 : break;
609 : }
610 :
611 4 : if( !pContext )
612 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
613 :
614 4 : return pContext;
615 : }
616 :
617 4 : void ScXMLErrorMessageContext::EndElement()
618 : {
619 4 : pValidationContext->SetErrorMessage(sTitle, sMessage.makeStringAndClear(), sMessageType, bDisplay);
620 4 : }
621 :
622 0 : ScXMLErrorMacroContext::ScXMLErrorMacroContext( ScXMLImport& rImport,
623 : sal_uInt16 nPrfx,
624 : const OUString& rLName,
625 : const ::com::sun::star::uno::Reference<
626 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
627 : ScXMLContentValidationContext* pTempValidationContext) :
628 : SvXMLImportContext( rImport, nPrfx, rLName ),
629 : sName(),
630 0 : bExecute(false)
631 : {
632 0 : pValidationContext = pTempValidationContext;
633 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
634 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationErrorMacroAttrTokenMap();
635 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
636 : {
637 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
638 0 : OUString aLocalName;
639 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
640 0 : sAttrName, &aLocalName );
641 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
642 :
643 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
644 : {
645 : case XML_TOK_ERROR_MACRO_ATTR_NAME:
646 0 : sName = sValue;
647 0 : break;
648 : case XML_TOK_ERROR_MACRO_ATTR_EXECUTE:
649 0 : bExecute = IsXMLToken(sValue, XML_TRUE);
650 0 : break;
651 : }
652 0 : }
653 0 : }
654 :
655 0 : ScXMLErrorMacroContext::~ScXMLErrorMacroContext()
656 : {
657 0 : }
658 :
659 0 : SvXMLImportContext *ScXMLErrorMacroContext::CreateChildContext( sal_uInt16 nPrefix,
660 : const OUString& rLName,
661 : const ::com::sun::star::uno::Reference<
662 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
663 : {
664 0 : SvXMLImportContext *pContext = NULL;
665 :
666 0 : if ((nPrefix == XML_NAMESPACE_SCRIPT) && IsXMLToken(rLName, XML_EVENTS))
667 : {
668 0 : pContext = new XMLEventsImportContext(GetImport(), nPrefix, rLName);
669 : }
670 0 : if (!pContext)
671 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
672 :
673 0 : return pContext;
674 : }
675 :
676 0 : void ScXMLErrorMacroContext::EndElement()
677 : {
678 0 : pValidationContext->SetErrorMacro( bExecute );
679 228 : }
680 :
681 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|