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 { 140 Any aRet = cppu::queryInterface( rType, 141 static_cast< XTypeProvider * >( this ), 142 static_cast< XContentIdentifier * >( this ) ); 143 144 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); 145 } 146 147 //========================================================================= 148 // 149 // XTypeProvider methods. 150 // 151 //========================================================================= 152 153 // virtual 154 Sequence< sal_Int8 > SAL_CALL 155 ContentIdentifier::getImplementationId() 156 { 157 static cppu::OImplementationId* pId = NULL; 158 if ( !pId ) 159 { 160 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 161 if ( !pId ) 162 { 163 static cppu::OImplementationId id( sal_False ); 164 pId = &id; 165 } 166 } 167 return (*pId).getImplementationId(); 168 } 169 170 //========================================================================= 171 // virtual 172 Sequence< com::sun::star::uno::Type > SAL_CALL 173 ContentIdentifier::getTypes() 174 { 175 static cppu::OTypeCollection* pCollection = NULL; 176 if ( !pCollection ) 177 { 178 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 179 if ( !pCollection ) 180 { 181 static cppu::OTypeCollection collection( 182 getCppuType( static_cast< 183 Reference < XTypeProvider > * >( 0 ) ), 184 getCppuType( static_cast< 185 Reference< XContentIdentifier > * >( 0 ) ) ); 186 pCollection = &collection; 187 } 188 } 189 return (*pCollection).getTypes(); 190 } 191 192 //========================================================================= 193 // 194 // XContentIdentifier methods. 195 // 196 //========================================================================= 197 198 // virtual 199 OUString SAL_CALL ContentIdentifier::getContentIdentifier() 200 { 201 return m_pImpl->m_aContentId; 202 } 203 204 //========================================================================= 205 // virtual 206 OUString SAL_CALL ContentIdentifier::getContentProviderScheme() 207 { 208 return m_pImpl->m_aProviderScheme; 209 } 210 211 } /* namespace ucbhelper */ 212