1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ucbhelper/contentidentifier.hxx>
21 #include "webdavprovider.hxx"
22 #include "webdavcontent.hxx"
24 #include "osl/mutex.hxx"
26 using namespace com::sun::star
;
27 using namespace http_dav_ucp
;
29 //=========================================================================
30 //=========================================================================
32 // ContentProvider Implementation.
34 //=========================================================================
35 //=========================================================================
37 ContentProvider::ContentProvider(
38 const uno::Reference
< lang::XMultiServiceFactory
>& rSMgr
)
39 : ::ucbhelper::ContentProviderImplHelper( rSMgr
),
40 m_xDAVSessionFactory( new DAVSessionFactory() ),
45 //=========================================================================
47 ContentProvider::~ContentProvider()
52 //=========================================================================
54 // XInterface methods.
56 //=========================================================================
58 XINTERFACE_IMPL_3( ContentProvider
,
61 ucb::XContentProvider
);
63 //=========================================================================
65 // XTypeProvider methods.
67 //=========================================================================
69 XTYPEPROVIDER_IMPL_3( ContentProvider
,
72 ucb::XContentProvider
);
74 //=========================================================================
76 // XServiceInfo methods.
78 //=========================================================================
80 XSERVICEINFO_IMPL_1( ContentProvider
,
81 OUString::createFromAscii(
82 "com.sun.star.comp.WebDAVContentProvider" ),
83 OUString::createFromAscii(
84 WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
) );
86 //=========================================================================
88 // Service factory implementation.
90 //=========================================================================
92 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider
);
94 //=========================================================================
96 // XContentProvider methods.
98 //=========================================================================
101 uno::Reference
< ucb::XContent
> SAL_CALL
102 ContentProvider::queryContent(
103 const uno::Reference
<
104 ucb::XContentIdentifier
>& Identifier
)
105 throw( ucb::IllegalIdentifierException
,
106 uno::RuntimeException
)
108 // Check URL scheme...
110 const OUString aScheme
111 = Identifier
->getContentProviderScheme().toAsciiLowerCase();
112 if ( aScheme
!= HTTP_URL_SCHEME
&& aScheme
!= HTTPS_URL_SCHEME
&&
113 aScheme
!= WEBDAV_URL_SCHEME
&& aScheme
!= DAV_URL_SCHEME
&&
114 aScheme
!= DAVS_URL_SCHEME
)
115 throw ucb::IllegalIdentifierException();
117 // Normalize URL and create new Id, if nessacary.
118 OUString aURL
= Identifier
->getContentIdentifier();
120 // At least: <scheme> + "://"
121 if ( aURL
.getLength() < ( aScheme
.getLength() + 3 ) )
122 throw ucb::IllegalIdentifierException();
124 if ( ( aURL
.getStr()[ aScheme
.getLength() ] != sal_Unicode( ':' ) ) ||
125 ( aURL
.getStr()[ aScheme
.getLength() + 1 ] != sal_Unicode( '/' ) ) ||
126 ( aURL
.getStr()[ aScheme
.getLength() + 2 ] != sal_Unicode( '/' ) ) )
127 throw ucb::IllegalIdentifierException();
129 uno::Reference
< ucb::XContentIdentifier
> xCanonicId
;
132 if ( aScheme
== WEBDAV_URL_SCHEME
)
134 aURL
= aURL
.replaceAt( 0,
135 WEBDAV_URL_SCHEME_LENGTH
,
136 OUString::createFromAscii(
140 else if ( aScheme
== DAV_URL_SCHEME
)
142 aURL
= aURL
.replaceAt( 0,
143 DAV_URL_SCHEME_LENGTH
,
144 OUString::createFromAscii(
148 else if ( aScheme
== DAVS_URL_SCHEME
)
150 aURL
= aURL
.replaceAt( 0,
151 DAVS_URL_SCHEME_LENGTH
,
152 OUString::createFromAscii(
153 HTTPS_URL_SCHEME
) );
157 sal_Int32 nPos
= aURL
.lastIndexOf( '/' );
158 if ( nPos
!= aURL
.getLength() - 1 )
160 // Find second slash in URL.
161 nPos
= aURL
.indexOf( '/', aURL
.indexOf( '/' ) + 1 );
163 throw ucb::IllegalIdentifierException();
165 nPos
= aURL
.indexOf( '/', nPos
+ 1 );
168 aURL
+= OUString::createFromAscii( "/" );
174 xCanonicId
= new ::ucbhelper::ContentIdentifier( m_xSMgr
, aURL
);
176 xCanonicId
= Identifier
;
178 osl::MutexGuard
aGuard( m_aMutex
);
180 // Check, if a content with given id already exists...
181 uno::Reference
< ucb::XContent
> xContent
182 = queryExistingContent( xCanonicId
).get();
186 // Create a new content.
190 xContent
= new ::http_dav_ucp::Content(
191 m_xSMgr
, this, xCanonicId
, m_xDAVSessionFactory
);
192 registerNewContent( xContent
);
194 catch ( ucb::ContentCreationException
const & )
196 throw ucb::IllegalIdentifierException();
199 if ( !xContent
->getIdentifier().is() )
200 throw ucb::IllegalIdentifierException();
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */