| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
/************************************************************************** |
| 22 |
TODO |
| 23 |
************************************************************************** |
| 24 |
|
| 25 |
- XInitialization::initialize does not work any longer! |
| 26 |
|
| 27 |
*************************************************************************/ |
| 28 |
#include <osl/diagnose.h> |
| 29 |
#include <com/sun/star/beans/PropertyValue.hpp> |
| 30 |
#include <com/sun/star/container/XHierarchicalNameAccess.hpp> |
| 31 |
#include <com/sun/star/ucb/IllegalIdentifierException.hpp> |
| 32 |
#include <com/sun/star/util/theOfficeInstallationDirectories.hpp> |
| 33 |
#include <cppuhelper/queryinterface.hxx> |
| 34 |
#include <cppuhelper/weak.hxx> |
| 35 |
#include <ucbhelper/contentidentifier.hxx> |
| 36 |
#include <ucbhelper/macros.hxx> |
| 37 |
#include "hierarchyprovider.hxx" |
| 38 |
#include "hierarchycontent.hxx" |
| 39 |
#include "hierarchyuri.hxx" |
| 40 |
|
| 41 |
#include "../inc/urihelper.hxx" |
| 42 |
|
| 43 |
using namespace com::sun::star; |
| 44 |
using namespace hierarchy_ucp; |
| 45 |
|
| 46 |
|
| 47 |
// HierarchyContentProvider Implementation. |
| 48 |
|
| 49 |
|
| 50 |
HierarchyContentProvider::HierarchyContentProvider( |
| 51 |
const uno::Reference< uno::XComponentContext >& rxContext ) |
| 52 |
: HierarchyContentProvider_Base( rxContext ) |
| 53 |
{ |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
// virtual |
| 58 |
HierarchyContentProvider::~HierarchyContentProvider() |
| 59 |
{ |
| 60 |
} |
| 61 |
|
| 62 |
// XServiceInfo methods. |
| 63 |
|
| 64 |
OUString SAL_CALL HierarchyContentProvider::getImplementationName() \ |
| 65 |
{ |
| 66 |
return u"com.sun.star.comp.ucb.HierarchyContentProvider"_ustr; |
| 67 |
} |
| 68 |
sal_Bool SAL_CALL HierarchyContentProvider::supportsService( const OUString& ServiceName ) |
| 69 |
{ |
| 70 |
return cppu::supportsService( this, ServiceName ); |
| 71 |
} |
| 72 |
css::uno::Sequence< OUString > HierarchyContentProvider::getSupportedServiceNames() |
| 73 |
{ |
| 74 |
return { u"com.sun.star.ucb.HierarchyContentProvider"_ustr }; |
| 75 |
} |
| 76 |
|
| 77 |
// Service factory implementation. |
| 78 |
|
| 79 |
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
| 80 |
ucb_HierarchyContentProvider_get_implementation( |
| 81 |
css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) |
| 82 |
{ |
| 83 |
return cppu::acquire(new HierarchyContentProvider(context)); |
| 84 |
} |
| 85 |
|
| 86 |
// XContentProvider methods. |
| 87 |
|
| 88 |
|
| 89 |
// virtual |
| 90 |
uno::Reference< ucb::XContent > SAL_CALL |
| 91 |
HierarchyContentProvider::queryContent( |
| 92 |
const uno::Reference< ucb::XContentIdentifier >& Identifier ) |
| 93 |
{ |
| 94 |
HierarchyUri aUri( Identifier->getContentIdentifier() ); |
| 95 |
if ( !aUri.isValid() ) |
| 96 |
throw ucb::IllegalIdentifierException(); |
| 97 |
|
| 98 |
// Encode URL and create new Id. This may "correct" user-typed-in URL's. |
| 99 |
uno::Reference< ucb::XContentIdentifier > xCanonicId |
| 100 |
= new ::ucbhelper::ContentIdentifier( ::ucb_impl::urihelper::encodeURI( aUri.getUri() ) ); |
| 101 |
osl::MutexGuard aGuard( m_aMutex ); |
| 102 |
|
| 103 |
// Check, if a content with given id already exists... |
| 104 |
uno::Reference< ucb::XContent > xContent |
| 105 |
= queryExistingContent( xCanonicId ); |
| 106 |
if ( xContent.is() ) |
| 107 |
return xContent; |
| 108 |
|
| 109 |
// Create a new content. |
| 110 |
xContent = HierarchyContent::create( m_xContext, this, xCanonicId ); |
| 111 |
registerNewContent( xContent ); |
| 112 |
|
| 113 |
if ( xContent.is() && !xContent->getIdentifier().is() ) |
| 114 |
throw ucb::IllegalIdentifierException(); |
| 115 |
|
| 116 |
return xContent; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
// XInitialization methods. |
| 121 |
|
| 122 |
|
| 123 |
// virtual |
| 124 |
void SAL_CALL HierarchyContentProvider::initialize( |
| 125 |
const uno::Sequence< uno::Any >& aArguments ) |
| 126 |
{ |
| 127 |
if ( aArguments.hasElements() ) |
| 128 |
OSL_FAIL( "HierarchyContentProvider::initialize : not supported!" ); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
// Non-interface methods. |
| 133 |
|
| 134 |
|
| 135 |
uno::Reference< lang::XMultiServiceFactory > |
| 136 |
HierarchyContentProvider::getConfigProvider( |
| 137 |
const OUString & rServiceSpecifier ) |
| 138 |
{ |
| 139 |
osl::MutexGuard aGuard( m_aMutex ); |
| 140 |
ConfigProviderMap::iterator it = m_aConfigProviderMap.find( |
| 141 |
rServiceSpecifier ); |
| 142 |
if ( it == m_aConfigProviderMap.end() ) |
| 143 |
{ |
| 144 |
try |
| 145 |
{ |
| 146 |
ConfigProviderMapEntry aEntry; |
| 147 |
aEntry.xConfigProvider.set( |
| 148 |
m_xContext->getServiceManager()->createInstanceWithContext(rServiceSpecifier, m_xContext), |
| 149 |
uno::UNO_QUERY ); |
| 150 |
|
| 151 |
if ( aEntry.xConfigProvider.is() ) |
| 152 |
{ |
| 153 |
m_aConfigProviderMap[ rServiceSpecifier ] = aEntry; |
| 154 |
return aEntry.xConfigProvider; |
| 155 |
} |
| 156 |
} |
| 157 |
catch ( uno::Exception const & ) |
| 158 |
{ |
| 159 |
// OSL_FAIL( // "HierarchyContentProvider::getConfigProvider - " |
| 160 |
// "caught exception!" ); |
| 161 |
} |
| 162 |
|
| 163 |
OSL_FAIL( "HierarchyContentProvider::getConfigProvider - " |
| 164 |
"No config provider!" ); |
| 165 |
|
| 166 |
return uno::Reference< lang::XMultiServiceFactory >(); |
| 167 |
} |
| 168 |
|
| 169 |
return (*it).second.xConfigProvider; |
| 170 |
} |
| 171 |
|
| 172 |
uno::Reference< container::XHierarchicalNameAccess > |
| 173 |
HierarchyContentProvider::getRootConfigReadNameAccess( |
| 174 |
const OUString & rServiceSpecifier ) |
| 175 |
{ |
| 176 |
osl::MutexGuard aGuard( m_aMutex ); |
| 177 |
ConfigProviderMap::iterator it = m_aConfigProviderMap.find( |
| 178 |
rServiceSpecifier ); |
| 179 |
if (it == m_aConfigProviderMap.end()) |
| 180 |
return uno::Reference< container::XHierarchicalNameAccess >(); |
| 181 |
|
| 182 |
if ( !( (*it).second.xRootReadAccess.is() ) ) |
| 183 |
{ |
| 184 |
if ( (*it).second.bTriedToGetRootReadAccess ) |
| 185 |
{ |
| 186 |
OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - " |
| 187 |
"Unable to read any config data! -> #82494#" ); |
| 188 |
return uno::Reference< container::XHierarchicalNameAccess >(); |
| 189 |
} |
| 190 |
|
| 191 |
try |
| 192 |
{ |
| 193 |
uno::Reference< lang::XMultiServiceFactory > xConfigProv |
| 194 |
= getConfigProvider( rServiceSpecifier ); |
| 195 |
|
| 196 |
if ( xConfigProv.is() ) |
| 197 |
{ |
| 198 |
beans::PropertyValue aProperty; |
| 199 |
aProperty.Name = "nodepath" ; |
| 200 |
aProperty.Value <<= OUString(); // root path |
| 201 |
uno::Sequence< uno::Any > aArguments{ uno::Any(aProperty) }; |
| 202 |
|
| 203 |
(*it).second.bTriedToGetRootReadAccess = true; |
| 204 |
|
| 205 |
(*it).second.xRootReadAccess.set( |
| 206 |
xConfigProv->createInstanceWithArguments( |
| 207 |
u"com.sun.star.ucb.HierarchyDataReadAccess"_ustr, |
| 208 |
aArguments ), |
| 209 |
uno::UNO_QUERY ); |
| 210 |
} |
| 211 |
} |
| 212 |
catch ( uno::RuntimeException const & ) |
| 213 |
{ |
| 214 |
throw; |
| 215 |
} |
| 216 |
catch ( uno::Exception const & ) |
| 217 |
{ |
| 218 |
// createInstance, createInstanceWithArguments |
| 219 |
|
| 220 |
OSL_FAIL( "HierarchyContentProvider::getRootConfigReadNameAccess - " |
| 221 |
"caught Exception!" ); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
return (*it).second.xRootReadAccess; |
| 226 |
} |
| 227 |
|
| 228 |
uno::Reference< util::XOfficeInstallationDirectories > |
| 229 |
HierarchyContentProvider::getOfficeInstallationDirectories() |
| 230 |
{ |
| 231 |
if ( !m_xOfficeInstDirs.is() ) |
| 232 |
{ |
| 233 |
osl::MutexGuard aGuard( m_aMutex ); |
| 234 |
if ( !m_xOfficeInstDirs.is() ) |
| 235 |
{ |
| 236 |
OSL_ENSURE( m_xContext.is(), "No service manager!" ); |
| 237 |
|
| 238 |
m_xOfficeInstDirs = util::theOfficeInstallationDirectories::get(m_xContext); |
| 239 |
} |
| 240 |
} |
| 241 |
return m_xOfficeInstDirs; |
| 242 |
} |
| 243 |
|
| 244 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |