1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 /**************************************************************************
32 **************************************************************************
34 *************************************************************************/
35 #include <comphelper/processfactory.hxx>
36 #include <ucbhelper/contentidentifier.hxx>
37 #include "webdavprovider.hxx"
38 #include "webdavcontent.hxx"
40 #include "osl/mutex.hxx"
42 using namespace com::sun::star
;
43 using namespace webdav_ucp
;
48 // ContentProvider Implementation.
53 ContentProvider::ContentProvider(
54 const uno::Reference
< uno::XComponentContext
>& rxContext
)
55 : ::ucbhelper::ContentProviderImplHelper( rxContext
),
56 m_xDAVSessionFactory( new DAVSessionFactory() ),
63 ContentProvider::~ContentProvider()
70 // XInterface methods.
72 void SAL_CALL
ContentProvider::acquire()
75 OWeakObject::acquire();
78 void SAL_CALL
ContentProvider::release()
81 OWeakObject::release();
84 css::uno::Any SAL_CALL
ContentProvider::queryInterface( const css::uno::Type
& rType
)
85 throw( css::uno::RuntimeException
, std::exception
)
87 css::uno::Any aRet
= cppu::queryInterface( rType
,
88 (static_cast< lang::XTypeProvider
* >(this)),
89 (static_cast< lang::XServiceInfo
* >(this)),
90 (static_cast< ucb::XContentProvider
* >(this))
92 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
95 // XTypeProvider methods.
99 XTYPEPROVIDER_IMPL_3( ContentProvider
,
102 ucb::XContentProvider
);
106 // XServiceInfo methods.
110 XSERVICEINFO_IMPL_1_CTX( ContentProvider
,
111 OUString( "com.sun.star.comp.WebDAVContentProvider" ),
112 WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
);
116 // Service factory implementation.
120 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider
);
124 // XContentProvider methods.
129 uno::Reference
< ucb::XContent
> SAL_CALL
130 ContentProvider::queryContent(
131 const uno::Reference
<
132 ucb::XContentIdentifier
>& Identifier
)
133 throw( ucb::IllegalIdentifierException
,
134 uno::RuntimeException
, std::exception
)
136 // Check URL scheme...
138 const OUString aScheme
139 = Identifier
->getContentProviderScheme().toAsciiLowerCase();
140 if ( aScheme
!= HTTP_URL_SCHEME
&& aScheme
!= HTTPS_URL_SCHEME
&& aScheme
!= WEBDAV_URL_SCHEME
141 && aScheme
!= DAV_URL_SCHEME
&& aScheme
!= DAVS_URL_SCHEME
&& aScheme
!= FTP_URL_SCHEME
)
142 throw ucb::IllegalIdentifierException();
144 // Normalize URL and create new Id, if nessacary.
145 OUString aURL
= Identifier
->getContentIdentifier();
147 // At least: <scheme> + "://"
148 if ( aURL
.getLength() < ( aScheme
.getLength() + 3 ) )
149 throw ucb::IllegalIdentifierException();
151 if ( aURL
.copy( aScheme
.getLength(), 3 ) != "://" )
152 throw ucb::IllegalIdentifierException();
154 uno::Reference
< ucb::XContentIdentifier
> xCanonicId
;
157 if ( aScheme
== WEBDAV_URL_SCHEME
)
159 aURL
= aURL
.replaceAt( 0,
160 WEBDAV_URL_SCHEME_LENGTH
,
161 OUString( HTTP_URL_SCHEME
) );
164 else if ( aScheme
== DAV_URL_SCHEME
)
166 aURL
= aURL
.replaceAt( 0,
167 DAV_URL_SCHEME_LENGTH
,
168 OUString( HTTP_URL_SCHEME
) );
171 else if ( aScheme
== DAVS_URL_SCHEME
)
173 aURL
= aURL
.replaceAt( 0,
174 DAVS_URL_SCHEME_LENGTH
,
175 OUString( HTTPS_URL_SCHEME
) );
179 sal_Int32 nPos
= aURL
.lastIndexOf( '/' );
180 if ( nPos
!= aURL
.getLength() - 1 )
182 // Find second slash in URL.
183 nPos
= aURL
.indexOf( '/', aURL
.indexOf( '/' ) + 1 );
185 throw ucb::IllegalIdentifierException();
187 nPos
= aURL
.indexOf( '/', nPos
+ 1 );
196 xCanonicId
= new ::ucbhelper::ContentIdentifier( aURL
);
198 xCanonicId
= Identifier
;
200 osl::MutexGuard
aGuard( m_aMutex
);
202 // Check, if a content with given id already exists...
203 uno::Reference
< ucb::XContent
> xContent
204 = queryExistingContent( xCanonicId
).get();
208 // Create a new content.
212 xContent
= new ::webdav_ucp::Content(
213 m_xContext
, this, xCanonicId
, m_xDAVSessionFactory
);
214 registerNewContent( xContent
);
216 catch ( ucb::ContentCreationException
const & )
218 throw ucb::IllegalIdentifierException();
221 if ( !xContent
->getIdentifier().is() )
222 throw ucb::IllegalIdentifierException();
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */