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