LCOV - code coverage report
Current view: top level - framework/source/dispatch - systemexec.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 7 48 14.6 %
Date: 2015-06-13 12:38:46 Functions: 10 18 55.6 %
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 <dispatch/systemexec.hxx>
      21             : #include <general.h>
      22             : #include <services.h>
      23             : 
      24             : #include <com/sun/star/system/SystemShellExecute.hpp>
      25             : #include <com/sun/star/util/PathSubstitution.hpp>
      26             : #include <com/sun/star/util/XStringSubstitution.hpp>
      27             : #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
      28             : #include <com/sun/star/frame/DispatchResultState.hpp>
      29             : 
      30             : #include <vcl/svapp.hxx>
      31             : #include <comphelper/processfactory.hxx>
      32             : 
      33             : namespace framework{
      34             : 
      35             : #define PROTOCOL_VALUE      "systemexecute:"
      36             : #define PROTOCOL_LENGTH     14
      37             : 
      38             : // XInterface, XTypeProvider, XServiceInfo
      39             : 
      40          10 : DEFINE_XSERVICEINFO_MULTISERVICE_2(SystemExec                   ,
      41             :                                  ::cppu::OWeakObject          ,
      42             :                                  SERVICENAME_PROTOCOLHANDLER  ,
      43             :                                  IMPLEMENTATIONNAME_SYSTEMEXEC)
      44             : 
      45           1 : DEFINE_INIT_SERVICE(SystemExec,
      46             :                     {
      47             :                         /*Attention
      48             :                             I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
      49             :                             to create a new instance of this class by our own supported service factory.
      50             :                             see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further information!
      51             :                         */
      52             :                     }
      53             :                    )
      54             : 
      55           1 : SystemExec::SystemExec( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
      56           1 :         : m_xContext    ( rxContext                     )
      57             : {
      58           1 : }
      59             : 
      60           2 : SystemExec::~SystemExec()
      61             : {
      62           2 : }
      63             : 
      64           0 : css::uno::Reference< css::frame::XDispatch > SAL_CALL SystemExec::queryDispatch( const css::util::URL&  aURL    ,
      65             :                                                                                  const OUString&,
      66             :                                                                                        sal_Int32 ) throw( css::uno::RuntimeException, std::exception )
      67             : {
      68           0 :     css::uno::Reference< css::frame::XDispatch > xDispatcher;
      69           0 :     if (aURL.Complete.startsWith(PROTOCOL_VALUE))
      70           0 :         xDispatcher = this;
      71           0 :     return xDispatcher;
      72             : }
      73             : 
      74           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, std::exception )
      75             : {
      76           0 :     sal_Int32 nCount = lDescriptor.getLength();
      77           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatcher( nCount );
      78           0 :     for( sal_Int32 i=0; i<nCount; ++i )
      79             :     {
      80           0 :         lDispatcher[i] = this->queryDispatch(
      81           0 :                             lDescriptor[i].FeatureURL,
      82           0 :                             lDescriptor[i].FrameName,
      83           0 :                             lDescriptor[i].SearchFlags);
      84             :     }
      85           0 :     return lDispatcher;
      86             : }
      87             : 
      88           0 : void SAL_CALL SystemExec::dispatch( const css::util::URL&                                  aURL       ,
      89             :                                     const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException, std::exception )
      90             : {
      91           0 :     dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
      92           0 : }
      93             : 
      94           0 : void SAL_CALL SystemExec::dispatchWithNotification( const css::util::URL&                                             aURL      ,
      95             :                                                     const css::uno::Sequence< css::beans::PropertyValue >&,
      96             :                                                     const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw( css::uno::RuntimeException, std::exception )
      97             : {
      98             :     // convert "systemexec:file:///c:/temp/test.html" => "file:///c:/temp/test.html"
      99           0 :     sal_Int32 c = aURL.Complete.getLength()-PROTOCOL_LENGTH;
     100           0 :     if (c<1) // we dont check for valid URLs here! The system will show an error message ...
     101             :     {
     102           0 :         impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
     103           0 :         return;
     104             :     }
     105           0 :     OUString sSystemURLWithVariables = aURL.Complete.copy(PROTOCOL_LENGTH, c);
     106             : 
     107             :     // TODO check security settings ...
     108             : 
     109             :     try
     110             :     {
     111           0 :         css::uno::Reference< css::util::XStringSubstitution > xPathSubst( css::util::PathSubstitution::create(m_xContext) );
     112             : 
     113           0 :         OUString sSystemURL = xPathSubst->substituteVariables(sSystemURLWithVariables, sal_True); // sal_True force an exception if unknown variables exists !
     114             : 
     115           0 :         css::uno::Reference< css::system::XSystemShellExecute > xShell = css::system::SystemShellExecute::create( m_xContext );
     116             : 
     117           0 :         xShell->execute(sSystemURL, OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY);
     118           0 :         impl_notifyResultListener(xListener, css::frame::DispatchResultState::SUCCESS);
     119             :     }
     120           0 :     catch(const css::uno::Exception&)
     121             :         {
     122           0 :             impl_notifyResultListener(xListener, css::frame::DispatchResultState::FAILURE);
     123           0 :         }
     124             : }
     125             : 
     126           0 : void SAL_CALL SystemExec::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >&,
     127             :                                              const css::util::URL& ) throw( css::uno::RuntimeException, std::exception )
     128             : {
     129             :     // not supported yet
     130           0 : }
     131             : 
     132           0 : void SAL_CALL SystemExec::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >&,
     133             :                                                 const css::util::URL& ) throw( css::uno::RuntimeException, std::exception )
     134             : {
     135             :     // not supported yet
     136           0 : }
     137             : 
     138           0 : void SystemExec::impl_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
     139             :                                            const sal_Int16                                                   nState   )
     140             : {
     141           0 :     if (xListener.is())
     142             :     {
     143           0 :         css::frame::DispatchResultEvent aEvent;
     144           0 :         aEvent.State = nState;
     145           0 :         xListener->dispatchFinished(aEvent);
     146             :     }
     147           0 : }
     148             : 
     149             : }       //  namespace framework
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11