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/Gradient.hpp>
28 #include <com/sun/star/awt/XBitmap.hpp>
29 #include <com/sun/star/drawing/Hatch.hpp>
30 #include <com/sun/star/io/XSeekable.hpp>
70 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
71 createFastChildContext(sal_Int32 Element,
72 const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
override;
75 static void importColor(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
76 void importMarker(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
77 void importDash(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
78 void importHatch(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
79 void importGradient(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
80 void importBitmap(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName );
83 uno::Reference< XNameContainer > mxTable;
92 mbOOoFormat( bOOoFormat )
96 css::uno::Reference< css::xml::sax::XFastContextHandler >
97 SvxXMLTableImportContext::createFastChildContext(sal_Int32 nElement,
98 const css::uno::Reference< css::xml::sax::XFastAttributeList > & rAttrList)
104 std::vector<std::pair<sal_Int32, OString>> aTmpAttrList;
106 aTmpAttrList.push_back({aIter.getToken(), OString(aIter.toCString())});
108 (SvxXMLTableImportContextEnum::Dash == meContext || SvxXMLTableImportContextEnum::Hatch == meContext ||
109 SvxXMLTableImportContextEnum::Bitmap == meContext) )
111 for(
auto & aIter : aTmpAttrList )
113 sal_Int32 aLocalAttr = aIter.first &
TOKEN_MASK;
115 SvxXMLTableImportContextEnum::Bitmap == meContext )
117 OString& rValue = aIter.second;
118 if( !rValue.isEmpty() &&
'#' == rValue[0] )
119 rValue = rValue.copy( 1 );
122 ( ( SvxXMLTableImportContextEnum::Dash == meContext &&
123 ( aLocalAttr == XML_DOTS1_LENGTH ||
124 aLocalAttr == XML_DOTS2_LENGTH ||
125 aLocalAttr == XML_DISTANCE ) ) ||
126 ( SvxXMLTableImportContextEnum::Hatch == meContext &&
127 ( aLocalAttr == XML_DISTANCE ) ) ) )
129 OString& rValue = aIter.second;
130 sal_Int32
nPos = rValue.getLength();
131 while( nPos && rValue[nPos-1] <=
' ' )
134 (
'c'==rValue[nPos-2] ||
'C'==rValue[nPos-2]) &&
135 (
'h'==rValue[nPos-1] ||
'H'==rValue[nPos-1]) )
137 rValue = rValue.copy( 0, nPos-2 );
145 for (
const auto& aIter : aTmpAttrList)
146 xFastList->add(aIter.first, aIter.second);
153 case SvxXMLTableImportContextEnum::Color:
154 importColor( xFastList, aAny, aName );
156 case SvxXMLTableImportContextEnum::Marker:
157 importMarker( xFastList, aAny, aName );
159 case SvxXMLTableImportContextEnum::Dash:
160 importDash( xFastList, aAny, aName );
162 case SvxXMLTableImportContextEnum::Hatch:
163 importHatch( xFastList, aAny, aName );
165 case SvxXMLTableImportContextEnum::Gradient:
166 importGradient( xFastList, aAny, aName );
168 case SvxXMLTableImportContextEnum::Bitmap:
169 importBitmap( xFastList, aAny, aName );
173 if( !aName.isEmpty() && aAny.hasValue() )
175 if( mxTable->hasByName( aName ) )
177 mxTable->replaceByName( aName, aAny );
181 mxTable->insertByName( aName, aAny );
185 catch (
const uno::Exception&)
192 void SvxXMLTableImportContext::importColor(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
196 switch (aIter.getToken())
216 void SvxXMLTableImportContext::importMarker(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
221 aMarkerStyle.importXML( xAttrList, rAny, rName );
223 catch (
const Exception&)
229 void SvxXMLTableImportContext::importDash(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
234 aDashStyle.importXML( xAttrList, rAny, rName );
236 catch (
const Exception&)
242 void SvxXMLTableImportContext::importHatch(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
247 aHatchStyle.importXML( xAttrList, rAny, rName );
249 catch (
const Exception&)
255 void SvxXMLTableImportContext::importGradient(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
260 aGradientStyle.importXML( xAttrList, rAny, rName );
262 catch (
const Exception&)
268 void SvxXMLTableImportContext::importBitmap(
const uno::Reference< XFastAttributeList >& xAttrList, Any& rAny, OUString& rName )
274 if (aGraphicAny.has<uno::Reference<graphic::XGraphic>>())
276 auto xGraphic = aGraphicAny.get<uno::Reference<graphic::XGraphic>>();
277 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
282 catch (
const Exception&)
290 const css::uno::Reference< css::uno::XComponentContext >& rContext,
291 const uno::Reference< XNameContainer > & rTable,
292 uno::Reference<XGraphicStorageHandler>
const & xGraphicStorageHandler)
321 const uno::Reference < embed::XStorage >& xStorage )
323 uno::Reference < io::XStream > xIStm( xStorage->openStreamElement(
"Content.xml", embed::ElementModes::READ ), uno::UNO_SET_THROW );
324 pParserInput->aInputStream = xIStm->getInputStream();
329 const uno::Reference < embed::XStorage > &xStorage,
330 const uno::Reference< XNameContainer >& xTable,
331 bool *bOptLoadedFromStorage ) noexcept
337 bool bUseStorage = aURLObj.
GetProtocol() == INetProtocol::NotValid;
343 xml::sax::InputSource aParserInput;
346 if( !bUseStorage || !xStorage.is() )
348 SfxMedium aMedium( rPath, rReferer, StreamMode::READ | StreamMode::NOCREATE );
349 aParserInput.sSystemId = aMedium.
GetName();
353 uno::Reference < embed::XStorage > xMediumStorage( aMedium.
GetStorage(
false ), uno::UNO_SET_THROW );
361 uno::Reference< embed::XStorage > xSubStorage;
365 xStorage, rPath, embed::ElementModes::READ, aNasty );
367 catch (
const uno::Exception&)
370 if( xSubStorage.is() )
375 xStorage, rPath, embed::ElementModes::READ, aNasty );
378 aParserInput.aInputStream = xStream->getInputStream();
380 if( bOptLoadedFromStorage )
381 *bOptLoadedFromStorage =
true;
384 uno::Reference<XGraphicStorageHandler> xGraphicStorageHandler;
385 if (xGraphicHelper.is())
386 xGraphicStorageHandler = xGraphicHelper.get();
390 uno::Reference< io::XSeekable > xSeek( aParserInput.aInputStream, uno::UNO_QUERY_THROW );
393 catch (
const uno::Exception&)
398 xImport->parseStream( aParserInput );
401 xGraphicHelper->dispose();
415 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& )
429 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Color,
mrTable, bOOoFormat );
434 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Marker,
mrTable, bOOoFormat );
439 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Dash,
mrTable, bOOoFormat );
444 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Hatch,
mrTable, bOOoFormat );
449 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Gradient,
mrTable, bOOoFormat );
454 return new SvxXMLTableImportContext( *
this, SvxXMLTableImportContextEnum::Bitmap,
mrTable, bOOoFormat );
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
constexpr sal_uInt16 XML_NAMESPACE_OFFICE_OOO
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)
const OUString & GetName() const
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_OOO
SvXMLNamespaceMap & GetNamespaceMap()
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
SvxXMLTableImportContextEnum
#define XMLOFF_WARN_UNKNOWN(area, rIter)
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)
constexpr sal_uInt16 XML_NAMESPACE_DRAW
void SetGraphicStorageHandler(css::uno::Reference< css::document::XGraphicStorageHandler > const &rxGraphicStorageHandler)
#define DBG_UNHANDLED_EXCEPTION(...)
#define TOOLS_WARN_EXCEPTION(area, stream)
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
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)
css::uno::Reference< css::io::XInputStream > const & GetInputStream()
const css::uno::Reference< css::container::XNameContainer > & mrTable
XMLOFF_DLLPUBLIC bool importXML(css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, css::uno::Any &rValue, OUString &rStrName, SvXMLImport &rImport)
virtual ~SvxXMLXTableImport() noexcept 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
static void openStorageStream(xml::sax::InputSource *pParserInput, rtl::Reference< SvXMLGraphicHelper > &rxGraphicHelper, const uno::Reference< embed::XStorage > &xStorage)
css::uno::Reference< css::embed::XStorage > GetStorage(bool bCreateTempFile=true)
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
INetProtocol GetProtocol() const
#define XML_ELEMENT(prefix, name)
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
Reference< XComponentContext > getProcessComponentContext()
constexpr sal_Int32 TOKEN_MASK
static rtl::Reference< SvXMLGraphicHelper > Create(const css::uno::Reference< css::embed::XStorage > &rXMLStorage, SvXMLGraphicHelperMode eCreateMode)
OUString toString(OptionInfo const *info)
virtual SvXMLImportContext * CreateFastContext(sal_Int32 Element, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList) override