1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ext_content.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #ifndef _UCBHELPER_CONTENT_HXX_
33 #define _UCBHELPER_CONTENT_HXX_
35 #include <rtl/string.hxx>
36 #include <rtl/ustring>
37 #include <osl/mutex.hxx>
38 #include <osl/thread.h>
40 #include <cppuhelper/weak.hxx>
41 #include <com/sun/star/ucb/XCommandTaskProcessor.hpp>
42 #include <com/sun/star/ucb/XCommandInfo.hpp>
43 #include <com/sun/star/ucb/XContent.hpp>
44 #include <com/sun/star/ucb/XPropertyTaskProcessor.hpp>
45 #include <com/sun/star/ucb/XContentIdentifier.hpp>
46 #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
47 #include <com/sun/star/lang/XComponent.hpp>
52 using namespace com::sun::star::ucb
;
53 using namespace com::sun::star::uno
;
54 using namespace com::sun::star::beans
;
55 using namespace com::sun::star::lang
;
62 template <class Type
> class safe_list
: public osl::Mutex
, public std::list
< Type
> {};
64 class OSimpleContentIdentifier
: public OWeakObject
,
65 public XContentIdentifier
69 OUString ProviderScheme
;
72 OSimpleContentIdentifier( const OUString
& rIdentifier
, const OUString
& rProviderScheme
);
75 virtual Any SAL_CALL
queryInterface( const Type
&type
) throw( RuntimeException
);
76 virtual void SAL_CALL
acquire() throw(RuntimeException
);
77 virtual void SAL_CALL
release() throw(RuntimeException
);
80 virtual OUString SAL_CALL
getContentIdentifier() throw(RuntimeException
);
81 virtual OUString SAL_CALL
getContentProviderScheme() throw(RuntimeException
);
85 //---------------------------------------------------------------------------
89 //---------------------------------------------------------------------------
94 public XCommandTaskProcessor
,
95 public XPropertyTaskProcessor
,
97 public XPropertySetInfo
,
101 struct PropertyChangeEventInfo
106 PropertyChangeEventInfo() : Handle( -1 ) {}
108 inline int operator ==( const PropertyChangeEventInfo
& crInfo
) const
109 { return Handle
== crInfo
.Handle
&& Handle
> 0 || Name
== crInfo
.Name
; }
111 inline int operator <( const PropertyChangeEventInfo
& crInfo
) const
112 { return Handle
!= crInfo
.Handle
? Handle
< crInfo
.Handle
: Name
< crInfo
.Name
; }
116 struct PropertyChangeListenerInfo
118 Reference
< XPropertiesChangeListener
> xListener
;
119 list
< PropertyChangeEventInfo
> aEventInfos
;
121 inline int operator ==( const PropertyChangeListenerInfo
& crInfo
) const
122 { return xListener
== crInfo
.xListener
; }
124 inline int operator <( const PropertyChangeListenerInfo
& crInfo
) const
125 { return xListener
< crInfo
.xListener
; }
130 Sequence
< PropertyChangeEvent
> matchListenerEvents( const Sequence
< PropertyChangeEvent
>& crEvents
, const PropertyChangeListenerInfo
& crInfo
);
132 safe_list
< Reference
< XContentEventListener
> > m_aContentListeners
;
133 safe_list
< Reference
< XEventListener
> > m_aComponentListeners
;
134 safe_list
< PropertyChangeListenerInfo
> m_aPropertyChangeListeners
;
136 virtual ~OContent() {}
138 virtual void broadcastContentEvent( const ContentEvent
& crEvent
);
139 virtual void broadcastPropertiesChangeEvents( const Sequence
< PropertyChangeEvent
>& crEvents
);
141 // To be implemented by inheritents
142 virtual Any
doCommand( const Command
& crCommand
) = 0;
145 virtual Any SAL_CALL
queryInterface( const Type
&type
) throw( RuntimeException
);
147 virtual void SAL_CALL
acquire() throw(RuntimeException
);
148 virtual void SAL_CALL
release() throw(RuntimeException
);
151 virtual void SAL_CALL
addContentEventListener( const Reference
< XContentEventListener
>& rListener
) throw();
152 virtual void SAL_CALL
removeContentEventListener( const Reference
< XContentEventListener
>& rListener
) throw();
155 virtual void SAL_CALL
dispose() throw();
156 virtual void SAL_CALL
addEventListener( const Reference
< XEventListener
>& xListener
) throw();
157 virtual void SAL_CALL
removeEventListener( const Reference
< XEventListener
>& xListener
) throw();
159 // XCommmandTaskProcessor
160 virtual Reference
< XCommandInfo
> SAL_CALL
getCommandsInfo() throw();
163 virtual CommandInfo SAL_CALL
getCommandInfoByName( const OUString
& rName
) throw( UnsupportedCommandException
);
164 virtual CommandInfo SAL_CALL
getCommandInfoByHandle( long nHandle
) throw( UnsupportedCommandException
);
165 virtual sal_Bool SAL_CALL
hasCommandByName( const OUString
& rName
) throw();
166 virtual sal_Bool SAL_CALL
hasCommandByHandle( long nHandle
) throw();
168 // XPropertyTaskProcessor
169 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw();
172 virtual Property SAL_CALL
getPropertyByName( const OUString
& Name
) throw( UnknownPropertyException
);
173 virtual sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
) throw();
174 virtual void SAL_CALL
addPropertiesChangeListener( const Sequence
< OUString
>& Names
, const Reference
< XPropertiesChangeListener
>& xListener
) throw();
175 virtual void SAL_CALL
removePropertiesChangeListener( const Sequence
< OUString
>& Names
, const Reference
< XPropertiesChangeListener
>& xListener
) throw();
178 //---------------------------------------------------------------------------
182 //---------------------------------------------------------------------------
184 // supported Commands
185 static const sal_Int32 OPEN
= 0;
186 static const sal_Int32 CLOSE
= 1;
188 class OFolderContent
: public OContent
191 // Already provided children
192 safe_list
< XContent
> m_aChildList
;
195 virtual Any
doCommand( const Command
& crCommand
);
197 // new methods, can be overloaded
198 virtual Any
doOpenCommand();
199 virtual Any
doCloseCommand();
201 // To be implemented by inheritants
202 virtual Sequence
< XContent
> getAllChildren() = 0;
206 // XCommmandTaskProcessor
207 virtual Reference
< XCommandTask
> SAL_CALL
createCommandTask(const Command
& rCommand
, const Reference
< XContentTaskEnvironment
>& rEnvironment
) throw();
210 virtual Sequence
< CommandInfo
> SAL_CALL
getCommands() throw();
213 //---------------------------------------------------------------------------
217 //---------------------------------------------------------------------------
223 Guard
< OContent
> m_aContentGuard
;
225 OContent
*m_pContent
;
226 Reference
< XContentTaskEnvironment
> m_xEnvironment
;
227 ContentTaskStatus m_eStatus
;
230 static void executeWorker( void * );
231 virtual ContentTaskStatus
setStatus( ContentTaskStatus eStatus
);
233 // To be implemented by inheritants
234 virtual void doExecute() = 0;
236 OContentTask( const Reference
< XContentTaskEnvironment
>& xEnv
, OContent
*pContent
);
237 virtual ~OContentTask();
240 virtual Any SAL_CALL
queryInterface( const Type
&type
) throw( RuntimeException
);
242 virtual void SAL_CALL
acquire() throw(RuntimeException
);
243 virtual void SAL_CALL
release() throw(RuntimeException
);
246 virtual void SAL_CALL
start() throw();
247 virtual void SAL_CALL
execute() throw( Exception
);
248 virtual void SAL_CALL
abort() throw();
249 virtual ContentTaskStatus SAL_CALL
getStatus() throw();
250 virtual Reference
< XContentTaskEnvironment
> SAL_CALL
getEnvironment() throw();
253 //---------------------------------------------------------------------------
257 //---------------------------------------------------------------------------
268 OCommandTask( const Reference
< XContentTaskEnvironment
>& xEnv
, OContent
*pContent
, const Command
& rCommand
);
269 virtual ~OCommandTask();
271 virtual void doExecute();
274 virtual Any SAL_CALL
queryInterface( const Type
&type
) throw( RuntimeException
);
275 virtual void SAL_CALL
acquire() throw(RuntimeException
);
276 virtual void SAL_CALL
release() throw(RuntimeException
);
279 virtual void SAL_CALL
start() throw();
280 virtual void SAL_CALL
execute() throw( Exception
);
281 virtual void SAL_CALL
abort() throw();
282 virtual ContentTaskStatus SAL_CALL
getStatus() throw();
283 virtual Reference
< XContentTaskEnvironment
> SAL_CALL
getEnvironment() throw();
286 virtual Command SAL_CALL
getCommand() throw();
287 virtual Any SAL_CALL
getResult() throw();
290 //---------------------------------------------------------------------------
294 //---------------------------------------------------------------------------
296 class OPropertyTask
:
301 Sequence
< PropertyValueInfo
> m_aProperties
;
302 PropertyTaskType m_eType
;
304 OPropertyTask(const Reference
< XContentTaskEnvironment
>& Environment
, OContent
*pContent
, const Sequence
< PropertyValue
>& Properties
, PropertyTaskType Type
);
305 virtual ~OPropertyTask();
307 virtual void doExecute();
309 // To be implemented by inheritants
310 virtual Any
setPropertyValue( PropertyValueInfo
& rProperty
) = 0;
311 virtual void getPropertyValue( PropertyValueInfo
& rProperty
) = 0;
314 virtual Any SAL_CALL
queryInterface( const Type
&type
) throw( RuntimeException
);
315 virtual void SAL_CALL
acquire() throw(RuntimeException
);
316 virtual void SAL_CALL
release() throw(RuntimeException
);
319 virtual void SAL_CALL
start() throw();
320 virtual void SAL_CALL
execute() throw( Exception
);
321 virtual void SAL_CALL
abort() throw();
322 virtual ContentTaskStatus SAL_CALL
getStatus() throw();
323 virtual Reference
< XContentTaskEnvironment
> SAL_CALL
getEnvironment() throw();
326 PropertyTaskType SAL_CALL
getType() throw();
327 Sequence
< PropertyValueInfo
> SAL_CALL
getProperties() throw();
330 #endif // _UCBHELPER_CONTENT_HXX_