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