1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sdext.hxx" 30 31 #include "pppoptimizer.hxx" 32 #include "impoptimizer.hxx" 33 #include <osl/file.hxx> 34 35 #include <com/sun/star/lang/IllegalArgumentException.hpp> 36 37 using namespace ::rtl; 38 using namespace ::com::sun::star::uno; 39 using namespace ::com::sun::star::util; 40 using namespace ::com::sun::star::lang; 41 using namespace ::com::sun::star::frame; 42 using namespace ::com::sun::star::beans; 43 44 #define SERVICE_NAME "com.sun.star.comp.PPPOptimizer" 45 46 // ---------------- 47 // - PPPOptimizer - 48 // ---------------- 49 50 PPPOptimizer::PPPOptimizer( const Reference< XComponentContext > &rxMSF ) : 51 mxMSF( rxMSF ) 52 { 53 } 54 55 // ----------------------------------------------------------------------------- 56 57 PPPOptimizer::~PPPOptimizer() 58 { 59 } 60 61 // ----------------------------------------------------------------------------- 62 // XInitialization 63 // ----------------------------------------------------------------------------- 64 65 void SAL_CALL PPPOptimizer::initialize( const Sequence< Any >& aArguments ) 66 throw ( Exception, RuntimeException ) 67 { 68 if( aArguments.getLength() != 1 ) 69 throw IllegalArgumentException(); 70 71 Reference< XFrame > xFrame; 72 aArguments[ 0 ] >>= xFrame; 73 if ( xFrame.is() ) 74 mxController = xFrame->getController(); 75 } 76 77 // ----------------------------------------------------------------------------- 78 // XServiceInfo 79 // ----------------------------------------------------------------------------- 80 81 OUString SAL_CALL PPPOptimizer::getImplementationName() 82 throw ( RuntimeException ) 83 { 84 return PPPOptimizer_getImplementationName(); 85 } 86 87 sal_Bool SAL_CALL PPPOptimizer::supportsService( const OUString& rServiceName ) 88 throw ( RuntimeException ) 89 { 90 return rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) ); 91 } 92 93 Sequence< OUString > SAL_CALL PPPOptimizer::getSupportedServiceNames() 94 throw ( RuntimeException ) 95 { 96 return PPPOptimizer_getSupportedServiceNames(); 97 } 98 99 // ----------------------------------------------------------------------------- 100 // XDispatchProvider 101 // ----------------------------------------------------------------------------- 102 103 Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizer::queryDispatch( 104 const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException ) 105 { 106 Reference < XDispatch > xRet; 107 if ( aURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 ) 108 { 109 // if ( aURL.Path.compareToAscii( "Function1" ) == 0 ) 110 xRet = this; 111 } 112 return xRet; 113 } 114 115 //------------------------------------------------------------------------------ 116 117 Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizer::queryDispatches( 118 const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException ) 119 { 120 Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() ); 121 Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray(); 122 const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray(); 123 for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts ) 124 { 125 *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags ); 126 } 127 return aReturn; 128 } 129 130 // ----------------------------------------------------------------------------- 131 // XDispatch 132 // ----------------------------------------------------------------------------- 133 134 void SAL_CALL PPPOptimizer::dispatch( const URL& rURL, const Sequence< PropertyValue >& lArguments ) 135 throw( RuntimeException ) 136 { 137 if ( mxController.is() && ( rURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 ) ) 138 { 139 if ( rURL.Path.compareToAscii( "optimize" ) == 0 ) 140 { 141 Reference< XModel > xModel( mxController->getModel() ); 142 if ( xModel.is() ) 143 { 144 try 145 { 146 ImpOptimizer aOptimizer( mxMSF, xModel ); 147 aOptimizer.Optimize( lArguments ); 148 } 149 catch( Exception& ) 150 { 151 } 152 } 153 } 154 } 155 } 156 157 //=============================================== 158 void SAL_CALL PPPOptimizer::addStatusListener( const Reference< XStatusListener >&, const URL& ) 159 throw( RuntimeException ) 160 { 161 // TODO 162 OSL_ENSURE( sal_False, "PPPOptimizer::addStatusListener()\nNot implemented yet!" ); 163 } 164 165 //=============================================== 166 void SAL_CALL PPPOptimizer::removeStatusListener( const Reference< XStatusListener >&, const URL& ) 167 throw( RuntimeException ) 168 { 169 // TODO 170 OSL_ENSURE( sal_False, "PPPOptimizer::removeStatusListener()\nNot implemented yet!" ); 171 } 172 173 // ----------------------------------------------------------------------------- 174 // returning filesize, on error zero is returned 175 sal_Int64 PPPOptimizer::GetFileSize( const rtl::OUString& rURL ) 176 { 177 sal_Int64 nFileSize = 0; 178 osl::DirectoryItem aItem; 179 if ( osl::DirectoryItem::get( rURL, aItem ) == osl::FileBase::E_None ) 180 { 181 osl::FileStatus aStatus( osl_FileStatus_Mask_FileSize ); 182 if ( aItem.getFileStatus( aStatus ) == osl::FileBase::E_None ) 183 { 184 nFileSize = aStatus.getFileSize(); 185 } 186 } 187 return nFileSize; 188 } 189 190 // ----------------------------------------------------------------------------- 191 192 OUString PPPOptimizer_getImplementationName() 193 { 194 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.PPPOptimizerImp" ) ); 195 } 196 197 Sequence< OUString > PPPOptimizer_getSupportedServiceNames() 198 { 199 Sequence < OUString > aRet(1); 200 OUString* pArray = aRet.getArray(); 201 pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); 202 return aRet; 203 } 204 205 Reference< XInterface > PPPOptimizer_createInstance( const Reference< XComponentContext > & rSMgr ) 206 throw( Exception ) 207 { 208 return (cppu::OWeakObject*) new PPPOptimizer( rSMgr ); 209 } 210