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: ContentHelper.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 ************************************************************************/
30 #ifndef DBA_CONTENTHELPER_HXX
31 #define DBA_CONTENTHELPER_HXX
33 #ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_
34 #include <com/sun/star/ucb/XContent.hpp>
36 #ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_
37 #include <com/sun/star/ucb/XCommandProcessor.hpp>
39 #ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGENOTIFIER_HPP_
40 #include <com/sun/star/beans/XPropertiesChangeNotifier.hpp>
42 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_
43 #include <com/sun/star/beans/XPropertyContainer.hpp>
45 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
46 #include <com/sun/star/lang/XServiceInfo.hpp>
48 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
49 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
51 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
52 #include <com/sun/star/lang/XInitialization.hpp>
54 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
55 #include <com/sun/star/container/XNameAccess.hpp>
57 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
58 #include <com/sun/star/sdbc/XRow.hpp>
60 #ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
61 #include <com/sun/star/embed/XStorage.hpp>
63 #ifndef _COM_SUN_STAR_EMBED_XEMBEDDEDOBJECT_HPP_
64 #include <com/sun/star/embed/XEmbeddedObject.hpp>
66 #ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
67 #include <com/sun/star/lang/XUnoTunnel.hpp>
69 #ifndef _CPPUHELPER_COMPBASE9_HXX_
70 #include <cppuhelper/compbase9.hxx>
72 #ifndef _COMPHELPER_BROADCASTHELPER_HXX_
73 #include <comphelper/broadcasthelper.hxx>
75 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
76 #include <comphelper/componentcontext.hxx>
78 #ifndef _COMPHELPER_UNO3_HXX_
79 #include <comphelper/uno3.hxx>
81 #ifndef _COMPHELPER_STLTYPES_HXX_
82 #include <comphelper/stl_types.hxx>
84 #ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_
85 #include <com/sun/star/beans/Property.hpp>
87 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
88 #include <com/sun/star/container/XChild.hpp>
90 #ifndef _COM_SUN_STAR_SDBCX_XRENAME_HPP_
91 #include <com/sun/star/sdbcx/XRename.hpp>
93 #ifndef CONNECTIVITY_SQLERROR_HXX
94 #include <connectivity/sqlerror.hxx>
96 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
97 #include <boost/shared_ptr.hpp>
102 class ODatabaseModelImpl
;
103 struct ContentProperties
105 ::rtl::OUString aTitle
; // Title
106 ::boost::optional
< ::rtl::OUString
>
107 aContentType
; // ContentType (aka MediaType aka MimeType)
108 sal_Bool bIsDocument
; // IsDocument
109 sal_Bool bIsFolder
; // IsFolder
110 sal_Bool bAsTemplate
; // AsTemplate
111 ::rtl::OUString sPersistentName
;// persistent name of the document
113 // @@@ Add other properties supported by your content.
116 : bIsDocument( sal_True
), bIsFolder( sal_False
), bAsTemplate( sal_False
) {}
119 class OContentHelper_Impl
122 OContentHelper_Impl();
123 virtual ~OContentHelper_Impl();
125 ContentProperties m_aProps
;
126 ODatabaseModelImpl
* m_pDataSource
; // this will stay alive as long as the content exists
129 typedef ::boost::shared_ptr
<OContentHelper_Impl
> TContentPtr
;
132 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar
< ::rtl::OUString
,
133 ::comphelper::UStringHash
,
134 ::comphelper::UStringEqual
135 > PropertyChangeListenerContainer
;
136 typedef ::comphelper::OBaseMutex OContentHelper_MBASE
;
137 typedef ::cppu::WeakComponentImplHelper9
< ::com::sun::star::ucb::XContent
138 , ::com::sun::star::ucb::XCommandProcessor
139 , ::com::sun::star::lang::XServiceInfo
140 , ::com::sun::star::beans::XPropertiesChangeNotifier
141 , ::com::sun::star::beans::XPropertyContainer
142 , ::com::sun::star::lang::XInitialization
143 , ::com::sun::star::lang::XUnoTunnel
144 , ::com::sun::star::container::XChild
145 , ::com::sun::star::sdbcx::XRename
146 > OContentHelper_COMPBASE
;
148 class OContentHelper
: public OContentHelper_MBASE
149 ,public OContentHelper_COMPBASE
151 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>
152 setPropertyValues( const ::com::sun::star::uno::Sequence
<
153 ::com::sun::star::beans::PropertyValue
>& rValues
,
154 const ::com::sun::star::uno::Reference
<
155 ::com::sun::star::ucb::XCommandEnvironment
>& xEnv
);
156 com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>
157 getProperties( const com::sun::star::uno::Reference
<
158 com::sun::star::ucb::XCommandEnvironment
> & xEnv
);
160 void impl_rename_throw(const ::rtl::OUString
& _sNewName
,bool _bNotify
= true);
163 ::cppu::OInterfaceContainerHelper m_aContentListeners
;
164 PropertyChangeListenerContainer m_aPropertyChangeListeners
;
165 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
167 const ::comphelper::ComponentContext m_aContext
;
168 const ::connectivity::SQLError m_aErrorHelper
;
170 sal_uInt32 m_nCommandId
;
173 virtual void SAL_CALL
disposing();
175 virtual void notifyDataSourceModified();
178 * This method can be used to propagate changes of property values.
180 * @param evt is a sequence of property change events.
182 void notifyPropertiesChange( const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyChangeEvent
>& evt
) const;
185 OContentHelper( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _xORB
186 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xParentContainer
187 ,const TContentPtr
& _pImpl
190 // com::sun::star::lang::XTypeProvider
191 virtual ::com::sun::star::uno::Sequence
<sal_Int8
> SAL_CALL
getImplementationId( ) throw(::com::sun::star::uno::RuntimeException
);
192 static ::com::sun::star::uno::Sequence
< sal_Int8
> getUnoTunnelImplementationId();
193 // ::com::sun::star::lang::XServiceInfo
194 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
);
195 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
);
196 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
);
199 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContentIdentifier
> SAL_CALL
getIdentifier( ) throw (::com::sun::star::uno::RuntimeException
) ;
200 virtual ::rtl::OUString SAL_CALL
getContentType( ) throw (::com::sun::star::uno::RuntimeException
) ;
201 virtual void SAL_CALL
addContentEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContentEventListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
) ;
202 virtual void SAL_CALL
removeContentEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XContentEventListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
) ;
205 virtual sal_Int32 SAL_CALL
createCommandIdentifier( ) throw (::com::sun::star::uno::RuntimeException
) ;
206 virtual ::com::sun::star::uno::Any SAL_CALL
execute( const ::com::sun::star::ucb::Command
& aCommand
, sal_Int32 CommandId
, const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XCommandEnvironment
>& Environment
) throw (::com::sun::star::uno::Exception
, ::com::sun::star::ucb::CommandAbortedException
, ::com::sun::star::uno::RuntimeException
) ;
207 virtual void SAL_CALL
abort( sal_Int32 CommandId
) throw (::com::sun::star::uno::RuntimeException
) ;
209 // XPropertiesChangeNotifier
210 virtual void SAL_CALL
addPropertiesChangeListener( const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& PropertyNames
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertiesChangeListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
) ;
211 virtual void SAL_CALL
removePropertiesChangeListener( const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& PropertyNames
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertiesChangeListener
>& Listener
) throw (::com::sun::star::uno::RuntimeException
) ;
213 // XPropertyContainer
214 virtual void SAL_CALL
addProperty( const ::rtl::OUString
& Name
, sal_Int16 Attributes
, const ::com::sun::star::uno::Any
& DefaultValue
) throw (::com::sun::star::beans::PropertyExistException
, ::com::sun::star::beans::IllegalTypeException
, ::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
) ;
215 virtual void SAL_CALL
removeProperty( const ::rtl::OUString
& Name
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::beans::NotRemoveableException
, ::com::sun::star::uno::RuntimeException
) ;
218 virtual void SAL_CALL
initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
220 // com::sun::star::lang::XUnoTunnel
221 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
) throw(::com::sun::star::uno::RuntimeException
);
222 static OContentHelper
* getImplementation( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxComponent
);
224 // ::com::sun::star::container::XChild
225 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
getParent( ) throw (::com::sun::star::uno::RuntimeException
);
226 virtual void SAL_CALL
setParent( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& Parent
) throw (::com::sun::star::lang::NoSupportException
, ::com::sun::star::uno::RuntimeException
);
229 virtual void SAL_CALL
rename( const ::rtl::OUString
& newName
) throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::container::ElementExistException
, ::com::sun::star::uno::RuntimeException
);
231 inline const ContentProperties
& getContentProperties() const { return m_pImpl
->m_aProps
; }
232 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
233 getPropertyValues( const ::com::sun::star::uno::Sequence
<
234 ::com::sun::star::beans::Property
>& rProperties
);
236 inline TContentPtr
getImpl() const { return m_pImpl
; }
239 virtual ::rtl::OUString
determineContentType() const = 0;
242 //........................................................................
243 } // namespace dbaccess
244 //........................................................................
245 #endif // DBA_CONTENTHELPER_HXX