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 
24 #ifndef _PROVIDER_HXX
25 #define _PROVIDER_HXX
26 
27 #include <rtl/ustring.hxx>
28 #include <osl/mutex.hxx>
29 #include <ucbhelper/providerhelper.hxx>
30 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
31 #include <com/sun/star/container/XContainerListener.hpp>
32 #include <com/sun/star/container/XContainer.hpp>
33 #include <com/sun/star/lang/XComponent.hpp>
34 
35 
36 namespace chelp {
37 
38 //=========================================================================
39 
40 // UNO service name for the provider. This name will be used by the UCB to
41 // create instances of the provider.
42 
43 //#define MYUCP_CONTENT_PROVIDER_SERVICE_NAME         "com.sun.star.ucb.CHelpContentProvider"
44 #define MYUCP_CONTENT_PROVIDER_SERVICE_NAME1   "com.sun.star.help.XMLHelp"
45 #define MYUCP_CONTENT_PROVIDER_SERVICE_NAME_LENGTH1	25
46 
47 #define MYUCP_CONTENT_PROVIDER_SERVICE_NAME2  "com.sun.star.ucb.HelpContentProvider"
48 #define MYUCP_CONTENT_PROVIDER_SERVICE_NAME_LENGTH2	36
49 
50 // URL scheme. This is the scheme the provider will be able to create
51 // contents for. The UCB will select the provider ( i.e. in order to create
52 // contents ) according to this scheme.
53 
54 #define MYUCP_URL_SCHEME        "vnd.sun.star.help"
55 #define MYUCP_URL_SCHEME_LENGTH	18
56 #define MYUCP_CONTENT_TYPE      "application/vnd.sun.star.xmlhelp"    // UCB Content Type.
57 
58 //=========================================================================
59 
60 
61 	class Databases;
62 
63 
64 	class ContentProvider :
65 		public ::ucbhelper::ContentProviderImplHelper,
66 		public ::com::sun::star::container::XContainerListener,
67 		public ::com::sun::star::lang::XComponent
68 	{
69 	public:
70 		ContentProvider(
71 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rSMgr );
72 
73 		virtual ~ContentProvider();
74 
75 		// XInterface
76 		XINTERFACE_DECL()
77 
78 			// XTypeProvider
79 			XTYPEPROVIDER_DECL()
80 
81 			// XServiceInfo
82 			XSERVICEINFO_DECL()
83 
84 			// XContentProvider
85 			virtual ::com::sun::star::uno::Reference<
86 		::com::sun::star::ucb::XContent > SAL_CALL
87 		queryContent( const ::com::sun::star::uno::Reference<
88 					  ::com::sun::star::ucb::XContentIdentifier >& Identifier )
89 			throw( ::com::sun::star::ucb::IllegalIdentifierException,
90 				   ::com::sun::star::uno::RuntimeException );
91 
92 		//////////////////////////////////////////////////////////////////////
93 		// Additional interfaces
94 		//////////////////////////////////////////////////////////////////////
95 
96 		// XComponent
97 
98 		virtual void SAL_CALL
99 		dispose(  )
100 			throw (::com::sun::star::uno::RuntimeException);
101 
102 		virtual void SAL_CALL
addEventListener(const::com::sun::star::uno::Reference<::com::sun::star::lang::XEventListener> & xListener)103 		addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener )
104 			throw (::com::sun::star::uno::RuntimeException)
105 		{
106 			(void)xListener;
107 		}
108 
109 		virtual void SAL_CALL
removeEventListener(const::com::sun::star::uno::Reference<::com::sun::star::lang::XEventListener> & aListener)110 		removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener )
111 			throw (::com::sun::star::uno::RuntimeException)
112 		{
113 			(void)aListener;
114 		}
115 
116 		// XConainerListener ( deriver from XEventListener )
117 
118 		virtual void SAL_CALL
disposing(const::com::sun::star::lang::EventObject & Source)119 		disposing( const ::com::sun::star::lang::EventObject& Source )
120 			throw (::com::sun::star::uno::RuntimeException)
121 		{
122 			(void)Source;
123 			m_xContainer = com::sun::star::uno::Reference<com::sun::star::container::XContainer>(0);
124 		}
125 
126 		virtual void SAL_CALL
elementInserted(const::com::sun::star::container::ContainerEvent & Event)127 		elementInserted( const ::com::sun::star::container::ContainerEvent& Event )
128 			throw (::com::sun::star::uno::RuntimeException)
129 		{
130 			(void)Event;
131 		}
132 
133 		virtual void SAL_CALL
elementRemoved(const::com::sun::star::container::ContainerEvent & Event)134 		elementRemoved( const ::com::sun::star::container::ContainerEvent& Event )
135 			throw (::com::sun::star::uno::RuntimeException)
136 		{
137 			(void)Event;
138 		}
139 
140 		virtual void SAL_CALL
141 		elementReplaced( const ::com::sun::star::container::ContainerEvent& Event )
142 			throw (::com::sun::star::uno::RuntimeException);
143 
144 
145 		//////////////////////////////////////////////////////////////////////
146 		// Non-interface methods.
147 		//////////////////////////////////////////////////////////////////////
148 
149 	private:
150 
151 		osl::Mutex     m_aMutex;
152 		bool           isInitialized;
153 		rtl::OUString  m_aScheme;
154 		Databases*     m_pDatabases;
155 		com::sun::star::uno::Reference<com::sun::star::container::XContainer> m_xContainer;
156 
157 		// private methods
158 
159 		void init();
160 
161 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
162 		getConfiguration() const;
163 
164 		::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess >
165 		getHierAccess( const ::com::sun::star::uno::Reference<  ::com::sun::star::lang::XMultiServiceFactory >& sProvider,
166 					   const char* file ) const;
167 
168 		::rtl::OUString
169 		getKey( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess >& xHierAccess,
170 				const char* key ) const;
171 
172 	  sal_Bool
173 	  getBooleanKey(
174 					const ::com::sun::star::uno::Reference<
175 					::com::sun::star::container::XHierarchicalNameAccess >& xHierAccess,
176 					const char* key) const;
177 
178 	  void subst( rtl::OUString& instpath ) const;
179 	};
180 
181 }
182 
183 #endif
184