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

Generated by: LCOV version 1.10