summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorMathias Bauer <mba@openoffice.org>2000-10-30 12:16:36 +0000
committerMathias Bauer <mba@openoffice.org>2000-10-30 12:16:36 +0000
commit43bd5f68a3567dacdbedd7b72b739a57b6df9d2f (patch)
tree18dc41f316b552d3de99680f956646d754d50750 /unotools
parent210a534b12bfc3befed9e50c74a1204adb994af1 (diff)
new fileaccess support
Diffstat (limited to 'unotools')
-rw-r--r--unotools/inc/unotools/tempfile.hxx36
-rw-r--r--unotools/inc/unotools/ucblockbytes.hxx22
-rw-r--r--unotools/source/ucbhelper/makefile.mk11
-rw-r--r--unotools/source/ucbhelper/tempfile.cxx105
-rw-r--r--unotools/source/ucbhelper/ucblockbytes.cxx256
5 files changed, 332 insertions, 98 deletions
diff --git a/unotools/inc/unotools/tempfile.hxx b/unotools/inc/unotools/tempfile.hxx
index a38c26e9a5cd..353128c9ab6d 100644
--- a/unotools/inc/unotools/tempfile.hxx
+++ b/unotools/inc/unotools/tempfile.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: tempfile.hxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: mba $ $Date: 2000-10-12 15:58:59 $
+ * last change: $Author: mba $ $Date: 2000-10-30 13:16:03 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -68,6 +68,26 @@
namespace utl
{
+class LocalFileHelper
+{
+public:
+ /**
+ Converts a "physical" file name into a "UCB compatible" URL ( if possible ).
+ If no UCP is available for the local file system, sal_False and an empty URL is returned.
+ Returning sal_True and an empty URL means that the URL doesn't point to a local file.
+ */
+ static sal_Bool ConvertPhysicalNameToURL( const String& rName, String& rReturn );
+
+ /**
+ Converts a "UCB compatible" URL into a "physical" file name.
+ If no UCP is available for the local file system, sal_False and an empty file name is returned,
+ otherwise sal_True and a valid URL, because a file name can always be converted if a UCP for the local
+ file system is present ( watch: this doesn't mean that this file really exists! )
+ */
+ static sal_Bool ConvertURLToPhysicalName( const String& rName, String& rReturn );
+
+};
+
struct TempFile_Impl;
/**
@@ -77,7 +97,7 @@ struct TempFile_Impl;
Creating a UCB content on a TempFile is only possible if a UCP for the local file system is present.
TempFiles can always be accessed by SvFileStreams or Sot/SvStorages using the "physical" file name ( not the URL, because
this may be a non-file URL, see below ), but if a UCB content can be created, it is also possible to take the URL and use
- the UCB helper classes for streams.
+ the UCB helper classes for streams. For convenience use UcbStreamHelper.
A Tempfile always has a "physical" file name ( a file name in the local computers host notation ) but it has a
"UCB compatible" URL only if a UCP for the local file system exists. This URL may have its own URL scheme
( not neccessarily "file://" ! ). The TempFile class methods take this into account, but other simple conversions like
@@ -151,18 +171,12 @@ public:
/**
Only create a "physical" file name for a temporary file that would be valid at that moment.
Should only be used for 3rd party code with a file name interface that wants to create the file by itself.
- If you want to convert this URL into a file name, always use the static method below, but never use any
- external conversion functions.
+ If you want to convert file name into a URL, always use class LocalFileHelper, but never use any
+ conversion functions of osl.
*/
static String CreateTempName( const String* pParent=NULL );
/**
- Converts a "physical" file name into a "UCB compatible" URL ( if possible ).
- If no UCP is available for the local file system, an empty URL is returned.
- */
- static String ConvertURLToPhysicalName( const String& rName );
-
- /**
The TempNameBaseDirectory is a subfolder in the folder that is passed as a "physical" file name in the
SetTempNameBaseDirectory method.
This subfolder will be used if a TempFile or TempName is created without a parent name or a parent name
diff --git a/unotools/inc/unotools/ucblockbytes.hxx b/unotools/inc/unotools/ucblockbytes.hxx
index 88f62192998f..a203e0694638 100644
--- a/unotools/inc/unotools/ucblockbytes.hxx
+++ b/unotools/inc/unotools/ucblockbytes.hxx
@@ -7,9 +7,18 @@
#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
#include <com/sun/star/io/XInputStream.hpp>
#endif
+#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_
+#include <com/sun/star/io/XOutputStream.hpp>
+#endif
+#ifndef _COM_SUN_STAR_IO_XSTREAM_HPP_
+#include <com/sun/star/io/XStream.hpp>
+#endif
#ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_
#include <com/sun/star/ucb/XContent.hpp>
#endif
+#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
+#include <com/sun/star/io/XSeekable.hpp>
+#endif
#include <vos/thread.hxx>
#include <vos/conditn.hxx>
@@ -62,7 +71,9 @@ class UcbLockBytes : public virtual SvLockBytes
String m_aRealURL;
DateTime m_aExpireDate;
- NS_UNO::Reference < NS_IO::XInputStream > m_xInputStream;
+ NS_UNO::Reference < NS_IO::XInputStream > m_xInputStream;
+ NS_UNO::Reference < NS_IO::XOutputStream > m_xOutputStream;
+ NS_UNO::Reference < NS_IO::XSeekable > m_xSeekable;
CommandThread_Impl* m_pCommandThread;
UcbLockBytesHandlerRef m_xHandler;
@@ -82,8 +93,12 @@ protected:
public:
- static UcbLockBytesRef CreateInputLockBytes( const NS_UNO::Reference < NS_UCB::XContent > xContent, UcbLockBytesHandler* pHandler=0 );
- static UcbLockBytesRef CreateInputLockBytes( const NS_UNO::Reference < NS_IO::XInputStream > xContent, UcbLockBytesHandler* pHandler=0 );
+ static UcbLockBytesRef CreateInOutputLockBytes( const NS_UNO::Reference < NS_UCB::XContent > xContent,
+ UcbLockBytesHandler* pHandler=0 );
+ static UcbLockBytesRef CreateInputLockBytes( const NS_UNO::Reference < NS_UCB::XContent > xContent,
+ UcbLockBytesHandler* pHandler=0 );
+ static UcbLockBytesRef CreateInputLockBytes( const NS_UNO::Reference < NS_IO::XInputStream > xContent,
+ UcbLockBytesHandler* pHandler=0 );
// SvLockBytes
virtual void SetSynchronMode (BOOL bSynchron);
@@ -108,6 +123,7 @@ public:
#if __PRIVATE
sal_Bool setInputStream_Impl( const NS_UNO::Reference < NS_IO::XInputStream > &rxInputStream );
+ sal_Bool setStream_Impl( const NS_UNO::Reference < NS_IO::XStream > &rxStream );
void terminate_Impl (void);
NS_UNO::Reference < NS_IO::XInputStream > getInputStream_Impl() const
diff --git a/unotools/source/ucbhelper/makefile.mk b/unotools/source/ucbhelper/makefile.mk
index 45ff30729eab..27810c33eea8 100644
--- a/unotools/source/ucbhelper/makefile.mk
+++ b/unotools/source/ucbhelper/makefile.mk
@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.2 $
+# $Revision: 1.3 $
#
-# last change: $Author: bmahbod $ $Date: 2000-10-06 23:53:15 $
+# last change: $Author: mba $ $Date: 2000-10-30 13:16:36 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -93,11 +93,12 @@ ENABLE_EXCEPTIONS=TRUE
# --- Files -------------------------------------
SLOFILES=\
- $(SLO)$/ucblockbytes.obj
+ $(SLO)$/ucblockbytes.obj \
+ $(SLO)$/tempfile.obj
# NETBSD: somewhere we have to instantiate the static data members.
-# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism
-# for GCC won't work. SCO and MACOSX: the linker does know about weak
+# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism
+# for GCC won't work. SCO and MACOSX: the linker does know about weak
# symbols, but we can't ignore multiple defined symbols
.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX"
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index 70ddb7411954..d23526144b70 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: tempfile.cxx,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: mba $ $Date: 2000-10-12 15:59:19 $
+ * last change: $Author: mba $ $Date: 2000-10-30 13:16:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -61,8 +61,11 @@
#include <unotools/tempfile.hxx>
+#include <ucbhelper/Fileidentifierconverter.hxx>
+#include <ucbhelper/contentbroker.hxx>
#include <rtl/ustring.hxx>
#include <osl/file.hxx>
+#include <osl/socket.h>
#include <tools/time.hxx>
#include <tools/debug.hxx>
#include <stdio.h>
@@ -77,6 +80,7 @@ static ::rtl::OUString aTempNameBase_Impl;
struct TempFile_Impl
{
String aName;
+ String aURL;
sal_Bool bIsDirectory;
};
@@ -86,20 +90,33 @@ String ConstructTempDir_Impl( const String* pParent )
String aName;
if ( pParent && pParent->Len() )
{
- // if parent given try to use it
- rtl::OUString aTmp( *pParent );
- rtl::OUString aRet;
-
- // test for valid filename
- if ( FileBase::getNormalizedPathFromFileURL( aTmp, aRet ) == FileBase::E_None )
+ ::ucb::ContentBroker* pBroker = ::ucb::ContentBroker::get();
+ if ( pBroker )
{
- ::osl::DirectoryItem aItem;
- sal_Int32 i = aRet.getLength();
- if ( aRet[i-1] == '/' )
- i--;
+ ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProviderManager > xManager =
+ pBroker->getContentProviderManagerInterface();
+
+ // if parent given try to use it
+ rtl::OUString aTmp( *pParent );
+ rtl::OUString aHost;
+ osl_getLocalHostname( &aHost.pData );
+
+ // test for valid filename
+ rtl::OUString aRet = ::ucb::getNormalizedPathFromFileURL( xManager, aTmp, aHost );
+ if ( aRet.getLength() )
+ {
+ ::osl::DirectoryItem aItem;
+ sal_Int32 i = aRet.getLength();
+ if ( aRet[i-1] == '/' )
+ i--;
- if ( DirectoryItem::get( ::rtl::OUString( aRet, i ), aItem ) == FileBase::E_None )
- aName = aRet;
+ if ( DirectoryItem::get( ::rtl::OUString( aRet, i ), aItem ) == FileBase::E_None )
+ aName = aRet;
+ }
+ }
+ else
+ {
+ DBG_WARNING( "::unotools::TempFile : UCB not present or not initialized!" );
}
}
@@ -281,19 +298,16 @@ String TempFile::GetFileName() const
String TempFile::GetURL() const
{
- rtl::OUString aTmp;
- FileBase::getFileURLFromNormalizedPath( pImp->aName, aTmp );
- return aTmp;
-}
+ if ( !pImp->aURL.Len() )
+ {
+ String aTmp;
+ LocalFileHelper::ConvertPhysicalNameToURL( GetFileName(), aTmp );
+ pImp->aURL = aTmp;
+ }
-String TempFile::ConvertURLToPhysicalName( const String& rName )
-{
- rtl::OUString aTmp;
- FileBase::getFileURLFromNormalizedPath( rName, aTmp );
- return aTmp;
+ return pImp->aURL;
}
-
String TempFile::SetTempNameBaseDirectory( const String &rBaseName )
{
String aName( rBaseName );
@@ -324,4 +338,47 @@ String TempFile::GetTempNameBaseDirectory()
return aTmp;
}
+sal_Bool LocalFileHelper::ConvertPhysicalNameToURL( const String& rName, String& rReturn )
+{
+ ::ucb::ContentBroker* pBroker = ::ucb::ContentBroker::get();
+ if ( !pBroker )
+ {
+ DBG_WARNING( "::unotools::TempFile : UCB not present or not initialized!" );
+ return sal_False;
+ }
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProviderManager > xManager =
+ pBroker->getContentProviderManagerInterface();
+
+ rtl::OUString aHost;
+ osl_getLocalHostname( &aHost.pData );
+
+ ::rtl::OUString aTmp;
+ FileBase::normalizePath( rName, aTmp );
+ rtl::OUString aRet = ::ucb::getFileURLFromNormalizedPath( xManager, aHost, aTmp );
+ rReturn = aRet;
+ return sal_True;
+}
+
+sal_Bool LocalFileHelper::ConvertURLToPhysicalName( const String& rName, String& rReturn )
+{
+ ::ucb::ContentBroker* pBroker = ::ucb::ContentBroker::get();
+ if ( !pBroker )
+ {
+ DBG_WARNING( "::unotools::TempFile : UCB not present or not initialized!" );
+ return sal_False;
+ }
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentProviderManager > xManager =
+ pBroker->getContentProviderManagerInterface();
+
+ rtl::OUString aHost;
+ osl_getLocalHostname( &aHost.pData );
+ rtl::OUString aRet = ::ucb::getNormalizedPathFromFileURL( xManager, aHost, rName );
+ ::rtl::OUString aTmp;
+ FileBase::getSystemPathFromNormalizedPath( aRet, aTmp );
+ rReturn = aTmp;
+ return sal_True;
+}
+
};
diff --git a/unotools/source/ucbhelper/ucblockbytes.cxx b/unotools/source/ucbhelper/ucblockbytes.cxx
index c7bc0ecaf456..e88cca66211f 100644
--- a/unotools/source/ucbhelper/ucblockbytes.cxx
+++ b/unotools/source/ucbhelper/ucblockbytes.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ucblockbytes.cxx,v $
*
- * $Revision: 1.12 $
+ * $Revision: 1.13 $
*
- * last change: $Author: mba $ $Date: 2000-10-23 12:26:53 $
+ * last change: $Author: mba $ $Date: 2000-10-30 13:16:36 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -62,6 +62,12 @@
#include <unotools/ucblockbytes.hxx>
#include <comphelper/processfactory.hxx>
+#ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_
+#include <com/sun/star/ucb/InsertCommandArgument.hpp>
+#endif
+#ifndef _COM_SUN_STAR_IO_XACTIVEDATASTREAMER_HPP_
+#include <com/sun/star/io/XActiveDataStreamer.hpp>
+#endif
#ifndef _COM_SUN_STAR_UCB_DOCUMENTHEADERFIELD_HPP_
#include <com/sun/star/ucb/DocumentHeaderField.hpp>
#endif
@@ -101,9 +107,6 @@
#ifndef _COM_SUN_STAR_IO_XACTIVEDATACONTROL_HPP_
#include <com/sun/star/io/XActiveDataControl.hpp>
#endif
-#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
-#include <com/sun/star/io/XSeekable.hpp>
-#endif
#ifndef _CPPUHELPER_IMPLBASE1_HXX_
#include <cppuhelper/implbase1.hxx>
#endif
@@ -114,6 +117,7 @@
#include <tools/inetmsg.hxx>
#endif
+#include <ucbhelper/contentbroker.hxx>
#include <ucbhelper/content.hxx>
using namespace ::com::sun::star::uno;
@@ -127,6 +131,58 @@ using namespace ::com::sun::star::beans;
namespace utl
{
+class UcbStreamer_Impl : public ::cppu::WeakImplHelper2< XActiveDataStreamer, XActiveDataControl >
+{
+ Reference < XStream > m_xStream;
+ UcbLockBytesRef m_xLockBytes;
+
+public:
+
+ UcbStreamer_Impl( UcbLockBytes* pLockBytes )
+ : m_xLockBytes( pLockBytes )
+ {}
+
+ // 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);
+
+ // XActiveDataStreamer
+ virtual void SAL_CALL setStream( const Reference< XStream >& aStream ) throw(RuntimeException);
+ virtual Reference< XStream > SAL_CALL getStream() throw(RuntimeException);
+};
+
+void SAL_CALL UcbStreamer_Impl::addListener ( const Reference<XStreamListener> &rxListener) throw(RuntimeException)
+{
+ // not supported
+}
+
+void SAL_CALL UcbStreamer_Impl::removeListener ( const Reference<XStreamListener> &rxListener) throw(RuntimeException)
+{
+ // not supported
+}
+
+void SAL_CALL UcbStreamer_Impl::start (void) throw(RuntimeException)
+{
+}
+
+void SAL_CALL UcbStreamer_Impl::terminate (void) throw(RuntimeException)
+{
+ m_xLockBytes->terminate_Impl();
+}
+
+void UcbStreamer_Impl::setStream( const Reference< XStream >& aStream ) throw(RuntimeException)
+{
+ m_xStream = aStream;
+ m_xLockBytes->setStream_Impl( aStream );
+}
+
+Reference< XStream > UcbStreamer_Impl::getStream() throw(RuntimeException)
+{
+ return m_xStream;
+}
+
class ProgressHandler_Impl: public cppu::OWeakObject, public XProgressHandler
{
Link m_aProgress;
@@ -199,7 +255,6 @@ public:
{ return m_xProgressHandler; }
};
-
class UcbPropertiesChangeListener_Impl : public ::cppu::WeakImplHelper1< XPropertiesChangeListener >
{
public:
@@ -347,6 +402,7 @@ CommandThread_Impl::CommandThread_Impl( UcbLockBytesRef xLockBytes,
CommandThread_Impl::~CommandThread_Impl()
{
+ m_xLockBytes->setCommandThread_Impl(0);
Reference< XPropertiesChangeNotifier > xProps ( m_pContent->get(), UNO_QUERY );
if ( xProps.is() )
xProps->removePropertiesChangeListener( Sequence< ::rtl::OUString >(), m_xListener );
@@ -436,8 +492,6 @@ UcbLockBytes::UcbLockBytes( UcbLockBytesHandler* pHandler )
, m_bTerminated (sal_False)
, m_bStreamValid (sal_False)
, m_bDontClose( sal_False )
- , m_nRead (0)
- , m_nSize (0)
, m_xHandler( pHandler )
, m_nError( ERRCODE_NONE )
{
@@ -446,21 +500,45 @@ UcbLockBytes::UcbLockBytes( UcbLockBytesHandler* pHandler )
//----------------------------------------------------------------------------
UcbLockBytes::~UcbLockBytes()
{
- if ( !m_bDontClose && m_xInputStream.is() )
- m_xInputStream->closeInput();
+ if ( !m_bDontClose )
+ {
+ if ( m_xInputStream.is() )
+ m_xInputStream->closeInput();
+ if ( m_xOutputStream.is() )
+ m_xOutputStream->closeOutput();
+ }
}
//----------------------------------------------------------------------------
+
+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();
+}
+
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;
+ m_xSeekable = Reference < XSeekable > ( rxInputStream, UNO_QUERY );
bRet = m_xInputStream.is();
aGuard.clear();
@@ -481,19 +559,11 @@ void UcbLockBytes::SetStreamValid_Impl()
void UcbLockBytes::terminate_Impl()
{
m_pCommandThread = NULL;
-
- Reference<XInputStream> xStream = getInputStream_Impl();
- Reference<XSeekable> xSeekable (xStream, UNO_QUERY);
-
- if ( xSeekable.is() )
- m_nSize = sal_uInt32(xSeekable->getLength());
-
m_bTerminated = sal_True;
-
m_aInitialized.set();
m_aTerminated.set();
- if ( GetError() == ERRCODE_NONE && !xStream.is() )
+ if ( GetError() == ERRCODE_NONE && !m_xInputStream.is() )
SetError( ERRCODE_IO_NOTEXISTS );
if ( m_xHandler.Is() )
@@ -520,7 +590,6 @@ ErrCode UcbLockBytes::ReadAt ( ULONG nPos, void *pBuffer, ULONG nCount, ULONG *p
}
Reference<XInputStream> xStream = getInputStream_Impl();
-
if ( !xStream.is() )
{
if ( m_bTerminated )
@@ -532,13 +601,12 @@ ErrCode UcbLockBytes::ReadAt ( ULONG nPos, void *pBuffer, ULONG nCount, ULONG *p
if ( pRead )
*pRead = 0;
- Reference < XSeekable > xSeekable( xStream, UNO_QUERY );
- if ( !xSeekable.is() )
+ if ( !m_xSeekable.is() )
return ERRCODE_IO_CANTREAD;
try
{
- xSeekable->seek( nPos );
+ m_xSeekable->seek( nPos );
}
catch ( IOException )
{
@@ -553,7 +621,7 @@ ErrCode UcbLockBytes::ReadAt ( ULONG nPos, void *pBuffer, ULONG nCount, ULONG *p
{
if ( !m_bTerminated && !IsSynchronMode() )
{
- sal_Int64 nLen = xSeekable->getLength();
+ sal_Int64 nLen = m_xSeekable->getLength();
if ( nPos + nCount > nLen )
return ERRCODE_IO_PENDING;
}
@@ -569,30 +637,64 @@ ErrCode UcbLockBytes::ReadAt ( ULONG nPos, void *pBuffer, ULONG nCount, ULONG *p
if (pRead)
*pRead = ULONG(nSize);
- sal_uInt32 nRead = VOS_MAX(m_nRead, nPos + nSize);
- SAL_CONST_CAST(UcbLockBytes*, this)->m_nRead = nRead;
-
return ERRCODE_NONE;
}
//----------------------------------------------------------------------------
-ErrCode UcbLockBytes::WriteAt ( ULONG, const void*, ULONG, ULONG *pWritten)
+ErrCode UcbLockBytes::WriteAt ( ULONG nPos, const void *pBuffer, ULONG nCount, ULONG *pWritten)
{
if ( pWritten )
*pWritten = 0;
- return ERRCODE_IO_CANTWRITE;
+
+ DBG_ASSERT( IsSynchronMode(), "Writing is only possible in SynchronMode!" );
+ 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 );
+
+ if ( !m_xOutputStream.is() || !m_xSeekable.is() )
+ return ERRCODE_IO_CANTWRITE;
+
+ try
+ {
+ m_xSeekable->seek( nPos );
+ }
+ catch ( IOException )
+ {
+ return ERRCODE_IO_CANTSEEK;
+ }
+
+ sal_Int8* pData = (sal_Int8*) pBuffer;
+ Sequence<sal_Int8> aData( pData, nCount );
+ try
+ {
+ m_xOutputStream->writeBytes( aData );
+ if ( pWritten )
+ *pWritten = nCount;
+ }
+ catch ( Exception )
+ {
+ return ERRCODE_IO_CANTWRITE;
+ }
+
+ return ERRCODE_NONE;
}
//----------------------------------------------------------------------------
-ErrCode UcbLockBytes::Flush (void) const
+ErrCode UcbLockBytes::Flush() const
{
+ if ( !m_xOutputStream.is() )
+ return ERRCODE_IO_CANTWRITE;
+ m_xOutputStream->flush();
return ERRCODE_NONE;
}
//----------------------------------------------------------------------------
ErrCode UcbLockBytes::SetSize (ULONG)
{
- return ERRCODE_IO_NOTSUPPORTED;
+ return ERRCODE_NONE;
}
//----------------------------------------------------------------------------
@@ -613,16 +715,12 @@ ErrCode UcbLockBytes::Stat( SvLockBytesStat *pStat, SvLockBytesStatFlag) const
Reference<XInputStream> xStream = getInputStream_Impl();
- if (!xStream.is())
- return ERRCODE_IO_INVALIDACCESS;
-
- Reference<XSeekable> xSeekable (xStream, UNO_QUERY);
- if (!xSeekable.is())
+ if ( !xStream.is() || !m_xSeekable.is() )
return ERRCODE_IO_INVALIDACCESS;
try
{
- pStat->nSize = ULONG(xSeekable->getLength());
+ pStat->nSize = ULONG(m_xSeekable->getLength());
}
catch (IOException)
{
@@ -739,10 +837,10 @@ UcbLockBytesRef UcbLockBytes::CreateInputLockBytes( const Reference < XContent >
Reference< XInteractionHandler > xInteractionHandler = Reference< XInteractionHandler > (
xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uui.InteractionHandler") ) ), UNO_QUERY );
- OpenCommandArgument2 aArgument;
- String aCmd( RTL_CONSTASCII_USTRINGPARAM( "Open" ) );
UcbLockBytesRef xLockBytes = new UcbLockBytes( pHandler );
Reference < XActiveDataSink > xSink = new UcbDataSink_Impl( xLockBytes );
+
+ OpenCommandArgument2 aArgument;
aArgument.Sink = xSink;
aArgument.Mode = OpenMode::DOCUMENT;
@@ -756,6 +854,33 @@ UcbLockBytesRef UcbLockBytes::CreateInputLockBytes( const Reference < XContent >
return xLockBytes;
}
+UcbLockBytesRef UcbLockBytes::CreateInOutputLockBytes( const Reference < XContent > xContent, 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.uui.InteractionHandler") ) ), UNO_QUERY );
+
+ UcbLockBytesRef xLockBytes = new UcbLockBytes( pHandler );
+ xLockBytes->SetSynchronMode( TRUE );
+ Reference< XActiveDataStreamer > xSink = (XActiveDataStreamer*)new UcbStreamer_Impl( xLockBytes );
+
+ OpenCommandArgument2 aArgument;
+ aArgument.Sink = xSink;
+ aArgument.Mode = OpenMode::DOCUMENT;
+
+ ProgressHandler_Impl *pProgressHdl = new ProgressHandler_Impl();
+ Reference< XProgressHandler > xProgressHdl = pProgressHdl;
+ pProgressHdl->SetProgressLink( LINK( &xLockBytes, UcbLockBytes, DataAvailHdl ) );
+
+ CommandThread_Impl aThread( xLockBytes, xContent, aArgument, xInteractionHandler, xProgressHdl, pHandler );
+ xLockBytes->setCommandThread_Impl( &aThread );
+ aThread.DoIt();
+ return xLockBytes;
+}
+
UcbLockBytesRef UcbLockBytes::CreateInputLockBytes( const Reference< XInputStream > xInputStream, UcbLockBytesHandler* pHandler )
{
if( !xInputStream.is() )
@@ -778,25 +903,46 @@ UcbLockBytesRef UcbLockBytes::CreateInputLockBytes( const Reference< XInputStrea
SvStream* UcbStreamHelper::CreateStream( const String& rFileName, StreamMode eOpenMode, UcbLockBytesHandler* pHandler, sal_Bool bForceSynchron )
{
SvStream* pStream = NULL;
- try
+ ::ucb::ContentBroker* pBroker = ::ucb::ContentBroker::get();
+ if ( pBroker )
{
- ::ucb::Content* pContent = new ::ucb::Content( rFileName, Reference < XCommandEnvironment >() );
- UcbLockBytesRef xLockBytes = UcbLockBytes::CreateInputLockBytes( pContent->get(), pHandler );
- if ( xLockBytes.Is() )
+ try
+ {
+ UcbLockBytesRef xLockBytes;
+ ::ucb::Content aContent( rFileName, Reference < XCommandEnvironment >() );
+ if ( eOpenMode & STREAM_WRITE )
+ {
+ sal_Bool bTruncate = ( eOpenMode & STREAM_TRUNC );
+ if ( bTruncate )
+ aContent.executeCommand( ::rtl::OUString::createFromAscii( "delete" ), makeAny( sal_Bool( sal_True ) ) );
+
+ InsertCommandArgument aInsertArg;
+ aInsertArg.Data = Reference< XInputStream >();
+ aInsertArg.ReplaceExisting = sal_False;
+ Any aCmdArg;
+ aCmdArg <<= aInsertArg;
+ aContent.executeCommand( ::rtl::OUString::createFromAscii( "insert" ), aCmdArg );
+ xLockBytes = UcbLockBytes::CreateInOutputLockBytes( aContent.get(), pHandler );
+ }
+ else
+ {
+ UcbLockBytes::CreateInputLockBytes( aContent.get(), pHandler );
+ }
+
+ if ( xLockBytes.Is() )
+ {
+ xLockBytes->SetSynchronMode( !pHandler || bForceSynchron );
+ pStream = new SvStream( xLockBytes );
+ }
+ }
+ catch ( Exception e )
{
- xLockBytes->SetSynchronMode( !pHandler || bForceSynchron );
- pStream = new SvStream( xLockBytes );
+ DBG_ERROR( "Any other exception!" );
}
}
- catch( ::ucb::ContentCreationException e )
- {
- if ( e.getReason() == ::ucb::ContentCreationException::NO_CONTENT_BROKER || e.getReason() == ::ucb::ContentCreationException::NO_CONTENT_PROVIDER )
- pStream = new SvFileStream( rFileName, eOpenMode );
- }
- catch ( Exception e )
- {
- DBG_ERROR( "Any other exception!" );
- }
+ else
+ // if no UCB is present at least conventional file io is supported
+ pStream = new SvFileStream( rFileName, eOpenMode );
return pStream;
}