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 #ifndef DBA_CONTENTHELPER_HXX 28 #define DBA_CONTENTHELPER_HXX 29 30 #ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_ 31 #include <com/sun/star/ucb/XContent.hpp> 32 #endif 33 #ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_ 34 #include <com/sun/star/ucb/XCommandProcessor.hpp> 35 #endif 36 #ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGENOTIFIER_HPP_ 37 #include <com/sun/star/beans/XPropertiesChangeNotifier.hpp> 38 #endif 39 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_ 40 #include <com/sun/star/beans/XPropertyContainer.hpp> 41 #endif 42 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ 43 #include <com/sun/star/lang/XServiceInfo.hpp> 44 #endif 45 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ 46 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 47 #endif 48 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ 49 #include <com/sun/star/lang/XInitialization.hpp> 50 #endif 51 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ 52 #include <com/sun/star/container/XNameAccess.hpp> 53 #endif 54 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ 55 #include <com/sun/star/sdbc/XRow.hpp> 56 #endif 57 #ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_ 58 #include <com/sun/star/embed/XStorage.hpp> 59 #endif 60 #ifndef _COM_SUN_STAR_EMBED_XEMBEDDEDOBJECT_HPP_ 61 #include <com/sun/star/embed/XEmbeddedObject.hpp> 62 #endif 63 #ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_ 64 #include <com/sun/star/lang/XUnoTunnel.hpp> 65 #endif 66 #ifndef _CPPUHELPER_COMPBASE9_HXX_ 67 #include <cppuhelper/compbase9.hxx> 68 #endif 69 #ifndef _COMPHELPER_BROADCASTHELPER_HXX_ 70 #include <comphelper/broadcasthelper.hxx> 71 #endif 72 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX 73 #include <comphelper/componentcontext.hxx> 74 #endif 75 #ifndef _COMPHELPER_UNO3_HXX_ 76 #include <comphelper/uno3.hxx> 77 #endif 78 #ifndef _COMPHELPER_STLTYPES_HXX_ 79 #include <comphelper/stl_types.hxx> 80 #endif 81 #ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ 82 #include <com/sun/star/beans/Property.hpp> 83 #endif 84 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ 85 #include <com/sun/star/container/XChild.hpp> 86 #endif 87 #ifndef _COM_SUN_STAR_SDBCX_XRENAME_HPP_ 88 #include <com/sun/star/sdbcx/XRename.hpp> 89 #endif 90 #ifndef CONNECTIVITY_SQLERROR_HXX 91 #include <connectivity/sqlerror.hxx> 92 #endif 93 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED 94 #include <boost/shared_ptr.hpp> 95 #endif 96 97 namespace dbaccess 98 { 99 class ODatabaseModelImpl; 100 struct ContentProperties 101 { 102 ::rtl::OUString aTitle; // Title 103 ::boost::optional< ::rtl::OUString > 104 aContentType; // ContentType (aka MediaType aka MimeType) 105 sal_Bool bIsDocument; // IsDocument 106 sal_Bool bIsFolder; // IsFolder 107 sal_Bool bAsTemplate; // AsTemplate 108 ::rtl::OUString sPersistentName;// persistent name of the document 109 110 ContentProperties() 111 :bIsDocument( sal_True ) 112 ,bIsFolder( sal_False ) 113 ,bAsTemplate( sal_False ) 114 { 115 } 116 }; 117 118 class OContentHelper_Impl 119 { 120 public: 121 OContentHelper_Impl(); 122 virtual ~OContentHelper_Impl(); 123 124 ContentProperties m_aProps; 125 ODatabaseModelImpl* m_pDataSource; // this will stay alive as long as the content exists 126 }; 127 128 typedef ::boost::shared_ptr<OContentHelper_Impl> TContentPtr; 129 130 131 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar< ::rtl::OUString, 132 ::comphelper::UStringHash, 133 ::comphelper::UStringEqual 134 > PropertyChangeListenerContainer; 135 typedef ::comphelper::OBaseMutex OContentHelper_MBASE; 136 typedef ::cppu::WeakComponentImplHelper9 < ::com::sun::star::ucb::XContent 137 , ::com::sun::star::ucb::XCommandProcessor 138 , ::com::sun::star::lang::XServiceInfo 139 , ::com::sun::star::beans::XPropertiesChangeNotifier 140 , ::com::sun::star::beans::XPropertyContainer 141 , ::com::sun::star::lang::XInitialization 142 , ::com::sun::star::lang::XUnoTunnel 143 , ::com::sun::star::container::XChild 144 , ::com::sun::star::sdbcx::XRename 145 > OContentHelper_COMPBASE; 146 147 class OContentHelper : public OContentHelper_MBASE 148 ,public OContentHelper_COMPBASE 149 { 150 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > 151 setPropertyValues( const ::com::sun::star::uno::Sequence< 152 ::com::sun::star::beans::PropertyValue >& rValues, 153 const ::com::sun::star::uno::Reference< 154 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ); 155 com::sun::star::uno::Sequence< com::sun::star::beans::Property > 156 getProperties( const com::sun::star::uno::Reference< 157 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 158 159 void impl_rename_throw(const ::rtl::OUString& _sNewName,bool _bNotify = true); 160 161 protected: 162 ::cppu::OInterfaceContainerHelper m_aContentListeners; 163 PropertyChangeListenerContainer m_aPropertyChangeListeners; 164 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 165 m_xParentContainer; 166 const ::comphelper::ComponentContext m_aContext; 167 const ::connectivity::SQLError m_aErrorHelper; 168 TContentPtr m_pImpl; 169 sal_uInt32 m_nCommandId; 170 171 // helper 172 virtual void SAL_CALL disposing(); 173 174 virtual void notifyDataSourceModified(); 175 176 /** 177 * This method can be used to propagate changes of property values. 178 * 179 * @param evt is a sequence of property change events. 180 */ 181 void notifyPropertiesChange( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyChangeEvent >& evt ) const; 182 183 ::rtl::OUString impl_getHierarchicalName( bool _includingRootContainer ) const; 184 185 public: 186 187 OContentHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB 188 ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xParentContainer 189 ,const TContentPtr& _pImpl 190 ); 191 192 // com::sun::star::lang::XTypeProvider 193 virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(::com::sun::star::uno::RuntimeException); 194 static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId(); 195 // ::com::sun::star::lang::XServiceInfo 196 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 197 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 198 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); 199 200 // XContent 201 virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentIdentifier > SAL_CALL getIdentifier( ) throw (::com::sun::star::uno::RuntimeException) ; 202 virtual ::rtl::OUString SAL_CALL getContentType( ) throw (::com::sun::star::uno::RuntimeException) ; 203 virtual void SAL_CALL addContentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentEventListener >& Listener ) throw (::com::sun::star::uno::RuntimeException) ; 204 virtual void SAL_CALL removeContentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentEventListener >& Listener ) throw (::com::sun::star::uno::RuntimeException) ; 205 206 // XCommandProcessor 207 virtual sal_Int32 SAL_CALL createCommandIdentifier( ) throw (::com::sun::star::uno::RuntimeException) ; 208 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) ; 209 virtual void SAL_CALL abort( sal_Int32 CommandId ) throw (::com::sun::star::uno::RuntimeException) ; 210 211 // XPropertiesChangeNotifier 212 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) ; 213 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) ; 214 215 // XPropertyContainer 216 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) ; 217 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 219 // XInitialization 220 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); 221 222 // com::sun::star::lang::XUnoTunnel 223 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); 224 static OContentHelper* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent ); 225 226 // ::com::sun::star::container::XChild 227 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent( ) throw (::com::sun::star::uno::RuntimeException); 228 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 230 // XRename 231 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); 232 233 inline const ContentProperties& getContentProperties() const { return m_pImpl->m_aProps; } 234 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 235 getPropertyValues( const ::com::sun::star::uno::Sequence< 236 ::com::sun::star::beans::Property >& rProperties ); 237 238 const ::comphelper::ComponentContext& getContext() const { return m_aContext; } 239 240 inline TContentPtr getImpl() const { return m_pImpl; } 241 242 protected: 243 virtual ::rtl::OUString determineContentType() const = 0; 244 }; 245 246 //........................................................................ 247 } // namespace dbaccess 248 //........................................................................ 249 #endif // DBA_CONTENTHELPER_HXX 250