xref: /trunk/main/ucb/source/ucp/hierarchy/hierarchyprovider.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 _HIERARCHYPROVIDER_HXX
29 #define _HIERARCHYPROVIDER_HXX
30 
31 #include <hash_map>
32 #include <ucbhelper/providerhelper.hxx>
33 #include <com/sun/star/lang/XInitialization.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 #define HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME \
49                 "com.sun.star.ucb.HierarchyContentProvider"
50 #define HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME_LENGTH  41
51 
52 #define HIERARCHY_URL_SCHEME \
53                 "vnd.sun.star.hier"
54 #define HIERARCHY_URL_SCHEME_LENGTH 17
55 
56 #define HIERARCHY_FOLDER_CONTENT_TYPE \
57                 "application/" HIERARCHY_URL_SCHEME "-folder"
58 #define HIERARCHY_LINK_CONTENT_TYPE \
59                 "application/" HIERARCHY_URL_SCHEME "-link"
60 
61 //=========================================================================
62 
63 struct ConfigProviderMapEntry
64 {
65     com::sun::star::uno::Reference<
66         com::sun::star::lang::XMultiServiceFactory > xConfigProvider;
67     com::sun::star::uno::Reference<
68         com::sun::star::container::XHierarchicalNameAccess > xRootReadAccess;
69     bool bTriedToGetRootReadAccess;  // #82494#
70 
71     ConfigProviderMapEntry() : bTriedToGetRootReadAccess( false ) {}
72 };
73 
74 struct equalString
75 {
76     bool operator()(
77         const rtl::OUString& rKey1, const rtl::OUString& rKey2 ) const
78     {
79         return !!( rKey1 == rKey2 );
80     }
81 };
82 
83 struct hashString
84 {
85     size_t operator()( const rtl::OUString & rName ) const
86     {
87         return rName.hashCode();
88     }
89 };
90 
91 typedef std::hash_map
92 <
93     rtl::OUString,  // servcie specifier
94     ConfigProviderMapEntry,
95     hashString,
96     equalString
97 >
98 ConfigProviderMap;
99 
100 //=========================================================================
101 
102 class HierarchyContentProvider : public ::ucbhelper::ContentProviderImplHelper,
103                                  public com::sun::star::lang::XInitialization
104 {
105     ConfigProviderMap   m_aConfigProviderMap;
106     com::sun::star::uno::Reference<
107         com::sun::star::util::XOfficeInstallationDirectories > m_xOfficeInstDirs;
108 
109 public:
110     HierarchyContentProvider(
111                 const com::sun::star::uno::Reference<
112                     com::sun::star::lang::XMultiServiceFactory >& rXSMgr );
113     virtual ~HierarchyContentProvider();
114 
115     // XInterface
116     XINTERFACE_DECL()
117 
118     // XTypeProvider
119     XTYPEPROVIDER_DECL()
120 
121     // XServiceInfo
122     XSERVICEINFO_DECL()
123 
124     // XContentProvider
125     virtual com::sun::star::uno::Reference<
126                 com::sun::star::ucb::XContent > SAL_CALL
127     queryContent( const com::sun::star::uno::Reference<
128                     com::sun::star::ucb::XContentIdentifier >& Identifier )
129         throw( com::sun::star::ucb::IllegalIdentifierException,
130                com::sun::star::uno::RuntimeException );
131 
132     // XInitialization
133     virtual void SAL_CALL
134     initialize( const ::com::sun::star::uno::Sequence<
135                         ::com::sun::star::uno::Any >& aArguments )
136         throw( ::com::sun::star::uno::Exception,
137                ::com::sun::star::uno::RuntimeException );
138 
139     // Non-Interface methods
140     com::sun::star::uno::Reference<
141         com::sun::star::lang::XMultiServiceFactory >
142     getConfigProvider( const rtl::OUString & rServiceSpecifier );
143     com::sun::star::uno::Reference<
144         com::sun::star::container::XHierarchicalNameAccess >
145     getRootConfigReadNameAccess( const rtl::OUString & rServiceSpecifier );
146 
147     // Note: may retrun an empty reference.
148     com::sun::star::uno::Reference<
149         com::sun::star::util::XOfficeInstallationDirectories >
150     getOfficeInstallationDirectories();
151 };
152 
153 } // namespace hierarchy_ucp
154 
155 #endif /* !_HIERARCHYPROVIDER_HXX */
156