summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2007-01-23 11:18:14 +0000
committerOliver Bolte <obo@openoffice.org>2007-01-23 11:18:14 +0000
commit4c2cefae797073999edabb3a7f29c47b1331d674 (patch)
treebf514829b497a5f40ea6646943946bc2425fe6c6 /writerperfect
parent7e1862f87df429a4cb2fec495fe58b16d60af4b2 (diff)
INTEGRATION: CWS fs08 (1.5.36); FILE MERGED
2007/01/04 11:44:20 fridrich_strba 1.5.36.6: some improvements and bug-fixes from cws wpsimport01 2007/01/03 15:51:59 fridrich_strba 1.5.36.5: make the mxChildStream and mxChildStorage members of the class again 2006/12/30 14:41:56 fridrich_strba 1.5.36.4: refactoring the stream class to make it a bit more robust 2006/12/22 16:18:36 fridrich_strba 1.5.36.3: trying to put belts and braces around the stream class 2006/12/20 16:06:40 fridrich_strba 1.5.36.2: removing warnings on wntmsci10 2006/12/18 09:27:18 fridrich_strba 1.5.36.1: convert writerperfect into a framework where converter libraries based on libwpd's api can simply plug themselves
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/source/stream/WPXSvStream.cxx142
1 files changed, 89 insertions, 53 deletions
diff --git a/writerperfect/source/stream/WPXSvStream.cxx b/writerperfect/source/stream/WPXSvStream.cxx
index b37f9d0e9099..749c1b2e0e64 100644
--- a/writerperfect/source/stream/WPXSvStream.cxx
+++ b/writerperfect/source/stream/WPXSvStream.cxx
@@ -1,12 +1,9 @@
#include "WPXSvStream.h"
+#include "filter/FilterInternal.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;
@@ -15,25 +12,24 @@ WPXSvInputStream::WPXSvInputStream( Reference< XInputStream > xStream ) :
mxChildStorage(),
mxChildStream(),
mxStream(xStream),
- mnOffset(0)
+ mxSeekable(xStream, UNO_QUERY),
+ maData(0)
{
- if (!xStream.is())
- {
+ if (!xStream.is() || !mxStream.is())
mnLength = 0;
- }
else
{
- Reference < XSeekable> xSeekable = Reference < XSeekable > (xStream, UNO_QUERY);
- if (!xSeekable.is())
+ if (!mxSeekable.is())
mnLength = 0;
else
{
try
{
- mnLength = xSeekable->getLength(); // exception
+ mnLength = mxSeekable->getLength();
}
catch ( ... )
{
+ WRITER_DEBUG_MSG(("mnLength = mxSeekable->getLength() threw exception\n"));
mnLength = 0;
}
}
@@ -46,83 +42,123 @@ WPXSvInputStream::~WPXSvInputStream()
const uint8_t * WPXSvInputStream::read(size_t numBytes, size_t &numBytesRead)
{
- // FIXME: assume no short reads (?)
- sal_Int64 oldMnOffset = mnOffset;
- mnOffset += mxStream->readBytes (maData, numBytes);
- numBytesRead = mnOffset - oldMnOffset;
+ numBytesRead = 0;
+
+ if (numBytes == 0 || atEOS())
+ return 0;
+
+ numBytesRead = mxStream->readSomeBytes (maData, numBytes);
+ if (numBytesRead == 0)
+ return 0;
+
return (const uint8_t *)maData.getConstArray();
}
-int WPXSvInputStream::seek(long offset, WPX_SEEK_TYPE seekType)
+long WPXSvInputStream::tell()
{
- if (seekType == WPX_SEEK_CUR && offset >= 0)
- {
- if (mnOffset + offset <= mnLength)
- {
- mxStream->skipBytes (offset); // exception ?
- mnOffset += offset;
- return FALSE;
- }
- else
- return TRUE;
- }
- Reference < XSeekable> xSeekable = Reference < XSeekable >(mxStream, UNO_QUERY);
-
- if (!xSeekable.is())
- return TRUE;
-
- if (seekType == WPX_SEEK_CUR)
- mnOffset += offset;
+ if ((mnLength == 0) || !mxStream.is() || !mxSeekable.is())
+ return -1L;
else
- mnOffset = offset;
+ return (long)mxSeekable->getPosition();
+}
- if (mnOffset > mnLength)
- return TRUE;
+int WPXSvInputStream::seek(long offset, WPX_SEEK_TYPE seekType)
+{
+ if ((mnLength == 0) || !mxStream.is() || !mxSeekable.is())
+ return -1;
- xSeekable->seek(mnOffset); // FIXME: catch exception!
+ sal_Int64 tmpPosition = mxSeekable->getPosition();
+ if (seekType == WPX_SEEK_CUR)
+ offset += tmpPosition;
- return FALSE;
-}
+ int retVal = 0;
+ if (offset < 0)
+ {
+ offset = 0;
+ retVal = -1;
+ }
+ if (offset > mnLength)
+ {
+ offset = mnLength;
+ retVal = -1;
+ }
-long WPXSvInputStream::tell()
-{
- return mnOffset;
+ try
+ {
+ mxSeekable->seek(offset);
+ return retVal;
+ }
+ catch (...)
+ {
+ WRITER_DEBUG_MSG(("mxSeekable->seek(offset) threw exception\n"));
+ return -1;
+ }
}
bool WPXSvInputStream::atEOS()
{
- return mnOffset >= mnLength;
+ if ((mnLength == 0) || !mxStream.is() || !mxSeekable.is())
+ return true;
+ return (mxSeekable->getPosition() >= mnLength);
}
bool WPXSvInputStream::isOLEStream()
{
- bool bAns;
+ if ((mnLength == 0) || !mxStream.is() || !mxSeekable.is())
+ return false;
+
+ sal_Int64 tmpPosition = mxSeekable->getPosition();
+ mxSeekable->seek(0);
SvStream *pStream = utl::UcbStreamHelper::CreateStream( mxStream );
- bAns = pStream && SotStorage::IsOLEStorage( pStream );
- delete pStream;
+ bool bAns = pStream && SotStorage::IsOLEStorage( pStream );
+ if (pStream)
+ delete pStream;
- seek (0, WPX_SEEK_SET);
+ mxSeekable->seek(tmpPosition);
return bAns;
}
-WPXInputStream * WPXSvInputStream::getDocumentOLEStream()
+WPXInputStream * WPXSvInputStream::getDocumentOLEStream(const char * name)
{
+ if ((mnLength == 0) || !mxStream.is() || !mxSeekable.is())
+ return 0;
+
+ sal_Int64 tmpPosition = mxSeekable->getPosition();
+ mxSeekable->seek(0);
+
SvStream *pStream = utl::UcbStreamHelper::CreateStream( mxStream );
+ if (!pStream || !SotStorage::IsOLEStorage( pStream ))
+ {
+ mxSeekable->seek(tmpPosition);
+ return 0;
+ }
+
mxChildStorage = new SotStorage( pStream, TRUE );
mxChildStream = mxChildStorage->OpenSotStream(
- rtl::OUString::createFromAscii( "PerfectOffice_MAIN" ),
+ rtl::OUString::createFromAscii( name ),
STREAM_STD_READ );
+ mxSeekable->seek(tmpPosition);
+
if ( !mxChildStream.Is() || mxChildStream->GetError() )
- return NULL;
+ {
+ mxSeekable->seek(tmpPosition);
+ return 0;
+ }
- Reference < XInputStream > xContents = new utl::OSeekableInputStreamWrapper( mxChildStream );
+ Reference < XInputStream > xContents(new utl::OSeekableInputStreamWrapper( mxChildStream ));
+ mxSeekable->seek(tmpPosition);
if (xContents.is())
return new WPXSvInputStream( xContents );
else
- return NULL;
+ return 0;
+}
+
+WPXInputStream * WPXSvInputStream::getDocumentOLEStream()
+{
+ return getDocumentOLEStream( "PerfectOffice_MAIN" );
}