summaryrefslogtreecommitdiff
path: root/lotuswordpro
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2021-02-13 15:51:20 +0100
committerDavid Tardon <dtardon@redhat.com>2021-02-21 16:23:39 +0100
commit301b09f0c4fef6fca52fa0b28827a657bbbb6b39 (patch)
treea982687cc5dbafe42046e6247714019d4cff24cb /lotuswordpro
parent78040af9acea0ab681aa54ff23844b647bc9b4f3 (diff)
lotuswordpro: allow to dump intermediate XML into file
If env. variable DBG_LWPIMPORT_DIR= is set to an existing directory, a formatted representation of the intermediate XML format is dumped into a file named lwpimport.xml in that directory. This makes debugging of Lotus Word Pro import a lot easier. Change-Id: I872c388c2b378d55f476973890a073ec932e1b4b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111283 Tested-by: Jenkins Reviewed-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'lotuswordpro')
-rw-r--r--lotuswordpro/source/filter/LotusWordProImportFilter.cxx131
1 files changed, 131 insertions, 0 deletions
diff --git a/lotuswordpro/source/filter/LotusWordProImportFilter.cxx b/lotuswordpro/source/filter/LotusWordProImportFilter.cxx
index 73335e0bab88..296561bcc375 100644
--- a/lotuswordpro/source/filter/LotusWordProImportFilter.cxx
+++ b/lotuswordpro/source/filter/LotusWordProImportFilter.cxx
@@ -30,6 +30,19 @@
#include "LotusWordProImportFilter.hxx"
#include "lwpfilter.hxx"
+#if OSL_DEBUG_LEVEL > 0
+#include <memory>
+
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/xml/sax/Writer.hpp>
+
+#include <comphelper/oslfile2streamwrap.hxx>
+
+#include <cppuhelper/weak.hxx>
+
+#include <osl/file.hxx>
+#endif
+
using namespace com::sun::star;
using com::sun::star::uno::Sequence;
using com::sun::star::uno::Any;
@@ -41,6 +54,100 @@ using com::sun::star::ucb::XCommandEnvironment;
using com::sun::star::document::XImporter;
using com::sun::star::xml::sax::XDocumentHandler;
+#if OSL_DEBUG_LEVEL > 0
+namespace
+{
+
+class DebugDocumentHandler final : public cppu::WeakImplHelper< XDocumentHandler >
+{
+public:
+ DebugDocumentHandler(const uno::Reference< XDocumentHandler >& handler, const uno::Reference< XDocumentHandler >& debug)
+ : m_handler(handler)
+ , m_debug(debug)
+ {
+ }
+
+ // XDocumentHandler
+
+ virtual void SAL_CALL
+ startDocument() override
+ {
+ m_handler->startDocument();
+ m_debug->startDocument();
+ }
+
+ virtual void SAL_CALL
+ endDocument() override
+ {
+ m_handler->endDocument();
+ m_debug->endDocument();
+ }
+
+ virtual void SAL_CALL
+ startElement(
+ const OUString& aName,
+ const uno::Reference< xml::sax::XAttributeList > & xAttribs) override
+ {
+ m_handler->startElement(aName, xAttribs);
+ m_debug->ignorableWhitespace(" "); // NOTE: needed for pretty-printing
+ m_debug->startElement(aName, xAttribs);
+ }
+
+ virtual void SAL_CALL
+ endElement(const OUString& aName) override
+ {
+ m_handler->endElement(aName);
+ m_debug->ignorableWhitespace(" "); // NOTE: needed for pretty-printing
+ m_debug->endElement(aName);
+ }
+
+ virtual void SAL_CALL
+ characters(const OUString& aChars) override
+ {
+ m_handler->characters(aChars);
+ m_debug->characters(aChars);
+ }
+
+ virtual void SAL_CALL
+ ignorableWhitespace(const OUString& aWhitespaces) override
+ {
+ m_handler->ignorableWhitespace(aWhitespaces);
+ m_debug->ignorableWhitespace(aWhitespaces);
+ }
+
+ virtual void SAL_CALL
+ processingInstruction(const OUString& aTarget, const OUString& aData) override
+ {
+ m_handler->processingInstruction(aTarget, aData);
+ m_debug->processingInstruction(aTarget, aData);
+ }
+
+ virtual void SAL_CALL
+ setDocumentLocator(const uno::Reference< xml::sax::XLocator >& xLocator) override
+ {
+ m_handler->setDocumentLocator(xLocator);
+ m_debug->setDocumentLocator(xLocator);
+ }
+
+ // XInterface
+
+ virtual uno::Any SAL_CALL queryInterface(const uno::Type & rType) override
+ {
+ uno::Any aIface = cppu::WeakImplHelper< XDocumentHandler >::queryInterface(rType);
+ // delegate all queries we cannot satisfy ourselves to the real handler
+ if (!aIface.has< uno::Reference< uno::XInterface > >())
+ aIface = m_handler->queryInterface(rType);
+ return aIface;
+ }
+
+private:
+ uno::Reference< XDocumentHandler > m_handler;
+ uno::Reference< XDocumentHandler > m_debug;
+};
+
+}
+#endif
+
// W o r d P r o
const sal_Int8 header[] = { 0x57, 0x6f, 0x72, 0x64, 0x50, 0x72, 0x6f };
@@ -61,6 +168,30 @@ bool LotusWordProImportFilter::importImpl( const Sequence< css::beans::PropertyV
// An XML import service: what we push sax messages to...
uno::Reference< XDocumentHandler > xInternalHandler(
mxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.comp.Writer.XMLImporter", mxContext ), UNO_QUERY );
+
+#if OSL_DEBUG_LEVEL > 0
+ std::unique_ptr<osl::File> pDebugFile;
+ const char* pDir = getenv("DBG_LWPIMPORT_DIR");
+ if (pDir)
+ {
+ OUString aStr(OStringToOUString(pDir, RTL_TEXTENCODING_UTF8));
+ OUString aFileURL;
+ osl_getFileURLFromSystemPath(aStr.pData, &aFileURL.pData);
+ pDebugFile = std::make_unique<osl::File>(aFileURL + "/lwpimport.xml");
+ if (pDebugFile->open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Create) != osl::File::E_None)
+ {
+ pDebugFile->open(osl_File_OpenFlag_Write);
+ pDebugFile->setSize(0);
+ }
+
+ uno::Reference< xml::sax::XWriter > xDebugWriter = xml::sax::Writer::create(mxContext);
+ uno::Reference< io::XOutputStream > xOutputStream(new comphelper::OSLOutputStreamWrapper(*pDebugFile));
+ xDebugWriter->setOutputStream(xOutputStream);
+
+ xInternalHandler.set(new DebugDocumentHandler(xInternalHandler, xDebugWriter));
+ }
+#endif
+
uno::Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
if (xImporter.is())
xImporter->setTargetDocument(mxDoc);