24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/container/XNameContainer.hpp>
26#include <com/sun/star/xml/sax/Writer.hpp>
27#include <com/sun/star/uno/Sequence.hxx>
28#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
29#include <com/sun/star/drawing/LineDash.hpp>
30#include <com/sun/star/awt/Gradient.hpp>
31#include <com/sun/star/awt/XBitmap.hpp>
32#include <com/sun/star/drawing/Hatch.hpp>
33#include <com/sun/star/embed/ElementModes.hpp>
37#include <rtl/ustrbuf.hxx>
48#include <com/sun/star/embed/XTransactedObject.hpp>
68using com::sun::star::embed::XTransactedObject;
72class SvxXMLTableEntryExporter
75 explicit SvxXMLTableEntryExporter(
SvXMLExport& rExport ) : mrExport( rExport ) {}
76 virtual ~SvxXMLTableEntryExporter();
78 virtual void exportEntry(
const OUString& rStrName,
const Any& rValue ) = 0;
84class SvxXMLColorEntryExporter :
public SvxXMLTableEntryExporter
87 explicit SvxXMLColorEntryExporter(
SvXMLExport& rExport );
89 virtual void exportEntry(
const OUString& rStrName,
const Any& rValue )
override;
92class SvxXMLLineEndEntryExporter :
public SvxXMLTableEntryExporter
95 explicit SvxXMLLineEndEntryExporter(
SvXMLExport& rExport );
97 virtual void exportEntry(
const OUString& rStrName,
const Any& rValue )
override;
102class SvxXMLDashEntryExporter :
public SvxXMLTableEntryExporter
105 explicit SvxXMLDashEntryExporter(
SvXMLExport& rExport );
107 virtual void exportEntry(
const OUString& rStrName,
const Any& rValue )
override;
113class SvxXMLHatchEntryExporter :
public SvxXMLTableEntryExporter
116 explicit SvxXMLHatchEntryExporter(
SvXMLExport& rExport );
118 virtual void exportEntry(
const OUString& rStrName,
const Any& rValue )
override;
123class SvxXMLGradientEntryExporter :
public SvxXMLTableEntryExporter
126 explicit SvxXMLGradientEntryExporter(
SvXMLExport& rExport );
128 virtual void exportEntry(
const OUString& rStrName,
const Any& rValue )
override;
133class SvxXMLBitmapEntryExporter :
public SvxXMLTableEntryExporter
136 explicit SvxXMLBitmapEntryExporter(
SvXMLExport& rExport );
138 virtual void exportEntry(
const OUString& rStrName,
const Any& rValue )
override;
144 const css::uno::Reference< css::uno::XComponentContext >& rContext,
145 const uno::Reference<xml::sax::XDocumentHandler> & rHandler,
146 const uno::Reference<container::XNameContainer >& xTable,
147 uno::Reference<document::XGraphicStorageHandler>
const & xGraphicStorageHandler)
167 uno::Reference< beans::XPropertySet > xProps( xOut, uno::UNO_QUERY );
170 OSL_FAIL(
"Missing stream metadata interface" );
176 xProps->setPropertyValue(
"MediaType",
uno::Any( OUString(
"text/xml" ) ) );
179 xProps->setPropertyValue(
"UseCommonStoragePasswordEncryption",
uno::Any(
true ) );
180 }
catch (
const uno::Exception & )
188 const uno::Reference < embed::XStorage >& xSubStorage )
190 uno::Reference < io::XStream >
xStream = xSubStorage->openStreamElement(
192 embed::ElementModes::WRITE );
195 *xOut =
xStream->getOutputStream();
199 const OUString& rURL,
200 const uno::Reference<container::XNameContainer >& xTable,
201 const uno::Reference<embed::XStorage >& xStorage,
205 std::unique_ptr<SfxMedium> pMedium;
209 bool bToStorage = aURLObj.
GetProtocol() == INetProtocol::NotValid;
217 uno::Reference< uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
219 uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create( xContext );
221 uno::Reference < io::XStream >
xStream;
222 uno::Reference < io::XOutputStream > xOut;
223 uno::Reference<embed::XStorage > xSubStorage;
224 uno::Reference<XGraphicStorageHandler> xGraphicStorageHandler;
225 const sal_Int32 eCreate = embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE;
227 if( !bToStorage || !xStorage.is() )
233 pMedium.reset(
new SfxMedium( rURL, StreamMode::WRITE | StreamMode::TRUNC ));
235 SvStream* pStream = pMedium->GetOutStream();
238 OSL_FAIL(
"no output stream!" );
247 OUString aPath = rURL;
252 xSubStorage = xStorage->openStorageElement( aPath, eCreate );
253 }
catch (uno::Exception &) {
254 OSL_FAIL(
"no output storage!" );
262 xStream = xStorage->openStreamElement( aPath, eCreate );
266 xOut =
xStream->getOutputStream();
267 }
catch (uno::Exception &) {
268 OSL_FAIL(
"no output stream!" );
276 if( !xOut.is() && xSubStorage.is() )
281 xWriter->setOutputStream( xOut );
282 if( xGraphicHelper.is() )
283 xGraphicStorageHandler = xGraphicHelper.get();
287 bRet = xExporter->exportTable();
290 xGraphicHelper->dispose();
291 xGraphicHelper.clear();
293 if( xSubStorage.is() )
295 uno::Reference< XTransactedObject > xTrans( xSubStorage, UNO_QUERY );
299 xSubStorage->dispose();
302 catch( uno::Exception& )
325 while( USHRT_MAX !=
nPos )
336 char const* pEleName;
338 std::unique_ptr<SvxXMLTableEntryExporter> pExporter;
342 pExporter.reset(
new SvxXMLColorEntryExporter(*
this));
343 pEleName =
"color-table";
347 pExporter.reset(
new SvxXMLLineEndEntryExporter(*
this));
348 pEleName =
"marker-table";
352 pExporter.reset(
new SvxXMLDashEntryExporter(*
this));
353 pEleName =
"dash-table";
357 pExporter.reset(
new SvxXMLHatchEntryExporter(*
this));
358 pEleName =
"hatch-table";
362 pExporter.reset(
new SvxXMLGradientEntryExporter(*
this));
363 pEleName =
"gradient-table";
367 pExporter.reset(
new SvxXMLBitmapEntryExporter(*
this));
368 pEleName =
"bitmap-table";
372 OSL_FAIL(
"unknown type for export");
381 for(
const OUString& rName : aNames )
383 aAny =
mxTable->getByName( rName );
384 pExporter->exportEntry( rName, aAny );
407SvxXMLTableEntryExporter::~SvxXMLTableEntryExporter()
412SvxXMLColorEntryExporter::SvxXMLColorEntryExporter(
SvXMLExport& rExport )
413: SvxXMLTableEntryExporter( rExport )
417void SvxXMLColorEntryExporter::exportEntry(
const OUString& rStrName,
const Any& rValue )
419 mrExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, rStrName );
421 sal_Int32 nColor = 0;
426 mrExport.AddAttribute( XML_NAMESPACE_DRAW, XML_COLOR, aOut.makeStringAndClear() );
432SvxXMLLineEndEntryExporter::SvxXMLLineEndEntryExporter(
SvXMLExport& rExport )
433: SvxXMLTableEntryExporter( rExport ), maMarkerStyle( rExport )
437void SvxXMLLineEndEntryExporter::exportEntry(
const OUString& rStrName,
const Any& rValue )
439 maMarkerStyle.exportXML( rStrName, rValue );
443SvxXMLDashEntryExporter::SvxXMLDashEntryExporter(
SvXMLExport& rExport )
444: SvxXMLTableEntryExporter( rExport ), maDashStyle( rExport )
448void SvxXMLDashEntryExporter::exportEntry(
const OUString& rStrName,
const Any& rValue )
450 maDashStyle.exportXML( rStrName, rValue );
454SvxXMLHatchEntryExporter::SvxXMLHatchEntryExporter(
SvXMLExport& rExport )
455: SvxXMLTableEntryExporter( rExport ), maHatchStyle( rExport )
459void SvxXMLHatchEntryExporter::exportEntry(
const OUString& rStrName,
const Any& rValue )
461 maHatchStyle.exportXML( rStrName, rValue );
465SvxXMLGradientEntryExporter::SvxXMLGradientEntryExporter(
SvXMLExport& rExport )
466: SvxXMLTableEntryExporter( rExport ), maGradientStyle( rExport )
470void SvxXMLGradientEntryExporter::exportEntry(
const OUString& rStrName,
const Any& rValue )
472 maGradientStyle.exportXML( rStrName, rValue );
476SvxXMLBitmapEntryExporter::SvxXMLBitmapEntryExporter(
SvXMLExport& rExport )
477: SvxXMLTableEntryExporter( rExport )
481void SvxXMLBitmapEntryExporter::exportEntry(
const OUString& rStrName,
const Any& rValue )
INetProtocol GetProtocol() const
const SvXMLNamespaceMap & GetNamespaceMap() const
SvXMLNamespaceMap & GetNamespaceMap_()
void addChaffWhenEncryptedStorage()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
comphelper::AttributeList & GetAttrList()
void SetGraphicStorageHandler(css::uno::Reference< css::document::XGraphicStorageHandler > const &rxGraphicStorageHandler)
static rtl::Reference< SvXMLGraphicHelper > Create(const css::uno::Reference< css::embed::XStorage > &rXMLStorage, SvXMLGraphicHelperMode eCreateMode)
sal_uInt16 GetFirstKey() const
sal_uInt16 GetNextKey(sal_uInt16 nOldKey) const
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
const css::uno::Reference< css::container::XNameContainer > & mxTable
static bool save(const OUString &rURL, const css::uno::Reference< css::container::XNameContainer > &xTable, const css::uno::Reference< css::embed::XStorage > &xStorage, OUString *pOptName)
SvxXMLXTableExportComponent(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::xml::sax::XDocumentHandler > &xHandler, const css::uno::Reference< css::container::XNameContainer > &xTable, css::uno::Reference< css::document::XGraphicStorageHandler > const &xGraphicStorageHandler)
virtual void ExportAutoStyles_() override
virtual void ExportMasterStyles_() override
virtual ~SvxXMLXTableExportComponent() override
virtual void ExportContent_() override
bool exportTable() noexcept
void AddAttribute(const OUString &sName, const OUString &sValue)
static css::uno::Reference< css::embed::XStorage > GetStorageFromURL(const OUString &aURL, sal_Int32 nStorageMode, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
css::uno::Type const & get()
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
#define TOOLS_WARN_EXCEPTION(area, stream)
XMLOFF_DLLPUBLIC void exportXML(OUString const &rStrName, css::uno::Any const &rValue, SvXMLExport &rExport)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
constexpr sal_uInt16 XML_NAMESPACE_DRAW
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_SVG
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
constexpr sal_uInt16 XML_NAMESPACE_OOO
static void initializeStreamMetadata(const uno::Reference< uno::XInterface > &xOut)
static void createStorageStream(uno::Reference< io::XOutputStream > *xOut, rtl::Reference< SvXMLGraphicHelper > &rxGraphicHelper, const uno::Reference< embed::XStorage > &xSubStorage)