Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / ext / ucpext_provider.cxx
blob8da160067d7709919c71abfa55e4ce7d6b270b72
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
29 #include "ucpext_provider.hxx"
30 #include "ucpext_content.hxx"
32 /** === begin UNO includes === **/
33 /** === end UNO includes === **/
35 #include <ucbhelper/contentidentifier.hxx>
36 #include <osl/diagnose.h>
37 #include <osl/mutex.hxx>
38 #include <comphelper/componentcontext.hxx>
39 #include <rtl/ustrbuf.hxx>
41 //......................................................................................................................
42 namespace ucb { namespace ucp { namespace ext
44 //......................................................................................................................
46 /** === begin UNO using === **/
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::uno::XInterface;
49 using ::com::sun::star::uno::UNO_QUERY;
50 using ::com::sun::star::uno::UNO_QUERY_THROW;
51 using ::com::sun::star::uno::UNO_SET_THROW;
52 using ::com::sun::star::uno::Exception;
53 using ::com::sun::star::uno::RuntimeException;
54 using ::com::sun::star::uno::Any;
55 using ::com::sun::star::uno::makeAny;
56 using ::com::sun::star::uno::Sequence;
57 using ::com::sun::star::uno::Type;
58 using ::com::sun::star::lang::XMultiServiceFactory;
59 using ::com::sun::star::ucb::XContentIdentifier;
60 using ::com::sun::star::ucb::IllegalIdentifierException;
61 using ::com::sun::star::ucb::XContent;
62 using ::com::sun::star::uno::XComponentContext;
63 /** === end UNO using === **/
65 //==================================================================================================================
66 //= ContentProvider
67 //==================================================================================================================
68 //------------------------------------------------------------------------------------------------------------------
69 ContentProvider::ContentProvider( const Reference< XMultiServiceFactory >& i_rServiceManager )
70 :ContentProvider_Base( i_rServiceManager )
74 //------------------------------------------------------------------------------------------------------------------
75 ContentProvider::~ContentProvider()
79 //------------------------------------------------------------------------------------------------------------------
80 ::rtl::OUString SAL_CALL ContentProvider::getImplementationName_static() throw (RuntimeException)
82 return ::rtl::OUString( "org.openoffice.comp.ucp.ext.ContentProvider" );
85 //------------------------------------------------------------------------------------------------------------------
86 ::rtl::OUString SAL_CALL ContentProvider::getImplementationName() throw (RuntimeException)
88 return getImplementationName_static();
91 //------------------------------------------------------------------------------------------------------------------
92 Sequence< ::rtl::OUString > SAL_CALL ContentProvider::getSupportedServiceNames_static( ) throw (RuntimeException)
94 Sequence< ::rtl::OUString > aServiceNames(2);
95 aServiceNames[0] = ::rtl::OUString( "com.sun.star.ucb.ContentProvider" );
96 aServiceNames[1] = ::rtl::OUString( "com.sun.star.ucb.ExtensionContentProvider" );
97 return aServiceNames;
100 //------------------------------------------------------------------------------------------------------------------
101 Sequence< ::rtl::OUString > SAL_CALL ContentProvider::getSupportedServiceNames( ) throw (RuntimeException)
103 return getSupportedServiceNames_static();
106 //------------------------------------------------------------------------------------------------------------------
107 Reference< XInterface > ContentProvider::Create( const Reference< XComponentContext >& i_rContext )
109 const ::comphelper::ComponentContext aContext( i_rContext );
110 return *( new ContentProvider( aContext.getLegacyServiceFactory() ) );
113 //------------------------------------------------------------------------------------------------------------------
114 ::rtl::OUString ContentProvider::getRootURL()
116 return ::rtl::OUString( "vnd.sun.star.extension://" );
119 //------------------------------------------------------------------------------------------------------------------
120 ::rtl::OUString ContentProvider::getArtificialNodeContentType()
122 return ::rtl::OUString( "application/vnd.sun.star.extension-content" );
125 //------------------------------------------------------------------------------------------------------------------
126 namespace
128 void lcl_ensureAndTransfer( ::rtl::OUString& io_rIdentifierFragment, ::rtl::OUStringBuffer& o_rNormalization, const sal_Unicode i_nLeadingChar )
130 if ( ( io_rIdentifierFragment.isEmpty() ) || ( io_rIdentifierFragment[0] != i_nLeadingChar ) )
131 throw IllegalIdentifierException();
132 io_rIdentifierFragment = io_rIdentifierFragment.copy( 1 );
133 o_rNormalization.append( i_nLeadingChar );
137 //------------------------------------------------------------------------------------------------------------------
138 Reference< XContent > SAL_CALL ContentProvider::queryContent( const Reference< XContentIdentifier >& i_rIdentifier )
139 throw( IllegalIdentifierException, RuntimeException )
141 // Check URL scheme...
142 const ::rtl::OUString sScheme( "vnd.sun.star.extension" );
143 if ( !i_rIdentifier->getContentProviderScheme().equalsIgnoreAsciiCase( sScheme ) )
144 throw IllegalIdentifierException();
146 // normalize the identifier
147 const ::rtl::OUString sIdentifier( i_rIdentifier->getContentIdentifier() );
149 // the scheme needs to be lower-case
150 ::rtl::OUStringBuffer aComposer;
151 aComposer.append( sIdentifier.copy( 0, sScheme.getLength() ).toAsciiLowerCase() );
153 // one : is required after the scheme
154 ::rtl::OUString sRemaining( sIdentifier.copy( sScheme.getLength() ) );
155 lcl_ensureAndTransfer( sRemaining, aComposer, ':' );
157 // and at least one /
158 lcl_ensureAndTransfer( sRemaining, aComposer, '/' );
160 // the normalized form requires one additional /, but we also accept identifiers which don't have it
161 if ( sRemaining.isEmpty() )
163 // the root content is a special case, it requires ///
164 aComposer.appendAscii( "//" );
166 else
168 if ( sRemaining[0] != '/' )
170 aComposer.append( sal_Unicode( '/' ) );
171 aComposer.append( sRemaining );
173 else
175 lcl_ensureAndTransfer( sRemaining, aComposer, '/' );
176 // by now, we moved "vnd.sun.star.extension://" from the URL to aComposer
177 if ( sRemaining.isEmpty() )
179 // again, it's the root content, but one / is missing
180 aComposer.append( sal_Unicode( '/' ) );
182 else
184 aComposer.append( sRemaining );
188 const Reference< XContentIdentifier > xNormalizedIdentifier( new ::ucbhelper::ContentIdentifier( m_xSMgr, aComposer.makeStringAndClear() ) );
190 ::osl::MutexGuard aGuard( m_aMutex );
192 // check if a content with given id already exists...
193 Reference< XContent > xContent( queryExistingContent( xNormalizedIdentifier ).get() );
194 if ( xContent.is() )
195 return xContent;
197 // create a new content
198 xContent = new Content( m_xSMgr, this, xNormalizedIdentifier );
199 if ( !xContent->getIdentifier().is() )
200 throw IllegalIdentifierException();
202 registerNewContent( xContent );
203 return xContent;
206 //......................................................................................................................
207 } } } // namespace ucb::ucp::ext
208 //......................................................................................................................
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */