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

Generated by: LCOV version 1.10