fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / ext / ucpext_provider.cxx
blobeb253161b406d2a86bf4dab8029a3c70e1a178a2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ucpext_provider.hxx"
21 #include "ucpext_content.hxx"
23 #include <ucbhelper/contentidentifier.hxx>
24 #include <osl/diagnose.h>
25 #include <osl/mutex.hxx>
26 #include <rtl/ustrbuf.hxx>
29 namespace ucb { namespace ucp { namespace ext
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::XInterface;
35 using ::com::sun::star::uno::UNO_QUERY;
36 using ::com::sun::star::uno::UNO_QUERY_THROW;
37 using ::com::sun::star::uno::UNO_SET_THROW;
38 using ::com::sun::star::uno::Exception;
39 using ::com::sun::star::uno::RuntimeException;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::uno::makeAny;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Type;
44 using ::com::sun::star::lang::XMultiServiceFactory;
45 using ::com::sun::star::ucb::XContentIdentifier;
46 using ::com::sun::star::ucb::IllegalIdentifierException;
47 using ::com::sun::star::ucb::XContent;
48 using ::com::sun::star::uno::XComponentContext;
51 //= ContentProvider
54 ContentProvider::ContentProvider( const Reference< XComponentContext >& rxContext )
55 :ContentProvider_Base( rxContext )
60 ContentProvider::~ContentProvider()
65 OUString SAL_CALL ContentProvider::getImplementationName_static() throw (RuntimeException)
67 return OUString( "org.openoffice.comp.ucp.ext.ContentProvider" );
71 OUString SAL_CALL ContentProvider::getImplementationName() throw (RuntimeException, std::exception)
73 return getImplementationName_static();
77 Sequence< OUString > SAL_CALL ContentProvider::getSupportedServiceNames_static( ) throw (RuntimeException)
79 Sequence< OUString > aServiceNames(2);
80 aServiceNames[0] = "com.sun.star.ucb.ContentProvider";
81 aServiceNames[1] = "com.sun.star.ucb.ExtensionContentProvider";
82 return aServiceNames;
86 Sequence< OUString > SAL_CALL ContentProvider::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
88 return getSupportedServiceNames_static();
92 Reference< XInterface > ContentProvider::Create( const Reference< XComponentContext >& i_rContext )
94 return *( new ContentProvider( i_rContext ) );
98 OUString ContentProvider::getRootURL()
100 return OUString( "vnd.sun.star.extension://" );
104 OUString ContentProvider::getArtificialNodeContentType()
106 return OUString( "application/vnd.sun.star.extension-content" );
110 namespace
112 void lcl_ensureAndTransfer( OUString& io_rIdentifierFragment, OUStringBuffer& o_rNormalization, const sal_Unicode i_nLeadingChar )
114 if ( ( io_rIdentifierFragment.isEmpty() ) || ( io_rIdentifierFragment[0] != i_nLeadingChar ) )
115 throw IllegalIdentifierException();
116 io_rIdentifierFragment = io_rIdentifierFragment.copy( 1 );
117 o_rNormalization.append( i_nLeadingChar );
122 Reference< XContent > SAL_CALL ContentProvider::queryContent( const Reference< XContentIdentifier >& i_rIdentifier )
123 throw( IllegalIdentifierException, RuntimeException, std::exception )
125 // Check URL scheme...
126 const OUString sScheme( "vnd.sun.star.extension" );
127 if ( !i_rIdentifier->getContentProviderScheme().equalsIgnoreAsciiCase( sScheme ) )
128 throw IllegalIdentifierException();
130 // normalize the identifier
131 const OUString sIdentifier( i_rIdentifier->getContentIdentifier() );
133 // the scheme needs to be lower-case
134 OUStringBuffer aComposer;
135 aComposer.append( sIdentifier.copy( 0, sScheme.getLength() ).toAsciiLowerCase() );
137 // one : is required after the scheme
138 OUString sRemaining( sIdentifier.copy( sScheme.getLength() ) );
139 lcl_ensureAndTransfer( sRemaining, aComposer, ':' );
141 // and at least one /
142 lcl_ensureAndTransfer( sRemaining, aComposer, '/' );
144 // the normalized form requires one additional /, but we also accept identifiers which don't have it
145 if ( sRemaining.isEmpty() )
147 // the root content is a special case, it requires /
148 aComposer.appendAscii( "//" );
150 else
152 if ( sRemaining[0] != '/' )
154 aComposer.append( '/' );
155 aComposer.append( sRemaining );
157 else
159 lcl_ensureAndTransfer( sRemaining, aComposer, '/' );
160 // by now, we moved "vnd.sun.star.extension://" from the URL to aComposer
161 if ( sRemaining.isEmpty() )
163 // again, it's the root content, but one / is missing
164 aComposer.append( '/' );
166 else
168 aComposer.append( sRemaining );
172 const Reference< XContentIdentifier > xNormalizedIdentifier( new ::ucbhelper::ContentIdentifier( aComposer.makeStringAndClear() ) );
174 ::osl::MutexGuard aGuard( m_aMutex );
176 // check if a content with given id already exists...
177 Reference< XContent > xContent( queryExistingContent( xNormalizedIdentifier ).get() );
178 if ( xContent.is() )
179 return xContent;
181 // create a new content
182 xContent = new Content( m_xContext, this, xNormalizedIdentifier );
183 if ( !xContent->getIdentifier().is() )
184 throw IllegalIdentifierException();
186 registerNewContent( xContent );
187 return xContent;
191 } } } // namespace ucb::ucp::ext
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */