LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlcvali.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 149 268 55.6 %
Date: 2014-04-11 Functions: 22 36 61.1 %
Legend: Lines: hit not hit

          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           2 :     const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
      55          18 :     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          12 :     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           1 : 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           1 :     SvXMLImportContext( rImport, nPrfx, rLName )
     177             : {
     178             :     // here are no attributes
     179           1 : }
     180             : 
     181           2 : ScXMLContentValidationsContext::~ScXMLContentValidationsContext()
     182             : {
     183           2 : }
     184             : 
     185           2 : 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           2 :     SvXMLImportContext *pContext = 0;
     191             : 
     192           2 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationsElemTokenMap();
     193           2 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     194             :     {
     195             :         case XML_TOK_CONTENT_VALIDATION:
     196           2 :             pContext = new ScXMLContentValidationContext( GetScImport(), nPrefix, rLName, xAttrList);
     197           2 :         break;
     198             :     }
     199             : 
     200           2 :     if( !pContext )
     201           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     202             : 
     203           2 :     return pContext;
     204             : }
     205             : 
     206           1 : void ScXMLContentValidationsContext::EndElement()
     207             : {
     208           1 : }
     209             : 
     210           2 : 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           2 :     bDisplayError(false)
     220             : {
     221           2 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     222           2 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationAttrTokenMap();
     223          10 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     224             :     {
     225           8 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     226          16 :         OUString aLocalName;
     227           8 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
     228           8 :                                             sAttrName, &aLocalName );
     229          16 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     230             : 
     231           8 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     232             :         {
     233             :             case XML_TOK_CONTENT_VALIDATION_NAME:
     234           2 :                 sName = sValue;
     235           2 :             break;
     236             :             case XML_TOK_CONTENT_VALIDATION_CONDITION:
     237           2 :                 sCondition = sValue;
     238           2 :             break;
     239             :             case XML_TOK_CONTENT_VALIDATION_BASE_CELL_ADDRESS:
     240           2 :                 sBaseCellAddress = sValue;
     241           2 :             break;
     242             :             case XML_TOK_CONTENT_VALIDATION_ALLOW_EMPTY_CELL:
     243           2 :                 if (IsXMLToken(sValue, XML_FALSE))
     244           0 :                     bAllowEmptyCell = false;
     245           2 :             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           8 :     }
     269           2 : }
     270             : 
     271           4 : ScXMLContentValidationContext::~ScXMLContentValidationContext()
     272             : {
     273           4 : }
     274             : 
     275           2 : 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           2 :     SvXMLImportContext *pContext = 0;
     281             : 
     282           2 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationElemTokenMap();
     283           2 :     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           2 :             pContext = new ScXMLErrorMessageContext( GetScImport(), nPrefix, rLName, xAttrList, this);
     290           2 :         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           2 :     if( !pContext )
     301           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     302             : 
     303           2 :     return pContext;
     304             : }
     305             : 
     306           2 : sheet::ValidationAlertStyle ScXMLContentValidationContext::GetAlertStyle() const
     307             : {
     308           2 :     if (IsXMLToken(sErrorMessageType, XML_MACRO))
     309           0 :         return sheet::ValidationAlertStyle_MACRO;
     310           2 :     if (IsXMLToken(sErrorMessageType, XML_STOP))
     311           1 :         return sheet::ValidationAlertStyle_STOP;
     312           1 :     if (IsXMLToken(sErrorMessageType, XML_WARNING))
     313           1 :         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           4 : 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           4 :     reGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
     324           4 :     if( bHasNmsp )
     325             :     {
     326             :         // the entire attribute contains a namespace: internal namespace not allowed
     327           4 :         rFormula = rCondition;
     328           4 :         rFormulaNmsp = rGlobNmsp;
     329           4 :         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           4 : }
     339             : 
     340           2 : void ScXMLContentValidationContext::GetCondition( ScMyImportValidation& rValidation ) const
     341             : {
     342           2 :     rValidation.aValidationType = sheet::ValidationType_ANY;    // default if no condition is given
     343           2 :     rValidation.aOperator = sheet::ConditionOperator_NONE;
     344             : 
     345           2 :     if( !sCondition.isEmpty() )
     346             :     {
     347             :         // extract leading namespace from condition string
     348           4 :         OUString aCondition, aConditionNmsp;
     349           2 :         FormulaGrammar::Grammar eGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
     350           2 :         GetScImport().ExtractFormulaNamespaceGrammar( aCondition, aConditionNmsp, eGrammar, sCondition );
     351           2 :         bool bHasNmsp = aCondition.getLength() < sCondition.getLength();
     352             : 
     353             :         // parse a condition from the attribute string
     354           4 :         ScXMLConditionParseResult aParseResult;
     355           2 :         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           2 :         bool bSecondaryPart = false;
     361           2 :         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           2 :                 rValidation.aValidationType = aParseResult.meValidation;
     376           2 :                 bSecondaryPart = true;
     377           2 :             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           2 :         if( bSecondaryPart )
     386             :         {
     387           2 :             ScXMLConditionHelper::parseCondition( aParseResult, aCondition, aParseResult.mnEndIndex );
     388           2 :             if( aParseResult.meToken == XML_COND_AND )
     389             :             {
     390           2 :                 ScXMLConditionHelper::parseCondition( aParseResult, aCondition, aParseResult.mnEndIndex );
     391           2 :                 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           2 :                         rValidation.aOperator = aParseResult.meOperator;
     397           2 :                     break;
     398             :                     default:;   // unacceptable or unknown condition
     399             :                 }
     400             :             }
     401             :         }
     402             : 
     403             :         // a validation type (date, integer) without a condition isn't possible
     404           2 :         if( rValidation.aOperator == sheet::ConditionOperator_NONE )
     405           0 :             rValidation.aValidationType = sheet::ValidationType_ANY;
     406             : 
     407             :         // parse the formulas
     408           2 :         if( rValidation.aValidationType != sheet::ValidationType_ANY )
     409             :         {
     410             :             SetFormula( rValidation.sFormula1, rValidation.sFormulaNmsp1, rValidation.eGrammar1,
     411           2 :                 aParseResult.maOperand1, aConditionNmsp, eGrammar, bHasNmsp );
     412             :             SetFormula( rValidation.sFormula2, rValidation.sFormulaNmsp2, rValidation.eGrammar2,
     413           2 :                 aParseResult.maOperand2, aConditionNmsp, eGrammar, bHasNmsp );
     414           2 :         }
     415             :     }
     416           2 : }
     417             : 
     418           2 : void ScXMLContentValidationContext::EndElement()
     419             : {
     420             :     // #i36650# event-listeners element moved up one level
     421           2 :     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           2 :     ScMyImportValidation aValidation;
     443           2 :     aValidation.eGrammar1 = aValidation.eGrammar2 = GetScImport().GetDocument()->GetStorageGrammar();
     444           2 :     aValidation.sName = sName;
     445           2 :     aValidation.sBaseCellAddress = sBaseCellAddress;
     446           2 :     aValidation.sImputTitle = sHelpTitle;
     447           2 :     aValidation.sImputMessage = sHelpMessage;
     448           2 :     aValidation.sErrorTitle = sErrorTitle;
     449           2 :     aValidation.sErrorMessage = sErrorMessage;
     450           2 :     GetCondition( aValidation );
     451           2 :     aValidation.aAlertStyle = GetAlertStyle();
     452           2 :     aValidation.bShowErrorMessage = bDisplayError;
     453           2 :     aValidation.bShowImputMessage = bDisplayHelp;
     454           2 :     aValidation.bIgnoreBlanks = bAllowEmptyCell;
     455           2 :     aValidation.nShowList = nShowList;
     456           2 :     GetScImport().AddValidation(aValidation);
     457           2 : }
     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           2 : void ScXMLContentValidationContext::SetErrorMessage(const OUString& sTitle, const OUString& sMessage,
     467             :     const OUString& sMessageType, const sal_Bool bDisplay)
     468             : {
     469           2 :     sErrorTitle = sTitle;
     470           2 :     sErrorMessage = sMessage;
     471           2 :     sErrorMessageType = sMessageType;
     472           2 :     bDisplayError = bDisplay;
     473           2 : }
     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           2 : 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           2 :     bDisplay(false)
     563             : {
     564           2 :     pValidationContext = pTempValidationContext;
     565           2 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     566           2 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetContentValidationErrorMessageAttrTokenMap();
     567           8 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     568             :     {
     569           6 :         const OUString& sAttrName(xAttrList->getNameByIndex( i ));
     570          12 :         OUString aLocalName;
     571           6 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
     572           6 :                                             sAttrName, &aLocalName );
     573          12 :         const OUString& sValue(xAttrList->getValueByIndex( i ));
     574             : 
     575           6 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     576             :         {
     577             :             case XML_TOK_ERROR_MESSAGE_ATTR_TITLE:
     578           2 :                 sTitle = sValue;
     579           2 :             break;
     580             :             case XML_TOK_ERROR_MESSAGE_ATTR_MESSAGE_TYPE:
     581           2 :                 sMessageType = sValue;
     582           2 :             break;
     583             :             case XML_TOK_ERROR_MESSAGE_ATTR_DISPLAY:
     584           2 :                 bDisplay = IsXMLToken(sValue, XML_TRUE);
     585           2 :             break;
     586             :         }
     587           6 :     }
     588           2 : }
     589             : 
     590           4 : ScXMLErrorMessageContext::~ScXMLErrorMessageContext()
     591             : {
     592           4 : }
     593             : 
     594           2 : 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           2 :     SvXMLImportContext *pContext = 0;
     600             : 
     601           2 :     const SvXMLTokenMap& rTokenMap = GetScImport().GetContentValidationMessageElemTokenMap();
     602           2 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     603             :     {
     604             :         case XML_TOK_P:
     605             :         {
     606           2 :             if(nParagraphCount)
     607           0 :                 sMessage.append('\n');
     608           2 :             ++nParagraphCount;
     609           2 :             pContext = new ScXMLContentContext( GetScImport(), nPrefix, rLName, xAttrList, sMessage);
     610             :         }
     611           2 :         break;
     612             :     }
     613             : 
     614           2 :     if( !pContext )
     615           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     616             : 
     617           2 :     return pContext;
     618             : }
     619             : 
     620           2 : void ScXMLErrorMessageContext::EndElement()
     621             : {
     622           2 :     pValidationContext->SetErrorMessage(sTitle, sMessage.makeStringAndClear(), sMessageType, bDisplay);
     623           2 : }
     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: */

Generated by: LCOV version 1.10