23#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
26#include <osl/mutex.hxx>
27#include <rtl/ustrbuf.hxx>
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::XInterface;
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::ucb::XContentIdentifier;
38 using ::com::sun::star::ucb::IllegalIdentifierException;
39 using ::com::sun::star::ucb::XContent;
40 using ::com::sun::star::uno::XComponentContext;
52 ContentProvider::~ContentProvider()
57 OUString SAL_CALL ContentProvider::getImplementationName()
59 return "org.openoffice.comp.ucp.ext.ContentProvider";
63 Sequence< OUString > SAL_CALL ContentProvider::getSupportedServiceNames( )
65 return {
"com.sun.star.ucb.ContentProvider",
"com.sun.star.ucb.ExtensionContentProvider" };
69 OUString ContentProvider::getRootURL()
71 return "vnd.sun.star.extension://";
75 OUString ContentProvider::getArtificialNodeContentType()
77 return "application/vnd.sun.star.extension-content";
83 void lcl_ensureAndTransfer( std::u16string_view& io_rIdentifierFragment, OUStringBuffer& o_rNormalization,
const sal_Unicode i_nLeadingChar )
85 if ( ( io_rIdentifierFragment.empty() ) || ( io_rIdentifierFragment[0] != i_nLeadingChar ) )
86 throw IllegalIdentifierException();
87 io_rIdentifierFragment = io_rIdentifierFragment.substr( 1 );
88 o_rNormalization.append( i_nLeadingChar );
93 Reference< XContent > SAL_CALL ContentProvider::queryContent(
const Reference< XContentIdentifier >& i_rIdentifier )
96 static constexpr OUStringLiteral sScheme( u
"vnd.sun.star.extension" );
97 if ( !i_rIdentifier->getContentProviderScheme().equalsIgnoreAsciiCase( sScheme ) )
98 throw IllegalIdentifierException();
101 const OUString sIdentifier( i_rIdentifier->getContentIdentifier() );
104 OUStringBuffer aComposer( sIdentifier.copy( 0, sScheme.getLength() ).toAsciiLowerCase() );
107 std::u16string_view sRemaining( sIdentifier.subView( sScheme.getLength() ) );
108 lcl_ensureAndTransfer( sRemaining, aComposer,
':' );
111 lcl_ensureAndTransfer( sRemaining, aComposer,
'/' );
114 if ( sRemaining.empty() )
117 aComposer.append(
"//" );
121 if ( sRemaining[0] !=
'/' )
123 aComposer.append( OUString::Concat(
"/") + sRemaining );
127 lcl_ensureAndTransfer( sRemaining, aComposer,
'/' );
129 if ( sRemaining.empty() )
132 aComposer.append(
'/' );
136 aComposer.append( sRemaining );
140 const Reference< XContentIdentifier > xNormalizedIdentifier( new ::ucbhelper::ContentIdentifier( aComposer.makeStringAndClear() ) );
142 ::osl::MutexGuard aGuard(
m_aMutex );
145 Reference< XContent > xContent( queryExistingContent( xNormalizedIdentifier ) );
150 xContent =
new Content( m_xContext,
this, xNormalizedIdentifier );
151 if ( !xContent->getIdentifier().is() )
152 throw IllegalIdentifierException();
154 registerNewContent( xContent );
162extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
164 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
ContentProvider(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
cppu::ImplInheritanceHelper< ::ucbhelper::ContentProviderImplHelper, css::container::XContainerListener, css::lang::XComponent > ContentProvider_Base
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_ext_ContentProvider_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)