LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlcvali.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 150 266 56.4 %
Date: 2012-08-25 Functions: 22 36 61.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 70 264 26.5 %

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

Generated by: LCOV version 1.10