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 : :
36 : : #include <osl/diagnose.h>
37 : : #include "osl/doublecheckedlocking.h"
38 : : #include <rtl/uri.hxx>
39 : : #include <rtl/ustrbuf.hxx>
40 : : #include <ucbhelper/contentidentifier.hxx>
41 : : #include <ucbhelper/propertyvalueset.hxx>
42 : : #include <ucbhelper/simpleinteractionrequest.hxx>
43 : : #include <ucbhelper/cancelcommandexecution.hxx>
44 : :
45 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
46 : : #include <com/sun/star/beans/PropertySetInfoChange.hpp>
47 : : #include <com/sun/star/beans/PropertySetInfoChangeEvent.hpp>
48 : : #include <com/sun/star/beans/PropertyValue.hpp>
49 : : #include <com/sun/star/io/XActiveDataSink.hpp>
50 : : #include <com/sun/star/io/XOutputStream.hpp>
51 : : #include <com/sun/star/lang/IllegalAccessException.hpp>
52 : : #include <com/sun/star/task/PasswordContainerInteractionHandler.hpp>
53 : : #include <com/sun/star/ucb/CommandEnvironment.hpp>
54 : : #include <com/sun/star/ucb/CommandFailedException.hpp>
55 : : #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
56 : : #include <com/sun/star/ucb/InsertCommandArgument.hpp>
57 : : #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
58 : : #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
59 : : #include "com/sun/star/ucb/InteractiveLockingLockedException.hpp"
60 : : #include "com/sun/star/ucb/InteractiveLockingLockExpiredException.hpp"
61 : : #include "com/sun/star/ucb/InteractiveLockingNotLockedException.hpp"
62 : : #include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp>
63 : : #include <com/sun/star/ucb/InteractiveNetworkGeneralException.hpp>
64 : : #include <com/sun/star/ucb/InteractiveNetworkReadException.hpp>
65 : : #include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
66 : : #include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp>
67 : : #include <com/sun/star/ucb/MissingInputStreamException.hpp>
68 : : #include <com/sun/star/ucb/MissingPropertiesException.hpp>
69 : : #include <com/sun/star/ucb/NameClash.hpp>
70 : : #include <com/sun/star/ucb/NameClashException.hpp>
71 : : #include <com/sun/star/ucb/OpenCommandArgument3.hpp>
72 : : #include <com/sun/star/ucb/OpenMode.hpp>
73 : : #include <com/sun/star/ucb/PostCommandArgument2.hpp>
74 : : #include <com/sun/star/ucb/TransferInfo.hpp>
75 : : #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
76 : : #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
77 : : #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
78 : : #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
79 : : #include <com/sun/star/ucb/XCommandInfo.hpp>
80 : : #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
81 : : #include <com/sun/star/uno/XComponentContext.hpp>
82 : :
83 : : #include "webdavcontent.hxx"
84 : : #include "webdavprovider.hxx"
85 : : #include "webdavresultset.hxx"
86 : : #include "ContentProperties.hxx"
87 : : #include "NeonUri.hxx"
88 : : #include "UCBDeadPropertyValue.hxx"
89 : :
90 : : using namespace com::sun::star;
91 : : using namespace webdav_ucp;
92 : :
93 : : //=========================================================================
94 : : //=========================================================================
95 : : //
96 : : // Content Implementation.
97 : : //
98 : : //=========================================================================
99 : : //=========================================================================
100 : :
101 : : //=========================================================================
102 : : // ctr for content on an existing webdav resource
103 : 2 : Content::Content(
104 : : const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
105 : : ContentProvider* pProvider,
106 : : const uno::Reference< ucb::XContentIdentifier >& Identifier,
107 : : rtl::Reference< DAVSessionFactory > const & rSessionFactory )
108 : : throw ( ucb::ContentCreationException )
109 : : : ContentImplHelper( rxSMgr, pProvider, Identifier ),
110 : : m_eResourceType( UNKNOWN ),
111 : : m_pProvider( pProvider ),
112 : : m_bTransient( false ),
113 : : m_bCollection( false ),
114 [ + - ][ + - ]: 2 : m_bDidGetOrHead( false )
115 : : {
116 : : try
117 : : {
118 : : m_xResAccess.reset( new DAVResourceAccess(
119 : : rxSMgr,
120 : : rSessionFactory,
121 [ + - ][ + - ]: 2 : Identifier->getContentIdentifier() ) );
[ + - ][ + - ]
122 : :
123 [ + - ][ + - ]: 2 : NeonUri aURI( Identifier->getContentIdentifier() );
[ + - ]
124 [ + - ][ + - ]: 2 : m_aEscapedTitle = aURI.GetPathBaseName();
125 : : }
126 [ # # ]: 0 : catch ( DAVException const & )
127 : : {
128 [ # # ]: 0 : throw ucb::ContentCreationException();
129 : : }
130 : 2 : }
131 : :
132 : : //=========================================================================
133 : : // ctr for content on an non-existing webdav resource
134 : 0 : Content::Content(
135 : : const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
136 : : ContentProvider* pProvider,
137 : : const uno::Reference< ucb::XContentIdentifier >& Identifier,
138 : : rtl::Reference< DAVSessionFactory > const & rSessionFactory,
139 : : sal_Bool isCollection )
140 : : throw ( ucb::ContentCreationException )
141 : : : ContentImplHelper( rxSMgr, pProvider, Identifier ),
142 : : m_eResourceType( UNKNOWN ),
143 : : m_pProvider( pProvider ),
144 : : m_bTransient( true ),
145 : : m_bCollection( isCollection ),
146 [ # # ][ # # ]: 0 : m_bDidGetOrHead( false )
147 : : {
148 : : try
149 : : {
150 : : m_xResAccess.reset( new DAVResourceAccess(
151 [ # # ][ # # ]: 0 : rxSMgr, rSessionFactory, Identifier->getContentIdentifier() ) );
[ # # ][ # # ]
152 : : }
153 [ # # ]: 0 : catch ( DAVException const & )
154 : : {
155 [ # # ]: 0 : throw ucb::ContentCreationException();
156 : : }
157 : :
158 : : // Do not set m_aEscapedTitle here! Content::insert relays on this!!!
159 : 0 : }
160 : :
161 : : //=========================================================================
162 : : // virtual
163 [ + - ][ + - ]: 2 : Content::~Content()
164 : : {
165 [ - + ]: 4 : }
166 : :
167 : : //=========================================================================
168 : : //
169 : : // XInterface methods.
170 : : //
171 : : //=========================================================================
172 : :
173 : : // virtual
174 : 30 : void SAL_CALL Content::acquire()
175 : : throw( )
176 : : {
177 : 30 : ContentImplHelper::acquire();
178 : 30 : }
179 : :
180 : : //=========================================================================
181 : : // virtual
182 : 30 : void SAL_CALL Content::release()
183 : : throw( )
184 : : {
185 : 30 : ContentImplHelper::release();
186 : 30 : }
187 : :
188 : : //=========================================================================
189 : : // virtual
190 : 8 : uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
191 : : throw ( uno::RuntimeException )
192 : : {
193 : : // Note: isFolder may require network activities! So call it only
194 : : // if it is really necessary!!!
195 : : uno::Any aRet = cppu::queryInterface(
196 : : rType,
197 [ + - ]: 8 : static_cast< ucb::XContentCreator * >( this ) );
198 [ - + ]: 8 : if ( aRet.hasValue() )
199 : : {
200 : : try
201 : : {
202 : : uno::Reference< beans::XPropertySet > const xProps(
203 [ # # ]: 0 : m_xSMgr, uno::UNO_QUERY_THROW );
204 : 0 : uno::Reference< uno::XComponentContext > xCtx;
205 [ # # ]: 0 : xCtx.set( xProps->getPropertyValue(
206 : 0 : rtl::OUString( "DefaultContext" ) ),
207 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
208 : :
209 : : uno::Reference< task::XInteractionHandler > xIH(
210 [ # # ]: 0 : task::PasswordContainerInteractionHandler::create( xCtx ) );
211 : :
212 : : // Supply a command env to isFolder() that contains an interaction
213 : : // handler that uses the password container service to obtain
214 : : // credentials without displaying a password gui.
215 : :
216 : : uno::Reference< ucb::XCommandEnvironment > xCmdEnv(
217 : : ucb::CommandEnvironment::create(
218 : : xCtx,
219 : : xIH,
220 [ # # ]: 0 : uno::Reference< ucb::XProgressHandler >() ) );
221 : :
222 [ # # ][ # # ]: 0 : return isFolder( xCmdEnv ) ? aRet : uno::Any();
223 : : }
224 [ # # # ]: 0 : catch ( uno::RuntimeException const & )
225 : : {
226 : 0 : throw;
227 : : }
228 [ # # ]: 0 : catch ( uno::Exception const & )
229 : : {
230 : 0 : return uno::Any();
231 : : }
232 : : }
233 [ - + ][ + - ]: 8 : return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
234 : : }
235 : :
236 : : //=========================================================================
237 : : //
238 : : // XTypeProvider methods.
239 : : //
240 : : //=========================================================================
241 : :
242 [ # # ][ # # ]: 0 : XTYPEPROVIDER_COMMON_IMPL( Content );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
243 : :
244 : : //=========================================================================
245 : : // virtual
246 : 0 : uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
247 : : throw( uno::RuntimeException )
248 : : {
249 : 0 : sal_Bool bFolder = sal_False;
250 : : try
251 : : {
252 : : bFolder
253 [ # # ]: 0 : = isFolder( uno::Reference< ucb::XCommandEnvironment >() );
254 : : }
255 [ # # # ]: 0 : catch ( uno::RuntimeException const & )
256 : : {
257 : 0 : throw;
258 : : }
259 : 0 : catch ( uno::Exception const & )
260 : : {
261 : : }
262 : :
263 : 0 : cppu::OTypeCollection * pCollection = 0;
264 : :
265 [ # # ]: 0 : if ( bFolder )
266 : : {
267 : : static cppu::OTypeCollection* pFolderTypes = 0;
268 : :
269 : 0 : pCollection = pFolderTypes;
270 [ # # ]: 0 : if ( !pCollection )
271 : : {
272 [ # # ][ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
273 : :
274 : 0 : pCollection = pFolderTypes;
275 [ # # ]: 0 : if ( !pCollection )
276 : : {
277 : : static cppu::OTypeCollection aCollection(
278 [ # # ]: 0 : CPPU_TYPE_REF( lang::XTypeProvider ),
279 [ # # ]: 0 : CPPU_TYPE_REF( lang::XServiceInfo ),
280 [ # # ]: 0 : CPPU_TYPE_REF( lang::XComponent ),
281 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XContent ),
282 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XCommandProcessor ),
283 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
284 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
285 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertyContainer ),
286 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
287 [ # # ]: 0 : CPPU_TYPE_REF( container::XChild ),
288 [ # # ][ # # ]: 0 : CPPU_TYPE_REF( ucb::XContentCreator ) ); // !!
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
289 : 0 : pCollection = &aCollection;
290 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
291 : 0 : pFolderTypes = pCollection;
292 [ # # ]: 0 : }
293 : : }
294 : : else {
295 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
296 : : }
297 : : }
298 : : else
299 : : {
300 : : static cppu::OTypeCollection* pDocumentTypes = 0;
301 : :
302 : 0 : pCollection = pDocumentTypes;
303 [ # # ]: 0 : if ( !pCollection )
304 : : {
305 [ # # ][ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
306 : :
307 : 0 : pCollection = pDocumentTypes;
308 [ # # ]: 0 : if ( !pCollection )
309 : : {
310 : : static cppu::OTypeCollection aCollection(
311 [ # # ]: 0 : CPPU_TYPE_REF( lang::XTypeProvider ),
312 [ # # ]: 0 : CPPU_TYPE_REF( lang::XServiceInfo ),
313 [ # # ]: 0 : CPPU_TYPE_REF( lang::XComponent ),
314 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XContent ),
315 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XCommandProcessor ),
316 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
317 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
318 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertyContainer ),
319 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
320 [ # # ][ # # ]: 0 : CPPU_TYPE_REF( container::XChild ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
321 : 0 : pCollection = &aCollection;
322 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
323 : 0 : pDocumentTypes = pCollection;
324 [ # # ]: 0 : }
325 : : }
326 : : else {
327 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
328 : : }
329 : : }
330 : :
331 : 0 : return (*pCollection).getTypes();
332 : : }
333 : :
334 : : //=========================================================================
335 : : //
336 : : // XServiceInfo methods.
337 : : //
338 : : //=========================================================================
339 : :
340 : : // virtual
341 : 0 : rtl::OUString SAL_CALL Content::getImplementationName()
342 : : throw( uno::RuntimeException )
343 : : {
344 : 0 : return rtl::OUString( "com.sun.star.comp.ucb.WebDAVContent" );
345 : : }
346 : :
347 : : //=========================================================================
348 : : // virtual
349 : 0 : uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames()
350 : : throw( uno::RuntimeException )
351 : : {
352 : 0 : uno::Sequence< rtl::OUString > aSNS( 1 );
353 : : aSNS.getArray()[ 0 ]
354 [ # # ]: 0 : = rtl::OUString( WEBDAV_CONTENT_SERVICE_NAME );
355 : 0 : return aSNS;
356 : : }
357 : :
358 : : //=========================================================================
359 : : //
360 : : // XContent methods.
361 : : //
362 : : //=========================================================================
363 : :
364 : : // virtual
365 : 0 : rtl::OUString SAL_CALL Content::getContentType()
366 : : throw( uno::RuntimeException )
367 : : {
368 : 0 : sal_Bool bFolder = sal_False;
369 : : try
370 : : {
371 : : bFolder
372 [ # # ]: 0 : = isFolder( uno::Reference< ucb::XCommandEnvironment >() );
373 : : }
374 [ # # # ]: 0 : catch ( uno::RuntimeException const & )
375 : : {
376 : 0 : throw;
377 : : }
378 : 0 : catch ( uno::Exception const & )
379 : : {
380 : : }
381 : :
382 [ # # ]: 0 : if ( bFolder )
383 : 0 : return rtl::OUString( WEBDAV_COLLECTION_TYPE );
384 : :
385 : 0 : return rtl::OUString( WEBDAV_CONTENT_TYPE );
386 : : }
387 : :
388 : : //=========================================================================
389 : : //
390 : : // XCommandProcessor methods.
391 : : //
392 : : //=========================================================================
393 : :
394 : : // virtual
395 : 0 : uno::Any SAL_CALL Content::execute(
396 : : const ucb::Command& aCommand,
397 : : sal_Int32 /*CommandId*/,
398 : : const uno::Reference< ucb::XCommandEnvironment >& Environment )
399 : : throw( uno::Exception,
400 : : ucb::CommandAbortedException,
401 : : uno::RuntimeException )
402 : : {
403 : : OSL_TRACE( ">>>>> Content::execute: start: command: %s, env: %s",
404 : : rtl::OUStringToOString( aCommand.Name,
405 : : RTL_TEXTENCODING_UTF8 ).getStr(),
406 : : Environment.is() ? "present" : "missing" );
407 : :
408 : 0 : uno::Any aRet;
409 : :
410 [ # # ]: 0 : if ( aCommand.Name == "getPropertyValues" )
411 : : {
412 : : //////////////////////////////////////////////////////////////////
413 : : // getPropertyValues
414 : : //////////////////////////////////////////////////////////////////
415 : :
416 [ # # ]: 0 : uno::Sequence< beans::Property > Properties;
417 [ # # ][ # # ]: 0 : if ( !( aCommand.Argument >>= Properties ) )
418 : : {
419 : : ucbhelper::cancelCommandExecution(
420 : : uno::makeAny( lang::IllegalArgumentException(
421 : : rtl::OUString( "Wrong argument type!" ),
422 : : static_cast< cppu::OWeakObject * >( this ),
423 : : -1 ) ),
424 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
425 : : // Unreachable
426 : : }
427 : :
428 [ # # ][ # # ]: 0 : aRet <<= getPropertyValues( Properties, Environment );
[ # # ]
429 : : }
430 [ # # ]: 0 : else if ( aCommand.Name == "setPropertyValues" )
431 : : {
432 : : //////////////////////////////////////////////////////////////////
433 : : // setPropertyValues
434 : : //////////////////////////////////////////////////////////////////
435 : :
436 [ # # ]: 0 : uno::Sequence< beans::PropertyValue > aProperties;
437 [ # # ][ # # ]: 0 : if ( !( aCommand.Argument >>= aProperties ) )
438 : : {
439 : : ucbhelper::cancelCommandExecution(
440 : : uno::makeAny( lang::IllegalArgumentException(
441 : : rtl::OUString( "Wrong argument type!" ),
442 : : static_cast< cppu::OWeakObject * >( this ),
443 : : -1 ) ),
444 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
445 : : // Unreachable
446 : : }
447 : :
448 [ # # ]: 0 : if ( !aProperties.getLength() )
449 : : {
450 : : ucbhelper::cancelCommandExecution(
451 : : uno::makeAny( lang::IllegalArgumentException(
452 : : rtl::OUString( "No properties!" ),
453 : : static_cast< cppu::OWeakObject * >( this ),
454 : : -1 ) ),
455 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
456 : : // Unreachable
457 : : }
458 : :
459 [ # # ][ # # ]: 0 : aRet <<= setPropertyValues( aProperties, Environment );
[ # # ][ # # ]
460 : : }
461 [ # # ]: 0 : else if ( aCommand.Name == "getPropertySetInfo" )
462 : : {
463 : : //////////////////////////////////////////////////////////////////
464 : : // getPropertySetInfo
465 : : //////////////////////////////////////////////////////////////////
466 : :
467 : : // Note: Implemented by base class.
468 : : aRet <<= getPropertySetInfo( Environment,
469 [ # # ][ # # ]: 0 : sal_False /* don't cache data */ );
470 : : }
471 [ # # ]: 0 : else if ( aCommand.Name == "getCommandInfo" )
472 : : {
473 : : //////////////////////////////////////////////////////////////////
474 : : // getCommandInfo
475 : : //////////////////////////////////////////////////////////////////
476 : :
477 : : // Note: Implemented by base class.
478 [ # # ][ # # ]: 0 : aRet <<= getCommandInfo( Environment, sal_False );
479 : : }
480 [ # # ]: 0 : else if ( aCommand.Name == "open" )
481 : : {
482 : : //////////////////////////////////////////////////////////////////
483 : : // open
484 : : //////////////////////////////////////////////////////////////////
485 : :
486 [ # # ]: 0 : ucb::OpenCommandArgument3 aOpenCommand;
487 [ # # ]: 0 : ucb::OpenCommandArgument2 aTmp;
488 [ # # ][ # # ]: 0 : if ( !( aCommand.Argument >>= aTmp ) )
489 : : {
490 : : ucbhelper::cancelCommandExecution(
491 : : uno::makeAny( lang::IllegalArgumentException(
492 : : rtl::OUString( "Wrong argument type!" ),
493 : : static_cast< cppu::OWeakObject * >( this ),
494 : : -1 ) ),
495 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
496 : : // Unreachable
497 : : }
498 [ # # ][ # # ]: 0 : if ( !( aCommand.Argument >>= aOpenCommand ) )
499 : : {
500 : : // compat mode, extract Arg2 info into newer structure
501 : 0 : aOpenCommand.Mode = aTmp.Mode;
502 : 0 : aOpenCommand.Priority = aTmp.Priority;
503 [ # # ]: 0 : aOpenCommand.Sink = aTmp.Sink;
504 [ # # ]: 0 : aOpenCommand.Properties = aTmp.Properties;
505 [ # # ]: 0 : aOpenCommand.SortingInfo = aTmp.SortingInfo;
506 : : }
507 : :
508 [ # # ][ # # ]: 0 : aRet = open( aOpenCommand, Environment );
[ # # ]
509 : : }
510 [ # # ]: 0 : else if ( aCommand.Name == "insert" )
511 : : {
512 : : //////////////////////////////////////////////////////////////////
513 : : // insert
514 : : //////////////////////////////////////////////////////////////////
515 : :
516 [ # # ]: 0 : ucb::InsertCommandArgument arg;
517 [ # # ][ # # ]: 0 : if ( !( aCommand.Argument >>= arg ) )
518 : : {
519 : : ucbhelper::cancelCommandExecution(
520 : : uno::makeAny( lang::IllegalArgumentException(
521 : : rtl::OUString( "Wrong argument type!" ),
522 : : static_cast< cppu::OWeakObject * >( this ),
523 : : -1 ) ),
524 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
525 : : // Unreachable
526 : : }
527 : :
528 [ # # ][ # # ]: 0 : insert( arg.Data, arg.ReplaceExisting, Environment );
529 : : }
530 [ # # ]: 0 : else if ( aCommand.Name == "delete" )
531 : : {
532 : : //////////////////////////////////////////////////////////////////
533 : : // delete
534 : : //////////////////////////////////////////////////////////////////
535 : :
536 : 0 : sal_Bool bDeletePhysical = sal_False;
537 : 0 : aCommand.Argument >>= bDeletePhysical;
538 : :
539 : : // KSO: Ignore parameter and destroy the content, if you don't support
540 : : // putting objects into trashcan. ( Since we do not have a trash can
541 : : // service yet (src603), you actually have no other choice. )
542 : : // if ( bDeletePhysical )
543 : : // {
544 : : try
545 : : {
546 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
547 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
548 : : SAL_WNODEPRECATED_DECLARATIONS_POP
549 : : {
550 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
551 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
552 : : }
553 [ # # ]: 0 : xResAccess->DESTROY( Environment );
554 : : {
555 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
556 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
557 [ # # ]: 0 : }
558 : : }
559 [ # # ]: 0 : catch ( DAVException const & e )
560 : : {
561 [ # # ]: 0 : cancelCommandExecution( e, Environment, sal_True );
562 : : // Unreachable
563 : : }
564 : : // }
565 : :
566 : : // Propagate destruction.
567 [ # # ]: 0 : destroy( bDeletePhysical );
568 : :
569 : : // Remove own and all children's Additional Core Properties.
570 [ # # ]: 0 : removeAdditionalPropertySet( sal_True );
571 : : }
572 [ # # ][ # # ]: 0 : else if ( aCommand.Name == "transfer" && isFolder( Environment ) )
[ # # ][ # # ]
573 : : {
574 : : //////////////////////////////////////////////////////////////////
575 : : // transfer
576 : : // ( Not available at documents )
577 : : //////////////////////////////////////////////////////////////////
578 : :
579 : 0 : ucb::TransferInfo transferArgs;
580 [ # # ][ # # ]: 0 : if ( !( aCommand.Argument >>= transferArgs ) )
581 : : {
582 : : ucbhelper::cancelCommandExecution(
583 : : uno::makeAny( lang::IllegalArgumentException(
584 : : rtl::OUString( "Wrong argument type!" ),
585 : : static_cast< cppu::OWeakObject * >( this ),
586 : : -1 ) ),
587 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
588 : : // Unreachable
589 : : }
590 : :
591 [ # # ]: 0 : transfer( transferArgs, Environment );
592 : : }
593 [ # # ]: 0 : else if ( aCommand.Name == "post" )
594 : : {
595 : : //////////////////////////////////////////////////////////////////
596 : : // post
597 : : //////////////////////////////////////////////////////////////////
598 : :
599 [ # # ]: 0 : ucb::PostCommandArgument2 aArg;
600 [ # # ][ # # ]: 0 : if ( !( aCommand.Argument >>= aArg ) )
601 : : {
602 : : ucbhelper::cancelCommandExecution(
603 : : uno::makeAny( lang::IllegalArgumentException(
604 : : rtl::OUString( "Wrong argument type!" ),
605 : : static_cast< cppu::OWeakObject * >( this ),
606 : : -1 ) ),
607 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
608 : : // Unreachable
609 : : }
610 : :
611 [ # # ][ # # ]: 0 : post( aArg, Environment );
612 : : }
613 [ # # ][ # # ]: 0 : else if ( aCommand.Name == "lock" && supportsExclusiveWriteLock( Environment ) )
[ # # ][ # # ]
614 : : {
615 : : //////////////////////////////////////////////////////////////////
616 : : // lock
617 : : //////////////////////////////////////////////////////////////////
618 : :
619 [ # # ]: 0 : lock( Environment );
620 : : }
621 [ # # ][ # # ]: 0 : else if ( aCommand.Name == "unlock" && supportsExclusiveWriteLock( Environment ) )
[ # # ][ # # ]
622 : : {
623 : : //////////////////////////////////////////////////////////////////
624 : : // unlock
625 : : //////////////////////////////////////////////////////////////////
626 : :
627 [ # # ]: 0 : unlock( Environment );
628 : : }
629 [ # # ][ # # ]: 0 : else if ( aCommand.Name == "createNewContent" && isFolder( Environment ) )
[ # # ][ # # ]
630 : : {
631 : : //////////////////////////////////////////////////////////////////
632 : : // createNewContent
633 : : //////////////////////////////////////////////////////////////////
634 : :
635 [ # # ]: 0 : ucb::ContentInfo aArg;
636 [ # # ][ # # ]: 0 : if ( !( aCommand.Argument >>= aArg ) )
637 : : {
638 : : ucbhelper::cancelCommandExecution(
639 : : uno::makeAny( lang::IllegalArgumentException(
640 : : rtl::OUString( "Wrong argument type!" ),
641 : : static_cast< cppu::OWeakObject * >( this ),
642 : : -1 ) ),
643 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
644 : : // Unreachable
645 : : }
646 : :
647 [ # # ][ # # ]: 0 : aRet = uno::makeAny( createNewContent( aArg ) );
[ # # ]
648 : : }
649 : : else
650 : : {
651 : : //////////////////////////////////////////////////////////////////
652 : : // Unsupported command
653 : : //////////////////////////////////////////////////////////////////
654 : :
655 : : ucbhelper::cancelCommandExecution(
656 : : uno::makeAny( ucb::UnsupportedCommandException(
657 : : aCommand.Name,
658 : : static_cast< cppu::OWeakObject * >( this ) ) ),
659 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
660 : : // Unreachable
661 : : }
662 : :
663 : : OSL_TRACE( "<<<<< Content::execute: end: command: %s",
664 : : rtl::OUStringToOString( aCommand.Name,
665 : : RTL_TEXTENCODING_UTF8 ).getStr() );
666 : :
667 : 0 : return aRet;
668 : : }
669 : :
670 : : //=========================================================================
671 : : // virtual
672 : 0 : void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
673 : : throw( uno::RuntimeException )
674 : : {
675 : : try
676 : : {
677 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
678 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
679 : : SAL_WNODEPRECATED_DECLARATIONS_POP
680 : : {
681 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
682 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
683 : : }
684 [ # # ]: 0 : xResAccess->abort();
685 : : {
686 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
687 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
688 [ # # ][ # # ]: 0 : }
689 : : }
690 : 0 : catch ( DAVException const & )
691 : : {
692 : : // abort failed!
693 : : }
694 : 0 : }
695 : :
696 : : //=========================================================================
697 : : //
698 : : // XPropertyContainer methods.
699 : : //
700 : : //=========================================================================
701 : :
702 : : // virtual
703 : 0 : void SAL_CALL Content::addProperty( const rtl::OUString& Name,
704 : : sal_Int16 Attributes,
705 : : const uno::Any& DefaultValue )
706 : : throw( beans::PropertyExistException,
707 : : beans::IllegalTypeException,
708 : : lang::IllegalArgumentException,
709 : : uno::RuntimeException )
710 : : {
711 : : // if ( m_bTransient )
712 : : // @@@ ???
713 : :
714 [ # # ]: 0 : if ( Name.isEmpty() )
715 [ # # ]: 0 : throw lang::IllegalArgumentException();
716 : :
717 : : // Check property type.
718 [ # # ][ # # ]: 0 : if ( !UCBDeadPropertyValue::supportsType( DefaultValue.getValueType() ) )
719 : : {
720 : : OSL_FAIL( "Content::addProperty - Unsupported property type!" );
721 [ # # ]: 0 : throw beans::IllegalTypeException();
722 : : }
723 : :
724 : : //////////////////////////////////////////////////////////////////////
725 : : // Make sure a property with the requested name does not already
726 : : // exist in dynamic and static(!) properties.
727 : : //////////////////////////////////////////////////////////////////////
728 : :
729 : : // @@@ Need real command environment here, but where to get it from?
730 : : // XPropertyContainer interface should be replaced by
731 : : // XCommandProcessor commands!
732 : 0 : uno::Reference< ucb::XCommandEnvironment > xEnv;
733 : :
734 : : // Note: This requires network access!
735 [ # # ]: 0 : if ( getPropertySetInfo( xEnv, sal_False /* don't cache data */ )
736 [ # # ][ # # ]: 0 : ->hasPropertyByName( Name ) )
[ # # ]
737 : : {
738 : : // Property does already exist.
739 [ # # ]: 0 : throw beans::PropertyExistException();
740 : : }
741 : :
742 : : //////////////////////////////////////////////////////////////////////
743 : : // Add a new dynamic property.
744 : : //////////////////////////////////////////////////////////////////////
745 : :
746 : 0 : ProppatchValue aValue( PROPSET, Name, DefaultValue );
747 : :
748 [ # # ]: 0 : std::vector< ProppatchValue > aProppatchValues;
749 [ # # ]: 0 : aProppatchValues.push_back( aValue );
750 : :
751 : : try
752 : : {
753 : : // Set property value at server.
754 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
755 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
756 : : SAL_WNODEPRECATED_DECLARATIONS_POP
757 : : {
758 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
759 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
760 : : }
761 [ # # ]: 0 : xResAccess->PROPPATCH( aProppatchValues, xEnv );
762 : : {
763 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
764 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
765 : : }
766 : :
767 : : // Notify propertyset info change listeners.
768 : : beans::PropertySetInfoChangeEvent evt(
769 : : static_cast< cppu::OWeakObject * >( this ),
770 : : Name,
771 : : -1, // No handle available
772 [ # # ][ # # ]: 0 : beans::PropertySetInfoChange::PROPERTY_INSERTED );
773 [ # # ][ # # ]: 0 : notifyPropertySetInfoChange( evt );
[ # # ]
774 : : }
775 [ # # ]: 0 : catch ( DAVException const & e )
776 : : {
777 [ # # ]: 0 : if ( e.getStatus() == SC_FORBIDDEN )
778 : : {
779 : : // Support for setting arbitrary dead properties is optional!
780 : :
781 : : // Store property locally.
782 : : ContentImplHelper::addProperty(
783 [ # # ]: 0 : Name, Attributes, DefaultValue );
784 : : }
785 : : else
786 : : {
787 [ # # ]: 0 : if ( shouldAccessNetworkAfterException( e ) )
788 : : {
789 : : try
790 : : {
791 [ # # ]: 0 : const ResourceType & rType = getResourceType( xEnv );
792 [ # # # ]: 0 : switch ( rType )
793 : : {
794 : : case UNKNOWN:
795 : : case DAV:
796 [ # # # # ]: 0 : throw lang::IllegalArgumentException();
797 : :
798 : : case FTP:
799 : : case NON_DAV:
800 : : // Store property locally.
801 : : ContentImplHelper::addProperty( Name,
802 : : Attributes,
803 [ # # ]: 0 : DefaultValue );
804 : 0 : break;
805 : :
806 : : default:
807 : : OSL_FAIL( "Content::addProperty - "
808 : : "Unsupported resource type!" );
809 : 0 : break;
810 : : }
811 : : }
812 [ # # ]: 0 : catch ( uno::Exception const & )
813 : : {
814 : : OSL_FAIL( "Content::addProperty - "
815 : : "Unable to determine resource type!" );
816 : : }
817 : : }
818 : : else
819 : : {
820 : : OSL_FAIL( "Content::addProperty - "
821 : : "Unable to determine resource type!" );
822 : : }
823 : : }
824 : 0 : }
825 : 0 : }
826 : :
827 : : //=========================================================================
828 : : // virtual
829 : 0 : void SAL_CALL Content::removeProperty( const rtl::OUString& Name )
830 : : throw( beans::UnknownPropertyException,
831 : : beans::NotRemoveableException,
832 : : uno::RuntimeException )
833 : : {
834 : : // @@@ Need real command environment here, but where to get it from?
835 : : // XPropertyContainer interface should be replaced by
836 : : // XCommandProcessor commands!
837 : 0 : uno::Reference< ucb::XCommandEnvironment > xEnv;
838 : :
839 : : //////////////////////////////////////////////////////////////////////
840 : : // Try to remove property from server.
841 : : //////////////////////////////////////////////////////////////////////
842 : :
843 : : try
844 : : {
845 [ # # ]: 0 : std::vector< ProppatchValue > aProppatchValues;
846 : 0 : ProppatchValue aValue( PROPREMOVE, Name, uno::Any() );
847 [ # # ]: 0 : aProppatchValues.push_back( aValue );
848 : :
849 : : // Remove property value from server.
850 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
851 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
852 : : SAL_WNODEPRECATED_DECLARATIONS_POP
853 : : {
854 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
855 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
856 : : }
857 [ # # ]: 0 : xResAccess->PROPPATCH( aProppatchValues, xEnv );
858 : : {
859 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
860 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
861 : : }
862 : :
863 : : // Notify propertyset info change listeners.
864 : : beans::PropertySetInfoChangeEvent evt(
865 : : static_cast< cppu::OWeakObject * >( this ),
866 : : Name,
867 : : -1, // No handle available
868 [ # # ][ # # ]: 0 : beans::PropertySetInfoChange::PROPERTY_REMOVED );
869 [ # # ][ # # ]: 0 : notifyPropertySetInfoChange( evt );
[ # # ]
870 : : }
871 [ # # ]: 0 : catch ( DAVException const & e )
872 : : {
873 [ # # ]: 0 : if ( e.getStatus() == SC_FORBIDDEN )
874 : : {
875 : : // Support for setting arbitrary dead properties is optional!
876 : :
877 : : // Try to remove property from local store.
878 [ # # ]: 0 : ContentImplHelper::removeProperty( Name );
879 : : }
880 : : else
881 : : {
882 [ # # ]: 0 : if ( shouldAccessNetworkAfterException( e ) )
883 : : {
884 : : try
885 : : {
886 [ # # ]: 0 : const ResourceType & rType = getResourceType( xEnv );
887 [ # # # ]: 0 : switch ( rType )
888 : : {
889 : : case UNKNOWN:
890 : : case DAV:
891 [ # # # # ]: 0 : throw beans::UnknownPropertyException();
892 : :
893 : : case FTP:
894 : : case NON_DAV:
895 : : // Try to remove property from local store.
896 [ # # ]: 0 : ContentImplHelper::removeProperty( Name );
897 : 0 : break;
898 : :
899 : : default:
900 : : OSL_FAIL( "Content::removeProperty - "
901 : : "Unsupported resource type!" );
902 : 0 : break;
903 : : }
904 : : }
905 [ # # ]: 0 : catch ( uno::Exception const & )
906 : : {
907 : : OSL_FAIL( "Content::removeProperty - "
908 : : "Unable to determine resource type!" );
909 : : }
910 : : }
911 : : else
912 : : {
913 : : OSL_FAIL( "Content::removeProperty - "
914 : : "Unable to determine resource type!" );
915 : : // throw beans::UnknownPropertyException();
916 : : }
917 : : }
918 : 0 : }
919 : 0 : }
920 : :
921 : : //=========================================================================
922 : : //
923 : : // XContentCreator methods.
924 : : //
925 : : //=========================================================================
926 : :
927 : : // virtual
928 : : uno::Sequence< ucb::ContentInfo > SAL_CALL
929 : 0 : Content::queryCreatableContentsInfo()
930 : : throw( uno::RuntimeException )
931 : : {
932 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
933 : :
934 [ # # ]: 0 : uno::Sequence< ucb::ContentInfo > aSeq( 2 );
935 : :
936 : : // document.
937 [ # # ]: 0 : aSeq.getArray()[ 0 ].Type
938 : 0 : = rtl::OUString( WEBDAV_CONTENT_TYPE );
939 [ # # ]: 0 : aSeq.getArray()[ 0 ].Attributes
940 : : = ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM
941 : 0 : | ucb::ContentInfoAttribute::KIND_DOCUMENT;
942 : :
943 : 0 : beans::Property aProp;
944 : : m_pProvider->getProperty(
945 [ # # ]: 0 : rtl::OUString( "Title" ), aProp );
946 : :
947 [ # # ]: 0 : uno::Sequence< beans::Property > aDocProps( 1 );
948 [ # # ]: 0 : aDocProps.getArray()[ 0 ] = aProp;
949 [ # # ][ # # ]: 0 : aSeq.getArray()[ 0 ].Properties = aDocProps;
950 : :
951 : : // folder.
952 [ # # ]: 0 : aSeq.getArray()[ 1 ].Type
953 : 0 : = rtl::OUString( WEBDAV_COLLECTION_TYPE );
954 [ # # ]: 0 : aSeq.getArray()[ 1 ].Attributes
955 : 0 : = ucb::ContentInfoAttribute::KIND_FOLDER;
956 : :
957 [ # # ]: 0 : uno::Sequence< beans::Property > aFolderProps( 1 );
958 [ # # ]: 0 : aFolderProps.getArray()[ 0 ] = aProp;
959 [ # # ][ # # ]: 0 : aSeq.getArray()[ 1 ].Properties = aFolderProps;
960 [ # # ][ # # ]: 0 : return aSeq;
[ # # ]
961 : : }
962 : :
963 : : //=========================================================================
964 : : // virtual
965 : : uno::Reference< ucb::XContent > SAL_CALL
966 : 0 : Content::createNewContent( const ucb::ContentInfo& Info )
967 : : throw( uno::RuntimeException )
968 : : {
969 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
970 : :
971 [ # # ]: 0 : if ( Info.Type.isEmpty() )
972 : 0 : return uno::Reference< ucb::XContent >();
973 : :
974 [ # # ][ # # ]: 0 : if ( ( Info.Type != WEBDAV_COLLECTION_TYPE ) && ( Info.Type != WEBDAV_CONTENT_TYPE ) )
[ # # ]
975 : 0 : return uno::Reference< ucb::XContent >();
976 : :
977 [ # # ][ # # ]: 0 : rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
978 : :
979 : : OSL_ENSURE( !aURL.isEmpty(),
980 : : "WebdavContent::createNewContent - empty identifier!" );
981 : :
982 [ # # ]: 0 : if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() )
983 : 0 : aURL += rtl::OUString("/");
984 : :
985 : : sal_Bool isCollection;
986 [ # # ]: 0 : if ( Info.Type == WEBDAV_COLLECTION_TYPE )
987 : : {
988 : 0 : aURL += rtl::OUString("New_Collection");
989 : 0 : isCollection = sal_True;
990 : : }
991 : : else
992 : : {
993 : 0 : aURL += rtl::OUString("New_Content");
994 : 0 : isCollection = sal_False;
995 : : }
996 : :
997 : : uno::Reference< ucb::XContentIdentifier > xId(
998 [ # # ][ # # ]: 0 : new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ) );
[ # # ]
999 : :
1000 : : // create the local content
1001 : : try
1002 : : {
1003 : : return new ::webdav_ucp::Content( m_xSMgr,
1004 : : m_pProvider,
1005 : : xId,
1006 : : m_xResAccess->getSessionFactory(),
1007 [ # # ][ # # ]: 0 : isCollection );
[ # # ][ # # ]
[ # # ][ # # ]
1008 : : }
1009 [ # # ]: 0 : catch ( ucb::ContentCreationException & )
1010 : : {
1011 : 0 : return uno::Reference< ucb::XContent >();
1012 [ # # ]: 0 : }
1013 : : }
1014 : :
1015 : : //=========================================================================
1016 : : // virtual
1017 : 0 : rtl::OUString Content::getParentURL()
1018 : : {
1019 : : // <scheme>:// -> ""
1020 : : // <scheme>://foo -> ""
1021 : : // <scheme>://foo/ -> ""
1022 : : // <scheme>://foo/bar -> <scheme>://foo/
1023 : : // <scheme>://foo/bar/ -> <scheme>://foo/
1024 : : // <scheme>://foo/bar/abc -> <scheme>://foo/bar/
1025 : :
1026 [ # # ][ # # ]: 0 : rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
1027 : :
1028 : 0 : sal_Int32 nPos = aURL.lastIndexOf( '/' );
1029 [ # # ]: 0 : if ( nPos == ( aURL.getLength() - 1 ) )
1030 : : {
1031 : : // Trailing slash found. Skip.
1032 : 0 : nPos = aURL.lastIndexOf( '/', nPos );
1033 : : }
1034 : :
1035 : 0 : sal_Int32 nPos1 = aURL.lastIndexOf( '/', nPos );
1036 [ # # ]: 0 : if ( nPos1 != -1 )
1037 : 0 : nPos1 = aURL.lastIndexOf( '/', nPos1 );
1038 : :
1039 [ # # ]: 0 : if ( nPos1 == -1 )
1040 : 0 : return rtl::OUString();
1041 : :
1042 : 0 : return rtl::OUString( aURL.copy( 0, nPos + 1 ) );
1043 : : }
1044 : :
1045 : : //=========================================================================
1046 : : //
1047 : : // Non-interface methods.
1048 : : //
1049 : : //=========================================================================
1050 : :
1051 : : // static
1052 : 0 : uno::Reference< sdbc::XRow > Content::getPropertyValues(
1053 : : const uno::Reference< lang::XMultiServiceFactory >& rSMgr,
1054 : : const uno::Sequence< beans::Property >& rProperties,
1055 : : const ContentProperties& rData,
1056 : : const rtl::Reference< ::ucbhelper::ContentProviderImplHelper >& rProvider,
1057 : : const rtl::OUString& rContentId )
1058 : : {
1059 : : // Note: Empty sequence means "get values of all supported properties".
1060 : :
1061 : : rtl::Reference< ::ucbhelper::PropertyValueSet > xRow
1062 [ # # ]: 0 : = new ::ucbhelper::PropertyValueSet( rSMgr );
1063 : :
1064 : 0 : sal_Int32 nCount = rProperties.getLength();
1065 [ # # ]: 0 : if ( nCount )
1066 : : {
1067 : 0 : uno::Reference< beans::XPropertySet > xAdditionalPropSet;
1068 : 0 : sal_Bool bTriedToGetAdditonalPropSet = sal_False;
1069 : :
1070 : 0 : const beans::Property* pProps = rProperties.getConstArray();
1071 [ # # ]: 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
1072 : : {
1073 : 0 : const beans::Property& rProp = pProps[ n ];
1074 : :
1075 : : // Process standard UCB, DAV and HTTP properties.
1076 [ # # ]: 0 : const uno::Any & rValue = rData.getValue( rProp.Name );
1077 [ # # ]: 0 : if ( rValue.hasValue() )
1078 : : {
1079 [ # # ]: 0 : xRow->appendObject( rProp, rValue );
1080 : : }
1081 : : else
1082 : : {
1083 : : // Process local Additional Properties.
1084 [ # # ][ # # ]: 0 : if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() )
[ # # ]
1085 : : {
1086 : : xAdditionalPropSet
1087 : : = uno::Reference< beans::XPropertySet >(
1088 : : rProvider->getAdditionalPropertySet( rContentId,
1089 : : sal_False ),
1090 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ]
1091 : 0 : bTriedToGetAdditonalPropSet = sal_True;
1092 : : }
1093 : :
1094 [ # # ][ # # ]: 0 : if ( !xAdditionalPropSet.is() ||
[ # # ]
1095 : : !xRow->appendPropertySetValue(
1096 [ # # ]: 0 : xAdditionalPropSet, rProp ) )
1097 : : {
1098 : : // Append empty entry.
1099 [ # # ]: 0 : xRow->appendVoid( rProp );
1100 : : }
1101 : : }
1102 : 0 : }
1103 : : }
1104 : : else
1105 : : {
1106 : : // Append all standard UCB, DAV and HTTP properties.
1107 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1108 : 0 : const std::auto_ptr< PropertyValueMap > & xProps = rData.getProperties();
1109 : : SAL_WNODEPRECATED_DECLARATIONS_POP
1110 : :
1111 [ # # ]: 0 : PropertyValueMap::const_iterator it = xProps->begin();
1112 [ # # ]: 0 : PropertyValueMap::const_iterator end = xProps->end();
1113 : :
1114 : : ContentProvider * pProvider
1115 : 0 : = static_cast< ContentProvider * >( rProvider.get() );
1116 : 0 : beans::Property aProp;
1117 : :
1118 [ # # ]: 0 : while ( it != end )
1119 : : {
1120 [ # # ][ # # ]: 0 : if ( pProvider->getProperty( (*it).first, aProp ) )
[ # # ]
1121 [ # # ][ # # ]: 0 : xRow->appendObject( aProp, (*it).second.value() );
1122 : :
1123 : 0 : ++it;
1124 : : }
1125 : :
1126 : : // Append all local Additional Properties.
1127 : : uno::Reference< beans::XPropertySet > xSet(
1128 : : rProvider->getAdditionalPropertySet( rContentId, sal_False ),
1129 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
1130 [ # # ]: 0 : xRow->appendPropertySet( xSet );
1131 : : }
1132 : :
1133 [ # # ][ # # ]: 0 : return uno::Reference< sdbc::XRow >( xRow.get() );
1134 : : }
1135 : :
1136 : : //=========================================================================
1137 : 0 : uno::Reference< sdbc::XRow > Content::getPropertyValues(
1138 : : const uno::Sequence< beans::Property >& rProperties,
1139 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1140 : : throw ( uno::Exception )
1141 : : {
1142 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1143 : 0 : std::auto_ptr< ContentProperties > xProps;
1144 : 0 : std::auto_ptr< ContentProperties > xCachedProps;
1145 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
1146 : : SAL_WNODEPRECATED_DECLARATIONS_POP
1147 : 0 : rtl::OUString aUnescapedTitle;
1148 : 0 : bool bHasAll = false;
1149 : 0 : uno::Reference< lang::XMultiServiceFactory > xSMgr;
1150 : 0 : uno::Reference< ucb::XContentIdentifier > xIdentifier;
1151 : 0 : rtl::Reference< ::ucbhelper::ContentProviderImplHelper > xProvider;
1152 : :
1153 : : {
1154 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1155 : :
1156 [ # # ]: 0 : aUnescapedTitle = NeonUri::unescape( m_aEscapedTitle );
1157 [ # # ]: 0 : xSMgr.set( m_xSMgr );
1158 [ # # ]: 0 : xIdentifier.set( m_xIdentifier );
1159 : 0 : xProvider.set( m_xProvider.get() );
1160 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
1161 : :
1162 : : // First, ask cache...
1163 [ # # ]: 0 : if ( m_xCachedProps.get() )
1164 : : {
1165 [ # # ][ # # ]: 0 : xCachedProps.reset( new ContentProperties( *m_xCachedProps.get() ) );
1166 : :
1167 [ # # ]: 0 : std::vector< rtl::OUString > aMissingProps;
1168 [ # # ][ # # ]: 0 : if ( xCachedProps->containsAllNames( rProperties, aMissingProps ) )
1169 : : {
1170 : : // All properties are already in cache! No server access needed.
1171 : 0 : bHasAll = true;
1172 : : }
1173 : :
1174 : : // use the cached ContentProperties instance
1175 [ # # ][ # # ]: 0 : xProps.reset( new ContentProperties( *xCachedProps.get() ) );
1176 [ # # ]: 0 : }
1177 : : }
1178 : :
1179 [ # # ][ # # ]: 0 : if ( !m_bTransient && !bHasAll )
1180 : : {
1181 : : /////////////////////////////////////////////////////////////////////
1182 : : // Obtain values from server...
1183 : : /////////////////////////////////////////////////////////////////////
1184 : :
1185 : : // First, identify whether resource is DAV or not
1186 [ # # ]: 0 : const ResourceType & rType = getResourceType( xEnv, xResAccess );
1187 : :
1188 : 0 : bool bNetworkAccessAllowed = true;
1189 : :
1190 [ # # ]: 0 : if ( DAV == rType )
1191 : : {
1192 : : // cache lookup... getResourceType may fill the props cache via
1193 : : // PROPFIND!
1194 [ # # ]: 0 : if ( m_xCachedProps.get() )
1195 : : {
1196 : : xCachedProps.reset(
1197 [ # # ][ # # ]: 0 : new ContentProperties( *m_xCachedProps.get() ) );
1198 : :
1199 [ # # ]: 0 : std::vector< rtl::OUString > aMissingProps;
1200 [ # # ][ # # ]: 0 : if ( xCachedProps->containsAllNames(
1201 : 0 : rProperties, aMissingProps ) )
1202 : : {
1203 : : // All properties are already in cache! No server access
1204 : : // needed.
1205 : 0 : bHasAll = true;
1206 : : }
1207 : :
1208 : : // use the cached ContentProperties instance
1209 [ # # ][ # # ]: 0 : xProps.reset( new ContentProperties( *xCachedProps.get() ) );
1210 : : }
1211 : :
1212 [ # # ]: 0 : if ( !bHasAll )
1213 : : {
1214 : : // Only DAV resources support PROPFIND
1215 [ # # ]: 0 : std::vector< rtl::OUString > aPropNames;
1216 : :
1217 : : uno::Sequence< beans::Property > aProperties(
1218 [ # # ]: 0 : rProperties.getLength() );
1219 : :
1220 [ # # ]: 0 : if ( !m_aFailedPropNames.empty() )
1221 : : {
1222 : 0 : sal_Int32 nProps = 0;
1223 : 0 : sal_Int32 nCount = rProperties.getLength();
1224 [ # # ]: 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
1225 : : {
1226 : 0 : const rtl::OUString & rName = rProperties[ n ].Name;
1227 : :
1228 : : std::vector< rtl::OUString >::const_iterator it
1229 [ # # ]: 0 : = m_aFailedPropNames.begin();
1230 : : std::vector< rtl::OUString >::const_iterator end
1231 [ # # ]: 0 : = m_aFailedPropNames.end();
1232 : :
1233 [ # # ][ # # ]: 0 : while ( it != end )
1234 : : {
1235 [ # # ]: 0 : if ( *it == rName )
1236 : 0 : break;
1237 : :
1238 : 0 : ++it;
1239 : : }
1240 : :
1241 [ # # ][ # # ]: 0 : if ( it == end )
1242 : : {
1243 [ # # ]: 0 : aProperties[ nProps ] = rProperties[ n ];
1244 : 0 : nProps++;
1245 : : }
1246 : : }
1247 : :
1248 [ # # ]: 0 : aProperties.realloc( nProps );
1249 : : }
1250 : : else
1251 : : {
1252 [ # # ]: 0 : aProperties = rProperties;
1253 : : }
1254 : :
1255 [ # # ]: 0 : if ( aProperties.getLength() > 0 )
1256 : : ContentProperties::UCBNamesToDAVNames(
1257 [ # # ]: 0 : aProperties, aPropNames );
1258 : :
1259 [ # # ]: 0 : if ( !aPropNames.empty() )
1260 : : {
1261 [ # # ]: 0 : std::vector< DAVResource > resources;
1262 : : try
1263 : : {
1264 : : xResAccess->PROPFIND(
1265 [ # # ]: 0 : DAVZERO, aPropNames, resources, xEnv );
1266 : :
1267 [ # # ]: 0 : if ( 1 == resources.size() )
1268 : : {
1269 [ # # ]: 0 : if ( xProps.get())
1270 : : xProps->addProperties(
1271 : : aPropNames,
1272 [ # # ][ # # ]: 0 : ContentProperties( resources[ 0 ] ));
[ # # ]
1273 : : else
1274 : : xProps.reset(
1275 [ # # ][ # # ]: 0 : new ContentProperties( resources[ 0 ] ) );
1276 : : }
1277 : : }
1278 [ # # ]: 0 : catch ( DAVException const & e )
1279 : : {
1280 : : bNetworkAccessAllowed
1281 : 0 : = shouldAccessNetworkAfterException( e );
1282 : :
1283 [ # # ]: 0 : if ( !bNetworkAccessAllowed )
1284 : : {
1285 [ # # ]: 0 : cancelCommandExecution( e, xEnv );
1286 : : // unreachable
1287 : : }
1288 : 0 : }
1289 [ # # ]: 0 : }
1290 : : }
1291 : : }
1292 : :
1293 [ # # ]: 0 : if ( bNetworkAccessAllowed )
1294 : : {
1295 : : // All properties obtained already?
1296 [ # # ]: 0 : std::vector< rtl::OUString > aMissingProps;
1297 [ # # ][ # # ]: 0 : if ( !( xProps.get()
[ # # ]
1298 : : && xProps->containsAllNames(
1299 [ # # ][ # # ]: 0 : rProperties, aMissingProps ) )
1300 : 0 : && !m_bDidGetOrHead )
1301 : : {
1302 : : // Possibly the missing props can be obtained using a HEAD
1303 : : // request.
1304 : :
1305 [ # # ]: 0 : std::vector< rtl::OUString > aHeaderNames;
1306 : : ContentProperties::UCBNamesToHTTPNames(
1307 : : rProperties,
1308 : : aHeaderNames,
1309 [ # # ]: 0 : true /* bIncludeUnmatched */ );
1310 : :
1311 [ # # ]: 0 : if ( !aHeaderNames.empty() )
1312 : : {
1313 : : try
1314 : : {
1315 [ # # ]: 0 : DAVResource resource;
1316 [ # # ]: 0 : xResAccess->HEAD( aHeaderNames, resource, xEnv );
1317 : 0 : m_bDidGetOrHead = true;
1318 : :
1319 [ # # ]: 0 : if ( xProps.get() )
1320 : : xProps->addProperties(
1321 : : aMissingProps,
1322 [ # # ][ # # ]: 0 : ContentProperties( resource ) );
[ # # ]
1323 : : else
1324 [ # # ][ # # ]: 0 : xProps.reset ( new ContentProperties( resource ) );
1325 : :
1326 [ # # ]: 0 : if ( m_eResourceType == NON_DAV )
1327 : : xProps->addProperties( aMissingProps,
1328 : : ContentProperties(
1329 : : aUnescapedTitle,
1330 [ # # ][ # # ]: 0 : false ) );
[ # # ]
1331 : : }
1332 [ # # ]: 0 : catch ( DAVException const & e )
1333 : : {
1334 : : bNetworkAccessAllowed
1335 : 0 : = shouldAccessNetworkAfterException( e );
1336 : :
1337 [ # # ]: 0 : if ( !bNetworkAccessAllowed )
1338 : : {
1339 [ # # ]: 0 : cancelCommandExecution( e, xEnv );
1340 : : // unreachable
1341 : : }
1342 : : }
1343 : 0 : }
1344 : 0 : }
1345 : : }
1346 : :
1347 : : // might trigger HTTP redirect.
1348 : : // Therefore, title must be updated here.
1349 [ # # ]: 0 : NeonUri aUri( xResAccess->getURL() );
1350 [ # # ]: 0 : aUnescapedTitle = aUri.GetPathBaseNameUnescaped();
1351 : :
1352 [ # # ]: 0 : if ( rType == UNKNOWN )
1353 : : {
1354 [ # # ][ # # ]: 0 : xProps.reset( new ContentProperties( aUnescapedTitle ) );
1355 : : }
1356 : :
1357 : : // For DAV resources we only know the Title, for non-DAV
1358 : : // resources we additionally know that it is a document.
1359 : :
1360 [ # # ]: 0 : if ( rType == DAV )
1361 : : {
1362 : : //xProps.reset(
1363 : : // new ContentProperties( aUnescapedTitle ) );
1364 : : xProps->addProperty(
1365 : : rtl::OUString( "Title" ),
1366 : : uno::makeAny( aUnescapedTitle ),
1367 [ # # ][ # # ]: 0 : true );
1368 : : }
1369 : : else
1370 : : {
1371 [ # # ]: 0 : if ( !xProps.get() )
1372 [ # # ][ # # ]: 0 : xProps.reset( new ContentProperties( aUnescapedTitle, false ) );
1373 : : else
1374 : : xProps->addProperty(
1375 : : rtl::OUString( "Title" ),
1376 : : uno::makeAny( aUnescapedTitle ),
1377 [ # # ][ # # ]: 0 : true );
1378 : :
1379 : : xProps->addProperty(
1380 : : rtl::OUString( "IsFolder" ),
1381 : : uno::makeAny( false ),
1382 [ # # ][ # # ]: 0 : true );
1383 : : xProps->addProperty(
1384 : : rtl::OUString( "IsDocument" ),
1385 : : uno::makeAny( true ),
1386 [ # # ][ # # ]: 0 : true );
1387 [ # # ]: 0 : }
1388 : : }
1389 : : else
1390 : : {
1391 : : // No server access for just created (not yet committed) objects.
1392 : : // Only a minimal set of properties supported at this stage.
1393 [ # # ]: 0 : if (m_bTransient)
1394 : : xProps.reset( new ContentProperties( aUnescapedTitle,
1395 [ # # ][ # # ]: 0 : m_bCollection ) );
1396 : : }
1397 : :
1398 : 0 : sal_Int32 nCount = rProperties.getLength();
1399 [ # # ]: 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
1400 : : {
1401 : 0 : const rtl::OUString rName = rProperties[ n ].Name;
1402 [ # # ]: 0 : if ( rName == "BaseURI" )
1403 : : {
1404 : : // Add BaseURI property, if requested.
1405 : : xProps->addProperty(
1406 : : rtl::OUString( "BaseURI" ),
1407 : : uno::makeAny( getBaseURI( xResAccess ) ),
1408 [ # # ][ # # ]: 0 : true );
[ # # ]
1409 : : }
1410 [ # # ]: 0 : else if ( rName == "CreatableContentsInfo" )
1411 : : {
1412 : : // Add CreatableContentsInfo property, if requested.
1413 : 0 : sal_Bool bFolder = sal_False;
1414 : : xProps->getValue(
1415 [ # # ]: 0 : rtl::OUString( "IsFolder" ) )
1416 : 0 : >>= bFolder;
1417 : : xProps->addProperty(
1418 : : rtl::OUString( "CreatableContentsInfo" ),
1419 : : uno::makeAny( bFolder
1420 : 0 : ? queryCreatableContentsInfo()
1421 : : : uno::Sequence< ucb::ContentInfo >() ),
1422 [ # # ][ # # ]: 0 : true );
[ # # ][ # # ]
[ # # ][ # # ]
1423 : : }
1424 : 0 : }
1425 : :
1426 : : uno::Reference< sdbc::XRow > xResultRow
1427 : : = getPropertyValues( xSMgr,
1428 : : rProperties,
1429 : 0 : *xProps,
1430 : : xProvider,
1431 [ # # ]: 0 : xIdentifier->getContentIdentifier() );
[ # # # # ]
1432 : :
1433 : : {
1434 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1435 : :
1436 [ # # ]: 0 : if ( !m_xCachedProps.get() )
1437 [ # # ][ # # ]: 0 : m_xCachedProps.reset( new CachableContentProperties( *xProps.get() ) );
1438 : : else
1439 [ # # ]: 0 : m_xCachedProps->addProperties( *xProps.get() );
1440 : :
1441 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
1442 [ # # ][ # # ]: 0 : m_aEscapedTitle = NeonUri::escapeSegment( aUnescapedTitle );
1443 : : }
1444 : :
1445 [ # # ][ # # ]: 0 : return xResultRow;
[ # # ]
1446 : : }
1447 : :
1448 : : //=========================================================================
1449 : 0 : uno::Sequence< uno::Any > Content::setPropertyValues(
1450 : : const uno::Sequence< beans::PropertyValue >& rValues,
1451 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1452 : : throw ( uno::Exception )
1453 : : {
1454 : 0 : uno::Reference< lang::XMultiServiceFactory > xSMgr;
1455 : 0 : uno::Reference< ucb::XContentIdentifier > xIdentifier;
1456 : 0 : rtl::Reference< ContentProvider > xProvider;
1457 : : sal_Bool bTransient;
1458 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1459 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
1460 : : SAL_WNODEPRECATED_DECLARATIONS_POP
1461 : :
1462 : : {
1463 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1464 : :
1465 : 0 : xProvider.set( m_pProvider );
1466 [ # # ]: 0 : xIdentifier.set( m_xIdentifier );
1467 : 0 : bTransient = m_bTransient;
1468 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
1469 [ # # ][ # # ]: 0 : xSMgr.set( m_xSMgr );
1470 : : }
1471 : :
1472 [ # # ]: 0 : uno::Sequence< uno::Any > aRet( rValues.getLength() );
1473 [ # # ]: 0 : uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() );
1474 : 0 : sal_Int32 nChanged = 0;
1475 : :
1476 [ # # ]: 0 : beans::PropertyChangeEvent aEvent;
1477 [ # # ]: 0 : aEvent.Source = static_cast< cppu::OWeakObject * >( this );
1478 : 0 : aEvent.Further = sal_False;
1479 : : // aEvent.PropertyName =
1480 : 0 : aEvent.PropertyHandle = -1;
1481 : : // aEvent.OldValue =
1482 : : // aEvent.NewValue =
1483 : :
1484 [ # # ]: 0 : std::vector< ProppatchValue > aProppatchValues;
1485 [ # # ]: 0 : std::vector< sal_Int32 > aProppatchPropsPositions;
1486 : :
1487 : 0 : uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet;
1488 : 0 : sal_Bool bTriedToGetAdditonalPropSet = sal_False;
1489 : :
1490 : 0 : sal_Bool bExchange = sal_False;
1491 : 0 : rtl::OUString aNewTitle;
1492 : 0 : rtl::OUString aOldTitle;
1493 : 0 : sal_Int32 nTitlePos = -1;
1494 : :
1495 : 0 : uno::Reference< beans::XPropertySetInfo > xInfo;
1496 : :
1497 : 0 : const beans::PropertyValue* pValues = rValues.getConstArray();
1498 : 0 : sal_Int32 nCount = rValues.getLength();
1499 [ # # ]: 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
1500 : : {
1501 : 0 : const beans::PropertyValue& rValue = pValues[ n ];
1502 : 0 : const rtl::OUString & rName = rValue.Name;
1503 : :
1504 : 0 : beans::Property aTmpProp;
1505 [ # # ]: 0 : xProvider->getProperty( rName, aTmpProp );
1506 : :
1507 [ # # ]: 0 : if ( aTmpProp.Attributes & beans::PropertyAttribute::READONLY )
1508 : : {
1509 : : // Read-only property!
1510 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1511 : : rtl::OUString( "Property is read-only!" ),
1512 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1513 : 0 : continue;
1514 : : }
1515 : :
1516 : : //////////////////////////////////////////////////////////////////
1517 : : // Mandatory props.
1518 : : //////////////////////////////////////////////////////////////////
1519 : :
1520 [ # # ]: 0 : if ( rName == "ContentType" )
1521 : : {
1522 : : // Read-only property!
1523 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1524 : : rtl::OUString( "Property is read-only!" ),
1525 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1526 : : }
1527 [ # # ]: 0 : else if ( rName == "IsDocument" )
1528 : : {
1529 : : // Read-only property!
1530 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1531 : : rtl::OUString( "Property is read-only!" ),
1532 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1533 : : }
1534 [ # # ]: 0 : else if ( rName == "IsFolder" )
1535 : : {
1536 : : // Read-only property!
1537 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1538 : : rtl::OUString( "Property is read-only!" ),
1539 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1540 : : }
1541 [ # # ]: 0 : else if ( rName == "Title" )
1542 : : {
1543 : 0 : rtl::OUString aNewValue;
1544 [ # # ]: 0 : if ( rValue.Value >>= aNewValue )
1545 : : {
1546 : : // No empty titles!
1547 [ # # ]: 0 : if ( !aNewValue.isEmpty() )
1548 : : {
1549 : : try
1550 : : {
1551 [ # # ][ # # ]: 0 : NeonUri aURI( xIdentifier->getContentIdentifier() );
[ # # ]
1552 [ # # ]: 0 : aOldTitle = aURI.GetPathBaseNameUnescaped();
1553 : :
1554 [ # # ]: 0 : if ( aNewValue != aOldTitle )
1555 : : {
1556 : : // modified title -> modified URL -> exchange !
1557 [ # # ]: 0 : if ( !bTransient )
1558 : 0 : bExchange = sal_True;
1559 : :
1560 : : // new value will be set later...
1561 : 0 : aNewTitle = aNewValue;
1562 : :
1563 : : // remember position within sequence of values (for
1564 : : // error handling).
1565 : 0 : nTitlePos = n;
1566 [ # # ]: 0 : }
1567 : : }
1568 [ # # ]: 0 : catch ( DAVException const & )
1569 : : {
1570 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalArgumentException(
1571 : : rtl::OUString( "Invalid content identifier!" ),
1572 : : static_cast< cppu::OWeakObject * >( this ),
1573 [ # # # # : 0 : -1 );
# # # # ]
1574 : : }
1575 : : }
1576 : : else
1577 : : {
1578 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalArgumentException(
1579 : : rtl::OUString( "Empty title not allowed!" ),
1580 : : static_cast< cppu::OWeakObject * >( this ),
1581 [ # # ][ # # ]: 0 : -1 );
[ # # ][ # # ]
1582 : : }
1583 : : }
1584 : : else
1585 : : {
1586 [ # # ]: 0 : aRet[ n ] <<= beans::IllegalTypeException(
1587 : : rtl::OUString( "Property value has wrong type!" ),
1588 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1589 : 0 : }
1590 : : }
1591 : : else
1592 : : {
1593 : : //////////////////////////////////////////////////////////////
1594 : : // Optional props.
1595 : : //////////////////////////////////////////////////////////////
1596 : :
1597 [ # # ]: 0 : if ( !xInfo.is() )
1598 : : xInfo = getPropertySetInfo( xEnv,
1599 [ # # ][ # # ]: 0 : sal_False /* don't cache data */ );
1600 : :
1601 [ # # ][ # # ]: 0 : if ( !xInfo->hasPropertyByName( rName ) )
[ # # ]
1602 : : {
1603 : : // Check, whether property exists. Skip otherwise.
1604 : : // PROPPATCH::set would add the property automatically, which
1605 : : // is not allowed for "setPropertyValues" command!
1606 [ # # ]: 0 : aRet[ n ] <<= beans::UnknownPropertyException(
1607 : : rtl::OUString( "Property is unknown!" ),
1608 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1609 : 0 : continue;
1610 : : }
1611 : :
1612 [ # # ]: 0 : if ( rName == "Size" )
1613 : : {
1614 : : // Read-only property!
1615 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1616 : : rtl::OUString( "Property is read-only!" ),
1617 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1618 : : }
1619 [ # # ]: 0 : else if ( rName == "DateCreated" )
1620 : : {
1621 : : // Read-only property!
1622 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1623 : : rtl::OUString( "Property is read-only!" ),
1624 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1625 : : }
1626 [ # # ]: 0 : else if ( rName == "DateModified" )
1627 : : {
1628 : : // Read-only property!
1629 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1630 : : rtl::OUString( "Property is read-only!" ),
1631 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1632 : : }
1633 [ # # ]: 0 : else if ( rName == "MediaType" )
1634 : : {
1635 : : // Read-only property!
1636 : : // (but could be writable, if 'getcontenttype' would be)
1637 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1638 : : rtl::OUString( "Property is read-only!" ),
1639 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1640 : : }
1641 [ # # ]: 0 : if ( rName == "CreatableContentsInfo" )
1642 : : {
1643 : : // Read-only property!
1644 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1645 : : rtl::OUString( "Property is read-only!" ),
1646 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1647 : : }
1648 : : else
1649 : : {
1650 [ # # ][ # # ]: 0 : if ( getResourceType( xEnv, xResAccess ) == DAV )
1651 : : {
1652 : : // Property value will be set on server.
1653 : 0 : ProppatchValue aValue( PROPSET, rName, rValue.Value );
1654 [ # # ]: 0 : aProppatchValues.push_back( aValue );
1655 : :
1656 : : // remember position within sequence of values (for
1657 : : // error handling).
1658 [ # # ]: 0 : aProppatchPropsPositions.push_back( n );
1659 : : }
1660 : : else
1661 : : {
1662 : : // Property value will be stored in local property store.
1663 [ # # # # ]: 0 : if ( !bTriedToGetAdditonalPropSet &&
[ # # ]
1664 : 0 : !xAdditionalPropSet.is() )
1665 : : {
1666 : : xAdditionalPropSet
1667 [ # # ][ # # ]: 0 : = getAdditionalPropertySet( sal_False );
1668 : 0 : bTriedToGetAdditonalPropSet = sal_True;
1669 : : }
1670 : :
1671 [ # # ]: 0 : if ( xAdditionalPropSet.is() )
1672 : : {
1673 : : try
1674 : : {
1675 : : uno::Any aOldValue
1676 [ # # ][ # # ]: 0 : = xAdditionalPropSet->getPropertyValue( rName );
1677 [ # # ]: 0 : if ( aOldValue != rValue.Value )
1678 : : {
1679 [ # # ]: 0 : xAdditionalPropSet->setPropertyValue(
1680 [ # # ]: 0 : rName, rValue.Value );
1681 : :
1682 : 0 : aEvent.PropertyName = rName;
1683 : 0 : aEvent.OldValue = aOldValue;
1684 : 0 : aEvent.NewValue = rValue.Value;
1685 : :
1686 [ # # ][ # # ]: 0 : aChanges.getArray()[ nChanged ] = aEvent;
1687 : 0 : nChanged++;
1688 : 0 : }
1689 : : }
1690 [ # # ]: 0 : catch ( beans::UnknownPropertyException const & e )
1691 : : {
1692 [ # # # # ]: 0 : aRet[ n ] <<= e;
1693 : : }
1694 [ # # ]: 0 : catch ( lang::WrappedTargetException const & e )
1695 : : {
1696 [ # # # # ]: 0 : aRet[ n ] <<= e;
1697 : : }
1698 [ # # ]: 0 : catch ( beans::PropertyVetoException const & e )
1699 : : {
1700 [ # # # # ]: 0 : aRet[ n ] <<= e;
1701 : : }
1702 [ # # # # : 0 : catch ( lang::IllegalArgumentException const & e )
# # # ]
1703 : : {
1704 [ # # # # ]: 0 : aRet[ n ] <<= e;
1705 : : }
1706 : : }
1707 : : else
1708 : : {
1709 [ # # ]: 0 : aRet[ n ] <<= uno::Exception(
1710 : : rtl::OUString( "No property set for storing the value!" ),
1711 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1712 : : }
1713 : : }
1714 : : }
1715 : : }
1716 [ # # ]: 0 : } // for
1717 : :
1718 [ # # ][ # # ]: 0 : if ( !bTransient && !aProppatchValues.empty() )
[ # # ]
1719 : : {
1720 : : try
1721 : : {
1722 : : // Set property values at server.
1723 [ # # ]: 0 : xResAccess->PROPPATCH( aProppatchValues, xEnv );
1724 : :
1725 : : std::vector< ProppatchValue >::const_iterator it
1726 [ # # ]: 0 : = aProppatchValues.begin();
1727 : : std::vector< ProppatchValue >::const_iterator end
1728 [ # # ]: 0 : = aProppatchValues.end();
1729 : :
1730 [ # # ][ # # ]: 0 : while ( it != end )
1731 : : {
1732 : 0 : aEvent.PropertyName = (*it).name;
1733 : 0 : aEvent.OldValue = uno::Any(); // @@@ to expensive to obtain!
1734 : 0 : aEvent.NewValue = (*it).value;
1735 : :
1736 [ # # ][ # # ]: 0 : aChanges.getArray()[ nChanged ] = aEvent;
1737 : 0 : nChanged++;
1738 : :
1739 : 0 : ++it;
1740 : : }
1741 : : }
1742 [ # # ]: 0 : catch ( DAVException const & e )
1743 : : {
1744 : : // OSL_FAIL( // "Content::setPropertyValues - PROPPATCH failed!" );
1745 : :
1746 [ # # ]: 0 : cancelCommandExecution( e, xEnv );
1747 : : // unreachable
1748 : : }
1749 : : }
1750 : :
1751 [ # # ]: 0 : if ( bExchange )
1752 : : {
1753 : : // Assemble new content identifier...
1754 : :
1755 [ # # ]: 0 : rtl::OUString aNewURL = getParentURL();
1756 [ # # ]: 0 : if ( aNewURL.lastIndexOf( '/' ) != ( aNewURL.getLength() - 1 ) )
1757 : 0 : aNewURL += rtl::OUString("/");
1758 : :
1759 [ # # ]: 0 : aNewURL += NeonUri::escapeSegment( aNewTitle );
1760 : :
1761 : : uno::Reference< ucb::XContentIdentifier > xNewId
1762 [ # # ][ # # ]: 0 : = new ::ucbhelper::ContentIdentifier( xSMgr, aNewURL );
[ # # ]
1763 : 0 : uno::Reference< ucb::XContentIdentifier > xOldId = xIdentifier;
1764 : :
1765 : : try
1766 : : {
1767 [ # # ][ # # ]: 0 : NeonUri sourceURI( xOldId->getContentIdentifier() );
[ # # ]
1768 [ # # ][ # # ]: 0 : NeonUri targetURI( xNewId->getContentIdentifier() );
[ # # ]
1769 [ # # ]: 0 : targetURI.SetScheme( sourceURI.GetScheme() );
1770 : :
1771 : : xResAccess->MOVE(
1772 [ # # ]: 0 : sourceURI.GetPath(), targetURI.GetURI(), sal_False, xEnv );
1773 : : // @@@ Should check for resources that could not be moved
1774 : : // (due to source access or target overwrite) and send
1775 : : // this information through the interaction handler.
1776 : :
1777 : : // @@@ Existing content should be checked to see if it needs
1778 : : // to be deleted at the source
1779 : :
1780 : : // @@@ Existing content should be checked to see if it has
1781 : : // been overwritten at the target
1782 : :
1783 [ # # ][ # # ]: 0 : if ( exchangeIdentity( xNewId ) )
1784 : : {
1785 [ # # ]: 0 : xResAccess->setURL( aNewURL );
1786 : :
1787 : : // DAV resources store all additional props on server!
1788 : : // // Adapt Additional Core Properties.
1789 : : // renameAdditionalPropertySet( xOldId->getContentIdentifier(),
1790 : : // xNewId->getContentIdentifier(),
1791 : : // sal_True );
1792 : : }
1793 : : else
1794 : : {
1795 : : // Do not set new title!
1796 : 0 : aNewTitle = rtl::OUString();
1797 : :
1798 : : // Set error .
1799 [ # # ]: 0 : aRet[ nTitlePos ] <<= uno::Exception(
1800 : : rtl::OUString("Exchange failed!"),
1801 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
1802 [ # # ][ # # ]: 0 : }
1803 : : }
1804 [ # # ]: 0 : catch ( DAVException const & e )
1805 : : {
1806 : : // Do not set new title!
1807 : 0 : aNewTitle = rtl::OUString();
1808 : :
1809 : : // Set error .
1810 [ # # # # : 0 : aRet[ nTitlePos ] <<= MapDAVException( e, sal_True );
# # ]
1811 : 0 : }
1812 : : }
1813 : :
1814 [ # # ]: 0 : if ( !aNewTitle.isEmpty() )
1815 : : {
1816 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1817 : :
1818 : 0 : aEvent.PropertyName = rtl::OUString("Title");
1819 [ # # ]: 0 : aEvent.OldValue = uno::makeAny( aOldTitle );
1820 [ # # ]: 0 : aEvent.NewValue = uno::makeAny( aNewTitle );
1821 : :
1822 [ # # ]: 0 : m_aEscapedTitle = NeonUri::escapeSegment( aNewTitle );
1823 : :
1824 [ # # ][ # # ]: 0 : aChanges.getArray()[ nChanged ] = aEvent;
1825 [ # # ]: 0 : nChanged++;
1826 : : }
1827 : :
1828 [ # # ]: 0 : if ( nChanged > 0 )
1829 : : {
1830 [ # # ]: 0 : aChanges.realloc( nChanged );
1831 [ # # ]: 0 : notifyPropertiesChange( aChanges );
1832 : : }
1833 : :
1834 : : {
1835 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1836 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
1837 : : }
1838 : :
1839 [ # # ][ # # ]: 0 : return aRet;
[ # # ]
1840 : : }
1841 : :
1842 : : //=========================================================================
1843 : 0 : uno::Any Content::open(
1844 : : const ucb::OpenCommandArgument3 & rArg,
1845 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1846 : : throw( uno::Exception )
1847 : : {
1848 : 0 : uno::Any aRet;
1849 : :
1850 : : sal_Bool bOpenFolder = ( ( rArg.Mode == ucb::OpenMode::ALL ) ||
1851 : : ( rArg.Mode == ucb::OpenMode::FOLDERS ) ||
1852 [ # # ][ # # ]: 0 : ( rArg.Mode == ucb::OpenMode::DOCUMENTS ) );
[ # # ]
1853 [ # # ]: 0 : if ( bOpenFolder )
1854 : : {
1855 [ # # ][ # # ]: 0 : if ( isFolder( xEnv ) )
1856 : : {
1857 : : // Open collection.
1858 : :
1859 : : uno::Reference< ucb::XDynamicResultSet > xSet
1860 [ # # ][ # # ]: 0 : = new DynamicResultSet( m_xSMgr, this, rArg, xEnv );
[ # # ]
1861 [ # # ]: 0 : aRet <<= xSet;
1862 : : }
1863 : : else
1864 : : {
1865 : : // Error: Not a folder!
1866 : :
1867 : 0 : rtl::OUStringBuffer aMsg;
1868 [ # # ][ # # ]: 0 : if ( getResourceType( xEnv ) == FTP )
1869 : : {
1870 : : // #114653#
1871 : : aMsg.appendAscii( "FTP over HTTP proxy: resource cannot "
1872 [ # # ]: 0 : "be opened as folder! Wrong Open Mode!" );
1873 : : }
1874 : : else
1875 : : {
1876 : : aMsg.appendAscii( "Non-folder resource cannot be "
1877 [ # # ]: 0 : "opened as folder! Wrong Open Mode!" );
1878 : : }
1879 : :
1880 : : ucbhelper::cancelCommandExecution(
1881 : : uno::makeAny(
1882 : : lang::IllegalArgumentException(
1883 : : aMsg.makeStringAndClear(),
1884 : : static_cast< cppu::OWeakObject * >( this ),
1885 : : -1 ) ),
1886 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ][ # # ]
1887 : : // Unreachable
1888 : : }
1889 : : }
1890 : :
1891 [ # # ]: 0 : if ( rArg.Sink.is() )
1892 : : {
1893 : : // Open document.
1894 : :
1895 [ # # ][ # # ]: 0 : if ( ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
1896 : : ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) )
1897 : : {
1898 : : // Currently(?) unsupported.
1899 : : ucbhelper::cancelCommandExecution(
1900 : : uno::makeAny(
1901 : : ucb::UnsupportedOpenModeException(
1902 : : rtl::OUString(),
1903 : : static_cast< cppu::OWeakObject * >( this ),
1904 : : sal_Int16( rArg.Mode ) ) ),
1905 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
1906 : : // Unreachable
1907 : : }
1908 : :
1909 [ # # ][ # # ]: 0 : rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
1910 : : uno::Reference< io::XOutputStream > xOut
1911 [ # # ]: 0 : = uno::Reference< io::XOutputStream >( rArg.Sink, uno::UNO_QUERY );
1912 [ # # ]: 0 : if ( xOut.is() )
1913 : : {
1914 : : // PUSH: write data
1915 : : try
1916 : : {
1917 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1918 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
1919 : : SAL_WNODEPRECATED_DECLARATIONS_POP
1920 : :
1921 : : {
1922 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
1923 : :
1924 : : xResAccess.reset(
1925 [ # # ][ # # ]: 0 : new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
1926 : : }
1927 : :
1928 [ # # ]: 0 : xResAccess->setFlags( rArg.OpeningFlags );
1929 [ # # ]: 0 : DAVResource aResource;
1930 [ # # ]: 0 : std::vector< rtl::OUString > aHeaders;
1931 : :
1932 [ # # ]: 0 : xResAccess->GET( xOut, aHeaders, aResource, xEnv );
1933 : 0 : m_bDidGetOrHead = true;
1934 : :
1935 : : {
1936 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
1937 : :
1938 : : // cache headers.
1939 [ # # ]: 0 : if ( !m_xCachedProps.get())
1940 : : m_xCachedProps.reset(
1941 [ # # ][ # # ]: 0 : new CachableContentProperties( aResource ) );
[ # # ][ # # ]
1942 : : else
1943 [ # # ][ # # ]: 0 : m_xCachedProps->addProperties( aResource );
[ # # ]
1944 : :
1945 : : m_xResAccess.reset(
1946 [ # # ][ # # ]: 0 : new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
1947 [ # # ]: 0 : }
1948 : : }
1949 [ # # ]: 0 : catch ( DAVException const & e )
1950 : : {
1951 [ # # ]: 0 : cancelCommandExecution( e, xEnv );
1952 : : // Unreachable
1953 : : }
1954 : : }
1955 : : else
1956 : : {
1957 : : uno::Reference< io::XActiveDataSink > xDataSink
1958 : : = uno::Reference< io::XActiveDataSink >( rArg.Sink,
1959 [ # # ]: 0 : uno::UNO_QUERY );
1960 [ # # ]: 0 : if ( xDataSink.is() )
1961 : : {
1962 : : // PULL: wait for client read
1963 : : try
1964 : : {
1965 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1966 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
1967 : : SAL_WNODEPRECATED_DECLARATIONS_POP
1968 : : {
1969 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
1970 : :
1971 : : xResAccess.reset(
1972 [ # # ][ # # ]: 0 : new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
1973 : : }
1974 : :
1975 [ # # ]: 0 : xResAccess->setFlags( rArg.OpeningFlags );
1976 : :
1977 : : // fill inputsream sync; return if all data present
1978 [ # # ]: 0 : DAVResource aResource;
1979 [ # # ]: 0 : std::vector< rtl::OUString > aHeaders;
1980 : :
1981 : : uno::Reference< io::XInputStream > xIn
1982 [ # # ]: 0 : = xResAccess->GET( aHeaders, aResource, xEnv );
1983 : 0 : m_bDidGetOrHead = true;
1984 : :
1985 : : {
1986 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
1987 : :
1988 : : // cache headers.
1989 [ # # ]: 0 : if ( !m_xCachedProps.get())
1990 : : m_xCachedProps.reset(
1991 [ # # ][ # # ]: 0 : new CachableContentProperties( aResource ) );
[ # # ][ # # ]
1992 : : else
1993 : : m_xCachedProps->addProperties(
1994 [ # # ]: 0 : aResource.properties );
1995 : :
1996 : : m_xResAccess.reset(
1997 [ # # ][ # # ]: 0 : new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
1998 : : }
1999 : :
2000 [ # # ][ # # ]: 0 : xDataSink->setInputStream( xIn );
[ # # ]
2001 : : }
2002 [ # # ]: 0 : catch ( DAVException const & e )
2003 : : {
2004 [ # # ]: 0 : cancelCommandExecution( e, xEnv );
2005 : : // Unreachable
2006 : : }
2007 : : }
2008 : : else
2009 : : {
2010 : : // Note: aOpenCommand.Sink may contain an XStream
2011 : : // implementation. Support for this type of
2012 : : // sink is optional...
2013 : : ucbhelper::cancelCommandExecution(
2014 : : uno::makeAny(
2015 : : ucb::UnsupportedDataSinkException(
2016 : : rtl::OUString(),
2017 : : static_cast< cppu::OWeakObject * >( this ),
2018 : : rArg.Sink ) ),
2019 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
2020 : : // Unreachable
2021 : 0 : }
2022 : 0 : }
2023 : : }
2024 : :
2025 : 0 : return aRet;
2026 : : }
2027 : :
2028 : : //=========================================================================
2029 : 0 : void Content::post(
2030 : : const ucb::PostCommandArgument2 & rArg,
2031 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2032 : : throw( uno::Exception )
2033 : : {
2034 [ # # ]: 0 : uno::Reference< io::XActiveDataSink > xSink( rArg.Sink, uno::UNO_QUERY );
2035 [ # # ]: 0 : if ( xSink.is() )
2036 : : {
2037 : : try
2038 : : {
2039 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2040 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
2041 : : SAL_WNODEPRECATED_DECLARATIONS_POP
2042 : : {
2043 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
2044 : : xResAccess.reset(
2045 [ # # ][ # # ]: 0 : new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
2046 : : }
2047 : :
2048 : : uno::Reference< io::XInputStream > xResult
2049 : : = xResAccess->POST( rArg.MediaType,
2050 : : rArg.Referer,
2051 : : rArg.Source,
2052 [ # # ]: 0 : xEnv );
2053 : :
2054 : : {
2055 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
2056 : : m_xResAccess.reset(
2057 [ # # ][ # # ]: 0 : new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
2058 : : }
2059 : :
2060 [ # # ][ # # ]: 0 : xSink->setInputStream( xResult );
[ # # ]
2061 : : }
2062 [ # # ]: 0 : catch ( DAVException const & e )
2063 : : {
2064 [ # # ]: 0 : cancelCommandExecution( e, xEnv, sal_True );
2065 : : // Unreachable
2066 : : }
2067 : : }
2068 : : else
2069 : : {
2070 [ # # ]: 0 : uno::Reference< io::XOutputStream > xResult( rArg.Sink, uno::UNO_QUERY );
2071 [ # # ]: 0 : if ( xResult.is() )
2072 : : {
2073 : : try
2074 : : {
2075 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2076 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
2077 : : SAL_WNODEPRECATED_DECLARATIONS_POP
2078 : : {
2079 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
2080 : : xResAccess.reset(
2081 [ # # ][ # # ]: 0 : new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
2082 : : }
2083 : :
2084 : : xResAccess->POST( rArg.MediaType,
2085 : : rArg.Referer,
2086 : : rArg.Source,
2087 : : xResult,
2088 [ # # ]: 0 : xEnv );
2089 : :
2090 : : {
2091 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
2092 : : m_xResAccess.reset(
2093 [ # # ][ # # ]: 0 : new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
2094 [ # # ]: 0 : }
2095 : : }
2096 [ # # ]: 0 : catch ( DAVException const & e )
2097 : : {
2098 [ # # ]: 0 : cancelCommandExecution( e, xEnv, sal_True );
2099 : : // Unreachable
2100 : : }
2101 : : }
2102 : : else
2103 : : {
2104 : : ucbhelper::cancelCommandExecution(
2105 : : uno::makeAny(
2106 : : ucb::UnsupportedDataSinkException(
2107 : : rtl::OUString(),
2108 : : static_cast< cppu::OWeakObject * >( this ),
2109 : : rArg.Sink ) ),
2110 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
2111 : : // Unreachable
2112 : 0 : }
2113 : 0 : }
2114 : 0 : }
2115 : :
2116 : : //=========================================================================
2117 : 0 : void Content::queryChildren( ContentRefList& rChildren )
2118 : : {
2119 : : // Obtain a list with a snapshot of all currently instanciated contents
2120 : : // from provider and extract the contents which are direct children
2121 : : // of this content.
2122 : :
2123 [ # # ]: 0 : ::ucbhelper::ContentRefList aAllContents;
2124 [ # # ]: 0 : m_xProvider->queryExistingContents( aAllContents );
2125 : :
2126 [ # # ][ # # ]: 0 : rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
2127 : 0 : sal_Int32 nURLPos = aURL.lastIndexOf( '/' );
2128 : :
2129 [ # # ]: 0 : if ( nURLPos != ( aURL.getLength() - 1 ) )
2130 : : {
2131 : : // No trailing slash found. Append.
2132 : 0 : aURL += rtl::OUString("/");
2133 : : }
2134 : :
2135 : 0 : sal_Int32 nLen = aURL.getLength();
2136 : :
2137 : 0 : ::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
2138 : 0 : ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
2139 : :
2140 [ # # ]: 0 : while ( it != end )
2141 : : {
2142 : 0 : ::ucbhelper::ContentImplHelperRef xChild = (*it);
2143 : : rtl::OUString aChildURL
2144 [ # # ][ # # ]: 0 : = xChild->getIdentifier()->getContentIdentifier();
[ # # ]
2145 : :
2146 : : // Is aURL a prefix of aChildURL?
2147 [ # # ]: 0 : if ( ( aChildURL.getLength() > nLen ) &&
[ # # # # ]
2148 : 0 : ( aChildURL.compareTo( aURL, nLen ) == 0 ) )
2149 : : {
2150 : 0 : sal_Int32 nPos = nLen;
2151 : 0 : nPos = aChildURL.indexOf( '/', nPos );
2152 : :
2153 [ # # ]: 0 : if ( ( nPos == -1 ) ||
[ # # # # ]
2154 : 0 : ( nPos == ( aChildURL.getLength() - 1 ) ) )
2155 : : {
2156 : : // No further slashes / only a final slash. It's a child!
2157 : : rChildren.push_back(
2158 : : ::webdav_ucp::Content::ContentRef(
2159 : : static_cast< ::webdav_ucp::Content * >(
2160 [ # # ]: 0 : xChild.get() ) ) );
2161 : : }
2162 : : }
2163 : 0 : ++it;
2164 : 0 : }
2165 : 0 : }
2166 : :
2167 : : //=========================================================================
2168 : 0 : void Content::insert(
2169 : : const uno::Reference< io::XInputStream > & xInputStream,
2170 : : sal_Bool bReplaceExisting,
2171 : : const uno::Reference< ucb::XCommandEnvironment >& Environment )
2172 : : throw( uno::Exception )
2173 : : {
2174 : : sal_Bool bTransient, bCollection;
2175 : 0 : rtl::OUString aEscapedTitle;
2176 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2177 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
2178 : : SAL_WNODEPRECATED_DECLARATIONS_POP
2179 : :
2180 : : {
2181 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2182 : :
2183 : 0 : bTransient = m_bTransient;
2184 : 0 : bCollection = m_bCollection;
2185 : 0 : aEscapedTitle = m_aEscapedTitle;
2186 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
2187 : : }
2188 : :
2189 : : // Check, if all required properties are present.
2190 : :
2191 [ # # ]: 0 : if ( aEscapedTitle.isEmpty() )
2192 : : {
2193 : : OSL_FAIL( "Content::insert - Title missing!" );
2194 : :
2195 [ # # ]: 0 : uno::Sequence< rtl::OUString > aProps( 1 );
2196 [ # # ]: 0 : aProps[ 0 ] = rtl::OUString("Title");
2197 : : ucbhelper::cancelCommandExecution(
2198 : : uno::makeAny( ucb::MissingPropertiesException(
2199 : : rtl::OUString(),
2200 : : static_cast< cppu::OWeakObject * >( this ),
2201 : : aProps ) ),
2202 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ][ # # ]
2203 : : // Unreachable
2204 : : }
2205 : :
2206 [ # # ]: 0 : if ( !bReplaceExisting )
2207 : : {
2208 : : /* [RFC 2616] - HTTP
2209 : :
2210 : : The PUT method requests that the enclosed entity be stored under the
2211 : : supplied Request-URI. If the Request-URI refers to an already
2212 : : existing resource, the enclosed entity SHOULD be considered as a
2213 : : modified version of the one residing on the origin server.
2214 : : */
2215 : :
2216 : : /* [RFC 2518] - WebDAV
2217 : :
2218 : : MKCOL creates a new collection resource at the location specified by
2219 : : the Request-URI. If the resource identified by the Request-URI is
2220 : : non-null then the MKCOL MUST fail.
2221 : : */
2222 : :
2223 : : // ==> Complain on PUT, continue on MKCOL.
2224 [ # # ][ # # ]: 0 : if ( !bTransient || ( bTransient && !bCollection ) )
[ # # ]
2225 : : {
2226 : : ucb::UnsupportedNameClashException aEx(
2227 : : rtl::OUString( "Unable to write without overwrite!" ),
2228 : : static_cast< cppu::OWeakObject * >( this ),
2229 [ # # ][ # # ]: 0 : ucb::NameClash::ERROR );
2230 : :
2231 : 0 : uno::Reference< task::XInteractionHandler > xIH;
2232 : :
2233 [ # # ]: 0 : if ( Environment.is() )
2234 [ # # ][ # # ]: 0 : xIH = Environment->getInteractionHandler();
[ # # ]
2235 : :
2236 [ # # ]: 0 : if ( xIH.is() )
2237 : : {
2238 [ # # ]: 0 : uno::Any aExAsAny( uno::makeAny( aEx ) );
2239 : :
2240 : : rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest
2241 : : = new ucbhelper::SimpleInteractionRequest(
2242 : : aExAsAny,
2243 : : ucbhelper::CONTINUATION_APPROVE
2244 [ # # ]: 0 : | ucbhelper::CONTINUATION_DISAPPROVE );
2245 [ # # ][ # # ]: 0 : xIH->handle( xRequest.get() );
[ # # ][ # # ]
2246 : :
2247 [ # # ]: 0 : const sal_Int32 nResp = xRequest->getResponse();
2248 : :
2249 [ # # # # ]: 0 : switch ( nResp )
2250 : : {
2251 : : case ucbhelper::CONTINUATION_UNKNOWN:
2252 : : // Not handled; throw.
2253 [ # # ]: 0 : throw aEx;
2254 : : // break;
2255 : :
2256 : : case ucbhelper::CONTINUATION_APPROVE:
2257 : : // Continue -> Overwrite.
2258 : 0 : bReplaceExisting = sal_True;
2259 : 0 : break;
2260 : :
2261 : : case ucbhelper::CONTINUATION_DISAPPROVE:
2262 : : // Abort.
2263 : : throw ucb::CommandFailedException(
2264 : : rtl::OUString(),
2265 : : uno::Reference< uno::XInterface >(),
2266 [ # # ]: 0 : aExAsAny );
2267 : : // break;
2268 : :
2269 : : default:
2270 : : OSL_FAIL( "Content::insert - "
2271 : : "Unknown interaction selection!" );
2272 : : throw ucb::CommandFailedException(
2273 : : rtl::OUString( "Unknown interaction selection!" ),
2274 : : uno::Reference< uno::XInterface >(),
2275 [ # # ]: 0 : aExAsAny );
2276 : : // break;
2277 : 0 : }
2278 : : }
2279 : : else
2280 : : {
2281 : : // No IH; throw.
2282 [ # # ]: 0 : throw aEx;
2283 [ # # ]: 0 : }
2284 : : }
2285 : : }
2286 : :
2287 [ # # ]: 0 : if ( bTransient )
2288 : : {
2289 : : // Assemble new content identifier...
2290 [ # # ]: 0 : rtl::OUString aURL = getParentURL();
2291 [ # # ]: 0 : if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) )
2292 : 0 : aURL += rtl::OUString("/");
2293 : :
2294 : 0 : aURL += aEscapedTitle;
2295 : :
2296 : : try
2297 : : {
2298 [ # # ]: 0 : xResAccess->setURL( aURL );
2299 : :
2300 [ # # ]: 0 : if ( bCollection )
2301 [ # # ]: 0 : xResAccess->MKCOL( Environment );
2302 : : else
2303 [ # # ]: 0 : xResAccess->PUT( xInputStream, Environment );
2304 : : }
2305 [ # # ]: 0 : catch ( DAVException const & except )
2306 : : {
2307 [ # # ]: 0 : if ( bCollection )
2308 : : {
2309 [ # # ]: 0 : if ( except.getStatus() == SC_METHOD_NOT_ALLOWED )
2310 : : {
2311 : : // [RFC 2518] - WebDAV
2312 : : // 405 (Method Not Allowed) - MKCOL can only be
2313 : : // executed on a deleted/non-existent resource.
2314 : :
2315 [ # # ]: 0 : if ( bReplaceExisting )
2316 : : {
2317 : : // Destroy old resource.
2318 : : try
2319 : : {
2320 [ # # ]: 0 : xResAccess->DESTROY( Environment );
2321 : : }
2322 [ # # ]: 0 : catch ( DAVException const & e )
2323 : : {
2324 [ # # ]: 0 : cancelCommandExecution( e, Environment, sal_True );
2325 : : // Unreachable
2326 : : }
2327 : :
2328 : : // Insert (recursion!).
2329 [ # # ]: 0 : insert( xInputStream, bReplaceExisting, Environment );
2330 : :
2331 : : {
2332 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2333 : : m_xResAccess.reset(
2334 [ # # # # : 0 : new DAVResourceAccess( *xResAccess.get() ) );
# # ]
2335 : : }
2336 : :
2337 : : // Success!
2338 : 0 : return;
2339 : : }
2340 : : else
2341 : : {
2342 : 0 : rtl::OUString aTitle;
2343 : : try
2344 : : {
2345 [ # # ]: 0 : NeonUri aURI( aURL );
2346 [ # # # # : 0 : aTitle = aURI.GetPathBaseNameUnescaped();
# # ]
2347 : : }
2348 : 0 : catch ( DAVException const & )
2349 : : {
2350 : : }
2351 : :
2352 : : ucbhelper::cancelCommandExecution(
2353 : : uno::makeAny(
2354 : : ucb::NameClashException(
2355 : : rtl::OUString(),
2356 : : static_cast< cppu::OWeakObject * >( this ),
2357 : : task::InteractionClassification_ERROR,
2358 : : aTitle ) ),
2359 [ # # # # : 0 : Environment );
# # # # #
# ]
2360 : : // Unreachable
2361 : : }
2362 : : }
2363 : : }
2364 : :
2365 [ # # # # ]: 0 : cancelCommandExecution( except, Environment, sal_True );
2366 : : // Unreachable
2367 : : }
2368 : :
2369 : : {
2370 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2371 : : m_xIdentifier
2372 [ # # ][ # # ]: 0 : = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL );
[ # # ][ # # ]
2373 : : }
2374 : :
2375 [ # # ]: 0 : inserted();
2376 : :
2377 : : {
2378 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2379 [ # # ]: 0 : m_bTransient = sal_False;
2380 [ # # ]: 0 : }
2381 : : }
2382 : : else
2383 : : {
2384 [ # # ]: 0 : if ( !xInputStream.is() )
2385 : : {
2386 : : ucbhelper::cancelCommandExecution(
2387 : : uno::makeAny(
2388 : : ucb::MissingInputStreamException(
2389 : : rtl::OUString(),
2390 : : static_cast< cppu::OWeakObject * >( this ) ) ),
2391 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
2392 : : // Unreachable
2393 : : }
2394 : :
2395 : : try
2396 : : {
2397 [ # # ]: 0 : xResAccess->PUT( xInputStream, Environment );
2398 : : }
2399 [ # # ]: 0 : catch ( DAVException const & e )
2400 : : {
2401 [ # # ]: 0 : cancelCommandExecution( e, Environment, sal_True );
2402 : : // Unreachable
2403 : : }
2404 : : }
2405 : :
2406 : : {
2407 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2408 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
2409 [ # # ][ # # ]: 0 : }
[ # # ]
2410 : : }
2411 : :
2412 : : //=========================================================================
2413 : 0 : void Content::transfer(
2414 : : const ucb::TransferInfo & rArgs,
2415 : : const uno::Reference< ucb::XCommandEnvironment >& Environment )
2416 : : throw( uno::Exception )
2417 : : {
2418 : 0 : uno::Reference< lang::XMultiServiceFactory > xSMgr;
2419 : 0 : uno::Reference< ucb::XContentIdentifier > xIdentifier;
2420 : 0 : uno::Reference< ucb::XContentProvider > xProvider;
2421 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2422 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
2423 : : SAL_WNODEPRECATED_DECLARATIONS_POP
2424 : :
2425 : : {
2426 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2427 : :
2428 [ # # ]: 0 : xSMgr.set( m_xSMgr );
2429 [ # # ]: 0 : xIdentifier.set( m_xIdentifier );
2430 [ # # ][ # # ]: 0 : xProvider.set( m_xProvider.get() );
2431 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
2432 : : }
2433 : :
2434 : 0 : rtl::OUString aTargetURI;
2435 : : try
2436 : : {
2437 [ # # ]: 0 : NeonUri sourceURI( rArgs.SourceURL );
2438 [ # # ][ # # ]: 0 : NeonUri targetURI( xIdentifier->getContentIdentifier() );
[ # # ]
2439 [ # # ]: 0 : aTargetURI = targetURI.GetPathBaseNameUnescaped();
2440 : :
2441 : : // Check source's and target's URL scheme
2442 : : //
2443 : 0 : const rtl::OUString aScheme = sourceURI.GetScheme().toAsciiLowerCase();
2444 [ # # ]: 0 : if ( aScheme == WEBDAV_URL_SCHEME )
2445 : : {
2446 : : sourceURI.SetScheme(
2447 [ # # ]: 0 : rtl::OUString( HTTP_URL_SCHEME ) );
2448 : : }
2449 [ # # ]: 0 : else if ( aScheme == DAV_URL_SCHEME )
2450 : : {
2451 : : sourceURI.SetScheme(
2452 [ # # ]: 0 : rtl::OUString( HTTP_URL_SCHEME ) );
2453 : : }
2454 [ # # ]: 0 : else if ( aScheme == DAVS_URL_SCHEME )
2455 : : {
2456 : : sourceURI.SetScheme(
2457 [ # # ]: 0 : rtl::OUString( HTTPS_URL_SCHEME ) );
2458 : : }
2459 : : else
2460 : : {
2461 [ # # ][ # # ]: 0 : if ( aScheme != HTTP_URL_SCHEME && aScheme != HTTPS_URL_SCHEME )
[ # # ]
2462 : : {
2463 : : ucbhelper::cancelCommandExecution(
2464 : : uno::makeAny(
2465 : : ucb::InteractiveBadTransferURLException(
2466 : : rtl::OUString( "Unsupported URL scheme!" ),
2467 : : static_cast< cppu::OWeakObject * >( this ) ) ),
2468 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
2469 : : // Unreachable
2470 : : }
2471 : : }
2472 : :
2473 [ # # ]: 0 : if ( targetURI.GetScheme().toAsciiLowerCase() == WEBDAV_URL_SCHEME )
2474 : : targetURI.SetScheme(
2475 [ # # ]: 0 : rtl::OUString( HTTP_URL_SCHEME ) );
2476 [ # # ]: 0 : else if ( targetURI.GetScheme().toAsciiLowerCase() == DAV_URL_SCHEME )
2477 : : targetURI.SetScheme(
2478 [ # # ]: 0 : rtl::OUString( HTTP_URL_SCHEME ) );
2479 : :
2480 : : // @@@ This implementation of 'transfer' only works
2481 : : // if the source and target are located at same host.
2482 : : // (Neon does not support cross-server copy/move)
2483 : :
2484 : : // Check for same host
2485 : : //
2486 [ # # # # ]: 0 : if ( !sourceURI.GetHost().isEmpty() &&
[ # # ]
2487 : 0 : ( sourceURI.GetHost() != targetURI.GetHost() ) )
2488 : : {
2489 : : ucbhelper::cancelCommandExecution(
2490 : : uno::makeAny( ucb::InteractiveBadTransferURLException(
2491 : : rtl::OUString( "Different hosts!" ),
2492 : : static_cast< cppu::OWeakObject * >( this ) ) ),
2493 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
2494 : : // Unreachable
2495 : : }
2496 : :
2497 : 0 : rtl::OUString aTitle = rArgs.NewTitle;
2498 : :
2499 [ # # ]: 0 : if ( aTitle.isEmpty() )
2500 [ # # ]: 0 : aTitle = sourceURI.GetPathBaseNameUnescaped();
2501 : :
2502 [ # # ]: 0 : if ( aTitle == "/" )
2503 : : {
2504 : : // kso: ???
2505 : 0 : aTitle = rtl::OUString();
2506 : : }
2507 : :
2508 [ # # ]: 0 : targetURI.AppendPath( aTitle );
2509 : :
2510 [ # # ][ # # ]: 0 : rtl::OUString aTargetURL = xIdentifier->getContentIdentifier();
2511 [ # # ]: 0 : if ( ( aTargetURL.lastIndexOf( '/' ) + 1 )
2512 : 0 : != aTargetURL.getLength() )
2513 : 0 : aTargetURL += rtl::OUString("/");
2514 : :
2515 : 0 : aTargetURL += aTitle;
2516 : :
2517 : : uno::Reference< ucb::XContentIdentifier > xTargetId
2518 [ # # ][ # # ]: 0 : = new ::ucbhelper::ContentIdentifier( xSMgr, aTargetURL );
[ # # ]
2519 : :
2520 : : DAVResourceAccess aSourceAccess( xSMgr,
2521 : : xResAccess->getSessionFactory(),
2522 [ # # ][ # # ]: 0 : sourceURI.GetURI() );
[ # # ]
2523 : :
2524 [ # # ]: 0 : if ( rArgs.MoveData == sal_True )
2525 : : {
2526 : : uno::Reference< ucb::XContentIdentifier > xId
2527 [ # # ][ # # ]: 0 : = new ::ucbhelper::ContentIdentifier( xSMgr, rArgs.SourceURL );
[ # # ]
2528 : :
2529 : : // Note: The static cast is okay here, because its sure that
2530 : : // xProvider is always the WebDAVContentProvider.
2531 : : rtl::Reference< Content > xSource
2532 : : = static_cast< Content * >(
2533 [ # # ][ # # ]: 0 : xProvider->queryContent( xId ).get() );
[ # # ][ # # ]
2534 : :
2535 : : // [RFC 2518] - WebDAV
2536 : : // If a resource exists at the destination and the Overwrite
2537 : : // header is "T" then prior to performing the move the server
2538 : : // MUST perform a DELETE with "Depth: infinity" on the
2539 : : // destination resource. If the Overwrite header is set to
2540 : : // "F" then the operation will fail.
2541 : :
2542 : 0 : aSourceAccess.MOVE( sourceURI.GetPath(),
2543 : 0 : targetURI.GetURI(),
2544 : : rArgs.NameClash
2545 : : == ucb::NameClash::OVERWRITE,
2546 [ # # ]: 0 : Environment );
2547 : :
2548 [ # # ]: 0 : if ( xSource.is() )
2549 : : {
2550 : : // Propagate destruction to listeners.
2551 [ # # ]: 0 : xSource->destroy( sal_True );
2552 : 0 : }
2553 : :
2554 : : // DAV resources store all additional props on server!
2555 : : // // Rename own and all children's Additional Core Properties.
2556 : : // renameAdditionalPropertySet( xId->getContentIdentifier(),
2557 : : // xTargetId->getContentIdentifier(),
2558 : : // sal_True );
2559 : : }
2560 : : else
2561 : : {
2562 : : // [RFC 2518] - WebDAV
2563 : : // If a resource exists at the destination and the Overwrite
2564 : : // header is "T" then prior to performing the copy the server
2565 : : // MUST perform a DELETE with "Depth: infinity" on the
2566 : : // destination resource. If the Overwrite header is set to
2567 : : // "F" then the operation will fail.
2568 : :
2569 : 0 : aSourceAccess.COPY( sourceURI.GetPath(),
2570 : 0 : targetURI.GetURI(),
2571 : : rArgs.NameClash
2572 : : == ucb::NameClash::OVERWRITE,
2573 [ # # ]: 0 : Environment );
2574 : :
2575 : : // DAV resources store all additional props on server!
2576 : : // // Copy own and all children's Additional Core Properties.
2577 : : // copyAdditionalPropertySet( xId->getContentIdentifier(),
2578 : : // xTargetId->getContentIdentifier(),
2579 : : // sal_True );
2580 : : }
2581 : :
2582 : : // Note: The static cast is okay here, because its sure that
2583 : : // xProvider is always the WebDAVContentProvider.
2584 : : rtl::Reference< Content > xTarget
2585 : : = static_cast< Content * >(
2586 [ # # ][ # # ]: 0 : xProvider->queryContent( xTargetId ).get() );
[ # # ][ # # ]
2587 : :
2588 : : // Announce transfered content in its new folder.
2589 [ # # ][ # # ]: 0 : xTarget->inserted();
[ # # ][ # # ]
2590 : : }
2591 [ # # ]: 0 : catch ( ucb::IllegalIdentifierException const & )
2592 : : {
2593 : : // queryContent
2594 : : }
2595 [ # # # ]: 0 : catch ( DAVException const & e )
2596 : : {
2597 : : // [RFC 2518] - WebDAV
2598 : : // 412 (Precondition Failed) - The server was unable to maintain
2599 : : // the liveness of the properties listed in the propertybehavior
2600 : : // XML element or the Overwrite header is "F" and the state of
2601 : : // the destination resource is non-null.
2602 : :
2603 [ # # ]: 0 : if ( e.getStatus() == SC_PRECONDITION_FAILED )
2604 : : {
2605 [ # # # ]: 0 : switch ( rArgs.NameClash )
2606 : : {
2607 : : case ucb::NameClash::ERROR:
2608 : : {
2609 : : ucbhelper::cancelCommandExecution(
2610 : : uno::makeAny(
2611 : : ucb::NameClashException(
2612 : : rtl::OUString(),
2613 : : static_cast< cppu::OWeakObject * >( this ),
2614 : : task::InteractionClassification_ERROR,
2615 : : aTargetURI ) ),
2616 [ # # # # : 0 : Environment );
# # # # #
# ]
2617 : : // Unreachable
2618 : : }
2619 : :
2620 : : case ucb::NameClash::OVERWRITE:
2621 : 0 : break;
2622 : :
2623 : : case ucb::NameClash::KEEP: // deprecated
2624 : : case ucb::NameClash::RENAME:
2625 : : case ucb::NameClash::ASK:
2626 : : default:
2627 : : {
2628 : : ucbhelper::cancelCommandExecution(
2629 : : uno::makeAny(
2630 : : ucb::UnsupportedNameClashException(
2631 : : rtl::OUString(),
2632 : : static_cast< cppu::OWeakObject * >( this ),
2633 : : rArgs.NameClash ) ),
2634 [ # # # # : 0 : Environment );
# # # # #
# ]
2635 : : // Unreachable
2636 : : }
2637 : : }
2638 : : }
2639 : :
2640 [ # # ]: 0 : cancelCommandExecution( e, Environment, sal_True );
2641 : : // Unreachable
2642 : : }
2643 : :
2644 : : {
2645 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2646 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
2647 [ # # ]: 0 : }
2648 : 0 : }
2649 : :
2650 : : //=========================================================================
2651 : 0 : void Content::destroy( sal_Bool bDeletePhysical )
2652 : : throw( uno::Exception )
2653 : : {
2654 : : // @@@ take care about bDeletePhysical -> trashcan support
2655 [ # # ][ # # ]: 0 : rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
2656 : :
2657 [ # # ]: 0 : uno::Reference< ucb::XContent > xThis = this;
2658 : :
2659 [ # # ]: 0 : deleted();
2660 : :
2661 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2662 : :
2663 : : // Process instanciated children...
2664 : :
2665 [ # # ]: 0 : ::webdav_ucp::Content::ContentRefList aChildren;
2666 [ # # ]: 0 : queryChildren( aChildren );
2667 : :
2668 : 0 : ContentRefList::const_iterator it = aChildren.begin();
2669 : 0 : ContentRefList::const_iterator end = aChildren.end();
2670 : :
2671 [ # # ]: 0 : while ( it != end )
2672 : : {
2673 [ # # ]: 0 : (*it)->destroy( bDeletePhysical );
2674 : 0 : ++it;
2675 [ # # ]: 0 : }
2676 : 0 : }
2677 : :
2678 : : //=========================================================================
2679 : 0 : bool Content::supportsExclusiveWriteLock(
2680 : : const uno::Reference< ucb::XCommandEnvironment >& Environment )
2681 : : {
2682 [ # # ]: 0 : if ( getResourceType( Environment ) == DAV )
2683 : : {
2684 [ # # ]: 0 : if ( m_xCachedProps.get() )
2685 : : {
2686 [ # # ]: 0 : uno::Sequence< ucb::LockEntry > aSupportedLocks;
2687 [ # # ][ # # ]: 0 : if ( m_xCachedProps->getValue( DAVProperties::SUPPORTEDLOCK )
2688 [ # # ]: 0 : >>= aSupportedLocks )
2689 : : {
2690 [ # # ]: 0 : for ( sal_Int32 n = 0; n < aSupportedLocks.getLength(); ++n )
2691 : : {
2692 [ # # ][ # # ]: 0 : if ( aSupportedLocks[ n ].Scope
[ # # ][ # # ]
2693 : : == ucb::LockScope_EXCLUSIVE &&
2694 [ # # ]: 0 : aSupportedLocks[ n ].Type
2695 : : == ucb::LockType_WRITE )
2696 : 0 : return true;
2697 : : }
2698 [ # # ][ # # ]: 0 : }
2699 : : }
2700 : : }
2701 : 0 : return false;
2702 : : }
2703 : :
2704 : : //=========================================================================
2705 : 0 : void Content::lock(
2706 : : const uno::Reference< ucb::XCommandEnvironment >& Environment )
2707 : : throw( uno::Exception )
2708 : : {
2709 : : try
2710 : : {
2711 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2712 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
2713 : : SAL_WNODEPRECATED_DECLARATIONS_POP
2714 : : {
2715 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2716 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
2717 : : }
2718 : :
2719 : 0 : uno::Any aOwnerAny;
2720 : : aOwnerAny
2721 [ # # ]: 0 : <<= rtl::OUString("http://ucb.openoffice.org");
2722 : :
2723 : : ucb::Lock aLock(
2724 : : ucb::LockScope_EXCLUSIVE,
2725 : : ucb::LockType_WRITE,
2726 : : ucb::LockDepth_ZERO,
2727 : : aOwnerAny,
2728 : : 180, // lock timeout in secs
2729 : : //-1, // infinite lock
2730 [ # # ][ # # ]: 0 : uno::Sequence< ::rtl::OUString >() );
[ # # ]
2731 : :
2732 [ # # ]: 0 : xResAccess->LOCK( aLock, Environment );
2733 : :
2734 : : {
2735 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2736 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
2737 [ # # ][ # # ]: 0 : }
2738 : : }
2739 [ # # ]: 0 : catch ( DAVException const & e )
2740 : : {
2741 [ # # ]: 0 : cancelCommandExecution( e, Environment, sal_False );
2742 : : // Unreachable
2743 : : }
2744 : 0 : }
2745 : :
2746 : : //=========================================================================
2747 : 0 : void Content::unlock(
2748 : : const uno::Reference< ucb::XCommandEnvironment >& Environment )
2749 : : throw( uno::Exception )
2750 : : {
2751 : : try
2752 : : {
2753 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2754 : 0 : std::auto_ptr< DAVResourceAccess > xResAccess;
2755 : : SAL_WNODEPRECATED_DECLARATIONS_POP
2756 : : {
2757 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2758 [ # # ][ # # ]: 0 : xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
[ # # ]
2759 : : }
2760 : :
2761 [ # # ]: 0 : xResAccess->UNLOCK( Environment );
2762 : :
2763 : : {
2764 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2765 [ # # ][ # # ]: 0 : m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
[ # # ]
2766 [ # # ]: 0 : }
2767 : : }
2768 [ # # ]: 0 : catch ( DAVException const & e )
2769 : : {
2770 [ # # ]: 0 : cancelCommandExecution( e, Environment, sal_False );
2771 : : // Unreachable
2772 : : }
2773 : 0 : }
2774 : :
2775 : : //=========================================================================
2776 : 0 : sal_Bool Content::exchangeIdentity(
2777 : : const uno::Reference< ucb::XContentIdentifier >& xNewId )
2778 : : {
2779 [ # # ]: 0 : if ( !xNewId.is() )
2780 : 0 : return sal_False;
2781 : :
2782 [ # # ]: 0 : osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
2783 : :
2784 [ # # ]: 0 : uno::Reference< ucb::XContent > xThis = this;
2785 : :
2786 : : // Already persistent?
2787 [ # # ]: 0 : if ( m_bTransient )
2788 : : {
2789 : : OSL_FAIL( "Content::exchangeIdentity - Not persistent!" );
2790 : 0 : return sal_False;
2791 : : }
2792 : :
2793 : : // Exchange own identitity.
2794 : :
2795 : : // Fail, if a content with given id already exists.
2796 : : // if ( !hasData( xNewId ) )
2797 : : {
2798 [ # # ][ # # ]: 0 : rtl::OUString aOldURL = m_xIdentifier->getContentIdentifier();
2799 : :
2800 [ # # ]: 0 : aGuard.clear();
2801 [ # # ][ # # ]: 0 : if ( exchange( xNewId ) )
2802 : : {
2803 : : // Process instanciated children...
2804 : :
2805 [ # # ]: 0 : ContentRefList aChildren;
2806 [ # # ]: 0 : queryChildren( aChildren );
2807 : :
2808 : 0 : ContentRefList::const_iterator it = aChildren.begin();
2809 : 0 : ContentRefList::const_iterator end = aChildren.end();
2810 : :
2811 [ # # ]: 0 : while ( it != end )
2812 : : {
2813 : 0 : ContentRef xChild = (*it);
2814 : :
2815 : : // Create new content identifier for the child...
2816 : : uno::Reference< ucb::XContentIdentifier >
2817 [ # # ]: 0 : xOldChildId = xChild->getIdentifier();
2818 : : rtl::OUString aOldChildURL
2819 [ # # ][ # # ]: 0 : = xOldChildId->getContentIdentifier();
2820 : : rtl::OUString aNewChildURL
2821 : : = aOldChildURL.replaceAt(
2822 : : 0,
2823 : : aOldURL.getLength(),
2824 [ # # ][ # # ]: 0 : xNewId->getContentIdentifier() );
2825 : : uno::Reference< ucb::XContentIdentifier > xNewChildId
2826 : : = new ::ucbhelper::ContentIdentifier(
2827 [ # # ][ # # ]: 0 : m_xSMgr, aNewChildURL );
[ # # ]
2828 : :
2829 [ # # ][ # # ]: 0 : if ( !xChild->exchangeIdentity( xNewChildId ) )
2830 : 0 : return sal_False;
2831 : :
2832 [ # # ]: 0 : ++it;
2833 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
2834 : 0 : return sal_True;
2835 [ # # ]: 0 : }
2836 : : }
2837 : :
2838 : : OSL_FAIL( "Content::exchangeIdentity - "
2839 : : "Panic! Cannot exchange identity!" );
2840 [ # # ]: 0 : return sal_False;
2841 : : }
2842 : :
2843 : : //=========================================================================
2844 : 0 : sal_Bool Content::isFolder(
2845 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
2846 : : throw( uno::Exception )
2847 : : {
2848 : : {
2849 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
2850 : :
2851 [ # # ]: 0 : if ( m_bTransient )
2852 [ # # ][ # # ]: 0 : return m_bCollection;
2853 : : }
2854 : :
2855 [ # # ]: 0 : uno::Sequence< beans::Property > aProperties( 1 );
2856 [ # # ][ # # ]: 0 : aProperties[ 0 ].Name = rtl::OUString("IsFolder");
2857 [ # # ]: 0 : aProperties[ 0 ].Handle = -1;
2858 [ # # ]: 0 : uno::Reference< sdbc::XRow > xRow( getPropertyValues( aProperties, xEnv ) );
2859 [ # # ]: 0 : if ( xRow.is() )
2860 : : {
2861 : : try
2862 : : {
2863 [ # # ][ # # ]: 0 : return xRow->getBoolean( 1 );
2864 : : }
2865 [ # # ]: 0 : catch ( sdbc::SQLException const & )
2866 : : {
2867 : : }
2868 : : }
2869 : :
2870 [ # # ]: 0 : return sal_False;
2871 : : }
2872 : :
2873 : : //=========================================================================
2874 : 0 : uno::Any Content::MapDAVException( const DAVException & e, sal_Bool bWrite )
2875 : : {
2876 : : // Map DAVException...
2877 : 0 : uno::Any aException;
2878 : :
2879 : 0 : rtl::OUString aURL;
2880 [ # # ]: 0 : if ( m_bTransient )
2881 : : {
2882 [ # # ]: 0 : aURL = getParentURL();
2883 [ # # ]: 0 : if ( aURL.lastIndexOf('/') != ( aURL.getLength() - 1 ) )
2884 : 0 : aURL += rtl::OUString(static_cast<sal_Unicode>('/'));
2885 : :
2886 : 0 : aURL += m_aEscapedTitle;
2887 : : }
2888 : : else
2889 : : {
2890 [ # # ][ # # ]: 0 : aURL = m_xIdentifier->getContentIdentifier();
2891 : : }
2892 : :
2893 [ # # ]: 0 : switch ( e.getStatus() )
2894 : : {
2895 : : case SC_NOT_FOUND:
2896 : : {
2897 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 1 );
2898 [ # # ]: 0 : aArgs[ 0 ] <<= beans::PropertyValue(
2899 : : rtl::OUString("Uri"), -1,
2900 : : uno::makeAny(aURL),
2901 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE);
2902 : :
2903 : : aException <<=
2904 : : ucb::InteractiveAugmentedIOException(
2905 : : rtl::OUString("Not found!"),
2906 : : static_cast< cppu::OWeakObject * >( this ),
2907 : : task::InteractionClassification_ERROR,
2908 : : ucb::IOErrorCode_NOT_EXISTING,
2909 [ # # ][ # # ]: 0 : aArgs );
[ # # ][ # # ]
2910 [ # # ]: 0 : return aException;
2911 : : }
2912 : : default:
2913 : 0 : break;
2914 : : }
2915 : :
2916 [ # # # # : 0 : switch ( e.getError() )
# # # #
# ]
2917 : : {
2918 : : case DAVException::DAV_HTTP_ERROR:
2919 : : {
2920 [ # # ]: 0 : if ( bWrite )
2921 : : aException <<=
2922 : : ucb::InteractiveNetworkWriteException(
2923 : 0 : e.getData(),
2924 : : static_cast< cppu::OWeakObject * >( this ),
2925 : : task::InteractionClassification_ERROR,
2926 [ # # # # ]: 0 : e.getData() );
[ # # ][ # # ]
2927 : : else
2928 : : aException <<=
2929 : : ucb::InteractiveNetworkReadException(
2930 : 0 : e.getData(),
2931 : : static_cast< cppu::OWeakObject * >( this ),
2932 : : task::InteractionClassification_ERROR,
2933 [ # # # # ]: 0 : e.getData() );
[ # # ][ # # ]
2934 : 0 : break;
2935 : : }
2936 : :
2937 : : case DAVException::DAV_HTTP_LOOKUP:
2938 : : aException <<=
2939 : : ucb::InteractiveNetworkResolveNameException(
2940 : : rtl::OUString(),
2941 : : static_cast< cppu::OWeakObject * >( this ),
2942 : : task::InteractionClassification_ERROR,
2943 [ # # ][ # # ]: 0 : e.getData() );
[ # # ][ # # ]
2944 : 0 : break;
2945 : :
2946 : : // @@@ No matching InteractiveNetwork*Exception
2947 : : // case DAVException::DAV_HTTP_AUTH:
2948 : : // break;
2949 : :
2950 : : // @@@ No matching InteractiveNetwork*Exception
2951 : : // case DAVException::DAV_HTTP_AUTHPROXY:
2952 : : // break;
2953 : :
2954 : : case DAVException::DAV_HTTP_CONNECT:
2955 : : aException <<=
2956 : : ucb::InteractiveNetworkConnectException(
2957 : : rtl::OUString(),
2958 : : static_cast< cppu::OWeakObject * >( this ),
2959 : : task::InteractionClassification_ERROR,
2960 [ # # ][ # # ]: 0 : e.getData() );
[ # # ][ # # ]
2961 : 0 : break;
2962 : :
2963 : : // @@@ No matching InteractiveNetwork*Exception
2964 : : // case DAVException::DAV_HTTP_TIMEOUT:
2965 : : // break;
2966 : :
2967 : : // @@@ No matching InteractiveNetwork*Exception
2968 : : // case DAVException::DAV_HTTP_REDIRECT:
2969 : : // break;
2970 : :
2971 : : // @@@ No matching InteractiveNetwork*Exception
2972 : : // case DAVException::DAV_SESSION_CREATE:
2973 : : // break;
2974 : :
2975 : : case DAVException::DAV_INVALID_ARG:
2976 : : aException <<=
2977 : : lang::IllegalArgumentException(
2978 : : rtl::OUString(),
2979 : : static_cast< cppu::OWeakObject * >( this ),
2980 [ # # ][ # # ]: 0 : -1 );
[ # # ][ # # ]
2981 : 0 : break;
2982 : :
2983 : : case DAVException::DAV_LOCKED:
2984 : : aException <<=
2985 : : ucb::InteractiveLockingLockedException(
2986 : : rtl::OUString("Locked!"),
2987 : : static_cast< cppu::OWeakObject * >( this ),
2988 : : task::InteractionClassification_ERROR,
2989 : : aURL,
2990 [ # # ][ # # ]: 0 : sal_False ); // not SelfOwned
[ # # ][ # # ]
2991 : 0 : break;
2992 : :
2993 : : case DAVException::DAV_LOCKED_SELF:
2994 : : aException <<=
2995 : : ucb::InteractiveLockingLockedException(
2996 : : rtl::OUString("Locked (self!)"),
2997 : : static_cast< cppu::OWeakObject * >( this ),
2998 : : task::InteractionClassification_ERROR,
2999 : : aURL,
3000 [ # # ][ # # ]: 0 : sal_True ); // SelfOwned
[ # # ][ # # ]
3001 : 0 : break;
3002 : :
3003 : : case DAVException::DAV_NOT_LOCKED:
3004 : : aException <<=
3005 : : ucb::InteractiveLockingNotLockedException(
3006 : : rtl::OUString("Not locked!"),
3007 : : static_cast< cppu::OWeakObject * >( this ),
3008 : : task::InteractionClassification_ERROR,
3009 [ # # ][ # # ]: 0 : aURL );
[ # # ][ # # ]
3010 : 0 : break;
3011 : :
3012 : : case DAVException::DAV_LOCK_EXPIRED:
3013 : : aException <<=
3014 : : ucb::InteractiveLockingLockExpiredException(
3015 : : rtl::OUString("Lock expired!"),
3016 : : static_cast< cppu::OWeakObject * >( this ),
3017 : : task::InteractionClassification_ERROR,
3018 [ # # ][ # # ]: 0 : aURL );
[ # # ][ # # ]
3019 : 0 : break;
3020 : :
3021 : : default:
3022 : : aException <<=
3023 : : ucb::InteractiveNetworkGeneralException(
3024 : : rtl::OUString(),
3025 : : static_cast< cppu::OWeakObject * >( this ),
3026 [ # # ][ # # ]: 0 : task::InteractionClassification_ERROR );
[ # # ][ # # ]
3027 : 0 : break;
3028 : : }
3029 : :
3030 : 0 : return aException;
3031 : : }
3032 : :
3033 : : //=========================================================================
3034 : : // static
3035 : 0 : bool Content::shouldAccessNetworkAfterException( const DAVException & e )
3036 : : {
3037 [ # # # # : 0 : if ( ( e.getStatus() == SC_NOT_FOUND ) ||
# # # # #
# ][ # # ]
3038 : 0 : ( e.getError() == DAVException::DAV_HTTP_LOOKUP ) ||
3039 : 0 : ( e.getError() == DAVException::DAV_HTTP_CONNECT ) ||
3040 : 0 : ( e.getError() == DAVException::DAV_HTTP_AUTH ) ||
3041 : 0 : ( e.getError() == DAVException::DAV_HTTP_AUTHPROXY ) )
3042 : 0 : return false;
3043 : :
3044 : 0 : return true;
3045 : : }
3046 : :
3047 : : //=========================================================================
3048 : 0 : void Content::cancelCommandExecution(
3049 : : const DAVException & e,
3050 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv,
3051 : : sal_Bool bWrite /* = sal_False */ )
3052 : : throw ( uno::Exception )
3053 : : {
3054 [ # # ]: 0 : ucbhelper::cancelCommandExecution( MapDAVException( e, bWrite ), xEnv );
3055 : : // Unreachable
3056 : 0 : }
3057 : :
3058 : : //=========================================================================
3059 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
3060 : : const rtl::OUString
3061 : 0 : Content::getBaseURI( const std::auto_ptr< DAVResourceAccess > & rResAccess )
3062 : : {
3063 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
3064 : :
3065 : : // First, try to obtain value of response header "Content-Location".
3066 [ # # ]: 0 : if ( m_xCachedProps.get() )
3067 : : {
3068 : 0 : rtl::OUString aLocation;
3069 [ # # ][ # # ]: 0 : m_xCachedProps->getValue( rtl::OUString( "Content-Location" ) ) >>= aLocation;
3070 [ # # ]: 0 : if ( !aLocation.isEmpty() )
3071 : : {
3072 : : try
3073 : : {
3074 : : // Do not use m_xIdentifier->getContentIdentifier() because it
3075 : : // for example does not reflect redirects applied to requests
3076 : : // done using the original URI but m_xResAccess' URI does.
3077 : 0 : return rtl::Uri::convertRelToAbs( rResAccess->getURL(),
3078 [ # # ]: 0 : aLocation );
3079 : : }
3080 : 0 : catch ( rtl::MalformedUriException const & )
3081 : : {
3082 : : }
3083 [ # # ]: 0 : }
3084 : : }
3085 : :
3086 [ # # ]: 0 : return rtl::OUString( rResAccess->getURL() );
3087 : : }
3088 : :
3089 : : //=========================================================================
3090 : 0 : const Content::ResourceType & Content::getResourceType(
3091 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv,
3092 : : const std::auto_ptr< DAVResourceAccess > & rResAccess )
3093 : : throw ( uno::Exception )
3094 : : {
3095 [ # # ]: 0 : if ( m_eResourceType == UNKNOWN )
3096 : : {
3097 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
3098 : :
3099 : : ResourceType eResourceType;
3100 : 0 : eResourceType = m_eResourceType;
3101 : :
3102 : 0 : const rtl::OUString & rURL = rResAccess->getURL();
3103 : : const rtl::OUString aScheme(
3104 : 0 : rURL.copy( 0, rURL.indexOf( ':' ) ).toAsciiLowerCase() );
3105 : :
3106 [ # # ]: 0 : if ( aScheme == FTP_URL_SCHEME )
3107 : : {
3108 : 0 : eResourceType = FTP;
3109 : : }
3110 : : else
3111 : : {
3112 : : try
3113 : : {
3114 : : // Try to fetch some frequently used property value, e.g. those
3115 : : // used when loading documents... along with identifying whether
3116 : : // this is a DAV resource.
3117 [ # # ]: 0 : std::vector< DAVResource > resources;
3118 [ # # ]: 0 : std::vector< rtl::OUString > aPropNames;
3119 [ # # ]: 0 : uno::Sequence< beans::Property > aProperties( 5 );
3120 [ # # ]: 0 : aProperties[ 0 ].Name
3121 : 0 : = rtl::OUString("IsFolder");
3122 [ # # ]: 0 : aProperties[ 1 ].Name
3123 : 0 : = rtl::OUString("IsDocument");
3124 [ # # ]: 0 : aProperties[ 2 ].Name
3125 : 0 : = rtl::OUString("IsReadOnly");
3126 [ # # ]: 0 : aProperties[ 3 ].Name
3127 : 0 : = rtl::OUString("MediaType");
3128 [ # # ]: 0 : aProperties[ 4 ].Name
3129 : 0 : = DAVProperties::SUPPORTEDLOCK;
3130 : :
3131 : : ContentProperties::UCBNamesToDAVNames(
3132 [ # # ]: 0 : aProperties, aPropNames );
3133 : :
3134 : : rResAccess->PROPFIND(
3135 [ # # ]: 0 : DAVZERO, aPropNames, resources, xEnv );
3136 : :
3137 [ # # ]: 0 : if ( resources.size() == 1 )
3138 : : {
3139 : : m_xCachedProps.reset(
3140 [ # # ][ # # ]: 0 : new CachableContentProperties( resources[ 0 ] ) );
[ # # ][ # # ]
3141 : : m_xCachedProps->containsAllNames(
3142 [ # # ]: 0 : aProperties, m_aFailedPropNames );
3143 : : }
3144 : :
3145 [ # # ]: 0 : eResourceType = DAV;
3146 : : }
3147 [ # # ]: 0 : catch ( DAVException const & e )
3148 : : {
3149 [ # # ]: 0 : rResAccess->resetUri();
3150 : :
3151 [ # # ]: 0 : if ( e.getStatus() == SC_METHOD_NOT_ALLOWED )
3152 : : {
3153 : : // Status SC_METHOD_NOT_ALLOWED is a safe indicator that the
3154 : : // resource is NON_DAV
3155 : 0 : eResourceType = NON_DAV;
3156 : : }
3157 : : }
3158 : : }
3159 [ # # ]: 0 : m_eResourceType = eResourceType;
3160 : : }
3161 : 0 : return m_eResourceType;
3162 : : }
3163 : : SAL_WNODEPRECATED_DECLARATIONS_POP
3164 : :
3165 : : //=========================================================================
3166 : 0 : const Content::ResourceType & Content::getResourceType(
3167 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
3168 : : throw ( uno::Exception )
3169 : : {
3170 : 0 : return getResourceType( xEnv, m_xResAccess );
3171 : : }
3172 : :
3173 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|