update dev300-m58
[ooovba.git] / sc / source / filter / xml / xmlcvali.cxx
blobb5ab6977fcf7b819df7241317b2db08cd7f4e25c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlcvali.cxx,v $
10 * $Revision: 1.27 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "xmlcvali.hxx"
39 #include "xmlimprt.hxx"
40 #include "xmlconti.hxx"
41 #include "document.hxx"
42 #include "XMLConverter.hxx"
44 #include <xmloff/xmltkmap.hxx>
45 #include <xmloff/nmspmap.hxx>
46 #include <xmloff/xmltoken.hxx>
47 #include <xmloff/xmlnmspe.hxx>
48 #include <xmloff/XMLEventsImportContext.hxx>
49 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
50 #include <tools/debug.hxx>
52 using namespace com::sun::star;
53 using namespace xmloff::token;
54 using namespace ::formula;
55 using ::rtl::OUString;
57 class ScXMLContentValidationContext : public SvXMLImportContext
59 rtl::OUString sName;
60 rtl::OUString sHelpTitle;
61 rtl::OUString sHelpMessage;
62 rtl::OUString sErrorTitle;
63 rtl::OUString sErrorMessage;
64 rtl::OUString sErrorMessageType;
65 rtl::OUString sBaseCellAddress;
66 rtl::OUString sCondition;
67 sal_Int16 nShowList;
68 sal_Bool bAllowEmptyCell;
69 sal_Bool bDisplayHelp;
70 sal_Bool bDisplayError;
72 SvXMLImportContextRef xEventContext;
74 const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
75 ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
77 com::sun::star::sheet::ValidationAlertStyle GetAlertStyle() const;
78 void SetFormula( OUString& rFormula, OUString& rFormulaNmsp, FormulaGrammar::Grammar& reGrammar,
79 const OUString& rCondition, const OUString& rGlobNmsp, FormulaGrammar::Grammar eGlobGrammar, bool bHasNmsp ) const;
80 void GetCondition( ScMyImportValidation& rValidation ) const;
82 public:
84 ScXMLContentValidationContext( ScXMLImport& rImport, USHORT nPrfx,
85 const ::rtl::OUString& rLName,
86 const ::com::sun::star::uno::Reference<
87 ::com::sun::star::xml::sax::XAttributeList>& xAttrList);
89 virtual ~ScXMLContentValidationContext();
91 virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
92 const ::rtl::OUString& rLocalName,
93 const ::com::sun::star::uno::Reference<
94 ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
96 virtual void EndElement();
98 void SetHelpMessage(const rtl::OUString& sTitle, const rtl::OUString& sMessage, const sal_Bool bDisplay);
99 void SetErrorMessage(const rtl::OUString& sTitle, const rtl::OUString& sMessage, const rtl::OUString& sMessageType, const sal_Bool bDisplay);
100 void SetErrorMacro(const sal_Bool bExecute);
103 class ScXMLHelpMessageContext : public SvXMLImportContext
105 rtl::OUString sTitle;
106 rtl::OUStringBuffer sMessage;
107 sal_Int32 nParagraphCount;
108 sal_Bool bDisplay;
110 ScXMLContentValidationContext* pValidationContext;
112 const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
113 ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
115 public:
117 ScXMLHelpMessageContext( ScXMLImport& rImport, USHORT nPrfx,
118 const ::rtl::OUString& rLName,
119 const ::com::sun::star::uno::Reference<
120 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
121 ScXMLContentValidationContext* pValidationContext);
123 virtual ~ScXMLHelpMessageContext();
125 virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
126 const ::rtl::OUString& rLocalName,
127 const ::com::sun::star::uno::Reference<
128 ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
130 virtual void EndElement();
133 class ScXMLErrorMessageContext : public SvXMLImportContext
135 rtl::OUString sTitle;
136 rtl::OUStringBuffer sMessage;
137 rtl::OUString sMessageType;
138 sal_Int32 nParagraphCount;
139 sal_Bool bDisplay;
141 ScXMLContentValidationContext* pValidationContext;
143 const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
144 ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
146 public:
148 ScXMLErrorMessageContext( ScXMLImport& rImport, USHORT nPrfx,
149 const ::rtl::OUString& rLName,
150 const ::com::sun::star::uno::Reference<
151 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
152 ScXMLContentValidationContext* pValidationContext);
154 virtual ~ScXMLErrorMessageContext();
156 virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
157 const ::rtl::OUString& rLocalName,
158 const ::com::sun::star::uno::Reference<
159 ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
161 virtual void EndElement();
164 class ScXMLErrorMacroContext : public SvXMLImportContext
166 rtl::OUString sName;
167 sal_Bool bExecute;
169 ScXMLContentValidationContext* pValidationContext;
171 const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
172 ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
174 public:
176 ScXMLErrorMacroContext( ScXMLImport& rImport, USHORT nPrfx,
177 const ::rtl::OUString& rLName,
178 const ::com::sun::star::uno::Reference<
179 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
180 ScXMLContentValidationContext* pValidationContext);
182 virtual ~ScXMLErrorMacroContext();
184 virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
185 const ::rtl::OUString& rLocalName,
186 const ::com::sun::star::uno::Reference<
187 ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
188 virtual void EndElement();
191 //------------------------------------------------------------------
193 ScXMLContentValidationsContext::ScXMLContentValidationsContext( ScXMLImport& rImport,
194 USHORT nPrfx,
195 const ::rtl::OUString& rLName,
196 const ::com::sun::star::uno::Reference<
197 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
198 SvXMLImportContext( rImport, nPrfx, rLName )
200 // here are no attributes
203 ScXMLContentValidationsContext::~ScXMLContentValidationsContext()
207 SvXMLImportContext *ScXMLContentValidationsContext::CreateChildContext( USHORT nPrefix,
208 const ::rtl::OUString& rLName,
209 const ::com::sun::star::uno::Reference<
210 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
212 SvXMLImportContext *pContext = 0;
214 const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationsElemTokenMap();
215 switch( rTokenMap.Get( nPrefix, rLName ) )
217 case XML_TOK_CONTENT_VALIDATION:
218 pContext = new ScXMLContentValidationContext( GetScImport(), nPrefix, rLName, xAttrList);
219 break;
222 if( !pContext )
223 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
225 return pContext;
228 void ScXMLContentValidationsContext::EndElement()
232 ScXMLContentValidationContext::ScXMLContentValidationContext( ScXMLImport& rImport,
233 USHORT nPrfx,
234 const ::rtl::OUString& rLName,
235 const ::com::sun::star::uno::Reference<
236 ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
237 SvXMLImportContext( rImport, nPrfx, rLName ),
238 nShowList(sheet::TableValidationVisibility::UNSORTED),
239 bAllowEmptyCell(sal_True),
240 bDisplayHelp(sal_False),
241 bDisplayError(sal_False)
243 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
244 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationAttrTokenMap();
245 for( sal_Int16 i=0; i < nAttrCount; ++i )
247 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
248 rtl::OUString aLocalName;
249 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
250 sAttrName, &aLocalName );
251 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
253 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
255 case XML_TOK_CONTENT_VALIDATION_NAME:
256 sName = sValue;
257 break;
258 case XML_TOK_CONTENT_VALIDATION_CONDITION:
259 sCondition = sValue;
260 break;
261 case XML_TOK_CONTENT_VALIDATION_BASE_CELL_ADDRESS:
262 sBaseCellAddress = sValue;
263 break;
264 case XML_TOK_CONTENT_VALIDATION_ALLOW_EMPTY_CELL:
265 if (IsXMLToken(sValue, XML_FALSE))
266 bAllowEmptyCell = sal_False;
267 break;
268 case XML_TOK_CONTENT_VALIDATION_DISPLAY_LIST:
270 if (IsXMLToken(sValue, XML_NO))
272 nShowList = sheet::TableValidationVisibility::INVISIBLE;
274 else if (IsXMLToken(sValue, XML_UNSORTED))
276 nShowList = sheet::TableValidationVisibility::UNSORTED;
278 else if (IsXMLToken(sValue, XML_SORTED_ASCENDING))
280 nShowList = sheet::TableValidationVisibility::SORTEDASCENDING;
283 break;
288 ScXMLContentValidationContext::~ScXMLContentValidationContext()
292 SvXMLImportContext *ScXMLContentValidationContext::CreateChildContext( USHORT nPrefix,
293 const ::rtl::OUString& rLName,
294 const ::com::sun::star::uno::Reference<
295 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
297 SvXMLImportContext *pContext = 0;
299 const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationElemTokenMap();
300 switch( rTokenMap.Get( nPrefix, rLName ) )
302 case XML_TOK_CONTENT_VALIDATION_ELEM_HELP_MESSAGE:
303 pContext = new ScXMLHelpMessageContext( GetScImport(), nPrefix, rLName, xAttrList, this);
304 break;
305 case XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MESSAGE:
306 pContext = new ScXMLErrorMessageContext( GetScImport(), nPrefix, rLName, xAttrList, this);
307 break;
308 case XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MACRO:
309 pContext = new ScXMLErrorMacroContext( GetScImport(), nPrefix, rLName, xAttrList, this);
310 break;
311 case XML_TOK_CONTENT_VALIDATION_ELEM_EVENT_LISTENERS:
312 pContext = new XMLEventsImportContext( GetImport(), nPrefix, rLName );
313 xEventContext = pContext;
314 break;
317 if( !pContext )
318 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
320 return pContext;
323 sheet::ValidationAlertStyle ScXMLContentValidationContext::GetAlertStyle() const
325 if (IsXMLToken(sErrorMessageType, XML_MACRO))
326 return sheet::ValidationAlertStyle_MACRO;
327 if (IsXMLToken(sErrorMessageType, XML_STOP))
328 return sheet::ValidationAlertStyle_STOP;
329 if (IsXMLToken(sErrorMessageType, XML_WARNING))
330 return sheet::ValidationAlertStyle_WARNING;
331 if (IsXMLToken(sErrorMessageType, XML_INFORMATION))
332 return sheet::ValidationAlertStyle_INFO;
333 // default for unknown
334 return sheet::ValidationAlertStyle_STOP;
337 void ScXMLContentValidationContext::SetFormula( OUString& rFormula, OUString& rFormulaNmsp, FormulaGrammar::Grammar& reGrammar,
338 const OUString& rCondition, const OUString& rGlobNmsp, FormulaGrammar::Grammar eGlobGrammar, bool bHasNmsp ) const
340 reGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
341 if( bHasNmsp )
343 // the entire attribute contains a namespace: internal namespace not allowed
344 rFormula = rCondition;
345 rFormulaNmsp = rGlobNmsp;
346 reGrammar = eGlobGrammar;
348 else
350 // the attribute does not contain a namespace: try to find a namespace of an external grammar
351 GetScImport().ExtractFormulaNamespaceGrammar( rFormula, rFormulaNmsp, reGrammar, rCondition, true );
352 if( reGrammar != FormulaGrammar::GRAM_EXTERNAL )
353 reGrammar = eGlobGrammar;
357 void ScXMLContentValidationContext::GetCondition( ScMyImportValidation& rValidation ) const
359 rValidation.aValidationType = sheet::ValidationType_ANY; // #b6343997# default if no condition is given
360 rValidation.aOperator = sheet::ConditionOperator_NONE;
362 if( sCondition.getLength() > 0 )
364 // extract leading namespace from condition string
365 OUString aCondition, aConditionNmsp;
366 FormulaGrammar::Grammar eGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
367 GetScImport().ExtractFormulaNamespaceGrammar( aCondition, aConditionNmsp, eGrammar, sCondition );
368 bool bHasNmsp = aCondition.getLength() < sCondition.getLength();
370 // parse a condition from the attribute string
371 ScXMLConditionParseResult aParseResult;
372 ScXMLConditionHelper::parseCondition( aParseResult, aCondition, 0 );
374 /* Check the result. A valid value in aParseResult.meToken implies
375 that the other members of aParseResult are filled with valid data
376 for that token. */
377 bool bSecondaryPart = false;
378 switch( aParseResult.meToken )
380 case XML_COND_TEXTLENGTH: // condition is 'cell-content-text-length()<operator><expression>'
381 case XML_COND_TEXTLENGTH_ISBETWEEN: // condition is 'cell-content-text-length-is-between(<expression1>,<expression2>)'
382 case XML_COND_TEXTLENGTH_ISNOTBETWEEN: // condition is 'cell-content-text-length-is-not-between(<expression1>,<expression2>)'
383 case XML_COND_ISINLIST: // condition is 'cell-content-is-in-list(<expression>)'
384 rValidation.aValidationType = aParseResult.meValidation;
385 rValidation.aOperator = aParseResult.meOperator;
386 break;
388 case XML_COND_ISWHOLENUMBER: // condition is 'cell-content-is-whole-number() and <condition>'
389 case XML_COND_ISDECIMALNUMBER: // condition is 'cell-content-is-decimal-number() and <condition>'
390 case XML_COND_ISDATE: // condition is 'cell-content-is-date() and <condition>'
391 case XML_COND_ISTIME: // condition is 'cell-content-is-time() and <condition>'
392 rValidation.aValidationType = aParseResult.meValidation;
393 bSecondaryPart = true;
394 break;
396 default:; // unacceptable or unknown condition
399 /* Parse the following 'and <condition>' part of some conditions. This
400 updates the members of aParseResult that will contain the operands
401 and comparison operator then. */
402 if( bSecondaryPart )
404 ScXMLConditionHelper::parseCondition( aParseResult, aCondition, aParseResult.mnEndIndex );
405 if( aParseResult.meToken == XML_COND_AND )
407 ScXMLConditionHelper::parseCondition( aParseResult, aCondition, aParseResult.mnEndIndex );
408 switch( aParseResult.meToken )
410 case XML_COND_CELLCONTENT: // condition is 'and cell-content()<operator><expression>'
411 case XML_COND_ISBETWEEN: // condition is 'and cell-content-is-between(<expression1>,<expression2>)'
412 case XML_COND_ISNOTBETWEEN: // condition is 'and cell-content-is-not-between(<expression1>,<expression2>)'
413 rValidation.aOperator = aParseResult.meOperator;
414 break;
415 default:; // unacceptable or unknown condition
420 // a validation type (date, integer) without a condition isn't possible
421 if( rValidation.aOperator == sheet::ConditionOperator_NONE )
422 rValidation.aValidationType = sheet::ValidationType_ANY;
424 // parse the formulas
425 if( rValidation.aValidationType != sheet::ValidationType_ANY )
427 SetFormula( rValidation.sFormula1, rValidation.sFormulaNmsp1, rValidation.eGrammar1,
428 aParseResult.maOperand1, aConditionNmsp, eGrammar, bHasNmsp );
429 SetFormula( rValidation.sFormula2, rValidation.sFormulaNmsp2, rValidation.eGrammar2,
430 aParseResult.maOperand2, aConditionNmsp, eGrammar, bHasNmsp );
435 void ScXMLContentValidationContext::EndElement()
437 // #i36650# event-listeners element moved up one level
438 if (xEventContext.Is())
440 rtl::OUString sOnError(RTL_CONSTASCII_USTRINGPARAM("OnError"));
441 XMLEventsImportContext* pEvents =
442 (XMLEventsImportContext*)&xEventContext;
443 uno::Sequence<beans::PropertyValue> aValues;
444 pEvents->GetEventSequence( sOnError, aValues );
446 sal_Int32 nLength = aValues.getLength();
447 for( sal_Int32 i = 0; i < nLength; i++ )
449 // #i47525# must allow "MacroName" or "Script"
450 if ( aValues[i].Name.equalsAsciiL( "MacroName", sizeof("MacroName")-1 ) ||
451 aValues[i].Name.equalsAsciiL( "Script", sizeof("Script")-1 ) )
453 aValues[i].Value >>= sErrorTitle;
454 break;
459 ScMyImportValidation aValidation;
460 aValidation.eGrammar1 = aValidation.eGrammar2 = GetScImport().GetDocument()->GetStorageGrammar();
461 aValidation.sName = sName;
462 aValidation.sBaseCellAddress = sBaseCellAddress;
463 aValidation.sImputTitle = sHelpTitle;
464 aValidation.sImputMessage = sHelpMessage;
465 aValidation.sErrorTitle = sErrorTitle;
466 aValidation.sErrorMessage = sErrorMessage;
467 GetCondition( aValidation );
468 aValidation.aAlertStyle = GetAlertStyle();
469 aValidation.bShowErrorMessage = bDisplayError;
470 aValidation.bShowImputMessage = bDisplayHelp;
471 aValidation.bIgnoreBlanks = bAllowEmptyCell;
472 aValidation.nShowList = nShowList;
473 GetScImport().AddValidation(aValidation);
476 void ScXMLContentValidationContext::SetHelpMessage(const rtl::OUString& sTitle, const rtl::OUString& sMessage, const sal_Bool bDisplay)
478 sHelpTitle = sTitle;
479 sHelpMessage = sMessage;
480 bDisplayHelp = bDisplay;
483 void ScXMLContentValidationContext::SetErrorMessage(const rtl::OUString& sTitle, const rtl::OUString& sMessage,
484 const rtl::OUString& sMessageType, const sal_Bool bDisplay)
486 sErrorTitle = sTitle;
487 sErrorMessage = sMessage;
488 sErrorMessageType = sMessageType;
489 bDisplayError = bDisplay;
492 void ScXMLContentValidationContext::SetErrorMacro(const sal_Bool bExecute)
494 sErrorMessageType = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("macro"));
495 bDisplayError = bExecute;
498 ScXMLHelpMessageContext::ScXMLHelpMessageContext( ScXMLImport& rImport,
499 USHORT nPrfx,
500 const ::rtl::OUString& rLName,
501 const ::com::sun::star::uno::Reference<
502 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
503 ScXMLContentValidationContext* pTempValidationContext) :
504 SvXMLImportContext( rImport, nPrfx, rLName ),
505 sTitle(),
506 sMessage(),
507 nParagraphCount(0),
508 bDisplay(sal_False)
510 pValidationContext = pTempValidationContext;
511 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
512 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationHelpMessageAttrTokenMap();
513 for( sal_Int16 i=0; i < nAttrCount; ++i )
515 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
516 rtl::OUString aLocalName;
517 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
518 sAttrName, &aLocalName );
519 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
521 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
523 case XML_TOK_HELP_MESSAGE_ATTR_TITLE:
524 sTitle = sValue;
525 break;
526 case XML_TOK_HELP_MESSAGE_ATTR_DISPLAY:
527 bDisplay = IsXMLToken(sValue, XML_TRUE);
528 break;
533 ScXMLHelpMessageContext::~ScXMLHelpMessageContext()
537 SvXMLImportContext *ScXMLHelpMessageContext::CreateChildContext( USHORT nPrefix,
538 const ::rtl::OUString& rLName,
539 const ::com::sun::star::uno::Reference<
540 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
542 SvXMLImportContext *pContext = 0;
544 const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationMessageElemTokenMap();
545 switch( rTokenMap.Get( nPrefix, rLName ) )
547 case XML_TOK_P:
549 if(nParagraphCount)
550 sMessage.append(static_cast<sal_Unicode>('\n'));
551 ++nParagraphCount;
552 pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLName, xAttrList, sMessage);
554 break;
557 if( !pContext )
558 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
560 return pContext;
563 void ScXMLHelpMessageContext::EndElement()
565 pValidationContext->SetHelpMessage(sTitle, sMessage.makeStringAndClear(), bDisplay);
568 ScXMLErrorMessageContext::ScXMLErrorMessageContext( ScXMLImport& rImport,
569 USHORT nPrfx,
570 const ::rtl::OUString& rLName,
571 const ::com::sun::star::uno::Reference<
572 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
573 ScXMLContentValidationContext* pTempValidationContext) :
574 SvXMLImportContext( rImport, nPrfx, rLName ),
575 sTitle(),
576 sMessage(),
577 sMessageType(),
578 nParagraphCount(0),
579 bDisplay(sal_False)
581 pValidationContext = pTempValidationContext;
582 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
583 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationErrorMessageAttrTokenMap();
584 for( sal_Int16 i=0; i < nAttrCount; ++i )
586 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
587 rtl::OUString aLocalName;
588 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
589 sAttrName, &aLocalName );
590 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
592 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
594 case XML_TOK_ERROR_MESSAGE_ATTR_TITLE:
595 sTitle = sValue;
596 break;
597 case XML_TOK_ERROR_MESSAGE_ATTR_MESSAGE_TYPE:
598 sMessageType = sValue;
599 break;
600 case XML_TOK_ERROR_MESSAGE_ATTR_DISPLAY:
601 bDisplay = IsXMLToken(sValue, XML_TRUE);
602 break;
607 ScXMLErrorMessageContext::~ScXMLErrorMessageContext()
611 SvXMLImportContext *ScXMLErrorMessageContext::CreateChildContext( USHORT nPrefix,
612 const ::rtl::OUString& rLName,
613 const ::com::sun::star::uno::Reference<
614 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
616 SvXMLImportContext *pContext = 0;
618 const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationMessageElemTokenMap();
619 switch( rTokenMap.Get( nPrefix, rLName ) )
621 case XML_TOK_P:
623 if(nParagraphCount)
624 sMessage.append(static_cast<sal_Unicode>('\n'));
625 ++nParagraphCount;
626 pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLName, xAttrList, sMessage);
628 break;
631 if( !pContext )
632 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
634 return pContext;
637 void ScXMLErrorMessageContext::EndElement()
639 pValidationContext->SetErrorMessage(sTitle, sMessage.makeStringAndClear(), sMessageType, bDisplay);
642 ScXMLErrorMacroContext::ScXMLErrorMacroContext( ScXMLImport& rImport,
643 USHORT nPrfx,
644 const ::rtl::OUString& rLName,
645 const ::com::sun::star::uno::Reference<
646 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
647 ScXMLContentValidationContext* pTempValidationContext) :
648 SvXMLImportContext( rImport, nPrfx, rLName ),
649 sName(),
650 bExecute(sal_False)
652 pValidationContext = pTempValidationContext;
653 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
654 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationErrorMacroAttrTokenMap();
655 for( sal_Int16 i=0; i < nAttrCount; ++i )
657 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
658 rtl::OUString aLocalName;
659 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
660 sAttrName, &aLocalName );
661 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
663 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
665 case XML_TOK_ERROR_MACRO_ATTR_NAME:
666 sName = sValue;
667 break;
668 case XML_TOK_ERROR_MACRO_ATTR_EXECUTE:
669 bExecute = IsXMLToken(sValue, XML_TRUE);
670 break;
675 ScXMLErrorMacroContext::~ScXMLErrorMacroContext()
679 SvXMLImportContext *ScXMLErrorMacroContext::CreateChildContext( USHORT nPrefix,
680 const ::rtl::OUString& rLName,
681 const ::com::sun::star::uno::Reference<
682 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
684 SvXMLImportContext *pContext = NULL;
686 if ((nPrefix == XML_NAMESPACE_SCRIPT) && IsXMLToken(rLName, XML_EVENTS))
688 pContext = new XMLEventsImportContext(GetImport(), nPrefix, rLName);
690 if (!pContext)
691 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
693 return pContext;
696 void ScXMLErrorMacroContext::EndElement()
698 pValidationContext->SetErrorMacro( bExecute );