xref: /aoo42x/main/xmlhelp/source/treeview/tvread.hxx (revision 7b6bd0c4)
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 _TREEVIEW_TVREAD_HXX_
25 #define _TREEVIEW_TVREAD_HXX_
26 
27 #ifndef INCLUDED_STL_VECTOR
28 #include <vector>
29 #define INCLUDED_STL_VECTOR
30 #endif
31 #include <rtl/ref.hxx>
32 #include <rtl/ustring.hxx>
33 #include <ucbhelper/macros.hxx>
34 #include <com/sun/star/uno/Type.hxx>
35 #include <cppuhelper/weak.hxx>
36 #include <com/sun/star/uno/XInterface.hpp>
37 #include <com/sun/star/lang/XTypeProvider.hpp>
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
40 #include <com/sun/star/util/XChangesNotifier.hpp>
41 #include <com/sun/star/lang/XComponent.hpp>
42 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #include <com/sun/star/deployment/XPackage.hpp>
44 #include "com/sun/star/ucb/XSimpleFileAccess.hpp"
45 
46 namespace treeview {
47 
48 
49 	class ConfigData
50 	{
51 	public:
52         enum {
53             PRODUCTNAME, PRODUCTVERSION, VENDORNAME, VENDORVERSION,
54             VENDORSHORT };
55 		ConfigData();
56 		int                    m_vAdd[5];
57 		rtl::OUString          m_vReplacement[5];
58 		rtl::OUString          prodName,prodVersion,vendName,vendVersion,vendShort;
59 
60 		std::vector< sal_uInt64 >		vFileLen;
61 		std::vector< rtl::OUString >	vFileURL;
62 		rtl::OUString locale,system;
63 		rtl::OUString appendix;
64 
65 		void SAL_CALL replaceName( rtl::OUString& oustring ) const;
66 	};
67 
68 
69 	class TVDom;
70 	class TVChildTarget;
71 
72 	class TVBase
73 		: public cppu::OWeakObject,
74 		  public com::sun::star::lang::XTypeProvider,
75 		  public com::sun::star::container::XNameAccess,
76 		  public com::sun::star::container::XHierarchicalNameAccess,
77 		  public com::sun::star::util::XChangesNotifier,
78 		  public com::sun::star::lang::XComponent
79 	{
80 		friend class TVChildTarget;
81 
82 	public:
83 
~TVBase()84 		virtual ~TVBase() { }
85 
86 		// XInterface
87 		virtual com::sun::star::uno::Any SAL_CALL
88 		queryInterface(
89 			const com::sun::star::uno::Type& aType )
90 			throw( com::sun::star::uno::RuntimeException);
91 
92 		virtual void SAL_CALL
93 		acquire(
94 			void )
95 			throw();
96 
97 		virtual void SAL_CALL
98 		release(
99 			void )
100 			throw();
101 
102 
103 		// XTypeProvider
104 
XTYPEPROVIDER_DECL()105 		XTYPEPROVIDER_DECL()
106 
107 
108 		// XNameAccess
109 
110 		virtual com::sun::star::uno::Type SAL_CALL
111 		getElementType(  )
112 			throw( com::sun::star::uno::RuntimeException )
113 		{
114 			return getCppuVoidType();
115 		}
116 
117 
hasElements()118 		virtual sal_Bool SAL_CALL hasElements()
119 			throw( com::sun::star::uno::RuntimeException )
120 		{
121 			return true;
122 		}
123 
124 		// XChangesNotifier
125 
126 		virtual void SAL_CALL
addChangesListener(const com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> & aListener)127 		addChangesListener(
128 			const com::sun::star::uno::Reference< com::sun::star::util::XChangesListener >& aListener )
129 			throw( com::sun::star::uno::RuntimeException )
130 		{
131 			// read only
132 			(void)aListener;
133 		}
134 
135 		virtual void SAL_CALL
removeChangesListener(const com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> & aListener)136 		removeChangesListener(
137 			const com::sun::star::uno::Reference< com::sun::star::util::XChangesListener >& aListener )
138 			throw( com::sun::star::uno::RuntimeException )
139 		{
140 			// read only
141 			(void)aListener;
142 		}
143 
144 
145 		// XComponent
146 
dispose()147 		virtual void SAL_CALL dispose( )
148 			throw( com::sun::star::uno::RuntimeException )
149 		{
150 		}
151 
addEventListener(const com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> & xListener)152 		virtual void SAL_CALL addEventListener(
153 			const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& xListener )
154 			throw( com::sun::star::uno::RuntimeException )
155 		{
156 			(void)xListener;
157 		}
158 
159 		virtual void SAL_CALL
removeEventListener(const com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> & aListener)160 		removeEventListener(
161 			const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& aListener )
162 			throw( com::sun::star::uno::RuntimeException )
163 		{
164 			(void)aListener;
165 		}
166 
167 
168 		// Abstract functions
169 		// XNameAccess
170 
171 		virtual com::sun::star::uno::Any SAL_CALL
172 		getByName( const rtl::OUString& aName )
173 			throw( com::sun::star::container::NoSuchElementException,
174 				   com::sun::star::lang::WrappedTargetException,
175 				   com::sun::star::uno::RuntimeException) = 0;
176 
177 		virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
178 		getElementNames( )
179 			throw( com::sun::star::uno::RuntimeException ) = 0;
180 
181 		virtual sal_Bool SAL_CALL
182 		hasByName( const rtl::OUString& aName )
183 			throw( com::sun::star::uno::RuntimeException ) = 0;
184 
185 
186 		// XHierarchicalNameAccess
187 
188 		virtual com::sun::star::uno::Any SAL_CALL
189 		getByHierarchicalName( const rtl::OUString& aName )
190 			throw( com::sun::star::container::NoSuchElementException,
191 				   com::sun::star::uno::RuntimeException ) = 0;
192 
193 		virtual sal_Bool SAL_CALL
194 		hasByHierarchicalName( const rtl::OUString& aName )
195 			throw( com::sun::star::uno::RuntimeException ) = 0;
196 
197 	}; // end class TVBase
198 
199 
200 
201 
202 
203 	class TVRead
204 		: public TVBase
205 	{
206 		friend class TVChildTarget;
207 
208 	public:
209 		TVRead( const ConfigData& configData,TVDom* tvDom = 0 );
210 
211 		~TVRead();
212 
213 		// XNameAccess
214 
215 		virtual com::sun::star::uno::Any SAL_CALL
216 		getByName( const rtl::OUString& aName )
217 			throw( com::sun::star::container::NoSuchElementException,
218 				   com::sun::star::lang::WrappedTargetException,
219 				   com::sun::star::uno::RuntimeException);
220 
221 		virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
222 		getElementNames( )
223 			throw( com::sun::star::uno::RuntimeException );
224 
225 		virtual sal_Bool SAL_CALL
226 		hasByName( const rtl::OUString& aName )
227 			throw( com::sun::star::uno::RuntimeException );
228 
229 
230 		// XHierarchicalNameAccess
231 
232 		virtual com::sun::star::uno::Any SAL_CALL
233 		getByHierarchicalName( const rtl::OUString& aName )
234 			throw( com::sun::star::container::NoSuchElementException,
235 				   com::sun::star::uno::RuntimeException );
236 
237 		virtual sal_Bool SAL_CALL
238 		hasByHierarchicalName( const rtl::OUString& aName )
239 			throw( com::sun::star::uno::RuntimeException );
240 
241 
242 	private:
243 
244 		rtl::OUString                    Title;
245 		rtl::OUString                    TargetURL;
246 		rtl::Reference< TVChildTarget >  Children;
247 
248 	};  // end class TVRead
249 
250 
251 
252 
253 
254 
255 	class TVChildTarget
256 		: public TVBase
257 	{
258 	public:
259 
260 		TVChildTarget( const ConfigData& configData,TVDom* tvDom );
261 
262 		TVChildTarget( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF );
263 
264 		~TVChildTarget();
265 
266 		virtual com::sun::star::uno::Any SAL_CALL
267 		getByName( const rtl::OUString& aName )
268 			throw( com::sun::star::container::NoSuchElementException,
269 				   com::sun::star::lang::WrappedTargetException,
270 				   com::sun::star::uno::RuntimeException);
271 
272 		virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
273 		getElementNames( )
274 			throw( com::sun::star::uno::RuntimeException );
275 
276 		virtual sal_Bool SAL_CALL
277 		hasByName( const rtl::OUString& aName )
278 			throw( com::sun::star::uno::RuntimeException );
279 
280 
281 		// XHierarchicalNameAccess
282 
283 		virtual com::sun::star::uno::Any SAL_CALL
284 		getByHierarchicalName( const rtl::OUString& aName )
285 			throw( com::sun::star::container::NoSuchElementException,
286 				   com::sun::star::uno::RuntimeException );
287 
288 		virtual sal_Bool SAL_CALL
289 		hasByHierarchicalName( const rtl::OUString& aName )
290 			throw( com::sun::star::uno::RuntimeException );
291 
292 
293 	private:
294 		std::vector< rtl::Reference< TVRead > >   Elements;
295 
296 		ConfigData init(
297 			const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF );
298 
299 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
300 		getConfiguration(
301 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSgr ) const;
302 
303 		::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess >
304 		getHierAccess( const ::com::sun::star::uno::Reference<  ::com::sun::star::lang::XMultiServiceFactory >& sProvider,
305 					   const char* file ) const;
306 
307 	  ::rtl::OUString
308 	  getKey( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess >& xHierAccess,
309 				const char* key ) const;
310 
311 	  sal_Bool
312 	  getBooleanKey(
313 					const ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess >& xHierAccess,
314 					const char* key) const;
315 
316 	  void subst(
317 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSgr,
318 			rtl::OUString& instpath ) const;
319 
320 	};  // end class TVChildTarget
321 
322 
323 	enum IteratorState
324 	{
325 		USER_EXTENSIONS,
326 		SHARED_EXTENSIONS,
327         BUNDLED_EXTENSIONS,
328 		END_REACHED
329 	};
330 
331 	class ExtensionIteratorBase
332 	{
333 	public:
334 		ExtensionIteratorBase( const rtl::OUString& aLanguage );
335 		void init( void );
336 
337 	private:
338 		com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetHelpPackageFromPackage
339 			( const com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
340 			  com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
341 
342 	protected:
343 		com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextUserHelpPackage
344 			( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
345 		com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextSharedHelpPackage
346 			( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
347 		com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetNextBundledHelpPackage
348 			( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >& o_xParentPackageBundle );
349 
350         void implGetLanguageVectorFromPackage( ::std::vector< ::rtl::OUString > &rv,
351 			com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
352 
353 		osl::Mutex																	m_aMutex;
354 		com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >	m_xContext;
355 		com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess >	m_xSFA;
356 
357 		IteratorState																m_eState;
358 		rtl::OUString																m_aLanguage;
359 
360 		com::sun::star::uno::Sequence< com::sun::star::uno::Reference
361 			< com::sun::star::deployment::XPackage > >								m_aUserPackagesSeq;
362 		bool																		m_bUserPackagesLoaded;
363 
364 		com::sun::star::uno::Sequence< com::sun::star::uno::Reference
365 			< com::sun::star::deployment::XPackage > >								m_aSharedPackagesSeq;
366 		bool																		m_bSharedPackagesLoaded;
367 
368         com::sun::star::uno::Sequence< com::sun::star::uno::Reference
369             < com::sun::star::deployment::XPackage > >								m_aBundledPackagesSeq;
370 		bool																		m_bBundledPackagesLoaded;
371 
372 		int																			m_iUserPackage;
373 		int																			m_iSharedPackage;
374         int																			m_iBundledPackage;
375 
376 	}; // end class ExtensionIteratorBase
377 
378 
379 	//===================================================================
380 	class TreeFileIterator : public ExtensionIteratorBase
381 	{
382 	public:
TreeFileIterator(const rtl::OUString & aLanguage)383 		TreeFileIterator( const rtl::OUString& aLanguage )
384 			: ExtensionIteratorBase( aLanguage )
385 		{}
386 
387 		rtl::OUString nextTreeFile( sal_Int32& rnFileSize );
388 
389 	private:
390 		rtl::OUString expandURL( const rtl::OUString& aURL );
391 		rtl::OUString implGetTreeFileFromPackage( sal_Int32& rnFileSize,
392 			com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage );
393 
394 	}; // end class TreeFileIterator
395 
396 
397 }
398 
399 
400 #endif
401