diff options
author | Michael Meeks <mmeeks@openoffice.org> | 2004-08-05 16:44:50 +0000 |
---|---|---|
committer | Michael Meeks <mmeeks@openoffice.org> | 2004-08-05 16:44:50 +0000 |
commit | d3d443127b4f02a4b89758dcb29a34bf5ee80e8a (patch) | |
tree | fe8d946d4c34f18eef63bfa2404d33bb831ec375 /writerperfect/source/stream | |
parent | new version for SRC680 (diff) | |
download | core-d3d443127b4f02a4b89758dcb29a34bf5ee80e8a.tar.gz core-d3d443127b4f02a4b89758dcb29a34bf5ee80e8a.zip |
Issue number: 32649
Submitted by: writerperfect team
Reviewed by: mh
Diffstat (limited to 'writerperfect/source/stream')
-rw-r--r-- | writerperfect/source/stream/WPXSvStream.cxx | 103 | ||||
-rw-r--r-- | writerperfect/source/stream/WPXSvStream.h | 33 | ||||
-rw-r--r-- | writerperfect/source/stream/makefile.mk | 14 |
3 files changed, 150 insertions, 0 deletions
diff --git a/writerperfect/source/stream/WPXSvStream.cxx b/writerperfect/source/stream/WPXSvStream.cxx new file mode 100644 index 000000000000..f6f14e85d3c8 --- /dev/null +++ b/writerperfect/source/stream/WPXSvStream.cxx @@ -0,0 +1,103 @@ +#include "WPXSvStream.h" +#include "libwpd_internal.h" + +#include <sot/storage.hxx> +#include <tools/stream.hxx> +#include <unotools/streamwrap.hxx> +#include <unotools/ucbstreamhelper.hxx> + +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_H_ +#include <com/sun/star/io/XSeekable.hpp> +#endif + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::io; + +WPXSvInputStream::WPXSvInputStream( Reference< XInputStream > xStream ) : + WPXInputStream(true), + mxStream(xStream), + mnOffset(0) +{ + Reference < XSeekable> xSeekable = Reference < XSeekable > (xStream, UNO_QUERY); + if (!xSeekable.is()) + mnLength = 0; + else + mnLength = xSeekable->getLength(); // exception +} + +WPXSvInputStream::~WPXSvInputStream() +{ +} + +const uint8_t * WPXSvInputStream::read(size_t numBytes) +{ + // FIXME: assume no short reads (?) + mnOffset += mxStream->readBytes (maData, numBytes); + return (const uint8_t *)maData.getConstArray(); +} + +int WPXSvInputStream::seek(long offset, WPX_SEEK_TYPE seekType) +{ + if (seekType == WPX_SEEK_CUR && offset >= 0) + { + mxStream->skipBytes (offset); // exception ? + mnOffset += offset; + return FALSE; + } + + Reference < XSeekable> xSeekable = Reference < XSeekable >(mxStream, UNO_QUERY); + + if (!xSeekable.is()) + return TRUE; + + if (seekType == WPX_SEEK_CUR) + mnOffset += offset; + else + mnOffset = offset; + + xSeekable->seek(mnOffset); // FIXME: catch exception! + + return FALSE; +} + +long WPXSvInputStream::tell() +{ + return mnOffset; +} + +bool WPXSvInputStream::atEOS() +{ + return mnOffset < mnLength; +} + +bool WPXSvInputStream::isOLEStream() +{ + bool bAns; + + SvStream *pStream = utl::UcbStreamHelper::CreateStream( mxStream ); + bAns = pStream && SotStorage::IsOLEStorage( pStream ); + delete pStream; + + return bAns; +} + +WPXInputStream * WPXSvInputStream::getDocumentOLEStream() +{ + SvStream *pStream = utl::UcbStreamHelper::CreateStream( mxStream ); + + SotStorage *pStorage = new SotStorage( pStream, TRUE ); + + fprintf (stderr, "Dodgy\n"); + SvStream *pContents = pStorage->OpenSotStream( + rtl::OUString::createFromAscii( "PerfectOffice_MAIN" ), + STREAM_STD_READ ); + + Reference < XInputStream > xContents = new utl::OInputStreamWrapper( pStream ); + if (xContents.is()) + return new WPXSvInputStream( xContents ); + else { + fprintf( stderr, "Badly wrong\n" ); + return NULL; + } + // FIXME: we leak pStorage - investigate protected destructor there. +} diff --git a/writerperfect/source/stream/WPXSvStream.h b/writerperfect/source/stream/WPXSvStream.h new file mode 100644 index 000000000000..cf12b286a904 --- /dev/null +++ b/writerperfect/source/stream/WPXSvStream.h @@ -0,0 +1,33 @@ +#ifndef WPXSVSTREAM_H +#define WPXSVSTREAM_H + +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_H_ +#include <com/sun/star/io/XInputStream.hpp> +#endif + +#include <libwpd/WPXStream.h> + +class WPXSvInputStream : public WPXInputStream +{ +public: + WPXSvInputStream( ::com::sun::star::uno::Reference< + ::com::sun::star::io::XInputStream > xStream ); + virtual ~WPXSvInputStream(); + + virtual bool isOLEStream(); + virtual WPXInputStream * getDocumentOLEStream(); + + virtual const uint8_t *read(size_t numBytes); + virtual int seek(long offset, WPX_SEEK_TYPE seekType); + virtual long tell(); + virtual bool atEOS(); + +private: + ::com::sun::star::uno::Reference< + ::com::sun::star::io::XInputStream > mxStream; + ::com::sun::star::uno::Sequence< sal_Int8 > maData; + sal_Int64 mnOffset; + sal_Int64 mnLength; +}; + +#endif diff --git a/writerperfect/source/stream/makefile.mk b/writerperfect/source/stream/makefile.mk new file mode 100644 index 000000000000..14d5fe2911c8 --- /dev/null +++ b/writerperfect/source/stream/makefile.mk @@ -0,0 +1,14 @@ +PRJ=..$/.. + +PRJNAME=stream +TARGET=stream +ENABLE_EXCEPTIONS=true + +.INCLUDE : settings.mk + +# broken but ... necessary, internal include shafted ... +INCPRE+=$(SOLARVER)$/$(UPD)$/$(INPATH)$/inc$/libwpd + +SLOFILES= $(SLO)$/WPXSvStream.obj + +.INCLUDE : target.mk |