1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 /**************************************************************************
23 **************************************************************************
25 *************************************************************************/
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <ucbhelper/contentidentifier.hxx>
28 #include <cppuhelper/typeprovider.hxx>
29 #include <cppuhelper/queryinterface.hxx>
30 #include <osl/mutex.hxx>
32 using namespace com::sun::star::uno
;
33 using namespace com::sun::star::lang
;
34 using namespace com::sun::star::ucb
;
43 // struct ContentIdentifier_Impl.
48 struct ContentIdentifier_Impl
50 OUString m_aContentId
;
51 OUString m_aProviderScheme
;
54 ContentIdentifier_Impl( const OUString
& rURL
);
59 // ContentIdentifier_Impl Implementation.
63 ContentIdentifier_Impl::ContentIdentifier_Impl(const OUString
& rURL
)
65 // Normalize URL scheme ( it's case insensitive ).
67 // The content provider scheme is the part before the first ':'
68 // within the content id.
69 sal_Int32 nPos
= rURL
.indexOf( ':', 0 );
72 OUString
aScheme( rURL
.copy( 0, nPos
) );
73 m_aProviderScheme
= aScheme
.toAsciiLowerCase();
74 m_aContentId
= rURL
.replaceAt( 0, nPos
, aScheme
);
80 // ContentIdentifier Implementation.
84 ContentIdentifier::ContentIdentifier( const OUString
& rURL
)
86 m_pImpl
= new ContentIdentifier_Impl( rURL
);
91 ContentIdentifier::~ContentIdentifier()
98 // XInterface methods.
104 void SAL_CALL
ContentIdentifier::acquire() throw()
106 OWeakObject::acquire();
111 void SAL_CALL
ContentIdentifier::release() throw()
113 OWeakObject::release();
119 ContentIdentifier::queryInterface( const Type
& rType
)
120 throw ( RuntimeException
, std::exception
)
122 Any aRet
= cppu::queryInterface( rType
,
123 static_cast< XTypeProvider
* >( this ),
124 static_cast< XContentIdentifier
* >( this ) );
126 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
131 // XTypeProvider methods.
136 Sequence
< sal_Int8
> SAL_CALL
137 ContentIdentifier::getImplementationId()
138 throw( RuntimeException
, std::exception
)
140 return css::uno::Sequence
<sal_Int8
>();
145 Sequence
< com::sun::star::uno::Type
> SAL_CALL
146 ContentIdentifier::getTypes()
147 throw( RuntimeException
, std::exception
)
149 static cppu::OTypeCollection
* pCollection
= NULL
;
152 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
155 static cppu::OTypeCollection
collection(
156 cppu::UnoType
<XTypeProvider
>::get(),
157 cppu::UnoType
<XContentIdentifier
>::get() );
158 pCollection
= &collection
;
161 return (*pCollection
).getTypes();
166 // XContentIdentifier methods.
171 OUString SAL_CALL
ContentIdentifier::getContentIdentifier()
172 throw( RuntimeException
, std::exception
)
174 return m_pImpl
->m_aContentId
;
179 OUString SAL_CALL
ContentIdentifier::getContentProviderScheme()
180 throw( RuntimeException
, std::exception
)
182 return m_pImpl
->m_aProviderScheme
;
185 } /* namespace ucbhelper */
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */