xref: /trunk/main/ucb/source/ucp/webdav/webdavcontentcaps.cxx (revision 59ddfc10bd384e83978dcd8c83c4a7ba8f8fdec1)
12f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52f86921cSAndrew Rist  * distributed with this work for additional information
62f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
92f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142f86921cSAndrew Rist  * software distributed under the License is distributed on an
152f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
172f86921cSAndrew Rist  * specific language governing permissions and limitations
182f86921cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202f86921cSAndrew Rist  *************************************************************/
212f86921cSAndrew Rist 
222f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir /**************************************************************************
27cdf0e10cSrcweir                                TODO
28cdf0e10cSrcweir  **************************************************************************
29cdf0e10cSrcweir 
30cdf0e10cSrcweir  *************************************************************************/
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <set>
33cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp>
34cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
35cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
36cdf0e10cSrcweir #include <com/sun/star/ucb/CommandInfo.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfo.hpp>
38cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
39cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp>
40cdf0e10cSrcweir #include <com/sun/star/ucb/PostCommandArgument2.hpp>
41cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
42cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
43cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
44cdf0e10cSrcweir #include <com/sun/star/ucb/Lock.hpp>
45cdf0e10cSrcweir #include <com/sun/star/ucb/LockEntry.hpp>
46cdf0e10cSrcweir #include "webdavcontent.hxx"
47cdf0e10cSrcweir #include "webdavprovider.hxx"
48cdf0e10cSrcweir #include "DAVSession.hxx"
49cdf0e10cSrcweir #include "ContentProperties.hxx"
50cdf0e10cSrcweir 
51cdf0e10cSrcweir using namespace com::sun::star;
52*59ddfc10SAndre Fischer using namespace http_dav_ucp;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //=========================================================================
55cdf0e10cSrcweir //
56cdf0e10cSrcweir // ContentProvider implementation.
57cdf0e10cSrcweir //
58cdf0e10cSrcweir //=========================================================================
59cdf0e10cSrcweir 
60cdf0e10cSrcweir bool ContentProvider::getProperty(
61cdf0e10cSrcweir         const rtl::OUString & rPropName, beans::Property & rProp, bool bStrict )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     if ( !m_pProps )
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
66cdf0e10cSrcweir         if ( !m_pProps )
67cdf0e10cSrcweir         {
68cdf0e10cSrcweir             m_pProps = new PropertyMap;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
71cdf0e10cSrcweir             // Fill map of known properties...
72cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             // Mandatory UCB properties.
75cdf0e10cSrcweir             m_pProps->insert(
76cdf0e10cSrcweir                 beans::Property(
77cdf0e10cSrcweir                     rtl::OUString(
78cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
79cdf0e10cSrcweir                     -1,
80cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
81cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
82cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir             m_pProps->insert(
85cdf0e10cSrcweir                 beans::Property(
86cdf0e10cSrcweir                     rtl::OUString(
87cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
88cdf0e10cSrcweir                     -1,
89cdf0e10cSrcweir                     getCppuBooleanType(),
90cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
91cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir             m_pProps->insert(
94cdf0e10cSrcweir                 beans::Property(
95cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
96cdf0e10cSrcweir                     -1,
97cdf0e10cSrcweir                     getCppuBooleanType(),
98cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
99cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir             m_pProps->insert(
102cdf0e10cSrcweir                 beans::Property(
103cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
104cdf0e10cSrcweir                     -1,
105cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
106cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND ) );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir             // Optional UCB properties.
109cdf0e10cSrcweir 
110cdf0e10cSrcweir             m_pProps->insert(
111cdf0e10cSrcweir                 beans::Property(
112cdf0e10cSrcweir                     rtl::OUString(
113cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ),
114cdf0e10cSrcweir                     -1,
115cdf0e10cSrcweir                     getCppuType( static_cast< const util::DateTime * >( 0 ) ),
116cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
117cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir             m_pProps->insert(
120cdf0e10cSrcweir                 beans::Property(
121cdf0e10cSrcweir                     rtl::OUString(
122cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ),
123cdf0e10cSrcweir                     -1,
124cdf0e10cSrcweir                     getCppuType( static_cast< const util::DateTime * >( 0 ) ),
125cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
126cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             m_pProps->insert(
129cdf0e10cSrcweir                 beans::Property(
130cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
131cdf0e10cSrcweir                     -1,
132cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
133cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
134cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             m_pProps->insert(
137cdf0e10cSrcweir                 beans::Property(
138cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ),
139cdf0e10cSrcweir                     -1,
140cdf0e10cSrcweir                     getCppuType( static_cast< const sal_Int64 * >( 0 ) ),
141cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
142cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir             m_pProps->insert(
145cdf0e10cSrcweir                 beans::Property(
146cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ),
147cdf0e10cSrcweir                     -1,
148cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
149cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
150cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir             m_pProps->insert(
153cdf0e10cSrcweir                 beans::Property(
154cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
155cdf0e10cSrcweir                         "CreatableContentsInfo" ) ),
156cdf0e10cSrcweir                     -1,
157cdf0e10cSrcweir                     getCppuType( static_cast<
158cdf0e10cSrcweir                         const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
159cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
160cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir             // Standard DAV properties.
163cdf0e10cSrcweir 
164cdf0e10cSrcweir             m_pProps->insert(
165cdf0e10cSrcweir                 beans::Property(
166cdf0e10cSrcweir                     DAVProperties::CREATIONDATE,
167cdf0e10cSrcweir                     -1,
168cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
169cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
170cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir             m_pProps->insert(
173cdf0e10cSrcweir                 beans::Property(
174cdf0e10cSrcweir                     DAVProperties::DISPLAYNAME,
175cdf0e10cSrcweir                     -1,
176cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
177cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND ) );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir             m_pProps->insert(
180cdf0e10cSrcweir                 beans::Property(
181cdf0e10cSrcweir                     DAVProperties::GETCONTENTLANGUAGE,
182cdf0e10cSrcweir                     -1,
183cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
184cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
185cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir             m_pProps->insert(
188cdf0e10cSrcweir                 beans::Property(
189cdf0e10cSrcweir                     DAVProperties::GETCONTENTLENGTH,
190cdf0e10cSrcweir                     -1,
191cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
192cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
193cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
194cdf0e10cSrcweir 
195cdf0e10cSrcweir             m_pProps->insert(
196cdf0e10cSrcweir                 beans::Property(
197cdf0e10cSrcweir                     DAVProperties::GETCONTENTTYPE ,
198cdf0e10cSrcweir                     -1,
199cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
200cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
201cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir             m_pProps->insert(
204cdf0e10cSrcweir                 beans::Property(
205cdf0e10cSrcweir                     DAVProperties::GETETAG,
206cdf0e10cSrcweir                     -1,
207cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
208cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
209cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir             m_pProps->insert(
212cdf0e10cSrcweir                 beans::Property(
213cdf0e10cSrcweir                     DAVProperties::GETLASTMODIFIED,
214cdf0e10cSrcweir                     -1,
215cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
216cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
217cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir             m_pProps->insert(
220cdf0e10cSrcweir                 beans::Property(
221cdf0e10cSrcweir                     DAVProperties::LOCKDISCOVERY,
222cdf0e10cSrcweir                     -1,
223cdf0e10cSrcweir                     getCppuType( static_cast<
224cdf0e10cSrcweir                                     const uno::Sequence< ucb::Lock > * >( 0 ) ),
225cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
226cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
227cdf0e10cSrcweir 
228cdf0e10cSrcweir             m_pProps->insert(
229cdf0e10cSrcweir                 beans::Property(
230cdf0e10cSrcweir                     DAVProperties::RESOURCETYPE,
231cdf0e10cSrcweir                     -1,
232cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
233cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
234cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
235cdf0e10cSrcweir 
236cdf0e10cSrcweir             m_pProps->insert(
237cdf0e10cSrcweir                 beans::Property(
238cdf0e10cSrcweir                     DAVProperties::SUPPORTEDLOCK,
239cdf0e10cSrcweir                     -1,
240cdf0e10cSrcweir                     getCppuType( static_cast<
241cdf0e10cSrcweir                                     const uno::Sequence<
242cdf0e10cSrcweir                                         ucb::LockEntry > * >( 0 ) ),
243cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND
244cdf0e10cSrcweir                         | beans::PropertyAttribute::READONLY ) );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir             m_pProps->insert(
247cdf0e10cSrcweir                 beans::Property(
248cdf0e10cSrcweir                     DAVProperties::EXECUTABLE,
249cdf0e10cSrcweir                     -1,
250cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
251cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND ) );
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
256cdf0e10cSrcweir     // Lookup property.
257cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     beans::Property aProp;
260cdf0e10cSrcweir     aProp.Name = rPropName;
261cdf0e10cSrcweir     const PropertyMap::const_iterator it = m_pProps->find( aProp );
262cdf0e10cSrcweir     if ( it != m_pProps->end() )
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir         rProp = (*it);
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir     else
267cdf0e10cSrcweir     {
268cdf0e10cSrcweir         if ( bStrict )
269cdf0e10cSrcweir             return false;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         // All unknown props are treated as:
272cdf0e10cSrcweir         rProp = beans::Property(
273cdf0e10cSrcweir                     rPropName,
274cdf0e10cSrcweir                     - 1,
275cdf0e10cSrcweir                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
276cdf0e10cSrcweir                     beans::PropertyAttribute::BOUND );
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     return true;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir //=========================================================================
283cdf0e10cSrcweir //
284cdf0e10cSrcweir // Content implementation.
285cdf0e10cSrcweir //
286cdf0e10cSrcweir //=========================================================================
287cdf0e10cSrcweir 
288cdf0e10cSrcweir // virtual
289cdf0e10cSrcweir uno::Sequence< beans::Property > Content::getProperties(
290cdf0e10cSrcweir     const uno::Reference< ucb::XCommandEnvironment > & xEnv )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir     sal_Bool bTransient;
293cdf0e10cSrcweir     std::auto_ptr< DAVResourceAccess > xResAccess;
294cdf0e10cSrcweir     std::auto_ptr< ContentProperties > xCachedProps;
295cdf0e10cSrcweir     rtl::Reference< ContentProvider >  xProvider;
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
299cdf0e10cSrcweir 
300cdf0e10cSrcweir         bTransient = m_bTransient;
301cdf0e10cSrcweir         xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
302cdf0e10cSrcweir         if ( m_xCachedProps.get() )
303cdf0e10cSrcweir             xCachedProps.reset(
304cdf0e10cSrcweir                 new ContentProperties( *m_xCachedProps.get() ) );
305cdf0e10cSrcweir         xProvider.set( m_pProvider );
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     typedef std::set< rtl::OUString > StringSet;
309cdf0e10cSrcweir     StringSet aPropSet;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     // No server access for just created (not yet committed) objects.
312cdf0e10cSrcweir     // Only a minimal set of properties supported at this stage.
313cdf0e10cSrcweir     if ( !bTransient )
314cdf0e10cSrcweir     {
315cdf0e10cSrcweir         // Obtain all properties supported for this resource from server.
316cdf0e10cSrcweir         try
317cdf0e10cSrcweir         {
318cdf0e10cSrcweir             std::vector< DAVResourceInfo > props;
319cdf0e10cSrcweir             xResAccess->PROPFIND( DAVZERO, props, xEnv );
320cdf0e10cSrcweir 
321cdf0e10cSrcweir             // Note: vector always contains exactly one resource info, because
322cdf0e10cSrcweir             //       we used a depth of DAVZERO for PROPFIND.
323cdf0e10cSrcweir             aPropSet.insert( (*props.begin()).properties.begin(),
324cdf0e10cSrcweir                              (*props.begin()).properties.end() );
325cdf0e10cSrcweir         }
326cdf0e10cSrcweir         catch ( DAVException const & )
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir         }
329cdf0e10cSrcweir     }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir     // Add DAV properties, map DAV properties to UCB properties.
332cdf0e10cSrcweir     sal_Bool bHasCreationDate     = sal_False; // creationdate     <-> DateCreated
333cdf0e10cSrcweir     sal_Bool bHasGetLastModified  = sal_False; // getlastmodified  <-> DateModified
334cdf0e10cSrcweir     sal_Bool bHasGetContentType   = sal_False; // getcontenttype   <-> MediaType
335cdf0e10cSrcweir     sal_Bool bHasGetContentLength = sal_False; // getcontentlength <-> Size
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     sal_Bool bHasContentType      = sal_False;
338cdf0e10cSrcweir     sal_Bool bHasIsDocument       = sal_False;
339cdf0e10cSrcweir     sal_Bool bHasIsFolder         = sal_False;
340cdf0e10cSrcweir     sal_Bool bHasTitle            = sal_False;
341cdf0e10cSrcweir     sal_Bool bHasBaseURI          = sal_False;
342cdf0e10cSrcweir     sal_Bool bHasDateCreated      = sal_False;
343cdf0e10cSrcweir     sal_Bool bHasDateModified     = sal_False;
344cdf0e10cSrcweir     sal_Bool bHasMediaType        = sal_False;
345cdf0e10cSrcweir     sal_Bool bHasSize             = sal_False;
346cdf0e10cSrcweir     sal_Bool bHasCreatableInfos   = sal_False;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         std::set< rtl::OUString >::const_iterator it  = aPropSet.begin();
350cdf0e10cSrcweir         std::set< rtl::OUString >::const_iterator end = aPropSet.end();
351cdf0e10cSrcweir         while ( it != end )
352cdf0e10cSrcweir         {
353cdf0e10cSrcweir             if ( !bHasCreationDate &&
354cdf0e10cSrcweir                  ( (*it) == DAVProperties::CREATIONDATE ) )
355cdf0e10cSrcweir             {
356cdf0e10cSrcweir                 bHasCreationDate = sal_True;
357cdf0e10cSrcweir             }
358cdf0e10cSrcweir             else if ( !bHasGetLastModified &&
359cdf0e10cSrcweir                       ( (*it) == DAVProperties::GETLASTMODIFIED ) )
360cdf0e10cSrcweir             {
361cdf0e10cSrcweir                 bHasGetLastModified = sal_True;
362cdf0e10cSrcweir             }
363cdf0e10cSrcweir             else if ( !bHasGetContentType &&
364cdf0e10cSrcweir                       ( (*it) == DAVProperties::GETCONTENTTYPE ) )
365cdf0e10cSrcweir             {
366cdf0e10cSrcweir                 bHasGetContentType = sal_True;
367cdf0e10cSrcweir             }
368cdf0e10cSrcweir             else if ( !bHasGetContentLength &&
369cdf0e10cSrcweir                       ( (*it) == DAVProperties::GETCONTENTLENGTH ) )
370cdf0e10cSrcweir             {
371cdf0e10cSrcweir                 bHasGetContentLength = sal_True;
372cdf0e10cSrcweir             }
373cdf0e10cSrcweir             else if ( !bHasContentType &&
374cdf0e10cSrcweir                       (*it).equalsAsciiL(
375cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) )
376cdf0e10cSrcweir             {
377cdf0e10cSrcweir                 bHasContentType = sal_True;
378cdf0e10cSrcweir             }
379cdf0e10cSrcweir             else if ( !bHasIsDocument &&
380cdf0e10cSrcweir                       (*it).equalsAsciiL(
381cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) )
382cdf0e10cSrcweir             {
383cdf0e10cSrcweir                 bHasIsDocument = sal_True;
384cdf0e10cSrcweir             }
385cdf0e10cSrcweir             else if ( !bHasIsFolder &&
386cdf0e10cSrcweir                       (*it).equalsAsciiL(
387cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) )
388cdf0e10cSrcweir             {
389cdf0e10cSrcweir                 bHasIsFolder = sal_True;
390cdf0e10cSrcweir             }
391cdf0e10cSrcweir             else if ( !bHasTitle &&
392cdf0e10cSrcweir                       (*it).equalsAsciiL(
393cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
394cdf0e10cSrcweir             {
395cdf0e10cSrcweir                 bHasTitle = sal_True;
396cdf0e10cSrcweir             }
397cdf0e10cSrcweir             else if ( !bHasBaseURI &&
398cdf0e10cSrcweir                       (*it).equalsAsciiL(
399cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "BaseURI" ) ) )
400cdf0e10cSrcweir             {
401cdf0e10cSrcweir                 bHasBaseURI = sal_True;
402cdf0e10cSrcweir             }
403cdf0e10cSrcweir             else if ( !bHasDateCreated &&
404cdf0e10cSrcweir                       (*it).equalsAsciiL(
405cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) ) )
406cdf0e10cSrcweir             {
407cdf0e10cSrcweir                 bHasDateCreated = sal_True;
408cdf0e10cSrcweir             }
409cdf0e10cSrcweir             else if ( !bHasDateModified &&
410cdf0e10cSrcweir                       (*it).equalsAsciiL(
411cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) )
412cdf0e10cSrcweir             {
413cdf0e10cSrcweir                 bHasDateModified = sal_True;
414cdf0e10cSrcweir             }
415cdf0e10cSrcweir             else if ( !bHasMediaType &&
416cdf0e10cSrcweir                       (*it).equalsAsciiL(
417cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
418cdf0e10cSrcweir             {
419cdf0e10cSrcweir                 bHasMediaType = sal_True;
420cdf0e10cSrcweir             }
421cdf0e10cSrcweir             else if ( !bHasSize &&
422cdf0e10cSrcweir                       (*it).equalsAsciiL(
423cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM( "Size" ) ) )
424cdf0e10cSrcweir             {
425cdf0e10cSrcweir                 bHasSize = sal_True;
426cdf0e10cSrcweir             }
427cdf0e10cSrcweir             else if ( !bHasCreatableInfos &&
428cdf0e10cSrcweir                       (*it).equalsAsciiL(
429cdf0e10cSrcweir                             RTL_CONSTASCII_STRINGPARAM(
430cdf0e10cSrcweir                                 "CreatableContentsInfo" ) ) )
431cdf0e10cSrcweir             {
432cdf0e10cSrcweir                 bHasCreatableInfos = sal_True;
433cdf0e10cSrcweir             }
434cdf0e10cSrcweir             it++;
435cdf0e10cSrcweir         }
436cdf0e10cSrcweir     }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir     // Add mandatory properties.
439cdf0e10cSrcweir     if ( !bHasContentType )
440cdf0e10cSrcweir         aPropSet.insert(
441cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ) );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir     if ( !bHasIsDocument )
444cdf0e10cSrcweir         aPropSet.insert(
445cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ) );
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     if ( !bHasIsFolder )
448cdf0e10cSrcweir         aPropSet.insert(
449cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ) );
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     if ( !bHasTitle )
452cdf0e10cSrcweir     {
453cdf0e10cSrcweir         // Always present since it can be calculated from content's URI.
454cdf0e10cSrcweir         aPropSet.insert(
455cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ) );
456cdf0e10cSrcweir     }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     // Add optional properties.
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     if ( !bHasBaseURI )
461cdf0e10cSrcweir     {
462cdf0e10cSrcweir         // Always present since it can be calculated from content's URI.
463cdf0e10cSrcweir         aPropSet.insert(
464cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ) );
465cdf0e10cSrcweir     }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir     if ( !bHasDateCreated && bHasCreationDate )
468cdf0e10cSrcweir         aPropSet.insert(
469cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ) );
470cdf0e10cSrcweir 
471cdf0e10cSrcweir     if ( !bHasDateModified && bHasGetLastModified )
472cdf0e10cSrcweir         aPropSet.insert(
473cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ) );
474cdf0e10cSrcweir 
475cdf0e10cSrcweir     if ( !bHasMediaType && bHasGetContentType )
476cdf0e10cSrcweir         aPropSet.insert(
477cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) );
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     if ( !bHasSize && bHasGetContentLength )
480cdf0e10cSrcweir         aPropSet.insert(
481cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ) );
482cdf0e10cSrcweir 
483cdf0e10cSrcweir     if ( !bHasCreatableInfos )
484cdf0e10cSrcweir         aPropSet.insert(
485cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
486cdf0e10cSrcweir                 "CreatableContentsInfo" ) ) );
487cdf0e10cSrcweir 
488cdf0e10cSrcweir     // Add cached properties, if present and still missing.
489cdf0e10cSrcweir     if ( xCachedProps.get() )
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         const std::set< rtl::OUString >::const_iterator set_end
492cdf0e10cSrcweir             = aPropSet.end();
493cdf0e10cSrcweir 
494cdf0e10cSrcweir         const std::auto_ptr< PropertyValueMap > & xProps
495cdf0e10cSrcweir             = xCachedProps->getProperties();
496cdf0e10cSrcweir 
497cdf0e10cSrcweir         PropertyValueMap::const_iterator       map_it  = xProps->begin();
498cdf0e10cSrcweir         const PropertyValueMap::const_iterator map_end = xProps->end();
499cdf0e10cSrcweir 
500cdf0e10cSrcweir         while ( map_it != map_end )
501cdf0e10cSrcweir         {
502cdf0e10cSrcweir             if ( aPropSet.find( (*map_it).first ) == set_end )
503cdf0e10cSrcweir                 aPropSet.insert( (*map_it).first );
504cdf0e10cSrcweir 
505cdf0e10cSrcweir             ++map_it;
506cdf0e10cSrcweir         }
507cdf0e10cSrcweir     }
508cdf0e10cSrcweir 
509cdf0e10cSrcweir     // std::set -> uno::Sequence
510cdf0e10cSrcweir     sal_Int32 nCount = aPropSet.size();
511cdf0e10cSrcweir     uno::Sequence< beans::Property > aProperties( nCount );
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     std::set< rtl::OUString >::const_iterator it = aPropSet.begin();
514cdf0e10cSrcweir     beans::Property aProp;
515cdf0e10cSrcweir 
516cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n, ++it )
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir         xProvider->getProperty( (*it), aProp );
519cdf0e10cSrcweir         aProperties[ n ] = aProp;
520cdf0e10cSrcweir     }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir     return aProperties;
523cdf0e10cSrcweir }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir //=========================================================================
526cdf0e10cSrcweir // virtual
527cdf0e10cSrcweir uno::Sequence< ucb::CommandInfo > Content::getCommands(
528cdf0e10cSrcweir     const uno::Reference< ucb::XCommandEnvironment > & xEnv )
529cdf0e10cSrcweir {
530cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
531cdf0e10cSrcweir 
532cdf0e10cSrcweir     uno::Sequence< ucb::CommandInfo > aCmdInfo( 8 );
533cdf0e10cSrcweir 
534cdf0e10cSrcweir     ///////////////////////////////////////////////////////////////
535cdf0e10cSrcweir     // Mandatory commands
536cdf0e10cSrcweir     ///////////////////////////////////////////////////////////////
537cdf0e10cSrcweir 
538cdf0e10cSrcweir     aCmdInfo[ 0 ] =
539cdf0e10cSrcweir             ucb::CommandInfo(
540cdf0e10cSrcweir                 rtl::OUString(
541cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
542cdf0e10cSrcweir                 -1,
543cdf0e10cSrcweir                 getCppuVoidType() );
544cdf0e10cSrcweir     aCmdInfo[ 1 ] =
545cdf0e10cSrcweir             ucb::CommandInfo(
546cdf0e10cSrcweir                 rtl::OUString(
547cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
548cdf0e10cSrcweir                 -1,
549cdf0e10cSrcweir                 getCppuVoidType() );
550cdf0e10cSrcweir     aCmdInfo[ 2 ] =
551cdf0e10cSrcweir             ucb::CommandInfo(
552cdf0e10cSrcweir                 rtl::OUString(
553cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
554cdf0e10cSrcweir                 -1,
555cdf0e10cSrcweir                 getCppuType( static_cast<
556cdf0e10cSrcweir                                 uno::Sequence< beans::Property > * >( 0 ) ) );
557cdf0e10cSrcweir     aCmdInfo[ 3 ] =
558cdf0e10cSrcweir             ucb::CommandInfo(
559cdf0e10cSrcweir                 rtl::OUString(
560cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
561cdf0e10cSrcweir                 -1,
562cdf0e10cSrcweir                 getCppuType( static_cast<
563cdf0e10cSrcweir                     uno::Sequence< beans::PropertyValue > * >( 0 ) ) );
564cdf0e10cSrcweir 
565cdf0e10cSrcweir     ///////////////////////////////////////////////////////////////
566cdf0e10cSrcweir     // Optional standard commands
567cdf0e10cSrcweir     ///////////////////////////////////////////////////////////////
568cdf0e10cSrcweir 
569cdf0e10cSrcweir     aCmdInfo[ 4 ] =
570cdf0e10cSrcweir             ucb::CommandInfo(
571cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
572cdf0e10cSrcweir                 -1,
573cdf0e10cSrcweir                 getCppuBooleanType() );
574cdf0e10cSrcweir     aCmdInfo[ 5 ] =
575cdf0e10cSrcweir             ucb::CommandInfo(
576cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
577cdf0e10cSrcweir                 -1,
578cdf0e10cSrcweir                 getCppuType( static_cast<
579cdf0e10cSrcweir                     ucb::InsertCommandArgument * >( 0 ) ) );
580cdf0e10cSrcweir     aCmdInfo[ 6 ] =
581cdf0e10cSrcweir             ucb::CommandInfo(
582cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
583cdf0e10cSrcweir                 -1,
584cdf0e10cSrcweir                 getCppuType( static_cast<
585cdf0e10cSrcweir                     ucb::OpenCommandArgument2 * >( 0 ) ) );
586cdf0e10cSrcweir 
587cdf0e10cSrcweir     ///////////////////////////////////////////////////////////////
588cdf0e10cSrcweir     // New commands
589cdf0e10cSrcweir     ///////////////////////////////////////////////////////////////
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     aCmdInfo[ 7 ] =
592cdf0e10cSrcweir             ucb::CommandInfo(
593cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "post" ) ),
594cdf0e10cSrcweir                 -1,
595cdf0e10cSrcweir                 getCppuType( static_cast<
596cdf0e10cSrcweir                     ucb::PostCommandArgument2 * >( 0 ) ) );
597cdf0e10cSrcweir 
598cdf0e10cSrcweir     sal_Bool bFolder = sal_False;
599cdf0e10cSrcweir 
600cdf0e10cSrcweir     try
601cdf0e10cSrcweir     {
602cdf0e10cSrcweir         bFolder = isFolder( xEnv );
603cdf0e10cSrcweir     }
604cdf0e10cSrcweir     catch ( uno::Exception const & )
605cdf0e10cSrcweir     {
606cdf0e10cSrcweir         return aCmdInfo;
607cdf0e10cSrcweir     }
608cdf0e10cSrcweir 
609cdf0e10cSrcweir     sal_Bool bSupportsLocking = supportsExclusiveWriteLock( xEnv );
610cdf0e10cSrcweir 
611cdf0e10cSrcweir     sal_Int32 nPos = aCmdInfo.getLength();
612cdf0e10cSrcweir     sal_Int32 nMoreCmds = ( bFolder ? 2 : 0 ) + ( bSupportsLocking ? 2 : 0 );
613cdf0e10cSrcweir     if ( nMoreCmds )
614cdf0e10cSrcweir         aCmdInfo.realloc( nPos + nMoreCmds );
615cdf0e10cSrcweir     else
616cdf0e10cSrcweir         return aCmdInfo;
617cdf0e10cSrcweir 
618cdf0e10cSrcweir     if ( bFolder )
619cdf0e10cSrcweir     {
620cdf0e10cSrcweir         ///////////////////////////////////////////////////////////////
621cdf0e10cSrcweir         // Optional standard commands
622cdf0e10cSrcweir         ///////////////////////////////////////////////////////////////
623cdf0e10cSrcweir 
624cdf0e10cSrcweir         aCmdInfo[ nPos ] =
625cdf0e10cSrcweir             ucb::CommandInfo(
626cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
627cdf0e10cSrcweir                 -1,
628cdf0e10cSrcweir                 getCppuType( static_cast< ucb::TransferInfo * >( 0 ) ) );
629cdf0e10cSrcweir         nPos++;
630cdf0e10cSrcweir         aCmdInfo[ nPos ] =
631cdf0e10cSrcweir             ucb::CommandInfo(
632cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
633cdf0e10cSrcweir                     "createNewContent" ) ),
634cdf0e10cSrcweir                 -1,
635cdf0e10cSrcweir                 getCppuType( static_cast< ucb::ContentInfo * >( 0 ) ) );
636cdf0e10cSrcweir         nPos++;
637cdf0e10cSrcweir     }
638cdf0e10cSrcweir     else
639cdf0e10cSrcweir     {
640cdf0e10cSrcweir         // no document-only commands at the moment.
641cdf0e10cSrcweir     }
642cdf0e10cSrcweir 
643cdf0e10cSrcweir     if ( bSupportsLocking )
644cdf0e10cSrcweir     {
645cdf0e10cSrcweir         aCmdInfo[ nPos ] =
646cdf0e10cSrcweir             ucb::CommandInfo(
647cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "lock" ) ),
648cdf0e10cSrcweir                 -1,
649cdf0e10cSrcweir                 getCppuVoidType() );
650cdf0e10cSrcweir         nPos++;
651cdf0e10cSrcweir         aCmdInfo[ nPos ] =
652cdf0e10cSrcweir             ucb::CommandInfo(
653cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unlock" ) ),
654cdf0e10cSrcweir                 -1,
655cdf0e10cSrcweir                 getCppuVoidType() );
656cdf0e10cSrcweir         nPos++;
657cdf0e10cSrcweir     }
658cdf0e10cSrcweir     return aCmdInfo;
659cdf0e10cSrcweir }
660