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