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>
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
;
59 template <class Type
> class safe_list
: public osl::Mutex
, public std::list
< Type
> {};
61 class OSimpleContentIdentifier
: public OWeakObject
,
62 public XContentIdentifier
66 OUString ProviderScheme
;
69 OSimpleContentIdentifier( const OUString
& rIdentifier
, const OUString
& rProviderScheme
);
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
);
77 virtual OUString SAL_CALL
getContentIdentifier() throw(RuntimeException
);
78 virtual OUString SAL_CALL
getContentProviderScheme() throw(RuntimeException
);
82 //---------------------------------------------------------------------------
86 //---------------------------------------------------------------------------
91 public XCommandTaskProcessor
,
92 public XPropertyTaskProcessor
,
94 public XPropertySetInfo
,
98 struct PropertyChangeEventInfo
103 PropertyChangeEventInfo() : Handle( -1 ) {}
105 inline int operator ==( const PropertyChangeEventInfo
& crInfo
) const
106 { return Handle
== crInfo
.Handle
&& Handle
> 0 || Name
== crInfo
.Name
; }
108 inline int operator <( const PropertyChangeEventInfo
& crInfo
) const
109 { return Handle
!= crInfo
.Handle
? Handle
< crInfo
.Handle
: Name
< crInfo
.Name
; }
113 struct PropertyChangeListenerInfo
115 Reference
< XPropertiesChangeListener
> xListener
;
116 list
< PropertyChangeEventInfo
> aEventInfos
;
118 inline int operator ==( const PropertyChangeListenerInfo
& crInfo
) const
119 { return xListener
== crInfo
.xListener
; }
121 inline int operator <( const PropertyChangeListenerInfo
& crInfo
) const
122 { return xListener
< crInfo
.xListener
; }
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
;
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;
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
);
148 virtual void SAL_CALL
addContentEventListener( const Reference
< XContentEventListener
>& rListener
) throw();
149 virtual void SAL_CALL
removeContentEventListener( const Reference
< XContentEventListener
>& rListener
) throw();
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();
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();
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 //---------------------------------------------------------------------------
179 //---------------------------------------------------------------------------
181 // supported Commands
182 static const sal_Int32 OPEN
= 0;
183 static const sal_Int32 CLOSE
= 1;
185 class OFolderContent
: public OContent
188 // Already provided children
189 safe_list
< XContent
> m_aChildList
;
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;
203 // XCommmandTaskProcessor
204 virtual Reference
< XCommandTask
> SAL_CALL
createCommandTask(const Command
& rCommand
, const Reference
< XContentTaskEnvironment
>& rEnvironment
) throw();
207 virtual Sequence
< CommandInfo
> SAL_CALL
getCommands() throw();
210 //---------------------------------------------------------------------------
214 //---------------------------------------------------------------------------
220 Guard
< OContent
> m_aContentGuard
;
222 OContent
*m_pContent
;
223 Reference
< XContentTaskEnvironment
> m_xEnvironment
;
224 ContentTaskStatus m_eStatus
;
227 static void executeWorker( void * );
228 virtual ContentTaskStatus
setStatus( ContentTaskStatus eStatus
);
230 // To be implemented by inheritants
231 virtual void doExecute() = 0;
233 OContentTask( const Reference
< XContentTaskEnvironment
>& xEnv
, OContent
*pContent
);
234 virtual ~OContentTask();
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
);
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 //---------------------------------------------------------------------------
254 //---------------------------------------------------------------------------
265 OCommandTask( const Reference
< XContentTaskEnvironment
>& xEnv
, OContent
*pContent
, const Command
& rCommand
);
266 virtual ~OCommandTask();
268 virtual void doExecute();
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
);
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();
283 virtual Command SAL_CALL
getCommand() throw();
284 virtual Any SAL_CALL
getResult() throw();
287 //---------------------------------------------------------------------------
291 //---------------------------------------------------------------------------
293 class OPropertyTask
:
298 Sequence
< PropertyValueInfo
> m_aProperties
;
299 PropertyTaskType m_eType
;
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;
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
);
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();
323 PropertyTaskType SAL_CALL
getType() throw();
324 Sequence
< PropertyValueInfo
> SAL_CALL
getProperties() throw();
327 #endif // _UCBHELPER_CONTENT_HXX_