fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / xml / xmlcvali.cxx
blob0c616f1b5cc837f2e8e4b974e04132056ec043e0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "xmlcvali.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlconti.hxx"
23 #include "document.hxx"
24 #include "XMLConverter.hxx"
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>
33 using namespace com::sun::star;
34 using namespace xmloff::token;
35 using namespace ::formula;
37 class ScXMLContentValidationContext : public SvXMLImportContext
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;
52 SvXMLImportContextRef xEventContext;
54 const ScXMLImport& GetScImport() const { return static_cast<const ScXMLImport&>(GetImport()); }
55 ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
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;
62 public:
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);
69 virtual ~ScXMLContentValidationContext();
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;
76 virtual void EndElement() SAL_OVERRIDE;
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);
83 class ScXMLHelpMessageContext : public SvXMLImportContext
85 OUString sTitle;
86 OUStringBuffer sMessage;
87 sal_Int32 nParagraphCount;
88 bool bDisplay;
90 ScXMLContentValidationContext* pValidationContext;
92 ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
94 public:
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);
102 virtual ~ScXMLHelpMessageContext();
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;
109 virtual void EndElement() SAL_OVERRIDE;
112 class ScXMLErrorMessageContext : public SvXMLImportContext
114 OUString sTitle;
115 OUStringBuffer sMessage;
116 OUString sMessageType;
117 sal_Int32 nParagraphCount;
118 bool bDisplay;
120 ScXMLContentValidationContext* pValidationContext;
122 ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
124 public:
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);
132 virtual ~ScXMLErrorMessageContext();
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;
139 virtual void EndElement() SAL_OVERRIDE;
142 class ScXMLErrorMacroContext : public SvXMLImportContext
144 OUString sName;
145 bool bExecute;
147 ScXMLContentValidationContext* pValidationContext;
149 ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
151 public:
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);
159 virtual ~ScXMLErrorMacroContext();
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;
168 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 SvXMLImportContext( rImport, nPrfx, rLName )
175 // here are no attributes
178 ScXMLContentValidationsContext::~ScXMLContentValidationsContext()
182 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 )
187 SvXMLImportContext *pContext = 0;
189 const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationsElemTokenMap();
190 switch( rTokenMap.Get( nPrefix, rLName ) )
192 case XML_TOK_CONTENT_VALIDATION:
193 pContext = new ScXMLContentValidationContext( GetScImport(), nPrefix, rLName, xAttrList);
194 break;
197 if( !pContext )
198 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
200 return pContext;
203 void ScXMLContentValidationsContext::EndElement()
207 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 bDisplayError(false)
218 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
219 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationAttrTokenMap();
220 for( sal_Int16 i=0; i < nAttrCount; ++i )
222 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
223 OUString aLocalName;
224 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
225 sAttrName, &aLocalName );
226 const OUString& sValue(xAttrList->getValueByIndex( i ));
228 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
230 case XML_TOK_CONTENT_VALIDATION_NAME:
231 sName = sValue;
232 break;
233 case XML_TOK_CONTENT_VALIDATION_CONDITION:
234 sCondition = sValue;
235 break;
236 case XML_TOK_CONTENT_VALIDATION_BASE_CELL_ADDRESS:
237 sBaseCellAddress = sValue;
238 break;
239 case XML_TOK_CONTENT_VALIDATION_ALLOW_EMPTY_CELL:
240 if (IsXMLToken(sValue, XML_FALSE))
241 bAllowEmptyCell = false;
242 break;
243 case XML_TOK_CONTENT_VALIDATION_DISPLAY_LIST:
245 if (IsXMLToken(sValue, XML_NO))
247 nShowList = sheet::TableValidationVisibility::INVISIBLE;
249 else if (IsXMLToken(sValue, XML_UNSORTED))
251 nShowList = sheet::TableValidationVisibility::UNSORTED;
253 else if (IsXMLToken(sValue, XML_SORT_ASCENDING))
255 nShowList = sheet::TableValidationVisibility::SORTEDASCENDING;
257 else if (IsXMLToken(sValue, XML_SORTED_ASCENDING))
259 // Read old wrong value, fdo#72548
260 nShowList = sheet::TableValidationVisibility::SORTEDASCENDING;
263 break;
268 ScXMLContentValidationContext::~ScXMLContentValidationContext()
272 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 )
277 SvXMLImportContext *pContext = 0;
279 const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationElemTokenMap();
280 switch( rTokenMap.Get( nPrefix, rLName ) )
282 case XML_TOK_CONTENT_VALIDATION_ELEM_HELP_MESSAGE:
283 pContext = new ScXMLHelpMessageContext( GetScImport(), nPrefix, rLName, xAttrList, this);
284 break;
285 case XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MESSAGE:
286 pContext = new ScXMLErrorMessageContext( GetScImport(), nPrefix, rLName, xAttrList, this);
287 break;
288 case XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MACRO:
289 pContext = new ScXMLErrorMacroContext( GetScImport(), nPrefix, rLName, xAttrList, this);
290 break;
291 case XML_TOK_CONTENT_VALIDATION_ELEM_EVENT_LISTENERS:
292 pContext = new XMLEventsImportContext( GetImport(), nPrefix, rLName );
293 xEventContext = pContext;
294 break;
297 if( !pContext )
298 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
300 return pContext;
303 sheet::ValidationAlertStyle ScXMLContentValidationContext::GetAlertStyle() const
305 if (IsXMLToken(sErrorMessageType, XML_MACRO))
306 return sheet::ValidationAlertStyle_MACRO;
307 if (IsXMLToken(sErrorMessageType, XML_STOP))
308 return sheet::ValidationAlertStyle_STOP;
309 if (IsXMLToken(sErrorMessageType, XML_WARNING))
310 return sheet::ValidationAlertStyle_WARNING;
311 if (IsXMLToken(sErrorMessageType, XML_INFORMATION))
312 return sheet::ValidationAlertStyle_INFO;
313 // default for unknown
314 return sheet::ValidationAlertStyle_STOP;
317 void ScXMLContentValidationContext::SetFormula( OUString& rFormula, OUString& rFormulaNmsp, FormulaGrammar::Grammar& reGrammar,
318 const OUString& rCondition, const OUString& rGlobNmsp, FormulaGrammar::Grammar eGlobGrammar, bool bHasNmsp ) const
320 reGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
321 if( bHasNmsp )
323 // the entire attribute contains a namespace: internal namespace not allowed
324 rFormula = rCondition;
325 rFormulaNmsp = rGlobNmsp;
326 reGrammar = eGlobGrammar;
328 else
330 // the attribute does not contain a namespace: try to find a namespace of an external grammar
331 GetScImport().ExtractFormulaNamespaceGrammar( rFormula, rFormulaNmsp, reGrammar, rCondition, true );
332 if( reGrammar != FormulaGrammar::GRAM_EXTERNAL )
333 reGrammar = eGlobGrammar;
337 void ScXMLContentValidationContext::GetCondition( ScMyImportValidation& rValidation ) const
339 rValidation.aValidationType = sheet::ValidationType_ANY; // default if no condition is given
340 rValidation.aOperator = sheet::ConditionOperator_NONE;
342 if( !sCondition.isEmpty() )
344 // extract leading namespace from condition string
345 OUString aCondition, aConditionNmsp;
346 FormulaGrammar::Grammar eGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
347 GetScImport().ExtractFormulaNamespaceGrammar( aCondition, aConditionNmsp, eGrammar, sCondition );
348 bool bHasNmsp = aCondition.getLength() < sCondition.getLength();
350 // parse a condition from the attribute string
351 ScXMLConditionParseResult aParseResult;
352 ScXMLConditionHelper::parseCondition( aParseResult, aCondition, 0 );
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 bool bSecondaryPart = false;
358 switch( aParseResult.meToken )
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 rValidation.aValidationType = aParseResult.meValidation;
365 rValidation.aOperator = aParseResult.meOperator;
366 break;
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 rValidation.aValidationType = aParseResult.meValidation;
373 bSecondaryPart = true;
374 break;
376 default:; // unacceptable or unknown condition
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 if( bSecondaryPart )
384 ScXMLConditionHelper::parseCondition( aParseResult, aCondition, aParseResult.mnEndIndex );
385 if( aParseResult.meToken == XML_COND_AND )
387 ScXMLConditionHelper::parseCondition( aParseResult, aCondition, aParseResult.mnEndIndex );
388 switch( aParseResult.meToken )
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 rValidation.aOperator = aParseResult.meOperator;
394 break;
395 default:; // unacceptable or unknown condition
400 // a validation type (date, integer) without a condition isn't possible
401 if( rValidation.aOperator == sheet::ConditionOperator_NONE )
402 rValidation.aValidationType = sheet::ValidationType_ANY;
404 // parse the formulas
405 if( rValidation.aValidationType != sheet::ValidationType_ANY )
407 SetFormula( rValidation.sFormula1, rValidation.sFormulaNmsp1, rValidation.eGrammar1,
408 aParseResult.maOperand1, aConditionNmsp, eGrammar, bHasNmsp );
409 SetFormula( rValidation.sFormula2, rValidation.sFormulaNmsp2, rValidation.eGrammar2,
410 aParseResult.maOperand2, aConditionNmsp, eGrammar, bHasNmsp );
415 void ScXMLContentValidationContext::EndElement()
417 // #i36650# event-listeners element moved up one level
418 if (xEventContext.Is())
420 OUString sOnError("OnError");
421 XMLEventsImportContext* pEvents =
422 static_cast<XMLEventsImportContext*>(&xEventContext);
423 uno::Sequence<beans::PropertyValue> aValues;
424 pEvents->GetEventSequence( sOnError, aValues );
426 sal_Int32 nLength = aValues.getLength();
427 for( sal_Int32 i = 0; i < nLength; i++ )
429 // #i47525# must allow "MacroName" or "Script"
430 if ( aValues[i].Name == "MacroName" ||
431 aValues[i].Name == "Script" )
433 aValues[i].Value >>= sErrorTitle;
434 break;
439 ScMyImportValidation aValidation;
440 aValidation.eGrammar1 = aValidation.eGrammar2 = GetScImport().GetDocument()->GetStorageGrammar();
441 aValidation.sName = sName;
442 aValidation.sBaseCellAddress = sBaseCellAddress;
443 aValidation.sImputTitle = sHelpTitle;
444 aValidation.sImputMessage = sHelpMessage;
445 aValidation.sErrorTitle = sErrorTitle;
446 aValidation.sErrorMessage = sErrorMessage;
447 GetCondition( aValidation );
448 aValidation.aAlertStyle = GetAlertStyle();
449 aValidation.bShowErrorMessage = bDisplayError;
450 aValidation.bShowImputMessage = bDisplayHelp;
451 aValidation.bIgnoreBlanks = bAllowEmptyCell;
452 aValidation.nShowList = nShowList;
453 GetScImport().AddValidation(aValidation);
456 void ScXMLContentValidationContext::SetHelpMessage(const OUString& sTitle, const OUString& sMessage, const bool bDisplay)
458 sHelpTitle = sTitle;
459 sHelpMessage = sMessage;
460 bDisplayHelp = bDisplay;
463 void ScXMLContentValidationContext::SetErrorMessage(const OUString& sTitle, const OUString& sMessage,
464 const OUString& sMessageType, const bool bDisplay)
466 sErrorTitle = sTitle;
467 sErrorMessage = sMessage;
468 sErrorMessageType = sMessageType;
469 bDisplayError = bDisplay;
472 void ScXMLContentValidationContext::SetErrorMacro(const bool bExecute)
474 sErrorMessageType = "macro";
475 bDisplayError = bExecute;
478 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 bDisplay(false)
490 pValidationContext = pTempValidationContext;
491 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
492 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationHelpMessageAttrTokenMap();
493 for( sal_Int16 i=0; i < nAttrCount; ++i )
495 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
496 OUString aLocalName;
497 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
498 sAttrName, &aLocalName );
499 const OUString& sValue(xAttrList->getValueByIndex( i ));
501 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
503 case XML_TOK_HELP_MESSAGE_ATTR_TITLE:
504 sTitle = sValue;
505 break;
506 case XML_TOK_HELP_MESSAGE_ATTR_DISPLAY:
507 bDisplay = IsXMLToken(sValue, XML_TRUE);
508 break;
513 ScXMLHelpMessageContext::~ScXMLHelpMessageContext()
517 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 )
522 SvXMLImportContext *pContext = 0;
524 const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationMessageElemTokenMap();
525 switch( rTokenMap.Get( nPrefix, rLName ) )
527 case XML_TOK_P:
529 if(nParagraphCount)
530 sMessage.append('\n');
531 ++nParagraphCount;
532 pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLName, xAttrList, sMessage);
534 break;
537 if( !pContext )
538 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
540 return pContext;
543 void ScXMLHelpMessageContext::EndElement()
545 pValidationContext->SetHelpMessage(sTitle, sMessage.makeStringAndClear(), bDisplay);
548 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 bDisplay(false)
561 pValidationContext = pTempValidationContext;
562 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
563 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationErrorMessageAttrTokenMap();
564 for( sal_Int16 i=0; i < nAttrCount; ++i )
566 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
567 OUString aLocalName;
568 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
569 sAttrName, &aLocalName );
570 const OUString& sValue(xAttrList->getValueByIndex( i ));
572 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
574 case XML_TOK_ERROR_MESSAGE_ATTR_TITLE:
575 sTitle = sValue;
576 break;
577 case XML_TOK_ERROR_MESSAGE_ATTR_MESSAGE_TYPE:
578 sMessageType = sValue;
579 break;
580 case XML_TOK_ERROR_MESSAGE_ATTR_DISPLAY:
581 bDisplay = IsXMLToken(sValue, XML_TRUE);
582 break;
587 ScXMLErrorMessageContext::~ScXMLErrorMessageContext()
591 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 )
596 SvXMLImportContext *pContext = 0;
598 const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationMessageElemTokenMap();
599 switch( rTokenMap.Get( nPrefix, rLName ) )
601 case XML_TOK_P:
603 if(nParagraphCount)
604 sMessage.append('\n');
605 ++nParagraphCount;
606 pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLName, xAttrList, sMessage);
608 break;
611 if( !pContext )
612 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
614 return pContext;
617 void ScXMLErrorMessageContext::EndElement()
619 pValidationContext->SetErrorMessage(sTitle, sMessage.makeStringAndClear(), sMessageType, bDisplay);
622 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 bExecute(false)
632 pValidationContext = pTempValidationContext;
633 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
634 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationErrorMacroAttrTokenMap();
635 for( sal_Int16 i=0; i < nAttrCount; ++i )
637 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
638 OUString aLocalName;
639 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
640 sAttrName, &aLocalName );
641 const OUString& sValue(xAttrList->getValueByIndex( i ));
643 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
645 case XML_TOK_ERROR_MACRO_ATTR_NAME:
646 sName = sValue;
647 break;
648 case XML_TOK_ERROR_MACRO_ATTR_EXECUTE:
649 bExecute = IsXMLToken(sValue, XML_TRUE);
650 break;
655 ScXMLErrorMacroContext::~ScXMLErrorMacroContext()
659 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 */ )
664 SvXMLImportContext *pContext = NULL;
666 if ((nPrefix == XML_NAMESPACE_SCRIPT) && IsXMLToken(rLName, XML_EVENTS))
668 pContext = new XMLEventsImportContext(GetImport(), nPrefix, rLName);
670 if (!pContext)
671 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
673 return pContext;
676 void ScXMLErrorMacroContext::EndElement()
678 pValidationContext->SetErrorMacro( bExecute );
681 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */