LCOV - code coverage report
Current view: top level - unotools/source/config - xmlaccelcfg.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 72 0.0 %
Date: 2014-04-14 Functions: 0 10 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 <unotools/xmlaccelcfg.hxx>
      21             : 
      22             : #include <vector>
      23             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      24             : #include <cppuhelper/implbase1.hxx>
      25             : 
      26             : using namespace com::sun::star::uno;
      27             : using namespace com::sun::star::xml::sax;
      28             : 
      29             : #define ELEMENT_ACCELERATORLIST     "acceleratorlist"
      30             : #define ELEMENT_ACCELERATORITEM     "item"
      31             : 
      32             : #define ATTRIBUTE_KEYCODE           "code"
      33             : #define ATTRIBUTE_MODIFIER          "modifier"
      34             : #define ATTRIBUTE_URL               "url"
      35             : 
      36           0 : Any SAL_CALL OReadAccelatorDocumentHandler::queryInterface( const Type & rType ) throw( RuntimeException, std::exception )
      37             : {
      38           0 :     Any a = ::cppu::queryInterface( rType ,(static_cast< XDocumentHandler* >(this)));
      39           0 :     if ( a.hasValue() )
      40           0 :         return a;
      41             :     else
      42           0 :         return OWeakObject::queryInterface( rType );
      43             : }
      44             : 
      45           0 : void SAL_CALL OReadAccelatorDocumentHandler::ignorableWhitespace(
      46             :     const OUString& )
      47             : throw( SAXException, RuntimeException, std::exception )
      48             : {
      49           0 : }
      50             : 
      51           0 : void SAL_CALL OReadAccelatorDocumentHandler::processingInstruction(
      52             :     const OUString&, const OUString& )
      53             : throw( SAXException, RuntimeException, std::exception )
      54             : {
      55           0 : }
      56             : 
      57           0 : void SAL_CALL OReadAccelatorDocumentHandler::setDocumentLocator(
      58             :     const Reference< XLocator > &xLocator)
      59             : throw(  SAXException, RuntimeException, std::exception )
      60             : {
      61           0 :     m_xLocator = xLocator;
      62           0 : }
      63             : 
      64           0 : OUString OReadAccelatorDocumentHandler::getErrorLineString()
      65             : {
      66             :     char buffer[32];
      67             : 
      68           0 :     if ( m_xLocator.is() )
      69             :     {
      70           0 :         return OUString::createFromAscii( buffer );
      71             :     }
      72             :     else
      73           0 :         return OUString();
      74             : }
      75             : 
      76           0 : void SAL_CALL OReadAccelatorDocumentHandler::startDocument(void)
      77             :     throw ( SAXException, RuntimeException, std::exception )
      78             : {
      79           0 : }
      80             : 
      81           0 : void SAL_CALL OReadAccelatorDocumentHandler::endDocument(void)
      82             :     throw( SAXException, RuntimeException, std::exception )
      83             : {
      84           0 :     if ( m_nElementDepth > 0 )
      85             :     {
      86           0 :         OUString aErrorMessage = getErrorLineString();
      87           0 :         aErrorMessage += "A closing element is missing!";
      88           0 :         throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
      89             :     }
      90           0 : }
      91             : 
      92           0 : void SAL_CALL OReadAccelatorDocumentHandler::startElement(
      93             :     const OUString& aElementName, const Reference< XAttributeList > &xAttrList )
      94             : throw( SAXException, RuntimeException, std::exception )
      95             : {
      96           0 :     m_nElementDepth++;
      97             : 
      98           0 :     if ( aElementName == ELEMENT_ACCELERATORLIST )
      99             :     {
     100             :         // acceleratorlist
     101           0 :         if ( m_bAcceleratorMode )
     102             :         {
     103           0 :             OUString aErrorMessage = getErrorLineString();
     104           0 :             aErrorMessage += "Accelerator list used twice!";
     105           0 :             throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     106             :         }
     107             :         else
     108           0 :             m_bAcceleratorMode = true;
     109             :     }
     110           0 :     else if ( aElementName == ELEMENT_ACCELERATORITEM )
     111             :     {
     112             :         // accelerator item
     113           0 :         if ( !m_bAcceleratorMode )
     114             :         {
     115           0 :             OUString aErrorMessage = getErrorLineString();
     116           0 :             aErrorMessage += "Accelerator list element has to be used before!";
     117           0 :             throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     118             :         }
     119             :         else
     120             :         {
     121             :             // read accelerator item
     122           0 :             m_bItemCloseExpected = true;
     123             : 
     124           0 :             SvtAcceleratorConfigItem aItem;
     125             : 
     126             :             // read attributes for accelerator
     127           0 :             for ( sal_Int16 i=0; i< xAttrList->getLength(); i++ )
     128             :             {
     129           0 :                 OUString aName = xAttrList->getNameByIndex( i );
     130           0 :                 OUString aValue = xAttrList->getValueByIndex( i );
     131             : 
     132           0 :                 if ( aName == ATTRIBUTE_URL )
     133           0 :                     aItem.aCommand = aValue;
     134           0 :                 else if ( aName == ATTRIBUTE_MODIFIER )
     135           0 :                     aItem.nModifier = (sal_uInt16)aValue.toInt32();
     136           0 :                 else if ( aName == ATTRIBUTE_KEYCODE )
     137           0 :                     aItem.nCode = (sal_uInt16)aValue.toInt32();
     138           0 :             }
     139             : 
     140           0 :             m_aReadAcceleratorList.push_back( aItem );
     141             :         }
     142             :     }
     143             :     else
     144             :     {
     145           0 :         OUString aErrorMessage = getErrorLineString();
     146           0 :         aErrorMessage += "Unknown element found!";
     147           0 :         throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     148             :     }
     149           0 : }
     150             : 
     151           0 : void SAL_CALL OReadAccelatorDocumentHandler::characters(const OUString&)
     152             : throw(  SAXException, RuntimeException, std::exception )
     153             : {
     154           0 : }
     155             : 
     156           0 : void SAL_CALL OReadAccelatorDocumentHandler::endElement( const OUString& aName )
     157             :     throw( SAXException, RuntimeException, std::exception )
     158             : {
     159           0 :     m_nElementDepth--;
     160             : 
     161           0 :     if ( aName == ELEMENT_ACCELERATORLIST )
     162             :     {
     163             :         // acceleratorlist
     164           0 :         if ( !m_bAcceleratorMode )
     165             :         {
     166           0 :             OUString aErrorMessage = getErrorLineString();
     167           0 :             aErrorMessage += "Accelerator list used twice!";
     168           0 :             throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     169             :         }
     170             :     }
     171           0 :     else if ( aName == ELEMENT_ACCELERATORITEM )
     172             :     {
     173           0 :         if ( !m_bItemCloseExpected )
     174             :         {
     175           0 :             OUString aErrorMessage = getErrorLineString();
     176           0 :             aErrorMessage += "Closing accelerator item element expected!";
     177           0 :             throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     178             :         }
     179             :     }
     180             :     else
     181             :     {
     182           0 :         OUString aErrorMessage = getErrorLineString();
     183           0 :         aErrorMessage += "Unknown closing element found!";
     184           0 :         throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
     185             :     }
     186           0 : }
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10