LCOV - code coverage report
Current view: top level - svl/source/fsstor - fsfactory.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 60 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             : 
      21             : #include "fsfactory.hxx"
      22             : #include "cppuhelper/factory.hxx"
      23             : #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
      24             : #include <com/sun/star/embed/ElementModes.hpp>
      25             : #include <com/sun/star/io/XSeekable.hpp>
      26             : #include <comphelper/processfactory.hxx>
      27             : #include <cppuhelper/supportsservice.hxx>
      28             : 
      29             : #include <ucbhelper/fileidentifierconverter.hxx>
      30             : #include <ucbhelper/content.hxx>
      31             : 
      32             : #include <unotools/tempfile.hxx>
      33             : #include <unotools/ucbhelper.hxx>
      34             : 
      35             : #include "fsstorage.hxx"
      36             : 
      37             : 
      38             : using namespace ::com::sun::star;
      39             : 
      40           0 : uno::Sequence< OUString > SAL_CALL FSStorageFactory::impl_staticGetSupportedServiceNames()
      41             : {
      42           0 :     uno::Sequence< OUString > aRet(2);
      43           0 :     aRet[0] = "com.sun.star.embed.FileSystemStorageFactory";
      44           0 :     aRet[1] = "com.sun.star.comp.embed.FileSystemStorageFactory";
      45           0 :     return aRet;
      46             : }
      47             : 
      48           0 : OUString SAL_CALL FSStorageFactory::impl_staticGetImplementationName()
      49             : {
      50           0 :     return OUString("com.sun.star.comp.embed.FileSystemStorageFactory");
      51             : }
      52             : 
      53           0 : uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::impl_staticCreateSelfInstance(
      54             :             const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
      55             : {
      56           0 :     return uno::Reference< uno::XInterface >( *new FSStorageFactory( comphelper::getComponentContext(xServiceManager) ) );
      57             : }
      58             : 
      59           0 : uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstance()
      60             :     throw ( uno::Exception,
      61             :             uno::RuntimeException, std::exception )
      62             : {
      63           0 :     OUString aTempURL;
      64             : 
      65           0 :     aTempURL = ::utl::TempFile( NULL, true ).GetURL();
      66             : 
      67           0 :     if ( aTempURL.isEmpty() )
      68           0 :         throw uno::RuntimeException(); // TODO: can not create tempfile
      69             : 
      70             :     ::ucbhelper::Content aResultContent(
      71             :         aTempURL, uno::Reference< ucb::XCommandEnvironment >(),
      72           0 :         comphelper::getProcessComponentContext() );
      73             : 
      74             :     return uno::Reference< uno::XInterface >(
      75             :         static_cast< OWeakObject* >(
      76             :             new FSStorage(  aResultContent,
      77             :                             embed::ElementModes::READWRITE,
      78           0 :                             m_xContext ) ),
      79           0 :         uno::UNO_QUERY );
      80             : }
      81             : 
      82           0 : uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstanceWithArguments(
      83             :             const uno::Sequence< uno::Any >& aArguments )
      84             :     throw ( uno::Exception,
      85             :             uno::RuntimeException, std::exception )
      86             : {
      87             :     // The request for storage can be done with up to three arguments
      88             : 
      89             :     // The first argument specifies a source for the storage
      90             :     // it must be URL.
      91             :     // The second value is a mode the storage should be open in.
      92             :     // And the third value is a media descriptor.
      93             : 
      94           0 :     sal_Int32 nArgNum = aArguments.getLength();
      95             :     OSL_ENSURE( nArgNum < 4, "Wrong parameter number" );
      96             : 
      97           0 :     if ( !nArgNum )
      98           0 :         return createInstance();
      99             : 
     100             :     // first try to retrieve storage open mode if any
     101             :     // by default the storage will be open in readonly mode
     102           0 :     sal_Int32 nStorageMode = embed::ElementModes::READ;
     103           0 :     if ( nArgNum >= 2 )
     104             :     {
     105           0 :         if( !( aArguments[1] >>= nStorageMode ) )
     106             :         {
     107             :             throw lang::IllegalArgumentException(
     108             :                 ("second argument to css.embed.FileSystemStorageFactory."
     109             :                  "createInstanceWithArguments must be a"
     110             :                  " css.embed.ElementModes"),
     111           0 :                 static_cast< OWeakObject * >(this), -1);
     112             :         }
     113             :         // it's always possible to read written storage in this implementation
     114           0 :         nStorageMode |= embed::ElementModes::READ;
     115             :     }
     116             : 
     117             :     // retrieve storage source URL
     118           0 :     OUString aURL;
     119             : 
     120           0 :     if ( !( aArguments[0] >>= aURL ) || aURL.isEmpty() )
     121             :     {
     122             :         throw lang::IllegalArgumentException(
     123             :             ("first argument to"
     124             :              " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
     125             :              " must be a (non-empty) URL"),
     126           0 :             static_cast< OWeakObject * >(this), -1);
     127             :     }
     128             : 
     129             :     // allow to use other ucp's
     130             :     // if ( !isLocalNotFile_Impl( aURL ) )
     131           0 :     if ( aURL.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:")
     132           0 :       || aURL.startsWithIgnoreAsciiCase("vnd.sun.star.zip:")
     133           0 :       || ::utl::UCBContentHelper::IsDocument( aURL ) )
     134             :     {
     135             :         throw lang::IllegalArgumentException(
     136           0 :             ("URL \"" + aURL + "\" passed as first argument to"
     137             :              " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
     138             :              " must be a file URL denoting a directory"),
     139           0 :             static_cast< OWeakObject * >(this), -1);
     140             :     }
     141             : 
     142           0 :     if ( ( nStorageMode & embed::ElementModes::WRITE ) && !( nStorageMode & embed::ElementModes::NOCREATE ) )
     143           0 :         FSStorage::MakeFolderNoUI( aURL );
     144           0 :     else if ( !::utl::UCBContentHelper::IsFolder( aURL ) )
     145             :         throw io::IOException(
     146           0 :             ("URL \"" + aURL + "\" passed to"
     147             :              " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
     148             :              " does not denote an existing directory"),
     149           0 :             static_cast< OWeakObject * >(this));
     150             : 
     151             :     ::ucbhelper::Content aResultContent(
     152             :         aURL, uno::Reference< ucb::XCommandEnvironment >(),
     153           0 :         comphelper::getProcessComponentContext() );
     154             : 
     155             :     // create storage based on source
     156             :     return uno::Reference< uno::XInterface >(
     157             :         static_cast< OWeakObject* >( new FSStorage( aResultContent,
     158             :                                                     nStorageMode,
     159           0 :                                                     m_xContext ) ),
     160           0 :         uno::UNO_QUERY );
     161             : }
     162             : 
     163           0 : OUString SAL_CALL FSStorageFactory::getImplementationName()
     164             :     throw ( uno::RuntimeException, std::exception )
     165             : {
     166           0 :     return impl_staticGetImplementationName();
     167             : }
     168             : 
     169           0 : sal_Bool SAL_CALL FSStorageFactory::supportsService( const OUString& ServiceName )
     170             :     throw ( uno::RuntimeException, std::exception )
     171             : {
     172           0 :     return cppu::supportsService(this, ServiceName);
     173             : }
     174             : 
     175           0 : uno::Sequence< OUString > SAL_CALL FSStorageFactory::getSupportedServiceNames()
     176             :     throw ( uno::RuntimeException, std::exception )
     177             : {
     178           0 :     return impl_staticGetSupportedServiceNames();
     179             : }
     180             : 
     181             : 
     182             : extern "C"
     183             : {
     184           0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL fsstorage_component_getFactory (
     185             :     const sal_Char * pImplementationName, void * pServiceManager,
     186             :     SAL_UNUSED_PARAMETER void * /* pRegistryKey */)
     187             : {
     188           0 :     void * pResult = 0;
     189           0 :     if (pServiceManager)
     190             :     {
     191           0 :         uno::Reference< lang::XSingleServiceFactory > xFactory;
     192           0 :         if (FSStorageFactory::impl_staticGetImplementationName().equalsAscii(pImplementationName))
     193             :         {
     194           0 :             xFactory = cppu::createOneInstanceFactory (
     195             :                 reinterpret_cast< lang::XMultiServiceFactory* >(pServiceManager),
     196             :                 FSStorageFactory::impl_staticGetImplementationName(),
     197             :                 FSStorageFactory::impl_staticCreateSelfInstance,
     198           0 :                 FSStorageFactory::impl_staticGetSupportedServiceNames() );
     199             :         }
     200           0 :         if (xFactory.is())
     201             :         {
     202           0 :             xFactory->acquire();
     203           0 :             pResult = xFactory.get();
     204           0 :         }
     205             :     }
     206           0 :     return pResult;
     207             : }
     208             : 
     209             : } // extern "C"
     210             : 
     211             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10