LCOV - code coverage report
Current view: top level - xmloff/source/core - xmlerror.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 29 86.2 %
Date: 2012-08-25 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 38 47.4 %

           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 "xmloff/xmlerror.hxx"
      30                 :            : #include <tools/debug.hxx>
      31                 :            : #include <rtl/ustring.hxx>
      32                 :            : #include <com/sun/star/xml/sax/XLocator.hpp>
      33                 :            : #include <com/sun/star/xml/sax/SAXParseException.hpp>
      34                 :            : #include <com/sun/star/uno/Any.hxx>
      35                 :            : #include <com/sun/star/uno/Reference.hxx>
      36                 :            : #include <com/sun/star/uno/Sequence.hxx>
      37                 :            : 
      38                 :            : 
      39                 :            : #include <rtl/ustrbuf.hxx>
      40                 :            : 
      41                 :            : 
      42                 :            : 
      43                 :            : using ::rtl::OUString;
      44                 :            : using ::rtl::OUStringBuffer;
      45                 :            : using ::com::sun::star::uno::Any;
      46                 :            : using ::com::sun::star::uno::Sequence;
      47                 :            : using ::com::sun::star::uno::Reference;
      48                 :            : using ::com::sun::star::xml::sax::XLocator;
      49                 :            : using ::com::sun::star::xml::sax::SAXParseException;
      50                 :            : 
      51                 :            : 
      52                 :            : //
      53                 :            : /// ErrorRecord: contains all information for one error
      54                 :            : //
      55                 :            : 
      56         [ +  - ]:        278 : class ErrorRecord
      57                 :            : {
      58                 :            : public:
      59                 :            : 
      60                 :            :     ErrorRecord( sal_Int32 nId,
      61                 :            :                  const Sequence<OUString>& rParams,
      62                 :            :                  const OUString& rExceptionMessage,
      63                 :            :                  sal_Int32 nRow,
      64                 :            :                  sal_Int32 nColumn,
      65                 :            :                  const OUString& rPublicId,
      66                 :            :                  const OUString& rSystemId);
      67                 :            :     ~ErrorRecord();
      68                 :            : 
      69                 :            :     sal_Int32 nId;  /// error ID
      70                 :            : 
      71                 :            :     OUString sExceptionMessage;/// message of original exception (if available)
      72                 :            : 
      73                 :            :     // XLocator information:
      74                 :            :     sal_Int32 nRow;     /// row number where error occurred (or -1 for unknown)
      75                 :            :     sal_Int32 nColumn;  /// column number where error occurred (or -1)
      76                 :            :     OUString sPublicId; /// public identifier
      77                 :            :     OUString sSystemId; /// public identifier
      78                 :            : 
      79                 :            :     /// message Parameters
      80                 :            :     Sequence<OUString> aParams;
      81                 :            : };
      82                 :            : 
      83                 :            : 
      84                 :        123 : ErrorRecord::ErrorRecord( sal_Int32 nID, const Sequence<OUString>& rParams,
      85                 :            :     const OUString& rExceptionMessage, sal_Int32 nRowNumber, sal_Int32 nCol,
      86                 :            :     const OUString& rPublicId, const OUString& rSystemId) :
      87                 :            :         nId(nID),
      88                 :            :         sExceptionMessage(rExceptionMessage),
      89                 :            :         nRow(nRowNumber),
      90                 :            :         nColumn(nCol),
      91                 :            :         sPublicId(rPublicId),
      92                 :            :         sSystemId(rSystemId),
      93         [ +  - ]:        123 :         aParams(rParams)
      94                 :            : {
      95                 :        123 : }
      96                 :            : 
      97         [ +  - ]:        401 : ErrorRecord::~ErrorRecord()
      98                 :            : {
      99                 :        401 : }
     100                 :            : 
     101                 :            : 
     102                 :            : 
     103                 :            : 
     104                 :          8 : XMLErrors::XMLErrors()
     105                 :            : {
     106                 :          8 : }
     107                 :            : 
     108                 :          8 : XMLErrors::~XMLErrors()
     109                 :            : {
     110                 :          8 : }
     111                 :            : 
     112                 :        123 : void XMLErrors::AddRecord(
     113                 :            :     sal_Int32 nId,
     114                 :            :     const Sequence<OUString> & rParams,
     115                 :            :     const OUString& rExceptionMessage,
     116                 :            :     sal_Int32 nRow,
     117                 :            :     sal_Int32 nColumn,
     118                 :            :     const OUString& rPublicId,
     119                 :            :     const OUString& rSystemId )
     120                 :            : {
     121                 :            :     aErrors.push_back( ErrorRecord( nId, rParams, rExceptionMessage,
     122         [ +  - ]:        123 :                                     nRow, nColumn, rPublicId, rSystemId ) );
     123                 :            : 
     124                 :            : #ifdef DBG_UTIL
     125                 :            : 
     126                 :            :     // give detailed assertion on this message
     127                 :            : 
     128                 :            :     OUStringBuffer sMessage;
     129                 :            : 
     130                 :            :     sMessage.appendAscii( "An error or a warning has occurred during XML import/export!\n" );
     131                 :            : 
     132                 :            :     // ID & flags
     133                 :            :     sMessage.appendAscii( "Error-Id: 0x");
     134                 :            :     sMessage.append( nId, 16 );
     135                 :            :     sMessage.appendAscii( "\n    Flags: " );
     136                 :            :     sal_Int32 nFlags = (nId & XMLERROR_MASK_FLAG);
     137                 :            :     sMessage.append( nFlags >> 28, 16 );
     138                 :            :     if( (nFlags & XMLERROR_FLAG_WARNING) != 0 )
     139                 :            :         sMessage.appendAscii( " WARNING" );
     140                 :            :     if( (nFlags & XMLERROR_FLAG_ERROR) != 0 )
     141                 :            :         sMessage.appendAscii( " ERRROR" );
     142                 :            :     if( (nFlags & XMLERROR_FLAG_SEVERE) != 0 )
     143                 :            :         sMessage.appendAscii( " SEVERE" );
     144                 :            :     sMessage.appendAscii( "\n    Class: " );
     145                 :            :     sal_Int32 nClass = (nId & XMLERROR_MASK_CLASS);
     146                 :            :     sMessage.append( nClass >> 16, 16 );
     147                 :            :     if( (nClass & XMLERROR_CLASS_IO) != 0 )
     148                 :            :         sMessage.appendAscii( " IO" );
     149                 :            :     if( (nClass & XMLERROR_CLASS_FORMAT) != 0 )
     150                 :            :         sMessage.appendAscii( " FORMAT" );
     151                 :            :     if( (nClass & XMLERROR_CLASS_API) != 0 )
     152                 :            :         sMessage.appendAscii( " API" );
     153                 :            :     if( (nClass & XMLERROR_CLASS_OTHER) != 0 )
     154                 :            :         sMessage.appendAscii( " OTHER" );
     155                 :            :     sMessage.appendAscii( "\n    Number: " );
     156                 :            :     sal_Int32 nNumber = (nId & XMLERROR_MASK_NUMBER);
     157                 :            :     sMessage.append( nNumber, 16 );
     158                 :            :     sMessage.appendAscii( "\n");
     159                 :            : 
     160                 :            :     // the parameters
     161                 :            :     sMessage.appendAscii( "Parameters:\n" );
     162                 :            :     sal_Int32 nLength = rParams.getLength();
     163                 :            :     const OUString* pParams = rParams.getConstArray();
     164                 :            :     for( sal_Int32 i = 0; i < nLength; i++ )
     165                 :            :     {
     166                 :            :         sMessage.appendAscii( "    " );
     167                 :            :         sMessage.append( i );
     168                 :            :         sMessage.appendAscii( ": " );
     169                 :            :         sMessage.append( pParams[i] );
     170                 :            :         sMessage.appendAscii( "\n" );
     171                 :            :     }
     172                 :            : 
     173                 :            :     // the exception message
     174                 :            :     sMessage.appendAscii( "Exception-Message: " );
     175                 :            :     sMessage.append( rExceptionMessage );
     176                 :            :     sMessage.appendAscii( "\n" );
     177                 :            : 
     178                 :            :     // position (if given)
     179                 :            :     if( (nRow != -1) || (nColumn != -1) )
     180                 :            :     {
     181                 :            :         sMessage.appendAscii( "Position:\n    Public Identifier: " );
     182                 :            :         sMessage.append( rPublicId );
     183                 :            :         sMessage.appendAscii( "\n    System Identifier: " );
     184                 :            :         sMessage.append( rSystemId );
     185                 :            :         sMessage.appendAscii( "\n    Row, Column: " );
     186                 :            :         sMessage.append( nRow );
     187                 :            :         sMessage.appendAscii( "," );
     188                 :            :         sMessage.append( nColumn );
     189                 :            :         sMessage.appendAscii( "\n" );
     190                 :            :     }
     191                 :            : 
     192                 :            :     // convert to byte string and signal the error
     193                 :            :     rtl::OString aError(rtl::OUStringToOString(sMessage.makeStringAndClear(),
     194                 :            :         RTL_TEXTENCODING_ASCII_US));
     195                 :            :     OSL_FAIL( aError.getStr() );
     196                 :            : #endif
     197                 :        123 : }
     198                 :            : 
     199                 :        123 : void XMLErrors::AddRecord(
     200                 :            :     sal_Int32 nId,
     201                 :            :     const Sequence<OUString> & rParams,
     202                 :            :     const OUString& rExceptionMessage,
     203                 :            :     const Reference<XLocator> & rLocator)
     204                 :            : {
     205         [ +  + ]:        123 :     if ( rLocator.is() )
     206                 :            :     {
     207                 :            :         AddRecord( nId, rParams, rExceptionMessage,
     208 [ +  - ][ +  - ]:        240 :                    rLocator->getLineNumber(), rLocator->getColumnNumber(),
     209 [ +  - ][ +  - ]:        360 :                    rLocator->getPublicId(), rLocator->getSystemId() );
         [ +  - ][ +  - ]
                 [ +  - ]
     210                 :            :     }
     211                 :            :     else
     212                 :            :     {
     213                 :          3 :         OUString sEmpty;
     214                 :            :         AddRecord( nId, rParams, rExceptionMessage,
     215         [ +  - ]:          3 :                    -1, -1, sEmpty, sEmpty );
     216                 :            :     }
     217                 :        123 : }
     218                 :            : 
     219                 :          6 : void XMLErrors::ThrowErrorAsSAXException(sal_Int32 nIdMask)
     220                 :            :     throw( SAXParseException )
     221                 :            : {
     222                 :            :     // search first error/warning that matches the nIdMask
     223 [ +  - ][ +  + ]:        254 :     for( ErrorList::iterator aIter = aErrors.begin();
     224                 :        127 :          aIter != aErrors.end();
     225                 :            :          ++aIter )
     226                 :            :     {
     227         [ -  + ]:        121 :         if ( (aIter->nId & nIdMask) != 0 )
     228                 :            :         {
     229                 :            :             // we throw the error
     230                 :          0 :             ErrorRecord& rErr = aErrors[0];
     231                 :          0 :             Any aAny;
     232         [ #  # ]:          0 :             aAny <<= rErr.aParams;
     233                 :            :             throw SAXParseException(
     234                 :            :                 rErr.sExceptionMessage, NULL, aAny,
     235 [ #  # ][ #  # ]:          0 :                 rErr.sPublicId, rErr.sSystemId, rErr.nRow, rErr.nColumn );
     236                 :            :         }
     237                 :            :     }
     238                 :          6 : }
     239                 :            : 
     240                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10