xref: /AOO41X/main/ucb/source/ucp/hierarchy/hierarchycontent.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_ucb.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir /**************************************************************************
32*cdf0e10cSrcweir                                 TODO
33*cdf0e10cSrcweir  **************************************************************************
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir  - optimize transfer command. "Move" should be implementable much more
36*cdf0e10cSrcweir    efficient!
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir  **************************************************************************
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir  - Root Folder vs. 'normal' Folder
41*cdf0e10cSrcweir     - root doesn't support command 'delete'
42*cdf0e10cSrcweir     - root doesn't support command 'insert'
43*cdf0e10cSrcweir     - root needs not created via XContentCreator - queryContent with root
44*cdf0e10cSrcweir       folder id ( HIERARCHY_ROOT_FOLDER_URL ) always returns a value != 0
45*cdf0e10cSrcweir     - root has no parent.
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir  *************************************************************************/
48*cdf0e10cSrcweir #include <osl/diagnose.h>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include "osl/doublecheckedlocking.h"
51*cdf0e10cSrcweir #include <rtl/ustring.h>
52*cdf0e10cSrcweir #include <rtl/ustring.hxx>
53*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyAccess.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalAccessException.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/ucb/MissingPropertiesException.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
67*cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
68*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
69*cdf0e10cSrcweir #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
70*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
71*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
72*cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
73*cdf0e10cSrcweir #include <ucbhelper/propertyvalueset.hxx>
74*cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx>
75*cdf0e10cSrcweir #include "hierarchycontent.hxx"
76*cdf0e10cSrcweir #include "hierarchyprovider.hxx"
77*cdf0e10cSrcweir #include "dynamicresultset.hxx"
78*cdf0e10cSrcweir #include "hierarchyuri.hxx"
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir #include "../inc/urihelper.hxx"
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir using namespace com::sun::star;
83*cdf0e10cSrcweir using namespace hierarchy_ucp;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir //=========================================================================
86*cdf0e10cSrcweir //=========================================================================
87*cdf0e10cSrcweir //
88*cdf0e10cSrcweir // HierarchyContent Implementation.
89*cdf0e10cSrcweir //
90*cdf0e10cSrcweir //=========================================================================
91*cdf0e10cSrcweir //=========================================================================
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir // static ( "virtual" ctor )
94*cdf0e10cSrcweir HierarchyContent* HierarchyContent::create(
95*cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
96*cdf0e10cSrcweir             HierarchyContentProvider* pProvider,
97*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& Identifier )
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir     // Fail, if content does not exist.
100*cdf0e10cSrcweir     HierarchyContentProperties aProps;
101*cdf0e10cSrcweir     if ( !loadData( rxSMgr, pProvider, Identifier, aProps ) )
102*cdf0e10cSrcweir         return 0;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     return new HierarchyContent( rxSMgr, pProvider, Identifier, aProps );
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir //=========================================================================
108*cdf0e10cSrcweir // static ( "virtual" ctor )
109*cdf0e10cSrcweir HierarchyContent* HierarchyContent::create(
110*cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
111*cdf0e10cSrcweir             HierarchyContentProvider* pProvider,
112*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& Identifier,
113*cdf0e10cSrcweir             const ucb::ContentInfo& Info )
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     if ( !Info.Type.getLength() )
116*cdf0e10cSrcweir         return 0;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     if ( !Info.Type.equalsAsciiL(
119*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM( HIERARCHY_FOLDER_CONTENT_TYPE ) ) &&
120*cdf0e10cSrcweir          !Info.Type.equalsAsciiL(
121*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM( HIERARCHY_LINK_CONTENT_TYPE ) ) )
122*cdf0e10cSrcweir         return 0;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir #if 0
125*cdf0e10cSrcweir     // Fail, if content does exist.
126*cdf0e10cSrcweir     if ( hasData( rxSMgr, pProvider, Identifier ) )
127*cdf0e10cSrcweir         return 0;
128*cdf0e10cSrcweir #endif
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     return new HierarchyContent( rxSMgr, pProvider, Identifier, Info );
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir //=========================================================================
134*cdf0e10cSrcweir HierarchyContent::HierarchyContent(
135*cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
136*cdf0e10cSrcweir             HierarchyContentProvider* pProvider,
137*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& Identifier,
138*cdf0e10cSrcweir             const HierarchyContentProperties& rProps )
139*cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ),
140*cdf0e10cSrcweir   m_aProps( rProps ),
141*cdf0e10cSrcweir   m_eState( PERSISTENT ),
142*cdf0e10cSrcweir   m_pProvider( pProvider ),
143*cdf0e10cSrcweir   m_bCheckedReadOnly( false ),
144*cdf0e10cSrcweir   m_bIsReadOnly( true )
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     setKind( Identifier );
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir //=========================================================================
150*cdf0e10cSrcweir HierarchyContent::HierarchyContent(
151*cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
152*cdf0e10cSrcweir             HierarchyContentProvider* pProvider,
153*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& Identifier,
154*cdf0e10cSrcweir             const ucb::ContentInfo& Info )
155*cdf0e10cSrcweir   : ContentImplHelper( rxSMgr, pProvider, Identifier ),
156*cdf0e10cSrcweir   m_aProps( Info.Type.equalsAsciiL(
157*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( HIERARCHY_FOLDER_CONTENT_TYPE ) )
158*cdf0e10cSrcweir             ? HierarchyEntryData::FOLDER
159*cdf0e10cSrcweir             : HierarchyEntryData::LINK ),
160*cdf0e10cSrcweir   m_eState( TRANSIENT ),
161*cdf0e10cSrcweir   m_pProvider( pProvider ),
162*cdf0e10cSrcweir   m_bCheckedReadOnly( false ),
163*cdf0e10cSrcweir   m_bIsReadOnly( true )
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir     setKind( Identifier );
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir //=========================================================================
169*cdf0e10cSrcweir // virtual
170*cdf0e10cSrcweir HierarchyContent::~HierarchyContent()
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir //=========================================================================
175*cdf0e10cSrcweir //
176*cdf0e10cSrcweir // XInterface methods.
177*cdf0e10cSrcweir //
178*cdf0e10cSrcweir //=========================================================================
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir // virtual
181*cdf0e10cSrcweir void SAL_CALL HierarchyContent::acquire()
182*cdf0e10cSrcweir     throw( )
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     ContentImplHelper::acquire();
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir //=========================================================================
188*cdf0e10cSrcweir // virtual
189*cdf0e10cSrcweir void SAL_CALL HierarchyContent::release()
190*cdf0e10cSrcweir     throw( )
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir     ContentImplHelper::release();
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir //=========================================================================
196*cdf0e10cSrcweir // virtual
197*cdf0e10cSrcweir uno::Any SAL_CALL HierarchyContent::queryInterface( const uno::Type & rType )
198*cdf0e10cSrcweir     throw ( uno::RuntimeException )
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir     uno::Any aRet = ContentImplHelper::queryInterface( rType );
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     if ( !aRet.hasValue() )
203*cdf0e10cSrcweir     {
204*cdf0e10cSrcweir         // Note: isReadOnly may be relative expensive. So avoid calling it
205*cdf0e10cSrcweir         //       unless it is really necessary.
206*cdf0e10cSrcweir         aRet = cppu::queryInterface(
207*cdf0e10cSrcweir                 rType, static_cast< ucb::XContentCreator * >( this ) );
208*cdf0e10cSrcweir         if ( aRet.hasValue() )
209*cdf0e10cSrcweir         {
210*cdf0e10cSrcweir             if ( !isFolder() || isReadOnly() )
211*cdf0e10cSrcweir                 return uno::Any();
212*cdf0e10cSrcweir         }
213*cdf0e10cSrcweir     }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir     return aRet;
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir //=========================================================================
219*cdf0e10cSrcweir //
220*cdf0e10cSrcweir // XTypeProvider methods.
221*cdf0e10cSrcweir //
222*cdf0e10cSrcweir //=========================================================================
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( HierarchyContent );
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir //=========================================================================
227*cdf0e10cSrcweir // virtual
228*cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL HierarchyContent::getTypes()
229*cdf0e10cSrcweir     throw( uno::RuntimeException )
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     cppu::OTypeCollection * pCollection = 0;
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     if ( isFolder() && !isReadOnly() )
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir         static cppu::OTypeCollection* pFolderTypes = 0;
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir         pCollection = pFolderTypes;
238*cdf0e10cSrcweir         if ( !pCollection )
239*cdf0e10cSrcweir         {
240*cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir             pCollection = pFolderTypes;
243*cdf0e10cSrcweir             if ( !pCollection )
244*cdf0e10cSrcweir             {
245*cdf0e10cSrcweir                 static cppu::OTypeCollection aCollection(
246*cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XTypeProvider ),
247*cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XServiceInfo ),
248*cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XComponent ),
249*cdf0e10cSrcweir                     CPPU_TYPE_REF( ucb::XContent ),
250*cdf0e10cSrcweir                     CPPU_TYPE_REF( ucb::XCommandProcessor ),
251*cdf0e10cSrcweir                     CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
252*cdf0e10cSrcweir                     CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
253*cdf0e10cSrcweir                     CPPU_TYPE_REF( beans::XPropertyContainer ),
254*cdf0e10cSrcweir                     CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
255*cdf0e10cSrcweir                     CPPU_TYPE_REF( container::XChild ),
256*cdf0e10cSrcweir                     CPPU_TYPE_REF( ucb::XContentCreator ) ); // !!
257*cdf0e10cSrcweir                 pCollection = &aCollection;
258*cdf0e10cSrcweir                 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
259*cdf0e10cSrcweir                 pFolderTypes = pCollection;
260*cdf0e10cSrcweir             }
261*cdf0e10cSrcweir         }
262*cdf0e10cSrcweir         else {
263*cdf0e10cSrcweir             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
264*cdf0e10cSrcweir         }
265*cdf0e10cSrcweir     }
266*cdf0e10cSrcweir     else
267*cdf0e10cSrcweir     {
268*cdf0e10cSrcweir         static cppu::OTypeCollection* pDocumentTypes = 0;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir         pCollection = pDocumentTypes;
271*cdf0e10cSrcweir         if ( !pCollection )
272*cdf0e10cSrcweir         {
273*cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir             pCollection = pDocumentTypes;
276*cdf0e10cSrcweir             if ( !pCollection )
277*cdf0e10cSrcweir             {
278*cdf0e10cSrcweir                 static cppu::OTypeCollection aCollection(
279*cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XTypeProvider ),
280*cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XServiceInfo ),
281*cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XComponent ),
282*cdf0e10cSrcweir                     CPPU_TYPE_REF( ucb::XContent ),
283*cdf0e10cSrcweir                     CPPU_TYPE_REF( ucb::XCommandProcessor ),
284*cdf0e10cSrcweir                     CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
285*cdf0e10cSrcweir                     CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
286*cdf0e10cSrcweir                     CPPU_TYPE_REF( beans::XPropertyContainer ),
287*cdf0e10cSrcweir                     CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
288*cdf0e10cSrcweir                     CPPU_TYPE_REF( container::XChild ) );
289*cdf0e10cSrcweir                 pCollection = &aCollection;
290*cdf0e10cSrcweir                 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
291*cdf0e10cSrcweir                 pDocumentTypes = pCollection;
292*cdf0e10cSrcweir             }
293*cdf0e10cSrcweir         }
294*cdf0e10cSrcweir         else {
295*cdf0e10cSrcweir             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
296*cdf0e10cSrcweir         }
297*cdf0e10cSrcweir     }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     return (*pCollection).getTypes();
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir //=========================================================================
303*cdf0e10cSrcweir //
304*cdf0e10cSrcweir // XServiceInfo methods.
305*cdf0e10cSrcweir //
306*cdf0e10cSrcweir //=========================================================================
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir // virtual
309*cdf0e10cSrcweir rtl::OUString SAL_CALL HierarchyContent::getImplementationName()
310*cdf0e10cSrcweir     throw( uno::RuntimeException )
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir     return rtl::OUString::createFromAscii(
313*cdf0e10cSrcweir                             "com.sun.star.comp.ucb.HierarchyContent" );
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir //=========================================================================
317*cdf0e10cSrcweir // virtual
318*cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL
319*cdf0e10cSrcweir HierarchyContent::getSupportedServiceNames()
320*cdf0e10cSrcweir     throw( uno::RuntimeException )
321*cdf0e10cSrcweir {
322*cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aSNS( 1 );
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir     if ( m_eKind == LINK )
325*cdf0e10cSrcweir         aSNS.getArray()[ 0 ] = rtl::OUString::createFromAscii(
326*cdf0e10cSrcweir                                 HIERARCHY_LINK_CONTENT_SERVICE_NAME );
327*cdf0e10cSrcweir     else if ( m_eKind == FOLDER )
328*cdf0e10cSrcweir         aSNS.getArray()[ 0 ] = rtl::OUString::createFromAscii(
329*cdf0e10cSrcweir                                 HIERARCHY_FOLDER_CONTENT_SERVICE_NAME );
330*cdf0e10cSrcweir     else
331*cdf0e10cSrcweir         aSNS.getArray()[ 0 ] = rtl::OUString::createFromAscii(
332*cdf0e10cSrcweir                                 HIERARCHY_ROOT_FOLDER_CONTENT_SERVICE_NAME );
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir     return aSNS;
335*cdf0e10cSrcweir }
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir //=========================================================================
338*cdf0e10cSrcweir //
339*cdf0e10cSrcweir // XContent methods.
340*cdf0e10cSrcweir //
341*cdf0e10cSrcweir //=========================================================================
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir // virtual
344*cdf0e10cSrcweir rtl::OUString SAL_CALL HierarchyContent::getContentType()
345*cdf0e10cSrcweir     throw( uno::RuntimeException )
346*cdf0e10cSrcweir {
347*cdf0e10cSrcweir     return m_aProps.getContentType();
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir //=========================================================================
351*cdf0e10cSrcweir // virtual
352*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > SAL_CALL
353*cdf0e10cSrcweir HierarchyContent::getIdentifier()
354*cdf0e10cSrcweir     throw( uno::RuntimeException )
355*cdf0e10cSrcweir {
356*cdf0e10cSrcweir     // Transient?
357*cdf0e10cSrcweir     if ( m_eState == TRANSIENT )
358*cdf0e10cSrcweir     {
359*cdf0e10cSrcweir         // Transient contents have no identifier.
360*cdf0e10cSrcweir         return uno::Reference< ucb::XContentIdentifier >();
361*cdf0e10cSrcweir     }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir     return ContentImplHelper::getIdentifier();
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir //=========================================================================
367*cdf0e10cSrcweir //
368*cdf0e10cSrcweir // XCommandProcessor methods.
369*cdf0e10cSrcweir //
370*cdf0e10cSrcweir //=========================================================================
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir // virtual
373*cdf0e10cSrcweir uno::Any SAL_CALL HierarchyContent::execute(
374*cdf0e10cSrcweir         const ucb::Command& aCommand,
375*cdf0e10cSrcweir         sal_Int32 /*CommandId*/,
376*cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment >& Environment )
377*cdf0e10cSrcweir     throw( uno::Exception,
378*cdf0e10cSrcweir            ucb::CommandAbortedException,
379*cdf0e10cSrcweir            uno::RuntimeException )
380*cdf0e10cSrcweir {
381*cdf0e10cSrcweir     uno::Any aRet;
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir     if ( aCommand.Name.equalsAsciiL(
384*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM( "getPropertyValues" ) ) )
385*cdf0e10cSrcweir     {
386*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
387*cdf0e10cSrcweir         // getPropertyValues
388*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir         uno::Sequence< beans::Property > Properties;
391*cdf0e10cSrcweir         if ( !( aCommand.Argument >>= Properties ) )
392*cdf0e10cSrcweir         {
393*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
394*cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
395*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
396*cdf0e10cSrcweir                                         "Wrong argument type!" ),
397*cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
398*cdf0e10cSrcweir                                     -1 ) ),
399*cdf0e10cSrcweir                 Environment );
400*cdf0e10cSrcweir             // Unreachable
401*cdf0e10cSrcweir         }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir         aRet <<= getPropertyValues( Properties );
404*cdf0e10cSrcweir     }
405*cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
406*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( "setPropertyValues" ) ) )
407*cdf0e10cSrcweir     {
408*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
409*cdf0e10cSrcweir         // setPropertyValues
410*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aProperties;
413*cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aProperties ) )
414*cdf0e10cSrcweir         {
415*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
416*cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
417*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
418*cdf0e10cSrcweir                                         "Wrong argument type!" ),
419*cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
420*cdf0e10cSrcweir                                     -1 ) ),
421*cdf0e10cSrcweir                 Environment );
422*cdf0e10cSrcweir             // Unreachable
423*cdf0e10cSrcweir         }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir         if ( !aProperties.getLength() )
426*cdf0e10cSrcweir         {
427*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
428*cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
429*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
430*cdf0e10cSrcweir                                         "No properties!" ),
431*cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
432*cdf0e10cSrcweir                                     -1 ) ),
433*cdf0e10cSrcweir                 Environment );
434*cdf0e10cSrcweir             // Unreachable
435*cdf0e10cSrcweir         }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir         aRet <<= setPropertyValues( aProperties, Environment );
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
440*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( "getPropertySetInfo" ) ) )
441*cdf0e10cSrcweir     {
442*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
443*cdf0e10cSrcweir         // getPropertySetInfo
444*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir         aRet <<= getPropertySetInfo( Environment );
447*cdf0e10cSrcweir     }
448*cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
449*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( "getCommandInfo" ) ) )
450*cdf0e10cSrcweir     {
451*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
452*cdf0e10cSrcweir         // getCommandInfo
453*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir         aRet <<= getCommandInfo( Environment );
456*cdf0e10cSrcweir     }
457*cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
458*cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "open" ) ) && isFolder() )
459*cdf0e10cSrcweir     {
460*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
461*cdf0e10cSrcweir         // open command for a folder content
462*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir         ucb::OpenCommandArgument2 aOpenCommand;
465*cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aOpenCommand ) )
466*cdf0e10cSrcweir         {
467*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
468*cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
469*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
470*cdf0e10cSrcweir                                         "Wrong argument type!" ),
471*cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
472*cdf0e10cSrcweir                                     -1 ) ),
473*cdf0e10cSrcweir                 Environment );
474*cdf0e10cSrcweir             // Unreachable
475*cdf0e10cSrcweir         }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir         uno::Reference< ucb::XDynamicResultSet > xSet
478*cdf0e10cSrcweir                 = new DynamicResultSet( m_xSMgr, this, aOpenCommand );
479*cdf0e10cSrcweir         aRet <<= xSet;
480*cdf0e10cSrcweir     }
481*cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
482*cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "insert" ) ) &&
483*cdf0e10cSrcweir               ( m_eKind != ROOT ) && !isReadOnly() )
484*cdf0e10cSrcweir     {
485*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
486*cdf0e10cSrcweir         // insert
487*cdf0e10cSrcweir         //  ( Not available at root folder )
488*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir         ucb::InsertCommandArgument aArg;
491*cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aArg ) )
492*cdf0e10cSrcweir         {
493*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
494*cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
495*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
496*cdf0e10cSrcweir                                         "Wrong argument type!" ),
497*cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
498*cdf0e10cSrcweir                                     -1 ) ),
499*cdf0e10cSrcweir                 Environment );
500*cdf0e10cSrcweir             // Unreachable
501*cdf0e10cSrcweir         }
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir         sal_Int32 nNameClash = aArg.ReplaceExisting
504*cdf0e10cSrcweir                              ? ucb::NameClash::OVERWRITE
505*cdf0e10cSrcweir                              : ucb::NameClash::ERROR;
506*cdf0e10cSrcweir         insert( nNameClash, Environment );
507*cdf0e10cSrcweir     }
508*cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
509*cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "delete" ) ) &&
510*cdf0e10cSrcweir               ( m_eKind != ROOT ) && !isReadOnly() )
511*cdf0e10cSrcweir     {
512*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
513*cdf0e10cSrcweir         // delete
514*cdf0e10cSrcweir         //  ( Not available at root folder )
515*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir         sal_Bool bDeletePhysical = sal_False;
518*cdf0e10cSrcweir         aCommand.Argument >>= bDeletePhysical;
519*cdf0e10cSrcweir         destroy( bDeletePhysical, Environment );
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir         // Remove own and all children's persistent data.
522*cdf0e10cSrcweir         if ( !removeData() )
523*cdf0e10cSrcweir         {
524*cdf0e10cSrcweir             uno::Any aProps
525*cdf0e10cSrcweir                 = uno::makeAny(
526*cdf0e10cSrcweir                          beans::PropertyValue(
527*cdf0e10cSrcweir                              rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
528*cdf0e10cSrcweir                                                "Uri")),
529*cdf0e10cSrcweir                              -1,
530*cdf0e10cSrcweir                              uno::makeAny(m_xIdentifier->
531*cdf0e10cSrcweir                                               getContentIdentifier()),
532*cdf0e10cSrcweir                              beans::PropertyState_DIRECT_VALUE));
533*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
534*cdf0e10cSrcweir                 ucb::IOErrorCode_CANT_WRITE,
535*cdf0e10cSrcweir                 uno::Sequence< uno::Any >(&aProps, 1),
536*cdf0e10cSrcweir                 Environment,
537*cdf0e10cSrcweir                 rtl::OUString::createFromAscii(
538*cdf0e10cSrcweir                     "Cannot remove persistent data!" ),
539*cdf0e10cSrcweir                 this );
540*cdf0e10cSrcweir             // Unreachable
541*cdf0e10cSrcweir         }
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir         // Remove own and all children's Additional Core Properties.
544*cdf0e10cSrcweir         removeAdditionalPropertySet( sal_True );
545*cdf0e10cSrcweir     }
546*cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
547*cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "transfer" ) ) &&
548*cdf0e10cSrcweir               isFolder() && !isReadOnly() )
549*cdf0e10cSrcweir     {
550*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
551*cdf0e10cSrcweir         // transfer
552*cdf0e10cSrcweir         //      ( Not available at link objects )
553*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir         ucb::TransferInfo aInfo;
556*cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aInfo ) )
557*cdf0e10cSrcweir         {
558*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "Wrong argument type!" );
559*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
560*cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
561*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
562*cdf0e10cSrcweir                                         "Wrong argument type!" ),
563*cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
564*cdf0e10cSrcweir                                     -1 ) ),
565*cdf0e10cSrcweir                 Environment );
566*cdf0e10cSrcweir             // Unreachable
567*cdf0e10cSrcweir         }
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir         transfer( aInfo, Environment );
570*cdf0e10cSrcweir     }
571*cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
572*cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "createNewContent" ) ) &&
573*cdf0e10cSrcweir               isFolder() && !isReadOnly() )
574*cdf0e10cSrcweir     {
575*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
576*cdf0e10cSrcweir         // createNewContent
577*cdf0e10cSrcweir         //      ( Not available at link objects )
578*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir         ucb::ContentInfo aInfo;
581*cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aInfo ) )
582*cdf0e10cSrcweir         {
583*cdf0e10cSrcweir             OSL_ENSURE( sal_False, "Wrong argument type!" );
584*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
585*cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
586*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
587*cdf0e10cSrcweir                                         "Wrong argument type!" ),
588*cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
589*cdf0e10cSrcweir                                     -1 ) ),
590*cdf0e10cSrcweir                 Environment );
591*cdf0e10cSrcweir             // Unreachable
592*cdf0e10cSrcweir         }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir         aRet <<= createNewContent( aInfo );
595*cdf0e10cSrcweir     }
596*cdf0e10cSrcweir     else
597*cdf0e10cSrcweir     {
598*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
599*cdf0e10cSrcweir         // Unsupported command
600*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
603*cdf0e10cSrcweir             uno::makeAny( ucb::UnsupportedCommandException(
604*cdf0e10cSrcweir                                 rtl::OUString(),
605*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) ) ),
606*cdf0e10cSrcweir             Environment );
607*cdf0e10cSrcweir         // Unreachable
608*cdf0e10cSrcweir     }
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir     return aRet;
611*cdf0e10cSrcweir }
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir //=========================================================================
614*cdf0e10cSrcweir // virtual
615*cdf0e10cSrcweir void SAL_CALL HierarchyContent::abort( sal_Int32 /*CommandId*/ )
616*cdf0e10cSrcweir     throw( uno::RuntimeException )
617*cdf0e10cSrcweir {
618*cdf0e10cSrcweir     // @@@ Generally, no action takes much time...
619*cdf0e10cSrcweir }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir //=========================================================================
622*cdf0e10cSrcweir //
623*cdf0e10cSrcweir // XContentCreator methods.
624*cdf0e10cSrcweir //
625*cdf0e10cSrcweir //=========================================================================
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir // virtual
628*cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > SAL_CALL
629*cdf0e10cSrcweir HierarchyContent::queryCreatableContentsInfo()
630*cdf0e10cSrcweir     throw( uno::RuntimeException )
631*cdf0e10cSrcweir {
632*cdf0e10cSrcweir     return m_aProps.getCreatableContentsInfo();
633*cdf0e10cSrcweir }
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir //=========================================================================
636*cdf0e10cSrcweir // virtual
637*cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL
638*cdf0e10cSrcweir HierarchyContent::createNewContent( const ucb::ContentInfo& Info )
639*cdf0e10cSrcweir     throw( uno::RuntimeException )
640*cdf0e10cSrcweir {
641*cdf0e10cSrcweir     if ( isFolder() )
642*cdf0e10cSrcweir     {
643*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir         if ( !Info.Type.getLength() )
646*cdf0e10cSrcweir             return uno::Reference< ucb::XContent >();
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir         sal_Bool bCreateFolder =
649*cdf0e10cSrcweir             Info.Type.equalsAsciiL(
650*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( HIERARCHY_FOLDER_CONTENT_TYPE ) );
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir         if ( !bCreateFolder &&
653*cdf0e10cSrcweir              !Info.Type.equalsAsciiL(
654*cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( HIERARCHY_LINK_CONTENT_TYPE ) ) )
655*cdf0e10cSrcweir             return uno::Reference< ucb::XContent >();
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir         rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir         OSL_ENSURE( aURL.getLength() > 0,
660*cdf0e10cSrcweir                     "HierarchyContent::createNewContent - empty identifier!" );
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir         if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() )
663*cdf0e10cSrcweir             aURL += rtl::OUString::createFromAscii( "/" );
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir         if ( bCreateFolder )
666*cdf0e10cSrcweir             aURL += rtl::OUString::createFromAscii( "New_Folder" );
667*cdf0e10cSrcweir         else
668*cdf0e10cSrcweir             aURL += rtl::OUString::createFromAscii( "New_Link" );
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir         uno::Reference< ucb::XContentIdentifier > xId
671*cdf0e10cSrcweir             = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL );
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir         return create( m_xSMgr, m_pProvider, xId, Info );
674*cdf0e10cSrcweir     }
675*cdf0e10cSrcweir     else
676*cdf0e10cSrcweir     {
677*cdf0e10cSrcweir         OSL_ENSURE( sal_False,
678*cdf0e10cSrcweir                     "createNewContent called on non-folder object!" );
679*cdf0e10cSrcweir         return uno::Reference< ucb::XContent >();
680*cdf0e10cSrcweir     }
681*cdf0e10cSrcweir }
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir //=========================================================================
684*cdf0e10cSrcweir // virtual
685*cdf0e10cSrcweir rtl::OUString HierarchyContent::getParentURL()
686*cdf0e10cSrcweir {
687*cdf0e10cSrcweir     HierarchyUri aUri( m_xIdentifier->getContentIdentifier() );
688*cdf0e10cSrcweir     return aUri.getParentUri();
689*cdf0e10cSrcweir }
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir //=========================================================================
692*cdf0e10cSrcweir //static
693*cdf0e10cSrcweir sal_Bool HierarchyContent::hasData(
694*cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
695*cdf0e10cSrcweir             HierarchyContentProvider* pProvider,
696*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& Identifier )
697*cdf0e10cSrcweir {
698*cdf0e10cSrcweir     rtl::OUString aURL = Identifier->getContentIdentifier();
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir     // Am I a root folder?
701*cdf0e10cSrcweir     HierarchyUri aUri( aURL );
702*cdf0e10cSrcweir     if ( aUri.isRootFolder() )
703*cdf0e10cSrcweir     {
704*cdf0e10cSrcweir         // hasData must always return 'true' for root folder
705*cdf0e10cSrcweir         // even if no persistent data exist!!!
706*cdf0e10cSrcweir         return sal_True;
707*cdf0e10cSrcweir     }
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir     return HierarchyEntry( rxSMgr, pProvider, aURL ).hasData();
710*cdf0e10cSrcweir }
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir //=========================================================================
713*cdf0e10cSrcweir //static
714*cdf0e10cSrcweir sal_Bool HierarchyContent::loadData(
715*cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
716*cdf0e10cSrcweir             HierarchyContentProvider* pProvider,
717*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& Identifier,
718*cdf0e10cSrcweir             HierarchyContentProperties& rProps )
719*cdf0e10cSrcweir {
720*cdf0e10cSrcweir     rtl::OUString aURL = Identifier->getContentIdentifier();
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir     // Am I a root folder?
723*cdf0e10cSrcweir     HierarchyUri aUri( aURL );
724*cdf0e10cSrcweir     if ( aUri.isRootFolder() )
725*cdf0e10cSrcweir     {
726*cdf0e10cSrcweir         rProps = HierarchyContentProperties( HierarchyEntryData::FOLDER );
727*cdf0e10cSrcweir     }
728*cdf0e10cSrcweir     else
729*cdf0e10cSrcweir     {
730*cdf0e10cSrcweir         HierarchyEntry aEntry( rxSMgr, pProvider, aURL );
731*cdf0e10cSrcweir         HierarchyEntryData aData;
732*cdf0e10cSrcweir         if ( !aEntry.getData( aData ) )
733*cdf0e10cSrcweir             return sal_False;
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir         rProps = HierarchyContentProperties( aData );
736*cdf0e10cSrcweir     }
737*cdf0e10cSrcweir     return sal_True;
738*cdf0e10cSrcweir }
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir //=========================================================================
741*cdf0e10cSrcweir sal_Bool HierarchyContent::storeData()
742*cdf0e10cSrcweir {
743*cdf0e10cSrcweir     HierarchyEntry aEntry(
744*cdf0e10cSrcweir             m_xSMgr, m_pProvider, m_xIdentifier->getContentIdentifier() );
745*cdf0e10cSrcweir     return aEntry.setData( m_aProps.getHierarchyEntryData(), sal_True );
746*cdf0e10cSrcweir }
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir //=========================================================================
749*cdf0e10cSrcweir sal_Bool HierarchyContent::renameData(
750*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& xOldId,
751*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& xNewId )
752*cdf0e10cSrcweir {
753*cdf0e10cSrcweir     HierarchyEntry aEntry(
754*cdf0e10cSrcweir             m_xSMgr, m_pProvider, xOldId->getContentIdentifier() );
755*cdf0e10cSrcweir     return aEntry.move( xNewId->getContentIdentifier(),
756*cdf0e10cSrcweir                         m_aProps.getHierarchyEntryData() );
757*cdf0e10cSrcweir }
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir //=========================================================================
760*cdf0e10cSrcweir sal_Bool HierarchyContent::removeData()
761*cdf0e10cSrcweir {
762*cdf0e10cSrcweir     HierarchyEntry aEntry(
763*cdf0e10cSrcweir         m_xSMgr, m_pProvider, m_xIdentifier->getContentIdentifier() );
764*cdf0e10cSrcweir     return aEntry.remove();
765*cdf0e10cSrcweir }
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir //=========================================================================
768*cdf0e10cSrcweir void HierarchyContent::setKind(
769*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& Identifier )
770*cdf0e10cSrcweir {
771*cdf0e10cSrcweir     if ( m_aProps.getIsFolder() )
772*cdf0e10cSrcweir     {
773*cdf0e10cSrcweir         // Am I a root folder?
774*cdf0e10cSrcweir         HierarchyUri aUri( Identifier->getContentIdentifier() );
775*cdf0e10cSrcweir         if ( aUri.isRootFolder() )
776*cdf0e10cSrcweir             m_eKind = ROOT;
777*cdf0e10cSrcweir         else
778*cdf0e10cSrcweir             m_eKind = FOLDER;
779*cdf0e10cSrcweir     }
780*cdf0e10cSrcweir     else
781*cdf0e10cSrcweir         m_eKind = LINK;
782*cdf0e10cSrcweir }
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir //=========================================================================
785*cdf0e10cSrcweir bool HierarchyContent::isReadOnly()
786*cdf0e10cSrcweir {
787*cdf0e10cSrcweir     if ( !m_bCheckedReadOnly )
788*cdf0e10cSrcweir     {
789*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
790*cdf0e10cSrcweir         if ( !m_bCheckedReadOnly )
791*cdf0e10cSrcweir         {
792*cdf0e10cSrcweir             m_bCheckedReadOnly = true;
793*cdf0e10cSrcweir             m_bIsReadOnly      = true;
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir             HierarchyUri aUri( m_xIdentifier->getContentIdentifier() );
796*cdf0e10cSrcweir             uno::Reference< lang::XMultiServiceFactory > xConfigProv
797*cdf0e10cSrcweir                 = m_pProvider->getConfigProvider( aUri.getService() );
798*cdf0e10cSrcweir             if ( xConfigProv.is() )
799*cdf0e10cSrcweir             {
800*cdf0e10cSrcweir                 uno::Sequence< rtl::OUString > aNames
801*cdf0e10cSrcweir                     = xConfigProv->getAvailableServiceNames();
802*cdf0e10cSrcweir                 sal_Int32 nCount = aNames.getLength();
803*cdf0e10cSrcweir                 for ( sal_Int32 n = 0; n < nCount; ++n )
804*cdf0e10cSrcweir                 {
805*cdf0e10cSrcweir                     if ( aNames[ n ].equalsAsciiL(
806*cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM(
807*cdf0e10cSrcweir                                 "com.sun.star.ucb.HierarchyDataReadWriteAccess"
808*cdf0e10cSrcweir                              ) ) )
809*cdf0e10cSrcweir                     {
810*cdf0e10cSrcweir                         m_bIsReadOnly = false;
811*cdf0e10cSrcweir                         break;
812*cdf0e10cSrcweir                     }
813*cdf0e10cSrcweir                 }
814*cdf0e10cSrcweir             }
815*cdf0e10cSrcweir         }
816*cdf0e10cSrcweir     }
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir     return m_bIsReadOnly;
819*cdf0e10cSrcweir }
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir //=========================================================================
822*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier >
823*cdf0e10cSrcweir HierarchyContent::makeNewIdentifier( const rtl::OUString& rTitle )
824*cdf0e10cSrcweir {
825*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir     // Assemble new content identifier...
828*cdf0e10cSrcweir     HierarchyUri aUri( m_xIdentifier->getContentIdentifier() );
829*cdf0e10cSrcweir     rtl::OUString aNewURL = aUri.getParentUri();
830*cdf0e10cSrcweir     aNewURL += rtl::OUString::createFromAscii( "/" );
831*cdf0e10cSrcweir     aNewURL += ::ucb_impl::urihelper::encodeSegment( rTitle );
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir     return uno::Reference< ucb::XContentIdentifier >(
834*cdf0e10cSrcweir         new ::ucbhelper::ContentIdentifier( m_xSMgr, aNewURL ) );
835*cdf0e10cSrcweir }
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir //=========================================================================
838*cdf0e10cSrcweir void HierarchyContent::queryChildren( HierarchyContentRefList& rChildren )
839*cdf0e10cSrcweir {
840*cdf0e10cSrcweir     if ( ( m_eKind != FOLDER ) && ( m_eKind != ROOT ) )
841*cdf0e10cSrcweir         return;
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir     // Obtain a list with a snapshot of all currently instanciated contents
844*cdf0e10cSrcweir     // from provider and extract the contents which are direct children
845*cdf0e10cSrcweir     // of this content.
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir     ::ucbhelper::ContentRefList aAllContents;
848*cdf0e10cSrcweir     m_xProvider->queryExistingContents( aAllContents );
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir     rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
851*cdf0e10cSrcweir     sal_Int32 nURLPos = aURL.lastIndexOf( '/' );
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir     if ( nURLPos != ( aURL.getLength() - 1 ) )
854*cdf0e10cSrcweir     {
855*cdf0e10cSrcweir         // No trailing slash found. Append.
856*cdf0e10cSrcweir         aURL += rtl::OUString::createFromAscii( "/" );
857*cdf0e10cSrcweir     }
858*cdf0e10cSrcweir 
859*cdf0e10cSrcweir     sal_Int32 nLen = aURL.getLength();
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir     ::ucbhelper::ContentRefList::const_iterator it  = aAllContents.begin();
862*cdf0e10cSrcweir     ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir     while ( it != end )
865*cdf0e10cSrcweir     {
866*cdf0e10cSrcweir         ::ucbhelper::ContentImplHelperRef xChild = (*it);
867*cdf0e10cSrcweir         rtl::OUString aChildURL
868*cdf0e10cSrcweir             = xChild->getIdentifier()->getContentIdentifier();
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir         // Is aURL a prefix of aChildURL?
871*cdf0e10cSrcweir         if ( ( aChildURL.getLength() > nLen ) &&
872*cdf0e10cSrcweir              ( aChildURL.compareTo( aURL, nLen ) == 0 ) )
873*cdf0e10cSrcweir         {
874*cdf0e10cSrcweir             sal_Int32 nPos = nLen;
875*cdf0e10cSrcweir             nPos = aChildURL.indexOf( '/', nPos );
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir             if ( ( nPos == -1 ) ||
878*cdf0e10cSrcweir                  ( nPos == ( aChildURL.getLength() - 1 ) ) )
879*cdf0e10cSrcweir             {
880*cdf0e10cSrcweir                 // No further slashes/ only a final slash. It's a child!
881*cdf0e10cSrcweir                 rChildren.push_back(
882*cdf0e10cSrcweir                     HierarchyContentRef(
883*cdf0e10cSrcweir                         static_cast< HierarchyContent * >( xChild.get() ) ) );
884*cdf0e10cSrcweir             }
885*cdf0e10cSrcweir         }
886*cdf0e10cSrcweir         ++it;
887*cdf0e10cSrcweir     }
888*cdf0e10cSrcweir }
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir //=========================================================================
891*cdf0e10cSrcweir sal_Bool HierarchyContent::exchangeIdentity(
892*cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& xNewId )
893*cdf0e10cSrcweir {
894*cdf0e10cSrcweir     if ( !xNewId.is() )
895*cdf0e10cSrcweir         return sal_False;
896*cdf0e10cSrcweir 
897*cdf0e10cSrcweir     osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
898*cdf0e10cSrcweir 
899*cdf0e10cSrcweir     uno::Reference< ucb::XContent > xThis = this;
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir     // Already persistent?
902*cdf0e10cSrcweir     if ( m_eState != PERSISTENT )
903*cdf0e10cSrcweir     {
904*cdf0e10cSrcweir         OSL_ENSURE( sal_False,
905*cdf0e10cSrcweir                     "HierarchyContent::exchangeIdentity - Not persistent!" );
906*cdf0e10cSrcweir         return sal_False;
907*cdf0e10cSrcweir     }
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir     // Am I the root folder?
910*cdf0e10cSrcweir     if ( m_eKind == ROOT )
911*cdf0e10cSrcweir     {
912*cdf0e10cSrcweir         OSL_ENSURE( sal_False, "HierarchyContent::exchangeIdentity - "
913*cdf0e10cSrcweir                                "Not supported by root folder!" );
914*cdf0e10cSrcweir         return sal_False;
915*cdf0e10cSrcweir     }
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir     // Exchange own identitity.
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir     // Fail, if a content with given id already exists.
920*cdf0e10cSrcweir     if ( !hasData( xNewId ) )
921*cdf0e10cSrcweir     {
922*cdf0e10cSrcweir         rtl::OUString aOldURL = m_xIdentifier->getContentIdentifier();
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir         aGuard.clear();
925*cdf0e10cSrcweir         if ( exchange( xNewId ) )
926*cdf0e10cSrcweir         {
927*cdf0e10cSrcweir             if ( m_eKind == FOLDER )
928*cdf0e10cSrcweir             {
929*cdf0e10cSrcweir                 // Process instanciated children...
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir                 HierarchyContentRefList aChildren;
932*cdf0e10cSrcweir                 queryChildren( aChildren );
933*cdf0e10cSrcweir 
934*cdf0e10cSrcweir                 HierarchyContentRefList::const_iterator it  = aChildren.begin();
935*cdf0e10cSrcweir                 HierarchyContentRefList::const_iterator end = aChildren.end();
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir                 while ( it != end )
938*cdf0e10cSrcweir                 {
939*cdf0e10cSrcweir                     HierarchyContentRef xChild = (*it);
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir                     // Create new content identifier for the child...
942*cdf0e10cSrcweir                     uno::Reference< ucb::XContentIdentifier > xOldChildId
943*cdf0e10cSrcweir                                                     = xChild->getIdentifier();
944*cdf0e10cSrcweir                     rtl::OUString aOldChildURL
945*cdf0e10cSrcweir                         = xOldChildId->getContentIdentifier();
946*cdf0e10cSrcweir                     rtl::OUString aNewChildURL
947*cdf0e10cSrcweir                         = aOldChildURL.replaceAt(
948*cdf0e10cSrcweir                                         0,
949*cdf0e10cSrcweir                                         aOldURL.getLength(),
950*cdf0e10cSrcweir                                         xNewId->getContentIdentifier() );
951*cdf0e10cSrcweir                     uno::Reference< ucb::XContentIdentifier > xNewChildId
952*cdf0e10cSrcweir                         = new ::ucbhelper::ContentIdentifier(
953*cdf0e10cSrcweir                             m_xSMgr, aNewChildURL );
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir                     if ( !xChild->exchangeIdentity( xNewChildId ) )
956*cdf0e10cSrcweir                         return sal_False;
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir                     ++it;
959*cdf0e10cSrcweir                 }
960*cdf0e10cSrcweir             }
961*cdf0e10cSrcweir             return sal_True;
962*cdf0e10cSrcweir         }
963*cdf0e10cSrcweir     }
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir     OSL_ENSURE( sal_False,
966*cdf0e10cSrcweir                 "HierarchyContent::exchangeIdentity - "
967*cdf0e10cSrcweir                 "Panic! Cannot exchange identity!" );
968*cdf0e10cSrcweir     return sal_False;
969*cdf0e10cSrcweir }
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir //=========================================================================
972*cdf0e10cSrcweir // static
973*cdf0e10cSrcweir uno::Reference< sdbc::XRow > HierarchyContent::getPropertyValues(
974*cdf0e10cSrcweir                 const uno::Reference< lang::XMultiServiceFactory >& rSMgr,
975*cdf0e10cSrcweir                 const uno::Sequence< beans::Property >& rProperties,
976*cdf0e10cSrcweir                 const HierarchyContentProperties& rData,
977*cdf0e10cSrcweir                 HierarchyContentProvider* pProvider,
978*cdf0e10cSrcweir                 const rtl::OUString& rContentId )
979*cdf0e10cSrcweir {
980*cdf0e10cSrcweir     // Note: Empty sequence means "get values of all supported properties".
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir     rtl::Reference< ::ucbhelper::PropertyValueSet > xRow
983*cdf0e10cSrcweir         = new ::ucbhelper::PropertyValueSet( rSMgr );
984*cdf0e10cSrcweir 
985*cdf0e10cSrcweir     sal_Int32 nCount = rProperties.getLength();
986*cdf0e10cSrcweir     if ( nCount )
987*cdf0e10cSrcweir     {
988*cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xAdditionalPropSet;
989*cdf0e10cSrcweir         sal_Bool bTriedToGetAdditonalPropSet = sal_False;
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir         const beans::Property* pProps = rProperties.getConstArray();
992*cdf0e10cSrcweir         for ( sal_Int32 n = 0; n < nCount; ++n )
993*cdf0e10cSrcweir         {
994*cdf0e10cSrcweir             const beans::Property& rProp = pProps[ n ];
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir             // Process Core properties.
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir             if ( rProp.Name.equalsAsciiL(
999*cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) )
1000*cdf0e10cSrcweir             {
1001*cdf0e10cSrcweir                 xRow->appendString ( rProp, rData.getContentType() );
1002*cdf0e10cSrcweir             }
1003*cdf0e10cSrcweir             else if ( rProp.Name.equalsAsciiL(
1004*cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
1005*cdf0e10cSrcweir             {
1006*cdf0e10cSrcweir                 xRow->appendString ( rProp, rData.getTitle() );
1007*cdf0e10cSrcweir             }
1008*cdf0e10cSrcweir             else if ( rProp.Name.equalsAsciiL(
1009*cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) )
1010*cdf0e10cSrcweir             {
1011*cdf0e10cSrcweir                 xRow->appendBoolean( rProp, rData.getIsDocument() );
1012*cdf0e10cSrcweir             }
1013*cdf0e10cSrcweir             else if ( rProp.Name.equalsAsciiL(
1014*cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) )
1015*cdf0e10cSrcweir             {
1016*cdf0e10cSrcweir                 xRow->appendBoolean( rProp, rData.getIsFolder() );
1017*cdf0e10cSrcweir             }
1018*cdf0e10cSrcweir             else if ( rProp.Name.equalsAsciiL(
1019*cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) )
1020*cdf0e10cSrcweir             {
1021*cdf0e10cSrcweir                 xRow->appendObject(
1022*cdf0e10cSrcweir                     rProp, uno::makeAny( rData.getCreatableContentsInfo() ) );
1023*cdf0e10cSrcweir             }
1024*cdf0e10cSrcweir             else if ( rProp.Name.equalsAsciiL(
1025*cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( "TargetURL" ) ) )
1026*cdf0e10cSrcweir             {
1027*cdf0e10cSrcweir                 // TargetURL is only supported by links.
1028*cdf0e10cSrcweir 
1029*cdf0e10cSrcweir                 if ( rData.getIsDocument() )
1030*cdf0e10cSrcweir                     xRow->appendString( rProp, rData.getTargetURL() );
1031*cdf0e10cSrcweir                 else
1032*cdf0e10cSrcweir                     xRow->appendVoid( rProp );
1033*cdf0e10cSrcweir             }
1034*cdf0e10cSrcweir             else
1035*cdf0e10cSrcweir             {
1036*cdf0e10cSrcweir                 // Not a Core Property! Maybe it's an Additional Core Property?!
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir                 if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() )
1039*cdf0e10cSrcweir                 {
1040*cdf0e10cSrcweir                     xAdditionalPropSet
1041*cdf0e10cSrcweir                         = uno::Reference< beans::XPropertySet >(
1042*cdf0e10cSrcweir                             pProvider->getAdditionalPropertySet( rContentId,
1043*cdf0e10cSrcweir                                                                  sal_False ),
1044*cdf0e10cSrcweir                             uno::UNO_QUERY );
1045*cdf0e10cSrcweir                     bTriedToGetAdditonalPropSet = sal_True;
1046*cdf0e10cSrcweir                 }
1047*cdf0e10cSrcweir 
1048*cdf0e10cSrcweir                 if ( xAdditionalPropSet.is() )
1049*cdf0e10cSrcweir                 {
1050*cdf0e10cSrcweir                     if ( !xRow->appendPropertySetValue(
1051*cdf0e10cSrcweir                                                 xAdditionalPropSet,
1052*cdf0e10cSrcweir                                                 rProp ) )
1053*cdf0e10cSrcweir                     {
1054*cdf0e10cSrcweir                         // Append empty entry.
1055*cdf0e10cSrcweir                         xRow->appendVoid( rProp );
1056*cdf0e10cSrcweir                     }
1057*cdf0e10cSrcweir                 }
1058*cdf0e10cSrcweir                 else
1059*cdf0e10cSrcweir                 {
1060*cdf0e10cSrcweir                     // Append empty entry.
1061*cdf0e10cSrcweir                     xRow->appendVoid( rProp );
1062*cdf0e10cSrcweir                 }
1063*cdf0e10cSrcweir             }
1064*cdf0e10cSrcweir         }
1065*cdf0e10cSrcweir     }
1066*cdf0e10cSrcweir     else
1067*cdf0e10cSrcweir     {
1068*cdf0e10cSrcweir         // Append all Core Properties.
1069*cdf0e10cSrcweir         xRow->appendString (
1070*cdf0e10cSrcweir             beans::Property( rtl::OUString::createFromAscii( "ContentType" ),
1071*cdf0e10cSrcweir                       -1,
1072*cdf0e10cSrcweir                       getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
1073*cdf0e10cSrcweir                       beans::PropertyAttribute::BOUND
1074*cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ),
1075*cdf0e10cSrcweir             rData.getContentType() );
1076*cdf0e10cSrcweir         xRow->appendString (
1077*cdf0e10cSrcweir             beans::Property( rtl::OUString::createFromAscii( "Title" ),
1078*cdf0e10cSrcweir                       -1,
1079*cdf0e10cSrcweir                       getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
1080*cdf0e10cSrcweir                           // @@@ Might actually be read-only!
1081*cdf0e10cSrcweir                       beans::PropertyAttribute::BOUND ),
1082*cdf0e10cSrcweir             rData.getTitle() );
1083*cdf0e10cSrcweir         xRow->appendBoolean(
1084*cdf0e10cSrcweir             beans::Property( rtl::OUString::createFromAscii( "IsDocument" ),
1085*cdf0e10cSrcweir                       -1,
1086*cdf0e10cSrcweir                       getCppuBooleanType(),
1087*cdf0e10cSrcweir                       beans::PropertyAttribute::BOUND
1088*cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ),
1089*cdf0e10cSrcweir             rData.getIsDocument() );
1090*cdf0e10cSrcweir         xRow->appendBoolean(
1091*cdf0e10cSrcweir             beans::Property( rtl::OUString::createFromAscii( "IsFolder" ),
1092*cdf0e10cSrcweir                       -1,
1093*cdf0e10cSrcweir                       getCppuBooleanType(),
1094*cdf0e10cSrcweir                       beans::PropertyAttribute::BOUND
1095*cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ),
1096*cdf0e10cSrcweir             rData.getIsFolder() );
1097*cdf0e10cSrcweir 
1098*cdf0e10cSrcweir         if ( rData.getIsDocument() )
1099*cdf0e10cSrcweir             xRow->appendString(
1100*cdf0e10cSrcweir                 beans::Property( rtl::OUString::createFromAscii( "TargetURL" ),
1101*cdf0e10cSrcweir                           -1,
1102*cdf0e10cSrcweir                           getCppuType(
1103*cdf0e10cSrcweir                             static_cast< const rtl::OUString * >( 0 ) ),
1104*cdf0e10cSrcweir                           // @@@ Might actually be read-only!
1105*cdf0e10cSrcweir                           beans::PropertyAttribute::BOUND ),
1106*cdf0e10cSrcweir                 rData.getTargetURL() );
1107*cdf0e10cSrcweir         xRow->appendObject(
1108*cdf0e10cSrcweir             beans::Property(
1109*cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "CreatableContentsInfo" ),
1110*cdf0e10cSrcweir                 -1,
1111*cdf0e10cSrcweir                 getCppuType( static_cast<
1112*cdf0e10cSrcweir                         const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
1113*cdf0e10cSrcweir                 beans::PropertyAttribute::BOUND
1114*cdf0e10cSrcweir                 | beans::PropertyAttribute::READONLY ),
1115*cdf0e10cSrcweir             uno::makeAny( rData.getCreatableContentsInfo() ) );
1116*cdf0e10cSrcweir 
1117*cdf0e10cSrcweir         // Append all Additional Core Properties.
1118*cdf0e10cSrcweir 
1119*cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xSet(
1120*cdf0e10cSrcweir             pProvider->getAdditionalPropertySet( rContentId, sal_False ),
1121*cdf0e10cSrcweir             uno::UNO_QUERY );
1122*cdf0e10cSrcweir         xRow->appendPropertySet( xSet );
1123*cdf0e10cSrcweir     }
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir     return uno::Reference< sdbc::XRow >( xRow.get() );
1126*cdf0e10cSrcweir }
1127*cdf0e10cSrcweir 
1128*cdf0e10cSrcweir //=========================================================================
1129*cdf0e10cSrcweir uno::Reference< sdbc::XRow > HierarchyContent::getPropertyValues(
1130*cdf0e10cSrcweir                         const uno::Sequence< beans::Property >& rProperties )
1131*cdf0e10cSrcweir {
1132*cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
1133*cdf0e10cSrcweir     return getPropertyValues( m_xSMgr,
1134*cdf0e10cSrcweir                               rProperties,
1135*cdf0e10cSrcweir                               m_aProps,
1136*cdf0e10cSrcweir                               m_pProvider,
1137*cdf0e10cSrcweir                               m_xIdentifier->getContentIdentifier() );
1138*cdf0e10cSrcweir }
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir //=========================================================================
1141*cdf0e10cSrcweir uno::Sequence< uno::Any > HierarchyContent::setPropertyValues(
1142*cdf0e10cSrcweir         const uno::Sequence< beans::PropertyValue >& rValues,
1143*cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1144*cdf0e10cSrcweir     throw( uno::Exception )
1145*cdf0e10cSrcweir {
1146*cdf0e10cSrcweir     osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1147*cdf0e10cSrcweir 
1148*cdf0e10cSrcweir     uno::Sequence< uno::Any > aRet( rValues.getLength() );
1149*cdf0e10cSrcweir     uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() );
1150*cdf0e10cSrcweir     sal_Int32 nChanged = 0;
1151*cdf0e10cSrcweir 
1152*cdf0e10cSrcweir     beans::PropertyChangeEvent aEvent;
1153*cdf0e10cSrcweir     aEvent.Source         = static_cast< cppu::OWeakObject * >( this );
1154*cdf0e10cSrcweir     aEvent.Further        = sal_False;
1155*cdf0e10cSrcweir //    aEvent.PropertyName   =
1156*cdf0e10cSrcweir     aEvent.PropertyHandle = -1;
1157*cdf0e10cSrcweir //    aEvent.OldValue       =
1158*cdf0e10cSrcweir //    aEvent.NewValue       =
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir     const beans::PropertyValue* pValues = rValues.getConstArray();
1161*cdf0e10cSrcweir     sal_Int32 nCount = rValues.getLength();
1162*cdf0e10cSrcweir 
1163*cdf0e10cSrcweir     uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet;
1164*cdf0e10cSrcweir     sal_Bool bTriedToGetAdditonalPropSet = sal_False;
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir     sal_Bool bExchange = sal_False;
1167*cdf0e10cSrcweir     rtl::OUString aOldTitle;
1168*cdf0e10cSrcweir     rtl::OUString aOldName;
1169*cdf0e10cSrcweir     sal_Int32 nTitlePos = -1;
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n )
1172*cdf0e10cSrcweir     {
1173*cdf0e10cSrcweir         const beans::PropertyValue& rValue = pValues[ n ];
1174*cdf0e10cSrcweir 
1175*cdf0e10cSrcweir         if ( rValue.Name.equalsAsciiL(
1176*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM(  "ContentType" ) ) )
1177*cdf0e10cSrcweir         {
1178*cdf0e10cSrcweir             // Read-only property!
1179*cdf0e10cSrcweir             aRet[ n ] <<= lang::IllegalAccessException(
1180*cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1181*cdf0e10cSrcweir                                 "Property is read-only!" ),
1182*cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ) );
1183*cdf0e10cSrcweir         }
1184*cdf0e10cSrcweir         else if ( rValue.Name.equalsAsciiL(
1185*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) )
1186*cdf0e10cSrcweir         {
1187*cdf0e10cSrcweir             // Read-only property!
1188*cdf0e10cSrcweir             aRet[ n ] <<= lang::IllegalAccessException(
1189*cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1190*cdf0e10cSrcweir                                 "Property is read-only!" ),
1191*cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ) );
1192*cdf0e10cSrcweir         }
1193*cdf0e10cSrcweir         else if ( rValue.Name.equalsAsciiL(
1194*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) )
1195*cdf0e10cSrcweir         {
1196*cdf0e10cSrcweir             // Read-only property!
1197*cdf0e10cSrcweir             aRet[ n ] <<= lang::IllegalAccessException(
1198*cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1199*cdf0e10cSrcweir                                 "Property is read-only!" ),
1200*cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ) );
1201*cdf0e10cSrcweir         }
1202*cdf0e10cSrcweir         else if ( rValue.Name.equalsAsciiL(
1203*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) )
1204*cdf0e10cSrcweir         {
1205*cdf0e10cSrcweir             // Read-only property!
1206*cdf0e10cSrcweir             aRet[ n ] <<= lang::IllegalAccessException(
1207*cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1208*cdf0e10cSrcweir                                 "Property is read-only!" ),
1209*cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ) );
1210*cdf0e10cSrcweir         }
1211*cdf0e10cSrcweir         else if ( rValue.Name.equalsAsciiL(
1212*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
1213*cdf0e10cSrcweir         {
1214*cdf0e10cSrcweir             if ( isReadOnly() )
1215*cdf0e10cSrcweir             {
1216*cdf0e10cSrcweir                 aRet[ n ] <<= lang::IllegalAccessException(
1217*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1218*cdf0e10cSrcweir                                     "Property is read-only!" ),
1219*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1220*cdf0e10cSrcweir             }
1221*cdf0e10cSrcweir             else
1222*cdf0e10cSrcweir             {
1223*cdf0e10cSrcweir                 rtl::OUString aNewValue;
1224*cdf0e10cSrcweir                 if ( rValue.Value >>= aNewValue )
1225*cdf0e10cSrcweir                 {
1226*cdf0e10cSrcweir                     // No empty titles!
1227*cdf0e10cSrcweir                     if ( aNewValue.getLength() > 0 )
1228*cdf0e10cSrcweir                     {
1229*cdf0e10cSrcweir                         if ( aNewValue != m_aProps.getTitle() )
1230*cdf0e10cSrcweir                         {
1231*cdf0e10cSrcweir                             // modified title -> modified URL -> exchange !
1232*cdf0e10cSrcweir                             if ( m_eState == PERSISTENT )
1233*cdf0e10cSrcweir                                 bExchange = sal_True;
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir                             aOldTitle = m_aProps.getTitle();
1236*cdf0e10cSrcweir                             aOldName  = m_aProps.getName();
1237*cdf0e10cSrcweir 
1238*cdf0e10cSrcweir                             m_aProps.setTitle( aNewValue );
1239*cdf0e10cSrcweir                             m_aProps.setName(
1240*cdf0e10cSrcweir                                 ::ucb_impl::urihelper::encodeSegment(
1241*cdf0e10cSrcweir                                     aNewValue ) );
1242*cdf0e10cSrcweir 
1243*cdf0e10cSrcweir                             // property change event will be set later...
1244*cdf0e10cSrcweir 
1245*cdf0e10cSrcweir                             // remember position within sequence of values
1246*cdf0e10cSrcweir                             // (for error handling).
1247*cdf0e10cSrcweir                             nTitlePos = n;
1248*cdf0e10cSrcweir                         }
1249*cdf0e10cSrcweir                     }
1250*cdf0e10cSrcweir                     else
1251*cdf0e10cSrcweir                     {
1252*cdf0e10cSrcweir                         aRet[ n ] <<= lang::IllegalArgumentException(
1253*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
1254*cdf0e10cSrcweir                                             "Empty title not allowed!" ),
1255*cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
1256*cdf0e10cSrcweir                                     -1 );
1257*cdf0e10cSrcweir                     }
1258*cdf0e10cSrcweir                 }
1259*cdf0e10cSrcweir                 else
1260*cdf0e10cSrcweir                 {
1261*cdf0e10cSrcweir                     aRet[ n ] <<= beans::IllegalTypeException(
1262*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1263*cdf0e10cSrcweir                                         "Property value has wrong type!" ),
1264*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1265*cdf0e10cSrcweir                 }
1266*cdf0e10cSrcweir             }
1267*cdf0e10cSrcweir         }
1268*cdf0e10cSrcweir         else if ( rValue.Name.equalsAsciiL(
1269*cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "TargetURL" ) ) )
1270*cdf0e10cSrcweir         {
1271*cdf0e10cSrcweir             if ( isReadOnly() )
1272*cdf0e10cSrcweir             {
1273*cdf0e10cSrcweir                 aRet[ n ] <<= lang::IllegalAccessException(
1274*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1275*cdf0e10cSrcweir                                     "Property is read-only!" ),
1276*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1277*cdf0e10cSrcweir             }
1278*cdf0e10cSrcweir             else
1279*cdf0e10cSrcweir             {
1280*cdf0e10cSrcweir                 // TargetURL is only supported by links.
1281*cdf0e10cSrcweir 
1282*cdf0e10cSrcweir                 if ( m_eKind == LINK )
1283*cdf0e10cSrcweir                 {
1284*cdf0e10cSrcweir                     rtl::OUString aNewValue;
1285*cdf0e10cSrcweir                     if ( rValue.Value >>= aNewValue )
1286*cdf0e10cSrcweir                     {
1287*cdf0e10cSrcweir                         // No empty target URL's!
1288*cdf0e10cSrcweir                         if ( aNewValue.getLength() > 0 )
1289*cdf0e10cSrcweir                         {
1290*cdf0e10cSrcweir                             if ( aNewValue != m_aProps.getTargetURL() )
1291*cdf0e10cSrcweir                             {
1292*cdf0e10cSrcweir                                 aEvent.PropertyName = rValue.Name;
1293*cdf0e10cSrcweir                                 aEvent.OldValue
1294*cdf0e10cSrcweir                                     = uno::makeAny( m_aProps.getTargetURL() );
1295*cdf0e10cSrcweir                                 aEvent.NewValue
1296*cdf0e10cSrcweir                                     = uno::makeAny( aNewValue );
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir                                 aChanges.getArray()[ nChanged ] = aEvent;
1299*cdf0e10cSrcweir 
1300*cdf0e10cSrcweir                                 m_aProps.setTargetURL( aNewValue );
1301*cdf0e10cSrcweir                                 nChanged++;
1302*cdf0e10cSrcweir                             }
1303*cdf0e10cSrcweir                         }
1304*cdf0e10cSrcweir                         else
1305*cdf0e10cSrcweir                         {
1306*cdf0e10cSrcweir                             aRet[ n ] <<= lang::IllegalArgumentException(
1307*cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
1308*cdf0e10cSrcweir                                             "Empty target URL not allowed!" ),
1309*cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
1310*cdf0e10cSrcweir                                     -1 );
1311*cdf0e10cSrcweir                         }
1312*cdf0e10cSrcweir                     }
1313*cdf0e10cSrcweir                     else
1314*cdf0e10cSrcweir                     {
1315*cdf0e10cSrcweir                         aRet[ n ] <<= beans::IllegalTypeException(
1316*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1317*cdf0e10cSrcweir                                         "Property value has wrong type!" ),
1318*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1319*cdf0e10cSrcweir                     }
1320*cdf0e10cSrcweir                 }
1321*cdf0e10cSrcweir                 else
1322*cdf0e10cSrcweir                 {
1323*cdf0e10cSrcweir                     aRet[ n ] <<= beans::UnknownPropertyException(
1324*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1325*cdf0e10cSrcweir                                     "TargetURL only supported by links!" ),
1326*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1327*cdf0e10cSrcweir                 }
1328*cdf0e10cSrcweir             }
1329*cdf0e10cSrcweir         }
1330*cdf0e10cSrcweir         else
1331*cdf0e10cSrcweir         {
1332*cdf0e10cSrcweir             // Not a Core Property! Maybe it's an Additional Core Property?!
1333*cdf0e10cSrcweir 
1334*cdf0e10cSrcweir             if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() )
1335*cdf0e10cSrcweir             {
1336*cdf0e10cSrcweir                 xAdditionalPropSet = getAdditionalPropertySet( sal_False );
1337*cdf0e10cSrcweir                 bTriedToGetAdditonalPropSet = sal_True;
1338*cdf0e10cSrcweir             }
1339*cdf0e10cSrcweir 
1340*cdf0e10cSrcweir             if ( xAdditionalPropSet.is() )
1341*cdf0e10cSrcweir             {
1342*cdf0e10cSrcweir                 try
1343*cdf0e10cSrcweir                 {
1344*cdf0e10cSrcweir                     uno::Any aOldValue = xAdditionalPropSet->getPropertyValue(
1345*cdf0e10cSrcweir                                                                 rValue.Name );
1346*cdf0e10cSrcweir                     if ( aOldValue != rValue.Value )
1347*cdf0e10cSrcweir                     {
1348*cdf0e10cSrcweir                         xAdditionalPropSet->setPropertyValue(
1349*cdf0e10cSrcweir                                                 rValue.Name, rValue.Value );
1350*cdf0e10cSrcweir 
1351*cdf0e10cSrcweir                         aEvent.PropertyName = rValue.Name;
1352*cdf0e10cSrcweir                         aEvent.OldValue     = aOldValue;
1353*cdf0e10cSrcweir                         aEvent.NewValue     = rValue.Value;
1354*cdf0e10cSrcweir 
1355*cdf0e10cSrcweir                         aChanges.getArray()[ nChanged ] = aEvent;
1356*cdf0e10cSrcweir                         nChanged++;
1357*cdf0e10cSrcweir                     }
1358*cdf0e10cSrcweir                 }
1359*cdf0e10cSrcweir                 catch ( beans::UnknownPropertyException const & e )
1360*cdf0e10cSrcweir                 {
1361*cdf0e10cSrcweir                     aRet[ n ] <<= e;
1362*cdf0e10cSrcweir                 }
1363*cdf0e10cSrcweir                 catch ( lang::WrappedTargetException const & e )
1364*cdf0e10cSrcweir                 {
1365*cdf0e10cSrcweir                     aRet[ n ] <<= e;
1366*cdf0e10cSrcweir                 }
1367*cdf0e10cSrcweir                 catch ( beans::PropertyVetoException const & e )
1368*cdf0e10cSrcweir                 {
1369*cdf0e10cSrcweir                     aRet[ n ] <<= e;
1370*cdf0e10cSrcweir                 }
1371*cdf0e10cSrcweir                 catch ( lang::IllegalArgumentException const & e )
1372*cdf0e10cSrcweir                 {
1373*cdf0e10cSrcweir                     aRet[ n ] <<= e;
1374*cdf0e10cSrcweir                 }
1375*cdf0e10cSrcweir             }
1376*cdf0e10cSrcweir             else
1377*cdf0e10cSrcweir             {
1378*cdf0e10cSrcweir                 aRet[ n ] <<= uno::Exception(
1379*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1380*cdf0e10cSrcweir                                     "No property set for storing the value!" ),
1381*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1382*cdf0e10cSrcweir             }
1383*cdf0e10cSrcweir         }
1384*cdf0e10cSrcweir     }
1385*cdf0e10cSrcweir 
1386*cdf0e10cSrcweir     if ( bExchange )
1387*cdf0e10cSrcweir     {
1388*cdf0e10cSrcweir         uno::Reference< ucb::XContentIdentifier > xOldId
1389*cdf0e10cSrcweir             = m_xIdentifier;
1390*cdf0e10cSrcweir         uno::Reference< ucb::XContentIdentifier > xNewId
1391*cdf0e10cSrcweir             = makeNewIdentifier( m_aProps.getTitle() );
1392*cdf0e10cSrcweir 
1393*cdf0e10cSrcweir         aGuard.clear();
1394*cdf0e10cSrcweir         if ( exchangeIdentity( xNewId ) )
1395*cdf0e10cSrcweir         {
1396*cdf0e10cSrcweir             // Adapt persistent data.
1397*cdf0e10cSrcweir             renameData( xOldId, xNewId );
1398*cdf0e10cSrcweir 
1399*cdf0e10cSrcweir             // Adapt Additional Core Properties.
1400*cdf0e10cSrcweir             renameAdditionalPropertySet( xOldId->getContentIdentifier(),
1401*cdf0e10cSrcweir                                          xNewId->getContentIdentifier(),
1402*cdf0e10cSrcweir                                          sal_True );
1403*cdf0e10cSrcweir         }
1404*cdf0e10cSrcweir         else
1405*cdf0e10cSrcweir         {
1406*cdf0e10cSrcweir             // Roll-back.
1407*cdf0e10cSrcweir             m_aProps.setTitle( aOldTitle );
1408*cdf0e10cSrcweir             m_aProps.setName ( aOldName );
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir             aOldTitle = aOldName = rtl::OUString();
1411*cdf0e10cSrcweir 
1412*cdf0e10cSrcweir             // Set error .
1413*cdf0e10cSrcweir             aRet[ nTitlePos ] <<= uno::Exception(
1414*cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "Exchange failed!" ),
1415*cdf0e10cSrcweir                     static_cast< cppu::OWeakObject * >( this ) );
1416*cdf0e10cSrcweir         }
1417*cdf0e10cSrcweir     }
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir     if ( aOldTitle.getLength() )
1420*cdf0e10cSrcweir     {
1421*cdf0e10cSrcweir         aEvent.PropertyName = rtl::OUString::createFromAscii( "Title" );
1422*cdf0e10cSrcweir         aEvent.OldValue     = uno::makeAny( aOldTitle );
1423*cdf0e10cSrcweir         aEvent.NewValue     = uno::makeAny( m_aProps.getTitle() );
1424*cdf0e10cSrcweir 
1425*cdf0e10cSrcweir         aChanges.getArray()[ nChanged ] = aEvent;
1426*cdf0e10cSrcweir         nChanged++;
1427*cdf0e10cSrcweir     }
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir     if ( nChanged > 0 )
1430*cdf0e10cSrcweir     {
1431*cdf0e10cSrcweir         // Save changes, if content was already made persistent.
1432*cdf0e10cSrcweir         if ( !bExchange && ( m_eState == PERSISTENT ) )
1433*cdf0e10cSrcweir         {
1434*cdf0e10cSrcweir             if ( !storeData() )
1435*cdf0e10cSrcweir             {
1436*cdf0e10cSrcweir                 uno::Any aProps
1437*cdf0e10cSrcweir                     = uno::makeAny(
1438*cdf0e10cSrcweir                              beans::PropertyValue(
1439*cdf0e10cSrcweir                                  rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1440*cdf0e10cSrcweir                                      "Uri")),
1441*cdf0e10cSrcweir                                  -1,
1442*cdf0e10cSrcweir                                  uno::makeAny(m_xIdentifier->
1443*cdf0e10cSrcweir                                                   getContentIdentifier()),
1444*cdf0e10cSrcweir                                  beans::PropertyState_DIRECT_VALUE));
1445*cdf0e10cSrcweir                 ucbhelper::cancelCommandExecution(
1446*cdf0e10cSrcweir                     ucb::IOErrorCode_CANT_WRITE,
1447*cdf0e10cSrcweir                     uno::Sequence< uno::Any >(&aProps, 1),
1448*cdf0e10cSrcweir                     xEnv,
1449*cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
1450*cdf0e10cSrcweir                         "Cannot store persistent data!" ),
1451*cdf0e10cSrcweir                     this );
1452*cdf0e10cSrcweir                 // Unreachable
1453*cdf0e10cSrcweir             }
1454*cdf0e10cSrcweir         }
1455*cdf0e10cSrcweir 
1456*cdf0e10cSrcweir         aChanges.realloc( nChanged );
1457*cdf0e10cSrcweir 
1458*cdf0e10cSrcweir         aGuard.clear();
1459*cdf0e10cSrcweir         notifyPropertiesChange( aChanges );
1460*cdf0e10cSrcweir     }
1461*cdf0e10cSrcweir 
1462*cdf0e10cSrcweir     return aRet;
1463*cdf0e10cSrcweir }
1464*cdf0e10cSrcweir 
1465*cdf0e10cSrcweir //=========================================================================
1466*cdf0e10cSrcweir void HierarchyContent::insert( sal_Int32 nNameClashResolve,
1467*cdf0e10cSrcweir                                const uno::Reference<
1468*cdf0e10cSrcweir                                     ucb::XCommandEnvironment > & xEnv )
1469*cdf0e10cSrcweir     throw( uno::Exception )
1470*cdf0e10cSrcweir {
1471*cdf0e10cSrcweir     osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1472*cdf0e10cSrcweir 
1473*cdf0e10cSrcweir     // Am I the root folder?
1474*cdf0e10cSrcweir     if ( m_eKind == ROOT )
1475*cdf0e10cSrcweir     {
1476*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1477*cdf0e10cSrcweir             uno::makeAny( ucb::UnsupportedCommandException(
1478*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1479*cdf0e10cSrcweir                                     "Not supported by root folder!" ),
1480*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) ) ),
1481*cdf0e10cSrcweir             xEnv );
1482*cdf0e10cSrcweir         // Unreachable
1483*cdf0e10cSrcweir     }
1484*cdf0e10cSrcweir 
1485*cdf0e10cSrcweir     // Check, if all required properties were set.
1486*cdf0e10cSrcweir     if ( m_aProps.getTitle().getLength() == 0 )
1487*cdf0e10cSrcweir     {
1488*cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aProps( 1 );
1489*cdf0e10cSrcweir         aProps[ 0 ] = rtl::OUString::createFromAscii( "Title" );
1490*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1491*cdf0e10cSrcweir             uno::makeAny( ucb::MissingPropertiesException(
1492*cdf0e10cSrcweir                                 rtl::OUString(),
1493*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ),
1494*cdf0e10cSrcweir                                 aProps ) ),
1495*cdf0e10cSrcweir             xEnv );
1496*cdf0e10cSrcweir         // Unreachable
1497*cdf0e10cSrcweir     }
1498*cdf0e10cSrcweir 
1499*cdf0e10cSrcweir     // Assemble new content identifier...
1500*cdf0e10cSrcweir 
1501*cdf0e10cSrcweir     uno::Reference< ucb::XContentIdentifier > xId
1502*cdf0e10cSrcweir         = makeNewIdentifier( m_aProps.getTitle() );
1503*cdf0e10cSrcweir 
1504*cdf0e10cSrcweir     // Handle possible name clash...
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir     switch ( nNameClashResolve )
1507*cdf0e10cSrcweir     {
1508*cdf0e10cSrcweir         // fail.
1509*cdf0e10cSrcweir         case ucb::NameClash::ERROR:
1510*cdf0e10cSrcweir             if ( hasData( xId ) )
1511*cdf0e10cSrcweir             {
1512*cdf0e10cSrcweir                 ucbhelper::cancelCommandExecution(
1513*cdf0e10cSrcweir                     uno::makeAny(
1514*cdf0e10cSrcweir                         ucb::NameClashException(
1515*cdf0e10cSrcweir                             rtl::OUString(),
1516*cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ),
1517*cdf0e10cSrcweir                             task::InteractionClassification_ERROR,
1518*cdf0e10cSrcweir                             m_aProps.getTitle() ) ),
1519*cdf0e10cSrcweir                     xEnv );
1520*cdf0e10cSrcweir                 // Unreachable
1521*cdf0e10cSrcweir             }
1522*cdf0e10cSrcweir             break;
1523*cdf0e10cSrcweir 
1524*cdf0e10cSrcweir         // replace existing object.
1525*cdf0e10cSrcweir         case ucb::NameClash::OVERWRITE:
1526*cdf0e10cSrcweir             break;
1527*cdf0e10cSrcweir 
1528*cdf0e10cSrcweir         // "invent" a new valid title.
1529*cdf0e10cSrcweir         case ucb::NameClash::RENAME:
1530*cdf0e10cSrcweir             if ( hasData( xId ) )
1531*cdf0e10cSrcweir             {
1532*cdf0e10cSrcweir                 sal_Int32 nTry = 0;
1533*cdf0e10cSrcweir 
1534*cdf0e10cSrcweir                 do
1535*cdf0e10cSrcweir                 {
1536*cdf0e10cSrcweir                     rtl::OUString aNewId = xId->getContentIdentifier();
1537*cdf0e10cSrcweir                     aNewId += rtl::OUString::createFromAscii( "_" );
1538*cdf0e10cSrcweir                     aNewId += rtl::OUString::valueOf( ++nTry );
1539*cdf0e10cSrcweir                     xId = new ::ucbhelper::ContentIdentifier( m_xSMgr, aNewId );
1540*cdf0e10cSrcweir                 }
1541*cdf0e10cSrcweir                 while ( hasData( xId ) && ( nTry < 1000 ) );
1542*cdf0e10cSrcweir 
1543*cdf0e10cSrcweir                 if ( nTry == 1000 )
1544*cdf0e10cSrcweir                 {
1545*cdf0e10cSrcweir                     ucbhelper::cancelCommandExecution(
1546*cdf0e10cSrcweir                         uno::makeAny(
1547*cdf0e10cSrcweir                             ucb::UnsupportedNameClashException(
1548*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1549*cdf0e10cSrcweir                                     "Unable to resolve name clash!" ),
1550*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ),
1551*cdf0e10cSrcweir                                 nNameClashResolve ) ),
1552*cdf0e10cSrcweir                     xEnv );
1553*cdf0e10cSrcweir                 // Unreachable
1554*cdf0e10cSrcweir                 }
1555*cdf0e10cSrcweir                 else
1556*cdf0e10cSrcweir                 {
1557*cdf0e10cSrcweir                     rtl::OUString aNewTitle( m_aProps.getTitle() );
1558*cdf0e10cSrcweir                     aNewTitle += rtl::OUString::createFromAscii( "_" );
1559*cdf0e10cSrcweir                     aNewTitle += rtl::OUString::valueOf( nTry );
1560*cdf0e10cSrcweir                     m_aProps.setTitle( aNewTitle );
1561*cdf0e10cSrcweir                 }
1562*cdf0e10cSrcweir             }
1563*cdf0e10cSrcweir             break;
1564*cdf0e10cSrcweir 
1565*cdf0e10cSrcweir         case ucb::NameClash::KEEP: // deprecated
1566*cdf0e10cSrcweir         case ucb::NameClash::ASK:
1567*cdf0e10cSrcweir         default:
1568*cdf0e10cSrcweir             if ( hasData( xId ) )
1569*cdf0e10cSrcweir             {
1570*cdf0e10cSrcweir                 ucbhelper::cancelCommandExecution(
1571*cdf0e10cSrcweir                     uno::makeAny(
1572*cdf0e10cSrcweir                         ucb::UnsupportedNameClashException(
1573*cdf0e10cSrcweir                                 rtl::OUString(),
1574*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ),
1575*cdf0e10cSrcweir                                 nNameClashResolve ) ),
1576*cdf0e10cSrcweir                     xEnv );
1577*cdf0e10cSrcweir                 // Unreachable
1578*cdf0e10cSrcweir             }
1579*cdf0e10cSrcweir             break;
1580*cdf0e10cSrcweir     }
1581*cdf0e10cSrcweir 
1582*cdf0e10cSrcweir     // Identifier changed?
1583*cdf0e10cSrcweir     sal_Bool bNewId = ( xId->getContentIdentifier()
1584*cdf0e10cSrcweir                             != m_xIdentifier->getContentIdentifier() );
1585*cdf0e10cSrcweir     m_xIdentifier = xId;
1586*cdf0e10cSrcweir 
1587*cdf0e10cSrcweir     if ( !storeData() )
1588*cdf0e10cSrcweir     {
1589*cdf0e10cSrcweir         uno::Any aProps
1590*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
1591*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1592*cdf0e10cSrcweir                                                     "Uri")),
1593*cdf0e10cSrcweir                                   -1,
1594*cdf0e10cSrcweir                                   uno::makeAny(m_xIdentifier->
1595*cdf0e10cSrcweir                                                    getContentIdentifier()),
1596*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
1597*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1598*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_WRITE,
1599*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
1600*cdf0e10cSrcweir             xEnv,
1601*cdf0e10cSrcweir             rtl::OUString::createFromAscii( "Cannot store persistent data!" ),
1602*cdf0e10cSrcweir             this );
1603*cdf0e10cSrcweir         // Unreachable
1604*cdf0e10cSrcweir     }
1605*cdf0e10cSrcweir 
1606*cdf0e10cSrcweir     m_eState = PERSISTENT;
1607*cdf0e10cSrcweir 
1608*cdf0e10cSrcweir     if ( bNewId )
1609*cdf0e10cSrcweir     {
1610*cdf0e10cSrcweir         aGuard.clear();
1611*cdf0e10cSrcweir         inserted();
1612*cdf0e10cSrcweir     }
1613*cdf0e10cSrcweir }
1614*cdf0e10cSrcweir 
1615*cdf0e10cSrcweir //=========================================================================
1616*cdf0e10cSrcweir void HierarchyContent::destroy( sal_Bool bDeletePhysical,
1617*cdf0e10cSrcweir                                 const uno::Reference<
1618*cdf0e10cSrcweir                                     ucb::XCommandEnvironment > & xEnv )
1619*cdf0e10cSrcweir     throw( uno::Exception )
1620*cdf0e10cSrcweir {
1621*cdf0e10cSrcweir     // @@@ take care about bDeletePhysical -> trashcan support
1622*cdf0e10cSrcweir 
1623*cdf0e10cSrcweir     osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1624*cdf0e10cSrcweir 
1625*cdf0e10cSrcweir     uno::Reference< ucb::XContent > xThis = this;
1626*cdf0e10cSrcweir 
1627*cdf0e10cSrcweir     // Persistent?
1628*cdf0e10cSrcweir     if ( m_eState != PERSISTENT )
1629*cdf0e10cSrcweir     {
1630*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1631*cdf0e10cSrcweir             uno::makeAny( ucb::UnsupportedCommandException(
1632*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1633*cdf0e10cSrcweir                                     "Not persistent!" ),
1634*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) ) ),
1635*cdf0e10cSrcweir             xEnv );
1636*cdf0e10cSrcweir         // Unreachable
1637*cdf0e10cSrcweir     }
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir     // Am I the root folder?
1640*cdf0e10cSrcweir     if ( m_eKind == ROOT )
1641*cdf0e10cSrcweir     {
1642*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1643*cdf0e10cSrcweir             uno::makeAny( ucb::UnsupportedCommandException(
1644*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1645*cdf0e10cSrcweir                                     "Not supported by root folder!" ),
1646*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) ) ),
1647*cdf0e10cSrcweir             xEnv );
1648*cdf0e10cSrcweir         // Unreachable
1649*cdf0e10cSrcweir     }
1650*cdf0e10cSrcweir 
1651*cdf0e10cSrcweir     m_eState = DEAD;
1652*cdf0e10cSrcweir 
1653*cdf0e10cSrcweir     aGuard.clear();
1654*cdf0e10cSrcweir     deleted();
1655*cdf0e10cSrcweir 
1656*cdf0e10cSrcweir     if ( m_eKind == FOLDER )
1657*cdf0e10cSrcweir     {
1658*cdf0e10cSrcweir         // Process instanciated children...
1659*cdf0e10cSrcweir 
1660*cdf0e10cSrcweir         HierarchyContentRefList aChildren;
1661*cdf0e10cSrcweir         queryChildren( aChildren );
1662*cdf0e10cSrcweir 
1663*cdf0e10cSrcweir         HierarchyContentRefList::const_iterator it  = aChildren.begin();
1664*cdf0e10cSrcweir         HierarchyContentRefList::const_iterator end = aChildren.end();
1665*cdf0e10cSrcweir 
1666*cdf0e10cSrcweir         while ( it != end )
1667*cdf0e10cSrcweir         {
1668*cdf0e10cSrcweir             (*it)->destroy( bDeletePhysical, xEnv );
1669*cdf0e10cSrcweir             ++it;
1670*cdf0e10cSrcweir         }
1671*cdf0e10cSrcweir     }
1672*cdf0e10cSrcweir }
1673*cdf0e10cSrcweir 
1674*cdf0e10cSrcweir //=========================================================================
1675*cdf0e10cSrcweir void HierarchyContent::transfer(
1676*cdf0e10cSrcweir             const ucb::TransferInfo& rInfo,
1677*cdf0e10cSrcweir             const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1678*cdf0e10cSrcweir     throw( uno::Exception )
1679*cdf0e10cSrcweir {
1680*cdf0e10cSrcweir     osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
1681*cdf0e10cSrcweir 
1682*cdf0e10cSrcweir     // Persistent?
1683*cdf0e10cSrcweir     if ( m_eState != PERSISTENT )
1684*cdf0e10cSrcweir     {
1685*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1686*cdf0e10cSrcweir             uno::makeAny( ucb::UnsupportedCommandException(
1687*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1688*cdf0e10cSrcweir                                     "Not persistent!" ),
1689*cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) ) ),
1690*cdf0e10cSrcweir             xEnv );
1691*cdf0e10cSrcweir         // Unreachable
1692*cdf0e10cSrcweir     }
1693*cdf0e10cSrcweir 
1694*cdf0e10cSrcweir     // Is source a hierarchy content?
1695*cdf0e10cSrcweir     if ( ( rInfo.SourceURL.getLength() < HIERARCHY_URL_SCHEME_LENGTH + 2 ) ||
1696*cdf0e10cSrcweir          ( rInfo.SourceURL.compareToAscii( HIERARCHY_URL_SCHEME ":/",
1697*cdf0e10cSrcweir                                            HIERARCHY_URL_SCHEME_LENGTH + 2 )
1698*cdf0e10cSrcweir             != 0 ) )
1699*cdf0e10cSrcweir     {
1700*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1701*cdf0e10cSrcweir             uno::makeAny( ucb::InteractiveBadTransferURLException(
1702*cdf0e10cSrcweir                             rtl::OUString(),
1703*cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ) ) ),
1704*cdf0e10cSrcweir             xEnv );
1705*cdf0e10cSrcweir         // Unreachable
1706*cdf0e10cSrcweir     }
1707*cdf0e10cSrcweir 
1708*cdf0e10cSrcweir     // Is source not a parent of me / not me?
1709*cdf0e10cSrcweir     rtl::OUString aId = m_xIdentifier->getContentIdentifier();
1710*cdf0e10cSrcweir     sal_Int32 nPos = aId.lastIndexOf( '/' );
1711*cdf0e10cSrcweir     if ( nPos != ( aId.getLength() - 1 ) )
1712*cdf0e10cSrcweir     {
1713*cdf0e10cSrcweir         // No trailing slash found. Append.
1714*cdf0e10cSrcweir         aId += rtl::OUString::createFromAscii( "/" );
1715*cdf0e10cSrcweir     }
1716*cdf0e10cSrcweir 
1717*cdf0e10cSrcweir     if ( rInfo.SourceURL.getLength() <= aId.getLength() )
1718*cdf0e10cSrcweir     {
1719*cdf0e10cSrcweir         if ( aId.compareTo(
1720*cdf0e10cSrcweir                 rInfo.SourceURL, rInfo.SourceURL.getLength() ) == 0 )
1721*cdf0e10cSrcweir         {
1722*cdf0e10cSrcweir             uno::Any aProps
1723*cdf0e10cSrcweir                 = uno::makeAny(beans::PropertyValue(
1724*cdf0e10cSrcweir                                       rtl::OUString(
1725*cdf0e10cSrcweir                                           RTL_CONSTASCII_USTRINGPARAM("Uri")),
1726*cdf0e10cSrcweir                                       -1,
1727*cdf0e10cSrcweir                                       uno::makeAny(rInfo.SourceURL),
1728*cdf0e10cSrcweir                                       beans::PropertyState_DIRECT_VALUE));
1729*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
1730*cdf0e10cSrcweir                 ucb::IOErrorCode_RECURSIVE,
1731*cdf0e10cSrcweir                 uno::Sequence< uno::Any >(&aProps, 1),
1732*cdf0e10cSrcweir                 xEnv,
1733*cdf0e10cSrcweir                 rtl::OUString::createFromAscii(
1734*cdf0e10cSrcweir                     "Target is equal to or is a child of source!" ),
1735*cdf0e10cSrcweir                 this );
1736*cdf0e10cSrcweir             // Unreachable
1737*cdf0e10cSrcweir         }
1738*cdf0e10cSrcweir     }
1739*cdf0e10cSrcweir 
1740*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1741*cdf0e10cSrcweir     // 0) Obtain content object for source.
1742*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1743*cdf0e10cSrcweir 
1744*cdf0e10cSrcweir     uno::Reference< ucb::XContentIdentifier > xId
1745*cdf0e10cSrcweir         = new ::ucbhelper::ContentIdentifier( m_xSMgr, rInfo.SourceURL );
1746*cdf0e10cSrcweir 
1747*cdf0e10cSrcweir     // Note: The static cast is okay here, because its sure that
1748*cdf0e10cSrcweir     //       m_xProvider is always the HierarchyContentProvider.
1749*cdf0e10cSrcweir     rtl::Reference< HierarchyContent > xSource;
1750*cdf0e10cSrcweir 
1751*cdf0e10cSrcweir     try
1752*cdf0e10cSrcweir     {
1753*cdf0e10cSrcweir         xSource = static_cast< HierarchyContent * >(
1754*cdf0e10cSrcweir                         m_xProvider->queryContent( xId ).get() );
1755*cdf0e10cSrcweir     }
1756*cdf0e10cSrcweir     catch ( ucb::IllegalIdentifierException const & )
1757*cdf0e10cSrcweir     {
1758*cdf0e10cSrcweir         // queryContent
1759*cdf0e10cSrcweir     }
1760*cdf0e10cSrcweir 
1761*cdf0e10cSrcweir     if ( !xSource.is() )
1762*cdf0e10cSrcweir     {
1763*cdf0e10cSrcweir         uno::Any aProps
1764*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
1765*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1766*cdf0e10cSrcweir                                       "Uri")),
1767*cdf0e10cSrcweir                                   -1,
1768*cdf0e10cSrcweir                                   uno::makeAny(xId->getContentIdentifier()),
1769*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
1770*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1771*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_READ,
1772*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
1773*cdf0e10cSrcweir             xEnv,
1774*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
1775*cdf0e10cSrcweir                 "Cannot instanciate source object!" ),
1776*cdf0e10cSrcweir             this );
1777*cdf0e10cSrcweir         // Unreachable
1778*cdf0e10cSrcweir     }
1779*cdf0e10cSrcweir 
1780*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1781*cdf0e10cSrcweir     // 1) Create new child content.
1782*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1783*cdf0e10cSrcweir 
1784*cdf0e10cSrcweir     rtl::OUString aType = xSource->isFolder()
1785*cdf0e10cSrcweir         ? rtl::OUString::createFromAscii( HIERARCHY_FOLDER_CONTENT_TYPE )
1786*cdf0e10cSrcweir         : rtl::OUString::createFromAscii( HIERARCHY_LINK_CONTENT_TYPE );
1787*cdf0e10cSrcweir     ucb::ContentInfo aContentInfo;
1788*cdf0e10cSrcweir     aContentInfo.Type = aType;
1789*cdf0e10cSrcweir     aContentInfo.Attributes = 0;
1790*cdf0e10cSrcweir 
1791*cdf0e10cSrcweir     // Note: The static cast is okay here, because its sure that
1792*cdf0e10cSrcweir     //       createNewContent always creates a HierarchyContent.
1793*cdf0e10cSrcweir     rtl::Reference< HierarchyContent > xTarget
1794*cdf0e10cSrcweir         = static_cast< HierarchyContent * >(
1795*cdf0e10cSrcweir             createNewContent( aContentInfo ).get() );
1796*cdf0e10cSrcweir     if ( !xTarget.is() )
1797*cdf0e10cSrcweir     {
1798*cdf0e10cSrcweir         uno::Any aProps
1799*cdf0e10cSrcweir             = uno::makeAny(beans::PropertyValue(
1800*cdf0e10cSrcweir                                   rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1801*cdf0e10cSrcweir                                       "Folder")),
1802*cdf0e10cSrcweir                                   -1,
1803*cdf0e10cSrcweir                                   uno::makeAny(aId),
1804*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE));
1805*cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
1806*cdf0e10cSrcweir             ucb::IOErrorCode_CANT_CREATE,
1807*cdf0e10cSrcweir             uno::Sequence< uno::Any >(&aProps, 1),
1808*cdf0e10cSrcweir             xEnv,
1809*cdf0e10cSrcweir             rtl::OUString::createFromAscii(
1810*cdf0e10cSrcweir                 "XContentCreator::createNewContent failed!" ),
1811*cdf0e10cSrcweir             this );
1812*cdf0e10cSrcweir         // Unreachable
1813*cdf0e10cSrcweir     }
1814*cdf0e10cSrcweir 
1815*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1816*cdf0e10cSrcweir     // 2) Copy data from source content to child content.
1817*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1818*cdf0e10cSrcweir 
1819*cdf0e10cSrcweir     uno::Sequence< beans::Property > aSourceProps
1820*cdf0e10cSrcweir                     = xSource->getPropertySetInfo( xEnv )->getProperties();
1821*cdf0e10cSrcweir     sal_Int32 nCount = aSourceProps.getLength();
1822*cdf0e10cSrcweir 
1823*cdf0e10cSrcweir     if ( nCount )
1824*cdf0e10cSrcweir     {
1825*cdf0e10cSrcweir         sal_Bool bHadTitle = ( rInfo.NewTitle.getLength() == 0 );
1826*cdf0e10cSrcweir 
1827*cdf0e10cSrcweir         // Get all source values.
1828*cdf0e10cSrcweir         uno::Reference< sdbc::XRow > xRow
1829*cdf0e10cSrcweir             = xSource->getPropertyValues( aSourceProps );
1830*cdf0e10cSrcweir 
1831*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aValues( nCount );
1832*cdf0e10cSrcweir         beans::PropertyValue* pValues = aValues.getArray();
1833*cdf0e10cSrcweir 
1834*cdf0e10cSrcweir         const beans::Property* pProps = aSourceProps.getConstArray();
1835*cdf0e10cSrcweir         for ( sal_Int32 n = 0; n < nCount; ++n )
1836*cdf0e10cSrcweir         {
1837*cdf0e10cSrcweir             const beans::Property& rProp  = pProps[ n ];
1838*cdf0e10cSrcweir             beans::PropertyValue&  rValue = pValues[ n ];
1839*cdf0e10cSrcweir 
1840*cdf0e10cSrcweir             rValue.Name   = rProp.Name;
1841*cdf0e10cSrcweir             rValue.Handle = rProp.Handle;
1842*cdf0e10cSrcweir 
1843*cdf0e10cSrcweir             if ( !bHadTitle && rProp.Name.equalsAsciiL(
1844*cdf0e10cSrcweir                                 RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
1845*cdf0e10cSrcweir             {
1846*cdf0e10cSrcweir                 // Set new title instead of original.
1847*cdf0e10cSrcweir                 bHadTitle = sal_True;
1848*cdf0e10cSrcweir                 rValue.Value <<= rInfo.NewTitle;
1849*cdf0e10cSrcweir             }
1850*cdf0e10cSrcweir             else
1851*cdf0e10cSrcweir                 rValue.Value = xRow->getObject(
1852*cdf0e10cSrcweir                                 n + 1,
1853*cdf0e10cSrcweir                                 uno::Reference< container::XNameAccess >() );
1854*cdf0e10cSrcweir 
1855*cdf0e10cSrcweir             rValue.State = beans::PropertyState_DIRECT_VALUE;
1856*cdf0e10cSrcweir 
1857*cdf0e10cSrcweir             if ( rProp.Attributes & beans::PropertyAttribute::REMOVABLE )
1858*cdf0e10cSrcweir             {
1859*cdf0e10cSrcweir                 // Add Additional Core Property.
1860*cdf0e10cSrcweir                 try
1861*cdf0e10cSrcweir                 {
1862*cdf0e10cSrcweir                     xTarget->addProperty( rProp.Name,
1863*cdf0e10cSrcweir                                           rProp.Attributes,
1864*cdf0e10cSrcweir                                           rValue.Value );
1865*cdf0e10cSrcweir                 }
1866*cdf0e10cSrcweir                 catch ( beans::PropertyExistException const & )
1867*cdf0e10cSrcweir                 {
1868*cdf0e10cSrcweir                 }
1869*cdf0e10cSrcweir                 catch ( beans::IllegalTypeException const & )
1870*cdf0e10cSrcweir                 {
1871*cdf0e10cSrcweir                 }
1872*cdf0e10cSrcweir                 catch ( lang::IllegalArgumentException const & )
1873*cdf0e10cSrcweir                 {
1874*cdf0e10cSrcweir                 }
1875*cdf0e10cSrcweir             }
1876*cdf0e10cSrcweir         }
1877*cdf0e10cSrcweir 
1878*cdf0e10cSrcweir         // Set target values.
1879*cdf0e10cSrcweir         xTarget->setPropertyValues( aValues, xEnv );
1880*cdf0e10cSrcweir     }
1881*cdf0e10cSrcweir 
1882*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1883*cdf0e10cSrcweir     // 3) Commit (insert) child.
1884*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1885*cdf0e10cSrcweir 
1886*cdf0e10cSrcweir     xTarget->insert( rInfo.NameClash, xEnv );
1887*cdf0e10cSrcweir 
1888*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1889*cdf0e10cSrcweir     // 4) Transfer (copy) children of source.
1890*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1891*cdf0e10cSrcweir 
1892*cdf0e10cSrcweir     if ( xSource->isFolder() )
1893*cdf0e10cSrcweir     {
1894*cdf0e10cSrcweir         HierarchyEntry aFolder(
1895*cdf0e10cSrcweir             m_xSMgr, m_pProvider, xId->getContentIdentifier() );
1896*cdf0e10cSrcweir         HierarchyEntry::iterator it;
1897*cdf0e10cSrcweir 
1898*cdf0e10cSrcweir         while ( aFolder.next( it ) )
1899*cdf0e10cSrcweir         {
1900*cdf0e10cSrcweir             const HierarchyEntryData& rResult = *it;
1901*cdf0e10cSrcweir 
1902*cdf0e10cSrcweir             rtl::OUString aChildId = xId->getContentIdentifier();
1903*cdf0e10cSrcweir             if ( ( aChildId.lastIndexOf( '/' ) + 1 ) != aChildId.getLength() )
1904*cdf0e10cSrcweir                 aChildId += rtl::OUString::createFromAscii( "/" );
1905*cdf0e10cSrcweir 
1906*cdf0e10cSrcweir             aChildId += rResult.getName();
1907*cdf0e10cSrcweir 
1908*cdf0e10cSrcweir             ucb::TransferInfo aInfo;
1909*cdf0e10cSrcweir             aInfo.MoveData  = sal_False;
1910*cdf0e10cSrcweir             aInfo.NewTitle  = rtl::OUString();
1911*cdf0e10cSrcweir             aInfo.SourceURL = aChildId;
1912*cdf0e10cSrcweir             aInfo.NameClash = rInfo.NameClash;
1913*cdf0e10cSrcweir 
1914*cdf0e10cSrcweir             // Transfer child to target.
1915*cdf0e10cSrcweir             xTarget->transfer( aInfo, xEnv );
1916*cdf0e10cSrcweir         }
1917*cdf0e10cSrcweir     }
1918*cdf0e10cSrcweir 
1919*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1920*cdf0e10cSrcweir     // 5) Destroy source ( when moving only ) .
1921*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1922*cdf0e10cSrcweir 
1923*cdf0e10cSrcweir     if ( rInfo.MoveData )
1924*cdf0e10cSrcweir     {
1925*cdf0e10cSrcweir         xSource->destroy( sal_True, xEnv );
1926*cdf0e10cSrcweir 
1927*cdf0e10cSrcweir         // Remove all persistent data of source and its children.
1928*cdf0e10cSrcweir         if ( !xSource->removeData() )
1929*cdf0e10cSrcweir         {
1930*cdf0e10cSrcweir             uno::Any aProps
1931*cdf0e10cSrcweir                 = uno::makeAny(
1932*cdf0e10cSrcweir                          beans::PropertyValue(
1933*cdf0e10cSrcweir                              rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1934*cdf0e10cSrcweir                                                "Uri")),
1935*cdf0e10cSrcweir                              -1,
1936*cdf0e10cSrcweir                              uno::makeAny(
1937*cdf0e10cSrcweir                                  xSource->m_xIdentifier->
1938*cdf0e10cSrcweir                                               getContentIdentifier()),
1939*cdf0e10cSrcweir                              beans::PropertyState_DIRECT_VALUE));
1940*cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
1941*cdf0e10cSrcweir                 ucb::IOErrorCode_CANT_WRITE,
1942*cdf0e10cSrcweir                 uno::Sequence< uno::Any >(&aProps, 1),
1943*cdf0e10cSrcweir                 xEnv,
1944*cdf0e10cSrcweir                 rtl::OUString::createFromAscii(
1945*cdf0e10cSrcweir                     "Cannot remove persistent data of source object!" ),
1946*cdf0e10cSrcweir                 this );
1947*cdf0e10cSrcweir             // Unreachable
1948*cdf0e10cSrcweir         }
1949*cdf0e10cSrcweir 
1950*cdf0e10cSrcweir         // Remove own and all children's Additional Core Properties.
1951*cdf0e10cSrcweir         xSource->removeAdditionalPropertySet( sal_True );
1952*cdf0e10cSrcweir     }
1953*cdf0e10cSrcweir }
1954*cdf0e10cSrcweir 
1955*cdf0e10cSrcweir //=========================================================================
1956*cdf0e10cSrcweir //=========================================================================
1957*cdf0e10cSrcweir //
1958*cdf0e10cSrcweir // HierarchyContentProperties Implementation.
1959*cdf0e10cSrcweir //
1960*cdf0e10cSrcweir //=========================================================================
1961*cdf0e10cSrcweir //=========================================================================
1962*cdf0e10cSrcweir 
1963*cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo >
1964*cdf0e10cSrcweir HierarchyContentProperties::getCreatableContentsInfo() const
1965*cdf0e10cSrcweir {
1966*cdf0e10cSrcweir     if ( getIsFolder() )
1967*cdf0e10cSrcweir     {
1968*cdf0e10cSrcweir         uno::Sequence< ucb::ContentInfo > aSeq( 2 );
1969*cdf0e10cSrcweir 
1970*cdf0e10cSrcweir         // Folder.
1971*cdf0e10cSrcweir         aSeq.getArray()[ 0 ].Type
1972*cdf0e10cSrcweir             = rtl::OUString::createFromAscii( HIERARCHY_FOLDER_CONTENT_TYPE );
1973*cdf0e10cSrcweir         aSeq.getArray()[ 0 ].Attributes
1974*cdf0e10cSrcweir             = ucb::ContentInfoAttribute::KIND_FOLDER;
1975*cdf0e10cSrcweir 
1976*cdf0e10cSrcweir         uno::Sequence< beans::Property > aFolderProps( 1 );
1977*cdf0e10cSrcweir         aFolderProps.getArray()[ 0 ] = beans::Property(
1978*cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "Title" ),
1979*cdf0e10cSrcweir                     -1,
1980*cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
1981*cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND );
1982*cdf0e10cSrcweir         aSeq.getArray()[ 0 ].Properties = aFolderProps;
1983*cdf0e10cSrcweir 
1984*cdf0e10cSrcweir         // Link.
1985*cdf0e10cSrcweir         aSeq.getArray()[ 1 ].Type
1986*cdf0e10cSrcweir             = rtl::OUString::createFromAscii( HIERARCHY_LINK_CONTENT_TYPE );
1987*cdf0e10cSrcweir         aSeq.getArray()[ 1 ].Attributes
1988*cdf0e10cSrcweir             = ucb::ContentInfoAttribute::KIND_LINK;
1989*cdf0e10cSrcweir 
1990*cdf0e10cSrcweir         uno::Sequence< beans::Property > aLinkProps( 2 );
1991*cdf0e10cSrcweir         aLinkProps.getArray()[ 0 ] = beans::Property(
1992*cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "Title" ),
1993*cdf0e10cSrcweir                     -1,
1994*cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
1995*cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND );
1996*cdf0e10cSrcweir         aLinkProps.getArray()[ 1 ] = beans::Property(
1997*cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "TargetURL" ),
1998*cdf0e10cSrcweir                     -1,
1999*cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
2000*cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND );
2001*cdf0e10cSrcweir         aSeq.getArray()[ 1 ].Properties = aLinkProps;
2002*cdf0e10cSrcweir 
2003*cdf0e10cSrcweir         return aSeq;
2004*cdf0e10cSrcweir     }
2005*cdf0e10cSrcweir     else
2006*cdf0e10cSrcweir     {
2007*cdf0e10cSrcweir         return uno::Sequence< ucb::ContentInfo >( 0 );
2008*cdf0e10cSrcweir     }
2009*cdf0e10cSrcweir }
2010