2000-09-28 16:29:53 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: ucblockbytes.cxx,v $
|
|
|
|
*
|
2001-07-02 06:54:24 +00:00
|
|
|
* $Revision: 1.29 $
|
2000-09-28 16:29:53 +00:00
|
|
|
*
|
2001-07-02 06:54:24 +00:00
|
|
|
* last change: $Author: mba $ $Date: 2001-07-02 07:54:24 $
|
2000-09-28 16:29:53 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2000-10-23 11:26:53 +00:00
|
|
|
#include <unotools/ucblockbytes.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
2000-09-27 11:27:08 +00:00
|
|
|
|
2000-10-30 12:16:36 +00:00
|
|
|
#ifndef _COM_SUN_STAR_IO_XACTIVEDATASTREAMER_HPP_
|
|
|
|
#include <com/sun/star/io/XActiveDataStreamer.hpp>
|
|
|
|
#endif
|
2000-10-16 13:16:35 +00:00
|
|
|
#ifndef _COM_SUN_STAR_UCB_DOCUMENTHEADERFIELD_HPP_
|
|
|
|
#include <com/sun/star/ucb/DocumentHeaderField.hpp>
|
|
|
|
#endif
|
2000-09-27 11:27:08 +00:00
|
|
|
#ifndef _COM_SUN_STAR_UCB_XCOMMANDINFO_HPP_
|
|
|
|
#include <com/sun/star/ucb/XCommandInfo.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_
|
|
|
|
#include <com/sun/star/ucb/XCommandProcessor.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
|
|
|
|
#include <com/sun/star/task/XInteractionHandler.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_
|
|
|
|
#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
|
|
|
|
#endif
|
2001-06-25 09:12:25 +00:00
|
|
|
#ifndef _COM_SUN_STAR_UCB_POSTCOMMANDARGUMENT_HPP_
|
|
|
|
#include <com/sun/star/ucb/PostCommandArgument.hpp>
|
|
|
|
#endif
|
2000-09-28 16:29:53 +00:00
|
|
|
#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
|
|
|
|
#include <com/sun/star/ucb/OpenMode.hpp>
|
2000-09-27 11:27:08 +00:00
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_
|
|
|
|
#include <com/sun/star/beans/Property.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
|
|
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGENOTIFIER_HPP_
|
|
|
|
#include <com/sun/star/beans/XPropertiesChangeNotifier.hpp>
|
|
|
|
#endif
|
2000-10-16 13:16:35 +00:00
|
|
|
#ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGELISTENER_HPP_
|
|
|
|
#include <com/sun/star/beans/XPropertiesChangeListener.hpp>
|
|
|
|
#endif
|
2000-09-27 11:27:08 +00:00
|
|
|
#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
|
|
|
|
#include <com/sun/star/sdbc/XRow.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XACTIVEDATASINK_HPP_
|
|
|
|
#include <com/sun/star/io/XActiveDataSink.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XACTIVEDATACONTROL_HPP_
|
|
|
|
#include <com/sun/star/io/XActiveDataControl.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _CPPUHELPER_IMPLBASE1_HXX_
|
|
|
|
#include <cppuhelper/implbase1.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _CPPUHELPER_IMPLBASE2_HXX_
|
|
|
|
#include <cppuhelper/implbase2.hxx>
|
|
|
|
#endif
|
2000-10-16 13:16:35 +00:00
|
|
|
#ifndef _TOOLS_INETMSG_HXX
|
|
|
|
#include <tools/inetmsg.hxx>
|
|
|
|
#endif
|
2001-03-30 08:36:35 +00:00
|
|
|
#ifndef _COM_SUN_STAR_IO_XTRUNCATE_HPP_
|
|
|
|
#include <com/sun/star/io/XTruncate.hpp>
|
|
|
|
#endif
|
2000-09-27 11:27:08 +00:00
|
|
|
|
2000-10-30 12:16:36 +00:00
|
|
|
#include <ucbhelper/contentbroker.hxx>
|
2000-09-27 11:27:08 +00:00
|
|
|
#include <ucbhelper/content.hxx>
|
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::io;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::ucb;
|
|
|
|
using namespace ::com::sun::star::task;
|
|
|
|
using namespace ::com::sun::star::lang;
|
2000-10-16 13:16:35 +00:00
|
|
|
using namespace ::com::sun::star::beans;
|
2000-09-27 11:27:08 +00:00
|
|
|
|
2000-10-12 15:04:32 +00:00
|
|
|
namespace utl
|
|
|
|
{
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
/**
|
|
|
|
Helper class for getting a XInputStream when opening a content
|
|
|
|
*/
|
|
|
|
class UcbDataSink_Impl : public ::cppu::WeakImplHelper2< XActiveDataControl, XActiveDataSink >
|
2000-10-30 12:16:36 +00:00
|
|
|
{
|
|
|
|
UcbLockBytesRef m_xLockBytes;
|
|
|
|
|
|
|
|
public:
|
2000-11-02 09:24:49 +00:00
|
|
|
UcbDataSink_Impl( UcbLockBytes* pLockBytes )
|
2000-10-30 12:16:36 +00:00
|
|
|
: m_xLockBytes( pLockBytes )
|
|
|
|
{}
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
SvLockBytes* getLockBytes (void)
|
|
|
|
{ return m_xLockBytes; }
|
|
|
|
|
2000-10-30 12:16:36 +00:00
|
|
|
// XActiveDataControl.
|
2000-11-02 09:24:49 +00:00
|
|
|
virtual void SAL_CALL addListener ( const Reference<XStreamListener> &rxListener) throw(RuntimeException) {}
|
|
|
|
virtual void SAL_CALL removeListener ( const Reference<XStreamListener> &rxListener) throw(RuntimeException) {}
|
|
|
|
virtual void SAL_CALL start (void) throw(RuntimeException) {}
|
|
|
|
virtual void SAL_CALL terminate (void) throw(RuntimeException)
|
|
|
|
{ m_xLockBytes->terminate_Impl(); }
|
2000-10-30 12:16:36 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
// XActiveDataSink.
|
|
|
|
virtual void SAL_CALL setInputStream ( const Reference<XInputStream> &rxInputStream) throw(RuntimeException)
|
|
|
|
{ m_xLockBytes->setInputStream_Impl (rxInputStream); }
|
|
|
|
virtual Reference<XInputStream> SAL_CALL getInputStream (void) throw(RuntimeException)
|
|
|
|
{ return m_xLockBytes->getInputStream_Impl(); }
|
2000-10-30 12:16:36 +00:00
|
|
|
};
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
/**
|
|
|
|
Helper class for getting a XStream when opening a content
|
|
|
|
*/
|
|
|
|
class UcbStreamer_Impl : public ::cppu::WeakImplHelper2< XActiveDataStreamer, XActiveDataControl >
|
2000-10-30 12:16:36 +00:00
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
Reference < XStream > m_xStream;
|
|
|
|
UcbLockBytesRef m_xLockBytes;
|
2000-10-30 12:16:36 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
public:
|
2000-10-30 12:16:36 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
UcbStreamer_Impl( UcbLockBytes* pLockBytes )
|
|
|
|
: m_xLockBytes( pLockBytes )
|
|
|
|
{}
|
2000-10-30 12:16:36 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
// XActiveDataControl.
|
|
|
|
virtual void SAL_CALL addListener ( const Reference<XStreamListener> &rxListener) throw(RuntimeException) {}
|
|
|
|
virtual void SAL_CALL removeListener ( const Reference<XStreamListener> &rxListener) throw(RuntimeException) {}
|
|
|
|
virtual void SAL_CALL start (void) throw(RuntimeException) {}
|
|
|
|
virtual void SAL_CALL terminate (void) throw(RuntimeException)
|
|
|
|
{ m_xLockBytes->terminate_Impl(); }
|
2000-10-30 12:16:36 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
// XActiveDataStreamer
|
|
|
|
virtual void SAL_CALL setStream( const Reference< XStream >& aStream ) throw(RuntimeException)
|
|
|
|
{ m_xStream = aStream; m_xLockBytes->setStream_Impl( aStream ); }
|
|
|
|
virtual Reference< XStream > SAL_CALL getStream() throw(RuntimeException)
|
|
|
|
{ return m_xStream; }
|
|
|
|
};
|
2000-10-30 12:16:36 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
/**
|
|
|
|
Helper class for progress handling while executing UCB commands
|
|
|
|
*/
|
|
|
|
class ProgressHandler_Impl: public ::cppu::WeakImplHelper1< XProgressHandler >
|
2000-09-27 11:27:08 +00:00
|
|
|
{
|
|
|
|
Link m_aProgress;
|
|
|
|
|
|
|
|
public:
|
2000-11-02 09:24:49 +00:00
|
|
|
ProgressHandler_Impl( const Link& rLink )
|
|
|
|
: m_aProgress( rLink )
|
|
|
|
{}
|
|
|
|
// XProgressHandler
|
|
|
|
virtual void SAL_CALL push(const Any & rStatus) throw (RuntimeException) {}
|
|
|
|
virtual void SAL_CALL pop() throw (RuntimeException) {}
|
|
|
|
virtual void SAL_CALL update(const Any & rStatus) throw (RuntimeException)
|
|
|
|
{ if ( m_aProgress.IsSet() ) m_aProgress.Call( 0 ); }
|
2000-09-27 11:27:08 +00:00
|
|
|
};
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
/**
|
|
|
|
Helper class for managing interactions and progress when executing UCB commands
|
|
|
|
*/
|
2000-09-27 11:27:08 +00:00
|
|
|
class UcbTaskEnvironment : public ::cppu::WeakImplHelper1< XCommandEnvironment >
|
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
Reference< XInteractionHandler > m_xInteractionHandler;
|
|
|
|
Reference< XProgressHandler > m_xProgressHandler;
|
2000-09-27 11:27:08 +00:00
|
|
|
|
|
|
|
public:
|
2000-11-02 09:24:49 +00:00
|
|
|
UcbTaskEnvironment( const Reference< XInteractionHandler>& rxInteractionHandler,
|
|
|
|
const Reference< XProgressHandler>& rxProgressHandler )
|
|
|
|
: m_xInteractionHandler( rxInteractionHandler )
|
|
|
|
, m_xProgressHandler( rxProgressHandler )
|
|
|
|
{}
|
|
|
|
|
2000-09-27 11:27:08 +00:00
|
|
|
|
|
|
|
virtual Reference<XInteractionHandler> SAL_CALL getInteractionHandler() throw (RuntimeException)
|
|
|
|
{ return m_xInteractionHandler; }
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
virtual Reference<XProgressHandler> SAL_CALL getProgressHandler() throw (RuntimeException)
|
2000-09-27 11:27:08 +00:00
|
|
|
{ return m_xProgressHandler; }
|
|
|
|
};
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Helper class for property change notifies when executing UCB commands
|
|
|
|
*/
|
2000-10-16 13:16:35 +00:00
|
|
|
class UcbPropertiesChangeListener_Impl : public ::cppu::WeakImplHelper1< XPropertiesChangeListener >
|
|
|
|
{
|
|
|
|
public:
|
2000-09-27 11:27:08 +00:00
|
|
|
UcbLockBytesRef m_xLockBytes;
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
UcbPropertiesChangeListener_Impl( UcbLockBytesRef rRef )
|
|
|
|
: m_xLockBytes( rRef )
|
|
|
|
{}
|
2000-10-16 13:16:35 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
virtual void SAL_CALL disposing ( const EventObject &rEvent) throw(RuntimeException) {}
|
2000-10-16 13:16:35 +00:00
|
|
|
virtual void SAL_CALL propertiesChange ( const Sequence<PropertyChangeEvent> &rEvent) throw(RuntimeException);
|
|
|
|
};
|
|
|
|
|
|
|
|
void SAL_CALL UcbPropertiesChangeListener_Impl::propertiesChange ( const Sequence<PropertyChangeEvent> &rEvent) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
sal_Int32 i, n = rEvent.getLength();
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
PropertyChangeEvent evt (rEvent[i]);
|
|
|
|
if (evt.PropertyName == ::rtl::OUString::createFromAscii ("DocumentHeader"))
|
|
|
|
{
|
|
|
|
Sequence<DocumentHeaderField> aHead;
|
|
|
|
if (evt.NewValue >>= aHead)
|
|
|
|
{
|
|
|
|
sal_Int32 k, m = aHead.getLength();
|
|
|
|
for (k = 0; k < m; k++)
|
|
|
|
{
|
|
|
|
String aName( aHead[k].Name );
|
|
|
|
String aValue( aHead[k].Value );
|
|
|
|
|
|
|
|
if (aName.CompareIgnoreCaseToAscii("Expires") == COMPARE_EQUAL)
|
|
|
|
{
|
|
|
|
DateTime aExpires (0, 0);
|
|
|
|
if (INetRFC822Message::ParseDateField (aValue, aExpires))
|
|
|
|
{
|
|
|
|
aExpires.ConvertToLocalTime();
|
|
|
|
m_xLockBytes->SetExpireDate_Impl( aExpires );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_xLockBytes->SetStreamValid_Impl();
|
|
|
|
}
|
|
|
|
else if (evt.PropertyName == rtl::OUString::createFromAscii ("PresentationURL"))
|
|
|
|
{
|
|
|
|
::rtl::OUString aUrl;
|
|
|
|
if (evt.NewValue >>= aUrl)
|
|
|
|
{
|
|
|
|
::rtl::OUString aBad (::rtl::OUString::createFromAscii ("private:"));
|
|
|
|
if (!(aUrl.compareTo (aBad, aBad.getLength()) == 0))
|
|
|
|
{
|
|
|
|
// URL changed (Redirection).
|
|
|
|
m_xLockBytes->SetRealURL_Impl( aUrl );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (evt.PropertyName == ::rtl::OUString::createFromAscii ("MediaType"))
|
|
|
|
{
|
|
|
|
::rtl::OUString aContentType;
|
|
|
|
if (evt.NewValue >>= aContentType)
|
|
|
|
m_xLockBytes->SetContentType_Impl( aContentType );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
/**
|
|
|
|
Helper class for opening UCB contents synchronously or asynchronously
|
|
|
|
*/
|
2000-10-16 13:16:35 +00:00
|
|
|
class CommandThread_Impl : public ::vos::OThread
|
|
|
|
{
|
2000-09-27 11:27:08 +00:00
|
|
|
public:
|
2000-10-16 13:16:35 +00:00
|
|
|
|
|
|
|
Reference < XContent > m_xContent;
|
|
|
|
Reference < XInteractionHandler > m_xInteract;
|
|
|
|
Reference < XProgressHandler > m_xProgress;
|
|
|
|
Reference < XPropertiesChangeListener > m_xListener;
|
2001-06-25 09:12:25 +00:00
|
|
|
Reference < XInterface > m_xSink;
|
2000-10-16 13:16:35 +00:00
|
|
|
::ucb::Content* m_pContent;
|
2001-06-25 09:12:25 +00:00
|
|
|
Command m_aArgument;
|
2000-10-16 13:16:35 +00:00
|
|
|
UcbLockBytesRef m_xLockBytes;
|
2000-10-18 12:05:55 +00:00
|
|
|
UcbLockBytesHandlerRef m_xHandler;
|
2000-10-16 13:16:35 +00:00
|
|
|
sal_Bool m_bCanceled : 1;
|
|
|
|
sal_Bool m_bRunning : 1;
|
|
|
|
|
|
|
|
CommandThread_Impl( UcbLockBytesRef xLockBytes,
|
|
|
|
Reference < XContent > xContent,
|
2001-06-25 09:12:25 +00:00
|
|
|
const Command& rArg,
|
|
|
|
Reference < XInterface > xSink,
|
2000-09-27 11:27:08 +00:00
|
|
|
Reference < XInteractionHandler > xInteract,
|
|
|
|
Reference < XProgressHandler > xProgress,
|
2000-10-18 12:05:55 +00:00
|
|
|
UcbLockBytesHandlerRef xRef );
|
2000-09-28 10:24:29 +00:00
|
|
|
|
2000-10-16 13:16:35 +00:00
|
|
|
~CommandThread_Impl();
|
2000-09-28 10:24:29 +00:00
|
|
|
|
2000-09-27 11:27:08 +00:00
|
|
|
virtual void SAL_CALL onTerminated();
|
|
|
|
virtual void SAL_CALL run();
|
|
|
|
void Cancel();
|
2000-11-03 11:13:58 +00:00
|
|
|
sal_Bool DoIt();
|
2000-09-27 11:27:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2000-10-16 13:16:35 +00:00
|
|
|
CommandThread_Impl::CommandThread_Impl( UcbLockBytesRef xLockBytes,
|
|
|
|
Reference < XContent > xContent,
|
2001-06-25 09:12:25 +00:00
|
|
|
const Command& rArg,
|
|
|
|
Reference < XInterface > xSink,
|
2000-10-16 13:16:35 +00:00
|
|
|
Reference < XInteractionHandler > xInteract,
|
|
|
|
Reference < XProgressHandler > xProgress,
|
2000-10-18 12:05:55 +00:00
|
|
|
UcbLockBytesHandlerRef xRef )
|
2000-10-16 13:16:35 +00:00
|
|
|
: m_xInteract( xInteract )
|
|
|
|
, m_xContent( xContent )
|
|
|
|
, m_xProgress( xProgress )
|
|
|
|
, m_xLockBytes( xLockBytes )
|
2000-10-18 12:05:55 +00:00
|
|
|
, m_xHandler( xRef )
|
2001-06-25 09:12:25 +00:00
|
|
|
, m_xSink( xSink )
|
2000-10-16 13:16:35 +00:00
|
|
|
, m_aArgument( rArg )
|
|
|
|
, m_bCanceled( sal_False )
|
|
|
|
, m_bRunning( sal_False )
|
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
m_xLockBytes->setCommandThread_Impl( this );
|
2000-10-16 13:16:35 +00:00
|
|
|
m_pContent = new ::ucb::Content( xContent, new UcbTaskEnvironment( m_xInteract, m_xProgress ) );
|
|
|
|
Reference < XContentIdentifier > xIdent = xContent->getIdentifier();
|
|
|
|
::rtl::OUString aScheme = xIdent->getContentProviderScheme();
|
2000-11-02 09:24:49 +00:00
|
|
|
|
|
|
|
// http protocol must be handled in a special way: during the opening process the input stream may change
|
|
|
|
// only the last inputstream after notifying the document headers is valid
|
2000-10-16 13:16:35 +00:00
|
|
|
if ( aScheme.compareToAscii("http") != COMPARE_EQUAL )
|
|
|
|
m_xLockBytes->SetStreamValid_Impl();
|
|
|
|
|
|
|
|
m_xListener = new UcbPropertiesChangeListener_Impl( m_xLockBytes );
|
|
|
|
Reference< XPropertiesChangeNotifier > xProps ( xContent, UNO_QUERY );
|
|
|
|
if ( xProps.is() )
|
2000-10-19 10:26:26 +00:00
|
|
|
xProps->addPropertiesChangeListener( Sequence< ::rtl::OUString >(), m_xListener );
|
2000-10-16 13:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CommandThread_Impl::~CommandThread_Impl()
|
|
|
|
{
|
2000-10-30 12:16:36 +00:00
|
|
|
m_xLockBytes->setCommandThread_Impl(0);
|
2000-10-16 13:16:35 +00:00
|
|
|
Reference< XPropertiesChangeNotifier > xProps ( m_pContent->get(), UNO_QUERY );
|
|
|
|
if ( xProps.is() )
|
2000-10-19 10:26:26 +00:00
|
|
|
xProps->removePropertiesChangeListener( Sequence< ::rtl::OUString >(), m_xListener );
|
2000-10-16 13:16:35 +00:00
|
|
|
delete m_pContent;
|
|
|
|
}
|
|
|
|
|
2000-09-27 11:27:08 +00:00
|
|
|
void CommandThread_Impl::run()
|
|
|
|
{
|
|
|
|
m_bRunning = sal_True;
|
|
|
|
|
|
|
|
if( !m_bCanceled && schedule() )
|
2000-11-30 08:17:11 +00:00
|
|
|
DoIt();
|
2000-09-27 11:27:08 +00:00
|
|
|
|
2000-10-19 16:09:49 +00:00
|
|
|
m_bRunning = sal_False;
|
|
|
|
}
|
2000-09-28 10:24:29 +00:00
|
|
|
|
2000-11-03 11:13:58 +00:00
|
|
|
sal_Bool CommandThread_Impl::DoIt()
|
2000-10-19 16:09:49 +00:00
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
// create content and execute command
|
2000-10-19 16:09:49 +00:00
|
|
|
Any aResult;
|
|
|
|
bool bException = false;
|
|
|
|
bool bAborted = false;
|
2000-09-27 11:27:08 +00:00
|
|
|
|
2000-10-19 16:09:49 +00:00
|
|
|
try
|
|
|
|
{
|
2001-06-25 09:12:25 +00:00
|
|
|
// "synchronize" ????
|
|
|
|
aResult = m_pContent->executeCommand( m_aArgument.Name, m_aArgument.Argument );
|
2000-10-19 16:09:49 +00:00
|
|
|
}
|
|
|
|
catch ( CommandAbortedException )
|
|
|
|
{
|
|
|
|
bAborted = true;
|
|
|
|
}
|
|
|
|
catch ( Exception )
|
|
|
|
{
|
|
|
|
bException = true;
|
2000-09-27 11:27:08 +00:00
|
|
|
}
|
|
|
|
|
2000-11-30 08:17:11 +00:00
|
|
|
if ( bAborted || bException )
|
2000-10-19 16:09:49 +00:00
|
|
|
{
|
2000-11-03 11:13:58 +00:00
|
|
|
if( m_xHandler.Is() )
|
2000-10-19 16:09:49 +00:00
|
|
|
m_xHandler->Handle( UcbLockBytesHandler::CANCEL, m_xLockBytes );
|
|
|
|
|
2001-06-25 09:12:25 +00:00
|
|
|
Reference < XActiveDataSink > xSink( m_xSink, UNO_QUERY );
|
2000-11-02 09:24:49 +00:00
|
|
|
if ( xSink.is() )
|
|
|
|
xSink->setInputStream( Reference < XInputStream >() );
|
|
|
|
|
2001-06-25 09:12:25 +00:00
|
|
|
Reference < XActiveDataStreamer > xStreamer( m_xSink, UNO_QUERY );
|
2000-11-02 09:24:49 +00:00
|
|
|
if ( xStreamer.is() )
|
|
|
|
xStreamer->setStream( Reference < XStream >() );
|
|
|
|
}
|
2000-11-03 11:13:58 +00:00
|
|
|
|
2001-06-25 09:12:25 +00:00
|
|
|
Reference < XActiveDataControl > xControl( m_xSink, UNO_QUERY );
|
2000-11-03 11:13:58 +00:00
|
|
|
if ( xControl.is() )
|
2000-11-02 09:24:49 +00:00
|
|
|
xControl->terminate();
|
2000-09-27 11:27:08 +00:00
|
|
|
|
2000-11-30 08:17:11 +00:00
|
|
|
return ( bAborted || bException );
|
|
|
|
}
|
2000-10-19 16:09:49 +00:00
|
|
|
|
2000-09-27 11:27:08 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void CommandThread_Impl::onTerminated()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void CommandThread_Impl::Cancel()
|
|
|
|
{
|
|
|
|
if ( m_bCanceled )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_bCanceled = sal_True;
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
if ( m_bRunning && m_pContent )
|
2000-09-27 11:27:08 +00:00
|
|
|
{
|
2000-09-28 10:24:29 +00:00
|
|
|
m_pContent->abortCommand();
|
2000-09-27 11:27:08 +00:00
|
|
|
m_bRunning = sal_False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-16 13:16:35 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2000-10-18 12:05:55 +00:00
|
|
|
UcbLockBytes::UcbLockBytes( UcbLockBytesHandler* pHandler )
|
2000-10-16 13:16:35 +00:00
|
|
|
: m_xInputStream (NULL)
|
|
|
|
, m_pCommandThread( NULL )
|
|
|
|
, m_bTerminated (sal_False)
|
|
|
|
, m_bStreamValid (sal_False)
|
|
|
|
, m_bDontClose( sal_False )
|
2000-10-18 12:05:55 +00:00
|
|
|
, m_xHandler( pHandler )
|
2000-10-16 13:16:35 +00:00
|
|
|
, m_nError( ERRCODE_NONE )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-09-27 11:27:08 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
UcbLockBytes::~UcbLockBytes()
|
|
|
|
{
|
2000-10-30 12:16:36 +00:00
|
|
|
if ( !m_bDontClose )
|
|
|
|
{
|
|
|
|
if ( m_xInputStream.is() )
|
2001-03-08 10:32:43 +00:00
|
|
|
{
|
2001-03-05 13:48:59 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_xInputStream->closeInput();
|
|
|
|
}
|
|
|
|
catch ( RuntimeException const & )
|
|
|
|
{}
|
|
|
|
catch ( IOException const & )
|
|
|
|
{}
|
2001-03-08 10:32:43 +00:00
|
|
|
}
|
2001-06-28 09:21:03 +00:00
|
|
|
}
|
2001-03-08 10:32:43 +00:00
|
|
|
|
2001-07-02 06:54:24 +00:00
|
|
|
if ( !m_xInputStream.is() && m_xOutputStream.is() )
|
2001-06-28 09:21:03 +00:00
|
|
|
{
|
|
|
|
try
|
2001-03-08 10:32:43 +00:00
|
|
|
{
|
2001-06-28 09:21:03 +00:00
|
|
|
m_xOutputStream->closeOutput();
|
2001-03-08 10:32:43 +00:00
|
|
|
}
|
2001-06-28 09:21:03 +00:00
|
|
|
catch ( RuntimeException const & )
|
|
|
|
{}
|
|
|
|
catch ( IOException const & )
|
|
|
|
{}
|
2000-10-30 12:16:36 +00:00
|
|
|
}
|
2000-09-27 11:27:08 +00:00
|
|
|
}
|
|
|
|
|
2001-06-26 13:43:56 +00:00
|
|
|
Reference < XInputStream > UcbLockBytes::getInputStream()
|
|
|
|
{
|
|
|
|
vos::OClearableGuard aGuard( m_aMutex );
|
|
|
|
m_bDontClose = sal_True;
|
|
|
|
return m_xInputStream;
|
|
|
|
}
|
|
|
|
|
2000-09-27 11:27:08 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2000-10-30 12:16:36 +00:00
|
|
|
|
|
|
|
sal_Bool UcbLockBytes::setStream_Impl( const Reference<XStream>& aStream )
|
|
|
|
{
|
|
|
|
vos::OClearableGuard aGuard( m_aMutex );
|
|
|
|
if ( aStream.is() )
|
|
|
|
{
|
|
|
|
m_xOutputStream = aStream->getOutputStream();
|
|
|
|
setInputStream_Impl( aStream->getInputStream() );
|
|
|
|
m_xSeekable = Reference < XSeekable > ( aStream, UNO_QUERY );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_xOutputStream = Reference < XOutputStream >();
|
|
|
|
setInputStream_Impl( Reference < XInputStream >() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_xInputStream.is();
|
|
|
|
}
|
|
|
|
|
2000-09-27 11:27:08 +00:00
|
|
|
sal_Bool UcbLockBytes::setInputStream_Impl( const Reference<XInputStream> &rxInputStream )
|
|
|
|
{
|
|
|
|
BOOL bRet;
|
|
|
|
|
|
|
|
vos::OClearableGuard aGuard( m_aMutex );
|
|
|
|
if ( !m_bDontClose && m_xInputStream.is() )
|
|
|
|
m_xInputStream->closeInput();
|
|
|
|
|
|
|
|
m_xInputStream = rxInputStream;
|
2000-10-30 12:16:36 +00:00
|
|
|
m_xSeekable = Reference < XSeekable > ( rxInputStream, UNO_QUERY );
|
2000-09-27 11:27:08 +00:00
|
|
|
bRet = m_xInputStream.is();
|
|
|
|
aGuard.clear();
|
|
|
|
|
2000-10-18 12:05:55 +00:00
|
|
|
if ( m_bStreamValid && m_xInputStream.is() )
|
2000-10-16 13:16:35 +00:00
|
|
|
m_aInitialized.set();
|
2000-09-27 11:27:08 +00:00
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2000-10-16 13:16:35 +00:00
|
|
|
void UcbLockBytes::SetStreamValid_Impl()
|
|
|
|
{
|
|
|
|
m_bStreamValid = sal_True;
|
|
|
|
if ( m_xInputStream.is() )
|
|
|
|
m_aInitialized.set();
|
|
|
|
}
|
|
|
|
|
2000-09-27 11:27:08 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void UcbLockBytes::terminate_Impl()
|
|
|
|
{
|
|
|
|
m_pCommandThread = NULL;
|
|
|
|
m_bTerminated = sal_True;
|
|
|
|
m_aInitialized.set();
|
|
|
|
m_aTerminated.set();
|
|
|
|
|
2000-10-30 12:16:36 +00:00
|
|
|
if ( GetError() == ERRCODE_NONE && !m_xInputStream.is() )
|
2000-10-05 16:02:26 +00:00
|
|
|
SetError( ERRCODE_IO_NOTEXISTS );
|
|
|
|
|
2000-10-18 12:05:55 +00:00
|
|
|
if ( m_xHandler.Is() )
|
|
|
|
m_xHandler->Handle( UcbLockBytesHandler::DONE, this );
|
2000-09-27 11:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void UcbLockBytes::SetSynchronMode (BOOL bSynchron)
|
|
|
|
{
|
|
|
|
SvLockBytes::SetSynchronMode (bSynchron);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
ErrCode UcbLockBytes::ReadAt ( ULONG nPos, void *pBuffer, ULONG nCount, ULONG *pRead) const
|
|
|
|
{
|
2000-10-11 10:33:52 +00:00
|
|
|
if ( IsSynchronMode() )
|
2000-10-18 12:05:55 +00:00
|
|
|
{
|
|
|
|
UcbLockBytes* pThis = const_cast < UcbLockBytes* >( this );
|
|
|
|
if ( m_xHandler.Is() )
|
|
|
|
m_xHandler->Handle( UcbLockBytesHandler::BEFOREWAIT, pThis );
|
|
|
|
pThis->m_aInitialized.wait();
|
|
|
|
if ( m_xHandler.Is() )
|
|
|
|
m_xHandler->Handle( UcbLockBytesHandler::AFTERWAIT, pThis );
|
|
|
|
}
|
2000-10-11 10:33:52 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
Reference <XInputStream> xStream = getInputStream_Impl();
|
2000-09-27 11:27:08 +00:00
|
|
|
if ( !xStream.is() )
|
|
|
|
{
|
2000-10-18 12:05:55 +00:00
|
|
|
if ( m_bTerminated )
|
2000-09-27 11:27:08 +00:00
|
|
|
return ERRCODE_IO_CANTREAD;
|
|
|
|
else
|
|
|
|
return ERRCODE_IO_PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pRead )
|
|
|
|
*pRead = 0;
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
Reference <XSeekable> xSeekable = getSeekable_Impl();
|
|
|
|
if ( !xSeekable.is() )
|
2000-09-27 11:27:08 +00:00
|
|
|
return ERRCODE_IO_CANTREAD;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
xSeekable->seek( nPos );
|
2000-09-27 11:27:08 +00:00
|
|
|
}
|
|
|
|
catch ( IOException )
|
|
|
|
{
|
|
|
|
return ERRCODE_IO_CANTSEEK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sequence<sal_Int8> aData;
|
|
|
|
sal_Int32 nSize;
|
|
|
|
|
|
|
|
nCount = VOS_MIN(nCount, 0x7FFFFFFF);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( !m_bTerminated && !IsSynchronMode() )
|
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
sal_Int64 nLen = xSeekable->getLength();
|
2000-09-27 11:27:08 +00:00
|
|
|
if ( nPos + nCount > nLen )
|
|
|
|
return ERRCODE_IO_PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
nSize = xStream->readBytes( aData, sal_Int32(nCount) );
|
|
|
|
}
|
|
|
|
catch (IOException)
|
|
|
|
{
|
|
|
|
return ERRCODE_IO_CANTREAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
rtl_copyMemory (pBuffer, aData.getConstArray(), nSize);
|
|
|
|
if (pRead)
|
|
|
|
*pRead = ULONG(nSize);
|
|
|
|
|
|
|
|
return ERRCODE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2000-10-30 12:16:36 +00:00
|
|
|
ErrCode UcbLockBytes::WriteAt ( ULONG nPos, const void *pBuffer, ULONG nCount, ULONG *pWritten)
|
2000-09-27 11:27:08 +00:00
|
|
|
{
|
|
|
|
if ( pWritten )
|
|
|
|
*pWritten = 0;
|
2000-10-30 12:16:36 +00:00
|
|
|
|
|
|
|
DBG_ASSERT( IsSynchronMode(), "Writing is only possible in SynchronMode!" );
|
2000-11-02 09:24:49 +00:00
|
|
|
DBG_ASSERT( m_aInitialized.check(), "Writing bevor stream is ready!" );
|
2000-10-30 12:16:36 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
Reference <XSeekable> xSeekable = getSeekable_Impl();
|
|
|
|
Reference <XOutputStream> xOutputStream = getOutputStream_Impl();
|
|
|
|
if ( !xOutputStream.is() || !xSeekable.is() )
|
2000-10-30 12:16:36 +00:00
|
|
|
return ERRCODE_IO_CANTWRITE;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
xSeekable->seek( nPos );
|
2000-10-30 12:16:36 +00:00
|
|
|
}
|
|
|
|
catch ( IOException )
|
|
|
|
{
|
|
|
|
return ERRCODE_IO_CANTSEEK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int8* pData = (sal_Int8*) pBuffer;
|
|
|
|
Sequence<sal_Int8> aData( pData, nCount );
|
|
|
|
try
|
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
xOutputStream->writeBytes( aData );
|
2000-10-30 12:16:36 +00:00
|
|
|
if ( pWritten )
|
|
|
|
*pWritten = nCount;
|
|
|
|
}
|
|
|
|
catch ( Exception )
|
|
|
|
{
|
|
|
|
return ERRCODE_IO_CANTWRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERRCODE_NONE;
|
2000-09-27 11:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2000-10-30 12:16:36 +00:00
|
|
|
ErrCode UcbLockBytes::Flush() const
|
2000-09-27 11:27:08 +00:00
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
Reference <XOutputStream > xOutputStream = getOutputStream_Impl();
|
|
|
|
if ( !xOutputStream.is() )
|
2000-10-30 12:16:36 +00:00
|
|
|
return ERRCODE_IO_CANTWRITE;
|
2000-11-02 09:24:49 +00:00
|
|
|
xOutputStream->flush();
|
2000-09-27 11:27:08 +00:00
|
|
|
return ERRCODE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2001-03-08 10:32:43 +00:00
|
|
|
ErrCode UcbLockBytes::SetSize (ULONG nNewSize)
|
2000-09-27 11:27:08 +00:00
|
|
|
{
|
2001-03-08 10:32:43 +00:00
|
|
|
SvLockBytesStat aStat;
|
|
|
|
Stat( &aStat, (SvLockBytesStatFlag) 0 );
|
|
|
|
ULONG nSize = aStat.nSize;
|
2001-03-30 08:36:35 +00:00
|
|
|
|
|
|
|
if ( nSize > nNewSize )
|
|
|
|
{
|
2001-04-03 14:06:31 +00:00
|
|
|
Reference < XTruncate > xTrunc( getOutputStream_Impl(), UNO_QUERY );
|
2001-03-30 08:36:35 +00:00
|
|
|
if ( xTrunc.is() )
|
|
|
|
{
|
|
|
|
xTrunc->truncate();
|
|
|
|
nSize = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DBG_WARNING("Not truncatable!");
|
|
|
|
}
|
|
|
|
|
2001-03-08 10:32:43 +00:00
|
|
|
if ( nSize < nNewSize )
|
|
|
|
{
|
|
|
|
ULONG nDiff = nNewSize-nSize, nCount=0;
|
|
|
|
BYTE* pBuffer = new BYTE[ nDiff ];
|
|
|
|
WriteAt( nSize, pBuffer, nDiff, &nCount );
|
|
|
|
delete pBuffer;
|
|
|
|
if ( nCount != nDiff )
|
|
|
|
return ERRCODE_IO_CANTWRITE;
|
|
|
|
}
|
|
|
|
|
2000-10-30 12:16:36 +00:00
|
|
|
return ERRCODE_NONE;
|
2000-09-27 11:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
ErrCode UcbLockBytes::Stat( SvLockBytesStat *pStat, SvLockBytesStatFlag) const
|
|
|
|
{
|
2000-10-11 10:33:52 +00:00
|
|
|
if ( IsSynchronMode() )
|
2000-10-18 12:05:55 +00:00
|
|
|
{
|
|
|
|
UcbLockBytes* pThis = const_cast < UcbLockBytes* >( this );
|
|
|
|
if ( m_xHandler.Is() )
|
|
|
|
m_xHandler->Handle( UcbLockBytesHandler::BEFOREWAIT, pThis );
|
|
|
|
pThis->m_aInitialized.wait();
|
|
|
|
if ( m_xHandler.Is() )
|
|
|
|
m_xHandler->Handle( UcbLockBytesHandler::AFTERWAIT, pThis );
|
|
|
|
}
|
2000-10-11 10:33:52 +00:00
|
|
|
|
2000-09-27 11:27:08 +00:00
|
|
|
if (!pStat)
|
|
|
|
return ERRCODE_IO_INVALIDPARAMETER;
|
|
|
|
|
2000-12-06 11:42:23 +00:00
|
|
|
Reference <XInputStream> xStream = getInputStream_Impl();
|
2000-11-02 09:24:49 +00:00
|
|
|
Reference <XSeekable> xSeekable = getSeekable_Impl();
|
2000-09-27 11:27:08 +00:00
|
|
|
|
2000-12-06 11:42:23 +00:00
|
|
|
if ( !xStream.is() )
|
|
|
|
{
|
|
|
|
if ( m_bTerminated )
|
|
|
|
return ERRCODE_IO_INVALIDACCESS;
|
|
|
|
else
|
|
|
|
return ERRCODE_IO_PENDING;
|
|
|
|
}
|
|
|
|
else if( !xSeekable.is() )
|
|
|
|
return ERRCODE_IO_CANTTELL;
|
2000-09-27 11:27:08 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
pStat->nSize = ULONG(xSeekable->getLength());
|
2000-09-27 11:27:08 +00:00
|
|
|
}
|
|
|
|
catch (IOException)
|
|
|
|
{
|
|
|
|
return ERRCODE_IO_CANTTELL;
|
|
|
|
}
|
|
|
|
|
2000-12-06 11:42:23 +00:00
|
|
|
return ERRCODE_NONE;
|
2000-09-27 11:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void UcbLockBytes::Cancel()
|
|
|
|
{
|
|
|
|
if ( m_bTerminated )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( m_pCommandThread )
|
|
|
|
{
|
|
|
|
m_pCommandThread->Cancel();
|
|
|
|
m_pCommandThread = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
IMPL_LINK( UcbLockBytes, DataAvailHdl, void*, EMPTYARG )
|
|
|
|
{
|
2000-10-18 12:05:55 +00:00
|
|
|
if ( hasInputStream_Impl() && m_xHandler.Is() )
|
|
|
|
m_xHandler->Handle( UcbLockBytesHandler::DATA_AVAILABLE, this );
|
2000-09-27 11:27:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
UcbLockBytesRef UcbLockBytes::CreateInputLockBytes( const Reference< XInputStream > xInputStream )
|
2000-09-27 11:27:08 +00:00
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
if( !xInputStream.is() )
|
2000-09-27 11:27:08 +00:00
|
|
|
return NULL;;
|
2000-10-30 12:16:36 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
UcbLockBytesRef xLockBytes = new UcbLockBytes();
|
|
|
|
xLockBytes->setDontClose_Impl();
|
|
|
|
xLockBytes->setInputStream_Impl( xInputStream );
|
|
|
|
xLockBytes->terminate_Impl();
|
2000-09-28 10:24:29 +00:00
|
|
|
return xLockBytes;
|
|
|
|
}
|
|
|
|
|
2001-06-25 09:12:25 +00:00
|
|
|
UcbLockBytesRef UcbLockBytes::CreateLockBytes( const Reference < XContent > xContent, const Sequence < PropertyValue >& rProps,
|
|
|
|
Reference < XInputStream > xPostData, UcbLockBytesHandler* pHandler )
|
|
|
|
{
|
|
|
|
if( !xContent.is() )
|
|
|
|
return NULL;;
|
|
|
|
|
|
|
|
Reference< XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
|
|
|
|
Reference< XInteractionHandler > xInteractionHandler = Reference< XInteractionHandler > (
|
|
|
|
xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY );
|
|
|
|
|
|
|
|
UcbLockBytesRef xLockBytes = new UcbLockBytes( pHandler );
|
|
|
|
xLockBytes->SetSynchronMode( !pHandler );
|
|
|
|
Reference< XActiveDataControl > xSink = (XActiveDataControl*) new UcbDataSink_Impl( xLockBytes );
|
|
|
|
|
|
|
|
if ( rProps.getLength() )
|
|
|
|
{
|
|
|
|
Reference < XCommandProcessor > xProcessor( xContent, UNO_QUERY );
|
|
|
|
Command aCommand;
|
|
|
|
aCommand.Name = ::rtl::OUString::createFromAscii("setPropertyValues");
|
|
|
|
aCommand.Handle = -1; /* unknown */
|
|
|
|
aCommand.Argument <<= rProps;
|
|
|
|
xProcessor->execute( aCommand, 0, Reference < XCommandEnvironment >() );
|
|
|
|
}
|
|
|
|
|
|
|
|
PostCommandArgument aArgument;
|
|
|
|
aArgument.Source = xPostData;
|
|
|
|
aArgument.Sink = xSink;
|
|
|
|
|
|
|
|
Command aCommand;
|
|
|
|
aCommand.Name = ::rtl::OUString::createFromAscii ("post");
|
|
|
|
aCommand.Argument <<= aArgument;
|
|
|
|
|
|
|
|
Reference< XProgressHandler > xProgressHdl = new ProgressHandler_Impl( LINK( &xLockBytes, UcbLockBytes, DataAvailHdl ) );
|
|
|
|
CommandThread_Impl* pThread = new CommandThread_Impl( xLockBytes, xContent, aCommand, xSink, xInteractionHandler, xProgressHdl, pHandler );
|
|
|
|
|
|
|
|
if ( !pHandler )
|
|
|
|
{
|
|
|
|
sal_Bool bError = pThread->DoIt();
|
|
|
|
if ( bError || !xLockBytes->getInputStream_Impl().is() )
|
|
|
|
xLockBytes->SetError( ERRCODE_IO_NOTEXISTS );
|
|
|
|
delete pThread;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pThread->create();
|
|
|
|
}
|
|
|
|
|
|
|
|
return xLockBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
UcbLockBytesRef UcbLockBytes::CreateLockBytes( const Reference < XContent > xContent, const Sequence < PropertyValue >& rProps,
|
|
|
|
StreamMode eOpenMode, UcbLockBytesHandler* pHandler )
|
2000-10-30 12:16:36 +00:00
|
|
|
{
|
|
|
|
if( !xContent.is() )
|
|
|
|
return NULL;;
|
|
|
|
|
|
|
|
Reference< XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
|
|
|
|
Reference< XInteractionHandler > xInteractionHandler = Reference< XInteractionHandler > (
|
2001-05-03 07:49:33 +00:00
|
|
|
xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY );
|
2000-10-30 12:16:36 +00:00
|
|
|
|
|
|
|
UcbLockBytesRef xLockBytes = new UcbLockBytes( pHandler );
|
2000-11-02 09:24:49 +00:00
|
|
|
xLockBytes->SetSynchronMode( !pHandler );
|
|
|
|
Reference< XActiveDataControl > xSink;
|
|
|
|
if ( eOpenMode & STREAM_WRITE )
|
|
|
|
xSink = (XActiveDataControl*) new UcbStreamer_Impl( xLockBytes );
|
|
|
|
else
|
|
|
|
xSink = (XActiveDataControl*) new UcbDataSink_Impl( xLockBytes );
|
2000-10-30 12:16:36 +00:00
|
|
|
|
2001-06-25 09:12:25 +00:00
|
|
|
if ( rProps.getLength() )
|
|
|
|
{
|
|
|
|
Reference < XCommandProcessor > xProcessor( xContent, UNO_QUERY );
|
|
|
|
Command aCommand;
|
|
|
|
aCommand.Name = ::rtl::OUString::createFromAscii("setPropertyValues");
|
|
|
|
aCommand.Handle = -1; /* unknown */
|
|
|
|
aCommand.Argument <<= rProps;
|
|
|
|
xProcessor->execute( aCommand, 0, Reference < XCommandEnvironment >() );
|
|
|
|
}
|
|
|
|
|
2000-10-30 12:16:36 +00:00
|
|
|
OpenCommandArgument2 aArgument;
|
|
|
|
aArgument.Sink = xSink;
|
|
|
|
aArgument.Mode = OpenMode::DOCUMENT;
|
|
|
|
|
2001-06-25 09:12:25 +00:00
|
|
|
Command aCommand;
|
|
|
|
aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("open") );
|
|
|
|
aCommand.Argument <<= aArgument;
|
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
Reference< XProgressHandler > xProgressHdl = new ProgressHandler_Impl( LINK( &xLockBytes, UcbLockBytes, DataAvailHdl ) );
|
2001-06-25 09:12:25 +00:00
|
|
|
CommandThread_Impl* pThread = new CommandThread_Impl( xLockBytes, xContent, aCommand, xSink, xInteractionHandler, xProgressHdl, pHandler );
|
2000-09-28 10:24:29 +00:00
|
|
|
|
2000-11-30 08:17:11 +00:00
|
|
|
if ( ( eOpenMode & STREAM_WRITE ) || !pHandler )
|
2000-10-19 16:09:49 +00:00
|
|
|
{
|
2000-11-02 09:24:49 +00:00
|
|
|
// first try read/write mode
|
2000-11-03 11:20:28 +00:00
|
|
|
sal_Bool bError = pThread->DoIt();
|
2000-11-16 16:12:53 +00:00
|
|
|
if ( bError || !xLockBytes->getInputStream_Impl().is() )
|
2000-11-03 11:13:58 +00:00
|
|
|
xLockBytes->SetError( ERRCODE_IO_NOTEXISTS );
|
2000-11-02 09:24:49 +00:00
|
|
|
delete pThread;
|
|
|
|
}
|
2000-10-30 12:16:36 +00:00
|
|
|
else
|
2000-11-02 09:24:49 +00:00
|
|
|
{
|
2000-11-30 08:17:11 +00:00
|
|
|
pThread->create();
|
2000-11-02 09:24:49 +00:00
|
|
|
}
|
2000-10-19 16:09:49 +00:00
|
|
|
|
2000-11-02 09:24:49 +00:00
|
|
|
return xLockBytes;
|
2000-10-19 16:09:49 +00:00
|
|
|
}
|
|
|
|
|
2000-10-12 15:04:32 +00:00
|
|
|
};
|