1*c142477cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c142477cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c142477cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c142477cSAndrew Rist * distributed with this work for additional information 6*c142477cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c142477cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c142477cSAndrew Rist * "License"); you may not use this file except in compliance 9*c142477cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*c142477cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*c142477cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c142477cSAndrew Rist * software distributed under the License is distributed on an 15*c142477cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c142477cSAndrew Rist * KIND, either express or implied. See the License for the 17*c142477cSAndrew Rist * specific language governing permissions and limitations 18*c142477cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*c142477cSAndrew Rist *************************************************************/ 21*c142477cSAndrew Rist 22*c142477cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sdext.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "pppoptimizer.hxx" 28cdf0e10cSrcweir #include "impoptimizer.hxx" 29cdf0e10cSrcweir #include <osl/file.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace ::rtl; 34cdf0e10cSrcweir using namespace ::com::sun::star::uno; 35cdf0e10cSrcweir using namespace ::com::sun::star::util; 36cdf0e10cSrcweir using namespace ::com::sun::star::lang; 37cdf0e10cSrcweir using namespace ::com::sun::star::frame; 38cdf0e10cSrcweir using namespace ::com::sun::star::beans; 39cdf0e10cSrcweir 40cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.comp.PPPOptimizer" 41cdf0e10cSrcweir 42cdf0e10cSrcweir // ---------------- 43cdf0e10cSrcweir // - PPPOptimizer - 44cdf0e10cSrcweir // ---------------- 45cdf0e10cSrcweir 46cdf0e10cSrcweir PPPOptimizer::PPPOptimizer( const Reference< XComponentContext > &rxMSF ) : 47cdf0e10cSrcweir mxMSF( rxMSF ) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir } 50cdf0e10cSrcweir 51cdf0e10cSrcweir // ----------------------------------------------------------------------------- 52cdf0e10cSrcweir 53cdf0e10cSrcweir PPPOptimizer::~PPPOptimizer() 54cdf0e10cSrcweir { 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir // ----------------------------------------------------------------------------- 58cdf0e10cSrcweir // XInitialization 59cdf0e10cSrcweir // ----------------------------------------------------------------------------- 60cdf0e10cSrcweir 61cdf0e10cSrcweir void SAL_CALL PPPOptimizer::initialize( const Sequence< Any >& aArguments ) 62cdf0e10cSrcweir throw ( Exception, RuntimeException ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir if( aArguments.getLength() != 1 ) 65cdf0e10cSrcweir throw IllegalArgumentException(); 66cdf0e10cSrcweir 67cdf0e10cSrcweir Reference< XFrame > xFrame; 68cdf0e10cSrcweir aArguments[ 0 ] >>= xFrame; 69cdf0e10cSrcweir if ( xFrame.is() ) 70cdf0e10cSrcweir mxController = xFrame->getController(); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir // ----------------------------------------------------------------------------- 74cdf0e10cSrcweir // XServiceInfo 75cdf0e10cSrcweir // ----------------------------------------------------------------------------- 76cdf0e10cSrcweir 77cdf0e10cSrcweir OUString SAL_CALL PPPOptimizer::getImplementationName() 78cdf0e10cSrcweir throw ( RuntimeException ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir return PPPOptimizer_getImplementationName(); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir sal_Bool SAL_CALL PPPOptimizer::supportsService( const OUString& rServiceName ) 84cdf0e10cSrcweir throw ( RuntimeException ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir return rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) ); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir Sequence< OUString > SAL_CALL PPPOptimizer::getSupportedServiceNames() 90cdf0e10cSrcweir throw ( RuntimeException ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir return PPPOptimizer_getSupportedServiceNames(); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir // ----------------------------------------------------------------------------- 96cdf0e10cSrcweir // XDispatchProvider 97cdf0e10cSrcweir // ----------------------------------------------------------------------------- 98cdf0e10cSrcweir 99cdf0e10cSrcweir Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizer::queryDispatch( 100cdf0e10cSrcweir const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir Reference < XDispatch > xRet; 103cdf0e10cSrcweir if ( aURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir // if ( aURL.Path.compareToAscii( "Function1" ) == 0 ) 106cdf0e10cSrcweir xRet = this; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir return xRet; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir //------------------------------------------------------------------------------ 112cdf0e10cSrcweir 113cdf0e10cSrcweir Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizer::queryDispatches( 114cdf0e10cSrcweir const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() ); 117cdf0e10cSrcweir Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray(); 118cdf0e10cSrcweir const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray(); 119cdf0e10cSrcweir for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags ); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir return aReturn; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir // ----------------------------------------------------------------------------- 127cdf0e10cSrcweir // XDispatch 128cdf0e10cSrcweir // ----------------------------------------------------------------------------- 129cdf0e10cSrcweir 130cdf0e10cSrcweir void SAL_CALL PPPOptimizer::dispatch( const URL& rURL, const Sequence< PropertyValue >& lArguments ) 131cdf0e10cSrcweir throw( RuntimeException ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir if ( mxController.is() && ( rURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 ) ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir if ( rURL.Path.compareToAscii( "optimize" ) == 0 ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir Reference< XModel > xModel( mxController->getModel() ); 138cdf0e10cSrcweir if ( xModel.is() ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir try 141cdf0e10cSrcweir { 142cdf0e10cSrcweir ImpOptimizer aOptimizer( mxMSF, xModel ); 143cdf0e10cSrcweir aOptimizer.Optimize( lArguments ); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir catch( Exception& ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir } 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir } 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir //=============================================== 154cdf0e10cSrcweir void SAL_CALL PPPOptimizer::addStatusListener( const Reference< XStatusListener >&, const URL& ) 155cdf0e10cSrcweir throw( RuntimeException ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir // TODO 158cdf0e10cSrcweir OSL_ENSURE( sal_False, "PPPOptimizer::addStatusListener()\nNot implemented yet!" ); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir //=============================================== 162cdf0e10cSrcweir void SAL_CALL PPPOptimizer::removeStatusListener( const Reference< XStatusListener >&, const URL& ) 163cdf0e10cSrcweir throw( RuntimeException ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir // TODO 166cdf0e10cSrcweir OSL_ENSURE( sal_False, "PPPOptimizer::removeStatusListener()\nNot implemented yet!" ); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir // ----------------------------------------------------------------------------- 170cdf0e10cSrcweir // returning filesize, on error zero is returned 171cdf0e10cSrcweir sal_Int64 PPPOptimizer::GetFileSize( const rtl::OUString& rURL ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir sal_Int64 nFileSize = 0; 174cdf0e10cSrcweir osl::DirectoryItem aItem; 175cdf0e10cSrcweir if ( osl::DirectoryItem::get( rURL, aItem ) == osl::FileBase::E_None ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir osl::FileStatus aStatus( osl_FileStatus_Mask_FileSize ); 178cdf0e10cSrcweir if ( aItem.getFileStatus( aStatus ) == osl::FileBase::E_None ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir nFileSize = aStatus.getFileSize(); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir } 183cdf0e10cSrcweir return nFileSize; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir // ----------------------------------------------------------------------------- 187cdf0e10cSrcweir 188cdf0e10cSrcweir OUString PPPOptimizer_getImplementationName() 189cdf0e10cSrcweir { 190cdf0e10cSrcweir return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.PPPOptimizerImp" ) ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir Sequence< OUString > PPPOptimizer_getSupportedServiceNames() 194cdf0e10cSrcweir { 195cdf0e10cSrcweir Sequence < OUString > aRet(1); 196cdf0e10cSrcweir OUString* pArray = aRet.getArray(); 197cdf0e10cSrcweir pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); 198cdf0e10cSrcweir return aRet; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir Reference< XInterface > PPPOptimizer_createInstance( const Reference< XComponentContext > & rSMgr ) 202cdf0e10cSrcweir throw( Exception ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir return (cppu::OWeakObject*) new PPPOptimizer( rSMgr ); 205cdf0e10cSrcweir } 206