Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : *
6 : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : *
8 : * OpenOffice.org - a multi-platform office productivity suite
9 : *
10 : * This file is part of OpenOffice.org.
11 : *
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.
15 : *
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).
21 : *
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.
26 : *
27 : ************************************************************************/
28 :
29 :
30 : /**************************************************************************
31 : TODO
32 : **************************************************************************
33 :
34 : *************************************************************************/
35 : #include <comphelper/processfactory.hxx>
36 : #include <ucbhelper/contentidentifier.hxx>
37 : #include "webdavprovider.hxx"
38 : #include "webdavcontent.hxx"
39 :
40 : #include "osl/mutex.hxx"
41 :
42 : using namespace com::sun::star;
43 : using namespace webdav_ucp;
44 :
45 :
46 :
47 :
48 : // ContentProvider Implementation.
49 :
50 :
51 :
52 :
53 2 : ContentProvider::ContentProvider(
54 : const uno::Reference< uno::XComponentContext >& rxContext )
55 : : ::ucbhelper::ContentProviderImplHelper( rxContext ),
56 0 : m_xDAVSessionFactory( new DAVSessionFactory() ),
57 2 : m_pProps( 0 )
58 : {
59 2 : }
60 :
61 :
62 : // virtual
63 6 : ContentProvider::~ContentProvider()
64 : {
65 2 : delete m_pProps;
66 4 : }
67 :
68 :
69 :
70 : // XInterface methods.
71 :
72 94 : void SAL_CALL ContentProvider::acquire()
73 : throw()
74 : {
75 94 : OWeakObject::acquire();
76 94 : }
77 :
78 94 : void SAL_CALL ContentProvider::release()
79 : throw()
80 : {
81 94 : OWeakObject::release();
82 94 : }
83 :
84 24 : css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
85 : throw( css::uno::RuntimeException, std::exception )
86 : {
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))
91 24 : );
92 24 : return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
93 : }
94 :
95 : // XTypeProvider methods.
96 :
97 :
98 :
99 0 : XTYPEPROVIDER_IMPL_3( ContentProvider,
100 : lang::XTypeProvider,
101 : lang::XServiceInfo,
102 : ucb::XContentProvider );
103 :
104 :
105 :
106 : // XServiceInfo methods.
107 :
108 :
109 :
110 8 : XSERVICEINFO_IMPL_1_CTX( ContentProvider,
111 : OUString( "com.sun.star.comp.WebDAVContentProvider" ),
112 : OUString( WEBDAV_CONTENT_PROVIDER_SERVICE_NAME ) );
113 :
114 :
115 :
116 : // Service factory implementation.
117 :
118 :
119 :
120 2 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
121 :
122 :
123 :
124 : // XContentProvider methods.
125 :
126 :
127 :
128 : // virtual
129 : uno::Reference< ucb::XContent > SAL_CALL
130 4 : ContentProvider::queryContent(
131 : const uno::Reference<
132 : ucb::XContentIdentifier >& Identifier )
133 : throw( ucb::IllegalIdentifierException,
134 : uno::RuntimeException, std::exception )
135 : {
136 : // Check URL scheme...
137 :
138 : const OUString aScheme
139 4 : = Identifier->getContentProviderScheme().toAsciiLowerCase();
140 12 : if ( aScheme != HTTP_URL_SCHEME && aScheme != HTTPS_URL_SCHEME && aScheme != WEBDAV_URL_SCHEME
141 4 : && aScheme != DAV_URL_SCHEME && aScheme != DAVS_URL_SCHEME && aScheme != FTP_URL_SCHEME )
142 0 : throw ucb::IllegalIdentifierException();
143 :
144 : // Normalize URL and create new Id, if nessacary.
145 8 : OUString aURL = Identifier->getContentIdentifier();
146 :
147 : // At least: <scheme> + "://"
148 4 : if ( aURL.getLength() < ( aScheme.getLength() + 3 ) )
149 0 : throw ucb::IllegalIdentifierException();
150 :
151 4 : if ( aURL.copy( aScheme.getLength(), 3 ) != "://" )
152 0 : throw ucb::IllegalIdentifierException();
153 :
154 8 : uno::Reference< ucb::XContentIdentifier > xCanonicId;
155 :
156 4 : bool bNewId = false;
157 4 : if ( aScheme == WEBDAV_URL_SCHEME )
158 : {
159 8 : aURL = aURL.replaceAt( 0,
160 : WEBDAV_URL_SCHEME_LENGTH,
161 4 : OUString( HTTP_URL_SCHEME ) );
162 4 : bNewId = true;
163 : }
164 0 : else if ( aScheme == DAV_URL_SCHEME )
165 : {
166 0 : aURL = aURL.replaceAt( 0,
167 : DAV_URL_SCHEME_LENGTH,
168 0 : OUString( HTTP_URL_SCHEME ) );
169 0 : bNewId = true;
170 : }
171 0 : else if ( aScheme == DAVS_URL_SCHEME )
172 : {
173 0 : aURL = aURL.replaceAt( 0,
174 : DAVS_URL_SCHEME_LENGTH,
175 0 : OUString( HTTPS_URL_SCHEME ) );
176 0 : bNewId = true;
177 : }
178 :
179 4 : sal_Int32 nPos = aURL.lastIndexOf( '/' );
180 4 : if ( nPos != aURL.getLength() - 1 )
181 : {
182 : // Find second slash in URL.
183 0 : nPos = aURL.indexOf( '/', aURL.indexOf( '/' ) + 1 );
184 0 : if ( nPos == -1 )
185 0 : throw ucb::IllegalIdentifierException();
186 :
187 0 : nPos = aURL.indexOf( '/', nPos + 1 );
188 0 : if ( nPos == -1 )
189 : {
190 0 : aURL += "/";
191 0 : bNewId = true;
192 : }
193 : }
194 :
195 4 : if ( bNewId )
196 4 : xCanonicId = new ::ucbhelper::ContentIdentifier( aURL );
197 : else
198 0 : xCanonicId = Identifier;
199 :
200 8 : osl::MutexGuard aGuard( m_aMutex );
201 :
202 : // Check, if a content with given id already exists...
203 : uno::Reference< ucb::XContent > xContent
204 4 : = queryExistingContent( xCanonicId ).get();
205 4 : if ( xContent.is() )
206 2 : return xContent;
207 :
208 : // Create a new content.
209 :
210 : try
211 : {
212 4 : xContent = new ::webdav_ucp::Content(
213 4 : m_xContext, this, xCanonicId, m_xDAVSessionFactory );
214 2 : registerNewContent( xContent );
215 : }
216 0 : catch ( ucb::ContentCreationException const & )
217 : {
218 0 : throw ucb::IllegalIdentifierException();
219 : }
220 :
221 2 : if ( !xContent->getIdentifier().is() )
222 0 : throw ucb::IllegalIdentifierException();
223 :
224 6 : return xContent;
225 : }
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|