1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef DBA_CONTENTHELPER_HXX
24 #define DBA_CONTENTHELPER_HXX
25 
26 #ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_
27 #include <com/sun/star/ucb/XContent.hpp>
28 #endif
29 #ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_
30 #include <com/sun/star/ucb/XCommandProcessor.hpp>
31 #endif
32 #ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGENOTIFIER_HPP_
33 #include <com/sun/star/beans/XPropertiesChangeNotifier.hpp>
34 #endif
35 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_
36 #include <com/sun/star/beans/XPropertyContainer.hpp>
37 #endif
38 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #endif
41 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
42 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
43 #endif
44 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
45 #include <com/sun/star/lang/XInitialization.hpp>
46 #endif
47 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
48 #include <com/sun/star/container/XNameAccess.hpp>
49 #endif
50 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
51 #include <com/sun/star/sdbc/XRow.hpp>
52 #endif
53 #ifndef _COM_SUN_STAR_EMBED_XSTORAGE_HPP_
54 #include <com/sun/star/embed/XStorage.hpp>
55 #endif
56 #ifndef _COM_SUN_STAR_EMBED_XEMBEDDEDOBJECT_HPP_
57 #include <com/sun/star/embed/XEmbeddedObject.hpp>
58 #endif
59 #ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
60 #include <com/sun/star/lang/XUnoTunnel.hpp>
61 #endif
62 #ifndef _CPPUHELPER_COMPBASE9_HXX_
63 #include <cppuhelper/compbase9.hxx>
64 #endif
65 #ifndef _COMPHELPER_BROADCASTHELPER_HXX_
66 #include <comphelper/broadcasthelper.hxx>
67 #endif
68 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
69 #include <comphelper/componentcontext.hxx>
70 #endif
71 #ifndef _COMPHELPER_UNO3_HXX_
72 #include <comphelper/uno3.hxx>
73 #endif
74 #ifndef _COMPHELPER_STLTYPES_HXX_
75 #include <comphelper/stl_types.hxx>
76 #endif
77 #ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_
78 #include <com/sun/star/beans/Property.hpp>
79 #endif
80 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
81 #include <com/sun/star/container/XChild.hpp>
82 #endif
83 #ifndef _COM_SUN_STAR_SDBCX_XRENAME_HPP_
84 #include <com/sun/star/sdbcx/XRename.hpp>
85 #endif
86 #ifndef CONNECTIVITY_SQLERROR_HXX
87 #include <connectivity/sqlerror.hxx>
88 #endif
89 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED
90 #include <boost/shared_ptr.hpp>
91 #endif
92 
93 namespace dbaccess
94 {
95 	class ODatabaseModelImpl;
96 	struct ContentProperties
97 	{
98 		::rtl::OUString aTitle;    		// Title
99         ::boost::optional< ::rtl::OUString >
100                         aContentType;   // ContentType (aka MediaType aka MimeType)
101 		sal_Bool        bIsDocument;    // IsDocument
102 		sal_Bool        bIsFolder;    	// IsFolder
103 		sal_Bool		bAsTemplate;	// AsTemplate
104 		::rtl::OUString	sPersistentName;// persistent name of the document
105 
ContentPropertiesdbaccess::ContentProperties106 		ContentProperties()
107 		    :bIsDocument( sal_True )
108             ,bIsFolder( sal_False )
109             ,bAsTemplate( sal_False )
110         {
111         }
112 	};
113 
114 	class OContentHelper_Impl
115 	{
116 	public:
117 		OContentHelper_Impl();
118 		virtual ~OContentHelper_Impl();
119 
120 		ContentProperties	m_aProps;
121 		ODatabaseModelImpl*	m_pDataSource; // this will stay alive as long as the content exists
122 	};
123 
124 	typedef ::boost::shared_ptr<OContentHelper_Impl> TContentPtr;
125 
126 
127 	typedef ::cppu::OMultiTypeInterfaceContainerHelperVar<	::rtl::OUString,
128 															::comphelper::UStringHash,
129 															::comphelper::UStringEqual
130 														> PropertyChangeListenerContainer;
131 	typedef ::comphelper::OBaseMutex	OContentHelper_MBASE;
132 	typedef ::cppu::WeakComponentImplHelper9	<	::com::sun::star::ucb::XContent
133 												,	::com::sun::star::ucb::XCommandProcessor
134 												,	::com::sun::star::lang::XServiceInfo
135 												,	::com::sun::star::beans::XPropertiesChangeNotifier
136 												,	::com::sun::star::beans::XPropertyContainer
137 												,	::com::sun::star::lang::XInitialization
138 												,	::com::sun::star::lang::XUnoTunnel
139 												,	::com::sun::star::container::XChild
140 												,	::com::sun::star::sdbcx::XRename
141 												>	OContentHelper_COMPBASE;
142 
143 	class OContentHelper :	 public OContentHelper_MBASE
144 							,public OContentHelper_COMPBASE
145 	{
146 		::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
147 			setPropertyValues( const ::com::sun::star::uno::Sequence<
148 								::com::sun::star::beans::PropertyValue >& rValues,
149 							const ::com::sun::star::uno::Reference<
150 								::com::sun::star::ucb::XCommandEnvironment >& xEnv );
151 		com::sun::star::uno::Sequence< com::sun::star::beans::Property >
152 			getProperties( const com::sun::star::uno::Reference<
153 							com::sun::star::ucb::XCommandEnvironment > & xEnv );
154 
155         void impl_rename_throw(const ::rtl::OUString& _sNewName,bool _bNotify = true);
156 
157 	protected:
158 		::cppu::OInterfaceContainerHelper	    m_aContentListeners;
159 		PropertyChangeListenerContainer		    m_aPropertyChangeListeners;
160 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
161                                                 m_xParentContainer;
162         const ::comphelper::ComponentContext    m_aContext;
163         const ::connectivity::SQLError          m_aErrorHelper;
164 		TContentPtr						        m_pImpl;
165 		sal_uInt32						        m_nCommandId;
166 
167 		// helper
168 		virtual void SAL_CALL disposing();
169 
170 		virtual void notifyDataSourceModified();
171 
172 		/**
173 		* This method can be used to propagate changes of property values.
174 		*
175 		* @param evt is a sequence of property change events.
176 		*/
177 		void notifyPropertiesChange( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyChangeEvent >& evt ) const;
178 
179         ::rtl::OUString impl_getHierarchicalName( bool _includingRootContainer ) const;
180 
181 	public:
182 
183 		OContentHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB
184 						,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >&	_xParentContainer
185 						,const TContentPtr& _pImpl
186 					);
187 
188 		// com::sun::star::lang::XTypeProvider
189 		virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId(  ) throw(::com::sun::star::uno::RuntimeException);
190 		static ::com::sun::star::uno::Sequence< sal_Int8 >	getUnoTunnelImplementationId();
191 		// ::com::sun::star::lang::XServiceInfo
192 		virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
193 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
194 		virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
195 
196 		// XContent
197 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentIdentifier > SAL_CALL getIdentifier(  ) throw (::com::sun::star::uno::RuntimeException) ;
198 		virtual ::rtl::OUString SAL_CALL getContentType(  ) throw (::com::sun::star::uno::RuntimeException) ;
199 		virtual void SAL_CALL addContentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentEventListener >& Listener ) throw (::com::sun::star::uno::RuntimeException) ;
200 		virtual void SAL_CALL removeContentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentEventListener >& Listener ) throw (::com::sun::star::uno::RuntimeException) ;
201 
202 		// XCommandProcessor
203 		virtual sal_Int32 SAL_CALL createCommandIdentifier(  ) throw (::com::sun::star::uno::RuntimeException) ;
204 		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) ;
205 		virtual void SAL_CALL abort( sal_Int32 CommandId ) throw (::com::sun::star::uno::RuntimeException) ;
206 
207 		// XPropertiesChangeNotifier
208 		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) ;
209 		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) ;
210 
211 		// XPropertyContainer
212 		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) ;
213 		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) ;
214 
215 		// XInitialization
216 		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);
217 
218 		// com::sun::star::lang::XUnoTunnel
219 		virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
220         static OContentHelper* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent );
221 
222 		// ::com::sun::star::container::XChild
223 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent(  ) throw (::com::sun::star::uno::RuntimeException);
224 		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);
225 
226 		// XRename
227 		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);
228 
getContentProperties() const229 		inline const ContentProperties& getContentProperties() const { return m_pImpl->m_aProps; }
230 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
231 			getPropertyValues( const ::com::sun::star::uno::Sequence<
232 							::com::sun::star::beans::Property >& rProperties );
233 
getContext() const234         const ::comphelper::ComponentContext& getContext() const { return m_aContext; }
235 
getImpl() const236 		inline TContentPtr getImpl() const { return m_pImpl; }
237 
238     protected:
239         virtual ::rtl::OUString determineContentType() const = 0;
240 	};
241 
242 //........................................................................
243 }	// namespace dbaccess
244 //........................................................................
245 #endif // DBA_CONTENTHELPER_HXX
246