LCOV - code coverage report
Current view: top level - libreoffice/writerfilter/source/filter - WriterFilterDetection.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 71 2.8 %
Date: 2012-12-27 Functions: 1 11 9.1 %
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 <WriterFilterDetection.hxx>
      22             : #include <comphelper/storagehelper.hxx>
      23             : #include <com/sun/star/io/XInputStream.hpp>
      24             : #include <sot/storage.hxx>
      25             : #include <unotools/ucbstreamhelper.hxx>
      26             : 
      27             : using namespace ::rtl;
      28             : using namespace ::cppu;
      29             : using namespace ::com::sun::star;
      30             : 
      31             : 
      32             : 
      33           0 : WriterFilterDetection::WriterFilterDetection(
      34             :     const uno::Reference< uno::XComponentContext >& rxContext) :
      35           0 :     m_xContext( rxContext )
      36             : {
      37           0 : }
      38             : 
      39             : 
      40           0 : WriterFilterDetection::~WriterFilterDetection()
      41             : {
      42           0 : }
      43             : 
      44             : 
      45           5 : OUString WriterFilterDetection_getImplementationName () throw (uno::RuntimeException)
      46             : {
      47           5 :    return OUString ( "com.sun.star.comp.Writer.WriterFilterDetector"  );
      48             : }
      49             : 
      50             : #define SERVICE_NAME1 "com.sun.star.document.ExtendedTypeDetection"
      51             : 
      52             : 
      53           0 : OUString WriterFilterDetection::detect( uno::Sequence< beans::PropertyValue >& rDescriptor )
      54             :    throw( uno::RuntimeException )
      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           0 :     bool bBinary = sTypeName == "writer_MS_Word_97" ||
      75           0 :                    sTypeName == "writer_MS_Word_97_Vorlage";
      76             : 
      77             :     try
      78             :     {
      79           0 :         if(bBinary)
      80             :         {
      81           0 :             SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xInputStream );
      82           0 :             if ( pStream && SotStorage::IsStorageFile(pStream) )
      83             : 
      84             :             {
      85           0 :                 SotStorageRef xStg = new SotStorage( pStream, sal_False );
      86             : 
      87           0 :                 bool bTable2 = xStg->IsContained(OUString("1Table"));
      88           0 :                 SotStorageStreamRef xRef = xStg->OpenSotStream(OUString("WordDocument"), STREAM_STD_READ | STREAM_NOCREATE );
      89             : 
      90           0 :                 if(bTable2 && xStg.Is())
      91             :                 {
      92           0 :                     xRef->Seek(2);
      93             :                     sal_Int16 nWord;
      94           0 :                     *xRef >> nWord;
      95             :                     //version detection
      96           0 :                     bWord = nWord >= 0x6a && nWord <= 0xc1;
      97           0 :                 }
      98             :             }
      99             :         }
     100             :         else
     101             :         {
     102           0 :             uno::Reference< embed::XStorage > xDocStorage;
     103           0 :             if ( sURL == "private:stream" )
     104           0 :                 xDocStorage = comphelper::OStorageHelper::GetStorageFromInputStream( xInputStream );
     105             :             else
     106             :                 xDocStorage = comphelper::OStorageHelper::GetStorageFromURL(
     107           0 :                                             sURL, embed::ElementModes::READ );
     108           0 :             if( xDocStorage.is() )
     109             :             {
     110           0 :                 uno::Sequence< OUString > aNames = xDocStorage->getElementNames();
     111           0 :                 const OUString* pNames = aNames.getConstArray();
     112           0 :                 for(sal_Int32 nName = 0; nName < aNames.getLength(); ++nName)
     113             :                 {
     114           0 :                     if ( pNames[nName] == "word" )
     115             :                     {
     116           0 :                         bWord = true;
     117           0 :                         if( sTypeName.isEmpty() )
     118           0 :                             sTypeName = "writer_MS_Word_2007";
     119           0 :                         break;
     120             :                     }
     121           0 :                 }
     122           0 :             }
     123             :         }
     124             :     }
     125           0 :     catch(const uno::Exception&)
     126             :     {
     127             :         OSL_FAIL("exception while opening storage");
     128             :     }
     129           0 :     if( !bWord )
     130           0 :         sTypeName = OUString();
     131           0 :    return sTypeName;
     132             : }
     133             : 
     134             : 
     135           0 : sal_Bool WriterFilterDetection_supportsService( const OUString& ServiceName ) throw (uno::RuntimeException)
     136             : {
     137           0 :    return ServiceName == SERVICE_NAME1;
     138             : }
     139             : 
     140             : 
     141           0 : uno::Sequence< OUString > WriterFilterDetection_getSupportedServiceNames(  ) throw (uno::RuntimeException)
     142             : {
     143           0 :    uno::Sequence < OUString > aRet(1);
     144           0 :    OUString* pArray = aRet.getArray();
     145           0 :    pArray[0] =  OUString ( SERVICE_NAME1  );
     146           0 :    return aRet;
     147             : }
     148             : #undef SERVICE_NAME1
     149             : 
     150             : 
     151           0 : uno::Reference< uno::XInterface > WriterFilterDetection_createInstance( const uno::Reference< uno::XComponentContext >& xContext)
     152             :                 throw( uno::Exception )
     153             : {
     154           0 :    return (cppu::OWeakObject*) new WriterFilterDetection( xContext );
     155             : }
     156             : 
     157             : 
     158           0 : OUString WriterFilterDetection::getImplementationName(  ) throw (uno::RuntimeException)
     159             : {
     160           0 :    return WriterFilterDetection_getImplementationName();
     161             : }
     162             : 
     163             : 
     164           0 : sal_Bool WriterFilterDetection::supportsService( const OUString& rServiceName ) throw (uno::RuntimeException)
     165             : {
     166           0 :     return WriterFilterDetection_supportsService( rServiceName );
     167             : }
     168             : 
     169             : 
     170           0 : uno::Sequence< OUString > WriterFilterDetection::getSupportedServiceNames(  ) throw (uno::RuntimeException)
     171             : {
     172           0 :     return WriterFilterDetection_getSupportedServiceNames();
     173             : }
     174             : 
     175             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10