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