merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / inc / ucbhelper / ext_content.hxx
blob06075ea4598f67948c778a34b362a127078a656b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
29 #ifndef _UCBHELPER_CONTENT_HXX_
30 #define _UCBHELPER_CONTENT_HXX_
32 #include <rtl/string.hxx>
33 #include <rtl/ustring>
34 #include <osl/mutex.hxx>
35 #include <osl/thread.h>
37 #include <cppuhelper/weak.hxx>
38 #include <com/sun/star/ucb/XCommandTaskProcessor.hpp>
39 #include <com/sun/star/ucb/XCommandInfo.hpp>
40 #include <com/sun/star/ucb/XContent.hpp>
41 #include <com/sun/star/ucb/XPropertyTaskProcessor.hpp>
42 #include <com/sun/star/ucb/XContentIdentifier.hpp>
43 #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
44 #include <com/sun/star/lang/XComponent.hpp>
46 #include <list>
48 using namespace cppu;
49 using namespace com::sun::star::ucb;
50 using namespace com::sun::star::uno;
51 using namespace com::sun::star::beans;
52 using namespace com::sun::star::lang;
53 using namespace std;
54 using namespace rtl;
55 using namespace osl;
59 template <class Type> class safe_list : public osl::Mutex, public std::list< Type > {};
61 class OSimpleContentIdentifier : public OWeakObject,
62 public XContentIdentifier
64 private:
65 OUString Identifier;
66 OUString ProviderScheme;
68 public:
69 OSimpleContentIdentifier( const OUString& rIdentifier, const OUString& rProviderScheme );
71 // XInterface
72 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
73 virtual void SAL_CALL acquire() throw(RuntimeException);
74 virtual void SAL_CALL release() throw(RuntimeException);
76 // XContentIdentifier
77 virtual OUString SAL_CALL getContentIdentifier() throw(RuntimeException);
78 virtual OUString SAL_CALL getContentProviderScheme() throw(RuntimeException);
82 //---------------------------------------------------------------------------
84 // FileSystemContent
86 //---------------------------------------------------------------------------
88 class OContent :
89 public OWeakObject,
90 public XContent,
91 public XCommandTaskProcessor,
92 public XPropertyTaskProcessor,
93 public XCommandInfo,
94 public XPropertySetInfo,
95 public XComponent
97 public:
98 struct PropertyChangeEventInfo
100 OUString Name;
101 long Handle;
103 PropertyChangeEventInfo() : Handle( -1 ) {}
105 inline int operator ==( const PropertyChangeEventInfo& crInfo ) const
106 { return Handle == crInfo.Handle && Handle > 0 || Name == crInfo.Name; }
107 #ifdef __SUNPRO_CC
108 inline int operator <( const PropertyChangeEventInfo& crInfo ) const
109 { return Handle != crInfo.Handle ? Handle < crInfo.Handle : Name < crInfo.Name; }
110 #endif
113 struct PropertyChangeListenerInfo
115 Reference< XPropertiesChangeListener > xListener;
116 list< PropertyChangeEventInfo > aEventInfos;
118 inline int operator ==( const PropertyChangeListenerInfo& crInfo ) const
119 { return xListener == crInfo.xListener; }
120 #ifdef __SUNPRO_CC
121 inline int operator <( const PropertyChangeListenerInfo& crInfo ) const
122 { return xListener < crInfo.xListener; }
123 #endif
126 protected:
127 Sequence< PropertyChangeEvent > matchListenerEvents( const Sequence< PropertyChangeEvent >& crEvents, const PropertyChangeListenerInfo & crInfo );
129 safe_list< Reference< XContentEventListener > > m_aContentListeners;
130 safe_list< Reference< XEventListener > > m_aComponentListeners;
131 safe_list< PropertyChangeListenerInfo > m_aPropertyChangeListeners;
132 public:
133 virtual ~OContent() {}
135 virtual void broadcastContentEvent( const ContentEvent & crEvent );
136 virtual void broadcastPropertiesChangeEvents( const Sequence< PropertyChangeEvent >& crEvents );
138 // To be implemented by inheritents
139 virtual Any doCommand( const Command & crCommand ) = 0;
141 // XInterface
142 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
144 virtual void SAL_CALL acquire() throw(RuntimeException);
145 virtual void SAL_CALL release() throw(RuntimeException);
147 // XContent
148 virtual void SAL_CALL addContentEventListener( const Reference< XContentEventListener >& rListener ) throw();
149 virtual void SAL_CALL removeContentEventListener( const Reference< XContentEventListener >& rListener ) throw();
151 // XComponent
152 virtual void SAL_CALL dispose() throw();
153 virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw();
154 virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& xListener ) throw();
156 // XCommmandTaskProcessor
157 virtual Reference< XCommandInfo > SAL_CALL getCommandsInfo() throw();
159 // XCommandInfo
160 virtual CommandInfo SAL_CALL getCommandInfoByName( const OUString& rName ) throw( UnsupportedCommandException );
161 virtual CommandInfo SAL_CALL getCommandInfoByHandle( long nHandle ) throw( UnsupportedCommandException );
162 virtual sal_Bool SAL_CALL hasCommandByName( const OUString& rName ) throw();
163 virtual sal_Bool SAL_CALL hasCommandByHandle( long nHandle ) throw();
165 // XPropertyTaskProcessor
166 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw();
168 // XPropertySetInfo
169 virtual Property SAL_CALL getPropertyByName( const OUString& Name ) throw( UnknownPropertyException );
170 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw();
171 virtual void SAL_CALL addPropertiesChangeListener( const Sequence< OUString >& Names, const Reference< XPropertiesChangeListener >& xListener ) throw();
172 virtual void SAL_CALL removePropertiesChangeListener( const Sequence< OUString >& Names, const Reference< XPropertiesChangeListener >& xListener ) throw();
175 //---------------------------------------------------------------------------
177 // FolderContent
179 //---------------------------------------------------------------------------
181 // supported Commands
182 static const sal_Int32 OPEN = 0;
183 static const sal_Int32 CLOSE = 1;
185 class OFolderContent : public OContent
187 protected:
188 // Already provided children
189 safe_list< XContent > m_aChildList;
191 // OContent
192 virtual Any doCommand( const Command & crCommand );
194 // new methods, can be overloaded
195 virtual Any doOpenCommand();
196 virtual Any doCloseCommand();
198 // To be implemented by inheritants
199 virtual Sequence< XContent > getAllChildren() = 0;
201 public:
203 // XCommmandTaskProcessor
204 virtual Reference< XCommandTask > SAL_CALL createCommandTask(const Command& rCommand, const Reference< XContentTaskEnvironment >& rEnvironment ) throw();
206 // XCommandInfo
207 virtual Sequence< CommandInfo > SAL_CALL getCommands() throw();
210 //---------------------------------------------------------------------------
212 // OContentTask
214 //---------------------------------------------------------------------------
216 class OContentTask :
217 public OWeakObject,
218 public XContentTask
220 Guard< OContent > m_aContentGuard;
221 protected:
222 OContent *m_pContent;
223 Reference< XContentTaskEnvironment > m_xEnvironment;
224 ContentTaskStatus m_eStatus;
225 oslThread m_aThread;
227 static void executeWorker( void * );
228 virtual ContentTaskStatus setStatus( ContentTaskStatus eStatus );
230 // To be implemented by inheritants
231 virtual void doExecute() = 0;
232 public:
233 OContentTask( const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent );
234 virtual ~OContentTask();
236 // XInterface
237 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
239 virtual void SAL_CALL acquire() throw(RuntimeException);
240 virtual void SAL_CALL release() throw(RuntimeException);
242 // XContentTask
243 virtual void SAL_CALL start() throw();
244 virtual void SAL_CALL execute() throw( Exception );
245 virtual void SAL_CALL abort() throw();
246 virtual ContentTaskStatus SAL_CALL getStatus() throw();
247 virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw();
250 //---------------------------------------------------------------------------
252 // OCommandTask
254 //---------------------------------------------------------------------------
256 class OCommandTask :
257 public OContentTask,
258 public XCommandTask
260 protected:
261 Command m_aCommand;
262 Any m_aResult;
264 public:
265 OCommandTask( const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent, const Command& rCommand );
266 virtual ~OCommandTask();
268 virtual void doExecute();
270 // XInterface
271 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
272 virtual void SAL_CALL acquire() throw(RuntimeException);
273 virtual void SAL_CALL release() throw(RuntimeException);
275 // XContentTask
276 virtual void SAL_CALL start() throw();
277 virtual void SAL_CALL execute() throw( Exception );
278 virtual void SAL_CALL abort() throw();
279 virtual ContentTaskStatus SAL_CALL getStatus() throw();
280 virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw();
282 // XCommandTask
283 virtual Command SAL_CALL getCommand() throw();
284 virtual Any SAL_CALL getResult() throw();
287 //---------------------------------------------------------------------------
289 // OPropertyTask
291 //---------------------------------------------------------------------------
293 class OPropertyTask :
294 public OContentTask,
295 public XPropertyTask
297 protected:
298 Sequence< PropertyValueInfo > m_aProperties;
299 PropertyTaskType m_eType;
300 public:
301 OPropertyTask(const Reference< XContentTaskEnvironment >& Environment, OContent *pContent, const Sequence< PropertyValue >& Properties, PropertyTaskType Type );
302 virtual ~OPropertyTask();
304 virtual void doExecute();
306 // To be implemented by inheritants
307 virtual Any setPropertyValue( PropertyValueInfo & rProperty ) = 0;
308 virtual void getPropertyValue( PropertyValueInfo & rProperty ) = 0;
310 // XInterface
311 virtual Any SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
312 virtual void SAL_CALL acquire() throw(RuntimeException);
313 virtual void SAL_CALL release() throw(RuntimeException);
315 // XContentTask
316 virtual void SAL_CALL start() throw();
317 virtual void SAL_CALL execute() throw( Exception );
318 virtual void SAL_CALL abort() throw();
319 virtual ContentTaskStatus SAL_CALL getStatus() throw();
320 virtual Reference< XContentTaskEnvironment > SAL_CALL getEnvironment() throw();
322 // XPropertyTask
323 PropertyTaskType SAL_CALL getType() throw();
324 Sequence< PropertyValueInfo > SAL_CALL getProperties() throw();
327 #endif // _UCBHELPER_CONTENT_HXX_