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