xref: /AOO41X/main/extensions/inc/ucbhelper/ext_content.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 
29 #ifndef _UCBHELPER_CONTENT_HXX_
30 #define _UCBHELPER_CONTENT_HXX_
31 
32 #include <rtl/string.hxx>
33 #include <rtl/ustring>
34 #include <osl/mutex.hxx>
35 #include <osl/thread.h>
36 
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>
45 
46 #include <list>
47 
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;
56 
57 
58 
59 template <class Type> class safe_list : public osl::Mutex, public std::list< Type > {};
60 
61 class OSimpleContentIdentifier :	public OWeakObject,
62 									public XContentIdentifier
63 {
64 private:
65 	OUString	Identifier;
66 	OUString	ProviderScheme;
67 
68 public:
69 	OSimpleContentIdentifier( const OUString& rIdentifier, const OUString& rProviderScheme );
70 
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);
75 
76 	// XContentIdentifier
77     virtual OUString 	SAL_CALL getContentIdentifier() throw(RuntimeException);
78     virtual OUString 	SAL_CALL getContentProviderScheme() throw(RuntimeException);
79 };
80 
81 
82 //---------------------------------------------------------------------------
83 //
84 //	FileSystemContent
85 //
86 //---------------------------------------------------------------------------
87 
88 class OContent :
89 public OWeakObject,
90 public XContent,
91 public XCommandTaskProcessor,
92 public XPropertyTaskProcessor,
93 public XCommandInfo,
94 public XPropertySetInfo,
95 public XComponent
96 {
97 public:
98 	struct PropertyChangeEventInfo
99 	{
100 		OUString	Name;
101 		long		Handle;
102 
103 		PropertyChangeEventInfo() : Handle( -1 ) {}
104 
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
111 	};
112 
113 	struct PropertyChangeListenerInfo
114 	{
115 		Reference< XPropertiesChangeListener >	xListener;
116 		list< PropertyChangeEventInfo >			aEventInfos;
117 
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
124 	};
125 
126 protected:
127 	Sequence< PropertyChangeEvent > matchListenerEvents( const Sequence< PropertyChangeEvent >& crEvents, const PropertyChangeListenerInfo & crInfo );
128 
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() {}
134 
135 	virtual void broadcastContentEvent( const ContentEvent & crEvent );
136 	virtual void broadcastPropertiesChangeEvents( const Sequence< PropertyChangeEvent >& crEvents );
137 
138 	// To be implemented by inheritents
139 	virtual Any doCommand( const Command & crCommand ) = 0;
140 
141 	// XInterface
142 	virtual Any			SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
143 
144 	virtual void SAL_CALL acquire() throw(RuntimeException);
145 	virtual void SAL_CALL release() throw(RuntimeException);
146 
147 	// XContent
148 	virtual void SAL_CALL addContentEventListener( const Reference< XContentEventListener >& rListener ) throw();
149 	virtual void SAL_CALL removeContentEventListener( const Reference< XContentEventListener >& rListener ) throw();
150 
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();
155 
156 	// XCommmandTaskProcessor
157 	virtual Reference< XCommandInfo > SAL_CALL getCommandsInfo() throw();
158 
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();
164 
165 	// XPropertyTaskProcessor
166 	virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw();
167 
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();
173 };
174 
175 //---------------------------------------------------------------------------
176 //
177 //	FolderContent
178 //
179 //---------------------------------------------------------------------------
180 
181 // supported Commands
182 static const sal_Int32 OPEN		= 0;
183 static const sal_Int32 CLOSE	= 1;
184 
185 class OFolderContent : public OContent
186 {
187 protected:
188 	// Already provided children
189 	safe_list< XContent >	m_aChildList;
190 
191 	// OContent
192 	virtual Any doCommand( const Command & crCommand );
193 
194 	// new methods, can be overloaded
195 	virtual Any doOpenCommand();
196 	virtual Any doCloseCommand();
197 
198 	// To be implemented by inheritants
199 	virtual Sequence< XContent > getAllChildren() = 0;
200 
201 public:
202 
203 	// XCommmandTaskProcessor
204 	virtual Reference< XCommandTask > SAL_CALL createCommandTask(const Command& rCommand, const Reference< XContentTaskEnvironment >& rEnvironment ) throw();
205 
206 	// XCommandInfo
207 	virtual Sequence< CommandInfo > SAL_CALL getCommands() throw();
208 };
209 
210 //---------------------------------------------------------------------------
211 //
212 //	OContentTask
213 //
214 //---------------------------------------------------------------------------
215 
216 class OContentTask :
217 public OWeakObject,
218 public XContentTask
219 {
220 	Guard< OContent >						m_aContentGuard;
221 protected:
222 	OContent								*m_pContent;
223 	Reference< XContentTaskEnvironment >	m_xEnvironment;
224 	ContentTaskStatus						m_eStatus;
225 	oslThread								m_aThread;
226 
227 	static void executeWorker( void * );
228 	virtual ContentTaskStatus setStatus( ContentTaskStatus eStatus );
229 
230 	// To be implemented by inheritants
231 	virtual void doExecute() = 0;
232 public:
233 	OContentTask(  const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent );
234 	virtual ~OContentTask();
235 
236 	// XInterface
237 	virtual Any			SAL_CALL queryInterface( const Type &type ) throw( RuntimeException );
238 
239 	virtual void SAL_CALL acquire() throw(RuntimeException);
240 	virtual void SAL_CALL release() throw(RuntimeException);
241 
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();
248 };
249 
250 //---------------------------------------------------------------------------
251 //
252 //	OCommandTask
253 //
254 //---------------------------------------------------------------------------
255 
256 class OCommandTask :
257 public OContentTask,
258 public XCommandTask
259 {
260 protected:
261 	Command				m_aCommand;
262 	Any					m_aResult;
263 
264 public:
265 	OCommandTask( const Reference< XContentTaskEnvironment >& xEnv, OContent *pContent, const Command& rCommand );
266 	virtual ~OCommandTask();
267 
268 	virtual void doExecute();
269 
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);
274 
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();
281 
282 	// XCommandTask
283 	virtual Command SAL_CALL getCommand() throw();
284 	virtual Any SAL_CALL getResult() throw();
285 };
286 
287 //---------------------------------------------------------------------------
288 //
289 //	OPropertyTask
290 //
291 //---------------------------------------------------------------------------
292 
293 class OPropertyTask :
294 public OContentTask,
295 public XPropertyTask
296 {
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();
303 
304 	virtual void doExecute();
305 
306 	// To be implemented by inheritants
307 	virtual Any setPropertyValue( PropertyValueInfo & rProperty ) = 0;
308 	virtual void getPropertyValue( PropertyValueInfo & rProperty ) = 0;
309 
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);
314 
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();
321 
322 	// XPropertyTask
323 	PropertyTaskType SAL_CALL getType() throw();
324 	Sequence< PropertyValueInfo > SAL_CALL getProperties() throw();
325 };
326 
327 #endif // _UCBHELPER_CONTENT_HXX_
328 
329 
330