Update ooo320-m1
[ooovba.git] / sdext / source / minimizer / pppoptimizer.cxx
bloba1782b61a485123de8d57a62ae0b63d5e87f7b4e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pppoptimizer.cxx,v $
11 * $Revision: 1.3 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "pppoptimizer.hxx"
36 #include "impoptimizer.hxx"
37 #include <osl/file.hxx>
39 using namespace ::rtl;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::util;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::frame;
44 using namespace ::com::sun::star::beans;
46 #define SERVICE_NAME "com.sun.star.comp.PPPOptimizer"
48 // ----------------
49 // - PPPOptimizer -
50 // ----------------
52 PPPOptimizer::PPPOptimizer( const Reference< XComponentContext > &rxMSF ) :
53 mxMSF( rxMSF )
57 // -----------------------------------------------------------------------------
59 PPPOptimizer::~PPPOptimizer()
63 // -----------------------------------------------------------------------------
64 // XInitialization
65 // -----------------------------------------------------------------------------
67 void SAL_CALL PPPOptimizer::initialize( const Sequence< Any >& aArguments )
68 throw ( Exception, RuntimeException )
70 if( aArguments.getLength() != 1 )
71 throw IllegalArgumentException();
73 Reference< XFrame > xFrame;
74 aArguments[ 0 ] >>= xFrame;
75 if ( xFrame.is() )
76 mxController = xFrame->getController();
79 // -----------------------------------------------------------------------------
80 // XServiceInfo
81 // -----------------------------------------------------------------------------
83 OUString SAL_CALL PPPOptimizer::getImplementationName()
84 throw ( RuntimeException )
86 return PPPOptimizer_getImplementationName();
89 sal_Bool SAL_CALL PPPOptimizer::supportsService( const OUString& rServiceName )
90 throw ( RuntimeException )
92 return rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
95 Sequence< OUString > SAL_CALL PPPOptimizer::getSupportedServiceNames()
96 throw ( RuntimeException )
98 return PPPOptimizer_getSupportedServiceNames();
101 // -----------------------------------------------------------------------------
102 // XDispatchProvider
103 // -----------------------------------------------------------------------------
105 Reference< com::sun::star::frame::XDispatch > SAL_CALL PPPOptimizer::queryDispatch(
106 const URL& aURL, const ::rtl::OUString& /* aTargetFrameName */, sal_Int32 /* nSearchFlags */ ) throw( RuntimeException )
108 Reference < XDispatch > xRet;
109 if ( aURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 )
111 // if ( aURL.Path.compareToAscii( "Function1" ) == 0 )
112 xRet = this;
114 return xRet;
117 //------------------------------------------------------------------------------
119 Sequence< Reference< com::sun::star::frame::XDispatch > > SAL_CALL PPPOptimizer::queryDispatches(
120 const Sequence< com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw( RuntimeException )
122 Sequence< Reference< com::sun::star::frame::XDispatch> > aReturn( aDescripts.getLength() );
123 Reference< com::sun::star::frame::XDispatch>* pReturn = aReturn.getArray();
124 const com::sun::star::frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
125 for (sal_Int16 i = 0; i < aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
127 *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
129 return aReturn;
132 // -----------------------------------------------------------------------------
133 // XDispatch
134 // -----------------------------------------------------------------------------
136 void SAL_CALL PPPOptimizer::dispatch( const URL& rURL, const Sequence< PropertyValue >& lArguments )
137 throw( RuntimeException )
139 if ( mxController.is() && ( rURL.Protocol.compareToAscii( "vnd.com.sun.star.comp.PPPOptimizer:" ) == 0 ) )
141 if ( rURL.Path.compareToAscii( "optimize" ) == 0 )
143 Reference< XModel > xModel( mxController->getModel() );
144 if ( xModel.is() )
148 ImpOptimizer aOptimizer( mxMSF, xModel );
149 aOptimizer.Optimize( lArguments );
151 catch( Exception& )
159 //===============================================
160 void SAL_CALL PPPOptimizer::addStatusListener( const Reference< XStatusListener >&, const URL& )
161 throw( RuntimeException )
163 // TODO
164 OSL_ENSURE( sal_False, "PPPOptimizer::addStatusListener()\nNot implemented yet!" );
167 //===============================================
168 void SAL_CALL PPPOptimizer::removeStatusListener( const Reference< XStatusListener >&, const URL& )
169 throw( RuntimeException )
171 // TODO
172 OSL_ENSURE( sal_False, "PPPOptimizer::removeStatusListener()\nNot implemented yet!" );
175 // -----------------------------------------------------------------------------
176 // returning filesize, on error zero is returned
177 sal_Int64 PPPOptimizer::GetFileSize( const rtl::OUString& rURL )
179 sal_Int64 nFileSize = 0;
180 osl::DirectoryItem aItem;
181 if ( osl::DirectoryItem::get( rURL, aItem ) == osl::FileBase::E_None )
183 osl::FileStatus aStatus( osl_FileStatus_Mask_FileSize );
184 if ( aItem.getFileStatus( aStatus ) == osl::FileBase::E_None )
186 nFileSize = aStatus.getFileSize();
189 return nFileSize;
192 // -----------------------------------------------------------------------------
194 OUString PPPOptimizer_getImplementationName()
196 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.PPPOptimizerImp" ) );
199 Sequence< OUString > PPPOptimizer_getSupportedServiceNames()
201 Sequence < OUString > aRet(1);
202 OUString* pArray = aRet.getArray();
203 pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
204 return aRet;
207 Reference< XInterface > PPPOptimizer_createInstance( const Reference< XComponentContext > & rSMgr )
208 throw( Exception )
210 return (cppu::OWeakObject*) new PPPOptimizer( rSMgr );