1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: contentidentifier.cxx,v $
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 /**************************************************************************
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>
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::lang
;
47 using namespace com::sun::star::ucb
;
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
;
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
)
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 );
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 //=========================================================================
117 ContentIdentifier::~ContentIdentifier()
122 //=========================================================================
124 // XInterface methods.
126 //=========================================================================
128 //=========================================================================
130 void SAL_CALL
ContentIdentifier::acquire() throw()
132 OWeakObject::acquire();
135 //=========================================================================
137 void SAL_CALL
ContentIdentifier::release() throw()
139 OWeakObject::release();
142 //=========================================================================
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 //=========================================================================
162 Sequence
< sal_Int8
> SAL_CALL
163 ContentIdentifier::getImplementationId()
164 throw( RuntimeException
)
166 static cppu::OImplementationId
* pId
= NULL
;
169 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
172 static cppu::OImplementationId
id( sal_False
);
176 return (*pId
).getImplementationId();
179 //=========================================================================
181 Sequence
< com::sun::star::uno::Type
> SAL_CALL
182 ContentIdentifier::getTypes()
183 throw( RuntimeException
)
185 static cppu::OTypeCollection
* pCollection
= NULL
;
188 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
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 //=========================================================================
209 OUString SAL_CALL
ContentIdentifier::getContentIdentifier()
210 throw( RuntimeException
)
212 return m_pImpl
->m_aContentId
;
215 //=========================================================================
217 OUString SAL_CALL
ContentIdentifier::getContentProviderScheme()
218 throw( RuntimeException
)
220 return m_pImpl
->m_aProviderScheme
;
223 } /* namespace ucbhelper */