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