LCOV - code coverage report
Current view: top level - ucb/source/ucp/expand - ucpexpand.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 53 0.0 %
Date: 2014-04-14 Functions: 0 17 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 "rtl/uri.hxx"
      22             : #include "osl/mutex.hxx"
      23             : #include "cppuhelper/compbase2.hxx"
      24             : #include "cppuhelper/factory.hxx"
      25             : #include "cppuhelper/implementationentry.hxx"
      26             : #include <cppuhelper/supportsservice.hxx>
      27             : #include "ucbhelper/content.hxx"
      28             : #include "com/sun/star/uno/XComponentContext.hpp"
      29             : #include "com/sun/star/lang/DisposedException.hpp"
      30             : #include "com/sun/star/lang/XServiceInfo.hpp"
      31             : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
      32             : #include "com/sun/star/registry/XRegistryKey.hpp"
      33             : #include "com/sun/star/util/theMacroExpander.hpp"
      34             : #include "com/sun/star/ucb/XContentProvider.hpp"
      35             : 
      36             : #define EXPAND_PROTOCOL "vnd.sun.star.expand"
      37             : #define ARLEN(x) sizeof (x) / sizeof *(x)
      38             : 
      39             : 
      40             : using namespace ::com::sun::star;
      41             : 
      42             : namespace
      43             : {
      44             : 
      45           0 : struct MutexHolder
      46             : {
      47             :     mutable ::osl::Mutex m_mutex;
      48             : };
      49             : 
      50             : typedef ::cppu::WeakComponentImplHelper2<
      51             :     lang::XServiceInfo, ucb::XContentProvider > t_impl_helper;
      52             : 
      53             : 
      54             : class ExpandContentProviderImpl : protected MutexHolder, public t_impl_helper
      55             : {
      56             :     uno::Reference< uno::XComponentContext > m_xComponentContext;
      57             :     uno::Reference< util::XMacroExpander >   m_xMacroExpander;
      58             :     OUString expandUri(
      59             :         uno::Reference< ucb::XContentIdentifier > const & xIdentifier ) const;
      60             : 
      61             : protected:
      62             :     inline void check() const;
      63             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
      64             : 
      65             : public:
      66           0 :     inline ExpandContentProviderImpl(
      67             :         uno::Reference< uno::XComponentContext > const & xComponentContext )
      68             :         : t_impl_helper( m_mutex ),
      69             :           m_xComponentContext( xComponentContext ),
      70           0 :           m_xMacroExpander( util::theMacroExpander::get(xComponentContext) )
      71           0 :         {}
      72             :     virtual ~ExpandContentProviderImpl() throw ();
      73             : 
      74             :     // XServiceInfo
      75             :     virtual OUString SAL_CALL getImplementationName()
      76             :         throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      77             :     virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName )
      78             :         throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      79             :     virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
      80             :         throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      81             : 
      82             :     // XContentProvider
      83             :     virtual uno::Reference< ucb::XContent > SAL_CALL queryContent(
      84             :         uno::Reference< ucb::XContentIdentifier > const & xIdentifier )
      85             :         throw (ucb::IllegalIdentifierException, uno::RuntimeException, std::exception) SAL_OVERRIDE;
      86             :     virtual sal_Int32 SAL_CALL compareContentIds(
      87             :         uno::Reference< ucb::XContentIdentifier > const & xId1,
      88             :         uno::Reference< ucb::XContentIdentifier > const & xId2 )
      89             :         throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
      90             : };
      91             : 
      92             : 
      93           0 : inline void ExpandContentProviderImpl::check() const
      94             : {
      95             :     // xxx todo guard?
      96             : //     MutexGuard guard( m_mutex );
      97           0 :     if (rBHelper.bInDispose || rBHelper.bDisposed)
      98             :     {
      99             :         throw lang::DisposedException(
     100             :             "expand content provider instance has "
     101             :             "already been disposed!",
     102             :             static_cast< OWeakObject * >(
     103           0 :                 const_cast< ExpandContentProviderImpl * >(this) ) );
     104             :     }
     105           0 : }
     106             : 
     107             : 
     108           0 : ExpandContentProviderImpl::~ExpandContentProviderImpl() throw ()
     109             : {
     110           0 : }
     111             : 
     112             : 
     113           0 : void ExpandContentProviderImpl::disposing()
     114             : {
     115           0 : }
     116             : 
     117             : 
     118           0 : static uno::Reference< uno::XInterface > SAL_CALL create(
     119             :     uno::Reference< uno::XComponentContext > const & xComponentContext )
     120             :     SAL_THROW( (uno::Exception) )
     121             : {
     122             :     return static_cast< ::cppu::OWeakObject * >(
     123           0 :         new ExpandContentProviderImpl( xComponentContext ) );
     124             : }
     125             : 
     126             : 
     127           0 : static OUString SAL_CALL implName()
     128             : {
     129           0 :     return OUString("com.sun.star.comp.ucb.ExpandContentProvider");
     130             : }
     131             : 
     132             : 
     133           0 : static uno::Sequence< OUString > SAL_CALL supportedServices()
     134             : {
     135             :     OUString names [] = {
     136             :         OUString("com.sun.star.ucb.ExpandContentProvider"),
     137             :         OUString("com.sun.star.ucb.ContentProvider")
     138           0 :     };
     139           0 :     return uno::Sequence< OUString >( names, ARLEN(names) );
     140             : }
     141             : 
     142             : // XServiceInfo
     143             : 
     144           0 : OUString ExpandContentProviderImpl::getImplementationName()
     145             :     throw (uno::RuntimeException, std::exception)
     146             : {
     147           0 :     check();
     148           0 :     return implName();
     149             : }
     150             : 
     151             : 
     152           0 : uno::Sequence< OUString > ExpandContentProviderImpl::getSupportedServiceNames()
     153             :     throw (uno::RuntimeException, std::exception)
     154             : {
     155           0 :     check();
     156           0 :     return supportedServices();
     157             : }
     158             : 
     159           0 : sal_Bool ExpandContentProviderImpl::supportsService(OUString const & serviceName )
     160             :     throw (uno::RuntimeException, std::exception)
     161             : {
     162           0 :     return cppu::supportsService(this, serviceName);
     163             : }
     164             : 
     165           0 : OUString ExpandContentProviderImpl::expandUri(
     166             :     uno::Reference< ucb::XContentIdentifier > const & xIdentifier ) const
     167             : {
     168           0 :     OUString uri( xIdentifier->getContentIdentifier() );
     169           0 :     if (!uri.startsWith(EXPAND_PROTOCOL ":"))
     170             :     {
     171             :         throw ucb::IllegalIdentifierException(
     172             :             "expected protocol " EXPAND_PROTOCOL "!",
     173             :             static_cast< OWeakObject * >(
     174           0 :                 const_cast< ExpandContentProviderImpl * >(this) ) );
     175             :     }
     176             :     // cut protocol
     177           0 :     OUString str( uri.copy( sizeof (EXPAND_PROTOCOL ":") -1 ) );
     178             :     // decode uric class chars
     179           0 :     str = ::rtl::Uri::decode(
     180           0 :         str, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
     181             :     // expand macro string
     182           0 :     return m_xMacroExpander->expandMacros( str );
     183             : }
     184             : 
     185             : // XContentProvider
     186             : 
     187           0 : uno::Reference< ucb::XContent > ExpandContentProviderImpl::queryContent(
     188             :     uno::Reference< ucb::XContentIdentifier > const & xIdentifier )
     189             :     throw (ucb::IllegalIdentifierException, uno::RuntimeException, std::exception)
     190             : {
     191           0 :     check();
     192           0 :     OUString uri( expandUri( xIdentifier ) );
     193             : 
     194           0 :     ::ucbhelper::Content ucb_content;
     195           0 :     if (::ucbhelper::Content::create(
     196             :             uri, uno::Reference< ucb::XCommandEnvironment >(),
     197           0 :             m_xComponentContext, ucb_content ))
     198             :     {
     199           0 :         return ucb_content.get();
     200             :     }
     201             :     else
     202             :     {
     203           0 :         return uno::Reference< ucb::XContent >();
     204           0 :     }
     205             : }
     206             : 
     207             : 
     208           0 : sal_Int32 ExpandContentProviderImpl::compareContentIds(
     209             :     uno::Reference< ucb::XContentIdentifier > const & xId1,
     210             :     uno::Reference< ucb::XContentIdentifier > const & xId2 )
     211             :     throw (uno::RuntimeException, std::exception)
     212             : {
     213           0 :     check();
     214             :     try
     215             :     {
     216           0 :         OUString uri1( expandUri( xId1 ) );
     217           0 :         OUString uri2( expandUri( xId2 ) );
     218           0 :         return uri1.compareTo( uri2 );
     219             :     }
     220           0 :     catch (const ucb::IllegalIdentifierException & exc)
     221             :     {
     222             :         (void) exc; // unused
     223             :         OSL_FAIL(
     224             :             OUStringToOString(
     225             :                 exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
     226           0 :         return -1;
     227             :     }
     228             : }
     229             : 
     230             : static const ::cppu::ImplementationEntry s_entries [] =
     231             : {
     232             :     {
     233             :         create,
     234             :         implName,
     235             :         supportedServices,
     236             :         ::cppu::createSingleComponentFactory,
     237             :         0, 0
     238             :     },
     239             :     { 0, 0, 0, 0, 0, 0 }
     240             : };
     241             : 
     242             : }
     243             : 
     244             : extern "C"
     245             : {
     246             : 
     247           0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL ucpexpand1_component_getFactory(
     248             :     const sal_Char * pImplName,
     249             :     lang::XMultiServiceFactory * pServiceManager,
     250             :     registry::XRegistryKey * pRegistryKey )
     251             : {
     252             :     return ::cppu::component_getFactoryHelper(
     253           0 :         pImplName, pServiceManager, pRegistryKey, s_entries );
     254             : }
     255             : 
     256             : }
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10