LCOV - code coverage report
Current view: top level - xmloff/source/transform - DocumentTContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 52 98.1 %
Date: 2012-08-25 Functions: 4 9 44.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 55 96 57.3 %

           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 <com/sun/star/xml/sax/SAXParseException.hpp>
      30                 :            : #include <com/sun/star/xml/sax/SAXException.hpp>
      31                 :            : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      32                 :            : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      33                 :            : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      34                 :            : #include <xmloff/nmspmap.hxx>
      35                 :            : #include <xmloff/xmltoken.hxx>
      36                 :            : #include "xmloff/xmlnmspe.hxx"
      37                 :            : 
      38                 :            : #include "TransformerBase.hxx"
      39                 :            : #include "MutableAttrList.hxx"
      40                 :            : 
      41                 :            : #include "DocumentTContext.hxx"
      42                 :            : 
      43                 :            : using ::rtl::OUString;
      44                 :            : 
      45                 :            : using namespace ::xmloff::token;
      46                 :            : using namespace ::com::sun::star::uno;
      47                 :            : using namespace ::com::sun::star::xml::sax;
      48                 :            : using namespace ::com::sun::star::beans;
      49                 :            : 
      50 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLDocumentTransformerContext, XMLTransformerContext );
      51                 :            : 
      52                 :         12 : XMLDocumentTransformerContext::XMLDocumentTransformerContext( XMLTransformerBase& rImp,
      53                 :            :                                                 const OUString& rQName ) :
      54                 :         12 :     XMLTransformerContext( rImp, rQName )
      55                 :            : {
      56                 :         12 : }
      57                 :            : 
      58                 :         12 : XMLDocumentTransformerContext::~XMLDocumentTransformerContext()
      59                 :            : {
      60         [ -  + ]:         24 : }
      61                 :            : 
      62                 :         12 : void XMLDocumentTransformerContext::StartElement( const Reference< XAttributeList >& rAttrList )
      63                 :            : {
      64                 :         12 :     Reference< XAttributeList > xAttrList( rAttrList );
      65                 :            : 
      66                 :         12 :     sal_Bool bMimeFound = sal_False;
      67                 :         12 :     OUString aClass;
      68                 :            :     OUString aClassQName(
      69                 :         12 :                     GetTransformer().GetNamespaceMap().GetQNameByKey(
      70   [ +  -  +  - ]:         24 :                                 XML_NAMESPACE_OFFICE, GetXMLToken(XML_CLASS ) ) );
      71                 :            : 
      72                 :         12 :     XMLMutableAttributeList *pMutableAttrList = 0;
      73 [ +  - ][ +  - ]:         12 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
                 [ +  - ]
      74         [ +  + ]:        454 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      75                 :            :     {
      76 [ +  - ][ +  - ]:        442 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      77                 :        442 :         OUString aLocalName;
      78                 :            :         sal_uInt16 nPrefix =
      79                 :        442 :             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      80         [ +  - ]:        442 :                                                                  &aLocalName );
      81 [ +  + ][ +  + ]:        456 :         if( XML_NAMESPACE_OFFICE == nPrefix &&
                 [ +  + ]
      82         [ +  - ]:         14 :             IsXMLToken( aLocalName, XML_MIMETYPE ) )
      83                 :            :         {
      84 [ +  - ][ +  - ]:          2 :             const OUString& rValue = xAttrList->getValueByIndex( i );
      85                 :            :             static const char * aTmp[] =
      86                 :            :             {
      87                 :            :                 "application/vnd.oasis.openoffice.",
      88                 :            :                 "application/x-vnd.oasis.openoffice.",
      89                 :            :                 "application/vnd.oasis.opendocument.",
      90                 :            :                 "application/x-vnd.oasis.document.",
      91                 :            :                 NULL
      92                 :            :             };
      93         [ +  - ]:          8 :             for (int k=0; aTmp[k]; k++)
      94                 :            :             {
      95                 :          6 :                 ::rtl::OUString sTmpString = ::rtl::OUString::createFromAscii(aTmp[k]);
      96         [ +  + ]:          6 :                 if( rValue.matchAsciiL( aTmp[k], sTmpString.getLength() ) )
      97                 :            :                 {
      98                 :          6 :                     aClass = rValue.copy( sTmpString.getLength() );
      99                 :            :                     break;
     100                 :            :                 }
     101         [ +  + ]:          6 :             }
     102                 :            : 
     103         [ +  - ]:          2 :             if( !pMutableAttrList )
     104                 :            :             {
     105         [ +  - ]:          2 :                 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
     106 [ +  - ][ +  - ]:          2 :                 xAttrList = pMutableAttrList;
     107                 :            :             }
     108         [ +  - ]:          2 :             pMutableAttrList->SetValueByIndex( i, aClass );
     109         [ +  - ]:          2 :             pMutableAttrList->RenameAttributeByIndex(i, aClassQName );
     110                 :          2 :             bMimeFound = sal_True;
     111                 :        442 :             break;
     112                 :            :         }
     113 [ +  + ][ +  + ]:        442 :     }
     114                 :            : 
     115         [ +  + ]:         12 :     if( !bMimeFound )
     116                 :            :     {
     117                 :            :         const Reference< XPropertySet > rPropSet =
     118                 :         10 :             GetTransformer().GetPropertySet();
     119                 :            : 
     120         [ +  - ]:         10 :         if( rPropSet.is() )
     121                 :            :         {
     122                 :            :             Reference< XPropertySetInfo > xPropSetInfo(
     123 [ +  - ][ +  - ]:         10 :                 rPropSet->getPropertySetInfo() );
     124         [ +  - ]:         10 :             OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("Class"));
     125 [ +  - ][ +  - ]:         10 :             if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName( aPropName ) )
         [ +  - ][ +  - ]
                 [ +  - ]
     126                 :            :             {
     127 [ +  - ][ +  - ]:         10 :                 Any aAny = rPropSet->getPropertyValue( aPropName );
     128                 :         10 :                 aAny >>= aClass;
     129                 :         10 :             }
     130                 :            :         }
     131                 :            : 
     132         [ +  - ]:         10 :         if( !aClass.isEmpty() )
     133                 :            :         {
     134         [ +  - ]:         10 :             if( !pMutableAttrList )
     135                 :            :             {
     136         [ +  - ]:         10 :                 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
     137 [ +  - ][ +  - ]:         10 :                 xAttrList = pMutableAttrList;
     138                 :            :             }
     139                 :            : 
     140         [ +  - ]:         10 :             pMutableAttrList->AddAttribute( aClassQName, aClass );
     141                 :         10 :         }
     142                 :            :     }
     143         [ +  - ]:         12 :     XMLTransformerContext::StartElement( xAttrList );
     144                 :         12 : }
     145                 :            : 
     146                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10