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

Generated by: LCOV version 1.10