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