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

Generated by: LCOV version 1.10