LCOV - code coverage report
Current view: top level - writerfilter/source/filter - WriterFilterDetection.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 56 0.0 %
Date: 2014-04-14 Functions: 0 10 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 <cppuhelper/implementationentry.hxx>
      21             : #include <cppuhelper/supportsservice.hxx>
      22             : #include <WriterFilterDetection.hxx>
      23             : #include <comphelper/storagehelper.hxx>
      24             : #include <com/sun/star/io/XInputStream.hpp>
      25             : #include <sot/storage.hxx>
      26             : #include <unotools/ucbstreamhelper.hxx>
      27             : 
      28             : using namespace ::rtl;
      29             : using namespace ::cppu;
      30             : using namespace ::com::sun::star;
      31             : 
      32             : 
      33             : 
      34           0 : WriterFilterDetection::WriterFilterDetection(
      35             :     const uno::Reference< uno::XComponentContext >& rxContext) :
      36           0 :     m_xContext( rxContext )
      37             : {
      38           0 : }
      39             : 
      40             : 
      41           0 : WriterFilterDetection::~WriterFilterDetection()
      42             : {
      43           0 : }
      44             : 
      45             : 
      46           0 : OUString WriterFilterDetection_getImplementationName () throw (uno::RuntimeException)
      47             : {
      48           0 :    return OUString ( "com.sun.star.comp.Writer.WriterFilterDetector"  );
      49             : }
      50             : 
      51             : 
      52             : 
      53           0 : OUString WriterFilterDetection::detect( uno::Sequence< beans::PropertyValue >& rDescriptor )
      54             :    throw( uno::RuntimeException, std::exception )
      55             : {
      56           0 :     OUString sTypeName;
      57           0 :     bool bWord = false;
      58           0 :     sal_Int32 nPropertyCount = rDescriptor.getLength();
      59           0 :     const beans::PropertyValue* pValues = rDescriptor.getConstArray();
      60           0 :     OUString sURL;
      61           0 :     uno::Reference < io::XStream > xStream;
      62           0 :     uno::Reference < io::XInputStream > xInputStream;
      63           0 :     for( sal_Int32 nProperty = 0; nProperty < nPropertyCount; ++nProperty )
      64             :     {
      65           0 :         if ( pValues[nProperty].Name == "TypeName" )
      66           0 :             rDescriptor[nProperty].Value >>= sTypeName;
      67           0 :         else if ( pValues[nProperty].Name == "URL" )
      68           0 :             pValues[nProperty].Value >>= sURL;
      69           0 :         else if ( pValues[nProperty].Name == "Stream" )
      70           0 :             pValues[nProperty].Value >>= xStream;
      71           0 :         else if ( pValues[nProperty].Name == "InputStream" )
      72           0 :             pValues[nProperty].Value >>= xInputStream;
      73             :     }
      74             :     try
      75             :     {
      76           0 :         uno::Reference< embed::XStorage > xDocStorage;
      77           0 :         if ( sURL == "private:stream" )
      78           0 :             xDocStorage = comphelper::OStorageHelper::GetStorageFromInputStream( xInputStream );
      79             :         else
      80           0 :             xDocStorage = comphelper::OStorageHelper::GetStorageFromURL( sURL, embed::ElementModes::READ );
      81           0 :         if( xDocStorage.is() )
      82             :         {
      83           0 :             uno::Sequence< OUString > aNames = xDocStorage->getElementNames();
      84           0 :             const OUString* pNames = aNames.getConstArray();
      85           0 :             for(sal_Int32 nName = 0; nName < aNames.getLength(); ++nName)
      86             :             {
      87           0 :                 if ( pNames[nName] == "word" )
      88             :                 {
      89           0 :                     bWord = true;
      90           0 :                     if( sTypeName.isEmpty() )
      91           0 :                         sTypeName = "writer_MS_Word_2007";
      92           0 :                     break;
      93             :                 }
      94           0 :             }
      95           0 :         }
      96             :     }
      97           0 :     catch(const uno::Exception&)
      98             :     {
      99             :         OSL_FAIL("exception while opening storage");
     100             :     }
     101           0 :     if( !bWord )
     102           0 :         sTypeName = OUString();
     103           0 :    return sTypeName;
     104             : }
     105             : 
     106             : 
     107           0 : uno::Sequence< OUString > WriterFilterDetection_getSupportedServiceNames(  ) throw (uno::RuntimeException)
     108             : {
     109           0 :    uno::Sequence < OUString > aRet(1);
     110           0 :    OUString* pArray = aRet.getArray();
     111           0 :    pArray[0] = "com.sun.star.document.ExtendedTypeDetection";
     112           0 :    return aRet;
     113             : }
     114             : 
     115             : 
     116           0 : uno::Reference< uno::XInterface > WriterFilterDetection_createInstance( const uno::Reference< uno::XComponentContext >& xContext)
     117             :                 throw( uno::Exception )
     118             : {
     119           0 :    return (cppu::OWeakObject*) new WriterFilterDetection( xContext );
     120             : }
     121             : 
     122             : 
     123           0 : OUString WriterFilterDetection::getImplementationName(  ) throw (uno::RuntimeException, std::exception)
     124             : {
     125           0 :    return WriterFilterDetection_getImplementationName();
     126             : }
     127             : 
     128             : 
     129           0 : sal_Bool WriterFilterDetection::supportsService( const OUString& rServiceName ) throw (uno::RuntimeException, std::exception)
     130             : {
     131           0 :     return cppu::supportsService( this, rServiceName );
     132             : }
     133             : 
     134             : 
     135           0 : uno::Sequence< OUString > WriterFilterDetection::getSupportedServiceNames(  ) throw (uno::RuntimeException, std::exception)
     136             : {
     137           0 :     return WriterFilterDetection_getSupportedServiceNames();
     138             : }
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10