1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "SchXMLDataTableContext.hxx"
22 #include <xmloff/xmlimp.hxx>
23 #include <xmloff/xmlnamespace.hxx>
24 #include <xmloff/namespacemap.hxx>
25 #include <xmloff/xmluconv.hxx>
26 #include <comphelper/processfactory.hxx>
27 #include <com/sun/star/chart/XChartDocument.hpp>
28 #include <com/sun/star/chart2/XChartDocument.hpp>
29 #include <com/sun/star/chart2/XDiagram.hpp>
30 #include <com/sun/star/chart2/XDataTable.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 using namespace ::xmloff::token
;
36 SchXMLDataTableContext::SchXMLDataTableContext(SchXMLImportHelper
& rImpHelper
, SvXMLImport
& rImport
)
37 : SvXMLImportContext(rImport
)
38 , mrImportHelper(rImpHelper
)
42 void SchXMLDataTableContext::startFastElement(
43 sal_Int32
/*nElement*/, const uno::Reference
<xml::sax::XFastAttributeList
>& xAttrList
)
45 // Check if we have all that is needed to create the data table instance
46 auto xChartDocument
= mrImportHelper
.GetChartDocument();
47 if (!xChartDocument
.is())
50 uno::Reference
<chart2::XChartDocument
> xNewChartDocument(xChartDocument
, uno::UNO_QUERY
);
51 if (!xNewChartDocument
.is())
54 uno::Reference
<chart2::XDiagram
> xDiagram(xNewChartDocument
->getFirstDiagram());
58 // Create a new DataTable instance
59 uno::Reference
<lang::XMultiServiceFactory
> xFactory
= comphelper::getProcessServiceFactory();
60 uno::Reference
<chart2::XDataTable
> xDataTable(
61 xFactory
->createInstance("com.sun.star.chart2.DataTable"), uno::UNO_QUERY
);
65 xDiagram
->setDataTable(xDataTable
);
67 OUString sAutoStyleName
;
69 for (auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
71 if (aIter
.getToken() == XML_ELEMENT(CHART
, XML_STYLE_NAME
))
72 sAutoStyleName
= aIter
.toString();
74 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
77 // Set the data table properties
78 uno::Reference
<beans::XPropertySet
> xPropertySet(xDataTable
, uno::UNO_QUERY
);
80 if (!sAutoStyleName
.isEmpty() && xPropertySet
.is())
82 mrImportHelper
.FillAutoStyle(sAutoStyleName
, xPropertySet
);
86 SchXMLDataTableContext::~SchXMLDataTableContext() {}
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */