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 _HIERARCHYDATA_HXX
29 #define _HIERARCHYDATA_HXX
30 
31 #include <rtl/ustring.hxx>
32 #include <osl/mutex.hxx>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 
35 namespace com { namespace sun { namespace star {
36     namespace container {
37         class XHierarchicalNameAccess;
38     }
39     namespace util {
40         class XOfficeInstallationDirectories;
41     }
42 } } }
43 
44 namespace hierarchy_ucp
45 {
46 
47 //=========================================================================
48 
49 class HierarchyEntryData
50 {
51 public:
52     enum Type { NONE, LINK, FOLDER };
53 
54     HierarchyEntryData() : m_aType( NONE ) {}
55     HierarchyEntryData( const Type & rType ) : m_aType( rType ) {}
56 
57     const rtl::OUString & getName() const { return m_aName; }
58     void setName( const rtl::OUString & rName ) { m_aName = rName; }
59 
60     const rtl::OUString & getTitle() const { return m_aTitle; }
61     void setTitle( const rtl::OUString & rTitle ) { m_aTitle = rTitle; }
62 
63     const rtl::OUString & getTargetURL() const { return m_aTargetURL; }
64     void setTargetURL( const rtl::OUString & rURL ) { m_aTargetURL = rURL; }
65 
66     Type getType() const
67     { return ( m_aType != NONE ) ? m_aType
68                                  : m_aTargetURL.getLength()
69                                     ? LINK
70                                     : FOLDER; }
71     void setType( const Type & rType ) { m_aType = rType; }
72 
73 private:
74     rtl::OUString m_aName;      // Name (language independent)
75     rtl::OUString m_aTitle;     // Title (language dependent)
76     rtl::OUString m_aTargetURL; // Target URL ( links only )
77     Type          m_aType;      // Type
78 };
79 
80 //=========================================================================
81 
82 class HierarchyContentProvider;
83 class HierarchyUri;
84 
85 class HierarchyEntry
86 {
87     ::rtl::OUString m_aServiceSpecifier;
88 	::rtl::OUString m_aName;
89 	::rtl::OUString m_aPath;
90 	::osl::Mutex 	m_aMutex;
91 	::com::sun::star::uno::Reference<
92 			::com::sun::star::lang::XMultiServiceFactory > m_xSMgr;
93 	::com::sun::star::uno::Reference<
94 			::com::sun::star::lang::XMultiServiceFactory > m_xConfigProvider;
95 	::com::sun::star::uno::Reference<
96 			::com::sun::star::container::XHierarchicalNameAccess >
97 														   m_xRootReadAccess;
98     ::com::sun::star::uno::Reference<
99             ::com::sun::star::util::XOfficeInstallationDirectories >
100                                                            m_xOfficeInstDirs;
101 	sal_Bool m_bTriedToGetRootReadAccess;  // #82494#
102 
103 private:
104     ::rtl::OUString createPathFromHierarchyURL( const HierarchyUri & rURI );
105 	::com::sun::star::uno::Reference<
106 			::com::sun::star::container::XHierarchicalNameAccess >
107 	getRootReadAccess();
108 
109 public:
110 	HierarchyEntry( const ::com::sun::star::uno::Reference<
111 						::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
112 					HierarchyContentProvider* pProvider,
113 					const ::rtl::OUString& rURL );
114 
115 	sal_Bool hasData();
116 
117 	sal_Bool getData( HierarchyEntryData& rData );
118 
119 	sal_Bool setData( const HierarchyEntryData& rData, sal_Bool bCreate );
120 
121 	sal_Bool move( const ::rtl::OUString& rNewURL,
122 				   const HierarchyEntryData& rData );
123 
124 	sal_Bool remove();
125 
126 	// Iteration.
127 
128 	struct iterator_Impl;
129 
130 	class iterator
131 	{
132 	friend class HierarchyEntry;
133 
134 		iterator_Impl*  m_pImpl;
135 
136 	public:
137 		iterator();
138 		~iterator();
139 
140 		const HierarchyEntryData& operator*() const;
141 	};
142 
143 	sal_Bool first( iterator& it );
144 	sal_Bool next ( iterator& it );
145 };
146 
147 } // namespace hierarchy_ucp
148 
149 #endif /* !_HIERARCHYDATA_HXX */
150