12f86921cSAndrew Rist /**************************************************************
22f86921cSAndrew Rist *
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
102f86921cSAndrew Rist *
112f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
122f86921cSAndrew Rist *
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.
192f86921cSAndrew Rist *
202f86921cSAndrew Rist *************************************************************/
212f86921cSAndrew Rist
222f86921cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25421ed02eSdamjan #include "precompiled_webdav.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir TODO
29cdf0e10cSrcweir **************************************************************************
30cdf0e10cSrcweir
31cdf0e10cSrcweir *************************************************************************/
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <osl/diagnose.h>
34c1c10f68SAriel Constenla-Haile #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>
569c0c1533SAndrea Pescetti #include <com/sun/star/ucb/InteractiveLockingLockNotAvailableException.hpp>
57c1c10f68SAriel Constenla-Haile #include <com/sun/star/ucb/InteractiveLockingLockedException.hpp>
58c1c10f68SAriel Constenla-Haile #include <com/sun/star/ucb/InteractiveLockingLockExpiredException.hpp>
59c1c10f68SAriel Constenla-Haile #include <com/sun/star/ucb/InteractiveLockingNotLockedException.hpp>
60cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp>
61cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkGeneralException.hpp>
62cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkReadException.hpp>
63cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp>
64cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp>
65cdf0e10cSrcweir #include <com/sun/star/ucb/MissingInputStreamException.hpp>
66cdf0e10cSrcweir #include <com/sun/star/ucb/MissingPropertiesException.hpp>
67cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
68cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp>
69cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
70cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
71cdf0e10cSrcweir #include <com/sun/star/ucb/PostCommandArgument2.hpp>
7206594b87SAriel Constenla-Haile #include <com/sun/star/ucb/PropertyCommandArgument.hpp>
73cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
74cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
75cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
76cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
77cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
78cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp>
79cdf0e10cSrcweir #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
80cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
81cdf0e10cSrcweir
82cdf0e10cSrcweir #include "webdavcontent.hxx"
83cdf0e10cSrcweir #include "webdavprovider.hxx"
84cdf0e10cSrcweir #include "webdavresultset.hxx"
85cdf0e10cSrcweir #include "ContentProperties.hxx"
86*9646dec5SDamjan Jovanovic #include "CurlUri.hxx"
87cdf0e10cSrcweir #include "UCBDeadPropertyValue.hxx"
889c0c1533SAndrea Pescetti #include <boost/current_function.hpp>
89cdf0e10cSrcweir
90cdf0e10cSrcweir using namespace com::sun::star;
9159ddfc10SAndre Fischer using namespace http_dav_ucp;
92cdf0e10cSrcweir
93c5b3447dSAriel Constenla-Haile namespace
94c5b3447dSAriel Constenla-Haile {
lcl_sendPartialGETRequest(bool & bError,DAVException & aLastException,const std::vector<rtl::OUString> aProps,std::vector<rtl::OUString> & aHeaderNames,const std::auto_ptr<DAVResourceAccess> & xResAccess,std::auto_ptr<ContentProperties> & xProps,const uno::Reference<ucb::XCommandEnvironment> & xEnv)95c5b3447dSAriel Constenla-Haile static void lcl_sendPartialGETRequest( bool &bError,
96c5b3447dSAriel Constenla-Haile DAVException &aLastException,
97c5b3447dSAriel Constenla-Haile const std::vector< rtl::OUString > aProps,
98c5b3447dSAriel Constenla-Haile std::vector< rtl::OUString > &aHeaderNames,
99c5b3447dSAriel Constenla-Haile const std::auto_ptr< DAVResourceAccess > &xResAccess,
100c5b3447dSAriel Constenla-Haile std::auto_ptr< ContentProperties > &xProps,
101c5b3447dSAriel Constenla-Haile const uno::Reference< ucb::XCommandEnvironment >& xEnv )
102c5b3447dSAriel Constenla-Haile {
103c5b3447dSAriel Constenla-Haile bool bIsRequestSize = false;
104c5b3447dSAriel Constenla-Haile DAVResource aResource;
105c5b3447dSAriel Constenla-Haile DAVRequestHeaders aPartialGet;
106c5b3447dSAriel Constenla-Haile aPartialGet.push_back(
107c5b3447dSAriel Constenla-Haile DAVRequestHeader(
108c5b3447dSAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Range" ) ),
109c5b3447dSAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "bytes=0-0" ))));
110c5b3447dSAriel Constenla-Haile
111c5b3447dSAriel Constenla-Haile for ( std::vector< rtl::OUString >::const_iterator it = aHeaderNames.begin();
112c5b3447dSAriel Constenla-Haile it != aHeaderNames.end(); it++ )
113c5b3447dSAriel Constenla-Haile {
114c5b3447dSAriel Constenla-Haile if ( it->equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
115c5b3447dSAriel Constenla-Haile {
116c5b3447dSAriel Constenla-Haile bIsRequestSize = true;
117c5b3447dSAriel Constenla-Haile break;
118c5b3447dSAriel Constenla-Haile }
119c5b3447dSAriel Constenla-Haile }
120c5b3447dSAriel Constenla-Haile
121c5b3447dSAriel Constenla-Haile if ( bIsRequestSize )
122c5b3447dSAriel Constenla-Haile {
123c5b3447dSAriel Constenla-Haile // we need to know if the server accepts range requests for a resource
124c5b3447dSAriel Constenla-Haile // and the range unit it uses
125c5b3447dSAriel Constenla-Haile aHeaderNames.push_back( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Accept-Ranges" ) ) );
126c5b3447dSAriel Constenla-Haile aHeaderNames.push_back( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Content-Range" ) ) );
127c5b3447dSAriel Constenla-Haile }
128c5b3447dSAriel Constenla-Haile try
129c5b3447dSAriel Constenla-Haile {
130c5b3447dSAriel Constenla-Haile uno::Reference< io::XInputStream > xIn = xResAccess->GET( aPartialGet,
131c5b3447dSAriel Constenla-Haile aHeaderNames,
132c5b3447dSAriel Constenla-Haile aResource,
133c5b3447dSAriel Constenla-Haile xEnv );
134c5b3447dSAriel Constenla-Haile bError = false;
135c5b3447dSAriel Constenla-Haile
136c5b3447dSAriel Constenla-Haile if ( bIsRequestSize )
137c5b3447dSAriel Constenla-Haile {
138c5b3447dSAriel Constenla-Haile // the ContentProperties maps "Content-Length" to the UCB "Size" property
139c5b3447dSAriel Constenla-Haile // This would have an unrealistic value of 1 byte because we did only a partial GET
140c5b3447dSAriel Constenla-Haile // Solution: if "Content-Range" is present, map it with UCB "Size" property
141c5b3447dSAriel Constenla-Haile rtl::OUString aAcceptRanges, aContentRange, aContentLength;
142c5b3447dSAriel Constenla-Haile std::vector< DAVPropertyValue > &aResponseProps = aResource.properties;
143c5b3447dSAriel Constenla-Haile for ( std::vector< DAVPropertyValue >::const_iterator it = aResponseProps.begin();
144c5b3447dSAriel Constenla-Haile it != aResponseProps.end(); it++ )
145c5b3447dSAriel Constenla-Haile {
146c5b3447dSAriel Constenla-Haile if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Accept-Ranges" ) ) )
147c5b3447dSAriel Constenla-Haile it->Value >>= aAcceptRanges;
148c5b3447dSAriel Constenla-Haile else if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Range" ) ) )
149c5b3447dSAriel Constenla-Haile it->Value >>= aContentRange;
150c5b3447dSAriel Constenla-Haile else if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
151c5b3447dSAriel Constenla-Haile it->Value >>= aContentLength;
152c5b3447dSAriel Constenla-Haile }
153c5b3447dSAriel Constenla-Haile
154c5b3447dSAriel Constenla-Haile sal_Int64 nSize = 1;
155c5b3447dSAriel Constenla-Haile if ( aContentLength.getLength() )
156c5b3447dSAriel Constenla-Haile {
157c5b3447dSAriel Constenla-Haile nSize = aContentLength.toInt64();
158c5b3447dSAriel Constenla-Haile }
159c5b3447dSAriel Constenla-Haile
160c5b3447dSAriel Constenla-Haile // according to http://tools.ietf.org/html/rfc2616#section-3.12
161c5b3447dSAriel Constenla-Haile // the only range unit defined is "bytes" and implementations
162c5b3447dSAriel Constenla-Haile // MAY ignore ranges specified using other units.
163c5b3447dSAriel Constenla-Haile if ( nSize == 1 &&
164c5b3447dSAriel Constenla-Haile aContentRange.getLength() &&
165c5b3447dSAriel Constenla-Haile aAcceptRanges.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "bytes" ) ) )
166c5b3447dSAriel Constenla-Haile {
167c5b3447dSAriel Constenla-Haile // Parse the Content-Range to get the size
168c5b3447dSAriel Constenla-Haile // vid. http://tools.ietf.org/html/rfc2616#section-14.16
169c5b3447dSAriel Constenla-Haile // Content-Range: <range unit> <bytes range>/<size>
170c5b3447dSAriel Constenla-Haile sal_Int32 nSlash = aContentRange.lastIndexOf( sal_Unicode('/'));
171c5b3447dSAriel Constenla-Haile if ( nSlash != -1 )
172c5b3447dSAriel Constenla-Haile {
173c5b3447dSAriel Constenla-Haile rtl::OUString aSize = aContentRange.copy( nSlash + 1 );
174c5b3447dSAriel Constenla-Haile // "*" means that the instance-length is unknown at the time when the response was generated
175c5b3447dSAriel Constenla-Haile if ( !aSize.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "*" )))
176c5b3447dSAriel Constenla-Haile {
177c5b3447dSAriel Constenla-Haile for ( std::vector< DAVPropertyValue >::iterator it = aResponseProps.begin();
178c5b3447dSAriel Constenla-Haile it != aResponseProps.end(); it++ )
179c5b3447dSAriel Constenla-Haile {
180c5b3447dSAriel Constenla-Haile if ( it->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
181c5b3447dSAriel Constenla-Haile {
182c5b3447dSAriel Constenla-Haile it->Value <<= aSize;
183c5b3447dSAriel Constenla-Haile break;
184c5b3447dSAriel Constenla-Haile }
185c5b3447dSAriel Constenla-Haile }
186c5b3447dSAriel Constenla-Haile }
187c5b3447dSAriel Constenla-Haile }
188c5b3447dSAriel Constenla-Haile }
189c5b3447dSAriel Constenla-Haile }
190c5b3447dSAriel Constenla-Haile
191c5b3447dSAriel Constenla-Haile if ( xProps.get() )
192c5b3447dSAriel Constenla-Haile xProps->addProperties(
193c5b3447dSAriel Constenla-Haile aProps,
194c5b3447dSAriel Constenla-Haile ContentProperties( aResource ) );
195c5b3447dSAriel Constenla-Haile else
196c5b3447dSAriel Constenla-Haile xProps.reset ( new ContentProperties( aResource ) );
197c5b3447dSAriel Constenla-Haile }
198c5b3447dSAriel Constenla-Haile catch ( DAVException const & ex )
199c5b3447dSAriel Constenla-Haile {
200c5b3447dSAriel Constenla-Haile aLastException = ex;
201c5b3447dSAriel Constenla-Haile }
202c5b3447dSAriel Constenla-Haile }
203c5b3447dSAriel Constenla-Haile }
204c5b3447dSAriel Constenla-Haile
205cdf0e10cSrcweir //=========================================================================
206cdf0e10cSrcweir //=========================================================================
207cdf0e10cSrcweir //
208cdf0e10cSrcweir // Content Implementation.
209cdf0e10cSrcweir //
210cdf0e10cSrcweir //=========================================================================
211cdf0e10cSrcweir //=========================================================================
212cdf0e10cSrcweir
213cdf0e10cSrcweir //=========================================================================
214cdf0e10cSrcweir // ctr for content on an existing webdav resource
Content(const uno::Reference<lang::XMultiServiceFactory> & rxSMgr,ContentProvider * pProvider,const uno::Reference<ucb::XContentIdentifier> & Identifier,rtl::Reference<DAVSessionFactory> const & rSessionFactory)215cdf0e10cSrcweir Content::Content(
216cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
217cdf0e10cSrcweir ContentProvider* pProvider,
218cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier,
219cdf0e10cSrcweir rtl::Reference< DAVSessionFactory > const & rSessionFactory )
220cdf0e10cSrcweir throw ( ucb::ContentCreationException )
221cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ),
222cdf0e10cSrcweir m_eResourceType( UNKNOWN ),
223cdf0e10cSrcweir m_pProvider( pProvider ),
224cdf0e10cSrcweir m_bTransient( false ),
225cdf0e10cSrcweir m_bCollection( false ),
226cdf0e10cSrcweir m_bDidGetOrHead( false )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir try
229cdf0e10cSrcweir {
230cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess(
231cdf0e10cSrcweir rxSMgr,
232cdf0e10cSrcweir rSessionFactory,
233cdf0e10cSrcweir Identifier->getContentIdentifier() ) );
234cdf0e10cSrcweir
235*9646dec5SDamjan Jovanovic CurlUri aURI( Identifier->getContentIdentifier() );
236cdf0e10cSrcweir m_aEscapedTitle = aURI.GetPathBaseName();
237cdf0e10cSrcweir }
238cdf0e10cSrcweir catch ( DAVException const & )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir throw ucb::ContentCreationException();
241cdf0e10cSrcweir }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir //=========================================================================
245cdf0e10cSrcweir // ctr for content on an non-existing webdav resource
Content(const uno::Reference<lang::XMultiServiceFactory> & rxSMgr,ContentProvider * pProvider,const uno::Reference<ucb::XContentIdentifier> & Identifier,rtl::Reference<DAVSessionFactory> const & rSessionFactory,sal_Bool isCollection)246cdf0e10cSrcweir Content::Content(
247cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
248cdf0e10cSrcweir ContentProvider* pProvider,
249cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier,
250cdf0e10cSrcweir rtl::Reference< DAVSessionFactory > const & rSessionFactory,
251cdf0e10cSrcweir sal_Bool isCollection )
252cdf0e10cSrcweir throw ( ucb::ContentCreationException )
253cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ),
254cdf0e10cSrcweir m_eResourceType( UNKNOWN ),
255cdf0e10cSrcweir m_pProvider( pProvider ),
256cdf0e10cSrcweir m_bTransient( true ),
257cdf0e10cSrcweir m_bCollection( isCollection ),
258cdf0e10cSrcweir m_bDidGetOrHead( false )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir try
261cdf0e10cSrcweir {
262cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess(
263cdf0e10cSrcweir rxSMgr, rSessionFactory, Identifier->getContentIdentifier() ) );
264cdf0e10cSrcweir }
265cdf0e10cSrcweir catch ( DAVException const & )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir throw ucb::ContentCreationException();
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
270cdf0e10cSrcweir // Do not set m_aEscapedTitle here! Content::insert relays on this!!!
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir //=========================================================================
274cdf0e10cSrcweir // virtual
~Content()275cdf0e10cSrcweir Content::~Content()
276cdf0e10cSrcweir {
277cdf0e10cSrcweir }
278cdf0e10cSrcweir
279cdf0e10cSrcweir //=========================================================================
280cdf0e10cSrcweir //
281cdf0e10cSrcweir // XInterface methods.
282cdf0e10cSrcweir //
283cdf0e10cSrcweir //=========================================================================
284cdf0e10cSrcweir
285cdf0e10cSrcweir // virtual
acquire()286cdf0e10cSrcweir void SAL_CALL Content::acquire()
287cdf0e10cSrcweir throw( )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir ContentImplHelper::acquire();
290cdf0e10cSrcweir }
291cdf0e10cSrcweir
292cdf0e10cSrcweir //=========================================================================
293cdf0e10cSrcweir // virtual
release()294cdf0e10cSrcweir void SAL_CALL Content::release()
295cdf0e10cSrcweir throw( )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir ContentImplHelper::release();
298cdf0e10cSrcweir }
299cdf0e10cSrcweir
300cdf0e10cSrcweir //=========================================================================
301cdf0e10cSrcweir // virtual
queryInterface(const uno::Type & rType)302cdf0e10cSrcweir uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
303cdf0e10cSrcweir throw ( uno::RuntimeException )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir // Note: isFolder may require network activities! So call it only
306cdf0e10cSrcweir // if it is really necessary!!!
307cdf0e10cSrcweir uno::Any aRet = cppu::queryInterface(
308cdf0e10cSrcweir rType,
309cdf0e10cSrcweir static_cast< ucb::XContentCreator * >( this ) );
310cdf0e10cSrcweir if ( aRet.hasValue() )
311cdf0e10cSrcweir {
312cdf0e10cSrcweir try
313cdf0e10cSrcweir {
314cdf0e10cSrcweir uno::Reference< beans::XPropertySet > const xProps(
315cdf0e10cSrcweir m_xSMgr, uno::UNO_QUERY_THROW );
316cdf0e10cSrcweir uno::Reference< uno::XComponentContext > xCtx;
317cdf0e10cSrcweir xCtx.set( xProps->getPropertyValue(
318cdf0e10cSrcweir rtl::OUString(
319cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ),
320cdf0e10cSrcweir uno::UNO_QUERY_THROW );
321cdf0e10cSrcweir
322cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xIH(
323cdf0e10cSrcweir task::PasswordContainerInteractionHandler::create( xCtx ) );
324cdf0e10cSrcweir
325cdf0e10cSrcweir // Supply a command env to isFolder() that contains an interaction
326cdf0e10cSrcweir // handler that uses the password container service to obtain
327cdf0e10cSrcweir // credentials without displaying a password gui.
328cdf0e10cSrcweir
329cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xCmdEnv(
330cdf0e10cSrcweir ucb::CommandEnvironment::create(
331cdf0e10cSrcweir xCtx,
332cdf0e10cSrcweir xIH,
333cdf0e10cSrcweir uno::Reference< ucb::XProgressHandler >() ) );
334cdf0e10cSrcweir
335cdf0e10cSrcweir return isFolder( xCmdEnv ) ? aRet : uno::Any();
336cdf0e10cSrcweir }
337cdf0e10cSrcweir catch ( uno::RuntimeException const & )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir throw;
340cdf0e10cSrcweir }
341cdf0e10cSrcweir catch ( uno::Exception const & )
342cdf0e10cSrcweir {
343cdf0e10cSrcweir return uno::Any();
344cdf0e10cSrcweir }
345cdf0e10cSrcweir }
346cdf0e10cSrcweir return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
347cdf0e10cSrcweir }
348cdf0e10cSrcweir
349cdf0e10cSrcweir //=========================================================================
350cdf0e10cSrcweir //
351cdf0e10cSrcweir // XTypeProvider methods.
352cdf0e10cSrcweir //
353cdf0e10cSrcweir //=========================================================================
354cdf0e10cSrcweir
355cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( Content );
356cdf0e10cSrcweir
357cdf0e10cSrcweir //=========================================================================
358cdf0e10cSrcweir // virtual
getTypes()359cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
360cdf0e10cSrcweir throw( uno::RuntimeException )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir sal_Bool bFolder = sal_False;
363cdf0e10cSrcweir try
364cdf0e10cSrcweir {
365cdf0e10cSrcweir bFolder
366cdf0e10cSrcweir = isFolder( uno::Reference< ucb::XCommandEnvironment >() );
367cdf0e10cSrcweir }
368cdf0e10cSrcweir catch ( uno::RuntimeException const & )
369cdf0e10cSrcweir {
370cdf0e10cSrcweir throw;
371cdf0e10cSrcweir }
372cdf0e10cSrcweir catch ( uno::Exception const & )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir }
375cdf0e10cSrcweir
376cdf0e10cSrcweir cppu::OTypeCollection * pCollection = 0;
377cdf0e10cSrcweir
378cdf0e10cSrcweir if ( bFolder )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir static cppu::OTypeCollection* pFolderTypes = 0;
381cdf0e10cSrcweir
382cdf0e10cSrcweir pCollection = pFolderTypes;
383cdf0e10cSrcweir if ( !pCollection )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
386cdf0e10cSrcweir
387cdf0e10cSrcweir pCollection = pFolderTypes;
388cdf0e10cSrcweir if ( !pCollection )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir static cppu::OTypeCollection aCollection(
391cdf0e10cSrcweir CPPU_TYPE_REF( lang::XTypeProvider ),
392cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ),
393cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ),
394cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ),
395cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ),
396cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
397cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
398cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ),
399cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
400cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ),
401cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContentCreator ) ); // !!
402cdf0e10cSrcweir pCollection = &aCollection;
403cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
404cdf0e10cSrcweir pFolderTypes = pCollection;
405cdf0e10cSrcweir }
406cdf0e10cSrcweir }
407cdf0e10cSrcweir else {
408cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
409cdf0e10cSrcweir }
410cdf0e10cSrcweir }
411cdf0e10cSrcweir else
412cdf0e10cSrcweir {
413cdf0e10cSrcweir static cppu::OTypeCollection* pDocumentTypes = 0;
414cdf0e10cSrcweir
415cdf0e10cSrcweir pCollection = pDocumentTypes;
416cdf0e10cSrcweir if ( !pCollection )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
419cdf0e10cSrcweir
420cdf0e10cSrcweir pCollection = pDocumentTypes;
421cdf0e10cSrcweir if ( !pCollection )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir static cppu::OTypeCollection aCollection(
424cdf0e10cSrcweir CPPU_TYPE_REF( lang::XTypeProvider ),
425cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ),
426cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ),
427cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ),
428cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ),
429cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
430cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
431cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ),
432cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
433cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ) );
434cdf0e10cSrcweir pCollection = &aCollection;
435cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
436cdf0e10cSrcweir pDocumentTypes = pCollection;
437cdf0e10cSrcweir }
438cdf0e10cSrcweir }
439cdf0e10cSrcweir else {
440cdf0e10cSrcweir OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
441cdf0e10cSrcweir }
442cdf0e10cSrcweir }
443cdf0e10cSrcweir
444cdf0e10cSrcweir return (*pCollection).getTypes();
445cdf0e10cSrcweir }
446cdf0e10cSrcweir
447cdf0e10cSrcweir //=========================================================================
448cdf0e10cSrcweir //
449cdf0e10cSrcweir // XServiceInfo methods.
450cdf0e10cSrcweir //
451cdf0e10cSrcweir //=========================================================================
452cdf0e10cSrcweir
453cdf0e10cSrcweir // virtual
getImplementationName()454cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getImplementationName()
455cdf0e10cSrcweir throw( uno::RuntimeException )
456cdf0e10cSrcweir {
457cdf0e10cSrcweir return rtl::OUString::createFromAscii(
458cdf0e10cSrcweir "com.sun.star.comp.ucb.WebDAVContent" );
459cdf0e10cSrcweir }
460cdf0e10cSrcweir
461cdf0e10cSrcweir //=========================================================================
462cdf0e10cSrcweir // virtual
getSupportedServiceNames()463cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames()
464cdf0e10cSrcweir throw( uno::RuntimeException )
465cdf0e10cSrcweir {
466cdf0e10cSrcweir uno::Sequence< rtl::OUString > aSNS( 1 );
467cdf0e10cSrcweir aSNS.getArray()[ 0 ]
468cdf0e10cSrcweir = rtl::OUString::createFromAscii( WEBDAV_CONTENT_SERVICE_NAME );
469cdf0e10cSrcweir return aSNS;
470cdf0e10cSrcweir }
471cdf0e10cSrcweir
472cdf0e10cSrcweir //=========================================================================
473cdf0e10cSrcweir //
474cdf0e10cSrcweir // XContent methods.
475cdf0e10cSrcweir //
476cdf0e10cSrcweir //=========================================================================
477cdf0e10cSrcweir
478cdf0e10cSrcweir // virtual
getContentType()479cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getContentType()
480cdf0e10cSrcweir throw( uno::RuntimeException )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir sal_Bool bFolder = sal_False;
483cdf0e10cSrcweir try
484cdf0e10cSrcweir {
485cdf0e10cSrcweir bFolder
486cdf0e10cSrcweir = isFolder( uno::Reference< ucb::XCommandEnvironment >() );
487cdf0e10cSrcweir }
488cdf0e10cSrcweir catch ( uno::RuntimeException const & )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir throw;
491cdf0e10cSrcweir }
492cdf0e10cSrcweir catch ( uno::Exception const & )
493cdf0e10cSrcweir {
494cdf0e10cSrcweir }
495cdf0e10cSrcweir
496cdf0e10cSrcweir if ( bFolder )
497cdf0e10cSrcweir return rtl::OUString::createFromAscii( WEBDAV_COLLECTION_TYPE );
498cdf0e10cSrcweir
499cdf0e10cSrcweir return rtl::OUString::createFromAscii( WEBDAV_CONTENT_TYPE );
500cdf0e10cSrcweir }
501cdf0e10cSrcweir
502cdf0e10cSrcweir //=========================================================================
503cdf0e10cSrcweir //
504cdf0e10cSrcweir // XCommandProcessor methods.
505cdf0e10cSrcweir //
506cdf0e10cSrcweir //=========================================================================
507cdf0e10cSrcweir
508cdf0e10cSrcweir // virtual
execute(const ucb::Command & aCommand,sal_Int32,const uno::Reference<ucb::XCommandEnvironment> & Environment)509cdf0e10cSrcweir uno::Any SAL_CALL Content::execute(
510cdf0e10cSrcweir const ucb::Command& aCommand,
511cdf0e10cSrcweir sal_Int32 /*CommandId*/,
512cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment )
513cdf0e10cSrcweir throw( uno::Exception,
514cdf0e10cSrcweir ucb::CommandAbortedException,
515cdf0e10cSrcweir uno::RuntimeException )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir OSL_TRACE( ">>>>> Content::execute: start: command: %s, env: %s",
518cdf0e10cSrcweir rtl::OUStringToOString( aCommand.Name,
519cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr(),
520cdf0e10cSrcweir Environment.is() ? "present" : "missing" );
521cdf0e10cSrcweir
522cdf0e10cSrcweir uno::Any aRet;
523cdf0e10cSrcweir
524cdf0e10cSrcweir if ( aCommand.Name.equalsAsciiL(
525cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "getPropertyValues" ) ) )
526cdf0e10cSrcweir {
527cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
528cdf0e10cSrcweir // getPropertyValues
529cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
530cdf0e10cSrcweir
531cdf0e10cSrcweir uno::Sequence< beans::Property > Properties;
532cdf0e10cSrcweir if ( !( aCommand.Argument >>= Properties ) )
533cdf0e10cSrcweir {
534cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
535cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException(
536cdf0e10cSrcweir rtl::OUString::createFromAscii(
537cdf0e10cSrcweir "Wrong argument type!" ),
538cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
539cdf0e10cSrcweir -1 ) ),
540cdf0e10cSrcweir Environment );
541cdf0e10cSrcweir // Unreachable
542cdf0e10cSrcweir }
543cdf0e10cSrcweir
544cdf0e10cSrcweir aRet <<= getPropertyValues( Properties, Environment );
545cdf0e10cSrcweir }
546cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
547cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "setPropertyValues" ) ) )
548cdf0e10cSrcweir {
549cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
550cdf0e10cSrcweir // setPropertyValues
551cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
552cdf0e10cSrcweir
553cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aProperties;
554cdf0e10cSrcweir if ( !( aCommand.Argument >>= aProperties ) )
555cdf0e10cSrcweir {
556cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
557cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException(
558cdf0e10cSrcweir rtl::OUString::createFromAscii(
559cdf0e10cSrcweir "Wrong argument type!" ),
560cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
561cdf0e10cSrcweir -1 ) ),
562cdf0e10cSrcweir Environment );
563cdf0e10cSrcweir // Unreachable
564cdf0e10cSrcweir }
565cdf0e10cSrcweir
566cdf0e10cSrcweir if ( !aProperties.getLength() )
567cdf0e10cSrcweir {
568cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
569cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException(
570cdf0e10cSrcweir rtl::OUString::createFromAscii(
571cdf0e10cSrcweir "No properties!" ),
572cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
573cdf0e10cSrcweir -1 ) ),
574cdf0e10cSrcweir Environment );
575cdf0e10cSrcweir // Unreachable
576cdf0e10cSrcweir }
577cdf0e10cSrcweir
578cdf0e10cSrcweir aRet <<= setPropertyValues( aProperties, Environment );
579cdf0e10cSrcweir }
580cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
581cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "getPropertySetInfo" ) ) )
582cdf0e10cSrcweir {
583cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
584cdf0e10cSrcweir // getPropertySetInfo
585cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
586cdf0e10cSrcweir
587cdf0e10cSrcweir // Note: Implemented by base class.
588cdf0e10cSrcweir aRet <<= getPropertySetInfo( Environment,
589cdf0e10cSrcweir sal_False /* don't cache data */ );
590cdf0e10cSrcweir }
591cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
592cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "getCommandInfo" ) ) )
593cdf0e10cSrcweir {
594cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
595cdf0e10cSrcweir // getCommandInfo
596cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
597cdf0e10cSrcweir
598cdf0e10cSrcweir // Note: Implemented by base class.
599cdf0e10cSrcweir aRet <<= getCommandInfo( Environment, sal_False );
600cdf0e10cSrcweir }
601cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
602cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "open" ) ) )
603cdf0e10cSrcweir {
604cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
605cdf0e10cSrcweir // open
606cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
607cdf0e10cSrcweir
608cdf0e10cSrcweir ucb::OpenCommandArgument2 aOpenCommand;
609cdf0e10cSrcweir if ( !( aCommand.Argument >>= aOpenCommand ) )
610cdf0e10cSrcweir {
611cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
612cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException(
613cdf0e10cSrcweir rtl::OUString::createFromAscii(
614cdf0e10cSrcweir "Wrong argument type!" ),
615cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
616cdf0e10cSrcweir -1 ) ),
617cdf0e10cSrcweir Environment );
618cdf0e10cSrcweir // Unreachable
619cdf0e10cSrcweir }
620cdf0e10cSrcweir
621cdf0e10cSrcweir aRet = open( aOpenCommand, Environment );
622cdf0e10cSrcweir }
623cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
624cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "insert" ) ) )
625cdf0e10cSrcweir {
626cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
627cdf0e10cSrcweir // insert
628cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
629cdf0e10cSrcweir
630cdf0e10cSrcweir ucb::InsertCommandArgument arg;
631cdf0e10cSrcweir if ( !( aCommand.Argument >>= arg ) )
632cdf0e10cSrcweir {
633cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
634cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException(
635cdf0e10cSrcweir rtl::OUString::createFromAscii(
636cdf0e10cSrcweir "Wrong argument type!" ),
637cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
638cdf0e10cSrcweir -1 ) ),
639cdf0e10cSrcweir Environment );
640cdf0e10cSrcweir // Unreachable
641cdf0e10cSrcweir }
642cdf0e10cSrcweir
643cdf0e10cSrcweir insert( arg.Data, arg.ReplaceExisting, Environment );
644cdf0e10cSrcweir }
645cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
646cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "delete" ) ) )
647cdf0e10cSrcweir {
648cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
649cdf0e10cSrcweir // delete
650cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
651cdf0e10cSrcweir
652cdf0e10cSrcweir sal_Bool bDeletePhysical = sal_False;
653cdf0e10cSrcweir aCommand.Argument >>= bDeletePhysical;
654cdf0e10cSrcweir
655cdf0e10cSrcweir // KSO: Ignore parameter and destroy the content, if you don't support
656cdf0e10cSrcweir // putting objects into trashcan. ( Since we do not have a trash can
657cdf0e10cSrcweir // service yet (src603), you actually have no other choice. )
658cdf0e10cSrcweir // if ( bDeletePhysical )
659cdf0e10cSrcweir // {
660cdf0e10cSrcweir try
661cdf0e10cSrcweir {
662cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
663cdf0e10cSrcweir {
664cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
665cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
666cdf0e10cSrcweir }
667cdf0e10cSrcweir xResAccess->DESTROY( Environment );
668cdf0e10cSrcweir {
669cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
670cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
671cdf0e10cSrcweir }
672cdf0e10cSrcweir }
673cdf0e10cSrcweir catch ( DAVException const & e )
674cdf0e10cSrcweir {
675cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_True );
676cdf0e10cSrcweir // Unreachable
677cdf0e10cSrcweir }
678cdf0e10cSrcweir // }
679cdf0e10cSrcweir
680cdf0e10cSrcweir // Propagate destruction.
681cdf0e10cSrcweir destroy( bDeletePhysical );
682cdf0e10cSrcweir
683cdf0e10cSrcweir // Remove own and all children's Additional Core Properties.
684cdf0e10cSrcweir removeAdditionalPropertySet( sal_True );
685cdf0e10cSrcweir }
686cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
687cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "transfer" ) )
688cdf0e10cSrcweir && isFolder( Environment ) )
689cdf0e10cSrcweir {
690cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
691cdf0e10cSrcweir // transfer
692cdf0e10cSrcweir // ( Not available at documents )
693cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
694cdf0e10cSrcweir
695cdf0e10cSrcweir ucb::TransferInfo transferArgs;
696cdf0e10cSrcweir if ( !( aCommand.Argument >>= transferArgs ) )
697cdf0e10cSrcweir {
698cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
699cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException(
700cdf0e10cSrcweir rtl::OUString::createFromAscii(
701cdf0e10cSrcweir "Wrong argument type!" ),
702cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
703cdf0e10cSrcweir -1 ) ),
704cdf0e10cSrcweir Environment );
705cdf0e10cSrcweir // Unreachable
706cdf0e10cSrcweir }
707cdf0e10cSrcweir
708cdf0e10cSrcweir transfer( transferArgs, Environment );
709cdf0e10cSrcweir }
710cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
711cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "post" ) ) )
712cdf0e10cSrcweir {
713cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
714cdf0e10cSrcweir // post
715cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
716cdf0e10cSrcweir
717cdf0e10cSrcweir ucb::PostCommandArgument2 aArg;
718cdf0e10cSrcweir if ( !( aCommand.Argument >>= aArg ) )
719cdf0e10cSrcweir {
720cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
721cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException(
722cdf0e10cSrcweir rtl::OUString::createFromAscii(
723cdf0e10cSrcweir "Wrong argument type!" ),
724cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
725cdf0e10cSrcweir -1 ) ),
726cdf0e10cSrcweir Environment );
727cdf0e10cSrcweir // Unreachable
728cdf0e10cSrcweir }
729cdf0e10cSrcweir
730cdf0e10cSrcweir post( aArg, Environment );
731cdf0e10cSrcweir }
732cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
7339c0c1533SAndrea Pescetti RTL_CONSTASCII_STRINGPARAM( "lock" ) ) )
734cdf0e10cSrcweir {
735cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
736cdf0e10cSrcweir // lock
737cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
738cdf0e10cSrcweir lock( Environment );
739cdf0e10cSrcweir }
740cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
7419c0c1533SAndrea Pescetti RTL_CONSTASCII_STRINGPARAM( "unlock" ) ) )
742cdf0e10cSrcweir {
743cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
744cdf0e10cSrcweir // unlock
745cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
746cdf0e10cSrcweir unlock( Environment );
747cdf0e10cSrcweir }
748cdf0e10cSrcweir else if ( aCommand.Name.equalsAsciiL(
749cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "createNewContent" ) ) &&
750cdf0e10cSrcweir isFolder( Environment ) )
751cdf0e10cSrcweir {
752cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
753cdf0e10cSrcweir // createNewContent
754cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
755cdf0e10cSrcweir
756cdf0e10cSrcweir ucb::ContentInfo aArg;
757cdf0e10cSrcweir if ( !( aCommand.Argument >>= aArg ) )
758cdf0e10cSrcweir {
759cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
760cdf0e10cSrcweir uno::makeAny( lang::IllegalArgumentException(
761cdf0e10cSrcweir rtl::OUString::createFromAscii(
762cdf0e10cSrcweir "Wrong argument type!" ),
763cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
764cdf0e10cSrcweir -1 ) ),
765cdf0e10cSrcweir Environment );
766cdf0e10cSrcweir // Unreachable
767cdf0e10cSrcweir }
768cdf0e10cSrcweir
769cdf0e10cSrcweir aRet = uno::makeAny( createNewContent( aArg ) );
770cdf0e10cSrcweir }
77106594b87SAriel Constenla-Haile else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "addProperty" )))
77206594b87SAriel Constenla-Haile {
77306594b87SAriel Constenla-Haile ucb::PropertyCommandArgument aPropArg;
77406594b87SAriel Constenla-Haile if ( !( aCommand.Argument >>= aPropArg ))
77506594b87SAriel Constenla-Haile {
77606594b87SAriel Constenla-Haile ucbhelper::cancelCommandExecution(
77706594b87SAriel Constenla-Haile uno::makeAny( lang::IllegalArgumentException(
77806594b87SAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
77906594b87SAriel Constenla-Haile "Wrong argument type!" )),
78006594b87SAriel Constenla-Haile static_cast< cppu::OWeakObject * >( this ),
78106594b87SAriel Constenla-Haile -1 ) ),
78206594b87SAriel Constenla-Haile Environment );
78306594b87SAriel Constenla-Haile }
78406594b87SAriel Constenla-Haile
78506594b87SAriel Constenla-Haile // TODO when/if XPropertyContainer is removed,
78606594b87SAriel Constenla-Haile // the command execution can be canceled in addProperty
78706594b87SAriel Constenla-Haile try
78806594b87SAriel Constenla-Haile {
78906594b87SAriel Constenla-Haile addProperty( aPropArg, Environment );
79006594b87SAriel Constenla-Haile }
79106594b87SAriel Constenla-Haile catch ( const beans::PropertyExistException &e )
79206594b87SAriel Constenla-Haile {
79306594b87SAriel Constenla-Haile ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment );
79406594b87SAriel Constenla-Haile }
79506594b87SAriel Constenla-Haile catch ( const beans::IllegalTypeException&e )
79606594b87SAriel Constenla-Haile {
79706594b87SAriel Constenla-Haile ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment );
79806594b87SAriel Constenla-Haile }
79906594b87SAriel Constenla-Haile catch ( const lang::IllegalArgumentException&e )
80006594b87SAriel Constenla-Haile {
80106594b87SAriel Constenla-Haile ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment );
80206594b87SAriel Constenla-Haile }
80306594b87SAriel Constenla-Haile }
80406594b87SAriel Constenla-Haile else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "removeProperty" )))
80506594b87SAriel Constenla-Haile {
80606594b87SAriel Constenla-Haile rtl::OUString sPropName;
80706594b87SAriel Constenla-Haile if ( !( aCommand.Argument >>= sPropName ) )
80806594b87SAriel Constenla-Haile {
80906594b87SAriel Constenla-Haile ucbhelper::cancelCommandExecution(
81006594b87SAriel Constenla-Haile uno::makeAny( lang::IllegalArgumentException(
81106594b87SAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
81206594b87SAriel Constenla-Haile "Wrong argument type!" )),
81306594b87SAriel Constenla-Haile static_cast< cppu::OWeakObject * >( this ),
81406594b87SAriel Constenla-Haile -1 ) ),
81506594b87SAriel Constenla-Haile Environment );
81606594b87SAriel Constenla-Haile }
81706594b87SAriel Constenla-Haile
81806594b87SAriel Constenla-Haile // TODO when/if XPropertyContainer is removed,
81906594b87SAriel Constenla-Haile // the command execution can be canceled in removeProperty
82006594b87SAriel Constenla-Haile try
82106594b87SAriel Constenla-Haile {
82206594b87SAriel Constenla-Haile removeProperty( sPropName, Environment );
82306594b87SAriel Constenla-Haile }
82406594b87SAriel Constenla-Haile catch( const beans::UnknownPropertyException &e )
82506594b87SAriel Constenla-Haile {
82606594b87SAriel Constenla-Haile ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment );
82706594b87SAriel Constenla-Haile }
82806594b87SAriel Constenla-Haile catch( const beans::NotRemoveableException &e )
82906594b87SAriel Constenla-Haile {
83006594b87SAriel Constenla-Haile ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment );
83106594b87SAriel Constenla-Haile }
83206594b87SAriel Constenla-Haile }
833cdf0e10cSrcweir else
834cdf0e10cSrcweir {
835cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
836cdf0e10cSrcweir // Unsupported command
837cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
838cdf0e10cSrcweir
839cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
840cdf0e10cSrcweir uno::makeAny( ucb::UnsupportedCommandException(
841cdf0e10cSrcweir aCommand.Name,
842cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ),
843cdf0e10cSrcweir Environment );
844cdf0e10cSrcweir // Unreachable
845cdf0e10cSrcweir }
846cdf0e10cSrcweir
847cdf0e10cSrcweir OSL_TRACE( "<<<<< Content::execute: end: command: %s",
848cdf0e10cSrcweir rtl::OUStringToOString( aCommand.Name,
849cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() );
850cdf0e10cSrcweir
851cdf0e10cSrcweir return aRet;
852cdf0e10cSrcweir }
853cdf0e10cSrcweir
854cdf0e10cSrcweir //=========================================================================
855cdf0e10cSrcweir // virtual
abort(sal_Int32)856cdf0e10cSrcweir void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
857cdf0e10cSrcweir throw( uno::RuntimeException )
858cdf0e10cSrcweir {
859cdf0e10cSrcweir try
860cdf0e10cSrcweir {
861cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
862cdf0e10cSrcweir {
863cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
864cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
865cdf0e10cSrcweir }
866cdf0e10cSrcweir xResAccess->abort();
867cdf0e10cSrcweir {
868cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
869cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
870cdf0e10cSrcweir }
871cdf0e10cSrcweir }
872cdf0e10cSrcweir catch ( DAVException const & )
873cdf0e10cSrcweir {
874cdf0e10cSrcweir // abort failed!
875cdf0e10cSrcweir }
876cdf0e10cSrcweir }
877cdf0e10cSrcweir
878cdf0e10cSrcweir //=========================================================================
879cdf0e10cSrcweir //
880cdf0e10cSrcweir // XPropertyContainer methods.
881cdf0e10cSrcweir //
882cdf0e10cSrcweir //=========================================================================
883cdf0e10cSrcweir
addProperty(const com::sun::star::ucb::PropertyCommandArgument & aCmdArg,const uno::Reference<ucb::XCommandEnvironment> & xEnv)88406594b87SAriel Constenla-Haile void Content::addProperty( const com::sun::star::ucb::PropertyCommandArgument &aCmdArg,
88506594b87SAriel Constenla-Haile const uno::Reference< ucb::XCommandEnvironment >& xEnv )
88606594b87SAriel Constenla-Haile throw( beans::PropertyExistException,
88706594b87SAriel Constenla-Haile beans::IllegalTypeException,
88806594b87SAriel Constenla-Haile lang::IllegalArgumentException,
88906594b87SAriel Constenla-Haile uno::RuntimeException )
890cdf0e10cSrcweir {
891cdf0e10cSrcweir // if ( m_bTransient )
892cdf0e10cSrcweir // @@@ ???
89306594b87SAriel Constenla-Haile const beans::Property aProperty = aCmdArg.Property;
89406594b87SAriel Constenla-Haile const uno::Any aDefaultValue = aCmdArg.DefaultValue;
895cdf0e10cSrcweir
89606594b87SAriel Constenla-Haile // check property Name
89706594b87SAriel Constenla-Haile if ( !aProperty.Name.getLength() )
89806594b87SAriel Constenla-Haile throw lang::IllegalArgumentException(
89906594b87SAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
90006594b87SAriel Constenla-Haile "\"addProperty\" with empty Property.Name")),
90106594b87SAriel Constenla-Haile static_cast< ::cppu::OWeakObject * >( this ),
90206594b87SAriel Constenla-Haile -1 );
903cdf0e10cSrcweir
904cdf0e10cSrcweir // Check property type.
90506594b87SAriel Constenla-Haile if ( !UCBDeadPropertyValue::supportsType( aProperty.Type ) )
90606594b87SAriel Constenla-Haile throw beans::IllegalTypeException(
90706594b87SAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
90806594b87SAriel Constenla-Haile "\"addProperty\" unsupported Property.Type")),
90906594b87SAriel Constenla-Haile static_cast< ::cppu::OWeakObject * >( this ) );
91006594b87SAriel Constenla-Haile
91106594b87SAriel Constenla-Haile // check default value
91206594b87SAriel Constenla-Haile if ( aDefaultValue.hasValue() && aDefaultValue.getValueType() != aProperty.Type )
91306594b87SAriel Constenla-Haile throw beans::IllegalTypeException(
91406594b87SAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
91506594b87SAriel Constenla-Haile "\"addProperty\" DefaultValue does not match Property.Type")),
91606594b87SAriel Constenla-Haile static_cast< ::cppu::OWeakObject * >( this ) );
917cdf0e10cSrcweir
918cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
919cdf0e10cSrcweir // Make sure a property with the requested name does not already
920cdf0e10cSrcweir // exist in dynamic and static(!) properties.
921cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
922cdf0e10cSrcweir
92306594b87SAriel Constenla-Haile // Take into account special properties with custom namespace
92406594b87SAriel Constenla-Haile // using <prop:the_propname xmlns:prop="the_namespace">
92506594b87SAriel Constenla-Haile rtl::OUString aSpecialName;
92606594b87SAriel Constenla-Haile bool bIsSpecial = DAVProperties::isUCBSpecialProperty( aProperty.Name, aSpecialName );
927cdf0e10cSrcweir
928cdf0e10cSrcweir // Note: This requires network access!
929cdf0e10cSrcweir if ( getPropertySetInfo( xEnv, sal_False /* don't cache data */ )
93006594b87SAriel Constenla-Haile ->hasPropertyByName( bIsSpecial ? aSpecialName : aProperty.Name ) )
931cdf0e10cSrcweir {
932cdf0e10cSrcweir // Property does already exist.
933cdf0e10cSrcweir throw beans::PropertyExistException();
934cdf0e10cSrcweir }
935cdf0e10cSrcweir
936cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
937cdf0e10cSrcweir // Add a new dynamic property.
938cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
939cdf0e10cSrcweir
94006594b87SAriel Constenla-Haile ProppatchValue aValue( PROPSET, aProperty.Name, aDefaultValue );
941cdf0e10cSrcweir
942cdf0e10cSrcweir std::vector< ProppatchValue > aProppatchValues;
943cdf0e10cSrcweir aProppatchValues.push_back( aValue );
944cdf0e10cSrcweir
945cdf0e10cSrcweir try
946cdf0e10cSrcweir {
947cdf0e10cSrcweir // Set property value at server.
948cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
949cdf0e10cSrcweir {
950cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
951cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
952cdf0e10cSrcweir }
953cdf0e10cSrcweir xResAccess->PROPPATCH( aProppatchValues, xEnv );
954cdf0e10cSrcweir {
955cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
956cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
957cdf0e10cSrcweir }
958cdf0e10cSrcweir
959cdf0e10cSrcweir // Notify propertyset info change listeners.
960cdf0e10cSrcweir beans::PropertySetInfoChangeEvent evt(
961cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
96206594b87SAriel Constenla-Haile bIsSpecial ? aSpecialName : aProperty.Name,
963cdf0e10cSrcweir -1, // No handle available
964cdf0e10cSrcweir beans::PropertySetInfoChange::PROPERTY_INSERTED );
965cdf0e10cSrcweir notifyPropertySetInfoChange( evt );
966cdf0e10cSrcweir }
967cdf0e10cSrcweir catch ( DAVException const & e )
968cdf0e10cSrcweir {
969cdf0e10cSrcweir if ( e.getStatus() == SC_FORBIDDEN )
970cdf0e10cSrcweir {
971cdf0e10cSrcweir // Support for setting arbitrary dead properties is optional!
972cdf0e10cSrcweir
973cdf0e10cSrcweir // Store property locally.
97406594b87SAriel Constenla-Haile ContentImplHelper::addProperty( bIsSpecial ? aSpecialName : aProperty.Name,
97506594b87SAriel Constenla-Haile aProperty.Attributes,
97606594b87SAriel Constenla-Haile aDefaultValue );
977cdf0e10cSrcweir }
978cdf0e10cSrcweir else
979cdf0e10cSrcweir {
980cdf0e10cSrcweir if ( shouldAccessNetworkAfterException( e ) )
981cdf0e10cSrcweir {
982cdf0e10cSrcweir try
983cdf0e10cSrcweir {
984cdf0e10cSrcweir const ResourceType & rType = getResourceType( xEnv );
985cdf0e10cSrcweir switch ( rType )
986cdf0e10cSrcweir {
987cdf0e10cSrcweir case UNKNOWN:
988cdf0e10cSrcweir case DAV:
989cdf0e10cSrcweir throw lang::IllegalArgumentException();
990cdf0e10cSrcweir
991cdf0e10cSrcweir case NON_DAV:
992cdf0e10cSrcweir // Store property locally.
99306594b87SAriel Constenla-Haile ContentImplHelper::addProperty( bIsSpecial ? aSpecialName : aProperty.Name,
99406594b87SAriel Constenla-Haile aProperty.Attributes,
99506594b87SAriel Constenla-Haile aDefaultValue );
996cdf0e10cSrcweir break;
997cdf0e10cSrcweir
998cdf0e10cSrcweir default:
999cdf0e10cSrcweir OSL_ENSURE( sal_False,
1000cdf0e10cSrcweir "Content::addProperty - "
1001cdf0e10cSrcweir "Unsupported resource type!" );
1002cdf0e10cSrcweir break;
1003cdf0e10cSrcweir }
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir catch ( uno::Exception const & )
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir OSL_ENSURE( sal_False,
1008cdf0e10cSrcweir "Content::addProperty - "
1009cdf0e10cSrcweir "Unable to determine resource type!" );
1010cdf0e10cSrcweir }
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir else
1013cdf0e10cSrcweir {
1014cdf0e10cSrcweir OSL_ENSURE( sal_False,
1015cdf0e10cSrcweir "Content::addProperty - "
1016cdf0e10cSrcweir "Unable to determine resource type!" );
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir }
1020cdf0e10cSrcweir }
1021cdf0e10cSrcweir
removeProperty(const rtl::OUString & Name,const uno::Reference<ucb::XCommandEnvironment> & xEnv)102206594b87SAriel Constenla-Haile void Content::removeProperty( const rtl::OUString& Name,
102306594b87SAriel Constenla-Haile const uno::Reference< ucb::XCommandEnvironment >& xEnv )
102406594b87SAriel Constenla-Haile throw( beans::UnknownPropertyException,
102506594b87SAriel Constenla-Haile beans::NotRemoveableException,
102606594b87SAriel Constenla-Haile uno::RuntimeException )
1027cdf0e10cSrcweir {
1028cdf0e10cSrcweir #if 0
1029cdf0e10cSrcweir // @@@ REMOVEABLE z.Z. nicht richtig an der PropSetInfo gesetzt!!!
1030cdf0e10cSrcweir try
1031cdf0e10cSrcweir {
1032cdf0e10cSrcweir beans::Property aProp
103306594b87SAriel Constenla-Haile = getPropertySetInfo( xEnv, sal_False /* don't cache data */ )
103406594b87SAriel Constenla-Haile ->getPropertyByName( Name );
1035cdf0e10cSrcweir
1036cdf0e10cSrcweir if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVEABLE ) )
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir // Not removeable!
1039cdf0e10cSrcweir throw beans::NotRemoveableException();
1040cdf0e10cSrcweir }
1041cdf0e10cSrcweir }
1042cdf0e10cSrcweir catch ( beans::UnknownPropertyException const & )
1043cdf0e10cSrcweir {
1044cdf0e10cSrcweir //OSL_ENSURE( sal_False, "removeProperty - Unknown property!" );
1045cdf0e10cSrcweir throw;
1046cdf0e10cSrcweir }
1047cdf0e10cSrcweir #endif
1048cdf0e10cSrcweir
1049cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1050cdf0e10cSrcweir // Try to remove property from server.
1051cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1052cdf0e10cSrcweir
1053cdf0e10cSrcweir try
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir std::vector< ProppatchValue > aProppatchValues;
1056cdf0e10cSrcweir ProppatchValue aValue( PROPREMOVE, Name, uno::Any() );
1057cdf0e10cSrcweir aProppatchValues.push_back( aValue );
1058cdf0e10cSrcweir
1059cdf0e10cSrcweir // Remove property value from server.
1060cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
1061cdf0e10cSrcweir {
1062cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1063cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
1064cdf0e10cSrcweir }
1065cdf0e10cSrcweir xResAccess->PROPPATCH( aProppatchValues, xEnv );
1066cdf0e10cSrcweir {
1067cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1068cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
1069cdf0e10cSrcweir }
1070cdf0e10cSrcweir
1071cdf0e10cSrcweir // Notify propertyset info change listeners.
1072cdf0e10cSrcweir beans::PropertySetInfoChangeEvent evt(
1073cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1074cdf0e10cSrcweir Name,
1075cdf0e10cSrcweir -1, // No handle available
1076cdf0e10cSrcweir beans::PropertySetInfoChange::PROPERTY_REMOVED );
1077cdf0e10cSrcweir notifyPropertySetInfoChange( evt );
1078cdf0e10cSrcweir }
1079cdf0e10cSrcweir catch ( DAVException const & e )
1080cdf0e10cSrcweir {
1081cdf0e10cSrcweir if ( e.getStatus() == SC_FORBIDDEN )
1082cdf0e10cSrcweir {
1083cdf0e10cSrcweir // Support for setting arbitrary dead properties is optional!
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir // Try to remove property from local store.
1086cdf0e10cSrcweir ContentImplHelper::removeProperty( Name );
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir else
1089cdf0e10cSrcweir {
1090cdf0e10cSrcweir if ( shouldAccessNetworkAfterException( e ) )
1091cdf0e10cSrcweir {
1092cdf0e10cSrcweir try
1093cdf0e10cSrcweir {
1094cdf0e10cSrcweir const ResourceType & rType = getResourceType( xEnv );
1095cdf0e10cSrcweir switch ( rType )
1096cdf0e10cSrcweir {
109706594b87SAriel Constenla-Haile case UNKNOWN:
109806594b87SAriel Constenla-Haile case DAV:
109906594b87SAriel Constenla-Haile throw beans::UnknownPropertyException();
110006594b87SAriel Constenla-Haile
110106594b87SAriel Constenla-Haile case NON_DAV:
110206594b87SAriel Constenla-Haile // Try to remove property from local store.
110306594b87SAriel Constenla-Haile ContentImplHelper::removeProperty( Name );
110406594b87SAriel Constenla-Haile break;
110506594b87SAriel Constenla-Haile
110606594b87SAriel Constenla-Haile default:
110706594b87SAriel Constenla-Haile OSL_ENSURE( sal_False,
110806594b87SAriel Constenla-Haile "Content::removeProperty - "
110906594b87SAriel Constenla-Haile "Unsupported resource type!" );
111006594b87SAriel Constenla-Haile break;
1111cdf0e10cSrcweir }
1112cdf0e10cSrcweir }
1113cdf0e10cSrcweir catch ( uno::Exception const & )
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir OSL_ENSURE( sal_False,
1116cdf0e10cSrcweir "Content::removeProperty - "
1117cdf0e10cSrcweir "Unable to determine resource type!" );
1118cdf0e10cSrcweir }
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir else
1121cdf0e10cSrcweir {
1122cdf0e10cSrcweir OSL_ENSURE( sal_False,
1123cdf0e10cSrcweir "Content::removeProperty - "
1124cdf0e10cSrcweir "Unable to determine resource type!" );
1125cdf0e10cSrcweir // throw beans::UnknownPropertyException();
1126cdf0e10cSrcweir }
1127cdf0e10cSrcweir }
1128cdf0e10cSrcweir }
1129cdf0e10cSrcweir }
1130cdf0e10cSrcweir
113106594b87SAriel Constenla-Haile // virtual
addProperty(const rtl::OUString & Name,sal_Int16 Attributes,const uno::Any & DefaultValue)113206594b87SAriel Constenla-Haile void SAL_CALL Content::addProperty( const rtl::OUString& Name,
113306594b87SAriel Constenla-Haile sal_Int16 Attributes,
113406594b87SAriel Constenla-Haile const uno::Any& DefaultValue )
113506594b87SAriel Constenla-Haile throw( beans::PropertyExistException,
113606594b87SAriel Constenla-Haile beans::IllegalTypeException,
113706594b87SAriel Constenla-Haile lang::IllegalArgumentException,
113806594b87SAriel Constenla-Haile uno::RuntimeException )
113906594b87SAriel Constenla-Haile {
114006594b87SAriel Constenla-Haile beans::Property aProperty;
114106594b87SAriel Constenla-Haile aProperty.Name = Name;
114206594b87SAriel Constenla-Haile aProperty.Type = DefaultValue.getValueType();
114306594b87SAriel Constenla-Haile aProperty.Attributes = Attributes;
114406594b87SAriel Constenla-Haile aProperty.Handle = -1;
114506594b87SAriel Constenla-Haile
114606594b87SAriel Constenla-Haile addProperty( ucb::PropertyCommandArgument( aProperty, DefaultValue ),
114706594b87SAriel Constenla-Haile uno::Reference< ucb::XCommandEnvironment >());
114806594b87SAriel Constenla-Haile }
114906594b87SAriel Constenla-Haile
115006594b87SAriel Constenla-Haile // virtual
removeProperty(const rtl::OUString & Name)115106594b87SAriel Constenla-Haile void SAL_CALL Content::removeProperty( const rtl::OUString& Name )
115206594b87SAriel Constenla-Haile throw( beans::UnknownPropertyException,
115306594b87SAriel Constenla-Haile beans::NotRemoveableException,
115406594b87SAriel Constenla-Haile uno::RuntimeException )
115506594b87SAriel Constenla-Haile {
115606594b87SAriel Constenla-Haile removeProperty( Name,
115706594b87SAriel Constenla-Haile uno::Reference< ucb::XCommandEnvironment >() );
115806594b87SAriel Constenla-Haile }
115906594b87SAriel Constenla-Haile
1160cdf0e10cSrcweir //=========================================================================
1161cdf0e10cSrcweir //
1162cdf0e10cSrcweir // XContentCreator methods.
1163cdf0e10cSrcweir //
1164cdf0e10cSrcweir //=========================================================================
1165cdf0e10cSrcweir
1166cdf0e10cSrcweir // virtual
1167cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > SAL_CALL
queryCreatableContentsInfo()1168cdf0e10cSrcweir Content::queryCreatableContentsInfo()
1169cdf0e10cSrcweir throw( uno::RuntimeException )
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1172cdf0e10cSrcweir
1173cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > aSeq( 2 );
1174cdf0e10cSrcweir
1175cdf0e10cSrcweir // document.
1176cdf0e10cSrcweir aSeq.getArray()[ 0 ].Type
1177cdf0e10cSrcweir = rtl::OUString::createFromAscii( WEBDAV_CONTENT_TYPE );
1178cdf0e10cSrcweir aSeq.getArray()[ 0 ].Attributes
1179cdf0e10cSrcweir = ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM
1180cdf0e10cSrcweir | ucb::ContentInfoAttribute::KIND_DOCUMENT;
1181cdf0e10cSrcweir
1182cdf0e10cSrcweir beans::Property aProp;
1183cdf0e10cSrcweir m_pProvider->getProperty(
1184cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), aProp );
1185cdf0e10cSrcweir
1186cdf0e10cSrcweir uno::Sequence< beans::Property > aDocProps( 1 );
1187cdf0e10cSrcweir aDocProps.getArray()[ 0 ] = aProp;
1188cdf0e10cSrcweir aSeq.getArray()[ 0 ].Properties = aDocProps;
1189cdf0e10cSrcweir
1190cdf0e10cSrcweir // folder.
1191cdf0e10cSrcweir aSeq.getArray()[ 1 ].Type
1192cdf0e10cSrcweir = rtl::OUString::createFromAscii( WEBDAV_COLLECTION_TYPE );
1193cdf0e10cSrcweir aSeq.getArray()[ 1 ].Attributes
1194cdf0e10cSrcweir = ucb::ContentInfoAttribute::KIND_FOLDER;
1195cdf0e10cSrcweir
1196cdf0e10cSrcweir uno::Sequence< beans::Property > aFolderProps( 1 );
1197cdf0e10cSrcweir aFolderProps.getArray()[ 0 ] = aProp;
1198cdf0e10cSrcweir aSeq.getArray()[ 1 ].Properties = aFolderProps;
1199cdf0e10cSrcweir return aSeq;
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir //=========================================================================
1203cdf0e10cSrcweir // virtual
1204cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL
createNewContent(const ucb::ContentInfo & Info)1205cdf0e10cSrcweir Content::createNewContent( const ucb::ContentInfo& Info )
1206cdf0e10cSrcweir throw( uno::RuntimeException )
1207cdf0e10cSrcweir {
1208cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1209cdf0e10cSrcweir
1210cdf0e10cSrcweir if ( !Info.Type.getLength() )
1211cdf0e10cSrcweir return uno::Reference< ucb::XContent >();
1212cdf0e10cSrcweir
1213cdf0e10cSrcweir if ( ( !Info.Type.equalsAsciiL(
1214cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_COLLECTION_TYPE ) ) )
1215cdf0e10cSrcweir &&
1216cdf0e10cSrcweir ( !Info.Type.equalsAsciiL(
1217cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_CONTENT_TYPE ) ) ) )
1218cdf0e10cSrcweir return uno::Reference< ucb::XContent >();
1219cdf0e10cSrcweir
1220cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
1221cdf0e10cSrcweir
1222cdf0e10cSrcweir OSL_ENSURE( aURL.getLength() > 0,
1223cdf0e10cSrcweir "WebdavContent::createNewContent - empty identifier!" );
1224cdf0e10cSrcweir
1225cdf0e10cSrcweir if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() )
1226cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" );
1227cdf0e10cSrcweir
1228cdf0e10cSrcweir sal_Bool isCollection;
1229cdf0e10cSrcweir if ( Info.Type.equalsAsciiL(
1230cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_COLLECTION_TYPE ) ) )
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "New_Collection" );
1233cdf0e10cSrcweir isCollection = sal_True;
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir else
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "New_Content" );
1238cdf0e10cSrcweir isCollection = sal_False;
1239cdf0e10cSrcweir }
1240cdf0e10cSrcweir
1241cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xId(
1242cdf0e10cSrcweir new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL ) );
1243cdf0e10cSrcweir
1244cdf0e10cSrcweir // create the local content
1245cdf0e10cSrcweir try
1246cdf0e10cSrcweir {
124759ddfc10SAndre Fischer return new ::http_dav_ucp::Content( m_xSMgr,
1248cdf0e10cSrcweir m_pProvider,
1249cdf0e10cSrcweir xId,
1250cdf0e10cSrcweir m_xResAccess->getSessionFactory(),
1251cdf0e10cSrcweir isCollection );
1252cdf0e10cSrcweir }
1253cdf0e10cSrcweir catch ( ucb::ContentCreationException & )
1254cdf0e10cSrcweir {
1255cdf0e10cSrcweir return uno::Reference< ucb::XContent >();
1256cdf0e10cSrcweir }
1257cdf0e10cSrcweir }
1258cdf0e10cSrcweir
1259cdf0e10cSrcweir //=========================================================================
1260cdf0e10cSrcweir // virtual
getParentURL()1261cdf0e10cSrcweir rtl::OUString Content::getParentURL()
1262cdf0e10cSrcweir {
1263cdf0e10cSrcweir // <scheme>:// -> ""
1264cdf0e10cSrcweir // <scheme>://foo -> ""
1265cdf0e10cSrcweir // <scheme>://foo/ -> ""
1266cdf0e10cSrcweir // <scheme>://foo/bar -> <scheme>://foo/
1267cdf0e10cSrcweir // <scheme>://foo/bar/ -> <scheme>://foo/
1268cdf0e10cSrcweir // <scheme>://foo/bar/abc -> <scheme>://foo/bar/
1269cdf0e10cSrcweir
1270cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
1271cdf0e10cSrcweir
1272cdf0e10cSrcweir sal_Int32 nPos = aURL.lastIndexOf( '/' );
1273cdf0e10cSrcweir if ( nPos == ( aURL.getLength() - 1 ) )
1274cdf0e10cSrcweir {
1275cdf0e10cSrcweir // Trailing slash found. Skip.
1276cdf0e10cSrcweir nPos = aURL.lastIndexOf( '/', nPos );
1277cdf0e10cSrcweir }
1278cdf0e10cSrcweir
1279cdf0e10cSrcweir sal_Int32 nPos1 = aURL.lastIndexOf( '/', nPos );
1280cdf0e10cSrcweir if ( nPos1 != -1 )
1281cdf0e10cSrcweir nPos1 = aURL.lastIndexOf( '/', nPos1 );
1282cdf0e10cSrcweir
1283cdf0e10cSrcweir if ( nPos1 == -1 )
1284cdf0e10cSrcweir return rtl::OUString();
1285cdf0e10cSrcweir
1286cdf0e10cSrcweir return rtl::OUString( aURL.copy( 0, nPos + 1 ) );
1287cdf0e10cSrcweir }
1288cdf0e10cSrcweir
1289cdf0e10cSrcweir //=========================================================================
1290cdf0e10cSrcweir //
1291cdf0e10cSrcweir // Non-interface methods.
1292cdf0e10cSrcweir //
1293cdf0e10cSrcweir //=========================================================================
1294cdf0e10cSrcweir
1295cdf0e10cSrcweir // static
getPropertyValues(const uno::Reference<lang::XMultiServiceFactory> & rSMgr,const uno::Sequence<beans::Property> & rProperties,const ContentProperties & rData,const rtl::Reference<::ucbhelper::ContentProviderImplHelper> & rProvider,const rtl::OUString & rContentId)1296cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues(
1297cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rSMgr,
1298cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties,
1299cdf0e10cSrcweir const ContentProperties& rData,
1300cdf0e10cSrcweir const rtl::Reference< ::ucbhelper::ContentProviderImplHelper >& rProvider,
1301cdf0e10cSrcweir const rtl::OUString& rContentId )
1302cdf0e10cSrcweir {
1303cdf0e10cSrcweir // Note: Empty sequence means "get values of all supported properties".
1304cdf0e10cSrcweir
1305cdf0e10cSrcweir rtl::Reference< ::ucbhelper::PropertyValueSet > xRow
1306cdf0e10cSrcweir = new ::ucbhelper::PropertyValueSet( rSMgr );
1307cdf0e10cSrcweir
1308cdf0e10cSrcweir sal_Int32 nCount = rProperties.getLength();
1309cdf0e10cSrcweir if ( nCount )
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xAdditionalPropSet;
1312cdf0e10cSrcweir sal_Bool bTriedToGetAdditonalPropSet = sal_False;
1313cdf0e10cSrcweir
1314cdf0e10cSrcweir const beans::Property* pProps = rProperties.getConstArray();
1315cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
1316cdf0e10cSrcweir {
1317cdf0e10cSrcweir const beans::Property& rProp = pProps[ n ];
1318cdf0e10cSrcweir
1319cdf0e10cSrcweir // Process standard UCB, DAV and HTTP properties.
1320cdf0e10cSrcweir const uno::Any & rValue = rData.getValue( rProp.Name );
1321cdf0e10cSrcweir if ( rValue.hasValue() )
1322cdf0e10cSrcweir {
1323cdf0e10cSrcweir xRow->appendObject( rProp, rValue );
1324cdf0e10cSrcweir }
1325cdf0e10cSrcweir else
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir // Process local Additional Properties.
1328cdf0e10cSrcweir if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() )
1329cdf0e10cSrcweir {
1330cdf0e10cSrcweir xAdditionalPropSet
1331cdf0e10cSrcweir = uno::Reference< beans::XPropertySet >(
1332cdf0e10cSrcweir rProvider->getAdditionalPropertySet( rContentId,
1333cdf0e10cSrcweir sal_False ),
1334cdf0e10cSrcweir uno::UNO_QUERY );
1335cdf0e10cSrcweir bTriedToGetAdditonalPropSet = sal_True;
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir
1338cdf0e10cSrcweir if ( !xAdditionalPropSet.is() ||
1339cdf0e10cSrcweir !xRow->appendPropertySetValue(
1340cdf0e10cSrcweir xAdditionalPropSet, rProp ) )
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir // Append empty entry.
1343cdf0e10cSrcweir xRow->appendVoid( rProp );
1344cdf0e10cSrcweir }
1345cdf0e10cSrcweir }
1346cdf0e10cSrcweir }
1347cdf0e10cSrcweir }
1348cdf0e10cSrcweir else
1349cdf0e10cSrcweir {
1350cdf0e10cSrcweir // Append all standard UCB, DAV and HTTP properties.
1351cdf0e10cSrcweir
1352cdf0e10cSrcweir const std::auto_ptr< PropertyValueMap > & xProps = rData.getProperties();
1353cdf0e10cSrcweir
1354cdf0e10cSrcweir PropertyValueMap::const_iterator it = xProps->begin();
1355cdf0e10cSrcweir PropertyValueMap::const_iterator end = xProps->end();
1356cdf0e10cSrcweir
1357cdf0e10cSrcweir ContentProvider * pProvider
1358cdf0e10cSrcweir = static_cast< ContentProvider * >( rProvider.get() );
1359cdf0e10cSrcweir beans::Property aProp;
1360cdf0e10cSrcweir
1361cdf0e10cSrcweir while ( it != end )
1362cdf0e10cSrcweir {
1363cdf0e10cSrcweir if ( pProvider->getProperty( (*it).first, aProp ) )
1364cdf0e10cSrcweir xRow->appendObject( aProp, (*it).second.value() );
1365cdf0e10cSrcweir
1366cdf0e10cSrcweir ++it;
1367cdf0e10cSrcweir }
1368cdf0e10cSrcweir
1369cdf0e10cSrcweir // Append all local Additional Properties.
1370cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xSet(
1371cdf0e10cSrcweir rProvider->getAdditionalPropertySet( rContentId, sal_False ),
1372cdf0e10cSrcweir uno::UNO_QUERY );
1373cdf0e10cSrcweir xRow->appendPropertySet( xSet );
1374cdf0e10cSrcweir }
1375cdf0e10cSrcweir
1376cdf0e10cSrcweir return uno::Reference< sdbc::XRow >( xRow.get() );
1377cdf0e10cSrcweir }
1378cdf0e10cSrcweir
1379cdf0e10cSrcweir //=========================================================================
getPropertyValues(const uno::Sequence<beans::Property> & rProperties,const uno::Reference<ucb::XCommandEnvironment> & xEnv)1380cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues(
1381cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties,
1382cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1383cdf0e10cSrcweir throw ( uno::Exception )
1384cdf0e10cSrcweir {
1385cdf0e10cSrcweir std::auto_ptr< ContentProperties > xProps;
1386cdf0e10cSrcweir std::auto_ptr< ContentProperties > xCachedProps;
1387cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
1388cdf0e10cSrcweir rtl::OUString aUnescapedTitle;
1389cdf0e10cSrcweir bool bHasAll = false;
1390cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMgr;
1391cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xIdentifier;
1392cdf0e10cSrcweir rtl::Reference< ::ucbhelper::ContentProviderImplHelper > xProvider;
1393cdf0e10cSrcweir
1394cdf0e10cSrcweir {
1395cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1396cdf0e10cSrcweir
1397*9646dec5SDamjan Jovanovic aUnescapedTitle = CurlUri::unescape( m_aEscapedTitle );
1398cdf0e10cSrcweir xSMgr.set( m_xSMgr );
1399cdf0e10cSrcweir xIdentifier.set( m_xIdentifier );
1400cdf0e10cSrcweir xProvider.set( m_xProvider.get() );
1401cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
1402cdf0e10cSrcweir
1403cdf0e10cSrcweir // First, ask cache...
1404cdf0e10cSrcweir if ( m_xCachedProps.get() )
1405cdf0e10cSrcweir {
1406cdf0e10cSrcweir xCachedProps.reset( new ContentProperties( *m_xCachedProps.get() ) );
1407cdf0e10cSrcweir
1408cdf0e10cSrcweir std::vector< rtl::OUString > aMissingProps;
1409cdf0e10cSrcweir if ( xCachedProps->containsAllNames( rProperties, aMissingProps ) )
1410cdf0e10cSrcweir {
1411cdf0e10cSrcweir // All properties are already in cache! No server access needed.
1412cdf0e10cSrcweir bHasAll = true;
1413cdf0e10cSrcweir }
1414cdf0e10cSrcweir
1415cdf0e10cSrcweir // use the cached ContentProperties instance
1416cdf0e10cSrcweir xProps.reset( new ContentProperties( *xCachedProps.get() ) );
1417cdf0e10cSrcweir }
1418cdf0e10cSrcweir }
1419cdf0e10cSrcweir
1420cdf0e10cSrcweir if ( !m_bTransient && !bHasAll )
1421cdf0e10cSrcweir {
1422cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////
1423cdf0e10cSrcweir // Obtain values from server...
1424cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////
1425cdf0e10cSrcweir
1426cdf0e10cSrcweir // First, identify whether resource is DAV or not
1427cdf0e10cSrcweir const ResourceType & rType = getResourceType( xEnv, xResAccess );
1428cdf0e10cSrcweir
1429cdf0e10cSrcweir bool bNetworkAccessAllowed = true;
1430cdf0e10cSrcweir
1431cdf0e10cSrcweir if ( DAV == rType )
1432cdf0e10cSrcweir {
1433cdf0e10cSrcweir // cache lookup... getResourceType may fill the props cache via
1434cdf0e10cSrcweir // PROPFIND!
1435cdf0e10cSrcweir if ( m_xCachedProps.get() )
1436cdf0e10cSrcweir {
1437cdf0e10cSrcweir xCachedProps.reset(
1438cdf0e10cSrcweir new ContentProperties( *m_xCachedProps.get() ) );
1439cdf0e10cSrcweir
1440cdf0e10cSrcweir std::vector< rtl::OUString > aMissingProps;
1441cdf0e10cSrcweir if ( xCachedProps->containsAllNames(
1442cdf0e10cSrcweir rProperties, aMissingProps ) )
1443cdf0e10cSrcweir {
1444cdf0e10cSrcweir // All properties are already in cache! No server access
1445cdf0e10cSrcweir // needed.
1446cdf0e10cSrcweir bHasAll = true;
1447cdf0e10cSrcweir }
1448cdf0e10cSrcweir
1449cdf0e10cSrcweir // use the cached ContentProperties instance
1450cdf0e10cSrcweir xProps.reset( new ContentProperties( *xCachedProps.get() ) );
1451cdf0e10cSrcweir }
1452cdf0e10cSrcweir
1453cdf0e10cSrcweir if ( !bHasAll )
1454cdf0e10cSrcweir {
14559c0c1533SAndrea Pescetti // Only DAV resources support PROPFIND,
14569c0c1533SAndrea Pescetti // check already done above in the outer 'if' head
1457cdf0e10cSrcweir std::vector< rtl::OUString > aPropNames;
1458cdf0e10cSrcweir
1459cdf0e10cSrcweir uno::Sequence< beans::Property > aProperties(
1460cdf0e10cSrcweir rProperties.getLength() );
1461cdf0e10cSrcweir
1462cdf0e10cSrcweir if ( m_aFailedPropNames.size() > 0 )
1463cdf0e10cSrcweir {
1464cdf0e10cSrcweir sal_Int32 nProps = 0;
1465cdf0e10cSrcweir sal_Int32 nCount = rProperties.getLength();
1466cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
1467cdf0e10cSrcweir {
1468cdf0e10cSrcweir const rtl::OUString & rName = rProperties[ n ].Name;
1469cdf0e10cSrcweir
1470cdf0e10cSrcweir std::vector< rtl::OUString >::const_iterator it
1471cdf0e10cSrcweir = m_aFailedPropNames.begin();
1472cdf0e10cSrcweir std::vector< rtl::OUString >::const_iterator end
1473cdf0e10cSrcweir = m_aFailedPropNames.end();
1474cdf0e10cSrcweir
1475cdf0e10cSrcweir while ( it != end )
1476cdf0e10cSrcweir {
14779c0c1533SAndrea Pescetti if ( *it == rName ) {
14789c0c1533SAndrea Pescetti //the failed property in cache is the same as the requested one
14799c0c1533SAndrea Pescetti //add to the requested properties list
14809c0c1533SAndrea Pescetti aProperties[ nProps ] = rProperties[ n ];
14819c0c1533SAndrea Pescetti nProps++;
1482cdf0e10cSrcweir break;
14839c0c1533SAndrea Pescetti }
1484cdf0e10cSrcweir
1485cdf0e10cSrcweir ++it;
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir }
1488cdf0e10cSrcweir
1489cdf0e10cSrcweir aProperties.realloc( nProps );
1490cdf0e10cSrcweir }
1491cdf0e10cSrcweir else
1492cdf0e10cSrcweir {
1493cdf0e10cSrcweir aProperties = rProperties;
1494cdf0e10cSrcweir }
1495cdf0e10cSrcweir
1496cdf0e10cSrcweir if ( aProperties.getLength() > 0 )
1497cdf0e10cSrcweir ContentProperties::UCBNamesToDAVNames(
1498cdf0e10cSrcweir aProperties, aPropNames );
1499cdf0e10cSrcweir
1500cdf0e10cSrcweir if ( aPropNames.size() > 0 )
1501cdf0e10cSrcweir {
1502cdf0e10cSrcweir std::vector< DAVResource > resources;
1503cdf0e10cSrcweir try
1504cdf0e10cSrcweir {
1505cdf0e10cSrcweir xResAccess->PROPFIND(
1506cdf0e10cSrcweir DAVZERO, aPropNames, resources, xEnv );
1507cdf0e10cSrcweir
1508cdf0e10cSrcweir if ( 1 == resources.size() )
1509cdf0e10cSrcweir {
1510cdf0e10cSrcweir if ( xProps.get())
1511cdf0e10cSrcweir xProps->addProperties(
1512cdf0e10cSrcweir aPropNames,
1513cdf0e10cSrcweir ContentProperties( resources[ 0 ] ));
1514cdf0e10cSrcweir else
1515cdf0e10cSrcweir xProps.reset(
1516cdf0e10cSrcweir new ContentProperties( resources[ 0 ] ) );
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir }
1519cdf0e10cSrcweir catch ( DAVException const & e )
1520cdf0e10cSrcweir {
1521cdf0e10cSrcweir bNetworkAccessAllowed
1522cdf0e10cSrcweir = shouldAccessNetworkAfterException( e );
1523cdf0e10cSrcweir
1524cdf0e10cSrcweir if ( !bNetworkAccessAllowed )
1525cdf0e10cSrcweir {
1526cdf0e10cSrcweir cancelCommandExecution( e, xEnv );
1527cdf0e10cSrcweir // unreachable
1528cdf0e10cSrcweir }
1529cdf0e10cSrcweir }
1530cdf0e10cSrcweir }
1531cdf0e10cSrcweir }
1532cdf0e10cSrcweir }
1533cdf0e10cSrcweir
1534cdf0e10cSrcweir if ( bNetworkAccessAllowed )
1535cdf0e10cSrcweir {
1536cdf0e10cSrcweir // All properties obtained already?
1537cdf0e10cSrcweir std::vector< rtl::OUString > aMissingProps;
1538cdf0e10cSrcweir if ( !( xProps.get()
1539cdf0e10cSrcweir && xProps->containsAllNames(
1540cdf0e10cSrcweir rProperties, aMissingProps ) )
1541f7fef0faSAriel Constenla-Haile || !m_bDidGetOrHead )
1542cdf0e10cSrcweir {
1543cdf0e10cSrcweir // Possibly the missing props can be obtained using a HEAD
1544cdf0e10cSrcweir // request.
1545cdf0e10cSrcweir
1546cdf0e10cSrcweir std::vector< rtl::OUString > aHeaderNames;
1547cdf0e10cSrcweir ContentProperties::UCBNamesToHTTPNames(
1548cdf0e10cSrcweir rProperties,
1549cdf0e10cSrcweir aHeaderNames,
1550cdf0e10cSrcweir true /* bIncludeUnmatched */ );
1551cdf0e10cSrcweir
1552cdf0e10cSrcweir if ( aHeaderNames.size() > 0 )
1553cdf0e10cSrcweir {
1554cdf0e10cSrcweir try
1555cdf0e10cSrcweir {
1556cdf0e10cSrcweir DAVResource resource;
1557cdf0e10cSrcweir xResAccess->HEAD( aHeaderNames, resource, xEnv );
1558cdf0e10cSrcweir m_bDidGetOrHead = true;
1559cdf0e10cSrcweir
1560cdf0e10cSrcweir if ( xProps.get() )
1561cdf0e10cSrcweir xProps->addProperties(
1562cdf0e10cSrcweir aMissingProps,
1563cdf0e10cSrcweir ContentProperties( resource ) );
1564cdf0e10cSrcweir else
1565cdf0e10cSrcweir xProps.reset ( new ContentProperties( resource ) );
1566cdf0e10cSrcweir
1567cdf0e10cSrcweir if ( m_eResourceType == NON_DAV )
1568cdf0e10cSrcweir xProps->addProperties( aMissingProps,
1569cdf0e10cSrcweir ContentProperties(
1570cdf0e10cSrcweir aUnescapedTitle,
1571cdf0e10cSrcweir false ) );
1572cdf0e10cSrcweir }
1573cdf0e10cSrcweir catch ( DAVException const & e )
1574cdf0e10cSrcweir {
1575c5b3447dSAriel Constenla-Haile // non "general-purpose servers" may not support HEAD requests
1576c5b3447dSAriel Constenla-Haile // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1
1577c5b3447dSAriel Constenla-Haile // In this case, perform a partial GET only to get the header info
1578c5b3447dSAriel Constenla-Haile // vid. http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
1579c5b3447dSAriel Constenla-Haile // WARNING if the server does not support partial GETs,
1580c5b3447dSAriel Constenla-Haile // the GET will transfer the whole content
1581c5b3447dSAriel Constenla-Haile bool bError = true;
1582c5b3447dSAriel Constenla-Haile DAVException aLastException = e;
1583c5b3447dSAriel Constenla-Haile
1584c5b3447dSAriel Constenla-Haile // According to the spec. the origin server SHOULD return
1585c5b3447dSAriel Constenla-Haile // * 405 (Method Not Allowed):
1586c5b3447dSAriel Constenla-Haile // the method is known but not allowed for the requested resource
1587c5b3447dSAriel Constenla-Haile // * 501 (Not Implemented):
1588c5b3447dSAriel Constenla-Haile // the method is unrecognized or not implemented
1589c5b3447dSAriel Constenla-Haile // TODO SC_NOT_FOUND is only for google-code server
1590c5b3447dSAriel Constenla-Haile if ( aLastException.getStatus() == SC_NOT_IMPLEMENTED ||
1591c5b3447dSAriel Constenla-Haile aLastException.getStatus() == SC_METHOD_NOT_ALLOWED ||
1592c5b3447dSAriel Constenla-Haile aLastException.getStatus() == SC_NOT_FOUND )
1593c5b3447dSAriel Constenla-Haile {
1594c5b3447dSAriel Constenla-Haile lcl_sendPartialGETRequest( bError,
1595c5b3447dSAriel Constenla-Haile aLastException,
1596c5b3447dSAriel Constenla-Haile aMissingProps,
1597c5b3447dSAriel Constenla-Haile aHeaderNames,
1598c5b3447dSAriel Constenla-Haile xResAccess,
1599c5b3447dSAriel Constenla-Haile xProps,
1600c5b3447dSAriel Constenla-Haile xEnv );
1601c5b3447dSAriel Constenla-Haile m_bDidGetOrHead = !bError;
1602c5b3447dSAriel Constenla-Haile }
1603cdf0e10cSrcweir
1604c5b3447dSAriel Constenla-Haile if ( bError )
1605cdf0e10cSrcweir {
1606c5b3447dSAriel Constenla-Haile if ( !(bNetworkAccessAllowed
1607c5b3447dSAriel Constenla-Haile = shouldAccessNetworkAfterException( aLastException )) )
1608c5b3447dSAriel Constenla-Haile {
1609c5b3447dSAriel Constenla-Haile cancelCommandExecution( aLastException, xEnv );
1610c5b3447dSAriel Constenla-Haile // unreachable
1611c5b3447dSAriel Constenla-Haile }
1612cdf0e10cSrcweir }
1613cdf0e10cSrcweir }
1614cdf0e10cSrcweir }
1615cdf0e10cSrcweir }
1616cdf0e10cSrcweir }
1617cdf0e10cSrcweir
1618cdf0e10cSrcweir // might trigger HTTP redirect.
1619cdf0e10cSrcweir // Therefore, title must be updated here.
1620*9646dec5SDamjan Jovanovic CurlUri aUri( xResAccess->getURL() );
1621cdf0e10cSrcweir aUnescapedTitle = aUri.GetPathBaseNameUnescaped();
1622cdf0e10cSrcweir
1623cdf0e10cSrcweir if ( rType == UNKNOWN )
1624cdf0e10cSrcweir {
1625cdf0e10cSrcweir xProps.reset( new ContentProperties( aUnescapedTitle ) );
1626cdf0e10cSrcweir }
1627cdf0e10cSrcweir
1628cdf0e10cSrcweir // For DAV resources we only know the Title, for non-DAV
1629cdf0e10cSrcweir // resources we additionally know that it is a document.
1630cdf0e10cSrcweir
1631cdf0e10cSrcweir if ( rType == DAV )
1632cdf0e10cSrcweir {
1633cdf0e10cSrcweir //xProps.reset(
1634cdf0e10cSrcweir // new ContentProperties( aUnescapedTitle ) );
1635cdf0e10cSrcweir xProps->addProperty(
1636cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
1637cdf0e10cSrcweir uno::makeAny( aUnescapedTitle ),
1638cdf0e10cSrcweir true );
1639cdf0e10cSrcweir }
1640cdf0e10cSrcweir else
1641cdf0e10cSrcweir {
1642cdf0e10cSrcweir if ( !xProps.get() )
1643cdf0e10cSrcweir xProps.reset( new ContentProperties( aUnescapedTitle, false ) );
1644cdf0e10cSrcweir else
1645cdf0e10cSrcweir xProps->addProperty(
1646cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
1647cdf0e10cSrcweir uno::makeAny( aUnescapedTitle ),
1648cdf0e10cSrcweir true );
1649cdf0e10cSrcweir
1650cdf0e10cSrcweir xProps->addProperty(
1651cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
1652cdf0e10cSrcweir uno::makeAny( false ),
1653cdf0e10cSrcweir true );
1654cdf0e10cSrcweir xProps->addProperty(
1655cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
1656cdf0e10cSrcweir uno::makeAny( true ),
1657cdf0e10cSrcweir true );
16580143b6e0SAriel Constenla-Haile xProps->addProperty(
16590143b6e0SAriel Constenla-Haile rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
16600143b6e0SAriel Constenla-Haile uno::makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WEBDAV_CONTENT_TYPE ) ) ),
16610143b6e0SAriel Constenla-Haile true );
1662cdf0e10cSrcweir }
1663cdf0e10cSrcweir }
1664cdf0e10cSrcweir else
1665cdf0e10cSrcweir {
1666cdf0e10cSrcweir // No server access for just created (not yet committed) objects.
1667cdf0e10cSrcweir // Only a minimal set of properties supported at this stage.
1668cdf0e10cSrcweir if (m_bTransient)
1669cdf0e10cSrcweir xProps.reset( new ContentProperties( aUnescapedTitle,
1670cdf0e10cSrcweir m_bCollection ) );
1671cdf0e10cSrcweir }
1672cdf0e10cSrcweir
1673cdf0e10cSrcweir sal_Int32 nCount = rProperties.getLength();
1674cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
1675cdf0e10cSrcweir {
1676cdf0e10cSrcweir const rtl::OUString rName = rProperties[ n ].Name;
1677cdf0e10cSrcweir if ( rName.equalsAsciiL(
1678cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "BaseURI" ) ) )
1679cdf0e10cSrcweir {
1680cdf0e10cSrcweir // Add BaseURI property, if requested.
1681cdf0e10cSrcweir xProps->addProperty(
1682cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BaseURI" ) ),
1683cdf0e10cSrcweir uno::makeAny( getBaseURI( xResAccess ) ),
1684cdf0e10cSrcweir true );
1685cdf0e10cSrcweir }
1686cdf0e10cSrcweir else if ( rName.equalsAsciiL(
1687cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) )
1688cdf0e10cSrcweir {
1689cdf0e10cSrcweir // Add CreatableContentsInfo property, if requested.
1690cdf0e10cSrcweir sal_Bool bFolder = sal_False;
1691cdf0e10cSrcweir xProps->getValue(
1692cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ) )
1693cdf0e10cSrcweir >>= bFolder;
1694cdf0e10cSrcweir xProps->addProperty(
1695cdf0e10cSrcweir rtl::OUString(
1696cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "CreatableContentsInfo" ) ),
1697cdf0e10cSrcweir uno::makeAny( bFolder
1698cdf0e10cSrcweir ? queryCreatableContentsInfo()
1699cdf0e10cSrcweir : uno::Sequence< ucb::ContentInfo >() ),
1700cdf0e10cSrcweir true );
1701cdf0e10cSrcweir }
1702cdf0e10cSrcweir }
1703cdf0e10cSrcweir
1704cdf0e10cSrcweir uno::Reference< sdbc::XRow > xResultRow
1705cdf0e10cSrcweir = getPropertyValues( xSMgr,
1706cdf0e10cSrcweir rProperties,
1707cdf0e10cSrcweir *xProps,
1708cdf0e10cSrcweir xProvider,
1709cdf0e10cSrcweir xIdentifier->getContentIdentifier() );
1710cdf0e10cSrcweir
1711cdf0e10cSrcweir {
1712cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1713cdf0e10cSrcweir
1714cdf0e10cSrcweir if ( !m_xCachedProps.get() )
1715cdf0e10cSrcweir m_xCachedProps.reset( new CachableContentProperties( *xProps.get() ) );
1716cdf0e10cSrcweir else
1717cdf0e10cSrcweir m_xCachedProps->addProperties( *xProps.get() );
1718cdf0e10cSrcweir
1719cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
1720*9646dec5SDamjan Jovanovic m_aEscapedTitle = CurlUri::escapeSegment( aUnescapedTitle );
1721cdf0e10cSrcweir }
1722cdf0e10cSrcweir
1723cdf0e10cSrcweir return xResultRow;
1724cdf0e10cSrcweir }
1725cdf0e10cSrcweir
1726cdf0e10cSrcweir //=========================================================================
setPropertyValues(const uno::Sequence<beans::PropertyValue> & rValues,const uno::Reference<ucb::XCommandEnvironment> & xEnv)1727cdf0e10cSrcweir uno::Sequence< uno::Any > Content::setPropertyValues(
1728cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rValues,
1729cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1730cdf0e10cSrcweir throw ( uno::Exception )
1731cdf0e10cSrcweir {
1732cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMgr;
1733cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xIdentifier;
1734cdf0e10cSrcweir rtl::Reference< ContentProvider > xProvider;
1735cdf0e10cSrcweir sal_Bool bTransient;
1736cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
1737cdf0e10cSrcweir
1738cdf0e10cSrcweir {
1739cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
1740cdf0e10cSrcweir
1741cdf0e10cSrcweir xProvider.set( m_pProvider );
1742cdf0e10cSrcweir xIdentifier.set( m_xIdentifier );
1743cdf0e10cSrcweir bTransient = m_bTransient;
1744cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
1745cdf0e10cSrcweir xSMgr.set( m_xSMgr );
1746cdf0e10cSrcweir }
1747cdf0e10cSrcweir
1748cdf0e10cSrcweir uno::Sequence< uno::Any > aRet( rValues.getLength() );
1749cdf0e10cSrcweir uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() );
1750cdf0e10cSrcweir sal_Int32 nChanged = 0;
1751cdf0e10cSrcweir
1752cdf0e10cSrcweir beans::PropertyChangeEvent aEvent;
1753cdf0e10cSrcweir aEvent.Source = static_cast< cppu::OWeakObject * >( this );
1754cdf0e10cSrcweir aEvent.Further = sal_False;
1755cdf0e10cSrcweir // aEvent.PropertyName =
1756cdf0e10cSrcweir aEvent.PropertyHandle = -1;
1757cdf0e10cSrcweir // aEvent.OldValue =
1758cdf0e10cSrcweir // aEvent.NewValue =
1759cdf0e10cSrcweir
1760cdf0e10cSrcweir std::vector< ProppatchValue > aProppatchValues;
1761cdf0e10cSrcweir std::vector< sal_Int32 > aProppatchPropsPositions;
1762cdf0e10cSrcweir
1763cdf0e10cSrcweir uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet;
1764cdf0e10cSrcweir sal_Bool bTriedToGetAdditonalPropSet = sal_False;
1765cdf0e10cSrcweir
1766cdf0e10cSrcweir sal_Bool bExchange = sal_False;
1767cdf0e10cSrcweir rtl::OUString aNewTitle;
1768cdf0e10cSrcweir rtl::OUString aOldTitle;
1769cdf0e10cSrcweir sal_Int32 nTitlePos = -1;
1770cdf0e10cSrcweir
1771cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > xInfo;
1772cdf0e10cSrcweir
1773cdf0e10cSrcweir const beans::PropertyValue* pValues = rValues.getConstArray();
1774cdf0e10cSrcweir sal_Int32 nCount = rValues.getLength();
1775cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
1776cdf0e10cSrcweir {
1777cdf0e10cSrcweir const beans::PropertyValue& rValue = pValues[ n ];
1778cdf0e10cSrcweir const rtl::OUString & rName = rValue.Name;
1779cdf0e10cSrcweir
1780cdf0e10cSrcweir beans::Property aTmpProp;
1781cdf0e10cSrcweir xProvider->getProperty( rName, aTmpProp );
1782cdf0e10cSrcweir
1783cdf0e10cSrcweir if ( aTmpProp.Attributes & beans::PropertyAttribute::READONLY )
1784cdf0e10cSrcweir {
1785cdf0e10cSrcweir // Read-only property!
1786cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException(
1787cdf0e10cSrcweir rtl::OUString::createFromAscii(
1788cdf0e10cSrcweir "Property is read-only!" ),
1789cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1790cdf0e10cSrcweir continue;
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir
1793cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
1794cdf0e10cSrcweir // Mandatory props.
1795cdf0e10cSrcweir //////////////////////////////////////////////////////////////////
1796cdf0e10cSrcweir
1797cdf0e10cSrcweir if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) )
1798cdf0e10cSrcweir {
1799cdf0e10cSrcweir // Read-only property!
1800cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException(
1801cdf0e10cSrcweir rtl::OUString::createFromAscii(
1802cdf0e10cSrcweir "Property is read-only!" ),
1803cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1804cdf0e10cSrcweir }
1805cdf0e10cSrcweir else if ( rName.equalsAsciiL(
1806cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) )
1807cdf0e10cSrcweir {
1808cdf0e10cSrcweir // Read-only property!
1809cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException(
1810cdf0e10cSrcweir rtl::OUString::createFromAscii(
1811cdf0e10cSrcweir "Property is read-only!" ),
1812cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1813cdf0e10cSrcweir }
1814cdf0e10cSrcweir else if ( rName.equalsAsciiL(
1815cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) )
1816cdf0e10cSrcweir {
1817cdf0e10cSrcweir // Read-only property!
1818cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException(
1819cdf0e10cSrcweir rtl::OUString::createFromAscii(
1820cdf0e10cSrcweir "Property is read-only!" ),
1821cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1822cdf0e10cSrcweir }
1823cdf0e10cSrcweir else if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
1824cdf0e10cSrcweir {
1825cdf0e10cSrcweir rtl::OUString aNewValue;
1826cdf0e10cSrcweir if ( rValue.Value >>= aNewValue )
1827cdf0e10cSrcweir {
1828cdf0e10cSrcweir // No empty titles!
1829cdf0e10cSrcweir if ( aNewValue.getLength() > 0 )
1830cdf0e10cSrcweir {
1831cdf0e10cSrcweir try
1832cdf0e10cSrcweir {
1833*9646dec5SDamjan Jovanovic CurlUri aURI( xIdentifier->getContentIdentifier() );
1834cdf0e10cSrcweir aOldTitle = aURI.GetPathBaseNameUnescaped();
1835cdf0e10cSrcweir
1836cdf0e10cSrcweir if ( aNewValue != aOldTitle )
1837cdf0e10cSrcweir {
1838cdf0e10cSrcweir // modified title -> modified URL -> exchange !
1839cdf0e10cSrcweir if ( !bTransient )
1840cdf0e10cSrcweir bExchange = sal_True;
1841cdf0e10cSrcweir
1842cdf0e10cSrcweir // new value will be set later...
1843cdf0e10cSrcweir aNewTitle = aNewValue;
1844cdf0e10cSrcweir
1845cdf0e10cSrcweir // remember position within sequence of values (for
1846cdf0e10cSrcweir // error handling).
1847cdf0e10cSrcweir nTitlePos = n;
1848cdf0e10cSrcweir }
1849cdf0e10cSrcweir }
1850cdf0e10cSrcweir catch ( DAVException const & )
1851cdf0e10cSrcweir {
1852cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalArgumentException(
1853cdf0e10cSrcweir rtl::OUString::createFromAscii(
1854cdf0e10cSrcweir "Invalid content identifier!" ),
1855cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1856cdf0e10cSrcweir -1 );
1857cdf0e10cSrcweir }
1858cdf0e10cSrcweir }
1859cdf0e10cSrcweir else
1860cdf0e10cSrcweir {
1861cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalArgumentException(
1862cdf0e10cSrcweir rtl::OUString::createFromAscii(
1863cdf0e10cSrcweir "Empty title not allowed!" ),
1864cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
1865cdf0e10cSrcweir -1 );
1866cdf0e10cSrcweir }
1867cdf0e10cSrcweir }
1868cdf0e10cSrcweir else
1869cdf0e10cSrcweir {
1870cdf0e10cSrcweir aRet[ n ] <<= beans::IllegalTypeException(
1871cdf0e10cSrcweir rtl::OUString::createFromAscii(
1872cdf0e10cSrcweir "Property value has wrong type!" ),
1873cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1874cdf0e10cSrcweir }
1875cdf0e10cSrcweir }
1876cdf0e10cSrcweir else
1877cdf0e10cSrcweir {
1878cdf0e10cSrcweir //////////////////////////////////////////////////////////////
1879cdf0e10cSrcweir // Optional props.
1880cdf0e10cSrcweir //////////////////////////////////////////////////////////////
1881cdf0e10cSrcweir
188206594b87SAriel Constenla-Haile rtl::OUString aSpecialName;
188306594b87SAriel Constenla-Haile bool bIsSpecial = DAVProperties::isUCBSpecialProperty( rName, aSpecialName );
188406594b87SAriel Constenla-Haile
1885cdf0e10cSrcweir if ( !xInfo.is() )
1886cdf0e10cSrcweir xInfo = getPropertySetInfo( xEnv,
1887cdf0e10cSrcweir sal_False /* don't cache data */ );
1888cdf0e10cSrcweir
188906594b87SAriel Constenla-Haile if ( !xInfo->hasPropertyByName( bIsSpecial ? aSpecialName : rName ) )
1890cdf0e10cSrcweir {
1891cdf0e10cSrcweir // Check, whether property exists. Skip otherwise.
1892cdf0e10cSrcweir // PROPPATCH::set would add the property automatically, which
1893cdf0e10cSrcweir // is not allowed for "setPropertyValues" command!
1894cdf0e10cSrcweir aRet[ n ] <<= beans::UnknownPropertyException(
1895cdf0e10cSrcweir rtl::OUString::createFromAscii(
1896cdf0e10cSrcweir "Property is unknown!" ),
1897cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1898cdf0e10cSrcweir continue;
1899cdf0e10cSrcweir }
1900cdf0e10cSrcweir
1901cdf0e10cSrcweir if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) )
1902cdf0e10cSrcweir {
1903cdf0e10cSrcweir // Read-only property!
1904cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException(
1905cdf0e10cSrcweir rtl::OUString::createFromAscii(
1906cdf0e10cSrcweir "Property is read-only!" ),
1907cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1908cdf0e10cSrcweir }
1909cdf0e10cSrcweir else if ( rName.equalsAsciiL(
1910cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) ) )
1911cdf0e10cSrcweir {
1912cdf0e10cSrcweir // Read-only property!
1913cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException(
1914cdf0e10cSrcweir rtl::OUString::createFromAscii(
1915cdf0e10cSrcweir "Property is read-only!" ),
1916cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1917cdf0e10cSrcweir }
1918cdf0e10cSrcweir else if ( rName.equalsAsciiL(
1919cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) )
1920cdf0e10cSrcweir {
1921cdf0e10cSrcweir // Read-only property!
1922cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException(
1923cdf0e10cSrcweir rtl::OUString::createFromAscii(
1924cdf0e10cSrcweir "Property is read-only!" ),
1925cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1926cdf0e10cSrcweir }
1927cdf0e10cSrcweir else if ( rName.equalsAsciiL(
1928cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
1929cdf0e10cSrcweir {
1930cdf0e10cSrcweir // Read-only property!
1931cdf0e10cSrcweir // (but could be writable, if 'getcontenttype' would be)
1932cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException(
1933cdf0e10cSrcweir rtl::OUString::createFromAscii(
1934cdf0e10cSrcweir "Property is read-only!" ),
1935cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1936cdf0e10cSrcweir }
1937cdf0e10cSrcweir if ( rName.equalsAsciiL(
193806594b87SAriel Constenla-Haile RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) )
1939cdf0e10cSrcweir {
1940cdf0e10cSrcweir // Read-only property!
1941cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalAccessException(
1942cdf0e10cSrcweir rtl::OUString::createFromAscii(
1943cdf0e10cSrcweir "Property is read-only!" ),
1944cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
1945cdf0e10cSrcweir }
1946cdf0e10cSrcweir else
1947cdf0e10cSrcweir {
1948cdf0e10cSrcweir if ( getResourceType( xEnv, xResAccess ) == DAV )
1949cdf0e10cSrcweir {
1950cdf0e10cSrcweir // Property value will be set on server.
1951cdf0e10cSrcweir ProppatchValue aValue( PROPSET, rName, rValue.Value );
1952cdf0e10cSrcweir aProppatchValues.push_back( aValue );
1953cdf0e10cSrcweir
1954cdf0e10cSrcweir // remember position within sequence of values (for
1955cdf0e10cSrcweir // error handling).
1956cdf0e10cSrcweir aProppatchPropsPositions.push_back( n );
1957cdf0e10cSrcweir }
1958cdf0e10cSrcweir else
1959cdf0e10cSrcweir {
1960cdf0e10cSrcweir // Property value will be stored in local property store.
1961cdf0e10cSrcweir if ( !bTriedToGetAdditonalPropSet &&
1962cdf0e10cSrcweir !xAdditionalPropSet.is() )
1963cdf0e10cSrcweir {
1964cdf0e10cSrcweir xAdditionalPropSet
1965cdf0e10cSrcweir = getAdditionalPropertySet( sal_False );
1966cdf0e10cSrcweir bTriedToGetAdditonalPropSet = sal_True;
1967cdf0e10cSrcweir }
1968cdf0e10cSrcweir
1969cdf0e10cSrcweir if ( xAdditionalPropSet.is() )
1970cdf0e10cSrcweir {
1971cdf0e10cSrcweir try
1972cdf0e10cSrcweir {
1973cdf0e10cSrcweir uno::Any aOldValue
1974cdf0e10cSrcweir = xAdditionalPropSet->getPropertyValue( rName );
1975cdf0e10cSrcweir if ( aOldValue != rValue.Value )
1976cdf0e10cSrcweir {
1977cdf0e10cSrcweir xAdditionalPropSet->setPropertyValue(
1978cdf0e10cSrcweir rName, rValue.Value );
1979cdf0e10cSrcweir
1980cdf0e10cSrcweir aEvent.PropertyName = rName;
1981cdf0e10cSrcweir aEvent.OldValue = aOldValue;
1982cdf0e10cSrcweir aEvent.NewValue = rValue.Value;
1983cdf0e10cSrcweir
1984cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent;
1985cdf0e10cSrcweir nChanged++;
1986cdf0e10cSrcweir }
1987cdf0e10cSrcweir }
1988cdf0e10cSrcweir catch ( beans::UnknownPropertyException const & e )
1989cdf0e10cSrcweir {
1990cdf0e10cSrcweir aRet[ n ] <<= e;
1991cdf0e10cSrcweir }
1992cdf0e10cSrcweir catch ( lang::WrappedTargetException const & e )
1993cdf0e10cSrcweir {
1994cdf0e10cSrcweir aRet[ n ] <<= e;
1995cdf0e10cSrcweir }
1996cdf0e10cSrcweir catch ( beans::PropertyVetoException const & e )
1997cdf0e10cSrcweir {
1998cdf0e10cSrcweir aRet[ n ] <<= e;
1999cdf0e10cSrcweir }
2000cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & e )
2001cdf0e10cSrcweir {
2002cdf0e10cSrcweir aRet[ n ] <<= e;
2003cdf0e10cSrcweir }
2004cdf0e10cSrcweir }
2005cdf0e10cSrcweir else
2006cdf0e10cSrcweir {
2007cdf0e10cSrcweir aRet[ n ] <<= uno::Exception(
2008cdf0e10cSrcweir rtl::OUString::createFromAscii(
2009cdf0e10cSrcweir "No property set for storing the value!" ),
2010cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
2011cdf0e10cSrcweir }
2012cdf0e10cSrcweir }
2013cdf0e10cSrcweir }
2014cdf0e10cSrcweir }
2015cdf0e10cSrcweir } // for
2016cdf0e10cSrcweir
2017cdf0e10cSrcweir if ( !bTransient && aProppatchValues.size() )
2018cdf0e10cSrcweir {
2019cdf0e10cSrcweir try
2020cdf0e10cSrcweir {
2021cdf0e10cSrcweir // Set property values at server.
2022cdf0e10cSrcweir xResAccess->PROPPATCH( aProppatchValues, xEnv );
2023cdf0e10cSrcweir
2024cdf0e10cSrcweir std::vector< ProppatchValue >::const_iterator it
2025cdf0e10cSrcweir = aProppatchValues.begin();
2026cdf0e10cSrcweir std::vector< ProppatchValue >::const_iterator end
2027cdf0e10cSrcweir = aProppatchValues.end();
2028cdf0e10cSrcweir
2029cdf0e10cSrcweir while ( it != end )
2030cdf0e10cSrcweir {
2031cdf0e10cSrcweir aEvent.PropertyName = (*it).name;
2032cdf0e10cSrcweir aEvent.OldValue = uno::Any(); // @@@ to expensive to obtain!
2033cdf0e10cSrcweir aEvent.NewValue = (*it).value;
2034cdf0e10cSrcweir
2035cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent;
2036cdf0e10cSrcweir nChanged++;
2037cdf0e10cSrcweir
2038cdf0e10cSrcweir ++it;
2039cdf0e10cSrcweir }
2040cdf0e10cSrcweir }
2041cdf0e10cSrcweir catch ( DAVException const & e )
2042cdf0e10cSrcweir {
2043cdf0e10cSrcweir // OSL_ENSURE( sal_False,
2044cdf0e10cSrcweir // "Content::setPropertyValues - PROPPATCH failed!" );
2045cdf0e10cSrcweir
2046cdf0e10cSrcweir #if 1
2047cdf0e10cSrcweir cancelCommandExecution( e, xEnv );
2048cdf0e10cSrcweir // unreachable
2049cdf0e10cSrcweir #else
2050cdf0e10cSrcweir // Note: PROPPATCH either sets ALL property values OR NOTHING.
2051cdf0e10cSrcweir
2052cdf0e10cSrcweir std::vector< sal_Int32 >::const_iterator it
2053cdf0e10cSrcweir = aProppatchPropsPositions.begin();
2054cdf0e10cSrcweir std::vector< sal_Int32 >::const_iterator end
2055cdf0e10cSrcweir = aProppatchPropsPositions.end();
2056cdf0e10cSrcweir
2057cdf0e10cSrcweir while ( it != end )
2058cdf0e10cSrcweir {
2059cdf0e10cSrcweir // Set error.
2060cdf0e10cSrcweir aRet[ (*it) ] <<= MapDAVException( e, sal_True );
2061cdf0e10cSrcweir ++it;
2062cdf0e10cSrcweir }
2063cdf0e10cSrcweir #endif
2064cdf0e10cSrcweir }
2065cdf0e10cSrcweir }
2066cdf0e10cSrcweir
2067cdf0e10cSrcweir if ( bExchange )
2068cdf0e10cSrcweir {
2069cdf0e10cSrcweir // Assemble new content identifier...
2070cdf0e10cSrcweir
2071cdf0e10cSrcweir rtl::OUString aNewURL = getParentURL();
2072cdf0e10cSrcweir if ( aNewURL.lastIndexOf( '/' ) != ( aNewURL.getLength() - 1 ) )
2073cdf0e10cSrcweir aNewURL += rtl::OUString::createFromAscii( "/" );
2074cdf0e10cSrcweir
2075*9646dec5SDamjan Jovanovic aNewURL += CurlUri::escapeSegment( aNewTitle );
2076cdf0e10cSrcweir
2077cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xNewId
2078cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( xSMgr, aNewURL );
2079cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xOldId = xIdentifier;
2080cdf0e10cSrcweir
2081cdf0e10cSrcweir try
2082cdf0e10cSrcweir {
2083*9646dec5SDamjan Jovanovic CurlUri sourceURI( xOldId->getContentIdentifier() );
2084*9646dec5SDamjan Jovanovic CurlUri targetURI( xNewId->getContentIdentifier() );
2085cdf0e10cSrcweir targetURI.SetScheme( sourceURI.GetScheme() );
2086cdf0e10cSrcweir
2087cdf0e10cSrcweir xResAccess->MOVE(
2088cdf0e10cSrcweir sourceURI.GetPath(), targetURI.GetURI(), sal_False, xEnv );
2089cdf0e10cSrcweir // @@@ Should check for resources that could not be moved
2090cdf0e10cSrcweir // (due to source access or target overwrite) and send
2091cdf0e10cSrcweir // this information through the interaction handler.
2092cdf0e10cSrcweir
2093cdf0e10cSrcweir // @@@ Existing content should be checked to see if it needs
2094cdf0e10cSrcweir // to be deleted at the source
2095cdf0e10cSrcweir
2096cdf0e10cSrcweir // @@@ Existing content should be checked to see if it has
2097cdf0e10cSrcweir // been overwritten at the target
2098cdf0e10cSrcweir
2099cdf0e10cSrcweir if ( exchangeIdentity( xNewId ) )
2100cdf0e10cSrcweir {
2101cdf0e10cSrcweir xResAccess->setURL( aNewURL );
2102cdf0e10cSrcweir
2103cdf0e10cSrcweir // DAV resources store all additional props on server!
2104cdf0e10cSrcweir // // Adapt Additional Core Properties.
2105cdf0e10cSrcweir // renameAdditionalPropertySet( xOldId->getContentIdentifier(),
2106cdf0e10cSrcweir // xNewId->getContentIdentifier(),
2107cdf0e10cSrcweir // sal_True );
2108cdf0e10cSrcweir }
2109cdf0e10cSrcweir else
2110cdf0e10cSrcweir {
2111cdf0e10cSrcweir // Do not set new title!
2112cdf0e10cSrcweir aNewTitle = rtl::OUString();
2113cdf0e10cSrcweir
2114cdf0e10cSrcweir // Set error .
2115cdf0e10cSrcweir aRet[ nTitlePos ] <<= uno::Exception(
2116cdf0e10cSrcweir rtl::OUString::createFromAscii( "Exchange failed!" ),
2117cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) );
2118cdf0e10cSrcweir }
2119cdf0e10cSrcweir }
2120cdf0e10cSrcweir catch ( DAVException const & e )
2121cdf0e10cSrcweir {
2122cdf0e10cSrcweir // Do not set new title!
2123cdf0e10cSrcweir aNewTitle = rtl::OUString();
2124cdf0e10cSrcweir
2125cdf0e10cSrcweir // Set error .
2126cdf0e10cSrcweir aRet[ nTitlePos ] <<= MapDAVException( e, sal_True );
2127cdf0e10cSrcweir }
2128cdf0e10cSrcweir }
2129cdf0e10cSrcweir
2130cdf0e10cSrcweir if ( aNewTitle.getLength() )
2131cdf0e10cSrcweir {
2132cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2133cdf0e10cSrcweir
2134cdf0e10cSrcweir aEvent.PropertyName = rtl::OUString::createFromAscii( "Title" );
2135cdf0e10cSrcweir aEvent.OldValue = uno::makeAny( aOldTitle );
2136cdf0e10cSrcweir aEvent.NewValue = uno::makeAny( aNewTitle );
2137cdf0e10cSrcweir
2138*9646dec5SDamjan Jovanovic m_aEscapedTitle = CurlUri::escapeSegment( aNewTitle );
2139cdf0e10cSrcweir
2140cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent;
2141cdf0e10cSrcweir nChanged++;
2142cdf0e10cSrcweir }
2143cdf0e10cSrcweir
2144cdf0e10cSrcweir if ( nChanged > 0 )
2145cdf0e10cSrcweir {
2146cdf0e10cSrcweir aChanges.realloc( nChanged );
2147cdf0e10cSrcweir notifyPropertiesChange( aChanges );
2148cdf0e10cSrcweir }
2149cdf0e10cSrcweir
2150cdf0e10cSrcweir {
2151cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2152cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
2153cdf0e10cSrcweir }
2154cdf0e10cSrcweir
2155cdf0e10cSrcweir return aRet;
2156cdf0e10cSrcweir }
2157cdf0e10cSrcweir
2158cdf0e10cSrcweir //=========================================================================
open(const ucb::OpenCommandArgument2 & rArg,const uno::Reference<ucb::XCommandEnvironment> & xEnv)2159cdf0e10cSrcweir uno::Any Content::open(
2160cdf0e10cSrcweir const ucb::OpenCommandArgument2 & rArg,
2161cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2162cdf0e10cSrcweir throw( uno::Exception )
2163cdf0e10cSrcweir {
2164cdf0e10cSrcweir uno::Any aRet;
2165cdf0e10cSrcweir
2166cdf0e10cSrcweir sal_Bool bOpenFolder = ( ( rArg.Mode == ucb::OpenMode::ALL ) ||
2167cdf0e10cSrcweir ( rArg.Mode == ucb::OpenMode::FOLDERS ) ||
2168cdf0e10cSrcweir ( rArg.Mode == ucb::OpenMode::DOCUMENTS ) );
2169cdf0e10cSrcweir if ( bOpenFolder )
2170cdf0e10cSrcweir {
2171cdf0e10cSrcweir if ( isFolder( xEnv ) )
2172cdf0e10cSrcweir {
2173cdf0e10cSrcweir // Open collection.
2174cdf0e10cSrcweir
2175cdf0e10cSrcweir uno::Reference< ucb::XDynamicResultSet > xSet
2176cdf0e10cSrcweir = new DynamicResultSet( m_xSMgr, this, rArg, xEnv );
2177cdf0e10cSrcweir aRet <<= xSet;
2178cdf0e10cSrcweir }
2179cdf0e10cSrcweir else
2180cdf0e10cSrcweir {
2181cdf0e10cSrcweir // Error: Not a folder!
2182cdf0e10cSrcweir
2183cdf0e10cSrcweir rtl::OUStringBuffer aMsg;
218459ddfc10SAndre Fischer aMsg.appendAscii( "Non-folder resource cannot be "
218559ddfc10SAndre Fischer "opened as folder! Wrong Open Mode!" );
2186cdf0e10cSrcweir
2187cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2188cdf0e10cSrcweir uno::makeAny(
2189cdf0e10cSrcweir lang::IllegalArgumentException(
2190cdf0e10cSrcweir aMsg.makeStringAndClear(),
2191cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
2192cdf0e10cSrcweir -1 ) ),
2193cdf0e10cSrcweir xEnv );
2194cdf0e10cSrcweir // Unreachable
2195cdf0e10cSrcweir }
2196cdf0e10cSrcweir }
2197cdf0e10cSrcweir
2198cdf0e10cSrcweir if ( rArg.Sink.is() )
2199cdf0e10cSrcweir {
2200cdf0e10cSrcweir // Open document.
2201cdf0e10cSrcweir
2202cdf0e10cSrcweir if ( ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
2203cdf0e10cSrcweir ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) )
2204cdf0e10cSrcweir {
2205cdf0e10cSrcweir // Currently(?) unsupported.
2206cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2207cdf0e10cSrcweir uno::makeAny(
2208cdf0e10cSrcweir ucb::UnsupportedOpenModeException(
2209cdf0e10cSrcweir rtl::OUString(),
2210cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
2211cdf0e10cSrcweir sal_Int16( rArg.Mode ) ) ),
2212cdf0e10cSrcweir xEnv );
2213cdf0e10cSrcweir // Unreachable
2214cdf0e10cSrcweir }
2215cdf0e10cSrcweir
2216cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
2217cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut
2218cdf0e10cSrcweir = uno::Reference< io::XOutputStream >( rArg.Sink, uno::UNO_QUERY );
2219cdf0e10cSrcweir if ( xOut.is() )
2220cdf0e10cSrcweir {
2221cdf0e10cSrcweir // PUSH: write data
2222cdf0e10cSrcweir try
2223cdf0e10cSrcweir {
2224cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
2225cdf0e10cSrcweir
2226cdf0e10cSrcweir {
2227cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
2228cdf0e10cSrcweir
2229cdf0e10cSrcweir xResAccess.reset(
2230cdf0e10cSrcweir new DAVResourceAccess( *m_xResAccess.get() ) );
2231cdf0e10cSrcweir }
2232cdf0e10cSrcweir
2233cdf0e10cSrcweir DAVResource aResource;
2234cdf0e10cSrcweir std::vector< rtl::OUString > aHeaders;
2235cdf0e10cSrcweir
2236cdf0e10cSrcweir xResAccess->GET( xOut, aHeaders, aResource, xEnv );
2237cdf0e10cSrcweir m_bDidGetOrHead = true;
2238cdf0e10cSrcweir
2239cdf0e10cSrcweir {
2240cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
2241cdf0e10cSrcweir
2242cdf0e10cSrcweir // cache headers.
2243cdf0e10cSrcweir if ( !m_xCachedProps.get())
2244cdf0e10cSrcweir m_xCachedProps.reset(
2245cdf0e10cSrcweir new CachableContentProperties( aResource ) );
2246cdf0e10cSrcweir else
2247cdf0e10cSrcweir m_xCachedProps->addProperties( aResource );
2248cdf0e10cSrcweir
2249cdf0e10cSrcweir m_xResAccess.reset(
2250cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) );
2251cdf0e10cSrcweir }
2252cdf0e10cSrcweir }
2253cdf0e10cSrcweir catch ( DAVException const & e )
2254cdf0e10cSrcweir {
2255cdf0e10cSrcweir cancelCommandExecution( e, xEnv );
2256cdf0e10cSrcweir // Unreachable
2257cdf0e10cSrcweir }
2258cdf0e10cSrcweir }
2259cdf0e10cSrcweir else
2260cdf0e10cSrcweir {
2261cdf0e10cSrcweir uno::Reference< io::XActiveDataSink > xDataSink
2262cdf0e10cSrcweir = uno::Reference< io::XActiveDataSink >( rArg.Sink,
2263cdf0e10cSrcweir uno::UNO_QUERY );
2264cdf0e10cSrcweir if ( xDataSink.is() )
2265cdf0e10cSrcweir {
2266cdf0e10cSrcweir // PULL: wait for client read
2267cdf0e10cSrcweir try
2268cdf0e10cSrcweir {
2269cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
2270cdf0e10cSrcweir {
2271cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
2272cdf0e10cSrcweir
2273cdf0e10cSrcweir xResAccess.reset(
2274cdf0e10cSrcweir new DAVResourceAccess( *m_xResAccess.get() ) );
2275cdf0e10cSrcweir }
2276cdf0e10cSrcweir
2277cdf0e10cSrcweir // fill inputsream sync; return if all data present
2278cdf0e10cSrcweir DAVResource aResource;
2279cdf0e10cSrcweir std::vector< rtl::OUString > aHeaders;
2280cdf0e10cSrcweir
2281cdf0e10cSrcweir uno::Reference< io::XInputStream > xIn
2282cdf0e10cSrcweir = xResAccess->GET( aHeaders, aResource, xEnv );
2283cdf0e10cSrcweir m_bDidGetOrHead = true;
2284cdf0e10cSrcweir
2285cdf0e10cSrcweir {
2286cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
2287cdf0e10cSrcweir
2288cdf0e10cSrcweir // cache headers.
2289cdf0e10cSrcweir if ( !m_xCachedProps.get())
2290cdf0e10cSrcweir m_xCachedProps.reset(
2291cdf0e10cSrcweir new CachableContentProperties( aResource ) );
2292cdf0e10cSrcweir else
2293cdf0e10cSrcweir m_xCachedProps->addProperties(
2294cdf0e10cSrcweir aResource.properties );
2295cdf0e10cSrcweir
2296cdf0e10cSrcweir m_xResAccess.reset(
2297cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) );
2298cdf0e10cSrcweir }
2299cdf0e10cSrcweir
2300cdf0e10cSrcweir xDataSink->setInputStream( xIn );
2301cdf0e10cSrcweir }
2302cdf0e10cSrcweir catch ( DAVException const & e )
2303cdf0e10cSrcweir {
2304cdf0e10cSrcweir cancelCommandExecution( e, xEnv );
2305cdf0e10cSrcweir // Unreachable
2306cdf0e10cSrcweir }
2307cdf0e10cSrcweir }
2308cdf0e10cSrcweir else
2309cdf0e10cSrcweir {
2310cdf0e10cSrcweir // Note: aOpenCommand.Sink may contain an XStream
2311cdf0e10cSrcweir // implementation. Support for this type of
2312cdf0e10cSrcweir // sink is optional...
2313cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2314cdf0e10cSrcweir uno::makeAny(
2315cdf0e10cSrcweir ucb::UnsupportedDataSinkException(
2316cdf0e10cSrcweir rtl::OUString(),
2317cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
2318cdf0e10cSrcweir rArg.Sink ) ),
2319cdf0e10cSrcweir xEnv );
2320cdf0e10cSrcweir // Unreachable
2321cdf0e10cSrcweir }
2322cdf0e10cSrcweir }
2323cdf0e10cSrcweir }
2324cdf0e10cSrcweir
2325cdf0e10cSrcweir return aRet;
2326cdf0e10cSrcweir }
2327cdf0e10cSrcweir
2328cdf0e10cSrcweir //=========================================================================
post(const ucb::PostCommandArgument2 & rArg,const uno::Reference<ucb::XCommandEnvironment> & xEnv)2329cdf0e10cSrcweir void Content::post(
2330cdf0e10cSrcweir const ucb::PostCommandArgument2 & rArg,
2331cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2332cdf0e10cSrcweir throw( uno::Exception )
2333cdf0e10cSrcweir {
2334cdf0e10cSrcweir uno::Reference< io::XActiveDataSink > xSink( rArg.Sink, uno::UNO_QUERY );
2335cdf0e10cSrcweir if ( xSink.is() )
2336cdf0e10cSrcweir {
2337cdf0e10cSrcweir try
2338cdf0e10cSrcweir {
2339cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
2340cdf0e10cSrcweir {
2341cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
2342cdf0e10cSrcweir xResAccess.reset(
2343cdf0e10cSrcweir new DAVResourceAccess( *m_xResAccess.get() ) );
2344cdf0e10cSrcweir }
2345cdf0e10cSrcweir
2346cdf0e10cSrcweir uno::Reference< io::XInputStream > xResult
2347cdf0e10cSrcweir = xResAccess->POST( rArg.MediaType,
2348cdf0e10cSrcweir rArg.Referer,
2349cdf0e10cSrcweir rArg.Source,
2350cdf0e10cSrcweir xEnv );
2351cdf0e10cSrcweir
2352cdf0e10cSrcweir {
2353cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
2354cdf0e10cSrcweir m_xResAccess.reset(
2355cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) );
2356cdf0e10cSrcweir }
2357cdf0e10cSrcweir
2358cdf0e10cSrcweir xSink->setInputStream( xResult );
2359cdf0e10cSrcweir }
2360cdf0e10cSrcweir catch ( DAVException const & e )
2361cdf0e10cSrcweir {
2362cdf0e10cSrcweir cancelCommandExecution( e, xEnv, sal_True );
2363cdf0e10cSrcweir // Unreachable
2364cdf0e10cSrcweir }
2365cdf0e10cSrcweir }
2366cdf0e10cSrcweir else
2367cdf0e10cSrcweir {
2368cdf0e10cSrcweir uno::Reference< io::XOutputStream > xResult( rArg.Sink, uno::UNO_QUERY );
2369cdf0e10cSrcweir if ( xResult.is() )
2370cdf0e10cSrcweir {
2371cdf0e10cSrcweir try
2372cdf0e10cSrcweir {
2373cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
2374cdf0e10cSrcweir {
2375cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
2376cdf0e10cSrcweir xResAccess.reset(
2377cdf0e10cSrcweir new DAVResourceAccess( *m_xResAccess.get() ) );
2378cdf0e10cSrcweir }
2379cdf0e10cSrcweir
2380cdf0e10cSrcweir xResAccess->POST( rArg.MediaType,
2381cdf0e10cSrcweir rArg.Referer,
2382cdf0e10cSrcweir rArg.Source,
2383cdf0e10cSrcweir xResult,
2384cdf0e10cSrcweir xEnv );
2385cdf0e10cSrcweir
2386cdf0e10cSrcweir {
2387cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
2388cdf0e10cSrcweir m_xResAccess.reset(
2389cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) );
2390cdf0e10cSrcweir }
2391cdf0e10cSrcweir }
2392cdf0e10cSrcweir catch ( DAVException const & e )
2393cdf0e10cSrcweir {
2394cdf0e10cSrcweir cancelCommandExecution( e, xEnv, sal_True );
2395cdf0e10cSrcweir // Unreachable
2396cdf0e10cSrcweir }
2397cdf0e10cSrcweir }
2398cdf0e10cSrcweir else
2399cdf0e10cSrcweir {
2400cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2401cdf0e10cSrcweir uno::makeAny(
2402cdf0e10cSrcweir ucb::UnsupportedDataSinkException(
2403cdf0e10cSrcweir rtl::OUString(),
2404cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
2405cdf0e10cSrcweir rArg.Sink ) ),
2406cdf0e10cSrcweir xEnv );
2407cdf0e10cSrcweir // Unreachable
2408cdf0e10cSrcweir }
2409cdf0e10cSrcweir }
2410cdf0e10cSrcweir }
2411cdf0e10cSrcweir
2412cdf0e10cSrcweir //=========================================================================
queryChildren(ContentRefList & rChildren)2413cdf0e10cSrcweir void Content::queryChildren( ContentRefList& rChildren )
2414cdf0e10cSrcweir {
2415cdf0e10cSrcweir // Obtain a list with a snapshot of all currently instanciated contents
2416cdf0e10cSrcweir // from provider and extract the contents which are direct children
2417cdf0e10cSrcweir // of this content.
2418cdf0e10cSrcweir
2419cdf0e10cSrcweir ::ucbhelper::ContentRefList aAllContents;
2420cdf0e10cSrcweir m_xProvider->queryExistingContents( aAllContents );
2421cdf0e10cSrcweir
2422cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
2423cdf0e10cSrcweir sal_Int32 nURLPos = aURL.lastIndexOf( '/' );
2424cdf0e10cSrcweir
2425cdf0e10cSrcweir if ( nURLPos != ( aURL.getLength() - 1 ) )
2426cdf0e10cSrcweir {
2427cdf0e10cSrcweir // No trailing slash found. Append.
2428cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" );
2429cdf0e10cSrcweir }
2430cdf0e10cSrcweir
2431cdf0e10cSrcweir sal_Int32 nLen = aURL.getLength();
2432cdf0e10cSrcweir
2433cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
2434cdf0e10cSrcweir ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
2435cdf0e10cSrcweir
2436cdf0e10cSrcweir while ( it != end )
2437cdf0e10cSrcweir {
2438cdf0e10cSrcweir ::ucbhelper::ContentImplHelperRef xChild = (*it);
2439cdf0e10cSrcweir rtl::OUString aChildURL
2440cdf0e10cSrcweir = xChild->getIdentifier()->getContentIdentifier();
2441cdf0e10cSrcweir
2442cdf0e10cSrcweir // Is aURL a prefix of aChildURL?
2443cdf0e10cSrcweir if ( ( aChildURL.getLength() > nLen ) &&
2444cdf0e10cSrcweir ( aChildURL.compareTo( aURL, nLen ) == 0 ) )
2445cdf0e10cSrcweir {
2446cdf0e10cSrcweir sal_Int32 nPos = nLen;
2447cdf0e10cSrcweir nPos = aChildURL.indexOf( '/', nPos );
2448cdf0e10cSrcweir
2449cdf0e10cSrcweir if ( ( nPos == -1 ) ||
2450cdf0e10cSrcweir ( nPos == ( aChildURL.getLength() - 1 ) ) )
2451cdf0e10cSrcweir {
2452cdf0e10cSrcweir // No further slashes / only a final slash. It's a child!
2453cdf0e10cSrcweir rChildren.push_back(
245459ddfc10SAndre Fischer ::http_dav_ucp::Content::ContentRef(
245559ddfc10SAndre Fischer static_cast< ::http_dav_ucp::Content * >(
2456cdf0e10cSrcweir xChild.get() ) ) );
2457cdf0e10cSrcweir }
2458cdf0e10cSrcweir }
2459cdf0e10cSrcweir ++it;
2460cdf0e10cSrcweir }
2461cdf0e10cSrcweir }
2462cdf0e10cSrcweir
2463cdf0e10cSrcweir //=========================================================================
insert(const uno::Reference<io::XInputStream> & xInputStream,sal_Bool bReplaceExisting,const uno::Reference<ucb::XCommandEnvironment> & Environment)2464cdf0e10cSrcweir void Content::insert(
2465cdf0e10cSrcweir const uno::Reference< io::XInputStream > & xInputStream,
2466cdf0e10cSrcweir sal_Bool bReplaceExisting,
2467cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment )
2468cdf0e10cSrcweir throw( uno::Exception )
2469cdf0e10cSrcweir {
2470cdf0e10cSrcweir sal_Bool bTransient, bCollection;
2471cdf0e10cSrcweir rtl::OUString aEscapedTitle;
2472cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
2473cdf0e10cSrcweir
2474cdf0e10cSrcweir {
2475cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2476cdf0e10cSrcweir
2477cdf0e10cSrcweir bTransient = m_bTransient;
2478cdf0e10cSrcweir bCollection = m_bCollection;
2479cdf0e10cSrcweir aEscapedTitle = m_aEscapedTitle;
2480cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
2481cdf0e10cSrcweir }
2482cdf0e10cSrcweir
2483cdf0e10cSrcweir // Check, if all required properties are present.
2484cdf0e10cSrcweir
2485cdf0e10cSrcweir if ( aEscapedTitle.getLength() == 0 )
2486cdf0e10cSrcweir {
2487cdf0e10cSrcweir OSL_ENSURE( sal_False, "Content::insert - Title missing!" );
2488cdf0e10cSrcweir
2489cdf0e10cSrcweir uno::Sequence< rtl::OUString > aProps( 1 );
2490cdf0e10cSrcweir aProps[ 0 ] = rtl::OUString::createFromAscii( "Title" );
2491cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2492cdf0e10cSrcweir uno::makeAny( ucb::MissingPropertiesException(
2493cdf0e10cSrcweir rtl::OUString(),
2494cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
2495cdf0e10cSrcweir aProps ) ),
2496cdf0e10cSrcweir Environment );
2497cdf0e10cSrcweir // Unreachable
2498cdf0e10cSrcweir }
2499cdf0e10cSrcweir
2500cdf0e10cSrcweir if ( !bReplaceExisting )
2501cdf0e10cSrcweir {
2502cdf0e10cSrcweir /* [RFC 2616] - HTTP
2503cdf0e10cSrcweir
2504cdf0e10cSrcweir The PUT method requests that the enclosed entity be stored under the
2505cdf0e10cSrcweir supplied Request-URI. If the Request-URI refers to an already
2506cdf0e10cSrcweir existing resource, the enclosed entity SHOULD be considered as a
2507cdf0e10cSrcweir modified version of the one residing on the origin server.
2508cdf0e10cSrcweir */
2509cdf0e10cSrcweir
2510cdf0e10cSrcweir /* [RFC 2518] - WebDAV
2511cdf0e10cSrcweir
2512cdf0e10cSrcweir MKCOL creates a new collection resource at the location specified by
2513cdf0e10cSrcweir the Request-URI. If the resource identified by the Request-URI is
2514cdf0e10cSrcweir non-null then the MKCOL MUST fail.
2515cdf0e10cSrcweir */
2516cdf0e10cSrcweir
2517cdf0e10cSrcweir // ==> Complain on PUT, continue on MKCOL.
2518cdf0e10cSrcweir if ( !bTransient || ( bTransient && !bCollection ) )
2519cdf0e10cSrcweir {
252059ddfc10SAndre Fischer #undef ERROR
2521cdf0e10cSrcweir ucb::UnsupportedNameClashException aEx(
252259ddfc10SAndre Fischer rtl::OUString::createFromAscii( "Unable to write without overwrite!" ),
2523cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
2524cdf0e10cSrcweir ucb::NameClash::ERROR );
2525cdf0e10cSrcweir
2526cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xIH;
2527cdf0e10cSrcweir
2528cdf0e10cSrcweir if ( Environment.is() )
2529cdf0e10cSrcweir xIH = Environment->getInteractionHandler();
2530cdf0e10cSrcweir
2531cdf0e10cSrcweir if ( xIH.is() )
2532cdf0e10cSrcweir {
2533cdf0e10cSrcweir uno::Any aExAsAny( uno::makeAny( aEx ) );
2534cdf0e10cSrcweir
2535cdf0e10cSrcweir rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest
2536cdf0e10cSrcweir = new ucbhelper::SimpleInteractionRequest(
2537cdf0e10cSrcweir aExAsAny,
2538cdf0e10cSrcweir ucbhelper::CONTINUATION_APPROVE
2539cdf0e10cSrcweir | ucbhelper::CONTINUATION_DISAPPROVE );
2540cdf0e10cSrcweir xIH->handle( xRequest.get() );
2541cdf0e10cSrcweir
2542cdf0e10cSrcweir const sal_Int32 nResp = xRequest->getResponse();
2543cdf0e10cSrcweir
2544cdf0e10cSrcweir switch ( nResp )
2545cdf0e10cSrcweir {
2546cdf0e10cSrcweir case ucbhelper::CONTINUATION_UNKNOWN:
2547cdf0e10cSrcweir // Not handled; throw.
2548cdf0e10cSrcweir throw aEx;
2549cdf0e10cSrcweir // break;
2550cdf0e10cSrcweir
2551cdf0e10cSrcweir case ucbhelper::CONTINUATION_APPROVE:
2552cdf0e10cSrcweir // Continue -> Overwrite.
2553cdf0e10cSrcweir bReplaceExisting = sal_True;
2554cdf0e10cSrcweir break;
2555cdf0e10cSrcweir
2556cdf0e10cSrcweir case ucbhelper::CONTINUATION_DISAPPROVE:
2557cdf0e10cSrcweir // Abort.
2558cdf0e10cSrcweir throw ucb::CommandFailedException(
2559cdf0e10cSrcweir rtl::OUString(),
2560cdf0e10cSrcweir uno::Reference< uno::XInterface >(),
2561cdf0e10cSrcweir aExAsAny );
2562cdf0e10cSrcweir // break;
2563cdf0e10cSrcweir
2564cdf0e10cSrcweir default:
2565cdf0e10cSrcweir OSL_ENSURE( sal_False,
2566cdf0e10cSrcweir "Content::insert - "
2567cdf0e10cSrcweir "Unknown interaction selection!" );
2568cdf0e10cSrcweir throw ucb::CommandFailedException(
2569cdf0e10cSrcweir rtl::OUString::createFromAscii(
2570cdf0e10cSrcweir "Unknown interaction selection!" ),
2571cdf0e10cSrcweir uno::Reference< uno::XInterface >(),
2572cdf0e10cSrcweir aExAsAny );
2573cdf0e10cSrcweir // break;
2574cdf0e10cSrcweir }
2575cdf0e10cSrcweir }
2576cdf0e10cSrcweir else
2577cdf0e10cSrcweir {
2578cdf0e10cSrcweir // No IH; throw.
2579cdf0e10cSrcweir throw aEx;
2580cdf0e10cSrcweir }
2581cdf0e10cSrcweir }
2582cdf0e10cSrcweir }
2583cdf0e10cSrcweir
2584cdf0e10cSrcweir if ( bTransient )
2585cdf0e10cSrcweir {
2586cdf0e10cSrcweir // Assemble new content identifier...
2587cdf0e10cSrcweir rtl::OUString aURL = getParentURL();
2588cdf0e10cSrcweir if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) )
2589cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" );
2590cdf0e10cSrcweir
2591cdf0e10cSrcweir aURL += aEscapedTitle;
2592cdf0e10cSrcweir
2593cdf0e10cSrcweir try
2594cdf0e10cSrcweir {
2595cdf0e10cSrcweir xResAccess->setURL( aURL );
2596cdf0e10cSrcweir
2597cdf0e10cSrcweir if ( bCollection )
2598cdf0e10cSrcweir xResAccess->MKCOL( Environment );
2599cdf0e10cSrcweir else
2600cdf0e10cSrcweir xResAccess->PUT( xInputStream, Environment );
2601cdf0e10cSrcweir }
2602cdf0e10cSrcweir catch ( DAVException const & except )
2603cdf0e10cSrcweir {
2604cdf0e10cSrcweir if ( bCollection )
2605cdf0e10cSrcweir {
2606cdf0e10cSrcweir if ( except.getStatus() == SC_METHOD_NOT_ALLOWED )
2607cdf0e10cSrcweir {
2608cdf0e10cSrcweir // [RFC 2518] - WebDAV
2609cdf0e10cSrcweir // 405 (Method Not Allowed) - MKCOL can only be
2610cdf0e10cSrcweir // executed on a deleted/non-existent resource.
2611cdf0e10cSrcweir
2612cdf0e10cSrcweir if ( bReplaceExisting )
2613cdf0e10cSrcweir {
2614cdf0e10cSrcweir // Destroy old resource.
2615cdf0e10cSrcweir try
2616cdf0e10cSrcweir {
2617cdf0e10cSrcweir xResAccess->DESTROY( Environment );
2618cdf0e10cSrcweir }
2619cdf0e10cSrcweir catch ( DAVException const & e )
2620cdf0e10cSrcweir {
2621cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_True );
2622cdf0e10cSrcweir // Unreachable
2623cdf0e10cSrcweir }
2624cdf0e10cSrcweir
2625cdf0e10cSrcweir // Insert (recursion!).
2626cdf0e10cSrcweir insert( xInputStream, bReplaceExisting, Environment );
2627cdf0e10cSrcweir
2628cdf0e10cSrcweir {
2629cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2630cdf0e10cSrcweir m_xResAccess.reset(
2631cdf0e10cSrcweir new DAVResourceAccess( *xResAccess.get() ) );
2632cdf0e10cSrcweir }
2633cdf0e10cSrcweir
2634cdf0e10cSrcweir // Success!
2635cdf0e10cSrcweir return;
2636cdf0e10cSrcweir }
2637cdf0e10cSrcweir else
2638cdf0e10cSrcweir {
2639cdf0e10cSrcweir rtl::OUString aTitle;
2640cdf0e10cSrcweir try
2641cdf0e10cSrcweir {
2642*9646dec5SDamjan Jovanovic CurlUri aURI( aURL );
2643cdf0e10cSrcweir aTitle = aURI.GetPathBaseNameUnescaped();
2644cdf0e10cSrcweir }
2645cdf0e10cSrcweir catch ( DAVException const & )
2646cdf0e10cSrcweir {
2647cdf0e10cSrcweir }
2648cdf0e10cSrcweir
2649cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2650cdf0e10cSrcweir uno::makeAny(
2651cdf0e10cSrcweir ucb::NameClashException(
2652cdf0e10cSrcweir rtl::OUString(),
2653cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
2654cdf0e10cSrcweir task::InteractionClassification_ERROR,
2655cdf0e10cSrcweir aTitle ) ),
2656cdf0e10cSrcweir Environment );
2657cdf0e10cSrcweir // Unreachable
2658cdf0e10cSrcweir }
2659cdf0e10cSrcweir }
2660cdf0e10cSrcweir }
2661cdf0e10cSrcweir
2662cdf0e10cSrcweir cancelCommandExecution( except, Environment, sal_True );
2663cdf0e10cSrcweir // Unreachable
2664cdf0e10cSrcweir }
2665cdf0e10cSrcweir
2666cdf0e10cSrcweir {
2667cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2668cdf0e10cSrcweir m_xIdentifier
2669cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, aURL );
2670cdf0e10cSrcweir }
2671cdf0e10cSrcweir
2672cdf0e10cSrcweir inserted();
2673cdf0e10cSrcweir
2674cdf0e10cSrcweir {
2675cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2676cdf0e10cSrcweir m_bTransient = sal_False;
2677cdf0e10cSrcweir }
2678cdf0e10cSrcweir }
2679cdf0e10cSrcweir else
2680cdf0e10cSrcweir {
2681cdf0e10cSrcweir if ( !xInputStream.is() )
2682cdf0e10cSrcweir {
2683cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2684cdf0e10cSrcweir uno::makeAny(
2685cdf0e10cSrcweir ucb::MissingInputStreamException(
2686cdf0e10cSrcweir rtl::OUString(),
2687cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ),
2688cdf0e10cSrcweir Environment );
2689cdf0e10cSrcweir // Unreachable
2690cdf0e10cSrcweir }
2691cdf0e10cSrcweir
2692cdf0e10cSrcweir try
2693cdf0e10cSrcweir {
2694cdf0e10cSrcweir xResAccess->PUT( xInputStream, Environment );
2695cdf0e10cSrcweir }
2696cdf0e10cSrcweir catch ( DAVException const & e )
2697cdf0e10cSrcweir {
2698cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_True );
2699cdf0e10cSrcweir // Unreachable
2700cdf0e10cSrcweir }
2701cdf0e10cSrcweir }
2702cdf0e10cSrcweir
2703cdf0e10cSrcweir {
2704cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2705cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
2706cdf0e10cSrcweir }
2707cdf0e10cSrcweir }
2708cdf0e10cSrcweir
2709cdf0e10cSrcweir //=========================================================================
transfer(const ucb::TransferInfo & rArgs,const uno::Reference<ucb::XCommandEnvironment> & Environment)2710cdf0e10cSrcweir void Content::transfer(
2711cdf0e10cSrcweir const ucb::TransferInfo & rArgs,
2712cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment )
2713cdf0e10cSrcweir throw( uno::Exception )
2714cdf0e10cSrcweir {
2715cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xSMgr;
2716cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xIdentifier;
2717cdf0e10cSrcweir uno::Reference< ucb::XContentProvider > xProvider;
2718cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
2719cdf0e10cSrcweir
2720cdf0e10cSrcweir {
2721cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2722cdf0e10cSrcweir
2723cdf0e10cSrcweir xSMgr.set( m_xSMgr );
2724cdf0e10cSrcweir xIdentifier.set( m_xIdentifier );
2725cdf0e10cSrcweir xProvider.set( m_xProvider.get() );
2726cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
2727cdf0e10cSrcweir }
2728cdf0e10cSrcweir
2729cdf0e10cSrcweir rtl::OUString aTargetURI;
2730cdf0e10cSrcweir try
2731cdf0e10cSrcweir {
2732*9646dec5SDamjan Jovanovic CurlUri sourceURI( rArgs.SourceURL );
2733*9646dec5SDamjan Jovanovic CurlUri targetURI( xIdentifier->getContentIdentifier() );
2734cdf0e10cSrcweir aTargetURI = targetURI.GetPathBaseNameUnescaped();
2735cdf0e10cSrcweir
2736cdf0e10cSrcweir // Check source's and target's URL scheme
2737cdf0e10cSrcweir //
2738cdf0e10cSrcweir const rtl::OUString aScheme = sourceURI.GetScheme().toAsciiLowerCase();
2739cdf0e10cSrcweir if ( aScheme.equalsAsciiL(
2740cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) )
2741cdf0e10cSrcweir {
2742cdf0e10cSrcweir sourceURI.SetScheme(
2743cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) );
2744cdf0e10cSrcweir }
2745cdf0e10cSrcweir else if ( aScheme.equalsAsciiL(
2746cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) )
2747cdf0e10cSrcweir {
2748cdf0e10cSrcweir sourceURI.SetScheme(
2749cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) );
2750cdf0e10cSrcweir }
2751cdf0e10cSrcweir else if ( aScheme.equalsAsciiL(
2752cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAVS_URL_SCHEME ) ) )
2753cdf0e10cSrcweir {
2754cdf0e10cSrcweir sourceURI.SetScheme(
2755cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTPS_URL_SCHEME ) );
2756cdf0e10cSrcweir }
2757cdf0e10cSrcweir else
2758cdf0e10cSrcweir {
2759cdf0e10cSrcweir if ( !aScheme.equalsAsciiL(
2760cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( HTTP_URL_SCHEME ) ) &&
2761cdf0e10cSrcweir !aScheme.equalsAsciiL(
2762cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( HTTPS_URL_SCHEME ) ) )
2763cdf0e10cSrcweir {
2764cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2765cdf0e10cSrcweir uno::makeAny(
2766cdf0e10cSrcweir ucb::InteractiveBadTransferURLException(
2767cdf0e10cSrcweir rtl::OUString::createFromAscii(
2768cdf0e10cSrcweir "Unsupported URL scheme!" ),
2769cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ),
2770cdf0e10cSrcweir Environment );
2771cdf0e10cSrcweir // Unreachable
2772cdf0e10cSrcweir }
2773cdf0e10cSrcweir }
2774cdf0e10cSrcweir
2775cdf0e10cSrcweir if ( targetURI.GetScheme().toAsciiLowerCase().equalsAsciiL(
2776cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( WEBDAV_URL_SCHEME ) ) )
2777cdf0e10cSrcweir targetURI.SetScheme(
2778cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) );
2779cdf0e10cSrcweir else if ( targetURI.GetScheme().toAsciiLowerCase().equalsAsciiL(
2780cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( DAV_URL_SCHEME ) ) )
2781cdf0e10cSrcweir targetURI.SetScheme(
2782cdf0e10cSrcweir rtl::OUString::createFromAscii( HTTP_URL_SCHEME ) );
2783cdf0e10cSrcweir
2784cdf0e10cSrcweir // @@@ This implementation of 'transfer' only works
2785cdf0e10cSrcweir // if the source and target are located at same host.
2786cdf0e10cSrcweir // (Neon does not support cross-server copy/move)
2787cdf0e10cSrcweir
2788cdf0e10cSrcweir // Check for same host
2789cdf0e10cSrcweir //
2790cdf0e10cSrcweir if ( sourceURI.GetHost().getLength() &&
2791cdf0e10cSrcweir ( sourceURI.GetHost() != targetURI.GetHost() ) )
2792cdf0e10cSrcweir {
2793cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2794cdf0e10cSrcweir uno::makeAny( ucb::InteractiveBadTransferURLException(
2795cdf0e10cSrcweir rtl::OUString::createFromAscii(
2796cdf0e10cSrcweir "Different hosts!" ),
2797cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ),
2798cdf0e10cSrcweir Environment );
2799cdf0e10cSrcweir // Unreachable
2800cdf0e10cSrcweir }
2801cdf0e10cSrcweir
2802cdf0e10cSrcweir rtl::OUString aTitle = rArgs.NewTitle;
2803cdf0e10cSrcweir
2804cdf0e10cSrcweir if ( !aTitle.getLength() )
2805cdf0e10cSrcweir aTitle = sourceURI.GetPathBaseNameUnescaped();
2806cdf0e10cSrcweir
2807cdf0e10cSrcweir if ( aTitle.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "/" ) ) )
2808cdf0e10cSrcweir {
2809cdf0e10cSrcweir // kso: ???
2810cdf0e10cSrcweir aTitle = rtl::OUString();
2811cdf0e10cSrcweir }
2812cdf0e10cSrcweir
2813cdf0e10cSrcweir targetURI.AppendPath( aTitle );
2814cdf0e10cSrcweir
2815cdf0e10cSrcweir rtl::OUString aTargetURL = xIdentifier->getContentIdentifier();
2816cdf0e10cSrcweir if ( ( aTargetURL.lastIndexOf( '/' ) + 1 )
2817cdf0e10cSrcweir != aTargetURL.getLength() )
2818cdf0e10cSrcweir aTargetURL += rtl::OUString::createFromAscii( "/" );
2819cdf0e10cSrcweir
2820cdf0e10cSrcweir aTargetURL += aTitle;
2821cdf0e10cSrcweir
2822cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xTargetId
2823cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( xSMgr, aTargetURL );
2824cdf0e10cSrcweir
2825cdf0e10cSrcweir DAVResourceAccess aSourceAccess( xSMgr,
2826cdf0e10cSrcweir xResAccess->getSessionFactory(),
2827cdf0e10cSrcweir sourceURI.GetURI() );
2828cdf0e10cSrcweir
2829cdf0e10cSrcweir if ( rArgs.MoveData == sal_True )
2830cdf0e10cSrcweir {
2831cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xId
2832cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( xSMgr, rArgs.SourceURL );
2833cdf0e10cSrcweir
2834cdf0e10cSrcweir // Note: The static cast is okay here, because its sure that
2835cdf0e10cSrcweir // xProvider is always the WebDAVContentProvider.
2836cdf0e10cSrcweir rtl::Reference< Content > xSource
2837cdf0e10cSrcweir = static_cast< Content * >(
2838cdf0e10cSrcweir xProvider->queryContent( xId ).get() );
2839cdf0e10cSrcweir
2840cdf0e10cSrcweir // [RFC 2518] - WebDAV
2841cdf0e10cSrcweir // If a resource exists at the destination and the Overwrite
2842cdf0e10cSrcweir // header is "T" then prior to performing the move the server
2843cdf0e10cSrcweir // MUST perform a DELETE with "Depth: infinity" on the
2844cdf0e10cSrcweir // destination resource. If the Overwrite header is set to
2845cdf0e10cSrcweir // "F" then the operation will fail.
2846cdf0e10cSrcweir
2847cdf0e10cSrcweir aSourceAccess.MOVE( sourceURI.GetPath(),
2848cdf0e10cSrcweir targetURI.GetURI(),
2849cdf0e10cSrcweir rArgs.NameClash
2850cdf0e10cSrcweir == ucb::NameClash::OVERWRITE,
2851cdf0e10cSrcweir Environment );
2852cdf0e10cSrcweir
2853cdf0e10cSrcweir if ( xSource.is() )
2854cdf0e10cSrcweir {
2855cdf0e10cSrcweir // Propagate destruction to listeners.
2856cdf0e10cSrcweir xSource->destroy( sal_True );
2857cdf0e10cSrcweir }
2858cdf0e10cSrcweir
2859cdf0e10cSrcweir // DAV resources store all additional props on server!
2860cdf0e10cSrcweir // // Rename own and all children's Additional Core Properties.
2861cdf0e10cSrcweir // renameAdditionalPropertySet( xId->getContentIdentifier(),
2862cdf0e10cSrcweir // xTargetId->getContentIdentifier(),
2863cdf0e10cSrcweir // sal_True );
2864cdf0e10cSrcweir }
2865cdf0e10cSrcweir else
2866cdf0e10cSrcweir {
2867cdf0e10cSrcweir // [RFC 2518] - WebDAV
2868cdf0e10cSrcweir // If a resource exists at the destination and the Overwrite
2869cdf0e10cSrcweir // header is "T" then prior to performing the copy the server
2870cdf0e10cSrcweir // MUST perform a DELETE with "Depth: infinity" on the
2871cdf0e10cSrcweir // destination resource. If the Overwrite header is set to
2872cdf0e10cSrcweir // "F" then the operation will fail.
2873cdf0e10cSrcweir
2874cdf0e10cSrcweir aSourceAccess.COPY( sourceURI.GetPath(),
2875cdf0e10cSrcweir targetURI.GetURI(),
2876cdf0e10cSrcweir rArgs.NameClash
2877cdf0e10cSrcweir == ucb::NameClash::OVERWRITE,
2878cdf0e10cSrcweir Environment );
2879cdf0e10cSrcweir
2880cdf0e10cSrcweir // DAV resources store all additional props on server!
2881cdf0e10cSrcweir // // Copy own and all children's Additional Core Properties.
2882cdf0e10cSrcweir // copyAdditionalPropertySet( xId->getContentIdentifier(),
2883cdf0e10cSrcweir // xTargetId->getContentIdentifier(),
2884cdf0e10cSrcweir // sal_True );
2885cdf0e10cSrcweir }
2886cdf0e10cSrcweir
2887cdf0e10cSrcweir // Note: The static cast is okay here, because its sure that
2888cdf0e10cSrcweir // xProvider is always the WebDAVContentProvider.
2889cdf0e10cSrcweir rtl::Reference< Content > xTarget
2890cdf0e10cSrcweir = static_cast< Content * >(
2891cdf0e10cSrcweir xProvider->queryContent( xTargetId ).get() );
2892cdf0e10cSrcweir
289386e1cf34SPedro Giffuni // Announce transferred content in its new folder.
2894cdf0e10cSrcweir xTarget->inserted();
2895cdf0e10cSrcweir }
2896cdf0e10cSrcweir catch ( ucb::IllegalIdentifierException const & )
2897cdf0e10cSrcweir {
2898cdf0e10cSrcweir // queryContent
2899cdf0e10cSrcweir }
2900cdf0e10cSrcweir catch ( DAVException const & e )
2901cdf0e10cSrcweir {
2902cdf0e10cSrcweir // [RFC 2518] - WebDAV
2903cdf0e10cSrcweir // 412 (Precondition Failed) - The server was unable to maintain
2904cdf0e10cSrcweir // the liveness of the properties listed in the propertybehavior
2905cdf0e10cSrcweir // XML element or the Overwrite header is "F" and the state of
2906cdf0e10cSrcweir // the destination resource is non-null.
2907cdf0e10cSrcweir
2908cdf0e10cSrcweir if ( e.getStatus() == SC_PRECONDITION_FAILED )
2909cdf0e10cSrcweir {
2910cdf0e10cSrcweir switch ( rArgs.NameClash )
2911cdf0e10cSrcweir {
291259ddfc10SAndre Fischer case 0/*ucb::NameClash::ERROR*/:
2913cdf0e10cSrcweir {
2914cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2915cdf0e10cSrcweir uno::makeAny(
2916cdf0e10cSrcweir ucb::NameClashException(
2917cdf0e10cSrcweir rtl::OUString(),
2918cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
2919cdf0e10cSrcweir task::InteractionClassification_ERROR,
2920cdf0e10cSrcweir aTargetURI ) ),
2921cdf0e10cSrcweir Environment );
2922cdf0e10cSrcweir // Unreachable
2923cdf0e10cSrcweir }
2924cdf0e10cSrcweir
2925cdf0e10cSrcweir case ucb::NameClash::OVERWRITE:
2926cdf0e10cSrcweir break;
2927cdf0e10cSrcweir
2928cdf0e10cSrcweir case ucb::NameClash::KEEP: // deprecated
2929cdf0e10cSrcweir case ucb::NameClash::RENAME:
2930cdf0e10cSrcweir case ucb::NameClash::ASK:
2931cdf0e10cSrcweir default:
2932cdf0e10cSrcweir {
2933cdf0e10cSrcweir ucbhelper::cancelCommandExecution(
2934cdf0e10cSrcweir uno::makeAny(
2935cdf0e10cSrcweir ucb::UnsupportedNameClashException(
2936cdf0e10cSrcweir rtl::OUString(),
2937cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
2938cdf0e10cSrcweir rArgs.NameClash ) ),
2939cdf0e10cSrcweir Environment );
2940cdf0e10cSrcweir // Unreachable
2941cdf0e10cSrcweir }
2942cdf0e10cSrcweir }
2943cdf0e10cSrcweir }
2944cdf0e10cSrcweir
2945cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_True );
2946cdf0e10cSrcweir // Unreachable
2947cdf0e10cSrcweir }
2948cdf0e10cSrcweir
2949cdf0e10cSrcweir {
2950cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2951cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
2952cdf0e10cSrcweir }
2953cdf0e10cSrcweir }
2954cdf0e10cSrcweir
2955cdf0e10cSrcweir //=========================================================================
destroy(sal_Bool bDeletePhysical)2956cdf0e10cSrcweir void Content::destroy( sal_Bool bDeletePhysical )
2957cdf0e10cSrcweir throw( uno::Exception )
2958cdf0e10cSrcweir {
2959cdf0e10cSrcweir // @@@ take care about bDeletePhysical -> trashcan support
2960cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
2961cdf0e10cSrcweir
2962cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this;
2963cdf0e10cSrcweir
2964cdf0e10cSrcweir deleted();
2965cdf0e10cSrcweir
2966cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
2967cdf0e10cSrcweir
2968cdf0e10cSrcweir // Process instanciated children...
2969cdf0e10cSrcweir
297059ddfc10SAndre Fischer ::http_dav_ucp::Content::ContentRefList aChildren;
2971cdf0e10cSrcweir queryChildren( aChildren );
2972cdf0e10cSrcweir
2973cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin();
2974cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end();
2975cdf0e10cSrcweir
2976cdf0e10cSrcweir while ( it != end )
2977cdf0e10cSrcweir {
2978cdf0e10cSrcweir (*it)->destroy( bDeletePhysical );
2979cdf0e10cSrcweir ++it;
2980cdf0e10cSrcweir }
2981cdf0e10cSrcweir }
2982cdf0e10cSrcweir
2983cdf0e10cSrcweir //=========================================================================
supportsExclusiveWriteLock(const uno::Reference<ucb::XCommandEnvironment> & Environment)2984cdf0e10cSrcweir bool Content::supportsExclusiveWriteLock(
2985cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment )
2986cdf0e10cSrcweir {
2987cdf0e10cSrcweir if ( getResourceType( Environment ) == DAV )
2988cdf0e10cSrcweir {
2989cdf0e10cSrcweir if ( m_xCachedProps.get() )
2990cdf0e10cSrcweir {
2991cdf0e10cSrcweir uno::Sequence< ucb::LockEntry > aSupportedLocks;
2992cdf0e10cSrcweir if ( m_xCachedProps->getValue( DAVProperties::SUPPORTEDLOCK )
2993cdf0e10cSrcweir >>= aSupportedLocks )
2994cdf0e10cSrcweir {
2995cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aSupportedLocks.getLength(); ++n )
2996cdf0e10cSrcweir {
2997cdf0e10cSrcweir if ( aSupportedLocks[ n ].Scope
2998cdf0e10cSrcweir == ucb::LockScope_EXCLUSIVE &&
2999cdf0e10cSrcweir aSupportedLocks[ n ].Type
3000cdf0e10cSrcweir == ucb::LockType_WRITE )
3001cdf0e10cSrcweir return true;
3002cdf0e10cSrcweir }
3003cdf0e10cSrcweir }
3004cdf0e10cSrcweir }
3005cdf0e10cSrcweir }
3006cdf0e10cSrcweir return false;
3007cdf0e10cSrcweir }
3008cdf0e10cSrcweir
3009cdf0e10cSrcweir //=========================================================================
lock(const uno::Reference<ucb::XCommandEnvironment> & Environment)3010cdf0e10cSrcweir void Content::lock(
3011cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment )
3012cdf0e10cSrcweir throw( uno::Exception )
3013cdf0e10cSrcweir {
30149c0c1533SAndrea Pescetti // i126305 TODO: add a check to see if this is really a DAV resource ?
30159c0c1533SAndrea Pescetti // currently if the lock is not supported
30169c0c1533SAndrea Pescetti // we got an error from the server that should be checked by the client (framework)
30179c0c1533SAndrea Pescetti rtl::OUString aURL;
30189c0c1533SAndrea Pescetti if ( m_bTransient )
30199c0c1533SAndrea Pescetti {
30209c0c1533SAndrea Pescetti aURL = getParentURL();
30219c0c1533SAndrea Pescetti if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) )
30229c0c1533SAndrea Pescetti aURL += rtl::OUString::createFromAscii( "/" );
30239c0c1533SAndrea Pescetti
30249c0c1533SAndrea Pescetti aURL += m_aEscapedTitle;
30259c0c1533SAndrea Pescetti }
30269c0c1533SAndrea Pescetti else
30279c0c1533SAndrea Pescetti {
30289c0c1533SAndrea Pescetti aURL = m_xIdentifier->getContentIdentifier();
30299c0c1533SAndrea Pescetti }
30309c0c1533SAndrea Pescetti
3031cdf0e10cSrcweir try
3032cdf0e10cSrcweir {
3033cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
3034cdf0e10cSrcweir {
3035cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
3036cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
3037cdf0e10cSrcweir }
3038cdf0e10cSrcweir
30399c0c1533SAndrea Pescetti // TODO i126305 to discuss:
30409c0c1533SAndrea Pescetti // the owner string is the string that will be returned when the lock will be
30419c0c1533SAndrea Pescetti // interrogated, via lockdiscovery.
30429c0c1533SAndrea Pescetti // It should tell a user who is holding the document lock.
30439c0c1533SAndrea Pescetti // The string currently set as owner is the one most useful now, telling what application locked the resource.
30449c0c1533SAndrea Pescetti // May be it would be better put here something better ?
30459c0c1533SAndrea Pescetti // Some string be added to office config? Or name of the user there? Or a document property user selectable?
30469c0c1533SAndrea Pescetti // in case of adding it in config, the lock command should be added a string for the owner, and this
30479c0c1533SAndrea Pescetti // will be in turn filled in by the framework (e.g. the ucb client).
30489c0c1533SAndrea Pescetti // Of course in case of a configuration item, the string should be checked against internationalization
30499c0c1533SAndrea Pescetti // and how to manage it in webdav protocol, this was not checked while solving i126305.
3050cdf0e10cSrcweir uno::Any aOwnerAny;
3051cdf0e10cSrcweir aOwnerAny
30529c0c1533SAndrea Pescetti <<= rtl::OUString::createFromAscii( "Apache OpenOffice - https://www.openoffice.org" );
30539c0c1533SAndrea Pescetti
30549c0c1533SAndrea Pescetti // TODO i126305 to discuss:
30559c0c1533SAndrea Pescetti // on some webdav server, the 180 time formerly used appears to be too long,
30569c0c1533SAndrea Pescetti // in this case, in response to a lock refresh operation we receive an error
30579c0c1533SAndrea Pescetti // as 'Connection reset by peer', meaning the session was timed out by the other end.
30589c0c1533SAndrea Pescetti // For now drop the defaul time to 120 seconds, seems better.
30599c0c1533SAndrea Pescetti // In the future, another way of keeping the connection alive should be devised.
3060cdf0e10cSrcweir ucb::Lock aLock(
3061cdf0e10cSrcweir ucb::LockScope_EXCLUSIVE,
3062cdf0e10cSrcweir ucb::LockType_WRITE,
3063cdf0e10cSrcweir ucb::LockDepth_ZERO,
3064cdf0e10cSrcweir aOwnerAny,
30659c0c1533SAndrea Pescetti 120, // lock timeout in secs
3066cdf0e10cSrcweir //-1, // infinite lock
3067cdf0e10cSrcweir uno::Sequence< ::rtl::OUString >() );
3068cdf0e10cSrcweir
3069cdf0e10cSrcweir xResAccess->LOCK( aLock, Environment );
3070cdf0e10cSrcweir
3071cdf0e10cSrcweir {
3072cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
3073cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
3074cdf0e10cSrcweir }
3075cdf0e10cSrcweir }
3076cdf0e10cSrcweir catch ( DAVException const & e )
3077cdf0e10cSrcweir {
30789c0c1533SAndrea Pescetti switch(e.getStatus())
30799c0c1533SAndrea Pescetti {
30809c0c1533SAndrea Pescetti case SC_LOCKED:
30819c0c1533SAndrea Pescetti {
30829c0c1533SAndrea Pescetti rtl::OUString aOwner( getLockOwner( Environment ) );
30839c0c1533SAndrea Pescetti
30849c0c1533SAndrea Pescetti throw(ucb::InteractiveLockingLockedException(
30859c0c1533SAndrea Pescetti rtl::OUString::createFromAscii( "Locked!" ),
30869c0c1533SAndrea Pescetti static_cast< cppu::OWeakObject * >( this ),
30879c0c1533SAndrea Pescetti task::InteractionClassification_ERROR,
30889c0c1533SAndrea Pescetti aURL,
30899c0c1533SAndrea Pescetti e.getExtendedError(),
30909c0c1533SAndrea Pescetti sal_False,
30919c0c1533SAndrea Pescetti aOwner ));
30929c0c1533SAndrea Pescetti }
30939c0c1533SAndrea Pescetti break;
3094ff309014SAndrea Pescetti case SC_FORBIDDEN:
3095ff309014SAndrea Pescetti case SC_NOT_IMPLEMENTED:
30969c0c1533SAndrea Pescetti case SC_METHOD_NOT_ALLOWED:
30979c0c1533SAndrea Pescetti // this it's not always received, but the RFC4918 (which supersed RFC2518)
30989c0c1533SAndrea Pescetti // tells about this in:
30999c0c1533SAndrea Pescetti // http://tools.ietf.org/html/rfc4918#appendix-D.1
31009c0c1533SAndrea Pescetti // throw exception, will be interpreted by the lock requester (framework)
31019c0c1533SAndrea Pescetti // it is actually a info, not an error
3102ff309014SAndrea Pescetti return;
31039c0c1533SAndrea Pescetti break;
31049c0c1533SAndrea Pescetti //i126305 TODO
31059c0c1533SAndrea Pescetti //see http://tools.ietf.org/html/rfc4918#section-9.10.6
31069c0c1533SAndrea Pescetti //not sure how to handle them, for the time being a dialog box is shown,
31079c0c1533SAndrea Pescetti //the client (framework) should manage it
31089c0c1533SAndrea Pescetti case SC_CONFLICT:
31099c0c1533SAndrea Pescetti case SC_PRECONDITION_FAILED:
31109c0c1533SAndrea Pescetti default:
31119c0c1533SAndrea Pescetti //fallthrou
31129c0c1533SAndrea Pescetti ;
31139c0c1533SAndrea Pescetti }
3114cdf0e10cSrcweir cancelCommandExecution( e, Environment, sal_False );
3115cdf0e10cSrcweir // Unreachable
3116cdf0e10cSrcweir }
3117cdf0e10cSrcweir }
3118cdf0e10cSrcweir
3119cdf0e10cSrcweir //=========================================================================
unlock(const uno::Reference<ucb::XCommandEnvironment> & Environment)3120cdf0e10cSrcweir void Content::unlock(
3121cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& Environment )
3122cdf0e10cSrcweir throw( uno::Exception )
3123cdf0e10cSrcweir {
3124cdf0e10cSrcweir try
3125cdf0e10cSrcweir {
3126cdf0e10cSrcweir std::auto_ptr< DAVResourceAccess > xResAccess;
3127cdf0e10cSrcweir {
3128cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
3129cdf0e10cSrcweir xResAccess.reset( new DAVResourceAccess( *m_xResAccess.get() ) );
3130cdf0e10cSrcweir }
3131cdf0e10cSrcweir
3132cdf0e10cSrcweir xResAccess->UNLOCK( Environment );
3133cdf0e10cSrcweir
3134cdf0e10cSrcweir {
3135cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
3136cdf0e10cSrcweir m_xResAccess.reset( new DAVResourceAccess( *xResAccess.get() ) );
3137cdf0e10cSrcweir }
3138cdf0e10cSrcweir }
3139cdf0e10cSrcweir catch ( DAVException const & e )
3140cdf0e10cSrcweir {
31419c0c1533SAndrea Pescetti //i126305 TODO need to rise an exception of the right type ?
31429c0c1533SAndrea Pescetti //meaning that the lock can not be released, since there is no such
31439c0c1533SAndrea Pescetti //exception we use ucb::InteractiveNetworkReadException
31449c0c1533SAndrea Pescetti throw ucb::InteractiveNetworkReadException( e.getData(),
31459c0c1533SAndrea Pescetti static_cast< cppu::OWeakObject * >( this ),
31469c0c1533SAndrea Pescetti task::InteractionClassification_INFO,
31479c0c1533SAndrea Pescetti e.getData() );//perhaps a more better should be used ?
3148cdf0e10cSrcweir // Unreachable
31499c0c1533SAndrea Pescetti cancelCommandExecution( e, Environment, sal_False );
3150cdf0e10cSrcweir }
3151cdf0e10cSrcweir }
3152cdf0e10cSrcweir
3153cdf0e10cSrcweir //=========================================================================
exchangeIdentity(const uno::Reference<ucb::XContentIdentifier> & xNewId)3154cdf0e10cSrcweir sal_Bool Content::exchangeIdentity(
3155cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& xNewId )
3156cdf0e10cSrcweir {
3157cdf0e10cSrcweir if ( !xNewId.is() )
3158cdf0e10cSrcweir return sal_False;
3159cdf0e10cSrcweir
3160cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
3161cdf0e10cSrcweir
3162cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this;
3163cdf0e10cSrcweir
3164cdf0e10cSrcweir // Already persistent?
3165cdf0e10cSrcweir if ( m_bTransient )
3166cdf0e10cSrcweir {
3167cdf0e10cSrcweir OSL_ENSURE( sal_False, "Content::exchangeIdentity - Not persistent!" );
3168cdf0e10cSrcweir return sal_False;
3169cdf0e10cSrcweir }
3170cdf0e10cSrcweir
3171cdf0e10cSrcweir // Exchange own identitity.
3172cdf0e10cSrcweir
3173cdf0e10cSrcweir // Fail, if a content with given id already exists.
3174cdf0e10cSrcweir // if ( !hasData( xNewId ) )
3175cdf0e10cSrcweir {
3176cdf0e10cSrcweir rtl::OUString aOldURL = m_xIdentifier->getContentIdentifier();
3177cdf0e10cSrcweir
3178cdf0e10cSrcweir aGuard.clear();
3179cdf0e10cSrcweir if ( exchange( xNewId ) )
3180cdf0e10cSrcweir {
3181cdf0e10cSrcweir // Process instanciated children...
3182cdf0e10cSrcweir
3183cdf0e10cSrcweir ContentRefList aChildren;
3184cdf0e10cSrcweir queryChildren( aChildren );
3185cdf0e10cSrcweir
3186cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin();
3187cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end();
3188cdf0e10cSrcweir
3189cdf0e10cSrcweir while ( it != end )
3190cdf0e10cSrcweir {
3191cdf0e10cSrcweir ContentRef xChild = (*it);
3192cdf0e10cSrcweir
3193cdf0e10cSrcweir // Create new content identifier for the child...
3194cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier >
3195cdf0e10cSrcweir xOldChildId = xChild->getIdentifier();
3196cdf0e10cSrcweir rtl::OUString aOldChildURL
3197cdf0e10cSrcweir = xOldChildId->getContentIdentifier();
3198cdf0e10cSrcweir rtl::OUString aNewChildURL
3199cdf0e10cSrcweir = aOldChildURL.replaceAt(
3200cdf0e10cSrcweir 0,
3201cdf0e10cSrcweir aOldURL.getLength(),
3202cdf0e10cSrcweir xNewId->getContentIdentifier() );
3203cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xNewChildId
3204cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier(
3205cdf0e10cSrcweir m_xSMgr, aNewChildURL );
3206cdf0e10cSrcweir
3207cdf0e10cSrcweir if ( !xChild->exchangeIdentity( xNewChildId ) )
3208cdf0e10cSrcweir return sal_False;
3209cdf0e10cSrcweir
3210cdf0e10cSrcweir ++it;
3211cdf0e10cSrcweir }
3212cdf0e10cSrcweir return sal_True;
3213cdf0e10cSrcweir }
3214cdf0e10cSrcweir }
3215cdf0e10cSrcweir
3216cdf0e10cSrcweir OSL_ENSURE( sal_False,
3217cdf0e10cSrcweir "Content::exchangeIdentity - "
3218cdf0e10cSrcweir "Panic! Cannot exchange identity!" );
3219cdf0e10cSrcweir return sal_False;
3220cdf0e10cSrcweir }
3221cdf0e10cSrcweir
3222cdf0e10cSrcweir //=========================================================================
isFolder(const uno::Reference<ucb::XCommandEnvironment> & xEnv)3223cdf0e10cSrcweir sal_Bool Content::isFolder(
3224cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
3225cdf0e10cSrcweir throw( uno::Exception )
3226cdf0e10cSrcweir {
3227cdf0e10cSrcweir {
3228cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
3229cdf0e10cSrcweir
3230cdf0e10cSrcweir if ( m_bTransient )
3231cdf0e10cSrcweir return m_bCollection;
3232cdf0e10cSrcweir }
3233cdf0e10cSrcweir
3234cdf0e10cSrcweir uno::Sequence< beans::Property > aProperties( 1 );
3235cdf0e10cSrcweir aProperties[ 0 ].Name = rtl::OUString::createFromAscii( "IsFolder" );
3236cdf0e10cSrcweir aProperties[ 0 ].Handle = -1;
3237cdf0e10cSrcweir uno::Reference< sdbc::XRow > xRow( getPropertyValues( aProperties, xEnv ) );
3238cdf0e10cSrcweir if ( xRow.is() )
3239cdf0e10cSrcweir {
3240cdf0e10cSrcweir try
3241cdf0e10cSrcweir {
3242cdf0e10cSrcweir return xRow->getBoolean( 1 );
3243cdf0e10cSrcweir }
3244cdf0e10cSrcweir catch ( sdbc::SQLException const & )
3245cdf0e10cSrcweir {
3246cdf0e10cSrcweir }
3247cdf0e10cSrcweir }
3248cdf0e10cSrcweir
3249cdf0e10cSrcweir return sal_False;
3250cdf0e10cSrcweir }
3251cdf0e10cSrcweir
3252cdf0e10cSrcweir //=========================================================================
MapDAVException(const DAVException & e,sal_Bool bWrite)3253cdf0e10cSrcweir uno::Any Content::MapDAVException( const DAVException & e, sal_Bool bWrite )
3254cdf0e10cSrcweir {
3255cdf0e10cSrcweir // Map DAVException...
3256cdf0e10cSrcweir uno::Any aException;
3257cdf0e10cSrcweir
3258cdf0e10cSrcweir rtl::OUString aURL;
3259cdf0e10cSrcweir if ( m_bTransient )
3260cdf0e10cSrcweir {
3261cdf0e10cSrcweir aURL = getParentURL();
3262cdf0e10cSrcweir if ( aURL.lastIndexOf( '/' ) != ( aURL.getLength() - 1 ) )
3263cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" );
3264cdf0e10cSrcweir
3265cdf0e10cSrcweir aURL += m_aEscapedTitle;
3266cdf0e10cSrcweir }
3267cdf0e10cSrcweir else
3268cdf0e10cSrcweir {
3269cdf0e10cSrcweir aURL = m_xIdentifier->getContentIdentifier();
3270cdf0e10cSrcweir }
3271cdf0e10cSrcweir
3272cdf0e10cSrcweir switch ( e.getStatus() )
3273cdf0e10cSrcweir {
3274cdf0e10cSrcweir case SC_NOT_FOUND:
3275cdf0e10cSrcweir {
3276cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 );
3277cdf0e10cSrcweir aArgs[ 0 ] <<= beans::PropertyValue(
3278cdf0e10cSrcweir rtl::OUString::createFromAscii("Uri"), -1,
3279cdf0e10cSrcweir uno::makeAny(aURL),
3280cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE);
3281cdf0e10cSrcweir
3282cdf0e10cSrcweir aException <<=
3283cdf0e10cSrcweir ucb::InteractiveAugmentedIOException(
3284cdf0e10cSrcweir rtl::OUString::createFromAscii( "Not found!" ),
3285cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3286cdf0e10cSrcweir task::InteractionClassification_ERROR,
3287cdf0e10cSrcweir ucb::IOErrorCode_NOT_EXISTING,
3288cdf0e10cSrcweir aArgs );
3289cdf0e10cSrcweir return aException;
3290cdf0e10cSrcweir }
3291cdf0e10cSrcweir default:
3292cdf0e10cSrcweir break;
3293cdf0e10cSrcweir }
3294cdf0e10cSrcweir
3295cdf0e10cSrcweir switch ( e.getError() )
3296cdf0e10cSrcweir {
3297cdf0e10cSrcweir case DAVException::DAV_HTTP_ERROR:
3298cdf0e10cSrcweir {
3299cdf0e10cSrcweir if ( bWrite )
3300cdf0e10cSrcweir aException <<=
3301cdf0e10cSrcweir ucb::InteractiveNetworkWriteException(
3302cdf0e10cSrcweir e.getData(),
3303cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3304cdf0e10cSrcweir task::InteractionClassification_ERROR,
3305cdf0e10cSrcweir e.getData() );
3306cdf0e10cSrcweir else
3307cdf0e10cSrcweir aException <<=
3308cdf0e10cSrcweir ucb::InteractiveNetworkReadException(
3309cdf0e10cSrcweir e.getData(),
3310cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3311cdf0e10cSrcweir task::InteractionClassification_ERROR,
3312cdf0e10cSrcweir e.getData() );
3313cdf0e10cSrcweir break;
3314cdf0e10cSrcweir }
3315cdf0e10cSrcweir
3316cdf0e10cSrcweir case DAVException::DAV_HTTP_LOOKUP:
3317cdf0e10cSrcweir aException <<=
3318cdf0e10cSrcweir ucb::InteractiveNetworkResolveNameException(
3319cdf0e10cSrcweir rtl::OUString(),
3320cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3321cdf0e10cSrcweir task::InteractionClassification_ERROR,
3322cdf0e10cSrcweir e.getData() );
3323cdf0e10cSrcweir break;
3324cdf0e10cSrcweir
3325cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3326cdf0e10cSrcweir // case DAVException::DAV_HTTP_AUTH:
3327cdf0e10cSrcweir // break;
3328cdf0e10cSrcweir
3329cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3330cdf0e10cSrcweir // case DAVException::DAV_HTTP_AUTHPROXY:
3331cdf0e10cSrcweir // break;
3332cdf0e10cSrcweir
3333cdf0e10cSrcweir case DAVException::DAV_HTTP_CONNECT:
3334cdf0e10cSrcweir aException <<=
3335cdf0e10cSrcweir ucb::InteractiveNetworkConnectException(
3336cdf0e10cSrcweir rtl::OUString(),
3337cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3338cdf0e10cSrcweir task::InteractionClassification_ERROR,
3339cdf0e10cSrcweir e.getData() );
3340cdf0e10cSrcweir break;
3341cdf0e10cSrcweir
3342cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3343cdf0e10cSrcweir // case DAVException::DAV_HTTP_TIMEOUT:
3344cdf0e10cSrcweir // break;
3345cdf0e10cSrcweir
3346cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3347cdf0e10cSrcweir // case DAVException::DAV_HTTP_REDIRECT:
3348cdf0e10cSrcweir // break;
3349cdf0e10cSrcweir
3350cdf0e10cSrcweir // @@@ No matching InteractiveNetwork*Exception
3351cdf0e10cSrcweir // case DAVException::DAV_SESSION_CREATE:
3352cdf0e10cSrcweir // break;
3353cdf0e10cSrcweir
3354cdf0e10cSrcweir case DAVException::DAV_INVALID_ARG:
3355cdf0e10cSrcweir aException <<=
3356cdf0e10cSrcweir lang::IllegalArgumentException(
3357cdf0e10cSrcweir rtl::OUString(),
3358cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3359cdf0e10cSrcweir -1 );
3360cdf0e10cSrcweir break;
3361cdf0e10cSrcweir
3362cdf0e10cSrcweir case DAVException::DAV_LOCKED:
3363cdf0e10cSrcweir #if 1
3364cdf0e10cSrcweir aException <<=
3365cdf0e10cSrcweir ucb::InteractiveLockingLockedException(
3366cdf0e10cSrcweir rtl::OUString::createFromAscii( "Locked!" ),
3367cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3368cdf0e10cSrcweir task::InteractionClassification_ERROR,
3369cdf0e10cSrcweir aURL,
33709c0c1533SAndrea Pescetti e.getExtendedError(),
33719c0c1533SAndrea Pescetti sal_False, // not SelfOwned
33729c0c1533SAndrea Pescetti rtl::OUString() );
3373cdf0e10cSrcweir #else
3374cdf0e10cSrcweir {
3375cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 );
3376cdf0e10cSrcweir aArgs[ 0 ] <<= beans::PropertyValue(
3377cdf0e10cSrcweir rtl::OUString::createFromAscii("Uri"), -1,
3378cdf0e10cSrcweir uno::makeAny(aURL),
3379cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE);
3380cdf0e10cSrcweir
3381cdf0e10cSrcweir aException <<=
3382cdf0e10cSrcweir ucb::InteractiveAugmentedIOException(
3383cdf0e10cSrcweir rtl::OUString::createFromAscii( "Locked!" ),
3384cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3385cdf0e10cSrcweir task::InteractionClassification_ERROR,
3386cdf0e10cSrcweir ucb::IOErrorCode_LOCKING_VIOLATION,
3387cdf0e10cSrcweir aArgs );
3388cdf0e10cSrcweir }
3389cdf0e10cSrcweir #endif
3390cdf0e10cSrcweir break;
3391cdf0e10cSrcweir
3392cdf0e10cSrcweir case DAVException::DAV_LOCKED_SELF:
3393cdf0e10cSrcweir aException <<=
3394cdf0e10cSrcweir ucb::InteractiveLockingLockedException(
3395cdf0e10cSrcweir rtl::OUString::createFromAscii( "Locked (self)!" ),
3396cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3397cdf0e10cSrcweir task::InteractionClassification_ERROR,
3398cdf0e10cSrcweir aURL,
33999c0c1533SAndrea Pescetti e.getExtendedError(),
34009c0c1533SAndrea Pescetti sal_True, // SelfOwned
34019c0c1533SAndrea Pescetti e.getOwner() );
3402cdf0e10cSrcweir break;
3403cdf0e10cSrcweir
3404cdf0e10cSrcweir case DAVException::DAV_NOT_LOCKED:
3405cdf0e10cSrcweir aException <<=
3406cdf0e10cSrcweir ucb::InteractiveLockingNotLockedException(
3407cdf0e10cSrcweir rtl::OUString::createFromAscii( "Not locked!" ),
3408cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3409cdf0e10cSrcweir task::InteractionClassification_ERROR,
34109c0c1533SAndrea Pescetti aURL,
34119c0c1533SAndrea Pescetti rtl::OUString() );//no extended info here
3412cdf0e10cSrcweir break;
3413cdf0e10cSrcweir
3414cdf0e10cSrcweir case DAVException::DAV_LOCK_EXPIRED:
3415cdf0e10cSrcweir aException <<=
3416cdf0e10cSrcweir ucb::InteractiveLockingLockExpiredException(
3417cdf0e10cSrcweir rtl::OUString::createFromAscii( "Lock expired!" ),
3418cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3419cdf0e10cSrcweir task::InteractionClassification_ERROR,
34209c0c1533SAndrea Pescetti aURL,
34219c0c1533SAndrea Pescetti rtl::OUString() );//no extended info here
3422cdf0e10cSrcweir break;
3423cdf0e10cSrcweir
3424cdf0e10cSrcweir default:
34259c0c1533SAndrea Pescetti rtl::OUStringBuffer buf( 512 );
34269c0c1533SAndrea Pescetti buf.appendAscii( BOOST_CURRENT_FUNCTION );
34279c0c1533SAndrea Pescetti buf.appendAscii( ":" );
34289c0c1533SAndrea Pescetti buf.append( (sal_Int32) __LINE__ );
34299c0c1533SAndrea Pescetti buf.appendAscii( " - Unknown DAV error: " );
34309c0c1533SAndrea Pescetti buf.append( (sal_Int32) e.getError() );
3431cdf0e10cSrcweir aException <<=
3432cdf0e10cSrcweir ucb::InteractiveNetworkGeneralException(
34339c0c1533SAndrea Pescetti rtl::OUString(buf.makeStringAndClear()),
3434cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ),
3435cdf0e10cSrcweir task::InteractionClassification_ERROR );
3436cdf0e10cSrcweir break;
3437cdf0e10cSrcweir }
3438cdf0e10cSrcweir
3439cdf0e10cSrcweir return aException;
3440cdf0e10cSrcweir }
3441cdf0e10cSrcweir
3442fc7f71c8SHerbert Dürr // #i124421# force the availability of type_info symbols for exceptions
3443fc7f71c8SHerbert Dürr // that used to be passed around in uno::Any variables and thrown later
ucb_dummyThrower(int i)3444fc7f71c8SHerbert Dürr void ucb_dummyThrower( int i) {
3445fc7f71c8SHerbert Dürr switch( i) {
3446fc7f71c8SHerbert Dürr case 10: throw ucb::InteractiveNetworkGeneralException();
3447fc7f71c8SHerbert Dürr case 11: throw ucb::InteractiveAugmentedIOException();
3448fc7f71c8SHerbert Dürr case 12: throw ucb::InteractiveNetworkGeneralException();
3449fc7f71c8SHerbert Dürr case 13: throw ucb::InteractiveNetworkWriteException();
3450fc7f71c8SHerbert Dürr case 14: throw ucb::InteractiveNetworkReadException();
3451fc7f71c8SHerbert Dürr case 15: throw ucb::InteractiveNetworkConnectException();
3452fc7f71c8SHerbert Dürr case 16: throw ucb::InteractiveLockingLockedException();
3453fc7f71c8SHerbert Dürr case 17: throw ucb::InteractiveLockingNotLockedException();
3454fc7f71c8SHerbert Dürr case 18: throw ucb::InteractiveNetworkGeneralException();
3455fc7f71c8SHerbert Dürr case 19: throw ucb::InteractiveLockingLockExpiredException();
3456fc7f71c8SHerbert Dürr }
3457fc7f71c8SHerbert Dürr }
3458fc7f71c8SHerbert Dürr
3459cdf0e10cSrcweir //=========================================================================
3460cdf0e10cSrcweir // static
shouldAccessNetworkAfterException(const DAVException & e)3461cdf0e10cSrcweir bool Content::shouldAccessNetworkAfterException( const DAVException & e )
3462cdf0e10cSrcweir {
3463cdf0e10cSrcweir if ( ( e.getStatus() == SC_NOT_FOUND ) ||
3464cdf0e10cSrcweir ( e.getError() == DAVException::DAV_HTTP_LOOKUP ) ||
3465cdf0e10cSrcweir ( e.getError() == DAVException::DAV_HTTP_CONNECT ) ||
3466cdf0e10cSrcweir ( e.getError() == DAVException::DAV_HTTP_AUTH ) ||
3467cdf0e10cSrcweir ( e.getError() == DAVException::DAV_HTTP_AUTHPROXY ) )
3468cdf0e10cSrcweir return false;
3469cdf0e10cSrcweir
3470cdf0e10cSrcweir return true;
3471cdf0e10cSrcweir }
3472cdf0e10cSrcweir
3473cdf0e10cSrcweir //=========================================================================
cancelCommandExecution(const DAVException & e,const uno::Reference<ucb::XCommandEnvironment> & xEnv,sal_Bool bWrite)3474cdf0e10cSrcweir void Content::cancelCommandExecution(
3475cdf0e10cSrcweir const DAVException & e,
3476cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv,
3477cdf0e10cSrcweir sal_Bool bWrite /* = sal_False */ )
3478cdf0e10cSrcweir throw ( uno::Exception )
3479cdf0e10cSrcweir {
3480cdf0e10cSrcweir ucbhelper::cancelCommandExecution( MapDAVException( e, bWrite ), xEnv );
3481cdf0e10cSrcweir // Unreachable
3482cdf0e10cSrcweir }
3483cdf0e10cSrcweir
3484cdf0e10cSrcweir //=========================================================================
3485cdf0e10cSrcweir const rtl::OUString
getBaseURI(const std::auto_ptr<DAVResourceAccess> & rResAccess)3486cdf0e10cSrcweir Content::getBaseURI( const std::auto_ptr< DAVResourceAccess > & rResAccess )
3487cdf0e10cSrcweir {
3488cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
3489cdf0e10cSrcweir
3490cdf0e10cSrcweir // First, try to obtain value of response header "Content-Location".
3491cdf0e10cSrcweir if ( m_xCachedProps.get() )
3492cdf0e10cSrcweir {
3493cdf0e10cSrcweir rtl::OUString aLocation;
3494cdf0e10cSrcweir m_xCachedProps->getValue( rtl::OUString(
3495cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
3496cdf0e10cSrcweir "Content-Location" ) ) ) >>= aLocation;
3497cdf0e10cSrcweir if ( aLocation.getLength() )
3498cdf0e10cSrcweir {
3499cdf0e10cSrcweir try
3500cdf0e10cSrcweir {
3501cdf0e10cSrcweir // Do not use m_xIdentifier->getContentIdentifier() because it
3502cdf0e10cSrcweir // for example does not reflect redirects applied to requests
3503cdf0e10cSrcweir // done using the original URI but m_xResAccess' URI does.
3504cdf0e10cSrcweir return rtl::Uri::convertRelToAbs( rResAccess->getURL(),
3505cdf0e10cSrcweir aLocation );
3506cdf0e10cSrcweir }
3507cdf0e10cSrcweir catch ( rtl::MalformedUriException const & )
3508cdf0e10cSrcweir {
3509cdf0e10cSrcweir }
3510cdf0e10cSrcweir }
3511cdf0e10cSrcweir }
3512cdf0e10cSrcweir
3513cdf0e10cSrcweir return rtl::OUString( rResAccess->getURL() );
3514cdf0e10cSrcweir }
3515cdf0e10cSrcweir
3516cdf0e10cSrcweir //=========================================================================
getResourceType(const uno::Reference<ucb::XCommandEnvironment> & xEnv,const std::auto_ptr<DAVResourceAccess> & rResAccess)3517cdf0e10cSrcweir const Content::ResourceType & Content::getResourceType(
3518cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv,
3519cdf0e10cSrcweir const std::auto_ptr< DAVResourceAccess > & rResAccess )
3520cdf0e10cSrcweir throw ( uno::Exception )
3521cdf0e10cSrcweir {
3522cdf0e10cSrcweir if ( m_eResourceType == UNKNOWN )
3523cdf0e10cSrcweir {
3524cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex );
3525cdf0e10cSrcweir
3526cdf0e10cSrcweir ResourceType eResourceType;
3527cdf0e10cSrcweir eResourceType = m_eResourceType;
3528cdf0e10cSrcweir
3529cdf0e10cSrcweir const rtl::OUString & rURL = rResAccess->getURL();
3530cdf0e10cSrcweir const rtl::OUString aScheme(
3531cdf0e10cSrcweir rURL.copy( 0, rURL.indexOf( ':' ) ).toAsciiLowerCase() );
3532cdf0e10cSrcweir
353359ddfc10SAndre Fischer try
3534cdf0e10cSrcweir {
353559ddfc10SAndre Fischer // Try to fetch some frequently used property value, e.g. those
353659ddfc10SAndre Fischer // used when loading documents... along with identifying whether
353759ddfc10SAndre Fischer // this is a DAV resource.
353859ddfc10SAndre Fischer std::vector< DAVResource > resources;
353959ddfc10SAndre Fischer std::vector< rtl::OUString > aPropNames;
35409c0c1533SAndrea Pescetti uno::Sequence< beans::Property > aProperties( 6 );
354159ddfc10SAndre Fischer aProperties[ 0 ].Name
354259ddfc10SAndre Fischer = rtl::OUString::createFromAscii( "IsFolder" );
354359ddfc10SAndre Fischer aProperties[ 1 ].Name
354459ddfc10SAndre Fischer = rtl::OUString::createFromAscii( "IsDocument" );
354559ddfc10SAndre Fischer aProperties[ 2 ].Name
354659ddfc10SAndre Fischer = rtl::OUString::createFromAscii( "IsReadOnly" );
354759ddfc10SAndre Fischer aProperties[ 3 ].Name
354859ddfc10SAndre Fischer = rtl::OUString::createFromAscii( "MediaType" );
354959ddfc10SAndre Fischer aProperties[ 4 ].Name
355059ddfc10SAndre Fischer = DAVProperties::SUPPORTEDLOCK;
35519c0c1533SAndrea Pescetti //we will need this to check for existing locks
35529c0c1533SAndrea Pescetti aProperties[ 5 ].Name
35539c0c1533SAndrea Pescetti = DAVProperties::LOCKDISCOVERY;
355459ddfc10SAndre Fischer
355559ddfc10SAndre Fischer ContentProperties::UCBNamesToDAVNames(
355659ddfc10SAndre Fischer aProperties, aPropNames );
355759ddfc10SAndre Fischer
355859ddfc10SAndre Fischer rResAccess->PROPFIND(
355959ddfc10SAndre Fischer DAVZERO, aPropNames, resources, xEnv );
356059ddfc10SAndre Fischer
356159ddfc10SAndre Fischer // TODO - is this really only one?
35629c0c1533SAndrea Pescetti // only one resource is received, see at:
35639c0c1533SAndrea Pescetti // WebDAVResponseParser::endElement()
35649c0c1533SAndrea Pescetti // case WebDAVName_response
35659c0c1533SAndrea Pescetti //in file: ucb/source/ucp/webdav/webdavresponseparser.cxx:
356659ddfc10SAndre Fischer if ( resources.size() == 1 )
356759ddfc10SAndre Fischer {
35689c0c1533SAndrea Pescetti // there is a single resource
356959ddfc10SAndre Fischer m_xCachedProps.reset(
357059ddfc10SAndre Fischer new CachableContentProperties( resources[ 0 ] ) );
357159ddfc10SAndre Fischer m_xCachedProps->containsAllNames(
357259ddfc10SAndre Fischer aProperties, m_aFailedPropNames );
357359ddfc10SAndre Fischer }
357459ddfc10SAndre Fischer
357559ddfc10SAndre Fischer eResourceType = DAV;
3576cdf0e10cSrcweir }
357759ddfc10SAndre Fischer catch ( DAVException const & e )
3578cdf0e10cSrcweir {
357959ddfc10SAndre Fischer rResAccess->resetUri();
3580ff309014SAndrea Pescetti switch( e.getStatus() )
3581cdf0e10cSrcweir {
3582ff309014SAndrea Pescetti // returned errors are part of base http 1.1 RFCs:
3583ff309014SAndrea Pescetti case SC_FORBIDDEN: // https://tools.ietf.org/html/rfc7231#section-6.5.3
3584ff309014SAndrea Pescetti case SC_NOT_IMPLEMENTED: // http://tools.ietf.org/html/rfc7231#section-6.6.2
3585ff309014SAndrea Pescetti case SC_METHOD_NOT_ALLOWED: // http://tools.ietf.org/html/rfc7231#section-6.5.5
358659ddfc10SAndre Fischer // Status SC_METHOD_NOT_ALLOWED is a safe indicator that the
358759ddfc10SAndre Fischer // resource is NON_DAV
358859ddfc10SAndre Fischer eResourceType = NON_DAV;
3589ff309014SAndrea Pescetti break;
3590ff309014SAndrea Pescetti default:
3591ff309014SAndrea Pescetti ;
3592cdf0e10cSrcweir }
3593fb7f54d2SOliver-Rainer Wittmann // cancel command execution is case that no user authentication data has been provided.
3594fb7f54d2SOliver-Rainer Wittmann if ( e.getError() == DAVException::DAV_HTTP_NOAUTH )
3595fb7f54d2SOliver-Rainer Wittmann {
3596fb7f54d2SOliver-Rainer Wittmann cancelCommandExecution( e, uno::Reference< ucb::XCommandEnvironment >() );
3597fb7f54d2SOliver-Rainer Wittmann }
3598cdf0e10cSrcweir }
3599cdf0e10cSrcweir m_eResourceType = eResourceType;
3600cdf0e10cSrcweir }
3601cdf0e10cSrcweir return m_eResourceType;
3602cdf0e10cSrcweir }
3603cdf0e10cSrcweir
3604cdf0e10cSrcweir //=========================================================================
getResourceType(const uno::Reference<ucb::XCommandEnvironment> & xEnv)3605cdf0e10cSrcweir const Content::ResourceType & Content::getResourceType(
3606cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv )
3607cdf0e10cSrcweir throw ( uno::Exception )
3608cdf0e10cSrcweir {
3609cdf0e10cSrcweir return getResourceType( xEnv, m_xResAccess );
3610cdf0e10cSrcweir }
36119c0c1533SAndrea Pescetti
getLockOwner(const uno::Reference<ucb::XCommandEnvironment> & Environment)36129c0c1533SAndrea Pescetti rtl::OUString Content::getLockOwner( const uno::Reference< ucb::XCommandEnvironment >& Environment )
36139c0c1533SAndrea Pescetti {
36149c0c1533SAndrea Pescetti rtl::OUString aOwner;
36159c0c1533SAndrea Pescetti try
36169c0c1533SAndrea Pescetti {
36179c0c1533SAndrea Pescetti //DAVProperties::LOCKDISCOVERY is not cached, need to get it from the server
36189c0c1533SAndrea Pescetti uno::Sequence< beans::Property > aProperties( 1 );
36199c0c1533SAndrea Pescetti aProperties[ 0 ].Name = DAVProperties::LOCKDISCOVERY;
36209c0c1533SAndrea Pescetti aProperties[ 0 ].Handle = -1;
36219c0c1533SAndrea Pescetti
36229c0c1533SAndrea Pescetti uno::Reference< sdbc::XRow > xRow( getPropertyValues( aProperties, Environment ) );
36239c0c1533SAndrea Pescetti
36249c0c1533SAndrea Pescetti sal_Int32 nCount = aProperties.getLength();
36259c0c1533SAndrea Pescetti uno::Sequence< uno::Any > aValues( nCount );
36269c0c1533SAndrea Pescetti uno::Any* pValues = aValues.getArray();
36279c0c1533SAndrea Pescetti pValues[ 0 ] = xRow->getObject( 1, uno::Reference< container::XNameAccess >() );
36289c0c1533SAndrea Pescetti
36299c0c1533SAndrea Pescetti uno::Sequence< ::com::sun::star::ucb::Lock > aLocks;
36309c0c1533SAndrea Pescetti
36319c0c1533SAndrea Pescetti if(aValues.getConstArray()[ 0 ] >>= aLocks)
36329c0c1533SAndrea Pescetti if(aLocks.getLength() > 0)
36339c0c1533SAndrea Pescetti {
36349c0c1533SAndrea Pescetti ucb::Lock aLock = aLocks[0];
36359c0c1533SAndrea Pescetti aLock.Owner >>= aOwner;
36369c0c1533SAndrea Pescetti OSL_TRACE("Content::getLockOwner - aOwner: '%s', <<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
36379c0c1533SAndrea Pescetti rtl::OUStringToOString(aOwner, RTL_TEXTENCODING_UTF8).getStr());
36389c0c1533SAndrea Pescetti
36399c0c1533SAndrea Pescetti }
36409c0c1533SAndrea Pescetti }
36419c0c1533SAndrea Pescetti catch ( uno::Exception&)
36429c0c1533SAndrea Pescetti { }
36439c0c1533SAndrea Pescetti
36449c0c1533SAndrea Pescetti return aOwner;
36459c0c1533SAndrea Pescetti }
3646