Update ooo320-m1
[ooovba.git] / ucbhelper / source / provider / contentidentifier.cxx
blobc59f3ca466932ba73f3c6db5fa55724ae478a9c7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: contentidentifier.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucbhelper.hxx"
34 /**************************************************************************
35 TODO
36 **************************************************************************
38 *************************************************************************/
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <ucbhelper/contentidentifier.hxx>
41 #include <cppuhelper/typeprovider.hxx>
42 #include <osl/mutex.hxx>
44 using namespace rtl;
45 using namespace com::sun::star::uno;
46 using namespace com::sun::star::lang;
47 using namespace com::sun::star::ucb;
49 namespace ucbhelper
52 //=========================================================================
53 //=========================================================================
55 // struct ContentIdentifier_Impl.
57 //=========================================================================
58 //=========================================================================
60 struct ContentIdentifier_Impl
62 Reference< XMultiServiceFactory > m_xSMgr;
63 OUString m_aContentId;
64 OUString m_aProviderScheme;
65 osl::Mutex m_aMutex;
67 ContentIdentifier_Impl( const Reference< XMultiServiceFactory >& rSMgr,
68 const OUString& rURL );
71 //=========================================================================
73 // ContentIdentifier_Impl Implementation.
75 //=========================================================================
77 ContentIdentifier_Impl::ContentIdentifier_Impl(
78 const Reference< XMultiServiceFactory >& rSMgr,
79 const OUString& rURL )
80 : m_xSMgr( rSMgr )
82 // Normalize URL scheme ( it's case insensitive ).
84 // The content provider scheme is the part before the first ':'
85 // within the content id.
86 sal_Int32 nPos = rURL.indexOf( ':', 0 );
87 if ( nPos != -1 )
89 OUString aScheme( rURL.copy( 0, nPos ) );
90 m_aProviderScheme = aScheme.toAsciiLowerCase();
91 m_aContentId = rURL.replaceAt( 0, nPos, aScheme );
95 //=========================================================================
97 // ContentIdentifier Implementation.
99 //=========================================================================
101 ContentIdentifier::ContentIdentifier(
102 const Reference< XMultiServiceFactory >& rxSMgr,
103 const OUString& rURL )
105 m_pImpl = new ContentIdentifier_Impl( rxSMgr, rURL );
108 //=========================================================================
109 ContentIdentifier::ContentIdentifier( const OUString& rURL )
111 m_pImpl = new ContentIdentifier_Impl(
112 Reference< XMultiServiceFactory >(), rURL );
115 //=========================================================================
116 // virtual
117 ContentIdentifier::~ContentIdentifier()
119 delete m_pImpl;
122 //=========================================================================
124 // XInterface methods.
126 //=========================================================================
128 //=========================================================================
129 // virtual
130 void SAL_CALL ContentIdentifier::acquire() throw()
132 OWeakObject::acquire();
135 //=========================================================================
136 // virtual
137 void SAL_CALL ContentIdentifier::release() throw()
139 OWeakObject::release();
142 //=========================================================================
143 // virtual
144 Any SAL_CALL
145 ContentIdentifier::queryInterface( const Type & rType )
146 throw ( RuntimeException )
148 Any aRet = cppu::queryInterface( rType,
149 static_cast< XTypeProvider * >( this ),
150 static_cast< XContentIdentifier * >( this ) );
152 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
155 //=========================================================================
157 // XTypeProvider methods.
159 //=========================================================================
161 // virtual
162 Sequence< sal_Int8 > SAL_CALL
163 ContentIdentifier::getImplementationId()
164 throw( RuntimeException )
166 static cppu::OImplementationId* pId = NULL;
167 if ( !pId )
169 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
170 if ( !pId )
172 static cppu::OImplementationId id( sal_False );
173 pId = &id;
176 return (*pId).getImplementationId();
179 //=========================================================================
180 // virtual
181 Sequence< com::sun::star::uno::Type > SAL_CALL
182 ContentIdentifier::getTypes()
183 throw( RuntimeException )
185 static cppu::OTypeCollection* pCollection = NULL;
186 if ( !pCollection )
188 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
189 if ( !pCollection )
191 static cppu::OTypeCollection collection(
192 getCppuType( static_cast<
193 Reference < XTypeProvider > * >( 0 ) ),
194 getCppuType( static_cast<
195 Reference< XContentIdentifier > * >( 0 ) ) );
196 pCollection = &collection;
199 return (*pCollection).getTypes();
202 //=========================================================================
204 // XContentIdentifier methods.
206 //=========================================================================
208 // virtual
209 OUString SAL_CALL ContentIdentifier::getContentIdentifier()
210 throw( RuntimeException )
212 return m_pImpl->m_aContentId;
215 //=========================================================================
216 // virtual
217 OUString SAL_CALL ContentIdentifier::getContentProviderScheme()
218 throw( RuntimeException )
220 return m_pImpl->m_aProviderScheme;
223 } /* namespace ucbhelper */