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/document/XExporter.hpp>
27 #include <com/sun/star/document/XFilter.hpp>
28 #include <com/sun/star/frame/XModule.hpp>
29 #include <com/sun/star/frame/XModel.hpp>
43 #include <sfx2/sfxsids.hrc>
46 #include <docfunc.hxx>
57 #include <strings.hrc>
60 #include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
79 const OUString& aDocHierarchicalName )
82 uno::Reference< uno::XComponentContext > xContext =
86 uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler;
88 uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
91 OSL_ENSURE(
m_xStg.is(),
"Where is my storage?" );
93 SvXMLGraphicHelperMode::Write );
94 xGraphicStorageHandler = xGraphicHelper.get();
101 SvXMLEmbeddedObjectHelperMode::Write );
102 xObjectResolver = xObjectHelper.get();
112 { OUString(
"ProgressRange"), 0,
114 beans::PropertyAttribute::MAYBEVOID, 0},
115 { OUString(
"ProgressMax"), 0,
117 beans::PropertyAttribute::MAYBEVOID, 0},
118 { OUString(
"ProgressCurrent"), 0,
120 beans::PropertyAttribute::MAYBEVOID, 0},
121 { OUString(
"WrittenNumberStyles"), 0,
123 beans::PropertyAttribute::MAYBEVOID, 0},
124 { OUString(
"UsePrettyPrinting"), 0,
126 beans::PropertyAttribute::MAYBEVOID, 0},
127 { OUString(
"ShowChanges"), 0,
129 beans::PropertyAttribute::MAYBEVOID, 0 },
130 { OUString(
"RedlineProtectionKey"), 0,
132 beans::PropertyAttribute::MAYBEVOID, 0 },
133 { OUString(
"BaseURI"), 0,
135 beans::PropertyAttribute::MAYBEVOID, 0 },
136 { OUString(
"StreamRelPath"), 0,
138 beans::PropertyAttribute::MAYBEVOID, 0 },
139 { OUString(
"StreamName"), 0,
141 beans::PropertyAttribute::MAYBEVOID, 0 },
142 { OUString(
"AutoTextMode"), 0,
144 beans::PropertyAttribute::MAYBEVOID, 0 },
145 { OUString(
"StyleNames"), 0,
147 beans::PropertyAttribute::MAYBEVOID, 0 },
148 { OUString(
"StyleFamilies"), 0,
150 beans::PropertyAttribute::MAYBEVOID, 0 },
152 { OUString(
"OutlineStyleAsNormalListStyle"), 0,
154 beans::PropertyAttribute::MAYBEVOID, 0 },
156 css::beans::PropertyAttribute::MAYBEVOID, 0 },
157 { OUString(), 0, css::uno::Type(), 0, 0 }
159 uno::Reference< beans::XPropertySet > xInfoSet(
163 xInfoSet->setPropertyValue(
"TargetStorage",
Any(
m_xStg ) );
168 sal_Int32 nProgressRange(1000000);
169 if (xStatusIndicator.is())
171 xStatusIndicator->start(
SwResId( STR_STATSTR_SWGWRITE),
174 xInfoSet->setPropertyValue(
"ProgressRange",
Any(nProgressRange));
176 xInfoSet->setPropertyValue(
"ProgressMax",
Any(static_cast < sal_Int32 >( -1 )));
189 xInfoSet->setPropertyValue(
"ShowChanges",
makeAny(isShowChanges));
200 const OUString
aName( !aDocHierarchicalName.isEmpty()
201 ? aDocHierarchicalName
202 : OUString(
"dummyObjectName" ) );
204 xInfoSet->setPropertyValue(
"StreamRelPath",
makeAny(
aName ) );
209 xInfoSet->setPropertyValue(
"AutoTextMode",
makeAny(
true) );
217 xInfoSet->setPropertyValue(
"OutlineStyleAsNormalListStyle",
makeAny(
true ) );
226 if( xStatusIndicator.is() )
229 Sequence < Any > aEmptyArgs( nArgs );
230 Any *pArgs = aEmptyArgs.getArray();
231 *pArgs++ <<= xInfoSet;
232 if( xStatusIndicator.is() )
233 *pArgs++ <<= xStatusIndicator;
235 if( xGraphicStorageHandler.is() )
237 if( xObjectResolver.is() )
240 Sequence < Any > aFilterArgs( nArgs );
241 pArgs = aFilterArgs.getArray();
242 *pArgs++ <<= xInfoSet;
243 if( xGraphicStorageHandler.is() )
244 *pArgs++ <<= xGraphicStorageHandler;
245 if( xObjectResolver.is() )
246 *pArgs++ <<= xObjectResolver;
247 if( xStatusIndicator.is() )
248 *pArgs++ <<= xStatusIndicator;
252 OSL_ENSURE( xModelComp.is(),
"XMLWriter::Write: got no model" );
253 if( !xModelComp.is() )
263 PropertyValue *pProps = aProps.getArray();
264 pProps->Name =
"FileName";
275 const uno::Reference<beans::XPropertySet> xPropSet(
m_xStg,
276 uno::UNO_QUERY_THROW);
281 if ((xPropSet->getPropertyValue(
"Version") >>= Version)
285 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
286 xModelComp, uno::UNO_QUERY_THROW);
287 xDMA->storeMetadataToStorage(
m_xStg);
290 catch (beans::UnknownPropertyException &)
292 catch (uno::Exception &)
303 Reference< frame::XModule > xModule( xModelComp, UNO_QUERY );
306 const OUString aModuleID = xModule->getIdentifier();
307 bStoreMeta = !aModuleID.isEmpty() &&
308 ( aModuleID ==
"com.sun.star.sdb.FormDesign" ||
309 aModuleID ==
"com.sun.star.sdb.TextReportDesign" );
312 catch( uno::Exception& )
320 xModelComp,
"meta.xml", xContext,
321 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisMetaExporter"
322 :
"com.sun.star.comp.Writer.XMLMetaExporter"),
323 aEmptyArgs, aProps ) )
326 sWarnFile =
"meta.xml";
333 xModelComp,
"settings.xml", xContext,
334 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisSettingsExporter"
335 :
"com.sun.star.comp.Writer.XMLSettingsExporter"),
336 aEmptyArgs, aProps ) )
341 sWarnFile =
"settings.xml";
350 xModelComp,
"styles.xml", xContext,
351 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisStylesExporter"
352 :
"com.sun.star.comp.Writer.XMLStylesExporter"),
353 aFilterArgs, aProps ) )
356 sErrFile =
"styles.xml";
362 xModelComp,
"content.xml", xContext,
363 (bOASIS ?
"com.sun.star.comp.Writer.XMLOasisContentExporter"
364 :
"com.sun.star.comp.Writer.XMLContentExporter"),
365 aFilterArgs, aProps ) )
368 sErrFile =
"content.xml";
379 uno::Reference < io::XStream > xStm =
m_xStg->openStreamElement(
"layout-cache", embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
381 if( !pStream->GetError() )
383 uno::Reference < beans::XPropertySet > xSet( xStm, UNO_QUERY );
385 aAny2 <<= OUString(
"application/binary");
386 xSet->setPropertyValue(
"MediaType", aAny2 );
390 catch ( uno::Exception& )
396 xGraphicHelper->dispose();
397 xGraphicHelper.clear();
398 xGraphicStorageHandler =
nullptr;
401 xObjectHelper->dispose();
402 xObjectHelper.clear();
403 xObjectResolver =
nullptr;
412 if (xStatusIndicator.is())
414 xStatusIndicator->end();
419 if( !sErrFile.isEmpty() )
421 DialogMask::ButtonsOk | DialogMask::MessageError );
426 if( !sWarnFile.isEmpty() )
428 DialogMask::ButtonsOk | DialogMask::MessageError );
437 return Write_( uno::Reference < task::XStatusIndicator >(), OUString() );
442 uno::Reference < task::XStatusIndicator > xStatusIndicator;
446 if ( pStatusBarItem )
447 pStatusBarItem->
GetValue() >>= xStatusIndicator;
450 if ( pDocHierarchItem )
451 aName = pDocHierarchItem->
GetValue();
453 return Write_( xStatusIndicator, aName );
457 const OUString* pFileName )
461 : static_cast<Writer *>(
this)->Write( rPaM, *rMed.
GetOutStream(), pFileName );
465 const uno::Reference<XComponent> & xComponent,
466 const char* pStreamName,
467 const uno::Reference<uno::XComponentContext> & rxContext,
468 const char* pServiceName,
469 const Sequence<Any> & rArguments,
472 OSL_ENSURE(
m_xStg.is(),
"Need storage!" );
473 OSL_ENSURE(
nullptr != pStreamName,
"Need stream name!" );
474 OSL_ENSURE(
nullptr != pServiceName,
"Need service name!" );
476 SAL_INFO(
"sw.filter",
"SwXMLWriter::WriteThroughComponent : stream " << pStreamName );
481 const OUString sStreamName = OUString::createFromAscii( pStreamName );
482 uno::Reference<io::XStream>
xStream =
483 m_xStg->openStreamElement( sStreamName,
484 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
486 uno::Reference <beans::XPropertySet > xSet( xStream, uno::UNO_QUERY );
490 xSet->setPropertyValue(
"MediaType",
Any(OUString(
"text/xml")) );
493 xSet->setPropertyValue(
"UseCommonStoragePasswordEncryption",
makeAny(
true) );
496 uno::Reference< io::XOutputStream > xOutputStream = xStream->getOutputStream();
499 uno::Reference< beans::XPropertySet > xInfoSet;
500 if( rArguments.hasElements() )
501 rArguments.getConstArray()[0] >>= xInfoSet;
502 OSL_ENSURE( xInfoSet.is(),
"missing property set" );
505 xInfoSet->setPropertyValue(
"StreamName",
makeAny( sStreamName ) );
510 xOutputStream, xComponent, rxContext,
511 pServiceName, rArguments, rMediaDesc );
513 catch ( uno::Exception& )
522 const uno::Reference<io::XOutputStream> & xOutputStream,
523 const uno::Reference<XComponent> & xComponent,
524 const uno::Reference<XComponentContext> & rxContext,
525 const char* pServiceName,
526 const Sequence<Any> & rArguments,
527 const Sequence<PropertyValue> & rMediaDesc )
529 OSL_ENSURE( xOutputStream.is(),
"I really need an output stream!" );
530 OSL_ENSURE( xComponent.is(),
"Need component!" );
531 OSL_ENSURE(
nullptr != pServiceName,
"Need component name!" );
534 uno::Reference< xml::sax::XWriter > xSaxWriter = xml::sax::Writer::create(rxContext);
535 SAL_INFO(
"sw.filter",
"SAX-Writer created" );
537 xSaxWriter->setOutputStream( xOutputStream );
540 Sequence<Any> aArgs( 1 + rArguments.getLength() );
541 aArgs[0] <<= xSaxWriter;
542 std::copy(rArguments.begin(), rArguments.end(), std::next(aArgs.begin()));
545 uno::Reference< document::XExporter > xExporter(
546 rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
547 OUString::createFromAscii(pServiceName), aArgs, rxContext), UNO_QUERY);
548 OSL_ENSURE( xExporter.is(),
549 "can't instantiate export filter component" );
550 if( !xExporter.is() )
552 SAL_INFO(
"sw.filter", pServiceName <<
" instantiated." );
554 xExporter->setSourceDocument( xComponent );
557 SAL_INFO(
"sw.filter",
"call filter()" );
558 uno::Reference<XFilter> xFilter( xExporter, UNO_QUERY );
559 return xFilter->filter( rMediaDesc );
563 [[maybe_unused]]
const OUString& ,
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
sal_Int32 GetVersion() const
#define WARN_WRITE_ERROR_FILE
virtual ErrCode Write(SwPaM &, SfxMedium &, const OUString *) override
ErrCode Write_(const css::uno::Reference< css::task::XStatusIndicator > &, const OUString &)
#define ERR_WRITE_ERROR_FILE
css::uno::Reference< css::frame::XModel > GetModel() const
The root element of a Writer document layout.
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
SvStream * GetOutStream()
css::uno::Reference< css::embed::XStorage > m_xStg
const css::uno::Any & GetValue() const
SfxObjectCreateMode GetCreateMode() const
bool IsPrettyPrinting() 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()
OUString SwResId(const char *pId)
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
void GetXMLWriter([[maybe_unused]] const OUString &, const OUString &rBaseURL, WriterRef &xRet)
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)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
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
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)