20#include <com/sun/star/embed/XStorage.hpp>
21#include <com/sun/star/embed/ElementModes.hpp>
22#include <com/sun/star/beans/PropertyAttribute.hpp>
23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <com/sun/star/task/XStatusIndicator.hpp>
25#include <com/sun/star/xml/sax/Writer.hpp>
26#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
27#include <com/sun/star/document/XExporter.hpp>
28#include <com/sun/star/document/XFilter.hpp>
29#include <com/sun/star/frame/XModule.hpp>
31#include <officecfg/Office/Common.hxx>
37#include <osl/diagnose.h>
44#include <sfx2/sfxsids.hrc>
64#include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
84 uno::Reference<task::XStatusIndicator> xStatusIndicator;
85 OUString aDocHierarchicalName;
91 pMediumItemSet->
GetItem(SID_PROGRESS_STATUSBAR_CONTROL);
93 pStatusBarItem->
GetValue() >>= xStatusIndicator;
95 pMediumItemSet->
GetItem(SID_DOC_HIERARCHICALNAME);
97 aDocHierarchicalName = pDocHierarchItem->
GetValue();
104 uno::Reference< uno::XComponentContext > xContext =
108 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
110 uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
113 OSL_ENSURE(
m_xStg.is(),
"Where is my storage?" );
115 SvXMLGraphicHelperMode::Write );
116 xGraphicStorageHandler = xGraphicHelper.get();
123 SvXMLEmbeddedObjectHelperMode::Write );
124 xObjectResolver = xObjectHelper.get();
134 { OUString(
"ProgressRange"), 0,
136 beans::PropertyAttribute::MAYBEVOID, 0},
137 { OUString(
"ProgressMax"), 0,
139 beans::PropertyAttribute::MAYBEVOID, 0},
140 { OUString(
"ProgressCurrent"), 0,
142 beans::PropertyAttribute::MAYBEVOID, 0},
143 { OUString(
"WrittenNumberStyles"), 0,
145 beans::PropertyAttribute::MAYBEVOID, 0},
146 { OUString(
"UsePrettyPrinting"), 0,
148 beans::PropertyAttribute::MAYBEVOID, 0},
149 { OUString(
"ShowChanges"), 0,
151 beans::PropertyAttribute::MAYBEVOID, 0 },
152 { OUString(
"RedlineProtectionKey"), 0,
154 beans::PropertyAttribute::MAYBEVOID, 0 },
155 { OUString(
"BaseURI"), 0,
157 beans::PropertyAttribute::MAYBEVOID, 0 },
158 { OUString(
"StreamRelPath"), 0,
160 beans::PropertyAttribute::MAYBEVOID, 0 },
161 { OUString(
"StreamName"), 0,
163 beans::PropertyAttribute::MAYBEVOID, 0 },
164 { OUString(
"AutoTextMode"), 0,
166 beans::PropertyAttribute::MAYBEVOID, 0 },
167 { OUString(
"StyleNames"), 0,
169 beans::PropertyAttribute::MAYBEVOID, 0 },
170 { OUString(
"StyleFamilies"), 0,
172 beans::PropertyAttribute::MAYBEVOID, 0 },
174 { OUString(
"OutlineStyleAsNormalListStyle"), 0,
176 beans::PropertyAttribute::MAYBEVOID, 0 },
178 css::beans::PropertyAttribute::MAYBEVOID, 0 },
180 { OUString(
"NoEmbDataSet"), 0,
182 beans::PropertyAttribute::MAYBEVOID, 0 },
184 uno::Reference< beans::XPropertySet > xInfoSet(
188 xInfoSet->setPropertyValue(
"TargetStorage",
Any(
m_xStg ) );
190 xInfoSet->setPropertyValue(
"NoEmbDataSet",
Any(bNoEmbDS));
195 sal_Int32 nProgressRange(1000000);
196 if (xStatusIndicator.is())
198 xStatusIndicator->start(
SwResId( STR_STATSTR_SWGWRITE),
201 xInfoSet->setPropertyValue(
"ProgressRange",
Any(nProgressRange));
203 xInfoSet->setPropertyValue(
"ProgressMax",
Any(
static_cast < sal_Int32
>( -1 )));
209 uno::Reference<drawing::XDrawPageSupplier>
const xDPS(xModelComp, uno::UNO_QUERY);
220 xInfoSet->setPropertyValue(
"ShowChanges",
Any(isShowChanges));
227 xInfoSet->setPropertyValue(
"BaseURI",
Any(
GetBaseURL() ) );
231 const OUString
aName( !aDocHierarchicalName.isEmpty()
232 ? aDocHierarchicalName
233 : OUString(
"dummyObjectName" ) );
235 xInfoSet->setPropertyValue(
"StreamRelPath",
Any(
aName ) );
240 xInfoSet->setPropertyValue(
"AutoTextMode",
Any(
true) );
248 xInfoSet->setPropertyValue(
"OutlineStyleAsNormalListStyle",
Any(
true ) );
257 if( xStatusIndicator.is() )
260 Sequence < Any > aEmptyArgs( nArgs );
261 Any *pArgs = aEmptyArgs.getArray();
262 *pArgs++ <<= xInfoSet;
263 if( xStatusIndicator.is() )
264 *pArgs++ <<= xStatusIndicator;
266 if( xGraphicStorageHandler.is() )
268 if( xObjectResolver.is() )
271 Sequence < Any > aFilterArgs( nArgs );
272 pArgs = aFilterArgs.getArray();
273 *pArgs++ <<= xInfoSet;
274 if( xGraphicStorageHandler.is() )
275 *pArgs++ <<= xGraphicStorageHandler;
276 if( xObjectResolver.is() )
277 *pArgs++ <<= xObjectResolver;
278 if( xStatusIndicator.is() )
279 *pArgs++ <<= xStatusIndicator;
288 PropertyValue *pProps = aProps.getArray();
289 pProps->Name =
"FileName";
300 const uno::Reference<beans::XPropertySet> xPropSet(
m_xStg,
301 uno::UNO_QUERY_THROW);
306 if ((xPropSet->getPropertyValue(
"Version") >>=
Version)
310 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
311 xModelComp, uno::UNO_QUERY_THROW);
312 xDMA->storeMetadataToStorage(
m_xStg);
315 catch (beans::UnknownPropertyException &)
317 catch (uno::Exception &)
328 Reference< frame::XModule > xModule( xModelComp, UNO_QUERY );
331 const OUString aModuleID = xModule->getIdentifier();
332 bStoreMeta = !aModuleID.isEmpty() &&
333 ( aModuleID ==
"com.sun.star.sdb.FormDesign" ||
334 aModuleID ==
"com.sun.star.sdb.TextReportDesign" );
337 catch( uno::Exception& )
345 xModelComp,
"meta.xml", xContext,
346 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisMetaExporter"
347 :
"com.sun.star.comp.Writer.XMLMetaExporter"),
348 aEmptyArgs, aProps ) )
351 sWarnFile =
"meta.xml";
358 xModelComp,
"settings.xml", xContext,
359 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisSettingsExporter"
360 :
"com.sun.star.comp.Writer.XMLSettingsExporter"),
361 aEmptyArgs, aProps ) )
366 sWarnFile =
"settings.xml";
375 xModelComp,
"styles.xml", xContext,
376 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisStylesExporter"
377 :
"com.sun.star.comp.Writer.XMLStylesExporter"),
378 aFilterArgs, aProps ) )
381 sErrFile =
"styles.xml";
387 xModelComp,
"content.xml", xContext,
388 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisContentExporter"
389 :
"com.sun.star.comp.Writer.XMLContentExporter"),
390 aFilterArgs, aProps ) )
393 sErrFile =
"content.xml";
404 uno::Reference < io::XStream > xStm =
m_xStg->openStreamElement(
"layout-cache", embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
406 if( !pStream->GetError() )
408 uno::Reference < beans::XPropertySet > xSet( xStm, UNO_QUERY );
410 aAny2 <<= OUString(
"application/binary");
411 xSet->setPropertyValue(
"MediaType", aAny2 );
415 catch ( uno::Exception& )
421 xGraphicHelper->dispose();
422 xGraphicHelper.clear();
423 xGraphicStorageHandler =
nullptr;
426 xObjectHelper->dispose();
427 xObjectHelper.clear();
428 xObjectResolver =
nullptr;
440 if (xStatusIndicator.is())
442 xStatusIndicator->end();
447 if( !sErrFile.isEmpty() )
449 DialogMask::ButtonsOk | DialogMask::MessageError );
454 if( !sWarnFile.isEmpty() )
456 DialogMask::ButtonsOk | DialogMask::MessageError );
474 const OUString* pFileName )
482 const uno::Reference<XComponent> & xComponent,
483 const char* pStreamName,
484 const uno::Reference<uno::XComponentContext> & rxContext,
485 const char* pServiceName,
486 const Sequence<Any> & rArguments,
487 const Sequence<beans::PropertyValue> & rMediaDesc )
489 OSL_ENSURE(
m_xStg.is(),
"Need storage!" );
490 OSL_ENSURE(
nullptr != pStreamName,
"Need stream name!" );
491 OSL_ENSURE(
nullptr != pServiceName,
"Need service name!" );
493 SAL_INFO(
"sw.filter",
"SwXMLWriter::WriteThroughComponent : stream " << pStreamName );
498 const OUString sStreamName = OUString::createFromAscii( pStreamName );
499 uno::Reference<io::XStream>
xStream =
500 m_xStg->openStreamElement( sStreamName,
501 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
503 uno::Reference <beans::XPropertySet > xSet( xStream, uno::UNO_QUERY );
507 xSet->setPropertyValue(
"MediaType",
Any(OUString(
"text/xml")) );
510 xSet->setPropertyValue(
"UseCommonStoragePasswordEncryption",
Any(
true) );
513 uno::Reference< io::XOutputStream > xOutputStream =
xStream->getOutputStream();
516 uno::Reference< beans::XPropertySet > xInfoSet;
517 if( rArguments.hasElements() )
518 rArguments.getConstArray()[0] >>= xInfoSet;
519 OSL_ENSURE( xInfoSet.is(),
"missing property set" );
522 xInfoSet->setPropertyValue(
"StreamName",
Any( sStreamName ) );
527 xOutputStream, xComponent, rxContext,
528 pServiceName, rArguments, rMediaDesc );
530 catch ( uno::Exception& )
539 const uno::Reference<io::XOutputStream> & xOutputStream,
540 const uno::Reference<XComponent> & xComponent,
541 const uno::Reference<XComponentContext> & rxContext,
542 const char* pServiceName,
543 const Sequence<Any> & rArguments,
544 const Sequence<PropertyValue> & rMediaDesc )
546 OSL_ENSURE( xOutputStream.is(),
"I really need an output stream!" );
547 OSL_ENSURE( xComponent.is(),
"Need component!" );
548 OSL_ENSURE(
nullptr != pServiceName,
"Need component name!" );
551 uno::Reference< xml::sax::XWriter > xSaxWriter = xml::sax::Writer::create(rxContext);
552 SAL_INFO(
"sw.filter",
"SAX-Writer created" );
554 xSaxWriter->setOutputStream( xOutputStream );
557 Sequence<Any> aArgs( 1 + rArguments.getLength() );
558 auto pArgs = aArgs.getArray();
559 *pArgs <<= xSaxWriter;
560 std::copy(rArguments.begin(), rArguments.end(), std::next(pArgs));
563 uno::Reference< document::XExporter > xExporter(
564 rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
565 OUString::createFromAscii(pServiceName), aArgs, rxContext), UNO_QUERY);
566 OSL_ENSURE( xExporter.is(),
567 "can't instantiate export filter component" );
568 if( !xExporter.is() )
570 SAL_INFO(
"sw.filter", pServiceName <<
" instantiated." );
572 xExporter->setSourceDocument( xComponent );
575 SAL_INFO(
"sw.filter",
"call filter()" );
576 uno::Reference<XFilter> xFilter( xExporter, UNO_QUERY );
577 return xFilter->filter( rMediaDesc );
581 [[maybe_unused]] std::u16string_view ,
const OUString& rBaseURL,
WriterRef& xRet )
@ ShowInsert
show all inserts
const OUString & GetValue() const
virtual const SwRootFrame * GetCurrentLayout() const =0
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
virtual void restoreAnnotationMarks(bool bDelete=true)=0
virtual void SetRedlineFlags(RedlineFlags eMode)=0
Set a new redline mode.
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
virtual const SwDocStat & GetDocStat() const =0
Document - Statistics.
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
SfxItemSet & GetItemSet() const
SvStream * GetOutStream()
css::uno::Reference< css::embed::XStorage > GetOutputStorage()
css::uno::Reference< css::frame::XModel3 > GetModel() const
SfxObjectCreateMode GetCreateMode() const
const css::uno::Any & GetValue() const
sal_Int32 GetVersion() const
virtual bool IsStgWriter() const override
css::uno::Reference< css::embed::XStorage > m_xStg
static rtl::Reference< SvXMLEmbeddedObjectHelper > Create(const css::uno::Reference< css::embed::XStorage > &, ::comphelper::IEmbeddedHelper &rDocPersist, SvXMLEmbeddedObjectHelperMode eCreateMode)
static rtl::Reference< SvXMLGraphicHelper > Create(const css::uno::Reference< css::embed::XStorage > &rXMLStorage, SvXMLGraphicHelperMode eCreateMode)
void WriteLayoutCache(SvStream &rStream)
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
SfxObjectShell * GetPersist() const
IDocumentMarkAccess * getIDocumentMarkAccess()
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
SwDocShell * GetDocShell()
IDocumentStatistics const & getIDocumentStatistics() const
PaM is Point and Mark: a selection of the document model.
The root element of a Writer document layout.
bool HasMergedParas() const
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding).
virtual ErrCode Write(SwPaM &, SfxMedium &, const OUString *) override
bool WriteThroughComponent(const css::uno::Reference< css::lang::XComponent > &xComponent, const char *pStreamName, const css::uno::Reference< css::uno::XComponentContext > &rFactory, const char *pServiceName, const css::uno::Sequence< css::uno::Any > &rArguments, const css::uno::Sequence< css::beans::PropertyValue > &rMediaDesc)
ErrCode Write_(const SfxItemSet *pMediumItemSet)
virtual ErrCode WriteMedium(SfxMedium &aTargetMedium) override
virtual ErrCode WriteStorage() override
virtual ~SwXMLWriter() override
SwXMLWriter(const OUString &rBaseURL)
void PutEditEngFontsInAttrPool()
void PutNumFormatFontsInAttrPool()
void SetBaseURL(const OUString &rURL)
const OUString * m_pOrigFileName
virtual ErrCode Write(SwPaM &, SfxMedium &, const OUString *)
const OUString & GetBaseURL() const
css::uno::Type const & get()
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
constexpr OUStringLiteral ODFVER_011_TEXT
constexpr OUStringLiteral ODFVER_010_TEXT
#define SAL_INFO(area, stream)
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
Reference< XComponentContext > getProcessComponentContext()
bool HasOutlineStyleToBeWrittenAsNormalListStyle(SwDoc &rDoc)
method to check, if the outline style has to written as a normal list style
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
void FixZOrder(uno::Reference< drawing::XShapes > const &xShapes, std::function< unsigned int(uno::Reference< beans::XPropertySet > const &)> const &rGetLayer)
#define ERR_WRITE_ERROR_FILE
#define ERR_SWG_WRITE_ERROR
#define WARN_SWG_FEATURES_LOST
#define WARN_WRITE_ERROR_FILE
OUString SwResId(TranslateId aId)
void GetXMLWriter(std::u16string_view, const OUString &rBaseURL, WriterRef &xRet)