LCOV - code coverage report
Current view: top level - ucbhelper/source/provider - registerucb.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 23 42 54.8 %
Date: 2014-11-03 Functions: 1 1 100.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 <ucbhelper/registerucb.hxx>
      21             : #include <com/sun/star/beans/XPropertySet.hpp>
      22             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      23             : #include <com/sun/star/ucb/XContentProviderManager.hpp>
      24             : #include <com/sun/star/ucb/XParameterizedContentProvider.hpp>
      25             : #include <com/sun/star/ucb/ContentProviderProxyFactory.hpp>
      26             : #include <com/sun/star/ucb/XContentProviderFactory.hpp>
      27             : #include <com/sun/star/uno/XComponentContext.hpp>
      28             : #include <com/sun/star/uno/RuntimeException.hpp>
      29             : 
      30             : #include "osl/diagnose.h"
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34             : namespace ucbhelper {
      35             : 
      36             : 
      37             : 
      38             : //  registerAtUcb
      39             : 
      40             : 
      41             : 
      42             : bool
      43        3077 : registerAtUcb(
      44             :     uno::Reference< ucb::XContentProviderManager > const & rManager,
      45             :     uno::Reference< uno::XComponentContext > const & rxContext,
      46             :     OUString const & rName,
      47             :     OUString const & rArguments,
      48             :     OUString const & rTemplate)
      49             :     throw (uno::RuntimeException)
      50             : {
      51             :     OSL_ENSURE(rxContext.is(),
      52             :                "ucb::registerAtUcb(): No service factory");
      53             : 
      54        3077 :     bool bNoProxy = rArguments.startsWith("{noproxy}");
      55             :     OUString
      56             :         aProviderArguments(bNoProxy ?
      57             :                                rArguments.
      58             :                                    copy(RTL_CONSTASCII_LENGTH("{noproxy}")) :
      59        3077 :                                rArguments);
      60             : 
      61        6154 :     uno::Reference< ucb::XContentProvider > xProvider;
      62             : 
      63        3077 :     if (!rName.isEmpty())
      64             :     {
      65             :         // First, try to instantiate proxy for provider:
      66        2896 :         if (!bNoProxy)
      67             :         {
      68        2896 :             uno::Reference< ucb::XContentProviderFactory > xProxyFactory;
      69             :             try
      70             :             {
      71        2896 :                 xProxyFactory = ucb::ContentProviderProxyFactory::create( rxContext );
      72             :             }
      73           0 :             catch (uno::Exception const &) {}
      74             :             OSL_ENSURE(xProxyFactory.is(), "No ContentProviderProxyFactory");
      75        2896 :             if (xProxyFactory.is())
      76        2896 :                 xProvider = xProxyFactory->createContentProvider(rName);
      77             :         }
      78             : 
      79             :         // Then, try to instantiate provider directly:
      80        2896 :         if (!xProvider.is())
      81             :             try
      82             :             {
      83           0 :                 xProvider = uno::Reference< ucb::XContentProvider >(
      84           0 :                     rxContext->getServiceManager()->createInstanceWithContext(rName, rxContext),
      85           0 :                     uno::UNO_QUERY);
      86             :             }
      87           0 :             catch (uno::RuntimeException const &) { throw; }
      88           0 :             catch (uno::Exception const &) {}
      89             :     }
      90             : 
      91             :     uno::Reference< ucb::XParameterizedContentProvider >
      92        6154 :         xParameterized(xProvider, uno::UNO_QUERY);
      93        3077 :     if (xParameterized.is())
      94             :     {
      95        2896 :         uno::Reference< ucb::XContentProvider > xInstance;
      96             :         try
      97             :         {
      98        8688 :             xInstance = xParameterized->registerInstance(rTemplate,
      99             :                                                          aProviderArguments,
     100        5792 :                                                          true);
     101             :                 //@@@ if this call replaces an old instance, the commit-or-
     102             :                 // rollback code below will not work
     103             :         }
     104           0 :         catch (lang::IllegalArgumentException const &) {}
     105             : 
     106        2896 :         if (xInstance.is())
     107        2896 :             xProvider = xInstance;
     108             :     }
     109             : 
     110        3077 :     bool bSuccess = false;
     111        3077 :     if (rManager.is() && (rName.isEmpty() || xProvider.is()))
     112             :     {
     113             :         try
     114             :         {
     115        3077 :             rManager->registerContentProvider(xProvider, rTemplate, true);
     116        3077 :             bSuccess = true;
     117             :         }
     118           0 :         catch (ucb::DuplicateProviderException const &)
     119             :         {
     120           0 :             if (xParameterized.is())
     121             :                 try
     122             :                 {
     123           0 :                     xParameterized->deregisterInstance(rTemplate,
     124           0 :                                                        aProviderArguments);
     125             :                 }
     126           0 :                 catch (lang::IllegalArgumentException const &) {}
     127             :         }
     128           0 :         catch (...)
     129             :         {
     130           0 :             if (xParameterized.is())
     131             :                 try
     132             :                 {
     133           0 :                     xParameterized->deregisterInstance(rTemplate,
     134           0 :                                                        aProviderArguments);
     135             :                 }
     136           0 :                 catch (lang::IllegalArgumentException const &) {}
     137           0 :                 catch (uno::RuntimeException const &) {}
     138           0 :             throw;
     139             :         }
     140             :     }
     141        6154 :     return bSuccess;
     142             : }
     143             : 
     144             : }
     145             : 
     146             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10