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 $
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
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
;
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;
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
;
110 ScXMLContentValidationContext
* pValidationContext
;
112 const ScXMLImport
& GetScImport() const { return (const ScXMLImport
&)GetImport(); }
113 ScXMLImport
& GetScImport() { return (ScXMLImport
&)GetImport(); }
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
;
141 ScXMLContentValidationContext
* pValidationContext
;
143 const ScXMLImport
& GetScImport() const { return (const ScXMLImport
&)GetImport(); }
144 ScXMLImport
& GetScImport() { return (ScXMLImport
&)GetImport(); }
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
169 ScXMLContentValidationContext
* pValidationContext
;
171 const ScXMLImport
& GetScImport() const { return (const ScXMLImport
&)GetImport(); }
172 ScXMLImport
& GetScImport() { return (ScXMLImport
&)GetImport(); }
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
,
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
);
223 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
228 void ScXMLContentValidationsContext::EndElement()
232 ScXMLContentValidationContext::ScXMLContentValidationContext( ScXMLImport
& rImport
,
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
:
258 case XML_TOK_CONTENT_VALIDATION_CONDITION
:
261 case XML_TOK_CONTENT_VALIDATION_BASE_CELL_ADDRESS
:
262 sBaseCellAddress
= sValue
;
264 case XML_TOK_CONTENT_VALIDATION_ALLOW_EMPTY_CELL
:
265 if (IsXMLToken(sValue
, XML_FALSE
))
266 bAllowEmptyCell
= sal_False
;
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
;
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);
305 case XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MESSAGE
:
306 pContext
= new ScXMLErrorMessageContext( GetScImport(), nPrefix
, rLName
, xAttrList
, this);
308 case XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MACRO
:
309 pContext
= new ScXMLErrorMacroContext( GetScImport(), nPrefix
, rLName
, xAttrList
, this);
311 case XML_TOK_CONTENT_VALIDATION_ELEM_EVENT_LISTENERS
:
312 pContext
= new XMLEventsImportContext( GetImport(), nPrefix
, rLName
);
313 xEventContext
= pContext
;
318 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
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
;
343 // the entire attribute contains a namespace: internal namespace not allowed
344 rFormula
= rCondition
;
345 rFormulaNmsp
= rGlobNmsp
;
346 reGrammar
= eGlobGrammar
;
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
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
;
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;
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. */
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
;
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
;
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
)
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
,
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
),
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
:
526 case XML_TOK_HELP_MESSAGE_ATTR_DISPLAY
:
527 bDisplay
= IsXMLToken(sValue
, XML_TRUE
);
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
) )
550 sMessage
.append(static_cast<sal_Unicode
>('\n'));
552 pContext
= new ScXMLContentContext( GetScImport(), nPrefix
, rLName
, xAttrList
, sMessage
);
558 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
563 void ScXMLHelpMessageContext::EndElement()
565 pValidationContext
->SetHelpMessage(sTitle
, sMessage
.makeStringAndClear(), bDisplay
);
568 ScXMLErrorMessageContext::ScXMLErrorMessageContext( ScXMLImport
& rImport
,
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
),
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
:
597 case XML_TOK_ERROR_MESSAGE_ATTR_MESSAGE_TYPE
:
598 sMessageType
= sValue
;
600 case XML_TOK_ERROR_MESSAGE_ATTR_DISPLAY
:
601 bDisplay
= IsXMLToken(sValue
, XML_TRUE
);
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
) )
624 sMessage
.append(static_cast<sal_Unicode
>('\n'));
626 pContext
= new ScXMLContentContext( GetScImport(), nPrefix
, rLName
, xAttrList
, sMessage
);
632 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
637 void ScXMLErrorMessageContext::EndElement()
639 pValidationContext
->SetErrorMessage(sTitle
, sMessage
.makeStringAndClear(), sMessageType
, bDisplay
);
642 ScXMLErrorMacroContext::ScXMLErrorMacroContext( ScXMLImport
& rImport
,
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
),
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
:
668 case XML_TOK_ERROR_MACRO_ATTR_EXECUTE
:
669 bExecute
= IsXMLToken(sValue
, XML_TRUE
);
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
);
691 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
696 void ScXMLErrorMacroContext::EndElement()
698 pValidationContext
->SetErrorMacro( bExecute
);