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