LCOV - code coverage report
Current view: top level - framework/source/dispatch - systemexec.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 57 0.0 %
Date: 2012-08-25 Functions: 0 23 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <dispatch/systemexec.hxx>
      30                 :            : #include <threadhelp/readguard.hxx>
      31                 :            : #include <general.h>
      32                 :            : #include <services.h>
      33                 :            : 
      34                 :            : #include <com/sun/star/system/XSystemShellExecute.hpp>
      35                 :            : #include <com/sun/star/util/PathSubstitution.hpp>
      36                 :            : #include <com/sun/star/util/XStringSubstitution.hpp>
      37                 :            : #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
      38                 :            : #include <com/sun/star/frame/DispatchResultState.hpp>
      39                 :            : 
      40                 :            : #include <vcl/svapp.hxx>
      41                 :            : #include <comphelper/componentcontext.hxx>
      42                 :            : 
      43                 :            : namespace framework{
      44                 :            : 
      45                 :            : #define PROTOCOL_VALUE      "systemexecute:"
      46                 :            : #define PROTOCOL_LENGTH     14
      47                 :            : 
      48                 :            : //_________________________________________________________________________________________________________________
      49                 :            : // XInterface, XTypeProvider, XServiceInfo
      50                 :            : 
      51                 :          0 : DEFINE_XINTERFACE_5(SystemExec                                      ,
      52                 :            :                     OWeakObject                                     ,
      53                 :            :                     DIRECT_INTERFACE(css::lang::XTypeProvider      ),
      54                 :            :                     DIRECT_INTERFACE(css::lang::XServiceInfo       ),
      55                 :            :                     DIRECT_INTERFACE(css::frame::XDispatchProvider ),
      56                 :            :                     DIRECT_INTERFACE(css::frame::XNotifyingDispatch),
      57                 :            :                     DIRECT_INTERFACE(css::frame::XDispatch         ))
      58                 :            : 
      59                 :          0 : DEFINE_XTYPEPROVIDER_5(SystemExec                    ,
      60                 :            :                        css::lang::XTypeProvider      ,
      61                 :            :                        css::lang::XServiceInfo       ,
      62                 :            :                        css::frame::XDispatchProvider ,
      63                 :            :                        css::frame::XNotifyingDispatch,
      64                 :            :                        css::frame::XDispatch         )
      65                 :            : 
      66                 :          0 : DEFINE_XSERVICEINFO_MULTISERVICE(SystemExec                   ,
      67                 :            :                                  ::cppu::OWeakObject          ,
      68                 :            :                                  SERVICENAME_PROTOCOLHANDLER  ,
      69                 :            :                                  IMPLEMENTATIONNAME_SYSTEMEXEC)
      70                 :            : 
      71                 :          0 : DEFINE_INIT_SERVICE(SystemExec,
      72                 :            :                     {
      73                 :            :                         /*Attention
      74                 :            :                             I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
      75                 :            :                             to create a new instance of this class by our own supported service factory.
      76                 :            :                             see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
      77                 :            :                         */
      78                 :            :                     }
      79                 :            :                    )
      80                 :            : 
      81                 :            : //_________________________________________________________________________________________________________________
      82                 :            : 
      83                 :          0 : SystemExec::SystemExec( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
      84                 :            :         //  Init baseclasses first
      85                 :          0 :         : ThreadHelpBase( &Application::GetSolarMutex() )
      86                 :            :         , OWeakObject   (                               )
      87                 :            :         // Init member
      88                 :          0 :         , m_xFactory    ( xFactory                      )
      89                 :            : {
      90                 :          0 : }
      91                 :            : 
      92                 :            : //_________________________________________________________________________________________________________________
      93                 :            : 
      94                 :          0 : SystemExec::~SystemExec()
      95                 :            : {
      96                 :          0 :     m_xFactory = NULL;
      97                 :          0 : }
      98                 :            : 
      99                 :            : //_________________________________________________________________________________________________________________
     100                 :            : 
     101                 :          0 : css::uno::Reference< css::frame::XDispatch > SAL_CALL SystemExec::queryDispatch( const css::util::URL&  aURL    ,
     102                 :            :                                                                                  const ::rtl::OUString&,
     103                 :            :                                                                                        sal_Int32 ) throw( css::uno::RuntimeException )
     104                 :            : {
     105                 :          0 :     css::uno::Reference< css::frame::XDispatch > xDispatcher;
     106                 :          0 :     if (aURL.Complete.compareToAscii(PROTOCOL_VALUE,PROTOCOL_LENGTH)==0)
     107                 :          0 :         xDispatcher = this;
     108                 :          0 :     return xDispatcher;
     109                 :            : }
     110                 :            : 
     111                 :            : //_________________________________________________________________________________________________________________
     112                 :            : 
     113                 :          0 : css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL SystemExec::queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor ) throw( css::uno::RuntimeException )
     114                 :            : {
     115                 :          0 :     sal_Int32 nCount = lDescriptor.getLength();
     116                 :          0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatcher( nCount );
     117                 :          0 :     for( sal_Int32 i=0; i<nCount; ++i )
     118                 :            :     {
     119                 :          0 :         lDispatcher[i] = this->queryDispatch(
     120                 :          0 :                             lDescriptor[i].FeatureURL,
     121                 :          0 :                             lDescriptor[i].FrameName,
     122                 :          0 :                             lDescriptor[i].SearchFlags);
     123                 :            :     }
     124                 :          0 :     return lDispatcher;
     125                 :            : }
     126                 :            : 
     127                 :            : //_________________________________________________________________________________________________________________
     128                 :            : 
     129                 :          0 : void SAL_CALL SystemExec::dispatch( const css::util::URL&                                  aURL       ,
     130                 :            :                                     const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException )
     131                 :            : {
     132                 :          0 :     dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
     133                 :          0 : }
     134                 :            : 
     135                 :            : //_________________________________________________________________________________________________________________
     136                 :            : 
     137                 :          0 : void SAL_CALL SystemExec::dispatchWithNotification( const css::util::URL&                                             aURL      ,
     138                 :            :                                                     const css::uno::Sequence< css::beans::PropertyValue >&,
     139                 :            :                                                     const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw( css::uno::RuntimeException )
     140                 :            : {
     141                 :            :     // convert "systemexec:file:///c:/temp/test.html" => "file:///c:/temp/test.html"
     142                 :          0 :     sal_Int32 c = aURL.Complete.getLength()-PROTOCOL_LENGTH;
     143                 :          0 :     if (c<1) // we dont check for valid URLs here! The system will show an error message ...
     144                 :            :     {
     145                 :          0 :         impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
     146                 :          0 :         return;
     147                 :            :     }
     148                 :          0 :     ::rtl::OUString sSystemURLWithVariables = aURL.Complete.copy(PROTOCOL_LENGTH, c);
     149                 :            : 
     150                 :            :     // SAFE ->
     151                 :          0 :     ReadGuard aReadLock(m_aLock);
     152                 :          0 :     css::uno::Reference< css::lang::XMultiServiceFactory > xFactory = m_xFactory;
     153                 :          0 :     aReadLock.unlock();
     154                 :            :     // <- SAFE
     155                 :            : 
     156                 :            :     // TODO check security settings ...
     157                 :            : 
     158                 :            :     try
     159                 :            :     {
     160                 :          0 :         css::uno::Reference< css::uno::XComponentContext > xContext( comphelper::ComponentContext(xFactory).getUNOContext() );
     161                 :          0 :         css::uno::Reference< css::util::XStringSubstitution > xPathSubst( css::util::PathSubstitution::create(xContext) );
     162                 :            : 
     163                 :          0 :         ::rtl::OUString sSystemURL = xPathSubst->substituteVariables(sSystemURLWithVariables, sal_True); // sal_True force an exception if unknown variables exists !
     164                 :            : 
     165                 :            :         css::uno::Reference< css::system::XSystemShellExecute > xShell(
     166                 :          0 :             xFactory->createInstance(SERVICENAME_SYSTEMSHELLEXECUTE),
     167                 :          0 :             css::uno::UNO_QUERY_THROW);
     168                 :            : 
     169                 :          0 :         xShell->execute(sSystemURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY);
     170                 :          0 :         impl_notifyResultListener(xListener, css::frame::DispatchResultState::SUCCESS);
     171                 :            :     }
     172                 :          0 :     catch(const css::uno::Exception&)
     173                 :            :         {
     174                 :          0 :             impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
     175                 :          0 :         }
     176                 :            : }
     177                 :            : 
     178                 :            : //_________________________________________________________________________________________________________________
     179                 :            : 
     180                 :          0 : void SAL_CALL SystemExec::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >&,
     181                 :            :                                              const css::util::URL& ) throw( css::uno::RuntimeException )
     182                 :            : {
     183                 :            :     // not suported yet
     184                 :          0 : }
     185                 :            : 
     186                 :            : //_________________________________________________________________________________________________________________
     187                 :            : 
     188                 :          0 : void SAL_CALL SystemExec::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >&,
     189                 :            :                                                 const css::util::URL& ) throw( css::uno::RuntimeException )
     190                 :            : {
     191                 :            :     // not suported yet
     192                 :          0 : }
     193                 :            : 
     194                 :            : //_________________________________________________________________________________________________________________
     195                 :            : 
     196                 :          0 : void SystemExec::impl_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
     197                 :            :                                            const sal_Int16                                                   nState   )
     198                 :            : {
     199                 :          0 :     if (xListener.is())
     200                 :            :     {
     201                 :          0 :         css::frame::DispatchResultEvent aEvent;
     202                 :          0 :         aEvent.State = nState;
     203                 :          0 :         xListener->dispatchFinished(aEvent);
     204                 :            :     }
     205                 :          0 : }
     206                 :            : 
     207                 :            : }       //  namespace framework
     208                 :            : 
     209                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10