1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_ucb.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir /************************************************************************** 32*cdf0e10cSrcweir TODO 33*cdf0e10cSrcweir ************************************************************************** 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir - XInitialization::initialize does not work any longer! 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir *************************************************************************/ 38*cdf0e10cSrcweir #include <osl/diagnose.h> 39*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/util/XOfficeInstallationDirectories.hpp> 43*cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx> 44*cdf0e10cSrcweir #include "hierarchyprovider.hxx" 45*cdf0e10cSrcweir #include "hierarchycontent.hxx" 46*cdf0e10cSrcweir #include "hierarchyuri.hxx" 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include "../inc/urihelper.hxx" 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using namespace com::sun::star; 51*cdf0e10cSrcweir using namespace hierarchy_ucp; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //========================================================================= 54*cdf0e10cSrcweir //========================================================================= 55*cdf0e10cSrcweir // 56*cdf0e10cSrcweir // HierarchyContentProvider Implementation. 57*cdf0e10cSrcweir // 58*cdf0e10cSrcweir //========================================================================= 59*cdf0e10cSrcweir //========================================================================= 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir HierarchyContentProvider::HierarchyContentProvider( 62*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rXSMgr ) 63*cdf0e10cSrcweir : ::ucbhelper::ContentProviderImplHelper( rXSMgr ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir //========================================================================= 68*cdf0e10cSrcweir // virtual 69*cdf0e10cSrcweir HierarchyContentProvider::~HierarchyContentProvider() 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //========================================================================= 74*cdf0e10cSrcweir // 75*cdf0e10cSrcweir // XInterface methods. 76*cdf0e10cSrcweir // 77*cdf0e10cSrcweir //========================================================================= 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir XINTERFACE_IMPL_4( HierarchyContentProvider, 80*cdf0e10cSrcweir lang::XTypeProvider, 81*cdf0e10cSrcweir lang::XServiceInfo, 82*cdf0e10cSrcweir ucb::XContentProvider, 83*cdf0e10cSrcweir lang::XInitialization ); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir //========================================================================= 86*cdf0e10cSrcweir // 87*cdf0e10cSrcweir // XTypeProvider methods. 88*cdf0e10cSrcweir // 89*cdf0e10cSrcweir //========================================================================= 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir XTYPEPROVIDER_IMPL_4( HierarchyContentProvider, 92*cdf0e10cSrcweir lang::XTypeProvider, 93*cdf0e10cSrcweir lang::XServiceInfo, 94*cdf0e10cSrcweir ucb::XContentProvider, 95*cdf0e10cSrcweir lang::XInitialization ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //========================================================================= 98*cdf0e10cSrcweir // 99*cdf0e10cSrcweir // XServiceInfo methods. 100*cdf0e10cSrcweir // 101*cdf0e10cSrcweir //========================================================================= 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir XSERVICEINFO_IMPL_1( HierarchyContentProvider, 104*cdf0e10cSrcweir rtl::OUString::createFromAscii( 105*cdf0e10cSrcweir "com.sun.star.comp.ucb.HierarchyContentProvider" ), 106*cdf0e10cSrcweir rtl::OUString::createFromAscii( 107*cdf0e10cSrcweir HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME ) ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir //========================================================================= 110*cdf0e10cSrcweir // 111*cdf0e10cSrcweir // Service factory implementation. 112*cdf0e10cSrcweir // 113*cdf0e10cSrcweir //========================================================================= 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyContentProvider ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir //========================================================================= 118*cdf0e10cSrcweir // 119*cdf0e10cSrcweir // XContentProvider methods. 120*cdf0e10cSrcweir // 121*cdf0e10cSrcweir //========================================================================= 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir // virtual 124*cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL 125*cdf0e10cSrcweir HierarchyContentProvider::queryContent( 126*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier ) 127*cdf0e10cSrcweir throw( ucb::IllegalIdentifierException, uno::RuntimeException ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir HierarchyUri aUri( Identifier->getContentIdentifier() ); 130*cdf0e10cSrcweir if ( !aUri.isValid() ) 131*cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // Encode URL and create new Id. This may "correct" user-typed-in URL's. 134*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xCanonicId 135*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, 136*cdf0e10cSrcweir ::ucb_impl::urihelper::encodeURI( 137*cdf0e10cSrcweir aUri.getUri() ) ); 138*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // Check, if a content with given id already exists... 141*cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent 142*cdf0e10cSrcweir = queryExistingContent( xCanonicId ).get(); 143*cdf0e10cSrcweir if ( xContent.is() ) 144*cdf0e10cSrcweir return xContent; 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // Create a new content. 147*cdf0e10cSrcweir xContent = HierarchyContent::create( m_xSMgr, this, xCanonicId ); 148*cdf0e10cSrcweir registerNewContent( xContent ); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir if ( xContent.is() && !xContent->getIdentifier().is() ) 151*cdf0e10cSrcweir throw ucb::IllegalIdentifierException(); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir return xContent; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir //========================================================================= 157*cdf0e10cSrcweir // 158*cdf0e10cSrcweir // XInitialization methods. 159*cdf0e10cSrcweir // 160*cdf0e10cSrcweir //========================================================================= 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir // virtual 163*cdf0e10cSrcweir void SAL_CALL HierarchyContentProvider::initialize( 164*cdf0e10cSrcweir const uno::Sequence< uno::Any >& aArguments ) 165*cdf0e10cSrcweir throw( uno::Exception, uno::RuntimeException ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir #if 0 168*cdf0e10cSrcweir if ( aArguments.getLength() > 0 ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir // Extract config provider from service init args. 171*cdf0e10cSrcweir aArguments[ 0 ] >>= m_xConfigProvider; 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir OSL_ENSURE( m_xConfigProvider.is(), 174*cdf0e10cSrcweir "HierarchyContentProvider::initialize - " 175*cdf0e10cSrcweir "No config provider!" ); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir #else 178*cdf0e10cSrcweir if ( aArguments.getLength() > 0 ) 179*cdf0e10cSrcweir OSL_ENSURE( false, 180*cdf0e10cSrcweir "HierarchyContentProvider::initialize : not supported!" ); 181*cdf0e10cSrcweir #endif 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir //========================================================================= 185*cdf0e10cSrcweir // 186*cdf0e10cSrcweir // Non-interface methods. 187*cdf0e10cSrcweir // 188*cdf0e10cSrcweir //========================================================================= 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > 191*cdf0e10cSrcweir HierarchyContentProvider::getConfigProvider( 192*cdf0e10cSrcweir const rtl::OUString & rServiceSpecifier ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 195*cdf0e10cSrcweir ConfigProviderMap::iterator it = m_aConfigProviderMap.find( 196*cdf0e10cSrcweir rServiceSpecifier ); 197*cdf0e10cSrcweir if ( it == m_aConfigProviderMap.end() ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir try 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir ConfigProviderMapEntry aEntry; 202*cdf0e10cSrcweir aEntry.xConfigProvider 203*cdf0e10cSrcweir = uno::Reference< lang::XMultiServiceFactory >( 204*cdf0e10cSrcweir m_xSMgr->createInstance( rServiceSpecifier ), 205*cdf0e10cSrcweir uno::UNO_QUERY ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir if ( aEntry.xConfigProvider.is() ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir m_aConfigProviderMap[ rServiceSpecifier ] = aEntry; 210*cdf0e10cSrcweir return aEntry.xConfigProvider; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir catch ( uno::Exception const & ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir // OSL_ENSURE( sal_False, 216*cdf0e10cSrcweir // "HierarchyContentProvider::getConfigProvider - " 217*cdf0e10cSrcweir // "caught exception!" ); 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir OSL_ENSURE( sal_False, 221*cdf0e10cSrcweir "HierarchyContentProvider::getConfigProvider - " 222*cdf0e10cSrcweir "No config provider!" ); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir return uno::Reference< lang::XMultiServiceFactory >(); 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir return (*it).second.xConfigProvider; 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir //========================================================================= 231*cdf0e10cSrcweir uno::Reference< container::XHierarchicalNameAccess > 232*cdf0e10cSrcweir HierarchyContentProvider::getRootConfigReadNameAccess( 233*cdf0e10cSrcweir const rtl::OUString & rServiceSpecifier ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 236*cdf0e10cSrcweir ConfigProviderMap::iterator it = m_aConfigProviderMap.find( 237*cdf0e10cSrcweir rServiceSpecifier ); 238*cdf0e10cSrcweir if ( it != m_aConfigProviderMap.end() ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir if ( !( (*it).second.xRootReadAccess.is() ) ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir if ( (*it).second.bTriedToGetRootReadAccess ) // #82494# 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir OSL_ENSURE( sal_False, 245*cdf0e10cSrcweir "HierarchyContentProvider::getRootConfigReadNameAccess - " 246*cdf0e10cSrcweir "Unable to read any config data! -> #82494#" ); 247*cdf0e10cSrcweir return uno::Reference< container::XHierarchicalNameAccess >(); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir try 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xConfigProv 253*cdf0e10cSrcweir = getConfigProvider( rServiceSpecifier ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir if ( xConfigProv.is() ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir uno::Sequence< uno::Any > aArguments( 1 ); 258*cdf0e10cSrcweir beans::PropertyValue aProperty; 259*cdf0e10cSrcweir aProperty.Name 260*cdf0e10cSrcweir = rtl::OUString( 261*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); 262*cdf0e10cSrcweir aProperty.Value <<= rtl::OUString(); // root path 263*cdf0e10cSrcweir aArguments[ 0 ] <<= aProperty; 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir (*it).second.bTriedToGetRootReadAccess = true; 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir (*it).second.xRootReadAccess 268*cdf0e10cSrcweir = uno::Reference< container::XHierarchicalNameAccess >( 269*cdf0e10cSrcweir xConfigProv->createInstanceWithArguments( 270*cdf0e10cSrcweir rtl::OUString( 271*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 272*cdf0e10cSrcweir "com.sun.star.ucb." 273*cdf0e10cSrcweir "HierarchyDataReadAccess" ) ), 274*cdf0e10cSrcweir aArguments ), 275*cdf0e10cSrcweir uno::UNO_QUERY ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir throw; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir catch ( uno::Exception const & ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir // createInstance, createInstanceWithArguments 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir OSL_ENSURE( sal_False, 287*cdf0e10cSrcweir "HierarchyContentProvider::getRootConfigReadNameAccess - " 288*cdf0e10cSrcweir "caught Exception!" ); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir return (*it).second.xRootReadAccess; 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir //========================================================================= 297*cdf0e10cSrcweir uno::Reference< util::XOfficeInstallationDirectories > 298*cdf0e10cSrcweir HierarchyContentProvider::getOfficeInstallationDirectories() 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir if ( !m_xOfficeInstDirs.is() ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex ); 303*cdf0e10cSrcweir if ( !m_xOfficeInstDirs.is() ) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir OSL_ENSURE( m_xSMgr.is(), "No service manager!" ); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir uno::Reference< uno::XComponentContext > xCtx; 308*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( 309*cdf0e10cSrcweir m_xSMgr, uno::UNO_QUERY ); 310*cdf0e10cSrcweir if ( xPropSet.is() ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir xPropSet->getPropertyValue( 313*cdf0e10cSrcweir rtl::OUString( 314*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ) 315*cdf0e10cSrcweir >>= xCtx; 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir OSL_ENSURE( xCtx.is(), 319*cdf0e10cSrcweir "Unable to obtain component context from " 320*cdf0e10cSrcweir "service manager!" ); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir if ( xCtx.is() ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir xCtx->getValueByName( 325*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 326*cdf0e10cSrcweir "/singletons/" 327*cdf0e10cSrcweir "com.sun.star.util.theOfficeInstallationDirectories" ) ) ) 328*cdf0e10cSrcweir >>= m_xOfficeInstDirs; 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir // Be silent. singleton only available in an Office environment. 331*cdf0e10cSrcweir // OSL_ENSURE( m_xOfficeInstDirs.is(), 332*cdf0e10cSrcweir // "Unable to obtain office directories singleton!" ); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir return m_xOfficeInstDirs; 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339