LibreOffice Module xmloff (master) 1
SchXMLDataTableContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22#include <xmloff/xmlimp.hxx>
25#include <xmloff/xmluconv.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>
32
33using namespace ::xmloff::token;
34using namespace css;
35
37 : SvXMLImportContext(rImport)
38 , mrImportHelper(rImpHelper)
39{
40}
41
43 sal_Int32 /*nElement*/, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList)
44{
45 // Check if we have all that is needed to create the data table instance
46 auto xChartDocument = mrImportHelper.GetChartDocument();
47 if (!xChartDocument.is())
48 return;
49
50 uno::Reference<chart2::XChartDocument> xNewChartDocument(xChartDocument, uno::UNO_QUERY);
51 if (!xNewChartDocument.is())
52 return;
53
54 uno::Reference<chart2::XDiagram> xDiagram(xNewChartDocument->getFirstDiagram());
55 if (!xDiagram.is())
56 return;
57
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);
62 if (!xDataTable.is())
63 return;
64
65 xDiagram->setDataTable(xDataTable);
66
67 OUString sAutoStyleName;
68
69 for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
70 {
71 if (aIter.getToken() == XML_ELEMENT(CHART, XML_STYLE_NAME))
72 sAutoStyleName = aIter.toString();
73 else
74 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
75 }
76
77 // Set the data table properties
78 uno::Reference<beans::XPropertySet> xPropertySet(xDataTable, uno::UNO_QUERY);
79
80 if (!sAutoStyleName.isEmpty() && xPropertySet.is())
81 {
82 mrImportHelper.FillAutoStyle(sAutoStyleName, xPropertySet);
83 }
84}
85
87
88/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~SchXMLDataTableContext() override
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
SchXMLDataTableContext(SchXMLImportHelper &rImpHelper, SvXMLImport &rImport)
SchXMLImportHelper & mrImportHelper
With this class you can import a <chart:chart> element containing its data as <table:table> element o...
const css::uno::Reference< css::chart::XChartDocument > & GetChartDocument() const
void FillAutoStyle(const OUString &rAutoStyleName, const css::uno::Reference< css::beans::XPropertySet > &rProp)
Fill in the autostyle.
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
Reference< XSingleServiceFactory > xFactory
Reference< XMultiServiceFactory > getProcessServiceFactory()
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97