1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * This file is part of OpenOffice.org. 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 11*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 12*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 15*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 16*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 18*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 19*cdf0e10cSrcweir * 20*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 21*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 22*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 23*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 24*cdf0e10cSrcweir * 25*cdf0e10cSrcweir ************************************************************************/ 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir #include "precompiled_ucb.hxx" 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir #include "ucpext_provider.hxx" 30*cdf0e10cSrcweir #include "ucpext_content.hxx" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir /** === begin UNO includes === **/ 33*cdf0e10cSrcweir /** === end UNO includes === **/ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx> 36*cdf0e10cSrcweir #include <osl/diagnose.h> 37*cdf0e10cSrcweir #include <osl/mutex.hxx> 38*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 39*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //...................................................................................................................... 42*cdf0e10cSrcweir namespace ucb { namespace ucp { namespace ext 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir //...................................................................................................................... 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir /** === begin UNO using === **/ 47*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 48*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 49*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 50*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 51*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 52*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 53*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 54*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 55*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 56*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 57*cdf0e10cSrcweir using ::com::sun::star::uno::Type; 58*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory; 59*cdf0e10cSrcweir using ::com::sun::star::ucb::XContentIdentifier; 60*cdf0e10cSrcweir using ::com::sun::star::ucb::IllegalIdentifierException; 61*cdf0e10cSrcweir using ::com::sun::star::ucb::XContent; 62*cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext; 63*cdf0e10cSrcweir /** === end UNO using === **/ 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir //================================================================================================================== 66*cdf0e10cSrcweir //= ContentProvider 67*cdf0e10cSrcweir //================================================================================================================== 68*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 69*cdf0e10cSrcweir ContentProvider::ContentProvider( const Reference< XMultiServiceFactory >& i_rServiceManager ) 70*cdf0e10cSrcweir :ContentProvider_Base( i_rServiceManager ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 75*cdf0e10cSrcweir ContentProvider::~ContentProvider() 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 80*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ContentProvider::getImplementationName_static() throw (RuntimeException) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.ucp.ext.ContentProvider" ) ); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 86*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ContentProvider::getImplementationName() throw (RuntimeException) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir return getImplementationName_static(); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 92*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ContentProvider::getSupportedServiceNames_static( ) throw (RuntimeException) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir Sequence< ::rtl::OUString > aServiceNames(2); 95*cdf0e10cSrcweir aServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.ContentProvider" ) ); 96*cdf0e10cSrcweir aServiceNames[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.ExtensionContentProvider" ) ); 97*cdf0e10cSrcweir return aServiceNames; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 101*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL ContentProvider::getSupportedServiceNames( ) throw (RuntimeException) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir return getSupportedServiceNames_static(); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 107*cdf0e10cSrcweir Reference< XInterface > ContentProvider::Create( const Reference< XComponentContext >& i_rContext ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir const ::comphelper::ComponentContext aContext( i_rContext ); 110*cdf0e10cSrcweir return *( new ContentProvider( aContext.getLegacyServiceFactory() ) ); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 114*cdf0e10cSrcweir ::rtl::OUString ContentProvider::getRootURL() 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.extension://" ) ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 120*cdf0e10cSrcweir ::rtl::OUString ContentProvider::getArtificialNodeContentType() 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.star.extension-content" ) ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 126*cdf0e10cSrcweir namespace 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir void lcl_ensureAndTransfer( ::rtl::OUString& io_rIdentifierFragment, ::rtl::OUStringBuffer& o_rNormalization, const sal_Unicode i_nLeadingChar ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir if ( ( io_rIdentifierFragment.getLength() == 0 ) || ( io_rIdentifierFragment[0] != i_nLeadingChar ) ) 131*cdf0e10cSrcweir throw IllegalIdentifierException(); 132*cdf0e10cSrcweir io_rIdentifierFragment = io_rIdentifierFragment.copy( 1 ); 133*cdf0e10cSrcweir o_rNormalization.append( i_nLeadingChar ); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 138*cdf0e10cSrcweir Reference< XContent > SAL_CALL ContentProvider::queryContent( const Reference< XContentIdentifier >& i_rIdentifier ) 139*cdf0e10cSrcweir throw( IllegalIdentifierException, RuntimeException ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir // Check URL scheme... 142*cdf0e10cSrcweir const ::rtl::OUString sScheme( rtl::OUString::createFromAscii( "vnd.sun.star.extension" ) ); 143*cdf0e10cSrcweir if ( !i_rIdentifier->getContentProviderScheme().equalsIgnoreAsciiCase( sScheme ) ) 144*cdf0e10cSrcweir throw IllegalIdentifierException(); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // normalize the identifier 147*cdf0e10cSrcweir const ::rtl::OUString sIdentifier( i_rIdentifier->getContentIdentifier() ); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir // the scheme needs to be lower-case 150*cdf0e10cSrcweir ::rtl::OUStringBuffer aComposer; 151*cdf0e10cSrcweir aComposer.append( sIdentifier.copy( 0, sScheme.getLength() ).toAsciiLowerCase() ); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // one : is required after the scheme 154*cdf0e10cSrcweir ::rtl::OUString sRemaining( sIdentifier.copy( sScheme.getLength() ) ); 155*cdf0e10cSrcweir lcl_ensureAndTransfer( sRemaining, aComposer, ':' ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // and at least one / 158*cdf0e10cSrcweir lcl_ensureAndTransfer( sRemaining, aComposer, '/' ); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // the normalized form requires one additional /, but we also accept identifiers which don't have it 161*cdf0e10cSrcweir if ( sRemaining.getLength() == 0 ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir // the root content is a special case, it requires /// 164*cdf0e10cSrcweir aComposer.appendAscii( "//" ); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir else 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir if ( sRemaining[0] != '/' ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir aComposer.append( sal_Unicode( '/' ) ); 171*cdf0e10cSrcweir aComposer.append( sRemaining ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir else 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir lcl_ensureAndTransfer( sRemaining, aComposer, '/' ); 176*cdf0e10cSrcweir // by now, we moved "vnd.sun.star.extension://" from the URL to aComposer 177*cdf0e10cSrcweir if ( sRemaining.getLength() == 0 ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir // again, it's the root content, but one / is missing 180*cdf0e10cSrcweir aComposer.append( sal_Unicode( '/' ) ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir else 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir aComposer.append( sRemaining ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir const Reference< XContentIdentifier > xNormalizedIdentifier( new ::ucbhelper::ContentIdentifier( m_xSMgr, aComposer.makeStringAndClear() ) ); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir // check if a content with given id already exists... 193*cdf0e10cSrcweir Reference< XContent > xContent( queryExistingContent( xNormalizedIdentifier ).get() ); 194*cdf0e10cSrcweir if ( xContent.is() ) 195*cdf0e10cSrcweir return xContent; 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir // create a new content 198*cdf0e10cSrcweir xContent = new Content( m_xSMgr, this, xNormalizedIdentifier ); 199*cdf0e10cSrcweir if ( !xContent->getIdentifier().is() ) 200*cdf0e10cSrcweir throw IllegalIdentifierException(); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir registerNewContent( xContent ); 203*cdf0e10cSrcweir return xContent; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //...................................................................................................................... 207*cdf0e10cSrcweir } } } // namespace ucb::ucp::ext 208*cdf0e10cSrcweir //...................................................................................................................... 209