LCOV - code coverage report
Current view: top level - framework/source/fwe/xml - saxnamespacefilter.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 68 0.0 %
Date: 2014-04-14 Functions: 0 12 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             : /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
      21             :                with solaris headers ...
      22             : */
      23             : #include <vector>
      24             : 
      25             : #include <stdio.h>
      26             : 
      27             : #include <xml/saxnamespacefilter.hxx>
      28             : 
      29             : #include <comphelper/attributelist.hxx>
      30             : 
      31             : #include <vcl/svapp.hxx>
      32             : 
      33             : using namespace ::com::sun::star::xml::sax;
      34             : using namespace ::com::sun::star::uno;
      35             : 
      36             : namespace framework{
      37             : 
      38           0 : SaxNamespaceFilter::SaxNamespaceFilter( Reference< XDocumentHandler >& rSax1DocumentHandler ) :
      39             :      m_xLocator( 0 ),
      40             :      xDocumentHandler( rSax1DocumentHandler ),
      41             :      m_nDepth( 0 ),
      42             :      m_aXMLAttributeNamespace( "xmlns" ),
      43           0 :      m_aXMLAttributeType( "CDATA" )
      44             : {
      45           0 : }
      46             : 
      47           0 : SaxNamespaceFilter::~SaxNamespaceFilter()
      48             : {
      49           0 : }
      50             : 
      51             : // XDocumentHandler
      52           0 : void SAL_CALL SaxNamespaceFilter::startDocument(void)
      53             :     throw ( SAXException, RuntimeException, std::exception )
      54             : {
      55           0 : }
      56             : 
      57           0 : void SAL_CALL SaxNamespaceFilter::endDocument(void)
      58             :     throw(  SAXException, RuntimeException, std::exception )
      59             : {
      60           0 : }
      61             : 
      62           0 : void SAL_CALL SaxNamespaceFilter::startElement(
      63             :     const OUString& rName, const Reference< XAttributeList > &xAttribs )
      64             :     throw(  SAXException, RuntimeException, std::exception )
      65             : {
      66           0 :     XMLNamespaces aXMLNamespaces;
      67           0 :     if ( !m_aNamespaceStack.empty() )
      68           0 :         aXMLNamespaces = m_aNamespaceStack.top();
      69             : 
      70           0 :     ::comphelper::AttributeList* pNewList = new ::comphelper::AttributeList();
      71             : 
      72             :     // examine all namespaces for this level
      73           0 :     ::std::vector< sal_Int16 > aAttributeIndexes;
      74             :     {
      75           0 :         for ( sal_Int16 i=0; i< xAttribs->getLength(); i++ )
      76             :         {
      77           0 :             OUString aName = xAttribs->getNameByIndex( i );
      78           0 :             if ( aName.startsWith( m_aXMLAttributeNamespace ) )
      79           0 :                 aXMLNamespaces.addNamespace( aName, xAttribs->getValueByIndex( i ));
      80             :             else
      81           0 :                 aAttributeIndexes.push_back( i );
      82           0 :         }
      83             :     }
      84             : 
      85             :     // current namespaces for this level
      86           0 :     m_aNamespaceStack.push( aXMLNamespaces );
      87             : 
      88             :     try
      89             :     {
      90             :         // apply namespaces to all remaing attributes
      91           0 :         for ( ::std::vector< sal_Int16 >::const_iterator i(
      92           0 :                   aAttributeIndexes.begin());
      93           0 :               i != aAttributeIndexes.end(); ++i )
      94             :         {
      95           0 :             OUString aAttributeName           = xAttribs->getNameByIndex( *i );
      96           0 :             OUString aValue                   = xAttribs->getValueByIndex( *i );
      97           0 :             OUString aNamespaceAttributeName = aXMLNamespaces.applyNSToAttributeName( aAttributeName );
      98           0 :             pNewList->AddAttribute( aNamespaceAttributeName, m_aXMLAttributeType, aValue );
      99           0 :         }
     100             :     }
     101           0 :     catch ( SAXException& e )
     102             :     {
     103           0 :         e.Message = OUString( getErrorLineString() + e.Message );
     104           0 :         throw;
     105             :     }
     106             : 
     107           0 :     OUString aNamespaceElementName;
     108             : 
     109             :     try
     110             :     {
     111           0 :          aNamespaceElementName = aXMLNamespaces.applyNSToElementName( rName );
     112             :     }
     113           0 :     catch ( SAXException& e )
     114             :     {
     115           0 :         e.Message = OUString( getErrorLineString() + e.Message );
     116           0 :         throw;
     117             :     }
     118             : 
     119           0 :     xDocumentHandler->startElement( aNamespaceElementName, pNewList );
     120           0 : }
     121             : 
     122           0 : void SAL_CALL SaxNamespaceFilter::endElement(const OUString& aName)
     123             :     throw(  SAXException, RuntimeException, std::exception )
     124             : {
     125           0 :     XMLNamespaces& aXMLNamespaces = m_aNamespaceStack.top();
     126           0 :     OUString aNamespaceElementName;
     127             : 
     128             :     try
     129             :     {
     130           0 :         aNamespaceElementName = aXMLNamespaces.applyNSToElementName( aName );
     131             :     }
     132           0 :     catch ( SAXException& e )
     133             :     {
     134           0 :         e.Message = OUString( getErrorLineString() + e.Message );
     135           0 :         throw;
     136             :     }
     137             : 
     138           0 :     xDocumentHandler->endElement( aNamespaceElementName );
     139           0 :     m_aNamespaceStack.pop();
     140           0 : }
     141             : 
     142           0 : void SAL_CALL SaxNamespaceFilter::characters(const OUString& aChars)
     143             :     throw(  SAXException, RuntimeException, std::exception )
     144             : {
     145           0 :     xDocumentHandler->characters( aChars );
     146           0 : }
     147             : 
     148           0 : void SAL_CALL SaxNamespaceFilter::ignorableWhitespace(const OUString& aWhitespaces)
     149             :     throw(  SAXException, RuntimeException, std::exception )
     150             : {
     151           0 :     xDocumentHandler->ignorableWhitespace( aWhitespaces );
     152           0 : }
     153             : 
     154           0 : void SAL_CALL SaxNamespaceFilter::processingInstruction(
     155             :     const OUString& aTarget, const OUString& aData)
     156             :     throw(  SAXException, RuntimeException, std::exception )
     157             : {
     158           0 :     xDocumentHandler->processingInstruction( aTarget, aData );
     159           0 : }
     160             : 
     161           0 : void SAL_CALL SaxNamespaceFilter::setDocumentLocator(
     162             :     const Reference< XLocator > &xLocator)
     163             :     throw(  SAXException, RuntimeException, std::exception )
     164             : {
     165           0 :     m_xLocator = xLocator;
     166           0 :     xDocumentHandler->setDocumentLocator( xLocator );
     167           0 : }
     168             : 
     169           0 : OUString SaxNamespaceFilter::getErrorLineString()
     170             : {
     171           0 :     if ( m_xLocator.is() )
     172             :     {
     173             :         char buffer[32];
     174           0 :         snprintf( buffer, sizeof(buffer), "Line: %ld - ", static_cast<long>( m_xLocator->getLineNumber() ));
     175           0 :         return OUString::createFromAscii( buffer );
     176             :     }
     177             :     else
     178           0 :         return OUString();
     179             : }
     180             : 
     181             : } // namespace
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10