24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/document/XExporter.hpp>
26#include <com/sun/star/document/XFilter.hpp>
27#include <com/sun/star/document/XImporter.hpp>
28#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
29#include <com/sun/star/io/WrongFormatException.hpp>
30#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
31#include <com/sun/star/lang/XInitialization.hpp>
32#include <com/sun/star/lang/XMultiServiceFactory.hpp>
33#include <com/sun/star/xml/sax/SAXParseException.hpp>
55 OUString
const thisMessage(
"SAXParseException: \"" + e.Message +
"\"");
57 return restMessage +
"\n" + thisMessage;
61 OUString
const thisMessage(
"SAXParseException: '" + e.Message +
"', Stream '" + e.SystemId
62 +
"', Line " + OUString::number(e.LineNumber) +
", Column "
63 + OUString::number(e.ColumnNumber));
65 return restMessage +
"\n" + thisMessage;
70 xml::sax::SAXParseException saxpe;
71 if (e.WrappedException >>= saxpe)
75 xml::sax::SAXException saxe;
76 if (e.WrappedException >>= saxe)
81 if (e.WrappedException >>= ue)
92 :
public cppu::WeakImplHelper<document::XFilter, document::XImporter, document::XExporter,
93 lang::XInitialization, lang::XServiceInfo>
95 uno::Reference<uno::XComponentContext>
m_xContext;
96 uno::Reference<lang::XComponent> m_xSrcDoc, m_xDstDoc;
97 uno::Sequence<uno::Any> m_xInitializationArguments;
100 explicit WriterFilter(uno::Reference<uno::XComponentContext> xContext)
106 sal_Bool SAL_CALL
filter(
const uno::Sequence<beans::PropertyValue>& rDescriptor)
override;
107 void SAL_CALL cancel()
override;
110 void SAL_CALL setTargetDocument(
const uno::Reference<lang::XComponent>& xDoc)
override;
113 void SAL_CALL setSourceDocument(
const uno::Reference<lang::XComponent>& xDoc)
override;
116 void SAL_CALL initialize(
const uno::Sequence<uno::Any>& rArguments)
override;
125sal_Bool WriterFilter::filter(
const uno::Sequence<beans::PropertyValue>& rDescriptor)
129 uno::Reference<lang::XMultiServiceFactory> xMSF(
m_xContext->getServiceManager(),
130 uno::UNO_QUERY_THROW);
131 uno::Reference<uno::XInterface> xIfc;
134 xIfc.set(xMSF->createInstance(
"com.sun.star.comp.Writer.DocxExport"),
137 catch (uno::RuntimeException&)
141 catch (uno::Exception& e)
144 throw lang::WrappedTargetRuntimeException(
"wrapped " +
a.getValueTypeName() +
": "
146 uno::Reference<uno::XInterface>(), a);
149 uno::Reference<lang::XInitialization> xInit(xIfc, uno::UNO_QUERY_THROW);
150 xInit->initialize(m_xInitializationArguments);
152 uno::Reference<document::XExporter> xExprtr(xIfc, uno::UNO_QUERY_THROW);
153 uno::Reference<document::XFilter> xFltr(xIfc, uno::UNO_QUERY_THROW);
154 xExprtr->setSourceDocument(m_xSrcDoc);
155 return xFltr->filter(rDescriptor);
159 uno::Reference<beans::XPropertySet>
const xDocProps(m_xDstDoc, uno::UNO_QUERY);
160 xDocProps->setPropertyValue(
"UndocumentedWriterfilterHack",
uno::Any(
true));
162 xDocProps->setPropertyValue(
"UndocumentedWriterfilterHack",
uno::Any(
false));
165 bool bRepairStorage = aMediaDesc.getUnpackedValueOrDefault(
"RepairPackage",
false);
167 = aMediaDesc.getUnpackedValueOrDefault(
"FilterOptions", OUString()) ==
"SkipImages";
169 uno::Reference<io::XInputStream> xInputStream;
174 new ::oox::core::FilterDetect(m_xContext));
175 xInputStream = xDetector->extractUnencryptedPackage(aMediaDesc);
177 catch (uno::Exception&)
181 if (!xInputStream.is())
186 m_xContext, xInputStream, m_xDstDoc, bRepairStorage,
192 uno::Reference<task::XStatusIndicator> xStatusIndicator
194 uno::Reference<task::XStatusIndicator>());
197 bSkipImages, rDescriptor));
199 uno::Reference<frame::XModel>
xModel(m_xDstDoc, uno::UNO_QUERY_THROW);
200 pDocument->setModel(xModel);
202 uno::Reference<drawing::XDrawPageSupplier> xDrawings(m_xDstDoc, uno::UNO_QUERY_THROW);
203 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawings->getDrawPage(), uno::UNO_SET_THROW);
204 pDocument->setDrawPage(xDrawPage);
208 pDocument->resolve(*pStream);
210 catch (xml::sax::SAXParseException
const& e)
214 throw lang::WrappedTargetRuntimeException(
"", getXWeak(),
uno::Any(wfe));
216 catch (xml::sax::SAXException
const& e)
220 throw lang::WrappedTargetRuntimeException(
"", getXWeak(),
uno::Any(wfe));
222 catch (uno::RuntimeException
const&)
226 catch (uno::Exception
const&)
231 throw lang::WrappedTargetRuntimeException(
"", getXWeak(), anyEx);
238 aGrabBagProperties[
"OOXTheme"] <<= pDocument->getThemeDom();
241 aGrabBagProperties[
"OOXCustomXml"] <<= pDocument->getCustomXmlDomList();
242 aGrabBagProperties[
"OOXCustomXmlProps"] <<= pDocument->getCustomXmlDomPropsList();
245 aGrabBagProperties[
"OOXGlossary"] <<= pDocument->getGlossaryDocDom();
246 aGrabBagProperties[
"OOXGlossaryDom"] <<= pDocument->getGlossaryDomList();
249 aGrabBagProperties[
"OOXEmbeddings"] <<= pDocument->getEmbeddingsList();
256 oox::StorageRef xVbaPrjStrg = std::make_shared<::oox::ole::OleStorage>(
257 m_xContext, pVBAProjectStream->getDocumentStream(),
false);
258 if (xVbaPrjStrg && xVbaPrjStrg->isStorage())
261 uno::Reference<frame::XFrame>
xFrame = aMediaDesc.getUnpackedValueOrDefault(
272 aVbaProject.importVbaProject(*xVbaPrjStrg, gHelper);
279 uno::Reference<io::XInputStream> xDataStream = pVBADataStream->getDocumentStream();
280 if (xDataStream.is())
281 aVbaProject.importVbaData(xDataStream);
294void WriterFilter::cancel() {}
296void WriterFilter::setTargetDocument(
const uno::Reference<lang::XComponent>& xDoc)
301 uno::Reference<lang::XMultiServiceFactory>
xFactory(xDoc, uno::UNO_QUERY);
302 uno::Reference<beans::XPropertySet> xSettings(
303 xFactory->createInstance(
"com.sun.star.document.Settings"), uno::UNO_QUERY);
305 xSettings->setPropertyValue(
"AddVerticalFrameOffsets",
uno::Any(
true));
306 xSettings->setPropertyValue(
"UseOldNumbering",
uno::Any(
false));
307 xSettings->setPropertyValue(
"IgnoreFirstLineIndentInNumbering",
uno::Any(
false));
308 xSettings->setPropertyValue(
"DoNotResetParaAttrsForNumFont",
uno::Any(
false));
309 xSettings->setPropertyValue(
"UseFormerLineSpacing",
uno::Any(
false));
310 xSettings->setPropertyValue(
"AddParaSpacingToTableCells",
uno::Any(
true));
311 xSettings->setPropertyValue(
"AddParaLineSpacingToTableCells",
uno::Any(
true));
312 xSettings->setPropertyValue(
"UseFormerObjectPositioning",
uno::Any(
false));
313 xSettings->setPropertyValue(
"ConsiderTextWrapOnObjPos",
uno::Any(
true));
314 xSettings->setPropertyValue(
"UseFormerTextWrapping",
uno::Any(
false));
315 xSettings->setPropertyValue(
"IgnoreTabsAndBlanksForLineCalculation",
uno::Any(
true));
316 xSettings->setPropertyValue(
"InvertBorderSpacing",
uno::Any(
true));
317 xSettings->setPropertyValue(
"CollapseEmptyCellPara",
uno::Any(
true));
322 xSettings->setPropertyValue(
"TabOverSpacing",
uno::Any(
true));
323 xSettings->setPropertyValue(
"UnbreakableNumberings",
uno::Any(
true));
325 xSettings->setPropertyValue(
"FloattableNomargins",
uno::Any(
true));
326 xSettings->setPropertyValue(
"ClippedPictures",
uno::Any(
true));
327 xSettings->setPropertyValue(
"BackgroundParaOverDrawings",
uno::Any(
true));
328 xSettings->setPropertyValue(
"TreatSingleColumnBreakAsPageBreak",
uno::Any(
true));
329 xSettings->setPropertyValue(
"PropLineSpacingShrinksFirstLine",
uno::Any(
true));
330 xSettings->setPropertyValue(
"DoNotCaptureDrawObjsOnPage",
uno::Any(
true));
331 xSettings->setPropertyValue(
"DisableOffPagePositioning",
uno::Any(
true));
332 xSettings->setPropertyValue(
"DropCapPunctuation",
uno::Any(
true));
336void WriterFilter::setSourceDocument(
const uno::Reference<lang::XComponent>& xDoc)
341void WriterFilter::initialize(
const uno::Sequence<uno::Any>& rArguments)
343 m_xInitializationArguments = rArguments;
346OUString WriterFilter::getImplementationName() {
return "com.sun.star.comp.Writer.WriterFilter"; }
348sal_Bool WriterFilter::supportsService(
const OUString& rServiceName)
353uno::Sequence<OUString> WriterFilter::getSupportedServiceNames()
355 uno::Sequence<OUString> aRet = { OUString(
"com.sun.star.document.ImportFilter"),
356 OUString(
"com.sun.star.document.ExportFilter") };
360extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
362 uno::XComponentContext* component, uno::Sequence<uno::Any>
const& )
364 return cppu::acquire(
new WriterFilter(component));
Reference< XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Writer_WriterFilter_get_implementation(uno::XComponentContext *component, uno::Sequence< uno::Any > const &)
static OUString lcl_GetExceptionMessageRec(xml::sax::SAXException const &e)
static OUString lcl_GetExceptionMessage(xml::sax::SAXException const &e)
static void putPropertiesToDocumentGrabBag(const css::uno::Reference< css::lang::XComponent > &xDstDoc, const comphelper::SequenceAsHashMap &rProperties)
static Stream::Pointer_t createMapper(css::uno::Reference< css::uno::XComponentContext > const &xContext, css::uno::Reference< css::io::XInputStream > const &xInputStream, css::uno::Reference< css::lang::XComponent > const &xModel, bool bRepairStorage, SourceDocumentType eDocumentType, utl::MediaDescriptor const &rMediaDesc)
static OOXMLStream::Pointer_t createStream(const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Reference< css::io::XInputStream > &rStream, bool bRepairStorage)
static OOXMLDocument * createDocument(const OOXMLStream::Pointer_t &pStream, const css::uno::Reference< css::task::XStatusIndicator > &xStatusIndicator, bool bSkipImage, const css::uno::Sequence< css::beans::PropertyValue > &rDescriptor)
OString exceptionToString(const css::uno::Any &caught)
Reference< XSingleServiceFactory > xFactory
#define SAL_WARN(area, stream)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Any SAL_CALL getCaughtException()
std::shared_ptr< StorageBase > StorageRef
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel