xref: /AOO41X/main/ucb/source/ucp/webdav/webdavcontent.cxx (revision c5b3447da367a731f6d69a171c8dc62484fbd13b)
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 /**************************************************************************
28cdf0e10cSrcweir                                   TODO
29cdf0e10cSrcweir  **************************************************************************
30cdf0e10cSrcweir 
31cdf0e10cSrcweir  *************************************************************************/
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <osl/diagnose.h>
34cdf0e10cSrcweir #include "osl/doublecheckedlocking.h"
35cdf0e10cSrcweir #include <rtl/uri.hxx>
36cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
37cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
38cdf0e10cSrcweir #include <ucbhelper/propertyvalueset.hxx>
39cdf0e10cSrcweir #include <ucbhelper/simpleinteractionrequest.hxx>
40cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
43cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChange.hpp>
44cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChangeEvent.hpp>
45cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
46cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
47cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
48cdf0e10cSrcweir #include <com/sun/star/lang/IllegalAccessException.hpp>
49cdf0e10cSrcweir #include <com/sun/star/task/PasswordContainerInteractionHandler.hpp>
50cdf0e10cSrcweir #include <com/sun/star/ucb/CommandEnvironment.hpp>
51cdf0e10cSrcweir #include <com/sun/star/ucb/CommandFailedException.hpp>
52cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
53cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp>
54cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
55cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
56cdf0e10cSrcweir #include "com/sun/star/ucb/InteractiveLockingLockedException.hpp"
57cdf0e10cSrcweir #include "com/sun/star/ucb/InteractiveLockingLockExpiredException.hpp"
58cdf0e10cSrcweir #include "com/sun/star/ucb/InteractiveLockingNotLockedException.hpp"
59cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp>
60cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkGeneralException.hpp>
61cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkReadException.hpp>
62cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
63cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp>
64cdf0e10cSrcweir #include <com/sun/star/ucb/MissingInputStreamException.hpp>
65cdf0e10cSrcweir #include <com/sun/star/ucb/MissingPropertiesException.hpp>
66cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
67cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp>
68cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
69cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
70cdf0e10cSrcweir #include <com/sun/star/ucb/PostCommandArgument2.hpp>
71cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
72cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
73cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
74cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
75cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
76cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
77cdf0e10cSrcweir #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
78cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
79cdf0e10cSrcweir 
80cdf0e10cSrcweir #include "webdavcontent.hxx"
81cdf0e10cSrcweir #include "webdavprovider.hxx"
82cdf0e10cSrcweir #include "webdavresultset.hxx"
83cdf0e10cSrcweir #include "ContentProperties.hxx"
8459ddfc10SAndre Fischer #include "SerfUri.hxx"
85cdf0e10cSrcweir #include "UCBDeadPropertyValue.hxx"
86cdf0e10cSrcweir 
87cdf0e10cSrcweir using namespace com::sun::star;
8859ddfc10SAndre Fischer using namespace http_dav_ucp;
89cdf0e10cSrcweir 
90*c5b3447dSAriel Constenla-Haile namespace
91*c5b3447dSAriel Constenla-Haile {
92*c5b3447dSAriel Constenla-Haile static void lcl_sendPartialGETRequest( bool &bError,
93*c5b3447dSAriel Constenla-Haile                                        DAVException &aLastException,
94*c5b3447dSAriel Constenla-Haile                                        const std::vector< rtl::OUString > aProps,
95*c5b3447dSAriel Constenla-Haile                                        std::vector< rtl::OUString > &aHeaderNames,
96*c5b3447dSAriel Constenla-Haile                                        const std::auto_ptr< DAVResourceAccess > &xResAccess,
97*c5b3447dSAriel Constenla-Haile                                        std::auto_ptr< ContentProperties > &xProps,
98*c5b3447dSAriel Constenla-Haile                                        const uno::Reference< ucb::XCommandEnvironment >& xEnv )
99*c5b3447dSAriel Constenla-Haile {
100*c5b3447dSAriel Constenla-Haile     bool bIsRequestSize = false;
101*c5b3447dSAriel Constenla-Haile     DAVResource aResource;
102*c5b3447dSAriel Constenla-Haile     DAVRequestHeaders aPartialGet;
103*c5b3447dSAriel Constenla-Haile     aPartialGet.push_back(
104*c5b3447dSAriel Constenla-Haile         DAVRequestHeader(
105*c5b3447dSAriel Constenla-Haile             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Range" ) ),
106*c5b3447dSAriel Constenla-Haile             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "bytes=0-0" ))));
107*c5b3447dSAriel Constenla-Haile 
108*c5b3447dSAriel Constenla-Haile     for ( std::vector< rtl::OUString >::const_iterator it = aHeaderNames.begin();
109*c5b3447dSAriel Constenla-Haile             it != aHeaderNames.end(); it++ )
110*c5b3447dSAriel Constenla-Haile     {
111*c5b3447dSAriel Constenla-Haile         if ( it->equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
112*c5b3447dSAriel Constenla-Haile         {
113*c5b3447dSAriel Constenla-Haile             bIsRequestSize = true;
114*c5b3447dSAriel Constenla-Haile             break;
115*c5b3447dSAriel Constenla-Haile         }
116*c5b3447dSAriel Constenla-Haile     }
117*c5b3447dSAriel Constenla-Haile 
118*c5b3447dSAriel Constenla-Haile     if ( bIsRequestSize )
119*c5b3447dSAriel Constenla-Haile     {
120*c5b3447dSAriel Constenla-Haile         // we need to know if the server accepts range requests for a resource
121*c5b3447dSAriel Constenla-Haile         // and the range unit it uses
122*c5b3447dSAriel Constenla-Haile         aHeaderNames.push_back( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Accept-Ranges" ) ) );
123*c5b3447dSAriel Constenla-Haile         aHeaderNames.push_back( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Content-Range" ) ) );
124*c5b3447dSAriel Constenla-Haile     }
125*c5b3447dSAriel Constenla-Haile     try
126*c5b3447dSAriel Constenla-Haile     {
127*c5b3447dSAriel Constenla-Haile         uno::Reference< io::XInputStream > xIn = xResAccess->GET( aPartialGet,
128*c5b3447dSAriel Constenla-Haile                                                                   aHeaderNames,
129*c5b3447dSAriel Constenla-Haile                                                                   aResource,
130*c5b3447dSAriel Constenla-Haile                                                                   xEnv );
131*c5b3447dSAriel Constenla-Haile         bError = false;
132*c5b3447dSAriel Constenla-Haile 
133*c5b3447dSAriel Constenla-Haile         if ( bIsRequestSize )
134*c5b3447dSAriel Constenla-Haile         {
135*c5b3447dSAriel Constenla-Haile             // the ContentProperties maps "Content-Length" to the UCB "Size" property
136*c5b3447dSAriel Constenla-Haile             // This would have an unrealistic value of 1 byte because we did only a partial GET
137*c5b3447dSAriel Constenla-Haile             // Solution: if "Content-Range" is present, map it with UCB "Size" property
138*c5b3447dSAriel Constenla-Haile             rtl::OUString aAcceptRanges, aContentRange, aContentLength;
139*c5b3447dSAriel Constenla-Haile             std::vector< DAVPropertyValue > &aResponseProps = aResource.properties;
140*c5b3447dSAriel Constenla-Haile             for ( std::vector< DAVPropertyValue >::const_iterator it = aResponseProps.begin();
141*c5b3447dSAriel Constenla-Haile                     it != aResponseProps.end(); it++ )
142*c5b3447dSAriel Constenla-Haile             {
143*c5b3447dSAriel Constenla-Haile                 if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Accept-Ranges" ) ) )
144*c5b3447dSAriel Constenla-Haile                     it->Value >>= aAcceptRanges;
145*c5b3447dSAriel Constenla-Haile                 else if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Range" ) ) )
146*c5b3447dSAriel Constenla-Haile                     it->Value >>= aContentRange;
147*c5b3447dSAriel Constenla-Haile                 else if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
148*c5b3447dSAriel Constenla-Haile                     it->Value >>= aContentLength;
149*c5b3447dSAriel Constenla-Haile             }
150*c5b3447dSAriel Constenla-Haile 
151*c5b3447dSAriel Constenla-Haile             sal_Int64 nSize = 1;
152*c5b3447dSAriel Constenla-Haile             if ( aContentLength.getLength() )
153*c5b3447dSAriel Constenla-Haile             {
154*c5b3447dSAriel Constenla-Haile                 nSize = aContentLength.toInt64();
155*c5b3447dSAriel Constenla-Haile             }
156*c5b3447dSAriel Constenla-Haile 
157*c5b3447dSAriel Constenla-Haile             // according to http://tools.ietf.org/html/rfc2616#section-3.12
158*c5b3447dSAriel Constenla-Haile             // the only range unit defined is "bytes" and implementations
159*c5b3447dSAriel Constenla-Haile             // MAY ignore ranges specified using other units.
160*c5b3447dSAriel Constenla-Haile             if ( nSize == 1 &&
161*c5b3447dSAriel Constenla-Haile                     aContentRange.getLength() &&
162*c5b3447dSAriel Constenla-Haile                     aAcceptRanges.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "bytes" ) ) )
163*c5b3447dSAriel Constenla-Haile             {
164*c5b3447dSAriel Constenla-Haile                 // Parse the Content-Range to get the size
165*c5b3447dSAriel Constenla-Haile                 // vid. http://tools.ietf.org/html/rfc2616#section-14.16
166*c5b3447dSAriel Constenla-Haile                 // Content-Range: <range unit> <bytes range>/<size>
167*c5b3447dSAriel Constenla-Haile                 sal_Int32 nSlash = aContentRange.lastIndexOf( sal_Unicode('/'));
168*c5b3447dSAriel Constenla-Haile                 if ( nSlash != -1 )
169*c5b3447dSAriel Constenla-Haile                 {
170*c5b3447dSAriel Constenla-Haile                     rtl::OUString aSize = aContentRange.copy( nSlash + 1 );
171*c5b3447dSAriel Constenla-Haile                     // "*" means that the instance-length is unknown at the time when the response was generated
172*c5b3447dSAriel Constenla-Haile                     if ( !aSize.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "*" )))
173*c5b3447dSAriel Constenla-Haile                     {
174*c5b3447dSAriel Constenla-Haile                         for ( std::vector< DAVPropertyValue >::iterator it = aResponseProps.begin();
175*c5b3447dSAriel Constenla-Haile                                 it != aResponseProps.end(); it++ )
176*c5b3447dSAriel Constenla-Haile                         {
177*c5b3447dSAriel Constenla-Haile                             if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
178*c5b3447dSAriel Constenla-Haile                             {
179*c5b3447dSAriel Constenla-Haile                                 it->Value <<= aSize;
180*c5b3447dSAriel Constenla-Haile                                 break;
181*c5b3447dSAriel Constenla-Haile                             }
182*c5b3447dSAriel Constenla-Haile                         }
183*c5b3447dSAriel Constenla-Haile                     }
184*c5b3447dSAriel Constenla-Haile                 }
185*c5b3447dSAriel Constenla-Haile             }
186*c5b3447dSAriel Constenla-Haile         }
187*c5b3447dSAriel Constenla-Haile 
188*c5b3447dSAriel Constenla-Haile         if ( xProps.get() )
189*c5b3447dSAriel Constenla-Haile             xProps->addProperties(
190*c5b3447dSAriel Constenla-Haile                 aProps,
191*c5b3447dSAriel Constenla-Haile                 ContentProperties( aResource ) );
192*c5b3447dSAriel Constenla-Haile         else
193*c5b3447dSAriel Constenla-Haile             xProps.reset ( new ContentProperties( aResource ) );
194*c5b3447dSAriel Constenla-Haile     }
195*c5b3447dSAriel Constenla-Haile     catch ( DAVException const & ex )
196*c5b3447dSAriel Constenla-Haile     {
197*c5b3447dSAriel Constenla-Haile         aLastException = ex;
198*c5b3447dSAriel Constenla-Haile     }
199*c5b3447dSAriel Constenla-Haile }
200*c5b3447dSAriel Constenla-Haile }
201*c5b3447dSAriel Constenla-Haile 
202cdf0e10cSrcweir //=========================================================================
203cdf0e10cSrcweir //=========================================================================
204cdf0e10cSrcweir //
205cdf0e10cSrcweir // Content Implementation.
206cdf0e10cSrcweir //
207cdf0e10cSrcweir //=========================================================================
208cdf0e10cSrcweir //=========================================================================
209cdf0e10cSrcweir 
210cdf0e10cSrcweir //=========================================================================
211cdf0e10cSrcweir // ctr for content on an existing webdav resource
212cdf0e10cSrcweir Content::Content(
213cdf0e10cSrcweir           const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
214cdf0e10cSrcweir           ContentProvider* pProvider,
215cdf0e10cSrcweir           const uno::Reference< ucb::XContentIdentifier >& Identifier,
216cdf0e10cSrcweir           rtl::Reference< DAVSessionFactory > const & rSessionFactory )
217cdf0e10cSrcweir   throw ( ucb::ContentCreationException )
218cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ),
219cdf0e10cSrcweir   m_eResourceType( UNKNOWN ),
220cdf0e10cSrcweir   m_pProvider( pProvider ),
221cdf0e10cSrcweir   m_bTransient( false ),
222cdf0e10cSrcweir   m_bCollection( false ),
223cdf0e10cSrcweir   m_bDidGetOrHead( false )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     try
226cdf0e10cSrcweir     {
227cdf0e10cSrcweir         m_xResAccess.reset( new DAVResourceAccess(
228cdf0e10cSrcweir                 rxSMgr,
229cdf0e10cSrcweir                 rSessionFactory,
230cdf0e10cSrcweir                 Identifier->getContentIdentifier() ) );
231cdf0e10cSrcweir 
23259ddfc10SAndre Fischer         SerfUri aURI( Identifier->getContentIdentifier() );
233cdf0e10cSrcweir         m_aEscapedTitle = aURI.GetPathBaseName();
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir     catch ( DAVException const & )
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         throw ucb::ContentCreationException();
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir //=========================================================================
242cdf0e10cSrcweir // ctr for content on an non-existing webdav resource
243cdf0e10cSrcweir Content::Content(
244cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
245cdf0e10cSrcweir             ContentProvider* pProvider,
246cdf0e10cSrcweir             const uno::Reference< ucb::XContentIdentifier >& Identifier,
247cdf0e10cSrcweir             rtl::Reference< DAVSessionFactory > const & rSessionFactory,
248cdf0e10cSrcweir             sal_Bool isCollection )
249cdf0e10cSrcweir   throw ( ucb::ContentCreationException )
250cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ),
251cdf0e10cSrcweir   m_eResourceType( UNKNOWN ),
252cdf0e10cSrcweir   m_pProvider( pProvider ),
253cdf0e10cSrcweir   m_bTransient( true ),
254cdf0e10cSrcweir   m_bCollection( isCollection ),
255cdf0e10cSrcweir   m_bDidGetOrHead( false )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     try
258cdf0e10cSrcweir     {
259cdf0e10cSrcweir         m_xResAccess.reset( new DAVResourceAccess(
260cdf0e10cSrcweir             rxSMgr, rSessionFactory, Identifier->getContentIdentifier() ) );
261cdf0e10cSrcweir     }
262cdf0e10cSrcweir     catch ( DAVException const & )
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir         throw ucb::ContentCreationException();
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     // Do not set m_aEscapedTitle here! Content::insert relays on this!!!
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir //=========================================================================
271cdf0e10cSrcweir // virtual
272cdf0e10cSrcweir Content::~Content()
273cdf0e10cSrcweir {
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir //=========================================================================
277cdf0e10cSrcweir //
278cdf0e10cSrcweir // XInterface methods.
279cdf0e10cSrcweir //
280cdf0e10cSrcweir //=========================================================================
281cdf0e10cSrcweir 
282cdf0e10cSrcweir // virtual
283cdf0e10cSrcweir void SAL_CALL Content::acquire()
284cdf0e10cSrcweir     throw( )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir     ContentImplHelper::acquire();
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir //=========================================================================
290cdf0e10cSrcweir // virtual
291cdf0e10cSrcweir void SAL_CALL Content::release()
292cdf0e10cSrcweir     throw( )
293cdf0e10cSrcweir {
294cdf0e10cSrcweir     ContentImplHelper::release();
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir //=========================================================================
298cdf0e10cSrcweir // virtual
299cdf0e10cSrcweir uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
300cdf0e10cSrcweir     throw ( uno::RuntimeException )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir     // Note: isFolder may require network activities! So call it only
303cdf0e10cSrcweir     //       if it is really necessary!!!
304cdf0e10cSrcweir     uno::Any aRet = cppu::queryInterface(
305cdf0e10cSrcweir         rType,
306cdf0e10cSrcweir         static_cast< ucb::XContentCreator * >( this ) );
307cdf0e10cSrcweir     if ( aRet.hasValue() )
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir         try
310cdf0e10cSrcweir         {
311cdf0e10cSrcweir             uno::Reference< beans::XPropertySet > const xProps(
312cdf0e10cSrcweir                 m_xSMgr, uno::UNO_QUERY_THROW );
313cdf0e10cSrcweir             uno::Reference< uno::XComponentContext > xCtx;
314cdf0e10cSrcweir             xCtx.set( xProps->getPropertyValue(
315cdf0e10cSrcweir                 rtl::OUString(
316cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ),
317cdf0e10cSrcweir                 uno::UNO_QUERY_THROW );
318cdf0e10cSrcweir 
319cdf0e10cSrcweir             uno::Reference< task::XInteractionHandler > xIH(
320cdf0e10cSrcweir                 task::PasswordContainerInteractionHandler::create( xCtx ) );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir             // Supply a command env to isFolder() that contains an interaction
323cdf0e10cSrcweir             // handler that uses the password container service to obtain
324cdf0e10cSrcweir             // credentials without displaying a password gui.
325cdf0e10cSrcweir 
326cdf0e10cSrcweir             uno::Reference< ucb::XCommandEnvironment > xCmdEnv(
327cdf0e10cSrcweir                 ucb::CommandEnvironment::create(
328cdf0e10cSrcweir                    xCtx,
329cdf0e10cSrcweir                    xIH,
330cdf0e10cSrcweir                    uno::Reference< ucb::XProgressHandler >() ) );
331cdf0e10cSrcweir 
332cdf0e10cSrcweir             return isFolder( xCmdEnv ) ? aRet : uno::Any();
333cdf0e10cSrcweir         }
334cdf0e10cSrcweir         catch ( uno::RuntimeException const & )
335cdf0e10cSrcweir         {
336cdf0e10cSrcweir             throw;
337cdf0e10cSrcweir         }
338cdf0e10cSrcweir         catch ( uno::Exception const & )
339cdf0e10cSrcweir         {
340cdf0e10cSrcweir             return uno::Any();
341cdf0e10cSrcweir         }
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir     return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
344cdf0e10cSrcweir }
345cdf0e10cSrcweir 
346cdf0e10cSrcweir //=========================================================================
347cdf0e10cSrcweir //
348cdf0e10cSrcweir // XTypeProvider methods.
349cdf0e10cSrcweir //
350cdf0e10cSrcweir //=========================================================================
351cdf0e10cSrcweir 
352cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( Content );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir //=========================================================================
355cdf0e10cSrcweir // virtual
356cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
357cdf0e10cSrcweir     throw( uno::RuntimeException )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir     sal_Bool bFolder = sal_False;
360cdf0e10cSrcweir     try
361cdf0e10cSrcweir     {
362cdf0e10cSrcweir         bFolder
363cdf0e10cSrcweir             = isFolder( uno::Reference< ucb::XCommandEnvironment >() );
364cdf0e10cSrcweir     }
365cdf0e10cSrcweir     catch ( uno::RuntimeException const & )
366cdf0e10cSrcweir     {
367cdf0e10cSrcweir         throw;
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir     catch ( uno::Exception const & )
370cdf0e10cSrcweir     {
371cdf0e10cSrcweir     }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir     cppu::OTypeCollection * pCollection = 0;
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     if ( bFolder )
376cdf0e10cSrcweir     {
377cdf0e10cSrcweir         static cppu::OTypeCollection* pFolderTypes = 0;
378cdf0e10cSrcweir 
379cdf0e10cSrcweir         pCollection = pFolderTypes;
380cdf0e10cSrcweir         if ( !pCollection )
381cdf0e10cSrcweir         {
382cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
383cdf0e10cSrcweir 
384cdf0e10cSrcweir             pCollection = pFolderTypes;
385cdf0e10cSrcweir             if ( !pCollection )
386cdf0e10cSrcweir             {
387cdf0e10cSrcweir                 static cppu::OTypeCollection aCollection(
388cdf0e10cSrcweir                     CPPU_TYPE_REF( lang::XTypeProvider ),
389cdf0e10cSrcweir                         CPPU_TYPE_REF( lang::XServiceInfo ),
390cdf0e10cSrcweir                         CPPU_TYPE_REF( lang::XComponent ),
391cdf0e10cSrcweir                         CPPU_TYPE_REF( ucb::XContent ),
392cdf0e10cSrcweir                         CPPU_TYPE_REF( ucb::XCommandProcessor ),
393cdf0e10cSrcweir                         CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
394cdf0e10cSrcweir                         CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
395cdf0e10cSrcweir                         CPPU_TYPE_REF( beans::XPropertyContainer ),
396cdf0e10cSrcweir                         CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
397cdf0e10cSrcweir                         CPPU_TYPE_REF( container::XChild ),
398cdf0e10cSrcweir                         CPPU_TYPE_REF( ucb::XContentCreator ) ); // !!
399cdf0e10cSrcweir                 pCollection = &aCollection;
400cdf0e10cSrcweir                 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
401cdf0e10cSrcweir                 pFolderTypes = pCollection;
402cdf0e10cSrcweir             }
403cdf0e10cSrcweir         }
404cdf0e10cSrcweir         else {
405cdf0e10cSrcweir             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
406cdf0e10cSrcweir         }
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir     else
409cdf0e10cSrcweir     {
410cdf0e10cSrcweir         static cppu::OTypeCollection* pDocumentTypes = 0;
411cdf0e10cSrcweir 
412cdf0e10cSrcweir         pCollection = pDocumentTypes;
413cdf0e10cSrcweir         if ( !pCollection )
414cdf0e10cSrcweir         {
415cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
416cdf0e10cSrcweir 
417cdf0e10cSrcweir             pCollection = pDocumentTypes;
418cdf0e10cSrcweir             if ( !pCollection )
419cdf0e10cSrcweir             {
420cdf0e10cSrcweir                 static cppu::OTypeCollection aCollection(
421cdf0e10cSrcweir                         CPPU_TYPE_REF( lang::XTypeProvider ),
422cdf0e10cSrcweir                         CPPU_TYPE_REF( lang::XServiceInfo ),
423cdf0e10cSrcweir                         CPPU_TYPE_REF( lang::XComponent ),
424cdf0e10cSrcweir                         CPPU_TYPE_REF( ucb::XContent ),
425cdf0e10cSrcweir                         CPPU_TYPE_REF( ucb::XCommandProcessor ),
426cdf0e10cSrcweir                         CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
427cdf0e10cSrcweir                         CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
428cdf0e10cSrcweir                         CPPU_TYPE_REF( beans::XPropertyContainer ),
429cdf0e10cSrcweir                         CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
430cdf0e10cSrcweir                         CPPU_TYPE_REF( container::XChild ) );
431cdf0e10cSrcweir                 pCollection = &aCollection;
432cdf0e10cSrcweir                 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
433cdf0e10cSrcweir                 pDocumentTypes = pCollection;
434cdf0e10cSrcweir             }
435cdf0e10cSrcweir         }
436cdf0e10cSrcweir         else {
437cdf0e10cSrcweir             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
438cdf0e10cSrcweir         }
439cdf0e10cSrcweir     }
440cdf0e10cSrcweir 
441cdf0e10cSrcweir     return (*pCollection).getTypes();
442cdf0e10cSrcweir }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir //=========================================================================
445cdf0e10cSrcweir //
446cdf0e10cSrcweir // XServiceInfo methods.
447cdf0e10cSrcweir //
448cdf0e10cSrcweir //=========================================================================
449cdf0e10cSrcweir 
450cdf0e10cSrcweir // virtual
451cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getImplementationName()
452cdf0e10cSrcweir     throw( uno::RuntimeException )
453cdf0e10cSrcweir {
454cdf0e10cSrcweir     return rtl::OUString::createFromAscii(
455cdf0e10cSrcweir                             "com.sun.star.comp.ucb.WebDAVContent" );
456cdf0e10cSrcweir }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir //=========================================================================
459cdf0e10cSrcweir // virtual
460cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames()
461cdf0e10cSrcweir     throw( uno::RuntimeException )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aSNS( 1 );
464cdf0e10cSrcweir     aSNS.getArray()[ 0 ]
465cdf0e10cSrcweir         = rtl::OUString::createFromAscii( WEBDAV_CONTENT_SERVICE_NAME );
466cdf0e10cSrcweir     return aSNS;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir //=========================================================================
470cdf0e10cSrcweir //
471cdf0e10cSrcweir // XContent methods.
472cdf0e10cSrcweir //
473cdf0e10cSrcweir //=========================================================================
474cdf0e10cSrcweir 
475cdf0e10cSrcweir // virtual
476cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getContentType()
477cdf0e10cSrcweir     throw( uno::RuntimeException )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir     sal_Bool bFolder = sal_False;
480cdf0e10cSrcweir     try
481cdf0e10cSrcweir     {
482cdf0e10cSrcweir         bFolder
483cdf0e10cSrcweir             = isFolder( uno::Reference< ucb::XCommandEnvironment >() );
484cdf0e10cSrcweir     }
485cdf0e10cSrcweir     catch ( uno::RuntimeException const & )
486cdf0e10cSrcweir     {
487cdf0e10cSrcweir         throw;
488cdf0e10cSrcweir     }
489cdf0e10cSrcweir     catch ( uno::Exception const & )
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir     }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir     if ( bFolder )
494cdf0e10cSrcweir         return rtl::OUString::createFromAscii( WEBDAV_COLLECTION_TYPE );
495cdf0e10cSrcweir 
496cdf0e10cSrcweir     return rtl::OUString::createFromAscii( WEBDAV_CONTENT_TYPE );
497cdf0e10cSrcweir }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir //=========================================================================
500cdf0e10cSrcweir //
501cdf0e10cSrcweir // XCommandProcessor methods.
502cdf0e10cSrcweir //
503cdf0e10cSrcweir //=========================================================================
504cdf0e10cSrcweir 
505cdf0e10cSrcweir // virtual
506cdf0e10cSrcweir uno::Any SAL_CALL Content::execute(
507cdf0e10cSrcweir         const ucb::Command& aCommand,
508cdf0e10cSrcweir         sal_Int32 /*CommandId*/,
509cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment >& Environment )
510cdf0e10cSrcweir     throw( uno::Exception,
511cdf0e10cSrcweir            ucb::CommandAbortedException,
512cdf0e10cSrcweir            uno::RuntimeException )
513cdf0e10cSrcweir {
514cdf0e10cSrcweir     OSL_TRACE( ">>>>> Content::execute: start: command: %s, env: %s",
515cdf0e10cSrcweir                rtl::OUStringToOString( aCommand.Name,
516cdf0e10cSrcweir                                        RTL_TEXTENCODING_UTF8 ).getStr(),
517cdf0e10cSrcweir                Environment.is() ? "present" : "missing" );
518cdf0e10cSrcweir 
519cdf0e10cSrcweir     uno::Any aRet;
520cdf0e10cSrcweir 
521cdf0e10cSrcweir     if ( aCommand.Name.equalsAsciiL(
522cdf0e10cSrcweir              RTL_CONSTASCII_STRINGPARAM( "getPropertyValues" ) ) )
523cdf0e10cSrcweir     {
524cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
525cdf0e10cSrcweir         // getPropertyValues
526cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
527cdf0e10cSrcweir 
528cdf0e10cSrcweir         uno::Sequence< beans::Property > Properties;
529cdf0e10cSrcweir         if ( !( aCommand.Argument >>= Properties ) )
530cdf0e10cSrcweir         {
531cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
532cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
533cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
534cdf0e10cSrcweir                                         "Wrong argument type!" ),
535cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
536cdf0e10cSrcweir                                     -1 ) ),
537cdf0e10cSrcweir                 Environment );
538cdf0e10cSrcweir             // Unreachable
539cdf0e10cSrcweir         }
540cdf0e10cSrcweir 
541cdf0e10cSrcweir         aRet <<= getPropertyValues( Properties, Environment );
542cdf0e10cSrcweir     }
543cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
544cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "setPropertyValues" ) ) )
545cdf0e10cSrcweir     {
546cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
547cdf0e10cSrcweir         // setPropertyValues
548cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
549cdf0e10cSrcweir 
550cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aProperties;
551cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aProperties ) )
552cdf0e10cSrcweir         {
553cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
554cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
555cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
556cdf0e10cSrcweir                                         "Wrong argument type!" ),
557cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
558cdf0e10cSrcweir                                     -1 ) ),
559cdf0e10cSrcweir                 Environment );
560cdf0e10cSrcweir             // Unreachable
561cdf0e10cSrcweir         }
562cdf0e10cSrcweir 
563cdf0e10cSrcweir         if ( !aProperties.getLength() )
564cdf0e10cSrcweir         {
565cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
566cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
567cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
568cdf0e10cSrcweir                                         "No properties!" ),
569cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
570cdf0e10cSrcweir                                     -1 ) ),
571cdf0e10cSrcweir                 Environment );
572cdf0e10cSrcweir             // Unreachable
573cdf0e10cSrcweir         }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir         aRet <<= setPropertyValues( aProperties, Environment );
576cdf0e10cSrcweir     }
577cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
578cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "getPropertySetInfo" ) ) )
579cdf0e10cSrcweir     {
580cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
581cdf0e10cSrcweir         // getPropertySetInfo
582cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
583cdf0e10cSrcweir 
584cdf0e10cSrcweir         // Note: Implemented by base class.
585cdf0e10cSrcweir         aRet <<= getPropertySetInfo( Environment,
586cdf0e10cSrcweir                                      sal_False /* don't cache data */ );
587cdf0e10cSrcweir     }
588cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
589cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "getCommandInfo" ) ) )
590cdf0e10cSrcweir     {
591cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
592cdf0e10cSrcweir         // getCommandInfo
593cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
594cdf0e10cSrcweir 
595cdf0e10cSrcweir         // Note: Implemented by base class.
596cdf0e10cSrcweir         aRet <<= getCommandInfo( Environment, sal_False );
597cdf0e10cSrcweir     }
598cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
599cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "open" ) ) )
600cdf0e10cSrcweir     {
601cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
602cdf0e10cSrcweir         // open
603cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
604cdf0e10cSrcweir 
605cdf0e10cSrcweir         ucb::OpenCommandArgument2 aOpenCommand;
606cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aOpenCommand ) )
607cdf0e10cSrcweir         {
608cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
609cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
610cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
611cdf0e10cSrcweir                                         "Wrong argument type!" ),
612cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
613cdf0e10cSrcweir                                     -1 ) ),
614cdf0e10cSrcweir                 Environment );
615cdf0e10cSrcweir             // Unreachable
616cdf0e10cSrcweir         }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir         aRet = open( aOpenCommand, Environment );
619cdf0e10cSrcweir     }
620cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
621cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "insert" ) ) )
622cdf0e10cSrcweir     {
623cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
624cdf0e10cSrcweir         // insert
625cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
626cdf0e10cSrcweir 
627cdf0e10cSrcweir         ucb::InsertCommandArgument arg;
628cdf0e10cSrcweir         if ( !( aCommand.Argument >>= arg ) )
629cdf0e10cSrcweir         {
630cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
631cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
632cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
633cdf0e10cSrcweir                                         "Wrong argument type!" ),
634cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
635cdf0e10cSrcweir                                     -1 ) ),
636cdf0e10cSrcweir                 Environment );
637cdf0e10cSrcweir             // Unreachable
638cdf0e10cSrcweir         }
639cdf0e10cSrcweir 
640cdf0e10cSrcweir         insert( arg.Data, arg.ReplaceExisting, Environment );
641cdf0e10cSrcweir     }
642cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
643cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "delete" ) ) )
644cdf0e10cSrcweir     {
645cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
646cdf0e10cSrcweir         // delete
647cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
648cdf0e10cSrcweir 
649cdf0e10cSrcweir         sal_Bool bDeletePhysical = sal_False;
650cdf0e10cSrcweir         aCommand.Argument >>= bDeletePhysical;
651cdf0e10cSrcweir 
652cdf0e10cSrcweir //  KSO: Ignore parameter and destroy the content, if you don't support
653cdf0e10cSrcweir //       putting objects into trashcan. ( Since we do not have a trash can
654cdf0e10cSrcweir //       service yet (src603), you actually have no other choice. )
655cdf0e10cSrcweir //      if ( bDeletePhysical )
656cdf0e10cSrcweir //  {
657cdf0e10cSrcweir         try
658cdf0e10cSrcweir         {
659cdf0e10cSrcweir             std::auto_ptr< DAVResourceAccess > xResAccess;
660cdf0e10cSrcweir             {
661cdf0e10cSrcweir                 osl::Guard< osl::Mutex > aGuard( m_aMutex );
662cdf0e10cSrcweir                 xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
663cdf0e10cSrcweir             }
664cdf0e10cSrcweir             xResAccess->DESTROY( Environment );
665cdf0e10cSrcweir             {
666cdf0e10cSrcweir                 osl::Guard< osl::Mutex > aGuard( m_aMutex );
667cdf0e10cSrcweir                 m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
668cdf0e10cSrcweir             }
669cdf0e10cSrcweir         }
670cdf0e10cSrcweir         catch ( DAVException const & e )
671cdf0e10cSrcweir         {
672cdf0e10cSrcweir             cancelCommandExecution( e, Environment, sal_True );
673cdf0e10cSrcweir             // Unreachable
674cdf0e10cSrcweir         }
675cdf0e10cSrcweir //      }
676cdf0e10cSrcweir 
677cdf0e10cSrcweir         // Propagate destruction.
678cdf0e10cSrcweir         destroy( bDeletePhysical );
679cdf0e10cSrcweir 
680cdf0e10cSrcweir         // Remove own and all children's Additional Core Properties.
681cdf0e10cSrcweir         removeAdditionalPropertySet( sal_True );
682cdf0e10cSrcweir     }
683cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
684cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "transfer" ) )
685cdf0e10cSrcweir               && isFolder( Environment ) )
686cdf0e10cSrcweir     {
687cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
688cdf0e10cSrcweir         // transfer
689cdf0e10cSrcweir         //  ( Not available at documents )
690cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
691cdf0e10cSrcweir 
692cdf0e10cSrcweir         ucb::TransferInfo transferArgs;
693cdf0e10cSrcweir         if ( !( aCommand.Argument >>= transferArgs ) )
694cdf0e10cSrcweir         {
695cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
696cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
697cdf0e10cSrcweir                                   rtl::OUString::createFromAscii(
698cdf0e10cSrcweir                                       "Wrong argument type!" ),
699cdf0e10cSrcweir                                   static_cast< cppu::OWeakObject * >( this ),
700cdf0e10cSrcweir                                   -1 ) ),
701cdf0e10cSrcweir                 Environment );
702cdf0e10cSrcweir             // Unreachable
703cdf0e10cSrcweir         }
704cdf0e10cSrcweir 
705cdf0e10cSrcweir         transfer( transferArgs, Environment );
706cdf0e10cSrcweir     }
707cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
708cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "post" ) ) )
709cdf0e10cSrcweir     {
710cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
711cdf0e10cSrcweir         // post
712cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
713cdf0e10cSrcweir 
714cdf0e10cSrcweir         ucb::PostCommandArgument2 aArg;
715cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aArg ) )
716cdf0e10cSrcweir         {
717cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
718cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
719cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
720cdf0e10cSrcweir                                         "Wrong argument type!" ),
721cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
722cdf0e10cSrcweir                                     -1 ) ),
723cdf0e10cSrcweir                 Environment );
724cdf0e10cSrcweir             // Unreachable
725cdf0e10cSrcweir         }
726cdf0e10cSrcweir 
727cdf0e10cSrcweir         post( aArg, Environment );
728cdf0e10cSrcweir     }
729cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
730cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "lock" ) ) &&
731cdf0e10cSrcweir               supportsExclusiveWriteLock( Environment ) )
732cdf0e10cSrcweir     {
733cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
734cdf0e10cSrcweir         // lock
735cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
736cdf0e10cSrcweir 
737cdf0e10cSrcweir         lock( Environment );
738cdf0e10cSrcweir     }
739cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
740cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "unlock" ) ) &&
741cdf0e10cSrcweir               supportsExclusiveWriteLock( Environment ) )
742cdf0e10cSrcweir     {
743cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
744cdf0e10cSrcweir         // unlock
745cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
746cdf0e10cSrcweir 
747cdf0e10cSrcweir         unlock( Environment );
748cdf0e10cSrcweir     }
749cdf0e10cSrcweir     else if ( aCommand.Name.equalsAsciiL(
750cdf0e10cSrcweir                   RTL_CONSTASCII_STRINGPARAM( "createNewContent" ) ) &&
751cdf0e10cSrcweir               isFolder( Environment ) )
752cdf0e10cSrcweir     {
753cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
754cdf0e10cSrcweir         // createNewContent
755cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
756cdf0e10cSrcweir 
757cdf0e10cSrcweir         ucb::ContentInfo aArg;
758cdf0e10cSrcweir         if ( !( aCommand.Argument >>= aArg ) )
759cdf0e10cSrcweir         {
760cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
761cdf0e10cSrcweir                 uno::makeAny( lang::IllegalArgumentException(
762cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
763cdf0e10cSrcweir                                         "Wrong argument type!" ),
764cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
765cdf0e10cSrcweir                                     -1 ) ),
766cdf0e10cSrcweir                 Environment );
767cdf0e10cSrcweir             // Unreachable
768cdf0e10cSrcweir         }
769cdf0e10cSrcweir 
770cdf0e10cSrcweir         aRet = uno::makeAny( createNewContent( aArg ) );
771cdf0e10cSrcweir     }
772cdf0e10cSrcweir     else
773cdf0e10cSrcweir     {
774cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
775cdf0e10cSrcweir         // Unsupported command
776cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
777cdf0e10cSrcweir 
778cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
779cdf0e10cSrcweir             uno::makeAny( ucb::UnsupportedCommandException(
780cdf0e10cSrcweir                               aCommand.Name,
781cdf0e10cSrcweir                               static_cast< cppu::OWeakObject * >( this ) ) ),
782cdf0e10cSrcweir             Environment );
783cdf0e10cSrcweir         // Unreachable
784cdf0e10cSrcweir     }
785cdf0e10cSrcweir 
786cdf0e10cSrcweir     OSL_TRACE( "<<<<< Content::execute: end: command: %s",
787cdf0e10cSrcweir                rtl::OUStringToOString( aCommand.Name,
788cdf0e10cSrcweir                                        RTL_TEXTENCODING_UTF8 ).getStr() );
789cdf0e10cSrcweir 
790cdf0e10cSrcweir     return aRet;
791cdf0e10cSrcweir }
792cdf0e10cSrcweir 
793cdf0e10cSrcweir //=========================================================================
794cdf0e10cSrcweir // virtual
795cdf0e10cSrcweir void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
796cdf0e10cSrcweir     throw( uno::RuntimeException )
797cdf0e10cSrcweir {
798cdf0e10cSrcweir     try
799cdf0e10cSrcweir     {
800cdf0e10cSrcweir         std::auto_ptr< DAVResourceAccess > xResAccess;
801cdf0e10cSrcweir         {
802cdf0e10cSrcweir             osl::MutexGuard aGuard( m_aMutex );
803cdf0e10cSrcweir             xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
804cdf0e10cSrcweir         }
805cdf0e10cSrcweir         xResAccess->abort();
806cdf0e10cSrcweir         {
807cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
808cdf0e10cSrcweir             m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
809cdf0e10cSrcweir         }
810cdf0e10cSrcweir     }
811cdf0e10cSrcweir     catch ( DAVException const & )
812cdf0e10cSrcweir     {
813cdf0e10cSrcweir         // abort failed!
814cdf0e10cSrcweir     }
815cdf0e10cSrcweir }
816cdf0e10cSrcweir 
817cdf0e10cSrcweir //=========================================================================
818cdf0e10cSrcweir //
819cdf0e10cSrcweir // XPropertyContainer methods.
820cdf0e10cSrcweir //
821cdf0e10cSrcweir //=========================================================================
822cdf0e10cSrcweir 
823cdf0e10cSrcweir // virtual
824cdf0e10cSrcweir void SAL_CALL Content::addProperty( const rtl::OUString& Name,
825cdf0e10cSrcweir                                     sal_Int16 Attributes,
826cdf0e10cSrcweir                                     const uno::Any& DefaultValue )
827cdf0e10cSrcweir     throw( beans::PropertyExistException,
828cdf0e10cSrcweir            beans::IllegalTypeException,
829cdf0e10cSrcweir            lang::IllegalArgumentException,
830cdf0e10cSrcweir            uno::RuntimeException )
831cdf0e10cSrcweir {
832cdf0e10cSrcweir //    if ( m_bTransient )
833cdf0e10cSrcweir //   @@@ ???
834cdf0e10cSrcweir 
835cdf0e10cSrcweir     if ( !Name.getLength() )
836cdf0e10cSrcweir         throw lang::IllegalArgumentException();
837cdf0e10cSrcweir 
838cdf0e10cSrcweir     // Check property type.
839cdf0e10cSrcweir     if ( !UCBDeadPropertyValue::supportsType( DefaultValue.getValueType() ) )
840cdf0e10cSrcweir     {
841cdf0e10cSrcweir         OSL_ENSURE( sal_False,
842cdf0e10cSrcweir                     "Content::addProperty - Unsupported property type!" );
843cdf0e10cSrcweir         throw beans::IllegalTypeException();
844cdf0e10cSrcweir     }
845cdf0e10cSrcweir 
846cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
847cdf0e10cSrcweir     // Make sure a property with the requested name does not already
848cdf0e10cSrcweir     // exist in dynamic and static(!) properties.
849cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
850cdf0e10cSrcweir 
851cdf0e10cSrcweir     // @@@ Need real command environment here, but where to get it from?
852cdf0e10cSrcweir     //     XPropertyContainer interface should be replaced by
853cdf0e10cSrcweir     //     XCommandProcessor commands!
854cdf0e10cSrcweir     uno::Reference< ucb::XCommandEnvironment > xEnv;
855cdf0e10cSrcweir 
856cdf0e10cSrcweir     // Note: This requires network access!
857cdf0e10cSrcweir     if ( getPropertySetInfo( xEnv, sal_False /* don't cache data */ )
858cdf0e10cSrcweir              ->hasPropertyByName( Name ) )
859cdf0e10cSrcweir     {
860cdf0e10cSrcweir         // Property does already exist.
861cdf0e10cSrcweir         throw beans::PropertyExistException();
862cdf0e10cSrcweir     }
863cdf0e10cSrcweir 
864cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
865cdf0e10cSrcweir     // Add a new dynamic property.
866cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
867cdf0e10cSrcweir 
868cdf0e10cSrcweir     ProppatchValue aValue( PROPSET, Name, DefaultValue );
869cdf0e10cSrcweir 
870cdf0e10cSrcweir     std::vector< ProppatchValue > aProppatchValues;
871cdf0e10cSrcweir     aProppatchValues.push_back( aValue );
872cdf0e10cSrcweir 
873cdf0e10cSrcweir     try
874cdf0e10cSrcweir     {
875cdf0e10cSrcweir         // Set property value at server.
876cdf0e10cSrcweir         std::auto_ptr< DAVResourceAccess > xResAccess;
877cdf0e10cSrcweir         {
878cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
879cdf0e10cSrcweir             xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
880cdf0e10cSrcweir         }
881cdf0e10cSrcweir         xResAccess->PROPPATCH( aProppatchValues, xEnv );
882cdf0e10cSrcweir         {
883cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
884cdf0e10cSrcweir             m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
885cdf0e10cSrcweir         }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir         // Notify propertyset info change listeners.
888cdf0e10cSrcweir         beans::PropertySetInfoChangeEvent evt(
889cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >( this ),
890cdf0e10cSrcweir             Name,
891cdf0e10cSrcweir             -1, // No handle available
892cdf0e10cSrcweir             beans::PropertySetInfoChange::PROPERTY_INSERTED );
893cdf0e10cSrcweir         notifyPropertySetInfoChange( evt );
894cdf0e10cSrcweir     }
895cdf0e10cSrcweir     catch ( DAVException const & e )
896cdf0e10cSrcweir     {
897cdf0e10cSrcweir         if ( e.getStatus() == SC_FORBIDDEN )
898cdf0e10cSrcweir         {
899cdf0e10cSrcweir             // Support for setting arbitrary dead properties is optional!
900cdf0e10cSrcweir 
901cdf0e10cSrcweir             // Store property locally.
902cdf0e10cSrcweir             ContentImplHelper::addProperty(
903cdf0e10cSrcweir                 Name, Attributes, DefaultValue );
904cdf0e10cSrcweir         }
905cdf0e10cSrcweir         else
906cdf0e10cSrcweir         {
907cdf0e10cSrcweir             if ( shouldAccessNetworkAfterException( e ) )
908cdf0e10cSrcweir             {
909cdf0e10cSrcweir                 try
910cdf0e10cSrcweir                 {
911cdf0e10cSrcweir                     const ResourceType & rType = getResourceType( xEnv );
912cdf0e10cSrcweir                     switch ( rType )
913cdf0e10cSrcweir                     {
914cdf0e10cSrcweir                     case UNKNOWN:
915cdf0e10cSrcweir                     case DAV:
916cdf0e10cSrcweir                         throw lang::IllegalArgumentException();
917cdf0e10cSrcweir 
918cdf0e10cSrcweir                     case NON_DAV:
919cdf0e10cSrcweir                         // Store property locally.
920cdf0e10cSrcweir                         ContentImplHelper::addProperty( Name,
921cdf0e10cSrcweir                                                         Attributes,
922cdf0e10cSrcweir                                                         DefaultValue );
923cdf0e10cSrcweir                         break;
924cdf0e10cSrcweir 
925cdf0e10cSrcweir                     default:
926cdf0e10cSrcweir                         OSL_ENSURE( sal_False,
927cdf0e10cSrcweir                                     "Content::addProperty - "
928cdf0e10cSrcweir                                     "Unsupported resource type!" );
929cdf0e10cSrcweir                         break;
930cdf0e10cSrcweir                     }
931cdf0e10cSrcweir                 }
932cdf0e10cSrcweir                 catch ( uno::Exception const & )
933cdf0e10cSrcweir                 {
934cdf0e10cSrcweir                     OSL_ENSURE( sal_False,
935cdf0e10cSrcweir                                 "Content::addProperty - "
936cdf0e10cSrcweir                                 "Unable to determine resource type!" );
937cdf0e10cSrcweir                 }
938cdf0e10cSrcweir             }
939cdf0e10cSrcweir             else
940cdf0e10cSrcweir             {
941cdf0e10cSrcweir                 OSL_ENSURE( sal_False,
942cdf0e10cSrcweir                             "Content::addProperty - "
943cdf0e10cSrcweir                             "Unable to determine resource type!" );
944cdf0e10cSrcweir             }
945cdf0e10cSrcweir         }
946cdf0e10cSrcweir     }
947cdf0e10cSrcweir }
948cdf0e10cSrcweir 
949cdf0e10cSrcweir //=========================================================================
950cdf0e10cSrcweir // virtual
951cdf0e10cSrcweir void SAL_CALL Content::removeProperty( const rtl::OUString& Name )
952cdf0e10cSrcweir     throw( beans::UnknownPropertyException,
953cdf0e10cSrcweir            beans::NotRemoveableException,
954cdf0e10cSrcweir            uno::RuntimeException )
955cdf0e10cSrcweir {
956cdf0e10cSrcweir     // @@@ Need real command environment here, but where to get it from?
957cdf0e10cSrcweir     //     XPropertyContainer interface should be replaced by
958cdf0e10cSrcweir     //     XCommandProcessor commands!
959cdf0e10cSrcweir     uno::Reference< ucb::XCommandEnvironment > xEnv;
960cdf0e10cSrcweir 
961cdf0e10cSrcweir #if 0
962cdf0e10cSrcweir     // @@@ REMOVEABLE z.Z. nicht richtig an der PropSetInfo gesetzt!!!
963cdf0e10cSrcweir     try
964cdf0e10cSrcweir     {
965cdf0e10cSrcweir         beans::Property aProp
966cdf0e10cSrcweir             = getPropertySetInfo( xEnv, sal_False /* don't cache data */ )
967cdf0e10cSrcweir                 ->getPropertyByName( Name );
968cdf0e10cSrcweir 
969cdf0e10cSrcweir         if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVEABLE ) )
970cdf0e10cSrcweir         {
971cdf0e10cSrcweir             // Not removeable!
972cdf0e10cSrcweir             throw beans::NotRemoveableException();
973cdf0e10cSrcweir         }
974cdf0e10cSrcweir     }
975cdf0e10cSrcweir     catch ( beans::UnknownPropertyException const & )
976cdf0e10cSrcweir     {
977cdf0e10cSrcweir         //OSL_ENSURE( sal_False, "removeProperty - Unknown property!" );
978cdf0e10cSrcweir         throw;
979cdf0e10cSrcweir     }
980cdf0e10cSrcweir #endif
981cdf0e10cSrcweir 
982cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
983cdf0e10cSrcweir     // Try to remove property from server.
984cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
985cdf0e10cSrcweir 
986cdf0e10cSrcweir     try
987cdf0e10cSrcweir     {
988cdf0e10cSrcweir         std::vector< ProppatchValue > aProppatchValues;
989cdf0e10cSrcweir         ProppatchValue aValue( PROPREMOVE, Name, uno::Any() );
990cdf0e10cSrcweir         aProppatchValues.push_back( aValue );
991cdf0e10cSrcweir 
992cdf0e10cSrcweir         // Remove property value from server.
993cdf0e10cSrcweir         std::auto_ptr< DAVResourceAccess > xResAccess;
994cdf0e10cSrcweir         {
995cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
996cdf0e10cSrcweir             xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
997cdf0e10cSrcweir         }
998cdf0e10cSrcweir         xResAccess->PROPPATCH( aProppatchValues, xEnv );
999cdf0e10cSrcweir         {
1000cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
1001cdf0e10cSrcweir             m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
1002cdf0e10cSrcweir         }
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir         // Notify propertyset info change listeners.
1005cdf0e10cSrcweir         beans::PropertySetInfoChangeEvent evt(
1006cdf0e10cSrcweir             static_cast< cppu::OWeakObject * >( this ),
1007cdf0e10cSrcweir             Name,
1008cdf0e10cSrcweir             -1, // No handle available
1009cdf0e10cSrcweir             beans::PropertySetInfoChange::PROPERTY_REMOVED );
1010cdf0e10cSrcweir         notifyPropertySetInfoChange( evt );
1011cdf0e10cSrcweir     }
1012cdf0e10cSrcweir     catch ( DAVException const & e )
1013cdf0e10cSrcweir     {
1014cdf0e10cSrcweir         if ( e.getStatus() == SC_FORBIDDEN )
1015cdf0e10cSrcweir         {
1016cdf0e10cSrcweir             // Support for setting arbitrary dead properties is optional!
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir             // Try to remove property from local store.
1019cdf0e10cSrcweir             ContentImplHelper::removeProperty( Name );
1020cdf0e10cSrcweir         }
1021cdf0e10cSrcweir         else
1022cdf0e10cSrcweir         {
1023cdf0e10cSrcweir             if ( shouldAccessNetworkAfterException( e ) )
1024cdf0e10cSrcweir             {
1025cdf0e10cSrcweir                 try
1026cdf0e10cSrcweir                 {
1027cdf0e10cSrcweir                     const ResourceType & rType = getResourceType( xEnv );
1028cdf0e10cSrcweir                     switch ( rType )
1029cdf0e10cSrcweir                     {
1030cdf0e10cSrcweir                         case UNKNOWN:
1031cdf0e10cSrcweir                         case DAV:
1032cdf0e10cSrcweir                             throw beans::UnknownPropertyException();
1033cdf0e10cSrcweir 
1034cdf0e10cSrcweir                         case NON_DAV:
1035cdf0e10cSrcweir                             // Try to remove property from local store.
1036cdf0e10cSrcweir                             ContentImplHelper::removeProperty( Name );
1037cdf0e10cSrcweir                             break;
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir                         default:
1040cdf0e10cSrcweir                             OSL_ENSURE( sal_False,
1041cdf0e10cSrcweir                                         "Content::removeProperty - "
1042cdf0e10cSrcweir                                         "Unsupported resource type!" );
1043cdf0e10cSrcweir                             break;
1044cdf0e10cSrcweir                     }
1045cdf0e10cSrcweir                 }
1046cdf0e10cSrcweir                 catch ( uno::Exception const & )
1047cdf0e10cSrcweir                 {
1048cdf0e10cSrcweir                     OSL_ENSURE( sal_False,
1049cdf0e10cSrcweir                                 "Content::removeProperty - "
1050cdf0e10cSrcweir                                 "Unable to determine resource type!" );
1051cdf0e10cSrcweir                 }
1052cdf0e10cSrcweir             }
1053cdf0e10cSrcweir             else
1054cdf0e10cSrcweir             {
1055cdf0e10cSrcweir                 OSL_ENSURE( sal_False,
1056cdf0e10cSrcweir                             "Content::removeProperty - "
1057cdf0e10cSrcweir                             "Unable to determine resource type!" );
1058cdf0e10cSrcweir //                throw beans::UnknownPropertyException();
1059cdf0e10cSrcweir             }
1060cdf0e10cSrcweir         }
1061cdf0e10cSrcweir     }
1062cdf0e10cSrcweir }
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir //=========================================================================
1065cdf0e10cSrcweir //
1066cdf0e10cSrcweir // XContentCreator methods.
1067cdf0e10cSrcweir //
1068cdf0e10cSrcweir //=========================================================================
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir // virtual
1071cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > SAL_CALL
1072cdf0e10cSrcweir Content::queryCreatableContentsInfo()
1073cdf0e10cSrcweir     throw( uno::RuntimeException )
1074cdf0e10cSrcweir {
1075cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir     uno::Sequence< ucb::ContentInfo > aSeq( 2 );
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir     // document.
1080cdf0e10cSrcweir     aSeq.getArray()[ 0 ].Type
1081cdf0e10cSrcweir         = rtl::OUString::createFromAscii( WEBDAV_CONTENT_TYPE );
1082cdf0e10cSrcweir     aSeq.getArray()[ 0 ].Attributes
1083cdf0e10cSrcweir         = ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM
1084cdf0e10cSrcweir           | ucb::ContentInfoAttribute::KIND_DOCUMENT;
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir     beans::Property aProp;
1087cdf0e10cSrcweir     m_pProvider->getProperty(
1088cdf0e10cSrcweir         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), aProp );
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir     uno::Sequence< beans::Property > aDocProps( 1 );
1091cdf0e10cSrcweir     aDocProps.getArray()[ 0 ] = aProp;
1092cdf0e10cSrcweir     aSeq.getArray()[ 0 ].Properties = aDocProps;
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir     // folder.
1095cdf0e10cSrcweir     aSeq.getArray()[ 1 ].Type
1096cdf0e10cSrcweir         = rtl::OUString::createFromAscii( WEBDAV_COLLECTION_TYPE );
1097cdf0e10cSrcweir     aSeq.getArray()[ 1 ].Attributes
1098cdf0e10cSrcweir         = ucb::ContentInfoAttribute::KIND_FOLDER;
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir     uno::Sequence< beans::Property > aFolderProps( 1 );
1101cdf0e10cSrcweir     aFolderProps.getArray()[ 0 ] = aProp;
1102cdf0e10cSrcweir     aSeq.getArray()[ 1 ].Properties = aFolderProps;
1103cdf0e10cSrcweir     return aSeq;
1104cdf0e10cSrcweir }
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir //=========================================================================
1107cdf0e10cSrcweir // virtual
1108cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL
1109cdf0e10cSrcweir Content::createNewContent( const ucb::ContentInfo& Info )
1110cdf0e10cSrcweir     throw( uno::RuntimeException )
1111cdf0e10cSrcweir {
1112cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir     if ( !Info.Type.getLength() )
1115cdf0e10cSrcweir         return uno::Reference< ucb::XContent >();
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir     if ( ( !Info.Type.equalsAsciiL(
1118cdf0e10cSrcweir                RTL_CONSTASCII_STRINGPARAM( WEBDAV_COLLECTION_TYPE ) ) )
1119cdf0e10cSrcweir          &&
1120cdf0e10cSrcweir          ( !Info.Type.equalsAsciiL(
1121cdf0e10cSrcweir              RTL_CONSTASCII_STRINGPARAM( WEBDAV_CONTENT_TYPE ) ) ) )
1122cdf0e10cSrcweir         return uno::Reference< ucb::XContent >();
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir     rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir     OSL_ENSURE( aURL.getLength() > 0,
1127cdf0e10cSrcweir                 "WebdavContent::createNewContent - empty identifier!" );
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir     if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() )
1130cdf0e10cSrcweir         aURL += rtl::OUString::createFromAscii( "/" );
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir     sal_Bool isCollection;
1133cdf0e10cSrcweir     if ( Info.Type.equalsAsciiL(
1134cdf0e10cSrcweir              RTL_CONSTASCII_STRINGPARAM( WEBDAV_COLLECTION_TYPE ) ) )
1135cdf0e10cSrcweir     {
1136cdf0e10cSrcweir         aURL += rtl::OUString::createFromAscii( "New_Collection" );
1137cdf0e10cSrcweir         isCollection = sal_True;
1138cdf0e10cSrcweir     }
1139cdf0e10cSrcweir     else
1140cdf0e10cSrcweir     {
1141cdf0e10cSrcweir         aURL += rtl::OUString::createFromAscii( "New_Content" );
1142cdf0e10cSrcweir         isCollection = sal_False;
1143cdf0e10cSrcweir     }
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir     uno::Reference< ucb::XContentIdentifier > xId(
1146cdf0e10cSrcweir                     new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ) );
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir     // create the local content
1149cdf0e10cSrcweir     try
1150cdf0e10cSrcweir     {
115159ddfc10SAndre Fischer         return new ::http_dav_ucp::Content( m_xSMgr,
1152cdf0e10cSrcweir                                           m_pProvider,
1153cdf0e10cSrcweir                                           xId,
1154cdf0e10cSrcweir                                           m_xResAccess->getSessionFactory(),
1155cdf0e10cSrcweir                                           isCollection );
1156cdf0e10cSrcweir     }
1157cdf0e10cSrcweir     catch ( ucb::ContentCreationException & )
1158cdf0e10cSrcweir     {
1159cdf0e10cSrcweir         return uno::Reference< ucb::XContent >();
1160cdf0e10cSrcweir     }
1161cdf0e10cSrcweir }
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir //=========================================================================
1164cdf0e10cSrcweir // virtual
1165cdf0e10cSrcweir rtl::OUString Content::getParentURL()
1166cdf0e10cSrcweir {
1167cdf0e10cSrcweir     // <scheme>://              -> ""
1168cdf0e10cSrcweir     // <scheme>://foo           -> ""
1169cdf0e10cSrcweir     // <scheme>://foo/          -> ""
1170cdf0e10cSrcweir     // <scheme>://foo/bar       -> <scheme>://foo/
1171cdf0e10cSrcweir     // <scheme>://foo/bar/      -> <scheme>://foo/
1172cdf0e10cSrcweir     // <scheme>://foo/bar/abc   -> <scheme>://foo/bar/
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir     rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir     sal_Int32 nPos = aURL.lastIndexOf( '/' );
1177cdf0e10cSrcweir     if ( nPos == ( aURL.getLength() - 1 ) )
1178cdf0e10cSrcweir     {
1179cdf0e10cSrcweir         // Trailing slash found. Skip.
1180cdf0e10cSrcweir         nPos = aURL.lastIndexOf( '/', nPos );
1181cdf0e10cSrcweir     }
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir     sal_Int32 nPos1 = aURL.lastIndexOf( '/', nPos );
1184cdf0e10cSrcweir     if ( nPos1 != -1 )
1185cdf0e10cSrcweir         nPos1 = aURL.lastIndexOf( '/', nPos1 );
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir     if ( nPos1 == -1 )
1188cdf0e10cSrcweir         return rtl::OUString();
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir     return rtl::OUString( aURL.copy( 0, nPos + 1 ) );
1191cdf0e10cSrcweir }
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir //=========================================================================
1194cdf0e10cSrcweir //
1195cdf0e10cSrcweir // Non-interface methods.
1196cdf0e10cSrcweir //
1197cdf0e10cSrcweir //=========================================================================
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir // static
1200cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues(
1201cdf0e10cSrcweir     const uno::Reference< lang::XMultiServiceFactory >& rSMgr,
1202cdf0e10cSrcweir     const uno::Sequence< beans::Property >& rProperties,
1203cdf0e10cSrcweir     const ContentProperties& rData,
1204cdf0e10cSrcweir     const rtl::Reference< ::ucbhelper::ContentProviderImplHelper >& rProvider,
1205cdf0e10cSrcweir     const rtl::OUString& rContentId )
1206cdf0e10cSrcweir {
1207cdf0e10cSrcweir     // Note: Empty sequence means "get values of all supported properties".
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir     rtl::Reference< ::ucbhelper::PropertyValueSet > xRow
1210cdf0e10cSrcweir         = new ::ucbhelper::PropertyValueSet( rSMgr );
1211cdf0e10cSrcweir 
1212cdf0e10cSrcweir     sal_Int32 nCount = rProperties.getLength();
1213cdf0e10cSrcweir     if ( nCount )
1214cdf0e10cSrcweir     {
1215cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xAdditionalPropSet;
1216cdf0e10cSrcweir         sal_Bool bTriedToGetAdditonalPropSet = sal_False;
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir         const beans::Property* pProps = rProperties.getConstArray();
1219cdf0e10cSrcweir         for ( sal_Int32 n = 0; n < nCount; ++n )
1220cdf0e10cSrcweir         {
1221cdf0e10cSrcweir             const beans::Property& rProp = pProps[ n ];
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir             // Process standard UCB, DAV and HTTP properties.
1224cdf0e10cSrcweir             const uno::Any & rValue = rData.getValue( rProp.Name );
1225cdf0e10cSrcweir             if ( rValue.hasValue() )
1226cdf0e10cSrcweir             {
1227cdf0e10cSrcweir                 xRow->appendObject( rProp, rValue );
1228cdf0e10cSrcweir             }
1229cdf0e10cSrcweir             else
1230cdf0e10cSrcweir             {
1231cdf0e10cSrcweir                 // Process local Additional Properties.
1232cdf0e10cSrcweir                 if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() )
1233cdf0e10cSrcweir                 {
1234cdf0e10cSrcweir                     xAdditionalPropSet
1235cdf0e10cSrcweir                         = uno::Reference< beans::XPropertySet >(
1236cdf0e10cSrcweir                             rProvider->getAdditionalPropertySet( rContentId,
1237cdf0e10cSrcweir                                                                  sal_False ),
1238cdf0e10cSrcweir                             uno::UNO_QUERY );
1239cdf0e10cSrcweir                     bTriedToGetAdditonalPropSet = sal_True;
1240cdf0e10cSrcweir                 }
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir                 if ( !xAdditionalPropSet.is() ||
1243cdf0e10cSrcweir                      !xRow->appendPropertySetValue(
1244cdf0e10cSrcweir                                             xAdditionalPropSet, rProp ) )
1245cdf0e10cSrcweir                 {
1246cdf0e10cSrcweir                     // Append empty entry.
1247cdf0e10cSrcweir                     xRow->appendVoid( rProp );
1248cdf0e10cSrcweir                 }
1249cdf0e10cSrcweir             }
1250cdf0e10cSrcweir         }
1251cdf0e10cSrcweir     }
1252cdf0e10cSrcweir     else
1253cdf0e10cSrcweir     {
1254cdf0e10cSrcweir         // Append all standard UCB, DAV and HTTP properties.
1255cdf0e10cSrcweir 
1256cdf0e10cSrcweir         const std::auto_ptr< PropertyValueMap > & xProps = rData.getProperties();
1257cdf0e10cSrcweir 
1258cdf0e10cSrcweir         PropertyValueMap::const_iterator it  = xProps->begin();
1259cdf0e10cSrcweir         PropertyValueMap::const_iterator end = xProps->end();
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir         ContentProvider * pProvider
1262cdf0e10cSrcweir             = static_cast< ContentProvider * >( rProvider.get() );
1263cdf0e10cSrcweir         beans::Property aProp;
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir         while ( it != end )
1266cdf0e10cSrcweir         {
1267cdf0e10cSrcweir             if ( pProvider->getProperty( (*it).first, aProp ) )
1268cdf0e10cSrcweir                 xRow->appendObject( aProp, (*it).second.value() );
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir             ++it;
1271cdf0e10cSrcweir         }
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir         // Append all local Additional Properties.
1274cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xSet(
1275cdf0e10cSrcweir             rProvider->getAdditionalPropertySet( rContentId, sal_False ),
1276cdf0e10cSrcweir             uno::UNO_QUERY );
1277cdf0e10cSrcweir         xRow->appendPropertySet( xSet );
1278cdf0e10cSrcweir     }
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir     return uno::Reference< sdbc::XRow >( xRow.get() );
1281cdf0e10cSrcweir }
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir //=========================================================================
1284cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues(
1285cdf0e10cSrcweir                 const uno::Sequence< beans::Property >& rProperties,
1286cdf0e10cSrcweir                 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1287cdf0e10cSrcweir     throw ( uno::Exception )
1288cdf0e10cSrcweir {
1289cdf0e10cSrcweir     std::auto_ptr< ContentProperties > xProps;
1290cdf0e10cSrcweir     std::auto_ptr< ContentProperties > xCachedProps;
1291cdf0e10cSrcweir     std::auto_ptr< DAVResourceAccess > xResAccess;
1292cdf0e10cSrcweir     rtl::OUString aUnescapedTitle;
1293cdf0e10cSrcweir     bool bHasAll = false;
1294cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMgr;
1295cdf0e10cSrcweir     uno::Reference< ucb::XContentIdentifier > xIdentifier;
1296cdf0e10cSrcweir     rtl::Reference< ::ucbhelper::ContentProviderImplHelper > xProvider;
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir     {
1299cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1300cdf0e10cSrcweir 
130159ddfc10SAndre Fischer         aUnescapedTitle = SerfUri::unescape( m_aEscapedTitle );
1302cdf0e10cSrcweir         xSMgr.set( m_xSMgr );
1303cdf0e10cSrcweir         xIdentifier.set( m_xIdentifier );
1304cdf0e10cSrcweir         xProvider.set( m_xProvider.get() );
1305cdf0e10cSrcweir         xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir         // First, ask cache...
1308cdf0e10cSrcweir         if ( m_xCachedProps.get() )
1309cdf0e10cSrcweir         {
1310cdf0e10cSrcweir             xCachedProps.reset( new ContentProperties( *m_xCachedProps.get() ) );
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir             std::vector< rtl::OUString > aMissingProps;
1313cdf0e10cSrcweir             if ( xCachedProps->containsAllNames( rProperties, aMissingProps ) )
1314cdf0e10cSrcweir             {
1315cdf0e10cSrcweir                 // All properties are already in cache! No server access needed.
1316cdf0e10cSrcweir                 bHasAll = true;
1317cdf0e10cSrcweir             }
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir             // use the cached ContentProperties instance
1320cdf0e10cSrcweir             xProps.reset( new ContentProperties( *xCachedProps.get() ) );
1321cdf0e10cSrcweir         }
1322cdf0e10cSrcweir     }
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir     if ( !m_bTransient && !bHasAll )
1325cdf0e10cSrcweir     {
1326cdf0e10cSrcweir         /////////////////////////////////////////////////////////////////////
1327cdf0e10cSrcweir         // Obtain values from server...
1328cdf0e10cSrcweir         /////////////////////////////////////////////////////////////////////
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir         // First, identify whether resource is DAV or not
1331cdf0e10cSrcweir         const ResourceType & rType = getResourceType( xEnv, xResAccess );
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir         bool bNetworkAccessAllowed = true;
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir         if ( DAV == rType )
1336cdf0e10cSrcweir         {
1337cdf0e10cSrcweir             // cache lookup... getResourceType may fill the props cache via
1338cdf0e10cSrcweir             // PROPFIND!
1339cdf0e10cSrcweir             if ( m_xCachedProps.get() )
1340cdf0e10cSrcweir             {
1341cdf0e10cSrcweir                 xCachedProps.reset(
1342cdf0e10cSrcweir                     new ContentProperties( *m_xCachedProps.get() ) );
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir                 std::vector< rtl::OUString > aMissingProps;
1345cdf0e10cSrcweir                 if ( xCachedProps->containsAllNames(
1346cdf0e10cSrcweir                          rProperties, aMissingProps ) )
1347cdf0e10cSrcweir                 {
1348cdf0e10cSrcweir                     // All properties are already in cache! No server access
1349cdf0e10cSrcweir                     // needed.
1350cdf0e10cSrcweir                     bHasAll = true;
1351cdf0e10cSrcweir                 }
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir                 // use the cached ContentProperties instance
1354cdf0e10cSrcweir                 xProps.reset( new ContentProperties( *xCachedProps.get() ) );
1355cdf0e10cSrcweir             }
1356cdf0e10cSrcweir 
1357cdf0e10cSrcweir             if ( !bHasAll )
1358cdf0e10cSrcweir             {
1359cdf0e10cSrcweir                 // Only DAV resources support PROPFIND
1360cdf0e10cSrcweir                 std::vector< rtl::OUString > aPropNames;
1361cdf0e10cSrcweir 
1362cdf0e10cSrcweir                 uno::Sequence< beans::Property > aProperties(
1363cdf0e10cSrcweir                     rProperties.getLength() );
1364cdf0e10cSrcweir 
1365cdf0e10cSrcweir                 if ( m_aFailedPropNames.size() > 0 )
1366cdf0e10cSrcweir                 {
1367cdf0e10cSrcweir                     sal_Int32 nProps = 0;
1368cdf0e10cSrcweir                     sal_Int32 nCount = rProperties.getLength();
1369cdf0e10cSrcweir                     for ( sal_Int32 n = 0; n < nCount; ++n )
1370cdf0e10cSrcweir                     {
1371cdf0e10cSrcweir                         const rtl::OUString & rName = rProperties[ n ].Name;
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir                         std::vector< rtl::OUString >::const_iterator it
1374cdf0e10cSrcweir                             = m_aFailedPropNames.begin();
1375cdf0e10cSrcweir                         std::vector< rtl::OUString >::const_iterator end
1376cdf0e10cSrcweir                             = m_aFailedPropNames.end();
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir                         while ( it != end )
1379cdf0e10cSrcweir                         {
1380cdf0e10cSrcweir                             if ( *it == rName )
1381cdf0e10cSrcweir                                 break;
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir                             ++it;
1384cdf0e10cSrcweir                         }
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir                         if ( it == end )
1387cdf0e10cSrcweir                         {
1388cdf0e10cSrcweir                             aProperties[ nProps ] = rProperties[ n ];
1389cdf0e10cSrcweir                             nProps++;
1390cdf0e10cSrcweir                         }
1391cdf0e10cSrcweir                     }
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir                     aProperties.realloc( nProps );
1394cdf0e10cSrcweir                 }
1395cdf0e10cSrcweir                 else
1396cdf0e10cSrcweir                 {
1397cdf0e10cSrcweir                     aProperties = rProperties;
1398cdf0e10cSrcweir                 }
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir                 if ( aProperties.getLength() > 0 )
1401cdf0e10cSrcweir                     ContentProperties::UCBNamesToDAVNames(
1402cdf0e10cSrcweir                         aProperties, aPropNames );
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir                 if ( aPropNames.size() > 0 )
1405cdf0e10cSrcweir                 {
1406cdf0e10cSrcweir                     std::vector< DAVResource > resources;
1407cdf0e10cSrcweir                     try
1408cdf0e10cSrcweir                     {
1409cdf0e10cSrcweir                         xResAccess->PROPFIND(
1410cdf0e10cSrcweir                             DAVZERO, aPropNames, resources, xEnv );
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir                         if ( 1 == resources.size() )
1413cdf0e10cSrcweir                         {
1414cdf0e10cSrcweir                             if ( xProps.get())
1415cdf0e10cSrcweir                                 xProps->addProperties(
1416cdf0e10cSrcweir                                     aPropNames,
1417cdf0e10cSrcweir                                     ContentProperties( resources[ 0 ] ));
1418cdf0e10cSrcweir                             else
1419cdf0e10cSrcweir                                 xProps.reset(
1420cdf0e10cSrcweir                                     new ContentProperties( resources[ 0 ] ) );
1421cdf0e10cSrcweir                         }
1422cdf0e10cSrcweir                     }
1423cdf0e10cSrcweir                     catch ( DAVException const & e )
1424cdf0e10cSrcweir                     {
1425cdf0e10cSrcweir                         bNetworkAccessAllowed
1426cdf0e10cSrcweir                             = shouldAccessNetworkAfterException( e );
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir                         if ( !bNetworkAccessAllowed )
1429cdf0e10cSrcweir                         {
1430cdf0e10cSrcweir                             cancelCommandExecution( e, xEnv );
1431cdf0e10cSrcweir                             // unreachable
1432cdf0e10cSrcweir                         }
1433cdf0e10cSrcweir                     }
1434cdf0e10cSrcweir                 }
1435cdf0e10cSrcweir             }
1436cdf0e10cSrcweir         }
1437cdf0e10cSrcweir 
1438cdf0e10cSrcweir         if ( bNetworkAccessAllowed )
1439cdf0e10cSrcweir         {
1440cdf0e10cSrcweir             // All properties obtained already?
1441cdf0e10cSrcweir             std::vector< rtl::OUString > aMissingProps;
1442cdf0e10cSrcweir             if ( !( xProps.get()
1443cdf0e10cSrcweir                     && xProps->containsAllNames(
1444cdf0e10cSrcweir                         rProperties, aMissingProps ) )
1445f7fef0faSAriel Constenla-Haile                  || !m_bDidGetOrHead )
1446cdf0e10cSrcweir             {
1447cdf0e10cSrcweir                 // Possibly the missing props can be obtained using a HEAD
1448cdf0e10cSrcweir                 // request.
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir                 std::vector< rtl::OUString > aHeaderNames;
1451cdf0e10cSrcweir                 ContentProperties::UCBNamesToHTTPNames(
1452cdf0e10cSrcweir                     rProperties,
1453cdf0e10cSrcweir                     aHeaderNames,
1454cdf0e10cSrcweir                     true /* bIncludeUnmatched */ );
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir                 if ( aHeaderNames.size() > 0 )
1457cdf0e10cSrcweir                 {
1458cdf0e10cSrcweir                     try
1459cdf0e10cSrcweir                     {
1460cdf0e10cSrcweir                         DAVResource resource;
1461cdf0e10cSrcweir                         xResAccess->HEAD( aHeaderNames, resource, xEnv );
1462cdf0e10cSrcweir                         m_bDidGetOrHead = true;
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir                         if ( xProps.get() )
1465cdf0e10cSrcweir                             xProps->addProperties(
1466cdf0e10cSrcweir                                 aMissingProps,
1467cdf0e10cSrcweir                                 ContentProperties( resource ) );
1468cdf0e10cSrcweir                         else
1469cdf0e10cSrcweir                             xProps.reset ( new ContentProperties( resource ) );
1470cdf0e10cSrcweir 
1471cdf0e10cSrcweir                         if ( m_eResourceType == NON_DAV )
1472cdf0e10cSrcweir                             xProps->addProperties( aMissingProps,
1473cdf0e10cSrcweir                                                    ContentProperties(
1474cdf0e10cSrcweir                                                        aUnescapedTitle,
1475cdf0e10cSrcweir                                                        false ) );
1476cdf0e10cSrcweir                     }
1477cdf0e10cSrcweir                     catch ( DAVException const & e )
1478cdf0e10cSrcweir                     {
1479*c5b3447dSAriel Constenla-Haile                         // non "general-purpose servers" may not support HEAD requests
1480*c5b3447dSAriel Constenla-Haile                         // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1
1481*c5b3447dSAriel Constenla-Haile                         // In this case, perform a partial GET only to get the header info
1482*c5b3447dSAriel Constenla-Haile                         // vid. http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
1483*c5b3447dSAriel Constenla-Haile                         // WARNING if the server does not support partial GETs,
1484*c5b3447dSAriel Constenla-Haile                         // the GET will transfer the whole content
1485*c5b3447dSAriel Constenla-Haile                         bool bError = true;
1486*c5b3447dSAriel Constenla-Haile                         DAVException aLastException = e;
1487cdf0e10cSrcweir 
1488*c5b3447dSAriel Constenla-Haile                         // According to the spec. the origin server SHOULD return
1489*c5b3447dSAriel Constenla-Haile                         // * 405 (Method Not Allowed):
1490*c5b3447dSAriel Constenla-Haile                         //      the method is known but not allowed for the requested resource
1491*c5b3447dSAriel Constenla-Haile                         // * 501 (Not Implemented):
1492*c5b3447dSAriel Constenla-Haile                         //      the method is unrecognized or not implemented
1493*c5b3447dSAriel Constenla-Haile                         // TODO SC_NOT_FOUND is only for google-code server
1494*c5b3447dSAriel Constenla-Haile                         if ( aLastException.getStatus() == SC_NOT_IMPLEMENTED ||
1495*c5b3447dSAriel Constenla-Haile                                 aLastException.getStatus() == SC_METHOD_NOT_ALLOWED ||
1496*c5b3447dSAriel Constenla-Haile                                 aLastException.getStatus() == SC_NOT_FOUND )
1497cdf0e10cSrcweir                         {
1498*c5b3447dSAriel Constenla-Haile                             lcl_sendPartialGETRequest( bError,
1499*c5b3447dSAriel Constenla-Haile                                                        aLastException,
1500*c5b3447dSAriel Constenla-Haile                                                        aMissingProps,
1501*c5b3447dSAriel Constenla-Haile                                                        aHeaderNames,
1502*c5b3447dSAriel Constenla-Haile                                                        xResAccess,
1503*c5b3447dSAriel Constenla-Haile                                                        xProps,
1504*c5b3447dSAriel Constenla-Haile                                                        xEnv );
1505*c5b3447dSAriel Constenla-Haile                             m_bDidGetOrHead = !bError;
1506*c5b3447dSAriel Constenla-Haile                         }
1507*c5b3447dSAriel Constenla-Haile 
1508*c5b3447dSAriel Constenla-Haile                         if ( bError )
1509*c5b3447dSAriel Constenla-Haile                         {
1510*c5b3447dSAriel Constenla-Haile                             if ( !(bNetworkAccessAllowed
1511*c5b3447dSAriel Constenla-Haile                                     = shouldAccessNetworkAfterException( aLastException )) )
1512*c5b3447dSAriel Constenla-Haile                             {
1513*c5b3447dSAriel Constenla-Haile                                 cancelCommandExecution( aLastException, xEnv );
1514cdf0e10cSrcweir                                 // unreachable
1515cdf0e10cSrcweir                             }
1516cdf0e10cSrcweir                         }
1517cdf0e10cSrcweir                     }
1518cdf0e10cSrcweir                 }
1519cdf0e10cSrcweir             }
1520*c5b3447dSAriel Constenla-Haile         }
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir         // might trigger HTTP redirect.
1523cdf0e10cSrcweir         // Therefore, title must be updated here.
152459ddfc10SAndre Fischer         SerfUri aUri( xResAccess->getURL() );
1525cdf0e10cSrcweir         aUnescapedTitle = aUri.GetPathBaseNameUnescaped();
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir         if ( rType == UNKNOWN )
1528cdf0e10cSrcweir         {
1529cdf0e10cSrcweir             xProps.reset( new ContentProperties( aUnescapedTitle ) );
1530cdf0e10cSrcweir         }
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir         // For DAV resources we only know the Title, for non-DAV
1533cdf0e10cSrcweir         // resources we additionally know that it is a document.
1534cdf0e10cSrcweir 
1535cdf0e10cSrcweir         if ( rType == DAV )
1536cdf0e10cSrcweir         {
1537cdf0e10cSrcweir             //xProps.reset(
1538cdf0e10cSrcweir             //    new ContentProperties( aUnescapedTitle ) );
1539cdf0e10cSrcweir             xProps->addProperty(
1540cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
1541cdf0e10cSrcweir                 uno::makeAny( aUnescapedTitle ),
1542cdf0e10cSrcweir                 true );
1543cdf0e10cSrcweir         }
1544cdf0e10cSrcweir         else
1545cdf0e10cSrcweir         {
1546cdf0e10cSrcweir             if ( !xProps.get() )
1547cdf0e10cSrcweir                 xProps.reset( new ContentProperties( aUnescapedTitle, false ) );
1548cdf0e10cSrcweir             else
1549cdf0e10cSrcweir                 xProps->addProperty(
1550cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
1551cdf0e10cSrcweir                     uno::makeAny( aUnescapedTitle ),
1552cdf0e10cSrcweir                     true );
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir             xProps->addProperty(
1555cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
1556cdf0e10cSrcweir                 uno::makeAny( false ),
1557cdf0e10cSrcweir                 true );
1558cdf0e10cSrcweir             xProps->addProperty(
1559cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
1560cdf0e10cSrcweir                 uno::makeAny( true ),
1561cdf0e10cSrcweir                 true );
1562cdf0e10cSrcweir         }
1563cdf0e10cSrcweir     }
1564cdf0e10cSrcweir     else
1565cdf0e10cSrcweir     {
1566cdf0e10cSrcweir         // No server access for just created (not yet committed) objects.
1567cdf0e10cSrcweir         // Only a minimal set of properties supported at this stage.
1568cdf0e10cSrcweir         if (m_bTransient)
1569cdf0e10cSrcweir             xProps.reset( new ContentProperties( aUnescapedTitle,
1570cdf0e10cSrcweir                                                  m_bCollection ) );
1571cdf0e10cSrcweir     }
1572cdf0e10cSrcweir 
1573cdf0e10cSrcweir     sal_Int32 nCount = rProperties.getLength();
1574cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n )
1575cdf0e10cSrcweir     {
1576cdf0e10cSrcweir         const rtl::OUString rName = rProperties[ n ].Name;
1577cdf0e10cSrcweir         if ( rName.equalsAsciiL(
1578cdf0e10cSrcweir                       RTL_CONSTASCII_STRINGPARAM( "BaseURI" ) ) )
1579cdf0e10cSrcweir         {
1580cdf0e10cSrcweir             // Add BaseURI property, if requested.
1581cdf0e10cSrcweir             xProps->addProperty(
1582cdf0e10cSrcweir                  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ),
1583cdf0e10cSrcweir                  uno::makeAny( getBaseURI( xResAccess ) ),
1584cdf0e10cSrcweir                  true );
1585cdf0e10cSrcweir         }
1586cdf0e10cSrcweir         else if ( rName.equalsAsciiL(
1587cdf0e10cSrcweir                       RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) )
1588cdf0e10cSrcweir         {
1589cdf0e10cSrcweir             // Add CreatableContentsInfo property, if requested.
1590cdf0e10cSrcweir             sal_Bool bFolder = sal_False;
1591cdf0e10cSrcweir             xProps->getValue(
1592cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ) )
1593cdf0e10cSrcweir                     >>= bFolder;
1594cdf0e10cSrcweir             xProps->addProperty(
1595cdf0e10cSrcweir                 rtl::OUString(
1596cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM( "CreatableContentsInfo" ) ),
1597cdf0e10cSrcweir                 uno::makeAny( bFolder
1598cdf0e10cSrcweir                                   ? queryCreatableContentsInfo()
1599cdf0e10cSrcweir                                   : uno::Sequence< ucb::ContentInfo >() ),
1600cdf0e10cSrcweir                 true );
1601cdf0e10cSrcweir         }
1602cdf0e10cSrcweir     }
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir     uno::Reference< sdbc::XRow > xResultRow
1605cdf0e10cSrcweir         = getPropertyValues( xSMgr,
1606cdf0e10cSrcweir                              rProperties,
1607cdf0e10cSrcweir                              *xProps,
1608cdf0e10cSrcweir                              xProvider,
1609cdf0e10cSrcweir                              xIdentifier->getContentIdentifier() );
1610cdf0e10cSrcweir 
1611cdf0e10cSrcweir     {
1612cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1613cdf0e10cSrcweir 
1614cdf0e10cSrcweir         if ( !m_xCachedProps.get() )
1615cdf0e10cSrcweir             m_xCachedProps.reset( new CachableContentProperties( *xProps.get() ) );
1616cdf0e10cSrcweir         else
1617cdf0e10cSrcweir             m_xCachedProps->addProperties( *xProps.get() );
1618cdf0e10cSrcweir 
1619cdf0e10cSrcweir         m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
162059ddfc10SAndre Fischer         m_aEscapedTitle = SerfUri::escapeSegment( aUnescapedTitle );
1621cdf0e10cSrcweir     }
1622cdf0e10cSrcweir 
1623cdf0e10cSrcweir     return xResultRow;
1624cdf0e10cSrcweir }
1625cdf0e10cSrcweir 
1626cdf0e10cSrcweir //=========================================================================
1627cdf0e10cSrcweir uno::Sequence< uno::Any > Content::setPropertyValues(
1628cdf0e10cSrcweir                 const uno::Sequence< beans::PropertyValue >& rValues,
1629cdf0e10cSrcweir                 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1630cdf0e10cSrcweir     throw ( uno::Exception )
1631cdf0e10cSrcweir {
1632cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMgr;
1633cdf0e10cSrcweir     uno::Reference< ucb::XContentIdentifier >    xIdentifier;
1634cdf0e10cSrcweir     rtl::Reference< ContentProvider >            xProvider;
1635cdf0e10cSrcweir     sal_Bool bTransient;
1636cdf0e10cSrcweir     std::auto_ptr< DAVResourceAccess > xResAccess;
1637cdf0e10cSrcweir 
1638cdf0e10cSrcweir     {
1639cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir         xProvider.set( m_pProvider );
1642cdf0e10cSrcweir         xIdentifier.set( m_xIdentifier );
1643cdf0e10cSrcweir         bTransient = m_bTransient;
1644cdf0e10cSrcweir         xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
1645cdf0e10cSrcweir         xSMgr.set( m_xSMgr );
1646cdf0e10cSrcweir     }
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir     uno::Sequence< uno::Any > aRet( rValues.getLength() );
1649cdf0e10cSrcweir     uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() );
1650cdf0e10cSrcweir     sal_Int32 nChanged = 0;
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir     beans::PropertyChangeEvent aEvent;
1653cdf0e10cSrcweir     aEvent.Source         = static_cast< cppu::OWeakObject * >( this );
1654cdf0e10cSrcweir     aEvent.Further        = sal_False;
1655cdf0e10cSrcweir     // aEvent.PropertyName =
1656cdf0e10cSrcweir     aEvent.PropertyHandle = -1;
1657cdf0e10cSrcweir     // aEvent.OldValue   =
1658cdf0e10cSrcweir     // aEvent.NewValue   =
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir     std::vector< ProppatchValue > aProppatchValues;
1661cdf0e10cSrcweir     std::vector< sal_Int32 > aProppatchPropsPositions;
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir     uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet;
1664cdf0e10cSrcweir     sal_Bool bTriedToGetAdditonalPropSet = sal_False;
1665cdf0e10cSrcweir 
1666cdf0e10cSrcweir     sal_Bool bExchange = sal_False;
1667cdf0e10cSrcweir     rtl::OUString aNewTitle;
1668cdf0e10cSrcweir     rtl::OUString aOldTitle;
1669cdf0e10cSrcweir     sal_Int32 nTitlePos = -1;
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir     uno::Reference< beans::XPropertySetInfo > xInfo;
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir     const beans::PropertyValue* pValues = rValues.getConstArray();
1674cdf0e10cSrcweir     sal_Int32 nCount = rValues.getLength();
1675cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n )
1676cdf0e10cSrcweir     {
1677cdf0e10cSrcweir         const beans::PropertyValue& rValue = pValues[ n ];
1678cdf0e10cSrcweir         const rtl::OUString & rName = rValue.Name;
1679cdf0e10cSrcweir 
1680cdf0e10cSrcweir         beans::Property aTmpProp;
1681cdf0e10cSrcweir         xProvider->getProperty( rName, aTmpProp );
1682cdf0e10cSrcweir 
1683cdf0e10cSrcweir         if ( aTmpProp.Attributes & beans::PropertyAttribute::READONLY )
1684cdf0e10cSrcweir         {
1685cdf0e10cSrcweir             // Read-only property!
1686cdf0e10cSrcweir             aRet[ n ] <<= lang::IllegalAccessException(
1687cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1688cdf0e10cSrcweir                                 "Property is read-only!" ),
1689cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ) );
1690cdf0e10cSrcweir             continue;
1691cdf0e10cSrcweir         }
1692cdf0e10cSrcweir 
1693cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
1694cdf0e10cSrcweir         // Mandatory props.
1695cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////
1696cdf0e10cSrcweir 
1697cdf0e10cSrcweir         if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) )
1698cdf0e10cSrcweir         {
1699cdf0e10cSrcweir             // Read-only property!
1700cdf0e10cSrcweir             aRet[ n ] <<= lang::IllegalAccessException(
1701cdf0e10cSrcweir                 rtl::OUString::createFromAscii(
1702cdf0e10cSrcweir                     "Property is read-only!" ),
1703cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ) );
1704cdf0e10cSrcweir         }
1705cdf0e10cSrcweir         else if ( rName.equalsAsciiL(
1706cdf0e10cSrcweir                       RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) )
1707cdf0e10cSrcweir         {
1708cdf0e10cSrcweir             // Read-only property!
1709cdf0e10cSrcweir             aRet[ n ] <<= lang::IllegalAccessException(
1710cdf0e10cSrcweir                 rtl::OUString::createFromAscii(
1711cdf0e10cSrcweir                     "Property is read-only!" ),
1712cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ) );
1713cdf0e10cSrcweir         }
1714cdf0e10cSrcweir         else if ( rName.equalsAsciiL(
1715cdf0e10cSrcweir                       RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) )
1716cdf0e10cSrcweir         {
1717cdf0e10cSrcweir             // Read-only property!
1718cdf0e10cSrcweir             aRet[ n ] <<= lang::IllegalAccessException(
1719cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1720cdf0e10cSrcweir                                 "Property is read-only!" ),
1721cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ) );
1722cdf0e10cSrcweir         }
1723cdf0e10cSrcweir         else if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
1724cdf0e10cSrcweir         {
1725cdf0e10cSrcweir             rtl::OUString aNewValue;
1726cdf0e10cSrcweir             if ( rValue.Value >>= aNewValue )
1727cdf0e10cSrcweir             {
1728cdf0e10cSrcweir                 // No empty titles!
1729cdf0e10cSrcweir                 if ( aNewValue.getLength() > 0 )
1730cdf0e10cSrcweir                 {
1731cdf0e10cSrcweir                     try
1732cdf0e10cSrcweir                     {
173359ddfc10SAndre Fischer                         SerfUri aURI( xIdentifier->getContentIdentifier() );
1734cdf0e10cSrcweir                         aOldTitle = aURI.GetPathBaseNameUnescaped();
1735cdf0e10cSrcweir 
1736cdf0e10cSrcweir                         if ( aNewValue != aOldTitle )
1737cdf0e10cSrcweir                         {
1738cdf0e10cSrcweir                             // modified title -> modified URL -> exchange !
1739cdf0e10cSrcweir                             if ( !bTransient )
1740cdf0e10cSrcweir                                 bExchange = sal_True;
1741cdf0e10cSrcweir 
1742cdf0e10cSrcweir                             // new value will be set later...
1743cdf0e10cSrcweir                             aNewTitle = aNewValue;
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir                             // remember position within sequence of values (for
1746cdf0e10cSrcweir                             // error handling).
1747cdf0e10cSrcweir                             nTitlePos = n;
1748cdf0e10cSrcweir                         }
1749cdf0e10cSrcweir                     }
1750cdf0e10cSrcweir                     catch ( DAVException const & )
1751cdf0e10cSrcweir                     {
1752cdf0e10cSrcweir                         aRet[ n ] <<= lang::IllegalArgumentException(
1753cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
1754cdf0e10cSrcweir                                 "Invalid content identifier!" ),
1755cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ),
1756cdf0e10cSrcweir                             -1 );
1757cdf0e10cSrcweir                     }
1758cdf0e10cSrcweir                 }
1759cdf0e10cSrcweir                 else
1760cdf0e10cSrcweir                 {
1761cdf0e10cSrcweir                     aRet[ n ] <<= lang::IllegalArgumentException(
1762cdf0e10cSrcweir                         rtl::OUString::createFromAscii(
1763cdf0e10cSrcweir                             "Empty title not allowed!" ),
1764cdf0e10cSrcweir                         static_cast< cppu::OWeakObject * >( this ),
1765cdf0e10cSrcweir                         -1 );
1766cdf0e10cSrcweir                 }
1767cdf0e10cSrcweir             }
1768cdf0e10cSrcweir             else
1769cdf0e10cSrcweir             {
1770cdf0e10cSrcweir                 aRet[ n ] <<= beans::IllegalTypeException(
1771cdf0e10cSrcweir                     rtl::OUString::createFromAscii(
1772cdf0e10cSrcweir                         "Property value has wrong type!" ),
1773cdf0e10cSrcweir                     static_cast< cppu::OWeakObject * >( this ) );
1774cdf0e10cSrcweir             }
1775cdf0e10cSrcweir         }
1776cdf0e10cSrcweir         else
1777cdf0e10cSrcweir         {
1778cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
1779cdf0e10cSrcweir             // Optional props.
1780cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
1781cdf0e10cSrcweir 
1782cdf0e10cSrcweir             if ( !xInfo.is() )
1783cdf0e10cSrcweir                 xInfo = getPropertySetInfo( xEnv,
1784cdf0e10cSrcweir                                             sal_False /* don't cache data */ );
1785cdf0e10cSrcweir 
1786cdf0e10cSrcweir             if ( !xInfo->hasPropertyByName( rName ) )
1787cdf0e10cSrcweir             {
1788cdf0e10cSrcweir                 // Check, whether property exists. Skip otherwise.
1789cdf0e10cSrcweir                 // PROPPATCH::set would add the property automatically, which
1790cdf0e10cSrcweir                 // is not allowed for "setPropertyValues" command!
1791cdf0e10cSrcweir                 aRet[ n ] <<= beans::UnknownPropertyException(
1792cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1793cdf0e10cSrcweir                                     "Property is unknown!" ),
1794cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1795cdf0e10cSrcweir                 continue;
1796cdf0e10cSrcweir             }
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir             if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) )
1799cdf0e10cSrcweir             {
1800cdf0e10cSrcweir                 // Read-only property!
1801cdf0e10cSrcweir                 aRet[ n ] <<= lang::IllegalAccessException(
1802cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1803cdf0e10cSrcweir                                     "Property is read-only!" ),
1804cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1805cdf0e10cSrcweir             }
1806cdf0e10cSrcweir             else if ( rName.equalsAsciiL(
1807cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) ) )
1808cdf0e10cSrcweir             {
1809cdf0e10cSrcweir                 // Read-only property!
1810cdf0e10cSrcweir                 aRet[ n ] <<= lang::IllegalAccessException(
1811cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1812cdf0e10cSrcweir                                     "Property is read-only!" ),
1813cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1814cdf0e10cSrcweir             }
1815cdf0e10cSrcweir             else if ( rName.equalsAsciiL(
1816cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) )
1817cdf0e10cSrcweir             {
1818cdf0e10cSrcweir                 // Read-only property!
1819cdf0e10cSrcweir                 aRet[ n ] <<= lang::IllegalAccessException(
1820cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1821cdf0e10cSrcweir                                     "Property is read-only!" ),
1822cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1823cdf0e10cSrcweir             }
1824cdf0e10cSrcweir             else if ( rName.equalsAsciiL(
1825cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
1826cdf0e10cSrcweir             {
1827cdf0e10cSrcweir                 // Read-only property!
1828cdf0e10cSrcweir                 // (but could be writable, if 'getcontenttype' would be)
1829cdf0e10cSrcweir                 aRet[ n ] <<= lang::IllegalAccessException(
1830cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1831cdf0e10cSrcweir                                     "Property is read-only!" ),
1832cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1833cdf0e10cSrcweir             }
1834cdf0e10cSrcweir             if ( rName.equalsAsciiL(
1835cdf0e10cSrcweir                      RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) )
1836cdf0e10cSrcweir             {
1837cdf0e10cSrcweir                 // Read-only property!
1838cdf0e10cSrcweir                 aRet[ n ] <<= lang::IllegalAccessException(
1839cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1840cdf0e10cSrcweir                                     "Property is read-only!" ),
1841cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1842cdf0e10cSrcweir             }
1843cdf0e10cSrcweir             else
1844cdf0e10cSrcweir             {
1845cdf0e10cSrcweir                 if ( getResourceType( xEnv, xResAccess ) == DAV )
1846cdf0e10cSrcweir                 {
1847cdf0e10cSrcweir                     // Property value will be set on server.
1848cdf0e10cSrcweir                     ProppatchValue aValue( PROPSET, rName, rValue.Value );
1849cdf0e10cSrcweir                     aProppatchValues.push_back( aValue );
1850cdf0e10cSrcweir 
1851cdf0e10cSrcweir                     // remember position within sequence of values (for
1852cdf0e10cSrcweir                     // error handling).
1853cdf0e10cSrcweir                     aProppatchPropsPositions.push_back( n );
1854cdf0e10cSrcweir                 }
1855cdf0e10cSrcweir                 else
1856cdf0e10cSrcweir                 {
1857cdf0e10cSrcweir                     // Property value will be stored in local property store.
1858cdf0e10cSrcweir                     if ( !bTriedToGetAdditonalPropSet &&
1859cdf0e10cSrcweir                          !xAdditionalPropSet.is() )
1860cdf0e10cSrcweir                     {
1861cdf0e10cSrcweir                         xAdditionalPropSet
1862cdf0e10cSrcweir                             = getAdditionalPropertySet( sal_False );
1863cdf0e10cSrcweir                         bTriedToGetAdditonalPropSet = sal_True;
1864cdf0e10cSrcweir                     }
1865cdf0e10cSrcweir 
1866cdf0e10cSrcweir                     if ( xAdditionalPropSet.is() )
1867cdf0e10cSrcweir                     {
1868cdf0e10cSrcweir                         try
1869cdf0e10cSrcweir                         {
1870cdf0e10cSrcweir                             uno::Any aOldValue
1871cdf0e10cSrcweir                                 = xAdditionalPropSet->getPropertyValue( rName );
1872cdf0e10cSrcweir                             if ( aOldValue != rValue.Value )
1873cdf0e10cSrcweir                             {
1874cdf0e10cSrcweir                                 xAdditionalPropSet->setPropertyValue(
1875cdf0e10cSrcweir                                                         rName, rValue.Value );
1876cdf0e10cSrcweir 
1877cdf0e10cSrcweir                                 aEvent.PropertyName = rName;
1878cdf0e10cSrcweir                                 aEvent.OldValue     = aOldValue;
1879cdf0e10cSrcweir                                 aEvent.NewValue     = rValue.Value;
1880cdf0e10cSrcweir 
1881cdf0e10cSrcweir                                 aChanges.getArray()[ nChanged ] = aEvent;
1882cdf0e10cSrcweir                                 nChanged++;
1883cdf0e10cSrcweir                             }
1884cdf0e10cSrcweir                         }
1885cdf0e10cSrcweir                         catch ( beans::UnknownPropertyException const & e )
1886cdf0e10cSrcweir                         {
1887cdf0e10cSrcweir                             aRet[ n ] <<= e;
1888cdf0e10cSrcweir                         }
1889cdf0e10cSrcweir                         catch ( lang::WrappedTargetException const & e )
1890cdf0e10cSrcweir                         {
1891cdf0e10cSrcweir                             aRet[ n ] <<= e;
1892cdf0e10cSrcweir                         }
1893cdf0e10cSrcweir                         catch ( beans::PropertyVetoException const & e )
1894cdf0e10cSrcweir                         {
1895cdf0e10cSrcweir                             aRet[ n ] <<= e;
1896cdf0e10cSrcweir                         }
1897cdf0e10cSrcweir                         catch ( lang::IllegalArgumentException const & e )
1898cdf0e10cSrcweir                         {
1899cdf0e10cSrcweir                             aRet[ n ] <<= e;
1900cdf0e10cSrcweir                         }
1901cdf0e10cSrcweir                     }
1902cdf0e10cSrcweir                     else
1903cdf0e10cSrcweir                     {
1904cdf0e10cSrcweir                         aRet[ n ] <<= uno::Exception(
1905cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
1906cdf0e10cSrcweir                                     "No property set for storing the value!" ),
1907cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) );
1908cdf0e10cSrcweir                     }
1909cdf0e10cSrcweir                 }
1910cdf0e10cSrcweir             }
1911cdf0e10cSrcweir         }
1912cdf0e10cSrcweir     } // for
1913cdf0e10cSrcweir 
1914cdf0e10cSrcweir     if ( !bTransient && aProppatchValues.size() )
1915cdf0e10cSrcweir     {
1916cdf0e10cSrcweir         try
1917cdf0e10cSrcweir         {
1918cdf0e10cSrcweir             // Set property values at server.
1919cdf0e10cSrcweir             xResAccess->PROPPATCH( aProppatchValues, xEnv );
1920cdf0e10cSrcweir 
1921cdf0e10cSrcweir             std::vector< ProppatchValue >::const_iterator it
1922cdf0e10cSrcweir                 = aProppatchValues.begin();
1923cdf0e10cSrcweir             std::vector< ProppatchValue >::const_iterator end
1924cdf0e10cSrcweir                 = aProppatchValues.end();
1925cdf0e10cSrcweir 
1926cdf0e10cSrcweir             while ( it != end )
1927cdf0e10cSrcweir             {
1928cdf0e10cSrcweir                 aEvent.PropertyName = (*it).name;
1929cdf0e10cSrcweir                 aEvent.OldValue     = uno::Any(); // @@@ to expensive to obtain!
1930cdf0e10cSrcweir                 aEvent.NewValue     = (*it).value;
1931cdf0e10cSrcweir 
1932cdf0e10cSrcweir                 aChanges.getArray()[ nChanged ] = aEvent;
1933cdf0e10cSrcweir                 nChanged++;
1934cdf0e10cSrcweir 
1935cdf0e10cSrcweir                 ++it;
1936cdf0e10cSrcweir             }
1937cdf0e10cSrcweir         }
1938cdf0e10cSrcweir         catch ( DAVException const & e )
1939cdf0e10cSrcweir         {
1940cdf0e10cSrcweir //            OSL_ENSURE( sal_False,
1941cdf0e10cSrcweir //                        "Content::setPropertyValues - PROPPATCH failed!" );
1942cdf0e10cSrcweir 
1943cdf0e10cSrcweir #if 1
1944cdf0e10cSrcweir             cancelCommandExecution( e, xEnv );
1945cdf0e10cSrcweir             // unreachable
1946cdf0e10cSrcweir #else
1947cdf0e10cSrcweir             // Note: PROPPATCH either sets ALL property values OR NOTHING.
1948cdf0e10cSrcweir 
1949cdf0e10cSrcweir             std::vector< sal_Int32 >::const_iterator it
1950cdf0e10cSrcweir                 = aProppatchPropsPositions.begin();
1951cdf0e10cSrcweir             std::vector< sal_Int32 >::const_iterator end
1952cdf0e10cSrcweir                 = aProppatchPropsPositions.end();
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir             while ( it != end )
1955cdf0e10cSrcweir             {
1956cdf0e10cSrcweir                 // Set error.
1957cdf0e10cSrcweir                 aRet[ (*it) ] <<= MapDAVException( e, sal_True );
1958cdf0e10cSrcweir                 ++it;
1959cdf0e10cSrcweir             }
1960cdf0e10cSrcweir #endif
1961cdf0e10cSrcweir         }
1962cdf0e10cSrcweir     }
1963cdf0e10cSrcweir 
1964cdf0e10cSrcweir     if ( bExchange )
1965cdf0e10cSrcweir     {
1966cdf0e10cSrcweir         // Assemble new content identifier...
1967cdf0e10cSrcweir 
1968cdf0e10cSrcweir         rtl::OUString aNewURL = getParentURL();
1969cdf0e10cSrcweir         if ( aNewURL.lastIndexOf( '/' ) != ( aNewURL.getLength() - 1 ) )
1970cdf0e10cSrcweir             aNewURL += rtl::OUString::createFromAscii( "/" );
1971cdf0e10cSrcweir 
197259ddfc10SAndre Fischer         aNewURL += SerfUri::escapeSegment( aNewTitle );
1973cdf0e10cSrcweir 
1974cdf0e10cSrcweir         uno::Reference< ucb::XContentIdentifier > xNewId
1975cdf0e10cSrcweir             = new ::ucbhelper::ContentIdentifier( xSMgr, aNewURL );
1976cdf0e10cSrcweir         uno::Reference< ucb::XContentIdentifier > xOldId = xIdentifier;
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir         try
1979cdf0e10cSrcweir         {
198059ddfc10SAndre Fischer             SerfUri sourceURI( xOldId->getContentIdentifier() );
198159ddfc10SAndre Fischer             SerfUri targetURI( xNewId->getContentIdentifier() );
1982cdf0e10cSrcweir             targetURI.SetScheme( sourceURI.GetScheme() );
1983cdf0e10cSrcweir 
1984cdf0e10cSrcweir             xResAccess->MOVE(
1985cdf0e10cSrcweir                 sourceURI.GetPath(), targetURI.GetURI(), sal_False, xEnv );
1986cdf0e10cSrcweir             // @@@ Should check for resources that could not be moved
1987cdf0e10cSrcweir             //     (due to source access or target overwrite) and send
1988cdf0e10cSrcweir             //     this information through the interaction handler.
1989cdf0e10cSrcweir 
1990cdf0e10cSrcweir             // @@@ Existing content should be checked to see if it needs
1991cdf0e10cSrcweir             //     to be deleted at the source
1992cdf0e10cSrcweir 
1993cdf0e10cSrcweir             // @@@ Existing content should be checked to see if it has
1994cdf0e10cSrcweir             //     been overwritten at the target
1995cdf0e10cSrcweir 
1996cdf0e10cSrcweir             if ( exchangeIdentity( xNewId ) )
1997cdf0e10cSrcweir             {
1998cdf0e10cSrcweir                 xResAccess->setURL( aNewURL );
1999cdf0e10cSrcweir 
2000cdf0e10cSrcweir // DAV resources store all additional props on server!
2001cdf0e10cSrcweir //              // Adapt Additional Core Properties.
2002cdf0e10cSrcweir //              renameAdditionalPropertySet( xOldId->getContentIdentifier(),
2003cdf0e10cSrcweir //                                           xNewId->getContentIdentifier(),
2004cdf0e10cSrcweir //                                           sal_True );
2005cdf0e10cSrcweir             }
2006cdf0e10cSrcweir             else
2007cdf0e10cSrcweir             {
2008cdf0e10cSrcweir                 // Do not set new title!
2009cdf0e10cSrcweir                 aNewTitle = rtl::OUString();
2010cdf0e10cSrcweir 
2011cdf0e10cSrcweir                 // Set error .
2012cdf0e10cSrcweir                 aRet[ nTitlePos ] <<= uno::Exception(
2013cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "Exchange failed!" ),
2014cdf0e10cSrcweir                     static_cast< cppu::OWeakObject * >( this ) );
2015cdf0e10cSrcweir             }
2016cdf0e10cSrcweir         }
2017cdf0e10cSrcweir         catch ( DAVException const & e )
2018cdf0e10cSrcweir         {
2019cdf0e10cSrcweir             // Do not set new title!
2020cdf0e10cSrcweir             aNewTitle = rtl::OUString();
2021cdf0e10cSrcweir 
2022cdf0e10cSrcweir             // Set error .
2023cdf0e10cSrcweir             aRet[ nTitlePos ] <<= MapDAVException( e, sal_True );
2024cdf0e10cSrcweir         }
2025cdf0e10cSrcweir     }
2026cdf0e10cSrcweir 
2027cdf0e10cSrcweir     if ( aNewTitle.getLength() )
2028cdf0e10cSrcweir     {
2029cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
2030cdf0e10cSrcweir 
2031cdf0e10cSrcweir         aEvent.PropertyName = rtl::OUString::createFromAscii( "Title" );
2032cdf0e10cSrcweir         aEvent.OldValue     = uno::makeAny( aOldTitle );
2033cdf0e10cSrcweir         aEvent.NewValue     = uno::makeAny( aNewTitle );
2034cdf0e10cSrcweir 
203559ddfc10SAndre Fischer         m_aEscapedTitle     = SerfUri::escapeSegment( aNewTitle );
2036cdf0e10cSrcweir 
2037cdf0e10cSrcweir         aChanges.getArray()[ nChanged ] = aEvent;
2038cdf0e10cSrcweir         nChanged++;
2039cdf0e10cSrcweir     }
2040cdf0e10cSrcweir 
2041cdf0e10cSrcweir     if ( nChanged > 0 )
2042cdf0e10cSrcweir     {
2043cdf0e10cSrcweir         aChanges.realloc( nChanged );
2044cdf0e10cSrcweir         notifyPropertiesChange( aChanges );
2045cdf0e10cSrcweir     }
2046cdf0e10cSrcweir 
2047cdf0e10cSrcweir     {
2048cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
2049cdf0e10cSrcweir         m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
2050cdf0e10cSrcweir     }
2051cdf0e10cSrcweir 
2052cdf0e10cSrcweir     return aRet;
2053cdf0e10cSrcweir }
2054cdf0e10cSrcweir 
2055cdf0e10cSrcweir //=========================================================================
2056cdf0e10cSrcweir uno::Any Content::open(
2057cdf0e10cSrcweir                 const ucb::OpenCommandArgument2 & rArg,
2058cdf0e10cSrcweir                 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2059cdf0e10cSrcweir     throw( uno::Exception )
2060cdf0e10cSrcweir {
2061cdf0e10cSrcweir     uno::Any aRet;
2062cdf0e10cSrcweir 
2063cdf0e10cSrcweir     sal_Bool bOpenFolder = ( ( rArg.Mode == ucb::OpenMode::ALL ) ||
2064cdf0e10cSrcweir                              ( rArg.Mode == ucb::OpenMode::FOLDERS ) ||
2065cdf0e10cSrcweir                              ( rArg.Mode == ucb::OpenMode::DOCUMENTS ) );
2066cdf0e10cSrcweir     if ( bOpenFolder )
2067cdf0e10cSrcweir     {
2068cdf0e10cSrcweir         if ( isFolder( xEnv ) )
2069cdf0e10cSrcweir         {
2070cdf0e10cSrcweir             // Open collection.
2071cdf0e10cSrcweir 
2072cdf0e10cSrcweir             uno::Reference< ucb::XDynamicResultSet > xSet
2073cdf0e10cSrcweir                 = new DynamicResultSet( m_xSMgr, this, rArg, xEnv );
2074cdf0e10cSrcweir             aRet <<= xSet;
2075cdf0e10cSrcweir         }
2076cdf0e10cSrcweir         else
2077cdf0e10cSrcweir         {
2078cdf0e10cSrcweir             // Error: Not a folder!
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir             rtl::OUStringBuffer aMsg;
2081cdf0e10cSrcweir             aMsg.appendAscii( "Non-folder resource cannot be "
2082cdf0e10cSrcweir                               "opened as folder! Wrong Open Mode!" );
2083cdf0e10cSrcweir 
2084cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
2085cdf0e10cSrcweir                 uno::makeAny(
2086cdf0e10cSrcweir                     lang::IllegalArgumentException(
2087cdf0e10cSrcweir                         aMsg.makeStringAndClear(),
2088cdf0e10cSrcweir                         static_cast< cppu::OWeakObject * >( this ),
2089cdf0e10cSrcweir                         -1 ) ),
2090cdf0e10cSrcweir                 xEnv );
2091cdf0e10cSrcweir             // Unreachable
2092cdf0e10cSrcweir         }
2093cdf0e10cSrcweir     }
2094cdf0e10cSrcweir 
2095cdf0e10cSrcweir     if ( rArg.Sink.is() )
2096cdf0e10cSrcweir     {
2097cdf0e10cSrcweir         // Open document.
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir         if ( ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
2100cdf0e10cSrcweir              ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) )
2101cdf0e10cSrcweir         {
2102cdf0e10cSrcweir             // Currently(?) unsupported.
2103cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
2104cdf0e10cSrcweir                 uno::makeAny(
2105cdf0e10cSrcweir                     ucb::UnsupportedOpenModeException(
2106cdf0e10cSrcweir                             rtl::OUString(),
2107cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ),
2108cdf0e10cSrcweir                             sal_Int16( rArg.Mode ) ) ),
2109cdf0e10cSrcweir                 xEnv );
2110cdf0e10cSrcweir             // Unreachable
2111cdf0e10cSrcweir         }
2112cdf0e10cSrcweir 
2113cdf0e10cSrcweir         rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
2114cdf0e10cSrcweir         uno::Reference< io::XOutputStream > xOut
2115cdf0e10cSrcweir             = uno::Reference< io::XOutputStream >( rArg.Sink, uno::UNO_QUERY );
2116cdf0e10cSrcweir         if ( xOut.is() )
2117cdf0e10cSrcweir         {
2118cdf0e10cSrcweir             // PUSH: write data
2119cdf0e10cSrcweir             try
2120cdf0e10cSrcweir             {
2121cdf0e10cSrcweir                 std::auto_ptr< DAVResourceAccess > xResAccess;
2122cdf0e10cSrcweir 
2123cdf0e10cSrcweir                 {
2124cdf0e10cSrcweir                     osl::MutexGuard aGuard( m_aMutex );
2125cdf0e10cSrcweir 
2126cdf0e10cSrcweir                     xResAccess.reset(
2127cdf0e10cSrcweir                         new DAVResourceAccess( *m_xResAccess.get() ) );
2128cdf0e10cSrcweir                 }
2129cdf0e10cSrcweir 
2130cdf0e10cSrcweir                 DAVResource aResource;
2131cdf0e10cSrcweir                 std::vector< rtl::OUString > aHeaders;
2132cdf0e10cSrcweir 
2133cdf0e10cSrcweir                 xResAccess->GET( xOut, aHeaders, aResource, xEnv );
2134cdf0e10cSrcweir                 m_bDidGetOrHead = true;
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir                 {
2137cdf0e10cSrcweir                     osl::MutexGuard aGuard( m_aMutex );
2138cdf0e10cSrcweir 
2139cdf0e10cSrcweir                     // cache headers.
2140cdf0e10cSrcweir                     if ( !m_xCachedProps.get())
2141cdf0e10cSrcweir                         m_xCachedProps.reset(
2142cdf0e10cSrcweir                             new CachableContentProperties( aResource ) );
2143cdf0e10cSrcweir                     else
2144cdf0e10cSrcweir                         m_xCachedProps->addProperties( aResource );
2145cdf0e10cSrcweir 
2146cdf0e10cSrcweir                     m_xResAccess.reset(
2147cdf0e10cSrcweir                         new DAVResourceAccess( *xResAccess.get() ) );
2148cdf0e10cSrcweir                 }
2149cdf0e10cSrcweir             }
2150cdf0e10cSrcweir             catch ( DAVException const & e )
2151cdf0e10cSrcweir             {
2152cdf0e10cSrcweir                 cancelCommandExecution( e, xEnv );
2153cdf0e10cSrcweir                 // Unreachable
2154cdf0e10cSrcweir             }
2155cdf0e10cSrcweir         }
2156cdf0e10cSrcweir         else
2157cdf0e10cSrcweir         {
2158cdf0e10cSrcweir             uno::Reference< io::XActiveDataSink > xDataSink
2159cdf0e10cSrcweir                 = uno::Reference< io::XActiveDataSink >( rArg.Sink,
2160cdf0e10cSrcweir                                                          uno::UNO_QUERY );
2161cdf0e10cSrcweir             if ( xDataSink.is() )
2162cdf0e10cSrcweir             {
2163cdf0e10cSrcweir                 // PULL: wait for client read
2164cdf0e10cSrcweir                 try
2165cdf0e10cSrcweir                 {
2166cdf0e10cSrcweir                     std::auto_ptr< DAVResourceAccess > xResAccess;
2167cdf0e10cSrcweir                     {
2168cdf0e10cSrcweir                         osl::MutexGuard aGuard( m_aMutex );
2169cdf0e10cSrcweir 
2170cdf0e10cSrcweir                         xResAccess.reset(
2171cdf0e10cSrcweir                             new DAVResourceAccess( *m_xResAccess.get() ) );
2172cdf0e10cSrcweir                     }
2173cdf0e10cSrcweir 
2174cdf0e10cSrcweir                     // fill inputsream sync; return if all data present
2175cdf0e10cSrcweir                     DAVResource aResource;
2176cdf0e10cSrcweir                     std::vector< rtl::OUString > aHeaders;
2177cdf0e10cSrcweir 
2178cdf0e10cSrcweir                     uno::Reference< io::XInputStream > xIn
2179cdf0e10cSrcweir                         = xResAccess->GET( aHeaders, aResource, xEnv );
2180cdf0e10cSrcweir                     m_bDidGetOrHead = true;
2181cdf0e10cSrcweir 
2182cdf0e10cSrcweir                     {
2183cdf0e10cSrcweir                         osl::MutexGuard aGuard( m_aMutex );
2184cdf0e10cSrcweir 
2185cdf0e10cSrcweir                         // cache headers.
2186cdf0e10cSrcweir                         if ( !m_xCachedProps.get())
2187cdf0e10cSrcweir                             m_xCachedProps.reset(
2188cdf0e10cSrcweir                                 new CachableContentProperties( aResource ) );
2189cdf0e10cSrcweir                         else
2190cdf0e10cSrcweir                             m_xCachedProps->addProperties(
2191cdf0e10cSrcweir                                 aResource.properties );
2192cdf0e10cSrcweir 
2193cdf0e10cSrcweir                         m_xResAccess.reset(
2194cdf0e10cSrcweir                             new DAVResourceAccess( *xResAccess.get() ) );
2195cdf0e10cSrcweir                     }
2196cdf0e10cSrcweir 
2197cdf0e10cSrcweir                     xDataSink->setInputStream( xIn );
2198cdf0e10cSrcweir                 }
2199cdf0e10cSrcweir                 catch ( DAVException const & e )
2200cdf0e10cSrcweir                 {
2201cdf0e10cSrcweir                     cancelCommandExecution( e, xEnv );
2202cdf0e10cSrcweir                     // Unreachable
2203cdf0e10cSrcweir                 }
2204cdf0e10cSrcweir             }
2205cdf0e10cSrcweir             else
2206cdf0e10cSrcweir             {
2207cdf0e10cSrcweir                 // Note: aOpenCommand.Sink may contain an XStream
2208cdf0e10cSrcweir                 //       implementation. Support for this type of
2209cdf0e10cSrcweir                 //       sink is optional...
2210cdf0e10cSrcweir                 ucbhelper::cancelCommandExecution(
2211cdf0e10cSrcweir                     uno::makeAny(
2212cdf0e10cSrcweir                         ucb::UnsupportedDataSinkException(
2213cdf0e10cSrcweir                             rtl::OUString(),
2214cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ),
2215cdf0e10cSrcweir                             rArg.Sink ) ),
2216cdf0e10cSrcweir                     xEnv );
2217cdf0e10cSrcweir                 // Unreachable
2218cdf0e10cSrcweir             }
2219cdf0e10cSrcweir         }
2220cdf0e10cSrcweir     }
2221cdf0e10cSrcweir 
2222cdf0e10cSrcweir     return aRet;
2223cdf0e10cSrcweir }
2224cdf0e10cSrcweir 
2225cdf0e10cSrcweir //=========================================================================
2226cdf0e10cSrcweir void Content::post(
2227cdf0e10cSrcweir                 const ucb::PostCommandArgument2 & rArg,
2228cdf0e10cSrcweir                 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2229cdf0e10cSrcweir     throw( uno::Exception )
2230cdf0e10cSrcweir {
2231cdf0e10cSrcweir     uno::Reference< io::XActiveDataSink > xSink( rArg.Sink, uno::UNO_QUERY );
2232cdf0e10cSrcweir     if ( xSink.is() )
2233cdf0e10cSrcweir     {
2234cdf0e10cSrcweir         try
2235cdf0e10cSrcweir         {
2236cdf0e10cSrcweir             std::auto_ptr< DAVResourceAccess > xResAccess;
2237cdf0e10cSrcweir             {
2238cdf0e10cSrcweir                 osl::MutexGuard aGuard( m_aMutex );
2239cdf0e10cSrcweir                 xResAccess.reset(
2240cdf0e10cSrcweir                     new DAVResourceAccess( *m_xResAccess.get() ) );
2241cdf0e10cSrcweir             }
2242cdf0e10cSrcweir 
2243cdf0e10cSrcweir             uno::Reference< io::XInputStream > xResult
2244cdf0e10cSrcweir                 = xResAccess->POST( rArg.MediaType,
2245cdf0e10cSrcweir                                     rArg.Referer,
2246cdf0e10cSrcweir                                     rArg.Source,
2247cdf0e10cSrcweir                                     xEnv );
2248cdf0e10cSrcweir 
2249cdf0e10cSrcweir             {
2250cdf0e10cSrcweir                  osl::MutexGuard aGuard( m_aMutex );
2251cdf0e10cSrcweir                  m_xResAccess.reset(
2252cdf0e10cSrcweir                      new DAVResourceAccess( *xResAccess.get() ) );
2253cdf0e10cSrcweir             }
2254cdf0e10cSrcweir 
2255cdf0e10cSrcweir             xSink->setInputStream( xResult );
2256cdf0e10cSrcweir         }
2257cdf0e10cSrcweir         catch ( DAVException const & e )
2258cdf0e10cSrcweir         {
2259cdf0e10cSrcweir             cancelCommandExecution( e, xEnv, sal_True );
2260cdf0e10cSrcweir             // Unreachable
2261cdf0e10cSrcweir         }
2262cdf0e10cSrcweir     }
2263cdf0e10cSrcweir     else
2264cdf0e10cSrcweir     {
2265cdf0e10cSrcweir         uno::Reference< io::XOutputStream > xResult( rArg.Sink, uno::UNO_QUERY );
2266cdf0e10cSrcweir         if ( xResult.is() )
2267cdf0e10cSrcweir         {
2268cdf0e10cSrcweir             try
2269cdf0e10cSrcweir             {
2270cdf0e10cSrcweir                 std::auto_ptr< DAVResourceAccess > xResAccess;
2271cdf0e10cSrcweir                 {
2272cdf0e10cSrcweir                     osl::MutexGuard aGuard( m_aMutex );
2273cdf0e10cSrcweir                     xResAccess.reset(
2274cdf0e10cSrcweir                         new DAVResourceAccess( *m_xResAccess.get() ) );
2275cdf0e10cSrcweir                 }
2276cdf0e10cSrcweir 
2277cdf0e10cSrcweir                 xResAccess->POST( rArg.MediaType,
2278cdf0e10cSrcweir                                   rArg.Referer,
2279cdf0e10cSrcweir                                   rArg.Source,
2280cdf0e10cSrcweir                                   xResult,
2281cdf0e10cSrcweir                                   xEnv );
2282cdf0e10cSrcweir 
2283cdf0e10cSrcweir                 {
2284cdf0e10cSrcweir                     osl::MutexGuard aGuard( m_aMutex );
2285cdf0e10cSrcweir                     m_xResAccess.reset(
2286cdf0e10cSrcweir                         new DAVResourceAccess( *xResAccess.get() ) );
2287cdf0e10cSrcweir                 }
2288cdf0e10cSrcweir             }
2289cdf0e10cSrcweir             catch ( DAVException const & e )
2290cdf0e10cSrcweir             {
2291cdf0e10cSrcweir                 cancelCommandExecution( e, xEnv, sal_True );
2292cdf0e10cSrcweir                 // Unreachable
2293cdf0e10cSrcweir             }
2294cdf0e10cSrcweir         }
2295cdf0e10cSrcweir         else
2296cdf0e10cSrcweir         {
2297cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
2298cdf0e10cSrcweir                 uno::makeAny(
2299cdf0e10cSrcweir                     ucb::UnsupportedDataSinkException(
2300cdf0e10cSrcweir                         rtl::OUString(),
2301cdf0e10cSrcweir                         static_cast< cppu::OWeakObject * >( this ),
2302cdf0e10cSrcweir                         rArg.Sink ) ),
2303cdf0e10cSrcweir                 xEnv );
2304cdf0e10cSrcweir             // Unreachable
2305cdf0e10cSrcweir         }
2306cdf0e10cSrcweir     }
2307cdf0e10cSrcweir }
2308cdf0e10cSrcweir 
2309cdf0e10cSrcweir //=========================================================================
2310cdf0e10cSrcweir void Content::queryChildren( ContentRefList& rChildren )
2311cdf0e10cSrcweir {
2312cdf0e10cSrcweir     // Obtain a list with a snapshot of all currently instanciated contents
2313cdf0e10cSrcweir     // from provider and extract the contents which are direct children
2314cdf0e10cSrcweir     // of this content.
2315cdf0e10cSrcweir 
2316cdf0e10cSrcweir     ::ucbhelper::ContentRefList aAllContents;
2317cdf0e10cSrcweir     m_xProvider->queryExistingContents( aAllContents );
2318cdf0e10cSrcweir 
2319cdf0e10cSrcweir     rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
2320cdf0e10cSrcweir     sal_Int32 nURLPos = aURL.lastIndexOf( '/' );
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir     if ( nURLPos != ( aURL.getLength() - 1 ) )
2323cdf0e10cSrcweir     {
2324cdf0e10cSrcweir         // No trailing slash found. Append.
2325cdf0e10cSrcweir         aURL += rtl::OUString::createFromAscii( "/" );
2326cdf0e10cSrcweir     }
2327cdf0e10cSrcweir 
2328cdf0e10cSrcweir     sal_Int32 nLen = aURL.getLength();
2329cdf0e10cSrcweir 
2330cdf0e10cSrcweir     ::ucbhelper::ContentRefList::const_iterator it  = aAllContents.begin();
2331cdf0e10cSrcweir     ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
2332cdf0e10cSrcweir 
2333cdf0e10cSrcweir     while ( it != end )
2334cdf0e10cSrcweir     {
2335cdf0e10cSrcweir         ::ucbhelper::ContentImplHelperRef xChild = (*it);
2336cdf0e10cSrcweir         rtl::OUString aChildURL
2337cdf0e10cSrcweir             = xChild->getIdentifier()->getContentIdentifier();
2338cdf0e10cSrcweir 
2339cdf0e10cSrcweir         // Is aURL a prefix of aChildURL?
2340cdf0e10cSrcweir         if ( ( aChildURL.getLength() > nLen ) &&
2341cdf0e10cSrcweir              ( aChildURL.compareTo( aURL, nLen ) == 0 ) )
2342cdf0e10cSrcweir         {
2343cdf0e10cSrcweir             sal_Int32 nPos = nLen;
2344cdf0e10cSrcweir             nPos = aChildURL.indexOf( '/', nPos );
2345cdf0e10cSrcweir 
2346cdf0e10cSrcweir             if ( ( nPos == -1 ) ||
2347cdf0e10cSrcweir                  ( nPos == ( aChildURL.getLength() - 1 ) ) )
2348cdf0e10cSrcweir             {
2349cdf0e10cSrcweir                 // No further slashes / only a final slash. It's a child!
2350cdf0e10cSrcweir                 rChildren.push_back(
235159ddfc10SAndre Fischer                     ::http_dav_ucp::Content::ContentRef(
235259ddfc10SAndre Fischer                         static_cast< ::http_dav_ucp::Content * >(
2353cdf0e10cSrcweir                             xChild.get() ) ) );
2354cdf0e10cSrcweir             }
2355cdf0e10cSrcweir         }
2356cdf0e10cSrcweir         ++it;
2357cdf0e10cSrcweir     }
2358cdf0e10cSrcweir }
2359cdf0e10cSrcweir 
2360cdf0e10cSrcweir //=========================================================================
2361cdf0e10cSrcweir void Content::insert(
2362cdf0e10cSrcweir         const uno::Reference< io::XInputStream > & xInputStream,
2363cdf0e10cSrcweir         sal_Bool bReplaceExisting,
2364cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment >& Environment )
2365cdf0e10cSrcweir     throw( uno::Exception )
2366cdf0e10cSrcweir {
2367cdf0e10cSrcweir     sal_Bool bTransient, bCollection;
2368cdf0e10cSrcweir     rtl::OUString aEscapedTitle;
2369cdf0e10cSrcweir     std::auto_ptr< DAVResourceAccess > xResAccess;
2370cdf0e10cSrcweir 
2371cdf0e10cSrcweir     {
2372cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
2373cdf0e10cSrcweir 
2374cdf0e10cSrcweir         bTransient    = m_bTransient;
2375cdf0e10cSrcweir         bCollection   = m_bCollection;
2376cdf0e10cSrcweir         aEscapedTitle = m_aEscapedTitle;
2377cdf0e10cSrcweir         xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
2378cdf0e10cSrcweir     }
2379cdf0e10cSrcweir 
2380cdf0e10cSrcweir     // Check, if all required properties are present.
2381cdf0e10cSrcweir 
2382cdf0e10cSrcweir     if ( aEscapedTitle.getLength() == 0 )
2383cdf0e10cSrcweir     {
2384cdf0e10cSrcweir         OSL_ENSURE( sal_False, "Content::insert - Title missing!" );
2385cdf0e10cSrcweir 
2386cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aProps( 1 );
2387cdf0e10cSrcweir         aProps[ 0 ] = rtl::OUString::createFromAscii( "Title" );
2388cdf0e10cSrcweir         ucbhelper::cancelCommandExecution(
2389cdf0e10cSrcweir             uno::makeAny( ucb::MissingPropertiesException(
2390cdf0e10cSrcweir                                 rtl::OUString(),
2391cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ),
2392cdf0e10cSrcweir                                 aProps ) ),
2393cdf0e10cSrcweir             Environment );
2394cdf0e10cSrcweir         // Unreachable
2395cdf0e10cSrcweir     }
2396cdf0e10cSrcweir 
2397cdf0e10cSrcweir     if ( !bReplaceExisting )
2398cdf0e10cSrcweir     {
2399cdf0e10cSrcweir         /* [RFC 2616] - HTTP
2400cdf0e10cSrcweir 
2401cdf0e10cSrcweir            The PUT method requests that the enclosed entity be stored under the
2402cdf0e10cSrcweir            supplied Request-URI. If the Request-URI refers to an already
2403cdf0e10cSrcweir            existing resource, the enclosed entity SHOULD be considered as a
2404cdf0e10cSrcweir            modified version of the one residing on the origin server.
2405cdf0e10cSrcweir         */
2406cdf0e10cSrcweir 
2407cdf0e10cSrcweir         /* [RFC 2518] - WebDAV
2408cdf0e10cSrcweir 
2409cdf0e10cSrcweir            MKCOL creates a new collection resource at the location specified by
2410cdf0e10cSrcweir            the Request-URI.  If the resource identified by the Request-URI is
2411cdf0e10cSrcweir            non-null then the MKCOL MUST fail.
2412cdf0e10cSrcweir         */
2413cdf0e10cSrcweir 
2414cdf0e10cSrcweir         // ==> Complain on PUT, continue on MKCOL.
2415cdf0e10cSrcweir         if ( !bTransient || ( bTransient && !bCollection  ) )
2416cdf0e10cSrcweir         {
241759ddfc10SAndre Fischer #undef ERROR
2418cdf0e10cSrcweir             ucb::UnsupportedNameClashException aEx(
241959ddfc10SAndre Fischer                 rtl::OUString::createFromAscii( "Unable to write without overwrite!" ),
2420cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ),
2421cdf0e10cSrcweir                 ucb::NameClash::ERROR );
2422cdf0e10cSrcweir 
2423cdf0e10cSrcweir             uno::Reference< task::XInteractionHandler > xIH;
2424cdf0e10cSrcweir 
2425cdf0e10cSrcweir             if ( Environment.is() )
2426cdf0e10cSrcweir                 xIH = Environment->getInteractionHandler();
2427cdf0e10cSrcweir 
2428cdf0e10cSrcweir             if ( xIH.is() )
2429cdf0e10cSrcweir             {
2430cdf0e10cSrcweir                 uno::Any aExAsAny( uno::makeAny( aEx ) );
2431cdf0e10cSrcweir 
2432cdf0e10cSrcweir                 rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest
2433cdf0e10cSrcweir                     = new ucbhelper::SimpleInteractionRequest(
2434cdf0e10cSrcweir                         aExAsAny,
2435cdf0e10cSrcweir                         ucbhelper::CONTINUATION_APPROVE
2436cdf0e10cSrcweir                             | ucbhelper::CONTINUATION_DISAPPROVE );
2437cdf0e10cSrcweir                 xIH->handle( xRequest.get() );
2438cdf0e10cSrcweir 
2439cdf0e10cSrcweir                 const sal_Int32 nResp = xRequest->getResponse();
2440cdf0e10cSrcweir 
2441cdf0e10cSrcweir                 switch ( nResp )
2442cdf0e10cSrcweir                 {
2443cdf0e10cSrcweir                     case ucbhelper::CONTINUATION_UNKNOWN:
2444cdf0e10cSrcweir                         // Not handled; throw.
2445cdf0e10cSrcweir                         throw aEx;
2446cdf0e10cSrcweir //                            break;
2447cdf0e10cSrcweir 
2448cdf0e10cSrcweir                     case ucbhelper::CONTINUATION_APPROVE:
2449cdf0e10cSrcweir                         // Continue -> Overwrite.
2450cdf0e10cSrcweir                         bReplaceExisting = sal_True;
2451cdf0e10cSrcweir                         break;
2452cdf0e10cSrcweir 
2453cdf0e10cSrcweir                     case ucbhelper::CONTINUATION_DISAPPROVE:
2454cdf0e10cSrcweir                         // Abort.
2455cdf0e10cSrcweir                         throw ucb::CommandFailedException(
2456cdf0e10cSrcweir                                     rtl::OUString(),
2457cdf0e10cSrcweir                                     uno::Reference< uno::XInterface >(),
2458cdf0e10cSrcweir                                     aExAsAny );
2459cdf0e10cSrcweir //                            break;
2460cdf0e10cSrcweir 
2461cdf0e10cSrcweir                     default:
2462cdf0e10cSrcweir                         OSL_ENSURE( sal_False,
2463cdf0e10cSrcweir                                     "Content::insert - "
2464cdf0e10cSrcweir                                     "Unknown interaction selection!" );
2465cdf0e10cSrcweir                         throw ucb::CommandFailedException(
2466cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
2467cdf0e10cSrcweir                                         "Unknown interaction selection!" ),
2468cdf0e10cSrcweir                                     uno::Reference< uno::XInterface >(),
2469cdf0e10cSrcweir                                     aExAsAny );
2470cdf0e10cSrcweir //                            break;
2471cdf0e10cSrcweir                 }
2472cdf0e10cSrcweir             }
2473cdf0e10cSrcweir             else
2474cdf0e10cSrcweir             {
2475cdf0e10cSrcweir                 // No IH; throw.
2476cdf0e10cSrcweir                 throw aEx;
2477cdf0e10cSrcweir             }
2478cdf0e10cSrcweir         }
2479cdf0e10cSrcweir     }
2480cdf0e10cSrcweir 
2481cdf0e10cSrcweir     if ( bTransient )
2482cdf0e10cSrcweir     {
2483cdf0e10cSrcweir         // Assemble new content identifier...
2484cdf0e10cSrcweir         rtl::OUString aURL = getParentURL();
2485cdf0e10cSrcweir         if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) )
2486cdf0e10cSrcweir             aURL += rtl::OUString::createFromAscii( "/" );
2487cdf0e10cSrcweir 
2488cdf0e10cSrcweir         aURL += aEscapedTitle;
2489cdf0e10cSrcweir 
2490cdf0e10cSrcweir         try
2491cdf0e10cSrcweir         {
2492cdf0e10cSrcweir             xResAccess->setURL( aURL );
2493cdf0e10cSrcweir 
2494cdf0e10cSrcweir             if ( bCollection )
2495cdf0e10cSrcweir                 xResAccess->MKCOL( Environment );
2496cdf0e10cSrcweir             else
2497cdf0e10cSrcweir                 xResAccess->PUT( xInputStream, Environment );
2498cdf0e10cSrcweir         }
2499cdf0e10cSrcweir         catch ( DAVException const & except )
2500cdf0e10cSrcweir         {
2501cdf0e10cSrcweir             if ( bCollection )
2502cdf0e10cSrcweir             {
2503cdf0e10cSrcweir                 if ( except.getStatus() == SC_METHOD_NOT_ALLOWED )
2504cdf0e10cSrcweir                 {
2505cdf0e10cSrcweir                     // [RFC 2518] - WebDAV
2506cdf0e10cSrcweir                     // 405 (Method Not Allowed) - MKCOL can only be
2507cdf0e10cSrcweir                     // executed on a deleted/non-existent resource.
2508cdf0e10cSrcweir 
2509cdf0e10cSrcweir                     if ( bReplaceExisting )
2510cdf0e10cSrcweir                     {
2511cdf0e10cSrcweir                         // Destroy old resource.
2512cdf0e10cSrcweir                         try
2513cdf0e10cSrcweir                         {
2514cdf0e10cSrcweir                             xResAccess->DESTROY( Environment );
2515cdf0e10cSrcweir                         }
2516cdf0e10cSrcweir                         catch ( DAVException const & e )
2517cdf0e10cSrcweir                         {
2518cdf0e10cSrcweir                             cancelCommandExecution( e, Environment, sal_True );
2519cdf0e10cSrcweir                             // Unreachable
2520cdf0e10cSrcweir                         }
2521cdf0e10cSrcweir 
2522cdf0e10cSrcweir                         // Insert (recursion!).
2523cdf0e10cSrcweir                         insert( xInputStream, bReplaceExisting, Environment );
2524cdf0e10cSrcweir 
2525cdf0e10cSrcweir                         {
2526cdf0e10cSrcweir                             osl::Guard< osl::Mutex > aGuard( m_aMutex );
2527cdf0e10cSrcweir                             m_xResAccess.reset(
2528cdf0e10cSrcweir                                 new DAVResourceAccess( *xResAccess.get() ) );
2529cdf0e10cSrcweir                         }
2530cdf0e10cSrcweir 
2531cdf0e10cSrcweir                         // Success!
2532cdf0e10cSrcweir                         return;
2533cdf0e10cSrcweir                     }
2534cdf0e10cSrcweir                     else
2535cdf0e10cSrcweir                     {
2536cdf0e10cSrcweir                         rtl::OUString aTitle;
2537cdf0e10cSrcweir                         try
2538cdf0e10cSrcweir                         {
253959ddfc10SAndre Fischer                             SerfUri aURI( aURL );
2540cdf0e10cSrcweir                             aTitle = aURI.GetPathBaseNameUnescaped();
2541cdf0e10cSrcweir                         }
2542cdf0e10cSrcweir                         catch ( DAVException const & )
2543cdf0e10cSrcweir                         {
2544cdf0e10cSrcweir                         }
2545cdf0e10cSrcweir 
2546cdf0e10cSrcweir                         ucbhelper::cancelCommandExecution(
2547cdf0e10cSrcweir                             uno::makeAny(
2548cdf0e10cSrcweir                                 ucb::NameClashException(
2549cdf0e10cSrcweir                                     rtl::OUString(),
2550cdf0e10cSrcweir                                     static_cast< cppu::OWeakObject * >( this ),
2551cdf0e10cSrcweir                                     task::InteractionClassification_ERROR,
2552cdf0e10cSrcweir                                     aTitle ) ),
2553cdf0e10cSrcweir                             Environment );
2554cdf0e10cSrcweir                         // Unreachable
2555cdf0e10cSrcweir                     }
2556cdf0e10cSrcweir                 }
2557cdf0e10cSrcweir             }
2558cdf0e10cSrcweir 
2559cdf0e10cSrcweir             cancelCommandExecution( except, Environment, sal_True );
2560cdf0e10cSrcweir             // Unreachable
2561cdf0e10cSrcweir         }
2562cdf0e10cSrcweir 
2563cdf0e10cSrcweir         {
2564cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
2565cdf0e10cSrcweir             m_xIdentifier
2566cdf0e10cSrcweir                 = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL );
2567cdf0e10cSrcweir         }
2568cdf0e10cSrcweir 
2569cdf0e10cSrcweir         inserted();
2570cdf0e10cSrcweir 
2571cdf0e10cSrcweir         {
2572cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
2573cdf0e10cSrcweir             m_bTransient = sal_False;
2574cdf0e10cSrcweir         }
2575cdf0e10cSrcweir     }
2576cdf0e10cSrcweir     else
2577cdf0e10cSrcweir     {
2578cdf0e10cSrcweir         if ( !xInputStream.is() )
2579cdf0e10cSrcweir         {
2580cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
2581cdf0e10cSrcweir                 uno::makeAny(
2582cdf0e10cSrcweir                     ucb::MissingInputStreamException(
2583cdf0e10cSrcweir                         rtl::OUString(),
2584cdf0e10cSrcweir                         static_cast< cppu::OWeakObject * >( this ) ) ),
2585cdf0e10cSrcweir                 Environment );
2586cdf0e10cSrcweir             // Unreachable
2587cdf0e10cSrcweir         }
2588cdf0e10cSrcweir 
2589cdf0e10cSrcweir         try
2590cdf0e10cSrcweir         {
2591cdf0e10cSrcweir             xResAccess->PUT( xInputStream, Environment );
2592cdf0e10cSrcweir         }
2593cdf0e10cSrcweir         catch ( DAVException const & e )
2594cdf0e10cSrcweir         {
2595cdf0e10cSrcweir             cancelCommandExecution( e, Environment, sal_True );
2596cdf0e10cSrcweir             // Unreachable
2597cdf0e10cSrcweir         }
2598cdf0e10cSrcweir     }
2599cdf0e10cSrcweir 
2600cdf0e10cSrcweir     {
2601cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
2602cdf0e10cSrcweir         m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
2603cdf0e10cSrcweir     }
2604cdf0e10cSrcweir }
2605cdf0e10cSrcweir 
2606cdf0e10cSrcweir //=========================================================================
2607cdf0e10cSrcweir void Content::transfer(
2608cdf0e10cSrcweir         const ucb::TransferInfo & rArgs,
2609cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment >& Environment )
2610cdf0e10cSrcweir     throw( uno::Exception )
2611cdf0e10cSrcweir {
2612cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xSMgr;
2613cdf0e10cSrcweir     uno::Reference< ucb::XContentIdentifier >    xIdentifier;
2614cdf0e10cSrcweir     uno::Reference< ucb::XContentProvider >      xProvider;
2615cdf0e10cSrcweir     std::auto_ptr< DAVResourceAccess > xResAccess;
2616cdf0e10cSrcweir 
2617cdf0e10cSrcweir     {
2618cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
2619cdf0e10cSrcweir 
2620cdf0e10cSrcweir         xSMgr.set( m_xSMgr );
2621cdf0e10cSrcweir         xIdentifier.set( m_xIdentifier );
2622cdf0e10cSrcweir         xProvider.set( m_xProvider.get() );
2623cdf0e10cSrcweir         xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
2624cdf0e10cSrcweir     }
2625cdf0e10cSrcweir 
2626cdf0e10cSrcweir     rtl::OUString aTargetURI;
2627cdf0e10cSrcweir     try
2628cdf0e10cSrcweir     {
262959ddfc10SAndre Fischer         SerfUri sourceURI( rArgs.SourceURL );
263059ddfc10SAndre Fischer         SerfUri targetURI( xIdentifier->getContentIdentifier() );
2631cdf0e10cSrcweir         aTargetURI = targetURI.GetPathBaseNameUnescaped();
2632cdf0e10cSrcweir 
2633cdf0e10cSrcweir         // Check source's and target's URL scheme
2634cdf0e10cSrcweir         //
2635cdf0e10cSrcweir         const rtl::OUString aScheme = sourceURI.GetScheme().toAsciiLowerCase();
2636cdf0e10cSrcweir         if ( aScheme.equalsAsciiL(
2637cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) )
2638cdf0e10cSrcweir         {
2639cdf0e10cSrcweir             sourceURI.SetScheme(
2640cdf0e10cSrcweir                 rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) );
2641cdf0e10cSrcweir         }
2642cdf0e10cSrcweir         else if ( aScheme.equalsAsciiL(
2643cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) )
2644cdf0e10cSrcweir         {
2645cdf0e10cSrcweir             sourceURI.SetScheme(
2646cdf0e10cSrcweir                 rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) );
2647cdf0e10cSrcweir         }
2648cdf0e10cSrcweir         else if ( aScheme.equalsAsciiL(
2649cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME ) ) )
2650cdf0e10cSrcweir         {
2651cdf0e10cSrcweir             sourceURI.SetScheme(
2652cdf0e10cSrcweir                 rtl::OUString::createFromAscii( HTTPS_URL_SCHEME ) );
2653cdf0e10cSrcweir         }
2654cdf0e10cSrcweir         else
2655cdf0e10cSrcweir         {
2656cdf0e10cSrcweir             if ( !aScheme.equalsAsciiL(
2657cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( HTTP_URL_SCHEME ) ) &&
2658cdf0e10cSrcweir                  !aScheme.equalsAsciiL(
2659cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( HTTPS_URL_SCHEME ) ) )
2660cdf0e10cSrcweir             {
2661cdf0e10cSrcweir                 ucbhelper::cancelCommandExecution(
2662cdf0e10cSrcweir                     uno::makeAny(
2663cdf0e10cSrcweir                         ucb::InteractiveBadTransferURLException(
2664cdf0e10cSrcweir                             rtl::OUString::createFromAscii(
2665cdf0e10cSrcweir                                 "Unsupported URL scheme!" ),
2666cdf0e10cSrcweir                             static_cast< cppu::OWeakObject * >( this ) ) ),
2667cdf0e10cSrcweir                     Environment );
2668cdf0e10cSrcweir                 // Unreachable
2669cdf0e10cSrcweir             }
2670cdf0e10cSrcweir         }
2671cdf0e10cSrcweir 
2672cdf0e10cSrcweir         if ( targetURI.GetScheme().toAsciiLowerCase().equalsAsciiL(
2673cdf0e10cSrcweir                  RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) )
2674cdf0e10cSrcweir             targetURI.SetScheme(
2675cdf0e10cSrcweir                 rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) );
2676cdf0e10cSrcweir         else if ( targetURI.GetScheme().toAsciiLowerCase().equalsAsciiL(
2677cdf0e10cSrcweir                  RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) )
2678cdf0e10cSrcweir             targetURI.SetScheme(
2679cdf0e10cSrcweir                 rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) );
2680cdf0e10cSrcweir 
2681cdf0e10cSrcweir         // @@@ This implementation of 'transfer' only works
2682cdf0e10cSrcweir         //     if the source and target are located at same host.
2683cdf0e10cSrcweir         //     (Neon does not support cross-server copy/move)
2684cdf0e10cSrcweir 
2685cdf0e10cSrcweir         // Check for same host
2686cdf0e10cSrcweir         //
2687cdf0e10cSrcweir         if ( sourceURI.GetHost().getLength() &&
2688cdf0e10cSrcweir              ( sourceURI.GetHost() != targetURI.GetHost() ) )
2689cdf0e10cSrcweir         {
2690cdf0e10cSrcweir             ucbhelper::cancelCommandExecution(
2691cdf0e10cSrcweir                 uno::makeAny( ucb::InteractiveBadTransferURLException(
2692cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
2693cdf0e10cSrcweir                                     "Different hosts!" ),
2694cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ) ) ),
2695cdf0e10cSrcweir                 Environment );
2696cdf0e10cSrcweir             // Unreachable
2697cdf0e10cSrcweir         }
2698cdf0e10cSrcweir 
2699cdf0e10cSrcweir         rtl::OUString aTitle = rArgs.NewTitle;
2700cdf0e10cSrcweir 
2701cdf0e10cSrcweir         if ( !aTitle.getLength() )
2702cdf0e10cSrcweir             aTitle = sourceURI.GetPathBaseNameUnescaped();
2703cdf0e10cSrcweir 
2704cdf0e10cSrcweir         if ( aTitle.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "/" ) ) )
2705cdf0e10cSrcweir         {
2706cdf0e10cSrcweir             // kso: ???
2707cdf0e10cSrcweir             aTitle = rtl::OUString();
2708cdf0e10cSrcweir         }
2709cdf0e10cSrcweir 
2710cdf0e10cSrcweir         targetURI.AppendPath( aTitle );
2711cdf0e10cSrcweir 
2712cdf0e10cSrcweir         rtl::OUString aTargetURL = xIdentifier->getContentIdentifier();
2713cdf0e10cSrcweir         if ( ( aTargetURL.lastIndexOf( '/' ) + 1 )
2714cdf0e10cSrcweir                 != aTargetURL.getLength() )
2715cdf0e10cSrcweir             aTargetURL += rtl::OUString::createFromAscii( "/" );
2716cdf0e10cSrcweir 
2717cdf0e10cSrcweir         aTargetURL += aTitle;
2718cdf0e10cSrcweir 
2719cdf0e10cSrcweir         uno::Reference< ucb::XContentIdentifier > xTargetId
2720cdf0e10cSrcweir             = new ::ucbhelper::ContentIdentifier( xSMgr, aTargetURL );
2721cdf0e10cSrcweir 
2722cdf0e10cSrcweir         DAVResourceAccess aSourceAccess( xSMgr,
2723cdf0e10cSrcweir                                          xResAccess->getSessionFactory(),
2724cdf0e10cSrcweir                                          sourceURI.GetURI() );
2725cdf0e10cSrcweir 
2726cdf0e10cSrcweir         if ( rArgs.MoveData == sal_True )
2727cdf0e10cSrcweir         {
2728cdf0e10cSrcweir             uno::Reference< ucb::XContentIdentifier > xId
2729cdf0e10cSrcweir                 = new ::ucbhelper::ContentIdentifier( xSMgr, rArgs.SourceURL );
2730cdf0e10cSrcweir 
2731cdf0e10cSrcweir             // Note: The static cast is okay here, because its sure that
2732cdf0e10cSrcweir             //       xProvider is always the WebDAVContentProvider.
2733cdf0e10cSrcweir             rtl::Reference< Content > xSource
2734cdf0e10cSrcweir                 = static_cast< Content * >(
2735cdf0e10cSrcweir                     xProvider->queryContent( xId ).get() );
2736cdf0e10cSrcweir 
2737cdf0e10cSrcweir             // [RFC 2518] - WebDAV
2738cdf0e10cSrcweir             // If a resource exists at the destination and the Overwrite
2739cdf0e10cSrcweir             // header is "T" then prior to performing the move the server
2740cdf0e10cSrcweir             // MUST perform a DELETE with "Depth: infinity" on the
2741cdf0e10cSrcweir             // destination resource.  If the Overwrite header is set to
2742cdf0e10cSrcweir             // "F" then the operation will fail.
2743cdf0e10cSrcweir 
2744cdf0e10cSrcweir             aSourceAccess.MOVE( sourceURI.GetPath(),
2745cdf0e10cSrcweir                                 targetURI.GetURI(),
2746cdf0e10cSrcweir                                 rArgs.NameClash
2747cdf0e10cSrcweir                                     == ucb::NameClash::OVERWRITE,
2748cdf0e10cSrcweir                                 Environment );
2749cdf0e10cSrcweir 
2750cdf0e10cSrcweir             if ( xSource.is() )
2751cdf0e10cSrcweir             {
2752cdf0e10cSrcweir                 // Propagate destruction to listeners.
2753cdf0e10cSrcweir                 xSource->destroy( sal_True );
2754cdf0e10cSrcweir             }
2755cdf0e10cSrcweir 
2756cdf0e10cSrcweir // DAV resources store all additional props on server!
2757cdf0e10cSrcweir //              // Rename own and all children's Additional Core Properties.
2758cdf0e10cSrcweir //              renameAdditionalPropertySet( xId->getContentIdentifier(),
2759cdf0e10cSrcweir //                                           xTargetId->getContentIdentifier(),
2760cdf0e10cSrcweir //                                           sal_True );
2761cdf0e10cSrcweir         }
2762cdf0e10cSrcweir         else
2763cdf0e10cSrcweir         {
2764cdf0e10cSrcweir             // [RFC 2518] - WebDAV
2765cdf0e10cSrcweir             // If a resource exists at the destination and the Overwrite
2766cdf0e10cSrcweir             // header is "T" then prior to performing the copy the server
2767cdf0e10cSrcweir             // MUST perform a DELETE with "Depth: infinity" on the
2768cdf0e10cSrcweir             // destination resource.  If the Overwrite header is set to
2769cdf0e10cSrcweir             // "F" then the operation will fail.
2770cdf0e10cSrcweir 
2771cdf0e10cSrcweir             aSourceAccess.COPY( sourceURI.GetPath(),
2772cdf0e10cSrcweir                                 targetURI.GetURI(),
2773cdf0e10cSrcweir                                 rArgs.NameClash
2774cdf0e10cSrcweir                                     == ucb::NameClash::OVERWRITE,
2775cdf0e10cSrcweir                                 Environment );
2776cdf0e10cSrcweir 
2777cdf0e10cSrcweir // DAV resources store all additional props on server!
2778cdf0e10cSrcweir //              // Copy own and all children's Additional Core Properties.
2779cdf0e10cSrcweir //              copyAdditionalPropertySet( xId->getContentIdentifier(),
2780cdf0e10cSrcweir //                                         xTargetId->getContentIdentifier(),
2781cdf0e10cSrcweir //                                         sal_True );
2782cdf0e10cSrcweir         }
2783cdf0e10cSrcweir 
2784cdf0e10cSrcweir         // Note: The static cast is okay here, because its sure that
2785cdf0e10cSrcweir         //       xProvider is always the WebDAVContentProvider.
2786cdf0e10cSrcweir         rtl::Reference< Content > xTarget
2787cdf0e10cSrcweir             = static_cast< Content * >(
2788cdf0e10cSrcweir                     xProvider->queryContent( xTargetId ).get() );
2789cdf0e10cSrcweir 
2790cdf0e10cSrcweir         // Announce transfered content in its new folder.
2791cdf0e10cSrcweir         xTarget->inserted();
2792cdf0e10cSrcweir     }
2793cdf0e10cSrcweir     catch ( ucb::IllegalIdentifierException const & )
2794cdf0e10cSrcweir     {
2795cdf0e10cSrcweir         // queryContent
2796cdf0e10cSrcweir     }
2797cdf0e10cSrcweir     catch ( DAVException const & e )
2798cdf0e10cSrcweir     {
2799cdf0e10cSrcweir         // [RFC 2518] - WebDAV
2800cdf0e10cSrcweir         // 412 (Precondition Failed) - The server was unable to maintain
2801cdf0e10cSrcweir         // the liveness of the properties listed in the propertybehavior
2802cdf0e10cSrcweir         // XML element or the Overwrite header is "F" and the state of
2803cdf0e10cSrcweir         // the destination resource is non-null.
2804cdf0e10cSrcweir 
2805cdf0e10cSrcweir         if ( e.getStatus() == SC_PRECONDITION_FAILED )
2806cdf0e10cSrcweir         {
2807cdf0e10cSrcweir             switch ( rArgs.NameClash )
2808cdf0e10cSrcweir             {
280959ddfc10SAndre Fischer                 case 0/*ucb::NameClash::ERROR*/:
2810cdf0e10cSrcweir                 {
2811cdf0e10cSrcweir                     ucbhelper::cancelCommandExecution(
2812cdf0e10cSrcweir                         uno::makeAny(
2813cdf0e10cSrcweir                             ucb::NameClashException(
2814cdf0e10cSrcweir                                 rtl::OUString(),
2815cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ),
2816cdf0e10cSrcweir                                 task::InteractionClassification_ERROR,
2817cdf0e10cSrcweir                                 aTargetURI ) ),
2818cdf0e10cSrcweir                         Environment );
2819cdf0e10cSrcweir                     // Unreachable
2820cdf0e10cSrcweir                 }
2821cdf0e10cSrcweir 
2822cdf0e10cSrcweir                 case ucb::NameClash::OVERWRITE:
2823cdf0e10cSrcweir                     break;
2824cdf0e10cSrcweir 
2825cdf0e10cSrcweir                 case ucb::NameClash::KEEP: // deprecated
2826cdf0e10cSrcweir                 case ucb::NameClash::RENAME:
2827cdf0e10cSrcweir                 case ucb::NameClash::ASK:
2828cdf0e10cSrcweir                 default:
2829cdf0e10cSrcweir                 {
2830cdf0e10cSrcweir                     ucbhelper::cancelCommandExecution(
2831cdf0e10cSrcweir                         uno::makeAny(
2832cdf0e10cSrcweir                             ucb::UnsupportedNameClashException(
2833cdf0e10cSrcweir                                 rtl::OUString(),
2834cdf0e10cSrcweir                                 static_cast< cppu::OWeakObject * >( this ),
2835cdf0e10cSrcweir                                 rArgs.NameClash ) ),
2836cdf0e10cSrcweir                         Environment );
2837cdf0e10cSrcweir                     // Unreachable
2838cdf0e10cSrcweir                 }
2839cdf0e10cSrcweir             }
2840cdf0e10cSrcweir         }
2841cdf0e10cSrcweir 
2842cdf0e10cSrcweir         cancelCommandExecution( e, Environment, sal_True );
2843cdf0e10cSrcweir         // Unreachable
2844cdf0e10cSrcweir     }
2845cdf0e10cSrcweir 
2846cdf0e10cSrcweir     {
2847cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
2848cdf0e10cSrcweir         m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
2849cdf0e10cSrcweir     }
2850cdf0e10cSrcweir }
2851cdf0e10cSrcweir 
2852cdf0e10cSrcweir //=========================================================================
2853cdf0e10cSrcweir void Content::destroy( sal_Bool bDeletePhysical )
2854cdf0e10cSrcweir     throw( uno::Exception )
2855cdf0e10cSrcweir {
2856cdf0e10cSrcweir     // @@@ take care about bDeletePhysical -> trashcan support
2857cdf0e10cSrcweir     rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
2858cdf0e10cSrcweir 
2859cdf0e10cSrcweir     uno::Reference< ucb::XContent > xThis = this;
2860cdf0e10cSrcweir 
2861cdf0e10cSrcweir     deleted();
2862cdf0e10cSrcweir 
2863cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
2864cdf0e10cSrcweir 
2865cdf0e10cSrcweir     // Process instanciated children...
2866cdf0e10cSrcweir 
286759ddfc10SAndre Fischer     ::http_dav_ucp::Content::ContentRefList aChildren;
2868cdf0e10cSrcweir     queryChildren( aChildren );
2869cdf0e10cSrcweir 
2870cdf0e10cSrcweir     ContentRefList::const_iterator it  = aChildren.begin();
2871cdf0e10cSrcweir     ContentRefList::const_iterator end = aChildren.end();
2872cdf0e10cSrcweir 
2873cdf0e10cSrcweir     while ( it != end )
2874cdf0e10cSrcweir     {
2875cdf0e10cSrcweir         (*it)->destroy( bDeletePhysical );
2876cdf0e10cSrcweir         ++it;
2877cdf0e10cSrcweir     }
2878cdf0e10cSrcweir }
2879cdf0e10cSrcweir 
2880cdf0e10cSrcweir //=========================================================================
2881cdf0e10cSrcweir bool Content::supportsExclusiveWriteLock(
2882cdf0e10cSrcweir   const uno::Reference< ucb::XCommandEnvironment >& Environment )
2883cdf0e10cSrcweir {
2884cdf0e10cSrcweir     if ( getResourceType( Environment ) == DAV )
2885cdf0e10cSrcweir     {
2886cdf0e10cSrcweir         if ( m_xCachedProps.get() )
2887cdf0e10cSrcweir         {
2888cdf0e10cSrcweir             uno::Sequence< ucb::LockEntry > aSupportedLocks;
2889cdf0e10cSrcweir             if ( m_xCachedProps->getValue( DAVProperties::SUPPORTEDLOCK )
2890cdf0e10cSrcweir                 >>= aSupportedLocks )
2891cdf0e10cSrcweir             {
2892cdf0e10cSrcweir                 for ( sal_Int32 n = 0; n < aSupportedLocks.getLength(); ++n )
2893cdf0e10cSrcweir                 {
2894cdf0e10cSrcweir                     if ( aSupportedLocks[ n ].Scope
2895cdf0e10cSrcweir                             == ucb::LockScope_EXCLUSIVE &&
2896cdf0e10cSrcweir                          aSupportedLocks[ n ].Type
2897cdf0e10cSrcweir                             == ucb::LockType_WRITE )
2898cdf0e10cSrcweir                         return true;
2899cdf0e10cSrcweir                 }
2900cdf0e10cSrcweir             }
2901cdf0e10cSrcweir         }
2902cdf0e10cSrcweir     }
2903cdf0e10cSrcweir     return false;
2904cdf0e10cSrcweir }
2905cdf0e10cSrcweir 
2906cdf0e10cSrcweir //=========================================================================
2907cdf0e10cSrcweir void Content::lock(
2908cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment >& Environment )
2909cdf0e10cSrcweir     throw( uno::Exception )
2910cdf0e10cSrcweir {
2911cdf0e10cSrcweir     try
2912cdf0e10cSrcweir     {
2913cdf0e10cSrcweir         std::auto_ptr< DAVResourceAccess > xResAccess;
2914cdf0e10cSrcweir         {
2915cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
2916cdf0e10cSrcweir             xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
2917cdf0e10cSrcweir         }
2918cdf0e10cSrcweir 
2919cdf0e10cSrcweir         uno::Any aOwnerAny;
2920cdf0e10cSrcweir         aOwnerAny
2921cdf0e10cSrcweir             <<= rtl::OUString::createFromAscii( "http://ucb.openoffice.org" );
2922cdf0e10cSrcweir 
2923cdf0e10cSrcweir         ucb::Lock aLock(
2924cdf0e10cSrcweir             ucb::LockScope_EXCLUSIVE,
2925cdf0e10cSrcweir             ucb::LockType_WRITE,
2926cdf0e10cSrcweir             ucb::LockDepth_ZERO,
2927cdf0e10cSrcweir             aOwnerAny,
2928cdf0e10cSrcweir             180, // lock timeout in secs
2929cdf0e10cSrcweir             //-1, // infinite lock
2930cdf0e10cSrcweir             uno::Sequence< ::rtl::OUString >() );
2931cdf0e10cSrcweir 
2932cdf0e10cSrcweir         xResAccess->LOCK( aLock, Environment );
2933cdf0e10cSrcweir 
2934cdf0e10cSrcweir         {
2935cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
2936cdf0e10cSrcweir             m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
2937cdf0e10cSrcweir         }
2938cdf0e10cSrcweir     }
2939cdf0e10cSrcweir     catch ( DAVException const & e )
2940cdf0e10cSrcweir     {
2941cdf0e10cSrcweir         cancelCommandExecution( e, Environment, sal_False );
2942cdf0e10cSrcweir         // Unreachable
2943cdf0e10cSrcweir     }
2944cdf0e10cSrcweir }
2945cdf0e10cSrcweir 
2946cdf0e10cSrcweir //=========================================================================
2947cdf0e10cSrcweir void Content::unlock(
2948cdf0e10cSrcweir         const uno::Reference< ucb::XCommandEnvironment >& Environment )
2949cdf0e10cSrcweir     throw( uno::Exception )
2950cdf0e10cSrcweir {
2951cdf0e10cSrcweir     try
2952cdf0e10cSrcweir     {
2953cdf0e10cSrcweir         std::auto_ptr< DAVResourceAccess > xResAccess;
2954cdf0e10cSrcweir         {
2955cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
2956cdf0e10cSrcweir             xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
2957cdf0e10cSrcweir         }
2958cdf0e10cSrcweir 
2959cdf0e10cSrcweir         xResAccess->UNLOCK( Environment );
2960cdf0e10cSrcweir 
2961cdf0e10cSrcweir         {
2962cdf0e10cSrcweir             osl::Guard< osl::Mutex > aGuard( m_aMutex );
2963cdf0e10cSrcweir             m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
2964cdf0e10cSrcweir         }
2965cdf0e10cSrcweir     }
2966cdf0e10cSrcweir     catch ( DAVException const & e )
2967cdf0e10cSrcweir     {
2968cdf0e10cSrcweir         cancelCommandExecution( e, Environment, sal_False );
2969cdf0e10cSrcweir         // Unreachable
2970cdf0e10cSrcweir     }
2971cdf0e10cSrcweir }
2972cdf0e10cSrcweir 
2973cdf0e10cSrcweir //=========================================================================
2974cdf0e10cSrcweir sal_Bool Content::exchangeIdentity(
2975cdf0e10cSrcweir     const uno::Reference< ucb::XContentIdentifier >& xNewId )
2976cdf0e10cSrcweir {
2977cdf0e10cSrcweir     if ( !xNewId.is() )
2978cdf0e10cSrcweir         return sal_False;
2979cdf0e10cSrcweir 
2980cdf0e10cSrcweir     osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
2981cdf0e10cSrcweir 
2982cdf0e10cSrcweir     uno::Reference< ucb::XContent > xThis = this;
2983cdf0e10cSrcweir 
2984cdf0e10cSrcweir     // Already persistent?
2985cdf0e10cSrcweir     if ( m_bTransient )
2986cdf0e10cSrcweir     {
2987cdf0e10cSrcweir         OSL_ENSURE( sal_False, "Content::exchangeIdentity - Not persistent!" );
2988cdf0e10cSrcweir         return sal_False;
2989cdf0e10cSrcweir     }
2990cdf0e10cSrcweir 
2991cdf0e10cSrcweir     // Exchange own identitity.
2992cdf0e10cSrcweir 
2993cdf0e10cSrcweir     // Fail, if a content with given id already exists.
2994cdf0e10cSrcweir //  if ( !hasData( xNewId ) )
2995cdf0e10cSrcweir     {
2996cdf0e10cSrcweir         rtl::OUString aOldURL = m_xIdentifier->getContentIdentifier();
2997cdf0e10cSrcweir 
2998cdf0e10cSrcweir         aGuard.clear();
2999cdf0e10cSrcweir         if ( exchange( xNewId ) )
3000cdf0e10cSrcweir         {
3001cdf0e10cSrcweir             // Process instanciated children...
3002cdf0e10cSrcweir 
3003cdf0e10cSrcweir             ContentRefList aChildren;
3004cdf0e10cSrcweir             queryChildren( aChildren );
3005cdf0e10cSrcweir 
3006cdf0e10cSrcweir             ContentRefList::const_iterator it  = aChildren.begin();
3007cdf0e10cSrcweir             ContentRefList::const_iterator end = aChildren.end();
3008cdf0e10cSrcweir 
3009cdf0e10cSrcweir             while ( it != end )
3010cdf0e10cSrcweir             {
3011cdf0e10cSrcweir                 ContentRef xChild = (*it);
3012cdf0e10cSrcweir 
3013cdf0e10cSrcweir                 // Create new content identifier for the child...
3014cdf0e10cSrcweir                 uno::Reference< ucb::XContentIdentifier >
3015cdf0e10cSrcweir                     xOldChildId = xChild->getIdentifier();
3016cdf0e10cSrcweir                 rtl::OUString aOldChildURL
3017cdf0e10cSrcweir                     = xOldChildId->getContentIdentifier();
3018cdf0e10cSrcweir                 rtl::OUString aNewChildURL
3019cdf0e10cSrcweir                     = aOldChildURL.replaceAt(
3020cdf0e10cSrcweir                         0,
3021cdf0e10cSrcweir                         aOldURL.getLength(),
3022cdf0e10cSrcweir                         xNewId->getContentIdentifier() );
3023cdf0e10cSrcweir                 uno::Reference< ucb::XContentIdentifier > xNewChildId
3024cdf0e10cSrcweir                     = new ::ucbhelper::ContentIdentifier(
3025cdf0e10cSrcweir                         m_xSMgr, aNewChildURL );
3026cdf0e10cSrcweir 
3027cdf0e10cSrcweir                 if ( !xChild->exchangeIdentity( xNewChildId ) )
3028cdf0e10cSrcweir                     return sal_False;
3029cdf0e10cSrcweir 
3030cdf0e10cSrcweir                 ++it;
3031cdf0e10cSrcweir             }
3032cdf0e10cSrcweir             return sal_True;
3033cdf0e10cSrcweir         }
3034cdf0e10cSrcweir     }
3035cdf0e10cSrcweir 
3036cdf0e10cSrcweir     OSL_ENSURE( sal_False,
3037cdf0e10cSrcweir                 "Content::exchangeIdentity - "
3038cdf0e10cSrcweir                 "Panic! Cannot exchange identity!" );
3039cdf0e10cSrcweir     return sal_False;
3040cdf0e10cSrcweir }
3041cdf0e10cSrcweir 
3042cdf0e10cSrcweir //=========================================================================
3043cdf0e10cSrcweir sal_Bool Content::isFolder(
3044cdf0e10cSrcweir             const uno::Reference< ucb::XCommandEnvironment >& xEnv )
3045cdf0e10cSrcweir     throw( uno::Exception )
3046cdf0e10cSrcweir {
3047cdf0e10cSrcweir     {
3048cdf0e10cSrcweir         osl::MutexGuard aGuard( m_aMutex );
3049cdf0e10cSrcweir 
3050cdf0e10cSrcweir         if ( m_bTransient )
3051cdf0e10cSrcweir             return m_bCollection;
3052cdf0e10cSrcweir     }
3053cdf0e10cSrcweir 
3054cdf0e10cSrcweir     uno::Sequence< beans::Property > aProperties( 1 );
3055cdf0e10cSrcweir     aProperties[ 0 ].Name   = rtl::OUString::createFromAscii( "IsFolder" );
3056cdf0e10cSrcweir     aProperties[ 0 ].Handle = -1;
3057cdf0e10cSrcweir     uno::Reference< sdbc::XRow > xRow( getPropertyValues( aProperties, xEnv ) );
3058cdf0e10cSrcweir     if ( xRow.is() )
3059cdf0e10cSrcweir     {
3060cdf0e10cSrcweir         try
3061cdf0e10cSrcweir         {
3062cdf0e10cSrcweir             return xRow->getBoolean( 1 );
3063cdf0e10cSrcweir         }
3064cdf0e10cSrcweir         catch ( sdbc::SQLException const & )
3065cdf0e10cSrcweir         {
3066cdf0e10cSrcweir         }
3067cdf0e10cSrcweir     }
3068cdf0e10cSrcweir 
3069cdf0e10cSrcweir     return sal_False;
3070cdf0e10cSrcweir }
3071cdf0e10cSrcweir 
3072cdf0e10cSrcweir //=========================================================================
3073cdf0e10cSrcweir uno::Any Content::MapDAVException( const DAVException & e, sal_Bool bWrite )
3074cdf0e10cSrcweir {
3075cdf0e10cSrcweir     // Map DAVException...
3076cdf0e10cSrcweir     uno::Any aException;
3077cdf0e10cSrcweir 
3078cdf0e10cSrcweir     rtl::OUString aURL;
3079cdf0e10cSrcweir     if ( m_bTransient )
3080cdf0e10cSrcweir     {
3081cdf0e10cSrcweir         aURL = getParentURL();
3082cdf0e10cSrcweir         if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) )
3083cdf0e10cSrcweir             aURL += rtl::OUString::createFromAscii( "/" );
3084cdf0e10cSrcweir 
3085cdf0e10cSrcweir         aURL += m_aEscapedTitle;
3086cdf0e10cSrcweir     }
3087cdf0e10cSrcweir     else
3088cdf0e10cSrcweir     {
3089cdf0e10cSrcweir         aURL = m_xIdentifier->getContentIdentifier();
3090cdf0e10cSrcweir     }
3091cdf0e10cSrcweir 
3092cdf0e10cSrcweir     switch ( e.getStatus() )
3093cdf0e10cSrcweir     {
3094cdf0e10cSrcweir         case SC_NOT_FOUND:
3095cdf0e10cSrcweir         {
3096cdf0e10cSrcweir             uno::Sequence< uno::Any > aArgs( 1 );
3097cdf0e10cSrcweir             aArgs[ 0 ] <<= beans::PropertyValue(
3098cdf0e10cSrcweir                 rtl::OUString::createFromAscii("Uri"), -1,
3099cdf0e10cSrcweir                 uno::makeAny(aURL),
3100cdf0e10cSrcweir                 beans::PropertyState_DIRECT_VALUE);
3101cdf0e10cSrcweir 
3102cdf0e10cSrcweir             aException <<=
3103cdf0e10cSrcweir                 ucb::InteractiveAugmentedIOException(
3104cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "Not found!" ),
3105cdf0e10cSrcweir                     static_cast< cppu::OWeakObject * >( this ),
3106cdf0e10cSrcweir                     task::InteractionClassification_ERROR,
3107cdf0e10cSrcweir                     ucb::IOErrorCode_NOT_EXISTING,
3108cdf0e10cSrcweir                     aArgs );
3109cdf0e10cSrcweir             return aException;
3110cdf0e10cSrcweir         }
3111cdf0e10cSrcweir         default:
3112cdf0e10cSrcweir             break;
3113cdf0e10cSrcweir     }
3114cdf0e10cSrcweir 
3115cdf0e10cSrcweir     switch ( e.getError() )
3116cdf0e10cSrcweir     {
3117cdf0e10cSrcweir     case DAVException::DAV_HTTP_ERROR:
3118cdf0e10cSrcweir         {
3119cdf0e10cSrcweir             if ( bWrite )
3120cdf0e10cSrcweir                 aException <<=
3121cdf0e10cSrcweir                     ucb::InteractiveNetworkWriteException(
3122cdf0e10cSrcweir                         e.getData(),
3123cdf0e10cSrcweir                         static_cast< cppu::OWeakObject * >( this ),
3124cdf0e10cSrcweir                         task::InteractionClassification_ERROR,
3125cdf0e10cSrcweir                         e.getData() );
3126cdf0e10cSrcweir             else
3127cdf0e10cSrcweir                 aException <<=
3128cdf0e10cSrcweir                     ucb::InteractiveNetworkReadException(
3129cdf0e10cSrcweir                         e.getData(),
3130cdf0e10cSrcweir                         static_cast< cppu::OWeakObject * >( this ),
3131cdf0e10cSrcweir                         task::InteractionClassification_ERROR,
3132cdf0e10cSrcweir                         e.getData() );
3133cdf0e10cSrcweir             break;
3134cdf0e10cSrcweir         }
3135cdf0e10cSrcweir 
3136cdf0e10cSrcweir     case DAVException::DAV_HTTP_LOOKUP:
3137cdf0e10cSrcweir         aException <<=
3138cdf0e10cSrcweir             ucb::InteractiveNetworkResolveNameException(
3139cdf0e10cSrcweir                 rtl::OUString(),
3140cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ),
3141cdf0e10cSrcweir                 task::InteractionClassification_ERROR,
3142cdf0e10cSrcweir                 e.getData() );
3143cdf0e10cSrcweir         break;
3144cdf0e10cSrcweir 
3145cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3146cdf0e10cSrcweir //    case DAVException::DAV_HTTP_AUTH:
3147cdf0e10cSrcweir //        break;
3148cdf0e10cSrcweir 
3149cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3150cdf0e10cSrcweir //    case DAVException::DAV_HTTP_AUTHPROXY:
3151cdf0e10cSrcweir //        break;
3152cdf0e10cSrcweir 
3153cdf0e10cSrcweir     case DAVException::DAV_HTTP_CONNECT:
3154cdf0e10cSrcweir         aException <<=
3155cdf0e10cSrcweir             ucb::InteractiveNetworkConnectException(
3156cdf0e10cSrcweir                 rtl::OUString(),
3157cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ),
3158cdf0e10cSrcweir                 task::InteractionClassification_ERROR,
3159cdf0e10cSrcweir                 e.getData() );
3160cdf0e10cSrcweir         break;
3161cdf0e10cSrcweir 
3162cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3163cdf0e10cSrcweir //    case DAVException::DAV_HTTP_TIMEOUT:
3164cdf0e10cSrcweir //        break;
3165cdf0e10cSrcweir 
3166cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3167cdf0e10cSrcweir //     case DAVException::DAV_HTTP_REDIRECT:
3168cdf0e10cSrcweir //         break;
3169cdf0e10cSrcweir 
3170cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3171cdf0e10cSrcweir //     case DAVException::DAV_SESSION_CREATE:
3172cdf0e10cSrcweir //         break;
3173cdf0e10cSrcweir 
3174cdf0e10cSrcweir     case DAVException::DAV_INVALID_ARG:
3175cdf0e10cSrcweir         aException <<=
3176cdf0e10cSrcweir             lang::IllegalArgumentException(
3177cdf0e10cSrcweir                 rtl::OUString(),
3178cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ),
3179cdf0e10cSrcweir                 -1 );
3180cdf0e10cSrcweir         break;
3181cdf0e10cSrcweir 
3182cdf0e10cSrcweir     case DAVException::DAV_LOCKED:
3183cdf0e10cSrcweir #if 1
3184cdf0e10cSrcweir         aException <<=
3185cdf0e10cSrcweir             ucb::InteractiveLockingLockedException(
3186cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "Locked!" ),
3187cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ),
3188cdf0e10cSrcweir                 task::InteractionClassification_ERROR,
3189cdf0e10cSrcweir                 aURL,
3190cdf0e10cSrcweir                 sal_False ); // not SelfOwned
3191cdf0e10cSrcweir #else
3192cdf0e10cSrcweir         {
3193cdf0e10cSrcweir             uno::Sequence< uno::Any > aArgs( 1 );
3194cdf0e10cSrcweir             aArgs[ 0 ] <<= beans::PropertyValue(
3195cdf0e10cSrcweir                 rtl::OUString::createFromAscii("Uri"), -1,
3196cdf0e10cSrcweir                 uno::makeAny(aURL),
3197cdf0e10cSrcweir                 beans::PropertyState_DIRECT_VALUE);
3198cdf0e10cSrcweir 
3199cdf0e10cSrcweir             aException <<=
3200cdf0e10cSrcweir                 ucb::InteractiveAugmentedIOException(
3201cdf0e10cSrcweir                     rtl::OUString::createFromAscii( "Locked!" ),
3202cdf0e10cSrcweir                     static_cast< cppu::OWeakObject * >( this ),
3203cdf0e10cSrcweir                     task::InteractionClassification_ERROR,
3204cdf0e10cSrcweir                     ucb::IOErrorCode_LOCKING_VIOLATION,
3205cdf0e10cSrcweir                     aArgs );
3206cdf0e10cSrcweir         }
3207cdf0e10cSrcweir #endif
3208cdf0e10cSrcweir         break;
3209cdf0e10cSrcweir 
3210cdf0e10cSrcweir     case DAVException::DAV_LOCKED_SELF:
3211cdf0e10cSrcweir         aException <<=
3212cdf0e10cSrcweir             ucb::InteractiveLockingLockedException(
3213cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "Locked (self)!" ),
3214cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ),
3215cdf0e10cSrcweir                 task::InteractionClassification_ERROR,
3216cdf0e10cSrcweir                 aURL,
3217cdf0e10cSrcweir                 sal_True ); // SelfOwned
3218cdf0e10cSrcweir         break;
3219cdf0e10cSrcweir 
3220cdf0e10cSrcweir     case DAVException::DAV_NOT_LOCKED:
3221cdf0e10cSrcweir         aException <<=
3222cdf0e10cSrcweir             ucb::InteractiveLockingNotLockedException(
3223cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "Not locked!" ),
3224cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ),
3225cdf0e10cSrcweir                 task::InteractionClassification_ERROR,
3226cdf0e10cSrcweir                 aURL );
3227cdf0e10cSrcweir         break;
3228cdf0e10cSrcweir 
3229cdf0e10cSrcweir     case DAVException::DAV_LOCK_EXPIRED:
3230cdf0e10cSrcweir         aException <<=
3231cdf0e10cSrcweir             ucb::InteractiveLockingLockExpiredException(
3232cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "Lock expired!" ),
3233cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ),
3234cdf0e10cSrcweir                 task::InteractionClassification_ERROR,
3235cdf0e10cSrcweir                 aURL );
3236cdf0e10cSrcweir         break;
3237cdf0e10cSrcweir 
3238cdf0e10cSrcweir     default:
3239cdf0e10cSrcweir         aException <<=
3240cdf0e10cSrcweir             ucb::InteractiveNetworkGeneralException(
3241cdf0e10cSrcweir                 rtl::OUString(),
3242cdf0e10cSrcweir                 static_cast< cppu::OWeakObject * >( this ),
3243cdf0e10cSrcweir                 task::InteractionClassification_ERROR );
3244cdf0e10cSrcweir         break;
3245cdf0e10cSrcweir     }
3246cdf0e10cSrcweir 
3247cdf0e10cSrcweir     return aException;
3248cdf0e10cSrcweir }
3249cdf0e10cSrcweir 
3250cdf0e10cSrcweir //=========================================================================
3251cdf0e10cSrcweir // static
3252cdf0e10cSrcweir bool Content::shouldAccessNetworkAfterException( const DAVException & e )
3253cdf0e10cSrcweir {
3254cdf0e10cSrcweir     if ( ( e.getStatus() == SC_NOT_FOUND ) ||
3255cdf0e10cSrcweir          ( e.getError() == DAVException::DAV_HTTP_LOOKUP ) ||
3256cdf0e10cSrcweir          ( e.getError() == DAVException::DAV_HTTP_CONNECT ) ||
3257cdf0e10cSrcweir          ( e.getError() == DAVException::DAV_HTTP_AUTH ) ||
3258cdf0e10cSrcweir          ( e.getError() == DAVException::DAV_HTTP_AUTHPROXY ) )
3259cdf0e10cSrcweir         return false;
3260cdf0e10cSrcweir 
3261cdf0e10cSrcweir     return true;
3262cdf0e10cSrcweir }
3263cdf0e10cSrcweir 
3264cdf0e10cSrcweir //=========================================================================
3265cdf0e10cSrcweir void Content::cancelCommandExecution(
3266cdf0e10cSrcweir                 const DAVException & e,
3267cdf0e10cSrcweir                 const uno::Reference< ucb::XCommandEnvironment > & xEnv,
3268cdf0e10cSrcweir                 sal_Bool bWrite /* = sal_False */ )
3269cdf0e10cSrcweir     throw ( uno::Exception )
3270cdf0e10cSrcweir {
3271cdf0e10cSrcweir     ucbhelper::cancelCommandExecution( MapDAVException( e, bWrite ), xEnv );
3272cdf0e10cSrcweir     // Unreachable
3273cdf0e10cSrcweir }
3274cdf0e10cSrcweir 
3275cdf0e10cSrcweir //=========================================================================
3276cdf0e10cSrcweir const rtl::OUString
3277cdf0e10cSrcweir Content::getBaseURI( const std::auto_ptr< DAVResourceAccess > & rResAccess )
3278cdf0e10cSrcweir {
3279cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( m_aMutex );
3280cdf0e10cSrcweir 
3281cdf0e10cSrcweir     // First, try to obtain value of response header "Content-Location".
3282cdf0e10cSrcweir     if ( m_xCachedProps.get() )
3283cdf0e10cSrcweir     {
3284cdf0e10cSrcweir         rtl::OUString aLocation;
3285cdf0e10cSrcweir         m_xCachedProps->getValue( rtl::OUString(
3286cdf0e10cSrcweir                                     RTL_CONSTASCII_USTRINGPARAM(
3287cdf0e10cSrcweir                                         "Content-Location" ) ) ) >>= aLocation;
3288cdf0e10cSrcweir         if ( aLocation.getLength() )
3289cdf0e10cSrcweir         {
3290cdf0e10cSrcweir             try
3291cdf0e10cSrcweir             {
3292cdf0e10cSrcweir                 // Do not use m_xIdentifier->getContentIdentifier() because it
3293cdf0e10cSrcweir                 // for example does not reflect redirects applied to requests
3294cdf0e10cSrcweir                 // done using the original URI but m_xResAccess' URI does.
3295cdf0e10cSrcweir                 return rtl::Uri::convertRelToAbs( rResAccess->getURL(),
3296cdf0e10cSrcweir                                                   aLocation );
3297cdf0e10cSrcweir             }
3298cdf0e10cSrcweir             catch ( rtl::MalformedUriException const & )
3299cdf0e10cSrcweir             {
3300cdf0e10cSrcweir             }
3301cdf0e10cSrcweir         }
3302cdf0e10cSrcweir     }
3303cdf0e10cSrcweir 
3304cdf0e10cSrcweir     return rtl::OUString( rResAccess->getURL() );
3305cdf0e10cSrcweir }
3306cdf0e10cSrcweir 
3307cdf0e10cSrcweir //=========================================================================
3308cdf0e10cSrcweir const Content::ResourceType & Content::getResourceType(
3309cdf0e10cSrcweir                     const uno::Reference< ucb::XCommandEnvironment >& xEnv,
3310cdf0e10cSrcweir                     const std::auto_ptr< DAVResourceAccess > & rResAccess )
3311cdf0e10cSrcweir     throw ( uno::Exception )
3312cdf0e10cSrcweir {
3313cdf0e10cSrcweir     if ( m_eResourceType == UNKNOWN )
3314cdf0e10cSrcweir     {
3315cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( m_aMutex );
3316cdf0e10cSrcweir 
3317cdf0e10cSrcweir         ResourceType eResourceType;
3318cdf0e10cSrcweir         eResourceType = m_eResourceType;
3319cdf0e10cSrcweir 
3320cdf0e10cSrcweir         const rtl::OUString & rURL = rResAccess->getURL();
3321cdf0e10cSrcweir         const rtl::OUString aScheme(
3322cdf0e10cSrcweir             rURL.copy( 0, rURL.indexOf( ':' ) ).toAsciiLowerCase() );
3323cdf0e10cSrcweir 
3324cdf0e10cSrcweir         try
3325cdf0e10cSrcweir         {
3326cdf0e10cSrcweir             // Try to fetch some frequently used property value, e.g. those
3327cdf0e10cSrcweir             // used when loading documents... along with identifying whether
3328cdf0e10cSrcweir             // this is a DAV resource.
3329cdf0e10cSrcweir             std::vector< DAVResource > resources;
3330cdf0e10cSrcweir             std::vector< rtl::OUString > aPropNames;
3331cdf0e10cSrcweir             uno::Sequence< beans::Property > aProperties( 5 );
3332cdf0e10cSrcweir             aProperties[ 0 ].Name
3333cdf0e10cSrcweir                 = rtl::OUString::createFromAscii( "IsFolder" );
3334cdf0e10cSrcweir             aProperties[ 1 ].Name
3335cdf0e10cSrcweir                 = rtl::OUString::createFromAscii( "IsDocument" );
3336cdf0e10cSrcweir             aProperties[ 2 ].Name
3337cdf0e10cSrcweir                 = rtl::OUString::createFromAscii( "IsReadOnly" );
3338cdf0e10cSrcweir             aProperties[ 3 ].Name
3339cdf0e10cSrcweir                 = rtl::OUString::createFromAscii( "MediaType" );
3340cdf0e10cSrcweir             aProperties[ 4 ].Name
3341cdf0e10cSrcweir                 = DAVProperties::SUPPORTEDLOCK;
3342cdf0e10cSrcweir 
3343cdf0e10cSrcweir             ContentProperties::UCBNamesToDAVNames(
3344cdf0e10cSrcweir                 aProperties, aPropNames );
3345cdf0e10cSrcweir 
3346cdf0e10cSrcweir             rResAccess->PROPFIND(
3347cdf0e10cSrcweir                 DAVZERO, aPropNames, resources, xEnv );
3348cdf0e10cSrcweir 
334959ddfc10SAndre Fischer             // TODO - is this really only one?
3350cdf0e10cSrcweir             if ( resources.size() == 1 )
3351cdf0e10cSrcweir             {
3352cdf0e10cSrcweir                 m_xCachedProps.reset(
3353cdf0e10cSrcweir                     new CachableContentProperties( resources[ 0 ] ) );
3354cdf0e10cSrcweir                 m_xCachedProps->containsAllNames(
3355cdf0e10cSrcweir                     aProperties, m_aFailedPropNames );
3356cdf0e10cSrcweir             }
3357cdf0e10cSrcweir 
3358cdf0e10cSrcweir             eResourceType = DAV;
3359cdf0e10cSrcweir         }
3360cdf0e10cSrcweir         catch ( DAVException const & e )
3361cdf0e10cSrcweir         {
3362cdf0e10cSrcweir             rResAccess->resetUri();
3363cdf0e10cSrcweir 
3364cdf0e10cSrcweir             if ( e.getStatus() == SC_METHOD_NOT_ALLOWED )
3365cdf0e10cSrcweir             {
3366cdf0e10cSrcweir                 // Status SC_METHOD_NOT_ALLOWED is a safe indicator that the
3367cdf0e10cSrcweir                 // resource is NON_DAV
3368cdf0e10cSrcweir                 eResourceType = NON_DAV;
3369cdf0e10cSrcweir             }
3370fb7f54d2SOliver-Rainer Wittmann             // cancel command execution is case that no user authentication data has been provided.
3371fb7f54d2SOliver-Rainer Wittmann             if ( e.getError() == DAVException::DAV_HTTP_NOAUTH )
3372fb7f54d2SOliver-Rainer Wittmann             {
3373fb7f54d2SOliver-Rainer Wittmann                 cancelCommandExecution( e, uno::Reference< ucb::XCommandEnvironment >() );
3374fb7f54d2SOliver-Rainer Wittmann             }
3375cdf0e10cSrcweir         }
3376cdf0e10cSrcweir         m_eResourceType = eResourceType;
3377cdf0e10cSrcweir     }
3378cdf0e10cSrcweir     return m_eResourceType;
3379cdf0e10cSrcweir }
3380cdf0e10cSrcweir 
3381cdf0e10cSrcweir //=========================================================================
3382cdf0e10cSrcweir const Content::ResourceType & Content::getResourceType(
3383cdf0e10cSrcweir                     const uno::Reference< ucb::XCommandEnvironment >& xEnv )
3384cdf0e10cSrcweir     throw ( uno::Exception )
3385cdf0e10cSrcweir {
3386cdf0e10cSrcweir     return getResourceType( xEnv, m_xResAccess );
3387cdf0e10cSrcweir }
3388