Bug n#90666

** Chasing xhtml (non) exporting: generating a 0 length file:

filter/source/xmlfilteradaptor/XmlFilterAdaptor.cxx:
    + (exporter)
      + calls '::exporter' on xsltfilter/XSLTFilter.cxx
      + then creates an 'XExporter/XFilter'
	    + [ com.sun.star.comp.Writer.XMLExporter ]
	    + calls 'filter' & problems occur ...

    + Everything goes really nicely until:
	XSLTransformer.java:
	    xostream.writeBytes(resultbuf.toByteArray());
	we get an:
	   com.sun.star.io.BufferSizeExceededException: 
	   [ an OO.o exception ]
	   
BufferSizeExceededException: thrown by:
     so3/source/persist/transprt.cxx, line 1192
     ucb/source/ucp/file/filstr.cxx, line 228
     comphelper/source/streaming/oslfile2streamwrap.cxx, line 93
     comphelper/source/streaming/seqstream.cxx, line 137
     configmgr/source/backend/binaryreader.cxx, line 254
     io/source/stm/omark.cxx, line 669
     sot/source/sdstor/ucbstorage.cxx, line 233
     svtools/source/misc/strmadpt.cxx, line 413
     unotools/source/streaming/streamhelper.cxx, line 89 [!]
     unotools/source/streaming/streamwrap.cxx, line 140  [!]
     unotools/source/ucbhelper/xtempfile.cxx, line 175   [!]
     package/source/zipapi/EntryInputStream.cxx, line 127
     package/source/zippackage/ZipPackageBuffer.cxx, line 93
     filter/source/xmlfilteradaptor/streamwrap.cxx, line 102 [!]
     
     Most likely candidate:
          io/source/stm/opipe.cxx, line 387

     Unfortunately - we don't hit opipe.cxx 'writeBytes' where
     we throw the exception ie.

	System.out.println("XSLTransformer: D - size bytes " +
			   resultbuf.toByteArray().length);
	try {
	    xostream.writeBytes(resultbuf.toByteArray());
	} catch (java.lang.Throwable ex) {
	    System.out.println ("Failed to write bytes " + ex);
	}

    Deep evilness gives us:

XSLTransformer: D - size bytes 1354
Failed to write bytes com.sun.star.io.BufferSizeExceededException: 

       This turns out to be from:

unohelper::OOutputStreamWrapper::writeBytes 1369 bytes
Tried to write 1352 bytes wrote 0 -> errcode 3088 (0xc10) throw BufferSizefoo
    + not the xmltransformerhelper stream thing ...
	[ why is there a duplicate foo::OOutputStreamWrapper ? ]

unotools/source/streaming/streamwrap.cxx, line 140  [!]

errorcodes in tools/inc/errcode.hxx 0xc10
#define ERRCODE_CLASS_SHIFT               8

0xc10 == (<ERRCODE_CLASS_WRITE> << 8) | ERRCODE_IO_CANTWRITE ...

      Why can't we write ?


** Most likely the OOutputStreamWrapper holds a reference to a stream
that no longer exists:

sfx2/source/objstor.cxx (ExportTo):
    pNewValue[i].Name = sOutputStream;
    pNewValue[i].Value <<= com::sun::star::uno::Reference < com::sun::star::io::XOutputStream > ( new utl::OOutputStreamWrapper ( *rMedium.GetOutStream() ) );
...
    return xFilter->filter( aArgs );

And at some stage *rMedium.GetOutStream() goes away ...

* Can we add an 'waitCompleted' method to XExportFilter ...
    + it's what we need ...

* 'endDocument' is called:    
    + we wait for m_cTransformed ...
    + however - it gets signalled far, far too early...