1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir #ifndef _UCBHELPER_CONTENT_HXX_ 30*cdf0e10cSrcweir #define _UCBHELPER_CONTENT_HXX_ 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <rtl/string.hxx> 33*cdf0e10cSrcweir #include <rtl/ustring> 34*cdf0e10cSrcweir #include <osl/mutex.hxx> 35*cdf0e10cSrcweir #include <osl/thread.h> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 38*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandTaskProcessor.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/ucb/XPropertyTaskProcessor.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifier.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertiesChangeListener.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <list> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir using namespace cppu; 49*cdf0e10cSrcweir using namespace com::sun::star::ucb; 50*cdf0e10cSrcweir using namespace com::sun::star::uno; 51*cdf0e10cSrcweir using namespace com::sun::star::beans; 52*cdf0e10cSrcweir using namespace com::sun::star::lang; 53*cdf0e10cSrcweir using namespace std; 54*cdf0e10cSrcweir using namespace rtl; 55*cdf0e10cSrcweir using namespace osl; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir template <class Type> class safe_list : public osl::Mutex, public std::list< Type > {}; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir class OSimpleContentIdentifier : public OWeakObject, 62*cdf0e10cSrcweir public XContentIdentifier 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir private: 65*cdf0e10cSrcweir OUString Identifier; 66*cdf0e10cSrcweir OUString ProviderScheme; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir public: 69*cdf0e10cSrcweir OSimpleContentIdentifier( const OUString& rIdentifier, const OUString& rProviderScheme ); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // XInterface 72*cdf0e10cSrcweir virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException ); 73*cdf0e10cSrcweir virtual void SAL_CALL acquire() throw(RuntimeException); 74*cdf0e10cSrcweir virtual void SAL_CALL release() throw(RuntimeException); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // XContentIdentifier 77*cdf0e10cSrcweir virtual OUString SAL_CALL getContentIdentifier() throw(RuntimeException); 78*cdf0e10cSrcweir virtual OUString SAL_CALL getContentProviderScheme() throw(RuntimeException); 79*cdf0e10cSrcweir }; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir //--------------------------------------------------------------------------- 83*cdf0e10cSrcweir // 84*cdf0e10cSrcweir // FileSystemContent 85*cdf0e10cSrcweir // 86*cdf0e10cSrcweir //--------------------------------------------------------------------------- 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir class OContent : 89*cdf0e10cSrcweir public OWeakObject, 90*cdf0e10cSrcweir public XContent, 91*cdf0e10cSrcweir public XCommandTaskProcessor, 92*cdf0e10cSrcweir public XPropertyTaskProcessor, 93*cdf0e10cSrcweir public XCommandInfo, 94*cdf0e10cSrcweir public XPropertySetInfo, 95*cdf0e10cSrcweir public XComponent 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir public: 98*cdf0e10cSrcweir struct PropertyChangeEventInfo 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir OUString Name; 101*cdf0e10cSrcweir long Handle; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir PropertyChangeEventInfo() : Handle( -1 ) {} 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir inline int operator ==( const PropertyChangeEventInfo& crInfo ) const 106*cdf0e10cSrcweir { return Handle == crInfo.Handle && Handle > 0 || Name == crInfo.Name; } 107*cdf0e10cSrcweir #ifdef __SUNPRO_CC 108*cdf0e10cSrcweir inline int operator <( const PropertyChangeEventInfo& crInfo ) const 109*cdf0e10cSrcweir { return Handle != crInfo.Handle ? Handle < crInfo.Handle : Name < crInfo.Name; } 110*cdf0e10cSrcweir #endif 111*cdf0e10cSrcweir }; 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir struct PropertyChangeListenerInfo 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir Reference< XPropertiesChangeListener > xListener; 116*cdf0e10cSrcweir list< PropertyChangeEventInfo > aEventInfos; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir inline int operator ==( const PropertyChangeListenerInfo& crInfo ) const 119*cdf0e10cSrcweir { return xListener == crInfo.xListener; } 120*cdf0e10cSrcweir #ifdef __SUNPRO_CC 121*cdf0e10cSrcweir inline int operator <( const PropertyChangeListenerInfo& crInfo ) const 122*cdf0e10cSrcweir { return xListener < crInfo.xListener; } 123*cdf0e10cSrcweir #endif 124*cdf0e10cSrcweir }; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir protected: 127*cdf0e10cSrcweir Sequence< PropertyChangeEvent > matchListenerEvents( const Sequence< PropertyChangeEvent >& crEvents, const PropertyChangeListenerInfo & crInfo ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir safe_list< Reference< XContentEventListener > > m_aContentListeners; 130*cdf0e10cSrcweir safe_list< Reference< XEventListener > > m_aComponentListeners; 131*cdf0e10cSrcweir safe_list< PropertyChangeListenerInfo > m_aPropertyChangeListeners; 132*cdf0e10cSrcweir public: 133*cdf0e10cSrcweir virtual ~OContent() {} 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir virtual void broadcastContentEvent( const ContentEvent & crEvent ); 136*cdf0e10cSrcweir virtual void broadcastPropertiesChangeEvents( const Sequence< PropertyChangeEvent >& crEvents ); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // To be implemented by inheritents 139*cdf0e10cSrcweir virtual Any doCommand( const Command & crCommand ) = 0; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // XInterface 142*cdf0e10cSrcweir virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException ); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir virtual void SAL_CALL acquire() throw(RuntimeException); 145*cdf0e10cSrcweir virtual void SAL_CALL release() throw(RuntimeException); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // XContent 148*cdf0e10cSrcweir virtual void SAL_CALL addContentEventListener( const Reference< XContentEventListener >& rListener ) throw(); 149*cdf0e10cSrcweir virtual void SAL_CALL removeContentEventListener( const Reference< XContentEventListener >& rListener ) throw(); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir // XComponent 152*cdf0e10cSrcweir virtual void SAL_CALL dispose() throw(); 153*cdf0e10cSrcweir virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw(); 154*cdf0e10cSrcweir virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& xListener ) throw(); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // XCommmandTaskProcessor 157*cdf0e10cSrcweir virtual Reference< XCommandInfo > SAL_CALL getCommandsInfo() throw(); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir // XCommandInfo 160*cdf0e10cSrcweir virtual CommandInfo SAL_CALL getCommandInfoByName( const OUString& rName ) throw( UnsupportedCommandException ); 161*cdf0e10cSrcweir virtual CommandInfo SAL_CALL getCommandInfoByHandle( long nHandle ) throw( UnsupportedCommandException ); 162*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasCommandByName( const OUString& rName ) throw(); 163*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasCommandByHandle( long nHandle ) throw(); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // XPropertyTaskProcessor 166*cdf0e10cSrcweir virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw(); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // XPropertySetInfo 169*cdf0e10cSrcweir virtual Property SAL_CALL getPropertyByName( const OUString& Name ) throw( UnknownPropertyException ); 170*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw(); 171*cdf0e10cSrcweir virtual void SAL_CALL addPropertiesChangeListener( const Sequence< OUString >& Names, const Reference< XPropertiesChangeListener >& xListener ) throw(); 172*cdf0e10cSrcweir virtual void SAL_CALL removePropertiesChangeListener( const Sequence< OUString >& Names, const Reference< XPropertiesChangeListener >& xListener ) throw(); 173*cdf0e10cSrcweir }; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir //--------------------------------------------------------------------------- 176*cdf0e10cSrcweir // 177*cdf0e10cSrcweir // FolderContent 178*cdf0e10cSrcweir // 179*cdf0e10cSrcweir //--------------------------------------------------------------------------- 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // supported Commands 182*cdf0e10cSrcweir static const sal_Int32 OPEN = 0; 183*cdf0e10cSrcweir static const sal_Int32 CLOSE = 1; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir class OFolderContent : public OContent 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir protected: 188*cdf0e10cSrcweir // Already provided children 189*cdf0e10cSrcweir safe_list< XContent > m_aChildList; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // OContent 192*cdf0e10cSrcweir virtual Any doCommand( const Command & crCommand ); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir // new methods, can be overloaded 195*cdf0e10cSrcweir virtual Any doOpenCommand(); 196*cdf0e10cSrcweir virtual Any doCloseCommand(); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir // To be implemented by inheritants 199*cdf0e10cSrcweir virtual Sequence< XContent > getAllChildren() = 0; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir public: 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir // XCommmandTaskProcessor 204*cdf0e10cSrcweir virtual Reference< XCommandTask > SAL_CALL createCommandTask(const Command& rCommand, const Reference< XContentTaskEnvironment >& rEnvironment ) throw(); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // XCommandInfo 207*cdf0e10cSrcweir virtual Sequence< CommandInfo > SAL_CALL getCommands() throw(); 208*cdf0e10cSrcweir }; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir //--------------------------------------------------------------------------- 211*cdf0e10cSrcweir // 212*cdf0e10cSrcweir // OContentTask 213*cdf0e10cSrcweir // 214*cdf0e10cSrcweir //--------------------------------------------------------------------------- 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir class OContentTask : 217*cdf0e10cSrcweir public OWeakObject, 218*cdf0e10cSrcweir public XContentTask 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir Guard< OContent > m_aContentGuard; 221*cdf0e10cSrcweir protected: 222*cdf0e10cSrcweir OContent *m_pContent; 223*cdf0e10cSrcweir Reference< XContentTaskEnvironment > m_xEnvironment; 224*cdf0e10cSrcweir ContentTaskStatus m_eStatus; 225*cdf0e10cSrcweir oslThread m_aThread; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir static void executeWorker( void * ); 228*cdf0e10cSrcweir virtual ContentTaskStatus setStatus( ContentTaskStatus eStatus ); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir // To be implemented by inheritants 231*cdf0e10cSrcweir virtual void doExecute() = 0; 232*cdf0e10cSrcweir public: 233*cdf0e10cSrcweir OContentTask( const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent ); 234*cdf0e10cSrcweir virtual ~OContentTask(); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir // XInterface 237*cdf0e10cSrcweir virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir virtual void SAL_CALL acquire() throw(RuntimeException); 240*cdf0e10cSrcweir virtual void SAL_CALL release() throw(RuntimeException); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir // XContentTask 243*cdf0e10cSrcweir virtual void SAL_CALL start() throw(); 244*cdf0e10cSrcweir virtual void SAL_CALL execute() throw( Exception ); 245*cdf0e10cSrcweir virtual void SAL_CALL abort() throw(); 246*cdf0e10cSrcweir virtual ContentTaskStatus SAL_CALL getStatus() throw(); 247*cdf0e10cSrcweir virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw(); 248*cdf0e10cSrcweir }; 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir //--------------------------------------------------------------------------- 251*cdf0e10cSrcweir // 252*cdf0e10cSrcweir // OCommandTask 253*cdf0e10cSrcweir // 254*cdf0e10cSrcweir //--------------------------------------------------------------------------- 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir class OCommandTask : 257*cdf0e10cSrcweir public OContentTask, 258*cdf0e10cSrcweir public XCommandTask 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir protected: 261*cdf0e10cSrcweir Command m_aCommand; 262*cdf0e10cSrcweir Any m_aResult; 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir public: 265*cdf0e10cSrcweir OCommandTask( const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent, const Command& rCommand ); 266*cdf0e10cSrcweir virtual ~OCommandTask(); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir virtual void doExecute(); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir // XInterface 271*cdf0e10cSrcweir virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException ); 272*cdf0e10cSrcweir virtual void SAL_CALL acquire() throw(RuntimeException); 273*cdf0e10cSrcweir virtual void SAL_CALL release() throw(RuntimeException); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // XContentTask 276*cdf0e10cSrcweir virtual void SAL_CALL start() throw(); 277*cdf0e10cSrcweir virtual void SAL_CALL execute() throw( Exception ); 278*cdf0e10cSrcweir virtual void SAL_CALL abort() throw(); 279*cdf0e10cSrcweir virtual ContentTaskStatus SAL_CALL getStatus() throw(); 280*cdf0e10cSrcweir virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw(); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // XCommandTask 283*cdf0e10cSrcweir virtual Command SAL_CALL getCommand() throw(); 284*cdf0e10cSrcweir virtual Any SAL_CALL getResult() throw(); 285*cdf0e10cSrcweir }; 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir //--------------------------------------------------------------------------- 288*cdf0e10cSrcweir // 289*cdf0e10cSrcweir // OPropertyTask 290*cdf0e10cSrcweir // 291*cdf0e10cSrcweir //--------------------------------------------------------------------------- 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir class OPropertyTask : 294*cdf0e10cSrcweir public OContentTask, 295*cdf0e10cSrcweir public XPropertyTask 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir protected: 298*cdf0e10cSrcweir Sequence< PropertyValueInfo > m_aProperties; 299*cdf0e10cSrcweir PropertyTaskType m_eType; 300*cdf0e10cSrcweir public: 301*cdf0e10cSrcweir OPropertyTask(const Reference< XContentTaskEnvironment >& Environment, OContent *pContent, const Sequence< PropertyValue >& Properties, PropertyTaskType Type ); 302*cdf0e10cSrcweir virtual ~OPropertyTask(); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir virtual void doExecute(); 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir // To be implemented by inheritants 307*cdf0e10cSrcweir virtual Any setPropertyValue( PropertyValueInfo & rProperty ) = 0; 308*cdf0e10cSrcweir virtual void getPropertyValue( PropertyValueInfo & rProperty ) = 0; 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir // XInterface 311*cdf0e10cSrcweir virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException ); 312*cdf0e10cSrcweir virtual void SAL_CALL acquire() throw(RuntimeException); 313*cdf0e10cSrcweir virtual void SAL_CALL release() throw(RuntimeException); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir // XContentTask 316*cdf0e10cSrcweir virtual void SAL_CALL start() throw(); 317*cdf0e10cSrcweir virtual void SAL_CALL execute() throw( Exception ); 318*cdf0e10cSrcweir virtual void SAL_CALL abort() throw(); 319*cdf0e10cSrcweir virtual ContentTaskStatus SAL_CALL getStatus() throw(); 320*cdf0e10cSrcweir virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw(); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir // XPropertyTask 323*cdf0e10cSrcweir PropertyTaskType SAL_CALL getType() throw(); 324*cdf0e10cSrcweir Sequence< PropertyValueInfo > SAL_CALL getProperties() throw(); 325*cdf0e10cSrcweir }; 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir #endif // _UCBHELPER_CONTENT_HXX_ 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir 330