1*ac9096f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ac9096f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ac9096f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ac9096f4SAndrew Rist  * distributed with this work for additional information
6*ac9096f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ac9096f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ac9096f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*ac9096f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ac9096f4SAndrew Rist  *
11*ac9096f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ac9096f4SAndrew Rist  *
13*ac9096f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ac9096f4SAndrew Rist  * software distributed under the License is distributed on an
15*ac9096f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ac9096f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ac9096f4SAndrew Rist  * specific language governing permissions and limitations
18*ac9096f4SAndrew Rist  * under the License.
19*ac9096f4SAndrew Rist  *
20*ac9096f4SAndrew Rist  *************************************************************/
21*ac9096f4SAndrew Rist 
22*ac9096f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucbhelper.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir 								TODO
29cdf0e10cSrcweir  **************************************************************************
30cdf0e10cSrcweir 
31cdf0e10cSrcweir  *************************************************************************/
32cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
34cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
35cdf0e10cSrcweir #include <osl/mutex.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace rtl;
38cdf0e10cSrcweir using namespace com::sun::star::uno;
39cdf0e10cSrcweir using namespace com::sun::star::lang;
40cdf0e10cSrcweir using namespace com::sun::star::ucb;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace ucbhelper
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //=========================================================================
46cdf0e10cSrcweir //=========================================================================
47cdf0e10cSrcweir //
48cdf0e10cSrcweir // struct ContentIdentifier_Impl.
49cdf0e10cSrcweir //
50cdf0e10cSrcweir //=========================================================================
51cdf0e10cSrcweir //=========================================================================
52cdf0e10cSrcweir 
53cdf0e10cSrcweir struct ContentIdentifier_Impl
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	Reference< XMultiServiceFactory > m_xSMgr;
56cdf0e10cSrcweir 	OUString 						  m_aContentId;
57cdf0e10cSrcweir 	OUString 						  m_aProviderScheme;
58cdf0e10cSrcweir 	osl::Mutex						  m_aMutex;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	ContentIdentifier_Impl( const Reference< XMultiServiceFactory >& rSMgr,
61cdf0e10cSrcweir 				  			const OUString& rURL );
62cdf0e10cSrcweir };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //=========================================================================
65cdf0e10cSrcweir //
66cdf0e10cSrcweir // ContentIdentifier_Impl Implementation.
67cdf0e10cSrcweir //
68cdf0e10cSrcweir //=========================================================================
69cdf0e10cSrcweir 
ContentIdentifier_Impl(const Reference<XMultiServiceFactory> & rSMgr,const OUString & rURL)70cdf0e10cSrcweir ContentIdentifier_Impl::ContentIdentifier_Impl(
71cdf0e10cSrcweir 				  const Reference< XMultiServiceFactory >& rSMgr,
72cdf0e10cSrcweir 				  const OUString& rURL )
73cdf0e10cSrcweir : m_xSMgr( rSMgr )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	// Normalize URL scheme ( it's case insensitive ).
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	// The content provider scheme is the part before the first ':'
78cdf0e10cSrcweir 	// within the content id.
79cdf0e10cSrcweir 	sal_Int32 nPos = rURL.indexOf( ':', 0 );
80cdf0e10cSrcweir 	if ( nPos != -1 )
81cdf0e10cSrcweir 	{
82cdf0e10cSrcweir 		OUString aScheme( rURL.copy( 0, nPos ) );
83cdf0e10cSrcweir 		m_aProviderScheme = aScheme.toAsciiLowerCase();
84cdf0e10cSrcweir 		m_aContentId = rURL.replaceAt( 0, nPos, aScheme );
85cdf0e10cSrcweir 	}
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir //=========================================================================
89cdf0e10cSrcweir //
90cdf0e10cSrcweir // ContentIdentifier Implementation.
91cdf0e10cSrcweir //
92cdf0e10cSrcweir //=========================================================================
93cdf0e10cSrcweir 
ContentIdentifier(const Reference<XMultiServiceFactory> & rxSMgr,const OUString & rURL)94cdf0e10cSrcweir ContentIdentifier::ContentIdentifier(
95cdf0e10cSrcweir 						const Reference< XMultiServiceFactory >& rxSMgr,
96cdf0e10cSrcweir 						const OUString& rURL )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	m_pImpl = new ContentIdentifier_Impl( rxSMgr, rURL );
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //=========================================================================
ContentIdentifier(const OUString & rURL)102cdf0e10cSrcweir ContentIdentifier::ContentIdentifier( const OUString& rURL )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	m_pImpl = new ContentIdentifier_Impl(
105cdf0e10cSrcweir 					Reference< XMultiServiceFactory >(), rURL );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir //=========================================================================
109cdf0e10cSrcweir // virtual
~ContentIdentifier()110cdf0e10cSrcweir ContentIdentifier::~ContentIdentifier()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	delete m_pImpl;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir //=========================================================================
116cdf0e10cSrcweir //
117cdf0e10cSrcweir // XInterface methods.
118cdf0e10cSrcweir //
119cdf0e10cSrcweir //=========================================================================
120cdf0e10cSrcweir 
121cdf0e10cSrcweir //=========================================================================
122cdf0e10cSrcweir // virtual
acquire()123cdf0e10cSrcweir void SAL_CALL ContentIdentifier::acquire() throw()
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	OWeakObject::acquire();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir //=========================================================================
129cdf0e10cSrcweir // virtual
release()130cdf0e10cSrcweir void SAL_CALL ContentIdentifier::release() throw()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	OWeakObject::release();
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir //=========================================================================
136cdf0e10cSrcweir // virtual
137cdf0e10cSrcweir Any SAL_CALL
queryInterface(const Type & rType)138cdf0e10cSrcweir ContentIdentifier::queryInterface( const Type & rType )
139cdf0e10cSrcweir 	throw ( RuntimeException )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	Any aRet = cppu::queryInterface( rType,
142cdf0e10cSrcweir 				static_cast< XTypeProvider * >( this ),
143cdf0e10cSrcweir 				static_cast< XContentIdentifier * >( this ) );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir //=========================================================================
149cdf0e10cSrcweir //
150cdf0e10cSrcweir // XTypeProvider methods.
151cdf0e10cSrcweir //
152cdf0e10cSrcweir //=========================================================================
153cdf0e10cSrcweir 
154cdf0e10cSrcweir // virtual
155cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL
getImplementationId()156cdf0e10cSrcweir ContentIdentifier::getImplementationId()
157cdf0e10cSrcweir 	throw( RuntimeException )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	static cppu::OImplementationId* pId = NULL;
160cdf0e10cSrcweir   	if ( !pId )
161cdf0e10cSrcweir   	{
162cdf0e10cSrcweir 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
163cdf0e10cSrcweir 	  	if ( !pId )
164cdf0e10cSrcweir 	  	{
165cdf0e10cSrcweir 		  	static cppu::OImplementationId id( sal_False );
166cdf0e10cSrcweir 		  	pId = &id;
167cdf0e10cSrcweir 	  	}
168cdf0e10cSrcweir   	}
169cdf0e10cSrcweir   	return (*pId).getImplementationId();
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir //=========================================================================
173cdf0e10cSrcweir // virtual
174cdf0e10cSrcweir Sequence< com::sun::star::uno::Type > SAL_CALL
getTypes()175cdf0e10cSrcweir ContentIdentifier::getTypes()
176cdf0e10cSrcweir 	throw( RuntimeException )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	static cppu::OTypeCollection* pCollection = NULL;
179cdf0e10cSrcweir   	if ( !pCollection )
180cdf0e10cSrcweir   	{
181cdf0e10cSrcweir 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
182cdf0e10cSrcweir 		if ( !pCollection )
183cdf0e10cSrcweir 		{
184cdf0e10cSrcweir 			static cppu::OTypeCollection collection(
185cdf0e10cSrcweir 					getCppuType( static_cast<
186cdf0e10cSrcweir 						Reference < XTypeProvider > * >( 0 ) ),
187cdf0e10cSrcweir 					getCppuType( static_cast<
188cdf0e10cSrcweir 						Reference< XContentIdentifier > * >( 0 ) ) );
189cdf0e10cSrcweir 			pCollection = &collection;
190cdf0e10cSrcweir 		}
191cdf0e10cSrcweir 	}
192cdf0e10cSrcweir 	return (*pCollection).getTypes();
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir //=========================================================================
196cdf0e10cSrcweir //
197cdf0e10cSrcweir // XContentIdentifier methods.
198cdf0e10cSrcweir //
199cdf0e10cSrcweir //=========================================================================
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // virtual
getContentIdentifier()202cdf0e10cSrcweir OUString SAL_CALL ContentIdentifier::getContentIdentifier()
203cdf0e10cSrcweir 	throw( RuntimeException )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	return m_pImpl->m_aContentId;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir //=========================================================================
209cdf0e10cSrcweir // virtual
getContentProviderScheme()210cdf0e10cSrcweir OUString SAL_CALL ContentIdentifier::getContentProviderScheme()
211cdf0e10cSrcweir 	throw( RuntimeException )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	return m_pImpl->m_aProviderScheme;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir } /* namespace ucbhelper */
217cdf0e10cSrcweir 
218