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>
47 #include <docfunc.hxx>
61 #include <strings.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 },
183 { OUString(), 0, css::uno::Type(), 0, 0 }
185 uno::Reference< beans::XPropertySet > xInfoSet(
189 xInfoSet->setPropertyValue(
"TargetStorage",
Any(
m_xStg ) );
191 xInfoSet->setPropertyValue(
"NoEmbDataSet",
Any(bNoEmbDS));
196 sal_Int32 nProgressRange(1000000);
197 if (xStatusIndicator.is())
199 xStatusIndicator->start(
SwResId( STR_STATSTR_SWGWRITE),
202 xInfoSet->setPropertyValue(
"ProgressRange",
Any(nProgressRange));
204 xInfoSet->setPropertyValue(
"ProgressMax",
Any(static_cast < sal_Int32 >( -1 )));
210 uno::Reference<drawing::XDrawPageSupplier>
const xDPS(xModelComp, uno::UNO_QUERY);
221 xInfoSet->setPropertyValue(
"ShowChanges",
Any(isShowChanges));
228 xInfoSet->setPropertyValue(
"BaseURI",
Any(
GetBaseURL() ) );
232 const OUString
aName( !aDocHierarchicalName.isEmpty()
233 ? aDocHierarchicalName
234 : OUString(
"dummyObjectName" ) );
236 xInfoSet->setPropertyValue(
"StreamRelPath",
Any(
aName ) );
241 xInfoSet->setPropertyValue(
"AutoTextMode",
Any(
true) );
249 xInfoSet->setPropertyValue(
"OutlineStyleAsNormalListStyle",
Any(
true ) );
258 if( xStatusIndicator.is() )
261 Sequence < Any > aEmptyArgs( nArgs );
262 Any *pArgs = aEmptyArgs.getArray();
263 *pArgs++ <<= xInfoSet;
264 if( xStatusIndicator.is() )
265 *pArgs++ <<= xStatusIndicator;
267 if( xGraphicStorageHandler.is() )
269 if( xObjectResolver.is() )
272 Sequence < Any > aFilterArgs( nArgs );
273 pArgs = aFilterArgs.getArray();
274 *pArgs++ <<= xInfoSet;
275 if( xGraphicStorageHandler.is() )
276 *pArgs++ <<= xGraphicStorageHandler;
277 if( xObjectResolver.is() )
278 *pArgs++ <<= xObjectResolver;
279 if( xStatusIndicator.is() )
280 *pArgs++ <<= xStatusIndicator;
289 PropertyValue *pProps = aProps.getArray();
290 pProps->Name =
"FileName";
301 const uno::Reference<beans::XPropertySet> xPropSet(
m_xStg,
302 uno::UNO_QUERY_THROW);
307 if ((xPropSet->getPropertyValue(
"Version") >>= Version)
311 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
312 xModelComp, uno::UNO_QUERY_THROW);
313 xDMA->storeMetadataToStorage(
m_xStg);
316 catch (beans::UnknownPropertyException &)
318 catch (uno::Exception &)
329 Reference< frame::XModule > xModule( xModelComp, UNO_QUERY );
332 const OUString aModuleID = xModule->getIdentifier();
333 bStoreMeta = !aModuleID.isEmpty() &&
334 ( aModuleID ==
"com.sun.star.sdb.FormDesign" ||
335 aModuleID ==
"com.sun.star.sdb.TextReportDesign" );
338 catch( uno::Exception& )
346 xModelComp,
"meta.xml", xContext,
347 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisMetaExporter"
348 :
"com.sun.star.comp.Writer.XMLMetaExporter"),
349 aEmptyArgs, aProps ) )
352 sWarnFile =
"meta.xml";
359 xModelComp,
"settings.xml", xContext,
360 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisSettingsExporter"
361 :
"com.sun.star.comp.Writer.XMLSettingsExporter"),
362 aEmptyArgs, aProps ) )
367 sWarnFile =
"settings.xml";
376 xModelComp,
"styles.xml", xContext,
377 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisStylesExporter"
378 :
"com.sun.star.comp.Writer.XMLStylesExporter"),
379 aFilterArgs, aProps ) )
382 sErrFile =
"styles.xml";
388 xModelComp,
"content.xml", xContext,
389 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisContentExporter"
390 :
"com.sun.star.comp.Writer.XMLContentExporter"),
391 aFilterArgs, aProps ) )
394 sErrFile =
"content.xml";
405 uno::Reference < io::XStream > xStm =
m_xStg->openStreamElement(
"layout-cache", embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
407 if( !pStream->GetError() )
409 uno::Reference < beans::XPropertySet > xSet( xStm, UNO_QUERY );
411 aAny2 <<= OUString(
"application/binary");
412 xSet->setPropertyValue(
"MediaType", aAny2 );
416 catch ( uno::Exception& )
422 xGraphicHelper->dispose();
423 xGraphicHelper.clear();
424 xGraphicStorageHandler =
nullptr;
427 xObjectHelper->dispose();
428 xObjectHelper.clear();
429 xObjectResolver =
nullptr;
441 if (xStatusIndicator.is())
443 xStatusIndicator->end();
448 if( !sErrFile.isEmpty() )
450 DialogMask::ButtonsOk | DialogMask::MessageError );
455 if( !sWarnFile.isEmpty() )
457 DialogMask::ButtonsOk | DialogMask::MessageError );
475 const OUString* pFileName )
479 : static_cast<Writer *>(
this)->Write( rPaM, *rMed.
GetOutStream(), pFileName );
483 const uno::Reference<XComponent> & xComponent,
484 const char* pStreamName,
485 const uno::Reference<uno::XComponentContext> & rxContext,
486 const char* pServiceName,
487 const Sequence<Any> & rArguments,
490 OSL_ENSURE(
m_xStg.is(),
"Need storage!" );
491 OSL_ENSURE(
nullptr != pStreamName,
"Need stream name!" );
492 OSL_ENSURE(
nullptr != pServiceName,
"Need service name!" );
494 SAL_INFO(
"sw.filter",
"SwXMLWriter::WriteThroughComponent : stream " << pStreamName );
499 const OUString sStreamName = OUString::createFromAscii( pStreamName );
500 uno::Reference<io::XStream>
xStream =
501 m_xStg->openStreamElement( sStreamName,
502 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
504 uno::Reference <beans::XPropertySet > xSet( xStream, uno::UNO_QUERY );
508 xSet->setPropertyValue(
"MediaType",
Any(OUString(
"text/xml")) );
511 xSet->setPropertyValue(
"UseCommonStoragePasswordEncryption",
Any(
true) );
514 uno::Reference< io::XOutputStream > xOutputStream = xStream->getOutputStream();
517 uno::Reference< beans::XPropertySet > xInfoSet;
518 if( rArguments.hasElements() )
519 rArguments.getConstArray()[0] >>= xInfoSet;
520 OSL_ENSURE( xInfoSet.is(),
"missing property set" );
523 xInfoSet->setPropertyValue(
"StreamName",
Any( sStreamName ) );
528 xOutputStream, xComponent, rxContext,
529 pServiceName, rArguments, rMediaDesc );
531 catch ( uno::Exception& )
540 const uno::Reference<io::XOutputStream> & xOutputStream,
541 const uno::Reference<XComponent> & xComponent,
542 const uno::Reference<XComponentContext> & rxContext,
543 const char* pServiceName,
544 const Sequence<Any> & rArguments,
545 const Sequence<PropertyValue> & rMediaDesc )
547 OSL_ENSURE( xOutputStream.is(),
"I really need an output stream!" );
548 OSL_ENSURE( xComponent.is(),
"Need component!" );
549 OSL_ENSURE(
nullptr != pServiceName,
"Need component name!" );
552 uno::Reference< xml::sax::XWriter > xSaxWriter = xml::sax::Writer::create(rxContext);
553 SAL_INFO(
"sw.filter",
"SAX-Writer created" );
555 xSaxWriter->setOutputStream( xOutputStream );
558 Sequence<Any> aArgs( 1 + rArguments.getLength() );
559 auto pArgs = aArgs.getArray();
560 *pArgs <<= xSaxWriter;
561 std::copy(rArguments.begin(), rArguments.end(), std::next(pArgs));
564 uno::Reference< document::XExporter > xExporter(
565 rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
566 OUString::createFromAscii(pServiceName), aArgs, rxContext), UNO_QUERY);
567 OSL_ENSURE( xExporter.is(),
568 "can't instantiate export filter component" );
569 if( !xExporter.is() )
571 SAL_INFO(
"sw.filter", pServiceName <<
" instantiated." );
573 xExporter->setSourceDocument( xComponent );
576 SAL_INFO(
"sw.filter",
"call filter()" );
577 uno::Reference<XFilter> xFilter( xExporter, UNO_QUERY );
578 return xFilter->filter( rMediaDesc );
582 [[maybe_unused]] std::u16string_view ,
const OUString& rBaseURL,
WriterRef& xRet )
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
#define WARN_SWG_FEATURES_LOST
const OUString & GetBaseURL() const
IDocumentStatistics const & getIDocumentStatistics() const
virtual const SwRootFrame * GetCurrentLayout() const =0
SwDocShell * GetDocShell()
#define ERR_SWG_WRITE_ERROR
void GetXMLWriter([[maybe_unused]] std::u16string_view, const OUString &rBaseURL, WriterRef &xRet)
sal_Int32 GetVersion() const
#define WARN_WRITE_ERROR_FILE
constexpr OUStringLiteral ODFVER_011_TEXT
css::uno::Reference< css::frame::XModel3 > GetModel() const
virtual ErrCode Write(SwPaM &, SfxMedium &, const OUString *) override
virtual void restoreAnnotationMarks(bool bDelete=true)=0
#define ERR_WRITE_ERROR_FILE
IDocumentMarkAccess * getIDocumentMarkAccess()
The root element of a Writer document layout.
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
OUString SwResId(TranslateId aId)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
ErrCode Write_(const SfxItemSet *pMediumItemSet)
SvStream * GetOutStream()
css::uno::Reference< css::embed::XStorage > m_xStg
const css::uno::Any & GetValue() const
SfxObjectCreateMode GetCreateMode() const
void SetBaseURL(const OUString &rURL)
virtual ErrCode WriteStorage() override
PaM is Point and Mark: a selection of the document model.
void PutNumFormatFontsInAttrPool()
static rtl::Reference< SvXMLEmbeddedObjectHelper > Create(const css::uno::Reference< css::embed::XStorage > &,::comphelper::IEmbeddedHelper &rDocPersist, SvXMLEmbeddedObjectHelperMode eCreateMode)
void PutEditEngFontsInAttrPool()
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
const OUString & GetValue() const
SwXMLWriter(const OUString &rBaseURL)
void WriteLayoutCache(SvStream &rStream)
virtual bool IsStgWriter() const override
SfxItemSet * GetItemSet() const
css::uno::Type const & get()
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
virtual void SetRedlineFlags(RedlineFlags eMode)=0
Set a new redline mode.
virtual const SwDocStat & GetDocStat() const =0
Document - Statistics.
#define SAL_INFO(area, stream)
virtual ~SwXMLWriter() override
SfxObjectShell * GetPersist() const
Reference< XComponentContext > getProcessComponentContext()
css::uno::Reference< css::embed::XStorage > GetOutputStorage()
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
bool HasOutlineStyleToBeWrittenAsNormalListStyle(SwDoc &rDoc)
method to check, if the outline style has to written as a normal list style
const OUString * m_pOrigFileName
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
bool HasMergedParas() const
static rtl::Reference< SvXMLGraphicHelper > Create(const css::uno::Reference< css::embed::XStorage > &rXMLStorage, SvXMLGraphicHelperMode eCreateMode)
void FixZOrder(uno::Reference< drawing::XShapes > const &xShapes, std::function< unsigned int(uno::Reference< beans::XPropertySet > const &)> const &rGetLayer)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
constexpr OUStringLiteral ODFVER_010_TEXT
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)
virtual ErrCode WriteMedium(SfxMedium &aTargetMedium) override