Branch data 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 <ucbhelper/contentidentifier.hxx>
36 : : #include "webdavprovider.hxx"
37 : : #include "webdavcontent.hxx"
38 : :
39 : : #include "osl/mutex.hxx"
40 : :
41 : : using namespace com::sun::star;
42 : : using namespace webdav_ucp;
43 : :
44 : : //=========================================================================
45 : : //=========================================================================
46 : : //
47 : : // ContentProvider Implementation.
48 : : //
49 : : //=========================================================================
50 : : //=========================================================================
51 : :
52 : 2 : ContentProvider::ContentProvider(
53 : : const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
54 : : : ::ucbhelper::ContentProviderImplHelper( rSMgr ),
55 : 0 : m_xDAVSessionFactory( new DAVSessionFactory() ),
56 [ + - ][ + - ]: 2 : m_pProps( 0 )
[ + - ]
57 : : {
58 : 2 : }
59 : :
60 : : //=========================================================================
61 : : // virtual
62 [ + - ]: 2 : ContentProvider::~ContentProvider()
63 : : {
64 [ - + ][ # # ]: 2 : delete m_pProps;
65 [ - + ]: 4 : }
66 : :
67 : : //=========================================================================
68 : : //
69 : : // XInterface methods.
70 : : //
71 : : //=========================================================================
72 : :
73 [ + - ][ + + ]: 204 : XINTERFACE_IMPL_3( ContentProvider,
[ + - ]
74 : : lang::XTypeProvider,
75 : : lang::XServiceInfo,
76 : : ucb::XContentProvider );
77 : :
78 : : //=========================================================================
79 : : //
80 : : // XTypeProvider methods.
81 : : //
82 : : //=========================================================================
83 : :
84 [ # # ][ # # ]: 0 : XTYPEPROVIDER_IMPL_3( ContentProvider,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
85 : : lang::XTypeProvider,
86 : : lang::XServiceInfo,
87 : : ucb::XContentProvider );
88 : :
89 : : //=========================================================================
90 : : //
91 : : // XServiceInfo methods.
92 : : //
93 : : //=========================================================================
94 : :
95 [ + - ][ + - ]: 8 : XSERVICEINFO_IMPL_1( ContentProvider,
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
96 : : rtl::OUString( "com.sun.star.comp.WebDAVContentProvider" ),
97 : 2 : rtl::OUString( WEBDAV_CONTENT_PROVIDER_SERVICE_NAME ) );
98 : :
99 : : //=========================================================================
100 : : //
101 : : // Service factory implementation.
102 : : //
103 : : //=========================================================================
104 : :
105 [ + - ][ + - ]: 2 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
106 : :
107 : : //=========================================================================
108 : : //
109 : : // XContentProvider methods.
110 : : //
111 : : //=========================================================================
112 : :
113 : : // virtual
114 : : uno::Reference< ucb::XContent > SAL_CALL
115 : 4 : ContentProvider::queryContent(
116 : : const uno::Reference<
117 : : ucb::XContentIdentifier >& Identifier )
118 : : throw( ucb::IllegalIdentifierException,
119 : : uno::RuntimeException )
120 : : {
121 : : // Check URL scheme...
122 : :
123 : : const rtl::OUString aScheme
124 [ + - ][ + - ]: 4 : = Identifier->getContentProviderScheme().toAsciiLowerCase();
125 [ + - ][ - + : 4 : if ( aScheme != HTTP_URL_SCHEME && aScheme != HTTPS_URL_SCHEME && aScheme != WEBDAV_URL_SCHEME
# # # # #
# ][ - + ]
[ + - ]
126 : 0 : && aScheme != DAV_URL_SCHEME && aScheme != DAVS_URL_SCHEME && aScheme != FTP_URL_SCHEME )
127 [ # # ]: 0 : throw ucb::IllegalIdentifierException();
128 : :
129 : : // Normalize URL and create new Id, if nessacary.
130 [ + - ][ + - ]: 4 : rtl::OUString aURL = Identifier->getContentIdentifier();
131 : :
132 : : // At least: <scheme> + "://"
133 [ - + ]: 4 : if ( aURL.getLength() < ( aScheme.getLength() + 3 ) )
134 [ # # ]: 0 : throw ucb::IllegalIdentifierException();
135 : :
136 [ + - + - : 12 : if ( ( aURL.getStr()[ aScheme.getLength() ] != sal_Unicode( ':' ) ) ||
- + ][ - + ]
137 : 4 : ( aURL.getStr()[ aScheme.getLength() + 1 ] != sal_Unicode( '/' ) ) ||
138 : 4 : ( aURL.getStr()[ aScheme.getLength() + 2 ] != sal_Unicode( '/' ) ) )
139 [ # # ]: 0 : throw ucb::IllegalIdentifierException();
140 : :
141 : 4 : uno::Reference< ucb::XContentIdentifier > xCanonicId;
142 : :
143 : 4 : bool bNewId = false;
144 [ + - ]: 4 : if ( aScheme == WEBDAV_URL_SCHEME )
145 : : {
146 : : aURL = aURL.replaceAt( 0,
147 : : WEBDAV_URL_SCHEME_LENGTH,
148 : 4 : rtl::OUString( HTTP_URL_SCHEME ) );
149 : 4 : bNewId = true;
150 : : }
151 [ # # ]: 0 : else if ( aScheme == DAV_URL_SCHEME )
152 : : {
153 : : aURL = aURL.replaceAt( 0,
154 : : DAV_URL_SCHEME_LENGTH,
155 : 0 : rtl::OUString( HTTP_URL_SCHEME ) );
156 : 0 : bNewId = true;
157 : : }
158 [ # # ]: 0 : else if ( aScheme == DAVS_URL_SCHEME )
159 : : {
160 : : aURL = aURL.replaceAt( 0,
161 : : DAVS_URL_SCHEME_LENGTH,
162 : 0 : rtl::OUString( HTTPS_URL_SCHEME ) );
163 : 0 : bNewId = true;
164 : : }
165 : :
166 : 4 : sal_Int32 nPos = aURL.lastIndexOf( '/' );
167 [ - + ]: 4 : if ( nPos != aURL.getLength() - 1 )
168 : : {
169 : : // Find second slash in URL.
170 : 0 : nPos = aURL.indexOf( '/', aURL.indexOf( '/' ) + 1 );
171 [ # # ]: 0 : if ( nPos == -1 )
172 [ # # ]: 0 : throw ucb::IllegalIdentifierException();
173 : :
174 : 0 : nPos = aURL.indexOf( '/', nPos + 1 );
175 [ # # ]: 0 : if ( nPos == -1 )
176 : : {
177 : 0 : aURL += rtl::OUString("/");
178 : 0 : bNewId = true;
179 : : }
180 : : }
181 : :
182 [ + - ]: 4 : if ( bNewId )
183 [ + - ][ + - ]: 4 : xCanonicId = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL );
[ + - ]
184 : : else
185 [ # # ]: 0 : xCanonicId = Identifier;
186 : :
187 [ + - ]: 4 : osl::MutexGuard aGuard( m_aMutex );
188 : :
189 : : // Check, if a content with given id already exists...
190 : : uno::Reference< ucb::XContent > xContent
191 [ + - ][ + + ]: 4 : = queryExistingContent( xCanonicId ).get();
[ + - ]
192 [ + + ]: 4 : if ( xContent.is() )
193 : : return xContent;
194 : :
195 : : // Create a new content.
196 : :
197 : : try
198 : : {
199 : : xContent = new ::webdav_ucp::Content(
200 [ + - ][ + - ]: 2 : m_xSMgr, this, xCanonicId, m_xDAVSessionFactory );
[ + - ]
201 [ + - ]: 2 : registerNewContent( xContent );
202 : : }
203 [ # # ]: 0 : catch ( ucb::ContentCreationException const & )
204 : : {
205 [ # # ]: 0 : throw ucb::IllegalIdentifierException();
206 : : }
207 : :
208 [ + - ][ + - ]: 2 : if ( !xContent->getIdentifier().is() )
[ - + ]
209 [ # # ]: 0 : throw ucb::IllegalIdentifierException();
210 : :
211 [ + - ]: 4 : return xContent;
212 : : }
213 : :
214 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|