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 : : #include <osl/diagnose.h>
35 : :
36 : : #include "osl/doublecheckedlocking.h"
37 : : #include <rtl/ustring.h>
38 : : #include <rtl/ustring.hxx>
39 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
40 : : #include <com/sun/star/beans/PropertyState.hpp>
41 : : #include <com/sun/star/beans/PropertyValue.hpp>
42 : : #include <com/sun/star/beans/XPropertyAccess.hpp>
43 : : #include <com/sun/star/container/XEnumerationAccess.hpp>
44 : : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
45 : : #include <com/sun/star/container/XNameContainer.hpp>
46 : : #include <com/sun/star/container/XNamed.hpp>
47 : : #include <com/sun/star/io/XActiveDataSink.hpp>
48 : : #include <com/sun/star/io/XInputStream.hpp>
49 : : #include <com/sun/star/io/XOutputStream.hpp>
50 : : #include <com/sun/star/lang/IllegalAccessException.hpp>
51 : : #include <com/sun/star/sdbc/XRow.hpp>
52 : : #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
53 : : #include <com/sun/star/ucb/InsertCommandArgument.hpp>
54 : : #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
55 : : #include <com/sun/star/ucb/MissingInputStreamException.hpp>
56 : : #include <com/sun/star/ucb/NameClash.hpp>
57 : : #include <com/sun/star/ucb/NameClashException.hpp>
58 : : #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
59 : : #include <com/sun/star/ucb/OpenMode.hpp>
60 : : #include <com/sun/star/ucb/TransferInfo.hpp>
61 : : #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
62 : : #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
63 : : #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
64 : : #include <com/sun/star/ucb/XCommandInfo.hpp>
65 : : #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
66 : : #include <com/sun/star/util/XChangesBatch.hpp>
67 : : #include <com/sun/star/uno/Any.hxx>
68 : : #include <com/sun/star/uno/Sequence.hxx>
69 : : #include <ucbhelper/contentidentifier.hxx>
70 : : #include <ucbhelper/propertyvalueset.hxx>
71 : : #include <ucbhelper/cancelcommandexecution.hxx>
72 : : #include "pkgcontent.hxx"
73 : : #include "pkgprovider.hxx"
74 : : #include "pkgresultset.hxx"
75 : :
76 : : #include "../inc/urihelper.hxx"
77 : :
78 : : using namespace com::sun::star;
79 : : using namespace package_ucp;
80 : :
81 : : #define NONE_MODIFIED sal_uInt32( 0x00 )
82 : : #define MEDIATYPE_MODIFIED sal_uInt32( 0x01 )
83 : : #define COMPRESSED_MODIFIED sal_uInt32( 0x02 )
84 : : #define ENCRYPTED_MODIFIED sal_uInt32( 0x04 )
85 : : #define ENCRYPTIONKEY_MODIFIED sal_uInt32( 0x08 )
86 : :
87 : : //=========================================================================
88 : : //=========================================================================
89 : : //
90 : : // ContentProperties Implementation.
91 : : //
92 : : //=========================================================================
93 : : //=========================================================================
94 : :
95 : 124 : ContentProperties::ContentProperties( const rtl::OUString& rContentType )
96 : : : aContentType( rContentType ),
97 : : nSize( 0 ),
98 : : bCompressed( sal_True ),
99 : : bEncrypted( sal_False ),
100 [ + - ]: 124 : bHasEncryptedEntries( sal_False )
101 : : {
102 [ + - ][ + + ]: 124 : bIsFolder = rContentType == PACKAGE_FOLDER_CONTENT_TYPE || rContentType == PACKAGE_ZIP_FOLDER_CONTENT_TYPE;
103 : 124 : bIsDocument = !bIsFolder;
104 : :
105 : : OSL_ENSURE( bIsFolder || rContentType == PACKAGE_STREAM_CONTENT_TYPE || rContentType == PACKAGE_ZIP_STREAM_CONTENT_TYPE,
106 : : "ContentProperties::ContentProperties - Unknown type!" );
107 : 124 : }
108 : :
109 : : //=========================================================================
110 : :
111 : : uno::Sequence< ucb::ContentInfo >
112 : 140 : ContentProperties::getCreatableContentsInfo( PackageUri const & rUri ) const
113 : : {
114 [ + + ]: 140 : if ( bIsFolder )
115 : : {
116 [ + - ]: 132 : uno::Sequence< beans::Property > aProps( 1 );
117 : : aProps.getArray()[ 0 ] = beans::Property(
118 : : rtl::OUString("Title"),
119 : : -1,
120 [ + - ]: 132 : getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
121 [ + - ]: 132 : beans::PropertyAttribute::BOUND );
122 : :
123 [ + - ]: 132 : uno::Sequence< ucb::ContentInfo > aSeq( 2 );
124 : :
125 : : // Folder.
126 [ + - ]: 132 : aSeq.getArray()[ 0 ].Type
127 [ + - ][ + - ]: 264 : = Content::getContentType( rUri.getScheme(), sal_True );
128 [ + - ]: 132 : aSeq.getArray()[ 0 ].Attributes
129 : 132 : = ucb::ContentInfoAttribute::KIND_FOLDER;
130 [ + - ][ + - ]: 132 : aSeq.getArray()[ 0 ].Properties = aProps;
131 : :
132 : : // Stream.
133 [ + - ]: 132 : aSeq.getArray()[ 1 ].Type
134 [ + - ][ + - ]: 264 : = Content::getContentType( rUri.getScheme(), sal_False );
135 [ + - ]: 132 : aSeq.getArray()[ 1 ].Attributes
136 : : = ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM
137 : 132 : | ucb::ContentInfoAttribute::KIND_DOCUMENT;
138 [ + - ][ + - ]: 132 : aSeq.getArray()[ 1 ].Properties = aProps;
139 : :
140 [ + - ][ + - ]: 132 : return aSeq;
[ + - ]
141 : : }
142 : : else
143 : : {
144 : 140 : return uno::Sequence< ucb::ContentInfo >( 0 );
145 : : }
146 : : }
147 : :
148 : : //=========================================================================
149 : : //=========================================================================
150 : : //
151 : : // Content Implementation.
152 : : //
153 : : //=========================================================================
154 : : //=========================================================================
155 : :
156 : : // static ( "virtual" ctor )
157 : 117 : Content* Content::create(
158 : : const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
159 : : ContentProvider* pProvider,
160 : : const uno::Reference< ucb::XContentIdentifier >& Identifier )
161 : : {
162 [ + - ][ + - ]: 117 : rtl::OUString aURL = Identifier->getContentIdentifier();
163 : 117 : PackageUri aURI( aURL );
164 [ + - ]: 117 : ContentProperties aProps;
165 : 117 : uno::Reference< container::XHierarchicalNameAccess > xPackage;
166 : :
167 [ + - ][ + - ]: 117 : if ( loadData( pProvider, aURI, aProps, xPackage ) )
168 : : {
169 : : // resource exists
170 : :
171 : 117 : sal_Int32 nLastSlash = aURL.lastIndexOf( '/' );
172 [ + + ]: 117 : if ( ( nLastSlash + 1 ) == aURL.getLength() )
173 : : {
174 : : // Client explicitly requested a folder!
175 [ - + ]: 68 : if ( !aProps.bIsFolder )
176 : 0 : return 0;
177 : : }
178 : :
179 : : uno::Reference< ucb::XContentIdentifier > xId
180 [ + - ][ + - ]: 117 : = new ::ucbhelper::ContentIdentifier( rxSMgr, aURI.getUri() );
[ + - ][ + - ]
181 [ + - ]: 117 : return new Content( rxSMgr, pProvider, xId, xPackage, aURI, aProps );
182 : : }
183 : : else
184 : : {
185 : : // resource doesn't exist
186 : :
187 : 0 : sal_Bool bFolder = sal_False;
188 : :
189 : : // Guess type according to URI.
190 : 0 : sal_Int32 nLastSlash = aURL.lastIndexOf( '/' );
191 [ # # ]: 0 : if ( ( nLastSlash + 1 ) == aURL.getLength() )
192 : 0 : bFolder = sal_True;
193 : :
194 : : uno::Reference< ucb::XContentIdentifier > xId
195 [ # # ][ # # ]: 0 : = new ::ucbhelper::ContentIdentifier( rxSMgr, aURI.getUri() );
[ # # ][ # # ]
196 : :
197 [ # # ]: 0 : ucb::ContentInfo aInfo;
198 [ # # ][ # # ]: 0 : if ( bFolder || aURI.isRootFolder() )
[ # # ][ # # ]
199 [ # # ][ # # ]: 0 : aInfo.Type = getContentType( aURI.getScheme(), sal_True );
200 : : else
201 [ # # ][ # # ]: 0 : aInfo.Type = getContentType( aURI.getScheme(), sal_False );
202 : :
203 [ # # ][ # # ]: 0 : return new Content( rxSMgr, pProvider, xId, xPackage, aURI, aInfo );
204 [ + - ]: 117 : }
205 : : }
206 : :
207 : : //=========================================================================
208 : : // static ( "virtual" ctor )
209 : 124 : Content* Content::create(
210 : : const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
211 : : ContentProvider* pProvider,
212 : : const uno::Reference< ucb::XContentIdentifier >& Identifier,
213 : : const ucb::ContentInfo& Info )
214 : : {
215 [ - + ]: 124 : if ( Info.Type.isEmpty() )
216 : 0 : return 0;
217 : :
218 [ + - ][ + - ]: 124 : PackageUri aURI( Identifier->getContentIdentifier() );
219 : :
220 [ - + ]: 310 : if ( !Info.Type.equalsIgnoreAsciiCase(
[ + + - + ]
221 [ + - ][ + - ]: 248 : getContentType( aURI.getScheme(), sal_True ) ) &&
[ # # ][ + - ]
222 : : !Info.Type.equalsIgnoreAsciiCase(
223 [ + - ][ + - ]: 186 : getContentType( aURI.getScheme(), sal_False ) ) )
[ + + ][ # # ]
224 : 0 : return 0;
225 : :
226 : 124 : uno::Reference< container::XHierarchicalNameAccess > xPackage;
227 : :
228 [ + - ][ + - ]: 124 : xPackage = pProvider->createPackage( aURI.getPackage(), aURI.getParam() );
[ + - ][ + - ]
229 : :
230 : : uno::Reference< ucb::XContentIdentifier > xId
231 [ + - ][ + - ]: 124 : = new ::ucbhelper::ContentIdentifier( rxSMgr, aURI.getUri() );
[ + - ][ + - ]
232 [ + - ]: 124 : return new Content( rxSMgr, pProvider, xId, xPackage, aURI, Info );
233 : : }
234 : :
235 : : //=========================================================================
236 : : // static
237 : 1013 : ::rtl::OUString Content::getContentType(
238 : : const ::rtl::OUString& aScheme, sal_Bool bFolder )
239 : : {
240 : : return ( rtl::OUString("application/")
241 : : + aScheme
242 : : + ( bFolder
243 : : ? rtl::OUString("-folder")
244 [ + + ][ + + ]: 1013 : : rtl::OUString("-stream") ) );
[ + + ]
245 : : }
246 : :
247 : : //=========================================================================
248 : 117 : Content::Content(
249 : : const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
250 : : ContentProvider* pProvider,
251 : : const uno::Reference< ucb::XContentIdentifier >& Identifier,
252 : : const uno::Reference< container::XHierarchicalNameAccess > & Package,
253 : : const PackageUri& rUri,
254 : : const ContentProperties& rProps )
255 : : : ContentImplHelper( rxSMgr, pProvider, Identifier ),
256 : : m_aUri( rUri ),
257 : : m_aProps( rProps ),
258 : : m_eState( PERSISTENT ),
259 : : m_xPackage( Package ),
260 : : m_pProvider( pProvider ),
261 [ + - ][ + - ]: 117 : m_nModifiedProps( NONE_MODIFIED )
262 : : {
263 : 117 : }
264 : :
265 : : //=========================================================================
266 : 124 : Content::Content(
267 : : const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
268 : : ContentProvider* pProvider,
269 : : const uno::Reference< ucb::XContentIdentifier >& Identifier,
270 : : const uno::Reference< container::XHierarchicalNameAccess > & Package,
271 : : const PackageUri& rUri,
272 : : const ucb::ContentInfo& Info )
273 : : : ContentImplHelper( rxSMgr, pProvider, Identifier ),
274 : : m_aUri( rUri ),
275 : : m_aProps( Info.Type ),
276 : : m_eState( TRANSIENT ),
277 : : m_xPackage( Package ),
278 : : m_pProvider( pProvider ),
279 [ + - ][ + - ]: 124 : m_nModifiedProps( NONE_MODIFIED )
280 : : {
281 : 124 : }
282 : :
283 : : //=========================================================================
284 : : // virtual
285 [ + - ]: 241 : Content::~Content()
286 : : {
287 [ - + ]: 482 : }
288 : :
289 : : //=========================================================================
290 : : //
291 : : // XInterface methods.
292 : : //
293 : : //=========================================================================
294 : :
295 : : // virtual
296 : 12830 : void SAL_CALL Content::acquire()
297 : : throw( )
298 : : {
299 : 12830 : ContentImplHelper::acquire();
300 : 12830 : }
301 : :
302 : : //=========================================================================
303 : : // virtual
304 : 12830 : void SAL_CALL Content::release()
305 : : throw( )
306 : : {
307 : 12830 : ContentImplHelper::release();
308 : 12830 : }
309 : :
310 : : //=========================================================================
311 : : // virtual
312 : 1720 : uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
313 : : throw ( uno::RuntimeException )
314 : : {
315 : 1720 : uno::Any aRet;
316 : :
317 [ + + ]: 1720 : if ( isFolder() )
318 : : aRet = cppu::queryInterface(
319 [ + - ]: 1498 : rType, static_cast< ucb::XContentCreator * >( this ) );
320 : :
321 [ - + ][ + - ]: 1720 : return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
322 : : }
323 : :
324 : : //=========================================================================
325 : : //
326 : : // XTypeProvider methods.
327 : : //
328 : : //=========================================================================
329 : :
330 [ # # ][ # # ]: 0 : XTYPEPROVIDER_COMMON_IMPL( Content );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
331 : :
332 : : //=========================================================================
333 : : // virtual
334 : 0 : uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
335 : : throw( uno::RuntimeException )
336 : : {
337 : 0 : cppu::OTypeCollection * pCollection = 0;
338 : :
339 [ # # ]: 0 : if ( isFolder() )
340 : : {
341 : : static cppu::OTypeCollection* pFolderTypes = 0;
342 : :
343 : 0 : pCollection = pFolderTypes;
344 [ # # ]: 0 : if ( !pCollection )
345 : : {
346 [ # # ][ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
347 : :
348 : 0 : pCollection = pFolderTypes;
349 [ # # ]: 0 : if ( !pCollection )
350 : : {
351 : : static cppu::OTypeCollection aCollection(
352 [ # # ]: 0 : CPPU_TYPE_REF( lang::XTypeProvider ),
353 [ # # ]: 0 : CPPU_TYPE_REF( lang::XServiceInfo ),
354 [ # # ]: 0 : CPPU_TYPE_REF( lang::XComponent ),
355 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XContent ),
356 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XCommandProcessor ),
357 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
358 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
359 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertyContainer ),
360 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
361 [ # # ]: 0 : CPPU_TYPE_REF( container::XChild ),
362 [ # # ][ # # ]: 0 : CPPU_TYPE_REF( ucb::XContentCreator ) ); // !!
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
363 : 0 : pCollection = &aCollection;
364 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
365 : 0 : pFolderTypes = pCollection;
366 [ # # ]: 0 : }
367 : : }
368 : : else {
369 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
370 : : }
371 : : }
372 : : else
373 : : {
374 : : static cppu::OTypeCollection* pDocumentTypes = 0;
375 : :
376 : 0 : pCollection = pDocumentTypes;
377 [ # # ]: 0 : if ( !pCollection )
378 : : {
379 [ # # ][ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
380 : :
381 : 0 : pCollection = pDocumentTypes;
382 [ # # ]: 0 : if ( !pCollection )
383 : : {
384 : : static cppu::OTypeCollection aCollection(
385 [ # # ]: 0 : CPPU_TYPE_REF( lang::XTypeProvider ),
386 [ # # ]: 0 : CPPU_TYPE_REF( lang::XServiceInfo ),
387 [ # # ]: 0 : CPPU_TYPE_REF( lang::XComponent ),
388 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XContent ),
389 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XCommandProcessor ),
390 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
391 [ # # ]: 0 : CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
392 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertyContainer ),
393 [ # # ]: 0 : CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
394 [ # # ][ # # ]: 0 : CPPU_TYPE_REF( container::XChild ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
395 : 0 : pCollection = &aCollection;
396 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
397 : 0 : pDocumentTypes = pCollection;
398 [ # # ]: 0 : }
399 : : }
400 : : else {
401 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
402 : : }
403 : : }
404 : :
405 : 0 : return (*pCollection).getTypes();
406 : : }
407 : :
408 : : //=========================================================================
409 : : //
410 : : // XServiceInfo methods.
411 : : //
412 : : //=========================================================================
413 : :
414 : : // virtual
415 : 0 : rtl::OUString SAL_CALL Content::getImplementationName()
416 : : throw( uno::RuntimeException )
417 : : {
418 : 0 : return rtl::OUString( "com.sun.star.comp.ucb.PackageContent" );
419 : : }
420 : :
421 : : //=========================================================================
422 : : // virtual
423 : 0 : uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames()
424 : : throw( uno::RuntimeException )
425 : : {
426 : 0 : uno::Sequence< rtl::OUString > aSNS( 1 );
427 [ # # ]: 0 : if ( isFolder() )
428 [ # # ]: 0 : aSNS.getArray()[ 0 ] = rtl::OUString( PACKAGE_FOLDER_CONTENT_SERVICE_NAME );
429 : : else
430 [ # # ]: 0 : aSNS.getArray()[ 0 ] = rtl::OUString( PACKAGE_STREAM_CONTENT_SERVICE_NAME );
431 : :
432 : 0 : return aSNS;
433 : : }
434 : :
435 : : //=========================================================================
436 : : //
437 : : // XContent methods.
438 : : //
439 : : //=========================================================================
440 : :
441 : : // virtual
442 : 0 : rtl::OUString SAL_CALL Content::getContentType()
443 : : throw( uno::RuntimeException )
444 : : {
445 : 0 : return m_aProps.aContentType;
446 : : }
447 : :
448 : : //=========================================================================
449 : : //
450 : : // XCommandProcessor methods.
451 : : //
452 : : //=========================================================================
453 : :
454 : : // virtual
455 : 934 : uno::Any SAL_CALL Content::execute(
456 : : const ucb::Command& aCommand,
457 : : sal_Int32 /*CommandId*/,
458 : : const uno::Reference< ucb::XCommandEnvironment >& Environment )
459 : : throw( uno::Exception,
460 : : ucb::CommandAbortedException,
461 : : uno::RuntimeException )
462 : : {
463 : 934 : uno::Any aRet;
464 : :
465 [ + + ]: 934 : if ( aCommand.Name == "getPropertyValues" )
466 : : {
467 : : //////////////////////////////////////////////////////////////////
468 : : // getPropertyValues
469 : : //////////////////////////////////////////////////////////////////
470 : :
471 [ + - ]: 183 : uno::Sequence< beans::Property > Properties;
472 [ + - ][ - + ]: 183 : if ( !( aCommand.Argument >>= Properties ) )
473 : : {
474 : : ucbhelper::cancelCommandExecution(
475 : : uno::makeAny( lang::IllegalArgumentException(
476 : : rtl::OUString( "Wrong argument type!" ),
477 : : static_cast< cppu::OWeakObject * >( this ),
478 : : -1 ) ),
479 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
480 : : // Unreachable
481 : : }
482 : :
483 [ + - ][ + - ]: 183 : aRet <<= getPropertyValues( Properties );
[ + - ]
484 : : }
485 [ + + ]: 751 : else if ( aCommand.Name == "setPropertyValues" )
486 : : {
487 : : //////////////////////////////////////////////////////////////////
488 : : // setPropertyValues
489 : : //////////////////////////////////////////////////////////////////
490 : :
491 [ + - ]: 124 : uno::Sequence< beans::PropertyValue > aProperties;
492 [ + - ][ - + ]: 124 : if ( !( aCommand.Argument >>= aProperties ) )
493 : : {
494 : : ucbhelper::cancelCommandExecution(
495 : : uno::makeAny( lang::IllegalArgumentException(
496 : : rtl::OUString( "Wrong argument type!" ),
497 : : static_cast< cppu::OWeakObject * >( this ),
498 : : -1 ) ),
499 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
500 : : // Unreachable
501 : : }
502 : :
503 [ - + ]: 124 : if ( !aProperties.getLength() )
504 : : {
505 : : ucbhelper::cancelCommandExecution(
506 : : uno::makeAny( lang::IllegalArgumentException(
507 : : rtl::OUString( "No properties!" ),
508 : : static_cast< cppu::OWeakObject * >( this ),
509 : : -1 ) ),
510 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
511 : : // Unreachable
512 : : }
513 : :
514 [ + - ][ + - ]: 124 : aRet <<= setPropertyValues( aProperties, Environment );
[ + - ][ + - ]
515 : : }
516 [ + + ]: 627 : else if ( aCommand.Name == "getPropertySetInfo" )
517 : : {
518 : : //////////////////////////////////////////////////////////////////
519 : : // getPropertySetInfo
520 : : //////////////////////////////////////////////////////////////////
521 : :
522 : : // Note: Implemented by base class.
523 [ + - ][ + - ]: 16 : aRet <<= getPropertySetInfo( Environment );
524 : : }
525 [ + + ]: 611 : else if ( aCommand.Name == "getCommandInfo" )
526 : : {
527 : : //////////////////////////////////////////////////////////////////
528 : : // getCommandInfo
529 : : //////////////////////////////////////////////////////////////////
530 : :
531 : : // Note: Implemented by base class.
532 [ + - ][ + - ]: 124 : aRet <<= getCommandInfo( Environment );
533 : : }
534 [ + + ]: 487 : else if ( aCommand.Name == "open" )
535 : : {
536 : : //////////////////////////////////////////////////////////////////
537 : : // open
538 : : //////////////////////////////////////////////////////////////////
539 : :
540 [ + - ]: 53 : ucb::OpenCommandArgument2 aOpenCommand;
541 [ + - ][ - + ]: 53 : if ( !( aCommand.Argument >>= aOpenCommand ) )
542 : : {
543 : : ucbhelper::cancelCommandExecution(
544 : : uno::makeAny( lang::IllegalArgumentException(
545 : : rtl::OUString( "Wrong argument type!" ),
546 : : static_cast< cppu::OWeakObject * >( this ),
547 : : -1 ) ),
548 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
549 : : // Unreachable
550 : : }
551 : :
552 [ + - ][ + - ]: 53 : aRet = open( aOpenCommand, Environment );
553 : : }
554 [ + - ][ + + ]: 434 : else if ( !m_aUri.isRootFolder() && aCommand.Name == "insert" )
[ + + ][ + + ]
555 : : {
556 : : //////////////////////////////////////////////////////////////////
557 : : // insert
558 : : //////////////////////////////////////////////////////////////////
559 : :
560 [ + - ]: 124 : ucb::InsertCommandArgument aArg;
561 [ + - ][ - + ]: 124 : if ( !( aCommand.Argument >>= aArg ) )
562 : : {
563 : : ucbhelper::cancelCommandExecution(
564 : : uno::makeAny( lang::IllegalArgumentException(
565 : : rtl::OUString( "Wrong argument type!" ),
566 : : static_cast< cppu::OWeakObject * >( this ),
567 : : -1 ) ),
568 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
569 : : // Unreachable
570 : : }
571 : :
572 : : sal_Int32 nNameClash = aArg.ReplaceExisting
573 : : ? ucb::NameClash::OVERWRITE
574 [ + - ]: 124 : : ucb::NameClash::ERROR;
575 [ + - ][ + - ]: 124 : insert( aArg.Data, nNameClash, Environment );
576 : : }
577 [ + - ][ + + ]: 310 : else if ( !m_aUri.isRootFolder() && aCommand.Name == "delete" )
[ - + ][ - + ]
578 : : {
579 : : //////////////////////////////////////////////////////////////////
580 : : // delete
581 : : //////////////////////////////////////////////////////////////////
582 : :
583 : 0 : sal_Bool bDeletePhysical = sal_False;
584 : 0 : aCommand.Argument >>= bDeletePhysical;
585 [ # # ]: 0 : destroy( bDeletePhysical, Environment );
586 : :
587 : : // Remove own and all children's persistent data.
588 [ # # ][ # # ]: 0 : if ( !removeData() )
589 : : {
590 : : uno::Any aProps
591 : : = uno::makeAny(
592 : : beans::PropertyValue(
593 : : rtl::OUString( "Uri"),
594 : : -1,
595 [ # # ]: 0 : uno::makeAny(m_xIdentifier->
596 : 0 : getContentIdentifier()),
597 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ]
598 : : ucbhelper::cancelCommandExecution(
599 : : ucb::IOErrorCode_CANT_WRITE,
600 : : uno::Sequence< uno::Any >(&aProps, 1),
601 : : Environment,
602 : : rtl::OUString( "Cannot remove persistent data!" ),
603 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
604 : : // Unreachable
605 : : }
606 : :
607 : : // Remove own and all children's Additional Core Properties.
608 [ # # ]: 0 : removeAdditionalPropertySet( sal_True );
609 : : }
610 [ + + ]: 310 : else if ( aCommand.Name == "transfer" )
611 : : {
612 : : //////////////////////////////////////////////////////////////////
613 : : // transfer
614 : : // ( Not available at stream objects )
615 : : //////////////////////////////////////////////////////////////////
616 : :
617 : 62 : ucb::TransferInfo aInfo;
618 [ - + ][ + - ]: 62 : if ( !( aCommand.Argument >>= aInfo ) )
619 : : {
620 : : ucbhelper::cancelCommandExecution(
621 : : uno::makeAny( lang::IllegalArgumentException(
622 : : rtl::OUString( "Wrong argument type!" ),
623 : : static_cast< cppu::OWeakObject * >( this ),
624 : : -1 ) ),
625 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
626 : : // Unreachable
627 : : }
628 : :
629 [ - + ]: 62 : transfer( aInfo, Environment );
630 : : }
631 [ + + ][ + - ]: 248 : else if ( aCommand.Name == "createNewContent" && isFolder() )
[ + + ]
632 : : {
633 : : //////////////////////////////////////////////////////////////////
634 : : // createNewContent
635 : : // ( Not available at stream objects )
636 : : //////////////////////////////////////////////////////////////////
637 : :
638 [ + - ]: 124 : ucb::ContentInfo aInfo;
639 [ + - ][ - + ]: 124 : if ( !( aCommand.Argument >>= aInfo ) )
640 : : {
641 : : OSL_FAIL( "Wrong argument type!" );
642 : : ucbhelper::cancelCommandExecution(
643 : : uno::makeAny( lang::IllegalArgumentException(
644 : : rtl::OUString( "Wrong argument type!" ),
645 : : static_cast< cppu::OWeakObject * >( this ),
646 : : -1 ) ),
647 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
648 : : // Unreachable
649 : : }
650 : :
651 [ + - ][ + - ]: 124 : aRet <<= createNewContent( aInfo );
[ + - ]
652 : : }
653 [ + - ]: 124 : else if ( aCommand.Name == "flush" )
654 : : {
655 : : //////////////////////////////////////////////////////////////////
656 : : // flush
657 : : // ( Not available at stream objects )
658 : : //////////////////////////////////////////////////////////////////
659 : :
660 [ + - ][ - + ]: 124 : if( !flushData() )
661 : : {
662 : : uno::Any aProps
663 : : = uno::makeAny(
664 : : beans::PropertyValue(
665 : : rtl::OUString( "Uri"),
666 : : -1,
667 [ # # ]: 0 : uno::makeAny(m_xIdentifier->
668 : 0 : getContentIdentifier()),
669 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ]
670 : : ucbhelper::cancelCommandExecution(
671 : : ucb::IOErrorCode_CANT_WRITE,
672 : : uno::Sequence< uno::Any >(&aProps, 1),
673 : : Environment,
674 : : rtl::OUString( "Cannot write file to disk!" ),
675 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
676 : : // Unreachable
677 : : }
678 : : }
679 : : else
680 : : {
681 : : //////////////////////////////////////////////////////////////////
682 : : // Unsupported command
683 : : //////////////////////////////////////////////////////////////////
684 : :
685 : : ucbhelper::cancelCommandExecution(
686 : : uno::makeAny( ucb::UnsupportedCommandException(
687 : : rtl::OUString(),
688 : : static_cast< cppu::OWeakObject * >( this ) ) ),
689 [ # # ][ # # ]: 0 : Environment );
[ # # ][ # # ]
[ # # ]
690 : : // Unreachable
691 : : }
692 : :
693 : 934 : return aRet;
694 : : }
695 : :
696 : : //=========================================================================
697 : : // virtual
698 : 0 : void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
699 : : throw( uno::RuntimeException )
700 : : {
701 : : // @@@ Implement logic to abort running commands, if this makes
702 : : // sense for your content.
703 : 0 : }
704 : :
705 : : //=========================================================================
706 : : //
707 : : // XContentCreator methods.
708 : : //
709 : : //=========================================================================
710 : :
711 : : // virtual
712 : : uno::Sequence< ucb::ContentInfo > SAL_CALL
713 : 0 : Content::queryCreatableContentsInfo()
714 : : throw( uno::RuntimeException )
715 : : {
716 : 0 : return m_aProps.getCreatableContentsInfo( m_aUri );
717 : : }
718 : :
719 : : //=========================================================================
720 : : // virtual
721 : : uno::Reference< ucb::XContent > SAL_CALL
722 : 124 : Content::createNewContent( const ucb::ContentInfo& Info )
723 : : throw( uno::RuntimeException )
724 : : {
725 [ + - ]: 124 : if ( isFolder() )
726 : : {
727 [ + - ]: 124 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
728 : :
729 [ - + ]: 124 : if ( Info.Type.isEmpty() )
730 : 0 : return uno::Reference< ucb::XContent >();
731 : :
732 [ - + ]: 310 : if ( !Info.Type.equalsIgnoreAsciiCase(
[ + + - + ]
733 [ + - ][ + - ]: 248 : getContentType( m_aUri.getScheme(), sal_True ) ) &&
[ + - ][ # # ]
734 : : !Info.Type.equalsIgnoreAsciiCase(
735 [ + - ][ + - ]: 186 : getContentType( m_aUri.getScheme(), sal_False ) ) )
[ + + ][ # # ]
736 : 0 : return uno::Reference< ucb::XContent >();
737 : :
738 [ + - ]: 124 : rtl::OUString aURL = m_aUri.getUri();
739 [ + - ]: 124 : aURL += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
740 : :
741 [ + + ]: 124 : if ( Info.Type.equalsIgnoreAsciiCase(
742 [ + - ][ + - ]: 124 : getContentType( m_aUri.getScheme(), sal_True ) ) )
743 [ + - ]: 62 : aURL += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("New_Folder"));
744 : : else
745 [ + - ]: 62 : aURL += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("New_Stream"));
746 : :
747 : : uno::Reference< ucb::XContentIdentifier > xId(
748 [ + - ][ + - ]: 124 : new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ) );
[ + - ]
749 : :
750 [ + - ][ + - ]: 124 : return create( m_xSMgr, m_pProvider, xId, Info );
[ + - ][ + - ]
751 : : }
752 : : else
753 : : {
754 : : OSL_FAIL( "createNewContent called on non-folder object!" );
755 : 124 : return uno::Reference< ucb::XContent >();
756 : : }
757 : : }
758 : :
759 : : //=========================================================================
760 : : //
761 : : // Non-interface methods.
762 : : //
763 : : //=========================================================================
764 : :
765 : : // virtual
766 : 248 : rtl::OUString Content::getParentURL()
767 : : {
768 : 248 : return m_aUri.getParentUri();
769 : : }
770 : :
771 : : //=========================================================================
772 : : // static
773 : 12 : uno::Reference< sdbc::XRow > Content::getPropertyValues(
774 : : const uno::Reference< lang::XMultiServiceFactory >& rSMgr,
775 : : const uno::Sequence< beans::Property >& rProperties,
776 : : ContentProvider* pProvider,
777 : : const rtl::OUString& rContentId )
778 : : {
779 [ + - ]: 12 : ContentProperties aData;
780 : 12 : uno::Reference< container::XHierarchicalNameAccess > xPackage;
781 [ + - ][ + - ]: 12 : if ( loadData( pProvider, PackageUri( rContentId ), aData, xPackage ) )
782 : : {
783 : : return getPropertyValues( rSMgr,
784 : : rProperties,
785 : : aData,
786 : : rtl::Reference<
787 : : ::ucbhelper::ContentProviderImplHelper >(
788 : : pProvider ),
789 [ + - ]: 12 : rContentId );
790 : : }
791 : : else
792 : : {
793 : : rtl::Reference< ::ucbhelper::PropertyValueSet > xRow
794 [ # # ]: 0 : = new ::ucbhelper::PropertyValueSet( rSMgr );
795 : :
796 : 0 : sal_Int32 nCount = rProperties.getLength();
797 [ # # ]: 0 : if ( nCount )
798 : : {
799 : 0 : const beans::Property* pProps = rProperties.getConstArray();
800 [ # # ]: 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
801 [ # # ]: 0 : xRow->appendVoid( pProps[ n ] );
802 : : }
803 : :
804 [ # # ][ # # ]: 0 : return uno::Reference< sdbc::XRow >( xRow.get() );
805 [ + - ]: 12 : }
806 : : }
807 : :
808 : : //=========================================================================
809 : : // static
810 : 195 : uno::Reference< sdbc::XRow > Content::getPropertyValues(
811 : : const uno::Reference< lang::XMultiServiceFactory >& rSMgr,
812 : : const uno::Sequence< beans::Property >& rProperties,
813 : : const ContentProperties& rData,
814 : : const rtl::Reference< ::ucbhelper::ContentProviderImplHelper >&
815 : : rProvider,
816 : : const rtl::OUString& rContentId )
817 : : {
818 : : // Note: Empty sequence means "get values of all supported properties".
819 : :
820 : : rtl::Reference< ::ucbhelper::PropertyValueSet > xRow
821 [ + - ]: 195 : = new ::ucbhelper::PropertyValueSet( rSMgr );
822 : :
823 : 195 : sal_Int32 nCount = rProperties.getLength();
824 [ + - ]: 195 : if ( nCount )
825 : : {
826 : 195 : uno::Reference< beans::XPropertySet > xAdditionalPropSet;
827 : 195 : sal_Bool bTriedToGetAdditonalPropSet = sal_False;
828 : :
829 : 195 : const beans::Property* pProps = rProperties.getConstArray();
830 [ + + ]: 534 : for ( sal_Int32 n = 0; n < nCount; ++n )
831 : : {
832 : 339 : const beans::Property& rProp = pProps[ n ];
833 : :
834 : : // Process Core properties.
835 : :
836 [ + + ]: 339 : if ( rProp.Name == "ContentType" )
837 : : {
838 [ + - ]: 16 : xRow->appendString ( rProp, rData.aContentType );
839 : : }
840 [ + + ]: 323 : else if ( rProp.Name == "Title" )
841 : : {
842 [ + - ]: 16 : xRow->appendString ( rProp, rData.aTitle );
843 : : }
844 [ + + ]: 307 : else if ( rProp.Name == "IsDocument" )
845 : : {
846 [ + - ]: 34 : xRow->appendBoolean( rProp, rData.bIsDocument );
847 : : }
848 [ + + ]: 273 : else if ( rProp.Name == "IsFolder" )
849 : : {
850 [ + - ]: 34 : xRow->appendBoolean( rProp, rData.bIsFolder );
851 : : }
852 [ + + ]: 239 : else if ( rProp.Name == "CreatableContentsInfo" )
853 : : {
854 : : xRow->appendObject(
855 : : rProp, uno::makeAny(
856 : : rData.getCreatableContentsInfo(
857 [ + - ][ + - ]: 140 : PackageUri( rContentId ) ) ) );
[ + - ][ + - ]
858 : : }
859 [ + + ]: 99 : else if ( rProp.Name == "MediaType" )
860 : : {
861 [ + - ]: 51 : xRow->appendString ( rProp, rData.aMediaType );
862 : : }
863 [ + + ]: 48 : else if ( rProp.Name == "Size" )
864 : : {
865 : : // Property only available for streams.
866 [ + - ]: 8 : if ( rData.bIsDocument )
867 [ + - ]: 8 : xRow->appendLong( rProp, rData.nSize );
868 : : else
869 [ # # ]: 0 : xRow->appendVoid( rProp );
870 : : }
871 [ + + ]: 40 : else if ( rProp.Name == "Compressed" )
872 : : {
873 : : // Property only available for streams.
874 [ + - ]: 8 : if ( rData.bIsDocument )
875 [ + - ]: 8 : xRow->appendBoolean( rProp, rData.bCompressed );
876 : : else
877 [ # # ]: 0 : xRow->appendVoid( rProp );
878 : : }
879 [ + + ]: 32 : else if ( rProp.Name == "Encrypted" )
880 : : {
881 : : // Property only available for streams.
882 [ + - ]: 8 : if ( rData.bIsDocument )
883 [ + - ]: 8 : xRow->appendBoolean( rProp, rData.bEncrypted );
884 : : else
885 [ # # ]: 0 : xRow->appendVoid( rProp );
886 : : }
887 [ + + ]: 24 : else if ( rProp.Name == "HasEncryptedEntries" )
888 : : {
889 : : // Property only available for root folder.
890 : 4 : PackageUri aURI( rContentId );
891 [ + - ][ + - ]: 4 : if ( aURI.isRootFolder() )
892 [ + - ]: 4 : xRow->appendBoolean( rProp, rData.bHasEncryptedEntries );
893 : : else
894 [ # # ]: 4 : xRow->appendVoid( rProp );
895 : : }
896 : : else
897 : : {
898 : : // Not a Core Property! Maybe it's an Additional Core Property?!
899 : :
900 [ + + ][ + - ]: 20 : if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() )
[ + + ]
901 : : {
902 : : xAdditionalPropSet
903 : : = uno::Reference< beans::XPropertySet >(
904 : : rProvider->getAdditionalPropertySet( rContentId,
905 : : sal_False ),
906 [ + - ][ + - ]: 16 : uno::UNO_QUERY );
[ + - ]
907 : 16 : bTriedToGetAdditonalPropSet = sal_True;
908 : : }
909 : :
910 [ - + ]: 20 : if ( xAdditionalPropSet.is() )
911 : : {
912 [ # # ]: 0 : if ( !xRow->appendPropertySetValue(
913 : : xAdditionalPropSet,
914 [ # # ]: 0 : rProp ) )
915 : : {
916 : : // Append empty entry.
917 [ # # ]: 0 : xRow->appendVoid( rProp );
918 : : }
919 : : }
920 : : else
921 : : {
922 : : // Append empty entry.
923 [ + - ]: 20 : xRow->appendVoid( rProp );
924 : : }
925 : : }
926 : 195 : }
927 : : }
928 : : else
929 : : {
930 : : // Append all Core Properties.
931 : : xRow->appendString (
932 : : beans::Property(
933 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ContentType")),
934 : : -1,
935 [ # # ]: 0 : getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
936 : : beans::PropertyAttribute::BOUND
937 : : | beans::PropertyAttribute::READONLY ),
938 [ # # ][ # # ]: 0 : rData.aContentType );
939 : : xRow->appendString(
940 : : beans::Property(
941 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")),
942 : : -1,
943 [ # # ]: 0 : getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
944 : : beans::PropertyAttribute::BOUND ),
945 [ # # ][ # # ]: 0 : rData.aTitle );
946 : : xRow->appendBoolean(
947 : : beans::Property(
948 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsDocument")),
949 : : -1,
950 [ # # ]: 0 : getCppuBooleanType(),
951 : : beans::PropertyAttribute::BOUND
952 : : | beans::PropertyAttribute::READONLY ),
953 [ # # ][ # # ]: 0 : rData.bIsDocument );
954 : : xRow->appendBoolean(
955 : : beans::Property(
956 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsFolder")),
957 : : -1,
958 [ # # ]: 0 : getCppuBooleanType(),
959 : : beans::PropertyAttribute::BOUND
960 : : | beans::PropertyAttribute::READONLY ),
961 [ # # ][ # # ]: 0 : rData.bIsFolder );
962 : : xRow->appendObject(
963 : : beans::Property(
964 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CreatableContentsInfo")),
965 : : -1,
966 : : getCppuType( static_cast<
967 [ # # ]: 0 : const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
968 : : beans::PropertyAttribute::BOUND
969 : : | beans::PropertyAttribute::READONLY ),
970 : : uno::makeAny(
971 [ # # ][ # # ]: 0 : rData.getCreatableContentsInfo( PackageUri( rContentId ) ) ) );
[ # # ][ # # ]
[ # # ]
972 : : xRow->appendString(
973 : : beans::Property(
974 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType")),
975 : : -1,
976 [ # # ]: 0 : getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
977 : : beans::PropertyAttribute::BOUND ),
978 [ # # ][ # # ]: 0 : rData.aMediaType );
979 : :
980 : : // Properties only available for streams.
981 [ # # ]: 0 : if ( rData.bIsDocument )
982 : : {
983 : : xRow->appendLong(
984 : : beans::Property(
985 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size")),
986 : : -1,
987 [ # # ]: 0 : getCppuType( static_cast< const sal_Int64 * >( 0 ) ),
988 : : beans::PropertyAttribute::BOUND
989 : : | beans::PropertyAttribute::READONLY ),
990 [ # # ][ # # ]: 0 : rData.nSize );
991 : :
992 : : xRow->appendBoolean(
993 : : beans::Property(
994 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Compressed")),
995 : : -1,
996 [ # # ]: 0 : getCppuBooleanType(),
997 : : beans::PropertyAttribute::BOUND ),
998 [ # # ][ # # ]: 0 : rData.bCompressed );
999 : :
1000 : : xRow->appendBoolean(
1001 : : beans::Property(
1002 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted")),
1003 : : -1,
1004 [ # # ]: 0 : getCppuBooleanType(),
1005 : : beans::PropertyAttribute::BOUND ),
1006 [ # # ][ # # ]: 0 : rData.bEncrypted );
1007 : : }
1008 : :
1009 : : // Properties only available for root folder.
1010 : 0 : PackageUri aURI( rContentId );
1011 [ # # ][ # # ]: 0 : if ( aURI.isRootFolder() )
1012 : : {
1013 : : xRow->appendBoolean(
1014 : : beans::Property(
1015 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasEncryptedEntries")),
1016 : : -1,
1017 [ # # ]: 0 : getCppuBooleanType(),
1018 : : beans::PropertyAttribute::BOUND
1019 : : | beans::PropertyAttribute::READONLY ),
1020 [ # # ][ # # ]: 0 : rData.bHasEncryptedEntries );
1021 : : }
1022 : :
1023 : : // Append all Additional Core Properties.
1024 : :
1025 : : uno::Reference< beans::XPropertySet > xSet(
1026 : : rProvider->getAdditionalPropertySet( rContentId, sal_False ),
1027 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
1028 [ # # ]: 0 : xRow->appendPropertySet( xSet );
1029 : : }
1030 : :
1031 [ + - ][ + - ]: 195 : return uno::Reference< sdbc::XRow >( xRow.get() );
1032 : : }
1033 : :
1034 : : //=========================================================================
1035 : 183 : uno::Reference< sdbc::XRow > Content::getPropertyValues(
1036 : : const uno::Sequence< beans::Property >& rProperties )
1037 : : {
1038 [ + - ]: 183 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
1039 : : return getPropertyValues( m_xSMgr,
1040 : : rProperties,
1041 : : m_aProps,
1042 : : rtl::Reference<
1043 : : ::ucbhelper::ContentProviderImplHelper >(
1044 : : m_xProvider.get() ),
1045 [ + - ][ + - ]: 183 : m_xIdentifier->getContentIdentifier() );
[ + - ][ + - ]
1046 : : }
1047 : :
1048 : : //=========================================================================
1049 : 124 : uno::Sequence< uno::Any > Content::setPropertyValues(
1050 : : const uno::Sequence< beans::PropertyValue >& rValues,
1051 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1052 : : throw( uno::Exception )
1053 : : {
1054 [ + - ]: 124 : osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1055 : :
1056 [ + - ]: 124 : uno::Sequence< uno::Any > aRet( rValues.getLength() );
1057 [ + - ]: 124 : uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() );
1058 : 124 : sal_Int32 nChanged = 0;
1059 : :
1060 [ + - ]: 124 : beans::PropertyChangeEvent aEvent;
1061 [ + - ]: 124 : aEvent.Source = static_cast< cppu::OWeakObject * >( this );
1062 : 124 : aEvent.Further = sal_False;
1063 : : // aEvent.PropertyName =
1064 : 124 : aEvent.PropertyHandle = -1;
1065 : : // aEvent.OldValue =
1066 : : // aEvent.NewValue =
1067 : :
1068 : 124 : const beans::PropertyValue* pValues = rValues.getConstArray();
1069 : 124 : sal_Int32 nCount = rValues.getLength();
1070 : :
1071 : 124 : uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet;
1072 : 124 : sal_Bool bTriedToGetAdditonalPropSet = sal_False;
1073 : 124 : sal_Bool bExchange = sal_False;
1074 : 124 : sal_Bool bStore = sal_False;
1075 : 124 : rtl::OUString aNewTitle;
1076 : 124 : sal_Int32 nTitlePos = -1;
1077 : :
1078 [ + + ]: 1984 : for ( sal_Int32 n = 0; n < nCount; ++n )
1079 : : {
1080 : 1860 : const beans::PropertyValue& rValue = pValues[ n ];
1081 : :
1082 [ + + ]: 1860 : if ( rValue.Name == "ContentType" )
1083 : : {
1084 : : // Read-only property!
1085 [ + - ]: 124 : aRet[ n ] <<= lang::IllegalAccessException(
1086 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1087 : : "Property is read-only!" )),
1088 [ + - ][ + - ]: 248 : static_cast< cppu::OWeakObject * >( this ) );
[ + - ][ + - ]
[ + - ]
1089 : : }
1090 [ + + ]: 1736 : else if ( rValue.Name == "IsDocument" )
1091 : : {
1092 : : // Read-only property!
1093 [ + - ]: 124 : aRet[ n ] <<= lang::IllegalAccessException(
1094 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1095 : : "Property is read-only!" )),
1096 [ + - ][ + - ]: 248 : static_cast< cppu::OWeakObject * >( this ) );
[ + - ][ + - ]
[ + - ]
1097 : : }
1098 [ + + ]: 1612 : else if ( rValue.Name == "IsFolder" )
1099 : : {
1100 : : // Read-only property!
1101 [ + - ]: 124 : aRet[ n ] <<= lang::IllegalAccessException(
1102 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1103 : : "Property is read-only!" )),
1104 [ + - ][ + - ]: 248 : static_cast< cppu::OWeakObject * >( this ) );
[ + - ][ + - ]
[ + - ]
1105 : : }
1106 [ + + ]: 1488 : else if ( rValue.Name == "CreatableContentsInfo" )
1107 : : {
1108 : : // Read-only property!
1109 [ + - ]: 124 : aRet[ n ] <<= lang::IllegalAccessException(
1110 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1111 : : "Property is read-only!" )),
1112 [ + - ][ + - ]: 248 : static_cast< cppu::OWeakObject * >( this ) );
[ + - ][ + - ]
[ + - ]
1113 : : }
1114 [ + + ]: 1364 : else if ( rValue.Name == "Title" )
1115 : : {
1116 [ + - ][ - + ]: 124 : if ( m_aUri.isRootFolder() )
1117 : : {
1118 : : // Read-only property!
1119 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1120 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1121 : : "Property is read-only!" )),
1122 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1123 : : }
1124 : : else
1125 : : {
1126 : 124 : rtl::OUString aNewValue;
1127 [ + - ]: 124 : if ( rValue.Value >>= aNewValue )
1128 : : {
1129 : : // No empty titles!
1130 [ + - ]: 124 : if ( !aNewValue.isEmpty() )
1131 : : {
1132 [ + - ]: 124 : if ( aNewValue != m_aProps.aTitle )
1133 : : {
1134 : : // modified title -> modified URL -> exchange !
1135 [ - + ]: 124 : if ( m_eState == PERSISTENT )
1136 : 0 : bExchange = sal_True;
1137 : :
1138 : : // new value will be set later...
1139 : 124 : aNewTitle = aNewValue;
1140 : :
1141 : : // remember position within sequence of values
1142 : : // (for error handling).
1143 : 124 : nTitlePos = n;
1144 : : }
1145 : : }
1146 : : else
1147 : : {
1148 [ # # ]: 0 : aRet[ n ] <<=
1149 : : lang::IllegalArgumentException(
1150 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1151 : : "Empty title not allowed!" )),
1152 : : static_cast< cppu::OWeakObject * >( this ),
1153 [ # # ][ # # ]: 0 : -1 );
[ # # ][ # # ]
[ # # ]
1154 : : }
1155 : : }
1156 : : else
1157 : : {
1158 [ # # ]: 0 : aRet[ n ] <<=
1159 : : beans::IllegalTypeException(
1160 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1161 : : "Property value has wrong type!" )),
1162 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1163 : 124 : }
1164 : : }
1165 : : }
1166 [ - + ]: 1240 : else if ( rValue.Name == "MediaType" )
1167 : : {
1168 : 0 : rtl::OUString aNewValue;
1169 [ # # ]: 0 : if ( rValue.Value >>= aNewValue )
1170 : : {
1171 [ # # ]: 0 : if ( aNewValue != m_aProps.aMediaType )
1172 : : {
1173 : 0 : aEvent.PropertyName = rValue.Name;
1174 [ # # ]: 0 : aEvent.OldValue = uno::makeAny( m_aProps.aMediaType );
1175 [ # # ]: 0 : aEvent.NewValue = uno::makeAny( aNewValue );
1176 : :
1177 : 0 : m_aProps.aMediaType = aNewValue;
1178 : 0 : nChanged++;
1179 : 0 : bStore = sal_True;
1180 : 0 : m_nModifiedProps |= MEDIATYPE_MODIFIED;
1181 : : }
1182 : : }
1183 : : else
1184 : : {
1185 [ # # ]: 0 : aRet[ n ] <<= beans::IllegalTypeException(
1186 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1187 : : "Property value has wrong type!" )),
1188 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1189 : 0 : }
1190 : : }
1191 [ + + ]: 1240 : else if ( rValue.Name == "Size" )
1192 : : {
1193 : : // Read-only property!
1194 [ + - ]: 124 : aRet[ n ] <<= lang::IllegalAccessException(
1195 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1196 : : "Property is read-only!" )),
1197 [ + - ][ + - ]: 248 : static_cast< cppu::OWeakObject * >( this ) );
[ + - ][ + - ]
[ + - ]
1198 : : }
1199 [ - + ]: 1116 : else if ( rValue.Name == "Compressed" )
1200 : : {
1201 : : // Property only available for streams.
1202 [ # # ]: 0 : if ( m_aProps.bIsDocument )
1203 : : {
1204 : : sal_Bool bNewValue;
1205 [ # # ]: 0 : if ( rValue.Value >>= bNewValue )
1206 : : {
1207 [ # # ]: 0 : if ( bNewValue != m_aProps.bCompressed )
1208 : : {
1209 : 0 : aEvent.PropertyName = rValue.Name;
1210 [ # # ]: 0 : aEvent.OldValue = uno::makeAny( m_aProps.bCompressed );
1211 [ # # ]: 0 : aEvent.NewValue = uno::makeAny( bNewValue );
1212 : :
1213 : 0 : m_aProps.bCompressed = bNewValue;
1214 : 0 : nChanged++;
1215 : 0 : bStore = sal_True;
1216 : 0 : m_nModifiedProps |= COMPRESSED_MODIFIED;
1217 : : }
1218 : : }
1219 : : else
1220 : : {
1221 [ # # ]: 0 : aRet[ n ] <<= beans::IllegalTypeException(
1222 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1223 : : "Property value has wrong type!" )),
1224 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1225 : : }
1226 : : }
1227 : : else
1228 : : {
1229 [ # # ]: 0 : aRet[ n ] <<= beans::UnknownPropertyException(
1230 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1231 : : "Compressed only supported by streams!" )),
1232 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1233 : : }
1234 : : }
1235 [ - + ]: 1116 : else if ( rValue.Name == "Encrypted" )
1236 : : {
1237 : : // Property only available for streams.
1238 [ # # ]: 0 : if ( m_aProps.bIsDocument )
1239 : : {
1240 : : sal_Bool bNewValue;
1241 [ # # ]: 0 : if ( rValue.Value >>= bNewValue )
1242 : : {
1243 [ # # ]: 0 : if ( bNewValue != m_aProps.bEncrypted )
1244 : : {
1245 : 0 : aEvent.PropertyName = rValue.Name;
1246 [ # # ]: 0 : aEvent.OldValue = uno::makeAny( m_aProps.bEncrypted );
1247 [ # # ]: 0 : aEvent.NewValue = uno::makeAny( bNewValue );
1248 : :
1249 : 0 : m_aProps.bEncrypted = bNewValue;
1250 : 0 : nChanged++;
1251 : 0 : bStore = sal_True;
1252 : 0 : m_nModifiedProps |= ENCRYPTED_MODIFIED;
1253 : : }
1254 : : }
1255 : : else
1256 : : {
1257 [ # # ]: 0 : aRet[ n ] <<= beans::IllegalTypeException(
1258 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1259 : : "Property value has wrong type!" )),
1260 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1261 : : }
1262 : : }
1263 : : else
1264 : : {
1265 [ # # ]: 0 : aRet[ n ] <<= beans::UnknownPropertyException(
1266 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1267 : : "Encrypted only supported by streams!" )),
1268 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1269 : : }
1270 : : }
1271 [ - + ]: 1116 : else if ( rValue.Name == "HasEncryptedEntries" )
1272 : : {
1273 : : // Read-only property!
1274 [ # # ]: 0 : aRet[ n ] <<= lang::IllegalAccessException(
1275 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1276 : : "Property is read-only!" )),
1277 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1278 : : }
1279 [ - + ]: 1116 : else if ( rValue.Name == "EncryptionKey" )
1280 : : {
1281 : : // @@@ This is a temporary solution. In the future submitting
1282 : : // the key should be done using an interaction handler!
1283 : :
1284 : : // Write-Only property. Only supported by root folder and streams
1285 : : // (all non-root folders of a package have the same encryption key).
1286 [ # # ][ # # ]: 0 : if ( m_aUri.isRootFolder() || m_aProps.bIsDocument )
[ # # ][ # # ]
1287 : : {
1288 [ # # ]: 0 : uno::Sequence < sal_Int8 > aNewValue;
1289 [ # # ][ # # ]: 0 : if ( rValue.Value >>= aNewValue )
1290 : : {
1291 [ # # ][ # # ]: 0 : if ( aNewValue != m_aProps.aEncryptionKey )
1292 : : {
1293 : 0 : aEvent.PropertyName = rValue.Name;
1294 : : aEvent.OldValue = uno::makeAny(
1295 [ # # ]: 0 : m_aProps.aEncryptionKey );
1296 [ # # ]: 0 : aEvent.NewValue = uno::makeAny( aNewValue );
1297 : :
1298 [ # # ]: 0 : m_aProps.aEncryptionKey = aNewValue;
1299 : 0 : nChanged++;
1300 : 0 : bStore = sal_True;
1301 : 0 : m_nModifiedProps |= ENCRYPTIONKEY_MODIFIED;
1302 : : }
1303 : : }
1304 : : else
1305 : : {
1306 [ # # ]: 0 : aRet[ n ] <<= beans::IllegalTypeException(
1307 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1308 : : "Property value has wrong type!" )),
1309 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1310 [ # # ]: 0 : }
1311 : : }
1312 : : else
1313 : : {
1314 [ # # ]: 0 : aRet[ n ] <<= beans::UnknownPropertyException(
1315 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1316 : : "EncryptionKey not supported by non-root folder!" )),
1317 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1318 : : }
1319 : : }
1320 : : else
1321 : : {
1322 : : // Not a Core Property! Maybe it's an Additional Core Property?!
1323 : :
1324 [ + + ][ + - ]: 1116 : if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() )
[ + + ]
1325 : : {
1326 [ + - ][ + - ]: 124 : xAdditionalPropSet = getAdditionalPropertySet( sal_False );
1327 : 124 : bTriedToGetAdditonalPropSet = sal_True;
1328 : : }
1329 : :
1330 [ - + ]: 1116 : if ( xAdditionalPropSet.is() )
1331 : : {
1332 : : try
1333 : : {
1334 : : uno::Any aOldValue
1335 [ # # ][ # # ]: 0 : = xAdditionalPropSet->getPropertyValue( rValue.Name );
1336 [ # # ]: 0 : if ( aOldValue != rValue.Value )
1337 : : {
1338 [ # # ]: 0 : xAdditionalPropSet->setPropertyValue(
1339 [ # # ]: 0 : rValue.Name, rValue.Value );
1340 : :
1341 : 0 : aEvent.PropertyName = rValue.Name;
1342 : 0 : aEvent.OldValue = aOldValue;
1343 : 0 : aEvent.NewValue = rValue.Value;
1344 : :
1345 [ # # ][ # # ]: 0 : aChanges.getArray()[ nChanged ] = aEvent;
1346 : 0 : nChanged++;
1347 : 0 : }
1348 : : }
1349 [ # # ]: 0 : catch ( beans::UnknownPropertyException const & e )
1350 : : {
1351 [ # # # # ]: 0 : aRet[ n ] <<= e;
1352 : : }
1353 [ # # ]: 0 : catch ( lang::WrappedTargetException const & e )
1354 : : {
1355 [ # # # # ]: 0 : aRet[ n ] <<= e;
1356 : : }
1357 [ # # ]: 0 : catch ( beans::PropertyVetoException const & e )
1358 : : {
1359 [ # # # # ]: 0 : aRet[ n ] <<= e;
1360 : : }
1361 [ # # # # : 0 : catch ( lang::IllegalArgumentException const & e )
# # # ]
1362 : : {
1363 [ # # # # ]: 0 : aRet[ n ] <<= e;
1364 : : }
1365 : : }
1366 : : else
1367 : : {
1368 [ + - ]: 1116 : aRet[ n ] <<= uno::Exception(
1369 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1370 : : "No property set for storing the value!" )),
1371 [ + - ][ + - ]: 2232 : static_cast< cppu::OWeakObject * >( this ) );
[ + - ][ + - ]
[ + - ]
1372 : : }
1373 : : }
1374 : : }
1375 : :
1376 [ - + ]: 124 : if ( bExchange )
1377 : : {
1378 : 0 : uno::Reference< ucb::XContentIdentifier > xOldId = m_xIdentifier;
1379 : :
1380 : : // Assemble new content identifier...
1381 [ # # ]: 0 : rtl::OUString aNewURL = m_aUri.getParentUri();
1382 [ # # ]: 0 : aNewURL += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
1383 : 0 : aNewURL += ::ucb_impl::urihelper::encodeSegment( aNewTitle );
1384 : : uno::Reference< ucb::XContentIdentifier > xNewId
1385 [ # # ][ # # ]: 0 : = new ::ucbhelper::ContentIdentifier( m_xSMgr, aNewURL );
[ # # ]
1386 : :
1387 [ # # ]: 0 : aGuard.clear();
1388 [ # # ][ # # ]: 0 : if ( exchangeIdentity( xNewId ) )
1389 : : {
1390 : : // Adapt persistent data.
1391 [ # # ]: 0 : renameData( xOldId, xNewId );
1392 : :
1393 : : // Adapt Additional Core Properties.
1394 [ # # ]: 0 : renameAdditionalPropertySet( xOldId->getContentIdentifier(),
1395 [ # # ]: 0 : xNewId->getContentIdentifier(),
1396 [ # # ][ # # ]: 0 : sal_True );
[ # # ]
1397 : : }
1398 : : else
1399 : : {
1400 : : // Do not set new title!
1401 : 0 : aNewTitle = rtl::OUString();
1402 : :
1403 : : // Set error .
1404 [ # # ]: 0 : aRet[ nTitlePos ] <<= uno::Exception(
1405 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Exchange failed!")),
1406 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
[ # # ][ # # ]
[ # # ]
1407 : 0 : }
1408 : : }
1409 : :
1410 [ + - ]: 124 : if ( !aNewTitle.isEmpty() )
1411 : : {
1412 [ + - ]: 124 : aEvent.PropertyName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title"));
1413 [ + - ]: 124 : aEvent.OldValue = uno::makeAny( m_aProps.aTitle );
1414 [ + - ]: 124 : aEvent.NewValue = uno::makeAny( aNewTitle );
1415 : :
1416 : 124 : m_aProps.aTitle = aNewTitle;
1417 : :
1418 [ + - ][ + - ]: 124 : aChanges.getArray()[ nChanged ] = aEvent;
1419 : 124 : nChanged++;
1420 : : }
1421 : :
1422 [ + - ]: 124 : if ( nChanged > 0 )
1423 : : {
1424 : : // Save changes, if content was already made persistent.
1425 [ + - ][ - + ]: 124 : if ( ( m_nModifiedProps & ENCRYPTIONKEY_MODIFIED ) ||
[ # # ]
1426 : : ( bStore && ( m_eState == PERSISTENT ) ) )
1427 : : {
1428 [ # # ][ # # ]: 0 : if ( !storeData( uno::Reference< io::XInputStream >() ) )
1429 : : {
1430 : : uno::Any aProps
1431 : : = uno::makeAny(
1432 : : beans::PropertyValue(
1433 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1434 : : "Uri")),
1435 : : -1,
1436 [ # # ]: 0 : uno::makeAny(m_xIdentifier->
1437 : 0 : getContentIdentifier()),
1438 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ][ # # ]
1439 : : ucbhelper::cancelCommandExecution(
1440 : : ucb::IOErrorCode_CANT_WRITE,
1441 : : uno::Sequence< uno::Any >(&aProps, 1),
1442 : : xEnv,
1443 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1444 : : "Cannot store persistent data!" )),
1445 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
[ # # ]
1446 : : // Unreachable
1447 : : }
1448 : : }
1449 : :
1450 [ + - ]: 124 : aGuard.clear();
1451 [ + - ]: 124 : aChanges.realloc( nChanged );
1452 [ + - ]: 124 : notifyPropertiesChange( aChanges );
1453 : : }
1454 : :
1455 [ + - ][ + - ]: 124 : return aRet;
[ + - ]
1456 : : }
1457 : :
1458 : : //=========================================================================
1459 : 53 : uno::Any Content::open(
1460 : : const ucb::OpenCommandArgument2& rArg,
1461 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1462 : : throw( uno::Exception )
1463 : : {
1464 [ + + ][ + - ]: 53 : if ( rArg.Mode == ucb::OpenMode::ALL ||
[ - + ]
1465 : : rArg.Mode == ucb::OpenMode::FOLDERS ||
1466 : : rArg.Mode == ucb::OpenMode::DOCUMENTS )
1467 : : {
1468 : : //////////////////////////////////////////////////////////////////
1469 : : // open command for a folder content
1470 : : //////////////////////////////////////////////////////////////////
1471 : :
1472 : : uno::Reference< ucb::XDynamicResultSet > xSet
1473 [ + - ][ + - ]: 43 : = new DynamicResultSet( m_xSMgr, this, rArg, xEnv );
[ + - ]
1474 [ + - ]: 43 : return uno::makeAny( xSet );
1475 : : }
1476 : : else
1477 : : {
1478 : : //////////////////////////////////////////////////////////////////
1479 : : // open command for a document content
1480 : : //////////////////////////////////////////////////////////////////
1481 : :
1482 [ + - ][ - + ]: 10 : if ( ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
1483 : : ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) )
1484 : : {
1485 : : // Currently(?) unsupported.
1486 : : ucbhelper::cancelCommandExecution(
1487 : : uno::makeAny( ucb::UnsupportedOpenModeException(
1488 : : rtl::OUString(),
1489 : : static_cast< cppu::OWeakObject * >( this ),
1490 : : sal_Int16( rArg.Mode ) ) ),
1491 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
1492 : : // Unreachable
1493 : : }
1494 : :
1495 [ + - ][ + - ]: 10 : rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
1496 [ + - ]: 10 : uno::Reference< io::XOutputStream > xOut( rArg.Sink, uno::UNO_QUERY );
1497 [ + + ]: 10 : if ( xOut.is() )
1498 : : {
1499 : : // PUSH: write data into xOut
1500 : :
1501 [ + - ]: 2 : uno::Reference< io::XInputStream > xIn = getInputStream();
1502 [ - + ]: 2 : if ( !xIn.is() )
1503 : : {
1504 : : // No interaction if we are not persistent!
1505 : : uno::Any aProps
1506 : : = uno::makeAny(
1507 : : beans::PropertyValue(
1508 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1509 : : "Uri")),
1510 : : -1,
1511 [ # # ]: 0 : uno::makeAny(m_xIdentifier->
1512 : 0 : getContentIdentifier()),
1513 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ][ # # ]
1514 : : ucbhelper::cancelCommandExecution(
1515 : : ucb::IOErrorCode_CANT_READ,
1516 : : uno::Sequence< uno::Any >(&aProps, 1),
1517 : : m_eState == PERSISTENT
1518 : : ? xEnv
1519 : : : uno::Reference< ucb::XCommandEnvironment >(),
1520 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Got no data stream!")),
1521 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
[ # # ][ # # ]
1522 : : // Unreachable
1523 : : }
1524 : :
1525 : : try
1526 : : {
1527 [ + - ]: 2 : uno::Sequence< sal_Int8 > aBuffer;
1528 [ + - ][ + - ]: 2 : sal_Int32 nRead = xIn->readSomeBytes( aBuffer, 65536 );
1529 : :
1530 [ + + ]: 4 : while ( nRead > 0 )
1531 : : {
1532 [ + - ]: 2 : aBuffer.realloc( nRead );
1533 [ + - ][ + - ]: 2 : xOut->writeBytes( aBuffer );
1534 [ + - ]: 2 : aBuffer.realloc( 0 );
1535 [ + - ][ + - ]: 2 : nRead = xIn->readSomeBytes( aBuffer, 65536 );
1536 : : }
1537 : :
1538 [ + - ][ + - ]: 2 : xOut->closeOutput();
[ + - ]
[ # # # # ]
1539 : : }
1540 [ # # ]: 0 : catch ( io::NotConnectedException const & )
1541 : : {
1542 : : // closeOutput, readSomeBytes, writeBytes
1543 : : }
1544 [ # # ]: 0 : catch ( io::BufferSizeExceededException const & )
1545 : : {
1546 : : // closeOutput, readSomeBytes, writeBytes
1547 : : }
1548 [ # # ]: 0 : catch ( io::IOException const & )
1549 : : {
1550 : : // closeOutput, readSomeBytes, writeBytes
1551 : 2 : }
1552 : : }
1553 : : else
1554 : : {
1555 : : uno::Reference< io::XActiveDataSink > xDataSink(
1556 [ + - ]: 8 : rArg.Sink, uno::UNO_QUERY );
1557 [ + - ]: 8 : if ( xDataSink.is() )
1558 : : {
1559 : : // PULL: wait for client read
1560 : :
1561 [ + - ]: 8 : uno::Reference< io::XInputStream > xIn = getInputStream();
1562 [ - + ]: 8 : if ( !xIn.is() )
1563 : : {
1564 : : // No interaction if we are not persistent!
1565 : : uno::Any aProps
1566 : : = uno::makeAny(
1567 : : beans::PropertyValue(
1568 : : rtl::OUString( "Uri"),
1569 : : -1,
1570 [ # # ]: 0 : uno::makeAny(m_xIdentifier->
1571 : 0 : getContentIdentifier()),
1572 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ]
1573 : : ucbhelper::cancelCommandExecution(
1574 : : ucb::IOErrorCode_CANT_READ,
1575 : : uno::Sequence< uno::Any >(&aProps, 1),
1576 : : m_eState == PERSISTENT
1577 : : ? xEnv
1578 : : : uno::Reference<
1579 : : ucb::XCommandEnvironment >(),
1580 : : rtl::OUString( "Got no data stream!" ),
1581 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
[ # # ]
1582 : : // Unreachable
1583 : : }
1584 : :
1585 : : // Done.
1586 [ + - ][ + - ]: 8 : xDataSink->setInputStream( xIn );
1587 : : }
1588 : : else
1589 : : {
1590 : : // Note: aOpenCommand.Sink may contain an XStream
1591 : : // implementation. Support for this type of
1592 : : // sink is optional...
1593 : : ucbhelper::cancelCommandExecution(
1594 : : uno::makeAny(
1595 : : ucb::UnsupportedDataSinkException(
1596 : : rtl::OUString(),
1597 : : static_cast< cppu::OWeakObject * >( this ),
1598 : : rArg.Sink ) ),
1599 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
1600 : : // Unreachable
1601 : 8 : }
1602 : 10 : }
1603 : : }
1604 : :
1605 : 53 : return uno::Any();
1606 : : }
1607 : :
1608 : : //=========================================================================
1609 : 124 : void Content::insert(
1610 : : const uno::Reference< io::XInputStream >& xStream,
1611 : : sal_Int32 nNameClashResolve,
1612 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1613 : : throw( uno::Exception )
1614 : : {
1615 [ + - ]: 124 : osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1616 : :
1617 : : // Check, if all required properties were set.
1618 [ + + ]: 124 : if ( isFolder() )
1619 : : {
1620 : : // Required: Title
1621 : :
1622 [ - + ]: 62 : if ( m_aProps.aTitle.isEmpty() )
1623 [ # # ]: 0 : m_aProps.aTitle = m_aUri.getName();
1624 : : }
1625 : : else
1626 : : {
1627 : : // Required: rArg.Data
1628 : :
1629 [ - + ]: 62 : if ( !xStream.is() )
1630 : : {
1631 : : ucbhelper::cancelCommandExecution(
1632 : : uno::makeAny( ucb::MissingInputStreamException(
1633 : : rtl::OUString(),
1634 : : static_cast< cppu::OWeakObject * >( this ) ) ),
1635 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
1636 : : // Unreachable
1637 : : }
1638 : :
1639 : : // Required: Title
1640 : :
1641 [ - + ]: 62 : if ( m_aProps.aTitle.isEmpty() )
1642 [ # # ]: 0 : m_aProps.aTitle = m_aUri.getName();
1643 : : }
1644 : :
1645 [ + - ]: 124 : rtl::OUString aNewURL = m_aUri.getParentUri();
1646 [ + - ]: 124 : if (1 + aNewURL.lastIndexOf('/') != aNewURL.getLength())
1647 : 124 : aNewURL += rtl::OUString("/");
1648 : 124 : aNewURL += ::ucb_impl::urihelper::encodeSegment( m_aProps.aTitle );
1649 : 124 : PackageUri aNewUri( aNewURL );
1650 : :
1651 : : // Handle possible name clash...
1652 [ - + - - ]: 124 : switch ( nNameClashResolve )
1653 : : {
1654 : : // fail.
1655 : : case ucb::NameClash::ERROR:
1656 [ # # ][ # # ]: 0 : if ( hasData( aNewUri ) )
1657 : : {
1658 : : ucbhelper::cancelCommandExecution(
1659 : : uno::makeAny( ucb::NameClashException(
1660 : : rtl::OUString(),
1661 : : static_cast< cppu::OWeakObject * >( this ),
1662 : : task::InteractionClassification_ERROR,
1663 : : m_aProps.aTitle ) ),
1664 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
1665 : : // Unreachable
1666 : : }
1667 : 0 : break;
1668 : :
1669 : : // replace (possibly) existing object.
1670 : : case ucb::NameClash::OVERWRITE:
1671 : 124 : break;
1672 : :
1673 : : // "invent" a new valid title.
1674 : : case ucb::NameClash::RENAME:
1675 [ # # ][ # # ]: 0 : if ( hasData( aNewUri ) )
1676 : : {
1677 : 0 : sal_Int32 nTry = 0;
1678 : :
1679 [ # # ][ # # ]: 0 : do
[ # # ]
1680 : : {
1681 [ # # ]: 0 : rtl::OUString aNew = aNewUri.getUri();
1682 : 0 : aNew += rtl::OUString("_");
1683 : 0 : aNew += rtl::OUString::valueOf( ++nTry );
1684 : 0 : aNewUri.setUri( aNew );
1685 : : }
1686 [ # # ]: 0 : while ( hasData( aNewUri ) && ( nTry < 1000 ) );
1687 : :
1688 [ # # ]: 0 : if ( nTry == 1000 )
1689 : : {
1690 : : ucbhelper::cancelCommandExecution(
1691 : : uno::makeAny(
1692 : : ucb::UnsupportedNameClashException(
1693 : : rtl::OUString( "Unable to resolve name clash!" ),
1694 : : static_cast< cppu::OWeakObject * >( this ),
1695 : : nNameClashResolve ) ),
1696 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
1697 : : // Unreachable
1698 : : }
1699 : : else
1700 : : {
1701 : 0 : m_aProps.aTitle += rtl::OUString("_");
1702 : 0 : m_aProps.aTitle += rtl::OUString::valueOf( nTry );
1703 : : }
1704 : : }
1705 : 0 : break;
1706 : :
1707 : : case ucb::NameClash::KEEP: // deprecated
1708 : : case ucb::NameClash::ASK:
1709 : : default:
1710 [ # # ][ # # ]: 0 : if ( hasData( aNewUri ) )
1711 : : {
1712 : : ucbhelper::cancelCommandExecution(
1713 : : uno::makeAny(
1714 : : ucb::UnsupportedNameClashException(
1715 : : rtl::OUString(),
1716 : : static_cast< cppu::OWeakObject * >( this ),
1717 : : nNameClashResolve ) ),
1718 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
1719 : : // Unreachable
1720 : : }
1721 : 0 : break;
1722 : : }
1723 : :
1724 : : // Identifier changed?
1725 [ + - ][ + - ]: 124 : sal_Bool bNewId = ( m_aUri.getUri() != aNewUri.getUri() );
1726 : :
1727 [ + - ]: 124 : if ( bNewId )
1728 : : {
1729 [ + - ][ + - ]: 124 : m_xIdentifier = new ::ucbhelper::ContentIdentifier( m_xSMgr, aNewURL );
[ + - ]
1730 : 124 : m_aUri = aNewUri;
1731 : : }
1732 : :
1733 [ + - ][ - + ]: 124 : if ( !storeData( xStream ) )
1734 : : {
1735 : : uno::Any aProps
1736 : : = uno::makeAny(beans::PropertyValue(
1737 : : rtl::OUString( "Uri"),
1738 : : -1,
1739 [ # # ]: 0 : uno::makeAny(m_xIdentifier->
1740 : 0 : getContentIdentifier()),
1741 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ]
1742 : : ucbhelper::cancelCommandExecution(
1743 : : ucb::IOErrorCode_CANT_WRITE,
1744 : : uno::Sequence< uno::Any >(&aProps, 1),
1745 : : xEnv,
1746 : : rtl::OUString("Cannot store persistent data!"),
1747 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
1748 : : // Unreachable
1749 : : }
1750 : :
1751 : 124 : m_eState = PERSISTENT;
1752 : :
1753 [ + - ]: 124 : if ( bNewId )
1754 : : {
1755 : : // Take over correct default values from underlying packager...
1756 : 124 : uno::Reference< container::XHierarchicalNameAccess > xXHierarchicalNameAccess;
1757 : : loadData( m_pProvider,
1758 : : m_aUri,
1759 : : m_aProps,
1760 [ + - ]: 124 : xXHierarchicalNameAccess );
1761 : :
1762 [ + - ]: 124 : aGuard.clear();
1763 [ + - ]: 124 : inserted();
1764 [ + - ]: 124 : }
1765 : 124 : }
1766 : :
1767 : : //=========================================================================
1768 : 0 : void Content::destroy(
1769 : : sal_Bool bDeletePhysical,
1770 : : const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1771 : : throw( uno::Exception )
1772 : : {
1773 : : // @@@ take care about bDeletePhysical -> trashcan support
1774 : :
1775 [ # # ]: 0 : osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1776 : :
1777 [ # # ]: 0 : uno::Reference< ucb::XContent > xThis = this;
1778 : :
1779 : : // Persistent?
1780 [ # # ]: 0 : if ( m_eState != PERSISTENT )
1781 : : {
1782 : : ucbhelper::cancelCommandExecution(
1783 : : uno::makeAny( ucb::UnsupportedCommandException(
1784 : : rtl::OUString( "Not persistent!" ),
1785 : : static_cast< cppu::OWeakObject * >( this ) ) ),
1786 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
1787 : : // Unreachable
1788 : : }
1789 : :
1790 : 0 : m_eState = DEAD;
1791 : :
1792 [ # # ]: 0 : aGuard.clear();
1793 [ # # ]: 0 : deleted();
1794 : :
1795 [ # # ]: 0 : if ( isFolder() )
1796 : : {
1797 : : // Process instanciated children...
1798 : :
1799 [ # # ]: 0 : ContentRefList aChildren;
1800 [ # # ]: 0 : queryChildren( aChildren );
1801 : :
1802 : 0 : ContentRefList::const_iterator it = aChildren.begin();
1803 : 0 : ContentRefList::const_iterator end = aChildren.end();
1804 : :
1805 [ # # ]: 0 : while ( it != end )
1806 : : {
1807 [ # # ]: 0 : (*it)->destroy( bDeletePhysical, xEnv );
1808 : 0 : ++it;
1809 : 0 : }
1810 [ # # ]: 0 : }
1811 : 0 : }
1812 : :
1813 : : //=========================================================================
1814 : 62 : void Content::transfer(
1815 : : const ucb::TransferInfo& rInfo,
1816 : : const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1817 : : throw( uno::Exception )
1818 : : {
1819 [ + - ]: 62 : osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1820 : :
1821 : : // Persistent?
1822 [ - + ]: 62 : if ( m_eState != PERSISTENT )
1823 : : {
1824 : : ucbhelper::cancelCommandExecution(
1825 : : uno::makeAny( ucb::UnsupportedCommandException(
1826 : : rtl::OUString( "Not persistent!" ),
1827 : : static_cast< cppu::OWeakObject * >( this ) ) ),
1828 [ # # ][ # # ]: 0 : xEnv );
[ # # ][ # # ]
[ # # ]
1829 : : // Unreachable
1830 : : }
1831 : :
1832 : : // Is source a package content?
1833 [ + - + - ]: 124 : if ( ( rInfo.SourceURL.isEmpty() ) ||
[ + - ]
1834 : : ( rInfo.SourceURL.compareTo(
1835 [ + - ]: 62 : m_aUri.getUri(), PACKAGE_URL_SCHEME_LENGTH + 3 ) != 0 ) )
1836 : : {
1837 : : ucbhelper::cancelCommandExecution(
1838 : : uno::makeAny( ucb::InteractiveBadTransferURLException(
1839 : : rtl::OUString(),
1840 : : static_cast< cppu::OWeakObject * >( this ) ) ),
1841 [ + - ][ + - ]: 62 : xEnv );
[ + - ][ - + ]
[ # # ]
1842 : : // Unreachable
1843 : : }
1844 : :
1845 : : // Is source not a parent of me / not me?
1846 [ # # ]: 0 : rtl::OUString aId = m_aUri.getParentUri();
1847 : 0 : aId += rtl::OUString("/");
1848 : :
1849 [ # # ]: 0 : if ( rInfo.SourceURL.getLength() <= aId.getLength() )
1850 : : {
1851 [ # # ]: 0 : if ( aId.compareTo(
1852 : 0 : rInfo.SourceURL, rInfo.SourceURL.getLength() ) == 0 )
1853 : : {
1854 : : uno::Any aProps
1855 : : = uno::makeAny(beans::PropertyValue(
1856 : : rtl::OUString( "Uri"),
1857 : : -1,
1858 : : uno::makeAny(rInfo.SourceURL),
1859 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
1860 : : ucbhelper::cancelCommandExecution(
1861 : : ucb::IOErrorCode_RECURSIVE,
1862 : : uno::Sequence< uno::Any >(&aProps, 1),
1863 : : xEnv,
1864 : : rtl::OUString( "Target is equal to or is a child of source!" ),
1865 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
1866 : : // Unreachable
1867 : : }
1868 : : }
1869 : :
1870 : : //////////////////////////////////////////////////////////////////////
1871 : : // 0) Obtain content object for source.
1872 : : //////////////////////////////////////////////////////////////////////
1873 : :
1874 : : uno::Reference< ucb::XContentIdentifier > xId
1875 [ # # ][ # # ]: 0 : = new ::ucbhelper::ContentIdentifier( m_xSMgr, rInfo.SourceURL );
[ # # ]
1876 : :
1877 : : // Note: The static cast is okay here, because its sure that
1878 : : // m_xProvider is always the PackageContentProvider.
1879 : 0 : rtl::Reference< Content > xSource;
1880 : :
1881 : : try
1882 : : {
1883 : : xSource = static_cast< Content * >(
1884 [ # # ][ # # ]: 0 : m_xProvider->queryContent( xId ).get() );
[ # # ][ # # ]
[ # # ]
1885 : : }
1886 [ # # ]: 0 : catch ( ucb::IllegalIdentifierException const & )
1887 : : {
1888 : : // queryContent
1889 : : }
1890 : :
1891 [ # # ]: 0 : if ( !xSource.is() )
1892 : : {
1893 : : uno::Any aProps
1894 : : = uno::makeAny(beans::PropertyValue(
1895 : : rtl::OUString( "Uri"),
1896 : : -1,
1897 [ # # ]: 0 : uno::makeAny(xId->getContentIdentifier()),
1898 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ]
1899 : : ucbhelper::cancelCommandExecution(
1900 : : ucb::IOErrorCode_CANT_READ,
1901 : : uno::Sequence< uno::Any >(&aProps, 1),
1902 : : xEnv,
1903 : : rtl::OUString( "Cannot instanciate source object!" ),
1904 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
1905 : : // Unreachable
1906 : : }
1907 : :
1908 : : //////////////////////////////////////////////////////////////////////
1909 : : // 1) Create new child content.
1910 : : //////////////////////////////////////////////////////////////////////
1911 : :
1912 : 0 : rtl::OUString aType = xSource->isFolder()
1913 [ # # ]: 0 : ? getContentType( m_aUri.getScheme(), sal_True )
1914 [ # # ][ # # ]: 0 : : getContentType( m_aUri.getScheme(), sal_False );
[ # # ][ # # ]
1915 [ # # ]: 0 : ucb::ContentInfo aContentInfo;
1916 : 0 : aContentInfo.Type = aType;
1917 : 0 : aContentInfo.Attributes = 0;
1918 : :
1919 : : // Note: The static cast is okay here, because its sure that
1920 : : // createNewContent always creates a Content.
1921 : : rtl::Reference< Content > xTarget
1922 [ # # ][ # # ]: 0 : = static_cast< Content * >( createNewContent( aContentInfo ).get() );
[ # # ]
1923 [ # # ]: 0 : if ( !xTarget.is() )
1924 : : {
1925 : : uno::Any aProps
1926 : : = uno::makeAny(beans::PropertyValue(
1927 : : rtl::OUString( "Folder"),
1928 : : -1,
1929 : : uno::makeAny(aId),
1930 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
1931 : : ucbhelper::cancelCommandExecution(
1932 : : ucb::IOErrorCode_CANT_CREATE,
1933 : : uno::Sequence< uno::Any >(&aProps, 1),
1934 : : xEnv,
1935 : : rtl::OUString( "XContentCreator::createNewContent failed!" ),
1936 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
1937 : : // Unreachable
1938 : : }
1939 : :
1940 : : //////////////////////////////////////////////////////////////////////
1941 : : // 2) Copy data from source content to child content.
1942 : : //////////////////////////////////////////////////////////////////////
1943 : :
1944 : : uno::Sequence< beans::Property > aSourceProps
1945 [ # # ][ # # ]: 0 : = xSource->getPropertySetInfo( xEnv )->getProperties();
[ # # ]
1946 : 0 : sal_Int32 nCount = aSourceProps.getLength();
1947 : :
1948 [ # # ]: 0 : if ( nCount )
1949 : : {
1950 : 0 : sal_Bool bHadTitle = rInfo.NewTitle.isEmpty();
1951 : :
1952 : : // Get all source values.
1953 : : uno::Reference< sdbc::XRow > xRow
1954 [ # # ]: 0 : = xSource->getPropertyValues( aSourceProps );
1955 : :
1956 [ # # ]: 0 : uno::Sequence< beans::PropertyValue > aValues( nCount );
1957 [ # # ]: 0 : beans::PropertyValue* pValues = aValues.getArray();
1958 : :
1959 : 0 : const beans::Property* pProps = aSourceProps.getConstArray();
1960 [ # # ]: 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
1961 : : {
1962 : 0 : const beans::Property& rProp = pProps[ n ];
1963 : 0 : beans::PropertyValue& rValue = pValues[ n ];
1964 : :
1965 : 0 : rValue.Name = rProp.Name;
1966 : 0 : rValue.Handle = rProp.Handle;
1967 : :
1968 [ # # ][ # # ]: 0 : if ( !bHadTitle && rProp.Name == "Title" )
[ # # ]
1969 : : {
1970 : : // Set new title instead of original.
1971 : 0 : bHadTitle = sal_True;
1972 [ # # ]: 0 : rValue.Value <<= rInfo.NewTitle;
1973 : : }
1974 : : else
1975 : : rValue.Value
1976 [ # # ]: 0 : = xRow->getObject( n + 1,
1977 : : uno::Reference<
1978 [ # # ]: 0 : container::XNameAccess >() );
[ # # # # ]
1979 : :
1980 : 0 : rValue.State = beans::PropertyState_DIRECT_VALUE;
1981 : :
1982 [ # # ]: 0 : if ( rProp.Attributes & beans::PropertyAttribute::REMOVABLE )
1983 : : {
1984 : : // Add Additional Core Property.
1985 : : try
1986 : : {
1987 : 0 : xTarget->addProperty( rProp.Name,
1988 : : rProp.Attributes,
1989 [ # # ]: 0 : rValue.Value );
1990 : : }
1991 [ # # ]: 0 : catch ( beans::PropertyExistException const & )
1992 : : {
1993 : : }
1994 [ # # ]: 0 : catch ( beans::IllegalTypeException const & )
1995 : : {
1996 : : }
1997 [ # # ]: 0 : catch ( lang::IllegalArgumentException const & )
1998 : : {
1999 : : }
2000 : : }
2001 : : }
2002 : :
2003 : : // Set target values.
2004 [ # # ][ # # ]: 0 : xTarget->setPropertyValues( aValues, xEnv );
[ # # ]
2005 : : }
2006 : :
2007 : : //////////////////////////////////////////////////////////////////////
2008 : : // 3) Commit (insert) child.
2009 : : //////////////////////////////////////////////////////////////////////
2010 : :
2011 [ # # ][ # # ]: 0 : xTarget->insert( xSource->getInputStream(), rInfo.NameClash, xEnv );
2012 : :
2013 : : //////////////////////////////////////////////////////////////////////
2014 : : // 4) Transfer (copy) children of source.
2015 : : //////////////////////////////////////////////////////////////////////
2016 : :
2017 [ # # ]: 0 : if ( xSource->isFolder() )
2018 : : {
2019 : : uno::Reference< container::XEnumeration > xIter
2020 [ # # ]: 0 : = xSource->getIterator();
2021 [ # # ]: 0 : if ( xIter.is() )
2022 : : {
2023 [ # # ][ # # ]: 0 : while ( xIter->hasMoreElements() )
[ # # ]
2024 : : {
2025 : : try
2026 : : {
2027 : 0 : uno::Reference< container::XNamed > xNamed;
2028 [ # # ][ # # ]: 0 : xIter->nextElement() >>= xNamed;
[ # # ]
2029 : :
2030 [ # # ]: 0 : if ( !xNamed.is() )
2031 : : {
2032 : : OSL_FAIL( "Content::transfer - Got no XNamed!" );
2033 : : break;
2034 : : }
2035 : :
2036 [ # # ][ # # ]: 0 : rtl::OUString aName = xNamed->getName();
2037 : :
2038 [ # # ]: 0 : if ( aName.isEmpty() )
2039 : : {
2040 : : OSL_FAIL( "Content::transfer - Empty name!" );
2041 : : break;
2042 : : }
2043 : :
2044 [ # # ][ # # ]: 0 : rtl::OUString aChildId = xId->getContentIdentifier();
2045 [ # # ]: 0 : if ( ( aChildId.lastIndexOf( '/' ) + 1 )
2046 : 0 : != aChildId.getLength() )
2047 : 0 : aChildId += rtl::OUString("/");
2048 : :
2049 : 0 : aChildId += ::ucb_impl::urihelper::encodeSegment( aName );
2050 : :
2051 : 0 : ucb::TransferInfo aInfo;
2052 : 0 : aInfo.MoveData = sal_False;
2053 : 0 : aInfo.NewTitle = rtl::OUString();
2054 : 0 : aInfo.SourceURL = aChildId;
2055 : 0 : aInfo.NameClash = rInfo.NameClash;
2056 : :
2057 : : // Transfer child to target.
2058 [ # # ][ # # ]: 0 : xTarget->transfer( aInfo, xEnv );
[ # # # ]
[ # # ]
2059 : : }
2060 [ # # ]: 0 : catch ( container::NoSuchElementException const & )
2061 : : {
2062 : : }
2063 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2064 : : {
2065 : : }
2066 : : }
2067 : 0 : }
2068 : : }
2069 : :
2070 : : //////////////////////////////////////////////////////////////////////
2071 : : // 5) Destroy source ( when moving only ) .
2072 : : //////////////////////////////////////////////////////////////////////
2073 : :
2074 [ # # ]: 0 : if ( rInfo.MoveData )
2075 : : {
2076 [ # # ]: 0 : xSource->destroy( sal_True, xEnv );
2077 : :
2078 : : // Remove all persistent data of source and its children.
2079 [ # # ][ # # ]: 0 : if ( !xSource->removeData() )
2080 : : {
2081 : : uno::Any aProps
2082 : : = uno::makeAny(
2083 : : beans::PropertyValue(
2084 : : rtl::OUString( "Uri"),
2085 : : -1,
2086 : : uno::makeAny(
2087 [ # # ]: 0 : xSource->m_xIdentifier->
2088 : 0 : getContentIdentifier()),
2089 [ # # ][ # # ]: 0 : beans::PropertyState_DIRECT_VALUE));
[ # # ]
2090 : : ucbhelper::cancelCommandExecution(
2091 : : ucb::IOErrorCode_CANT_WRITE,
2092 : : uno::Sequence< uno::Any >(&aProps, 1),
2093 : : xEnv,
2094 : : rtl::OUString( "Cannot remove persistent data of source object!" ),
2095 [ # # ][ # # ]: 0 : this );
[ # # ][ # # ]
2096 : : // Unreachable
2097 : : }
2098 : :
2099 : : // Remove own and all children's Additional Core Properties.
2100 [ # # ]: 0 : xSource->removeAdditionalPropertySet( sal_True );
2101 [ # # ][ # # ]: 62 : }
[ # # ]
2102 : 0 : }
2103 : :
2104 : : //=========================================================================
2105 : 0 : sal_Bool Content::exchangeIdentity(
2106 : : const uno::Reference< ucb::XContentIdentifier >& xNewId )
2107 : : {
2108 [ # # ]: 0 : if ( !xNewId.is() )
2109 : 0 : return sal_False;
2110 : :
2111 [ # # ]: 0 : osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
2112 : :
2113 [ # # ]: 0 : uno::Reference< ucb::XContent > xThis = this;
2114 : :
2115 : : // Already persistent?
2116 [ # # ]: 0 : if ( m_eState != PERSISTENT )
2117 : : {
2118 : : OSL_FAIL( "Content::exchangeIdentity - Not persistent!" );
2119 : 0 : return sal_False;
2120 : : }
2121 : :
2122 : : // Exchange own identitity.
2123 : :
2124 : : // Fail, if a content with given id already exists.
2125 [ # # ][ # # ]: 0 : PackageUri aNewUri( xNewId->getContentIdentifier() );
2126 [ # # ][ # # ]: 0 : if ( !hasData( aNewUri ) )
2127 : : {
2128 [ # # ][ # # ]: 0 : rtl::OUString aOldURL = m_xIdentifier->getContentIdentifier();
2129 : :
2130 [ # # ]: 0 : aGuard.clear();
2131 [ # # ][ # # ]: 0 : if ( exchange( xNewId ) )
2132 : : {
2133 : 0 : m_aUri = aNewUri;
2134 [ # # ]: 0 : if ( isFolder() )
2135 : : {
2136 : : // Process instanciated children...
2137 : :
2138 [ # # ]: 0 : ContentRefList aChildren;
2139 [ # # ]: 0 : queryChildren( aChildren );
2140 : :
2141 : 0 : ContentRefList::const_iterator it = aChildren.begin();
2142 : 0 : ContentRefList::const_iterator end = aChildren.end();
2143 : :
2144 [ # # ]: 0 : while ( it != end )
2145 : : {
2146 : 0 : ContentRef xChild = (*it);
2147 : :
2148 : : // Create new content identifier for the child...
2149 : : uno::Reference< ucb::XContentIdentifier > xOldChildId
2150 [ # # ]: 0 : = xChild->getIdentifier();
2151 : : rtl::OUString aOldChildURL
2152 [ # # ][ # # ]: 0 : = xOldChildId->getContentIdentifier();
2153 : : rtl::OUString aNewChildURL
2154 : : = aOldChildURL.replaceAt(
2155 : : 0,
2156 : : aOldURL.getLength(),
2157 [ # # ][ # # ]: 0 : xNewId->getContentIdentifier() );
2158 : : uno::Reference< ucb::XContentIdentifier > xNewChildId
2159 : : = new ::ucbhelper::ContentIdentifier(
2160 [ # # ][ # # ]: 0 : m_xSMgr, aNewChildURL );
[ # # ]
2161 : :
2162 [ # # ][ # # ]: 0 : if ( !xChild->exchangeIdentity( xNewChildId ) )
2163 : 0 : return sal_False;
2164 : :
2165 [ # # ]: 0 : ++it;
2166 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ]
2167 : : }
2168 : 0 : return sal_True;
2169 [ # # ]: 0 : }
2170 : : }
2171 : :
2172 : : OSL_FAIL( "Content::exchangeIdentity - Panic! Cannot exchange identity!" );
2173 [ # # ]: 0 : return sal_False;
2174 : : }
2175 : :
2176 : : //=========================================================================
2177 : 0 : void Content::queryChildren( ContentRefList& rChildren )
2178 : : {
2179 : : // Obtain a list with a snapshot of all currently instanciated contents
2180 : : // from provider and extract the contents which are direct children
2181 : : // of this content.
2182 : :
2183 [ # # ]: 0 : ::ucbhelper::ContentRefList aAllContents;
2184 [ # # ]: 0 : m_xProvider->queryExistingContents( aAllContents );
2185 : :
2186 [ # # ][ # # ]: 0 : rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
2187 : :
2188 : : OSL_ENSURE( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ),
2189 : : "Content::queryChildren - Invalid URL!" );
2190 : :
2191 : 0 : aURL += rtl::OUString("/");
2192 : :
2193 : 0 : sal_Int32 nLen = aURL.getLength();
2194 : :
2195 : 0 : ::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
2196 : 0 : ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
2197 : :
2198 [ # # ]: 0 : while ( it != end )
2199 : : {
2200 : 0 : ::ucbhelper::ContentImplHelperRef xChild = (*it);
2201 : : rtl::OUString aChildURL
2202 [ # # ][ # # ]: 0 : = xChild->getIdentifier()->getContentIdentifier();
[ # # ]
2203 : :
2204 : : // Is aURL a prefix of aChildURL?
2205 [ # # ]: 0 : if ( ( aChildURL.getLength() > nLen ) &&
[ # # # # ]
2206 : 0 : ( aChildURL.compareTo( aURL, nLen ) == 0 ) )
2207 : : {
2208 [ # # ]: 0 : if ( aChildURL.indexOf( '/', nLen ) == -1 )
2209 : : {
2210 : : // No further slashes. It's a child!
2211 : : rChildren.push_back(
2212 : : ContentRef(
2213 [ # # ]: 0 : static_cast< Content * >( xChild.get() ) ) );
2214 : : }
2215 : : }
2216 : 0 : ++it;
2217 : 0 : }
2218 : 0 : }
2219 : :
2220 : : //=========================================================================
2221 : 301 : uno::Reference< container::XHierarchicalNameAccess > Content::getPackage(
2222 : : const PackageUri& rURI )
2223 : : {
2224 [ + - ]: 301 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2225 : :
2226 : 301 : uno::Reference< container::XHierarchicalNameAccess > xPackage;
2227 [ + - ][ + - ]: 301 : if ( rURI.getPackage() == m_aUri.getPackage() )
[ + - ]
2228 : : {
2229 [ - + ]: 301 : if ( !m_xPackage.is() )
2230 [ # # ][ # # ]: 0 : m_xPackage = m_pProvider->createPackage( m_aUri.getPackage(), m_aUri.getParam() );
[ # # ][ # # ]
2231 : :
2232 : 301 : return m_xPackage;
2233 : : }
2234 : :
2235 [ # # ][ # # ]: 301 : return m_pProvider->createPackage( rURI.getPackage(), rURI.getParam() );
[ # # ][ + - ]
2236 : : }
2237 : :
2238 : : //=========================================================================
2239 : 301 : uno::Reference< container::XHierarchicalNameAccess > Content::getPackage()
2240 : : {
2241 : 301 : return getPackage( m_aUri );
2242 : : }
2243 : :
2244 : : //=========================================================================
2245 : : // static
2246 : 0 : sal_Bool Content::hasData(
2247 : : ContentProvider* pProvider,
2248 : : const PackageUri& rURI,
2249 : : uno::Reference< container::XHierarchicalNameAccess > & rxPackage )
2250 : : {
2251 [ # # ]: 0 : rxPackage = pProvider->createPackage( rURI.getPackage(), rURI.getParam() );
2252 [ # # ]: 0 : if ( !rxPackage.is() )
2253 : 0 : return sal_False;
2254 : :
2255 : 0 : return rxPackage->hasByHierarchicalName( rURI.getPath() );
2256 : : }
2257 : :
2258 : : //=========================================================================
2259 : 0 : sal_Bool Content::hasData( const PackageUri& rURI )
2260 : : {
2261 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2262 : :
2263 : 0 : uno::Reference< container::XHierarchicalNameAccess > xPackage;
2264 [ # # ][ # # ]: 0 : if ( rURI.getPackage() == m_aUri.getPackage() )
[ # # ]
2265 : : {
2266 [ # # ][ # # ]: 0 : xPackage = getPackage();
2267 [ # # ]: 0 : if ( !xPackage.is() )
2268 : 0 : return sal_False;
2269 : :
2270 [ # # ][ # # ]: 0 : return xPackage->hasByHierarchicalName( rURI.getPath() );
[ # # ]
2271 : : }
2272 : :
2273 [ # # ][ # # ]: 0 : return hasData( m_pProvider, rURI, xPackage );
2274 : : }
2275 : :
2276 : : //=========================================================================
2277 : : //static
2278 : 253 : sal_Bool Content::loadData(
2279 : : ContentProvider* pProvider,
2280 : : const PackageUri& rURI,
2281 : : ContentProperties& rProps,
2282 : : uno::Reference< container::XHierarchicalNameAccess > & rxPackage )
2283 : : {
2284 [ + - ]: 253 : rxPackage = pProvider->createPackage( rURI.getPackage(), rURI.getParam() );
2285 [ - + ]: 253 : if ( !rxPackage.is() )
2286 : 0 : return sal_False;
2287 : :
2288 [ + + ]: 253 : if ( rURI.isRootFolder() )
2289 : : {
2290 : : // Properties available only from package
2291 : : uno::Reference< beans::XPropertySet > xPackagePropSet(
2292 [ + - ]: 103 : rxPackage, uno::UNO_QUERY );
2293 : :
2294 : : OSL_ENSURE( xPackagePropSet.is(),
2295 : : "Content::loadData - "
2296 : : "Got no XPropertySet interface from package!" );
2297 : :
2298 [ + - ]: 103 : if ( xPackagePropSet.is() )
2299 : : {
2300 : : // HasEncryptedEntries ( only avalibale at root folder )
2301 : : try
2302 : : {
2303 : : uno::Any aHasEncryptedEntries
2304 [ + - ]: 103 : = xPackagePropSet->getPropertyValue(
2305 [ + - ]: 103 : rtl::OUString( "HasEncryptedEntries" ) );
[ # # # ]
2306 [ - + ]: 103 : if ( !( aHasEncryptedEntries >>= rProps.bHasEncryptedEntries ) )
2307 : : {
2308 : : OSL_FAIL( "Content::loadData - "
2309 : : "Got no HasEncryptedEntries value!" );
2310 : 103 : return sal_False;
2311 [ + - ]: 103 : }
2312 : : }
2313 [ # # ]: 0 : catch ( beans::UnknownPropertyException const & )
2314 : : {
2315 : : OSL_FAIL( "Content::loadData - "
2316 : : "Got no HasEncryptedEntries value!" );
2317 : 0 : return sal_False;
2318 : : }
2319 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2320 : : {
2321 : : OSL_FAIL( "Content::loadData - "
2322 : : "Got no HasEncryptedEntries value!" );
2323 : 0 : return sal_False;
2324 : : }
2325 [ + - ]: 103 : }
2326 : : }
2327 : :
2328 [ - + ]: 253 : if ( !rxPackage->hasByHierarchicalName( rURI.getPath() ) )
2329 : 0 : return sal_False;
2330 : :
2331 : : try
2332 : : {
2333 [ + - ][ + - ]: 253 : uno::Any aEntry = rxPackage->getByHierarchicalName( rURI.getPath() );
[ + - ]
2334 [ + - ]: 253 : if ( aEntry.hasValue() )
2335 : : {
2336 : 253 : uno::Reference< beans::XPropertySet > xPropSet;
2337 [ + - ]: 253 : aEntry >>= xPropSet;
2338 : :
2339 [ - + ]: 253 : if ( !xPropSet.is() )
2340 : : {
2341 : : OSL_FAIL( "Content::loadData - Got no XPropertySet interface!" );
2342 : 0 : return sal_False;
2343 : : }
2344 : :
2345 : : // Title
2346 [ + - ]: 253 : rProps.aTitle = rURI.getName();
2347 : :
2348 : : // MediaType
2349 : : try
2350 : : {
2351 : : uno::Any aMediaType
2352 [ + - ]: 253 : = xPropSet->getPropertyValue(
2353 [ + - ]: 253 : rtl::OUString("MediaType") );
[ # # # ]
2354 [ - + ]: 253 : if ( !( aMediaType >>= rProps.aMediaType ) )
2355 : : {
2356 : : OSL_FAIL( "Content::loadData - Got no MediaType value!" );
2357 : 253 : return sal_False;
2358 [ + - ]: 253 : }
2359 : : }
2360 [ # # ]: 0 : catch ( beans::UnknownPropertyException const & )
2361 : : {
2362 : : OSL_FAIL( "Content::loadData - Got no MediaType value!" );
2363 : 0 : return sal_False;
2364 : : }
2365 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2366 : : {
2367 : : OSL_FAIL( "Content::loadData - Got no MediaType value!" );
2368 : 0 : return sal_False;
2369 : : }
2370 : :
2371 : 253 : uno::Reference< container::XEnumerationAccess > xEnumAccess;
2372 [ + - ]: 253 : aEntry >>= xEnumAccess;
2373 : :
2374 : : // ContentType / IsFolder / IsDocument
2375 [ + + ]: 253 : if ( xEnumAccess.is() )
2376 : : {
2377 : : // folder
2378 [ + - ][ + - ]: 173 : rProps.aContentType = getContentType( rURI.getScheme(), sal_True );
2379 : 173 : rProps.bIsDocument = sal_False;
2380 : 173 : rProps.bIsFolder = sal_True;
2381 : : }
2382 : : else
2383 : : {
2384 : : // stream
2385 [ + - ][ + - ]: 80 : rProps.aContentType = getContentType( rURI.getScheme(), sal_False );
2386 : 80 : rProps.bIsDocument = sal_True;
2387 : 80 : rProps.bIsFolder = sal_False;
2388 : : }
2389 : :
2390 [ + + ]: 253 : if ( rProps.bIsDocument )
2391 : : {
2392 : : // Size ( only available for streams )
2393 : : try
2394 : : {
2395 : : uno::Any aSize
2396 [ + - ]: 80 : = xPropSet->getPropertyValue(
2397 [ + - ]: 80 : rtl::OUString("Size") );
[ # # # ]
2398 [ - + ]: 80 : if ( !( aSize >>= rProps.nSize ) )
2399 : : {
2400 : : OSL_FAIL( "Content::loadData - Got no Size value!" );
2401 : 80 : return sal_False;
2402 [ + - ]: 80 : }
2403 : : }
2404 [ # # ]: 0 : catch ( beans::UnknownPropertyException const & )
2405 : : {
2406 : : OSL_FAIL( "Content::loadData - Got no Size value!" );
2407 : 0 : return sal_False;
2408 : : }
2409 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2410 : : {
2411 : : OSL_FAIL( "Content::loadData - Got no Size value!" );
2412 : 0 : return sal_False;
2413 : : }
2414 : :
2415 : : // Compressed ( only available for streams )
2416 : : try
2417 : : {
2418 : : uno::Any aCompressed
2419 [ + - ]: 80 : = xPropSet->getPropertyValue(
2420 [ + - ]: 80 : rtl::OUString("Compressed") );
[ # # # ]
2421 [ - + ]: 80 : if ( !( aCompressed >>= rProps.bCompressed ) )
2422 : : {
2423 : : OSL_FAIL( "Content::loadData - Got no Compressed value!" );
2424 : 80 : return sal_False;
2425 [ + - ]: 80 : }
2426 : : }
2427 [ # # ]: 0 : catch ( beans::UnknownPropertyException const & )
2428 : : {
2429 : : OSL_FAIL( "Content::loadData - Got no Compressed value!" );
2430 : 0 : return sal_False;
2431 : : }
2432 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2433 : : {
2434 : : OSL_FAIL( "Content::loadData - Got no Compressed value!" );
2435 : 0 : return sal_False;
2436 : : }
2437 : :
2438 : : // Encrypted ( only available for streams )
2439 : : try
2440 : : {
2441 : : uno::Any aEncrypted
2442 [ + - ]: 80 : = xPropSet->getPropertyValue(
2443 [ + - ]: 80 : rtl::OUString("Encrypted") );
[ # # # ]
2444 [ - + ]: 80 : if ( !( aEncrypted >>= rProps.bEncrypted ) )
2445 : : {
2446 : : OSL_FAIL( "Content::loadData - Got no Encrypted value!" );
2447 : 80 : return sal_False;
2448 [ + - ]: 80 : }
2449 : : }
2450 [ # # ]: 0 : catch ( beans::UnknownPropertyException const & )
2451 : : {
2452 : : OSL_FAIL( "Content::loadData - Got no Encrypted value!" );
2453 : 0 : return sal_False;
2454 : : }
2455 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2456 : : {
2457 : : OSL_FAIL( "Content::loadData - Got no Encrypted value!" );
2458 : 0 : return sal_False;
2459 : : }
2460 : : }
2461 : 253 : return sal_True;
2462 [ - + ][ # # ]: 253 : }
2463 : : }
2464 : 0 : catch ( container::NoSuchElementException const & )
2465 : : {
2466 : : // getByHierarchicalName
2467 : : }
2468 : :
2469 : 253 : return sal_False;
2470 : : }
2471 : :
2472 : : //=========================================================================
2473 : 0 : sal_Bool Content::renameData(
2474 : : const uno::Reference< ucb::XContentIdentifier >& xOldId,
2475 : : const uno::Reference< ucb::XContentIdentifier >& xNewId )
2476 : : {
2477 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2478 : :
2479 [ # # ][ # # ]: 0 : PackageUri aURI( xOldId->getContentIdentifier() );
2480 : : uno::Reference< container::XHierarchicalNameAccess > xNA = getPackage(
2481 [ # # ]: 0 : aURI );
2482 [ # # ]: 0 : if ( !xNA.is() )
2483 : 0 : return sal_False;
2484 : :
2485 [ # # ][ # # ]: 0 : if ( !xNA->hasByHierarchicalName( aURI.getPath() ) )
[ # # ][ # # ]
2486 : 0 : return sal_False;
2487 : :
2488 : : try
2489 : : {
2490 [ # # ][ # # ]: 0 : uno::Any aEntry = xNA->getByHierarchicalName( aURI.getPath() );
[ # # ]
2491 : 0 : uno::Reference< container::XNamed > xNamed;
2492 [ # # ]: 0 : aEntry >>= xNamed;
2493 : :
2494 [ # # ]: 0 : if ( !xNamed.is() )
2495 : : {
2496 : : OSL_FAIL( "Content::renameData - Got no XNamed interface!" );
2497 : 0 : return sal_False;
2498 : : }
2499 : :
2500 [ # # ][ # # ]: 0 : PackageUri aNewURI( xNewId->getContentIdentifier() );
2501 : :
2502 : : // No success indicator!? No return value / exceptions specified.
2503 [ # # ][ # # ]: 0 : xNamed->setName( aNewURI.getName() );
[ # # ]
2504 : :
2505 [ # # ]: 0 : return sal_True;
2506 : : }
2507 [ # # ]: 0 : catch ( container::NoSuchElementException const & )
2508 : : {
2509 : : // getByHierarchicalName
2510 : : }
2511 : :
2512 [ # # ]: 0 : return sal_False;
2513 : : }
2514 : :
2515 : : //=========================================================================
2516 : 124 : sal_Bool Content::storeData( const uno::Reference< io::XInputStream >& xStream )
2517 : : {
2518 [ + - ]: 124 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2519 : :
2520 [ + - ]: 124 : uno::Reference< container::XHierarchicalNameAccess > xNA = getPackage();
2521 [ - + ]: 124 : if ( !xNA.is() )
2522 : 0 : return sal_False;
2523 : :
2524 : : uno::Reference< beans::XPropertySet > xPackagePropSet(
2525 [ + - ]: 124 : xNA, uno::UNO_QUERY );
2526 : : OSL_ENSURE( xPackagePropSet.is(),
2527 : : "Content::storeData - "
2528 : : "Got no XPropertySet interface from package!" );
2529 : :
2530 [ - + ]: 124 : if ( !xPackagePropSet.is() )
2531 : 0 : return sal_False;
2532 : :
2533 [ - + ]: 124 : if ( m_nModifiedProps & ENCRYPTIONKEY_MODIFIED )
2534 : : {
2535 [ # # ][ # # ]: 0 : if ( m_aUri.isRootFolder() )
2536 : : {
2537 : : // Property available only from package and from streams (see below)
2538 : : try
2539 : : {
2540 [ # # ]: 0 : xPackagePropSet->setPropertyValue(
2541 : : rtl::OUString("EncryptionKey"),
2542 [ # # ][ # # ]: 0 : uno::makeAny( m_aProps.aEncryptionKey ) );
[ # # # #
# ]
2543 : 0 : m_nModifiedProps &= ~ENCRYPTIONKEY_MODIFIED;
2544 : : }
2545 [ # # ]: 0 : catch ( beans::UnknownPropertyException const & )
2546 : : {
2547 : : // setPropertyValue
2548 : : }
2549 [ # # ]: 0 : catch ( beans::PropertyVetoException const & )
2550 : : {
2551 : : // setPropertyValue
2552 : : }
2553 [ # # ]: 0 : catch ( lang::IllegalArgumentException const & )
2554 : : {
2555 : : // setPropertyValue
2556 : : }
2557 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2558 : : {
2559 : : // setPropertyValue
2560 : : }
2561 : : }
2562 : : }
2563 : :
2564 [ + - ][ + - ]: 124 : if ( !xNA->hasByHierarchicalName( m_aUri.getPath() ) )
[ + - ][ + - ]
2565 : : {
2566 : : // if ( !bCreate )
2567 : : // return sal_True;
2568 : :
2569 : : try
2570 : : {
2571 : : // Create new resource...
2572 : : uno::Reference< lang::XSingleServiceFactory > xFac(
2573 [ + - ]: 124 : xNA, uno::UNO_QUERY );
2574 [ - + ]: 124 : if ( !xFac.is() )
2575 : : {
2576 : : OSL_FAIL( "Content::storeData - "
2577 : : "Got no XSingleServiceFactory interface!" );
2578 : 0 : return sal_False;
2579 : : }
2580 : :
2581 [ + - ]: 124 : uno::Sequence< uno::Any > aArgs( 1 );
2582 [ + - ][ + - ]: 124 : aArgs[ 0 ] <<= isFolder();
2583 : :
2584 : : uno::Reference< uno::XInterface > xNew
2585 [ + - ][ + - ]: 124 : = xFac->createInstanceWithArguments( aArgs );
2586 : :
2587 [ - + ]: 124 : if ( !xNew.is() )
2588 : : {
2589 : : OSL_FAIL( "Content::storeData - createInstance failed!" );
2590 : 0 : return sal_False;
2591 : : }
2592 : :
2593 [ + - ]: 124 : PackageUri aParentUri( getParentURL() );
2594 : : uno::Any aEntry
2595 [ + - ][ + - ]: 124 : = xNA->getByHierarchicalName( aParentUri.getPath() );
[ + - ]
2596 : 124 : uno::Reference< container::XNameContainer > xParentContainer;
2597 [ + - ]: 124 : aEntry >>= xParentContainer;
2598 : :
2599 [ - + ]: 124 : if ( !xParentContainer.is() )
2600 : : {
2601 : : OSL_FAIL( "Content::storeData - "
2602 : : "Got no XNameContainer interface!" );
2603 : 0 : return sal_False;
2604 : : }
2605 : :
2606 [ + - ]: 124 : xParentContainer->insertByName( m_aProps.aTitle,
2607 [ + - ][ + - ]: 124 : uno::makeAny( xNew ) );
[ - + ][ - + ]
[ - + ][ - + ]
[ + - ][ - + ]
[ + - ]
2608 : : }
2609 [ # # # # : 0 : catch ( uno::RuntimeException const & )
# # # ]
2610 : : {
2611 : 0 : throw;
2612 : : }
2613 [ # # ]: 0 : catch ( lang::IllegalArgumentException const & )
2614 : : {
2615 : : // insertByName
2616 : : OSL_FAIL( "Content::storeData - insertByName failed!" );
2617 : 0 : return sal_False;
2618 : : }
2619 [ # # ]: 0 : catch ( container::ElementExistException const & )
2620 : : {
2621 : : // insertByName
2622 : : OSL_FAIL( "Content::storeData - insertByName failed!" );
2623 : 0 : return sal_False;
2624 : : }
2625 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2626 : : {
2627 : : // insertByName
2628 : : OSL_FAIL( "Content::storeData - insertByName failed!" );
2629 : 0 : return sal_False;
2630 : : }
2631 [ # # ]: 0 : catch ( container::NoSuchElementException const & )
2632 : : {
2633 : : // getByHierarchicalName
2634 : : OSL_FAIL( "Content::storeData - getByHierarchicalName failed!" );
2635 : 0 : return sal_False;
2636 : : }
2637 [ # # ]: 0 : catch ( uno::Exception const & )
2638 : : {
2639 : : // createInstanceWithArguments
2640 : : OSL_FAIL( "Content::storeData - Error!" );
2641 : 0 : return sal_False;
2642 : : }
2643 : : }
2644 : :
2645 [ + - ][ + - ]: 124 : if ( !xNA->hasByHierarchicalName( m_aUri.getPath() ) )
[ + - ][ - + ]
2646 : 0 : return sal_False;
2647 : :
2648 : : try
2649 : : {
2650 : 124 : uno::Reference< beans::XPropertySet > xPropSet;
2651 [ + - ][ + - ]: 124 : xNA->getByHierarchicalName( m_aUri.getPath() ) >>= xPropSet;
[ + - ][ + - ]
2652 : :
2653 [ - + ]: 124 : if ( !xPropSet.is() )
2654 : : {
2655 : : OSL_FAIL( "Content::storeData - Got no XPropertySet interface!" );
2656 : 0 : return sal_False;
2657 : : }
2658 : :
2659 : : //////////////////////////////////////////////////////////////////
2660 : : // Store property values...
2661 : : //////////////////////////////////////////////////////////////////
2662 : :
2663 [ - + ]: 124 : if ( m_nModifiedProps & MEDIATYPE_MODIFIED )
2664 : : {
2665 [ # # ]: 0 : xPropSet->setPropertyValue(
2666 : : rtl::OUString("MediaType"),
2667 [ # # ][ # # ]: 0 : uno::makeAny( m_aProps.aMediaType ) );
2668 : 0 : m_nModifiedProps &= ~MEDIATYPE_MODIFIED;
2669 : : }
2670 : :
2671 [ - + ]: 124 : if ( m_nModifiedProps & COMPRESSED_MODIFIED )
2672 : : {
2673 [ # # ]: 0 : if ( !isFolder() )
2674 [ # # ]: 0 : xPropSet->setPropertyValue(
2675 : : rtl::OUString("Compressed"),
2676 [ # # ][ # # ]: 0 : uno::makeAny( m_aProps.bCompressed ) );
2677 : :
2678 : 0 : m_nModifiedProps &= ~COMPRESSED_MODIFIED;
2679 : : }
2680 : :
2681 [ - + ]: 124 : if ( m_nModifiedProps & ENCRYPTED_MODIFIED )
2682 : : {
2683 [ # # ]: 0 : if ( !isFolder() )
2684 [ # # ]: 0 : xPropSet->setPropertyValue(
2685 : : rtl::OUString("Encrypted"),
2686 [ # # ][ # # ]: 0 : uno::makeAny( m_aProps.bEncrypted ) );
2687 : :
2688 : 0 : m_nModifiedProps &= ~ENCRYPTED_MODIFIED;
2689 : : }
2690 : :
2691 [ - + ]: 124 : if ( m_nModifiedProps & ENCRYPTIONKEY_MODIFIED )
2692 : : {
2693 [ # # ]: 0 : if ( !isFolder() )
2694 [ # # ]: 0 : xPropSet->setPropertyValue(
2695 : : rtl::OUString("EncryptionKey"),
2696 [ # # ][ # # ]: 0 : uno::makeAny( m_aProps.aEncryptionKey ) );
2697 : :
2698 : 0 : m_nModifiedProps &= ~ENCRYPTIONKEY_MODIFIED;
2699 : : }
2700 : :
2701 : : //////////////////////////////////////////////////////////////////
2702 : : // Store data stream...
2703 : : //////////////////////////////////////////////////////////////////
2704 : :
2705 [ + + ][ + - ]: 124 : if ( xStream.is() && !isFolder() )
[ + + ]
2706 : : {
2707 : : uno::Reference< io::XActiveDataSink > xSink(
2708 [ + - ]: 62 : xPropSet, uno::UNO_QUERY );
2709 : :
2710 [ - + ]: 62 : if ( !xSink.is() )
2711 : : {
2712 : : OSL_FAIL( "Content::storeData - "
2713 : : "Got no XActiveDataSink interface!" );
2714 : 0 : return sal_False;
2715 : : }
2716 : :
2717 [ + - ][ + - ]: 62 : xSink->setInputStream( xStream );
[ + - ]
2718 : : }
2719 : :
2720 [ # # # # : 124 : return sal_True;
# # ]
2721 : : }
2722 [ # # ]: 0 : catch ( container::NoSuchElementException const & )
2723 : : {
2724 : : // getByHierarchicalName
2725 : : }
2726 [ # # ]: 0 : catch ( beans::UnknownPropertyException const & )
2727 : : {
2728 : : // setPropertyValue
2729 : : }
2730 [ # # ]: 0 : catch ( beans::PropertyVetoException const & )
2731 : : {
2732 : : // setPropertyValue
2733 : : }
2734 [ # # ]: 0 : catch ( lang::IllegalArgumentException const & )
2735 : : {
2736 : : // setPropertyValue
2737 : : }
2738 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2739 : : {
2740 : : // setPropertyValue
2741 : : }
2742 : :
2743 : : OSL_FAIL( "Content::storeData - Error!" );
2744 [ + - ]: 124 : return sal_False;
2745 : : }
2746 : :
2747 : : //=========================================================================
2748 : 0 : sal_Bool Content::removeData()
2749 : : {
2750 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2751 : :
2752 [ # # ]: 0 : uno::Reference< container::XHierarchicalNameAccess > xNA = getPackage();
2753 [ # # ]: 0 : if ( !xNA.is() )
2754 : 0 : return sal_False;
2755 : :
2756 [ # # ]: 0 : PackageUri aParentUri( getParentURL() );
2757 [ # # ][ # # ]: 0 : if ( !xNA->hasByHierarchicalName( aParentUri.getPath() ) )
[ # # ][ # # ]
2758 : 0 : return sal_False;
2759 : :
2760 : : try
2761 : : {
2762 [ # # ][ # # ]: 0 : uno::Any aEntry = xNA->getByHierarchicalName( aParentUri.getPath() );
[ # # ]
2763 : 0 : uno::Reference< container::XNameContainer > xContainer;
2764 [ # # ]: 0 : aEntry >>= xContainer;
2765 : :
2766 [ # # ]: 0 : if ( !xContainer.is() )
2767 : : {
2768 : : OSL_FAIL( "Content::removeData - "
2769 : : "Got no XNameContainer interface!" );
2770 : 0 : return sal_False;
2771 : : }
2772 : :
2773 [ # # ][ # # ]: 0 : xContainer->removeByName( m_aUri.getName() );
[ # # ]
2774 [ # # # ]: 0 : return sal_True;
2775 : : }
2776 [ # # ]: 0 : catch ( container::NoSuchElementException const & )
2777 : : {
2778 : : // getByHierarchicalName, removeByName
2779 : : }
2780 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2781 : : {
2782 : : // removeByName
2783 : : }
2784 : :
2785 : : OSL_FAIL( "Content::removeData - Error!" );
2786 [ # # ]: 0 : return sal_False;
2787 : : }
2788 : :
2789 : : //=========================================================================
2790 : 124 : sal_Bool Content::flushData()
2791 : : {
2792 [ + - ]: 124 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2793 : :
2794 : : // Note: XChangesBatch is only implemented by the package itself, not
2795 : : // by the single entries. Maybe this has to change...
2796 : :
2797 [ + - ]: 124 : uno::Reference< container::XHierarchicalNameAccess > xNA = getPackage();
2798 [ - + ]: 124 : if ( !xNA.is() )
2799 : 0 : return sal_False;
2800 : :
2801 [ + - ]: 124 : uno::Reference< util::XChangesBatch > xBatch( xNA, uno::UNO_QUERY );
2802 [ - + ]: 124 : if ( !xBatch.is() )
2803 : : {
2804 : : OSL_FAIL( "Content::flushData - Got no XChangesBatch interface!" );
2805 : 0 : return sal_False;
2806 : : }
2807 : :
2808 : : try
2809 : : {
2810 [ + - ][ + - ]: 124 : xBatch->commitChanges();
2811 : 124 : return sal_True;
2812 : : }
2813 [ # # ]: 0 : catch ( lang::WrappedTargetException const & )
2814 : : {
2815 : : }
2816 : :
2817 : : OSL_FAIL( "Content::flushData - Error!" );
2818 [ + - ][ # # ]: 124 : return sal_False;
2819 : : }
2820 : :
2821 : : //=========================================================================
2822 : 10 : uno::Reference< io::XInputStream > Content::getInputStream()
2823 : : {
2824 [ + - ]: 10 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2825 : :
2826 : 10 : uno::Reference< io::XInputStream > xStream;
2827 [ + - ]: 10 : uno::Reference< container::XHierarchicalNameAccess > xNA = getPackage();
2828 [ + - ]: 10 : if ( !xNA.is() )
2829 : : return xStream;
2830 : :
2831 [ + - ][ + - ]: 10 : if ( !xNA->hasByHierarchicalName( m_aUri.getPath() ) )
[ + - ][ + - ]
2832 : : return xStream;
2833 : :
2834 : : try
2835 : : {
2836 [ + - ][ + - ]: 10 : uno::Any aEntry = xNA->getByHierarchicalName( m_aUri.getPath() );
[ + - ]
2837 : 10 : uno::Reference< io::XActiveDataSink > xSink;
2838 [ + - ]: 10 : aEntry >>= xSink;
2839 : :
2840 [ - + ]: 10 : if ( !xSink.is() )
2841 : : {
2842 : : OSL_FAIL( "Content::getInputStream - "
2843 : : "Got no XActiveDataSink interface!" );
2844 : : return xStream;
2845 : : }
2846 : :
2847 [ + - ][ + - ]: 20 : xStream = xSink->getInputStream();
[ + - ][ - + ]
2848 : :
2849 : : OSL_ENSURE( xStream.is(),
2850 [ + - ][ # # ]: 20 : "Content::getInputStream - Got no stream!" );
2851 : : }
2852 [ # # ]: 0 : catch ( container::NoSuchElementException const & )
2853 : : {
2854 : : // getByHierarchicalName
2855 : : }
2856 : :
2857 [ + - ]: 10 : return xStream;
2858 : : }
2859 : :
2860 : : //=========================================================================
2861 : 43 : uno::Reference< container::XEnumeration > Content::getIterator()
2862 : : {
2863 [ + - ]: 43 : osl::Guard< osl::Mutex > aGuard( m_aMutex );
2864 : :
2865 : 43 : uno::Reference< container::XEnumeration > xIter;
2866 [ + - ]: 43 : uno::Reference< container::XHierarchicalNameAccess > xNA = getPackage();
2867 [ + - ]: 43 : if ( !xNA.is() )
2868 : : return xIter;
2869 : :
2870 [ + - ][ + - ]: 43 : if ( !xNA->hasByHierarchicalName( m_aUri.getPath() ) )
[ + - ][ + - ]
2871 : : return xIter;
2872 : :
2873 : : try
2874 : : {
2875 [ + - ][ + - ]: 43 : uno::Any aEntry = xNA->getByHierarchicalName( m_aUri.getPath() );
[ + - ]
2876 : 43 : uno::Reference< container::XEnumerationAccess > xIterFac;
2877 [ + - ]: 43 : aEntry >>= xIterFac;
2878 : :
2879 [ - + ]: 43 : if ( !xIterFac.is() )
2880 : : {
2881 : : OSL_FAIL( "Content::getIterator - "
2882 : : "Got no XEnumerationAccess interface!" );
2883 : : return xIter;
2884 : : }
2885 : :
2886 [ + - ][ + - ]: 86 : xIter = xIterFac->createEnumeration();
[ + - ][ - + ]
2887 : :
2888 : : OSL_ENSURE( xIter.is(),
2889 [ + - ][ # # ]: 86 : "Content::getIterator - Got no iterator!" );
2890 : : }
2891 [ # # ]: 0 : catch ( container::NoSuchElementException const & )
2892 : : {
2893 : : // getByHierarchicalName
2894 : : }
2895 : :
2896 [ + - ]: 43 : return xIter;
2897 : : }
2898 : :
2899 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|