xref: /trunk/main/ucbhelper/source/provider/contentidentifier.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_ucbhelper.hxx"
30 
31 /**************************************************************************
32                                 TODO
33  **************************************************************************
34 
35  *************************************************************************/
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <ucbhelper/contentidentifier.hxx>
38 #include <cppuhelper/typeprovider.hxx>
39 #include <osl/mutex.hxx>
40 
41 using namespace rtl;
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::lang;
44 using namespace com::sun::star::ucb;
45 
46 namespace ucbhelper
47 {
48 
49 //=========================================================================
50 //=========================================================================
51 //
52 // struct ContentIdentifier_Impl.
53 //
54 //=========================================================================
55 //=========================================================================
56 
57 struct ContentIdentifier_Impl
58 {
59     Reference< XMultiServiceFactory > m_xSMgr;
60     OUString                          m_aContentId;
61     OUString                          m_aProviderScheme;
62     osl::Mutex                        m_aMutex;
63 
64     ContentIdentifier_Impl( const Reference< XMultiServiceFactory >& rSMgr,
65                             const OUString& rURL );
66 };
67 
68 //=========================================================================
69 //
70 // ContentIdentifier_Impl Implementation.
71 //
72 //=========================================================================
73 
74 ContentIdentifier_Impl::ContentIdentifier_Impl(
75                   const Reference< XMultiServiceFactory >& rSMgr,
76                   const OUString& rURL )
77 : m_xSMgr( rSMgr )
78 {
79     // Normalize URL scheme ( it's case insensitive ).
80 
81     // The content provider scheme is the part before the first ':'
82     // within the content id.
83     sal_Int32 nPos = rURL.indexOf( ':', 0 );
84     if ( nPos != -1 )
85     {
86         OUString aScheme( rURL.copy( 0, nPos ) );
87         m_aProviderScheme = aScheme.toAsciiLowerCase();
88         m_aContentId = rURL.replaceAt( 0, nPos, aScheme );
89     }
90 }
91 
92 //=========================================================================
93 //
94 // ContentIdentifier Implementation.
95 //
96 //=========================================================================
97 
98 ContentIdentifier::ContentIdentifier(
99                         const Reference< XMultiServiceFactory >& rxSMgr,
100                         const OUString& rURL )
101 {
102     m_pImpl = new ContentIdentifier_Impl( rxSMgr, rURL );
103 }
104 
105 //=========================================================================
106 ContentIdentifier::ContentIdentifier( const OUString& rURL )
107 {
108     m_pImpl = new ContentIdentifier_Impl(
109                     Reference< XMultiServiceFactory >(), rURL );
110 }
111 
112 //=========================================================================
113 // virtual
114 ContentIdentifier::~ContentIdentifier()
115 {
116     delete m_pImpl;
117 }
118 
119 //=========================================================================
120 //
121 // XInterface methods.
122 //
123 //=========================================================================
124 
125 //=========================================================================
126 // virtual
127 void SAL_CALL ContentIdentifier::acquire() throw()
128 {
129     OWeakObject::acquire();
130 }
131 
132 //=========================================================================
133 // virtual
134 void SAL_CALL ContentIdentifier::release() throw()
135 {
136     OWeakObject::release();
137 }
138 
139 //=========================================================================
140 // virtual
141 Any SAL_CALL
142 ContentIdentifier::queryInterface( const Type & rType )
143     throw ( RuntimeException )
144 {
145     Any aRet = cppu::queryInterface( rType,
146                 static_cast< XTypeProvider * >( this ),
147                 static_cast< XContentIdentifier * >( this ) );
148 
149     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
150 }
151 
152 //=========================================================================
153 //
154 // XTypeProvider methods.
155 //
156 //=========================================================================
157 
158 // virtual
159 Sequence< sal_Int8 > SAL_CALL
160 ContentIdentifier::getImplementationId()
161     throw( RuntimeException )
162 {
163     static cppu::OImplementationId* pId = NULL;
164     if ( !pId )
165     {
166         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
167         if ( !pId )
168         {
169             static cppu::OImplementationId id( sal_False );
170             pId = &id;
171         }
172     }
173     return (*pId).getImplementationId();
174 }
175 
176 //=========================================================================
177 // virtual
178 Sequence< com::sun::star::uno::Type > SAL_CALL
179 ContentIdentifier::getTypes()
180     throw( RuntimeException )
181 {
182     static cppu::OTypeCollection* pCollection = NULL;
183     if ( !pCollection )
184     {
185         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
186         if ( !pCollection )
187         {
188             static cppu::OTypeCollection collection(
189                     getCppuType( static_cast<
190                         Reference < XTypeProvider > * >( 0 ) ),
191                     getCppuType( static_cast<
192                         Reference< XContentIdentifier > * >( 0 ) ) );
193             pCollection = &collection;
194         }
195     }
196     return (*pCollection).getTypes();
197 }
198 
199 //=========================================================================
200 //
201 // XContentIdentifier methods.
202 //
203 //=========================================================================
204 
205 // virtual
206 OUString SAL_CALL ContentIdentifier::getContentIdentifier()
207     throw( RuntimeException )
208 {
209     return m_pImpl->m_aContentId;
210 }
211 
212 //=========================================================================
213 // virtual
214 OUString SAL_CALL ContentIdentifier::getContentProviderScheme()
215     throw( RuntimeException )
216 {
217     return m_pImpl->m_aProviderScheme;
218 }
219 
220 } /* namespace ucbhelper */
221 
222