21#include <com/sun/star/document/XGraphicStorageHandler.hpp>
22#include <com/sun/star/embed/ElementModes.hpp>
23#include <com/sun/star/container/XNameContainer.hpp>
24#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
25#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
26#include <com/sun/star/drawing/LineDash.hpp>
27#include <com/sun/star/awt/Gradient2.hpp>
28#include <com/sun/star/awt/XBitmap.hpp>
29#include <com/sun/star/awt/ColorStop.hpp>
30#include <com/sun/star/drawing/Hatch.hpp>
31#include <com/sun/star/io/XSeekable.hpp>
70 SvxXMLTableImportContext( SvXMLImport& rImport, SvxXMLTableImportContextEnum eContext, uno::Reference< XNameContainer > xTable,
73 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
75 const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
override;
78 static void importColor(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
79 void importMarker(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
80 void importDash(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
81 void importHatch(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
82 void importBitmap(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
85 uno::Reference< XNameContainer > mxTable;
86 SvxXMLTableImportContextEnum meContext;
92SvxXMLTableImportContext::SvxXMLTableImportContext( SvXMLImport& rImport, SvxXMLTableImportContextEnum eContext, uno::Reference< XNameContainer > xTable,
bool bOOoFormat )
94 mbOOoFormat( bOOoFormat )
106 uno::Reference< XNameContainer > mxTable;
109 std::vector<css::awt::ColorStop> maColorStopVec;
112 XMLGradientHelperContext(
113 SvXMLImport& rImport,
114 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
115 const css::uno::Reference< XNameContainer >& rxTable);
116 virtual ~XMLGradientHelperContext()
override;
119 const css::uno::Reference<css::xml::sax::XFastAttributeList>& AttrList)
override;
120 virtual void SAL_CALL
endFastElement(sal_Int32 nElement)
override;
123 XMLGradientHelperContext::XMLGradientHelperContext(
124 SvXMLImport& rImport,
125 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
126 const uno::Reference< XNameContainer >& rxTable)
134 aGradientStyle.importXML( xAttrList, maAny, maStrName );
136 catch (
const uno::Exception&)
142 XMLGradientHelperContext::~XMLGradientHelperContext()
145 if( !maStrName.isEmpty() && maAny.hasValue() )
147 if( mxTable->hasByName( maStrName ) )
149 mxTable->replaceByName( maStrName, maAny );
153 mxTable->insertByName( maStrName, maAny );
158 css::uno::Reference<css::xml::sax::XFastContextHandler> XMLGradientHelperContext::createFastChildContext(
160 const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
171 void XMLGradientHelperContext::endFastElement(sal_Int32 )
175 if (!maColorStopVec.empty())
177 awt::Gradient2 aGradient;
185css::uno::Reference< css::xml::sax::XFastContextHandler >
186 SvxXMLTableImportContext::createFastChildContext(sal_Int32 nElement,
187 const css::uno::Reference< css::xml::sax::XFastAttributeList > & rAttrList)
193 std::vector<std::pair<sal_Int32, OString>> aTmpAttrList;
195 aTmpAttrList.push_back({aIter.getToken(), OString(aIter.toCString())});
197 (SvxXMLTableImportContextEnum::Dash == meContext || SvxXMLTableImportContextEnum::Hatch == meContext ||
198 SvxXMLTableImportContextEnum::Bitmap == meContext) )
200 for(
auto & aIter : aTmpAttrList )
202 sal_Int32 aLocalAttr = aIter.first &
TOKEN_MASK;
204 SvxXMLTableImportContextEnum::Bitmap == meContext )
206 OString& rValue = aIter.second;
207 if( !rValue.isEmpty() &&
'#' == rValue[0] )
208 rValue = rValue.copy( 1 );
211 ( ( SvxXMLTableImportContextEnum::Dash == meContext &&
212 ( aLocalAttr == XML_DOTS1_LENGTH ||
213 aLocalAttr == XML_DOTS2_LENGTH ||
214 aLocalAttr == XML_DISTANCE ) ) ||
215 ( SvxXMLTableImportContextEnum::Hatch == meContext &&
216 ( aLocalAttr == XML_DISTANCE ) ) ) )
218 OString& rValue = aIter.second;
219 sal_Int32
nPos = rValue.getLength();
220 while( nPos && rValue[nPos-1] <=
' ' )
223 (
'c'==rValue[nPos-2] ||
'C'==rValue[nPos-2]) &&
224 (
'h'==rValue[nPos-1] ||
'H'==rValue[nPos-1]) )
226 rValue = rValue.copy( 0, nPos-2 );
237 return new XMLGradientHelperContext( GetImport(), rAttrList, mxTable );
243 for (
const auto& aIter : aTmpAttrList)
244 xFastList->add(aIter.first, aIter.second);
251 case SvxXMLTableImportContextEnum::Color:
252 importColor( xFastList, aAny, aName );
254 case SvxXMLTableImportContextEnum::Marker:
255 importMarker( xFastList, aAny, aName );
257 case SvxXMLTableImportContextEnum::Dash:
258 importDash( xFastList, aAny, aName );
260 case SvxXMLTableImportContextEnum::Hatch:
261 importHatch( xFastList, aAny, aName );
263 case SvxXMLTableImportContextEnum::Bitmap:
264 importBitmap( xFastList, aAny, aName );
273 if( !
aName.isEmpty() && aAny.hasValue() )
275 if( mxTable->hasByName( aName ) )
277 mxTable->replaceByName( aName, aAny );
281 mxTable->insertByName( aName, aAny );
285 catch (
const uno::Exception&)
292void SvxXMLTableImportContext::importColor(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
296 switch (aIter.getToken())
316void SvxXMLTableImportContext::importMarker(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
321 aMarkerStyle.importXML( xAttrList, rAny, rName );
323 catch (
const Exception&)
329void SvxXMLTableImportContext::importDash(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
334 aDashStyle.importXML( xAttrList, rAny, rName );
336 catch (
const Exception&)
342void SvxXMLTableImportContext::importHatch(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
347 aHatchStyle.importXML( xAttrList, rAny, rName );
349 catch (
const Exception&)
355void SvxXMLTableImportContext::importBitmap(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
361 if (aGraphicAny.has<uno::Reference<graphic::XGraphic>>())
363 auto xGraphic = aGraphicAny.get<uno::Reference<graphic::XGraphic>>();
364 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
369 catch (
const Exception&)
377 const css::uno::Reference< css::uno::XComponentContext >& rContext,
378 const uno::Reference< XNameContainer > & rTable,
379 uno::Reference<XGraphicStorageHandler>
const & xGraphicStorageHandler)
383 SetGraphicStorageHandler(xGraphicStorageHandler);
394 GetNamespaceMap().Add(
"___office",
397 GetNamespaceMap().Add(
"___draw",
400 GetNamespaceMap().Add(
"___loext",
411 const uno::Reference < embed::XStorage >& xStorage )
413 uno::Reference < io::XStream > xIStm( xStorage->openStreamElement(
"Content.xml", embed::ElementModes::READ ), uno::UNO_SET_THROW );
414 pParserInput->aInputStream = xIStm->getInputStream();
419 const uno::Reference < embed::XStorage > &xStorage,
420 const uno::Reference< XNameContainer >& xTable,
421 bool *bOptLoadedFromStorage )
noexcept
427 bool bUseStorage = aURLObj.
GetProtocol() == INetProtocol::NotValid;
431 uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
433 xml::sax::InputSource aParserInput;
436 if( !bUseStorage || !xStorage.is() )
438 SfxMedium aMedium( rPath, rReferer, StreamMode::READ | StreamMode::NOCREATE );
439 aParserInput.sSystemId = aMedium.
GetName();
443 uno::Reference < embed::XStorage > xMediumStorage( aMedium.
GetStorage(
false ), uno::UNO_SET_THROW );
451 uno::Reference< embed::XStorage > xSubStorage;
455 xStorage, rPath, embed::ElementModes::READ, aNasty );
457 catch (
const uno::Exception&)
460 if( xSubStorage.is() )
465 xStorage, rPath, embed::ElementModes::READ, aNasty );
468 aParserInput.aInputStream =
xStream->getInputStream();
470 if( bOptLoadedFromStorage )
471 *bOptLoadedFromStorage =
true;
474 uno::Reference<XGraphicStorageHandler> xGraphicStorageHandler;
475 if (xGraphicHelper.is())
476 xGraphicStorageHandler = xGraphicHelper.get();
480 uno::Reference< io::XSeekable > xSeek( aParserInput.aInputStream, uno::UNO_QUERY_THROW );
483 catch (
const uno::Exception&)
488 xImport->parseStream( aParserInput );
491 xGraphicHelper->dispose();
505 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& )
519 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Color,
mrTable, bOOoFormat );
524 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Marker,
mrTable, bOOoFormat );
529 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Dash,
mrTable, bOOoFormat );
534 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Hatch,
mrTable, bOOoFormat );
539 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Gradient,
mrTable, bOOoFormat );
544 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Bitmap,
mrTable, bOOoFormat );
INetProtocol GetProtocol() const
const OUString & GetName() const
css::uno::Reference< css::embed::XStorage > GetStorage(bool bCreateTempFile=true)
css::uno::Reference< css::io::XInputStream > const & GetInputStream()
static rtl::Reference< SvXMLGraphicHelper > Create(const css::uno::Reference< css::embed::XStorage > &rXMLStorage, SvXMLGraphicHelperMode eCreateMode)
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
static bool load(const OUString &rPath, const OUString &rReferer, const css::uno::Reference< css::embed::XStorage > &xStorage, const css::uno::Reference< css::container::XNameContainer > &xTable, bool *bOptLoadedFromStorage) noexcept
virtual ~SvxXMLXTableImport() noexcept override
const css::uno::Reference< css::container::XNameContainer > & mrTable
SvxXMLXTableImport(const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Reference< css::container::XNameContainer > &rTable, css::uno::Reference< css::document::XGraphicStorageHandler > const &rxGraphicStorageHandler)
virtual SvXMLImportContext * CreateFastContext(sal_Int32 Element, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList) override
static css::uno::Reference< css::embed::XStorage > GetStorageAtPath(const css::uno::Reference< css::embed::XStorage > &xStorage, std::u16string_view aPath, sal_uInt32 nOpenMode, LifecycleProxy const &rNastiness)
static css::uno::Reference< css::io::XStream > GetStreamAtPath(const css::uno::Reference< css::embed::XStorage > &xStorage, std::u16string_view aPath, sal_uInt32 nOpenMode, LifecycleProxy const &rNastiness)
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
XMLOFF_DLLPUBLIC bool importXML(css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, css::uno::Any &rValue, OUString &rStrName, SvXMLImport &rImport)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString toString(OptionInfo const *info)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
constexpr sal_Int32 TOKEN_MASK
constexpr sal_uInt16 XML_NAMESPACE_DRAW
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_OFFICE_OOO
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
constexpr sal_uInt16 XML_NAMESPACE_OOO
static void openStorageStream(xml::sax::InputSource *pParserInput, rtl::Reference< SvXMLGraphicHelper > &rxGraphicHelper, const uno::Reference< embed::XStorage > &xStorage)