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

Generated by: LCOV version 1.10