1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: webdavprovider.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 /**************************************************************************
36 **************************************************************************
38 *************************************************************************/
42 #include <ucbhelper/contentidentifier.hxx>
43 #include "webdavprovider.hxx"
44 #include "webdavcontent.hxx"
46 #include "osl/mutex.hxx"
48 using namespace com::sun::star
;
49 using namespace webdav_ucp
;
51 //=========================================================================
52 //=========================================================================
54 // ContentProvider Implementation.
56 //=========================================================================
57 //=========================================================================
59 ContentProvider::ContentProvider(
60 const uno::Reference
< lang::XMultiServiceFactory
>& rSMgr
)
61 : ::ucbhelper::ContentProviderImplHelper( rSMgr
),
62 m_xDAVSessionFactory( new DAVSessionFactory() ),
67 //=========================================================================
69 ContentProvider::~ContentProvider()
74 //=========================================================================
76 // XInterface methods.
78 //=========================================================================
80 XINTERFACE_IMPL_3( ContentProvider
,
83 ucb::XContentProvider
);
85 //=========================================================================
87 // XTypeProvider methods.
89 //=========================================================================
91 XTYPEPROVIDER_IMPL_3( ContentProvider
,
94 ucb::XContentProvider
);
96 //=========================================================================
98 // XServiceInfo methods.
100 //=========================================================================
102 XSERVICEINFO_IMPL_1( ContentProvider
,
103 rtl::OUString::createFromAscii(
104 "com.sun.star.comp.WebDAVContentProvider" ),
105 rtl::OUString::createFromAscii(
106 WEBDAV_CONTENT_PROVIDER_SERVICE_NAME
) );
108 //=========================================================================
110 // Service factory implementation.
112 //=========================================================================
114 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider
);
116 //=========================================================================
118 // XContentProvider methods.
120 //=========================================================================
123 uno::Reference
< ucb::XContent
> SAL_CALL
124 ContentProvider::queryContent(
125 const uno::Reference
<
126 ucb::XContentIdentifier
>& Identifier
)
127 throw( ucb::IllegalIdentifierException
,
128 uno::RuntimeException
)
130 // Check URL scheme...
132 const rtl::OUString aScheme
133 = Identifier
->getContentProviderScheme().toAsciiLowerCase();
134 if ( !aScheme
.equalsAsciiL(
135 RTL_CONSTASCII_STRINGPARAM( HTTP_URL_SCHEME
) ) &&
136 !aScheme
.equalsAsciiL(
137 RTL_CONSTASCII_STRINGPARAM( HTTPS_URL_SCHEME
) ) &&
138 !aScheme
.equalsAsciiL(
139 RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME
) ) &&
140 !aScheme
.equalsAsciiL(
141 RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME
) ) &&
142 !aScheme
.equalsAsciiL(
143 RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME
) ) &&
144 !aScheme
.equalsAsciiL(
145 RTL_CONSTASCII_STRINGPARAM( PLAIN_WEBDAV_URL_SCHEME
) ) &&
146 !aScheme
.equalsAsciiL(
147 RTL_CONSTASCII_STRINGPARAM( PLAIN_WEBDAVS_URL_SCHEME
) ) &&
148 !aScheme
.equalsAsciiL(
149 RTL_CONSTASCII_STRINGPARAM( FTP_URL_SCHEME
) ) )
150 throw ucb::IllegalIdentifierException();
152 // Normalize URL and create new Id, if nessacary.
153 rtl::OUString aURL
= Identifier
->getContentIdentifier();
155 // At least: <scheme> + "://"
156 if ( aURL
.getLength() < ( aScheme
.getLength() + 3 ) )
157 throw ucb::IllegalIdentifierException();
159 if ( ( aURL
.getStr()[ aScheme
.getLength() ] != sal_Unicode( ':' ) ) ||
160 ( aURL
.getStr()[ aScheme
.getLength() + 1 ] != sal_Unicode( '/' ) ) ||
161 ( aURL
.getStr()[ aScheme
.getLength() + 2 ] != sal_Unicode( '/' ) ) )
162 throw ucb::IllegalIdentifierException();
164 uno::Reference
< ucb::XContentIdentifier
> xCanonicId
;
170 } const *pScheme
, pReplace
[] = {
171 { WEBDAV_URL_SCHEME
, HTTP_URL_SCHEME
},
172 { DAV_URL_SCHEME
, HTTP_URL_SCHEME
},
173 { DAVS_URL_SCHEME
, HTTPS_URL_SCHEME
},
174 { PLAIN_WEBDAV_URL_SCHEME
, HTTP_URL_SCHEME
},
175 { PLAIN_WEBDAVS_URL_SCHEME
, HTTPS_URL_SCHEME
},
178 for ( pScheme
= pReplace
; pScheme
->from
; ++pScheme
)
180 if ( aScheme
.equalsAscii( pScheme
->from
) )
182 aURL
= aURL
.replaceAt( 0,
183 strlen( pScheme
->from
),
184 rtl::OUString::createFromAscii( pScheme
->to
) );
190 sal_Int32 nPos
= aURL
.lastIndexOf( '/' );
191 if ( nPos
!= aURL
.getLength() - 1 )
193 // Find second slash in URL.
194 nPos
= aURL
.indexOf( '/', aURL
.indexOf( '/' ) + 1 );
196 throw ucb::IllegalIdentifierException();
198 nPos
= aURL
.indexOf( '/', nPos
+ 1 );
201 aURL
+= rtl::OUString::createFromAscii( "/" );
207 xCanonicId
= new ::ucbhelper::ContentIdentifier( m_xSMgr
, aURL
);
209 xCanonicId
= Identifier
;
211 #if OSL_DEBUG_LEVEL > 0
212 fprintf( stderr
, "ContentProvider::queryContent(): bNewId=%s, xCanonicId=%s\n",
213 bNewId
? "YES" : "NO",
214 rtl::OUStringToOString( xCanonicId
->getContentIdentifier(), RTL_TEXTENCODING_UTF8
).getStr() );
217 osl::MutexGuard
aGuard( m_aMutex
);
219 // Check, if a content with given id already exists...
220 uno::Reference
< ucb::XContent
> xContent
221 = queryExistingContent( xCanonicId
).get();
225 // Create a new content.
229 xContent
= new ::webdav_ucp::Content(
230 m_xSMgr
, this, xCanonicId
, m_xDAVSessionFactory
);
231 registerNewContent( xContent
);
233 catch ( ucb::ContentCreationException
const & )
235 throw ucb::IllegalIdentifierException();
238 if ( !xContent
->getIdentifier().is() )
239 throw ucb::IllegalIdentifierException();