20#include <com/sun/star/io/XInputStream.hpp>
21#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22#include <com/sun/star/ucb/XCommandEnvironment.hpp>
23#include <com/sun/star/uno/Reference.hxx>
24#include <com/sun/star/uno/XComponentContext.hpp>
33#if OSL_DEBUG_LEVEL > 0
36#include <com/sun/star/io/XOutputStream.hpp>
37#include <com/sun/star/xml/sax/Writer.hpp>
43#include <osl/file.hxx>
49using com::sun::star::uno::Any;
50using com::sun::star::uno::UNO_QUERY;
51using com::sun::star::uno::Exception;
52using com::sun::star::io::XInputStream;
53using com::sun::star::beans::PropertyValue;
54using com::sun::star::ucb::XCommandEnvironment;
55using com::sun::star::document::XImporter;
56using com::sun::star::xml::sax::XDocumentHandler;
58#if OSL_DEBUG_LEVEL > 0
62class DebugDocumentHandler final :
public cppu::WeakImplHelper< XDocumentHandler >
65 DebugDocumentHandler(uno::Reference< XDocumentHandler > handler, uno::Reference< XDocumentHandler > debug)
66 : m_handler(
std::move(handler))
67 , m_debug(
std::move(debug))
74 startDocument()
override
76 m_handler->startDocument();
77 m_debug->startDocument();
81 endDocument()
override
83 m_handler->endDocument();
84 m_debug->endDocument();
89 const OUString& aName,
90 const uno::Reference< xml::sax::XAttributeList > & xAttribs)
override
92 m_handler->startElement(aName, xAttribs);
93 m_debug->ignorableWhitespace(
" ");
94 m_debug->startElement(aName, xAttribs);
98 endElement(
const OUString& aName)
override
100 m_handler->endElement(aName);
101 m_debug->ignorableWhitespace(
" ");
102 m_debug->endElement(aName);
105 virtual void SAL_CALL
106 characters(
const OUString& aChars)
override
108 m_handler->characters(aChars);
109 m_debug->characters(aChars);
112 virtual void SAL_CALL
113 ignorableWhitespace(
const OUString& aWhitespaces)
override
115 m_handler->ignorableWhitespace(aWhitespaces);
116 m_debug->ignorableWhitespace(aWhitespaces);
119 virtual void SAL_CALL
120 processingInstruction(
const OUString& aTarget,
const OUString& aData)
override
122 m_handler->processingInstruction(aTarget, aData);
123 m_debug->processingInstruction(aTarget, aData);
126 virtual void SAL_CALL
127 setDocumentLocator(
const uno::Reference< xml::sax::XLocator >& xLocator)
override
129 m_handler->setDocumentLocator(xLocator);
130 m_debug->setDocumentLocator(xLocator);
137 uno::Any aIface = cppu::WeakImplHelper< XDocumentHandler >::queryInterface(rType);
139 if (!aIface.has< uno::Reference< uno::XInterface > >())
140 aIface = m_handler->queryInterface(rType);
145 uno::Reference< XDocumentHandler > m_handler;
146 uno::Reference< XDocumentHandler > m_debug;
158 for (
const PropertyValue& rValue : aDescriptor)
161 if ( rValue.Name ==
"URL" )
162 rValue.Value >>= sURL;
166 if (!inputStream.
good())
170 uno::Reference< XDocumentHandler > xInternalHandler(
171 mxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.comp.Writer.XMLImporter",
mxContext ), UNO_QUERY );
173#if OSL_DEBUG_LEVEL > 0
174 std::unique_ptr<osl::File> pDebugFile;
175 const char* pDir = getenv(
"DBG_LWPIMPORT_DIR");
178 OUString
aStr(OStringToOUString(pDir, RTL_TEXTENCODING_UTF8));
180 osl_getFileURLFromSystemPath(
aStr.pData, &aFileURL.pData);
181 pDebugFile = std::make_unique<osl::File>(aFileURL +
"/lwpimport.xml");
182 if (pDebugFile->open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Create) != osl::File::E_None)
184 pDebugFile->open(osl_File_OpenFlag_Write);
185 pDebugFile->setSize(0);
188 uno::Reference< xml::sax::XWriter > xDebugWriter = xml::sax::Writer::create(
mxContext);
190 xDebugWriter->setOutputStream(xOutputStream);
192 xInternalHandler.set(
new DebugDocumentHandler(xInternalHandler, xDebugWriter));
196 uno::Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
198 xImporter->setTargetDocument(
mxDoc);
206 uno::Reference< XDocumentHandler > xHandler;
227 OUString sTypeName(
"writer_LotusWordPro_Document" );
229 uno::Reference < XInputStream > xInputStream;
230 for (
const PropertyValue& rValue : std::as_const(Descriptor))
232 if ( rValue.Name ==
"TypeName" )
233 rValue.Value >>= sTypeName;
234 else if ( rValue.Name ==
"InputStream" )
235 rValue.Value >>= xInputStream;
236 else if ( rValue.Name ==
"URL" )
237 rValue.Value >>= sURL;
240 uno::Reference< css::ucb::XCommandEnvironment > xEnv;
241 if (!xInputStream.is())
253 if (!xInputStream.is())
259 if ( ( nLen != xInputStream->readBytes(
aData, nLen ) )
260 || ( memcmp(
static_cast<void const *
>(
header),
static_cast<void const *
>(
aData.getConstArray()), nLen ) != 0 ) )
274 return "com.sun.star.comp.Writer.LotusWordProImportFilter";
284 return {
"com.sun.star.document.ImportFilter",
"com.sun.star.document.ExtendedTypeDetection" };
287extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
289 css::uno::XComponentContext *context,
290 css::uno::Sequence<css::uno::Any>
const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * LotusWordProImportFilter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr sal_Int8 header[]
SAL_DLLPUBLIC_EXPORT bool TestImportLWP(SvStream &rStream)
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
virtual OUString SAL_CALL detect(css::uno::Sequence< css::beans::PropertyValue > &Descriptor) override
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
bool importImpl(const css::uno::Sequence< css::beans::PropertyValue > &aDescriptor)
virtual sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &aDescriptor) override
css::uno::Reference< css::lang::XComponent > mxDoc
virtual void SAL_CALL cancel() override
css::uno::Reference< css::io::XInputStream > openStream()
int ReadWordproFile(SvStream &rStream, uno::Reference< css::xml::sax::XDocumentHandler > const &xHandler)
#define SAL_N_ELEMENTS(arr)
constexpr OUStringLiteral aData
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)